aead and digest support env init for init2.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- include/wd_util.h | 2 ++ wd_aead.c | 8 ++++++-- wd_cipher.c | 19 +++++-------------- wd_comp.c | 20 +++++--------------- wd_dh.c | 18 +++++------------- wd_digest.c | 10 +++++++--- wd_ecc.c | 19 +++++-------------- wd_rsa.c | 18 +++++------------- wd_util.c | 17 ++++++++++++++++- 9 files changed, 56 insertions(+), 75 deletions(-)
diff --git a/include/wd_util.h b/include/wd_util.h index ce76852..3265946 100644 --- a/include/wd_util.h +++ b/include/wd_util.h @@ -444,6 +444,8 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, struct wd_alg_driver *driver, enum wd_type type, int max_op_type);
+void wd_ctx_param_uninit(struct wd_ctx_params *ctx_params); + /** * wd_alg_attrs_init() - Request the ctxs and initialize the sched_domain * with the given devices list, ctxs number and numa mask. diff --git a/wd_aead.c b/wd_aead.c index 9db2480..1e6011d 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -599,8 +599,9 @@ res_retry: goto out_dlopen; }
+ aead_ctx_params.ctx_set_num = aead_ctx_num; ret = wd_ctx_param_init(&aead_ctx_params, ctx_params, - aead_ctx_num, wd_aead_setting.driver, + wd_aead_setting.driver, WD_AEAD_TYPE, WD_DIGEST_CIPHER_DECRYPTION + 1); if (ret) { if (ret == -WD_EAGAIN) { @@ -625,13 +626,16 @@ res_retry: goto res_retry; } WD_ERR("fail to init alg attrs.\n"); - goto out_driver; + goto out_ctx_uninit; }
wd_alg_set_init(&wd_aead_setting.status); + wd_ctx_param_uninit(&aead_ctx_params);
return 0;
+out_ctx_uninit: + wd_ctx_param_uninit(&aead_ctx_params); out_driver: wd_alg_drv_unbind(wd_aead_setting.driver); out_dlopen: diff --git a/wd_cipher.c b/wd_cipher.c index e4f3d6b..7ba4de4 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -384,7 +384,6 @@ int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_p { struct wd_ctx_nums cipher_ctx_num[WD_CIPHER_DECRYPTION + 1] = {0}; struct wd_ctx_params cipher_ctx_params = {0}; - struct bitmask *inner_bmp; int ret = 0; bool flag;
@@ -412,15 +411,6 @@ int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_p goto out_uninit; }
- inner_bmp = numa_allocate_nodemask(); - if (!inner_bmp) { - WD_ERR("fail to allocate nodemask.\n"); - ret = -WD_ENOMEM; - goto out_dlopen; - } - - cipher_ctx_params.bmp = inner_bmp; - res_retry: memset(&wd_cipher_setting.config, 0, sizeof(struct wd_ctx_config_internal));
@@ -429,7 +419,7 @@ res_retry: if (!wd_cipher_setting.driver) { WD_ERR("fail to bind a valid driver.\n"); ret = -WD_EINVAL; - goto out_bmp; + goto out_dlopen; }
cipher_ctx_params.ctx_set_num = cipher_ctx_num; @@ -459,17 +449,18 @@ res_retry: goto res_retry; } WD_ERR("fail to init alg attrs.\n"); - goto out_driver; + goto out_ctx_uninit; }
wd_alg_set_init(&wd_cipher_setting.status); + wd_ctx_param_uninit(&cipher_ctx_params);
return 0;
+out_ctx_uninit: + wd_ctx_param_uninit(&cipher_ctx_params); out_driver: wd_alg_drv_unbind(wd_cipher_setting.driver); -out_bmp: - numa_free_nodemask(inner_bmp); out_dlopen: wd_dlclose_drv(wd_cipher_setting.dlh_list); out_uninit: diff --git a/wd_comp.c b/wd_comp.c index 7b79864..3d3deae 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -206,7 +206,6 @@ int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_par { struct wd_ctx_nums comp_ctx_num[WD_DIR_MAX] = {0}; struct wd_ctx_params comp_ctx_params; - struct bitmask *inner_bmp; int ret = 0; bool flag;
@@ -234,14 +233,6 @@ int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_par goto out_uninit; }
- inner_bmp = numa_allocate_nodemask(); - if (!inner_bmp) { - WD_ERR("fail to allocate nodemask.\n"); - ret = -WD_ENOMEM; - goto out_dlopen; - } - comp_ctx_params.bmp = inner_bmp; - res_retry: memset(&wd_comp_setting.config, 0, sizeof(struct wd_ctx_config_internal));
@@ -249,7 +240,7 @@ res_retry: wd_comp_setting.driver = wd_alg_drv_bind(task_type, alg); if (!wd_comp_setting.driver) { WD_ERR("fail to bind a valid driver.\n"); - goto out_bmp; + goto out_dlopen; }
comp_ctx_params.ctx_set_num = comp_ctx_num; @@ -278,19 +269,18 @@ res_retry: goto res_retry; } WD_ERR("fail to init alg attrs.\n"); - goto out_driver; + goto out_ctx_uninit; }
wd_alg_set_init(&wd_comp_setting.status); - - numa_free_nodemask(inner_bmp); + wd_ctx_param_uninit(&comp_ctx_params);
return 0;
+out_ctx_uninit: + wd_ctx_param_uninit(&comp_ctx_params); out_driver: wd_alg_drv_unbind(wd_comp_setting.driver); -out_bmp: - numa_free_nodemask(inner_bmp); out_dlopen: wd_dlclose_drv(wd_comp_setting.dlh_list); out_uninit: diff --git a/wd_dh.c b/wd_dh.c index 2f6978b..82e7624 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -197,7 +197,6 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param { struct wd_ctx_nums dh_ctx_num[WD_DH_PHASE2] = {0}; struct wd_ctx_params dh_ctx_params = {0}; - struct bitmask *inner_bmp; bool flag; int ret;
@@ -225,14 +224,6 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param goto out_clear_init; }
- inner_bmp = numa_allocate_nodemask(); - if (!inner_bmp) { - ret = -WD_ENOMEM; - WD_ERR("fail to allocate nodemask.\n"); - goto out_dlopen; - } - dh_ctx_params.bmp = inner_bmp; - res_retry: memset(&wd_dh_setting.config, 0, sizeof(struct wd_ctx_config_internal));
@@ -241,7 +232,7 @@ res_retry: if (!wd_dh_setting.driver) { WD_ERR("fail to bind a valid driver.\n"); ret = -WD_EINVAL; - goto out_bmp; + goto out_dlopen; }
dh_ctx_params.ctx_set_num = dh_ctx_num; @@ -270,17 +261,18 @@ res_retry: goto res_retry; } WD_ERR("failed to init alg attrs!\n"); - goto out_driver; + goto out_ctx_uninit; }
wd_alg_set_init(&wd_dh_setting.status); + wd_ctx_param_uninit(&dh_ctx_params);
return 0;
+out_ctx_uninit: + wd_ctx_param_uninit(&dh_ctx_params); out_driver: wd_alg_drv_unbind(wd_dh_setting.driver); -out_bmp: - numa_free_nodemask(inner_bmp); out_dlopen: wd_dlclose_drv(wd_dh_setting.dlh_list); out_clear_init: diff --git a/wd_digest.c b/wd_digest.c index c57e7d6..2e70f27 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -340,8 +340,8 @@ static bool wd_digest_algs_check(const char *alg) int wd_digest_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params) { - struct wd_ctx_nums digest_ctx_num[1] = {0}; struct wd_ctx_params digest_ctx_params = {0}; + struct wd_ctx_nums digest_ctx_num[1] = {0}; int ret = 0; bool flag;
@@ -385,8 +385,9 @@ res_retry: goto out_dlopen; }
+ digest_ctx_params.ctx_set_num = digest_ctx_num; ret = wd_ctx_param_init(&digest_ctx_params, ctx_params, - digest_ctx_num, wd_digest_setting.driver, 1); + wd_digest_setting.driver, WD_DIGEST_TYPE, 1); if (ret) { if (ret == -WD_EAGAIN) { wd_disable_drv(wd_digest_setting.driver); @@ -410,13 +411,16 @@ res_retry: goto res_retry; } WD_ERR("fail to init alg attrs.\n"); - goto out_driver; + goto out_ctx_uninit; }
wd_alg_set_init(&wd_digest_setting.status); + wd_ctx_param_uninit(&digest_ctx_params);
return 0;
+out_ctx_uninit: + wd_ctx_param_uninit(&digest_ctx_params); out_driver: wd_alg_drv_unbind(wd_digest_setting.driver); out_dlopen: diff --git a/wd_ecc.c b/wd_ecc.c index 183d2bd..21f7c30 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -253,7 +253,6 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para { struct wd_ctx_nums ecc_ctx_num[WD_EC_OP_MAX] = {0}; struct wd_ctx_params ecc_ctx_params = {0}; - struct bitmask *inner_bmp; bool flag; int ret;
@@ -281,14 +280,6 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para goto out_clear_init; }
- inner_bmp = numa_allocate_nodemask(); - if (!inner_bmp) { - WD_ERR("fail to allocate nodemask.\n"); - ret = -WD_ENOMEM; - goto out_dlopen; - } - ecc_ctx_params.bmp = inner_bmp; - res_retry: memset(&wd_ecc_setting.config, 0, sizeof(struct wd_ctx_config_internal));
@@ -297,7 +288,7 @@ res_retry: if (!wd_ecc_setting.driver) { WD_ERR("failed to bind a valid driver!\n"); ret = -WD_EINVAL; - goto out_bmp; + goto out_dlopen; }
ecc_ctx_params.ctx_set_num = ecc_ctx_num; @@ -326,17 +317,17 @@ res_retry: goto res_retry; } WD_ERR("failed to init alg attrs!\n"); - goto out_driver; + goto out_ctx_uninit; }
wd_alg_set_init(&wd_ecc_setting.status); + wd_ctx_param_uninit(&ecc_ctx_params);
return 0; - +out_ctx_uninit: + wd_ctx_param_uninit(&ecc_ctx_params); out_driver: wd_alg_drv_unbind(wd_ecc_setting.driver); -out_bmp: - numa_free_nodemask(inner_bmp); out_dlopen: wd_dlclose_drv(wd_ecc_setting.dlh_list); out_clear_init: diff --git a/wd_rsa.c b/wd_rsa.c index c51c7b1..e685628 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -238,7 +238,6 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para { struct wd_ctx_nums rsa_ctx_num[WD_RSA_GENKEY] = {0}; struct wd_ctx_params rsa_ctx_params = {0}; - struct bitmask *inner_bmp; bool flag; int ret;
@@ -266,14 +265,6 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para goto out_clear_init; }
- inner_bmp = numa_allocate_nodemask(); - if (!inner_bmp) { - WD_ERR("fail to allocate nodemask.\n"); - ret = -WD_ENOMEM; - goto out_dlopen; - } - rsa_ctx_params.bmp = inner_bmp; - res_retry: memset(&wd_rsa_setting.config, 0, sizeof(struct wd_ctx_config_internal));
@@ -282,7 +273,7 @@ res_retry: if (!wd_rsa_setting.driver) { WD_ERR("failed to bind a valid driver!\n"); ret = -WD_EINVAL; - goto out_bmp; + goto out_dlopen; }
rsa_ctx_params.ctx_set_num = rsa_ctx_num; @@ -311,17 +302,18 @@ res_retry: goto res_retry; } WD_ERR("failed to init alg attrs!\n"); - goto out_driver; + goto out_ctx_uninit; }
wd_alg_set_init(&wd_rsa_setting.status); + wd_ctx_param_uninit(&rsa_ctx_params);
return 0;
+out_ctx_uninit: + wd_ctx_param_uninit(&rsa_ctx_params); out_driver: wd_alg_drv_unbind(wd_rsa_setting.driver); -out_bmp: - numa_free_nodemask(inner_bmp); out_dlopen: wd_dlclose_drv(wd_rsa_setting.dlh_list); out_clear_init: diff --git a/wd_util.c b/wd_util.c index 9b5486b..e80cca0 100644 --- a/wd_util.c +++ b/wd_util.c @@ -2084,6 +2084,11 @@ out_free_str: return ret; }
+void wd_ctx_param_uninit(struct wd_ctx_params *ctx_params) +{ + numa_free_nodemask(ctx_params->bmp); +} + int wd_ctx_param_init(struct wd_ctx_params *ctx_params, struct wd_ctx_params *user_ctx_params, struct wd_alg_driver *driver, @@ -2093,22 +2098,30 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, const char *var_s; int i, ret;
+ ctx_params->bmp = numa_allocate_nodemask(); + if (!ctx_params->bmp) { + WD_ERR("fail to allocate nodemask.\n"); + return -WD_ENOMEM; + } + var_s = secure_getenv(env_name); if (var_s && strlen(var_s)) { /* environment variable has the highest priority */ ret = wd_env_set_ctx_nums(env_name, var_s, ctx_params, max_op_type); if (ret) { WD_ERR("fail to init ctx nums from %s!\n", env_name); + numa_free_nodemask(ctx_params->bmp); return -WD_EINVAL; } } else { /* environment variable is not set, try to use user_ctx_params first */ if (user_ctx_params) { - ctx_params->bmp = user_ctx_params->bmp; + copy_bitmask_to_bitmask(user_ctx_params->bmp, ctx_params->bmp); ctx_params->ctx_set_num = user_ctx_params->ctx_set_num; ctx_params->op_type_num = user_ctx_params->op_type_num; if (ctx_params->op_type_num > max_op_type) { WD_ERR("fail to check user op type numbers.\n"); + numa_free_nodemask(ctx_params->bmp); return -WD_EINVAL; }
@@ -2116,6 +2129,7 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, }
/* user_ctx_params is also not set, use driver's defalut queue_num */ + numa_free_nodemask(ctx_params->bmp); ctx_params->bmp = NULL; for (i = 0; i < driver->op_type_num; i++) { ctx_params->ctx_set_num[i].sync_ctx_num = driver->queue_num; @@ -2126,6 +2140,7 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, ctx_params->op_type_num = driver->op_type_num; if (ctx_params->op_type_num > max_op_type) { WD_ERR("fail to check driver op type numbers.\n"); + numa_free_nodemask(ctx_params->bmp); return -WD_EAGAIN; }