!52 libwd: update source code to 2.3.37
From: @youngersun Reviewed-by: @hao-fang Signed-off-by: @hao-fang
This commit is contained in:
commit
1f4d147065
@ -1,213 +0,0 @@
|
||||
From c1e75c6c27ea54dec9e31223af49e33aa0d38490 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Mon, 13 Dec 2021 18:55:32 +0800
|
||||
Subject: [PATCH 01/28] uadk/digest - add stream mode for digest sync
|
||||
|
||||
Support the sec digest steam mode. Using the session to store
|
||||
the stream BD state, using the iv_bytes to notify the BD state
|
||||
from message. So one session only supports one stream. User
|
||||
can use the has_next flag to indicate whether there is any
|
||||
packet to be input.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 50 ++++++++++++++++++++-----------------
|
||||
include/drv/wd_digest_drv.h | 2 ++
|
||||
wd_digest.c | 20 ++++++++++++---
|
||||
3 files changed, 46 insertions(+), 26 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index e43ded2..2fd23f3 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -73,6 +73,8 @@
|
||||
/* The max BD data length is 16M-512B */
|
||||
#define MAX_INPUT_DATA_LEN 0xFFFE00
|
||||
#define MAX_CCM_AAD_LEN 65279
|
||||
+#define SHA1_ALIGN_SZ 64
|
||||
+#define SHA512_ALIGN_SZ 128
|
||||
|
||||
#define AUTHPAD_OFFSET 2
|
||||
#define AUTHTYPE_OFFSET 6
|
||||
@@ -1229,31 +1231,24 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
|
||||
static void qm_fill_digest_long_bd(struct wd_digest_msg *msg,
|
||||
struct hisi_sec_sqe *sqe)
|
||||
{
|
||||
- struct wd_digest_tag *digest_tag = (void *)(uintptr_t)msg->usr_data;
|
||||
__u64 total_bits;
|
||||
|
||||
if (msg->has_next && (msg->iv_bytes == 0)) {
|
||||
/* LONG BD FIRST */
|
||||
sqe->ai_apd_cs = AI_GEN_INNER;
|
||||
sqe->ai_apd_cs |= AUTHPAD_NOPAD << AUTHPAD_OFFSET;
|
||||
- msg->iv_bytes = msg->out_bytes;
|
||||
} else if (msg->has_next && (msg->iv_bytes != 0)) {
|
||||
/* LONG BD 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;
|
||||
- msg->iv_bytes = msg->out_bytes;
|
||||
} else if (!msg->has_next && (msg->iv_bytes != 0)) {
|
||||
/* LONG BD END */
|
||||
sqe->ai_apd_cs = AI_GEN_IVIN_ADDR;
|
||||
sqe->ai_apd_cs |= AUTHPAD_PAD << AUTHPAD_OFFSET;
|
||||
sqe->type2.a_ivin_addr = sqe->type2.mac_addr;
|
||||
- total_bits = digest_tag->long_data_len * BYTE_BITS;
|
||||
+ total_bits = msg->long_data_len * BYTE_BITS;
|
||||
sqe->type2.long_a_data_len = total_bits;
|
||||
- msg->iv_bytes = 0;
|
||||
- } else {
|
||||
- /* SHORT BD */
|
||||
- msg->iv_bytes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1282,21 +1277,37 @@ static void parse_digest_bd2(struct hisi_sec_sqe *sqe, struct wd_digest_msg *rec
|
||||
#endif
|
||||
}
|
||||
|
||||
-static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
|
||||
+static int digest_long_bd_check(struct wd_digest_msg *msg)
|
||||
{
|
||||
- if (type == BD_TYPE2 && msg->in_bytes == 0) {
|
||||
- WD_ERR("digest bd2 not supports 0 packet!\n");
|
||||
+ if (msg->alg >= WD_DIGEST_SHA512 && msg->in_bytes % SHA512_ALIGN_SZ)
|
||||
+ return -WD_EINVAL;
|
||||
+ else if (msg->in_bytes % SHA1_ALIGN_SZ)
|
||||
+ 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 == 0))) {
|
||||
+ WD_ERR("kunpeng 920, digest mode not support 0 size!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(msg->in_bytes > MAX_INPUT_DATA_LEN)) {
|
||||
- WD_ERR("failed to check digest input data length!\n");
|
||||
+ WD_ERR("input data length is too long, size:%u!\n", msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (unlikely(msg->out_bytes & WORD_ALIGNMENT_MASK)) {
|
||||
- WD_ERR("failed to check digest out length!\n");
|
||||
- return -WD_EINVAL;
|
||||
+ if (msg->has_next) {
|
||||
+ ret = digest_long_bd_check(msg);
|
||||
+ if (ret) {
|
||||
+ WD_ERR("input data isn't aligned, size:%u!\n", msg->in_bytes);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1435,31 +1446,24 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
|
||||
static void qm_fill_digest_long_bd3(struct wd_digest_msg *msg,
|
||||
struct hisi_sec_sqe3 *sqe)
|
||||
{
|
||||
- struct wd_digest_tag *digest_tag = (void *)(uintptr_t)msg->usr_data;
|
||||
__u64 total_bits;
|
||||
|
||||
if (msg->has_next && (msg->iv_bytes == 0)) {
|
||||
/* LONG BD FIRST */
|
||||
sqe->auth_mac_key |= AI_GEN_INNER << SEC_AI_GEN_OFFSET_V3;
|
||||
sqe->stream_scene.stream_auth_pad = AUTHPAD_NOPAD;
|
||||
- msg->iv_bytes = msg->out_bytes;
|
||||
} else if (msg->has_next && (msg->iv_bytes != 0)) {
|
||||
/* LONG BD 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;
|
||||
- msg->iv_bytes = msg->out_bytes;
|
||||
} else if (!msg->has_next && (msg->iv_bytes != 0)) {
|
||||
/* LONG BD END */
|
||||
sqe->auth_mac_key |= AI_GEN_IVIN_ADDR << SEC_AI_GEN_OFFSET_V3;
|
||||
sqe->stream_scene.stream_auth_pad = AUTHPAD_PAD;
|
||||
sqe->auth_ivin.a_ivin_addr = sqe->mac_addr;
|
||||
- total_bits = digest_tag->long_data_len * BYTE_BITS;
|
||||
+ total_bits = msg->long_data_len * BYTE_BITS;
|
||||
sqe->stream_scene.long_a_data_len = total_bits;
|
||||
- msg->iv_bytes = 0;
|
||||
- } else {
|
||||
- /* SHORT BD */
|
||||
- msg->iv_bytes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/include/drv/wd_digest_drv.h b/include/drv/wd_digest_drv.h
|
||||
index 8ccf291..ac3b028 100644
|
||||
--- a/include/drv/wd_digest_drv.h
|
||||
+++ b/include/drv/wd_digest_drv.h
|
||||
@@ -45,6 +45,8 @@ struct wd_digest_msg {
|
||||
__u8 *in;
|
||||
/* output data pointer */
|
||||
__u8 *out;
|
||||
+ /* total of data for stream mode */
|
||||
+ __u64 long_data_len;
|
||||
};
|
||||
|
||||
struct wd_digest_driver {
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index 22aa98e..c110f7b 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -46,6 +46,10 @@ struct wd_digest_sess {
|
||||
unsigned char key[MAX_HMAC_KEY_SIZE];
|
||||
__u32 key_bytes;
|
||||
void *sched_key;
|
||||
+ /* Notify the BD state */
|
||||
+ int state;
|
||||
+ /* Total of data for stream mode */
|
||||
+ __u64 long_data_len;
|
||||
};
|
||||
|
||||
struct wd_env_config wd_digest_env_config;
|
||||
@@ -286,11 +290,19 @@ static void fill_request_msg(struct wd_digest_msg *msg,
|
||||
msg->in_bytes = req->in_bytes;
|
||||
msg->out = req->out;
|
||||
msg->out_bytes = req->out_bytes;
|
||||
- msg->has_next = req->has_next;
|
||||
msg->data_fmt = req->data_fmt;
|
||||
+ msg->has_next = req->has_next;
|
||||
+ sess->long_data_len += req->in_bytes;
|
||||
+ msg->long_data_len = sess->long_data_len;
|
||||
+ /* To store the stream bd state */
|
||||
+ msg->iv_bytes = sess->state;
|
||||
+ if (req->has_next == 0) {
|
||||
+ sess->long_data_len = 0;
|
||||
+ sess->state = 0;
|
||||
+ }
|
||||
}
|
||||
|
||||
-static int send_recv_sync(struct wd_ctx_internal *ctx,
|
||||
+static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *dsess,
|
||||
struct wd_digest_msg *msg)
|
||||
{
|
||||
__u64 recv_cnt = 0;
|
||||
@@ -320,6 +332,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx,
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
+ if (msg->has_next)
|
||||
+ dsess->state = msg->out_bytes;
|
||||
} while (ret < 0);
|
||||
|
||||
out:
|
||||
@@ -353,7 +367,7 @@ int wd_do_digest_sync(handle_t h_sess, struct wd_digest_req *req)
|
||||
return ret;
|
||||
|
||||
ctx = config->ctxs + idx;
|
||||
- ret = send_recv_sync(ctx, &msg);
|
||||
+ ret = send_recv_sync(ctx, dsess, &msg);
|
||||
req->state = msg.result;
|
||||
|
||||
return ret;
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,508 +0,0 @@
|
||||
From 08d633649d4a3c557bf042241e3953c3dd5cf586 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Thu, 9 Sep 2021 19:18:05 +0800
|
||||
Subject: [PATCH 02/28] test/digest: support the digest stream mode
|
||||
|
||||
Test the digest stream mode by compare to no stream mode.
|
||||
Tools supports the multiple thread testing.
|
||||
|
||||
For example:
|
||||
test_hisi_sec --digest 0 --sync --optype 3 --pktlen 1024 \
|
||||
--keylen 16 --times 1 --multi 2
|
||||
more details:
|
||||
test_hisi_sec --help
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
test/hisi_sec_test/test_hisi_sec.c | 370 ++++++++++++++++++++++++++++-
|
||||
test/hisi_sec_test/test_hisi_sec.h | 4 +-
|
||||
2 files changed, 360 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/test/hisi_sec_test/test_hisi_sec.c b/test/hisi_sec_test/test_hisi_sec.c
|
||||
index a2dba05..e1521f6 100644
|
||||
--- a/test/hisi_sec_test/test_hisi_sec.c
|
||||
+++ b/test/hisi_sec_test/test_hisi_sec.c
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/syscall.h>
|
||||
+#include <stdbool.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/time.h>
|
||||
#include <getopt.h>
|
||||
@@ -53,6 +54,8 @@ static unsigned int g_data_fmt = WD_FLAT_BUF;
|
||||
static unsigned int g_sgl_num = 0;
|
||||
static pthread_spinlock_t lock = 0;
|
||||
|
||||
+static struct hash_testvec g_long_hash_tv;
|
||||
+
|
||||
char *skcipher_names[MAX_ALGO_PER_TYPE] =
|
||||
{"ecb(aes)", "cbc(aes)", "xts(aes)", "ofb(aes)", "cfb(aes)", "ecb(des3_ede)",
|
||||
"cbc(des3_ede)", "cbc(sm4)", "xts(sm4)", "ofb(sm4)", "cfb(sm4)", "ecb(sm4)", NULL,};
|
||||
@@ -1509,7 +1512,7 @@ int get_digest_resource(struct hash_testvec **alg_tv, int* alg, int* mode)
|
||||
}
|
||||
if (g_ivlen == 1) {
|
||||
tmp_tv = tv;
|
||||
- tv = &long_hash_tv_template[0];
|
||||
+ tv = &g_long_hash_tv;
|
||||
tv->dsize = tmp_tv->dsize;
|
||||
} else if (g_ivlen == 2) {
|
||||
tmp_tv = tv;
|
||||
@@ -1587,7 +1590,7 @@ static int sec_digest_sync_once(void)
|
||||
|
||||
/* if mode is HMAC, should set key */
|
||||
if (setup.mode == WD_DIGEST_HMAC) {
|
||||
- ret = wd_digest_set_key(h_sess, (const __u8*)tv->key, tv->ksize);
|
||||
+ ret = wd_digest_set_key(h_sess, (const __u8 *)tv->key, tv->ksize);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("sess set key failed!\n");
|
||||
goto out_key;
|
||||
@@ -1622,6 +1625,311 @@ out_src:
|
||||
return ret;
|
||||
}
|
||||
|
||||
+static int sec_digest_sync_stream_cmp(void)
|
||||
+{
|
||||
+ struct wd_digest_sess_setup setup = {0};
|
||||
+ struct hash_testvec *tv = NULL;
|
||||
+ handle_t h_sess = 0;
|
||||
+ struct wd_digest_req req;
|
||||
+ unsigned long cnt = g_times;
|
||||
+ int ret;
|
||||
+ size_t unit_sz;
|
||||
+
|
||||
+ /* config setup */
|
||||
+ ret = init_digest_ctx_config(CTX_TYPE_ENCRYPT, CTX_MODE_SYNC);
|
||||
+ if (ret) {
|
||||
+ SEC_TST_PRT("Fail to init sigle ctx config!\n");
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ /* config arg */
|
||||
+ memset(&req, 0, sizeof(struct wd_digest_req));
|
||||
+ get_digest_resource(&tv, (int *)&setup.alg, (int *)&setup.mode);
|
||||
+
|
||||
+ unit_sz = cal_unit_sz(BUFF_SIZE * 8, g_sgl_num);
|
||||
+ req.in = create_buf(g_data_fmt, BUFF_SIZE * 8, unit_sz);
|
||||
+ if (!req.in) {
|
||||
+ ret = -ENOMEM;
|
||||
+ goto out_src;
|
||||
+ }
|
||||
+
|
||||
+ req.in_bytes = tv->psize;
|
||||
+ copy_mem(g_data_fmt, req.in, WD_FLAT_BUF,
|
||||
+ (void *)tv->plaintext, tv->psize);
|
||||
+
|
||||
+ req.out = create_buf(WD_FLAT_BUF, BUFF_SIZE, unit_sz);
|
||||
+ if (!req.out) {
|
||||
+ ret = -ENOMEM;
|
||||
+ goto out_dst;
|
||||
+ }
|
||||
+
|
||||
+ req.out_buf_bytes = BUFF_SIZE;
|
||||
+ req.out_bytes = tv->dsize;
|
||||
+ req.data_fmt = g_data_fmt;
|
||||
+ req.has_next = 0;
|
||||
+
|
||||
+ h_sess = wd_digest_alloc_sess(&setup);
|
||||
+ if (!h_sess) {
|
||||
+ ret = -EINVAL;
|
||||
+ goto out_sess;
|
||||
+ }
|
||||
+
|
||||
+ /* if mode is HMAC, should set key */
|
||||
+ ret = wd_digest_set_key(h_sess, (const __u8 *)tv->key, tv->ksize);
|
||||
+ if (ret) {
|
||||
+ SEC_TST_PRT("sess set key failed!\n");
|
||||
+ goto out_key;
|
||||
+ }
|
||||
+
|
||||
+ while (cnt) {
|
||||
+ ret = wd_do_digest_sync(h_sess, &req);
|
||||
+ cnt--;
|
||||
+ }
|
||||
+
|
||||
+ SEC_TST_PRT("one hash BD dump the out memory, cmp the stream mode:\n");
|
||||
+ dump_mem(WD_FLAT_BUF, req.out, 16);
|
||||
+
|
||||
+out_key:
|
||||
+ wd_digest_free_sess(h_sess);
|
||||
+out_sess:
|
||||
+ free_buf(WD_FLAT_BUF, req.out);
|
||||
+out_dst:
|
||||
+ free_buf(g_data_fmt, req.in);
|
||||
+out_src:
|
||||
+ digest_uninit_config();
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static int sec_digest_sync_stream_mode(void)
|
||||
+{
|
||||
+ struct wd_digest_sess_setup setup;
|
||||
+ struct hash_testvec *tv = NULL;
|
||||
+ handle_t h_sess = 0;
|
||||
+ struct wd_digest_req req;
|
||||
+ unsigned long cnt = g_times;
|
||||
+ int ret, data_len;
|
||||
+ void *bak_in = NULL;
|
||||
+
|
||||
+ /* config setup */
|
||||
+ ret = init_digest_ctx_config(CTX_TYPE_ENCRYPT, CTX_MODE_SYNC);
|
||||
+ if (ret) {
|
||||
+ SEC_TST_PRT("Fail to init sigle ctx config!\n");
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ /* config arg */
|
||||
+ memset(&req, 0, sizeof(struct wd_digest_req));
|
||||
+ get_digest_resource(&tv, (int *)&setup.alg, (int *)&setup.mode);
|
||||
+
|
||||
+ req.in = malloc(BUFF_SIZE * 8);
|
||||
+ if (!req.in) {
|
||||
+ SEC_TST_PRT("req src in mem malloc failed!\n");
|
||||
+ ret = -1;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ bak_in = req.in;
|
||||
+
|
||||
+ memcpy(req.in, tv->plaintext, tv->psize);
|
||||
+ req.in_bytes = tv->psize;
|
||||
+
|
||||
+ req.out = malloc(BUFF_SIZE);
|
||||
+ if (!req.out) {
|
||||
+ SEC_TST_PRT("req dst out mem malloc failed!\n");
|
||||
+ ret = -1;
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ req.out_buf_bytes = BUFF_SIZE;
|
||||
+ req.out_bytes = tv->dsize;
|
||||
+ req.data_fmt = g_data_fmt;
|
||||
+ req.has_next = 0;
|
||||
+
|
||||
+ h_sess = wd_digest_alloc_sess(&setup);
|
||||
+ if (!h_sess) {
|
||||
+ ret = -1;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ data_len = tv->psize;
|
||||
+
|
||||
+ /* if mode is HMAC, should set key */
|
||||
+ ret = wd_digest_set_key(h_sess, (const __u8 *)tv->key, tv->ksize);
|
||||
+ if (ret) {
|
||||
+ SEC_TST_PRT("sess set key failed!\n");
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+ while (cnt) {
|
||||
+ do {
|
||||
+ if (data_len > 256) { // soft block size
|
||||
+ req.in_bytes = 256;
|
||||
+ data_len -= 256;
|
||||
+ req.has_next = 1;
|
||||
+ } else {
|
||||
+ req.has_next = 0;
|
||||
+ req.in_bytes = data_len;
|
||||
+ }
|
||||
+ ret = wd_do_digest_sync(h_sess, &req);
|
||||
+
|
||||
+ if (ret)
|
||||
+ goto out;
|
||||
+
|
||||
+ if (req.has_next != 0)
|
||||
+ req.in += 256;
|
||||
+ else
|
||||
+ break;
|
||||
+ } while (true);
|
||||
+ data_len = tv->psize;
|
||||
+ req.has_next = 0;
|
||||
+ req.in = bak_in;
|
||||
+ memcpy(req.in, tv->plaintext, tv->psize);
|
||||
+ cnt--;
|
||||
+ }
|
||||
+ SEC_TST_PRT("long hash BD dump the out memory:--------->:\n");
|
||||
+ dump_mem(g_data_fmt, req.out, 16);
|
||||
+
|
||||
+out:
|
||||
+ free(req.out);
|
||||
+ free(req.in);
|
||||
+ if (h_sess)
|
||||
+ wd_digest_free_sess(h_sess);
|
||||
+
|
||||
+ digest_uninit_config();
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void *digest_sync_stream_mode_send_td(void *data)
|
||||
+{
|
||||
+ int thread_id = (int)syscall(__NR_gettid);
|
||||
+ struct wd_digest_sess_setup setup = {0};
|
||||
+ struct hash_testvec *tv = NULL;
|
||||
+ unsigned long cnt = g_times;
|
||||
+ struct wd_digest_req req;
|
||||
+ int ret, data_len;
|
||||
+ void *bak_in = NULL;
|
||||
+ handle_t h_sess = 0;
|
||||
+
|
||||
+ get_digest_resource(&tv, (int *)&setup.alg, (int *)&setup.mode);
|
||||
+
|
||||
+ h_sess = wd_digest_alloc_sess(&setup);
|
||||
+ if (!h_sess) {
|
||||
+ ret = -EINVAL;
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ /* if mode is HMAC, should set key */
|
||||
+ ret = wd_digest_set_key(h_sess, (const __u8 *)tv->key, tv->ksize);
|
||||
+ if (ret) {
|
||||
+ SEC_TST_PRT("sess set key failed!\n");
|
||||
+ goto out_key;
|
||||
+ }
|
||||
+
|
||||
+ /* config arg */
|
||||
+ memset(&req, 0, sizeof(struct wd_digest_req));
|
||||
+
|
||||
+ req.in = malloc(BUFF_SIZE * 8);
|
||||
+ if (!req.in) {
|
||||
+ SEC_TST_PRT("req src in mem malloc failed!\n");
|
||||
+ ret = -1;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ bak_in = req.in;
|
||||
+
|
||||
+ memcpy(req.in, tv->plaintext, tv->psize);
|
||||
+ req.in_bytes = tv->psize;
|
||||
+
|
||||
+ req.out = malloc(BUFF_SIZE);
|
||||
+ if (!req.out) {
|
||||
+ SEC_TST_PRT("req dst out mem malloc failed!\n");
|
||||
+ ret = -1;
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ req.out_buf_bytes = BUFF_SIZE;
|
||||
+ req.out_bytes = tv->dsize;
|
||||
+ req.data_fmt = g_data_fmt;
|
||||
+ req.has_next = 0;
|
||||
+
|
||||
+ data_len = tv->psize;
|
||||
+
|
||||
+ while (cnt) {
|
||||
+ do {
|
||||
+ if (data_len > 256) { // soft block size
|
||||
+ req.in_bytes = 256;
|
||||
+ data_len -= 256;
|
||||
+ req.has_next = 1;
|
||||
+ } else {
|
||||
+ req.has_next = 0;
|
||||
+ req.in_bytes = data_len;
|
||||
+ }
|
||||
+ ret = wd_do_digest_sync(h_sess, &req);
|
||||
+
|
||||
+ if (ret)
|
||||
+ goto out;
|
||||
+
|
||||
+ if (req.has_next != 0)
|
||||
+ req.in += 256;
|
||||
+ else
|
||||
+ break;
|
||||
+
|
||||
+ } while (true);
|
||||
+ data_len = tv->psize;
|
||||
+ req.has_next = 0;
|
||||
+ req.in = bak_in;
|
||||
+ memcpy(req.in, tv->plaintext, tv->psize);
|
||||
+ cnt--;
|
||||
+ }
|
||||
+ SEC_TST_PRT("Pid - %d, thread-id - %d, long hash BD dump the out memory:\n", getpid(), thread_id);
|
||||
+ dump_mem(g_data_fmt, req.out, 16);
|
||||
+out_key:
|
||||
+ wd_digest_free_sess(h_sess);
|
||||
+out:
|
||||
+ if (req.out)
|
||||
+ free(req.out);
|
||||
+ if (bak_in)
|
||||
+ free(bak_in);
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
+static int sec_digest_sync_stream_mode_multi(void)
|
||||
+{
|
||||
+ static pthread_t sendtd[64];
|
||||
+ thread_data_d td_data;
|
||||
+ int i, ret;
|
||||
+
|
||||
+ /* config setup */
|
||||
+ ret = init_digest_ctx_config(CTX_TYPE_ENCRYPT, CTX_MODE_SYNC);
|
||||
+ if (ret) {
|
||||
+ SEC_TST_PRT("Fail to init sigle ctx config!\n");
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ /* send thread */
|
||||
+ td_data.send_num = g_times;
|
||||
+ td_data.recv_num = g_times;
|
||||
+ for (i = 0; i < g_thread_num; i++) {
|
||||
+ ret = pthread_create(&sendtd[i], NULL, digest_sync_stream_mode_send_td, &td_data);
|
||||
+ if (ret) {
|
||||
+ SEC_TST_PRT("Create send thread fail!\n");
|
||||
+ goto out_thr;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ /* join thread */
|
||||
+ for (i = 0; i < g_thread_num; i++) {
|
||||
+ ret = pthread_join(sendtd[i], NULL);
|
||||
+ if (ret) {
|
||||
+ SEC_TST_PRT("Join sendtd thread fail!\n");
|
||||
+ goto out_thr;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+out_thr:
|
||||
+ digest_uninit_config();
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
static void *digest_async_cb(void *data)
|
||||
{
|
||||
// struct wd_digest_req *req = (struct wd_digest_req *)data;
|
||||
@@ -1791,7 +2099,7 @@ static int sec_digest_async_once(void)
|
||||
|
||||
/* if mode is HMAC, should set key */
|
||||
if (setup.mode == WD_DIGEST_HMAC) {
|
||||
- ret = wd_digest_set_key(h_sess, (const __u8*)tv->key, tv->ksize);
|
||||
+ ret = wd_digest_set_key(h_sess, (const __u8 *)tv->key, tv->ksize);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("sess set key failed!\n");
|
||||
goto out_key;
|
||||
@@ -1895,7 +2203,7 @@ static int sec_digest_sync_multi(void)
|
||||
|
||||
/* if mode is HMAC, should set key */
|
||||
if (setup.mode == WD_DIGEST_HMAC) {
|
||||
- ret = wd_digest_set_key(h_sess, (const __u8*)tv->key, tv->ksize);
|
||||
+ ret = wd_digest_set_key(h_sess, (const __u8 *)tv->key, tv->ksize);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("sess set key failed!\n");
|
||||
goto out_key;
|
||||
@@ -1998,7 +2306,7 @@ static int sec_digest_async_multi(void)
|
||||
|
||||
/* if mode is HMAC, should set key */
|
||||
if (setup.mode == WD_DIGEST_HMAC) {
|
||||
- ret = wd_digest_set_key(h_sess, (const __u8*)tv->key, tv->ksize);
|
||||
+ ret = wd_digest_set_key(h_sess, (const __u8 *)tv->key, tv->ksize);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("sess set key failed!\n");
|
||||
goto out;
|
||||
@@ -3471,7 +3779,7 @@ 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(" test_hisi_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");
|
||||
@@ -3498,6 +3806,7 @@ static void print_help(void)
|
||||
SEC_TST_PRT(" [--optype]:\n");
|
||||
SEC_TST_PRT(" 0 : encryption operation or normal mode for hash\n");
|
||||
SEC_TST_PRT(" 1 : decryption operation or hmac mode for hash\n");
|
||||
+ SEC_TST_PRT(" 3 : hmac mode for stream hash mode\n");
|
||||
SEC_TST_PRT(" [--pktlen]:\n");
|
||||
SEC_TST_PRT(" set the length of BD message in bytes\n");
|
||||
SEC_TST_PRT(" [--keylen]:\n");
|
||||
@@ -3514,10 +3823,12 @@ static void print_help(void)
|
||||
SEC_TST_PRT(" the number of QP queues 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(" --pktlen 16 --keylen 16 --times 1 --multi 1\n");
|
||||
- SEC_TST_PRT(" ./test_hisi_sec --perf --sync --pktlen 1024 --block 1024 \n");
|
||||
- SEC_TST_PRT(" --blknum 100000 --times 10000 --multi 1 --ctxnum 1\n");
|
||||
+ SEC_TST_PRT(" ./test_hisi_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 3\n");
|
||||
+ SEC_TST_PRT("--pktlen 16 --keylen 16 --times 1 --multi 2\n");
|
||||
+ SEC_TST_PRT(" ./test_hisi_sec --perf --sync --pktlen 1024 --block 1024\n");
|
||||
+ SEC_TST_PRT("--blknum 100000 --times 10000 --multi 1 --ctxnum 1\n");
|
||||
SEC_TST_PRT("UPDATE:2020-11-06\n");
|
||||
}
|
||||
|
||||
@@ -3684,6 +3995,28 @@ static int test_sec_default_case()
|
||||
return test_sec_cipher_sync_once();
|
||||
}
|
||||
|
||||
+static void long_hash_data_init(void)
|
||||
+{
|
||||
+ g_long_hash_tv.plaintext = malloc(g_pktlen);
|
||||
+ if (g_long_hash_tv.plaintext == NULL)
|
||||
+ return;
|
||||
+
|
||||
+ g_long_hash_tv.psize = g_pktlen;
|
||||
+
|
||||
+ g_long_hash_tv.key = malloc(16);
|
||||
+ if (g_long_hash_tv.key == NULL) {
|
||||
+ free(g_long_hash_tv.plaintext);
|
||||
+ return;
|
||||
+ }
|
||||
+ g_long_hash_tv.ksize = 16;
|
||||
+}
|
||||
+
|
||||
+static void long_hash_data_uninit(void)
|
||||
+{
|
||||
+ free(g_long_hash_tv.plaintext);
|
||||
+ free(g_long_hash_tv.key);
|
||||
+}
|
||||
+
|
||||
static int test_sec_run(__u32 sync_mode, __u32 alg_class)
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -3698,13 +4031,26 @@ static int test_sec_run(__u32 sync_mode, __u32 alg_class)
|
||||
SEC_TST_PRT("currently cipher test is synchronize once, one thread!\n");
|
||||
}
|
||||
} else if (alg_class == DIGEST_CLASS) {
|
||||
- if (g_thread_num > 1) {
|
||||
- SEC_TST_PRT("currently digest test is synchronize multi -%d threads!\n", g_thread_num);
|
||||
+ SEC_TST_PRT("hisi_sec HMAC-digest mode.\n");
|
||||
+ long_hash_data_init();
|
||||
+ if (g_thread_num > 1 && g_direction != 3) {
|
||||
+ SEC_TST_PRT("currently digest test is synchronize psize:%u, multi -%d threads!\n", g_pktlen, g_thread_num);
|
||||
ret = sec_digest_sync_multi();
|
||||
+ } else if (g_thread_num > 1 && g_direction == 3) {
|
||||
+ ret = sec_digest_sync_stream_mode_multi();
|
||||
+ (void)sec_digest_sync_stream_cmp();
|
||||
+ SEC_TST_PRT("currently digest long hash mode, psize:%u, multi thread!\n", g_pktlen);
|
||||
+ } else if (g_thread_num == 1 && g_direction == 3) {
|
||||
+ if (g_ivlen == 1) {
|
||||
+ ret = sec_digest_sync_stream_mode();
|
||||
+ (void)sec_digest_sync_stream_cmp();
|
||||
+ SEC_TST_PRT("currently digest long hash mode, psize:%u, one thread!\n", g_pktlen);
|
||||
+ }
|
||||
} else {
|
||||
ret = sec_digest_sync_once();
|
||||
SEC_TST_PRT("currently digest test is synchronize once, one thread!\n");
|
||||
}
|
||||
+ long_hash_data_uninit();
|
||||
} else if (alg_class == AEAD_CLASS) {
|
||||
if (g_thread_num > 1) {
|
||||
SEC_TST_PRT("currently aead test is synchronize multi -%d threads!\n", g_thread_num);
|
||||
diff --git a/test/hisi_sec_test/test_hisi_sec.h b/test/hisi_sec_test/test_hisi_sec.h
|
||||
index f0d0812..defd3c4 100644
|
||||
--- a/test/hisi_sec_test/test_hisi_sec.h
|
||||
+++ b/test/hisi_sec_test/test_hisi_sec.h
|
||||
@@ -41,8 +41,8 @@ struct cipher_testvec {
|
||||
};
|
||||
|
||||
struct hash_testvec {
|
||||
- const char *key;
|
||||
- const char *plaintext;
|
||||
+ char *key;
|
||||
+ char *plaintext;
|
||||
const char *digest;
|
||||
unsigned int psize;
|
||||
unsigned short ksize;
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,82 +0,0 @@
|
||||
From a119cf2838ee41078c452f93d5b48bea2561dfcc Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Tue, 14 Dec 2021 19:24:47 +0800
|
||||
Subject: [PATCH 03/28] aead/cipher/digest: fix some code issues
|
||||
|
||||
1. Due to the schedule already has the a checking for poll
|
||||
policy, so delete the checking for poll policy in poll.
|
||||
2. modify some comments.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
wd_aead.c | 9 ++-------
|
||||
wd_cipher.c | 5 -----
|
||||
wd_digest.c | 5 -----
|
||||
3 files changed, 2 insertions(+), 17 deletions(-)
|
||||
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index 54bd28d..f93f791 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -367,12 +367,12 @@ static int aead_param_check(struct wd_aead_sess *sess,
|
||||
static int aead_init_check(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
if (!config || !sched) {
|
||||
- WD_ERR("failed to check aead init input param!\n");
|
||||
+ WD_ERR("wd aead config or sched is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (!wd_is_sva(config->ctxs[0].ctx)) {
|
||||
- WD_ERR("failed to system is SVA mode!\n");
|
||||
+ WD_ERR("err, non sva, please check system!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -660,11 +660,6 @@ int wd_aead_poll(__u32 expt, __u32 *count)
|
||||
handle_t h_ctx = wd_aead_setting.sched.h_sched_ctx;
|
||||
struct wd_sched *sched = &wd_aead_setting.sched;
|
||||
|
||||
- if (unlikely(!sched->poll_policy)) {
|
||||
- WD_ERR("failed to check aead poll_policy!\n");
|
||||
- return -WD_EINVAL;
|
||||
- }
|
||||
-
|
||||
return sched->poll_policy(h_ctx, expt, count);
|
||||
}
|
||||
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index f9d643d..9977765 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -580,11 +580,6 @@ int wd_cipher_poll(__u32 expt, __u32 *count)
|
||||
handle_t h_ctx = wd_cipher_setting.sched.h_sched_ctx;
|
||||
struct wd_sched *sched = &wd_cipher_setting.sched;
|
||||
|
||||
- if (unlikely(!sched->poll_policy)) {
|
||||
- WD_ERR("failed to check cipher poll_policy!\n");
|
||||
- return -WD_EINVAL;
|
||||
- }
|
||||
-
|
||||
return sched->poll_policy(h_ctx, expt, count);
|
||||
}
|
||||
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index c110f7b..1962f09 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -484,11 +484,6 @@ int wd_digest_poll(__u32 expt, __u32 *count)
|
||||
handle_t h_ctx = wd_digest_setting.sched.h_sched_ctx;
|
||||
struct wd_sched *sched = &wd_digest_setting.sched;
|
||||
|
||||
- if (unlikely(!sched->poll_policy)) {
|
||||
- WD_ERR("failed to check digest poll_policy!\n");
|
||||
- return -WD_EINVAL;
|
||||
- }
|
||||
-
|
||||
return sched->poll_policy(h_ctx, expt, count);
|
||||
}
|
||||
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
From d27f5accc09bc63d81a6a972fd019e208cddc9a8 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Tue, 14 Dec 2021 19:24:48 +0800
|
||||
Subject: [PATCH 04/28] digest/v1: fixed hmac key 0 length checking
|
||||
|
||||
The length of keylen checking v1 and v2 should be the same.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
v1/wd_digest.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
|
||||
index 6b22cdd..d684512 100644
|
||||
--- a/v1/wd_digest.c
|
||||
+++ b/v1/wd_digest.c
|
||||
@@ -243,7 +243,7 @@ int wcrypto_set_digest_key(void *ctx, __u8 *key, __u16 key_len)
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (key_len > MAX_HMAC_KEY_SIZE) {
|
||||
+ if (key_len == 0 || key_len > MAX_HMAC_KEY_SIZE) {
|
||||
WD_ERR("%s: input key length err!\n", __func__);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
From 6136bd700e5f5b23843a3e8aae9e3a925c37ca50 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Tue, 14 Dec 2021 19:24:49 +0800
|
||||
Subject: [PATCH 05/28] digest/v1: check the length of the key need to be
|
||||
changed.
|
||||
|
||||
The maximum length of the key is fixed by digest spec.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
v1/wd_digest.c | 4 +++-
|
||||
1 file changed, 3 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
|
||||
index d684512..aae4823 100644
|
||||
--- a/v1/wd_digest.c
|
||||
+++ b/v1/wd_digest.c
|
||||
@@ -243,7 +243,9 @@ int wcrypto_set_digest_key(void *ctx, __u8 *key, __u16 key_len)
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (key_len == 0 || key_len > MAX_HMAC_KEY_SIZE) {
|
||||
+ if ((ctxt->setup.alg <= WCRYPTO_SHA224 && key_len >
|
||||
+ MAX_HMAC_KEY_SIZE >> 1) || key_len == 0 ||
|
||||
+ key_len > MAX_HMAC_KEY_SIZE) {
|
||||
WD_ERR("%s: input key length err!\n", __func__);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,67 +0,0 @@
|
||||
From 1903e366f228ac6ee9dfb826b75b9d698bb180d8 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Wed, 22 Dec 2021 14:38:03 +0800
|
||||
Subject: [PATCH 07/28] qm/v1: fixup the incorrect configuration of the type
|
||||
|
||||
1. SEC should setting the sqc type is 0. it doesn't depend on
|
||||
encryption or decryption direction.
|
||||
2. Modify the HPRE sqc type configuration.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
v1/drv/hisi_qm_udrv.c | 5 +++++
|
||||
v1/wd.h | 5 ++++-
|
||||
2 files changed, 9 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/v1/drv/hisi_qm_udrv.c b/v1/drv/hisi_qm_udrv.c
|
||||
index 7fb6599..02aaf81 100644
|
||||
--- a/v1/drv/hisi_qm_udrv.c
|
||||
+++ b/v1/drv/hisi_qm_udrv.c
|
||||
@@ -277,16 +277,19 @@ static bool hpre_alg_info_init(struct wd_queue *q, const char *alg)
|
||||
struct qm_queue_info *info = qinfo->priv;
|
||||
bool is_found = true;
|
||||
|
||||
+ /* DH/RSA: qm sqc_type = 0, ECC: qm sqc_type = 1 */
|
||||
if (!strcmp(alg, "rsa")) {
|
||||
qinfo->atype = WCRYPTO_RSA;
|
||||
info->sqe_size = QM_HPRE_BD_SIZE;
|
||||
info->sqe_fill[WCRYPTO_RSA] = qm_fill_rsa_sqe;
|
||||
info->sqe_parse[WCRYPTO_RSA] = qm_parse_rsa_sqe;
|
||||
+ priv->direction = 0;
|
||||
} else if (!strcmp(alg, "dh")) {
|
||||
qinfo->atype = WCRYPTO_DH;
|
||||
info->sqe_size = QM_HPRE_BD_SIZE;
|
||||
info->sqe_fill[WCRYPTO_DH] = qm_fill_dh_sqe;
|
||||
info->sqe_parse[WCRYPTO_DH] = qm_parse_dh_sqe;
|
||||
+ priv->direction = 0;
|
||||
} else if (!strcmp(alg, "ecdh")) {
|
||||
qinfo->atype = WCRYPTO_ECDH;
|
||||
info->sqe_size = QM_HPRE_BD_SIZE;
|
||||
@@ -414,6 +417,8 @@ static int qm_set_queue_alg_info(struct wd_queue *q)
|
||||
} else if (zip_alg_info_init(qinfo, alg)) {
|
||||
ret = WD_SUCCESS;
|
||||
} else if (sec_alg_info_init(qinfo, alg)) {
|
||||
+ /* setting the type is 0 for sqc_type */
|
||||
+ priv->direction = 0;
|
||||
ret = WD_SUCCESS;
|
||||
} else if (!strcmp(alg, "xts(aes)") ||
|
||||
!strcmp(alg, "xts(sm4)")) {
|
||||
diff --git a/v1/wd.h b/v1/wd.h
|
||||
index 30fbf89..3dd69eb 100644
|
||||
--- a/v1/wd.h
|
||||
+++ b/v1/wd.h
|
||||
@@ -73,7 +73,10 @@ struct wcrypto_cb_tag {
|
||||
};
|
||||
|
||||
struct wcrypto_paras {
|
||||
- /* 0--encipher/compress .etc, 1 ---decipher/decomp .etc */
|
||||
+ /*
|
||||
+ * 0--encipher/compress .etc, 1 ---decipher/decomp .etc
|
||||
+ * it not been used for HiSilicon SEC currently.
|
||||
+ */
|
||||
__u8 direction;
|
||||
__u8 is_poll;
|
||||
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
From c602a3e77fbd95286e233c7ed257762687d8ebac Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Wed, 22 Dec 2021 14:38:04 +0800
|
||||
Subject: [PATCH 08/28] qm: fixup the incorrect configuration of the type
|
||||
|
||||
SEC should setting the sqc type is 0. it doesn't depend on
|
||||
global configuration.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 3 ++-
|
||||
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index 2fd23f3..603bdda 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -2306,7 +2306,8 @@ int hisi_sec_init(struct wd_ctx_config_internal *config, void *priv)
|
||||
/* allocate qp for each context */
|
||||
for (i = 0; i < config->ctx_num; i++) {
|
||||
h_ctx = config->ctxs[i].ctx;
|
||||
- qm_priv.op_type = config->ctxs[i].op_type;
|
||||
+ /* setting the type is 0 for sqc_type */
|
||||
+ qm_priv.op_type = 0;
|
||||
qm_priv.qp_mode = config->ctxs[i].ctx_mode;
|
||||
qm_priv.idx = i;
|
||||
h_qp = hisi_qm_alloc_qp(&qm_priv, h_ctx);
|
||||
--
|
||||
2.31.1
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,63 +0,0 @@
|
||||
From 0d65963667c4795a28701e5a212422ebcff27c74 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Thu, 23 Dec 2021 15:40:15 +0800
|
||||
Subject: [PATCH 10/28] digest: some optimizations for digest stream mode
|
||||
|
||||
1. add some comments for session state.
|
||||
2. The stream status is set only when the last msg message is
|
||||
successfully received.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
wd_digest.c | 14 +++++++++-----
|
||||
1 file changed, 9 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index 1962f09..bbb258f 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#define POLL_SIZE 100000
|
||||
#define POLL_TIME 1000
|
||||
+#define STREAM_MODE_STATE 1
|
||||
|
||||
static int g_digest_mac_len[WD_DIGEST_TYPE_MAX] = {
|
||||
WD_DIGEST_SM3_LEN, WD_DIGEST_MD5_LEN, WD_DIGEST_SHA1_LEN,
|
||||
@@ -46,8 +47,11 @@ struct wd_digest_sess {
|
||||
unsigned char key[MAX_HMAC_KEY_SIZE];
|
||||
__u32 key_bytes;
|
||||
void *sched_key;
|
||||
- /* Notify the BD state */
|
||||
- int state;
|
||||
+ /*
|
||||
+ * Notify the BD state, 1 is final BD or middle BD,
|
||||
+ * 0 is normal mode or first BD, one session only supports one stream.
|
||||
+ */
|
||||
+ int state;
|
||||
/* Total of data for stream mode */
|
||||
__u64 long_data_len;
|
||||
};
|
||||
@@ -294,7 +298,7 @@ static void fill_request_msg(struct wd_digest_msg *msg,
|
||||
msg->has_next = req->has_next;
|
||||
sess->long_data_len += req->in_bytes;
|
||||
msg->long_data_len = sess->long_data_len;
|
||||
- /* To store the stream bd state */
|
||||
+ /* To store the stream bd state, iv_bytes also means bd state */
|
||||
msg->iv_bytes = sess->state;
|
||||
if (req->has_next == 0) {
|
||||
sess->long_data_len = 0;
|
||||
@@ -332,8 +336,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *ds
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
- if (msg->has_next)
|
||||
- dsess->state = msg->out_bytes;
|
||||
+ if (msg->has_next && msg->result == WD_SUCCESS)
|
||||
+ dsess->state = STREAM_MODE_STATE;
|
||||
} while (ret < 0);
|
||||
|
||||
out:
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,44 +0,0 @@
|
||||
From 17bc4f46411541e725d30ec76693982765a96114 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Mon, 27 Dec 2021 09:52:00 +0800
|
||||
Subject: [PATCH 12/28] uadk: fix error of wd_get_avail_ctx return value
|
||||
|
||||
When wd_get_avail_ctx return negative value,
|
||||
wd should not use this device.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd.c | 3 ++-
|
||||
wd_util.c | 2 +-
|
||||
2 files changed, 3 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/wd.c b/wd.c
|
||||
index 838efa7..2bb2fdd 100644
|
||||
--- a/wd.c
|
||||
+++ b/wd.c
|
||||
@@ -675,7 +675,8 @@ struct uacce_dev *wd_get_accel_dev(const char *alg_name)
|
||||
while (list) {
|
||||
tmp = numa_distance(node, list->dev->numa_id);
|
||||
ctx_num = wd_get_avail_ctx(list->dev);
|
||||
- if ((dis > tmp && ctx_num) || (dis == tmp && ctx_num > max)) {
|
||||
+ if ((dis > tmp && ctx_num > 0) ||
|
||||
+ (dis == tmp && ctx_num > max)) {
|
||||
dev = list->dev;
|
||||
dis = tmp;
|
||||
max = ctx_num;
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index c973eff..3c1fd26 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -846,7 +846,7 @@ static handle_t request_ctx_on_numa(struct wd_env_config_per_numa *config)
|
||||
for (i = 0; i < config->dev_num; i++) {
|
||||
dev = config->dev + i;
|
||||
ctx_num = wd_get_avail_ctx(dev);
|
||||
- if (!ctx_num)
|
||||
+ if (ctx_num <= 0)
|
||||
continue;
|
||||
|
||||
h_ctx = wd_request_ctx(dev);
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,85 +0,0 @@
|
||||
From 6a83adca797b8917907d56097f72b3755acf74fa Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Mon, 27 Dec 2021 09:51:59 +0800
|
||||
Subject: [PATCH 13/28] uadk: fix comment content
|
||||
|
||||
There must be 1 space between the block comment character
|
||||
and the comment content.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
v1/drv/hisi_qm_udrv.c | 2 +-
|
||||
v1/wd_cipher.h | 2 +-
|
||||
v1/wd_dh.h | 2 +-
|
||||
wd_comp.c | 2 +-
|
||||
wd_util.c | 2 +-
|
||||
5 files changed, 5 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/v1/drv/hisi_qm_udrv.c b/v1/drv/hisi_qm_udrv.c
|
||||
index 02aaf81..63f346b 100644
|
||||
--- a/v1/drv/hisi_qm_udrv.c
|
||||
+++ b/v1/drv/hisi_qm_udrv.c
|
||||
@@ -77,7 +77,7 @@ static int qm_hw_sgl_sge_init(struct wd_sgl *sgl, struct hisi_sgl *hisi_sgl,
|
||||
return WD_SUCCESS;
|
||||
}
|
||||
|
||||
-/* 'num' starts from 1*/
|
||||
+/* 'num' starts from 1 */
|
||||
void qm_hw_sgl_sge_uninit(struct wd_sgl *sgl, struct hisi_sgl *hisi_sgl,
|
||||
int num, struct wd_mm_br *br, __u32 buf_sz)
|
||||
{
|
||||
diff --git a/v1/wd_cipher.h b/v1/wd_cipher.h
|
||||
index 2ab0e1d..7059f53 100644
|
||||
--- a/v1/wd_cipher.h
|
||||
+++ b/v1/wd_cipher.h
|
||||
@@ -92,7 +92,7 @@ struct wcrypto_cipher_op_data {
|
||||
/* Cipher message format of Warpdrive */
|
||||
struct wcrypto_cipher_msg {
|
||||
__u8 alg_type:4; /* Denoted by enum wcrypto_type */
|
||||
- __u8 alg:4; /* Denoted by enum wcrypto_cipher_alg*/
|
||||
+ __u8 alg:4; /* Denoted by enum wcrypto_cipher_alg */
|
||||
__u8 op_type:4; /* Denoted by enum wcrypto_cipher_op_type */
|
||||
__u8 mode:4; /* Denoted by enum wcrypto_cipher_mode */
|
||||
__u8 data_fmt; /* Data format, denoted by enum wcrypto_buff_type */
|
||||
diff --git a/v1/wd_dh.h b/v1/wd_dh.h
|
||||
index 6364966..e411830 100644
|
||||
--- a/v1/wd_dh.h
|
||||
+++ b/v1/wd_dh.h
|
||||
@@ -64,7 +64,7 @@ struct wcrypto_dh_msg {
|
||||
__u8 result; /* Data format, denoted by WD error code */
|
||||
__u16 key_bytes; /* Key size */
|
||||
__u8 *x_p; /* This is Xa and p data in order. Should be DMA buffer */
|
||||
- __u8 *g; /* This is PV also at phase 2. Should be DMA buffer*/
|
||||
+ __u8 *g; /* This is PV also at phase 2. Should be DMA buffer */
|
||||
__u8 *out; /* Result address, should be DMA buffer */
|
||||
__u16 xbytes; /* parameter Xa size */
|
||||
__u16 pbytes; /* parameter p size */
|
||||
diff --git a/wd_comp.c b/wd_comp.c
|
||||
index 6f0cf9d..e34d590 100644
|
||||
--- a/wd_comp.c
|
||||
+++ b/wd_comp.c
|
||||
@@ -584,7 +584,7 @@ static int append_store_block(struct wd_comp_sess *sess,
|
||||
memcpy(req->dst, store_block, blocksize);
|
||||
req->dst_len = blocksize;
|
||||
checksum = (__u32) cpu_to_be32(checksum);
|
||||
- /*if zlib, ADLER32*/
|
||||
+ /* if zlib, ADLER32 */
|
||||
memcpy(req->dst + blocksize, &checksum, sizeof(checksum));
|
||||
req->dst_len += sizeof(checksum);
|
||||
} else if (sess->alg_type == WD_GZIP) {
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 3c1fd26..3170f3c 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -34,7 +34,7 @@ static const char *comp_ctx_type[2][2] = {
|
||||
{"async-comp:", "async-decomp:"}
|
||||
};
|
||||
|
||||
-/* define two ctx mode here for cipher and other alg*/
|
||||
+/* define two ctx mode here for cipher and other alg */
|
||||
static const char *ctx_type[2][1] = { {"sync:"}, {"async:"} };
|
||||
|
||||
struct async_task {
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,424 +0,0 @@
|
||||
From ca3131392a8cb3209599dc6ca4c377460346b36a Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Mon, 27 Dec 2021 09:52:01 +0800
|
||||
Subject: [PATCH 14/28] uadk: max numa number should not be fixed
|
||||
|
||||
numa_num_configured_nodes() returns the number
|
||||
of memory nodes in the system, so use it as max
|
||||
numa number is good.
|
||||
when function is called in io path, use static array
|
||||
as much as possible, so use a numa number macro.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
include/wd_sched.h | 5 +-
|
||||
include/wd_util.h | 6 +-
|
||||
test/hisi_sec_test/test_hisi_sec.c | 5 +-
|
||||
uadk_tool/sec_uadk_benchmark.c | 13 ++--
|
||||
wd_sched.c | 39 +++++++----
|
||||
wd_util.c | 106 ++++++++++++++++++-----------
|
||||
6 files changed, 109 insertions(+), 65 deletions(-)
|
||||
|
||||
diff --git a/include/wd_sched.h b/include/wd_sched.h
|
||||
index a008d57..78125f4 100644
|
||||
--- a/include/wd_sched.h
|
||||
+++ b/include/wd_sched.h
|
||||
@@ -8,7 +8,6 @@
|
||||
#define SCHED_SAMPLE_h
|
||||
#include "wd_alg_common.h"
|
||||
|
||||
-#define MAX_NUMA_NUM 4
|
||||
#define INVALID_POS 0xFFFFFFFF
|
||||
|
||||
/* The global policy type */
|
||||
@@ -48,8 +47,8 @@ int wd_sched_rr_instance(const struct wd_sched *sched,
|
||||
* @func: The ctx poll function of user underlying operating.
|
||||
*
|
||||
*/
|
||||
-struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num, __u8 numa_num,
|
||||
- user_poll_func func);
|
||||
+struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num,
|
||||
+ __u16 numa_num, user_poll_func func);
|
||||
|
||||
/**
|
||||
* wd_sched_rr_release - Release schedule memory.
|
||||
diff --git a/include/wd_util.h b/include/wd_util.h
|
||||
index 643309c..81f4ba8 100644
|
||||
--- a/include/wd_util.h
|
||||
+++ b/include/wd_util.h
|
||||
@@ -59,12 +59,9 @@ struct wd_env_config_per_numa {
|
||||
};
|
||||
|
||||
struct wd_env_config {
|
||||
- unsigned long numa_num;
|
||||
struct wd_env_config_per_numa *config_per_numa;
|
||||
/* Let's make it as a gobal config, not per numa */
|
||||
bool enable_internal_poll;
|
||||
- __u8 disable_env;
|
||||
- __u8 op_type_num;
|
||||
int (*alg_poll_ctx)(__u32, __u32, __u32 *);
|
||||
void (*alg_uninit)(void);
|
||||
|
||||
@@ -74,6 +71,9 @@ struct wd_env_config {
|
||||
struct wd_ctx_config *ctx_config;
|
||||
const struct wd_config_variable *table;
|
||||
__u32 table_size;
|
||||
+ __u16 numa_num;
|
||||
+ __u8 disable_env;
|
||||
+ __u8 op_type_num;
|
||||
};
|
||||
|
||||
struct wd_config_variable {
|
||||
diff --git a/test/hisi_sec_test/test_hisi_sec.c b/test/hisi_sec_test/test_hisi_sec.c
|
||||
index e1521f6..dda291d 100644
|
||||
--- a/test/hisi_sec_test/test_hisi_sec.c
|
||||
+++ b/test/hisi_sec_test/test_hisi_sec.c
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <sys/mman.h>
|
||||
#include <sys/time.h>
|
||||
#include <getopt.h>
|
||||
+#include <numa.h>
|
||||
|
||||
#include "test_hisi_sec.h"
|
||||
#include "wd_cipher.h"
|
||||
@@ -493,7 +494,9 @@ static int init_ctx_config(int type, int mode)
|
||||
if (list->dev->numa_id < 0)
|
||||
list->dev->numa_id = 0;
|
||||
|
||||
- g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, MAX_NUMA_NUM, wd_cipher_poll_ctx);
|
||||
+ g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1,
|
||||
+ numa_max_node() + 1,
|
||||
+ wd_cipher_poll_ctx);
|
||||
if (!g_sched) {
|
||||
printf("Fail to alloc sched!\n");
|
||||
goto out;
|
||||
diff --git a/uadk_tool/sec_uadk_benchmark.c b/uadk_tool/sec_uadk_benchmark.c
|
||||
index 21738ed..40ba227 100644
|
||||
--- a/uadk_tool/sec_uadk_benchmark.c
|
||||
+++ b/uadk_tool/sec_uadk_benchmark.c
|
||||
@@ -1,5 +1,6 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
|
||||
+#include <numa.h>
|
||||
#include "uadk_benchmark.h"
|
||||
|
||||
#include "sec_uadk_benchmark.h"
|
||||
@@ -347,8 +348,12 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options)
|
||||
static int init_ctx_config(char *alg, int subtype, int mode)
|
||||
{
|
||||
struct uacce_dev_list *list;
|
||||
+ int i, max_node;
|
||||
int ret = 0;
|
||||
- int i;
|
||||
+
|
||||
+ max_node = numa_max_node() + 1;
|
||||
+ if (max_node <= 0)
|
||||
+ return -EINVAL;
|
||||
|
||||
list = wd_get_accel_list(alg);
|
||||
if (!list) {
|
||||
@@ -369,13 +374,13 @@ static int init_ctx_config(char *alg, int subtype, int mode)
|
||||
|
||||
switch(subtype) {
|
||||
case CIPHER_TYPE:
|
||||
- g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, MAX_NUMA_NUM, wd_cipher_poll_ctx);
|
||||
+ g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, max_node, wd_cipher_poll_ctx);
|
||||
break;
|
||||
case AEAD_TYPE:
|
||||
- g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, MAX_NUMA_NUM, wd_aead_poll_ctx);
|
||||
+ g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, max_node, wd_aead_poll_ctx);
|
||||
break;
|
||||
case DIGEST_TYPE:
|
||||
- g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, MAX_NUMA_NUM, wd_digest_poll_ctx);
|
||||
+ g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, max_node, wd_digest_poll_ctx);
|
||||
break;
|
||||
default:
|
||||
SEC_TST_PRT("Fail to parse alg subtype!\n");
|
||||
diff --git a/wd_sched.c b/wd_sched.c
|
||||
index 8ca309c..b310077 100644
|
||||
--- a/wd_sched.c
|
||||
+++ b/wd_sched.c
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
+#include <numa.h>
|
||||
#include "wd_sched.h"
|
||||
|
||||
#define MAX_POLL_TIMES 1000
|
||||
@@ -37,6 +38,8 @@ struct sched_key {
|
||||
* @begin: the start pos in ctxs of config.
|
||||
* @end: the end pos in ctxx of config.
|
||||
* @last: the last one which be distributed.
|
||||
+ * @valid: the region used flag.
|
||||
+ * @lock: lock the currentscheduling region.
|
||||
*/
|
||||
struct sched_ctx_region {
|
||||
__u32 begin;
|
||||
@@ -64,14 +67,13 @@ struct wd_sched_info {
|
||||
* @policy: define the policy of the scheduler.
|
||||
* @numa_num: the max numa numbers of the scheduler.
|
||||
* @type_num: the max operation types of the scheduler.
|
||||
- * @numa_id: current task's numa id
|
||||
* @poll_func: the task's poll operation function.
|
||||
* @sched_info: the context of the scheduler
|
||||
*/
|
||||
struct wd_sched_ctx {
|
||||
__u32 policy;
|
||||
__u32 type_num;
|
||||
- __u8 numa_num;
|
||||
+ __u16 numa_num;
|
||||
user_poll_func poll_func;
|
||||
struct wd_sched_info sched_info[0];
|
||||
};
|
||||
@@ -200,11 +202,11 @@ static int session_sched_poll_policy(handle_t sched_ctx,
|
||||
{
|
||||
struct wd_sched_ctx *ctx = (struct wd_sched_ctx *)sched_ctx;
|
||||
struct wd_sched_info *sched_info;
|
||||
- int numa[MAX_NUMA_NUM];
|
||||
+ __u16 numa[NUMA_NUM_NODES];
|
||||
__u32 loop_time = 0;
|
||||
__u32 last_count = 0;
|
||||
- __u8 tail = 0;
|
||||
- __u8 i;
|
||||
+ __u16 tail = 0;
|
||||
+ __u16 i;
|
||||
int ret;
|
||||
|
||||
if (!sched_ctx || !count || !ctx) {
|
||||
@@ -212,6 +214,11 @@ static int session_sched_poll_policy(handle_t sched_ctx,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
+ if (ctx->numa_num > NUMA_NUM_NODES) {
|
||||
+ WD_ERR("ERROR: %s ctx numa num is invalid!\n", __FUNCTION__);
|
||||
+ return -EINVAL;
|
||||
+ }
|
||||
+
|
||||
sched_info = ctx->sched_info;
|
||||
for (i = 0; i < ctx->numa_num; i++)
|
||||
if (sched_info[i].valid)
|
||||
@@ -412,13 +419,23 @@ out:
|
||||
return;
|
||||
}
|
||||
|
||||
-struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num, __u8 numa_num,
|
||||
- user_poll_func func)
|
||||
+struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num,
|
||||
+ __u16 numa_num, user_poll_func func)
|
||||
{
|
||||
struct wd_sched_info *sched_info;
|
||||
struct wd_sched_ctx *sched_ctx;
|
||||
struct wd_sched *sched;
|
||||
- int i, j;
|
||||
+ int i, j, max_node;
|
||||
+
|
||||
+ max_node = numa_max_node() + 1;
|
||||
+ if (max_node <= 0)
|
||||
+ return NULL;
|
||||
+
|
||||
+ if (!numa_num || numa_num > max_node) {
|
||||
+ WD_ERR("Error: %s numa number = %u!\n", __FUNCTION__,
|
||||
+ numa_num);
|
||||
+ return NULL;
|
||||
+ }
|
||||
|
||||
if (sched_type >= SCHED_POLICY_BUTT || !type_num) {
|
||||
WD_ERR("Error: %s sched_type = %u or type_num = %u is invalid!\n",
|
||||
@@ -426,12 +443,6 @@ struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num, __u8 numa_num
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- if (!numa_num) {
|
||||
- WD_ERR("Warning: %s set numa number as %d!\n", __FUNCTION__,
|
||||
- MAX_NUMA_NUM);
|
||||
- numa_num = MAX_NUMA_NUM;
|
||||
- }
|
||||
-
|
||||
sched = calloc(1, sizeof(struct wd_sched));
|
||||
if (!sched) {
|
||||
WD_ERR("Error: %s wd_sched alloc error!\n", __FUNCTION__);
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 3170f3c..3a1def5 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -357,26 +357,28 @@ static void wd_free_numa(struct wd_env_config *config)
|
||||
* @numa_dev_num: number of devices of the same type (like sec2) on each numa.
|
||||
* @numa_num: number of numa node that has this type of device.
|
||||
*/
|
||||
-static void wd_get_dev_numa(struct uacce_dev_list *head,
|
||||
- int *numa_dev_num, __u8 *numa_num, __u8 size)
|
||||
+static __u16 wd_get_dev_numa(struct uacce_dev_list *head,
|
||||
+ int *numa_dev_num, __u16 size)
|
||||
{
|
||||
struct uacce_dev_list *list = head;
|
||||
+ __u16 numa_num = 0;
|
||||
|
||||
while (list) {
|
||||
if (list->dev->numa_id < 0) {
|
||||
list->dev->numa_id = 0;
|
||||
} else if (list->dev->numa_id >= size) {
|
||||
WD_ERR("numa id is wrong(%d)\n", list->dev->numa_id);
|
||||
- *numa_num = 0;
|
||||
- return;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
if (!numa_dev_num[list->dev->numa_id])
|
||||
- (*numa_num)++;
|
||||
+ numa_num++;
|
||||
|
||||
numa_dev_num[list->dev->numa_id]++;
|
||||
list = list->next;
|
||||
}
|
||||
+
|
||||
+ return numa_num;
|
||||
}
|
||||
|
||||
static void wd_set_numa_dev(struct uacce_dev_list *head,
|
||||
@@ -400,39 +402,18 @@ static void wd_set_numa_dev(struct uacce_dev_list *head,
|
||||
}
|
||||
}
|
||||
|
||||
-static int wd_alloc_numa(struct wd_env_config *config,
|
||||
- const struct wd_alg_ops *ops)
|
||||
+static int wd_set_config_numa(struct wd_env_config *config,
|
||||
+ int *numa_dev_num, int max_node)
|
||||
{
|
||||
struct wd_env_config_per_numa *config_numa;
|
||||
- struct uacce_dev_list *head;
|
||||
- int numa_dev_num[MAX_NUMA_NUM] = {0};
|
||||
- __u8 numa_num = 0;
|
||||
- int i, ret;
|
||||
-
|
||||
- /* get uacce_dev */
|
||||
- head = wd_get_accel_list(ops->alg_name);
|
||||
- if (!head) {
|
||||
- WD_ERR("no device to support %s\n", ops->alg_name);
|
||||
- return -WD_ENODEV;
|
||||
- }
|
||||
-
|
||||
- /* get numa num and device num of each numa from uacce_dev list */
|
||||
- wd_get_dev_numa(head, numa_dev_num, &numa_num, MAX_NUMA_NUM);
|
||||
- if (numa_num == 0 || numa_num > MAX_NUMA_NUM) {
|
||||
- WD_ERR("numa num err(%u)!\n", numa_num);
|
||||
- wd_free_list_accels(head);
|
||||
- return -WD_ENODEV;
|
||||
- }
|
||||
+ int i;
|
||||
|
||||
- config->numa_num = numa_num;
|
||||
- config->config_per_numa = calloc(numa_num, sizeof(*config_numa));
|
||||
- if (!config->config_per_numa) {
|
||||
- ret = -WD_ENOMEM;
|
||||
- goto free_list;
|
||||
- }
|
||||
+ config->config_per_numa = calloc(config->numa_num, sizeof(*config_numa));
|
||||
+ if (!config->config_per_numa)
|
||||
+ return -WD_ENOMEM;
|
||||
|
||||
config_numa = config->config_per_numa;
|
||||
- for (i = 0; i < MAX_NUMA_NUM; i++) {
|
||||
+ for (i = 0; i < max_node; i++) {
|
||||
if (!numa_dev_num[i])
|
||||
continue;
|
||||
|
||||
@@ -440,24 +421,65 @@ static int wd_alloc_numa(struct wd_env_config *config,
|
||||
config_numa->dev = calloc(numa_dev_num[i],
|
||||
sizeof(struct uacce_dev));
|
||||
if (!config_numa->dev) {
|
||||
- ret = -WD_ENOMEM;
|
||||
- goto free_mem;
|
||||
+ /* free config_per_numa and all uacce dev */
|
||||
+ wd_free_numa(config);
|
||||
+ return -WD_ENOMEM;
|
||||
}
|
||||
|
||||
config_numa->dev_num = 0;
|
||||
config_numa++;
|
||||
}
|
||||
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int wd_alloc_numa(struct wd_env_config *config,
|
||||
+ const struct wd_alg_ops *ops)
|
||||
+{
|
||||
+ struct uacce_dev_list *head;
|
||||
+ int *numa_dev_num;
|
||||
+ int ret, max_node;
|
||||
+
|
||||
+ max_node = numa_max_node() + 1;
|
||||
+ if (max_node <= 0)
|
||||
+ return -WD_EINVAL;
|
||||
+
|
||||
+ numa_dev_num = calloc(max_node, sizeof(int));
|
||||
+ if (!numa_dev_num)
|
||||
+ return -WD_ENOMEM;
|
||||
+
|
||||
+ /* get uacce_dev */
|
||||
+ head = wd_get_accel_list(ops->alg_name);
|
||||
+ if (!head) {
|
||||
+ WD_ERR("no device to support %s\n", ops->alg_name);
|
||||
+ ret = -WD_ENODEV;
|
||||
+ goto free_numa_dev_num;
|
||||
+ }
|
||||
+
|
||||
+ /* get numa num and device num of each numa from uacce_dev list */
|
||||
+ config->numa_num = wd_get_dev_numa(head, numa_dev_num, max_node);
|
||||
+ if (config->numa_num == 0 || config->numa_num > max_node) {
|
||||
+ WD_ERR("numa num err(%u)!\n", config->numa_num);
|
||||
+ ret = -WD_ENODEV;
|
||||
+ goto free_list;
|
||||
+ }
|
||||
+
|
||||
+ /* alloc and init config_per_numa and all uacce dev */
|
||||
+ ret = wd_set_config_numa(config, numa_dev_num, max_node);
|
||||
+ if (ret)
|
||||
+ goto free_list;
|
||||
+
|
||||
/* set device and device num for config numa from uacce_dev list */
|
||||
wd_set_numa_dev(head, config);
|
||||
wd_free_list_accels(head);
|
||||
+ free(numa_dev_num);
|
||||
|
||||
return 0;
|
||||
|
||||
-free_mem:
|
||||
- wd_free_numa(config);
|
||||
free_list:
|
||||
wd_free_list_accels(head);
|
||||
+free_numa_dev_num:
|
||||
+ free(numa_dev_num);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -981,18 +1003,22 @@ static int wd_sched_fill_table(struct wd_env_config_per_numa *config_numa,
|
||||
static int wd_init_sched_config(struct wd_env_config *config)
|
||||
{
|
||||
struct wd_env_config_per_numa *config_numa;
|
||||
+ int i, j, ret, max_node, type_num;
|
||||
struct wd_sched *sched;
|
||||
- int type_num = config->op_type_num;
|
||||
- int i, j, ret;
|
||||
void *func = NULL;
|
||||
|
||||
+ max_node = numa_max_node() + 1;
|
||||
+ if (max_node <= 0)
|
||||
+ return -WD_EINVAL;
|
||||
+
|
||||
if (!config->enable_internal_poll)
|
||||
func = config->alg_poll_ctx;
|
||||
|
||||
config->internal_sched = false;
|
||||
+ type_num = config->op_type_num;
|
||||
if (!config->sched) {
|
||||
config->sched = wd_sched_rr_alloc(SCHED_POLICY_RR, type_num,
|
||||
- MAX_NUMA_NUM, func);
|
||||
+ max_node, func);
|
||||
if (!config->sched)
|
||||
return -WD_ENOMEM;
|
||||
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
From cf1b23feddeba22869d35d5f1fa4b4675f9b8984 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 30 Dec 2021 12:07:26 +0800
|
||||
Subject: [PATCH 15/28] uadk: mempool: remove MISC_DVE_UACCE_CTRL
|
||||
|
||||
MISC_DVE_UACCE_CTRL is no longer used, clean it.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_mempool.c | 1 -
|
||||
1 file changed, 1 deletion(-)
|
||||
|
||||
diff --git a/wd_mempool.c b/wd_mempool.c
|
||||
index 2462560..bbf5edb 100644
|
||||
--- a/wd_mempool.c
|
||||
+++ b/wd_mempool.c
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
#define SYSFS_NODE_PATH "/sys/devices/system/node/node"
|
||||
#define MAX_HP_STR_SIZE 64
|
||||
-#define MISC_DVE_UACCE_CTRL "/dev/uacce_ctrl"
|
||||
#define HUGETLB_FLAG_ENCODE_SHIFT 26
|
||||
|
||||
#define BITS_PER_LONG ((unsigned int)sizeof(unsigned long) * 8)
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
From 80fd67d79a66c45171890460ed8a8cc8bc83bb7a Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 30 Dec 2021 12:07:28 +0800
|
||||
Subject: [PATCH 16/28] uadk: mempool: check stats null pointer
|
||||
|
||||
If user input's stats is null pointer, it will cause
|
||||
a segment fault, fix it.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_mempool.c | 5 +++++
|
||||
1 file changed, 5 insertions(+)
|
||||
|
||||
diff --git a/wd_mempool.c b/wd_mempool.c
|
||||
index bbf5edb..b6e1088 100644
|
||||
--- a/wd_mempool.c
|
||||
+++ b/wd_mempool.c
|
||||
@@ -958,6 +958,11 @@ void wd_mempool_stats(handle_t mempool, struct wd_mempool_stats *stats)
|
||||
return;
|
||||
}
|
||||
|
||||
+ if (!stats) {
|
||||
+ WD_ERR("wd_mempool: mempool stats is NULL\n");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
wd_spinlock(&mp->lock);
|
||||
|
||||
stats->page_type = mp->page_type;
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
From 19add2ea6da8525bafb8fb2747965cbb55dbea75 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 30 Dec 2021 12:07:29 +0800
|
||||
Subject: [PATCH 17/28] uadk: fix wd_get_config_numa info
|
||||
|
||||
wd_get_config_numa is used to get config numa
|
||||
by node id, not set a numa dev.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_util.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 3a1def5..faaf821 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -391,7 +391,7 @@ static void wd_set_numa_dev(struct uacce_dev_list *head,
|
||||
while (list) {
|
||||
config_numa = wd_get_config_numa(config, list->dev->numa_id);
|
||||
if (!config_numa) {
|
||||
- WD_ERR("set numa dev err!\n");
|
||||
+ WD_ERR("%s got wrong numa node!\n", __func__);
|
||||
break;
|
||||
}
|
||||
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,46 +0,0 @@
|
||||
From 0feee4ccc2b3d0f60d84d39310fc1f85a3d28d63 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 30 Dec 2021 12:07:30 +0800
|
||||
Subject: [PATCH 18/28] uadk: fix static check warning
|
||||
|
||||
1.set null pointer after free.
|
||||
2.define const pointer.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_sched.c | 4 +++-
|
||||
wd_util.c | 2 +-
|
||||
2 files changed, 4 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/wd_sched.c b/wd_sched.c
|
||||
index b310077..3330a4d 100644
|
||||
--- a/wd_sched.c
|
||||
+++ b/wd_sched.c
|
||||
@@ -406,8 +406,10 @@ void wd_sched_rr_release(struct wd_sched *sched)
|
||||
sched_info = sched_ctx->sched_info;
|
||||
for (i = 0; i < sched_ctx->numa_num; i++) {
|
||||
for (j = 0; j < SCHED_MODE_BUTT; j++) {
|
||||
- if (sched_info[i].ctx_region[j])
|
||||
+ if (sched_info[i].ctx_region[j]) {
|
||||
free(sched_info[i].ctx_region[j]);
|
||||
+ sched_info[i].ctx_region[j] = NULL;
|
||||
+ }
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index faaf821..62f9359 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -403,7 +403,7 @@ static void wd_set_numa_dev(struct uacce_dev_list *head,
|
||||
}
|
||||
|
||||
static int wd_set_config_numa(struct wd_env_config *config,
|
||||
- int *numa_dev_num, int max_node)
|
||||
+ const int *numa_dev_num, int max_node)
|
||||
{
|
||||
struct wd_env_config_per_numa *config_numa;
|
||||
int i;
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,69 +0,0 @@
|
||||
From 4a15745d3544eae2c41419d5fb64802e2a16a9f5 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 30 Dec 2021 12:07:31 +0800
|
||||
Subject: [PATCH 19/28] uadk: fix numa array use too much stack space
|
||||
|
||||
numa array will take 32768 bytes, too big for
|
||||
a process, replace it by check numa invalid status.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_sched.c | 19 ++++++++++++-------
|
||||
1 file changed, 12 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/wd_sched.c b/wd_sched.c
|
||||
index 3330a4d..f97c15f 100644
|
||||
--- a/wd_sched.c
|
||||
+++ b/wd_sched.c
|
||||
@@ -202,10 +202,8 @@ static int session_sched_poll_policy(handle_t sched_ctx,
|
||||
{
|
||||
struct wd_sched_ctx *ctx = (struct wd_sched_ctx *)sched_ctx;
|
||||
struct wd_sched_info *sched_info;
|
||||
- __u16 numa[NUMA_NUM_NODES];
|
||||
__u32 loop_time = 0;
|
||||
__u32 last_count = 0;
|
||||
- __u16 tail = 0;
|
||||
__u16 i;
|
||||
int ret;
|
||||
|
||||
@@ -220,9 +218,6 @@ static int session_sched_poll_policy(handle_t sched_ctx,
|
||||
}
|
||||
|
||||
sched_info = ctx->sched_info;
|
||||
- for (i = 0; i < ctx->numa_num; i++)
|
||||
- if (sched_info[i].valid)
|
||||
- numa[tail++]= i;
|
||||
|
||||
/*
|
||||
* Try different numa's ctx if we can't receive any
|
||||
@@ -231,15 +226,25 @@ static int session_sched_poll_policy(handle_t sched_ctx,
|
||||
*/
|
||||
while (loop_time < MAX_POLL_TIMES) {
|
||||
loop_time++;
|
||||
- for (i = 0; i < tail;) {
|
||||
+ for (i = 0; i < ctx->numa_num;) {
|
||||
+ /* If current numa is not valid, find next. */
|
||||
+ if (!sched_info[i].valid) {
|
||||
+ i++;
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
last_count = *count;
|
||||
- ret = session_poll_policy_rr(ctx, numa[i], expect, count);
|
||||
+ ret = session_poll_policy_rr(ctx, i, expect, count);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (expect == *count)
|
||||
return 0;
|
||||
|
||||
+ /*
|
||||
+ * If no package is received, find next numa,
|
||||
+ * otherwise, keep receiving packets at this node.
|
||||
+ */
|
||||
if (last_count == *count)
|
||||
i++;
|
||||
}
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,86 +0,0 @@
|
||||
From 34b4dcc70a808c286378a9b6aeb72d5ba88493ef Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 30 Dec 2021 12:07:32 +0800
|
||||
Subject: [PATCH 20/28] uadk: fix get_dev_info
|
||||
|
||||
Fix for get_int_attr and get_str_attr
|
||||
return value is not checked in get_dev_info.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd.c | 43 +++++++++++++++++++++++++++++++++----------
|
||||
1 file changed, 33 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/wd.c b/wd.c
|
||||
index 2bb2fdd..25386d7 100644
|
||||
--- a/wd.c
|
||||
+++ b/wd.c
|
||||
@@ -137,23 +137,43 @@ static int get_dev_info(struct uacce_dev *dev)
|
||||
int value = 0;
|
||||
int ret;
|
||||
|
||||
- get_int_attr(dev, "flags", &dev->flags);
|
||||
- get_str_attr(dev, "api", dev->api, WD_NAME_SIZE);
|
||||
-
|
||||
/* hardware err isolate flag */
|
||||
ret = access_attr(dev->dev_root, "isolate", F_OK);
|
||||
if (!ret) {
|
||||
- get_int_attr(dev, "isolate", &value);
|
||||
- if (value == 1)
|
||||
+ ret = get_int_attr(dev, "isolate", &value);
|
||||
+ if (ret < 0)
|
||||
+ return ret;
|
||||
+ else if (value == 1)
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
- get_str_attr(dev, "algorithms", dev->algs, MAX_ATTR_STR_SIZE);
|
||||
- get_int_attr(dev, "region_mmio_size", &value);
|
||||
+ ret = get_int_attr(dev, "flags", &dev->flags);
|
||||
+ if (ret < 0)
|
||||
+ return ret;
|
||||
+
|
||||
+ ret = get_int_attr(dev, "region_mmio_size", &value);
|
||||
+ if (ret < 0)
|
||||
+ return ret;
|
||||
+
|
||||
dev->qfrs_offs[UACCE_QFRT_MMIO] = value;
|
||||
- get_int_attr(dev, "region_dus_size", &value);
|
||||
+
|
||||
+ ret = get_int_attr(dev, "region_dus_size", &value);
|
||||
+ if (ret < 0)
|
||||
+ return ret;
|
||||
+
|
||||
dev->qfrs_offs[UACCE_QFRT_DUS] = value;
|
||||
- get_int_attr(dev, "device/numa_node", &dev->numa_id);
|
||||
+
|
||||
+ ret = get_int_attr(dev, "device/numa_node", &dev->numa_id);
|
||||
+ if (ret < 0)
|
||||
+ return ret;
|
||||
+
|
||||
+ ret = get_str_attr(dev, "api", dev->api, WD_NAME_SIZE);
|
||||
+ if (ret < 0)
|
||||
+ return ret;
|
||||
+
|
||||
+ ret = get_str_attr(dev, "algorithms", dev->algs, MAX_ATTR_STR_SIZE);
|
||||
+ if (ret < 0)
|
||||
+ return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -195,8 +215,11 @@ static struct uacce_dev *read_uacce_sysfs(const char *dev_name)
|
||||
goto out_dir;
|
||||
|
||||
ret = get_dev_info(dev);
|
||||
- if (ret)
|
||||
+ if (ret) {
|
||||
+ WD_ERR("failed to get dev info: ret = %d!\n", ret);
|
||||
goto out_dir;
|
||||
+ }
|
||||
+
|
||||
break;
|
||||
}
|
||||
if (!dev_dir)
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,92 +0,0 @@
|
||||
From 913a84cbdce651aea50a6e12117ee93ccbbdbf1c Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 30 Dec 2021 12:07:33 +0800
|
||||
Subject: [PATCH 21/28] uadk: fix pthread_spin_init
|
||||
|
||||
pthread_spin_init() may fail with errors,
|
||||
check return value for it.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
drv/hisi_qm_udrv.c | 16 ++++++++++++----
|
||||
wd_util.c | 9 +++++++--
|
||||
2 files changed, 19 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
|
||||
index 8282c51..845fa46 100644
|
||||
--- a/drv/hisi_qm_udrv.c
|
||||
+++ b/drv/hisi_qm_udrv.c
|
||||
@@ -298,7 +298,7 @@ static int hisi_qm_setup_info(struct hisi_qp *qp, struct hisi_qm_priv *config)
|
||||
ret = hisi_qm_get_qfrs_offs(qp->h_ctx, q_info);
|
||||
if (ret) {
|
||||
WD_ERR("get dev qfrs offset fail.\n");
|
||||
- return ret;
|
||||
+ goto err_out;
|
||||
}
|
||||
|
||||
ret = hisi_qm_setup_db(qp->h_ctx, q_info);
|
||||
@@ -323,7 +323,11 @@ static int hisi_qm_setup_info(struct hisi_qp *qp, struct hisi_qm_priv *config)
|
||||
q_info->region_size[UACCE_QFRT_DUS] - sizeof(uint32_t);
|
||||
q_info->ds_rx_base = q_info->ds_tx_base - sizeof(uint32_t);
|
||||
|
||||
- pthread_spin_init(&q_info->lock, PTHREAD_PROCESS_SHARED);
|
||||
+ ret = pthread_spin_init(&q_info->lock, PTHREAD_PROCESS_SHARED);
|
||||
+ if (ret) {
|
||||
+ WD_ERR("init qinfo lock fail\n");
|
||||
+ goto err_out;
|
||||
+ }
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -560,7 +564,7 @@ static struct hisi_sgl *hisi_qm_align_sgl(const void *sgl, __u32 sge_num)
|
||||
handle_t hisi_qm_create_sglpool(__u32 sgl_num, __u32 sge_num)
|
||||
{
|
||||
struct hisi_sgl_pool *sgl_pool;
|
||||
- int i;
|
||||
+ int i, ret;
|
||||
|
||||
if (!sgl_num || !sge_num || sge_num > HISI_SGE_NUM_IN_SGL) {
|
||||
WD_ERR("create sgl_pool failed, sgl_num=%u, sge_num=%u\n",
|
||||
@@ -601,7 +605,11 @@ handle_t hisi_qm_create_sglpool(__u32 sgl_num, __u32 sge_num)
|
||||
sgl_pool->sge_num = sge_num;
|
||||
sgl_pool->depth = sgl_num;
|
||||
sgl_pool->top = sgl_num;
|
||||
- pthread_spin_init(&sgl_pool->lock, PTHREAD_PROCESS_SHARED);
|
||||
+ ret = pthread_spin_init(&sgl_pool->lock, PTHREAD_PROCESS_SHARED);
|
||||
+ if (ret) {
|
||||
+ WD_ERR("init sgl pool lock failed.\n");
|
||||
+ goto err_out;
|
||||
+ }
|
||||
|
||||
return (handle_t)sgl_pool;
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 62f9359..83c77c4 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -68,7 +68,7 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in,
|
||||
struct wd_ctx_config *cfg)
|
||||
{
|
||||
struct wd_ctx_internal *ctxs;
|
||||
- int i;
|
||||
+ int i, ret;
|
||||
|
||||
if (!cfg->ctx_num) {
|
||||
WD_ERR("invalid parameters, ctx_num is 0!\n");
|
||||
@@ -93,7 +93,12 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in,
|
||||
}
|
||||
|
||||
clone_ctx_to_internal(cfg->ctxs + i, ctxs + i);
|
||||
- pthread_spin_init(&ctxs[i].lock, PTHREAD_PROCESS_SHARED);
|
||||
+ ret = pthread_spin_init(&ctxs[i].lock, PTHREAD_PROCESS_SHARED);
|
||||
+ if (ret) {
|
||||
+ WD_ERR("init ctxs lock failed!\n");
|
||||
+ free(ctxs);
|
||||
+ return ret;
|
||||
+ }
|
||||
}
|
||||
|
||||
in->ctxs = ctxs;
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,69 +0,0 @@
|
||||
From 1c037d1a257714802890f83aaa970fc140786915 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 30 Dec 2021 12:07:34 +0800
|
||||
Subject: [PATCH 22/28] uadk: env: optimize find_async_queue
|
||||
|
||||
No need to find ctx idx from begin to end,
|
||||
if it is in ctx range, calculate its offset
|
||||
from begin ctx.
|
||||
If offset not set, find_async_queue should
|
||||
return NULL.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_util.c | 29 ++++++++++++++---------------
|
||||
1 file changed, 14 insertions(+), 15 deletions(-)
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 83c77c4..ee1c084 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -1061,7 +1061,9 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config,
|
||||
struct wd_env_config_per_numa *config_numa;
|
||||
struct wd_ctx_range **ctx_table;
|
||||
struct async_task_queue *head;
|
||||
- int i, j, n = -1, num = 0;
|
||||
+ int offset = -1;
|
||||
+ int num = 0;
|
||||
+ int i;
|
||||
|
||||
FOREACH_NUMA(i, config, config_numa) {
|
||||
num += config_numa->sync_ctx_num + config_numa->async_ctx_num;
|
||||
@@ -1074,23 +1076,20 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config,
|
||||
|
||||
ctx_table = config_numa->ctx_table;
|
||||
for (i = 0; i < config_numa->op_type_num; i++) {
|
||||
- for (j = ctx_table[CTX_MODE_ASYNC][i].begin;
|
||||
- j <= ctx_table[CTX_MODE_ASYNC][i].end;
|
||||
- j++) {
|
||||
- if (j == idx) {
|
||||
- n = j - ctx_table[CTX_MODE_ASYNC][i].begin;
|
||||
- if (n >= config_numa->async_poll_num)
|
||||
- n = n % config_numa->async_poll_num;
|
||||
- break;
|
||||
- }
|
||||
+ if (idx <= ctx_table[CTX_MODE_ASYNC][i].end &&
|
||||
+ idx >= ctx_table[CTX_MODE_ASYNC][i].begin) {
|
||||
+ offset = idx - ctx_table[CTX_MODE_ASYNC][i].begin;
|
||||
+ if (offset >= config_numa->async_poll_num)
|
||||
+ offset = offset % config_numa->async_poll_num;
|
||||
}
|
||||
}
|
||||
+
|
||||
+ if (offset < 0)
|
||||
+ return NULL;
|
||||
+
|
||||
head = (struct async_task_queue *)config_numa->async_task_queue_array;
|
||||
- if (n >= 0) {
|
||||
- head += n;
|
||||
- return head;
|
||||
- }
|
||||
- return head;
|
||||
+
|
||||
+ return head + offset;
|
||||
}
|
||||
|
||||
/* fix me: all return value here, and no config input */
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,175 +0,0 @@
|
||||
From a98e9a6092ae5af499353a739f30506bee7db73f Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 30 Dec 2021 12:15:29 +0800
|
||||
Subject: [PATCH 23/28] uadk: env: optimize some function
|
||||
|
||||
1.find_async_queue add some abnormal branch judgment
|
||||
2.wd_init_async_polling_thread_per_numa use queue_head
|
||||
to save a task queue head.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_util.c | 71 ++++++++++++++++++++++++++++++++-----------------------
|
||||
1 file changed, 41 insertions(+), 30 deletions(-)
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index ee1c084..49e1d66 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -1061,7 +1061,7 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config,
|
||||
struct wd_env_config_per_numa *config_numa;
|
||||
struct wd_ctx_range **ctx_table;
|
||||
struct async_task_queue *head;
|
||||
- int offset = -1;
|
||||
+ unsigned long offset;
|
||||
int num = 0;
|
||||
int i;
|
||||
|
||||
@@ -1071,8 +1071,15 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config,
|
||||
break;
|
||||
}
|
||||
|
||||
- if (i == config->numa_num)
|
||||
+ if (i == config->numa_num) {
|
||||
+ WD_ERR("failed to find a proper numa node!\n");
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ if (!config_numa->async_poll_num) {
|
||||
+ WD_ERR("invalid parameter, async_poll_num of numa is zero!\n");
|
||||
return NULL;
|
||||
+ }
|
||||
|
||||
ctx_table = config_numa->ctx_table;
|
||||
for (i = 0; i < config_numa->op_type_num; i++) {
|
||||
@@ -1081,11 +1088,15 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config,
|
||||
offset = idx - ctx_table[CTX_MODE_ASYNC][i].begin;
|
||||
if (offset >= config_numa->async_poll_num)
|
||||
offset = offset % config_numa->async_poll_num;
|
||||
+
|
||||
+ break;
|
||||
}
|
||||
}
|
||||
|
||||
- if (offset < 0)
|
||||
+ if (i == config_numa->op_type_num) {
|
||||
+ WD_ERR("failed to find async queue for ctx: idx %u!\n", idx);
|
||||
return NULL;
|
||||
+ }
|
||||
|
||||
head = (struct async_task_queue *)config_numa->async_task_queue_array;
|
||||
|
||||
@@ -1193,18 +1204,18 @@ static int wd_init_one_task_queue(struct async_task_queue *task_queue,
|
||||
void *alg_poll_ctx)
|
||||
|
||||
{
|
||||
- struct async_task *head;
|
||||
+ struct async_task *task_head;
|
||||
pthread_t thread_id;
|
||||
pthread_attr_t attr;
|
||||
int depth, ret;
|
||||
|
||||
task_queue->depth = depth = WD_ASYNC_DEF_QUEUE_DEPTH;
|
||||
|
||||
- head = calloc(task_queue->depth, sizeof(*head));
|
||||
- if (!head)
|
||||
+ task_head = calloc(task_queue->depth, sizeof(struct async_task));
|
||||
+ if (!task_head)
|
||||
return -WD_ENOMEM;
|
||||
|
||||
- task_queue->head = head;
|
||||
+ task_queue->head = task_head;
|
||||
task_queue->left_task = depth;
|
||||
task_queue->alg_poll_ctx = alg_poll_ctx;
|
||||
|
||||
@@ -1245,7 +1256,7 @@ err_uninit_full_sem:
|
||||
err_uninit_empty_sem:
|
||||
sem_destroy(&task_queue->empty_sem);
|
||||
err_free_head:
|
||||
- free(head);
|
||||
+ free(task_head);
|
||||
ret = -errno;
|
||||
return ret;
|
||||
}
|
||||
@@ -1272,45 +1283,45 @@ static void wd_uninit_one_task_queue(struct async_task_queue *task_queue)
|
||||
static int wd_init_async_polling_thread_per_numa(struct wd_env_config *config,
|
||||
struct wd_env_config_per_numa *config_numa)
|
||||
{
|
||||
- struct async_task_queue *task_queue, *head;
|
||||
- int i, j, n, ret;
|
||||
+ struct async_task_queue *task_queue, *queue_head;
|
||||
+ int i, j, poll_thread_num, ret;
|
||||
|
||||
if (!config_numa->async_ctx_num)
|
||||
return 0;
|
||||
|
||||
- if (config_numa->async_poll_num <= 0) {
|
||||
- WD_ERR("Invalid async poll number (%ld) is set.\n",
|
||||
+ if (!config_numa->async_poll_num) {
|
||||
+ WD_ERR("invalid async poll num (%lu) is set.\n",
|
||||
config_numa->async_poll_num);
|
||||
- WD_ERR("Change to default value: %d\n", WD_ASYNC_DEF_POLL_NUM);
|
||||
+ WD_ERR("change to default value: %d\n", WD_ASYNC_DEF_POLL_NUM);
|
||||
config_numa->async_poll_num = WD_ASYNC_DEF_POLL_NUM;
|
||||
}
|
||||
|
||||
+ poll_thread_num = config_numa->async_poll_num;
|
||||
+ if (poll_thread_num > config_numa->async_ctx_num) {
|
||||
+ poll_thread_num = config_numa->async_ctx_num;
|
||||
+ WD_ERR("downgrade poll thread num from %lu to %lu.\n",
|
||||
+ config_numa->async_poll_num,
|
||||
+ config_numa->async_ctx_num);
|
||||
+ }
|
||||
+
|
||||
/* make max task queues as the number of async ctxs */
|
||||
- task_queue = calloc(config_numa->async_ctx_num, sizeof(*head));
|
||||
- if (!task_queue)
|
||||
+ queue_head = calloc(config_numa->async_ctx_num, sizeof(*queue_head));
|
||||
+ if (!queue_head)
|
||||
return -WD_ENOMEM;
|
||||
- head = task_queue;
|
||||
- config_numa->async_task_queue_array = (void *)head;
|
||||
|
||||
- if (config_numa->async_poll_num > config_numa->async_ctx_num) {
|
||||
- n = config_numa->async_ctx_num;
|
||||
- WD_ERR("Can't create more async polling threads than the "
|
||||
- "number of ctx number. Downgrade it from %ld to %ld.\n",
|
||||
- config_numa->async_poll_num,
|
||||
- config_numa->async_ctx_num);
|
||||
- } else
|
||||
- n = config_numa->async_poll_num;
|
||||
- for (i = 0; i < n; task_queue++, i++) {
|
||||
+ task_queue = queue_head;
|
||||
+ for (i = 0; i < poll_thread_num; task_queue++, i++) {
|
||||
ret = wd_init_one_task_queue(task_queue, config->alg_poll_ctx);
|
||||
if (ret) {
|
||||
- task_queue = head;
|
||||
for (j = 0; j < i; task_queue++, j++)
|
||||
wd_uninit_one_task_queue(task_queue);
|
||||
- free(head);
|
||||
+ free(queue_head);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
+ config_numa->async_task_queue_array = (void *)queue_head;
|
||||
+
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1322,10 +1333,10 @@ static void wd_uninit_async_polling_thread_per_numa(struct wd_env_config *cfg,
|
||||
|
||||
head = config_numa->async_task_queue_array;
|
||||
task_queue = head;
|
||||
+ n = config_numa->async_poll_num;
|
||||
if (config_numa->async_poll_num > config_numa->async_ctx_num)
|
||||
n = config_numa->async_ctx_num;
|
||||
- else
|
||||
- n = config_numa->async_poll_num;
|
||||
+
|
||||
for (i = 0; i < n; task_queue++, i++)
|
||||
wd_uninit_one_task_queue(task_queue);
|
||||
free(head);
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,37 +0,0 @@
|
||||
From 09db34533df0920fe0102e85ab573038ad69bf2d Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 30 Dec 2021 20:34:50 +0800
|
||||
Subject: [PATCH 24/28] uadk: v1: delete unused parameter
|
||||
|
||||
capa is not used in copy_if_better.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
v1/wd.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/v1/wd.c b/v1/wd.c
|
||||
index 6568243..26f6692 100644
|
||||
--- a/v1/wd.c
|
||||
+++ b/v1/wd.c
|
||||
@@ -349,7 +349,7 @@ static int get_dev_info(struct dev_info *dinfo, const char *alg)
|
||||
}
|
||||
|
||||
static bool copy_if_better(struct dev_info *old, struct dev_info *new,
|
||||
- struct wd_capa *capa, unsigned int node_mask)
|
||||
+ unsigned int node_mask)
|
||||
{
|
||||
bool find_node = false;
|
||||
|
||||
@@ -437,7 +437,7 @@ static int find_available_dev(struct dev_info *dinfop,
|
||||
ret = get_dev_info(&dinfo, capa->alg);
|
||||
if (!ret) {
|
||||
cnt++;
|
||||
- if (copy_if_better(dinfop, &dinfo, capa, node_mask)) {
|
||||
+ if (copy_if_better(dinfop, &dinfo, node_mask)) {
|
||||
find_node = true;
|
||||
break;
|
||||
}
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,212 +0,0 @@
|
||||
From d827ac994867b2dd06d5723d62c6c618f0c5c77b Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 30 Dec 2021 20:34:51 +0800
|
||||
Subject: [PATCH 25/28] uadk: env: fix wd_add_task_to_async_queue return value
|
||||
|
||||
wd_add_task_to_async_queue may fail with error code,
|
||||
add return value check after call it.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_aead.c | 10 ++++++++--
|
||||
wd_cipher.c | 10 ++++++++--
|
||||
wd_comp.c | 4 +++-
|
||||
wd_dh.c | 6 ++++--
|
||||
wd_digest.c | 11 ++++++++---
|
||||
wd_ecc.c | 6 ++++--
|
||||
wd_rsa.c | 6 ++++--
|
||||
wd_util.c | 20 +++++++++++++-------
|
||||
8 files changed, 52 insertions(+), 21 deletions(-)
|
||||
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index f93f791..ebad440 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -596,11 +596,17 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req)
|
||||
if (ret != -WD_EBUSY)
|
||||
WD_ERR("failed to send BD, hw is err!\n");
|
||||
|
||||
- wd_put_msg_to_pool(&wd_aead_setting.pool, idx, msg->tag);
|
||||
+ goto fail_with_msg;
|
||||
}
|
||||
|
||||
- wd_add_task_to_async_queue(&wd_aead_env_config, idx);
|
||||
+ ret = wd_add_task_to_async_queue(&wd_aead_env_config, idx);
|
||||
+ if (ret)
|
||||
+ goto fail_with_msg;
|
||||
+
|
||||
+ return 0;
|
||||
|
||||
+fail_with_msg:
|
||||
+ wd_put_msg_to_pool(&wd_aead_setting.pool, idx, msg->tag);
|
||||
return ret;
|
||||
}
|
||||
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index 9977765..9c1f98c 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -515,11 +515,17 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req)
|
||||
if (ret != -WD_EBUSY)
|
||||
WD_ERR("wd cipher async send err!\n");
|
||||
|
||||
- wd_put_msg_to_pool(&wd_cipher_setting.pool, idx, msg->tag);
|
||||
+ goto fail_with_msg;
|
||||
}
|
||||
|
||||
- wd_add_task_to_async_queue(&wd_cipher_env_config, idx);
|
||||
+ ret = wd_add_task_to_async_queue(&wd_cipher_env_config, idx);
|
||||
+ if (ret)
|
||||
+ goto fail_with_msg;
|
||||
+
|
||||
+ return 0;
|
||||
|
||||
+fail_with_msg:
|
||||
+ wd_put_msg_to_pool(&wd_cipher_setting.pool, idx, msg->tag);
|
||||
return ret;
|
||||
}
|
||||
|
||||
diff --git a/wd_comp.c b/wd_comp.c
|
||||
index e34d590..fc355a9 100644
|
||||
--- a/wd_comp.c
|
||||
+++ b/wd_comp.c
|
||||
@@ -724,7 +724,9 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
|
||||
|
||||
pthread_spin_unlock(&ctx->lock);
|
||||
|
||||
- wd_add_task_to_async_queue(&wd_comp_env_config, idx);
|
||||
+ ret = wd_add_task_to_async_queue(&wd_comp_env_config, idx);
|
||||
+ if (ret)
|
||||
+ wd_put_msg_to_pool(&wd_comp_setting.pool, idx, msg->tag);
|
||||
|
||||
return ret;
|
||||
}
|
||||
diff --git a/wd_dh.c b/wd_dh.c
|
||||
index 177ffad..7b849ac 100644
|
||||
--- a/wd_dh.c
|
||||
+++ b/wd_dh.c
|
||||
@@ -341,9 +341,11 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req)
|
||||
}
|
||||
pthread_spin_unlock(&ctx->lock);
|
||||
|
||||
- wd_add_task_to_async_queue(&wd_dh_env_config, idx);
|
||||
+ ret = wd_add_task_to_async_queue(&wd_dh_env_config, idx);
|
||||
+ if (ret)
|
||||
+ goto fail_with_msg;
|
||||
|
||||
- return ret;
|
||||
+ return 0;
|
||||
|
||||
fail_with_msg:
|
||||
wd_put_msg_to_pool(&wd_dh_setting.pool, idx, mid);
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index bbb258f..2b3661d 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -420,13 +420,18 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req)
|
||||
if (ret != -WD_EBUSY)
|
||||
WD_ERR("failed to send BD, hw is err!\n");
|
||||
|
||||
- wd_put_msg_to_pool(&wd_digest_setting.pool, idx, msg->tag);
|
||||
- return ret;
|
||||
+ goto fail_with_msg;
|
||||
}
|
||||
|
||||
- wd_add_task_to_async_queue(&wd_digest_env_config, idx);
|
||||
+ ret = wd_add_task_to_async_queue(&wd_digest_env_config, idx);
|
||||
+ if (ret)
|
||||
+ goto fail_with_msg;
|
||||
|
||||
return 0;
|
||||
+
|
||||
+fail_with_msg:
|
||||
+ wd_put_msg_to_pool(&wd_digest_setting.pool, idx, msg->tag);
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
||||
diff --git a/wd_ecc.c b/wd_ecc.c
|
||||
index 8b625e4..e37fb39 100644
|
||||
--- a/wd_ecc.c
|
||||
+++ b/wd_ecc.c
|
||||
@@ -2187,9 +2187,11 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req)
|
||||
}
|
||||
pthread_spin_unlock(&ctx->lock);
|
||||
|
||||
- wd_add_task_to_async_queue(&wd_ecc_env_config, idx);
|
||||
+ ret = wd_add_task_to_async_queue(&wd_ecc_env_config, idx);
|
||||
+ if (ret)
|
||||
+ goto fail_with_msg;
|
||||
|
||||
- return ret;
|
||||
+ return 0;
|
||||
|
||||
fail_with_msg:
|
||||
wd_put_msg_to_pool(&wd_ecc_setting.pool, idx, mid);
|
||||
diff --git a/wd_rsa.c b/wd_rsa.c
|
||||
index 2831111..b6cc0d1 100644
|
||||
--- a/wd_rsa.c
|
||||
+++ b/wd_rsa.c
|
||||
@@ -397,9 +397,11 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req)
|
||||
if (ret)
|
||||
goto fail_with_msg;
|
||||
|
||||
- wd_add_task_to_async_queue(&wd_rsa_env_config, idx);
|
||||
+ ret = wd_add_task_to_async_queue(&wd_rsa_env_config, idx);
|
||||
+ if (ret)
|
||||
+ goto fail_with_msg;
|
||||
|
||||
- return ret;
|
||||
+ return 0;
|
||||
|
||||
fail_with_msg:
|
||||
wd_put_msg_to_pool(&wd_rsa_setting.pool, idx, mid);
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 49e1d66..e04747b 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -1108,17 +1108,20 @@ int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx)
|
||||
{
|
||||
struct async_task_queue *task_queue;
|
||||
struct async_task *head, *task;
|
||||
- int prod;
|
||||
+ int prod, ret;
|
||||
|
||||
if (!config->enable_internal_poll)
|
||||
return 0;
|
||||
|
||||
task_queue = find_async_queue(config, idx);
|
||||
if (!task_queue)
|
||||
- return 0;
|
||||
+ return -WD_EINVAL;
|
||||
|
||||
- if (sem_wait(&task_queue->empty_sem))
|
||||
- return 0;
|
||||
+ ret = sem_wait(&task_queue->empty_sem);
|
||||
+ if (ret) {
|
||||
+ WD_ERR("failed to wait empty_sem!\n");
|
||||
+ return ret;
|
||||
+ }
|
||||
|
||||
pthread_mutex_lock(&task_queue->lock);
|
||||
|
||||
@@ -1135,10 +1138,13 @@ int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx)
|
||||
|
||||
pthread_mutex_unlock(&task_queue->lock);
|
||||
|
||||
- if (sem_post(&task_queue->full_sem))
|
||||
- return 0;
|
||||
+ ret = sem_post(&task_queue->full_sem);
|
||||
+ if (ret) {
|
||||
+ WD_ERR("failed to post full_sem!\n");
|
||||
+ return ret;
|
||||
+ }
|
||||
|
||||
- return 1;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static void *async_poll_process_func(void *args)
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
From 3ccff1938ec43efa1a4bb3f367d1985e35b91c0e Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 30 Dec 2021 20:34:52 +0800
|
||||
Subject: [PATCH 26/28] uadk: sched: fix memory leak
|
||||
|
||||
sched_ctx and sched must be associated to
|
||||
release the memory of sched_ctx
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_sched.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/wd_sched.c b/wd_sched.c
|
||||
index f97c15f..a85fd95 100644
|
||||
--- a/wd_sched.c
|
||||
+++ b/wd_sched.c
|
||||
@@ -463,6 +463,7 @@ struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num,
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
+ sched->h_sched_ctx = (handle_t)sched_ctx;
|
||||
sched_info = sched_ctx->sched_info;
|
||||
|
||||
for (i = 0; i < numa_num; i++) {
|
||||
@@ -482,7 +483,6 @@ struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num,
|
||||
sched->sched_init = sched_table[sched_type].sched_init;
|
||||
sched->pick_next_ctx = sched_table[sched_type].pick_next_ctx;
|
||||
sched->poll_policy = sched_table[sched_type].poll_policy;
|
||||
- sched->h_sched_ctx = (handle_t)sched_ctx;
|
||||
|
||||
return sched;
|
||||
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,47 +0,0 @@
|
||||
From 5927f19669247d738dfd4a687b5f134a2d289784 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Wed, 29 Dec 2021 17:14:11 +0800
|
||||
Subject: [PATCH 27/28] hisi-sec: bugfix for out_bytes checking
|
||||
|
||||
1. Add out_bytes checking for digest alg. and modify some log
|
||||
information.
|
||||
2. Optimize the in_bytes length checking.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 11 ++++++++---
|
||||
1 file changed, 8 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index 603bdda..d31a1b9 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -1279,9 +1279,9 @@ static void parse_digest_bd2(struct hisi_sec_sqe *sqe, struct wd_digest_msg *rec
|
||||
|
||||
static int digest_long_bd_check(struct wd_digest_msg *msg)
|
||||
{
|
||||
- if (msg->alg >= WD_DIGEST_SHA512 && msg->in_bytes % SHA512_ALIGN_SZ)
|
||||
+ if (msg->alg >= WD_DIGEST_SHA512 && msg->in_bytes & (SHA512_ALIGN_SZ - 1))
|
||||
return -WD_EINVAL;
|
||||
- else if (msg->in_bytes % SHA1_ALIGN_SZ)
|
||||
+ else if (msg->in_bytes & (SHA1_ALIGN_SZ - 1))
|
||||
return -WD_EINVAL;
|
||||
|
||||
return 0;
|
||||
@@ -1298,7 +1298,12 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
|
||||
}
|
||||
|
||||
if (unlikely(msg->in_bytes > MAX_INPUT_DATA_LEN)) {
|
||||
- WD_ERR("input data length is too long, size:%u!\n", msg->in_bytes);
|
||||
+ WD_ERR("digest input length is too long, size:%u!\n", msg->in_bytes);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ if (unlikely(msg->out_bytes & WORD_ALIGNMENT_MASK)) {
|
||||
+ WD_ERR("digest out length is error, size:%u!\n", msg->out_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,421 +0,0 @@
|
||||
From 0ec02e23cfc86ea664905a11b28635cab12ee29a Mon Sep 17 00:00:00 2001
|
||||
From: Liulongfang <liulongfang@foxmail.com>
|
||||
Date: Wed, 5 Jan 2022 14:46:54 +0800
|
||||
Subject: [PATCH 29/53] uadk/tools: modify NO-SVA test scenario
|
||||
|
||||
In the No-SVA scenario, the user's business data needs to be copied
|
||||
from the user memory to the block memory allocated by the user mode
|
||||
through the copy method.
|
||||
After the business execution is completed, it needs to be copied back.
|
||||
The test tool should truly reflect the copy operation process.
|
||||
|
||||
Signed-off-by: Liulongfang <liulongfang@foxmail.com>
|
||||
---
|
||||
uadk_tool/Makefile.am | 2 +-
|
||||
uadk_tool/sec_wd_benchmark.c | 122 +++++++++++++++++++++++++++++------
|
||||
uadk_tool/uadk_benchmark.c | 2 +-
|
||||
3 files changed, 103 insertions(+), 23 deletions(-)
|
||||
|
||||
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am
|
||||
index 36536a2..f79a6e3 100644
|
||||
--- a/uadk_tool/Makefile.am
|
||||
+++ b/uadk_tool/Makefile.am
|
||||
@@ -16,7 +16,7 @@ uadk_tool_LDADD=$(libwd_la_OBJECTS) \
|
||||
../.libs/libhisi_sec.a \
|
||||
../.libs/libhisi_hpre.a \
|
||||
../.libs/libhisi_zip.a \
|
||||
- include/libcrypto.a -ldl -lnuma
|
||||
+ $(top_srcdir)/uadk_tool/include/libcrypto.a -ldl -lnuma
|
||||
else
|
||||
uadk_tool_LDADD=-L../.libs -l:libwd.so.2 -l:libwd_crypto.so.2 \
|
||||
-L$(top_srcdir)/uadk_tool/include -l:libcrypto.so.1.1 -lnuma
|
||||
diff --git a/uadk_tool/sec_wd_benchmark.c b/uadk_tool/sec_wd_benchmark.c
|
||||
index c650e9a..dffd3a7 100644
|
||||
--- a/uadk_tool/sec_wd_benchmark.c
|
||||
+++ b/uadk_tool/sec_wd_benchmark.c
|
||||
@@ -36,6 +36,7 @@ struct thread_queue_res {
|
||||
|
||||
struct wcrypto_async_tag {
|
||||
void *ctx;
|
||||
+ char *out_buf;
|
||||
int thread_id;
|
||||
int cnt;
|
||||
};
|
||||
@@ -54,17 +55,34 @@ static unsigned int g_pktlen;
|
||||
|
||||
static void *cipher_async_cb(void *message, void *cipher_tag)
|
||||
{
|
||||
+ struct wcrypto_async_tag *async_tag = (struct wcrypto_async_tag *)cipher_tag;
|
||||
+ struct wcrypto_cipher_msg *req = (struct wcrypto_cipher_msg *)message;
|
||||
+
|
||||
+ // no-sva data copy from uadk to user
|
||||
+ memcpy(async_tag->out_buf, req->out, g_pktlen);
|
||||
+
|
||||
return NULL;
|
||||
}
|
||||
|
||||
-static void *aead_async_cb(void *message, void *cipher_tag)
|
||||
+static void *aead_async_cb(void *message, void *aead_tag)
|
||||
{
|
||||
+ struct wcrypto_async_tag *async_tag = (struct wcrypto_async_tag *)aead_tag;
|
||||
+ struct wcrypto_aead_msg *req = (struct wcrypto_aead_msg *)message;
|
||||
+
|
||||
+ // no-sva data copy from uadk to user
|
||||
+ memcpy(async_tag->out_buf, req->out, g_pktlen);
|
||||
+
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *digest_async_cb(void *message, void *digest_tag)
|
||||
{
|
||||
- // struct WCRYPTO_req *req = (struct WCRYPTO_req *)data;
|
||||
+ struct wcrypto_async_tag *async_tag = (struct wcrypto_async_tag *)digest_tag;
|
||||
+ struct wcrypto_digest_msg *req = (struct wcrypto_digest_msg *)message;
|
||||
+
|
||||
+ // no-sva data copy from uadk to user
|
||||
+ memcpy(async_tag->out_buf, req->out, 16);
|
||||
+
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -563,6 +581,8 @@ static void *sec_wd_async_run(void *arg)
|
||||
struct wcrypto_async_tag *tag = NULL;
|
||||
char priv_key[MAX_IVK_LENTH];
|
||||
struct thread_bd_res *bd_res;
|
||||
+ char *src_data_buf = NULL;
|
||||
+ char *out_data_buf = NULL;
|
||||
struct wd_queue *queue;
|
||||
void *ctx = NULL;
|
||||
void **res_in;
|
||||
@@ -584,13 +604,27 @@ static void *sec_wd_async_run(void *arg)
|
||||
res_out = bd_res->out;
|
||||
res_iv = bd_res->iv;
|
||||
|
||||
+ /* create user data buffer */
|
||||
+ src_data_buf = malloc(g_pktlen * sizeof(char));
|
||||
+ if (!src_data_buf)
|
||||
+ return NULL;
|
||||
+
|
||||
+ get_rand_data(src_data_buf, g_pktlen);
|
||||
+ out_data_buf = malloc(g_pktlen * sizeof(char));
|
||||
+ if (!out_data_buf) {
|
||||
+ free(src_data_buf);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
|
||||
tag = malloc(sizeof(struct wcrypto_async_tag)); // set the user tag
|
||||
if (!tag) {
|
||||
SEC_TST_PRT("wcrypto async alloc tag fail!\n");
|
||||
+ free(src_data_buf);
|
||||
+ free(out_data_buf);
|
||||
return NULL;
|
||||
}
|
||||
- tag->thread_id = pdata->td_id;
|
||||
+ tag->out_buf = out_data_buf;
|
||||
|
||||
switch(pdata->subtype) {
|
||||
case CIPHER_TYPE:
|
||||
@@ -607,7 +641,7 @@ static void *sec_wd_async_run(void *arg)
|
||||
ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup);
|
||||
if (!ctx) {
|
||||
SEC_TST_PRT("wd create cipher ctx fail!\n");
|
||||
- return NULL;
|
||||
+ goto async_err;
|
||||
}
|
||||
tag->ctx = ctx;
|
||||
|
||||
@@ -615,7 +649,7 @@ static void *sec_wd_async_run(void *arg)
|
||||
if (ret) {
|
||||
SEC_TST_PRT("wd cipher set key fail!\n");
|
||||
wcrypto_del_cipher_ctx(ctx);
|
||||
- return NULL;
|
||||
+ goto async_err;
|
||||
}
|
||||
|
||||
if (queue->capa.priv.direction == 0)
|
||||
@@ -637,6 +671,9 @@ static void *sec_wd_async_run(void *arg)
|
||||
if (get_run_state() == 0)
|
||||
break;
|
||||
|
||||
+ // no-sva data copy to uadk
|
||||
+ memcpy(copdata.in, src_data_buf, g_pktlen);
|
||||
+
|
||||
ret = wcrypto_do_cipher(ctx, &copdata, (void *)tag);
|
||||
if (ret == -WD_EBUSY) {
|
||||
usleep(SEND_USLEEP * try_cnt);
|
||||
@@ -672,7 +709,7 @@ static void *sec_wd_async_run(void *arg)
|
||||
ctx = wcrypto_create_aead_ctx(queue, &aead_setup);
|
||||
if (!ctx) {
|
||||
SEC_TST_PRT("wd create aead ctx fail!\n");
|
||||
- return NULL;
|
||||
+ goto async_err;
|
||||
}
|
||||
tag->ctx = ctx;
|
||||
|
||||
@@ -680,7 +717,7 @@ static void *sec_wd_async_run(void *arg)
|
||||
if (ret) {
|
||||
SEC_TST_PRT("wd aead set key fail!\n");
|
||||
wcrypto_del_aead_ctx(ctx);
|
||||
- return NULL;
|
||||
+ goto async_err;
|
||||
}
|
||||
|
||||
authsize = 16; //set defaut size
|
||||
@@ -688,7 +725,7 @@ static void *sec_wd_async_run(void *arg)
|
||||
if (ret) {
|
||||
SEC_TST_PRT("set authsize fail!\n");
|
||||
wcrypto_del_aead_ctx(ctx);
|
||||
- return NULL;
|
||||
+ goto async_err;
|
||||
}
|
||||
|
||||
if (queue->capa.priv.direction == 0) {
|
||||
@@ -715,6 +752,9 @@ static void *sec_wd_async_run(void *arg)
|
||||
if (get_run_state() == 0)
|
||||
break;
|
||||
|
||||
+ // no-sva data copy to uadk
|
||||
+ memcpy(aopdata.in, src_data_buf, g_pktlen);
|
||||
+
|
||||
ret = wcrypto_do_aead(ctx, &aopdata, (void *)tag);
|
||||
if (ret == -WD_EBUSY) {
|
||||
usleep(SEND_USLEEP * try_cnt);
|
||||
@@ -750,7 +790,7 @@ static void *sec_wd_async_run(void *arg)
|
||||
ctx = wcrypto_create_digest_ctx(queue, &digest_setup);
|
||||
if (!ctx) {
|
||||
SEC_TST_PRT("wd create digest ctx fail!\n");
|
||||
- return NULL;
|
||||
+ goto async_err;
|
||||
}
|
||||
tag->ctx = ctx;
|
||||
|
||||
@@ -760,7 +800,7 @@ static void *sec_wd_async_run(void *arg)
|
||||
if (ret) {
|
||||
SEC_TST_PRT("wd digest set key fail!\n");
|
||||
wcrypto_del_digest_ctx(ctx);
|
||||
- return NULL;
|
||||
+ goto async_err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -777,6 +817,9 @@ static void *sec_wd_async_run(void *arg)
|
||||
if (get_run_state() == 0)
|
||||
break;
|
||||
|
||||
+ // no-sva data copy to uadk
|
||||
+ memcpy(dopdata.in, src_data_buf, g_pktlen);
|
||||
+
|
||||
ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag);
|
||||
if (ret == -WD_EBUSY) {
|
||||
usleep(SEND_USLEEP * try_cnt);
|
||||
@@ -802,7 +845,7 @@ static void *sec_wd_async_run(void *arg)
|
||||
add_send_complete();
|
||||
|
||||
while (1) {
|
||||
- if (get_recv_time() > 0) // wait Async mode finish recv
|
||||
+ if (get_recv_time() == g_thread_num) // wait Async mode finish recv
|
||||
break;
|
||||
usleep(SEND_USLEEP);
|
||||
}
|
||||
@@ -819,6 +862,10 @@ static void *sec_wd_async_run(void *arg)
|
||||
break;
|
||||
}
|
||||
|
||||
+async_err:
|
||||
+ free(tag);
|
||||
+ free(src_data_buf);
|
||||
+ free(out_data_buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -834,6 +881,8 @@ static void *sec_wd_sync_run(void *arg)
|
||||
char priv_key[MAX_IVK_LENTH];
|
||||
struct thread_bd_res *bd_res;
|
||||
struct wd_queue *queue;
|
||||
+ char *src_data_buf = NULL;
|
||||
+ char *out_data_buf = NULL;
|
||||
void *ctx = NULL;
|
||||
void *tag = NULL;
|
||||
void **res_in;
|
||||
@@ -855,6 +904,18 @@ static void *sec_wd_sync_run(void *arg)
|
||||
res_out = bd_res->out;
|
||||
res_iv = bd_res->iv;
|
||||
|
||||
+ /* create user data buffer */
|
||||
+ src_data_buf = malloc(g_pktlen * sizeof(char));
|
||||
+ if (!src_data_buf)
|
||||
+ return NULL;
|
||||
+
|
||||
+ get_rand_data(src_data_buf, g_pktlen);
|
||||
+ out_data_buf = malloc(g_pktlen * sizeof(char));
|
||||
+ if (!out_data_buf) {
|
||||
+ free(src_data_buf);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
|
||||
|
||||
switch(pdata->subtype) {
|
||||
@@ -871,14 +932,14 @@ static void *sec_wd_sync_run(void *arg)
|
||||
ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup);
|
||||
if (!ctx) {
|
||||
SEC_TST_PRT("wd create cipher ctx fail!\n");
|
||||
- return NULL;
|
||||
+ goto sync_err;
|
||||
}
|
||||
|
||||
ret = wcrypto_set_cipher_key(ctx, (__u8*)priv_key, (__u16)pdata->keysize);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("wd cipher set key fail!\n");
|
||||
wcrypto_del_cipher_ctx(ctx);
|
||||
- return NULL;
|
||||
+ goto sync_err;
|
||||
}
|
||||
|
||||
if (queue->capa.priv.direction == 0)
|
||||
@@ -899,6 +960,9 @@ static void *sec_wd_sync_run(void *arg)
|
||||
if (get_run_state() == 0)
|
||||
break;
|
||||
|
||||
+ // no-sva data copy to uadk
|
||||
+ memcpy(copdata.in, src_data_buf, g_pktlen);
|
||||
+
|
||||
ret = wcrypto_do_cipher(ctx, &copdata, tag);
|
||||
if (ret == -WD_EBUSY) {
|
||||
usleep(SEND_USLEEP * try_cnt);
|
||||
@@ -916,6 +980,9 @@ static void *sec_wd_sync_run(void *arg)
|
||||
copdata.in = res_in[i];
|
||||
copdata.out = res_out[i];
|
||||
copdata.iv = res_iv[i];
|
||||
+
|
||||
+ // no-sva data copy from uadk to user
|
||||
+ memcpy(out_data_buf, copdata.out, g_pktlen);
|
||||
}
|
||||
wcrypto_del_cipher_ctx(ctx);
|
||||
|
||||
@@ -933,14 +1000,14 @@ static void *sec_wd_sync_run(void *arg)
|
||||
ctx = wcrypto_create_aead_ctx(queue, &aead_setup);
|
||||
if (!ctx) {
|
||||
SEC_TST_PRT("wd create aead ctx fail!\n");
|
||||
- return NULL;
|
||||
+ goto sync_err;
|
||||
}
|
||||
|
||||
ret = wcrypto_set_aead_ckey(ctx, (__u8*)priv_key, (__u16)pdata->keysize);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("wd aead set key fail!\n");
|
||||
wcrypto_del_aead_ctx(ctx);
|
||||
- return NULL;
|
||||
+ goto sync_err;
|
||||
}
|
||||
|
||||
authsize = 16; //set defaut size
|
||||
@@ -948,7 +1015,7 @@ static void *sec_wd_sync_run(void *arg)
|
||||
if (ret) {
|
||||
SEC_TST_PRT("set authsize fail!\n");
|
||||
wcrypto_del_aead_ctx(ctx);
|
||||
- return NULL;
|
||||
+ goto sync_err;
|
||||
}
|
||||
|
||||
if (queue->capa.priv.direction == 0) {
|
||||
@@ -974,6 +1041,9 @@ static void *sec_wd_sync_run(void *arg)
|
||||
if (get_run_state() == 0)
|
||||
break;
|
||||
|
||||
+ // no-sva data copy to uadk
|
||||
+ memcpy(aopdata.in, src_data_buf, g_pktlen);
|
||||
+
|
||||
ret = wcrypto_do_aead(ctx, &aopdata, tag);
|
||||
if (ret == -WD_EBUSY) {
|
||||
usleep(SEND_USLEEP * try_cnt);
|
||||
@@ -991,6 +1061,9 @@ static void *sec_wd_sync_run(void *arg)
|
||||
aopdata.in = res_in[i];
|
||||
aopdata.out = res_out[i];
|
||||
aopdata.iv = res_iv[i];
|
||||
+
|
||||
+ // no-sva data copy from uadk to user
|
||||
+ memcpy(out_data_buf, aopdata.out, g_pktlen);
|
||||
}
|
||||
wcrypto_del_aead_ctx(ctx);
|
||||
|
||||
@@ -1008,7 +1081,7 @@ static void *sec_wd_sync_run(void *arg)
|
||||
ctx = wcrypto_create_digest_ctx(queue, &digest_setup);
|
||||
if (!ctx) {
|
||||
SEC_TST_PRT("wd create digest ctx fail!\n");
|
||||
- return NULL;
|
||||
+ goto sync_err;
|
||||
}
|
||||
|
||||
if (digest_setup.mode == WCRYPTO_DIGEST_HMAC) {
|
||||
@@ -1017,7 +1090,7 @@ static void *sec_wd_sync_run(void *arg)
|
||||
if (ret) {
|
||||
SEC_TST_PRT("wd digest set key fail!\n");
|
||||
wcrypto_del_digest_ctx(ctx);
|
||||
- return NULL;
|
||||
+ goto sync_err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1033,6 +1106,9 @@ static void *sec_wd_sync_run(void *arg)
|
||||
if (get_run_state() == 0)
|
||||
break;
|
||||
|
||||
+ // no-sva data copy to uadk
|
||||
+ memcpy(dopdata.in, src_data_buf, g_pktlen);
|
||||
+
|
||||
ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag);
|
||||
if (ret == -WD_EBUSY) {
|
||||
usleep(SEND_USLEEP * try_cnt);
|
||||
@@ -1048,7 +1124,10 @@ static void *sec_wd_sync_run(void *arg)
|
||||
try_cnt = 0;
|
||||
i = count % MAX_BLOCK_NM;
|
||||
dopdata.in = res_in[i];
|
||||
- dopdata.out = res_out[i];
|
||||
+ dopdata.out = res_out[i];
|
||||
+
|
||||
+ // no-sva data copy from uadk to user
|
||||
+ memcpy(out_data_buf, dopdata.out, 16);
|
||||
}
|
||||
wcrypto_del_digest_ctx(ctx);
|
||||
break;
|
||||
@@ -1056,6 +1135,9 @@ static void *sec_wd_sync_run(void *arg)
|
||||
|
||||
add_recv_data(count);
|
||||
|
||||
+sync_err:
|
||||
+ free(src_data_buf);
|
||||
+ free(out_data_buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1097,7 +1179,6 @@ int sec_wd_sync_threads(struct acc_option *options)
|
||||
|
||||
sync_error:
|
||||
return ret;
|
||||
-
|
||||
}
|
||||
|
||||
int sec_wd_async_threads(struct acc_option *options)
|
||||
@@ -1185,4 +1266,3 @@ int sec_wd_benchmark(struct acc_option *options)
|
||||
|
||||
return 0;
|
||||
}
|
||||
-
|
||||
diff --git a/uadk_tool/uadk_benchmark.c b/uadk_tool/uadk_benchmark.c
|
||||
index 5773b2c..8067ed7 100644
|
||||
--- a/uadk_tool/uadk_benchmark.c
|
||||
+++ b/uadk_tool/uadk_benchmark.c
|
||||
@@ -551,7 +551,7 @@ static void print_help(void)
|
||||
ACC_TST_PRT(" [--seconds]:\n");
|
||||
ACC_TST_PRT(" set the test times\n");
|
||||
ACC_TST_PRT(" [--multi]:\n");
|
||||
- ACC_TST_PRT(" set the number of threads\n");
|
||||
+ ACC_TST_PRT(" set the number of process\n");
|
||||
ACC_TST_PRT(" [--thread]:\n");
|
||||
ACC_TST_PRT(" set the number of threads\n");
|
||||
ACC_TST_PRT(" [--ctxnum]:\n");
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
From 4478ede7a98cc9f84b30bb5766007b2acbec1a2f Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 4 Jan 2022 12:20:32 +0800
|
||||
Subject: [PATCH 30/53] wd: fix wd_parse_async_poll_num
|
||||
|
||||
skip parse poll number if inner poll is not enabled.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_util.c | 5 +++++
|
||||
1 file changed, 5 insertions(+)
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index e04747b..58463e9 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -759,6 +759,11 @@ int wd_parse_async_poll_num(struct wd_env_config *config, const char *s)
|
||||
char *left, *section, *start;
|
||||
int node, poll_num, ret;
|
||||
|
||||
+ if (!config->enable_internal_poll) {
|
||||
+ WD_ERR("internal poll not enabled, skip parse poll number!\n");
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
start = strdup(s);
|
||||
if (!start)
|
||||
return -ENOMEM;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,81 +0,0 @@
|
||||
From 8094e7a2344cf558eb056e7afc153299a3642f39 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 4 Jan 2022 12:20:28 +0800
|
||||
Subject: [PATCH 31/53] uadk: optimize wd_init_async_polling_thread_per_numa
|
||||
|
||||
use fmin to get poll thread num.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_util.c | 23 +++++++++--------------
|
||||
1 file changed, 9 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 58463e9..fd132aa 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <semaphore.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
+#include <math.h>
|
||||
#include "wd_alg_common.h"
|
||||
#include "wd_util.h"
|
||||
#include "wd_sched.h"
|
||||
@@ -1295,7 +1296,8 @@ static int wd_init_async_polling_thread_per_numa(struct wd_env_config *config,
|
||||
struct wd_env_config_per_numa *config_numa)
|
||||
{
|
||||
struct async_task_queue *task_queue, *queue_head;
|
||||
- int i, j, poll_thread_num, ret;
|
||||
+ int i, j, ret;
|
||||
+ double num;
|
||||
|
||||
if (!config_numa->async_ctx_num)
|
||||
return 0;
|
||||
@@ -1307,13 +1309,7 @@ static int wd_init_async_polling_thread_per_numa(struct wd_env_config *config,
|
||||
config_numa->async_poll_num = WD_ASYNC_DEF_POLL_NUM;
|
||||
}
|
||||
|
||||
- poll_thread_num = config_numa->async_poll_num;
|
||||
- if (poll_thread_num > config_numa->async_ctx_num) {
|
||||
- poll_thread_num = config_numa->async_ctx_num;
|
||||
- WD_ERR("downgrade poll thread num from %lu to %lu.\n",
|
||||
- config_numa->async_poll_num,
|
||||
- config_numa->async_ctx_num);
|
||||
- }
|
||||
+ num = fmin(config_numa->async_poll_num, config_numa->async_ctx_num);
|
||||
|
||||
/* make max task queues as the number of async ctxs */
|
||||
queue_head = calloc(config_numa->async_ctx_num, sizeof(*queue_head));
|
||||
@@ -1321,7 +1317,7 @@ static int wd_init_async_polling_thread_per_numa(struct wd_env_config *config,
|
||||
return -WD_ENOMEM;
|
||||
|
||||
task_queue = queue_head;
|
||||
- for (i = 0; i < poll_thread_num; task_queue++, i++) {
|
||||
+ for (i = 0; i < num; task_queue++, i++) {
|
||||
ret = wd_init_one_task_queue(task_queue, config->alg_poll_ctx);
|
||||
if (ret) {
|
||||
for (j = 0; j < i; task_queue++, j++)
|
||||
@@ -1340,15 +1336,14 @@ static void wd_uninit_async_polling_thread_per_numa(struct wd_env_config *cfg,
|
||||
struct wd_env_config_per_numa *config_numa)
|
||||
{
|
||||
struct async_task_queue *task_queue, *head;
|
||||
- int i, n;
|
||||
+ double num;
|
||||
+ int i;
|
||||
|
||||
head = config_numa->async_task_queue_array;
|
||||
task_queue = head;
|
||||
- n = config_numa->async_poll_num;
|
||||
- if (config_numa->async_poll_num > config_numa->async_ctx_num)
|
||||
- n = config_numa->async_ctx_num;
|
||||
+ num = fmin(config_numa->async_poll_num, config_numa->async_ctx_num);
|
||||
|
||||
- for (i = 0; i < n; task_queue++, i++)
|
||||
+ for (i = 0; i < num; task_queue++, i++)
|
||||
wd_uninit_one_task_queue(task_queue);
|
||||
free(head);
|
||||
config_numa->async_task_queue_array = NULL;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,113 +0,0 @@
|
||||
From a3b74902cadf6dd671a093c6747a5bd624d09cc4 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 4 Jan 2022 12:20:29 +0800
|
||||
Subject: [PATCH 32/53] uadk: env: fix wd_add_task_to_async_queue
|
||||
|
||||
clear global information if an add task error occurred.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_util.c | 38 ++++++++++++++++++++++++--------------
|
||||
1 file changed, 24 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index fd132aa..676f475 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -45,7 +45,9 @@ struct async_task {
|
||||
struct async_task_queue {
|
||||
struct async_task *head;
|
||||
int depth;
|
||||
+ /* the producer offset of task queue */
|
||||
int prod;
|
||||
+ /* the consumer offset of task queue */
|
||||
int cons;
|
||||
int cur_task;
|
||||
int left_task;
|
||||
@@ -1113,8 +1115,8 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config,
|
||||
int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx)
|
||||
{
|
||||
struct async_task_queue *task_queue;
|
||||
- struct async_task *head, *task;
|
||||
- int prod, ret;
|
||||
+ struct async_task *task;
|
||||
+ int curr_prod, ret;
|
||||
|
||||
if (!config->enable_internal_poll)
|
||||
return 0;
|
||||
@@ -1131,14 +1133,13 @@ int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx)
|
||||
|
||||
pthread_mutex_lock(&task_queue->lock);
|
||||
|
||||
- prod = task_queue->prod;
|
||||
- head = task_queue->head;
|
||||
- task = head + prod;
|
||||
- /* fix me */
|
||||
+ /* get an available async task and fill ctx idx */
|
||||
+ curr_prod = task_queue->prod;
|
||||
+ task = task_queue->head + curr_prod;
|
||||
task->idx = idx;
|
||||
|
||||
- prod = (prod + 1) % task_queue->depth;
|
||||
- task_queue->prod = prod;
|
||||
+ /* update global information of task queue */
|
||||
+ task_queue->prod = (curr_prod + 1) % task_queue->depth;
|
||||
task_queue->cur_task++;
|
||||
task_queue->left_task--;
|
||||
|
||||
@@ -1147,10 +1148,19 @@ int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx)
|
||||
ret = sem_post(&task_queue->full_sem);
|
||||
if (ret) {
|
||||
WD_ERR("failed to post full_sem!\n");
|
||||
- return ret;
|
||||
+ goto err_out;
|
||||
}
|
||||
|
||||
return 0;
|
||||
+
|
||||
+err_out:
|
||||
+ pthread_mutex_lock(&task_queue->lock);
|
||||
+ task_queue->left_task++;
|
||||
+ task_queue->cur_task--;
|
||||
+ task_queue->prod = curr_prod;
|
||||
+ pthread_mutex_unlock(&task_queue->lock);
|
||||
+
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
static void *async_poll_process_func(void *args)
|
||||
@@ -1216,18 +1226,18 @@ static int wd_init_one_task_queue(struct async_task_queue *task_queue,
|
||||
void *alg_poll_ctx)
|
||||
|
||||
{
|
||||
- struct async_task *task_head;
|
||||
+ struct async_task *head;
|
||||
pthread_t thread_id;
|
||||
pthread_attr_t attr;
|
||||
int depth, ret;
|
||||
|
||||
task_queue->depth = depth = WD_ASYNC_DEF_QUEUE_DEPTH;
|
||||
|
||||
- task_head = calloc(task_queue->depth, sizeof(struct async_task));
|
||||
- if (!task_head)
|
||||
+ head = calloc(task_queue->depth, sizeof(*head));
|
||||
+ if (!head)
|
||||
return -WD_ENOMEM;
|
||||
|
||||
- task_queue->head = task_head;
|
||||
+ task_queue->head = head;
|
||||
task_queue->left_task = depth;
|
||||
task_queue->alg_poll_ctx = alg_poll_ctx;
|
||||
|
||||
@@ -1268,7 +1278,7 @@ err_uninit_full_sem:
|
||||
err_uninit_empty_sem:
|
||||
sem_destroy(&task_queue->empty_sem);
|
||||
err_free_head:
|
||||
- free(task_head);
|
||||
+ free(head);
|
||||
ret = -errno;
|
||||
return ret;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
From 72f58fe17adc3396a5c6826c5acf9a235b02b635 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 4 Jan 2022 12:20:30 +0800
|
||||
Subject: [PATCH 33/53] uadk: optimize find_async_queue
|
||||
|
||||
No need to determine offset size before modulo.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_util.c | 8 +++-----
|
||||
1 file changed, 3 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 676f475..9e96114 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -1069,7 +1069,7 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config,
|
||||
struct wd_env_config_per_numa *config_numa;
|
||||
struct wd_ctx_range **ctx_table;
|
||||
struct async_task_queue *head;
|
||||
- unsigned long offset;
|
||||
+ unsigned long offset = 0;
|
||||
int num = 0;
|
||||
int i;
|
||||
|
||||
@@ -1093,10 +1093,8 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config,
|
||||
for (i = 0; i < config_numa->op_type_num; i++) {
|
||||
if (idx <= ctx_table[CTX_MODE_ASYNC][i].end &&
|
||||
idx >= ctx_table[CTX_MODE_ASYNC][i].begin) {
|
||||
- offset = idx - ctx_table[CTX_MODE_ASYNC][i].begin;
|
||||
- if (offset >= config_numa->async_poll_num)
|
||||
- offset = offset % config_numa->async_poll_num;
|
||||
-
|
||||
+ offset = (idx - ctx_table[CTX_MODE_ASYNC][i].begin) %
|
||||
+ config_numa->async_poll_num;
|
||||
break;
|
||||
}
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
From e2b9b8fbf8ee1f8e9775b473de7ee464f32aed50 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 4 Jan 2022 12:20:27 +0800
|
||||
Subject: [PATCH 34/53] uadk: fix check_after_sink
|
||||
|
||||
No need to check last ret, it cause check_after_sink.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd.c | 8 ++------
|
||||
1 file changed, 2 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/wd.c b/wd.c
|
||||
index 25386d7..238ce8a 100644
|
||||
--- a/wd.c
|
||||
+++ b/wd.c
|
||||
@@ -171,11 +171,7 @@ static int get_dev_info(struct uacce_dev *dev)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
- ret = get_str_attr(dev, "algorithms", dev->algs, MAX_ATTR_STR_SIZE);
|
||||
- if (ret < 0)
|
||||
- return ret;
|
||||
-
|
||||
- return 0;
|
||||
+ return get_str_attr(dev, "algorithms", dev->algs, MAX_ATTR_STR_SIZE);
|
||||
}
|
||||
|
||||
static struct uacce_dev *read_uacce_sysfs(const char *dev_name)
|
||||
@@ -215,7 +211,7 @@ static struct uacce_dev *read_uacce_sysfs(const char *dev_name)
|
||||
goto out_dir;
|
||||
|
||||
ret = get_dev_info(dev);
|
||||
- if (ret) {
|
||||
+ if (ret < 0) {
|
||||
WD_ERR("failed to get dev info: ret = %d!\n", ret);
|
||||
goto out_dir;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
From 6ede569a63ce4f4ead3865b96c5dfff4e9b2fcaf Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 4 Jan 2022 16:48:01 +0800
|
||||
Subject: [PATCH 35/53] uadk: fix wd_request_ctx
|
||||
|
||||
wd_get_accel_name and strncpy should use relative path.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd.c | 6 +++---
|
||||
1 file changed, 3 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/wd.c b/wd.c
|
||||
index 238ce8a..746fa02 100644
|
||||
--- a/wd.c
|
||||
+++ b/wd.c
|
||||
@@ -328,11 +328,11 @@ handle_t wd_request_ctx(struct uacce_dev *dev)
|
||||
if (!ctx)
|
||||
return 0;
|
||||
|
||||
- ctx->dev_name = wd_get_accel_name(char_dev_path, 0);
|
||||
+ ctx->dev_name = wd_get_accel_name(dev->char_dev_path, 0);
|
||||
if (!ctx->dev_name)
|
||||
goto free_ctx;
|
||||
|
||||
- ctx->drv_name = wd_get_accel_name(char_dev_path, 1);
|
||||
+ ctx->drv_name = wd_get_accel_name(dev->char_dev_path, 1);
|
||||
if (!ctx->drv_name)
|
||||
goto free_dev_name;
|
||||
|
||||
@@ -342,7 +342,7 @@ handle_t wd_request_ctx(struct uacce_dev *dev)
|
||||
|
||||
wd_ctx_init_qfrs_offs(ctx);
|
||||
|
||||
- strncpy(ctx->dev_path, char_dev_path, MAX_DEV_NAME_LEN);
|
||||
+ strncpy(ctx->dev_path, dev->char_dev_path, MAX_DEV_NAME_LEN);
|
||||
ctx->dev_path[MAX_DEV_NAME_LEN - 1] = '\0';
|
||||
|
||||
ctx->fd = open(char_dev_path, O_RDWR | O_CLOEXEC);
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,77 +0,0 @@
|
||||
From cca176ed2ab3a34e5eb73cc70247c0f2dd02bdac Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 4 Jan 2022 21:26:09 +0800
|
||||
Subject: [PATCH 36/53] uadk: fix sched params begin issue
|
||||
|
||||
begin field of sched params need to be smaller than end,
|
||||
otherwise begin ctx is used all the time. So add a check
|
||||
to prevent invalid user input.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_sched.c | 17 +++++++++++------
|
||||
1 file changed, 11 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/wd_sched.c b/wd_sched.c
|
||||
index a85fd95..aeaf11b 100644
|
||||
--- a/wd_sched.c
|
||||
+++ b/wd_sched.c
|
||||
@@ -93,7 +93,7 @@ static __u32 sched_get_next_pos_rr(struct sched_ctx_region *region,
|
||||
|
||||
if (pos < region->end)
|
||||
region->last++;
|
||||
- else if (pos >= region->end)
|
||||
+ else
|
||||
region->last = region->begin;
|
||||
|
||||
pthread_mutex_unlock(®ion->lock);
|
||||
@@ -209,12 +209,12 @@ static int session_sched_poll_policy(handle_t sched_ctx,
|
||||
|
||||
if (!sched_ctx || !count || !ctx) {
|
||||
WD_ERR("ERROR: %s the para is NULL!\n", __FUNCTION__);
|
||||
- return -EINVAL;
|
||||
+ return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->numa_num > NUMA_NUM_NODES) {
|
||||
WD_ERR("ERROR: %s ctx numa num is invalid!\n", __FUNCTION__);
|
||||
- return -EINVAL;
|
||||
+ return -WD_EINVAL;
|
||||
}
|
||||
|
||||
sched_info = ctx->sched_info;
|
||||
@@ -359,7 +359,12 @@ int wd_sched_rr_instance(const struct wd_sched *sched,
|
||||
if (!sched || !sched->h_sched_ctx || !param) {
|
||||
WD_ERR("ERROR: %s para err: sched of h_sched_ctx is NULL!\n",
|
||||
__FUNCTION__);
|
||||
- return -EINVAL;
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ if (param->begin > param->end) {
|
||||
+ WD_ERR("ERROR: sched_params's begin is larger than end!\n");
|
||||
+ return -WD_EINVAL;
|
||||
}
|
||||
|
||||
numa_id = param->numa_id;
|
||||
@@ -372,7 +377,7 @@ int wd_sched_rr_instance(const struct wd_sched *sched,
|
||||
(type >= sched_ctx->type_num)) {
|
||||
WD_ERR("ERROR: %s para err: numa_id=%d, mode=%u, type=%u!\n",
|
||||
__FUNCTION__, numa_id, mode, type);
|
||||
- return -EINVAL;
|
||||
+ return -WD_EINVAL;
|
||||
}
|
||||
|
||||
sched_info = sched_ctx->sched_info;
|
||||
@@ -380,7 +385,7 @@ int wd_sched_rr_instance(const struct wd_sched *sched,
|
||||
if (!sched_info[numa_id].ctx_region[mode]) {
|
||||
WD_ERR("ERROR: %s para err: ctx_region:numa_id=%d, mode=%u is NULL!\n",
|
||||
__FUNCTION__, numa_id, mode);
|
||||
- return -EINVAL;
|
||||
+ return -WD_EINVAL;
|
||||
}
|
||||
|
||||
sched_info[numa_id].ctx_region[mode][type].begin = param->begin;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,88 +0,0 @@
|
||||
From d25bfc4577d47cbf5254b565876b4ca943580881 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 6 Jan 2022 21:25:48 +0800
|
||||
Subject: [PATCH 37/53] uadk: optimize wd_request_ctx
|
||||
|
||||
open fd first is more reasonable since it often goes wrong.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd.c | 26 ++++++++++++--------------
|
||||
1 file changed, 12 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/wd.c b/wd.c
|
||||
index 746fa02..787d74b 100644
|
||||
--- a/wd.c
|
||||
+++ b/wd.c
|
||||
@@ -300,11 +300,6 @@ static struct uacce_dev *clone_uacce_dev(struct uacce_dev *dev)
|
||||
return new;
|
||||
}
|
||||
|
||||
-static void free_uacce_dev(struct uacce_dev *dev)
|
||||
-{
|
||||
- free(dev);
|
||||
-}
|
||||
-
|
||||
static void wd_ctx_init_qfrs_offs(struct wd_ctx_h *ctx)
|
||||
{
|
||||
memcpy(&ctx->qfrs_offs, &ctx->dev->qfrs_offs,
|
||||
@@ -316,6 +311,7 @@ handle_t wd_request_ctx(struct uacce_dev *dev)
|
||||
struct wd_ctx_h *ctx;
|
||||
char char_dev_path[PATH_MAX];
|
||||
char *ptrRet = NULL;
|
||||
+ int fd;
|
||||
|
||||
if (!dev || !strlen(dev->dev_root))
|
||||
return 0;
|
||||
@@ -324,9 +320,15 @@ handle_t wd_request_ctx(struct uacce_dev *dev)
|
||||
if (ptrRet == NULL)
|
||||
return 0;
|
||||
|
||||
+ fd = open(char_dev_path, O_RDWR | O_CLOEXEC);
|
||||
+ if (fd < 0) {
|
||||
+ WD_ERR("failed to open %s!(err = %d)\n", char_dev_path, -errno);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
ctx = calloc(1, sizeof(struct wd_ctx_h));
|
||||
if (!ctx)
|
||||
- return 0;
|
||||
+ goto close_fd;
|
||||
|
||||
ctx->dev_name = wd_get_accel_name(dev->char_dev_path, 0);
|
||||
if (!ctx->dev_name)
|
||||
@@ -340,27 +342,23 @@ handle_t wd_request_ctx(struct uacce_dev *dev)
|
||||
if (!ctx->dev)
|
||||
goto free_drv_name;
|
||||
|
||||
+ ctx->fd = fd;
|
||||
+
|
||||
wd_ctx_init_qfrs_offs(ctx);
|
||||
|
||||
strncpy(ctx->dev_path, dev->char_dev_path, MAX_DEV_NAME_LEN);
|
||||
ctx->dev_path[MAX_DEV_NAME_LEN - 1] = '\0';
|
||||
|
||||
- ctx->fd = open(char_dev_path, O_RDWR | O_CLOEXEC);
|
||||
- if (ctx->fd < 0) {
|
||||
- WD_ERR("failed to open %s (%d).\n", char_dev_path, -errno);
|
||||
- goto free_dev;
|
||||
- }
|
||||
-
|
||||
return (handle_t)ctx;
|
||||
|
||||
-free_dev:
|
||||
- free_uacce_dev(ctx->dev);
|
||||
free_drv_name:
|
||||
free(ctx->drv_name);
|
||||
free_dev_name:
|
||||
free(ctx->dev_name);
|
||||
free_ctx:
|
||||
free(ctx);
|
||||
+close_fd:
|
||||
+ close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
From 556bf83c694c85c124b90428cb7622cc7babd411 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Mon, 10 Jan 2022 18:52:02 +0800
|
||||
Subject: [PATCH 38/53] uadk: env: bugfix for wd_init_resource
|
||||
|
||||
If sched is internal alloc, free it and set to NULL.
|
||||
Otherwise do not free sched resource from user input.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_util.c | 5 ++++-
|
||||
1 file changed, 4 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 9e96114..2e0e062 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -1412,7 +1412,10 @@ static int wd_init_resource(struct wd_env_config *config,
|
||||
err_uninit_alg:
|
||||
ops->alg_uninit();
|
||||
err_uninit_sched:
|
||||
- wd_uninit_sched_config(config->sched);
|
||||
+ if (config->internal_sched) {
|
||||
+ wd_uninit_sched_config(config->sched);
|
||||
+ config->sched = NULL;
|
||||
+ }
|
||||
err_uninit_ctx:
|
||||
wd_free_ctx(config->ctx_config);
|
||||
return ret;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,256 +0,0 @@
|
||||
From 388f0f7959acc5130c43b7a7d4a43603724a20a5 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Mon, 10 Jan 2022 18:52:03 +0800
|
||||
Subject: [PATCH 39/53] uadk: env: fix wd ctx num init
|
||||
|
||||
No need to set environment variables for ctx num init,
|
||||
because environment variables need to parse after set,
|
||||
add wd_parse_ctx_attr to set environment config directly.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
include/wd_util.h | 1 -
|
||||
wd_util.c | 152 +++++++++++++---------------------------------
|
||||
2 files changed, 43 insertions(+), 110 deletions(-)
|
||||
|
||||
diff --git a/include/wd_util.h b/include/wd_util.h
|
||||
index 81f4ba8..de2cd44 100644
|
||||
--- a/include/wd_util.h
|
||||
+++ b/include/wd_util.h
|
||||
@@ -72,7 +72,6 @@ struct wd_env_config {
|
||||
const struct wd_config_variable *table;
|
||||
__u32 table_size;
|
||||
__u16 numa_num;
|
||||
- __u8 disable_env;
|
||||
__u8 op_type_num;
|
||||
};
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 2e0e062..ad108bf 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -474,8 +474,10 @@ static int wd_alloc_numa(struct wd_env_config *config,
|
||||
|
||||
/* alloc and init config_per_numa and all uacce dev */
|
||||
ret = wd_set_config_numa(config, numa_dev_num, max_node);
|
||||
- if (ret)
|
||||
+ if (ret) {
|
||||
+ WD_ERR("failed to set numa config, ret = %d!\n", ret);
|
||||
goto free_list;
|
||||
+ }
|
||||
|
||||
/* set device and device num for config numa from uacce_dev list */
|
||||
wd_set_numa_dev(head, config);
|
||||
@@ -801,11 +803,8 @@ static int wd_parse_env(struct wd_env_config *config)
|
||||
|
||||
for (i = 0; i < config->table_size; i++) {
|
||||
var = config->table + i;
|
||||
- if (config->disable_env)
|
||||
- var_s = var->def_val;
|
||||
- else
|
||||
- var_s = secure_getenv(var->name);
|
||||
|
||||
+ var_s = secure_getenv(var->name);
|
||||
if (!var_s || !strlen(var_s)) {
|
||||
var_s = var->def_val;
|
||||
WD_ERR("no %s environment variable! Use default: %s\n",
|
||||
@@ -839,6 +838,40 @@ static void wd_free_env(struct wd_env_config *config)
|
||||
}
|
||||
}
|
||||
|
||||
+static int wd_parse_ctx_attr(struct wd_env_config *env_config,
|
||||
+ struct wd_ctx_attr *attr)
|
||||
+{
|
||||
+ struct wd_env_config_per_numa *config_numa;
|
||||
+ int ret;
|
||||
+
|
||||
+ config_numa = wd_get_config_numa(env_config, attr->node);
|
||||
+ if (!config_numa) {
|
||||
+ WD_ERR("%s got wrong numa node!\n", __func__);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ config_numa->op_type_num = env_config->op_type_num;
|
||||
+ ret = wd_alloc_ctx_table(config_numa);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+
|
||||
+ config_numa->ctx_table[attr->mode][attr->type].size = attr->num;
|
||||
+ wd_fill_ctx_table(env_config);
|
||||
+
|
||||
+ /* Use default sched and disable internal poll */
|
||||
+ env_config->sched = NULL;
|
||||
+ env_config->enable_internal_poll = 0;
|
||||
+ config_numa->async_poll_num = 0;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int wd_init_env_config(struct wd_env_config *config,
|
||||
+ struct wd_ctx_attr *attr)
|
||||
+{
|
||||
+ return attr ? wd_parse_ctx_attr(config, attr) : wd_parse_env(config);
|
||||
+}
|
||||
+
|
||||
static __u8 get_ctx_mode(struct wd_env_config_per_numa *config, int idx)
|
||||
{
|
||||
struct wd_ctx_range **ctx_table = config->ctx_table;
|
||||
@@ -869,6 +902,7 @@ static int get_op_type(struct wd_env_config_per_numa *config,
|
||||
return i;
|
||||
}
|
||||
|
||||
+ WD_ERR("failed to get op type!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1030,6 +1064,7 @@ static int wd_init_sched_config(struct wd_env_config *config)
|
||||
config->internal_sched = false;
|
||||
type_num = config->op_type_num;
|
||||
if (!config->sched) {
|
||||
+ WD_ERR("no sched is specified, alloc a default sched!\n");
|
||||
config->sched = wd_sched_rr_alloc(SCHED_POLICY_RR, type_num,
|
||||
max_node, func);
|
||||
if (!config->sched)
|
||||
@@ -1430,100 +1465,6 @@ static void wd_uninit_resource(struct wd_env_config *config)
|
||||
wd_free_ctx(config->ctx_config);
|
||||
}
|
||||
|
||||
-static void *wd_alloc_table(const struct wd_config_variable *table,
|
||||
- __u32 table_size)
|
||||
-{
|
||||
- struct wd_config_variable *alg_table;
|
||||
- int i, j;
|
||||
-
|
||||
- alg_table = malloc(table_size * sizeof(struct wd_config_variable));
|
||||
- if (!alg_table)
|
||||
- return NULL;
|
||||
-
|
||||
- memcpy(alg_table, table,
|
||||
- table_size * sizeof(struct wd_config_variable));
|
||||
- for (i = 0; i < table_size - 1; i++) {
|
||||
- alg_table[i].def_val = malloc(MAX_STR_LEN);
|
||||
- if (!alg_table[i].def_val) {
|
||||
- WD_ERR("%s malloc fail\n", __func__);
|
||||
- goto free_mem;
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- return alg_table;
|
||||
-
|
||||
-free_mem:
|
||||
- for (j = 0; j < i; j++)
|
||||
- free(alg_table[j].def_val);
|
||||
-
|
||||
- free(alg_table);
|
||||
- return NULL;
|
||||
-}
|
||||
-
|
||||
-static int wd_alg_table_init(const struct wd_config_variable *table,
|
||||
- __u32 table_size,
|
||||
- struct wd_ctx_attr *attr,
|
||||
- struct wd_env_config *env_config)
|
||||
-{
|
||||
- struct wd_config_variable *var_tbl;
|
||||
- const char *type_tbl;
|
||||
- int ret;
|
||||
-
|
||||
- if (!attr) {
|
||||
- env_config->disable_env = 0;
|
||||
- env_config->table = table;
|
||||
- return 0;
|
||||
- }
|
||||
-
|
||||
- env_config->disable_env = 1;
|
||||
-
|
||||
- var_tbl = wd_alloc_table(table, table_size);
|
||||
- if (!var_tbl)
|
||||
- return -WD_ENOMEM;
|
||||
-
|
||||
- env_config->table = var_tbl;
|
||||
-
|
||||
- /**
|
||||
- * Below def_val's memory is allocated from wd_alloc_table,
|
||||
- * the length of memory allocated to def_val is MAX_STR_LEN.
|
||||
- *
|
||||
- * We use mode and type as index of a string two-dimensional
|
||||
- * array to init def_val.
|
||||
- */
|
||||
- if (env_config->op_type_num == 1)
|
||||
- type_tbl = ctx_type[attr->mode][attr->type];
|
||||
- else
|
||||
- type_tbl = comp_ctx_type[attr->mode][attr->type];
|
||||
-
|
||||
- ret = snprintf(var_tbl[0].def_val, MAX_STR_LEN, "%s%u%c%u",
|
||||
- type_tbl, attr->num, '@', attr->node);
|
||||
- if (ret < 0)
|
||||
- return -errno;
|
||||
-
|
||||
- return 0;
|
||||
-}
|
||||
-
|
||||
-static void wd_alg_table_uninit(struct wd_env_config *config)
|
||||
-{
|
||||
- struct wd_config_variable *table;
|
||||
- int i;
|
||||
-
|
||||
- if (!config->disable_env)
|
||||
- return;
|
||||
-
|
||||
- table = (struct wd_config_variable *)config->table;
|
||||
- if (!table)
|
||||
- return;
|
||||
-
|
||||
- for (i = 0; i < config->table_size - 1; i++) {
|
||||
- free(table[i].def_val);
|
||||
- table[i].def_val = NULL;
|
||||
- }
|
||||
-
|
||||
- free(table);
|
||||
- table = NULL;
|
||||
-}
|
||||
-
|
||||
int wd_alg_env_init(struct wd_env_config *env_config,
|
||||
const struct wd_config_variable *table,
|
||||
const struct wd_alg_ops *ops,
|
||||
@@ -1534,18 +1475,14 @@ int wd_alg_env_init(struct wd_env_config *env_config,
|
||||
|
||||
env_config->op_type_num = ops->op_type_num;
|
||||
env_config->alg_poll_ctx = ops->alg_poll_ctx;
|
||||
+ env_config->table = table;
|
||||
env_config->table_size = table_size;
|
||||
|
||||
- ret = wd_alg_table_init(table, table_size,
|
||||
- ctx_attr, env_config);
|
||||
- if (ret)
|
||||
- return ret;
|
||||
-
|
||||
ret = wd_alloc_numa(env_config, ops);
|
||||
if (ret)
|
||||
- goto table_uninit;
|
||||
+ return ret;
|
||||
|
||||
- ret = wd_parse_env(env_config);
|
||||
+ ret = wd_init_env_config(env_config, ctx_attr);
|
||||
if (ret)
|
||||
goto free_numa;
|
||||
|
||||
@@ -1562,8 +1499,6 @@ free_env:
|
||||
wd_free_env(env_config);
|
||||
free_numa:
|
||||
wd_free_numa(env_config);
|
||||
-table_uninit:
|
||||
- wd_alg_table_uninit(env_config);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1576,7 +1511,6 @@ void wd_alg_env_uninit(struct wd_env_config *env_config)
|
||||
wd_uninit_resource(env_config);
|
||||
wd_free_env(env_config);
|
||||
wd_free_numa(env_config);
|
||||
- wd_alg_table_uninit(env_config);
|
||||
}
|
||||
|
||||
int wd_alg_get_env_param(struct wd_env_config *env_config,
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,39 +0,0 @@
|
||||
From f4cd396150be285aa614f4272a51cd3dacf99096 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Mon, 10 Jan 2022 20:01:41 +0800
|
||||
Subject: [PATCH 40/53] uadk: modify for free and return
|
||||
|
||||
After free local variable, no need to set NULL.
|
||||
If return value is not associated with other
|
||||
functions, no need to set value, return directly.
|
||||
|
||||
Signed-off-by: JunchongPan <panjunchong@hisilicon.com>
|
||||
---
|
||||
wd_util.c | 4 +---
|
||||
1 file changed, 1 insertion(+), 3 deletions(-)
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index ad108bf..c2c109c 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -599,7 +599,6 @@ free_mem:
|
||||
}
|
||||
|
||||
free(ctx_table);
|
||||
- ctx_table = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -652,8 +651,7 @@ static int wd_parse_section(struct wd_env_config *config, char *section)
|
||||
config_numa = wd_get_config_numa(config, node);
|
||||
if (!config_numa) {
|
||||
WD_ERR("%s got wrong numa node: %s!\n", __func__, section);
|
||||
- ret = -WD_EINVAL;
|
||||
- return ret;
|
||||
+ return -WD_EINVAL;
|
||||
}
|
||||
|
||||
config_numa->op_type_num = config->op_type_num;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,516 +0,0 @@
|
||||
From b8c3d3c5f1b3db3b89ed975bb51c7546676f2bd1 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Mon, 10 Jan 2022 18:52:04 +0800
|
||||
Subject: [PATCH 41/53] uadk: include: fix uadk compatibility
|
||||
|
||||
Fix that C++ program can't call the uadk interface.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
include/drv/wd_aead_drv.h | 9 +++++++++
|
||||
include/drv/wd_cipher_drv.h | 9 +++++++++
|
||||
include/drv/wd_comp_drv.h | 8 ++++++++
|
||||
include/drv/wd_dh_drv.h | 8 ++++++++
|
||||
include/drv/wd_digest_drv.h | 9 +++++++++
|
||||
include/drv/wd_ecc_drv.h | 8 ++++++++
|
||||
include/drv/wd_rsa_drv.h | 8 ++++++++
|
||||
include/hisi_qm_udrv.h | 8 ++++++++
|
||||
include/uacce.h | 9 +++++++++
|
||||
include/wd.h | 8 ++++++++
|
||||
include/wd_aead.h | 8 ++++++++
|
||||
include/wd_alg_common.h | 8 ++++++++
|
||||
include/wd_cipher.h | 8 ++++++++
|
||||
include/wd_common.h | 8 ++++++++
|
||||
include/wd_comp.h | 8 ++++++++
|
||||
include/wd_dh.h | 8 ++++++++
|
||||
include/wd_digest.h | 8 ++++++++
|
||||
include/wd_rsa.h | 8 ++++++++
|
||||
include/wd_sched.h | 8 ++++++++
|
||||
include/wd_util.h | 8 ++++++++
|
||||
20 files changed, 164 insertions(+)
|
||||
|
||||
diff --git a/include/drv/wd_aead_drv.h b/include/drv/wd_aead_drv.h
|
||||
index d2016f0..78a5673 100644
|
||||
--- a/include/drv/wd_aead_drv.h
|
||||
+++ b/include/drv/wd_aead_drv.h
|
||||
@@ -7,6 +7,10 @@
|
||||
#include "include/wd_alg_common.h"
|
||||
#include "include/wd_aead.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
struct wd_aead_msg {
|
||||
struct wd_aead_req req;
|
||||
/* Request identifier */
|
||||
@@ -87,4 +91,9 @@ static void __attribute__((constructor)) set_aead_driver(void) \
|
||||
wd_aead_set_driver(&drv); \
|
||||
}
|
||||
#endif
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif /* __WD_AEAD_DRV_H */
|
||||
diff --git a/include/drv/wd_cipher_drv.h b/include/drv/wd_cipher_drv.h
|
||||
index d6798c0..e649869 100644
|
||||
--- a/include/drv/wd_cipher_drv.h
|
||||
+++ b/include/drv/wd_cipher_drv.h
|
||||
@@ -7,6 +7,10 @@
|
||||
#include "../wd_cipher.h"
|
||||
#include "../wd_alg_common.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
/* fixme wd_cipher_msg */
|
||||
struct wd_cipher_msg {
|
||||
struct wd_cipher_req req;
|
||||
@@ -72,4 +76,9 @@ static void __attribute__((constructor)) set_driver(void) \
|
||||
wd_cipher_set_driver(&drv); \
|
||||
}
|
||||
#endif
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif /* __WD_CIPHER_DRV_H */
|
||||
diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h
|
||||
index b4dc722..8146a50 100644
|
||||
--- a/include/drv/wd_comp_drv.h
|
||||
+++ b/include/drv/wd_comp_drv.h
|
||||
@@ -7,6 +7,10 @@
|
||||
#include <pthread.h>
|
||||
#include "../wd_comp.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
enum wd_comp_strm_pos {
|
||||
WD_COMP_STREAM_NEW,
|
||||
WD_COMP_STREAM_OLD,
|
||||
@@ -79,4 +83,8 @@ static void __attribute__((constructor)) set_driver(void) \
|
||||
}
|
||||
#endif
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif /* __WD_COMP_DRV_H */
|
||||
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
|
||||
index 08212b1..5d436d1 100644
|
||||
--- a/include/drv/wd_dh_drv.h
|
||||
+++ b/include/drv/wd_dh_drv.h
|
||||
@@ -6,6 +6,10 @@
|
||||
|
||||
#include "../wd_dh.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
/* DH message format */
|
||||
struct wd_dh_msg {
|
||||
struct wd_dh_req req;
|
||||
@@ -45,4 +49,8 @@ static void __attribute__((constructor)) set_driver_dh(void) \
|
||||
}
|
||||
#endif
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif /* __WD_DH_DRV_H */
|
||||
diff --git a/include/drv/wd_digest_drv.h b/include/drv/wd_digest_drv.h
|
||||
index ac3b028..fdde772 100644
|
||||
--- a/include/drv/wd_digest_drv.h
|
||||
+++ b/include/drv/wd_digest_drv.h
|
||||
@@ -6,6 +6,10 @@
|
||||
#include "include/wd_digest.h"
|
||||
#include "include/wd_alg_common.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
/* fixme wd_digest_msg */
|
||||
struct wd_digest_msg {
|
||||
struct wd_digest_req req;
|
||||
@@ -75,4 +79,9 @@ static void __attribute__((constructor)) set_drivers(void) \
|
||||
wd_digest_set_driver(&drv); \
|
||||
}
|
||||
#endif
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif /* __WD_DIGEST_DRV_H */
|
||||
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
|
||||
index 9f4575f..7e0d27e 100644
|
||||
--- a/include/drv/wd_ecc_drv.h
|
||||
+++ b/include/drv/wd_ecc_drv.h
|
||||
@@ -7,6 +7,10 @@
|
||||
#include "../wd_ecc.h"
|
||||
#include "../wd_alg_common.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
/* ECC */
|
||||
#define ECDH_IN_PARAM_NUM 2
|
||||
#define ECDH_OUT_PARAM_NUM 2
|
||||
@@ -198,4 +202,8 @@ static void __attribute__((constructor)) set_driver_ecc(void) \
|
||||
}
|
||||
#endif
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif /* __WD_ECC_DRV_H */
|
||||
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
|
||||
index 3c4b144..948625f 100644
|
||||
--- a/include/drv/wd_rsa_drv.h
|
||||
+++ b/include/drv/wd_rsa_drv.h
|
||||
@@ -5,6 +5,10 @@
|
||||
|
||||
#include "../wd_rsa.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
struct wd_rsa_kg_in {
|
||||
__u8 *e;
|
||||
__u8 *p;
|
||||
@@ -70,4 +74,8 @@ static void __attribute__((constructor)) set_driver_rsa(void) \
|
||||
}
|
||||
#endif
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif /* __WD_RSA_DRV_H */
|
||||
diff --git a/include/hisi_qm_udrv.h b/include/hisi_qm_udrv.h
|
||||
index 11ee4ad..707d0e3 100644
|
||||
--- a/include/hisi_qm_udrv.h
|
||||
+++ b/include/hisi_qm_udrv.h
|
||||
@@ -12,6 +12,10 @@
|
||||
#include "wd.h"
|
||||
#include "wd_alg_common.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
#define WD_CAPA_PRIV_DATA_SIZE 64
|
||||
|
||||
#define QM_L32BITS_MASK 0xffffffff
|
||||
@@ -180,4 +184,8 @@ __u32 hisi_qm_get_list_size(struct wd_datalist *start_node,
|
||||
|
||||
void hisi_qm_enable_interrupt(handle_t ctx, __u8 enable);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
diff --git a/include/uacce.h b/include/uacce.h
|
||||
index 7c69df8..07e36fe 100644
|
||||
--- a/include/uacce.h
|
||||
+++ b/include/uacce.h
|
||||
@@ -10,6 +10,10 @@
|
||||
#include <linux/types.h>
|
||||
#include <linux/ioctl.h>
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
#define UACCE_CMD_START _IO('W', 0)
|
||||
#define UACCE_CMD_PUT_Q _IO('W', 1)
|
||||
#define UACCE_CMD_GET_SS_DMA _IOR('W', 100, unsigned long)
|
||||
@@ -33,4 +37,9 @@ enum uacce_qfrt {
|
||||
UACCE_QFRT_DUS = 1, /* device user share */
|
||||
UACCE_QFRT_MAX,
|
||||
};
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
diff --git a/include/wd.h b/include/wd.h
|
||||
index ac564d8..273cbb8 100644
|
||||
--- a/include/wd.h
|
||||
+++ b/include/wd.h
|
||||
@@ -14,6 +14,10 @@
|
||||
#include <unistd.h>
|
||||
#include "uacce.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
#define PATH_STR_SIZE 256
|
||||
#define MAX_ATTR_STR_SIZE 384
|
||||
#define WD_NAME_SIZE 64
|
||||
@@ -483,4 +487,8 @@ void wd_mempool_stats(handle_t mempool, struct wd_mempool_stats *stats);
|
||||
*/
|
||||
void wd_blockpool_stats(handle_t blkpool, struct wd_blockpool_stats *stats);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
diff --git a/include/wd_aead.h b/include/wd_aead.h
|
||||
index 6377008..f169812 100644
|
||||
--- a/include/wd_aead.h
|
||||
+++ b/include/wd_aead.h
|
||||
@@ -14,6 +14,10 @@
|
||||
#include "wd_digest.h"
|
||||
#include "wd.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
/**
|
||||
* wd_aead_op_type - Algorithm type of option
|
||||
*/
|
||||
@@ -214,4 +218,8 @@ void wd_aead_ctx_num_uninit(void);
|
||||
int wd_aead_get_env_param(__u32 node, __u32 type, __u32 mode,
|
||||
__u32 *num, __u8 *is_enable);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif /* __WD_AEAD_H */
|
||||
diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h
|
||||
index 01a12ca..94336f0 100644
|
||||
--- a/include/wd_alg_common.h
|
||||
+++ b/include/wd_alg_common.h
|
||||
@@ -12,6 +12,10 @@
|
||||
#include "wd.h"
|
||||
#include "wd_common.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
/* Required compiler attributes */
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
@@ -103,4 +107,8 @@ struct wd_datalist {
|
||||
struct wd_datalist *next;
|
||||
};
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
diff --git a/include/wd_cipher.h b/include/wd_cipher.h
|
||||
index 8c73396..660d7e8 100644
|
||||
--- a/include/wd_cipher.h
|
||||
+++ b/include/wd_cipher.h
|
||||
@@ -11,6 +11,10 @@
|
||||
#include "wd.h"
|
||||
#include "wd_alg_common.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
#define AES_KEYSIZE_128 16
|
||||
#define AES_KEYSIZE_192 24
|
||||
#define AES_KEYSIZE_256 32
|
||||
@@ -185,4 +189,8 @@ void wd_cipher_ctx_num_uninit(void);
|
||||
int wd_cipher_get_env_param(__u32 node, __u32 type, __u32 mode,
|
||||
__u32 *num, __u8 *is_enable);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif /* __WD_CIPHER_H */
|
||||
diff --git a/include/wd_common.h b/include/wd_common.h
|
||||
index 61919d5..91dd066 100644
|
||||
--- a/include/wd_common.h
|
||||
+++ b/include/wd_common.h
|
||||
@@ -7,9 +7,17 @@
|
||||
#ifndef __WD_COMMON_H
|
||||
#define __WD_COMMON_H
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
enum wd_buff_type {
|
||||
WD_FLAT_BUF,
|
||||
WD_SGL_BUF,
|
||||
};
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif /* __WD_COMMON_H */
|
||||
diff --git a/include/wd_comp.h b/include/wd_comp.h
|
||||
index b6225df..460cfa7 100644
|
||||
--- a/include/wd_comp.h
|
||||
+++ b/include/wd_comp.h
|
||||
@@ -12,6 +12,10 @@
|
||||
#include "wd.h"
|
||||
#include "wd_alg_common.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
enum wd_comp_alg_type {
|
||||
WD_DEFLATE,
|
||||
WD_ZLIB,
|
||||
@@ -217,4 +221,8 @@ void wd_comp_ctx_num_uninit(void);
|
||||
int wd_comp_get_env_param(__u32 node, __u32 type, __u32 mode,
|
||||
__u32 *num, __u8 *is_enable);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif /* __WD_COMP_H */
|
||||
diff --git a/include/wd_dh.h b/include/wd_dh.h
|
||||
index c0bce85..f342722 100644
|
||||
--- a/include/wd_dh.h
|
||||
+++ b/include/wd_dh.h
|
||||
@@ -12,6 +12,10 @@
|
||||
#include "wd.h"
|
||||
#include "wd_alg_common.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
#define BYTE_BITS 8
|
||||
#define BYTE_BITS_SHIFT 3
|
||||
#define GET_NEGATIVE(val) (0 - (val))
|
||||
@@ -69,4 +73,8 @@ void wd_dh_ctx_num_uninit(void);
|
||||
int wd_dh_get_env_param(__u32 node, __u32 type, __u32 mode,
|
||||
__u32 *num, __u8 *is_enable);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif /* __WD_DH_H */
|
||||
diff --git a/include/wd_digest.h b/include/wd_digest.h
|
||||
index 8e8e236..7e93a80 100644
|
||||
--- a/include/wd_digest.h
|
||||
+++ b/include/wd_digest.h
|
||||
@@ -11,6 +11,10 @@
|
||||
#include "wd_alg_common.h"
|
||||
#include "wd.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
#define MAX_HMAC_KEY_SIZE 128U
|
||||
|
||||
/**
|
||||
@@ -209,4 +213,8 @@ void wd_digest_ctx_num_uninit(void);
|
||||
int wd_digest_get_env_param(__u32 node, __u32 type, __u32 mode,
|
||||
__u32 *num, __u8 *is_enable);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif /* __WD_DIGEST_H */
|
||||
diff --git a/include/wd_rsa.h b/include/wd_rsa.h
|
||||
index 044819b..081bc2a 100644
|
||||
--- a/include/wd_rsa.h
|
||||
+++ b/include/wd_rsa.h
|
||||
@@ -12,6 +12,10 @@
|
||||
#include "wd.h"
|
||||
#include "wd_alg_common.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
#define BYTE_BITS 8
|
||||
#define BYTE_BITS_SHIFT 3
|
||||
#define CRT_PARAMS_SZ(key_size) ((5 * (key_size)) >> 1)
|
||||
@@ -216,4 +220,8 @@ void wd_rsa_ctx_num_uninit(void);
|
||||
int wd_rsa_get_env_param(__u32 node, __u32 type, __u32 mode,
|
||||
__u32 *num, __u8 *is_enable);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif /* __WD_RSA_H */
|
||||
diff --git a/include/wd_sched.h b/include/wd_sched.h
|
||||
index 78125f4..2ae6103 100644
|
||||
--- a/include/wd_sched.h
|
||||
+++ b/include/wd_sched.h
|
||||
@@ -8,6 +8,10 @@
|
||||
#define SCHED_SAMPLE_h
|
||||
#include "wd_alg_common.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
#define INVALID_POS 0xFFFFFFFF
|
||||
|
||||
/* The global policy type */
|
||||
@@ -56,4 +60,8 @@ struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num,
|
||||
*/
|
||||
void wd_sched_rr_release(struct wd_sched *sched);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
diff --git a/include/wd_util.h b/include/wd_util.h
|
||||
index de2cd44..ef95907 100644
|
||||
--- a/include/wd_util.h
|
||||
+++ b/include/wd_util.h
|
||||
@@ -10,6 +10,10 @@
|
||||
#include <stdbool.h>
|
||||
#include "wd_alg_common.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
#define FOREACH_NUMA(i, config, config_numa) \
|
||||
for (i = 0, config_numa = config->config_per_numa; \
|
||||
i < config->numa_num; config_numa++, i++)
|
||||
@@ -309,4 +313,8 @@ int wd_set_ctx_attr(struct wd_ctx_attr *ctx_attr,
|
||||
*/
|
||||
int wd_check_ctx(struct wd_ctx_config_internal *config, __u8 mode, __u32 idx);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif /* __WD_UTIL_H */
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,50 +0,0 @@
|
||||
From bb09e342c186f111600e763ca7a5bfb8713df6f7 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Wed, 12 Jan 2022 09:44:57 +0800
|
||||
Subject: [PATCH 42/53] uadk: fix for resources are repeatedly released
|
||||
|
||||
Segment fault occur when environment resources
|
||||
are repeatedly released, so add pointer check
|
||||
for wd_free_ctx and wd_free_env and clear dirty
|
||||
global Variables.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_util.c | 7 +++++++
|
||||
1 file changed, 7 insertions(+)
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index c2c109c..6cae768 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -825,6 +825,9 @@ static void wd_free_env(struct wd_env_config *config)
|
||||
struct wd_env_config_per_numa *config_numa;
|
||||
int i, j;
|
||||
|
||||
+ if (!config->config_per_numa)
|
||||
+ return;
|
||||
+
|
||||
FOREACH_NUMA(i, config, config_numa) {
|
||||
if (!config_numa->ctx_table)
|
||||
continue;
|
||||
@@ -1010,6 +1013,9 @@ err_free_ctx_config:
|
||||
|
||||
static void wd_free_ctx(struct wd_ctx_config *ctx_config)
|
||||
{
|
||||
+ if (!ctx_config)
|
||||
+ return;
|
||||
+
|
||||
wd_put_wd_ctx(ctx_config, ctx_config->ctx_num);
|
||||
free(ctx_config->ctxs);
|
||||
free(ctx_config);
|
||||
@@ -1451,6 +1457,7 @@ err_uninit_sched:
|
||||
}
|
||||
err_uninit_ctx:
|
||||
wd_free_ctx(config->ctx_config);
|
||||
+ config->ctx_config = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,785 +0,0 @@
|
||||
From c421a68ee4f70675235443f9cc968f264c7a39a6 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Thu, 13 Jan 2022 10:37:10 +0800
|
||||
Subject: [PATCH 43/53] aead: modify the aead's request api
|
||||
|
||||
1. Add the parameter of mac address for Openssl engine. Previous
|
||||
plan not adapted to the Openssl engine, it caused the low performance.
|
||||
So after modification, user should allocated the mac memory and set
|
||||
the mac length as doing task.
|
||||
2. Deleted a parameter in api. the out_buffer_bytes is a redundant
|
||||
code.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 72 ++----------------
|
||||
include/wd_aead.h | 6 +-
|
||||
test/hisi_sec_test/test_hisi_sec.c | 116 ++++++++++++++++++++++-------
|
||||
uadk_tool/sec_uadk_benchmark.c | 33 ++++----
|
||||
wd_aead.c | 46 ++++++++----
|
||||
5 files changed, 152 insertions(+), 121 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index d31a1b9..f5db7eb 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -73,8 +73,8 @@
|
||||
/* The max BD data length is 16M-512B */
|
||||
#define MAX_INPUT_DATA_LEN 0xFFFE00
|
||||
#define MAX_CCM_AAD_LEN 65279
|
||||
-#define SHA1_ALIGN_SZ 64
|
||||
-#define SHA512_ALIGN_SZ 128
|
||||
+#define SHA1_ALIGN_SZ 64U
|
||||
+#define SHA512_ALIGN_SZ 128U
|
||||
|
||||
#define AUTHPAD_OFFSET 2
|
||||
#define AUTHTYPE_OFFSET 6
|
||||
@@ -1739,48 +1739,12 @@ static void set_aead_auth_iv(struct wd_aead_msg *msg)
|
||||
}
|
||||
}
|
||||
|
||||
-static void fill_aead_mac_addr_pbuff(struct wd_aead_msg *msg, __u64 *mac_addr)
|
||||
-{
|
||||
- __u64 addr = 0;
|
||||
-
|
||||
- if (msg->op_type == WD_CIPHER_DECRYPTION_DIGEST)
|
||||
- addr = (__u64)(uintptr_t)msg->in + msg->in_bytes + msg->assoc_bytes;
|
||||
-
|
||||
- /* AEAD output MAC addr use out addr */
|
||||
- if (msg->op_type == WD_CIPHER_ENCRYPTION_DIGEST)
|
||||
- addr = (__u64)(uintptr_t)msg->out + msg->out_bytes - msg->auth_bytes;
|
||||
-
|
||||
- *mac_addr = addr;
|
||||
-}
|
||||
-
|
||||
-static void fill_aead_mac_addr_sgl(struct wd_aead_msg *msg, __u64 *mac_addr)
|
||||
-{
|
||||
- msg->mac = calloc(1, msg->auth_bytes);
|
||||
- if (!msg->mac) {
|
||||
- WD_ERR("failed to alloc mac memory!\n");
|
||||
- return;
|
||||
- }
|
||||
-
|
||||
- if (msg->op_type == WD_CIPHER_DECRYPTION_DIGEST)
|
||||
- hisi_qm_sgl_copy(msg->mac, msg->in,
|
||||
- msg->in_bytes + msg->assoc_bytes,
|
||||
- msg->auth_bytes, COPY_SGL_TO_PBUFF);
|
||||
-
|
||||
- *mac_addr = (__u64)(uintptr_t)msg->mac;
|
||||
-}
|
||||
-
|
||||
static void fill_aead_bd2_addr(struct wd_aead_msg *msg,
|
||||
struct hisi_sec_sqe *sqe)
|
||||
{
|
||||
sqe->type2.data_src_addr = (__u64)(uintptr_t)msg->in;
|
||||
sqe->type2.data_dst_addr = (__u64)(uintptr_t)msg->out;
|
||||
-
|
||||
- /* AEAD input MAC addr use in addr */
|
||||
- if (msg->data_fmt == WD_FLAT_BUF)
|
||||
- fill_aead_mac_addr_pbuff(msg, &sqe->type2.mac_addr);
|
||||
- else
|
||||
- fill_aead_mac_addr_sgl(msg, &sqe->type2.mac_addr);
|
||||
-
|
||||
+ sqe->type2.mac_addr = (__u64)(uintptr_t)msg->mac;
|
||||
sqe->type2.c_key_addr = (__u64)(uintptr_t)msg->ckey;
|
||||
sqe->type2.a_key_addr = (__u64)(uintptr_t)msg->akey;
|
||||
sqe->type2.c_ivin_addr = (__u64)(uintptr_t)msg->iv;
|
||||
@@ -1939,7 +1903,7 @@ static void parse_aead_bd2(struct hisi_sec_sqe *sqe,
|
||||
if (recv_msg->auth_bytes == 0)
|
||||
recv_msg->auth_bytes = sqe->type2.icvw_kmode &
|
||||
SEC_AUTH_LEN_MASK;
|
||||
- recv_msg->out_bytes = sqe->type2.clen_ivhlen + recv_msg->auth_bytes +
|
||||
+ recv_msg->out_bytes = sqe->type2.clen_ivhlen +
|
||||
sqe->type2.cipher_src_offset;
|
||||
|
||||
#ifdef DEBUG
|
||||
@@ -1961,15 +1925,9 @@ int hisi_sec_aead_recv(handle_t ctx, struct wd_aead_msg *recv_msg)
|
||||
|
||||
parse_aead_bd2(&sqe, recv_msg);
|
||||
|
||||
- if (recv_msg->data_fmt == WD_SGL_BUF) {
|
||||
- if (sqe.type_auth_cipher & (SEC_CIPHER_ENC << SEC_CIPHER_OFFSET))
|
||||
- hisi_qm_sgl_copy(recv_msg->mac, recv_msg->out,
|
||||
- recv_msg->out_bytes - recv_msg->auth_bytes,
|
||||
- recv_msg->auth_bytes, COPY_PBUFF_TO_SGL);
|
||||
-
|
||||
+ if (recv_msg->data_fmt == WD_SGL_BUF)
|
||||
hisi_sec_put_sgl(h_qp, recv_msg->alg_type, recv_msg->in,
|
||||
recv_msg->out);
|
||||
- }
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -2089,18 +2047,10 @@ static int fill_aead_bd3_mode(struct wd_aead_msg *msg,
|
||||
static void fill_aead_bd3_addr(struct wd_aead_msg *msg,
|
||||
struct hisi_sec_sqe3 *sqe)
|
||||
{
|
||||
- __u64 mac_addr;
|
||||
-
|
||||
sqe->data_src_addr = (__u64)(uintptr_t)msg->in;
|
||||
sqe->data_dst_addr = (__u64)(uintptr_t)msg->out;
|
||||
|
||||
- /* AEAD input MAC addr use in and out addr */
|
||||
- if (msg->data_fmt == WD_FLAT_BUF)
|
||||
- fill_aead_mac_addr_pbuff(msg, &mac_addr);
|
||||
- else
|
||||
- fill_aead_mac_addr_sgl(msg, &mac_addr);
|
||||
-
|
||||
- sqe->mac_addr = mac_addr;
|
||||
+ sqe->mac_addr = (__u64)(uintptr_t)msg->mac;
|
||||
sqe->c_key_addr = (__u64)(uintptr_t)msg->ckey;
|
||||
sqe->a_key_addr = (__u64)(uintptr_t)msg->akey;
|
||||
sqe->no_scene.c_ivin_addr = (__u64)(uintptr_t)msg->iv;
|
||||
@@ -2237,7 +2187,7 @@ static void parse_aead_bd3(struct hisi_sec_sqe3 *sqe,
|
||||
if (recv_msg->auth_bytes == 0)
|
||||
recv_msg->auth_bytes = (sqe->c_icv_key >> SEC_MAC_OFFSET_V3) &
|
||||
SEC_MAC_LEN_MASK;
|
||||
- recv_msg->out_bytes = sqe->c_len_ivin + recv_msg->auth_bytes +
|
||||
+ recv_msg->out_bytes = sqe->c_len_ivin +
|
||||
sqe->cipher_src_offset;
|
||||
|
||||
#ifdef DEBUG
|
||||
@@ -2259,15 +2209,9 @@ int hisi_sec_aead_recv_v3(handle_t ctx, struct wd_aead_msg *recv_msg)
|
||||
|
||||
parse_aead_bd3(&sqe, recv_msg);
|
||||
|
||||
- if (recv_msg->data_fmt == WD_SGL_BUF) {
|
||||
- if (sqe.c_icv_key & SEC_CIPHER_ENC)
|
||||
- hisi_qm_sgl_copy(recv_msg->mac, recv_msg->out,
|
||||
- recv_msg->out_bytes - recv_msg->auth_bytes,
|
||||
- recv_msg->auth_bytes, COPY_PBUFF_TO_SGL);
|
||||
-
|
||||
+ if (recv_msg->data_fmt == WD_SGL_BUF)
|
||||
hisi_sec_put_sgl(h_qp, recv_msg->alg_type,
|
||||
recv_msg->in, recv_msg->out);
|
||||
- }
|
||||
|
||||
return 0;
|
||||
}
|
||||
diff --git a/include/wd_aead.h b/include/wd_aead.h
|
||||
index f169812..a632cd8 100644
|
||||
--- a/include/wd_aead.h
|
||||
+++ b/include/wd_aead.h
|
||||
@@ -52,11 +52,12 @@ typedef void *wd_alg_aead_cb_t(struct wd_aead_req *req, void *cb_param);
|
||||
* @ op_type: denoted by enum wd_aead_op_type
|
||||
* @ src: input data pointer
|
||||
* @ dst: output data pointer
|
||||
+ * @ mac: mac data pointer
|
||||
* @ iv: input iv pointer
|
||||
* @ in_bytes: input data length
|
||||
* @ out_bytes: output data length
|
||||
- * @ out_buf_bytes: output data buffer length
|
||||
* @ iv_bytes: input iv length
|
||||
+ * @ mac_bytes: mac data buffer length
|
||||
* @ assoc_bytes: input associated data length
|
||||
* @ state: operation result, denoted by WD error code
|
||||
* @ cb: callback function pointer
|
||||
@@ -72,11 +73,12 @@ struct wd_aead_req {
|
||||
struct wd_datalist *list_dst;
|
||||
void *dst;
|
||||
};
|
||||
+ void *mac;
|
||||
void *iv;
|
||||
__u32 in_bytes;
|
||||
__u32 out_bytes;
|
||||
- __u32 out_buf_bytes;
|
||||
__u16 iv_bytes;
|
||||
+ __u16 mac_bytes;
|
||||
__u16 assoc_bytes;
|
||||
__u16 state;
|
||||
__u8 data_fmt;
|
||||
diff --git a/test/hisi_sec_test/test_hisi_sec.c b/test/hisi_sec_test/test_hisi_sec.c
|
||||
index dda291d..6f27cd1 100644
|
||||
--- a/test/hisi_sec_test/test_hisi_sec.c
|
||||
+++ b/test/hisi_sec_test/test_hisi_sec.c
|
||||
@@ -279,6 +279,7 @@ static void dump_mem(int sgl, unsigned char *buf, size_t len)
|
||||
if ((i + 1) % 8 == 0)
|
||||
SEC_TST_PRT("\n");
|
||||
}
|
||||
+ SEC_TST_PRT("\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2523,6 +2524,7 @@ static int sec_aead_sync_once(void)
|
||||
unsigned long Perf = 0;
|
||||
float speed, time_used;
|
||||
unsigned long cnt = g_times;
|
||||
+ __u16 mac_bytes;
|
||||
__u16 auth_size;
|
||||
__u16 in_size;
|
||||
__u16 iv_len;
|
||||
@@ -2553,8 +2555,7 @@ static int sec_aead_sync_once(void)
|
||||
|
||||
/* should set key */
|
||||
dump_mem(WD_FLAT_BUF, (void *)tv->key, tv->klen);
|
||||
- if (setup.cmode == WD_CIPHER_CCM ||
|
||||
- setup.cmode == WD_CIPHER_GCM) {
|
||||
+ if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM) {
|
||||
ret = wd_aead_set_ckey(h_sess, (const __u8*)tv->key, tv->klen);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("aead sess set key failed!\n");
|
||||
@@ -2576,6 +2577,7 @@ static int sec_aead_sync_once(void)
|
||||
}
|
||||
|
||||
auth_size = (__u16)(tv->clen - tv->plen);
|
||||
+ mac_bytes = auth_size;
|
||||
ret = wd_aead_set_authsize(h_sess, auth_size);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("set auth size fail, authsize: %u\n", auth_size);
|
||||
@@ -2596,6 +2598,18 @@ static int sec_aead_sync_once(void)
|
||||
}
|
||||
SEC_TST_PRT("aead get max auth size: %u\n", ret);
|
||||
|
||||
+ if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM)
|
||||
+ mac_bytes = 16;
|
||||
+
|
||||
+ req.mac = malloc(mac_bytes);
|
||||
+ if (!req.mac) {
|
||||
+ SEC_TST_PRT("req iv mem malloc failed!\n");
|
||||
+ ret = -ENOMEM;
|
||||
+ goto out_key;
|
||||
+ }
|
||||
+ memset(req.mac, 0, mac_bytes);
|
||||
+ req.mac_bytes = mac_bytes;
|
||||
+
|
||||
if (g_direction == 0)
|
||||
req.op_type = WD_CIPHER_ENCRYPTION_DIGEST;
|
||||
else
|
||||
@@ -2609,7 +2623,7 @@ static int sec_aead_sync_once(void)
|
||||
}
|
||||
if (in_size > BUFF_SIZE) {
|
||||
SEC_TST_PRT("alloc in buffer block size too small!\n");
|
||||
- goto out_key;
|
||||
+ goto out_mac;
|
||||
}
|
||||
unit_sz = cal_unit_sz(in_size, g_sgl_num);
|
||||
void *src = create_buf(WD_FLAT_BUF, in_size, unit_sz);
|
||||
@@ -2627,10 +2641,14 @@ static int sec_aead_sync_once(void)
|
||||
req.in_bytes = tv->plen;
|
||||
} else {
|
||||
memcpy(src, tv->assoc, tv->alen);
|
||||
- memcpy((src + req.assoc_bytes), tv->ctext, tv->clen);
|
||||
+ memcpy(src + req.assoc_bytes, tv->ctext, tv->clen - auth_size);
|
||||
req.in_bytes = tv->clen - auth_size;
|
||||
+ memcpy(req.mac, tv->ctext + tv->clen - auth_size, auth_size);
|
||||
}
|
||||
|
||||
+ SEC_TST_PRT("mac addr src is:\n");
|
||||
+ dump_mem(0, req.mac, auth_size);
|
||||
+
|
||||
req.src = create_buf(g_data_fmt, in_size, unit_sz);
|
||||
if (!req.src) {
|
||||
ret = -ENOMEM;
|
||||
@@ -2643,21 +2661,19 @@ static int sec_aead_sync_once(void)
|
||||
dump_mem(g_data_fmt, req.src, tv->alen + req.in_bytes);
|
||||
|
||||
if (g_direction == 0) {
|
||||
- req.out_bytes = req.assoc_bytes + tv->clen;
|
||||
+ req.out_bytes = req.assoc_bytes + tv->clen - auth_size;
|
||||
} else {
|
||||
req.out_bytes = req.assoc_bytes + tv->plen;
|
||||
}
|
||||
|
||||
- req.out_buf_bytes = req.out_bytes + auth_size;
|
||||
// alloc out buffer memory
|
||||
- unit_sz = cal_unit_sz(req.out_buf_bytes, g_sgl_num);
|
||||
- req.dst = create_buf(g_data_fmt, req.out_buf_bytes, unit_sz);
|
||||
+ unit_sz = cal_unit_sz(req.out_bytes, g_sgl_num);
|
||||
+ req.dst = create_buf(g_data_fmt, req.out_bytes, unit_sz);
|
||||
if (!req.dst) {
|
||||
ret = -ENOMEM;
|
||||
goto out_dst;
|
||||
}
|
||||
|
||||
- // set iv
|
||||
req.iv = malloc(AES_BLOCK_SIZE);
|
||||
if (!req.iv) {
|
||||
SEC_TST_PRT("req iv mem malloc failed!\n");
|
||||
@@ -2688,7 +2704,10 @@ static int sec_aead_sync_once(void)
|
||||
SEC_TST_PRT("Pro-%d, thread_id-%d, speed:%0.3f ops, Perf: %ld KB/s\n", getpid(),
|
||||
(int)syscall(__NR_gettid), speed, Perf);
|
||||
|
||||
+ SEC_TST_PRT("aead dump out addr is:\n");
|
||||
dump_mem(g_data_fmt, req.dst, req.out_bytes);
|
||||
+ SEC_TST_PRT("aead dump mac addr is:\n");
|
||||
+ dump_mem(0, req.mac, auth_size);
|
||||
|
||||
free(req.iv);
|
||||
out_iv:
|
||||
@@ -2696,6 +2715,8 @@ out_iv:
|
||||
out_dst:
|
||||
free_buf(g_data_fmt, req.src);
|
||||
out_src:
|
||||
+out_mac:
|
||||
+ free(req.mac);
|
||||
out_key:
|
||||
wd_aead_free_sess(h_sess);
|
||||
out:
|
||||
@@ -2827,6 +2848,7 @@ static int sec_aead_async_once(void)
|
||||
static pthread_t send_td;
|
||||
static pthread_t poll_td;
|
||||
thread_data_d td_data;
|
||||
+ __u16 mac_bytes;
|
||||
__u16 auth_size;
|
||||
__u16 in_size;
|
||||
__u16 iv_len;
|
||||
@@ -2857,8 +2879,7 @@ static int sec_aead_async_once(void)
|
||||
|
||||
/* should set key */
|
||||
dump_mem(WD_FLAT_BUF, (void *)tv->key, tv->klen);
|
||||
- if (setup.cmode == WD_CIPHER_CCM ||
|
||||
- setup.cmode == WD_CIPHER_GCM) {
|
||||
+ if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM) {
|
||||
ret = wd_aead_set_ckey(h_sess, (const __u8*)tv->key, tv->klen);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("aead sess set key failed!\n");
|
||||
@@ -2880,6 +2901,7 @@ static int sec_aead_async_once(void)
|
||||
}
|
||||
|
||||
auth_size = (__u16)(tv->clen - tv->plen);
|
||||
+ mac_bytes = auth_size;
|
||||
ret = wd_aead_set_authsize(h_sess, auth_size);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("set auth size fail, authsize: %u\n", auth_size);
|
||||
@@ -2898,6 +2920,17 @@ static int sec_aead_async_once(void)
|
||||
goto out_key;
|
||||
}
|
||||
SEC_TST_PRT("aead get max auth size: %u\n", ret);
|
||||
+ if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM)
|
||||
+ mac_bytes = 16;
|
||||
+
|
||||
+ req.mac = malloc(mac_bytes);
|
||||
+ if (!req.mac) {
|
||||
+ SEC_TST_PRT("req iv mem malloc failed!\n");
|
||||
+ ret = -ENOMEM;
|
||||
+ goto out_key;
|
||||
+ }
|
||||
+ memset(req.mac, 0, mac_bytes);
|
||||
+ req.mac_bytes = mac_bytes;
|
||||
|
||||
if (g_direction == 0)
|
||||
req.op_type = WD_CIPHER_ENCRYPTION_DIGEST;
|
||||
@@ -2908,7 +2941,7 @@ static int sec_aead_async_once(void)
|
||||
in_size = tv->alen + tv->plen + auth_size;
|
||||
if (in_size > BUFF_SIZE) {
|
||||
SEC_TST_PRT("alloc in buffer block size too small!\n");
|
||||
- goto out_key;
|
||||
+ goto out_mac;
|
||||
}
|
||||
req.assoc_bytes = tv->alen;
|
||||
unit_sz = cal_unit_sz(BUFF_SIZE, g_sgl_num);
|
||||
@@ -2931,15 +2964,15 @@ static int sec_aead_async_once(void)
|
||||
req.in_bytes = tv->plen;
|
||||
} else {
|
||||
memcpy(src, tv->assoc, tv->alen);
|
||||
- memcpy((src + tv->alen), tv->ctext, tv->clen);
|
||||
+ memcpy(src + tv->alen, tv->ctext, tv->clen - auth_size);
|
||||
req.in_bytes = tv->clen - auth_size;
|
||||
+ memcpy(req.mac, tv->ctext + tv->clen - auth_size, auth_size);
|
||||
}
|
||||
|
||||
-
|
||||
copy_mem(g_data_fmt, req.src, WD_FLAT_BUF, src,
|
||||
(size_t)(req.in_bytes + tv->alen));
|
||||
free(src);
|
||||
- SEC_TST_PRT("aead req src in--------->: %u\n", tv->alen + req.in_bytes);
|
||||
+ SEC_TST_PRT("aead req alen---->: %u. in_bytes--->:%u\n", tv->alen, req.in_bytes);
|
||||
dump_mem(g_data_fmt, req.src, tv->alen + req.in_bytes);
|
||||
|
||||
// alloc out buffer memory
|
||||
@@ -2949,7 +2982,6 @@ static int sec_aead_async_once(void)
|
||||
goto out_dst;
|
||||
}
|
||||
|
||||
- req.out_buf_bytes = BUFF_SIZE;
|
||||
if (g_direction == 0)
|
||||
req.out_bytes = tv->alen + tv->clen;
|
||||
else
|
||||
@@ -3010,6 +3042,8 @@ out_iv:
|
||||
out_dst:
|
||||
free_buf(g_data_fmt, req.src);
|
||||
out_src:
|
||||
+out_mac:
|
||||
+ free(req.mac);
|
||||
out_key:
|
||||
wd_aead_free_sess(h_sess);
|
||||
out:
|
||||
@@ -3026,6 +3060,7 @@ static int sec_aead_sync_multi(void)
|
||||
struct wd_aead_req req;
|
||||
static pthread_t sendtd[64];
|
||||
thread_data_d td_data;
|
||||
+ __u16 mac_bytes;
|
||||
__u16 auth_size;
|
||||
__u16 in_size;
|
||||
__u16 iv_len;
|
||||
@@ -3056,8 +3091,7 @@ static int sec_aead_sync_multi(void)
|
||||
|
||||
/* should set key */
|
||||
dump_mem(WD_FLAT_BUF, (void *)tv->key, tv->klen);
|
||||
- if (setup.cmode == WD_CIPHER_CCM ||
|
||||
- setup.cmode == WD_CIPHER_GCM) {
|
||||
+ if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM) {
|
||||
ret = wd_aead_set_ckey(h_sess, (const __u8*)tv->key, tv->klen);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("aead sess set key failed!\n");
|
||||
@@ -3079,6 +3113,7 @@ static int sec_aead_sync_multi(void)
|
||||
}
|
||||
|
||||
auth_size = (__u16)(tv->clen - tv->plen);
|
||||
+ mac_bytes = auth_size;
|
||||
ret = wd_aead_set_authsize(h_sess, auth_size);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("set auth size fail, authsize: %u\n", auth_size);
|
||||
@@ -3098,6 +3133,18 @@ static int sec_aead_sync_multi(void)
|
||||
}
|
||||
SEC_TST_PRT("aead get max auth size: %u\n", ret);
|
||||
|
||||
+ if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM)
|
||||
+ mac_bytes = 16;
|
||||
+
|
||||
+ req.mac = malloc(mac_bytes);
|
||||
+ if (!req.mac) {
|
||||
+ SEC_TST_PRT("req iv mem malloc failed!\n");
|
||||
+ ret = -ENOMEM;
|
||||
+ goto out_key;
|
||||
+ }
|
||||
+ memset(req.mac, 0, mac_bytes);
|
||||
+ req.mac_bytes = mac_bytes;
|
||||
+
|
||||
if (g_direction == 0)
|
||||
req.op_type = WD_CIPHER_ENCRYPTION_DIGEST;
|
||||
else
|
||||
@@ -3108,7 +3155,7 @@ static int sec_aead_sync_multi(void)
|
||||
in_size = tv->alen + tv->plen + auth_size;
|
||||
if (in_size > BUFF_SIZE) {
|
||||
SEC_TST_PRT("alloc in buffer block size too small!\n");
|
||||
- goto out_key;
|
||||
+ goto out_mac;
|
||||
}
|
||||
unit_sz = cal_unit_sz(BUFF_SIZE, g_sgl_num);
|
||||
void *src = create_buf(WD_FLAT_BUF, BUFF_SIZE, unit_sz);
|
||||
@@ -3123,8 +3170,9 @@ static int sec_aead_sync_multi(void)
|
||||
req.in_bytes = tv->plen;
|
||||
} else {
|
||||
memcpy(src, tv->assoc, tv->alen);
|
||||
- memcpy((src + tv->alen), tv->ctext, tv->clen);
|
||||
+ memcpy(src + tv->alen, tv->ctext, tv->clen - auth_size);
|
||||
req.in_bytes = tv->clen - auth_size;
|
||||
+ memcpy(req.mac, tv->ctext + tv->clen - auth_size, auth_size);
|
||||
}
|
||||
|
||||
req.src = create_buf(g_data_fmt, in_size, unit_sz);
|
||||
@@ -3137,7 +3185,7 @@ static int sec_aead_sync_multi(void)
|
||||
(size_t)(req.in_bytes + tv->alen));
|
||||
free(src);
|
||||
|
||||
- SEC_TST_PRT("aead req src in--------->: %u\n", tv->alen + req.in_bytes);
|
||||
+ SEC_TST_PRT("aead req src in>: alen:%u, input len:%d\n", tv->alen, req.in_bytes);
|
||||
dump_mem(g_data_fmt, req.src, tv->alen + req.in_bytes);
|
||||
|
||||
// alloc out buffer memory
|
||||
@@ -3147,7 +3195,6 @@ static int sec_aead_sync_multi(void)
|
||||
goto out_dst;
|
||||
}
|
||||
|
||||
- req.out_buf_bytes = BUFF_SIZE;
|
||||
if (g_direction == 0)
|
||||
req.out_bytes = tv->alen + tv->clen;
|
||||
else
|
||||
@@ -3175,6 +3222,7 @@ static int sec_aead_sync_multi(void)
|
||||
td_data.recv_num = g_times;
|
||||
td_data.sum_perf = 0;
|
||||
|
||||
+ printf("%s, req->in_bytes:%d\n", __func__, req.in_bytes);
|
||||
for (i = 0; i < g_thread_num; i++) {
|
||||
ret = pthread_create(&sendtd[i], NULL, aead_sync_send_thread, &td_data);
|
||||
if (ret) {
|
||||
@@ -3200,6 +3248,8 @@ out_iv:
|
||||
out_dst:
|
||||
free_buf(g_data_fmt, req.src);
|
||||
out_src:
|
||||
+out_mac:
|
||||
+ free(req.mac);
|
||||
out_key:
|
||||
wd_aead_free_sess(h_sess);
|
||||
out:
|
||||
@@ -3217,6 +3267,7 @@ static int sec_aead_async_multi(void)
|
||||
static pthread_t send_td[64];
|
||||
static pthread_t poll_td;
|
||||
thread_data_d td_data;
|
||||
+ __u16 mac_bytes;
|
||||
__u16 auth_size;
|
||||
__u16 in_size;
|
||||
__u16 iv_len;
|
||||
@@ -3247,8 +3298,7 @@ static int sec_aead_async_multi(void)
|
||||
|
||||
/* should set key */
|
||||
dump_mem(WD_FLAT_BUF, (void *)tv->key, tv->klen);
|
||||
- if (setup.cmode == WD_CIPHER_CCM ||
|
||||
- setup.cmode == WD_CIPHER_GCM) {
|
||||
+ if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM) {
|
||||
ret = wd_aead_set_ckey(h_sess, (const __u8*)tv->key, tv->klen);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("aead sess set key failed!\n");
|
||||
@@ -3270,6 +3320,7 @@ static int sec_aead_async_multi(void)
|
||||
}
|
||||
|
||||
auth_size = (__u16)(tv->clen - tv->plen);
|
||||
+ mac_bytes = auth_size;
|
||||
ret = wd_aead_set_authsize(h_sess, auth_size);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("set auth size fail, authsize: %u\n", auth_size);
|
||||
@@ -3289,6 +3340,15 @@ static int sec_aead_async_multi(void)
|
||||
}
|
||||
SEC_TST_PRT("aead get max auth size: %u\n", ret);
|
||||
|
||||
+ if (setup.cmode == WD_CIPHER_CCM || setup.cmode == WD_CIPHER_GCM)
|
||||
+ mac_bytes = 16;
|
||||
+
|
||||
+ req.mac = malloc(mac_bytes);
|
||||
+ if (req.mac == NULL)
|
||||
+ goto out;
|
||||
+ memset(req.mac, 0, mac_bytes);
|
||||
+ req.mac_bytes = mac_bytes;
|
||||
+
|
||||
if (g_direction == 0)
|
||||
req.op_type = WD_CIPHER_ENCRYPTION_DIGEST;
|
||||
else
|
||||
@@ -3321,8 +3381,9 @@ static int sec_aead_async_multi(void)
|
||||
req.in_bytes = tv->plen;
|
||||
} else {
|
||||
memcpy(src, tv->assoc, tv->alen);
|
||||
- memcpy((src + tv->alen), tv->ctext, tv->clen);
|
||||
+ memcpy(src + tv->alen, tv->ctext, tv->clen - auth_size);
|
||||
req.in_bytes = tv->clen - auth_size;
|
||||
+ memcpy(req.mac, tv->ctext + (tv->clen - auth_size), auth_size);
|
||||
}
|
||||
|
||||
copy_mem(g_data_fmt, req.src, WD_FLAT_BUF, src,
|
||||
@@ -3338,9 +3399,8 @@ static int sec_aead_async_multi(void)
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
- req.out_buf_bytes = BUFF_SIZE;
|
||||
if (g_direction == 0)
|
||||
- req.out_bytes = tv->alen + tv->clen;
|
||||
+ req.out_bytes = tv->alen + tv->clen - auth_size;
|
||||
else
|
||||
req.out_bytes = tv->alen + tv->plen;
|
||||
|
||||
@@ -3396,6 +3456,8 @@ static int sec_aead_async_multi(void)
|
||||
|
||||
dump_mem(g_data_fmt, req.dst, req.out_bytes);
|
||||
out:
|
||||
+ if (req.mac)
|
||||
+ free(req.mac);
|
||||
if (req.src)
|
||||
free_buf(g_data_fmt, req.src);
|
||||
if (req.dst)
|
||||
diff --git a/uadk_tool/sec_uadk_benchmark.c b/uadk_tool/sec_uadk_benchmark.c
|
||||
index 40ba227..d68ac25 100644
|
||||
--- a/uadk_tool/sec_uadk_benchmark.c
|
||||
+++ b/uadk_tool/sec_uadk_benchmark.c
|
||||
@@ -24,6 +24,7 @@ struct thread_pool {
|
||||
struct bd_pool *pool;
|
||||
u8 *iv;
|
||||
u8 *key;
|
||||
+ u8 *mac;
|
||||
} g_uadk_pool;
|
||||
|
||||
typedef struct uadk_thread_res {
|
||||
@@ -475,6 +476,7 @@ int init_uadk_bd_pool(void)
|
||||
|
||||
g_uadk_pool.iv = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
|
||||
g_uadk_pool.key = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
|
||||
+ g_uadk_pool.mac = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
|
||||
|
||||
g_uadk_pool.pool = malloc(g_thread_num * sizeof(struct bd_pool));
|
||||
if (!g_uadk_pool.pool) {
|
||||
@@ -611,9 +613,10 @@ static void *sec_uadk_async_run(void *arg)
|
||||
struct wd_aead_req areq;
|
||||
struct wd_digest_req dreq;
|
||||
struct bd_pool *uadk_pool;
|
||||
- u8 *priv_iv, *priv_key;
|
||||
+ u8 *priv_iv, *priv_key, *priv_mac;
|
||||
int try_cnt = 0;
|
||||
handle_t h_sess;
|
||||
+ u32 auth_size = 16;
|
||||
u32 count = 0;
|
||||
int ret, i = 0;
|
||||
|
||||
@@ -623,6 +626,7 @@ static void *sec_uadk_async_run(void *arg)
|
||||
uadk_pool = &g_uadk_pool.pool[pdata->td_id];
|
||||
priv_iv = &g_uadk_pool.iv[pdata->td_id];
|
||||
priv_key = &g_uadk_pool.key[pdata->td_id];
|
||||
+ priv_mac = &g_uadk_pool.mac[pdata->td_id];
|
||||
|
||||
memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
|
||||
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
|
||||
@@ -687,7 +691,7 @@ static void *sec_uadk_async_run(void *arg)
|
||||
wd_aead_free_sess(h_sess);
|
||||
return NULL;
|
||||
}
|
||||
- ret = wd_aead_set_authsize(h_sess, 16);
|
||||
+ ret = wd_aead_set_authsize(h_sess, auth_size);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("set auth size fail, authsize: 16\n");
|
||||
wd_aead_free_sess(h_sess);
|
||||
@@ -696,16 +700,15 @@ static void *sec_uadk_async_run(void *arg)
|
||||
|
||||
areq.op_type = pdata->optype;
|
||||
areq.iv = priv_iv; // aead IV need update with param
|
||||
+ areq.mac = priv_mac;
|
||||
areq.iv_bytes = pdata->ivsize;
|
||||
+ areq.mac_bytes = auth_size;
|
||||
areq.assoc_bytes = 16;
|
||||
areq.in_bytes = g_pktlen;
|
||||
- if (areq.op_type) {// decrypto
|
||||
+ if (areq.op_type)// decrypto
|
||||
areq.out_bytes = g_pktlen + 16; // aadsize = 16;
|
||||
- areq.out_buf_bytes = areq.out_bytes + 16; // authsize = 16
|
||||
- } else {
|
||||
+ else
|
||||
areq.out_bytes = g_pktlen + 32; // aadsize + authsize = 32;
|
||||
- areq.out_buf_bytes = areq.out_bytes + 32;
|
||||
- }
|
||||
|
||||
areq.data_fmt = 0;
|
||||
areq.state = 0;
|
||||
@@ -795,8 +798,9 @@ static void *sec_uadk_sync_run(void *arg)
|
||||
struct wd_aead_req areq;
|
||||
struct wd_digest_req dreq;
|
||||
struct bd_pool *uadk_pool;
|
||||
- u8 *priv_iv, *priv_key;
|
||||
+ u8 *priv_iv, *priv_key, *priv_mac;
|
||||
handle_t h_sess;
|
||||
+ u32 auth_size = 16;
|
||||
u32 count = 0;
|
||||
int ret, i = 0;
|
||||
|
||||
@@ -806,6 +810,7 @@ static void *sec_uadk_sync_run(void *arg)
|
||||
uadk_pool = &g_uadk_pool.pool[pdata->td_id];
|
||||
priv_iv = &g_uadk_pool.iv[pdata->td_id];
|
||||
priv_key = &g_uadk_pool.key[pdata->td_id];
|
||||
+ priv_mac = &g_uadk_pool.mac[pdata->td_id];
|
||||
|
||||
memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
|
||||
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
|
||||
@@ -860,7 +865,7 @@ static void *sec_uadk_sync_run(void *arg)
|
||||
wd_aead_free_sess(h_sess);
|
||||
return NULL;
|
||||
}
|
||||
- ret = wd_aead_set_authsize(h_sess, 16);
|
||||
+ ret = wd_aead_set_authsize(h_sess, auth_size);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("set auth size fail, authsize: 16\n");
|
||||
wd_aead_free_sess(h_sess);
|
||||
@@ -869,16 +874,16 @@ static void *sec_uadk_sync_run(void *arg)
|
||||
|
||||
areq.op_type = pdata->optype;
|
||||
areq.iv = priv_iv; // aead IV need update with param
|
||||
+ areq.mac = priv_mac;
|
||||
+ areq.mac_bytes = 16;
|
||||
areq.iv_bytes = pdata->ivsize;
|
||||
areq.assoc_bytes = 16;
|
||||
areq.in_bytes = g_pktlen;
|
||||
- if (areq.op_type) {// decrypto
|
||||
+ areq.mac_bytes = auth_size;
|
||||
+ if (areq.op_type)// decrypto
|
||||
areq.out_bytes = g_pktlen + 16; // aadsize = 16;
|
||||
- areq.out_buf_bytes = areq.out_bytes + 16; // authsize = 16
|
||||
- } else {
|
||||
+ else
|
||||
areq.out_bytes = g_pktlen + 32; // aadsize + authsize = 32;
|
||||
- areq.out_buf_bytes = areq.out_bytes + 32;
|
||||
- }
|
||||
|
||||
areq.data_fmt = 0;
|
||||
areq.state = 0;
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index ebad440..670bb33 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -305,6 +305,33 @@ void wd_aead_free_sess(handle_t h_sess)
|
||||
free(sess);
|
||||
}
|
||||
|
||||
+static int aead_mac_param_check(struct wd_aead_sess *sess,
|
||||
+ struct wd_aead_req *req)
|
||||
+{
|
||||
+ int ret = 0;
|
||||
+
|
||||
+ switch (sess->cmode) {
|
||||
+ case WD_CIPHER_CBC:
|
||||
+ if (req->mac_bytes < g_aead_mac_len[sess->dalg]) {
|
||||
+ WD_ERR("failed to check cbc-hmac mac buffer length!\n");
|
||||
+ ret = -WD_EINVAL;
|
||||
+ }
|
||||
+ break;
|
||||
+ case WD_CIPHER_CCM:
|
||||
+ case WD_CIPHER_GCM:
|
||||
+ if (req->mac_bytes < WD_AEAD_CCM_GCM_MAX) {
|
||||
+ WD_ERR("failed to check CCM or GCM mac buffer length!\n");
|
||||
+ ret = -WD_EINVAL;
|
||||
+ }
|
||||
+ break;
|
||||
+ default:
|
||||
+ ret = -WD_EINVAL;
|
||||
+ WD_ERR("set the aead cmode is error!\n");
|
||||
+ }
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
static int aead_param_check(struct wd_aead_sess *sess,
|
||||
struct wd_aead_req *req)
|
||||
{
|
||||
@@ -328,33 +355,23 @@ static int aead_param_check(struct wd_aead_sess *sess,
|
||||
}
|
||||
|
||||
if (unlikely(req->iv_bytes != get_iv_block_size(sess->cmode))) {
|
||||
- WD_ERR("failed to check aead IV length!\n");
|
||||
+ WD_ERR("failed to check aead IV length, size:%u\n", req->iv_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (unlikely(req->out_buf_bytes < req->out_bytes)) {
|
||||
- WD_ERR("failed to check aead out buffer length!\n");
|
||||
- return -WD_EINVAL;
|
||||
- }
|
||||
-
|
||||
- if (unlikely(req->op_type == WD_CIPHER_ENCRYPTION_DIGEST &&
|
||||
- req->out_buf_bytes < (req->out_bytes + sess->auth_bytes))) {
|
||||
- WD_ERR("failed to check aead type or mac length!\n");
|
||||
+ ret = aead_mac_param_check(sess, req);
|
||||
+ if (unlikely(ret))
|
||||
return -WD_EINVAL;
|
||||
- }
|
||||
|
||||
if (req->data_fmt == WD_SGL_BUF) {
|
||||
len = req->in_bytes + req->assoc_bytes;
|
||||
- if (req->op_type == WD_CIPHER_DECRYPTION_DIGEST)
|
||||
- len += sess->auth_bytes;
|
||||
-
|
||||
ret = wd_check_datalist(req->list_src, len);
|
||||
if (unlikely(ret)) {
|
||||
WD_ERR("failed to check the src datalist!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- ret = wd_check_datalist(req->list_dst, req->out_buf_bytes);
|
||||
+ ret = wd_check_datalist(req->list_dst, req->out_bytes);
|
||||
if (unlikely(ret)) {
|
||||
WD_ERR("failed to check the dst datalist!\n");
|
||||
return -WD_EINVAL;
|
||||
@@ -480,6 +497,7 @@ static void fill_request_msg(struct wd_aead_msg *msg, struct wd_aead_req *req,
|
||||
msg->iv = req->iv;
|
||||
msg->iv_bytes = req->iv_bytes;
|
||||
msg->assoc_bytes = req->assoc_bytes;
|
||||
+ msg->mac = req->mac;
|
||||
msg->auth_bytes = sess->auth_bytes;
|
||||
msg->data_fmt = req->data_fmt;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,80 +0,0 @@
|
||||
From e191549317c08e340b9406bf2958868b1f119df2 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Thu, 13 Jan 2022 16:33:37 +0800
|
||||
Subject: [PATCH 44/53] cipher: add semi-weak keys checking
|
||||
|
||||
Add semi-weak keys checking based on OpenSSL. it will improve the
|
||||
security of the system.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
wd_cipher.c | 30 +++++++++++++++++++++++-------
|
||||
1 file changed, 23 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index 9c1f98c..85f7e65 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -19,15 +19,31 @@
|
||||
#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE)
|
||||
|
||||
#define WD_POOL_MAX_ENTRIES 1024
|
||||
-#define DES_WEAK_KEY_NUM 4
|
||||
+#define DES_WEAK_KEY_NUM 16
|
||||
#define MAX_RETRY_COUNTS 200000000
|
||||
|
||||
#define POLL_SIZE 100000
|
||||
#define POLL_TIME 1000
|
||||
|
||||
-static __u64 des_weak_key[DES_WEAK_KEY_NUM] = {
|
||||
- 0x0101010101010101, 0xFEFEFEFEFEFEFEFE,
|
||||
- 0xE0E0E0E0F1F1F1F1, 0x1F1F1F1F0E0E0E0E
|
||||
+static const unsigned char des_weak_keys[DES_WEAK_KEY_NUM][DES_KEY_SIZE] = {
|
||||
+ /* weak keys */
|
||||
+ {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
|
||||
+ {0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE},
|
||||
+ {0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E},
|
||||
+ {0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1},
|
||||
+ /* semi-weak keys */
|
||||
+ {0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE},
|
||||
+ {0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01},
|
||||
+ {0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1},
|
||||
+ {0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E},
|
||||
+ {0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1},
|
||||
+ {0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01},
|
||||
+ {0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE},
|
||||
+ {0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E},
|
||||
+ {0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E},
|
||||
+ {0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01},
|
||||
+ {0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE},
|
||||
+ {0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1}
|
||||
};
|
||||
|
||||
struct wd_cipher_setting {
|
||||
@@ -81,12 +97,12 @@ void wd_cipher_set_driver(struct wd_cipher_driver *drv)
|
||||
wd_cipher_setting.driver = drv;
|
||||
}
|
||||
|
||||
-static bool is_des_weak_key(const __u64 *key)
|
||||
+static bool is_des_weak_key(const __u8 *key)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < DES_WEAK_KEY_NUM; i++) {
|
||||
- if (*key == des_weak_key[i])
|
||||
+ if (memcmp(des_weak_keys[i], key, DES_KEY_SIZE) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -173,7 +189,7 @@ int wd_cipher_set_key(handle_t h_sess, const __u8 *key, __u32 key_len)
|
||||
WD_ERR("cipher set key input key length err!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
- if (sess->alg == WD_CIPHER_DES && is_des_weak_key((__u64 *)key)) {
|
||||
+ if (sess->alg == WD_CIPHER_DES && is_des_weak_key(key)) {
|
||||
WD_ERR("input des key is weak key!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
From ef361818b1a67a6540ea4b0d2538090eea56863e Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Sat, 15 Jan 2022 16:53:58 +0800
|
||||
Subject: [PATCH 45/53] uadk: ioctl return result should be printed
|
||||
|
||||
ioctl return result may be discarded,
|
||||
it is useful to debug kernel error,
|
||||
so it should be printed directly.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd.c | 6 ++++--
|
||||
1 file changed, 4 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/wd.c b/wd.c
|
||||
index 787d74b..6bbf677 100644
|
||||
--- a/wd.c
|
||||
+++ b/wd.c
|
||||
@@ -386,7 +386,8 @@ int wd_ctx_start(handle_t h_ctx)
|
||||
|
||||
ret = wd_ctx_set_io_cmd(h_ctx, UACCE_CMD_START, NULL);
|
||||
if (ret)
|
||||
- WD_ERR("Fail to start on %s (%d).\n", ctx->dev_path, -errno);
|
||||
+ WD_ERR("Fail to start on %s (%d), ret = %d!\n",
|
||||
+ ctx->dev_path, -errno, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -401,7 +402,8 @@ int wd_release_ctx_force(handle_t h_ctx)
|
||||
|
||||
ret = wd_ctx_set_io_cmd(h_ctx, UACCE_CMD_PUT_Q, NULL);
|
||||
if (ret)
|
||||
- WD_ERR("Fail to stop on %s (%d).\n", ctx->dev_path, -errno);
|
||||
+ WD_ERR("Fail to stop on %s (%d), ret = %d!\n",
|
||||
+ ctx->dev_path, -errno, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,412 +0,0 @@
|
||||
From 282d7d06d0585d117ab62263ab3722950e9693f0 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Sat, 15 Jan 2022 16:53:59 +0800
|
||||
Subject: [PATCH 46/53] uadk: fix environment uninit repeatly error
|
||||
|
||||
use wd_uninit_env_config to restore wd_init_env_config do,
|
||||
move setting gloab environment config to wd_init_env_config.
|
||||
function should not be set to NULL, because it may used to
|
||||
uninit resource.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
include/wd_util.h | 7 ++--
|
||||
wd_aead.c | 4 +--
|
||||
wd_cipher.c | 4 +--
|
||||
wd_comp.c | 4 +--
|
||||
wd_dh.c | 4 +--
|
||||
wd_digest.c | 4 +--
|
||||
wd_ecc.c | 4 +--
|
||||
wd_rsa.c | 4 +--
|
||||
wd_util.c | 88 ++++++++++++++++++++++++++++++-----------------
|
||||
9 files changed, 74 insertions(+), 49 deletions(-)
|
||||
|
||||
diff --git a/include/wd_util.h b/include/wd_util.h
|
||||
index ef95907..2d3c1e4 100644
|
||||
--- a/include/wd_util.h
|
||||
+++ b/include/wd_util.h
|
||||
@@ -66,8 +66,6 @@ struct wd_env_config {
|
||||
struct wd_env_config_per_numa *config_per_numa;
|
||||
/* Let's make it as a gobal config, not per numa */
|
||||
bool enable_internal_poll;
|
||||
- int (*alg_poll_ctx)(__u32, __u32, __u32 *);
|
||||
- void (*alg_uninit)(void);
|
||||
|
||||
/* resource config */
|
||||
struct wd_sched *sched;
|
||||
@@ -263,8 +261,11 @@ int wd_alg_env_init(struct wd_env_config *config,
|
||||
* wd_alg_env_uninit() - uninit specific wd algorithm environment configuration.
|
||||
* @config: Pointer of wd_env_config which is used to store environment
|
||||
* variable information.
|
||||
+ * @ops: Define functions which will be used by specific wd algorithm
|
||||
+ * environment init.
|
||||
*/
|
||||
-void wd_alg_env_uninit(struct wd_env_config *env_config);
|
||||
+void wd_alg_env_uninit(struct wd_env_config *env_config,
|
||||
+ const struct wd_alg_ops *ops);
|
||||
|
||||
/*
|
||||
* wd_add_task_to_async_queue() - Add an async request to its related async
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index 670bb33..32d06ec 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -716,7 +716,7 @@ int wd_aead_env_init(struct wd_sched *sched)
|
||||
|
||||
void wd_aead_env_uninit(void)
|
||||
{
|
||||
- return wd_alg_env_uninit(&wd_aead_env_config);
|
||||
+ return wd_alg_env_uninit(&wd_aead_env_config, &wd_aead_ops);
|
||||
}
|
||||
|
||||
int wd_aead_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
|
||||
@@ -734,7 +734,7 @@ int wd_aead_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
|
||||
|
||||
void wd_aead_ctx_num_uninit(void)
|
||||
{
|
||||
- return wd_alg_env_uninit(&wd_aead_env_config);
|
||||
+ return wd_alg_env_uninit(&wd_aead_env_config, &wd_aead_ops);
|
||||
}
|
||||
|
||||
int wd_aead_get_env_param(__u32 node, __u32 type, __u32 mode,
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index 85f7e65..5be3123 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -634,7 +634,7 @@ int wd_cipher_env_init(struct wd_sched *sched)
|
||||
|
||||
void wd_cipher_env_uninit(void)
|
||||
{
|
||||
- return wd_alg_env_uninit(&wd_cipher_env_config);
|
||||
+ return wd_alg_env_uninit(&wd_cipher_env_config, &wd_cipher_ops);
|
||||
}
|
||||
|
||||
int wd_cipher_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
|
||||
@@ -652,7 +652,7 @@ int wd_cipher_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
|
||||
|
||||
void wd_cipher_ctx_num_uninit(void)
|
||||
{
|
||||
- return wd_alg_env_uninit(&wd_cipher_env_config);
|
||||
+ return wd_alg_env_uninit(&wd_cipher_env_config, &wd_cipher_ops);
|
||||
}
|
||||
|
||||
int wd_cipher_get_env_param(__u32 node, __u32 type, __u32 mode,
|
||||
diff --git a/wd_comp.c b/wd_comp.c
|
||||
index fc355a9..7868551 100644
|
||||
--- a/wd_comp.c
|
||||
+++ b/wd_comp.c
|
||||
@@ -775,7 +775,7 @@ int wd_comp_env_init(struct wd_sched *sched)
|
||||
|
||||
void wd_comp_env_uninit(void)
|
||||
{
|
||||
- return wd_alg_env_uninit(&wd_comp_env_config);
|
||||
+ return wd_alg_env_uninit(&wd_comp_env_config, &wd_comp_ops);
|
||||
}
|
||||
|
||||
int wd_comp_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
|
||||
@@ -798,7 +798,7 @@ int wd_comp_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
|
||||
|
||||
void wd_comp_ctx_num_uninit(void)
|
||||
{
|
||||
- return wd_alg_env_uninit(&wd_comp_env_config);
|
||||
+ return wd_alg_env_uninit(&wd_comp_env_config, &wd_comp_ops);
|
||||
}
|
||||
|
||||
int wd_comp_get_env_param(__u32 node, __u32 type, __u32 mode,
|
||||
diff --git a/wd_dh.c b/wd_dh.c
|
||||
index 7b849ac..1784099 100644
|
||||
--- a/wd_dh.c
|
||||
+++ b/wd_dh.c
|
||||
@@ -564,7 +564,7 @@ int wd_dh_env_init(struct wd_sched *sched)
|
||||
|
||||
void wd_dh_env_uninit(void)
|
||||
{
|
||||
- return wd_alg_env_uninit(&wd_dh_env_config);
|
||||
+ return wd_alg_env_uninit(&wd_dh_env_config, &wd_dh_ops);
|
||||
}
|
||||
|
||||
int wd_dh_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
|
||||
@@ -582,7 +582,7 @@ int wd_dh_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
|
||||
|
||||
void wd_dh_ctx_num_uninit(void)
|
||||
{
|
||||
- return wd_alg_env_uninit(&wd_dh_env_config);
|
||||
+ return wd_alg_env_uninit(&wd_dh_env_config, &wd_dh_ops);
|
||||
}
|
||||
|
||||
int wd_dh_get_env_param(__u32 node, __u32 type, __u32 mode,
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index 2b3661d..525d6a9 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -525,7 +525,7 @@ int wd_digest_env_init(struct wd_sched *sched)
|
||||
|
||||
void wd_digest_env_uninit(void)
|
||||
{
|
||||
- return wd_alg_env_uninit(&wd_digest_env_config);
|
||||
+ return wd_alg_env_uninit(&wd_digest_env_config, &wd_digest_ops);
|
||||
}
|
||||
|
||||
int wd_digest_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
|
||||
@@ -543,7 +543,7 @@ int wd_digest_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
|
||||
|
||||
void wd_digest_ctx_num_uninit(void)
|
||||
{
|
||||
- return wd_alg_env_uninit(&wd_digest_env_config);
|
||||
+ return wd_alg_env_uninit(&wd_digest_env_config, &wd_digest_ops);
|
||||
}
|
||||
|
||||
int wd_digest_get_env_param(__u32 node, __u32 type, __u32 mode,
|
||||
diff --git a/wd_ecc.c b/wd_ecc.c
|
||||
index e37fb39..e324473 100644
|
||||
--- a/wd_ecc.c
|
||||
+++ b/wd_ecc.c
|
||||
@@ -2286,7 +2286,7 @@ int wd_ecc_env_init(struct wd_sched *sched)
|
||||
|
||||
void wd_ecc_env_uninit(void)
|
||||
{
|
||||
- return wd_alg_env_uninit(&wd_ecc_env_config);
|
||||
+ return wd_alg_env_uninit(&wd_ecc_env_config, &wd_ecc_ops);
|
||||
}
|
||||
|
||||
int wd_ecc_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
|
||||
@@ -2304,7 +2304,7 @@ int wd_ecc_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
|
||||
|
||||
void wd_ecc_ctx_num_uninit(void)
|
||||
{
|
||||
- return wd_alg_env_uninit(&wd_ecc_env_config);
|
||||
+ return wd_alg_env_uninit(&wd_ecc_env_config, &wd_ecc_ops);
|
||||
}
|
||||
|
||||
int wd_ecc_get_env_param(__u32 node, __u32 type, __u32 mode,
|
||||
diff --git a/wd_rsa.c b/wd_rsa.c
|
||||
index b6cc0d1..1f911b4 100644
|
||||
--- a/wd_rsa.c
|
||||
+++ b/wd_rsa.c
|
||||
@@ -1160,7 +1160,7 @@ int wd_rsa_env_init(struct wd_sched *sched)
|
||||
|
||||
void wd_rsa_env_uninit(void)
|
||||
{
|
||||
- return wd_alg_env_uninit(&wd_rsa_env_config);
|
||||
+ return wd_alg_env_uninit(&wd_rsa_env_config, &wd_rsa_ops);
|
||||
}
|
||||
|
||||
int wd_rsa_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
|
||||
@@ -1178,7 +1178,7 @@ int wd_rsa_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
|
||||
|
||||
void wd_rsa_ctx_num_uninit(void)
|
||||
{
|
||||
- return wd_alg_env_uninit(&wd_rsa_env_config);
|
||||
+ return wd_alg_env_uninit(&wd_rsa_env_config, &wd_rsa_ops);
|
||||
}
|
||||
|
||||
int wd_rsa_get_env_param(__u32 node, __u32 type, __u32 mode,
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 6cae768..38599c2 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -868,11 +868,27 @@ static int wd_parse_ctx_attr(struct wd_env_config *env_config,
|
||||
}
|
||||
|
||||
static int wd_init_env_config(struct wd_env_config *config,
|
||||
- struct wd_ctx_attr *attr)
|
||||
+ struct wd_ctx_attr *attr,
|
||||
+ const struct wd_alg_ops *ops,
|
||||
+ const struct wd_config_variable *table,
|
||||
+ __u32 table_size)
|
||||
{
|
||||
+ config->op_type_num = ops->op_type_num;
|
||||
+ config->table_size = table_size;
|
||||
+ config->table = table;
|
||||
+
|
||||
return attr ? wd_parse_ctx_attr(config, attr) : wd_parse_env(config);
|
||||
}
|
||||
|
||||
+static void wd_uninit_env_config(struct wd_env_config *config)
|
||||
+{
|
||||
+ config->op_type_num = 0;
|
||||
+ config->table_size = 0;
|
||||
+ config->table = NULL;
|
||||
+
|
||||
+ wd_free_env(config);
|
||||
+}
|
||||
+
|
||||
static __u8 get_ctx_mode(struct wd_env_config_per_numa *config, int idx)
|
||||
{
|
||||
struct wd_ctx_range **ctx_table = config->ctx_table;
|
||||
@@ -1051,7 +1067,8 @@ static int wd_sched_fill_table(struct wd_env_config_per_numa *config_numa,
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int wd_init_sched_config(struct wd_env_config *config)
|
||||
+static int wd_init_sched_config(struct wd_env_config *config,
|
||||
+ void *alg_poll_ctx)
|
||||
{
|
||||
struct wd_env_config_per_numa *config_numa;
|
||||
int i, j, ret, max_node, type_num;
|
||||
@@ -1063,7 +1080,7 @@ static int wd_init_sched_config(struct wd_env_config *config)
|
||||
return -WD_EINVAL;
|
||||
|
||||
if (!config->enable_internal_poll)
|
||||
- func = config->alg_poll_ctx;
|
||||
+ func = alg_poll_ctx;
|
||||
|
||||
config->internal_sched = false;
|
||||
type_num = config->op_type_num;
|
||||
@@ -1340,7 +1357,8 @@ static void wd_uninit_one_task_queue(struct async_task_queue *task_queue)
|
||||
}
|
||||
|
||||
static int wd_init_async_polling_thread_per_numa(struct wd_env_config *config,
|
||||
- struct wd_env_config_per_numa *config_numa)
|
||||
+ struct wd_env_config_per_numa *config_numa,
|
||||
+ void *alg_poll_ctx)
|
||||
{
|
||||
struct async_task_queue *task_queue, *queue_head;
|
||||
int i, j, ret;
|
||||
@@ -1365,7 +1383,7 @@ static int wd_init_async_polling_thread_per_numa(struct wd_env_config *config,
|
||||
|
||||
task_queue = queue_head;
|
||||
for (i = 0; i < num; task_queue++, i++) {
|
||||
- ret = wd_init_one_task_queue(task_queue, config->alg_poll_ctx);
|
||||
+ ret = wd_init_one_task_queue(task_queue, alg_poll_ctx);
|
||||
if (ret) {
|
||||
for (j = 0; j < i; task_queue++, j++)
|
||||
wd_uninit_one_task_queue(task_queue);
|
||||
@@ -1386,6 +1404,9 @@ static void wd_uninit_async_polling_thread_per_numa(struct wd_env_config *cfg,
|
||||
double num;
|
||||
int i;
|
||||
|
||||
+ if (!config_numa || !config_numa->async_task_queue_array)
|
||||
+ return;
|
||||
+
|
||||
head = config_numa->async_task_queue_array;
|
||||
task_queue = head;
|
||||
num = fmin(config_numa->async_poll_num, config_numa->async_ctx_num);
|
||||
@@ -1396,7 +1417,8 @@ static void wd_uninit_async_polling_thread_per_numa(struct wd_env_config *cfg,
|
||||
config_numa->async_task_queue_array = NULL;
|
||||
}
|
||||
|
||||
-static int wd_init_async_polling_thread(struct wd_env_config *config)
|
||||
+static int wd_init_async_polling_thread(struct wd_env_config *config,
|
||||
+ void *alg_poll_ctx)
|
||||
{
|
||||
struct wd_env_config_per_numa *config_numa;
|
||||
int i, ret;
|
||||
@@ -1405,12 +1427,19 @@ static int wd_init_async_polling_thread(struct wd_env_config *config)
|
||||
return 0;
|
||||
|
||||
FOREACH_NUMA(i, config, config_numa) {
|
||||
- ret = wd_init_async_polling_thread_per_numa(config, config_numa);
|
||||
+ ret = wd_init_async_polling_thread_per_numa(config, config_numa,
|
||||
+ alg_poll_ctx);
|
||||
if (ret)
|
||||
- return ret;
|
||||
+ goto out;
|
||||
}
|
||||
|
||||
return 0;
|
||||
+
|
||||
+out:
|
||||
+ FOREACH_NUMA(i, config, config_numa)
|
||||
+ wd_uninit_async_polling_thread_per_numa(config, config_numa);
|
||||
+
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
static void wd_uninit_async_polling_thread(struct wd_env_config *config)
|
||||
@@ -1434,7 +1463,7 @@ static int wd_init_resource(struct wd_env_config *config,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
- ret = wd_init_sched_config(config);
|
||||
+ ret = wd_init_sched_config(config, ops->alg_poll_ctx);
|
||||
if (ret)
|
||||
goto err_uninit_ctx;
|
||||
|
||||
@@ -1442,7 +1471,7 @@ static int wd_init_resource(struct wd_env_config *config,
|
||||
if (ret)
|
||||
goto err_uninit_sched;
|
||||
|
||||
- ret = wd_init_async_polling_thread(config);
|
||||
+ ret = wd_init_async_polling_thread(config, ops->alg_poll_ctx);
|
||||
if (ret)
|
||||
goto err_uninit_alg;
|
||||
|
||||
@@ -1461,13 +1490,19 @@ err_uninit_ctx:
|
||||
return ret;
|
||||
}
|
||||
|
||||
-static void wd_uninit_resource(struct wd_env_config *config)
|
||||
+static void wd_uninit_resource(struct wd_env_config *config,
|
||||
+ const struct wd_alg_ops *ops)
|
||||
{
|
||||
wd_uninit_async_polling_thread(config);
|
||||
- config->alg_uninit();
|
||||
- if (config->internal_sched)
|
||||
+ ops->alg_uninit();
|
||||
+
|
||||
+ if (config->internal_sched) {
|
||||
wd_uninit_sched_config(config->sched);
|
||||
+ config->sched = NULL;
|
||||
+ }
|
||||
+
|
||||
wd_free_ctx(config->ctx_config);
|
||||
+ config->ctx_config = NULL;
|
||||
}
|
||||
|
||||
int wd_alg_env_init(struct wd_env_config *env_config,
|
||||
@@ -1478,43 +1513,32 @@ int wd_alg_env_init(struct wd_env_config *env_config,
|
||||
{
|
||||
int ret;
|
||||
|
||||
- env_config->op_type_num = ops->op_type_num;
|
||||
- env_config->alg_poll_ctx = ops->alg_poll_ctx;
|
||||
- env_config->table = table;
|
||||
- env_config->table_size = table_size;
|
||||
-
|
||||
ret = wd_alloc_numa(env_config, ops);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
- ret = wd_init_env_config(env_config, ctx_attr);
|
||||
+ ret = wd_init_env_config(env_config, ctx_attr, ops, table, table_size);
|
||||
if (ret)
|
||||
goto free_numa;
|
||||
|
||||
ret = wd_init_resource(env_config, ops);
|
||||
if (ret)
|
||||
- goto free_env;
|
||||
-
|
||||
- /* Use alg_uninit as a sign of initialization complete */
|
||||
- env_config->alg_uninit = ops->alg_uninit;
|
||||
+ goto uninit_env_config;
|
||||
|
||||
return 0;
|
||||
|
||||
-free_env:
|
||||
- wd_free_env(env_config);
|
||||
+uninit_env_config:
|
||||
+ wd_uninit_env_config(env_config);
|
||||
free_numa:
|
||||
wd_free_numa(env_config);
|
||||
return ret;
|
||||
}
|
||||
|
||||
-void wd_alg_env_uninit(struct wd_env_config *env_config)
|
||||
+void wd_alg_env_uninit(struct wd_env_config *env_config,
|
||||
+ const struct wd_alg_ops *ops)
|
||||
{
|
||||
- /* Check whether the initialization is complete */
|
||||
- if (!env_config->alg_uninit)
|
||||
- return;
|
||||
-
|
||||
- wd_uninit_resource(env_config);
|
||||
- wd_free_env(env_config);
|
||||
+ wd_uninit_resource(env_config, ops);
|
||||
+ wd_uninit_env_config(env_config);
|
||||
wd_free_numa(env_config);
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,140 +0,0 @@
|
||||
From e4a3312ea000abb796d513c59a8ae10dd9ef605b Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Sat, 15 Jan 2022 16:54:00 +0800
|
||||
Subject: [PATCH 47/53] uadk: fix wd_free_ctx and wd_uninit_sched_config
|
||||
|
||||
wd_free_ctx and wd_uninit_sched_config not use struct wd_env_config
|
||||
as an input parameter, they need to clear wd_env_config member outside,
|
||||
so optimize it to set null within the function.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_util.c | 51 ++++++++++++++++++++++++---------------------------
|
||||
1 file changed, 24 insertions(+), 27 deletions(-)
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 38599c2..8ad2bd0 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -1027,14 +1027,18 @@ err_free_ctx_config:
|
||||
return ret;
|
||||
}
|
||||
|
||||
-static void wd_free_ctx(struct wd_ctx_config *ctx_config)
|
||||
+static void wd_free_ctx(struct wd_env_config *config)
|
||||
{
|
||||
- if (!ctx_config)
|
||||
+ struct wd_ctx_config *ctx_config;
|
||||
+
|
||||
+ if (!config->ctx_config)
|
||||
return;
|
||||
|
||||
+ ctx_config = config->ctx_config;
|
||||
wd_put_wd_ctx(ctx_config, ctx_config->ctx_num);
|
||||
free(ctx_config->ctxs);
|
||||
free(ctx_config);
|
||||
+ config->ctx_config = NULL;
|
||||
}
|
||||
|
||||
static int wd_sched_fill_table(struct wd_env_config_per_numa *config_numa,
|
||||
@@ -1067,14 +1071,23 @@ static int wd_sched_fill_table(struct wd_env_config_per_numa *config_numa,
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static void wd_uninit_sched_config(struct wd_env_config *config)
|
||||
+{
|
||||
+ if (!config->sched || !config->internal_sched)
|
||||
+ return;
|
||||
+
|
||||
+ wd_sched_rr_release(config->sched);
|
||||
+ config->sched = NULL;
|
||||
+}
|
||||
+
|
||||
static int wd_init_sched_config(struct wd_env_config *config,
|
||||
void *alg_poll_ctx)
|
||||
{
|
||||
struct wd_env_config_per_numa *config_numa;
|
||||
int i, j, ret, max_node, type_num;
|
||||
- struct wd_sched *sched;
|
||||
void *func = NULL;
|
||||
|
||||
+ type_num = config->op_type_num;
|
||||
max_node = numa_max_node() + 1;
|
||||
if (max_node <= 0)
|
||||
return -WD_EINVAL;
|
||||
@@ -1083,7 +1096,6 @@ static int wd_init_sched_config(struct wd_env_config *config,
|
||||
func = alg_poll_ctx;
|
||||
|
||||
config->internal_sched = false;
|
||||
- type_num = config->op_type_num;
|
||||
if (!config->sched) {
|
||||
WD_ERR("no sched is specified, alloc a default sched!\n");
|
||||
config->sched = wd_sched_rr_alloc(SCHED_POLICY_RR, type_num,
|
||||
@@ -1094,13 +1106,12 @@ static int wd_init_sched_config(struct wd_env_config *config,
|
||||
config->internal_sched = true;
|
||||
}
|
||||
|
||||
- sched = config->sched;
|
||||
- sched->name = "SCHED_RR";
|
||||
+ config->sched->name = "SCHED_RR";
|
||||
|
||||
FOREACH_NUMA(i, config, config_numa) {
|
||||
for (j = 0; j < CTX_MODE_MAX; j++) {
|
||||
ret = wd_sched_fill_table(config_numa,
|
||||
- sched, j,
|
||||
+ config->sched, j,
|
||||
type_num);
|
||||
if (ret)
|
||||
goto err_release_sched;
|
||||
@@ -1110,13 +1121,9 @@ static int wd_init_sched_config(struct wd_env_config *config,
|
||||
return 0;
|
||||
|
||||
err_release_sched:
|
||||
- wd_sched_rr_release(sched);
|
||||
- return ret;
|
||||
-}
|
||||
+ wd_uninit_sched_config(config);
|
||||
|
||||
-static void wd_uninit_sched_config(struct wd_sched *sched_config)
|
||||
-{
|
||||
- return wd_sched_rr_release(sched_config);
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
static struct async_task_queue *find_async_queue(struct wd_env_config *config,
|
||||
@@ -1480,13 +1487,9 @@ static int wd_init_resource(struct wd_env_config *config,
|
||||
err_uninit_alg:
|
||||
ops->alg_uninit();
|
||||
err_uninit_sched:
|
||||
- if (config->internal_sched) {
|
||||
- wd_uninit_sched_config(config->sched);
|
||||
- config->sched = NULL;
|
||||
- }
|
||||
+ wd_uninit_sched_config(config);
|
||||
err_uninit_ctx:
|
||||
- wd_free_ctx(config->ctx_config);
|
||||
- config->ctx_config = NULL;
|
||||
+ wd_free_ctx(config);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1495,14 +1498,8 @@ static void wd_uninit_resource(struct wd_env_config *config,
|
||||
{
|
||||
wd_uninit_async_polling_thread(config);
|
||||
ops->alg_uninit();
|
||||
-
|
||||
- if (config->internal_sched) {
|
||||
- wd_uninit_sched_config(config->sched);
|
||||
- config->sched = NULL;
|
||||
- }
|
||||
-
|
||||
- wd_free_ctx(config->ctx_config);
|
||||
- config->ctx_config = NULL;
|
||||
+ wd_uninit_sched_config(config);
|
||||
+ wd_free_ctx(config);
|
||||
}
|
||||
|
||||
int wd_alg_env_init(struct wd_env_config *env_config,
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,206 +0,0 @@
|
||||
From 8ad7bf917ea2940042e707cf37187d2623004bbc Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Sat, 15 Jan 2022 16:54:01 +0800
|
||||
Subject: [PATCH 48/53] uadk: env: fix free ctx table memory leak
|
||||
|
||||
Add wd_free_ctx_table to free ctx table of all numa and
|
||||
wd_free_ctx_table_per_numa to free single numa's ctx table.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
include/wd_util.h | 2 +-
|
||||
wd_util.c | 79 +++++++++++++++++++++++------------------------
|
||||
2 files changed, 40 insertions(+), 41 deletions(-)
|
||||
|
||||
diff --git a/include/wd_util.h b/include/wd_util.h
|
||||
index 2d3c1e4..c07ecce 100644
|
||||
--- a/include/wd_util.h
|
||||
+++ b/include/wd_util.h
|
||||
@@ -16,7 +16,7 @@ extern "C" {
|
||||
|
||||
#define FOREACH_NUMA(i, config, config_numa) \
|
||||
for (i = 0, config_numa = config->config_per_numa; \
|
||||
- i < config->numa_num; config_numa++, i++)
|
||||
+ config_numa && i < config->numa_num; config_numa++, i++)
|
||||
|
||||
struct wd_async_msg_pool {
|
||||
struct msg_pool *pools;
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 8ad2bd0..7fa688d 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -351,9 +351,6 @@ static void wd_free_numa(struct wd_env_config *config)
|
||||
struct wd_env_config_per_numa *config_numa;
|
||||
int i;
|
||||
|
||||
- if (!config->config_per_numa)
|
||||
- return;
|
||||
-
|
||||
FOREACH_NUMA(i, config, config_numa)
|
||||
free(config_numa->dev);
|
||||
|
||||
@@ -566,12 +563,12 @@ out:
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
-static int wd_alloc_ctx_table(struct wd_env_config_per_numa *config_numa)
|
||||
+static int wd_alloc_ctx_table_per_numa(struct wd_env_config_per_numa *config)
|
||||
{
|
||||
struct wd_ctx_range **ctx_table;
|
||||
int i, j, ret;
|
||||
|
||||
- if (config_numa->ctx_table)
|
||||
+ if (config->ctx_table)
|
||||
return 0;
|
||||
|
||||
ctx_table = calloc(1, sizeof(struct wd_ctx_range *) * CTX_MODE_MAX);
|
||||
@@ -581,27 +578,48 @@ static int wd_alloc_ctx_table(struct wd_env_config_per_numa *config_numa)
|
||||
for (i = 0; i < CTX_MODE_MAX; i++) {
|
||||
ctx_table[i] = calloc(1,
|
||||
sizeof(struct wd_ctx_range) *
|
||||
- config_numa->op_type_num);
|
||||
+ config->op_type_num);
|
||||
if (!ctx_table[i]) {
|
||||
ret = -WD_ENOMEM;
|
||||
goto free_mem;
|
||||
}
|
||||
}
|
||||
|
||||
- config_numa->ctx_table = ctx_table;
|
||||
+ config->ctx_table = ctx_table;
|
||||
|
||||
return 0;
|
||||
|
||||
free_mem:
|
||||
- for (j = 0; j < i; j++) {
|
||||
+ for (j = 0; j < i; j++)
|
||||
free(ctx_table[j]);
|
||||
- ctx_table[j] = NULL;
|
||||
- }
|
||||
|
||||
free(ctx_table);
|
||||
return ret;
|
||||
}
|
||||
|
||||
+static void wd_free_ctx_table_per_numa(struct wd_env_config_per_numa *config)
|
||||
+{
|
||||
+ int i;
|
||||
+
|
||||
+ if (!config->ctx_table)
|
||||
+ return;
|
||||
+
|
||||
+ for (i = 0; i < CTX_MODE_MAX; i++)
|
||||
+ free(config->ctx_table[i]);
|
||||
+
|
||||
+ free(config->ctx_table);
|
||||
+ config->ctx_table = NULL;
|
||||
+}
|
||||
+
|
||||
+static void wd_free_ctx_table(struct wd_env_config *config)
|
||||
+{
|
||||
+ struct wd_env_config_per_numa *config_numa;
|
||||
+ int i;
|
||||
+
|
||||
+ FOREACH_NUMA(i, config, config_numa)
|
||||
+ wd_free_ctx_table_per_numa(config_numa);
|
||||
+}
|
||||
+
|
||||
static int get_and_fill_ctx_num(struct wd_env_config_per_numa *config_numa,
|
||||
const char *p, int ctx_num)
|
||||
{
|
||||
@@ -655,15 +673,18 @@ static int wd_parse_section(struct wd_env_config *config, char *section)
|
||||
}
|
||||
|
||||
config_numa->op_type_num = config->op_type_num;
|
||||
- ret = wd_alloc_ctx_table(config_numa);
|
||||
+ ret = wd_alloc_ctx_table_per_numa(config_numa);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = get_and_fill_ctx_num(config_numa, section, ctx_num);
|
||||
- if (ret)
|
||||
+ if (ret) {
|
||||
WD_ERR("%s got wrong ctx type: %s!\n", __func__, section);
|
||||
+ wd_free_ctx_table_per_numa(config_numa);
|
||||
+ return ret;
|
||||
+ }
|
||||
|
||||
- return ret;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static int get_start_ctx_index(struct wd_env_config *config,
|
||||
@@ -722,9 +743,8 @@ static void wd_fill_ctx_table(struct wd_env_config *config)
|
||||
|
||||
static int parse_ctx_num(struct wd_env_config *config, const char *s)
|
||||
{
|
||||
- struct wd_env_config_per_numa *config_numa;
|
||||
char *left, *section, *start;
|
||||
- int i, ret;
|
||||
+ int ret;
|
||||
|
||||
start = strdup(s);
|
||||
if (!start)
|
||||
@@ -744,9 +764,7 @@ static int parse_ctx_num(struct wd_env_config *config, const char *s)
|
||||
return 0;
|
||||
|
||||
err_free_ctx_table:
|
||||
- FOREACH_NUMA(i, config, config_numa)
|
||||
- free(config_numa->ctx_table);
|
||||
-
|
||||
+ wd_free_ctx_table(config);
|
||||
free(start);
|
||||
return ret;
|
||||
}
|
||||
@@ -820,25 +838,6 @@ static int wd_parse_env(struct wd_env_config *config)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static void wd_free_env(struct wd_env_config *config)
|
||||
-{
|
||||
- struct wd_env_config_per_numa *config_numa;
|
||||
- int i, j;
|
||||
-
|
||||
- if (!config->config_per_numa)
|
||||
- return;
|
||||
-
|
||||
- FOREACH_NUMA(i, config, config_numa) {
|
||||
- if (!config_numa->ctx_table)
|
||||
- continue;
|
||||
-
|
||||
- for (j = 0; j < CTX_MODE_MAX; j++)
|
||||
- free(config_numa->ctx_table[j]);
|
||||
-
|
||||
- free(config_numa->ctx_table);
|
||||
- }
|
||||
-}
|
||||
-
|
||||
static int wd_parse_ctx_attr(struct wd_env_config *env_config,
|
||||
struct wd_ctx_attr *attr)
|
||||
{
|
||||
@@ -852,7 +851,7 @@ static int wd_parse_ctx_attr(struct wd_env_config *env_config,
|
||||
}
|
||||
|
||||
config_numa->op_type_num = env_config->op_type_num;
|
||||
- ret = wd_alloc_ctx_table(config_numa);
|
||||
+ ret = wd_alloc_ctx_table_per_numa(config_numa);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@@ -882,11 +881,11 @@ static int wd_init_env_config(struct wd_env_config *config,
|
||||
|
||||
static void wd_uninit_env_config(struct wd_env_config *config)
|
||||
{
|
||||
+ wd_free_ctx_table(config);
|
||||
+
|
||||
config->op_type_num = 0;
|
||||
config->table_size = 0;
|
||||
config->table = NULL;
|
||||
-
|
||||
- wd_free_env(config);
|
||||
}
|
||||
|
||||
static __u8 get_ctx_mode(struct wd_env_config_per_numa *config, int idx)
|
||||
--
|
||||
2.25.1
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,51 +0,0 @@
|
||||
From 4491fd2e4fb1c1d101e4c2d45998b484ce946443 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Wed, 19 Jan 2022 11:25:34 +0800
|
||||
Subject: [PATCH 51/53] uadk: fix for wd_env_config numa_num
|
||||
|
||||
numa number should be updated synchronously
|
||||
with config_per_numa, so set it to zero when
|
||||
free numa.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
include/wd_util.h | 2 +-
|
||||
wd_util.c | 2 ++
|
||||
2 files changed, 3 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/include/wd_util.h b/include/wd_util.h
|
||||
index c07ecce..2d3c1e4 100644
|
||||
--- a/include/wd_util.h
|
||||
+++ b/include/wd_util.h
|
||||
@@ -16,7 +16,7 @@ extern "C" {
|
||||
|
||||
#define FOREACH_NUMA(i, config, config_numa) \
|
||||
for (i = 0, config_numa = config->config_per_numa; \
|
||||
- config_numa && i < config->numa_num; config_numa++, i++)
|
||||
+ i < config->numa_num; config_numa++, i++)
|
||||
|
||||
struct wd_async_msg_pool {
|
||||
struct msg_pool *pools;
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 7fa688d..44c8909 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -356,6 +356,7 @@ static void wd_free_numa(struct wd_env_config *config)
|
||||
|
||||
free(config->config_per_numa);
|
||||
config->config_per_numa = NULL;
|
||||
+ config->numa_num = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -484,6 +485,7 @@ static int wd_alloc_numa(struct wd_env_config *config,
|
||||
return 0;
|
||||
|
||||
free_list:
|
||||
+ config->numa_num = 0;
|
||||
wd_free_list_accels(head);
|
||||
free_numa_dev_num:
|
||||
free(numa_dev_num);
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,588 +0,0 @@
|
||||
From 92364a0a3a38a02d64cca10d3153e94ee01c3969 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Tue, 25 Jan 2022 14:33:48 +0800
|
||||
Subject: [PATCH 52/53] hisi-sec: add some dfx information in comments
|
||||
|
||||
Add some dfx information in comments to improves locating
|
||||
efficiency.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 86 ++++++++++++++++++++++++++++++--------------------
|
||||
wd_aead.c | 39 ++++++++++++++---------
|
||||
wd_cipher.c | 21 +++++++-----
|
||||
wd_digest.c | 12 ++++---
|
||||
4 files changed, 97 insertions(+), 61 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index f5db7eb..14656c8 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -576,7 +576,7 @@ static int get_3des_c_key_len(struct wd_cipher_msg *msg, __u8 *c_key_len)
|
||||
} else if (msg->key_bytes == SEC_3DES_3KEY_SIZE) {
|
||||
*c_key_len = CKEY_LEN_3DES_3KEY;
|
||||
} else {
|
||||
- WD_ERR("invalid 3des key size!\n");
|
||||
+ WD_ERR("invalid 3des key size, size = %u\n", msg->key_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -602,7 +602,7 @@ static int get_aes_c_key_len(struct wd_cipher_msg *msg, __u8 *c_key_len)
|
||||
*c_key_len = CKEY_LEN_256BIT;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("invalid AES key size!\n");
|
||||
+ WD_ERR("invalid AES key size, size = %u\n", len);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -634,7 +634,7 @@ static int fill_cipher_bd2_alg(struct wd_cipher_msg *msg, struct hisi_sec_sqe *s
|
||||
sqe->type2.icvw_kmode = (__u16)c_key_len << SEC_CKEY_OFFSET;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("invalid cipher type!\n");
|
||||
+ WD_ERR("invalid cipher alg type, alg = %u\n", msg->alg);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -660,7 +660,7 @@ static int fill_cipher_bd2_mode(struct wd_cipher_msg *msg, struct hisi_sec_sqe *
|
||||
c_mode = C_MODE_XTS;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("invalid cipher mode type!\n");
|
||||
+ WD_ERR("invalid cipher mode type, mode = %u\n", msg->mode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
sqe->type2.icvw_kmode |= (__u16)(c_mode) << SEC_CMODE_OFFSET;
|
||||
@@ -719,7 +719,8 @@ static int cipher_len_check(struct wd_cipher_msg *msg)
|
||||
{
|
||||
if (msg->in_bytes > MAX_INPUT_DATA_LEN ||
|
||||
!msg->in_bytes) {
|
||||
- WD_ERR("input cipher length is error!\n");
|
||||
+ WD_ERR("input cipher length is error, size = %u\n",
|
||||
+ msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -730,7 +731,8 @@ static int cipher_len_check(struct wd_cipher_msg *msg)
|
||||
|
||||
if (msg->mode == WD_CIPHER_XTS) {
|
||||
if (msg->in_bytes < AES_BLOCK_SIZE) {
|
||||
- WD_ERR("input cipher length is too small!\n");
|
||||
+ WD_ERR("input cipher length is too small, size = %u\n",
|
||||
+ msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
return 0;
|
||||
@@ -738,13 +740,15 @@ static int cipher_len_check(struct wd_cipher_msg *msg)
|
||||
|
||||
if (msg->alg == WD_CIPHER_3DES || msg->alg == WD_CIPHER_DES) {
|
||||
if (msg->in_bytes & (DES3_BLOCK_SIZE - 1)) {
|
||||
- WD_ERR("input 3DES or DES cipher parameter is error!\n");
|
||||
+ WD_ERR("input 3DES or DES cipher parameter is error, size = %u\n",
|
||||
+ msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
return 0;
|
||||
} else if (msg->alg == WD_CIPHER_AES || msg->alg == WD_CIPHER_SM4) {
|
||||
if (msg->in_bytes & (AES_BLOCK_SIZE - 1)) {
|
||||
- WD_ERR("input AES or SM4 cipher parameter is error!\n");
|
||||
+ WD_ERR("input AES or SM4 cipher parameter is error, size = %u\n",
|
||||
+ msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
return 0;
|
||||
@@ -1006,7 +1010,7 @@ static int fill_cipher_bd3_alg(struct wd_cipher_msg *msg,
|
||||
sqe->c_icv_key |= (__u16)c_key_len << SEC_CKEY_OFFSET_V3;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("invalid cipher type!\n");
|
||||
+ WD_ERR("invalid cipher alg type, alg = %u\n", msg->alg);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1041,7 +1045,7 @@ static int fill_cipher_bd3_mode(struct wd_cipher_msg *msg,
|
||||
c_mode = C_MODE_CFB;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("invalid cipher mode type!\n");
|
||||
+ WD_ERR("invalid cipher mode type, mode = %u\n", msg->mode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
sqe->c_mode_alg |= (__u16)c_mode;
|
||||
@@ -1201,7 +1205,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
|
||||
struct hisi_sec_sqe *sqe)
|
||||
{
|
||||
if (msg->alg >= WD_DIGEST_TYPE_MAX) {
|
||||
- WD_ERR("invalid digest type!\n");
|
||||
+ WD_ERR("invalid digest alg type, alg = %u\n", msg->alg);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1211,7 +1215,8 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
|
||||
(__u32)g_digest_a_alg[msg->alg] << AUTH_ALG_OFFSET;
|
||||
else if (msg->mode == WD_DIGEST_HMAC) {
|
||||
if (msg->key_bytes & WORD_ALIGNMENT_MASK) {
|
||||
- WD_ERR("invalid digest key_bytes!\n");
|
||||
+ WD_ERR("invalid digest key_bytes, size = %u\n",
|
||||
+ msg->key_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
sqe->type2.mac_key_alg |= (__u32)(msg->key_bytes /
|
||||
@@ -1221,7 +1226,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
|
||||
sqe->type2.mac_key_alg |=
|
||||
(__u32)g_hmac_a_alg[msg->alg] << AUTH_ALG_OFFSET;
|
||||
} else {
|
||||
- WD_ERR("invalid digest mode!\n");
|
||||
+ WD_ERR("invalid digest mode, mode = %u\n", msg->mode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1298,19 +1303,22 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
|
||||
}
|
||||
|
||||
if (unlikely(msg->in_bytes > MAX_INPUT_DATA_LEN)) {
|
||||
- WD_ERR("digest input length is too long, size:%u!\n", msg->in_bytes);
|
||||
+ WD_ERR("digest input length is too long, size = %u\n",
|
||||
+ msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(msg->out_bytes & WORD_ALIGNMENT_MASK)) {
|
||||
- WD_ERR("digest out length is error, size:%u!\n", msg->out_bytes);
|
||||
+ WD_ERR("digest out length is error, size = %u\n",
|
||||
+ msg->out_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (msg->has_next) {
|
||||
ret = digest_long_bd_check(msg);
|
||||
if (ret) {
|
||||
- WD_ERR("input data isn't aligned, size:%u!\n", msg->in_bytes);
|
||||
+ WD_ERR("input data isn't aligned, size = %u\n",
|
||||
+ msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
}
|
||||
@@ -1421,7 +1429,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
|
||||
struct hisi_sec_sqe3 *sqe)
|
||||
{
|
||||
if (msg->alg >= WD_DIGEST_TYPE_MAX) {
|
||||
- WD_ERR("Invalid digest type!\n");
|
||||
+ WD_ERR("invalid digest type, alg = %u\n", msg->alg);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1432,7 +1440,8 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
|
||||
(__u32)g_digest_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3;
|
||||
} else if (msg->mode == WD_DIGEST_HMAC) {
|
||||
if (msg->key_bytes & WORD_ALIGNMENT_MASK) {
|
||||
- WD_ERR("Invalid digest key_bytes!\n");
|
||||
+ WD_ERR("invalid digest key_bytes, size = %u\n",
|
||||
+ msg->key_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
sqe->auth_mac_key |= (__u32)(msg->key_bytes /
|
||||
@@ -1441,7 +1450,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
|
||||
sqe->auth_mac_key |=
|
||||
(__u32)g_hmac_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3;
|
||||
} else {
|
||||
- WD_ERR("Invalid digest mode!\n");
|
||||
+ WD_ERR("invalid digest mode, mode = %u\n", msg->mode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1601,7 +1610,8 @@ static int aead_get_aes_key_len(struct wd_aead_msg *msg, __u8 *key_len)
|
||||
*key_len = CKEY_LEN_256BIT;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("failed to check AES key size!\n");
|
||||
+ WD_ERR("failed to check AES key size, size = %u\n",
|
||||
+ msg->ckey_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1622,7 +1632,7 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg,
|
||||
sqe->type2.icvw_kmode = (__u16)c_key_len << SEC_CKEY_OFFSET;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("failed to check aead calg type!\n");
|
||||
+ WD_ERR("failed to check aead calg type, calg = %u\n", msg->calg);
|
||||
ret = -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1632,13 +1642,15 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg,
|
||||
return ret;
|
||||
|
||||
if (unlikely(msg->auth_bytes & WORD_ALIGNMENT_MASK)) {
|
||||
- WD_ERR("failed to check aead auth_bytes!\n");
|
||||
+ WD_ERR("failed to check aead auth_bytes, size = %u\n",
|
||||
+ msg->auth_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
sqe->type2.mac_key_alg = msg->auth_bytes / WORD_BYTES;
|
||||
|
||||
if (unlikely(msg->akey_bytes & WORD_ALIGNMENT_MASK)) {
|
||||
- WD_ERR("failed to check aead auth key bytes!\n");
|
||||
+ WD_ERR("failed to check aead auth key bytes, size = %u\n",
|
||||
+ msg->akey_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
sqe->type2.mac_key_alg |= (__u32)(msg->akey_bytes /
|
||||
@@ -1655,7 +1667,7 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg,
|
||||
d_alg = A_ALG_HMAC_SHA512 << AUTH_ALG_OFFSET;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("failed to check aead dalg type!\n");
|
||||
+ WD_ERR("failed to check aead dalg type, dalg = %u\n", msg->dalg);
|
||||
ret = -WD_EINVAL;
|
||||
}
|
||||
sqe->type2.mac_key_alg |= d_alg;
|
||||
@@ -1685,7 +1697,8 @@ static int fill_aead_bd2_mode(struct wd_aead_msg *msg,
|
||||
sqe->type2.icvw_kmode |= msg->auth_bytes;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("failed to check aead cmode type!\n");
|
||||
+ WD_ERR("failed to check aead cmode type, cmode = %u\n",
|
||||
+ msg->cmode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
sqe->type2.icvw_kmode |= (__u16)(c_mode) << SEC_CMODE_OFFSET;
|
||||
@@ -1758,13 +1771,15 @@ static void fill_aead_bd2_addr(struct wd_aead_msg *msg,
|
||||
static int aead_len_check(struct wd_aead_msg *msg)
|
||||
{
|
||||
if (unlikely(msg->in_bytes + msg->assoc_bytes > MAX_INPUT_DATA_LEN)) {
|
||||
- WD_ERR("aead input data length is too long!\n");
|
||||
+ WD_ERR("aead input data length is too long, size = %u\n",
|
||||
+ msg->in_bytes + msg->assoc_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(msg->cmode == WD_CIPHER_CCM &&
|
||||
msg->assoc_bytes > MAX_CCM_AAD_LEN)) {
|
||||
- WD_ERR("failed to check ccm aad len, input is too long!\n");
|
||||
+ WD_ERR("failed to check ccm aad len, input is too long, size = %u\n",
|
||||
+ msg->assoc_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1793,7 +1808,7 @@ static int fill_aead_bd2(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe)
|
||||
sqe->type_auth_cipher |= AUTH_MAC_VERIFY <<
|
||||
SEC_AUTH_OFFSET;
|
||||
} else {
|
||||
- WD_ERR("failed to check aead op type!\n");
|
||||
+ WD_ERR("failed to check aead op type, op = %u\n", msg->op_type);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
sqe->sds_sa_type |= (__u8)(de | scene);
|
||||
@@ -1950,12 +1965,14 @@ static int aead_bd3_msg_check(struct wd_aead_msg *msg)
|
||||
}
|
||||
|
||||
if (unlikely(msg->auth_bytes & WORD_ALIGNMENT_MASK)) {
|
||||
- WD_ERR("failed to check aead auth_bytes!\n");
|
||||
+ WD_ERR("failed to check aead auth_bytes, size = %u\n",
|
||||
+ msg->auth_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(msg->akey_bytes & WORD_ALIGNMENT_MASK)) {
|
||||
- WD_ERR("failed to check aead auth key bytes!\n");
|
||||
+ WD_ERR("failed to check aead auth key bytes, size = %u\n",
|
||||
+ msg->akey_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1980,7 +1997,7 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg,
|
||||
sqe->c_icv_key |= (__u16)c_key_len << SEC_CKEY_OFFSET_V3;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("failed to check aead calg type!\n");
|
||||
+ WD_ERR("failed to check aead calg type, calg = %u\n", msg->calg);
|
||||
ret = -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -2009,7 +2026,7 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg,
|
||||
d_alg = A_ALG_HMAC_SHA512 << SEC_AUTH_ALG_OFFSET_V3;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("failed to check aead dalg type!\n");
|
||||
+ WD_ERR("failed to check aead dalg type, dalg = %u\n", msg->dalg);
|
||||
ret = -WD_EINVAL;
|
||||
}
|
||||
sqe->auth_mac_key |= d_alg;
|
||||
@@ -2037,7 +2054,8 @@ static int fill_aead_bd3_mode(struct wd_aead_msg *msg,
|
||||
sqe->c_icv_key |= msg->auth_bytes << SEC_MAC_OFFSET_V3;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("failed to check aead cmode type!\n");
|
||||
+ WD_ERR("failed to check aead cmode type, cmode = %u\n",
|
||||
+ msg->cmode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -2082,7 +2100,7 @@ static int fill_aead_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe)
|
||||
sqe->auth_mac_key = AUTH_MAC_VERIFY;
|
||||
sqe->huk_iv_seq = WD_DIGEST_THEN_CIPHER << SEC_SEQ_OFFSET_V3;
|
||||
} else {
|
||||
- WD_ERR("failed to check aead op type!\n");
|
||||
+ WD_ERR("failed to check aead op type, op = %u\n", msg->op_type);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
sqe->bd_param |= (__u16)(de | scene);
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index 32d06ec..82a1f97 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -110,7 +110,7 @@ static int cipher_key_len_check(enum wd_cipher_alg alg, __u16 length)
|
||||
ret = aes_key_len_check(length);
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("failed to check cipher key!\n");
|
||||
+ WD_ERR("failed to set the cipher alg, alg = %d\n", alg);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ int wd_aead_set_ckey(handle_t h_sess, const __u8 *key, __u16 key_len)
|
||||
int ret;
|
||||
|
||||
if (unlikely(!key || !sess)) {
|
||||
- WD_ERR("failed to check cipher key inpupt param!\n");
|
||||
+ WD_ERR("failed to check cipher key input param!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ int wd_aead_set_akey(handle_t h_sess, const __u8 *key, __u16 key_len)
|
||||
return 0;
|
||||
|
||||
err_key_len:
|
||||
- WD_ERR("failed to check authenticate key length!\n");
|
||||
+ WD_ERR("failed to check authenticate key length, size = %u\n", key_len);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -206,20 +206,23 @@ int wd_aead_set_authsize(handle_t h_sess, __u16 authsize)
|
||||
if (authsize < WD_AEAD_CCM_GCM_MIN ||
|
||||
authsize > WD_AEAD_CCM_GCM_MAX ||
|
||||
authsize % (WD_AEAD_CCM_GCM_MIN >> 1)) {
|
||||
- WD_ERR("failed to check aead CCM authsize!\n");
|
||||
+ WD_ERR("failed to check aead CCM authsize, size = %u\n",
|
||||
+ authsize);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
} else if (sess->cmode == WD_CIPHER_GCM) {
|
||||
if (authsize < WD_AEAD_CCM_GCM_MIN << 1 ||
|
||||
authsize > WD_AEAD_CCM_GCM_MAX) {
|
||||
- WD_ERR("failed to check aead GCM authsize!\n");
|
||||
+ WD_ERR("failed to check aead GCM authsize, size = %u\n",
|
||||
+ authsize);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
} else {
|
||||
if (sess->dalg >= WD_DIGEST_TYPE_MAX ||
|
||||
authsize & (WD_AEAD_CCM_GCM_MAX - 1) ||
|
||||
authsize > g_aead_mac_len[sess->dalg]) {
|
||||
- WD_ERR("failed to check aead mac authsize!\n");
|
||||
+ WD_ERR("failed to check aead mac authsize, size = %u\n",
|
||||
+ authsize);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
}
|
||||
@@ -313,20 +316,22 @@ static int aead_mac_param_check(struct wd_aead_sess *sess,
|
||||
switch (sess->cmode) {
|
||||
case WD_CIPHER_CBC:
|
||||
if (req->mac_bytes < g_aead_mac_len[sess->dalg]) {
|
||||
- WD_ERR("failed to check cbc-hmac mac buffer length!\n");
|
||||
+ WD_ERR("failed to check cbc-hmac mac buffer length, size = %u\n",
|
||||
+ req->mac_bytes);
|
||||
ret = -WD_EINVAL;
|
||||
}
|
||||
break;
|
||||
case WD_CIPHER_CCM:
|
||||
case WD_CIPHER_GCM:
|
||||
if (req->mac_bytes < WD_AEAD_CCM_GCM_MAX) {
|
||||
- WD_ERR("failed to check CCM or GCM mac buffer length!\n");
|
||||
+ WD_ERR("failed to check CCM or GCM mac buffer length, size = %u\n",
|
||||
+ req->mac_bytes);
|
||||
ret = -WD_EINVAL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ret = -WD_EINVAL;
|
||||
- WD_ERR("set the aead cmode is error!\n");
|
||||
+ WD_ERR("set the aead cmode is error, cmode = %d\n", sess->cmode);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -350,12 +355,14 @@ static int aead_param_check(struct wd_aead_sess *sess,
|
||||
|
||||
if (unlikely(sess->cmode == WD_CIPHER_CBC &&
|
||||
(req->in_bytes & (AES_BLOCK_SIZE - 1)))) {
|
||||
- WD_ERR("failed to check aead input data length!\n");
|
||||
+ WD_ERR("failed to check aead input data length, size = %u\n",
|
||||
+ req->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(req->iv_bytes != get_iv_block_size(sess->cmode))) {
|
||||
- WD_ERR("failed to check aead IV length, size:%u\n", req->iv_bytes);
|
||||
+ WD_ERR("failed to check aead IV length, size = %u\n",
|
||||
+ req->iv_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -367,13 +374,15 @@ static int aead_param_check(struct wd_aead_sess *sess,
|
||||
len = req->in_bytes + req->assoc_bytes;
|
||||
ret = wd_check_datalist(req->list_src, len);
|
||||
if (unlikely(ret)) {
|
||||
- WD_ERR("failed to check the src datalist!\n");
|
||||
+ WD_ERR("failed to check the src datalist, size = %u\n",
|
||||
+ len);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
ret = wd_check_datalist(req->list_dst, req->out_bytes);
|
||||
if (unlikely(ret)) {
|
||||
- WD_ERR("failed to check the dst datalist!\n");
|
||||
+ WD_ERR("failed to check the dst datalist, size = %u\n",
|
||||
+ req->out_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
}
|
||||
@@ -407,13 +416,13 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
|
||||
ret = wd_init_ctx_config(&wd_aead_setting.config, config);
|
||||
if (ret) {
|
||||
- WD_ERR("failed to set config, ret = %d!\n", ret);
|
||||
+ WD_ERR("failed to set config, ret = %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = wd_init_sched(&wd_aead_setting.sched, sched);
|
||||
if (ret < 0) {
|
||||
- WD_ERR("failed to set sched, ret = %d!\n", ret);
|
||||
+ WD_ERR("failed to set sched, ret = %d\n", ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index 5be3123..0b29fb5 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -126,7 +126,7 @@ static int cipher_key_len_check(struct wd_cipher_sess *sess, __u32 length)
|
||||
int ret = 0;
|
||||
|
||||
if (sess->mode == WD_CIPHER_XTS && length == AES_KEYSIZE_192) {
|
||||
- WD_ERR("unsupported XTS key length, length = %u.\n", length);
|
||||
+ WD_ERR("unsupported XTS key length, length = %u\n", length);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ static int cipher_key_len_check(struct wd_cipher_sess *sess, __u32 length)
|
||||
ret = -WD_EINVAL;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("cipher input alg err, alg is %d.\n", sess->alg);
|
||||
+ WD_ERR("cipher input alg err, alg = %d\n", sess->alg);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -358,14 +358,16 @@ static int cipher_iv_len_check(struct wd_cipher_req *req,
|
||||
case WD_CIPHER_AES:
|
||||
case WD_CIPHER_SM4:
|
||||
if (req->iv_bytes != AES_BLOCK_SIZE) {
|
||||
- WD_ERR("AES or SM4 input iv bytes is err!\n");
|
||||
+ WD_ERR("AES or SM4 input iv bytes is err, size = %u\n",
|
||||
+ req->iv_bytes);
|
||||
ret = -WD_EINVAL;
|
||||
}
|
||||
break;
|
||||
case WD_CIPHER_3DES:
|
||||
case WD_CIPHER_DES:
|
||||
if (req->iv_bytes != DES3_BLOCK_SIZE) {
|
||||
- WD_ERR("3DES or DES input iv bytes is err!\n");
|
||||
+ WD_ERR("3DES or DES input iv bytes is err, size = %u\n",
|
||||
+ req->iv_bytes);
|
||||
ret = -WD_EINVAL;
|
||||
}
|
||||
break;
|
||||
@@ -384,7 +386,7 @@ static int wd_cipher_check_params(handle_t h_sess,
|
||||
int ret = 0;
|
||||
|
||||
if (unlikely(!h_sess || !req)) {
|
||||
- WD_ERR("cipher input sess or req is NULL.\n");
|
||||
+ WD_ERR("cipher input sess or req is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -394,21 +396,24 @@ static int wd_cipher_check_params(handle_t h_sess,
|
||||
}
|
||||
|
||||
if (unlikely(req->out_buf_bytes < req->in_bytes)) {
|
||||
- WD_ERR("cipher set out_buf_bytes is error!\n");
|
||||
+ WD_ERR("cipher set out_buf_bytes is error, size = %u\n",
|
||||
+ req->out_buf_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (req->data_fmt == WD_SGL_BUF) {
|
||||
ret = wd_check_datalist(req->list_src, req->in_bytes);
|
||||
if (unlikely(ret)) {
|
||||
- WD_ERR("failed to check the src datalist!\n");
|
||||
+ WD_ERR("failed to check the src datalist, len = %u\n",
|
||||
+ req->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
/* cipher dst len is equal to src len */
|
||||
ret = wd_check_datalist(req->list_dst, req->in_bytes);
|
||||
if (unlikely(ret)) {
|
||||
- WD_ERR("failed to check the dst datalist!\n");
|
||||
+ WD_ERR("failed to check the dst datalist, len = %u\n",
|
||||
+ req->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
}
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index 525d6a9..d4e710d 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -98,7 +98,8 @@ int wd_digest_set_key(handle_t h_sess, const __u8 *key, __u32 key_len)
|
||||
if ((sess->alg <= WD_DIGEST_SHA224 && key_len >
|
||||
MAX_HMAC_KEY_SIZE >> 1) || key_len == 0 ||
|
||||
key_len > MAX_HMAC_KEY_SIZE) {
|
||||
- WD_ERR("failed to check digest key length!\n");
|
||||
+ WD_ERR("failed to check digest key length, size = %u\n",
|
||||
+ key_len);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -258,20 +259,23 @@ static int digest_param_check(struct wd_digest_sess *sess,
|
||||
}
|
||||
|
||||
if (unlikely(req->out_buf_bytes < req->out_bytes)) {
|
||||
- WD_ERR("failed to check digest out buffer length!\n");
|
||||
+ WD_ERR("failed to check digest out buffer length, size = %u\n",
|
||||
+ req->out_buf_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(sess->alg >= WD_DIGEST_TYPE_MAX || req->out_bytes == 0 ||
|
||||
req->out_bytes > g_digest_mac_len[sess->alg])) {
|
||||
- WD_ERR("failed to check digest type or mac length!\n");
|
||||
+ WD_ERR("failed to check digest type or mac length, alg = %d, out_bytes = %u\n",
|
||||
+ sess->alg, req->out_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (req->data_fmt == WD_SGL_BUF) {
|
||||
ret = wd_check_datalist(req->list_in, req->in_bytes);
|
||||
if (unlikely(ret)) {
|
||||
- WD_ERR("failed to check the src datalist!\n");
|
||||
+ WD_ERR("failed to check the src datalist, size = %u\n",
|
||||
+ req->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,119 +0,0 @@
|
||||
From 7d208baa2ea3b3adb161683e9e2446dd01ae14a0 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Thu, 27 Jan 2022 10:16:59 +0800
|
||||
Subject: [PATCH 53/53] hisi-sec: delete some dummy parameter checking
|
||||
|
||||
1. If an error is detected, the system exits rather than
|
||||
continues. here is fix it.
|
||||
2. Due to the auth length checking logic same as the api
|
||||
layer. So this code is reduntant and needs to be deleted.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 56 +++++++++++++++++---------------------------------
|
||||
1 file changed, 19 insertions(+), 37 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index 14656c8..61e0698 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -1618,6 +1618,17 @@ static int aead_get_aes_key_len(struct wd_aead_msg *msg, __u8 *key_len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static int aead_bd_msg_check(struct wd_aead_msg *msg)
|
||||
+{
|
||||
+ if (unlikely(msg->akey_bytes & WORD_ALIGNMENT_MASK)) {
|
||||
+ WD_ERR("failed to check aead auth key bytes, size = %u\n",
|
||||
+ msg->akey_bytes);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
static int fill_aead_bd2_alg(struct wd_aead_msg *msg,
|
||||
struct hisi_sec_sqe *sqe)
|
||||
{
|
||||
@@ -1633,26 +1644,19 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg,
|
||||
break;
|
||||
default:
|
||||
WD_ERR("failed to check aead calg type, calg = %u\n", msg->calg);
|
||||
- ret = -WD_EINVAL;
|
||||
+ return -WD_EINVAL;
|
||||
}
|
||||
|
||||
/* CCM/GCM this region is set to 0 */
|
||||
- if (msg->cmode == WD_CIPHER_CCM ||
|
||||
- msg->cmode == WD_CIPHER_GCM)
|
||||
+ if (msg->cmode == WD_CIPHER_CCM || msg->cmode == WD_CIPHER_GCM)
|
||||
return ret;
|
||||
|
||||
- if (unlikely(msg->auth_bytes & WORD_ALIGNMENT_MASK)) {
|
||||
- WD_ERR("failed to check aead auth_bytes, size = %u\n",
|
||||
- msg->auth_bytes);
|
||||
- return -WD_EINVAL;
|
||||
- }
|
||||
sqe->type2.mac_key_alg = msg->auth_bytes / WORD_BYTES;
|
||||
|
||||
- if (unlikely(msg->akey_bytes & WORD_ALIGNMENT_MASK)) {
|
||||
- WD_ERR("failed to check aead auth key bytes, size = %u\n",
|
||||
- msg->akey_bytes);
|
||||
- return -WD_EINVAL;
|
||||
- }
|
||||
+ ret = aead_bd_msg_check(msg);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+
|
||||
sqe->type2.mac_key_alg |= (__u32)(msg->akey_bytes /
|
||||
WORD_BYTES) << MAC_LEN_OFFSET;
|
||||
|
||||
@@ -1957,28 +1961,6 @@ static struct wd_aead_driver hisi_aead_driver = {
|
||||
|
||||
WD_AEAD_SET_DRIVER(hisi_aead_driver);
|
||||
|
||||
-static int aead_bd3_msg_check(struct wd_aead_msg *msg)
|
||||
-{
|
||||
- if (unlikely(!msg->in_bytes)) {
|
||||
- WD_ERR("failed to check aead in_bytes 0 length!\n");
|
||||
- return -WD_EINVAL;
|
||||
- }
|
||||
-
|
||||
- if (unlikely(msg->auth_bytes & WORD_ALIGNMENT_MASK)) {
|
||||
- WD_ERR("failed to check aead auth_bytes, size = %u\n",
|
||||
- msg->auth_bytes);
|
||||
- return -WD_EINVAL;
|
||||
- }
|
||||
-
|
||||
- if (unlikely(msg->akey_bytes & WORD_ALIGNMENT_MASK)) {
|
||||
- WD_ERR("failed to check aead auth key bytes, size = %u\n",
|
||||
- msg->akey_bytes);
|
||||
- return -WD_EINVAL;
|
||||
- }
|
||||
-
|
||||
- return 0;
|
||||
-}
|
||||
-
|
||||
static int fill_aead_bd3_alg(struct wd_aead_msg *msg,
|
||||
struct hisi_sec_sqe3 *sqe)
|
||||
{
|
||||
@@ -1998,14 +1980,14 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg,
|
||||
break;
|
||||
default:
|
||||
WD_ERR("failed to check aead calg type, calg = %u\n", msg->calg);
|
||||
- ret = -WD_EINVAL;
|
||||
+ return -WD_EINVAL;
|
||||
}
|
||||
|
||||
/* CCM/GCM this region is set to 0 */
|
||||
if (msg->cmode == WD_CIPHER_CCM || msg->cmode == WD_CIPHER_GCM)
|
||||
return ret;
|
||||
|
||||
- ret = aead_bd3_msg_check(msg);
|
||||
+ ret = aead_bd_msg_check(msg);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,45 +0,0 @@
|
||||
From bbdb8e4337270cbc1125f9e5fa3b004e98a543d1 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Thu, 10 Feb 2022 14:55:43 +0800
|
||||
Subject: [PATCH 54/64] hisi-qm-udrv/v1: deleted a dummy branch
|
||||
|
||||
Deleted an invalid branch in qm_set_queue_alg_info. the software
|
||||
won't go to that line of code.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
v1/drv/hisi_qm_udrv.c | 18 ++++--------------
|
||||
1 file changed, 4 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/v1/drv/hisi_qm_udrv.c b/v1/drv/hisi_qm_udrv.c
|
||||
index 63f346b..b457efd 100644
|
||||
--- a/v1/drv/hisi_qm_udrv.c
|
||||
+++ b/v1/drv/hisi_qm_udrv.c
|
||||
@@ -423,20 +423,10 @@ static int qm_set_queue_alg_info(struct wd_queue *q)
|
||||
} else if (!strcmp(alg, "xts(aes)") ||
|
||||
!strcmp(alg, "xts(sm4)")) {
|
||||
qinfo->atype = WCRYPTO_CIPHER;
|
||||
- if (strstr(q->dev_path, "zip")) {
|
||||
- info->sqe_size = QM_ZIP_BD_SIZE;
|
||||
- info->sqe_fill[WCRYPTO_CIPHER] = qm_fill_zip_cipher_sqe;
|
||||
- info->sqe_parse[WCRYPTO_CIPHER] = qm_parse_zip_cipher_sqe;
|
||||
- ret = WD_SUCCESS;
|
||||
- } else if (strstr(q->dev_path, "sec")) {
|
||||
- priv->direction = 0;
|
||||
- info->sqe_size = QM_SEC_BD_SIZE;
|
||||
- info->sqe_fill[WCRYPTO_CIPHER] = qm_fill_cipher_sqe;
|
||||
- info->sqe_parse[WCRYPTO_CIPHER] = qm_parse_cipher_sqe;
|
||||
- ret = WD_SUCCESS;
|
||||
- } else { /* To be extended */
|
||||
- WD_ERR("queue xts alg engine err!\n");
|
||||
- }
|
||||
+ info->sqe_size = QM_ZIP_BD_SIZE;
|
||||
+ info->sqe_fill[WCRYPTO_CIPHER] = qm_fill_zip_cipher_sqe;
|
||||
+ info->sqe_parse[WCRYPTO_CIPHER] = qm_parse_zip_cipher_sqe;
|
||||
+ ret = WD_SUCCESS;
|
||||
} else { /* To be extended */
|
||||
WD_ERR("queue alg err!\n");
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,51 +0,0 @@
|
||||
From 124472212b51781c8ab8ad26131d8442cd049380 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Thu, 10 Feb 2022 14:55:44 +0800
|
||||
Subject: [PATCH 55/64] hisi-sec/v1: update the SEC BD1 mode configuration
|
||||
|
||||
Update SEC BD1 XTS mode CI_GEN config from 3 to 0, because
|
||||
ZIP XTS LBA hardware accomplish is different from SEC XTS LBA.
|
||||
So we config SEC BD1 XTS ci_gen=0, which means cipher_ivin_addr
|
||||
mode.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
v1/drv/hisi_sec_udrv.c | 15 +++++++++++----
|
||||
1 file changed, 11 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c
|
||||
index 2d06bd7..7345baf 100644
|
||||
--- a/v1/drv/hisi_sec_udrv.c
|
||||
+++ b/v1/drv/hisi_sec_udrv.c
|
||||
@@ -298,10 +298,11 @@ static int fill_cipher_bd1_type(struct wcrypto_cipher_msg *msg,
|
||||
|
||||
fill_bd_addr_type(msg->data_fmt, sqe);
|
||||
|
||||
- if (msg->mode == WCRYPTO_CIPHER_XTS)
|
||||
- sqe->type1.ci_gen = CI_GEN_BY_LBA;
|
||||
- else
|
||||
- sqe->type1.ci_gen = CI_GEN_BY_ADDR;
|
||||
+ /*
|
||||
+ * BD1 cipher only provides ci_gen=0 for compatibility, so user
|
||||
+ * should prepare iv[gran_num] and iv_bytes is sum of all grans
|
||||
+ */
|
||||
+ sqe->type1.ci_gen = CI_GEN_BY_ADDR;
|
||||
|
||||
return WD_SUCCESS;
|
||||
}
|
||||
@@ -1453,6 +1454,12 @@ static void parse_cipher_bd1(struct wd_queue *q, struct hisi_sec_sqe *sqe,
|
||||
sqe->type1.c_key_addr_l);
|
||||
drv_iova_unmap(q, cipher_msg->key, (void *)(uintptr_t)dma_addr,
|
||||
cipher_msg->key_bytes);
|
||||
+ if (cipher_msg->iv) {
|
||||
+ dma_addr = DMA_ADDR(sqe->type1.c_ivin_addr_h,
|
||||
+ sqe->type1.c_ivin_addr_l);
|
||||
+ drv_iova_unmap(q, cipher_msg->iv, (void *)(uintptr_t)dma_addr,
|
||||
+ cipher_msg->iv_bytes);
|
||||
+ }
|
||||
}
|
||||
|
||||
static void cipher_ofb_data_handle(struct wcrypto_cipher_msg *msg)
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,116 +0,0 @@
|
||||
From a1d263fc8bc5aa87a9287b7d5a5fb717a1556bc5 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 15 Feb 2022 11:49:49 +0800
|
||||
Subject: [PATCH 56/64] uadk: optimize algorithm initialization
|
||||
|
||||
malloc and memset can be replaced by calloc.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_aead.c | 3 +--
|
||||
wd_dh.c | 4 +---
|
||||
wd_digest.c | 4 +---
|
||||
wd_ecc.c | 4 +---
|
||||
wd_rsa.c | 4 +---
|
||||
5 files changed, 5 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index 82a1f97..d8581db 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -441,12 +441,11 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
}
|
||||
|
||||
/* init ctx related resources in specific driver */
|
||||
- priv = malloc(wd_aead_setting.driver->drv_ctx_size);
|
||||
+ priv = calloc(1, wd_aead_setting.driver->drv_ctx_size);
|
||||
if (!priv) {
|
||||
ret = -WD_ENOMEM;
|
||||
goto out_priv;
|
||||
}
|
||||
- memset(priv, 0, wd_aead_setting.driver->drv_ctx_size);
|
||||
wd_aead_setting.priv = priv;
|
||||
|
||||
ret = wd_aead_setting.driver->init(&wd_aead_setting.config, priv);
|
||||
diff --git a/wd_dh.c b/wd_dh.c
|
||||
index 1784099..b361d5d 100644
|
||||
--- a/wd_dh.c
|
||||
+++ b/wd_dh.c
|
||||
@@ -127,14 +127,12 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
}
|
||||
|
||||
/* initialize ctx related resources in specific driver */
|
||||
- priv = malloc(wd_dh_setting.driver->drv_ctx_size);
|
||||
+ priv = calloc(1, wd_dh_setting.driver->drv_ctx_size);
|
||||
if (!priv) {
|
||||
- WD_ERR("failed to calloc drv ctx\n");
|
||||
ret = -WD_ENOMEM;
|
||||
goto out_priv;
|
||||
}
|
||||
|
||||
- memset(priv, 0, wd_dh_setting.driver->drv_ctx_size);
|
||||
wd_dh_setting.priv = priv;
|
||||
ret = wd_dh_setting.driver->init(&wd_dh_setting.config, priv,
|
||||
wd_dh_setting.driver->alg_name);
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index d4e710d..1c05851 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -203,13 +203,11 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
}
|
||||
|
||||
/* init ctx related resources in specific driver */
|
||||
- priv = malloc(wd_digest_setting.driver->drv_ctx_size);
|
||||
+ priv = calloc(1, wd_digest_setting.driver->drv_ctx_size);
|
||||
if (!priv) {
|
||||
- WD_ERR("failed to alloc digest driver ctx!\n");
|
||||
ret = -WD_ENOMEM;
|
||||
goto out_priv;
|
||||
}
|
||||
- memset(priv, 0, wd_digest_setting.driver->drv_ctx_size);
|
||||
wd_digest_setting.priv = priv;
|
||||
|
||||
ret = wd_digest_setting.driver->init(&wd_digest_setting.config, priv);
|
||||
diff --git a/wd_ecc.c b/wd_ecc.c
|
||||
index e324473..89566ea 100644
|
||||
--- a/wd_ecc.c
|
||||
+++ b/wd_ecc.c
|
||||
@@ -181,14 +181,12 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
}
|
||||
|
||||
/* initialize ctx related resources in specific driver */
|
||||
- priv = malloc(wd_ecc_setting.driver->drv_ctx_size);
|
||||
+ priv = calloc(1, wd_ecc_setting.driver->drv_ctx_size);
|
||||
if (!priv) {
|
||||
- WD_ERR("failed to calloc drv ctx\n");
|
||||
ret = -WD_ENOMEM;
|
||||
goto out_priv;
|
||||
}
|
||||
|
||||
- memset(priv, 0, wd_ecc_setting.driver->drv_ctx_size);
|
||||
wd_ecc_setting.priv = priv;
|
||||
ret = wd_ecc_setting.driver->init(&wd_ecc_setting.config, priv,
|
||||
wd_ecc_setting.driver->alg_name);
|
||||
diff --git a/wd_rsa.c b/wd_rsa.c
|
||||
index 1f911b4..2e61927 100644
|
||||
--- a/wd_rsa.c
|
||||
+++ b/wd_rsa.c
|
||||
@@ -167,14 +167,12 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
}
|
||||
|
||||
/* initialize ctx related resources in specific driver */
|
||||
- priv = malloc(wd_rsa_setting.driver->drv_ctx_size);
|
||||
+ priv = calloc(1, wd_rsa_setting.driver->drv_ctx_size);
|
||||
if (!priv) {
|
||||
- WD_ERR("failed to calloc drv ctx\n");
|
||||
ret = -WD_ENOMEM;
|
||||
goto out_priv;
|
||||
}
|
||||
|
||||
- memset(priv, 0, wd_rsa_setting.driver->drv_ctx_size);
|
||||
wd_rsa_setting.priv = priv;
|
||||
ret = wd_rsa_setting.driver->init(&wd_rsa_setting.config, priv,
|
||||
wd_rsa_setting.driver->alg_name);
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,135 +0,0 @@
|
||||
From b2bcc88b513328491a0f02700b926678e63c944b Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 15 Feb 2022 11:49:50 +0800
|
||||
Subject: [PATCH 57/64] uadk: fix send exception handling
|
||||
|
||||
when qm send message failed, uadk should return immediately
|
||||
instead of enable interrupt.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
drv/hisi_comp.c | 10 +++++++---
|
||||
drv/hisi_sec.c | 24 ++++++++++++++++++------
|
||||
2 files changed, 25 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
|
||||
index e0e913d..5ea5dc3 100644
|
||||
--- a/drv/hisi_comp.c
|
||||
+++ b/drv/hisi_comp.c
|
||||
@@ -945,12 +945,16 @@ static int hisi_zip_comp_send(handle_t ctx, struct wd_comp_msg *msg, void *priv)
|
||||
return ret;
|
||||
}
|
||||
ret = hisi_qm_send(h_qp, &sqe, 1, &count);
|
||||
- if (ret < 0 && ret != -WD_EBUSY)
|
||||
- WD_ERR("qm send is err(%d)!\n", ret);
|
||||
+ if (ret < 0) {
|
||||
+ if (ret != -WD_EBUSY)
|
||||
+ WD_ERR("qm send is err(%d)!\n", ret);
|
||||
+
|
||||
+ return ret;
|
||||
+ }
|
||||
|
||||
hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
|
||||
- return ret;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static int get_alg_type(__u32 type)
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index 61e0698..338823b 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -946,11 +946,13 @@ int hisi_sec_cipher_send(handle_t ctx, struct wd_cipher_msg *msg)
|
||||
|
||||
if (msg->data_fmt == WD_SGL_BUF)
|
||||
hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
|
||||
+
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
|
||||
- return ret;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
int hisi_sec_cipher_recv(handle_t ctx, struct wd_cipher_msg *recv_msg)
|
||||
@@ -1147,11 +1149,13 @@ int hisi_sec_cipher_send_v3(handle_t ctx, struct wd_cipher_msg *msg)
|
||||
|
||||
if (msg->data_fmt == WD_SGL_BUF)
|
||||
hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
|
||||
+
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
|
||||
- return ret;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static void parse_cipher_bd3(struct hisi_sec_sqe3 *sqe, struct wd_cipher_msg *recv_msg)
|
||||
@@ -1388,11 +1392,13 @@ int hisi_sec_digest_send(handle_t ctx, struct wd_digest_msg *msg)
|
||||
|
||||
if (msg->data_fmt == WD_SGL_BUF)
|
||||
hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
|
||||
+
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
|
||||
- return ret;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
int hisi_sec_digest_recv(handle_t ctx, struct wd_digest_msg *recv_msg)
|
||||
@@ -1544,11 +1550,13 @@ int hisi_sec_digest_send_v3(handle_t ctx, struct wd_digest_msg *msg)
|
||||
|
||||
if (msg->data_fmt == WD_SGL_BUF)
|
||||
hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
|
||||
+
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
|
||||
- return ret;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static void parse_digest_bd3(struct hisi_sec_sqe3 *sqe,
|
||||
@@ -1887,11 +1895,13 @@ int hisi_sec_aead_send(handle_t ctx, struct wd_aead_msg *msg)
|
||||
|
||||
if (msg->data_fmt == WD_SGL_BUF)
|
||||
hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
|
||||
+
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
|
||||
- return ret;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static void parse_aead_bd2(struct hisi_sec_sqe *sqe,
|
||||
@@ -2152,11 +2162,13 @@ int hisi_sec_aead_send_v3(handle_t ctx, struct wd_aead_msg *msg)
|
||||
|
||||
if (msg->data_fmt == WD_SGL_BUF)
|
||||
hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
|
||||
+
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
|
||||
- return ret;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static void parse_aead_bd3(struct hisi_sec_sqe3 *sqe,
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,165 +0,0 @@
|
||||
From c7d657b037cb9a37daaa3df79ac806e6ac1d4fa2 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 15 Feb 2022 11:49:51 +0800
|
||||
Subject: [PATCH 58/64] uadk: sec: fix hisi_sec_digest_send
|
||||
|
||||
When digest send a sgl format message, it will use
|
||||
hisi_sec_fill_sgl to get sgl memory from sgl memory pool,
|
||||
when send message exit abnormally, sgl should be put back.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
drv/hisi_sec.c | 58 +++++++++++++++++++++-----------------------------
|
||||
1 file changed, 24 insertions(+), 34 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index 338823b..7f5aae2 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -929,10 +929,8 @@ int hisi_sec_cipher_send(handle_t ctx, struct wd_cipher_msg *msg)
|
||||
if (msg->data_fmt == WD_SGL_BUF) {
|
||||
ret = hisi_sec_fill_sgl(h_qp, &msg->in, &msg->out, &sqe,
|
||||
msg->alg_type);
|
||||
- if (ret) {
|
||||
- WD_ERR("failed to get sgl!\n");
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
}
|
||||
|
||||
sqe.type2.clen_ivhlen |= (__u32)msg->in_bytes;
|
||||
@@ -1132,10 +1130,8 @@ int hisi_sec_cipher_send_v3(handle_t ctx, struct wd_cipher_msg *msg)
|
||||
if (msg->data_fmt == WD_SGL_BUF) {
|
||||
ret = hisi_sec_fill_sgl_v3(h_qp, &msg->in, &msg->out, &sqe,
|
||||
msg->alg_type);
|
||||
- if (ret) {
|
||||
- WD_ERR("failed to get sgl!\n");
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
}
|
||||
|
||||
sqe.c_len_ivin = (__u32)msg->in_bytes;
|
||||
@@ -1360,10 +1356,8 @@ int hisi_sec_digest_send(handle_t ctx, struct wd_digest_msg *msg)
|
||||
if (msg->data_fmt == WD_SGL_BUF) {
|
||||
ret = hisi_sec_fill_sgl(h_qp, &msg->in, &msg->out, &sqe,
|
||||
msg->alg_type);
|
||||
- if (ret) {
|
||||
- WD_ERR("failed to get sgl!\n");
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
}
|
||||
|
||||
sqe.sds_sa_type |= (__u8)(de | scene);
|
||||
@@ -1372,10 +1366,8 @@ int hisi_sec_digest_send(handle_t ctx, struct wd_digest_msg *msg)
|
||||
sqe.type2.mac_addr = (__u64)(uintptr_t)msg->out;
|
||||
|
||||
ret = fill_digest_bd2_alg(msg, &sqe);
|
||||
- if (ret) {
|
||||
- WD_ERR("failed to fill digest bd alg!\n");
|
||||
- return ret;
|
||||
- }
|
||||
+ if (ret)
|
||||
+ goto put_sgl;
|
||||
|
||||
qm_fill_digest_long_bd(msg, &sqe);
|
||||
|
||||
@@ -1390,15 +1382,18 @@ int hisi_sec_digest_send(handle_t ctx, struct wd_digest_msg *msg)
|
||||
if (ret != -WD_EBUSY)
|
||||
WD_ERR("digest send sqe is err(%d)!\n", ret);
|
||||
|
||||
- if (msg->data_fmt == WD_SGL_BUF)
|
||||
- hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
|
||||
-
|
||||
- return ret;
|
||||
+ goto put_sgl;
|
||||
}
|
||||
|
||||
hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
|
||||
return 0;
|
||||
+
|
||||
+put_sgl:
|
||||
+ if (msg->data_fmt == WD_SGL_BUF)
|
||||
+ hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
|
||||
+
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
int hisi_sec_digest_recv(handle_t ctx, struct wd_digest_msg *recv_msg)
|
||||
@@ -1517,10 +1512,8 @@ int hisi_sec_digest_send_v3(handle_t ctx, struct wd_digest_msg *msg)
|
||||
if (msg->data_fmt == WD_SGL_BUF) {
|
||||
ret = hisi_sec_fill_sgl_v3(h_qp, &msg->in, &msg->out, &sqe,
|
||||
msg->alg_type);
|
||||
- if (ret) {
|
||||
- WD_ERR("failed to get sgl!\n");
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
}
|
||||
|
||||
sqe.bd_param |= (__u16)(de | scene);
|
||||
@@ -1529,10 +1522,8 @@ int hisi_sec_digest_send_v3(handle_t ctx, struct wd_digest_msg *msg)
|
||||
sqe.mac_addr = (__u64)(uintptr_t)msg->out;
|
||||
|
||||
ret = fill_digest_bd3_alg(msg, &sqe);
|
||||
- if (ret) {
|
||||
- WD_ERR("failed to fill digest bd alg!\n");
|
||||
- return ret;
|
||||
- }
|
||||
+ if (ret)
|
||||
+ goto put_sgl;
|
||||
|
||||
qm_fill_digest_long_bd3(msg, &sqe);
|
||||
|
||||
@@ -1548,15 +1539,18 @@ int hisi_sec_digest_send_v3(handle_t ctx, struct wd_digest_msg *msg)
|
||||
if (ret != -WD_EBUSY)
|
||||
WD_ERR("digest send sqe is err(%d)!\n", ret);
|
||||
|
||||
- if (msg->data_fmt == WD_SGL_BUF)
|
||||
- hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
|
||||
-
|
||||
- return ret;
|
||||
+ goto put_sgl;
|
||||
}
|
||||
|
||||
hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
|
||||
return 0;
|
||||
+
|
||||
+put_sgl:
|
||||
+ if (msg->data_fmt == WD_SGL_BUF)
|
||||
+ hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
|
||||
+
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
static void parse_digest_bd3(struct hisi_sec_sqe3 *sqe,
|
||||
@@ -1873,10 +1867,8 @@ int hisi_sec_aead_send(handle_t ctx, struct wd_aead_msg *msg)
|
||||
|
||||
if (msg->data_fmt == WD_SGL_BUF) {
|
||||
ret = hisi_sec_fill_sgl(h_qp, &msg->in, &msg->out, &sqe, msg->alg_type);
|
||||
- if (ret) {
|
||||
- WD_ERR("failed to get sgl!\n");
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
}
|
||||
|
||||
fill_aead_bd2_addr(msg, &sqe);
|
||||
@@ -2141,10 +2133,8 @@ int hisi_sec_aead_send_v3(handle_t ctx, struct wd_aead_msg *msg)
|
||||
if (msg->data_fmt == WD_SGL_BUF) {
|
||||
ret = hisi_sec_fill_sgl_v3(h_qp, &msg->in, &msg->out, &sqe,
|
||||
msg->alg_type);
|
||||
- if (ret) {
|
||||
- WD_ERR("failed to get sgl!\n");
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
}
|
||||
|
||||
fill_aead_bd3_addr(msg, &sqe);
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,606 +0,0 @@
|
||||
From 42055f42381b51428be8138042f2a7b6b9964c10 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 15 Feb 2022 11:49:52 +0800
|
||||
Subject: [PATCH 59/64] uadk: sec: some clean code
|
||||
|
||||
The number of characters in a single line exceeds 80 and
|
||||
WD_ERR's line change is not aligned.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
drv/hisi_sec.c | 175 ++++++++++++++++++++++++++++---------------------
|
||||
1 file changed, 102 insertions(+), 73 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index 7f5aae2..264d850 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -547,18 +547,24 @@ static void update_iv_sgl(struct wd_cipher_msg *msg)
|
||||
case WD_CIPHER_CBC:
|
||||
if (msg->op_type == WD_CIPHER_ENCRYPTION &&
|
||||
msg->out_bytes >= msg->iv_bytes)
|
||||
- hisi_qm_sgl_copy(msg->iv, msg->out, msg->out_bytes -
|
||||
- msg->iv_bytes, msg->iv_bytes, COPY_SGL_TO_PBUFF);
|
||||
+ hisi_qm_sgl_copy(msg->iv, msg->out,
|
||||
+ msg->out_bytes - msg->iv_bytes,
|
||||
+ msg->iv_bytes, COPY_SGL_TO_PBUFF);
|
||||
+
|
||||
if (msg->op_type == WD_CIPHER_DECRYPTION &&
|
||||
msg->in_bytes >= msg->iv_bytes)
|
||||
- hisi_qm_sgl_copy(msg->iv, msg->in, msg->in_bytes -
|
||||
- msg->iv_bytes, msg->iv_bytes, COPY_SGL_TO_PBUFF);
|
||||
+ hisi_qm_sgl_copy(msg->iv, msg->in,
|
||||
+ msg->in_bytes - msg->iv_bytes,
|
||||
+ msg->iv_bytes, COPY_SGL_TO_PBUFF);
|
||||
+
|
||||
break;
|
||||
case WD_CIPHER_OFB:
|
||||
case WD_CIPHER_CFB:
|
||||
if (msg->out_bytes >= msg->iv_bytes)
|
||||
- hisi_qm_sgl_copy(msg->iv, msg->out, msg->out_bytes -
|
||||
- msg->iv_bytes, msg->iv_bytes, COPY_SGL_TO_PBUFF);
|
||||
+ hisi_qm_sgl_copy(msg->iv, msg->out,
|
||||
+ msg->out_bytes - msg->iv_bytes,
|
||||
+ msg->iv_bytes, COPY_SGL_TO_PBUFF);
|
||||
+
|
||||
break;
|
||||
case WD_CIPHER_CTR:
|
||||
ctr_iv_inc(msg->iv, msg->iv_bytes >>
|
||||
@@ -576,7 +582,8 @@ static int get_3des_c_key_len(struct wd_cipher_msg *msg, __u8 *c_key_len)
|
||||
} else if (msg->key_bytes == SEC_3DES_3KEY_SIZE) {
|
||||
*c_key_len = CKEY_LEN_3DES_3KEY;
|
||||
} else {
|
||||
- WD_ERR("invalid 3des key size, size = %u\n", msg->key_bytes);
|
||||
+ WD_ERR("failed to check 3des key size, size = %u\n",
|
||||
+ msg->key_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -602,14 +609,15 @@ static int get_aes_c_key_len(struct wd_cipher_msg *msg, __u8 *c_key_len)
|
||||
*c_key_len = CKEY_LEN_256BIT;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("invalid AES key size, size = %u\n", len);
|
||||
+ WD_ERR("failed to check AES key size, size = %u\n", len);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int fill_cipher_bd2_alg(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe)
|
||||
+static int fill_cipher_bd2_alg(struct wd_cipher_msg *msg,
|
||||
+ struct hisi_sec_sqe *sqe)
|
||||
{
|
||||
__u8 c_key_len = 0;
|
||||
int ret = 0;
|
||||
@@ -634,14 +642,15 @@ static int fill_cipher_bd2_alg(struct wd_cipher_msg *msg, struct hisi_sec_sqe *s
|
||||
sqe->type2.icvw_kmode = (__u16)c_key_len << SEC_CKEY_OFFSET;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("invalid cipher alg type, alg = %u\n", msg->alg);
|
||||
+ WD_ERR("failed to check cipher alg type, alg = %u\n", msg->alg);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
-static int fill_cipher_bd2_mode(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe)
|
||||
+static int fill_cipher_bd2_mode(struct wd_cipher_msg *msg,
|
||||
+ struct hisi_sec_sqe *sqe)
|
||||
{
|
||||
__u16 c_mode;
|
||||
|
||||
@@ -660,7 +669,8 @@ static int fill_cipher_bd2_mode(struct wd_cipher_msg *msg, struct hisi_sec_sqe *
|
||||
c_mode = C_MODE_XTS;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("invalid cipher mode type, mode = %u\n", msg->mode);
|
||||
+ WD_ERR("failed to check cipher mode type, mode = %u\n",
|
||||
+ msg->mode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
sqe->type2.icvw_kmode |= (__u16)(c_mode) << SEC_CMODE_OFFSET;
|
||||
@@ -668,7 +678,8 @@ static int fill_cipher_bd2_mode(struct wd_cipher_msg *msg, struct hisi_sec_sqe *
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static void fill_cipher_bd2_addr(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe)
|
||||
+static void fill_cipher_bd2_addr(struct wd_cipher_msg *msg,
|
||||
+ struct hisi_sec_sqe *sqe)
|
||||
{
|
||||
sqe->type2.data_src_addr = (__u64)(uintptr_t)msg->in;
|
||||
sqe->type2.data_dst_addr = (__u64)(uintptr_t)msg->out;
|
||||
@@ -688,7 +699,8 @@ static void fill_cipher_bd2_addr(struct wd_cipher_msg *msg, struct hisi_sec_sqe
|
||||
sqe->type2.mac_addr = (__u64)(uintptr_t)msg;
|
||||
}
|
||||
|
||||
-static void parse_cipher_bd2(struct hisi_sec_sqe *sqe, struct wd_cipher_msg *recv_msg)
|
||||
+static void parse_cipher_bd2(struct hisi_sec_sqe *sqe,
|
||||
+ struct wd_cipher_msg *recv_msg)
|
||||
{
|
||||
struct wd_cipher_msg *rmsg;
|
||||
__u16 done;
|
||||
@@ -696,7 +708,7 @@ static void parse_cipher_bd2(struct hisi_sec_sqe *sqe, struct wd_cipher_msg *rec
|
||||
done = sqe->type2.done_flag & SEC_DONE_MASK;
|
||||
if (done != SEC_HW_TASK_DONE || sqe->type2.error_type) {
|
||||
WD_ERR("SEC BD %s fail! done=0x%x, etype=0x%x\n", "cipher",
|
||||
- done, sqe->type2.error_type);
|
||||
+ done, sqe->type2.error_type);
|
||||
recv_msg->result = WD_IN_EPARA;
|
||||
} else {
|
||||
recv_msg->result = WD_SUCCESS;
|
||||
@@ -720,7 +732,7 @@ static int cipher_len_check(struct wd_cipher_msg *msg)
|
||||
if (msg->in_bytes > MAX_INPUT_DATA_LEN ||
|
||||
!msg->in_bytes) {
|
||||
WD_ERR("input cipher length is error, size = %u\n",
|
||||
- msg->in_bytes);
|
||||
+ msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -732,7 +744,7 @@ static int cipher_len_check(struct wd_cipher_msg *msg)
|
||||
if (msg->mode == WD_CIPHER_XTS) {
|
||||
if (msg->in_bytes < AES_BLOCK_SIZE) {
|
||||
WD_ERR("input cipher length is too small, size = %u\n",
|
||||
- msg->in_bytes);
|
||||
+ msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
return 0;
|
||||
@@ -740,15 +752,15 @@ static int cipher_len_check(struct wd_cipher_msg *msg)
|
||||
|
||||
if (msg->alg == WD_CIPHER_3DES || msg->alg == WD_CIPHER_DES) {
|
||||
if (msg->in_bytes & (DES3_BLOCK_SIZE - 1)) {
|
||||
- WD_ERR("input 3DES or DES cipher parameter is error, size = %u\n",
|
||||
- msg->in_bytes);
|
||||
+ WD_ERR("failed to check input bytes of 3DES or DES, size = %u\n",
|
||||
+ msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
return 0;
|
||||
} else if (msg->alg == WD_CIPHER_AES || msg->alg == WD_CIPHER_SM4) {
|
||||
if (msg->in_bytes & (AES_BLOCK_SIZE - 1)) {
|
||||
- WD_ERR("input AES or SM4 cipher parameter is error, size = %u\n",
|
||||
- msg->in_bytes);
|
||||
+ WD_ERR("failed to check input bytes of AES or SM4, size = %u\n",
|
||||
+ msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
return 0;
|
||||
@@ -802,7 +814,7 @@ static int hisi_sec_fill_sgl(handle_t h_qp, __u8 **in, __u8 **out,
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist*)(*in));
|
||||
+ hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist *)(*in));
|
||||
if (!hw_sgl_in) {
|
||||
WD_ERR("failed to get sgl in for hw_v2!\n");
|
||||
return -WD_EINVAL;
|
||||
@@ -811,9 +823,10 @@ static int hisi_sec_fill_sgl(handle_t h_qp, __u8 **in, __u8 **out,
|
||||
if (type == WD_DIGEST) {
|
||||
hw_sgl_out = *out;
|
||||
} else {
|
||||
- hw_sgl_out = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist*)(*out));
|
||||
+ hw_sgl_out = hisi_qm_get_hw_sgl(h_sgl_pool,
|
||||
+ (struct wd_datalist *)(*out));
|
||||
if (!hw_sgl_out) {
|
||||
- WD_ERR("failed to get hw sgl out!\n");
|
||||
+ WD_ERR("failed to get hw sgl out for hw_v2!\n");
|
||||
hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_in);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -841,7 +854,7 @@ static int hisi_sec_fill_sgl_v3(handle_t h_qp, __u8 **in, __u8 **out,
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist*)(*in));
|
||||
+ hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist *)(*in));
|
||||
if (!hw_sgl_in) {
|
||||
WD_ERR("failed to get sgl in for hw_v3!\n");
|
||||
return -WD_EINVAL;
|
||||
@@ -851,9 +864,10 @@ static int hisi_sec_fill_sgl_v3(handle_t h_qp, __u8 **in, __u8 **out,
|
||||
hw_sgl_out = *out;
|
||||
sqe->bd_param |= SEC_PBUFF_MODE_MASK_V3;
|
||||
} else {
|
||||
- hw_sgl_out = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist*)(*out));
|
||||
+ hw_sgl_out = hisi_qm_get_hw_sgl(h_sgl_pool,
|
||||
+ (struct wd_datalist *)(*out));
|
||||
if (!hw_sgl_out) {
|
||||
- WD_ERR("failed to get hw sgl out!\n");
|
||||
+ WD_ERR("failed to get hw sgl out for hw_v3!\n");
|
||||
hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_in);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -943,7 +957,8 @@ int hisi_sec_cipher_send(handle_t ctx, struct wd_cipher_msg *msg)
|
||||
WD_ERR("cipher send sqe is err(%d)!\n", ret);
|
||||
|
||||
if (msg->data_fmt == WD_SGL_BUF)
|
||||
- hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
|
||||
+ hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in,
|
||||
+ msg->out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -969,7 +984,7 @@ int hisi_sec_cipher_recv(handle_t ctx, struct wd_cipher_msg *recv_msg)
|
||||
|
||||
if (recv_msg->data_fmt == WD_SGL_BUF)
|
||||
hisi_sec_put_sgl(h_qp, recv_msg->alg_type, recv_msg->in,
|
||||
- recv_msg->out);
|
||||
+ recv_msg->out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1010,7 +1025,7 @@ static int fill_cipher_bd3_alg(struct wd_cipher_msg *msg,
|
||||
sqe->c_icv_key |= (__u16)c_key_len << SEC_CKEY_OFFSET_V3;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("invalid cipher alg type, alg = %u\n", msg->alg);
|
||||
+ WD_ERR("failed to check cipher alg type, alg = %u\n", msg->alg);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1045,7 +1060,8 @@ static int fill_cipher_bd3_mode(struct wd_cipher_msg *msg,
|
||||
c_mode = C_MODE_CFB;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("invalid cipher mode type, mode = %u\n", msg->mode);
|
||||
+ WD_ERR("failed to check cipher mode type, mode = %u\n",
|
||||
+ msg->mode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
sqe->c_mode_alg |= (__u16)c_mode;
|
||||
@@ -1144,7 +1160,8 @@ int hisi_sec_cipher_send_v3(handle_t ctx, struct wd_cipher_msg *msg)
|
||||
WD_ERR("cipher send sqe is err(%d)!\n", ret);
|
||||
|
||||
if (msg->data_fmt == WD_SGL_BUF)
|
||||
- hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
|
||||
+ hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in,
|
||||
+ msg->out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1154,7 +1171,8 @@ int hisi_sec_cipher_send_v3(handle_t ctx, struct wd_cipher_msg *msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static void parse_cipher_bd3(struct hisi_sec_sqe3 *sqe, struct wd_cipher_msg *recv_msg)
|
||||
+static void parse_cipher_bd3(struct hisi_sec_sqe3 *sqe,
|
||||
+ struct wd_cipher_msg *recv_msg)
|
||||
{
|
||||
struct wd_cipher_msg *rmsg;
|
||||
__u16 done;
|
||||
@@ -1162,7 +1180,7 @@ static void parse_cipher_bd3(struct hisi_sec_sqe3 *sqe, struct wd_cipher_msg *re
|
||||
done = sqe->done_flag & SEC_DONE_MASK;
|
||||
if (done != SEC_HW_TASK_DONE || sqe->error_type) {
|
||||
WD_ERR("SEC BD3 %s fail! done=0x%x, etype=0x%x\n", "cipher",
|
||||
- done, sqe->error_type);
|
||||
+ done, sqe->error_type);
|
||||
recv_msg->result = WD_IN_EPARA;
|
||||
} else {
|
||||
recv_msg->result = WD_SUCCESS;
|
||||
@@ -1205,7 +1223,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
|
||||
struct hisi_sec_sqe *sqe)
|
||||
{
|
||||
if (msg->alg >= WD_DIGEST_TYPE_MAX) {
|
||||
- WD_ERR("invalid digest alg type, alg = %u\n", msg->alg);
|
||||
+ WD_ERR("failed to check digest alg type, alg = %u\n", msg->alg);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1215,8 +1233,8 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
|
||||
(__u32)g_digest_a_alg[msg->alg] << AUTH_ALG_OFFSET;
|
||||
else if (msg->mode == WD_DIGEST_HMAC) {
|
||||
if (msg->key_bytes & WORD_ALIGNMENT_MASK) {
|
||||
- WD_ERR("invalid digest key_bytes, size = %u\n",
|
||||
- msg->key_bytes);
|
||||
+ WD_ERR("failed to check digest key_bytes, size = %u\n",
|
||||
+ msg->key_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
sqe->type2.mac_key_alg |= (__u32)(msg->key_bytes /
|
||||
@@ -1226,7 +1244,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
|
||||
sqe->type2.mac_key_alg |=
|
||||
(__u32)g_hmac_a_alg[msg->alg] << AUTH_ALG_OFFSET;
|
||||
} else {
|
||||
- WD_ERR("invalid digest mode, mode = %u\n", msg->mode);
|
||||
+ WD_ERR("failed to check digest mode, mode = %u\n", msg->mode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1238,7 +1256,7 @@ static void qm_fill_digest_long_bd(struct wd_digest_msg *msg,
|
||||
{
|
||||
__u64 total_bits;
|
||||
|
||||
- if (msg->has_next && (msg->iv_bytes == 0)) {
|
||||
+ if (msg->has_next && !msg->iv_bytes) {
|
||||
/* LONG BD FIRST */
|
||||
sqe->ai_apd_cs = AI_GEN_INNER;
|
||||
sqe->ai_apd_cs |= AUTHPAD_NOPAD << AUTHPAD_OFFSET;
|
||||
@@ -1257,14 +1275,15 @@ static void qm_fill_digest_long_bd(struct wd_digest_msg *msg,
|
||||
}
|
||||
}
|
||||
|
||||
-static void parse_digest_bd2(struct hisi_sec_sqe *sqe, struct wd_digest_msg *recv_msg)
|
||||
+static void parse_digest_bd2(struct hisi_sec_sqe *sqe,
|
||||
+ struct wd_digest_msg *recv_msg)
|
||||
{
|
||||
__u16 done;
|
||||
|
||||
done = sqe->type2.done_flag & SEC_DONE_MASK;
|
||||
if (done != SEC_HW_TASK_DONE || sqe->type2.error_type) {
|
||||
WD_ERR("SEC BD %s fail! done=0x%x, etype=0x%x\n", "digest",
|
||||
- done, sqe->type2.error_type);
|
||||
+ done, sqe->type2.error_type);
|
||||
recv_msg->result = WD_IN_EPARA;
|
||||
} else {
|
||||
recv_msg->result = WD_SUCCESS;
|
||||
@@ -1284,9 +1303,12 @@ static void parse_digest_bd2(struct hisi_sec_sqe *sqe, struct wd_digest_msg *rec
|
||||
|
||||
static int digest_long_bd_check(struct wd_digest_msg *msg)
|
||||
{
|
||||
- if (msg->alg >= WD_DIGEST_SHA512 && msg->in_bytes & (SHA512_ALIGN_SZ - 1))
|
||||
- return -WD_EINVAL;
|
||||
- else if (msg->in_bytes & (SHA1_ALIGN_SZ - 1))
|
||||
+ __u32 alg_align_sz;
|
||||
+
|
||||
+ alg_align_sz = msg->alg >= WD_DIGEST_SHA512 ?
|
||||
+ SHA512_ALIGN_SZ - 1 : SHA1_ALIGN_SZ - 1;
|
||||
+
|
||||
+ if (msg->in_bytes & alg_align_sz)
|
||||
return -WD_EINVAL;
|
||||
|
||||
return 0;
|
||||
@@ -1297,20 +1319,20 @@ 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 == 0))) {
|
||||
+ 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;
|
||||
}
|
||||
|
||||
if (unlikely(msg->in_bytes > MAX_INPUT_DATA_LEN)) {
|
||||
WD_ERR("digest input length is too long, size = %u\n",
|
||||
- msg->in_bytes);
|
||||
+ msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(msg->out_bytes & WORD_ALIGNMENT_MASK)) {
|
||||
WD_ERR("digest out length is error, size = %u\n",
|
||||
- msg->out_bytes);
|
||||
+ msg->out_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1318,7 +1340,7 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
|
||||
ret = digest_long_bd_check(msg);
|
||||
if (ret) {
|
||||
WD_ERR("input data isn't aligned, size = %u\n",
|
||||
- msg->in_bytes);
|
||||
+ msg->in_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
}
|
||||
@@ -1430,7 +1452,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
|
||||
struct hisi_sec_sqe3 *sqe)
|
||||
{
|
||||
if (msg->alg >= WD_DIGEST_TYPE_MAX) {
|
||||
- WD_ERR("invalid digest type, alg = %u\n", msg->alg);
|
||||
+ WD_ERR("failed to check digest type, alg = %u\n", msg->alg);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1441,8 +1463,8 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
|
||||
(__u32)g_digest_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3;
|
||||
} else if (msg->mode == WD_DIGEST_HMAC) {
|
||||
if (msg->key_bytes & WORD_ALIGNMENT_MASK) {
|
||||
- WD_ERR("invalid digest key_bytes, size = %u\n",
|
||||
- msg->key_bytes);
|
||||
+ WD_ERR("failed to check digest key bytes, size = %u\n",
|
||||
+ msg->key_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
sqe->auth_mac_key |= (__u32)(msg->key_bytes /
|
||||
@@ -1451,7 +1473,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
|
||||
sqe->auth_mac_key |=
|
||||
(__u32)g_hmac_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3;
|
||||
} else {
|
||||
- WD_ERR("invalid digest mode, mode = %u\n", msg->mode);
|
||||
+ WD_ERR("failed to check digest mode, mode = %u\n", msg->mode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1463,7 +1485,7 @@ static void qm_fill_digest_long_bd3(struct wd_digest_msg *msg,
|
||||
{
|
||||
__u64 total_bits;
|
||||
|
||||
- if (msg->has_next && (msg->iv_bytes == 0)) {
|
||||
+ if (msg->has_next && !msg->iv_bytes) {
|
||||
/* LONG BD FIRST */
|
||||
sqe->auth_mac_key |= AI_GEN_INNER << SEC_AI_GEN_OFFSET_V3;
|
||||
sqe->stream_scene.stream_auth_pad = AUTHPAD_NOPAD;
|
||||
@@ -1561,7 +1583,7 @@ static void parse_digest_bd3(struct hisi_sec_sqe3 *sqe,
|
||||
done = sqe->done_flag & SEC_DONE_MASK;
|
||||
if (done != SEC_HW_TASK_DONE || sqe->error_type) {
|
||||
WD_ERR("SEC BD3 %s fail! done=0x%x, etype=0x%x\n", "digest",
|
||||
- done, sqe->error_type);
|
||||
+ done, sqe->error_type);
|
||||
recv_msg->result = WD_IN_EPARA;
|
||||
} else {
|
||||
recv_msg->result = WD_SUCCESS;
|
||||
@@ -1613,7 +1635,7 @@ static int aead_get_aes_key_len(struct wd_aead_msg *msg, __u8 *key_len)
|
||||
break;
|
||||
default:
|
||||
WD_ERR("failed to check AES key size, size = %u\n",
|
||||
- msg->ckey_bytes);
|
||||
+ msg->ckey_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1624,7 +1646,7 @@ static int aead_bd_msg_check(struct wd_aead_msg *msg)
|
||||
{
|
||||
if (unlikely(msg->akey_bytes & WORD_ALIGNMENT_MASK)) {
|
||||
WD_ERR("failed to check aead auth key bytes, size = %u\n",
|
||||
- msg->akey_bytes);
|
||||
+ msg->akey_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1645,7 +1667,8 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg,
|
||||
sqe->type2.icvw_kmode = (__u16)c_key_len << SEC_CKEY_OFFSET;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("failed to check aead calg type, calg = %u\n", msg->calg);
|
||||
+ WD_ERR("failed to check aead calg type, calg = %u\n",
|
||||
+ msg->calg);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1673,7 +1696,8 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg,
|
||||
d_alg = A_ALG_HMAC_SHA512 << AUTH_ALG_OFFSET;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("failed to check aead dalg type, dalg = %u\n", msg->dalg);
|
||||
+ WD_ERR("failed to check aead dalg type, dalg = %u\n",
|
||||
+ msg->dalg);
|
||||
ret = -WD_EINVAL;
|
||||
}
|
||||
sqe->type2.mac_key_alg |= d_alg;
|
||||
@@ -1704,7 +1728,7 @@ static int fill_aead_bd2_mode(struct wd_aead_msg *msg,
|
||||
break;
|
||||
default:
|
||||
WD_ERR("failed to check aead cmode type, cmode = %u\n",
|
||||
- msg->cmode);
|
||||
+ msg->cmode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
sqe->type2.icvw_kmode |= (__u16)(c_mode) << SEC_CMODE_OFFSET;
|
||||
@@ -1778,14 +1802,14 @@ static int aead_len_check(struct wd_aead_msg *msg)
|
||||
{
|
||||
if (unlikely(msg->in_bytes + msg->assoc_bytes > MAX_INPUT_DATA_LEN)) {
|
||||
WD_ERR("aead input data length is too long, size = %u\n",
|
||||
- msg->in_bytes + msg->assoc_bytes);
|
||||
+ msg->in_bytes + msg->assoc_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(msg->cmode == WD_CIPHER_CCM &&
|
||||
msg->assoc_bytes > MAX_CCM_AAD_LEN)) {
|
||||
- WD_ERR("failed to check ccm aad len, input is too long, size = %u\n",
|
||||
- msg->assoc_bytes);
|
||||
+ WD_ERR("aead ccm aad length is too long, size = %u\n",
|
||||
+ msg->assoc_bytes);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1851,7 +1875,7 @@ int hisi_sec_aead_send(handle_t ctx, struct wd_aead_msg *msg)
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (unlikely(msg->cmode != WD_CIPHER_CBC && msg->in_bytes == 0)) {
|
||||
+ if (unlikely(msg->cmode != WD_CIPHER_CBC && !msg->in_bytes)) {
|
||||
WD_ERR("ccm or gcm not supports 0 packet size at hw_v2!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -1866,7 +1890,8 @@ int hisi_sec_aead_send(handle_t ctx, struct wd_aead_msg *msg)
|
||||
return ret;
|
||||
|
||||
if (msg->data_fmt == WD_SGL_BUF) {
|
||||
- ret = hisi_sec_fill_sgl(h_qp, &msg->in, &msg->out, &sqe, msg->alg_type);
|
||||
+ ret = hisi_sec_fill_sgl(h_qp, &msg->in, &msg->out,
|
||||
+ &sqe, msg->alg_type);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
@@ -1886,7 +1911,8 @@ int hisi_sec_aead_send(handle_t ctx, struct wd_aead_msg *msg)
|
||||
WD_ERR("aead send sqe is err(%d)!\n", ret);
|
||||
|
||||
if (msg->data_fmt == WD_SGL_BUF)
|
||||
- hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
|
||||
+ hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in,
|
||||
+ msg->out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1906,7 +1932,7 @@ static void parse_aead_bd2(struct hisi_sec_sqe *sqe,
|
||||
if (done != SEC_HW_TASK_DONE || sqe->type2.error_type ||
|
||||
icv == SEC_HW_ICV_ERR) {
|
||||
WD_ERR("SEC BD aead fail! done=0x%x, etype=0x%x, icv=0x%x\n",
|
||||
- done, sqe->type2.error_type, icv);
|
||||
+ done, sqe->type2.error_type, icv);
|
||||
recv_msg->result = WD_IN_EPARA;
|
||||
} else {
|
||||
recv_msg->result = WD_SUCCESS;
|
||||
@@ -1921,7 +1947,7 @@ static void parse_aead_bd2(struct hisi_sec_sqe *sqe,
|
||||
recv_msg->mac = (__u8 *)(uintptr_t)sqe->type2.mac_addr;
|
||||
recv_msg->auth_bytes = (sqe->type2.mac_key_alg &
|
||||
SEC_MAC_LEN_MASK) * WORD_BYTES;
|
||||
- if (recv_msg->auth_bytes == 0)
|
||||
+ if (!recv_msg->auth_bytes)
|
||||
recv_msg->auth_bytes = sqe->type2.icvw_kmode &
|
||||
SEC_AUTH_LEN_MASK;
|
||||
recv_msg->out_bytes = sqe->type2.clen_ivhlen +
|
||||
@@ -1981,7 +2007,8 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg,
|
||||
sqe->c_icv_key |= (__u16)c_key_len << SEC_CKEY_OFFSET_V3;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("failed to check aead calg type, calg = %u\n", msg->calg);
|
||||
+ WD_ERR("failed to check aead calg type, calg = %u\n",
|
||||
+ msg->calg);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -2010,7 +2037,8 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg,
|
||||
d_alg = A_ALG_HMAC_SHA512 << SEC_AUTH_ALG_OFFSET_V3;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("failed to check aead dalg type, dalg = %u\n", msg->dalg);
|
||||
+ WD_ERR("failed to check aead dalg type, dalg = %u\n",
|
||||
+ msg->dalg);
|
||||
ret = -WD_EINVAL;
|
||||
}
|
||||
sqe->auth_mac_key |= d_alg;
|
||||
@@ -2039,7 +2067,7 @@ static int fill_aead_bd3_mode(struct wd_aead_msg *msg,
|
||||
break;
|
||||
default:
|
||||
WD_ERR("failed to check aead cmode type, cmode = %u\n",
|
||||
- msg->cmode);
|
||||
+ msg->cmode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -2151,7 +2179,8 @@ int hisi_sec_aead_send_v3(handle_t ctx, struct wd_aead_msg *msg)
|
||||
WD_ERR("aead send sqe is err(%d)!\n", ret);
|
||||
|
||||
if (msg->data_fmt == WD_SGL_BUF)
|
||||
- hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out);
|
||||
+ hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in,
|
||||
+ msg->out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -2171,7 +2200,7 @@ static void parse_aead_bd3(struct hisi_sec_sqe3 *sqe,
|
||||
if (done != SEC_HW_TASK_DONE || sqe->error_type ||
|
||||
icv == SEC_HW_ICV_ERR) {
|
||||
WD_ERR("SEC BD3 aead fail! done=0x%x, etype=0x%x, icv=0x%x\n",
|
||||
- done, sqe->error_type, icv);
|
||||
+ done, sqe->error_type, icv);
|
||||
recv_msg->result = WD_IN_EPARA;
|
||||
} else {
|
||||
recv_msg->result = WD_SUCCESS;
|
||||
@@ -2186,7 +2215,7 @@ static void parse_aead_bd3(struct hisi_sec_sqe3 *sqe,
|
||||
recv_msg->mac = (__u8 *)(uintptr_t)sqe->mac_addr;
|
||||
recv_msg->auth_bytes = ((sqe->auth_mac_key >> SEC_MAC_OFFSET_V3) &
|
||||
SEC_MAC_LEN_MASK) * WORD_BYTES;
|
||||
- if (recv_msg->auth_bytes == 0)
|
||||
+ if (!recv_msg->auth_bytes)
|
||||
recv_msg->auth_bytes = (sqe->c_icv_key >> SEC_MAC_OFFSET_V3) &
|
||||
SEC_MAC_LEN_MASK;
|
||||
recv_msg->out_bytes = sqe->c_len_ivin +
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,59 +0,0 @@
|
||||
From b9b1cb826756b2a27ed99745a5fb9be338abd09f Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 15 Feb 2022 11:49:53 +0800
|
||||
Subject: [PATCH 60/64] uadk: optimize wd_ctx_qfr_mmap
|
||||
|
||||
wd_ctx_qfr_mmap may return NULL when user input wrong parameters
|
||||
or mmap failed, so detail information should be printed.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd.c | 12 ++++++++----
|
||||
1 file changed, 8 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/wd.c b/wd.c
|
||||
index 6bbf677..d1652dd 100644
|
||||
--- a/wd.c
|
||||
+++ b/wd.c
|
||||
@@ -386,7 +386,7 @@ int wd_ctx_start(handle_t h_ctx)
|
||||
|
||||
ret = wd_ctx_set_io_cmd(h_ctx, UACCE_CMD_START, NULL);
|
||||
if (ret)
|
||||
- WD_ERR("Fail to start on %s (%d), ret = %d!\n",
|
||||
+ WD_ERR("failed to start on %s (%d), ret = %d!\n",
|
||||
ctx->dev_path, -errno, ret);
|
||||
|
||||
return ret;
|
||||
@@ -402,7 +402,7 @@ int wd_release_ctx_force(handle_t h_ctx)
|
||||
|
||||
ret = wd_ctx_set_io_cmd(h_ctx, UACCE_CMD_PUT_Q, NULL);
|
||||
if (ret)
|
||||
- WD_ERR("Fail to stop on %s (%d), ret = %d!\n",
|
||||
+ WD_ERR("failed to stop on %s (%d), ret = %d!\n",
|
||||
ctx->dev_path, -errno, ret);
|
||||
|
||||
return ret;
|
||||
@@ -415,14 +415,18 @@ void *wd_ctx_mmap_qfr(handle_t h_ctx, enum uacce_qfrt qfrt)
|
||||
size_t size;
|
||||
void *addr;
|
||||
|
||||
- if (!ctx || qfrt >= UACCE_QFRT_MAX || !ctx->qfrs_offs[qfrt])
|
||||
+ if (!ctx || qfrt >= UACCE_QFRT_MAX || !ctx->qfrs_offs[qfrt]) {
|
||||
+ WD_ERR("failed to check input ctx or qfrt!\n");
|
||||
return NULL;
|
||||
+ }
|
||||
|
||||
size = ctx->qfrs_offs[qfrt];
|
||||
|
||||
addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, ctx->fd, off);
|
||||
- if (addr == MAP_FAILED)
|
||||
+ if (addr == MAP_FAILED) {
|
||||
+ WD_ERR("failed to mmap, qfrt = %d, err = %d!\n", qfrt, -errno);
|
||||
return NULL;
|
||||
+ }
|
||||
|
||||
ctx->qfrs_base[qfrt] = addr;
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,65 +0,0 @@
|
||||
From 1da22fb07ffeabe82310b8619563fd5971214e18 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 15 Feb 2022 11:49:54 +0800
|
||||
Subject: [PATCH 61/64] uadk: optimize wd_sched_rr_instance
|
||||
|
||||
Schedule ctx numa number and schedule type number should
|
||||
also be printed, the error information is more usefull
|
||||
if when it has a comparison.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_sched.c | 24 +++++++++++++++++-------
|
||||
1 file changed, 17 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/wd_sched.c b/wd_sched.c
|
||||
index aeaf11b..ef90233 100644
|
||||
--- a/wd_sched.c
|
||||
+++ b/wd_sched.c
|
||||
@@ -129,7 +129,7 @@ static bool sched_key_valid(struct wd_sched_ctx *ctx,
|
||||
{
|
||||
if (key->numa_id >= ctx->numa_num || key->mode >= SCHED_MODE_BUTT ||
|
||||
key->type >= ctx->type_num) {
|
||||
- WD_ERR("ERROR: %s key error - numa:%d, mode:%u, type%u!\n",
|
||||
+ WD_ERR("ERROR: %s key error - numa: %d, mode: %u, type: %u!\n",
|
||||
__FUNCTION__, key->numa_id, key->mode, key->type);
|
||||
return false;
|
||||
}
|
||||
@@ -372,18 +372,28 @@ int wd_sched_rr_instance(const struct wd_sched *sched,
|
||||
mode = param->mode;
|
||||
sched_ctx = (struct wd_sched_ctx *)sched->h_sched_ctx;
|
||||
|
||||
- if ((numa_id >= sched_ctx->numa_num) || (numa_id < 0) ||
|
||||
- (mode >= SCHED_MODE_BUTT) ||
|
||||
- (type >= sched_ctx->type_num)) {
|
||||
- WD_ERR("ERROR: %s para err: numa_id=%d, mode=%u, type=%u!\n",
|
||||
- __FUNCTION__, numa_id, mode, type);
|
||||
+ if (numa_id >= sched_ctx->numa_num || numa_id < 0) {
|
||||
+ WD_ERR("ERROR: %s para err: numa_id = %d, numa_num = %u\n",
|
||||
+ __FUNCTION__, numa_id, sched_ctx->numa_num);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ if (type >= sched_ctx->type_num) {
|
||||
+ WD_ERR("ERROR: %s para err: type = %u, type_num = %u\n",
|
||||
+ __FUNCTION__, type, sched_ctx->type_num);
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ if (mode >= SCHED_MODE_BUTT) {
|
||||
+ WD_ERR("ERROR: %s para err: mode = %u, mode_num = %d!\n",
|
||||
+ __FUNCTION__, mode, SCHED_MODE_BUTT);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
sched_info = sched_ctx->sched_info;
|
||||
|
||||
if (!sched_info[numa_id].ctx_region[mode]) {
|
||||
- WD_ERR("ERROR: %s para err: ctx_region:numa_id=%d, mode=%u is NULL!\n",
|
||||
+ WD_ERR("ERROR: %s ctx_region of numa_id = %d, mode = %u is NULL!\n",
|
||||
__FUNCTION__, numa_id, mode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,127 +0,0 @@
|
||||
From b670d346baac3be4b3b55a481c196abbdaf36bd3 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 15 Feb 2022 11:49:55 +0800
|
||||
Subject: [PATCH 62/64] uadk: optimize wd_get_accel_list
|
||||
|
||||
wd_get_accel_list should skip nosva device,
|
||||
so add a step to check sva flags, get_dev_info
|
||||
should not print error info when device is nosva.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd.c | 39 +++++++++++++++++++++------------------
|
||||
1 file changed, 21 insertions(+), 18 deletions(-)
|
||||
|
||||
diff --git a/wd.c b/wd.c
|
||||
index d1652dd..afcf134 100644
|
||||
--- a/wd.c
|
||||
+++ b/wd.c
|
||||
@@ -44,16 +44,18 @@ static int get_raw_attr(const char *dev_root, const char *attr, char *buf,
|
||||
ssize_t size;
|
||||
int fd;
|
||||
|
||||
- if (!dev_root || !attr || !buf || !sz)
|
||||
- return -WD_EINVAL;
|
||||
-
|
||||
size = snprintf(attr_file, PATH_STR_SIZE, "%s/%s", dev_root, attr);
|
||||
- if (size < 0)
|
||||
+ if (size < 0) {
|
||||
+ WD_ERR("failed to snprintf, dev_root: %s, attr: %s!\n",
|
||||
+ dev_root, attr);
|
||||
return -WD_EINVAL;
|
||||
+ }
|
||||
|
||||
ptrRet = realpath(attr_file, attr_path);
|
||||
- if (ptrRet == NULL)
|
||||
+ if (ptrRet == NULL) {
|
||||
+ WD_ERR("failed to resolve path, attr_file: %s!\n", attr_file);
|
||||
return -WD_ENODEV;
|
||||
+ }
|
||||
|
||||
fd = open(attr_path, O_RDONLY, 0);
|
||||
if (fd < 0) {
|
||||
@@ -78,16 +80,15 @@ static int get_int_attr(struct uacce_dev *dev, const char *attr, int *val)
|
||||
char buf[MAX_ATTR_STR_SIZE] = {0};
|
||||
int ret;
|
||||
|
||||
- if (!dev || !val)
|
||||
- return -WD_EINVAL;
|
||||
-
|
||||
ret = get_raw_attr(dev->dev_root, attr, buf, MAX_ATTR_STR_SIZE - 1);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
*val = strtol(buf, NULL, 10);
|
||||
- if (errno == ERANGE)
|
||||
+ if (errno == ERANGE) {
|
||||
+ WD_ERR("failed to strtol %s, out of range!\n", buf);
|
||||
return -errno;
|
||||
+ }
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -97,9 +98,6 @@ static int get_str_attr(struct uacce_dev *dev, const char *attr, char *buf,
|
||||
{
|
||||
int ret;
|
||||
|
||||
- if (!dev)
|
||||
- return -WD_EINVAL;
|
||||
-
|
||||
ret = get_raw_attr(dev->dev_root, attr, buf, buf_sz);
|
||||
if (ret < 0) {
|
||||
buf[0] = '\0';
|
||||
@@ -143,13 +141,19 @@ static int get_dev_info(struct uacce_dev *dev)
|
||||
ret = get_int_attr(dev, "isolate", &value);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
- else if (value == 1)
|
||||
+ else if (value == 1) {
|
||||
+ WD_ERR("skip isolated uacce device!\n");
|
||||
return -ENODEV;
|
||||
+ }
|
||||
}
|
||||
|
||||
ret = get_int_attr(dev, "flags", &dev->flags);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
+ else if (!(dev->flags & UACCE_DEV_SVA)) {
|
||||
+ WD_ERR("skip none sva uacce device!\n");
|
||||
+ return -ENODEV;
|
||||
+ }
|
||||
|
||||
ret = get_int_attr(dev, "region_mmio_size", &value);
|
||||
if (ret < 0)
|
||||
@@ -211,10 +215,8 @@ static struct uacce_dev *read_uacce_sysfs(const char *dev_name)
|
||||
goto out_dir;
|
||||
|
||||
ret = get_dev_info(dev);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to get dev info: ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
goto out_dir;
|
||||
- }
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -529,6 +531,9 @@ int wd_get_avail_ctx(struct uacce_dev *dev)
|
||||
{
|
||||
int avail_ctx, ret;
|
||||
|
||||
+ if (!dev)
|
||||
+ return -WD_EINVAL;
|
||||
+
|
||||
ret = get_int_attr(dev, "available_instances", &avail_ctx);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
@@ -551,8 +556,6 @@ static int get_dev_alg_name(const char *d_name, char *dev_alg_name, size_t sz)
|
||||
ret = get_raw_attr(dev_path, "algorithms", dev_alg_name, sz);
|
||||
if (ret < 0) {
|
||||
dev_alg_name[0] = '\0';
|
||||
- WD_ERR("failed to get alg for %s, ret = %d\n",
|
||||
- dev_path, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,38 +0,0 @@
|
||||
From f266f7920f0f58b71f2755a8cbad284f1848316c Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Tue, 15 Feb 2022 11:49:56 +0800
|
||||
Subject: [PATCH 63/64] uadk: fix staic check warning
|
||||
|
||||
1.fix unterminated string.
|
||||
2.fix bit operation of int data.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/wd.c b/wd.c
|
||||
index afcf134..565c173 100644
|
||||
--- a/wd.c
|
||||
+++ b/wd.c
|
||||
@@ -77,7 +77,7 @@ static int get_raw_attr(const char *dev_root, const char *attr, char *buf,
|
||||
|
||||
static int get_int_attr(struct uacce_dev *dev, const char *attr, int *val)
|
||||
{
|
||||
- char buf[MAX_ATTR_STR_SIZE] = {0};
|
||||
+ char buf[MAX_ATTR_STR_SIZE] = {'\0'};
|
||||
int ret;
|
||||
|
||||
ret = get_raw_attr(dev->dev_root, attr, buf, MAX_ATTR_STR_SIZE - 1);
|
||||
@@ -150,7 +150,7 @@ static int get_dev_info(struct uacce_dev *dev)
|
||||
ret = get_int_attr(dev, "flags", &dev->flags);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
- else if (!(dev->flags & UACCE_DEV_SVA)) {
|
||||
+ else if (!((unsigned int)dev->flags & UACCE_DEV_SVA)) {
|
||||
WD_ERR("skip none sva uacce device!\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,134 +0,0 @@
|
||||
From 2b4923b7290eba36bc2fefc517129fb30a3d207d Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Mon, 21 Feb 2022 09:14:17 +0800
|
||||
Subject: [PATCH 64/64] uadk/v1: fix the waiting time for receiving task
|
||||
|
||||
SEC device processes tasks quickly. If 'usleep' is used to
|
||||
wait for the hardware to process tasks, CPU scheduling will
|
||||
reduce performance. Therefore, increase the number of cycles
|
||||
to replace 'usleep'.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
v1/wd_aead.c | 15 ++++++++-------
|
||||
v1/wd_cipher.c | 15 ++++++++-------
|
||||
v1/wd_digest.c | 15 ++++++++-------
|
||||
3 files changed, 24 insertions(+), 21 deletions(-)
|
||||
|
||||
diff --git a/v1/wd_aead.c b/v1/wd_aead.c
|
||||
index 181b971..ad22426 100644
|
||||
--- a/v1/wd_aead.c
|
||||
+++ b/v1/wd_aead.c
|
||||
@@ -35,8 +35,7 @@
|
||||
#define MAX_AEAD_AUTH_SIZE 64
|
||||
#define MAX_AEAD_ASSOC_SIZE 65536
|
||||
#define MAX_HMAC_KEY_SIZE 128
|
||||
-#define MAX_AEAD_RETRY_CNT 2000000
|
||||
-#define AEAD_SLEEP_INTERVAL 0xf
|
||||
+#define MAX_AEAD_RETRY_CNT 20000000
|
||||
|
||||
#define DES_KEY_SIZE 8
|
||||
#define SM4_KEY_SIZE 16
|
||||
@@ -509,16 +508,18 @@ static int aead_recv_sync(struct wcrypto_aead_ctx *a_ctx,
|
||||
while (true) {
|
||||
ret = wd_burst_recv(a_ctx->q, (void **)(resp + recv_count),
|
||||
num - recv_count);
|
||||
- if (ret >= 0) {
|
||||
+ if (ret > 0) {
|
||||
recv_count += ret;
|
||||
if (recv_count == num)
|
||||
break;
|
||||
|
||||
- if (++rx_cnt > MAX_AEAD_RETRY_CNT)
|
||||
+ rx_cnt = 0;
|
||||
+ } else if (ret == 0) {
|
||||
+ if (++rx_cnt > MAX_AEAD_RETRY_CNT) {
|
||||
+ WD_ERR("%s:wcrypto_recv timeout, num = %u, recv_count = %u!\n",
|
||||
+ __func__, num, recv_count);
|
||||
break;
|
||||
-
|
||||
- if (!(rx_cnt & AEAD_SLEEP_INTERVAL))
|
||||
- usleep(1);
|
||||
+ }
|
||||
} else {
|
||||
WD_ERR("do aead wcrypto_recv error!\n");
|
||||
return ret;
|
||||
diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c
|
||||
index 7df44e7..8bf71be 100644
|
||||
--- a/v1/wd_cipher.c
|
||||
+++ b/v1/wd_cipher.c
|
||||
@@ -30,8 +30,7 @@
|
||||
#include "v1/wd_util.h"
|
||||
|
||||
#define MAX_CIPHER_KEY_SIZE 64
|
||||
-#define MAX_CIPHER_RETRY_CNT 2000000
|
||||
-#define CIPHER_SLEEP_INTERVAL 0xf
|
||||
+#define MAX_CIPHER_RETRY_CNT 20000000
|
||||
|
||||
#define DES_KEY_SIZE 8
|
||||
#define SM4_KEY_SIZE 16
|
||||
@@ -379,16 +378,18 @@ static int cipher_recv_sync(struct wcrypto_cipher_ctx *c_ctx,
|
||||
while (true) {
|
||||
ret = wd_burst_recv(c_ctx->q, (void **)(resp + recv_count),
|
||||
num - recv_count);
|
||||
- if (ret >= 0) {
|
||||
+ if (ret > 0) {
|
||||
recv_count += ret;
|
||||
if (recv_count == num)
|
||||
break;
|
||||
|
||||
- if (++rx_cnt > MAX_CIPHER_RETRY_CNT)
|
||||
+ rx_cnt = 0;
|
||||
+ } else if (ret == 0) {
|
||||
+ if (++rx_cnt > MAX_CIPHER_RETRY_CNT) {
|
||||
+ WD_ERR("%s:wcrypto_recv timeout, num = %u, recv_count = %u!\n",
|
||||
+ __func__, num, recv_count);
|
||||
break;
|
||||
-
|
||||
- if (!(rx_cnt & CIPHER_SLEEP_INTERVAL))
|
||||
- usleep(1);
|
||||
+ }
|
||||
} else {
|
||||
WD_ERR("do cipher wcrypto_recv error!\n");
|
||||
return ret;
|
||||
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
|
||||
index aae4823..2179415 100644
|
||||
--- a/v1/wd_digest.c
|
||||
+++ b/v1/wd_digest.c
|
||||
@@ -30,8 +30,7 @@
|
||||
#include "wd_util.h"
|
||||
|
||||
#define MAX_HMAC_KEY_SIZE 128
|
||||
-#define MAX_DIGEST_RETRY_CNT 2000000
|
||||
-#define DIGEST_SLEEP_INTERVAL 0xf
|
||||
+#define MAX_DIGEST_RETRY_CNT 20000000
|
||||
#define SEC_SHA1_ALIGN_SZ 64
|
||||
#define SEC_SHA512_ALIGN_SZ 128
|
||||
|
||||
@@ -275,16 +274,18 @@ static int digest_recv_sync(struct wcrypto_digest_ctx *d_ctx,
|
||||
while (true) {
|
||||
ret = wd_burst_recv(d_ctx->q, (void **)(resp + recv_count),
|
||||
num - recv_count);
|
||||
- if (ret >= 0) {
|
||||
+ if (ret > 0) {
|
||||
recv_count += ret;
|
||||
if (recv_count == num)
|
||||
break;
|
||||
|
||||
- if (++rx_cnt > MAX_DIGEST_RETRY_CNT)
|
||||
+ rx_cnt = 0;
|
||||
+ } else if (ret == 0) {
|
||||
+ if (++rx_cnt > MAX_DIGEST_RETRY_CNT) {
|
||||
+ WD_ERR("%s:wcrypto_recv timeout, num = %u, recv_count = %u!\n",
|
||||
+ __func__, num, recv_count);
|
||||
break;
|
||||
-
|
||||
- if (!(rx_cnt & DIGEST_SLEEP_INTERVAL))
|
||||
- usleep(1);
|
||||
+ }
|
||||
} else {
|
||||
WD_ERR("do digest wcrypto_recv error!\n");
|
||||
return ret;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
From 12afca7c245a7003c7d9e8e4445426794346940e Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Mon, 21 Feb 2022 20:09:51 +0800
|
||||
Subject: [PATCH 67/76] uadk: comp: optimize for spin lock
|
||||
|
||||
Printf should be outside of the lock region.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_comp.c | 10 ++++++++--
|
||||
1 file changed, 8 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/wd_comp.c b/wd_comp.c
|
||||
index 7868551..4a97f06 100644
|
||||
--- a/wd_comp.c
|
||||
+++ b/wd_comp.c
|
||||
@@ -718,15 +718,21 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
|
||||
|
||||
ret = wd_comp_setting.driver->comp_send(ctx->ctx, msg, priv);
|
||||
if (ret < 0) {
|
||||
+ pthread_spin_unlock(&ctx->lock);
|
||||
WD_ERR("wd comp send err(%d)!\n", ret);
|
||||
- wd_put_msg_to_pool(&wd_comp_setting.pool, idx, msg->tag);
|
||||
+ goto fail_with_msg;
|
||||
}
|
||||
|
||||
pthread_spin_unlock(&ctx->lock);
|
||||
|
||||
ret = wd_add_task_to_async_queue(&wd_comp_env_config, idx);
|
||||
if (ret)
|
||||
- wd_put_msg_to_pool(&wd_comp_setting.pool, idx, msg->tag);
|
||||
+ goto fail_with_msg;
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+fail_with_msg:
|
||||
+ wd_put_msg_to_pool(&wd_comp_setting.pool, idx, msg->tag);
|
||||
|
||||
return ret;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,239 +0,0 @@
|
||||
From e4758e80e2dc38ff018cd561636860121603b93f Mon Sep 17 00:00:00 2001
|
||||
From: Yang Shen <shenyang39@huawei.com>
|
||||
Date: Wed, 16 Feb 2022 15:05:11 +0800
|
||||
Subject: [PATCH 68/76] hisi-comp: cleanup for duplication code
|
||||
|
||||
The algorithms zlib/gzip/deflate have same process. The only difference is
|
||||
the protocol. So move the generic logic into a function and the difference
|
||||
into the parameters.
|
||||
|
||||
Signed-off-by: Yang Shen <shenyang39@huawei.com>
|
||||
---
|
||||
drv/hisi_comp.c | 161 ++++++++++++++----------------------------------
|
||||
1 file changed, 45 insertions(+), 116 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
|
||||
index 5ea5dc3..0760908 100644
|
||||
--- a/drv/hisi_comp.c
|
||||
+++ b/drv/hisi_comp.c
|
||||
@@ -223,33 +223,9 @@ static void fill_buf_addr_deflate(struct hisi_zip_sqe *sqe, void *src,
|
||||
sqe->stream_ctx_addr_h = upper_32_bits(ctx_buf);
|
||||
}
|
||||
|
||||
-static int fill_buf_deflate(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
- struct wd_comp_msg *msg)
|
||||
-{
|
||||
- struct wd_comp_req *req = &msg->req;
|
||||
- __u32 out_size = msg->avail_out;
|
||||
- __u32 in_size = req->src_len;
|
||||
- void *ctx_buf;
|
||||
- int ret;
|
||||
-
|
||||
- ret = buf_size_check_deflate(&in_size, &out_size);
|
||||
- if (ret)
|
||||
- return ret;
|
||||
-
|
||||
- fill_buf_size_deflate(sqe, in_size, out_size);
|
||||
-
|
||||
- if (msg->ctx_buf)
|
||||
- ctx_buf = msg->ctx_buf + RSV_OFFSET;
|
||||
- else
|
||||
- ctx_buf = NULL;
|
||||
-
|
||||
- fill_buf_addr_deflate(sqe, req->src, req->dst, ctx_buf);
|
||||
-
|
||||
- return 0;
|
||||
-}
|
||||
-
|
||||
-static int fill_buf_zlib(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
- struct wd_comp_msg *msg)
|
||||
+static int fill_buf_deflate_generic(struct hisi_zip_sqe *sqe,
|
||||
+ struct wd_comp_msg *msg,
|
||||
+ const char *head, int head_size)
|
||||
{
|
||||
__u32 in_size = msg->req.src_len;
|
||||
__u32 out_size = msg->avail_out;
|
||||
@@ -258,14 +234,14 @@ static int fill_buf_zlib(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
void *ctx_buf = NULL;
|
||||
int ret;
|
||||
|
||||
- if (msg->stream_pos == WD_COMP_STREAM_NEW) {
|
||||
+ if (msg->stream_pos == WD_COMP_STREAM_NEW && head != NULL) {
|
||||
if (msg->req.op_type == WD_DIR_COMPRESS) {
|
||||
- memcpy(dst, ZLIB_HEADER, ZLIB_HEADER_SZ);
|
||||
- dst += ZLIB_HEADER_SZ;
|
||||
- out_size -= ZLIB_HEADER_SZ;
|
||||
+ memcpy(dst, head, head_size);
|
||||
+ dst += head_size;
|
||||
+ out_size -= head_size;
|
||||
} else {
|
||||
- src += ZLIB_HEADER_SZ;
|
||||
- in_size -= ZLIB_HEADER_SZ;
|
||||
+ src += head_size;
|
||||
+ in_size -= head_size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,39 +259,22 @@ static int fill_buf_zlib(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int fill_buf_gzip(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
- struct wd_comp_msg *msg)
|
||||
+static int fill_buf_deflate(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
+ struct wd_comp_msg *msg)
|
||||
{
|
||||
- __u32 in_size = msg->req.src_len;
|
||||
- __u32 out_size = msg->avail_out;
|
||||
- void *src = msg->req.src;
|
||||
- void *dst = msg->req.dst;
|
||||
- void *ctx_buf = NULL;
|
||||
- int ret;
|
||||
-
|
||||
- if (msg->stream_pos == WD_COMP_STREAM_NEW) {
|
||||
- if (msg->req.op_type == WD_DIR_COMPRESS) {
|
||||
- memcpy(dst, GZIP_HEADER, GZIP_HEADER_SZ);
|
||||
- dst += GZIP_HEADER_SZ;
|
||||
- out_size -= GZIP_HEADER_SZ;
|
||||
- } else {
|
||||
- src += GZIP_HEADER_SZ;
|
||||
- in_size -= GZIP_HEADER_SZ;
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- ret = buf_size_check_deflate(&in_size, &out_size);
|
||||
- if (ret)
|
||||
- return ret;
|
||||
-
|
||||
- fill_buf_size_deflate(sqe, in_size, out_size);
|
||||
-
|
||||
- if (msg->ctx_buf)
|
||||
- ctx_buf = msg->ctx_buf + RSV_OFFSET;
|
||||
+ return fill_buf_deflate_generic(sqe, msg, NULL, 0);
|
||||
+}
|
||||
|
||||
- fill_buf_addr_deflate(sqe, src, dst, ctx_buf);
|
||||
+static int fill_buf_zlib(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
+ struct wd_comp_msg *msg)
|
||||
+{
|
||||
+ return fill_buf_deflate_generic(sqe, msg, ZLIB_HEADER, ZLIB_HEADER_SZ);
|
||||
+}
|
||||
|
||||
- return 0;
|
||||
+static int fill_buf_gzip(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
+ struct wd_comp_msg *msg)
|
||||
+{
|
||||
+ return fill_buf_deflate_generic(sqe, msg, GZIP_HEADER, GZIP_HEADER_SZ);
|
||||
}
|
||||
|
||||
static void fill_buf_type_sgl(struct hisi_zip_sqe *sqe)
|
||||
@@ -358,23 +317,6 @@ static int fill_buf_addr_deflate_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int fill_buf_deflate_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
- struct wd_comp_msg *msg)
|
||||
-{
|
||||
- struct wd_comp_req *req = &msg->req;
|
||||
- int ret;
|
||||
-
|
||||
- fill_buf_type_sgl(sqe);
|
||||
-
|
||||
- ret = fill_buf_addr_deflate_sgl(h_qp, sqe, msg);
|
||||
- if (ret)
|
||||
- return ret;
|
||||
-
|
||||
- fill_buf_size_deflate(sqe, req->src_len, msg->avail_out);
|
||||
-
|
||||
- return 0;
|
||||
-}
|
||||
-
|
||||
static void fill_buf_sgl_skip(struct hisi_zip_sqe *sqe, __u32 src_skip,
|
||||
__u32 dst_skip)
|
||||
{
|
||||
@@ -389,8 +331,9 @@ static void fill_buf_sgl_skip(struct hisi_zip_sqe *sqe, __u32 src_skip,
|
||||
sqe->dw8 = val;
|
||||
}
|
||||
|
||||
-static int fill_buf_zlib_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
- struct wd_comp_msg *msg)
|
||||
+static int fill_buf_deflate_slg_generic(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
+ struct wd_comp_msg *msg, const char *head,
|
||||
+ int head_size)
|
||||
{
|
||||
struct wd_comp_req *req = &msg->req;
|
||||
__u32 out_size = msg->avail_out;
|
||||
@@ -405,13 +348,13 @@ static int fill_buf_zlib_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
- if (msg->req.op_type == WD_DIR_COMPRESS) {
|
||||
- memcpy(req->list_dst->data, ZLIB_HEADER, ZLIB_HEADER_SZ);
|
||||
- dst_skip = ZLIB_HEADER_SZ;
|
||||
- out_size -= ZLIB_HEADER_SZ;
|
||||
- } else {
|
||||
- src_skip = ZLIB_HEADER_SZ;
|
||||
- in_size -= ZLIB_HEADER_SZ;
|
||||
+ if (head != NULL && msg->req.op_type == WD_DIR_COMPRESS) {
|
||||
+ memcpy(req->list_dst->data, head, head_size);
|
||||
+ dst_skip = head_size;
|
||||
+ out_size -= head_size;
|
||||
+ } else if (head != NULL && msg->req.op_type == WD_DIR_DECOMPRESS) {
|
||||
+ src_skip = head_size;
|
||||
+ in_size -= head_size;
|
||||
}
|
||||
|
||||
fill_buf_sgl_skip(sqe, src_skip, dst_skip);
|
||||
@@ -421,36 +364,22 @@ static int fill_buf_zlib_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int fill_buf_gzip_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
- struct wd_comp_msg *msg)
|
||||
+static int fill_buf_deflate_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
+ struct wd_comp_msg *msg)
|
||||
{
|
||||
- struct wd_comp_req *req = &msg->req;
|
||||
- __u32 out_size = msg->avail_out;
|
||||
- __u32 in_size = req->src_len;
|
||||
- __u32 src_skip = 0;
|
||||
- __u32 dst_skip = 0;
|
||||
- int ret;
|
||||
-
|
||||
- fill_buf_type_sgl(sqe);
|
||||
-
|
||||
- ret = fill_buf_addr_deflate_sgl(h_qp, sqe, msg);
|
||||
- if (ret)
|
||||
- return ret;
|
||||
-
|
||||
- if (msg->req.op_type == WD_DIR_COMPRESS) {
|
||||
- memcpy(req->list_dst->data, GZIP_HEADER, GZIP_HEADER_SZ);
|
||||
- dst_skip = GZIP_HEADER_SZ;
|
||||
- out_size -= GZIP_HEADER_SZ;
|
||||
- } else {
|
||||
- src_skip = GZIP_HEADER_SZ;
|
||||
- in_size -= GZIP_HEADER_SZ;
|
||||
- }
|
||||
-
|
||||
- fill_buf_sgl_skip(sqe, src_skip, dst_skip);
|
||||
+ return fill_buf_deflate_slg_generic(h_qp, sqe, msg, NULL, 0);
|
||||
+}
|
||||
|
||||
- fill_buf_size_deflate(sqe, in_size, out_size);
|
||||
+static int fill_buf_zlib_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
+ struct wd_comp_msg *msg)
|
||||
+{
|
||||
+ return fill_buf_deflate_slg_generic(h_qp, sqe, msg, ZLIB_HEADER, ZLIB_HEADER_SZ);
|
||||
+}
|
||||
|
||||
- return 0;
|
||||
+static int fill_buf_gzip_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
+ struct wd_comp_msg *msg)
|
||||
+{
|
||||
+ return fill_buf_deflate_slg_generic(h_qp, sqe, msg, GZIP_HEADER, GZIP_HEADER_SZ);
|
||||
}
|
||||
|
||||
static void fill_buf_size_lz77_zstd(struct hisi_zip_sqe *sqe, __u32 in_size,
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,80 +0,0 @@
|
||||
From fb0abcd7e3d0afdad015193e7e220b6597e0c606 Mon Sep 17 00:00:00 2001
|
||||
From: Yang Shen <shenyang39@huawei.com>
|
||||
Date: Wed, 16 Feb 2022 15:05:12 +0800
|
||||
Subject: [PATCH 69/76] wd_comp: remove some useless printf
|
||||
|
||||
Due to the called function has print the error reason, the call function
|
||||
has no need to add printf.
|
||||
|
||||
Signed-off-by: Yang Shen <shenyang39@huawei.com>
|
||||
---
|
||||
wd_comp.c | 20 +++++---------------
|
||||
1 file changed, 5 insertions(+), 15 deletions(-)
|
||||
|
||||
diff --git a/wd_comp.c b/wd_comp.c
|
||||
index 4a97f06..722666d 100644
|
||||
--- a/wd_comp.c
|
||||
+++ b/wd_comp.c
|
||||
@@ -459,10 +459,8 @@ int wd_do_comp_sync(handle_t h_sess, struct wd_comp_req *req)
|
||||
int ret;
|
||||
|
||||
ret = wd_comp_check_params(sess, req, CTX_MODE_SYNC);
|
||||
- if (ret) {
|
||||
- WD_ERR("fail to check params!\n");
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
|
||||
if (!req->src_len) {
|
||||
WD_ERR("invalid: req src_len is 0!\n");
|
||||
@@ -477,10 +475,8 @@ int wd_do_comp_sync(handle_t h_sess, struct wd_comp_req *req)
|
||||
msg.stream_mode = WD_COMP_STATELESS;
|
||||
|
||||
ret = wd_comp_sync_job(sess, req, &msg);
|
||||
- if (ret) {
|
||||
- WD_ERR("fail to check params!\n");
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
|
||||
req->src_len = msg.in_cons;
|
||||
req->dst_len = msg.produced;
|
||||
@@ -499,10 +495,8 @@ int wd_do_comp_sync2(handle_t h_sess, struct wd_comp_req *req)
|
||||
int ret;
|
||||
|
||||
ret = wd_comp_check_params(sess, req, CTX_MODE_SYNC);
|
||||
- if (ret) {
|
||||
- WD_ERR("fail to check params!\n");
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
|
||||
if (!req->src_len) {
|
||||
WD_ERR("invalid: req src_len is 0!\n");
|
||||
@@ -655,10 +649,8 @@ int wd_do_comp_strm(handle_t h_sess, struct wd_comp_req *req)
|
||||
src_len = req->src_len;
|
||||
|
||||
ret = wd_comp_sync_job(sess, req, &msg);
|
||||
- if (ret) {
|
||||
- WD_ERR("fail to check params!\n");
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
|
||||
req->src_len = msg.in_cons;
|
||||
req->dst_len = msg.produced;
|
||||
@@ -685,10 +677,8 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
|
||||
__u32 idx;
|
||||
|
||||
ret = wd_comp_check_params(sess, req, CTX_MODE_ASYNC);
|
||||
- if (ret) {
|
||||
- WD_ERR("fail to check params!\n");
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
|
||||
if (!req->src_len) {
|
||||
WD_ERR("invalid: req src_len is 0!\n");
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,639 +0,0 @@
|
||||
From 471df047de19c8ec5a111e8c39a17f4240f6dead Mon Sep 17 00:00:00 2001
|
||||
From: Yang Shen <shenyang39@huawei.com>
|
||||
Date: Wed, 16 Feb 2022 15:05:13 +0800
|
||||
Subject: [PATCH 70/76] sample: add a demo for comp
|
||||
|
||||
Add the sample for uadk comp which is aimed to support test of
|
||||
compression/decompression and provide users with API reference.
|
||||
|
||||
Signed-off-by: Yang Shen <shenyang39@huawei.com>
|
||||
---
|
||||
sample/Makefile.am | 10 +-
|
||||
sample/uadk_comp.c | 505 +++++++++++++++++++++++++++++++++++++++++++
|
||||
sample/uadk_sample.c | 76 -------
|
||||
3 files changed, 510 insertions(+), 81 deletions(-)
|
||||
create mode 100644 sample/uadk_comp.c
|
||||
delete mode 100644 sample/uadk_sample.c
|
||||
|
||||
diff --git a/sample/Makefile.am b/sample/Makefile.am
|
||||
index 62ab902..eb8d71b 100644
|
||||
--- a/sample/Makefile.am
|
||||
+++ b/sample/Makefile.am
|
||||
@@ -1,16 +1,16 @@
|
||||
ACLOCAL_AMFLAGS = -I m4 -I./include
|
||||
AM_CFLAGS=-Wall -fno-strict-aliasing -I$(top_srcdir) -I$(top_srcdir)/include
|
||||
|
||||
-bin_PROGRAMS=uadk_sample
|
||||
+bin_PROGRAMS=uadk_comp
|
||||
|
||||
-uadk_sample_SOURCES=uadk_sample.c
|
||||
+uadk_comp_SOURCES=uadk_comp.c
|
||||
|
||||
if WD_STATIC_DRV
|
||||
AM_CFLAGS+=-Bstatic
|
||||
-uadk_sample_LDADD=../.libs/libwd.a \
|
||||
+uadk_comp_LDADD=../.libs/libwd.a \
|
||||
../.libs/libwd_comp.a \
|
||||
../.libs/libhisi_zip.a -lpthread -lnuma
|
||||
else
|
||||
-uadk_sample_LDADD=-L../.libs -l:libwd.so.2 -l:libwd_comp.so.2 -lpthread -lnuma
|
||||
+uadk_comp_LDADD=-L../.libs -l:libwd.so.2 -l:libwd_comp.so.2 -lpthread -lnuma
|
||||
endif
|
||||
-uadk_sample_LDFLAGS=-Wl,-rpath,'/usr/local/lib'
|
||||
+uadk_comp_LDFLAGS=-Wl,-rpath,'/usr/local/lib'
|
||||
diff --git a/sample/uadk_comp.c b/sample/uadk_comp.c
|
||||
new file mode 100644
|
||||
index 0000000..908c7bc
|
||||
--- /dev/null
|
||||
+++ b/sample/uadk_comp.c
|
||||
@@ -0,0 +1,505 @@
|
||||
+#include <stdlib.h>
|
||||
+#include <stdio.h>
|
||||
+#include <getopt.h>
|
||||
+#include <math.h>
|
||||
+#include <sys/stat.h>
|
||||
+
|
||||
+#include "wd_alg_common.h"
|
||||
+#include "wd_comp.h"
|
||||
+#include "wd_sched.h"
|
||||
+
|
||||
+#define SCHED_RR_NAME "sched_rr"
|
||||
+
|
||||
+#define CTX_SET_NUM 1
|
||||
+#define CTX_SET_SIZE 4
|
||||
+#define MAX_ALG_LEN 32
|
||||
+#define MAX_THREAD 1024
|
||||
+
|
||||
+#define no_argument 0
|
||||
+#define required_argument 1
|
||||
+#define optional_argument 2
|
||||
+
|
||||
+struct request_config {
|
||||
+ char algname[MAX_ALG_LEN];
|
||||
+ enum wd_comp_alg_type alg;
|
||||
+ enum wd_comp_level complv;
|
||||
+ enum wd_comp_op_type optype;
|
||||
+ enum wd_comp_winsz_type winsize;
|
||||
+ enum wd_ctx_mode request_mode;
|
||||
+ enum wd_buff_type buftype;
|
||||
+ struct wd_ctx_config ctx;
|
||||
+ struct wd_sched *sched;
|
||||
+ struct uacce_dev_list *list;
|
||||
+};
|
||||
+
|
||||
+struct request_data {
|
||||
+ handle_t h_sess;
|
||||
+ struct wd_comp_req req;
|
||||
+};
|
||||
+
|
||||
+struct acc_alg_item {
|
||||
+ char *name;
|
||||
+ int alg;
|
||||
+};
|
||||
+
|
||||
+static struct request_config config = {
|
||||
+ .complv = WD_COMP_L8,
|
||||
+ .optype = WD_DIR_COMPRESS,
|
||||
+ .winsize = WD_COMP_WS_8K,
|
||||
+ .request_mode = CTX_MODE_SYNC,
|
||||
+ .buftype = WD_FLAT_BUF,
|
||||
+};
|
||||
+
|
||||
+static struct request_data data;
|
||||
+
|
||||
+static struct acc_alg_item alg_options[] = {
|
||||
+ {"zlib", WD_ZLIB},
|
||||
+ {"gzip", WD_GZIP},
|
||||
+ {"deflate", WD_DEFLATE},
|
||||
+ {"lz77_zstd", WD_LZ77_ZSTD},
|
||||
+ {"", WD_COMP_ALG_MAX}
|
||||
+};
|
||||
+
|
||||
+static void cowfail(char *s)
|
||||
+{
|
||||
+ fprintf(stderr, ""
|
||||
+ "__________________________________\n\n"
|
||||
+ "%s"
|
||||
+ "\n----------------------------------\n"
|
||||
+ "\t \\ ^__^\n"
|
||||
+ "\t \\ (oo)\\_______\n"
|
||||
+ "\t (__)\\ )\\\\\n"
|
||||
+ "\t ||----w |\n"
|
||||
+ "\t || ||\n"
|
||||
+ "\n", s);
|
||||
+}
|
||||
+
|
||||
+static struct uacce_dev_list* get_dev_list(char *alg_name)
|
||||
+{
|
||||
+ struct uacce_dev_list *list, *p, *head = NULL, *prev = NULL;
|
||||
+ int ctx_set_num = CTX_SET_NUM;
|
||||
+ int max_ctx_num;
|
||||
+ int i;
|
||||
+
|
||||
+ for (i = 0; i < ARRAY_SIZE(alg_options); i++)
|
||||
+ if (!strcmp(alg_name, alg_options[i].name))
|
||||
+ config.alg = alg_options[i].alg;
|
||||
+
|
||||
+ list = wd_get_accel_list(alg_name);
|
||||
+ if (!list)
|
||||
+ return NULL;
|
||||
+
|
||||
+ p = list;
|
||||
+ /* Find one device matching the requested contexts. */
|
||||
+ while (p) {
|
||||
+ max_ctx_num = wd_get_avail_ctx(p->dev);
|
||||
+ /*
|
||||
+ * Check whether there's enough contexts.
|
||||
+ * There may be multiple taskes running together.
|
||||
+ * The number of multiple taskes is specified in children.
|
||||
+ */
|
||||
+ if (max_ctx_num < ctx_set_num * CTX_SET_SIZE) {
|
||||
+ if (!head)
|
||||
+ head = p;
|
||||
+ prev = p;
|
||||
+ p = p->next;
|
||||
+ } else
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ if (!p) {
|
||||
+ fprintf(stderr, "%s request too much contexts: %d.\n",
|
||||
+ __func__, ctx_set_num);
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ /* Adjust p to the head of list if p is in the middle. */
|
||||
+ if (p && (p != list)) {
|
||||
+ prev->next = p->next;
|
||||
+ p->next = head;
|
||||
+ return p;
|
||||
+ }
|
||||
+
|
||||
+ return list;
|
||||
+
|
||||
+out:
|
||||
+ wd_free_list_accels(list);
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
+static int lib_poll_func(__u32 pos, __u32 expect, __u32 *count)
|
||||
+{
|
||||
+ int ret;
|
||||
+
|
||||
+ ret = wd_comp_poll_ctx(pos, expect, count);
|
||||
+ if (ret < 0)
|
||||
+ return ret;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static struct wd_sched *uadk_comp_sched_init(void)
|
||||
+{
|
||||
+ int ctx_set_num = CTX_SET_NUM;
|
||||
+ struct sched_params param;
|
||||
+ struct wd_sched *sched;
|
||||
+ int i, j, ret;
|
||||
+
|
||||
+ sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 2, 2, lib_poll_func);
|
||||
+ if (!sched) {
|
||||
+ printf("%s fail to alloc sched.\n", __func__);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ sched->name = SCHED_RR_NAME;
|
||||
+
|
||||
+ /*
|
||||
+ * All contexts for 2 modes & 2 types.
|
||||
+ * The test only uses one kind of contexts at the same time.
|
||||
+ */
|
||||
+ for (i = 0; i < CTX_SET_SIZE; i++) {
|
||||
+ for (j = ctx_set_num * i; j < ctx_set_num * (i + 1); j++) {
|
||||
+ param.mode = i / 2;
|
||||
+ param.type = i % 2;
|
||||
+ param.numa_id = 0;
|
||||
+ param.begin = ctx_set_num * i;
|
||||
+ param.end = ctx_set_num * (i + 1) - 1;
|
||||
+ ret = wd_sched_rr_instance(sched, ¶m);
|
||||
+ if (ret < 0) {
|
||||
+ fprintf(stderr, "%s fail to fill sched region.\n",
|
||||
+ __func__);
|
||||
+ goto out_free_sched;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return sched;
|
||||
+
|
||||
+out_free_sched:
|
||||
+ wd_sched_rr_release(sched);
|
||||
+
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
+static int uadk_comp_ctx_init(void)
|
||||
+{
|
||||
+ struct wd_ctx_config *ctx = &config.ctx;
|
||||
+ int ctx_set_num = CTX_SET_NUM;
|
||||
+ struct wd_sched *sched;
|
||||
+ int i, j, ret;
|
||||
+
|
||||
+ memset(ctx, 0, sizeof(struct wd_ctx_config));
|
||||
+ ctx->ctx_num = ctx_set_num * CTX_SET_SIZE;
|
||||
+ ctx->ctxs = calloc(ctx_set_num * CTX_SET_SIZE, sizeof(struct wd_ctx));
|
||||
+ if (!ctx->ctxs) {
|
||||
+ fprintf(stderr, "%s fail to allocate contexts.\n", __func__);
|
||||
+ return -WD_ENOMEM;
|
||||
+ }
|
||||
+
|
||||
+ for (i = 0; i < CTX_SET_SIZE; i++) {
|
||||
+ for (j = ctx_set_num * i; j < ctx_set_num * (i + 1); j++) {
|
||||
+ ctx->ctxs[j].ctx = wd_request_ctx(config.list->dev);
|
||||
+ if (!ctx->ctxs[j].ctx) {
|
||||
+ fprintf(stderr, "%s fail to request context #%d.\n",
|
||||
+ __func__, i);
|
||||
+ ret = -WD_EINVAL;
|
||||
+ goto out_free_ctx;
|
||||
+ }
|
||||
+ ctx->ctxs[j].ctx_mode = i / 2;
|
||||
+ ctx->ctxs[j].op_type = i % 2;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ sched = uadk_comp_sched_init();
|
||||
+ if (!sched) {
|
||||
+ ret = -WD_EINVAL;
|
||||
+ goto out_free_ctx;
|
||||
+ }
|
||||
+
|
||||
+ config.sched = sched;
|
||||
+
|
||||
+ ret = wd_comp_init(ctx, sched);
|
||||
+ if (ret) {
|
||||
+ fprintf(stderr, "%s fail to init comp.\n", __func__);
|
||||
+ goto out_free_sched;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+out_free_sched:
|
||||
+ wd_sched_rr_release(sched);
|
||||
+
|
||||
+out_free_ctx:
|
||||
+ for (i = 0; i < ctx->ctx_num; i++)
|
||||
+ if (ctx->ctxs[i].ctx)
|
||||
+ wd_release_ctx(ctx->ctxs[i].ctx);
|
||||
+ free(ctx->ctxs);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static void uadk_comp_ctx_uninit(void)
|
||||
+{
|
||||
+ struct wd_ctx_config *ctx = &config.ctx;
|
||||
+ int i;
|
||||
+
|
||||
+ wd_comp_uninit();
|
||||
+
|
||||
+ for (i = 0; i < ctx->ctx_num; i++)
|
||||
+ wd_release_ctx(ctx->ctxs[i].ctx);
|
||||
+
|
||||
+ wd_free_list_accels(config.list);
|
||||
+ wd_sched_rr_release(config.sched);
|
||||
+}
|
||||
+
|
||||
+static int uadk_comp_sess_init(void)
|
||||
+{
|
||||
+ struct wd_comp_sess_setup setup = {0};
|
||||
+ struct sched_params param = {0};
|
||||
+ handle_t h_sess;
|
||||
+ int ret = 0;
|
||||
+
|
||||
+ setup.alg_type = config.alg;
|
||||
+ setup.op_type = config.optype;
|
||||
+ setup.comp_lv = config.complv;
|
||||
+ setup.win_sz = config.winsize;
|
||||
+ param.type = config.optype;
|
||||
+ setup.sched_param = ¶m;
|
||||
+
|
||||
+ h_sess = wd_comp_alloc_sess(&setup);
|
||||
+ if (!h_sess) {
|
||||
+ fprintf(stderr, "%s fail to alloc comp sess.\n", __func__);
|
||||
+ ret = -WD_EINVAL;
|
||||
+ goto out_free_sess;
|
||||
+ }
|
||||
+ data.h_sess = h_sess;
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+out_free_sess:
|
||||
+ wd_comp_free_sess(data.h_sess);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static void uadk_comp_sess_uninit(void)
|
||||
+{
|
||||
+ wd_comp_free_sess(data.h_sess);
|
||||
+}
|
||||
+
|
||||
+static int uadk_req_buf_init(struct wd_comp_req *req, FILE *source)
|
||||
+{
|
||||
+ int src_len = req->src_len;
|
||||
+ int dst_len = req->dst_len;
|
||||
+ void *src, *dst;
|
||||
+ int ret;
|
||||
+
|
||||
+ src = malloc(src_len);
|
||||
+ if (!src) {
|
||||
+ fprintf(stderr, "%s fail to alloc src.\n", __func__);
|
||||
+ return -WD_ENOMEM;
|
||||
+ }
|
||||
+
|
||||
+ dst = malloc(dst_len);
|
||||
+ if (!dst) {
|
||||
+ fprintf(stderr, "%s fail to alloc dst.\n", __func__);
|
||||
+ ret = -WD_ENOMEM;
|
||||
+ goto out_free_src;
|
||||
+ }
|
||||
+
|
||||
+ ret = fread(src, 1, src_len, source);
|
||||
+ if (ret != src_len) {
|
||||
+ fprintf(stderr, "%s fail to read stdin.\n", __func__);
|
||||
+ ret = -WD_ENOMEM;
|
||||
+ goto out_free_dst;
|
||||
+ }
|
||||
+
|
||||
+ req->src = src;
|
||||
+ req->dst = dst;
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+out_free_dst:
|
||||
+ free(dst);
|
||||
+
|
||||
+out_free_src:
|
||||
+ free(src);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static void uadk_req_buf_uninit(void)
|
||||
+{
|
||||
+ free(data.req.src);
|
||||
+ free(data.req.dst);
|
||||
+}
|
||||
+
|
||||
+static int uadk_comp_request_init(FILE *source)
|
||||
+{
|
||||
+ struct wd_comp_req *req;
|
||||
+ struct stat fs;
|
||||
+ int fd, ret;
|
||||
+
|
||||
+ fd = fileno(source);
|
||||
+ ret = fstat(fd, &fs);
|
||||
+ if (ret < 0) {
|
||||
+ fprintf(stderr, "%s fstat error.\n", __func__);
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ req = &data.req;
|
||||
+ req->op_type = config.optype;
|
||||
+ req->data_fmt = WD_FLAT_BUF;
|
||||
+ req->src_len = fs.st_size;
|
||||
+ req->dst_len = fs.st_size * 4;
|
||||
+
|
||||
+ return uadk_req_buf_init(req, source);
|
||||
+}
|
||||
+
|
||||
+static void uadk_comp_request_uninit(void)
|
||||
+{
|
||||
+ uadk_req_buf_uninit();
|
||||
+}
|
||||
+
|
||||
+static int uadk_do_comp(void)
|
||||
+{
|
||||
+ int ret;
|
||||
+
|
||||
+ ret = wd_do_comp_sync2(data.h_sess, &data.req);
|
||||
+ if (ret < 0)
|
||||
+ fprintf(stderr, "%s fail to do comp sync(ret = %d).\n", __func__, ret);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static int uadk_comp_write_file(FILE *dest)
|
||||
+{
|
||||
+ int size;
|
||||
+
|
||||
+ size = fwrite(data.req.dst, 1, data.req.dst_len, dest);
|
||||
+ if (size < 0)
|
||||
+ return size;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int operation(FILE *source, FILE *dest)
|
||||
+{
|
||||
+ int ret;
|
||||
+
|
||||
+ ret = uadk_comp_ctx_init();
|
||||
+ if (ret) {
|
||||
+ fprintf(stderr, "%s fail to init ctx!\n", __func__);
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ ret = uadk_comp_sess_init();
|
||||
+ if (ret) {
|
||||
+ fprintf(stderr, "%s fail to init sess!\n", __func__);
|
||||
+ goto out_ctx_uninit;
|
||||
+ }
|
||||
+
|
||||
+ ret = uadk_comp_request_init(source);
|
||||
+ if (ret) {
|
||||
+ fprintf(stderr, "%s fail to init request!\n", __func__);
|
||||
+ goto out_sess_uninit;
|
||||
+ }
|
||||
+
|
||||
+ ret = uadk_do_comp();
|
||||
+ if (ret) {
|
||||
+ fprintf(stderr, "%s fail to do request!\n", __func__);
|
||||
+ goto out_sess_uninit;
|
||||
+ }
|
||||
+
|
||||
+ ret = uadk_comp_write_file(dest);
|
||||
+ if (ret)
|
||||
+ fprintf(stderr, "%s fail to write result!\n", __func__);
|
||||
+
|
||||
+ uadk_comp_request_uninit();
|
||||
+
|
||||
+out_sess_uninit:
|
||||
+ uadk_comp_sess_uninit();
|
||||
+
|
||||
+out_ctx_uninit:
|
||||
+ uadk_comp_ctx_uninit();
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static void print_help(void)
|
||||
+{
|
||||
+ fprintf(stderr, ""
|
||||
+ "uadk_comp - a tool used to do compress/decompress\n\n"
|
||||
+ "Arguments:\n"
|
||||
+ "\t[--alg]: "
|
||||
+ "The name of the algorithm (can find under .../uacce/<dev>/algorithms)\n"
|
||||
+ "\t[--optype]: "
|
||||
+ "Use 0/1 stand for compression/decompression.\n"
|
||||
+ "\t[--winsize]: "
|
||||
+ "The window size for compression(8K as default).\n"
|
||||
+ "\t[--complv]: "
|
||||
+ "The compression level(8 as default).\n"
|
||||
+ "\t[--help] "
|
||||
+ "Print Help (this message) and exit\n"
|
||||
+ "");
|
||||
+}
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ int option_index = 0;
|
||||
+ int help = 0;
|
||||
+ int ret, c;
|
||||
+
|
||||
+ static struct option long_options[] = {
|
||||
+ {"help", no_argument, 0, 0},
|
||||
+ {"alg", required_argument, 0, 1},
|
||||
+ {"complv", required_argument, 0, 2},
|
||||
+ {"optype", required_argument, 0, 3},
|
||||
+ {"winsize", required_argument, 0, 4},
|
||||
+ {0, 0, 0, 0}
|
||||
+ };
|
||||
+
|
||||
+ while (!help) {
|
||||
+ c = getopt_long(argc, argv, "", long_options, &option_index);
|
||||
+ if (c == -1)
|
||||
+ break;
|
||||
+
|
||||
+ switch (c) {
|
||||
+ case 0:
|
||||
+ help = 1;
|
||||
+ break;
|
||||
+ case 1:
|
||||
+ config.list = get_dev_list(optarg);
|
||||
+ if (!config.list) {
|
||||
+ cowfail("Can't find your algorithm!\n");
|
||||
+ help = 1;
|
||||
+ } else {
|
||||
+ strcpy(config.algname, optarg);
|
||||
+ }
|
||||
+ break;
|
||||
+ case 2:
|
||||
+ config.complv = strtol(optarg, NULL, 0);
|
||||
+ break;
|
||||
+ case 3:
|
||||
+ config.optype = strtol(optarg, NULL, 0);
|
||||
+ break;
|
||||
+ case 4:
|
||||
+ config.winsize = strtol(optarg, NULL, 0);
|
||||
+ break;
|
||||
+ default:
|
||||
+ help = 1;
|
||||
+ cowfail("bad input test parameter!\n");
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (help) {
|
||||
+ print_help();
|
||||
+ exit(-1);
|
||||
+ }
|
||||
+
|
||||
+ ret = operation(stdin, stdout);
|
||||
+ if (ret)
|
||||
+ cowfail("So sad for we do something wrong!\n");
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
diff --git a/sample/uadk_sample.c b/sample/uadk_sample.c
|
||||
deleted file mode 100644
|
||||
index 3ec2c47..0000000
|
||||
--- a/sample/uadk_sample.c
|
||||
+++ /dev/null
|
||||
@@ -1,76 +0,0 @@
|
||||
-#include "wd_comp.h"
|
||||
-
|
||||
-#define TEST_WORD_LEN 64
|
||||
-
|
||||
-int operation(int op_type, void *src, int src_sz, void *dst, int *dst_sz)
|
||||
-{
|
||||
- struct wd_comp_sess_setup setup = {0};
|
||||
- struct wd_comp_req req = {0};
|
||||
- handle_t h_dfl;
|
||||
- int ret;
|
||||
-
|
||||
- if (!src || !dst || !dst_sz || (*dst_sz <= 0))
|
||||
- return -EINVAL;
|
||||
- ret = wd_comp_env_init(NULL);
|
||||
- if (ret < 0)
|
||||
- goto out;
|
||||
-
|
||||
- setup.alg_type = WD_ZLIB;
|
||||
- setup.win_sz = WD_COMP_WS_32K;
|
||||
- setup.comp_lv = WD_COMP_L8;
|
||||
- setup.op_type = op_type;
|
||||
- h_dfl = wd_comp_alloc_sess(&setup);
|
||||
- if (!h_dfl) {
|
||||
- ret = -EINVAL;
|
||||
- goto out_sess;
|
||||
- }
|
||||
- req.src = src;
|
||||
- req.src_len = src_sz;
|
||||
- req.dst = dst;
|
||||
- req.dst_len = *dst_sz;
|
||||
- req.op_type = op_type;
|
||||
- req.data_fmt = WD_FLAT_BUF;
|
||||
- do {
|
||||
- ret = wd_do_comp_sync(h_dfl, &req);
|
||||
- } while (ret == -WD_EBUSY);
|
||||
- if (ret)
|
||||
- goto out_comp;
|
||||
- *dst_sz = req.dst_len;
|
||||
- wd_comp_free_sess(h_dfl);
|
||||
- wd_comp_env_uninit();
|
||||
- return 0;
|
||||
-out_comp:
|
||||
- wd_comp_free_sess(h_dfl);
|
||||
-out_sess:
|
||||
- wd_comp_env_uninit();
|
||||
-out:
|
||||
- return ret;
|
||||
-}
|
||||
-
|
||||
-int main(void)
|
||||
-{
|
||||
- char src[TEST_WORD_LEN] = {0}, dst[TEST_WORD_LEN] = {0};
|
||||
- char tmp[TEST_WORD_LEN] = {0};
|
||||
- int ret, src_sz, dst_sz, tmp_sz;
|
||||
-
|
||||
- strcpy(src, "go to test.");
|
||||
- src_sz = strlen(src);
|
||||
- dst_sz = tmp_sz = TEST_WORD_LEN;
|
||||
- ret = operation(WD_DIR_COMPRESS, src, src_sz, tmp, &tmp_sz);
|
||||
- if (ret < 0)
|
||||
- goto out;
|
||||
- ret = operation(WD_DIR_DECOMPRESS, tmp, tmp_sz, dst, &dst_sz);
|
||||
- if (ret < 0)
|
||||
- goto out;
|
||||
- if ((src_sz == dst_sz) && !strcmp(src, dst))
|
||||
- printf("Compression verified!\n");
|
||||
- else {
|
||||
- printf("Fail to verify the compression!\n");
|
||||
- ret = -EFAULT;
|
||||
- goto out;
|
||||
- }
|
||||
- return 0;
|
||||
-out:
|
||||
- return ret;
|
||||
-}
|
||||
-
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,291 +0,0 @@
|
||||
From 47705e97580314d97c6ad781b0252a80d8024fc1 Mon Sep 17 00:00:00 2001
|
||||
From: Liulongfang <liulongfang@foxmail.com>
|
||||
Date: Tue, 22 Feb 2022 11:47:02 +0800
|
||||
Subject: [PATCH 71/76] uadk/tool: modify uadk_benchmark toos code
|
||||
|
||||
1.bugfix some alg parameter
|
||||
2.add multi thread for async mode to poll BD
|
||||
|
||||
Signed-off-by: Liulongfang <liulongfang@foxmail.com>
|
||||
---
|
||||
uadk_tool/sec_uadk_benchmark.c | 55 +++++++++++++++++--------------
|
||||
uadk_tool/sec_wd_benchmark.c | 59 +++++++++++++++++++---------------
|
||||
uadk_tool/uadk_benchmark.c | 4 +--
|
||||
3 files changed, 66 insertions(+), 52 deletions(-)
|
||||
|
||||
diff --git a/uadk_tool/sec_uadk_benchmark.c b/uadk_tool/sec_uadk_benchmark.c
|
||||
index d68ac25..467e621 100644
|
||||
--- a/uadk_tool/sec_uadk_benchmark.c
|
||||
+++ b/uadk_tool/sec_uadk_benchmark.c
|
||||
@@ -180,13 +180,13 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options)
|
||||
break;
|
||||
case DES3_128_ECB:
|
||||
keysize = 16;
|
||||
- ivsize = 8;
|
||||
+ ivsize = 0;
|
||||
mode = WD_CIPHER_ECB;
|
||||
alg = WD_CIPHER_3DES;
|
||||
break;
|
||||
case DES3_192_ECB:
|
||||
keysize = 24;
|
||||
- ivsize = 8;
|
||||
+ ivsize = 0;
|
||||
mode = WD_CIPHER_ECB;
|
||||
alg = WD_CIPHER_3DES;
|
||||
break;
|
||||
@@ -204,7 +204,7 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options)
|
||||
break;
|
||||
case SM4_128_ECB:
|
||||
keysize = 16;
|
||||
- ivsize = 16;
|
||||
+ ivsize = 0;
|
||||
mode = WD_CIPHER_ECB;
|
||||
alg = WD_CIPHER_SM4;
|
||||
break;
|
||||
@@ -233,7 +233,7 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options)
|
||||
alg = WD_CIPHER_SM4;
|
||||
break;
|
||||
case SM4_128_XTS:
|
||||
- keysize = 16;
|
||||
+ keysize = 32;
|
||||
ivsize = 16;
|
||||
mode = WD_CIPHER_XTS;
|
||||
alg = WD_CIPHER_SM4;
|
||||
@@ -560,11 +560,14 @@ void *sec_uadk_poll(void *data)
|
||||
poll_ctx uadk_poll_ctx = NULL;
|
||||
thread_data *pdata = (thread_data *)data;
|
||||
u32 expt = ACC_QUEUE_SIZE * g_thread_num;
|
||||
+ u32 id = pdata->td_id;
|
||||
u32 last_time = 2; /* poll need one more recv time */
|
||||
u32 count = 0;
|
||||
u32 recv = 0;
|
||||
- u32 i = 0;
|
||||
- int ret;
|
||||
+ int ret;
|
||||
+
|
||||
+ if (id > g_ctxnum)
|
||||
+ return NULL;
|
||||
|
||||
switch(pdata->subtype) {
|
||||
case CIPHER_TYPE:
|
||||
@@ -582,15 +585,13 @@ void *sec_uadk_poll(void *data)
|
||||
}
|
||||
|
||||
while (last_time) {
|
||||
- for (i = 0; i < g_ctx_cfg.ctx_num; i++) {
|
||||
- ret = uadk_poll_ctx(i, expt, &recv);
|
||||
- // SEC_TST_PRT("expt %u, poll %d recv: %u!\n", expt, i, recv);
|
||||
- count += recv;
|
||||
- recv = 0;
|
||||
- if (unlikely(ret != -WD_EAGAIN && ret < 0)) {
|
||||
- SEC_TST_PRT("poll ret: %u!\n", ret);
|
||||
- goto recv_error;
|
||||
- }
|
||||
+ ret = uadk_poll_ctx(id, expt, &recv);
|
||||
+ // SEC_TST_PRT("expt %u, poll %d recv: %u!\n", expt, i, recv);
|
||||
+ count += recv;
|
||||
+ recv = 0;
|
||||
+ if (unlikely(ret != -WD_EAGAIN && ret < 0)) {
|
||||
+ SEC_TST_PRT("poll ret: %u!\n", ret);
|
||||
+ goto recv_error;
|
||||
}
|
||||
|
||||
if (get_run_state() == 0)
|
||||
@@ -989,7 +990,7 @@ int sec_uadk_async_threads(struct acc_option *options)
|
||||
thread_data threads_args[THREADS_NUM];
|
||||
thread_data threads_option;
|
||||
pthread_t tdid[THREADS_NUM];
|
||||
- pthread_t pollid;
|
||||
+ pthread_t pollid[THREADS_NUM];
|
||||
int i, ret;
|
||||
|
||||
/* alg param parse and set to thread data */
|
||||
@@ -998,10 +999,14 @@ int sec_uadk_async_threads(struct acc_option *options)
|
||||
return ret;
|
||||
|
||||
/* poll thread */
|
||||
- ret = pthread_create(&pollid, NULL, sec_uadk_poll, &threads_option);
|
||||
- if (ret) {
|
||||
- SEC_TST_PRT("Create poll thread fail!\n");
|
||||
- goto async_error;
|
||||
+ for (i = 0; i < g_ctxnum; i++) {
|
||||
+ threads_args[i].subtype = threads_option.subtype;
|
||||
+ threads_args[i].td_id = i;
|
||||
+ ret = pthread_create(&pollid, NULL, sec_uadk_poll, &threads_args[i]);
|
||||
+ if (ret) {
|
||||
+ SEC_TST_PRT("Create poll thread fail!\n");
|
||||
+ goto async_error;
|
||||
+ }
|
||||
}
|
||||
|
||||
for (i = 0; i < g_thread_num; i++) {
|
||||
@@ -1028,10 +1033,12 @@ int sec_uadk_async_threads(struct acc_option *options)
|
||||
}
|
||||
}
|
||||
|
||||
- ret = pthread_join(pollid, NULL);
|
||||
- if (ret) {
|
||||
- SEC_TST_PRT("Join poll thread fail!\n");
|
||||
- goto async_error;
|
||||
+ for (i = 0; i < g_ctxnum; i++) {
|
||||
+ ret = pthread_join(pollid[i], NULL);
|
||||
+ if (ret) {
|
||||
+ SEC_TST_PRT("Join poll thread fail!\n");
|
||||
+ goto async_error;
|
||||
+ }
|
||||
}
|
||||
|
||||
async_error:
|
||||
diff --git a/uadk_tool/sec_wd_benchmark.c b/uadk_tool/sec_wd_benchmark.c
|
||||
index dffd3a7..74b106e 100644
|
||||
--- a/uadk_tool/sec_wd_benchmark.c
|
||||
+++ b/uadk_tool/sec_wd_benchmark.c
|
||||
@@ -200,13 +200,13 @@ static int sec_wd_param_parse(thread_data *tddata, struct acc_option *options)
|
||||
break;
|
||||
case DES3_128_ECB:
|
||||
keysize = 16;
|
||||
- ivsize = 8;
|
||||
+ ivsize = 0;
|
||||
mode = WCRYPTO_CIPHER_ECB;
|
||||
alg = WCRYPTO_CIPHER_3DES;
|
||||
break;
|
||||
case DES3_192_ECB:
|
||||
keysize = 24;
|
||||
- ivsize = 8;
|
||||
+ ivsize = 0;
|
||||
mode = WCRYPTO_CIPHER_ECB;
|
||||
alg = WCRYPTO_CIPHER_3DES;
|
||||
break;
|
||||
@@ -224,7 +224,7 @@ static int sec_wd_param_parse(thread_data *tddata, struct acc_option *options)
|
||||
break;
|
||||
case SM4_128_ECB:
|
||||
keysize = 16;
|
||||
- ivsize = 16;
|
||||
+ ivsize = 0;
|
||||
mode = WCRYPTO_CIPHER_ECB;
|
||||
alg = WCRYPTO_CIPHER_SM4;
|
||||
break;
|
||||
@@ -253,7 +253,7 @@ static int sec_wd_param_parse(thread_data *tddata, struct acc_option *options)
|
||||
alg = WCRYPTO_CIPHER_SM4;
|
||||
break;
|
||||
case SM4_128_XTS:
|
||||
- keysize = 16;
|
||||
+ keysize = 32;
|
||||
ivsize = 16;
|
||||
mode = WCRYPTO_CIPHER_XTS;
|
||||
alg = WCRYPTO_CIPHER_SM4;
|
||||
@@ -525,9 +525,9 @@ void *sec_wd_poll(void *data)
|
||||
poll_ctx uadk_poll_ctx = NULL;
|
||||
u32 expt = ACC_QUEUE_SIZE * g_thread_num;
|
||||
u32 last_time = 2; /* poll need one more recv time */
|
||||
+ u32 id = pdata->td_id;
|
||||
u32 count = 0;
|
||||
u32 recv = 0;
|
||||
- u32 i = 0;
|
||||
|
||||
switch(pdata->subtype) {
|
||||
case CIPHER_TYPE:
|
||||
@@ -544,20 +544,21 @@ void *sec_wd_poll(void *data)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+ if (id > g_thread_num)
|
||||
+ return NULL;
|
||||
+
|
||||
while (last_time) {
|
||||
- for (i = 0; i < g_thread_num; i++) {
|
||||
- recv = uadk_poll_ctx(g_thread_queue.bd_res[i].queue, expt);
|
||||
- /*
|
||||
- * warpdrive async mode poll easy to 100% with small package.
|
||||
- * SEC_TST_PRT("warpdrive poll %d recv: %u!\n", i, recv);
|
||||
- */
|
||||
- if (unlikely(recv < 0)) {
|
||||
- SEC_TST_PRT("poll ret: %u!\n", recv);
|
||||
- goto recv_error;
|
||||
- }
|
||||
- count += recv;
|
||||
- recv = 0;
|
||||
+ recv = uadk_poll_ctx(g_thread_queue.bd_res[id].queue, expt);
|
||||
+ /*
|
||||
+ * warpdrive async mode poll easy to 100% with small package.
|
||||
+ * SEC_TST_PRT("warpdrive poll %d recv: %u!\n", i, recv);
|
||||
+ */
|
||||
+ if (unlikely(recv < 0)) {
|
||||
+ SEC_TST_PRT("poll ret: %u!\n", recv);
|
||||
+ goto recv_error;
|
||||
}
|
||||
+ count += recv;
|
||||
+ recv = 0;
|
||||
|
||||
if (get_run_state() == 0)
|
||||
last_time--;
|
||||
@@ -1186,7 +1187,7 @@ int sec_wd_async_threads(struct acc_option *options)
|
||||
thread_data threads_args[THREADS_NUM];
|
||||
thread_data threads_option;
|
||||
pthread_t tdid[THREADS_NUM];
|
||||
- pthread_t pollid;
|
||||
+ pthread_t pollid[THREADS_NUM];
|
||||
int i, ret;
|
||||
|
||||
/* alg param parse and set to thread data */
|
||||
@@ -1195,10 +1196,14 @@ int sec_wd_async_threads(struct acc_option *options)
|
||||
return ret;
|
||||
|
||||
/* poll thread */
|
||||
- ret = pthread_create(&pollid, NULL, sec_wd_poll, &threads_option);
|
||||
- if (ret) {
|
||||
- SEC_TST_PRT("Create poll thread fail!\n");
|
||||
- goto async_error;
|
||||
+ for (i = 0; i < g_thread_num; i++) {
|
||||
+ threads_args[i].subtype = threads_option.subtype;
|
||||
+ threads_args[i].td_id = i;
|
||||
+ ret = pthread_create(&pollid[i], NULL, sec_wd_poll, &threads_args[i]);
|
||||
+ if (ret) {
|
||||
+ SEC_TST_PRT("Create poll thread fail!\n");
|
||||
+ goto async_error;
|
||||
+ }
|
||||
}
|
||||
|
||||
for (i = 0; i < g_thread_num; i++) {
|
||||
@@ -1225,10 +1230,12 @@ int sec_wd_async_threads(struct acc_option *options)
|
||||
}
|
||||
}
|
||||
|
||||
- ret = pthread_join(pollid, NULL);
|
||||
- if (ret) {
|
||||
- SEC_TST_PRT("Join poll thread fail!\n");
|
||||
- goto async_error;
|
||||
+ for (i = 0; i < g_thread_num; i++) {
|
||||
+ ret = pthread_join(pollid[i], NULL);
|
||||
+ if (ret) {
|
||||
+ SEC_TST_PRT("Join poll thread fail!\n");
|
||||
+ goto async_error;
|
||||
+ }
|
||||
}
|
||||
|
||||
async_error:
|
||||
diff --git a/uadk_tool/uadk_benchmark.c b/uadk_tool/uadk_benchmark.c
|
||||
index 0d7fc71..8c3c96f 100644
|
||||
--- a/uadk_tool/uadk_benchmark.c
|
||||
+++ b/uadk_tool/uadk_benchmark.c
|
||||
@@ -271,7 +271,7 @@ int get_rand_int(int range)
|
||||
ACC_TST_PRT("rand range error!\n");
|
||||
return 1;
|
||||
}
|
||||
- srand((unsigned) time(NULL) * getpid());
|
||||
+ srand((unsigned)time(NULL) * getpid());
|
||||
randnum = rand() % range;
|
||||
|
||||
return randnum;
|
||||
@@ -281,7 +281,7 @@ void get_rand_data(u8 *addr, int size)
|
||||
{
|
||||
int i;
|
||||
|
||||
- srand((unsigned) time(NULL) * getpid());
|
||||
+ srand((unsigned)time(NULL) * getpid());
|
||||
for (i = 0; i < size; i++) {
|
||||
addr[i] = rand() % 0xFF;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
From a1f58e62ddb6419f50bfb3ae743d6db39533a42c Mon Sep 17 00:00:00 2001
|
||||
From: Liulongfang <liulongfang@foxmail.com>
|
||||
Date: Wed, 23 Feb 2022 10:36:09 +0800
|
||||
Subject: [PATCH 72/76] uadk/tools: modify uadk benchmark clean code
|
||||
|
||||
modify uadk benchmark thread create warning
|
||||
|
||||
Signed-off-by: Liulongfang <liulongfang@foxmail.com>
|
||||
---
|
||||
uadk_tool/sec_uadk_benchmark.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/uadk_tool/sec_uadk_benchmark.c b/uadk_tool/sec_uadk_benchmark.c
|
||||
index 467e621..6eeee12 100644
|
||||
--- a/uadk_tool/sec_uadk_benchmark.c
|
||||
+++ b/uadk_tool/sec_uadk_benchmark.c
|
||||
@@ -1002,7 +1002,7 @@ int sec_uadk_async_threads(struct acc_option *options)
|
||||
for (i = 0; i < g_ctxnum; i++) {
|
||||
threads_args[i].subtype = threads_option.subtype;
|
||||
threads_args[i].td_id = i;
|
||||
- ret = pthread_create(&pollid, NULL, sec_uadk_poll, &threads_args[i]);
|
||||
+ ret = pthread_create(&pollid[i], NULL, sec_uadk_poll, &threads_args[i]);
|
||||
if (ret) {
|
||||
SEC_TST_PRT("Create poll thread fail!\n");
|
||||
goto async_error;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,55 +0,0 @@
|
||||
From 4b10036f1504396fd61fac2ada45c8bc84cfd77e Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 24 Feb 2022 11:22:26 +0800
|
||||
Subject: [PATCH 73/76] uadk: v1: fix for cookie initialization
|
||||
|
||||
If ctx message number is too big, it takes a lot of time
|
||||
to initialize each cookies and drag performance, so this
|
||||
patch reduce it from 1024 to 64.
|
||||
We also found calloc in wd_init_cookie_pool use to much cpu
|
||||
when it does memset zero, which is not unnecessary, so
|
||||
replace it with malloc is better.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
v1/wd_util.c | 7 ++++---
|
||||
v1/wd_util.h | 2 +-
|
||||
2 files changed, 5 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/v1/wd_util.c b/v1/wd_util.c
|
||||
index 616bf69..715804c 100644
|
||||
--- a/v1/wd_util.c
|
||||
+++ b/v1/wd_util.c
|
||||
@@ -85,12 +85,13 @@ void wd_free_id(__u8 *buf, __u32 size, __u32 id, __u32 id_max)
|
||||
int wd_init_cookie_pool(struct wd_cookie_pool *pool,
|
||||
__u32 cookies_size, __u32 cookies_num)
|
||||
{
|
||||
- pool->cookies = calloc(1, cookies_size * cookies_num + cookies_num);
|
||||
+ __u64 total_size = cookies_size * cookies_num;
|
||||
+
|
||||
+ pool->cookies = malloc(total_size + cookies_num);
|
||||
if (!pool->cookies)
|
||||
return -WD_ENOMEM;
|
||||
|
||||
- pool->cstatus = (void *)((uintptr_t)pool->cookies +
|
||||
- cookies_num * cookies_size);
|
||||
+ pool->cstatus = (void *)((uintptr_t)pool->cookies + total_size);
|
||||
pool->cookies_num = cookies_num;
|
||||
pool->cookies_size = cookies_size;
|
||||
pool->cid = 0;
|
||||
diff --git a/v1/wd_util.h b/v1/wd_util.h
|
||||
index 1ac157e..78b91ee 100644
|
||||
--- a/v1/wd_util.h
|
||||
+++ b/v1/wd_util.h
|
||||
@@ -36,7 +36,7 @@
|
||||
#include "v1/wd_ecc.h"
|
||||
#include "v1/wd_adapter.h"
|
||||
|
||||
-#define WD_CTX_MSG_NUM 1024
|
||||
+#define WD_CTX_MSG_NUM 64
|
||||
#define WD_HPRE_CTX_MSG_NUM 64
|
||||
#define WD_RNG_CTX_MSG_NUM 256
|
||||
#define WD_MAX_CTX_NUM 256
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
From f9f3fc6a1de8e20680ef4c5c0efd98c7d503b87b Mon Sep 17 00:00:00 2001
|
||||
From: Haojian Zhuang <haojian.zhuang@linaro.org>
|
||||
Date: Wed, 23 Feb 2022 15:36:10 +0800
|
||||
Subject: [PATCH 74/76] uadk: update file permission on cleanup
|
||||
|
||||
Set execution permission on cleanup.sh.
|
||||
|
||||
Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>
|
||||
---
|
||||
cleanup.sh | 0
|
||||
1 file changed, 0 insertions(+), 0 deletions(-)
|
||||
mode change 100644 => 100755 cleanup.sh
|
||||
|
||||
diff --git a/cleanup.sh b/cleanup.sh
|
||||
old mode 100644
|
||||
new mode 100755
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,58 +0,0 @@
|
||||
From 42a496b15f685a8b3d763fe779cea17346e2116d Mon Sep 17 00:00:00 2001
|
||||
From: Zhangfei Gao <zhangfei.gao@linaro.org>
|
||||
Date: Wed, 23 Feb 2022 06:39:14 +0000
|
||||
Subject: [PATCH 75/76] uadk_tool: fix build warning of sec_wd_benchmark
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
Fix build warning:
|
||||
In file included from sec_wd_benchmark.c:3:
|
||||
uadk_benchmark.h:168:31: note: expected ‘u8 *’ {aka ‘unsigned char *’} but argument is of type ‘char *’
|
||||
168 | extern void get_rand_data(u8 *addr, int size);
|
||||
| ~~~~^~~~
|
||||
|
||||
sec_wd_benchmark.c: In function ‘sec_wd_async_run’:
|
||||
sec_wd_benchmark.c:613:16: warning: pointer targets in passing argument 1 of ‘get_rand_data’ differ in signedness [-Wpointer-sign]
|
||||
613 | get_rand_data(src_data_buf, g_pktlen);
|
||||
| ^~~~~~~~~~~~
|
||||
| |
|
||||
| char *
|
||||
|
||||
sec_wd_benchmark.c: In function ‘sec_wd_sync_run’:
|
||||
sec_wd_benchmark.c:913:16: warning: pointer targets in passing argument 1 of ‘get_rand_data’ differ in signedness [-Wpointer-sign]
|
||||
913 | get_rand_data(src_data_buf, g_pktlen);
|
||||
| ^~~~~~~~~~~~
|
||||
| |
|
||||
| char *
|
||||
|
||||
Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
|
||||
---
|
||||
uadk_tool/sec_wd_benchmark.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/uadk_tool/sec_wd_benchmark.c b/uadk_tool/sec_wd_benchmark.c
|
||||
index 74b106e..2e9c55d 100644
|
||||
--- a/uadk_tool/sec_wd_benchmark.c
|
||||
+++ b/uadk_tool/sec_wd_benchmark.c
|
||||
@@ -610,7 +610,7 @@ static void *sec_wd_async_run(void *arg)
|
||||
if (!src_data_buf)
|
||||
return NULL;
|
||||
|
||||
- get_rand_data(src_data_buf, g_pktlen);
|
||||
+ get_rand_data((u8 *)src_data_buf, g_pktlen);
|
||||
out_data_buf = malloc(g_pktlen * sizeof(char));
|
||||
if (!out_data_buf) {
|
||||
free(src_data_buf);
|
||||
@@ -910,7 +910,7 @@ static void *sec_wd_sync_run(void *arg)
|
||||
if (!src_data_buf)
|
||||
return NULL;
|
||||
|
||||
- get_rand_data(src_data_buf, g_pktlen);
|
||||
+ get_rand_data((u8 *)src_data_buf, g_pktlen);
|
||||
out_data_buf = malloc(g_pktlen * sizeof(char));
|
||||
if (!out_data_buf) {
|
||||
free(src_data_buf);
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -1,86 +0,0 @@
|
||||
From 0bcb18fc0c90e6e1ad10a457de5765e7ff609be7 Mon Sep 17 00:00:00 2001
|
||||
From: Junchong Pan <panjunchong@hisilicon.com>
|
||||
Date: Wed, 2 Mar 2022 07:15:19 +0000
|
||||
Subject: [PATCH 077/109] rsa: fix interface name and log msg
|
||||
|
||||
wd_rsa_key_bits() is used to get key bits,
|
||||
changing its name to wd_rsa_get_key_bits()
|
||||
can make the semantics clearer.
|
||||
|
||||
Signed-off-by: Junchong Pan <panjunchong@hisilicon.com>
|
||||
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
---
|
||||
include/wd_rsa.h | 2 +-
|
||||
test/hisi_hpre_test/test_hisi_hpre.c | 6 +++---
|
||||
wd_rsa.c | 4 ++--
|
||||
3 files changed, 6 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/include/wd_rsa.h b/include/wd_rsa.h
|
||||
index 081bc2a..0978b79 100644
|
||||
--- a/include/wd_rsa.h
|
||||
+++ b/include/wd_rsa.h
|
||||
@@ -67,7 +67,7 @@ struct wd_rsa_sess_setup {
|
||||
};
|
||||
|
||||
bool wd_rsa_is_crt(handle_t sess);
|
||||
-__u32 wd_rsa_key_bits(handle_t sess);
|
||||
+__u32 wd_rsa_get_key_bits(handle_t sess);
|
||||
void wd_rsa_get_pubkey(handle_t sess, struct wd_rsa_pubkey **pubkey);
|
||||
void wd_rsa_get_prikey(handle_t sess, struct wd_rsa_prikey **prikey);
|
||||
int wd_rsa_set_pubkey_params(handle_t sess, struct wd_dtb *e, struct wd_dtb *n);
|
||||
diff --git a/test/hisi_hpre_test/test_hisi_hpre.c b/test/hisi_hpre_test/test_hisi_hpre.c
|
||||
index 924adb7..57d76fd 100644
|
||||
--- a/test/hisi_hpre_test/test_hisi_hpre.c
|
||||
+++ b/test/hisi_hpre_test/test_hisi_hpre.c
|
||||
@@ -6793,7 +6793,7 @@ static int get_rsa_key_from_test_sample(handle_t sess, char *pubkey_file,
|
||||
memset(&wd_q, 0, sizeof(wd_q));
|
||||
memset(&wd_p, 0, sizeof(wd_p));
|
||||
|
||||
- bits = wd_rsa_key_bits(sess);
|
||||
+ bits = wd_rsa_get_key_bits(sess);
|
||||
if (bits == 1024) {
|
||||
e = rsa_e_1024;
|
||||
p = rsa_p_1024;
|
||||
@@ -7348,7 +7348,7 @@ int hpre_test_result_check(handle_t sess, struct wd_rsa_req *req, void *key)
|
||||
}
|
||||
|
||||
wd_rsa_get_prikey(sess, &prikey);
|
||||
- keybits = wd_rsa_key_bits(sess);
|
||||
+ keybits = wd_rsa_get_key_bits(sess);
|
||||
key_size = keybits >> 3;
|
||||
if (req->op_type == WD_RSA_GENKEY) {
|
||||
if (wd_rsa_is_crt(sess)) {
|
||||
@@ -7907,7 +7907,7 @@ static void _rsa_cb(void *req_t)
|
||||
struct test_hpre_pthread_dt *thread_info = tag->thread_info;
|
||||
|
||||
wd_rsa_get_prikey(sess, &prikey);
|
||||
- keybits = wd_rsa_key_bits(sess);
|
||||
+ keybits = wd_rsa_get_key_bits(sess);
|
||||
key_size = keybits >> 3;
|
||||
|
||||
thread_info->recv_task_num++;
|
||||
diff --git a/wd_rsa.c b/wd_rsa.c
|
||||
index 2e61927..4c8fd71 100644
|
||||
--- a/wd_rsa.c
|
||||
+++ b/wd_rsa.c
|
||||
@@ -599,7 +599,7 @@ struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess)
|
||||
|
||||
kg_out = malloc(kg_out_size + sizeof(*kg_out));
|
||||
if (!kg_out) {
|
||||
- WD_ERR("sess malloc kg_in memory fail!\n");
|
||||
+ WD_ERR("sess malloc kg_out memory fail!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -875,7 +875,7 @@ bool wd_rsa_is_crt(handle_t sess)
|
||||
return ((struct wd_rsa_sess *)sess)->setup.is_crt;
|
||||
}
|
||||
|
||||
-__u32 wd_rsa_key_bits(handle_t sess)
|
||||
+__u32 wd_rsa_get_key_bits(handle_t sess)
|
||||
{
|
||||
if (!sess) {
|
||||
WD_ERR("get rsa key bits, sess NULL!\n");
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,127 +0,0 @@
|
||||
From f15516b66eb92d0c9a90532eb23c96e93a14ee10 Mon Sep 17 00:00:00 2001
|
||||
From: Junchong Pan <panjunchong@hisilicon.com>
|
||||
Date: Wed, 2 Mar 2022 07:25:49 +0000
|
||||
Subject: [PATCH 078/109] uadk: modify param verification
|
||||
|
||||
When config->ctxs[0] is NULL, take ctxs[0].ctx
|
||||
may cause a crash, so check config->ctxs[0] when
|
||||
performing init param check.
|
||||
|
||||
Signed-off-by: Junchong Pan <panjunchong@hisilicon.com>
|
||||
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
---
|
||||
v1/wd_sgl.c | 4 ++--
|
||||
wd_aead.c | 2 +-
|
||||
wd_cipher.c | 2 +-
|
||||
wd_comp.c | 5 ++---
|
||||
wd_dh.c | 2 +-
|
||||
wd_digest.c | 2 +-
|
||||
wd_ecc.c | 2 +-
|
||||
7 files changed, 9 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/v1/wd_sgl.c b/v1/wd_sgl.c
|
||||
index 97edbf4..9995d69 100644
|
||||
--- a/v1/wd_sgl.c
|
||||
+++ b/v1/wd_sgl.c
|
||||
@@ -516,8 +516,8 @@ void wd_free_sgl(void *pool, struct wd_sgl *sgl)
|
||||
struct wd_sgl *next;
|
||||
int i;
|
||||
|
||||
- if (unlikely(!p || !sgl)) {
|
||||
- WD_ERR("pool or sgl is null!\n");
|
||||
+ if (unlikely(!p || !sgl || !p->sgl_pool)) {
|
||||
+ WD_ERR("pool or sgl or p->sgl_pool is null!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index d8581db..a78f152 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -392,7 +392,7 @@ static int aead_param_check(struct wd_aead_sess *sess,
|
||||
|
||||
static int aead_init_check(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- if (!config || !sched) {
|
||||
+ if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) {
|
||||
WD_ERR("wd aead config or sched is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index 0b29fb5..8daac0f 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -157,7 +157,7 @@ static int cipher_key_len_check(struct wd_cipher_sess *sess, __u32 length)
|
||||
static int cipher_init_check(struct wd_ctx_config *config,
|
||||
struct wd_sched *sched)
|
||||
{
|
||||
- if (!config || !sched) {
|
||||
+ if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) {
|
||||
WD_ERR("wd cipher config or sched is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
diff --git a/wd_comp.c b/wd_comp.c
|
||||
index 722666d..886e6fc 100644
|
||||
--- a/wd_comp.c
|
||||
+++ b/wd_comp.c
|
||||
@@ -87,7 +87,7 @@ int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
void *priv;
|
||||
int ret;
|
||||
|
||||
- if (!config || !sched) {
|
||||
+ if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) {
|
||||
WD_ERR("invalid params, config or sched is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -223,8 +223,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
||||
req = &msg->req;
|
||||
req->src_len = msg->in_cons;
|
||||
req->dst_len = msg->produced;
|
||||
- if (req->cb)
|
||||
- req->cb(req, req->cb_param);
|
||||
+ req->cb(req, req->cb_param);
|
||||
|
||||
/* free msg cache to msg_pool */
|
||||
wd_put_msg_to_pool(&wd_comp_setting.pool, idx, resp_msg.tag);
|
||||
diff --git a/wd_dh.c b/wd_dh.c
|
||||
index b361d5d..841a126 100644
|
||||
--- a/wd_dh.c
|
||||
+++ b/wd_dh.c
|
||||
@@ -80,7 +80,7 @@ void wd_dh_set_driver(struct wd_dh_driver *drv)
|
||||
|
||||
static int param_check(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- if (!config || !config->ctxs[0].ctx || !sched) {
|
||||
+ if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) {
|
||||
WD_ERR("config or sched NULL\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index 1c05851..21c3876 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -154,7 +154,7 @@ void wd_digest_free_sess(handle_t h_sess)
|
||||
|
||||
static int digest_init_check(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- if (!config || !sched) {
|
||||
+ if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) {
|
||||
WD_ERR("failed to check input param!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
diff --git a/wd_ecc.c b/wd_ecc.c
|
||||
index 89566ea..3232e67 100644
|
||||
--- a/wd_ecc.c
|
||||
+++ b/wd_ecc.c
|
||||
@@ -134,7 +134,7 @@ void wd_ecc_set_driver(struct wd_ecc_driver *drv)
|
||||
|
||||
static int init_param_check(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
- if (!config || !config->ctxs[0].ctx || !sched) {
|
||||
+ if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) {
|
||||
WD_ERR("config or sched NULL\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,38 +0,0 @@
|
||||
From e0451ee34c5d5c258fbb359a89a7a925ace7efa4 Mon Sep 17 00:00:00 2001
|
||||
From: Junchong Pan <panjunchong@hisilicon.com>
|
||||
Date: Fri, 4 Mar 2022 01:56:08 +0000
|
||||
Subject: [PATCH 079/109] uadk/v1: cleanup ret value
|
||||
|
||||
It is unnecessary to initialize variable 'ret' and
|
||||
return it when the function is executed successfully,
|
||||
so remove 'ret'.
|
||||
|
||||
Signed-off-by: Junchong Pan <panjunchong@hisilicon.com>
|
||||
---
|
||||
v1/wd_aead.c | 3 +--
|
||||
1 file changed, 1 insertion(+), 2 deletions(-)
|
||||
|
||||
diff --git a/v1/wd_aead.c b/v1/wd_aead.c
|
||||
index ad22426..6d8c541 100644
|
||||
--- a/v1/wd_aead.c
|
||||
+++ b/v1/wd_aead.c
|
||||
@@ -263,7 +263,6 @@ free_ctx_id:
|
||||
int wcrypto_aead_setauthsize(void *ctx, __u16 authsize)
|
||||
{
|
||||
struct wcrypto_aead_ctx *ctxt = ctx;
|
||||
- int ret = WD_SUCCESS;
|
||||
|
||||
if (!ctx) {
|
||||
WD_ERR("input param is NULL!\n");
|
||||
@@ -277,7 +276,7 @@ int wcrypto_aead_setauthsize(void *ctx, __u16 authsize)
|
||||
|
||||
ctxt->auth_size = authsize;
|
||||
|
||||
- return ret;
|
||||
+ return WD_SUCCESS;
|
||||
}
|
||||
|
||||
int wcrypto_aead_getauthsize(void *ctx)
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,46 +0,0 @@
|
||||
From f5f79ed6d426809ef7ad4dc06bbdf7d2ba1bd9bc Mon Sep 17 00:00:00 2001
|
||||
From: Junchong Pan <panjunchong@hisilicon.com>
|
||||
Date: Fri, 4 Mar 2022 02:22:19 +0000
|
||||
Subject: [PATCH 080/109] uadk/wd: fixup about checking device
|
||||
|
||||
Add non-empty check for ctx->dev.
|
||||
|
||||
Signed-off-by: Junchong Pan <panjunchong@hisilicon.com>
|
||||
---
|
||||
wd.c | 6 +++---
|
||||
1 file changed, 3 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/wd.c b/wd.c
|
||||
index 565c173..b88ee62 100644
|
||||
--- a/wd.c
|
||||
+++ b/wd.c
|
||||
@@ -480,7 +480,7 @@ char *wd_ctx_get_api(handle_t h_ctx)
|
||||
{
|
||||
struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
|
||||
|
||||
- if (!ctx)
|
||||
+ if (!ctx || !ctx->dev)
|
||||
return NULL;
|
||||
|
||||
return ctx->dev->api;
|
||||
@@ -508,7 +508,7 @@ int wd_is_sva(handle_t h_ctx)
|
||||
{
|
||||
struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
|
||||
|
||||
- if (!ctx)
|
||||
+ if (!ctx || !ctx->dev)
|
||||
return -WD_EINVAL;
|
||||
|
||||
if ((unsigned int)ctx->dev->flags & UACCE_DEV_SVA)
|
||||
@@ -521,7 +521,7 @@ int wd_get_numa_id(handle_t h_ctx)
|
||||
{
|
||||
struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
|
||||
|
||||
- if (!ctx)
|
||||
+ if (!ctx || !ctx->dev)
|
||||
return -WD_EINVAL;
|
||||
|
||||
return ctx->dev->numa_id;
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,347 +0,0 @@
|
||||
From 50b68c0405544702181deb9dda28381169b17d09 Mon Sep 17 00:00:00 2001
|
||||
From: Junchong Pan <panjunchong@hisilicon.com>
|
||||
Date: Fri, 4 Mar 2022 02:25:54 +0000
|
||||
Subject: [PATCH 081/109] uadk: cleanup hpre code
|
||||
|
||||
Includes:
|
||||
1.Remove useless interface param.
|
||||
2.Remove ASSERT.
|
||||
3.Remove print address.
|
||||
|
||||
Signed-off-by: Junchong Pan <panjunchong@hisilicon.com>
|
||||
---
|
||||
drv/hisi_hpre.c | 26 +++++++++++++++-------
|
||||
drv/hisi_qm_udrv.c | 2 --
|
||||
v1/drv/hisi_hpre_udrv.c | 48 ++++++++++++++++++++++++++++-------------
|
||||
v1/wd_ecc.c | 24 ++++++++++-----------
|
||||
wd_ecc.c | 24 ++++++++++-----------
|
||||
5 files changed, 75 insertions(+), 49 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
|
||||
index fbb38e0..f1d7720 100644
|
||||
--- a/drv/hisi_hpre.c
|
||||
+++ b/drv/hisi_hpre.c
|
||||
@@ -127,7 +127,7 @@ static bool is_hpre_bin_fmt(const char *data, int dsz, int bsz)
|
||||
}
|
||||
|
||||
static int crypto_bin_to_hpre_bin(char *dst, const char *src,
|
||||
- int b_size, int d_size, const char *p_name)
|
||||
+ __u32 b_size, __u32 d_size, const char *p_name)
|
||||
{
|
||||
int i = d_size - 1;
|
||||
bool is_hpre_bin;
|
||||
@@ -1469,6 +1469,11 @@ static struct wd_ecc_out *create_ecdh_out(struct wd_ecc_msg *msg)
|
||||
struct wd_ecc_dh_out *dh_out;
|
||||
struct wd_ecc_out *out;
|
||||
|
||||
+ if (!hsz) {
|
||||
+ WD_ERR("get msg key size error!\n");
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
out = malloc(len);
|
||||
if (!out) {
|
||||
WD_ERR("failed to alloc, sz = %u!\n", len);
|
||||
@@ -1601,6 +1606,11 @@ static int ecc_fill(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
+ if (!hw_sz) {
|
||||
+ WD_ERR("get msg key size error!\n");
|
||||
+ return -WD_EINVAL;
|
||||
+ }
|
||||
+
|
||||
memset(hw_msg, 0, sizeof(*hw_msg));
|
||||
|
||||
/* prepare algorithm */
|
||||
@@ -1646,7 +1656,7 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
|
||||
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
||||
struct wd_sm2_enc_in *ein = msg->req.src;
|
||||
struct wd_ecc_msg *msg_dst[2] = {NULL};
|
||||
- struct hisi_hpre_sqe hw_msg[2] = {{0}};
|
||||
+ struct hisi_hpre_sqe hw_msg[2] = {0};
|
||||
struct wd_hash_mt *hash = &msg->hash;
|
||||
__u16 send_cnt = 0;
|
||||
int ret;
|
||||
@@ -1918,7 +1928,7 @@ static __u32 get_hash_bytes(__u8 type)
|
||||
return val;
|
||||
}
|
||||
|
||||
-static void msg_pack(char *dst, __u64 dst_len, __u64 *out_len,
|
||||
+static void msg_pack(char *dst, __u64 *out_len,
|
||||
const void *src, __u32 src_len)
|
||||
{
|
||||
if (unlikely(!src || !src_len))
|
||||
@@ -1961,8 +1971,8 @@ static int sm2_kdf(struct wd_dtb *out, struct wd_ecc_point *x2y2,
|
||||
ctr[2] = (i >> 8) & 0xFF;
|
||||
ctr[1] = (i >> 16) & 0xFF;
|
||||
ctr[0] = (i >> 24) & 0xFF;
|
||||
- msg_pack(p_in, lens, &in_len, x2y2->x.data, x2y2_len);
|
||||
- msg_pack(p_in, lens, &in_len, ctr, sizeof(ctr));
|
||||
+ msg_pack(p_in, &in_len, x2y2->x.data, x2y2_len);
|
||||
+ msg_pack(p_in, &in_len, ctr, sizeof(ctr));
|
||||
|
||||
t_out = m_len >= h_bytes ? tmp : p_out;
|
||||
ret = hash->cb(p_in, in_len, t_out, h_bytes, hash->usr);
|
||||
@@ -2026,9 +2036,9 @@ static int sm2_hash(struct wd_dtb *out, struct wd_ecc_point *x2y2,
|
||||
if (unlikely(!p_in))
|
||||
return -WD_ENOMEM;
|
||||
|
||||
- msg_pack(p_in, lens, &in_len, x2y2->x.data, x2y2->x.dsize);
|
||||
- msg_pack(p_in, lens, &in_len, msg->data, msg->dsize);
|
||||
- msg_pack(p_in, lens, &in_len, x2y2->y.data, x2y2->y.dsize);
|
||||
+ msg_pack(p_in, &in_len, x2y2->x.data, x2y2->x.dsize);
|
||||
+ msg_pack(p_in, &in_len, msg->data, msg->dsize);
|
||||
+ msg_pack(p_in, &in_len, x2y2->y.data, x2y2->y.dsize);
|
||||
ret = hash->cb(p_in, in_len, hash_out, h_bytes, hash->usr);
|
||||
if (unlikely(ret)) {
|
||||
WD_ERR("failed to hash cb, ret = %d!\n", ret);
|
||||
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
|
||||
index 845fa46..2e692a1 100644
|
||||
--- a/drv/hisi_qm_udrv.c
|
||||
+++ b/drv/hisi_qm_udrv.c
|
||||
@@ -896,8 +896,6 @@ void hisi_qm_dump_sgl(void *sgl)
|
||||
int i;
|
||||
|
||||
while (tmp) {
|
||||
- WD_ERR("sgl = %p\n", tmp);
|
||||
- WD_ERR("sgl->next_dma : 0x%lx\n", tmp->next_dma);
|
||||
WD_ERR("sgl->entry_sum_in_chain : %u\n",
|
||||
tmp->entry_sum_in_chain);
|
||||
WD_ERR("sgl->entry_sum_in_sgl : %u\n",
|
||||
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c
|
||||
index c6ca0ad..ba32114 100644
|
||||
--- a/v1/drv/hisi_hpre_udrv.c
|
||||
+++ b/v1/drv/hisi_hpre_udrv.c
|
||||
@@ -499,7 +499,6 @@ int qm_fill_rsa_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
hw_msg->low_tag = tag->ctx_id;
|
||||
hw_msg->done = 0x1;
|
||||
hw_msg->etype = 0x0;
|
||||
- ASSERT(!info->req_cache[i]);
|
||||
info->req_cache[i] = msg;
|
||||
|
||||
return WD_SUCCESS;
|
||||
@@ -517,7 +516,10 @@ int qm_parse_rsa_sqe(void *msg, const struct qm_queue_info *info,
|
||||
__u16 kbytes;
|
||||
int ret;
|
||||
|
||||
- ASSERT(rsa_msg);
|
||||
+ if (unlikely(!rsa_msg)) {
|
||||
+ WD_ERR("info->req_cache is null at index:%hu\n", i);
|
||||
+ return 0;
|
||||
+ }
|
||||
|
||||
/* if this hardware message not belong to me, then try again */
|
||||
if (usr && LOW_U16(hw_msg->low_tag) != usr)
|
||||
@@ -700,7 +702,6 @@ int qm_fill_dh_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
if (unlikely(ret))
|
||||
goto map_xp_fail;
|
||||
}
|
||||
- ASSERT(!info->req_cache[i]);
|
||||
info->req_cache[i] = msg;
|
||||
|
||||
ret = qm_final_fill_dh_sqe(q, msg, hw_msg);
|
||||
@@ -726,7 +727,11 @@ int qm_parse_dh_sqe(void *msg, const struct qm_queue_info *info,
|
||||
struct wd_queue *q = info->q;
|
||||
int ret;
|
||||
|
||||
- ASSERT(dh_msg);
|
||||
+ if (unlikely(!dh_msg)) {
|
||||
+ WD_ERR("info->req_cache is null at index:%hu\n", i);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
if (usr && LOW_U16(hw_msg->low_tag) != usr)
|
||||
return 0;
|
||||
if (hw_msg->done != HPRE_HW_TASK_DONE || hw_msg->etype) {
|
||||
@@ -1668,7 +1673,6 @@ static int qm_fill_ecc_sqe_general(void *message, struct qm_queue_info *info,
|
||||
hw_msg->low_tag = tag->ctx_id;
|
||||
hw_msg->done = 0x1;
|
||||
hw_msg->etype = 0x0;
|
||||
- ASSERT(!info->req_cache[i]);
|
||||
info->req_cache[i] = msg;
|
||||
|
||||
return WD_SUCCESS;
|
||||
@@ -1942,6 +1946,7 @@ static int fill_sm2_dec_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
struct wd_mm_br *br = &qinfo->br;
|
||||
__u32 ksz = req_src->key_bytes;
|
||||
struct wcrypto_ecc_msg *dst;
|
||||
+ int ret;
|
||||
|
||||
/* c2 data lens <= 4096 bit */
|
||||
if (din->c2.dsize <= BITS_TO_BYTES(4096) &&
|
||||
@@ -1966,11 +1971,21 @@ static int fill_sm2_dec_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
dst->in = (void *)&din->c1;
|
||||
dst->out = br->alloc(br->usr, ECDH_OUT_PARAMS_SZ(ksz));
|
||||
if (unlikely(!dst->out)) {
|
||||
- free(dst);
|
||||
- return -WD_ENOMEM;
|
||||
+ ret = -WD_ENOMEM;
|
||||
+ goto free_dst;
|
||||
}
|
||||
|
||||
- return qm_fill_ecc_sqe_general(dst, info, i);
|
||||
+ ret = qm_fill_ecc_sqe_general(dst, info, i);
|
||||
+ if (ret)
|
||||
+ goto free_out;
|
||||
+
|
||||
+ return ret;
|
||||
+
|
||||
+free_out:
|
||||
+ br->free(br->usr, dst->out);
|
||||
+free_dst:
|
||||
+ free(dst);
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
int qm_fill_ecc_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
@@ -1997,7 +2012,10 @@ static int qm_parse_ecc_sqe_general(void *msg, const struct qm_queue_info *info,
|
||||
__u16 kbytes;
|
||||
int ret;
|
||||
|
||||
- ASSERT(ecc_msg);
|
||||
+ if (unlikely(!ecc_msg)) {
|
||||
+ WD_ERR("info->req_cache is null at index:%hu\n", i);
|
||||
+ return 0;
|
||||
+ }
|
||||
|
||||
/* if this hw msg not belong to me, then try again */
|
||||
if (usr && LOW_U16(hw_msg->low_tag) != usr)
|
||||
@@ -2146,7 +2164,7 @@ static __u32 get_hash_bytes(__u8 type)
|
||||
return val;
|
||||
}
|
||||
|
||||
-static void msg_pack(char *dst, __u64 dst_len, __u64 *out_len,
|
||||
+static void msg_pack(char *dst, __u64 *out_len,
|
||||
const void *src, __u32 src_len)
|
||||
{
|
||||
if (unlikely(!src || !src_len))
|
||||
@@ -2191,8 +2209,8 @@ static int sm2_kdf(struct wd_dtb *out, struct wcrypto_ecc_point *x2y2,
|
||||
ctr[1] = (i >> 16) & 0xFF;
|
||||
ctr[0] = (i >> 24) & 0xFF;
|
||||
in_len = 0;
|
||||
- msg_pack(p_in, lens, &in_len, x2y2->x.data, x2y2_len);
|
||||
- msg_pack(p_in, lens, &in_len, ctr, sizeof(ctr));
|
||||
+ msg_pack(p_in, &in_len, x2y2->x.data, x2y2_len);
|
||||
+ msg_pack(p_in, &in_len, ctr, sizeof(ctr));
|
||||
|
||||
t_out = m_len >= h_bytes ? tmp : p_out;
|
||||
ret = hash->cb(p_in, in_len, t_out, h_bytes, hash->usr);
|
||||
@@ -2257,9 +2275,9 @@ static int sm2_hash(struct wd_dtb *out, struct wcrypto_ecc_point *x2y2,
|
||||
if (unlikely(!p_in))
|
||||
return -WD_ENOMEM;
|
||||
|
||||
- msg_pack(p_in, lens, &in_len, x2y2->x.data, x2y2->x.dsize);
|
||||
- msg_pack(p_in, lens, &in_len, msg->data, msg->dsize);
|
||||
- msg_pack(p_in, lens, &in_len, x2y2->y.data, x2y2->y.dsize);
|
||||
+ msg_pack(p_in, &in_len, x2y2->x.data, x2y2->x.dsize);
|
||||
+ msg_pack(p_in, &in_len, msg->data, msg->dsize);
|
||||
+ msg_pack(p_in, &in_len, x2y2->y.data, x2y2->y.dsize);
|
||||
ret = hash->cb(p_in, in_len, hash_out, h_bytes, hash->usr);
|
||||
if (unlikely(ret)) {
|
||||
WD_ERR("failed to hash cb, ret = %d!\n", ret);
|
||||
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c
|
||||
index c710d8a..2358243 100644
|
||||
--- a/v1/wd_ecc.c
|
||||
+++ b/v1/wd_ecc.c
|
||||
@@ -1508,7 +1508,7 @@ static int ecc_request_init(struct wcrypto_ecc_msg *req,
|
||||
return WD_SUCCESS;
|
||||
}
|
||||
|
||||
-static void msg_pack(char *dst, __u64 dst_len, __u64 *out_len,
|
||||
+static void msg_pack(char *dst, __u64 *out_len,
|
||||
const void *src, __u32 src_len)
|
||||
{
|
||||
if (unlikely(!src || !src_len))
|
||||
@@ -1831,17 +1831,17 @@ static int sm2_compute_za_hash(__u8 *za, __u32 *len, struct wd_dtb *id,
|
||||
|
||||
memset(p_in, 0, lens);
|
||||
temp = id_bits >> 8;
|
||||
- msg_pack(p_in, lens, &in_len, &temp, sizeof(__u8));
|
||||
+ msg_pack(p_in, &in_len, &temp, sizeof(__u8));
|
||||
temp = id_bits & 0xFF;
|
||||
- msg_pack(p_in, lens, &in_len, &temp, sizeof(__u8));
|
||||
+ msg_pack(p_in, &in_len, &temp, sizeof(__u8));
|
||||
if (id)
|
||||
- msg_pack(p_in, lens, &in_len, id->data, id_bytes);
|
||||
- msg_pack(p_in, lens, &in_len, cv->a.data, key_size);
|
||||
- msg_pack(p_in, lens, &in_len, cv->b.data, key_size);
|
||||
- msg_pack(p_in, lens, &in_len, cv->g.x.data, key_size);
|
||||
- msg_pack(p_in, lens, &in_len, cv->g.y.data, key_size);
|
||||
- msg_pack(p_in, lens, &in_len, pub->x.data, key_size);
|
||||
- msg_pack(p_in, lens, &in_len, pub->y.data, key_size);
|
||||
+ msg_pack(p_in, &in_len, id->data, id_bytes);
|
||||
+ msg_pack(p_in, &in_len, cv->a.data, key_size);
|
||||
+ msg_pack(p_in, &in_len, cv->b.data, key_size);
|
||||
+ msg_pack(p_in, &in_len, cv->g.x.data, key_size);
|
||||
+ msg_pack(p_in, &in_len, cv->g.y.data, key_size);
|
||||
+ msg_pack(p_in, &in_len, pub->x.data, key_size);
|
||||
+ msg_pack(p_in, &in_len, pub->y.data, key_size);
|
||||
|
||||
hash_bytes = get_hash_bytes(hash->type);
|
||||
*len = hash_bytes;
|
||||
@@ -1885,8 +1885,8 @@ static int sm2_compute_digest(void *ctx, struct wd_dtb *hash_msg,
|
||||
|
||||
/* e = h(ZA || M) */
|
||||
memset(p_in, 0, lens);
|
||||
- msg_pack(p_in, lens, &in_len, za, za_len);
|
||||
- msg_pack(p_in, lens, &in_len, plaintext->data, plaintext->dsize);
|
||||
+ msg_pack(p_in, &in_len, za, za_len);
|
||||
+ msg_pack(p_in, &in_len, plaintext->data, plaintext->dsize);
|
||||
hash_msg->dsize = hash_bytes;
|
||||
ret = hash->cb((const char *)p_in, in_len, hash_msg->data,
|
||||
hash_bytes, hash->usr);
|
||||
diff --git a/wd_ecc.c b/wd_ecc.c
|
||||
index 3232e67..a9994b2 100644
|
||||
--- a/wd_ecc.c
|
||||
+++ b/wd_ecc.c
|
||||
@@ -1396,7 +1396,7 @@ static int fill_ecc_msg(struct wd_ecc_msg *msg, struct wd_ecc_req *req,
|
||||
return WD_SUCCESS;
|
||||
}
|
||||
|
||||
-static void msg_pack(char *dst, __u64 dst_len, __u64 *out_len,
|
||||
+static void msg_pack(char *dst, __u64 *out_len,
|
||||
const void *src, __u32 src_len)
|
||||
{
|
||||
if (!src || !src_len)
|
||||
@@ -1596,17 +1596,17 @@ static int sm2_compute_za_hash(__u8 *za, __u32 *len, struct wd_dtb *id,
|
||||
|
||||
memset(p_in, 0, lens);
|
||||
temp = id_bits >> 8;
|
||||
- msg_pack(p_in, lens, &in_len, &temp, sizeof(__u8));
|
||||
+ msg_pack(p_in, &in_len, &temp, sizeof(__u8));
|
||||
temp = id_bits & 0xFF;
|
||||
- msg_pack(p_in, lens, &in_len, &temp, sizeof(__u8));
|
||||
+ msg_pack(p_in, &in_len, &temp, sizeof(__u8));
|
||||
if (id)
|
||||
- msg_pack(p_in, lens, &in_len, id->data, id_bytes);
|
||||
- msg_pack(p_in, lens, &in_len, cv->a.data, key_size);
|
||||
- msg_pack(p_in, lens, &in_len, cv->b.data, key_size);
|
||||
- msg_pack(p_in, lens, &in_len, cv->g.x.data, key_size);
|
||||
- msg_pack(p_in, lens, &in_len, cv->g.y.data, key_size);
|
||||
- msg_pack(p_in, lens, &in_len, pub->x.data, key_size);
|
||||
- msg_pack(p_in, lens, &in_len, pub->y.data, key_size);
|
||||
+ msg_pack(p_in, &in_len, id->data, id_bytes);
|
||||
+ msg_pack(p_in, &in_len, cv->a.data, key_size);
|
||||
+ msg_pack(p_in, &in_len, cv->b.data, key_size);
|
||||
+ msg_pack(p_in, &in_len, cv->g.x.data, key_size);
|
||||
+ msg_pack(p_in, &in_len, cv->g.y.data, key_size);
|
||||
+ msg_pack(p_in, &in_len, pub->x.data, key_size);
|
||||
+ msg_pack(p_in, &in_len, pub->y.data, key_size);
|
||||
hash_bytes = get_hash_bytes(hash->type);
|
||||
*len = hash_bytes;
|
||||
ret = hash->cb((const char *)p_in, in_len,
|
||||
@@ -1649,8 +1649,8 @@ static int sm2_compute_digest(struct wd_ecc_sess *sess, struct wd_dtb *hash_msg,
|
||||
|
||||
/* e = h(ZA || M) */
|
||||
memset(p_in, 0, lens);
|
||||
- msg_pack(p_in, lens, &in_len, za, za_len);
|
||||
- msg_pack(p_in, lens, &in_len, plaintext->data, plaintext->dsize);
|
||||
+ msg_pack(p_in, &in_len, za, za_len);
|
||||
+ msg_pack(p_in, &in_len, plaintext->data, plaintext->dsize);
|
||||
hash_msg->dsize = hash_bytes;
|
||||
ret = hash->cb((const char *)p_in, in_len, hash_msg->data,
|
||||
hash_bytes, hash->usr);
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
From 1c72d89b848290814601517e73f6a9d8eb6e5caa Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 3 Mar 2022 15:10:04 +0800
|
||||
Subject: [PATCH 082/109] uadk: v1: fix pool cstatus memset problem
|
||||
|
||||
wd_alloc_id use __atomic_test_and_set to find
|
||||
an available cookie with zero status,
|
||||
it may not find a zero cookie with dirty memory,
|
||||
so cookie status region should be set to zero.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
v1/wd_util.c | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/v1/wd_util.c b/v1/wd_util.c
|
||||
index 715804c..112cc16 100644
|
||||
--- a/v1/wd_util.c
|
||||
+++ b/v1/wd_util.c
|
||||
@@ -92,6 +92,8 @@ int wd_init_cookie_pool(struct wd_cookie_pool *pool,
|
||||
return -WD_ENOMEM;
|
||||
|
||||
pool->cstatus = (void *)((uintptr_t)pool->cookies + total_size);
|
||||
+ memset(pool->cstatus, 0, cookies_num);
|
||||
+
|
||||
pool->cookies_num = cookies_num;
|
||||
pool->cookies_size = cookies_size;
|
||||
pool->cid = 0;
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,108 +0,0 @@
|
||||
From 1d20eaf8c0829531ab5cb4fc8ecd4142147b482d Mon Sep 17 00:00:00 2001
|
||||
From: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
Date: Wed, 9 Mar 2022 01:30:51 +0000
|
||||
Subject: [PATCH 084/109] uadk: bugfix segment fault when uninitializing
|
||||
|
||||
When the initialization of each alg driver failed,
|
||||
the wd_<alg>_setting.priv should be set to NULL.
|
||||
Otherwise there will be segment fault when
|
||||
uninitializing the alg driver.
|
||||
|
||||
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
|
||||
---
|
||||
wd_aead.c | 1 +
|
||||
wd_cipher.c | 1 +
|
||||
wd_comp.c | 1 +
|
||||
wd_dh.c | 1 +
|
||||
wd_digest.c | 1 +
|
||||
wd_ecc.c | 1 +
|
||||
wd_rsa.c | 1 +
|
||||
7 files changed, 7 insertions(+)
|
||||
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index a78f152..7df8e80 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -458,6 +458,7 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
|
||||
out_init:
|
||||
free(priv);
|
||||
+ wd_aead_setting.priv = NULL;
|
||||
out_priv:
|
||||
wd_uninit_async_request_pool(&wd_aead_setting.pool);
|
||||
out_sched:
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index 8daac0f..afd8c4d 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -299,6 +299,7 @@ int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
|
||||
out_init:
|
||||
free(priv);
|
||||
+ wd_cipher_setting.priv = NULL;
|
||||
out_priv:
|
||||
wd_uninit_async_request_pool(&wd_cipher_setting.pool);
|
||||
out_sched:
|
||||
diff --git a/wd_comp.c b/wd_comp.c
|
||||
index 886e6fc..8d0c603 100644
|
||||
--- a/wd_comp.c
|
||||
+++ b/wd_comp.c
|
||||
@@ -145,6 +145,7 @@ int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
|
||||
out_init:
|
||||
free(priv);
|
||||
+ wd_comp_setting.priv = NULL;
|
||||
out_priv:
|
||||
wd_uninit_async_request_pool(&wd_comp_setting.pool);
|
||||
out_sched:
|
||||
diff --git a/wd_dh.c b/wd_dh.c
|
||||
index 841a126..f5d70a2 100644
|
||||
--- a/wd_dh.c
|
||||
+++ b/wd_dh.c
|
||||
@@ -145,6 +145,7 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
|
||||
out_init:
|
||||
free(priv);
|
||||
+ wd_dh_setting.priv = NULL;
|
||||
out_priv:
|
||||
wd_uninit_async_request_pool(&wd_dh_setting.pool);
|
||||
out_sched:
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index 21c3876..06774be 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -220,6 +220,7 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
|
||||
out_init:
|
||||
free(priv);
|
||||
+ wd_digest_setting.priv = NULL;
|
||||
out_priv:
|
||||
wd_uninit_async_request_pool(&wd_digest_setting.pool);
|
||||
out_sched:
|
||||
diff --git a/wd_ecc.c b/wd_ecc.c
|
||||
index a9994b2..d925bc3 100644
|
||||
--- a/wd_ecc.c
|
||||
+++ b/wd_ecc.c
|
||||
@@ -199,6 +199,7 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
|
||||
out_init:
|
||||
free(priv);
|
||||
+ wd_ecc_setting.priv = NULL;
|
||||
out_priv:
|
||||
wd_uninit_async_request_pool(&wd_ecc_setting.pool);
|
||||
out_sched:
|
||||
diff --git a/wd_rsa.c b/wd_rsa.c
|
||||
index 4c8fd71..8fc405f 100644
|
||||
--- a/wd_rsa.c
|
||||
+++ b/wd_rsa.c
|
||||
@@ -185,6 +185,7 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
|
||||
out_init:
|
||||
free(priv);
|
||||
+ wd_rsa_setting.priv = NULL;
|
||||
out_priv:
|
||||
wd_uninit_async_request_pool(&wd_rsa_setting.pool);
|
||||
out_sched:
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,47 +0,0 @@
|
||||
From 4e2b91f8079ad1195e20c730cda4e33643918257 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Tue, 8 Mar 2022 16:14:17 +0800
|
||||
Subject: [PATCH 085/109] drv/sec: support sm4-ecb alg by new fs
|
||||
|
||||
Kunpeng 920 can supports sm4-ecb by test, and has
|
||||
been updated the chip fs.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 4 ----
|
||||
v1/drv/hisi_sec_udrv.c | 4 ----
|
||||
2 files changed, 8 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index 264d850..16fcb5f 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -656,10 +656,6 @@ static int fill_cipher_bd2_mode(struct wd_cipher_msg *msg,
|
||||
|
||||
switch (msg->mode) {
|
||||
case WD_CIPHER_ECB:
|
||||
- if (msg->alg == WD_CIPHER_SM4) {
|
||||
- WD_ERR("kunpeng 920 not support ECB(SM4)!\n");
|
||||
- return -WD_EINVAL;
|
||||
- }
|
||||
c_mode = C_MODE_ECB;
|
||||
break;
|
||||
case WD_CIPHER_CBC:
|
||||
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c
|
||||
index 7345baf..3e1e7d1 100644
|
||||
--- a/v1/drv/hisi_sec_udrv.c
|
||||
+++ b/v1/drv/hisi_sec_udrv.c
|
||||
@@ -165,10 +165,6 @@ static int fill_cipher_bd2_mode(struct wcrypto_cipher_msg *msg,
|
||||
|
||||
switch (msg->mode) {
|
||||
case WCRYPTO_CIPHER_ECB:
|
||||
- if (msg->alg == WCRYPTO_CIPHER_SM4) {
|
||||
- WD_ERR("kunpeng 920 not support ECB(SM4)!\n");
|
||||
- return -WD_EINVAL;
|
||||
- }
|
||||
sqe->type2.c_mode = C_MODE_ECB;
|
||||
break;
|
||||
case WCRYPTO_CIPHER_CBC:
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,74 +0,0 @@
|
||||
From f83ee120e0dcab4120d65c045787a6bfc58b8c92 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Tue, 8 Mar 2022 18:18:16 +0800
|
||||
Subject: [PATCH 086/109] digest: simplify the process of represent BD state
|
||||
|
||||
The value of 'out_bytes' can be expressed the BD state. So not need to
|
||||
use the marco variable. The BD state is non-zero value when the msg
|
||||
recived successfully. Otherwise the BD state is zero.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
wd_digest.c | 22 +++++++++++++---------
|
||||
1 file changed, 13 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index 06774be..fb29746 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#define POLL_SIZE 100000
|
||||
#define POLL_TIME 1000
|
||||
-#define STREAM_MODE_STATE 1
|
||||
|
||||
static int g_digest_mac_len[WD_DIGEST_TYPE_MAX] = {
|
||||
WD_DIGEST_SM3_LEN, WD_DIGEST_MD5_LEN, WD_DIGEST_SHA1_LEN,
|
||||
@@ -48,10 +47,10 @@ struct wd_digest_sess {
|
||||
__u32 key_bytes;
|
||||
void *sched_key;
|
||||
/*
|
||||
- * Notify the BD state, 1 is final BD or middle BD,
|
||||
- * 0 is normal mode or first BD, one session only supports one stream.
|
||||
+ * Notify the BD state, zero is frist BD, non-zero
|
||||
+ * is middle or final BD.
|
||||
*/
|
||||
- int state;
|
||||
+ int bd_state;
|
||||
/* Total of data for stream mode */
|
||||
__u64 long_data_len;
|
||||
};
|
||||
@@ -301,11 +300,11 @@ static void fill_request_msg(struct wd_digest_msg *msg,
|
||||
msg->has_next = req->has_next;
|
||||
sess->long_data_len += req->in_bytes;
|
||||
msg->long_data_len = sess->long_data_len;
|
||||
- /* To store the stream bd state, iv_bytes also means bd state */
|
||||
- msg->iv_bytes = sess->state;
|
||||
+ /* To store the stream BD state, iv_bytes also means BD state */
|
||||
+ msg->iv_bytes = sess->bd_state;
|
||||
if (req->has_next == 0) {
|
||||
sess->long_data_len = 0;
|
||||
- sess->state = 0;
|
||||
+ sess->bd_state = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,8 +338,13 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *ds
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
- if (msg->has_next && msg->result == WD_SUCCESS)
|
||||
- dsess->state = STREAM_MODE_STATE;
|
||||
+
|
||||
+ /*
|
||||
+ * 'out_bytes' can be expressed BD state, non-zero is final BD or
|
||||
+ * middle BD as stream mode.
|
||||
+ */
|
||||
+ if (msg->has_next)
|
||||
+ dsess->bd_state = msg->out_bytes;
|
||||
} while (ret < 0);
|
||||
|
||||
out:
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,45 +0,0 @@
|
||||
From d554782317fb25319690c2f6453994494a0396d0 Mon Sep 17 00:00:00 2001
|
||||
From: JunchongPan <panjunchong@hisilicon.com>
|
||||
Date: Thu, 10 Mar 2022 20:58:46 +0800
|
||||
Subject: [PATCH 087/109] uadk/qm_udrv: Modify goto err_out
|
||||
|
||||
In setup_region, when mmap_qfr return NULL, don't need
|
||||
to set sq_base/mmio_base NULL, return ENOMEM direct.
|
||||
|
||||
Signed-off-by: JunchongPan <panjunchong@hisilicon.com>
|
||||
---
|
||||
drv/hisi_qm_udrv.c | 9 ++-------
|
||||
1 file changed, 2 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
|
||||
index 2e692a1..906dfa3 100644
|
||||
--- a/drv/hisi_qm_udrv.c
|
||||
+++ b/drv/hisi_qm_udrv.c
|
||||
@@ -168,22 +168,17 @@ static int hisi_qm_setup_region(handle_t h_ctx,
|
||||
q_info->sq_base = wd_ctx_mmap_qfr(h_ctx, UACCE_QFRT_DUS);
|
||||
if (!q_info->sq_base) {
|
||||
WD_ERR("mmap dus fail\n");
|
||||
- goto err_out;
|
||||
+ return -WD_ENOMEM;
|
||||
}
|
||||
|
||||
q_info->mmio_base = wd_ctx_mmap_qfr(h_ctx, UACCE_QFRT_MMIO);
|
||||
if (!q_info->mmio_base) {
|
||||
wd_ctx_unmap_qfr(h_ctx, UACCE_QFRT_DUS);
|
||||
WD_ERR("mmap mmio fail\n");
|
||||
- goto err_out;
|
||||
+ return -WD_ENOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
-
|
||||
-err_out:
|
||||
- q_info->sq_base = NULL;
|
||||
- q_info->mmio_base = NULL;
|
||||
- return -WD_ENOMEM;
|
||||
}
|
||||
|
||||
static void hisi_qm_unset_region(handle_t h_ctx,
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,992 +0,0 @@
|
||||
From 61912fcfdef3b29e22731b38fbb81dff47102568 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 10 Mar 2022 20:03:18 +0800
|
||||
Subject: [PATCH 088/109] uadk: unify wd print format
|
||||
|
||||
Unify print format with following rules:
|
||||
1. failed to do sth.
|
||||
2. invalid: sth is NULL.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
drv/hisi_qm_udrv.c | 63 ++++++++++++++++++------------------
|
||||
wd.c | 6 ++--
|
||||
wd_mempool.c | 61 ++++++++++++++++++++--------------
|
||||
wd_sched.c | 52 ++++++++++++++---------------
|
||||
wd_util.c | 81 ++++++++++++++++++++--------------------------
|
||||
5 files changed, 130 insertions(+), 133 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
|
||||
index 906dfa3..be06570 100644
|
||||
--- a/drv/hisi_qm_udrv.c
|
||||
+++ b/drv/hisi_qm_udrv.c
|
||||
@@ -167,14 +167,14 @@ static int hisi_qm_setup_region(handle_t h_ctx,
|
||||
{
|
||||
q_info->sq_base = wd_ctx_mmap_qfr(h_ctx, UACCE_QFRT_DUS);
|
||||
if (!q_info->sq_base) {
|
||||
- WD_ERR("mmap dus fail\n");
|
||||
+ WD_ERR("failed to mmap dus!\n");
|
||||
return -WD_ENOMEM;
|
||||
}
|
||||
|
||||
q_info->mmio_base = wd_ctx_mmap_qfr(h_ctx, UACCE_QFRT_MMIO);
|
||||
if (!q_info->mmio_base) {
|
||||
wd_ctx_unmap_qfr(h_ctx, UACCE_QFRT_DUS);
|
||||
- WD_ERR("mmap mmio fail\n");
|
||||
+ WD_ERR("failed to mmap mmio!\n");
|
||||
return -WD_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -197,14 +197,14 @@ static __u32 get_version_id(handle_t h_ctx)
|
||||
|
||||
api_name = wd_ctx_get_api(h_ctx);
|
||||
if (!api_name || strlen(api_name) <= VERSION_ID_SHIFT) {
|
||||
- WD_ERR("api name error = %s\n", api_name);
|
||||
+ WD_ERR("invalid: api name is %s!\n", api_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
id = api_name + VERSION_ID_SHIFT;
|
||||
ver = strtoul(id, NULL, 10);
|
||||
if (!ver || ver == ULONG_MAX) {
|
||||
- WD_ERR("fail to strtoul, ver = %lu\n", ver);
|
||||
+ WD_ERR("failed to strtoul, ver = %lu!\n", ver);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ static int his_qm_set_qp_ctx(handle_t h_ctx, struct hisi_qm_priv *config,
|
||||
q_info->qc_type = qp_ctx.qc_type;
|
||||
ret = wd_ctx_set_io_cmd(h_ctx, UACCE_CMD_QM_SET_QP_CTX, &qp_ctx);
|
||||
if (ret < 0) {
|
||||
- WD_ERR("HISI QM fail to set qc_type, use default value\n");
|
||||
+ WD_ERR("failed to set qc_type, use default value!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -265,13 +265,13 @@ static int hisi_qm_get_qfrs_offs(handle_t h_ctx,
|
||||
q_info->region_size[UACCE_QFRT_DUS] = wd_ctx_get_region_size(h_ctx,
|
||||
UACCE_QFRT_DUS);
|
||||
if (!q_info->region_size[UACCE_QFRT_DUS]) {
|
||||
- WD_ERR("fail to get DUS qfrs offset.\n");
|
||||
+ WD_ERR("failed to get DUS qfrs offset!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
q_info->region_size[UACCE_QFRT_MMIO] = wd_ctx_get_region_size(h_ctx,
|
||||
UACCE_QFRT_MMIO);
|
||||
if (!q_info->region_size[UACCE_QFRT_MMIO]) {
|
||||
- WD_ERR("fail to get MMIO qfrs offset.\n");
|
||||
+ WD_ERR("failed to get MMIO qfrs offset!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -286,25 +286,25 @@ static int hisi_qm_setup_info(struct hisi_qp *qp, struct hisi_qm_priv *config)
|
||||
q_info = &qp->q_info;
|
||||
ret = hisi_qm_setup_region(qp->h_ctx, q_info);
|
||||
if (ret) {
|
||||
- WD_ERR("setup region fail\n");
|
||||
+ WD_ERR("failed to setup region!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = hisi_qm_get_qfrs_offs(qp->h_ctx, q_info);
|
||||
if (ret) {
|
||||
- WD_ERR("get dev qfrs offset fail.\n");
|
||||
+ WD_ERR("failed to get dev qfrs offset!\n");
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
ret = hisi_qm_setup_db(qp->h_ctx, q_info);
|
||||
if (ret) {
|
||||
- WD_ERR("setup db fail\n");
|
||||
+ WD_ERR("failed to setup db!\n");
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
ret = his_qm_set_qp_ctx(qp->h_ctx, config, q_info);
|
||||
if (ret) {
|
||||
- WD_ERR("setup io cmd fail\n");
|
||||
+ WD_ERR("failed to setup io cmd!\n");
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ static int hisi_qm_setup_info(struct hisi_qp *qp, struct hisi_qm_priv *config)
|
||||
|
||||
ret = pthread_spin_init(&q_info->lock, PTHREAD_PROCESS_SHARED);
|
||||
if (ret) {
|
||||
- WD_ERR("init qinfo lock fail\n");
|
||||
+ WD_ERR("failed to init qinfo lock!\n");
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
@@ -352,8 +352,8 @@ handle_t hisi_qm_alloc_qp(struct hisi_qm_priv *config, handle_t ctx)
|
||||
if (!config)
|
||||
goto out;
|
||||
|
||||
- if (config->sqe_size <= 0) {
|
||||
- WD_ERR("invalid sqe size (%u)\n", config->sqe_size);
|
||||
+ if (!config->sqe_size) {
|
||||
+ WD_ERR("invalid: sqe size is zero!\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -367,7 +367,8 @@ handle_t hisi_qm_alloc_qp(struct hisi_qm_priv *config, handle_t ctx)
|
||||
if (ret)
|
||||
goto out_qp;
|
||||
|
||||
- qp->h_sgl_pool = hisi_qm_create_sglpool(HISI_SGL_NUM_IN_BD, HISI_SGE_NUM_IN_SGL);
|
||||
+ qp->h_sgl_pool = hisi_qm_create_sglpool(HISI_SGL_NUM_IN_BD,
|
||||
+ HISI_SGE_NUM_IN_SGL);
|
||||
if (!qp->h_sgl_pool)
|
||||
goto out_qp;
|
||||
|
||||
@@ -396,7 +397,7 @@ void hisi_qm_free_qp(handle_t h_qp)
|
||||
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
|
||||
|
||||
if (!qp) {
|
||||
- WD_ERR("h_qp is NULL.\n");
|
||||
+ WD_ERR("invalid: h_qp is NULL!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -461,7 +462,7 @@ static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, void *resp)
|
||||
j = CQE_SQ_HEAD_INDEX(cqe);
|
||||
if (j >= QM_Q_DEPTH) {
|
||||
pthread_spin_unlock(&q_info->lock);
|
||||
- WD_ERR("CQE_SQ_HEAD_INDEX(%u) error\n", j);
|
||||
+ WD_ERR("CQE_SQ_HEAD_INDEX(%u) error!\n", j);
|
||||
return -WD_EIO;
|
||||
}
|
||||
memcpy(resp, (void *)((uintptr_t)q_info->sq_base +
|
||||
@@ -535,7 +536,7 @@ static void *hisi_qm_create_sgl(__u32 sge_num)
|
||||
sge_num * (sizeof(struct hisi_sge)) + HISI_SGL_ALIGE;
|
||||
sgl = calloc(1, size);
|
||||
if (!sgl) {
|
||||
- WD_ERR("failed to create sgl\n");
|
||||
+ WD_ERR("failed to create sgl!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -562,36 +563,34 @@ handle_t hisi_qm_create_sglpool(__u32 sgl_num, __u32 sge_num)
|
||||
int i, ret;
|
||||
|
||||
if (!sgl_num || !sge_num || sge_num > HISI_SGE_NUM_IN_SGL) {
|
||||
- WD_ERR("create sgl_pool failed, sgl_num=%u, sge_num=%u\n",
|
||||
+ WD_ERR("failed to create sgl_pool, sgl_num=%u, sge_num=%u!\n",
|
||||
sgl_num, sge_num);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sgl_pool = calloc(1, sizeof(struct hisi_sgl_pool));
|
||||
if (!sgl_pool) {
|
||||
- WD_ERR("sgl pool alloc memory failed.\n");
|
||||
+ WD_ERR("failed to alloc memory for sgl_pool!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
sgl_pool->sgl = calloc(sgl_num, sizeof(void *));
|
||||
if (!sgl_pool->sgl) {
|
||||
- WD_ERR("sgl array alloc memory failed.\n");
|
||||
+ WD_ERR("failed to alloc memory for sgl!\n");
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
sgl_pool->sgl_align = calloc(sgl_num, sizeof(void *));
|
||||
if (!sgl_pool->sgl_align) {
|
||||
- WD_ERR("sgl align array alloc memory failed.\n");
|
||||
+ WD_ERR("failed to alloc memory for sgl align!\n");
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
/* base the sgl_num create the sgl chain */
|
||||
for (i = 0; i < sgl_num; i++) {
|
||||
sgl_pool->sgl[i] = hisi_qm_create_sgl(sge_num);
|
||||
- if (!sgl_pool->sgl[i]) {
|
||||
- WD_ERR("sgl create failed.\n");
|
||||
+ if (!sgl_pool->sgl[i])
|
||||
goto err_out;
|
||||
- }
|
||||
|
||||
sgl_pool->sgl_align[i] = hisi_qm_align_sgl(sgl_pool->sgl[i], sge_num);
|
||||
}
|
||||
@@ -602,7 +601,7 @@ handle_t hisi_qm_create_sglpool(__u32 sgl_num, __u32 sge_num)
|
||||
sgl_pool->top = sgl_num;
|
||||
ret = pthread_spin_init(&sgl_pool->lock, PTHREAD_PROCESS_SHARED);
|
||||
if (ret) {
|
||||
- WD_ERR("init sgl pool lock failed.\n");
|
||||
+ WD_ERR("failed to init sgl pool lock!\n");
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
@@ -619,7 +618,7 @@ void hisi_qm_destroy_sglpool(handle_t sgl_pool)
|
||||
int i;
|
||||
|
||||
if (!pool) {
|
||||
- WD_ERR("sgl_pool is NULL\n");
|
||||
+ WD_ERR("invalid: sgl_pool is NULL!\n");
|
||||
return;
|
||||
}
|
||||
if (pool->sgl) {
|
||||
@@ -642,7 +641,7 @@ static struct hisi_sgl *hisi_qm_sgl_pop(struct hisi_sgl_pool *pool)
|
||||
pthread_spin_lock(&pool->lock);
|
||||
|
||||
if (pool->top == 0) {
|
||||
- WD_ERR("The sgl pool is empty\n");
|
||||
+ WD_ERR("invalid: the sgl pool is empty!\n");
|
||||
pthread_spin_unlock(&pool->lock);
|
||||
return NULL;
|
||||
}
|
||||
@@ -657,7 +656,7 @@ static int hisi_qm_sgl_push(struct hisi_sgl_pool *pool, struct hisi_sgl *hw_sgl)
|
||||
{
|
||||
pthread_spin_lock(&pool->lock);
|
||||
if (pool->top >= pool->depth) {
|
||||
- WD_ERR("The sgl pool is full\n");
|
||||
+ WD_ERR("invalid: the sgl pool is full!\n");
|
||||
pthread_spin_unlock(&pool->lock);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -705,7 +704,7 @@ void *hisi_qm_get_hw_sgl(handle_t sgl_pool, struct wd_datalist *sgl)
|
||||
int i = 0;
|
||||
|
||||
if (!pool || !sgl) {
|
||||
- WD_ERR("get hw sgl pool or sgl is NULL\n");
|
||||
+ WD_ERR("invalid: hw sgl pool or sgl is NULL!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -723,7 +722,7 @@ void *hisi_qm_get_hw_sgl(handle_t sgl_pool, struct wd_datalist *sgl)
|
||||
}
|
||||
|
||||
if (tmp->len > HISI_MAX_SIZE_IN_SGE) {
|
||||
- WD_ERR("the data len is invalid: %u\n", tmp->len);
|
||||
+ WD_ERR("invalid: the data len is %u!\n", tmp->len);
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
@@ -742,7 +741,7 @@ void *hisi_qm_get_hw_sgl(handle_t sgl_pool, struct wd_datalist *sgl)
|
||||
if (i == pool->sge_num && tmp->next) {
|
||||
next = hisi_qm_sgl_pop(pool);
|
||||
if (!next) {
|
||||
- WD_ERR("the sgl pool is not enough\n");
|
||||
+ WD_ERR("invalid: the sgl pool is not enough!\n");
|
||||
goto err_out;
|
||||
}
|
||||
cur->next_dma = (uintptr_t)next;
|
||||
diff --git a/wd.c b/wd.c
|
||||
index b88ee62..0774837 100644
|
||||
--- a/wd.c
|
||||
+++ b/wd.c
|
||||
@@ -59,14 +59,14 @@ static int get_raw_attr(const char *dev_root, const char *attr, char *buf,
|
||||
|
||||
fd = open(attr_path, O_RDONLY, 0);
|
||||
if (fd < 0) {
|
||||
- WD_ERR("open %s fail (%d)!\n", attr_path, -errno);
|
||||
+ WD_ERR("failed to open %s(%d)!\n", attr_path, -errno);
|
||||
return -WD_ENODEV;
|
||||
}
|
||||
|
||||
memset(buf, 0, sz);
|
||||
size = read(fd, buf, sz);
|
||||
if (size <= 0) {
|
||||
- WD_ERR("read nothing at %s!\n", attr_path);
|
||||
+ WD_ERR("failed to read anything at %s!\n", attr_path);
|
||||
size = -WD_EIO;
|
||||
}
|
||||
|
||||
@@ -601,7 +601,7 @@ static int check_alg_name(const char *alg_name)
|
||||
while (alg_name[i] != '\0') {
|
||||
i++;
|
||||
if (i >= MAX_ATTR_STR_SIZE) {
|
||||
- WD_ERR("get list failed, alg name is too long!\n");
|
||||
+ WD_ERR("failed to get list, alg name is too long!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
}
|
||||
diff --git a/wd_mempool.c b/wd_mempool.c
|
||||
index b6e1088..bfacd28 100644
|
||||
--- a/wd_mempool.c
|
||||
+++ b/wd_mempool.c
|
||||
@@ -206,12 +206,17 @@ static __always_inline unsigned long wd_ffs(unsigned long word)
|
||||
|
||||
static struct bitmap *create_bitmap(int bits)
|
||||
{
|
||||
- struct bitmap *bm = calloc(1, sizeof(*bm));
|
||||
- if (!bm)
|
||||
+ struct bitmap *bm;
|
||||
+
|
||||
+ bm = calloc(1, sizeof(*bm));
|
||||
+ if (!bm) {
|
||||
+ WD_ERR("failed to alloc memory for bitmap!\n");
|
||||
return NULL;
|
||||
+ }
|
||||
|
||||
bm->map = calloc(BITS_TO_LONGS(bits), sizeof(unsigned long));
|
||||
if (!bm->map) {
|
||||
+ WD_ERR("failed to alloc memory for bitmap map!\n");
|
||||
free(bm);
|
||||
return NULL;
|
||||
}
|
||||
@@ -346,6 +351,7 @@ static int alloc_memzone(struct blkpool *bp, void *addr, size_t blk_num,
|
||||
|
||||
zone = calloc(1, sizeof(struct memzone));
|
||||
if (!zone) {
|
||||
+ WD_ERR("failed to alloc memory for memzone!\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
@@ -389,7 +395,8 @@ static void free_mem_to_mempool(struct blkpool *bp)
|
||||
static int check_mempool_real_size(struct mempool *mp, struct blkpool *bp)
|
||||
{
|
||||
if (bp->blk_size * bp->depth > mp->real_size) {
|
||||
- WD_ERR("wd_mempool: mempool too small: %lu\n", mp->real_size);
|
||||
+ WD_ERR("invalid: mempool size is too small: %lu!\n",
|
||||
+ mp->real_size);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
@@ -525,8 +532,10 @@ static int init_blkpool_elem(struct blkpool *bp)
|
||||
int i;
|
||||
|
||||
bp->blk_elem = calloc(bp->depth, sizeof(void *));
|
||||
- if (!bp->blk_elem)
|
||||
+ if (!bp->blk_elem) {
|
||||
+ WD_ERR("failed to alloc memory for blk_elem!\n");
|
||||
return -ENOMEM;
|
||||
+ }
|
||||
|
||||
TAILQ_FOREACH(iter, &bp->mz_list, node) {
|
||||
for (i = 0; i < iter->blk_num; i++)
|
||||
@@ -544,7 +553,7 @@ handle_t wd_blockpool_create(handle_t mempool, size_t block_size,
|
||||
int ret;
|
||||
|
||||
if (!mp || !block_size || !block_num) {
|
||||
- WD_ERR("wd_mempool: input parameter is invalid value\n");
|
||||
+ WD_ERR("invalid: mempool is NULL or block param is 0!\n");
|
||||
return (handle_t)(-WD_EINVAL);
|
||||
}
|
||||
|
||||
@@ -552,8 +561,10 @@ handle_t wd_blockpool_create(handle_t mempool, size_t block_size,
|
||||
return (handle_t)(-WD_EBUSY);
|
||||
|
||||
bp = calloc(1, sizeof(struct blkpool));
|
||||
- if (!bp)
|
||||
+ if (!bp) {
|
||||
+ WD_ERR("failed to alloc memory for blkpool!\n");
|
||||
return (handle_t)(-WD_ENOMEM);
|
||||
+ }
|
||||
|
||||
bp->top = block_num;
|
||||
bp->depth = block_num;
|
||||
@@ -563,13 +574,13 @@ handle_t wd_blockpool_create(handle_t mempool, size_t block_size,
|
||||
|
||||
ret = alloc_mem_from_mempool(mp, bp);
|
||||
if (ret < 0) {
|
||||
- WD_ERR("wd_mempool: failed to allocate memory from mempool\n");
|
||||
+ WD_ERR("failed to allocate memory from mempool!\n");
|
||||
goto err_free_bp;
|
||||
}
|
||||
|
||||
ret = init_blkpool_elem(bp);
|
||||
if (ret < 0) {
|
||||
- WD_ERR("wd_mempool: failed to init blkpool\n");
|
||||
+ WD_ERR("failed to init blkpool!\n");
|
||||
goto err_free_mem;
|
||||
}
|
||||
|
||||
@@ -590,7 +601,7 @@ void wd_blockpool_destroy(handle_t blkpool)
|
||||
struct mempool *mp;
|
||||
|
||||
if (!bp) {
|
||||
- WD_ERR("wd_mempool: blkpool is NULL\n");
|
||||
+ WD_ERR("invalid: blkpool is NULL!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -620,13 +631,13 @@ static int get_value_from_sysfs(const char *path, ssize_t path_size)
|
||||
|
||||
fd = open(dev_path, O_RDONLY, 0);
|
||||
if (fd < 0) {
|
||||
- WD_ERR("wd_mempool: failed to open %s\n", dev_path);
|
||||
+ WD_ERR("failed to open %s!\n", dev_path);
|
||||
goto err_open;
|
||||
}
|
||||
|
||||
size = read(fd, buf, sizeof(buf));
|
||||
if (size <= 0) {
|
||||
- WD_ERR("wd_mempool: failed to read %s\n", dev_path);
|
||||
+ WD_ERR("failed to read %s!\n", dev_path);
|
||||
goto err_read;
|
||||
}
|
||||
|
||||
@@ -716,7 +727,7 @@ static int get_hugepage_info(struct mempool *mp)
|
||||
|
||||
dir = opendir(hugepage_path);
|
||||
if (!dir) {
|
||||
- WD_ERR("wd_mempool: failed to open %s\n", hugepage_path);
|
||||
+ WD_ERR("failed to open %s\n!", hugepage_path);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
@@ -728,13 +739,13 @@ static int get_hugepage_info(struct mempool *mp)
|
||||
|
||||
tmp = calloc(1, sizeof(*tmp));
|
||||
if (!tmp) {
|
||||
- WD_ERR("wd_mempool: failed to calloc\n");
|
||||
+ WD_ERR("failed to calloc for sys_hugepage_config!\n");
|
||||
goto err_free_list;
|
||||
}
|
||||
ret = get_hugepage_info_per_type(hugepage_path, MAX_HP_STR_SIZE,
|
||||
hp_dir, tmp);
|
||||
if (ret < 0) {
|
||||
- WD_ERR("wd_mempool: failed to get hugepage info\n");
|
||||
+ WD_ERR("failed to get hugepage info!\n");
|
||||
goto err_free;
|
||||
}
|
||||
|
||||
@@ -779,7 +790,7 @@ static int mbind_memory(void *addr, size_t size, int node)
|
||||
node_mask = 1U << (unsigned int)node;
|
||||
ret = mbind(addr, size, MPOL_BIND, &node_mask, max_node, 0);
|
||||
if (ret < 0) {
|
||||
- WD_ERR("wd_mempool: failed to mbind memory, %d\n", ret);
|
||||
+ WD_ERR("failed to mbind memory, ret is %d!\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -805,7 +816,7 @@ static int alloc_mem_from_hugepage(struct mempool *mp)
|
||||
break;
|
||||
}
|
||||
if (!iter) {
|
||||
- WD_ERR("wd_mempool: failed to find proper hugepage\n");
|
||||
+ WD_ERR("failed to find proper hugepage!\n");
|
||||
ret = -ENOMEM;
|
||||
goto err_put_info;
|
||||
}
|
||||
@@ -826,7 +837,7 @@ static int alloc_mem_from_hugepage(struct mempool *mp)
|
||||
p = mmap(NULL, real_size, PROT_READ | PROT_WRITE, MAP_PRIVATE |
|
||||
MAP_ANONYMOUS | MAP_HUGETLB | flags, -1, 0);
|
||||
if (p == MAP_FAILED) {
|
||||
- WD_ERR("wd_mempool: failed to allocate huge page\n");
|
||||
+ WD_ERR("failed to allocate huge page!\n");
|
||||
ret = -ENOMEM;
|
||||
goto err_put_info;
|
||||
}
|
||||
@@ -862,7 +873,7 @@ static int alloc_mempool_memory(struct mempool *mp)
|
||||
|
||||
ret = alloc_mem_from_hugepage(mp);
|
||||
if (ret) {
|
||||
- WD_ERR("wd_mempool: failed to alloc memory from hugepage\n");
|
||||
+ WD_ERR("failed to alloc memory from hugepage!\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
@@ -908,8 +919,10 @@ handle_t wd_mempool_create(size_t size, int node)
|
||||
size += WD_MEMPOOL_BLOCK_SIZE - (WD_MEMPOOL_SIZE_MASK & size);
|
||||
|
||||
mp = calloc(1, sizeof(*mp));
|
||||
- if (!mp)
|
||||
+ if (!mp) {
|
||||
+ WD_ERR("failed to alloc memory for mempool!\n");
|
||||
return (handle_t)(-WD_ENOMEM);
|
||||
+ }
|
||||
|
||||
mp->node = node;
|
||||
mp->size = size;
|
||||
@@ -938,7 +951,7 @@ void wd_mempool_destroy(handle_t mempool)
|
||||
struct mempool *mp = (struct mempool *)mempool;
|
||||
|
||||
if (!mp) {
|
||||
- WD_ERR("wd_mempool: mempool is NULL\n");
|
||||
+ WD_ERR("invalid: mempool is NULL!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -954,12 +967,12 @@ void wd_mempool_stats(handle_t mempool, struct wd_mempool_stats *stats)
|
||||
struct mempool *mp = (struct mempool *)mempool;
|
||||
|
||||
if (!mp) {
|
||||
- WD_ERR("wd_mempool: mempool is NULL\n");
|
||||
+ WD_ERR("invalid: mempool is NULL!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!stats) {
|
||||
- WD_ERR("wd_mempool: mempool stats is NULL\n");
|
||||
+ WD_ERR("invalid: mempool stats is NULL!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -984,7 +997,7 @@ void wd_blockpool_stats(handle_t blkpool, struct wd_blockpool_stats *stats)
|
||||
struct memzone *iter;
|
||||
|
||||
if (!bp || !stats) {
|
||||
- WD_ERR("wd_mempool: blkpool or stats is NULL\n");
|
||||
+ WD_ERR("invalid: blkpool or stats is NULL!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1001,7 +1014,7 @@ void wd_blockpool_stats(handle_t blkpool, struct wd_blockpool_stats *stats)
|
||||
}
|
||||
|
||||
if (!size) {
|
||||
- WD_ERR("wd_mempool: blkpool size is zero\n");
|
||||
+ WD_ERR("invalid: blkpool size is zero!\n");
|
||||
wd_unspinlock(&bp->lock);
|
||||
return;
|
||||
}
|
||||
diff --git a/wd_sched.c b/wd_sched.c
|
||||
index ef90233..9b1998c 100644
|
||||
--- a/wd_sched.c
|
||||
+++ b/wd_sched.c
|
||||
@@ -129,8 +129,8 @@ static bool sched_key_valid(struct wd_sched_ctx *ctx,
|
||||
{
|
||||
if (key->numa_id >= ctx->numa_num || key->mode >= SCHED_MODE_BUTT ||
|
||||
key->type >= ctx->type_num) {
|
||||
- WD_ERR("ERROR: %s key error - numa: %d, mode: %u, type: %u!\n",
|
||||
- __FUNCTION__, key->numa_id, key->mode, key->type);
|
||||
+ WD_ERR("invalid: sched key's numa: %d, mode: %u, type: %u!\n",
|
||||
+ key->numa_id, key->mode, key->type);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -207,13 +207,13 @@ static int session_sched_poll_policy(handle_t sched_ctx,
|
||||
__u16 i;
|
||||
int ret;
|
||||
|
||||
- if (!sched_ctx || !count || !ctx) {
|
||||
- WD_ERR("ERROR: %s the para is NULL!\n", __FUNCTION__);
|
||||
+ if (!count || !ctx) {
|
||||
+ WD_ERR("invalid: sched ctx is NULL or count is zero!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->numa_num > NUMA_NUM_NODES) {
|
||||
- WD_ERR("ERROR: %s ctx numa num is invalid!\n", __FUNCTION__);
|
||||
+ WD_ERR("invalid: ctx's numa number is %d!\n", ctx->numa_num);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -270,16 +270,14 @@ static __u32 session_sched_init_ctx(handle_t sched_ctx,
|
||||
bool ret;
|
||||
|
||||
if (!ctx || !key) {
|
||||
- WD_ERR("ERROR: %s the pointer para is NULL!\n", __FUNCTION__);
|
||||
+ WD_ERR("invalid: sched ctx or key is NULL!\n");
|
||||
return INVALID_POS;
|
||||
}
|
||||
|
||||
key->mode = sched_mode;
|
||||
ret = sched_key_valid(ctx, key);
|
||||
- if (!ret) {
|
||||
- WD_ERR("ERROR: %s the key is invalid!\n", __FUNCTION__);
|
||||
+ if (!ret)
|
||||
return INVALID_POS;
|
||||
- }
|
||||
|
||||
region = sched_get_ctx_range(ctx, key);
|
||||
if (!region)
|
||||
@@ -295,7 +293,7 @@ handle_t session_sched_init(handle_t h_sched_ctx, void *sched_param)
|
||||
|
||||
skey = malloc(sizeof(struct sched_key));
|
||||
if (!skey) {
|
||||
- WD_ERR("fail to alloc session sched key!\n");
|
||||
+ WD_ERR("failed to alloc memory for session sched key!\n");
|
||||
return (handle_t)(-WD_ENOMEM);
|
||||
}
|
||||
|
||||
@@ -328,7 +326,7 @@ static __u32 session_sched_pick_next_ctx(handle_t sched_ctx,
|
||||
struct sched_key *key = (struct sched_key *)sched_key;
|
||||
|
||||
if (unlikely(!sched_ctx || !key)) {
|
||||
- WD_ERR("ERROR: %s the pointer para is NULL!\n", __FUNCTION__);
|
||||
+ WD_ERR("invalid: sched ctx or key is NULL!\n");
|
||||
return INVALID_POS;
|
||||
}
|
||||
|
||||
@@ -357,13 +355,12 @@ int wd_sched_rr_instance(const struct wd_sched *sched,
|
||||
int numa_id;
|
||||
|
||||
if (!sched || !sched->h_sched_ctx || !param) {
|
||||
- WD_ERR("ERROR: %s para err: sched of h_sched_ctx is NULL!\n",
|
||||
- __FUNCTION__);
|
||||
+ WD_ERR("invalid: sched or sched_params is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (param->begin > param->end) {
|
||||
- WD_ERR("ERROR: sched_params's begin is larger than end!\n");
|
||||
+ WD_ERR("invalid: sched_params's begin is larger than end!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -373,28 +370,28 @@ int wd_sched_rr_instance(const struct wd_sched *sched,
|
||||
sched_ctx = (struct wd_sched_ctx *)sched->h_sched_ctx;
|
||||
|
||||
if (numa_id >= sched_ctx->numa_num || numa_id < 0) {
|
||||
- WD_ERR("ERROR: %s para err: numa_id = %d, numa_num = %u\n",
|
||||
- __FUNCTION__, numa_id, sched_ctx->numa_num);
|
||||
+ WD_ERR("invalid: sched_ctx's numa_id is %d, numa_num is %u!\n",
|
||||
+ numa_id, sched_ctx->numa_num);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (type >= sched_ctx->type_num) {
|
||||
- WD_ERR("ERROR: %s para err: type = %u, type_num = %u\n",
|
||||
- __FUNCTION__, type, sched_ctx->type_num);
|
||||
+ WD_ERR("invalid: sched_ctx's type is %u, type_num is %u!\n",
|
||||
+ type, sched_ctx->type_num);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (mode >= SCHED_MODE_BUTT) {
|
||||
- WD_ERR("ERROR: %s para err: mode = %u, mode_num = %d!\n",
|
||||
- __FUNCTION__, mode, SCHED_MODE_BUTT);
|
||||
+ WD_ERR("invalid: sched_ctx's mode is %u, mode_num is %d!\n",
|
||||
+ mode, SCHED_MODE_BUTT);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
sched_info = sched_ctx->sched_info;
|
||||
|
||||
if (!sched_info[numa_id].ctx_region[mode]) {
|
||||
- WD_ERR("ERROR: %s ctx_region of numa_id = %d, mode = %u is NULL!\n",
|
||||
- __FUNCTION__, numa_id, mode);
|
||||
+ WD_ERR("invalid: ctx_region is NULL, numa: %d, mode: %u!\n",
|
||||
+ numa_id, mode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -454,27 +451,26 @@ struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num,
|
||||
return NULL;
|
||||
|
||||
if (!numa_num || numa_num > max_node) {
|
||||
- WD_ERR("Error: %s numa number = %u!\n", __FUNCTION__,
|
||||
- numa_num);
|
||||
+ WD_ERR("invalid: numa number is %u!\n", numa_num);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (sched_type >= SCHED_POLICY_BUTT || !type_num) {
|
||||
- WD_ERR("Error: %s sched_type = %u or type_num = %u is invalid!\n",
|
||||
- __FUNCTION__, sched_type, type_num);
|
||||
+ WD_ERR("invalid: sched_type is %u or type_num is %u!\n",
|
||||
+ sched_type, type_num);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sched = calloc(1, sizeof(struct wd_sched));
|
||||
if (!sched) {
|
||||
- WD_ERR("Error: %s wd_sched alloc error!\n", __FUNCTION__);
|
||||
+ WD_ERR("failed to alloc memory for wd_sched!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sched_ctx = calloc(1, sizeof(struct wd_sched_ctx) +
|
||||
sizeof(struct wd_sched_info) * numa_num);
|
||||
if (!sched_ctx) {
|
||||
- WD_ERR("Error: %s sched_ctx alloc error!\n", __FUNCTION__);
|
||||
+ WD_ERR("failed to alloc memory for sched_ctx!\n");
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 44c8909..03316b6 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -74,7 +74,7 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in,
|
||||
int i, ret;
|
||||
|
||||
if (!cfg->ctx_num) {
|
||||
- WD_ERR("invalid parameters, ctx_num is 0!\n");
|
||||
+ WD_ERR("invalid: ctx_num is 0!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in,
|
||||
|
||||
for (i = 0; i < cfg->ctx_num; i++) {
|
||||
if (!cfg->ctxs[i].ctx) {
|
||||
- WD_ERR("invalid parameters, ctx is NULL!\n");
|
||||
+ WD_ERR("invalid: ctx is NULL!\n");
|
||||
free(ctxs);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in,
|
||||
clone_ctx_to_internal(cfg->ctxs + i, ctxs + i);
|
||||
ret = pthread_spin_init(&ctxs[i].lock, PTHREAD_PROCESS_SHARED);
|
||||
if (ret) {
|
||||
- WD_ERR("init ctxs lock failed!\n");
|
||||
+ WD_ERR("failed to init ctxs lock!\n");
|
||||
free(ctxs);
|
||||
return ret;
|
||||
}
|
||||
@@ -243,7 +243,7 @@ void *wd_find_msg_in_pool(struct wd_async_msg_pool *pool,
|
||||
|
||||
/* tag value start from 1 */
|
||||
if (tag == 0 || tag > msg_num) {
|
||||
- WD_ERR("invalid message cache tag(%u)\n", tag);
|
||||
+ WD_ERR("invalid: message cache tag is %u!\n", tag);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ void wd_put_msg_to_pool(struct wd_async_msg_pool *pool, int ctx_idx, __u32 tag)
|
||||
|
||||
/* tag value start from 1 */
|
||||
if (!tag || tag > msg_num) {
|
||||
- WD_ERR("invalid message cache idx(%u)\n", tag);
|
||||
+ WD_ERR("invalid: message cache idx is %u!\n", tag);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -318,14 +318,11 @@ void dump_env_info(struct wd_env_config *config)
|
||||
config_numa->async_ctx_num);
|
||||
for (j = 0; j < CTX_MODE_MAX; j++)
|
||||
for (k = 0; k < config_numa->op_type_num; k++) {
|
||||
- WD_ERR("-> %s: %d: [%d][%d].begin: %u\n",
|
||||
- __func__,
|
||||
+ WD_ERR("-> %d: [%d][%d].begin: %u\n",
|
||||
i, j, k, ctx_table[j][k].begin);
|
||||
- WD_ERR("-> %s: %d: [%d][%d].end: %u\n",
|
||||
- __func__,
|
||||
+ WD_ERR("-> %d: [%d][%d].end: %u\n",
|
||||
i, j, k, ctx_table[j][k].end);
|
||||
- WD_ERR("-> %s: %d: [%d][%d].size: %u\n",
|
||||
- __func__,
|
||||
+ WD_ERR("-> %d: [%d][%d].size: %u\n",
|
||||
i, j, k, ctx_table[j][k].size);
|
||||
}
|
||||
}
|
||||
@@ -340,8 +337,10 @@ static void *wd_get_config_numa(struct wd_env_config *config, int node)
|
||||
if (config_numa->node == node)
|
||||
break;
|
||||
|
||||
- if (i == config->numa_num)
|
||||
+ if (i == config->numa_num) {
|
||||
+ WD_ERR("invalid: missing numa node is %d!\n", node);
|
||||
return NULL;
|
||||
+ }
|
||||
|
||||
return config_numa;
|
||||
}
|
||||
@@ -373,7 +372,7 @@ static __u16 wd_get_dev_numa(struct uacce_dev_list *head,
|
||||
if (list->dev->numa_id < 0) {
|
||||
list->dev->numa_id = 0;
|
||||
} else if (list->dev->numa_id >= size) {
|
||||
- WD_ERR("numa id is wrong(%d)\n", list->dev->numa_id);
|
||||
+ WD_ERR("invalid: numa id is %d!\n", list->dev->numa_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -396,10 +395,8 @@ static void wd_set_numa_dev(struct uacce_dev_list *head,
|
||||
|
||||
while (list) {
|
||||
config_numa = wd_get_config_numa(config, list->dev->numa_id);
|
||||
- if (!config_numa) {
|
||||
- WD_ERR("%s got wrong numa node!\n", __func__);
|
||||
+ if (!config_numa)
|
||||
break;
|
||||
- }
|
||||
|
||||
dev = config_numa->dev + config_numa->dev_num;
|
||||
memcpy(dev, list->dev, sizeof(*list->dev));
|
||||
@@ -457,7 +454,7 @@ static int wd_alloc_numa(struct wd_env_config *config,
|
||||
/* get uacce_dev */
|
||||
head = wd_get_accel_list(ops->alg_name);
|
||||
if (!head) {
|
||||
- WD_ERR("no device to support %s\n", ops->alg_name);
|
||||
+ WD_ERR("invalid: no device to support %s\n", ops->alg_name);
|
||||
ret = -WD_ENODEV;
|
||||
goto free_numa_dev_num;
|
||||
}
|
||||
@@ -465,7 +462,7 @@ static int wd_alloc_numa(struct wd_env_config *config,
|
||||
/* get numa num and device num of each numa from uacce_dev list */
|
||||
config->numa_num = wd_get_dev_numa(head, numa_dev_num, max_node);
|
||||
if (config->numa_num == 0 || config->numa_num > max_node) {
|
||||
- WD_ERR("numa num err(%u)!\n", config->numa_num);
|
||||
+ WD_ERR("invalid: numa number is %u!\n", config->numa_num);
|
||||
ret = -WD_ENODEV;
|
||||
goto free_list;
|
||||
}
|
||||
@@ -519,13 +516,13 @@ int wd_parse_async_poll_en(struct wd_env_config *config, const char *s)
|
||||
int tmp;
|
||||
|
||||
if (!is_number(s)) {
|
||||
- WD_ERR("invalid async poll en flag: %s!\n", s);
|
||||
+ WD_ERR("invalid: async poll en flag is %s!\n", s);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
tmp = strtol(s, NULL, 10);
|
||||
if (tmp != 0 && tmp != 1) {
|
||||
- WD_ERR("async poll en flag is not 0 or 1!\n");
|
||||
+ WD_ERR("invalid: async poll en flag is not 0 or 1!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -539,7 +536,7 @@ static int parse_num_on_numa(const char *s, int *num, int *node)
|
||||
char *sep, *start, *left;
|
||||
|
||||
if (!strlen(s)) {
|
||||
- WD_ERR("input string length is zero!\n");
|
||||
+ WD_ERR("invalid: input string length is zero!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -560,7 +557,7 @@ static int parse_num_on_numa(const char *s, int *num, int *node)
|
||||
}
|
||||
|
||||
out:
|
||||
- WD_ERR("input env format is invalid:%s\n", s);
|
||||
+ WD_ERR("invalid: input env format is %s!\n", s);
|
||||
free(start);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -658,7 +655,7 @@ static int wd_parse_section(struct wd_env_config *config, char *section)
|
||||
|
||||
ctx_section = index(section, ':');
|
||||
if (!ctx_section) {
|
||||
- WD_ERR("%s got wrong format: %s!\n", __func__, section);
|
||||
+ WD_ERR("invalid: ctx section got wrong format: %s!\n", section);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -669,10 +666,8 @@ static int wd_parse_section(struct wd_env_config *config, char *section)
|
||||
return ret;
|
||||
|
||||
config_numa = wd_get_config_numa(config, node);
|
||||
- if (!config_numa) {
|
||||
- WD_ERR("%s got wrong numa node: %s!\n", __func__, section);
|
||||
+ if (!config_numa)
|
||||
return -WD_EINVAL;
|
||||
- }
|
||||
|
||||
config_numa->op_type_num = config->op_type_num;
|
||||
ret = wd_alloc_ctx_table_per_numa(config_numa);
|
||||
@@ -681,7 +676,8 @@ static int wd_parse_section(struct wd_env_config *config, char *section)
|
||||
|
||||
ret = get_and_fill_ctx_num(config_numa, section, ctx_num);
|
||||
if (ret) {
|
||||
- WD_ERR("%s got wrong ctx type: %s!\n", __func__, section);
|
||||
+ WD_ERR("invalid: ctx section got wrong ctx type: %s!\n",
|
||||
+ section);
|
||||
wd_free_ctx_table_per_numa(config_numa);
|
||||
return ret;
|
||||
}
|
||||
@@ -798,8 +794,6 @@ int wd_parse_async_poll_num(struct wd_env_config *config, const char *s)
|
||||
goto out;
|
||||
config_numa = wd_get_config_numa(config, node);
|
||||
if (!config_numa) {
|
||||
- WD_ERR("%s got wrong numa node: %s!\n",
|
||||
- __func__, section);
|
||||
ret = -WD_EINVAL;
|
||||
goto out;
|
||||
}
|
||||
@@ -831,7 +825,7 @@ static int wd_parse_env(struct wd_env_config *config)
|
||||
|
||||
ret = var->parse_fn(config, var_s);
|
||||
if (ret) {
|
||||
- WD_ERR("fail to parse %s environment variable!\n",
|
||||
+ WD_ERR("failed to parse %s environment variable!\n",
|
||||
var->name);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -847,10 +841,8 @@ static int wd_parse_ctx_attr(struct wd_env_config *env_config,
|
||||
int ret;
|
||||
|
||||
config_numa = wd_get_config_numa(env_config, attr->node);
|
||||
- if (!config_numa) {
|
||||
- WD_ERR("%s got wrong numa node!\n", __func__);
|
||||
+ if (!config_numa)
|
||||
return -WD_EINVAL;
|
||||
- }
|
||||
|
||||
config_numa->op_type_num = env_config->op_type_num;
|
||||
ret = wd_alloc_ctx_table_per_numa(config_numa);
|
||||
@@ -958,7 +950,7 @@ static int wd_get_wd_ctx(struct wd_env_config_per_numa *config,
|
||||
h_ctx = request_ctx_on_numa(config);
|
||||
if (!h_ctx) {
|
||||
ret = -WD_EBUSY;
|
||||
- WD_ERR("err: request too many ctxs\n");
|
||||
+ WD_ERR("failed to request more ctxs!\n");
|
||||
goto free_ctx;
|
||||
}
|
||||
|
||||
@@ -1149,7 +1141,7 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config,
|
||||
}
|
||||
|
||||
if (!config_numa->async_poll_num) {
|
||||
- WD_ERR("invalid parameter, async_poll_num of numa is zero!\n");
|
||||
+ WD_ERR("invalid: async_poll_num of numa is zero!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1304,17 +1296,17 @@ static int wd_init_one_task_queue(struct async_task_queue *task_queue,
|
||||
task_queue->alg_poll_ctx = alg_poll_ctx;
|
||||
|
||||
if (sem_init(&task_queue->empty_sem, 0, depth)) {
|
||||
- WD_ERR("empty_sem init failed.\n");
|
||||
+ WD_ERR("failed to init empty_sem!\n");
|
||||
goto err_free_head;
|
||||
}
|
||||
|
||||
if (sem_init(&task_queue->full_sem, 0, 0)) {
|
||||
- WD_ERR("full_sem init failed.\n");
|
||||
+ WD_ERR("failed to init full_sem!\n");
|
||||
goto err_uninit_empty_sem;
|
||||
}
|
||||
|
||||
if (pthread_mutex_init(&task_queue->lock, NULL)) {
|
||||
- WD_ERR("mutex init failed.\n");
|
||||
+ WD_ERR("failed to init task queue's mutex lock!\n");
|
||||
goto err_uninit_full_sem;
|
||||
}
|
||||
|
||||
@@ -1323,7 +1315,7 @@ static int wd_init_one_task_queue(struct async_task_queue *task_queue,
|
||||
task_queue->tid = 0;
|
||||
if (pthread_create(&thread_id, &attr, async_poll_process_func,
|
||||
task_queue)) {
|
||||
- WD_ERR("create poll thread failed.\n");
|
||||
+ WD_ERR("failed to create poll thread!\n");
|
||||
goto err_destory_mutex;
|
||||
}
|
||||
|
||||
@@ -1547,18 +1539,15 @@ int wd_alg_get_env_param(struct wd_env_config *env_config,
|
||||
struct wd_env_config_per_numa *config_numa;
|
||||
|
||||
if (!num || !is_enable) {
|
||||
- WD_ERR("input parameter num or is_enable is NULL!\n");
|
||||
+ WD_ERR("invalid: input pointer num or is_enable is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
*is_enable = env_config->enable_internal_poll;
|
||||
|
||||
config_numa = wd_get_config_numa(env_config, attr.node);
|
||||
- if (!config_numa) {
|
||||
- WD_ERR("%s got wrong numa node: %u!\n",
|
||||
- __func__, attr.node);
|
||||
+ if (!config_numa)
|
||||
return -WD_EINVAL;
|
||||
- }
|
||||
|
||||
*num = (config_numa->ctx_table) ?
|
||||
config_numa->ctx_table[attr.mode][attr.type].size : 0;
|
||||
@@ -1570,7 +1559,7 @@ int wd_set_ctx_attr(struct wd_ctx_attr *ctx_attr,
|
||||
__u32 node, __u32 type, __u8 mode, __u32 num)
|
||||
{
|
||||
if (mode >= CTX_MODE_MAX) {
|
||||
- WD_ERR("wrong ctx mode(%u))!\n", mode);
|
||||
+ WD_ERR("invalid: ctx mode is %u!\n", mode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1594,7 +1583,7 @@ int wd_check_ctx(struct wd_ctx_config_internal *config, __u8 mode, __u32 idx)
|
||||
|
||||
ctx = config->ctxs + idx;
|
||||
if (ctx->ctx_mode != mode) {
|
||||
- WD_ERR("ctx %u mode = %hhu error!\n", idx, ctx->ctx_mode);
|
||||
+ WD_ERR("invalid: ctx(%u) mode is %hhu!\n", idx, ctx->ctx_mode);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,68 +0,0 @@
|
||||
From b56736c04686f0611e6b3865dd894cba62a3b0a2 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 10 Mar 2022 20:03:12 +0800
|
||||
Subject: [PATCH 089/109] uadk: v1: fix wd_bmm pool_init
|
||||
|
||||
setup br alloc and free should be checked at the same time,
|
||||
wd_reserve_memory should be rolled back.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
v1/wd_bmm.c | 15 +++++----------
|
||||
1 file changed, 5 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/v1/wd_bmm.c b/v1/wd_bmm.c
|
||||
index af59983..11f2ee8 100644
|
||||
--- a/v1/wd_bmm.c
|
||||
+++ b/v1/wd_bmm.c
|
||||
@@ -216,7 +216,7 @@ static void *pool_init(struct wd_queue *q, struct wd_blkpool *pool,
|
||||
void *addr = NULL;
|
||||
|
||||
/* use user's memory, and its br alloc function */
|
||||
- if (setup->br.alloc) {
|
||||
+ if (setup->br.alloc && setup->br.free) {
|
||||
addr = setup->br.alloc(setup->br.usr, pool->act_mem_sz);
|
||||
if (!addr) {
|
||||
WD_ERR("failed to allocate memory in user pool.\n");
|
||||
@@ -226,14 +226,15 @@ static void *pool_init(struct wd_queue *q, struct wd_blkpool *pool,
|
||||
pool->usr_mem_start = addr;
|
||||
if (usr_pool_init(pool)) {
|
||||
WD_ERR("failed to initialize user pool.\n");
|
||||
- goto err_pool_init;
|
||||
+ setup->br.free(setup->br.usr, addr);
|
||||
+ return NULL;
|
||||
}
|
||||
} else {
|
||||
/* use wd to reserve memory */
|
||||
addr = wd_reserve_memory(q, pool->act_mem_sz);
|
||||
if (!addr) {
|
||||
WD_ERR("wd pool failed to reserve memory.\n");
|
||||
- goto err_pool_init;
|
||||
+ return NULL;
|
||||
}
|
||||
|
||||
pool->usr_mem_start = addr;
|
||||
@@ -241,19 +242,13 @@ static void *pool_init(struct wd_queue *q, struct wd_blkpool *pool,
|
||||
WD_ERR("failed to initialize wd pool.\n");
|
||||
|
||||
/* release q will free memory */
|
||||
- goto err_pool_init;
|
||||
+ return NULL;
|
||||
}
|
||||
setup->block_num = pool->setup.block_num;
|
||||
pool->q = q;
|
||||
}
|
||||
|
||||
return pool;
|
||||
-
|
||||
-err_pool_init:
|
||||
- if (setup->br.alloc && setup->br.free)
|
||||
- setup->br.free(setup->br.usr, addr);
|
||||
-
|
||||
- return NULL;
|
||||
}
|
||||
|
||||
void *wd_blkpool_create(struct wd_queue *q, struct wd_blkpool_setup *setup)
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,116 +0,0 @@
|
||||
From 5f9d701e8a56f4b7a0ff9c1b0c24fd130427cf1f Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 10 Mar 2022 20:03:13 +0800
|
||||
Subject: [PATCH 090/109] uadk: v1: fix wd create ctx memory leak
|
||||
|
||||
ctx's block memory should be freed if wd fail to create ctx.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
v1/wd_aead.c | 12 ++++++++----
|
||||
v1/wd_cipher.c | 5 ++++-
|
||||
v1/wd_dh.c | 4 +++-
|
||||
v1/wd_digest.c | 6 +++++-
|
||||
4 files changed, 20 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/v1/wd_aead.c b/v1/wd_aead.c
|
||||
index 6d8c541..ec537b3 100644
|
||||
--- a/v1/wd_aead.c
|
||||
+++ b/v1/wd_aead.c
|
||||
@@ -229,14 +229,13 @@ void *wcrypto_create_aead_ctx(struct wd_queue *q,
|
||||
ctx->ckey = setup->br.alloc(setup->br.usr, MAX_CIPHER_KEY_SIZE);
|
||||
if (!ctx->ckey) {
|
||||
WD_ERR("fail to alloc cipher ctx key!\n");
|
||||
- free(ctx);
|
||||
- goto free_ctx_id;
|
||||
+ goto free_ctx;
|
||||
}
|
||||
ctx->akey = setup->br.alloc(setup->br.usr, MAX_AEAD_KEY_SIZE);
|
||||
if (!ctx->akey) {
|
||||
WD_ERR("fail to alloc authenticate ctx key!\n");
|
||||
setup->br.free(setup->br.usr, ctx->ckey);
|
||||
- goto free_ctx;
|
||||
+ goto free_ctx_ckey;
|
||||
}
|
||||
|
||||
ctx->iv_blk_size = get_iv_block_size(setup->cmode);
|
||||
@@ -244,11 +243,16 @@ void *wcrypto_create_aead_ctx(struct wd_queue *q,
|
||||
sizeof(struct wcrypto_aead_cookie), WD_CTX_MSG_NUM);
|
||||
if (ret) {
|
||||
WD_ERR("fail to init cookie pool!\n");
|
||||
- goto free_ctx;
|
||||
+ goto free_ctx_akey;
|
||||
}
|
||||
init_aead_cookie(ctx, setup);
|
||||
|
||||
return ctx;
|
||||
+
|
||||
+free_ctx_akey:
|
||||
+ setup->br.free(setup->br.usr, ctx->akey);
|
||||
+free_ctx_ckey:
|
||||
+ setup->br.free(setup->br.usr, ctx->ckey);
|
||||
free_ctx:
|
||||
free(ctx);
|
||||
free_ctx_id:
|
||||
diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c
|
||||
index 8bf71be..921c464 100644
|
||||
--- a/v1/wd_cipher.c
|
||||
+++ b/v1/wd_cipher.c
|
||||
@@ -217,11 +217,14 @@ void *wcrypto_create_cipher_ctx(struct wd_queue *q,
|
||||
sizeof(struct wcrypto_cipher_cookie), WD_CTX_MSG_NUM);
|
||||
if (ret) {
|
||||
WD_ERR("fail to init cookie pool!\n");
|
||||
- goto free_ctx;
|
||||
+ goto free_ctx_key;
|
||||
}
|
||||
init_cipher_cookie(ctx, setup);
|
||||
|
||||
return ctx;
|
||||
+
|
||||
+free_ctx_key:
|
||||
+ setup->br.free(setup->br.usr, ctx->key);
|
||||
free_ctx:
|
||||
free(ctx);
|
||||
free_ctx_id:
|
||||
diff --git a/v1/wd_dh.c b/v1/wd_dh.c
|
||||
index f83dd91..66f1081 100644
|
||||
--- a/v1/wd_dh.c
|
||||
+++ b/v1/wd_dh.c
|
||||
@@ -174,10 +174,12 @@ void *wcrypto_create_dh_ctx(struct wd_queue *q, struct wcrypto_dh_ctx_setup *set
|
||||
|
||||
ret = wcrypto_init_dh_cookie(ctx);
|
||||
if (ret)
|
||||
- goto free_ctx;
|
||||
+ goto free_ctx_gdata;
|
||||
|
||||
return ctx;
|
||||
|
||||
+free_ctx_gdata:
|
||||
+ setup->br.free(setup->br.usr, ctx->g.data);
|
||||
free_ctx:
|
||||
free(ctx);
|
||||
free_ctx_id:
|
||||
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
|
||||
index 2179415..c84e71d 100644
|
||||
--- a/v1/wd_digest.c
|
||||
+++ b/v1/wd_digest.c
|
||||
@@ -199,11 +199,15 @@ void *wcrypto_create_digest_ctx(struct wd_queue *q,
|
||||
sizeof(struct wcrypto_digest_cookie), WD_CTX_MSG_NUM);
|
||||
if (ret) {
|
||||
WD_ERR("fail to init cookie pool!\n");
|
||||
- goto free_ctx;
|
||||
+ goto free_ctx_key;
|
||||
}
|
||||
init_digest_cookie(ctx, setup);
|
||||
|
||||
return ctx;
|
||||
+
|
||||
+free_ctx_key:
|
||||
+ if (setup->mode == WCRYPTO_DIGEST_HMAC)
|
||||
+ setup->br.free(setup->br.usr, ctx->key);
|
||||
free_ctx:
|
||||
free(ctx);
|
||||
free_ctx_id:
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,51 +0,0 @@
|
||||
From 00d8dd57f97586658770a258f3e8fb331180f457 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 10 Mar 2022 20:03:15 +0800
|
||||
Subject: [PATCH 091/109] uadk: mempool: fix redundant assignment
|
||||
|
||||
1. pos_first is no need to be assinged because it
|
||||
will get a value later.
|
||||
2. improve performance by giving other threads or
|
||||
processes a chance to run
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_mempool.c | 7 +++++--
|
||||
1 file changed, 5 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/wd_mempool.c b/wd_mempool.c
|
||||
index bfacd28..8467c48 100644
|
||||
--- a/wd_mempool.c
|
||||
+++ b/wd_mempool.c
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <sys/mman.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
+#include <pthread.h>
|
||||
#include "wd.h"
|
||||
|
||||
#define SYSFS_NODE_PATH "/sys/devices/system/node/node"
|
||||
@@ -409,8 +410,8 @@ static int alloc_block_from_mempool(struct mempool *mp,
|
||||
int mem_combined_num,
|
||||
int mem_splited_num)
|
||||
{
|
||||
- int pos_first = pos;
|
||||
int pos_last = pos;
|
||||
+ int pos_first;
|
||||
int i, ret;
|
||||
|
||||
do {
|
||||
@@ -607,7 +608,9 @@ void wd_blockpool_destroy(handle_t blkpool)
|
||||
|
||||
mp = bp->mp;
|
||||
wd_atomic_sub(&bp->ref, 1);
|
||||
- while(wd_atomic_load(&bp->ref));
|
||||
+ while (wd_atomic_load(&bp->ref))
|
||||
+ sched_yield();
|
||||
+
|
||||
free_mem_to_mempool(bp);
|
||||
free(bp->blk_elem);
|
||||
free(bp);
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,126 +0,0 @@
|
||||
From 26661c4ae49d1c4c6914d8aba4e8d32db609d24b Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 10 Mar 2022 20:03:16 +0800
|
||||
Subject: [PATCH 092/109] uadk: v1: fix del ctx
|
||||
|
||||
It is better to check whether the number of CTX
|
||||
is greater than 0 before del ctx.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
v1/wd_aead.c | 11 +++++------
|
||||
v1/wd_cipher.c | 12 ++++++------
|
||||
v1/wd_comp.c | 13 +++++++------
|
||||
v1/wd_digest.c | 11 +++++------
|
||||
4 files changed, 23 insertions(+), 24 deletions(-)
|
||||
|
||||
diff --git a/v1/wd_aead.c b/v1/wd_aead.c
|
||||
index ec537b3..cf358bf 100644
|
||||
--- a/v1/wd_aead.c
|
||||
+++ b/v1/wd_aead.c
|
||||
@@ -685,16 +685,15 @@ void wcrypto_del_aead_ctx(void *ctx)
|
||||
qinfo = ctxt->q->qinfo;
|
||||
wd_uninit_cookie_pool(&ctxt->pool);
|
||||
wd_spinlock(&qinfo->qlock);
|
||||
- wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, ctxt->ctx_id - 1,
|
||||
- WD_MAX_CTX_NUM);
|
||||
- qinfo->ctx_num--;
|
||||
- if (!qinfo->ctx_num)
|
||||
- memset(&qinfo->br, 0, sizeof(qinfo->br));
|
||||
- if (qinfo->ctx_num < 0) {
|
||||
+ if (qinfo->ctx_num <= 0) {
|
||||
wd_unspinlock(&qinfo->qlock);
|
||||
WD_ERR("fail to delete aead ctx!\n");
|
||||
return;
|
||||
}
|
||||
+ wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, ctxt->ctx_id - 1,
|
||||
+ WD_MAX_CTX_NUM);
|
||||
+ if (!(--qinfo->ctx_num))
|
||||
+ memset(&qinfo->br, 0, sizeof(qinfo->br));
|
||||
wd_unspinlock(&qinfo->qlock);
|
||||
del_ctx_key(ctxt);
|
||||
free(ctx);
|
||||
diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c
|
||||
index 921c464..8eb6a6f 100644
|
||||
--- a/v1/wd_cipher.c
|
||||
+++ b/v1/wd_cipher.c
|
||||
@@ -553,16 +553,16 @@ void wcrypto_del_cipher_ctx(void *ctx)
|
||||
qinfo = c_ctx->q->qinfo;
|
||||
wd_uninit_cookie_pool(&c_ctx->pool);
|
||||
wd_spinlock(&qinfo->qlock);
|
||||
- wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, c_ctx->ctx_id - 1,
|
||||
- WD_MAX_CTX_NUM);
|
||||
- qinfo->ctx_num--;
|
||||
- if (!qinfo->ctx_num)
|
||||
- memset(&qinfo->br, 0, sizeof(qinfo->br));
|
||||
- if (qinfo->ctx_num < 0) {
|
||||
+ if (qinfo->ctx_num <= 0) {
|
||||
wd_unspinlock(&qinfo->qlock);
|
||||
WD_ERR("error:repeat del cipher ctx!\n");
|
||||
return;
|
||||
}
|
||||
+ wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, c_ctx->ctx_id - 1,
|
||||
+ WD_MAX_CTX_NUM);
|
||||
+ if (!(--qinfo->ctx_num))
|
||||
+ memset(&qinfo->br, 0, sizeof(qinfo->br));
|
||||
+
|
||||
wd_unspinlock(&qinfo->qlock);
|
||||
del_ctx_key(c_ctx);
|
||||
free(ctx);
|
||||
diff --git a/v1/wd_comp.c b/v1/wd_comp.c
|
||||
index 32d89c8..4ce79bd 100644
|
||||
--- a/v1/wd_comp.c
|
||||
+++ b/v1/wd_comp.c
|
||||
@@ -339,16 +339,17 @@ void wcrypto_del_comp_ctx(void *ctx)
|
||||
|
||||
wd_uninit_cookie_pool(&cctx->pool);
|
||||
wd_spinlock(&qinfo->qlock);
|
||||
- wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, cctx->ctx_id -1,
|
||||
- WD_MAX_CTX_NUM);
|
||||
- qinfo->ctx_num--;
|
||||
- if (!qinfo->ctx_num) {
|
||||
- memset(&qinfo->br, 0, sizeof(qinfo->br));
|
||||
- } else if (qinfo->ctx_num < 0) {
|
||||
+ if (qinfo->ctx_num <= 0) {
|
||||
wd_unspinlock(&qinfo->qlock);
|
||||
WD_ERR("error: repeat delete compress ctx!\n");
|
||||
return;
|
||||
}
|
||||
+
|
||||
+ wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, cctx->ctx_id -1,
|
||||
+ WD_MAX_CTX_NUM);
|
||||
+ if (!(--qinfo->ctx_num))
|
||||
+ memset(&qinfo->br, 0, sizeof(qinfo->br));
|
||||
+
|
||||
wd_unspinlock(&qinfo->qlock);
|
||||
|
||||
free(cctx);
|
||||
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
|
||||
index c84e71d..5acb660 100644
|
||||
--- a/v1/wd_digest.c
|
||||
+++ b/v1/wd_digest.c
|
||||
@@ -472,16 +472,15 @@ void wcrypto_del_digest_ctx(void *ctx)
|
||||
qinfo = d_ctx->q->qinfo;
|
||||
wd_uninit_cookie_pool(&d_ctx->pool);
|
||||
wd_spinlock(&qinfo->qlock);
|
||||
- wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, d_ctx->ctx_id - 1,
|
||||
- WD_MAX_CTX_NUM);
|
||||
- qinfo->ctx_num--;
|
||||
- if (!qinfo->ctx_num)
|
||||
- memset(&qinfo->br, 0, sizeof(qinfo->br));
|
||||
- if (qinfo->ctx_num < 0) {
|
||||
+ if (qinfo->ctx_num <= 0) {
|
||||
wd_unspinlock(&qinfo->qlock);
|
||||
WD_ERR("error: repeat del digest ctx!\n");
|
||||
return;
|
||||
}
|
||||
+ wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, d_ctx->ctx_id - 1,
|
||||
+ WD_MAX_CTX_NUM);
|
||||
+ if (!(--qinfo->ctx_num))
|
||||
+ memset(&qinfo->br, 0, sizeof(qinfo->br));
|
||||
wd_unspinlock(&qinfo->qlock);
|
||||
del_ctx_key(d_ctx);
|
||||
free(ctx);
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,110 +0,0 @@
|
||||
From 3b201e8cfc8306e84dc51cbeccd86510e9c0da50 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 10 Mar 2022 20:03:17 +0800
|
||||
Subject: [PATCH 093/109] uadk: v1: clean code for wd
|
||||
|
||||
1. get_int_attr should return INT_MAX instead of
|
||||
INT_MAX_SIZE.
|
||||
2. qinfo should be set to NULL if memory is freed,
|
||||
q_info memory should be freed at last.
|
||||
3. optimize is_alg_support
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
v1/wd.c | 23 ++++++++++++++++-------
|
||||
v1/wd.h | 1 -
|
||||
2 files changed, 16 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/v1/wd.c b/v1/wd.c
|
||||
index 26f6692..39c4167 100644
|
||||
--- a/v1/wd.c
|
||||
+++ b/v1/wd.c
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <assert.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/poll.h>
|
||||
+#include <limits.h>
|
||||
|
||||
#include "v1/wd.h"
|
||||
#include "v1/wd_util.h"
|
||||
@@ -118,8 +119,10 @@ static int get_int_attr(struct dev_info *dinfo, const char *attr)
|
||||
* When the value is bigger than INT_MAX, it returns INT_MAX
|
||||
*/
|
||||
size = get_raw_attr(dinfo->dev_root, attr, buf, MAX_ATTR_STR_SIZE);
|
||||
- if (size < 0 || size >= INT_MAX_SIZE)
|
||||
+ if (size < 0)
|
||||
return size;
|
||||
+ else if (size >= INT_MAX_SIZE)
|
||||
+ return INT_MAX;
|
||||
/* Handing the read string's end tails '\n' to '\0' */
|
||||
buf[size] = '\0';
|
||||
return atoi((char *)buf);
|
||||
@@ -186,19 +189,23 @@ static int get_ul_vec_attr(struct dev_info *dinfo, const char *attr,
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int is_alg_support(struct dev_info *dinfo, const char *alg)
|
||||
+static bool is_alg_support(struct dev_info *dinfo, const char *alg)
|
||||
{
|
||||
- int alg_support_flag = 0;
|
||||
char *alg_save = NULL;
|
||||
char *alg_tmp;
|
||||
|
||||
+ if (!alg)
|
||||
+ return false;
|
||||
+
|
||||
alg_tmp = strtok_r(dinfo->algs, "\n", &alg_save);
|
||||
while (alg_tmp != NULL) {
|
||||
- if (alg && !strcmp(alg_tmp, alg))
|
||||
- alg_support_flag++;
|
||||
+ if (!strcmp(alg_tmp, alg))
|
||||
+ return true;
|
||||
+
|
||||
alg_tmp = strtok_r(NULL, "\n", &alg_save);
|
||||
}
|
||||
- return alg_support_flag;
|
||||
+
|
||||
+ return false;
|
||||
}
|
||||
|
||||
static bool is_weight_more(unsigned int new, unsigned int old)
|
||||
@@ -279,7 +286,7 @@ static int get_str_attr_all(struct dev_info *dinfo, const char *alg)
|
||||
|
||||
/* Add algorithm check to cut later pointless logic */
|
||||
ret = is_alg_support(dinfo, alg);
|
||||
- if (ret == 0)
|
||||
+ if (!ret)
|
||||
return -EPFNOSUPPORT;
|
||||
|
||||
ret = get_str_attr(dinfo, "api", dinfo->api, WD_NAME_SIZE);
|
||||
@@ -605,6 +612,7 @@ err_with_fd:
|
||||
wd_close_queue(q);
|
||||
err_with_dev:
|
||||
free(dinfop);
|
||||
+ q->qinfo = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -647,6 +655,7 @@ void wd_release_queue(struct wd_queue *q)
|
||||
|
||||
wd_close_queue(q);
|
||||
free((void *)qinfo->dev_info);
|
||||
+ q->qinfo = NULL;
|
||||
}
|
||||
|
||||
int wd_send(struct wd_queue *q, void *req)
|
||||
diff --git a/v1/wd.h b/v1/wd.h
|
||||
index 3dd69eb..429c6b6 100644
|
||||
--- a/v1/wd.h
|
||||
+++ b/v1/wd.h
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
-#include <limits.h>
|
||||
#include <assert.h>
|
||||
#include "uacce.h"
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,110 +0,0 @@
|
||||
From b68986ce59e52b57256eaef90c6e24493822a3ee Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 10 Mar 2022 20:03:19 +0800
|
||||
Subject: [PATCH 094/109] uadk: v1: fix drv_reserve_mem memory leak
|
||||
|
||||
share region memory should be freed and
|
||||
qfr region should be unmaped if drv_reserve_mem fail.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
v1/wd.c | 9 +--------
|
||||
v1/wd_adapter.c | 24 ++++++++++++++++++++++--
|
||||
v1/wd_adapter.h | 1 +
|
||||
3 files changed, 24 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/v1/wd.c b/v1/wd.c
|
||||
index 39c4167..b94ec43 100644
|
||||
--- a/v1/wd.c
|
||||
+++ b/v1/wd.c
|
||||
@@ -618,7 +618,6 @@ err_with_dev:
|
||||
|
||||
void wd_release_queue(struct wd_queue *q)
|
||||
{
|
||||
- struct wd_ss_region *rg;
|
||||
struct wd_ss_region_list *head;
|
||||
struct q_info *qinfo, *sqinfo;
|
||||
|
||||
@@ -645,13 +644,7 @@ void wd_release_queue(struct wd_queue *q)
|
||||
if (qinfo->ss_size)
|
||||
drv_unmap_reserve_mem(q, qinfo->ss_va, qinfo->ss_size);
|
||||
|
||||
- while (true) {
|
||||
- rg = TAILQ_FIRST(&qinfo->ss_list);
|
||||
- if (!rg)
|
||||
- break;
|
||||
- TAILQ_REMOVE(&qinfo->ss_list, rg, next);
|
||||
- free(rg);
|
||||
- }
|
||||
+ drv_free_slice(q);
|
||||
|
||||
wd_close_queue(q);
|
||||
free((void *)qinfo->dev_info);
|
||||
diff --git a/v1/wd_adapter.c b/v1/wd_adapter.c
|
||||
index f8bef2b..e53c561 100644
|
||||
--- a/v1/wd_adapter.c
|
||||
+++ b/v1/wd_adapter.c
|
||||
@@ -150,6 +150,20 @@ int drv_recv(struct wd_queue *q, void **req, __u32 num)
|
||||
return hw_dio_tbl[qinfo->hw_type_id].recv(q, req, num);
|
||||
}
|
||||
|
||||
+void drv_free_slice(struct wd_queue *q)
|
||||
+{
|
||||
+ struct q_info *qinfo = q->qinfo;
|
||||
+ struct wd_ss_region *rgn;
|
||||
+
|
||||
+ while (true) {
|
||||
+ rgn = TAILQ_FIRST(&qinfo->ss_list);
|
||||
+ if (!rgn)
|
||||
+ break;
|
||||
+ TAILQ_REMOVE(&qinfo->ss_list, rgn, next);
|
||||
+ free(rgn);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
void drv_add_slice(struct wd_queue *q, struct wd_ss_region *rgn)
|
||||
{
|
||||
struct q_info *qinfo = q->qinfo;
|
||||
@@ -209,12 +223,12 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size)
|
||||
if (ret < 0) {
|
||||
drv_show_ss_slices(q);
|
||||
WD_ERR("get DMA fail!\n");
|
||||
- return NULL;
|
||||
+ goto err_out;
|
||||
}
|
||||
rgn = malloc(sizeof(*rgn));
|
||||
if (!rgn) {
|
||||
WD_ERR("alloc ss region fail!\n");
|
||||
- return NULL;
|
||||
+ goto err_out;
|
||||
}
|
||||
memset(rgn, 0, sizeof(*rgn));
|
||||
|
||||
@@ -231,6 +245,12 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size)
|
||||
}
|
||||
|
||||
return ptr;
|
||||
+
|
||||
+err_out:
|
||||
+ drv_free_slice(q);
|
||||
+ drv_unmap_reserve_mem(q, ptr, size);
|
||||
+
|
||||
+ return NULL;
|
||||
}
|
||||
|
||||
void drv_unmap_reserve_mem(struct wd_queue *q, void *addr, size_t size)
|
||||
diff --git a/v1/wd_adapter.h b/v1/wd_adapter.h
|
||||
index e1e1233..a5edd24 100644
|
||||
--- a/v1/wd_adapter.h
|
||||
+++ b/v1/wd_adapter.h
|
||||
@@ -67,6 +67,7 @@ void drv_close(struct wd_queue *q);
|
||||
int drv_send(struct wd_queue *q, void **req, __u32 num);
|
||||
int drv_recv(struct wd_queue *q, void **req, __u32 num);
|
||||
void drv_flush(struct wd_queue *q);
|
||||
+void drv_free_slice(struct wd_queue *q);
|
||||
void *drv_reserve_mem(struct wd_queue *q, size_t size);
|
||||
void drv_unmap_reserve_mem(struct wd_queue *q, void *addr, size_t size);
|
||||
int drv_get_sgl_info(struct wd_queue *q, struct hw_sgl_info *info);
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
From c79a52c5470ada323f3fabcc88d8dd8dc1300658 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Thu, 10 Mar 2022 20:03:14 +0800
|
||||
Subject: [PATCH 095/109] uadk: cipher: fix wd_cipher_check_params
|
||||
|
||||
no need to set ret and optimize the return line.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
wd_cipher.c | 8 ++------
|
||||
1 file changed, 2 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index afd8c4d..88d3b04 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -384,7 +384,7 @@ static int wd_cipher_check_params(handle_t h_sess,
|
||||
struct wd_cipher_req *req, __u8 mode)
|
||||
{
|
||||
struct wd_cipher_sess *sess = (struct wd_cipher_sess *)h_sess;
|
||||
- int ret = 0;
|
||||
+ int ret;
|
||||
|
||||
if (unlikely(!h_sess || !req)) {
|
||||
WD_ERR("cipher input sess or req is NULL!\n");
|
||||
@@ -419,11 +419,7 @@ static int wd_cipher_check_params(handle_t h_sess,
|
||||
}
|
||||
}
|
||||
|
||||
- ret = cipher_iv_len_check(req, sess);
|
||||
- if (unlikely(ret))
|
||||
- return ret;
|
||||
-
|
||||
- return 0;
|
||||
+ return cipher_iv_len_check(req, sess);
|
||||
}
|
||||
|
||||
static int send_recv_sync(struct wd_ctx_internal *ctx,
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,308 +0,0 @@
|
||||
From 634b2341b94ff972142da89d30f0a4c08586a0b6 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Thu, 10 Mar 2022 20:29:44 +0800
|
||||
Subject: [PATCH 096/109] sec: unify print format
|
||||
|
||||
Unify print format with following rules:
|
||||
1. failed to do sth.
|
||||
2. invalid: sth is NULL.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 20 ++++++++++----------
|
||||
wd_aead.c | 12 ++++++------
|
||||
wd_cipher.c | 20 ++++++++++----------
|
||||
wd_digest.c | 10 +++++-----
|
||||
4 files changed, 31 insertions(+), 31 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index 16fcb5f..aa86a6b 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -703,7 +703,7 @@ static void parse_cipher_bd2(struct hisi_sec_sqe *sqe,
|
||||
|
||||
done = sqe->type2.done_flag & SEC_DONE_MASK;
|
||||
if (done != SEC_HW_TASK_DONE || sqe->type2.error_type) {
|
||||
- WD_ERR("SEC BD %s fail! done=0x%x, etype=0x%x\n", "cipher",
|
||||
+ WD_ERR("failed to parse cipher BD2! done=0x%x, etype=0x%x\n",
|
||||
done, sqe->type2.error_type);
|
||||
recv_msg->result = WD_IN_EPARA;
|
||||
} else {
|
||||
@@ -927,7 +927,7 @@ int hisi_sec_cipher_send(handle_t ctx, struct wd_cipher_msg *msg)
|
||||
int ret;
|
||||
|
||||
if (!msg) {
|
||||
- WD_ERR("input cipher msg is NULL!\n");
|
||||
+ WD_ERR("invalid: input cipher msg is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1130,7 +1130,7 @@ int hisi_sec_cipher_send_v3(handle_t ctx, struct wd_cipher_msg *msg)
|
||||
int ret;
|
||||
|
||||
if (!msg) {
|
||||
- WD_ERR("input cipher msg is NULL!\n");
|
||||
+ WD_ERR("invalid: input cipher msg is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1175,7 +1175,7 @@ static void parse_cipher_bd3(struct hisi_sec_sqe3 *sqe,
|
||||
|
||||
done = sqe->done_flag & SEC_DONE_MASK;
|
||||
if (done != SEC_HW_TASK_DONE || sqe->error_type) {
|
||||
- WD_ERR("SEC BD3 %s fail! done=0x%x, etype=0x%x\n", "cipher",
|
||||
+ WD_ERR("failed to parse cipher BD3! done=0x%x, etype=0x%x\n",
|
||||
done, sqe->error_type);
|
||||
recv_msg->result = WD_IN_EPARA;
|
||||
} else {
|
||||
@@ -1278,7 +1278,7 @@ static void parse_digest_bd2(struct hisi_sec_sqe *sqe,
|
||||
|
||||
done = sqe->type2.done_flag & SEC_DONE_MASK;
|
||||
if (done != SEC_HW_TASK_DONE || sqe->type2.error_type) {
|
||||
- WD_ERR("SEC BD %s fail! done=0x%x, etype=0x%x\n", "digest",
|
||||
+ WD_ERR("failed to parse digest BD2! done=0x%x, etype=0x%x\n",
|
||||
done, sqe->type2.error_type);
|
||||
recv_msg->result = WD_IN_EPARA;
|
||||
} else {
|
||||
@@ -1354,7 +1354,7 @@ int hisi_sec_digest_send(handle_t ctx, struct wd_digest_msg *msg)
|
||||
int ret;
|
||||
|
||||
if (!msg) {
|
||||
- WD_ERR("input digest msg is NULL!\n");
|
||||
+ WD_ERR("invalid: input digest msg is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1510,7 +1510,7 @@ int hisi_sec_digest_send_v3(handle_t ctx, struct wd_digest_msg *msg)
|
||||
int ret;
|
||||
|
||||
if (!msg) {
|
||||
- WD_ERR("input digest msg is NULL!\n");
|
||||
+ WD_ERR("invalid: input digest msg is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1578,7 +1578,7 @@ static void parse_digest_bd3(struct hisi_sec_sqe3 *sqe,
|
||||
|
||||
done = sqe->done_flag & SEC_DONE_MASK;
|
||||
if (done != SEC_HW_TASK_DONE || sqe->error_type) {
|
||||
- WD_ERR("SEC BD3 %s fail! done=0x%x, etype=0x%x\n", "digest",
|
||||
+ WD_ERR("failed to parse digest BD3! done=0x%x, etype=0x%x\n",
|
||||
done, sqe->error_type);
|
||||
recv_msg->result = WD_IN_EPARA;
|
||||
} else {
|
||||
@@ -1927,7 +1927,7 @@ static void parse_aead_bd2(struct hisi_sec_sqe *sqe,
|
||||
icv = (sqe->type2.done_flag & SEC_ICV_MASK) >> 1;
|
||||
if (done != SEC_HW_TASK_DONE || sqe->type2.error_type ||
|
||||
icv == SEC_HW_ICV_ERR) {
|
||||
- WD_ERR("SEC BD aead fail! done=0x%x, etype=0x%x, icv=0x%x\n",
|
||||
+ WD_ERR("failed to parse aead BD2! done=0x%x, etype=0x%x, icv=0x%x\n",
|
||||
done, sqe->type2.error_type, icv);
|
||||
recv_msg->result = WD_IN_EPARA;
|
||||
} else {
|
||||
@@ -2195,7 +2195,7 @@ static void parse_aead_bd3(struct hisi_sec_sqe3 *sqe,
|
||||
icv = (sqe->done_flag & SEC_ICV_MASK) >> 1;
|
||||
if (done != SEC_HW_TASK_DONE || sqe->error_type ||
|
||||
icv == SEC_HW_ICV_ERR) {
|
||||
- WD_ERR("SEC BD3 aead fail! done=0x%x, etype=0x%x, icv=0x%x\n",
|
||||
+ WD_ERR("failed to parse aead BD3! done=0x%x, etype=0x%x, icv=0x%x\n",
|
||||
done, sqe->error_type, icv);
|
||||
recv_msg->result = WD_IN_EPARA;
|
||||
} else {
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index 7df8e80..74047b5 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -63,14 +63,14 @@ static void wd_aead_set_static_drv(void)
|
||||
{
|
||||
wd_aead_setting.driver = wd_aead_get_driver();
|
||||
if (!wd_aead_setting.driver)
|
||||
- WD_ERR("fail to get driver\n");
|
||||
+ WD_ERR("failed to get driver!\n");
|
||||
}
|
||||
#else
|
||||
static void __attribute__((constructor)) wd_aead_open_driver(void)
|
||||
{
|
||||
wd_aead_setting.dlhandle = dlopen("libhisi_sec.so", RTLD_NOW);
|
||||
if (!wd_aead_setting.dlhandle)
|
||||
- WD_ERR("failed to open libhisi_sec.so\n");
|
||||
+ WD_ERR("failed to open libhisi_sec.so!\n");
|
||||
}
|
||||
|
||||
static void __attribute__((destructor)) wd_aead_close_driver(void)
|
||||
@@ -344,7 +344,7 @@ static int aead_param_check(struct wd_aead_sess *sess,
|
||||
int ret;
|
||||
|
||||
if (unlikely(!sess || !req)) {
|
||||
- WD_ERR("aead input sess or req is NULL.\n");
|
||||
+ WD_ERR("invalid: aead input sess or req is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -393,7 +393,7 @@ static int aead_param_check(struct wd_aead_sess *sess,
|
||||
static int aead_init_check(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
{
|
||||
if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) {
|
||||
- WD_ERR("wd aead config or sched is NULL!\n");
|
||||
+ WD_ERR("invalid: wd aead config or sched is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -594,7 +594,7 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req)
|
||||
return -WD_EINVAL;
|
||||
|
||||
if (unlikely(!req->cb)) {
|
||||
- WD_ERR("aead input req cb is NULL.\n");
|
||||
+ WD_ERR("invalid: aead input req cb is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -647,7 +647,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
||||
int ret;
|
||||
|
||||
if (!count) {
|
||||
- WD_ERR("aead poll ctx input param is NULL!\n");
|
||||
+ WD_ERR("invalid: aead poll ctx input param is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index 88d3b04..563eece 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -75,14 +75,14 @@ static void wd_cipher_set_static_drv(void)
|
||||
{
|
||||
wd_cipher_setting.driver = wd_cipher_get_driver();
|
||||
if (!wd_cipher_setting.driver)
|
||||
- WD_ERR("fail to get driver\n");
|
||||
+ WD_ERR("failed to get driver!\n");
|
||||
}
|
||||
#else
|
||||
static void __attribute__((constructor)) wd_cipher_open_driver(void)
|
||||
{
|
||||
wd_cipher_setting.dlhandle = dlopen("libhisi_sec.so", RTLD_NOW);
|
||||
if (!wd_cipher_setting.dlhandle)
|
||||
- WD_ERR("fail to open libhisi_sec.so\n");
|
||||
+ WD_ERR("failed to open libhisi_sec.so!\n");
|
||||
}
|
||||
|
||||
static void __attribute__((destructor)) wd_cipher_close_driver(void)
|
||||
@@ -158,7 +158,7 @@ static int cipher_init_check(struct wd_ctx_config *config,
|
||||
struct wd_sched *sched)
|
||||
{
|
||||
if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) {
|
||||
- WD_ERR("wd cipher config or sched is NULL!\n");
|
||||
+ WD_ERR("invalid: wd cipher config or sched is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ int wd_cipher_set_key(handle_t h_sess, const __u8 *key, __u32 key_len)
|
||||
int ret;
|
||||
|
||||
if (!key || !sess) {
|
||||
- WD_ERR("cipher set key input param err!\n");
|
||||
+ WD_ERR("invalid: cipher set key input param err!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -205,13 +205,13 @@ handle_t wd_cipher_alloc_sess(struct wd_cipher_sess_setup *setup)
|
||||
struct wd_cipher_sess *sess = NULL;
|
||||
|
||||
if (unlikely(!setup)) {
|
||||
- WD_ERR("cipher input setup is NULL!\n");
|
||||
+ WD_ERR("invalid: cipher input setup is NULL!\n");
|
||||
return (handle_t)0;
|
||||
}
|
||||
|
||||
sess = malloc(sizeof(struct wd_cipher_sess));
|
||||
if (!sess) {
|
||||
- WD_ERR("fail to alloc session memory!\n");
|
||||
+ WD_ERR("failed to alloc session memory!\n");
|
||||
return (handle_t)0;
|
||||
}
|
||||
memset(sess, 0, sizeof(struct wd_cipher_sess));
|
||||
@@ -235,7 +235,7 @@ void wd_cipher_free_sess(handle_t h_sess)
|
||||
struct wd_cipher_sess *sess = (struct wd_cipher_sess *)h_sess;
|
||||
|
||||
if (unlikely(!sess)) {
|
||||
- WD_ERR("cipher input h_sess is NULL!\n");
|
||||
+ WD_ERR("invalid: cipher input h_sess is NULL!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -387,12 +387,12 @@ static int wd_cipher_check_params(handle_t h_sess,
|
||||
int ret;
|
||||
|
||||
if (unlikely(!h_sess || !req)) {
|
||||
- WD_ERR("cipher input sess or req is NULL!\n");
|
||||
+ WD_ERR("invalid: cipher input sess or req is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(mode == CTX_MODE_ASYNC && !req->cb)) {
|
||||
- WD_ERR("cipher req cb is NULL!\n");
|
||||
+ WD_ERR("invalid: cipher req cb is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -557,7 +557,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
||||
int ret;
|
||||
|
||||
if (unlikely(!count)) {
|
||||
- WD_ERR("wd cipher poll ctx input param is NULL!\n");
|
||||
+ WD_ERR("invalid: cipher poll ctx input param is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index fb29746..0ddc074 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -62,7 +62,7 @@ static void wd_digest_set_static_drv(void)
|
||||
{
|
||||
wd_digest_setting.driver = wd_digest_get_driver();
|
||||
if (!wd_digest_setting.driver)
|
||||
- WD_ERR("fail to get driver\n");
|
||||
+ WD_ERR("failed to get driver!\n");
|
||||
}
|
||||
#else
|
||||
static void __attribute__((constructor)) wd_digest_open_driver(void)
|
||||
@@ -70,7 +70,7 @@ static void __attribute__((constructor)) 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)
|
||||
- WD_ERR("fail to open libhisi_sec.so\n");
|
||||
+ WD_ERR("failed to open libhisi_sec.so!\n");
|
||||
}
|
||||
|
||||
static void __attribute__((destructor)) wd_digest_close_driver(void)
|
||||
@@ -252,7 +252,7 @@ static int digest_param_check(struct wd_digest_sess *sess,
|
||||
int ret;
|
||||
|
||||
if (unlikely(!sess || !req)) {
|
||||
- WD_ERR("digest input sess or req is NULL.\n");
|
||||
+ WD_ERR("invalid: digest input sess or req is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req)
|
||||
return -WD_EINVAL;
|
||||
|
||||
if (unlikely(!req->cb)) {
|
||||
- WD_ERR("digest input req cb is NULL.\n");
|
||||
+ WD_ERR("invalid: digest input req cb is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -451,7 +451,7 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
||||
int ret;
|
||||
|
||||
if (unlikely(!count)) {
|
||||
- WD_ERR("digest count is NULL.\n");
|
||||
+ WD_ERR("invalid: digest poll ctx input param is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,514 +0,0 @@
|
||||
From 6d87a3c206df306cff533d8aacf40cc5966d8441 Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Thu, 10 Mar 2022 20:29:45 +0800
|
||||
Subject: [PATCH 097/109] drv/hpre: unify print format
|
||||
|
||||
Unify print format with following rules:
|
||||
1.failed to do sth.
|
||||
2.add prefix "invalid: " for check parameters printf
|
||||
3.add "!" at the end.unify print format
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
drv/hisi_hpre.c | 125 +++++++++++++++++++++++-------------------------
|
||||
1 file changed, 60 insertions(+), 65 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
|
||||
index f1d7720..11ef78b 100644
|
||||
--- a/drv/hisi_hpre.c
|
||||
+++ b/drv/hisi_hpre.c
|
||||
@@ -134,12 +134,12 @@ static int crypto_bin_to_hpre_bin(char *dst, const char *src,
|
||||
int j;
|
||||
|
||||
if (!dst || !src || b_size <= 0 || d_size <= 0) {
|
||||
- WD_ERR("%s: trans to hpre bin parameters err!\n", p_name);
|
||||
+ WD_ERR("invalid: %s trans to hpre bin parameters err!\n", p_name);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (b_size < d_size) {
|
||||
- WD_ERR("%s: trans to hpre bin data too long!\n", p_name);
|
||||
+ WD_ERR("invalid: %s trans to hpre bin data too long!\n", p_name);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ static int hpre_bin_to_crypto_bin(char *dst, const char *src, int b_size,
|
||||
int k = 0;
|
||||
|
||||
if (!dst || !src || b_size <= 0) {
|
||||
- WD_ERR("%s trans to crypto bin: parameters err!\n", p_name);
|
||||
+ WD_ERR("invalid: %s trans to crypto bin parameters err!\n", p_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -254,10 +254,9 @@ static int fill_rsa_pubkey(struct wd_rsa_pubkey *pubkey, void **data)
|
||||
wd_rsa_get_pubkey_params(pubkey, &wd_e, &wd_n);
|
||||
ret = crypto_bin_to_hpre_bin(wd_e->data, (const char *)wd_e->data,
|
||||
wd_e->bsize, wd_e->dsize, "rsa e");
|
||||
- if (ret) {
|
||||
- WD_ERR("rsa pubkey e format fail!\n");
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
+
|
||||
ret = crypto_bin_to_hpre_bin(wd_n->data, (const char *)wd_n->data,
|
||||
wd_n->bsize, wd_n->dsize, "rsa n");
|
||||
if (ret)
|
||||
@@ -349,7 +348,7 @@ static int rsa_out_transfer(struct wd_rsa_msg *msg,
|
||||
wd_rsa_get_kg_out_crt_params(key, &qinv, &dq, &dp);
|
||||
ret = hpre_tri_bin_transfer(&qinv, &dq, &dp);
|
||||
if (ret) {
|
||||
- WD_ERR("parse rsa genkey qinv&&dq&&dp format fail!\n");
|
||||
+ WD_ERR("failed to parse rsa genkey qinv&&dq&&dp format!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -361,7 +360,7 @@ static int rsa_out_transfer(struct wd_rsa_msg *msg,
|
||||
wd_rsa_get_kg_out_params(key, &d, &n);
|
||||
ret = hpre_tri_bin_transfer(&d, &n, NULL);
|
||||
if (ret) {
|
||||
- WD_ERR("parse rsa genkey1 d&&n format fail!\n");
|
||||
+ WD_ERR("failed to parse rsa genkey1 d&&n format!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -402,7 +401,7 @@ static int rsa_prepare_key(struct wd_rsa_msg *msg,
|
||||
return ret;
|
||||
ret = wd_rsa_kg_in_data((void *)msg->key, (char **)&data);
|
||||
if (ret < 0) {
|
||||
- WD_ERR("Get rsa gen key data in fail!\n");
|
||||
+ WD_ERR("failed to get rsa gen key data!\n");
|
||||
return ret;
|
||||
}
|
||||
if (hw_msg->alg == HPRE_ALG_NC_CRT)
|
||||
@@ -410,7 +409,7 @@ static int rsa_prepare_key(struct wd_rsa_msg *msg,
|
||||
else
|
||||
hw_msg->alg = HPRE_ALG_KG_STD;
|
||||
} else {
|
||||
- WD_ERR("Invalid rsa operatin type!\n");
|
||||
+ WD_ERR("invalid: rsa operatin type %u is error!\n", req->op_type);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -546,10 +545,10 @@ static int rsa_recv(handle_t ctx, struct wd_rsa_msg *msg)
|
||||
|
||||
if (hw_msg.done != HPRE_HW_TASK_DONE ||
|
||||
hw_msg.etype || hw_msg.etype1) {
|
||||
- WD_ERR("HPRE do rsa fail!done=0x%x, etype=0x%x, etype1=0x%x\n",
|
||||
+ WD_ERR("failed to do rsa task! done=0x%x, etype=0x%x, etype1=0x%x!\n",
|
||||
hw_msg.done, hw_msg.etype, hw_msg.etype1);
|
||||
if (hw_msg.etype1 & HPRE_HW_SVA_ERROR)
|
||||
- WD_ERR("failed to SVA prefetch: status=%u\n",
|
||||
+ WD_ERR("failed to SVA prefetch: status=%u!\n",
|
||||
hw_msg.sva_status);
|
||||
if (hw_msg.done == HPRE_HW_TASK_INIT)
|
||||
msg->result = WD_EINVAL;
|
||||
@@ -559,7 +558,7 @@ static int rsa_recv(handle_t ctx, struct wd_rsa_msg *msg)
|
||||
msg->tag = LW_U16(hw_msg.low_tag);
|
||||
ret = rsa_out_transfer(msg, &hw_msg);
|
||||
if (ret) {
|
||||
- WD_ERR("qm rsa out transfer fail!\n");
|
||||
+ WD_ERR("failed to transfer out rsa BD!\n");
|
||||
msg->result = WD_OUT_EPARA;
|
||||
} else {
|
||||
msg->result = WD_SUCCESS;
|
||||
@@ -591,14 +590,14 @@ static int fill_dh_xp_params(struct wd_dh_msg *msg,
|
||||
ret = crypto_bin_to_hpre_bin(x, (const char *)x,
|
||||
msg->key_bytes, req->xbytes, "dh x");
|
||||
if (ret) {
|
||||
- WD_ERR("dh x para format fail!\n");
|
||||
+ WD_ERR("failed to transfer dh x para format to hpre bin!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = crypto_bin_to_hpre_bin(p, (const char *)p,
|
||||
msg->key_bytes, req->pbytes, "dh p");
|
||||
if (ret) {
|
||||
- WD_ERR("dh p para format fail!\n");
|
||||
+ WD_ERR("failed to transfer dh p para format to hpre bin!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -654,7 +653,7 @@ static int dh_send(handle_t ctx, struct wd_dh_msg *msg)
|
||||
(const char *)msg->g, msg->key_bytes,
|
||||
msg->gbytes, "dh g");
|
||||
if (ret) {
|
||||
- WD_ERR("dh g para format fail!\n");
|
||||
+ WD_ERR("failed to transfer dh g para format to hpre bin!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -688,10 +687,10 @@ static int dh_recv(handle_t ctx, struct wd_dh_msg *msg)
|
||||
|
||||
if (hw_msg.done != HPRE_HW_TASK_DONE ||
|
||||
hw_msg.etype || hw_msg.etype1) {
|
||||
- WD_ERR("HPRE do dh fail!done=0x%x, etype=0x%x, etype1=0x%x\n",
|
||||
+ WD_ERR("failed to do dh task! done=0x%x, etype=0x%x, etype1=0x%x!\n",
|
||||
hw_msg.done, hw_msg.etype, hw_msg.etype1);
|
||||
if (hw_msg.etype1 & HPRE_HW_SVA_ERROR)
|
||||
- WD_ERR("failed to SVA prefetch: status=%u\n",
|
||||
+ WD_ERR("failed to SVA prefetch: status=%u!\n",
|
||||
hw_msg.sva_status);
|
||||
if (hw_msg.done == HPRE_HW_TASK_INIT)
|
||||
msg->result = WD_EINVAL;
|
||||
@@ -701,7 +700,7 @@ static int dh_recv(handle_t ctx, struct wd_dh_msg *msg)
|
||||
msg->tag = LW_U16(hw_msg.low_tag);
|
||||
ret = dh_out_transfer(msg, &hw_msg);
|
||||
if (ret) {
|
||||
- WD_ERR("dh out transfer fail!\n");
|
||||
+ WD_ERR("failed to transfer out dh BD!\n");
|
||||
msg->result = WD_OUT_EPARA;
|
||||
} else {
|
||||
msg->result = WD_SUCCESS;
|
||||
@@ -1021,7 +1020,7 @@ static int ecc_prepare_sign_in(struct wd_ecc_msg *msg,
|
||||
int ret;
|
||||
|
||||
if (!in->dgst_set) {
|
||||
- WD_ERR("prepare sign_in, hash not set!\n");
|
||||
+ WD_ERR("invalid: prepare sign_in, hash not set!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1029,17 +1028,17 @@ static int ecc_prepare_sign_in(struct wd_ecc_msg *msg,
|
||||
k = &in->k;
|
||||
if (!in->k_set) {
|
||||
if (msg->req.op_type == WD_ECDSA_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)) {
|
||||
- WD_ERR("ecc sign in k all zero!\n");
|
||||
+ WD_ERR("invalid: ecc sign in k all zero!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (is_all_zero(e, msg)) {
|
||||
- WD_ERR("ecc sign in e all zero!\n");
|
||||
+ WD_ERR("invalid: ecc sign in e all zero!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1072,7 +1071,7 @@ static int ecc_prepare_verf_in(struct wd_ecc_msg *msg,
|
||||
int ret;
|
||||
|
||||
if (!vin->dgst_set) {
|
||||
- WD_ERR("prepare verf_in, hash not set!\n");
|
||||
+ WD_ERR("invalid: prepare verf_in, hash not set!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1081,7 +1080,7 @@ static int ecc_prepare_verf_in(struct wd_ecc_msg *msg,
|
||||
r = &vin->r;
|
||||
|
||||
if (is_all_zero(e, msg)) {
|
||||
- WD_ERR("ecc verf in e all zero!\n");
|
||||
+ WD_ERR("invalid: ecc verf in e all zero!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1182,17 +1181,13 @@ static int ecc_prepare_dh_compute_in(struct wd_ecc_msg *msg,
|
||||
|
||||
ret = crypto_bin_to_hpre_bin(pbk->x.data, (const char *)pbk->x.data,
|
||||
pbk->x.bsize, pbk->x.dsize, "ecdh compute x");
|
||||
- if (ret) {
|
||||
- WD_ERR("ecc dh compute in x format fail!\n");
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
|
||||
ret = crypto_bin_to_hpre_bin(pbk->y.data, (const char *)pbk->y.data,
|
||||
pbk->y.bsize, pbk->y.dsize, "ecdh compute y");
|
||||
- if (ret) {
|
||||
- WD_ERR("ecc dh compute in y format fail!\n");
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
|
||||
*data = pbk->x.data;
|
||||
|
||||
@@ -1221,12 +1216,12 @@ static int u_is_in_p(struct wd_ecc_msg *msg)
|
||||
if (msg->curve_id == WD_X25519)
|
||||
pbk->x.data[0] &= 0x7f;
|
||||
if (!less_than_latter(&pbk->x, p)) {
|
||||
- WD_ERR("ux is out of p!\n");
|
||||
+ WD_ERR("invalid: ux is out of p!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (is_all_zero(&pbk->x, msg)) {
|
||||
- WD_ERR("ux is zero!\n");
|
||||
+ WD_ERR("invalid: ux is zero!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1342,7 +1337,7 @@ static int ecc_prepare_iot(struct wd_ecc_msg *msg,
|
||||
ecc_get_io_len(hw_msg->alg, kbytes, &i_sz, &o_sz);
|
||||
ret = ecc_prepare_in(msg, hw_msg, &data);
|
||||
if (ret) {
|
||||
- WD_ERR("ecc_prepare_in fail!\n");
|
||||
+ WD_ERR("failed to prepare ecc in!\n");
|
||||
return ret;
|
||||
}
|
||||
hw_msg->low_in = LW_U32((uintptr_t)data);
|
||||
@@ -1350,7 +1345,7 @@ static int ecc_prepare_iot(struct wd_ecc_msg *msg,
|
||||
|
||||
ret = ecc_prepare_out(msg, &data);
|
||||
if (ret) {
|
||||
- WD_ERR("ecc_prepare_out fail!\n");
|
||||
+ WD_ERR("failed to prepare ecc out!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1374,7 +1369,7 @@ static __u32 get_hw_keysz(__u32 ksz)
|
||||
else if (ksz <= BITS_TO_BYTES(576))
|
||||
size = BITS_TO_BYTES(576);
|
||||
else
|
||||
- WD_ERR("failed to get hw keysize : ksz = %u.\n", ksz);
|
||||
+ WD_ERR("invalid: keysize %u is error!\n", ksz);
|
||||
|
||||
return size;
|
||||
}
|
||||
@@ -1408,12 +1403,12 @@ static int set_param(struct wd_dtb *dst, const struct wd_dtb *src,
|
||||
const char *p_name)
|
||||
{
|
||||
if (unlikely(!src || !src->data)) {
|
||||
- WD_ERR("%s: src or data NULL!\n", p_name);
|
||||
+ WD_ERR("invalid: %s src or data NULL!\n", p_name);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(!src->dsize || src->dsize > dst->bsize)) {
|
||||
- WD_ERR("%s: src dsz = %u error, dst bsz = %u!\n",
|
||||
+ WD_ERR("invalid: %s src dsz %u, dst bsz %u is error!\n",
|
||||
p_name, src->dsize, dst->bsize);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -1470,13 +1465,13 @@ static struct wd_ecc_out *create_ecdh_out(struct wd_ecc_msg *msg)
|
||||
struct wd_ecc_out *out;
|
||||
|
||||
if (!hsz) {
|
||||
- WD_ERR("get msg key size error!\n");
|
||||
+ WD_ERR("failed to get msg key size!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out = malloc(len);
|
||||
if (!out) {
|
||||
- WD_ERR("failed to alloc, sz = %u!\n", len);
|
||||
+ WD_ERR("failed to alloc out memory, sz = %u!\n", len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1527,13 +1522,13 @@ static struct wd_ecc_msg *create_req(struct wd_ecc_msg *src, __u8 req_idx)
|
||||
|
||||
dst = malloc(sizeof(*dst) + sizeof(*src));
|
||||
if (unlikely(!dst)) {
|
||||
- WD_ERR("failed to alloc dst\n");
|
||||
+ WD_ERR("failed to alloc dst!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ecc_key = malloc(sizeof(*ecc_key) + sizeof(*prikey));
|
||||
if (unlikely(!ecc_key)) {
|
||||
- WD_ERR("failed to alloc ecc_key\n");
|
||||
+ WD_ERR("failed to alloc ecc_key!\n");
|
||||
goto fail_alloc_key;
|
||||
}
|
||||
|
||||
@@ -1541,7 +1536,7 @@ static struct wd_ecc_msg *create_req(struct wd_ecc_msg *src, __u8 req_idx)
|
||||
ecc_key->prikey = prikey;
|
||||
prikey->data = malloc(ECC_PRIKEY_SZ(src->key_bytes));
|
||||
if (unlikely(!prikey->data)) {
|
||||
- WD_ERR("failed to alloc prikey data\n");
|
||||
+ WD_ERR("failed to alloc prikey data!\n");
|
||||
goto fail_alloc_key_data;
|
||||
}
|
||||
init_prikey(prikey, src->key_bytes);
|
||||
@@ -1551,7 +1546,7 @@ static struct wd_ecc_msg *create_req(struct wd_ecc_msg *src, __u8 req_idx)
|
||||
|
||||
ret = init_req(dst, src, ecc_key, req_idx);
|
||||
if (unlikely(ret)) {
|
||||
- WD_ERR("failed to init req, ret = %d\n", ret);
|
||||
+ WD_ERR("failed to init req, ret = %d!\n", ret);
|
||||
goto fail_set_prikey;
|
||||
}
|
||||
|
||||
@@ -1602,12 +1597,12 @@ static int ecc_fill(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
|
||||
|
||||
if (unlikely(!op_type || (op_type >= WD_EC_OP_MAX &&
|
||||
op_type != HPRE_SM2_ENC && op_type != HPRE_SM2_DEC))) {
|
||||
- WD_ERR("op_type = %u error!\n", op_type);
|
||||
+ WD_ERR("invalid: input op_type %u is error!\n", op_type);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (!hw_sz) {
|
||||
- WD_ERR("get msg key size error!\n");
|
||||
+ WD_ERR("failed to get msg key size!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1666,12 +1661,12 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
|
||||
return ecc_general_send(ctx, msg);
|
||||
|
||||
if (unlikely(!ein->k_set)) {
|
||||
- WD_ERR("error: k not set\n");
|
||||
+ WD_ERR("invalid: k not set!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(!hash->cb || hash->type >= WD_HASH_MAX)) {
|
||||
- WD_ERR("hash parameter error, type = %u\n", hash->type);
|
||||
+ WD_ERR("invalid: input hash type %u is error!\n", hash->type);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1682,19 +1677,19 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
|
||||
*/
|
||||
ret = split_req(msg, msg_dst);
|
||||
if (unlikely(ret)) {
|
||||
- WD_ERR("failed to split req, ret = %d\n", ret);
|
||||
+ WD_ERR("failed to split req, ret = %d!\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = ecc_fill(msg_dst[0], &hw_msg[0]);
|
||||
if (unlikely(ret)) {
|
||||
- WD_ERR("failed to fill 1th sqe, ret = %d\n", ret);
|
||||
+ WD_ERR("failed to fill 1th sqe, ret = %d!\n", ret);
|
||||
goto fail_fill_sqe;
|
||||
}
|
||||
|
||||
ret = ecc_fill(msg_dst[1], &hw_msg[1]);
|
||||
if (unlikely(ret)) {
|
||||
- WD_ERR("failed to fill 2th sqe, ret = %d\n", ret);
|
||||
+ WD_ERR("failed to fill 2th sqe, ret = %d!\n", ret);
|
||||
goto fail_fill_sqe;
|
||||
}
|
||||
|
||||
@@ -1725,7 +1720,7 @@ static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg)
|
||||
return ecc_general_send(ctx, msg);
|
||||
|
||||
if (unlikely(!hash->cb || hash->type >= WD_HASH_MAX)) {
|
||||
- WD_ERR("hash parameter error, type = %u\n", hash->type);
|
||||
+ WD_ERR("invalid: input hash type %u is error!\n", hash->type);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1779,7 +1774,7 @@ static int ecdh_out_transfer(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_ms
|
||||
|
||||
ret = hpre_tri_bin_transfer(&key->x, y, NULL);
|
||||
if (ret) {
|
||||
- WD_ERR("parse ecdh out format fail!\n");
|
||||
+ WD_ERR("failed to transfer ecdh format to crypto bin!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1889,7 +1884,7 @@ static int ecc_out_transfer(struct wd_ecc_msg *msg,
|
||||
hw_msg->alg == HPRE_ALG_X_DH_MULTIPLY)
|
||||
ret = ecdh_out_transfer(msg, hw_msg);
|
||||
else
|
||||
- WD_ERR("ecc out trans fail algorithm %u error!\n", hw_msg->alg);
|
||||
+ WD_ERR("invalid: algorithm type %u is error!\n", hw_msg->alg);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1921,7 +1916,7 @@ static __u32 get_hash_bytes(__u8 type)
|
||||
val = BITS_TO_BYTES(512);
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("get hash bytes: type %u error!\n", type);
|
||||
+ WD_ERR("invalid: hash type %u is error!\n", type);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1977,7 +1972,7 @@ static int sm2_kdf(struct wd_dtb *out, struct wd_ecc_point *x2y2,
|
||||
t_out = m_len >= h_bytes ? tmp : p_out;
|
||||
ret = hash->cb(p_in, in_len, t_out, h_bytes, hash->usr);
|
||||
if (ret) {
|
||||
- WD_ERR("failed to hash cb, ret = %d!\n", ret);
|
||||
+ WD_ERR("%s failed to do hash cb, ret = %d!\n", __func__, ret);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2041,7 +2036,7 @@ static int sm2_hash(struct wd_dtb *out, struct wd_ecc_point *x2y2,
|
||||
msg_pack(p_in, &in_len, x2y2->y.data, x2y2->y.dsize);
|
||||
ret = hash->cb(p_in, in_len, hash_out, h_bytes, hash->usr);
|
||||
if (unlikely(ret)) {
|
||||
- WD_ERR("failed to hash cb, ret = %d!\n", ret);
|
||||
+ WD_ERR("%s failed to do hash cb, ret = %d!\n", __func__, ret);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -2088,7 +2083,7 @@ static int sm2_convert_enc_out(struct wd_ecc_msg *src,
|
||||
/* C3 = hash(x2 || M || y2) */
|
||||
ret = sm2_hash(&eout->c3, &x2y2, &ein->plaintext, hash);
|
||||
if (unlikely(ret)) {
|
||||
- WD_ERR("failed to sm2 hash, ret = %d!\n", ret);
|
||||
+ WD_ERR("failed to do sm2 hash, ret = %d!\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -2096,7 +2091,7 @@ static int sm2_convert_enc_out(struct wd_ecc_msg *src,
|
||||
kdf_out = &eout->c2;
|
||||
ret = sm2_kdf(kdf_out, &x2y2, ein->plaintext.dsize, hash);
|
||||
if (unlikely(ret)) {
|
||||
- WD_ERR("failed to sm2 kdf, ret = %d!\n", ret);
|
||||
+ WD_ERR("%s failed to do sm2 kdf, ret = %d!\n", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -2138,7 +2133,7 @@ static int sm2_convert_dec_out(struct wd_ecc_msg *src,
|
||||
/* t = KDF(x2 || y2, klen) */
|
||||
ret = sm2_kdf(&dout->plaintext, &x2y2, din->c2.dsize, &src->hash);
|
||||
if (unlikely(ret)) {
|
||||
- WD_ERR("failed to sm2 kdf, ret = %d!\n", ret);
|
||||
+ WD_ERR("%s failed to do sm2 kdf, ret = %d!\n", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -2166,10 +2161,10 @@ static int ecc_sqe_parse(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
|
||||
|
||||
if (hw_msg->done != HPRE_HW_TASK_DONE ||
|
||||
hw_msg->etype || hw_msg->etype1) {
|
||||
- WD_ERR("HPRE do ecc fail!done=0x%x, etype=0x%x, etype1=0x%x\n",
|
||||
+ WD_ERR("failed to do ecc task! done=0x%x, etype=0x%x, etype1=0x%x!\n",
|
||||
hw_msg->done, hw_msg->etype, hw_msg->etype1);
|
||||
if (hw_msg->etype1 & HPRE_HW_SVA_ERROR)
|
||||
- WD_ERR("failed to SVA prefetch: status=%u\n",
|
||||
+ WD_ERR("failed to SVA prefetch: status=%u!\n",
|
||||
hw_msg->sva_status);
|
||||
|
||||
if (hw_msg->done == HPRE_HW_TASK_INIT)
|
||||
@@ -2181,7 +2176,7 @@ static int ecc_sqe_parse(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
|
||||
ret = ecc_out_transfer(msg, hw_msg);
|
||||
if (ret) {
|
||||
msg->result = WD_OUT_EPARA;
|
||||
- WD_ERR("ecc out transfer fail!\n");
|
||||
+ WD_ERR("failed to transfer out ecc BD, ret = %d!\n", ret);
|
||||
}
|
||||
msg->tag = LW_U16(hw_msg->low_tag);
|
||||
}
|
||||
@@ -2247,7 +2242,7 @@ static int sm2_enc_parse(handle_t h_qp,
|
||||
hw_msg->low_tag = 0; /* use sync mode */
|
||||
ret = ecc_sqe_parse(first, hw_msg);
|
||||
if (ret) {
|
||||
- WD_ERR("failed to parse first BD, ret = %d\n", ret);
|
||||
+ WD_ERR("failed to parse first BD, ret = %d!\n", ret);
|
||||
goto free_first;
|
||||
}
|
||||
|
||||
@@ -2291,7 +2286,7 @@ static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
|
||||
hw_msg->low_tag = 0; /* use sync mode */
|
||||
ret = ecc_sqe_parse(dst, hw_msg);
|
||||
if (ret) {
|
||||
- WD_ERR("failed to parse decode BD, ret = %d\n", ret);
|
||||
+ WD_ERR("failed to parse decode BD, ret = %d!\n", ret);
|
||||
goto fail;
|
||||
}
|
||||
msg->result = dst->result;
|
||||
--
|
||||
2.27.0
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,66 +0,0 @@
|
||||
From e4ed630c442a7a5affb14dbcd70f20cbeaf6d969 Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Thu, 10 Mar 2022 20:29:47 +0800
|
||||
Subject: [PATCH 099/109] drv/hpre: free memory when BD sends failed
|
||||
|
||||
When BD fails to send to the hardware, the requested
|
||||
memory needs to be freed.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
drv/hisi_hpre.c | 23 +++++++++++++++++++----
|
||||
1 file changed, 19 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
|
||||
index 11ef78b..e46efef 100644
|
||||
--- a/drv/hisi_hpre.c
|
||||
+++ b/drv/hisi_hpre.c
|
||||
@@ -1699,7 +1699,11 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
|
||||
goto fail_fill_sqe;
|
||||
}
|
||||
|
||||
- return hisi_qm_send(h_qp, &hw_msg, SM2_SQE_NUM, &send_cnt);
|
||||
+ ret = hisi_qm_send(h_qp, &hw_msg, SM2_SQE_NUM, &send_cnt);
|
||||
+ if (unlikely(ret))
|
||||
+ goto fail_fill_sqe;
|
||||
+
|
||||
+ return ret;
|
||||
|
||||
fail_fill_sqe:
|
||||
free_req(msg_dst[0]);
|
||||
@@ -1713,6 +1717,7 @@ static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg)
|
||||
struct wd_sm2_dec_in *din = (void *)msg->req.src;
|
||||
struct wd_hash_mt *hash = &msg->hash;
|
||||
struct wd_ecc_msg *dst;
|
||||
+ int ret;
|
||||
|
||||
/* c2 data lens <= 4096 bit */
|
||||
if (din->c2.dsize <= BITS_TO_BYTES(4096) &&
|
||||
@@ -1739,11 +1744,21 @@ static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg)
|
||||
/* dst->req.dst last store point "struct wd_ecc_msg *" */
|
||||
dst->req.dst = create_ecdh_out(dst);
|
||||
if (unlikely(!dst->req.dst)) {
|
||||
- free(dst);
|
||||
- return -WD_ENOMEM;
|
||||
+ ret = -WD_ENOMEM;
|
||||
+ goto free_dst;
|
||||
}
|
||||
|
||||
- return ecc_general_send(ctx, dst);
|
||||
+ ret = ecc_general_send(ctx, dst);
|
||||
+ if (unlikely(ret))
|
||||
+ goto free_req_dst;
|
||||
+
|
||||
+ return ret;
|
||||
+
|
||||
+free_req_dst:
|
||||
+ free(dst->req.dst);
|
||||
+free_dst:
|
||||
+ free(dst);
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
static int ecc_send(handle_t ctx, struct wd_ecc_msg *msg)
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
From 608b4ff6c4c5942d51086781956d36629465ca56 Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Thu, 10 Mar 2022 20:29:48 +0800
|
||||
Subject: [PATCH 100/109] v1/hpre: add unlikely() for branch prefetch
|
||||
|
||||
Add unlikely() on the route of doing request to improve
|
||||
branch prefetch success rate.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
v1/drv/hisi_hpre_udrv.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c
|
||||
index ba32114..bd87cbe 100644
|
||||
--- a/v1/drv/hisi_hpre_udrv.c
|
||||
+++ b/v1/drv/hisi_hpre_udrv.c
|
||||
@@ -1976,7 +1976,7 @@ static int fill_sm2_dec_sqe(void *message, struct qm_queue_info *info, __u16 i)
|
||||
}
|
||||
|
||||
ret = qm_fill_ecc_sqe_general(dst, info, i);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
goto free_out;
|
||||
|
||||
return ret;
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,207 +0,0 @@
|
||||
From e308fbdd62bb7a59b1550ed748b85cc79cfc2019 Mon Sep 17 00:00:00 2001
|
||||
From: Yang Shen <shenyang39@huawei.com>
|
||||
Date: Thu, 10 Mar 2022 20:29:49 +0800
|
||||
Subject: [PATCH 101/109] comp: unify print format
|
||||
|
||||
Unify print format with following rules:
|
||||
1.failed to do sth.
|
||||
2.add prefix "invalid: " for check parameters printf
|
||||
3.add "!" at the end.
|
||||
|
||||
Signed-off-by: Yang Shen <shenyang39@huawei.com>
|
||||
---
|
||||
wd_comp.c | 46 ++++++++++++++++++++++------------------------
|
||||
1 file changed, 22 insertions(+), 24 deletions(-)
|
||||
|
||||
diff --git a/wd_comp.c b/wd_comp.c
|
||||
index 8d0c603..de71e9c 100644
|
||||
--- a/wd_comp.c
|
||||
+++ b/wd_comp.c
|
||||
@@ -60,14 +60,14 @@ static void wd_comp_set_static_drv(void)
|
||||
{
|
||||
wd_comp_setting.driver = wd_comp_get_driver();
|
||||
if (!wd_comp_setting.driver)
|
||||
- WD_ERR("fail to get driver\n");
|
||||
+ WD_ERR("failed to get driver!\n");
|
||||
}
|
||||
#else
|
||||
static void __attribute__((constructor)) wd_comp_open_driver(void)
|
||||
{
|
||||
wd_comp_setting.dlhandle = dlopen("libhisi_zip.so", RTLD_NOW);
|
||||
if (!wd_comp_setting.dlhandle)
|
||||
- WD_ERR("Fail to open libhisi_zip.so\n");
|
||||
+ WD_ERR("failed to open libhisi_zip.so!\n");
|
||||
}
|
||||
|
||||
static void __attribute__((destructor)) wd_comp_close_driver(void)
|
||||
@@ -88,12 +88,12 @@ int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
int ret;
|
||||
|
||||
if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) {
|
||||
- WD_ERR("invalid params, config or sched is NULL!\n");
|
||||
+ WD_ERR("invalid: config or sched is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (!wd_is_sva(config->ctxs[0].ctx)) {
|
||||
- WD_ERR("err, non sva, please check system!\n");
|
||||
+ WD_ERR("failed to find sva device, please check system!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
||||
int ret;
|
||||
|
||||
if (unlikely(!count)) {
|
||||
- WD_ERR("comp poll input count is NULL\n");
|
||||
+ WD_ERR("invalid: comp poll count is 0!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
||||
priv);
|
||||
if (ret < 0) {
|
||||
if (ret == -WD_HW_EACCESS)
|
||||
- WD_ERR("wd comp recv hw err!\n");
|
||||
+ WD_ERR("wd comp recv hw error!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
||||
msg = wd_find_msg_in_pool(&wd_comp_setting.pool, idx,
|
||||
resp_msg.tag);
|
||||
if (!msg) {
|
||||
- WD_ERR("get msg from pool is NULL!\n");
|
||||
+ WD_ERR("failed to get msg from pool!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -341,7 +341,7 @@ static int wd_comp_check_buffer(struct wd_comp_req *req)
|
||||
}
|
||||
} else if (req->data_fmt == WD_SGL_BUF) {
|
||||
if (!req->list_src || !req->list_dst) {
|
||||
- WD_ERR("invalid: src or dst is NULL!\n");
|
||||
+ WD_ERR("invalid: list_src or list_dst is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
}
|
||||
@@ -381,17 +381,17 @@ static int wd_comp_check_params(struct wd_comp_sess *sess,
|
||||
}
|
||||
|
||||
if (mode == CTX_MODE_ASYNC && !req->cb) {
|
||||
- WD_ERR("async comp input cb is NULL!\n");
|
||||
+ WD_ERR("invalid: async comp cb is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (mode == CTX_MODE_ASYNC && !req->cb_param) {
|
||||
- WD_ERR("async comp input cb param is NULL!\n");
|
||||
+ WD_ERR("invalid: async comp cb param is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (mode == CTX_MODE_SYNC && req->cb) {
|
||||
- WD_ERR("sync comp input cb should be NULL!\n");
|
||||
+ WD_ERR("invalid: sync comp cb should be NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -409,6 +409,7 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess,
|
||||
__u64 recv_count = 0;
|
||||
__u32 idx;
|
||||
int ret;
|
||||
+
|
||||
idx = wd_comp_setting.sched.pick_next_ctx(h_sched_ctx,
|
||||
sess->sched_key,
|
||||
CTX_MODE_SYNC);
|
||||
@@ -423,7 +424,7 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess,
|
||||
ret = wd_comp_setting.driver->comp_send(ctx->ctx, msg, priv);
|
||||
if (ret < 0) {
|
||||
pthread_spin_unlock(&ctx->lock);
|
||||
- WD_ERR("wd comp send err(%d)!\n", ret);
|
||||
+ WD_ERR("wd comp send error, ret = %d!\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -431,17 +432,17 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess,
|
||||
if (msg->is_polled) {
|
||||
ret = wd_ctx_wait(ctx->ctx, POLL_TIME);
|
||||
if (ret < 0)
|
||||
- WD_ERR("wd ctx wait timeout(%d)!\n", ret);
|
||||
+ WD_ERR("wd ctx wait timeout, ret = %d!\n", ret);
|
||||
}
|
||||
ret = wd_comp_setting.driver->comp_recv(ctx->ctx, msg, priv);
|
||||
if (ret == -WD_HW_EACCESS) {
|
||||
pthread_spin_unlock(&ctx->lock);
|
||||
- WD_ERR("wd comp recv hw err!\n");
|
||||
+ WD_ERR("wd comp recv hw error!\n");
|
||||
return ret;
|
||||
} else if (ret == -WD_EAGAIN) {
|
||||
if (++recv_count > MAX_RETRY_COUNTS) {
|
||||
pthread_spin_unlock(&ctx->lock);
|
||||
- WD_ERR("wd comp recv timeout fail!\n");
|
||||
+ WD_ERR("wd comp recv timeout!\n");
|
||||
return -WD_ETIMEDOUT;
|
||||
}
|
||||
}
|
||||
@@ -523,8 +524,7 @@ int wd_do_comp_sync2(handle_t h_sess, struct wd_comp_req *req)
|
||||
|
||||
ret = wd_do_comp_strm(h_sess, &strm_req);
|
||||
if (ret < 0 || strm_req.status == WD_IN_EPARA) {
|
||||
- WD_ERR("wd comp, invalid or incomplete data! "
|
||||
- "ret(%d), req.status(%u)\n",
|
||||
+ WD_ERR("wd comp, invalid or incomplete data! ret = %d, status = %u!\n",
|
||||
ret, strm_req.status);
|
||||
return ret;
|
||||
}
|
||||
@@ -622,10 +622,8 @@ int wd_do_comp_strm(handle_t h_sess, struct wd_comp_req *req)
|
||||
int ret;
|
||||
|
||||
ret = wd_comp_check_params(sess, req, CTX_MODE_SYNC);
|
||||
- if (ret) {
|
||||
- WD_ERR("fail to check params!\n");
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
|
||||
if (req->data_fmt > WD_FLAT_BUF) {
|
||||
WD_ERR("invalid: data_fmt is %d!\n", req->data_fmt);
|
||||
@@ -696,7 +694,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
|
||||
|
||||
tag = wd_get_msg_from_pool(&wd_comp_setting.pool, idx, (void **)&msg);
|
||||
if (tag < 0) {
|
||||
- WD_ERR("busy, failed to get msg from pool!\n");
|
||||
+ WD_ERR("failed to get msg from pool!\n");
|
||||
return -WD_EBUSY;
|
||||
}
|
||||
fill_comp_msg(sess, msg, req);
|
||||
@@ -709,7 +707,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
|
||||
ret = wd_comp_setting.driver->comp_send(ctx->ctx, msg, priv);
|
||||
if (ret < 0) {
|
||||
pthread_spin_unlock(&ctx->lock);
|
||||
- WD_ERR("wd comp send err(%d)!\n", ret);
|
||||
+ WD_ERR("wd comp send error, ret = %d!\n", ret);
|
||||
goto fail_with_msg;
|
||||
}
|
||||
|
||||
@@ -780,7 +778,7 @@ int wd_comp_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
|
||||
int ret;
|
||||
|
||||
if (type >= WD_DIR_MAX) {
|
||||
- WD_ERR("wrong type(%u))!\n", type);
|
||||
+ WD_ERR("invalid: op_type is %u!\n", type);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -804,7 +802,7 @@ int wd_comp_get_env_param(__u32 node, __u32 type, __u32 mode,
|
||||
int ret;
|
||||
|
||||
if (type >= WD_DIR_MAX) {
|
||||
- WD_ERR("wrong type(%u))!\n", type);
|
||||
+ WD_ERR("invalid: op_type is %u!\n", type);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,217 +0,0 @@
|
||||
From be7121984d223d146348ede53626b0afb1026256 Mon Sep 17 00:00:00 2001
|
||||
From: Yang Shen <shenyang39@huawei.com>
|
||||
Date: Thu, 10 Mar 2022 20:29:50 +0800
|
||||
Subject: [PATCH 102/109] drv/comp: unify print format
|
||||
|
||||
Unify print format with following rules:
|
||||
1.failed to do sth.
|
||||
2.add prefix "invalid: " for check parameters printf
|
||||
3.add "!" at the end.
|
||||
|
||||
Signed-off-by: Yang Shen <shenyang39@huawei.com>
|
||||
---
|
||||
drv/hisi_comp.c | 50 +++++++++++++++++++++++++------------------------
|
||||
1 file changed, 26 insertions(+), 24 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
|
||||
index 0760908..5883bb4 100644
|
||||
--- a/drv/hisi_comp.c
|
||||
+++ b/drv/hisi_comp.c
|
||||
@@ -192,12 +192,12 @@ struct hisi_zip_ctx {
|
||||
static int buf_size_check_deflate(__u32 *in_size, __u32 *out_size)
|
||||
{
|
||||
if (unlikely(*in_size > HZ_MAX_SIZE)) {
|
||||
- WD_ERR("invalid: out of range in_len(%u)!\n", *in_size);
|
||||
+ WD_ERR("invalid: in_len(%u) is out of range!\n", *in_size);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(*out_size > HZ_MAX_SIZE)) {
|
||||
- WD_ERR("warning: out of range avail_out(%u), will set 8MB size max!\n",
|
||||
+ WD_ERR("warning: avail_out(%u) is out of range, will set 8MB size max!\n",
|
||||
*out_size);
|
||||
*out_size = HZ_MAX_SIZE;
|
||||
}
|
||||
@@ -295,19 +295,19 @@ static int fill_buf_addr_deflate_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
|
||||
h_sgl_pool = hisi_qm_get_sglpool(h_qp);
|
||||
if (!h_sgl_pool) {
|
||||
- WD_ERR("failed to get sglpool\n");
|
||||
+ WD_ERR("failed to get sglpool!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_src);
|
||||
if (!hw_sgl_in) {
|
||||
- WD_ERR("failed to get hw sgl in\n");
|
||||
+ WD_ERR("failed to get hw sgl in!\n");
|
||||
return -WD_ENOMEM;
|
||||
}
|
||||
|
||||
hw_sgl_out = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_dst);
|
||||
if (!hw_sgl_out) {
|
||||
- WD_ERR("failed to get hw sgl out\n");
|
||||
+ WD_ERR("failed to get hw sgl out!\n");
|
||||
hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_in);
|
||||
return -WD_ENOMEM;
|
||||
}
|
||||
@@ -419,17 +419,18 @@ static int fill_buf_lz77_zstd(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
void *ctx_buf = NULL;
|
||||
|
||||
if (unlikely(!data)) {
|
||||
- WD_ERR("wd_lz77_zstd_data address is NULL\n");
|
||||
+ WD_ERR("invalid: wd_lz77_zstd_data address is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(in_size > ZSTD_MAX_SIZE)) {
|
||||
- WD_ERR("invalid input data size of lz77_zstd(%u)\n", in_size);
|
||||
+ WD_ERR("invalid: in_len(%u) of lz77_zstd is out of range!\n",
|
||||
+ in_size);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(out_size > HZ_MAX_SIZE)) {
|
||||
- WD_ERR("warning: out of range avail_out(%u), will set 8MB size max!\n",
|
||||
+ WD_ERR("warning: avail_out(%u) is out of range , will set 8MB size max!\n",
|
||||
out_size);
|
||||
out_size = HZ_MAX_SIZE;
|
||||
}
|
||||
@@ -439,7 +440,7 @@ static int fill_buf_lz77_zstd(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
* the frequency information about input data.
|
||||
*/
|
||||
if (unlikely(out_size < ZSTD_FREQ_DATA_SIZE + lit_size)) {
|
||||
- WD_ERR("output buffer size of lz77_zstd is not enough(%u)\n",
|
||||
+ WD_ERR("invalid: sequences output size(%u) is not enough!\n",
|
||||
ZSTD_FREQ_DATA_SIZE + in_size);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -491,12 +492,13 @@ static int fill_buf_lz77_zstd_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
int ret;
|
||||
|
||||
if (unlikely(in_size > ZSTD_MAX_SIZE)) {
|
||||
- WD_ERR("invalid input data size of lz77_zstd(%u)\n", in_size);
|
||||
+ WD_ERR("invalid: in_len(%u) of lz77_zstd is out of range!\n",
|
||||
+ in_size);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
if (unlikely(!data)) {
|
||||
- WD_ERR("wd_lz77_zstd_data address is NULL\n");
|
||||
+ WD_ERR("invalid: wd_lz77_zstd_data address is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -513,26 +515,26 @@ static int fill_buf_lz77_zstd_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
|
||||
h_sgl_pool = hisi_qm_get_sglpool(h_qp);
|
||||
if (!h_sgl_pool) {
|
||||
- WD_ERR("failed to get sglpool\n");
|
||||
+ WD_ERR("failed to get sglpool!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_src);
|
||||
if (!hw_sgl_in) {
|
||||
- WD_ERR("failed to get hw sgl in\n");
|
||||
+ WD_ERR("failed to get hw sgl in!\n");
|
||||
return -WD_ENOMEM;
|
||||
}
|
||||
|
||||
hw_sgl_out_lit = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_dst);
|
||||
if (!hw_sgl_out_lit) {
|
||||
- WD_ERR("failed to get hw sgl out for literals\n");
|
||||
+ WD_ERR("failed to get hw sgl out for literals!\n");
|
||||
ret = -WD_ENOMEM;
|
||||
goto err_free_sgl_in;
|
||||
}
|
||||
|
||||
hw_sgl_out_seq = hisi_qm_get_hw_sgl(h_sgl_pool, seq_start);
|
||||
if (!hw_sgl_out_seq) {
|
||||
- WD_ERR("failed to get hw sgl out for sequences\n");
|
||||
+ WD_ERR("failed to get hw sgl out for sequences!\n");
|
||||
ret = -WD_ENOMEM;
|
||||
goto err_free_sgl_out_lit;
|
||||
}
|
||||
@@ -626,7 +628,7 @@ static int fill_comp_level_lz77_zstd(struct hisi_zip_sqe *sqe, enum wd_comp_leve
|
||||
sqe->dw9 = val;
|
||||
break;
|
||||
default:
|
||||
- WD_ERR("invalid: comp_lv in unsupported (%d)\n", comp_lv);
|
||||
+ WD_ERR("invalid: comp_lv(%d) is unsupport!\n", comp_lv);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -821,7 +823,7 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
|
||||
|
||||
if ((hw_type <= HISI_QM_API_VER2_BASE && alg_type > WD_GZIP) ||
|
||||
(hw_type >= HISI_QM_API_VER3_BASE && alg_type >= WD_COMP_ALG_MAX)) {
|
||||
- WD_ERR("invalid algorithm type(%d)\n", alg_type);
|
||||
+ WD_ERR("invalid: algorithm type is %d!\n", alg_type);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -870,13 +872,13 @@ static int hisi_zip_comp_send(handle_t ctx, struct wd_comp_msg *msg, void *priv)
|
||||
|
||||
ret = fill_zip_comp_sqe(qp, msg, &sqe);
|
||||
if (ret < 0) {
|
||||
- WD_ERR("failed to fill zip sqe(%d)!\n", ret);
|
||||
+ WD_ERR("failed to fill zip sqe, ret = %d!\n", ret);
|
||||
return ret;
|
||||
}
|
||||
ret = hisi_qm_send(h_qp, &sqe, 1, &count);
|
||||
if (ret < 0) {
|
||||
if (ret != -WD_EBUSY)
|
||||
- WD_ERR("qm send is err(%d)!\n", ret);
|
||||
+ WD_ERR("failed to send to hardware, ret = %d!\n", ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -919,7 +921,7 @@ static void free_hw_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
|
||||
h_sgl_pool = hisi_qm_get_sglpool(h_qp);
|
||||
if (!h_sgl_pool) {
|
||||
- WD_ERR("failed to get sglpool to free hw sgl\n");
|
||||
+ WD_ERR("failed to get sglpool to free hw sgl!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -949,7 +951,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
|
||||
|
||||
alg_type = get_alg_type(type);
|
||||
if (alg_type < 0) {
|
||||
- WD_ERR("failed to get request algorithm type(%u)\n", type);
|
||||
+ WD_ERR("invalid: hardware type is %u!\n", type);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
@@ -960,7 +962,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
|
||||
if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
|
||||
recv_msg = wd_comp_get_msg(qp->q_info.idx, tag);
|
||||
if (!recv_msg) {
|
||||
- WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
|
||||
+ WD_ERR("failed to get send msg! idx = %u, tag = %u!\n",
|
||||
qp->q_info.idx, tag);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -970,7 +972,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
|
||||
|
||||
if (status != 0 && status != HZ_NEGACOMPRESS &&
|
||||
status != HZ_CRC_ERR && status != HZ_DECOMP_END) {
|
||||
- WD_ERR("bad status(ctx_st=0x%x, s=0x%x, t=%u)\n",
|
||||
+ WD_ERR("bad request(ctx_st = 0x%x, status = 0x%x, algorithm type = %u)!\n",
|
||||
ctx_st, status, type);
|
||||
recv_msg->req.status = WD_IN_EPARA;
|
||||
}
|
||||
@@ -993,7 +995,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
|
||||
if (ctx_st == HZ_DECOMP_NO_SPACE)
|
||||
recv_msg->req.status = WD_EAGAIN;
|
||||
|
||||
- dbg("zip recv lst =%hu, ctx_st=0x%x, status=0x%x, alg=%u\n", lstblk, ctx_st, status, type);
|
||||
+ dbg("zip recv lst =%hu, ctx_st=0x%x, status=0x%x, alg=%u!\n", lstblk, ctx_st, status, type);
|
||||
if (lstblk && (status == HZ_DECOMP_END))
|
||||
recv_msg->req.status = WD_STREAM_END;
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,272 +0,0 @@
|
||||
From bbbaf91e0819a3ef6953a434b229a105a1008892 Mon Sep 17 00:00:00 2001
|
||||
From: Yang Shen <shenyang39@huawei.com>
|
||||
Date: Thu, 10 Mar 2022 20:29:51 +0800
|
||||
Subject: [PATCH 103/109] comp: add unlikely() for branch prefetch
|
||||
|
||||
Add unlikely() on the route of doing request to improve
|
||||
branch prefetch success rate.
|
||||
|
||||
Signed-off-by: Yang Shen <shenyang39@huawei.com>
|
||||
---
|
||||
wd_comp.c | 69 ++++++++++++++++++++++++++++---------------------------
|
||||
1 file changed, 35 insertions(+), 34 deletions(-)
|
||||
|
||||
diff --git a/wd_comp.c b/wd_comp.c
|
||||
index de71e9c..9a71dfc 100644
|
||||
--- a/wd_comp.c
|
||||
+++ b/wd_comp.c
|
||||
@@ -198,7 +198,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
||||
*count = 0;
|
||||
|
||||
ret = wd_check_ctx(config, CTX_MODE_ASYNC, idx);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
ctx = config->ctxs + idx;
|
||||
@@ -206,7 +206,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
||||
do {
|
||||
ret = wd_comp_setting.driver->comp_recv(ctx->ctx, &resp_msg,
|
||||
priv);
|
||||
- if (ret < 0) {
|
||||
+ if (unlikely(ret < 0)) {
|
||||
if (ret == -WD_HW_EACCESS)
|
||||
WD_ERR("wd comp recv hw error!\n");
|
||||
return ret;
|
||||
@@ -216,7 +216,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
||||
|
||||
msg = wd_find_msg_in_pool(&wd_comp_setting.pool, idx,
|
||||
resp_msg.tag);
|
||||
- if (!msg) {
|
||||
+ if (unlikely(!msg)) {
|
||||
WD_ERR("failed to get msg from pool!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -335,12 +335,12 @@ static void fill_comp_msg(struct wd_comp_sess *sess, struct wd_comp_msg *msg,
|
||||
static int wd_comp_check_buffer(struct wd_comp_req *req)
|
||||
{
|
||||
if (req->data_fmt == WD_FLAT_BUF) {
|
||||
- if (!req->src || !req->dst) {
|
||||
+ if (unlikely(!req->src || !req->dst)) {
|
||||
WD_ERR("invalid: src or dst is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
} else if (req->data_fmt == WD_SGL_BUF) {
|
||||
- if (!req->list_src || !req->list_dst) {
|
||||
+ if (unlikely(!req->list_src || !req->list_dst)) {
|
||||
WD_ERR("invalid: list_src or list_dst is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -360,37 +360,37 @@ static int wd_comp_check_params(struct wd_comp_sess *sess,
|
||||
{
|
||||
int ret;
|
||||
|
||||
- if (!sess || !req) {
|
||||
+ if (unlikely(!sess || !req)) {
|
||||
WD_ERR("invalid: sess or req is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (req->data_fmt > WD_SGL_BUF) {
|
||||
+ if (unlikely(req->data_fmt > WD_SGL_BUF)) {
|
||||
WD_ERR("invalid: data_fmt is %d!\n", req->data_fmt);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
ret = wd_comp_check_buffer(req);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
- if (req->op_type != WD_DIR_COMPRESS &&
|
||||
- req->op_type != WD_DIR_DECOMPRESS) {
|
||||
+ if (unlikely(req->op_type != WD_DIR_COMPRESS &&
|
||||
+ req->op_type != WD_DIR_DECOMPRESS)) {
|
||||
WD_ERR("invalid: op_type is %d!\n", req->op_type);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (mode == CTX_MODE_ASYNC && !req->cb) {
|
||||
+ if (unlikely(mode == CTX_MODE_ASYNC && !req->cb)) {
|
||||
WD_ERR("invalid: async comp cb is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (mode == CTX_MODE_ASYNC && !req->cb_param) {
|
||||
+ if (unlikely(mode == CTX_MODE_ASYNC && !req->cb_param)) {
|
||||
WD_ERR("invalid: async comp cb param is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
- if (mode == CTX_MODE_SYNC && req->cb) {
|
||||
+ if (unlikely(mode == CTX_MODE_SYNC && req->cb)) {
|
||||
WD_ERR("invalid: sync comp cb should be NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -414,7 +414,7 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess,
|
||||
sess->sched_key,
|
||||
CTX_MODE_SYNC);
|
||||
ret = wd_check_ctx(config, CTX_MODE_SYNC, idx);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
ctx = config->ctxs + idx;
|
||||
@@ -422,7 +422,7 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess,
|
||||
pthread_spin_lock(&ctx->lock);
|
||||
|
||||
ret = wd_comp_setting.driver->comp_send(ctx->ctx, msg, priv);
|
||||
- if (ret < 0) {
|
||||
+ if (unlikely(ret < 0)) {
|
||||
pthread_spin_unlock(&ctx->lock);
|
||||
WD_ERR("wd comp send error, ret = %d!\n", ret);
|
||||
return ret;
|
||||
@@ -431,11 +431,11 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess,
|
||||
do {
|
||||
if (msg->is_polled) {
|
||||
ret = wd_ctx_wait(ctx->ctx, POLL_TIME);
|
||||
- if (ret < 0)
|
||||
+ if (unlikely(ret < 0))
|
||||
WD_ERR("wd ctx wait timeout, ret = %d!\n", ret);
|
||||
}
|
||||
ret = wd_comp_setting.driver->comp_recv(ctx->ctx, msg, priv);
|
||||
- if (ret == -WD_HW_EACCESS) {
|
||||
+ if (unlikely(ret == -WD_HW_EACCESS)) {
|
||||
pthread_spin_unlock(&ctx->lock);
|
||||
WD_ERR("wd comp recv hw error!\n");
|
||||
return ret;
|
||||
@@ -460,10 +460,10 @@ int wd_do_comp_sync(handle_t h_sess, struct wd_comp_req *req)
|
||||
int ret;
|
||||
|
||||
ret = wd_comp_check_params(sess, req, CTX_MODE_SYNC);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
- if (!req->src_len) {
|
||||
+ if (unlikely(!req->src_len)) {
|
||||
WD_ERR("invalid: req src_len is 0!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -476,7 +476,7 @@ int wd_do_comp_sync(handle_t h_sess, struct wd_comp_req *req)
|
||||
msg.stream_mode = WD_COMP_STATELESS;
|
||||
|
||||
ret = wd_comp_sync_job(sess, req, &msg);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
req->src_len = msg.in_cons;
|
||||
@@ -496,10 +496,10 @@ int wd_do_comp_sync2(handle_t h_sess, struct wd_comp_req *req)
|
||||
int ret;
|
||||
|
||||
ret = wd_comp_check_params(sess, req, CTX_MODE_SYNC);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
- if (!req->src_len) {
|
||||
+ if (unlikely(!req->src_len)) {
|
||||
WD_ERR("invalid: req src_len is 0!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -523,7 +523,7 @@ int wd_do_comp_sync2(handle_t h_sess, struct wd_comp_req *req)
|
||||
}
|
||||
|
||||
ret = wd_do_comp_strm(h_sess, &strm_req);
|
||||
- if (ret < 0 || strm_req.status == WD_IN_EPARA) {
|
||||
+ if (unlikely(ret < 0 || strm_req.status == WD_IN_EPARA)) {
|
||||
WD_ERR("wd comp, invalid or incomplete data! ret = %d, status = %u!\n",
|
||||
ret, strm_req.status);
|
||||
return ret;
|
||||
@@ -573,7 +573,7 @@ static int append_store_block(struct wd_comp_sess *sess,
|
||||
__u32 isize = sess->isize;
|
||||
|
||||
if (sess->alg_type == WD_ZLIB) {
|
||||
- if (req->dst_len < blocksize + sizeof(checksum))
|
||||
+ if (unlikely(req->dst_len < blocksize + sizeof(checksum)))
|
||||
return -WD_EINVAL;
|
||||
memcpy(req->dst, store_block, blocksize);
|
||||
req->dst_len = blocksize;
|
||||
@@ -582,7 +582,8 @@ static int append_store_block(struct wd_comp_sess *sess,
|
||||
memcpy(req->dst + blocksize, &checksum, sizeof(checksum));
|
||||
req->dst_len += sizeof(checksum);
|
||||
} else if (sess->alg_type == WD_GZIP) {
|
||||
- if (req->dst_len < blocksize + sizeof(checksum) + sizeof(isize))
|
||||
+ if (unlikely(req->dst_len < blocksize +
|
||||
+ sizeof(checksum) + sizeof(isize)))
|
||||
return -WD_EINVAL;
|
||||
memcpy(req->dst, store_block, blocksize);
|
||||
req->dst_len = blocksize;
|
||||
@@ -622,10 +623,10 @@ int wd_do_comp_strm(handle_t h_sess, struct wd_comp_req *req)
|
||||
int ret;
|
||||
|
||||
ret = wd_comp_check_params(sess, req, CTX_MODE_SYNC);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
- if (req->data_fmt > WD_FLAT_BUF) {
|
||||
+ if (unlikely(req->data_fmt > WD_FLAT_BUF)) {
|
||||
WD_ERR("invalid: data_fmt is %d!\n", req->data_fmt);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -647,7 +648,7 @@ int wd_do_comp_strm(handle_t h_sess, struct wd_comp_req *req)
|
||||
src_len = req->src_len;
|
||||
|
||||
ret = wd_comp_sync_job(sess, req, &msg);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
req->src_len = msg.in_cons;
|
||||
@@ -675,10 +676,10 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
|
||||
__u32 idx;
|
||||
|
||||
ret = wd_comp_check_params(sess, req, CTX_MODE_ASYNC);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
- if (!req->src_len) {
|
||||
+ if (unlikely(!req->src_len)) {
|
||||
WD_ERR("invalid: req src_len is 0!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -687,13 +688,13 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
|
||||
sess->sched_key,
|
||||
CTX_MODE_ASYNC);
|
||||
ret = wd_check_ctx(config, CTX_MODE_ASYNC, idx);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
ctx = config->ctxs + idx;
|
||||
|
||||
tag = wd_get_msg_from_pool(&wd_comp_setting.pool, idx, (void **)&msg);
|
||||
- if (tag < 0) {
|
||||
+ if (unlikely(tag < 0)) {
|
||||
WD_ERR("failed to get msg from pool!\n");
|
||||
return -WD_EBUSY;
|
||||
}
|
||||
@@ -705,7 +706,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
|
||||
pthread_spin_lock(&ctx->lock);
|
||||
|
||||
ret = wd_comp_setting.driver->comp_send(ctx->ctx, msg, priv);
|
||||
- if (ret < 0) {
|
||||
+ if (unlikely(ret < 0)) {
|
||||
pthread_spin_unlock(&ctx->lock);
|
||||
WD_ERR("wd comp send error, ret = %d!\n", ret);
|
||||
goto fail_with_msg;
|
||||
@@ -714,7 +715,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
|
||||
pthread_spin_unlock(&ctx->lock);
|
||||
|
||||
ret = wd_add_task_to_async_queue(&wd_comp_env_config, idx);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
goto fail_with_msg;
|
||||
|
||||
return 0;
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,199 +0,0 @@
|
||||
From 4077df41a1ba2ccd155195e16026d0329d062f85 Mon Sep 17 00:00:00 2001
|
||||
From: Yang Shen <shenyang39@huawei.com>
|
||||
Date: Thu, 10 Mar 2022 20:29:52 +0800
|
||||
Subject: [PATCH 104/109] drv/comp: add unlikely() for branch prefetch
|
||||
|
||||
Add unlikely() on the route of doing request to improve
|
||||
branch prefetch success rate.
|
||||
|
||||
Signed-off-by: Yang Shen <shenyang39@huawei.com>
|
||||
---
|
||||
drv/hisi_comp.c | 46 +++++++++++++++++++++++-----------------------
|
||||
1 file changed, 23 insertions(+), 23 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
|
||||
index 5883bb4..860da43 100644
|
||||
--- a/drv/hisi_comp.c
|
||||
+++ b/drv/hisi_comp.c
|
||||
@@ -246,7 +246,7 @@ static int fill_buf_deflate_generic(struct hisi_zip_sqe *sqe,
|
||||
}
|
||||
|
||||
ret = buf_size_check_deflate(&in_size, &out_size);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
fill_buf_size_deflate(sqe, in_size, out_size);
|
||||
@@ -294,19 +294,19 @@ static int fill_buf_addr_deflate_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
handle_t h_sgl_pool;
|
||||
|
||||
h_sgl_pool = hisi_qm_get_sglpool(h_qp);
|
||||
- if (!h_sgl_pool) {
|
||||
+ if (unlikely(!h_sgl_pool)) {
|
||||
WD_ERR("failed to get sglpool!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_src);
|
||||
- if (!hw_sgl_in) {
|
||||
+ if (unlikely(!hw_sgl_in)) {
|
||||
WD_ERR("failed to get hw sgl in!\n");
|
||||
return -WD_ENOMEM;
|
||||
}
|
||||
|
||||
hw_sgl_out = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_dst);
|
||||
- if (!hw_sgl_out) {
|
||||
+ if (unlikely(!hw_sgl_out)) {
|
||||
WD_ERR("failed to get hw sgl out!\n");
|
||||
hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_in);
|
||||
return -WD_ENOMEM;
|
||||
@@ -345,7 +345,7 @@ static int fill_buf_deflate_slg_generic(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
fill_buf_type_sgl(sqe);
|
||||
|
||||
ret = fill_buf_addr_deflate_sgl(h_qp, sqe, msg);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
if (head != NULL && msg->req.op_type == WD_DIR_COMPRESS) {
|
||||
@@ -514,26 +514,26 @@ static int fill_buf_lz77_zstd_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
fill_buf_size_lz77_zstd(sqe, in_size, lits_size, out_size - lits_size);
|
||||
|
||||
h_sgl_pool = hisi_qm_get_sglpool(h_qp);
|
||||
- if (!h_sgl_pool) {
|
||||
+ if (unlikely(!h_sgl_pool)) {
|
||||
WD_ERR("failed to get sglpool!\n");
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_src);
|
||||
- if (!hw_sgl_in) {
|
||||
+ if (unlikely(!hw_sgl_in)) {
|
||||
WD_ERR("failed to get hw sgl in!\n");
|
||||
return -WD_ENOMEM;
|
||||
}
|
||||
|
||||
hw_sgl_out_lit = hisi_qm_get_hw_sgl(h_sgl_pool, req->list_dst);
|
||||
- if (!hw_sgl_out_lit) {
|
||||
+ if (unlikely(!hw_sgl_out_lit)) {
|
||||
WD_ERR("failed to get hw sgl out for literals!\n");
|
||||
ret = -WD_ENOMEM;
|
||||
goto err_free_sgl_in;
|
||||
}
|
||||
|
||||
hw_sgl_out_seq = hisi_qm_get_hw_sgl(h_sgl_pool, seq_start);
|
||||
- if (!hw_sgl_out_seq) {
|
||||
+ if (unlikely(!hw_sgl_out_seq)) {
|
||||
WD_ERR("failed to get hw sgl out for sequences!\n");
|
||||
ret = -WD_ENOMEM;
|
||||
goto err_free_sgl_out_lit;
|
||||
@@ -680,7 +680,7 @@ static void get_data_size_lz77_zstd(struct hisi_zip_sqe *sqe, enum wd_comp_op_ty
|
||||
struct wd_lz77_zstd_data *data = recv_msg->req.priv;
|
||||
void *ctx_buf = recv_msg->ctx_buf;
|
||||
|
||||
- if (!data)
|
||||
+ if (unlikely(!data))
|
||||
return;
|
||||
|
||||
data->lit_num = sqe->comp_data_length;
|
||||
@@ -782,7 +782,7 @@ static int hisi_zip_init(struct wd_ctx_config_internal *config, void *priv)
|
||||
qm_priv.qp_mode = config->ctxs[i].ctx_mode;
|
||||
qm_priv.idx = i;
|
||||
h_qp = hisi_qm_alloc_qp(&qm_priv, h_ctx);
|
||||
- if (!h_qp)
|
||||
+ if (unlikely(!h_qp))
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -821,14 +821,14 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
|
||||
__u8 state;
|
||||
int ret;
|
||||
|
||||
- if ((hw_type <= HISI_QM_API_VER2_BASE && alg_type > WD_GZIP) ||
|
||||
- (hw_type >= HISI_QM_API_VER3_BASE && alg_type >= WD_COMP_ALG_MAX)) {
|
||||
+ if (unlikely((hw_type <= HISI_QM_API_VER2_BASE && alg_type > WD_GZIP) ||
|
||||
+ (hw_type >= HISI_QM_API_VER3_BASE && alg_type >= WD_COMP_ALG_MAX))) {
|
||||
WD_ERR("invalid: algorithm type is %d!\n", alg_type);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
ret = ops[alg_type].fill_buf[msg->req.data_fmt]((handle_t)qp, sqe, msg);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
ops[alg_type].fill_sqe_type(sqe);
|
||||
@@ -838,7 +838,7 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
|
||||
ops[alg_type].fill_tag(sqe, msg->tag);
|
||||
|
||||
ret = ops[alg_type].fill_comp_level(sqe, msg->comp_lv);
|
||||
- if (ret)
|
||||
+ if (unlikely(ret))
|
||||
return ret;
|
||||
|
||||
state = (msg->stream_mode == WD_COMP_STATEFUL) ? HZ_STATEFUL :
|
||||
@@ -871,12 +871,12 @@ static int hisi_zip_comp_send(handle_t ctx, struct wd_comp_msg *msg, void *priv)
|
||||
int ret;
|
||||
|
||||
ret = fill_zip_comp_sqe(qp, msg, &sqe);
|
||||
- if (ret < 0) {
|
||||
+ if (unlikely(ret < 0)) {
|
||||
WD_ERR("failed to fill zip sqe, ret = %d!\n", ret);
|
||||
return ret;
|
||||
}
|
||||
ret = hisi_qm_send(h_qp, &sqe, 1, &count);
|
||||
- if (ret < 0) {
|
||||
+ if (unlikely(ret < 0)) {
|
||||
if (ret != -WD_EBUSY)
|
||||
WD_ERR("failed to send to hardware, ret = %d!\n", ret);
|
||||
|
||||
@@ -920,7 +920,7 @@ static void free_hw_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
||||
handle_t h_sgl_pool;
|
||||
|
||||
h_sgl_pool = hisi_qm_get_sglpool(h_qp);
|
||||
- if (!h_sgl_pool) {
|
||||
+ if (unlikely(!h_sgl_pool)) {
|
||||
WD_ERR("failed to get sglpool to free hw sgl!\n");
|
||||
return;
|
||||
}
|
||||
@@ -950,7 +950,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
|
||||
__u32 tag;
|
||||
|
||||
alg_type = get_alg_type(type);
|
||||
- if (alg_type < 0) {
|
||||
+ if (unlikely(alg_type < 0)) {
|
||||
WD_ERR("invalid: hardware type is %u!\n", type);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
@@ -961,7 +961,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
|
||||
|
||||
if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
|
||||
recv_msg = wd_comp_get_msg(qp->q_info.idx, tag);
|
||||
- if (!recv_msg) {
|
||||
+ if (unlikely(!recv_msg)) {
|
||||
WD_ERR("failed to get send msg! idx = %u, tag = %u!\n",
|
||||
qp->q_info.idx, tag);
|
||||
return -WD_EINVAL;
|
||||
@@ -970,8 +970,8 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
|
||||
|
||||
recv_msg->req.status = 0;
|
||||
|
||||
- if (status != 0 && status != HZ_NEGACOMPRESS &&
|
||||
- status != HZ_CRC_ERR && status != HZ_DECOMP_END) {
|
||||
+ if (unlikely(status != 0 && status != HZ_NEGACOMPRESS &&
|
||||
+ status != HZ_CRC_ERR && status != HZ_DECOMP_END)) {
|
||||
WD_ERR("bad request(ctx_st = 0x%x, status = 0x%x, algorithm type = %u)!\n",
|
||||
ctx_st, status, type);
|
||||
recv_msg->req.status = WD_IN_EPARA;
|
||||
@@ -1019,7 +1019,7 @@ static int hisi_zip_comp_recv(handle_t ctx, struct wd_comp_msg *recv_msg,
|
||||
int ret;
|
||||
|
||||
ret = hisi_qm_recv(h_qp, &sqe, 1, &count);
|
||||
- if (ret < 0)
|
||||
+ if (unlikely(ret < 0))
|
||||
return ret;
|
||||
|
||||
return parse_zip_sqe(qp, &sqe, recv_msg);
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,73 +0,0 @@
|
||||
From 8ebb63a449ec1514f7758aa866d29a6b94845e13 Mon Sep 17 00:00:00 2001
|
||||
From: Weili Qian <qianweili@huawei.com>
|
||||
Date: Mon, 14 Mar 2022 18:47:57 +0800
|
||||
Subject: [PATCH 106/109] hisi_hpre: modify the return value of function
|
||||
|
||||
When these functions are executed successfully,
|
||||
the caller of these functions will not care about
|
||||
the value of the data size, so there is no need
|
||||
to return the data size, just returning a "WD_SUCCESS"
|
||||
will be fine.
|
||||
|
||||
Signed-off-by: Weili Qian <qianweili@huawei.com>
|
||||
---
|
||||
drv/hisi_hpre.c | 14 +++++++-------
|
||||
1 file changed, 7 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
|
||||
index e46efef..d9546a6 100644
|
||||
--- a/drv/hisi_hpre.c
|
||||
+++ b/drv/hisi_hpre.c
|
||||
@@ -221,8 +221,7 @@ static int fill_rsa_crt_prikey2(struct wd_rsa_prikey *prikey,
|
||||
|
||||
*data = wd_dq->data;
|
||||
|
||||
- return (int)(wd_dq->bsize + wd_qinv->bsize + wd_p->bsize +
|
||||
- wd_q->bsize + wd_dp->bsize);
|
||||
+ return WD_SUCCESS;
|
||||
}
|
||||
|
||||
static int fill_rsa_prikey1(struct wd_rsa_prikey *prikey, void **data)
|
||||
@@ -243,7 +242,7 @@ static int fill_rsa_prikey1(struct wd_rsa_prikey *prikey, void **data)
|
||||
|
||||
*data = wd_d->data;
|
||||
|
||||
- return (int)(wd_n->bsize + wd_d->bsize);
|
||||
+ return WD_SUCCESS;
|
||||
}
|
||||
|
||||
static int fill_rsa_pubkey(struct wd_rsa_pubkey *pubkey, void **data)
|
||||
@@ -263,7 +262,8 @@ static int fill_rsa_pubkey(struct wd_rsa_pubkey *pubkey, void **data)
|
||||
return ret;
|
||||
|
||||
*data = wd_e->data;
|
||||
- return (int)(wd_n->bsize + wd_e->bsize);
|
||||
+
|
||||
+ return WD_SUCCESS;
|
||||
}
|
||||
|
||||
static int fill_rsa_genkey_in(struct wd_rsa_kg_in *genkey)
|
||||
@@ -382,17 +382,17 @@ static int rsa_prepare_key(struct wd_rsa_msg *msg,
|
||||
if (req->op_type == WD_RSA_SIGN) {
|
||||
if (hw_msg->alg == HPRE_ALG_NC_CRT) {
|
||||
ret = fill_rsa_crt_prikey2((void *)msg->key, &data);
|
||||
- if (ret <= 0)
|
||||
+ if (ret)
|
||||
return ret;
|
||||
} else {
|
||||
ret = fill_rsa_prikey1((void *)msg->key, &data);
|
||||
- if (ret < 0)
|
||||
+ if (ret)
|
||||
return ret;
|
||||
hw_msg->alg = HPRE_ALG_NC_NCRT;
|
||||
}
|
||||
} else if (req->op_type == WD_RSA_VERIFY) {
|
||||
ret = fill_rsa_pubkey((void *)msg->key, &data);
|
||||
- if (ret < 0)
|
||||
+ if (ret)
|
||||
return ret;
|
||||
hw_msg->alg = HPRE_ALG_NC_NCRT;
|
||||
} else if (req->op_type == WD_RSA_GENKEY) {
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,955 +0,0 @@
|
||||
From f01c1ddc862fc07ce247c8d64083918cf84009c8 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Wed, 16 Mar 2022 18:55:28 +0800
|
||||
Subject: [PATCH 107/109] uadk: parse epoll flag from environment variable
|
||||
|
||||
1.wd_set_epoll_en is used to parse epoll enable flag
|
||||
from environment variable and store it to global variable.
|
||||
2.When uadk works in synchronize mode, it will check the
|
||||
global variable and decide whether to use wd_ctx_wait.
|
||||
3.HPRE algorithm(ecc, rsa, dh) is also support epoll wait now.
|
||||
4.hisi_qm_enable_interrupt is used to enable interrupt mode dynamically
|
||||
when uadk send packets, but since we can init queue with fixed mode now,
|
||||
it is not so efficient and can be replaced.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
docs/wd_environment_variable | 5 +++
|
||||
drv/hisi_comp.c | 5 +--
|
||||
drv/hisi_hpre.c | 3 ++
|
||||
drv/hisi_qm_udrv.c | 21 ++----------
|
||||
drv/hisi_sec.c | 15 ++-------
|
||||
include/drv/wd_aead_drv.h | 2 --
|
||||
include/drv/wd_cipher_drv.h | 2 --
|
||||
include/drv/wd_comp_drv.h | 2 --
|
||||
include/drv/wd_digest_drv.h | 2 --
|
||||
include/hisi_qm_udrv.h | 4 +--
|
||||
include/wd_alg_common.h | 3 ++
|
||||
include/wd_util.h | 9 +++++
|
||||
wd_aead.c | 23 +++++--------
|
||||
wd_cipher.c | 23 +++++--------
|
||||
wd_comp.c | 26 +++++++--------
|
||||
wd_dh.c | 23 ++++++++-----
|
||||
wd_digest.c | 24 ++++++--------
|
||||
wd_ecc.c | 23 ++++++++-----
|
||||
wd_rsa.c | 23 ++++++++-----
|
||||
wd_sched.c | 2 +-
|
||||
wd_util.c | 64 ++++++++++++++++++++++++++++--------
|
||||
21 files changed, 163 insertions(+), 141 deletions(-)
|
||||
|
||||
diff --git a/docs/wd_environment_variable b/docs/wd_environment_variable
|
||||
index 3ada5fb..8ac2da7 100644
|
||||
--- a/docs/wd_environment_variable
|
||||
+++ b/docs/wd_environment_variable
|
||||
@@ -47,6 +47,11 @@ WD_<alg>_ASYNC_POLL_NUM
|
||||
WD_<alg>_ASYNC_POLL_NUM=2@0,4@2 means to configure 2 async polling threads in
|
||||
node0, and 4 polling threads in node2.
|
||||
|
||||
+WD_<alg>_EPOLL_EN
|
||||
+ Define if wd_do_<alg>_sync enable wd_ctx_wait in WD. WD_<alg>_EPOLL_EN=1
|
||||
+ means enable wd_ctx_wait in WD, driver will wait to receive the package until
|
||||
+ hardware is done with package, otherwise driver will try to receive the package
|
||||
+ directly after the package is sent.
|
||||
|
||||
2. User model
|
||||
=============
|
||||
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
|
||||
index 860da43..9fdf3f1 100644
|
||||
--- a/drv/hisi_comp.c
|
||||
+++ b/drv/hisi_comp.c
|
||||
@@ -780,6 +780,9 @@ static int hisi_zip_init(struct wd_ctx_config_internal *config, void *priv)
|
||||
qm_priv.sqe_size = sizeof(struct hisi_zip_sqe);
|
||||
qm_priv.op_type = config->ctxs[i].op_type;
|
||||
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) ?
|
||||
+ config->epoll_en : 0;
|
||||
qm_priv.idx = i;
|
||||
h_qp = hisi_qm_alloc_qp(&qm_priv, h_ctx);
|
||||
if (unlikely(!h_qp))
|
||||
@@ -883,8 +886,6 @@ static int hisi_zip_comp_send(handle_t ctx, struct wd_comp_msg *msg, void *priv)
|
||||
return ret;
|
||||
}
|
||||
|
||||
- hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
-
|
||||
return 0;
|
||||
}
|
||||
|
||||
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
|
||||
index d9546a6..7e14027 100644
|
||||
--- a/drv/hisi_hpre.c
|
||||
+++ b/drv/hisi_hpre.c
|
||||
@@ -466,6 +466,9 @@ static int hpre_init(struct wd_ctx_config_internal *config, void *priv, const ch
|
||||
for (i = 0; i < config->ctx_num; i++) {
|
||||
h_ctx = config->ctxs[i].ctx;
|
||||
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) ?
|
||||
+ config->epoll_en : 0;
|
||||
qm_priv.idx = i;
|
||||
h_qp = hisi_qm_alloc_qp(&qm_priv, h_ctx);
|
||||
if (!h_qp) {
|
||||
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
|
||||
index be06570..2c0d87c 100644
|
||||
--- a/drv/hisi_qm_udrv.c
|
||||
+++ b/drv/hisi_qm_udrv.c
|
||||
@@ -309,6 +309,7 @@ static int hisi_qm_setup_info(struct hisi_qp *qp, struct hisi_qm_priv *config)
|
||||
}
|
||||
|
||||
q_info->qp_mode = config->qp_mode;
|
||||
+ q_info->epoll_en = config->epoll_en;
|
||||
q_info->idx = config->idx;
|
||||
q_info->sqe_size = config->sqe_size;
|
||||
q_info->cqc_phase = 1;
|
||||
@@ -479,7 +480,7 @@ static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, void *resp)
|
||||
i++;
|
||||
}
|
||||
|
||||
- q_info->db(q_info, QM_DBELL_CMD_CQ, i, 0);
|
||||
+ q_info->db(q_info, QM_DBELL_CMD_CQ, i, q_info->epoll_en);
|
||||
|
||||
/* only support one thread poll one queue, so no need protect */
|
||||
q_info->cq_head_index = i;
|
||||
@@ -919,21 +920,3 @@ __u32 hisi_qm_get_list_size(struct wd_datalist *start_node,
|
||||
|
||||
return lits_size;
|
||||
}
|
||||
-
|
||||
-void hisi_qm_enable_interrupt(handle_t ctx, __u8 enable)
|
||||
-{
|
||||
- struct hisi_qm_queue_info *q_info;
|
||||
- struct hisi_qp *qp;
|
||||
- handle_t h_qp;
|
||||
-
|
||||
- if (!enable)
|
||||
- return;
|
||||
-
|
||||
- h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
||||
- qp = (struct hisi_qp *)h_qp;
|
||||
- q_info = &qp->q_info;
|
||||
-
|
||||
- pthread_spin_lock(&q_info->lock);
|
||||
- q_info->db(q_info, QM_DBELL_CMD_CQ, q_info->cq_head_index, 1);
|
||||
- pthread_spin_unlock(&q_info->lock);
|
||||
-}
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index aa86a6b..0732cdc 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -959,8 +959,6 @@ int hisi_sec_cipher_send(handle_t ctx, struct wd_cipher_msg *msg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
- hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
-
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1162,8 +1160,6 @@ int hisi_sec_cipher_send_v3(handle_t ctx, struct wd_cipher_msg *msg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
- hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
-
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1403,8 +1399,6 @@ int hisi_sec_digest_send(handle_t ctx, struct wd_digest_msg *msg)
|
||||
goto put_sgl;
|
||||
}
|
||||
|
||||
- hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
-
|
||||
return 0;
|
||||
|
||||
put_sgl:
|
||||
@@ -1560,8 +1554,6 @@ int hisi_sec_digest_send_v3(handle_t ctx, struct wd_digest_msg *msg)
|
||||
goto put_sgl;
|
||||
}
|
||||
|
||||
- hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
-
|
||||
return 0;
|
||||
|
||||
put_sgl:
|
||||
@@ -1913,8 +1905,6 @@ int hisi_sec_aead_send(handle_t ctx, struct wd_aead_msg *msg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
- hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
-
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2181,8 +2171,6 @@ int hisi_sec_aead_send_v3(handle_t ctx, struct wd_aead_msg *msg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
- hisi_qm_enable_interrupt(ctx, msg->is_polled);
|
||||
-
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2285,6 +2273,9 @@ int hisi_sec_init(struct wd_ctx_config_internal *config, void *priv)
|
||||
/* setting the type is 0 for sqc_type */
|
||||
qm_priv.op_type = 0;
|
||||
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) ?
|
||||
+ config->epoll_en : 0;
|
||||
qm_priv.idx = i;
|
||||
h_qp = hisi_qm_alloc_qp(&qm_priv, h_ctx);
|
||||
if (!h_qp)
|
||||
diff --git a/include/drv/wd_aead_drv.h b/include/drv/wd_aead_drv.h
|
||||
index 78a5673..137e70a 100644
|
||||
--- a/include/drv/wd_aead_drv.h
|
||||
+++ b/include/drv/wd_aead_drv.h
|
||||
@@ -31,8 +31,6 @@ struct wd_aead_msg {
|
||||
__u8 data_fmt;
|
||||
/* Operation result, denoted by WD error code */
|
||||
__u8 result;
|
||||
- /* epoll flag */
|
||||
- __u8 is_polled;
|
||||
|
||||
/* in bytes */
|
||||
__u32 in_bytes;
|
||||
diff --git a/include/drv/wd_cipher_drv.h b/include/drv/wd_cipher_drv.h
|
||||
index e649869..87b77d3 100644
|
||||
--- a/include/drv/wd_cipher_drv.h
|
||||
+++ b/include/drv/wd_cipher_drv.h
|
||||
@@ -28,8 +28,6 @@ struct wd_cipher_msg {
|
||||
__u8 data_fmt;
|
||||
/* Operation result, denoted by WD error code */
|
||||
__u8 result;
|
||||
- /* epoll flag */
|
||||
- __u8 is_polled;
|
||||
|
||||
/* Key bytes */
|
||||
__u16 key_bytes;
|
||||
diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h
|
||||
index 8146a50..73403b5 100644
|
||||
--- a/include/drv/wd_comp_drv.h
|
||||
+++ b/include/drv/wd_comp_drv.h
|
||||
@@ -50,8 +50,6 @@ struct wd_comp_msg {
|
||||
__u32 checksum;
|
||||
/* Request identifier */
|
||||
__u32 tag;
|
||||
- /* Epoll flag */
|
||||
- __u8 is_polled;
|
||||
};
|
||||
|
||||
struct wd_comp_driver {
|
||||
diff --git a/include/drv/wd_digest_drv.h b/include/drv/wd_digest_drv.h
|
||||
index fdde772..6907bc5 100644
|
||||
--- a/include/drv/wd_digest_drv.h
|
||||
+++ b/include/drv/wd_digest_drv.h
|
||||
@@ -27,8 +27,6 @@ struct wd_digest_msg {
|
||||
__u8 data_fmt;
|
||||
/* Operation result, denoted by WD error code */
|
||||
__u8 result;
|
||||
- /* epoll flag */
|
||||
- __u8 is_polled;
|
||||
/* user identifier: struct wcrypto_cb_tag */
|
||||
__u64 usr_data;
|
||||
|
||||
diff --git a/include/hisi_qm_udrv.h b/include/hisi_qm_udrv.h
|
||||
index 707d0e3..68de837 100644
|
||||
--- a/include/hisi_qm_udrv.h
|
||||
+++ b/include/hisi_qm_udrv.h
|
||||
@@ -47,6 +47,7 @@ struct hisi_qm_priv {
|
||||
__u16 op_type;
|
||||
/* index of ctxs */
|
||||
__u32 idx;
|
||||
+ bool epoll_en;
|
||||
};
|
||||
|
||||
struct hisi_qm_queue_info {
|
||||
@@ -71,6 +72,7 @@ struct hisi_qm_queue_info {
|
||||
bool cqc_phase;
|
||||
pthread_spinlock_t lock;
|
||||
unsigned long region_size[UACCE_QFRT_MAX];
|
||||
+ bool epoll_en;
|
||||
};
|
||||
|
||||
struct hisi_qp {
|
||||
@@ -182,8 +184,6 @@ int hisi_qm_get_free_sqe_num(handle_t h_qp);
|
||||
__u32 hisi_qm_get_list_size(struct wd_datalist *start_node,
|
||||
struct wd_datalist *end_node);
|
||||
|
||||
-void hisi_qm_enable_interrupt(handle_t ctx, __u8 enable);
|
||||
-
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h
|
||||
index 94336f0..30d244f 100644
|
||||
--- a/include/wd_alg_common.h
|
||||
+++ b/include/wd_alg_common.h
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <asm/types.h>
|
||||
#include <pthread.h>
|
||||
+#include <stdbool.h>
|
||||
#include "wd.h"
|
||||
#include "wd_common.h"
|
||||
|
||||
@@ -27,6 +28,7 @@ extern "C" {
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
#define MAX_STR_LEN 256
|
||||
#define CTX_TYPE_INVALID 9999
|
||||
+#define POLL_TIME 1000
|
||||
|
||||
enum wd_ctx_mode {
|
||||
CTX_MODE_SYNC = 0,
|
||||
@@ -74,6 +76,7 @@ struct wd_ctx_config_internal {
|
||||
struct wd_ctx_internal *ctxs;
|
||||
void *priv;
|
||||
int pid;
|
||||
+ bool epoll_en;
|
||||
};
|
||||
|
||||
/**
|
||||
diff --git a/include/wd_util.h b/include/wd_util.h
|
||||
index 2d3c1e4..a41b4c9 100644
|
||||
--- a/include/wd_util.h
|
||||
+++ b/include/wd_util.h
|
||||
@@ -314,6 +314,15 @@ int wd_set_ctx_attr(struct wd_ctx_attr *ctx_attr,
|
||||
*/
|
||||
int wd_check_ctx(struct wd_ctx_config_internal *config, __u8 mode, __u32 idx);
|
||||
|
||||
+/**
|
||||
+ * wd_set_epoll_en() - set epoll enable flag from environment variable value.
|
||||
+ * @var_name: Environment variable name string.
|
||||
+ * @epoll_en: epoll enable flag.
|
||||
+ *
|
||||
+ * Return 0 if the value is 0 or 1, otherwise return -WD_EINVAL.
|
||||
+ */
|
||||
+int wd_set_epoll_en(const char *var_name, bool *epoll_en);
|
||||
+
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
diff --git a/wd_aead.c b/wd_aead.c
|
||||
index 74047b5..2e006c3 100644
|
||||
--- a/wd_aead.c
|
||||
+++ b/wd_aead.c
|
||||
@@ -21,8 +21,6 @@
|
||||
#define WD_POOL_MAX_ENTRIES 1024
|
||||
#define MAX_RETRY_COUNTS 200000000
|
||||
|
||||
-#define POLL_SIZE 70000
|
||||
-#define POLL_TIME 1000
|
||||
|
||||
static int g_aead_mac_len[WD_DIGEST_TYPE_MAX] = {
|
||||
WD_DIGEST_SM3_LEN, WD_DIGEST_MD5_LEN, WD_DIGEST_SHA1_LEN,
|
||||
@@ -414,17 +412,18 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
+ ret = wd_set_epoll_en("WD_AEAD_EPOLL_EN",
|
||||
+ &wd_aead_setting.config.epoll_en);
|
||||
+ if (ret < 0)
|
||||
+ return ret;
|
||||
+
|
||||
ret = wd_init_ctx_config(&wd_aead_setting.config, config);
|
||||
- if (ret) {
|
||||
- WD_ERR("failed to set config, ret = %d\n", ret);
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
|
||||
ret = wd_init_sched(&wd_aead_setting.sched, sched);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to set sched, ret = %d\n", ret);
|
||||
+ if (ret < 0)
|
||||
goto out;
|
||||
- }
|
||||
|
||||
/* set driver */
|
||||
#ifdef WD_STATIC_DRV
|
||||
@@ -435,10 +434,8 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
ret = wd_init_async_request_pool(&wd_aead_setting.pool,
|
||||
config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
sizeof(struct wd_aead_msg));
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to init aead aysnc request pool.\n");
|
||||
+ if (ret < 0)
|
||||
goto out_sched;
|
||||
- }
|
||||
|
||||
/* init ctx related resources in specific driver */
|
||||
priv = calloc(1, wd_aead_setting.driver->drv_ctx_size);
|
||||
@@ -525,7 +522,7 @@ static int send_recv_sync(struct wd_ctx_internal *ctx,
|
||||
}
|
||||
|
||||
do {
|
||||
- if (msg->is_polled) {
|
||||
+ if (wd_aead_setting.config.epoll_en) {
|
||||
ret = wd_ctx_wait(ctx->ctx, POLL_TIME);
|
||||
if (unlikely(ret < 0))
|
||||
WD_ERR("wd aead ctx wait timeout(%d)!\n", ret);
|
||||
@@ -563,7 +560,6 @@ int wd_do_aead_sync(handle_t h_sess, struct wd_aead_req *req)
|
||||
|
||||
memset(&msg, 0, sizeof(struct wd_aead_msg));
|
||||
fill_request_msg(&msg, req, sess);
|
||||
- msg.is_polled = (req->in_bytes >= POLL_SIZE);
|
||||
req->state = 0;
|
||||
|
||||
idx = wd_aead_setting.sched.pick_next_ctx(
|
||||
@@ -616,7 +612,6 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req)
|
||||
|
||||
fill_request_msg(msg, req, sess);
|
||||
msg->tag = msg_id;
|
||||
- msg->is_polled = 0;
|
||||
|
||||
ret = wd_aead_setting.driver->aead_send(ctx->ctx, msg);
|
||||
if (unlikely(ret < 0)) {
|
||||
diff --git a/wd_cipher.c b/wd_cipher.c
|
||||
index 563eece..6d286f9 100644
|
||||
--- a/wd_cipher.c
|
||||
+++ b/wd_cipher.c
|
||||
@@ -22,8 +22,6 @@
|
||||
#define DES_WEAK_KEY_NUM 16
|
||||
#define MAX_RETRY_COUNTS 200000000
|
||||
|
||||
-#define POLL_SIZE 100000
|
||||
-#define POLL_TIME 1000
|
||||
|
||||
static const unsigned char des_weak_keys[DES_WEAK_KEY_NUM][DES_KEY_SIZE] = {
|
||||
/* weak keys */
|
||||
@@ -255,17 +253,18 @@ int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
+ ret = wd_set_epoll_en("WD_CIPHER_EPOLL_EN",
|
||||
+ &wd_cipher_setting.config.epoll_en);
|
||||
+ if (ret < 0)
|
||||
+ return ret;
|
||||
+
|
||||
ret = wd_init_ctx_config(&wd_cipher_setting.config, config);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to set config, ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
return ret;
|
||||
- }
|
||||
|
||||
ret = wd_init_sched(&wd_cipher_setting.sched, sched);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to set sched, ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
goto out;
|
||||
- }
|
||||
|
||||
#ifdef WD_STATIC_DRV
|
||||
/* set driver */
|
||||
@@ -276,10 +275,8 @@ int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
ret = wd_init_async_request_pool(&wd_cipher_setting.pool,
|
||||
config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
sizeof(struct wd_cipher_msg));
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to init req pool, ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
goto out_sched;
|
||||
- }
|
||||
|
||||
/* init ctx related resources in specific driver */
|
||||
priv = calloc(1, wd_cipher_setting.driver->drv_ctx_size);
|
||||
@@ -436,7 +433,7 @@ static int send_recv_sync(struct wd_ctx_internal *ctx,
|
||||
}
|
||||
|
||||
do {
|
||||
- if (msg->is_polled) {
|
||||
+ if (wd_cipher_setting.config.epoll_en) {
|
||||
ret = wd_ctx_wait(ctx->ctx, POLL_TIME);
|
||||
if (unlikely(ret < 0))
|
||||
WD_ERR("wd cipher ctx wait timeout(%d)!\n", ret);
|
||||
@@ -476,7 +473,6 @@ int wd_do_cipher_sync(handle_t h_sess, struct wd_cipher_req *req)
|
||||
|
||||
memset(&msg, 0, sizeof(struct wd_cipher_msg));
|
||||
fill_request_msg(&msg, req, sess);
|
||||
- msg.is_polled = (req->in_bytes >= POLL_SIZE);
|
||||
req->state = 0;
|
||||
|
||||
idx = wd_cipher_setting.sched.pick_next_ctx(
|
||||
@@ -526,7 +522,6 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req)
|
||||
|
||||
fill_request_msg(msg, req, sess);
|
||||
msg->tag = msg_id;
|
||||
- msg->is_polled = 0;
|
||||
|
||||
ret = wd_cipher_setting.driver->cipher_send(ctx->ctx, msg);
|
||||
if (unlikely(ret < 0)) {
|
||||
diff --git a/wd_comp.c b/wd_comp.c
|
||||
index 9a71dfc..3bd7f43 100644
|
||||
--- a/wd_comp.c
|
||||
+++ b/wd_comp.c
|
||||
@@ -22,8 +22,6 @@
|
||||
#define HW_CTX_SIZE (64 * 1024)
|
||||
#define STREAM_CHUNK (128 * 1024)
|
||||
|
||||
-#define POLL_SIZE 250000
|
||||
-#define POLL_TIME 1000
|
||||
|
||||
#define swap_byte(x) \
|
||||
((((x) & 0x000000ff) << 24) | \
|
||||
@@ -97,16 +95,18 @@ int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
+ ret = wd_set_epoll_en("WD_COMP_EPOLL_EN",
|
||||
+ &wd_comp_setting.config.epoll_en);
|
||||
+ if (ret < 0)
|
||||
+ return ret;
|
||||
+
|
||||
ret = wd_init_ctx_config(&wd_comp_setting.config, config);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to set config, ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
return ret;
|
||||
- }
|
||||
+
|
||||
ret = wd_init_sched(&wd_comp_setting.sched, sched);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to set sched, ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
goto out;
|
||||
- }
|
||||
/*
|
||||
* Fix me: ctx could be passed into wd_comp_set_static_drv to help to
|
||||
* choose static compiled vendor driver. For dynamic vendor driver,
|
||||
@@ -125,10 +125,9 @@ int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
ret = wd_init_async_request_pool(&wd_comp_setting.pool,
|
||||
config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
sizeof(struct wd_comp_msg));
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to init req pool, ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
goto out_sched;
|
||||
- }
|
||||
+
|
||||
/* init ctx related resources in specific driver */
|
||||
priv = calloc(1, wd_comp_setting.driver->drv_ctx_size);
|
||||
if (!priv) {
|
||||
@@ -429,7 +428,7 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess,
|
||||
}
|
||||
|
||||
do {
|
||||
- if (msg->is_polled) {
|
||||
+ if (config->epoll_en) {
|
||||
ret = wd_ctx_wait(ctx->ctx, POLL_TIME);
|
||||
if (unlikely(ret < 0))
|
||||
WD_ERR("wd ctx wait timeout, ret = %d!\n", ret);
|
||||
@@ -472,7 +471,6 @@ int wd_do_comp_sync(handle_t h_sess, struct wd_comp_req *req)
|
||||
|
||||
fill_comp_msg(sess, &msg, req);
|
||||
msg.ctx_buf = sess->ctx_buf;
|
||||
- msg.is_polled = (req->src_len >= POLL_SIZE);
|
||||
msg.stream_mode = WD_COMP_STATELESS;
|
||||
|
||||
ret = wd_comp_sync_job(sess, req, &msg);
|
||||
@@ -643,7 +641,6 @@ int wd_do_comp_strm(handle_t h_sess, struct wd_comp_req *req)
|
||||
/* fill true flag */
|
||||
msg.req.last = req->last;
|
||||
msg.stream_mode = WD_COMP_STATEFUL;
|
||||
- msg.is_polled = (req->src_len >= POLL_SIZE);
|
||||
|
||||
src_len = req->src_len;
|
||||
|
||||
@@ -701,7 +698,6 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
|
||||
fill_comp_msg(sess, msg, req);
|
||||
msg->tag = tag;
|
||||
msg->stream_mode = WD_COMP_STATELESS;
|
||||
- msg->is_polled = 0;
|
||||
|
||||
pthread_spin_lock(&ctx->lock);
|
||||
|
||||
diff --git a/wd_dh.c b/wd_dh.c
|
||||
index c0d3e00..aaea812 100644
|
||||
--- a/wd_dh.c
|
||||
+++ b/wd_dh.c
|
||||
@@ -101,17 +101,18 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
if (param_check(config, sched))
|
||||
return -WD_EINVAL;
|
||||
|
||||
+ ret = wd_set_epoll_en("WD_DH_EPOLL_EN",
|
||||
+ &wd_dh_setting.config.epoll_en);
|
||||
+ if (ret < 0)
|
||||
+ return ret;
|
||||
+
|
||||
ret = wd_init_ctx_config(&wd_dh_setting.config, config);
|
||||
- if (ret) {
|
||||
- WD_ERR("failed to initialize ctx config, ret = %d!\n", ret);
|
||||
+ if (ret)
|
||||
return ret;
|
||||
- }
|
||||
|
||||
ret = wd_init_sched(&wd_dh_setting.sched, sched);
|
||||
- if (ret) {
|
||||
- WD_ERR("failed to initialize sched, ret = %d!\n", ret);
|
||||
+ if (ret)
|
||||
goto out;
|
||||
- }
|
||||
|
||||
#ifdef WD_STATIC_DRV
|
||||
wd_dh_set_static_drv();
|
||||
@@ -121,10 +122,8 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
ret = wd_init_async_request_pool(&wd_dh_setting.pool,
|
||||
config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
sizeof(struct wd_dh_msg));
|
||||
- if (ret) {
|
||||
- WD_ERR("failed to initialize async req pool, ret = %d!\n", ret);
|
||||
+ if (ret)
|
||||
goto out_sched;
|
||||
- }
|
||||
|
||||
/* initialize ctx related resources in specific driver */
|
||||
priv = calloc(1, wd_dh_setting.driver->drv_ctx_size);
|
||||
@@ -236,6 +235,12 @@ static int dh_recv_sync(handle_t ctx, struct wd_dh_msg *msg)
|
||||
int ret;
|
||||
|
||||
do {
|
||||
+ if (wd_dh_setting.config.epoll_en) {
|
||||
+ ret = wd_ctx_wait(ctx, POLL_TIME);
|
||||
+ if (ret < 0)
|
||||
+ WD_ERR("wd ctx wait timeout(%d)!\n", ret);
|
||||
+ }
|
||||
+
|
||||
ret = wd_dh_setting.driver->recv(ctx, msg);
|
||||
if (ret == -WD_EAGAIN) {
|
||||
if (rx_cnt++ >= DH_RECV_MAX_CNT) {
|
||||
diff --git a/wd_digest.c b/wd_digest.c
|
||||
index 0ddc074..7afbd9c 100644
|
||||
--- a/wd_digest.c
|
||||
+++ b/wd_digest.c
|
||||
@@ -19,8 +19,6 @@
|
||||
#define DES_WEAK_KEY_NUM 4
|
||||
#define MAX_RETRY_COUNTS 200000000
|
||||
|
||||
-#define POLL_SIZE 100000
|
||||
-#define POLL_TIME 1000
|
||||
|
||||
static int g_digest_mac_len[WD_DIGEST_TYPE_MAX] = {
|
||||
WD_DIGEST_SM3_LEN, WD_DIGEST_MD5_LEN, WD_DIGEST_SHA1_LEN,
|
||||
@@ -28,6 +26,7 @@ static int g_digest_mac_len[WD_DIGEST_TYPE_MAX] = {
|
||||
WD_DIGEST_SHA384_LEN, WD_DIGEST_SHA512_LEN,
|
||||
WD_DIGEST_SHA512_224_LEN, WD_DIGEST_SHA512_256_LEN
|
||||
};
|
||||
+
|
||||
struct wd_digest_setting {
|
||||
struct wd_ctx_config_internal config;
|
||||
struct wd_sched sched;
|
||||
@@ -175,17 +174,18 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
+ ret = wd_set_epoll_en("WD_DIGEST_EPOLL_EN",
|
||||
+ &wd_digest_setting.config.epoll_en);
|
||||
+ if (ret < 0)
|
||||
+ return ret;
|
||||
+
|
||||
ret = wd_init_ctx_config(&wd_digest_setting.config, config);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to set config, ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
return ret;
|
||||
- }
|
||||
|
||||
ret = wd_init_sched(&wd_digest_setting.sched, sched);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to set sched, ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
goto out;
|
||||
- }
|
||||
|
||||
/* set driver */
|
||||
#ifdef WD_STATIC_DRV
|
||||
@@ -196,10 +196,8 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
ret = wd_init_async_request_pool(&wd_digest_setting.pool,
|
||||
config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
sizeof(struct wd_digest_msg));
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to init req pool, ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
goto out_sched;
|
||||
- }
|
||||
|
||||
/* init ctx related resources in specific driver */
|
||||
priv = calloc(1, wd_digest_setting.driver->drv_ctx_size);
|
||||
@@ -322,7 +320,7 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *ds
|
||||
}
|
||||
|
||||
do {
|
||||
- if (msg->is_polled) {
|
||||
+ if (wd_digest_setting.config.epoll_en) {
|
||||
ret = wd_ctx_wait(ctx->ctx, POLL_TIME);
|
||||
if (unlikely(ret < 0))
|
||||
WD_ERR("wd digest ctx wait timeout(%d)!\n", ret);
|
||||
@@ -367,7 +365,6 @@ int wd_do_digest_sync(handle_t h_sess, struct wd_digest_req *req)
|
||||
|
||||
memset(&msg, 0, sizeof(struct wd_digest_msg));
|
||||
fill_request_msg(&msg, req, dsess);
|
||||
- msg.is_polled = (req->in_bytes >= POLL_SIZE);
|
||||
req->state = 0;
|
||||
|
||||
idx = wd_digest_setting.sched.pick_next_ctx(
|
||||
@@ -420,7 +417,6 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req)
|
||||
|
||||
fill_request_msg(msg, req, dsess);
|
||||
msg->tag = msg_id;
|
||||
- msg->is_polled = 0;
|
||||
|
||||
ret = wd_digest_setting.driver->digest_send(ctx->ctx, msg);
|
||||
if (unlikely(ret < 0)) {
|
||||
diff --git a/wd_ecc.c b/wd_ecc.c
|
||||
index af62b9a..a6c2209 100644
|
||||
--- a/wd_ecc.c
|
||||
+++ b/wd_ecc.c
|
||||
@@ -155,17 +155,18 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
if (init_param_check(config, sched))
|
||||
return -WD_EINVAL;
|
||||
|
||||
+ ret = wd_set_epoll_en("WD_ECC_EPOLL_EN",
|
||||
+ &wd_ecc_setting.config.epoll_en);
|
||||
+ if (ret < 0)
|
||||
+ return ret;
|
||||
+
|
||||
ret = wd_init_ctx_config(&wd_ecc_setting.config, config);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to set config, ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
return ret;
|
||||
- }
|
||||
|
||||
ret = wd_init_sched(&wd_ecc_setting.sched, sched);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to set sched, ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
goto out;
|
||||
- }
|
||||
|
||||
#ifdef WD_STATIC_DRV
|
||||
wd_ecc_set_static_drv();
|
||||
@@ -175,10 +176,8 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
ret = wd_init_async_request_pool(&wd_ecc_setting.pool,
|
||||
config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
sizeof(struct wd_ecc_msg));
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to initialize async req pool, ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
goto out_sched;
|
||||
- }
|
||||
|
||||
/* initialize ctx related resources in specific driver */
|
||||
priv = calloc(1, wd_ecc_setting.driver->drv_ctx_size);
|
||||
@@ -1435,6 +1434,12 @@ static int ecc_recv_sync(handle_t ctx, struct wd_ecc_msg *msg)
|
||||
int ret;
|
||||
|
||||
do {
|
||||
+ if (wd_ecc_setting.config.epoll_en) {
|
||||
+ ret = wd_ctx_wait(ctx, POLL_TIME);
|
||||
+ if (ret < 0)
|
||||
+ WD_ERR("wd ctx wait timeout(%d)!\n", ret);
|
||||
+ }
|
||||
+
|
||||
ret = wd_ecc_setting.driver->recv(ctx, msg);
|
||||
if (ret == -WD_EAGAIN) {
|
||||
if (rx_cnt++ >= ECC_RECV_MAX_CNT) {
|
||||
diff --git a/wd_rsa.c b/wd_rsa.c
|
||||
index 8371475..ca39cff 100644
|
||||
--- a/wd_rsa.c
|
||||
+++ b/wd_rsa.c
|
||||
@@ -141,17 +141,18 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
if (param_check(config, sched))
|
||||
return -WD_EINVAL;
|
||||
|
||||
+ ret = wd_set_epoll_en("WD_RSA_EPOLL_EN",
|
||||
+ &wd_rsa_setting.config.epoll_en);
|
||||
+ if (ret < 0)
|
||||
+ return ret;
|
||||
+
|
||||
ret = wd_init_ctx_config(&wd_rsa_setting.config, config);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to set config, ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
return ret;
|
||||
- }
|
||||
|
||||
ret = wd_init_sched(&wd_rsa_setting.sched, sched);
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to set sched, ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
goto out;
|
||||
- }
|
||||
|
||||
#ifdef WD_STATIC_DRV
|
||||
wd_rsa_set_static_drv();
|
||||
@@ -161,10 +162,8 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
|
||||
ret = wd_init_async_request_pool(&wd_rsa_setting.pool,
|
||||
config->ctx_num, WD_POOL_MAX_ENTRIES,
|
||||
sizeof(struct wd_rsa_msg));
|
||||
- if (ret < 0) {
|
||||
- WD_ERR("failed to initialize async req pool, ret = %d!\n", ret);
|
||||
+ if (ret < 0)
|
||||
goto out_sched;
|
||||
- }
|
||||
|
||||
/* initialize ctx related resources in specific driver */
|
||||
priv = calloc(1, wd_rsa_setting.driver->drv_ctx_size);
|
||||
@@ -296,6 +295,12 @@ static int rsa_recv_sync(handle_t ctx, struct wd_rsa_msg *msg)
|
||||
int ret;
|
||||
|
||||
do {
|
||||
+ if (wd_rsa_setting.config.epoll_en) {
|
||||
+ ret = wd_ctx_wait(ctx, POLL_TIME);
|
||||
+ if (ret < 0)
|
||||
+ WD_ERR("wd ctx wait timeout(%d)!\n", ret);
|
||||
+ }
|
||||
+
|
||||
ret = wd_rsa_setting.driver->recv(ctx, msg);
|
||||
if (ret == -WD_EAGAIN) {
|
||||
if (rx_cnt++ >= RSA_RECV_MAX_CNT) {
|
||||
diff --git a/wd_sched.c b/wd_sched.c
|
||||
index 9b1998c..dfd390b 100644
|
||||
--- a/wd_sched.c
|
||||
+++ b/wd_sched.c
|
||||
@@ -213,7 +213,7 @@ static int session_sched_poll_policy(handle_t sched_ctx,
|
||||
}
|
||||
|
||||
if (ctx->numa_num > NUMA_NUM_NODES) {
|
||||
- WD_ERR("invalid: ctx's numa number is %d!\n", ctx->numa_num);
|
||||
+ WD_ERR("invalid: ctx's numa number is %u!\n", ctx->numa_num);
|
||||
return -WD_EINVAL;
|
||||
}
|
||||
|
||||
diff --git a/wd_util.c b/wd_util.c
|
||||
index 03316b6..57dafa7 100644
|
||||
--- a/wd_util.c
|
||||
+++ b/wd_util.c
|
||||
@@ -85,8 +85,10 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in,
|
||||
}
|
||||
|
||||
ctxs = calloc(1, cfg->ctx_num * sizeof(struct wd_ctx_internal));
|
||||
- if (!ctxs)
|
||||
+ if (!ctxs) {
|
||||
+ WD_ERR("failed to alloc memory for internal ctxs!\n");
|
||||
return -WD_ENOMEM;
|
||||
+ }
|
||||
|
||||
for (i = 0; i < cfg->ctx_num; i++) {
|
||||
if (!cfg->ctxs[i].ctx) {
|
||||
@@ -115,8 +117,10 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in,
|
||||
int wd_init_sched(struct wd_sched *in, struct wd_sched *from)
|
||||
{
|
||||
if (!from->name || !from->sched_init ||
|
||||
- !from->pick_next_ctx || !from->poll_policy)
|
||||
+ !from->pick_next_ctx || !from->poll_policy) {
|
||||
+ WD_ERR("invalid: member of wd_sched is NULL!\n");
|
||||
return -WD_EINVAL;
|
||||
+ }
|
||||
|
||||
in->h_sched_ctx = from->h_sched_ctx;
|
||||
in->name = strdup(from->name);
|
||||
@@ -170,13 +174,16 @@ void wd_memset_zero(void *data, __u32 size)
|
||||
static int init_msg_pool(struct msg_pool *pool, __u32 msg_num, __u32 msg_size)
|
||||
{
|
||||
pool->msgs = calloc(1, msg_num * msg_size);
|
||||
- if (!pool->msgs)
|
||||
+ if (!pool->msgs) {
|
||||
+ WD_ERR("failed to alloc memory for msgs arrary of msg pool!\n");
|
||||
return -WD_ENOMEM;
|
||||
+ }
|
||||
|
||||
pool->used = calloc(1, msg_num * sizeof(int));
|
||||
if (!pool->used) {
|
||||
free(pool->msgs);
|
||||
pool->msgs = NULL;
|
||||
+ WD_ERR("failed to alloc memory for used arrary of msg pool!\n");
|
||||
return -WD_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -204,8 +211,10 @@ int wd_init_async_request_pool(struct wd_async_msg_pool *pool, __u32 pool_num,
|
||||
pool->pool_num = pool_num;
|
||||
|
||||
pool->pools = calloc(1, pool->pool_num * sizeof(struct msg_pool));
|
||||
- if (!pool->pools)
|
||||
+ if (!pool->pools) {
|
||||
+ WD_ERR("failed to alloc memory for async msg pools!\n");
|
||||
return -WD_ENOMEM;
|
||||
+ }
|
||||
|
||||
for (i = 0; i < pool->pool_num; i++) {
|
||||
ret = init_msg_pool(&pool->pools[i], msg_num, msg_size);
|
||||
@@ -510,27 +519,33 @@ static int is_number(const char *str)
|
||||
return 1;
|
||||
}
|
||||
|
||||
-/* 1 enable, 0 disable, others error */
|
||||
-int wd_parse_async_poll_en(struct wd_env_config *config, const char *s)
|
||||
+static int str_to_bool(const char *s, bool *target)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
- if (!is_number(s)) {
|
||||
- WD_ERR("invalid: async poll en flag is %s!\n", s);
|
||||
+ if (!is_number(s))
|
||||
return -WD_EINVAL;
|
||||
- }
|
||||
|
||||
tmp = strtol(s, NULL, 10);
|
||||
- if (tmp != 0 && tmp != 1) {
|
||||
- WD_ERR("invalid: async poll en flag is not 0 or 1!\n");
|
||||
+ if (tmp != 0 && tmp != 1)
|
||||
return -WD_EINVAL;
|
||||
- }
|
||||
|
||||
- config->enable_internal_poll = tmp;
|
||||
+ *target = tmp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+int wd_parse_async_poll_en(struct wd_env_config *config, const char *s)
|
||||
+{
|
||||
+ int ret;
|
||||
+
|
||||
+ ret = str_to_bool(s, &config->enable_internal_poll);
|
||||
+ if (ret)
|
||||
+ WD_ERR("failed to parse async poll enable flag(%s)!\n", s);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
static int parse_num_on_numa(const char *s, int *num, int *node)
|
||||
{
|
||||
char *sep, *start, *left;
|
||||
@@ -1589,3 +1604,26 @@ int wd_check_ctx(struct wd_ctx_config_internal *config, __u8 mode, __u32 idx)
|
||||
|
||||
return 0;
|
||||
}
|
||||
+
|
||||
+int wd_set_epoll_en(const char *var_name, bool *epoll_en)
|
||||
+{
|
||||
+ const char *s;
|
||||
+ int ret;
|
||||
+
|
||||
+ s = secure_getenv(var_name);
|
||||
+ if (!s || !strlen(s)) {
|
||||
+ *epoll_en = 0;
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ ret = str_to_bool(s, epoll_en);
|
||||
+ if (ret) {
|
||||
+ WD_ERR("failed to parse %s!\n", var_name);
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ if (*epoll_en)
|
||||
+ WD_ERR("epoll wait is enabled!\n");
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
From 1b4b3526112a4207f9ea84620fe0e91714f83729 Mon Sep 17 00:00:00 2001
|
||||
From: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
Date: Wed, 16 Mar 2022 17:52:22 +0800
|
||||
Subject: [PATCH 108/109] test: enable epoll in sanity scripts
|
||||
|
||||
epoll is enabled by WD_COMP_EPOLL_EN,
|
||||
so set it to 1 to test the function.
|
||||
|
||||
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
|
||||
---
|
||||
test/sanity_test.sh | 3 ++-
|
||||
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/test/sanity_test.sh b/test/sanity_test.sh
|
||||
index 688485c..207eee5 100755
|
||||
--- a/test/sanity_test.sh
|
||||
+++ b/test/sanity_test.sh
|
||||
@@ -362,7 +362,8 @@ run_zip_test_v2()
|
||||
dd if=/var/log/syslog of=/tmp/syslog bs=1M count=16 >& /dev/null
|
||||
sw_dfl_hw_ifl /tmp/syslog
|
||||
hw_dfl_sw_ifl /tmp/syslog
|
||||
- hw_dfl_hw_ifl /tmp/syslog
|
||||
+ WD_COMP_EPOLL_EN=1 hw_dfl_hw_ifl /tmp/syslog
|
||||
+ WD_COMP_EPOLL_EN=0 hw_dfl_hw_ifl /tmp/syslog
|
||||
# test without environment variables
|
||||
#zip_sva_perf -b 8192 -s 81920 -l 1000 --self
|
||||
# test with environment variables
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,162 +0,0 @@
|
||||
From c46b3f972de457ffdb80325f88eae175bd8bd3a7 Mon Sep 17 00:00:00 2001
|
||||
From: Kai Ye <yekai13@huawei.com>
|
||||
Date: Fri, 1 Apr 2022 11:01:11 +0800
|
||||
Subject: [PATCH 110/183] drv/sec - modification for clean code
|
||||
|
||||
1. Delete some debug code. Debug code is not allowed in the
|
||||
release version.
|
||||
2. Fix a code style issue in sec drv exit.
|
||||
|
||||
Signed-off-by: Kai Ye <yekai13@huawei.com>
|
||||
---
|
||||
drv/hisi_sec.c | 67 ++++++--------------------------------------------
|
||||
1 file changed, 7 insertions(+), 60 deletions(-)
|
||||
|
||||
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
|
||||
index 0732cdc..396e11e 100644
|
||||
--- a/drv/hisi_sec.c
|
||||
+++ b/drv/hisi_sec.c
|
||||
@@ -486,20 +486,6 @@ static int g_hmac_a_alg[WD_DIGEST_TYPE_MAX] = {
|
||||
int hisi_sec_init(struct wd_ctx_config_internal *config, void *priv);
|
||||
void hisi_sec_exit(void *priv);
|
||||
|
||||
-#ifdef DEBUG
|
||||
-static void sec_dump_bd(unsigned char *bd, unsigned int len)
|
||||
-{
|
||||
- unsigned int i;
|
||||
-
|
||||
- for (i = 0; i < len; i++) {
|
||||
- WD_ERR("\\0x%02x", bd[i]);
|
||||
- if ((i + 1) % WORD_BYTES == 0)
|
||||
- WD_ERR("\n");
|
||||
- }
|
||||
- WD_ERR("\n");
|
||||
-}
|
||||
-#endif
|
||||
-
|
||||
/* increment counter (128-bit int) by software */
|
||||
static void ctr_iv_inc(__u8 *counter, __u32 c)
|
||||
{
|
||||
@@ -1286,11 +1272,6 @@ static void parse_digest_bd2(struct hisi_sec_sqe *sqe,
|
||||
recv_msg->data_fmt = hisi_sec_get_data_fmt_v2(sqe->sds_sa_type);
|
||||
recv_msg->in = (__u8 *)(uintptr_t)sqe->type2.data_src_addr;
|
||||
recv_msg->alg_type = WD_DIGEST;
|
||||
-
|
||||
-#ifdef DEBUG
|
||||
- WD_ERR("Dump digest recv sqe-->!\n");
|
||||
- sec_dump_bd((unsigned char *)sqe, SQE_BYTES_NUMS);
|
||||
-#endif
|
||||
}
|
||||
|
||||
static int digest_long_bd_check(struct wd_digest_msg *msg)
|
||||
@@ -1385,11 +1366,6 @@ int hisi_sec_digest_send(handle_t ctx, struct wd_digest_msg *msg)
|
||||
|
||||
qm_fill_digest_long_bd(msg, &sqe);
|
||||
|
||||
-#ifdef DEBUG
|
||||
- WD_ERR("Dump digest send sqe-->!\n");
|
||||
- sec_dump_bd((unsigned char *)&sqe, SQE_BYTES_NUMS);
|
||||
-#endif
|
||||
-
|
||||
sqe.type2.tag = msg->tag;
|
||||
ret = hisi_qm_send(h_qp, &sqe, 1, &count);
|
||||
if (ret < 0) {
|
||||
@@ -1539,11 +1515,6 @@ int hisi_sec_digest_send_v3(handle_t ctx, struct wd_digest_msg *msg)
|
||||
|
||||
qm_fill_digest_long_bd3(msg, &sqe);
|
||||
|
||||
-#ifdef DEBUG
|
||||
- WD_ERR("Dump digest send sqe-->!\n");
|
||||
- sec_dump_bd((unsigned char *)&sqe, SQE_BYTES_NUMS);
|
||||
-#endif
|
||||
-
|
||||
sqe.tag = (__u64)(uintptr_t)msg->tag;
|
||||
|
||||
ret = hisi_qm_send(h_qp, &sqe, 1, &count);
|
||||
@@ -1582,11 +1553,6 @@ static void parse_digest_bd3(struct hisi_sec_sqe3 *sqe,
|
||||
recv_msg->data_fmt = hisi_sec_get_data_fmt_v3(sqe->bd_param);
|
||||
recv_msg->in = (__u8 *)(uintptr_t)sqe->data_src_addr;
|
||||
recv_msg->alg_type = WD_DIGEST;
|
||||
-
|
||||
-#ifdef DEBUG
|
||||
- WD_ERR("Dump digest recv sqe-->!\n");
|
||||
- sec_dump_bd((unsigned char *)sqe, SQE_BYTES_NUMS);
|
||||
-#endif
|
||||
}
|
||||
|
||||
int hisi_sec_digest_recv_v3(handle_t ctx, struct wd_digest_msg *recv_msg)
|
||||
@@ -1886,11 +1852,6 @@ int hisi_sec_aead_send(handle_t ctx, struct wd_aead_msg *msg)
|
||||
|
||||
fill_aead_bd2_addr(msg, &sqe);
|
||||
|
||||
-#ifdef DEBUG
|
||||
- WD_ERR("Dump aead send sqe-->!\n");
|
||||
- sec_dump_bd((unsigned char *)&sqe, SQE_BYTES_NUMS);
|
||||
-#endif
|
||||
-
|
||||
sqe.type2.tag = (__u16)msg->tag;
|
||||
|
||||
ret = hisi_qm_send(h_qp, &sqe, 1, &count);
|
||||
@@ -1938,11 +1899,6 @@ static void parse_aead_bd2(struct hisi_sec_sqe *sqe,
|
||||
SEC_AUTH_LEN_MASK;
|
||||
recv_msg->out_bytes = sqe->type2.clen_ivhlen +
|
||||
sqe->type2.cipher_src_offset;
|
||||
-
|
||||
-#ifdef DEBUG
|
||||
- WD_ERR("Dump aead recv sqe-->!\n");
|
||||
- sec_dump_bd((unsigned char *)sqe, SQE_BYTES_NUMS);
|
||||
-#endif
|
||||
}
|
||||
|
||||
int hisi_sec_aead_recv(handle_t ctx, struct wd_aead_msg *recv_msg)
|
||||
@@ -2153,11 +2109,6 @@ int hisi_sec_aead_send_v3(handle_t ctx, struct wd_aead_msg *msg)
|
||||
|
||||
fill_aead_bd3_addr(msg, &sqe);
|
||||
|
||||
-#ifdef DEBUG
|
||||
- WD_ERR("Dump aead send sqe-->!\n");
|
||||
- sec_dump_bd((unsigned char *)&sqe, SQE_BYTES_NUMS);
|
||||
-#endif
|
||||
-
|
||||
sqe.tag = msg->tag;
|
||||
ret = hisi_qm_send(h_qp, &sqe, 1, &count);
|
||||
if (ret < 0) {
|
||||
@@ -2204,11 +2155,6 @@ static void parse_aead_bd3(struct hisi_sec_sqe3 *sqe,
|
||||
SEC_MAC_LEN_MASK;
|
||||
recv_msg->out_bytes = sqe->c_len_ivin +
|
||||
sqe->cipher_src_offset;
|
||||
-
|
||||
-#ifdef DEBUG
|
||||
- WD_ERR("Dump aead recv sqe-->!\n");
|
||||
- sec_dump_bd((unsigned char *)sqe, SQE_BYTES_NUMS);
|
||||
-#endif
|
||||
}
|
||||
|
||||
int hisi_sec_aead_recv_v3(handle_t ctx, struct wd_aead_msg *recv_msg)
|
||||
@@ -2296,16 +2242,17 @@ out:
|
||||
|
||||
void hisi_sec_exit(void *priv)
|
||||
{
|
||||
- if (!priv) {
|
||||
- WD_ERR("hisi sec exit input parameter is err!\n");
|
||||
- return;
|
||||
- }
|
||||
-
|
||||
struct hisi_sec_ctx *sec_ctx = priv;
|
||||
- struct wd_ctx_config_internal *config = &sec_ctx->config;
|
||||
+ struct wd_ctx_config_internal *config;
|
||||
handle_t h_qp;
|
||||
int i;
|
||||
|
||||
+ if (!sec_ctx) {
|
||||
+ WD_ERR("hisi sec exit input parameter is err!\n");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ config = &sec_ctx->config;
|
||||
for (i = 0; i < config->ctx_num; i++) {
|
||||
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
|
||||
hisi_qm_free_qp(h_qp);
|
||||
--
|
||||
2.27.0
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user