236 lines
6.2 KiB
Diff
236 lines
6.2 KiB
Diff
From 409e0dc66bf5f805339c5cb413773753e3071be0 Mon Sep 17 00:00:00 2001
|
|
From: Weili Qian <qianweili@huawei.com>
|
|
Date: Sat, 11 Feb 2023 15:19:31 +0800
|
|
Subject: [PATCH 13/28] uadk/dh: add the init2 interface for dh
|
|
|
|
This set of interfaces puts resource initialization
|
|
operations into the init2 interface, simplifying the
|
|
initialization operations when users use the dh algorithm.
|
|
|
|
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
|
---
|
|
include/wd_dh.h | 30 +++++++++++++
|
|
libwd_crypto.map | 3 ++
|
|
wd_dh.c | 109 ++++++++++++++++++++++++++++++++++++++---------
|
|
3 files changed, 123 insertions(+), 19 deletions(-)
|
|
|
|
diff --git a/include/wd_dh.h b/include/wd_dh.h
|
|
index 3912680..afc2f7c 100644
|
|
--- a/include/wd_dh.h
|
|
+++ b/include/wd_dh.h
|
|
@@ -61,6 +61,36 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count);
|
|
int wd_dh_poll(__u32 expt, __u32 *count);
|
|
int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched);
|
|
void wd_dh_uninit(void);
|
|
+
|
|
+/**
|
|
+ * wd_dh_init2_() - A simplify interface to initializate dh.
|
|
+ * This interface keeps most functions of
|
|
+ * wd_dh_init(). Users just need to descripe the deployment of
|
|
+ * business scenarios. Then the initialization will request appropriate
|
|
+ * resources to support the business scenarios.
|
|
+ * To make the initializate simpler, ctx_params support set NULL.
|
|
+ * And then the function will set them as default.
|
|
+ * Please do not use this interface with wd_dh_init() together, or
|
|
+ * some resources may be leak.
|
|
+ *
|
|
+ * @alg: The algorithm users want to use.
|
|
+ * @sched_type: The scheduling type users want to use.
|
|
+ * @task_type: Reserved.
|
|
+ * @ctx_params: The ctxs resources users want to use. Include per operation
|
|
+ * type ctx numbers and business process run numa.
|
|
+ *
|
|
+ * Return 0 if succeed and others if fail.
|
|
+ */
|
|
+int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params);
|
|
+
|
|
+#define wd_dh_init2(alg, sched_type, task_type) \
|
|
+ wd_dh_init2_(alg, sched_type, task_type, NULL)
|
|
+
|
|
+/**
|
|
+ * wd_dh_uninit2() - Uninitialise ctx configuration and scheduler.
|
|
+ */
|
|
+void wd_dh_uninit2(void);
|
|
+
|
|
int wd_dh_env_init(struct wd_sched *sched);
|
|
void wd_dh_env_uninit(void);
|
|
int wd_dh_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode);
|
|
diff --git a/libwd_crypto.map b/libwd_crypto.map
|
|
index 871ef36..5c46c44 100644
|
|
--- a/libwd_crypto.map
|
|
+++ b/libwd_crypto.map
|
|
@@ -112,6 +112,9 @@ global:
|
|
wd_dh_poll;
|
|
wd_dh_init;
|
|
wd_dh_uninit;
|
|
+ wd_dh_init2;
|
|
+ wd_dh_init2_;
|
|
+ wd_dh_uninit2;
|
|
wd_dh_env_init;
|
|
wd_dh_env_uninit;
|
|
wd_dh_ctx_num_init;
|
|
diff --git a/wd_dh.c b/wd_dh.c
|
|
index 4cb5c26..d861b34 100644
|
|
--- a/wd_dh.c
|
|
+++ b/wd_dh.c
|
|
@@ -41,6 +41,17 @@ static struct wd_dh_setting {
|
|
} wd_dh_setting;
|
|
|
|
struct wd_env_config wd_dh_env_config;
|
|
+static struct wd_init_attrs wd_dh_init_attrs;
|
|
+
|
|
+static struct wd_ctx_nums wd_dh_ctx_num[] = {
|
|
+ {1, 1}, {}
|
|
+};
|
|
+
|
|
+static struct wd_ctx_params wd_dh_ctx_params = {
|
|
+ .op_type_num = 1,
|
|
+ .ctx_set_num = wd_dh_ctx_num,
|
|
+ .bmp = NULL,
|
|
+};
|
|
|
|
#ifdef WD_STATIC_DRV
|
|
static void wd_dh_set_static_drv(void)
|
|
@@ -79,30 +90,19 @@ static void wd_dh_clear_status(void)
|
|
wd_alg_clear_init(&wd_dh_setting.status);
|
|
}
|
|
|
|
-int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
|
+static int wd_dh_common_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
|
{
|
|
void *priv;
|
|
- bool flag;
|
|
int ret;
|
|
|
|
- pthread_atfork(NULL, NULL, wd_dh_clear_status);
|
|
-
|
|
- flag = wd_alg_try_init(&wd_dh_setting.status);
|
|
- if (!flag)
|
|
- return 0;
|
|
-
|
|
- ret = wd_init_param_check(config, sched);
|
|
- if (ret)
|
|
- goto out_clear_init;
|
|
-
|
|
ret = wd_set_epoll_en("WD_DH_EPOLL_EN",
|
|
&wd_dh_setting.config.epoll_en);
|
|
if (ret < 0)
|
|
- goto out_clear_init;
|
|
+ return ret;
|
|
|
|
ret = wd_init_ctx_config(&wd_dh_setting.config, config);
|
|
if (ret)
|
|
- goto out_clear_init;
|
|
+ return ret;
|
|
|
|
ret = wd_init_sched(&wd_dh_setting.sched, sched);
|
|
if (ret)
|
|
@@ -134,8 +134,6 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
|
goto out_free_priv;
|
|
}
|
|
|
|
- wd_alg_set_init(&wd_dh_setting.status);
|
|
-
|
|
return 0;
|
|
|
|
out_free_priv:
|
|
@@ -147,12 +145,10 @@ out_clear_sched:
|
|
wd_clear_sched(&wd_dh_setting.sched);
|
|
out_clear_ctx_config:
|
|
wd_clear_ctx_config(&wd_dh_setting.config);
|
|
-out_clear_init:
|
|
- wd_alg_clear_init(&wd_dh_setting.status);
|
|
return ret;
|
|
}
|
|
|
|
-void wd_dh_uninit(void)
|
|
+static void wd_dh_common_uninit(void)
|
|
{
|
|
if (!wd_dh_setting.priv) {
|
|
WD_ERR("invalid: repeat uninit dh!\n");
|
|
@@ -170,6 +166,81 @@ void wd_dh_uninit(void)
|
|
/* unset config, sched, driver */
|
|
wd_clear_sched(&wd_dh_setting.sched);
|
|
wd_clear_ctx_config(&wd_dh_setting.config);
|
|
+}
|
|
+
|
|
+int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
|
+{
|
|
+ bool flag;
|
|
+ int ret;
|
|
+
|
|
+ pthread_atfork(NULL, NULL, wd_dh_clear_status);
|
|
+
|
|
+ flag = wd_alg_try_init(&wd_dh_setting.status);
|
|
+ if (!flag)
|
|
+ return 0;
|
|
+
|
|
+ ret = wd_init_param_check(config, sched);
|
|
+ if (ret)
|
|
+ goto out_clear_init;
|
|
+
|
|
+ ret = wd_dh_common_init(config, sched);
|
|
+ if (ret)
|
|
+ goto out_clear_init;
|
|
+
|
|
+ wd_alg_set_init(&wd_dh_setting.status);
|
|
+
|
|
+ return 0;
|
|
+
|
|
+out_clear_init:
|
|
+ wd_alg_clear_init(&wd_dh_setting.status);
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+void wd_dh_uninit(void)
|
|
+{
|
|
+ wd_dh_common_uninit();
|
|
+ wd_alg_clear_init(&wd_dh_setting.status);
|
|
+}
|
|
+
|
|
+int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params)
|
|
+{
|
|
+ bool flag;
|
|
+ int ret;
|
|
+
|
|
+ pthread_atfork(NULL, NULL, wd_dh_clear_status);
|
|
+
|
|
+ flag = wd_alg_try_init(&wd_dh_setting.status);
|
|
+ if (!flag)
|
|
+ return 0;
|
|
+
|
|
+ if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) {
|
|
+ WD_ERR("invalid: input param is wrong!\n");
|
|
+ ret = -WD_EINVAL;
|
|
+ goto out_clear_init;
|
|
+ }
|
|
+
|
|
+ wd_dh_init_attrs.alg = alg;
|
|
+ wd_dh_init_attrs.sched_type = sched_type;
|
|
+ wd_dh_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_dh_ctx_params;
|
|
+ wd_dh_init_attrs.alg_init = wd_dh_common_init;
|
|
+ wd_dh_init_attrs.alg_poll_ctx = wd_dh_poll_ctx;
|
|
+ ret = wd_alg_attrs_init(&wd_dh_init_attrs);
|
|
+ if (ret)
|
|
+ goto out_clear_init;
|
|
+
|
|
+ wd_alg_set_init(&wd_dh_setting.status);
|
|
+
|
|
+ return 0;
|
|
+
|
|
+out_clear_init:
|
|
+ wd_alg_clear_init(&wd_dh_setting.status);
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+void wd_dh_uninit2(void)
|
|
+{
|
|
+ wd_dh_common_uninit();
|
|
+ wd_alg_attrs_uninit(&wd_dh_init_attrs);
|
|
wd_alg_clear_init(&wd_dh_setting.status);
|
|
}
|
|
|
|
--
|
|
2.25.1
|
|
|