!61 libwd: update the source code to 2.4.0
From: @xiao_jiang_shui Reviewed-by: @hao-fang Signed-off-by: @hao-fang
This commit is contained in:
commit
04742926aa
@ -1,97 +0,0 @@
|
||||
From 01ca714340a06ee7f559ba4086f3173351692413 Mon Sep 17 00:00:00 2001
|
||||
From: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
Date: Thu, 15 Dec 2022 16:08:31 +0800
|
||||
Subject: [PATCH 1/4] uadk/v1/ecc: bugfix buffer overwritten of sm2 decryption
|
||||
|
||||
Fix the problem that the input data field 'c1.x' is overwitten
|
||||
by the output data calculated by the hardware.
|
||||
|
||||
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
---
|
||||
v1/drv/hisi_hpre_udrv.c | 24 ++++++++++++------------
|
||||
1 file changed, 12 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c
|
||||
index 4a97917..191beab 100644
|
||||
--- a/v1/drv/hisi_hpre_udrv.c
|
||||
+++ b/v1/drv/hisi_hpre_udrv.c
|
||||
@@ -1969,7 +1969,6 @@ static int fill_sm2_dec_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
|
||||
/* compute d * c1 */
|
||||
memcpy(dst, req_src, sizeof(*dst));
|
||||
-
|
||||
dst->op_type = HPRE_SM2_DEC;
|
||||
*(struct wcrypto_ecc_msg **)(dst + 1) = req_src;
|
||||
dst->in = (void *)&din->c1;
|
||||
@@ -2047,8 +2046,8 @@ static int qm_parse_ecc_sqe_general(void *msg, const struct qm_queue_info *info,
|
||||
|
||||
dma_out = DMA_ADDR(hw_msg->hi_out, hw_msg->low_out);
|
||||
dma_key = DMA_ADDR(hw_msg->hi_key, hw_msg->low_key);
|
||||
- dma_in = DMA_ADDR(hw_msg->hi_in, hw_msg->hi_in);
|
||||
- drv_iova_unmap(q, NULL, (void *)(uintptr_t)dma_in, olen);
|
||||
+ dma_in = DMA_ADDR(hw_msg->hi_in, hw_msg->low_in);
|
||||
+ drv_iova_unmap(q, NULL, (void *)(uintptr_t)dma_in, ilen);
|
||||
drv_iova_unmap(q, NULL, (void *)(uintptr_t)dma_out, olen);
|
||||
drv_iova_unmap(q, NULL, (void *)(uintptr_t)dma_key, kbytes);
|
||||
|
||||
@@ -2265,8 +2264,8 @@ static int is_equal(struct wd_dtb *src, struct wd_dtb *dst)
|
||||
static int sm2_hash(struct wd_dtb *out, struct wcrypto_ecc_point *x2y2,
|
||||
struct wd_dtb *msg, struct q_info *q_info)
|
||||
{
|
||||
- struct wcrypto_hash_mt *hash = &q_info->hash;
|
||||
__u64 lens = (__u64)msg->dsize + 2 * (__u64)x2y2->x.dsize;
|
||||
+ struct wcrypto_hash_mt *hash = &q_info->hash;
|
||||
char hash_out[MAX_HASH_LENS] = {0};
|
||||
__u64 in_len = 0;
|
||||
__u32 h_bytes;
|
||||
@@ -2353,8 +2352,10 @@ static int sm2_convert_dec_out(struct wcrypto_ecc_msg *src,
|
||||
struct wcrypto_sm2_dec_out *dout = &out->param.dout;
|
||||
struct wcrypto_ecc_in *in = (void *)src->in;
|
||||
struct wcrypto_sm2_dec_in *din = &in->param.din;
|
||||
+ char buff[MAX_HASH_LENS] = {0};
|
||||
struct wcrypto_ecc_point x2y2;
|
||||
__u32 ksz = dst->key_bytes;
|
||||
+ struct wd_dtb u = {0};
|
||||
int ret;
|
||||
|
||||
/* dec origin out data fmt:
|
||||
@@ -2362,8 +2363,6 @@ static int sm2_convert_dec_out(struct wcrypto_ecc_msg *src,
|
||||
* final out data fmt:
|
||||
* | plaintext |
|
||||
*/
|
||||
-
|
||||
- /* x2y2 :copy x2y2 into din->c1 */
|
||||
x2y2.x.data = (void *)dst->out;
|
||||
x2y2.y.data = (void *)(dst->out + ksz);
|
||||
x2y2.x.dsize = ksz;
|
||||
@@ -2376,20 +2375,21 @@ static int sm2_convert_dec_out(struct wcrypto_ecc_msg *src,
|
||||
return ret;
|
||||
}
|
||||
|
||||
- /* M' = C2 XOR t */
|
||||
+ /* M' = c2 XOR t */
|
||||
sm2_xor(&dout->plaintext, &din->c2);
|
||||
|
||||
- /* u = hash(x2 || M' || y2), save u to din->c2 */
|
||||
- ret = sm2_hash(&din->c1.x, &x2y2, &dout->plaintext, q_info);
|
||||
+ /* u = hash(x2 || M' || y2) */
|
||||
+ u.data = buff;
|
||||
+ ret = sm2_hash(&u, &x2y2, &dout->plaintext, q_info);
|
||||
if (unlikely(ret)) {
|
||||
WD_ERR("failed to compute c3, ret = %d!\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
- /* u == c3 */
|
||||
- ret = is_equal(&din->c1.x, &din->c3);
|
||||
+ /* Judge whether u == c3 */
|
||||
+ ret = is_equal(&u, &din->c3);
|
||||
if (ret)
|
||||
- WD_ERR("failed to dec sm2, u != C3!\n");
|
||||
+ WD_ERR("failed to dec sm2, u != c3!\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
42
0001-wd-Fix-GCC-12-build-issue.patch
Normal file
42
0001-wd-Fix-GCC-12-build-issue.patch
Normal file
@ -0,0 +1,42 @@
|
||||
From 1202af2e7ed7fc768eac49e9b73866a96bd6926c Mon Sep 17 00:00:00 2001
|
||||
From: Zhangfei Gao <zhangfei.gao@linaro.org>
|
||||
Date: Sat, 31 Dec 2022 11:38:13 +0000
|
||||
Subject: [PATCH 01/28] wd: Fix GCC 12 build issue
|
||||
|
||||
Build errors happen with GCC 12
|
||||
|
||||
wd.c: In function 'wd_is_isolate':
|
||||
wd.c:193:21: error: the comparison will always evaluate as 'true' for the address of 'dev_root' will never be NULL [-Werror=address]
|
||||
193 | if (!dev || !dev->dev_root)
|
||||
| ^
|
||||
In file included from wd.c:21:
|
||||
./include/wd.h:131:14: note: 'dev_root' declared here
|
||||
131 | char dev_root[PATH_STR_SIZE];
|
||||
| ^~~~~~~~
|
||||
cc1: all warnings being treated as errors
|
||||
make[1]: *** [Makefile:816: wd.lo] Error 1
|
||||
|
||||
Fix by using strlen(dev->dev_root).
|
||||
|
||||
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
|
||||
Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
|
||||
---
|
||||
wd.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/wd.c b/wd.c
|
||||
index 629c0df..4f75113 100644
|
||||
--- a/wd.c
|
||||
+++ b/wd.c
|
||||
@@ -190,7 +190,7 @@ int wd_is_isolate(struct uacce_dev *dev)
|
||||
int value = 0;
|
||||
int ret;
|
||||
|
||||
- if (!dev || !dev->dev_root)
|
||||
+ if (!dev || !strlen(dev->dev_root))
|
||||
return -WD_EINVAL;
|
||||
|
||||
ret = access_attr(dev->dev_root, "isolate", F_OK);
|
||||
--
|
||||
2.25.1
|
||||
|
||||
164
0002-digest-add-the-0-byte-packet-checking-for-long-hash.patch
Normal file
164
0002-digest-add-the-0-byte-packet-checking-for-long-hash.patch
Normal file
@ -0,0 +1,164 @@
|
||||
From 10c8644742e240f46ba0b27ae18100a344876217 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Tue, 17 Jan 2023 16:29:38 +0800
|
||||
Subject: [PATCH 02/28] digest: add the 0 byte packet checking for long hash
|
||||
|
||||
Hardware v2 digest needs to check the zero byte packet in the
|
||||
frist and middle bd.Add a function that get the hash bd type.
|
||||
It can simplify the code of the process of hash bd type checking.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 72 +++++++++++++++++++++++++++++++++++++++++++-------
|
||||
1 file changed, 62 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index c30b653..116424e 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -187,6 +187,13 @@ enum sec_c_width {
|
||||
C_WIDTH_CS3 = 0x3,
|
||||
};
|
||||
|
||||
+enum hash_bd_type {
|
||||
+ HASH_SINGLE_BD,
|
||||
+ HASH_FRIST_BD,
|
||||
+ HASH_MIDDLE_BD,
|
||||
+ HASH_END_BD,
|
||||
+};
|
||||
+
|
||||
struct hisi_sec_ctx {
|
||||
struct wd_ctx_config_internal config;
|
||||
};
|
||||
@@ -1379,9 +1386,29 @@ static int long_hash_param_check(handle_t h_qp, struct wd_digest_msg *msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static enum hash_bd_type get_hash_bd_type(struct wd_digest_msg *msg)
|
||||
+{
|
||||
+ /*
|
||||
+ * [has_next , iv_bytes]
|
||||
+ * [ 1 , 0 ] = long hash(frist bd)
|
||||
+ * [ 1 , 1 ] = long hash(middle bd)
|
||||
+ * [ 0 , 1 ] = long hash(end bd)
|
||||
+ * [ 0 , 0 ] = block hash(single bd)
|
||||
+ */
|
||||
+ if (msg->has_next && !msg->iv_bytes)
|
||||
+ return HASH_FRIST_BD;
|
||||
+ else if (msg->has_next && msg->iv_bytes)
|
||||
+ return HASH_MIDDLE_BD;
|
||||
+ else if (!msg->has_next && msg->iv_bytes)
|
||||
+ return HASH_END_BD;
|
||||
+ else
|
||||
+ return HASH_SINGLE_BD;
|
||||
+}
|
||||
+
|
||||
static int fill_digest_long_hash(handle_t h_qp, struct wd_digest_msg *msg,
|
||||
struct hisi_sec_sqe *sqe)
|
||||
{
|
||||
+ enum hash_bd_type bd_type = get_hash_bd_type(msg);
|
||||
__u64 total_bits;
|
||||
int ret;
|
||||
|
||||
@@ -1389,20 +1416,20 @@ static int fill_digest_long_hash(handle_t h_qp, struct wd_digest_msg *msg,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
- if (msg->has_next && !msg->iv_bytes) {
|
||||
+ if (bd_type == HASH_FRIST_BD) {
|
||||
/* Long hash first */
|
||||
sqe->ai_apd_cs = AI_GEN_INNER;
|
||||
sqe->ai_apd_cs |= AUTHPAD_NOPAD << AUTHPAD_OFFSET;
|
||||
}
|
||||
|
||||
- if (msg->has_next && msg->iv_bytes) {
|
||||
+ if (bd_type == HASH_MIDDLE_BD) {
|
||||
/* Long hash middle */
|
||||
sqe->ai_apd_cs = AI_GEN_IVIN_ADDR;
|
||||
sqe->ai_apd_cs |= AUTHPAD_NOPAD << AUTHPAD_OFFSET;
|
||||
sqe->type2.a_ivin_addr = sqe->type2.mac_addr;
|
||||
}
|
||||
|
||||
- if (!msg->has_next && msg->iv_bytes) {
|
||||
+ if (bd_type == HASH_END_BD) {
|
||||
/* Long hash end */
|
||||
sqe->ai_apd_cs = AI_GEN_IVIN_ADDR;
|
||||
sqe->ai_apd_cs |= AUTHPAD_PAD << AUTHPAD_OFFSET;
|
||||
@@ -1478,14 +1505,38 @@ static int aes_auth_len_check(struct wd_digest_msg *msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static int digest_bd2_zero_packet_check(struct wd_digest_msg *msg)
|
||||
+{
|
||||
+ enum hash_bd_type type = get_hash_bd_type(msg);
|
||||
+
|
||||
+ /* Long hash first and middle bd */
|
||||
+ if (type == HASH_FRIST_BD || type == HASH_MIDDLE_BD) {
|
||||
+ WD_ERR("hardware v2 not supports 0 size in long hash!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ /* Block mode hash bd */
|
||||
+ if (type == HASH_SINGLE_BD) {
|
||||
+ WD_ERR("hardware v2 not supports 0 size in block hash!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
|
||||
{
|
||||
int ret;
|
||||
|
||||
- /* End BD not need to check the input zero bytes */
|
||||
- if (unlikely(type == BD_TYPE2 && !msg->has_next && !msg->in_bytes)) {
|
||||
- WD_ERR("kunpeng 920, digest mode not support 0 size!\n");
|
||||
- return -WD_EINVAL;
|
||||
+ /*
|
||||
+ * Hardware v2 needs to check the zero byte packet in the block
|
||||
+ * and long hash mode. Frist and Middle bd not supports 0 size,
|
||||
+ * final bd not need to check it. Hardware v3 has fixed it.
|
||||
+ */
|
||||
+ if (type == BD_TYPE2 && !msg->in_bytes) {
|
||||
+ ret = digest_bd2_zero_packet_check(msg);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
if (type == BD_TYPE3) {
|
||||
@@ -1714,6 +1765,7 @@ static int aes_auth_long_hash_check(struct wd_digest_msg *msg)
|
||||
static int fill_digest_long_hash3(handle_t h_qp, struct wd_digest_msg *msg,
|
||||
struct hisi_sec_sqe3 *sqe)
|
||||
{
|
||||
+ enum hash_bd_type bd_type = get_hash_bd_type(msg);
|
||||
__u64 total_bits;
|
||||
int ret;
|
||||
|
||||
@@ -1725,20 +1777,20 @@ static int fill_digest_long_hash3(handle_t h_qp, struct wd_digest_msg *msg,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
- if (msg->has_next && !msg->iv_bytes) {
|
||||
+ if (bd_type == HASH_FRIST_BD) {
|
||||
/* Long hash first */
|
||||
sqe->auth_mac_key |= AI_GEN_INNER << SEC_AI_GEN_OFFSET_V3;
|
||||
sqe->stream_scene.stream_auth_pad = AUTHPAD_NOPAD;
|
||||
}
|
||||
|
||||
- if (msg->has_next && msg->iv_bytes) {
|
||||
+ if (bd_type == HASH_MIDDLE_BD) {
|
||||
/* Long hash middle */
|
||||
sqe->auth_mac_key |= AI_GEN_IVIN_ADDR << SEC_AI_GEN_OFFSET_V3;
|
||||
sqe->stream_scene.stream_auth_pad = AUTHPAD_NOPAD;
|
||||
sqe->auth_ivin.a_ivin_addr = sqe->mac_addr;
|
||||
}
|
||||
|
||||
- if (!msg->has_next && msg->iv_bytes) {
|
||||
+ if (bd_type == HASH_END_BD) {
|
||||
/* Long hash end */
|
||||
sqe->auth_mac_key |= AI_GEN_IVIN_ADDR << SEC_AI_GEN_OFFSET_V3;
|
||||
sqe->stream_scene.stream_auth_pad = AUTHPAD_PAD;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,71 +0,0 @@
|
||||
From 3cd236bcafd4b6ff20363892a70dc5769af7e51a Mon Sep 17 00:00:00 2001
|
||||
From: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
Date: Thu, 15 Dec 2022 16:07:57 +0800
|
||||
Subject: [PATCH 2/4] uadk/ecc: cleanup sm2 dec out code
|
||||
|
||||
Delete incorrect comments and use variable name
|
||||
that meet the algorithm criteria.
|
||||
|
||||
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
---
|
||||
drv/hisi_hpre.c | 19 +++++++++----------
|
||||
1 file changed, 9 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
|
||||
index 552a565..a172df5 100644
|
||||
--- a/drv/hisi_hpre.c
|
||||
+++ b/drv/hisi_hpre.c
|
||||
@@ -2191,11 +2191,11 @@ static int sm2_convert_dec_out(struct wd_ecc_msg *src,
|
||||
struct wd_sm2_dec_out *dout = &out->param.dout;
|
||||
struct wd_ecc_in *in = (void *)src->req.src;
|
||||
struct wd_sm2_dec_in *din = &in->param.din;
|
||||
+ char buff[MAX_HASH_LENS] = {0};
|
||||
struct wd_ecc_dh_out *dh_out;
|
||||
__u32 ksz = dst->key_bytes;
|
||||
struct wd_ecc_point x2y2;
|
||||
- struct wd_dtb tmp = {0};
|
||||
- char buff[64] = {0};
|
||||
+ struct wd_dtb u = {0};
|
||||
int ret;
|
||||
|
||||
/*
|
||||
@@ -2211,8 +2211,6 @@ static int sm2_convert_dec_out(struct wd_ecc_msg *src,
|
||||
x2y2.x.dsize = ksz;
|
||||
x2y2.y.dsize = ksz;
|
||||
|
||||
- tmp.data = buff;
|
||||
-
|
||||
/* t = KDF(x2 || y2, klen) */
|
||||
ret = sm2_kdf(&dout->plaintext, &x2y2, din->c2.dsize, &src->hash);
|
||||
if (unlikely(ret)) {
|
||||
@@ -2220,20 +2218,21 @@ static int sm2_convert_dec_out(struct wd_ecc_msg *src,
|
||||
return ret;
|
||||
}
|
||||
|
||||
- /* M' = C2 XOR t */
|
||||
+ /* M' = c2 XOR t */
|
||||
sm2_xor(&dout->plaintext, &din->c2);
|
||||
|
||||
- /* u = hash(x2 || M' || y2), save u to din->c2 */
|
||||
- ret = sm2_hash(&tmp, &x2y2, &dout->plaintext, &src->hash);
|
||||
+ /* u = hash(x2 || M' || y2) */
|
||||
+ u.data = buff;
|
||||
+ ret = sm2_hash(&u, &x2y2, &dout->plaintext, &src->hash);
|
||||
if (unlikely(ret)) {
|
||||
WD_ERR("failed to compute c3, ret = %d!\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
- /* u == c3 */
|
||||
- ret = is_equal(&tmp, &din->c3);
|
||||
+ /* Judge whether u == c3 */
|
||||
+ ret = is_equal(&u, &din->c3);
|
||||
if (ret)
|
||||
- WD_ERR("failed to decode sm2, u != C3!\n");
|
||||
+ WD_ERR("failed to decode sm2, u != c3!\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
37
0003-drv-hisi_sec-modify-the-hardware-name.patch
Normal file
37
0003-drv-hisi_sec-modify-the-hardware-name.patch
Normal file
@ -0,0 +1,37 @@
|
||||
From 0c55f846de06a659a4962ff78f18a6958c64ae9f Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Tue, 17 Jan 2023 16:33:34 +0800
|
||||
Subject: [PATCH 03/28] drv/hisi_sec: modify the hardware name
|
||||
|
||||
Modify the hardware name and printing level for driver initialization.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index 116424e..6187346 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -2580,7 +2580,7 @@ static void hisi_sec_driver_adapter(struct hisi_qp *qp)
|
||||
struct hisi_qm_queue_info q_info = qp->q_info;
|
||||
|
||||
if (q_info.hw_type == HISI_QM_API_VER2_BASE) {
|
||||
- WD_ERR("hisi sec init Kunpeng920!\n");
|
||||
+ WD_INFO("hisi sec init HIP08!\n");
|
||||
hisi_cipher_driver.cipher_send = hisi_sec_cipher_send;
|
||||
hisi_cipher_driver.cipher_recv = hisi_sec_cipher_recv;
|
||||
|
||||
@@ -2590,7 +2590,7 @@ static void hisi_sec_driver_adapter(struct hisi_qp *qp)
|
||||
hisi_aead_driver.aead_send = hisi_sec_aead_send;
|
||||
hisi_aead_driver.aead_recv = hisi_sec_aead_recv;
|
||||
} else {
|
||||
- WD_ERR("hisi sec init Kunpeng930!\n");
|
||||
+ WD_INFO("hisi sec init HIP09!\n");
|
||||
hisi_cipher_driver.cipher_send = hisi_sec_cipher_send_v3;
|
||||
hisi_cipher_driver.cipher_recv = hisi_sec_cipher_recv_v3;
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,153 +0,0 @@
|
||||
From 770967b993db3bb6dcdb9e23d4d9f6c14869cd4d Mon Sep 17 00:00:00 2001
|
||||
From: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
Date: Thu, 15 Dec 2022 16:50:20 +0800
|
||||
Subject: [PATCH 3/4] uadk/v1/ecc: bugfix incorrect parameter length
|
||||
|
||||
In 'struct wd_dtb', the member 'bsize' indicates the whole
|
||||
buffer size of the data, the member 'dsize' indicates the
|
||||
valid size of the data. The 'bsize' is generally greater
|
||||
than or equal to 'dsize'. In some cases, the data will be
|
||||
filled with zero, the value of 'dsize' will not be updated,
|
||||
so directly using 'dsize' may truncate the data and cause
|
||||
erroneous judgement.
|
||||
|
||||
The solution is when check whether a 'struct wd_dtb' type
|
||||
variable is all zero, if 'bsize' is larger than 'dsize',
|
||||
the length of the data should be the value of 'bsize'.
|
||||
And the key size value is redundant.
|
||||
|
||||
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
---
|
||||
v1/drv/hisi_hpre_udrv.c | 22 +++++++++++++---------
|
||||
v1/wd_ecc.c | 14 +++++++-------
|
||||
2 files changed, 20 insertions(+), 16 deletions(-)
|
||||
|
||||
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c
|
||||
index 191beab..9e3bd3b 100644
|
||||
--- a/v1/drv/hisi_hpre_udrv.c
|
||||
+++ b/v1/drv/hisi_hpre_udrv.c
|
||||
@@ -1111,17 +1111,21 @@ static void correct_random(struct wd_dtb *k)
|
||||
k->data[lens] = 0;
|
||||
}
|
||||
|
||||
-static bool is_all_zero(struct wd_dtb *e, struct wcrypto_ecc_msg *msg,
|
||||
- const char *p_name)
|
||||
+static bool is_all_zero(struct wd_dtb *e, const char *p_name)
|
||||
{
|
||||
int i;
|
||||
|
||||
- for (i = 0; i < e->dsize && i < msg->key_bytes; i++) {
|
||||
+ if (!e || !e->data) {
|
||||
+ WD_ERR("invalid: %s is NULL!\n", p_name);
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ for (i = 0; i < e->bsize; i++) {
|
||||
if (e->data[i])
|
||||
return false;
|
||||
}
|
||||
|
||||
- WD_ERR("error: %s all zero!\n", p_name);
|
||||
+ WD_ERR("invalid: %s all zero!\n", p_name);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1144,15 +1148,15 @@ static int ecc_prepare_sign_in(struct wcrypto_ecc_msg *msg,
|
||||
e = &in->dgst;
|
||||
if (!in->k_set) {
|
||||
if (msg->op_type != WCRYPTO_SM2_SIGN) {
|
||||
- WD_ERR("random k not set!\n");
|
||||
+ WD_ERR("invalid: random k not set!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
hw_msg->sm2_ksel = 1;
|
||||
- } else if (is_all_zero(k, msg, "ecc sgn k")) {
|
||||
+ } else if (is_all_zero(k, "ecc sgn k")) {
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (is_all_zero(e, msg, "ecc sgn e"))
|
||||
+ if (is_all_zero(e, "ecc sgn e"))
|
||||
return -WD_EINVAL;
|
||||
|
||||
ret = qm_crypto_bin_to_hpre_bin(e->data, (const char *)e->data,
|
||||
@@ -1192,7 +1196,7 @@ static int ecc_prepare_verf_in(struct wcrypto_ecc_msg *msg, void **data)
|
||||
s = &vin->s;
|
||||
r = &vin->r;
|
||||
|
||||
- if (is_all_zero(e, msg, "ecc vrf e"))
|
||||
+ if (is_all_zero(e, "ecc vrf e"))
|
||||
return -WD_EINVAL;
|
||||
|
||||
ret = qm_crypto_bin_to_hpre_bin(e->data, (const char *)e->data,
|
||||
@@ -1274,7 +1278,7 @@ static int ecc_prepare_sm2_enc_in(struct wcrypto_ecc_msg *msg,
|
||||
int ret;
|
||||
|
||||
if (ein->k_set) {
|
||||
- if (is_all_zero(k, msg, "sm2 enc k"))
|
||||
+ if (is_all_zero(k, "sm2 enc k"))
|
||||
return -WD_EINVAL;
|
||||
|
||||
ret = qm_crypto_bin_to_hpre_bin(k->data, (const char *)k->data,
|
||||
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c
|
||||
index e108051..e6b771a 100644
|
||||
--- a/v1/wd_ecc.c
|
||||
+++ b/v1/wd_ecc.c
|
||||
@@ -544,6 +544,7 @@ static struct wcrypto_ecc_in *create_ecc_sign_in(struct wcrypto_ecc_ctx *ctx,
|
||||
{
|
||||
if (is_dgst)
|
||||
return create_ecc_in(ctx, ECC_SIGN_IN_PARAM_NUM);
|
||||
+
|
||||
return create_sm2_sign_in(ctx, m_len);
|
||||
}
|
||||
|
||||
@@ -1489,7 +1490,6 @@ static int ecc_request_init(struct wcrypto_ecc_msg *req,
|
||||
if (req->op_type == WCRYPTO_ECXDH_GEN_KEY ||
|
||||
req->op_type == WCRYPTO_SM2_KG) {
|
||||
struct wcrypto_ecc_point *g = NULL;
|
||||
-
|
||||
wcrypto_get_ecc_prikey_params((void *)key, NULL, NULL,
|
||||
NULL, NULL, &g, NULL);
|
||||
req->in = (void *)g;
|
||||
@@ -1715,11 +1715,11 @@ static bool less_than_latter(struct wd_dtb *d, struct wd_dtb *n)
|
||||
return ret < 0;
|
||||
}
|
||||
|
||||
-static bool is_all_zero(struct wd_dtb *p, struct wcrypto_ecc_ctx *ctx)
|
||||
+static bool is_all_zero(struct wd_dtb *p)
|
||||
{
|
||||
int i;
|
||||
|
||||
- for (i = 0; i < p->dsize && i < ctx->key_size; i++) {
|
||||
+ for (i = 0; i < p->bsize; i++) {
|
||||
if (p->data[i])
|
||||
return false;
|
||||
}
|
||||
@@ -1733,7 +1733,7 @@ static bool check_k_param(struct wd_dtb *k, struct wcrypto_ecc_ctx *ctx)
|
||||
int ret;
|
||||
|
||||
if (unlikely(!k->data)) {
|
||||
- WD_ERR("error: k->data NULL!\n");
|
||||
+ WD_ERR("invalid: k->data NULL!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1744,12 +1744,12 @@ static bool check_k_param(struct wd_dtb *k, struct wcrypto_ecc_ctx *ctx)
|
||||
}
|
||||
|
||||
if (unlikely(!less_than_latter(k, &cv->n))) {
|
||||
- WD_ERR("error: k >= n\n");
|
||||
+ WD_ERR("invalid: k >= n!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
- if (unlikely(is_all_zero(k, ctx))) {
|
||||
- WD_ERR("error: k all zero\n");
|
||||
+ if (unlikely(is_all_zero(k))) {
|
||||
+ WD_ERR("invalid: k all zero!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
451
0004-uadk-Add-driver-dynamic-loading-function.patch
Normal file
451
0004-uadk-Add-driver-dynamic-loading-function.patch
Normal file
@ -0,0 +1,451 @@
|
||||
From 760111f47ef44fc401ded9bd3079ee193cc449bb Mon Sep 17 00:00:00 2001
|
||||
From: Longfang Liu <liulongfang@huawei.com>
|
||||
Date: Sat, 7 Jan 2023 16:08:56 +0800
|
||||
Subject: [PATCH 04/28] uadk: Add driver dynamic loading function
|
||||
|
||||
According to the logical layering of UADK, the device driver has
|
||||
been updated from the previous fixed binding HiSilicon accelerator
|
||||
to the dynamic registration method through the algorithm linked
|
||||
list method.
|
||||
|
||||
After the update, it can support the use of instruction
|
||||
acceleration and third-party device drivers.
|
||||
|
||||
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
|
||||
---
|
||||
Makefile.am | 4 +-
|
||||
include/wd_alg.h | 95 ++++++++++++++
|
||||
include/wd_alg_common.h | 1 +
|
||||
libwd.map | 8 ++
|
||||
wd_alg.c | 265 ++++++++++++++++++++++++++++++++++++++++
|
||||
5 files changed, 371 insertions(+), 2 deletions(-)
|
||||
create mode 100644 include/wd_alg.h
|
||||
create mode 100644 wd_alg.c
|
||||
|
||||
diff --git a/Makefile.am b/Makefile.am
|
||||
index ee8454b..1ea6d6b 100644
|
||||
--- a/Makefile.am
|
||||
+++ b/Makefile.am
|
||||
@@ -33,7 +33,7 @@ AM_CFLAGS+= -DUADK_RELEASED_TIME="\"Released ${MONTH} ${DAY}, ${YEAR}\""
|
||||
pkginclude_HEADERS = include/wd.h include/wd_cipher.h include/wd_aead.h \
|
||||
include/wd_comp.h include/wd_dh.h include/wd_digest.h \
|
||||
include/wd_rsa.h include/uacce.h include/wd_alg_common.h \
|
||||
- include/wd_ecc.h include/wd_sched.h
|
||||
+ include/wd_ecc.h include/wd_sched.h include/wd_alg.h
|
||||
|
||||
nobase_pkginclude_HEADERS = v1/wd.h v1/wd_cipher.h v1/wd_aead.h v1/uacce.h v1/wd_dh.h \
|
||||
v1/wd_digest.h v1/wd_rsa.h v1/wd_bmm.h
|
||||
@@ -41,7 +41,7 @@ nobase_pkginclude_HEADERS = v1/wd.h v1/wd_cipher.h v1/wd_aead.h v1/uacce.h v1/wd
|
||||
lib_LTLIBRARIES=libwd.la libwd_comp.la libwd_crypto.la libhisi_zip.la \
|
||||
libhisi_hpre.la libhisi_sec.la
|
||||
|
||||
-libwd_la_SOURCES=wd.c wd_mempool.c wd.h \
|
||||
+libwd_la_SOURCES=wd.c wd_mempool.c wd.h wd_alg.c wd_alg.h \
|
||||
v1/wd.c v1/wd.h v1/wd_adapter.c v1/wd_adapter.h \
|
||||
v1/wd_rng.c v1/wd_rng.h \
|
||||
v1/wd_rsa.c v1/wd_rsa.h \
|
||||
diff --git a/include/wd_alg.h b/include/wd_alg.h
|
||||
new file mode 100644
|
||||
index 0000000..e25e191
|
||||
--- /dev/null
|
||||
+++ b/include/wd_alg.h
|
||||
@@ -0,0 +1,95 @@
|
||||
+// SPDX-License-Identifier: Apache-2.0
|
||||
+/*
|
||||
+ * Copyright 2023 Huawei Technologies Co.,Ltd. All rights reserved.
|
||||
+ */
|
||||
+
|
||||
+#ifndef __WD_ALG_H
|
||||
+#define __WD_ALG_H
|
||||
+#include <errno.h>
|
||||
+#include <fcntl.h>
|
||||
+#include <stdbool.h>
|
||||
+#include <stdint.h>
|
||||
+#include <stdio.h>
|
||||
+#include <string.h>
|
||||
+#include <syslog.h>
|
||||
+#include <unistd.h>
|
||||
+#include <asm/types.h>
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
+#define handle_t uintptr_t
|
||||
+enum alg_priority {
|
||||
+ UADK_ALG_SOFT = 0x0,
|
||||
+ UADK_ALG_CE_INSTR = 0x1,
|
||||
+ UADK_ALG_SVE_INSTR = 0x2,
|
||||
+ 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
|
||||
+ * @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
|
||||
+ * algorithm business and requires queues to be executed separately
|
||||
+ * @priv_size: parameter memory size passed between the internal
|
||||
+ * interfaces of the driver
|
||||
+ * @fallback: soft calculation driver handle when performing soft
|
||||
+ * calculation supplement
|
||||
+ * @init: callback interface for initializing device drivers
|
||||
+ * @exit: callback interface for destroying device drivers
|
||||
+ * @send: callback interface used to send task packets to
|
||||
+ * hardware devices.
|
||||
+ * @recv: callback interface used to retrieve the calculation
|
||||
+ * result of the task packets from the hardware device.
|
||||
+ * @get_usage: callback interface used to obtain the
|
||||
+ * utilization rate of devices.
|
||||
+ */
|
||||
+struct wd_alg_driver {
|
||||
+ const char *drv_name;
|
||||
+ const char *alg_name;
|
||||
+ int priority;
|
||||
+ int queue_num;
|
||||
+ int op_type_num;
|
||||
+ int priv_size;
|
||||
+ handle_t fallback;
|
||||
+
|
||||
+ int (*init)(void *conf, void *priv);
|
||||
+ void (*exit)(void *priv);
|
||||
+ int (*send)(handle_t ctx, void *drv_msg);
|
||||
+ int (*recv)(handle_t ctx, void *drv_msg);
|
||||
+ int (*get_usage)(void *param);
|
||||
+};
|
||||
+
|
||||
+int wd_alg_driver_register(struct wd_alg_driver *drv);
|
||||
+void wd_alg_driver_unregister(struct wd_alg_driver *drv);
|
||||
+
|
||||
+struct wd_alg_list {
|
||||
+ const char *alg_name;
|
||||
+ const char *drv_name;
|
||||
+ bool available;
|
||||
+ int priority;
|
||||
+ int refcnt;
|
||||
+
|
||||
+ struct wd_alg_driver *drv;
|
||||
+ struct wd_alg_list *next;
|
||||
+};
|
||||
+
|
||||
+struct wd_alg_driver *wd_request_drv(const char *alg_name, bool hw_mask);
|
||||
+void wd_release_drv(struct wd_alg_driver *drv);
|
||||
+
|
||||
+bool wd_drv_alg_support(const char *alg_name,
|
||||
+ struct wd_alg_driver *drv);
|
||||
+void wd_enable_drv(struct wd_alg_driver *drv);
|
||||
+void wd_disable_drv(struct wd_alg_driver *drv);
|
||||
+
|
||||
+struct wd_alg_list *wd_get_alg_head(void);
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
+#endif
|
||||
diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h
|
||||
index 56539cc..d04b046 100644
|
||||
--- a/include/wd_alg_common.h
|
||||
+++ b/include/wd_alg_common.h
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include "wd.h"
|
||||
+#include "wd_alg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
diff --git a/libwd.map b/libwd.map
|
||||
index 459f9ba..5522ec0 100644
|
||||
--- a/libwd.map
|
||||
+++ b/libwd.map
|
||||
@@ -41,5 +41,13 @@ global:
|
||||
wd_add_dev_to_list;
|
||||
wd_find_dev_by_numa;
|
||||
|
||||
+ wd_alg_driver_register;
|
||||
+ wd_alg_driver_unregister;
|
||||
+ wd_request_drv;
|
||||
+ wd_release_drv;
|
||||
+ wd_drv_alg_support;
|
||||
+ wd_enable_drv;
|
||||
+ wd_disable_drv;
|
||||
+ wd_get_alg_head;
|
||||
local: *;
|
||||
};
|
||||
diff --git a/wd_alg.c b/wd_alg.c
|
||||
new file mode 100644
|
||||
index 0000000..5e4edaf
|
||||
--- /dev/null
|
||||
+++ b/wd_alg.c
|
||||
@@ -0,0 +1,265 @@
|
||||
+/* SPDX-License-Identifier: Apache-2.0 */
|
||||
+/*
|
||||
+ * Copyright 2023 Huawei Technologies Co.,Ltd. All rights reserved.
|
||||
+ */
|
||||
+
|
||||
+#define _GNU_SOURCE
|
||||
+#include <ctype.h>
|
||||
+#include <dirent.h>
|
||||
+#include <errno.h>
|
||||
+#include <stdbool.h>
|
||||
+#include <stdlib.h>
|
||||
+#include <string.h>
|
||||
+#include <pthread.h>
|
||||
+
|
||||
+#include "wd.h"
|
||||
+#include "wd_alg.h"
|
||||
+
|
||||
+#define SYS_CLASS_DIR "/sys/class/uacce"
|
||||
+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_accel_dev(const char *dev_name)
|
||||
+{
|
||||
+ struct dirent *dev_dir;
|
||||
+ DIR *wd_class;
|
||||
+
|
||||
+ wd_class = opendir(SYS_CLASS_DIR);
|
||||
+ if (!wd_class) {
|
||||
+ WD_ERR("UADK framework isn't enabled in system!\n");
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ while ((dev_dir = readdir(wd_class)) != NULL) {
|
||||
+ if (!strncmp(dev_dir->d_name, ".", LINUX_CRTDIR_SIZE) ||
|
||||
+ !strncmp(dev_dir->d_name, "..", LINUX_PRTDIR_SIZE))
|
||||
+ continue;
|
||||
+
|
||||
+ if (!strncmp(dev_dir->d_name, dev_name, strlen(dev_name))) {
|
||||
+ closedir(wd_class);
|
||||
+ return true;
|
||||
+ }
|
||||
+ }
|
||||
+ closedir(wd_class);
|
||||
+
|
||||
+ return false;
|
||||
+}
|
||||
+
|
||||
+int wd_alg_driver_register(struct wd_alg_driver *drv)
|
||||
+{
|
||||
+ struct wd_alg_list *new_alg;
|
||||
+
|
||||
+ if (!drv) {
|
||||
+ WD_ERR("invalid: register drv is NULL!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ new_alg = calloc(1, sizeof(struct wd_alg_list));
|
||||
+ if (!new_alg) {
|
||||
+ WD_ERR("failed to alloc alg driver memory!\n");
|
||||
+ return -WD_ENOMEM;
|
||||
+ }
|
||||
+
|
||||
+ new_alg->alg_name = drv->alg_name;
|
||||
+ new_alg->drv_name = drv->drv_name;
|
||||
+ new_alg->priority = drv->priority;
|
||||
+ 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;
|
||||
+ }
|
||||
+
|
||||
+ pthread_mutex_lock(&mutex);
|
||||
+ alg_list_tail->next = new_alg;
|
||||
+ alg_list_tail = new_alg;
|
||||
+ pthread_mutex_unlock(&mutex);
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+void wd_alg_driver_unregister(struct wd_alg_driver *drv)
|
||||
+{
|
||||
+ struct wd_alg_list *npre = &alg_list_head;
|
||||
+ struct wd_alg_list *pnext = npre->next;
|
||||
+
|
||||
+ /* Alg driver list has no drivers */
|
||||
+ if (!pnext || !drv)
|
||||
+ return;
|
||||
+
|
||||
+ 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) {
|
||||
+ break;
|
||||
+ }
|
||||
+ npre = pnext;
|
||||
+ pnext = pnext->next;
|
||||
+ }
|
||||
+
|
||||
+ /* The current algorithm is not registered */
|
||||
+ if (!pnext) {
|
||||
+ pthread_mutex_unlock(&mutex);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ /* Used to locate the problem and ensure symmetrical use driver */
|
||||
+ if (pnext->refcnt > 0)
|
||||
+ WD_ERR("driver<%s> still in used: %d\n", pnext->drv_name, pnext->refcnt);
|
||||
+
|
||||
+ if (pnext == alg_list_tail)
|
||||
+ alg_list_tail = npre;
|
||||
+
|
||||
+ npre->next = pnext->next;
|
||||
+ free(pnext);
|
||||
+ pthread_mutex_unlock(&mutex);
|
||||
+}
|
||||
+
|
||||
+struct wd_alg_list *wd_get_alg_head(void)
|
||||
+{
|
||||
+ return &alg_list_head;
|
||||
+}
|
||||
+
|
||||
+bool wd_drv_alg_support(const char *alg_name,
|
||||
+ struct wd_alg_driver *drv)
|
||||
+{
|
||||
+ struct wd_alg_list *head = &alg_list_head;
|
||||
+ struct wd_alg_list *pnext = head->next;
|
||||
+
|
||||
+ while (pnext) {
|
||||
+ if (!strcmp(alg_name, pnext->alg_name) &&
|
||||
+ !strcmp(drv->drv_name, pnext->drv_name)) {
|
||||
+ return true;
|
||||
+ }
|
||||
+ pnext = pnext->next;
|
||||
+ }
|
||||
+
|
||||
+ return false;
|
||||
+}
|
||||
+
|
||||
+void wd_enable_drv(struct wd_alg_driver *drv)
|
||||
+{
|
||||
+ struct wd_alg_list *head = &alg_list_head;
|
||||
+ struct wd_alg_list *pnext = head->next;
|
||||
+
|
||||
+ if (!pnext || !drv)
|
||||
+ return;
|
||||
+
|
||||
+ 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) {
|
||||
+ 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;
|
||||
+ }
|
||||
+ pthread_mutex_unlock(&mutex);
|
||||
+}
|
||||
+
|
||||
+void wd_disable_drv(struct wd_alg_driver *drv)
|
||||
+{
|
||||
+ struct wd_alg_list *head = &alg_list_head;
|
||||
+ struct wd_alg_list *pnext = head->next;
|
||||
+
|
||||
+ if (!pnext || !drv)
|
||||
+ return;
|
||||
+
|
||||
+ 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) {
|
||||
+ break;
|
||||
+ }
|
||||
+ pnext = pnext->next;
|
||||
+ }
|
||||
+
|
||||
+ pnext->available = false;
|
||||
+ pthread_mutex_unlock(&mutex);
|
||||
+}
|
||||
+
|
||||
+struct wd_alg_driver *wd_request_drv(const char *alg_name, bool hw_mask)
|
||||
+{
|
||||
+ struct wd_alg_list *head = &alg_list_head;
|
||||
+ struct wd_alg_list *pnext = head->next;
|
||||
+ struct wd_alg_list *select_node = NULL;
|
||||
+ struct wd_alg_driver *drv = NULL;
|
||||
+ int tmp_priority = -1;
|
||||
+
|
||||
+ if (!pnext || !alg_name) {
|
||||
+ WD_ERR("invalid: request alg param is error!\n");
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ /* Check the list to get an best driver */
|
||||
+ pthread_mutex_lock(&mutex);
|
||||
+ while (pnext) {
|
||||
+ /* hw_mask true mean not to used hardware dev */
|
||||
+ if (hw_mask && pnext->drv->priority == UADK_ALG_HW) {
|
||||
+ pnext = pnext->next;
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ if (!strcmp(alg_name, pnext->alg_name) && pnext->available &&
|
||||
+ pnext->drv->priority > tmp_priority) {
|
||||
+ tmp_priority = pnext->drv->priority;
|
||||
+ select_node = pnext;
|
||||
+ drv = pnext->drv;
|
||||
+ }
|
||||
+ pnext = pnext->next;
|
||||
+ }
|
||||
+
|
||||
+ if (select_node)
|
||||
+ select_node->refcnt++;
|
||||
+ pthread_mutex_unlock(&mutex);
|
||||
+
|
||||
+ return drv;
|
||||
+}
|
||||
+
|
||||
+void wd_release_drv(struct wd_alg_driver *drv)
|
||||
+{
|
||||
+ struct wd_alg_list *head = &alg_list_head;
|
||||
+ struct wd_alg_list *pnext = head->next;
|
||||
+ struct wd_alg_list *select_node = NULL;
|
||||
+
|
||||
+ if (!pnext || !drv)
|
||||
+ return;
|
||||
+
|
||||
+ 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) {
|
||||
+ select_node = pnext;
|
||||
+ break;
|
||||
+ }
|
||||
+ pnext = pnext->next;
|
||||
+ }
|
||||
+
|
||||
+ if (select_node && select_node->refcnt > 0)
|
||||
+ select_node->refcnt--;
|
||||
+ pthread_mutex_unlock(&mutex);
|
||||
+}
|
||||
+
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,74 +0,0 @@
|
||||
From 835ae83290197bd32b5c0e146221fc86f13d57da Mon Sep 17 00:00:00 2001
|
||||
From: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
Date: Thu, 15 Dec 2022 16:04:33 +0800
|
||||
Subject: [PATCH 4/4] uadk/ecc: bugfix incorrect parameter length
|
||||
|
||||
When check whether a 'struct wd_dtb' type variable is all
|
||||
zero, the length of the data should be the value of 'bsize'.
|
||||
Directly using 'dsize' may truncate the data in some cases
|
||||
and cause erroneous judgement.
|
||||
|
||||
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
---
|
||||
drv/hisi_hpre.c | 17 +++++++++++------
|
||||
1 file changed, 11 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
|
||||
index a172df5..d8b212d 100644
|
||||
--- a/drv/hisi_hpre.c
|
||||
+++ b/drv/hisi_hpre.c
|
||||
@@ -1054,11 +1054,16 @@ static void ecc_get_io_len(__u32 atype, __u32 hsz, size_t *ilen,
|
||||
}
|
||||
}
|
||||
|
||||
-static bool is_all_zero(struct wd_dtb *e, struct wd_ecc_msg *msg)
|
||||
+static bool is_all_zero(struct wd_dtb *e)
|
||||
{
|
||||
int i;
|
||||
|
||||
- for (i = 0; i < e->dsize && i < msg->key_bytes; i++) {
|
||||
+ if (!e || !e->data) {
|
||||
+ WD_ERR("invalid: e or e->data is NULL\n");
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ for (i = 0; i < e->bsize; i++) {
|
||||
if (e->data[i])
|
||||
return false;
|
||||
}
|
||||
@@ -1094,12 +1099,12 @@ static int ecc_prepare_sign_in(struct wd_ecc_msg *msg,
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
hw_msg->sm2_ksel = 1;
|
||||
- } else if (is_all_zero(k, msg)) {
|
||||
+ } else if (is_all_zero(k)) {
|
||||
WD_ERR("invalid: ecc sign in k all zero!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (is_all_zero(e, msg)) {
|
||||
+ if (is_all_zero(e)) {
|
||||
WD_ERR("invalid: ecc sign in e all zero!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -1141,7 +1146,7 @@ static int ecc_prepare_verf_in(struct wd_ecc_msg *msg,
|
||||
s = &vin->s;
|
||||
r = &vin->r;
|
||||
|
||||
- if (is_all_zero(e, msg)) {
|
||||
+ if (is_all_zero(e)) {
|
||||
WD_ERR("invalid: ecc verf in e all zero!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -1282,7 +1287,7 @@ static int u_is_in_p(struct wd_ecc_msg *msg)
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (is_all_zero(&pbk->x, msg)) {
|
||||
+ if (is_all_zero(&pbk->x)) {
|
||||
WD_ERR("invalid: ux is zero!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
191
0005-uadk-update-scheduler-for-dynamic-loading.patch
Normal file
191
0005-uadk-update-scheduler-for-dynamic-loading.patch
Normal file
@ -0,0 +1,191 @@
|
||||
From 73d26c1649aae62a361939ff22ccb67f93e3a0fa Mon Sep 17 00:00:00 2001
|
||||
From: Longfang Liu <liulongfang@huawei.com>
|
||||
Date: Sat, 7 Jan 2023 16:08:57 +0800
|
||||
Subject: [PATCH 05/28] uadk: update scheduler for dynamic loading
|
||||
|
||||
The dynamic loading function of uadk requires two new types of
|
||||
scheduler modes, which are used to adapt to instruction acceleration
|
||||
without hardware resources and SVE acceleration that needs to
|
||||
be bound to CPU cores.
|
||||
|
||||
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
|
||||
---
|
||||
include/wd_sched.h | 6 ++-
|
||||
wd_sched.c | 105 ++++++++++++++++++++++++++++++++++++++++++---
|
||||
2 files changed, 105 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/include/wd_sched.h b/include/wd_sched.h
|
||||
index 2ae6103..a492d70 100644
|
||||
--- a/include/wd_sched.h
|
||||
+++ b/include/wd_sched.h
|
||||
@@ -18,7 +18,11 @@ extern "C" {
|
||||
enum sched_policy_type {
|
||||
/* requests will be sent to ctxs one by one */
|
||||
SCHED_POLICY_RR = 0,
|
||||
- SCHED_POLICY_BUTT
|
||||
+ /* requests will no need ctxs */
|
||||
+ SCHED_POLICY_NONE,
|
||||
+ /* requests will need a fixed ctx */
|
||||
+ SCHED_POLICY_SINGLE,
|
||||
+ SCHED_POLICY_BUTT,
|
||||
};
|
||||
|
||||
struct sched_params {
|
||||
diff --git a/wd_sched.c b/wd_sched.c
|
||||
index 98f4cfd..9a52c4d 100644
|
||||
--- a/wd_sched.c
|
||||
+++ b/wd_sched.c
|
||||
@@ -347,6 +347,82 @@ static int session_sched_poll_policy(handle_t h_sched_ctx, __u32 expect, __u32 *
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static handle_t sched_none_init(handle_t h_sched_ctx, void *sched_param)
|
||||
+{
|
||||
+ return (handle_t)0;
|
||||
+}
|
||||
+
|
||||
+static __u32 sched_none_pick_next_ctx(handle_t sched_ctx,
|
||||
+ void *sched_key, const int sched_mode)
|
||||
+{
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int sched_none_poll_policy(handle_t h_sched_ctx,
|
||||
+ __u32 expect, __u32 *count)
|
||||
+{
|
||||
+ struct wd_sched_ctx *sched_ctx = (struct wd_sched_ctx *)h_sched_ctx;
|
||||
+ __u32 loop_times = MAX_POLL_TIMES + expect;
|
||||
+ __u32 poll_num = 0;
|
||||
+ int ret;
|
||||
+
|
||||
+ while (loop_times > 0) {
|
||||
+ /* Default use ctx 0 */
|
||||
+ ret = sched_ctx->poll_func(0, 1, &poll_num);
|
||||
+ if ((ret < 0) && (ret != -EAGAIN))
|
||||
+ return ret;
|
||||
+ else if (ret == -EAGAIN)
|
||||
+ continue;
|
||||
+
|
||||
+ *count += poll_num;
|
||||
+ if (*count == expect)
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static handle_t sched_single_init(handle_t h_sched_ctx, void *sched_param)
|
||||
+{
|
||||
+ return (handle_t)0;
|
||||
+}
|
||||
+
|
||||
+static __u32 sched_single_pick_next_ctx(handle_t sched_ctx,
|
||||
+ void *sched_key, const int sched_mode)
|
||||
+{
|
||||
+#define CTX_ASYNC 1
|
||||
+#define CTX_SYNC 0
|
||||
+
|
||||
+ if (sched_mode)
|
||||
+ return CTX_ASYNC;
|
||||
+ else
|
||||
+ return CTX_SYNC;
|
||||
+}
|
||||
+
|
||||
+static int sched_single_poll_policy(handle_t h_sched_ctx,
|
||||
+ __u32 expect, __u32 *count)
|
||||
+{
|
||||
+ struct wd_sched_ctx *sched_ctx = (struct wd_sched_ctx *)h_sched_ctx;
|
||||
+ __u32 loop_times = MAX_POLL_TIMES + expect;
|
||||
+ __u32 poll_num = 0;
|
||||
+ int ret;
|
||||
+
|
||||
+ while (loop_times > 0) {
|
||||
+ /* Default async mode use ctx 0 */
|
||||
+ ret = sched_ctx->poll_func(0, 1, &poll_num);
|
||||
+ if ((ret < 0) && (ret != -EAGAIN))
|
||||
+ return ret;
|
||||
+ else if (ret == -EAGAIN)
|
||||
+ continue;
|
||||
+
|
||||
+ *count += poll_num;
|
||||
+ if (*count == expect)
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
static struct wd_sched sched_table[SCHED_POLICY_BUTT] = {
|
||||
{
|
||||
.name = "RR scheduler",
|
||||
@@ -354,7 +430,19 @@ static struct wd_sched sched_table[SCHED_POLICY_BUTT] = {
|
||||
.sched_init = session_sched_init,
|
||||
.pick_next_ctx = session_sched_pick_next_ctx,
|
||||
.poll_policy = session_sched_poll_policy,
|
||||
- },
|
||||
+ }, {
|
||||
+ .name = "None scheduler",
|
||||
+ .sched_policy = SCHED_POLICY_SINGLE,
|
||||
+ .sched_init = sched_none_init,
|
||||
+ .pick_next_ctx = sched_none_pick_next_ctx,
|
||||
+ .poll_policy = sched_none_poll_policy,
|
||||
+ }, {
|
||||
+ .name = "Single scheduler",
|
||||
+ .sched_policy = SCHED_POLICY_SINGLE,
|
||||
+ .sched_init = sched_single_init,
|
||||
+ .pick_next_ctx = sched_single_pick_next_ctx,
|
||||
+ .poll_policy = sched_single_poll_policy,
|
||||
+ }
|
||||
};
|
||||
|
||||
static int wd_sched_get_nearby_numa_id(struct wd_sched_info *sched_info, int node, int numa_num)
|
||||
@@ -463,9 +551,12 @@ void wd_sched_rr_release(struct wd_sched *sched)
|
||||
|
||||
sched_ctx = (struct wd_sched_ctx *)sched->h_sched_ctx;
|
||||
if (!sched_ctx)
|
||||
- goto out;
|
||||
+ goto ctx_out;
|
||||
|
||||
sched_info = sched_ctx->sched_info;
|
||||
+ if (!sched_info)
|
||||
+ goto info_out;
|
||||
+
|
||||
for (i = 0; i < sched_ctx->numa_num; i++) {
|
||||
for (j = 0; j < SCHED_MODE_BUTT; j++) {
|
||||
if (sched_info[i].ctx_region[j]) {
|
||||
@@ -475,9 +566,9 @@ void wd_sched_rr_release(struct wd_sched *sched)
|
||||
}
|
||||
}
|
||||
|
||||
+info_out:
|
||||
free(sched_ctx);
|
||||
-
|
||||
-out:
|
||||
+ctx_out:
|
||||
free(sched);
|
||||
|
||||
return;
|
||||
@@ -531,8 +622,11 @@ struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num,
|
||||
}
|
||||
|
||||
sched->h_sched_ctx = (handle_t)sched_ctx;
|
||||
- sched_info = sched_ctx->sched_info;
|
||||
+ if (sched_type == SCHED_POLICY_NONE ||
|
||||
+ sched_type == SCHED_POLICY_SINGLE)
|
||||
+ goto simple_ok;
|
||||
|
||||
+ sched_info = sched_ctx->sched_info;
|
||||
for (i = 0; i < numa_num; i++) {
|
||||
for (j = 0; j < SCHED_MODE_BUTT; j++) {
|
||||
sched_info[i].ctx_region[j] =
|
||||
@@ -542,6 +636,7 @@ struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num,
|
||||
}
|
||||
}
|
||||
|
||||
+simple_ok:
|
||||
sched_ctx->poll_func = func;
|
||||
sched_ctx->policy = sched_type;
|
||||
sched_ctx->type_num = type_num;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
745
0006-uadk-improve-the-dynamic-loading-public-framework.patch
Normal file
745
0006-uadk-improve-the-dynamic-loading-public-framework.patch
Normal file
@ -0,0 +1,745 @@
|
||||
From ac2eb4e38e8aed5ca7bacec00186158145dd459e Mon Sep 17 00:00:00 2001
|
||||
From: Longfang Liu <liulongfang@huawei.com>
|
||||
Date: Sat, 7 Jan 2023 16:08:58 +0800
|
||||
Subject: [PATCH 06/28] uadk: improve the dynamic loading public framework
|
||||
|
||||
After the dynamic loading function is added, device resource
|
||||
initialization, driver acquisition, and scheduler initialization
|
||||
functions need to be extracted into the public framework.
|
||||
|
||||
so that the algorithm can quickly adapt to the dynamic loading
|
||||
function internally.
|
||||
|
||||
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
|
||||
---
|
||||
include/wd_alg_common.h | 10 +
|
||||
include/wd_util.h | 63 ++++-
|
||||
wd_comp.c | 2 +-
|
||||
wd_util.c | 549 +++++++++++++++++++++++++++++++++++++++-
|
||||
4 files changed, 620 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h
|
||||
index d04b046..31208ad 100644
|
||||
--- a/include/wd_alg_common.h
|
||||
+++ b/include/wd_alg_common.h
|
||||
@@ -28,6 +28,13 @@ extern "C" {
|
||||
#define CTX_TYPE_INVALID 9999
|
||||
#define POLL_TIME 1000
|
||||
|
||||
+enum alg_task_type {
|
||||
+ TASK_MIX = 0x0,
|
||||
+ TASK_HW,
|
||||
+ TASK_INSTR,
|
||||
+ TASK_MAX_TYPE,
|
||||
+};
|
||||
+
|
||||
enum wd_ctx_mode {
|
||||
CTX_MODE_SYNC = 0,
|
||||
CTX_MODE_ASYNC,
|
||||
@@ -130,6 +137,9 @@ struct wd_sched {
|
||||
handle_t h_sched_ctx;
|
||||
};
|
||||
|
||||
+typedef int (*wd_alg_init)(struct wd_ctx_config *config, struct wd_sched *sched);
|
||||
+typedef int (*wd_alg_poll_ctx)(__u32 idx, __u32 expt, __u32 *count);
|
||||
+
|
||||
struct wd_datalist {
|
||||
void *data;
|
||||
__u32 len;
|
||||
diff --git a/include/wd_util.h b/include/wd_util.h
|
||||
index d4b2814..a730f36 100644
|
||||
--- a/include/wd_util.h
|
||||
+++ b/include/wd_util.h
|
||||
@@ -117,9 +117,12 @@ struct wd_msg_handle {
|
||||
struct wd_init_attrs {
|
||||
__u32 sched_type;
|
||||
char *alg;
|
||||
+ struct wd_alg_driver *driver;
|
||||
struct wd_sched *sched;
|
||||
struct wd_ctx_params *ctx_params;
|
||||
struct wd_ctx_config *ctx_config;
|
||||
+ wd_alg_init alg_init;
|
||||
+ wd_alg_poll_ctx alg_poll_ctx;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -415,13 +418,69 @@ static inline void wd_alg_clear_init(enum wd_status *status)
|
||||
}
|
||||
|
||||
/**
|
||||
- * wd_alg_pre_init() - Request the ctxs and initialize the sched_domain
|
||||
+ * wd_ctx_param_init() - Initialize the current device driver according
|
||||
+ * to the obtained queue resource and the applied driver.
|
||||
+ * @config: device resources requested by the current algorithm.
|
||||
+ * @driver: device driver for the current algorithm application.
|
||||
+ * @drv_priv: the parameter pointer of the current device driver.
|
||||
+ *
|
||||
+ * Return 0 if succeed and other error number if fail.
|
||||
+ */
|
||||
+int wd_ctx_param_init(struct wd_ctx_params *ctx_params,
|
||||
+ struct wd_ctx_params *user_ctx_params,
|
||||
+ struct wd_ctx_nums *ctx_set_num,
|
||||
+ struct wd_alg_driver *driver, int max_op_type);
|
||||
+
|
||||
+/**
|
||||
+ * wd_alg_attrs_init() - Request the ctxs and initialize the sched_domain
|
||||
* with the given devices list, ctxs number and numa mask.
|
||||
* @attrs: the algorithm initialization parameters.
|
||||
*
|
||||
* Return device if succeed and other error number if fail.
|
||||
*/
|
||||
-int wd_alg_pre_init(struct wd_init_attrs *attrs);
|
||||
+int wd_alg_attrs_init(struct wd_init_attrs *attrs);
|
||||
+void wd_alg_attrs_uninit(struct wd_init_attrs *attrs);
|
||||
+
|
||||
+/**
|
||||
+ * wd_alg_drv_bind() - Request the ctxs and initialize the sched_domain
|
||||
+ * with the given devices list, ctxs number and numa mask.
|
||||
+ * @task_type: the type of task specified by the current algorithm.
|
||||
+ * @alg_name: the name of the algorithm specified by the task.
|
||||
+ *
|
||||
+ * Return device driver if succeed and other NULL if fail.
|
||||
+ */
|
||||
+struct wd_alg_driver *wd_alg_drv_bind(int task_type, char *alg_name);
|
||||
+void wd_alg_drv_unbind(struct wd_alg_driver *drv);
|
||||
+
|
||||
+/**
|
||||
+ * wd_alg_init_driver() - Initialize the current device driver according
|
||||
+ * to the obtained queue resource and the applied driver.
|
||||
+ * @config: device resources requested by the current algorithm.
|
||||
+ * @driver: device driver for the current algorithm application.
|
||||
+ * @drv_priv: the parameter pointer of the current device driver.
|
||||
+ *
|
||||
+ * Return 0 if succeed and other error number if fail.
|
||||
+ */
|
||||
+int wd_alg_init_driver(struct wd_ctx_config_internal *config,
|
||||
+ struct wd_alg_driver *driver, void **drv_priv);
|
||||
+void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
|
||||
+ struct wd_alg_driver *driver, void **drv_priv);
|
||||
+
|
||||
+/**
|
||||
+ * wd_dlopen_drv() - Open the dynamic library file of the device driver.
|
||||
+ * @cust_lib_dir: the file path of the dynamic library file.
|
||||
+ */
|
||||
+void *wd_dlopen_drv(const char *cust_lib_dir);
|
||||
+void wd_dlclose_drv(void *dlh_list);
|
||||
+
|
||||
+/**
|
||||
+ * wd_get_lib_file_path() - Find the path of the dynamic library file in
|
||||
+ * the current system.
|
||||
+ * @lib_file: the name of the library file.
|
||||
+ * @lib_path: the found dynamic library file path.
|
||||
+ * @is_dir: Specify whether to query the file dir or the file path.
|
||||
+ */
|
||||
+int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir);
|
||||
|
||||
/**
|
||||
* wd_dfx_msg_cnt() - Message counter interface for ctx
|
||||
diff --git a/wd_comp.c b/wd_comp.c
|
||||
index cca6eb9..ecfa573 100644
|
||||
--- a/wd_comp.c
|
||||
+++ b/wd_comp.c
|
||||
@@ -248,7 +248,7 @@ int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_par
|
||||
wd_comp_sched->name = SCHED_RR_NAME;
|
||||
wd_comp_init_attrs.sched = wd_comp_sched;
|
||||
|
||||
- ret = wd_alg_pre_init(&wd_comp_init_attrs);
|
||||
+ ret = wd_alg_attrs_init(&wd_comp_init_attrs);
|
||||
if (ret)
|
||||
goto out_freesched;
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 433dd56..dab4fc8 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -5,6 +5,8 @@
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
+#include <dirent.h>
|
||||
+#include <dlfcn.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <string.h>
|
||||
@@ -23,6 +25,8 @@
|
||||
#define WD_INIT_SLEEP_UTIME 1000
|
||||
#define WD_INIT_RETRY_TIMES 10000
|
||||
|
||||
+#define DEF_DRV_LIB_FILE "libwd.so"
|
||||
+
|
||||
struct msg_pool {
|
||||
/* message array allocated dynamically */
|
||||
void *msgs;
|
||||
@@ -64,6 +68,72 @@ struct async_task_queue {
|
||||
int (*alg_poll_ctx)(__u32, __u32, __u32 *);
|
||||
};
|
||||
|
||||
+struct drv_lib_list {
|
||||
+ void *dlhandle;
|
||||
+ struct drv_lib_list *next;
|
||||
+};
|
||||
+
|
||||
+struct acc_alg_item {
|
||||
+ char *name;
|
||||
+ char *algtype;
|
||||
+};
|
||||
+
|
||||
+static struct acc_alg_item alg_options[] = {
|
||||
+ {"zlib", "zlib-deflate"},
|
||||
+ {"gzip", "gzip"},
|
||||
+ {"deflate", "deflate"},
|
||||
+ {"lz77_zstd", "lz77_zstd"},
|
||||
+
|
||||
+ {"rsa", "rsa"},
|
||||
+ {"dh", "dh"},
|
||||
+ {"ecdh", "ecdh"},
|
||||
+ {"x25519", "x25519"},
|
||||
+ {"x448", "x448"},
|
||||
+ {"ecdsa", "ecdsa"},
|
||||
+ {"sm2", "sm2"},
|
||||
+
|
||||
+ {"ecb(aes)", "cipher"},
|
||||
+ {"cbc(aes)", "cipher"},
|
||||
+ {"xts(aes)", "cipher"},
|
||||
+ {"ofb(aes)", "cipher"},
|
||||
+ {"cfb(aes)", "cipher"},
|
||||
+ {"ctr(aes)", "cipher"},
|
||||
+ {"cbc-cs1(aes)", "cipher"},
|
||||
+ {"cbc-cs2(aes)", "cipher"},
|
||||
+ {"cbc-cs3(aes)", "cipher"},
|
||||
+ {"ecb(sm4)", "cipher"},
|
||||
+ {"xts(sm4)", "cipher"},
|
||||
+ {"cbc(sm4)", "cipher"},
|
||||
+ {"ofb(sm4)", "cipher"},
|
||||
+ {"cfb(sm4)", "cipher"},
|
||||
+ {"ctr(sm4)", "cipher"},
|
||||
+ {"cbc-cs1(sm4)", "cipher"},
|
||||
+ {"cbc-cs2(sm4)", "cipher"},
|
||||
+ {"cbc-cs3(sm4)", "cipher"},
|
||||
+ {"ecb(des)", "cipher"},
|
||||
+ {"cbc(des)", "cipher"},
|
||||
+ {"ecb(des3_ede)", "cipher"},
|
||||
+ {"cbc(des3_ede)", "cipher"},
|
||||
+
|
||||
+ {"ccm(aes)", "aead"},
|
||||
+ {"gcm(aes)", "aead"},
|
||||
+ {"ccm(sm4)", "aead"},
|
||||
+ {"gcm(sm4)", "aead"},
|
||||
+ {"authenc(hmac(sha256),cbc(aes))", "aead"},
|
||||
+ {"authenc(hmac(sha256),cbc(sm4))", "aead"},
|
||||
+
|
||||
+ {"sm3", "digest"},
|
||||
+ {"md5", "digest"},
|
||||
+ {"sha1", "digest"},
|
||||
+ {"sha256", "digest"},
|
||||
+ {"sha224", "digest"},
|
||||
+ {"sha384", "digest"},
|
||||
+ {"sha512", "digest"},
|
||||
+ {"sha512-224", "digest"},
|
||||
+ {"sha512-256", "digest"},
|
||||
+ {"", ""}
|
||||
+};
|
||||
+
|
||||
static void clone_ctx_to_internal(struct wd_ctx *ctx,
|
||||
struct wd_ctx_internal *ctx_in)
|
||||
{
|
||||
@@ -1779,6 +1849,358 @@ int wd_init_param_check(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static void wd_get_alg_type(const char *alg_name, char *alg_type)
|
||||
+{
|
||||
+ int i;
|
||||
+
|
||||
+ for (i = 0; i < ARRAY_SIZE(alg_options); i++) {
|
||||
+ if (strcmp(alg_name, alg_options[i].name) == 0) {
|
||||
+ (void)strcpy(alg_type, alg_options[i].algtype);
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/**
|
||||
+ * There are many other .so files in this file directory (/root/lib/),
|
||||
+ * and it is necessary to screen out valid uadk driver files
|
||||
+ * through this function.
|
||||
+ */
|
||||
+static int file_check_valid(char *lib_file)
|
||||
+{
|
||||
+#define FILE_HEAD_SZ 4
|
||||
+#define FILE_TAIL_SZ 4
|
||||
+ int file_len = strlen(lib_file);
|
||||
+ char file_head[FILE_HEAD_SZ] = "lib";
|
||||
+ char file_tail[FILE_TAIL_SZ] = ".so";
|
||||
+ int i, j;
|
||||
+
|
||||
+ /* Lib file name is libxx_xxx.so */
|
||||
+ for (i = 0; i < FILE_HEAD_SZ - 1; i++) {
|
||||
+ if (lib_file[i] != file_head[i])
|
||||
+ return -EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ for (i = file_len - (FILE_TAIL_SZ - 1), j = 0;
|
||||
+ i < file_len && j < FILE_TAIL_SZ; i++, j++) {
|
||||
+ if (lib_file[i] != file_tail[j])
|
||||
+ return -EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int wd_alg_init_fallback(struct wd_alg_driver *fb_driver)
|
||||
+{
|
||||
+ if (!fb_driver->init) {
|
||||
+ WD_ERR("soft sec driver have no init interface.\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ fb_driver->init(NULL, NULL);
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static void wd_alg_uninit_fallback(struct wd_alg_driver *fb_driver)
|
||||
+{
|
||||
+ if (!fb_driver->exit) {
|
||||
+ WD_ERR("soft sec driver have no exit interface.\n");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ fb_driver->exit(NULL);
|
||||
+}
|
||||
+
|
||||
+int wd_alg_init_driver(struct wd_ctx_config_internal *config,
|
||||
+ struct wd_alg_driver *driver, void **drv_priv)
|
||||
+{
|
||||
+ void *priv;
|
||||
+ int ret;
|
||||
+
|
||||
+ /* Init ctx related resources in specific driver */
|
||||
+ priv = calloc(1, driver->priv_size);
|
||||
+ if (!priv)
|
||||
+ return -WD_ENOMEM;
|
||||
+
|
||||
+ if (!driver->init) {
|
||||
+ driver->fallback = 0;
|
||||
+ WD_ERR("driver have no init interface.\n");
|
||||
+ ret = -WD_EINVAL;
|
||||
+ goto err_alloc;
|
||||
+ }
|
||||
+
|
||||
+ ret = driver->init(config, priv);
|
||||
+ if (ret < 0) {
|
||||
+ WD_ERR("driver init failed.\n");
|
||||
+ goto err_alloc;
|
||||
+ }
|
||||
+
|
||||
+ if (driver->fallback) {
|
||||
+ ret = wd_alg_init_fallback((struct wd_alg_driver *)driver->fallback);
|
||||
+ if (ret) {
|
||||
+ driver->fallback = 0;
|
||||
+ WD_ERR("soft alg driver init failed.\n");
|
||||
+ }
|
||||
+ }
|
||||
+ *drv_priv = priv;
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+err_alloc:
|
||||
+ free(priv);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
|
||||
+ struct wd_alg_driver *driver, void **drv_priv)
|
||||
+{
|
||||
+ void *priv = *drv_priv;
|
||||
+
|
||||
+ driver->exit(priv);
|
||||
+ /* Ctx config just need clear once */
|
||||
+ if (driver->priority == UADK_ALG_HW)
|
||||
+ wd_clear_ctx_config(config);
|
||||
+
|
||||
+ if (driver->fallback)
|
||||
+ wd_alg_uninit_fallback((struct wd_alg_driver *)driver->fallback);
|
||||
+
|
||||
+ if (priv) {
|
||||
+ free(priv);
|
||||
+ priv = NULL;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void wd_dlclose_drv(void *dlh_list)
|
||||
+{
|
||||
+ struct drv_lib_list *dlhead = (struct drv_lib_list *)dlh_list;
|
||||
+ struct drv_lib_list *dlnode;
|
||||
+
|
||||
+ if (!dlhead) {
|
||||
+ WD_INFO("driver so file list is empty.\n");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ while (dlhead) {
|
||||
+ dlnode = dlhead;
|
||||
+ dlhead = dlhead->next;
|
||||
+ dlclose(dlnode);
|
||||
+ free(dlnode);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static void add_lib_to_list(struct drv_lib_list *head,
|
||||
+ struct drv_lib_list *node)
|
||||
+{
|
||||
+ struct drv_lib_list *tmp = head;
|
||||
+
|
||||
+ while (tmp->next)
|
||||
+ tmp = tmp->next;
|
||||
+
|
||||
+ tmp->next = node;
|
||||
+}
|
||||
+
|
||||
+int wd_ctx_param_init(struct wd_ctx_params *ctx_params,
|
||||
+ struct wd_ctx_params *user_ctx_params,
|
||||
+ struct wd_ctx_nums *ctx_set_num,
|
||||
+ struct wd_alg_driver *driver, int max_op_type)
|
||||
+{
|
||||
+ int i;
|
||||
+
|
||||
+ if (!user_ctx_params) {
|
||||
+ ctx_params->bmp = NULL;
|
||||
+ ctx_params->ctx_set_num = ctx_set_num;
|
||||
+ ctx_params->op_type_num = driver->op_type_num;
|
||||
+ if (ctx_params->op_type_num > max_op_type) {
|
||||
+ WD_ERR("fail to check driver op type numbers.\n");
|
||||
+ return -WD_EAGAIN;
|
||||
+ }
|
||||
+
|
||||
+ for (i = 0; i < ctx_params->op_type_num; i++) {
|
||||
+ ctx_set_num[i].sync_ctx_num = driver->queue_num;
|
||||
+ ctx_set_num[i].async_ctx_num = driver->queue_num;
|
||||
+ }
|
||||
+ } else {
|
||||
+ ctx_params->bmp = user_ctx_params->bmp;
|
||||
+ ctx_params->ctx_set_num = user_ctx_params->ctx_set_num;
|
||||
+ ctx_params->op_type_num = user_ctx_params->op_type_num;
|
||||
+ if (ctx_params->op_type_num > max_op_type) {
|
||||
+ WD_ERR("fail to check user op type numbers.\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static void dladdr_empty(void) {}
|
||||
+int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir)
|
||||
+{
|
||||
+ char file_path[PATH_STR_SIZE] = {0};
|
||||
+ Dl_info file_info;
|
||||
+ int len, rc, i;
|
||||
+
|
||||
+ /* Get libwd.so file's system path */
|
||||
+ rc = dladdr((void *)dladdr_empty, &file_info);
|
||||
+ if (!rc) {
|
||||
+ WD_ERR("fail to get lib file path.\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+ strncpy(file_path, file_info.dli_fname, PATH_STR_SIZE - 1);
|
||||
+
|
||||
+ /* Clear the file path's tail file name */
|
||||
+ len = strlen(file_path) - 1;
|
||||
+ for (i = len; i >= 0; i--) {
|
||||
+ if (file_path[i] == '/') {
|
||||
+ memset(&file_path[i], 0, PATH_STR_SIZE - i + 1);
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (is_dir) {
|
||||
+ (void)snprintf(lib_path, PATH_STR_SIZE, "%s", file_path);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ len = snprintf(lib_path, PATH_STR_SIZE, "%s/%s", file_path, lib_file);
|
||||
+ if (len < 0)
|
||||
+ return -WD_EINVAL;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+void *wd_dlopen_drv(const char *cust_lib_dir)
|
||||
+{
|
||||
+ typedef int (*alg_ops)(struct wd_alg_driver *drv);
|
||||
+ struct drv_lib_list *node, *head = NULL;
|
||||
+ char lib_dir_path[PATH_STR_SIZE] = {0};
|
||||
+ char lib_path[PATH_STR_SIZE] = {0};
|
||||
+ struct dirent *lib_dir;
|
||||
+ alg_ops dl_func = NULL;
|
||||
+ DIR *wd_dir;
|
||||
+ int ret;
|
||||
+
|
||||
+ if (!cust_lib_dir) {
|
||||
+ ret = wd_get_lib_file_path(NULL, lib_dir_path, true);
|
||||
+ if (ret)
|
||||
+ return NULL;
|
||||
+ } else {
|
||||
+ (void)snprintf(lib_path, PATH_STR_SIZE, "%s/%s", cust_lib_dir, DEF_DRV_LIB_FILE);
|
||||
+ ret = access(lib_path, F_OK);
|
||||
+ if (ret)
|
||||
+ return NULL;
|
||||
+
|
||||
+ strncpy(lib_dir_path, cust_lib_dir, PATH_STR_SIZE - 1);
|
||||
+ }
|
||||
+
|
||||
+ wd_dir = opendir(lib_dir_path);
|
||||
+ if (!wd_dir) {
|
||||
+ WD_ERR("UADK driver lib dir: %s not exist!\n", lib_dir_path);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ while ((lib_dir = readdir(wd_dir)) != NULL) {
|
||||
+ if (!strncmp(lib_dir->d_name, ".", LINUX_CRTDIR_SIZE) ||
|
||||
+ !strncmp(lib_dir->d_name, "..", LINUX_PRTDIR_SIZE))
|
||||
+ continue;
|
||||
+
|
||||
+ ret = file_check_valid(lib_dir->d_name);
|
||||
+ if (ret)
|
||||
+ continue;
|
||||
+
|
||||
+ node = calloc(1, sizeof(*node));
|
||||
+ if (!node)
|
||||
+ goto free_list;
|
||||
+
|
||||
+ ret = snprintf(lib_path, PATH_STR_SIZE, "%s/%s", lib_dir_path, lib_dir->d_name);
|
||||
+ if (ret < 0)
|
||||
+ goto free_node;
|
||||
+
|
||||
+ node->dlhandle = dlopen(lib_path, RTLD_NOW);
|
||||
+ if (!node->dlhandle) {
|
||||
+ free(node);
|
||||
+ /* there are many other files need to skip */
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ dl_func = dlsym(node->dlhandle, "wd_alg_driver_register");
|
||||
+ if (dl_func == NULL) {
|
||||
+ dlclose(node->dlhandle);
|
||||
+ free(node);
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ if (!head)
|
||||
+ head = node;
|
||||
+ else
|
||||
+ add_lib_to_list(head, node);
|
||||
+ }
|
||||
+ closedir(wd_dir);
|
||||
+
|
||||
+ return (void *)head;
|
||||
+
|
||||
+free_node:
|
||||
+ free(node);
|
||||
+free_list:
|
||||
+ closedir(wd_dir);
|
||||
+ wd_dlclose_drv(head);
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
+struct wd_alg_driver *wd_alg_drv_bind(int task_type, char *alg_name)
|
||||
+{
|
||||
+ struct wd_alg_driver *set_driver = NULL;
|
||||
+ struct wd_alg_driver *drv;
|
||||
+
|
||||
+ /* Get alg driver and dev name */
|
||||
+ switch (task_type) {
|
||||
+ case TASK_INSTR:
|
||||
+ drv = wd_request_drv(alg_name, true);
|
||||
+ if (!drv) {
|
||||
+ WD_ERR("no soft %s driver support\n", alg_name);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ set_driver = drv;
|
||||
+ set_driver->fallback = 0;
|
||||
+ break;
|
||||
+ case TASK_HW:
|
||||
+ case TASK_MIX:
|
||||
+ drv = wd_request_drv(alg_name, false);
|
||||
+ if (!drv) {
|
||||
+ WD_ERR("no HW %s driver support\n", alg_name);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ set_driver = drv;
|
||||
+ set_driver->fallback = 0;
|
||||
+ if (task_type == TASK_MIX) {
|
||||
+ drv = wd_request_drv(alg_name, true);
|
||||
+ if (!drv) {
|
||||
+ set_driver->fallback = 0;
|
||||
+ WD_ERR("no soft %s driver support\n", alg_name);
|
||||
+ } else {
|
||||
+ set_driver->fallback = (handle_t)drv;
|
||||
+ WD_ERR("successful to get soft driver\n");
|
||||
+ }
|
||||
+ }
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ return set_driver;
|
||||
+}
|
||||
+
|
||||
+void wd_alg_drv_unbind(struct wd_alg_driver *drv)
|
||||
+{
|
||||
+ struct wd_alg_driver *fb_drv = NULL;
|
||||
+
|
||||
+ if (!drv)
|
||||
+ return;
|
||||
+
|
||||
+ fb_drv = (struct wd_alg_driver *)drv->fallback;
|
||||
+ if (fb_drv)
|
||||
+ wd_release_drv(fb_drv);
|
||||
+ wd_release_drv(drv);
|
||||
+}
|
||||
+
|
||||
bool wd_alg_try_init(enum wd_status *status)
|
||||
{
|
||||
enum wd_status expected;
|
||||
@@ -1960,7 +2382,7 @@ free_ctxs:
|
||||
return ret;
|
||||
}
|
||||
|
||||
-int wd_alg_pre_init(struct wd_init_attrs *attrs)
|
||||
+static int wd_alg_ctx_init(struct wd_init_attrs *attrs)
|
||||
{
|
||||
struct wd_ctx_config *ctx_config = attrs->ctx_config;
|
||||
struct wd_ctx_params *ctx_params = attrs->ctx_params;
|
||||
@@ -2034,3 +2456,128 @@ out_freelist:
|
||||
|
||||
return ret;
|
||||
}
|
||||
+
|
||||
+static void wd_alg_ctx_uninit(struct wd_ctx_config *ctx_config)
|
||||
+{
|
||||
+ int i;
|
||||
+
|
||||
+ for (i = 0; i < ctx_config->ctx_num; i++)
|
||||
+ if (ctx_config->ctxs[i].ctx) {
|
||||
+ wd_release_ctx(ctx_config->ctxs[i].ctx);
|
||||
+ ctx_config->ctxs[i].ctx = 0;
|
||||
+ }
|
||||
+
|
||||
+ free(ctx_config->ctxs);
|
||||
+}
|
||||
+
|
||||
+int wd_alg_attrs_init(struct wd_init_attrs *attrs)
|
||||
+{
|
||||
+ wd_alg_poll_ctx alg_poll_func = attrs->alg_poll_ctx;
|
||||
+ wd_alg_init alg_init_func = attrs->alg_init;
|
||||
+ __u32 sched_type = attrs->sched_type;
|
||||
+ struct wd_ctx_config *ctx_config = NULL;
|
||||
+ struct wd_sched *alg_sched = NULL;
|
||||
+ char alg_type[WD_NAME_SIZE];
|
||||
+ char *alg = attrs->alg;
|
||||
+ int driver_type = UADK_ALG_HW;
|
||||
+ int ret;
|
||||
+
|
||||
+ if (!attrs->ctx_params)
|
||||
+ return -WD_EINVAL;
|
||||
+
|
||||
+ if (attrs->driver)
|
||||
+ driver_type = attrs->driver->priority;
|
||||
+
|
||||
+ switch (driver_type) {
|
||||
+ case UADK_ALG_SOFT:
|
||||
+ case UADK_ALG_CE_INSTR:
|
||||
+ /* No need to alloc resource */
|
||||
+ if (sched_type != SCHED_POLICY_NONE)
|
||||
+ return -WD_EINVAL;
|
||||
+
|
||||
+ alg_sched = wd_sched_rr_alloc(SCHED_POLICY_NONE, 1, 1, alg_poll_func);
|
||||
+ if (!alg_sched) {
|
||||
+ WD_ERR("fail to alloc scheduler\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+ attrs->sched = alg_sched;
|
||||
+
|
||||
+ ret = wd_sched_rr_instance(alg_sched, NULL);
|
||||
+ if (ret) {
|
||||
+ WD_ERR("fail to instance scheduler\n");
|
||||
+ goto out_freesched;
|
||||
+ }
|
||||
+ break;
|
||||
+ case UADK_ALG_SVE_INSTR:
|
||||
+ /* Todo lock cpu core */
|
||||
+ if (sched_type != SCHED_POLICY_SINGLE)
|
||||
+ return -WD_EINVAL;
|
||||
+
|
||||
+ alg_sched = wd_sched_rr_alloc(SCHED_POLICY_SINGLE, 1, 1, alg_poll_func);
|
||||
+ if (!alg_sched) {
|
||||
+ WD_ERR("fail to alloc scheduler\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+ attrs->sched = alg_sched;
|
||||
+
|
||||
+ ret = wd_sched_rr_instance(alg_sched, NULL);
|
||||
+ if (ret) {
|
||||
+ WD_ERR("fail to instance scheduler\n");
|
||||
+ goto out_freesched;
|
||||
+ }
|
||||
+ break;
|
||||
+ case UADK_ALG_HW:
|
||||
+ wd_get_alg_type(alg, alg_type);
|
||||
+ attrs->alg = alg_type;
|
||||
+
|
||||
+ ctx_config = calloc(1, sizeof(*ctx_config));
|
||||
+ if (!ctx_config) {
|
||||
+ WD_ERR("fail to alloc ctx config\n");
|
||||
+ return -WD_ENOMEM;
|
||||
+ }
|
||||
+ attrs->ctx_config = ctx_config;
|
||||
+
|
||||
+ alg_sched = wd_sched_rr_alloc(sched_type, attrs->ctx_params->op_type_num,
|
||||
+ numa_max_node() + 1, alg_poll_func);
|
||||
+ if (!alg_sched) {
|
||||
+ WD_ERR("fail to instance scheduler\n");
|
||||
+ ret = -WD_EINVAL;
|
||||
+ goto out_ctx_config;
|
||||
+ }
|
||||
+ attrs->sched = alg_sched;
|
||||
+
|
||||
+ ret = wd_alg_ctx_init(attrs);
|
||||
+ if (ret) {
|
||||
+ WD_ERR("fail to init ctx\n");
|
||||
+ goto out_freesched;
|
||||
+ }
|
||||
+
|
||||
+ ret = alg_init_func(ctx_config, alg_sched);
|
||||
+ if (ret)
|
||||
+ goto out_pre_init;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+out_pre_init:
|
||||
+ wd_alg_ctx_uninit(ctx_config);
|
||||
+out_freesched:
|
||||
+ wd_sched_rr_release(alg_sched);
|
||||
+out_ctx_config:
|
||||
+ if (ctx_config)
|
||||
+ free(ctx_config);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void wd_alg_attrs_uninit(struct wd_init_attrs *attrs)
|
||||
+{
|
||||
+ struct wd_ctx_config *ctx_config = attrs->ctx_config;
|
||||
+ struct wd_sched *alg_sched = attrs->sched;
|
||||
+
|
||||
+ if (ctx_config) {
|
||||
+ wd_alg_ctx_uninit(ctx_config);
|
||||
+ free(ctx_config);
|
||||
+ }
|
||||
+ wd_sched_rr_release(alg_sched);
|
||||
+}
|
||||
+
|
||||
--
|
||||
2.25.1
|
||||
|
||||
452
0007-uadk-doc-adding-dynamically-loaded-design-documents.patch
Normal file
452
0007-uadk-doc-adding-dynamically-loaded-design-documents.patch
Normal file
File diff suppressed because one or more lines are too long
119
0008-uadk-added-ability-to-query-supported-algorithms.patch
Normal file
119
0008-uadk-added-ability-to-query-supported-algorithms.patch
Normal file
@ -0,0 +1,119 @@
|
||||
From d5c95ee9c68f6be540805a14d1743bf05c712574 Mon Sep 17 00:00:00 2001
|
||||
From: Longfang Liu <liulongfang@huawei.com>
|
||||
Date: Sat, 7 Jan 2023 16:09:00 +0800
|
||||
Subject: [PATCH 08/28] uadk: added ability to query supported algorithms
|
||||
|
||||
After the driver dynamic loading function is added, the corresponding
|
||||
function of querying all algorithms supported on the current UADK
|
||||
is added.
|
||||
|
||||
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
|
||||
---
|
||||
include/wd.h | 12 +++++++++++
|
||||
wd.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++-
|
||||
2 files changed, 67 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/include/wd.h b/include/wd.h
|
||||
index e102fe2..21af7ff 100644
|
||||
--- a/include/wd.h
|
||||
+++ b/include/wd.h
|
||||
@@ -29,6 +29,7 @@ extern "C" {
|
||||
#define LINUX_PRTDIR_SIZE 2
|
||||
#define WD_CTX_CNT_NUM 1024
|
||||
#define WD_IPC_KEY 0x500011
|
||||
+#define CRYPTO_MAX_ALG_NAME 128
|
||||
|
||||
/* Required compiler attributes */
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
@@ -578,6 +579,17 @@ bool wd_need_debug(void);
|
||||
*/
|
||||
bool wd_need_info(void);
|
||||
|
||||
+struct wd_capability {
|
||||
+ char alg_name[CRYPTO_MAX_ALG_NAME];
|
||||
+ char drv_name[CRYPTO_MAX_ALG_NAME];
|
||||
+ int priority;
|
||||
+
|
||||
+ struct wd_capability *next;
|
||||
+};
|
||||
+
|
||||
+struct wd_capability *wd_get_alg_cap(void);
|
||||
+void wd_release_alg_cap(struct wd_capability *head);
|
||||
+
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
diff --git a/wd.c b/wd.c
|
||||
index 4f75113..b6286b5 100644
|
||||
--- a/wd.c
|
||||
+++ b/wd.c
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <sched.h>
|
||||
|
||||
#include "wd.h"
|
||||
-
|
||||
+#include "wd_alg.h"
|
||||
#define SYS_CLASS_DIR "/sys/class/uacce"
|
||||
|
||||
enum UADK_LOG_LEVEL {
|
||||
@@ -882,3 +882,57 @@ char *wd_ctx_get_dev_name(handle_t h_ctx)
|
||||
|
||||
return ctx->dev_name;
|
||||
}
|
||||
+
|
||||
+void wd_release_alg_cap(struct wd_capability *head)
|
||||
+{
|
||||
+ struct wd_capability *cap_pnext = head;
|
||||
+ struct wd_capability *cap_node = NULL;
|
||||
+
|
||||
+ while (cap_pnext) {
|
||||
+ cap_node = cap_pnext;
|
||||
+ cap_pnext = cap_pnext->next;
|
||||
+ free(cap_node);
|
||||
+ }
|
||||
+
|
||||
+ if (head)
|
||||
+ free(head);
|
||||
+}
|
||||
+
|
||||
+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;
|
||||
+
|
||||
+ while (pnext) {
|
||||
+ cap_node = calloc(1, sizeof(struct wd_capability));
|
||||
+ if (!cap_head) {
|
||||
+ 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->priority = pnext->priority;
|
||||
+ cap_node->next = NULL;
|
||||
+
|
||||
+ cap_pnext->next = cap_node;
|
||||
+ cap_pnext = cap_node;
|
||||
+ pnext = pnext->next;
|
||||
+ if (i == 0) {
|
||||
+ cap_head = cap_node;
|
||||
+ cap_pnext = cap_head;
|
||||
+ }
|
||||
+ i++;
|
||||
+ }
|
||||
+
|
||||
+ return cap_head;
|
||||
+
|
||||
+alloc_err:
|
||||
+ wd_release_alg_cap(cap_head);
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
--
|
||||
2.25.1
|
||||
|
||||
534
0009-uadk-zip-Adapt-the-zip-module-to-the-dynamic-loading.patch
Normal file
534
0009-uadk-zip-Adapt-the-zip-module-to-the-dynamic-loading.patch
Normal file
@ -0,0 +1,534 @@
|
||||
From f827469bc5734934e9488d4d5f5d842132c6d168 Mon Sep 17 00:00:00 2001
|
||||
From: Longfang Liu <liulongfang@huawei.com>
|
||||
Date: Sat, 7 Jan 2023 16:09:01 +0800
|
||||
Subject: [PATCH 09/28] uadk/zip: Adapt the zip module to the dynamic loading
|
||||
framework
|
||||
|
||||
After adding the zip module of the init2 interface, combine its
|
||||
initialization part with dynamic loading, and transform the HiSilicon
|
||||
driver of zip, and use the dynamic loading function to realize the
|
||||
connection between the driver and the algorithm layer.
|
||||
|
||||
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
|
||||
---
|
||||
drv/hisi_comp.c | 59 +++++++--
|
||||
include/drv/wd_comp_drv.h | 27 -----
|
||||
wd_comp.c | 243 ++++++++++++++++++++------------------
|
||||
3 files changed, 175 insertions(+), 154 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
|
||||
index 2eede39..01e2ad8 100644
|
||||
--- a/drv/hisi_comp.c
|
||||
+++ b/drv/hisi_comp.c
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
#define ZLIB_HEADER "\x78\x9c"
|
||||
#define ZLIB_HEADER_SZ 2
|
||||
-
|
||||
+#define ZIP_CTX_Q_NUM_DEF 1
|
||||
/*
|
||||
* We use a extra field for gzip block length. So the fourth byte is \x04.
|
||||
* This is necessary because our software don't know the size of block when
|
||||
@@ -771,8 +771,9 @@ static void hisi_zip_sqe_ops_adapt(handle_t h_qp)
|
||||
}
|
||||
}
|
||||
|
||||
-static int hisi_zip_init(struct wd_ctx_config_internal *config, void *priv)
|
||||
+static int hisi_zip_init(void *conf, void *priv)
|
||||
{
|
||||
+ struct wd_ctx_config_internal *config = conf;
|
||||
struct hisi_zip_ctx *zip_ctx = (struct hisi_zip_ctx *)priv;
|
||||
struct hisi_qm_priv qm_priv;
|
||||
handle_t h_qp = 0;
|
||||
@@ -1055,14 +1056,50 @@ static int hisi_zip_comp_recv(handle_t ctx, void *comp_msg)
|
||||
return parse_zip_sqe(qp, &sqe, recv_msg);
|
||||
}
|
||||
|
||||
-struct wd_comp_driver hisi_zip = {
|
||||
- .drv_name = "hisi_zip",
|
||||
- .alg_name = "zlib\ngzip\ndeflate\nlz77_zstd",
|
||||
- .drv_ctx_size = sizeof(struct hisi_zip_ctx),
|
||||
- .init = hisi_zip_init,
|
||||
- .exit = hisi_zip_exit,
|
||||
- .comp_send = hisi_zip_comp_send,
|
||||
- .comp_recv = hisi_zip_comp_recv,
|
||||
+#define GEN_ZIP_ALG_DRIVER(zip_alg_name) \
|
||||
+{\
|
||||
+ .drv_name = "hisi_zip",\
|
||||
+ .alg_name = zip_alg_name,\
|
||||
+ .priority = UADK_ALG_HW,\
|
||||
+ .priv_size = sizeof(struct hisi_zip_ctx),\
|
||||
+ .queue_num = ZIP_CTX_Q_NUM_DEF,\
|
||||
+ .op_type_num = 2,\
|
||||
+ .fallback = 0,\
|
||||
+ .init = hisi_zip_init,\
|
||||
+ .exit = hisi_zip_exit,\
|
||||
+ .send = hisi_zip_comp_send,\
|
||||
+ .recv = hisi_zip_comp_recv,\
|
||||
+}
|
||||
+
|
||||
+static struct wd_alg_driver zip_alg_driver[] = {
|
||||
+ GEN_ZIP_ALG_DRIVER("zlib"),
|
||||
+ GEN_ZIP_ALG_DRIVER("gzip"),
|
||||
+
|
||||
+ GEN_ZIP_ALG_DRIVER("deflate"),
|
||||
+ GEN_ZIP_ALG_DRIVER("lz77_zstd"),
|
||||
};
|
||||
|
||||
-WD_COMP_SET_DRIVER(hisi_zip);
|
||||
+static void __attribute__((constructor)) hisi_zip_probe(void)
|
||||
+{
|
||||
+ int alg_num = ARRAY_SIZE(zip_alg_driver);
|
||||
+ int i, ret;
|
||||
+
|
||||
+ WD_INFO("Info: register ZIP alg drivers!\n");
|
||||
+
|
||||
+ for (i = 0; i < alg_num; i++) {
|
||||
+ ret = wd_alg_driver_register(&zip_alg_driver[i]);
|
||||
+ if (ret)
|
||||
+ WD_ERR("Error: register ZIP %s failed!\n",
|
||||
+ zip_alg_driver[i].alg_name);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static void __attribute__((destructor)) hisi_zip_remove(void)
|
||||
+{
|
||||
+ int alg_num = ARRAY_SIZE(zip_alg_driver);
|
||||
+ int i;
|
||||
+
|
||||
+ for (i = 0; i < alg_num; i++)
|
||||
+ wd_alg_driver_unregister(&zip_alg_driver[i]);
|
||||
+}
|
||||
+
|
||||
diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h
|
||||
index 4aeaee4..213cf2d 100644
|
||||
--- a/include/drv/wd_comp_drv.h
|
||||
+++ b/include/drv/wd_comp_drv.h
|
||||
@@ -55,35 +55,8 @@ struct wd_comp_msg {
|
||||
__u32 tag;
|
||||
};
|
||||
|
||||
-struct wd_comp_driver {
|
||||
- const char *drv_name;
|
||||
- const char *alg_name;
|
||||
- __u32 drv_ctx_size;
|
||||
- int (*init)(struct wd_ctx_config_internal *config, void *priv);
|
||||
- void (*exit)(void *priv);
|
||||
- int (*comp_send)(handle_t ctx, void *comp_msg);
|
||||
- int (*comp_recv)(handle_t ctx, void *comp_msg);
|
||||
-};
|
||||
-
|
||||
-void wd_comp_set_driver(struct wd_comp_driver *drv);
|
||||
-struct wd_comp_driver *wd_comp_get_driver(void);
|
||||
-
|
||||
struct wd_comp_msg *wd_comp_get_msg(__u32 idx, __u32 tag);
|
||||
|
||||
-#ifdef WD_STATIC_DRV
|
||||
-#define WD_COMP_SET_DRIVER(drv) \
|
||||
-struct wd_comp_driver *wd_comp_get_driver(void) \
|
||||
-{ \
|
||||
- return &drv; \
|
||||
-}
|
||||
-#else
|
||||
-#define WD_COMP_SET_DRIVER(drv) \
|
||||
-static void __attribute__((constructor)) set_comp_driver(void) \
|
||||
-{ \
|
||||
- wd_comp_set_driver(&(drv)); \
|
||||
-}
|
||||
-#endif
|
||||
-
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
diff --git a/wd_comp.c b/wd_comp.c
|
||||
index ecfa573..b7e0eb7 100644
|
||||
--- a/wd_comp.c
|
||||
+++ b/wd_comp.c
|
||||
@@ -19,8 +19,6 @@
|
||||
#define HW_CTX_SIZE (64 * 1024)
|
||||
#define STREAM_CHUNK (128 * 1024)
|
||||
|
||||
-#define SCHED_RR_NAME "sched_rr"
|
||||
-
|
||||
#define swap_byte(x) \
|
||||
((((x) & 0x000000ff) << 24) | \
|
||||
(((x) & 0x0000ff00) << 8) | \
|
||||
@@ -42,56 +40,61 @@ struct wd_comp_sess {
|
||||
|
||||
struct wd_comp_setting {
|
||||
enum wd_status status;
|
||||
- enum wd_status status2;
|
||||
struct wd_ctx_config_internal config;
|
||||
struct wd_sched sched;
|
||||
- struct wd_comp_driver *driver;
|
||||
+ struct wd_async_msg_pool pool;
|
||||
+ struct wd_alg_driver *driver;
|
||||
void *priv;
|
||||
void *dlhandle;
|
||||
- struct wd_async_msg_pool pool;
|
||||
+ void *dlh_list;
|
||||
} wd_comp_setting;
|
||||
|
||||
struct wd_env_config wd_comp_env_config;
|
||||
-
|
||||
static struct wd_init_attrs wd_comp_init_attrs;
|
||||
-static struct wd_ctx_config wd_comp_ctx;
|
||||
-static struct wd_sched *wd_comp_sched;
|
||||
-
|
||||
-static struct wd_ctx_nums wd_comp_ctx_num[] = {
|
||||
- {1, 1}, {1, 1}, {}
|
||||
-};
|
||||
|
||||
-static struct wd_ctx_params wd_comp_ctx_params = {
|
||||
- .op_type_num = WD_DIR_MAX,
|
||||
- .ctx_set_num = wd_comp_ctx_num,
|
||||
- .bmp = NULL,
|
||||
-};
|
||||
-
|
||||
-#ifdef WD_STATIC_DRV
|
||||
-static void wd_comp_set_static_drv(void)
|
||||
+static void wd_comp_close_driver(void)
|
||||
{
|
||||
- wd_comp_setting.driver = wd_comp_get_driver();
|
||||
- if (!wd_comp_setting.driver)
|
||||
- WD_ERR("failed to get driver!\n");
|
||||
+ if (wd_comp_setting.dlhandle) {
|
||||
+ wd_release_drv(wd_comp_setting.driver);
|
||||
+ dlclose(wd_comp_setting.dlhandle);
|
||||
+ wd_comp_setting.dlhandle = NULL;
|
||||
+ }
|
||||
}
|
||||
-#else
|
||||
-static void __attribute__((constructor)) wd_comp_open_driver(void)
|
||||
+
|
||||
+static int wd_comp_open_driver(void)
|
||||
{
|
||||
- wd_comp_setting.dlhandle = dlopen("libhisi_zip.so", RTLD_NOW);
|
||||
- if (!wd_comp_setting.dlhandle)
|
||||
+ struct wd_alg_driver *driver = NULL;
|
||||
+ char lib_path[PATH_STR_SIZE];
|
||||
+ const char *alg_name = "zlib";
|
||||
+ int ret;
|
||||
+
|
||||
+ /*
|
||||
+ * Compatible with the normal acquisition of device
|
||||
+ * drivers in the init interface
|
||||
+ */
|
||||
+ if (wd_comp_setting.dlh_list)
|
||||
+ return 0;
|
||||
+
|
||||
+ ret = wd_get_lib_file_path("libhisi_zip.so", lib_path, false);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+
|
||||
+ wd_comp_setting.dlhandle = dlopen(lib_path, RTLD_NOW);
|
||||
+ if (!wd_comp_setting.dlhandle) {
|
||||
WD_ERR("failed to open libhisi_zip.so, %s\n", dlerror());
|
||||
-}
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
|
||||
-static void __attribute__((destructor)) wd_comp_close_driver(void)
|
||||
-{
|
||||
- if (wd_comp_setting.dlhandle)
|
||||
- dlclose(wd_comp_setting.dlhandle);
|
||||
-}
|
||||
-#endif
|
||||
+ driver = wd_request_drv(alg_name, false);
|
||||
+ if (!driver) {
|
||||
+ wd_comp_close_driver();
|
||||
+ WD_ERR("failed to get %s driver support\n", alg_name);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
|
||||
-void wd_comp_set_driver(struct wd_comp_driver *drv)
|
||||
-{
|
||||
- wd_comp_setting.driver = drv;
|
||||
+ wd_comp_setting.driver = driver;
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static void wd_comp_clear_status(void)
|
||||
@@ -101,13 +104,8 @@ static void wd_comp_clear_status(void)
|
||||
|
||||
static int wd_comp_init_nolock(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- void *priv;
|
||||
int ret;
|
||||
|
||||
- ret = wd_init_param_check(config, sched);
|
||||
- if (ret)
|
||||
- return ret;
|
||||
-
|
||||
ret = wd_set_epoll_en("WD_COMP_EPOLL_EN",
|
||||
&wd_comp_setting.config.epoll_en);
|
||||
if (ret < 0)
|
||||
@@ -120,19 +118,6 @@ static int wd_comp_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
|
||||
ret = wd_init_sched(&wd_comp_setting.sched, sched);
|
||||
if (ret < 0)
|
||||
goto out_clear_ctx_config;
|
||||
- /*
|
||||
- * Fix me: ctx could be passed into wd_comp_set_static_drv to help to
|
||||
- * choose static compiled vendor driver. For dynamic vendor driver,
|
||||
- * wd_comp_open_driver will be called in the process of opening
|
||||
- * libwd_comp.so to load related driver dynamic library. Vendor driver
|
||||
- * pointer will be passed to wd_comp_setting.driver in the process of
|
||||
- * opening of vendor driver dynamic library. A configure file could be
|
||||
- * introduced to help to define which vendor driver lib should be
|
||||
- * loaded.
|
||||
- */
|
||||
-#ifdef WD_STATIC_DRV
|
||||
- wd_comp_set_static_drv();
|
||||
-#endif
|
||||
|
||||
/* fix me: sadly find we allocate async pool for every ctx */
|
||||
ret = wd_init_async_request_pool(&wd_comp_setting.pool,
|
||||
@@ -141,24 +126,14 @@ static int wd_comp_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
|
||||
if (ret < 0)
|
||||
goto out_clear_sched;
|
||||
|
||||
- /* init ctx related resources in specific driver */
|
||||
- priv = calloc(1, wd_comp_setting.driver->drv_ctx_size);
|
||||
- if (!priv) {
|
||||
- ret = -WD_ENOMEM;
|
||||
+ ret = wd_alg_init_driver(&wd_comp_setting.config,
|
||||
+ wd_comp_setting.driver,
|
||||
+ &wd_comp_setting.priv);
|
||||
+ if (ret)
|
||||
goto out_clear_pool;
|
||||
- }
|
||||
- wd_comp_setting.priv = priv;
|
||||
- ret = wd_comp_setting.driver->init(&wd_comp_setting.config, priv);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to do driver init, ret = %d!\n", ret);
|
||||
- goto out_free_priv;
|
||||
- }
|
||||
|
||||
return 0;
|
||||
|
||||
-out_free_priv:
|
||||
- free(priv);
|
||||
- wd_comp_setting.priv = NULL;
|
||||
out_clear_pool:
|
||||
wd_uninit_async_request_pool(&wd_comp_setting.pool);
|
||||
out_clear_sched:
|
||||
@@ -175,16 +150,14 @@ static void wd_comp_uninit_nolock(void)
|
||||
if (!priv)
|
||||
return;
|
||||
|
||||
- wd_comp_setting.driver->exit(priv);
|
||||
- free(priv);
|
||||
- wd_comp_setting.priv = NULL;
|
||||
-
|
||||
/* uninit async request pool */
|
||||
wd_uninit_async_request_pool(&wd_comp_setting.pool);
|
||||
|
||||
/* unset config, sched, driver */
|
||||
wd_clear_sched(&wd_comp_setting.sched);
|
||||
- wd_clear_ctx_config(&wd_comp_setting.config);
|
||||
+
|
||||
+ wd_alg_uninit_driver(&wd_comp_setting.config,
|
||||
+ wd_comp_setting.driver, &priv);
|
||||
}
|
||||
|
||||
int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
@@ -198,28 +171,43 @@ int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
if (!flag)
|
||||
return 0;
|
||||
|
||||
+ ret = wd_init_param_check(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ ret = wd_comp_open_driver();
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
ret = wd_comp_init_nolock(config, sched);
|
||||
- if (ret) {
|
||||
- wd_alg_clear_init(&wd_comp_setting.status);
|
||||
- goto out;
|
||||
- }
|
||||
+ if (ret)
|
||||
+ goto out_clear_driver;
|
||||
|
||||
wd_alg_set_init(&wd_comp_setting.status);
|
||||
|
||||
-out:
|
||||
+ return 0;
|
||||
+
|
||||
+out_clear_driver:
|
||||
+ wd_comp_close_driver();
|
||||
+out_clear_init:
|
||||
+ wd_alg_clear_init(&wd_comp_setting.status);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void wd_comp_uninit(void)
|
||||
{
|
||||
wd_comp_uninit_nolock();
|
||||
+
|
||||
+ wd_comp_close_driver();
|
||||
wd_alg_clear_init(&wd_comp_setting.status);
|
||||
}
|
||||
|
||||
int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params)
|
||||
{
|
||||
+ struct wd_ctx_nums comp_ctx_num[WD_DIR_MAX] = {0};
|
||||
+ struct wd_ctx_params comp_ctx_params;
|
||||
+ int ret = 0;
|
||||
bool flag;
|
||||
- int ret;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_comp_clear_status);
|
||||
|
||||
@@ -227,61 +215,84 @@ int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_par
|
||||
if (!flag)
|
||||
return 0;
|
||||
|
||||
- if (!alg) {
|
||||
- WD_ERR("invalid: alg is NULL!\n");
|
||||
+ 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;
|
||||
}
|
||||
|
||||
- wd_comp_init_attrs.alg = alg;
|
||||
- wd_comp_init_attrs.sched_type = sched_type;
|
||||
+ /*
|
||||
+ * Driver lib file path could set by env param.
|
||||
+ * than 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");
|
||||
+ goto out_uninit;
|
||||
+ }
|
||||
|
||||
- wd_comp_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_comp_ctx_params;
|
||||
- wd_comp_init_attrs.ctx_config = &wd_comp_ctx;
|
||||
+res_retry:
|
||||
+ memset(&wd_comp_setting.config, 0, sizeof(struct wd_ctx_config_internal));
|
||||
|
||||
- wd_comp_sched = wd_sched_rr_alloc(sched_type, wd_comp_init_attrs.ctx_params->op_type_num,
|
||||
- numa_max_node() + 1, wd_comp_poll_ctx);
|
||||
- if (!wd_comp_sched) {
|
||||
- ret = -WD_EINVAL;
|
||||
- goto out_uninit;
|
||||
+ /* Get alg driver and dev name */
|
||||
+ wd_comp_setting.driver = wd_alg_drv_bind(task_type, alg);
|
||||
+ if (!wd_comp_setting.driver) {
|
||||
+ WD_ERR("fail to bind a valid driver.\n");
|
||||
+ goto out_dlopen;
|
||||
}
|
||||
- wd_comp_sched->name = SCHED_RR_NAME;
|
||||
- wd_comp_init_attrs.sched = wd_comp_sched;
|
||||
|
||||
- ret = wd_alg_attrs_init(&wd_comp_init_attrs);
|
||||
- if (ret)
|
||||
- goto out_freesched;
|
||||
+ ret = wd_ctx_param_init(&comp_ctx_params, ctx_params,
|
||||
+ comp_ctx_num, wd_comp_setting.driver,
|
||||
+ WD_DIR_MAX);
|
||||
+ if (ret) {
|
||||
+ if (ret == -WD_EAGAIN) {
|
||||
+ wd_disable_drv(wd_comp_setting.driver);
|
||||
+ wd_alg_drv_unbind(wd_comp_setting.driver);
|
||||
+ goto res_retry;
|
||||
+ }
|
||||
+ goto out_driver;
|
||||
+ }
|
||||
|
||||
- ret = wd_comp_init_nolock(&wd_comp_ctx, wd_comp_sched);
|
||||
- if (ret)
|
||||
- goto out_freesched;
|
||||
+ wd_comp_init_attrs.alg = alg;
|
||||
+ wd_comp_init_attrs.sched_type = sched_type;
|
||||
+ wd_comp_init_attrs.driver = wd_comp_setting.driver;
|
||||
+ wd_comp_init_attrs.ctx_params = &comp_ctx_params;
|
||||
+ wd_comp_init_attrs.alg_init = wd_comp_init_nolock;
|
||||
+ wd_comp_init_attrs.alg_poll_ctx = wd_comp_poll_ctx;
|
||||
+ ret = wd_alg_attrs_init(&wd_comp_init_attrs);
|
||||
+ if (ret) {
|
||||
+ if (ret == -WD_ENODEV) {
|
||||
+ wd_disable_drv(wd_comp_setting.driver);
|
||||
+ wd_alg_drv_unbind(wd_comp_setting.driver);
|
||||
+ goto res_retry;
|
||||
+ }
|
||||
+ WD_ERR("fail to init alg attrs.\n");
|
||||
+ goto out_driver;
|
||||
+ }
|
||||
|
||||
wd_alg_set_init(&wd_comp_setting.status);
|
||||
|
||||
return 0;
|
||||
|
||||
-out_freesched:
|
||||
- wd_sched_rr_release(wd_comp_sched);
|
||||
-
|
||||
+out_driver:
|
||||
+ wd_alg_drv_unbind(wd_comp_setting.driver);
|
||||
+out_dlopen:
|
||||
+ wd_dlclose_drv(wd_comp_setting.dlh_list);
|
||||
out_uninit:
|
||||
wd_alg_clear_init(&wd_comp_setting.status);
|
||||
-
|
||||
return ret;
|
||||
}
|
||||
|
||||
void wd_comp_uninit2(void)
|
||||
{
|
||||
- int i;
|
||||
-
|
||||
wd_comp_uninit_nolock();
|
||||
|
||||
- for (i = 0; i < wd_comp_ctx.ctx_num; i++)
|
||||
- if (wd_comp_ctx.ctxs[i].ctx) {
|
||||
- wd_release_ctx(wd_comp_ctx.ctxs[i].ctx);
|
||||
- wd_comp_ctx.ctxs[i].ctx = 0;
|
||||
- }
|
||||
-
|
||||
- wd_sched_rr_release(wd_comp_sched);
|
||||
+ 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_setting.dlh_list = NULL;
|
||||
wd_alg_clear_init(&wd_comp_setting.status);
|
||||
}
|
||||
|
||||
@@ -315,7 +326,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
||||
ctx = config->ctxs + idx;
|
||||
|
||||
do {
|
||||
- ret = wd_comp_setting.driver->comp_recv(ctx->ctx, &resp_msg);
|
||||
+ ret = wd_comp_setting.driver->recv(ctx->ctx, &resp_msg);
|
||||
if (unlikely(ret < 0)) {
|
||||
if (ret == -WD_HW_EACCESS)
|
||||
WD_ERR("wd comp recv hw error!\n");
|
||||
@@ -546,8 +557,8 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess,
|
||||
wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx);
|
||||
ctx = config->ctxs + idx;
|
||||
|
||||
- msg_handle.send = wd_comp_setting.driver->comp_send;
|
||||
- msg_handle.recv = wd_comp_setting.driver->comp_recv;
|
||||
+ msg_handle.send = wd_comp_setting.driver->send;
|
||||
+ msg_handle.recv = wd_comp_setting.driver->recv;
|
||||
|
||||
pthread_spin_lock(&ctx->lock);
|
||||
ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg,
|
||||
@@ -806,7 +817,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
|
||||
msg->tag = tag;
|
||||
msg->stream_mode = WD_COMP_STATELESS;
|
||||
|
||||
- ret = wd_comp_setting.driver->comp_send(ctx->ctx, msg);
|
||||
+ ret = wd_comp_setting.driver->send(ctx->ctx, msg);
|
||||
if (unlikely(ret < 0)) {
|
||||
WD_ERR("wd comp send error, ret = %d!\n", ret);
|
||||
goto fail_with_msg;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
98
0010-uadk-libs-update-compile-options.patch
Normal file
98
0010-uadk-libs-update-compile-options.patch
Normal file
@ -0,0 +1,98 @@
|
||||
From 019cc3dd67eb90e7a131c1ad04bfde20de0d25a7 Mon Sep 17 00:00:00 2001
|
||||
From: Longfang Liu <liulongfang@huawei.com>
|
||||
Date: Wed, 28 Dec 2022 09:56:04 +0800
|
||||
Subject: [PATCH 10/28] uadk/libs: update compile options
|
||||
|
||||
On the new uadk framework, dynamic library loading functions such
|
||||
as dlopen are used, and corresponding compilation options need to
|
||||
be added -ldl.
|
||||
|
||||
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
|
||||
---
|
||||
Makefile.am | 4 ++--
|
||||
sample/Makefile.am | 2 +-
|
||||
test/Makefile.am | 4 ++--
|
||||
test/hisi_sec_test/Makefile.am | 2 +-
|
||||
test/hisi_zip_test/Makefile.am | 2 +-
|
||||
5 files changed, 7 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/Makefile.am b/Makefile.am
|
||||
index 1ea6d6b..bd7b36f 100644
|
||||
--- a/Makefile.am
|
||||
+++ b/Makefile.am
|
||||
@@ -86,7 +86,7 @@ if WD_STATIC_DRV
|
||||
AM_CFLAGS += -DWD_STATIC_DRV
|
||||
AM_CFLAGS += -DWD_NO_LOG
|
||||
|
||||
-libwd_la_LIBADD = $(libwd_la_OBJECTS) -lnuma
|
||||
+libwd_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma
|
||||
|
||||
libwd_comp_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma
|
||||
libwd_comp_la_DEPENDENCIES = libwd.la
|
||||
@@ -108,7 +108,7 @@ UADK_COMP_SYMBOL= -Wl,--version-script,$(top_srcdir)/libwd_comp.map
|
||||
UADK_V1_SYMBOL= -Wl,--version-script,$(top_srcdir)/v1/libwd.map
|
||||
|
||||
libwd_la_LDFLAGS=$(UADK_VERSION) $(UADK_WD_SYMBOL) $(UADK_V1_SYMBOL)
|
||||
-libwd_la_LIBADD= -lnuma
|
||||
+libwd_la_LIBADD= -ldl -lnuma
|
||||
|
||||
libwd_comp_la_LIBADD= -lwd -ldl -lnuma
|
||||
libwd_comp_la_LDFLAGS=$(UADK_VERSION) $(UADK_COMP_SYMBOL)
|
||||
diff --git a/sample/Makefile.am b/sample/Makefile.am
|
||||
index eb8d71b..2f2d5ac 100644
|
||||
--- a/sample/Makefile.am
|
||||
+++ b/sample/Makefile.am
|
||||
@@ -9,7 +9,7 @@ if WD_STATIC_DRV
|
||||
AM_CFLAGS+=-Bstatic
|
||||
uadk_comp_LDADD=../.libs/libwd.a \
|
||||
../.libs/libwd_comp.a \
|
||||
- ../.libs/libhisi_zip.a -lpthread -lnuma
|
||||
+ ../.libs/libhisi_zip.a -ldl -lpthread -lnuma
|
||||
else
|
||||
uadk_comp_LDADD=-L../.libs -l:libwd.so.2 -l:libwd_comp.so.2 -lpthread -lnuma
|
||||
endif
|
||||
diff --git a/test/Makefile.am b/test/Makefile.am
|
||||
index 860a103..87b97ca 100644
|
||||
--- a/test/Makefile.am
|
||||
+++ b/test/Makefile.am
|
||||
@@ -6,9 +6,9 @@ wd_mempool_test_SOURCES=wd_mempool_test.c
|
||||
if WD_STATIC_DRV
|
||||
AM_CFLAGS+=-Bstatic
|
||||
wd_mempool_test_LDADD=../.libs/libwd.a ../.libs/libwd_crypto.a \
|
||||
- ../.libs/libhisi_sec.a -lnuma -lpthread
|
||||
+ ../.libs/libhisi_sec.a -ldl -lnuma -lpthread
|
||||
else
|
||||
-wd_mempool_test_LDADD=-L../.libs -lwd -lwd_crypto -lnuma -lpthread
|
||||
+wd_mempool_test_LDADD=-L../.libs -lwd -ldl -lwd_crypto -lnuma -lpthread
|
||||
endif
|
||||
wd_mempool_test_LDFLAGS=-Wl,-rpath,'/usr/local/lib'
|
||||
|
||||
diff --git a/test/hisi_sec_test/Makefile.am b/test/hisi_sec_test/Makefile.am
|
||||
index 9955ab1..61506d4 100644
|
||||
--- a/test/hisi_sec_test/Makefile.am
|
||||
+++ b/test/hisi_sec_test/Makefile.am
|
||||
@@ -8,7 +8,7 @@ test_hisi_sec_SOURCES=test_hisi_sec.c
|
||||
if WD_STATIC_DRV
|
||||
AM_CFLAGS+=-Bstatic
|
||||
test_hisi_sec_LDADD=../../.libs/libwd.a ../../.libs/libwd_crypto.a \
|
||||
- ../../.libs/libhisi_sec.a -lnuma
|
||||
+ ../../.libs/libhisi_sec.a -ldl -lnuma
|
||||
else
|
||||
test_hisi_sec_LDADD=-L../../.libs -l:libwd.so.2 -l:libwd_crypto.so.2 -lnuma
|
||||
endif
|
||||
diff --git a/test/hisi_zip_test/Makefile.am b/test/hisi_zip_test/Makefile.am
|
||||
index 0782ef7..f671582 100644
|
||||
--- a/test/hisi_zip_test/Makefile.am
|
||||
+++ b/test/hisi_zip_test/Makefile.am
|
||||
@@ -7,7 +7,7 @@ zip_sva_perf_SOURCES=test_sva_perf.c test_lib.c testsuit.c
|
||||
|
||||
if WD_STATIC_DRV
|
||||
zip_sva_perf_LDADD=../../.libs/libwd.a ../../.libs/libwd_comp.a \
|
||||
- ../../.libs/libhisi_zip.a -lpthread -lnuma $(libcrypto_LIBS)
|
||||
+ ../../.libs/libhisi_zip.a -ldl -lpthread -lnuma $(libcrypto_LIBS)
|
||||
else
|
||||
zip_sva_perf_LDADD=-L../../.libs -l:libwd.so.2 -l:libwd_comp.so.2 \
|
||||
-lpthread -lnuma $(libcrypto_LIBS)
|
||||
--
|
||||
2.25.1
|
||||
|
||||
233
0011-uadk-ecc-add-the-init2-interface-for-ecc.patch
Normal file
233
0011-uadk-ecc-add-the-init2-interface-for-ecc.patch
Normal file
@ -0,0 +1,233 @@
|
||||
From 8d581b8f1ddbc6858c51487b8addbe10efade7d1 Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Sat, 11 Feb 2023 15:19:29 +0800
|
||||
Subject: [PATCH 11/28] uadk/ecc: add the init2 interface for ecc
|
||||
|
||||
This set of interfaces puts resource initialization
|
||||
operations into the init2 interface, simplifying the
|
||||
initialization operations when users use the ecc algorithm.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
include/wd_ecc.h | 28 ++++++++++++
|
||||
libwd_crypto.map | 3 ++
|
||||
wd_ecc.c | 109 ++++++++++++++++++++++++++++++++++++++---------
|
||||
3 files changed, 121 insertions(+), 19 deletions(-)
|
||||
|
||||
diff --git a/include/wd_ecc.h b/include/wd_ecc.h
|
||||
index a92bb4b..6f670e2 100644
|
||||
--- a/include/wd_ecc.h
|
||||
+++ b/include/wd_ecc.h
|
||||
@@ -432,6 +432,34 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched);
|
||||
*/
|
||||
void wd_ecc_uninit(void);
|
||||
|
||||
+/**
|
||||
+ * wd_ecc_init2_() - A simplify interface to initializate ecc.
|
||||
+ * This interface keeps most functions of
|
||||
+ * wd_ecc_init(). Users just need to descripe the deployment of
|
||||
+ * business scenarios. Then the initialization will request appropriate
|
||||
+ * resources to support the business scenarios.
|
||||
+ * To make the initializate simpler, ctx_params support set NULL.
|
||||
+ * And then the function will set them as default.
|
||||
+ * Please do not use this interface with wd_ecc_init() together, or
|
||||
+ * some resources may be leak.
|
||||
+ *
|
||||
+ * @alg: The algorithm users want to use.
|
||||
+ * @sched_type: The scheduling type users want to use.
|
||||
+ * @task_type: Reserved.
|
||||
+ * @ctx_params: The ctxs resources users want to use. Include per operation
|
||||
+ * type ctx numbers and business process run numa.
|
||||
+ *
|
||||
+ * Return 0 if succeed and others if fail.
|
||||
+ */
|
||||
+int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params);
|
||||
+
|
||||
+#define wd_ecc_init2(alg, sched_type, task_type) \
|
||||
+ wd_ecc_init2_(alg, sched_type, task_type, NULL)
|
||||
+
|
||||
+/**
|
||||
+ * wd_ecc_uninit2() - Uninitialise ctx configuration and scheduler.
|
||||
+ */
|
||||
+void wd_ecc_uninit2(void);
|
||||
|
||||
/**
|
||||
* wd_ecc_alloc_sess() - Allocate a wd ecc session.
|
||||
diff --git a/libwd_crypto.map b/libwd_crypto.map
|
||||
index 5fadc53..2983f20 100644
|
||||
--- a/libwd_crypto.map
|
||||
+++ b/libwd_crypto.map
|
||||
@@ -154,6 +154,9 @@ global:
|
||||
wd_ecdsa_get_sign_out_params;
|
||||
wd_ecc_init;
|
||||
wd_ecc_uninit;
|
||||
+ wd_ecc_init2;
|
||||
+ wd_ecc_init2_;
|
||||
+ wd_ecc_uninit2;
|
||||
wd_ecc_alloc_sess;
|
||||
wd_ecc_free_sess;
|
||||
wd_ecc_poll;
|
||||
diff --git a/wd_ecc.c b/wd_ecc.c
|
||||
index 99811b5..4cad1e4 100644
|
||||
--- a/wd_ecc.c
|
||||
+++ b/wd_ecc.c
|
||||
@@ -74,6 +74,17 @@ static struct wd_ecc_setting {
|
||||
} wd_ecc_setting;
|
||||
|
||||
struct wd_env_config wd_ecc_env_config;
|
||||
+static struct wd_init_attrs wd_ecc_init_attrs;
|
||||
+
|
||||
+static struct wd_ctx_nums wd_ecc_ctx_num[] = {
|
||||
+ {1, 1}, {}
|
||||
+};
|
||||
+
|
||||
+static struct wd_ctx_params wd_ecc_ctx_params = {
|
||||
+ .op_type_num = 1,
|
||||
+ .ctx_set_num = wd_ecc_ctx_num,
|
||||
+ .bmp = NULL,
|
||||
+};
|
||||
|
||||
static const struct wd_ecc_curve_list curve_list[] = {
|
||||
/* parameter 3 is key width */
|
||||
@@ -135,30 +146,19 @@ static void wd_ecc_clear_status(void)
|
||||
wd_alg_clear_init(&wd_ecc_setting.status);
|
||||
}
|
||||
|
||||
-int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
+static int wd_ecc_common_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
void *priv;
|
||||
- bool flag;
|
||||
int ret;
|
||||
|
||||
- pthread_atfork(NULL, NULL, wd_ecc_clear_status);
|
||||
-
|
||||
- flag = wd_alg_try_init(&wd_ecc_setting.status);
|
||||
- if (!flag)
|
||||
- return 0;
|
||||
-
|
||||
- ret = wd_init_param_check(config, sched);
|
||||
- if (ret)
|
||||
- goto out_clear_init;
|
||||
-
|
||||
ret = wd_set_epoll_en("WD_ECC_EPOLL_EN",
|
||||
&wd_ecc_setting.config.epoll_en);
|
||||
if (ret < 0)
|
||||
- goto out_clear_init;
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_ctx_config(&wd_ecc_setting.config, config);
|
||||
if (ret < 0)
|
||||
- goto out_clear_init;
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_sched(&wd_ecc_setting.sched, sched);
|
||||
if (ret < 0)
|
||||
@@ -190,8 +190,6 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
goto out_free_priv;
|
||||
}
|
||||
|
||||
- wd_alg_set_init(&wd_ecc_setting.status);
|
||||
-
|
||||
return 0;
|
||||
|
||||
out_free_priv:
|
||||
@@ -203,12 +201,10 @@ out_clear_sched:
|
||||
wd_clear_sched(&wd_ecc_setting.sched);
|
||||
out_clear_ctx_config:
|
||||
wd_clear_ctx_config(&wd_ecc_setting.config);
|
||||
-out_clear_init:
|
||||
- wd_alg_clear_init(&wd_ecc_setting.status);
|
||||
return ret;
|
||||
}
|
||||
|
||||
-void wd_ecc_uninit(void)
|
||||
+static void wd_ecc_common_uninit(void)
|
||||
{
|
||||
if (!wd_ecc_setting.priv) {
|
||||
WD_ERR("invalid: repeat uninit ecc!\n");
|
||||
@@ -226,6 +222,81 @@ void wd_ecc_uninit(void)
|
||||
/* unset config, sched, driver */
|
||||
wd_clear_sched(&wd_ecc_setting.sched);
|
||||
wd_clear_ctx_config(&wd_ecc_setting.config);
|
||||
+}
|
||||
+
|
||||
+int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
+{
|
||||
+ bool flag;
|
||||
+ int ret;
|
||||
+
|
||||
+ pthread_atfork(NULL, NULL, wd_ecc_clear_status);
|
||||
+
|
||||
+ flag = wd_alg_try_init(&wd_ecc_setting.status);
|
||||
+ if (!flag)
|
||||
+ return 0;
|
||||
+
|
||||
+ ret = wd_init_param_check(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ ret = wd_ecc_common_init(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ wd_alg_set_init(&wd_ecc_setting.status);
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+out_clear_init:
|
||||
+ wd_alg_clear_init(&wd_ecc_setting.status);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void wd_ecc_uninit(void)
|
||||
+{
|
||||
+ wd_ecc_common_uninit();
|
||||
+ wd_alg_clear_init(&wd_ecc_setting.status);
|
||||
+}
|
||||
+
|
||||
+int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params)
|
||||
+{
|
||||
+ bool flag;
|
||||
+ int ret;
|
||||
+
|
||||
+ pthread_atfork(NULL, NULL, wd_ecc_clear_status);
|
||||
+
|
||||
+ flag = wd_alg_try_init(&wd_ecc_setting.status);
|
||||
+ if (!flag)
|
||||
+ return 0;
|
||||
+
|
||||
+ 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_clear_init;
|
||||
+ }
|
||||
+
|
||||
+ wd_ecc_init_attrs.alg = alg;
|
||||
+ wd_ecc_init_attrs.sched_type = sched_type;
|
||||
+ wd_ecc_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_ecc_ctx_params;
|
||||
+ wd_ecc_init_attrs.alg_init = wd_ecc_common_init;
|
||||
+ wd_ecc_init_attrs.alg_poll_ctx = wd_ecc_poll_ctx;
|
||||
+ ret = wd_alg_attrs_init(&wd_ecc_init_attrs);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ wd_alg_set_init(&wd_ecc_setting.status);
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+out_clear_init:
|
||||
+ wd_alg_clear_init(&wd_ecc_setting.status);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void wd_ecc_uninit2(void)
|
||||
+{
|
||||
+ wd_ecc_common_uninit();
|
||||
+ wd_alg_attrs_uninit(&wd_ecc_init_attrs);
|
||||
wd_alg_clear_init(&wd_ecc_setting.status);
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
233
0012-uadk-rsa-add-the-init2-interface-for-rsa.patch
Normal file
233
0012-uadk-rsa-add-the-init2-interface-for-rsa.patch
Normal file
@ -0,0 +1,233 @@
|
||||
From 89f5b9d27d44ff6b7c8b14f3bedb1f6a3471690e Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Sat, 11 Feb 2023 15:19:30 +0800
|
||||
Subject: [PATCH 12/28] uadk/rsa: add the init2 interface for rsa
|
||||
|
||||
This set of interfaces puts resource initialization
|
||||
operations into the init2 interface, simplifying the
|
||||
initialization operations when users use the rsa algorithm.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
include/wd_rsa.h | 28 ++++++++++++
|
||||
libwd_crypto.map | 3 ++
|
||||
wd_rsa.c | 109 ++++++++++++++++++++++++++++++++++++++---------
|
||||
3 files changed, 121 insertions(+), 19 deletions(-)
|
||||
|
||||
diff --git a/include/wd_rsa.h b/include/wd_rsa.h
|
||||
index e16171f..733d0b7 100644
|
||||
--- a/include/wd_rsa.h
|
||||
+++ b/include/wd_rsa.h
|
||||
@@ -120,6 +120,34 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched);
|
||||
*/
|
||||
void wd_rsa_uninit(void);
|
||||
|
||||
+/**
|
||||
+ * wd_rsa_init2_() - A simplify interface to initializate rsa.
|
||||
+ * This interface keeps most functions of
|
||||
+ * wd_rsa_init(). Users just need to descripe the deployment of
|
||||
+ * business scenarios. Then the initialization will request appropriate
|
||||
+ * resources to support the business scenarios.
|
||||
+ * To make the initializate simpler, ctx_params support set NULL.
|
||||
+ * And then the function will set them as default.
|
||||
+ * Please do not use this interface with wd_rsa_init() together, or
|
||||
+ * some resources may be leak.
|
||||
+ *
|
||||
+ * @alg: The algorithm users want to use.
|
||||
+ * @sched_type: The scheduling type users want to use.
|
||||
+ * @task_type: Reserved.
|
||||
+ * @ctx_params: The ctxs resources users want to use. Include per operation
|
||||
+ * type ctx numbers and business process run numa.
|
||||
+ *
|
||||
+ * Return 0 if succeed and others if fail.
|
||||
+ */
|
||||
+int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params);
|
||||
+
|
||||
+#define wd_rsa_init2(alg, sched_type, task_type) \
|
||||
+ wd_rsa_init2_(alg, sched_type, task_type, NULL)
|
||||
+
|
||||
+/**
|
||||
+ * wd_rsa_uninit2() - Uninitialise ctx configuration and scheduler.
|
||||
+ */
|
||||
+void wd_rsa_uninit2(void);
|
||||
|
||||
/**
|
||||
* wd_rsa_alloc_sess() - Allocate a wd rsa session.
|
||||
diff --git a/libwd_crypto.map b/libwd_crypto.map
|
||||
index 2983f20..871ef36 100644
|
||||
--- a/libwd_crypto.map
|
||||
+++ b/libwd_crypto.map
|
||||
@@ -81,6 +81,9 @@ global:
|
||||
wd_rsa_set_kg_out_psz;
|
||||
wd_rsa_init;
|
||||
wd_rsa_uninit;
|
||||
+ wd_rsa_init2;
|
||||
+ wd_rsa_init2_;
|
||||
+ wd_rsa_uninit2;
|
||||
wd_rsa_alloc_sess;
|
||||
wd_rsa_free_sess;
|
||||
wd_do_rsa_async;
|
||||
diff --git a/wd_rsa.c b/wd_rsa.c
|
||||
index 0b76c48..99bfe48 100644
|
||||
--- a/wd_rsa.c
|
||||
+++ b/wd_rsa.c
|
||||
@@ -82,6 +82,17 @@ static struct wd_rsa_setting {
|
||||
} wd_rsa_setting;
|
||||
|
||||
struct wd_env_config wd_rsa_env_config;
|
||||
+static struct wd_init_attrs wd_rsa_init_attrs;
|
||||
+
|
||||
+static struct wd_ctx_nums wd_rsa_ctx_num[] = {
|
||||
+ {1, 1}, {}
|
||||
+};
|
||||
+
|
||||
+static struct wd_ctx_params wd_rsa_ctx_params = {
|
||||
+ .op_type_num = 1,
|
||||
+ .ctx_set_num = wd_rsa_ctx_num,
|
||||
+ .bmp = NULL,
|
||||
+};
|
||||
|
||||
#ifdef WD_STATIC_DRV
|
||||
static void wd_rsa_set_static_drv(void)
|
||||
@@ -120,30 +131,19 @@ static void wd_rsa_clear_status(void)
|
||||
wd_alg_clear_init(&wd_rsa_setting.status);
|
||||
}
|
||||
|
||||
-int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
+static int wd_rsa_common_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
void *priv;
|
||||
- bool flag;
|
||||
int ret;
|
||||
|
||||
- pthread_atfork(NULL, NULL, wd_rsa_clear_status);
|
||||
-
|
||||
- flag = wd_alg_try_init(&wd_rsa_setting.status);
|
||||
- if (!flag)
|
||||
- return 0;
|
||||
-
|
||||
- ret = wd_init_param_check(config, sched);
|
||||
- if (ret)
|
||||
- goto out_clear_init;
|
||||
-
|
||||
ret = wd_set_epoll_en("WD_RSA_EPOLL_EN",
|
||||
&wd_rsa_setting.config.epoll_en);
|
||||
if (ret < 0)
|
||||
- goto out_clear_init;
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_ctx_config(&wd_rsa_setting.config, config);
|
||||
if (ret < 0)
|
||||
- goto out_clear_init;
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_sched(&wd_rsa_setting.sched, sched);
|
||||
if (ret < 0)
|
||||
@@ -175,8 +175,6 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
goto out_free_priv;
|
||||
}
|
||||
|
||||
- wd_alg_set_init(&wd_rsa_setting.status);
|
||||
-
|
||||
return 0;
|
||||
|
||||
out_free_priv:
|
||||
@@ -188,12 +186,10 @@ out_clear_sched:
|
||||
wd_clear_sched(&wd_rsa_setting.sched);
|
||||
out_clear_ctx_config:
|
||||
wd_clear_ctx_config(&wd_rsa_setting.config);
|
||||
-out_clear_init:
|
||||
- wd_alg_clear_init(&wd_rsa_setting.status);
|
||||
return ret;
|
||||
}
|
||||
|
||||
-void wd_rsa_uninit(void)
|
||||
+static void wd_rsa_common_uninit(void)
|
||||
{
|
||||
if (!wd_rsa_setting.priv) {
|
||||
WD_ERR("invalid: repeat uninit rsa!\n");
|
||||
@@ -211,6 +207,81 @@ void wd_rsa_uninit(void)
|
||||
/* unset config, sched, driver */
|
||||
wd_clear_sched(&wd_rsa_setting.sched);
|
||||
wd_clear_ctx_config(&wd_rsa_setting.config);
|
||||
+}
|
||||
+
|
||||
+int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
+{
|
||||
+ bool flag;
|
||||
+ int ret;
|
||||
+
|
||||
+ pthread_atfork(NULL, NULL, wd_rsa_clear_status);
|
||||
+
|
||||
+ flag = wd_alg_try_init(&wd_rsa_setting.status);
|
||||
+ if (!flag)
|
||||
+ return 0;
|
||||
+
|
||||
+ ret = wd_init_param_check(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ ret = wd_rsa_common_init(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ wd_alg_set_init(&wd_rsa_setting.status);
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+out_clear_init:
|
||||
+ wd_alg_clear_init(&wd_rsa_setting.status);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void wd_rsa_uninit(void)
|
||||
+{
|
||||
+ wd_rsa_common_uninit();
|
||||
+ wd_alg_clear_init(&wd_rsa_setting.status);
|
||||
+}
|
||||
+
|
||||
+int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params)
|
||||
+{
|
||||
+ bool flag;
|
||||
+ int ret;
|
||||
+
|
||||
+ pthread_atfork(NULL, NULL, wd_rsa_clear_status);
|
||||
+
|
||||
+ flag = wd_alg_try_init(&wd_rsa_setting.status);
|
||||
+ if (!flag)
|
||||
+ return 0;
|
||||
+
|
||||
+ 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_clear_init;
|
||||
+ }
|
||||
+
|
||||
+ wd_rsa_init_attrs.alg = alg;
|
||||
+ wd_rsa_init_attrs.sched_type = sched_type;
|
||||
+ wd_rsa_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_rsa_ctx_params;
|
||||
+ wd_rsa_init_attrs.alg_init = wd_rsa_common_init;
|
||||
+ wd_rsa_init_attrs.alg_poll_ctx = wd_rsa_poll_ctx;
|
||||
+ ret = wd_alg_attrs_init(&wd_rsa_init_attrs);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ wd_alg_set_init(&wd_rsa_setting.status);
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+out_clear_init:
|
||||
+ wd_alg_clear_init(&wd_rsa_setting.status);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void wd_rsa_uninit2(void)
|
||||
+{
|
||||
+ wd_rsa_common_uninit();
|
||||
+ wd_alg_attrs_uninit(&wd_rsa_init_attrs);
|
||||
wd_alg_clear_init(&wd_rsa_setting.status);
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
235
0013-uadk-dh-add-the-init2-interface-for-dh.patch
Normal file
235
0013-uadk-dh-add-the-init2-interface-for-dh.patch
Normal file
@ -0,0 +1,235 @@
|
||||
From 409e0dc66bf5f805339c5cb413773753e3071be0 Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Sat, 11 Feb 2023 15:19:31 +0800
|
||||
Subject: [PATCH 13/28] uadk/dh: add the init2 interface for dh
|
||||
|
||||
This set of interfaces puts resource initialization
|
||||
operations into the init2 interface, simplifying the
|
||||
initialization operations when users use the dh algorithm.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
include/wd_dh.h | 30 +++++++++++++
|
||||
libwd_crypto.map | 3 ++
|
||||
wd_dh.c | 109 ++++++++++++++++++++++++++++++++++++++---------
|
||||
3 files changed, 123 insertions(+), 19 deletions(-)
|
||||
|
||||
diff --git a/include/wd_dh.h b/include/wd_dh.h
|
||||
index 3912680..afc2f7c 100644
|
||||
--- a/include/wd_dh.h
|
||||
+++ b/include/wd_dh.h
|
||||
@@ -61,6 +61,36 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count);
|
||||
int wd_dh_poll(__u32 expt, __u32 *count);
|
||||
int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched);
|
||||
void wd_dh_uninit(void);
|
||||
+
|
||||
+/**
|
||||
+ * wd_dh_init2_() - A simplify interface to initializate dh.
|
||||
+ * This interface keeps most functions of
|
||||
+ * wd_dh_init(). Users just need to descripe the deployment of
|
||||
+ * business scenarios. Then the initialization will request appropriate
|
||||
+ * resources to support the business scenarios.
|
||||
+ * To make the initializate simpler, ctx_params support set NULL.
|
||||
+ * And then the function will set them as default.
|
||||
+ * Please do not use this interface with wd_dh_init() together, or
|
||||
+ * some resources may be leak.
|
||||
+ *
|
||||
+ * @alg: The algorithm users want to use.
|
||||
+ * @sched_type: The scheduling type users want to use.
|
||||
+ * @task_type: Reserved.
|
||||
+ * @ctx_params: The ctxs resources users want to use. Include per operation
|
||||
+ * type ctx numbers and business process run numa.
|
||||
+ *
|
||||
+ * Return 0 if succeed and others if fail.
|
||||
+ */
|
||||
+int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params);
|
||||
+
|
||||
+#define wd_dh_init2(alg, sched_type, task_type) \
|
||||
+ wd_dh_init2_(alg, sched_type, task_type, NULL)
|
||||
+
|
||||
+/**
|
||||
+ * wd_dh_uninit2() - Uninitialise ctx configuration and scheduler.
|
||||
+ */
|
||||
+void wd_dh_uninit2(void);
|
||||
+
|
||||
int wd_dh_env_init(struct wd_sched *sched);
|
||||
void wd_dh_env_uninit(void);
|
||||
int wd_dh_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode);
|
||||
diff --git a/libwd_crypto.map b/libwd_crypto.map
|
||||
index 871ef36..5c46c44 100644
|
||||
--- a/libwd_crypto.map
|
||||
+++ b/libwd_crypto.map
|
||||
@@ -112,6 +112,9 @@ global:
|
||||
wd_dh_poll;
|
||||
wd_dh_init;
|
||||
wd_dh_uninit;
|
||||
+ wd_dh_init2;
|
||||
+ wd_dh_init2_;
|
||||
+ wd_dh_uninit2;
|
||||
wd_dh_env_init;
|
||||
wd_dh_env_uninit;
|
||||
wd_dh_ctx_num_init;
|
||||
diff --git a/wd_dh.c b/wd_dh.c
|
||||
index 4cb5c26..d861b34 100644
|
||||
--- a/wd_dh.c
|
||||
+++ b/wd_dh.c
|
||||
@@ -41,6 +41,17 @@ static struct wd_dh_setting {
|
||||
} wd_dh_setting;
|
||||
|
||||
struct wd_env_config wd_dh_env_config;
|
||||
+static struct wd_init_attrs wd_dh_init_attrs;
|
||||
+
|
||||
+static struct wd_ctx_nums wd_dh_ctx_num[] = {
|
||||
+ {1, 1}, {}
|
||||
+};
|
||||
+
|
||||
+static struct wd_ctx_params wd_dh_ctx_params = {
|
||||
+ .op_type_num = 1,
|
||||
+ .ctx_set_num = wd_dh_ctx_num,
|
||||
+ .bmp = NULL,
|
||||
+};
|
||||
|
||||
#ifdef WD_STATIC_DRV
|
||||
static void wd_dh_set_static_drv(void)
|
||||
@@ -79,30 +90,19 @@ static void wd_dh_clear_status(void)
|
||||
wd_alg_clear_init(&wd_dh_setting.status);
|
||||
}
|
||||
|
||||
-int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
+static int wd_dh_common_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
void *priv;
|
||||
- bool flag;
|
||||
int ret;
|
||||
|
||||
- pthread_atfork(NULL, NULL, wd_dh_clear_status);
|
||||
-
|
||||
- flag = wd_alg_try_init(&wd_dh_setting.status);
|
||||
- if (!flag)
|
||||
- return 0;
|
||||
-
|
||||
- ret = wd_init_param_check(config, sched);
|
||||
- if (ret)
|
||||
- goto out_clear_init;
|
||||
-
|
||||
ret = wd_set_epoll_en("WD_DH_EPOLL_EN",
|
||||
&wd_dh_setting.config.epoll_en);
|
||||
if (ret < 0)
|
||||
- goto out_clear_init;
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_ctx_config(&wd_dh_setting.config, config);
|
||||
if (ret)
|
||||
- goto out_clear_init;
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_sched(&wd_dh_setting.sched, sched);
|
||||
if (ret)
|
||||
@@ -134,8 +134,6 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
goto out_free_priv;
|
||||
}
|
||||
|
||||
- wd_alg_set_init(&wd_dh_setting.status);
|
||||
-
|
||||
return 0;
|
||||
|
||||
out_free_priv:
|
||||
@@ -147,12 +145,10 @@ out_clear_sched:
|
||||
wd_clear_sched(&wd_dh_setting.sched);
|
||||
out_clear_ctx_config:
|
||||
wd_clear_ctx_config(&wd_dh_setting.config);
|
||||
-out_clear_init:
|
||||
- wd_alg_clear_init(&wd_dh_setting.status);
|
||||
return ret;
|
||||
}
|
||||
|
||||
-void wd_dh_uninit(void)
|
||||
+static void wd_dh_common_uninit(void)
|
||||
{
|
||||
if (!wd_dh_setting.priv) {
|
||||
WD_ERR("invalid: repeat uninit dh!\n");
|
||||
@@ -170,6 +166,81 @@ void wd_dh_uninit(void)
|
||||
/* unset config, sched, driver */
|
||||
wd_clear_sched(&wd_dh_setting.sched);
|
||||
wd_clear_ctx_config(&wd_dh_setting.config);
|
||||
+}
|
||||
+
|
||||
+int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
+{
|
||||
+ bool flag;
|
||||
+ int ret;
|
||||
+
|
||||
+ pthread_atfork(NULL, NULL, wd_dh_clear_status);
|
||||
+
|
||||
+ flag = wd_alg_try_init(&wd_dh_setting.status);
|
||||
+ if (!flag)
|
||||
+ return 0;
|
||||
+
|
||||
+ ret = wd_init_param_check(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ ret = wd_dh_common_init(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ wd_alg_set_init(&wd_dh_setting.status);
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+out_clear_init:
|
||||
+ wd_alg_clear_init(&wd_dh_setting.status);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void wd_dh_uninit(void)
|
||||
+{
|
||||
+ wd_dh_common_uninit();
|
||||
+ wd_alg_clear_init(&wd_dh_setting.status);
|
||||
+}
|
||||
+
|
||||
+int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params)
|
||||
+{
|
||||
+ bool flag;
|
||||
+ int ret;
|
||||
+
|
||||
+ pthread_atfork(NULL, NULL, wd_dh_clear_status);
|
||||
+
|
||||
+ flag = wd_alg_try_init(&wd_dh_setting.status);
|
||||
+ if (!flag)
|
||||
+ return 0;
|
||||
+
|
||||
+ 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_clear_init;
|
||||
+ }
|
||||
+
|
||||
+ wd_dh_init_attrs.alg = alg;
|
||||
+ wd_dh_init_attrs.sched_type = sched_type;
|
||||
+ wd_dh_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_dh_ctx_params;
|
||||
+ wd_dh_init_attrs.alg_init = wd_dh_common_init;
|
||||
+ wd_dh_init_attrs.alg_poll_ctx = wd_dh_poll_ctx;
|
||||
+ ret = wd_alg_attrs_init(&wd_dh_init_attrs);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ wd_alg_set_init(&wd_dh_setting.status);
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+out_clear_init:
|
||||
+ wd_alg_clear_init(&wd_dh_setting.status);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void wd_dh_uninit2(void)
|
||||
+{
|
||||
+ wd_dh_common_uninit();
|
||||
+ wd_alg_attrs_uninit(&wd_dh_init_attrs);
|
||||
wd_alg_clear_init(&wd_dh_setting.status);
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
552
0014-uadk-ecc-adapt-the-ecc-module-to-the-dynamic-loading.patch
Normal file
552
0014-uadk-ecc-adapt-the-ecc-module-to-the-dynamic-loading.patch
Normal file
@ -0,0 +1,552 @@
|
||||
From 827f1bd89761201cacee267a66066f4a31c5c5b3 Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Sat, 11 Feb 2023 15:19:32 +0800
|
||||
Subject: [PATCH 14/28] uadk/ecc: adapt the ecc module to the dynamic loading
|
||||
framework
|
||||
|
||||
After adding the ecc module of the init2 interface, combine it
|
||||
dynamically load the initialization part, transform HiSilicon HPRE
|
||||
driven, and implemented using the dynamic loading function Connection
|
||||
between driver and algorithm layer.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
drv/hisi_hpre.c | 124 ++++++++++++++++++++-------
|
||||
include/drv/wd_ecc_drv.h | 27 ------
|
||||
wd_ecc.c | 181 +++++++++++++++++++++++++--------------
|
||||
3 files changed, 209 insertions(+), 123 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
|
||||
index d8b212d..a08e5e6 100644
|
||||
--- a/drv/hisi_hpre.c
|
||||
+++ b/drv/hisi_hpre.c
|
||||
@@ -32,6 +32,7 @@
|
||||
#define SM2_PONIT_SIZE 64
|
||||
#define MAX_HASH_LENS BITS_TO_BYTES(521)
|
||||
#define HW_PLAINTEXT_BYTES_MAX BITS_TO_BYTES(4096)
|
||||
+#define HPRE_CTX_Q_NUM_DEF 1
|
||||
|
||||
#define CRT_PARAMS_SZ(key_size) ((5 * (key_size)) >> 1)
|
||||
#define CRT_GEN_PARAMS_SZ(key_size) ((7 * (key_size)) >> 1)
|
||||
@@ -459,37 +460,26 @@ static int rsa_prepare_iot(struct wd_rsa_msg *msg,
|
||||
return ret;
|
||||
}
|
||||
|
||||
-static int hpre_init(struct wd_ctx_config_internal *config, void *priv, const char *alg_name)
|
||||
+static int hpre_init_qm_priv(struct wd_ctx_config_internal *config,
|
||||
+ struct hisi_hpre_ctx *hpre_ctx,
|
||||
+ struct hisi_qm_priv *qm_priv)
|
||||
{
|
||||
- struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
|
||||
- struct hisi_qm_priv qm_priv;
|
||||
handle_t h_ctx, h_qp;
|
||||
int i, j;
|
||||
|
||||
- if (!config->ctx_num) {
|
||||
- WD_ERR("invalid: hpre init config ctx num is 0!\n");
|
||||
- return -WD_EINVAL;
|
||||
- }
|
||||
-
|
||||
memcpy(&hpre_ctx->config, config, sizeof(*config));
|
||||
|
||||
/* allocate qp for each context */
|
||||
- qm_priv.sqe_size = sizeof(struct hisi_hpre_sqe);
|
||||
-
|
||||
- /* DH/RSA: qm sqc_type = 0, ECC: qm sqc_type = 1; */
|
||||
- if (!strcmp(alg_name, "ecc"))
|
||||
- qm_priv.op_type = HPRE_HW_V3_ECC_ALG_TYPE;
|
||||
- else
|
||||
- qm_priv.op_type = HPRE_HW_V2_ALG_TYPE;
|
||||
+ qm_priv->sqe_size = sizeof(struct hisi_hpre_sqe);
|
||||
|
||||
for (i = 0; i < config->ctx_num; i++) {
|
||||
h_ctx = config->ctxs[i].ctx;
|
||||
- qm_priv.qp_mode = config->ctxs[i].ctx_mode;
|
||||
+ qm_priv->qp_mode = config->ctxs[i].ctx_mode;
|
||||
/* Setting the epoll en to 0 for ASYNC ctx */
|
||||
- qm_priv.epoll_en = (qm_priv.qp_mode == CTX_MODE_SYNC) ?
|
||||
+ qm_priv->epoll_en = (qm_priv->qp_mode == CTX_MODE_SYNC) ?
|
||||
config->epoll_en : 0;
|
||||
- qm_priv.idx = i;
|
||||
- h_qp = hisi_qm_alloc_qp(&qm_priv, h_ctx);
|
||||
+ qm_priv->idx = i;
|
||||
+ h_qp = hisi_qm_alloc_qp(qm_priv, h_ctx);
|
||||
if (!h_qp) {
|
||||
WD_ERR("failed to alloc qp!\n");
|
||||
goto out;
|
||||
@@ -506,6 +496,45 @@ out:
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
+static int hpre_rsa_dh_init(struct wd_ctx_config_internal *config, void *priv, const char *alg_name)
|
||||
+{
|
||||
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
|
||||
+ struct hisi_qm_priv qm_priv;
|
||||
+ int ret;
|
||||
+
|
||||
+ if (!config->ctx_num) {
|
||||
+ WD_ERR("invalid: hpre rsa/dh init config ctx num is 0!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ qm_priv.op_type = HPRE_HW_V2_ALG_TYPE;
|
||||
+ ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int hpre_ecc_init(void *conf, void *priv)
|
||||
+{
|
||||
+ struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
|
||||
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
|
||||
+ struct hisi_qm_priv qm_priv;
|
||||
+ int ret;
|
||||
+
|
||||
+ if (!config->ctx_num) {
|
||||
+ WD_ERR("invalid: hpre ecc init config ctx num is 0!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ qm_priv.op_type = HPRE_HW_V3_ECC_ALG_TYPE;
|
||||
+ ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
static void hpre_exit(void *priv)
|
||||
{
|
||||
struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
|
||||
@@ -624,7 +653,7 @@ static struct wd_rsa_driver rsa_hisi_hpre = {
|
||||
.drv_name = "hisi_hpre",
|
||||
.alg_name = "rsa",
|
||||
.drv_ctx_size = sizeof(struct hisi_hpre_ctx),
|
||||
- .init = hpre_init,
|
||||
+ .init = hpre_rsa_dh_init,
|
||||
.exit = hpre_exit,
|
||||
.send = rsa_send,
|
||||
.recv = rsa_recv,
|
||||
@@ -777,7 +806,7 @@ static struct wd_dh_driver dh_hisi_hpre = {
|
||||
.drv_name = "hisi_hpre",
|
||||
.alg_name = "dh",
|
||||
.drv_ctx_size = sizeof(struct hisi_hpre_ctx),
|
||||
- .init = hpre_init,
|
||||
+ .init = hpre_rsa_dh_init,
|
||||
.exit = hpre_exit,
|
||||
.send = dh_send,
|
||||
.recv = dh_recv,
|
||||
@@ -2427,16 +2456,51 @@ static int ecc_recv(handle_t ctx, void *ecc_msg)
|
||||
return ecc_sqe_parse((struct hisi_qp *)h_qp, msg, &hw_msg);
|
||||
}
|
||||
|
||||
-static struct wd_ecc_driver ecc_hisi_hpre = {
|
||||
- .drv_name = "hisi_hpre",
|
||||
- .alg_name = "ecc",
|
||||
- .drv_ctx_size = sizeof(struct hisi_hpre_ctx),
|
||||
- .init = hpre_init,
|
||||
- .exit = hpre_exit,
|
||||
- .send = ecc_send,
|
||||
- .recv = ecc_recv,
|
||||
+#define GEN_HPRE_ALG_DRIVER(hpre_alg_name) \
|
||||
+{\
|
||||
+ .drv_name = "hisi_hpre",\
|
||||
+ .alg_name = hpre_alg_name,\
|
||||
+ .priority = UADK_ALG_HW,\
|
||||
+ .priv_size = sizeof(struct hisi_hpre_ctx),\
|
||||
+ .queue_num = HPRE_CTX_Q_NUM_DEF,\
|
||||
+ .op_type_num = 1,\
|
||||
+ .fallback = 0,\
|
||||
+ .init = hpre_ecc_init,\
|
||||
+ .exit = hpre_exit,\
|
||||
+ .send = ecc_send,\
|
||||
+ .recv = ecc_recv,\
|
||||
+}
|
||||
+
|
||||
+static struct wd_alg_driver hpre_alg_driver[] = {
|
||||
+ 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 void __attribute__((constructor)) hisi_hpre_probe(void)
|
||||
+{
|
||||
+ int alg_num = ARRAY_SIZE(hpre_alg_driver);
|
||||
+ int i, ret;
|
||||
+
|
||||
+ WD_INFO("Info: register HPRE alg drivers!\n");
|
||||
+
|
||||
+ for (i = 0; i < alg_num; i++) {
|
||||
+ ret = wd_alg_driver_register(&hpre_alg_driver[i]);
|
||||
+ if (ret)
|
||||
+ WD_ERR("failed to register HPRE %s driver!\n", hpre_alg_driver[i].alg_name);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static void __attribute__((destructor)) hisi_hpre_remove(void)
|
||||
+{
|
||||
+ int alg_num = ARRAY_SIZE(hpre_alg_driver);
|
||||
+ int i;
|
||||
+
|
||||
+ for (i = 0; i < alg_num; i++)
|
||||
+ wd_alg_driver_unregister(&hpre_alg_driver[i]);
|
||||
+}
|
||||
+
|
||||
WD_RSA_SET_DRIVER(rsa_hisi_hpre);
|
||||
WD_DH_SET_DRIVER(dh_hisi_hpre);
|
||||
-WD_ECC_SET_DRIVER(ecc_hisi_hpre);
|
||||
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
|
||||
index 4d27ccb..f5805cd 100644
|
||||
--- a/include/drv/wd_ecc_drv.h
|
||||
+++ b/include/drv/wd_ecc_drv.h
|
||||
@@ -175,35 +175,8 @@ struct wd_ecc_out {
|
||||
char data[];
|
||||
};
|
||||
|
||||
-struct wd_ecc_driver {
|
||||
- const char *drv_name;
|
||||
- const char *alg_name;
|
||||
- __u32 drv_ctx_size;
|
||||
- int (*init)(struct wd_ctx_config_internal *config, void *priv,
|
||||
- const char *alg_name);
|
||||
- void (*exit)(void *priv);
|
||||
- int (*send)(handle_t sess, void *ecc_msg);
|
||||
- int (*recv)(handle_t sess, void *ecc_msg);
|
||||
-};
|
||||
-
|
||||
-void wd_ecc_set_driver(struct wd_ecc_driver *drv);
|
||||
-struct wd_ecc_driver *wd_ecc_get_driver(void);
|
||||
struct wd_ecc_msg *wd_ecc_get_msg(__u32 idx, __u32 tag);
|
||||
|
||||
-#ifdef WD_STATIC_DRV
|
||||
-#define WD_ECC_SET_DRIVER(drv) \
|
||||
-struct wd_ecc_driver *wd_ecc_get_driver(void) \
|
||||
-{ \
|
||||
- return &drv; \
|
||||
-}
|
||||
-#else
|
||||
-#define WD_ECC_SET_DRIVER(drv) \
|
||||
-static void __attribute__((constructor)) set_driver_ecc(void) \
|
||||
-{ \
|
||||
- wd_ecc_set_driver(&(drv)); \
|
||||
-}
|
||||
-#endif
|
||||
-
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
diff --git a/wd_ecc.c b/wd_ecc.c
|
||||
index 4cad1e4..57954e0 100644
|
||||
--- a/wd_ecc.c
|
||||
+++ b/wd_ecc.c
|
||||
@@ -66,26 +66,16 @@ static struct wd_ecc_setting {
|
||||
enum wd_status status;
|
||||
struct wd_ctx_config_internal config;
|
||||
struct wd_sched sched;
|
||||
- void *sched_ctx;
|
||||
- const struct wd_ecc_driver *driver;
|
||||
+ struct wd_async_msg_pool pool;
|
||||
+ struct wd_alg_driver *driver;
|
||||
void *priv;
|
||||
void *dlhandle;
|
||||
- struct wd_async_msg_pool pool;
|
||||
+ void *dlh_list;
|
||||
} wd_ecc_setting;
|
||||
|
||||
struct wd_env_config wd_ecc_env_config;
|
||||
static struct wd_init_attrs wd_ecc_init_attrs;
|
||||
|
||||
-static struct wd_ctx_nums wd_ecc_ctx_num[] = {
|
||||
- {1, 1}, {}
|
||||
-};
|
||||
-
|
||||
-static struct wd_ctx_params wd_ecc_ctx_params = {
|
||||
- .op_type_num = 1,
|
||||
- .ctx_set_num = wd_ecc_ctx_num,
|
||||
- .bmp = NULL,
|
||||
-};
|
||||
-
|
||||
static const struct wd_ecc_curve_list curve_list[] = {
|
||||
/* parameter 3 is key width */
|
||||
{ WD_X25519, "x25519", 256, X25519_256_PARAM },
|
||||
@@ -109,36 +99,50 @@ static const struct curve_param_desc curve_pram_list[] = {
|
||||
{ ECC_CURVE_G, offsetof(struct wd_ecc_prikey, g), offsetof(struct wd_ecc_pubkey, g) }
|
||||
};
|
||||
|
||||
-#ifdef WD_STATIC_DRV
|
||||
-static void wd_ecc_set_static_drv(void)
|
||||
+static void wd_ecc_close_driver(void)
|
||||
{
|
||||
- wd_ecc_setting.driver = wd_ecc_get_driver();
|
||||
- if (!wd_ecc_setting.driver)
|
||||
- WD_ERR("failed to get ecc driver!\n");
|
||||
-}
|
||||
-#else
|
||||
-static void __attribute__((constructor)) wd_ecc_open_driver(void)
|
||||
-{
|
||||
- wd_ecc_setting.dlhandle = dlopen("libhisi_hpre.so", RTLD_NOW);
|
||||
if (!wd_ecc_setting.dlhandle)
|
||||
- WD_ERR("failed to open libhisi_hpre.so, %s\n", dlerror());
|
||||
-}
|
||||
+ return;
|
||||
|
||||
-static void __attribute__((destructor)) wd_ecc_close_driver(void)
|
||||
-{
|
||||
- if (wd_ecc_setting.dlhandle)
|
||||
- dlclose(wd_ecc_setting.dlhandle);
|
||||
+ wd_release_drv(wd_ecc_setting.driver);
|
||||
+ dlclose(wd_ecc_setting.dlhandle);
|
||||
+ wd_ecc_setting.dlhandle = NULL;
|
||||
}
|
||||
-#endif
|
||||
|
||||
-void wd_ecc_set_driver(struct wd_ecc_driver *drv)
|
||||
+static int wd_ecc_open_driver(void)
|
||||
{
|
||||
- if (!drv) {
|
||||
- WD_ERR("invalid: ecc drv is NULL!\n");
|
||||
- return;
|
||||
+ struct wd_alg_driver *driver = NULL;
|
||||
+ char lib_path[PATH_STR_SIZE];
|
||||
+ const char *alg_name = "sm2";
|
||||
+ int ret;
|
||||
+
|
||||
+ /*
|
||||
+ * Compatible with the normal acquisition of device
|
||||
+ * drivers in the init interface
|
||||
+ */
|
||||
+ if (wd_ecc_setting.dlh_list)
|
||||
+ return 0;
|
||||
+
|
||||
+ ret = wd_get_lib_file_path("libhisi_hpre.so", lib_path, false);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+
|
||||
+ wd_ecc_setting.dlhandle = dlopen(lib_path, RTLD_NOW);
|
||||
+ if (!wd_ecc_setting.dlhandle) {
|
||||
+ WD_ERR("failed to open libhisi_hpre.so, %s!\n", dlerror());
|
||||
+ return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- wd_ecc_setting.driver = drv;
|
||||
+ driver = wd_request_drv(alg_name, false);
|
||||
+ if (!driver) {
|
||||
+ wd_ecc_close_driver();
|
||||
+ WD_ERR("failed to get %s driver support\n", alg_name);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ wd_ecc_setting.driver = driver;
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static void wd_ecc_clear_status(void)
|
||||
@@ -148,7 +152,6 @@ static void wd_ecc_clear_status(void)
|
||||
|
||||
static int wd_ecc_common_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- void *priv;
|
||||
int ret;
|
||||
|
||||
ret = wd_set_epoll_en("WD_ECC_EPOLL_EN",
|
||||
@@ -164,10 +167,6 @@ static int wd_ecc_common_init(struct wd_ctx_config *config, struct wd_sched *sch
|
||||
if (ret < 0)
|
||||
goto out_clear_ctx_config;
|
||||
|
||||
-#ifdef WD_STATIC_DRV
|
||||
- wd_ecc_set_static_drv();
|
||||
-#endif
|
||||
-
|
||||
/* fix me: sadly find we allocate async pool for every ctx */
|
||||
ret = wd_init_async_request_pool(&wd_ecc_setting.pool,
|
||||
config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
@@ -175,26 +174,14 @@ static int wd_ecc_common_init(struct wd_ctx_config *config, struct wd_sched *sch
|
||||
if (ret < 0)
|
||||
goto out_clear_sched;
|
||||
|
||||
- /* initialize ctx related resources in specific driver */
|
||||
- priv = calloc(1, wd_ecc_setting.driver->drv_ctx_size);
|
||||
- if (!priv) {
|
||||
- ret = -WD_ENOMEM;
|
||||
+ ret = wd_alg_init_driver(&wd_ecc_setting.config,
|
||||
+ wd_ecc_setting.driver,
|
||||
+ &wd_ecc_setting.priv);
|
||||
+ if (ret)
|
||||
goto out_clear_pool;
|
||||
- }
|
||||
-
|
||||
- wd_ecc_setting.priv = priv;
|
||||
- ret = wd_ecc_setting.driver->init(&wd_ecc_setting.config, priv,
|
||||
- wd_ecc_setting.driver->alg_name);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to init ecc driver, ret = %d!\n", ret);
|
||||
- goto out_free_priv;
|
||||
- }
|
||||
|
||||
return 0;
|
||||
|
||||
-out_free_priv:
|
||||
- free(priv);
|
||||
- wd_ecc_setting.priv = NULL;
|
||||
out_clear_pool:
|
||||
wd_uninit_async_request_pool(&wd_ecc_setting.pool);
|
||||
out_clear_sched:
|
||||
@@ -211,17 +198,14 @@ static void wd_ecc_common_uninit(void)
|
||||
return;
|
||||
}
|
||||
|
||||
- /* driver uninit */
|
||||
- wd_ecc_setting.driver->exit(wd_ecc_setting.priv);
|
||||
- free(wd_ecc_setting.priv);
|
||||
- wd_ecc_setting.priv = NULL;
|
||||
-
|
||||
/* uninit async request pool */
|
||||
wd_uninit_async_request_pool(&wd_ecc_setting.pool);
|
||||
|
||||
/* unset config, sched, driver */
|
||||
wd_clear_sched(&wd_ecc_setting.sched);
|
||||
- wd_clear_ctx_config(&wd_ecc_setting.config);
|
||||
+ wd_alg_uninit_driver(&wd_ecc_setting.config,
|
||||
+ wd_ecc_setting.driver,
|
||||
+ &wd_ecc_setting.priv);
|
||||
}
|
||||
|
||||
int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
@@ -239,14 +223,20 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
if (ret)
|
||||
goto out_clear_init;
|
||||
|
||||
- ret = wd_ecc_common_init(config, sched);
|
||||
+ ret = wd_ecc_open_driver();
|
||||
if (ret)
|
||||
goto out_clear_init;
|
||||
|
||||
+ ret = wd_ecc_common_init(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_close_driver;
|
||||
+
|
||||
wd_alg_set_init(&wd_ecc_setting.status);
|
||||
|
||||
return 0;
|
||||
|
||||
+out_close_driver:
|
||||
+ wd_ecc_close_driver();
|
||||
out_clear_init:
|
||||
wd_alg_clear_init(&wd_ecc_setting.status);
|
||||
return ret;
|
||||
@@ -255,11 +245,14 @@ out_clear_init:
|
||||
void wd_ecc_uninit(void)
|
||||
{
|
||||
wd_ecc_common_uninit();
|
||||
+ wd_ecc_close_driver();
|
||||
wd_alg_clear_init(&wd_ecc_setting.status);
|
||||
}
|
||||
|
||||
int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params)
|
||||
{
|
||||
+ struct wd_ctx_nums ecc_ctx_num[WD_EC_OP_MAX] = {0};
|
||||
+ struct wd_ctx_params ecc_ctx_params = {0};
|
||||
bool flag;
|
||||
int ret;
|
||||
|
||||
@@ -275,19 +268,66 @@ 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");
|
||||
+ ret = -WD_EINVAL;
|
||||
+ goto out_clear_init;
|
||||
+ }
|
||||
+
|
||||
+res_retry:
|
||||
+ memset(&wd_ecc_setting.config, 0, sizeof(struct wd_ctx_config_internal));
|
||||
+
|
||||
+ /* Get alg driver and dev name */
|
||||
+ wd_ecc_setting.driver = wd_alg_drv_bind(task_type, alg);
|
||||
+ if (!wd_ecc_setting.driver) {
|
||||
+ WD_ERR("failed to bind a valid driver!\n");
|
||||
+ ret = -WD_EINVAL;
|
||||
+ goto out_dlopen;
|
||||
+ }
|
||||
+
|
||||
+ ret = wd_ctx_param_init(&ecc_ctx_params, ctx_params,
|
||||
+ ecc_ctx_num, wd_ecc_setting.driver,
|
||||
+ WD_EC_OP_MAX);
|
||||
+ if (ret) {
|
||||
+ if (ret == -WD_EAGAIN) {
|
||||
+ wd_disable_drv(wd_ecc_setting.driver);
|
||||
+ wd_alg_drv_unbind(wd_ecc_setting.driver);
|
||||
+ goto res_retry;
|
||||
+ }
|
||||
+ goto out_driver;
|
||||
+ }
|
||||
+
|
||||
wd_ecc_init_attrs.alg = alg;
|
||||
wd_ecc_init_attrs.sched_type = sched_type;
|
||||
- wd_ecc_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_ecc_ctx_params;
|
||||
+ wd_ecc_init_attrs.driver = wd_ecc_setting.driver;
|
||||
+ wd_ecc_init_attrs.ctx_params = &ecc_ctx_params;
|
||||
wd_ecc_init_attrs.alg_init = wd_ecc_common_init;
|
||||
wd_ecc_init_attrs.alg_poll_ctx = wd_ecc_poll_ctx;
|
||||
ret = wd_alg_attrs_init(&wd_ecc_init_attrs);
|
||||
- if (ret)
|
||||
- goto out_clear_init;
|
||||
+ if (ret) {
|
||||
+ if (ret == -WD_ENODEV) {
|
||||
+ wd_disable_drv(wd_ecc_setting.driver);
|
||||
+ wd_alg_drv_unbind(wd_ecc_setting.driver);
|
||||
+ goto res_retry;
|
||||
+ }
|
||||
+ WD_ERR("failed to init alg attrs!\n");
|
||||
+ goto out_driver;
|
||||
+ }
|
||||
|
||||
wd_alg_set_init(&wd_ecc_setting.status);
|
||||
|
||||
return 0;
|
||||
|
||||
+out_driver:
|
||||
+ wd_alg_drv_unbind(wd_ecc_setting.driver);
|
||||
+out_dlopen:
|
||||
+ wd_dlclose_drv(wd_ecc_setting.dlh_list);
|
||||
out_clear_init:
|
||||
wd_alg_clear_init(&wd_ecc_setting.status);
|
||||
return ret;
|
||||
@@ -297,6 +337,9 @@ void wd_ecc_uninit2(void)
|
||||
{
|
||||
wd_ecc_common_uninit();
|
||||
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_setting.dlh_list = NULL;
|
||||
wd_alg_clear_init(&wd_ecc_setting.status);
|
||||
}
|
||||
|
||||
@@ -1098,6 +1141,12 @@ handle_t wd_ecc_alloc_sess(struct wd_ecc_sess_setup *setup)
|
||||
if (setup_param_check(setup))
|
||||
return (handle_t)0;
|
||||
|
||||
+ ret = wd_drv_alg_support(setup->alg, wd_ecc_setting.driver);
|
||||
+ if (!ret) {
|
||||
+ WD_ERR("failed to support this algorithm: %s!\n", setup->alg);
|
||||
+ return (handle_t)0;
|
||||
+ }
|
||||
+
|
||||
sess = calloc(1, sizeof(struct wd_ecc_sess));
|
||||
if (!sess)
|
||||
return (handle_t)0;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
451
0015-uadk-rsa-adapt-the-rsa-module-to-the-dynamic-loading.patch
Normal file
451
0015-uadk-rsa-adapt-the-rsa-module-to-the-dynamic-loading.patch
Normal file
@ -0,0 +1,451 @@
|
||||
From 35e7cb7a5d3477ab7191ac601ddb89dddb80c271 Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Sat, 11 Feb 2023 15:19:33 +0800
|
||||
Subject: [PATCH 15/28] uadk/rsa: adapt the rsa module to the dynamic loading
|
||||
framework
|
||||
|
||||
After adding the rsa module of the init2 interface, combine it
|
||||
dynamically load the initialization part, transform HiSilicon HPRE
|
||||
driven, and implemented using the dynamic loading function Connection
|
||||
between driver and algorithm layer.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
drv/hisi_hpre.c | 32 ++++---
|
||||
include/drv/wd_dh_drv.h | 3 +-
|
||||
include/drv/wd_rsa_drv.h | 27 ------
|
||||
wd_dh.c | 3 +-
|
||||
wd_rsa.c | 175 ++++++++++++++++++++++++---------------
|
||||
5 files changed, 131 insertions(+), 109 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
|
||||
index a08e5e6..8ecb950 100644
|
||||
--- a/drv/hisi_hpre.c
|
||||
+++ b/drv/hisi_hpre.c
|
||||
@@ -496,8 +496,9 @@ out:
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
-static int hpre_rsa_dh_init(struct wd_ctx_config_internal *config, void *priv, const char *alg_name)
|
||||
+static int hpre_rsa_dh_init(void *conf, void *priv)
|
||||
{
|
||||
+ struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
|
||||
struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
|
||||
struct hisi_qm_priv qm_priv;
|
||||
int ret;
|
||||
@@ -649,16 +650,6 @@ static int rsa_recv(handle_t ctx, void *rsa_msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static struct wd_rsa_driver rsa_hisi_hpre = {
|
||||
- .drv_name = "hisi_hpre",
|
||||
- .alg_name = "rsa",
|
||||
- .drv_ctx_size = sizeof(struct hisi_hpre_ctx),
|
||||
- .init = hpre_rsa_dh_init,
|
||||
- .exit = hpre_exit,
|
||||
- .send = rsa_send,
|
||||
- .recv = rsa_recv,
|
||||
-};
|
||||
-
|
||||
static int fill_dh_xp_params(struct wd_dh_msg *msg,
|
||||
struct hisi_hpre_sqe *hw_msg)
|
||||
{
|
||||
@@ -2479,6 +2470,20 @@ static struct wd_alg_driver hpre_alg_driver[] = {
|
||||
GEN_HPRE_ALG_DRIVER("x448"),
|
||||
};
|
||||
|
||||
+static struct wd_alg_driver hpre_rsa_driver = {
|
||||
+ .drv_name = "hisi_hpre",
|
||||
+ .alg_name = "rsa",
|
||||
+ .priority = UADK_ALG_HW,
|
||||
+ .priv_size = sizeof(struct hisi_hpre_ctx),
|
||||
+ .queue_num = HPRE_CTX_Q_NUM_DEF,
|
||||
+ .op_type_num = 1,
|
||||
+ .fallback = 0,
|
||||
+ .init = hpre_rsa_dh_init,
|
||||
+ .exit = hpre_exit,
|
||||
+ .send = rsa_send,
|
||||
+ .recv = rsa_recv,
|
||||
+};
|
||||
+
|
||||
static void __attribute__((constructor)) hisi_hpre_probe(void)
|
||||
{
|
||||
int alg_num = ARRAY_SIZE(hpre_alg_driver);
|
||||
@@ -2486,6 +2491,9 @@ static void __attribute__((constructor)) hisi_hpre_probe(void)
|
||||
|
||||
WD_INFO("Info: register HPRE alg drivers!\n");
|
||||
|
||||
+ ret = wd_alg_driver_register(&hpre_rsa_driver);
|
||||
+ if (ret)
|
||||
+ WD_ERR("failed to register HPRE rsa driver!\n");
|
||||
for (i = 0; i < alg_num; i++) {
|
||||
ret = wd_alg_driver_register(&hpre_alg_driver[i]);
|
||||
if (ret)
|
||||
@@ -2500,7 +2508,7 @@ static void __attribute__((destructor)) hisi_hpre_remove(void)
|
||||
|
||||
for (i = 0; i < alg_num; i++)
|
||||
wd_alg_driver_unregister(&hpre_alg_driver[i]);
|
||||
+ wd_alg_driver_unregister(&hpre_rsa_driver);
|
||||
}
|
||||
|
||||
-WD_RSA_SET_DRIVER(rsa_hisi_hpre);
|
||||
WD_DH_SET_DRIVER(dh_hisi_hpre);
|
||||
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
|
||||
index 64144e1..0bf8b06 100644
|
||||
--- a/include/drv/wd_dh_drv.h
|
||||
+++ b/include/drv/wd_dh_drv.h
|
||||
@@ -28,8 +28,7 @@ struct wd_dh_driver {
|
||||
const char *drv_name;
|
||||
const char *alg_name;
|
||||
__u32 drv_ctx_size;
|
||||
- int (*init)(struct wd_ctx_config_internal *config, void *priv,
|
||||
- const char *alg_name);
|
||||
+ int (*init)(void *conf, void *priv);
|
||||
void (*exit)(void *priv);
|
||||
int (*send)(handle_t sess, void *dh_msg);
|
||||
int (*recv)(handle_t sess, void *dh_msg);
|
||||
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
|
||||
index baf112f..d231ecf 100644
|
||||
--- a/include/drv/wd_rsa_drv.h
|
||||
+++ b/include/drv/wd_rsa_drv.h
|
||||
@@ -49,35 +49,8 @@ struct wd_rsa_msg {
|
||||
__u8 *key; /* Input key VA pointer, should be DMA buffer */
|
||||
};
|
||||
|
||||
-struct wd_rsa_driver {
|
||||
- const char *drv_name;
|
||||
- const char *alg_name;
|
||||
- __u32 drv_ctx_size;
|
||||
- int (*init)(struct wd_ctx_config_internal *config, void *priv,
|
||||
- const char *alg_name);
|
||||
- void (*exit)(void *priv);
|
||||
- int (*send)(handle_t sess, void *rsa_msg);
|
||||
- int (*recv)(handle_t sess, void *rsa_msg);
|
||||
-};
|
||||
-
|
||||
-void wd_rsa_set_driver(struct wd_rsa_driver *drv);
|
||||
-struct wd_rsa_driver *wd_rsa_get_driver(void);
|
||||
struct wd_rsa_msg *wd_rsa_get_msg(__u32 idx, __u32 tag);
|
||||
|
||||
-#ifdef WD_STATIC_DRV
|
||||
-#define WD_RSA_SET_DRIVER(drv) \
|
||||
-struct wd_rsa_driver *wd_rsa_get_driver(void) \
|
||||
-{ \
|
||||
- return &drv; \
|
||||
-}
|
||||
-#else
|
||||
-#define WD_RSA_SET_DRIVER(drv) \
|
||||
-static void __attribute__((constructor)) set_driver_rsa(void) \
|
||||
-{ \
|
||||
- wd_rsa_set_driver(&(drv)); \
|
||||
-}
|
||||
-#endif
|
||||
-
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
diff --git a/wd_dh.c b/wd_dh.c
|
||||
index d861b34..dd6c921 100644
|
||||
--- a/wd_dh.c
|
||||
+++ b/wd_dh.c
|
||||
@@ -127,8 +127,7 @@ static int wd_dh_common_init(struct wd_ctx_config *config, struct wd_sched *sche
|
||||
}
|
||||
|
||||
wd_dh_setting.priv = priv;
|
||||
- ret = wd_dh_setting.driver->init(&wd_dh_setting.config, priv,
|
||||
- wd_dh_setting.driver->alg_name);
|
||||
+ ret = wd_dh_setting.driver->init(&wd_dh_setting.config, priv);
|
||||
if (ret < 0) {
|
||||
WD_ERR("failed to init dh driver, ret= %d!\n", ret);
|
||||
goto out_free_priv;
|
||||
diff --git a/wd_rsa.c b/wd_rsa.c
|
||||
index 99bfe48..77fe5c0 100644
|
||||
--- a/wd_rsa.c
|
||||
+++ b/wd_rsa.c
|
||||
@@ -74,56 +74,60 @@ static struct wd_rsa_setting {
|
||||
enum wd_status status;
|
||||
struct wd_ctx_config_internal config;
|
||||
struct wd_sched sched;
|
||||
- void *sched_ctx;
|
||||
- const struct wd_rsa_driver *driver;
|
||||
+ struct wd_async_msg_pool pool;
|
||||
+ struct wd_alg_driver *driver;
|
||||
void *priv;
|
||||
void *dlhandle;
|
||||
- struct wd_async_msg_pool pool;
|
||||
+ void *dlh_list;
|
||||
} wd_rsa_setting;
|
||||
|
||||
struct wd_env_config wd_rsa_env_config;
|
||||
static struct wd_init_attrs wd_rsa_init_attrs;
|
||||
|
||||
-static struct wd_ctx_nums wd_rsa_ctx_num[] = {
|
||||
- {1, 1}, {}
|
||||
-};
|
||||
-
|
||||
-static struct wd_ctx_params wd_rsa_ctx_params = {
|
||||
- .op_type_num = 1,
|
||||
- .ctx_set_num = wd_rsa_ctx_num,
|
||||
- .bmp = NULL,
|
||||
-};
|
||||
-
|
||||
-#ifdef WD_STATIC_DRV
|
||||
-static void wd_rsa_set_static_drv(void)
|
||||
+static void wd_rsa_close_driver(void)
|
||||
{
|
||||
- wd_rsa_setting.driver = wd_rsa_get_driver();
|
||||
- if (!wd_rsa_setting.driver)
|
||||
- WD_ERR("failed to get rsa driver!\n");
|
||||
-}
|
||||
-#else
|
||||
-static void __attribute__((constructor)) wd_rsa_open_driver(void)
|
||||
-{
|
||||
- wd_rsa_setting.dlhandle = dlopen("libhisi_hpre.so", RTLD_NOW);
|
||||
if (!wd_rsa_setting.dlhandle)
|
||||
- WD_ERR("failed to open libhisi_hpre.so, %s\n", dlerror());
|
||||
-}
|
||||
+ return;
|
||||
|
||||
-static void __attribute__((destructor)) wd_rsa_close_driver(void)
|
||||
-{
|
||||
- if (wd_rsa_setting.dlhandle)
|
||||
- dlclose(wd_rsa_setting.dlhandle);
|
||||
+ wd_release_drv(wd_rsa_setting.driver);
|
||||
+ dlclose(wd_rsa_setting.dlhandle);
|
||||
+ wd_rsa_setting.dlhandle = NULL;
|
||||
}
|
||||
-#endif
|
||||
|
||||
-void wd_rsa_set_driver(struct wd_rsa_driver *drv)
|
||||
+static int wd_rsa_open_driver(void)
|
||||
{
|
||||
- if (!drv) {
|
||||
- WD_ERR("invalid: rsa drv is NULL!\n");
|
||||
- return;
|
||||
+ struct wd_alg_driver *driver = NULL;
|
||||
+ char lib_path[PATH_STR_SIZE];
|
||||
+ const char *alg_name = "rsa";
|
||||
+ int ret;
|
||||
+
|
||||
+ /*
|
||||
+ * Compatible with the normal acquisition of device
|
||||
+ * drivers in the init interface.
|
||||
+ */
|
||||
+ if (wd_rsa_setting.dlh_list)
|
||||
+ return 0;
|
||||
+
|
||||
+ ret = wd_get_lib_file_path("libhisi_hpre.so", lib_path, false);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+
|
||||
+ wd_rsa_setting.dlhandle = dlopen(lib_path, RTLD_NOW);
|
||||
+ if (!wd_rsa_setting.dlhandle) {
|
||||
+ WD_ERR("failed to open libhisi_hpre.so, %s!\n", dlerror());
|
||||
+ return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- wd_rsa_setting.driver = drv;
|
||||
+ driver = wd_request_drv(alg_name, false);
|
||||
+ if (!driver) {
|
||||
+ wd_rsa_close_driver();
|
||||
+ WD_ERR("failed to get %s driver support!\n", alg_name);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ wd_rsa_setting.driver = driver;
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static void wd_rsa_clear_status(void)
|
||||
@@ -133,7 +137,6 @@ static void wd_rsa_clear_status(void)
|
||||
|
||||
static int wd_rsa_common_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- void *priv;
|
||||
int ret;
|
||||
|
||||
ret = wd_set_epoll_en("WD_RSA_EPOLL_EN",
|
||||
@@ -149,10 +152,6 @@ static int wd_rsa_common_init(struct wd_ctx_config *config, struct wd_sched *sch
|
||||
if (ret < 0)
|
||||
goto out_clear_ctx_config;
|
||||
|
||||
-#ifdef WD_STATIC_DRV
|
||||
- wd_rsa_set_static_drv();
|
||||
-#endif
|
||||
-
|
||||
/* fix me: sadly find we allocate async pool for every ctx */
|
||||
ret = wd_init_async_request_pool(&wd_rsa_setting.pool,
|
||||
config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
@@ -160,26 +159,14 @@ static int wd_rsa_common_init(struct wd_ctx_config *config, struct wd_sched *sch
|
||||
if (ret < 0)
|
||||
goto out_clear_sched;
|
||||
|
||||
- /* initialize ctx related resources in specific driver */
|
||||
- priv = calloc(1, wd_rsa_setting.driver->drv_ctx_size);
|
||||
- if (!priv) {
|
||||
- ret = -WD_ENOMEM;
|
||||
+ ret = wd_alg_init_driver(&wd_rsa_setting.config,
|
||||
+ wd_rsa_setting.driver,
|
||||
+ &wd_rsa_setting.priv);
|
||||
+ if (ret)
|
||||
goto out_clear_pool;
|
||||
- }
|
||||
-
|
||||
- wd_rsa_setting.priv = priv;
|
||||
- ret = wd_rsa_setting.driver->init(&wd_rsa_setting.config, priv,
|
||||
- wd_rsa_setting.driver->alg_name);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to init rsa driver, ret = %d!\n", ret);
|
||||
- goto out_free_priv;
|
||||
- }
|
||||
|
||||
return 0;
|
||||
|
||||
-out_free_priv:
|
||||
- free(priv);
|
||||
- wd_rsa_setting.priv = NULL;
|
||||
out_clear_pool:
|
||||
wd_uninit_async_request_pool(&wd_rsa_setting.pool);
|
||||
out_clear_sched:
|
||||
@@ -196,17 +183,14 @@ static void wd_rsa_common_uninit(void)
|
||||
return;
|
||||
}
|
||||
|
||||
- /* driver uninit */
|
||||
- wd_rsa_setting.driver->exit(wd_rsa_setting.priv);
|
||||
- free(wd_rsa_setting.priv);
|
||||
- wd_rsa_setting.priv = NULL;
|
||||
-
|
||||
/* uninit async request pool */
|
||||
wd_uninit_async_request_pool(&wd_rsa_setting.pool);
|
||||
|
||||
/* unset config, sched, driver */
|
||||
wd_clear_sched(&wd_rsa_setting.sched);
|
||||
- wd_clear_ctx_config(&wd_rsa_setting.config);
|
||||
+ wd_alg_uninit_driver(&wd_rsa_setting.config,
|
||||
+ wd_rsa_setting.driver,
|
||||
+ &wd_rsa_setting.priv);
|
||||
}
|
||||
|
||||
int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
@@ -224,14 +208,20 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
if (ret)
|
||||
goto out_clear_init;
|
||||
|
||||
- ret = wd_rsa_common_init(config, sched);
|
||||
+ ret = wd_rsa_open_driver();
|
||||
if (ret)
|
||||
goto out_clear_init;
|
||||
|
||||
+ ret = wd_rsa_common_init(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_close_driver;
|
||||
+
|
||||
wd_alg_set_init(&wd_rsa_setting.status);
|
||||
|
||||
return 0;
|
||||
|
||||
+out_close_driver:
|
||||
+ wd_rsa_close_driver();
|
||||
out_clear_init:
|
||||
wd_alg_clear_init(&wd_rsa_setting.status);
|
||||
return ret;
|
||||
@@ -240,11 +230,14 @@ out_clear_init:
|
||||
void wd_rsa_uninit(void)
|
||||
{
|
||||
wd_rsa_common_uninit();
|
||||
+ wd_rsa_close_driver();
|
||||
wd_alg_clear_init(&wd_rsa_setting.status);
|
||||
}
|
||||
|
||||
int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params)
|
||||
{
|
||||
+ struct wd_ctx_nums rsa_ctx_num[WD_RSA_GENKEY] = {0};
|
||||
+ struct wd_ctx_params rsa_ctx_params = {0};
|
||||
bool flag;
|
||||
int ret;
|
||||
|
||||
@@ -260,19 +253,66 @@ 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");
|
||||
+ ret = -WD_EINVAL;
|
||||
+ goto out_clear_init;
|
||||
+ }
|
||||
+
|
||||
+res_retry:
|
||||
+ memset(&wd_rsa_setting.config, 0, sizeof(struct wd_ctx_config_internal));
|
||||
+
|
||||
+ /* Get alg driver and dev name */
|
||||
+ wd_rsa_setting.driver = wd_alg_drv_bind(task_type, alg);
|
||||
+ if (!wd_rsa_setting.driver) {
|
||||
+ WD_ERR("failed to bind a valid driver!\n");
|
||||
+ ret = -WD_EINVAL;
|
||||
+ goto out_dlopen;
|
||||
+ }
|
||||
+
|
||||
+ ret = wd_ctx_param_init(&rsa_ctx_params, ctx_params,
|
||||
+ rsa_ctx_num, wd_rsa_setting.driver,
|
||||
+ WD_RSA_GENKEY);
|
||||
+ if (ret) {
|
||||
+ if (ret == -WD_EAGAIN) {
|
||||
+ wd_disable_drv(wd_rsa_setting.driver);
|
||||
+ wd_alg_drv_unbind(wd_rsa_setting.driver);
|
||||
+ goto res_retry;
|
||||
+ }
|
||||
+ goto out_driver;
|
||||
+ }
|
||||
+
|
||||
wd_rsa_init_attrs.alg = alg;
|
||||
wd_rsa_init_attrs.sched_type = sched_type;
|
||||
- wd_rsa_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_rsa_ctx_params;
|
||||
+ wd_rsa_init_attrs.driver = wd_rsa_setting.driver;
|
||||
+ wd_rsa_init_attrs.ctx_params = &rsa_ctx_params;
|
||||
wd_rsa_init_attrs.alg_init = wd_rsa_common_init;
|
||||
wd_rsa_init_attrs.alg_poll_ctx = wd_rsa_poll_ctx;
|
||||
ret = wd_alg_attrs_init(&wd_rsa_init_attrs);
|
||||
- if (ret)
|
||||
- goto out_clear_init;
|
||||
+ if (ret) {
|
||||
+ if (ret == -WD_ENODEV) {
|
||||
+ wd_disable_drv(wd_rsa_setting.driver);
|
||||
+ wd_alg_drv_unbind(wd_rsa_setting.driver);
|
||||
+ goto res_retry;
|
||||
+ }
|
||||
+ WD_ERR("failed to init alg attrs!\n");
|
||||
+ goto out_driver;
|
||||
+ }
|
||||
|
||||
wd_alg_set_init(&wd_rsa_setting.status);
|
||||
|
||||
return 0;
|
||||
|
||||
+out_driver:
|
||||
+ wd_alg_drv_unbind(wd_rsa_setting.driver);
|
||||
+out_dlopen:
|
||||
+ wd_dlclose_drv(wd_rsa_setting.dlh_list);
|
||||
out_clear_init:
|
||||
wd_alg_clear_init(&wd_rsa_setting.status);
|
||||
return ret;
|
||||
@@ -282,6 +322,9 @@ void wd_rsa_uninit2(void)
|
||||
{
|
||||
wd_rsa_common_uninit();
|
||||
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_setting.dlh_list = NULL;
|
||||
wd_alg_clear_init(&wd_rsa_setting.status);
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
410
0016-uadk-dh-adapt-the-dh-module-to-the-dynamic-loading-f.patch
Normal file
410
0016-uadk-dh-adapt-the-dh-module-to-the-dynamic-loading-f.patch
Normal file
@ -0,0 +1,410 @@
|
||||
From 3d5cad6d620aa353fbaff53dc9b502d918817b1f Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Sat, 11 Feb 2023 15:19:34 +0800
|
||||
Subject: [PATCH 16/28] uadk/dh: adapt the dh module to the dynamic loading
|
||||
framework
|
||||
|
||||
After adding the ecc module of the init2 interface, combine it
|
||||
dynamically load the initialization part, transform HiSilicon HPRE
|
||||
driven, and implemented using the dynamic loading function Connection
|
||||
between driver and algorithm layer.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
drv/hisi_hpre.c | 32 +++++---
|
||||
include/drv/wd_dh_drv.h | 26 ------
|
||||
wd_dh.c | 174 +++++++++++++++++++++++++---------------
|
||||
3 files changed, 129 insertions(+), 103 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
|
||||
index 8ecb950..4d21788 100644
|
||||
--- a/drv/hisi_hpre.c
|
||||
+++ b/drv/hisi_hpre.c
|
||||
@@ -793,16 +793,6 @@ static int dh_recv(handle_t ctx, void *dh_msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static struct wd_dh_driver dh_hisi_hpre = {
|
||||
- .drv_name = "hisi_hpre",
|
||||
- .alg_name = "dh",
|
||||
- .drv_ctx_size = sizeof(struct hisi_hpre_ctx),
|
||||
- .init = hpre_rsa_dh_init,
|
||||
- .exit = hpre_exit,
|
||||
- .send = dh_send,
|
||||
- .recv = dh_recv,
|
||||
-};
|
||||
-
|
||||
static int ecc_prepare_alg(struct wd_ecc_msg *msg,
|
||||
struct hisi_hpre_sqe *hw_msg)
|
||||
{
|
||||
@@ -2484,6 +2474,19 @@ static struct wd_alg_driver hpre_rsa_driver = {
|
||||
.recv = rsa_recv,
|
||||
};
|
||||
|
||||
+static struct wd_alg_driver hpre_dh_driver = {
|
||||
+ .drv_name = "hisi_hpre",
|
||||
+ .alg_name = "dh",
|
||||
+ .priority = UADK_ALG_HW,
|
||||
+ .priv_size = sizeof(struct hisi_hpre_ctx),
|
||||
+ .queue_num = HPRE_CTX_Q_NUM_DEF,
|
||||
+ .op_type_num = 1,
|
||||
+ .fallback = 0,
|
||||
+ .init = hpre_rsa_dh_init,
|
||||
+ .exit = hpre_exit,
|
||||
+ .send = dh_send,
|
||||
+ .recv = dh_recv,
|
||||
+};
|
||||
static void __attribute__((constructor)) hisi_hpre_probe(void)
|
||||
{
|
||||
int alg_num = ARRAY_SIZE(hpre_alg_driver);
|
||||
@@ -2494,6 +2497,11 @@ static void __attribute__((constructor)) hisi_hpre_probe(void)
|
||||
ret = wd_alg_driver_register(&hpre_rsa_driver);
|
||||
if (ret)
|
||||
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");
|
||||
+
|
||||
for (i = 0; i < alg_num; i++) {
|
||||
ret = wd_alg_driver_register(&hpre_alg_driver[i]);
|
||||
if (ret)
|
||||
@@ -2508,7 +2516,7 @@ static void __attribute__((destructor)) hisi_hpre_remove(void)
|
||||
|
||||
for (i = 0; i < alg_num; i++)
|
||||
wd_alg_driver_unregister(&hpre_alg_driver[i]);
|
||||
+
|
||||
+ wd_alg_driver_unregister(&hpre_dh_driver);
|
||||
wd_alg_driver_unregister(&hpre_rsa_driver);
|
||||
}
|
||||
-
|
||||
-WD_DH_SET_DRIVER(dh_hisi_hpre);
|
||||
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
|
||||
index 0bf8b06..d205dc4 100644
|
||||
--- a/include/drv/wd_dh_drv.h
|
||||
+++ b/include/drv/wd_dh_drv.h
|
||||
@@ -24,34 +24,8 @@ struct wd_dh_msg {
|
||||
__u8 result; /* Data format, denoted by WD error code */
|
||||
};
|
||||
|
||||
-struct wd_dh_driver {
|
||||
- const char *drv_name;
|
||||
- const char *alg_name;
|
||||
- __u32 drv_ctx_size;
|
||||
- int (*init)(void *conf, void *priv);
|
||||
- void (*exit)(void *priv);
|
||||
- int (*send)(handle_t sess, void *dh_msg);
|
||||
- int (*recv)(handle_t sess, void *dh_msg);
|
||||
-};
|
||||
-
|
||||
-void wd_dh_set_driver(struct wd_dh_driver *drv);
|
||||
-struct wd_dh_driver *wd_dh_get_driver(void);
|
||||
struct wd_dh_msg *wd_dh_get_msg(__u32 idx, __u32 tag);
|
||||
|
||||
-#ifdef WD_STATIC_DRV
|
||||
-#define WD_DH_SET_DRIVER(drv) \
|
||||
-struct wd_dh_driver *wd_dh_get_driver(void) \
|
||||
-{ \
|
||||
- return &drv; \
|
||||
-}
|
||||
-#else
|
||||
-#define WD_DH_SET_DRIVER(drv) \
|
||||
-static void __attribute__((constructor)) set_driver_dh(void) \
|
||||
-{ \
|
||||
- wd_dh_set_driver(&(drv)); \
|
||||
-}
|
||||
-#endif
|
||||
-
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
diff --git a/wd_dh.c b/wd_dh.c
|
||||
index dd6c921..d45ac89 100644
|
||||
--- a/wd_dh.c
|
||||
+++ b/wd_dh.c
|
||||
@@ -33,56 +33,60 @@ static struct wd_dh_setting {
|
||||
enum wd_status status;
|
||||
struct wd_ctx_config_internal config;
|
||||
struct wd_sched sched;
|
||||
- void *sched_ctx;
|
||||
- const struct wd_dh_driver *driver;
|
||||
+ struct wd_async_msg_pool pool;
|
||||
+ struct wd_alg_driver *driver;
|
||||
void *priv;
|
||||
void *dlhandle;
|
||||
- struct wd_async_msg_pool pool;
|
||||
+ void *dlh_list;
|
||||
} wd_dh_setting;
|
||||
|
||||
struct wd_env_config wd_dh_env_config;
|
||||
static struct wd_init_attrs wd_dh_init_attrs;
|
||||
|
||||
-static struct wd_ctx_nums wd_dh_ctx_num[] = {
|
||||
- {1, 1}, {}
|
||||
-};
|
||||
-
|
||||
-static struct wd_ctx_params wd_dh_ctx_params = {
|
||||
- .op_type_num = 1,
|
||||
- .ctx_set_num = wd_dh_ctx_num,
|
||||
- .bmp = NULL,
|
||||
-};
|
||||
-
|
||||
-#ifdef WD_STATIC_DRV
|
||||
-static void wd_dh_set_static_drv(void)
|
||||
+static void wd_dh_close_driver(void)
|
||||
{
|
||||
- wd_dh_setting.driver = wd_dh_get_driver();
|
||||
- if (!wd_dh_setting.driver)
|
||||
- WD_ERR("failed to get dh driver!\n");
|
||||
-}
|
||||
-#else
|
||||
-static void __attribute__((constructor)) wd_dh_open_driver(void)
|
||||
-{
|
||||
- wd_dh_setting.dlhandle = dlopen("libhisi_hpre.so", RTLD_NOW);
|
||||
if (!wd_dh_setting.dlhandle)
|
||||
- WD_ERR("failed to open libhisi_hpre.so, %s\n", dlerror());
|
||||
-}
|
||||
+ return;
|
||||
|
||||
-static void __attribute__((destructor)) wd_dh_close_driver(void)
|
||||
-{
|
||||
- if (wd_dh_setting.dlhandle)
|
||||
- dlclose(wd_dh_setting.dlhandle);
|
||||
+ wd_release_drv(wd_dh_setting.driver);
|
||||
+ dlclose(wd_dh_setting.dlhandle);
|
||||
+ wd_dh_setting.dlhandle = NULL;
|
||||
}
|
||||
-#endif
|
||||
|
||||
-void wd_dh_set_driver(struct wd_dh_driver *drv)
|
||||
+static int wd_dh_open_driver(void)
|
||||
{
|
||||
- if (!drv) {
|
||||
- WD_ERR("invalid: dh drv is NULL!\n");
|
||||
- return;
|
||||
+ struct wd_alg_driver *driver = NULL;
|
||||
+ char lib_path[PATH_STR_SIZE];
|
||||
+ const char *alg_name = "dh";
|
||||
+ int ret;
|
||||
+
|
||||
+ /*
|
||||
+ * Compatible with the normal acquisition of device
|
||||
+ * drivers in the init interface.
|
||||
+ */
|
||||
+ if (wd_dh_setting.dlh_list)
|
||||
+ return 0;
|
||||
+
|
||||
+ ret = wd_get_lib_file_path("libhisi_hpre.so", lib_path, false);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+
|
||||
+ wd_dh_setting.dlhandle = dlopen(lib_path, RTLD_NOW);
|
||||
+ if (!wd_dh_setting.dlhandle) {
|
||||
+ WD_ERR("failed to open libhisi_hpre.so, %s!\n", dlerror());
|
||||
+ return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- wd_dh_setting.driver = drv;
|
||||
+ driver = wd_request_drv(alg_name, false);
|
||||
+ if (!driver) {
|
||||
+ wd_dh_close_driver();
|
||||
+ WD_ERR("failed to get %s driver support\n", alg_name);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ wd_dh_setting.driver = driver;
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static void wd_dh_clear_status(void)
|
||||
@@ -92,7 +96,6 @@ static void wd_dh_clear_status(void)
|
||||
|
||||
static int wd_dh_common_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- void *priv;
|
||||
int ret;
|
||||
|
||||
ret = wd_set_epoll_en("WD_DH_EPOLL_EN",
|
||||
@@ -108,10 +111,6 @@ static int wd_dh_common_init(struct wd_ctx_config *config, struct wd_sched *sche
|
||||
if (ret)
|
||||
goto out_clear_ctx_config;
|
||||
|
||||
-#ifdef WD_STATIC_DRV
|
||||
- wd_dh_set_static_drv();
|
||||
-#endif
|
||||
-
|
||||
/* initialize async request pool */
|
||||
ret = wd_init_async_request_pool(&wd_dh_setting.pool,
|
||||
config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
@@ -119,25 +118,14 @@ static int wd_dh_common_init(struct wd_ctx_config *config, struct wd_sched *sche
|
||||
if (ret)
|
||||
goto out_clear_sched;
|
||||
|
||||
- /* initialize ctx related resources in specific driver */
|
||||
- priv = calloc(1, wd_dh_setting.driver->drv_ctx_size);
|
||||
- if (!priv) {
|
||||
- ret = -WD_ENOMEM;
|
||||
+ ret = wd_alg_init_driver(&wd_dh_setting.config,
|
||||
+ wd_dh_setting.driver,
|
||||
+ &wd_dh_setting.priv);
|
||||
+ if (ret)
|
||||
goto out_clear_pool;
|
||||
- }
|
||||
-
|
||||
- wd_dh_setting.priv = priv;
|
||||
- ret = wd_dh_setting.driver->init(&wd_dh_setting.config, priv);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to init dh driver, ret= %d!\n", ret);
|
||||
- goto out_free_priv;
|
||||
- }
|
||||
|
||||
return 0;
|
||||
|
||||
-out_free_priv:
|
||||
- free(priv);
|
||||
- wd_dh_setting.priv = NULL;
|
||||
out_clear_pool:
|
||||
wd_uninit_async_request_pool(&wd_dh_setting.pool);
|
||||
out_clear_sched:
|
||||
@@ -154,17 +142,14 @@ static void wd_dh_common_uninit(void)
|
||||
return;
|
||||
}
|
||||
|
||||
- /* driver uninit */
|
||||
- wd_dh_setting.driver->exit(wd_dh_setting.priv);
|
||||
- free(wd_dh_setting.priv);
|
||||
- wd_dh_setting.priv = NULL;
|
||||
-
|
||||
/* uninit async request pool */
|
||||
wd_uninit_async_request_pool(&wd_dh_setting.pool);
|
||||
|
||||
/* unset config, sched, driver */
|
||||
wd_clear_sched(&wd_dh_setting.sched);
|
||||
- wd_clear_ctx_config(&wd_dh_setting.config);
|
||||
+ wd_alg_uninit_driver(&wd_dh_setting.config,
|
||||
+ wd_dh_setting.driver,
|
||||
+ &wd_dh_setting.priv);
|
||||
}
|
||||
|
||||
int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
@@ -182,14 +167,20 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
if (ret)
|
||||
goto out_clear_init;
|
||||
|
||||
- ret = wd_dh_common_init(config, sched);
|
||||
+ ret = wd_dh_open_driver();
|
||||
if (ret)
|
||||
goto out_clear_init;
|
||||
|
||||
+ ret = wd_dh_common_init(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_close_driver;
|
||||
+
|
||||
wd_alg_set_init(&wd_dh_setting.status);
|
||||
|
||||
return 0;
|
||||
|
||||
+out_close_driver:
|
||||
+ wd_dh_close_driver();
|
||||
out_clear_init:
|
||||
wd_alg_clear_init(&wd_dh_setting.status);
|
||||
return ret;
|
||||
@@ -198,11 +189,14 @@ out_clear_init:
|
||||
void wd_dh_uninit(void)
|
||||
{
|
||||
wd_dh_common_uninit();
|
||||
+ wd_dh_close_driver();
|
||||
wd_alg_clear_init(&wd_dh_setting.status);
|
||||
}
|
||||
|
||||
int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params)
|
||||
{
|
||||
+ struct wd_ctx_nums dh_ctx_num[WD_DH_PHASE2] = {0};
|
||||
+ struct wd_ctx_params dh_ctx_params = {0};
|
||||
bool flag;
|
||||
int ret;
|
||||
|
||||
@@ -218,19 +212,66 @@ 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");
|
||||
+ ret = -WD_EINVAL;
|
||||
+ goto out_clear_init;
|
||||
+ }
|
||||
+
|
||||
+res_retry:
|
||||
+ memset(&wd_dh_setting.config, 0, sizeof(struct wd_ctx_config_internal));
|
||||
+
|
||||
+ /* Get alg driver and dev name */
|
||||
+ wd_dh_setting.driver = wd_alg_drv_bind(task_type, alg);
|
||||
+ if (!wd_dh_setting.driver) {
|
||||
+ WD_ERR("fail to bind a valid driver.\n");
|
||||
+ ret = -WD_EINVAL;
|
||||
+ goto out_dlopen;
|
||||
+ }
|
||||
+
|
||||
+ ret = wd_ctx_param_init(&dh_ctx_params, ctx_params,
|
||||
+ dh_ctx_num, wd_dh_setting.driver,
|
||||
+ WD_DH_PHASE2);
|
||||
+ if (ret) {
|
||||
+ if (ret == -WD_EAGAIN) {
|
||||
+ wd_disable_drv(wd_dh_setting.driver);
|
||||
+ wd_alg_drv_unbind(wd_dh_setting.driver);
|
||||
+ goto res_retry;
|
||||
+ }
|
||||
+ goto out_driver;
|
||||
+ }
|
||||
+
|
||||
wd_dh_init_attrs.alg = alg;
|
||||
wd_dh_init_attrs.sched_type = sched_type;
|
||||
- wd_dh_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_dh_ctx_params;
|
||||
+ wd_dh_init_attrs.driver = wd_dh_setting.driver;
|
||||
+ wd_dh_init_attrs.ctx_params = &dh_ctx_params;
|
||||
wd_dh_init_attrs.alg_init = wd_dh_common_init;
|
||||
wd_dh_init_attrs.alg_poll_ctx = wd_dh_poll_ctx;
|
||||
ret = wd_alg_attrs_init(&wd_dh_init_attrs);
|
||||
- if (ret)
|
||||
- goto out_clear_init;
|
||||
+ if (ret) {
|
||||
+ if (ret == -WD_ENODEV) {
|
||||
+ wd_disable_drv(wd_dh_setting.driver);
|
||||
+ wd_alg_drv_unbind(wd_dh_setting.driver);
|
||||
+ goto res_retry;
|
||||
+ }
|
||||
+ WD_ERR("failed to init alg attrs!\n");
|
||||
+ goto out_driver;
|
||||
+ }
|
||||
|
||||
wd_alg_set_init(&wd_dh_setting.status);
|
||||
|
||||
return 0;
|
||||
|
||||
+out_driver:
|
||||
+ wd_alg_drv_unbind(wd_dh_setting.driver);
|
||||
+out_dlopen:
|
||||
+ wd_dlclose_drv(wd_dh_setting.dlh_list);
|
||||
out_clear_init:
|
||||
wd_alg_clear_init(&wd_dh_setting.status);
|
||||
return ret;
|
||||
@@ -240,6 +281,9 @@ void wd_dh_uninit2(void)
|
||||
{
|
||||
wd_dh_common_uninit();
|
||||
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_setting.dlh_list = NULL;
|
||||
wd_alg_clear_init(&wd_dh_setting.status);
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -0,0 +1,55 @@
|
||||
From c2ae0f385c036f05436902aebe4df205be884c34 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Wed, 15 Mar 2023 16:07:19 +0800
|
||||
Subject: [PATCH 17/28] uadk - the description document of the uadk log is
|
||||
added
|
||||
|
||||
The document file describes how to set up a uadk log.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
docs/log.rst | 32 ++++++++++++++++++++++++++++++++
|
||||
1 file changed, 32 insertions(+)
|
||||
create mode 100644 docs/log.rst
|
||||
|
||||
diff --git a/docs/log.rst b/docs/log.rst
|
||||
new file mode 100644
|
||||
index 0000000..5e36591
|
||||
--- /dev/null
|
||||
+++ b/docs/log.rst
|
||||
@@ -0,0 +1,32 @@
|
||||
+
|
||||
+The rsyslog.conf file is the main configuration file for the rsyslogd which logs system
|
||||
+messages on systems. The uadk library can set up the log level and log file by use the rsyslogd.
|
||||
+the uadk log can be printed in message or syslog file default. You can set your own uadk.log
|
||||
+file in rsyslog.conf.
|
||||
+
|
||||
+1. If selected the static compilation, the syslog will not be used, The information will be printed
|
||||
+ on the serial port.
|
||||
+2. If not edited the rsyslog.conf, the log files will be printed in /var/log/messages.
|
||||
+3. If you don't want to use the rsyslogd, you can edit the Makefile.am. The information will be
|
||||
+ printed on the serial port.
|
||||
+4. If you want to use the rsyslogd, you can see the following information.
|
||||
+
|
||||
+The uadk supports four setting commands, the log level parameters:
|
||||
+ local5.err # display the error conditions
|
||||
+ local5.info # display the warning and error conditions
|
||||
+ local5.debug # display the debug,warning,error conditions
|
||||
+ local5.* # print levels are not differentiated.
|
||||
+
|
||||
+The following steps will help you set up the syslog file:
|
||||
+
|
||||
+step 1:
|
||||
+ Add the following information to the last line of /etc/rsyslog.conf:
|
||||
+ local5.err /var/log/uadk.log
|
||||
+
|
||||
+step 2:
|
||||
+ Restart the rsyslog daemon service. The cmd is:
|
||||
+ service rsyslog restart
|
||||
+
|
||||
+After you run the tasks. You can see the uadk.log in /var/log/uadk/log. If you want to clear the
|
||||
+log file, you can use the following cmd: echo 0 > /var/log/uadk.log.
|
||||
+
|
||||
--
|
||||
2.25.1
|
||||
|
||||
399
0018-uadk-the-features-of-testing-the-correctness-is-adde.patch
Normal file
399
0018-uadk-the-features-of-testing-the-correctness-is-adde.patch
Normal file
@ -0,0 +1,399 @@
|
||||
From e6c5c4808e1db6bc367aaa3c5282446d516abf50 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Thu, 16 Mar 2023 09:32:22 +0800
|
||||
Subject: [PATCH 18/28] uadk - the features of testing the correctness is added
|
||||
|
||||
Unified the acc test framework. This framework is used to run algorithm
|
||||
correctness. It can helps developers with feature self-testing. Only
|
||||
supports sec engine self-testing currently.
|
||||
Such as:
|
||||
test_sec_sva --cipher 0 --sync --optype 0 --pktlen 16 --keylen \
|
||||
16 --times 1 --multi 1
|
||||
after:
|
||||
uadk_tool test --m sec --cipher 0 --sync --optype 0 --pktlen 16 \
|
||||
--keylen 16 --times 1 --multi 1
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
configure.ac | 1 -
|
||||
test/Makefile.am | 3 +-
|
||||
test/hisi_sec_test/Makefile.am | 15 ----
|
||||
test/wd_mempool_test.c | 2 +-
|
||||
uadk_tool/Makefile.am | 4 +-
|
||||
.../test/sec_template_tv.h | 6 +-
|
||||
.../test/test_sec.c | 42 +++++----
|
||||
uadk_tool/test/test_sec.h | 10 +++
|
||||
uadk_tool/test/uadk_test.c | 86 +++++++++++++++++++
|
||||
uadk_tool/test/uadk_test.h | 8 ++
|
||||
uadk_tool/uadk_tool.c | 7 +-
|
||||
11 files changed, 141 insertions(+), 43 deletions(-)
|
||||
delete mode 100644 test/hisi_sec_test/Makefile.am
|
||||
rename test/hisi_sec_test/test_hisi_sec.h => uadk_tool/test/sec_template_tv.h (99%)
|
||||
rename test/hisi_sec_test/test_hisi_sec.c => uadk_tool/test/test_sec.c (98%)
|
||||
mode change 100755 => 100644
|
||||
create mode 100644 uadk_tool/test/test_sec.h
|
||||
create mode 100644 uadk_tool/test/uadk_test.c
|
||||
create mode 100644 uadk_tool/test/uadk_test.h
|
||||
|
||||
diff --git a/configure.ac b/configure.ac
|
||||
index 3eb853f..7109d97 100644
|
||||
--- a/configure.ac
|
||||
+++ b/configure.ac
|
||||
@@ -91,7 +91,6 @@ AC_CONFIG_FILES([Makefile
|
||||
lib/libwd_crypto.pc lib/libwd_comp.pc lib/libwd.pc
|
||||
test/Makefile
|
||||
test/hisi_hpre_test/Makefile
|
||||
- test/hisi_sec_test/Makefile
|
||||
test/hisi_zip_test/Makefile
|
||||
uadk_tool/Makefile
|
||||
sample/Makefile
|
||||
diff --git a/test/Makefile.am b/test/Makefile.am
|
||||
index 87b97ca..5666000 100644
|
||||
--- a/test/Makefile.am
|
||||
+++ b/test/Makefile.am
|
||||
@@ -12,8 +12,7 @@ wd_mempool_test_LDADD=-L../.libs -lwd -ldl -lwd_crypto -lnuma -lpthread
|
||||
endif
|
||||
wd_mempool_test_LDFLAGS=-Wl,-rpath,'/usr/local/lib'
|
||||
|
||||
-SUBDIRS=. hisi_sec_test
|
||||
-
|
||||
+SUBDIRS = .
|
||||
if HAVE_CRYPTO
|
||||
SUBDIRS += hisi_hpre_test
|
||||
|
||||
diff --git a/test/hisi_sec_test/Makefile.am b/test/hisi_sec_test/Makefile.am
|
||||
deleted file mode 100644
|
||||
index 61506d4..0000000
|
||||
--- a/test/hisi_sec_test/Makefile.am
|
||||
+++ /dev/null
|
||||
@@ -1,15 +0,0 @@
|
||||
-AM_CFLAGS=-Wall -Werror -fno-strict-aliasing -I$(top_srcdir)/include -pthread
|
||||
-AUTOMAKE_OPTIONS = subdir-objects
|
||||
-
|
||||
-bin_PROGRAMS=test_hisi_sec
|
||||
-
|
||||
-test_hisi_sec_SOURCES=test_hisi_sec.c
|
||||
-
|
||||
-if WD_STATIC_DRV
|
||||
-AM_CFLAGS+=-Bstatic
|
||||
-test_hisi_sec_LDADD=../../.libs/libwd.a ../../.libs/libwd_crypto.a \
|
||||
- ../../.libs/libhisi_sec.a -ldl -lnuma
|
||||
-else
|
||||
-test_hisi_sec_LDADD=-L../../.libs -l:libwd.so.2 -l:libwd_crypto.so.2 -lnuma
|
||||
-endif
|
||||
-test_hisi_sec_LDFLAGS=-Wl,-rpath,'/usr/local/lib'
|
||||
diff --git a/test/wd_mempool_test.c b/test/wd_mempool_test.c
|
||||
index cf6be70..ad04636 100644
|
||||
--- a/test/wd_mempool_test.c
|
||||
+++ b/test/wd_mempool_test.c
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <sys/mman.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
-#include "hisi_sec_test/test_hisi_sec.h"
|
||||
+#include "../uadk_tool/test/sec_template_tv.h"
|
||||
#include "wd.h"
|
||||
#include "wd_cipher.h"
|
||||
#include "wd_sched.h"
|
||||
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am
|
||||
index d5b125f..6d0450e 100644
|
||||
--- a/uadk_tool/Makefile.am
|
||||
+++ b/uadk_tool/Makefile.am
|
||||
@@ -14,7 +14,9 @@ uadk_tool_SOURCES=uadk_tool.c dfx/uadk_dfx.c dfx/uadk_dfx.h \
|
||||
benchmark/hpre_uadk_benchmark.c benchmark/hpre_uadk_benchmark.h \
|
||||
benchmark/hpre_wd_benchmark.c hpre_wd_benchmark.h \
|
||||
benchmark/zip_uadk_benchmark.c benchmark/zip_uadk_benchmark.h \
|
||||
- benchmark/zip_wd_benchmark.c benchmark/zip_wd_benchmark.h
|
||||
+ benchmark/zip_wd_benchmark.c benchmark/zip_wd_benchmark.h \
|
||||
+ test/uadk_test.c test/uadk_test.h \
|
||||
+ test/test_sec.c test/test_sec.h test/sec_template_tv.h
|
||||
|
||||
if WD_STATIC_DRV
|
||||
AM_CFLAGS+=-Bstatic
|
||||
diff --git a/test/hisi_sec_test/test_hisi_sec.h b/uadk_tool/test/sec_template_tv.h
|
||||
similarity index 99%
|
||||
rename from test/hisi_sec_test/test_hisi_sec.h
|
||||
rename to uadk_tool/test/sec_template_tv.h
|
||||
index 8e21681..1a6f960 100644
|
||||
--- a/test/hisi_sec_test/test_hisi_sec.h
|
||||
+++ b/uadk_tool/test/sec_template_tv.h
|
||||
@@ -1,8 +1,8 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
/* Copyright 2020-2021 Huawei Technologies Co.,Ltd. All rights reserved. */
|
||||
|
||||
-#ifndef TEST_HISI_SEC_H_
|
||||
-#define TEST_HISI_SEC_H
|
||||
+#ifndef SEC_TEMPLATE_TV_H
|
||||
+#define SEC_TEMPLATE_TV_H
|
||||
|
||||
enum alg_class {
|
||||
CIPHER_CLASS,
|
||||
@@ -1840,4 +1840,4 @@ struct aead_testvec sm4_gcm_tv_template_128[] = {
|
||||
}
|
||||
};
|
||||
|
||||
-#endif /* TEST_HISI_SEC_H_ */
|
||||
+#endif /* SEC_TEMPLATE_TV_H */
|
||||
diff --git a/test/hisi_sec_test/test_hisi_sec.c b/uadk_tool/test/test_sec.c
|
||||
old mode 100755
|
||||
new mode 100644
|
||||
similarity index 98%
|
||||
rename from test/hisi_sec_test/test_hisi_sec.c
|
||||
rename to uadk_tool/test/test_sec.c
|
||||
index 7d5da7c..9fe007e
|
||||
--- a/test/hisi_sec_test/test_hisi_sec.c
|
||||
+++ b/uadk_tool/test/test_sec.c
|
||||
@@ -12,11 +12,12 @@
|
||||
#include <getopt.h>
|
||||
#include <numa.h>
|
||||
|
||||
-#include "test_hisi_sec.h"
|
||||
-#include "wd_cipher.h"
|
||||
-#include "wd_digest.h"
|
||||
-#include "wd_aead.h"
|
||||
-#include "wd_sched.h"
|
||||
+#include "sec_template_tv.h"
|
||||
+#include "test_sec.h"
|
||||
+#include "include/wd_cipher.h"
|
||||
+#include "include/wd_digest.h"
|
||||
+#include "include/wd_aead.h"
|
||||
+#include "include/wd_sched.h"
|
||||
|
||||
#define SEC_TST_PRT printf
|
||||
#define HW_CTX_SIZE (24 * 1024)
|
||||
@@ -26,6 +27,7 @@
|
||||
#define SVA_THREADS 64
|
||||
#define USE_CTX_NUM 64
|
||||
#define BYTES_TO_MB 20
|
||||
+#define SEC_ARGV_OFFSET 3
|
||||
|
||||
#define SCHED_SINGLE "sched_single"
|
||||
#define SCHED_NULL_CTX_SIZE 4
|
||||
@@ -4013,13 +4015,13 @@ out_thr:
|
||||
static void print_help(void)
|
||||
{
|
||||
SEC_TST_PRT("NAME\n");
|
||||
- SEC_TST_PRT(" test_hisi_sec: test wd sec function,etc\n");
|
||||
+ SEC_TST_PRT(" uadk_tool test --m sec: test wd sec function,etc\n");
|
||||
SEC_TST_PRT("USAGE\n");
|
||||
- SEC_TST_PRT(" test_hisi_sec [--cipher] [--digest] [--aead] [--perf]\n");
|
||||
- SEC_TST_PRT(" test_hisi_sec [--optype] [--pktlen] [--keylen] [--times]\n");
|
||||
- SEC_TST_PRT(" test_hisi_sec [--multi] [--sync] [--async] [--help]\n");
|
||||
- SEC_TST_PRT(" test_hisi_sec [--block] [--blknum] [--ctxnum]\n");
|
||||
- SEC_TST_PRT(" numactl --cpubind=0 --membind=0,1 ./test_hisi_sec xxxx\n");
|
||||
+ SEC_TST_PRT(" uadk_tool test --m sec [--cipher] [--digest] [--aead] [--perf]\n");
|
||||
+ SEC_TST_PRT(" uadk_tool test --m sec [--optype] [--pktlen] [--keylen] [--times]\n");
|
||||
+ SEC_TST_PRT(" uadk_tool test --m sec [--multi] [--sync] [--async] [--help]\n");
|
||||
+ SEC_TST_PRT(" uadk_tool test --m sec [--block] [--blknum] [--ctxnum]\n");
|
||||
+ SEC_TST_PRT(" numactl --cpubind=0 --membind=0,1 ./uadk_tool test --m sec xxxx\n");
|
||||
SEC_TST_PRT(" specify numa nodes for cpu and memory\n");
|
||||
SEC_TST_PRT("DESCRIPTION\n");
|
||||
SEC_TST_PRT(" [--cipher ]:\n");
|
||||
@@ -4060,17 +4062,19 @@ static void print_help(void)
|
||||
SEC_TST_PRT(" the number of QP queues used by the entire test task\n");
|
||||
SEC_TST_PRT(" [--stream]:\n");
|
||||
SEC_TST_PRT(" set the steam mode for digest\n");
|
||||
+ SEC_TST_PRT(" [--sglnum]:\n");
|
||||
+ SEC_TST_PRT(" the number of scatterlist number used by the entire test task\n");
|
||||
SEC_TST_PRT(" [--help] = usage\n");
|
||||
SEC_TST_PRT("Example\n");
|
||||
- SEC_TST_PRT(" ./test_hisi_sec --cipher 0 --sync --optype 0\n");
|
||||
+ SEC_TST_PRT(" ./uadk_tool test --m sec --cipher 0 --sync --optype 0\n");
|
||||
SEC_TST_PRT("--pktlen 16 --keylen 16 --times 1 --multi 1\n");
|
||||
- SEC_TST_PRT(" ./test_hisi_sec --digest 0 --sync --optype 0\n");
|
||||
+ SEC_TST_PRT(" ./uadk_tool test --m sec --digest 0 --sync --optype 0\n");
|
||||
SEC_TST_PRT("--pktlen 16 --keylen 16 --times 1 --multi 2 --stream\n");
|
||||
- SEC_TST_PRT(" ./test_hisi_sec --digest 1 --sync --optype 0\n");
|
||||
+ SEC_TST_PRT(" ./uadk_tool test --m sec --digest 1 --sync --optype 0\n");
|
||||
SEC_TST_PRT("--pktlen 16 --keylen 16 --times 1 --multi 2 --stream\n");
|
||||
- SEC_TST_PRT(" ./test_hisi_sec --perf --sync --pktlen 1024 --block 1024\n");
|
||||
+ SEC_TST_PRT(" ./uadk_tool test --m sec --perf --sync --pktlen 1024 --block 1024\n");
|
||||
SEC_TST_PRT("--blknum 100000 --times 10000 --multi 1 --ctxnum 1\n");
|
||||
- SEC_TST_PRT("UPDATE:2022-06-29\n");
|
||||
+ SEC_TST_PRT("UPDATE:2022-12-16\n");
|
||||
}
|
||||
|
||||
static void test_sec_cmd_parse(int argc, char *argv[], struct test_sec_option *option)
|
||||
@@ -4335,7 +4339,7 @@ static int test_sec_run(__u32 sync_mode, __u32 alg_class)
|
||||
return ret;
|
||||
}
|
||||
|
||||
-int main(int argc, char *argv[])
|
||||
+int test_sec_entry(int argc, char *argv[])
|
||||
{
|
||||
struct test_sec_option option = {0};
|
||||
int ret = 0;
|
||||
@@ -4343,14 +4347,14 @@ int main(int argc, char *argv[])
|
||||
SEC_TST_PRT("this is a hisi sec test.\n");
|
||||
|
||||
g_thread_num = 1;
|
||||
- if (!argv[1]) {
|
||||
+ if (!argv[1 + SEC_ARGV_OFFSET])
|
||||
return test_sec_default_case();
|
||||
- }
|
||||
|
||||
test_sec_cmd_parse(argc, argv, &option);
|
||||
ret = test_sec_option_convert(&option);
|
||||
if (ret)
|
||||
return ret;
|
||||
+
|
||||
if (option.algclass == PERF_CLASS)
|
||||
return sec_sva_test();
|
||||
|
||||
diff --git a/uadk_tool/test/test_sec.h b/uadk_tool/test/test_sec.h
|
||||
new file mode 100644
|
||||
index 0000000..abb55da
|
||||
--- /dev/null
|
||||
+++ b/uadk_tool/test/test_sec.h
|
||||
@@ -0,0 +1,10 @@
|
||||
+/* SPDX-License-Identifier: Apache-2.0 */
|
||||
+
|
||||
+#ifndef TEST_SEC_H
|
||||
+#define TEST_SEC_H
|
||||
+
|
||||
+
|
||||
+int test_sec_entry(int argc, char *argv[]);
|
||||
+
|
||||
+#endif /* TEST_SEC_H */
|
||||
+
|
||||
diff --git a/uadk_tool/test/uadk_test.c b/uadk_tool/test/uadk_test.c
|
||||
new file mode 100644
|
||||
index 0000000..760cef9
|
||||
--- /dev/null
|
||||
+++ b/uadk_tool/test/uadk_test.c
|
||||
@@ -0,0 +1,86 @@
|
||||
+/* SPDX-License-Identifier: Apache-2.0 */
|
||||
+
|
||||
+#include <stdbool.h>
|
||||
+#include <stdio.h>
|
||||
+#include <stdlib.h>
|
||||
+#include <string.h>
|
||||
+#include <time.h>
|
||||
+#include <getopt.h>
|
||||
+#include <unistd.h>
|
||||
+#include <limits.h>
|
||||
+#include <sys/ipc.h>
|
||||
+#include <sys/shm.h>
|
||||
+
|
||||
+#include "test_sec.h"
|
||||
+
|
||||
+enum uadk_test_op_type {
|
||||
+ DISPLAY_MODULE = 22,
|
||||
+ DISPLAY_HELP,
|
||||
+};
|
||||
+
|
||||
+int test_hpre_entry(int argc, char *argv[])
|
||||
+{
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+int test_zip_entry(int argc, char *argv[])
|
||||
+{
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+void print_test_help(void)
|
||||
+{
|
||||
+ printf("NAME\n");
|
||||
+ printf(" uadk_tool test : Test the correctness of the acc algorithm, etc\n");
|
||||
+ printf("USAGE\n");
|
||||
+ printf(" uadk_tool test [--m] = module name\n");
|
||||
+ printf(" hpre, sec, zip\n");
|
||||
+ printf(" uadk_tool test [--help] = usage\n");
|
||||
+ printf("Example\n");
|
||||
+ printf(" uadk_tool test --m hpre --xx\n");
|
||||
+ printf(" uadk_tool test --m sec --xx\n");
|
||||
+ printf(" uadk_tool test --m zip --xx\n");
|
||||
+}
|
||||
+
|
||||
+void acc_test_run(int argc, char *argv[])
|
||||
+{
|
||||
+ char *input_module = NULL;
|
||||
+ int option_index = 0;
|
||||
+ int opt;
|
||||
+
|
||||
+ static struct option long_options[] = {
|
||||
+ {"m", required_argument, 0, 22},
|
||||
+ {"help", no_argument, 0, 23},
|
||||
+ {0, 0, 0, 0}
|
||||
+ };
|
||||
+
|
||||
+ while (1) {
|
||||
+ opt = getopt_long(argc, argv, "", long_options, &option_index);
|
||||
+ if (opt == -1)
|
||||
+ break;
|
||||
+
|
||||
+ switch (opt) {
|
||||
+ case DISPLAY_MODULE:
|
||||
+ input_module = optarg;
|
||||
+ if (!strcmp(input_module, "hpre")) {
|
||||
+ (void)test_hpre_entry(argc, argv);
|
||||
+ } else if (!strcmp(input_module, "sec")) {
|
||||
+ (void)test_sec_entry(argc, argv);
|
||||
+ } else if (!strcmp(input_module, "zip")) {
|
||||
+ (void)test_zip_entry(argc, argv);
|
||||
+ } else {
|
||||
+ print_test_help();
|
||||
+ printf("failed to parse module parameter!\n");
|
||||
+ }
|
||||
+ break;
|
||||
+ case DISPLAY_HELP:
|
||||
+ print_test_help();
|
||||
+ break;
|
||||
+ default:
|
||||
+ printf("bad input parameter, exit!\n");
|
||||
+ print_test_help();
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
diff --git a/uadk_tool/test/uadk_test.h b/uadk_tool/test/uadk_test.h
|
||||
new file mode 100644
|
||||
index 0000000..3f876ac
|
||||
--- /dev/null
|
||||
+++ b/uadk_tool/test/uadk_test.h
|
||||
@@ -0,0 +1,8 @@
|
||||
+/* SPDX-License-Identifier: Apache-2.0 */
|
||||
+#ifndef UADK_TEST_H
|
||||
+#define UADK_TEST_H
|
||||
+
|
||||
+void print_test_help(void);
|
||||
+void acc_test_run(int argc, char *argv[]);
|
||||
+#endif
|
||||
+
|
||||
diff --git a/uadk_tool/uadk_tool.c b/uadk_tool/uadk_tool.c
|
||||
index ce83d7a..63e6d0f 100644
|
||||
--- a/uadk_tool/uadk_tool.c
|
||||
+++ b/uadk_tool/uadk_tool.c
|
||||
@@ -2,14 +2,16 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
-#include "dfx/uadk_dfx.h"
|
||||
#include "benchmark/uadk_benchmark.h"
|
||||
+#include "dfx/uadk_dfx.h"
|
||||
+#include "test/uadk_test.h"
|
||||
|
||||
static void print_tool_help(void)
|
||||
{
|
||||
printf("NAME\n");
|
||||
printf("uadk_tool dfx : Show some information for library.\n");
|
||||
printf("uadk_tool benchmark : Test UADK acc performance.\n");
|
||||
+ printf("uadk_tool test : Test the correctness of the acc algorithm.\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@@ -34,6 +36,9 @@ int main(int argc, char **argv)
|
||||
if (ret)
|
||||
return ret;
|
||||
(void)acc_benchmark_run(&option);
|
||||
+ } else if (!strcmp("test", argv[index])) {
|
||||
+ printf("start UADK acc algorithm test.\n");
|
||||
+ acc_test_run(argc, argv);
|
||||
} else {
|
||||
print_tool_help();
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
251
0019-uadk-cipher-add-the-init2-interface-for-cipher.patch
Normal file
251
0019-uadk-cipher-add-the-init2-interface-for-cipher.patch
Normal file
@ -0,0 +1,251 @@
|
||||
From b5cfe0cf4d7965c8cf10c496ec9c134796e13b25 Mon Sep 17 00:00:00 2001
|
||||
From: Longfang Liu <liulongfang@huawei.com>
|
||||
Date: Sat, 25 Feb 2023 17:35:34 +0800
|
||||
Subject: [PATCH 19/28] uadk/cipher: add the init2 interface for cipher
|
||||
|
||||
This set of interfaces puts resource initialization operations
|
||||
into the init2 interface, simplifying the initialization operations
|
||||
when users use the cipher algorithm.
|
||||
|
||||
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
|
||||
---
|
||||
include/wd_cipher.h | 29 +++++++++++
|
||||
libwd_crypto.map | 3 ++
|
||||
wd_cipher.c | 120 ++++++++++++++++++++++++++++++++++++--------
|
||||
3 files changed, 132 insertions(+), 20 deletions(-)
|
||||
|
||||
diff --git a/include/wd_cipher.h b/include/wd_cipher.h
|
||||
index 8e69852..3c41b6b 100644
|
||||
--- a/include/wd_cipher.h
|
||||
+++ b/include/wd_cipher.h
|
||||
@@ -105,6 +105,35 @@ struct wd_cipher_req {
|
||||
int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched);
|
||||
void wd_cipher_uninit(void);
|
||||
|
||||
+/**
|
||||
+ * wd_cipher_init2_() - A simplify interface to initializate uadk
|
||||
+ * encryption and decryption. This interface keeps most functions of
|
||||
+ * wd_cipher_init(). Users just need to descripe the deployment of
|
||||
+ * business scenarios. Then the initialization will request appropriate
|
||||
+ * resources to support the business scenarios.
|
||||
+ * To make the initializate simpler, ctx_params support set NULL.
|
||||
+ * And then the function will set them as driver's default.
|
||||
+ * Please do not use this interface with wd_cipher_init() together, or
|
||||
+ * some resources may be leak.
|
||||
+ *
|
||||
+ * @alg: The algorithm users want to use.
|
||||
+ * @sched_type: The scheduling type users want to use.
|
||||
+ * @task_type: Task types, including soft computing, hardware and hybrid computing.
|
||||
+ * @ctx_params: The ctxs resources users want to use. Include per operation
|
||||
+ * type ctx numbers and business process run numa.
|
||||
+ *
|
||||
+ * Return 0 if succeed and others if fail.
|
||||
+ */
|
||||
+int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params);
|
||||
+
|
||||
+#define wd_cipher_init2(alg, sched_type, task_type) \
|
||||
+ wd_cipher_init2(alg, sched_type, task_type, NULL)
|
||||
+
|
||||
+/**
|
||||
+ * wd_cipher_uninit2() - Uninitialise ctx configuration and scheduler.
|
||||
+ */
|
||||
+void wd_cipher_uninit2(void);
|
||||
+
|
||||
/**
|
||||
* wd_cipher_alloc_sess() Allocate a wd cipher session
|
||||
* @ setup Parameters to setup this session.
|
||||
diff --git a/libwd_crypto.map b/libwd_crypto.map
|
||||
index 5c46c44..a5dd688 100644
|
||||
--- a/libwd_crypto.map
|
||||
+++ b/libwd_crypto.map
|
||||
@@ -2,6 +2,9 @@ UADK_CRYPTO_2.0 {
|
||||
global:
|
||||
wd_cipher_init;
|
||||
wd_cipher_uninit;
|
||||
+ wd_cipher_init2;
|
||||
+ wd_cipher_init2_;
|
||||
+ wd_cipher_uninit2;
|
||||
wd_cipher_alloc_sess;
|
||||
wd_cipher_free_sess;
|
||||
wd_cipher_set_key;
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index 8af2e4b..af56876 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -67,6 +67,17 @@ struct wd_cipher_sess {
|
||||
};
|
||||
|
||||
struct wd_env_config wd_cipher_env_config;
|
||||
+static struct wd_init_attrs wd_cipher_init_attrs;
|
||||
+
|
||||
+static struct wd_ctx_nums wd_cipher_ctx_num[] = {
|
||||
+ {1, 1}, {}
|
||||
+};
|
||||
+
|
||||
+static struct wd_ctx_params wd_cipher_ctx_params = {
|
||||
+ .op_type_num = WD_CIPHER_DECRYPTION,
|
||||
+ .ctx_set_num = wd_cipher_ctx_num,
|
||||
+ .bmp = NULL,
|
||||
+};
|
||||
|
||||
#ifdef WD_STATIC_DRV
|
||||
static void wd_cipher_set_static_drv(void)
|
||||
@@ -233,30 +244,20 @@ static void wd_cipher_clear_status(void)
|
||||
wd_alg_clear_init(&wd_cipher_setting.status);
|
||||
}
|
||||
|
||||
-int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
+static int wd_cipher_common_init(struct wd_ctx_config *config,
|
||||
+ struct wd_sched *sched)
|
||||
{
|
||||
void *priv;
|
||||
- bool flag;
|
||||
int ret;
|
||||
|
||||
- pthread_atfork(NULL, NULL, wd_cipher_clear_status);
|
||||
-
|
||||
- flag = wd_alg_try_init(&wd_cipher_setting.status);
|
||||
- if (!flag)
|
||||
- return 0;
|
||||
-
|
||||
- ret = wd_init_param_check(config, sched);
|
||||
- if (ret)
|
||||
- goto out_clear_init;
|
||||
-
|
||||
ret = wd_set_epoll_en("WD_CIPHER_EPOLL_EN",
|
||||
&wd_cipher_setting.config.epoll_en);
|
||||
if (ret < 0)
|
||||
- goto out_clear_init;
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_ctx_config(&wd_cipher_setting.config, config);
|
||||
if (ret < 0)
|
||||
- goto out_clear_init;
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_sched(&wd_cipher_setting.sched, sched);
|
||||
if (ret < 0)
|
||||
@@ -284,12 +285,10 @@ int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
|
||||
ret = wd_cipher_setting.driver->init(&wd_cipher_setting.config, priv);
|
||||
if (ret < 0) {
|
||||
- WD_ERR("failed to do dirver init, ret = %d.\n", ret);
|
||||
+ WD_ERR("failed to init cipher dirver!\n");
|
||||
goto out_free_priv;
|
||||
}
|
||||
|
||||
- wd_alg_set_init(&wd_cipher_setting.status);
|
||||
-
|
||||
return 0;
|
||||
|
||||
out_free_priv:
|
||||
@@ -301,12 +300,10 @@ out_clear_sched:
|
||||
wd_clear_sched(&wd_cipher_setting.sched);
|
||||
out_clear_ctx_config:
|
||||
wd_clear_ctx_config(&wd_cipher_setting.config);
|
||||
-out_clear_init:
|
||||
- wd_alg_clear_init(&wd_cipher_setting.status);
|
||||
return ret;
|
||||
}
|
||||
|
||||
-void wd_cipher_uninit(void)
|
||||
+static void wd_cipher_common_uninit(void)
|
||||
{
|
||||
void *priv = wd_cipher_setting.priv;
|
||||
|
||||
@@ -317,9 +314,92 @@ void wd_cipher_uninit(void)
|
||||
wd_cipher_setting.priv = NULL;
|
||||
free(priv);
|
||||
|
||||
+ /* uninit async request pool */
|
||||
wd_uninit_async_request_pool(&wd_cipher_setting.pool);
|
||||
+
|
||||
+ /* unset config, sched, driver */
|
||||
wd_clear_sched(&wd_cipher_setting.sched);
|
||||
wd_clear_ctx_config(&wd_cipher_setting.config);
|
||||
+}
|
||||
+
|
||||
+int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
+{
|
||||
+ bool flag;
|
||||
+ int ret;
|
||||
+
|
||||
+ pthread_atfork(NULL, NULL, wd_cipher_clear_status);
|
||||
+
|
||||
+ flag = wd_alg_try_init(&wd_cipher_setting.status);
|
||||
+ if (!flag)
|
||||
+ return 0;
|
||||
+
|
||||
+ ret = wd_init_param_check(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ ret = wd_cipher_common_init(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ wd_alg_set_init(&wd_cipher_setting.status);
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+out_clear_init:
|
||||
+ wd_alg_clear_init(&wd_cipher_setting.status);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void wd_cipher_uninit(void)
|
||||
+{
|
||||
+ wd_cipher_common_uninit();
|
||||
+ wd_alg_clear_init(&wd_cipher_setting.status);
|
||||
+}
|
||||
+
|
||||
+int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params)
|
||||
+{
|
||||
+ bool flag;
|
||||
+ int ret;
|
||||
+
|
||||
+ pthread_atfork(NULL, NULL, wd_cipher_clear_status);
|
||||
+
|
||||
+ flag = wd_alg_try_init(&wd_cipher_setting.status);
|
||||
+ if (!flag)
|
||||
+ return 0;
|
||||
+
|
||||
+ 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;
|
||||
+ }
|
||||
+
|
||||
+ wd_cipher_init_attrs.alg = alg;
|
||||
+ wd_cipher_init_attrs.sched_type = sched_type;
|
||||
+ wd_cipher_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_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) {
|
||||
+ WD_ERR("fail to init alg attrs.\n");
|
||||
+ goto out_uninit;
|
||||
+ }
|
||||
+
|
||||
+ wd_alg_set_init(&wd_cipher_setting.status);
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+out_uninit:
|
||||
+ wd_alg_clear_init(&wd_cipher_setting.status);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void wd_cipher_uninit2(void)
|
||||
+{
|
||||
+ wd_cipher_common_uninit();
|
||||
+
|
||||
+ wd_alg_attrs_uninit(&wd_cipher_init_attrs);
|
||||
+
|
||||
wd_alg_clear_init(&wd_cipher_setting.status);
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
622
0020-uadk-sec-adapt-the-sec-module-to-the-dynamic-loading.patch
Normal file
622
0020-uadk-sec-adapt-the-sec-module-to-the-dynamic-loading.patch
Normal file
@ -0,0 +1,622 @@
|
||||
From f9a97f4fb2b6258431fa2af9934a114cde559b8a Mon Sep 17 00:00:00 2001
|
||||
From: Longfang Liu <liulongfang@huawei.com>
|
||||
Date: Sat, 25 Feb 2023 17:35:35 +0800
|
||||
Subject: [PATCH 20/28] uadk/sec: adapt the sec module to the dynamic loading
|
||||
framework
|
||||
|
||||
After adding the cipher module of the init2 interface, combine it
|
||||
Dynamically load the initialization part, transform HiSilicon
|
||||
sec driven, and implemented using the dynamic loading function
|
||||
Connection between driver and algorithm layer.
|
||||
|
||||
Signed-off-by: Longfang Liu <liulongfang@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 102 +++++++++++++++---
|
||||
include/drv/wd_aead_drv.h | 2 +-
|
||||
include/drv/wd_cipher_drv.h | 26 -----
|
||||
include/drv/wd_digest_drv.h | 2 +-
|
||||
wd_cipher.c | 210 ++++++++++++++++++++++++------------
|
||||
5 files changed, 229 insertions(+), 113 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index 6187346..0527bff 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -80,6 +80,8 @@
|
||||
#define WD_CIPHER_THEN_DIGEST 0x0
|
||||
#define WD_DIGEST_THEN_CIPHER 0x1
|
||||
|
||||
+#define SEC_CTX_Q_NUM_DEF 1
|
||||
+
|
||||
enum C_ALG {
|
||||
C_ALG_DES = 0x0,
|
||||
C_ALG_3DES = 0x1,
|
||||
@@ -515,9 +517,54 @@ 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(struct wd_ctx_config_internal *config, void *priv);
|
||||
+int hisi_sec_init(void *conf, void *priv);
|
||||
void hisi_sec_exit(void *priv);
|
||||
|
||||
+static int hisi_sec_get_usage(void *param)
|
||||
+{
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+#define GEN_SEC_ALG_DRIVER(sec_alg_name) \
|
||||
+{\
|
||||
+ .drv_name = "hisi_sec2_cipher",\
|
||||
+ .alg_name = sec_alg_name,\
|
||||
+ .priority = UADK_ALG_HW,\
|
||||
+ .priv_size = sizeof(struct hisi_sec_ctx),\
|
||||
+ .queue_num = SEC_CTX_Q_NUM_DEF,\
|
||||
+ .op_type_num = 1,\
|
||||
+ .fallback = 0,\
|
||||
+ .init = hisi_sec_init,\
|
||||
+ .exit = hisi_sec_exit,\
|
||||
+ .get_usage = hisi_sec_get_usage,\
|
||||
+}
|
||||
+
|
||||
+static struct wd_alg_driver cipher_alg_driver[] = {
|
||||
+ GEN_SEC_ALG_DRIVER("ecb(aes)"),
|
||||
+ GEN_SEC_ALG_DRIVER("cbc(aes)"),
|
||||
+ GEN_SEC_ALG_DRIVER("xts(aes)"),
|
||||
+ GEN_SEC_ALG_DRIVER("ecb(sm4)"),
|
||||
+ GEN_SEC_ALG_DRIVER("cbc(sm4)"),
|
||||
+ GEN_SEC_ALG_DRIVER("ctr(sm4)"),
|
||||
+ GEN_SEC_ALG_DRIVER("xts(sm4)"),
|
||||
+ GEN_SEC_ALG_DRIVER("ecb(des)"),
|
||||
+ GEN_SEC_ALG_DRIVER("cbc(des)"),
|
||||
+ GEN_SEC_ALG_DRIVER("ecb(des3_ede)"),
|
||||
+ GEN_SEC_ALG_DRIVER("cbc(des3_ede)"),
|
||||
+
|
||||
+ GEN_SEC_ALG_DRIVER("ctr(aes)"),
|
||||
+ GEN_SEC_ALG_DRIVER("ofb(aes)"),
|
||||
+ GEN_SEC_ALG_DRIVER("cfb(aes)"),
|
||||
+ GEN_SEC_ALG_DRIVER("cbc-cs1(aes)"),
|
||||
+ GEN_SEC_ALG_DRIVER("cbc-cs2(aes)"),
|
||||
+ GEN_SEC_ALG_DRIVER("cbc-cs3(aes)"),
|
||||
+ GEN_SEC_ALG_DRIVER("ofb(sm4)"),
|
||||
+ GEN_SEC_ALG_DRIVER("cfb(sm4)"),
|
||||
+ GEN_SEC_ALG_DRIVER("cbc-cs1(sm4)"),
|
||||
+ GEN_SEC_ALG_DRIVER("cbc-cs2(sm4)"),
|
||||
+ GEN_SEC_ALG_DRIVER("cbc-cs3(sm4)"),
|
||||
+};
|
||||
+
|
||||
static void dump_sec_msg(void *msg, const char *alg)
|
||||
{
|
||||
struct wd_cipher_msg *cmsg;
|
||||
@@ -1071,16 +1118,6 @@ int hisi_sec_cipher_recv(handle_t ctx, void *cipher_msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static struct wd_cipher_driver hisi_cipher_driver = {
|
||||
- .drv_name = "hisi_sec2",
|
||||
- .alg_name = "cipher",
|
||||
- .drv_ctx_size = sizeof(struct hisi_sec_ctx),
|
||||
- .init = hisi_sec_init,
|
||||
- .exit = hisi_sec_exit,
|
||||
-};
|
||||
-
|
||||
-WD_CIPHER_SET_DRIVER(hisi_cipher_driver);
|
||||
-
|
||||
static int fill_cipher_bd3_alg(struct wd_cipher_msg *msg,
|
||||
struct hisi_sec_sqe3 *sqe)
|
||||
{
|
||||
@@ -2578,11 +2615,15 @@ int hisi_sec_aead_recv_v3(handle_t ctx, void *aead_msg)
|
||||
static void hisi_sec_driver_adapter(struct hisi_qp *qp)
|
||||
{
|
||||
struct hisi_qm_queue_info q_info = qp->q_info;
|
||||
+ int alg_num, i;
|
||||
|
||||
if (q_info.hw_type == HISI_QM_API_VER2_BASE) {
|
||||
WD_INFO("hisi sec init HIP08!\n");
|
||||
- hisi_cipher_driver.cipher_send = hisi_sec_cipher_send;
|
||||
- hisi_cipher_driver.cipher_recv = hisi_sec_cipher_recv;
|
||||
+ alg_num = ARRAY_SIZE(cipher_alg_driver);
|
||||
+ for (i = 0; i < alg_num; i++) {
|
||||
+ cipher_alg_driver[i].send = hisi_sec_cipher_send;
|
||||
+ cipher_alg_driver[i].recv = hisi_sec_cipher_recv;
|
||||
+ }
|
||||
|
||||
hisi_digest_driver.digest_send = hisi_sec_digest_send;
|
||||
hisi_digest_driver.digest_recv = hisi_sec_digest_recv;
|
||||
@@ -2591,8 +2632,11 @@ static void hisi_sec_driver_adapter(struct hisi_qp *qp)
|
||||
hisi_aead_driver.aead_recv = hisi_sec_aead_recv;
|
||||
} else {
|
||||
WD_INFO("hisi sec init HIP09!\n");
|
||||
- hisi_cipher_driver.cipher_send = hisi_sec_cipher_send_v3;
|
||||
- hisi_cipher_driver.cipher_recv = hisi_sec_cipher_recv_v3;
|
||||
+ alg_num = ARRAY_SIZE(cipher_alg_driver);
|
||||
+ for (i = 0; i < alg_num; i++) {
|
||||
+ cipher_alg_driver[i].send = hisi_sec_cipher_send_v3;
|
||||
+ cipher_alg_driver[i].recv = hisi_sec_cipher_recv_v3;
|
||||
+ }
|
||||
|
||||
hisi_digest_driver.digest_send = hisi_sec_digest_send_v3;
|
||||
hisi_digest_driver.digest_recv = hisi_sec_digest_recv_v3;
|
||||
@@ -2602,8 +2646,9 @@ static void hisi_sec_driver_adapter(struct hisi_qp *qp)
|
||||
}
|
||||
}
|
||||
|
||||
-int hisi_sec_init(struct wd_ctx_config_internal *config, void *priv)
|
||||
+int hisi_sec_init(void *conf, void *priv)
|
||||
{
|
||||
+ struct wd_ctx_config_internal *config = conf;
|
||||
struct hisi_sec_ctx *sec_ctx = priv;
|
||||
struct hisi_qm_priv qm_priv;
|
||||
handle_t h_qp = 0;
|
||||
@@ -2661,3 +2706,28 @@ void hisi_sec_exit(void *priv)
|
||||
hisi_qm_free_qp(h_qp);
|
||||
}
|
||||
}
|
||||
+
|
||||
+static void __attribute__((constructor)) hisi_sec2_probe(void)
|
||||
+{
|
||||
+ int alg_num = ARRAY_SIZE(cipher_alg_driver);
|
||||
+ int i, ret;
|
||||
+
|
||||
+ WD_INFO("Info: register SEC alg drivers!\n");
|
||||
+
|
||||
+ for (i = 0; i < alg_num; i++) {
|
||||
+ ret = wd_alg_driver_register(&cipher_alg_driver[i]);
|
||||
+ if (ret)
|
||||
+ WD_ERR("Error: register SEC %s failed!\n",
|
||||
+ cipher_alg_driver[i].alg_name);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static void __attribute__((destructor)) hisi_sec2_remove(void)
|
||||
+{
|
||||
+ int alg_num = ARRAY_SIZE(cipher_alg_driver);
|
||||
+ int i;
|
||||
+
|
||||
+ for (i = 0; i < alg_num; i++)
|
||||
+ wd_alg_driver_unregister(&cipher_alg_driver[i]);
|
||||
+}
|
||||
+
|
||||
diff --git a/include/drv/wd_aead_drv.h b/include/drv/wd_aead_drv.h
|
||||
index 7c657f6..8446238 100644
|
||||
--- a/include/drv/wd_aead_drv.h
|
||||
+++ b/include/drv/wd_aead_drv.h
|
||||
@@ -67,7 +67,7 @@ struct wd_aead_driver {
|
||||
const char *drv_name;
|
||||
const char *alg_name;
|
||||
__u32 drv_ctx_size;
|
||||
- int (*init)(struct wd_ctx_config_internal *config, void *priv);
|
||||
+ int (*init)(void *conf, void *priv);
|
||||
void (*exit)(void *priv);
|
||||
int (*aead_send)(handle_t ctx, void *aead_msg);
|
||||
int (*aead_recv)(handle_t ctx, void *aead_msg);
|
||||
diff --git a/include/drv/wd_cipher_drv.h b/include/drv/wd_cipher_drv.h
|
||||
index 82fb89a..c6d8ddf 100644
|
||||
--- a/include/drv/wd_cipher_drv.h
|
||||
+++ b/include/drv/wd_cipher_drv.h
|
||||
@@ -50,34 +50,8 @@ struct wd_cipher_msg {
|
||||
__u8 *out;
|
||||
};
|
||||
|
||||
-struct wd_cipher_driver {
|
||||
- const char *drv_name;
|
||||
- const char *alg_name;
|
||||
- __u32 drv_ctx_size;
|
||||
- int (*init)(struct wd_ctx_config_internal *config, void *priv);
|
||||
- void (*exit)(void *priv);
|
||||
- int (*cipher_send)(handle_t ctx, void *cipher_msg);
|
||||
- int (*cipher_recv)(handle_t ctx, void *cipher_msg);
|
||||
-};
|
||||
-
|
||||
-void wd_cipher_set_driver(struct wd_cipher_driver *drv);
|
||||
-struct wd_cipher_driver *wd_cipher_get_driver(void);
|
||||
struct wd_cipher_msg *wd_cipher_get_msg(__u32 idx, __u32 tag);
|
||||
|
||||
-#ifdef WD_STATIC_DRV
|
||||
-#define WD_CIPHER_SET_DRIVER(drv) \
|
||||
-struct wd_cipher_driver *wd_cipher_get_driver(void) \
|
||||
-{ \
|
||||
- return &drv; \
|
||||
-}
|
||||
-#else
|
||||
-#define WD_CIPHER_SET_DRIVER(drv) \
|
||||
-static void __attribute__((constructor)) set_cipher_driver(void) \
|
||||
-{ \
|
||||
- wd_cipher_set_driver(&(drv)); \
|
||||
-}
|
||||
-#endif
|
||||
-
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
diff --git a/include/drv/wd_digest_drv.h b/include/drv/wd_digest_drv.h
|
||||
index 586588b..96b32e2 100644
|
||||
--- a/include/drv/wd_digest_drv.h
|
||||
+++ b/include/drv/wd_digest_drv.h
|
||||
@@ -55,7 +55,7 @@ struct wd_digest_driver {
|
||||
const char *drv_name;
|
||||
const char *alg_name;
|
||||
__u32 drv_ctx_size;
|
||||
- int (*init)(struct wd_ctx_config_internal *config, void *priv);
|
||||
+ int (*init)(void *conf, void *priv);
|
||||
void (*exit)(void *priv);
|
||||
int (*digest_send)(handle_t ctx, void *digest_msg);
|
||||
int (*digest_recv)(handle_t ctx, void *digest_msg);
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index af56876..eca9711 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -43,15 +43,24 @@ static const unsigned char des_weak_keys[DES_WEAK_KEY_NUM][DES_KEY_SIZE] = {
|
||||
{0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1}
|
||||
};
|
||||
|
||||
+static char *wd_cipher_alg_name[WD_CIPHER_ALG_TYPE_MAX][WD_CIPHER_MODE_TYPE_MAX] = {
|
||||
+ {"ecb(sm4)", "cbc(sm4)", "ctr(sm4)", "xts(sm4)", "ofb(sm4)",
|
||||
+ "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)",}
|
||||
+};
|
||||
+
|
||||
struct wd_cipher_setting {
|
||||
enum wd_status status;
|
||||
struct wd_ctx_config_internal config;
|
||||
struct wd_sched sched;
|
||||
- void *sched_ctx;
|
||||
- struct wd_cipher_driver *driver;
|
||||
+ struct wd_async_msg_pool pool;
|
||||
+ struct wd_alg_driver *driver;
|
||||
void *priv;
|
||||
void *dlhandle;
|
||||
- struct wd_async_msg_pool pool;
|
||||
+ void *dlh_list;
|
||||
} wd_cipher_setting;
|
||||
|
||||
struct wd_cipher_sess {
|
||||
@@ -69,41 +78,49 @@ struct wd_cipher_sess {
|
||||
struct wd_env_config wd_cipher_env_config;
|
||||
static struct wd_init_attrs wd_cipher_init_attrs;
|
||||
|
||||
-static struct wd_ctx_nums wd_cipher_ctx_num[] = {
|
||||
- {1, 1}, {}
|
||||
-};
|
||||
-
|
||||
-static struct wd_ctx_params wd_cipher_ctx_params = {
|
||||
- .op_type_num = WD_CIPHER_DECRYPTION,
|
||||
- .ctx_set_num = wd_cipher_ctx_num,
|
||||
- .bmp = NULL,
|
||||
-};
|
||||
-
|
||||
-#ifdef WD_STATIC_DRV
|
||||
-static void wd_cipher_set_static_drv(void)
|
||||
+static void wd_cipher_close_driver(void)
|
||||
{
|
||||
- wd_cipher_setting.driver = wd_cipher_get_driver();
|
||||
- if (!wd_cipher_setting.driver)
|
||||
- WD_ERR("failed to get driver!\n");
|
||||
+ if (wd_cipher_setting.dlhandle) {
|
||||
+ wd_release_drv(wd_cipher_setting.driver);
|
||||
+ dlclose(wd_cipher_setting.dlhandle);
|
||||
+ wd_cipher_setting.dlhandle = NULL;
|
||||
+ }
|
||||
}
|
||||
-#else
|
||||
-static void __attribute__((constructor)) wd_cipher_open_driver(void)
|
||||
+
|
||||
+static int wd_cipher_open_driver(void)
|
||||
{
|
||||
- wd_cipher_setting.dlhandle = dlopen("libhisi_sec.so", RTLD_NOW);
|
||||
- if (!wd_cipher_setting.dlhandle)
|
||||
+ struct wd_alg_driver *driver = NULL;
|
||||
+ const char *alg_name = "cbc(aes)";
|
||||
+ char lib_path[PATH_STR_SIZE];
|
||||
+ 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;
|
||||
+
|
||||
+ wd_cipher_setting.dlhandle = dlopen(lib_path, RTLD_NOW);
|
||||
+ if (!wd_cipher_setting.dlhandle) {
|
||||
WD_ERR("failed to open libhisi_sec.so, %s\n", dlerror());
|
||||
-}
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
|
||||
-static void __attribute__((destructor)) wd_cipher_close_driver(void)
|
||||
-{
|
||||
- if (wd_cipher_setting.dlhandle)
|
||||
- dlclose(wd_cipher_setting.dlhandle);
|
||||
-}
|
||||
-#endif
|
||||
+ driver = wd_request_drv(alg_name, false);
|
||||
+ if (!driver) {
|
||||
+ wd_cipher_close_driver();
|
||||
+ WD_ERR("failed to get %s driver support\n", alg_name);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
|
||||
-void wd_cipher_set_driver(struct wd_cipher_driver *drv)
|
||||
-{
|
||||
- wd_cipher_setting.driver = drv;
|
||||
+ wd_cipher_setting.driver = driver;
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static bool is_des_weak_key(const __u8 *key)
|
||||
@@ -196,6 +213,7 @@ int wd_cipher_set_key(handle_t h_sess, const __u8 *key, __u32 key_len)
|
||||
handle_t wd_cipher_alloc_sess(struct wd_cipher_sess_setup *setup)
|
||||
{
|
||||
struct wd_cipher_sess *sess = NULL;
|
||||
+ bool ret;
|
||||
|
||||
if (unlikely(!setup)) {
|
||||
WD_ERR("invalid: cipher input setup is NULL!\n");
|
||||
@@ -209,18 +227,35 @@ handle_t wd_cipher_alloc_sess(struct wd_cipher_sess_setup *setup)
|
||||
}
|
||||
memset(sess, 0, sizeof(struct wd_cipher_sess));
|
||||
|
||||
+ 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;
|
||||
+ }
|
||||
+ sess->alg_name = wd_cipher_alg_name[setup->alg][setup->mode];
|
||||
sess->alg = setup->alg;
|
||||
sess->mode = setup->mode;
|
||||
+ ret = wd_drv_alg_support(sess->alg_name, wd_cipher_setting.driver);
|
||||
+ if (!ret) {
|
||||
+ WD_ERR("failed to support this algorithm: %s!\n", sess->alg_name);
|
||||
+ goto err_sess;
|
||||
+ }
|
||||
+
|
||||
/* Some simple scheduler don't need scheduling parameters */
|
||||
sess->sched_key = (void *)wd_cipher_setting.sched.sched_init(
|
||||
wd_cipher_setting.sched.h_sched_ctx, setup->sched_param);
|
||||
if (WD_IS_ERR(sess->sched_key)) {
|
||||
WD_ERR("failed to init session schedule key!\n");
|
||||
- free(sess);
|
||||
- return (handle_t)0;
|
||||
+ goto err_sess;
|
||||
}
|
||||
|
||||
return (handle_t)sess;
|
||||
+
|
||||
+err_sess:
|
||||
+ if (sess->sched_key)
|
||||
+ free(sess->sched_key);
|
||||
+ free(sess);
|
||||
+ return (handle_t)0;
|
||||
}
|
||||
|
||||
void wd_cipher_free_sess(handle_t h_sess)
|
||||
@@ -247,7 +282,6 @@ static void wd_cipher_clear_status(void)
|
||||
static int wd_cipher_common_init(struct wd_ctx_config *config,
|
||||
struct wd_sched *sched)
|
||||
{
|
||||
- void *priv;
|
||||
int ret;
|
||||
|
||||
ret = wd_set_epoll_en("WD_CIPHER_EPOLL_EN",
|
||||
@@ -263,11 +297,6 @@ static int wd_cipher_common_init(struct wd_ctx_config *config,
|
||||
if (ret < 0)
|
||||
goto out_clear_ctx_config;
|
||||
|
||||
-#ifdef WD_STATIC_DRV
|
||||
- /* set driver */
|
||||
- wd_cipher_set_static_drv();
|
||||
-#endif
|
||||
-
|
||||
/* allocate async pool for every ctx */
|
||||
ret = wd_init_async_request_pool(&wd_cipher_setting.pool,
|
||||
config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
@@ -275,25 +304,14 @@ static int wd_cipher_common_init(struct wd_ctx_config *config,
|
||||
if (ret < 0)
|
||||
goto out_clear_sched;
|
||||
|
||||
- /* init ctx related resources in specific driver */
|
||||
- priv = calloc(1, wd_cipher_setting.driver->drv_ctx_size);
|
||||
- if (!priv) {
|
||||
- ret = -WD_ENOMEM;
|
||||
+ ret = wd_alg_init_driver(&wd_cipher_setting.config,
|
||||
+ wd_cipher_setting.driver,
|
||||
+ &wd_cipher_setting.priv);
|
||||
+ if (ret)
|
||||
goto out_clear_pool;
|
||||
- }
|
||||
- wd_cipher_setting.priv = priv;
|
||||
-
|
||||
- ret = wd_cipher_setting.driver->init(&wd_cipher_setting.config, priv);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to init cipher dirver!\n");
|
||||
- goto out_free_priv;
|
||||
- }
|
||||
|
||||
return 0;
|
||||
|
||||
-out_free_priv:
|
||||
- free(priv);
|
||||
- wd_cipher_setting.priv = NULL;
|
||||
out_clear_pool:
|
||||
wd_uninit_async_request_pool(&wd_cipher_setting.pool);
|
||||
out_clear_sched:
|
||||
@@ -310,16 +328,14 @@ static void wd_cipher_common_uninit(void)
|
||||
if (!priv)
|
||||
return;
|
||||
|
||||
- wd_cipher_setting.driver->exit(priv);
|
||||
- wd_cipher_setting.priv = NULL;
|
||||
- free(priv);
|
||||
-
|
||||
/* uninit async request pool */
|
||||
wd_uninit_async_request_pool(&wd_cipher_setting.pool);
|
||||
|
||||
/* unset config, sched, driver */
|
||||
wd_clear_sched(&wd_cipher_setting.sched);
|
||||
- wd_clear_ctx_config(&wd_cipher_setting.config);
|
||||
+
|
||||
+ wd_alg_uninit_driver(&wd_cipher_setting.config,
|
||||
+ wd_cipher_setting.driver, &priv);
|
||||
}
|
||||
|
||||
int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
@@ -337,14 +353,20 @@ int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
if (ret)
|
||||
goto out_clear_init;
|
||||
|
||||
- ret = wd_cipher_common_init(config, sched);
|
||||
+ ret = wd_cipher_open_driver();
|
||||
if (ret)
|
||||
goto out_clear_init;
|
||||
|
||||
+ ret = wd_cipher_common_init(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_close_driver;
|
||||
+
|
||||
wd_alg_set_init(&wd_cipher_setting.status);
|
||||
|
||||
return 0;
|
||||
|
||||
+out_close_driver:
|
||||
+ wd_cipher_close_driver();
|
||||
out_clear_init:
|
||||
wd_alg_clear_init(&wd_cipher_setting.status);
|
||||
return ret;
|
||||
@@ -353,13 +375,17 @@ out_clear_init:
|
||||
void wd_cipher_uninit(void)
|
||||
{
|
||||
wd_cipher_common_uninit();
|
||||
+
|
||||
+ wd_cipher_close_driver();
|
||||
wd_alg_clear_init(&wd_cipher_setting.status);
|
||||
}
|
||||
|
||||
int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params)
|
||||
{
|
||||
+ struct wd_ctx_nums cipher_ctx_num[WD_CIPHER_DECRYPTION + 1] = {0};
|
||||
+ struct wd_ctx_params cipher_ctx_params = {0};
|
||||
+ int ret = 0;
|
||||
bool flag;
|
||||
- int ret;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_cipher_clear_status);
|
||||
|
||||
@@ -374,21 +400,65 @@ 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.
|
||||
+ * than 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");
|
||||
+ goto out_uninit;
|
||||
+ }
|
||||
+
|
||||
+res_retry:
|
||||
+ 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;
|
||||
+ }
|
||||
+
|
||||
+ ret = wd_ctx_param_init(&cipher_ctx_params, ctx_params,
|
||||
+ cipher_ctx_num, wd_cipher_setting.driver,
|
||||
+ 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;
|
||||
+ }
|
||||
+ goto out_driver;
|
||||
+ }
|
||||
+
|
||||
wd_cipher_init_attrs.alg = alg;
|
||||
wd_cipher_init_attrs.sched_type = sched_type;
|
||||
- wd_cipher_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_cipher_ctx_params;
|
||||
+ 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);
|
||||
+ goto res_retry;
|
||||
+ }
|
||||
WD_ERR("fail to init alg attrs.\n");
|
||||
- goto out_uninit;
|
||||
+ goto out_driver;
|
||||
}
|
||||
|
||||
wd_alg_set_init(&wd_cipher_setting.status);
|
||||
|
||||
return 0;
|
||||
|
||||
+out_driver:
|
||||
+ wd_alg_drv_unbind(wd_cipher_setting.driver);
|
||||
+out_dlopen:
|
||||
+ wd_dlclose_drv(wd_cipher_setting.dlh_list);
|
||||
out_uninit:
|
||||
wd_alg_clear_init(&wd_cipher_setting.status);
|
||||
return ret;
|
||||
@@ -399,7 +469,9 @@ void wd_cipher_uninit2(void)
|
||||
wd_cipher_common_uninit();
|
||||
|
||||
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_setting.dlh_list = NULL;
|
||||
wd_alg_clear_init(&wd_cipher_setting.status);
|
||||
}
|
||||
|
||||
@@ -506,8 +578,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx,
|
||||
struct wd_msg_handle msg_handle;
|
||||
int ret;
|
||||
|
||||
- msg_handle.send = wd_cipher_setting.driver->cipher_send;
|
||||
- msg_handle.recv = wd_cipher_setting.driver->cipher_recv;
|
||||
+ msg_handle.send = wd_cipher_setting.driver->send;
|
||||
+ msg_handle.recv = wd_cipher_setting.driver->recv;
|
||||
|
||||
pthread_spin_lock(&ctx->lock);
|
||||
ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL,
|
||||
@@ -586,7 +658,7 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req)
|
||||
fill_request_msg(msg, req, sess);
|
||||
msg->tag = msg_id;
|
||||
|
||||
- ret = wd_cipher_setting.driver->cipher_send(ctx->ctx, msg);
|
||||
+ ret = wd_cipher_setting.driver->send(ctx->ctx, msg);
|
||||
if (unlikely(ret < 0)) {
|
||||
if (ret != -WD_EBUSY)
|
||||
WD_ERR("wd cipher async send err!\n");
|
||||
@@ -634,7 +706,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
||||
ctx = config->ctxs + idx;
|
||||
|
||||
do {
|
||||
- ret = wd_cipher_setting.driver->cipher_recv(ctx->ctx, &resp_msg);
|
||||
+ ret = wd_cipher_setting.driver->recv(ctx->ctx, &resp_msg);
|
||||
if (ret == -WD_EAGAIN)
|
||||
return ret;
|
||||
else if (ret < 0) {
|
||||
--
|
||||
2.25.1
|
||||
|
||||
31
0021-uadk-fix-dlsym-problem.patch
Normal file
31
0021-uadk-fix-dlsym-problem.patch
Normal file
@ -0,0 +1,31 @@
|
||||
From 2cd8bdd0e8c96463394fd402f52526fa0d1e1200 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 28 Mar 2023 20:09:16 +0800
|
||||
Subject: [PATCH 21/28] uadk: fix dlsym problem
|
||||
|
||||
If the -lwd link is not added, dlsym fails to search for
|
||||
wd_alg_driver_register symbol, so add link and dependence.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
Makefile.am | 3 ++-
|
||||
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/Makefile.am b/Makefile.am
|
||||
index bd7b36f..a4bb470 100644
|
||||
--- a/Makefile.am
|
||||
+++ b/Makefile.am
|
||||
@@ -118,8 +118,9 @@ libwd_crypto_la_LIBADD= -lwd -ldl -lnuma
|
||||
libwd_crypto_la_LDFLAGS=$(UADK_VERSION) $(UADK_CRYPTO_SYMBOL)
|
||||
libwd_crypto_la_DEPENDENCIES= libwd.la
|
||||
|
||||
-libhisi_zip_la_LIBADD= -ldl
|
||||
+libhisi_zip_la_LIBADD= -lwd -ldl
|
||||
libhisi_zip_la_LDFLAGS=$(UADK_VERSION)
|
||||
+libhisi_zip_la_DEPENDENCIES= libwd.la
|
||||
|
||||
libhisi_sec_la_LIBADD= -lwd -lwd_crypto
|
||||
libhisi_sec_la_LDFLAGS=$(UADK_VERSION)
|
||||
--
|
||||
2.25.1
|
||||
|
||||
28
0022-uadk-drv-fix-drv_name-for-sec2.patch
Normal file
28
0022-uadk-drv-fix-drv_name-for-sec2.patch
Normal file
@ -0,0 +1,28 @@
|
||||
From af61e4be412cb90b3d06d4fc7c716723c61eabe3 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 28 Mar 2023 20:11:12 +0800
|
||||
Subject: [PATCH 22/28] uadk/drv: fix drv_name for sec2
|
||||
|
||||
The driver name must match the actual driver name of the kernel.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
drv/hisi_sec.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index 0527bff..a84cc7a 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -527,7 +527,7 @@ static int hisi_sec_get_usage(void *param)
|
||||
|
||||
#define GEN_SEC_ALG_DRIVER(sec_alg_name) \
|
||||
{\
|
||||
- .drv_name = "hisi_sec2_cipher",\
|
||||
+ .drv_name = "hisi_sec2",\
|
||||
.alg_name = sec_alg_name,\
|
||||
.priority = UADK_ALG_HW,\
|
||||
.priv_size = sizeof(struct hisi_sec_ctx),\
|
||||
--
|
||||
2.25.1
|
||||
|
||||
241
0023-uadk-digest-introduce-the-init2-interface-for-digest.patch
Normal file
241
0023-uadk-digest-introduce-the-init2-interface-for-digest.patch
Normal file
@ -0,0 +1,241 @@
|
||||
From bbea0513ea1238de2e97e532b45b452208d03203 Mon Sep 17 00:00:00 2001
|
||||
From: Hao Fang <fanghao11@huawei.com>
|
||||
Date: Wed, 26 Apr 2023 11:55:25 +0800
|
||||
Subject: [PATCH 23/28] uadk/digest: introduce the init2 interface for digest
|
||||
|
||||
The basic init process is complex for users who need
|
||||
to know the device, scheduler, etc.
|
||||
|
||||
So introduce the init2 interface just for simplifying the
|
||||
initialization process when user use the digest algorithm.
|
||||
|
||||
Signed-off-by: Hao Fang <fanghao11@huawei.com>
|
||||
---
|
||||
include/wd_digest.h | 28 +++++++++++
|
||||
libwd_crypto.map | 3 ++
|
||||
wd_digest.c | 113 +++++++++++++++++++++++++++++++++++++-------
|
||||
3 files changed, 127 insertions(+), 17 deletions(-)
|
||||
|
||||
diff --git a/include/wd_digest.h b/include/wd_digest.h
|
||||
index a44328e..874e9c1 100644
|
||||
--- a/include/wd_digest.h
|
||||
+++ b/include/wd_digest.h
|
||||
@@ -142,6 +142,34 @@ struct wd_digest_tag {
|
||||
|
||||
int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched);
|
||||
void wd_digest_uninit(void);
|
||||
+/**
|
||||
+ * wd_digest_init2_() - A simplify interface to initializate uadk
|
||||
+ * digest operation. This interface keeps most functions of
|
||||
+ * wd_digest_init(). Users just need to descripe the deployment of
|
||||
+ * business scenarios. Then the initialization will request appropriate
|
||||
+ * resources to support the business scenarios.
|
||||
+ * To make the initializate simpler, ctx_params support set NULL.
|
||||
+ * And then the function will set them as driver's default.
|
||||
+ * Please do not use this interface with wd_digest_init() together, or
|
||||
+ * some resources may be leak.
|
||||
+ *
|
||||
+ * @alg: The algorithm users want to use.
|
||||
+ * @sched_type: The scheduling type users want to use.
|
||||
+ * @task_type: Task types, including soft computing, hardware and hybrid computing.
|
||||
+ * @ctx_params: The ctxs resources users want to use. Include per operation
|
||||
+ * type ctx numbers and business process run numa.
|
||||
+ *
|
||||
+ * Return 0 if succeed and others if fail.
|
||||
+ */
|
||||
+int wd_digest_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params);
|
||||
+
|
||||
+#define wd_digest_init2(alg, sched_type, task_type) \
|
||||
+ wd_digest_init2_(alg, sched_type, task_type, NULL)
|
||||
+
|
||||
+/**
|
||||
+ * wd_digest_uninit2() - Uninitialise ctx configuration and scheduler.
|
||||
+ */
|
||||
+void wd_digest_uninit2(void);
|
||||
|
||||
/**
|
||||
* wd_digest_alloc_sess() - Create a digest session.
|
||||
diff --git a/libwd_crypto.map b/libwd_crypto.map
|
||||
index a5dd688..e28dd79 100644
|
||||
--- a/libwd_crypto.map
|
||||
+++ b/libwd_crypto.map
|
||||
@@ -45,6 +45,9 @@ global:
|
||||
|
||||
wd_digest_init;
|
||||
wd_digest_uninit;
|
||||
+ wd_digest_init2;
|
||||
+ wd_digest_init2_;
|
||||
+ wd_digest_uninit2;
|
||||
wd_digest_alloc_sess;
|
||||
wd_digest_free_sess;
|
||||
wd_do_digest_sync;
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index 8c01709..03d3ace 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -66,6 +66,17 @@ struct wd_digest_sess {
|
||||
};
|
||||
|
||||
struct wd_env_config wd_digest_env_config;
|
||||
+static struct wd_init_attrs wd_digest_init_attrs;
|
||||
+
|
||||
+static struct wd_ctx_nums wd_digest_ctx_num[] = {
|
||||
+ {1, 1}, {}
|
||||
+};
|
||||
+
|
||||
+static struct wd_ctx_params wd_digest_ctx_params = {
|
||||
+ .op_type_num = 1,
|
||||
+ .ctx_set_num = wd_digest_ctx_num,
|
||||
+ .bmp = NULL,
|
||||
+};
|
||||
|
||||
#ifdef WD_STATIC_DRV
|
||||
static void wd_digest_set_static_drv(void)
|
||||
@@ -188,30 +199,20 @@ static void wd_digest_clear_status(void)
|
||||
wd_alg_clear_init(&wd_digest_setting.status);
|
||||
}
|
||||
|
||||
-int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
+static int wd_digest_init_nolock(struct wd_ctx_config *config,
|
||||
+ struct wd_sched *sched)
|
||||
{
|
||||
void *priv;
|
||||
- bool flag;
|
||||
int ret;
|
||||
|
||||
- pthread_atfork(NULL, NULL, wd_digest_clear_status);
|
||||
-
|
||||
- flag = wd_alg_try_init(&wd_digest_setting.status);
|
||||
- if (!flag)
|
||||
- return 0;
|
||||
-
|
||||
- ret = wd_init_param_check(config, sched);
|
||||
- if (ret)
|
||||
- goto out_clear_init;
|
||||
-
|
||||
ret = wd_set_epoll_en("WD_DIGEST_EPOLL_EN",
|
||||
&wd_digest_setting.config.epoll_en);
|
||||
if (ret < 0)
|
||||
- goto out_clear_init;
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_ctx_config(&wd_digest_setting.config, config);
|
||||
if (ret < 0)
|
||||
- goto out_clear_init;
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_sched(&wd_digest_setting.sched, sched);
|
||||
if (ret < 0)
|
||||
@@ -243,8 +244,6 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
goto out_free_priv;
|
||||
}
|
||||
|
||||
- wd_alg_set_init(&wd_digest_setting.status);
|
||||
-
|
||||
return 0;
|
||||
|
||||
out_free_priv:
|
||||
@@ -256,12 +255,39 @@ out_clear_sched:
|
||||
wd_clear_sched(&wd_digest_setting.sched);
|
||||
out_clear_ctx_config:
|
||||
wd_clear_ctx_config(&wd_digest_setting.config);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
+{
|
||||
+ bool flag;
|
||||
+ int ret;
|
||||
+
|
||||
+ pthread_atfork(NULL, NULL, wd_digest_clear_status);
|
||||
+
|
||||
+ flag = wd_alg_try_init(&wd_digest_setting.status);
|
||||
+ if (!flag)
|
||||
+ return 0;
|
||||
+
|
||||
+ ret = wd_init_param_check(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ ret = wd_digest_init_nolock(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ wd_alg_set_init(&wd_digest_setting.status);
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
out_clear_init:
|
||||
wd_alg_clear_init(&wd_digest_setting.status);
|
||||
return ret;
|
||||
}
|
||||
|
||||
-void wd_digest_uninit(void)
|
||||
+static void wd_digest_uninit_nolock(void)
|
||||
{
|
||||
void *priv = wd_digest_setting.priv;
|
||||
|
||||
@@ -276,6 +302,59 @@ void wd_digest_uninit(void)
|
||||
|
||||
wd_clear_sched(&wd_digest_setting.sched);
|
||||
wd_clear_ctx_config(&wd_digest_setting.config);
|
||||
+}
|
||||
+
|
||||
+void wd_digest_uninit(void)
|
||||
+{
|
||||
+ wd_digest_uninit_nolock();
|
||||
+ wd_alg_clear_init(&wd_digest_setting.status);
|
||||
+}
|
||||
+
|
||||
+int wd_digest_init2_(char *alg, __u32 sched_type, int task_type,
|
||||
+ struct wd_ctx_params *ctx_params)
|
||||
+{
|
||||
+ bool flag;
|
||||
+ int ret;
|
||||
+
|
||||
+ pthread_atfork(NULL, NULL, wd_digest_clear_status);
|
||||
+
|
||||
+ flag = wd_alg_try_init(&wd_digest_setting.status);
|
||||
+ if (!flag)
|
||||
+ return 0;
|
||||
+
|
||||
+ 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;
|
||||
+ }
|
||||
+
|
||||
+ wd_digest_init_attrs.alg = alg;
|
||||
+ wd_digest_init_attrs.sched_type = sched_type;
|
||||
+ wd_digest_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_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) {
|
||||
+ WD_ERR("fail to init alg attrs.\n");
|
||||
+ goto out_uninit;
|
||||
+ }
|
||||
+
|
||||
+ wd_alg_set_init(&wd_digest_setting.status);
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+out_uninit:
|
||||
+ wd_alg_clear_init(&wd_digest_setting.status);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void wd_digest_uninit2(void)
|
||||
+{
|
||||
+ wd_digest_uninit_nolock();
|
||||
+
|
||||
+ wd_alg_attrs_uninit(&wd_digest_init_attrs);
|
||||
+
|
||||
wd_alg_clear_init(&wd_digest_setting.status);
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
241
0024-uadk-aead-introduce-the-init2-interface-for-aead.patch
Normal file
241
0024-uadk-aead-introduce-the-init2-interface-for-aead.patch
Normal file
@ -0,0 +1,241 @@
|
||||
From 8a319d5ab3b4c30d84b7dc1204c3d5f4fc9dbe2a Mon Sep 17 00:00:00 2001
|
||||
From: Hao Fang <fanghao11@huawei.com>
|
||||
Date: Wed, 26 Apr 2023 11:55:26 +0800
|
||||
Subject: [PATCH 24/28] uadk/aead: introduce the init2 interface for aead
|
||||
|
||||
The basic init process is complex for users who need to
|
||||
know the device, scheduler, etc.
|
||||
|
||||
So introduce the init2 interface just for simplifying
|
||||
the initialization process when user use the aead algorithm.
|
||||
|
||||
Signed-off-by: Hao Fang <fanghao11@huawei.com>
|
||||
---
|
||||
include/wd_aead.h | 28 ++++++++++++
|
||||
libwd_crypto.map | 3 ++
|
||||
wd_aead.c | 113 +++++++++++++++++++++++++++++++++++++++-------
|
||||
3 files changed, 127 insertions(+), 17 deletions(-)
|
||||
|
||||
diff --git a/include/wd_aead.h b/include/wd_aead.h
|
||||
index ba7d062..ef1b57b 100644
|
||||
--- a/include/wd_aead.h
|
||||
+++ b/include/wd_aead.h
|
||||
@@ -96,6 +96,34 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched);
|
||||
*/
|
||||
void wd_aead_uninit(void);
|
||||
|
||||
+/**
|
||||
+ * wd_aead_init2_() - A simplify interface to initializate uadk
|
||||
+ * aead operation. This interface keeps most functions of
|
||||
+ * wd_aead_init(). Users just need to descripe the deployment of
|
||||
+ * business scenarios. Then the initialization will request appropriate
|
||||
+ * resources to support the business scenarios.
|
||||
+ * To make the initializate simpler, ctx_params support set NULL.
|
||||
+ * And then the function will set them as driver's default.
|
||||
+ * Please do not use this interface with wd_aead_init() together, or
|
||||
+ * some resources may be leak.
|
||||
+ *
|
||||
+ * @alg: The algorithm users want to use.
|
||||
+ * @sched_type: The scheduling type users want to use.
|
||||
+ * @task_type: Task types, including soft computing, hardware and hybrid computing.
|
||||
+ * @ctx_params: The ctxs resources users want to use. Include per operation
|
||||
+ * type ctx numbers and business process run numa.
|
||||
+ *
|
||||
+ * Return 0 if succeed and others if fail.
|
||||
+ */
|
||||
+int wd_aead_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params);
|
||||
+
|
||||
+#define wd_aead_init2(alg, sched_type, task_type) \
|
||||
+ wd_aead_init2_(alg, sched_type, task_type, NULL)
|
||||
+
|
||||
+/**
|
||||
+ * wd_aead_uninit2() - Uninitialise ctx configuration and scheduler.
|
||||
+ */
|
||||
+void wd_aead_uninit2(void);
|
||||
/**
|
||||
* wd_aead_alloc_sess() Allocate a wd aead session
|
||||
* @ setup Parameters to setup this session.
|
||||
diff --git a/libwd_crypto.map b/libwd_crypto.map
|
||||
index e28dd79..e8555c9 100644
|
||||
--- a/libwd_crypto.map
|
||||
+++ b/libwd_crypto.map
|
||||
@@ -23,6 +23,9 @@ global:
|
||||
|
||||
wd_aead_init;
|
||||
wd_aead_uninit;
|
||||
+ wd_aead_init2;
|
||||
+ wd_aead_init2_;
|
||||
+ wd_aead_uninit2;
|
||||
wd_aead_alloc_sess;
|
||||
wd_aead_free_sess;
|
||||
wd_aead_set_ckey;
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index 9b80922..8b63daa 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -56,6 +56,17 @@ struct wd_aead_sess {
|
||||
};
|
||||
|
||||
struct wd_env_config wd_aead_env_config;
|
||||
+static struct wd_init_attrs wd_aead_init_attrs;
|
||||
+
|
||||
+static struct wd_ctx_nums wd_aead_ctx_num[] = {
|
||||
+ {1, 1}, {}
|
||||
+};
|
||||
+
|
||||
+static struct wd_ctx_params wd_aead_ctx_params = {
|
||||
+ .op_type_num = 1,
|
||||
+ .ctx_set_num = wd_aead_ctx_num,
|
||||
+ .bmp = NULL,
|
||||
+};
|
||||
|
||||
#ifdef WD_STATIC_DRV
|
||||
static void wd_aead_set_static_drv(void)
|
||||
@@ -394,30 +405,19 @@ static void wd_aead_clear_status(void)
|
||||
wd_alg_clear_init(&wd_aead_setting.status);
|
||||
}
|
||||
|
||||
-int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
+static int wd_aead_init_nolock(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
void *priv;
|
||||
- bool flag;
|
||||
int ret;
|
||||
|
||||
- pthread_atfork(NULL, NULL, wd_aead_clear_status);
|
||||
-
|
||||
- flag = wd_alg_try_init(&wd_aead_setting.status);
|
||||
- if (!flag)
|
||||
- return 0;
|
||||
-
|
||||
- ret = wd_init_param_check(config, sched);
|
||||
- if (ret)
|
||||
- goto out_clear_init;
|
||||
-
|
||||
ret = wd_set_epoll_en("WD_AEAD_EPOLL_EN",
|
||||
&wd_aead_setting.config.epoll_en);
|
||||
if (ret < 0)
|
||||
- goto out_clear_init;
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_ctx_config(&wd_aead_setting.config, config);
|
||||
if (ret)
|
||||
- goto out_clear_init;
|
||||
+ return ret;
|
||||
|
||||
ret = wd_init_sched(&wd_aead_setting.sched, sched);
|
||||
if (ret < 0)
|
||||
@@ -449,8 +449,6 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
goto out_free_priv;
|
||||
}
|
||||
|
||||
- wd_alg_set_init(&wd_aead_setting.status);
|
||||
-
|
||||
return 0;
|
||||
|
||||
out_free_priv:
|
||||
@@ -462,12 +460,39 @@ out_clear_sched:
|
||||
wd_clear_sched(&wd_aead_setting.sched);
|
||||
out_clear_ctx_config:
|
||||
wd_clear_ctx_config(&wd_aead_setting.config);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
+{
|
||||
+ bool flag;
|
||||
+ int ret;
|
||||
+
|
||||
+ pthread_atfork(NULL, NULL, wd_aead_clear_status);
|
||||
+
|
||||
+ flag = wd_alg_try_init(&wd_aead_setting.status);
|
||||
+ if (!flag)
|
||||
+ return 0;
|
||||
+
|
||||
+ ret = wd_init_param_check(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ ret = wd_aead_init_nolock(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_clear_init;
|
||||
+
|
||||
+ wd_alg_set_init(&wd_aead_setting.status);
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
out_clear_init:
|
||||
wd_alg_clear_init(&wd_aead_setting.status);
|
||||
return ret;
|
||||
}
|
||||
|
||||
-void wd_aead_uninit(void)
|
||||
+static void wd_aead_uninit_nolock(void)
|
||||
{
|
||||
void *priv = wd_aead_setting.priv;
|
||||
|
||||
@@ -481,6 +506,60 @@ void wd_aead_uninit(void)
|
||||
wd_uninit_async_request_pool(&wd_aead_setting.pool);
|
||||
wd_clear_sched(&wd_aead_setting.sched);
|
||||
wd_clear_ctx_config(&wd_aead_setting.config);
|
||||
+}
|
||||
+
|
||||
+void wd_aead_uninit(void)
|
||||
+{
|
||||
+ wd_aead_uninit_nolock();
|
||||
+ wd_alg_clear_init(&wd_aead_setting.status);
|
||||
+}
|
||||
+
|
||||
+
|
||||
+int wd_aead_init2_(char *alg, __u32 sched_type, int task_type,
|
||||
+ struct wd_ctx_params *ctx_params)
|
||||
+{
|
||||
+ bool flag;
|
||||
+ int ret;
|
||||
+
|
||||
+ pthread_atfork(NULL, NULL, wd_aead_clear_status);
|
||||
+
|
||||
+ flag = wd_alg_try_init(&wd_aead_setting.status);
|
||||
+ if (!flag)
|
||||
+ return 0;
|
||||
+
|
||||
+ 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;
|
||||
+ }
|
||||
+
|
||||
+ wd_aead_init_attrs.alg = alg;
|
||||
+ wd_aead_init_attrs.sched_type = sched_type;
|
||||
+ wd_aead_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_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) {
|
||||
+ WD_ERR("fail to init alg attrs.\n");
|
||||
+ goto out_uninit;
|
||||
+ }
|
||||
+
|
||||
+ wd_alg_set_init(&wd_aead_setting.status);
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+out_uninit:
|
||||
+ wd_alg_clear_init(&wd_aead_setting.status);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void wd_aead_uninit2(void)
|
||||
+{
|
||||
+ wd_aead_uninit_nolock();
|
||||
+
|
||||
+ wd_alg_attrs_uninit(&wd_aead_init_attrs);
|
||||
+
|
||||
wd_alg_clear_init(&wd_aead_setting.status);
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
571
0025-uadk-digest-adapt-the-module-dynamic-load-for-the-di.patch
Normal file
571
0025-uadk-digest-adapt-the-module-dynamic-load-for-the-di.patch
Normal file
@ -0,0 +1,571 @@
|
||||
From c022879fbe09e6067c390b6a43f4d6fea9e30a2f Mon Sep 17 00:00:00 2001
|
||||
From: Hao Fang <fanghao11@huawei.com>
|
||||
Date: Wed, 26 Apr 2023 11:55:27 +0800
|
||||
Subject: [PATCH 25/28] uadk/digest: adapt the module dynamic load for the
|
||||
digest algs
|
||||
|
||||
After adding the digest module of the init2 interface, combine the
|
||||
driver module dynamic load in the initialization process, transform
|
||||
HiSilicon digest driver, and implemented using the dynamic loading
|
||||
function connection between driver and algorithm layer.
|
||||
|
||||
Signed-off-by: Hao Fang <fanghao11@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 58 +++++++---
|
||||
include/drv/wd_digest_drv.h | 26 -----
|
||||
wd_digest.c | 224 ++++++++++++++++++++++++------------
|
||||
3 files changed, 193 insertions(+), 115 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index a84cc7a..a918882 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -565,6 +565,22 @@ static struct wd_alg_driver cipher_alg_driver[] = {
|
||||
GEN_SEC_ALG_DRIVER("cbc-cs3(sm4)"),
|
||||
};
|
||||
|
||||
+static struct wd_alg_driver digest_alg_driver[] = {
|
||||
+ GEN_SEC_ALG_DRIVER("sm3"),
|
||||
+ GEN_SEC_ALG_DRIVER("md5"),
|
||||
+ GEN_SEC_ALG_DRIVER("sha1"),
|
||||
+ GEN_SEC_ALG_DRIVER("sha224"),
|
||||
+ GEN_SEC_ALG_DRIVER("sha256"),
|
||||
+ GEN_SEC_ALG_DRIVER("sha384"),
|
||||
+ GEN_SEC_ALG_DRIVER("sha512"),
|
||||
+ GEN_SEC_ALG_DRIVER("sha512-224"),
|
||||
+ GEN_SEC_ALG_DRIVER("sha512-256"),
|
||||
+ GEN_SEC_ALG_DRIVER("xcbc-mac-96(aes)"),
|
||||
+ GEN_SEC_ALG_DRIVER("xcbc-prf-128(aes)"),
|
||||
+ GEN_SEC_ALG_DRIVER("cmac(aes)"),
|
||||
+ GEN_SEC_ALG_DRIVER("gmac(aes)"),
|
||||
+};
|
||||
+
|
||||
static void dump_sec_msg(void *msg, const char *alg)
|
||||
{
|
||||
struct wd_cipher_msg *cmsg;
|
||||
@@ -1698,16 +1714,6 @@ int hisi_sec_digest_recv(handle_t ctx, void *digest_msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static struct wd_digest_driver hisi_digest_driver = {
|
||||
- .drv_name = "hisi_sec2",
|
||||
- .alg_name = "digest",
|
||||
- .drv_ctx_size = sizeof(struct hisi_sec_ctx),
|
||||
- .init = hisi_sec_init,
|
||||
- .exit = hisi_sec_exit,
|
||||
-};
|
||||
-
|
||||
-WD_DIGEST_SET_DRIVER(hisi_digest_driver);
|
||||
-
|
||||
static int hmac_key_len_check(struct wd_digest_msg *msg)
|
||||
{
|
||||
switch (msg->alg) {
|
||||
@@ -2625,8 +2631,11 @@ static void hisi_sec_driver_adapter(struct hisi_qp *qp)
|
||||
cipher_alg_driver[i].recv = hisi_sec_cipher_recv;
|
||||
}
|
||||
|
||||
- hisi_digest_driver.digest_send = hisi_sec_digest_send;
|
||||
- hisi_digest_driver.digest_recv = hisi_sec_digest_recv;
|
||||
+ alg_num = ARRAY_SIZE(digest_alg_driver);
|
||||
+ for (i = 0; i < alg_num; i++) {
|
||||
+ digest_alg_driver[i].send = hisi_sec_digest_send;
|
||||
+ digest_alg_driver[i].recv = hisi_sec_digest_recv;
|
||||
+ }
|
||||
|
||||
hisi_aead_driver.aead_send = hisi_sec_aead_send;
|
||||
hisi_aead_driver.aead_recv = hisi_sec_aead_recv;
|
||||
@@ -2638,8 +2647,11 @@ static void hisi_sec_driver_adapter(struct hisi_qp *qp)
|
||||
cipher_alg_driver[i].recv = hisi_sec_cipher_recv_v3;
|
||||
}
|
||||
|
||||
- hisi_digest_driver.digest_send = hisi_sec_digest_send_v3;
|
||||
- hisi_digest_driver.digest_recv = hisi_sec_digest_recv_v3;
|
||||
+ alg_num = ARRAY_SIZE(digest_alg_driver);
|
||||
+ for (i = 0; i < alg_num; i++) {
|
||||
+ digest_alg_driver[i].send = hisi_sec_digest_send_v3;
|
||||
+ digest_alg_driver[i].recv = hisi_sec_digest_recv_v3;
|
||||
+ }
|
||||
|
||||
hisi_aead_driver.aead_send = hisi_sec_aead_send_v3;
|
||||
hisi_aead_driver.aead_recv = hisi_sec_aead_recv_v3;
|
||||
@@ -2709,25 +2721,39 @@ void hisi_sec_exit(void *priv)
|
||||
|
||||
static void __attribute__((constructor)) hisi_sec2_probe(void)
|
||||
{
|
||||
- int alg_num = ARRAY_SIZE(cipher_alg_driver);
|
||||
+ int alg_num;
|
||||
int i, ret;
|
||||
|
||||
WD_INFO("Info: register SEC alg drivers!\n");
|
||||
|
||||
+ 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)
|
||||
WD_ERR("Error: register SEC %s failed!\n",
|
||||
cipher_alg_driver[i].alg_name);
|
||||
}
|
||||
+
|
||||
+ 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)
|
||||
+ WD_ERR("Error: register SEC %s failed!\n",
|
||||
+ digest_alg_driver[i].alg_name);
|
||||
+ }
|
||||
}
|
||||
|
||||
static void __attribute__((destructor)) hisi_sec2_remove(void)
|
||||
{
|
||||
- int alg_num = ARRAY_SIZE(cipher_alg_driver);
|
||||
+ int alg_num;
|
||||
int i;
|
||||
|
||||
+ alg_num = ARRAY_SIZE(cipher_alg_driver);
|
||||
for (i = 0; i < alg_num; i++)
|
||||
wd_alg_driver_unregister(&cipher_alg_driver[i]);
|
||||
+
|
||||
+ alg_num = ARRAY_SIZE(digest_alg_driver);
|
||||
+ for (i = 0; i < alg_num; i++)
|
||||
+ wd_alg_driver_unregister(&digest_alg_driver[i]);
|
||||
}
|
||||
|
||||
diff --git a/include/drv/wd_digest_drv.h b/include/drv/wd_digest_drv.h
|
||||
index 96b32e2..3c4477d 100644
|
||||
--- a/include/drv/wd_digest_drv.h
|
||||
+++ b/include/drv/wd_digest_drv.h
|
||||
@@ -51,34 +51,8 @@ struct wd_digest_msg {
|
||||
__u64 long_data_len;
|
||||
};
|
||||
|
||||
-struct wd_digest_driver {
|
||||
- const char *drv_name;
|
||||
- const char *alg_name;
|
||||
- __u32 drv_ctx_size;
|
||||
- int (*init)(void *conf, void *priv);
|
||||
- void (*exit)(void *priv);
|
||||
- int (*digest_send)(handle_t ctx, void *digest_msg);
|
||||
- int (*digest_recv)(handle_t ctx, void *digest_msg);
|
||||
-};
|
||||
-
|
||||
-void wd_digest_set_driver(struct wd_digest_driver *drv);
|
||||
-struct wd_digest_driver *wd_digest_get_driver(void);
|
||||
struct wd_digest_msg *wd_digest_get_msg(__u32 idx, __u32 tag);
|
||||
|
||||
-#ifdef WD_STATIC_DRV
|
||||
-#define WD_DIGEST_SET_DRIVER(drv) \
|
||||
-struct wd_digest_driver *wd_digest_get_driver(void) \
|
||||
-{ \
|
||||
- return &drv; \
|
||||
-}
|
||||
-#else
|
||||
-#define WD_DIGEST_SET_DRIVER(drv) \
|
||||
-static void __attribute__((constructor)) set_digest_drivers(void) \
|
||||
-{ \
|
||||
- wd_digest_set_driver(&(drv)); \
|
||||
-}
|
||||
-#endif
|
||||
-
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index 03d3ace..c57e7d6 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -37,15 +37,22 @@ static int g_digest_mac_full_len[WD_DIGEST_TYPE_MAX] = {
|
||||
WD_DIGEST_SHA512_224_FULL_LEN, WD_DIGEST_SHA512_256_FULL_LEN
|
||||
};
|
||||
|
||||
+/* These algs's name need correct match with digest alg type */
|
||||
+static char *wd_digest_alg_name[WD_DIGEST_TYPE_MAX] = {
|
||||
+ "sm3", "md5", "sha1", "sha256", "sha224", "sha384",
|
||||
+ "sha512", "sha512-224", "sha512-256", "xcbc-mac-96(aes)",
|
||||
+ "xcbc-prf-128(aes)", "cmac(aes)", "gmac(aes)"
|
||||
+};
|
||||
+
|
||||
struct wd_digest_setting {
|
||||
enum wd_status status;
|
||||
struct wd_ctx_config_internal config;
|
||||
struct wd_sched sched;
|
||||
- struct wd_digest_driver *driver;
|
||||
+ struct wd_alg_driver *driver;
|
||||
struct wd_async_msg_pool pool;
|
||||
- void *sched_ctx;
|
||||
void *priv;
|
||||
void *dlhandle;
|
||||
+ void *dlh_list;
|
||||
} wd_digest_setting;
|
||||
|
||||
struct wd_digest_sess {
|
||||
@@ -68,42 +75,49 @@ struct wd_digest_sess {
|
||||
struct wd_env_config wd_digest_env_config;
|
||||
static struct wd_init_attrs wd_digest_init_attrs;
|
||||
|
||||
-static struct wd_ctx_nums wd_digest_ctx_num[] = {
|
||||
- {1, 1}, {}
|
||||
-};
|
||||
-
|
||||
-static struct wd_ctx_params wd_digest_ctx_params = {
|
||||
- .op_type_num = 1,
|
||||
- .ctx_set_num = wd_digest_ctx_num,
|
||||
- .bmp = NULL,
|
||||
-};
|
||||
-
|
||||
-#ifdef WD_STATIC_DRV
|
||||
-static void wd_digest_set_static_drv(void)
|
||||
+static void wd_digest_close_driver(void)
|
||||
{
|
||||
- wd_digest_setting.driver = wd_digest_get_driver();
|
||||
- if (!wd_digest_setting.driver)
|
||||
- WD_ERR("failed to get driver!\n");
|
||||
+ if (wd_digest_setting.dlhandle) {
|
||||
+ wd_release_drv(wd_digest_setting.driver);
|
||||
+ dlclose(wd_digest_setting.dlhandle);
|
||||
+ wd_digest_setting.dlhandle = NULL;
|
||||
+ }
|
||||
}
|
||||
-#else
|
||||
-static void __attribute__((constructor)) wd_digest_open_driver(void)
|
||||
+
|
||||
+static int wd_digest_open_driver(void)
|
||||
{
|
||||
- /* Fix me: vendor driver should be put in /usr/lib/wd/ */
|
||||
- wd_digest_setting.dlhandle = dlopen("libhisi_sec.so", RTLD_NOW);
|
||||
- if (!wd_digest_setting.dlhandle)
|
||||
+ struct wd_alg_driver *driver = NULL;
|
||||
+ const char *alg_name = "sm3";
|
||||
+ char lib_path[PATH_STR_SIZE];
|
||||
+ 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;
|
||||
+
|
||||
+ wd_digest_setting.dlhandle = dlopen(lib_path, RTLD_NOW);
|
||||
+ if (!wd_digest_setting.dlhandle) {
|
||||
WD_ERR("failed to open libhisi_sec.so, %s\n", dlerror());
|
||||
-}
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
|
||||
-static void __attribute__((destructor)) wd_digest_close_driver(void)
|
||||
-{
|
||||
- if (wd_digest_setting.dlhandle)
|
||||
- dlclose(wd_digest_setting.dlhandle);
|
||||
-}
|
||||
-#endif
|
||||
+ driver = wd_request_drv(alg_name, false);
|
||||
+ if (!driver) {
|
||||
+ wd_digest_close_driver();
|
||||
+ WD_ERR("failed to get %s driver support\n", alg_name);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
|
||||
-void wd_digest_set_driver(struct wd_digest_driver *drv)
|
||||
-{
|
||||
- wd_digest_setting.driver = drv;
|
||||
+ wd_digest_setting.driver = driver;
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static int aes_key_len_check(__u32 length)
|
||||
@@ -154,29 +168,46 @@ int wd_digest_set_key(handle_t h_sess, const __u8 *key, __u32 key_len)
|
||||
handle_t wd_digest_alloc_sess(struct wd_digest_sess_setup *setup)
|
||||
{
|
||||
struct wd_digest_sess *sess = NULL;
|
||||
+ bool ret;
|
||||
|
||||
if (unlikely(!setup)) {
|
||||
WD_ERR("failed to check alloc sess param!\n");
|
||||
return (handle_t)0;
|
||||
}
|
||||
|
||||
+ if (setup->alg >= WD_DIGEST_TYPE_MAX) {
|
||||
+ WD_ERR("failed to check algorithm setup!\n");
|
||||
+ return (handle_t)0;
|
||||
+ }
|
||||
+
|
||||
sess = malloc(sizeof(struct wd_digest_sess));
|
||||
if (!sess)
|
||||
return (handle_t)0;
|
||||
memset(sess, 0, sizeof(struct wd_digest_sess));
|
||||
|
||||
+ sess->alg_name = wd_digest_alg_name[setup->alg];
|
||||
sess->alg = setup->alg;
|
||||
sess->mode = setup->mode;
|
||||
+ ret = wd_drv_alg_support(sess->alg_name, wd_digest_setting.driver);
|
||||
+ if (!ret) {
|
||||
+ WD_ERR("failed to support this algorithm: %s!\n", sess->alg_name);
|
||||
+ goto err_sess;
|
||||
+ }
|
||||
/* Some simple scheduler don't need scheduling parameters */
|
||||
sess->sched_key = (void *)wd_digest_setting.sched.sched_init(
|
||||
wd_digest_setting.sched.h_sched_ctx, setup->sched_param);
|
||||
if (WD_IS_ERR(sess->sched_key)) {
|
||||
WD_ERR("failed to init session schedule key!\n");
|
||||
- free(sess);
|
||||
- return (handle_t)0;
|
||||
+ goto err_sess;
|
||||
}
|
||||
|
||||
return (handle_t)sess;
|
||||
+
|
||||
+err_sess:
|
||||
+ if (sess->sched_key)
|
||||
+ free(sess->sched_key);
|
||||
+ free(sess);
|
||||
+ return (handle_t)0;
|
||||
}
|
||||
|
||||
void wd_digest_free_sess(handle_t h_sess)
|
||||
@@ -202,7 +233,6 @@ static void wd_digest_clear_status(void)
|
||||
static int wd_digest_init_nolock(struct wd_ctx_config *config,
|
||||
struct wd_sched *sched)
|
||||
{
|
||||
- void *priv;
|
||||
int ret;
|
||||
|
||||
ret = wd_set_epoll_en("WD_DIGEST_EPOLL_EN",
|
||||
@@ -218,11 +248,6 @@ static int wd_digest_init_nolock(struct wd_ctx_config *config,
|
||||
if (ret < 0)
|
||||
goto out_clear_ctx_config;
|
||||
|
||||
- /* set driver */
|
||||
-#ifdef WD_STATIC_DRV
|
||||
- wd_digest_set_static_drv();
|
||||
-#endif
|
||||
-
|
||||
/* allocate async pool for every ctx */
|
||||
ret = wd_init_async_request_pool(&wd_digest_setting.pool,
|
||||
config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
@@ -230,25 +255,14 @@ static int wd_digest_init_nolock(struct wd_ctx_config *config,
|
||||
if (ret < 0)
|
||||
goto out_clear_sched;
|
||||
|
||||
- /* init ctx related resources in specific driver */
|
||||
- priv = calloc(1, wd_digest_setting.driver->drv_ctx_size);
|
||||
- if (!priv) {
|
||||
- ret = -WD_ENOMEM;
|
||||
+ ret = wd_alg_init_driver(&wd_digest_setting.config,
|
||||
+ wd_digest_setting.driver,
|
||||
+ &wd_digest_setting.priv);
|
||||
+ if (ret)
|
||||
goto out_clear_pool;
|
||||
- }
|
||||
- wd_digest_setting.priv = priv;
|
||||
-
|
||||
- ret = wd_digest_setting.driver->init(&wd_digest_setting.config, priv);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to init digest dirver!\n");
|
||||
- goto out_free_priv;
|
||||
- }
|
||||
|
||||
return 0;
|
||||
|
||||
-out_free_priv:
|
||||
- free(priv);
|
||||
- wd_digest_setting.priv = NULL;
|
||||
out_clear_pool:
|
||||
wd_uninit_async_request_pool(&wd_digest_setting.pool);
|
||||
out_clear_sched:
|
||||
@@ -274,14 +288,20 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
if (ret)
|
||||
goto out_clear_init;
|
||||
|
||||
- ret = wd_digest_init_nolock(config, sched);
|
||||
+ ret = wd_digest_open_driver();
|
||||
if (ret)
|
||||
goto out_clear_init;
|
||||
|
||||
+ ret = wd_digest_init_nolock(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_close_driver;
|
||||
+
|
||||
wd_alg_set_init(&wd_digest_setting.status);
|
||||
|
||||
return 0;
|
||||
|
||||
+out_close_driver:
|
||||
+ wd_digest_close_driver();
|
||||
out_clear_init:
|
||||
wd_alg_clear_init(&wd_digest_setting.status);
|
||||
return ret;
|
||||
@@ -294,27 +314,36 @@ static void wd_digest_uninit_nolock(void)
|
||||
if (!priv)
|
||||
return;
|
||||
|
||||
- wd_digest_setting.driver->exit(priv);
|
||||
- wd_digest_setting.priv = NULL;
|
||||
- free(priv);
|
||||
-
|
||||
wd_uninit_async_request_pool(&wd_digest_setting.pool);
|
||||
-
|
||||
wd_clear_sched(&wd_digest_setting.sched);
|
||||
- wd_clear_ctx_config(&wd_digest_setting.config);
|
||||
+ wd_alg_uninit_driver(&wd_digest_setting.config,
|
||||
+ wd_digest_setting.driver, &priv);
|
||||
}
|
||||
|
||||
void wd_digest_uninit(void)
|
||||
{
|
||||
wd_digest_uninit_nolock();
|
||||
+ wd_digest_close_driver();
|
||||
wd_alg_clear_init(&wd_digest_setting.status);
|
||||
}
|
||||
|
||||
+static bool wd_digest_algs_check(const char *alg)
|
||||
+{
|
||||
+ for (int i = 0; i < WD_DIGEST_TYPE_MAX; i++) {
|
||||
+ if (!strcmp(alg, wd_digest_alg_name[i]))
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ return false;
|
||||
+}
|
||||
+
|
||||
int wd_digest_init2_(char *alg, __u32 sched_type, int task_type,
|
||||
struct wd_ctx_params *ctx_params)
|
||||
{
|
||||
+ struct wd_ctx_nums digest_ctx_num[1] = {0};
|
||||
+ struct wd_ctx_params digest_ctx_params = {0};
|
||||
+ int ret = 0;
|
||||
bool flag;
|
||||
- int ret;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_digest_clear_status);
|
||||
|
||||
@@ -322,28 +351,76 @@ int wd_digest_init2_(char *alg, __u32 sched_type, int task_type,
|
||||
if (!flag)
|
||||
return 0;
|
||||
|
||||
- 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;
|
||||
}
|
||||
|
||||
+ 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()
|
||||
+ * 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");
|
||||
+ goto out_uninit;
|
||||
+ }
|
||||
+
|
||||
+res_retry:
|
||||
+ 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;
|
||||
+ }
|
||||
+
|
||||
+ ret = wd_ctx_param_init(&digest_ctx_params, ctx_params,
|
||||
+ digest_ctx_num, wd_digest_setting.driver, 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;
|
||||
+ }
|
||||
+ goto out_driver;
|
||||
+ }
|
||||
+
|
||||
wd_digest_init_attrs.alg = alg;
|
||||
wd_digest_init_attrs.sched_type = sched_type;
|
||||
- wd_digest_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_digest_ctx_params;
|
||||
+ 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);
|
||||
+ goto res_retry;
|
||||
+ }
|
||||
WD_ERR("fail to init alg attrs.\n");
|
||||
- goto out_uninit;
|
||||
+ goto out_driver;
|
||||
}
|
||||
|
||||
wd_alg_set_init(&wd_digest_setting.status);
|
||||
|
||||
return 0;
|
||||
|
||||
+out_driver:
|
||||
+ wd_alg_drv_unbind(wd_digest_setting.driver);
|
||||
+out_dlopen:
|
||||
+ wd_dlclose_drv(wd_digest_setting.dlh_list);
|
||||
out_uninit:
|
||||
wd_alg_clear_init(&wd_digest_setting.status);
|
||||
return ret;
|
||||
@@ -352,9 +429,10 @@ out_uninit:
|
||||
void wd_digest_uninit2(void)
|
||||
{
|
||||
wd_digest_uninit_nolock();
|
||||
-
|
||||
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_setting.dlh_list = NULL;
|
||||
wd_alg_clear_init(&wd_digest_setting.status);
|
||||
}
|
||||
|
||||
@@ -483,8 +561,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *ds
|
||||
struct wd_msg_handle msg_handle;
|
||||
int ret;
|
||||
|
||||
- msg_handle.send = wd_digest_setting.driver->digest_send;
|
||||
- msg_handle.recv = wd_digest_setting.driver->digest_recv;
|
||||
+ msg_handle.send = wd_digest_setting.driver->send;
|
||||
+ msg_handle.recv = wd_digest_setting.driver->recv;
|
||||
|
||||
pthread_spin_lock(&ctx->lock);
|
||||
ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg,
|
||||
@@ -572,7 +650,7 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req)
|
||||
fill_request_msg(msg, req, dsess);
|
||||
msg->tag = msg_id;
|
||||
|
||||
- ret = wd_digest_setting.driver->digest_send(ctx->ctx, msg);
|
||||
+ ret = wd_digest_setting.driver->send(ctx->ctx, msg);
|
||||
if (unlikely(ret < 0)) {
|
||||
if (ret != -WD_EBUSY)
|
||||
WD_ERR("failed to send BD, hw is err!\n");
|
||||
@@ -620,7 +698,7 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
||||
ctx = config->ctxs + idx;
|
||||
|
||||
do {
|
||||
- ret = wd_digest_setting.driver->digest_recv(ctx->ctx,
|
||||
+ ret = wd_digest_setting.driver->recv(ctx->ctx,
|
||||
&recv_msg);
|
||||
if (ret == -WD_EAGAIN) {
|
||||
return ret;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
559
0026-uadk-aead-adadpt-the-module-dynamic-load-for-aead-al.patch
Normal file
559
0026-uadk-aead-adadpt-the-module-dynamic-load-for-aead-al.patch
Normal file
@ -0,0 +1,559 @@
|
||||
From d114c41cef30c36ae5d63f11ef6a14c48e26f241 Mon Sep 17 00:00:00 2001
|
||||
From: Hao Fang <fanghao11@huawei.com>
|
||||
Date: Wed, 26 Apr 2023 11:55:28 +0800
|
||||
Subject: [PATCH 26/28] uadk/aead: adadpt the module dynamic load for aead algs
|
||||
|
||||
After adding the aead module of the init2 interface, combine the
|
||||
driver module dynamic load in the initialization process,
|
||||
transform HiSilicon aead driver, and implemented using the dynamic
|
||||
loading function connection between driver and algorithm layer.
|
||||
|
||||
Signed-off-by: Hao Fang <fanghao11@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 47 +++++---
|
||||
include/drv/wd_aead_drv.h | 26 -----
|
||||
wd_aead.c | 230 ++++++++++++++++++++++++++------------
|
||||
3 files changed, 190 insertions(+), 113 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index a918882..bf05e05 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -581,6 +581,15 @@ static struct wd_alg_driver digest_alg_driver[] = {
|
||||
GEN_SEC_ALG_DRIVER("gmac(aes)"),
|
||||
};
|
||||
|
||||
+static struct wd_alg_driver aead_alg_driver[] = {
|
||||
+ GEN_SEC_ALG_DRIVER("ccm(aes)"),
|
||||
+ GEN_SEC_ALG_DRIVER("gcm(aes)"),
|
||||
+ 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)
|
||||
{
|
||||
struct wd_cipher_msg *cmsg;
|
||||
@@ -2349,16 +2358,6 @@ int hisi_sec_aead_recv(handle_t ctx, void *aead_msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static struct wd_aead_driver hisi_aead_driver = {
|
||||
- .drv_name = "hisi_sec2",
|
||||
- .alg_name = "aead",
|
||||
- .drv_ctx_size = sizeof(struct hisi_sec_ctx),
|
||||
- .init = hisi_sec_init,
|
||||
- .exit = hisi_sec_exit,
|
||||
-};
|
||||
-
|
||||
-WD_AEAD_SET_DRIVER(hisi_aead_driver);
|
||||
-
|
||||
static int fill_aead_bd3_alg(struct wd_aead_msg *msg,
|
||||
struct hisi_sec_sqe3 *sqe)
|
||||
{
|
||||
@@ -2636,9 +2635,11 @@ static void hisi_sec_driver_adapter(struct hisi_qp *qp)
|
||||
digest_alg_driver[i].send = hisi_sec_digest_send;
|
||||
digest_alg_driver[i].recv = hisi_sec_digest_recv;
|
||||
}
|
||||
-
|
||||
- hisi_aead_driver.aead_send = hisi_sec_aead_send;
|
||||
- hisi_aead_driver.aead_recv = hisi_sec_aead_recv;
|
||||
+ alg_num = ARRAY_SIZE(aead_alg_driver);
|
||||
+ for (i = 0; i < alg_num; i++) {
|
||||
+ aead_alg_driver[i].send = hisi_sec_aead_send;
|
||||
+ aead_alg_driver[i].recv = hisi_sec_aead_recv;
|
||||
+ }
|
||||
} else {
|
||||
WD_INFO("hisi sec init HIP09!\n");
|
||||
alg_num = ARRAY_SIZE(cipher_alg_driver);
|
||||
@@ -2652,9 +2653,11 @@ static void hisi_sec_driver_adapter(struct hisi_qp *qp)
|
||||
digest_alg_driver[i].send = hisi_sec_digest_send_v3;
|
||||
digest_alg_driver[i].recv = hisi_sec_digest_recv_v3;
|
||||
}
|
||||
-
|
||||
- hisi_aead_driver.aead_send = hisi_sec_aead_send_v3;
|
||||
- hisi_aead_driver.aead_recv = hisi_sec_aead_recv_v3;
|
||||
+ alg_num = ARRAY_SIZE(aead_alg_driver);
|
||||
+ for (i = 0; i < alg_num; i++) {
|
||||
+ aead_alg_driver[i].send = hisi_sec_aead_send_v3;
|
||||
+ aead_alg_driver[i].recv = hisi_sec_aead_recv_v3;
|
||||
+ }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2741,6 +2744,14 @@ static void __attribute__((constructor)) hisi_sec2_probe(void)
|
||||
WD_ERR("Error: register SEC %s failed!\n",
|
||||
digest_alg_driver[i].alg_name);
|
||||
}
|
||||
+
|
||||
+ 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)
|
||||
+ WD_ERR("Error: register SEC %s failed!\n",
|
||||
+ aead_alg_driver[i].alg_name);
|
||||
+ }
|
||||
}
|
||||
|
||||
static void __attribute__((destructor)) hisi_sec2_remove(void)
|
||||
@@ -2755,5 +2766,9 @@ static void __attribute__((destructor)) hisi_sec2_remove(void)
|
||||
alg_num = ARRAY_SIZE(digest_alg_driver);
|
||||
for (i = 0; i < alg_num; i++)
|
||||
wd_alg_driver_unregister(&digest_alg_driver[i]);
|
||||
+
|
||||
+ alg_num = ARRAY_SIZE(aead_alg_driver);
|
||||
+ for (i = 0; i < alg_num; i++)
|
||||
+ wd_alg_driver_unregister(&aead_alg_driver[i]);
|
||||
}
|
||||
|
||||
diff --git a/include/drv/wd_aead_drv.h b/include/drv/wd_aead_drv.h
|
||||
index 8446238..d2ecb22 100644
|
||||
--- a/include/drv/wd_aead_drv.h
|
||||
+++ b/include/drv/wd_aead_drv.h
|
||||
@@ -63,34 +63,8 @@ struct wd_aead_msg {
|
||||
__u8 *mac;
|
||||
};
|
||||
|
||||
-struct wd_aead_driver {
|
||||
- const char *drv_name;
|
||||
- const char *alg_name;
|
||||
- __u32 drv_ctx_size;
|
||||
- int (*init)(void *conf, void *priv);
|
||||
- void (*exit)(void *priv);
|
||||
- int (*aead_send)(handle_t ctx, void *aead_msg);
|
||||
- int (*aead_recv)(handle_t ctx, void *aead_msg);
|
||||
-};
|
||||
-
|
||||
-void wd_aead_set_driver(struct wd_aead_driver *drv);
|
||||
-struct wd_aead_driver *wd_aead_get_driver(void);
|
||||
struct wd_aead_msg *wd_aead_get_msg(__u32 idx, __u32 tag);
|
||||
|
||||
-#ifdef WD_STATIC_DRV
|
||||
-#define WD_AEAD_SET_DRIVER(drv) \
|
||||
-struct wd_aead_driver *wd_aead_get_driver(void) \
|
||||
-{ \
|
||||
- return &drv; \
|
||||
-}
|
||||
-#else
|
||||
-#define WD_AEAD_SET_DRIVER(drv) \
|
||||
-static void __attribute__((constructor)) set_aead_driver(void) \
|
||||
-{ \
|
||||
- wd_aead_set_driver(&(drv)); \
|
||||
-}
|
||||
-#endif
|
||||
-
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index 8b63daa..9db2480 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -29,15 +29,23 @@ static int g_aead_mac_len[WD_DIGEST_TYPE_MAX] = {
|
||||
WD_DIGEST_SHA512_224_LEN, WD_DIGEST_SHA512_256_LEN
|
||||
};
|
||||
|
||||
+/* These algs's name need correct match with alg/mode type */
|
||||
+static char *wd_aead_alg_name[WD_CIPHER_ALG_TYPE_MAX][WD_CIPHER_MODE_TYPE_MAX] = {
|
||||
+ {"", "authenc(hmac(sha256),cbc(sm4))", "", "", "", "", "", "", "",
|
||||
+ "ccm(sm4)", "gcm(sm4)"},
|
||||
+ {"", "authenc(hmac(sha256),cbc(aes))", "", "", "", "", "", "", "",
|
||||
+ "ccm(aes)", "gcm(aes)"}
|
||||
+};
|
||||
+
|
||||
struct wd_aead_setting {
|
||||
enum wd_status status;
|
||||
struct wd_ctx_config_internal config;
|
||||
struct wd_sched sched;
|
||||
- struct wd_aead_driver *driver;
|
||||
+ struct wd_alg_driver *driver;
|
||||
struct wd_async_msg_pool pool;
|
||||
- void *sched_ctx;
|
||||
void *priv;
|
||||
void *dlhandle;
|
||||
+ void *dlh_list;
|
||||
} wd_aead_setting;
|
||||
|
||||
struct wd_aead_sess {
|
||||
@@ -58,41 +66,49 @@ struct wd_aead_sess {
|
||||
struct wd_env_config wd_aead_env_config;
|
||||
static struct wd_init_attrs wd_aead_init_attrs;
|
||||
|
||||
-static struct wd_ctx_nums wd_aead_ctx_num[] = {
|
||||
- {1, 1}, {}
|
||||
-};
|
||||
-
|
||||
-static struct wd_ctx_params wd_aead_ctx_params = {
|
||||
- .op_type_num = 1,
|
||||
- .ctx_set_num = wd_aead_ctx_num,
|
||||
- .bmp = NULL,
|
||||
-};
|
||||
-
|
||||
-#ifdef WD_STATIC_DRV
|
||||
-static void wd_aead_set_static_drv(void)
|
||||
+static void wd_aead_close_driver(void)
|
||||
{
|
||||
- wd_aead_setting.driver = wd_aead_get_driver();
|
||||
- if (!wd_aead_setting.driver)
|
||||
- WD_ERR("failed to get driver!\n");
|
||||
+ if (wd_aead_setting.dlhandle) {
|
||||
+ wd_release_drv(wd_aead_setting.driver);
|
||||
+ dlclose(wd_aead_setting.dlhandle);
|
||||
+ wd_aead_setting.dlhandle = NULL;
|
||||
+ }
|
||||
}
|
||||
-#else
|
||||
-static void __attribute__((constructor)) wd_aead_open_driver(void)
|
||||
+
|
||||
+static int wd_aead_open_driver(void)
|
||||
{
|
||||
- wd_aead_setting.dlhandle = dlopen("libhisi_sec.so", RTLD_NOW);
|
||||
- if (!wd_aead_setting.dlhandle)
|
||||
+ struct wd_alg_driver *driver = NULL;
|
||||
+ const char *alg_name = "gcm(aes)";
|
||||
+ char lib_path[PATH_STR_SIZE];
|
||||
+ 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;
|
||||
+
|
||||
+ wd_aead_setting.dlhandle = dlopen(lib_path, RTLD_NOW);
|
||||
+ if (!wd_aead_setting.dlhandle) {
|
||||
WD_ERR("failed to open libhisi_sec.so, %s\n", dlerror());
|
||||
-}
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
|
||||
-static void __attribute__((destructor)) wd_aead_close_driver(void)
|
||||
-{
|
||||
- if (wd_aead_setting.dlhandle)
|
||||
- dlclose(wd_aead_setting.dlhandle);
|
||||
-}
|
||||
-#endif
|
||||
+ driver = wd_request_drv(alg_name, false);
|
||||
+ if (!driver) {
|
||||
+ wd_aead_close_driver();
|
||||
+ WD_ERR("failed to get %s driver support\n", alg_name);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
|
||||
-void wd_aead_set_driver(struct wd_aead_driver *drv)
|
||||
-{
|
||||
- wd_aead_setting.driver = drv;
|
||||
+ wd_aead_setting.driver = driver;
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static int aes_key_len_check(__u32 length)
|
||||
@@ -272,12 +288,19 @@ int wd_aead_get_maxauthsize(handle_t h_sess)
|
||||
handle_t wd_aead_alloc_sess(struct wd_aead_sess_setup *setup)
|
||||
{
|
||||
struct wd_aead_sess *sess = NULL;
|
||||
+ bool ret;
|
||||
|
||||
if (unlikely(!setup)) {
|
||||
WD_ERR("failed to check session input parameter!\n");
|
||||
return (handle_t)0;
|
||||
}
|
||||
|
||||
+ if (setup->calg >= WD_CIPHER_ALG_TYPE_MAX ||
|
||||
+ setup->cmode >= WD_CIPHER_MODE_TYPE_MAX) {
|
||||
+ WD_ERR("failed to check algorithm setup!\n");
|
||||
+ return (handle_t)0;
|
||||
+ }
|
||||
+
|
||||
sess = malloc(sizeof(struct wd_aead_sess));
|
||||
if (!sess) {
|
||||
WD_ERR("failed to alloc session memory!\n");
|
||||
@@ -285,20 +308,32 @@ handle_t wd_aead_alloc_sess(struct wd_aead_sess_setup *setup)
|
||||
}
|
||||
memset(sess, 0, sizeof(struct wd_aead_sess));
|
||||
|
||||
+ sess->alg_name = wd_aead_alg_name[setup->calg][setup->cmode];
|
||||
sess->calg = setup->calg;
|
||||
sess->cmode = setup->cmode;
|
||||
sess->dalg = setup->dalg;
|
||||
sess->dmode = setup->dmode;
|
||||
+ ret = wd_drv_alg_support(sess->alg_name, wd_aead_setting.driver);
|
||||
+ if (!ret) {
|
||||
+ WD_ERR("failed to support this algorithm: %s!\n", sess->alg_name);
|
||||
+ goto err_sess;
|
||||
+ }
|
||||
+
|
||||
/* Some simple scheduler don't need scheduling parameters */
|
||||
sess->sched_key = (void *)wd_aead_setting.sched.sched_init(
|
||||
wd_aead_setting.sched.h_sched_ctx, setup->sched_param);
|
||||
if (WD_IS_ERR(sess->sched_key)) {
|
||||
WD_ERR("failed to init session schedule key!\n");
|
||||
- free(sess);
|
||||
- return (handle_t)0;
|
||||
+ goto err_sess;
|
||||
}
|
||||
|
||||
return (handle_t)sess;
|
||||
+err_sess:
|
||||
+ if (sess->sched_key)
|
||||
+ free(sess->sched_key);
|
||||
+ free(sess);
|
||||
+ return (handle_t)0;
|
||||
+
|
||||
}
|
||||
|
||||
void wd_aead_free_sess(handle_t h_sess)
|
||||
@@ -407,7 +442,6 @@ static void wd_aead_clear_status(void)
|
||||
|
||||
static int wd_aead_init_nolock(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- void *priv;
|
||||
int ret;
|
||||
|
||||
ret = wd_set_epoll_en("WD_AEAD_EPOLL_EN",
|
||||
@@ -423,11 +457,6 @@ static int wd_aead_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
|
||||
if (ret < 0)
|
||||
goto out_clear_ctx_config;
|
||||
|
||||
- /* set driver */
|
||||
-#ifdef WD_STATIC_DRV
|
||||
- wd_aead_set_static_drv();
|
||||
-#endif
|
||||
-
|
||||
/* init async request pool */
|
||||
ret = wd_init_async_request_pool(&wd_aead_setting.pool,
|
||||
config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
@@ -435,25 +464,14 @@ static int wd_aead_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
|
||||
if (ret < 0)
|
||||
goto out_clear_sched;
|
||||
|
||||
- /* init ctx related resources in specific driver */
|
||||
- priv = calloc(1, wd_aead_setting.driver->drv_ctx_size);
|
||||
- if (!priv) {
|
||||
- ret = -WD_ENOMEM;
|
||||
+ ret = wd_alg_init_driver(&wd_aead_setting.config,
|
||||
+ wd_aead_setting.driver,
|
||||
+ &wd_aead_setting.priv);
|
||||
+ if (ret)
|
||||
goto out_clear_pool;
|
||||
- }
|
||||
- wd_aead_setting.priv = priv;
|
||||
-
|
||||
- ret = wd_aead_setting.driver->init(&wd_aead_setting.config, priv);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to init aead dirver!\n");
|
||||
- goto out_free_priv;
|
||||
- }
|
||||
|
||||
return 0;
|
||||
|
||||
-out_free_priv:
|
||||
- free(priv);
|
||||
- wd_aead_setting.priv = NULL;
|
||||
out_clear_pool:
|
||||
wd_uninit_async_request_pool(&wd_aead_setting.pool);
|
||||
out_clear_sched:
|
||||
@@ -479,14 +497,20 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
if (ret)
|
||||
goto out_clear_init;
|
||||
|
||||
- ret = wd_aead_init_nolock(config, sched);
|
||||
+ ret = wd_aead_open_driver();
|
||||
if (ret)
|
||||
goto out_clear_init;
|
||||
|
||||
+ ret = wd_aead_init_nolock(config, sched);
|
||||
+ if (ret)
|
||||
+ goto out_close_driver;
|
||||
+
|
||||
wd_alg_set_init(&wd_aead_setting.status);
|
||||
|
||||
return 0;
|
||||
|
||||
+out_close_driver:
|
||||
+ wd_aead_close_driver();
|
||||
out_clear_init:
|
||||
wd_alg_clear_init(&wd_aead_setting.status);
|
||||
return ret;
|
||||
@@ -499,27 +523,40 @@ static void wd_aead_uninit_nolock(void)
|
||||
if (!priv)
|
||||
return;
|
||||
|
||||
- wd_aead_setting.driver->exit(priv);
|
||||
- wd_aead_setting.priv = NULL;
|
||||
- free(priv);
|
||||
-
|
||||
wd_uninit_async_request_pool(&wd_aead_setting.pool);
|
||||
wd_clear_sched(&wd_aead_setting.sched);
|
||||
- wd_clear_ctx_config(&wd_aead_setting.config);
|
||||
+ wd_alg_uninit_driver(&wd_aead_setting.config,
|
||||
+ wd_aead_setting.driver, &priv);
|
||||
}
|
||||
|
||||
void wd_aead_uninit(void)
|
||||
{
|
||||
wd_aead_uninit_nolock();
|
||||
+ wd_aead_close_driver();
|
||||
wd_alg_clear_init(&wd_aead_setting.status);
|
||||
}
|
||||
|
||||
+static bool wd_aead_algs_check(const char *alg)
|
||||
+{
|
||||
+ for (int i = 0; i < WD_CIPHER_ALG_TYPE_MAX; i++) {
|
||||
+ for (int j = 0; j < WD_CIPHER_MODE_TYPE_MAX; j++) {
|
||||
+ if (!wd_aead_alg_name[i][j])
|
||||
+ continue;
|
||||
+ if (!strcmp(alg, wd_aead_alg_name[i][j]))
|
||||
+ return true;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return false;
|
||||
+}
|
||||
|
||||
int wd_aead_init2_(char *alg, __u32 sched_type, int task_type,
|
||||
struct wd_ctx_params *ctx_params)
|
||||
{
|
||||
+ struct wd_ctx_nums aead_ctx_num[WD_DIGEST_CIPHER_DECRYPTION + 1] = {0};
|
||||
+ struct wd_ctx_params aead_ctx_params = {0};
|
||||
+ int ret = 0;
|
||||
bool flag;
|
||||
- int ret;
|
||||
|
||||
pthread_atfork(NULL, NULL, wd_aead_clear_status);
|
||||
|
||||
@@ -527,28 +564,78 @@ int wd_aead_init2_(char *alg, __u32 sched_type, int task_type,
|
||||
if (!flag)
|
||||
return 0;
|
||||
|
||||
- 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;
|
||||
}
|
||||
|
||||
+ 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()
|
||||
+ * 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");
|
||||
+ goto out_uninit;
|
||||
+ }
|
||||
+
|
||||
+res_retry:
|
||||
+ 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;
|
||||
+ }
|
||||
+
|
||||
+ ret = wd_ctx_param_init(&aead_ctx_params, ctx_params,
|
||||
+ aead_ctx_num, wd_aead_setting.driver,
|
||||
+ 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;
|
||||
+ }
|
||||
+ goto out_driver;
|
||||
+ }
|
||||
+
|
||||
wd_aead_init_attrs.alg = alg;
|
||||
wd_aead_init_attrs.sched_type = sched_type;
|
||||
- wd_aead_init_attrs.ctx_params = ctx_params ? ctx_params : &wd_aead_ctx_params;
|
||||
+ 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);
|
||||
+ goto res_retry;
|
||||
+ }
|
||||
WD_ERR("fail to init alg attrs.\n");
|
||||
- goto out_uninit;
|
||||
+ goto out_driver;
|
||||
}
|
||||
|
||||
wd_alg_set_init(&wd_aead_setting.status);
|
||||
|
||||
return 0;
|
||||
|
||||
+out_driver:
|
||||
+ wd_alg_drv_unbind(wd_aead_setting.driver);
|
||||
+out_dlopen:
|
||||
+ wd_dlclose_drv(wd_aead_setting.dlh_list);
|
||||
out_uninit:
|
||||
wd_alg_clear_init(&wd_aead_setting.status);
|
||||
return ret;
|
||||
@@ -557,9 +644,10 @@ out_uninit:
|
||||
void wd_aead_uninit2(void)
|
||||
{
|
||||
wd_aead_uninit_nolock();
|
||||
-
|
||||
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_setting.dlh_list = NULL;
|
||||
wd_alg_clear_init(&wd_aead_setting.status);
|
||||
}
|
||||
|
||||
@@ -596,8 +684,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx,
|
||||
struct wd_msg_handle msg_handle;
|
||||
int ret;
|
||||
|
||||
- msg_handle.send = wd_aead_setting.driver->aead_send;
|
||||
- msg_handle.recv = wd_aead_setting.driver->aead_recv;
|
||||
+ msg_handle.send = wd_aead_setting.driver->send;
|
||||
+ msg_handle.recv = wd_aead_setting.driver->recv;
|
||||
|
||||
pthread_spin_lock(&ctx->lock);
|
||||
ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL,
|
||||
@@ -676,7 +764,7 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req)
|
||||
fill_request_msg(msg, req, sess);
|
||||
msg->tag = msg_id;
|
||||
|
||||
- ret = wd_aead_setting.driver->aead_send(ctx->ctx, msg);
|
||||
+ ret = wd_aead_setting.driver->send(ctx->ctx, msg);
|
||||
if (unlikely(ret < 0)) {
|
||||
if (ret != -WD_EBUSY)
|
||||
WD_ERR("failed to send BD, hw is err!\n");
|
||||
@@ -724,7 +812,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
||||
ctx = config->ctxs + idx;
|
||||
|
||||
do {
|
||||
- ret = wd_aead_setting.driver->aead_recv(ctx->ctx, &resp_msg);
|
||||
+ ret = wd_aead_setting.driver->recv(ctx->ctx, &resp_msg);
|
||||
if (ret == -WD_EAGAIN) {
|
||||
return ret;
|
||||
} else if (ret < 0) {
|
||||
--
|
||||
2.25.1
|
||||
|
||||
249
0027-uadk-tool-add-init2-test-for-digest-algs.patch
Normal file
249
0027-uadk-tool-add-init2-test-for-digest-algs.patch
Normal file
@ -0,0 +1,249 @@
|
||||
From 248baee2bffc98f7575f07b31fd341752cdd3648 Mon Sep 17 00:00:00 2001
|
||||
From: Hao Fang <fanghao11@huawei.com>
|
||||
Date: Wed, 26 Apr 2023 11:55:29 +0800
|
||||
Subject: [PATCH 27/28] uadk/tool: add init2 test for digest algs
|
||||
|
||||
add testcase for init2 just use cmd --init 2.
|
||||
default or --init 1 for init interface.
|
||||
|
||||
Signed-off-by: Hao Fang <fanghao11@huawei.com>
|
||||
---
|
||||
uadk_tool/test/test_sec.c | 152 +++++++++++++++++++++++++++++++++-----
|
||||
1 file changed, 132 insertions(+), 20 deletions(-)
|
||||
|
||||
diff --git a/uadk_tool/test/test_sec.c b/uadk_tool/test/test_sec.c
|
||||
index 9fe007e..6bd4319 100644
|
||||
--- a/uadk_tool/test/test_sec.c
|
||||
+++ b/uadk_tool/test/test_sec.c
|
||||
@@ -59,6 +59,7 @@ static unsigned int g_use_env;
|
||||
static unsigned int g_ctxnum;
|
||||
static unsigned int g_data_fmt = WD_FLAT_BUF;
|
||||
static unsigned int g_sgl_num = 0;
|
||||
+static unsigned int g_init;
|
||||
static pthread_spinlock_t lock = 0;
|
||||
|
||||
static struct hash_testvec g_long_hash_tv;
|
||||
@@ -85,6 +86,25 @@ enum digest_type {
|
||||
LOCAL_AES_XCBC_MAC_96,
|
||||
};
|
||||
|
||||
+char *digest_names[MAX_ALGO_PER_TYPE] = {
|
||||
+ "sm3",
|
||||
+ "md5",
|
||||
+ "sha1",
|
||||
+ "sha256",
|
||||
+ "sha224",
|
||||
+ "sha384",
|
||||
+ "sha512",
|
||||
+ "sha512-224",
|
||||
+ "sha512-256",
|
||||
+ "cmac(aes)",
|
||||
+ "gmac(aes)", /* --digest 10: test aes-gmac-128 */
|
||||
+ "gmac(aes)", /* --digest 11: test aes-gmac-192 */
|
||||
+ "gmac(aes)", /* --digest 12: test aes-gmac-256 */
|
||||
+ "xcbc-mac-96(aes)",
|
||||
+ "xcbc-prf-128(aes)",
|
||||
+ "ccm(aes)", /* --digest 15: for error alg test */
|
||||
+};
|
||||
+
|
||||
struct sva_bd {
|
||||
char *src;
|
||||
char *dst;
|
||||
@@ -138,6 +158,7 @@ struct test_sec_option {
|
||||
__u32 stream_mode;
|
||||
__u32 sgl_num;
|
||||
__u32 use_env;
|
||||
+ __u32 init;
|
||||
};
|
||||
|
||||
//static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
|
||||
@@ -649,21 +670,6 @@ static void uninit_config(void)
|
||||
wd_sched_rr_release(g_sched);
|
||||
}
|
||||
|
||||
-static void digest_uninit_config(void)
|
||||
-{
|
||||
- int i;
|
||||
-
|
||||
- if (g_use_env) {
|
||||
- wd_digest_env_uninit();
|
||||
- return;
|
||||
- }
|
||||
-
|
||||
- wd_digest_uninit();
|
||||
- for (i = 0; i < g_ctx_cfg.ctx_num; i++)
|
||||
- wd_release_ctx(g_ctx_cfg.ctxs[i].ctx);
|
||||
- free(g_ctx_cfg.ctxs);
|
||||
-}
|
||||
-
|
||||
static int test_sec_cipher_sync_once(void)
|
||||
{
|
||||
struct cipher_testvec *tv = NULL;
|
||||
@@ -1400,7 +1406,7 @@ static __u32 sched_digest_pick_next_ctx(handle_t h_sched_ctx,
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int init_digest_ctx_config(int type, int mode)
|
||||
+static int digest_init1(int type, int mode)
|
||||
{
|
||||
struct uacce_dev_list *list;
|
||||
struct wd_sched sched;
|
||||
@@ -1450,6 +1456,108 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
+static int digest_init2(int type, int mode)
|
||||
+{
|
||||
+ struct wd_ctx_nums *ctx_set_num;
|
||||
+ struct wd_ctx_params cparams;
|
||||
+ int ret;
|
||||
+
|
||||
+ if (g_testalg >= MAX_ALGO_PER_TYPE)
|
||||
+ return -WD_EINVAL;
|
||||
+
|
||||
+ ctx_set_num = calloc(1, sizeof(*ctx_set_num));
|
||||
+ if (!ctx_set_num) {
|
||||
+ WD_ERR("failed to alloc ctx_set_size!\n");
|
||||
+ return -WD_ENOMEM;
|
||||
+ }
|
||||
+
|
||||
+ cparams.op_type_num = 1;
|
||||
+ cparams.ctx_set_num = ctx_set_num;
|
||||
+ cparams.bmp = numa_allocate_nodemask();
|
||||
+ if (!cparams.bmp) {
|
||||
+ WD_ERR("failed to create nodemask!\n");
|
||||
+ ret = -WD_ENOMEM;
|
||||
+ goto out_freectx;
|
||||
+ }
|
||||
+
|
||||
+ numa_bitmask_setall(cparams.bmp);
|
||||
+
|
||||
+ if (mode == CTX_MODE_SYNC)
|
||||
+ ctx_set_num->sync_ctx_num = g_ctxnum;
|
||||
+
|
||||
+ if (mode == CTX_MODE_ASYNC)
|
||||
+ ctx_set_num->async_ctx_num = g_ctxnum;
|
||||
+
|
||||
+ ret = wd_digest_init2_(digest_names[g_testalg], 0, 0, &cparams);
|
||||
+ if (ret)
|
||||
+ goto out_freebmp;
|
||||
+
|
||||
+out_freebmp:
|
||||
+ numa_free_nodemask(cparams.bmp);
|
||||
+
|
||||
+out_freectx:
|
||||
+ free(ctx_set_num);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static int init_digest_ctx_config(int type, int mode)
|
||||
+{
|
||||
+ int ret = -1;
|
||||
+
|
||||
+ switch (g_init) {
|
||||
+ case 0:
|
||||
+ case 1:
|
||||
+ SEC_TST_PRT("uadk entry init1!\n");
|
||||
+ ret = digest_init1(type, mode);
|
||||
+ break;
|
||||
+ case 2:
|
||||
+ SEC_TST_PRT("uadk entry init2!\n");
|
||||
+ ret = digest_init2(type, mode);
|
||||
+ break;
|
||||
+ default:
|
||||
+ SEC_TST_PRT("unsupported init-type%u!\n", g_init);
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static void digest_uninit1(void)
|
||||
+{
|
||||
+ int i;
|
||||
+
|
||||
+ if (g_use_env) {
|
||||
+ wd_digest_env_uninit();
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ wd_digest_uninit();
|
||||
+ for (i = 0; i < g_ctx_cfg.ctx_num; i++)
|
||||
+ wd_release_ctx(g_ctx_cfg.ctxs[i].ctx);
|
||||
+ free(g_ctx_cfg.ctxs);
|
||||
+}
|
||||
+
|
||||
+static void digest_uninit2(void)
|
||||
+{
|
||||
+ wd_digest_uninit2();
|
||||
+}
|
||||
+
|
||||
+static void digest_uninit_config(void)
|
||||
+{
|
||||
+ switch (g_init) {
|
||||
+ case 0:
|
||||
+ case 1:
|
||||
+ digest_uninit1();
|
||||
+ break;
|
||||
+ case 2:
|
||||
+ digest_uninit2();
|
||||
+ break;
|
||||
+ default:
|
||||
+ SEC_TST_PRT("unsupported uninit-type%u!\n", g_init);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
int get_digest_resource(struct hash_testvec **alg_tv, int* alg, int* mode)
|
||||
{
|
||||
struct hash_testvec *tmp_tv;
|
||||
@@ -4083,6 +4191,7 @@ static void test_sec_cmd_parse(int argc, char *argv[], struct test_sec_option *o
|
||||
int c;
|
||||
|
||||
static struct option long_options[] = {
|
||||
+ {"help", no_argument, 0, 0},
|
||||
{"cipher", required_argument, 0, 1},
|
||||
{"digest", required_argument, 0, 2},
|
||||
{"aead", required_argument, 0, 3},
|
||||
@@ -4100,7 +4209,7 @@ static void test_sec_cmd_parse(int argc, char *argv[], struct test_sec_option *o
|
||||
{"stream", no_argument, 0, 15},
|
||||
{"sglnum", required_argument, 0, 16},
|
||||
{"use_env", no_argument, 0, 17},
|
||||
- {"help", no_argument, 0, 18},
|
||||
+ {"init", required_argument, 0, 18},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
@@ -4110,6 +4219,9 @@ static void test_sec_cmd_parse(int argc, char *argv[], struct test_sec_option *o
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
+ case 0:
|
||||
+ print_help();
|
||||
+ exit(-1);
|
||||
case 1:
|
||||
option->algclass = CIPHER_CLASS;
|
||||
option->algtype = strtol(optarg, NULL, 0);
|
||||
@@ -4165,8 +4277,8 @@ static void test_sec_cmd_parse(int argc, char *argv[], struct test_sec_option *o
|
||||
option->use_env = 1;
|
||||
break;
|
||||
case 18:
|
||||
- print_help();
|
||||
- exit(-1);
|
||||
+ option->init = strtol(optarg, NULL, 0);
|
||||
+ break;
|
||||
default:
|
||||
SEC_TST_PRT("bad input parameter, exit\n");
|
||||
print_help();
|
||||
@@ -4216,7 +4328,7 @@ static int test_sec_option_convert(struct test_sec_option *option)
|
||||
g_data_fmt = option->sgl_num ? WD_SGL_BUF : WD_FLAT_BUF;
|
||||
g_sgl_num = option->sgl_num;
|
||||
g_stream = option->stream_mode;
|
||||
-
|
||||
+ g_init = option->init;
|
||||
SEC_TST_PRT("set global times is %lld\n", g_times);
|
||||
|
||||
g_thread_num = option->xmulti ? option->xmulti : 1;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
150
0028-uadk-tool-add-init2-test-for-aead-algs.patch
Normal file
150
0028-uadk-tool-add-init2-test-for-aead-algs.patch
Normal file
@ -0,0 +1,150 @@
|
||||
From 607e33147fae795cf3733425701762f5f2104df5 Mon Sep 17 00:00:00 2001
|
||||
From: Hao Fang <fanghao11@huawei.com>
|
||||
Date: Wed, 26 Apr 2023 11:55:30 +0800
|
||||
Subject: [PATCH 28/28] uadk/tool: add init2 test for aead algs
|
||||
|
||||
add testcase cmd --init 2 for init2.
|
||||
default or --init 1 for init.
|
||||
|
||||
Signed-off-by: Hao Fang <fanghao11@huawei.com>
|
||||
---
|
||||
uadk_tool/test/test_sec.c | 102 +++++++++++++++++++++++++++++++++++++-
|
||||
1 file changed, 100 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/uadk_tool/test/test_sec.c b/uadk_tool/test/test_sec.c
|
||||
index 6bd4319..412f764 100644
|
||||
--- a/uadk_tool/test/test_sec.c
|
||||
+++ b/uadk_tool/test/test_sec.c
|
||||
@@ -105,6 +105,17 @@ char *digest_names[MAX_ALGO_PER_TYPE] = {
|
||||
"ccm(aes)", /* --digest 15: for error alg test */
|
||||
};
|
||||
|
||||
+char *aead_names[MAX_ALGO_PER_TYPE] = {
|
||||
+ "ccm(aes)",
|
||||
+ "gcm(aes)",
|
||||
+ "authenc(hmac(sha256),cbc(aes))",
|
||||
+ "ccm(sm4)",
|
||||
+ "gcm(sm4)",
|
||||
+ "authenc(hmac(sha256),cbc(sm4))",
|
||||
+ "sm3", /*--aead 6: for error alg test */
|
||||
+ "authenc(hmac(sha3),cbc(aes))", /* --aead 7: for error alg test */
|
||||
+};
|
||||
+
|
||||
struct sva_bd {
|
||||
char *src;
|
||||
char *dst;
|
||||
@@ -2658,7 +2669,7 @@ static __u32 sched_aead_pick_next_ctx(handle_t h_sched_ctx,
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int init_aead_ctx_config(int type, int mode)
|
||||
+static int aead_init1(int type, int mode)
|
||||
{
|
||||
struct uacce_dev_list *list;
|
||||
struct wd_sched sched;
|
||||
@@ -2708,7 +2719,74 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
-static void aead_uninit_config(void)
|
||||
+static int aead_init2(int type, int mode)
|
||||
+{
|
||||
+ struct wd_ctx_nums *ctx_set_num;
|
||||
+ struct wd_ctx_params cparams;
|
||||
+ int ret;
|
||||
+
|
||||
+ if (g_testalg >= MAX_ALGO_PER_TYPE)
|
||||
+ return -WD_EINVAL;
|
||||
+
|
||||
+ ctx_set_num = calloc(1, sizeof(*ctx_set_num));
|
||||
+ if (!ctx_set_num) {
|
||||
+ WD_ERR("failed to alloc ctx_set_size!\n");
|
||||
+ return -WD_ENOMEM;
|
||||
+ }
|
||||
+
|
||||
+ cparams.op_type_num = 1;
|
||||
+ cparams.ctx_set_num = ctx_set_num;
|
||||
+ cparams.bmp = numa_allocate_nodemask();
|
||||
+ if (!cparams.bmp) {
|
||||
+ WD_ERR("failed to create nodemask!\n");
|
||||
+ ret = -WD_ENOMEM;
|
||||
+ goto out_freectx;
|
||||
+ }
|
||||
+
|
||||
+ numa_bitmask_setall(cparams.bmp);
|
||||
+
|
||||
+ if (mode == CTX_MODE_SYNC)
|
||||
+ ctx_set_num->sync_ctx_num = g_ctxnum;
|
||||
+
|
||||
+ if (mode == CTX_MODE_ASYNC)
|
||||
+ ctx_set_num->async_ctx_num = g_ctxnum;
|
||||
+
|
||||
+ ret = wd_aead_init2_(aead_names[g_testalg], 0, 0, &cparams);
|
||||
+ if (ret)
|
||||
+ goto out_freebmp;
|
||||
+
|
||||
+out_freebmp:
|
||||
+ numa_free_nodemask(cparams.bmp);
|
||||
+
|
||||
+out_freectx:
|
||||
+ free(ctx_set_num);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static int init_aead_ctx_config(int type, int mode)
|
||||
+{
|
||||
+ int ret = -1;
|
||||
+
|
||||
+ switch (g_init) {
|
||||
+ case 0:
|
||||
+ case 1:
|
||||
+ SEC_TST_PRT("uadk entry init1!\n");
|
||||
+ ret = aead_init1(type, mode);
|
||||
+ break;
|
||||
+ case 2:
|
||||
+ SEC_TST_PRT("uadk entry init2!\n");
|
||||
+ ret = aead_init2(type, mode);
|
||||
+ break;
|
||||
+ default:
|
||||
+ SEC_TST_PRT("unsupported aead init-type%u!\n", g_init);
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static void aead_uninit1(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -2723,6 +2801,26 @@ static void aead_uninit_config(void)
|
||||
free(g_ctx_cfg.ctxs);
|
||||
}
|
||||
|
||||
+static void aead_uninit2(void)
|
||||
+{
|
||||
+ wd_aead_uninit2();
|
||||
+}
|
||||
+
|
||||
+static void aead_uninit_config(void)
|
||||
+{
|
||||
+ switch (g_init) {
|
||||
+ case 0:
|
||||
+ case 1:
|
||||
+ aead_uninit1();
|
||||
+ break;
|
||||
+ case 2:
|
||||
+ aead_uninit2();
|
||||
+ break;
|
||||
+ default:
|
||||
+ SEC_TST_PRT("unsupported aead uninit-type%u!\n", g_init);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
int get_aead_resource(struct aead_testvec **alg_tv,
|
||||
int* alg, int* mode, int* dalg, int* dmode)
|
||||
{
|
||||
--
|
||||
2.25.1
|
||||
|
||||
Binary file not shown.
BIN
libwd-2.4.0.tar.gz
Normal file
BIN
libwd-2.4.0.tar.gz
Normal file
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
Name: libwd
|
||||
Summary: User Space Accelerator Development Kit
|
||||
Version: 2.3.37
|
||||
Release: 4
|
||||
Version: 2.4.0
|
||||
Release: 1
|
||||
License: Apache-2.0
|
||||
Source: %{name}-%{version}.tar.gz
|
||||
Vendor: Huawei Corporation
|
||||
@ -14,10 +14,34 @@ BuildRequires: numactl-devel, compat-openssl11-devel, zlib-devel
|
||||
BuildRequires: automake, autoconf, libtool
|
||||
BuildRequires: gcc, make
|
||||
ExclusiveArch: aarch64
|
||||
Patch0001: 0001-uadk-v1-ecc-bugfix-buffer-overwritten-of-sm2-decrypt.patch
|
||||
Patch0002: 0002-uadk-ecc-cleanup-sm2-dec-out-code.patch
|
||||
Patch0003: 0003-uadk-v1-ecc-bugfix-incorrect-parameter-length.patch
|
||||
Patch0004: 0004-uadk-ecc-bugfix-incorrect-parameter-length.patch
|
||||
Patch0001: 0001-wd-Fix-GCC-12-build-issue.patch
|
||||
Patch0002: 0002-digest-add-the-0-byte-packet-checking-for-long-hash.patch
|
||||
Patch0003: 0003-drv-hisi_sec-modify-the-hardware-name.patch
|
||||
Patch0004: 0004-uadk-Add-driver-dynamic-loading-function.patch
|
||||
Patch0005: 0005-uadk-update-scheduler-for-dynamic-loading.patch
|
||||
Patch0006: 0006-uadk-improve-the-dynamic-loading-public-framework.patch
|
||||
Patch0007: 0007-uadk-doc-adding-dynamically-loaded-design-documents.patch
|
||||
Patch0008: 0008-uadk-added-ability-to-query-supported-algorithms.patch
|
||||
Patch0009: 0009-uadk-zip-Adapt-the-zip-module-to-the-dynamic-loading.patch
|
||||
Patch0010: 0010-uadk-libs-update-compile-options.patch
|
||||
Patch0011: 0011-uadk-ecc-add-the-init2-interface-for-ecc.patch
|
||||
Patch0012: 0012-uadk-rsa-add-the-init2-interface-for-rsa.patch
|
||||
Patch0013: 0013-uadk-dh-add-the-init2-interface-for-dh.patch
|
||||
Patch0014: 0014-uadk-ecc-adapt-the-ecc-module-to-the-dynamic-loading.patch
|
||||
Patch0015: 0015-uadk-rsa-adapt-the-rsa-module-to-the-dynamic-loading.patch
|
||||
Patch0016: 0016-uadk-dh-adapt-the-dh-module-to-the-dynamic-loading-f.patch
|
||||
Patch0017: 0017-uadk-the-description-document-of-the-uadk-log-is-add.patch
|
||||
Patch0018: 0018-uadk-the-features-of-testing-the-correctness-is-adde.patch
|
||||
Patch0019: 0019-uadk-cipher-add-the-init2-interface-for-cipher.patch
|
||||
Patch0020: 0020-uadk-sec-adapt-the-sec-module-to-the-dynamic-loading.patch
|
||||
Patch0021: 0021-uadk-fix-dlsym-problem.patch
|
||||
Patch0022: 0022-uadk-drv-fix-drv_name-for-sec2.patch
|
||||
Patch0023: 0023-uadk-digest-introduce-the-init2-interface-for-digest.patch
|
||||
Patch0024: 0024-uadk-aead-introduce-the-init2-interface-for-aead.patch
|
||||
Patch0025: 0025-uadk-digest-adapt-the-module-dynamic-load-for-the-di.patch
|
||||
Patch0026: 0026-uadk-aead-adadpt-the-module-dynamic-load-for-aead-al.patch
|
||||
Patch0027: 0027-uadk-tool-add-init2-test-for-digest-algs.patch
|
||||
Patch0028: 0028-uadk-tool-add-init2-test-for-aead-algs.patch
|
||||
|
||||
%description
|
||||
This package contains the User Space Accelerator Library
|
||||
@ -61,7 +85,6 @@ cp include/wd_aead.h ${RPM_BUILD_ROOT}/usr/include/uadk
|
||||
cp include/wd_ecc.h ${RPM_BUILD_ROOT}/usr/include/uadk
|
||||
cp include/wd_ecc_curve.h ${RPM_BUILD_ROOT}/usr/include/uadk
|
||||
cp include/wd_alg_common.h ${RPM_BUILD_ROOT}/usr/include/uadk
|
||||
cp include/wd_common.h ${RPM_BUILD_ROOT}/usr/include/uadk
|
||||
cp include/wd_sched.h ${RPM_BUILD_ROOT}/usr/include/uadk
|
||||
cp v1/uacce.h ${RPM_BUILD_ROOT}/usr/include/uadk/v1
|
||||
cp v1/wd.h ${RPM_BUILD_ROOT}/usr/include/uadk/v1
|
||||
@ -103,7 +126,6 @@ rm -rf ${RPM_BUILD_ROOT}
|
||||
/usr/include/uadk/wd_ecc.h
|
||||
/usr/include/uadk/wd_ecc_curve.h
|
||||
/usr/include/uadk/wd_alg_common.h
|
||||
/usr/include/uadk/wd_common.h
|
||||
/usr/include/uadk/wd_sched.h
|
||||
/usr/include/uadk/v1/uacce.h
|
||||
/usr/include/uadk/v1/wd.h
|
||||
@ -174,6 +196,9 @@ fi
|
||||
/sbin/ldconfig
|
||||
|
||||
%changelog
|
||||
* Fri May 5 2023 JiangShui Yang <yangjiangshui@h-partners.com> 2.4.0-1
|
||||
- libwd: update the source code to 2.4.0
|
||||
|
||||
* Mon Mar 20 2023 JiangShui Yang <yangjiangshui@h-partners.com> 2.3.37-4
|
||||
- libwd: modify the build requirement
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user