Projects
Eulaceura:Factory
libwd
_service:obs_scm:0052-uadk-modify-uadk-static-c...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:0052-uadk-modify-uadk-static-compile.patch of Package libwd
From a282605e6550b5572072f9968370fd01502a04f5 Mon Sep 17 00:00:00 2001 From: Longfang Liu <liulongfang@huawei.com> Date: Fri, 29 Mar 2024 17:04:01 +0800 Subject: [PATCH 52/52] uadk: modify uadk static compile After the UADK framework supports dynamic loading. Device drivers are all default used in the form of dynamic libraries. Static compilation requires static declaration and cannot declare unknown device drivers. Therefore, static compilation only supports HiSilicon device drivers. Signed-off-by: Longfang Liu <liulongfang@huawei.com> Signed-off-by: Qi Tao <taoqi10@huawei.com> --- drv/hisi_comp.c | 8 ++++++ drv/hisi_hpre.c | 9 ++++++ drv/hisi_sec.c | 8 ++++++ include/wd_alg.h | 26 +++++++++++++---- include/wd_alg_common.h | 17 +++++++---- wd_aead.c | 61 ++++++++++++++++++++++++++------------- wd_alg.c | 25 +++++++++++++++- wd_cipher.c | 61 ++++++++++++++++++++++++++------------- wd_comp.c | 63 ++++++++++++++++++++++++++++------------- wd_dh.c | 61 ++++++++++++++++++++++++++------------- wd_digest.c | 63 ++++++++++++++++++++++++++++------------- wd_ecc.c | 61 ++++++++++++++++++++++++++------------- wd_rsa.c | 61 ++++++++++++++++++++++++++------------- 13 files changed, 377 insertions(+), 147 deletions(-) diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c index a1af567..2fa5eff 100644 --- a/drv/hisi_comp.c +++ b/drv/hisi_comp.c @@ -1109,7 +1109,11 @@ static struct wd_alg_driver zip_alg_driver[] = { GEN_ZIP_ALG_DRIVER("lz77_zstd"), }; +#ifdef WD_STATIC_DRV +void hisi_zip_probe(void) +#else static void __attribute__((constructor)) hisi_zip_probe(void) +#endif { int alg_num = ARRAY_SIZE(zip_alg_driver); int i, ret; @@ -1124,7 +1128,11 @@ static void __attribute__((constructor)) hisi_zip_probe(void) } } +#ifdef WD_STATIC_DRV +void hisi_zip_remove(void) +#else static void __attribute__((destructor)) hisi_zip_remove(void) +#endif { int alg_num = ARRAY_SIZE(zip_alg_driver); int i; diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index babc795..68a11ae 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -1,3 +1,4 @@ + /* SPDX-License-Identifier: Apache-2.0 */ /* Copyright 2020-2021 Huawei Technologies Co.,Ltd. All rights reserved. */ @@ -2547,7 +2548,11 @@ static struct wd_alg_driver hpre_dh_driver = { .get_usage = hpre_get_usage, }; +#ifdef WD_STATIC_DRV +void hisi_hpre_probe(void) +#else static void __attribute__((constructor)) hisi_hpre_probe(void) +#endif { __u32 alg_num = ARRAY_SIZE(hpre_ecc_driver); __u32 i; @@ -2569,7 +2574,11 @@ static void __attribute__((constructor)) hisi_hpre_probe(void) } } +#ifdef WD_STATIC_DRV +void hisi_hpre_remove(void) +#else static void __attribute__((destructor)) hisi_hpre_remove(void) +#endif { __u32 alg_num = ARRAY_SIZE(hpre_ecc_driver); __u32 i; diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index b218cd8..aba4185 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -3087,7 +3087,11 @@ static void hisi_sec_exit(struct wd_alg_driver *drv) drv->priv = NULL; } +#ifdef WD_STATIC_DRV +void hisi_sec2_probe(void) +#else static void __attribute__((constructor)) hisi_sec2_probe(void) +#endif { int alg_num; int i, ret; @@ -3119,7 +3123,11 @@ static void __attribute__((constructor)) hisi_sec2_probe(void) } } +#ifdef WD_STATIC_DRV +void hisi_sec2_remove(void) +#else static void __attribute__((destructor)) hisi_sec2_remove(void) +#endif { int alg_num; int i; diff --git a/include/wd_alg.h b/include/wd_alg.h index 861b7d9..1735896 100644 --- a/include/wd_alg.h +++ b/include/wd_alg.h @@ -69,7 +69,7 @@ enum alg_dev_type { UADK_ALG_HW = 0x3 }; -/** +/* * @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 @@ -133,7 +133,7 @@ inline int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg return drv->recv(drv, ctx, msg); } -/** +/* * wd_alg_driver_register() - Register a device driver. * @wd_alg_driver: a device driver that supports an algorithm. * @@ -142,7 +142,7 @@ inline int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg 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 @@ -165,7 +165,7 @@ struct wd_alg_list { 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. @@ -175,7 +175,7 @@ struct wd_alg_list { 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. @@ -185,7 +185,7 @@ void wd_release_drv(struct wd_alg_driver *drv); 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. */ @@ -194,6 +194,20 @@ void wd_disable_drv(struct wd_alg_driver *drv); struct wd_alg_list *wd_get_alg_head(void); +#ifdef WD_STATIC_DRV +/* + * duplicate drivers will be skipped when it register to alg_list + */ +void hisi_sec2_probe(void); +void hisi_hpre_probe(void); +void hisi_zip_probe(void); + +void hisi_sec2_remove(void); +void hisi_hpre_remove(void); +void hisi_zip_remove(void); + +#endif + #ifdef __cplusplus } #endif diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h index 32b8630..1235f1d 100644 --- a/include/wd_alg_common.h +++ b/include/wd_alg_common.h @@ -55,7 +55,12 @@ enum wd_ctx_mode { CTX_MODE_MAX, }; -/** +enum wd_init_type { + WD_TYPE_V1, + WD_TYPE_V2, +}; + +/* * struct wd_ctx - Define one ctx and related type. * @ctx: The ctx itself. * @op_type: Define the operation type of this specific ctx. @@ -69,7 +74,7 @@ struct wd_ctx { __u8 ctx_mode; }; -/** +/* * struct wd_cap_config - Capabilities. * @ctx_msg_num: number of asynchronous msg pools that the user wants to allocate. * Optional, user can set ctx_msg_num based on the number of requests @@ -82,7 +87,7 @@ struct wd_cap_config { __u32 resv; }; -/** +/* * struct wd_ctx_config - Define a ctx set and its related attributes, which * will be used in the scope of current process. * @ctx_num: The ctx number in below ctx array. @@ -98,7 +103,7 @@ struct wd_ctx_config { struct wd_cap_config *cap; }; -/** +/* * struct wd_ctx_nums - Define the ctx sets numbers. * @sync_ctx_num: The ctx numbers which are used for sync mode for each * ctx sets. @@ -110,7 +115,7 @@ struct wd_ctx_nums { __u32 async_ctx_num; }; -/** +/* * struct wd_ctx_params - Define the ctx sets params which are used for init * algorithms. * @op_type_num: Used for index of ctx_set_num, the order is the same as @@ -144,7 +149,7 @@ struct wd_ctx_config_internal { unsigned long *msg_cnt; }; -/** +/* * struct wd_comp_sched - Define a scheduler. * @name: Name of this scheduler. * @sched_policy: Method for scheduler to perform scheduling diff --git a/wd_aead.c b/wd_aead.c index 57daa80..daed761 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -62,22 +62,48 @@ struct wd_aead_sess { struct wd_env_config wd_aead_env_config; static struct wd_init_attrs wd_aead_init_attrs; -static void wd_aead_close_driver(void) +static void wd_aead_close_driver(int init_type) { +#ifndef WD_STATIC_DRV + if (init_type == WD_TYPE_V2) { + wd_dlclose_drv(wd_aead_setting.dlh_list); + return; + } + if (wd_aead_setting.dlhandle) { wd_release_drv(wd_aead_setting.driver); dlclose(wd_aead_setting.dlhandle); wd_aead_setting.dlhandle = NULL; } +#else + wd_release_drv(wd_aead_setting.driver); + hisi_sec2_remove(); +#endif } -static int wd_aead_open_driver(void) +static int wd_aead_open_driver(int init_type) { struct wd_alg_driver *driver = NULL; const char *alg_name = "gcm(aes)"; +#ifndef WD_STATIC_DRV char lib_path[PATH_MAX]; int ret; + if (init_type == WD_TYPE_V2) { + /* + * Driver lib file path could set by env param. + * then open tham 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"); + return -WD_EINVAL; + } + + return WD_SUCCESS; + } + ret = wd_get_lib_file_path("libhisi_sec.so", lib_path, false); if (ret) return ret; @@ -87,17 +113,21 @@ static int wd_aead_open_driver(void) WD_ERR("failed to open libhisi_sec.so, %s\n", dlerror()); return -WD_EINVAL; } - +#else + hisi_sec2_probe(); + if (init_type == WD_TYPE_V2) + return WD_SUCCESS; +#endif driver = wd_request_drv(alg_name, false); if (!driver) { - wd_aead_close_driver(); + wd_aead_close_driver(WD_TYPE_V1); WD_ERR("failed to get %s driver support\n", alg_name); return -WD_EINVAL; } wd_aead_setting.driver = driver; - return 0; + return WD_SUCCESS; } static int aes_key_len_check(__u32 length) @@ -466,7 +496,7 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_clear_init; - ret = wd_aead_open_driver(); + ret = wd_aead_open_driver(WD_TYPE_V1); if (ret) goto out_clear_init; @@ -479,7 +509,7 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched) return 0; out_close_driver: - wd_aead_close_driver(); + wd_aead_close_driver(WD_TYPE_V1); out_clear_init: wd_alg_clear_init(&wd_aead_setting.status); return ret; @@ -509,7 +539,7 @@ void wd_aead_uninit(void) if (ret) return; - wd_aead_close_driver(); + wd_aead_close_driver(WD_TYPE_V1); wd_alg_clear_init(&wd_aead_setting.status); } @@ -551,16 +581,9 @@ int wd_aead_init2_(char *alg, __u32 sched_type, int task_type, goto out_uninit; } - /* - * Driver lib file path could set by env param. - * 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("failed to open driver lib files.\n"); + state = wd_aead_open_driver(WD_TYPE_V2); + if (state) goto out_uninit; - } while (ret != 0) { memset(&wd_aead_setting.config, 0, sizeof(struct wd_ctx_config_internal)); @@ -613,7 +636,7 @@ out_params_uninit: out_driver: wd_alg_drv_unbind(wd_aead_setting.driver); out_dlopen: - wd_dlclose_drv(wd_aead_setting.dlh_list); + wd_aead_close_driver(WD_TYPE_V2); out_uninit: wd_alg_clear_init(&wd_aead_setting.status); return ret; @@ -629,7 +652,7 @@ void wd_aead_uninit2(void) wd_alg_attrs_uninit(&wd_aead_init_attrs); wd_alg_drv_unbind(wd_aead_setting.driver); - wd_dlclose_drv(wd_aead_setting.dlh_list); + wd_aead_close_driver(WD_TYPE_V2); wd_aead_setting.dlh_list = NULL; wd_alg_clear_init(&wd_aead_setting.status); } diff --git a/wd_alg.c b/wd_alg.c index f34a407..0a15fe8 100644 --- a/wd_alg.c +++ b/wd_alg.c @@ -150,6 +150,26 @@ static bool wd_alg_driver_match(struct wd_alg_driver *drv, return true; } +static bool wd_alg_repeat_check(struct wd_alg_driver *drv) +{ + struct wd_alg_list *npre = &alg_list_head; + struct wd_alg_list *pnext = NULL; + + pthread_mutex_lock(&mutex); + pnext = npre->next; + while (pnext) { + if (wd_alg_driver_match(drv, pnext)) { + pthread_mutex_unlock(&mutex); + return true; + } + npre = pnext; + pnext = pnext->next; + } + pthread_mutex_unlock(&mutex); + + return false; +} + int wd_alg_driver_register(struct wd_alg_driver *drv) { struct wd_alg_list *new_alg; @@ -164,6 +184,9 @@ int wd_alg_driver_register(struct wd_alg_driver *drv) return -WD_EINVAL; } + if (wd_alg_repeat_check(drv)) + return 0; + new_alg = calloc(1, sizeof(struct wd_alg_list)); if (!new_alg) { WD_ERR("failed to alloc alg driver memory!\n"); @@ -238,7 +261,7 @@ bool wd_drv_alg_support(const char *alg_name, struct wd_alg_list *head = &alg_list_head; struct wd_alg_list *pnext = head->next; - if (!alg_name) + if (!alg_name || !drv) return false; while (pnext) { diff --git a/wd_cipher.c b/wd_cipher.c index 279ca8b..9b6e884 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -72,22 +72,48 @@ struct wd_cipher_sess { struct wd_env_config wd_cipher_env_config; static struct wd_init_attrs wd_cipher_init_attrs; -static void wd_cipher_close_driver(void) +static void wd_cipher_close_driver(int init_type) { +#ifndef WD_STATIC_DRV + if (init_type == WD_TYPE_V2) { + wd_dlclose_drv(wd_cipher_setting.dlh_list); + return; + } + if (wd_cipher_setting.dlhandle) { wd_release_drv(wd_cipher_setting.driver); dlclose(wd_cipher_setting.dlhandle); wd_cipher_setting.dlhandle = NULL; } +#else + wd_release_drv(wd_cipher_setting.driver); + hisi_sec2_remove(); +#endif } -static int wd_cipher_open_driver(void) +static int wd_cipher_open_driver(int init_type) { struct wd_alg_driver *driver = NULL; const char *alg_name = "cbc(aes)"; +#ifndef WD_STATIC_DRV char lib_path[PATH_MAX]; int ret; + if (init_type == WD_TYPE_V2) { + /* + * Driver lib file path could set by env param. + * then open tham by wd_dlopen_drv() + * use NULL means dynamic query path + */ + wd_cipher_setting.dlh_list = wd_dlopen_drv(NULL); + if (!wd_cipher_setting.dlh_list) { + WD_ERR("fail to open driver lib files.\n"); + return -WD_EINVAL; + } + + return WD_SUCCESS; + } + ret = wd_get_lib_file_path("libhisi_sec.so", lib_path, false); if (ret) return ret; @@ -97,17 +123,21 @@ static int wd_cipher_open_driver(void) WD_ERR("failed to open libhisi_sec.so, %s\n", dlerror()); return -WD_EINVAL; } - +#else + hisi_sec2_probe(); + if (init_type == WD_TYPE_V2) + return WD_SUCCESS; +#endif driver = wd_request_drv(alg_name, false); if (!driver) { - wd_cipher_close_driver(); + wd_cipher_close_driver(WD_TYPE_V1); WD_ERR("failed to get %s driver support\n", alg_name); return -WD_EINVAL; } wd_cipher_setting.driver = driver; - return 0; + return WD_SUCCESS; } static bool is_des_weak_key(const __u8 *key) @@ -365,7 +395,7 @@ int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_clear_init; - ret = wd_cipher_open_driver(); + ret = wd_cipher_open_driver(WD_TYPE_V1); if (ret) goto out_clear_init; @@ -378,7 +408,7 @@ int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched) return 0; out_close_driver: - wd_cipher_close_driver(); + wd_cipher_close_driver(WD_TYPE_V1); out_clear_init: wd_alg_clear_init(&wd_cipher_setting.status); return ret; @@ -392,7 +422,7 @@ void wd_cipher_uninit(void) if (ret) return; - wd_cipher_close_driver(); + wd_cipher_close_driver(WD_TYPE_V1); wd_alg_clear_init(&wd_cipher_setting.status); } @@ -421,16 +451,9 @@ int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_p goto out_uninit; } - /* - * Driver lib file path could set by env param. - * then open tham by wd_dlopen_drv() - * use NULL means dynamic query path - */ - wd_cipher_setting.dlh_list = wd_dlopen_drv(NULL); - if (!wd_cipher_setting.dlh_list) { - WD_ERR("fail to open driver lib files.\n"); + state = wd_cipher_open_driver(WD_TYPE_V2); + if (state) goto out_uninit; - } while (ret != 0) { memset(&wd_cipher_setting.config, 0, sizeof(struct wd_ctx_config_internal)); @@ -484,7 +507,7 @@ out_params_uninit: out_driver: wd_alg_drv_unbind(wd_cipher_setting.driver); out_dlopen: - wd_dlclose_drv(wd_cipher_setting.dlh_list); + wd_cipher_close_driver(WD_TYPE_V2); out_uninit: wd_alg_clear_init(&wd_cipher_setting.status); return ret; @@ -500,7 +523,7 @@ void wd_cipher_uninit2(void) wd_alg_attrs_uninit(&wd_cipher_init_attrs); wd_alg_drv_unbind(wd_cipher_setting.driver); - wd_dlclose_drv(wd_cipher_setting.dlh_list); + wd_cipher_close_driver(WD_TYPE_V2); wd_cipher_setting.dlh_list = NULL; wd_alg_clear_init(&wd_cipher_setting.status); } diff --git a/wd_comp.c b/wd_comp.c index cabd17f..459223e 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -54,22 +54,48 @@ struct wd_comp_setting { struct wd_env_config wd_comp_env_config; static struct wd_init_attrs wd_comp_init_attrs; -static void wd_comp_close_driver(void) +static void wd_comp_close_driver(int init_type) { +#ifndef WD_STATIC_DRV + if (init_type == WD_TYPE_V2) { + wd_dlclose_drv(wd_comp_setting.dlh_list); + return; + } + if (wd_comp_setting.dlhandle) { wd_release_drv(wd_comp_setting.driver); dlclose(wd_comp_setting.dlhandle); wd_comp_setting.dlhandle = NULL; } +#else + wd_release_drv(wd_comp_setting.driver); + hisi_zip_remove(); +#endif } -static int wd_comp_open_driver(void) +static int wd_comp_open_driver(int init_type) { struct wd_alg_driver *driver = NULL; - char lib_path[PATH_MAX]; const char *alg_name = "zlib"; +#ifndef WD_STATIC_DRV + char lib_path[PATH_MAX]; int ret; + if (init_type == WD_TYPE_V2) { + /* + * Driver lib file path could set by env param. + * then open them by wd_dlopen_drv() + * use NULL means dynamic query path + */ + wd_comp_setting.dlh_list = wd_dlopen_drv(NULL); + if (!wd_comp_setting.dlh_list) { + WD_ERR("fail to open driver lib files.\n"); + return -WD_EINVAL; + } + + return WD_SUCCESS; + } + ret = wd_get_lib_file_path("libhisi_zip.so", lib_path, false); if (ret) return ret; @@ -79,17 +105,21 @@ static int wd_comp_open_driver(void) WD_ERR("failed to open libhisi_zip.so, %s\n", dlerror()); return -WD_EINVAL; } - +#else + hisi_zip_probe(); + if (init_type == WD_TYPE_V2) + return WD_SUCCESS; +#endif driver = wd_request_drv(alg_name, false); if (!driver) { - wd_comp_close_driver(); + wd_comp_close_driver(WD_TYPE_V1); WD_ERR("failed to get %s driver support\n", alg_name); return -WD_EINVAL; } wd_comp_setting.driver = driver; - return 0; + return WD_SUCCESS; } static void wd_comp_clear_status(void) @@ -185,7 +215,7 @@ int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_clear_init; - ret = wd_comp_open_driver(); + ret = wd_comp_open_driver(WD_TYPE_V1); if (ret) goto out_clear_init; @@ -198,7 +228,7 @@ int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched) return 0; out_clear_driver: - wd_comp_close_driver(); + wd_comp_close_driver(WD_TYPE_V1); out_clear_init: wd_alg_clear_init(&wd_comp_setting.status); return ret; @@ -212,7 +242,7 @@ void wd_comp_uninit(void) if (ret) return; - wd_comp_close_driver(); + wd_comp_close_driver(WD_TYPE_V1); wd_alg_clear_init(&wd_comp_setting.status); } @@ -241,16 +271,9 @@ int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_par goto out_uninit; } - /* - * Driver lib file path could set by env param. - * then open tham by wd_dlopen_drv() - * use NULL means dynamic query path - */ - wd_comp_setting.dlh_list = wd_dlopen_drv(NULL); - if (!wd_comp_setting.dlh_list) { - WD_ERR("fail to open driver lib files.\n"); + state = wd_comp_open_driver(WD_TYPE_V2); + if (state) goto out_uninit; - } while (ret != 0) { memset(&wd_comp_setting.config, 0, sizeof(struct wd_ctx_config_internal)); @@ -303,7 +326,7 @@ out_params_uninit: out_unbind_drv: wd_alg_drv_unbind(wd_comp_setting.driver); out_dlclose: - wd_dlclose_drv(wd_comp_setting.dlh_list); + wd_comp_close_driver(WD_TYPE_V2); out_uninit: wd_alg_clear_init(&wd_comp_setting.status); return ret; @@ -319,7 +342,7 @@ void wd_comp_uninit2(void) wd_alg_attrs_uninit(&wd_comp_init_attrs); wd_alg_drv_unbind(wd_comp_setting.driver); - wd_dlclose_drv(wd_comp_setting.dlh_list); + wd_comp_close_driver(WD_TYPE_V2); wd_comp_setting.dlh_list = NULL; wd_alg_clear_init(&wd_comp_setting.status); } diff --git a/wd_dh.c b/wd_dh.c index 4d08de6..36b0cd7 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -41,23 +41,49 @@ static struct wd_dh_setting { struct wd_env_config wd_dh_env_config; static struct wd_init_attrs wd_dh_init_attrs; -static void wd_dh_close_driver(void) +static void wd_dh_close_driver(int init_type) { +#ifndef WD_STATIC_DRV + if (init_type == WD_TYPE_V2) { + wd_dlclose_drv(wd_dh_setting.dlh_list); + return; + } + if (!wd_dh_setting.dlhandle) return; wd_release_drv(wd_dh_setting.driver); dlclose(wd_dh_setting.dlhandle); wd_dh_setting.dlhandle = NULL; +#else + wd_release_drv(wd_dh_setting.driver); + hisi_hpre_remove(); +#endif } -static int wd_dh_open_driver(void) +static int wd_dh_open_driver(int init_type) { struct wd_alg_driver *driver = NULL; - char lib_path[PATH_MAX]; const char *alg_name = "dh"; +#ifndef WD_STATIC_DRV + char lib_path[PATH_MAX]; int ret; + if (init_type == WD_TYPE_V2) { + /* + * Driver lib file path could set by env param. + * then open them by wd_dlopen_drv() + * default dir in the /root/lib/xxx.so and then dlopen + */ + wd_dh_setting.dlh_list = wd_dlopen_drv(NULL); + if (!wd_dh_setting.dlh_list) { + WD_ERR("failed to open driver lib files.\n"); + return -WD_EINVAL; + } + + return WD_SUCCESS; + } + ret = wd_get_lib_file_path("libhisi_hpre.so", lib_path, false); if (ret) return ret; @@ -67,10 +93,14 @@ static int wd_dh_open_driver(void) WD_ERR("failed to open libhisi_hpre.so, %s!\n", dlerror()); return -WD_EINVAL; } - +#else + hisi_hpre_probe(); + if (init_type == WD_TYPE_V2) + return WD_SUCCESS; +#endif driver = wd_request_drv(alg_name, false); if (!driver) { - wd_dh_close_driver(); + wd_dh_close_driver(WD_TYPE_V1); WD_ERR("failed to get %s driver support\n", alg_name); return -WD_EINVAL; } @@ -158,7 +188,7 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_clear_init; - ret = wd_dh_open_driver(); + ret = wd_dh_open_driver(WD_TYPE_V1); if (ret) goto out_clear_init; @@ -171,7 +201,7 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched) return WD_SUCCESS; out_close_driver: - wd_dh_close_driver(); + wd_dh_close_driver(WD_TYPE_V1); out_clear_init: wd_alg_clear_init(&wd_dh_setting.status); return ret; @@ -185,7 +215,7 @@ void wd_dh_uninit(void) if (ret) return; - wd_dh_close_driver(); + wd_dh_close_driver(WD_TYPE_V1); wd_alg_clear_init(&wd_dh_setting.status); } @@ -212,16 +242,9 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param goto out_clear_init; } - /* - * Driver lib file path could set by env param. - * than open tham by wd_dlopen_drv() - * default dir in the /root/lib/xxx.so and then dlopen - */ - wd_dh_setting.dlh_list = wd_dlopen_drv(NULL); - if (!wd_dh_setting.dlh_list) { - WD_ERR("failed to open driver lib files!\n"); + state = wd_dh_open_driver(WD_TYPE_V2); + if (state) goto out_clear_init; - } while (ret) { memset(&wd_dh_setting.config, 0, sizeof(struct wd_ctx_config_internal)); @@ -275,7 +298,7 @@ out_params_uninit: out_driver: wd_alg_drv_unbind(wd_dh_setting.driver); out_dlopen: - wd_dlclose_drv(wd_dh_setting.dlh_list); + wd_dh_close_driver(WD_TYPE_V2); out_clear_init: wd_alg_clear_init(&wd_dh_setting.status); return ret; @@ -291,7 +314,7 @@ void wd_dh_uninit2(void) wd_alg_attrs_uninit(&wd_dh_init_attrs); wd_alg_drv_unbind(wd_dh_setting.driver); - wd_dlclose_drv(wd_dh_setting.dlh_list); + wd_dh_close_driver(WD_TYPE_V2); wd_dh_setting.dlh_list = NULL; wd_alg_clear_init(&wd_dh_setting.status); } diff --git a/wd_digest.c b/wd_digest.c index 0df7204..7449259 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -73,22 +73,48 @@ struct wd_digest_sess { struct wd_env_config wd_digest_env_config; static struct wd_init_attrs wd_digest_init_attrs; -static void wd_digest_close_driver(void) +static void wd_digest_close_driver(int init_type) { +#ifndef WD_STATIC_DRV + if (init_type == WD_TYPE_V2) { + wd_dlclose_drv(wd_digest_setting.dlh_list); + return; + } + if (wd_digest_setting.dlhandle) { wd_release_drv(wd_digest_setting.driver); dlclose(wd_digest_setting.dlhandle); wd_digest_setting.dlhandle = NULL; } +#else + wd_release_drv(wd_digest_setting.driver); + hisi_sec2_remove(); +#endif } -static int wd_digest_open_driver(void) +static int wd_digest_open_driver(int init_type) { struct wd_alg_driver *driver = NULL; const char *alg_name = "sm3"; +#ifndef WD_STATIC_DRV char lib_path[PATH_MAX]; int ret; + if (init_type == WD_TYPE_V2) { + /* + * Driver lib file path could set by env param. + * then open tham 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"); + return -WD_EINVAL; + } + + return WD_SUCCESS; + } + ret = wd_get_lib_file_path("libhisi_sec.so", lib_path, false); if (ret) return ret; @@ -98,17 +124,21 @@ static int wd_digest_open_driver(void) WD_ERR("failed to open libhisi_sec.so, %s\n", dlerror()); return -WD_EINVAL; } - +#else + hisi_sec2_probe(); + if (init_type == WD_TYPE_V2) + return WD_SUCCESS; +#endif driver = wd_request_drv(alg_name, false); if (!driver) { - wd_digest_close_driver(); + wd_digest_close_driver(WD_TYPE_V1); WD_ERR("failed to get %s driver support\n", alg_name); return -WD_EINVAL; } wd_digest_setting.driver = driver; - return 0; + return WD_SUCCESS; } static int aes_key_len_check(__u32 length) @@ -277,7 +307,7 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_clear_init; - ret = wd_digest_open_driver(); + ret = wd_digest_open_driver(WD_TYPE_V1); if (ret) goto out_clear_init; @@ -290,7 +320,7 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched) return 0; out_close_driver: - wd_digest_close_driver(); + wd_digest_close_driver(WD_TYPE_V1); out_clear_init: wd_alg_clear_init(&wd_digest_setting.status); return ret; @@ -319,7 +349,7 @@ void wd_digest_uninit(void) if (ret) return; - wd_digest_close_driver(); + wd_digest_close_driver(WD_TYPE_V1); wd_alg_clear_init(&wd_digest_setting.status); } @@ -356,16 +386,11 @@ int wd_digest_init2_(char *alg, __u32 sched_type, int task_type, WD_ERR("invalid: digest:%s unsupported!\n", alg); goto out_uninit; } - /* - * Driver lib file path could set by env param. - * 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("failed to open driver lib files.\n"); + + state = wd_digest_open_driver(WD_TYPE_V2); + if (state) goto out_uninit; - } + while (ret != 0) { memset(&wd_digest_setting.config, 0, sizeof(struct wd_ctx_config_internal)); @@ -417,7 +442,7 @@ out_params_uninit: out_driver: wd_alg_drv_unbind(wd_digest_setting.driver); out_dlopen: - wd_dlclose_drv(wd_digest_setting.dlh_list); + wd_digest_close_driver(WD_TYPE_V2); out_uninit: wd_alg_clear_init(&wd_digest_setting.status); return ret; @@ -433,7 +458,7 @@ void wd_digest_uninit2(void) wd_alg_attrs_uninit(&wd_digest_init_attrs); wd_alg_drv_unbind(wd_digest_setting.driver); - wd_dlclose_drv(wd_digest_setting.dlh_list); + wd_digest_close_driver(WD_TYPE_V2); wd_digest_setting.dlh_list = NULL; wd_alg_clear_init(&wd_digest_setting.status); } diff --git a/wd_ecc.c b/wd_ecc.c index e75bca0..24f167f 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -95,23 +95,49 @@ static const struct curve_param_desc curve_pram_list[] = { { ECC_CURVE_G, offsetof(struct wd_ecc_prikey, g), offsetof(struct wd_ecc_pubkey, g) } }; -static void wd_ecc_close_driver(void) +static void wd_ecc_close_driver(int init_type) { +#ifndef WD_STATIC_DRV + if (init_type == WD_TYPE_V2) { + wd_dlclose_drv(wd_ecc_setting.dlh_list); + return; + } + if (!wd_ecc_setting.dlhandle) return; wd_release_drv(wd_ecc_setting.driver); dlclose(wd_ecc_setting.dlhandle); wd_ecc_setting.dlhandle = NULL; +#else + wd_release_drv(wd_ecc_setting.driver); + hisi_hpre_remove(); +#endif } -static int wd_ecc_open_driver(void) +static int wd_ecc_open_driver(int init_type) { struct wd_alg_driver *driver = NULL; - char lib_path[PATH_MAX]; const char *alg_name = "sm2"; +#ifndef WD_STATIC_DRV + char lib_path[PATH_MAX]; int ret; + if (init_type == WD_TYPE_V2) { + /* + * Driver lib file path could set by env param. + * then open them by wd_dlopen_drv() + * default dir in the /root/lib/xxx.so and then dlopen + */ + wd_ecc_setting.dlh_list = wd_dlopen_drv(NULL); + if (!wd_ecc_setting.dlh_list) { + WD_ERR("failed to open driver lib files.\n"); + return -WD_EINVAL; + } + + return WD_SUCCESS; + } + ret = wd_get_lib_file_path("libhisi_hpre.so", lib_path, false); if (ret) return ret; @@ -121,10 +147,14 @@ static int wd_ecc_open_driver(void) WD_ERR("failed to open libhisi_hpre.so, %s!\n", dlerror()); return -WD_EINVAL; } - +#else + hisi_hpre_probe(); + if (init_type == WD_TYPE_V2) + return WD_SUCCESS; +#endif driver = wd_request_drv(alg_name, false); if (!driver) { - wd_ecc_close_driver(); + wd_ecc_close_driver(WD_TYPE_V1); WD_ERR("failed to get %s driver support\n", alg_name); return -WD_EINVAL; } @@ -221,7 +251,7 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_clear_init; - ret = wd_ecc_open_driver(); + ret = wd_ecc_open_driver(WD_TYPE_V1); if (ret) goto out_clear_init; @@ -234,7 +264,7 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched) return WD_SUCCESS; out_close_driver: - wd_ecc_close_driver(); + wd_ecc_close_driver(WD_TYPE_V1); out_clear_init: wd_alg_clear_init(&wd_ecc_setting.status); return ret; @@ -248,7 +278,7 @@ void wd_ecc_uninit(void) if (ret) return; - wd_ecc_close_driver(); + wd_ecc_close_driver(WD_TYPE_V1); wd_alg_clear_init(&wd_ecc_setting.status); } @@ -277,16 +307,9 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para goto out_clear_init; } - /* - * Driver lib file path could set by env param. - * than open tham by wd_dlopen_drv() - * default dir in the /root/lib/xxx.so and then dlopen - */ - wd_ecc_setting.dlh_list = wd_dlopen_drv(NULL); - if (!wd_ecc_setting.dlh_list) { - WD_ERR("failed to open driver lib files!\n"); + state = wd_ecc_open_driver(WD_TYPE_V2); + if (state) goto out_clear_init; - } while (ret) { memset(&wd_ecc_setting.config, 0, sizeof(struct wd_ctx_config_internal)); @@ -340,7 +363,7 @@ out_params_uninit: out_driver: wd_alg_drv_unbind(wd_ecc_setting.driver); out_dlopen: - wd_dlclose_drv(wd_ecc_setting.dlh_list); + wd_ecc_close_driver(WD_TYPE_V2); out_clear_init: wd_alg_clear_init(&wd_ecc_setting.status); return ret; @@ -356,7 +379,7 @@ void wd_ecc_uninit2(void) wd_alg_attrs_uninit(&wd_ecc_init_attrs); wd_alg_drv_unbind(wd_ecc_setting.driver); - wd_dlclose_drv(wd_ecc_setting.dlh_list); + wd_ecc_close_driver(WD_TYPE_V2); wd_ecc_setting.dlh_list = NULL; wd_alg_clear_init(&wd_ecc_setting.status); } diff --git a/wd_rsa.c b/wd_rsa.c index 8e51177..f7f815c 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -82,23 +82,49 @@ static struct wd_rsa_setting { struct wd_env_config wd_rsa_env_config; static struct wd_init_attrs wd_rsa_init_attrs; -static void wd_rsa_close_driver(void) +static void wd_rsa_close_driver(int init_type) { +#ifndef WD_STATIC_DRV + if (init_type == WD_TYPE_V2) { + wd_dlclose_drv(wd_rsa_setting.dlh_list); + return; + } + if (!wd_rsa_setting.dlhandle) return; wd_release_drv(wd_rsa_setting.driver); dlclose(wd_rsa_setting.dlhandle); wd_rsa_setting.dlhandle = NULL; +#else + wd_release_drv(wd_rsa_setting.driver); + hisi_hpre_remove(); +#endif } -static int wd_rsa_open_driver(void) +static int wd_rsa_open_driver(int init_type) { struct wd_alg_driver *driver = NULL; - char lib_path[PATH_MAX]; const char *alg_name = "rsa"; +#ifndef WD_STATIC_DRV + char lib_path[PATH_MAX]; int ret; + if (init_type == WD_TYPE_V2) { + /* + * Driver lib file path could set by env param. + * then open them by wd_dlopen_drv() + * default dir in the /root/lib/xxx.so and then dlopen + */ + wd_rsa_setting.dlh_list = wd_dlopen_drv(NULL); + if (!wd_rsa_setting.dlh_list) { + WD_ERR("failed to open driver lib files.\n"); + return -WD_EINVAL; + } + + return WD_SUCCESS; + } + ret = wd_get_lib_file_path("libhisi_hpre.so", lib_path, false); if (ret) return ret; @@ -108,10 +134,14 @@ static int wd_rsa_open_driver(void) WD_ERR("failed to open libhisi_hpre.so, %s!\n", dlerror()); return -WD_EINVAL; } - +#else + hisi_hpre_probe(); + if (init_type == WD_TYPE_V2) + return WD_SUCCESS; +#endif driver = wd_request_drv(alg_name, false); if (!driver) { - wd_rsa_close_driver(); + wd_rsa_close_driver(WD_TYPE_V1); WD_ERR("failed to get %s driver support!\n", alg_name); return -WD_EINVAL; } @@ -198,7 +228,7 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_clear_init; - ret = wd_rsa_open_driver(); + ret = wd_rsa_open_driver(WD_TYPE_V1); if (ret) goto out_clear_init; @@ -211,7 +241,7 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched) return WD_SUCCESS; out_close_driver: - wd_rsa_close_driver(); + wd_rsa_close_driver(WD_TYPE_V1); out_clear_init: wd_alg_clear_init(&wd_rsa_setting.status); return ret; @@ -225,7 +255,7 @@ void wd_rsa_uninit(void) if (ret) return; - wd_rsa_close_driver(); + wd_rsa_close_driver(WD_TYPE_V1); wd_alg_clear_init(&wd_rsa_setting.status); } @@ -252,16 +282,9 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para goto out_clear_init; } - /* - * Driver lib file path could set by env param. - * than open tham by wd_dlopen_drv() - * default dir in the /root/lib/xxx.so and then dlopen - */ - wd_rsa_setting.dlh_list = wd_dlopen_drv(NULL); - if (!wd_rsa_setting.dlh_list) { - WD_ERR("failed to open driver lib files!\n"); + state = wd_rsa_open_driver(WD_TYPE_V2); + if (state) goto out_clear_init; - } while (ret) { memset(&wd_rsa_setting.config, 0, sizeof(struct wd_ctx_config_internal)); @@ -315,7 +338,7 @@ out_params_uninit: out_driver: wd_alg_drv_unbind(wd_rsa_setting.driver); out_dlopen: - wd_dlclose_drv(wd_rsa_setting.dlh_list); + wd_rsa_close_driver(WD_TYPE_V2); out_clear_init: wd_alg_clear_init(&wd_rsa_setting.status); return ret; @@ -331,7 +354,7 @@ void wd_rsa_uninit2(void) wd_alg_attrs_uninit(&wd_rsa_init_attrs); wd_alg_drv_unbind(wd_rsa_setting.driver); - wd_dlclose_drv(wd_rsa_setting.dlh_list); + wd_rsa_close_driver(WD_TYPE_V2); wd_rsa_setting.dlh_list = NULL; wd_alg_clear_init(&wd_rsa_setting.status); } -- 2.25.1
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2