*** BLURB HERE ***
Longfang Liu (2): uadk/v1: improve the judgment conditions of tag uadk: modify uadk static compile
Qi Tao (3): uadk: fix some cleancode issues uadk: delete useless codes. uadk: simplify repetitive codes
Wenkai Lin (6): cipher: optimze input lengths check uadk/v1: fix for sec cipher bd1 ci_gen configuration uadk: fix for shmget shmflag sec: optimze for directly assigning values to structures util: optimize for wd_handle_msg_sync uadk: drv/hisi - optimize qm recv function
drv/hisi_comp.c | 8 ++++ drv/hisi_hpre.c | 9 ++++ drv/hisi_qm_udrv.c | 45 ++++++++++--------- drv/hisi_sec.c | 63 +++++++++++--------------- drv/isa_ce_sm4.c | 96 ++++++++++++++++------------------------ include/wd_alg.h | 26 ++++++++--- include/wd_alg_common.h | 17 ++++--- uadk_tool/dfx/uadk_dfx.c | 2 +- v1/drv/hisi_hpre_udrv.c | 4 +- v1/drv/hisi_sec_udrv.c | 12 +++-- v1/wd.c | 3 +- v1/wd_rng.c | 4 +- wd_aead.c | 61 +++++++++++++++++-------- wd_alg.c | 25 ++++++++++- wd_cipher.c | 87 ++++++++++++++++++++++++++++-------- wd_comp.c | 63 +++++++++++++++++--------- wd_dh.c | 61 +++++++++++++++++-------- wd_digest.c | 63 ++++++++++++++++++-------- wd_ecc.c | 61 +++++++++++++++++-------- wd_rsa.c | 61 +++++++++++++++++-------- wd_util.c | 28 +++++++----- 21 files changed, 508 insertions(+), 291 deletions(-)
From: Wenkai Lin linwenkai6@hisilicon.com
It is more reasonable to check the input lengths of various cipher algorithms at the algorithm layer.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- drv/hisi_sec.c | 19 +++++-------------- wd_cipher.c | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index 852340d..6625c41 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -960,10 +960,9 @@ static void parse_cipher_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe, dump_sec_msg(temp_msg, "cipher"); }
-static int aes_sm4_len_check(struct wd_cipher_msg *msg) +static int aes_len_check(struct wd_cipher_msg *msg) { - if (msg->alg == WD_CIPHER_AES && - msg->in_bytes <= AES_BLOCK_SIZE && + if (msg->in_bytes <= AES_BLOCK_SIZE && (msg->mode == WD_CIPHER_CBC_CS1 || msg->mode == WD_CIPHER_CBC_CS2 || msg->mode == WD_CIPHER_CBC_CS3)) { @@ -972,13 +971,6 @@ static int aes_sm4_len_check(struct wd_cipher_msg *msg) return -WD_EINVAL; }
- if ((msg->in_bytes & (AES_BLOCK_SIZE - 1)) && - (msg->mode == WD_CIPHER_CBC || msg->mode == WD_CIPHER_ECB)) { - WD_ERR("failed to check input bytes of AES or SM4, size = %u\n", - msg->in_bytes); - return -WD_EINVAL; - } - return 0; }
@@ -986,8 +978,7 @@ static int cipher_len_check(struct wd_cipher_msg *msg) { int ret;
- if (msg->in_bytes > MAX_INPUT_DATA_LEN || - !msg->in_bytes) { + if (msg->in_bytes > MAX_INPUT_DATA_LEN) { WD_ERR("input cipher length is error, size = %u\n", msg->in_bytes); return -WD_EINVAL; @@ -1016,8 +1007,8 @@ static int cipher_len_check(struct wd_cipher_msg *msg) return 0; }
- if (msg->alg == WD_CIPHER_AES || msg->alg == WD_CIPHER_SM4) { - ret = aes_sm4_len_check(msg); + if (msg->alg == WD_CIPHER_AES) { + ret = aes_len_check(msg); if (ret) return ret; } diff --git a/wd_cipher.c b/wd_cipher.c index 63ec362..6f7411f 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -565,6 +565,28 @@ static int cipher_iv_len_check(struct wd_cipher_req *req, return ret; }
+static int cipher_len_check(handle_t h_sess, struct wd_cipher_req *req) +{ + struct wd_cipher_sess *sess = (struct wd_cipher_sess *)h_sess; + + if (!req->in_bytes) { + WD_ERR("invalid: cipher input length is zero!\n"); + return -WD_EINVAL; + } + + if (sess->alg != WD_CIPHER_AES && sess->alg != WD_CIPHER_SM4) + return 0; + + if ((req->in_bytes & (AES_BLOCK_SIZE - 1)) && + (sess->mode == WD_CIPHER_CBC || sess->mode == WD_CIPHER_ECB)) { + WD_ERR("failed to check input bytes of AES or SM4, size = %u\n", + req->in_bytes); + return -WD_EINVAL; + } + + return 0; +} + static int wd_cipher_check_params(handle_t h_sess, struct wd_cipher_req *req, __u8 mode) { @@ -587,6 +609,10 @@ static int wd_cipher_check_params(handle_t h_sess, return -WD_EINVAL; }
+ ret = cipher_len_check(h_sess, req); + if (unlikely(ret)) + return ret; + ret = wd_check_src_dst(req->src, req->in_bytes, req->dst, req->out_bytes); if (unlikely(ret)) { WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n");
From: Longfang Liu liulongfang@huawei.com
Before calling this function, it is guaranteed that the tag is not empty.
In addition, some alarm issues in hpre have been modified.
Signed-off-by: Longfang Liu liulongfang@huawei.com --- v1/drv/hisi_hpre_udrv.c | 4 ++-- v1/drv/hisi_sec_udrv.c | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c index de614f2..eaee4b1 100644 --- a/v1/drv/hisi_hpre_udrv.c +++ b/v1/drv/hisi_hpre_udrv.c @@ -212,13 +212,13 @@ static int qm_fill_rsa_pubkey(struct wcrypto_rsa_pubkey *pubkey, void **data) wd_e->bsize, wd_e->dsize, "rsa pubkey e"); if (unlikely(ret)) return ret; - wd_e->dsize = wd_e->dsize; + wd_e->dsize = wd_e->bsize;
ret = qm_crypto_bin_to_hpre_bin(wd_n->data, (const char *)wd_n->data, wd_n->bsize, wd_n->dsize, "rsa pubkey n"); if (unlikely(ret)) return ret; - wd_n->dsize = wd_n->dsize; + wd_n->dsize = wd_n->bsize;
*data = wd_e->data; return (int)(wd_n->bsize + wd_e->bsize); diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c index d046327..c0bd73d 100644 --- a/v1/drv/hisi_sec_udrv.c +++ b/v1/drv/hisi_sec_udrv.c @@ -759,8 +759,7 @@ static int fill_cipher_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe, return ret; }
- if (tag) - sqe->type2.tag = tag->wcrypto_tag.ctx_id; + sqe->type2.tag = tag->wcrypto_tag.ctx_id;
return ret; }
From: Wenkai Lin linwenkai6@hisilicon.com
In storage scenarios, the XTS mode is used for encrypting and decrypting data on and off disks. According to the definition of this mode, the input parameter to genarate IV is the LBA, so update SEC bd1 xts mode CI_GEN from 0 to 3, which means use LBA mode.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/drv/hisi_sec_udrv.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c index c0bd73d..d4e090a 100644 --- a/v1/drv/hisi_sec_udrv.c +++ b/v1/drv/hisi_sec_udrv.c @@ -312,11 +312,10 @@ static int fill_cipher_bd1_type(struct wcrypto_cipher_msg *msg,
fill_bd_addr_type(msg->data_fmt, sqe);
- /* - * BD1 cipher only provides ci_gen=0 for compatibility, so user - * should prepare iv[gran_num] and iv_bytes is sum of all grans - */ - sqe->type1.ci_gen = CI_GEN_BY_ADDR; + if (msg->mode == WCRYPTO_CIPHER_XTS) + sqe->type1.ci_gen = CI_GEN_BY_LBA; + else + sqe->type1.ci_gen = CI_GEN_BY_ADDR;
return WD_SUCCESS; }
1. Use macros to replace repeated calculations. 2. Remove duplicate initialization of variable. 3. Use "__u32" to replace "unsigned int". 4. Fix format alignment and comment formatting.
Signed-off-by: Qi Tao taoqi10@huawei.com --- drv/isa_ce_sm4.c | 34 ++++++++++++++++------------------ v1/wd.c | 3 ++- v1/wd_rng.c | 4 ++-- 3 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/drv/isa_ce_sm4.c b/drv/isa_ce_sm4.c index 4aa62f1..0e19818 100644 --- a/drv/isa_ce_sm4.c +++ b/drv/isa_ce_sm4.c @@ -18,10 +18,10 @@ #define SM4_ENCRYPT 1 #define SM4_DECRYPT 0 #define MSG_Q_DEPTH 1024 -#define INCREASE_BITS 96 -#define BYTE_BITS 8 +#define INCREASE_BYTES 12 #define SM4_BLOCK_SIZE 16 #define MAX_BLOCK_NUM (1U << 28) +#define CTR96_SHIFT_BITS 8 #define SM4_BYTES2BLKS(nbytes) ((nbytes) >> 4) #define SM4_KEY_SIZE 16
@@ -49,14 +49,14 @@ static void isa_ce_exit(struct wd_alg_driver *drv) /* increment upper 96 bits of 128-bit counter by 1 */ static void ctr96_inc(__u8 *counter) { - __u32 n = INCREASE_BITS / BYTE_BITS; + __u32 n = INCREASE_BYTES; __u32 c = 1;
do { --n; c += counter[n]; counter[n] = (__u8)c; - c >>= BYTE_BITS; + c >>= CTR96_SHIFT_BITS; } while (n); }
@@ -74,7 +74,7 @@ static void sm4_v8_ctr32_encrypt(__u8 *in, __u8 *out, n = (n + 1) % SM4_BLOCK_SIZE; }
- ctr32 = GETU32(iv + INCREASE_BITS / BYTE_BITS); + ctr32 = GETU32(iv + INCREASE_BYTES); while (len >= SM4_BLOCK_SIZE) { blocks = len / SM4_BLOCK_SIZE; /* @@ -97,7 +97,7 @@ static void sm4_v8_ctr32_encrypt(__u8 *in, __u8 *out, } sm4_v8_ctr32_encrypt_blocks(in, out, blocks, key, iv); /* (*ctr) does not update iv, caller does: */ - PUTU32(iv + INCREASE_BITS / BYTE_BITS, ctr32); + PUTU32(iv + INCREASE_BYTES, ctr32); /* ... overflow was detected, propagate carry. */ if (ctr32 == 0) ctr96_inc(iv); @@ -107,10 +107,9 @@ static void sm4_v8_ctr32_encrypt(__u8 *in, __u8 *out, in += offset; } if (len) { - memset(ecount_buf, 0, SM4_BLOCK_SIZE); sm4_v8_ctr32_encrypt_blocks(ecount_buf, ecount_buf, 1, key, iv); ++ctr32; - PUTU32(iv + INCREASE_BITS / BYTE_BITS, ctr32); + PUTU32(iv + INCREASE_BYTES, ctr32); if (ctr32 == 0) ctr96_inc(iv); while (len--) { @@ -233,11 +232,13 @@ static void sm4_set_decrypt_key(const __u8 *userKey, struct SM4_KEY *key)
static void sm4_cfb_encrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rkey_enc) { - unsigned int nbytes = msg->in_bytes; + unsigned char keydata[SM4_BLOCK_SIZE]; const unsigned char *src = msg->in; unsigned char *dst = msg->out; - unsigned int blocks; - unsigned int bbytes; + __u32 nbytes = msg->in_bytes; + __u32 blocks; + __u32 bbytes; + __u32 i = 0;
blocks = SM4_BYTES2BLKS(nbytes); if (blocks) { @@ -249,9 +250,6 @@ static void sm4_cfb_encrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rke }
if (nbytes > 0) { - unsigned char keydata[SM4_BLOCK_SIZE]; - unsigned int i = 0; - sm4_v8_crypt_block(msg->iv, keydata, rkey_enc); while (nbytes > 0) { *dst++ = *src++ ^ keydata[i++]; @@ -269,11 +267,11 @@ static void sm4_cfb_encrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rke
static void sm4_cfb_decrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rkey_dec) { - unsigned int nbytes = msg->in_bytes; + __u32 nbytes = msg->in_bytes; const unsigned char *src = msg->in; unsigned char *dst = msg->out; - unsigned int blocks; - unsigned int bbytes; + __u32 blocks; + __u32 bbytes;
blocks = SM4_BYTES2BLKS(nbytes); if (blocks) { @@ -286,7 +284,7 @@ static void sm4_cfb_decrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rke
if (nbytes > 0) { unsigned char keydata[SM4_BLOCK_SIZE]; - unsigned int i = 0; + __u32 i = 0;
sm4_v8_crypt_block(msg->iv, keydata, rkey_dec); while (nbytes > 0) { diff --git a/v1/wd.c b/v1/wd.c index 26e7af3..4286bbe 100644 --- a/v1/wd.c +++ b/v1/wd.c @@ -88,7 +88,8 @@ static int get_raw_attr(const char *dev_root, const char *attr, if (ptrRet == NULL) return -WD_ENODEV;
- /* The attr_file = "/sys/class/uacce/xxx" + /* + * The attr_file = "/sys/class/uacce/xxx" * It's the Internal Definition File Node */ fd = open(attr_path, O_RDONLY, 0); diff --git a/v1/wd_rng.c b/v1/wd_rng.c index 24a4b7a..7a89cd1 100644 --- a/v1/wd_rng.c +++ b/v1/wd_rng.c @@ -57,7 +57,7 @@ static int wcrypto_setup_qinfo(struct wcrypto_rng_ctx_setup *setup, WD_ERR("algorithm mismatch!\n"); return ret; } - qinfo = q->qinfo; + qinfo = q->qinfo; /* lock at ctx creating */ wd_spinlock(&qinfo->qlock); if (qinfo->ctx_num >= WD_MAX_CTX_NUM) { @@ -120,7 +120,7 @@ void *wcrypto_create_rng_ctx(struct wd_queue *q, return ctx;
free_ctx_id: - qinfo = q->qinfo; + qinfo = q->qinfo; wd_spinlock(&qinfo->qlock); qinfo->ctx_num--; wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, ctx_id, WD_MAX_CTX_NUM);
Remove the while loop that can never be entered.
Signed-off-by: Qi Tao taoqi10@huawei.com --- drv/isa_ce_sm4.c | 6 ------ 1 file changed, 6 deletions(-)
diff --git a/drv/isa_ce_sm4.c b/drv/isa_ce_sm4.c index 0e19818..ceaefeb 100644 --- a/drv/isa_ce_sm4.c +++ b/drv/isa_ce_sm4.c @@ -68,12 +68,6 @@ static void sm4_v8_ctr32_encrypt(__u8 *in, __u8 *out, __u32 ctr32; __u32 n = 0;
- while (n && len) { - *(out++) = *(in++) ^ ecount_buf[n]; - --len; - n = (n + 1) % SM4_BLOCK_SIZE; - } - ctr32 = GETU32(iv + INCREASE_BYTES); while (len >= SM4_BLOCK_SIZE) { blocks = len / SM4_BLOCK_SIZE;
Combines two similar functions into one function to simplify the codes.
Signed-off-by: Qi Tao taoqi10@huawei.com --- drv/isa_ce_sm4.c | 70 +++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 42 deletions(-)
diff --git a/drv/isa_ce_sm4.c b/drv/isa_ce_sm4.c index ceaefeb..6b2ea88 100644 --- a/drv/isa_ce_sm4.c +++ b/drv/isa_ce_sm4.c @@ -224,69 +224,45 @@ static void sm4_set_decrypt_key(const __u8 *userKey, struct SM4_KEY *key) sm4_v8_set_decrypt_key(userKey, key); }
-static void sm4_cfb_encrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rkey_enc) +static void sm4_cfb_crypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rkey, const int enc) { unsigned char keydata[SM4_BLOCK_SIZE]; const unsigned char *src = msg->in; unsigned char *dst = msg->out; __u32 nbytes = msg->in_bytes; - __u32 blocks; - __u32 bbytes; + __u32 blocks, bbytes; __u32 i = 0;
blocks = SM4_BYTES2BLKS(nbytes); if (blocks) { - sm4_v8_cfb_encrypt_blocks(src, dst, blocks, rkey_enc, msg->iv); + if (enc == SM4_ENCRYPT) + sm4_v8_cfb_encrypt_blocks(src, dst, blocks, rkey, msg->iv); + else + sm4_v8_cfb_decrypt_blocks(src, dst, blocks, rkey, msg->iv); + bbytes = blocks * SM4_BLOCK_SIZE; dst += bbytes; src += bbytes; nbytes -= bbytes; }
- if (nbytes > 0) { - sm4_v8_crypt_block(msg->iv, keydata, rkey_enc); - while (nbytes > 0) { - *dst++ = *src++ ^ keydata[i++]; - nbytes--; - } + if (nbytes == 0) + return;
- /* store new IV */ + sm4_v8_crypt_block(msg->iv, keydata, rkey); + while (nbytes > 0) { + *dst++ = *src++ ^ keydata[i++]; + nbytes--; + } + + /* store new IV */ + if (enc == SM4_ENCRYPT) { if (msg->out_bytes >= msg->iv_bytes) memcpy(msg->iv, msg->out + msg->out_bytes - msg->iv_bytes, msg->iv_bytes); else memcpy(msg->iv, msg->out, msg->out_bytes); - } -} - -static void sm4_cfb_decrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rkey_dec) -{ - __u32 nbytes = msg->in_bytes; - const unsigned char *src = msg->in; - unsigned char *dst = msg->out; - __u32 blocks; - __u32 bbytes; - - blocks = SM4_BYTES2BLKS(nbytes); - if (blocks) { - sm4_v8_cfb_decrypt_blocks(src, dst, blocks, rkey_dec, msg->iv); - bbytes = blocks * SM4_BLOCK_SIZE; - dst += bbytes; - src += bbytes; - nbytes -= bbytes; - } - - if (nbytes > 0) { - unsigned char keydata[SM4_BLOCK_SIZE]; - __u32 i = 0; - - sm4_v8_crypt_block(msg->iv, keydata, rkey_dec); - while (nbytes > 0) { - *dst++ = *src++ ^ keydata[i++]; - nbytes--; - } - - /* store new IV */ + } else { if (msg->in_bytes >= msg->iv_bytes) memcpy(msg->iv, msg->in + msg->in_bytes - msg->iv_bytes, msg->iv_bytes); @@ -295,6 +271,16 @@ static void sm4_cfb_decrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rke } }
+static void sm4_cfb_encrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rkey_enc) +{ + sm4_cfb_crypt(msg, rkey_enc, SM4_ENCRYPT); +} + +static void sm4_cfb_decrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rkey_dec) +{ + sm4_cfb_crypt(msg, rkey_dec, SM4_DECRYPT); +} + static int sm4_xts_encrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rkey) { struct SM4_KEY rkey2;
From: Wenkai Lin linwenkai6@hisilicon.com
The shmflag should be 0600 in octal, not 600 in decimal.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- uadk_tool/dfx/uadk_dfx.c | 2 +- wd_util.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/uadk_tool/dfx/uadk_dfx.c b/uadk_tool/dfx/uadk_dfx.c index 796135a..9c54b7b 100644 --- a/uadk_tool/dfx/uadk_dfx.c +++ b/uadk_tool/dfx/uadk_dfx.c @@ -16,7 +16,7 @@
#define uadk_build_date() printf("built on: %s %s\n", __DATE__, __TIME__) #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -#define PRIVILEGE_FLAG 666 +#define PRIVILEGE_FLAG 0666
struct uadk_env_var { const char *module; diff --git a/wd_util.c b/wd_util.c index fb58167..2635dc3 100644 --- a/wd_util.c +++ b/wd_util.c @@ -19,7 +19,7 @@ #define WD_BALANCE_THRHD 1280 #define WD_RECV_MAX_CNT_SLEEP 60000000 #define WD_RECV_MAX_CNT_NOSLEEP 200000000 -#define PRIVILEGE_FLAG 600 +#define PRIVILEGE_FLAG 0600 #define MIN(a, b) ((a) > (b) ? (b) : (a)) #define MAX(a, b) ((a) > (b) ? (a) : (b))
From: Wenkai Lin linwenkai6@hisilicon.com
It is more reasonable to use pointers for value assignment.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- drv/hisi_sec.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index 6625c41..b218cd8 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -542,66 +542,54 @@ static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *
static int cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *msg) { - handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct hisi_qp *qp = (struct hisi_qp *)h_qp; - struct hisi_qm_queue_info q_info = qp->q_info; + struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
- if (q_info.hw_type == HISI_QM_API_VER2_BASE) + if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE) return hisi_sec_cipher_send(drv, ctx, msg); return hisi_sec_cipher_send_v3(drv, ctx, msg); }
static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) { - handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct hisi_qp *qp = (struct hisi_qp *)h_qp; - struct hisi_qm_queue_info q_info = qp->q_info; + struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
- if (q_info.hw_type == HISI_QM_API_VER2_BASE) + if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE) return hisi_sec_cipher_recv(drv, ctx, msg); return hisi_sec_cipher_recv_v3(drv, ctx, msg); }
static int digest_send(struct wd_alg_driver *drv, handle_t ctx, void *msg) { - handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct hisi_qp *qp = (struct hisi_qp *)h_qp; - struct hisi_qm_queue_info q_info = qp->q_info; + struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
- if (q_info.hw_type == HISI_QM_API_VER2_BASE) + if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE) return hisi_sec_digest_send(drv, ctx, msg); return hisi_sec_digest_send_v3(drv, ctx, msg); }
static int digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) { - handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct hisi_qp *qp = (struct hisi_qp *)h_qp; - struct hisi_qm_queue_info q_info = qp->q_info; + struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
- if (q_info.hw_type == HISI_QM_API_VER2_BASE) + if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE) return hisi_sec_digest_recv(drv, ctx, msg); return hisi_sec_digest_recv_v3(drv, ctx, msg); }
static int aead_send(struct wd_alg_driver *drv, handle_t ctx, void *msg) { - handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct hisi_qp *qp = (struct hisi_qp *)h_qp; - struct hisi_qm_queue_info q_info = qp->q_info; + struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
- if (q_info.hw_type == HISI_QM_API_VER2_BASE) + if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE) return hisi_sec_aead_send(drv, ctx, msg); return hisi_sec_aead_send_v3(drv, ctx, msg); }
static int aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) { - handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct hisi_qp *qp = (struct hisi_qp *)h_qp; - struct hisi_qm_queue_info q_info = qp->q_info; + struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
- if (q_info.hw_type == HISI_QM_API_VER2_BASE) + if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE) return hisi_sec_aead_recv(drv, ctx, msg); return hisi_sec_aead_recv_v3(drv, ctx, msg); }
From: Wenkai Lin linwenkai6@hisilicon.com
1. Separate rx_cnt auto-increment and judgment. 2. Reduce the condition judgment in the case of eagain.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd_util.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/wd_util.c b/wd_util.c index 2635dc3..0744ff0 100644 --- a/wd_util.c +++ b/wd_util.c @@ -1822,24 +1822,28 @@ int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_hand do { if (epoll_en) { ret = wd_ctx_wait(ctx, POLL_TIME); - if (ret < 0) + if (unlikely(ret < 0)) WD_ERR("wd ctx wait timeout(%d)!\n", ret); }
ret = msg_handle->recv(drv, ctx, msg); - if (ret == -WD_EAGAIN) { - if (unlikely(rx_cnt++ >= timeout)) { - WD_ERR("failed to recv msg: timeout!\n"); - return -WD_ETIMEDOUT; + if (ret != -WD_EAGAIN) { + if (unlikely(ret < 0)) { + WD_ERR("failed to recv msg: error = %d!\n", ret); + return ret; } + break; + }
- if (balance && *balance > WD_BALANCE_THRHD) - usleep(1); - } else if (unlikely(ret < 0)) { - WD_ERR("failed to recv msg: error = %d!\n", ret); - return ret; + rx_cnt++; + if (unlikely(rx_cnt >= timeout)) { + WD_ERR("failed to recv msg: timeout!\n"); + return -WD_ETIMEDOUT; } - } while (ret < 0); + + if (balance && *balance > WD_BALANCE_THRHD) + usleep(1); + } while (1);
if (balance) *balance = rx_cnt;
From: Wenkai Lin linwenkai6@hisilicon.com
Ensure that the value written by the hardware is read from the memory each time, reduce the number of packet receiving times by half. Also sqe address is only need calculated when packets are received.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- drv/hisi_qm_udrv.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c index d8b5271..304764e 100644 --- a/drv/hisi_qm_udrv.c +++ b/drv/hisi_qm_udrv.c @@ -21,8 +21,8 @@ #define QM_DBELL_SQN_MASK 0x3ff #define QM_DBELL_CMD_MASK 0xf #define QM_Q_DEPTH 1024 -#define CQE_PHASE(cq) (__le16_to_cpu((cq)->w7) & 0x1) -#define CQE_SQ_HEAD_INDEX(cq) (__le16_to_cpu((cq)->sq_head) & 0xffff) +#define CQE_PHASE(cqe) (__le16_to_cpu((cqe)->w7) & 0x1) +#define CQE_SQ_HEAD_INDEX(cqe) (__le16_to_cpu((cqe)->sq_head) & 0xffff) #define VERSION_ID_SHIFT 9
#define UACCE_CMD_QM_SET_QP_CTX _IOWR('H', 10, struct hisi_qp_ctx) @@ -505,32 +505,33 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count) return 0; }
-static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, void *resp) +static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, handle_t h_ctx, + void *resp, __u16 idx) { - struct hisi_qp *qp = container_of(q_info, struct hisi_qp, q_info); + __u16 i, j, cqe_phase; struct cqe *cqe; - __u16 i, j;
pthread_spin_lock(&q_info->rv_lock); i = q_info->cq_head_index; cqe = q_info->cq_base + i * sizeof(struct cqe); + cqe_phase = CQE_PHASE(cqe); + /* Use dsb to read from memory and improve the receiving efficiency. */ + rmb();
- if (q_info->cqc_phase == CQE_PHASE(cqe)) { - /* Make sure cqe valid bit is set */ - rmb(); - j = CQE_SQ_HEAD_INDEX(cqe); - if (unlikely(j >= q_info->sq_depth)) { - pthread_spin_unlock(&q_info->rv_lock); - WD_DEV_ERR(qp->h_ctx, "CQE_SQ_HEAD_INDEX(%u) error!\n", j); - return -WD_EIO; - } - memcpy(resp, (void *)((uintptr_t)q_info->sq_base + - j * q_info->sqe_size), q_info->sqe_size); - } else { + if (q_info->cqc_phase != cqe_phase) { pthread_spin_unlock(&q_info->rv_lock); return -WD_EAGAIN; }
+ j = CQE_SQ_HEAD_INDEX(cqe); + if (unlikely(j >= q_info->sq_depth)) { + pthread_spin_unlock(&q_info->rv_lock); + WD_DEV_ERR(h_ctx, "CQE_SQ_HEAD_INDEX(%u) error!\n", j); + return -WD_EIO; + } + memcpy((void *)((uintptr_t)resp + idx * q_info->sqe_size), + (void *)((uintptr_t)q_info->sq_base + j * q_info->sqe_size), q_info->sqe_size); + if (i == q_info->cq_depth - 1) { q_info->cqc_phase = !(q_info->cqc_phase); i = 0; @@ -544,7 +545,7 @@ static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, void *resp) */ if (unlikely(wd_ioread32(q_info->ds_rx_base) == 1)) { pthread_spin_unlock(&q_info->rv_lock); - WD_DEV_ERR(qp->h_ctx, "wd queue hw error happened after qm receive!\n"); + WD_DEV_ERR(h_ctx, "wd queue hw error happened before qm receive!\n"); return -WD_HW_EACCESS; }
@@ -565,8 +566,9 @@ int hisi_qm_recv(handle_t h_qp, void *resp, __u16 expect, __u16 *count) { struct hisi_qp *qp = (struct hisi_qp *)h_qp; struct hisi_qm_queue_info *q_info; - int recv_num = 0; - int i, ret, offset; + __u16 recv_num = 0; + __u16 i; + int ret;
if (unlikely(!resp || !qp || !count)) return -WD_EINVAL; @@ -581,8 +583,7 @@ int hisi_qm_recv(handle_t h_qp, void *resp, __u16 expect, __u16 *count) }
for (i = 0; i < expect; i++) { - offset = i * q_info->sqe_size; - ret = hisi_qm_recv_single(q_info, resp + offset); + ret = hisi_qm_recv_single(q_info, qp->h_ctx, resp, i); if (ret) break; recv_num++;
From: Longfang Liu liulongfang@huawei.com
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 6f7411f..505773a 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); }