1. ldl should be last 2. simple code for env init
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- Makefile.am | 2 +- include/wd_util.h | 20 ++----- wd_cipher.c | 8 +-- wd_comp.c | 10 +--- wd_dh.c | 9 +-- wd_ecc.c | 9 +-- wd_rsa.c | 9 +-- wd_util.c | 149 ++++++++++++++++++++++++---------------------- 8 files changed, 94 insertions(+), 122 deletions(-)
diff --git a/Makefile.am b/Makefile.am index c66bbfe..601a20d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -118,7 +118,7 @@ libwd_crypto_la_LIBADD= -lwd -ldl -lnuma libwd_crypto_la_LDFLAGS=$(UADK_VERSION) $(UADK_CRYPTO_SYMBOL) libwd_crypto_la_DEPENDENCIES= libwd.la
-libhisi_zip_la_LIBADD= -ldl -lwd +libhisi_zip_la_LIBADD= -lwd -ldl libhisi_zip_la_LDFLAGS=$(UADK_VERSION)
libhisi_sec_la_LIBADD= -lwd -lwd_crypto diff --git a/include/wd_util.h b/include/wd_util.h index 434f068..baac0e3 100644 --- a/include/wd_util.h +++ b/include/wd_util.h @@ -420,16 +420,16 @@ static inline void wd_alg_clear_init(enum wd_status *status) /** * wd_ctx_param_init() - Initialize the current device driver according * to the obtained queue resource and the applied driver. - * @config: device resources requested by the current algorithm. + * @ctx_params: wd_ctx_params to be initialized. + * @user_ctx_params: user input wd_ctx_params. * @driver: device driver for the current algorithm application. - * @drv_priv: the parameter pointer of the current device driver. + * @env_name: algorithm environment variable. + * @max_op_type: algorithm max operation type. * * Return 0 if succeed and other error number if fail. */ -int wd_ctx_param_init(struct wd_ctx_params *ctx_params, - struct wd_ctx_params *user_ctx_params, - struct wd_ctx_nums *ctx_set_num, - struct wd_alg_driver *driver, int max_op_type); +int wd_ctx_param_init(struct wd_ctx_params *ctx_params, struct wd_ctx_params *user_ctx_params, + struct wd_alg_driver *driver, const char *env_name, int max_op_type);
/** * wd_alg_attrs_init() - Request the ctxs and initialize the sched_domain @@ -482,14 +482,6 @@ void wd_dlclose_drv(void *dlh_list); */ int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir);
-/** - * wd_env_set_ctx_ctx_nums() - Set the ctx_set_num by parsing the environment variable. - * @name: the name of the environment variable. - * @ctx_nums: array to be initialized. - * @size: array size. - */ -int wd_env_set_ctx_nums(const char *name, struct wd_ctx_nums *ctx_nums, __u32 size); - /** * wd_dfx_msg_cnt() - Message counter interface for ctx * @msg: Shared memory addr. diff --git a/wd_cipher.c b/wd_cipher.c index 80d4be2..b24fcf9 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -422,14 +422,10 @@ res_retry: goto out_dlopen; }
- ret = wd_env_set_ctx_nums("WD_CIPHER_CTX_NUM", cipher_ctx_num, WD_CIPHER_DECRYPTION + 1); - if (ret) { - WD_ERR("fail to init cipher ctx nums from env!\n"); - goto out_driver; - }
+ cipher_ctx_params.ctx_set_num = cipher_ctx_num; ret = wd_ctx_param_init(&cipher_ctx_params, ctx_params, - cipher_ctx_num, wd_cipher_setting.driver, + wd_cipher_setting.driver, "WD_CIPHER_CTX_NUM", WD_CIPHER_DECRYPTION + 1); if (ret) { if (ret == -WD_EAGAIN) { diff --git a/wd_comp.c b/wd_comp.c index 99553c5..f38a922 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -243,15 +243,9 @@ res_retry: goto out_dlopen; }
- - ret = wd_env_set_ctx_nums("WD_COMP_CTX_NUM", comp_ctx_num, WD_DIR_MAX); - if (ret) { - WD_ERR("fail to init comp ctx nums from env!\n"); - goto out_driver; - } - + comp_ctx_params.ctx_set_num = comp_ctx_num; ret = wd_ctx_param_init(&comp_ctx_params, ctx_params, - comp_ctx_num, wd_comp_setting.driver, + wd_comp_setting.driver, "WD_COMP_CTX_NUM", WD_DIR_MAX); if (ret) { if (ret == -WD_EAGAIN) { diff --git a/wd_dh.c b/wd_dh.c index bb8e76f..7b32f8a 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -235,14 +235,9 @@ res_retry: goto out_dlopen; }
- ret = wd_env_set_ctx_nums("WD_DH_CTX_NUM", dh_ctx_num, WD_DH_PHASE2); - if (ret) { - WD_ERR("fail to init dh ctx nums from env!\n"); - goto out_driver; - } - + dh_ctx_params.ctx_set_num = dh_ctx_num; ret = wd_ctx_param_init(&dh_ctx_params, ctx_params, - dh_ctx_num, wd_dh_setting.driver, + wd_dh_setting.driver, "WD_DH_CTX_NUM", WD_DH_PHASE2); if (ret) { if (ret == -WD_EAGAIN) { diff --git a/wd_ecc.c b/wd_ecc.c index bef7982..0565aea 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -291,14 +291,9 @@ res_retry: goto out_dlopen; }
- ret = wd_env_set_ctx_nums("WD_ECC_CTX_NUM", ecc_ctx_num, WD_EC_OP_MAX); - if (ret) { - WD_ERR("fail to init ecc ctx nums from env!\n"); - goto out_driver; - } - + ecc_ctx_params.ctx_set_num = ecc_ctx_num; ret = wd_ctx_param_init(&ecc_ctx_params, ctx_params, - ecc_ctx_num, wd_ecc_setting.driver, + wd_ecc_setting.driver, "WD_ECC_CTX_NUM", WD_EC_OP_MAX); if (ret) { if (ret == -WD_EAGAIN) { diff --git a/wd_rsa.c b/wd_rsa.c index 9f5fb57..f062b78 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -276,14 +276,9 @@ res_retry: goto out_dlopen; }
- ret = wd_env_set_ctx_nums("WD_RSA_CTX_NUM", rsa_ctx_num, WD_RSA_GENKEY); - if (ret) { - WD_ERR("fail to init rsa ctx nums from env!\n"); - goto out_driver; - } - + rsa_ctx_params.ctx_set_num = rsa_ctx_num; ret = wd_ctx_param_init(&rsa_ctx_params, ctx_params, - rsa_ctx_num, wd_rsa_setting.driver, + wd_rsa_setting.driver, "WD_RSA_CTX_NUM", WD_RSA_GENKEY); if (ret) { if (ret == -WD_EAGAIN) { diff --git a/wd_util.c b/wd_util.c index b8a3355..41b390c 100644 --- a/wd_util.c +++ b/wd_util.c @@ -2000,16 +2000,81 @@ static void add_lib_to_list(struct drv_lib_list *head, tmp->next = node; }
-int wd_ctx_param_init(struct wd_ctx_params *ctx_params, - struct wd_ctx_params *user_ctx_params, - struct wd_ctx_nums *ctx_set_num, - struct wd_alg_driver *driver, int max_op_type) +static int wd_set_ctx_nums(struct wd_ctx_nums *ctx_nums, const char *section, + __u32 op_type_num, int is_comp) { - int i; + int i, j, ctx_num, node, ret; + char *ctx_section; + const char *type; + + if (is_comp && op_type_num > ARRAY_SIZE(comp_ctx_type)) + return -WD_EINVAL; + + ctx_section = index(section, ':'); + ctx_section++; + ret = parse_num_on_numa(ctx_section, &ctx_num, &node); + if (ret) + return ret; + + for (i = 0; i < CTX_MODE_MAX; i++) { + for (j = 0; j < op_type_num; j++) { + type = is_comp ? comp_ctx_type[i][j] : ctx_type[i][0]; + if (strncmp(section, type, strlen(type))) + continue; + + if (!i) + ctx_nums[j].sync_ctx_num = ctx_num; + else + ctx_nums[j].async_ctx_num = ctx_num; + + return 0; + } + } + + return -WD_EINVAL; +} + +static int wd_env_set_ctx_nums(const char *name, struct wd_ctx_nums *ctx_nums, __u32 size) +{ + char *left, *section, *start, *var_s; + int is_comp; + int ret = 0; + + is_comp = strncmp(name, "WD_COMP_CTX_NUM", strlen(name)) ? 0 : 1; + + var_s = secure_getenv(name); + if (!var_s || !strlen(var_s)) + return 0; + + start = strdup(var_s); + if (!start) + return -WD_ENOMEM; + + left = start; + while ((section = strsep(&left, ","))) { + ret = wd_set_ctx_nums(ctx_nums, section, size, is_comp); + if (ret) + goto out_free_str; + } + +out_free_str: + free(start); + return ret; +} + +int wd_ctx_param_init(struct wd_ctx_params *ctx_params, struct wd_ctx_params *user_ctx_params, + struct wd_alg_driver *driver, const char *env_name, int max_op_type) +{ + int i, ret; + + ret = wd_env_set_ctx_nums(env_name, ctx_params->ctx_set_num, max_op_type); + if (ret) { + WD_ERR("fail to init ctx nums from %s!\n", env_name); + return -WD_EINVAL; + }
- if (!user_ctx_params) { + if (!ret || !user_ctx_params) { ctx_params->bmp = NULL; - ctx_params->ctx_set_num = ctx_set_num; 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"); @@ -2017,10 +2082,11 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, }
for (i = 0; i < ctx_params->op_type_num; i++) { - if (!ctx_set_num[i].sync_ctx_num || !ctx_set_num[i].async_ctx_num) { - ctx_set_num[i].sync_ctx_num = driver->queue_num; - ctx_set_num[i].async_ctx_num = driver->queue_num; - } + if (!ctx_params->ctx_set_num[i].sync_ctx_num) + ctx_params->ctx_set_num[i].sync_ctx_num = driver->queue_num; + + if (!ctx_params->ctx_set_num[i].async_ctx_num) + ctx_params->ctx_set_num[i].async_ctx_num = driver->queue_num; } } else { ctx_params->bmp = user_ctx_params->bmp; @@ -2582,64 +2648,3 @@ void wd_alg_attrs_uninit(struct wd_init_attrs *attrs) } wd_sched_rr_release(alg_sched); } - -static int wd_set_ctx_nums(struct wd_ctx_nums *ctx_nums, const char *section, - __u32 op_type_num, int is_comp) -{ - int i, j, ctx_num, node, ret; - char *ctx_section; - const char *type; - - if (is_comp && op_type_num > ARRAY_SIZE(comp_ctx_type)) - return -WD_EINVAL; - - ctx_section = index(section, ':'); - ctx_section++; - ret = parse_num_on_numa(ctx_section, &ctx_num, &node); - if (ret) - return ret; - - for (i = 0; i < CTX_MODE_MAX; i++) { - for (j = 0; j < op_type_num; j++) { - type = is_comp ? comp_ctx_type[i][j] : ctx_type[i][0]; - if (strncmp(section, type, strlen(type))) - continue; - - if (!i) - ctx_nums[j].sync_ctx_num = ctx_num; - else - ctx_nums[j].async_ctx_num = ctx_num; - - return 0; - } - } - - return -WD_EINVAL; -} - -int wd_env_set_ctx_nums(const char *name, struct wd_ctx_nums *ctx_nums, __u32 size) -{ - char *left, *section, *start, *var_s; - int ret, is_comp; - - is_comp = strncmp(name, "WD_COMP_CTX_NUM", strlen(name)) ? 0 : 1; - - var_s = secure_getenv(name); - if (!var_s || !strlen(var_s)) - return 0; - - start = strdup(var_s); - if (!start) - return -WD_ENOMEM; - - left = start; - while ((section = strsep(&left, ","))) { - ret = wd_set_ctx_nums(ctx_nums, section, size, is_comp); - if (ret) - goto out_free_str; - } - -out_free_str: - free(start); - return ret; -}