libwd: backport for uadk from 2.3.31 to 2.3.36

Update some patch for uadk from mainline.
To get more information, please visit the homepage:
https://github.comp/Linaro/uadk

Signed-off-by: Yang Shen <shenyang39@huawei.com>
(cherry picked from commit ec2f993b84012fa86acbeb8a0ae943ebdb61eb82)
This commit is contained in:
Yang Shen 2022-07-26 09:56:35 +08:00 committed by openeuler-sync-bot
parent 4a483583e9
commit 47b81024d5
69 changed files with 21901 additions and 1 deletions

View File

@ -0,0 +1,162 @@
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

View File

@ -0,0 +1,410 @@
From c9ce97bff9154e712225fb06dc692b5101bd7eef Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 2 Apr 2022 09:47:09 +0800
Subject: [PATCH 111/183] uadk: fix mempool code
1.optimize print info
2.numa node should be checked first
3.remove unused function
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_mempool.c | 149 ++++++++++++++++++++++-----------------------------
1 file changed, 64 insertions(+), 85 deletions(-)
diff --git a/wd_mempool.c b/wd_mempool.c
index 8467c48..7701f63 100644
--- a/wd_mempool.c
+++ b/wd_mempool.c
@@ -33,7 +33,6 @@
#define round_down(x, y) ((x) & ~wd_round_mask(x, y))
#define WD_MEMPOOL_BLOCK_SIZE ((unsigned long)1 << 12)
#define WD_MEMPOOL_SIZE_MASK (WD_MEMPOOL_BLOCK_SIZE - 1)
-#define WD_MEMPOOL_NO_NUMA -1
#define WD_HUNDRED 100
#define PAGE_SIZE_OFFSET 10
@@ -303,10 +302,13 @@ void *wd_block_alloc(handle_t blkpool)
struct blkpool *bp = (struct blkpool*)blkpool;
void *p;
- if (!bp)
+ if (!bp) {
+ WD_ERR("invalid: block pool is NULL!\n");
return NULL;
+ }
if (!wd_atomic_test_add(&bp->ref, 1, 0)) {
+ WD_ERR("failed to alloc block, block pool is busy now!\n");
return NULL;
}
@@ -353,7 +355,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;
+ return -WD_ENOMEM;
}
zone->addr = addr;
@@ -398,7 +400,7 @@ static int check_mempool_real_size(struct mempool *mp, struct blkpool *bp)
if (bp->blk_size * bp->depth > mp->real_size) {
WD_ERR("invalid: mempool size is too small: %lu!\n",
mp->real_size);
- return -ENOMEM;
+ return -WD_ENOMEM;
}
return 0;
@@ -416,14 +418,15 @@ static int alloc_block_from_mempool(struct mempool *mp,
do {
pos_first = find_next_zero_bit(mp->bitmap, pos_last);
- if (pos_first == mp->bitmap->bits)
- return -ENOMEM;
+ if (pos_first == mp->bitmap->bits) {
+ WD_ERR("failed to find free block from mempool!\n");
+ return -WD_ENOMEM;
+ }
pos_last = pos_first;
- for (i = 0; i < mem_combined_num - 1; i++) {
+ for (i = 0; i < mem_combined_num - 1; i++)
if (!test_bit(mp->bitmap, ++pos_last))
break;
- }
} while (i != mem_combined_num - 1);
for (i = pos_last; i >= pos_first; i--)
@@ -439,7 +442,7 @@ static int alloc_block_from_mempool(struct mempool *mp,
err_clear_bit:
for (i = pos_last; i >= pos_first; i--)
clear_bit(mp->bitmap, i);
- return -ENOMEM;
+ return -WD_ENOMEM;
}
/* In this case, multiple blocks are in one mem block */
@@ -447,7 +450,7 @@ static int alloc_mem_multi_in_one(struct mempool *mp, struct blkpool *bp)
{
int mem_splited_num = mp->blk_size / bp->blk_size;
int blk_num = bp->depth;
- int ret = -ENOMEM;
+ int ret = -WD_ENOMEM;
int pos = 0;
wd_spinlock(&mp->lock);
@@ -490,7 +493,7 @@ static int alloc_mem_one_need_multi(struct mempool *mp, struct blkpool *bp)
wd_spinlock(&mp->lock);
if (check_mempool_real_size(mp, bp)) {
- ret = -ENOMEM;
+ ret = -WD_ENOMEM;
goto err_check_size;
}
@@ -535,13 +538,12 @@ static int init_blkpool_elem(struct blkpool *bp)
bp->blk_elem = calloc(bp->depth, sizeof(void *));
if (!bp->blk_elem) {
WD_ERR("failed to alloc memory for blk_elem!\n");
- return -ENOMEM;
+ return -WD_ENOMEM;
}
- TAILQ_FOREACH(iter, &bp->mz_list, node) {
+ TAILQ_FOREACH(iter, &bp->mz_list, node)
for (i = 0; i < iter->blk_num; i++)
bp->blk_elem[idx++] = iter->addr + i * bp->blk_size;
- }
return 0;
}
@@ -558,8 +560,10 @@ handle_t wd_blockpool_create(handle_t mempool, size_t block_size,
return (handle_t)(-WD_EINVAL);
}
- if (!wd_atomic_test_add(&mp->ref, 1, 0))
+ if (!wd_atomic_test_add(&mp->ref, 1, 0)) {
+ WD_ERR("failed to create blockpool, mempool is busy now!\n");
return (handle_t)(-WD_EBUSY);
+ }
bp = calloc(1, sizeof(struct blkpool));
if (!bp) {
@@ -574,16 +578,12 @@ handle_t wd_blockpool_create(handle_t mempool, size_t block_size,
bp->mp = mp;
ret = alloc_mem_from_mempool(mp, bp);
- if (ret < 0) {
- WD_ERR("failed to allocate memory from mempool!\n");
+ if (ret < 0)
goto err_free_bp;
- }
ret = init_blkpool_elem(bp);
- if (ret < 0) {
- WD_ERR("failed to init blkpool!\n");
+ if (ret < 0)
goto err_free_mem;
- }
wd_atomic_add(&bp->ref, 1);
return (handle_t)bp;
@@ -625,12 +625,11 @@ static int get_value_from_sysfs(const char *path, ssize_t path_size)
ssize_t size;
int fd;
- if (!path || !path_size)
- return -WD_ENODEV;
-
ptrRet = realpath(path, dev_path);
- if (ptrRet == NULL)
+ if (!ptrRet) {
+ WD_ERR("failed to resolve path: %s!\n", path);
return -WD_ENODEV;
+ }
fd = open(dev_path, O_RDONLY, 0);
if (fd < 0) {
@@ -663,24 +662,28 @@ static int get_hugepage_info_per_type(const char *hugepage_path, int path_size,
char *size_pos;
int ret;
- if (!hugepage_path || !path_size)
- return -WD_ENODEV;
-
size_pos = index(name, '-');
- if (!size_pos)
- return -1;
+ if (!size_pos) {
+ WD_ERR("failed to resolve dir name: %s!\n", name);
+ return -WD_EINVAL;
+ }
+
size_pos++;
errno = 0;
size = strtol(size_pos, NULL, 10);
- if (errno)
+ if (errno) {
+ WD_ERR("failed to resolve size pos to number: %s!\n", size_pos);
return -errno;
+ }
cfg->page_size = size << PAGE_SIZE_OFFSET;
ret = snprintf(path, sizeof(path), "%s/%s/nr_hugepages", hugepage_path,
name);
- if (ret < 0)
- return -EINVAL;
+ if (ret < 0) {
+ WD_ERR("failed to get nr hugepages path!\n");
+ return -WD_EINVAL;
+ }
ret = get_value_from_sysfs(path, MAX_ATTR_STR_SIZE);
if (ret < 0)
@@ -690,15 +693,17 @@ static int get_hugepage_info_per_type(const char *hugepage_path, int path_size,
ret = snprintf(path, sizeof(path), "%s/%s/free_hugepages",
hugepage_path, name);
- if (ret < 0)
- return -EINVAL;
+ if (ret < 0) {
+ WD_ERR("failed to get free hugepages path!\n");
+ return -WD_EINVAL;
+ }
ret = get_value_from_sysfs(path, MAX_ATTR_STR_SIZE);
if (ret < 0)
return ret;
cfg->free_num = ret;
- return 1;
+ return 0;
}
static void put_hugepage_info(struct mempool *mp)
@@ -720,13 +725,12 @@ static int get_hugepage_info(struct mempool *mp)
DIR *dir;
int ret;
- if (mp->node == -1)
- return -EINVAL;
-
ret = snprintf(hugepage_path, sizeof(hugepage_path), "%s%d/hugepages",
SYSFS_NODE_PATH, mp->node);
- if (ret < 0)
- return -EINVAL;
+ if (ret < 0) {
+ WD_ERR("failed to get hugepages path!\n");
+ return -WD_EINVAL;
+ }
dir = opendir(hugepage_path);
if (!dir) {
@@ -747,10 +751,8 @@ static int get_hugepage_info(struct mempool *mp)
}
ret = get_hugepage_info_per_type(hugepage_path, MAX_HP_STR_SIZE,
hp_dir, tmp);
- if (ret < 0) {
- WD_ERR("failed to get hugepage info!\n");
+ if (ret < 0)
goto err_free;
- }
/* list: page size small -> big */
TAILQ_FOREACH(iter, &mp->hp_list, node) {
@@ -783,13 +785,6 @@ static int mbind_memory(void *addr, size_t size, int node)
unsigned long node_mask;
int ret = 0;
- /*
- * if node is equal to -1, the memory is not bound to numa node by default
- * or the system does not support numa.
- */
- if (node == -1)
- return ret;
-
node_mask = 1U << (unsigned int)node;
ret = mbind(addr, size, MPOL_BIND, &node_mask, max_node, 0);
if (ret < 0) {
@@ -814,13 +809,13 @@ static int alloc_mem_from_hugepage(struct mempool *mp)
return ret;
/* find proper hugepage: use small huge page if possible */
- TAILQ_FOREACH(iter, &mp->hp_list, node) {
+ TAILQ_FOREACH(iter, &mp->hp_list, node)
if (iter->page_size * iter->free_num >= mp->size)
break;
- }
+
if (!iter) {
WD_ERR("failed to find proper hugepage!\n");
- ret = -ENOMEM;
+ ret = -WD_ENOMEM;
goto err_put_info;
}
@@ -841,7 +836,7 @@ static int alloc_mem_from_hugepage(struct mempool *mp)
MAP_ANONYMOUS | MAP_HUGETLB | flags, -1, 0);
if (p == MAP_FAILED) {
WD_ERR("failed to allocate huge page!\n");
- ret = -ENOMEM;
+ ret = -WD_ENOMEM;
goto err_put_info;
}
@@ -870,24 +865,6 @@ static void free_hugepage_mem(struct mempool *mp)
put_hugepage_info(mp);
}
-static int alloc_mempool_memory(struct mempool *mp)
-{
- int ret;
-
- ret = alloc_mem_from_hugepage(mp);
- if (ret) {
- WD_ERR("failed to alloc memory from hugepage!\n");
- return -ENOMEM;
- }
-
- return 0;
-}
-
-static void free_mempool_memory(struct mempool *mp)
-{
- free_hugepage_mem(mp);
-}
-
static int init_mempool(struct mempool *mp)
{
/* size of mp should align to 4KB */
@@ -896,7 +873,7 @@ static int init_mempool(struct mempool *mp)
bm = create_bitmap(bits);
if (!bm)
- return -ENOMEM;
+ return -WD_ENOMEM;
mp->bitmap = bm;
mp->free_blk_num = bits;
mp->blk_num = bits;
@@ -915,8 +892,10 @@ handle_t wd_mempool_create(size_t size, int node)
struct mempool *mp;
int ret;
- if (!size || node < WD_MEMPOOL_NO_NUMA || node > numa_max_node())
+ if (!size || node < 0 || node > numa_max_node()) {
+ WD_ERR("invalid: numa node is %d, size is %ld!\n", node, size);
return (handle_t)(-WD_EINVAL);
+ }
if (WD_MEMPOOL_SIZE_MASK & size)
size += WD_MEMPOOL_BLOCK_SIZE - (WD_MEMPOOL_SIZE_MASK & size);
@@ -931,7 +910,7 @@ handle_t wd_mempool_create(size_t size, int node)
mp->size = size;
mp->blk_size = WD_MEMPOOL_BLOCK_SIZE;
- ret = alloc_mempool_memory(mp);
+ ret = alloc_mem_from_hugepage(mp);
if (ret < 0)
goto free_pool;
@@ -943,7 +922,7 @@ handle_t wd_mempool_create(size_t size, int node)
return (handle_t)mp;
free_pool_memory:
- free_mempool_memory(mp);
+ free_hugepage_mem(mp);
free_pool:
free(mp);
return (handle_t)(-WD_ENOMEM);
@@ -961,7 +940,7 @@ void wd_mempool_destroy(handle_t mempool)
wd_atomic_sub(&mp->ref, 1);
while(wd_atomic_load(&mp->ref));
uninit_mempool(mp);
- free_mempool_memory(mp);
+ free_hugepage_mem(mp);
free(mp);
}
@@ -987,8 +966,8 @@ void wd_mempool_stats(handle_t mempool, struct wd_mempool_stats *stats)
stats->blk_size = mp->blk_size;
stats->blk_num = mp->blk_num;
stats->free_blk_num = mp->free_blk_num;
- stats->blk_usage_rate = (stats->blk_num - mp->free_blk_num) * WD_HUNDRED /
- stats->blk_num;
+ stats->blk_usage_rate = (stats->blk_num - mp->free_blk_num) /
+ stats->blk_num * WD_HUNDRED;
wd_unspinlock(&mp->lock);
}
@@ -1009,12 +988,11 @@ void wd_blockpool_stats(handle_t blkpool, struct wd_blockpool_stats *stats)
stats->block_size = bp->blk_size;
stats->block_num = bp->depth;
stats->free_block_num = bp->free_block_num;
- stats->block_usage_rate = (bp->depth - bp->free_block_num) * WD_HUNDRED /
- bp->depth;
+ stats->block_usage_rate = (bp->depth - bp->free_block_num) /
+ bp->depth * WD_HUNDRED;
- TAILQ_FOREACH(iter, &bp->mz_list, node) {
+ TAILQ_FOREACH(iter, &bp->mz_list, node)
size += (iter->end - iter->begin + 1) * bp->mp->blk_size;
- }
if (!size) {
WD_ERR("invalid: blkpool size is zero!\n");
@@ -1022,7 +1000,8 @@ void wd_blockpool_stats(handle_t blkpool, struct wd_blockpool_stats *stats)
return;
}
- stats->mem_waste_rate = (size - bp->blk_size * bp->depth) * WD_HUNDRED / size;
+ stats->mem_waste_rate = (size - bp->blk_size * bp->depth) /
+ size * WD_HUNDRED;
wd_unspinlock(&bp->lock);
}
--
2.27.0

View File

@ -0,0 +1,142 @@
From 60cc5e8ead870777d36eed1242163f678de08226 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 2 Apr 2022 09:47:10 +0800
Subject: [PATCH 112/183] uadk: some clean code for wd
1.remove unused header file
2.simplify code
3.add branch prediction to IO path
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_cipher.c | 1 -
wd_mempool.c | 6 ++----
wd_sched.c | 39 +++++++++++++++++++++++++--------------
3 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/wd_cipher.c b/wd_cipher.c
index 6d286f9..6cf1377 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -7,7 +7,6 @@
#include <stdlib.h>
#include <pthread.h>
#include <sched.h>
-#include <numa.h>
#include "wd_cipher.h"
#include "wd_util.h"
#include "include/drv/wd_cipher_drv.h"
diff --git a/wd_mempool.c b/wd_mempool.c
index 7701f63..03df19a 100644
--- a/wd_mempool.c
+++ b/wd_mempool.c
@@ -488,14 +488,12 @@ static int alloc_mem_one_need_multi(struct mempool *mp, struct blkpool *bp)
int mem_combined_num = bp->blk_size / mp->blk_size +
(bp->blk_size % mp->blk_size ? 1 : 0);
int blk_num = bp->depth;
+ int ret = -WD_ENOMEM;
int pos = 0;
- int ret;
wd_spinlock(&mp->lock);
- if (check_mempool_real_size(mp, bp)) {
- ret = -WD_ENOMEM;
+ if (check_mempool_real_size(mp, bp))
goto err_check_size;
- }
while (blk_num > 0) {
ret = alloc_block_from_mempool(mp, bp, pos,
diff --git a/wd_sched.c b/wd_sched.c
index dfd390b..3a19780 100644
--- a/wd_sched.c
+++ b/wd_sched.c
@@ -180,7 +180,7 @@ static int session_poll_policy_rr(struct wd_sched_ctx *ctx, int numa_id,
end = region[SCHED_MODE_ASYNC][i].end;
ret = session_poll_region(ctx, begin, end, expect,
count);
- if (ret)
+ if (unlikely(ret))
return ret;
}
@@ -207,12 +207,12 @@ static int session_sched_poll_policy(handle_t sched_ctx,
__u16 i;
int ret;
- if (!count || !ctx) {
+ if (unlikely(!count || !ctx)) {
WD_ERR("invalid: sched ctx is NULL or count is zero!\n");
return -WD_EINVAL;
}
- if (ctx->numa_num > NUMA_NUM_NODES) {
+ if (unlikely(ctx->numa_num > NUMA_NUM_NODES)) {
WD_ERR("invalid: ctx's numa number is %u!\n", ctx->numa_num);
return -WD_EINVAL;
}
@@ -224,8 +224,7 @@ static int session_sched_poll_policy(handle_t sched_ctx,
* package last time, it is more efficient. In most
* bad situation, poll ends after MAX_POLL_TIMES loop.
*/
- while (loop_time < MAX_POLL_TIMES) {
- loop_time++;
+ while (++loop_time < MAX_POLL_TIMES) {
for (i = 0; i < ctx->numa_num;) {
/* If current numa is not valid, find next. */
if (!sched_info[i].valid) {
@@ -235,7 +234,7 @@ static int session_sched_poll_policy(handle_t sched_ctx,
last_count = *count;
ret = session_poll_policy_rr(ctx, i, expect, count);
- if (ret)
+ if (unlikely(ret))
return ret;
if (expect == *count)
@@ -438,22 +437,34 @@ out:
return;
}
+static int numa_num_check(__u16 numa_num)
+{
+ int max_node;
+
+ max_node = numa_max_node() + 1;
+ if (max_node <= 0) {
+ WD_ERR("invalid: numa max node is %d!\n", max_node);
+ return -WD_EINVAL;
+ }
+
+ if (!numa_num || numa_num > max_node) {
+ WD_ERR("invalid: numa number is %u!\n", numa_num);
+ return -WD_EINVAL;
+ }
+
+ return 0;
+}
+
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, max_node;
-
- max_node = numa_max_node() + 1;
- if (max_node <= 0)
- return NULL;
+ int i, j;
- if (!numa_num || numa_num > max_node) {
- WD_ERR("invalid: numa number is %u!\n", numa_num);
+ if (numa_num_check(numa_num))
return NULL;
- }
if (sched_type >= SCHED_POLICY_BUTT || !type_num) {
WD_ERR("invalid: sched_type is %u or type_num is %u!\n",
--
2.27.0

View File

@ -0,0 +1,108 @@
From 9dd275d4e67eb7dc6d4ff3cee49e2929bd497b4f Mon Sep 17 00:00:00 2001
From: Liulongfang <liulongfang@huawei.com>
Date: Sat, 2 Apr 2022 09:22:01 +0800
Subject: [PATCH 113/183] wd/sched: modify default sched param
In the general scenario, after the scheduler is initialized, the user
wished to use the default scheduling parameters through the default
configuration when initilazing the task session
Signed-off-by: Liulongfang <liulongfang@huawei.com>
---
wd_sched.c | 42 ++++++++++++++++++++++++++++++++++++++----
1 file changed, 38 insertions(+), 4 deletions(-)
diff --git a/wd_sched.c b/wd_sched.c
index 3a19780..d9a33fc 100644
--- a/wd_sched.c
+++ b/wd_sched.c
@@ -4,8 +4,10 @@
* Copyright 2020-2021 Linaro ltd.
*/
+#define _GNU_SOURCE
#include <stdlib.h>
#include <stdbool.h>
+#include <sched.h>
#include <numa.h>
#include "wd_sched.h"
@@ -19,7 +21,7 @@ enum sched_region_mode {
/**
* sched_key - The key if schedule region.
- * @numa_id: The numa_id map the hardware.
+ * @numa_id: The schedule numa region id.
* @mode: Sync mode:0, async_mode:1
* @type: Service type , the value must smaller than type_num.
* @sync_ctxid: alloc ctx id for sync mode
@@ -109,6 +111,7 @@ static struct sched_ctx_region *sched_get_ctx_range(struct wd_sched_ctx *ctx,
{
struct wd_sched_info *sched_info;
int numa_id;
+ int type;
sched_info = ctx->sched_info;
if (key->numa_id >= 0 &&
@@ -117,8 +120,10 @@ static struct sched_ctx_region *sched_get_ctx_range(struct wd_sched_ctx *ctx,
/* If the key->numa_id is not exist, we should scan for a region */
for (numa_id = 0; numa_id < ctx->numa_num; numa_id++) {
- if (sched_info[numa_id].ctx_region[key->mode][key->type].valid)
- return &sched_info[numa_id].ctx_region[key->mode][key->type];
+ for (type = 0; type < ctx->type_num; type++) {
+ if (sched_info[numa_id].ctx_region[key->mode][type].valid)
+ return &sched_info[numa_id].ctx_region[key->mode][type];
+ }
}
return NULL;
@@ -285,6 +290,29 @@ static __u32 session_sched_init_ctx(handle_t sched_ctx,
return sched_get_next_pos_rr(region, NULL);
}
+static int get_nearby_numa_id(handle_t sched_ctx)
+{
+#define MAX_NUMA_DISTANCE 1024
+ struct wd_sched_ctx *ctx = (struct wd_sched_ctx *)sched_ctx;
+ struct wd_sched_info *sched_info = ctx->sched_info;
+ int cpu = sched_getcpu();
+ int node = numa_node_of_cpu(cpu);
+ int dis = MAX_NUMA_DISTANCE;
+ int i, tmp, valid_id = -1;
+
+ for (i = 0; i < ctx->numa_num; i++) {
+ if (sched_info[i].valid) {
+ tmp = numa_distance(node, i);
+ if (dis > tmp) {
+ valid_id = i;
+ dis = tmp;
+ }
+ }
+ }
+
+ return valid_id;
+}
+
handle_t session_sched_init(handle_t h_sched_ctx, void *sched_param)
{
struct sched_params *param = (struct sched_params *)sched_param;
@@ -296,8 +324,14 @@ handle_t session_sched_init(handle_t h_sched_ctx, void *sched_param)
return (handle_t)(-WD_ENOMEM);
}
- if (!param) {
+ if (!param || param->numa_id < 0) {
memset(skey, 0, sizeof(struct sched_key));
+ skey->numa_id = get_nearby_numa_id(h_sched_ctx);
+ if (skey->numa_id < 0) {
+ WD_ERR("failed to get valid sched numa region!\n");
+ free(skey);
+ return (handle_t)(-WD_ENOMEM);
+ }
} else {
skey->type = param->type;
skey->numa_id = param->numa_id;
--
2.27.0

View File

@ -0,0 +1,44 @@
From 89ce496b9c9f91feb941d6f083771250f886e266 Mon Sep 17 00:00:00 2001
From: Liulongfang <liulongfang@huawei.com>
Date: Wed, 11 May 2022 10:08:22 +0800
Subject: [PATCH 115/183] uadk: update README
add simple compilation instructions for uadk
Signed-off-by: Liulongfang <liulongfang@huawei.com>
---
README | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/README b/README
index 10804ec..34d45e3 100644
--- a/README
+++ b/README
@@ -31,6 +31,24 @@ include/*
docs/*
Documentations.
+Build UADK in native environment
+
+ $ ./cleanup.sh
+
+ Make sure that all generated files could be removed.
+
+ $ ./autogen.sh
+ $ ./conf.sh
+
+ UADK could be configured as either static or dynamic library by conf.sh.
+ By default, it's configured as dynamic library.
+
+ $ make
+ $ sudo make install
+
+ Both dynamic and static libraries would be installed in /usr/local/lib
+ directory. And all head files would be installed in /usr/local/include/uadk
+ directory.
======================================
--
2.27.0

View File

@ -0,0 +1,406 @@
From 6e4ee881aa5eb420fc101cf7d8970d3ba202d926 Mon Sep 17 00:00:00 2001
From: Liulongfang <liulongfang@huawei.com>
Date: Wed, 11 May 2022 11:44:26 +0800
Subject: [PATCH 116/183] uadk: add BD id check for sync mode
In synchronous mode, when multiple threads in a single queue send and
receive messages, if one thread exits the message overtime, other threads
may receive the overtime message, resulting in message misalignment.
Therefore, we need to add the message sequence number check. if it is
not our own sequence number, it means that the message is received
incorrectly and needs to exit.
Signed-off-by: Liulongfang <liulongfang@huawei.com>
---
drv/hisi_comp.c | 34 ++++++++++++++++++++++------------
drv/hisi_hpre.c | 17 +++++++++++++++++
drv/hisi_qm_udrv.c | 36 ++++++++++++++++++++++++++++++++++++
drv/hisi_sec.c | 35 +++++++++++++++++++++++++++++++----
include/drv/wd_dh_drv.h | 2 +-
include/drv/wd_ecc_drv.h | 2 +-
include/drv/wd_rsa_drv.h | 2 +-
include/hisi_qm_udrv.h | 15 +++++++++++++++
8 files changed, 124 insertions(+), 19 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index 9fdf3f1..e1d2f6e 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -873,6 +873,7 @@ static int hisi_zip_comp_send(handle_t ctx, struct wd_comp_msg *msg, void *priv)
__u16 count = 0;
int ret;
+ hisi_set_msg_id(h_qp, &msg->tag);
ret = fill_zip_comp_sqe(qp, msg, &sqe);
if (unlikely(ret < 0)) {
WD_ERR("failed to fill zip sqe, ret = %d!\n", ret);
@@ -939,6 +940,22 @@ static void free_hw_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
}
}
+static void get_ctx_buf(struct hisi_zip_sqe *sqe,
+ struct wd_comp_msg *recv_msg)
+{
+ recv_msg->avail_out = sqe->dest_avail_out;
+ if (VA_ADDR(sqe->stream_ctx_addr_h, sqe->stream_ctx_addr_l)) {
+ /*
+ * In ASYNC mode, recv_msg->ctx_buf is NULL.
+ * recv_msg->ctx_buf is only valid in SYNC mode.
+ * ctx_dwx uses 4 BYTES
+ */
+ *(__u32 *)recv_msg->ctx_buf = sqe->ctx_dw0;
+ *(__u32 *)(recv_msg->ctx_buf + CTX_DW1_OFFSET) = sqe->ctx_dw1;
+ *(__u32 *)(recv_msg->ctx_buf + CTX_DW2_OFFSET) = sqe->ctx_dw2;
+ }
+}
+
static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
struct wd_comp_msg *recv_msg)
{
@@ -947,7 +964,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
__u16 lstblk = sqe->dw3 & HZ_LSTBLK_MASK;
__u32 status = sqe->dw3 & HZ_STATUS_MASK;
__u32 type = sqe->dw9 & HZ_REQ_TYPE_MASK;
- int alg_type;
+ int alg_type, ret;
__u32 tag;
alg_type = get_alg_type(type);
@@ -957,6 +974,9 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
}
tag = ops[alg_type].get_tag(sqe);
+ ret = hisi_check_bd_id((handle_t)qp, recv_msg->tag, tag);
+ if (ret)
+ return ret;
recv_msg->tag = tag;
@@ -980,17 +1000,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
ops[alg_type].get_data_size(sqe, qp->q_info.qc_type, recv_msg);
- recv_msg->avail_out = sqe->dest_avail_out;
- if (VA_ADDR(sqe->stream_ctx_addr_h, sqe->stream_ctx_addr_l)) {
- /*
- * In ASYNC mode, recv_msg->ctx_buf is NULL.
- * recv_msg->ctx_buf is only valid in SYNC mode.
- * ctx_dwx uses 4 BYTES
- */
- *(__u32 *)recv_msg->ctx_buf = sqe->ctx_dw0;
- *(__u32 *)(recv_msg->ctx_buf + CTX_DW1_OFFSET) = sqe->ctx_dw1;
- *(__u32 *)(recv_msg->ctx_buf + CTX_DW2_OFFSET) = sqe->ctx_dw2;
- }
+ get_ctx_buf(sqe, recv_msg);
/* last block no space, need resend null size req */
if (ctx_st == HZ_DECOMP_NO_SPACE)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 7e14027..33127e0 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -528,6 +528,7 @@ static int rsa_send(handle_t ctx, struct wd_rsa_msg *msg)
if (ret < 0)
return ret;
+ hisi_set_msg_id(h_qp, &msg->tag);
hw_msg.done = 0x1;
hw_msg.etype = 0x0;
hw_msg.low_tag = msg->tag;
@@ -546,6 +547,10 @@ static int rsa_recv(handle_t ctx, struct wd_rsa_msg *msg)
if (ret < 0)
return ret;
+ ret = hisi_check_bd_id(h_qp, msg->tag, hw_msg.low_tag);
+ if (ret)
+ return ret;
+
if (hw_msg.done != HPRE_HW_TASK_DONE ||
hw_msg.etype || hw_msg.etype1) {
WD_ERR("failed to do rsa task! done=0x%x, etype=0x%x, etype1=0x%x!\n",
@@ -668,6 +673,7 @@ static int dh_send(handle_t ctx, struct wd_dh_msg *msg)
if (ret)
return ret;
+ hisi_set_msg_id(h_qp, &msg->tag);
hw_msg.low_out = LW_U32((uintptr_t)req->pri);
hw_msg.hi_out = HI_U32((uintptr_t)req->pri);
hw_msg.done = 0x1;
@@ -688,6 +694,10 @@ static int dh_recv(handle_t ctx, struct wd_dh_msg *msg)
if (ret < 0)
return ret;
+ ret = hisi_check_bd_id(h_qp, msg->tag, hw_msg.low_tag);
+ if (ret)
+ return ret;
+
if (hw_msg.done != HPRE_HW_TASK_DONE ||
hw_msg.etype || hw_msg.etype1) {
WD_ERR("failed to do dh task! done=0x%x, etype=0x%x, etype1=0x%x!\n",
@@ -1766,6 +1776,9 @@ free_dst:
static int ecc_send(handle_t ctx, struct wd_ecc_msg *msg)
{
+ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+
+ hisi_set_msg_id(h_qp, &msg->tag);
if (msg->req.op_type == WD_SM2_ENCRYPT)
return sm2_enc_send(ctx, msg);
else if (msg->req.op_type == WD_SM2_DECRYPT)
@@ -2333,6 +2346,10 @@ static int ecc_recv(handle_t ctx, struct wd_ecc_msg *msg)
if (ret)
return ret;
+ ret = hisi_check_bd_id(h_qp, msg->tag, hw_msg.low_tag);
+ if (ret)
+ return ret;
+
if (hw_msg.alg == HPRE_ALG_ECDH_MULTIPLY &&
hw_msg.sm2_mlen == HPRE_SM2_ENC)
return sm2_enc_parse(h_qp, msg, &hw_msg);
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 2c0d87c..53d5a55 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -528,6 +528,42 @@ int hisi_qm_recv(handle_t h_qp, void *resp, __u16 expect, __u16 *count)
return ret;
}
+int hisi_check_bd_id(handle_t h_qp, __u32 mid, __u32 bid)
+{
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ __u8 mode = qp->q_info.qp_mode;
+
+ if (mode == CTX_MODE_SYNC && mid != bid) {
+ WD_ERR("failed to recv self bd, send id: %u, recv id: %u\n",
+ mid, bid);
+ return -WD_EINVAL;
+ }
+
+ return 0;
+}
+
+void hisi_set_msg_id(handle_t h_qp, __u32 *tag)
+{
+ static __thread __u64 rand_seed = 0x330eabcd;
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ __u8 mode = qp->q_info.qp_mode;
+ __u16 seeds[3] = {0};
+ __u64 id;
+
+ /*
+ * The random message id on a single queue is obtained through the
+ * system's pseudo-random number generation algorithm to ensure
+ * that 1024 packets on a queue will not have duplicate id
+ */
+ if (mode == CTX_MODE_SYNC) {
+ seeds[0] = LW_U16(rand_seed);
+ seeds[1] = LW_U16(rand_seed >> 16);
+ id = nrand48(seeds);
+ *tag = LW_U32(id);
+ rand_seed = id;
+ }
+}
+
static void *hisi_qm_create_sgl(__u32 sge_num)
{
void *sgl;
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 396e11e..88eacc3 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -929,6 +929,7 @@ int hisi_sec_cipher_send(handle_t ctx, struct wd_cipher_msg *msg)
return ret;
}
+ hisi_set_msg_id(h_qp, &msg->tag);
sqe.type2.clen_ivhlen |= (__u32)msg->in_bytes;
sqe.type2.tag = (__u16)msg->tag;
fill_cipher_bd2_addr(msg, &sqe);
@@ -959,6 +960,10 @@ int hisi_sec_cipher_recv(handle_t ctx, struct wd_cipher_msg *recv_msg)
if (ret < 0)
return ret;
+ ret = hisi_check_bd_id(h_qp, (__u16)recv_msg->tag, sqe.type2.tag);
+ if (ret)
+ return ret;
+
parse_cipher_bd2(&sqe, recv_msg);
recv_msg->tag = sqe.type2.tag;
@@ -1130,6 +1135,7 @@ int hisi_sec_cipher_send_v3(handle_t ctx, struct wd_cipher_msg *msg)
return ret;
}
+ hisi_set_msg_id(h_qp, &msg->tag);
sqe.c_len_ivin = (__u32)msg->in_bytes;
sqe.tag = (__u64)(uintptr_t)msg->tag;
fill_cipher_bd3_addr(msg, &sqe);
@@ -1187,6 +1193,10 @@ int hisi_sec_cipher_recv_v3(handle_t ctx, struct wd_cipher_msg *recv_msg)
if (ret < 0)
return ret;
+ ret = hisi_check_bd_id(h_qp, recv_msg->tag, sqe.tag);
+ if (ret)
+ return ret;
+
parse_cipher_bd3(&sqe, recv_msg);
recv_msg->tag = sqe.tag;
@@ -1366,7 +1376,8 @@ int hisi_sec_digest_send(handle_t ctx, struct wd_digest_msg *msg)
qm_fill_digest_long_bd(msg, &sqe);
- sqe.type2.tag = msg->tag;
+ hisi_set_msg_id(h_qp, &msg->tag);
+ sqe.type2.tag = (__u16)msg->tag;
ret = hisi_qm_send(h_qp, &sqe, 1, &count);
if (ret < 0) {
if (ret != -WD_EBUSY)
@@ -1395,6 +1406,10 @@ int hisi_sec_digest_recv(handle_t ctx, struct wd_digest_msg *recv_msg)
if (ret < 0)
return ret;
+ ret = hisi_check_bd_id(h_qp, (__u16)recv_msg->tag, sqe.type2.tag);
+ if (ret)
+ return ret;
+
parse_digest_bd2(&sqe, recv_msg);
if (recv_msg->data_fmt == WD_SGL_BUF)
@@ -1515,6 +1530,7 @@ int hisi_sec_digest_send_v3(handle_t ctx, struct wd_digest_msg *msg)
qm_fill_digest_long_bd3(msg, &sqe);
+ hisi_set_msg_id(h_qp, &msg->tag);
sqe.tag = (__u64)(uintptr_t)msg->tag;
ret = hisi_qm_send(h_qp, &sqe, 1, &count);
@@ -1566,6 +1582,10 @@ int hisi_sec_digest_recv_v3(handle_t ctx, struct wd_digest_msg *recv_msg)
if (ret < 0)
return ret;
+ ret = hisi_check_bd_id(h_qp, recv_msg->tag, sqe.tag);
+ if (ret)
+ return ret;
+
parse_digest_bd3(&sqe, recv_msg);
if (recv_msg->data_fmt == WD_SGL_BUF)
@@ -1851,7 +1871,7 @@ int hisi_sec_aead_send(handle_t ctx, struct wd_aead_msg *msg)
}
fill_aead_bd2_addr(msg, &sqe);
-
+ hisi_set_msg_id(h_qp, &msg->tag);
sqe.type2.tag = (__u16)msg->tag;
ret = hisi_qm_send(h_qp, &sqe, 1, &count);
@@ -1912,6 +1932,10 @@ int hisi_sec_aead_recv(handle_t ctx, struct wd_aead_msg *recv_msg)
if (ret < 0)
return ret;
+ ret = hisi_check_bd_id(h_qp, (__u16)recv_msg->tag, sqe.type2.tag);
+ if (ret)
+ return ret;
+
parse_aead_bd2(&sqe, recv_msg);
if (recv_msg->data_fmt == WD_SGL_BUF)
@@ -2078,7 +2102,6 @@ static int fill_aead_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe)
return 0;
}
-
int hisi_sec_aead_send_v3(handle_t ctx, struct wd_aead_msg *msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
@@ -2108,7 +2131,7 @@ int hisi_sec_aead_send_v3(handle_t ctx, struct wd_aead_msg *msg)
}
fill_aead_bd3_addr(msg, &sqe);
-
+ hisi_set_msg_id(h_qp, &msg->tag);
sqe.tag = msg->tag;
ret = hisi_qm_send(h_qp, &sqe, 1, &count);
if (ret < 0) {
@@ -2168,6 +2191,10 @@ int hisi_sec_aead_recv_v3(handle_t ctx, struct wd_aead_msg *recv_msg)
if (ret < 0)
return ret;
+ ret = hisi_check_bd_id(h_qp, recv_msg->tag, sqe.tag);
+ if (ret)
+ return ret;
+
parse_aead_bd3(&sqe, recv_msg);
if (recv_msg->data_fmt == WD_SGL_BUF)
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
index 5d436d1..0d3fb2b 100644
--- a/include/drv/wd_dh_drv.h
+++ b/include/drv/wd_dh_drv.h
@@ -13,7 +13,7 @@ extern "C" {
/* DH message format */
struct wd_dh_msg {
struct wd_dh_req req;
- __u64 tag; /* User-defined request identifier */
+ __u32 tag; /* User-defined request identifier */
void *g;
__u16 gbytes;
__u16 key_bytes; /* Input key bytes */
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index 7e0d27e..66ed641 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -48,7 +48,7 @@ extern "C" {
struct wd_ecc_msg {
struct wd_ecc_req req;
struct wd_hash_mt hash;
- __u64 tag; /* User-defined request identifier */
+ __u32 tag; /* User-defined request identifier */
__u8 *key; /* Input key VA, should be DMA buffer */
__u16 key_bytes; /* key bytes */
__u8 curve_id; /* Ec curve denoted by enum wd_ecc_curve_type */
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
index 948625f..837420e 100644
--- a/include/drv/wd_rsa_drv.h
+++ b/include/drv/wd_rsa_drv.h
@@ -39,7 +39,7 @@ struct wd_rsa_kg_out {
/* RSA message format */
struct wd_rsa_msg {
struct wd_rsa_req req;
- __u64 tag; /* User-defined request identifier */
+ __u32 tag; /* User-defined request identifier */
__u16 key_bytes; /* Input key bytes */
__u8 key_type; /* Denoted by enum wd_rsa_key_type */
__u8 result; /* Data format, denoted by WD error code */
diff --git a/include/hisi_qm_udrv.h b/include/hisi_qm_udrv.h
index 68de837..773f57b 100644
--- a/include/hisi_qm_udrv.h
+++ b/include/hisi_qm_udrv.h
@@ -116,6 +116,21 @@ int hisi_qm_recv(handle_t h_qp, void *resp, __u16 expect, __u16 *count);
handle_t hisi_qm_alloc_qp(struct hisi_qm_priv *config, handle_t ctx);
void hisi_qm_free_qp(handle_t h_qp);
+/**
+ * hisi_check_bd_id - Check the SQE BD's id and send msg id.
+ * @h_qp: Handle of the qp.
+ * @mid: send message id.
+ * @bid: recv BD id.
+ */
+int hisi_check_bd_id(handle_t h_qp, __u32 mid, __u32 bid);
+
+/**
+ * hisi_set_msg_id - set the message tag id.
+ * @h_qp: Handle of the qp.
+ * @tag: the message tag id.
+ */
+void hisi_set_msg_id(handle_t h_qp, __u32 *tag);
+
/**
* hisi_qm_create_sglpool - Create sgl pool in qm.
* @sgl_num: the sgl number.
--
2.27.0

View File

@ -0,0 +1,80 @@
From f2b3a8ce0f30c0902ae93edbea5bccd87a166116 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sun, 24 Apr 2022 09:54:22 +0800
Subject: [PATCH 117/183] uadk: ecc: optimize create_ecc_out line
ecc function statements can be simplified.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_ecc.c | 25 +++----------------------
1 file changed, 3 insertions(+), 22 deletions(-)
diff --git a/wd_ecc.c b/wd_ecc.c
index a6c2209..671b62d 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -1284,18 +1284,12 @@ set_param_error:
struct wd_ecc_out *wd_ecxdh_new_out(handle_t sess)
{
- struct wd_ecc_out *ecc_out;
-
if (!sess) {
WD_ERR("invalid: new ecc dh out sess NULL!\n");
return NULL;
}
- ecc_out = create_ecc_out((struct wd_ecc_sess *)sess, ECDH_OUT_PARAM_NUM);
- if (!ecc_out)
- return NULL;
-
- return ecc_out;
+ return create_ecc_out((struct wd_ecc_sess *)sess, ECDH_OUT_PARAM_NUM);
}
void wd_ecxdh_get_out_params(struct wd_ecc_out *out, struct wd_ecc_point **key)
@@ -1881,18 +1875,12 @@ struct wd_ecc_in *wd_sm2_new_verf_in(handle_t sess,
static struct wd_ecc_out *wd_ecc_new_sign_out(struct wd_ecc_sess *sess)
{
- struct wd_ecc_out *ecc_out;
-
if (!sess) {
WD_ERR("invalid: new ecc sout ctx NULL!\n");
return NULL;
}
- ecc_out = create_ecc_out(sess, ECC_SIGN_OUT_PARAM_NUM);
- if (!ecc_out)
- return NULL;
-
- return ecc_out;
+ return create_ecc_out(sess, ECC_SIGN_OUT_PARAM_NUM);
}
struct wd_ecc_out *wd_sm2_new_sign_out(handle_t sess)
@@ -1902,19 +1890,12 @@ struct wd_ecc_out *wd_sm2_new_sign_out(handle_t sess)
struct wd_ecc_out *wd_sm2_new_kg_out(handle_t sess)
{
- struct wd_ecc_out *ecc_out;
-
if (!sess) {
WD_ERR("invalid: new sm2 kg out sess NULL!\n");
return NULL;
}
- ecc_out = create_ecc_out((struct wd_ecc_sess *)sess,
- SM2_KG_OUT_PARAM_NUM);
- if (!ecc_out)
- return NULL;
-
- return ecc_out;
+ return create_ecc_out((struct wd_ecc_sess *)sess, SM2_KG_OUT_PARAM_NUM);
}
void wd_sm2_get_kg_out_params(struct wd_ecc_out *out,
--
2.27.0

View File

@ -0,0 +1,344 @@
From a43bac94144b6bb59a992a3781e5367f67a2af79 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sun, 24 Apr 2022 09:54:23 +0800
Subject: [PATCH 118/183] uadk: fix parameter of function has different name
Parameter of function has different name than previous
declaration of header, so fix them.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
include/wd_aead.h | 4 ++--
include/wd_cipher.h | 4 ++--
include/wd_comp.h | 4 ++--
include/wd_digest.h | 4 ++--
include/wd_ecc.h | 4 ++--
include/wd_rsa.h | 4 ++--
include/wd_util.h | 27 +++++++++++++++------------
v1/drv/hisi_hpre_udrv.h | 2 +-
v1/drv/hisi_qm_udrv.h | 2 +-
v1/drv/hisi_zip_udrv.h | 2 +-
v1/wd_aead.h | 10 +++++-----
v1/wd_cipher.h | 4 ++--
v1/wd_digest.h | 4 ++--
13 files changed, 39 insertions(+), 36 deletions(-)
diff --git a/include/wd_aead.h b/include/wd_aead.h
index a632cd8..3840062 100644
--- a/include/wd_aead.h
+++ b/include/wd_aead.h
@@ -161,11 +161,11 @@ int wd_aead_get_maxauthsize(handle_t h_sess);
/**
* wd_aead_poll_ctx() poll operation for asynchronous operation
- * @index: index of ctx which will be polled.
+ * @idx: index of ctx which will be polled.
* @expt: user expected num respondences
* @count: how many respondences this poll has to get.
*/
-int wd_aead_poll_ctx(__u32 index, __u32 expt, __u32* count);
+int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count);
/**
* wd_aead_poll() Poll finished request.
diff --git a/include/wd_cipher.h b/include/wd_cipher.h
index 660d7e8..127cd45 100644
--- a/include/wd_cipher.h
+++ b/include/wd_cipher.h
@@ -135,11 +135,11 @@ int wd_do_cipher_sync(handle_t h_sess, struct wd_cipher_req *req);
int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req);
/**
* wd_cipher_poll_ctx() poll operation for asynchronous operation
- * @index: index of ctx which will be polled.
+ * @idx: index of ctx which will be polled.
* @expt: user expected num respondences
* @count: how many respondences this poll has to get.
*/
-int wd_cipher_poll_ctx(__u32 index, __u32 expt, __u32* count);
+int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count);
/**
* wd_cipher_poll() Poll finished request.
* this function will call poll_policy function which is registered to wd cipher
diff --git a/include/wd_comp.h b/include/wd_comp.h
index 460cfa7..5688b8b 100644
--- a/include/wd_comp.h
+++ b/include/wd_comp.h
@@ -154,7 +154,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req);
/**
* wd_comp_poll_ctx() - Poll a ctx.
- * @index: The index of ctx which will be polled.
+ * @idx: The index of ctx which will be polled.
* @expt: Max number of requests to poll. If 0, polled all finished
* requests in this ctx.
* @count: Return the number of polled requests finally.
@@ -163,7 +163,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req);
* User defines polling policy in poll_policiy, when it needs to poll a
* specific ctx, this function should be used.
*/
-int wd_comp_poll_ctx(__u32 index, __u32 expt, __u32 *count);
+int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count);
int wd_comp_poll(__u32 expt, __u32 *count);
diff --git a/include/wd_digest.h b/include/wd_digest.h
index 7e93a80..92b9a4f 100644
--- a/include/wd_digest.h
+++ b/include/wd_digest.h
@@ -157,11 +157,11 @@ int wd_digest_set_key(handle_t h_sess, const __u8 *key, __u32 key_len);
/**
* wd_digest_poll() - Poll operation for asynchronous operation.
- * @index: index of ctx which will be polled.
+ * @idx: index of ctx which will be polled.
* @expt: Count of polling
* @count: recv poll nums.
*/
-int wd_digest_poll_ctx(__u32 index, __u32 expt, __u32 *count);
+int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count);
/**
* wd_digest_poll() - Poll operation for asynchronous operation.
diff --git a/include/wd_ecc.h b/include/wd_ecc.h
index 43b9c89..5aaec23 100644
--- a/include/wd_ecc.h
+++ b/include/wd_ecc.h
@@ -458,10 +458,10 @@ int wd_ecc_poll(__u32 expt, __u32 *count);
/**
* wd_do_ecc() - Send a sync eccression request.
- * @sess: The session which request will be sent to.
+ * @h_sess: The session which request will be sent to.
* @req: Request.
*/
-int wd_do_ecc_sync(handle_t sess, struct wd_ecc_req *req);
+int wd_do_ecc_sync(handle_t h_sess, struct wd_ecc_req *req);
/**
* wd_do_ecc_async() - Send an async eccression request.
diff --git a/include/wd_rsa.h b/include/wd_rsa.h
index 0978b79..ef7a12c 100644
--- a/include/wd_rsa.h
+++ b/include/wd_rsa.h
@@ -143,10 +143,10 @@ int wd_rsa_poll(__u32 expt, __u32 *count);
/**
* wd_do_rsa() - Send a sync rsaression request.
- * @sess: The session which request will be sent to.
+ * @h_sess: The session which request will be sent to.
* @req: Request.
*/
-int wd_do_rsa_sync(handle_t sess, struct wd_rsa_req *req);
+int wd_do_rsa_sync(handle_t h_sess, struct wd_rsa_req *req);
/**
* wd_do_rsa_async() - Send an async rsaression request.
diff --git a/include/wd_util.h b/include/wd_util.h
index a41b4c9..7fe3d72 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -168,7 +168,7 @@ void wd_uninit_async_request_pool(struct wd_async_msg_pool *pool);
/*
* wd_get_msg_from_pool() - Get a free message from pool.
* @pool: Pointer of global pools.
- * @index: Index of pool. Should be 0 ~ (pool_num - 1).
+ * @ctx_idx: Index of pool. Should be 0 ~ (pool_num - 1).
* @msg: Put pointer of got message into *msg.
*
* Return tag of got message. This tag can be used to put a message and
@@ -177,25 +177,28 @@ void wd_uninit_async_request_pool(struct wd_async_msg_pool *pool);
* be used to avoid possible error; -WD_EBUSY will return if related message pool
* is full.
*/
-int wd_get_msg_from_pool(struct wd_async_msg_pool *pool, int index, void **msg);
+int wd_get_msg_from_pool(struct wd_async_msg_pool *pool, int ctx_idx,
+ void **msg);
/*
* wd_put_msg_to_pool() - Put a message to pool.
* @pool: Pointer of global pools.
- * @index: Index of pool. Should be 0 ~ (pool_num - 1).
+ * @ctx_idx: Index of pool. Should be 0 ~ (pool_num - 1).
* @tag: Tag of put message.
*/
-void wd_put_msg_to_pool(struct wd_async_msg_pool *pool, int index, __u32 tag);
+void wd_put_msg_to_pool(struct wd_async_msg_pool *pool, int ctx_idx,
+ __u32 tag);
/*
* wd_find_msg_in_pool() - Find a message in pool.
* @pool: Pointer of global pools.
- * @index: Index of pool. Should be 0 ~ (pool_num - 1).
+ * @ctx_idx: Index of pool. Should be 0 ~ (pool_num - 1).
* @tag: Tag of expected message.
*
* Return pointer of message whose tag is input tag.
*/
-void *wd_find_msg_in_pool(struct wd_async_msg_pool *pool, int index, __u32 tag);
+void *wd_find_msg_in_pool(struct wd_async_msg_pool *pool, int ctx_idx,
+ __u32 tag);
/*
* wd_check_datalist() - Check the data list length
@@ -243,7 +246,7 @@ int wd_parse_async_poll_num(struct wd_env_config *config, const char *s);
* wd_alg_env_init() - Init wd algorithm environment variable configurations.
* This is a help function which can be used by specific
* wd algorithm APIs.
- * @config: Pointer of wd_env_config which is used to store environment
+ * @env_config: Pointer of wd_env_config which is used to store environment
* variable information.
* @table: Table which is used to define specific environment variable、its
* default value and related parsing operations.
@@ -251,7 +254,7 @@ int wd_parse_async_poll_num(struct wd_env_config *config, const char *s);
* environment init.
* @table_size: Size of above table.
*/
-int wd_alg_env_init(struct wd_env_config *config,
+int wd_alg_env_init(struct wd_env_config *env_config,
const struct wd_config_variable *table,
const struct wd_alg_ops *ops,
__u32 table_size,
@@ -272,9 +275,9 @@ void wd_alg_env_uninit(struct wd_env_config *env_config,
* task queue.
* @config: Pointer of wd_env_config which is used to store environment
* variable information.
- * @index: Index of ctx in config.
+ * @idx: Index of ctx in config.
*/
-int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 index);
+int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx);
/*
* dump_env_info() - dump wd algorithm ctx info.
@@ -287,12 +290,12 @@ void dump_env_info(struct wd_env_config *config);
* wd_alg_get_env_param() - get specific ctx number.
* @config: Pointer of wd_env_config which is used to store environment
* variable information.
- * @ctx_attr: ctx attributes.
+ * @attr: ctx attributes.
* @num: save ctx number.
* @is_enable: save enable inner poll flag.
*/
int wd_alg_get_env_param(struct wd_env_config *env_config,
- struct wd_ctx_attr ctx_attr,
+ struct wd_ctx_attr attr,
__u32 *num, __u8 *is_enable);
/*
diff --git a/v1/drv/hisi_hpre_udrv.h b/v1/drv/hisi_hpre_udrv.h
index d84c4c7..632ad28 100644
--- a/v1/drv/hisi_hpre_udrv.h
+++ b/v1/drv/hisi_hpre_udrv.h
@@ -83,6 +83,6 @@ int qm_fill_rsa_sqe(void *message, struct qm_queue_info *info, __u16 i);
int qm_parse_rsa_sqe(void *msg, const struct qm_queue_info *info,
__u16 i, __u16 usr);
int qm_fill_ecc_sqe(void *message, struct qm_queue_info *info, __u16 i);
-int qm_parse_ecc_sqe(void *msg, const struct qm_queue_info *info,
+int qm_parse_ecc_sqe(void *message, const struct qm_queue_info *info,
__u16 i, __u16 usr);
#endif
diff --git a/v1/drv/hisi_qm_udrv.h b/v1/drv/hisi_qm_udrv.h
index 3707c7d..588da00 100644
--- a/v1/drv/hisi_qm_udrv.h
+++ b/v1/drv/hisi_qm_udrv.h
@@ -174,7 +174,7 @@ struct hisi_qm_inject_op {
int qm_init_queue(struct wd_queue *q);
void qm_uninit_queue(struct wd_queue *q);
-int qm_send(struct wd_queue *q, void **msg, __u32 num);
+int qm_send(struct wd_queue *q, void **req, __u32 num);
int qm_recv(struct wd_queue *q, void **resp, __u32 num);
int hisi_qm_inject_op_register(struct wd_queue *q, struct hisi_qm_inject_op *op);
int qm_get_hwsgl_info(struct wd_queue *q, struct hw_sgl_info *sgl_info);
diff --git a/v1/drv/hisi_zip_udrv.h b/v1/drv/hisi_zip_udrv.h
index 4246342..c93b01a 100644
--- a/v1/drv/hisi_zip_udrv.h
+++ b/v1/drv/hisi_zip_udrv.h
@@ -125,7 +125,7 @@ struct hisi_zip_sqe_v3 {
#define HZ_REQ_TYPE_MASK 0xff
int qm_fill_zip_sqe(void *smsg, struct qm_queue_info *info, __u16 i);
-int qm_parse_zip_sqe(void *msg, const struct qm_queue_info *info,
+int qm_parse_zip_sqe(void *hw_msg, const struct qm_queue_info *info,
__u16 i, __u16 usr);
int qm_fill_zip_sqe_v3(void *smsg, struct qm_queue_info *info, __u16 i);
int qm_parse_zip_sqe_v3(void *msg, const struct qm_queue_info *info,
diff --git a/v1/wd_aead.h b/v1/wd_aead.h
index 4cc1081..ae5697b 100644
--- a/v1/wd_aead.h
+++ b/v1/wd_aead.h
@@ -142,7 +142,7 @@ void *wcrypto_create_aead_ctx(struct wd_queue *q,
* @key: cipher key addr
* @key_len: cipher key length
*/
-int wcrypto_set_aead_ckey(void *ctx, __u8 *ckey, __u16 key_len);
+int wcrypto_set_aead_ckey(void *ctx, __u8 *key, __u16 key_len);
/**
* wcrypto_set_aead_akey() - set authenticate key to aead context.
@@ -150,7 +150,7 @@ int wcrypto_set_aead_ckey(void *ctx, __u8 *ckey, __u16 key_len);
* @key: authenticate key addr
* @key_len: authenticate key length
*/
-int wcrypto_set_aead_akey(void *ctx, __u8 *akey, __u16 key_len);
+int wcrypto_set_aead_akey(void *ctx, __u8 *key, __u16 key_len);
/**
* wcrypto_aead_setauthsize() - set aead authsize to aead context.
@@ -184,13 +184,13 @@ int wcrypto_do_aead(void *ctx, struct wcrypto_aead_op_data *opdata,
/**
* wcrypto_burst_aead() - (a)synchronous multiple aead operations
- * @ctx: context of user, created by wcrypto_create_aead_ctx.
+ * @a_ctx: context of user, created by wcrypto_create_aead_ctx.
* @opdata: operational data
* @tag: asynchronous:user_tag; synchronous:NULL.
* @num: operations number per calling, maximum number is WCRYPTO_MAX_BURST_NUM.
*/
-int wcrypto_burst_aead(void *ctx, struct wcrypto_aead_op_data **opdata,
- void **tag, __u32 num);
+int wcrypto_burst_aead(void *a_ctx, struct wcrypto_aead_op_data **opdata,
+ void **tag, __u32 num);
/**
* wcrypto_aead_poll() - poll operation for asynchronous operation
diff --git a/v1/wd_cipher.h b/v1/wd_cipher.h
index 7059f53..591a590 100644
--- a/v1/wd_cipher.h
+++ b/v1/wd_cipher.h
@@ -151,11 +151,11 @@ void wcrypto_del_cipher_ctx(void *ctx);
/**
* wcrypto_burst_cipher() - (a)synchronous multiple cipher operations
* @ctx: context of user, created by wcrypto_create_cipher_ctx.
- * @opdata: operational data
+ * @c_opdata: operational data
* @tag: asynchronous:user_tag; synchronous:NULL.
* @num: operations number per calling, maximum number is WCRYPTO_MAX_BURST_NUM.
*/
-int wcrypto_burst_cipher(void *ctx, struct wcrypto_cipher_op_data **opdata,
+int wcrypto_burst_cipher(void *ctx, struct wcrypto_cipher_op_data **c_opdata,
void **tag, __u32 num);
#ifdef __cplusplus
diff --git a/v1/wd_digest.h b/v1/wd_digest.h
index b9b98fe..6ad4c85 100644
--- a/v1/wd_digest.h
+++ b/v1/wd_digest.h
@@ -152,12 +152,12 @@ void wcrypto_del_digest_ctx(void *ctx);
/**
* wcrypto_burst_digest() - (a)synchronous multiple digest operations
- * @ctx: context of user, created by wcrypto_create_digest_ctx.
+ * @d_ctx: context of user, created by wcrypto_create_digest_ctx.
* @opdata: operational data
* @tag: asynchronous:user_tag; synchronous:NULL.
* @num: operations number per calling, maximum number is WCRYPTO_MAX_BURST_NUM.
*/
-int wcrypto_burst_digest(void *ctx, struct wcrypto_digest_op_data **opdata,
+int wcrypto_burst_digest(void *d_ctx, struct wcrypto_digest_op_data **opdata,
void **tag, __u32 num);
#ifdef __cplusplus
--
2.27.0

View File

@ -0,0 +1,31 @@
From 91d11133e1f6d79e38da014123ddd0b0dc132be6 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sun, 24 Apr 2022 09:54:24 +0800
Subject: [PATCH 119/183] uadk: ecc: fix local variable referenced in macro
REGULAR_LEN is is calculated by multiplying the key length
by the constant parameter num, use CURVE_PARAM_NUM is better.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
v1/wd_ecc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c
index 2358243..e2837bd 100644
--- a/v1/wd_ecc.c
+++ b/v1/wd_ecc.c
@@ -1822,9 +1822,8 @@ static int sm2_compute_za_hash(__u8 *za, __u32 *len, struct wd_dtb *id,
id_bytes = id->dsize;
}
-#define REGULAR_LENS (6 * key_size) /* a b xG yG xA yA */
/* ZA = h(ENTL || ID || a || b || xG || yG || xA || yA) */
- lens = sizeof(__u16) + id_bytes + REGULAR_LENS;
+ lens = sizeof(__u16) + id_bytes + CURVE_PARAM_NUM * key_size;
p_in = malloc(lens);
if (unlikely(!p_in))
return -WD_ENOMEM;
--
2.27.0

View File

@ -0,0 +1,44 @@
From af330daeb1d215c312e0e4ff74cb4bc5f0f35cad Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sun, 24 Apr 2022 09:54:25 +0800
Subject: [PATCH 120/183] uadk: fix switch statement has no default branch
msg->op_type is non-enumeral type '__u8', so switch statement
on it should have a default branch.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
drv/hisi_hpre.c | 3 ++-
v1/drv/hisi_hpre_udrv.c | 2 ++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 33127e0..2a15900 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -1330,7 +1330,8 @@ static int ecc_prepare_out(struct wd_ecc_msg *msg, void **data)
case WD_SM2_KG:
*data = kout->pub.x.data;
break;
- /* fall-through */
+ default:
+ break;
}
return ret;
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c
index bd87cbe..3d8a00f 100644
--- a/v1/drv/hisi_hpre_udrv.c
+++ b/v1/drv/hisi_hpre_udrv.c
@@ -1466,6 +1466,8 @@ static int qm_ecc_prepare_out(struct wcrypto_ecc_msg *msg, void **data)
case WCRYPTO_SM2_KG:
ret = ecc_prepare_sm2_kg_out(out, data);
break;
+ default:
+ break;
}
return ret;
--
2.27.0

View File

@ -0,0 +1,112 @@
From 47eb2bf35cf8bce3f3e9b163fe6e1c5596ce1aa9 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sun, 24 Apr 2022 09:54:27 +0800
Subject: [PATCH 121/183] uadk: fix macro argument
macro argument 'drv' should be enclosed in parentheses.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
include/drv/wd_aead_drv.h | 2 +-
include/drv/wd_cipher_drv.h | 2 +-
include/drv/wd_comp_drv.h | 2 +-
include/drv/wd_dh_drv.h | 2 +-
include/drv/wd_digest_drv.h | 2 +-
include/drv/wd_ecc_drv.h | 2 +-
include/drv/wd_rsa_drv.h | 2 +-
7 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/include/drv/wd_aead_drv.h b/include/drv/wd_aead_drv.h
index 137e70a..6d883bf 100644
--- a/include/drv/wd_aead_drv.h
+++ b/include/drv/wd_aead_drv.h
@@ -86,7 +86,7 @@ struct wd_aead_driver *wd_aead_get_driver(void) \
#define WD_AEAD_SET_DRIVER(drv) \
static void __attribute__((constructor)) set_aead_driver(void) \
{ \
- wd_aead_set_driver(&drv); \
+ wd_aead_set_driver(&(drv)); \
}
#endif
diff --git a/include/drv/wd_cipher_drv.h b/include/drv/wd_cipher_drv.h
index 87b77d3..ecd421d 100644
--- a/include/drv/wd_cipher_drv.h
+++ b/include/drv/wd_cipher_drv.h
@@ -71,7 +71,7 @@ struct wd_cipher_driver *wd_cipher_get_driver(void) \
#define WD_CIPHER_SET_DRIVER(drv) \
static void __attribute__((constructor)) set_driver(void) \
{ \
- wd_cipher_set_driver(&drv); \
+ wd_cipher_set_driver(&(drv)); \
}
#endif
diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h
index 73403b5..a6c93d0 100644
--- a/include/drv/wd_comp_drv.h
+++ b/include/drv/wd_comp_drv.h
@@ -77,7 +77,7 @@ struct wd_comp_driver *wd_comp_get_driver(void) \
#define WD_COMP_SET_DRIVER(drv) \
static void __attribute__((constructor)) set_driver(void) \
{ \
- wd_comp_set_driver(&drv); \
+ wd_comp_set_driver(&(drv)); \
}
#endif
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
index 0d3fb2b..f0235c7 100644
--- a/include/drv/wd_dh_drv.h
+++ b/include/drv/wd_dh_drv.h
@@ -45,7 +45,7 @@ struct wd_dh_driver *wd_dh_get_driver(void) \
#define WD_DH_SET_DRIVER(drv) \
static void __attribute__((constructor)) set_driver_dh(void) \
{ \
- wd_dh_set_driver(&drv); \
+ wd_dh_set_driver(&(drv)); \
}
#endif
diff --git a/include/drv/wd_digest_drv.h b/include/drv/wd_digest_drv.h
index 6907bc5..2401728 100644
--- a/include/drv/wd_digest_drv.h
+++ b/include/drv/wd_digest_drv.h
@@ -74,7 +74,7 @@ struct wd_digest_driver *wd_digest_get_driver(void) \
#define WD_DIGEST_SET_DRIVER(drv) \
static void __attribute__((constructor)) set_drivers(void) \
{ \
- wd_digest_set_driver(&drv); \
+ wd_digest_set_driver(&(drv)); \
}
#endif
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index 66ed641..74dbcf8 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -198,7 +198,7 @@ struct wd_ecc_driver *wd_ecc_get_driver(void) \
#define WD_ECC_SET_DRIVER(drv) \
static void __attribute__((constructor)) set_driver_ecc(void) \
{ \
- wd_ecc_set_driver(&drv); \
+ wd_ecc_set_driver(&(drv)); \
}
#endif
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
index 837420e..bde6bbd 100644
--- a/include/drv/wd_rsa_drv.h
+++ b/include/drv/wd_rsa_drv.h
@@ -70,7 +70,7 @@ struct wd_rsa_driver *wd_rsa_get_driver(void) \
#define WD_RSA_SET_DRIVER(drv) \
static void __attribute__((constructor)) set_driver_rsa(void) \
{ \
- wd_rsa_set_driver(&drv); \
+ wd_rsa_set_driver(&(drv)); \
}
#endif
--
2.27.0

View File

@ -0,0 +1,29 @@
From 26406484d65db093e24dd230ad544ed027e6722f Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sun, 24 Apr 2022 09:54:28 +0800
Subject: [PATCH 122/183] uadk: fix ret uninit problem
If switch go out with default branch, it return
random value.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_rsa.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/wd_rsa.c b/wd_rsa.c
index ca39cff..b7f250e 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -1007,7 +1007,7 @@ static int rsa_prikey2_param_set(struct wd_rsa_prikey2 *pkey2,
struct wd_dtb *param,
enum wd_rsa_crt_prikey_para type)
{
- int ret;
+ int ret = -WD_EINVAL;
if (param->dsize > pkey2->key_size || !param->data)
return -WD_EINVAL;
--
2.27.0

View File

@ -0,0 +1,204 @@
From bd323b07e49644efdb1890ef53232ad32925dd2d Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sun, 24 Apr 2022 09:54:30 +0800
Subject: [PATCH 123/183] uadk: qm: optimize sgl copy function
1.Reduce the number of variables and optimize memcpy statements.
2.A single line contains more than 80 characters, fix it.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
drv/hisi_qm_udrv.c | 81 +++++++++++++++++++++---------------------
include/hisi_qm_udrv.h | 4 +--
2 files changed, 43 insertions(+), 42 deletions(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 53d5a55..3cb6ffb 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -262,15 +262,18 @@ static int his_qm_set_qp_ctx(handle_t h_ctx, struct hisi_qm_priv *config,
static int hisi_qm_get_qfrs_offs(handle_t h_ctx,
struct hisi_qm_queue_info *q_info)
{
- 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]) {
+ enum uacce_qfrt type;
+
+ type = UACCE_QFRT_DUS;
+ q_info->region_size[type] = wd_ctx_get_region_size(h_ctx, type);
+ if (!q_info->region_size[type]) {
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]) {
+
+ type = UACCE_QFRT_MMIO;
+ q_info->region_size[type] = wd_ctx_get_region_size(h_ctx, type);
+ if (!q_info->region_size[type]) {
WD_ERR("failed to get MMIO qfrs offset!\n");
return -WD_EINVAL;
}
@@ -629,7 +632,8 @@ handle_t hisi_qm_create_sglpool(__u32 sgl_num, __u32 sge_num)
if (!sgl_pool->sgl[i])
goto err_out;
- sgl_pool->sgl_align[i] = hisi_qm_align_sgl(sgl_pool->sgl[i], sge_num);
+ sgl_pool->sgl_align[i] = hisi_qm_align_sgl(sgl_pool->sgl[i],
+ sge_num);
}
sgl_pool->sgl_num = sgl_num;
@@ -808,35 +812,33 @@ handle_t hisi_qm_get_sglpool(handle_t h_qp)
return qp->h_sgl_pool;
}
-static void hisi_qm_sgl_copy_inner(void *dst_buff, struct hisi_sgl *hw_sgl,
+static void hisi_qm_sgl_copy_inner(void *pbuff, struct hisi_sgl *hw_sgl,
int begin_sge, __u32 sge_offset, __u32 size)
{
struct hisi_sgl *tmp = hw_sgl;
- __u32 offset = 0;
- __u32 len;
- int i;
+ int i = begin_sge + 1;
+ __u32 offset;
+ void *src;
- len = tmp->sge_entries[begin_sge].len - sge_offset;
+ src = (void *)tmp->sge_entries[begin_sge].buff + sge_offset;
+ offset = tmp->sge_entries[begin_sge].len - sge_offset;
/* the first one is enough for copy size, copy and return */
- if (len >= size) {
- memcpy(dst_buff,
- (void *)tmp->sge_entries[begin_sge].buff + sge_offset, size);
+ if (offset >= size) {
+ memcpy(pbuff, src, size);
return;
}
- memcpy(dst_buff, (void *)tmp->sge_entries[begin_sge].buff + sge_offset, len);
- offset += len;
-
- i = begin_sge + 1;
+ memcpy(pbuff, src, offset);
while (tmp) {
for (; i < tmp->entry_sum_in_sgl; i++) {
+ src = (void *)tmp->sge_entries[i].buff;
if (offset + tmp->sge_entries[i].len >= size) {
- memcpy(dst_buff + offset, (void *)tmp->sge_entries[i].buff, size - offset);
+ memcpy(pbuff + offset, src, size - offset);
return;
}
- memcpy(dst_buff + offset, (void *)tmp->sge_entries[i].buff, tmp->sge_entries[i].len);
+ memcpy(pbuff + offset, src, tmp->sge_entries[i].len);
offset += tmp->sge_entries[i].len;
}
@@ -845,32 +847,30 @@ static void hisi_qm_sgl_copy_inner(void *dst_buff, struct hisi_sgl *hw_sgl,
}
}
-static void hisi_qm_pbuff_copy_inner(const void *buff, struct hisi_sgl *hw_sgl,
- int begin_sge, __u32 sge_offset, __u32 size)
+static void hisi_qm_pbuff_copy_inner(void *pbuff, struct hisi_sgl *hw_sgl,
+ int begin_sge, __u32 sge_offset,
+ __u32 size)
{
struct hisi_sgl *tmp = hw_sgl;
+ int i = begin_sge + 1;
__u32 offset = 0;
- __u32 len;
- int i;
+ void *dst;
- len = tmp->sge_entries[begin_sge].len - sge_offset;
- if (len >= size) {
- memcpy((void *)tmp->sge_entries[begin_sge].buff + sge_offset,
- buff, size);
+ if (tmp->sge_entries[begin_sge].len - sge_offset >= size) {
+ dst = (void *)tmp->sge_entries[begin_sge].buff + sge_offset;
+ memcpy(dst, pbuff, size);
return;
}
- i = begin_sge + 1;
while (tmp) {
for (; i < tmp->entry_sum_in_sgl; i++) {
+ dst = (void *)tmp->sge_entries[i].buff;
if (offset + tmp->sge_entries[i].len >= size) {
- memcpy((void *)tmp->sge_entries[i].buff,
- buff + offset, size - offset);
+ memcpy(dst, pbuff + offset, size - offset);
return;
}
- memcpy((void *)tmp->sge_entries[i].buff,
- buff + offset, tmp->sge_entries[i].len);
+ memcpy(dst, pbuff + offset, tmp->sge_entries[i].len);
offset += tmp->sge_entries[i].len;
}
@@ -879,16 +879,16 @@ static void hisi_qm_pbuff_copy_inner(const void *buff, struct hisi_sgl *hw_sgl,
}
}
-void hisi_qm_sgl_copy(void *dst_buff, void *hw_sgl, __u32 offset, __u32 size,
- __u8 direct)
+void hisi_qm_sgl_copy(void *pbuff, void *hw_sgl, __u32 offset, __u32 size,
+ __u8 direct)
{
struct hisi_sgl *tmp = hw_sgl;
- __u32 len = 0;
__u32 sge_offset = 0;
+ __u32 len = 0;
int begin_sge = 0;
int i;
- if (!dst_buff || !size || !tmp)
+ if (!pbuff || !size || !tmp)
return;
while (len + tmp->entry_size_in_sgl <= offset) {
@@ -916,9 +916,10 @@ void hisi_qm_sgl_copy(void *dst_buff, void *hw_sgl, __u32 offset, __u32 size,
}
if (direct == COPY_SGL_TO_PBUFF)
- hisi_qm_sgl_copy_inner(dst_buff, tmp, begin_sge, sge_offset, size);
+ hisi_qm_sgl_copy_inner(pbuff, tmp, begin_sge, sge_offset, size);
else
- hisi_qm_pbuff_copy_inner(dst_buff, tmp, begin_sge, sge_offset, size);
+ hisi_qm_pbuff_copy_inner(pbuff, tmp, begin_sge, sge_offset,
+ size);
}
void hisi_qm_dump_sgl(void *sgl)
diff --git a/include/hisi_qm_udrv.h b/include/hisi_qm_udrv.h
index 773f57b..2395fd7 100644
--- a/include/hisi_qm_udrv.h
+++ b/include/hisi_qm_udrv.h
@@ -170,7 +170,7 @@ handle_t hisi_qm_get_sglpool(handle_t h_qp);
/**
* hisi_qm_sgl_copy: Buffer copying from hw sgl to pbuff or pbuff to sgl
- * @dst_buff: Dst pbuff point
+ * @pbuff: pbuff point
* @hw_sgl: Src hw sgl point
* @offset: Offset in hw sgl chain
* @size: Copy size
@@ -179,7 +179,7 @@ handle_t hisi_qm_get_sglpool(handle_t h_qp);
* If the len of sgl is not enough, will copy much as soon as
* possible before the offset to end of the sgl.
*/
-void hisi_qm_sgl_copy(void *dst_buff, void *hw_sgl, __u32 offset,
+void hisi_qm_sgl_copy(void *pbuff, void *hw_sgl, __u32 offset,
__u32 size, __u8 direct);
/**
--
2.27.0

View File

@ -0,0 +1,823 @@
From d1e97dbd394a2a4f1c00cd001f81a08340c33070 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sun, 24 Apr 2022 09:54:26 +0800
Subject: [PATCH 124/183] uadk: fix problems with referencing header files
1.includes are not sorted properly. Order-ref:
standard library headers, OS library headers,
and project-specific headers.
2.Header file is not self contained.
3.Include file is redundant, should be removed.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
drv/hisi_hpre.c | 1 -
include/drv/wd_aead_drv.h | 5 +++--
include/drv/wd_cipher_drv.h | 4 +++-
include/drv/wd_comp_drv.h | 3 +++
include/drv/wd_dh_drv.h | 2 ++
include/drv/wd_digest_drv.h | 5 +++--
include/drv/wd_ecc_drv.h | 5 ++++-
include/hisi_qm_udrv.h | 2 +-
include/uacce.h | 1 -
include/wd.h | 1 +
include/wd_aead.h | 4 ++--
include/wd_alg_common.h | 1 -
include/wd_comp.h | 2 --
include/wd_digest.h | 2 +-
include/wd_ecc.h | 2 --
include/wd_util.h | 1 +
v1/drv/hisi_hpre_udrv.c | 2 +-
v1/drv/hisi_qm_udrv.c | 4 ++--
v1/drv/hisi_rng_udrv.c | 2 +-
v1/drv/hisi_sec_udrv.c | 2 +-
v1/drv/hisi_zip_udrv.c | 2 +-
v1/wd.c | 4 +---
v1/wd.h | 1 -
v1/wd_adapter.c | 4 ++--
v1/wd_adapter.h | 4 ----
v1/wd_aead.c | 3 ---
v1/wd_bmm.c | 1 -
v1/wd_bmm.h | 3 +++
v1/wd_cipher.c | 5 +----
v1/wd_comp.c | 3 ---
v1/wd_dh.c | 3 ---
v1/wd_digest.c | 3 ---
v1/wd_ecc.c | 3 ---
v1/wd_rng.c | 5 +----
v1/wd_rsa.c | 5 +----
v1/wd_sgl.c | 1 -
v1/wd_sgl.h | 4 ++++
v1/wd_util.h | 3 +--
wd.c | 2 +-
wd_aead.c | 2 +-
wd_cipher.c | 2 +-
wd_comp.c | 2 +-
wd_dh.c | 2 +-
wd_digest.c | 2 +-
wd_ecc.c | 2 +-
wd_util.c | 2 +-
46 files changed, 52 insertions(+), 72 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 2a15900..bf0f440 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -10,7 +10,6 @@
#include <stdint.h>
#include <fcntl.h>
#include <sys/stat.h>
-#include <sys/ioctl.h>
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <sys/types.h>
diff --git a/include/drv/wd_aead_drv.h b/include/drv/wd_aead_drv.h
index 6d883bf..cc28ed5 100644
--- a/include/drv/wd_aead_drv.h
+++ b/include/drv/wd_aead_drv.h
@@ -4,8 +4,9 @@
#ifndef __WD_AEAD_DRV_H
#define __WD_AEAD_DRV_H
-#include "include/wd_alg_common.h"
-#include "include/wd_aead.h"
+#include "../wd_common.h"
+#include "../wd_alg_common.h"
+#include "../wd_aead.h"
#ifdef __cplusplus
extern "C" {
diff --git a/include/drv/wd_cipher_drv.h b/include/drv/wd_cipher_drv.h
index ecd421d..0ec758d 100644
--- a/include/drv/wd_cipher_drv.h
+++ b/include/drv/wd_cipher_drv.h
@@ -4,8 +4,10 @@
#ifndef __WD_CIPHER_DRV_H
#define __WD_CIPHER_DRV_H
-#include "../wd_cipher.h"
+#include <asm/types.h>
+#include "../wd_common.h"
#include "../wd_alg_common.h"
+#include "../wd_cipher.h"
#ifdef __cplusplus
extern "C" {
diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h
index a6c93d0..0913ed6 100644
--- a/include/drv/wd_comp_drv.h
+++ b/include/drv/wd_comp_drv.h
@@ -5,6 +5,9 @@
#define __WD_COMP_DRV_H
#include <pthread.h>
+#include <asm/types.h>
+#include "../wd_common.h"
+#include "../wd_alg_common.h"
#include "../wd_comp.h"
#ifdef __cplusplus
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
index f0235c7..192e7d8 100644
--- a/include/drv/wd_dh_drv.h
+++ b/include/drv/wd_dh_drv.h
@@ -4,6 +4,8 @@
#ifndef __WD_DH_DRV_H
#define __WD_DH_DRV_H
+#include <asm/types.h>
+#include "../wd_alg_common.h"
#include "../wd_dh.h"
#ifdef __cplusplus
diff --git a/include/drv/wd_digest_drv.h b/include/drv/wd_digest_drv.h
index 2401728..b426ab2 100644
--- a/include/drv/wd_digest_drv.h
+++ b/include/drv/wd_digest_drv.h
@@ -3,8 +3,9 @@
#ifndef __WD_DIGEST_DRV_H
#define __WD_DIGEST_DRV_H
-#include "include/wd_digest.h"
-#include "include/wd_alg_common.h"
+#include "../wd_common.h"
+#include "../wd_alg_common.h"
+#include "../wd_digest.h"
#ifdef __cplusplus
extern "C" {
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index 74dbcf8..ca21759 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -4,8 +4,11 @@
#ifndef __WD_ECC_DRV_H
#define __WD_ECC_DRV_H
+#include <stdint.h>
+#include <asm/types.h>
+
+#include "../wd.h"
#include "../wd_ecc.h"
-#include "../wd_alg_common.h"
#ifdef __cplusplus
extern "C" {
diff --git a/include/hisi_qm_udrv.h b/include/hisi_qm_udrv.h
index 2395fd7..ea5807e 100644
--- a/include/hisi_qm_udrv.h
+++ b/include/hisi_qm_udrv.h
@@ -4,9 +4,9 @@
#ifndef __HZIP_DRV_H__
#define __HZIP_DRV_H__
-#include <linux/types.h>
#include <stdbool.h>
#include <pthread.h>
+#include <linux/types.h>
#include "config.h"
#include "wd.h"
diff --git a/include/uacce.h b/include/uacce.h
index 07e36fe..fb3fb22 100644
--- a/include/uacce.h
+++ b/include/uacce.h
@@ -7,7 +7,6 @@
#ifndef _UAPIUUACCE_H
#define _UAPIUUACCE_H
-#include <linux/types.h>
#include <linux/ioctl.h>
#ifdef __cplusplus
diff --git a/include/wd.h b/include/wd.h
index 273cbb8..56c4109 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -12,6 +12,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <asm/types.h>
#include "uacce.h"
#ifdef __cplusplus
diff --git a/include/wd_aead.h b/include/wd_aead.h
index 3840062..3be8e8a 100644
--- a/include/wd_aead.h
+++ b/include/wd_aead.h
@@ -8,11 +8,11 @@
#define __WD_AEAD_H
#include <dlfcn.h>
-#include "wd_alg_common.h"
#include "config.h"
+#include "wd.h"
+#include "wd_alg_common.h"
#include "wd_cipher.h"
#include "wd_digest.h"
-#include "wd.h"
#ifdef __cplusplus
extern "C" {
diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h
index 30d244f..855f71d 100644
--- a/include/wd_alg_common.h
+++ b/include/wd_alg_common.h
@@ -7,7 +7,6 @@
#ifndef WD_ALG_COMMON_H
#define WD_ALG_COMMON_H
-#include <asm/types.h>
#include <pthread.h>
#include <stdbool.h>
#include "wd.h"
diff --git a/include/wd_comp.h b/include/wd_comp.h
index 5688b8b..e043a83 100644
--- a/include/wd_comp.h
+++ b/include/wd_comp.h
@@ -7,8 +7,6 @@
#ifndef __WD_COMP_H
#define __WD_COMP_H
-#include <stdbool.h>
-
#include "wd.h"
#include "wd_alg_common.h"
diff --git a/include/wd_digest.h b/include/wd_digest.h
index 92b9a4f..e1a33cd 100644
--- a/include/wd_digest.h
+++ b/include/wd_digest.h
@@ -8,8 +8,8 @@
#define __WD_DIGEST_H
#include <dlfcn.h>
-#include "wd_alg_common.h"
#include "wd.h"
+#include "wd_alg_common.h"
#ifdef __cplusplus
extern "C" {
diff --git a/include/wd_ecc.h b/include/wd_ecc.h
index 5aaec23..05a776d 100644
--- a/include/wd_ecc.h
+++ b/include/wd_ecc.h
@@ -7,10 +7,8 @@
#ifndef __WD_ECC_H
#define __WD_ECC_H
-#include <stdbool.h>
#include <stdlib.h>
#include <errno.h>
-#include <linux/types.h>
#include "wd.h"
#include "wd_alg_common.h"
diff --git a/include/wd_util.h b/include/wd_util.h
index 7fe3d72..1243428 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -8,6 +8,7 @@
#define __WD_UTIL_H
#include <stdbool.h>
+#include <asm/types.h>
#include "wd_alg_common.h"
#ifdef __cplusplus
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c
index 3d8a00f..76ba3e8 100644
--- a/v1/drv/hisi_hpre_udrv.c
+++ b/v1/drv/hisi_hpre_udrv.c
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#include "config.h"
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
@@ -28,6 +27,7 @@
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <sys/types.h>
+#include "config.h"
#include "v1/wd_util.h"
#include "hisi_hpre_udrv.h"
diff --git a/v1/drv/hisi_qm_udrv.c b/v1/drv/hisi_qm_udrv.c
index b457efd..54aa016 100644
--- a/v1/drv/hisi_qm_udrv.c
+++ b/v1/drv/hisi_qm_udrv.c
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#include "config.h"
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
@@ -29,10 +28,11 @@
#include <sys/eventfd.h>
#include <sys/types.h>
-#include "v1/drv/hisi_qm_udrv.h"
+#include "config.h"
#include "v1/drv/hisi_zip_udrv.h"
#include "v1/drv/hisi_hpre_udrv.h"
#include "v1/drv/hisi_sec_udrv.h"
+#include "v1/drv/hisi_qm_udrv.h"
#define HISI_SGL_SGE_NUM_MAX 255
#define HISI_SGL_ALIGN_SZ 64
diff --git a/v1/drv/hisi_rng_udrv.c b/v1/drv/hisi_rng_udrv.c
index d051a25..a66bca5 100644
--- a/v1/drv/hisi_rng_udrv.c
+++ b/v1/drv/hisi_rng_udrv.c
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#include "config.h"
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
@@ -30,6 +29,7 @@
#include <sys/types.h>
#include <unistd.h>
+#include "config.h"
#include "hisi_rng_udrv.h"
#define HISI_RNG_BYTES 4
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c
index 3e1e7d1..0e8bf57 100644
--- a/v1/drv/hisi_sec_udrv.c
+++ b/v1/drv/hisi_sec_udrv.c
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#include "config.h"
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
@@ -29,6 +28,7 @@
#include <sys/eventfd.h>
#include <sys/types.h>
+#include "config.h"
#include "hisi_sec_udrv.h"
#define DES_KEY_SIZE 8
diff --git a/v1/drv/hisi_zip_udrv.c b/v1/drv/hisi_zip_udrv.c
index f59c08f..1dec4d6 100644
--- a/v1/drv/hisi_zip_udrv.c
+++ b/v1/drv/hisi_zip_udrv.c
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#include "config.h"
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
@@ -28,6 +27,7 @@
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <sys/types.h>
+#include "config.h"
#include "v1/wd_util.h"
#include "v1/wd_comp.h"
#include "v1/wd_cipher.h"
diff --git a/v1/wd.c b/v1/wd.c
index b94ec43..8e3a91c 100644
--- a/v1/wd.c
+++ b/v1/wd.c
@@ -18,20 +18,18 @@
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
-#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <sys/mman.h>
#include <string.h>
-#include <assert.h>
#include <dirent.h>
#include <sys/poll.h>
#include <limits.h>
-#include "v1/wd.h"
#include "v1/wd_util.h"
#include "v1/wd_adapter.h"
+#include "v1/wd.h"
#define SYS_CLASS_DIR "/sys/class"
#define LINUX_DEV_DIR "/dev"
diff --git a/v1/wd.h b/v1/wd.h
index 429c6b6..1bd9669 100644
--- a/v1/wd.h
+++ b/v1/wd.h
@@ -24,7 +24,6 @@
#include <sys/types.h>
#include <stdbool.h>
#include <sys/stat.h>
-#include <sys/queue.h>
#include <fcntl.h>
#include <stdint.h>
#include <unistd.h>
diff --git a/v1/wd_adapter.c b/v1/wd_adapter.c
index e53c561..53bf41e 100644
--- a/v1/wd_adapter.c
+++ b/v1/wd_adapter.c
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-#include "config.h"
#include <stdio.h>
#include <string.h>
#include <dirent.h>
+#include "config.h"
#include "v1/wd_util.h"
-#include "v1/wd_adapter.h"
#include "v1/drv/dummy_drv.h"
#include "v1/drv/hisi_qm_udrv.h"
#include "v1/drv/hisi_rng_udrv.h"
+#include "v1/wd_adapter.h"
#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
diff --git a/v1/wd_adapter.h b/v1/wd_adapter.h
index a5edd24..bcceff2 100644
--- a/v1/wd_adapter.h
+++ b/v1/wd_adapter.h
@@ -21,11 +21,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <stdint.h>
#include <unistd.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
#include <sys/mman.h>
#include "wd.h"
diff --git a/v1/wd_aead.c b/v1/wd_aead.c
index cf358bf..d66f6e0 100644
--- a/v1/wd_aead.c
+++ b/v1/wd_aead.c
@@ -17,12 +17,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
#include <sys/mman.h>
#include "wd.h"
diff --git a/v1/wd_bmm.c b/v1/wd_bmm.c
index 11f2ee8..8f41997 100644
--- a/v1/wd_bmm.c
+++ b/v1/wd_bmm.c
@@ -20,7 +20,6 @@
#include <stdint.h>
#include <unistd.h>
#include <stdlib.h>
-#include <assert.h>
#include <errno.h>
#include <sys/queue.h>
diff --git a/v1/wd_bmm.h b/v1/wd_bmm.h
index 22ba702..88a8f9d 100644
--- a/v1/wd_bmm.h
+++ b/v1/wd_bmm.h
@@ -17,6 +17,9 @@
#ifndef _WD_BMM_H
#define _WD_BMM_H
+#include <asm/types.h>
+#include "wd.h"
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c
index 8eb6a6f..355d9aa 100644
--- a/v1/wd_cipher.c
+++ b/v1/wd_cipher.c
@@ -17,17 +17,14 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
#include <sys/mman.h>
#include "v1/wd.h"
-#include "v1/wd_cipher.h"
#include "v1/wd_util.h"
+#include "v1/wd_cipher.h"
#define MAX_CIPHER_KEY_SIZE 64
#define MAX_CIPHER_RETRY_CNT 20000000
diff --git a/v1/wd_comp.c b/v1/wd_comp.c
index 4ce79bd..7debef7 100644
--- a/v1/wd_comp.c
+++ b/v1/wd_comp.c
@@ -17,11 +17,8 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
#include <sys/mman.h>
#include "wd.h"
#include "wd_util.h"
diff --git a/v1/wd_dh.c b/v1/wd_dh.c
index 66f1081..d11d5cd 100644
--- a/v1/wd_dh.c
+++ b/v1/wd_dh.c
@@ -17,12 +17,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
#include <sys/mman.h>
#include "wd.h"
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
index 5acb660..71e5747 100644
--- a/v1/wd_digest.c
+++ b/v1/wd_digest.c
@@ -17,12 +17,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
#include <sys/mman.h>
#include "wd.h"
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c
index e2837bd..dfa5192 100644
--- a/v1/wd_ecc.c
+++ b/v1/wd_ecc.c
@@ -17,12 +17,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
#include <sys/mman.h>
#include "wd.h"
diff --git a/v1/wd_rng.c b/v1/wd_rng.c
index 4f6c114..d9d420e 100644
--- a/v1/wd_rng.c
+++ b/v1/wd_rng.c
@@ -17,17 +17,14 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
#include <sys/mman.h>
#include "wd.h"
-#include "wd_rng.h"
#include "wd_util.h"
+#include "wd_rng.h"
#define MAX_NUM 10
#define RNG_RESEND_CNT 8
diff --git a/v1/wd_rsa.c b/v1/wd_rsa.c
index 11635df..4de249f 100644
--- a/v1/wd_rsa.c
+++ b/v1/wd_rsa.c
@@ -17,17 +17,14 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
#include <sys/mman.h>
#include "wd.h"
-#include "wd_rsa.h"
#include "wd_util.h"
+#include "wd_rsa.h"
#define RSA_BALANCE_THRHD 1280
#define RSA_RESEND_CNT 8
diff --git a/v1/wd_sgl.c b/v1/wd_sgl.c
index 9995d69..9bdbe92 100644
--- a/v1/wd_sgl.c
+++ b/v1/wd_sgl.c
@@ -19,7 +19,6 @@
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
-#include <sys/queue.h>
#include "wd.h"
#include "wd_adapter.h"
diff --git a/v1/wd_sgl.h b/v1/wd_sgl.h
index c923677..e2e82f2 100644
--- a/v1/wd_sgl.h
+++ b/v1/wd_sgl.h
@@ -17,6 +17,10 @@
#ifndef _WD_SGL_H
#define _WD_SGL_H
+#include <stddef.h>
+#include <asm/types.h>
+#include "wd.h"
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/v1/wd_util.h b/v1/wd_util.h
index 78b91ee..d1642f8 100644
--- a/v1/wd_util.h
+++ b/v1/wd_util.h
@@ -24,13 +24,13 @@
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
-#include <linux/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <sys/queue.h>
+#include <linux/types.h>
#include "v1/wd.h"
#include "v1/wd_ecc.h"
@@ -88,7 +88,6 @@
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-#define offsetof(t, m) ((size_t)(uintptr_t)&((t *)0)->m)
struct wd_lock {
__u8 lock;
diff --git a/wd.c b/wd.c
index 0774837..3ce9c1e 100644
--- a/wd.c
+++ b/wd.c
@@ -17,8 +17,8 @@
#include <numa.h>
#include <sched.h>
-#include "wd.h"
#include "wd_alg_common.h"
+#include "wd.h"
#define SYS_CLASS_DIR "/sys/class/uacce"
diff --git a/wd_aead.c b/wd_aead.c
index 2e006c3..36ca842 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -6,9 +6,9 @@
#include <stdlib.h>
#include <pthread.h>
-#include "wd_aead.h"
#include "wd_util.h"
#include "include/drv/wd_aead_drv.h"
+#include "wd_aead.h"
#define XTS_MODE_KEY_DIVISOR 2
#define SM4_KEY_SIZE 16
diff --git a/wd_cipher.c b/wd_cipher.c
index 6cf1377..43e83b7 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -7,9 +7,9 @@
#include <stdlib.h>
#include <pthread.h>
#include <sched.h>
-#include "wd_cipher.h"
#include "wd_util.h"
#include "include/drv/wd_cipher_drv.h"
+#include "wd_cipher.h"
#define XTS_MODE_KEY_DIVISOR 2
#define SM4_KEY_SIZE 16
diff --git a/wd_comp.c b/wd_comp.c
index 3bd7f43..cc8f192 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -14,8 +14,8 @@
#include "config.h"
#include "drv/wd_comp_drv.h"
-#include "wd_comp.h"
#include "wd_util.h"
+#include "wd_comp.h"
#define WD_POOL_MAX_ENTRIES 1024
#define MAX_RETRY_COUNTS 200000000
diff --git a/wd_dh.c b/wd_dh.c
index aaea812..c16701d 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -14,8 +14,8 @@
#include "config.h"
#include "include/drv/wd_dh_drv.h"
-#include "wd_dh.h"
#include "wd_util.h"
+#include "wd_dh.h"
#define WD_POOL_MAX_ENTRIES 1024
#define DH_BALANCE_THRHD 1280
diff --git a/wd_digest.c b/wd_digest.c
index 7afbd9c..d5602ef 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -6,9 +6,9 @@
#include <stdlib.h>
#include <pthread.h>
-#include "wd_digest.h"
#include "wd_util.h"
#include "include/drv/wd_digest_drv.h"
+#include "wd_digest.h"
#define XTS_MODE_KEY_DIVISOR 2
#define SM4_KEY_SIZE 16
diff --git a/wd_ecc.c b/wd_ecc.c
index 671b62d..9005103 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -12,10 +12,10 @@
#include <time.h>
#include <dlfcn.h>
-#include "wd_ecc.h"
#include "wd_util.h"
#include "include/drv/wd_ecc_drv.h"
#include "include/wd_ecc_curve.h"
+#include "wd_ecc.h"
#define WD_POOL_MAX_ENTRIES 1024
#define WD_ECC_CTX_MSG_NUM 64
diff --git a/wd_util.c b/wd_util.c
index 57dafa7..43cedc6 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -12,8 +12,8 @@
#include <ctype.h>
#include <math.h>
#include "wd_alg_common.h"
-#include "wd_util.h"
#include "wd_sched.h"
+#include "wd_util.h"
#define WD_ASYNC_DEF_POLL_NUM 1
#define WD_ASYNC_DEF_QUEUE_DEPTH 1024
--
2.27.0

View File

@ -0,0 +1,761 @@
From 280e01c8a0aae071d54200f9a5fdcdc5035c3a9c Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sun, 24 Apr 2022 09:54:29 +0800
Subject: [PATCH 125/183] uadk: fix parameter used as working variable
input parameter of function should not be used as
working variable, fix it.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
drv/hisi_hpre.c | 3 ++-
drv/hisi_sec.c | 3 ++-
v1/drv/hisi_hpre_udrv.c | 13 ++++++----
v1/drv/hisi_sec_udrv.c | 3 ++-
v1/wd.c | 13 +++++-----
v1/wd_adapter.c | 15 ++++++------
v1/wd_aead.c | 3 ++-
v1/wd_cipher.c | 3 ++-
v1/wd_comp.c | 3 ++-
v1/wd_dh.c | 3 ++-
v1/wd_digest.c | 3 ++-
v1/wd_ecc.c | 6 +++--
v1/wd_rng.c | 3 ++-
v1/wd_rsa.c | 3 ++-
v1/wd_sgl.c | 54 ++++++++++++++++++++++++-----------------
wd_aead.c | 3 ++-
wd_cipher.c | 3 ++-
wd_comp.c | 9 ++++---
wd_dh.c | 3 ++-
wd_digest.c | 3 ++-
wd_ecc.c | 6 +++--
wd_mempool.c | 18 ++++++++------
wd_util.c | 3 ++-
23 files changed, 110 insertions(+), 69 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index bf0f440..4e62c0f 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -1965,11 +1965,12 @@ static void msg_pack(char *dst, __u64 *out_len,
}
static int sm2_kdf(struct wd_dtb *out, struct wd_ecc_point *x2y2,
- __u64 m_len, struct wd_hash_mt *hash)
+ __u64 mt_len, struct wd_hash_mt *hash)
{
char p_out[MAX_HASH_LENS] = {0};
__u32 h_bytes, x2y2_len;
char *tmp = out->data;
+ __u64 m_len = mt_len;
__u64 in_len, lens;
char *p_in, *t_out;
__u8 ctr[4];
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 88eacc3..b17ce0f 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -487,9 +487,10 @@ int hisi_sec_init(struct wd_ctx_config_internal *config, void *priv);
void hisi_sec_exit(void *priv);
/* increment counter (128-bit int) by software */
-static void ctr_iv_inc(__u8 *counter, __u32 c)
+static void ctr_iv_inc(__u8 *counter, __u32 len)
{
__u32 n = CTR_128BIT_COUNTER;
+ __u32 c = len;
do {
--n;
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c
index 76ba3e8..805160e 100644
--- a/v1/drv/hisi_hpre_udrv.c
+++ b/v1/drv/hisi_hpre_udrv.c
@@ -1873,13 +1873,14 @@ static int split_req(struct qm_queue_info *info,
return 0;
}
-static int fill_sm2_enc_sqe(void *message, struct qm_queue_info *info, __u16 i)
+static int fill_sm2_enc_sqe(void *msg, struct qm_queue_info *info, __u16 idx)
{
struct wcrypto_hash_mt *hash = &((struct q_info *)info->q->qinfo)->hash;
- struct wcrypto_ecc_msg *req_src = message;
+ struct wcrypto_ecc_msg *req_src = msg;
struct wcrypto_sm2_enc_in *ein = (void *)req_src->in;
struct wcrypto_ecc_msg *req_dst[2] = {NULL};
struct wd_dtb *plaintext = &ein->plaintext;
+ __u16 i = idx;
int ret;
if (plaintext->dsize <= HW_PLAINTEXT_BYTES_MAX &&
@@ -2053,11 +2054,12 @@ static int qm_parse_ecc_sqe_general(void *msg, const struct qm_queue_info *info,
return 1;
}
-static int parse_first_sqe(void *hw_msg, struct qm_queue_info *info, __u16 i,
+static int parse_first_sqe(void *hw_msg, struct qm_queue_info *info, __u16 idx,
__u16 usr)
{
- struct wcrypto_ecc_msg *msg = info->req_cache[i];
+ struct wcrypto_ecc_msg *msg = info->req_cache[idx];
struct wcrypto_ecc_msg *msg_src;
+ __u16 i = idx;
int ret;
ret = qm_parse_ecc_sqe_general(hw_msg, info, i, usr);
@@ -2177,10 +2179,11 @@ static void msg_pack(char *dst, __u64 *out_len,
}
static int sm2_kdf(struct wd_dtb *out, struct wcrypto_ecc_point *x2y2,
- __u64 m_len, struct q_info *q_info)
+ __u64 hash_mt_len, struct q_info *q_info)
{
struct wcrypto_hash_mt *hash = &q_info->hash;
char p_out[MAX_HASH_LENS] = {0};
+ __u64 m_len = hash_mt_len;
__u32 h_bytes, x2y2_len;
char *tmp = out->data;
__u64 in_len, lens;
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c
index 0e8bf57..4d5ede5 100644
--- a/v1/drv/hisi_sec_udrv.c
+++ b/v1/drv/hisi_sec_udrv.c
@@ -206,10 +206,11 @@ static void fill_bd3_addr_type(__u8 data_fmt, struct hisi_sec_bd3_sqe *sqe3)
}
/* increment counter (128-bit int) by c */
-static void ctr_iv_inc(__u8 *counter, __u32 c, __u8 data_fmt)
+static void ctr_iv_inc(__u8 *counter, __u32 shift_len, __u8 data_fmt)
{
__u32 n = CTR_128BIT_COUNTER;
__u8 *counter1 = counter;
+ __u32 c = shift_len;
if (data_fmt == WD_SGL_BUF) {
counter1 = wd_get_first_sge_buf((struct wd_sgl *)counter);
diff --git a/v1/wd.c b/v1/wd.c
index 8e3a91c..8ef83c6 100644
--- a/v1/wd.c
+++ b/v1/wd.c
@@ -845,19 +845,20 @@ void *wd_dma_to_va(struct wd_queue *q, void *dma)
void *wd_drv_mmap_qfr(struct wd_queue *q, enum uacce_qfrt qfrt, size_t size)
{
struct q_info *qinfo = q->qinfo;
+ size_t tmp = size;
off_t off;
off = qfrt * getpagesize();
if (qfrt != WD_UACCE_QFRT_SS)
- size = qinfo->qfrs_offset[qfrt];
+ tmp = qinfo->qfrs_offset[qfrt];
- return mmap(0, size, PROT_READ | PROT_WRITE,
+ return mmap(0, tmp, PROT_READ | PROT_WRITE,
MAP_SHARED, qinfo->fd, off);
}
void wd_drv_unmmap_qfr(struct wd_queue *q, void *addr,
- enum uacce_qfrt qfrt, size_t size)
+ enum uacce_qfrt qfrt, size_t size)
{
struct q_info *qinfo = q->qinfo;
@@ -865,9 +866,9 @@ void wd_drv_unmmap_qfr(struct wd_queue *q, void *addr,
return;
if (qfrt != WD_UACCE_QFRT_SS)
- size = qinfo->qfrs_offset[qfrt];
-
- munmap(addr, size);
+ munmap(addr, qinfo->qfrs_offset[qfrt]);
+ else
+ munmap(addr, size);
}
int wd_register_log(wd_log log)
{
diff --git a/v1/wd_adapter.c b/v1/wd_adapter.c
index 53bf41e..0b7b084 100644
--- a/v1/wd_adapter.c
+++ b/v1/wd_adapter.c
@@ -198,15 +198,16 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size)
struct wd_ss_region *rgn = NULL;
struct q_info *qinfo = q->qinfo;
unsigned long info = 0;
+ size_t tmp = size;
unsigned long i = 0;
void *ptr = NULL;
int ret = 1;
/* Make sure memory map granularity size align */
if (!qinfo->iommu_type)
- size = ALIGN(size, WD_UACCE_GRAN_SIZE);
+ tmp = ALIGN(tmp, WD_UACCE_GRAN_SIZE);
- ptr = wd_drv_mmap_qfr(q, WD_UACCE_QFRT_SS, size);
+ ptr = wd_drv_mmap_qfr(q, WD_UACCE_QFRT_SS, tmp);
if (ptr == MAP_FAILED) {
int value = errno;
@@ -215,8 +216,8 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size)
}
qinfo->ss_va = ptr;
- qinfo->ss_size = size;
- size = 0;
+ qinfo->ss_size = tmp;
+ tmp = 0;
while (ret > 0) {
info = (unsigned long)i;
ret = ioctl(qinfo->fd, WD_UACCE_CMD_GET_SS_DMA, &info);
@@ -238,8 +239,8 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size)
rgn->size = (info & WD_UACCE_GRAN_NUM_MASK) <<
WD_UACCE_GRAN_SHIFT;
rgn->pa = info & (~WD_UACCE_GRAN_NUM_MASK);
- rgn->va = ptr + size;
- size += rgn->size;
+ rgn->va = ptr + tmp;
+ tmp += rgn->size;
drv_add_slice(q, rgn);
i++;
}
@@ -248,7 +249,7 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size)
err_out:
drv_free_slice(q);
- drv_unmap_reserve_mem(q, ptr, size);
+ drv_unmap_reserve_mem(q, ptr, tmp);
return NULL;
}
diff --git a/v1/wd_aead.c b/v1/wd_aead.c
index d66f6e0..4ff690a 100644
--- a/v1/wd_aead.c
+++ b/v1/wd_aead.c
@@ -635,6 +635,7 @@ int wcrypto_aead_poll(struct wd_queue *q, unsigned int num)
struct wcrypto_aead_msg *aead_resp = NULL;
struct wcrypto_aead_ctx *ctx;
struct wcrypto_aead_tag *tag;
+ unsigned int tmp = num;
int count = 0;
int ret;
@@ -664,7 +665,7 @@ int wcrypto_aead_poll(struct wd_queue *q, unsigned int num)
ctx->setup.cb(aead_resp, tag->wcrypto_tag.tag);
aead_requests_uninit(&aead_resp, ctx, 1);
wd_put_cookies(&ctx->pool, (void **)&tag, 1);
- } while (--num);
+ } while (--tmp);
return count;
}
diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c
index 355d9aa..ad21a3a 100644
--- a/v1/wd_cipher.c
+++ b/v1/wd_cipher.c
@@ -504,6 +504,7 @@ int wcrypto_cipher_poll(struct wd_queue *q, unsigned int num)
struct wcrypto_cipher_msg *cipher_resp = NULL;
struct wcrypto_cipher_ctx *ctx;
struct wcrypto_cipher_tag *tag;
+ unsigned int tmp = num;
int count = 0;
int ret;
@@ -532,7 +533,7 @@ int wcrypto_cipher_poll(struct wd_queue *q, unsigned int num)
ctx = tag->wcrypto_tag.ctx;
ctx->setup.cb(cipher_resp, tag->wcrypto_tag.tag);
wd_put_cookies(&ctx->pool, (void **)&tag, 1);
- } while (--num);
+ } while (--tmp);
return count;
}
diff --git a/v1/wd_comp.c b/v1/wd_comp.c
index 7debef7..33546d4 100644
--- a/v1/wd_comp.c
+++ b/v1/wd_comp.c
@@ -280,6 +280,7 @@ int wcrypto_comp_poll(struct wd_queue *q, unsigned int num)
struct wcrypto_comp_msg *resp = NULL;
struct wcrypto_comp_ctx *ctx;
struct wcrypto_comp_tag *tag;
+ unsigned int tmp = num;
int count = 0;
int ret;
@@ -309,7 +310,7 @@ int wcrypto_comp_poll(struct wd_queue *q, unsigned int num)
ctx->cb(resp, tag->wcrypto_tag.tag);
wd_put_cookies(&ctx->pool, (void **)&tag, 1);
resp = NULL;
- } while (--num);
+ } while (--tmp);
return ret < 0 ? ret : count;
}
diff --git a/v1/wd_dh.c b/v1/wd_dh.c
index d11d5cd..49f52d9 100644
--- a/v1/wd_dh.c
+++ b/v1/wd_dh.c
@@ -371,6 +371,7 @@ int wcrypto_dh_poll(struct wd_queue *q, unsigned int num)
struct wcrypto_dh_msg *resp = NULL;
struct wcrypto_dh_ctx *ctx;
struct wcrypto_cb_tag *tag;
+ unsigned int tmp = num;
int count = 0;
int ret;
@@ -394,7 +395,7 @@ int wcrypto_dh_poll(struct wd_queue *q, unsigned int num)
ctx->setup.cb(resp, tag->tag);
wd_put_cookies(&ctx->pool, (void **)&tag, 1);
resp = NULL;
- } while (--num);
+ } while (--tmp);
return count;
}
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
index 71e5747..14df736 100644
--- a/v1/wd_digest.c
+++ b/v1/wd_digest.c
@@ -422,6 +422,7 @@ int wcrypto_digest_poll(struct wd_queue *q, unsigned int num)
struct wcrypto_digest_msg *digest_resp = NULL;
struct wcrypto_digest_ctx *ctx;
struct wcrypto_digest_tag *tag;
+ unsigned int tmp = num;
int count = 0;
int ret;
@@ -451,7 +452,7 @@ int wcrypto_digest_poll(struct wd_queue *q, unsigned int num)
ctx = tag->wcrypto_tag.ctx;
ctx->setup.cb(digest_resp, tag->wcrypto_tag.tag);
wd_put_cookies(&ctx->pool, (void **)&tag, 1);
- } while (--num);
+ } while (--tmp);
return count;
}
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c
index dfa5192..58dabfc 100644
--- a/v1/wd_ecc.c
+++ b/v1/wd_ecc.c
@@ -180,8 +180,9 @@ static int trans_to_binpad(char *dst, const char *src,
return WD_SUCCESS;
}
-static void wd_memset_zero(void *data, __u32 size)
+static void wd_memset_zero(void *data, __u32 mem_size)
{
+ __u32 size = mem_size;
char *s = data;
if (unlikely(!s))
@@ -1620,6 +1621,7 @@ static int ecc_poll(struct wd_queue *q, unsigned int num)
struct wcrypto_ecc_msg *resp = NULL;
struct wcrypto_ecc_ctx *ctx;
struct wcrypto_cb_tag *tag;
+ unsigned int tmp = num;
int count = 0;
int ret;
@@ -1638,7 +1640,7 @@ static int ecc_poll(struct wd_queue *q, unsigned int num)
ctx->setup.cb(resp, tag->tag);
wd_put_cookies(&ctx->pool, (void **)&tag, 1);
resp = NULL;
- } while (--num);
+ } while (--tmp);
return count;
}
diff --git a/v1/wd_rng.c b/v1/wd_rng.c
index d9d420e..7b3bda3 100644
--- a/v1/wd_rng.c
+++ b/v1/wd_rng.c
@@ -160,6 +160,7 @@ int wcrypto_rng_poll(struct wd_queue *q, unsigned int num)
struct wcrypto_rng_msg *resp = NULL;
struct wcrypto_rng_ctx *ctx;
struct wcrypto_cb_tag *tag;
+ unsigned int tmp = num;
int count = 0;
int ret;
@@ -184,7 +185,7 @@ int wcrypto_rng_poll(struct wd_queue *q, unsigned int num)
ctx->setup.cb(resp, tag->tag);
wd_put_cookies(&ctx->pool, (void **)&tag, 1);
resp = NULL;
- } while (--num);
+ } while (--tmp);
return count;
}
diff --git a/v1/wd_rsa.c b/v1/wd_rsa.c
index 4de249f..6ba29d7 100644
--- a/v1/wd_rsa.c
+++ b/v1/wd_rsa.c
@@ -1034,6 +1034,7 @@ int wcrypto_rsa_poll(struct wd_queue *q, unsigned int num)
struct wcrypto_rsa_msg *resp = NULL;
struct wcrypto_rsa_ctx *ctx;
struct wcrypto_cb_tag *tag;
+ unsigned int tmp = num;
int count = 0;
int ret;
@@ -1056,7 +1057,7 @@ int wcrypto_rsa_poll(struct wd_queue *q, unsigned int num)
ctx->setup.cb(resp, tag->tag);
wd_put_cookies(&ctx->pool, (void **)&tag, 1);
resp = NULL;
- } while (--num);
+ } while (--tmp);
return count;
}
diff --git a/v1/wd_sgl.c b/v1/wd_sgl.c
index 9bdbe92..dffbf12 100644
--- a/v1/wd_sgl.c
+++ b/v1/wd_sgl.c
@@ -512,32 +512,33 @@ struct wd_sgl *wd_alloc_sgl(void *pool, __u32 size)
void wd_free_sgl(void *pool, struct wd_sgl *sgl)
{
struct wd_sglpool *p = pool;
+ struct wd_sgl *tmp = sgl;
struct wd_sgl *next;
int i;
- if (unlikely(!p || !sgl || !p->sgl_pool)) {
+ if (unlikely(!p || !tmp || !p->sgl_pool)) {
WD_ERR("pool or sgl or p->sgl_pool is null!\n");
return;
}
- if (unlikely((uintptr_t)sgl->next & FLAG_MERGED_SGL)) {
+ if (unlikely((uintptr_t)tmp->next & FLAG_MERGED_SGL)) {
WD_ERR("This is a merged sgl, u cannot free it!\n");
return;
}
do {
- next = sgl->next;
- sgl->buf_sum = sgl->buf_num;
- sgl->next = NULL;
- sgl->sum_data_bytes = 0;
- for (i = 0; i < sgl->buf_num; i++)
- sgl->sge[i].data_len = 0;
+ next = tmp->next;
+ tmp->buf_sum = tmp->buf_num;
+ tmp->next = NULL;
+ tmp->sum_data_bytes = 0;
+ for (i = 0; i < tmp->buf_num; i++)
+ tmp->sge[i].data_len = 0;
/* have to update current 'wd_sgl' before free it */
- wd_free_blk(p->sgl_pool, sgl);
+ wd_free_blk(p->sgl_pool, tmp);
wd_get_free_blk_num(p->sgl_pool, &p->free_sgl_num);
next = (struct wd_sgl *)((uintptr_t)next & (~FLAG_MERGED_SGL));
- sgl = next;
+ tmp = next;
} while (next);
}
@@ -577,12 +578,16 @@ int wd_sgl_merge(struct wd_sgl *dst_sgl, struct wd_sgl *src_sgl)
return WD_SUCCESS;
}
-static void sgl_cp_to_pbuf(struct wd_sgl *sgl, int strtsg, int strtad,
- void *pbuf, size_t size)
+static void sgl_cp_to_pbuf(struct wd_sgl *src_sgl, int start_sg, int strtad,
+ void *buf, size_t sgl_sz)
{
- __u32 sz = sgl->pool->setup.buf_size;
- __u32 act_sz = MIN(size, sz - strtad);
+ __u32 sz = src_sgl->pool->setup.buf_size;
+ __u32 act_sz = MIN(sgl_sz, sz - strtad);
+ struct wd_sgl *sgl = src_sgl;
+ int strtsg = start_sg;
+ size_t size = sgl_sz;
struct wd_sgl *next;
+ void *pbuf = buf;
int i;
next = (struct wd_sgl *)((uintptr_t)sgl->next & (~FLAG_MERGED_SGL));
@@ -654,12 +659,16 @@ int wd_sgl_cp_to_pbuf(struct wd_sgl *sgl, size_t offset, void *pbuf, size_t size
return 0;
}
-static void sgl_cp_from_pbuf(struct wd_sgl *sgl, int strtsg, int strtad,
- void *pbuf, size_t size)
+static void sgl_cp_from_pbuf(struct wd_sgl *dst_sgl, int start_sg, int strtad,
+ void *buf, size_t mem_sz)
{
- __u32 sz = sgl->pool->setup.buf_size;
- __u32 act_sz = MIN(size, sz - strtad);
+ __u32 sz = dst_sgl->pool->setup.buf_size;
+ __u32 act_sz = MIN(mem_sz, sz - strtad);
+ struct wd_sgl *sgl = dst_sgl;
+ int strtsg = start_sg;
+ size_t size = mem_sz;
struct wd_sgl *next;
+ void *pbuf = buf;
int i;
next = (struct wd_sgl *)((uintptr_t)sgl->next & (~FLAG_MERGED_SGL));
@@ -766,18 +775,19 @@ void wd_sgl_iova_unmap(void *pool, void *sgl_iova, struct wd_sgl *sgl)
void *wd_get_last_sge_buf(struct wd_sgl *sgl)
{
+ struct wd_sgl *tmp = sgl;
uintptr_t next;
- if (unlikely(!sgl || !sgl->buf_num)) {
+ if (unlikely(!tmp || !tmp->buf_num)) {
WD_ERR("sgl or buf_num in sgl is null!\n");
return NULL;
}
- next = (uintptr_t)sgl->next & (~FLAG_MERGED_SGL);
+ next = (uintptr_t)tmp->next & (~FLAG_MERGED_SGL);
if (next)
- sgl = (struct wd_sgl *)next;
+ tmp = (struct wd_sgl *)next;
- return sgl->sge[sgl->buf_num - 1].buf;
+ return tmp->sge[tmp->buf_num - 1].buf;
}
void *wd_get_first_sge_buf(struct wd_sgl *sgl)
diff --git a/wd_aead.c b/wd_aead.c
index 36ca842..b3e7b41 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -639,6 +639,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
struct wd_aead_msg resp_msg, *msg;
struct wd_aead_req *req;
__u64 recv_count = 0;
+ __u32 tmp = expt;
int ret;
if (!count) {
@@ -678,7 +679,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
wd_put_msg_to_pool(&wd_aead_setting.pool,
idx, resp_msg.tag);
*count = recv_count;
- } while (--expt);
+ } while (--tmp);
return ret;
}
diff --git a/wd_cipher.c b/wd_cipher.c
index 43e83b7..b074dd2 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -548,6 +548,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
struct wd_cipher_msg resp_msg, *msg;
struct wd_cipher_req *req;
__u64 recv_count = 0;
+ __u32 tmp = expt;
int ret;
if (unlikely(!count)) {
@@ -588,7 +589,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
wd_put_msg_to_pool(&wd_cipher_setting.pool, idx,
resp_msg.tag);
*count = recv_count;
- } while (--expt);
+ } while (--tmp);
return ret;
}
diff --git a/wd_comp.c b/wd_comp.c
index cc8f192..502bc23 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -187,6 +187,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
struct wd_comp_msg *msg;
struct wd_comp_req *req;
__u64 recv_count = 0;
+ __u32 tmp = expt;
int ret;
if (unlikely(!count)) {
@@ -228,7 +229,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
/* free msg cache to msg_pool */
wd_put_msg_to_pool(&wd_comp_setting.pool, idx, resp_msg.tag);
*count = recv_count;
- } while (--expt);
+ } while (--tmp);
return ret;
}
@@ -545,14 +546,16 @@ int wd_do_comp_sync2(handle_t h_sess, struct wd_comp_req *req)
return 0;
}
-static unsigned int bit_reverse(register unsigned int x)
+static unsigned int bit_reverse(register unsigned int target)
{
+ register unsigned int x = target;
+
x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
- return((x >> 16) | (x << 16));
+ return ((x >> 16) | (x << 16));
}
/**
diff --git a/wd_dh.c b/wd_dh.c
index c16701d..2b02e3c 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -365,6 +365,7 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
struct wd_dh_req *req;
struct wd_dh_msg *msg;
__u32 rcv_cnt = 0;
+ __u32 tmp = expt;
int ret;
if (unlikely(!count)) {
@@ -405,7 +406,7 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
req->cb(req);
wd_put_msg_to_pool(&wd_dh_setting.pool, idx, rcv_msg.tag);
*count = rcv_cnt;
- } while (--expt);
+ } while (--tmp);
return ret;
}
diff --git a/wd_digest.c b/wd_digest.c
index d5602ef..1d4e4cc 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -444,6 +444,7 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
struct wd_digest_msg recv_msg, *msg;
struct wd_digest_req *req;
__u32 recv_cnt = 0;
+ __u32 tmp = expt;
int ret;
if (unlikely(!count)) {
@@ -486,7 +487,7 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
wd_put_msg_to_pool(&wd_digest_setting.pool, idx,
recv_msg.tag);
*count = recv_cnt;
- } while (--expt);
+ } while (--tmp);
return ret;
}
diff --git a/wd_ecc.c b/wd_ecc.c
index 9005103..c6bd111 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -301,10 +301,11 @@ static __u32 get_hash_bytes(__u8 type)
return val;
}
-static void init_dtb_param(void *dtb, char *start,
+static void init_dtb_param(void *dtb, char *str,
__u32 dsz, __u32 bsz, __u32 num)
{
struct wd_dtb *tmp = dtb;
+ char *start = str;
int i = 0;
while (i++ < num) {
@@ -2190,6 +2191,7 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
struct wd_ctx_internal *ctx;
struct wd_ecc_req *req;
__u32 rcv_cnt = 0;
+ __u32 tmp = expt;
int ret;
if (unlikely(!count)) {
@@ -2230,7 +2232,7 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
req->cb(req);
wd_put_msg_to_pool(&wd_ecc_setting.pool, idx, recv_msg.tag);
*count = rcv_cnt;
- } while (--expt);
+ } while (--tmp);
return ret;
}
diff --git a/wd_mempool.c b/wd_mempool.c
index 03df19a..d9259de 100644
--- a/wd_mempool.c
+++ b/wd_mempool.c
@@ -174,8 +174,9 @@ struct mempool {
*
* Undefined if no bit exists, so code should check against 0 first.
*/
-static __always_inline unsigned long wd_ffs(unsigned long word)
+static __always_inline unsigned long wd_ffs(unsigned long target_word)
{
+ unsigned long word = target_word;
int num = 0;
if ((word & 0xffffffff) == 0) {
@@ -234,9 +235,11 @@ static void destroy_bitmap(struct bitmap *bm)
}
static unsigned long _find_next_bit(unsigned long *map, unsigned long bits,
- unsigned long start, unsigned long invert)
+ unsigned long begin_position,
+ unsigned long invert)
{
unsigned long tmp, mask, next_bit;
+ unsigned long start = begin_position;
if (start >= bits)
return bits;
@@ -888,15 +891,16 @@ static void uninit_mempool(struct mempool *mp)
handle_t wd_mempool_create(size_t size, int node)
{
struct mempool *mp;
+ size_t tmp = size;
int ret;
- if (!size || node < 0 || node > numa_max_node()) {
- WD_ERR("invalid: numa node is %d, size is %ld!\n", node, size);
+ if (!tmp || node < 0 || node > numa_max_node()) {
+ WD_ERR("invalid: numa node is %d, size is %ld!\n", node, tmp);
return (handle_t)(-WD_EINVAL);
}
- if (WD_MEMPOOL_SIZE_MASK & size)
- size += WD_MEMPOOL_BLOCK_SIZE - (WD_MEMPOOL_SIZE_MASK & size);
+ if (WD_MEMPOOL_SIZE_MASK & tmp)
+ tmp += WD_MEMPOOL_BLOCK_SIZE - (WD_MEMPOOL_SIZE_MASK & tmp);
mp = calloc(1, sizeof(*mp));
if (!mp) {
@@ -905,7 +909,7 @@ handle_t wd_mempool_create(size_t size, int node)
}
mp->node = node;
- mp->size = size;
+ mp->size = tmp;
mp->blk_size = WD_MEMPOOL_BLOCK_SIZE;
ret = alloc_mem_from_hugepage(mp);
diff --git a/wd_util.c b/wd_util.c
index 43cedc6..8bda8d7 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -162,12 +162,13 @@ void wd_clear_ctx_config(struct wd_ctx_config_internal *in)
void wd_memset_zero(void *data, __u32 size)
{
+ __u32 tmp = size;
char *s = data;
if (!s)
return;
- while (size--)
+ while (tmp--)
*s++ = 0;
}
--
2.27.0

View File

@ -0,0 +1,305 @@
From 46321d786961ea5d5a63b12084ee2ed551067c3d Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Tue, 31 May 2022 17:01:01 +0800
Subject: [PATCH 127/183] uadk: move parameter check into wd_util.c
The code for wd alg init parameter checking is same,
so move it into wd_util.c from wd_<alg>.c.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
include/wd_util.h | 9 +++++++++
wd_aead.c | 17 +----------------
wd_cipher.c | 18 +-----------------
wd_comp.c | 12 +++---------
wd_dh.c | 20 +++-----------------
wd_digest.c | 17 +----------------
wd_ecc.c | 20 +++-----------------
wd_rsa.c | 20 +++-----------------
wd_util.c | 20 ++++++++++++++++++++
9 files changed, 44 insertions(+), 109 deletions(-)
diff --git a/include/wd_util.h b/include/wd_util.h
index 1243428..89dfe87 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -327,6 +327,15 @@ int wd_check_ctx(struct wd_ctx_config_internal *config, __u8 mode, __u32 idx);
*/
int wd_set_epoll_en(const char *var_name, bool *epoll_en);
+/**
+ * wd_init_check() - Check input parameters for wd_<alg>_init.
+ * @config: Ctx configuration input by user.
+ * @sched: Scheduler configuration input by user.
+ *
+ * Return 0 if successful or less than 0 otherwise.
+ */
+int wd_init_param_check(struct wd_ctx_config *config, struct wd_sched *sched);
+
#ifdef __cplusplus
}
#endif
diff --git a/wd_aead.c b/wd_aead.c
index b3e7b41..3f47f8b 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -388,27 +388,12 @@ static int aead_param_check(struct wd_aead_sess *sess,
return 0;
}
-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("invalid: wd aead 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");
- return -WD_EINVAL;
- }
-
- return 0;
-}
-
int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
{
void *priv;
int ret;
- ret = aead_init_check(config, sched);
+ ret = wd_init_param_check(config, sched);
if (ret)
return ret;
diff --git a/wd_cipher.c b/wd_cipher.c
index b074dd2..be8996f 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -151,22 +151,6 @@ static int cipher_key_len_check(struct wd_cipher_sess *sess, __u32 length)
return ret;
}
-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("invalid: wd cipher 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");
- return -WD_EINVAL;
- }
-
- return 0;
-}
-
int wd_cipher_set_key(handle_t h_sess, const __u8 *key, __u32 key_len)
{
struct wd_cipher_sess *sess = (struct wd_cipher_sess *)h_sess;
@@ -248,7 +232,7 @@ int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched)
void *priv;
int ret;
- ret = cipher_init_check(config, sched);
+ ret = wd_init_param_check(config, sched);
if (ret)
return ret;
diff --git a/wd_comp.c b/wd_comp.c
index 502bc23..f2d01b6 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -85,15 +85,9 @@ int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched)
void *priv;
int ret;
- if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) {
- WD_ERR("invalid: config or sched is NULL!\n");
- return -WD_EINVAL;
- }
-
- if (!wd_is_sva(config->ctxs[0].ctx)) {
- WD_ERR("failed to find sva device, please check system!\n");
- return -WD_EINVAL;
- }
+ ret = wd_init_param_check(config, sched);
+ if (ret)
+ return ret;
ret = wd_set_epoll_en("WD_COMP_EPOLL_EN",
&wd_comp_setting.config.epoll_en);
diff --git a/wd_dh.c b/wd_dh.c
index 2b02e3c..dfa9505 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -78,28 +78,14 @@ void wd_dh_set_driver(struct wd_dh_driver *drv)
wd_dh_setting.driver = drv;
}
-static int param_check(struct wd_ctx_config *config, struct wd_sched *sched)
-{
- if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) {
- WD_ERR("invalid: config or sched is NULL!\n");
- return -WD_EINVAL;
- }
-
- if (!wd_is_sva(config->ctxs[0].ctx)) {
- WD_ERR("invalid: the mode is non sva, please check system!\n");
- return -WD_EINVAL;
- }
-
- return 0;
-}
-
int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
{
void *priv;
int ret;
- if (param_check(config, sched))
- return -WD_EINVAL;
+ ret = wd_init_param_check(config, sched);
+ if (ret)
+ return ret;
ret = wd_set_epoll_en("WD_DH_EPOLL_EN",
&wd_dh_setting.config.epoll_en);
diff --git a/wd_digest.c b/wd_digest.c
index 1d4e4cc..46546cb 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -150,27 +150,12 @@ void wd_digest_free_sess(handle_t h_sess)
free(sess);
}
-static int digest_init_check(struct wd_ctx_config *config, struct wd_sched *sched)
-{
- if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) {
- WD_ERR("failed to check input param!\n");
- return -WD_EINVAL;
- }
-
- if (!wd_is_sva(config->ctxs[0].ctx)) {
- WD_ERR("err, non sva, please check system!\n");
- return -WD_EINVAL;
- }
-
- return 0;
-}
-
int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched)
{
void *priv;
int ret;
- ret = digest_init_check(config, sched);
+ ret = wd_init_param_check(config, sched);
if (ret)
return ret;
diff --git a/wd_ecc.c b/wd_ecc.c
index c6bd111..c463049 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -132,28 +132,14 @@ void wd_ecc_set_driver(struct wd_ecc_driver *drv)
wd_ecc_setting.driver = drv;
}
-static int init_param_check(struct wd_ctx_config *config, struct wd_sched *sched)
-{
- if (!config || !config->ctxs || !config->ctxs[0].ctx || !sched) {
- WD_ERR("invalid: config or sched is NULL!\n");
- return -WD_EINVAL;
- }
-
- if (!wd_is_sva(config->ctxs[0].ctx)) {
- WD_ERR("invalid: the mode is non sva, please check system!\n");
- return -WD_EINVAL;
- }
-
- return 0;
-}
-
int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
{
void *priv;
int ret;
- if (init_param_check(config, sched))
- return -WD_EINVAL;
+ ret = wd_init_param_check(config, sched);
+ if (ret)
+ return ret;
ret = wd_set_epoll_en("WD_ECC_EPOLL_EN",
&wd_ecc_setting.config.epoll_en);
diff --git a/wd_rsa.c b/wd_rsa.c
index b7f250e..836c8ae 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -118,28 +118,14 @@ void wd_rsa_set_driver(struct wd_rsa_driver *drv)
wd_rsa_setting.driver = drv;
}
-static int param_check(struct wd_ctx_config *config, struct wd_sched *sched)
-{
- if (!config || !config->ctxs[0].ctx || !sched) {
- WD_ERR("invalid: config or sched NULL!\n");
- return -WD_EINVAL;
- }
-
- if (!wd_is_sva(config->ctxs[0].ctx)) {
- WD_ERR("invalid: the mode is non sva, please check system!\n");
- return -WD_EINVAL;
- }
-
- return 0;
-}
-
int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
{
void *priv;
int ret;
- if (param_check(config, sched))
- return -WD_EINVAL;
+ ret = wd_init_param_check(config, sched);
+ if (ret)
+ return ret;
ret = wd_set_epoll_en("WD_RSA_EPOLL_EN",
&wd_rsa_setting.config.epoll_en);
diff --git a/wd_util.c b/wd_util.c
index 8bda8d7..4d5faf9 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -1628,3 +1628,23 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en)
return 0;
}
+
+int wd_init_param_check(struct wd_ctx_config *config, struct wd_sched *sched)
+{
+ if (!config || !config->ctxs || !config->ctxs[0].ctx) {
+ WD_ERR("invalid: config or config->ctxs is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ if (!sched) {
+ WD_ERR("invalid: sched is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ if (!wd_is_sva(config->ctxs[0].ctx)) {
+ WD_ERR("invalid: the mode is non sva, please check system!\n");
+ return -WD_EINVAL;
+ }
+
+ return 0;
+}
--
2.27.0

View File

@ -0,0 +1,121 @@
From aa9833fb3e1f28446e0dc93aa72887002cf70ca0 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Tue, 31 May 2022 17:01:02 +0800
Subject: [PATCH 128/183] comp: remove unused variable priv
Remove variable priv in function comp_send and comp_recv,
it is unused now.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
drv/hisi_comp.c | 5 ++---
include/drv/wd_comp_drv.h | 4 ++--
wd_comp.c | 12 ++++--------
3 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index e1d2f6e..2a2367b 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -865,7 +865,7 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
return 0;
}
-static int hisi_zip_comp_send(handle_t ctx, struct wd_comp_msg *msg, void *priv)
+static int hisi_zip_comp_send(handle_t ctx, struct wd_comp_msg *msg)
{
struct hisi_qp *qp = wd_ctx_get_priv(ctx);
handle_t h_qp = (handle_t)qp;
@@ -1020,8 +1020,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
return 0;
}
-static int hisi_zip_comp_recv(handle_t ctx, struct wd_comp_msg *recv_msg,
- void *priv)
+static int hisi_zip_comp_recv(handle_t ctx, struct wd_comp_msg *recv_msg)
{
struct hisi_qp *qp = wd_ctx_get_priv(ctx);
handle_t h_qp = (handle_t)qp;
diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h
index 0913ed6..e3d2269 100644
--- a/include/drv/wd_comp_drv.h
+++ b/include/drv/wd_comp_drv.h
@@ -61,8 +61,8 @@ struct wd_comp_driver {
__u32 drv_ctx_size;
int (*init)(struct wd_ctx_config_internal *config, void *priv);
void (*exit)(void *priv);
- int (*comp_send)(handle_t ctx, struct wd_comp_msg *msg, void *priv);
- int (*comp_recv)(handle_t ctx, struct wd_comp_msg *msg, void *priv);
+ int (*comp_send)(handle_t ctx, struct wd_comp_msg *msg);
+ int (*comp_recv)(handle_t ctx, struct wd_comp_msg *msg);
};
void wd_comp_set_driver(struct wd_comp_driver *drv);
diff --git a/wd_comp.c b/wd_comp.c
index f2d01b6..1ae0e78 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -175,7 +175,6 @@ struct wd_comp_msg *wd_comp_get_msg(__u32 idx, __u32 tag)
int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
{
struct wd_ctx_config_internal *config = &wd_comp_setting.config;
- void *priv = wd_comp_setting.priv;
struct wd_ctx_internal *ctx;
struct wd_comp_msg resp_msg;
struct wd_comp_msg *msg;
@@ -198,8 +197,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_comp_setting.driver->comp_recv(ctx->ctx, &resp_msg,
- priv);
+ ret = wd_comp_setting.driver->comp_recv(ctx->ctx, &resp_msg);
if (unlikely(ret < 0)) {
if (ret == -WD_HW_EACCESS)
WD_ERR("wd comp recv hw error!\n");
@@ -398,7 +396,6 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess,
{
struct wd_ctx_config_internal *config = &wd_comp_setting.config;
handle_t h_sched_ctx = wd_comp_setting.sched.h_sched_ctx;
- void *priv = wd_comp_setting.priv;
struct wd_ctx_internal *ctx;
__u64 recv_count = 0;
__u32 idx;
@@ -415,7 +412,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);
+ ret = wd_comp_setting.driver->comp_send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
pthread_spin_unlock(&ctx->lock);
WD_ERR("wd comp send error, ret = %d!\n", ret);
@@ -428,7 +425,7 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess,
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);
+ ret = wd_comp_setting.driver->comp_recv(ctx->ctx, msg);
if (unlikely(ret == -WD_HW_EACCESS)) {
pthread_spin_unlock(&ctx->lock);
WD_ERR("wd comp recv hw error!\n");
@@ -663,7 +660,6 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
struct wd_ctx_config_internal *config = &wd_comp_setting.config;
struct wd_comp_sess *sess = (struct wd_comp_sess *)h_sess;
handle_t h_sched_ctx = wd_comp_setting.sched.h_sched_ctx;
- void *priv = wd_comp_setting.priv;
struct wd_ctx_internal *ctx;
struct wd_comp_msg *msg;
int tag, ret;
@@ -698,7 +694,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);
+ ret = wd_comp_setting.driver->comp_send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
pthread_spin_unlock(&ctx->lock);
WD_ERR("wd comp send error, ret = %d!\n", ret);
--
2.27.0

View File

@ -0,0 +1,36 @@
From 60b860d2fc7029e2399bb2380f1650dd0eff7d51 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Tue, 31 May 2022 17:01:04 +0800
Subject: [PATCH 129/183] ecc: remove the lock in async send funciton
When sending message, a lock has been added in function 'hisi_qm_send'
to ensure atomicity, so there is no need to repeat lock in
function 'wd_do_ecc_async'.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
wd_ecc.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/wd_ecc.c b/wd_ecc.c
index c463049..7dd3853 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -2151,13 +2151,9 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req)
goto fail_with_msg;
msg->tag = mid;
- pthread_spin_lock(&ctx->lock);
ret = ecc_send(ctx->ctx, msg);
- if (ret) {
- pthread_spin_unlock(&ctx->lock);
+ if (ret)
goto fail_with_msg;
- }
- pthread_spin_unlock(&ctx->lock);
ret = wd_add_task_to_async_queue(&wd_ecc_env_config, idx);
if (ret)
--
2.27.0

View File

@ -0,0 +1,36 @@
From 6b02f3609923def84213d3a6e775fa45ddfae1b7 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Tue, 31 May 2022 17:01:03 +0800
Subject: [PATCH 130/183] dh: remove the lock in async send
When sending task, a lock has been added in function 'hisi_qm_send'
to ensure atomicity, so there is no need to repeat lock in
function 'wd_do_dh_async'.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
wd_dh.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/wd_dh.c b/wd_dh.c
index dfa9505..dd669f1 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -323,13 +323,9 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req)
goto fail_with_msg;
msg->tag = mid;
- pthread_spin_lock(&ctx->lock);
ret = dh_send(ctx->ctx, msg);
- if (ret) {
- pthread_spin_unlock(&ctx->lock);
+ if (ret)
goto fail_with_msg;
- }
- pthread_spin_unlock(&ctx->lock);
ret = wd_add_task_to_async_queue(&wd_dh_env_config, idx);
if (ret)
--
2.27.0

View File

@ -0,0 +1,39 @@
From a4022d3fea696df788b236a686979f84b4aa4e80 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Tue, 31 May 2022 17:01:05 +0800
Subject: [PATCH 131/183] comp: remove the lock in async send
When sending BD, a lock has been added in function 'hisi_qm_send'
to ensure atomicity, so there is no need to repeat lock in
function 'wd_do_comp_async'.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
wd_comp.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/wd_comp.c b/wd_comp.c
index 1ae0e78..6bf5f82 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -692,17 +692,12 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
msg->tag = tag;
msg->stream_mode = WD_COMP_STATELESS;
- pthread_spin_lock(&ctx->lock);
-
ret = wd_comp_setting.driver->comp_send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
- pthread_spin_unlock(&ctx->lock);
WD_ERR("wd comp send error, ret = %d!\n", ret);
goto fail_with_msg;
}
- pthread_spin_unlock(&ctx->lock);
-
ret = wd_add_task_to_async_queue(&wd_comp_env_config, idx);
if (unlikely(ret))
goto fail_with_msg;
--
2.27.0

View File

@ -0,0 +1,88 @@
From f33daa68150250815df2a359a54167c0b426c0af Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Tue, 31 May 2022 17:01:06 +0800
Subject: [PATCH 132/183] dh: remove repeated send BD
If -WD_EBUSY is returned When BD is sent, the app
determines whether to resend the BD. The function wd_do_dh_sync
and wd_do_dh_async does not try to resend the BD.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
wd_dh.c | 37 ++++++++++---------------------------
1 file changed, 10 insertions(+), 27 deletions(-)
diff --git a/wd_dh.c b/wd_dh.c
index dd669f1..5f9dff1 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -19,7 +19,6 @@
#define WD_POOL_MAX_ENTRIES 1024
#define DH_BALANCE_THRHD 1280
-#define DH_RESEND_CNT 8
#define DH_MAX_KEY_SIZE 512
#define DH_RECV_MAX_CNT 60000000 // 1 min
#define WD_DH_G2 2
@@ -192,28 +191,6 @@ static int fill_dh_msg(struct wd_dh_msg *msg, struct wd_dh_req *req,
return 0;
}
-static int dh_send(handle_t ctx, struct wd_dh_msg *msg)
-{
- __u32 tx_cnt = 0;
- int ret;
-
- do {
- ret = wd_dh_setting.driver->send(ctx, msg);
- if (ret == -WD_EBUSY) {
- if (tx_cnt++ >= DH_RESEND_CNT) {
- WD_ERR("failed to send: retry exit!\n");
- break;
- }
- usleep(1);
- } else if (ret < 0) {
- WD_ERR("failed to send: send error = %d!\n", ret);
- break;
- }
- } while (ret);
-
- return ret;
-}
-
static int dh_recv_sync(handle_t ctx, struct wd_dh_msg *msg)
{
struct wd_dh_req *req = &msg->req;
@@ -278,9 +255,11 @@ int wd_do_dh_sync(handle_t sess, struct wd_dh_req *req)
return ret;
pthread_spin_lock(&ctx->lock);
- ret = dh_send(ctx->ctx, &msg);
- if (unlikely(ret))
+ ret = wd_dh_setting.driver->send(ctx->ctx, &msg);
+ if (unlikely(ret < 0)) {
+ WD_ERR("failed to send dh BD, ret = %d!\n", ret);
goto fail;
+ }
ret = dh_recv_sync(ctx->ctx, &msg);
req->pri_bytes = msg.req.pri_bytes;
@@ -323,9 +302,13 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req)
goto fail_with_msg;
msg->tag = mid;
- ret = dh_send(ctx->ctx, msg);
- if (ret)
+ ret = wd_dh_setting.driver->send(ctx->ctx, msg);
+ if (unlikely(ret)) {
+ if (ret != -WD_EBUSY)
+ WD_ERR("failed to send dh BD, hw is err!\n");
+
goto fail_with_msg;
+ }
ret = wd_add_task_to_async_queue(&wd_dh_env_config, idx);
if (ret)
--
2.27.0

View File

@ -0,0 +1,87 @@
From 6cda439c798c470878d1f12beff0a30236b23da3 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Tue, 31 May 2022 17:01:07 +0800
Subject: [PATCH 133/183] ecc: remove repeated send BD
If -WD_EBUSY is returned When BD is sent, the app
determines whether to resend the BD. The function wd_do_ecc_sync
and wd_do_ecc_async does not try to resend the BD.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
wd_ecc.c | 36 ++++++++++--------------------------
1 file changed, 10 insertions(+), 26 deletions(-)
diff --git a/wd_ecc.c b/wd_ecc.c
index 7dd3853..f22b72d 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -22,7 +22,6 @@
#define WD_ECC_MAX_CTX 256
#define ECC_BALANCE_THRHD 1280
#define ECC_RECV_MAX_CNT 60000000
-#define ECC_RESEND_CNT 8
#define ECC_MAX_HW_BITS 521
#define ECC_MAX_KEY_SIZE BITS_TO_BYTES(ECC_MAX_HW_BITS)
#define ECC_MAX_IN_NUM 4
@@ -1387,27 +1386,6 @@ static void msg_pack(char *dst, __u64 *out_len,
*out_len += src_len;
}
-static int ecc_send(handle_t ctx, struct wd_ecc_msg *msg)
-{
- __u32 tx_cnt = 0;
- int ret;
-
- do {
- ret = wd_ecc_setting.driver->send(ctx, msg);
- if (ret == -WD_EBUSY) {
- if (tx_cnt++ >= ECC_RESEND_CNT) {
- WD_ERR("failed to send: retry exit!\n");
- break;
- }
- usleep(1);
- } else if (ret < 0) {
- WD_ERR("failed to send: send error = %d!\n", ret);
- break;
- }
- } while (ret);
-
- return ret;
-}
static int ecc_recv_sync(handle_t ctx, struct wd_ecc_msg *msg)
{
struct wd_ecc_req *req = &msg->req;
@@ -1473,9 +1451,11 @@ int wd_do_ecc_sync(handle_t h_sess, struct wd_ecc_req *req)
return ret;
pthread_spin_lock(&ctx->lock);
- ret = ecc_send(ctx->ctx, &msg);
- if (unlikely(ret))
+ ret = wd_ecc_setting.driver->send(ctx->ctx, &msg);
+ if (unlikely(ret < 0)) {
+ WD_ERR("failed to send ecc BD, hw is err!\n");
goto fail;
+ }
ret = ecc_recv_sync(ctx->ctx, &msg);
fail:
@@ -2151,9 +2131,13 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req)
goto fail_with_msg;
msg->tag = mid;
- ret = ecc_send(ctx->ctx, msg);
- if (ret)
+ ret = wd_ecc_setting.driver->send(ctx->ctx, msg);
+ if (unlikely(ret)) {
+ if (ret != -WD_EBUSY)
+ WD_ERR("failed to send ecc BD, hw is err!\n");
+
goto fail_with_msg;
+ }
ret = wd_add_task_to_async_queue(&wd_ecc_env_config, idx);
if (ret)
--
2.27.0

View File

@ -0,0 +1,88 @@
From 9453dd339c43df967cff11f92f270de6f48615a1 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Tue, 31 May 2022 17:01:08 +0800
Subject: [PATCH 134/183] rsa: remove repeated send BD
If -WD_EBUSY is returned When BD is sent, the app
determines whether to resend the BD. The function wd_do_rsa_sync
and wd_do_rsa_async does not try to resend the BD.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
wd_rsa.c | 37 ++++++++++---------------------------
1 file changed, 10 insertions(+), 27 deletions(-)
diff --git a/wd_rsa.c b/wd_rsa.c
index 836c8ae..024f0e0 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -20,7 +20,6 @@
#define WD_HW_EACCESS 62
#define RSA_BALANCE_THRHD 1280
-#define RSA_RESEND_CNT 8
#define RSA_MAX_KEY_SIZE 512
#define RSA_RECV_MAX_CNT 60000000 // 1 min
@@ -252,28 +251,6 @@ static int fill_rsa_msg(struct wd_rsa_msg *msg, struct wd_rsa_req *req,
return 0;
}
-static int rsa_send(handle_t ctx, struct wd_rsa_msg *msg)
-{
- __u32 tx_cnt = 0;
- int ret;
-
- do {
- ret = wd_rsa_setting.driver->send(ctx, msg);
- if (ret == -WD_EBUSY) {
- if (tx_cnt++ >= RSA_RESEND_CNT) {
- WD_ERR("failed to send: retry exit!\n");
- break;
- }
- usleep(1);
- } else if (ret < 0) {
- WD_ERR("failed to send: send error = %d!\n", ret);
- break;
- }
- } while (ret);
-
- return ret;
-}
-
static int rsa_recv_sync(handle_t ctx, struct wd_rsa_msg *msg)
{
struct wd_rsa_req *req = &msg->req;
@@ -339,9 +316,11 @@ int wd_do_rsa_sync(handle_t h_sess, struct wd_rsa_req *req)
return ret;
pthread_spin_lock(&ctx->lock);
- ret = rsa_send(ctx->ctx, &msg);
- if (unlikely(ret))
+ ret = wd_rsa_setting.driver->send(ctx->ctx, &msg);
+ if (unlikely(ret < 0)) {
+ WD_ERR("failed to send rsa BD, ret = %d!\n", ret);
goto fail;
+ }
ret = rsa_recv_sync(ctx->ctx, &msg);
fail:
@@ -383,9 +362,13 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req)
goto fail_with_msg;
msg->tag = mid;
- ret = rsa_send(ctx->ctx, msg);
- if (ret)
+ ret = wd_rsa_setting.driver->send(ctx->ctx, msg);
+ if (unlikely(ret)) {
+ if (ret != -WD_EBUSY)
+ WD_ERR("failed to send rsa BD, hw is err!\n");
+
goto fail_with_msg;
+ }
ret = wd_add_task_to_async_queue(&wd_rsa_env_config, idx);
if (ret)
--
2.27.0

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,38 @@
From 14c04483057e73f7b5781766d48802055051d59d Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Wed, 8 Jun 2022 09:48:50 +0800
Subject: [PATCH 136/183] uadk: missing header file after install uadk
Add header file in build file.
Signed-off-by: Kai Ye <yekai13@huawei.com>
---
Makefile.am | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index a42ec60..0b31cb3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -25,13 +25,13 @@ UADK_VERSION = -version-number ${MAJOR}:${MINOR}:${REVISION}
AM_CFLAGS+= -DUADK_VERSION_NUMBER="\"libwd version: ${MAJOR}.${MINOR}.${REVISION}\""
-include_HEADERS = include/wd.h include/wd_cipher.h include/wd_comp.h \
- include/wd_dh.h include/wd_digest.h include/wd_rsa.h \
- include/uacce.h include/wd_alg_common.h \
+include_HEADERS = include/wd.h include/wd_cipher.h include/wd_aead.h \
+ include/wd_comp.h include/wd_dh.h include/wd_digest.h \
+ include/wd_rsa.h include/uacce.h include/wd_alg_common.h \
include/wd_common.h include/wd_ecc.h include/wd_sched.h
-nobase_include_HEADERS = v1/wd.h v1/wd_cipher.h v1/uacce.h v1/wd_dh.h v1/wd_digest.h \
- v1/wd_rsa.h v1/wd_bmm.h
+nobase_include_HEADERS = v1/wd.h v1/wd_cipher.h v1/wd_aead.h v1/uacce.h v1/wd_dh.h \
+ v1/wd_digest.h v1/wd_rsa.h v1/wd_bmm.h
lib_LTLIBRARIES=libwd.la libwd_comp.la libwd_crypto.la libhisi_zip.la \
libhisi_hpre.la libhisi_sec.la
--
2.27.0

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,96 @@
From 96eae2df1f7a42580037320ae78d513ae5c69dc3 Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Wed, 22 Jun 2022 10:26:29 +0800
Subject: [PATCH 139/183] uadk: sgl data can be dumped
Users can dump the sgl data after setting the uadk log is the
debug level.
Signed-off-by: Kai Ye <yekai13@huawei.com>
---
drv/hisi_qm_udrv.c | 55 +++++++++++++++++++++++++++-------------------
1 file changed, 33 insertions(+), 22 deletions(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 3cb6ffb..985aecc 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -737,6 +737,37 @@ void hisi_qm_put_hw_sgl(handle_t sgl_pool, void *hw_sgl)
return;
}
+static void hisi_qm_dump_sgl(void *sgl)
+{
+ struct hisi_sgl *tmp = (struct hisi_sgl *)sgl;
+ bool need_debug = wd_need_debug();
+ int k = 0;
+ int i;
+
+ if (!need_debug)
+ return;
+
+ while (tmp) {
+ WD_DEBUG("[sgl-%d]->entry_sum_in_chain: %u\n", k,
+ tmp->entry_sum_in_chain);
+ WD_DEBUG("[sgl-%d]->entry_sum_in_sgl: %u\n", k,
+ tmp->entry_sum_in_sgl);
+ WD_DEBUG("[sgl-%d]->entry_length_in_sgl: %u\n", k,
+ tmp->entry_length_in_sgl);
+ for (i = 0; i < tmp->entry_sum_in_sgl; i++)
+ WD_DEBUG("[sgl-%d]->sge_entries[%d].len: %u\n", k, i,
+ tmp->sge_entries[i].len);
+
+ tmp = (struct hisi_sgl *)tmp->next_dma;
+ k++;
+
+ if (!tmp) {
+ WD_DEBUG("debug: sgl num size:%d\n", k);
+ return;
+ }
+ }
+}
+
void *hisi_qm_get_hw_sgl(handle_t sgl_pool, struct wd_datalist *sgl)
{
struct hisi_sgl_pool *pool = (struct hisi_sgl_pool *)sgl_pool;
@@ -799,6 +830,8 @@ void *hisi_qm_get_hw_sgl(handle_t sgl_pool, struct wd_datalist *sgl)
if (!head->entry_sum_in_chain)
goto err_out;
+ hisi_qm_dump_sgl(head);
+
return head;
err_out:
hisi_qm_put_hw_sgl(sgl_pool, head);
@@ -922,28 +955,6 @@ void hisi_qm_sgl_copy(void *pbuff, void *hw_sgl, __u32 offset, __u32 size,
size);
}
-void hisi_qm_dump_sgl(void *sgl)
-{
- struct hisi_sgl *tmp = (struct hisi_sgl *)sgl;
- int i;
-
- while (tmp) {
- WD_ERR("sgl->entry_sum_in_chain : %u\n",
- tmp->entry_sum_in_chain);
- WD_ERR("sgl->entry_sum_in_sgl : %u\n",
- tmp->entry_sum_in_sgl);
- WD_ERR("sgl->entry_length_in_sgl : %u\n",
- tmp->entry_length_in_sgl);
- for (i = 0; i < tmp->entry_sum_in_sgl; i++) {
- WD_ERR("sgl->sge_entries[%d].buff : 0x%lx\n", i,
- tmp->sge_entries[i].buff);
- WD_ERR("sgl->sge_entries[%d].len : %u\n", i,
- tmp->sge_entries[i].len);
- }
- tmp = (struct hisi_sgl *)tmp->next_dma;
- }
-}
-
__u32 hisi_qm_get_list_size(struct wd_datalist *start_node,
struct wd_datalist *end_node)
{
--
2.27.0

View File

@ -0,0 +1,631 @@
From 71d7f88f42da4959037adebd34804ef32af95d0d Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Wed, 22 Jun 2022 10:26:30 +0800
Subject: [PATCH 140/183] uadk: supports zip and sec message dumping
Dumping ZIP and SEC messages as receiving task errors.
Signed-off-by: Kai Ye <yekai13@huawei.com>
---
drv/hisi_comp.c | 18 ++-
drv/hisi_sec.c | 297 +++++++++++++++++++++++-------------
include/drv/wd_aead_drv.h | 1 +
include/drv/wd_cipher_drv.h | 1 +
include/drv/wd_digest_drv.h | 1 +
wd_aead.c | 5 +
wd_cipher.c | 5 +
wd_digest.c | 5 +
8 files changed, 227 insertions(+), 106 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index 2c0fc41..69785e9 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -189,6 +189,13 @@ struct hisi_zip_ctx {
struct wd_ctx_config_internal config;
};
+static void dump_zip_msg(struct wd_comp_msg *msg)
+{
+ WD_ERR("dump zip message after a task error occurs.\n");
+ WD_ERR("avali_out:%u in_cons:%u produced:%u data_fmt:%d.\n",
+ msg->avail_out, msg->in_cons, msg->produced, msg->data_fmt);
+}
+
static int buf_size_check_deflate(__u32 *in_size, __u32 *out_size)
{
if (unlikely(*in_size > HZ_MAX_SIZE)) {
@@ -958,13 +965,15 @@ static void get_ctx_buf(struct hisi_zip_sqe *sqe,
}
static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
- struct wd_comp_msg *recv_msg)
+ struct wd_comp_msg *msg)
{
__u32 buf_type = (sqe->dw9 & HZ_BUF_TYPE_MASK) >> BUF_TYPE_SHIFT;
__u16 ctx_st = sqe->ctx_dw0 & HZ_CTX_ST_MASK;
__u16 lstblk = sqe->dw3 & HZ_LSTBLK_MASK;
__u32 status = sqe->dw3 & HZ_STATUS_MASK;
__u32 type = sqe->dw9 & HZ_REQ_TYPE_MASK;
+ struct wd_comp_msg *recv_msg = msg;
+ bool need_debug = wd_need_debug();
int alg_type, ret;
__u32 tag;
@@ -1007,7 +1016,9 @@ 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);
+ if (need_debug)
+ WD_DEBUG("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;
@@ -1018,6 +1029,9 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
if (buf_type == WD_SGL_BUF)
free_hw_sgl((handle_t)qp, sqe, alg_type);
+ if (unlikely(recv_msg->req.status == WD_IN_EPARA))
+ dump_zip_msg(recv_msg);
+
return 0;
}
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 7f12549..5865ffb 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -486,6 +486,56 @@ 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);
+static void dump_sec_msg(void *msg, const char *alg)
+{
+ struct wd_cipher_msg *cmsg;
+ struct wd_digest_msg *dmsg;
+ struct wd_aead_msg *amsg;
+
+ WD_ERR("dump %s alg message after a task error occurs.\n", alg);
+
+ if (!strcmp(alg, "cipher")) {
+ cmsg = (struct wd_cipher_msg *)msg;
+ WD_ERR("type:%u alg:%u op_type:%u mode:%u data_fmt:%u\n",
+ cmsg->alg_type, cmsg->alg, cmsg->op_type, cmsg->mode,
+ cmsg->data_fmt);
+ WD_ERR("key_bytes:%u iv_bytes:%u in_bytes:%u out_bytes:%u\n",
+ cmsg->key_bytes, cmsg->iv_bytes, cmsg->in_bytes, cmsg->out_bytes);
+ } else if (!strcmp(alg, "digest")) {
+ dmsg = (struct wd_digest_msg *)msg;
+ WD_ERR("type:%u alg:%u has_next:%u mode:%u data_fmt:%u\n",
+ dmsg->alg_type, dmsg->alg, dmsg->has_next, dmsg->mode, dmsg->data_fmt);
+ WD_ERR("key_bytes:%u iv_bytes:%u in_bytes:%u out_bytes:%u\n",
+ dmsg->key_bytes, dmsg->iv_bytes, dmsg->in_bytes, dmsg->out_bytes);
+ } else if (!strcmp(alg, "aead")) {
+ amsg = (struct wd_aead_msg *)msg;
+ WD_ERR("type:%u calg:%u op_type:%u cmode:%u\n",
+ amsg->alg_type, amsg->calg, amsg->op_type, amsg->cmode);
+ WD_ERR("data_fmt:%u ckey_bytes:%u auth_bytes:%u\n",
+ amsg->data_fmt, amsg->ckey_bytes, amsg->auth_bytes);
+ WD_ERR("assoc_bytes:%u in_bytes:%u out_bytes:%u\n",
+ amsg->assoc_bytes, amsg->in_bytes, amsg->out_bytes);
+ }
+}
+
+static __u8 get_data_fmt_v3(__u32 bd_param)
+{
+ /* Only check the src addr type */
+ if (bd_param & SEC_PBUFF_MODE_MASK_V3)
+ return WD_SGL_BUF;
+
+ return WD_FLAT_BUF;
+}
+
+static __u8 get_data_fmt_v2(__u32 sds_sa_type)
+{
+ /* Only check the src addr type */
+ if (sds_sa_type & SEC_SGL_SDS_MASK)
+ return WD_SGL_BUF;
+
+ return WD_FLAT_BUF;
+}
+
/* increment counter (128-bit int) by software */
static void ctr_iv_inc(__u8 *counter, __u32 len)
{
@@ -668,25 +718,14 @@ static void fill_cipher_bd2_addr(struct wd_cipher_msg *msg,
sqe->type2.data_dst_addr = (__u64)(uintptr_t)msg->out;
sqe->type2.c_ivin_addr = (__u64)(uintptr_t)msg->iv;
sqe->type2.c_key_addr = (__u64)(uintptr_t)msg->key;
-
- /*
- * Because some special algorithms need to update IV
- * after receiving the BD, and the relevant information
- * is in the send message, so the BD field segment is
- * needed to return the message pointer.
- * The Cipher algorithm does not use the mac_addr segment
- * in the BD domain and the hardware will copy all the
- * field values of the send BD when returning, so we use
- * mac_addr to carry the message pointer here.
- */
- sqe->type2.mac_addr = (__u64)(uintptr_t)msg;
}
-static void parse_cipher_bd2(struct hisi_sec_sqe *sqe,
+static void parse_cipher_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe,
struct wd_cipher_msg *recv_msg)
{
- struct wd_cipher_msg *rmsg;
+ struct wd_cipher_msg *temp_msg;
__u16 done;
+ __u32 tag;
done = sqe->type2.done_flag & SEC_DONE_MASK;
if (done != SEC_HW_TASK_DONE || sqe->type2.error_type) {
@@ -697,17 +736,33 @@ static void parse_cipher_bd2(struct hisi_sec_sqe *sqe,
recv_msg->result = WD_SUCCESS;
}
- rmsg = (struct wd_cipher_msg *)(uintptr_t)sqe->type2.mac_addr;
+ tag = sqe->type2.tag;
+ recv_msg->tag = tag;
+
+ if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
+ recv_msg->alg_type = WD_CIPHER;
+ recv_msg->data_fmt = get_data_fmt_v2(sqe->sds_sa_type);
+ recv_msg->in = (__u8 *)(uintptr_t)sqe->type2.data_src_addr;
+ recv_msg->out = (__u8 *)(uintptr_t)sqe->type2.data_dst_addr;
+ temp_msg = wd_cipher_get_msg(qp->q_info.idx, tag);
+ if (!temp_msg) {
+ recv_msg->result = WD_IN_EPARA;
+ WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
+ qp->q_info.idx, tag);
+ return;
+ }
+ } else {
+ /* The synchronization mode uses the same message */
+ temp_msg = recv_msg;
+ }
- if (rmsg->data_fmt != WD_SGL_BUF)
- update_iv(rmsg);
+ if (temp_msg->data_fmt != WD_SGL_BUF)
+ update_iv(temp_msg);
else
- update_iv_sgl(rmsg);
+ update_iv_sgl(temp_msg);
- recv_msg->data_fmt = rmsg->data_fmt;
- recv_msg->alg_type = rmsg->alg_type;
- recv_msg->in = rmsg->in;
- recv_msg->out = rmsg->out;
+ if (unlikely(recv_msg->result != WD_SUCCESS))
+ dump_sec_msg(temp_msg, "cipher");
}
static int cipher_len_check(struct wd_cipher_msg *msg)
@@ -752,24 +807,6 @@ static int cipher_len_check(struct wd_cipher_msg *msg)
return 0;
}
-static __u8 hisi_sec_get_data_fmt_v3(__u32 bd_param)
-{
- /* Only check the src addr type */
- if (bd_param & SEC_PBUFF_MODE_MASK_V3)
- return WD_SGL_BUF;
-
- return WD_FLAT_BUF;
-}
-
-static __u8 hisi_sec_get_data_fmt_v2(__u32 sds_sa_type)
-{
- /* Only check the src addr type */
- if (sds_sa_type & SEC_SGL_SDS_MASK)
- return WD_SGL_BUF;
-
- return WD_FLAT_BUF;
-}
-
static void hisi_sec_put_sgl(handle_t h_qp, __u8 alg_type, void *in, void *out)
{
handle_t h_sgl_pool;
@@ -967,8 +1004,7 @@ int hisi_sec_cipher_recv(handle_t ctx, void *cipher_msg)
if (ret)
return ret;
- parse_cipher_bd2(&sqe, recv_msg);
- recv_msg->tag = sqe.type2.tag;
+ parse_cipher_bd2((struct hisi_qp *)h_qp, &sqe, recv_msg);
if (recv_msg->data_fmt == WD_SGL_BUF)
hisi_sec_put_sgl(h_qp, recv_msg->alg_type, recv_msg->in,
@@ -1064,18 +1100,6 @@ static void fill_cipher_bd3_addr(struct wd_cipher_msg *msg,
sqe->data_dst_addr = (__u64)(uintptr_t)msg->out;
sqe->no_scene.c_ivin_addr = (__u64)(uintptr_t)msg->iv;
sqe->c_key_addr = (__u64)(uintptr_t)msg->key;
-
- /*
- * Because some special algorithms need to update IV
- * after receiving the BD, and the relevant information
- * is in the send message, so the BD field segment is
- * needed to return the message pointer.
- * The Cipher algorithm does not use the mac_addr segment
- * in the BD domain and the hardware will copy all the
- * field values of the send BD when returning, so we use
- * mac_addr to carry the message pointer here.
- */
- sqe->mac_addr = (__u64)(uintptr_t)msg;
}
static int fill_cipher_bd3(struct wd_cipher_msg *msg, struct hisi_sec_sqe3 *sqe)
@@ -1159,11 +1183,12 @@ int hisi_sec_cipher_send_v3(handle_t ctx, void *cipher_msg)
return 0;
}
-static void parse_cipher_bd3(struct hisi_sec_sqe3 *sqe,
+static void parse_cipher_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
struct wd_cipher_msg *recv_msg)
{
- struct wd_cipher_msg *rmsg;
+ struct wd_cipher_msg *temp_msg;
__u16 done;
+ __u32 tag;
done = sqe->done_flag & SEC_DONE_MASK;
if (done != SEC_HW_TASK_DONE || sqe->error_type) {
@@ -1174,16 +1199,33 @@ static void parse_cipher_bd3(struct hisi_sec_sqe3 *sqe,
recv_msg->result = WD_SUCCESS;
}
- rmsg = (struct wd_cipher_msg *)(uintptr_t)sqe->mac_addr;
- if (rmsg->data_fmt != WD_SGL_BUF)
- update_iv(rmsg);
+ tag = sqe->tag;
+
+ recv_msg->tag = tag;
+ if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
+ recv_msg->alg_type = WD_CIPHER;
+ recv_msg->data_fmt = get_data_fmt_v3(sqe->bd_param);
+ recv_msg->in = (__u8 *)(uintptr_t)sqe->data_src_addr;
+ recv_msg->out = (__u8 *)(uintptr_t)sqe->data_dst_addr;
+ temp_msg = wd_cipher_get_msg(qp->q_info.idx, tag);
+ if (!temp_msg) {
+ recv_msg->result = WD_IN_EPARA;
+ WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
+ qp->q_info.idx, tag);
+ return;
+ }
+ } else {
+ /* The synchronization mode uses the same message */
+ temp_msg = recv_msg;
+ }
+
+ if (temp_msg->data_fmt != WD_SGL_BUF)
+ update_iv(temp_msg);
else
- update_iv_sgl(rmsg);
+ update_iv_sgl(temp_msg);
- recv_msg->data_fmt = rmsg->data_fmt;
- recv_msg->alg_type = rmsg->alg_type;
- recv_msg->in = rmsg->in;
- recv_msg->out = rmsg->out;
+ if (unlikely(recv_msg->result != WD_SUCCESS))
+ dump_sec_msg(temp_msg, "cipher");
}
int hisi_sec_cipher_recv_v3(handle_t ctx, void *cipher_msg)
@@ -1202,8 +1244,7 @@ int hisi_sec_cipher_recv_v3(handle_t ctx, void *cipher_msg)
if (ret)
return ret;
- parse_cipher_bd3(&sqe, recv_msg);
- recv_msg->tag = sqe.tag;
+ parse_cipher_bd3((struct hisi_qp *)h_qp, &sqe, recv_msg);
if (recv_msg->data_fmt == WD_SGL_BUF)
hisi_sec_put_sgl(h_qp, recv_msg->alg_type, recv_msg->in,
@@ -1268,9 +1309,10 @@ static void qm_fill_digest_long_bd(struct wd_digest_msg *msg,
}
}
-static void parse_digest_bd2(struct hisi_sec_sqe *sqe,
+static void parse_digest_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe,
struct wd_digest_msg *recv_msg)
{
+ struct wd_digest_msg *temp_msg;
__u16 done;
done = sqe->type2.done_flag & SEC_DONE_MASK;
@@ -1284,9 +1326,24 @@ static void parse_digest_bd2(struct hisi_sec_sqe *sqe,
recv_msg->tag = sqe->type2.tag;
- 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;
+ if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
+ recv_msg->alg_type = WD_DIGEST;
+ recv_msg->data_fmt = get_data_fmt_v2(sqe->sds_sa_type);
+ recv_msg->in = (__u8 *)(uintptr_t)sqe->type2.data_src_addr;
+ temp_msg = wd_digest_get_msg(qp->q_info.idx, recv_msg->tag);
+ if (!temp_msg) {
+ recv_msg->result = WD_IN_EPARA;
+ WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
+ qp->q_info.idx, recv_msg->tag);
+ return;
+ }
+ } else {
+ /* The synchronization mode uses the same message */
+ temp_msg = recv_msg;
+ }
+
+ if (unlikely(recv_msg->result != WD_SUCCESS))
+ dump_sec_msg(temp_msg, "digest");
}
static int digest_long_bd_check(struct wd_digest_msg *msg)
@@ -1417,7 +1474,7 @@ int hisi_sec_digest_recv(handle_t ctx, void *digest_msg)
if (ret)
return ret;
- parse_digest_bd2(&sqe, recv_msg);
+ parse_digest_bd2((struct hisi_qp *)h_qp, &sqe, recv_msg);
if (recv_msg->data_fmt == WD_SGL_BUF)
hisi_sec_put_sgl(h_qp, recv_msg->alg_type, recv_msg->in,
@@ -1558,9 +1615,10 @@ put_sgl:
return ret;
}
-static void parse_digest_bd3(struct hisi_sec_sqe3 *sqe,
+static void parse_digest_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
struct wd_digest_msg *recv_msg)
{
+ struct wd_digest_msg *temp_msg;
__u16 done;
done = sqe->done_flag & SEC_DONE_MASK;
@@ -1574,9 +1632,24 @@ static void parse_digest_bd3(struct hisi_sec_sqe3 *sqe,
recv_msg->tag = sqe->tag;
- 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;
+ if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
+ recv_msg->alg_type = WD_DIGEST;
+ recv_msg->data_fmt = get_data_fmt_v3(sqe->bd_param);
+ recv_msg->in = (__u8 *)(uintptr_t)sqe->data_src_addr;
+ temp_msg = wd_digest_get_msg(qp->q_info.idx, recv_msg->tag);
+ if (!temp_msg) {
+ recv_msg->result = WD_IN_EPARA;
+ WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
+ qp->q_info.idx, recv_msg->tag);
+ return;
+ }
+ } else {
+ /* The synchronization mode uses the same message */
+ temp_msg = recv_msg;
+ }
+
+ if (unlikely(recv_msg->result != WD_SUCCESS))
+ dump_sec_msg(temp_msg, "digest");
}
int hisi_sec_digest_recv_v3(handle_t ctx, void *digest_msg)
@@ -1595,7 +1668,7 @@ int hisi_sec_digest_recv_v3(handle_t ctx, void *digest_msg)
if (ret)
return ret;
- parse_digest_bd3(&sqe, recv_msg);
+ parse_digest_bd3((struct hisi_qp *)h_qp, &sqe, recv_msg);
if (recv_msg->data_fmt == WD_SGL_BUF)
hisi_sec_put_sgl(h_qp, recv_msg->alg_type, recv_msg->in,
@@ -1899,9 +1972,10 @@ int hisi_sec_aead_send(handle_t ctx, void *aead_msg)
return 0;
}
-static void parse_aead_bd2(struct hisi_sec_sqe *sqe,
+static void parse_aead_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe,
struct wd_aead_msg *recv_msg)
{
+ struct wd_aead_msg *temp_msg;
__u16 done, icv;
done = sqe->type2.done_flag & SEC_DONE_MASK;
@@ -1917,18 +1991,25 @@ static void parse_aead_bd2(struct hisi_sec_sqe *sqe,
recv_msg->tag = sqe->type2.tag;
- 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->out = (__u8 *)(uintptr_t)sqe->type2.data_dst_addr;
- recv_msg->alg_type = WD_AEAD;
- 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)
- recv_msg->auth_bytes = sqe->type2.icvw_kmode &
- SEC_AUTH_LEN_MASK;
- recv_msg->out_bytes = sqe->type2.clen_ivhlen +
- sqe->type2.cipher_src_offset;
+ if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
+ recv_msg->alg_type = WD_AEAD;
+ recv_msg->data_fmt = get_data_fmt_v2(sqe->sds_sa_type);
+ recv_msg->in = (__u8 *)(uintptr_t)sqe->type2.data_src_addr;
+ recv_msg->out = (__u8 *)(uintptr_t)sqe->type2.data_dst_addr;
+ temp_msg = wd_aead_get_msg(qp->q_info.idx, recv_msg->tag);
+ if (!temp_msg) {
+ recv_msg->result = WD_IN_EPARA;
+ WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
+ qp->q_info.idx, recv_msg->tag);
+ return;
+ }
+ } else {
+ /* The synchronization mode uses the same message */
+ temp_msg = recv_msg;
+ }
+
+ if (unlikely(recv_msg->result != WD_SUCCESS))
+ dump_sec_msg(temp_msg, "aead");
}
int hisi_sec_aead_recv(handle_t ctx, void *aead_msg)
@@ -1947,7 +2028,7 @@ int hisi_sec_aead_recv(handle_t ctx, void *aead_msg)
if (ret)
return ret;
- parse_aead_bd2(&sqe, recv_msg);
+ parse_aead_bd2((struct hisi_qp *)h_qp, &sqe, recv_msg);
if (recv_msg->data_fmt == WD_SGL_BUF)
hisi_sec_put_sgl(h_qp, recv_msg->alg_type, recv_msg->in,
@@ -2160,9 +2241,10 @@ int hisi_sec_aead_send_v3(handle_t ctx, void *aead_msg)
return 0;
}
-static void parse_aead_bd3(struct hisi_sec_sqe3 *sqe,
+static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
struct wd_aead_msg *recv_msg)
{
+ struct wd_aead_msg *temp_msg;
__u16 done, icv;
done = sqe->done_flag & SEC_DONE_MASK;
@@ -2178,18 +2260,25 @@ static void parse_aead_bd3(struct hisi_sec_sqe3 *sqe,
recv_msg->tag = sqe->tag;
- 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->out = (__u8 *)(uintptr_t)sqe->data_dst_addr;
- recv_msg->alg_type = WD_AEAD;
- 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)
- recv_msg->auth_bytes = (sqe->c_icv_key >> SEC_MAC_OFFSET_V3) &
- SEC_MAC_LEN_MASK;
- recv_msg->out_bytes = sqe->c_len_ivin +
- sqe->cipher_src_offset;
+ if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
+ recv_msg->alg_type = WD_AEAD;
+ recv_msg->data_fmt = get_data_fmt_v3(sqe->bd_param);
+ recv_msg->in = (__u8 *)(uintptr_t)sqe->data_src_addr;
+ recv_msg->out = (__u8 *)(uintptr_t)sqe->data_dst_addr;
+ temp_msg = wd_aead_get_msg(qp->q_info.idx, recv_msg->tag);
+ if (!temp_msg) {
+ recv_msg->result = WD_IN_EPARA;
+ WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
+ qp->q_info.idx, recv_msg->tag);
+ return;
+ }
+ } else {
+ /* The synchronization mode uses the same message */
+ temp_msg = recv_msg;
+ }
+
+ if (unlikely(recv_msg->result != WD_SUCCESS))
+ dump_sec_msg(temp_msg, "aead");
}
int hisi_sec_aead_recv_v3(handle_t ctx, void *aead_msg)
@@ -2208,7 +2297,7 @@ int hisi_sec_aead_recv_v3(handle_t ctx, void *aead_msg)
if (ret)
return ret;
- parse_aead_bd3(&sqe, recv_msg);
+ parse_aead_bd3((struct hisi_qp *)h_qp, &sqe, recv_msg);
if (recv_msg->data_fmt == WD_SGL_BUF)
hisi_sec_put_sgl(h_qp, recv_msg->alg_type,
diff --git a/include/drv/wd_aead_drv.h b/include/drv/wd_aead_drv.h
index cca28ba..de4a7d7 100644
--- a/include/drv/wd_aead_drv.h
+++ b/include/drv/wd_aead_drv.h
@@ -76,6 +76,7 @@ struct wd_aead_driver {
void wd_aead_set_driver(struct wd_aead_driver *drv);
struct wd_aead_driver *wd_aead_get_driver(void);
+struct wd_aead_msg *wd_aead_get_msg(__u32 idx, __u32 tag);
#ifdef WD_STATIC_DRV
#define WD_AEAD_SET_DRIVER(drv) \
diff --git a/include/drv/wd_cipher_drv.h b/include/drv/wd_cipher_drv.h
index 84c9844..a8da8cc 100644
--- a/include/drv/wd_cipher_drv.h
+++ b/include/drv/wd_cipher_drv.h
@@ -62,6 +62,7 @@ struct wd_cipher_driver {
void wd_cipher_set_driver(struct wd_cipher_driver *drv);
struct wd_cipher_driver *wd_cipher_get_driver(void);
+struct wd_cipher_msg *wd_cipher_get_msg(__u32 idx, __u32 tag);
#ifdef WD_STATIC_DRV
#define WD_CIPHER_SET_DRIVER(drv) \
diff --git a/include/drv/wd_digest_drv.h b/include/drv/wd_digest_drv.h
index 10ce6e1..39839f6 100644
--- a/include/drv/wd_digest_drv.h
+++ b/include/drv/wd_digest_drv.h
@@ -64,6 +64,7 @@ struct wd_digest_driver {
void wd_digest_set_driver(struct wd_digest_driver *drv);
struct wd_digest_driver *wd_digest_get_driver(void);
+struct wd_digest_msg *wd_digest_get_msg(__u32 idx, __u32 tag);
#ifdef WD_STATIC_DRV
#define WD_DIGEST_SET_DRIVER(drv) \
diff --git a/wd_aead.c b/wd_aead.c
index 0c54de3..d43ace1 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -596,6 +596,11 @@ fail_with_msg:
return ret;
}
+struct wd_aead_msg *wd_aead_get_msg(__u32 idx, __u32 tag)
+{
+ return wd_find_msg_in_pool(&wd_aead_setting.pool, idx, tag);
+}
+
int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
{
struct wd_ctx_config_internal *config = &wd_aead_setting.config;
diff --git a/wd_cipher.c b/wd_cipher.c
index 0cd2e42..3d00598 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -505,6 +505,11 @@ fail_with_msg:
return ret;
}
+struct wd_cipher_msg *wd_cipher_get_msg(__u32 idx, __u32 tag)
+{
+ return wd_find_msg_in_pool(&wd_cipher_setting.pool, idx, tag);
+}
+
int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
{
struct wd_ctx_config_internal *config = &wd_cipher_setting.config;
diff --git a/wd_digest.c b/wd_digest.c
index ae37e32..43b4bc5 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -405,6 +405,11 @@ fail_with_msg:
return ret;
}
+struct wd_digest_msg *wd_digest_get_msg(__u32 idx, __u32 tag)
+{
+ return wd_find_msg_in_pool(&wd_digest_setting.pool, idx, tag);
+}
+
int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
{
struct wd_ctx_config_internal *config = &wd_digest_setting.config;
--
2.27.0

View File

@ -0,0 +1,65 @@
From 45d65ffcfea660dded788d6819399833e017fd9f Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Wed, 22 Jun 2022 10:26:31 +0800
Subject: [PATCH 141/183] uadk: add device isolation interface
Users need to check whether the device is isolated before using
the device. So add an isolation interface.
Signed-off-by: Kai Ye <yekai13@huawei.com>
---
include/wd.h | 8 ++++++++
wd.c | 18 ++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/include/wd.h b/include/wd.h
index 8c45522..b8044a4 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -293,6 +293,14 @@ int wd_ctx_wait(handle_t h_ctx, __u16 ms);
*/
int wd_is_sva(handle_t h_ctx);
+/**
+ * wd_is_isolate() - Check if the device has been isolated.
+ * @dev: Indicate one device.
+ *
+ * Return 1 if isolated, 0 for not isolated, less than 0 otherwise.
+ */
+int wd_is_isolate(struct uacce_dev *dev);
+
/**
* wd_get_accel_name() - Get device name or driver name.
* @dev_path: The path of device. e.g. /dev/hisi_zip-0.
diff --git a/wd.c b/wd.c
index 2dbb2ab..9715e10 100644
--- a/wd.c
+++ b/wd.c
@@ -186,6 +186,24 @@ static int access_attr(const char *dev_root, const char *attr, int mode)
return access(attr_file, mode);
}
+int wd_is_isolate(struct uacce_dev *dev)
+{
+ int value = 0;
+ int ret;
+
+ if (!dev || !dev->dev_root)
+ return -WD_EINVAL;
+
+ ret = access_attr(dev->dev_root, "isolate", F_OK);
+ if (!ret) {
+ ret = get_int_attr(dev, "isolate", &value);
+ if (ret < 0)
+ return ret;
+ }
+
+ return value == 1 ? 1 : 0;
+}
+
static int get_dev_info(struct uacce_dev *dev)
{
int value = 0;
--
2.27.0

View File

@ -0,0 +1,249 @@
From 2884d11a6307d239f72515309b565132c97f1172 Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Wed, 22 Jun 2022 10:26:32 +0800
Subject: [PATCH 142/183] uadk: add WD_DEV_ERR api
This interface supports device differentiation by the handle of.
context. Users can use the api if they have requested the ctx.
Otherwise, occurred an error.
Signed-off-by: Kai Ye <yekai13@huawei.com>
---
drv/hisi_hpre.c | 4 ----
drv/hisi_qm_udrv.c | 33 +++++++++++++++++----------------
include/hisi_qm_udrv.h | 5 +++++
include/wd.h | 14 ++++++++++++++
wd.c | 10 ++++++++++
5 files changed, 46 insertions(+), 20 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 7fd4189..d503d84 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -44,10 +44,6 @@
#define GEN_PARAMS_SZ(key_size) ((key_size) << 1)
#define CRT_PARAM_SZ(key_size) ((key_size) >> 1)
-#define container_of(ptr, type, member) ({ \
- typeof(((type *)0)->member)(*__mptr) = (ptr); \
- (type *)((char *)__mptr - offsetof(type, member)); })
-
enum hpre_alg_type {
HPRE_ALG_NC_NCRT = 0x0,
HPRE_ALG_NC_CRT = 0x1,
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 985aecc..9eaf60c 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("failed to mmap dus!\n");
+ WD_DEV_ERR(h_ctx, "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("failed to mmap mmio!\n");
+ WD_DEV_ERR(h_ctx, "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("invalid: api name is %s!\n", api_name);
+ WD_DEV_ERR(h_ctx, "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("failed to strtoul, ver = %lu!\n", ver);
+ WD_DEV_ERR(h_ctx, "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("failed to set qc_type, use default value!\n");
+ WD_DEV_ERR(h_ctx, "failed to set qc_type, use default value!\n");
return ret;
}
@@ -267,14 +267,14 @@ static int hisi_qm_get_qfrs_offs(handle_t h_ctx,
type = UACCE_QFRT_DUS;
q_info->region_size[type] = wd_ctx_get_region_size(h_ctx, type);
if (!q_info->region_size[type]) {
- WD_ERR("failed to get DUS qfrs offset!\n");
+ WD_DEV_ERR(h_ctx, "failed to get DUS qfrs offset!\n");
return -WD_EINVAL;
}
type = UACCE_QFRT_MMIO;
q_info->region_size[type] = wd_ctx_get_region_size(h_ctx, type);
if (!q_info->region_size[type]) {
- WD_ERR("failed to get MMIO qfrs offset!\n");
+ WD_DEV_ERR(h_ctx, "failed to get MMIO qfrs offset!\n");
return -WD_EINVAL;
}
@@ -289,25 +289,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("failed to setup region!\n");
+ WD_DEV_ERR(qp->h_ctx, "failed to setup region!\n");
return ret;
}
ret = hisi_qm_get_qfrs_offs(qp->h_ctx, q_info);
if (ret) {
- WD_ERR("failed to get dev qfrs offset!\n");
+ WD_DEV_ERR(qp->h_ctx, "failed to get dev qfrs offset!\n");
goto err_out;
}
ret = hisi_qm_setup_db(qp->h_ctx, q_info);
if (ret) {
- WD_ERR("failed to setup db!\n");
+ WD_DEV_ERR(qp->h_ctx, "failed to setup db!\n");
goto err_out;
}
ret = his_qm_set_qp_ctx(qp->h_ctx, config, q_info);
if (ret) {
- WD_ERR("failed to setup io cmd!\n");
+ WD_DEV_ERR(qp->h_ctx, "failed to setup io cmd!\n");
goto err_out;
}
@@ -324,7 +324,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("failed to init qinfo lock!\n");
+ WD_DEV_ERR(qp->h_ctx, "failed to init qinfo lock!\n");
goto err_out;
}
@@ -455,6 +455,7 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, void *resp)
{
+ struct hisi_qp *qp = container_of(q_info, struct hisi_qp, q_info);
struct cqe *cqe;
__u16 i, j;
@@ -466,7 +467,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_DEV_ERR(qp->h_ctx, "CQE_SQ_HEAD_INDEX(%u) error!\n", j);
return -WD_EIO;
}
memcpy(resp, (void *)((uintptr_t)q_info->sq_base +
@@ -510,7 +511,7 @@ int hisi_qm_recv(handle_t h_qp, void *resp, __u16 expect, __u16 *count)
q_info = &qp->q_info;
if (wd_ioread32(q_info->ds_rx_base) == 1) {
- WD_ERR("wd queue hw error happened before qm receive!\n");
+ WD_DEV_ERR(qp->h_ctx, "wd queue hw error happened before qm receive!\n");
return -WD_HW_EACCESS;
}
@@ -524,7 +525,7 @@ int hisi_qm_recv(handle_t h_qp, void *resp, __u16 expect, __u16 *count)
*count = recv_num++;
if (wd_ioread32(q_info->ds_rx_base) == 1) {
- WD_ERR("wd queue hw error happened in qm receive!\n");
+ WD_DEV_ERR(qp->h_ctx, "wd queue hw error happened in qm receive!\n");
return -WD_HW_EACCESS;
}
@@ -537,7 +538,7 @@ int hisi_check_bd_id(handle_t h_qp, __u32 mid, __u32 bid)
__u8 mode = qp->q_info.qp_mode;
if (mode == CTX_MODE_SYNC && mid != bid) {
- WD_ERR("failed to recv self bd, send id: %u, recv id: %u\n",
+ WD_DEV_ERR(qp->h_ctx, "failed to recv self bd, send id: %u, recv id: %u\n",
mid, bid);
return -WD_EINVAL;
}
diff --git a/include/hisi_qm_udrv.h b/include/hisi_qm_udrv.h
index ea5807e..0ea17c6 100644
--- a/include/hisi_qm_udrv.h
+++ b/include/hisi_qm_udrv.h
@@ -29,6 +29,11 @@ extern "C" {
#define BYTE_BITS 8
#define BYTE_BITS_SHIFT 3
+#define __offsetof(t, m) ((size_t)(uintptr_t)&((t *)0)->m)
+#define container_of(ptr, type, member) ({ \
+ typeof(((type *)0)->member)(*__mptr) = (ptr); \
+ (type *)((char *)__mptr - __offsetof(type, member)); })
+
enum hisi_qm_sgl_copy_dir {
COPY_SGL_TO_PBUFF,
COPY_PBUFF_TO_SGL
diff --git a/include/wd.h b/include/wd.h
index b8044a4..b0580ba 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -57,6 +57,13 @@ typedef void (*wd_log)(const char *format, ...);
#define WD_ERR(fmt, args...) fprintf(stderr, fmt, ##args)
#endif
+/* @h_ctx: The handle of context. */
+#define WD_DEV_ERR(h_ctx, format, args...)\
+ do { \
+ char *dev_name = wd_ctx_get_dev_name(h_ctx); \
+ WD_ERR("%s: "format"\n", dev_name, ##args); \
+ } while (0)
+
#define WD_CONSOLE printf
/* WD error code */
@@ -496,6 +503,13 @@ void wd_mempool_stats(handle_t mempool, struct wd_mempool_stats *stats);
*/
void wd_blockpool_stats(handle_t blkpool, struct wd_blockpool_stats *stats);
+/**
+ * wd_ctx_get_dev_name() - Get the device name about task.
+ * @h_ctx: The handle of context.
+ * Return device name.
+ */
+char *wd_ctx_get_dev_name(handle_t h_ctx);
+
/**
* wd_get_version() - Get the libwd version number and released time.
*/
diff --git a/wd.c b/wd.c
index 9715e10..b0c3dec 100644
--- a/wd.c
+++ b/wd.c
@@ -826,3 +826,13 @@ bool wd_need_info(void)
{
return uadk_log_level >= WD_LOG_INFO;
}
+
+char *wd_ctx_get_dev_name(handle_t h_ctx)
+{
+ struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
+
+ if (!ctx)
+ return NULL;
+
+ return ctx->dev_name;
+}
--
2.27.0

View File

@ -0,0 +1,42 @@
From e54fc1d2840a7bd9b884a84d5fd4de385f23e03f Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Fri, 1 Jul 2022 11:01:06 +0800
Subject: [PATCH 143/183] uadk/ecc - remove a redefined macro
Macro 'offsetof' has been defined in 'stddef.h'. So remove the
redefined one in 'wd_ecc_drv.h'.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
include/drv/wd_ecc_drv.h | 2 --
wd_ecc.c | 1 +
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index ef98606..857da20 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -45,8 +45,6 @@ extern "C" {
#define WD_X448 0x2
#define WD_SM2P256 0x3
-#define offsetof(t, m) ((size_t)(uintptr_t)&((t *)0)->m)
-
/* ECC message format */
struct wd_ecc_msg {
struct wd_ecc_req req;
diff --git a/wd_ecc.c b/wd_ecc.c
index 1ff6ed3..4cf287b 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -8,6 +8,7 @@
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
+#include <stddef.h>
#include <string.h>
#include <time.h>
#include <dlfcn.h>
--
2.27.0

View File

@ -0,0 +1,40 @@
From 24a24c44373d3d2fb185bd7c3c3d8d158b63569e Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Fri, 1 Jul 2022 11:01:07 +0800
Subject: [PATCH 144/183] uadk/hisi - remove a redefined macro
Macro 'offsetof' has been defined in 'stddef.h'. So remove the
redefined one in 'hisi_qm_udrv.h'.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
include/hisi_qm_udrv.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/hisi_qm_udrv.h b/include/hisi_qm_udrv.h
index 0ea17c6..88758ac 100644
--- a/include/hisi_qm_udrv.h
+++ b/include/hisi_qm_udrv.h
@@ -5,6 +5,7 @@
#define __HZIP_DRV_H__
#include <stdbool.h>
+#include <stddef.h>
#include <pthread.h>
#include <linux/types.h>
@@ -29,10 +30,9 @@ extern "C" {
#define BYTE_BITS 8
#define BYTE_BITS_SHIFT 3
-#define __offsetof(t, m) ((size_t)(uintptr_t)&((t *)0)->m)
#define container_of(ptr, type, member) ({ \
typeof(((type *)0)->member)(*__mptr) = (ptr); \
- (type *)((char *)__mptr - __offsetof(type, member)); })
+ (type *)((char *)__mptr - offsetof(type, member)); })
enum hisi_qm_sgl_copy_dir {
COPY_SGL_TO_PBUFF,
--
2.27.0

View File

@ -0,0 +1,542 @@
From c69f4b5e4889a2311940efa0478e099b34d0084a Mon Sep 17 00:00:00 2001
From: Yang Shen <shenyang39@huawei.com>
Date: Mon, 11 Jul 2022 21:00:09 +0800
Subject: [PATCH 145/183] uadk/doc - fix text style for wd_design.md
Remove all end of line space.
Signed-off-by: Yang Shen <shenyang39@huawei.com>
---
docs/wd_design.md | 248 +++++++++++++++++++++++-----------------------
1 file changed, 124 insertions(+), 124 deletions(-)
diff --git a/docs/wd_design.md b/docs/wd_design.md
index f4151db..ba5a5b9 100644
--- a/docs/wd_design.md
+++ b/docs/wd_design.md
@@ -102,17 +102,17 @@ libwd and many other algorithm libraries for different applications.
![overview](./wd_overview.png)
-Libwd provides a wrapper of basic UACCE user space interfaces, they are a set
+Libwd provides a wrapper of basic UACCE user space interfaces, they are a set
of helper functions.
-Algorithm libraries offer a set of APIs to users, who could use this set of
-APIs to do specific task without accessing low level implementations. Algorithm
-libraries also offer a register interface to let hardware vendors to register
-their own user space driver, which could use above helper functions to do UACCE
+Algorithm libraries offer a set of APIs to users, who could use this set of
+APIs to do specific task without accessing low level implementations. Algorithm
+libraries also offer a register interface to let hardware vendors to register
+their own user space driver, which could use above helper functions to do UACCE
related work.
-So two mechanisms are provided to user application. User application could
-either access libwd or algorithm libraries. And all of these are compiled as
+So two mechanisms are provided to user application. User application could
+either access libwd or algorithm libraries. And all of these are compiled as
libraries. User application could pick up appropriate libraries to link.
This document focuses on the design of libwd and algorithm libraries.
@@ -124,42 +124,42 @@ UADK relies on SVA (Shared Virtual Address) that needs to be supported
by IOMMU.
In UADK framework, virtual address could be used by vendor driver and
-application directly. And it's actually the same virtual address, memory copy
+application directly. And it's actually the same virtual address, memory copy
could be avoided between vendor driver and application with SVA.
### UACCE user space API
As the kernel driver of UADK, UACCE offers a set of APIs between kernel
-and user space. UACCE is introduced in "uacce.rst" and "sysfs-driver-uacce"
+and user space. UACCE is introduced in "uacce.rst" and "sysfs-driver-uacce"
in kernel documents.
-Hardware accelerator registers in UACCE as a char dev. At the same time,
-hardware informations of accelerators are also exported in sysfs node. For
-example, the file path of char dev is */dev/[Accel]* and hardware informations
-are in */sys/class/uacce/[Accel]/*. The same name is shared in both devfs and
+Hardware accelerator registers in UACCE as a char dev. At the same time,
+hardware information of accelerators are also exported in sysfs node. For
+example, the file path of char dev is */dev/[Accel]* and hardware information
+are in */sys/class/uacce/[Accel]/*. The same name is shared in both devfs and
sysfs. The *Accel* is comprised of name, dash and id.
-After opening this char device once, vendor driver will get a context to access
-the resource of this accelerator device. Vendor driver can configure above
-context by ioctl of this opened fd, and mmap hardware resource, like MMIO or
+After opening this char device once, vendor driver will get a context to access
+the resource of this accelerator device. Vendor driver can configure above
+context by ioctl of this opened fd, and mmap hardware resource, like MMIO or
context to user space.
## Libwd Helper Functions
-Hardware accelerator communicates with CPU by MMIO and contexts. Libwd helper
-functions provide the interface that vendor driver could access memory from
+Hardware accelerator communicates with CPU by MMIO and contexts. Libwd helper
+functions provide the interface that vendor driver could access memory from
UADK. And libwd is only accessed by vendor driver.
### Context
-Context is a dual directional hardware communication resource between hardware
-accelerator and CPU. When a vendor driver wants to access resources of an
+Context is a dual directional hardware communication resource between hardware
+accelerator and CPU. When a vendor driver wants to access resources of an
accelerator, a context is the requisite resource.
-UACCE creates a char dev for each registered hardware device. Once the char dev
+UACCE creates a char dev for each registered hardware device. Once the char dev
is opened by UADK, a handle of context is created. Vendor driver or
application could refer to the context by the handle.
@@ -173,7 +173,7 @@ Libwd defines APIs to allocate contexts.
| Layer | Parameter | Direction | Comments |
| :-- | :-- | :-- | :-- |
-| libwd | *dev* | IN | A device in sysfs. All attrs informations in sysfs |
+| libwd | *dev* | IN | A device in sysfs. All attrs information in sysfs |
| | | | are recorded in this *struct uacce_dev*. |
Return the context handle if it succeeds. Return 0 if it fails.
@@ -187,16 +187,16 @@ Return the context handle if it succeeds. Return 0 if it fails.
### mmap
-With a context, resources on hardware accelerator could be shared to CPU.
-When vendor driver or application wants to access the resource, it needs to map
+With a context, resources on hardware accelerator could be shared to CPU.
+When vendor driver or application wants to access the resource, it needs to map
the context.
-Libwd provides API to create the mapping between virtual address and physical
-address. The mapping could cover three different types. They are MMIO (device
-MMIO region), DUS (device user share region) and SS (static share memory
+Libwd provides API to create the mapping between virtual address and physical
+address. The mapping could cover three different types. They are MMIO (device
+MMIO region), DUS (device user share region) and SS (static share memory
region).
-*wd_ctx_mmap_qfr()* and *wd_ctx_unmap_qfr()* are a pair of APIs to create and
+*wd_ctx_mmap_qfr()* and *wd_ctx_unmap_qfr()* are a pair of APIs to create and
destroy the mapping.
***void *wd_ctx_mmap_qfr(handle_t h_ctx, enum uacce_qfrt qfrt);***
@@ -222,39 +222,39 @@ Return virtual address if it succeeds. Return NULL if it fails.
*wd_ctx_unmap_qfr()* unmaps qfile region from user space.
-qfrt means queue file region type. The details could be found in UACCE kernel
+qfrt means queue file region type. The details could be found in UACCE kernel
driver.
## Algorithm Libraries
-Libwd is a fundamental layer what user relies on to access hardware. UADK also
-provides algorithm interfaces that user could get out of the hardware details,
-such as contexts. With the algorithm interface, the user application could be
+Libwd is a fundamental layer what user relies on to access hardware. UADK also
+provides algorithm interfaces that user could get out of the hardware details,
+such as contexts. With the algorithm interface, the user application could be
executed on multiple vendor's hardware.
### Compression Algorithm
-In compression algorithm, the contexts won't be accessed by user any more.
+In compression algorithm, the contexts won't be accessed by user any more.
Instead, user only need to focus on compressing and decompressing.
-In libwd, everything is based on context resource. In compression algorithm,
-everything is based on session. Session is a superset of context, since vendor
-driver may apply multiple contexts for performance. With compression algorithm
+In libwd, everything is based on context resource. In compression algorithm,
+everything is based on session. Session is a superset of context, since vendor
+driver may apply multiple contexts for performance. With compression algorithm
layer, user doesn't care how the multiple contexts are used.
#### Session in Compression Algorithm
-The session in compression algorithm records working algorithm, accelerator,
-working mode, working context, and so on. It helps to gather more informations
-and encapsulates them together. Application only needs to record the handle of
+The session in compression algorithm records working algorithm, accelerator,
+working mode, working context, and so on. It helps to gather more information
+and encapsulates them together. Application only needs to record the handle of
session.
-Whatever user wants to compress or decompress, a session is always necessary.
-Each session could only support either compression or decompression. And there
-are also some configurations of the compression/decompression. They are defined
+Whatever user wants to compress or decompress, a session is always necessary.
+Each session could only support either compression or decompression. And there
+are also some configurations of the compression/decompression. They are defined
in the *struct wd_comp_sess_setup*.
```
@@ -267,7 +267,7 @@ struct wd_comp_sess_setup {
};
```
-With *struct wd_comp_sess_setup*, a session could be created. The details of
+With *struct wd_comp_sess_setup*, a session could be created. The details of
the session is encapsuled. Only a handle is exported to user.
***handle_t wd_comp_alloc_sess(struct wd_comp_sess_setup \*setup)***
@@ -277,7 +277,7 @@ the session is encapsuled. Only a handle is exported to user.
| compress | *setup* | IN | The structure describes the configurations of |
| algorithm | | | compression or decompression. |
-If a session is created successfully, a non-zero handle value is returned.
+If a session is created successfully, a non-zero handle value is returned.
If fails to create a session, just return 0.
@@ -293,8 +293,8 @@ With the handle, a related session could be destroyed.
#### Compression & Decompression
-Compression & decompression always submit data buffer to hardware accelerator
-and collect the output. These buffer informations could be encapsulated into a
+Compression & decompression always submit data buffer to hardware accelerator
+and collect the output. These buffer information could be encapsulated into a
structure, *struct wd_comp_req*.
```
@@ -333,19 +333,19 @@ structure, *struct wd_comp_req*.
| *status* | OUT | Indicate the result. 0 means successful, and others |
| | | are error code. |
-When an application gets a session, it could request hardware accelerator to
-work in synchronous mode or asychronous mode. *cb* is the callback function
-of user application that is only used in asynchronous mode. *cb_param* is the
+When an application gets a session, it could request hardware accelerator to
+work in synchronous mode or asynchronous mode. *cb* is the callback function
+of user application that is only used in asynchronous mode. *cb_param* is the
parameter of the asynchronous callback function.
-Since synchronous or asynchronous mode is specified in *struct wd_comp_req*,
-the compression or decompression could be treated that user submits requests to
+Since synchronous or asynchronous mode is specified in *struct wd_comp_req*,
+the compression or decompression could be treated that user submits requests to
a session.
-There're two kinds of compression interface. One is block mode that the data
-in the request is not related to the previous or later data. And the other is
-stream mode that the data in the request is related to the data in the previous
-or later request. If user wants to compress/decompress large data buffer, it's
+There're two kinds of compression interface. One is block mode that the data
+in the request is not related to the previous or later data. And the other is
+stream mode that the data in the request is related to the data in the previous
+or later request. If user wants to compress/decompress large data buffer, it's
suggested to use stream mode.
@@ -358,10 +358,10 @@ suggested to use stream mode.
| | *req* | IN & | Indicate the source and destination buffer. |
| | | OUT | |
-*wd_do_comp_sync()* sends a synchronous compression/decompression request for
+*wd_do_comp_sync()* sends a synchronous compression/decompression request for
block mode.
-Return 0 if it succeeds. Return negative value if it fails. Parameter *req*
+Return 0 if it succeeds. Return negative value if it fails. Parameter *req*
contains the buffer information.
@@ -374,11 +374,11 @@ contains the buffer information.
| | *req* | IN & | Indicate the source and destination buffer. |
| | | OUT | |
-Return 0 if it succeeds. Return negative value if it fails. Parameter *req*
+Return 0 if it succeeds. Return negative value if it fails. Parameter *req*
contains the buffer information.
-*wd_do_comp_strm()* sends a synchronous compression/decompression request for
-stream mode. *wd_do_comp_strm()* just likes *wd_do_comp_sync()*, user only
+*wd_do_comp_strm()* sends a synchronous compression/decompression request for
+stream mode. *wd_do_comp_strm()* just likes *wd_do_comp_sync()*, user only
sends one request that the data buffer should be processed at one time.
@@ -391,27 +391,27 @@ sends one request that the data buffer should be processed at one time.
| | *req* | IN & | Indicate the source and destination buffer. |
| | | OUT | |
-Return 0 if it succeeds. Return negative value if it fails. Parameter *req*
+Return 0 if it succeeds. Return negative value if it fails. Parameter *req*
contains the buffer information.
-*wd_do_comp_sync2()* sends a synchronous compression/decompression request for
-stream mode. *wd_do_comp_sync2()* is the superset of *wd_do_comp_strm()*. If
-the data buffer of one request is too large to hardware accelerator, it could
+*wd_do_comp_sync2()* sends a synchronous compression/decompression request for
+stream mode. *wd_do_comp_sync2()* is the superset of *wd_do_comp_strm()*. If
+the data buffer of one request is too large to hardware accelerator, it could
split it into several requests until all data handled by hardware.
#### Asynchronous Mode
-In synchronous mode, user application is blocked until the submitted request
-is finished by hardware accelerator. Then a new request could be submitted.
-In hardware accelerator, multiple requests are always processed in a stream
-line. If a process needs to submit multiple requests to hardware, it can't
-get good performance in synchronous mode. Since the stream line isn't fully
-used. In this case, asynchronous mode could help user application to gain
+In synchronous mode, user application is blocked until the submitted request
+is finished by hardware accelerator. Then a new request could be submitted.
+In hardware accelerator, multiple requests are always processed in a stream
+line. If a process needs to submit multiple requests to hardware, it can't
+get good performance in synchronous mode. Since the stream line isn't fully
+used. In this case, asynchronous mode could help user application to gain
better performance.
-In asynchronous mode, user application gets return immediately while a request
+In asynchronous mode, user application gets return immediately while a request
is submitted.
***int wd_do_comp_async(handle_t h_sess, struct wd_comp_req \*req)***
@@ -423,11 +423,11 @@ is submitted.
| | *req* | IN & | Indicate the source and destination buffer. |
| | | OUT | |
-Return 0 if it succeeds. Return negative value if it fails. Parameter *req*
+Return 0 if it succeeds. Return negative value if it fails. Parameter *req*
contains the buffer information.
-When hardware accelerator finishes the request, the callback that
-is provided by user will be invoked. Because the compression library isn't
+When hardware accelerator finishes the request, the callback that
+is provided by user will be invoked. Because the compression library isn't
driven by interrupt, a polling function is necessary to check result.
***int wd_comp_poll(__u32 expt, __u32 \*count)***
@@ -446,8 +446,8 @@ Usually *wd_comp_poll()* could be invoked in a user defined polling thread.
#### Bind Accelerator and Driver
-Compression algorithm library requires each vendor driver providing an
-instance, *struct wd_comp_driver*. This instance represents a vendor driver.
+Compression algorithm library requires each vendor driver providing an
+instance, *struct wd_comp_driver*. This instance represents a vendor driver.
Compression algorithm library binds an vendor driver by the instance.
```
@@ -472,14 +472,14 @@ Compression algorithm library binds an vendor driver by the instance.
| | vendor driver. |
-A matched vendor driver is bound to compression algorithm library in a global
-instance, *struct wd_comp_setting*. The binding process is finished by
+A matched vendor driver is bound to compression algorithm library in a global
+instance, *struct wd_comp_setting*. The binding process is finished by
macro *WD_COMP_SET_DRIVER()*.
-*struct wd_comp_setting* binds context resources, user scheduler and vendor
-driver together. At first, user application needs to allocate contexts and to
-create scheduler instance. Then use *wd_comp_init()* to initialize vendor
+*struct wd_comp_setting* binds context resources, user scheduler and vendor
+driver together. At first, user application needs to allocate contexts and to
+create scheduler instance. Then use *wd_comp_init()* to initialize vendor
device.
***int wd_comp_init(struct wd_ctx_config \*config, struct wd_sched \*sched)***
@@ -492,7 +492,7 @@ device.
Return 0 if it succeeds. And return error number if it fails.
-In *wd_comp_init()*, context resources, user scheduler and vendor driver are
+In *wd_comp_init()*, context resources, user scheduler and vendor driver are
initialized.
@@ -504,13 +504,13 @@ In *wd_comp_uninit()*, all configurations on resources are cleared.
### Scheduler
-When algorithm layer is used, context resource is not exposed to user any more.
-So user could define a scheduler that allocate context resources, arrange
+When algorithm layer is used, context resource is not exposed to user any more.
+So user could define a scheduler that allocate context resources, arrange
proper resources to sessions and free context resources.
For user convenient, a sample scheduler is provided in UADK for reference.
-***struct wd_sched \*sample_sched_alloc(__u8 sched_type, __u8 type_num,
+***struct wd_sched \*sample_sched_alloc(__u8 sched_type, __u8 type_num,
__u8 numa_num, user_poll_func func)***
| Layer | Parameter | Direction | Comments |
@@ -535,7 +535,7 @@ Return a scheduler instance if it succeeds. And return NULL if it fails.
*sample_sched_release()* is used to release a scheduler instance.
-***int sample_sched_fill_data(const struct wd_sched \*sched, int numa_id,
+***int sample_sched_fill_data(const struct wd_sched \*sched, int numa_id,
__u8 mode, __u8 type, __u32 begin, __u32 end)***
| Layer | Parameter | Direction | Comments |
@@ -548,23 +548,23 @@ __u8 mode, __u8 type, __u32 begin, __u32 end)***
| | *begin* | Input | The index of first context in the region. |
| | *end* | Input | The index of last context in the region. |
-After context resources allocated by *wd_request_ctx()*, user could specify
-which context resources are working in the specified mode or type by
+After context resources allocated by *wd_request_ctx()*, user could specify
+which context resources are working in the specified mode or type by
*sample_sched_fill_data()*.
### Environment Variable
-According to above document, user need to care NUMA node and context number
-to make use of UADK. The configuration process is a little boring. The idea
-of Environment Variable is to make those parameters configured in user's
+According to above document, user need to care NUMA node and context number
+to make use of UADK. The configuration process is a little boring. The idea
+of Environment Variable is to make those parameters configured in user's
environment variable. It could help user to configure those parameters.
***wd_comp_env_init(void)***
-Create a registered table for algorithm that could parse different environment
-variables. With those parameters from user environment variables, allocate
+Create a registered table for algorithm that could parse different environment
+variables. With those parameters from user environment variables, allocate
related hardware resources.
@@ -583,7 +583,7 @@ Free allocated hardware resources.
| | *mode* | Input | Specify operation mode. |
| | | | 0 -- sync mode, 1 -- async mode. |
-Specify the parameters and create a pseudo environment variable. By this
+Specify the parameters and create a pseudo environment variable. By this
pseduo environment table, allocate related hardware resource.
@@ -592,7 +592,7 @@ pseduo environment table, allocate related hardware resource.
Free allocated hardware resources like ***wd_comp_env_uninit()***.
-***wd_comp_get_env_param(__u32 node, __u32 type, __u32 mode,
+***wd_comp_get_env_param(__u32 node, __u32 type, __u32 mode,
__u32 \*num, __u8 \*is_enable)***
| Layer | Parameter | Direction | Comments |
@@ -605,28 +605,28 @@ Free allocated hardware resources like ***wd_comp_env_uninit()***.
| | *is_enable* | Output | Indicate whether asynchronous polling |
| | | | mode is enabled or not. |
-Query context number that is defined in environment variable by specified
-NUMA node, type and operation mode. At the same time, asynchronous polling
+Query context number that is defined in environment variable by specified
+NUMA node, type and operation mode. At the same time, asynchronous polling
mode is queried.
## Vendor Driver
-A vendor driver is the counterpart of a hardware accelerator. Without the
-vendor driver, the accelerator can't work. *Context* could store the
-informations from the both accelerator and vendor driver.
+A vendor driver is the counterpart of a hardware accelerator. Without the
+vendor driver, the accelerator can't work. *Context* could store the
+information from the both accelerator and vendor driver.
-If an accelerator is a bit special and not be generalized, application could
-access the vendor driver directly. The interface to application is defined
+If an accelerator is a bit special and not be generalized, application could
+access the vendor driver directly. The interface to application is defined
by vendor driver itself.
-Before accessing hardware accelerator, vendor driver needs to allocate
-*context* first. In the *struct wd_ctx*, the node path of accelerator is also
-recorded. If there're multiple accelerators share a same vendor driver, vendor
+Before accessing hardware accelerator, vendor driver needs to allocate
+*context* first. In the *struct wd_ctx*, the node path of accelerator is also
+recorded. If there're multiple accelerators share a same vendor driver, vendor
driver should decide to choose which accelerator by itself.
-Application may want to track *context*. It's not good to share *context* to
+Application may want to track *context*. It's not good to share *context* to
application directly. It's better to transfer *context* to handle for security.
@@ -635,41 +635,41 @@ application directly. It's better to transfer *context* to handle for security.
### Example in user application
-Here's an example of compression in user application. User application just
+Here's an example of compression in user application. User application just
needs a few APIs to complete synchronous compression.
![comp_sync](./wd_comp_sync.png)
-Synchoronous operation means polling hardware accelerator status of each
-operation. It costs too much CPU resources on polling and causes performance
-down. User application could divide the job into multiple parts. Then it
+Synchoronous operation means polling hardware accelerator status of each
+operation. It costs too much CPU resources on polling and causes performance
+down. User application could divide the job into multiple parts. Then it
could make use of asynchronous mechanism to save time on polling.
![comp_async2](./wd_comp_async2.png)
-There's also a limitation on asynchronous operation in SVA scenario. Let's
-assume there're two output frames generated by accelerator, A frame and B
-frame. If the output is in fixed-length, then we can calculate the address of
-A and B frame in the output buffer of application. If the length of hardware
-accelerator output isn't fixed, we have to setup the temperary buffer to store
-A and B frame. Then a memory copy operation is required between temperary
-buffer and application buffer. So we use compression as a demo to explain
-asynchronous operation. It doesn't mean that we recommend to use asynchronous
+There's also a limitation on asynchronous operation in SVA scenario. Let's
+assume there're two output frames generated by accelerator, A frame and B
+frame. If the output is in fixed-length, then we can calculate the address of
+A and B frame in the output buffer of application. If the length of hardware
+accelerator output isn't fixed, we have to setup the temperary buffer to store
+A and B frame. Then a memory copy operation is required between temperary
+buffer and application buffer. So we use compression as a demo to explain
+asynchronous operation. It doesn't mean that we recommend to use asynchronous
compression.
### Vendor Driver Exposed to User Application
-Here's an example of implementing vendor driver that is exposed to application
+Here's an example of implementing vendor driver that is exposed to application
direcly.
-When user application needs to access hardware accelerator, it calls the
-interface in vendor driver. The interface is defined by vendor driver. Then
+When user application needs to access hardware accelerator, it calls the
+interface in vendor driver. The interface is defined by vendor driver. Then
vendor driver requests a context by *wd_request_ctx()*.
-With the context, vendor driver could access hardware accelerator by libwd,
-such as MMIO, memory mapping, and so on. And application has to use the
+With the context, vendor driver could access hardware accelerator by libwd,
+such as MMIO, memory mapping, and so on. And application has to use the
interface that is defined by vendor driver.
-When application doesn't want to access hardware accelerator, vendor driver
+When application doesn't want to access hardware accelerator, vendor driver
could invokes *wd_release_ctx()* to release the hardware.
--
2.27.0

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,115 @@
From 9c9794bda2151eb66432a099b028d28628a43406 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Mon, 18 Jul 2022 10:17:05 +0800
Subject: [PATCH 153/183] drv/qm: fix spin lock destroy
Spin lock must be destroyed when initialization fails.
Fix missing destroy pool lock and q_info lock.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
drv/hisi_qm_udrv.c | 49 ++++++++++++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 15 deletions(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 9eaf60c..f1468a4 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -335,6 +335,14 @@ err_out:
return ret;
}
+static void hisi_qm_clear_info(struct hisi_qp *qp)
+{
+ struct hisi_qm_queue_info *q_info = &qp->q_info;
+
+ pthread_spin_destroy(&q_info->lock);
+ hisi_qm_unset_region(qp->h_ctx, q_info);
+}
+
static int get_free_num(struct hisi_qm_queue_info *q_info)
{
/* The device should reserve one buffer. */
@@ -374,7 +382,7 @@ handle_t hisi_qm_alloc_qp(struct hisi_qm_priv *config, handle_t ctx)
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;
+ goto free_info;
ret = wd_ctx_start(qp->h_ctx);
if (ret)
@@ -390,6 +398,8 @@ handle_t hisi_qm_alloc_qp(struct hisi_qm_priv *config, handle_t ctx)
free_pool:
hisi_qm_destroy_sglpool(qp->h_sgl_pool);
+free_info:
+ hisi_qm_clear_info(qp);
out_qp:
free(qp);
out:
@@ -598,6 +608,23 @@ static struct hisi_sgl *hisi_qm_align_sgl(const void *sgl, __u32 sge_num)
return sgl_align;
}
+static void hisi_qm_free_sglpool(struct hisi_sgl_pool *pool)
+{
+ int i;
+
+ if (pool->sgl) {
+ for (i = 0; i < pool->sgl_num; i++)
+ if (pool->sgl[i])
+ free(pool->sgl[i]);
+
+ free(pool->sgl);
+ }
+
+ if (pool->sgl_align)
+ free(pool->sgl_align);
+ free(pool);
+}
+
handle_t hisi_qm_create_sglpool(__u32 sgl_num, __u32 sge_num)
{
struct hisi_sgl_pool *sgl_pool;
@@ -650,30 +677,22 @@ handle_t hisi_qm_create_sglpool(__u32 sgl_num, __u32 sge_num)
return (handle_t)sgl_pool;
err_out:
- hisi_qm_destroy_sglpool((handle_t)sgl_pool);
+ hisi_qm_free_sglpool(sgl_pool);
return (handle_t)0;
}
void hisi_qm_destroy_sglpool(handle_t sgl_pool)
{
- struct hisi_sgl_pool *pool = (struct hisi_sgl_pool *)sgl_pool;
- int i;
+ struct hisi_sgl_pool *pool;
- if (!pool) {
+ if (!sgl_pool) {
WD_ERR("invalid: sgl_pool is NULL!\n");
return;
}
- if (pool->sgl) {
- for (i = 0; i < pool->sgl_num; i++)
- if (pool->sgl[i])
- free(pool->sgl[i]);
-
- free(pool->sgl);
- }
- if (pool->sgl_align)
- free(pool->sgl_align);
- free(pool);
+ pool = (struct hisi_sgl_pool *)sgl_pool;
+ pthread_spin_destroy(&pool->lock);
+ hisi_qm_free_sglpool(pool);
}
static struct hisi_sgl *hisi_qm_sgl_pop(struct hisi_sgl_pool *pool)
--
2.27.0

View File

@ -0,0 +1,144 @@
From 2004801f44c0b6259b051e5a55bde5c54306fd63 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Mon, 18 Jul 2022 10:17:06 +0800
Subject: [PATCH 154/183] drv/qm: modify the lock for send and receive BD
If the same lock is used for BD receiving and BD sending,
the BD receiving and BD sending threads compete for lock in
asynchronous scenarios, affecting tasks performance.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
drv/hisi_qm_udrv.c | 38 +++++++++++++++++++++++++-------------
include/hisi_qm_udrv.h | 3 ++-
2 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index f1468a4..da756c4 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -322,14 +322,22 @@ 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);
- ret = pthread_spin_init(&q_info->lock, PTHREAD_PROCESS_SHARED);
+ ret = pthread_spin_init(&q_info->rv_lock, PTHREAD_PROCESS_SHARED);
if (ret) {
- WD_DEV_ERR(qp->h_ctx, "failed to init qinfo lock!\n");
+ WD_DEV_ERR(qp->h_ctx, "failed to init qinfo rv_lock!\n");
goto err_out;
}
+ ret = pthread_spin_init(&q_info->sd_lock, PTHREAD_PROCESS_SHARED);
+ if (ret) {
+ WD_DEV_ERR(qp->h_ctx, "failed to init qinfo sd_lock!\n");
+ goto err_destory_lock;
+ }
+
return 0;
+err_destory_lock:
+ pthread_spin_destroy(&q_info->rv_lock);
err_out:
hisi_qm_unset_region(qp->h_ctx, q_info);
return ret;
@@ -339,14 +347,16 @@ static void hisi_qm_clear_info(struct hisi_qp *qp)
{
struct hisi_qm_queue_info *q_info = &qp->q_info;
- pthread_spin_destroy(&q_info->lock);
+ pthread_spin_destroy(&q_info->sd_lock);
+ pthread_spin_destroy(&q_info->rv_lock);
hisi_qm_unset_region(qp->h_ctx, q_info);
}
static int get_free_num(struct hisi_qm_queue_info *q_info)
{
/* The device should reserve one buffer. */
- return (QM_Q_DEPTH - 1) - q_info->used_num;
+ return (QM_Q_DEPTH - 1) -
+ __atomic_load_n(&q_info->used_num, __ATOMIC_RELAXED);
}
int hisi_qm_get_free_sqe_num(handle_t h_qp)
@@ -441,10 +451,10 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
return -WD_HW_EACCESS;
}
- pthread_spin_lock(&q_info->lock);
+ pthread_spin_lock(&q_info->sd_lock);
free_num = get_free_num(q_info);
if (!free_num) {
- pthread_spin_unlock(&q_info->lock);
+ pthread_spin_unlock(&q_info->sd_lock);
return -WD_EBUSY;
}
@@ -455,10 +465,12 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
tail = (tail + send_num) % QM_Q_DEPTH;
q_info->db(q_info, QM_DBELL_CMD_SQ, tail, 0);
q_info->sq_tail_index = tail;
- q_info->used_num += send_num;
+
+ /* Make sure used_num is changed before the next thread gets free sqe. */
+ __atomic_add_fetch(&q_info->used_num, send_num, __ATOMIC_RELAXED);
*count = send_num;
- pthread_spin_unlock(&q_info->lock);
+ pthread_spin_unlock(&q_info->sd_lock);
return 0;
}
@@ -469,21 +481,21 @@ static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, void *resp)
struct cqe *cqe;
__u16 i, j;
- pthread_spin_lock(&q_info->lock);
+ pthread_spin_lock(&q_info->rv_lock);
i = q_info->cq_head_index;
cqe = q_info->cq_base + i * sizeof(struct cqe);
if (q_info->cqc_phase == CQE_PHASE(cqe)) {
j = CQE_SQ_HEAD_INDEX(cqe);
if (j >= QM_Q_DEPTH) {
- pthread_spin_unlock(&q_info->lock);
+ pthread_spin_unlock(&q_info->rv_lock);
WD_DEV_ERR(qp->h_ctx, "CQE_SQ_HEAD_INDEX(%u) error!\n", j);
return -WD_EIO;
}
memcpy(resp, (void *)((uintptr_t)q_info->sq_base +
j * q_info->sqe_size), q_info->sqe_size);
} else {
- pthread_spin_unlock(&q_info->lock);
+ pthread_spin_unlock(&q_info->rv_lock);
return -WD_EAGAIN;
}
@@ -500,8 +512,8 @@ static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, void *resp)
q_info->cq_head_index = i;
q_info->sq_head_index = i;
- q_info->used_num--;
- pthread_spin_unlock(&q_info->lock);
+ __atomic_sub_fetch(&q_info->used_num, 1, __ATOMIC_RELAXED);
+ pthread_spin_unlock(&q_info->rv_lock);
return 0;
}
diff --git a/include/hisi_qm_udrv.h b/include/hisi_qm_udrv.h
index 88758ac..92333ed 100644
--- a/include/hisi_qm_udrv.h
+++ b/include/hisi_qm_udrv.h
@@ -75,7 +75,8 @@ struct hisi_qm_queue_info {
__u16 hw_type;
__u32 idx;
bool cqc_phase;
- pthread_spinlock_t lock;
+ pthread_spinlock_t sd_lock;
+ pthread_spinlock_t rv_lock;
unsigned long region_size[UACCE_QFRT_MAX];
bool epoll_en;
};
--
2.27.0

View File

@ -0,0 +1,475 @@
From 746d250131c3727e658f11f37fbb0a8cb18d1b18 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 23 Jul 2022 16:50:22 +0800
Subject: [PATCH 155/183] uadk: v1: fix goto warning
1. The goto statement can only jump down.
2. Fix wd_recv return value check.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
v1/drv/hisi_rng_udrv.c | 4 +--
v1/wd.c | 33 ++++++++++---------
v1/wd_comp.c | 25 ++++++++-------
v1/wd_dh.c | 72 ++++++++++++++++++++++++++----------------
v1/wd_ecc.c | 15 ++++++---
v1/wd_rng.c | 54 +++++++++++++++++--------------
v1/wd_rsa.c | 71 +++++++++++++++++++++++++----------------
7 files changed, 164 insertions(+), 110 deletions(-)
diff --git a/v1/drv/hisi_rng_udrv.c b/v1/drv/hisi_rng_udrv.c
index a66bca5..b86a948 100644
--- a/v1/drv/hisi_rng_udrv.c
+++ b/v1/drv/hisi_rng_udrv.c
@@ -97,7 +97,6 @@ static int rng_read(struct rng_queue_info *info, struct wcrypto_rng_msg *msg)
int val;
do {
-recv_again:
val = wd_reg_read((void *)((uintptr_t)info->mmio_base +
RNG_NUM_OFFSET));
if (!val) {
@@ -105,8 +104,9 @@ recv_again:
WD_ERR("read random data timeout\n");
break;
}
+
usleep(1);
- goto recv_again;
+ continue;
}
recv_count = 0;
diff --git a/v1/wd.c b/v1/wd.c
index 8ef83c6..2c435ba 100644
--- a/v1/wd.c
+++ b/v1/wd.c
@@ -524,7 +524,7 @@ static int get_queue_from_dev(struct wd_queue *q, const struct dev_info *dev)
qinfo->fd = open(q_path, O_RDWR | O_CLOEXEC);
if (qinfo->fd == -1) {
WD_ERR("open %s failed, errno = %d!\n", q_path, errno);
- return -ENODEV;
+ return -WD_ENODEV;
}
qinfo->hw_type = dev->api;
@@ -575,23 +575,26 @@ int wd_request_queue(struct wd_queue *q)
return -WD_ENOMEM;
};
q->qinfo = dinfop + 1;
-try_again:
- ret = find_available_res(q, dinfop, NULL);
- if (ret) {
- WD_ERR("cannot find available device\n");
- goto err_with_dev;
- }
- ret = get_queue_from_dev(q, (const struct dev_info *)dinfop);
- if (ret == -WD_ENODEV) {
- try_cnt++;
- if (try_cnt < _TRY_REQUEST_TIMES) {
+ do {
+ ret = find_available_res(q, dinfop, NULL);
+ if (ret) {
+ WD_ERR("cannot find available device\n");
+ goto err_with_dev;
+ }
+
+ ret = get_queue_from_dev(q, (const struct dev_info *)dinfop);
+ if (!ret) {
+ break;
+ } else {
+ if (try_cnt++ > _TRY_REQUEST_TIMES) {
+ WD_ERR("fail to get queue!\n");
+ goto err_with_dev;
+ }
+
memset(dinfop, 0, sizeof(*dinfop));
- goto try_again;
}
- WD_ERR("fail to get queue!\n");
- goto err_with_dev;
- }
+ } while (true);
ret = drv_open(q);
if (ret) {
diff --git a/v1/wd_comp.c b/v1/wd_comp.c
index 33546d4..2f1b8bd 100644
--- a/v1/wd_comp.c
+++ b/v1/wd_comp.c
@@ -243,19 +243,22 @@ int wcrypto_do_comp(void *ctx, struct wcrypto_comp_op_data *opdata, void *tag)
return ret;
resp = (void *)(uintptr_t)cctx->ctx_id;
-recv_again:
- ret = wd_recv(cctx->q, (void **)&resp);
- if (ret == -WD_HW_EACCESS) {
- WD_ERR("wd_recv hw err!\n");
- goto err_put_cookie;
- } else if (ret == 0) {
- if (++recv_count > MAX_RETRY_COUNTS) {
- WD_ERR("wd_recv timeout fail!\n");
- ret = -ETIMEDOUT;
+
+ do {
+ ret = wd_recv(cctx->q, (void **)&resp);
+ if (ret > 0) {
+ break;
+ } else if (!ret) {
+ if (++recv_count > MAX_RETRY_COUNTS) {
+ WD_ERR("wd_recv timeout fail!\n");
+ ret = -ETIMEDOUT;
+ goto err_put_cookie;
+ }
+ } else {
+ WD_ERR("failed to recv msg: ret = %d!\n", ret);
goto err_put_cookie;
}
- goto recv_again;
- }
+ } while (true);
opdata->consumed = resp->in_cons;
opdata->produced = resp->produced;
diff --git a/v1/wd_dh.c b/v1/wd_dh.c
index 49f52d9..1164f2c 100644
--- a/v1/wd_dh.c
+++ b/v1/wd_dh.c
@@ -307,6 +307,31 @@ static int do_dh_prepare(struct wcrypto_dh_op_data *opdata,
return 0;
}
+static int dh_send(struct wcrypto_dh_ctx *ctx, struct wcrypto_dh_msg *req)
+{
+ uint32_t tx_cnt = 0;
+ int ret;
+
+ do {
+ ret = wd_send(ctx->q, req);
+ if (!ret) {
+ break;
+ } else if (ret == -WD_EBUSY) {
+ if (tx_cnt++ > DH_RESEND_CNT) {
+ WD_ERR("do dh send cnt %u, exit!\n", tx_cnt);
+ break;
+ }
+
+ usleep(1);
+ } else {
+ WD_ERR("do dh wd_send err!\n");
+ break;
+ }
+ } while (true);
+
+ return ret;
+}
+
int wcrypto_do_dh(void *ctx, struct wcrypto_dh_op_data *opdata, void *tag)
{
struct wcrypto_dh_msg *resp = NULL;
@@ -314,46 +339,39 @@ int wcrypto_do_dh(void *ctx, struct wcrypto_dh_op_data *opdata, void *tag)
struct wcrypto_dh_cookie *cookie;
struct wcrypto_dh_msg *req;
uint32_t rx_cnt = 0;
- uint32_t tx_cnt = 0;
int ret;
ret = do_dh_prepare(opdata, &cookie, ctxt, &req, tag);
if (unlikely(ret))
return ret;
-send_again:
- ret = wd_send(ctxt->q, req);
- if (ret == -WD_EBUSY) {
- usleep(1);
- if (tx_cnt++ < DH_RESEND_CNT)
- goto send_again;
- else {
- WD_ERR("do dh send cnt %u, exit!\n", tx_cnt);
- goto fail_with_cookie;
- }
- } else if (unlikely(ret)) {
- WD_ERR("do dh wd_send err!\n");
+ ret = dh_send(ctxt, req);
+ if (unlikely(ret))
goto fail_with_cookie;
- }
if (tag)
return ret;
resp = (void *)(uintptr_t)ctxt->ctx_id;
-recv_again:
- ret = wd_recv(ctxt->q, (void **)&resp);
- if (!ret) {
- if (unlikely(rx_cnt++ >= DH_RECV_MAX_CNT)) {
- WD_ERR("failed to receive: timeout!\n");
- return -WD_ETIMEDOUT;
- } else if (balance > DH_BALANCE_THRHD) {
- usleep(1);
+
+ do {
+ ret = wd_recv(ctxt->q, (void **)&resp);
+ if (ret > 0) {
+ break;
+ } else if (!ret) {
+ if (unlikely(rx_cnt++ >= DH_RECV_MAX_CNT)) {
+ WD_ERR("failed to receive: timeout!\n");
+ ret = -WD_ETIMEDOUT;
+ goto fail_with_cookie;
+ }
+
+ if (balance > DH_BALANCE_THRHD)
+ usleep(1);
+ } else {
+ WD_ERR("do dh wd_recv err!\n");
+ goto fail_with_cookie;
}
- goto recv_again;
- } else if (unlikely(ret < 0)) {
- WD_ERR("do dh wd_recv err!\n");
- goto fail_with_cookie;
- }
+ } while (true);
balance = rx_cnt;
opdata->pri = (void *)resp->out;
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c
index 58dabfc..4f9ec53 100644
--- a/v1/wd_ecc.c
+++ b/v1/wd_ecc.c
@@ -1523,17 +1523,20 @@ static int ecc_send(struct wcrypto_ecc_ctx *ctx, struct wcrypto_ecc_msg *req)
do {
ret = wd_send(ctx->q, req);
- if (ret == -WD_EBUSY) {
+ if (!ret) {
+ break;
+ } else if (ret == -WD_EBUSY) {
if (tx_cnt++ >= ECC_RESEND_CNT) {
WD_ERR("failed to send: retry exit!\n");
break;
}
+
usleep(1);
} else if (unlikely(ret)) {
WD_ERR("failed to send: send error = %d!\n", ret);
break;
}
- } while (ret);
+ } while (true);
return ret;
}
@@ -1549,7 +1552,9 @@ static int ecc_sync_recv(struct wcrypto_ecc_ctx *ctx,
do {
ret = wd_recv(ctx->q, (void **)&resp);
- if (!ret) {
+ if (ret > 0) {
+ break;
+ } else if (!ret) {
if (rx_cnt++ >= ECC_RECV_MAX_CNT) {
WD_ERR("failed to recv: timeout!\n");
return -WD_ETIMEDOUT;
@@ -1557,11 +1562,11 @@ static int ecc_sync_recv(struct wcrypto_ecc_ctx *ctx,
if (balance > ECC_BALANCE_THRHD)
usleep(1);
- } else if (unlikely(ret < 0)) {
+ } else {
WD_ERR("failed to recv: error = %d!\n", ret);
return ret;
}
- } while (!ret);
+ } while (true);
balance = rx_cnt;
opdata->out = resp->out;
diff --git a/v1/wd_rng.c b/v1/wd_rng.c
index 7b3bda3..2077578 100644
--- a/v1/wd_rng.c
+++ b/v1/wd_rng.c
@@ -174,7 +174,7 @@ int wcrypto_rng_poll(struct wd_queue *q, unsigned int num)
if (!ret)
break;
- if (ret == -WD_EINVAL) {
+ if (ret < 0) {
WD_ERR("recv err at trng poll!\n");
return ret;
}
@@ -241,37 +241,45 @@ int wcrypto_do_rng(void *ctx, struct wcrypto_rng_op_data *opdata, void *tag)
if (ret)
return ret;
-send_again:
- ret = wd_send(ctxt->q, req);
- if (ret) {
- if (++tx_cnt > RNG_RESEND_CNT) {
- WD_ERR("do trng send cnt %u, exit!\n", tx_cnt);
+ do {
+ ret = wd_send(ctxt->q, req);
+ if (!ret) {
+ break;
+ } else if (ret == -WD_EBUSY) {
+ if (++tx_cnt > RNG_RESEND_CNT) {
+ WD_ERR("do trng send cnt %u, exit!\n", tx_cnt);
+ goto fail_with_cookie;
+ }
+
+ usleep(1);
+ } else {
+ WD_ERR("do rng wd_send err!\n");
goto fail_with_cookie;
}
- usleep(1);
- goto send_again;
- }
+ } while (true);
if (tag)
return ret;
resp = (void *)(uintptr_t)ctxt->ctx_id;
-recv_again:
- ret = wd_recv(ctxt->q, (void **)&resp);
- if (!ret) {
- if (++rx_cnt > RNG_RECV_CNT) {
- WD_ERR("do trng recv cnt %u, exit!\n", rx_cnt);
- ret = -WD_ETIMEDOUT;
+
+ do {
+ ret = wd_recv(ctxt->q, (void **)&resp);
+ if (ret > 0) {
+ break;
+ } else if (!ret) {
+ if (++rx_cnt > RNG_RECV_CNT) {
+ WD_ERR("do trng recv cnt %u, exit!\n", rx_cnt);
+ ret = -WD_ETIMEDOUT;
+ goto fail_with_cookie;
+ }
+
+ usleep(1);
+ } else {
+ WD_ERR("do trng recv err!\n");
goto fail_with_cookie;
}
- usleep(1);
- goto recv_again;
- }
-
- if (ret < 0) {
- WD_ERR("do trng recv err!\n");
- goto fail_with_cookie;
- }
+ } while (true);
opdata->out_bytes = resp->out_bytes;
ret = WD_SUCCESS;
diff --git a/v1/wd_rsa.c b/v1/wd_rsa.c
index 6ba29d7..f0cdda7 100644
--- a/v1/wd_rsa.c
+++ b/v1/wd_rsa.c
@@ -970,6 +970,31 @@ static int do_rsa_prepare(struct wcrypto_rsa_ctx *ctxt,
return 0;
}
+static int rsa_send(struct wcrypto_rsa_ctx *ctx, struct wcrypto_rsa_msg *req)
+{
+ uint32_t tx_cnt = 0;
+ int ret;
+
+ do {
+ ret = wd_send(ctx->q, req);
+ if (!ret) {
+ break;
+ } else if (ret == -WD_EBUSY) {
+ if (tx_cnt++ > RSA_RESEND_CNT) {
+ WD_ERR("do rsa send cnt %u, exit!\n", tx_cnt);
+ break;
+ }
+
+ usleep(1);
+ } else {
+ WD_ERR("do rsa wd_send err!\n");
+ break;
+ }
+ } while (true);
+
+ return ret;
+}
+
int wcrypto_do_rsa(void *ctx, struct wcrypto_rsa_op_data *opdata, void *tag)
{
struct wcrypto_rsa_msg *resp = NULL;
@@ -977,46 +1002,38 @@ int wcrypto_do_rsa(void *ctx, struct wcrypto_rsa_op_data *opdata, void *tag)
struct wcrypto_rsa_cookie *cookie;
struct wcrypto_rsa_msg *req;
uint32_t rx_cnt = 0;
- uint32_t tx_cnt = 0;
int ret;
ret = do_rsa_prepare(ctxt, opdata, &cookie, &req, tag);
if (unlikely(ret))
return ret;
-send_again:
- ret = wd_send(ctxt->q, req);
- if (ret == -WD_EBUSY) {
- usleep(1);
- if (tx_cnt++ < RSA_RESEND_CNT)
- goto send_again;
- else {
- WD_ERR("do rsa send cnt %u, exit!\n", tx_cnt);
- goto fail_with_cookie;
- }
- } else if (unlikely(ret)) {
- WD_ERR("do rsa wd_send err!\n");
+ ret = rsa_send(ctxt, req);
+ if (unlikely(ret))
goto fail_with_cookie;
- }
if (tag)
return ret;
resp = (void *)(uintptr_t)ctxt->ctx_id;
-recv_again:
- ret = wd_recv(ctxt->q, (void **)&resp);
- if (!ret) {
- if (unlikely(rx_cnt++ >= RSA_RECV_MAX_CNT)) {
- WD_ERR("failed to recv: timeout!\n");
- return -WD_ETIMEDOUT;
- } else if (balance > RSA_BALANCE_THRHD) {
- usleep(1);
+ do {
+ ret = wd_recv(ctxt->q, (void **)&resp);
+ if (ret > 0) {
+ break;
+ } else if (!ret) {
+ if (unlikely(rx_cnt++ >= RSA_RECV_MAX_CNT)) {
+ WD_ERR("failed to recv: timeout!\n");
+ ret = -WD_ETIMEDOUT;
+ goto fail_with_cookie;
+ }
+
+ if (balance > RSA_BALANCE_THRHD)
+ usleep(1);
+ } else {
+ WD_ERR("do rsa wd_recv err!\n");
+ goto fail_with_cookie;
}
- goto recv_again;
- } else if (unlikely(ret < 0)) {
- WD_ERR("do rsa wd_recv err!\n");
- goto fail_with_cookie;
- }
+ } while (true);
balance = rx_cnt;
opdata->out = (void *)resp->out;
--
2.27.0

View File

@ -0,0 +1,68 @@
From 28904d5266bc827b05ac1beb5e819878b56fc3f2 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 23 Jul 2022 16:50:23 +0800
Subject: [PATCH 156/183] uadk: fix comment blank
Use 1 blank space(' ') instead of TAB('\t')
between the right comment and the previous code.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
v1/drv/dummy_drv.c | 4 ++--
v1/internal/dummy_hw_usr_if.h | 2 +-
v1/wd_util.h | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/v1/drv/dummy_drv.c b/v1/drv/dummy_drv.c
index 206fa2b..f551b79 100644
--- a/v1/drv/dummy_drv.c
+++ b/v1/drv/dummy_drv.c
@@ -30,8 +30,8 @@
struct dummy_q_priv {
int ver;
- int head; /* queue head */
- int resp_tail; /* resp tail in the queue */
+ int head; /* queue head */
+ int resp_tail; /* resp tail in the queue */
/* so in the user side: when add to queue, head++ but don't exceed resp_tail.
* when get back from the queue, resp_tail++ but don't exceed tail.
* in the kernel side: when get from queue, tail++ but don't exceed head-1 */
diff --git a/v1/internal/dummy_hw_usr_if.h b/v1/internal/dummy_hw_usr_if.h
index c35f75d..3a9df48 100644
--- a/v1/internal/dummy_hw_usr_if.h
+++ b/v1/internal/dummy_hw_usr_if.h
@@ -35,7 +35,7 @@
/* the format of the device io space, which is of drv */
struct dummy_hw_queue_reg {
- char hw_tag[DUMMY_HW_TAG_SZ]; /* should be "WDDUMMY\0" */
+ char hw_tag[DUMMY_HW_TAG_SZ]; /* should be "WDDUMMY\0" */
struct ring_bd ring[Q_BDS]; /* in real hardware, this is good to be
in memory space, and will be fast
for communication. here we keep it
diff --git a/v1/wd_util.h b/v1/wd_util.h
index d1642f8..e69b5f9 100644
--- a/v1/wd_util.h
+++ b/v1/wd_util.h
@@ -359,7 +359,7 @@ struct wcrypto_ecc_out {
static inline void wd_reg_write(void *reg_addr, uint32_t value)
{
*((uint32_t *)reg_addr) = value;
- wmb(); /* load fence */
+ wmb(); /* load fence */
}
static inline uint32_t wd_reg_read(void *reg_addr)
@@ -367,7 +367,7 @@ static inline uint32_t wd_reg_read(void *reg_addr)
uint32_t temp;
temp = *((uint32_t *)reg_addr);
- rmb(); /* load fence */
+ rmb(); /* load fence */
return temp;
}
--
2.27.0

View File

@ -0,0 +1,155 @@
From 190cfeed8f1970f886e2fa3d9a7f45ad0a779966 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 23 Jul 2022 16:50:24 +0800
Subject: [PATCH 157/183] uadk: fix different name in declaration and
definition
Fix static check warnings, which are described like this, "
Parameter 2 'void ** resp' of function 'dummy_get_from_dio_q'
has different name than previous declaration 'void ** req'".
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
v1/drv/dummy_drv.h | 2 +-
v1/wd_aead.c | 10 +++++-----
v1/wd_digest.c | 12 ++++++------
wd_ecc.c | 6 +++---
4 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/v1/drv/dummy_drv.h b/v1/drv/dummy_drv.h
index 7dca1a1..392a47e 100644
--- a/v1/drv/dummy_drv.h
+++ b/v1/drv/dummy_drv.h
@@ -28,7 +28,7 @@
int dummy_set_queue_dio(struct wd_queue *q);
void dummy_unset_queue_dio(struct wd_queue *q);
int dummy_add_to_dio_q(struct wd_queue *q, void **req, __u32 num);
-int dummy_get_from_dio_q(struct wd_queue *q, void **req, __u32 num);
+int dummy_get_from_dio_q(struct wd_queue *q, void **resp, __u32 num);
void dummy_flush(struct wd_queue *q);
void *dummy_reserve_mem(struct wd_queue *q, size_t size);
diff --git a/v1/wd_aead.c b/v1/wd_aead.c
index 4ff690a..4028895 100644
--- a/v1/wd_aead.c
+++ b/v1/wd_aead.c
@@ -566,7 +566,7 @@ static int param_check(struct wcrypto_aead_ctx *a_ctx,
return WD_SUCCESS;
}
-int wcrypto_burst_aead(void *a_ctx, struct wcrypto_aead_op_data **a_opdata,
+int wcrypto_burst_aead(void *a_ctx, struct wcrypto_aead_op_data **opdata,
void **tag, __u32 num)
{
struct wcrypto_aead_cookie *cookies[WCRYPTO_MAX_BURST_NUM] = { NULL };
@@ -575,7 +575,7 @@ int wcrypto_burst_aead(void *a_ctx, struct wcrypto_aead_op_data **a_opdata,
__u32 i;
int ret;
- if (param_check(ctxt, a_opdata, tag, num))
+ if (param_check(ctxt, opdata, tag, num))
return -WD_EINVAL;
ret = wd_get_cookies(&ctxt->pool, (void **)cookies, num);
@@ -585,13 +585,13 @@ int wcrypto_burst_aead(void *a_ctx, struct wcrypto_aead_op_data **a_opdata,
}
for (i = 0; i < num; i++) {
- cookies[i]->tag.priv = a_opdata[i]->priv;
+ cookies[i]->tag.priv = opdata[i]->priv;
req[i] = &cookies[i]->msg;
if (tag)
cookies[i]->tag.wcrypto_tag.tag = tag[i];
}
- ret = aead_requests_init(req, a_opdata, ctxt, num);
+ ret = aead_requests_init(req, opdata, ctxt, num);
if (unlikely(ret))
goto fail_with_cookies;
@@ -604,7 +604,7 @@ int wcrypto_burst_aead(void *a_ctx, struct wcrypto_aead_op_data **a_opdata,
if (tag)
return ret;
- ret = aead_recv_sync(ctxt, a_opdata, num);
+ ret = aead_recv_sync(ctxt, opdata, num);
fail_with_send:
aead_requests_uninit(req, ctxt, num);
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
index 14df736..557ad18 100644
--- a/v1/wd_digest.c
+++ b/v1/wd_digest.c
@@ -351,7 +351,7 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx,
return WD_SUCCESS;
}
-int wcrypto_burst_digest(void *d_ctx, struct wcrypto_digest_op_data **d_opdata,
+int wcrypto_burst_digest(void *d_ctx, struct wcrypto_digest_op_data **opdata,
void **tag, __u32 num)
{
struct wcrypto_digest_cookie *cookies[WCRYPTO_MAX_BURST_NUM] = {NULL};
@@ -360,7 +360,7 @@ int wcrypto_burst_digest(void *d_ctx, struct wcrypto_digest_op_data **d_opdata,
__u32 i;
int ret;
- if (param_check(ctxt, d_opdata, tag, num))
+ if (param_check(ctxt, opdata, tag, num))
return -WD_EINVAL;
ret = wd_get_cookies(&ctxt->pool, (void **)cookies, num);
@@ -370,15 +370,15 @@ int wcrypto_burst_digest(void *d_ctx, struct wcrypto_digest_op_data **d_opdata,
}
for (i = 0; i < num; i++) {
- cookies[i]->tag.priv = d_opdata[i]->priv;
+ cookies[i]->tag.priv = opdata[i]->priv;
req[i] = &cookies[i]->msg;
if (tag)
cookies[i]->tag.wcrypto_tag.tag = tag[i];
}
- digest_requests_init(req, d_opdata, d_ctx, num);
+ digest_requests_init(req, opdata, d_ctx, num);
/* when num is 1, wcrypto_burst_digest supports stream mode */
- if (num == 1 && !d_opdata[0]->has_next) {
+ if (num == 1 && !opdata[0]->has_next) {
cookies[0]->tag.long_data_len = ctxt->io_bytes;
ctxt->io_bytes = 0;
}
@@ -392,7 +392,7 @@ int wcrypto_burst_digest(void *d_ctx, struct wcrypto_digest_op_data **d_opdata,
if (tag)
return ret;
- ret = digest_recv_sync(ctxt, d_opdata, num);
+ ret = digest_recv_sync(ctxt, opdata, num);
fail_with_cookies:
wd_put_cookies(&ctxt->pool, (void **)cookies, num);
diff --git a/wd_ecc.c b/wd_ecc.c
index 4cf287b..60a320b 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -1277,7 +1277,7 @@ struct wd_ecc_out *wd_ecxdh_new_out(handle_t sess)
return create_ecc_out((struct wd_ecc_sess *)sess, ECDH_OUT_PARAM_NUM);
}
-void wd_ecxdh_get_out_params(struct wd_ecc_out *out, struct wd_ecc_point **key)
+void wd_ecxdh_get_out_params(struct wd_ecc_out *out, struct wd_ecc_point **pbk)
{
struct wd_ecc_dh_out *dh_out = (void *)out;
@@ -1286,8 +1286,8 @@ void wd_ecxdh_get_out_params(struct wd_ecc_out *out, struct wd_ecc_point **key)
return;
}
- if (key)
- *key = &dh_out->out;
+ if (pbk)
+ *pbk = &dh_out->out;
}
void wd_ecc_del_in(handle_t sess, struct wd_ecc_in *in)
--
2.27.0

View File

@ -0,0 +1,126 @@
From 45be6faf148734bfcfe5ea1536cae3e4a434cd84 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 23 Jul 2022 16:50:25 +0800
Subject: [PATCH 158/183] uadk: fix pointer parameters are not checked
Pointer parameters of the "wd_xxx_poll" function are not checked
whether the pointer is null. Param: "count".
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_aead.c | 7 ++++++-
wd_cipher.c | 5 +++++
wd_dh.c | 5 +++++
wd_digest.c | 5 +++++
wd_ecc.c | 5 +++++
wd_rsa.c | 5 +++++
6 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/wd_aead.c b/wd_aead.c
index d43ace1..a1bdb12 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -611,7 +611,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
__u32 tmp = expt;
int ret;
- if (!count) {
+ if (unlikely(!count)) {
WD_ERR("invalid: aead poll ctx input param is NULL!\n");
return -WD_EINVAL;
}
@@ -658,6 +658,11 @@ 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(!count)) {
+ WD_ERR("invalid: aead poll input param is NULL!\n");
+ return -WD_EINVAL;
+ }
+
return sched->poll_policy(h_ctx, expt, count);
}
diff --git a/wd_cipher.c b/wd_cipher.c
index 3d00598..884c933 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -568,6 +568,11 @@ 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(!count)) {
+ WD_ERR("invalid: cipher poll input param is NULL!\n");
+ return -WD_EINVAL;
+ }
+
return sched->poll_policy(h_ctx, expt, count);
}
diff --git a/wd_dh.c b/wd_dh.c
index 461f04e..41c4a2a 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -348,6 +348,11 @@ int wd_dh_poll(__u32 expt, __u32 *count)
{
handle_t h_sched_ctx = wd_dh_setting.sched.h_sched_ctx;
+ if (unlikely(!count)) {
+ WD_ERR("invalid: dh poll count is NULL!\n");
+ return -WD_EINVAL;
+ }
+
return wd_dh_setting.sched.poll_policy(h_sched_ctx, expt, count);
}
diff --git a/wd_digest.c b/wd_digest.c
index 43b4bc5..3e64168 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -470,6 +470,11 @@ 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(!count)) {
+ WD_ERR("invalid: digest poll input param is NULL!\n");
+ return -WD_EINVAL;
+ }
+
return sched->poll_policy(h_ctx, expt, count);
}
diff --git a/wd_ecc.c b/wd_ecc.c
index 60a320b..fed02cb 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -2176,6 +2176,11 @@ int wd_ecc_poll(__u32 expt, __u32 *count)
{
handle_t h_sched_sess = wd_ecc_setting.sched.h_sched_ctx;
+ if (unlikely(!count)) {
+ WD_ERR("invalid: ecc poll param count is NULL!\n");
+ return -WD_EINVAL;
+ }
+
return wd_ecc_setting.sched.poll_policy(h_sched_sess, expt, count);
}
diff --git a/wd_rsa.c b/wd_rsa.c
index e76da09..89d3450 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -404,6 +404,11 @@ int wd_rsa_poll(__u32 expt, __u32 *count)
{
handle_t h_sched_ctx = wd_rsa_setting.sched.h_sched_ctx;
+ if (unlikely(!count)) {
+ WD_ERR("invalid: rsa poll count is NULL!\n");
+ return -WD_EINVAL;
+ }
+
return wd_rsa_setting.sched.poll_policy(h_sched_ctx, expt, count);
}
--
2.27.0

View File

@ -0,0 +1,69 @@
From 2563892aaab90d594b70251253f67efce378c491 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 23 Jul 2022 16:50:26 +0800
Subject: [PATCH 159/183] uadk: fix cqe phase
1.Use explicit members from struct cqe is better
2.Use le16_to_cpu to process a __le16 data
This changes sync from kernel patch:
crypto: hisilicon - fix endianness verification problem of QM
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
drv/hisi_qm_udrv.c | 5 +++--
v1/drv/hisi_qm_udrv.h | 7 ++++---
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index da756c4..39c99d1 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright 2020-2021 Huawei Technologies Co.,Ltd. All rights reserved. */
+#include <asm/byteorder.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
@@ -19,8 +20,8 @@
#define QM_DBELL_SQN_MASK 0x3ff
#define QM_DBELL_CMD_MASK 0xf
#define QM_Q_DEPTH 1024
-#define CQE_PHASE(cq) (((*((__u32 *)(cq) + 3)) >> 16) & 0x1)
-#define CQE_SQ_HEAD_INDEX(cq) ((*((__u32 *)(cq) + 2)) & 0xffff)
+#define CQE_PHASE(cq) (__le16_to_cpu((cq)->w7) & 0x1)
+#define CQE_SQ_HEAD_INDEX(cq) (__le16_to_cpu((cq)->sq_head) & 0xffff)
#define VERSION_ID_SHIFT 9
#define UACCE_CMD_QM_SET_QP_CTX _IOWR('H', 10, struct hisi_qp_ctx)
diff --git a/v1/drv/hisi_qm_udrv.h b/v1/drv/hisi_qm_udrv.h
index 588da00..0d40d86 100644
--- a/v1/drv/hisi_qm_udrv.h
+++ b/v1/drv/hisi_qm_udrv.h
@@ -17,6 +17,7 @@
#ifndef __HISI_QM_DRV_H__
#define __HISI_QM_DRV_H__
+#include <asm/byteorder.h>
#include <linux/types.h>
#include "config.h"
#include "v1/wd.h"
@@ -69,9 +70,9 @@
/* cqe shift */
-#define CQE_PHASE(cq) (((*((__u32 *)(cq) + 3)) >> 16) & 0x1)
-#define CQE_SQ_NUM(cq) ((*((__u32 *)(cq) + 2)) >> 16)
-#define CQE_SQ_HEAD_INDEX(cq) ((*((__u32 *)(cq) + 2)) & 0xffff)
+#define CQE_PHASE(cq) (__le16_to_cpu((cq)->w7) & 0x1)
+#define CQE_SQ_NUM(cq) __le16_to_cpu((cq)->sq_num)
+#define CQE_SQ_HEAD_INDEX(cq) (__le16_to_cpu((cq)->sq_head) & 0xffff)
/* wd sgl len */
#define WD_SGL_PAD0_LEN 2
--
2.27.0

View File

@ -0,0 +1,92 @@
From e4459ddbe6b9423710208d0b086cd7a491aa0f55 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 23 Jul 2022 16:50:27 +0800
Subject: [PATCH 160/183] uadk: v1: fix include file order
Includes are not sorted properly. Order-ref: standard library headers,
OS library headers, and project-specific headers.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
v1/drv/dummy_drv.c | 2 +-
v1/wd_aead.c | 2 +-
v1/wd_dh.c | 2 +-
v1/wd_digest.c | 2 +-
v1/wd_ecc.c | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/v1/drv/dummy_drv.c b/v1/drv/dummy_drv.c
index f551b79..b1c1968 100644
--- a/v1/drv/dummy_drv.c
+++ b/v1/drv/dummy_drv.c
@@ -18,9 +18,9 @@
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
-#include <linux/types.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
+#include <linux/types.h>
#include "v1/wd_util.h"
#include "dummy_drv.h"
diff --git a/v1/wd_aead.c b/v1/wd_aead.c
index 4028895..ab1250a 100644
--- a/v1/wd_aead.c
+++ b/v1/wd_aead.c
@@ -23,8 +23,8 @@
#include <sys/mman.h>
#include "wd.h"
-#include "wd_aead.h"
#include "wd_util.h"
+#include "wd_aead.h"
#define MAX_AEAD_KEY_SIZE 64
#define MAX_AEAD_MAC_SIZE 64
diff --git a/v1/wd_dh.c b/v1/wd_dh.c
index 1164f2c..25483c1 100644
--- a/v1/wd_dh.c
+++ b/v1/wd_dh.c
@@ -23,8 +23,8 @@
#include <sys/mman.h>
#include "wd.h"
-#include "wd_dh.h"
#include "wd_util.h"
+#include "wd_dh.h"
#define WD_DH_G2 2
#define DH_BALANCE_THRHD 1280
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
index 557ad18..7b01b14 100644
--- a/v1/wd_digest.c
+++ b/v1/wd_digest.c
@@ -23,8 +23,8 @@
#include <sys/mman.h>
#include "wd.h"
-#include "wd_digest.h"
#include "wd_util.h"
+#include "wd_digest.h"
#define MAX_HMAC_KEY_SIZE 128
#define MAX_DIGEST_RETRY_CNT 20000000
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c
index 4f9ec53..d3f6694 100644
--- a/v1/wd_ecc.c
+++ b/v1/wd_ecc.c
@@ -23,9 +23,9 @@
#include <sys/mman.h>
#include "wd.h"
+#include "wd_util.h"
#include "internal/wd_ecc_curve.h"
#include "wd_ecc.h"
-#include "wd_util.h"
#define ECC_BALANCE_THRHD 1280
#define ECC_RECV_MAX_CNT 60000000
--
2.27.0

View File

@ -0,0 +1,45 @@
From 8b19ff4c4b243ca2b0adf9c19bc20c3b83c9c4b1 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 23 Jul 2022 16:50:28 +0800
Subject: [PATCH 161/183] uadk: fix BufferOverFlow
Fix that read or write outside of array bounds
of buf if string not ended with 0.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_mempool.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/wd_mempool.c b/wd_mempool.c
index d9259de..6143a69 100644
--- a/wd_mempool.c
+++ b/wd_mempool.c
@@ -624,7 +624,7 @@ static int get_value_from_sysfs(const char *path, ssize_t path_size)
char buf[MAX_ATTR_STR_SIZE];
char *ptrRet = NULL;
ssize_t size;
- int fd;
+ int fd, ret;
ptrRet = realpath(path, dev_path);
if (!ptrRet) {
@@ -645,7 +645,14 @@ static int get_value_from_sysfs(const char *path, ssize_t path_size)
}
close(fd);
- return (int)strtol(buf, NULL, 10);
+
+ ret = strtol(buf, NULL, 10);
+ if (errno == ERANGE) {
+ WD_ERR("failed to strtol %s, out of range!\n", buf);
+ goto err_read;
+ }
+
+ return ret;
err_read:
close(fd);
--
2.27.0

View File

@ -0,0 +1,44 @@
From e3f943d0974bee65c8ab6ca16eff541a20a4fc5e Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 23 Jul 2022 16:50:29 +0800
Subject: [PATCH 162/183] uadk: fix macro argument warning
macro argument 'array' should be enclosed in parentheses.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
include/wd_util.h | 4 ++--
v1/wd_ecc.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/wd_util.h b/include/wd_util.h
index 83a9684..83ac5f8 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -18,8 +18,8 @@ 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++)
+ for ((i) = 0, (config_numa) = (config)->config_per_numa; \
+ (i) < (config)->numa_num; (config_numa)++, (i)++)
struct wd_async_msg_pool {
struct msg_pool *pools;
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c
index d3f6694..dae5e23 100644
--- a/v1/wd_ecc.c
+++ b/v1/wd_ecc.c
@@ -37,7 +37,7 @@
#define ECC_MAX_OUT_NUM 4
#define CURVE_PARAM_NUM 6
#define ECC_POINT_NUM 2
-#define WD_ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
+#define WD_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
#define MAX_CURVE_SIZE (ECC_MAX_KEY_SIZE * CURVE_PARAM_NUM)
#define MAX_HASH_LENS ECC_MAX_KEY_SIZE
#define SM2_KEY_SIZE 32
--
2.27.0

View File

@ -0,0 +1,67 @@
From c8025681d15bdfdee9cc00796b68f02f1cf85d67 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 23 Jul 2022 16:50:30 +0800
Subject: [PATCH 163/183] uadk: driver init should check ctx num
If 'i' is >= field 'ctx_num', then qp is still 0,
it will results in a dereference of a null pointer
when hisi_sec_driver_adapter use qp's member.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
drv/hisi_comp.c | 5 +++++
drv/hisi_hpre.c | 5 +++++
drv/hisi_sec.c | 5 +++++
3 files changed, 15 insertions(+)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index 69785e9..c940c3f 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -780,6 +780,11 @@ static int hisi_zip_init(struct wd_ctx_config_internal *config, void *priv)
handle_t h_ctx;
int i;
+ if (!config->ctx_num) {
+ WD_ERR("invalid: zip init config ctx num is 0!\n");
+ return -WD_EINVAL;
+ }
+
memcpy(&zip_ctx->config, config, sizeof(struct wd_ctx_config_internal));
/* allocate qp for each context */
for (i = 0; i < config->ctx_num; i++) {
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index d503d84..4c6e532 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -447,6 +447,11 @@ static int hpre_init(struct wd_ctx_config_internal *config, void *priv, const ch
handle_t h_ctx, h_qp;
int i, j;
+ if (!config->ctx_num) {
+ WD_ERR("invalid: hpre init config ctx num is 0!\n");
+ return -WD_EINVAL;
+ }
+
memcpy(&hpre_ctx->config, config, sizeof(*config));
/* allocate qp for each context */
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 5865ffb..858dbb6 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -2341,6 +2341,11 @@ int hisi_sec_init(struct wd_ctx_config_internal *config, void *priv)
handle_t h_ctx;
int i, j;
+ if (!config->ctx_num) {
+ WD_ERR("invalid: sec init config ctx num is 0!\n");
+ return -WD_EINVAL;
+ }
+
qm_priv.sqe_size = sizeof(struct hisi_sec_sqe);
/* allocate qp for each context */
for (i = 0; i < config->ctx_num; i++) {
--
2.27.0

View File

@ -0,0 +1,104 @@
From 3d84ae9b37c608a045322312a929839042d6b2a9 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 23 Jul 2022 16:50:31 +0800
Subject: [PATCH 164/183] uadk: fix cast pointer problem
The pointer is cast to another pointer in a different type,
fix it with void pointer.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
v1/drv/hisi_hpre_udrv.c | 5 +++--
v1/wd_ecc.c | 6 +++---
wd_ecc.c | 6 +++---
3 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c
index 805160e..4a97917 100644
--- a/v1/drv/hisi_hpre_udrv.c
+++ b/v1/drv/hisi_hpre_udrv.c
@@ -1215,8 +1215,9 @@ static int ecc_prepare_verf_in(struct wcrypto_ecc_msg *msg, void **data)
return 0;
}
-static int ecc_prepare_dh_gen_in(struct wcrypto_ecc_point *in, void **data)
+static int ecc_prepare_dh_gen_in(void *input, void **data)
{
+ struct wcrypto_ecc_point *in = input;
int ret;
ret = qm_crypto_bin_to_hpre_bin(in->x.data, (const char *)in->x.data,
@@ -1325,7 +1326,7 @@ static int qm_ecc_prepare_in(struct wcrypto_ecc_msg *msg,
hw_msg->bd_rsv2 = 1; /* fall through */
case WCRYPTO_ECXDH_GEN_KEY: /* fall through */
case WCRYPTO_SM2_KG:
- ret = ecc_prepare_dh_gen_in((struct wcrypto_ecc_point *)in,
+ ret = ecc_prepare_dh_gen_in((void *)in,
data);
break;
case WCRYPTO_ECXDH_COMPUTE_KEY:
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c
index dae5e23..c2a5100 100644
--- a/v1/wd_ecc.c
+++ b/v1/wd_ecc.c
@@ -435,7 +435,7 @@ static struct wcrypto_ecc_in *create_sm2_sign_in(struct wcrypto_ecc_ctx *ctx,
}
in->size = len - sizeof(struct wcrypto_ecc_in);
- dgst = (struct wd_dtb *)in;
+ dgst = (void *)in;
dgst->data = in->data;
dgst->dsize = ctx->key_size;
dgst->bsize = hsz;
@@ -475,7 +475,7 @@ static struct wcrypto_ecc_in *create_sm2_enc_in(struct wcrypto_ecc_ctx *ctx,
}
in->size = ksz + m_len;
- k = (struct wd_dtb *)in;
+ k = (void *)in;
k->data = in->data;
k->dsize = ksz;
k->bsize = ksz;
@@ -2017,7 +2017,7 @@ static struct wcrypto_ecc_in *create_sm2_verf_in(struct wcrypto_ecc_ctx *ctx,
memset(in, 0, len);
in->size = len - sizeof(struct wcrypto_ecc_in);
- dgst = (struct wd_dtb *)in;
+ dgst = (void *)in;
dgst->data = in->data;
dgst->dsize = ctx->key_size;
dgst->bsize = hsz;
diff --git a/wd_ecc.c b/wd_ecc.c
index fed02cb..136e8e2 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -445,7 +445,7 @@ static struct wd_ecc_in *create_sm2_sign_in(struct wd_ecc_sess *sess,
memset(in, 0, len);
in->size = len - sizeof(struct wd_ecc_in);
- dgst = (struct wd_dtb *)in;
+ dgst = (void *)in;
dgst->data = in->data;
dgst->dsize = ksz;
dgst->bsize = ksz;
@@ -485,7 +485,7 @@ static struct wd_ecc_in *create_sm2_enc_in(struct wd_ecc_sess *sess,
memset(in, 0, len);
in->size = ksz + m_len;
- k = (struct wd_dtb *)in;
+ k = (void *)in;
k->data = in->data;
k->dsize = ksz;
k->bsize = ksz;
@@ -1707,7 +1707,7 @@ static struct wd_ecc_in *create_sm2_verf_in(struct wd_ecc_sess *sess,
memset(in, 0, len);
in->size = len - sizeof(struct wd_ecc_in);
- dgst = (struct wd_dtb *)in;
+ dgst = (void *)in;
dgst->data = in->data;
dgst->dsize = sess->key_size;
dgst->bsize = hsz;
--
2.27.0

View File

@ -0,0 +1,60 @@
From 1e1b1fce4977f41f1cb1a86d22aca43a18531efc Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 23 Jul 2022 16:50:32 +0800
Subject: [PATCH 165/183] uadk: fix function params usage
parameter 'expt' of function 'wd_rsa_poll_ctx'
should not be used as working variable.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
v1/wd_ecc.c | 5 +++--
wd_rsa.c | 3 ++-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c
index c2a5100..e108051 100644
--- a/v1/wd_ecc.c
+++ b/v1/wd_ecc.c
@@ -269,14 +269,15 @@ static void init_dtb_param(void *dtb, char *start,
__u32 dsz, __u32 bsz, __u32 num)
{
struct wd_dtb *tmp = dtb;
+ char *pos = start;
int i = 0;
while (i++ < num) {
- tmp->data = start;
+ tmp->data = pos;
tmp->dsize = dsz;
tmp->bsize = bsz;
tmp += 1;
- start += bsz;
+ pos += bsz;
}
}
diff --git a/wd_rsa.c b/wd_rsa.c
index 89d3450..fb2b6b0 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -356,6 +356,7 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
struct wd_rsa_req *req;
struct wd_rsa_msg recv_msg, *msg;
__u32 rcv_cnt = 0;
+ __u32 tmp = expt;
int ret;
if (unlikely(!count)) {
@@ -395,7 +396,7 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
req->cb(req);
wd_put_msg_to_pool(&wd_rsa_setting.pool, idx, recv_msg.tag);
*count = rcv_cnt;
- } while (--expt);
+ } while (--tmp);
return ret;
}
--
2.27.0

View File

@ -0,0 +1,30 @@
From 76d36759e69f7ed303e8fbf42b46052383f86337 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 23 Jul 2022 16:50:33 +0800
Subject: [PATCH 166/183] uadk: fix size_t usage
The variable is assigned by value from strlen,
its type should be size_t.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
wd_util.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/wd_util.c b/wd_util.c
index 04a2a5b..349df81 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -585,7 +585,8 @@ free_numa_dev_num:
static int is_number(const char *str)
{
- int len, i;
+ size_t len;
+ int i;
if (!str)
return 0;
--
2.27.0

View File

@ -0,0 +1,79 @@
From 19c524e4be9fcd9af5145dde9e11725e4c7eb1c2 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 23 Jul 2022 16:50:34 +0800
Subject: [PATCH 167/183] uadk: fix atoi usage
atoi is called, use the functions like strtol
to transform string to integer instead.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
v1/wd.c | 23 +++++++++++++----------
wd_mempool.c | 4 ++--
2 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/v1/wd.c b/v1/wd.c
index 2c435ba..6e081e6 100644
--- a/v1/wd.c
+++ b/v1/wd.c
@@ -109,21 +109,24 @@ static int get_raw_attr(const char *dev_root, const char *attr,
static int get_int_attr(struct dev_info *dinfo, const char *attr)
{
- int size;
- char buf[MAX_ATTR_STR_SIZE];
+ char buf[MAX_ATTR_STR_SIZE] = {'\0'};
+ int ret;
/*
* The signed int max number is INT_MAX 10bit char "4294967295"
* 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)
- 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);
+ ret = get_raw_attr(dinfo->dev_root, attr, buf, MAX_ATTR_STR_SIZE - 1);
+ if (ret < 0)
+ return ret;
+
+ ret = strtol(buf, NULL, 10);
+ if (errno == ERANGE) {
+ WD_ERR("failed to strtol %s, out of range!\n", buf);
+ return -errno;
+ }
+
+ return ret;
}
/*
diff --git a/wd_mempool.c b/wd_mempool.c
index 6143a69..b27d28c 100644
--- a/wd_mempool.c
+++ b/wd_mempool.c
@@ -620,8 +620,8 @@ void wd_blockpool_destroy(handle_t blkpool)
static int get_value_from_sysfs(const char *path, ssize_t path_size)
{
+ char buf[MAX_ATTR_STR_SIZE] = {'\0'};
char dev_path[PATH_MAX];
- char buf[MAX_ATTR_STR_SIZE];
char *ptrRet = NULL;
ssize_t size;
int fd, ret;
@@ -638,7 +638,7 @@ static int get_value_from_sysfs(const char *path, ssize_t path_size)
goto err_open;
}
- size = read(fd, buf, sizeof(buf));
+ size = read(fd, buf, MAX_ATTR_STR_SIZE - 1);
if (size <= 0) {
WD_ERR("failed to read %s!\n", dev_path);
goto err_read;
--
2.27.0

View File

@ -0,0 +1,37 @@
From 05a357678b603cd6d30cbedabfb981620b056eed Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 23 Jul 2022 16:50:35 +0800
Subject: [PATCH 168/183] uadk: fix lm not link problem
Some gcc version need user to assign -lm parameter.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
Makefile.am | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 9782ed4..5856126 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -91,7 +91,7 @@ libwd_comp_la_DEPENDENCIES = libwd.la
libhisi_zip_la_LIBADD = -ldl
-libwd_crypto_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma
+libwd_crypto_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma -lm
libwd_crypto_la_DEPENDENCIES = libwd.la
libhisi_sec_la_LIBADD = $(libwd_la_OBJECTS) $(libwd_crypto_la_OBJECTS)
@@ -110,7 +110,7 @@ libwd_comp_la_DEPENDENCIES= libwd.la
libhisi_zip_la_LIBADD= -ldl
libhisi_zip_la_LDFLAGS=$(UADK_VERSION)
-libwd_crypto_la_LIBADD= -lwd -ldl -lnuma
+libwd_crypto_la_LIBADD= -lwd -ldl -lnuma -lm
libwd_crypto_la_LDFLAGS=$(UADK_VERSION)
libwd_crypto_la_DEPENDENCIES= libwd.la
--
2.27.0

View File

@ -0,0 +1,47 @@
From 2cb12ab4c85a8699635e75866ae4b0ff9881adc3 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sat, 23 Jul 2022 16:50:36 +0800
Subject: [PATCH 169/183] uadk: remove unneed comment and macro
Remove unneed comment and macro from v1 wd.c
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
v1/wd.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/v1/wd.c b/v1/wd.c
index 6e081e6..b8fd28c 100644
--- a/v1/wd.c
+++ b/v1/wd.c
@@ -31,14 +31,13 @@
#include "v1/wd_adapter.h"
#include "v1/wd.h"
-#define SYS_CLASS_DIR "/sys/class"
#define LINUX_DEV_DIR "/dev"
-#define WD_UACCE_CLASS_DIR SYS_CLASS_DIR"/"WD_UACCE_CLASS_NAME
+#define WD_UACCE_CLASS_DIR "/sys/class/"WD_UACCE_CLASS_NAME
#define _TRY_REQUEST_TIMES 64
#define INT_MAX_SIZE 10
#define LINUX_CRTDIR_SIZE 1
#define LINUX_PRTDIR_SIZE 2
-#define INSTANCE_RATIO_FOR_DEV_SCHED 4
+#define INSTANCE_RATIO_FOR_DEV_SCHED 4
#define GET_WEIGHT(distance, instances) (\
((instances) & 0xffff) | (((distance) & 0xffff) << 16))
@@ -112,10 +111,6 @@ static int get_int_attr(struct dev_info *dinfo, const char *attr)
char buf[MAX_ATTR_STR_SIZE] = {'\0'};
int ret;
- /*
- * The signed int max number is INT_MAX 10bit char "4294967295"
- * When the value is bigger than INT_MAX, it returns INT_MAX
- */
ret = get_raw_attr(dinfo->dev_root, attr, buf, MAX_ATTR_STR_SIZE - 1);
if (ret < 0)
return ret;
--
2.27.0

View File

@ -0,0 +1,56 @@
From fbdf545556c1fe85e5c35001af675ea0cb8ab968 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Sat, 23 Jul 2022 10:48:56 +0800
Subject: [PATCH 170/183] drv/hpre: remove repeatedly included header file
Some header files have included in hisi_qm_udrv.h, remove them from
hisi_hpre.c.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
drv/hisi_hpre.c | 10 ++--------
include/drv/wd_rsa_drv.h | 2 ++
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 4c6e532..8454eff 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -2,19 +2,13 @@
/* Copyright 2020-2021 Huawei Technologies Co.,Ltd. All rights reserved. */
#include <stdlib.h>
-#include <unistd.h>
#include <stdio.h>
-#include <sys/mman.h>
-#include <assert.h>
-#include <string.h>
-#include <stdint.h>
-#include <fcntl.h>
-#include <sys/stat.h>
+#include <unistd.h>
#include <sys/epoll.h>
#include <sys/eventfd.h>
+#include <sys/mman.h>
#include <sys/types.h>
#include "hisi_qm_udrv.h"
-#include "wd.h"
#include "../include/drv/wd_rsa_drv.h"
#include "../include/drv/wd_dh_drv.h"
#include "../include/drv/wd_ecc_drv.h"
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
index 28c3337..83f1af2 100644
--- a/include/drv/wd_rsa_drv.h
+++ b/include/drv/wd_rsa_drv.h
@@ -3,6 +3,8 @@
#ifndef __WD_RSA_DRV_H
#define __WD_RSA_DRV_H
+#include <asm/types.h>
+
#include "../wd_rsa.h"
#ifdef __cplusplus
--
2.27.0

View File

@ -0,0 +1,138 @@
From 06d0a1a22e611a23f91573d125dc83295a2b0256 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Sat, 23 Jul 2022 10:48:57 +0800
Subject: [PATCH 171/183] drv/hpre: add hpre_result_check()
When process recv completed task from hardware,
driver will check BD status. The check logic for ECC/DH/RSA
is the same. Therefore, call hpre_resut_check() to check the BD
status to reduce duplicate code.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
drv/hisi_hpre.c | 75 ++++++++++++++++++++-----------------------------
1 file changed, 30 insertions(+), 45 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 8454eff..76529e8 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -531,6 +531,25 @@ static int rsa_send(handle_t ctx, void *rsa_msg)
return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
}
+static void hpre_result_check(struct hisi_hpre_sqe *hw_msg,
+ __u8 *result)
+{
+ *result = WD_SUCCESS;
+
+ if (hw_msg->done != HPRE_HW_TASK_DONE ||
+ hw_msg->etype || hw_msg->etype1) {
+ WD_ERR("failed to do hpre 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",
+ hw_msg->sva_status);
+ if (hw_msg->done == HPRE_HW_TASK_INIT)
+ *result = WD_EINVAL;
+ else
+ *result = WD_IN_EPARA;
+ }
+}
+
static int rsa_recv(handle_t ctx, void *rsa_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
@@ -547,25 +566,13 @@ static int rsa_recv(handle_t ctx, void *rsa_msg)
if (ret)
return ret;
- if (hw_msg.done != HPRE_HW_TASK_DONE ||
- hw_msg.etype || hw_msg.etype1) {
- 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",
- hw_msg.sva_status);
- if (hw_msg.done == HPRE_HW_TASK_INIT)
- msg->result = WD_EINVAL;
- else
- msg->result = WD_IN_EPARA;
- } else {
- msg->tag = LW_U16(hw_msg.low_tag);
+ msg->tag = LW_U16(hw_msg.low_tag);
+ hpre_result_check(&hw_msg, &msg->result);
+ if (!msg->result) {
ret = rsa_out_transfer(msg, &hw_msg);
if (ret) {
WD_ERR("failed to transfer out rsa BD!\n");
msg->result = WD_OUT_EPARA;
- } else {
- msg->result = WD_SUCCESS;
}
}
@@ -696,25 +703,13 @@ static int dh_recv(handle_t ctx, void *dh_msg)
if (ret)
return ret;
- if (hw_msg.done != HPRE_HW_TASK_DONE ||
- hw_msg.etype || hw_msg.etype1) {
- 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",
- hw_msg.sva_status);
- if (hw_msg.done == HPRE_HW_TASK_INIT)
- msg->result = WD_EINVAL;
- else
- msg->result = WD_IN_EPARA;
- } else {
- msg->tag = LW_U16(hw_msg.low_tag);
+ msg->tag = LW_U16(hw_msg.low_tag);
+ hpre_result_check(&hw_msg, &msg->result);
+ if (!msg->result) {
ret = dh_out_transfer(msg, &hw_msg);
if (ret) {
WD_ERR("failed to transfer out dh BD!\n");
msg->result = WD_OUT_EPARA;
- } else {
- msg->result = WD_SUCCESS;
}
}
@@ -2191,26 +2186,16 @@ static int ecc_sqe_parse(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
{
int ret;
- if (hw_msg->done != HPRE_HW_TASK_DONE ||
- hw_msg->etype || hw_msg->etype1) {
- 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",
- hw_msg->sva_status);
-
- if (hw_msg->done == HPRE_HW_TASK_INIT)
- ret = -WD_EINVAL;
- else
- ret = -WD_IN_EPARA;
- } else {
- msg->result = WD_SUCCESS;
+ msg->tag = LW_U16(hw_msg->low_tag);
+ hpre_result_check(hw_msg, &msg->result);
+ if (!msg->result) {
ret = ecc_out_transfer(msg, hw_msg);
if (ret) {
msg->result = WD_OUT_EPARA;
WD_ERR("failed to transfer out ecc BD, ret = %d!\n", ret);
}
- msg->tag = LW_U16(hw_msg->low_tag);
+ } else {
+ ret = -msg->result;
}
return ret;
--
2.27.0

View File

@ -0,0 +1,67 @@
From 892ac1efc8dac5dfb0434c953c66d379533ea0f4 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Sat, 23 Jul 2022 10:48:58 +0800
Subject: [PATCH 172/183] drv/hpre: move format check to is_hpre_bin_fmt()
Move the check format from crypto_bin_to_hpre_bin()
to is_hpre_bin_fmt(), all check are done by is_hpre_bin_fmt().
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
drv/hisi_hpre.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 76529e8..c3c74a0 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -100,18 +100,24 @@ struct hisi_hpre_ctx {
struct wd_ctx_config_internal config;
};
-static bool is_hpre_bin_fmt(const char *data, int dsz, int bsz)
+static bool is_hpre_bin_fmt(char *dst, const char *src, int dsz, int bsz)
{
- const char *temp = data + dsz;
+ const char *temp = src + dsz;
int lens = bsz - dsz;
int i = 0;
+ if (!lens)
+ return true;
+
while (i < lens) {
- if (temp[i] && !data[i])
- return true;
+ if (temp[i] && !src[i])
+ break;
i++;
}
+ if (dst == src && i != lens)
+ return true;
+
return false;
}
@@ -119,7 +125,6 @@ static int crypto_bin_to_hpre_bin(char *dst, const char *src,
__u32 b_size, __u32 d_size, const char *p_name)
{
int i = d_size - 1;
- bool is_hpre_bin;
int j;
if (!dst || !src || b_size <= 0 || d_size <= 0) {
@@ -132,8 +137,7 @@ static int crypto_bin_to_hpre_bin(char *dst, const char *src,
return -WD_EINVAL;
}
- is_hpre_bin = is_hpre_bin_fmt(src, d_size, b_size);
- if (b_size == d_size || (dst == src && is_hpre_bin))
+ if (is_hpre_bin_fmt(dst, src, d_size, b_size))
return WD_SUCCESS;
for (j = b_size - 1; j >= 0; j--, i--) {
--
2.27.0

View File

@ -0,0 +1,55 @@
From 8d53e4e7194addaf3e9831ba5f197440d0522ad0 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Sat, 23 Jul 2022 10:48:59 +0800
Subject: [PATCH 173/183] drv/hpre: change the parameter type
Change the function parameter type to '__u32'
because the input value by callers is not less than 0.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
drv/hisi_hpre.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index c3c74a0..aea7749 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -100,7 +100,7 @@ struct hisi_hpre_ctx {
struct wd_ctx_config_internal config;
};
-static bool is_hpre_bin_fmt(char *dst, const char *src, int dsz, int bsz)
+static bool is_hpre_bin_fmt(char *dst, const char *src, __u32 dsz, __u32 bsz)
{
const char *temp = src + dsz;
int lens = bsz - dsz;
@@ -127,7 +127,7 @@ static int crypto_bin_to_hpre_bin(char *dst, const char *src,
int i = d_size - 1;
int j;
- if (!dst || !src || b_size <= 0 || d_size <= 0) {
+ if (!dst || !src || !b_size || !d_size) {
WD_ERR("invalid: %s trans to hpre bin parameters err!\n", p_name);
return -WD_EINVAL;
}
@@ -150,14 +150,14 @@ static int crypto_bin_to_hpre_bin(char *dst, const char *src,
return WD_SUCCESS;
}
-static int hpre_bin_to_crypto_bin(char *dst, const char *src, int b_size,
+static int hpre_bin_to_crypto_bin(char *dst, const char *src, __u32 b_size,
const char *p_name)
{
int i, cnt;
int j = 0;
int k = 0;
- if (!dst || !src || b_size <= 0) {
+ if (!dst || !src || !b_size) {
WD_ERR("invalid: %s trans to crypto bin parameters err!\n", p_name);
return 0;
}
--
2.27.0

View File

@ -0,0 +1,27 @@
From d0300cca906531d85d025c1c17a3d845a0f45902 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Sat, 23 Jul 2022 10:49:00 +0800
Subject: [PATCH 174/183] drv/hpre: remove redundant blank line
This patch removes redundant blank line from the hpre driver.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
drv/hisi_hpre.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index aea7749..d957101 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -771,7 +771,6 @@ static int ecc_prepare_alg(struct wd_ecc_msg *msg,
return 0;
}
-
static int trans_cv_param_to_hpre_bin(struct wd_dtb *p, struct wd_dtb *a,
struct wd_dtb *b, struct wd_dtb *n,
struct wd_ecc_point *g)
--
2.27.0

View File

@ -0,0 +1,71 @@
From 3c59e2ada00a20ff8aec3fe13920cf155a63740c Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Sat, 23 Jul 2022 10:49:01 +0800
Subject: [PATCH 175/183] drv/qm: 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>
---
drv/hisi_qm_udrv.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 39c99d1..7f26e52 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -442,12 +442,12 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
__u16 free_num, send_num;
__u16 tail;
- if (!qp || !req || !count)
+ if (unlikely(!qp || !req || !count))
return -WD_EINVAL;
q_info = &qp->q_info;
- if (wd_ioread32(q_info->ds_tx_base) == 1) {
+ if (unlikely(wd_ioread32(q_info->ds_tx_base) == 1)) {
WD_ERR("wd queue hw error happened before qm send!\n");
return -WD_HW_EACCESS;
}
@@ -488,7 +488,7 @@ static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, void *resp)
if (q_info->cqc_phase == CQE_PHASE(cqe)) {
j = CQE_SQ_HEAD_INDEX(cqe);
- if (j >= QM_Q_DEPTH) {
+ if (unlikely(j >= QM_Q_DEPTH)) {
pthread_spin_unlock(&q_info->rv_lock);
WD_DEV_ERR(qp->h_ctx, "CQE_SQ_HEAD_INDEX(%u) error!\n", j);
return -WD_EIO;
@@ -526,14 +526,14 @@ int hisi_qm_recv(handle_t h_qp, void *resp, __u16 expect, __u16 *count)
int recv_num = 0;
int i, ret, offset;
- if (!resp || !qp || !count)
+ if (unlikely(!resp || !qp || !count))
return -WD_EINVAL;
- if (!expect)
+ if (unlikely(!expect))
return 0;
q_info = &qp->q_info;
- if (wd_ioread32(q_info->ds_rx_base) == 1) {
+ if (unlikely(wd_ioread32(q_info->ds_rx_base) == 1)) {
WD_DEV_ERR(qp->h_ctx, "wd queue hw error happened before qm receive!\n");
return -WD_HW_EACCESS;
}
@@ -547,7 +547,7 @@ int hisi_qm_recv(handle_t h_qp, void *resp, __u16 expect, __u16 *count)
}
*count = recv_num++;
- if (wd_ioread32(q_info->ds_rx_base) == 1) {
+ if (unlikely(wd_ioread32(q_info->ds_rx_base) == 1)) {
WD_DEV_ERR(qp->h_ctx, "wd queue hw error happened in qm receive!\n");
return -WD_HW_EACCESS;
}
--
2.27.0

View File

@ -0,0 +1,28 @@
From 16800a92f326560006d0480faacde3cf1d5d6cb2 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Sat, 23 Jul 2022 10:49:02 +0800
Subject: [PATCH 176/183] drv/qm: remove redundant add 1
The variable 'recv_num' is no longer used, remove redundant add 1;
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
drv/hisi_qm_udrv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 7f26e52..6459ffa 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -546,7 +546,7 @@ int hisi_qm_recv(handle_t h_qp, void *resp, __u16 expect, __u16 *count)
recv_num++;
}
- *count = recv_num++;
+ *count = recv_num;
if (unlikely(wd_ioread32(q_info->ds_rx_base) == 1)) {
WD_DEV_ERR(qp->h_ctx, "wd queue hw error happened in qm receive!\n");
return -WD_HW_EACCESS;
--
2.27.0

View File

@ -0,0 +1,41 @@
From 913b0b03484eace681dd53a2fdf6a20e594f07d8 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Sat, 23 Jul 2022 10:49:03 +0800
Subject: [PATCH 177/183] drv/qm: remove useless parameter 'sq_head_index'
The 'sq_head_index' is operated by the accelerator hardware, and
is useless to the driver. Therefore, remove 'sq_head_index'.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
drv/hisi_qm_udrv.c | 1 -
include/hisi_qm_udrv.h | 1 -
2 files changed, 2 deletions(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 6459ffa..93f2eb7 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -511,7 +511,6 @@ static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, void *resp)
/* only support one thread poll one queue, so no need protect */
q_info->cq_head_index = i;
- q_info->sq_head_index = i;
__atomic_sub_fetch(&q_info->used_num, 1, __ATOMIC_RELAXED);
pthread_spin_unlock(&q_info->rv_lock);
diff --git a/include/hisi_qm_udrv.h b/include/hisi_qm_udrv.h
index 92333ed..22dedf3 100644
--- a/include/hisi_qm_udrv.h
+++ b/include/hisi_qm_udrv.h
@@ -67,7 +67,6 @@ struct hisi_qm_queue_info {
void *ds_rx_base;
__u8 qp_mode;
__u16 sq_tail_index;
- __u16 sq_head_index;
__u16 cq_head_index;
__u16 sqn;
__u16 qc_type;
--
2.27.0

View File

@ -0,0 +1,106 @@
From 282f78fc44dc216166ae463944d952f753f7c8b6 Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Sat, 23 Jul 2022 10:49:04 +0800
Subject: [PATCH 178/183] uadk: add wd_<alg>_get_msg()
Add wd_<alg>_get_msg() for driver to obtain the sent
message by the user.
Signed-off-by: Kai Ye <yekai13@huawei.com>
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
include/drv/wd_dh_drv.h | 1 +
include/drv/wd_ecc_drv.h | 1 +
include/drv/wd_rsa_drv.h | 1 +
wd_dh.c | 5 +++++
wd_ecc.c | 5 +++++
wd_rsa.c | 5 +++++
6 files changed, 18 insertions(+)
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
index f8e3065..57f774d 100644
--- a/include/drv/wd_dh_drv.h
+++ b/include/drv/wd_dh_drv.h
@@ -36,6 +36,7 @@ struct wd_dh_driver {
void wd_dh_set_driver(struct wd_dh_driver *drv);
struct wd_dh_driver *wd_dh_get_driver(void);
+struct wd_dh_msg *wd_dh_get_msg(__u32 idx, __u32 tag);
#ifdef WD_STATIC_DRV
#define WD_DH_SET_DRIVER(drv) \
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index 857da20..ddf5e5b 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -188,6 +188,7 @@ struct wd_ecc_driver {
void wd_ecc_set_driver(struct wd_ecc_driver *drv);
struct wd_ecc_driver *wd_ecc_get_driver(void);
+struct wd_ecc_msg *wd_ecc_get_msg(__u32 idx, __u32 tag);
#ifdef WD_STATIC_DRV
#define WD_ECC_SET_DRIVER(drv) \
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
index 83f1af2..108c2a3 100644
--- a/include/drv/wd_rsa_drv.h
+++ b/include/drv/wd_rsa_drv.h
@@ -61,6 +61,7 @@ struct wd_rsa_driver {
void wd_rsa_set_driver(struct wd_rsa_driver *drv);
struct wd_rsa_driver *wd_rsa_get_driver(void);
+struct wd_rsa_msg *wd_rsa_get_msg(__u32 idx, __u32 tag);
#ifdef WD_STATIC_DRV
#define WD_RSA_SET_DRIVER(drv) \
diff --git a/wd_dh.c b/wd_dh.c
index 41c4a2a..0bf770d 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -290,6 +290,11 @@ fail_with_msg:
return ret;
}
+struct wd_dh_msg *wd_dh_get_msg(__u32 idx, __u32 tag)
+{
+ return wd_find_msg_in_pool(&wd_dh_setting.pool, idx, tag);
+}
+
int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
{
struct wd_ctx_config_internal *config = &wd_dh_setting.config;
diff --git a/wd_ecc.c b/wd_ecc.c
index 136e8e2..2266b1d 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -2119,6 +2119,11 @@ fail_with_msg:
return ret;
}
+struct wd_ecc_msg *wd_ecc_get_msg(__u32 idx, __u32 tag)
+{
+ return wd_find_msg_in_pool(&wd_ecc_setting.pool, idx, tag);
+}
+
int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
{
struct wd_ctx_config_internal *config = &wd_ecc_setting.config;
diff --git a/wd_rsa.c b/wd_rsa.c
index fb2b6b0..489833e 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -349,6 +349,11 @@ fail_with_msg:
return ret;
}
+struct wd_rsa_msg *wd_rsa_get_msg(__u32 idx, __u32 tag)
+{
+ return wd_find_msg_in_pool(&wd_rsa_setting.pool, idx, tag);
+}
+
int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
{
struct wd_ctx_config_internal *config = &wd_rsa_setting.config;
--
2.27.0

View File

@ -0,0 +1,206 @@
From 40bf83f1ee78c6cf28114ea93c2d93eb3a312c1e Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Sat, 23 Jul 2022 10:49:05 +0800
Subject: [PATCH 179/183] drv/hpre: support dump BD when BD checks fail
When BD parsing fails, dumped BD information.
Signed-off-by: Kai Ye <yekai13@huawei.com>
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
drv/hisi_hpre.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 78 insertions(+), 5 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index d957101..768c9a1 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -100,6 +100,27 @@ struct hisi_hpre_ctx {
struct wd_ctx_config_internal config;
};
+static void dump_hpre_msg(void *msg, const char *s)
+{
+ struct wd_rsa_msg *rsa_msg;
+ struct wd_ecc_msg *ecc_msg;
+ struct wd_dh_msg *dh_msg;
+
+ WD_ERR("dump %s alg message after a task error occurs.\n", s);
+
+ if (!strcmp(s, "rsa")) {
+ rsa_msg = (struct wd_rsa_msg *)msg;
+ WD_ERR("key_bytes:%u key_type:%u\n", rsa_msg->key_bytes, rsa_msg->key_type);
+ } else if (!strcmp(s, "ecc")) {
+ ecc_msg = (struct wd_ecc_msg *)msg;
+ WD_ERR("key_bytes:%u curve_id:%u\n", ecc_msg->key_bytes, ecc_msg->curve_id);
+ } else if (!strcmp(s, "dh")) {
+ dh_msg = (struct wd_dh_msg *)msg;
+ WD_ERR("gbytes:%u key_bytes:%u is_g2:%u\n", dh_msg->gbytes,
+ dh_msg->key_bytes, dh_msg->is_g2);
+ }
+}
+
static bool is_hpre_bin_fmt(char *dst, const char *src, __u32 dsz, __u32 bsz)
{
const char *temp = src + dsz;
@@ -557,8 +578,10 @@ static void hpre_result_check(struct hisi_hpre_sqe *hw_msg,
static int rsa_recv(handle_t ctx, void *rsa_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
struct hisi_hpre_sqe hw_msg = {0};
struct wd_rsa_msg *msg = rsa_msg;
+ struct wd_rsa_msg *temp_msg;
__u16 recv_cnt = 0;
int ret;
@@ -571,6 +594,17 @@ static int rsa_recv(handle_t ctx, void *rsa_msg)
return ret;
msg->tag = LW_U16(hw_msg.low_tag);
+ if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
+ temp_msg = wd_rsa_get_msg(qp->q_info.idx, msg->tag);
+ if (!temp_msg) {
+ WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
+ qp->q_info.idx, msg->tag);
+ return -WD_EINVAL;
+ }
+ } else {
+ temp_msg = msg;
+ }
+
hpre_result_check(&hw_msg, &msg->result);
if (!msg->result) {
ret = rsa_out_transfer(msg, &hw_msg);
@@ -580,6 +614,9 @@ static int rsa_recv(handle_t ctx, void *rsa_msg)
}
}
+ if (unlikely(msg->result != WD_SUCCESS))
+ dump_hpre_msg(temp_msg, "rsa");
+
return 0;
}
@@ -694,8 +731,10 @@ static int dh_send(handle_t ctx, void *dh_msg)
static int dh_recv(handle_t ctx, void *dh_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
struct wd_dh_msg *msg = dh_msg;
struct hisi_hpre_sqe hw_msg = {0};
+ struct wd_dh_msg *temp_msg;
__u16 recv_cnt = 0;
int ret;
@@ -708,6 +747,17 @@ static int dh_recv(handle_t ctx, void *dh_msg)
return ret;
msg->tag = LW_U16(hw_msg.low_tag);
+ if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
+ temp_msg = wd_dh_get_msg(qp->q_info.idx, msg->tag);
+ if (!temp_msg) {
+ WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
+ qp->q_info.idx, msg->tag);
+ return -WD_EINVAL;
+ }
+ } else {
+ temp_msg = msg;
+ }
+
hpre_result_check(&hw_msg, &msg->result);
if (!msg->result) {
ret = dh_out_transfer(msg, &hw_msg);
@@ -717,6 +767,9 @@ static int dh_recv(handle_t ctx, void *dh_msg)
}
}
+ if (unlikely(msg->result != WD_SUCCESS))
+ dump_hpre_msg(temp_msg, "dh");
+
return 0;
}
@@ -2185,22 +2238,42 @@ static int sm2_convert_dec_out(struct wd_ecc_msg *src,
return ret;
}
-static int ecc_sqe_parse(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
+static int ecc_sqe_parse(struct hisi_qp *qp, struct wd_ecc_msg *msg,
+ struct hisi_hpre_sqe *hw_msg)
{
+ struct wd_ecc_msg *temp_msg;
int ret;
msg->tag = LW_U16(hw_msg->low_tag);
+ if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
+ temp_msg = wd_ecc_get_msg(qp->q_info.idx, msg->tag);
+ if (!temp_msg) {
+ WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
+ qp->q_info.idx, msg->tag);
+ return -WD_EINVAL;
+ }
+ } else {
+ temp_msg = msg;
+ }
+
hpre_result_check(hw_msg, &msg->result);
if (!msg->result) {
ret = ecc_out_transfer(msg, hw_msg);
if (ret) {
msg->result = WD_OUT_EPARA;
WD_ERR("failed to transfer out ecc BD, ret = %d!\n", ret);
+ goto dump_err_msg;
}
} else {
ret = -msg->result;
+ goto dump_err_msg;
}
+ return ret;
+
+dump_err_msg:
+ dump_hpre_msg(temp_msg, "ecc");
+
return ret;
}
@@ -2234,7 +2307,7 @@ static int parse_second_sqe(handle_t h_qp,
dst = *(struct wd_ecc_msg **)((uintptr_t)data +
hsz * ECDH_OUT_PARAM_NUM);
hw_msg.low_tag = 0; /* use sync mode */
- ret = ecc_sqe_parse(dst, &hw_msg);
+ ret = ecc_sqe_parse((struct hisi_qp *)h_qp, dst, &hw_msg);
msg->result = dst->result;
*second = dst;
@@ -2260,7 +2333,7 @@ static int sm2_enc_parse(handle_t h_qp,
/* parse first sqe */
hw_msg->low_tag = 0; /* use sync mode */
- ret = ecc_sqe_parse(first, hw_msg);
+ ret = ecc_sqe_parse((struct hisi_qp *)h_qp, first, hw_msg);
if (ret) {
WD_ERR("failed to parse first BD, ret = %d!\n", ret);
goto free_first;
@@ -2304,7 +2377,7 @@ static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
/* parse first sqe */
hw_msg->low_tag = 0; /* use sync mode */
- ret = ecc_sqe_parse(dst, hw_msg);
+ ret = ecc_sqe_parse((struct hisi_qp *)ctx, dst, hw_msg);
if (ret) {
WD_ERR("failed to parse decode BD, ret = %d!\n", ret);
goto fail;
@@ -2347,7 +2420,7 @@ static int ecc_recv(handle_t ctx, void *ecc_msg)
hw_msg.sm2_mlen == HPRE_SM2_DEC)
return sm2_dec_parse(h_qp, msg, &hw_msg);
- return ecc_sqe_parse(msg, &hw_msg);
+ return ecc_sqe_parse((struct hisi_qp *)h_qp, msg, &hw_msg);
}
static struct wd_ecc_driver ecc_hisi_hpre = {
--
2.27.0

View File

@ -0,0 +1,129 @@
From d2996f7251e18c164fc3faba909e4ab90361c2e3 Mon Sep 17 00:00:00 2001
From: Zhiqi Song <songzhiqi1@huawei.com>
Date: Sat, 23 Jul 2022 15:28:50 +0800
Subject: [PATCH 180/183] drv/hpre: bugfix about sm2 async parsing error
After a series of modification, the 'hw_msg->low_tag' is used to
represent the sequence of sync or async task element now.
In async mode, the value of 'hw_msg->low_tag' comes from async task
pool, refers to wd_get_msg_from_pool(). In sync mode, the value of
'hw_msg->low_tag' is a random number, refers to hisi_set_msg_id().
Therefore, whether 'hw_msg->low_tag' is zero cannot be used as the
judgment condition for different modes, so 'hw_msg->low_tag' cannot
be set to zero directly. This is the reason why the async task of
sm2 failed.
To fix this problem, we remove the operation of setting tag to zero,
use 'qp_mode' to distinguish between sync and async modes.
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
---
drv/hisi_hpre.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 768c9a1..18e5a3c 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -1939,13 +1939,13 @@ static int sm2_enc_out_transfer(struct wd_ecc_msg *msg,
}
static int ecc_out_transfer(struct wd_ecc_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+ struct hisi_hpre_sqe *hw_msg, __u8 qp_mode)
{
int ret = -WD_EINVAL;
void *va;
/* async */
- if (LW_U16(hw_msg->low_tag)) {
+ if (qp_mode == CTX_MODE_ASYNC) {
va = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
msg->req.dst = container_of(va, struct wd_ecc_out, data);
}
@@ -2258,7 +2258,7 @@ static int ecc_sqe_parse(struct hisi_qp *qp, struct wd_ecc_msg *msg,
hpre_result_check(hw_msg, &msg->result);
if (!msg->result) {
- ret = ecc_out_transfer(msg, hw_msg);
+ ret = ecc_out_transfer(msg, hw_msg, qp->q_info.qp_mode);
if (ret) {
msg->result = WD_OUT_EPARA;
WD_ERR("failed to transfer out ecc BD, ret = %d!\n", ret);
@@ -2306,7 +2306,6 @@ static int parse_second_sqe(handle_t h_qp,
hsz = (hw_msg.task_len1 + 1) * BYTE_BITS;
dst = *(struct wd_ecc_msg **)((uintptr_t)data +
hsz * ECDH_OUT_PARAM_NUM);
- hw_msg.low_tag = 0; /* use sync mode */
ret = ecc_sqe_parse((struct hisi_qp *)h_qp, dst, &hw_msg);
msg->result = dst->result;
*second = dst;
@@ -2314,8 +2313,8 @@ static int parse_second_sqe(handle_t h_qp,
return ret;
}
-static int sm2_enc_parse(handle_t h_qp,
- struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
+static int sm2_enc_parse(handle_t h_qp, struct wd_ecc_msg *msg,
+ struct hisi_hpre_sqe *hw_msg)
{
__u16 tag = LW_U16(hw_msg->low_tag);
struct wd_ecc_msg *second = NULL;
@@ -2325,6 +2324,7 @@ static int sm2_enc_parse(handle_t h_qp,
__u32 hsz;
int ret;
+ msg->tag = tag;
data = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
hsz = (hw_msg->task_len1 + 1) * BYTE_BITS;
first = *(struct wd_ecc_msg **)((uintptr_t)data +
@@ -2332,7 +2332,6 @@ static int sm2_enc_parse(handle_t h_qp,
memcpy(&src, first + 1, sizeof(src));
/* parse first sqe */
- hw_msg->low_tag = 0; /* use sync mode */
ret = ecc_sqe_parse((struct hisi_qp *)h_qp, first, hw_msg);
if (ret) {
WD_ERR("failed to parse first BD, ret = %d!\n", ret);
@@ -2351,11 +2350,12 @@ static int sm2_enc_parse(handle_t h_qp,
WD_ERR("failed to convert sm2 std format, ret = %d!\n", ret);
goto free_second;
}
+
free_second:
free_req(second);
free_first:
free_req(first);
- msg->tag = tag;
+
return ret;
}
@@ -2376,21 +2376,21 @@ static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
memcpy(&src, dst + 1, sizeof(src));
/* parse first sqe */
- hw_msg->low_tag = 0; /* use sync mode */
ret = ecc_sqe_parse((struct hisi_qp *)ctx, dst, hw_msg);
if (ret) {
WD_ERR("failed to parse decode BD, ret = %d!\n", ret);
goto fail;
}
msg->result = dst->result;
+ msg->tag = tag;
ret = sm2_convert_dec_out(&src, dst);
if (unlikely(ret)) {
WD_ERR("failed to convert sm2 decode out, ret = %d!\n", ret);
goto fail;
}
+
fail:
- msg->tag = tag;
free(dst->req.dst);
free(dst);
--
2.27.0

View File

@ -0,0 +1,74 @@
From 5e5bd0a4eb5a1bd794a4b6d8998bfaf40d98c808 Mon Sep 17 00:00:00 2001
From: Zhiqi Song <songzhiqi1@huawei.com>
Date: Sat, 23 Jul 2022 15:43:12 +0800
Subject: [PATCH 181/183] drv/hpre: bugfix async tag of rsa and dh
Use 'qp_mode' to distinguish between sync and async modes
of RSA and DH algs.
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
---
drv/hisi_hpre.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 18e5a3c..2e9db2f 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -336,7 +336,7 @@ static int hpre_tri_bin_transfer(struct wd_dtb *bin0, struct wd_dtb *bin1,
}
static int rsa_out_transfer(struct wd_rsa_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+ struct hisi_hpre_sqe *hw_msg, __u8 qp_mode)
{
struct wd_rsa_req *req = &msg->req;
struct wd_rsa_kg_out *key = req->dst;
@@ -348,7 +348,7 @@ static int rsa_out_transfer(struct wd_rsa_msg *msg,
if (hw_msg->alg == HPRE_ALG_KG_CRT || hw_msg->alg == HPRE_ALG_KG_STD) {
/* async */
- if (LW_U16(hw_msg->low_tag)) {
+ if (qp_mode == CTX_MODE_ASYNC) {
data = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
key = container_of(data, struct wd_rsa_kg_out, data);
} else {
@@ -607,7 +607,7 @@ static int rsa_recv(handle_t ctx, void *rsa_msg)
hpre_result_check(&hw_msg, &msg->result);
if (!msg->result) {
- ret = rsa_out_transfer(msg, &hw_msg);
+ ret = rsa_out_transfer(msg, &hw_msg, qp->q_info.qp_mode);
if (ret) {
WD_ERR("failed to transfer out rsa BD!\n");
msg->result = WD_OUT_EPARA;
@@ -660,7 +660,7 @@ static int fill_dh_xp_params(struct wd_dh_msg *msg,
}
static int dh_out_transfer(struct wd_dh_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+ struct hisi_hpre_sqe *hw_msg, __u8 qp_mode)
{
__u16 key_bytes = (hw_msg->task_len1 + 1) * BYTE_BITS;
struct wd_dh_req *req = &msg->req;
@@ -668,7 +668,7 @@ static int dh_out_transfer(struct wd_dh_msg *msg,
int ret;
/* async */
- if (LW_U16(hw_msg->low_tag))
+ if (qp_mode == CTX_MODE_ASYNC)
out = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
else
out = req->pri;
@@ -760,7 +760,7 @@ static int dh_recv(handle_t ctx, void *dh_msg)
hpre_result_check(&hw_msg, &msg->result);
if (!msg->result) {
- ret = dh_out_transfer(msg, &hw_msg);
+ ret = dh_out_transfer(msg, &hw_msg, qp->q_info.qp_mode);
if (ret) {
WD_ERR("failed to transfer out dh BD!\n");
msg->result = WD_OUT_EPARA;
--
2.27.0

View File

@ -0,0 +1,47 @@
From 858b0598f933cbaa832bb0da85e003c63b366f5d Mon Sep 17 00:00:00 2001
From: Zhiqi Song <songzhiqi1@huawei.com>
Date: Sat, 23 Jul 2022 15:56:27 +0800
Subject: [PATCH 182/183] drv/hpre: cleanup ecc sqe parsing process
The previous processing logic of ecc_sqe_parse() was
not clear enough, so it was modified.
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
---
drv/hisi_hpre.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 2e9db2f..552a565 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -2257,18 +2257,18 @@ static int ecc_sqe_parse(struct hisi_qp *qp, struct wd_ecc_msg *msg,
}
hpre_result_check(hw_msg, &msg->result);
- if (!msg->result) {
- ret = ecc_out_transfer(msg, hw_msg, qp->q_info.qp_mode);
- if (ret) {
- msg->result = WD_OUT_EPARA;
- WD_ERR("failed to transfer out ecc BD, ret = %d!\n", ret);
- goto dump_err_msg;
- }
- } else {
+ if (msg->result) {
ret = -msg->result;
goto dump_err_msg;
}
+ ret = ecc_out_transfer(msg, hw_msg, qp->q_info.qp_mode);
+ if (ret) {
+ msg->result = WD_OUT_EPARA;
+ WD_ERR("failed to transfer out ecc BD, ret = %d!\n", ret);
+ goto dump_err_msg;
+ }
+
return ret;
dump_err_msg:
--
2.27.0

View File

@ -1,7 +1,7 @@
Name: libwd
Summary: User Space Accelerator Development Kit
Version: 2.3.21
Release: 5
Release: 6
License: Apache-2.0
Source: %{name}-%{version}.tar.gz
Vendor: Huawei Corporation
@ -113,6 +113,74 @@ Patch0096: 0096-drv-comp-add-unlikely-for-branch-prefetch.patch
Patch0097: 0097-hisi_hpre-modify-the-return-value-of-function.patch
Patch0098: 0098-uadk-parse-epoll-flag-from-environment-variable.patch
Patch0099: 0099-test-enable-epoll-in-sanity-scripts.patch
Patch0100: 0100-drv-sec-modification-for-clean-code.patch
Patch0101: 0101-uadk-fix-mempool-code.patch
Patch0102: 0102-uadk-some-clean-code-for-wd.patch
Patch0103: 0103-wd-sched-modify-default-sched-param.patch
Patch0104: 0104-uadk-update-README.patch
Patch0105: 0105-uadk-add-BD-id-check-for-sync-mode.patch
Patch0106: 0106-uadk-ecc-optimize-create_ecc_out-line.patch
Patch0107: 0107-uadk-fix-parameter-of-function-has-different-name.patch
Patch0108: 0108-uadk-ecc-fix-local-variable-referenced-in-macro.patch
Patch0109: 0109-uadk-fix-switch-statement-has-no-default-branch.patch
Patch0110: 0110-uadk-fix-macro-argument.patch
Patch0111: 0111-uadk-fix-ret-uninit-problem.patch
Patch0112: 0112-uadk-qm-optimize-sgl-copy-function.patch
Patch0113: 0113-uadk-fix-problems-with-referencing-header-files.patch
Patch0114: 0114-uadk-fix-parameter-used-as-working-variable.patch
Patch0115: 0115-uadk-move-parameter-check-into-wd_util.c.patch
Patch0116: 0116-comp-remove-unused-variable-priv.patch
Patch0117: 0117-ecc-remove-the-lock-in-async-send-funciton.patch
Patch0118: 0118-dh-remove-the-lock-in-async-send.patch
Patch0119: 0119-comp-remove-the-lock-in-async-send.patch
Patch0120: 0120-dh-remove-repeated-send-BD.patch
Patch0121: 0121-ecc-remove-repeated-send-BD.patch
Patch0122: 0122-rsa-remove-repeated-send-BD.patch
Patch0123: 0123-uadk-move-send-and-recv-code-into-wd_util.c.patch
Patch0124: 0124-uadk-missing-header-file-after-install-uadk.patch
Patch0125: 0125-uadk-support-some-uadk-dfx-stronger-features.patch
Patch0126: 0126-uadk-sgl-data-can-be-dumped.patch
Patch0127: 0127-uadk-supports-zip-and-sec-message-dumping.patch
Patch0128: 0128-uadk-add-device-isolation-interface.patch
Patch0129: 0129-uadk-add-WD_DEV_ERR-api.patch
Patch0130: 0130-uadk-ecc-remove-a-redefined-macro.patch
Patch0131: 0131-uadk-hisi-remove-a-redefined-macro.patch
Patch0132: 0132-uadk-doc-fix-text-style-for-wd_design.md.patch
Patch0133: 0133-uadk_tool-Update-some-new-test-features.patch
Patch0134: 0134-uadk_tool-Add-SVA-test-function-of-HPRE-algorithm.patch
Patch0135: 0135-uadk_tool-Add-No-SVA-mode-test-function-to-HPRE.patch
Patch0136: 0136-uadk_tool-Add-SVA-mode-test-function-to-ZIP-module.patch
Patch0137: 0137-uadk_tool-Add-NO-SVA-mode-test-function-for-ZIP-modu.patch
Patch0138: 0138-drv-qm-fix-spin-lock-destroy.patch
Patch0139: 0139-drv-qm-modify-the-lock-for-send-and-receive-BD.patch
Patch0140: 0140-uadk-v1-fix-goto-warning.patch
Patch0141: 0141-uadk-fix-comment-blank.patch
Patch0142: 0142-uadk-fix-different-name-in-declaration-and-definitio.patch
Patch0143: 0143-uadk-fix-pointer-parameters-are-not-checked.patch
Patch0144: 0144-uadk-fix-cqe-phase.patch
Patch0145: 0145-uadk-v1-fix-include-file-order.patch
Patch0146: 0146-uadk-fix-BufferOverFlow.patch
Patch0147: 0147-uadk-fix-macro-argument-warning.patch
Patch0148: 0148-uadk-driver-init-should-check-ctx-num.patch
Patch0149: 0149-uadk-fix-cast-pointer-problem.patch
Patch0150: 0150-uadk-fix-function-params-usage.patch
Patch0151: 0151-uadk-fix-size_t-usage.patch
Patch0152: 0152-uadk-fix-atoi-usage.patch
Patch0153: 0153-uadk-fix-lm-not-link-problem.patch
Patch0154: 0154-uadk-remove-unneed-comment-and-macro.patch
Patch0155: 0155-drv-hpre-remove-repeatedly-included-header-file.patch
Patch0156: 0156-drv-hpre-add-hpre_result_check.patch
Patch0157: 0157-drv-hpre-move-format-check-to-is_hpre_bin_fmt.patch
Patch0158: 0158-drv-hpre-change-the-parameter-type.patch
Patch0159: 0159-drv-hpre-remove-redundant-blank-line.patch
Patch0160: 0160-drv-qm-add-unlikely-for-branch-prefetch.patch
Patch0161: 0161-drv-qm-remove-redundant-add-1.patch
Patch0162: 0162-drv-qm-remove-useless-parameter-sq_head_index.patch
Patch0163: 0163-uadk-add-wd_-alg-_get_msg.patch
Patch0164: 0164-drv-hpre-support-dump-BD-when-BD-checks-fail.patch
Patch0165: 0165-drv-hpre-bugfix-about-sm2-async-parsing-error.patch
Patch0166: 0166-drv-hpre-bugfix-async-tag-of-rsa-and-dh.patch
Patch0167: 0167-drv-hpre-cleanup-ecc-sqe-parsing-process.patch
%description
This package contains the User Space Accelerator Library
@ -270,6 +338,9 @@ fi
/sbin/ldconfig
%changelog
* Tue Jul 26 2022 Yang Shen <shenyang39@huawei.com> 2.3.21-6
- libwd: backport the patch of uadk from 2.3.31 to 2.3.36
* Mon Mar 21 2022 Yang Shen <shenyang39@huawei.com> 2.3.21-5
- libwd: backport the patch of uadk from 2.3.28 to 2.3.31