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 digest algorithm.
Signed-off-by: Hao Fang fanghao11@huawei.com --- include/wd_digest.h | 28 +++++++++++ libwd_crypto.map | 3 ++ wd_digest.c | 113 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 127 insertions(+), 17 deletions(-)
diff --git a/include/wd_digest.h b/include/wd_digest.h index a44328e..f938295 100644 --- a/include/wd_digest.h +++ b/include/wd_digest.h @@ -142,6 +142,34 @@ struct wd_digest_tag {
int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched); void wd_digest_uninit(void); +/** + * wd_digest_init2_() - A simplify interface to initializate uadk + * digest operation. This interface keeps most functions of + * wd_digest_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_digest_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_digest_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params); + +#define wd_digest_init2(alg, sched_type, task_type) \ + wd_digest_init2(alg, sched_type, task_type, NULL) + +/** + * wd_digest_uninit2() - Uninitialise ctx configuration and scheduler. + */ +void wd_digest_uninit2(void);
/** * wd_digest_alloc_sess() - Create a digest session. diff --git a/libwd_crypto.map b/libwd_crypto.map index a5dd688..e28dd79 100644 --- a/libwd_crypto.map +++ b/libwd_crypto.map @@ -45,6 +45,9 @@ global:
wd_digest_init; wd_digest_uninit; + wd_digest_init2; + wd_digest_init2_; + wd_digest_uninit2; wd_digest_alloc_sess; wd_digest_free_sess; wd_do_digest_sync; diff --git a/wd_digest.c b/wd_digest.c index 8c01709..03d3ace 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -66,6 +66,17 @@ struct wd_digest_sess { };
struct wd_env_config wd_digest_env_config; +static struct wd_init_attrs wd_digest_init_attrs; + +static struct wd_ctx_nums wd_digest_ctx_num[] = { + {1, 1}, {} +}; + +static struct wd_ctx_params wd_digest_ctx_params = { + .op_type_num = 1, + .ctx_set_num = wd_digest_ctx_num, + .bmp = NULL, +};
#ifdef WD_STATIC_DRV static void wd_digest_set_static_drv(void) @@ -188,30 +199,20 @@ static void wd_digest_clear_status(void) wd_alg_clear_init(&wd_digest_setting.status); }
-int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched) +static int wd_digest_init_nolock(struct wd_ctx_config *config, + struct wd_sched *sched) { void *priv; - bool flag; int ret;
- pthread_atfork(NULL, NULL, wd_digest_clear_status); - - flag = wd_alg_try_init(&wd_digest_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_DIGEST_EPOLL_EN", &wd_digest_setting.config.epoll_en); if (ret < 0) - goto out_clear_init; + return ret;
ret = wd_init_ctx_config(&wd_digest_setting.config, config); if (ret < 0) - goto out_clear_init; + return ret;
ret = wd_init_sched(&wd_digest_setting.sched, sched); if (ret < 0) @@ -243,8 +244,6 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched) goto out_free_priv; }
- wd_alg_set_init(&wd_digest_setting.status); - return 0;
out_free_priv: @@ -256,12 +255,39 @@ out_clear_sched: wd_clear_sched(&wd_digest_setting.sched); out_clear_ctx_config: wd_clear_ctx_config(&wd_digest_setting.config); + + return ret; +} + +int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched) +{ + bool flag; + int ret; + + pthread_atfork(NULL, NULL, wd_digest_clear_status); + + flag = wd_alg_try_init(&wd_digest_setting.status); + if (!flag) + return 0; + + ret = wd_init_param_check(config, sched); + if (ret) + goto out_clear_init; + + ret = wd_digest_init_nolock(config, sched); + if (ret) + goto out_clear_init; + + wd_alg_set_init(&wd_digest_setting.status); + + return 0; + out_clear_init: wd_alg_clear_init(&wd_digest_setting.status); return ret; }
-void wd_digest_uninit(void) +static void wd_digest_uninit_nolock(void) { void *priv = wd_digest_setting.priv;
@@ -276,6 +302,59 @@ void wd_digest_uninit(void)
wd_clear_sched(&wd_digest_setting.sched); wd_clear_ctx_config(&wd_digest_setting.config); +} + +void wd_digest_uninit(void) +{ + wd_digest_uninit_nolock(); + wd_alg_clear_init(&wd_digest_setting.status); +} + +int wd_digest_init2_(char *alg, __u32 sched_type, int task_type, + struct wd_ctx_params *ctx_params) +{ + bool flag; + int ret; + + pthread_atfork(NULL, NULL, wd_digest_clear_status); + + flag = wd_alg_try_init(&wd_digest_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_digest_init_attrs.alg = alg; + wd_digest_init_attrs.sched_type = sched_type; + wd_digest_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_digest_ctx_params; + wd_digest_init_attrs.alg_init = wd_digest_init_nolock; + wd_digest_init_attrs.alg_poll_ctx = wd_digest_poll_ctx; + ret = wd_alg_attrs_init(&wd_digest_init_attrs); + if (ret) { + WD_ERR("fail to init alg attrs.\n"); + goto out_uninit; + } + + wd_alg_set_init(&wd_digest_setting.status); + + return 0; + +out_uninit: + wd_alg_clear_init(&wd_digest_setting.status); + return ret; +} + +void wd_digest_uninit2(void) +{ + wd_digest_uninit_nolock(); + + wd_alg_attrs_uninit(&wd_digest_init_attrs); + wd_alg_clear_init(&wd_digest_setting.status); }