According to the needs of device driver registration. Algorithm-driven priorities and types need to be distinguished.
Hao Fang (1): uadk/crypto: tinyfix for digest/aead/cipher init2
Longfang Liu (3): uadk/alg: bugfix some dynamically loading framework issues uadk: fix some uadk framework issues uadk/drv: update the registration properties of the uadk driver.
drv/hisi_comp.c | 9 +-- drv/hisi_hpre.c | 52 ++++++++++------- drv/hisi_sec.c | 26 ++++----- include/wd.h | 6 ++ include/wd_alg.h | 52 ++++++++++++++++- wd.c | 18 +++--- wd_aead.c | 102 ++++++++++++++++------------------ wd_alg.c | 139 +++++++++++++++++++++++++++++++++------------- wd_cipher.c | 141 ++++++++++++++++++++++++++++------------------- wd_digest.c | 104 ++++++++++++++++------------------ wd_util.c | 21 +++++-- 11 files changed, 412 insertions(+), 258 deletions(-)
According to the needs of device driver registration. Algorithm-driven priorities and types need to be distinguished. In addition, the name memory space of the algorithm linked list needs to be dynamically allocated, and direct pointer references will cause life cycle mismatches and errors. Finally, fix the code that matches part of the registered device with the driver.
Signed-off-by: Longfang Liu liulongfang@huawei.com --- include/wd_alg.h | 52 +++++++++++++++++- wd_alg.c | 139 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 150 insertions(+), 41 deletions(-)
diff --git a/include/wd_alg.h b/include/wd_alg.h index e25e191..0f446cf 100644 --- a/include/wd_alg.h +++ b/include/wd_alg.h @@ -20,6 +20,9 @@ extern "C" { #endif
#define handle_t uintptr_t +#define ALG_NAME_SIZE 128 +#define DEV_NAME_LEN 128 + enum alg_priority { UADK_ALG_SOFT = 0x0, UADK_ALG_CE_INSTR = 0x1, @@ -31,6 +34,13 @@ enum alg_priority { * @drv_name: name of the current device driver * @alg_name: name of the algorithm supported by the driver * @priority: priority of the type of algorithm supported by the driver + * the larger the value of priority, the higher the priority of the driver, + * it will be used first when selecting a driver. + * soft calculation can be defined as 0. + * hard calculation can be defined as a value above 100. + * instruction acceleration can define a higher value according to + * the performance situation, such as 400. + * @calc_type: the calculation method of algorithm supported by the driver * @queue_num: number of device queues required by the device to * execute the algorithm task * @op_type_num: number of modes in which the device executes the @@ -52,6 +62,7 @@ struct wd_alg_driver { const char *drv_name; const char *alg_name; int priority; + int calc_type; int queue_num; int op_type_num; int priv_size; @@ -64,25 +75,62 @@ struct wd_alg_driver { int (*get_usage)(void *param); };
+/** + * wd_alg_driver_register() - Register a device driver. + * @wd_alg_driver: a device driver that supports an algorithm. + * + * Return the execution result, non-zero means error code. + */ int wd_alg_driver_register(struct wd_alg_driver *drv); void wd_alg_driver_unregister(struct wd_alg_driver *drv);
+/** + * @alg_name: name of the algorithm supported by the driver + * @drv_name: name of the current device driver + * @available: Indicates whether the current driver still has resources available + * @priority: priority of the type of algorithm supported by the driver + * @calc_type: the calculation method of algorithm supported by the driver + * @refcnt: the number of times the algorithm driver is being cited by the task + * + * @drv: device Drivers Supporting Algorithms + * @next: pointer to the next node of the algorithm linked list + */ struct wd_alg_list { - const char *alg_name; - const char *drv_name; + char alg_name[ALG_NAME_SIZE]; + char drv_name[DEV_NAME_LEN]; bool available; int priority; + int calc_type; int refcnt;
struct wd_alg_driver *drv; struct wd_alg_list *next; };
+/** + * wd_request_drv() - Apply for an algorithm driver. + * @alg_name: task algorithm name. + * @hw_mask: the flag of shield hardware device drivers. + * + * Returns the applied algorithm driver, non means error. + */ struct wd_alg_driver *wd_request_drv(const char *alg_name, bool hw_mask); void wd_release_drv(struct wd_alg_driver *drv);
+/** + * wd_drv_alg_support() - Check the algorithms supported by the driver. + * @alg_name: task algorithm name. + * @drv: a device driver that supports an algorithm. + * + * Return check result. + */ bool wd_drv_alg_support(const char *alg_name, struct wd_alg_driver *drv); + +/** + * wd_enable_drv() - Re-enable use of the current device driver. + * @drv: a device driver that supports an algorithm. + */ void wd_enable_drv(struct wd_alg_driver *drv); void wd_disable_drv(struct wd_alg_driver *drv);
diff --git a/wd_alg.c b/wd_alg.c index 5e4edaf..ffcadac 100644 --- a/wd_alg.c +++ b/wd_alg.c @@ -16,11 +16,55 @@ #include "wd_alg.h"
#define SYS_CLASS_DIR "/sys/class/uacce" +#define SVA_FILE_NAME "flags" +#define DEV_SVA_SIZE 32 +#define STR_DECIMAL 0xA + static struct wd_alg_list alg_list_head; static struct wd_alg_list *alg_list_tail = &alg_list_head;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+static bool wd_check_dev_sva(const char *dev_name) +{ + char dev_path[PATH_MAX] = {'\0'}; + char buf[DEV_SVA_SIZE] = {'\0'}; + unsigned int val; + ssize_t ret; + int fd; + + ret = snprintf(dev_path, PATH_STR_SIZE, "%s/%s/%s", SYS_CLASS_DIR, + dev_name, SVA_FILE_NAME); + if (ret < 0) { + WD_ERR("failed to snprintf, device name: %s!\n", dev_name); + return false; + } + + /** + * The opened file is the specified device driver file. + * no need for realpath processing. + */ + fd = open(dev_path, O_RDONLY, 0); + if (fd < 0) { + WD_ERR("failed to open %s(%d)!\n", dev_path, -errno); + return false; + } + + ret = read(fd, buf, DEV_SVA_SIZE - 1); + if (ret <= 0) { + WD_ERR("failed to read anything at %s!\n", dev_path); + close(fd); + return false; + } + close(fd); + + val = strtol(buf, NULL, STR_DECIMAL); + if (val & UACCE_DEV_SVA) + return true; + + return false; +} + static bool wd_check_accel_dev(const char *dev_name) { struct dirent *dev_dir; @@ -37,7 +81,8 @@ static bool wd_check_accel_dev(const char *dev_name) !strncmp(dev_dir->d_name, "..", LINUX_PRTDIR_SIZE)) continue;
- if (!strncmp(dev_dir->d_name, dev_name, strlen(dev_name))) { + if (!strncmp(dev_dir->d_name, dev_name, strlen(dev_name)) && + wd_check_dev_sva(dev_dir->d_name)) { closedir(wd_class); return true; } @@ -47,6 +92,46 @@ static bool wd_check_accel_dev(const char *dev_name) return false; }
+static bool wd_alg_check_available(int calc_type, const char *dev_name) +{ + bool ret = false; + + switch (calc_type) { + case UADK_ALG_SOFT: + break; + /* Should find the CPU if not support CE */ + case UADK_ALG_CE_INSTR: + break; + /* Should find the CPU if not support SVE */ + case UADK_ALG_SVE_INSTR: + break; + /* Check if the current driver has device support */ + case UADK_ALG_HW: + ret = wd_check_accel_dev(dev_name); + break; + } + + return ret; +} + +static bool wd_alg_driver_match(struct wd_alg_driver *drv, + struct wd_alg_list *node) +{ + if (strcmp(drv->alg_name, node->alg_name)) + return false; + + if (strcmp(drv->drv_name, node->drv_name)) + return false; + + if (drv->priority != node->priority) + return false; + + if (drv->calc_type != node->calc_type) + return false; + + return true; +} + int wd_alg_driver_register(struct wd_alg_driver *drv) { struct wd_alg_list *new_alg; @@ -62,24 +147,18 @@ int wd_alg_driver_register(struct wd_alg_driver *drv) return -WD_ENOMEM; }
- new_alg->alg_name = drv->alg_name; - new_alg->drv_name = drv->drv_name; + strncpy(new_alg->alg_name, drv->alg_name, ALG_NAME_SIZE - 1); + strncpy(new_alg->drv_name, drv->drv_name, DEV_NAME_LEN - 1); new_alg->priority = drv->priority; + new_alg->calc_type = drv->calc_type; new_alg->drv = drv; new_alg->refcnt = 0; new_alg->next = NULL;
- if (drv->priority == UADK_ALG_HW) { - /* If not find dev, remove this driver node */ - new_alg->available = wd_check_accel_dev(drv->drv_name); - if (!new_alg->available) { - free(new_alg); - WD_ERR("failed to find alg driver's device!\n"); - return -WD_ENODEV; - } - } else { - /* Should find the CPU if not support SVE or CE */ - new_alg->available = true; + new_alg->available = wd_alg_check_available(drv->calc_type, drv->drv_name); + if (!new_alg->available) { + free(new_alg); + return -WD_ENODEV; }
pthread_mutex_lock(&mutex); @@ -101,11 +180,8 @@ void wd_alg_driver_unregister(struct wd_alg_driver *drv)
pthread_mutex_lock(&mutex); while (pnext) { - if (!strcmp(drv->alg_name, pnext->alg_name) && - !strcmp(drv->drv_name, pnext->drv_name) && - drv->priority == pnext->priority) { + if (wd_alg_driver_match(drv, pnext)) break; - } npre = pnext; pnext = pnext->next; } @@ -160,21 +236,12 @@ void wd_enable_drv(struct wd_alg_driver *drv)
pthread_mutex_lock(&mutex); while (pnext) { - if (!strcmp(drv->alg_name, pnext->alg_name) && - !strcmp(drv->drv_name, pnext->drv_name) && - drv->priority == pnext->priority) { + if (wd_alg_driver_match(drv, pnext)) break; - } pnext = pnext->next; }
- if (drv->priority == UADK_ALG_HW) { - /* If not find dev, remove this driver node */ - pnext->available = wd_check_accel_dev(drv->drv_name); - } else { - /* Should find the CPU if not support SVE or CE */ - pnext->available = true; - } + pnext->available = wd_alg_check_available(drv->calc_type, drv->drv_name); pthread_mutex_unlock(&mutex); }
@@ -188,11 +255,8 @@ void wd_disable_drv(struct wd_alg_driver *drv)
pthread_mutex_lock(&mutex); while (pnext) { - if (!strcmp(drv->alg_name, pnext->alg_name) && - !strcmp(drv->drv_name, pnext->drv_name) && - drv->priority == pnext->priority) { + if (wd_alg_driver_match(drv, pnext) && pnext->available) break; - } pnext = pnext->next; }
@@ -217,7 +281,7 @@ struct wd_alg_driver *wd_request_drv(const char *alg_name, bool hw_mask) pthread_mutex_lock(&mutex); while (pnext) { /* hw_mask true mean not to used hardware dev */ - if (hw_mask && pnext->drv->priority == UADK_ALG_HW) { + if (hw_mask && pnext->drv->calc_type == UADK_ALG_HW) { pnext = pnext->next; continue; } @@ -249,17 +313,14 @@ void wd_release_drv(struct wd_alg_driver *drv)
pthread_mutex_lock(&mutex); while (pnext) { - if (!strcmp(drv->alg_name, pnext->alg_name) && - !strcmp(drv->drv_name, pnext->drv_name) && - drv->priority == pnext->priority) { + if (wd_alg_driver_match(drv, pnext) && pnext->refcnt > 0) { select_node = pnext; break; } pnext = pnext->next; }
- if (select_node && select_node->refcnt > 0) + if (select_node) select_node->refcnt--; pthread_mutex_unlock(&mutex); } -
Fix the problem that some driver codes in uadk cause the driver to fail to load. In addition, solve the framework code for obtaining the current registration algorithm in the external interface.
Signed-off-by: Longfang Liu liulongfang@huawei.com --- include/wd.h | 6 ++++++ wd.c | 18 +++++++++--------- wd_util.c | 21 ++++++++++++++++----- 3 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/include/wd.h b/include/wd.h index 1011817..0e67cad 100644 --- a/include/wd.h +++ b/include/wd.h @@ -584,11 +584,17 @@ bool wd_need_info(void); struct wd_capability { char alg_name[CRYPTO_MAX_ALG_NAME]; char drv_name[CRYPTO_MAX_ALG_NAME]; + bool available; int priority; + int calc_type;
struct wd_capability *next; };
+/** + * wd_get_alg_cap() - Get the algorithm information supported + * in the current system. + */ struct wd_capability *wd_get_alg_cap(void); void wd_release_alg_cap(struct wd_capability *head);
diff --git a/wd.c b/wd.c index 6f61f11..ddde38d 100644 --- a/wd.c +++ b/wd.c @@ -931,7 +931,7 @@ char *wd_ctx_get_dev_name(handle_t h_ctx) void wd_release_alg_cap(struct wd_capability *head) { struct wd_capability *cap_pnext = head; - struct wd_capability *cap_node = NULL; + struct wd_capability *cap_node;
while (cap_pnext) { cap_node = cap_pnext; @@ -948,30 +948,30 @@ struct wd_capability *wd_get_alg_cap(void) struct wd_alg_list *head = wd_get_alg_head(); struct wd_alg_list *pnext = head->next; struct wd_capability *cap_head = NULL; - struct wd_capability *cap_node = NULL; struct wd_capability *cap_pnext = NULL; - int i = 0; + struct wd_capability *cap_node;
while (pnext) { cap_node = calloc(1, sizeof(struct wd_capability)); - if (!cap_head) { + if (!cap_node) { WD_ERR("fail to alloc wd capability head\n"); goto alloc_err; }
strcpy(cap_node->alg_name, pnext->alg_name); strcpy(cap_node->drv_name, pnext->drv_name); + cap_node->available = pnext->available; cap_node->priority = pnext->priority; + cap_node->calc_type = pnext->calc_type; cap_node->next = NULL;
- cap_pnext->next = cap_node; - cap_pnext = cap_node; pnext = pnext->next; - if (i == 0) { + if (!cap_pnext) { cap_head = cap_node; - cap_pnext = cap_head; + cap_pnext = cap_node; } - i++; + cap_pnext->next = cap_node; + cap_pnext = cap_node; }
return cap_head; diff --git a/wd_util.c b/wd_util.c index 121b6d5..74505a0 100644 --- a/wd_util.c +++ b/wd_util.c @@ -90,7 +90,7 @@ struct acc_alg_item { };
static struct acc_alg_item alg_options[] = { - {"zlib", "zlib-deflate"}, + {"zlib", "zlib"}, {"gzip", "gzip"}, {"deflate", "deflate"}, {"lz77_zstd", "lz77_zstd"}, @@ -142,6 +142,10 @@ static struct acc_alg_item alg_options[] = { {"sha512", "digest"}, {"sha512-224", "digest"}, {"sha512-256", "digest"}, + {"cmac(aes)", "digest"}, + {"gmac(aes)", "digest"}, + {"xcbc-mac-96(aes)", "digest"}, + {"xcbc-prf-128(aes)", "digest"}, {"", ""} };
@@ -1962,7 +1966,7 @@ void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
driver->exit(priv); /* Ctx config just need clear once */ - if (driver->priority == UADK_ALG_HW) + if (driver->calc_type == UADK_ALG_HW) wd_clear_ctx_config(config);
if (driver->fallback) @@ -1970,7 +1974,7 @@ void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
if (priv) { free(priv); - priv = NULL; + *drv_priv = NULL; } }
@@ -2176,7 +2180,7 @@ int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir) len = strlen(file_path) - 1; for (i = len; i >= 0; i--) { if (file_path[i] == '/') { - memset(&file_path[i], 0, PATH_MAX - i + 1); + memset(&file_path[i], 0, PATH_MAX - i); break; } } @@ -2312,6 +2316,9 @@ struct wd_alg_driver *wd_alg_drv_bind(int task_type, char *alg_name) } } break; + default: + WD_ERR("task type error.\n"); + return NULL; }
return set_driver; @@ -2623,7 +2630,7 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs) return -WD_EINVAL;
if (attrs->driver) - driver_type = attrs->driver->priority; + driver_type = attrs->driver->calc_type;
switch (driver_type) { case UADK_ALG_SOFT: @@ -2692,6 +2699,10 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs) ret = alg_init_func(ctx_config, alg_sched); if (ret) goto out_pre_init; + break; + default: + WD_ERR("driver type error: %d\n", driver_type); + return -WD_EINVAL; }
return 0;
From: Hao Fang fanghao11@huawei.com
1.avoid using 'goto' up for flow control label. 2.fix typo: than -> then. 3.optimize the uninit process. 4.rm the authenc(hmac(sha256),cbc(sm4)) driver register. 5.repair the algorithm whitelist verification function of the cipher interface layer.
Signed-off-by: Hao Fang fanghao11@huawei.com --- drv/hisi_sec.c | 1 - wd_aead.c | 102 +++++++++++++++++------------------ wd_cipher.c | 141 +++++++++++++++++++++++++++++-------------------- wd_digest.c | 104 +++++++++++++++++------------------- 4 files changed, 180 insertions(+), 168 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index 89d113d..0715c55 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -604,7 +604,6 @@ static struct wd_alg_driver aead_alg_driver[] = { GEN_SEC_ALG_DRIVER("authenc(hmac(sha256),cbc(aes))"), GEN_SEC_ALG_DRIVER("ccm(sm4)"), GEN_SEC_ALG_DRIVER("gcm(sm4)"), - GEN_SEC_ALG_DRIVER("authenc(hmac(sha256),cbc(sm4))"), };
static void dump_sec_msg(void *msg, const char *alg) diff --git a/wd_aead.c b/wd_aead.c index 85acf5d..d9969f9 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -89,13 +89,6 @@ static int wd_aead_open_driver(void) char lib_path[PATH_MAX]; int ret;
- /* - * Compatible with the normal acquisition of device - * drivers in the init interface - */ - if (wd_aead_setting.dlh_list) - return 0; - ret = wd_get_lib_file_path("libhisi_sec.so", lib_path, false); if (ret) return ret; @@ -340,7 +333,6 @@ err_sess: free(sess->sched_key); free(sess); return (handle_t)0; - }
void wd_aead_free_sess(handle_t h_sess) @@ -497,19 +489,18 @@ out_clear_init:
static void wd_aead_uninit_nolock(void) { - void *priv = wd_aead_setting.priv; - - if (!priv) - return; - wd_uninit_async_request_pool(&wd_aead_setting.pool); wd_clear_sched(&wd_aead_setting.sched); wd_alg_uninit_driver(&wd_aead_setting.config, - wd_aead_setting.driver, &priv); + wd_aead_setting.driver, + &wd_aead_setting.priv); }
void wd_aead_uninit(void) { + if (!wd_aead_setting.priv) + return; + wd_aead_uninit_nolock(); wd_aead_close_driver(); wd_alg_clear_init(&wd_aead_setting.status); @@ -534,7 +525,7 @@ int wd_aead_init2_(char *alg, __u32 sched_type, int task_type, { struct wd_ctx_nums aead_ctx_num[WD_DIGEST_CIPHER_DECRYPTION + 1] = {0}; struct wd_ctx_params aead_ctx_params = {0}; - int ret = 0; + int ret = -WD_EINVAL; bool flag;
pthread_atfork(NULL, NULL, wd_aead_clear_status); @@ -546,69 +537,66 @@ int wd_aead_init2_(char *alg, __u32 sched_type, int task_type, 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; }
if (!wd_aead_algs_check(alg)) { WD_ERR("invalid: aead:%s unsupported!\n", alg); - ret = -WD_EINVAL; goto out_uninit; }
/* * Driver lib file path could set by env param. - * than open them by wd_dlopen_drv() + * then open them by wd_dlopen_drv() * use NULL means dynamic query path */ wd_aead_setting.dlh_list = wd_dlopen_drv(NULL); if (!wd_aead_setting.dlh_list) { - WD_ERR("fail to open driver lib files.\n"); + WD_ERR("failed to open driver lib files.\n"); goto out_uninit; }
-res_retry: - memset(&wd_aead_setting.config, 0, sizeof(struct wd_ctx_config_internal)); + while (ret != 0) { + memset(&wd_aead_setting.config, 0, sizeof(struct wd_ctx_config_internal));
- /* Get alg driver and dev name */ - wd_aead_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_aead_setting.driver) { - WD_ERR("fail to bind a valid driver.\n"); - ret = -WD_EINVAL; - goto out_dlopen; - } + /* Get alg driver and dev name */ + wd_aead_setting.driver = wd_alg_drv_bind(task_type, alg); + if (!wd_aead_setting.driver) { + WD_ERR("failed to bind %s driver.\n", alg); + goto out_dlopen; + }
- aead_ctx_params.ctx_set_num = aead_ctx_num; - ret = wd_ctx_param_init(&aead_ctx_params, ctx_params, - wd_aead_setting.driver, WD_AEAD_TYPE, - WD_DIGEST_CIPHER_DECRYPTION + 1); - if (ret) { - if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_aead_setting.driver); - wd_alg_drv_unbind(wd_aead_setting.driver); - goto res_retry; + aead_ctx_params.ctx_set_num = aead_ctx_num; + ret = wd_ctx_param_init(&aead_ctx_params, ctx_params, + wd_aead_setting.driver, WD_AEAD_TYPE, + WD_DIGEST_CIPHER_DECRYPTION + 1); + if (ret) { + if (ret == -WD_EAGAIN) { + wd_disable_drv(wd_aead_setting.driver); + wd_alg_drv_unbind(wd_aead_setting.driver); + continue; + } + goto out_driver; } - goto out_driver; - }
- wd_aead_init_attrs.alg = alg; - wd_aead_init_attrs.sched_type = sched_type; - wd_aead_init_attrs.driver = wd_aead_setting.driver; - wd_aead_init_attrs.ctx_params = &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) { - if (ret == -WD_ENODEV) { - wd_disable_drv(wd_aead_setting.driver); - wd_alg_drv_unbind(wd_aead_setting.driver); - wd_ctx_param_uninit(&aead_ctx_params); - goto res_retry; + wd_aead_init_attrs.alg = alg; + wd_aead_init_attrs.sched_type = sched_type; + wd_aead_init_attrs.driver = wd_aead_setting.driver; + wd_aead_init_attrs.ctx_params = &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) { + if (ret == -WD_ENODEV) { + wd_disable_drv(wd_aead_setting.driver); + wd_alg_drv_unbind(wd_aead_setting.driver); + wd_ctx_param_uninit(&aead_ctx_params); + continue; + } + WD_ERR("failed to init alg attrs.\n"); + goto out_params_uninit; } - WD_ERR("fail to init alg attrs.\n"); - goto out_params_uninit; } - wd_alg_set_init(&wd_aead_setting.status); wd_ctx_param_uninit(&aead_ctx_params);
@@ -627,6 +615,9 @@ out_uninit:
void wd_aead_uninit2(void) { + if (!wd_aead_setting.priv) + return; + wd_aead_uninit_nolock(); wd_alg_attrs_uninit(&wd_aead_init_attrs); wd_alg_drv_unbind(wd_aead_setting.driver); @@ -713,6 +704,7 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL, wd_aead_setting.config.epoll_en); pthread_spin_unlock(&ctx->lock); + return ret; }
diff --git a/wd_cipher.c b/wd_cipher.c index a8fbecb..85c32c1 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -49,14 +49,14 @@ static char *wd_cipher_alg_name[WD_CIPHER_ALG_TYPE_MAX][WD_CIPHER_MODE_TYPE_MAX] "cfb(sm4)", "cbc-cs1(sm4)", "cbc-cs2(sm4)", "cbc-cs3(sm4)"}, {"ecb(aes)", "cbc(aes)", "ctr(aes)", "xts(aes)", "ofb(aes)", "cfb(aes)", "cbc-cs1(aes)", "cbc-cs2(aes)", "cbc-cs3(aes)"}, - {"cbc(des)", "ecb(des)",}, - {"cbc(des3_ede)", "ecb(des3_ede)",} + {"ecb(des)", "cbc(des)",}, + {"ecb(des3_ede)", "cbc(des3_ede)",} };
struct wd_cipher_setting { enum wd_status status; struct wd_ctx_config_internal config; - struct wd_sched sched; + struct wd_sched sched; struct wd_async_msg_pool pool; struct wd_alg_driver *driver; void *priv; @@ -95,13 +95,6 @@ static int wd_cipher_open_driver(void) char lib_path[PATH_MAX]; int ret;
- /* - * Compatible with the normal acquisition of device - * drivers in the init interface - */ - if (wd_cipher_setting.dlh_list) - return 0; - ret = wd_get_lib_file_path("libhisi_sec.so", lib_path, false); if (ret) return ret; @@ -181,6 +174,24 @@ static int cipher_key_len_check(struct wd_cipher_sess *sess, __u32 length) return ret; }
+static bool wd_cipher_alg_check(const char *alg_name) +{ + int i, j; + + for (i = 0; i < WD_CIPHER_ALG_TYPE_MAX; i++) { + for (j = 0; j < WD_CIPHER_MODE_TYPE_MAX; j++) { + /* Some algorithms do not support all modes */ + if (!wd_cipher_alg_name[i][j] || + !strlen(wd_cipher_alg_name[i][j])) + continue; + if (!strcmp(alg_name, wd_cipher_alg_name[i][j])) + return true; + } + } + + return false; +} + int wd_cipher_set_key(handle_t h_sess, const __u8 *key, __u32 key_len) { struct wd_cipher_sess *sess = (struct wd_cipher_sess *)h_sess; @@ -231,8 +242,9 @@ handle_t wd_cipher_alloc_sess(struct wd_cipher_sess_setup *setup) if (setup->alg >= WD_CIPHER_ALG_TYPE_MAX || setup->mode >= WD_CIPHER_MODE_TYPE_MAX) { WD_ERR("failed to check algorithm!\n"); - return (handle_t)0; + goto err_sess; } + sess->alg_name = wd_cipher_alg_name[setup->alg][setup->mode]; sess->alg = setup->alg; sess->mode = setup->mode; @@ -322,12 +334,12 @@ out_clear_ctx_config: return ret; }
-static void wd_cipher_common_uninit(void) +static int wd_cipher_common_uninit(void) { void *priv = wd_cipher_setting.priv;
if (!priv) - return; + return -WD_EINVAL;
/* uninit async request pool */ wd_uninit_async_request_pool(&wd_cipher_setting.pool); @@ -336,7 +348,10 @@ static void wd_cipher_common_uninit(void) wd_clear_sched(&wd_cipher_setting.sched);
wd_alg_uninit_driver(&wd_cipher_setting.config, - wd_cipher_setting.driver, &priv); + wd_cipher_setting.driver, + &wd_cipher_setting.priv); + + return 0; }
int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched) @@ -375,7 +390,11 @@ out_clear_init:
void wd_cipher_uninit(void) { - wd_cipher_common_uninit(); + int ret; + + ret = wd_cipher_common_uninit(); + if (ret) + return;
wd_cipher_close_driver(); wd_alg_clear_init(&wd_cipher_setting.status); @@ -385,7 +404,7 @@ 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}; - int ret = 0; + int ret = -WD_EINVAL; bool flag;
pthread_atfork(NULL, NULL, wd_cipher_clear_status); @@ -394,16 +413,21 @@ int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_p if (!flag) return -WD_EEXIST;
- if (!alg || sched_type > SCHED_POLICY_BUTT || - task_type < 0 || task_type > TASK_MAX_TYPE) { + 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; + } + + flag = wd_cipher_alg_check(alg); + if (!flag) { + WD_ERR("invalid: cipher:%s unsupported!\n", alg); goto out_uninit; }
/* * Driver lib file path could set by env param. - * than open tham by wd_dlopen_drv() + * then open tham by wd_dlopen_drv() * use NULL means dynamic query path */ wd_cipher_setting.dlh_list = wd_dlopen_drv(NULL); @@ -412,46 +436,46 @@ int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_p goto out_uninit; }
-res_retry: - memset(&wd_cipher_setting.config, 0, sizeof(struct wd_ctx_config_internal)); + while (ret != 0) { + memset(&wd_cipher_setting.config, 0, sizeof(struct wd_ctx_config_internal));
- /* Get alg driver and dev name */ - wd_cipher_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_cipher_setting.driver) { - WD_ERR("fail to bind a valid driver.\n"); - ret = -WD_EINVAL; - goto out_dlopen; - } + /* Get alg driver and dev name */ + wd_cipher_setting.driver = wd_alg_drv_bind(task_type, alg); + if (!wd_cipher_setting.driver) { + WD_ERR("failed to bind %s driver.\n", alg); + goto out_dlopen; + }
- cipher_ctx_params.ctx_set_num = cipher_ctx_num; - ret = wd_ctx_param_init(&cipher_ctx_params, ctx_params, - wd_cipher_setting.driver, - WD_CIPHER_TYPE, WD_CIPHER_DECRYPTION + 1); - if (ret) { - if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_cipher_setting.driver); - wd_alg_drv_unbind(wd_cipher_setting.driver); - goto res_retry; + cipher_ctx_params.ctx_set_num = cipher_ctx_num; + ret = wd_ctx_param_init(&cipher_ctx_params, ctx_params, + wd_cipher_setting.driver, + WD_CIPHER_TYPE, WD_CIPHER_DECRYPTION + 1); + if (ret) { + if (ret == -WD_EAGAIN) { + wd_disable_drv(wd_cipher_setting.driver); + wd_alg_drv_unbind(wd_cipher_setting.driver); + continue; + } + goto out_driver; } - goto out_driver; - }
- wd_cipher_init_attrs.alg = alg; - wd_cipher_init_attrs.sched_type = sched_type; - wd_cipher_init_attrs.driver = wd_cipher_setting.driver; - wd_cipher_init_attrs.ctx_params = &cipher_ctx_params; - wd_cipher_init_attrs.alg_init = wd_cipher_common_init; - wd_cipher_init_attrs.alg_poll_ctx = wd_cipher_poll_ctx; - ret = wd_alg_attrs_init(&wd_cipher_init_attrs); - if (ret) { - if (ret == -WD_ENODEV) { - wd_disable_drv(wd_cipher_setting.driver); - wd_alg_drv_unbind(wd_cipher_setting.driver); - wd_ctx_param_uninit(&cipher_ctx_params); - goto res_retry; + wd_cipher_init_attrs.alg = alg; + wd_cipher_init_attrs.sched_type = sched_type; + wd_cipher_init_attrs.driver = wd_cipher_setting.driver; + wd_cipher_init_attrs.ctx_params = &cipher_ctx_params; + wd_cipher_init_attrs.alg_init = wd_cipher_common_init; + wd_cipher_init_attrs.alg_poll_ctx = wd_cipher_poll_ctx; + ret = wd_alg_attrs_init(&wd_cipher_init_attrs); + if (ret) { + if (ret == -WD_ENODEV) { + wd_disable_drv(wd_cipher_setting.driver); + wd_alg_drv_unbind(wd_cipher_setting.driver); + wd_ctx_param_uninit(&cipher_ctx_params); + continue; + } + WD_ERR("fail to init alg attrs.\n"); + goto out_params_uninit; } - WD_ERR("fail to init alg attrs.\n"); - goto out_params_uninit; }
wd_alg_set_init(&wd_cipher_setting.status); @@ -472,7 +496,11 @@ out_uninit:
void wd_cipher_uninit2(void) { - wd_cipher_common_uninit(); + int ret; + + ret = wd_cipher_common_uninit(); + if (ret) + return;
wd_alg_attrs_uninit(&wd_cipher_init_attrs); wd_alg_drv_unbind(wd_cipher_setting.driver); @@ -591,6 +619,7 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL, wd_cipher_setting.config.epoll_en); pthread_spin_unlock(&ctx->lock); + return ret; }
diff --git a/wd_digest.c b/wd_digest.c index 73f44e5..5370f45 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -48,8 +48,8 @@ static char *wd_digest_alg_name[WD_DIGEST_TYPE_MAX] = { struct wd_digest_setting { enum wd_status status; struct wd_ctx_config_internal config; - struct wd_sched sched; - struct wd_alg_driver *driver; + struct wd_sched sched; + struct wd_alg_driver *driver; struct wd_async_msg_pool pool; void *priv; void *dlhandle; @@ -92,13 +92,6 @@ static int wd_digest_open_driver(void) char lib_path[PATH_MAX]; int ret;
- /* - * Compatible with the normal acquisition of device - * drivers in the init interface - */ - if (wd_digest_setting.dlh_list) - return 0; - ret = wd_get_lib_file_path("libhisi_sec.so", lib_path, false); if (ret) return ret; @@ -310,19 +303,18 @@ out_clear_init:
static void wd_digest_uninit_nolock(void) { - void *priv = wd_digest_setting.priv; - - if (!priv) - return; - wd_uninit_async_request_pool(&wd_digest_setting.pool); wd_clear_sched(&wd_digest_setting.sched); wd_alg_uninit_driver(&wd_digest_setting.config, - wd_digest_setting.driver, &priv); + wd_digest_setting.driver, + &wd_digest_setting.priv); }
void wd_digest_uninit(void) { + if (!wd_digest_setting.priv) + return; + wd_digest_uninit_nolock(); wd_digest_close_driver(); wd_alg_clear_init(&wd_digest_setting.status); @@ -343,7 +335,7 @@ int wd_digest_init2_(char *alg, __u32 sched_type, int task_type, { struct wd_ctx_params digest_ctx_params = {0}; struct wd_ctx_nums digest_ctx_num = {0}; - int ret = 0; + int ret = -WD_EINVAL; bool flag;
pthread_atfork(NULL, NULL, wd_digest_clear_status); @@ -355,67 +347,64 @@ int wd_digest_init2_(char *alg, __u32 sched_type, int task_type, 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; }
if (!wd_digest_algs_check(alg)) { WD_ERR("invalid: digest:%s unsupported!\n", alg); - ret = -WD_EINVAL; goto out_uninit; } /* * Driver lib file path could set by env param. - * than open them by wd_dlopen_drv() + * then open them by wd_dlopen_drv() * use NULL means dynamic query path */ wd_digest_setting.dlh_list = wd_dlopen_drv(NULL); if (!wd_digest_setting.dlh_list) { - WD_ERR("fail to open driver lib files.\n"); + WD_ERR("failed to open driver lib files.\n"); goto out_uninit; }
-res_retry: - memset(&wd_digest_setting.config, 0, sizeof(struct wd_ctx_config_internal)); + while (ret != 0) { + memset(&wd_digest_setting.config, 0, sizeof(struct wd_ctx_config_internal));
- /* Get alg driver and dev name */ - wd_digest_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_digest_setting.driver) { - WD_ERR("fail to bind a valid driver.\n"); - ret = -WD_EINVAL; - goto out_dlopen; - } + /* Get alg driver and dev name */ + wd_digest_setting.driver = wd_alg_drv_bind(task_type, alg); + if (!wd_digest_setting.driver) { + WD_ERR("failed to bind %s driver.\n", alg); + goto out_dlopen; + }
- digest_ctx_params.ctx_set_num = &digest_ctx_num; - ret = wd_ctx_param_init(&digest_ctx_params, ctx_params, - wd_digest_setting.driver, WD_DIGEST_TYPE, 1); - if (ret) { - if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_digest_setting.driver); - wd_alg_drv_unbind(wd_digest_setting.driver); - goto res_retry; + digest_ctx_params.ctx_set_num = &digest_ctx_num; + ret = wd_ctx_param_init(&digest_ctx_params, ctx_params, + wd_digest_setting.driver, WD_DIGEST_TYPE, 1); + if (ret) { + if (ret == -WD_EAGAIN) { + wd_disable_drv(wd_digest_setting.driver); + wd_alg_drv_unbind(wd_digest_setting.driver); + continue; + } + goto out_driver; } - goto out_driver; - } - - wd_digest_init_attrs.alg = alg; - wd_digest_init_attrs.sched_type = sched_type; - wd_digest_init_attrs.driver = wd_digest_setting.driver; - wd_digest_init_attrs.ctx_params = &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) { - if (ret == -WD_ENODEV) { - wd_disable_drv(wd_digest_setting.driver); - wd_alg_drv_unbind(wd_digest_setting.driver); - wd_ctx_param_uninit(&digest_ctx_params); - goto res_retry; + + wd_digest_init_attrs.alg = alg; + wd_digest_init_attrs.sched_type = sched_type; + wd_digest_init_attrs.driver = wd_digest_setting.driver; + wd_digest_init_attrs.ctx_params = &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) { + if (ret == -WD_ENODEV) { + wd_disable_drv(wd_digest_setting.driver); + wd_alg_drv_unbind(wd_digest_setting.driver); + wd_ctx_param_uninit(&digest_ctx_params); + continue; + } + WD_ERR("failed to init alg attrs.\n"); + goto out_params_uninit; } - WD_ERR("fail to init alg attrs.\n"); - goto out_params_uninit; } - wd_alg_set_init(&wd_digest_setting.status); wd_ctx_param_uninit(&digest_ctx_params);
@@ -434,6 +423,9 @@ out_uninit:
void wd_digest_uninit2(void) { + if (!wd_digest_setting.priv) + return; + wd_digest_uninit_nolock(); wd_alg_attrs_uninit(&wd_digest_init_attrs); wd_alg_drv_unbind(wd_digest_setting.driver);
1.update the registration attribute of the driver of the hpre device. 2.update the driver registration properties of the zip device 3.update the driver registration properties of the sec device
Signed-off-by: Longfang Liu liulongfang@huawei.com --- drv/hisi_comp.c | 9 +++++---- drv/hisi_hpre.c | 52 +++++++++++++++++++++++++++++++------------------ drv/hisi_sec.c | 25 ++++++++++++------------ 3 files changed, 51 insertions(+), 35 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c index 26df469..b6f4d19 100644 --- a/drv/hisi_comp.c +++ b/drv/hisi_comp.c @@ -1060,8 +1060,9 @@ static int hisi_zip_comp_recv(handle_t ctx, void *comp_msg) #define GEN_ZIP_ALG_DRIVER(zip_alg_name) \ {\ .drv_name = "hisi_zip",\ - .alg_name = zip_alg_name,\ - .priority = UADK_ALG_HW,\ + .alg_name = (zip_alg_name),\ + .calc_type = UADK_ALG_HW,\ + .priority = 100,\ .priv_size = sizeof(struct hisi_zip_ctx),\ .queue_num = ZIP_CTX_Q_NUM_DEF,\ .op_type_num = 2,\ @@ -1089,7 +1090,7 @@ static void __attribute__((constructor)) hisi_zip_probe(void)
for (i = 0; i < alg_num; i++) { ret = wd_alg_driver_register(&zip_alg_driver[i]); - if (ret) + if (ret && ret != -WD_ENODEV) WD_ERR("Error: register ZIP %s failed!\n", zip_alg_driver[i].alg_name); } @@ -1100,7 +1101,7 @@ static void __attribute__((destructor)) hisi_zip_remove(void) int alg_num = ARRAY_SIZE(zip_alg_driver); int i;
+ WD_INFO("Info: unregister ZIP alg drivers!\n"); for (i = 0; i < alg_num; i++) wd_alg_driver_unregister(&zip_alg_driver[i]); } - diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index b9be464..15cadbe 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -2438,11 +2438,17 @@ static int ecc_recv(handle_t ctx, void *ecc_msg) return ecc_sqe_parse((struct hisi_qp *)h_qp, msg, &hw_msg); }
-#define GEN_HPRE_ECC_DRIVER(hpre_alg_name) \ +static int hpre_get_usage(void *param) +{ + return 0; +} + +#define GEN_HPRE_ALG_DRIVER(hpre_alg_name) \ {\ .drv_name = "hisi_hpre",\ - .alg_name = hpre_alg_name,\ - .priority = UADK_ALG_HW,\ + .alg_name = (hpre_alg_name),\ + .calc_type = UADK_ALG_HW,\ + .priority = 100,\ .priv_size = sizeof(struct hisi_hpre_ctx),\ .queue_num = HPRE_CTX_Q_NUM_DEF,\ .op_type_num = 1,\ @@ -2451,20 +2457,22 @@ static int ecc_recv(handle_t ctx, void *ecc_msg) .exit = hpre_exit,\ .send = ecc_send,\ .recv = ecc_recv,\ + .get_usage = hpre_get_usage,\ }
static struct wd_alg_driver hpre_ecc_driver[] = { - GEN_HPRE_ECC_DRIVER("sm2"), - GEN_HPRE_ECC_DRIVER("ecdh"), - GEN_HPRE_ECC_DRIVER("ecdsa"), - GEN_HPRE_ECC_DRIVER("x25519"), - GEN_HPRE_ECC_DRIVER("x448"), + GEN_HPRE_ALG_DRIVER("sm2"), + GEN_HPRE_ALG_DRIVER("ecdh"), + GEN_HPRE_ALG_DRIVER("ecdsa"), + GEN_HPRE_ALG_DRIVER("x25519"), + GEN_HPRE_ALG_DRIVER("x448"), };
static struct wd_alg_driver hpre_rsa_driver = { .drv_name = "hisi_hpre", .alg_name = "rsa", - .priority = UADK_ALG_HW, + .calc_type = UADK_ALG_HW, + .priority = 100, .priv_size = sizeof(struct hisi_hpre_ctx), .queue_num = HPRE_CTX_Q_NUM_DEF, .op_type_num = 1, @@ -2473,12 +2481,14 @@ static struct wd_alg_driver hpre_rsa_driver = { .exit = hpre_exit, .send = rsa_send, .recv = rsa_recv, + .get_usage = hpre_get_usage, };
static struct wd_alg_driver hpre_dh_driver = { .drv_name = "hisi_hpre", .alg_name = "dh", - .priority = UADK_ALG_HW, + .calc_type = UADK_ALG_HW, + .priority = 100, .priv_size = sizeof(struct hisi_hpre_ctx), .queue_num = HPRE_CTX_Q_NUM_DEF, .op_type_num = 1, @@ -2487,37 +2497,41 @@ static struct wd_alg_driver hpre_dh_driver = { .exit = hpre_exit, .send = dh_send, .recv = dh_recv, + .get_usage = hpre_get_usage, }; + static void __attribute__((constructor)) hisi_hpre_probe(void) { - int alg_num = ARRAY_SIZE(hpre_ecc_driver); - int i, ret; + __u32 alg_num = ARRAY_SIZE(hpre_ecc_driver); + __u32 i; + int ret;
WD_INFO("Info: register HPRE alg drivers!\n"); - ret = wd_alg_driver_register(&hpre_rsa_driver); - if (ret) + if (ret && ret != -WD_ENODEV) WD_ERR("failed to register HPRE rsa driver!\n");
ret = wd_alg_driver_register(&hpre_dh_driver); - if (ret) - WD_ERR("failed to register HPRE dh driver!\n"); + if (ret && ret != -WD_ENODEV) + WD_ERR("failed to register HPRE rsa driver!\n");
for (i = 0; i < alg_num; i++) { ret = wd_alg_driver_register(&hpre_ecc_driver[i]); - if (ret) + if (ret && ret != -WD_ENODEV) WD_ERR("failed to register HPRE %s driver!\n", hpre_ecc_driver[i].alg_name); } }
static void __attribute__((destructor)) hisi_hpre_remove(void) { - int alg_num = ARRAY_SIZE(hpre_ecc_driver); - int i; + __u32 alg_num = ARRAY_SIZE(hpre_ecc_driver); + __u32 i;
+ WD_INFO("Info: unregister HPRE alg drivers!\n"); for (i = 0; i < alg_num; i++) wd_alg_driver_unregister(&hpre_ecc_driver[i]);
wd_alg_driver_unregister(&hpre_dh_driver); + wd_alg_driver_unregister(&hpre_rsa_driver); } diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index 0715c55..e6589a0 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -534,8 +534,8 @@ static __u32 g_sec_hmac_full_len[WD_DIGEST_TYPE_MAX] = { SEC_HMAC_SHA512_MAC_LEN, SEC_HMAC_SHA512_224_MAC_LEN, SEC_HMAC_SHA512_256_MAC_LEN };
-int hisi_sec_init(void *conf, void *priv); -void hisi_sec_exit(void *priv); +static int hisi_sec_init(void *conf, void *priv); +static void hisi_sec_exit(void *priv);
static int hisi_sec_get_usage(void *param) { @@ -545,8 +545,9 @@ static int hisi_sec_get_usage(void *param) #define GEN_SEC_ALG_DRIVER(sec_alg_name) \ {\ .drv_name = "hisi_sec2",\ - .alg_name = sec_alg_name,\ - .priority = UADK_ALG_HW,\ + .alg_name = (sec_alg_name),\ + .calc_type = UADK_ALG_HW,\ + .priority = 100,\ .priv_size = sizeof(struct hisi_sec_ctx),\ .queue_num = SEC_CTX_Q_NUM_DEF,\ .op_type_num = 1,\ @@ -3020,7 +3021,7 @@ static void hisi_sec_driver_adapter(struct hisi_qp *qp) } }
-int hisi_sec_init(void *conf, void *priv) +static int hisi_sec_init(void *conf, void *priv) { struct wd_ctx_config_internal *config = conf; struct hisi_sec_ctx *sec_ctx = priv; @@ -3063,15 +3064,15 @@ out: return -WD_EINVAL; }
-void hisi_sec_exit(void *priv) +static void hisi_sec_exit(void *priv) { struct hisi_sec_ctx *sec_ctx = priv; struct wd_ctx_config_internal *config; handle_t h_qp; __u32 i;
- if (!sec_ctx) { - WD_ERR("hisi sec exit input parameter is err!\n"); + if (!priv) { + WD_ERR("invalid: input parameter is NULL!\n"); return; }
@@ -3092,7 +3093,7 @@ static void __attribute__((constructor)) hisi_sec2_probe(void) alg_num = ARRAY_SIZE(cipher_alg_driver); for (i = 0; i < alg_num; i++) { ret = wd_alg_driver_register(&cipher_alg_driver[i]); - if (ret) + if (ret && ret != -WD_ENODEV) WD_ERR("Error: register SEC %s failed!\n", cipher_alg_driver[i].alg_name); } @@ -3100,7 +3101,7 @@ static void __attribute__((constructor)) hisi_sec2_probe(void) alg_num = ARRAY_SIZE(digest_alg_driver); for (i = 0; i < alg_num; i++) { ret = wd_alg_driver_register(&digest_alg_driver[i]); - if (ret) + if (ret && ret != -WD_ENODEV) WD_ERR("Error: register SEC %s failed!\n", digest_alg_driver[i].alg_name); } @@ -3108,7 +3109,7 @@ static void __attribute__((constructor)) hisi_sec2_probe(void) alg_num = ARRAY_SIZE(aead_alg_driver); for (i = 0; i < alg_num; i++) { ret = wd_alg_driver_register(&aead_alg_driver[i]); - if (ret) + if (ret && ret != -WD_ENODEV) WD_ERR("Error: register SEC %s failed!\n", aead_alg_driver[i].alg_name); } @@ -3119,6 +3120,7 @@ static void __attribute__((destructor)) hisi_sec2_remove(void) int alg_num; int i;
+ WD_INFO("Info: unregister SEC alg drivers!\n"); alg_num = ARRAY_SIZE(cipher_alg_driver); for (i = 0; i < alg_num; i++) wd_alg_driver_unregister(&cipher_alg_driver[i]); @@ -3131,4 +3133,3 @@ static void __attribute__((destructor)) hisi_sec2_remove(void) for (i = 0; i < alg_num; i++) wd_alg_driver_unregister(&aead_alg_driver[i]); } -