242 lines
6.3 KiB
Diff
242 lines
6.3 KiB
Diff
From 8a319d5ab3b4c30d84b7dc1204c3d5f4fc9dbe2a Mon Sep 17 00:00:00 2001
|
|
From: Hao Fang <fanghao11@huawei.com>
|
|
Date: Wed, 26 Apr 2023 11:55:26 +0800
|
|
Subject: [PATCH 24/28] uadk/aead: introduce the init2 interface for aead
|
|
|
|
The basic init process is complex for users who need to
|
|
know the device, scheduler, etc.
|
|
|
|
So introduce the init2 interface just for simplifying
|
|
the initialization process when user use the aead algorithm.
|
|
|
|
Signed-off-by: Hao Fang <fanghao11@huawei.com>
|
|
---
|
|
include/wd_aead.h | 28 ++++++++++++
|
|
libwd_crypto.map | 3 ++
|
|
wd_aead.c | 113 +++++++++++++++++++++++++++++++++++++++-------
|
|
3 files changed, 127 insertions(+), 17 deletions(-)
|
|
|
|
diff --git a/include/wd_aead.h b/include/wd_aead.h
|
|
index ba7d062..ef1b57b 100644
|
|
--- a/include/wd_aead.h
|
|
+++ b/include/wd_aead.h
|
|
@@ -96,6 +96,34 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched);
|
|
*/
|
|
void wd_aead_uninit(void);
|
|
|
|
+/**
|
|
+ * wd_aead_init2_() - A simplify interface to initializate uadk
|
|
+ * aead operation. This interface keeps most functions of
|
|
+ * wd_aead_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 driver's default.
|
|
+ * Please do not use this interface with wd_aead_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: Task types, including soft computing, hardware and hybrid computing.
|
|
+ * @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_aead_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params);
|
|
+
|
|
+#define wd_aead_init2(alg, sched_type, task_type) \
|
|
+ wd_aead_init2_(alg, sched_type, task_type, NULL)
|
|
+
|
|
+/**
|
|
+ * wd_aead_uninit2() - Uninitialise ctx configuration and scheduler.
|
|
+ */
|
|
+void wd_aead_uninit2(void);
|
|
/**
|
|
* wd_aead_alloc_sess() Allocate a wd aead session
|
|
* @ setup Parameters to setup this session.
|
|
diff --git a/libwd_crypto.map b/libwd_crypto.map
|
|
index e28dd79..e8555c9 100644
|
|
--- a/libwd_crypto.map
|
|
+++ b/libwd_crypto.map
|
|
@@ -23,6 +23,9 @@ global:
|
|
|
|
wd_aead_init;
|
|
wd_aead_uninit;
|
|
+ wd_aead_init2;
|
|
+ wd_aead_init2_;
|
|
+ wd_aead_uninit2;
|
|
wd_aead_alloc_sess;
|
|
wd_aead_free_sess;
|
|
wd_aead_set_ckey;
|
|
diff --git a/wd_aead.c b/wd_aead.c
|
|
index 9b80922..8b63daa 100644
|
|
--- a/wd_aead.c
|
|
+++ b/wd_aead.c
|
|
@@ -56,6 +56,17 @@ struct wd_aead_sess {
|
|
};
|
|
|
|
struct wd_env_config wd_aead_env_config;
|
|
+static struct wd_init_attrs wd_aead_init_attrs;
|
|
+
|
|
+static struct wd_ctx_nums wd_aead_ctx_num[] = {
|
|
+ {1, 1}, {}
|
|
+};
|
|
+
|
|
+static struct wd_ctx_params wd_aead_ctx_params = {
|
|
+ .op_type_num = 1,
|
|
+ .ctx_set_num = wd_aead_ctx_num,
|
|
+ .bmp = NULL,
|
|
+};
|
|
|
|
#ifdef WD_STATIC_DRV
|
|
static void wd_aead_set_static_drv(void)
|
|
@@ -394,30 +405,19 @@ static void wd_aead_clear_status(void)
|
|
wd_alg_clear_init(&wd_aead_setting.status);
|
|
}
|
|
|
|
-int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
|
+static int wd_aead_init_nolock(struct wd_ctx_config *config, struct wd_sched *sched)
|
|
{
|
|
void *priv;
|
|
- bool flag;
|
|
int ret;
|
|
|
|
- pthread_atfork(NULL, NULL, wd_aead_clear_status);
|
|
-
|
|
- flag = wd_alg_try_init(&wd_aead_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_AEAD_EPOLL_EN",
|
|
&wd_aead_setting.config.epoll_en);
|
|
if (ret < 0)
|
|
- goto out_clear_init;
|
|
+ return ret;
|
|
|
|
ret = wd_init_ctx_config(&wd_aead_setting.config, config);
|
|
if (ret)
|
|
- goto out_clear_init;
|
|
+ return ret;
|
|
|
|
ret = wd_init_sched(&wd_aead_setting.sched, sched);
|
|
if (ret < 0)
|
|
@@ -449,8 +449,6 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
|
goto out_free_priv;
|
|
}
|
|
|
|
- wd_alg_set_init(&wd_aead_setting.status);
|
|
-
|
|
return 0;
|
|
|
|
out_free_priv:
|
|
@@ -462,12 +460,39 @@ out_clear_sched:
|
|
wd_clear_sched(&wd_aead_setting.sched);
|
|
out_clear_ctx_config:
|
|
wd_clear_ctx_config(&wd_aead_setting.config);
|
|
+
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
|
+{
|
|
+ bool flag;
|
|
+ int ret;
|
|
+
|
|
+ pthread_atfork(NULL, NULL, wd_aead_clear_status);
|
|
+
|
|
+ flag = wd_alg_try_init(&wd_aead_setting.status);
|
|
+ if (!flag)
|
|
+ return 0;
|
|
+
|
|
+ ret = wd_init_param_check(config, sched);
|
|
+ if (ret)
|
|
+ goto out_clear_init;
|
|
+
|
|
+ ret = wd_aead_init_nolock(config, sched);
|
|
+ if (ret)
|
|
+ goto out_clear_init;
|
|
+
|
|
+ wd_alg_set_init(&wd_aead_setting.status);
|
|
+
|
|
+ return 0;
|
|
+
|
|
out_clear_init:
|
|
wd_alg_clear_init(&wd_aead_setting.status);
|
|
return ret;
|
|
}
|
|
|
|
-void wd_aead_uninit(void)
|
|
+static void wd_aead_uninit_nolock(void)
|
|
{
|
|
void *priv = wd_aead_setting.priv;
|
|
|
|
@@ -481,6 +506,60 @@ void wd_aead_uninit(void)
|
|
wd_uninit_async_request_pool(&wd_aead_setting.pool);
|
|
wd_clear_sched(&wd_aead_setting.sched);
|
|
wd_clear_ctx_config(&wd_aead_setting.config);
|
|
+}
|
|
+
|
|
+void wd_aead_uninit(void)
|
|
+{
|
|
+ wd_aead_uninit_nolock();
|
|
+ wd_alg_clear_init(&wd_aead_setting.status);
|
|
+}
|
|
+
|
|
+
|
|
+int wd_aead_init2_(char *alg, __u32 sched_type, int task_type,
|
|
+ struct wd_ctx_params *ctx_params)
|
|
+{
|
|
+ bool flag;
|
|
+ int ret;
|
|
+
|
|
+ pthread_atfork(NULL, NULL, wd_aead_clear_status);
|
|
+
|
|
+ flag = wd_alg_try_init(&wd_aead_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_uninit;
|
|
+ }
|
|
+
|
|
+ wd_aead_init_attrs.alg = alg;
|
|
+ wd_aead_init_attrs.sched_type = sched_type;
|
|
+ wd_aead_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_aead_ctx_params;
|
|
+ wd_aead_init_attrs.alg_init = wd_aead_init_nolock;
|
|
+ wd_aead_init_attrs.alg_poll_ctx = wd_aead_poll_ctx;
|
|
+ ret = wd_alg_attrs_init(&wd_aead_init_attrs);
|
|
+ if (ret) {
|
|
+ WD_ERR("fail to init alg attrs.\n");
|
|
+ goto out_uninit;
|
|
+ }
|
|
+
|
|
+ wd_alg_set_init(&wd_aead_setting.status);
|
|
+
|
|
+ return 0;
|
|
+
|
|
+out_uninit:
|
|
+ wd_alg_clear_init(&wd_aead_setting.status);
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+void wd_aead_uninit2(void)
|
|
+{
|
|
+ wd_aead_uninit_nolock();
|
|
+
|
|
+ wd_alg_attrs_uninit(&wd_aead_init_attrs);
|
|
+
|
|
wd_alg_clear_init(&wd_aead_setting.status);
|
|
}
|
|
|
|
--
|
|
2.25.1
|
|
|