diff --git a/0100-drv-sec-modification-for-clean-code.patch b/0100-drv-sec-modification-for-clean-code.patch new file mode 100644 index 0000000..e4aa0ee --- /dev/null +++ b/0100-drv-sec-modification-for-clean-code.patch @@ -0,0 +1,162 @@ +From c46b3f972de457ffdb80325f88eae175bd8bd3a7 Mon Sep 17 00:00:00 2001 +From: Kai Ye +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 +--- + 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 + diff --git a/0101-uadk-fix-mempool-code.patch b/0101-uadk-fix-mempool-code.patch new file mode 100644 index 0000000..cf1f6e3 --- /dev/null +++ b/0101-uadk-fix-mempool-code.patch @@ -0,0 +1,410 @@ +From c9ce97bff9154e712225fb06dc692b5101bd7eef Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0102-uadk-some-clean-code-for-wd.patch b/0102-uadk-some-clean-code-for-wd.patch new file mode 100644 index 0000000..aade206 --- /dev/null +++ b/0102-uadk-some-clean-code-for-wd.patch @@ -0,0 +1,142 @@ +From 60cc5e8ead870777d36eed1242163f678de08226 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + #include + #include +-#include + #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 + diff --git a/0103-wd-sched-modify-default-sched-param.patch b/0103-wd-sched-modify-default-sched-param.patch new file mode 100644 index 0000000..89ee4f8 --- /dev/null +++ b/0103-wd-sched-modify-default-sched-param.patch @@ -0,0 +1,108 @@ +From 9dd275d4e67eb7dc6d4ff3cee49e2929bd497b4f Mon Sep 17 00:00:00 2001 +From: Liulongfang +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 +--- + 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 + #include ++#include + #include + #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 + diff --git a/0104-uadk-update-README.patch b/0104-uadk-update-README.patch new file mode 100644 index 0000000..3ba58ff --- /dev/null +++ b/0104-uadk-update-README.patch @@ -0,0 +1,44 @@ +From 89ce496b9c9f91feb941d6f083771250f886e266 Mon Sep 17 00:00:00 2001 +From: Liulongfang +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 +--- + 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 + diff --git a/0105-uadk-add-BD-id-check-for-sync-mode.patch b/0105-uadk-add-BD-id-check-for-sync-mode.patch new file mode 100644 index 0000000..b20bc1a --- /dev/null +++ b/0105-uadk-add-BD-id-check-for-sync-mode.patch @@ -0,0 +1,406 @@ +From 6e4ee881aa5eb420fc101cf7d8970d3ba202d926 Mon Sep 17 00:00:00 2001 +From: Liulongfang +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 +--- + 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 + diff --git a/0106-uadk-ecc-optimize-create_ecc_out-line.patch b/0106-uadk-ecc-optimize-create_ecc_out-line.patch new file mode 100644 index 0000000..4e0e63c --- /dev/null +++ b/0106-uadk-ecc-optimize-create_ecc_out-line.patch @@ -0,0 +1,80 @@ +From f2b3a8ce0f30c0902ae93edbea5bccd87a166116 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0107-uadk-fix-parameter-of-function-has-different-name.patch b/0107-uadk-fix-parameter-of-function-has-different-name.patch new file mode 100644 index 0000000..5d2fbc5 --- /dev/null +++ b/0107-uadk-fix-parameter-of-function-has-different-name.patch @@ -0,0 +1,344 @@ +From a43bac94144b6bb59a992a3781e5367f67a2af79 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0108-uadk-ecc-fix-local-variable-referenced-in-macro.patch b/0108-uadk-ecc-fix-local-variable-referenced-in-macro.patch new file mode 100644 index 0000000..305741f --- /dev/null +++ b/0108-uadk-ecc-fix-local-variable-referenced-in-macro.patch @@ -0,0 +1,31 @@ +From 91d11133e1f6d79e38da014123ddd0b0dc132be6 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0109-uadk-fix-switch-statement-has-no-default-branch.patch b/0109-uadk-fix-switch-statement-has-no-default-branch.patch new file mode 100644 index 0000000..9352164 --- /dev/null +++ b/0109-uadk-fix-switch-statement-has-no-default-branch.patch @@ -0,0 +1,44 @@ +From af330daeb1d215c312e0e4ff74cb4bc5f0f35cad Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0110-uadk-fix-macro-argument.patch b/0110-uadk-fix-macro-argument.patch new file mode 100644 index 0000000..c8be485 --- /dev/null +++ b/0110-uadk-fix-macro-argument.patch @@ -0,0 +1,112 @@ +From 47eb2bf35cf8bce3f3e9b163fe6e1c5596ce1aa9 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0111-uadk-fix-ret-uninit-problem.patch b/0111-uadk-fix-ret-uninit-problem.patch new file mode 100644 index 0000000..40bd53b --- /dev/null +++ b/0111-uadk-fix-ret-uninit-problem.patch @@ -0,0 +1,29 @@ +From 26406484d65db093e24dd230ad544ed027e6722f Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0112-uadk-qm-optimize-sgl-copy-function.patch b/0112-uadk-qm-optimize-sgl-copy-function.patch new file mode 100644 index 0000000..f350b83 --- /dev/null +++ b/0112-uadk-qm-optimize-sgl-copy-function.patch @@ -0,0 +1,204 @@ +From bd323b07e49644efdb1890ef53232ad32925dd2d Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0113-uadk-fix-problems-with-referencing-header-files.patch b/0113-uadk-fix-problems-with-referencing-header-files.patch new file mode 100644 index 0000000..5ac635e --- /dev/null +++ b/0113-uadk-fix-problems-with-referencing-header-files.patch @@ -0,0 +1,823 @@ +From d1e97dbd394a2a4f1c00cd001f81a08340c33070 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + #include + #include +-#include + #include + #include + #include +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 ++#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 ++#include ++#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 ++#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 ++#include ++ ++#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 + #include + #include ++#include + + #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 + #include + + #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 + #include + #include ++#include + #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 +-#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 + #include + #include + #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 +- + #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 + +-#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 + #include + #include +-#include + + #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 ++#include + #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 + #include + #include +@@ -28,6 +27,7 @@ + #include + #include + #include ++#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 + #include + #include +@@ -29,10 +28,11 @@ + #include + #include + +-#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 + #include + #include +@@ -30,6 +29,7 @@ + #include + #include + ++#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 + #include + #include +@@ -29,6 +28,7 @@ + #include + #include + ++#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 + #include + #include +@@ -28,6 +27,7 @@ + #include + #include + #include ++#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 + #include + #include +-#include + #include + #include + #include + #include + #include +-#include + #include + #include + #include + +-#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 + #include + #include +-#include + #include + #include + #include +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 + #include + #include + ++#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 + #include + #include +-#include + #include +-#include +-#include +-#include + #include + + #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 + #include + #include +-#include + #include + + #include +-#include +-#include + #include + + #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 + #include + #include +-#include + #include + #include + +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 ++#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 + #include + #include +-#include + #include + + #include +-#include +-#include + #include + + #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 + #include + #include +-#include + #include + #include +-#include +-#include + #include + #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 + #include + #include +-#include + #include + + #include +-#include +-#include + #include + + #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 + #include + #include +-#include + #include + + #include +-#include +-#include + #include + + #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 + #include + #include +-#include + #include + + #include +-#include +-#include + #include + + #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 + #include + #include +-#include + #include + + #include +-#include +-#include + #include + + #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 + #include + #include +-#include + #include + + #include +-#include +-#include + #include + + #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 + #include + #include +-#include + + #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 ++#include ++#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 + #include + #include +-#include + #include + #include + #include + #include + #include + #include ++#include + + #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 + #include + +-#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 + #include +-#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 + #include + #include +-#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 + #include +-#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 + #include + +-#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 + #include + #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 + diff --git a/0114-uadk-fix-parameter-used-as-working-variable.patch b/0114-uadk-fix-parameter-used-as-working-variable.patch new file mode 100644 index 0000000..4138677 --- /dev/null +++ b/0114-uadk-fix-parameter-used-as-working-variable.patch @@ -0,0 +1,761 @@ +From 280e01c8a0aae071d54200f9a5fdcdc5035c3a9c Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0115-uadk-move-parameter-check-into-wd_util.c.patch b/0115-uadk-move-parameter-check-into-wd_util.c.patch new file mode 100644 index 0000000..6708028 --- /dev/null +++ b/0115-uadk-move-parameter-check-into-wd_util.c.patch @@ -0,0 +1,305 @@ +From 46321d786961ea5d5a63b12084ee2ed551067c3d Mon Sep 17 00:00:00 2001 +From: Weili Qian +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_.c. + +Signed-off-by: Weili Qian +--- + 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__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 + diff --git a/0116-comp-remove-unused-variable-priv.patch b/0116-comp-remove-unused-variable-priv.patch new file mode 100644 index 0000000..84b6bcc --- /dev/null +++ b/0116-comp-remove-unused-variable-priv.patch @@ -0,0 +1,121 @@ +From aa9833fb3e1f28446e0dc93aa72887002cf70ca0 Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 + diff --git a/0117-ecc-remove-the-lock-in-async-send-funciton.patch b/0117-ecc-remove-the-lock-in-async-send-funciton.patch new file mode 100644 index 0000000..6bf674b --- /dev/null +++ b/0117-ecc-remove-the-lock-in-async-send-funciton.patch @@ -0,0 +1,36 @@ +From 60b860d2fc7029e2399bb2380f1650dd0eff7d51 Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 + diff --git a/0118-dh-remove-the-lock-in-async-send.patch b/0118-dh-remove-the-lock-in-async-send.patch new file mode 100644 index 0000000..b57d088 --- /dev/null +++ b/0118-dh-remove-the-lock-in-async-send.patch @@ -0,0 +1,36 @@ +From 6b02f3609923def84213d3a6e775fa45ddfae1b7 Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 + diff --git a/0119-comp-remove-the-lock-in-async-send.patch b/0119-comp-remove-the-lock-in-async-send.patch new file mode 100644 index 0000000..47f14ef --- /dev/null +++ b/0119-comp-remove-the-lock-in-async-send.patch @@ -0,0 +1,39 @@ +From a4022d3fea696df788b236a686979f84b4aa4e80 Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 + diff --git a/0120-dh-remove-repeated-send-BD.patch b/0120-dh-remove-repeated-send-BD.patch new file mode 100644 index 0000000..4c888d3 --- /dev/null +++ b/0120-dh-remove-repeated-send-BD.patch @@ -0,0 +1,88 @@ +From f33daa68150250815df2a359a54167c0b426c0af Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 + diff --git a/0121-ecc-remove-repeated-send-BD.patch b/0121-ecc-remove-repeated-send-BD.patch new file mode 100644 index 0000000..13f8543 --- /dev/null +++ b/0121-ecc-remove-repeated-send-BD.patch @@ -0,0 +1,87 @@ +From 6cda439c798c470878d1f12beff0a30236b23da3 Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 + diff --git a/0122-rsa-remove-repeated-send-BD.patch b/0122-rsa-remove-repeated-send-BD.patch new file mode 100644 index 0000000..04382f6 --- /dev/null +++ b/0122-rsa-remove-repeated-send-BD.patch @@ -0,0 +1,88 @@ +From 9453dd339c43df967cff11f92f270de6f48615a1 Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 + diff --git a/0123-uadk-move-send-and-recv-code-into-wd_util.c.patch b/0123-uadk-move-send-and-recv-code-into-wd_util.c.patch new file mode 100644 index 0000000..74908f8 --- /dev/null +++ b/0123-uadk-move-send-and-recv-code-into-wd_util.c.patch @@ -0,0 +1,1040 @@ +From d72b1bd6a9fae5dadfbaacf64e51353e78c785c5 Mon Sep 17 00:00:00 2001 +From: Zhiqi Song +Date: Tue, 7 Jun 2022 14:26:49 +0800 +Subject: [PATCH 135/183] uadk: move send and recv code into wd_util.c + +In the synchronization scenario, the code for sending and +receiving BD code is same in wd_.c, so move them +into wd_util.c from wd_.c. + +Signed-off-by: Weili Qian +Signed-off-by: Zhiqi Song +--- + drv/hisi_comp.c | 6 ++-- + drv/hisi_hpre.c | 18 +++++++---- + drv/hisi_sec.c | 44 +++++++++++++++++---------- + include/drv/wd_aead_drv.h | 4 +-- + include/drv/wd_cipher_drv.h | 4 +-- + include/drv/wd_comp_drv.h | 4 +-- + include/drv/wd_dh_drv.h | 4 +-- + include/drv/wd_digest_drv.h | 4 +-- + include/drv/wd_ecc_drv.h | 4 +-- + include/drv/wd_rsa_drv.h | 4 +-- + include/wd_util.h | 18 +++++++++++ + wd_aead.c | 35 ++++------------------ + wd_cipher.c | 35 ++++------------------ + wd_comp.c | 37 ++++------------------- + wd_dh.c | 58 ++++++++--------------------------- + wd_digest.c | 45 ++++++++-------------------- + wd_ecc.c | 60 ++++++++----------------------------- + wd_rsa.c | 60 ++++++++----------------------------- + wd_util.c | 47 +++++++++++++++++++++++++++++ + 19 files changed, 192 insertions(+), 299 deletions(-) + +diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c +index 2a2367b..2c0fc41 100644 +--- a/drv/hisi_comp.c ++++ b/drv/hisi_comp.c +@@ -865,9 +865,10 @@ 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) ++static int hisi_zip_comp_send(handle_t ctx, void *comp_msg) + { + struct hisi_qp *qp = wd_ctx_get_priv(ctx); ++ struct wd_comp_msg *msg = comp_msg; + handle_t h_qp = (handle_t)qp; + struct hisi_zip_sqe sqe = {0}; + __u16 count = 0; +@@ -1020,9 +1021,10 @@ 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) ++static int hisi_zip_comp_recv(handle_t ctx, void *comp_msg) + { + struct hisi_qp *qp = wd_ctx_get_priv(ctx); ++ struct wd_comp_msg *recv_msg = comp_msg; + handle_t h_qp = (handle_t)qp; + struct hisi_zip_sqe sqe = {0}; + __u16 count = 0; +diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c +index 4e62c0f..7fd4189 100644 +--- a/drv/hisi_hpre.c ++++ b/drv/hisi_hpre.c +@@ -499,9 +499,10 @@ static void hpre_exit(void *priv) + } + } + +-static int rsa_send(handle_t ctx, struct wd_rsa_msg *msg) ++static int rsa_send(handle_t ctx, void *rsa_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_rsa_msg *msg = rsa_msg; + struct hisi_hpre_sqe hw_msg; + __u16 send_cnt = 0; + int ret; +@@ -535,10 +536,11 @@ static int rsa_send(handle_t ctx, struct wd_rsa_msg *msg) + return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt); + } + +-static int rsa_recv(handle_t ctx, struct wd_rsa_msg *msg) ++static int rsa_recv(handle_t ctx, void *rsa_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); + struct hisi_hpre_sqe hw_msg = {0}; ++ struct wd_rsa_msg *msg = rsa_msg; + __u16 recv_cnt = 0; + int ret; + +@@ -638,9 +640,10 @@ static int dh_out_transfer(struct wd_dh_msg *msg, + return WD_SUCCESS; + } + +-static int dh_send(handle_t ctx, struct wd_dh_msg *msg) ++static int dh_send(handle_t ctx, void *dh_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_dh_msg *msg = dh_msg; + struct wd_dh_req *req = &msg->req; + struct hisi_hpre_sqe hw_msg; + __u16 send_cnt = 0; +@@ -682,9 +685,10 @@ static int dh_send(handle_t ctx, struct wd_dh_msg *msg) + return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt); + } + +-static int dh_recv(handle_t ctx, struct wd_dh_msg *msg) ++static int dh_recv(handle_t ctx, void *dh_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_dh_msg *msg = dh_msg; + struct hisi_hpre_sqe hw_msg = {0}; + __u16 recv_cnt = 0; + int ret; +@@ -1774,9 +1778,10 @@ free_dst: + return ret; + } + +-static int ecc_send(handle_t ctx, struct wd_ecc_msg *msg) ++static int ecc_send(handle_t ctx, void *ecc_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_ecc_msg *msg = ecc_msg; + + hisi_set_msg_id(h_qp, &msg->tag); + if (msg->req.op_type == WD_SM2_ENCRYPT) +@@ -2336,9 +2341,10 @@ fail: + return ret; + } + +-static int ecc_recv(handle_t ctx, struct wd_ecc_msg *msg) ++static int ecc_recv(handle_t ctx, void *ecc_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_ecc_msg *msg = ecc_msg; + struct hisi_hpre_sqe hw_msg; + __u16 recv_cnt = 0; + int ret; +diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c +index b17ce0f..7f12549 100644 +--- a/drv/hisi_sec.c ++++ b/drv/hisi_sec.c +@@ -906,9 +906,10 @@ static int fill_cipher_bd2(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe) + return 0; + } + +-int hisi_sec_cipher_send(handle_t ctx, struct wd_cipher_msg *msg) ++int hisi_sec_cipher_send(handle_t ctx, void *cipher_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_cipher_msg *msg = cipher_msg; + struct hisi_sec_sqe sqe; + __u16 count = 0; + int ret; +@@ -950,10 +951,11 @@ int hisi_sec_cipher_send(handle_t ctx, struct wd_cipher_msg *msg) + return 0; + } + +-int hisi_sec_cipher_recv(handle_t ctx, struct wd_cipher_msg *recv_msg) ++int hisi_sec_cipher_recv(handle_t ctx, void *cipher_msg) + { +- struct hisi_sec_sqe sqe; + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_cipher_msg *recv_msg = cipher_msg; ++ struct hisi_sec_sqe sqe; + __u16 count = 0; + int ret; + +@@ -1112,9 +1114,10 @@ static int fill_cipher_bd3(struct wd_cipher_msg *msg, struct hisi_sec_sqe3 *sqe) + return 0; + } + +-int hisi_sec_cipher_send_v3(handle_t ctx, struct wd_cipher_msg *msg) ++int hisi_sec_cipher_send_v3(handle_t ctx, void *cipher_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_cipher_msg *msg = cipher_msg; + struct hisi_sec_sqe3 sqe; + __u16 count = 0; + int ret; +@@ -1183,10 +1186,11 @@ static void parse_cipher_bd3(struct hisi_sec_sqe3 *sqe, + recv_msg->out = rmsg->out; + } + +-int hisi_sec_cipher_recv_v3(handle_t ctx, struct wd_cipher_msg *recv_msg) ++int hisi_sec_cipher_recv_v3(handle_t ctx, void *cipher_msg) + { +- struct hisi_sec_sqe3 sqe; + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_cipher_msg *recv_msg = cipher_msg; ++ struct hisi_sec_sqe3 sqe; + __u16 count = 0; + int ret; + +@@ -1332,9 +1336,10 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type) + return 0; + } + +-int hisi_sec_digest_send(handle_t ctx, struct wd_digest_msg *msg) ++int hisi_sec_digest_send(handle_t ctx, void *digest_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_digest_msg *msg = digest_msg; + struct hisi_sec_sqe sqe; + __u16 count = 0; + __u8 scene; +@@ -1396,9 +1401,10 @@ put_sgl: + return ret; + } + +-int hisi_sec_digest_recv(handle_t ctx, struct wd_digest_msg *recv_msg) ++int hisi_sec_digest_recv(handle_t ctx, void *digest_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_digest_msg *recv_msg = digest_msg; + struct hisi_sec_sqe sqe; + __u16 count = 0; + int ret; +@@ -1486,9 +1492,10 @@ static void qm_fill_digest_long_bd3(struct wd_digest_msg *msg, + } + } + +-int hisi_sec_digest_send_v3(handle_t ctx, struct wd_digest_msg *msg) ++int hisi_sec_digest_send_v3(handle_t ctx, void *digest_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_digest_msg *msg = digest_msg; + struct hisi_sec_sqe3 sqe; + __u16 count = 0; + __u16 scene; +@@ -1572,9 +1579,10 @@ static void parse_digest_bd3(struct hisi_sec_sqe3 *sqe, + recv_msg->alg_type = WD_DIGEST; + } + +-int hisi_sec_digest_recv_v3(handle_t ctx, struct wd_digest_msg *recv_msg) ++int hisi_sec_digest_recv_v3(handle_t ctx, void *digest_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_digest_msg *recv_msg = digest_msg; + struct hisi_sec_sqe3 sqe; + __u16 count = 0; + int ret; +@@ -1838,9 +1846,10 @@ static int fill_aead_bd2(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe) + return 0; + } + +-int hisi_sec_aead_send(handle_t ctx, struct wd_aead_msg *msg) ++int hisi_sec_aead_send(handle_t ctx, void *aead_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_aead_msg *msg = aead_msg; + struct hisi_sec_sqe sqe; + __u16 count = 0; + int ret; +@@ -1922,10 +1931,11 @@ static void parse_aead_bd2(struct hisi_sec_sqe *sqe, + sqe->type2.cipher_src_offset; + } + +-int hisi_sec_aead_recv(handle_t ctx, struct wd_aead_msg *recv_msg) ++int hisi_sec_aead_recv(handle_t ctx, void *aead_msg) + { +- struct hisi_sec_sqe sqe; + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_aead_msg *recv_msg = aead_msg; ++ struct hisi_sec_sqe sqe; + __u16 count = 0; + int ret; + +@@ -2103,9 +2113,10 @@ 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) ++int hisi_sec_aead_send_v3(handle_t ctx, void *aead_msg) + { + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_aead_msg *msg = aead_msg; + struct hisi_sec_sqe3 sqe; + __u16 count = 0; + int ret; +@@ -2181,10 +2192,11 @@ static void parse_aead_bd3(struct hisi_sec_sqe3 *sqe, + sqe->cipher_src_offset; + } + +-int hisi_sec_aead_recv_v3(handle_t ctx, struct wd_aead_msg *recv_msg) ++int hisi_sec_aead_recv_v3(handle_t ctx, void *aead_msg) + { +- struct hisi_sec_sqe3 sqe; + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); ++ struct wd_aead_msg *recv_msg = aead_msg; ++ struct hisi_sec_sqe3 sqe; + __u16 count = 0; + int ret; + +diff --git a/include/drv/wd_aead_drv.h b/include/drv/wd_aead_drv.h +index cc28ed5..cca28ba 100644 +--- a/include/drv/wd_aead_drv.h ++++ b/include/drv/wd_aead_drv.h +@@ -70,8 +70,8 @@ struct wd_aead_driver { + __u32 drv_ctx_size; + int (*init)(struct wd_ctx_config_internal *config, void *priv); + void (*exit)(void *priv); +- int (*aead_send)(handle_t ctx, struct wd_aead_msg *msg); +- int (*aead_recv)(handle_t ctx, struct wd_aead_msg *msg); ++ int (*aead_send)(handle_t ctx, void *aead_msg); ++ int (*aead_recv)(handle_t ctx, void *aead_msg); + }; + + void wd_aead_set_driver(struct wd_aead_driver *drv); +diff --git a/include/drv/wd_cipher_drv.h b/include/drv/wd_cipher_drv.h +index 0ec758d..84c9844 100644 +--- a/include/drv/wd_cipher_drv.h ++++ b/include/drv/wd_cipher_drv.h +@@ -56,8 +56,8 @@ struct wd_cipher_driver { + __u32 drv_ctx_size; + int (*init)(struct wd_ctx_config_internal *config, void *priv); + void (*exit)(void *priv); +- int (*cipher_send)(handle_t ctx, struct wd_cipher_msg *msg); +- int (*cipher_recv)(handle_t ctx, struct wd_cipher_msg *msg); ++ int (*cipher_send)(handle_t ctx, void *cipher_msg); ++ int (*cipher_recv)(handle_t ctx, void *cipher_msg); + }; + + void wd_cipher_set_driver(struct wd_cipher_driver *drv); +diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h +index e3d2269..a84f895 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); +- int (*comp_recv)(handle_t ctx, struct wd_comp_msg *msg); ++ int (*comp_send)(handle_t ctx, void *comp_msg); ++ int (*comp_recv)(handle_t ctx, void *comp_msg); + }; + + void wd_comp_set_driver(struct wd_comp_driver *drv); +diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h +index 192e7d8..f8e3065 100644 +--- a/include/drv/wd_dh_drv.h ++++ b/include/drv/wd_dh_drv.h +@@ -30,8 +30,8 @@ struct wd_dh_driver { + int (*init)(struct wd_ctx_config_internal *config, void *priv, + const char *alg_name); + void (*exit)(void *priv); +- int (*send)(handle_t sess, struct wd_dh_msg *msg); +- int (*recv)(handle_t sess, struct wd_dh_msg *msg); ++ int (*send)(handle_t sess, void *dh_msg); ++ int (*recv)(handle_t sess, void *dh_msg); + }; + + void wd_dh_set_driver(struct wd_dh_driver *drv); +diff --git a/include/drv/wd_digest_drv.h b/include/drv/wd_digest_drv.h +index b426ab2..10ce6e1 100644 +--- a/include/drv/wd_digest_drv.h ++++ b/include/drv/wd_digest_drv.h +@@ -58,8 +58,8 @@ struct wd_digest_driver { + __u32 drv_ctx_size; + int (*init)(struct wd_ctx_config_internal *config, void *priv); + void (*exit)(void *priv); +- int (*digest_send)(handle_t ctx, struct wd_digest_msg *msg); +- int (*digest_recv)(handle_t ctx, struct wd_digest_msg *msg); ++ int (*digest_send)(handle_t ctx, void *digest_msg); ++ int (*digest_recv)(handle_t ctx, void *digest_msg); + }; + + void wd_digest_set_driver(struct wd_digest_driver *drv); +diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h +index ca21759..ef98606 100644 +--- a/include/drv/wd_ecc_drv.h ++++ b/include/drv/wd_ecc_drv.h +@@ -184,8 +184,8 @@ struct wd_ecc_driver { + int (*init)(struct wd_ctx_config_internal *config, void *priv, + const char *alg_name); + void (*exit)(void *priv); +- int (*send)(handle_t sess, struct wd_ecc_msg *msg); +- int (*recv)(handle_t sess, struct wd_ecc_msg *msg); ++ int (*send)(handle_t sess, void *ecc_msg); ++ int (*recv)(handle_t sess, void *ecc_msg); + }; + + void wd_ecc_set_driver(struct wd_ecc_driver *drv); +diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h +index bde6bbd..28c3337 100644 +--- a/include/drv/wd_rsa_drv.h ++++ b/include/drv/wd_rsa_drv.h +@@ -53,8 +53,8 @@ struct wd_rsa_driver { + int (*init)(struct wd_ctx_config_internal *config, void *priv, + const char *alg_name); + void (*exit)(void *priv); +- int (*send)(handle_t sess, struct wd_rsa_msg *msg); +- int (*recv)(handle_t sess, struct wd_rsa_msg *msg); ++ int (*send)(handle_t sess, void *rsa_msg); ++ int (*recv)(handle_t sess, void *rsa_msg); + }; + + void wd_rsa_set_driver(struct wd_rsa_driver *drv); +diff --git a/include/wd_util.h b/include/wd_util.h +index 89dfe87..eb250f0 100644 +--- a/include/wd_util.h ++++ b/include/wd_util.h +@@ -99,6 +99,11 @@ struct wd_ctx_attr { + __u8 mode; + }; + ++struct wd_msg_handle { ++ int (*send)(handle_t sess, void *msg); ++ int (*recv)(handle_t sess, void *msg); ++}; ++ + /* + * wd_init_ctx_config() - Init internal ctx configuration. + * @in: ctx configuration in global setting. +@@ -327,6 +332,19 @@ 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_handle_msg_sync() - recv msg from hardware ++ * @msg_handle: callback of msg handle ops. ++ * @ctx: the handle of context. ++ * @msg: the msg of task. ++ * @balance: estimated number of receiving msg. ++ * @epoll_en: whether to enable epoll. ++ * ++ * Return 0 if successful or less than 0 otherwise. ++ */ ++int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx, ++ void *msg, __u64 *balance, bool epoll_en); ++ + /** + * wd_init_check() - Check input parameters for wd__init. + * @config: Ctx configuration input by user. +diff --git a/wd_aead.c b/wd_aead.c +index 3f47f8b..7c07271 100644 +--- a/wd_aead.c ++++ b/wd_aead.c +@@ -19,8 +19,6 @@ + #define WD_AEAD_CCM_GCM_MIN 4U + #define WD_AEAD_CCM_GCM_MAX 16 + #define WD_POOL_MAX_ENTRIES 1024 +-#define MAX_RETRY_COUNTS 200000000 +- + + static int g_aead_mac_len[WD_DIGEST_TYPE_MAX] = { + WD_DIGEST_SM3_LEN, WD_DIGEST_MD5_LEN, WD_DIGEST_SHA1_LEN, +@@ -496,36 +494,15 @@ static void fill_request_msg(struct wd_aead_msg *msg, struct wd_aead_req *req, + static int send_recv_sync(struct wd_ctx_internal *ctx, + struct wd_aead_msg *msg) + { +- __u64 recv_cnt = 0; ++ struct wd_msg_handle msg_handle; + int ret; + +- pthread_spin_lock(&ctx->lock); +- ret = wd_aead_setting.driver->aead_send(ctx->ctx, msg); +- if (unlikely(ret < 0)) { +- WD_ERR("failed to send aead bd!\n"); +- goto out; +- } +- +- do { +- if (wd_aead_setting.config.epoll_en) { +- ret = wd_ctx_wait(ctx->ctx, POLL_TIME); +- if (unlikely(ret < 0)) +- WD_ERR("wd aead ctx wait timeout(%d)!\n", ret); +- } +- ret = wd_aead_setting.driver->aead_recv(ctx->ctx, msg); +- if (ret == -WD_HW_EACCESS) { +- WD_ERR("wd aead recv err!\n"); +- goto out; +- } else if (ret == -WD_EAGAIN) { +- if (++recv_cnt > MAX_RETRY_COUNTS) { +- WD_ERR("wd aead recv timeout fail!\n"); +- ret = -WD_ETIMEDOUT; +- goto out; +- } +- } +- } while (ret < 0); ++ msg_handle.send = wd_aead_setting.driver->aead_send; ++ msg_handle.recv = wd_aead_setting.driver->aead_recv; + +-out: ++ pthread_spin_lock(&ctx->lock); ++ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL, ++ wd_aead_setting.config.epoll_en); + pthread_spin_unlock(&ctx->lock); + return ret; + } +diff --git a/wd_cipher.c b/wd_cipher.c +index be8996f..a7e393b 100644 +--- a/wd_cipher.c ++++ b/wd_cipher.c +@@ -19,8 +19,6 @@ + + #define WD_POOL_MAX_ENTRIES 1024 + #define DES_WEAK_KEY_NUM 16 +-#define MAX_RETRY_COUNTS 200000000 +- + + static const unsigned char des_weak_keys[DES_WEAK_KEY_NUM][DES_KEY_SIZE] = { + /* weak keys */ +@@ -405,36 +403,15 @@ static int wd_cipher_check_params(handle_t h_sess, + static int send_recv_sync(struct wd_ctx_internal *ctx, + struct wd_cipher_msg *msg) + { +- __u64 recv_cnt = 0; ++ struct wd_msg_handle msg_handle; + int ret; + +- pthread_spin_lock(&ctx->lock); +- ret = wd_cipher_setting.driver->cipher_send(ctx->ctx, msg); +- if (unlikely(ret < 0)) { +- WD_ERR("wd cipher send err!\n"); +- goto out; +- } +- +- do { +- if (wd_cipher_setting.config.epoll_en) { +- ret = wd_ctx_wait(ctx->ctx, POLL_TIME); +- if (unlikely(ret < 0)) +- WD_ERR("wd cipher ctx wait timeout(%d)!\n", ret); +- } +- ret = wd_cipher_setting.driver->cipher_recv(ctx->ctx, msg); +- if (ret == -WD_HW_EACCESS) { +- WD_ERR("wd cipher recv err!\n"); +- goto out; +- } else if (ret == -WD_EAGAIN) { +- if (++recv_cnt > MAX_RETRY_COUNTS) { +- WD_ERR("wd cipher recv timeout fail!\n"); +- ret = -WD_ETIMEDOUT; +- goto out; +- } +- } +- } while (ret < 0); ++ msg_handle.send = wd_cipher_setting.driver->cipher_send; ++ msg_handle.recv = wd_cipher_setting.driver->cipher_recv; + +-out: ++ pthread_spin_lock(&ctx->lock); ++ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL, ++ wd_cipher_setting.config.epoll_en); + pthread_spin_unlock(&ctx->lock); + return ret; + } +diff --git a/wd_comp.c b/wd_comp.c +index 6bf5f82..9107d60 100644 +--- a/wd_comp.c ++++ b/wd_comp.c +@@ -18,11 +18,9 @@ + #include "wd_comp.h" + + #define WD_POOL_MAX_ENTRIES 1024 +-#define MAX_RETRY_COUNTS 200000000 + #define HW_CTX_SIZE (64 * 1024) + #define STREAM_CHUNK (128 * 1024) + +- + #define swap_byte(x) \ + ((((x) & 0x000000ff) << 24) | \ + (((x) & 0x0000ff00) << 8) | \ +@@ -396,8 +394,8 @@ 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; ++ struct wd_msg_handle msg_handle; + struct wd_ctx_internal *ctx; +- __u64 recv_count = 0; + __u32 idx; + int ret; + +@@ -410,35 +408,12 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess, + + ctx = config->ctxs + idx; + +- 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); +- return ret; +- } +- +- do { +- if (config->epoll_en) { +- ret = wd_ctx_wait(ctx->ctx, POLL_TIME); +- if (unlikely(ret < 0)) +- WD_ERR("wd ctx wait timeout, ret = %d!\n", ret); +- } +- 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"); +- return ret; +- } else if (ret == -WD_EAGAIN) { +- if (++recv_count > MAX_RETRY_COUNTS) { +- pthread_spin_unlock(&ctx->lock); +- WD_ERR("wd comp recv timeout!\n"); +- return -WD_ETIMEDOUT; +- } +- } +- } while (ret == -WD_EAGAIN); ++ msg_handle.send = wd_comp_setting.driver->comp_send; ++ msg_handle.recv = wd_comp_setting.driver->comp_recv; + ++ pthread_spin_lock(&ctx->lock); ++ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, ++ NULL, config->epoll_en); + pthread_spin_unlock(&ctx->lock); + + return ret; +diff --git a/wd_dh.c b/wd_dh.c +index 5f9dff1..9571ab6 100644 +--- a/wd_dh.c ++++ b/wd_dh.c +@@ -18,12 +18,10 @@ + #include "wd_dh.h" + + #define WD_POOL_MAX_ENTRIES 1024 +-#define DH_BALANCE_THRHD 1280 + #define DH_MAX_KEY_SIZE 512 +-#define DH_RECV_MAX_CNT 60000000 // 1 min + #define WD_DH_G2 2 + +-static __thread int balance; ++static __thread __u64 balance; + + struct wd_dh_sess { + __u32 alg_type; +@@ -191,45 +189,12 @@ static int fill_dh_msg(struct wd_dh_msg *msg, struct wd_dh_req *req, + return 0; + } + +-static int dh_recv_sync(handle_t ctx, struct wd_dh_msg *msg) +-{ +- struct wd_dh_req *req = &msg->req; +- __u32 rx_cnt = 0; +- int ret; +- +- do { +- if (wd_dh_setting.config.epoll_en) { +- ret = wd_ctx_wait(ctx, POLL_TIME); +- if (ret < 0) +- WD_ERR("wd ctx wait timeout(%d)!\n", ret); +- } +- +- ret = wd_dh_setting.driver->recv(ctx, msg); +- if (ret == -WD_EAGAIN) { +- if (rx_cnt++ >= DH_RECV_MAX_CNT) { +- WD_ERR("failed to recv: timeout!\n"); +- return -WD_ETIMEDOUT; +- } +- +- if (balance > DH_BALANCE_THRHD) +- usleep(1); +- } else if (ret < 0) { +- WD_ERR("failed to recv: error = %d!\n", ret); +- return ret; +- } +- } while (ret < 0); +- +- balance = rx_cnt; +- req->status = msg->result; +- +- return GET_NEGATIVE(req->status); +-} +- + int wd_do_dh_sync(handle_t sess, struct wd_dh_req *req) + { + struct wd_ctx_config_internal *config = &wd_dh_setting.config; + handle_t h_sched_ctx = wd_dh_setting.sched.h_sched_ctx; + struct wd_dh_sess *sess_t = (struct wd_dh_sess *)sess; ++ struct wd_msg_handle msg_handle; + struct wd_ctx_internal *ctx; + struct wd_dh_msg msg; + __u32 idx; +@@ -254,19 +219,20 @@ int wd_do_dh_sync(handle_t sess, struct wd_dh_req *req) + if (unlikely(ret)) + return ret; + ++ msg_handle.send = wd_dh_setting.driver->send; ++ msg_handle.recv = wd_dh_setting.driver->recv; ++ + pthread_spin_lock(&ctx->lock); +- 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 = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance, ++ wd_dh_setting.config.epoll_en); ++ pthread_spin_unlock(&ctx->lock); ++ if (unlikely(ret)) ++ return ret; + +- ret = dh_recv_sync(ctx->ctx, &msg); + req->pri_bytes = msg.req.pri_bytes; +-fail: +- pthread_spin_unlock(&ctx->lock); ++ req->status = msg.result; + +- return ret; ++ return GET_NEGATIVE(msg.result); + } + + int wd_do_dh_async(handle_t sess, struct wd_dh_req *req) +diff --git a/wd_digest.c b/wd_digest.c +index 46546cb..0fff7c8 100644 +--- a/wd_digest.c ++++ b/wd_digest.c +@@ -17,8 +17,6 @@ + + #define WD_POOL_MAX_ENTRIES 1024 + #define DES_WEAK_KEY_NUM 4 +-#define MAX_RETRY_COUNTS 200000000 +- + + static int g_digest_mac_len[WD_DIGEST_TYPE_MAX] = { + WD_DIGEST_SM3_LEN, WD_DIGEST_MD5_LEN, WD_DIGEST_SHA1_LEN, +@@ -294,41 +292,24 @@ static void fill_request_msg(struct wd_digest_msg *msg, + static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *dsess, + struct wd_digest_msg *msg) + { +- __u64 recv_cnt = 0; ++ struct wd_msg_handle msg_handle; + int ret; + ++ msg_handle.send = wd_digest_setting.driver->digest_send; ++ msg_handle.recv = wd_digest_setting.driver->digest_recv; ++ + pthread_spin_lock(&ctx->lock); +- ret = wd_digest_setting.driver->digest_send(ctx->ctx, msg); +- if (unlikely(ret < 0)) { +- WD_ERR("failed to send bd!\n"); ++ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, ++ NULL, wd_digest_setting.config.epoll_en); ++ if (unlikely(ret)) + goto out; +- } + +- do { +- if (wd_digest_setting.config.epoll_en) { +- ret = wd_ctx_wait(ctx->ctx, POLL_TIME); +- if (unlikely(ret < 0)) +- WD_ERR("wd digest ctx wait timeout(%d)!\n", ret); +- } +- ret = wd_digest_setting.driver->digest_recv(ctx->ctx, msg); +- if (ret == -WD_HW_EACCESS) { +- WD_ERR("wd digest recv err!\n"); +- goto out; +- } else if (ret == -WD_EAGAIN) { +- if (++recv_cnt > MAX_RETRY_COUNTS) { +- WD_ERR("wd digest recv timeout fail!\n"); +- ret = -WD_ETIMEDOUT; +- goto out; +- } +- } +- +- /* +- * 'out_bytes' can be expressed BD state, non-zero is final BD or +- * middle BD as stream mode. +- */ +- if (msg->has_next) +- dsess->bd_state = msg->out_bytes; +- } while (ret < 0); ++ /* ++ * 'out_bytes' can be expressed BD state, non-zero is final BD or ++ * middle BD as stream mode. ++ */ ++ if (msg->has_next) ++ dsess->bd_state = msg->out_bytes; + + out: + pthread_spin_unlock(&ctx->lock); +diff --git a/wd_ecc.c b/wd_ecc.c +index f22b72d..76c9d5f 100644 +--- a/wd_ecc.c ++++ b/wd_ecc.c +@@ -20,8 +20,6 @@ + #define WD_POOL_MAX_ENTRIES 1024 + #define WD_ECC_CTX_MSG_NUM 64 + #define WD_ECC_MAX_CTX 256 +-#define ECC_BALANCE_THRHD 1280 +-#define ECC_RECV_MAX_CNT 60000000 + #define ECC_MAX_HW_BITS 521 + #define ECC_MAX_KEY_SIZE BITS_TO_BYTES(ECC_MAX_HW_BITS) + #define ECC_MAX_IN_NUM 4 +@@ -34,7 +32,7 @@ + #define GET_NEGATIVE(val) (0 - (val)) + #define ZA_PARAM_NUM 6 + +-static __thread int balance; ++static __thread __u64 balance; + + struct curve_param_desc { + __u32 type; +@@ -1386,46 +1384,12 @@ static void msg_pack(char *dst, __u64 *out_len, + *out_len += src_len; + } + +-static int ecc_recv_sync(handle_t ctx, struct wd_ecc_msg *msg) +-{ +- struct wd_ecc_req *req = &msg->req; +- __u32 rx_cnt = 0; +- int ret; +- +- do { +- if (wd_ecc_setting.config.epoll_en) { +- ret = wd_ctx_wait(ctx, POLL_TIME); +- if (ret < 0) +- WD_ERR("wd ctx wait timeout(%d)!\n", ret); +- } +- +- ret = wd_ecc_setting.driver->recv(ctx, msg); +- if (ret == -WD_EAGAIN) { +- if (rx_cnt++ >= ECC_RECV_MAX_CNT) { +- WD_ERR("failed to recv: timeout!\n"); +- return -WD_ETIMEDOUT; +- } +- +- if (balance > ECC_BALANCE_THRHD) +- usleep(1); +- } else if (ret < 0) { +- WD_ERR("failed to recv: error = %d!\n", ret); +- return ret; +- } +- } while (ret < 0); +- +- balance = rx_cnt; +- req->status = msg->result; +- req->dst_bytes = msg->req.dst_bytes; +- +- return GET_NEGATIVE(req->status); +-} +- + int wd_do_ecc_sync(handle_t h_sess, struct wd_ecc_req *req) + { + struct wd_ctx_config_internal *config = &wd_ecc_setting.config; + handle_t h_sched_ctx = wd_ecc_setting.sched.h_sched_ctx; + struct wd_ecc_sess *sess = (struct wd_ecc_sess *)h_sess; ++ struct wd_msg_handle msg_handle; + struct wd_ctx_internal *ctx; + struct wd_ecc_msg msg; + __u32 idx; +@@ -1450,18 +1414,20 @@ int wd_do_ecc_sync(handle_t h_sess, struct wd_ecc_req *req) + if (unlikely(ret)) + return ret; + +- pthread_spin_lock(&ctx->lock); +- 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; +- } ++ msg_handle.send = wd_ecc_setting.driver->send; ++ msg_handle.recv = wd_ecc_setting.driver->recv; + +- ret = ecc_recv_sync(ctx->ctx, &msg); +-fail: ++ pthread_spin_lock(&ctx->lock); ++ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance, ++ wd_ecc_setting.config.epoll_en); + pthread_spin_unlock(&ctx->lock); ++ if (unlikely(ret)) ++ return ret; + +- return ret; ++ req->dst_bytes = msg.req.dst_bytes; ++ req->status = msg.result; ++ ++ return GET_NEGATIVE(msg.result); + } + + static void get_sign_out_params(struct wd_ecc_out *out, +diff --git a/wd_rsa.c b/wd_rsa.c +index 024f0e0..868e78b 100644 +--- a/wd_rsa.c ++++ b/wd_rsa.c +@@ -19,11 +19,9 @@ + #define WD_POOL_MAX_ENTRIES 1024 + #define WD_HW_EACCESS 62 + +-#define RSA_BALANCE_THRHD 1280 + #define RSA_MAX_KEY_SIZE 512 +-#define RSA_RECV_MAX_CNT 60000000 // 1 min + +-static __thread int balance; ++static __thread __u64 balance; + + struct wd_rsa_pubkey { + struct wd_dtb n; +@@ -251,46 +249,12 @@ static int fill_rsa_msg(struct wd_rsa_msg *msg, struct wd_rsa_req *req, + return 0; + } + +-static int rsa_recv_sync(handle_t ctx, struct wd_rsa_msg *msg) +-{ +- struct wd_rsa_req *req = &msg->req; +- __u32 rx_cnt = 0; +- int ret; +- +- do { +- if (wd_rsa_setting.config.epoll_en) { +- ret = wd_ctx_wait(ctx, POLL_TIME); +- if (ret < 0) +- WD_ERR("wd ctx wait timeout(%d)!\n", ret); +- } +- +- ret = wd_rsa_setting.driver->recv(ctx, msg); +- if (ret == -WD_EAGAIN) { +- if (rx_cnt++ >= RSA_RECV_MAX_CNT) { +- WD_ERR("failed to recv: timeout!\n"); +- return -WD_ETIMEDOUT; +- } +- +- if (balance > RSA_BALANCE_THRHD) +- usleep(1); +- } else if (ret < 0) { +- WD_ERR("failed to recv: error = %d!\n", ret); +- return ret; +- } +- } while (ret < 0); +- +- balance = rx_cnt; +- req->status = msg->result; +- req->dst_bytes = msg->req.dst_bytes; +- +- return GET_NEGATIVE(req->status); +-} +- + int wd_do_rsa_sync(handle_t h_sess, struct wd_rsa_req *req) + { + struct wd_ctx_config_internal *config = &wd_rsa_setting.config; + handle_t h_sched_ctx = wd_rsa_setting.sched.h_sched_ctx; + struct wd_rsa_sess *sess = (struct wd_rsa_sess *)h_sess; ++ struct wd_msg_handle msg_handle; + struct wd_ctx_internal *ctx; + struct wd_rsa_msg msg; + __u32 idx; +@@ -315,18 +279,20 @@ int wd_do_rsa_sync(handle_t h_sess, struct wd_rsa_req *req) + if (unlikely(ret)) + return ret; + +- pthread_spin_lock(&ctx->lock); +- 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; +- } ++ msg_handle.send = wd_rsa_setting.driver->send; ++ msg_handle.recv = wd_rsa_setting.driver->recv; + +- ret = rsa_recv_sync(ctx->ctx, &msg); +-fail: ++ pthread_spin_lock(&ctx->lock); ++ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance, ++ wd_rsa_setting.config.epoll_en); + pthread_spin_unlock(&ctx->lock); ++ if (unlikely(ret)) ++ return ret; + +- return ret; ++ req->dst_bytes = msg.req.dst_bytes; ++ req->status = msg.result; ++ ++ return GET_NEGATIVE(msg.result); + } + + int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req) +diff --git a/wd_util.c b/wd_util.c +index 4d5faf9..de77d1e 100644 +--- a/wd_util.c ++++ b/wd_util.c +@@ -17,6 +17,9 @@ + + #define WD_ASYNC_DEF_POLL_NUM 1 + #define WD_ASYNC_DEF_QUEUE_DEPTH 1024 ++#define WD_BALANCE_THRHD 1280 ++#define WD_RECV_MAX_CNT_SLEEP 60000000 ++#define WD_RECV_MAX_CNT_NOSLEEP 200000000 + + struct msg_pool { + /* message array allocated dynamically */ +@@ -1629,6 +1632,50 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en) + return 0; + } + ++int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx, ++ void *msg, __u64 *balance, bool epoll_en) ++{ ++ __u64 timeout = WD_RECV_MAX_CNT_NOSLEEP; ++ __u64 rx_cnt = 0; ++ int ret; ++ ++ if (balance) ++ timeout = WD_RECV_MAX_CNT_SLEEP; ++ ++ ret = msg_handle->send(ctx, msg); ++ if (unlikely(ret < 0)) { ++ WD_ERR("failed to send msg to hw, ret = %d!\n", ret); ++ return ret; ++ } ++ ++ do { ++ if (epoll_en) { ++ ret = wd_ctx_wait(ctx, POLL_TIME); ++ if (ret < 0) ++ WD_ERR("wd ctx wait timeout(%d)!\n", ret); ++ } ++ ++ ret = msg_handle->recv(ctx, msg); ++ if (ret == -WD_EAGAIN) { ++ if (unlikely(rx_cnt++ >= timeout)) { ++ WD_ERR("failed to recv msg: timeout!\n"); ++ return -WD_ETIMEDOUT; ++ } ++ ++ if (balance && *balance > WD_BALANCE_THRHD) ++ usleep(1); ++ } else if (unlikely(ret < 0)) { ++ WD_ERR("failed to recv msg: error = %d!\n", ret); ++ return ret; ++ } ++ } while (ret < 0); ++ ++ if (balance) ++ *balance = rx_cnt; ++ ++ return ret; ++} ++ + int wd_init_param_check(struct wd_ctx_config *config, struct wd_sched *sched) + { + if (!config || !config->ctxs || !config->ctxs[0].ctx) { +-- +2.27.0 + diff --git a/0124-uadk-missing-header-file-after-install-uadk.patch b/0124-uadk-missing-header-file-after-install-uadk.patch new file mode 100644 index 0000000..990d506 --- /dev/null +++ b/0124-uadk-missing-header-file-after-install-uadk.patch @@ -0,0 +1,38 @@ +From 14c04483057e73f7b5781766d48802055051d59d Mon Sep 17 00:00:00 2001 +From: Kai Ye +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 +--- + 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 + diff --git a/0125-uadk-support-some-uadk-dfx-stronger-features.patch b/0125-uadk-support-some-uadk-dfx-stronger-features.patch new file mode 100644 index 0000000..555cf92 --- /dev/null +++ b/0125-uadk-support-some-uadk-dfx-stronger-features.patch @@ -0,0 +1,1212 @@ +From 0951f91ba62c25a3bad11bdb16384692c640a0aa Mon Sep 17 00:00:00 2001 +From: Kai Ye +Date: Wed, 22 Jun 2022 10:26:28 +0800 +Subject: [PATCH 125/167] uadk: support some uadk dfx stronger features + +1. Add the function of setting the uadk log level, include error, info, + debug by syslog. the uadk log can be printed in message or syslog + file default. You can set your own uadk.log file in rsyslog.conf. + If selected the static compilation, the syslog will not be used. +2. The number of packets in a queue can be read through the + 'uadk_tool'. the maximum number of queues supported is 1024. +3. The 'uadk_tool' supports displaying the library build date. supports + displaying the environment variables. more details, use 'uadk_tool dfx + --help or uadk_tool --help'. + +Signed-off-by: Kai Ye +--- + Makefile.am | 5 + + include/wd.h | 69 +++-- + include/wd_alg_common.h | 1 + + include/wd_util.h | 25 +- + test/hisi_zip_test/test_lib.c | 2 + + uadk_tool/Makefile.am | 11 +- + .../{ => benchmark}/sec_soft_benchmark.c | 0 + .../{ => benchmark}/sec_soft_benchmark.h | 0 + .../{ => benchmark}/sec_uadk_benchmark.c | 0 + .../{ => benchmark}/sec_uadk_benchmark.h | 0 + uadk_tool/{ => benchmark}/sec_wd_benchmark.c | 0 + uadk_tool/{ => benchmark}/sec_wd_benchmark.h | 0 + uadk_tool/{ => benchmark}/uadk_benchmark.c | 3 +- + uadk_tool/{ => benchmark}/uadk_benchmark.h | 2 +- + uadk_tool/dfx/uadk_dfx.c | 253 ++++++++++++++++++ + uadk_tool/{ => dfx}/uadk_dfx.h | 3 - + uadk_tool/uadk_dfx.c | 79 ------ + uadk_tool/uadk_tool.c | 21 +- + wd.c | 79 +++++- + wd_aead.c | 4 +- + wd_cipher.c | 3 + + wd_comp.c | 2 + + wd_dh.c | 2 + + wd_digest.c | 2 + + wd_ecc.c | 6 +- + wd_rsa.c | 2 + + wd_util.c | 91 ++++++- + 27 files changed, 528 insertions(+), 137 deletions(-) + rename uadk_tool/{ => benchmark}/sec_soft_benchmark.c (100%) + rename uadk_tool/{ => benchmark}/sec_soft_benchmark.h (100%) + rename uadk_tool/{ => benchmark}/sec_uadk_benchmark.c (100%) + rename uadk_tool/{ => benchmark}/sec_uadk_benchmark.h (100%) + rename uadk_tool/{ => benchmark}/sec_wd_benchmark.c (100%) + rename uadk_tool/{ => benchmark}/sec_wd_benchmark.h (100%) + rename uadk_tool/{ => benchmark}/uadk_benchmark.c (99%) + rename uadk_tool/{ => benchmark}/uadk_benchmark.h (97%) + create mode 100644 uadk_tool/dfx/uadk_dfx.c + rename uadk_tool/{ => dfx}/uadk_dfx.h (59%) + delete mode 100644 uadk_tool/uadk_dfx.c + +diff --git a/Makefile.am b/Makefile.am +index d7e49f7..7a097f9 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -23,7 +23,11 @@ MINOR = 3 + REVISION = 21 + UADK_VERSION = -version-number ${MAJOR}:${MINOR}:${REVISION} + ++DAY = 11 ++MONTH = Jun ++YEAR = 2022 + AM_CFLAGS+= -DUADK_VERSION_NUMBER="\"libwd version: ${MAJOR}.${MINOR}.${REVISION}\"" ++AM_CFLAGS+= -DUADK_RELEASED_TIME="\"Released ${MONTH} ${DAY}, ${YEAR}\"" + + 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 \ +@@ -78,6 +82,7 @@ libhisi_hpre_la_SOURCES=drv/hisi_hpre.c drv/hisi_qm_udrv.c \ + hisi_qm_udrv.h wd_hpre_drv.h + if WD_STATIC_DRV + AM_CFLAGS += -DWD_STATIC_DRV ++AM_CFLAGS += -DWD_NO_LOG + + libwd_la_LIBADD = $(libwd_la_OBJECTS) -lnuma + +diff --git a/include/wd.h b/include/wd.h +index 56c4109..8c45522 100644 +--- a/include/wd.h ++++ b/include/wd.h +@@ -8,9 +8,11 @@ + #define __WD_H + #include + #include ++#include + #include + #include + #include ++#include + #include + #include + #include "uacce.h" +@@ -25,39 +27,37 @@ extern "C" { + #define MAX_DEV_NAME_LEN 256 + #define LINUX_CRTDIR_SIZE 1 + #define LINUX_PRTDIR_SIZE 2 ++#define WD_CTX_CNT_NUM 1024 ++#define WD_IPC_KEY 0x500011 + + typedef void (*wd_log)(const char *format, ...); + +-#ifndef WD_ERR +-#ifndef WITH_LOG_FILE +-extern wd_log log_out; +- +-#define __WD_FILENAME__ (strrchr(__FILE__, '/') ? \ +- ((char *)((uintptr_t)strrchr(__FILE__, '/') + 1)) : __FILE__) +- +-#define WD_ERR(format, args...) \ +- (log_out ? log_out("[%s, %d, %s]:"format, \ +- __WD_FILENAME__, __LINE__, __func__, ##args) : \ +- fprintf(stderr, format, ##args)) ++#ifndef WD_NO_LOG ++#define WD_DEBUG(fmt, args...) \ ++ do {\ ++ openlog("uadk-debug", LOG_CONS | LOG_PID, LOG_LOCAL5);\ ++ syslog(LOG_DEBUG, fmt, ##args);\ ++ } while (0) ++ ++#define WD_INFO(fmt, args...) \ ++ do {\ ++ openlog("uadk-info", LOG_CONS | LOG_PID, LOG_LOCAL5);\ ++ syslog(LOG_INFO, fmt, ##args);\ ++ } while (0) ++ ++#define WD_ERR(fmt, args...) \ ++ do {\ ++ openlog("uadk-err", LOG_CONS | LOG_PID, LOG_LOCAL5);\ ++ syslog(LOG_ERR, fmt, ##args);\ ++ } while (0) + #else +-extern FILE *flog_fd; +-#define WD_ERR(format, args...) do { \ +- if (!flog_fd) \ +- flog_fd = fopen(WITH_LOG_FILE, "a+"); \ +- if (flog_fd) \ +- fprintf(flog_fd, format, ##args); \ +- else \ +- fprintf(stderr, "log %s not exists!", \ +- WITH_LOG_FILE); \ +-} while (0) +-#endif ++#define OPEN_LOG(s) ++#define WD_DEBUG(fmt, args...) fprintf(stderr, fmt, ##args) ++#define WD_INFO(fmt, args...) fprintf(stderr, fmt, ##args) ++#define WD_ERR(fmt, args...) fprintf(stderr, fmt, ##args) + #endif + +-#ifdef DEBUG_LOG +-#define dbg(msg, ...) fprintf(stderr, msg, ##__VA_ARGS__) +-#else +-#define dbg(msg, ...) +-#endif ++#define WD_CONSOLE printf + + /* WD error code */ + #define WD_SUCCESS 0 +@@ -488,6 +488,21 @@ 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_get_version() - Get the libwd version number and released time. ++ */ ++void wd_get_version(void); ++ ++/** ++ * wd_need_debug() - Get the debug flag from rsyslog.cnf ++ */ ++bool wd_need_debug(void); ++ ++/** ++ * wd_need_info() - Get the info flag from rsyslog.cnf ++ */ ++bool wd_need_info(void); ++ + #ifdef __cplusplus + } + #endif +diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h +index 855f71d..c455dc3 100644 +--- a/include/wd_alg_common.h ++++ b/include/wd_alg_common.h +@@ -76,6 +76,7 @@ struct wd_ctx_config_internal { + void *priv; + int pid; + bool epoll_en; ++ unsigned long *msg_cnt; + }; + + /** +diff --git a/include/wd_util.h b/include/wd_util.h +index eb250f0..83a9684 100644 +--- a/include/wd_util.h ++++ b/include/wd_util.h +@@ -8,6 +8,8 @@ + #define __WD_UTIL_H + + #include ++#include ++#include + #include + #include "wd_alg_common.h" + +@@ -292,7 +294,7 @@ int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx); + */ + 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. +@@ -304,7 +306,7 @@ int wd_alg_get_env_param(struct wd_env_config *env_config, + struct wd_ctx_attr attr, + __u32 *num, __u8 *is_enable); + +-/* ++/** + * wd_set_ctx_attr() - set node type and mode for ctx + * @ctx_attr: ctx attributes pointer. + * @node: numa id. +@@ -315,7 +317,7 @@ int wd_alg_get_env_param(struct wd_env_config *env_config, + int wd_set_ctx_attr(struct wd_ctx_attr *ctx_attr, + __u32 node, __u32 type, __u8 mode, __u32 num); + +-/* ++/** + * wd_check_ctx() - check ctx mode and index + * @config: ctx config pointer. + * @mode: synchronous or asynchronous mode. +@@ -354,6 +356,23 @@ int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx, + */ + int wd_init_param_check(struct wd_ctx_config *config, struct wd_sched *sched); + ++/** ++ * wd_dfx_msg_cnt() - Message counter interface for ctx ++ * @msg: Shared memory addr. ++ * @numSize: Number of elements. ++ * @index: Indicates the CTX index. ++ */ ++static inline void wd_dfx_msg_cnt(unsigned long *msg, __u32 numsize, __u32 idx) ++{ ++ bool ret; ++ ++ ret = wd_need_info(); ++ if (idx > numsize || !ret) ++ return; ++ ++ msg[idx]++; ++} ++ + #ifdef __cplusplus + } + #endif +diff --git a/test/hisi_zip_test/test_lib.c b/test/hisi_zip_test/test_lib.c +index 374244a..5918699 100644 +--- a/test/hisi_zip_test/test_lib.c ++++ b/test/hisi_zip_test/test_lib.c +@@ -22,6 +22,8 @@ struct check_rand_ctx { + unsigned short state[3]; + }; + ++#define dbg(msg, ...) fprintf(stderr, msg, ##__VA_ARGS__) ++ + static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_spinlock_t lock; + static int count = 0; +diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am +index da5b229..f04b2f0 100644 +--- a/uadk_tool/Makefile.am ++++ b/uadk_tool/Makefile.am +@@ -1,13 +1,16 @@ + ACLOCAL_AMFLAGS = -I m4 -I./include +-AM_CFLAGS=-Wall -fno-strict-aliasing -I$(top_srcdir) -I$(top_srcdir)/include \ ++AUTOMAKE_OPTIONS = foreign subdir-objects ++AM_CFLAGS=-Wall -fno-strict-aliasing -I$(top_srcdir) -I$(top_srcdir)/benchmark/include \ + -pthread + + #AUTOMAKE_OPTIONS = subdir-objects + + bin_PROGRAMS=uadk_tool + +-uadk_tool_SOURCES=uadk_tool.c uadk_dfx.c uadk_benchmark.c \ +- sec_uadk_benchmark.c sec_wd_benchmark.c ++uadk_tool_SOURCES=uadk_tool.c dfx/uadk_dfx.c dfx/uadk_dfx.h \ ++ benchmark/uadk_benchmark.c benchmark/uadk_benchmark.h \ ++ benchmark/sec_uadk_benchmark.c benchmark/sec_uadk_benchmark.h \ ++ benchmark/sec_wd_benchmark.c benchmark/sec_wd_benchmark.h + + if WD_STATIC_DRV + AM_CFLAGS+=-Bstatic +@@ -27,7 +30,7 @@ uadk_tool_LDFLAGS=-Wl,-rpath,'/usr/local/lib' + if WITH_OPENSSL_DIR + AM_CFLAGS+= -DWITH_OPENSSL_DIR -I$(with_openssl_dir)/include + +-uadk_tool_SOURCES+=sec_soft_benchmark.c ++uadk_tool_SOURCES+=benchmark/sec_soft_benchmark.c benchmark/sec_soft_benchmark.h + + if WD_STATIC_DRV + uadk_tool_LDADD+= $(with_openssl_dir)/libcrypto.a +diff --git a/uadk_tool/sec_soft_benchmark.c b/uadk_tool/benchmark/sec_soft_benchmark.c +similarity index 100% +rename from uadk_tool/sec_soft_benchmark.c +rename to uadk_tool/benchmark/sec_soft_benchmark.c +diff --git a/uadk_tool/sec_soft_benchmark.h b/uadk_tool/benchmark/sec_soft_benchmark.h +similarity index 100% +rename from uadk_tool/sec_soft_benchmark.h +rename to uadk_tool/benchmark/sec_soft_benchmark.h +diff --git a/uadk_tool/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c +similarity index 100% +rename from uadk_tool/sec_uadk_benchmark.c +rename to uadk_tool/benchmark/sec_uadk_benchmark.c +diff --git a/uadk_tool/sec_uadk_benchmark.h b/uadk_tool/benchmark/sec_uadk_benchmark.h +similarity index 100% +rename from uadk_tool/sec_uadk_benchmark.h +rename to uadk_tool/benchmark/sec_uadk_benchmark.h +diff --git a/uadk_tool/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c +similarity index 100% +rename from uadk_tool/sec_wd_benchmark.c +rename to uadk_tool/benchmark/sec_wd_benchmark.c +diff --git a/uadk_tool/sec_wd_benchmark.h b/uadk_tool/benchmark/sec_wd_benchmark.h +similarity index 100% +rename from uadk_tool/sec_wd_benchmark.h +rename to uadk_tool/benchmark/sec_wd_benchmark.h +diff --git a/uadk_tool/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c +similarity index 99% +rename from uadk_tool/uadk_benchmark.c +rename to uadk_tool/benchmark/uadk_benchmark.c +index 8c3c96f..84941d5 100644 +--- a/uadk_tool/uadk_benchmark.c ++++ b/uadk_tool/benchmark/uadk_benchmark.c +@@ -567,7 +567,7 @@ static void print_help(void) + ACC_TST_PRT("UPDATE:2021-7-28\n"); + } + +-void benchmark_cmd_parse(int argc, char *argv[], struct acc_option *option) ++int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) + { + int option_index = 0; + int c; +@@ -638,6 +638,7 @@ void benchmark_cmd_parse(int argc, char *argv[], struct acc_option *option) + exit(-1); + } + } ++ return 0; + } + + int acc_option_convert(struct acc_option *option) +diff --git a/uadk_tool/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h +similarity index 97% +rename from uadk_tool/uadk_benchmark.h +rename to uadk_tool/benchmark/uadk_benchmark.h +index 7ce0426..2cb3dc0 100644 +--- a/uadk_tool/uadk_benchmark.h ++++ b/uadk_tool/benchmark/uadk_benchmark.h +@@ -170,7 +170,7 @@ extern void add_recv_data(u32 cnt); + extern void add_send_complete(void); + extern u32 get_recv_time(void); + +-void benchmark_cmd_parse(int argc, char *argv[], struct acc_option *option); ++int acc_cmd_parse(int argc, char *argv[], struct acc_option *option); + int acc_default_case(struct acc_option *option); + int acc_option_convert(struct acc_option *option); + int acc_benchmark_run(struct acc_option *option); +diff --git a/uadk_tool/dfx/uadk_dfx.c b/uadk_tool/dfx/uadk_dfx.c +new file mode 100644 +index 0000000..796135a +--- /dev/null ++++ b/uadk_tool/dfx/uadk_dfx.c +@@ -0,0 +1,253 @@ ++/* SPDX-License-Identifier: Apache-2.0 */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "include/wd.h" ++#include "uadk_dfx.h" ++ ++#define uadk_build_date() printf("built on: %s %s\n", __DATE__, __TIME__) ++#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) ++#define PRIVILEGE_FLAG 666 ++ ++struct uadk_env_var { ++ const char *module; ++ const char *alg; ++ const char *ctx_num_var; ++ const char *epoll_en_var; ++}; ++ ++struct uadk_env_table { ++ int sync_ctx_num; ++ int sync_numa; ++ int async_ctx_num; ++ int async_numa; ++ int poll_en; ++}; ++ ++enum dfx_op_type { ++ DISPLAY_VERSION = 2, ++ DISPLAY_DATE, ++ DISPLAY_DIR, ++ DISPLAY_ENV, ++ DISPLAY_COUNT, ++ DISPLAY_HELP, ++}; ++ ++const char *uadk_modules[] = {"sec", "hpre", "zip"}; ++ ++const struct uadk_env_var env_vars[] = { ++ {.module = "sec", .alg = "CIPHER", .ctx_num_var = "WD_CIPHER_CTX_NUM", ++ .epoll_en_var = "WD_CIPHER_EPOLL_EN"}, ++ {.module = "sec", .alg = "AEAD", .ctx_num_var = "WD_AEAD_CTX_NUM", ++ .epoll_en_var = "WD_AEAD_EPOLL_EN"}, ++ {.module = "sec", .alg = "DIGEST", .ctx_num_var = "WD_DIGEST_CTX_NUM", ++ .epoll_en_var = "WD_DIGEST_EPOLL_EN"}, ++ {.module = "hpre", .alg = "DH", .ctx_num_var = "WD_DH_CTX_NUM", ++ .epoll_en_var = "WD_DH_EPOLL_EN"}, ++ {.module = "hpre", .alg = "RSA", .ctx_num_var = "WD_RSA_CTX_NUM", ++ .epoll_en_var = "WD_RSA_EPOLL_EN"}, ++ {.module = "hpre", .alg = "ECC", .ctx_num_var = "WD_ECC_CTX_NUM", ++ .epoll_en_var = "WD_ECC_EPOLL_EN"}, ++ {.module = "zip", .alg = "COMP", .ctx_num_var = "WD_COMP_CTX_NUM", ++ .epoll_en_var = "WD_COMP_EPOLL_EN"}, ++}; ++ ++static void dump_ctx_count(unsigned long *count) ++{ ++ __u32 idx = 0; ++ int i; ++ ++ if (!count) ++ return; ++ ++ printf("displays the ctx counter value...\n"); ++ for (i = 0; i < WD_CTX_CNT_NUM; i++) { ++ if (count[i]) { ++ printf("ctx-[%d]:%lu \t", i, count[i]); ++ idx++; ++ } else { ++ continue; ++ } ++ ++ if ((idx & 0x3) == 0) ++ printf("\n"); ++ } ++ printf("\n"); ++} ++ ++static int get_shared_id(void) ++{ ++ int shm; ++ ++ shm = shmget(WD_IPC_KEY, sizeof(unsigned long) * WD_CTX_CNT_NUM, ++ IPC_CREAT | PRIVILEGE_FLAG); ++ if (shm < 0) { ++ printf("failed to get the shared memory id.\n"); ++ return -EINVAL; ++ } ++ ++ return shm; ++} ++ ++static int uadk_shared_read(void) ++{ ++ unsigned long *shared; ++ void *ptr; ++ int shm; ++ ++ shm = get_shared_id(); ++ if (shm < 0) ++ return -EINVAL; ++ ++ ptr = (int *)shmat(shm, NULL, 0); ++ if (ptr < 0) { ++ printf("failed to get the shared memory addr.\n"); ++ return -EINVAL; ++ } ++ ++ shared = (unsigned long *)ptr; ++ ++ printf("get the shared memory addr successful.\n"); ++ dump_ctx_count(shared); ++ ++ shmdt(ptr); ++ ++ return 0; ++} ++ ++bool uadk_check_module(const char *module) ++{ ++ int i; ++ ++ for (i = 0; i < ARRAY_SIZE(uadk_modules); i++) { ++ if (!strncmp(module, uadk_modules[i], strlen(module))) ++ return true; ++ } ++ ++ return false; ++} ++ ++static void uadk_ctx_env_config(const char *s) ++{ ++ char *env_setion; ++ ++ if (!s) { ++ printf("input ctx env config is NULL.\n"); ++ return; ++ } ++ ++ env_setion = getenv(s); ++ if (!env_setion) { ++ printf("not found the %s env config!\n", s); ++ return; ++ } ++ ++ printf("%s=%s\n", s, env_setion); ++} ++ ++static void uadk_parse_env_config(const char *module) ++{ ++ int i; ++ ++ for (i = 0; i < ARRAY_SIZE(env_vars); i++) { ++ if (!strncmp(module, env_vars[i].module, strlen(module))) { ++ uadk_ctx_env_config(env_vars[i].ctx_num_var); ++ uadk_ctx_env_config(env_vars[i].epoll_en_var); ++ } ++ } ++} ++ ++static void uadk_exe_path(void) ++{ ++ char dir[PATH_MAX] = {0}; ++ int n; ++ ++ n = readlink("/proc/self/exe", dir, PATH_MAX); ++ if (n < 0 || n >= PATH_MAX) ++ printf("uadk tool failed to get the exe path.\n"); ++ ++ dir[PATH_MAX - 1] = '\0'; ++ printf("exe path: %s\n", dir); ++} ++ ++void print_dfx_help(void) ++{ ++ printf("NAME\n"); ++ printf(" uadk_tool dfx : uadk library dfx function, etc\n"); ++ printf("USAGE\n"); ++ printf(" uadk_tool dfx [--version] = Show library version\n"); ++ printf(" uadk_tool dfx [--date] = Show build date\n"); ++ printf(" uadk_tool dfx [--dir] = Show library dir\n"); ++ printf(" uadk_tool dfx [--env] = Show environment variables\n"); ++ printf(" uadk_tool dfx [--count] = Show the ctx message count\n"); ++ printf(" uadk_tool dfx [--help] = usage\n"); ++ printf("Example\n"); ++ printf(" uadk_tool dfx --version\n"); ++ printf(" uadk_tool dfx --env sec\n"); ++ printf(" uadk_tool dfx --count\n"); ++} ++ ++void dfx_cmd_parse(int argc, char *argv[]) ++{ ++ bool check_module = false; ++ char *input_module = NULL; ++ int option_index = 0; ++ int opt; ++ ++ static struct option long_options[] = { ++ {"version", no_argument, 0, 2}, ++ {"date", no_argument, 0, 3}, ++ {"dir", no_argument, 0, 4}, ++ {"env", required_argument, 0, 5}, ++ {"count", no_argument, 0, 6}, ++ {"help", no_argument, 0, 7}, ++ {0, 0, 0, 0} ++ }; ++ ++ while (1) { ++ opt = getopt_long(argc, argv, "", long_options, &option_index); ++ if (opt == -1) ++ break; ++ ++ switch (opt) { ++ case DISPLAY_VERSION: ++ wd_get_version(); ++ break; ++ case DISPLAY_DATE: ++ uadk_build_date(); ++ break; ++ case DISPLAY_DIR: ++ uadk_exe_path(); ++ break; ++ case DISPLAY_ENV: ++ input_module = optarg; ++ check_module = uadk_check_module(input_module); ++ if (check_module) { ++ uadk_parse_env_config(input_module); ++ } else { ++ print_dfx_help(); ++ printf("failed to parse module parameter!\n"); ++ } ++ break; ++ case DISPLAY_COUNT: ++ uadk_shared_read(); ++ break; ++ case DISPLAY_HELP: ++ print_dfx_help(); ++ break; ++ default: ++ printf("bad input parameter, exit!\n"); ++ print_dfx_help(); ++ break; ++ } ++ } ++} +diff --git a/uadk_tool/uadk_dfx.h b/uadk_tool/dfx/uadk_dfx.h +similarity index 59% +rename from uadk_tool/uadk_dfx.h +rename to uadk_tool/dfx/uadk_dfx.h +index 5f5d9e7..8dc1da1 100644 +--- a/uadk_tool/uadk_dfx.h ++++ b/uadk_tool/dfx/uadk_dfx.h +@@ -2,9 +2,6 @@ + #ifndef UADK_DFX_H + #define UADK_DFX_H + +-#define UADK_VERSION_TEXT "UADK 2.3.22, Released Dec 20th, 2021" +-#define UADK_VERSION_TAG "4b9c69d" +- + void print_dfx_help(void); + void dfx_cmd_parse(int argc, char *argv[]); + #endif +diff --git a/uadk_tool/uadk_dfx.c b/uadk_tool/uadk_dfx.c +deleted file mode 100644 +index 96c4919..0000000 +--- a/uadk_tool/uadk_dfx.c ++++ /dev/null +@@ -1,79 +0,0 @@ +-/* SPDX-License-Identifier: Apache-2.0 */ +- +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include "uadk_dfx.h" +- +-#define print_date() printf("built on: %s %s\n", __DATE__, __TIME__) +- +-static void print_version(void) +-{ +- printf("%s\n", UADK_VERSION_TEXT); +- printf("%s\n", UADK_VERSION_TAG); +-} +- +-static void print_exe_path(void) +-{ +- char dir[PATH_MAX] = {0}; +- int n; +- +- n = readlink("/proc/self/exe", dir, PATH_MAX); +- if (n < 0 || n >= PATH_MAX) +- printf("uadk tool failed to get the exe path.\n"); +- +- printf("exe path: %s\n", dir); +-} +- +-void print_dfx_help(void) +-{ +- printf("NAME\n"); +- printf(" uadk_tool --dfx : uadk library dfx function, etc\n"); +- printf("USAGE\n"); +- printf(" uadk_tool --dfx [--version] = Show library version\n"); +- printf(" uadk_tool --dfx [--date] = Show build date\n"); +- printf(" uadk_tool --dfx [--dir] = Show library dir\n"); +- printf(" uadk_tool --dfx [--help] = usage\n"); +-} +- +-void dfx_cmd_parse(int argc, char *argv[]) +-{ +- int option_index = 0; +- int c; +- +- static struct option long_options[] = { +- {"version", no_argument, 0, 2}, +- {"date", no_argument, 0, 3}, +- {"dir", no_argument, 0, 4}, +- {"help", no_argument, 0, 5}, +- {0, 0, 0, 0} +- }; +- +- while (1) { +- c = getopt_long(argc, argv, "", long_options, &option_index); +- if (c == -1) +- break; +- +- switch (c) { +- case 2: +- print_version(); +- break; +- case 3: +- print_date(); +- break; +- case 4: +- print_exe_path(); +- break; +- case 5: +- print_dfx_help(); +- break; +- default: +- printf("bad input parameter, exit\n"); +- exit(-1); +- } +- } +-} +diff --git a/uadk_tool/uadk_tool.c b/uadk_tool/uadk_tool.c +index 88beeba..ce83d7a 100644 +--- a/uadk_tool/uadk_tool.c ++++ b/uadk_tool/uadk_tool.c +@@ -1,12 +1,9 @@ + /* SPDX-License-Identifier: Apache-2.0 */ + + #include +-#include + #include +-#include +-#include +-#include "uadk_dfx.h" +-#include "uadk_benchmark.h" ++#include "dfx/uadk_dfx.h" ++#include "benchmark/uadk_benchmark.h" + + static void print_tool_help(void) + { +@@ -18,17 +15,21 @@ static void print_tool_help(void) + int main(int argc, char **argv) + { + struct acc_option option = {0}; ++ int index = 1; + int ret; + +- if (argc > 1) { +- if (!strcmp("dfx", argv[1])) { ++ if (argc > index) { ++ if (!strcmp("dfx", argv[index])) { + dfx_cmd_parse(argc, argv); +- } else if (!strcmp("benchmark", argv[1])) { ++ } else if (!strcmp("benchmark", argv[index])) { + printf("start UADK benchmark test.\n"); +- if (!argv[2]) ++ if (!argv[++index]) + acc_default_case(&option); + +- benchmark_cmd_parse(argc, argv, &option); ++ ret = acc_cmd_parse(argc, argv, &option); ++ if (ret) ++ return ret; ++ + ret = acc_option_convert(&option); + if (ret) + return ret; +diff --git a/wd.c b/wd.c +index 3ce9c1e..2dbb2ab 100644 +--- a/wd.c ++++ b/wd.c +@@ -14,6 +14,7 @@ + #include + #include + #include ++#include + #include + #include + +@@ -22,7 +23,14 @@ + + #define SYS_CLASS_DIR "/sys/class/uacce" + +-const char *WD_VERSION = UADK_VERSION_NUMBER; ++enum UADK_LOG_LEVEL { ++ LOG_NONE = 0, ++ WD_LOG_ERROR, ++ WD_LOG_INFO, ++ WD_LOG_DEBUG, ++}; ++ ++static int uadk_log_level; + + struct wd_ctx_h { + int fd; +@@ -35,6 +43,54 @@ struct wd_ctx_h { + void *priv; + }; + ++static void wd_parse_log_level(void) ++{ ++ const char *syslog_file = "/etc/rsyslog.conf"; ++ const char *log_dir = "/var/log/uadk.log"; ++ bool log_debug = false; ++ bool log_info = false; ++ struct stat file_info; ++ char *file_contents; ++ FILE *in_file; ++ ++ in_file = fopen(syslog_file, "r"); ++ if (!in_file) { ++ WD_ERR("failed to open the rsyslog.conf file.\n"); ++ return; ++ } ++ ++ if (stat(syslog_file, &file_info) == -1) { ++ WD_ERR("failed to get file information.\n"); ++ goto close_file; ++ } ++ ++ file_contents = malloc(file_info.st_size); ++ if (!file_contents) { ++ WD_ERR("failed to get file contents memory.\n"); ++ goto close_file; ++ } ++ ++ while (fscanf(in_file, "%[^\n ] ", file_contents) != EOF) { ++ if (!strcmp("local5.debug", file_contents)) ++ log_debug = true; ++ else if (!strcmp("local5.info", file_contents)) ++ log_info = true; ++ ++ if (log_debug && !strcmp(log_dir, file_contents)) { ++ uadk_log_level = WD_LOG_DEBUG; ++ break; ++ } else if (log_info && !strcmp(log_dir, file_contents)) { ++ uadk_log_level = WD_LOG_INFO; ++ break; ++ } ++ } ++ ++ free(file_contents); ++ ++close_file: ++ fclose(in_file); ++} ++ + static int get_raw_attr(const char *dev_root, const char *attr, char *buf, + size_t sz) + { +@@ -189,6 +245,8 @@ static struct uacce_dev *read_uacce_sysfs(const char *dev_name) + if (!dev_name) + return NULL; + ++ wd_parse_log_level(); ++ + dev = calloc(1, sizeof(struct uacce_dev)); + if (!dev) + return NULL; +@@ -731,3 +789,22 @@ int wd_ctx_set_io_cmd(handle_t h_ctx, unsigned long cmd, void *arg) + + return ioctl(ctx->fd, cmd, arg); + } ++ ++void wd_get_version(void) ++{ ++ const char *wd_released_time = UADK_RELEASED_TIME; ++ const char *wd_version = UADK_VERSION_NUMBER; ++ ++ WD_CONSOLE("%s\n", wd_version); ++ WD_CONSOLE("%s\n", wd_released_time); ++} ++ ++bool wd_need_debug(void) ++{ ++ return uadk_log_level >= WD_LOG_DEBUG; ++} ++ ++bool wd_need_info(void) ++{ ++ return uadk_log_level >= WD_LOG_INFO; ++} +diff --git a/wd_aead.c b/wd_aead.c +index 7c07271..0c54de3 100644 +--- a/wd_aead.c ++++ b/wd_aead.c +@@ -413,7 +413,7 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched) + wd_aead_set_static_drv(); + #endif + +- /* init sync request pool */ ++ /* init async request pool */ + ret = wd_init_async_request_pool(&wd_aead_setting.pool, + config->ctx_num, WD_POOL_MAX_ENTRIES, + sizeof(struct wd_aead_msg)); +@@ -531,6 +531,7 @@ int wd_do_aead_sync(handle_t h_sess, struct wd_aead_req *req) + if (unlikely(ret)) + return ret; + ++ wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + ctx = config->ctxs + idx; + ret = send_recv_sync(ctx, &msg); + req->state = msg.result; +@@ -563,6 +564,7 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req) + if (ret) + return ret; + ++ wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + ctx = config->ctxs + idx; + + msg_id = wd_get_msg_from_pool(&wd_aead_setting.pool, +diff --git a/wd_cipher.c b/wd_cipher.c +index a7e393b..0cd2e42 100644 +--- a/wd_cipher.c ++++ b/wd_cipher.c +@@ -442,7 +442,9 @@ int wd_do_cipher_sync(handle_t h_sess, struct wd_cipher_req *req) + if (unlikely(ret)) + return ret; + ++ wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + ctx = config->ctxs + idx; ++ + ret = send_recv_sync(ctx, &msg); + req->state = msg.result; + +@@ -472,6 +474,7 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req) + return ret; + + ctx = config->ctxs + idx; ++ wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + + msg_id = wd_get_msg_from_pool(&wd_cipher_setting.pool, idx, + (void **)&msg); +diff --git a/wd_comp.c b/wd_comp.c +index 9107d60..eacebd3 100644 +--- a/wd_comp.c ++++ b/wd_comp.c +@@ -406,6 +406,7 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess, + if (unlikely(ret)) + return ret; + ++ wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + ctx = config->ctxs + idx; + + msg_handle.send = wd_comp_setting.driver->comp_send; +@@ -656,6 +657,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req) + if (unlikely(ret)) + return ret; + ++ wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + ctx = config->ctxs + idx; + + tag = wd_get_msg_from_pool(&wd_comp_setting.pool, idx, (void **)&msg); +diff --git a/wd_dh.c b/wd_dh.c +index 9571ab6..461f04e 100644 +--- a/wd_dh.c ++++ b/wd_dh.c +@@ -212,6 +212,7 @@ int wd_do_dh_sync(handle_t sess, struct wd_dh_req *req) + if (ret) + return ret; + ++ wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + ctx = config->ctxs + idx; + + memset(&msg, 0, sizeof(struct wd_dh_msg)); +@@ -257,6 +258,7 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req) + if (ret) + return ret; + ++ wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + ctx = config->ctxs + idx; + + mid = wd_get_msg_from_pool(&wd_dh_setting.pool, idx, (void **)&msg); +diff --git a/wd_digest.c b/wd_digest.c +index 0fff7c8..ae37e32 100644 +--- a/wd_digest.c ++++ b/wd_digest.c +@@ -340,6 +340,7 @@ int wd_do_digest_sync(handle_t h_sess, struct wd_digest_req *req) + if (unlikely(ret)) + return ret; + ++ wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + ctx = config->ctxs + idx; + ret = send_recv_sync(ctx, dsess, &msg); + req->state = msg.result; +@@ -372,6 +373,7 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req) + if (ret) + return ret; + ++ wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + ctx = config->ctxs + idx; + + msg_id = wd_get_msg_from_pool(&wd_digest_setting.pool, idx, +diff --git a/wd_ecc.c b/wd_ecc.c +index 76c9d5f..1ff6ed3 100644 +--- a/wd_ecc.c ++++ b/wd_ecc.c +@@ -853,14 +853,14 @@ static int fill_user_curve_cfg(struct wd_ecc_curve *param, + if (setup->cv.type == WD_CV_CFG_ID) { + curve_id = setup->cv.cfg.id; + ret = fill_param_by_id(param, setup->key_bits, curve_id); +- dbg("set curve id %u!\n", curve_id); ++ WD_DEBUG("set curve id %u!\n", curve_id); + } else if (setup->cv.type == WD_CV_CFG_PARAM) { + ret = set_key_cv(param, src_param); + if (ret) { + WD_ERR("failed to set key cv!\n"); + return ret; + } +- dbg("set curve by user param!\n"); ++ WD_DEBUG("set curve by user param!\n"); + } else { + WD_ERR("invalid: fill curve cfg type %u is error!\n", setup->cv.type); + return -WD_EINVAL; +@@ -1407,6 +1407,7 @@ int wd_do_ecc_sync(handle_t h_sess, struct wd_ecc_req *req) + if (ret) + return ret; + ++ wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + ctx = config->ctxs + idx; + + memset(&msg, 0, sizeof(struct wd_ecc_msg)); +@@ -2086,6 +2087,7 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req) + if (ret) + return ret; + ++ wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + ctx = config->ctxs + idx; + + mid = wd_get_msg_from_pool(&wd_ecc_setting.pool, idx, (void **)&msg); +diff --git a/wd_rsa.c b/wd_rsa.c +index 868e78b..e76da09 100644 +--- a/wd_rsa.c ++++ b/wd_rsa.c +@@ -272,6 +272,7 @@ int wd_do_rsa_sync(handle_t h_sess, struct wd_rsa_req *req) + if (ret) + return ret; + ++ wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + ctx = config->ctxs + idx; + + memset(&msg, 0, sizeof(struct wd_rsa_msg)); +@@ -317,6 +318,7 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req) + if (ret) + return ret; + ++ wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + ctx = config->ctxs + idx; + + mid = wd_get_msg_from_pool(&wd_rsa_setting.pool, idx, (void **)&msg); +diff --git a/wd_util.c b/wd_util.c +index de77d1e..04a2a5b 100644 +--- a/wd_util.c ++++ b/wd_util.c +@@ -20,6 +20,7 @@ + #define WD_BALANCE_THRHD 1280 + #define WD_RECV_MAX_CNT_SLEEP 60000000 + #define WD_RECV_MAX_CNT_NOSLEEP 200000000 ++#define PRIVILEGE_FLAG 600 + + struct msg_pool { + /* message array allocated dynamically */ +@@ -70,11 +71,76 @@ static void clone_ctx_to_internal(struct wd_ctx *ctx, + ctx_in->ctx_mode = ctx->ctx_mode; + } + ++static int get_shared_memory_id(__u32 numsize) ++{ ++ int shm; ++ ++ shm = shmget(WD_IPC_KEY, sizeof(unsigned long) * numsize, ++ IPC_CREAT | PRIVILEGE_FLAG); ++ if (shm < 0) { ++ WD_ERR("failed to get shared memory id.\n"); ++ return -WD_EINVAL; ++ } ++ ++ return shm; ++} ++ ++static unsigned long *wd_shared_create(__u32 numsize) ++{ ++ bool need_info = wd_need_info(); ++ void *ptr; ++ int shm; ++ ++ if (!need_info) ++ return NULL; ++ ++ if (numsize > WD_CTX_CNT_NUM) { ++ WD_ERR("invalid: input parameter is err!\n"); ++ return NULL; ++ } ++ ++ shm = get_shared_memory_id(numsize); ++ if (shm < 0) ++ return NULL; ++ ++ ptr = shmat(shm, NULL, 0); ++ if (ptr == (void *)-1) { ++ WD_ERR("failed to get shared memory addr.\n"); ++ return NULL; ++ } ++ ++ memset(ptr, 0, sizeof(unsigned long) * numsize); ++ ++ return ptr; ++} ++ ++static void wd_shared_delete(__u32 numsize) ++{ ++ bool need_info = wd_need_info(); ++ int shm; ++ ++ if (!need_info) ++ return; ++ ++ if (numsize > WD_CTX_CNT_NUM) { ++ WD_ERR("invalid: input parameter is err!\n"); ++ return; ++ } ++ ++ shm = get_shared_memory_id(numsize); ++ if (shm < 0) ++ return; ++ ++ /* deleted shared memory */ ++ shmctl(shm, IPC_RMID, NULL); ++} ++ + int wd_init_ctx_config(struct wd_ctx_config_internal *in, + struct wd_ctx_config *cfg) + { ++ bool need_info = wd_need_info(); + struct wd_ctx_internal *ctxs; +- int i, ret; ++ int i, j, ret; + + if (!cfg->ctx_num) { + WD_ERR("invalid: ctx_num is 0!\n"); +@@ -87,25 +153,29 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in, + return -WD_EEXIST; + } + ++ in->msg_cnt = wd_shared_create(WD_CTX_CNT_NUM); ++ if (!in->msg_cnt && need_info) ++ return -WD_EINVAL; ++ + ctxs = calloc(1, cfg->ctx_num * sizeof(struct wd_ctx_internal)); + if (!ctxs) { + WD_ERR("failed to alloc memory for internal ctxs!\n"); ++ wd_shared_delete(WD_CTX_CNT_NUM); + return -WD_ENOMEM; + } + + for (i = 0; i < cfg->ctx_num; i++) { + if (!cfg->ctxs[i].ctx) { + WD_ERR("invalid: ctx is NULL!\n"); +- free(ctxs); +- return -WD_EINVAL; ++ ret = -WD_EINVAL; ++ goto err_out; + } + + clone_ctx_to_internal(cfg->ctxs + i, ctxs + i); + ret = pthread_spin_init(&ctxs[i].lock, PTHREAD_PROCESS_SHARED); + if (ret) { + WD_ERR("failed to init ctxs lock!\n"); +- free(ctxs); +- return ret; ++ goto err_out; + } + } + +@@ -115,6 +185,14 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in, + in->ctx_num = cfg->ctx_num; + + return 0; ++ ++err_out: ++ for (j = 0; j < i; j++) ++ pthread_spin_destroy(&ctxs[j].lock); ++ ++ wd_shared_delete(WD_CTX_CNT_NUM); ++ free(ctxs); ++ return ret; + } + + int wd_init_sched(struct wd_sched *in, struct wd_sched *from) +@@ -161,6 +239,9 @@ void wd_clear_ctx_config(struct wd_ctx_config_internal *in) + free(in->ctxs); + in->ctxs = NULL; + } ++ ++ wd_shared_delete(WD_CTX_CNT_NUM); ++ in->msg_cnt = NULL; + } + + void wd_memset_zero(void *data, __u32 size) +-- +2.27.0 + diff --git a/0126-uadk-sgl-data-can-be-dumped.patch b/0126-uadk-sgl-data-can-be-dumped.patch new file mode 100644 index 0000000..e8746d3 --- /dev/null +++ b/0126-uadk-sgl-data-can-be-dumped.patch @@ -0,0 +1,96 @@ +From 96eae2df1f7a42580037320ae78d513ae5c69dc3 Mon Sep 17 00:00:00 2001 +From: Kai Ye +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 +--- + 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 + diff --git a/0127-uadk-supports-zip-and-sec-message-dumping.patch b/0127-uadk-supports-zip-and-sec-message-dumping.patch new file mode 100644 index 0000000..340a8ff --- /dev/null +++ b/0127-uadk-supports-zip-and-sec-message-dumping.patch @@ -0,0 +1,631 @@ +From 71d7f88f42da4959037adebd34804ef32af95d0d Mon Sep 17 00:00:00 2001 +From: Kai Ye +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 +--- + 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 + diff --git a/0128-uadk-add-device-isolation-interface.patch b/0128-uadk-add-device-isolation-interface.patch new file mode 100644 index 0000000..a9dc5e7 --- /dev/null +++ b/0128-uadk-add-device-isolation-interface.patch @@ -0,0 +1,65 @@ +From 45d65ffcfea660dded788d6819399833e017fd9f Mon Sep 17 00:00:00 2001 +From: Kai Ye +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 +--- + 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 + diff --git a/0129-uadk-add-WD_DEV_ERR-api.patch b/0129-uadk-add-WD_DEV_ERR-api.patch new file mode 100644 index 0000000..401d9ed --- /dev/null +++ b/0129-uadk-add-WD_DEV_ERR-api.patch @@ -0,0 +1,249 @@ +From 2884d11a6307d239f72515309b565132c97f1172 Mon Sep 17 00:00:00 2001 +From: Kai Ye +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 +--- + 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 + diff --git a/0130-uadk-ecc-remove-a-redefined-macro.patch b/0130-uadk-ecc-remove-a-redefined-macro.patch new file mode 100644 index 0000000..2b47407 --- /dev/null +++ b/0130-uadk-ecc-remove-a-redefined-macro.patch @@ -0,0 +1,42 @@ +From e54fc1d2840a7bd9b884a84d5fd4de385f23e03f Mon Sep 17 00:00:00 2001 +From: Yang Shen +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 +--- + 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 + #include + #include ++#include + #include + #include + #include +-- +2.27.0 + diff --git a/0131-uadk-hisi-remove-a-redefined-macro.patch b/0131-uadk-hisi-remove-a-redefined-macro.patch new file mode 100644 index 0000000..1f99da8 --- /dev/null +++ b/0131-uadk-hisi-remove-a-redefined-macro.patch @@ -0,0 +1,40 @@ +From 24a24c44373d3d2fb185bd7c3c3d8d158b63569e Mon Sep 17 00:00:00 2001 +From: Yang Shen +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 +--- + 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 ++#include + #include + #include + +@@ -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 + diff --git a/0132-uadk-doc-fix-text-style-for-wd_design.md.patch b/0132-uadk-doc-fix-text-style-for-wd_design.md.patch new file mode 100644 index 0000000..7ad2b10 --- /dev/null +++ b/0132-uadk-doc-fix-text-style-for-wd_design.md.patch @@ -0,0 +1,542 @@ +From c69f4b5e4889a2311940efa0478e099b34d0084a Mon Sep 17 00:00:00 2001 +From: Yang Shen +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 +--- + 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 + diff --git a/0133-uadk_tool-Update-some-new-test-features.patch b/0133-uadk_tool-Update-some-new-test-features.patch new file mode 100644 index 0000000..7971093 --- /dev/null +++ b/0133-uadk_tool-Update-some-new-test-features.patch @@ -0,0 +1,1246 @@ +From e1f90f375fc35862d2c775f97a3119b95f19c8a2 Mon Sep 17 00:00:00 2001 +From: Longfang Liu +Date: Mon, 18 Jul 2022 17:16:31 +0800 +Subject: [PATCH 147/183] uadk_tool: Update some new test features + +1. Modify part of the repeated code macro. +2. Add new random number generation method. +3. Add new test parameters, support test algorithm +query and address pre-step function. + +Signed-off-by: Longfang Liu +--- + uadk_tool/benchmark/sec_soft_benchmark.c | 7 +- + uadk_tool/benchmark/sec_soft_benchmark.h | 1 - + uadk_tool/benchmark/sec_uadk_benchmark.c | 65 ++++---- + uadk_tool/benchmark/sec_wd_benchmark.c | 191 ++++++----------------- + uadk_tool/benchmark/uadk_benchmark.c | 115 ++++++++------ + uadk_tool/benchmark/uadk_benchmark.h | 20 ++- + 6 files changed, 166 insertions(+), 233 deletions(-) + +diff --git a/uadk_tool/benchmark/sec_soft_benchmark.c b/uadk_tool/benchmark/sec_soft_benchmark.c +index 2f6bccb..a622329 100644 +--- a/uadk_tool/benchmark/sec_soft_benchmark.c ++++ b/uadk_tool/benchmark/sec_soft_benchmark.c +@@ -56,11 +56,8 @@ typedef struct soft_jobs_res { + u32 use_engine; + } jobs_data; + +-#define MAX_POOL_LENTH 4096 + #define MAX_IVK_LENTH 64 + #define DEF_IVK_DATA 0xAA +-#define MAX_TRY_CNT 5000 +-#define SEND_USLEEP 100 + + static unsigned int g_thread_num; + static unsigned int g_ctxnum; +@@ -613,7 +610,7 @@ static void *sec_soft_async_run(void *arg) + exit_pause: + ASYNC_WAIT_CTX_free(waitctx); + +- add_recv_data(count); ++ add_recv_data(count, g_pktlen); + + return NULL; + } +@@ -802,7 +799,7 @@ static void *sec_soft_sync_run(void *arg) + break; + } + +- add_recv_data(count); ++ add_recv_data(count, g_pktlen); + + return NULL; + } +diff --git a/uadk_tool/benchmark/sec_soft_benchmark.h b/uadk_tool/benchmark/sec_soft_benchmark.h +index 8331eb5..c1374d6 100644 +--- a/uadk_tool/benchmark/sec_soft_benchmark.h ++++ b/uadk_tool/benchmark/sec_soft_benchmark.h +@@ -4,6 +4,5 @@ + + #include "uadk_benchmark.h" + +- + extern int sec_soft_benchmark(struct acc_option *options); + #endif /* SEC_SOFT_BENCHMARK_H */ +diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c +index 6eeee12..09cd8f4 100644 +--- a/uadk_tool/benchmark/sec_uadk_benchmark.c ++++ b/uadk_tool/benchmark/sec_uadk_benchmark.c +@@ -10,6 +10,8 @@ + #include "include/wd_sched.h" + + #define SEC_TST_PRT printf ++#define MAX_IVK_LENTH 64 ++#define DEF_IVK_DATA 0xAA + + struct uadk_bd { + u8 *src; +@@ -37,18 +39,12 @@ typedef struct uadk_thread_res { + u32 td_id; + } thread_data; + +-#define MAX_POOL_LENTH 4096 +-#define MAX_IVK_LENTH 64 +-#define DEF_IVK_DATA 0xAA +-#define MAX_TRY_CNT 5000 +-#define SEND_USLEEP 100 +- + static struct wd_ctx_config g_ctx_cfg; + static struct wd_sched *g_sched; + static unsigned int g_thread_num; + static unsigned int g_ctxnum; ++static unsigned int g_prefetch; + static unsigned int g_pktlen; +-static struct sched_params g_param; + + static void *cipher_async_cb(struct wd_cipher_req *req, void *data) + { +@@ -349,6 +345,7 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options) + static int init_ctx_config(char *alg, int subtype, int mode) + { + struct uacce_dev_list *list; ++ struct sched_params param; + int i, max_node; + int ret = 0; + +@@ -385,7 +382,7 @@ static int init_ctx_config(char *alg, int subtype, int mode) + break; + default: + SEC_TST_PRT("Fail to parse alg subtype!\n"); +- return -EINVAL; ++ goto out; + } + if (!g_sched) { + SEC_TST_PRT("Fail to alloc sched!\n"); +@@ -397,12 +394,12 @@ static int init_ctx_config(char *alg, int subtype, int mode) + list->dev->numa_id = 0; + + g_sched->name = SCHED_SINGLE; +- g_param.numa_id = list->dev->numa_id; +- g_param.type = 0; +- g_param.mode = mode; +- g_param.begin = 0; +- g_param.end = g_ctxnum - 1; +- ret = wd_sched_rr_instance(g_sched, &g_param); ++ param.numa_id = list->dev->numa_id; ++ param.type = 0; ++ param.mode = mode; ++ param.begin = 0; ++ param.end = g_ctxnum - 1; ++ ret = wd_sched_rr_instance(g_sched, ¶m); + if (ret) { + SEC_TST_PRT("Fail to fill sched data!\n"); + goto out; +@@ -419,6 +416,8 @@ static int init_ctx_config(char *alg, int subtype, int mode) + case DIGEST_TYPE: + ret = wd_digest_init(&g_ctx_cfg, g_sched); + break; ++ default: ++ goto out; + } + if (ret) { + SEC_TST_PRT("Fail to cipher ctx!\n"); +@@ -461,18 +460,13 @@ static void uninit_ctx_config(int subtype) + wd_sched_rr_release(g_sched); + } + +-int init_uadk_bd_pool(void) ++static int init_uadk_bd_pool(void) + { + unsigned long step; +- int fill_size; + int i, j; + + // make the block not align to 4K + step = sizeof(char) * g_pktlen * 2; +- if (g_pktlen > MAX_IVK_LENTH) +- fill_size = MAX_IVK_LENTH; +- else +- fill_size = g_pktlen; + + g_uadk_pool.iv = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char)); + g_uadk_pool.key = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char)); +@@ -498,7 +492,9 @@ int init_uadk_bd_pool(void) + if (!g_uadk_pool.pool[i].bds[j].dst) + goto malloc_error3; + +- get_rand_data(g_uadk_pool.pool[i].bds[j].src, fill_size); ++ get_rand_data(g_uadk_pool.pool[i].bds[j].src, g_pktlen); ++ if (g_prefetch) ++ get_rand_data(g_uadk_pool.pool[i].bds[j].dst, g_pktlen); + } + } + } +@@ -526,12 +522,13 @@ malloc_error1: + + free(g_uadk_pool.iv); + free(g_uadk_pool.key); ++ free(g_uadk_pool.mac); + + SEC_TST_PRT("init uadk bd pool alloc failed!\n"); + return -ENOMEM; + } + +-void free_uadk_bd_pool(void) ++static void free_uadk_bd_pool(void) + { + int i, j; + +@@ -550,21 +547,22 @@ void free_uadk_bd_pool(void) + + free(g_uadk_pool.iv); + free(g_uadk_pool.key); ++ free(g_uadk_pool.mac); + } + + /*-------------------------------uadk benchmark main code-------------------------------------*/ + +-void *sec_uadk_poll(void *data) ++static void *sec_uadk_poll(void *data) + { + typedef int (*poll_ctx)(__u32 idx, __u32 expt, __u32 *count); + poll_ctx uadk_poll_ctx = NULL; + thread_data *pdata = (thread_data *)data; + u32 expt = ACC_QUEUE_SIZE * g_thread_num; + u32 id = pdata->td_id; +- u32 last_time = 2; /* poll need one more recv time */ ++ u32 last_time = 2; // poll need one more recv time + u32 count = 0; + u32 recv = 0; +- int ret; ++ int ret; + + if (id > g_ctxnum) + return NULL; +@@ -586,7 +584,6 @@ void *sec_uadk_poll(void *data) + + while (last_time) { + ret = uadk_poll_ctx(id, expt, &recv); +- // SEC_TST_PRT("expt %u, poll %d recv: %u!\n", expt, i, recv); + count += recv; + recv = 0; + if (unlikely(ret != -WD_EAGAIN && ret < 0)) { +@@ -599,7 +596,7 @@ void *sec_uadk_poll(void *data) + } + + recv_error: +- add_recv_data(count); ++ add_recv_data(count, g_pktlen); + + return NULL; + } +@@ -636,7 +633,6 @@ static void *sec_uadk_async_run(void *arg) + case CIPHER_TYPE: + cipher_setup.alg = pdata->alg; + cipher_setup.mode = pdata->mode; +- cipher_setup.sched_param = (void *)&g_param; + h_sess = wd_cipher_alloc_sess(&cipher_setup); + if (!h_sess) + return NULL; +@@ -682,7 +678,6 @@ static void *sec_uadk_async_run(void *arg) + case AEAD_TYPE: // just ccm and gcm + aead_setup.calg = pdata->alg; + aead_setup.cmode = pdata->mode; +- aead_setup.sched_param = (void *)&g_param; + h_sess = wd_aead_alloc_sess(&aead_setup); + if (!h_sess) + return NULL; +@@ -740,7 +735,6 @@ static void *sec_uadk_async_run(void *arg) + case DIGEST_TYPE: + digest_setup.alg = pdata->alg; + digest_setup.mode = pdata->mode; // digest mode is optype +- digest_setup.sched_param = (void *)&g_param; + h_sess = wd_digest_alloc_sess(&digest_setup); + if (!h_sess) + return NULL; +@@ -820,7 +814,6 @@ static void *sec_uadk_sync_run(void *arg) + case CIPHER_TYPE: + cipher_setup.alg = pdata->alg; + cipher_setup.mode = pdata->mode; +- cipher_setup.sched_param = (void *)&g_param; + h_sess = wd_cipher_alloc_sess(&cipher_setup); + if (!h_sess) + return NULL; +@@ -845,7 +838,7 @@ static void *sec_uadk_sync_run(void *arg) + creq.src = uadk_pool->bds[i].src; + creq.dst = uadk_pool->bds[i].dst; + ret = wd_do_cipher_sync(h_sess, &creq); +- if (ret || creq.state) ++ if ((ret < 0 && ret != -WD_EBUSY) || creq.state) + break; + count++; + if (get_run_state() == 0) +@@ -856,7 +849,6 @@ static void *sec_uadk_sync_run(void *arg) + case AEAD_TYPE: // just ccm and gcm + aead_setup.calg = pdata->alg; + aead_setup.cmode = pdata->mode; +- aead_setup.sched_param = (void *)&g_param; + h_sess = wd_aead_alloc_sess(&aead_setup); + if (!h_sess) + return NULL; +@@ -905,7 +897,6 @@ static void *sec_uadk_sync_run(void *arg) + case DIGEST_TYPE: + digest_setup.alg = pdata->alg; + digest_setup.mode = pdata->mode; // digest mode is optype +- digest_setup.sched_param = (void *)&g_param; + h_sess = wd_digest_alloc_sess(&digest_setup); + if (!h_sess) + return NULL; +@@ -939,7 +930,7 @@ static void *sec_uadk_sync_run(void *arg) + break; + } + +- add_recv_data(count); ++ add_recv_data(count, g_pktlen); + + return NULL; + } +@@ -982,7 +973,6 @@ int sec_uadk_sync_threads(struct acc_option *options) + + sync_error: + return ret; +- + } + + int sec_uadk_async_threads(struct acc_option *options) +@@ -998,10 +988,10 @@ int sec_uadk_async_threads(struct acc_option *options) + if (ret) + return ret; + +- /* poll thread */ + for (i = 0; i < g_ctxnum; i++) { + threads_args[i].subtype = threads_option.subtype; + threads_args[i].td_id = i; ++ /* poll thread */ + ret = pthread_create(&pollid[i], NULL, sec_uadk_poll, &threads_args[i]); + if (ret) { + SEC_TST_PRT("Create poll thread fail!\n"); +@@ -1053,6 +1043,7 @@ int sec_uadk_benchmark(struct acc_option *options) + g_thread_num = options->threads; + g_pktlen = options->pktlen; + g_ctxnum = options->ctxnums; ++ g_prefetch = options->prefetch; + if (options->optype > WD_CIPHER_DECRYPTION) { + SEC_TST_PRT("SEC optype error: %u\n", options->optype); + return -EINVAL; +diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c +index 2e9c55d..3017fb8 100644 +--- a/uadk_tool/benchmark/sec_wd_benchmark.c ++++ b/uadk_tool/benchmark/sec_wd_benchmark.c +@@ -11,6 +11,9 @@ + #include "v1/wd_util.h" + + #define SEC_TST_PRT printf ++#define MAX_IVK_LENTH 64 ++#define DEF_IVK_DATA 0xAA ++#define SQE_SIZE 128 + + typedef struct wd_thread_res { + u32 subtype; +@@ -32,57 +35,31 @@ struct thread_bd_res { + + struct thread_queue_res { + struct thread_bd_res *bd_res; +-} g_thread_queue; ++}; + + struct wcrypto_async_tag { + void *ctx; +- char *out_buf; + int thread_id; + int cnt; + }; + +-#define MAX_IVK_LENTH 64 +-#define DEF_IVK_DATA 0xAA +-#define MAX_TRY_CNT 5000 +-#define SEND_USLEEP 100 +-#define TEST_MAX_THRD 128 +-#define SQE_SIZE 128 +-#define MAX_BLOCK_NM 4096 +- ++static struct thread_queue_res g_thread_queue; + static unsigned int g_thread_num; +-static unsigned int g_ctxnum; + static unsigned int g_pktlen; + + static void *cipher_async_cb(void *message, void *cipher_tag) + { +- struct wcrypto_async_tag *async_tag = (struct wcrypto_async_tag *)cipher_tag; +- struct wcrypto_cipher_msg *req = (struct wcrypto_cipher_msg *)message; +- +- // no-sva data copy from uadk to user +- memcpy(async_tag->out_buf, req->out, g_pktlen); +- + return NULL; + } + +-static void *aead_async_cb(void *message, void *aead_tag) ++static void *aead_async_cb(void *message, void *cipher_tag) + { +- struct wcrypto_async_tag *async_tag = (struct wcrypto_async_tag *)aead_tag; +- struct wcrypto_aead_msg *req = (struct wcrypto_aead_msg *)message; +- +- // no-sva data copy from uadk to user +- memcpy(async_tag->out_buf, req->out, g_pktlen); +- + return NULL; + } + + static void *digest_async_cb(void *message, void *digest_tag) + { +- struct wcrypto_async_tag *async_tag = (struct wcrypto_async_tag *)digest_tag; +- struct wcrypto_digest_msg *req = (struct wcrypto_digest_msg *)message; +- +- // no-sva data copy from uadk to user +- memcpy(async_tag->out_buf, req->out, 16); +- ++ // struct WCRYPTO_req *req = (struct WCRYPTO_req *)data; + return NULL; + } + +@@ -396,9 +373,9 @@ static int init_wd_queue(struct acc_option *options) + // use no-sva pbuffer + memset(&blksetup, 0, sizeof(blksetup)); + blksetup.block_size = g_pktlen + SQE_SIZE; //aead need mac and aad out +- blksetup.block_num = MAX_BLOCK_NM * 4; //set pool inv + key + in + out ++ blksetup.block_num = MAX_BLOCK_NM; //set pool inv + key + in + out + blksetup.align_size = SQE_SIZE; +- SEC_TST_PRT("create pool memory: %d KB\n", (MAX_BLOCK_NM * blksetup.block_size) >> 10); ++ // SEC_TST_PRT("create pool memory: %d KB\n", (MAX_BLOCK_NM * blksetup.block_size) >> 10); + + for (j = 0; j < g_thread_num; j++) { + g_thread_queue.bd_res[j].pool = wd_blkpool_create(g_thread_queue.bd_res[j].queue, &blksetup); +@@ -411,8 +388,8 @@ static int init_wd_queue(struct acc_option *options) + + // alloc in pbuffer res + for (m = 0; m < g_thread_num; m++) { +- g_thread_queue.bd_res[m].in = malloc(MAX_BLOCK_NM * sizeof(void *)); +- for (idx = 0; idx < MAX_BLOCK_NM; idx++) { ++ g_thread_queue.bd_res[m].in = malloc(MAX_POOL_LENTH * sizeof(void *)); ++ for (idx = 0; idx < MAX_POOL_LENTH; idx++) { + g_thread_queue.bd_res[m].in[idx] = wd_alloc_blk(g_thread_queue.bd_res[m].pool); + if (!g_thread_queue.bd_res[m].in[idx]) { + SEC_TST_PRT("create pool %dth in memory fail!\n", m); +@@ -427,8 +404,8 @@ static int init_wd_queue(struct acc_option *options) + + // alloc out pbuffer res + for (n = 0; n < g_thread_num; n++) { +- g_thread_queue.bd_res[n].out = malloc(MAX_BLOCK_NM * sizeof(void *)); +- for (idx = 0; idx < MAX_BLOCK_NM; idx++) { ++ g_thread_queue.bd_res[n].out = malloc(MAX_POOL_LENTH * sizeof(void *)); ++ for (idx = 0; idx < MAX_POOL_LENTH; idx++) { + g_thread_queue.bd_res[n].out[idx] = wd_alloc_blk(g_thread_queue.bd_res[n].pool); + if (!g_thread_queue.bd_res[n].out[idx]) { + SEC_TST_PRT("create pool %dth out memory fail!\n", n); +@@ -443,8 +420,8 @@ static int init_wd_queue(struct acc_option *options) + + // alloc iv pbuffer res + for (k = 0; k < g_thread_num; k++) { +- g_thread_queue.bd_res[k].iv = malloc(MAX_BLOCK_NM * sizeof(void *)); +- for (idx = 0; idx < MAX_BLOCK_NM; idx++) { ++ g_thread_queue.bd_res[k].iv = malloc(MAX_POOL_LENTH * sizeof(void *)); ++ for (idx = 0; idx < MAX_POOL_LENTH; idx++) { + g_thread_queue.bd_res[k].iv[idx] = wd_alloc_blk(g_thread_queue.bd_res[k].pool); + if (!g_thread_queue.bd_res[k].iv[idx]) { + SEC_TST_PRT("create pool %dth iv memory fail!\n", k); +@@ -462,21 +439,21 @@ static int init_wd_queue(struct acc_option *options) + + iv_err: + for (k--; k >= 0; k--) { +- for (idx = 0; idx < MAX_BLOCK_NM; idx++) ++ for (idx = 0; idx < MAX_POOL_LENTH; idx++) + wd_free_blk(g_thread_queue.bd_res[k].pool, + g_thread_queue.bd_res[k].iv[idx]); + free(g_thread_queue.bd_res[k].iv); + } + out_err: + for (n--; n >= 0; n--) { +- for (idx = 0; idx < MAX_BLOCK_NM; idx++) ++ for (idx = 0; idx < MAX_POOL_LENTH; idx++) + wd_free_blk(g_thread_queue.bd_res[n].pool, + g_thread_queue.bd_res[n].out[idx]); + free(g_thread_queue.bd_res[n].out); + } + in_err: + for (m--; m >= 0; m--) { +- for (idx = 0; idx < MAX_BLOCK_NM; idx++) ++ for (idx = 0; idx < MAX_POOL_LENTH; idx++) + wd_free_blk(g_thread_queue.bd_res[m].pool, + g_thread_queue.bd_res[m].in[idx]); + free(g_thread_queue.bd_res[m].in); +@@ -498,7 +475,7 @@ static void uninit_wd_queue(void) + int i, j, idx; + + for (i = 0; i < g_thread_num; i++) { +- for (idx = 0; idx < MAX_BLOCK_NM; idx++) { ++ for (idx = 0; idx < MAX_POOL_LENTH; idx++) { + wd_free_blk(g_thread_queue.bd_res[i].pool, g_thread_queue.bd_res[i].iv[idx]); + wd_free_blk(g_thread_queue.bd_res[i].pool, g_thread_queue.bd_res[i].in[idx]); + wd_free_blk(g_thread_queue.bd_res[i].pool, g_thread_queue.bd_res[i].out[idx]); +@@ -522,22 +499,22 @@ void *sec_wd_poll(void *data) + { + typedef int (*poll_ctx)(struct wd_queue *q, unsigned int num); + thread_data *pdata = (thread_data *)data; +- poll_ctx uadk_poll_ctx = NULL; ++ poll_ctx wd_poll_ctx = NULL; + u32 expt = ACC_QUEUE_SIZE * g_thread_num; +- u32 last_time = 2; /* poll need one more recv time */ ++ u32 last_time = 2; // poll need one more recv time + u32 id = pdata->td_id; + u32 count = 0; +- u32 recv = 0; ++ int recv = 0; + + switch(pdata->subtype) { + case CIPHER_TYPE: +- uadk_poll_ctx = wcrypto_cipher_poll; ++ wd_poll_ctx = wcrypto_cipher_poll; + break; + case AEAD_TYPE: +- uadk_poll_ctx = wcrypto_aead_poll; ++ wd_poll_ctx = wcrypto_aead_poll; + break; + case DIGEST_TYPE: +- uadk_poll_ctx = wcrypto_digest_poll; ++ wd_poll_ctx = wcrypto_digest_poll; + break; + default: + SEC_TST_PRT("<<<<<out; + res_iv = bd_res->iv; + +- /* create user data buffer */ +- src_data_buf = malloc(g_pktlen * sizeof(char)); +- if (!src_data_buf) +- return NULL; +- +- get_rand_data((u8 *)src_data_buf, g_pktlen); +- out_data_buf = malloc(g_pktlen * sizeof(char)); +- if (!out_data_buf) { +- free(src_data_buf); +- return NULL; +- } +- + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + tag = malloc(sizeof(struct wcrypto_async_tag)); // set the user tag + if (!tag) { + SEC_TST_PRT("wcrypto async alloc tag fail!\n"); +- free(src_data_buf); +- free(out_data_buf); + return NULL; + } +- tag->out_buf = out_data_buf; ++ tag->thread_id = pdata->td_id; + + switch(pdata->subtype) { + case CIPHER_TYPE: +@@ -642,7 +603,7 @@ static void *sec_wd_async_run(void *arg) + ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup); + if (!ctx) { + SEC_TST_PRT("wd create cipher ctx fail!\n"); +- goto async_err; ++ return NULL; + } + tag->ctx = ctx; + +@@ -650,7 +611,7 @@ static void *sec_wd_async_run(void *arg) + if (ret) { + SEC_TST_PRT("wd cipher set key fail!\n"); + wcrypto_del_cipher_ctx(ctx); +- goto async_err; ++ return NULL; + } + + if (queue->capa.priv.direction == 0) +@@ -672,9 +633,6 @@ static void *sec_wd_async_run(void *arg) + if (get_run_state() == 0) + break; + +- // no-sva data copy to uadk +- memcpy(copdata.in, src_data_buf, g_pktlen); +- + ret = wcrypto_do_cipher(ctx, &copdata, (void *)tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); +@@ -687,7 +645,7 @@ static void *sec_wd_async_run(void *arg) + } + + count++; +- i = count % MAX_BLOCK_NM; ++ i = count % MAX_POOL_LENTH; + tag->cnt = i; + try_cnt = 0; + copdata.in = res_in[i]; +@@ -710,7 +668,7 @@ static void *sec_wd_async_run(void *arg) + ctx = wcrypto_create_aead_ctx(queue, &aead_setup); + if (!ctx) { + SEC_TST_PRT("wd create aead ctx fail!\n"); +- goto async_err; ++ return NULL; + } + tag->ctx = ctx; + +@@ -718,7 +676,7 @@ static void *sec_wd_async_run(void *arg) + if (ret) { + SEC_TST_PRT("wd aead set key fail!\n"); + wcrypto_del_aead_ctx(ctx); +- goto async_err; ++ return NULL; + } + + authsize = 16; //set defaut size +@@ -726,7 +684,7 @@ static void *sec_wd_async_run(void *arg) + if (ret) { + SEC_TST_PRT("set authsize fail!\n"); + wcrypto_del_aead_ctx(ctx); +- goto async_err; ++ return NULL; + } + + if (queue->capa.priv.direction == 0) { +@@ -753,9 +711,6 @@ static void *sec_wd_async_run(void *arg) + if (get_run_state() == 0) + break; + +- // no-sva data copy to uadk +- memcpy(aopdata.in, src_data_buf, g_pktlen); +- + ret = wcrypto_do_aead(ctx, &aopdata, (void *)tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); +@@ -768,7 +723,7 @@ static void *sec_wd_async_run(void *arg) + } + + count++; +- i = count % MAX_BLOCK_NM; ++ i = count % MAX_POOL_LENTH; + tag->cnt = i; + try_cnt = 0; + aopdata.in = res_in[i]; +@@ -791,7 +746,7 @@ static void *sec_wd_async_run(void *arg) + ctx = wcrypto_create_digest_ctx(queue, &digest_setup); + if (!ctx) { + SEC_TST_PRT("wd create digest ctx fail!\n"); +- goto async_err; ++ return NULL; + } + tag->ctx = ctx; + +@@ -801,7 +756,7 @@ static void *sec_wd_async_run(void *arg) + if (ret) { + SEC_TST_PRT("wd digest set key fail!\n"); + wcrypto_del_digest_ctx(ctx); +- goto async_err; ++ return NULL; + } + } + +@@ -818,9 +773,6 @@ static void *sec_wd_async_run(void *arg) + if (get_run_state() == 0) + break; + +- // no-sva data copy to uadk +- memcpy(dopdata.in, src_data_buf, g_pktlen); +- + ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); +@@ -833,7 +785,7 @@ static void *sec_wd_async_run(void *arg) + } + + count++; +- i = count % MAX_BLOCK_NM; ++ i = count % MAX_POOL_LENTH; + tag->cnt = i; + try_cnt = 0; + dopdata.in = res_in[i]; +@@ -846,7 +798,7 @@ static void *sec_wd_async_run(void *arg) + add_send_complete(); + + while (1) { +- if (get_recv_time() == g_thread_num) // wait Async mode finish recv ++ if (get_recv_time() > 0) // wait Async mode finish recv + break; + usleep(SEND_USLEEP); + } +@@ -863,10 +815,6 @@ static void *sec_wd_async_run(void *arg) + break; + } + +-async_err: +- free(tag); +- free(src_data_buf); +- free(out_data_buf); + return NULL; + } + +@@ -882,8 +830,6 @@ static void *sec_wd_sync_run(void *arg) + char priv_key[MAX_IVK_LENTH]; + struct thread_bd_res *bd_res; + struct wd_queue *queue; +- char *src_data_buf = NULL; +- char *out_data_buf = NULL; + void *ctx = NULL; + void *tag = NULL; + void **res_in; +@@ -905,18 +851,6 @@ static void *sec_wd_sync_run(void *arg) + res_out = bd_res->out; + res_iv = bd_res->iv; + +- /* create user data buffer */ +- src_data_buf = malloc(g_pktlen * sizeof(char)); +- if (!src_data_buf) +- return NULL; +- +- get_rand_data((u8 *)src_data_buf, g_pktlen); +- out_data_buf = malloc(g_pktlen * sizeof(char)); +- if (!out_data_buf) { +- free(src_data_buf); +- return NULL; +- } +- + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + + switch(pdata->subtype) { +@@ -933,14 +867,14 @@ static void *sec_wd_sync_run(void *arg) + ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup); + if (!ctx) { + SEC_TST_PRT("wd create cipher ctx fail!\n"); +- goto sync_err; ++ return NULL; + } + + ret = wcrypto_set_cipher_key(ctx, (__u8*)priv_key, (__u16)pdata->keysize); + if (ret) { + SEC_TST_PRT("wd cipher set key fail!\n"); + wcrypto_del_cipher_ctx(ctx); +- goto sync_err; ++ return NULL; + } + + if (queue->capa.priv.direction == 0) +@@ -961,9 +895,6 @@ static void *sec_wd_sync_run(void *arg) + if (get_run_state() == 0) + break; + +- // no-sva data copy to uadk +- memcpy(copdata.in, src_data_buf, g_pktlen); +- + ret = wcrypto_do_cipher(ctx, &copdata, tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); +@@ -977,13 +908,10 @@ static void *sec_wd_sync_run(void *arg) + + count++; + try_cnt = 0; +- i = count % MAX_BLOCK_NM; ++ i = count % MAX_POOL_LENTH; + copdata.in = res_in[i]; + copdata.out = res_out[i]; + copdata.iv = res_iv[i]; +- +- // no-sva data copy from uadk to user +- memcpy(out_data_buf, copdata.out, g_pktlen); + } + wcrypto_del_cipher_ctx(ctx); + +@@ -1001,14 +929,14 @@ static void *sec_wd_sync_run(void *arg) + ctx = wcrypto_create_aead_ctx(queue, &aead_setup); + if (!ctx) { + SEC_TST_PRT("wd create aead ctx fail!\n"); +- goto sync_err; ++ return NULL; + } + + ret = wcrypto_set_aead_ckey(ctx, (__u8*)priv_key, (__u16)pdata->keysize); + if (ret) { + SEC_TST_PRT("wd aead set key fail!\n"); + wcrypto_del_aead_ctx(ctx); +- goto sync_err; ++ return NULL; + } + + authsize = 16; //set defaut size +@@ -1016,7 +944,7 @@ static void *sec_wd_sync_run(void *arg) + if (ret) { + SEC_TST_PRT("set authsize fail!\n"); + wcrypto_del_aead_ctx(ctx); +- goto sync_err; ++ return NULL; + } + + if (queue->capa.priv.direction == 0) { +@@ -1042,9 +970,6 @@ static void *sec_wd_sync_run(void *arg) + if (get_run_state() == 0) + break; + +- // no-sva data copy to uadk +- memcpy(aopdata.in, src_data_buf, g_pktlen); +- + ret = wcrypto_do_aead(ctx, &aopdata, tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); +@@ -1058,13 +983,10 @@ static void *sec_wd_sync_run(void *arg) + + count++; + try_cnt = 0; +- i = count % MAX_BLOCK_NM; ++ i = count % MAX_POOL_LENTH; + aopdata.in = res_in[i]; + aopdata.out = res_out[i]; + aopdata.iv = res_iv[i]; +- +- // no-sva data copy from uadk to user +- memcpy(out_data_buf, aopdata.out, g_pktlen); + } + wcrypto_del_aead_ctx(ctx); + +@@ -1082,7 +1004,7 @@ static void *sec_wd_sync_run(void *arg) + ctx = wcrypto_create_digest_ctx(queue, &digest_setup); + if (!ctx) { + SEC_TST_PRT("wd create digest ctx fail!\n"); +- goto sync_err; ++ return NULL; + } + + if (digest_setup.mode == WCRYPTO_DIGEST_HMAC) { +@@ -1091,7 +1013,7 @@ static void *sec_wd_sync_run(void *arg) + if (ret) { + SEC_TST_PRT("wd digest set key fail!\n"); + wcrypto_del_digest_ctx(ctx); +- goto sync_err; ++ return NULL; + } + } + +@@ -1107,9 +1029,6 @@ static void *sec_wd_sync_run(void *arg) + if (get_run_state() == 0) + break; + +- // no-sva data copy to uadk +- memcpy(dopdata.in, src_data_buf, g_pktlen); +- + ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); +@@ -1123,22 +1042,16 @@ static void *sec_wd_sync_run(void *arg) + + count++; + try_cnt = 0; +- i = count % MAX_BLOCK_NM; ++ i = count % MAX_POOL_LENTH; + dopdata.in = res_in[i]; +- dopdata.out = res_out[i]; +- +- // no-sva data copy from uadk to user +- memcpy(out_data_buf, dopdata.out, 16); ++ dopdata.out = res_out[i]; + } + wcrypto_del_digest_ctx(ctx); + break; + } + +- add_recv_data(count); ++ add_recv_data(count, g_pktlen); + +-sync_err: +- free(src_data_buf); +- free(out_data_buf); + return NULL; + } + +@@ -1180,6 +1093,7 @@ int sec_wd_sync_threads(struct acc_option *options) + + sync_error: + return ret; ++ + } + + int sec_wd_async_threads(struct acc_option *options) +@@ -1249,7 +1163,6 @@ int sec_wd_benchmark(struct acc_option *options) + + g_thread_num = options->threads; + g_pktlen = options->pktlen; +- g_ctxnum = options->ctxnums; + if (options->optype > WCRYPTO_CIPHER_DECRYPTION) { + SEC_TST_PRT("SEC optype error: %u\n", options->optype); + return -EINVAL; +diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c +index 84941d5..2904cba 100644 +--- a/uadk_tool/benchmark/uadk_benchmark.c ++++ b/uadk_tool/benchmark/uadk_benchmark.c +@@ -10,19 +10,19 @@ + + #define BYTES_TO_KB 10 + #define TABLE_SPACE_SIZE 8 +-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + + /*----------------------------------------head struct--------------------------------------------------------*/ + static unsigned int g_run_state = 1; + static pthread_mutex_t acc_mutex = PTHREAD_MUTEX_INITIALIZER; + static struct _recv_data { ++ double pkg_len; + u64 send_cnt; + u64 recv_cnt; + u32 send_times; + u32 recv_times; + } g_recv_data; + +-/* SVA mode and NOSVA mode change need re_insmode driver ko */ ++/* SVA mode and NOSVA mode change need re_insmod driver ko */ + enum test_type { + SVA_MODE = 0x1, + NOSVA_MODE = 0x2, +@@ -63,7 +63,7 @@ static struct acc_alg_item alg_options[] = { + {"rsa-2048-crt", RSA_2048_CRT}, + {"rsa-3072-crt", RSA_3072_CRT}, + {"rsa-4096-crt", RSA_4096_CRT}, +- {"dh-768 ", DH_768}, ++ {"dh-768", DH_768}, + {"dh-1024", DH_1024}, + {"dh-1536", DH_1536}, + {"dh-2048", DH_2048}, +@@ -131,10 +131,14 @@ void add_send_complete(void) + __atomic_add_fetch(&g_recv_data.send_times, 1, __ATOMIC_RELAXED); + } + +-void add_recv_data(u32 cnt) ++void add_recv_data(u32 cnt, u32 pkglen) + { + pthread_mutex_lock(&acc_mutex); + g_recv_data.recv_cnt += cnt; ++ if (g_recv_data.pkg_len == 0) ++ g_recv_data.pkg_len = pkglen; ++ else ++ g_recv_data.pkg_len = ((double)pkglen + g_recv_data.pkg_len) / 2; + g_recv_data.recv_times++; + pthread_mutex_unlock(&acc_mutex); + } +@@ -148,6 +152,7 @@ void init_recv_data(void) + { + g_recv_data.send_cnt = 0; + g_recv_data.recv_cnt = 0; ++ g_recv_data.pkg_len = 0.0; + g_recv_data.send_times = 0; + g_recv_data.recv_times = 0; + } +@@ -263,28 +268,21 @@ void time_start(u32 seconds) + alarm(seconds); + } + +-int get_rand_int(int range) +-{ +- int randnum; +- +- if (range <= 0) { +- ACC_TST_PRT("rand range error!\n"); +- return 1; +- } +- srand((unsigned)time(NULL) * getpid()); +- randnum = rand() % range; +- +- return randnum; +-} +- +-void get_rand_data(u8 *addr, int size) ++void get_rand_data(u8 *addr, u32 size) + { ++ unsigned short rand_state[3] = { ++ (0xae >> 16) & 0xffff, 0xae & 0xffff, 0x330e}; + int i; + +- srand((unsigned)time(NULL) * getpid()); +- for (i = 0; i < size; i++) { +- addr[i] = rand() % 0xFF; +- } ++#if 1 ++ // only 32bit valid, other 32bit is zero ++ for (i = 0; i < size >> 3; i++) ++ *((u64 *)addr + i) = nrand48(rand_state); ++#else ++ // full 64bit valid ++ for (i = 0; i < size >> 2; i++) ++ *((u32 *)addr + i) = nrand48(rand_state); ++#endif + } + + /*-------------------------------------main code------------------------------------------------------*/ +@@ -320,7 +318,7 @@ static void parse_alg_param(struct acc_option *option) + case X25519_ALG: + snprintf(option->algclass, MAX_ALG_NAME, "%s", "x25519"); + option->acctype = HPRE_TYPE; +- option->subtype = X22519_TYPE; ++ option->subtype = X25519_TYPE; + break; + case X448_ALG: + snprintf(option->algclass, MAX_ALG_NAME, "%s", "x448"); +@@ -366,8 +364,8 @@ void cal_perfermance_data(struct acc_option *option, u32 sttime) + double perfermance; + double cpu_rate; + u32 ttime = 1000; +- u32 perfdata; +- u32 perfops; ++ double perfdata; ++ double perfops; + double ops; + u32 ptime; + int i, len; +@@ -397,13 +395,13 @@ void cal_perfermance_data(struct acc_option *option, u32 sttime) + palgname[i] = '\0'; + + ptime = ptime - sttime; +- perfdata = (g_recv_data.recv_cnt * option->pktlen) >> BYTES_TO_KB; +- perfops = (g_recv_data.recv_cnt) >> BYTES_TO_KB; +- perfermance = (double)perfdata / option->times; +- ops = (double)perfops / option->times; ++ perfdata = g_recv_data.pkg_len * g_recv_data.recv_cnt / 1024.0; ++ perfops = (double)(g_recv_data.recv_cnt) / 1000.0; ++ perfermance = perfdata / option->times; ++ ops = perfops / option->times; + cpu_rate = (double)ptime / option->times; + ACC_TST_PRT("algname: length: perf: iops: CPU_rate:\n" +- "%s %uBytes %.1fKB/s %.1fKops %.2f%%\n", ++ "%s %-2uBytes %.1fKB/s %.1fKops %.2f%%\n", + palgname, option->pktlen, perfermance, ops, cpu_rate); + } + +@@ -419,11 +417,11 @@ static int benchmark_run(struct acc_option *option) + ret = sec_wd_benchmark(option); + } + usleep(20000); +- #ifdef WITH_OPENSSL_DIR ++#ifdef WITH_OPENSSL_DIR + if (option->modetype & SOFT_MODE) { + ret = sec_soft_benchmark(option); + } +- #endif ++#endif + break; + case HPRE_TYPE: + break; +@@ -447,6 +445,7 @@ static void dump_param(struct acc_option *option) + ACC_TST_PRT(" [--ctxnum]: %u\n", option->ctxnums); + ACC_TST_PRT(" [--algclass]:%s\n", option->algclass); + ACC_TST_PRT(" [--acctype]: %u\n", option->acctype); ++ ACC_TST_PRT(" [--prefetch]:%u\n", option->prefetch); + ACC_TST_PRT(" [--engine]: %s\n", option->engine); + } + +@@ -457,6 +456,7 @@ int acc_benchmark_run(struct acc_option *option) + int i, ret = 0; + int status; + ++ ACC_TST_PRT("start UADK benchmark test.\n"); + parse_alg_param(option); + dump_param(option); + +@@ -558,13 +558,27 @@ static void print_help(void) + ACC_TST_PRT(" set the number of threads\n"); + ACC_TST_PRT(" [--ctxnum]:\n"); + ACC_TST_PRT(" the number of QP queues used by the entire test task\n"); ++ ACC_TST_PRT(" [--prefetch]:\n"); ++ ACC_TST_PRT(" in SVA mode, Enable prefetch can reduce page faults and improve performance\n"); + ACC_TST_PRT(" [--engine]:\n"); + ACC_TST_PRT(" set the test openssl engine\n"); ++ ACC_TST_PRT(" [--alglist]:\n"); ++ ACC_TST_PRT(" list the all support alg\n"); + ACC_TST_PRT(" [--help] = usage\n"); + ACC_TST_PRT("Example\n"); + ACC_TST_PRT(" ./uadk_tool benchmark --alg aes-128-cbc --mode sva --opt 0 --sync\n"); + ACC_TST_PRT(" --pktlen 1024 --seconds 1 --multi 1 --thread 1 --ctxnum 4\n"); +- ACC_TST_PRT("UPDATE:2021-7-28\n"); ++ ACC_TST_PRT("UPDATE:2022-7-18\n"); ++} ++ ++static void print_support_alg(void) ++{ ++ int i; ++ ++ ACC_TST_PRT("UADK benchmark supported ALG:\n"); ++ for (i = 0; i < ALG_MAX; i++) { ++ ACC_TST_PRT("%s\n", alg_options[i].name); ++ } + } + + int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) +@@ -583,8 +597,10 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) + {"thread", required_argument, 0, 9}, + {"multi", required_argument, 0, 10}, + {"ctxnum", required_argument, 0, 11}, +- {"engine", required_argument, 0, 12}, +- {"help", no_argument, 0, 13}, ++ {"prefetch", no_argument, 0, 12}, ++ {"engine", required_argument, 0, 13}, ++ {"alglist", no_argument, 0, 14}, ++ {"help", no_argument, 0, 15}, + {0, 0, 0, 0} + }; + +@@ -593,7 +609,6 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) + if (c == -1) + break; + +- // ACC_TST_PRT("index:%d , optarg name:%s\n", c, optarg); + switch (c) { + case 2: + option->algtype = get_alg_type(optarg); +@@ -627,26 +642,36 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) + option->ctxnums = strtol(optarg, NULL, 0); + break; + case 12: +- strcpy(option->engine, optarg); ++ option->prefetch = 1; + break; + case 13: +- print_help(); ++ strcpy(option->engine, optarg); + break; ++ case 14: ++ print_support_alg(); ++ goto to_exit; ++ case 15: ++ print_help(); ++ goto to_exit; + default: + ACC_TST_PRT("bad input test parameter!\n"); + print_help(); +- exit(-1); ++ goto to_exit; + } + } ++ + return 0; ++ ++to_exit: ++ return -EINVAL; + } + + int acc_option_convert(struct acc_option *option) + { +- if (option->algtype >= ALG_MAX) ++ if (option->algtype >= ALG_MAX) { ++ ACC_TST_PRT("invalid: input algname is wrong!\n"); + goto param_err; +- else if (option->algtype < 0) +- option->algtype = AES_128_CBC; ++ } + + if (option->modetype >= INVALID_MODE) + goto param_err; +@@ -657,8 +682,8 @@ int acc_option_convert(struct acc_option *option) + /* Min test package size is 64Bytes */ + if (option->pktlen > MAX_DATA_SIZE) + goto param_err; +- else if (option->pktlen < 64) +- option->pktlen = 64; ++ else if (option->pktlen < 16) ++ option->pktlen = 16; + + if (option->times > MAX_TIME_SECONDS) { + ACC_TST_PRT("uadk benchmark max test times to 128 seconds\n"); +diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h +index 2cb3dc0..a344fac 100644 +--- a/uadk_tool/benchmark/uadk_benchmark.h ++++ b/uadk_tool/benchmark/uadk_benchmark.h +@@ -15,7 +15,6 @@ + #include + #include + #include +-#include + #include + + #define ACC_TST_PRT printf +@@ -24,21 +23,30 @@ + #define MAX_CTX_NUM 64 + #define MAX_TIME_SECONDS 128 + #define BYTES_TO_MB 20 +-#define MAX_OPT_TYPE 5 ++#define MAX_OPT_TYPE 6 + #define MAX_DATA_SIZE (15 * 1024 * 1024) + #define MAX_ALG_NAME 64 + #define ACC_QUEUE_SIZE 1024 + ++#define MAX_BLOCK_NM 16384 /* BLOCK_NUM must 4 times of POOL_LENTH */ ++#define MAX_POOL_LENTH 4096 ++#define MAX_TRY_CNT 5000 ++#define SEND_USLEEP 100 ++ + typedef unsigned char u8; + typedef unsigned int u32; + typedef unsigned long long u64; + #define SCHED_SINGLE "sched_single" ++#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + + /** + * struct acc_option - Define the test acc app option list. + * @algclass: 0:cipher 1:digest + * @acctype: The sub alg type, reference func get_cipher_resource. + * @syncmode: 0:sync mode 1:async mode ++ * @modetype: sva, no-sva, soft mode ++ * @optype: enc/dec, comp/decomp ++ * @prefetch: write allocated memory to prevent page faults + */ + struct acc_option { + char algname[64]; +@@ -56,6 +64,7 @@ struct acc_option { + u32 subtype; + char engine[64]; + u32 engine_flag; ++ u32 prefetch; + }; + + enum acc_type { +@@ -74,7 +83,7 @@ enum alg_type { + ECDH_TYPE, + ECDSA_TYPE, + SM2_TYPE, +- X22519_TYPE, ++ X25519_TYPE, + X448_TYPE, + }; + +@@ -164,9 +173,8 @@ extern void cal_perfermance_data(struct acc_option *option, u32 sttime); + extern void time_start(u32 seconds); + extern int get_run_state(void); + extern void set_run_state(int state); +-extern int get_rand_int(int range); +-extern void get_rand_data(u8 *addr, int size); +-extern void add_recv_data(u32 cnt); ++extern void get_rand_data(u8 *addr, u32 size); ++extern void add_recv_data(u32 cnt, u32 pkglen); + extern void add_send_complete(void); + extern u32 get_recv_time(void); + +-- +2.27.0 + diff --git a/0134-uadk_tool-Add-SVA-test-function-of-HPRE-algorithm.patch b/0134-uadk_tool-Add-SVA-test-function-of-HPRE-algorithm.patch new file mode 100644 index 0000000..e7dfd04 --- /dev/null +++ b/0134-uadk_tool-Add-SVA-test-function-of-HPRE-algorithm.patch @@ -0,0 +1,4145 @@ +From 133b429c4949dba6af0809c531cb08ac96238f60 Mon Sep 17 00:00:00 2001 +From: Longfang Liu +Date: Mon, 18 Jul 2022 17:16:32 +0800 +Subject: [PATCH 148/183] uadk_tool: Add SVA test function of HPRE algorithm + +Add the performance test function of SVA mode of +RSA, DH, ECC algorithms for HPRE module. + +Signed-off-by: Longfang Liu +--- + uadk_tool/benchmark/hpre_protocol_data.h | 1667 ++++++++++++++ + uadk_tool/benchmark/hpre_uadk_benchmark.c | 2433 +++++++++++++++++++++ + uadk_tool/benchmark/hpre_uadk_benchmark.h | 6 + + 3 files changed, 4106 insertions(+) + create mode 100644 uadk_tool/benchmark/hpre_protocol_data.h + create mode 100644 uadk_tool/benchmark/hpre_uadk_benchmark.c + create mode 100644 uadk_tool/benchmark/hpre_uadk_benchmark.h + +diff --git a/uadk_tool/benchmark/hpre_protocol_data.h b/uadk_tool/benchmark/hpre_protocol_data.h +new file mode 100644 +index 0000000..9c92138 +--- /dev/null ++++ b/uadk_tool/benchmark/hpre_protocol_data.h +@@ -0,0 +1,1667 @@ ++/* SPDX-License-Identifier: Apache-2.0 */ ++#ifndef HPRE_PROTOCOL_DATA_H ++#define HPRE_PROTOCOL_DATA_H ++ ++static unsigned char rsa_e_1024[] = { ++ 0x01, 0x00, 0x01, ++}; ++ ++static unsigned char rsa_p_1024[] = { ++ 0xf6, 0x49, 0xf2, 0xec, 0x89, 0xc8, 0xc2, 0x9b, 0x38, 0xd8, 0x74, 0x9b, 0x77, 0xed, 0x96, 0xc7, ++ 0x6d, 0xed, 0x15, 0x51, 0x2d, 0xfe, 0x67, 0x10, 0xa5, 0xdf, 0xd0, 0x59, 0x79, 0x75, 0x00, 0x60, ++ 0x3d, 0xd0, 0xf6, 0xe4, 0xda, 0x16, 0x5a, 0x24, 0x14, 0x01, 0xfa, 0x19, 0x07, 0x75, 0x21, 0x70, ++ 0x88, 0x40, 0xd9, 0x2f, 0xec, 0x83, 0x9e, 0x5f, 0xaa, 0xc0, 0xa3, 0x70, 0x18, 0xf5, 0x78, 0xdf, ++}; ++ ++static unsigned char rsa_q_1024[] = { ++ 0xcf, 0x53, 0x52, 0x09, 0x0d, 0xd7, 0x84, 0xdb, 0xa4, 0x4c, 0x79, 0x74, 0x0d, 0x94, 0xa0, 0x19, ++ 0x94, 0x33, 0xbf, 0x39, 0xe5, 0xef, 0xf5, 0xe9, 0x6c, 0xef, 0xd0, 0x9a, 0x4c, 0x00, 0x14, 0x68, ++ 0x66, 0xa7, 0x80, 0x32, 0x14, 0x84, 0xc9, 0x6f, 0x9a, 0x7d, 0x43, 0x0e, 0x9f, 0x85, 0x27, 0x6c, ++ 0x65, 0x50, 0x9b, 0x88, 0x54, 0x22, 0x72, 0x95, 0x90, 0x26, 0xc4, 0xa8, 0x19, 0x1c, 0x47, 0x03, ++}; ++ ++static unsigned char rsa_dp_1024[] = { ++ 0xd0, 0xb6, 0x66, 0x28, 0xd1, 0xb2, 0xd2, 0x48, 0x1c, 0x6a, 0x42, 0x97, 0x25, 0x90, 0xb0, 0x40, ++ 0x1d, 0x05, 0xd7, 0x14, 0xce, 0x77, 0x52, 0xfc, 0x26, 0xb5, 0x7e, 0xa8, 0xf4, 0x66, 0x94, 0x84, ++ 0xfa, 0x9d, 0xc5, 0x3c, 0xb7, 0x1c, 0x4e, 0x13, 0x58, 0xe9, 0x3b, 0xfa, 0x4d, 0xf9, 0x92, 0xf6, ++ 0xfc, 0x60, 0x88, 0x2d, 0x36, 0xaf, 0x6b, 0x5d, 0x03, 0x24, 0xf0, 0xdc, 0x24, 0x2a, 0x91, 0xdd, ++}; ++ ++static unsigned char rsa_dq_1024[] = { ++ 0x09, 0x4a, 0x89, 0x9d, 0xa0, 0x42, 0x2d, 0x51, 0x0e, 0x8e, 0xe2, 0xce, 0x81, 0xa1, 0x4c, 0x7f, ++ 0x78, 0xf5, 0xcc, 0xb7, 0x12, 0x87, 0xeb, 0x74, 0x57, 0x8e, 0x73, 0xc1, 0xc6, 0x70, 0x26, 0x79, ++ 0xfb, 0x47, 0xbc, 0x66, 0x02, 0x27, 0x65, 0x43, 0x9c, 0x1f, 0xca, 0xf6, 0x87, 0xcd, 0x96, 0xd3, ++ 0xb3, 0xc2, 0xa6, 0x05, 0xb9, 0x07, 0x86, 0x2d, 0x0f, 0xb5, 0xbd, 0x10, 0x6f, 0x77, 0xa5, 0xf3, ++}; ++ ++static unsigned char rsa_qinv_1024[] = { ++ 0x59, 0xf3, 0xaf, 0x75, 0xde, 0xdd, 0xcc, 0xc7, 0x62, 0xd7, 0xed, 0x4e, 0x81, 0x18, 0xca, 0x42, ++ 0xab, 0x36, 0x3b, 0x83, 0x5c, 0xd0, 0x55, 0x3f, 0x37, 0x3a, 0xa9, 0x64, 0x25, 0x65, 0x05, 0xde, ++ 0x87, 0xca, 0x54, 0xdb, 0x24, 0xdc, 0xe8, 0xf7, 0x4a, 0xfe, 0x2c, 0x59, 0xbf, 0x3d, 0x45, 0x43, ++ 0x91, 0x9e, 0x6b, 0x9c, 0xf6, 0xce, 0xb2, 0xf8, 0xc5, 0x2e, 0xef, 0x85, 0x58, 0xed, 0x4a, 0x0e, ++}; ++ ++static unsigned char rsa_d_1024[] = { ++ 0x13, 0xbe, 0x3a, 0x33, 0xf3, 0xad, 0x6f, 0xc7, 0x3a, 0x8c, 0x77, 0xe3, 0x73, 0xb8, 0x13, 0xf0, ++ 0x66, 0x50, 0xd7, 0x04, 0xe5, 0xeb, 0x11, 0x31, 0x97, 0x9b, 0xac, 0xd5, 0x72, 0x9f, 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 0xd0, 0xc4, 0x14, 0x9c, ++ 0xa9, 0xa4, 0x7e, 0x97, 0x04, 0xb9, 0xe7, 0x60, 0x47, 0xa2, 0xed, 0xea, 0xda, 0xec, 0x4e, 0x0a, ++ 0x7a, 0x01, 0x00, 0x19, 0x19, 0x99, 0x49, 0x28, 0x70, 0x07, 0x21, 0xd8, 0x0d, 0x1f, 0x2d, 0xa2, ++ 0x9d, 0x78, 0x94, 0x26, 0xdd, 0x26, 0x65, 0x66, 0xf3, 0x04, 0xc3, 0x3b, 0x5e, 0xca, 0x43, 0x9d, ++}; ++ ++static unsigned char rsa_e_2048[] = { ++ 0x01, 0x00, 0x01, ++}; ++ ++static unsigned char rsa_p_2048[] = { ++ 0x01, 0xf8, 0x33, 0x75, 0x8c, 0x8d, 0x6b, 0xed, 0x4b, 0xf7, 0x0a, 0x3a, 0x67, 0xd5, 0x91, ++ 0x27, 0xe6, 0x62, 0x90, 0x67, 0xd2, 0xe3, 0x33, 0xdc, 0xba, 0x96, 0x81, 0xb7, 0xc9, 0xc8, ++ 0xa6, 0x64, 0x8b, 0xe9, 0x2f, 0x1d, 0x87, 0x3c, 0x9a, 0x95, 0x19, 0x8b, 0x04, 0x8c, 0x1a, ++ 0xc1, 0x6b, 0x76, 0x8d, 0xe3, 0x2a, 0x50, 0xec, 0xb8, 0xf7, 0x02, 0x38, 0x5d, 0xd0, 0xe6, ++ 0xc0, 0x9f, 0xb5, 0xc6, 0xf7, 0xd0, 0x34, 0xec, 0xd5, 0x4d, 0xf5, 0x26, 0x32, 0x8a, 0xe8, ++ 0x5f, 0xd5, 0x1d, 0x0e, 0xd8, 0xcd, 0x84, 0xe0, 0xd6, 0x09, 0x3a, 0xcd, 0x8b, 0x5c, 0x96, ++ 0x89, 0xf0, 0x2e, 0xb7, 0x87, 0x9c, 0x12, 0xeb, 0xd6, 0x84, 0x00, 0x3d, 0x1c, 0xff, 0xa0, ++ 0xaa, 0x82, 0x0a, 0x4d, 0x53, 0x06, 0xde, 0x5a, 0x0c, 0x4a, 0xd4, 0x94, 0x5b, 0x01, 0xac, ++ 0x9f, 0x9e, 0x7e, 0x90, 0xb0, 0xd7, 0x19 ++}; ++ ++static unsigned char rsa_q_2048[] = { ++ 0x01, 0xe1, 0xf1, 0x9b, 0xd6, 0xcf, 0x15, 0x49, 0x4c, 0xfa, 0x90, 0xf1, 0x27, 0xb1, 0xe2, ++ 0xc9, 0xf8, 0xec, 0x97, 0xc5, 0x10, 0x6c, 0xad, 0x62, 0xba, 0x1b, 0x23, 0x1e, 0x95, 0xb3, ++ 0x30, 0x89, 0x15, 0xc2, 0x19, 0x9e, 0xa8, 0x06, 0x30, 0xe1, 0xf0, 0x14, 0xfa, 0x99, 0x10, ++ 0x22, 0x13, 0x43, 0xb1, 0x97, 0xa4, 0x7d, 0x5d, 0x92, 0xa4, 0xf1, 0x28, 0x33, 0xbc, 0x9b, ++ 0x20, 0xba, 0x73, 0x66, 0x32, 0x96, 0x63, 0xb2, 0x1d, 0x49, 0xe8, 0xbc, 0x2e, 0x88, 0x2b, ++ 0x9f, 0x89, 0x14, 0xb6, 0x5e, 0xe1, 0xe9, 0x0f, 0x1c, 0xa8, 0xd5, 0xa4, 0xda, 0x61, 0xde, ++ 0x0c, 0x36, 0xce, 0xf2, 0x89, 0xeb, 0x59, 0xd5, 0xd0, 0xdf, 0x77, 0xb5, 0x14, 0xa6, 0xcf, ++ 0x35, 0x86, 0xf1, 0x78, 0x1a, 0x8a, 0x52, 0x6f, 0x06, 0x20, 0x17, 0xca, 0xa8, 0xae, 0x4a, ++ 0x60, 0xf9, 0x89, 0x05, 0xc6, 0x0d, 0x87 ++}; ++ ++static unsigned char rsa_dp_2048[] = { ++ 0x54, 0xd7, 0xb3, 0xec, 0x16, 0xd0, 0x16, 0x7a, 0x35, 0xf3, 0xce, 0xa8, 0x32, 0x53, 0xde, ++ 0xb6, 0xf1, 0xd7, 0x02, 0xe1, 0x85, 0xc1, 0xf0, 0x5e, 0xa5, 0x7c, 0xe6, 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, 0x96, 0x43, 0x85, 0x48, 0x3b, 0xce, 0x46, 0x70, 0xe7, 0x0c, 0x67, 0x83, 0x55, 0x4a, 0xa8, ++ 0x46, 0xf1, 0xa8, 0xad, 0x77, 0xa8, 0xfc, 0x1f, 0x11, 0xcc, 0x8a, 0x69, 0x41, 0xaf, 0x98, 0xf1, ++ 0x77, 0x45, 0x16, 0x39, 0x0e, 0x87, 0x14, 0x07, 0x55, 0x9c, 0x43, 0x33, 0x17, 0xb1, 0x30, 0x7d, ++ 0xdb, 0x78, 0x9d, 0x0f, 0xe7, 0x96, 0xe8, 0x50, 0x66, 0x32, 0x2d, 0xf8, 0xa8, 0x6d, 0x6b, 0x39, ++ 0x59, 0x65, 0xcb, 0xb4, 0x75, 0xfa, 0x1e, 0x44, 0x46, 0x1a, 0x41, 0x8b, 0x4d, 0xae, 0x3f, 0xd5 ++}; ++ ++static unsigned char rsa_qinv_3072[] = { ++ 0xb2, 0xa1, 0x52, 0x54, 0xee, 0xcd, 0xb9, 0x07, 0xde, 0x26, 0x8a, 0x1b, 0x93, 0x91, 0xf7, 0x08, ++ 0xbe, 0x81, 0x23, 0x0c, 0xba, 0x24, 0x7a, 0x66, 0x57, 0x41, 0x09, 0xc6, 0x3a, 0x25, 0xa8, 0x56, ++ 0x03, 0x34, 0xcd, 0xcb, 0x97, 0xe8, 0x48, 0xdf, 0x64, 0xc8, 0xd3, 0xe2, 0xfd, 0xaa, 0xcb, 0xdc, ++ 0x9c, 0xfc, 0xab, 0x0d, 0x00, 0x57, 0x06, 0xb3, 0x71, 0x53, 0xe9, 0x2d, 0x7c, 0xcc, 0x68, 0xca, ++ 0x24, 0x94, 0x11, 0x48, 0x21, 0xb0, 0x55, 0xcb, 0xa9, 0x2b, 0x09, 0x99, 0x90, 0x9a, 0xaa, 0xea, ++ 0xa3, 0xbd, 0x4d, 0xf3, 0xba, 0x67, 0x55, 0x3c, 0x5c, 0xbf, 0xfa, 0x23, 0xbf, 0xfc, 0xcd, 0x7e, ++ 0x99, 0x60, 0xf1, 0x71, 0x78, 0x03, 0x15, 0xbb, 0xda, 0x54, 0xd9, 0x3d, 0x0d, 0x19, 0xad, 0xbf, ++ 0x3e, 0x35, 0xa9, 0x5d, 0xf7, 0xb1, 0x88, 0x78, 0x96, 0x59, 0xda, 0x0b, 0x54, 0xd9, 0x8a, 0x64, ++ 0x89, 0xf8, 0xea, 0x27, 0x78, 0x73, 0x58, 0x40, 0x1f, 0xec, 0xa3, 0xdd, 0xe3, 0xdb, 0x88, 0xdb, ++ 0x3f, 0x00, 0xc1, 0xdb, 0x95, 0x24, 0x7d, 0x55, 0x2f, 0xe1, 0xa1, 0xa5, 0x70, 0x13, 0xd5, 0xc7, ++ 0x26, 0x41, 0x9f, 0x79, 0xc7, 0x5b, 0x30, 0x58, 0x65, 0x16, 0xa0, 0x0d, 0xac, 0x1d, 0xc8, 0x8d, ++ 0xe1, 0xce, 0xc2, 0x61, 0x0f, 0xb0, 0x02, 0xc9, 0x80, 0x1e, 0xbd, 0x25, 0x83, 0xbc, 0x9d, 0xdc ++}; ++ ++static unsigned char rsa_d_3072[] = { ++ 0x33, 0x49, 0x58, 0xb0, 0x89, 0x3d, 0x96, 0x78, 0xb7, 0x2a, 0x99, 0x5e, 0x0c, 0x56, 0xae, 0x08, ++ 0x32, 0xe1, 0xb9, 0x1c, 0x17, 0xd7, 0x71, 0xaa, 0x57, 0x37, 0x58, 0xbf, 0x94, 0xf8, 0xa0, 0xdf, ++ 0xdb, 0x0a, 0xfd, 0x2f, 0xce, 0x8a, 0x82, 0x43, 0x11, 0x48, 0x6b, 0xec, 0x61, 0x72, 0x77, 0x98, ++ 0x53, 0x00, 0x32, 0x5e, 0xbe, 0x3d, 0x37, 0xaf, 0x53, 0x55, 0x13, 0xc7, 0x61, 0x03, 0x6a, 0x28, ++ 0xc8, 0xe6, 0xa8, 0xac, 0x5f, 0xcf, 0x15, 0x54, 0x36, 0xc4, 0x74, 0x60, 0x3b, 0xcc, 0xbc, 0x4f, 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, 0x90, 0xd9, 0xad, 0x6e, 0x26, 0x89, 0xf9, 0x7f, 0x7f, 0x0a, 0x3b, 0xe5, 0xf8, ++ 0x40, 0x88, 0x10, 0x08, 0x40, 0xc8, 0x31, 0x84, 0x8f, 0x18, 0x5c, 0xe6, 0x60, 0xa0, 0x3a, 0x94, ++ 0xc7, 0x45, 0xf8, 0xbc, 0x90, 0x2c, 0x2d, 0x92, 0x41, 0x6e, 0xe0, 0xb5, 0xe4, 0x85, 0x69, 0xfc, ++ 0xef, 0xd6, 0xdb, 0xe9, 0x73, 0x73, 0x42, 0x5f, 0x0f, 0x08, 0xec, 0xd6, 0xd7, 0x92, 0xa6, 0x7f, ++ 0xfb, 0xa1, 0x31, 0x7d, 0x57, 0x44, 0xdf, 0xfa, 0xf8, 0xaf, 0x2e, 0x5a, 0x00, 0xa2, 0x6a, 0x2b, ++ 0x9d, 0x05, 0xf5, 0xba, 0xd4, 0x19, 0x07, 0xd2, 0x1e, 0x85, 0x67, 0xf1, 0x51, 0x96, 0xe0, 0x44, ++ 0xba, 0x76, 0xf4, 0x4e, 0xa0, 0x2b, 0xb0, 0x6e, 0xe8, 0xd9, 0xb1, 0xd3, 0xcd, 0x85, 0xd0, 0x45, ++ 0x70, 0x70, 0x1c, 0x94, 0xcc, 0x7e, 0x6b, 0x81, 0x19, 0x07, 0xdd, 0x05, 0x91, 0xc2, 0x78, 0x32, ++ 0x72, 0x09, 0x62, 0x30, 0xf0, 0x73, 0x7b, 0xbc, 0x5e, 0x7d, 0x3d, 0xfe, 0x0d, 0x8b, 0xef, 0x31, ++ 0xdb, 0x8e, 0x28, 0x20, 0xae, 0x0e, 0xe0, 0x7d, 0x63, 0x79, 0x05, 0x1b, 0x13, 0x8a, 0x8d, 0x15 ++}; ++ ++static unsigned char rsa_e_4096[] = { ++ 0x01, 0x00, 0x01 ++}; ++ ++static unsigned char rsa_p_4096[] = { ++ 0xff, 0x0f, 0x4f, 0x6c, 0xdd, 0x59, 0xd8, 0x48, 0x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, 0xce, 0x6d, 0x60, 0xa9, 0x3a, 0xb2, 0xc3, 0x15, 0xfe, 0x97, 0xcd, 0x92, 0x56, 0x9d, ++ 0x63, 0x97, 0xad, 0x3e, 0x48, 0xcd, 0x05, 0x15, 0x31, 0x71, 0xfd, 0x8d, 0xb4, 0x5f, 0x32, 0x08, ++ 0xc3, 0x33, 0xf3, 0x69, 0x9e, 0xb7, 0xf6, 0x3a, 0x24, 0x4b, 0x34, 0xf3, 0x52, 0xac, 0xed, 0xdf, ++ 0x18, 0x79, 0xbb, 0x2f, 0x8f, 0xd6, 0xf4, 0xae, 0xe3, 0xae, 0x61, 0x9e, 0x32, 0x16, 0x08, 0x61 ++}; ++ ++static unsigned char rsa_dq_4096[] = { ++ 0xb8, 0x1a, 0x74, 0xe6, 0x96, 0x0a, 0x4e, 0x1f, 0xf0, 0x84, 0xf5, 0x52, 0xe4, 0xd4, 0x66, 0xe0, ++ 0x78, 0x0e, 0xc7, 0x45, 0xa7, 0xdc, 0x89, 0x8d, 0x06, 0x60, 0x5f, 0x54, 0xf7, 0x36, 0x4f, 0x27, ++ 0x70, 0xd3, 0x71, 0x4e, 0xf9, 0x79, 0x34, 0x39, 0xf7, 0xe1, 0xaf, 0xf0, 0x8d, 0xd3, 0x27, 0x94, ++ 0xca, 0x61, 0x66, 0x0d, 0x89, 0x0e, 0xc0, 0x12, 0x35, 0xc4, 0xff, 0x12, 0x1e, 0xba, 0xfb, 0x72, ++ 0x19, 0x68, 0xa7, 0x47, 0x7a, 0x96, 0x62, 0x37, 0x1b, 0x24, 0x25, 0x0b, 0x43, 0x05, 0x3e, 0xbe, ++ 0x97, 0xf8, 0xe8, 0x95, 0xf2, 0xd5, 0xc3, 0xad, 0xca, 0xf7, 0x38, 0xd3, 0x52, 0x56, 0xd1, 0xa8, ++ 0x45, 0xdd, 0xde, 0x54, 0x09, 0x8c, 0x18, 0x37, 0x4a, 0x6a, 0x17, 0x8a, 0x52, 0x13, 0xba, 0xcc, ++ 0x71, 0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0x32, 0x2f, 0x46, 0x8c, 0x89, 0xe6, 0x2c, 0x75, 0x11, 0x16, 0xd5, 0xea, ++ 0xbf, 0x0c, 0x21, 0x75, 0x3a, 0xad, 0x9a, 0xd1, 0x3e, 0xd8, 0x4d, 0xee, 0x89, 0xe3, 0x6b, 0x51 ++}; ++ ++static unsigned char rsa_n_4096[] = { ++ 0xe7, 0xbd, 0x61, 0x33, 0xc2, 0xd8, 0x4c, 0x41, 0xa0, 0x3d, 0xd2, 0xa6, 0xad, 0x39, 0x2b, 0x62, ++ 0x26, 0x3f, 0x7f, 0xa3, 0xbe, 0xdf, 0x35, 0xd3, 0x62, 0x67, 0x3b, 0x09, 0xe5, 0x9d, 0xf4, 0x21, ++ 0x6f, 0x0b, 0xf1, 0x9a, 0x5a, 0xe0, 0x72, 0x80, 0xcf, 0x27, 0x99, 0x25, 0xea, 0x3d, 0x73, 0x70, ++ 0x7f, 0x03, 0x61, 0x9d, 0xca, 0x25, 0xf2, 0xd2, 0x29, 0x04, 0x1a, 0xf5, 0x08, 0xa6, 0xac, 0xc0, ++ 0x6d, 0x1f, 0x0e, 0x0e, 0xfd, 0x6e, 0x73, 0xe7, 0x1d, 0x60, 0x92, 0x13, 0xc3, 0x20, 0x39, 0x95, ++ 0x9a, 0x1e, 0x31, 0x07, 0x07, 0x45, 0x62, 0x97, 0xe4, 0xe4, 0x41, 0x98, 0xf2, 0x4c, 0x06, 0x9b, ++ 0xb1, 0x13, 0x28, 0x70, 0xa8, 0x2c, 0x99, 0x59, 0x8a, 0x85, 0x0b, 0x92, 0xde, 0x35, 0x9a, 0x68, ++ 0x9b, 0x9f, 0x8f, 0x70, 0x1e, 0x68, 0x22, 0x25, 0x32, 0xdf, 0x78, 0xac, 0xc3, 0x0b, 0x2f, 0x4e, ++ 0x26, 0x1c, 0x6a, 0xb9, 0x2d, 0x98, 0xa6, 0x48, 0x94, 0xce, 0x37, 0x01, 0x08, 0x0f, 0x28, 0x42, ++ 0x2b, 0x97, 0x93, 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c5, 0x64, 0x4c, 0x29, 0xd4, 0x27, 0x08, 0xe3, 0x69 ++}; ++ ++static unsigned char dh_g_5[] = {0x05}; ++static unsigned char dh_g_2[] = {0x02}; ++ ++static unsigned char dh_p_768[] = { ++ 0xdd, 0xe8, 0xa1, 0x7d, 0xdd, 0x39, 0x87, 0x3c, 0xa1, 0x6a, 0xeb, 0x1b, 0x4f, 0x14, 0x72, 0x88, ++ 0x6c, 0x14, 0x6d, 0x24, 0xb7, 0xda, 0xf8, 0x97, 0xaa, 0xba, 0xb4, 0xdd, 0xc9, 0x5b, 0x28, 0x10, ++ 0x49, 0xfa, 0x93, 0xcc, 0x62, 0xc0, 0x70, 0xf8, 0xd6, 0xdc, 0xb2, 0x80, 0x35, 0x20, 0x84, 0xa4, ++ 0x99, 0xfc, 0x10, 0x7c, 0x9d, 0xc0, 0xc6, 0xd4, 0x8b, 0x0c, 0x57, 0xf1, 0x01, 0xf5, 0x1a, 0x4f, ++ 0x20, 0xfa, 0x8d, 0x66, 0x8b, 0x22, 0x3c, 0x96, 0xef, 0xd0, 0xde, 0xe5, 0x7e, 0x7f, 0x23, 0xdc, ++ 0x6d, 0x71, 0xdf, 0xc3, 0xe5, 0x1b, 0x39, 0xfe, 0xb7, 0x77, 0xe5, 0x72, 0x0d, 0x1c, 0x8d, 0xb7 ++}; ++ ++static unsigned char dh_xa_768[] = { ++ 0xe0, 0x80, 0x86, 0x24, 0xe2, 0x20, 0x35, 0x97, 0xda, 0x0e, 0x68, 0x39, 0x01, 0xdd, 0x01, 0x87, ++ 0xa2, 0x47, 0xd2, 0x0d, 0xee, 0xfe, 0xdc, 0x5a, 0x37, 0x23, 0xeb, 0x3d, 0xe8, 0x1e, 0x39, 0x2d, ++ 0xbf, 0xa6, 0xe9, 0x17, 0x48, 0xe2, 0xea, 0xef, 0x1d, 0x2f, 0xe2, 0xaf, 0x3c, 0xbc, 0xae, 0xa7, ++ 0x42, 0x9b, 0xa5, 0x7d, 0x47, 0x8a, 0x20, 0xc5, 0xae, 0xa1, 0xe4, 0xe8, 0x1c, 0x05, 0xc0, 0x0a, ++ 0x05, 0xdc, 0x01, 0x74, 0xde, 0xad, 0xad, 0x07, 0xec, 0x6e, 0x6a, 0xc7, 0xee, 0x0f, 0xb8, 0xbe, ++ 0xaa, 0x46, 0x61, 0x8c, 0x12, 0x5a, 0xaf, 0x05, 0xff, 0x1b, 0x35, 0x6b, 0xe2, 0x3d, 0x48, 0x4f ++}; ++ ++static unsigned char dh_except_a_pubkey_768[] = { ++ 0xba, 0xe7, 0x3, 0x5b, 0xe4, 0x70, 0x8b, 0xe0, 0xe1, 0x92, 0x13, 0x86, 0x74, 0x4, 0xdc, 0x6a, ++ 0x0a, 0x2a, 0x20, 0xec, 0x6d, 0xbf, 0xf0, 0x46, 0xf7, 0x9, 0x2, 0xdb, 0x2f, 0x70, 0x11, 0xdd, ++ 0xb0, 0x13, 0xa2, 0xc1, 0x58, 0x74, 0x29, 0x19, 0x8d, 0x4a, 0x94, 0x80, 0x0b, 0xd7, 0x25, 0x85, ++ 0x10, 0x35, 0x97, 0x48, 0x6e, 0x70, 0x28, 0xae, 0x58, 0x97, 0x7d, 0xf2, 0x19, 0x27, 0x13, 0xab, ++ 0x47, 0x9b, 0x54, 0xdf, 0xc3, 0x5b, 0x5f, 0x5e, 0xb4, 0x64, 0x47, 0xce, 0x40, 0x3b, 0x0c, 0x4a, ++ 0x62, 0x52, 0xba, 0xc7, 0xf0, 0x36, 0x87, 0x9c, 0x79, 0x9a, 0x83, 0x11, 0x61, 0x0c, 0x1b, 0x6b ++}; ++ ++static unsigned char dh_except_b_pubkey_768[] = { ++ 0x0d, 0xe8, 0xa1, 0x7d, 0xdd, 0x39, 0x87, 0x3c, 0xa1, 0x6a, 0xeb, 0x1b, 0x4f, 0x14, 0x72, 0x88, ++ 0x6c, 0x14, 0x6d, 0x24, 0xb7, 0xda, 0xf8, 0x97, 0xaa, 0xba, 0xb4, 0xdd, 0xc9, 0x5b, 0x28, 0x10, ++ 0x49, 0xfa, 0x93, 0xcc, 0x62, 0xc0, 0x70, 0xf8, 0xd6, 0xdc, 0xb2, 0x80, 0x35, 0x20, 0x84, 0xa4, ++ 0x99, 0xfc, 0x10, 0x7c, 0x9d, 0xc0, 0xc6, 0xd4, 0x8b, 0x0c, 0x57, 0xf1, 0x1, 0xf5, 0x1a, 0x4f, ++ 0x20, 0xfa, 0x8d, 0x66, 0x8b, 0x22, 0x3c, 0x96, 0xef, 0xd0, 0xde, 0xe5, 0x7e, 0x7f, 0x23, 0xdc, ++ 0x6d, 0x71, 0xdf, 0xc3, 0xe5, 0x1b, 0x39, 0xfe, 0xb7, 0x77, 0xe5, 0x72, 0x0d, 0x1c, 0x8d, 0xb7 ++}; ++ ++static unsigned char dh_share_key_768[] = { ++ 0x55, 0x9, 0x6b, 0x9c, 0xc6, 0x37, 0xa9, 0x9b, 0xdf, 0x67, 0x73, 0x7b, 0x46, 0xf9, 0x63, 0x47, ++ 0xcb, 0xa0, 0x57, 0x2a, 0xed, 0x97, 0x2f, 0xfe, 0x92, 0xf2, 0x20, 0x2c, 0x7e, 0xee, 0x7d, 0x11, ++ 0x78, 0xe6, 0xb9, 0x9, 0xd1, 0x94, 0xce, 0xd1, 0x5b, 0xf4, 0x44, 0xa9, 0xcb, 0x26, 0x2, 0x36, ++ 0x57, 0x2c, 0xa2, 0xbe, 0x37, 0xde, 0x86, 0x46, 0x20, 0x27, 0x9d, 0xa0, 0x2f, 0x4, 0xc1, 0xcd, ++ 0xff, 0x81, 0xe5, 0xe6, 0x2c, 0x9e, 0x39, 0x82, 0x31, 0x54, 0x33, 0xf8, 0xe7, 0xa0, 0xe5, 0x96, ++ 0xa4, 0x40, 0xc4, 0x44, 0xfe, 0x93, 0x66, 0xe2, 0xda, 0xaa, 0xb8, 0xfb, 0x2f, 0x3b, 0x8c, 0xce, ++}; ++ ++static unsigned char dh_p_1024[] = { ++ 0x6a, 0xf3, 0x2c, 0xd2, 0x2d, 0x55, 0xc1, 0x54, 0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, 0x5a, 0x37, 0x23, 0xeb, 0x3d, 0xe8, 0x1e, 0x39, 0x2d, ++ 0xbf, 0xa6, 0xe9, 0x17, 0x48, 0xe2, 0xea, 0xef, 0x1d, 0x2f, 0xe2, 0xaf, 0x3c, 0xbc, 0xae, 0xa7, ++ 0x42, 0x9b, 0xa5, 0x7d, 0x47, 0x8a, 0x20, 0xc5, 0xae, 0xa1, 0xe4, 0xe8, 0x1c, 0x05, 0xc0, 0x0a, ++ 0x05, 0xdc, 0x01, 0x74, 0xde, 0xad, 0xad, 0x07, 0xec, 0x6e, 0x6a, 0xc7, 0xee, 0x0f, 0xb8, 0xbe, ++ 0xaa, 0x46, 0x61, 0x8c, 0x12, 0x5a, 0xaf, 0x05, 0xff, 0x1b, 0x35, 0x6b, 0xe2, 0x3d, 0x48, 0x4f ++}; ++ ++static unsigned char dh_except_a_pubkey_1024[] = { ++ 0x5d, 0xa6, 0x7, 0x56, 0x93, 0x89, 0xe5, 0x0f, 0x2a, 0xb5, 0x67, 0x3a, 0xcf, 0xc3, 0x82, 0x83, ++ 0xf6, 0x88, 0x52, 0x0b, 0xfc, 0x6a, 0x5b, 0x1a, 0x57, 0x87, 0x86, 0xef, 0xda, 0x47, 0xdb, 0x4d, ++ 0xba, 0xe7, 0x3, 0x5b, 0xe4, 0x70, 0x8b, 0xe0, 0xe1, 0x92, 0x13, 0x86, 0x74, 0x4, 0xdc, 0x6a, ++ 0x0a, 0x2a, 0x20, 0xec, 0x6d, 0xbf, 0xf0, 0x46, 0xf7, 0x9, 0x2, 0xdb, 0x2f, 0x70, 0x11, 0xdd, ++ 0xb0, 0x13, 0xa2, 0xc1, 0x58, 0x74, 0x29, 0x19, 0x8d, 0x4a, 0x94, 0x80, 0x0b, 0xd7, 0x25, 0x85, ++ 0x10, 0x35, 0x97, 0x48, 0x6e, 0x70, 0x28, 0xae, 0x58, 0x97, 0x7d, 0xf2, 0x19, 0x27, 0x13, 0xab, ++ 0x47, 0x9b, 0x54, 0xdf, 0xc3, 0x5b, 0x5f, 0x5e, 0xb4, 0x64, 0x47, 0xce, 0x40, 0x3b, 0x0c, 0x4a, ++ 0x62, 0x52, 0xba, 0xc7, 0xf0, 0x36, 0x87, 0x9c, 0x79, 0x9a, 0x83, 0x11, 0x61, 0x0c, 0x1b, 0x6b ++}; ++ ++static unsigned char dh_except_b_pubkey_1024[] = { ++ 0x4a, 0xf3, 0x2c, 0xd2, 0x2d, 0x55, 0xc1, 0x54, 0x40, 0x18, 0x71, 0x7, 0x96, 0xa9, 0x56, 0x6e, ++ 0x45, 0x58, 0x24, 0xce, 0x75, 0x80, 0x3, 0x68, 0x36, 0x96, 0x3, 0xb2, 0x9c, 0x25, 0xbc, 0x55, ++ 0x0d, 0xe8, 0xa1, 0x7d, 0xdd, 0x39, 0x87, 0x3c, 0xa1, 0x6a, 0xeb, 0x1b, 0x4f, 0x14, 0x72, 0x88, ++ 0x6c, 0x14, 0x6d, 0x24, 0xb7, 0xda, 0xf8, 0x97, 0xaa, 0xba, 0xb4, 0xdd, 0xc9, 0x5b, 0x28, 0x10, ++ 0x49, 0xfa, 0x93, 0xcc, 0x62, 0xc0, 0x70, 0xf8, 0xd6, 0xdc, 0xb2, 0x80, 0x35, 0x20, 0x84, 0xa4, ++ 0x99, 0xfc, 0x10, 0x7c, 0x9d, 0xc0, 0xc6, 0xd4, 0x8b, 0x0c, 0x57, 0xf1, 0x1, 0xf5, 0x1a, 0x4f, ++ 0x20, 0xfa, 0x8d, 0x66, 0x8b, 0x22, 0x3c, 0x96, 0xef, 0xd0, 0xde, 0xe5, 0x7e, 0x7f, 0x23, 0xdc, ++ 0x6d, 0x71, 0xdf, 0xc3, 0xe5, 0x1b, 0x39, 0xfe, 0xb7, 0x77, 0xe5, 0x72, 0x0d, 0x1c, 0x8d, 0xb7 ++}; ++ ++static unsigned char dh_share_key_1024[] = { ++ 0xcc, 0x48, 0x97, 0xe4, 0x21, 0x65, 0xa6, 0x55, 0xb8, 0xf3, 0xb2, 0x7b, 0x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xf3,0x7f,0x64,0x70,0x13,0x59,0x8e,0x44,0x31,0x92,0x1b,0xb4,0xaa, ++ 0xf9,0x64,0xfd,0xb7,0x3c,0x81,0xc0,0xf9,0x66,0x5d,0xff,0x9,0x3e,0x26,0xaf,0x1a, ++ 0xc0,0xd2,0xd9,0x7c,0x0e,0x6f,0x81,0x12,0x82,0x90,0x1b,0x37,0xb7,0x1a,0x7e,0x36, ++ 0x79,0x15,0xb1,0xe1,0xd5,0x2d,0x72,0xd4,0x47,0xf7,0x30,0x3c,0x17,0xe1,0x76,0x15, ++ 0xbc,0x17,0xdc,0x9d,0xd9,0xfc,0xfd,0xb6,0xe6,0xbd,0x8e,0x47,0x8d,0xbb,0xa8,0x8a, ++ 0xe7,0xe7,0x57,0xf2,0xd8,0x80,0x4c,0xdd,0xe7,0xaf,0x29,0xee,0x40,0x4e,0x2,0xad, ++ 0xec,0xb3,0x18,0x8e,0x4b,0x2d,0xd2,0x28,0x4e,0x58,0x85,0x29,0xe3,0x93,0x1b,0xa7, ++}; ++ ++static unsigned char dh_except_a_pubkey_1536[] = { ++ 0x97,0x1e,0x6d,0xf7,0xb1,0x2f,0xa7,0x82,0x9e,0x99,0x22,0xfb,0xf3,0x4e,0x2a,0x73, ++ 0xcc,0xd9,0x2b,0x10,0x1,0xfb,0xac,0xf1,0x81,0xfe,0x78,0x3d,0x23,0xb0,0xcf,0x5c, ++ 0x95,0x69,0x36,0xc0,0x99,0x6a,0xd2,0x9c,0xf0,0x85,0x8d,0xda,0x5d,0xba,0x8e,0x0f, ++ 0xa3,0xce,0xbe,0x9b,0xe8,0x3b,0xad,0x71,0xfd,0xfd,0x53,0x25,0xee,0x61,0x26,0x15, ++ 0x0a,0x46,0x9e,0xce,0x85,0xb1,0x5c,0xf1,0xa0,0x8f,0xe7,0x89,0xe3,0x4f,0x7c,0xea, ++ 0x18,0xd3,0xa9,0x44,0xce,0x35,0x9,0x86,0x80,0x8c,0x30,0x1,0xbc,0x6d,0xf6,0x6a, ++ 0x3a,0xa6,0xad,0xbe,0xfa,0x73,0x6b,0xb0,0x35,0x8c,0x63,0x80,0xb6,0x58,0x51,0x6e, ++ 0x4c,0x5d,0x4a,0xe9,0xa9,0x72,0x6,0x9f,0xa2,0x3e,0x64,0xaf,0x70,0x63,0xee,0x2a, ++ 0x5d,0x73,0xf3,0xdc,0xa3,0x32,0x0f,0x8,0x48,0xcf,0x13,0x80,0x0d,0xdb,0x91,0xdf, ++ 0x87,0x99,0xa4,0x8a,0x50,0xe9,0x75,0x43,0xfb,0x56,0xd7,0x89,0xc3,0x10,0x7e,0xd0, ++ 0xb7,0x46,0xd8,0x41,0x91,0xdf,0xb1,0x91,0x8e,0xc1,0x58,0xd7,0x7c,0x33,0x1e,0xb3, ++ 0xa3,0xda,0xcb,0xf5,0x0,0x76,0xe4,0xee,0x20,0xd6,0x9d,0x8a,0x28,0xa4,0xdb,0xf9, ++}; ++ ++static unsigned char dh_except_b_pubkey_1536[] = { ++ 0x44, 0x58, 0xe8, 0x62, 0xc8, 0xd2, 0xb5, 0x45, 0x1f, 0xa5, 0xc3, 0xdb, 0x8e, 0x69, 0x42, 0xd2, ++ 0x21, 0x7e, 0x6b, 0x26, 0x69, 0x45, 0xf1, 0x33, 0xcf, 0xd7, 0xe6, 0x6e, 0x64, 0xc3, 0x29, 0xa5, ++ 0x68, 0x49, 0x3d, 0x13, 0x0b, 0x42, 0x36, 0xa6, 0xf4, 0xb1, 0xab, 0xa3, 0x8f, 0xe6, 0xcf, 0x46, ++ 0xe8, 0x85, 0xf3, 0xaa, 0xcb, 0x9, 0x84, 0x32, 0x34, 0xf7, 0x46, 0x0a, 0x65, 0xf9, 0xb5, 0x97, ++ 0xc2, 0x4a, 0x6f, 0x41, 0x40, 0xc9, 0x9e, 0x63, 0xe1, 0x0f, 0xd2, 0x12, 0x59, 0x35, 0xcc, 0x39, ++ 0x99, 0x4, 0xe8, 0x9a, 0xd2, 0x0, 0x7a, 0xce, 0x3c, 0x78, 0xfe, 0xea, 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c, 0x34, 0x23, 0x99, 0x74, 0xf8, 0x80, 0x1b, 0xc1, 0x97, 0x34, 0xdf, 0x23, ++ 0x15, 0xa2, 0x8b, 0xec, 0xf3, 0x3e, 0x20, 0x93, 0x63, 0x88, 0x17, 0x70, 0x75, 0xbb, 0x9d, 0xb8, ++ 0x32, 0xb0, 0xae, 0xb5, 0x24, 0x6a, 0x86, 0xf6, 0xc1, 0x60, 0x41, 0xc4, 0xf4, 0x95, 0x6e, 0x10, ++ 0x2f, 0xd8, 0x58, 0x56, 0x42, 0x82, 0x71, 0x85, 0x19, 0xde, 0x91, 0xf0, 0x2f, 0x30, 0x0c, 0x63, ++}; ++ ++static unsigned char dh_except_a_pubkey_3072[] = { ++ 0xa5, 0x24, 0x63, 0x20, 0xb2, 0x56, 0x9a, 0x94, 0x97, 0xf7, 0x88, 0x41, 0x35, 0xeb, 0x52, 0x37, ++ 0xa4, 0xf2, 0x74, 0x1b, 0x38, 0xe4, 0x4c, 0x8b, 0x4b, 0xd2, 0xa5, 0xad, 0xb8, 0x2f, 0x7b, 0x5a, ++ 0xfd, 0xbc, 0x9c, 0xe0, 0xea, 0x9e, 0x82, 0x3, 0x62, 0xe2, 0xdc, 0x6c, 0x56, 0x9, 0x2, 0x28, ++ 0xb8, 0x2d, 0xb8, 0x46, 0xaf, 0x3a, 0xf4, 0x51, 0xf7, 0x4d, 0xc4, 0xd9, 0xa9, 0x1d, 0x67, 0x9d, ++ 0x2b, 0x18, 0x56, 0x86, 0x2a, 0x3, 0x19, 0xe9, 0x6, 0xeb, 0x4a, 0x6f, 0x2a, 0x40, 0x28, 0xbb, ++ 0x3e, 0x87, 0xc1, 0xce, 0x39, 0x6e, 0x3b, 0x1f, 0xb0, 0x9, 0x33, 0x67, 0x19, 0x0e, 0x1a, 0xb2, ++ 0xb3, 0x7d, 0xd3, 0xe6, 0x33, 0xf4, 0x7c, 0x82, 0x73, 0x7b, 0xb6, 0x16, 0x55, 0xff, 0x76, 0xaf, ++ 0x7f, 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, 0x94, 0x8b, 0x53, 0x02, 0x21, 0x40, 0xd7, ++ 0x36, 0x76, 0xf3, 0xc8, 0xc0, 0x36, 0x3d, 0x23, 0xc9, 0xbd, 0x92, 0x51, 0xf2, 0x4b, 0x83, 0x15, ++ 0xe0, 0x80, 0x86, 0x24, 0xe2, 0x20, 0x35, 0x97, 0xda, 0x0e, 0x68, 0x39, 0x01, 0xdd, 0x01, 0x87, ++ 0xa2, 0x47, 0xd2, 0x0d, 0xee, 0xfe, 0xdc, 0x5a, 0x37, 0x23, 0xeb, 0x3d, 0xe8, 0x1e, 0x39, 0x2d, ++ 0xbf, 0xa6, 0xe9, 0x17, 0x48, 0xe2, 0xea, 0xef, 0x1d, 0x2f, 0xe2, 0xaf, 0x3c, 0xbc, 0xae, 0xa7, ++ 0x42, 0x9b, 0xa5, 0x7d, 0x47, 0x8a, 0x20, 0xc5, 0xae, 0xa1, 0xe4, 0xe8, 0x1c, 0x05, 0xc0, 0x0a, ++ 0x05, 0xdc, 0x01, 0x74, 0xde, 0xad, 0xad, 0x07, 0xec, 0x6e, 0x6a, 0xc7, 0xee, 0x0f, 0xb8, 0xbe, ++ 0xaa, 0x46, 0x61, 0x8c, 0x12, 0x5a, 0xaf, 0x05, 0xff, 0x1b, 0x35, 0x6b, 0xe2, 0x3d, 0x48, 0x4f ++}; ++ ++static unsigned char dh_except_a_pubkey_4096[] = { ++ 0xa5, 0x24, 0x63, 0x20, 0xb2, 0x56, 0x9a, 0x94, 0x97, 0xf7, 0x88, 0x41, 0x35, 0xeb, 0x52, 0x37, ++ 0xa4, 0xf2, 0x74, 0x1b, 0x38, 0xe4, 0x4c, 0x8b, 0x4b, 0xd2, 0xa5, 0xad, 0xb8, 0x2f, 0x7b, 0x5a, ++ 0xfd, 0xbc, 0x9c, 0xe0, 0xea, 0x9e, 0x82, 0x3, 0x62, 0xe2, 0xdc, 0x6c, 0x56, 0x9, 0x2, 0x28, ++ 0xb8, 0x2d, 0xb8, 0x46, 0xaf, 0x3a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, 0x47, 0xdb, 0x4d, ++ 0xba, 0xe7, 0x3, 0x5b, 0xe4, 0x70, 0x8b, 0xe0, 0xe1, 0x92, 0x13, 0x86, 0x74, 0x4, 0xdc, 0x6a, ++ 0x0a, 0x2a, 0x20, 0xec, 0x6d, 0xbf, 0xf0, 0x46, 0xf7, 0x9, 0x2, 0xdb, 0x2f, 0x70, 0x11, 0xdd, ++ 0xb0, 0x13, 0xa2, 0xc1, 0x58, 0x74, 0x29, 0x19, 0x8d, 0x4a, 0x94, 0x80, 0x0b, 0xd7, 0x25, 0x85, ++ 0x10, 0x35, 0x97, 0x48, 0x6e, 0x70, 0x28, 0xae, 0x58, 0x97, 0x7d, 0xf2, 0x19, 0x27, 0x13, 0xab, ++ 0x47, 0x9b, 0x54, 0xdf, 0xc3, 0x5b, 0x5f, 0x5e, 0xb4, 0x64, 0x47, 0xce, 0x40, 0x3b, 0x0c, 0x4a, ++ 0x62, 0x52, 0xba, 0xc7, 0xf0, 0x36, 0x87, 0x9c, 0x79, 0x9a, 0x83, 0x11, 0x61, 0x0c, 0x1b, 0x6b ++}; ++ ++static unsigned char dh_except_b_pubkey_4096[] = { ++ 0x44, 0x58, 0xe8, 0x62, 0xc8, 0xd2, 0xb5, 0x45, 0x1f, 0xa5, 0xc3, 0xdb, 0x8e, 0x69, 0x42, 0xd2, ++ 0x21, 0x7e, 0x6b, 0x26, 0x69, 0x45, 0xf1, 0x33, 0xcf, 0xd7, 0xe6, 0x6e, 0x64, 0xc3, 0x29, 0xa5, ++ 0x68, 0x49, 0x3d, 0x13, 0x0b, 0x42, 0x36, 0xa6, 0xf4, 0xb1, 0xab, 0xa3, 0x8f, 0xe6, 0xcf, 0x46, ++ 0xe8, 0x85, 0xf3, 0xaa, 0xcb, 0x9, 0x84, 0x32, 0x34, 0xf7, 0x46, 0x0a, 0x65, 0xf9, 0xb5, 0x97, ++ 0xc2, 0x4a, 0x6f, 0x41, 0x40, 0xc9, 0x9e, 0x63, 0xe1, 0x0f, 0xd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xe6, 0xb9, 0x9, 0xd1, 0x94, 0xce, 0xd1, 0x5b, 0xf4, 0x44, 0xa9, 0xcb, 0x26, 0x2, 0x36, ++ 0x57, 0x2c, 0xa2, 0xbe, 0x37, 0xde, 0x86, 0x46, 0x20, 0x27, 0x9d, 0xa0, 0x2f, 0x4, 0xc1, 0xcd, ++ 0xff, 0x81, 0xe5, 0xe6, 0x2c, 0x9e, 0x39, 0x82, 0x31, 0x54, 0x33, 0xf8, 0xe7, 0xa0, 0xe5, 0x96, ++ 0xa4, 0x40, 0xc4, 0x44, 0xfe, 0x93, 0x66, 0xe2, 0xda, 0xaa, 0xb8, 0xfb, 0x2f, 0x3b, 0x8c, 0xce, ++}; ++ ++/******************************************* ECDH ********************************************/ ++static char ecdh_a_secp128r1[] = { ++ 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc ++}; ++ ++static char ecdh_b_secp128r1[] = { ++ 0xe8, 0x75, 0x79, 0xc1, 0x10, 0x79, 0xf4, 0x3d, 0xd8, 0x24, 0x99, 0x3c, 0x2c, 0xee, 0x5e, 0xd3 ++}; ++ ++static char ecdh_p_secp128r1[] = { ++ 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ++}; ++ ++static char ecdh_n_secp128r1[] = { ++ 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x75, 0xa3, 0x0d, 0x1b, 0x90, 0x38, 0xa1, 0x15 ++}; ++ ++static char ecdh_g_secp128r1[] = { ++ 0x16, 0x1f, 0xf7, 0x52, 0x8b, 0x89, 0x9b, 0x2d, 0x0c, 0x28, 0x60, 0x7c, 0xa5, 0x2c, 0x5b, 0x86, ++ 0xcf, 0x5a, 0xc8, 0x39, 0x5b, 0xaf, 0xeb, 0x13, 0xc0, 0x2d, 0xa2, 0x92, 0xdd, 0xed, 0x7a, 0x83 ++}; ++ ++static char ecdh_da_secp128r1[] = { ++ 0xfe, 0x4e, 0xc2, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x78, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00 ++}; ++ ++static char ecdh_cp_pubkey_secp128r1[] = { ++ 0x04, ++ 0xcc, 0x40, 0x99, 0x3b, 0xcd, 0x0b, 0xcf, 0xcb, 0x9a, 0x96, 0x08, 0x56, 0xc2, 0x96, 0x2c, 0xe1, ++ 0xdf, 0x69, 0x2a, 0x71, 0xaf, 0x96, 0xe2, 0xeb, 0x5a, 0x26, 0x7f, 0xd3, 0x7a, 0xe8, 0x70, 0xf3 ++}; ++ ++static char ecdh_except_b_pubkey_secp128r1[] = { ++ 0x04, ++ 0xcc, 0x40, 0x99, 0x3b, 0xcd, 0x0b, 0xcf, 0xcb, 0x9a, 0x96, 0x08, 0x56, 0xc2, 0x96, 0x2c, 0xe1, ++ 0xdf, 0x69, 0x2a, 0x71, 0xaf, 0x96, 0xe2, 0xeb, 0x5a, 0x26, 0x7f, 0xd3, 0x7a, 0xe8, 0x70, 0xf3 ++}; ++ ++static char ecdh_cp_sharekey_secp128r1[] = { ++ 0x68, 0x55, 0x71, 0xa4, 0xd7, 0x51, 0x49, 0xa8, 0x78, 0xa8, 0x3a, 0xc1, 0x3f, 0xb3, 0x8c, 0xcb ++}; ++ ++/* ecc sign or verf*/ ++static char ecc_except_kinv_secp128r1[] = { ++ 0xfe, 0x4e, 0xc2, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x78, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00 ++}; ++ ++static char ecc_except_e_secp128r1[] = { ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x4 ++}; ++ ++static char ecc_cp_sign_secp128r1[] = { ++ 0x2e, 0x69, 0xad, 0x4f, 0xd5, 0xd4, 0x62, 0xec, 0xf2, 0xde, 0x21, 0x4f, 0xbc, 0x1f, 0xe8, 0x19, ++ 0x7b, 0x98, 0x8d, 0xaf, 0xe4, 0x6c, 0x60, 0x73, 0x00, 0xb0, 0x8b, 0xef, 0x89, 0x65, 0x35, 0x84 ++}; ++ ++static char ecdh_a_secp192k1[] = { ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ++}; ++ ++static char ecdh_b_secp192k1[] = { ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 ++}; ++ ++static char ecdh_p_secp192k1[] = { ++ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ++ 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xee, 0x37 ++}; ++ ++static char ecdh_n_secp192k1[] = { ++ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x26, 0xf2, 0xfc, 0x17, ++ 0x0f, 0x69, 0x46, 0x6a, 0x74, 0xde, 0xfd, 0x8d ++}; ++ ++static char ecdh_g_secp192k1[] = { ++ 0xdb, 0x4f, 0xf1, 0x0e, 0xc0, 0x57, 0xe9, 0xae, 0x26, 0xb0, 0x7d, 0x02, 0x80, 0xb7, 0xf4, 0x34, ++ 0x1d, 0xa5, 0xd1, 0xb1, 0xea, 0xe0, 0x6c, 0x7d, ++ 0x9b, 0x2f, 0x2f, 0x6d, 0x9c, 0x56, 0x28, 0xa7, 0x84, 0x41, 0x63, 0xd0, 0x15, 0xbe, 0x86, 0x34, ++ 0x40, 0x82, 0xaa, 0x88, 0xd9, 0x5e, 0x2f, 0x9d ++}; ++ ++static char ecdh_da_secp192k1[] = { ++ 0x2b, 0x58, 0xc2, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x58, 0xc2, 0x5e, 0x00, 0x00, 0x00, 0x00, ++ 0x67, 0x6a, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00 ++}; ++ ++static char ecdh_cp_pubkey_secp192k1[] = { ++ 0x04, ++ 0xec, 0x0e, 0x64, 0xac, 0x04, 0x2a, 0x88, 0x86, 0xed, 0xc1, 0xf2, 0x50, 0x0f, 0xe1, 0x27, 0x63, ++ 0x86, 0x63, 0x9e, 0xb2, 0x82, 0x21, 0x6e, 0x3f, 0x48, 0x59, 0x76, 0xb9, 0x4e, 0xd9, 0xe2, 0x02, ++ 0xb4, 0xdb, 0xfc, 0x8f, 0x49, 0xe7, 0x24, 0x9b, 0xbe, 0x33, 0xee, 0xc8, 0xcc, 0x9e, 0x00, 0x9a ++}; ++ ++static char ecdh_cp_sharekey_secp192k1[] = { ++ 0x79, 0xd3, 0x1c, 0x98, 0xfb, 0xd2, 0xb6, 0x7c, 0x60, 0x4b, 0x6e, 0x4c, 0xa9, 0x95, 0xcb, 0xac, ++ 0xb0, 0xf9, 0x05, 0xed, 0x9a, 0xcb, 0x2e, 0x5b ++}; ++ ++static char ecdh_except_b_pubkey_secp192k1[] = { ++ 0x04, ++ 0xec, 0x0e, 0x64, 0xac, 0x04, 0x2a, 0x88, 0x86, 0xed, 0xc1, 0xf2, 0x50, 0x0f, 0xe1, 0x27, 0x63, ++ 0x86, 0x63, 0x9e, 0xb2, 0x82, 0x21, 0x6e, 0x3f, 0x48, 0x59, 0x76, 0xb9, 0x4e, 0xd9, 0xe2, 0x02, ++ 0xb4, 0xdb, 0xfc, 0x8f, 0x49, 0xe7, 0x24, 0x9b, 0xbe, 0x33, 0xee, 0xc8, 0xcc, 0x9e, 0x00, 0x9a ++}; ++ ++/* ecc sign or verf*/ ++static unsigned char ecc_except_kinv_secp192k1[] = { ++ 0x71, 0x71, 0xb4, 0x5b, 0x79, 0x51, 0x94, 0x70, 0x53, 0xf9, 0x77, 0x02, 0x64, 0xef, 0xc4, 0xdb, ++ 0x64, 0xfc, 0xbe, 0x4e, 0x44, 0x4a, 0xc6, 0x54 ++}; ++ ++static unsigned char ecc_except_e_secp192k1[] = { ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04 ++}; ++ ++/* 224 */ ++static char ecdh_a_secp224r1[] = { ++ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, ++ 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE ++}; ++ ++static char ecdh_b_secp224r1[] = { ++ 0xB4, 0x05, 0x0A, 0x85, 0x0C, 0x04, 0xB3, 0xAB, 0xF5, 0x41, 0x32, 0x56, 0x50, 0x44, ++ 0xB0, 0xB7, 0xD7, 0xBF, 0xD8, 0xBA, 0x27, 0x0B, 0x39, 0x43, 0x23, 0x55, 0xFF, 0xB4 ++}; ++ ++static char ecdh_p_secp224r1[] = { ++ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, ++ 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ++}; ++ ++static char ecdh_n_secp224r1[] = { ++ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, ++ 0x16, 0xA2, 0xE0, 0xB8, 0xF0, 0x3E, 0x13, 0xDD, 0x29, 0x45, 0x5C, 0x5C, 0x2A, 0x3D ++}; ++ ++static char ecdh_g_secp224r1[] = { ++ 0xB7, 0x0E, 0x0C, 0xBD, 0x6B, 0xB4, 0xBF, 0x7F, 0x32, 0x13, 0x90, 0xB9, 0x4A, 0x03, ++ 0xC1, 0xD3, 0x56, 0xC2, 0x11, 0x22, 0x34, 0x32, 0x80, 0xD6, 0x11, 0x5C, 0x1D, 0x21, ++ 0xBD, 0x37, 0x63, 0x88, 0xB5, 0xF7, 0x23, 0xFB, 0x4C, 0x22, 0xDF, 0xE6, 0xCD, 0x43, ++ 0x75, 0xA0, 0x5A, 0x07, 0x47, 0x64, 0x44, 0xD5, 0x81, 0x99, 0x85, 0x00, 0x7E, 0x34 ++}; ++ ++static char ecdh_da_secp224r1[] = { ++ 0x41, 0x5c, 0x8c, 0x34, 0xfd, 0x70, 0x76, 0x3c, 0x6a, 0x81, 0x8e, 0x33, 0x7c, 0xa5, ++ 0x59, 0x6b, 0xfb, 0x58, 0x8e, 0x74, 0xb8, 0xc7, 0x3c, 0xcf, 0xde, 0xe3, 0x81, 0x60 ++}; ++ ++static char ecdh_cp_pubkey_secp224r1[] = { ++ 0x04, ++ 0x5b, 0x46, 0x50, 0x7c, 0x7a, 0x37, 0x82, 0x05, 0x5a, 0xc7, 0xd0, 0x29, 0xf8, 0xdd, ++ 0xe6, 0x3e, 0xb4, 0xc2, 0x31, 0x59, 0xfd, 0xa4, 0xb7, 0xee, 0x61, 0x83, 0x7c, 0x80, ++ 0xf1, 0x51, 0xf0, 0x5b, 0xfb, 0xc6, 0x63, 0x23, 0x9a, 0x13, 0xfa, 0x47, 0x68, 0x7b, ++ 0x3e, 0x47, 0xb3, 0x88, 0xca, 0x3e, 0x4b, 0x71, 0x24, 0x17, 0xc7, 0x4c, 0xd0, 0x06 ++}; ++ ++static char ecdh_except_b_pubkey_secp224r1[] = { ++ 0x04, ++ 0x5b, 0x46, 0x50, 0x7c, 0x7a, 0x37, 0x82, 0x05, 0x5a, 0xc7, 0xd0, 0x29, 0xf8, 0xdd, ++ 0xe6, 0x3e, 0xb4, 0xc2, 0x31, 0x59, 0xfd, 0xa4, 0xb7, 0xee, 0x61, 0x83, 0x7c, 0x80, ++ 0xf1, 0x51, 0xf0, 0x5b, 0xfb, 0xc6, 0x63, 0x23, 0x9a, 0x13, 0xfa, 0x47, 0x68, 0x7b, ++ 0x3e, 0x47, 0xb3, 0x88, 0xca, 0x3e, 0x4b, 0x71, 0x24, 0x17, 0xc7, 0x4c, 0xd0, 0x06 ++}; ++ ++static char ecdh_cp_sharekey_secp224r1[] = { ++ 0x2f, 0xc0, 0x04, 0x34, 0x0e, 0x03, 0xb0, 0xd2, 0x84, 0xe1, 0x4f, 0x4f, 0x7b, 0xac, ++ 0x53, 0xaa, 0x32, 0x5c, 0xbd, 0xe5, 0xbc, 0x2a, 0xe3, 0xda, 0x48, 0x38, 0x67, 0x16 ++}; ++ ++ ++/* 256 */ ++static char ecdh_a_secp256k1[] = { ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ++}; ++ ++static char ecdh_b_secp256k1[] = { ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07 ++}; ++ ++static char ecdh_p_secp256k1[] = { ++ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ++ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f ++}; ++ ++static char ecdh_n_secp256k1[] = { ++ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, ++ 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41 ++}; ++ ++static char ecdh_g_secp256k1[] = { ++ 0x79, 0xBE, 0x66, 0x7E, 0xF9, 0xDC, 0xBB, 0xAC, 0x55, 0xA0, 0x62, 0x95, 0xCE, 0x87, 0x0B, 0x07, ++ 0x02, 0x9B, 0xFC, 0xDB, 0x2D, 0xCE, 0x28, 0xD9, 0x59, 0xF2, 0x81, 0x5B, 0x16, 0xF8, 0x17, 0x98, ++ 0x48, 0x3a, 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, ++ 0xfd, 0x17, 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8 ++}; ++ ++static char ecdh_da_secp256k1[] = { ++ 0x71, 0x71, 0xb4, 0x5b, 0x79, 0x51, 0x94, 0x70, 0x53, 0xf9, 0x77, 0x02, 0x64, 0xef, 0xc4, 0xdb, ++ 0x64, 0xfc, 0xbe, 0x4e, 0x44, 0x4a, 0xc6, 0x54, 0x71, 0x69, 0x2e, 0x4a, 0x46, 0xa7, 0x2d, 0xa3 ++}; ++ ++#if 0 ++static char ecdh_db_secp256k1[] = { ++ 0xe2, 0x74, 0x69, 0xc8, 0x17, 0x6c, 0x0d, 0xca, 0xdd, 0x9e, 0xf6, 0x2f, 0x30, 0x9f, 0xad, 0xf3, ++ 0xdd, 0x16, 0xcc, 0x0c, 0xb1, 0xd0, 0x7b, 0xf4, 0xde, 0x9d, 0xf2, 0x5d, 0x22, 0x03, 0xce, 0x41 ++}; ++#endif ++ ++static char ecdh_cp_pubkey_secp256k1[] = { ++ 0x04, ++ 0x68, 0xae, 0x87, 0x7c, 0x45, 0xb3, 0x8b, 0xa8, 0xa8, 0x8e, 0x4b, 0xe5, 0x1f, 0x4e, 0xe6, 0x89, ++ 0x67, 0x73, 0x71, 0x96, 0x92, 0x2e, 0x57, 0x07, 0xc4, 0x30, 0xa5, 0xcf, 0x9f, 0x58, 0xb0, 0x6f, ++ 0x26, 0xd3, 0x58, 0xa4, 0xb6, 0xfc, 0xb6, 0x4b, 0x0f, 0x63, 0xd9, 0xa6, 0xa0, 0x1b, 0xba, 0x10, ++ 0x10, 0xa4, 0xab, 0x28, 0x6e, 0xab, 0x51, 0x34, 0xac, 0x3d, 0x2b, 0x39, 0xf1, 0xd7, 0x21, 0x48 ++}; ++ ++static char ecdh_except_b_pubkey_secp256k1[] = { ++ 0x04, ++ 0x90, 0x34, 0x99, 0xc8, 0x9e, 0x32, 0xdb, 0xcd, 0x24, 0x4e, 0x31, 0x51, 0x1c, 0x83, 0x4b, 0xf7, ++ 0x68, 0xf0, 0xbb, 0xa3, 0x91, 0x38, 0xa8, 0xf1, 0xab, 0x76, 0x36, 0xcd, 0x23, 0x3f, 0x57, 0x3b, ++ 0x22, 0x1a, 0x3f, 0x2e, 0x40, 0x8b, 0xe2, 0x7b, 0xd4, 0x91, 0xe4, 0xf2, 0x36, 0x00, 0xbe, 0xae, ++ 0x9c, 0xf2, 0xfc, 0xb4, 0xb9, 0x8b, 0x5b, 0xa7, 0x39, 0x88, 0xf2, 0x3b, 0xe2, 0xe5, 0xab, 0x1b ++}; ++ ++static char ecdh_cp_sharekey_secp256k1[] = { ++ 0xd8, 0x9d, 0x1e, 0x25, 0xa2, 0x5, 0xd8, 0xad, 0x0f, 0x1c, 0x7a, 0x44, 0xd4, 0xe6, 0x96, 0xc2, ++ 0xd3, 0xbc, 0x05, 0xa1, 0x8d, 0x4a, 0x2, 0x11, 0x0e, 0x93, 0xcd, 0xb9, 0x56, 0xd6, 0x44, 0x1c, ++}; ++ ++/* ecc sign or verf*/ ++static unsigned char ecc_except_kinv_secp256k1[] = { ++ 0x71, 0x71, 0xb4, 0x5b, 0x79, 0x51, 0x94, 0x70, 0x53, 0xf9, 0x77, 0x02, 0x64, 0xef, 0xc4, 0xdb, ++ 0x64, 0xfc, 0xbe, 0x4e, 0x44, 0x4a, 0xc6, 0x54, 0x71, 0x69, 0x2e, 0x4a, 0x46, 0xa7, 0x2d, 0xa3 ++}; ++ ++static unsigned char ecc_except_e_secp256k1[] = { ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04 ++}; ++ ++static unsigned char ecc_cp_sign_secp256k1[] = { ++ 0x30,0x45,0x02,0x20,0x68,0xae,0x87,0x7c,0x45,0xb3,0x8b,0xa8,0xa8,0x8e,0x4b,0xe5, ++ 0x1f,0x4e,0xe6,0x89,0x67,0x73,0x71,0x96,0x92,0x2e,0x57,0x07,0xc4,0x30,0xa5,0xcf, ++ 0x9f,0x58,0xb0,0x6f,0x02,0x21,0x00,0xdb,0x14,0xac,0x48,0x0d,0x0a,0xe9,0xe4,0x1d, ++ 0x8d,0xca,0x47,0xb6,0x0e,0x44,0xf6,0xfb,0xde,0x86,0x9b,0x38,0x76,0x98,0x67,0x12, ++ 0x7f,0x1d,0x09,0x97,0xab,0xc2,0xcb ++}; ++ ++static char ecdh_a_secp320k1[] = { ++ 0x3e, 0xe3, 0x0b, 0x56, 0x8f, 0xba, 0xb0, 0xf8, 0x83, 0xcc, 0xeb, 0xd4, 0x6d, 0x3f, 0x3b, 0xb8, ++ 0xa2, 0xa7, 0x35, 0x13, 0xf5, 0xeb, 0x79, 0xda, 0x66, 0x19, 0x0e, 0xb0, 0x85, 0xff, 0xa9, 0xf4, ++ 0x92, 0xf3, 0x75, 0xa9, 0x7d, 0x86, 0x0e, 0xb4 ++}; ++ ++static char ecdh_b_secp320k1[] = { ++ 0x52, 0x08, 0x83, 0x94, 0x9d, 0xfd, 0xbc, 0x42, 0xd3, 0xad, 0x19, 0x86, 0x40, 0x68, 0x8a, 0x6f, ++ 0xe1, 0x3f, 0x41, 0x34, 0x95, 0x54, 0xb4, 0x9a, 0xcc, 0x31, 0xdc, 0xcd, 0x88, 0x45, 0x39, 0x81, ++ 0x6f, 0x5e, 0xb4, 0xac, 0x8f, 0xb1, 0xf1, 0xa6 ++}; ++ ++static char ecdh_p_secp320k1[] = { ++ 0xd3, 0x5e, 0x47, 0x20, 0x36, 0xbc, 0x4f, 0xb7, 0xe1, 0x3c, 0x78, 0x5e, 0xd2, 0x01, 0xe0, 0x65, ++ 0xf9, 0x8f, 0xcf, 0xa6, 0xf6, 0xf4, 0x0d, 0xef, 0x4f, 0x92, 0xb9, 0xec, 0x78, 0x93, 0xec, 0x28, ++ 0xfc, 0xd4, 0x12, 0xb1, 0xf1, 0xb3, 0x2e, 0x27 ++}; ++ ++static char ecdh_n_secp320k1[] = { ++ 0xd3, 0x5e, 0x47, 0x20, 0x36, 0xbc, 0x4f, 0xb7, 0xe1, 0x3c, 0x78, 0x5e, 0xd2, 0x01, 0xe0, 0x65, ++ 0xf9, 0x8f, 0xcf, 0xa5, 0xb6, 0x8f, 0x12, 0xa3, 0x2d, 0x48, 0x2e, 0xc7, 0xee, 0x86, 0x58, 0xe9, ++ 0x86, 0x91, 0x55, 0x5b, 0x44, 0xc5, 0x93, 0x11 ++}; ++ ++static char ecdh_g_secp320k1[] = { ++ 0x43, 0xbd, 0x7e, 0x9a, 0xfb, 0x53, 0xd8, 0xb8, 0x52, 0x89, 0xbc, 0xc4, 0x8e, 0xe5, 0xbf, 0xe6, ++ 0xf2, 0x01, 0x37, 0xd1, 0x0a, 0x08, 0x7e, 0xb6, 0xe7, 0x87, 0x1e, 0x2a, 0x10, 0xa5, 0x99, 0xc7, ++ 0x10, 0xaf, 0x8d, 0x0d, 0x39, 0xe2, 0x06, 0x11, ++ 0x14, 0xfd, 0xd0, 0x55, 0x45, 0xec, 0x1c, 0xc8, 0xab, 0x40, 0x93, 0x24, 0x7f, 0x77, 0x27, 0x5e, ++ 0x07, 0x43, 0xff, 0xed, 0x11, 0x71, 0x82, 0xea, 0xa9, 0xc7, 0x78, 0x77, 0xaa, 0xac, 0x6a, 0xc7, ++ 0xd3, 0x52, 0x45, 0xd1, 0x69, 0x2e, 0x8e, 0xe1, ++}; ++ ++static char ecdh_da_secp320k1[] = { ++ 0x6a, 0x5b, 0xc2, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x21, 0x8e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x31, 0x00, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x6a, 0x5b, 0xc2, 0x5e, 0x00, 0x00, 0x00, 0x00, ++ 0x21, 0x8e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 ++}; ++ ++static char ecdh_cp_pubkey_secp320k1[] = { ++ 0x04, ++ 0x5f, 0x25, 0x77, 0xa9, 0xb5, 0x0a, 0x6f, 0xd3, 0xcb, 0x43, 0x93, 0xe0, 0xb7, 0x41, 0x3b, 0x56, ++ 0xc3, 0xfe, 0x1e, 0x5c, 0xb9, 0x32, 0x3a, 0x74, 0x68, 0xf8, 0x69, 0xea, 0xcf, 0x5b, 0x82, 0xd2, ++ 0x38, 0x8c, 0x96, 0x87, 0x97, 0xc3, 0x89, 0x9d, 0x13, 0x02, 0x40, 0xba, 0x88, 0xfa, 0x0c, 0x5a, ++ 0x64, 0x52, 0x7c, 0x36, 0xbd, 0xa6, 0x92, 0xb7, 0x6f, 0xb1, 0xd5, 0x81, 0xdb, 0xd5, 0x78, 0x96, ++ 0x50, 0x6a, 0x48, 0xec, 0x75, 0x04, 0x01, 0x3e, 0x86, 0x07, 0x74, 0x5b, 0xa7, 0x72, 0x44, 0x27 ++}; ++ ++static char ecdh_except_b_pubkey_secp320k1[] = { ++ 0x04, ++ 0x5f, 0x25, 0x77, 0xa9, 0xb5, 0x0a, 0x6f, 0xd3, 0xcb, 0x43, 0x93, 0xe0, 0xb7, 0x41, 0x3b, 0x56, ++ 0xc3, 0xfe, 0x1e, 0x5c, 0xb9, 0x32, 0x3a, 0x74, 0x68, 0xf8, 0x69, 0xea, 0xcf, 0x5b, 0x82, 0xd2, ++ 0x38, 0x8c, 0x96, 0x87, 0x97, 0xc3, 0x89, 0x9d, 0x13, 0x02, 0x40, 0xba, 0x88, 0xfa, 0x0c, 0x5a, ++ 0x64, 0x52, 0x7c, 0x36, 0xbd, 0xa6, 0x92, 0xb7, 0x6f, 0xb1, 0xd5, 0x81, 0xdb, 0xd5, 0x78, 0x96, ++ 0x50, 0x6a, 0x48, 0xec, 0x75, 0x04, 0x01, 0x3e, 0x86, 0x07, 0x74, 0x5b, 0xa7, 0x72, 0x44, 0x27 ++}; ++ ++static char ecdh_cp_sharekey_secp320k1[] = { ++ 0x69, 0x8a, 0x70, 0x4e, 0xf8, 0x4a, 0x9a, 0x80, 0xe8, 0x48, 0xc9, 0xb9, 0xac, 0x2a, 0x74, 0xf0, ++ 0xe5, 0x29, 0x60, 0x6d, 0xf3, 0x4e, 0x01, 0xa6, 0x20, 0x37, 0xc2, 0x0f, 0xba, 0x98, 0x91, 0x3b, ++ 0xc2, 0x75, 0xa3, 0xc6, 0x75, 0x90, 0x79, 0xb4 ++}; ++ ++/* ecc sign or verf*/ ++static unsigned char ecc_except_kinv_secp320k1[] = { ++ 0x71, 0x71, 0xb4, 0x5b, 0x79, 0x51, 0x94, 0x70, 0x53, 0xf9, 0x77, 0x02, 0x64, 0xef, 0xc4, 0xdb, ++ 0x64, 0xfc, 0xbe, 0x4e, 0x44, 0x4a, 0xc6, 0x54, 0x71, 0x69, 0x2e, 0x4a, 0x46, 0xa7, 0x2d, 0xa3 ++}; ++ ++static unsigned char ecc_except_e_secp320k1[] = { ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04 ++}; ++ ++/* 384 */ ++static char ecdh_a_secp384r1[] = { ++ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, ++ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, ++ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFC ++}; ++ ++static char ecdh_b_secp384r1[] = { ++ 0xB3, 0x31, 0x2F, 0xA7, 0xE2, 0x3E, 0xE7, 0xE4, 0x98, 0x8E, 0x05, 0x6B, ++ 0xE3, 0xF8, 0x2D, 0x19, 0x18, 0x1D, 0x9C, 0x6E, 0xFE, 0x81, 0x41, 0x12, ++ 0x03, 0x14, 0x08, 0x8F, 0x50, 0x13, 0x87, 0x5A, 0xC6, 0x56, 0x39, 0x8D, ++ 0x8A, 0x2E, 0xD1, 0x9D, 0x2A, 0x85, 0xC8, 0xED, 0xD3, 0xEC, 0x2A, 0xEF ++}; ++ ++static char ecdh_p_secp384r1[] = { ++ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, ++ 0x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 0x0A, 0x60, 0xB1, 0xCE, ++ 0x1D, 0x7E, 0x81, 0x9D, 0x7A, 0x43, 0x1D, 0x7C, 0x90, 0xEA, 0x0E, 0x5F ++}; ++ ++static char ecdh_da_secp384r1[] = { ++ 0xee, 0x57, 0xd7, 0xad, 0xbc, 0x8c, 0x5d, 0x82, 0x65, 0x7f, 0x03, 0xcb, 0x12, 0xc1, 0x38, 0x0d, ++ 0x02, 0x5c, 0xb7, 0x8f, 0xa4, 0x36, 0x56, 0x27, 0x25, 0x85, 0xaa, 0x3e, 0xdf, 0x22, 0x88, 0x7b, ++ 0xe3, 0xe7, 0xc5, 0xf1, 0xd7, 0x37, 0x8c, 0xc7, 0x56, 0xca, 0xa7, 0x93, 0x37, 0xbd, 0xf9, 0x37 ++}; ++ ++static char ecdh_cp_pubkey_secp384r1[] = { ++ 0x04, ++ 0x7d, 0x54, 0xd0, 0x72, 0x45, 0x4b, 0x5a, 0x48, 0xed, 0xc6, 0x19, 0xde, 0x8f, 0x1b, 0xa6, 0xfd, ++ 0xe5, 0x00, 0xbc, 0x74, 0xbb, 0xee, 0xdc, 0x6b, 0x1c, 0x6d, 0x36, 0xf1, 0x2a, 0x6a, 0x3c, 0xcd, ++ 0xd5, 0xb9, 0xf8, 0x3c, 0x57, 0xe8, 0xc2, 0xb2, 0xe6, 0x60, 0x58, 0x03, 0x3e, 0x48, 0xf4, 0xc4, ++ 0x4b, 0x80, 0x58, 0x8c, 0xc7, 0x65, 0x2e, 0xdd, 0x23, 0x31, 0xd2, 0xae, 0x62, 0x62, 0xc3, 0xb4, ++ 0x57, 0x88, 0xc6, 0x84, 0x51, 0xaf, 0x8c, 0x7b, 0x94, 0x2a, 0x43, 0x68, 0x31, 0xbd, 0x3d, 0x4f, ++ 0x43, 0xae, 0x79, 0x50, 0x80, 0x60, 0x09, 0xfa, 0x42, 0xfe, 0x9d, 0x18, 0xce, 0xbe, 0xfd, 0x64 ++}; ++ ++static char ecdh_except_b_pubkey_secp384r1[] = { ++ 0x04, ++ 0x7d, 0x54, 0xd0, 0x72, 0x45, 0x4b, 0x5a, 0x48, 0xed, 0xc6, 0x19, 0xde, 0x8f, 0x1b, 0xa6, 0xfd, ++ 0xe5, 0x00, 0xbc, 0x74, 0xbb, 0xee, 0xdc, 0x6b, 0x1c, 0x6d, 0x36, 0xf1, 0x2a, 0x6a, 0x3c, 0xcd, ++ 0xd5, 0xb9, 0xf8, 0x3c, 0x57, 0xe8, 0xc2, 0xb2, 0xe6, 0x60, 0x58, 0x03, 0x3e, 0x48, 0xf4, 0xc4, ++ 0x4b, 0x80, 0x58, 0x8c, 0xc7, 0x65, 0x2e, 0xdd, 0x23, 0x31, 0xd2, 0xae, 0x62, 0x62, 0xc3, 0xb4, ++ 0x57, 0x88, 0xc6, 0x84, 0x51, 0xaf, 0x8c, 0x7b, 0x94, 0x2a, 0x43, 0x68, 0x31, 0xbd, 0x3d, 0x4f, ++ 0x43, 0xae, 0x79, 0x50, 0x80, 0x60, 0x09, 0xfa, 0x42, 0xfe, 0x9d, 0x18, 0xce, 0xbe, 0xfd, 0x64 ++}; ++ ++static char ecdh_cp_sharekey_secp384r1[] = { ++ 0x82, 0x80, 0x4b, 0x00, 0x8c, 0x3c, 0x29, 0x51, 0xc8, 0x77, 0x1f, 0x72, 0xe2, 0x8c, 0x9d, 0x2a, ++ 0x3c, 0xf3, 0xe3, 0x7c, 0xc0, 0xc9, 0x80, 0x20, 0xe2, 0x1a, 0x45, 0xb6, 0x20, 0x13, 0x18, 0x91, ++ 0x61, 0xfa, 0xf1, 0x9d, 0x9f, 0xf2, 0x95, 0x78, 0xdd, 0xfe, 0x73, 0x9f, 0x09, 0x24, 0xa1, 0x4b ++}; ++ ++/* ecc sign or verf*/ ++static unsigned char ecc_except_kinv_secp384r1[] = { ++ /* ++ 0x71, 0x71, 0xb4, 0x5b, 0x79, 0x51, 0x94, 0x70, 0x53, 0xf9, 0x77, 0x02, 0x64, 0xef, 0xc4, 0xdb, ++ 0x64, 0xfc, 0xbe, 0x4e, 0x44, 0x4a, 0xc6, 0x54, 0x71, 0x69, 0x2e, 0x4a, 0x46, 0xa7, 0x2d, 0xa3*/ ++}; ++ ++static unsigned char ecc_except_e_secp384r1[] = { ++ /* ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04*/ ++}; ++ ++/* 521 */ ++static char ecdh_a_secp521r1[] = { ++ 0x01, 0xff, ++ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ++ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ++ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ++ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc ++}; ++ ++static char ecdh_b_secp521r1[] = { ++ 0x00, 0xe6, 0x15, 0x1c, 0x79, 0x17, 0x8d, 0x1b, 0x5c, 0xfa, ++ 0xbc, 0x7e, 0x53, 0x82, 0xb9, 0x33, 0xbc, 0x16, 0x2c, 0x9f, 0x27, 0xed, 0x6d, 0x79, 0x34, 0xf2, ++ 0xba, 0x07, 0x92, 0x9e, 0x96, 0xea, 0xe9, 0xdd, 0xb5, 0xae, 0x57, 0x7a, 0x54, 0xe1, 0x3c, 0x71, ++ 0xa9, 0x6e, 0x3e, 0x3d, 0x88, 0xaf, 0x92, 0x77, 0xe8, 0xe6, 0x61, 0xfe, 0xed, 0x39, 0xbd, 0x11, ++ 0x19, 0x25, 0x3f, 0x09, 0x4e, 0x71, 0x25, 0xcc ++}; ++ ++static char ecdh_p_secp521r1[] = { ++ 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ++ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ++ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ++ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ++ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ++}; ++ ++static char ecdh_n_secp521r1[] = { ++ 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ++ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ++ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfa, 0x51, 0x86, 0x87, 0x83, 0xbf, 0x2f, 0x96, 0x6b, ++ 0x7f, 0xcc, 0x01, 0x48, 0xf7, 0x09, 0xa5, 0xd0, 0x3b, 0xb5, 0xc9, 0xb8, 0x89, 0x9c, 0x47, 0xae, ++ 0xbb, 0x6f, 0xb7, 0x1e, 0x91, 0x38, 0x64, 0x09 ++}; ++ ++static char ecdh_g_secp521r1[] = { ++ 0x00, 0xc6, ++ 0x85, 0x8e, 0x06, 0xb7, 0x04, 0x04, 0xe9, 0xcd, 0x9e, 0x3e, 0xcb, 0x66, 0x23, 0x95, 0xb4, 0x42, ++ 0x9c, 0x64, 0x81, 0x39, 0x05, 0x3f, 0xb5, 0x21, 0xf8, 0x28, 0xaf, 0x60, 0x6b, 0x4d, 0x3d, 0xba, ++ 0xa1, 0x4b, 0x5e, 0x77, 0xef, 0xe7, 0x59, 0x28, 0xfe, 0x1d, 0xc1, 0x27, 0xa2, 0xff, 0xa8, 0xde, ++ 0x33, 0x48, 0xb3, 0xc1, 0x85, 0x6a, 0x42, 0x9b, 0xf9, 0x7e, 0x7e, 0x31, 0xc2, 0xe5, 0xbd, 0x66, ++ ++ 0x01, 0x18, 0x39, 0x29, 0x6a, 0x78, 0x9a, 0x3b, 0xc0, 0x04, ++ 0x5c, 0x8a, 0x5f, 0xb4, 0x2c, 0x7d, 0x1b, 0xd9, 0x98, 0xf5, 0x44, 0x49, 0x57, 0x9b, 0x44, 0x68, ++ 0x17, 0xaf, 0xbd, 0x17, 0x27, 0x3e, 0x66, 0x2c, 0x97, 0xee, 0x72, 0x99, 0x5e, 0xf4, 0x26, 0x40, ++ 0xc5, 0x50, 0xb9, 0x01, 0x3f, 0xad, 0x07, 0x61, 0x35, 0x3c, 0x70, 0x86, 0xa2, 0x72, 0xc2, 0x40, ++ 0x88, 0xbe, 0x94, 0x76, 0x9f, 0xd1, 0x66, 0x50 ++}; ++ ++static char ecdh_da_secp521r1[] = { ++ 0x00, 0xe6, 0x15, 0x1c, 0x79, 0x17, 0x8d, 0x1b, 0x5c, 0xfa, ++ 0xbc, 0x7e, 0x53, 0x82, 0xb9, 0x33, 0xbc, 0x16, 0x2c, 0x9f, 0x27, 0xed, 0x6d, 0x79, 0x34, 0xf2, ++ 0xba, 0x07, 0x92, 0x9e, 0x96, 0xea, 0xe9, 0xdd, 0xb5, 0xae, 0x57, 0x7a, 0x54, 0xe1, 0x3c, 0x71, ++ 0xa9, 0x6e, 0x3e, 0x3d, 0x88, 0xaf, 0x92, 0x77, 0xe8, 0xe6, 0x61, 0xfe, 0xed, 0x39, 0xbd, 0x11, ++ 0x19, 0x25, 0x3f, 0x09, 0x4e, 0x71, 0x25, 0xcc ++}; ++ ++static char ecdh_except_b_pubkey_secp521r1[] = { ++ 0x04, ++ 0x01, 0x16, 0x0a, 0x52, 0xaa, 0x18, 0x96, 0x56, 0xf6, 0x27, 0xd1, 0x59, 0xbd, 0x7d, 0x0f, 0x57, ++ 0xfd, 0x34, 0xfa, 0x52, 0x1b, 0x04, 0xbd, 0x9a, 0x90, 0xd5, 0x8d, 0xad, 0x41, 0x32, 0x80, 0x14, ++ 0x6e, 0x73, 0x58, 0x83, 0x98, 0xeb, 0xb0, 0x6b, 0xb5, 0x63, 0x8e, 0xa1, 0x06, 0x04, 0x86, 0x94, ++ 0x9e, 0x34, 0x53, 0xf4, 0x93, 0x37, 0x1c, 0xbc, 0xbb, 0x7b, 0x4c, 0x97, 0x87, 0x32, 0x92, 0xf2, ++ 0x36, 0xdd, 0x01, 0x30, 0xa1, 0xa7, 0x68, 0x5a, 0x3e, 0x40, 0xe9, 0xbf, 0x3d, 0x2a, 0x1b, 0xbf, ++ 0x09, 0xa0, 0x51, 0xe8, 0x1d, 0x23, 0x27, 0x9c, 0x70, 0xb2, 0x18, 0x42, 0x02, 0x09, 0x02, 0x66, ++ 0xc7, 0xdb, 0x1a, 0xec, 0xe5, 0x20, 0x68, 0x31, 0x31, 0x6e, 0x70, 0xbe, 0x09, 0x72, 0x79, 0x42, ++ 0xe2, 0x3b, 0x3b, 0xd3, 0x0a, 0xe4, 0x9c, 0x34, 0x4c, 0x61, 0x74, 0x7c, 0xed, 0xe1, 0x84, 0x89, ++ 0x4b, 0xf4, 0xd5, 0xc3 ++}; ++ ++static char ecdh_cp_pubkey_secp521r1[] = { ++ 0x04, ++ 0x01, 0x16, 0x0a, 0x52, 0xaa, 0x18, 0x96, 0x56, 0xf6, 0x27, 0xd1, 0x59, 0xbd, 0x7d, 0x0f, 0x57, ++ 0xfd, 0x34, 0xfa, 0x52, 0x1b, 0x04, 0xbd, 0x9a, 0x90, 0xd5, 0x8d, 0xad, 0x41, 0x32, 0x80, 0x14, ++ 0x6e, 0x73, 0x58, 0x83, 0x98, 0xeb, 0xb0, 0x6b, 0xb5, 0x63, 0x8e, 0xa1, 0x06, 0x04, 0x86, 0x94, ++ 0x9e, 0x34, 0x53, 0xf4, 0x93, 0x37, 0x1c, 0xbc, 0xbb, 0x7b, 0x4c, 0x97, 0x87, 0x32, 0x92, 0xf2, ++ 0x36, 0xdd, 0x01, 0x30, 0xa1, 0xa7, 0x68, 0x5a, 0x3e, 0x40, 0xe9, 0xbf, 0x3d, 0x2a, 0x1b, 0xbf, ++ 0x09, 0xa0, 0x51, 0xe8, 0x1d, 0x23, 0x27, 0x9c, 0x70, 0xb2, 0x18, 0x42, 0x02, 0x09, 0x02, 0x66, ++ 0xc7, 0xdb, 0x1a, 0xec, 0xe5, 0x20, 0x68, 0x31, 0x31, 0x6e, 0x70, 0xbe, 0x09, 0x72, 0x79, 0x42, ++ 0xe2, 0x3b, 0x3b, 0xd3, 0x0a, 0xe4, 0x9c, 0x34, 0x4c, 0x61, 0x74, 0x7c, 0xed, 0xe1, 0x84, 0x89, ++ 0x4b, 0xf4, 0xd5, 0xc3 ++}; ++ ++static char ecdh_cp_sharekey_secp521r1[] = { ++ 0x01, 0xaf, 0x53, 0x84, 0x60, 0x59, 0x79, 0x64, 0x09, 0x5f, 0x2b, 0x4e, 0x82, 0xc4, 0x79, 0x21, ++ 0x55, 0x9c, 0xb0, 0x2f, 0x7d, 0xd4, 0x2f, 0x5d, 0xca, 0xfc, 0x4f, 0x70, 0x28, 0x6e, 0x2b, 0x13, ++ 0x2e, 0x5f, 0xf0, 0x1f, 0x50, 0x87, 0xf5, 0x82, 0x2f, 0xa7, 0x31, 0x5b, 0xfd, 0x5c, 0x0e, 0xef, ++ 0xaf, 0x5c, 0x80, 0x53, 0x48, 0xed, 0xcf, 0x14, 0xdc, 0x91, 0xc5, 0xc9, 0x1b, 0xff, 0xa8, 0x16, ++ 0x42, 0xa8 ++}; ++ ++/* ecc sign or verf*/ ++static unsigned char ecc_except_kinv_secp521r1[] = { ++ 0x71, 0x71, 0xb4, 0x5b, 0x79, 0x51, 0x94, 0x70, 0x53, 0xf9, 0x77, 0x02, 0x64, 0xef, 0xc4, 0xdb, ++ 0x64, 0xfc, 0xbe, 0x4e, 0x44, 0x4a, 0xc6, 0x54, 0x71, 0x69, 0x2e, 0x4a, 0x46, 0xa7, 0x2d, 0xa3 ++}; ++ ++static unsigned char ecc_except_e_secp521r1[] = { ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04 ++}; ++ ++static unsigned char sm2_k[] = { ++ 0x7c, 0x47, 0x81, 0x10, 0x54, 0xc6, 0xf9, 0x96, 0x13, 0xa5, 0x78, 0xeb, 0x84, 0x53, 0x70, 0x6c, ++ 0xcb, 0x96, 0x38, 0x4f, 0xe7, 0xdf, 0x5c, 0x17, 0x16, 0x71, 0xe7, 0x60, 0xbf, 0xa8, 0xbe, 0x3a ++}; ++ ++static unsigned char sm2_id[] = { ++ 0x41, 0x4c, 0x49, 0x43, 0x45, 0x31, 0x32, 0x33, 0x40, 0x59, 0x41, 0x48, 0x4f, 0x4f, 0x2e, 0x43, ++ 0x4f, 0x4d ++}; ++ ++static unsigned char sm2_plaintext[] = { ++ 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74 ++}; ++ ++static unsigned char sm2_plaintext_l[513] = { ++ 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74 ++}; ++ ++static unsigned char sm2_sign_data[] = { ++ /* r */ ++ 0xe6, 0xcd, 0x2d, 0xf9, 0x4f, 0x57, 0x40, 0x9e, 0x6b, 0xec, 0x8c, 0x0e, 0xf0, 0x44, 0x5c, 0xa4, ++ 0xfa, 0xea, 0x24, 0xe3, 0xf2, 0x28, 0x0e, 0xad, 0xc1, 0xa4, 0x1c, 0xf6, 0x24, 0x88, 0xaf, 0xd2, ++ ++ /* s */ ++ 0x98, 0x0e, 0x4f, 0xda, 0xbd, 0xe9, 0x9e, 0xc1, 0x6d, 0x59, 0x87, 0xd0, 0x23, 0x19, 0x84, 0xd1, ++ 0x94, 0x07, 0x7b, 0xb5, 0x43, 0xa8, 0x93, 0x00, 0xd4, 0xbb, 0xc7, 0xf8, 0x83, 0xb3, 0xf0, 0xc3, ++}; ++ ++static unsigned char sm2_ciphertext[] = { ++ /* c1 x */ ++ 0xe6, 0xcd, 0x2d, 0xf9, 0x4f, 0x57, 0x40, 0x9e, 0x6b, 0xec, 0x8c, 0x0e, 0xf0, 0x44, 0x5c, 0xa4, ++ 0xfa, 0xe9, 0xb7, 0x7e, 0x7e, 0xb4, 0xad, 0x46, 0x5c, 0x83, 0xb8, 0x8c, 0xbd, 0x23, 0x3c, 0x5e, ++ /* c1 y */ ++ 0x80, 0x89, 0xf0, 0xea, 0x2c, 0x84, 0x63, 0x45, 0xd8, 0x99, 0x7b, 0x5c, 0x2c, 0x75, 0x7d, 0x8e, ++ 0x5c, 0x99, 0x6e, 0x46, 0x85, 0x9f, 0x19, 0xd3, 0x7e, 0xb0, 0x3b, 0x24, 0xde, 0xab, 0xae, 0x30, ++ /* c3 */ ++ 0xfb, 0xcf, 0x24, 0x19, 0xf8, 0x61, 0x1c, 0xba, 0xb1, 0xd0, 0x6f, 0x4f, 0x84, 0xda, 0x9a, 0xe6, ++ 0x2d, 0x42, 0x27, 0xa1, 0x2b, 0x27, 0x26, 0x32, 0xc2, 0x6d, 0xda, 0x35, 0x54, 0xf9, 0xfc, 0xf8, ++ /* c2 */ ++ 0xdf, 0xe8, 0x59, 0xe8, 0x35, 0xb3, 0x98, 0x18, 0xca, 0x56, 0xaa, 0x29, 0x7b, 0x01, ++}; ++ ++static unsigned char sm2_ciphertext_l[609] = { ++ 0xe6, 0xcd, 0x2d, 0xf9, 0x4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9e, 0xfd, 0x1f, 0x0b, ++ 0xcd, 0x86, 0xa7, 0xb9, 0xb1, 0x74, 0xd0, 0x51, 0x3d, 0x1e, 0x8d, 0xb3, 0x4f, 0x46, 0x9f, 0xfb, ++ 0x36, 0x43, 0x3d, 0xff, 0xaf, 0x19, 0x29, 0xb5, 0x41, 0x4c, 0x75, 0x4d, 0x75, 0x41, 0x5e, 0xe1, ++ 0x86, 0x5b, 0xbb, 0x94, 0x13, 0xd3, 0xa7, 0x23, 0xb4, 0xfb, 0x6f, 0x7f, 0x36, 0xfe, 0x9f, 0xec, ++ 0x80, 0x56, 0x5c, 0x79, 0x78, 0x9d, 0xed, 0xe0, 0x0a, 0x68, 0xd9, 0xc1, 0x19, 0x93, 0x94, 0x2c, ++ 0x3d, ++}; ++ ++static unsigned char sm2_pubkey[] = { ++ 0x04, ++ 0x09, 0xf9, 0xdf, 0x31, 0x1e, 0x54, 0x21, 0xa1, 0x50, 0xdd, 0x7d, 0x16, 0x1e, 0x4b, 0xc5, 0xc6, ++ 0x72, 0x17, 0x9f, 0xad, 0x18, 0x33, 0xfc, 0x07, 0x6b, 0xb0, 0x8f, 0xf3, 0x56, 0xf3, 0x50, 0x20, ++ 0xcc, 0xea, 0x49, 0x0c, 0xe2, 0x67, 0x75, 0xa5, 0x2d, 0xc6, 0xea, 0x71, 0x8c, 0xc1, 0xaa, 0x60, ++ 0x0a, 0xed, 0x05, 0xfb, 0xf3, 0x5e, 0x08, 0x4a, 0x66, 0x32, 0xf6, 0x07, 0x2d, 0xa9, 0xad, 0x13 ++}; ++ ++static unsigned char sm2_priv[] = { ++ 0x39, 0x45, 0x20, 0x8f, 0x7b, 0x21, 0x44, 0xb1, 0x3f, 0x36, 0xe3, 0x8a, 0xc6, 0xd3, 0x9f, 0x95, ++ 0x88, 0x93, 0x93, 0x69, 0x28, 0x60, 0xb5, 0x1a, 0x42, 0xfb, 0x81, 0xef, 0x4d, 0xf7, 0xc5, 0xb8 ++}; ++ ++static unsigned char sm2_digest[] = { ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74 ++}; ++#endif +diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c +new file mode 100644 +index 0000000..e722c36 +--- /dev/null ++++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c +@@ -0,0 +1,2433 @@ ++/* SPDX-License-Identifier: Apache-2.0 */ ++ ++#include ++#include "uadk_benchmark.h" ++ ++#include "hpre_uadk_benchmark.h" ++#include "hpre_protocol_data.h" ++#include "include/wd.h" ++#include "include/wd_rsa.h" ++#include "include/wd_dh.h" ++#include "include/wd_ecc.h" ++#include "include/wd_sched.h" ++ ++#define ECC_CURVE_ID 0x3 /* def set secp256k1 */ ++#define HPRE_TST_PRT printf ++#define ERR_OPTYPE 0xFF ++#define SM2_DG_SZ 1024 ++ ++struct hpre_rsa_key_in { ++ void *e; ++ void *p; ++ void *q; ++ u32 e_size; ++ u32 p_size; ++ u32 q_size; ++ void *data[]; ++}; ++ ++static __thread struct hpre_rsa_key_in *rsa_key_in = NULL; ++static const char rsa_m[8] = {0x54, 0x85, 0x9b, 0x34, 0x2c, 0x49, 0xea, 0x2a}; ++ ++struct rsa_async_tag { ++ handle_t sess; ++}; ++ ++//----------------------------------RSA param--------------------------------------// ++struct hpre_dh_param { ++ const void *x; ++ const void *p; ++ const void *g; ++ const void *except_pub_key; ++ const void *pub_key; ++ const void *share_key; ++ u32 x_size; ++ u32 p_size; ++ u32 g_size; ++ u32 pub_key_size; ++ u32 share_key_size; ++ u32 except_pub_key_size; ++ u32 key_bits; ++ u32 optype; ++}; ++ ++//----------------------------------DH param-------------------------------------// ++struct hpre_ecc_setup { ++ void *except_pub_key; // use in ecdh phase 2 ++ const void *pub_key; // use in ecdh phase 1 ++ const void *share_key; // use in ecdh phase 2 ++ const void *digest; //use in ecdsa sign ++ const void *k; // ecdsa sign in ++ const void *rp; // x coordinate of k*generator used in ecdsa ++ const void *sign; // ecdsa sign out or verf in ++ const void *priv_key; // use in ecdsa sign ++ void *msg; // sm2 plaintext,ciphertext or digest input ++ const void *userid; // sm2 user id ++ const void *ciphertext; // sm2 ciphertext ++ const void *plaintext; // sm2 plaintext ++ u32 key_size; ++ u32 share_key_size; ++ u32 except_pub_key_size; ++ u32 digest_size; ++ u32 k_size; ++ u32 rp_size; ++ u32 sign_size; ++ u32 priv_key_size; ++ u32 pub_key_size; ++ u32 msg_size; ++ u32 userid_size; ++ u32 ciphertext_size; ++ u32 plaintext_size; ++ u32 op_type; ++ u32 key_bits; ++ u32 nid; ++ u32 curve_id; // WD ecc curve_id ++}; ++ ++//----------------------------------ECC param-------------------------------------// ++ ++typedef struct uadk_thread_res { ++ u32 subtype; ++ u32 keybits; ++ u32 kmode; ++ u32 optype; ++ u32 td_id; ++} thread_data; ++ ++static struct wd_ctx_config g_ctx_cfg; ++static struct wd_sched *g_sched; ++static unsigned int g_thread_num; ++static unsigned int g_ctxnum; ++ ++static const char* const alg_operations[] = { ++ "GenKey", "ShareKey", "Encrypt", "Decrypt", "Sign", "Verify", ++}; ++ ++static void get_dh_param(u32 algtype, u32 *keysize) ++{ ++ switch(algtype) { ++ case DH_768: ++ *keysize = 768; ++ break; ++ case DH_1024: ++ *keysize = 1024; ++ break; ++ case DH_1536: ++ *keysize = 1536; ++ break; ++ case DH_2048: ++ *keysize = 2048; ++ break; ++ case DH_3072: ++ *keysize = 3072; ++ break; ++ case DH_4096: ++ *keysize = 4096; ++ break; ++ } ++} ++ ++static u32 get_dh_optype(u32 optype) ++{ ++ u32 op_type = 0; ++ ++ switch(optype) { ++ case 0: //GENKEY1 ++ op_type = WD_DH_PHASE1; ++ break; ++ case 1: //GENKEY12 ++ op_type = WD_DH_PHASE2; ++ break; ++ default: ++ HPRE_TST_PRT("failed to set dh op_type\n"); ++ HPRE_TST_PRT("DH Gen1: 0\n"); ++ HPRE_TST_PRT("DH Gen2: 1\n"); ++ return ERR_OPTYPE; ++ } ++ ++ return op_type; ++} ++ ++static void get_rsa_param(u32 algtype, u32 *keysize, u32 *mode) ++{ ++ switch(algtype) { ++ case RSA_1024: ++ *keysize = 1024; ++ *mode = 0; ++ break; ++ case RSA_2048: ++ *keysize = 2048; ++ *mode = 0; ++ break; ++ case RSA_3072: ++ *keysize = 3072; ++ *mode = 0; ++ break; ++ case RSA_4096: ++ *keysize = 4096; ++ *mode = 0; ++ break; ++ case RSA_1024_CRT: ++ *keysize = 1024; ++ *mode = 1; ++ break; ++ case RSA_2048_CRT: ++ *keysize = 2048; ++ *mode = 1; ++ break; ++ case RSA_3072_CRT: ++ *keysize = 3072; ++ *mode = 1; ++ break; ++ case RSA_4096_CRT: ++ *keysize = 4096; ++ *mode = 1; ++ break; ++ } ++} ++ ++static u32 get_rsa_optype(u32 optype) ++{ ++ u32 op_type = 0; ++ ++ switch(optype) { ++ case 0: //GENKEY1 ++ op_type = WD_RSA_GENKEY; ++ break; ++ case 4: //Sign ++ op_type = WD_RSA_SIGN; ++ break; ++ case 5: //Verf ++ op_type = WD_RSA_VERIFY; ++ break; ++ default: ++ HPRE_TST_PRT("failed to set rsa op_type\n"); ++ HPRE_TST_PRT("RSA Gen: 0\n"); ++ HPRE_TST_PRT("RSA Sign: 4\n"); ++ HPRE_TST_PRT("RSA Verf: 5\n"); ++ return ERR_OPTYPE; ++ } ++ ++ return op_type; ++} ++ ++static void get_ecc_param(u32 algtype, u32 *keysize) ++{ ++ switch(algtype) { ++ case ECDH_256: ++ *keysize = 256; ++ break; ++ case ECDH_384: ++ *keysize = 384; ++ break; ++ case ECDH_521: ++ *keysize = 521; ++ break; ++ case ECDSA_256: ++ *keysize = 256; ++ break; ++ case ECDSA_384: ++ *keysize = 384; ++ break; ++ case ECDSA_521: ++ *keysize = 521; ++ break; ++ case SM2_ALG: ++ *keysize = 256; ++ break; ++ case X25519_ALG: ++ *keysize = 256; ++ break; ++ case X448_ALG: ++ *keysize = 448; ++ break; ++ } ++} ++ ++static u32 get_ecc_optype(u32 subtype, u32 optype) ++{ ++ u32 op_type = 0; ++ ++ if (subtype == SM2_TYPE) { ++ switch (optype) { ++ case 0: ++ op_type = WD_SM2_KG; ++ break; ++ case 2: ++ op_type = WD_SM2_ENCRYPT; ++ break; ++ case 3: ++ op_type = WD_SM2_DECRYPT; ++ break; ++ case 4: ++ op_type = WD_SM2_SIGN; ++ break; ++ case 5: ++ op_type = WD_SM2_VERIFY; ++ break; ++ default: ++ HPRE_TST_PRT("failed to set SM2 op_type\n"); ++ HPRE_TST_PRT("SM2 KeyGen: 0\n"); ++ HPRE_TST_PRT("SM2 Encrypt: 2\n"); ++ HPRE_TST_PRT("SM2 Decrypt: 3\n"); ++ HPRE_TST_PRT("SM2 Sign: 4\n"); ++ HPRE_TST_PRT("SM2 Verify: 5\n"); ++ return ERR_OPTYPE; ++ } ++ } else if (subtype == ECDH_TYPE || ++ subtype == X25519_TYPE || subtype == X448_TYPE) { ++ switch(optype) { ++ case 0: //GENKEY ++ op_type = WD_ECXDH_GEN_KEY; ++ break; ++ case 1: //COMPUTEKEY ++ op_type = WD_ECXDH_COMPUTE_KEY; ++ break; ++ default: ++ HPRE_TST_PRT("failed to set ECDH op_type\n"); ++ HPRE_TST_PRT("ECDH GenKey: 0\n"); ++ HPRE_TST_PRT("ECDH ShareKey: 1\n"); ++ return ERR_OPTYPE; ++ } ++ } else if (subtype == ECDSA_TYPE) { ++ switch(optype) { ++ case 4: //Sign ++ op_type = WD_ECDSA_SIGN; ++ break; ++ case 5: //Verf ++ op_type = WD_ECDSA_VERIFY; ++ break; ++ default: ++ HPRE_TST_PRT("failed to set ECDSA op_type\n"); ++ HPRE_TST_PRT("ECDSA Sign: 4\n"); ++ HPRE_TST_PRT("ECDSA Verf: 5\n"); ++ return ERR_OPTYPE; ++ } ++ } ++ ++ return op_type; ++} ++ ++static int hpre_uadk_param_parse(thread_data *tddata, struct acc_option *options) ++{ ++ u32 algtype = options->algtype; ++ u32 optype = 0; ++ u32 keysize = 0; ++ u32 mode = 0; ++ ++ if (algtype >= RSA_1024 && algtype <= RSA_4096_CRT) { ++ get_rsa_param(algtype, &keysize, &mode); ++ optype = get_rsa_optype(options->optype); ++ } else if (algtype <= DH_4096) { ++ get_dh_param(algtype, &keysize); ++ optype = get_dh_optype(options->optype); ++ } else if (algtype <= X448_ALG) { ++ get_ecc_param(algtype, &keysize); ++ optype = get_ecc_optype(options->subtype, options->optype); ++ } else { ++ HPRE_TST_PRT("failed to set hpre alg!\n"); ++ return -EINVAL; ++ } ++ ++ if (optype == ERR_OPTYPE) ++ return -EINVAL; ++ ++ /* HPRE package length is keybits */ ++ options->pktlen = keysize >> 3; ++ tddata->keybits = keysize; ++ tddata->kmode = mode; ++ tddata->optype = optype; ++ ++ HPRE_TST_PRT("%s to run %s task!\n", options->algclass, ++ alg_operations[options->optype]); ++ ++ return 0; ++} ++ ++static int init_hpre_ctx_config(char *alg, int subtype, int mode) ++{ ++ struct uacce_dev_list *list; ++ struct sched_params param; ++ int i, max_node; ++ int ret = 0; ++ ++ max_node = numa_max_node() + 1; ++ if (max_node <= 0) ++ return -EINVAL; ++ ++ list = wd_get_accel_list(alg); ++ if (!list) { ++ HPRE_TST_PRT("failed to get %s device\n", alg); ++ return -ENODEV; ++ } ++ memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config)); ++ g_ctx_cfg.ctx_num = g_ctxnum; ++ g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx)); ++ if (!g_ctx_cfg.ctxs) ++ return -ENOMEM; ++ ++ for (i = 0; i < g_ctxnum; i++) { ++ g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(list->dev); ++ g_ctx_cfg.ctxs[i].op_type = 0; // default op_type ++ g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode; ++ } ++ ++ switch(subtype) { ++ case RSA_TYPE: ++ g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, max_node, wd_rsa_poll_ctx); ++ break; ++ case DH_TYPE: ++ g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, max_node, wd_dh_poll_ctx); ++ break; ++ case ECDH_TYPE: ++ case ECDSA_TYPE: ++ case SM2_TYPE: ++ case X25519_TYPE: ++ case X448_TYPE: ++ g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, max_node, wd_ecc_poll_ctx); ++ break; ++ default: ++ HPRE_TST_PRT("failed to parse alg subtype!\n"); ++ g_sched = NULL; ++ } ++ if (!g_sched) { ++ HPRE_TST_PRT("failed to alloc sched!\n"); ++ goto out; ++ } ++ ++ /* If there is no numa, we defualt config to zero */ ++ if (list->dev->numa_id < 0) ++ list->dev->numa_id = 0; ++ ++ g_sched->name = SCHED_SINGLE; ++ param.numa_id = list->dev->numa_id; ++ param.type = 0; ++ param.mode = mode; ++ param.begin = 0; ++ param.end = g_ctxnum - 1; ++ ret = wd_sched_rr_instance(g_sched, ¶m); ++ if (ret) { ++ HPRE_TST_PRT("failed to fill hpre sched data!\n"); ++ goto out; ++ } ++ ++ /* init */ ++ switch(subtype) { ++ case RSA_TYPE: ++ ret = wd_rsa_init(&g_ctx_cfg, g_sched); ++ break; ++ case DH_TYPE: ++ ret = wd_dh_init(&g_ctx_cfg, g_sched); ++ break; ++ case ECDH_TYPE: ++ case ECDSA_TYPE: ++ case SM2_TYPE: ++ case X25519_TYPE: ++ case X448_TYPE: ++ ret = wd_ecc_init(&g_ctx_cfg, g_sched); ++ break; ++ default: ++ ret = -EINVAL; ++ } ++ if (ret) { ++ HPRE_TST_PRT("failed to get hpre ctx!\n"); ++ goto out; ++ } ++ ++ wd_free_list_accels(list); ++ ++ return 0; ++out: ++ free(g_ctx_cfg.ctxs); ++ wd_sched_rr_release(g_sched); ++ ++ return ret; ++} ++ ++static void uninit_hpre_ctx_config(int subtype) ++{ ++ int i; ++ ++ /* uninit */ ++ switch(subtype) { ++ case RSA_TYPE: ++ wd_rsa_uninit(); ++ break; ++ case DH_TYPE: ++ wd_dh_uninit(); ++ break; ++ case ECDH_TYPE: ++ case ECDSA_TYPE: ++ case SM2_TYPE: ++ case X25519_TYPE: ++ case X448_TYPE: ++ wd_ecc_uninit(); ++ break; ++ default: ++ HPRE_TST_PRT("failed to parse alg subtype on uninit!\n"); ++ return; ++ } ++ ++ for (i = 0; i < g_ctx_cfg.ctx_num; i++) ++ wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); ++ free(g_ctx_cfg.ctxs); ++ wd_sched_rr_release(g_sched); ++} ++ ++/*-------------------------------uadk benchmark main code-------------------------------------*/ ++ ++void *hpre_uadk_poll(void *data) ++{ ++ typedef int (*poll_ctx)(__u32 idx, __u32 expt, __u32 *count); ++ poll_ctx uadk_poll_ctx = NULL; ++ thread_data *pdata = (thread_data *)data; ++ u32 expt = ACC_QUEUE_SIZE * g_thread_num; ++ u32 id = pdata->td_id; ++ u32 last_time = 2; // poll need one more recv time ++ u32 count = 0; ++ u32 recv = 0; ++ int ret; ++ ++ if (id > g_ctxnum) ++ return NULL; ++ ++ switch(pdata->subtype) { ++ case RSA_TYPE: ++ uadk_poll_ctx = wd_rsa_poll_ctx; ++ break; ++ case DH_TYPE: ++ uadk_poll_ctx = wd_dh_poll_ctx; ++ break; ++ case ECDH_TYPE: ++ case ECDSA_TYPE: ++ case SM2_TYPE: ++ case X25519_TYPE: ++ case X448_TYPE: ++ uadk_poll_ctx = wd_ecc_poll_ctx; ++ break; ++ default: ++ HPRE_TST_PRT("<<<<<keybits >> 3); ++ ++ return NULL; ++} ++ ++static int get_rsa_key_from_sample(handle_t sess, char *privkey_file, ++ char *crt_privkey_file, u32 key_bits, u32 is_crt) ++{ ++ struct wd_dtb wd_e, wd_d, wd_n, wd_dq, wd_dp, wd_qinv, wd_q, wd_p; ++ int e_bytes, d_bytes, n_bytes, q_bytes, p_bytes, qinv_bytes; ++ u8 *p, *q, *n, *e, *d, *dmp1, *dmq1, *iqmp; ++ int dq_bytes, dp_bytes, bits, wd_lenth; ++ u32 key_size = key_bits >> 3; ++ char *wd_mem; ++ int ret = 0; ++ ++ memset(&wd_e, 0, sizeof(wd_e)); ++ memset(&wd_d, 0, sizeof(wd_d)); ++ memset(&wd_n, 0, sizeof(wd_n)); ++ memset(&wd_dq, 0, sizeof(wd_dq)); ++ memset(&wd_dp, 0, sizeof(wd_dp)); ++ memset(&wd_qinv, 0, sizeof(wd_qinv)); ++ memset(&wd_q, 0, sizeof(wd_q)); ++ memset(&wd_p, 0, sizeof(wd_p)); ++ ++ bits = wd_rsa_get_key_bits(sess); ++ switch (bits) { ++ case 1024: ++ e = rsa_e_1024; ++ n = rsa_n_1024; ++ p = rsa_p_1024; ++ q = rsa_q_1024; ++ dmp1 = rsa_dp_1024; ++ dmq1 = rsa_dq_1024; ++ iqmp = rsa_qinv_1024; ++ d = rsa_d_1024; ++ e_bytes = ARRAY_SIZE(rsa_e_1024); ++ n_bytes = ARRAY_SIZE(rsa_n_1024); ++ q_bytes = ARRAY_SIZE(rsa_q_1024); ++ p_bytes = ARRAY_SIZE(rsa_p_1024); ++ dq_bytes = ARRAY_SIZE(rsa_dq_1024); ++ dp_bytes = ARRAY_SIZE(rsa_dp_1024); ++ qinv_bytes = ARRAY_SIZE(rsa_qinv_1024); ++ d_bytes = ARRAY_SIZE(rsa_d_1024); ++ break; ++ case 2048: ++ e = rsa_e_2048; ++ n = rsa_n_2048; ++ p = rsa_p_2048; ++ q = rsa_q_2048; ++ dmp1 = rsa_dp_2048; ++ dmq1 = rsa_dq_2048; ++ iqmp = rsa_qinv_2048; ++ d = rsa_d_2048; ++ e_bytes = ARRAY_SIZE(rsa_e_2048); ++ n_bytes = ARRAY_SIZE(rsa_n_2048); ++ q_bytes = ARRAY_SIZE(rsa_q_2048); ++ p_bytes = ARRAY_SIZE(rsa_p_2048); ++ dq_bytes = ARRAY_SIZE(rsa_dq_2048); ++ dp_bytes = ARRAY_SIZE(rsa_dp_2048); ++ qinv_bytes = ARRAY_SIZE(rsa_qinv_2048); ++ d_bytes = ARRAY_SIZE(rsa_d_2048); ++ break; ++ case 3072: ++ e = rsa_e_3072; ++ n = rsa_n_3072; ++ p = rsa_p_3072; ++ q = rsa_q_3072; ++ dmp1 = rsa_dp_3072; ++ dmq1 = rsa_dq_3072; ++ iqmp = rsa_qinv_3072; ++ d = rsa_d_3072; ++ e_bytes = ARRAY_SIZE(rsa_e_3072); ++ n_bytes = ARRAY_SIZE(rsa_n_3072); ++ q_bytes = ARRAY_SIZE(rsa_q_3072); ++ p_bytes = ARRAY_SIZE(rsa_p_3072); ++ dq_bytes = ARRAY_SIZE(rsa_dq_3072); ++ dp_bytes = ARRAY_SIZE(rsa_dp_3072); ++ qinv_bytes = ARRAY_SIZE(rsa_qinv_3072); ++ d_bytes = ARRAY_SIZE(rsa_d_3072); ++ break; ++ case 4096: ++ e = rsa_e_4096; ++ n = rsa_n_4096; ++ p = rsa_p_4096; ++ q = rsa_q_4096; ++ dmp1 = rsa_dp_4096; ++ dmq1 = rsa_dq_4096; ++ iqmp = rsa_qinv_4096; ++ d = rsa_d_4096; ++ e_bytes = ARRAY_SIZE(rsa_e_4096); ++ n_bytes = ARRAY_SIZE(rsa_n_4096); ++ q_bytes = ARRAY_SIZE(rsa_q_4096); ++ p_bytes = ARRAY_SIZE(rsa_p_4096); ++ dq_bytes = ARRAY_SIZE(rsa_dq_4096); ++ dp_bytes = ARRAY_SIZE(rsa_dp_4096); ++ qinv_bytes = ARRAY_SIZE(rsa_qinv_4096); ++ d_bytes = ARRAY_SIZE(rsa_d_4096); ++ break; ++ default: ++ HPRE_TST_PRT("invalid key bits = %d!\n", bits); ++ return -EINVAL; ++ } ++ ++ wd_lenth = e_bytes + n_bytes + q_bytes + p_bytes + dq_bytes + ++ dp_bytes + qinv_bytes + d_bytes; ++ wd_mem = malloc(wd_lenth); ++ if (!wd_mem) { ++ HPRE_TST_PRT("failed to alloc rsa key memory!\n"); ++ return -EINVAL; ++ } ++ ++ wd_e.data = wd_mem; ++ wd_n.data = wd_e.data + e_bytes; ++ ++ memcpy(wd_e.data, e, e_bytes); ++ wd_e.dsize = e_bytes; ++ memcpy(wd_n.data, n, n_bytes); ++ wd_n.dsize = n_bytes; ++ if (wd_rsa_set_pubkey_params(sess, &wd_e, &wd_n)) { ++ HPRE_TST_PRT("failed to set rsa pubkey!\n"); ++ ret = -EINVAL; ++ goto gen_fail; ++ } ++ ++ if (rsa_key_in) { ++ memcpy(rsa_key_in->e, e, e_bytes); ++ memcpy(rsa_key_in->p, p, p_bytes); ++ memcpy(rsa_key_in->q, q, q_bytes); ++ rsa_key_in->e_size = e_bytes; ++ rsa_key_in->p_size = p_bytes; ++ rsa_key_in->q_size = q_bytes; ++ } ++ ++ if (is_crt) { ++ wd_q.data = wd_n.data + n_bytes; ++ wd_p.data = wd_q.data + q_bytes; ++ wd_dq.data = wd_p.data + p_bytes; ++ wd_dp.data = wd_dq.data + dq_bytes; ++ wd_qinv.data = wd_dp.data + dp_bytes; ++ ++ /* CRT mode private key */ ++ wd_dq.dsize = dq_bytes; ++ memcpy(wd_dq.data, dmq1, dq_bytes); ++ ++ wd_dp.dsize = dp_bytes; ++ memcpy(wd_dp.data, dmp1, dp_bytes); ++ ++ wd_q.dsize = q_bytes; ++ memcpy(wd_q.data, q, q_bytes); ++ ++ wd_p.dsize = p_bytes; ++ memcpy(wd_p.data, p, p_bytes); ++ ++ wd_qinv.dsize = qinv_bytes; ++ memcpy(wd_qinv.data, iqmp, qinv_bytes); ++ ++ if (wd_rsa_set_crt_prikey_params(sess, &wd_dq, ++ &wd_dp, &wd_qinv, ++ &wd_q, &wd_p)) { ++ HPRE_TST_PRT("failed to set rsa crt prikey!\n"); ++ ret = -EINVAL; ++ goto gen_fail; ++ } ++ ++ if (crt_privkey_file) { ++ memcpy(crt_privkey_file, wd_dq.data, (key_bits >> 4) * 5); ++ memcpy(crt_privkey_file + (key_bits >> 4) * 5, ++ wd_e.data, (key_bits >> 2)); ++ } ++ ++ } else { ++ //wd_rsa_get_prikey_params(prikey, &wd_d, &wd_n); ++ wd_d.data = wd_mem + (wd_lenth - d_bytes); ++ ++ /* common mode private key */ ++ wd_d.dsize = d_bytes; ++ memcpy(wd_d.data, d, d_bytes); ++ ++ if (wd_rsa_set_prikey_params(sess, &wd_d, &wd_n)) { ++ HPRE_TST_PRT("failed to set rsa prikey!\n"); ++ ret = -EINVAL; ++ goto gen_fail; ++ } ++ ++ ++ if (privkey_file) { ++ memcpy(privkey_file, wd_d.data, key_size); ++ memcpy(privkey_file + key_size, wd_n.data, key_size); ++ memcpy(privkey_file + 2 * key_size, wd_e.data, key_size); ++ memcpy(privkey_file + 3 * key_size, wd_n.data, key_size); ++ } ++ } ++ ++gen_fail: ++ free(wd_mem); ++ ++ return ret; ++} ++ ++static int get_hpre_keygen_opdata(handle_t sess, struct wd_rsa_req *req) ++{ ++ struct wd_rsa_pubkey *pubkey; ++ struct wd_rsa_prikey *prikey; ++ struct wd_dtb t_e, t_p, t_q; ++ struct wd_dtb *e, *p, *q; ++ ++ wd_rsa_get_pubkey(sess, &pubkey); ++ wd_rsa_get_pubkey_params(pubkey, &e, NULL); ++ wd_rsa_get_prikey(sess, &prikey); ++ ++ if (wd_rsa_is_crt(sess)) { ++ wd_rsa_get_crt_prikey_params(prikey, NULL , NULL, NULL, &q, &p); ++ } else { ++ e = &t_e; ++ p = &t_p; ++ q = &t_q; ++ e->data = rsa_key_in->e; ++ e->dsize = rsa_key_in->e_size; ++ p->data = rsa_key_in->p; ++ p->dsize = rsa_key_in->p_size; ++ q->data = rsa_key_in->q; ++ q->dsize = rsa_key_in->q_size; ++ } ++ ++ req->src = wd_rsa_new_kg_in(sess, e, p, q); ++ if (!req->src) { ++ HPRE_TST_PRT("failed to create rsa kgen in!\n"); ++ return -ENOMEM; ++ } ++ req->dst = wd_rsa_new_kg_out(sess); ++ if (!req->dst) { ++ HPRE_TST_PRT("failed to create rsa kgen out!\n"); ++ wd_rsa_del_kg_in(sess, req->src); ++ return -ENOMEM; ++ } ++ ++ return 0; ++} ++ ++static int get_ecc_curve(struct hpre_ecc_setup *setup, u32 cid) ++{ ++ switch (cid) { ++ case 0: // secp128R1 ++ setup->nid = 706; ++ setup->curve_id = WD_SECP128R1; ++ break; ++ case 1: // secp192K1 ++ setup->nid = 711; ++ setup->curve_id = WD_SECP192K1; ++ break; ++ case 2: // secp224R1 ++ setup->nid = 712; ++ setup->curve_id = WD_SECP224R1; ++ break; ++ case 3: // secp256K1 ++ setup->nid = 714; ++ setup->curve_id = WD_SECP256K1; ++ break; ++ case 4: // brainpoolP320R1 ++ setup->nid = 929; ++ setup->curve_id = WD_BRAINPOOLP320R1; ++ break; ++ case 5: // secp384R1 ++ setup->nid = 715; ++ setup->curve_id = WD_SECP384R1; ++ break; ++ case 6: // secp521R1 ++ setup->nid = 716; ++ setup->curve_id = WD_SECP521R1; ++ break; ++ default: ++ HPRE_TST_PRT("failed to get ecc curve id!\n"); ++ return -EINVAL; ++ } ++ ++ return 0; ++} ++ ++static int get_ecc_key_param(struct wd_ecc_curve *param, u32 key_bits) ++{ ++ u32 key_size = (key_bits + 7) / 8; ++ ++ switch (key_bits) { ++ case 128: ++ param->a.data = ecdh_a_secp128r1; ++ param->b.data = ecdh_b_secp128r1; ++ param->p.data = ecdh_p_secp128r1; ++ param->n.data = ecdh_n_secp128r1; ++ param->g.x.data = ecdh_g_secp128r1; ++ param->g.y.data = ecdh_g_secp128r1 + key_size; ++ case 192: ++ param->a.data = ecdh_a_secp192k1; ++ param->b.data = ecdh_b_secp192k1; ++ param->p.data = ecdh_p_secp192k1; ++ param->n.data = ecdh_n_secp192k1; ++ param->g.x.data = ecdh_g_secp192k1; ++ param->g.y.data = ecdh_g_secp192k1 + key_size; ++ case 224: ++ param->a.data = ecdh_a_secp224r1; ++ param->b.data = ecdh_b_secp224r1; ++ param->p.data = ecdh_p_secp224r1; ++ param->n.data = ecdh_n_secp224r1; ++ param->g.x.data = ecdh_g_secp224r1; ++ param->g.y.data = ecdh_g_secp224r1 + key_size; ++ case 256: ++ param->a.data = ecdh_a_secp256k1; ++ param->b.data = ecdh_b_secp256k1; ++ param->p.data = ecdh_p_secp256k1; ++ param->n.data = ecdh_n_secp256k1; ++ param->g.x.data = ecdh_g_secp256k1; ++ param->g.y.data = ecdh_g_secp256k1 + key_size; ++ case 320: ++ param->a.data = ecdh_a_secp320k1; ++ param->b.data = ecdh_b_secp320k1; ++ param->p.data = ecdh_p_secp320k1; ++ param->n.data = ecdh_n_secp320k1; ++ param->g.x.data = ecdh_g_secp320k1; ++ param->g.y.data = ecdh_g_secp320k1 + key_size; ++ case 384: ++ param->a.data = ecdh_a_secp384r1; ++ param->b.data = ecdh_b_secp384r1; ++ param->p.data = ecdh_p_secp384r1; ++ param->n.data = ecdh_n_secp384r1; ++ param->g.x.data = ecdh_g_secp384r1; ++ param->g.y.data = ecdh_g_secp384r1 + key_size; ++ case 521: ++ param->a.data = ecdh_a_secp521r1; ++ param->b.data = ecdh_b_secp521r1; ++ param->p.data = ecdh_p_secp521r1; ++ param->n.data = ecdh_n_secp521r1; ++ param->g.x.data = ecdh_g_secp521r1; ++ param->g.y.data = ecdh_g_secp521r1 + key_size; ++ default: ++ HPRE_TST_PRT("key_bits %d not find\n", key_bits); ++ return -EINVAL; ++ } ++ ++ param->a.bsize = key_size; ++ param->a.dsize = key_size; ++ param->b.bsize = key_size; ++ param->b.dsize = key_size; ++ param->p.bsize = key_size; ++ param->p.dsize = key_size; ++ param->n.bsize = key_size; ++ param->n.dsize = key_size; ++ param->g.x.bsize = key_size; ++ param->g.x.dsize = key_size; ++ param->g.y.bsize = key_size; ++ param->g.y.dsize = key_size; ++ ++ return 0; ++} ++ ++static int ecc_get_rand(char *out, size_t out_len, void *usr) ++{ ++ //int ret; ++ ++ get_rand_data((u8 *)out, out_len); ++ //ret = RAND_priv_bytes((void *)out, out_len); ++ //if (ret != 1) { ++ // HPRE_TST_PRT("failed to get ecc rand data:%d\n", ret); ++ // return -EINVAL; ++ //} ++ ++ return 0; ++} ++ ++static int get_ecc_param_from_sample(struct hpre_ecc_setup *setup, ++ u32 subtype, u32 key_bits) ++{ ++ int key_size = (key_bits + 7) / 8; ++ u32 len; ++ ++ setup->key_bits = key_bits; ++ ++ if (setup->nid == 714 || key_bits == 256) { // NID_secp256k1 ++ /* sm2 */ ++ if (subtype == SM2_TYPE) { ++ setup->priv_key = sm2_priv; ++ setup->priv_key_size = sizeof(sm2_priv); ++ setup->pub_key = sm2_pubkey; ++ setup->pub_key_size = sizeof(sm2_pubkey); ++ ++ len = SM2_DG_SZ; ++ setup->msg = malloc(len); ++ if (!setup->msg) ++ return -1; ++ memset(setup->msg, 0xFF, len); ++ ++ if (true) { // for msg_sigest mode ++ memcpy(setup->msg, sm2_digest, sizeof(sm2_digest)); ++ setup->msg_size = sizeof(sm2_digest); ++ } else { ++ memcpy(setup->msg, sm2_plaintext, sizeof(sm2_plaintext)); ++ setup->msg_size = sizeof(sm2_plaintext); ++ } ++ ++ if (setup->msg_size > 512) { ++ setup->ciphertext = sm2_ciphertext_l; ++ setup->ciphertext_size = sizeof(sm2_ciphertext_l); ++ setup->plaintext = sm2_plaintext_l; ++ setup->plaintext_size = sizeof(sm2_plaintext_l); ++ } else { ++ setup->ciphertext = sm2_ciphertext; ++ setup->ciphertext_size = sizeof(sm2_ciphertext); ++ setup->plaintext = sm2_plaintext; ++ setup->plaintext_size = sizeof(sm2_plaintext); ++ } ++ ++ setup->k = sm2_k; ++ setup->k_size = sizeof(sm2_k); ++ setup->userid = sm2_id; ++ setup->userid_size = sizeof(sm2_id); ++ setup->sign = sm2_sign_data; ++ setup->sign_size = sizeof(sm2_sign_data); ++ ++ } else { ++ setup->priv_key = ecdh_da_secp256k1; ++ setup->except_pub_key = ecdh_except_b_pubkey_secp256k1; ++ setup->pub_key = ecdh_cp_pubkey_secp256k1; ++ setup->share_key = ecdh_cp_sharekey_secp256k1; ++ setup->priv_key_size = sizeof(ecdh_da_secp256k1); ++ setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp256k1); ++ setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp256k1); ++ setup->share_key_size = sizeof(ecdh_cp_sharekey_secp256k1); ++ ++ /* ecc sign */ ++ setup->msg = ecc_except_e_secp256k1; ++ setup->msg_size = sizeof(ecc_except_e_secp256k1); ++ setup->k = ecc_except_kinv_secp256k1; ++ setup->k_size = sizeof(ecc_except_kinv_secp256k1); ++ setup->rp = ecdh_cp_pubkey_secp256k1 + 1; ++ setup->rp_size = key_size; ++ ++ /* ecc verf */ ++ setup->sign = ecc_cp_sign_secp256k1; ++ setup->sign_size = sizeof(ecc_cp_sign_secp256k1); ++ } ++ } else if (setup->nid == 706 || key_bits == 128) { ++ setup->priv_key = ecdh_da_secp128r1; ++ setup->except_pub_key = ecdh_except_b_pubkey_secp128r1; ++ setup->pub_key = ecdh_cp_pubkey_secp128r1; ++ setup->share_key = ecdh_cp_sharekey_secp128r1; ++ setup->priv_key_size = sizeof(ecdh_da_secp128r1); ++ setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp128r1); ++ setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp128r1); ++ setup->share_key_size = sizeof(ecdh_cp_sharekey_secp128r1); ++ ++ /* ecc sign */ ++ setup->msg = ecc_except_e_secp128r1; ++ setup->msg_size = sizeof(ecc_except_e_secp128r1); ++ setup->k = ecc_except_kinv_secp128r1; ++ setup->k_size = sizeof(ecc_except_kinv_secp128r1); ++ setup->rp = ecdh_cp_pubkey_secp128r1 + 1; ++ setup->rp_size = key_size; ++ ++ /* ecc verf */ ++ setup->sign = ecc_cp_sign_secp128r1; ++ setup->sign_size = sizeof(ecc_cp_sign_secp128r1); ++ ++ } else if (setup->nid == 711 || key_bits == 192) { ++ setup->priv_key = ecdh_da_secp192k1; ++ setup->except_pub_key = ecdh_except_b_pubkey_secp192k1; ++ setup->pub_key = ecdh_cp_pubkey_secp192k1; ++ setup->share_key = ecdh_cp_sharekey_secp192k1; ++ setup->priv_key_size = sizeof(ecdh_da_secp192k1); ++ setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp192k1); ++ setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp192k1); ++ setup->share_key_size = sizeof(ecdh_cp_sharekey_secp192k1); ++ ++ /* ecc sign */ ++ setup->msg = ecc_except_e_secp192k1; ++ setup->msg_size = sizeof(ecc_except_e_secp192k1); ++ setup->k = ecc_except_kinv_secp192k1; ++ setup->k_size = sizeof(ecc_except_kinv_secp192k1); ++ setup->rp = ecdh_cp_pubkey_secp192k1 + 1; ++ setup->rp_size = key_size; ++ ++ /* ecc verf */ ++ setup->sign = ecc_cp_sign_secp256k1; ++ setup->sign_size = sizeof(ecc_cp_sign_secp256k1); ++ } else if (setup->nid == 712 || key_bits == 224) { ++ setup->priv_key = ecdh_da_secp224r1; ++ setup->except_pub_key = ecdh_except_b_pubkey_secp224r1; ++ setup->pub_key = ecdh_cp_pubkey_secp224r1; ++ setup->share_key = ecdh_cp_sharekey_secp224r1; ++ setup->priv_key_size = sizeof(ecdh_da_secp224r1); ++ setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp224r1); ++ setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp224r1); ++ setup->share_key_size = sizeof(ecdh_cp_sharekey_secp224r1); ++ } else if (setup->nid == 929 || key_bits == 320) { ++ setup->priv_key = ecdh_da_secp320k1; ++ setup->except_pub_key = ecdh_except_b_pubkey_secp320k1; ++ setup->pub_key = ecdh_cp_pubkey_secp320k1; ++ setup->share_key = ecdh_cp_sharekey_secp320k1; ++ setup->priv_key_size = sizeof(ecdh_da_secp320k1); ++ setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp320k1); ++ setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp320k1); ++ setup->share_key_size = sizeof(ecdh_cp_sharekey_secp320k1); ++ ++ /* ecc sign */ ++ setup->msg = ecc_except_e_secp320k1; ++ setup->msg_size = sizeof(ecc_except_e_secp320k1); ++ setup->k = ecc_except_kinv_secp320k1; ++ setup->k_size = sizeof(ecc_except_kinv_secp320k1); ++ setup->rp = ecdh_cp_pubkey_secp192k1 + 1; ++ setup->rp_size = key_size; ++ ++ /* ecc verf */ ++ setup->sign = ecc_cp_sign_secp256k1; ++ setup->sign_size = sizeof(ecc_cp_sign_secp256k1); ++ ++ } else if (setup->nid == 931 || key_bits == 384) { ++ setup->priv_key = ecdh_da_secp384r1; ++ setup->except_pub_key = ecdh_except_b_pubkey_secp384r1; ++ setup->pub_key = ecdh_cp_pubkey_secp384r1; ++ setup->share_key = ecdh_cp_sharekey_secp384r1; ++ setup->priv_key_size = sizeof(ecdh_da_secp384r1); ++ setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp384r1); ++ setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp384r1); ++ setup->share_key_size = sizeof(ecdh_cp_sharekey_secp384r1); ++ ++ /* ecc sign */ ++ setup->msg = ecc_except_e_secp384r1; ++ setup->msg_size = sizeof(ecc_except_e_secp384r1); ++ setup->k = ecc_except_kinv_secp384r1; ++ setup->k_size = sizeof(ecc_except_kinv_secp384r1); ++ setup->rp = ecdh_cp_pubkey_secp384r1 + 1; ++ setup->rp_size = key_size; ++ ++ /* ecc verf */ ++ setup->sign = ecc_cp_sign_secp256k1; ++ setup->sign_size = sizeof(ecc_cp_sign_secp256k1); ++ } else if (setup->nid == 716 || key_bits == 521) { ++ setup->priv_key = ecdh_da_secp521r1; ++ setup->except_pub_key = ecdh_except_b_pubkey_secp521r1; ++ setup->pub_key = ecdh_cp_pubkey_secp521r1; ++ setup->share_key = ecdh_cp_sharekey_secp521r1; ++ setup->priv_key_size = sizeof(ecdh_da_secp521r1); ++ setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp521r1); ++ setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp521r1); ++ setup->share_key_size = sizeof(ecdh_cp_sharekey_secp521r1); ++ ++ /* ecc sign */ ++ setup->msg = ecc_except_e_secp521r1; ++ setup->msg_size = sizeof(ecc_except_e_secp521r1); ++ setup->k = ecc_except_kinv_secp521r1; ++ setup->k_size = sizeof(ecc_except_kinv_secp521r1); ++ setup->rp = ecdh_cp_pubkey_secp521r1 + 1; ++ setup->rp_size = key_size; ++ ++ /* ecc verf */ ++ setup->sign = ecc_cp_sign_secp256k1; ++ setup->sign_size = sizeof(ecc_cp_sign_secp256k1); ++ ++ } else { ++ HPRE_TST_PRT("init test sess setup not find this bits %d or nid %d\n", ++ key_bits, setup->nid); ++ return -EINVAL; ++ } ++ ++ return 0; ++} ++ ++static void *rsa_uadk_sync_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ int key_size = pdata->keybits >> 3; ++ struct wd_rsa_sess_setup setup; ++ struct wd_rsa_req req; ++ void *key_info = NULL; ++ handle_t h_sess; ++ u32 count = 0; ++ int ret; ++ ++ memset(&setup, 0, sizeof(setup)); ++ memset(&req, 0, sizeof(req)); ++ setup.key_bits = pdata->keybits; ++ setup.is_crt = pdata->kmode; ++ ++ h_sess = wd_rsa_alloc_sess(&setup); ++ if (!h_sess) ++ return NULL; ++ ++ key_info = malloc(key_size * 16); ++ if (!key_info) { ++ HPRE_TST_PRT("failed to alloc RSA key info!\n"); ++ return NULL; ++ } ++ memset(key_info, 0, key_size * 16); ++ ++ rsa_key_in = malloc(2 * key_size + sizeof(struct hpre_rsa_key_in)); ++ if (!rsa_key_in) { ++ HPRE_TST_PRT("failed to alloc RSA key input param!\n"); ++ goto key_release; ++ } ++ rsa_key_in->e = rsa_key_in + 1; ++ rsa_key_in->p = rsa_key_in->e + key_size; ++ rsa_key_in->q = rsa_key_in->p + (key_size >> 1); ++ ++ ret = get_rsa_key_from_sample(h_sess, key_info, key_info, ++ pdata->keybits, pdata->kmode); ++ if (ret) { ++ HPRE_TST_PRT("failed to get sample key data!\n"); ++ goto sample_release; ++ } ++ ++ req.src_bytes = key_size; ++ req.dst_bytes = key_size; ++ req.op_type = pdata->optype; ++ if (req.op_type == WD_RSA_GENKEY) { ++ ret = get_hpre_keygen_opdata(h_sess, &req); ++ if (ret){ ++ HPRE_TST_PRT("failed to fill rsa key gen req!\n"); ++ goto sample_release; ++ } ++ } else { ++ req.src = malloc(key_size); ++ if (!req.src) { ++ HPRE_TST_PRT("failed to alloc rsa in buffer!\n"); ++ goto sample_release; ++ } ++ memset(req.src, 0, req.src_bytes); ++ memcpy(req.src + key_size - sizeof(rsa_m), rsa_m, sizeof(rsa_m)); ++ req.dst = malloc(key_size); ++ if (!req.dst) { ++ HPRE_TST_PRT("failed to alloc rsa out buffer!\n"); ++ goto src_release; ++ } ++ } ++ ++ do { ++ ret = wd_do_rsa_sync(h_sess, &req); ++ if (ret || req.status) { ++ HPRE_TST_PRT("failed to do rsa task, status: %d\n", req.status); ++ goto dst_release; ++ } ++ ++ count++; ++ if (get_run_state() == 0) ++ break; ++ } while(true); ++ ++ /* clean output buffer remainings in the last time operation */ ++ if (req.op_type == WD_RSA_GENKEY) { ++ char *data; ++ int len; ++ ++ len = wd_rsa_kg_out_data((void *)req.dst, &data); ++ if (len < 0) { ++ HPRE_TST_PRT("failed to wd rsa get key gen out data!\n"); ++ goto sample_release; ++ } ++ memset(data, 0, len); ++ ++ wd_rsa_del_kg_in(h_sess, req.src); ++ req.src = NULL; ++ wd_rsa_del_kg_out(h_sess, req.dst); ++ req.dst = NULL; ++ } ++ ++dst_release: ++ if (req.dst) ++ free(req.dst); ++src_release: ++ if (req.src) ++ free(req.src); ++sample_release: ++ free(rsa_key_in); ++key_release: ++ free(key_info); ++ ++ wd_rsa_free_sess(h_sess); ++ add_recv_data(count, key_size); ++ ++ return NULL; ++} ++ ++static void rsa_async_cb(void *req_t) ++{ ++ //struct wd_rsa_req *req = req_t; ++ //struct rsa_async_tag *tag = req->cb_param; ++ //enum wd_rsa_op_type op_type = req->op_type; ++ //handle_t h_sess = tag->sess; ++ ++ return; ++} ++ ++static void *rsa_uadk_async_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ int key_size = pdata->keybits >> 3; ++ struct rsa_async_tag *tag; ++ struct wd_rsa_sess_setup setup; ++ struct wd_rsa_req req; ++ void *key_info = NULL; ++ int try_cnt = 0; ++ handle_t h_sess; ++ u32 count = 0; ++ int i, ret; ++ ++ memset(&setup, 0, sizeof(setup)); ++ memset(&req, 0, sizeof(req)); ++ setup.key_bits = pdata->keybits; ++ setup.is_crt = pdata->kmode; ++ ++ h_sess = wd_rsa_alloc_sess(&setup); ++ if (!h_sess) ++ return NULL; ++ ++ key_info = malloc(key_size * 16); ++ if (!key_info) { ++ HPRE_TST_PRT("failed to alloc RSA key info!\n"); ++ return NULL; ++ } ++ memset(key_info, 0, key_size * 16); ++ ++ rsa_key_in = malloc(2 * key_size + sizeof(struct hpre_rsa_key_in)); ++ if (!rsa_key_in) { ++ HPRE_TST_PRT("failed to alloc RSA key input param!\n"); ++ goto key_release; ++ } ++ rsa_key_in->e = rsa_key_in + 1; ++ rsa_key_in->p = rsa_key_in->e + key_size; ++ rsa_key_in->q = rsa_key_in->p + (key_size >> 1); ++ ++ ret = get_rsa_key_from_sample(h_sess, key_info, key_info, ++ pdata->keybits, pdata->kmode); ++ if (ret) { ++ HPRE_TST_PRT("failed to get sample key data!\n"); ++ goto sample_release; ++ } ++ ++ req.src_bytes = key_size; ++ req.dst_bytes = key_size; ++ req.op_type = pdata->optype; ++ if (req.op_type == WD_RSA_GENKEY) { ++ ret = get_hpre_keygen_opdata(h_sess, &req); ++ if (ret){ ++ HPRE_TST_PRT("failed to fill rsa key gen req!\n"); ++ goto sample_release; ++ } ++ } else { ++ req.src = malloc(key_size); ++ if (!req.src) { ++ HPRE_TST_PRT("failed to alloc rsa in buffer!\n"); ++ goto sample_release; ++ } ++ memset(req.src, 0, req.src_bytes); ++ memcpy(req.src + key_size - sizeof(rsa_m), rsa_m, sizeof(rsa_m)); ++ req.dst = malloc(key_size); ++ if (!req.dst) { ++ HPRE_TST_PRT("failed to alloc rsa out buffer!\n"); ++ goto src_release; ++ } ++ } ++ ++ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); ++ if (!tag) { ++ HPRE_TST_PRT("failed to malloc rsa tag!\n"); ++ goto dst_release; ++ } ++ req.cb = rsa_async_cb; ++ ++ do { ++ if (get_run_state() == 0) ++ break; ++ ++ try_cnt = 0; ++ i = count % MAX_POOL_LENTH; ++ tag[i].sess = h_sess; ++ req.cb_param = &tag[i]; ++ ++ ret = wd_do_rsa_async(h_sess, &req); ++ if (ret == -WD_EBUSY) { ++ usleep(SEND_USLEEP * try_cnt); ++ try_cnt++; ++ if (try_cnt > MAX_TRY_CNT) { ++ HPRE_TST_PRT("Test RSA send fail %d times!\n", MAX_TRY_CNT); ++ try_cnt = 0; ++ } ++ continue; ++ } else if (ret) { ++ HPRE_TST_PRT("failed to do rsa async task!\n"); ++ goto tag_release; ++ } ++ count++; ++ } while(true); ++ ++ /* clean output buffer remainings in the last time operation */ ++ if (req.op_type == WD_RSA_GENKEY) { ++ char *data; ++ int len; ++ ++ len = wd_rsa_kg_out_data((void *)req.dst, &data); ++ if (len < 0) { ++ HPRE_TST_PRT("failed to wd rsa get key gen out data!\n"); ++ goto tag_release; ++ } ++ memset(data, 0, len); ++ ++ wd_rsa_del_kg_in(h_sess, req.src); ++ req.src = NULL; ++ wd_rsa_del_kg_out(h_sess, req.dst); ++ req.dst = NULL; ++ } ++ ++tag_release: ++ free(tag); ++dst_release: ++ if (req.dst) ++ free(req.dst); ++src_release: ++ if (req.src) ++ free(req.src); ++sample_release: ++ free(rsa_key_in); ++key_release: ++ free(key_info); ++ ++ wd_rsa_free_sess(h_sess); ++ add_send_complete(); ++ ++ return NULL; ++} ++ ++static int get_dh_param_from_sample(struct hpre_dh_param *setup, ++ u32 key_bits, u8 is_g2) ++{ ++ setup->key_bits = key_bits; ++ ++ switch (key_bits) { ++ case 768: ++ setup->x = dh_xa_768; ++ setup->p = dh_p_768; ++ setup->except_pub_key = dh_except_b_pubkey_768; ++ setup->pub_key = dh_except_a_pubkey_768; ++ setup->share_key = dh_share_key_768; ++ setup->x_size = sizeof(dh_xa_768); ++ setup->p_size = sizeof(dh_p_768); ++ setup->except_pub_key_size = sizeof(dh_except_b_pubkey_768); ++ setup->pub_key_size = sizeof(dh_except_a_pubkey_768); ++ setup->share_key_size = sizeof(dh_share_key_768); ++ break; ++ case 1024: ++ setup->x = dh_xa_1024; ++ setup->p = dh_p_1024; ++ setup->except_pub_key = dh_except_b_pubkey_1024; ++ setup->pub_key = dh_except_a_pubkey_1024; ++ setup->share_key = dh_share_key_1024; ++ setup->x_size = sizeof(dh_xa_1024); ++ setup->p_size = sizeof(dh_p_1024); ++ setup->except_pub_key_size = sizeof(dh_except_b_pubkey_1024); ++ setup->pub_key_size = sizeof(dh_except_a_pubkey_1024); ++ setup->share_key_size = sizeof(dh_share_key_1024); ++ break; ++ case 1536: ++ setup->x = dh_xa_1536; ++ setup->p = dh_p_1536; ++ setup->except_pub_key = dh_except_b_pubkey_1536; ++ setup->pub_key = dh_except_a_pubkey_1536; ++ setup->share_key = dh_share_key_1536; ++ setup->x_size = sizeof(dh_xa_1536); ++ setup->p_size = sizeof(dh_p_1536); ++ setup->except_pub_key_size = sizeof(dh_except_b_pubkey_1536); ++ setup->pub_key_size = sizeof(dh_except_a_pubkey_1536); ++ setup->share_key_size = sizeof(dh_share_key_1536); ++ break; ++ case 2048: ++ setup->x = dh_xa_2048; ++ setup->p = dh_p_2048; ++ setup->except_pub_key = dh_except_b_pubkey_2048; ++ setup->pub_key = dh_except_a_pubkey_2048; ++ setup->share_key = dh_share_key_2048; ++ setup->x_size = sizeof(dh_xa_2048); ++ setup->p_size = sizeof(dh_p_2048); ++ setup->except_pub_key_size = sizeof(dh_except_b_pubkey_2048); ++ setup->pub_key_size = sizeof(dh_except_a_pubkey_2048); ++ setup->share_key_size = sizeof(dh_share_key_2048); ++ break; ++ case 3072: ++ setup->x = dh_xa_3072; ++ setup->p = dh_p_3072; ++ setup->except_pub_key = dh_except_b_pubkey_3072; ++ setup->pub_key = dh_except_a_pubkey_3072; ++ setup->share_key = dh_share_key_3072; ++ setup->x_size = sizeof(dh_xa_3072); ++ setup->p_size = sizeof(dh_p_3072); ++ setup->except_pub_key_size = sizeof(dh_except_b_pubkey_3072); ++ setup->pub_key_size = sizeof(dh_except_a_pubkey_3072); ++ setup->share_key_size = sizeof(dh_share_key_3072); ++ break; ++ case 4096: ++ setup->x = dh_xa_4096; ++ setup->p = dh_p_4096; ++ setup->except_pub_key = dh_except_b_pubkey_4096; ++ setup->pub_key = dh_except_a_pubkey_4096; ++ setup->share_key = dh_share_key_4096; ++ setup->x_size = sizeof(dh_xa_4096); ++ setup->p_size = sizeof(dh_p_4096); ++ setup->except_pub_key_size = sizeof(dh_except_b_pubkey_4096); ++ setup->pub_key_size = sizeof(dh_except_a_pubkey_4096); ++ setup->share_key_size = sizeof(dh_share_key_4096); ++ break; ++ default: ++ HPRE_TST_PRT("failed to find dh keybits %u\n", key_bits); ++ return -EINVAL; ++ } ++ ++ if (is_g2) { ++ setup->g = dh_g_2; ++ } else { ++ setup->g = dh_g_5; ++ } ++ setup->g_size = 1; ++ ++ return 0; ++} ++ ++static int get_dh_opdata_param(handle_t h_sess, struct wd_dh_req *req, ++ struct hpre_dh_param *setup, int key_size) ++{ ++ unsigned char *ag_bin = NULL; ++ struct wd_dtb ctx_g; ++ int ret; ++ ++ ag_bin = malloc(2 * key_size); ++ if (!ag_bin) ++ return -ENOMEM; ++ ++ memset(ag_bin, 0, 2 * key_size); ++ req->pv = ag_bin; ++ ++ req->x_p = malloc(2 * key_size); ++ if (!req->x_p) ++ goto ag_error; ++ ++ memset(req->x_p, 0, 2 * key_size); ++ ++ req->pri = malloc(2 * key_size); ++ if (!req->pri) ++ goto xp_error; ++ ++ memset(req->pri, 0, 2 * key_size); ++ req->pri_bytes = 2 * key_size; ++ ++ ctx_g.data = malloc(key_size); ++ if (!ctx_g.data) ++ goto ctx_release; ++ ++ if (setup->optype == WD_DH_PHASE1) { // GEN1 ++ memcpy(req->x_p, setup->x, setup->x_size); ++ memcpy(req->x_p + key_size, setup->p, setup->p_size); ++ memcpy(ctx_g.data, setup->g, setup->g_size); ++ req->pbytes = setup->p_size; ++ req->xbytes = setup->x_size; ++ ctx_g.dsize = setup->g_size; ++ ctx_g.bsize = key_size; ++ ++ ret = wd_dh_set_g(h_sess, &ctx_g); ++ if (ret) ++ HPRE_TST_PRT("wd_dh_set_g run failed\n"); ++ } else { // GEN1 ++ memcpy(req->x_p, setup->x, setup->x_size); ++ memcpy(req->x_p + key_size, setup->p, setup->p_size); ++ memcpy(req->pv, setup->except_pub_key, setup->except_pub_key_size); ++ req->pbytes = setup->p_size; ++ req->xbytes = setup->x_size; ++ req->pvbytes = setup->except_pub_key_size; ++ } ++ ++ free(ctx_g.data); ++ ++ return 0; ++ ++ctx_release: ++ free(req->pri); ++xp_error: ++ free(req->x_p); ++ag_error: ++ free(req->pv); ++ ++ return -ENOMEM; ++} ++ ++static void dh_async_cb(void *req_t) ++{ ++ //struct wd_dh_req *req = req_t; ++ //struct rsa_async_tag *tag = req->cb_param; ++ //enum wd_rsa_op_type op_type = req->op_type; ++ //handle_t h_sess = tag->sess; ++ ++ return; ++} ++ ++static void *dh_uadk_async_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ int key_size = pdata->keybits >> 3; ++ struct wd_dh_sess_setup dh_setup; ++ struct rsa_async_tag *tag; ++ struct hpre_dh_param param; ++ struct wd_dh_req req; ++ handle_t h_sess; ++ int try_cnt = 0; ++ u32 count = 0; ++ int i, ret; ++ ++ memset(&dh_setup, 0, sizeof(dh_setup)); ++ memset(&req, 0, sizeof(req)); ++ dh_setup.key_bits = pdata->keybits; ++ if (pdata->optype == WD_DH_PHASE2) ++ dh_setup.is_g2 = true; // G1 is 0; G2 is 1; ++ ++ h_sess = wd_dh_alloc_sess(&dh_setup); ++ if (!h_sess) ++ return NULL; ++ ++ ret = get_dh_param_from_sample(¶m, pdata->keybits, pdata->kmode); ++ if (ret) ++ goto sess_release; ++ ++ param.optype = pdata->optype; ++ req.op_type = pdata->optype; ++ ret = get_dh_opdata_param(h_sess, &req, ¶m, key_size); ++ if (ret){ ++ HPRE_TST_PRT("failed to fill dh key gen req!\n"); ++ goto param_release; ++ } ++ ++ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); ++ if (!tag) { ++ HPRE_TST_PRT("failed to malloc rsa tag!\n"); ++ goto param_release; ++ } ++ req.cb = dh_async_cb; ++ ++ do { ++ if (get_run_state() == 0) ++ break; ++ ++ try_cnt = 0; ++ i = count % MAX_POOL_LENTH; ++ tag[i].sess = h_sess; ++ req.cb_param = &tag[i]; ++ ++ ret = wd_do_dh_async(h_sess, &req); ++ if (ret == -WD_EBUSY) { ++ usleep(SEND_USLEEP * try_cnt); ++ try_cnt++; ++ if (try_cnt > MAX_TRY_CNT) { ++ HPRE_TST_PRT("Test DH send fail %d times!\n", MAX_TRY_CNT); ++ try_cnt = 0; ++ } ++ continue; ++ } else if (ret) { ++ HPRE_TST_PRT("failed to do DH async task!\n"); ++ goto tag_release; ++ } ++ count++; ++ } while(true); ++ ++tag_release: ++ free(tag); ++param_release: ++ free(req.x_p); ++ free(req.pv); ++ free(req.pri); ++sess_release: ++ wd_dh_free_sess(h_sess); ++ add_send_complete(); ++ ++ return NULL; ++} ++ ++static void *dh_uadk_sync_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ int key_size = pdata->keybits >> 3; ++ struct wd_dh_sess_setup dh_setup; ++ struct hpre_dh_param setup; ++ struct wd_dh_req req; ++ handle_t h_sess; ++ u32 count = 0; ++ int ret; ++ ++ memset(&dh_setup, 0, sizeof(dh_setup)); ++ memset(&req, 0, sizeof(req)); ++ dh_setup.key_bits = pdata->keybits; ++ if (pdata->optype == WD_DH_PHASE2) ++ dh_setup.is_g2 = true; // G1 is 0; G2 is 1; ++ ++ h_sess = wd_dh_alloc_sess(&dh_setup); ++ if (!h_sess) ++ return NULL; ++ ++ ret = get_dh_param_from_sample(&setup, pdata->keybits, pdata->kmode); ++ if (ret) ++ goto sess_release; ++ ++ setup.optype = pdata->optype; ++ req.op_type = pdata->optype; ++ ret = get_dh_opdata_param(h_sess, &req, &setup, key_size); ++ if (ret){ ++ HPRE_TST_PRT("failed to fill dh key gen req!\n"); ++ goto param_release; ++ } ++ ++ do { ++ ret = wd_do_dh_sync(h_sess, &req); ++ if (ret || req.status) { ++ HPRE_TST_PRT("failed to do dh task, status: %d\n", req.status); ++ goto param_release; ++ } ++ ++ count++; ++ if (get_run_state() == 0) ++ break; ++ } while(true); ++ ++param_release: ++ free(req.x_p); ++ free(req.pv); ++ free(req.pri); ++sess_release: ++ wd_dh_free_sess(h_sess); ++ add_recv_data(count, key_size); ++ ++ return NULL; ++} ++ ++static int hpre_compute_hash(const char *in, size_t in_len, ++ char *out, size_t out_len, void *usr) ++{ ++ /* perf test for none hash check */ ++ return 0; ++} ++ ++static int ecdsa_param_fill(handle_t h_sess, struct wd_ecc_req *req, ++ struct wd_ecc_key *ecc_key, struct hpre_ecc_setup *setup, ++ thread_data *pdata) ++{ ++ int key_insize = (pdata->keybits + 7) / 8; ++ u32 optype = pdata->optype; ++ struct wd_ecc_out *ecc_out = NULL; ++ struct wd_ecc_in *ecc_in = NULL; ++ struct wd_ecc_point pub; ++ struct wd_dtb d, e, k; ++ int ret = 0; ++ ++ if (optype == WD_ECDSA_SIGN) {// Sign ++ ecc_out = wd_ecdsa_new_sign_out(h_sess); ++ if (!ecc_out) { ++ HPRE_TST_PRT("failed to get ecdsa out!\n"); ++ return -ENOMEM; ++ } ++ ++ d.data = (void *)setup->priv_key; ++ d.dsize = setup->priv_key_size; ++ d.bsize = setup->priv_key_size; ++ ret = wd_ecc_set_prikey(ecc_key, &d); ++ if (ret) { ++ HPRE_TST_PRT("failed to set ecdsa prikey!\n"); ++ goto del_ecc_out; ++ } ++ ++ pub.x.data = (void *)setup->pub_key + 1; ++ pub.x.dsize = key_insize; ++ pub.x.bsize = key_insize; ++ pub.y.data = pub.x.data + key_insize; ++ pub.y.dsize = key_insize; ++ pub.y.bsize = key_insize; ++ ret = wd_ecc_set_pubkey(ecc_key, &pub); ++ if (ret) { ++ HPRE_TST_PRT("failed to set ecdsa pubkey!\n"); ++ goto del_ecc_out; ++ } ++ ++ e.data = (void *)setup->msg; ++ e.dsize = setup->msg_size; ++ e.bsize = key_insize; ++ ++ k.data = (void *)setup->k; ++ k.dsize = setup->k_size; ++ k.bsize = key_insize; ++ ecc_in = wd_ecdsa_new_sign_in(h_sess, &e, &k); ++ if (!ecc_in) { ++ HPRE_TST_PRT("failed to get ecdsa sign in!\n"); ++ ret = -ENOMEM; ++ goto del_ecc_out; ++ } ++ ++ req->src = ecc_in; ++ req->dst = ecc_out; ++ } else { // Verf ++ pub.x.data = (void *)setup->pub_key + 1; ++ pub.x.dsize = key_insize; ++ pub.x.bsize = key_insize; ++ pub.y.data = pub.x.data + key_insize; ++ pub.y.dsize = key_insize; ++ pub.y.bsize = key_insize; ++ ret = wd_ecc_set_pubkey(ecc_key, &pub); ++ if (ret) { ++ HPRE_TST_PRT("failed to set ecdsa pubkey!\n"); ++ return -ENOMEM; ++ } ++ ++ e.data = (void *)setup->msg; ++ e.dsize = setup->msg_size; ++ e.bsize = key_insize; ++ ++ d.data = (void *)setup->sign; ++ d.dsize = key_insize; ++ d.bsize = key_insize; ++ k.data = d.data + key_insize; ++ k.dsize = key_insize; ++ k.bsize = key_insize; ++ ecc_in = wd_ecdsa_new_verf_in(h_sess, &e, &d, &k); ++ if (!ecc_in) { ++ HPRE_TST_PRT("failed to get ecdsa verf ecc in!\n"); ++ return -ENOMEM; ++ } ++ ++ req->src = ecc_in; ++ } ++ ++ return 0; ++del_ecc_out: ++ if (ecc_out) ++ (void)wd_ecc_del_out(h_sess, ecc_out); ++ return ret; ++} ++ ++static int sm2_param_fill(handle_t h_sess, struct wd_ecc_req *req, ++ struct hpre_ecc_setup *setup, thread_data *pdata) ++{ ++ int key_insize = (pdata->keybits + 7) / 8; ++ u32 optype = pdata->optype; ++ struct wd_ecc_out *ecc_out = NULL; ++ struct wd_ecc_in *ecc_in = NULL; ++ struct wd_ecc_point tmp; ++ struct wd_dtb d, e, k; ++ ++ switch (optype) { ++ case WD_SM2_SIGN:// Sign ++ ecc_out = wd_sm2_new_sign_out(h_sess); ++ if (!ecc_out) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); ++ return -ENOMEM; ++ } ++ ++ e.data = (void *)setup->msg; ++ e.dsize = setup->msg_size; ++ e.bsize = setup->msg_size; ++ k.data = (void *)setup->k; ++ k.dsize = setup->k_size; ++ k.bsize = key_insize; ++ ecc_in = wd_sm2_new_sign_in(h_sess, &e, &k, NULL, 1); ++ if (!ecc_in) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); ++ goto del_ecc_out; ++ } ++ req->src = ecc_in; ++ req->dst = ecc_out; ++ break; ++ case WD_SM2_VERIFY: // Verf ++ ecc_out = wd_sm2_new_sign_out(h_sess); ++ if (!ecc_out) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); ++ return -ENOMEM; ++ } ++ ++ e.data = (void *)setup->msg; ++ e.dsize = setup->msg_size; ++ e.bsize = key_insize; ++ d.data = (void *)setup->sign; ++ d.dsize = key_insize; ++ d.bsize = key_insize; ++ k.data = d.data + key_insize; ++ k.dsize = key_insize; ++ k.bsize = key_insize; ++ ecc_in = wd_sm2_new_verf_in(h_sess, &e, &d, &k, NULL, 1); ++ if (!ecc_in) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); ++ goto del_ecc_out; ++ } ++ ++ req->src = ecc_in; ++ req->dst = ecc_out; ++ break; ++ case WD_SM2_ENCRYPT: // Enc ++ ecc_out = wd_sm2_new_enc_out(h_sess, setup->msg_size); ++ if (!ecc_out) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); ++ return -ENOMEM; ++ } ++ ++ e.data = (void *)setup->plaintext; ++ e.dsize = setup->plaintext_size; ++ e.bsize = setup->plaintext_size; ++ k.data = (void *)setup->k; ++ k.dsize = setup->k_size; ++ k.bsize = key_insize; ++ ecc_in = wd_sm2_new_enc_in(h_sess, &e, &k); ++ if (!ecc_in) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); ++ goto del_ecc_out; ++ } ++ req->src = ecc_in; ++ req->dst = ecc_out; ++ break; ++ case WD_SM2_DECRYPT: // Dec ++ tmp.x.data = (void *)setup->ciphertext; ++ tmp.x.dsize = 32; ++ tmp.y.data = tmp.x.data + 32; ++ tmp.y.dsize = 32; ++ e.data = tmp.y.data + 32; ++ e.dsize = 32; ++ d.data = e.data + 32; ++ d.dsize = setup->ciphertext_size - 32 * 3; ++ ecc_in = wd_sm2_new_dec_in(h_sess, &tmp, &d, &e); ++ if (!ecc_in) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); ++ return -ENOMEM; ++ } ++ ++ ecc_out = wd_sm2_new_dec_out(h_sess, d.dsize); ++ if (!ecc_out) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); ++ goto del_ecc_in; ++ } ++ ++ req->src = ecc_in; ++ req->dst = ecc_out; ++ break; ++ case WD_SM2_KG: // KG ++ ecc_out = wd_sm2_new_kg_out(h_sess); ++ if (!ecc_out) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); ++ return -ENOMEM; ++ } ++ ++ req->dst = ecc_out; ++ break; ++ default: ++ HPRE_TST_PRT("failed to match sm2 optype!\n"); ++ return -ENOMEM; ++ } ++ ++ return 0; ++ ++del_ecc_in: ++ if (ecc_in) ++ (void)wd_ecc_del_in(h_sess, ecc_in); ++del_ecc_out: ++ if (ecc_out) ++ (void)wd_ecc_del_out(h_sess, ecc_out); ++ ++ return -ENOMEM; ++} ++ ++static int ecc_param_fill(handle_t h_sess, struct wd_ecc_req *req, ++ struct wd_ecc_key *ecc_key, struct hpre_ecc_setup *setup, ++ thread_data *pdata) ++{ ++ int key_insize = (pdata->keybits + 7) / 8; ++ u32 subtype = pdata->subtype; ++ u32 optype = pdata->optype; ++ struct wd_ecc_out *ecc_out = NULL; ++ struct wd_ecc_in *ecc_in = NULL; ++ struct wd_ecc_point tmp; ++ struct wd_dtb d; ++ int ret = 0; ++ ++ ecc_out = wd_ecxdh_new_out(h_sess); ++ if (!ecc_out) { ++ HPRE_TST_PRT("failed to alloc ecc out!\n"); ++ return -ENOMEM; ++ } ++ if (optype == WD_ECXDH_GEN_KEY) { // gen ++ d.data = (void *)setup->priv_key; ++ d.dsize = setup->priv_key_size; ++ d.bsize = setup->priv_key_size; ++ ret = wd_ecc_set_prikey(ecc_key, &d); ++ if (ret) { ++ HPRE_TST_PRT("failed to set ecxdh prikey!\n"); ++ goto del_ecc_out; ++ } ++ ++ req->dst = ecc_out; ++ } else { // compute ++ if (subtype == ECDH_TYPE) ++ tmp.x.data = setup->except_pub_key; ++ else ++ tmp.x.data = setup->except_pub_key + 1; ++ tmp.x.bsize = key_insize; ++ tmp.x.dsize = key_insize; ++ tmp.y.data = tmp.x.data + key_insize; ++ tmp.y.bsize = key_insize; ++ tmp.y.dsize = key_insize; ++ ecc_in = wd_ecxdh_new_in(h_sess, &tmp); ++ if (!ecc_in) { ++ HPRE_TST_PRT("failed to get ecxdh sign in!\n"); ++ goto del_ecc_out; ++ } ++ ++ d.data = (void *)setup->priv_key; ++ d.dsize = setup->priv_key_size; ++ d.bsize = setup->priv_key_size; ++ ret = wd_ecc_set_prikey(ecc_key, &d); ++ if (ret) { ++ HPRE_TST_PRT("failed to set ecc prikey!\n"); ++ goto del_ecc_out; ++ } ++ ++ req->src = ecc_in; ++ req->dst = ecc_out; ++ } ++ ++ return 0; ++ ++del_ecc_out: ++ if (ecc_out) ++ (void)wd_ecc_del_out(h_sess, ecc_out); ++ ++ return ret; ++} ++ ++static void *ecc_uadk_sync_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ int key_size = pdata->keybits >> 3; ++ u32 subtype = pdata->subtype; ++ struct wd_ecc_sess_setup sess_setup; ++ struct hpre_ecc_setup setup; ++ struct wd_ecc_curve param; ++ struct wd_ecc_key *ecc_key; ++ struct wd_ecc_point pbk; ++ struct wd_dtb prk; ++ struct wd_ecc_req req; ++ u32 cid = ECC_CURVE_ID; ++ handle_t h_sess; ++ u32 count = 0; ++ int ret; ++ ++ memset(&sess_setup, 0, sizeof(sess_setup)); ++ memset(¶m, 0, sizeof(param)); ++ memset(&req, 0, sizeof(req)); ++ ++ memset(&setup, 0, sizeof(setup)); ++ if (subtype != X448_TYPE || subtype != X25519_TYPE) { ++ ret = get_ecc_curve(&setup, cid); ++ if (ret) ++ return NULL; ++ } ++ ++ sess_setup.key_bits = pdata->keybits; ++ if (subtype == ECDH_TYPE || subtype == ECDSA_TYPE) { ++ if (cid > ECC_CURVE_ID) { ++ sess_setup.cv.type = WD_CV_CFG_PARAM; ++ get_ecc_key_param(¶m, pdata->keybits); ++ sess_setup.cv.cfg.pparam = ¶m; ++ } else { ++ sess_setup.cv.type = WD_CV_CFG_ID; ++ sess_setup.cv.cfg.id = setup.curve_id; ++ } ++ } ++ ++ sess_setup.rand.cb = ecc_get_rand; ++ switch (subtype) { ++ case SM2_TYPE: ++ sess_setup.alg = "sm2"; ++ break; ++ case ECDH_TYPE: ++ sess_setup.alg = "ecdh"; ++ break; ++ case ECDSA_TYPE: ++ sess_setup.alg = "ecdsa"; ++ break; ++ } ++ ++ // set def setting; ++ sess_setup.hash.cb = hpre_compute_hash; ++ sess_setup.hash.type = WD_HASH_SHA256; ++ ++ ret = get_ecc_param_from_sample(&setup, subtype, pdata->keybits); ++ if (ret) ++ return NULL; ++ ++ h_sess = wd_ecc_alloc_sess(&sess_setup); ++ if (!h_sess) ++ goto msg_release; ++ ++ prk.data = (void *)setup.priv_key; ++ prk.dsize = setup.priv_key_size; ++ prk.bsize = setup.priv_key_size; ++ pbk.x.data = (char *)setup.pub_key + 1; ++ pbk.x.dsize = key_size; ++ pbk.x.bsize = key_size; ++ pbk.y.data = pbk.x.data + key_size; ++ pbk.y.dsize = key_size; ++ pbk.y.bsize = key_size; ++ ++ ecc_key = wd_ecc_get_key(h_sess); ++ ret = wd_ecc_set_prikey(ecc_key, &prk); ++ if (ret) { ++ HPRE_TST_PRT("failed to pre set ecc prikey!\n"); ++ goto sess_release; ++ } ++ ++ ret = wd_ecc_set_pubkey(ecc_key, &pbk); ++ if (ret) { ++ HPRE_TST_PRT("failed to pre set ecc pubkey!\n"); ++ goto sess_release; ++ } ++ ++ req.op_type = pdata->optype; ++ switch (subtype) { ++ case ECDSA_TYPE: // ECC alg ++ ret = ecdsa_param_fill(h_sess, &req, ecc_key, &setup, pdata); ++ if (ret) ++ goto src_release; ++ break; ++ case SM2_TYPE: // SM2 alg ++ ret = sm2_param_fill(h_sess, &req, &setup, pdata); ++ if (ret) ++ goto src_release; ++ break; ++ default: // ECDH, X25519, X448 alg ++ ret = ecc_param_fill(h_sess, &req, ecc_key, &setup, pdata); ++ if (ret) ++ goto src_release; ++ break; ++ } ++ ++ do { ++ ret = wd_do_ecc_sync(h_sess, &req); ++ if (ret || req.status) { ++ HPRE_TST_PRT("failed to do ecc task, status: %d\n", req.status); ++ goto src_release; ++ } ++ ++ count++; ++ if (get_run_state() == 0) ++ break; ++ } while(true); ++ ++src_release: ++ if (req.src) ++ (void)wd_ecc_del_in(h_sess, req.src); ++ if (req.dst) ++ (void)wd_ecc_del_out(h_sess, req.dst); ++sess_release: ++ wd_ecc_free_sess(h_sess); ++msg_release: ++ if (subtype == SM2_TYPE) ++ free(setup.msg); ++ ++ add_recv_data(count, key_size); ++ ++ return NULL; ++} ++ ++static void ecc_async_cb(void *req_t) ++{ ++ //struct wd_ecc_req *req = req_t; ++ //struct rsa_async_tag *tag = req->cb_param; ++ //enum wd_rsa_op_type op_type = req->op_type; ++ //handle_t h_sess = tag->sess; ++ ++ return; ++} ++ ++static void *ecc_uadk_async_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ int key_size = pdata->keybits >> 3; ++ u32 subtype = pdata->subtype; ++ struct wd_ecc_sess_setup sess_setup; ++ struct rsa_async_tag *tag; ++ struct hpre_ecc_setup setup; ++ struct wd_ecc_curve param; ++ struct wd_ecc_key *ecc_key; ++ struct wd_ecc_point pbk; ++ struct wd_ecc_req req; ++ struct wd_dtb prk; ++ u32 cid = ECC_CURVE_ID; ++ handle_t h_sess; ++ int try_cnt = 0; ++ u32 count = 0; ++ int i, ret; ++ ++ memset(&sess_setup, 0, sizeof(sess_setup)); ++ memset(¶m, 0, sizeof(param)); ++ memset(&req, 0, sizeof(req)); ++ ++ memset(&setup, 0, sizeof(setup)); ++ if (subtype != X448_TYPE || subtype != X25519_TYPE) { ++ ret = get_ecc_curve(&setup, cid); ++ if (ret) ++ return NULL; ++ } ++ ++ sess_setup.key_bits = pdata->keybits; ++ if (subtype == ECDH_TYPE || subtype == ECDSA_TYPE) { ++ if (cid > ECC_CURVE_ID) { ++ sess_setup.cv.type = WD_CV_CFG_PARAM; ++ get_ecc_key_param(¶m, pdata->keybits); ++ sess_setup.cv.cfg.pparam = ¶m; ++ } else { ++ sess_setup.cv.type = WD_CV_CFG_ID; ++ sess_setup.cv.cfg.id = setup.curve_id; ++ } ++ } ++ ++ sess_setup.rand.cb = ecc_get_rand; ++ switch (subtype) { ++ case SM2_TYPE: ++ sess_setup.alg = "sm2"; ++ break; ++ case ECDH_TYPE: ++ sess_setup.alg = "ecdh"; ++ break; ++ case ECDSA_TYPE: ++ sess_setup.alg = "ecdsa"; ++ break; ++ } ++ ++ // set def setting; ++ sess_setup.hash.cb = hpre_compute_hash; ++ sess_setup.hash.type = WD_HASH_SHA256; ++ ++ ret = get_ecc_param_from_sample(&setup, subtype, pdata->keybits); ++ if (ret) ++ return NULL; ++ ++ h_sess = wd_ecc_alloc_sess(&sess_setup); ++ if (!h_sess) ++ goto msg_release; ++ ++ prk.data = (void *)setup.priv_key; ++ prk.dsize = setup.priv_key_size; ++ prk.bsize = setup.priv_key_size; ++ pbk.x.data = (char *)setup.pub_key + 1; ++ pbk.x.dsize = key_size; ++ pbk.x.bsize = key_size; ++ pbk.y.data = pbk.x.data + key_size; ++ pbk.y.dsize = key_size; ++ pbk.y.bsize = key_size; ++ ++ ecc_key = wd_ecc_get_key(h_sess); ++ ret = wd_ecc_set_prikey(ecc_key, &prk); ++ if (ret) { ++ HPRE_TST_PRT("failed to pre set ecc prikey!\n"); ++ goto sess_release; ++ } ++ ++ ret = wd_ecc_set_pubkey(ecc_key, &pbk); ++ if (ret) { ++ HPRE_TST_PRT("failed to pre set ecc pubkey!\n"); ++ goto sess_release; ++ } ++ ++ req.op_type = pdata->optype; ++ switch (subtype) { ++ case ECDSA_TYPE: // ECC alg ++ ret = ecdsa_param_fill(h_sess, &req, ecc_key, &setup, pdata); ++ if (ret) ++ goto src_release; ++ break; ++ case SM2_TYPE: // SM2 alg ++ ret = sm2_param_fill(h_sess, &req, &setup, pdata); ++ if (ret) ++ goto src_release; ++ break; ++ default: // ECDH, X25519, X448 alg ++ ret = ecc_param_fill(h_sess, &req, ecc_key, &setup, pdata); ++ if (ret) ++ goto src_release; ++ break; ++ } ++ ++ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); ++ if (!tag) { ++ HPRE_TST_PRT("failed to malloc rsa tag!\n"); ++ goto src_release; ++ } ++ req.cb = ecc_async_cb; ++ ++ do { ++ if (get_run_state() == 0) ++ break; ++ ++ try_cnt = 0; ++ i = count % MAX_POOL_LENTH; ++ tag[i].sess = h_sess; ++ req.cb_param = &tag[i]; ++ ++ ret = wd_do_ecc_sync(h_sess, &req); ++ if (ret == -WD_EBUSY) { ++ usleep(SEND_USLEEP * try_cnt); ++ try_cnt++; ++ if (try_cnt > MAX_TRY_CNT) { ++ HPRE_TST_PRT("Test ECC send fail %d times!\n", MAX_TRY_CNT); ++ try_cnt = 0; ++ } ++ continue; ++ } else if (ret) { ++ HPRE_TST_PRT("failed to do ECC async task!\n"); ++ goto tag_release; ++ } ++ count++; ++ } while(true); ++ ++tag_release: ++ free(tag); ++src_release: ++ if (req.src) ++ (void)wd_ecc_del_in(h_sess, req.src); ++ if (req.dst) ++ (void)wd_ecc_del_out(h_sess, req.dst); ++sess_release: ++ wd_ecc_free_sess(h_sess); ++msg_release: ++ if (subtype == SM2_TYPE) ++ free(setup.msg); ++ ++ add_send_complete(); ++ ++ return NULL; ++} ++ ++static int hpre_uadk_sync_threads(struct acc_option *options) ++{ ++ typedef void *(*hpre_sync_run)(void *arg); ++ hpre_sync_run uadk_hpre_sync_run = NULL; ++ thread_data threads_args[THREADS_NUM]; ++ thread_data threads_option; ++ pthread_t tdid[THREADS_NUM]; ++ int i, ret; ++ ++ /* alg param parse and set to thread data */ ++ threads_option.subtype = options->subtype; ++ threads_option.td_id = 0; ++ ret = hpre_uadk_param_parse(&threads_option, options); ++ if (ret) ++ return ret; ++ ++ switch (options->subtype) { ++ case RSA_TYPE: ++ uadk_hpre_sync_run = rsa_uadk_sync_run; ++ break; ++ case DH_TYPE: ++ uadk_hpre_sync_run = dh_uadk_sync_run; ++ break; ++ case ECDH_TYPE: ++ case ECDSA_TYPE: ++ case SM2_TYPE: ++ case X25519_TYPE: ++ case X448_TYPE: ++ uadk_hpre_sync_run = ecc_uadk_sync_run; ++ break; ++ default: ++ HPRE_TST_PRT("failed to parse alg subtype on uninit!\n"); ++ return -EINVAL; ++ } ++ ++ for (i = 0; i < g_thread_num; i++) { ++ threads_args[i].subtype = threads_option.subtype; ++ threads_args[i].kmode = threads_option.kmode; ++ threads_args[i].keybits = threads_option.keybits; ++ threads_args[i].optype = threads_option.optype; ++ threads_args[i].td_id = i; ++ ret = pthread_create(&tdid[i], NULL, uadk_hpre_sync_run, &threads_args[i]); ++ if (ret) { ++ HPRE_TST_PRT("Create sync thread fail!\n"); ++ goto sync_error; ++ } ++ } ++ ++ /* join thread */ ++ for (i = 0; i < g_thread_num; i++) { ++ ret = pthread_join(tdid[i], NULL); ++ if (ret) { ++ HPRE_TST_PRT("Join sync thread fail!\n"); ++ goto sync_error; ++ } ++ } ++ ++sync_error: ++ return ret; ++} ++ ++static int hpre_uadk_async_threads(struct acc_option *options) ++{ ++ typedef void *(*hpre_async_run)(void *arg); ++ hpre_async_run uadk_hpre_async_run = NULL; ++ thread_data threads_args[THREADS_NUM]; ++ thread_data threads_option; ++ pthread_t tdid[THREADS_NUM]; ++ pthread_t pollid[THREADS_NUM]; ++ int i, ret; ++ ++ /* alg param parse and set to thread data */ ++ threads_option.subtype = options->subtype; ++ threads_option.td_id = 0; ++ ret = hpre_uadk_param_parse(&threads_option, options); ++ if (ret) ++ return ret; ++ ++ switch (options->subtype) { ++ case RSA_TYPE: ++ uadk_hpre_async_run = rsa_uadk_async_run; ++ break; ++ case DH_TYPE: ++ uadk_hpre_async_run = dh_uadk_async_run; ++ break; ++ case ECDH_TYPE: ++ case ECDSA_TYPE: ++ case SM2_TYPE: ++ case X25519_TYPE: ++ case X448_TYPE: ++ uadk_hpre_async_run = ecc_uadk_async_run; ++ break; ++ default: ++ HPRE_TST_PRT("failed to parse alg subtype on uninit!\n"); ++ return -EINVAL; ++ } ++ ++ for (i = 0; i < g_ctxnum; i++) { ++ threads_args[i].subtype = threads_option.subtype; ++ threads_args[i].td_id = i; ++ /* poll thread */ ++ ret = pthread_create(&pollid[i], NULL, hpre_uadk_poll, &threads_args[i]); ++ if (ret) { ++ HPRE_TST_PRT("Create poll thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++ for (i = 0; i < g_thread_num; i++) { ++ threads_args[i].subtype = threads_option.subtype; ++ threads_args[i].kmode = threads_option.kmode; ++ threads_args[i].keybits = threads_option.keybits; ++ threads_args[i].optype = threads_option.optype; ++ threads_args[i].td_id = i; ++ ret = pthread_create(&tdid[i], NULL, uadk_hpre_async_run, &threads_args[i]); ++ if (ret) { ++ HPRE_TST_PRT("Create async thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++ /* join thread */ ++ for (i = 0; i < g_thread_num; i++) { ++ ret = pthread_join(tdid[i], NULL); ++ if (ret) { ++ HPRE_TST_PRT("Join async thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++ for (i = 0; i < g_ctxnum; i++) { ++ ret = pthread_join(pollid[i], NULL); ++ if (ret) { ++ HPRE_TST_PRT("Join poll thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++async_error: ++ return ret; ++} ++ ++int hpre_uadk_benchmark(struct acc_option *options) ++{ ++ u32 ptime; ++ int ret; ++ ++ g_thread_num = options->threads; ++ g_ctxnum = options->ctxnums; ++ ++ if (options->optype >= (WD_EC_OP_MAX - WD_ECDSA_VERIFY)) { ++ HPRE_TST_PRT("HPRE optype error: %u\n", options->optype); ++ return -EINVAL; ++ } ++ ++ ret = init_hpre_ctx_config(options->algclass, options->subtype, ++ options->syncmode); ++ if (ret) ++ return ret; ++ ++ get_pid_cpu_time(&ptime); ++ time_start(options->times); ++ if (options->syncmode) ++ ret = hpre_uadk_async_threads(options); ++ else ++ ret = hpre_uadk_sync_threads(options); ++ cal_perfermance_data(options, ptime); ++ if (ret) ++ return ret; ++ ++ uninit_hpre_ctx_config(options->subtype); ++ ++ return 0; ++} +diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.h b/uadk_tool/benchmark/hpre_uadk_benchmark.h +new file mode 100644 +index 0000000..7e3966d +--- /dev/null ++++ b/uadk_tool/benchmark/hpre_uadk_benchmark.h +@@ -0,0 +1,6 @@ ++/* SPDX-License-Identifier: Apache-2.0 */ ++#ifndef HPRE_UADK_BENCHMARK_H ++#define HPRE_UADK_BENCHMARK_H ++ ++extern int hpre_uadk_benchmark(struct acc_option *options); ++#endif /* HPRE_UADK_BENCHMARK_H */ +-- +2.27.0 + diff --git a/0135-uadk_tool-Add-No-SVA-mode-test-function-to-HPRE.patch b/0135-uadk_tool-Add-No-SVA-mode-test-function-to-HPRE.patch new file mode 100644 index 0000000..d3b9efd --- /dev/null +++ b/0135-uadk_tool-Add-No-SVA-mode-test-function-to-HPRE.patch @@ -0,0 +1,2590 @@ +From a845386d02be1e51832a01681f97a032707f9026 Mon Sep 17 00:00:00 2001 +From: Longfang Liu +Date: Mon, 18 Jul 2022 17:16:33 +0800 +Subject: [PATCH 149/183] uadk_tool: Add No-SVA mode test function to HPRE + +Added No-SVA mode performance test function for +HPRE's RSA, DH, ECC algorithms. + +Signed-off-by: Longfang Liu +--- + uadk_tool/benchmark/hpre_wd_benchmark.c | 2553 +++++++++++++++++++++++ + uadk_tool/benchmark/hpre_wd_benchmark.h | 6 + + 2 files changed, 2559 insertions(+) + create mode 100644 uadk_tool/benchmark/hpre_wd_benchmark.c + create mode 100644 uadk_tool/benchmark/hpre_wd_benchmark.h + +diff --git a/uadk_tool/benchmark/hpre_wd_benchmark.c b/uadk_tool/benchmark/hpre_wd_benchmark.c +new file mode 100644 +index 0000000..c9b0c18 +--- /dev/null ++++ b/uadk_tool/benchmark/hpre_wd_benchmark.c +@@ -0,0 +1,2553 @@ ++/* SPDX-License-Identifier: Apache-2.0 */ ++ ++#include ++#include "uadk_benchmark.h" ++ ++#include "hpre_wd_benchmark.h" ++#include "hpre_protocol_data.h" ++#include "v1/wd.h" ++#include "v1/wd_ecc.h" ++#include "v1/wd_rsa.h" ++#include "v1/wd_dh.h" ++#include "v1/wd_bmm.h" ++#include "v1/wd_util.h" ++ ++#define ECC_CURVE_ID 0x3 /* def set secp256k1 */ ++#define HPRE_TST_PRT printf ++#define ERR_OPTYPE 0xFF ++#define SM2_DG_SZ 1024 ++#define SEND_USLEEP 100 ++#define ALIGN_SIZE 128 ++ ++static char rsa_m[8] = {0x54, 0x85, 0x9b, 0x34, 0x2c, 0x49, 0xea, 0x2a}; ++ ++struct hpre_rsa_key_in { ++ void *e; ++ void *p; ++ void *q; ++ u32 e_size; ++ u32 p_size; ++ u32 q_size; ++ void *data[]; ++}; ++static __thread struct hpre_rsa_key_in *rsa_key_in = NULL; ++ ++struct rsa_async_tag { ++ void *ctx; ++ int cnt; ++ int optype; ++}; ++ ++//----------------------------------RSA param--------------------------------------// ++struct hpre_dh_param { ++ const void *x; ++ const void *p; ++ const void *g; ++ const void *except_pub_key; ++ const void *pub_key; ++ const void *share_key; ++ void *pool; ++ u32 x_size; ++ u32 p_size; ++ u32 g_size; ++ u32 pub_key_size; ++ u32 share_key_size; ++ u32 except_pub_key_size; ++ u32 key_bits; ++ u32 optype; ++}; ++ ++//----------------------------------DH param-------------------------------------// ++struct hpre_ecc_setup { ++ void *except_pub_key; // use in ecdh phase 2 ++ const void *pub_key; // use in ecdh phase 1 ++ const void *share_key; // use in ecdh phase 2 ++ const void *degist; //ecdsa sign in ++ const void *k; //ecdsa sign in ++ const void *rp; //ecdsa sign in ++ const void *sign; // ecdsa sign out or verf in ++ const void *priv_key; // use in ecdsa sign ++ void *msg; // sm2 plaintext,ciphertext or digest input ++ const void *userid; // sm2 user id ++ const void *ciphertext; // sm2 ciphertext ++ const void *plaintext; // sm2 plaintext ++ u32 key_size; ++ u32 share_key_size; ++ u32 except_pub_key_size; ++ u32 degist_size; ++ u32 k_size; ++ u32 rp_size; ++ u32 sign_size; ++ u32 priv_key_size; ++ u32 pub_key_size; ++ u32 msg_size; ++ u32 userid_size; ++ u32 ciphertext_size; ++ u32 plaintext_size; ++ u32 op_type; ++ u32 key_bits; ++ u32 nid; ++ u32 curve_id; // WD ecc curve_id ++}; ++ ++//----------------------------------ECC param-------------------------------------// ++struct thread_bd_res { ++ struct wd_queue *queue; ++ void *pool; ++}; ++ ++struct thread_queue_res { ++ struct thread_bd_res *bd_res; ++}; ++ ++typedef struct uadk_thread_res { ++ u32 subtype; ++ u32 keybits; ++ u32 kmode; ++ u32 optype; ++ u32 td_id; ++} thread_data; ++ ++static unsigned int g_thread_num; ++static struct thread_queue_res g_thread_queue; ++ ++static const char* const alg_operations[] = { ++ "GenKey", "ShareKey", "Encrypt", "Decrypt", "Sign", "Verify", ++}; ++ ++static void get_rsa_param(u32 algtype, u32 *keysize, u32 *mode) ++{ ++ switch(algtype) { ++ case RSA_1024: ++ *keysize = 1024; ++ *mode = 0; ++ break; ++ case RSA_2048: ++ *keysize = 2048; ++ *mode = 0; ++ break; ++ case RSA_3072: ++ *keysize = 3072; ++ *mode = 0; ++ break; ++ case RSA_4096: ++ *keysize = 4096; ++ *mode = 0; ++ break; ++ case RSA_1024_CRT: ++ *keysize = 1024; ++ *mode = 1; ++ break; ++ case RSA_2048_CRT: ++ *keysize = 2048; ++ *mode = 1; ++ break; ++ case RSA_3072_CRT: ++ *keysize = 3072; ++ *mode = 1; ++ break; ++ case RSA_4096_CRT: ++ *keysize = 4096; ++ *mode = 1; ++ break; ++ } ++} ++ ++static u32 get_rsa_optype(u32 optype) ++{ ++ u32 op_type = 0; ++ ++ switch(optype) { ++ case 0: //GENKEY1 ++ op_type = WCRYPTO_RSA_GENKEY; ++ break; ++ case 4: //Sign ++ op_type = WCRYPTO_RSA_SIGN; ++ break; ++ case 5: //Verf ++ op_type = WCRYPTO_RSA_VERIFY; ++ break; ++ default: ++ HPRE_TST_PRT("failed to set rsa op_type\n"); ++ HPRE_TST_PRT("RSA Gen: 0\n"); ++ HPRE_TST_PRT("RSA Sign: 4\n"); ++ HPRE_TST_PRT("RSA Verf: 5\n"); ++ return ERR_OPTYPE; ++ } ++ ++ return op_type; ++} ++ ++static void get_dh_param(u32 algtype, u32 *keysize) ++{ ++ switch(algtype) { ++ case DH_768: ++ *keysize = 768; ++ break; ++ case DH_1024: ++ *keysize = 1024; ++ break; ++ case DH_1536: ++ *keysize = 1536; ++ break; ++ case DH_2048: ++ *keysize = 2048; ++ break; ++ case DH_3072: ++ *keysize = 3072; ++ break; ++ case DH_4096: ++ *keysize = 4096; ++ break; ++ } ++} ++ ++static u32 get_dh_optype(u32 optype) ++{ ++ u32 op_type = 0; ++ ++ switch(optype) { ++ case 0: //GENKEY1 ++ op_type = WCRYPTO_DH_PHASE1; ++ break; ++ case 1: //GENKEY12 ++ op_type = WCRYPTO_DH_PHASE2; ++ break; ++ default: ++ HPRE_TST_PRT("failed to set dh op_type\n"); ++ HPRE_TST_PRT("DH Gen1: 0\n"); ++ HPRE_TST_PRT("DH Gen2: 1\n"); ++ return ERR_OPTYPE; ++ } ++ ++ return op_type; ++} ++ ++static void get_ecc_param(u32 algtype, u32 *keysize) ++{ ++ switch(algtype) { ++ case ECDH_256: ++ *keysize = 256; ++ break; ++ case ECDH_384: ++ *keysize = 384; ++ break; ++ case ECDH_521: ++ *keysize = 521; ++ break; ++ case ECDSA_256: ++ *keysize = 256; ++ break; ++ case ECDSA_384: ++ *keysize = 384; ++ break; ++ case ECDSA_521: ++ *keysize = 521; ++ break; ++ case SM2_ALG: ++ *keysize = 256; ++ break; ++ case X25519_ALG: ++ *keysize = 256; ++ break; ++ case X448_ALG: ++ *keysize = 448; ++ break; ++ } ++} ++ ++static u32 get_ecc_optype(u32 subtype, u32 optype) ++{ ++ u32 op_type = 0; ++ ++ if (subtype == SM2_TYPE) { ++ switch (optype) { ++ case 0: ++ op_type = WCRYPTO_SM2_KG; ++ break; ++ case 2: ++ op_type = WCRYPTO_SM2_ENCRYPT; ++ break; ++ case 3: ++ op_type = WCRYPTO_SM2_DECRYPT; ++ break; ++ case 4: ++ op_type = WCRYPTO_SM2_SIGN; ++ break; ++ case 5: ++ op_type = WCRYPTO_SM2_VERIFY; ++ break; ++ default: ++ HPRE_TST_PRT("failed to set SM2 op_type\n"); ++ HPRE_TST_PRT("SM2 KeyGen: 0\n"); ++ HPRE_TST_PRT("SM2 Encrypt: 2\n"); ++ HPRE_TST_PRT("SM2 Decrypt: 3\n"); ++ HPRE_TST_PRT("SM2 Sign: 4\n"); ++ HPRE_TST_PRT("SM2 Verify: 5\n"); ++ return ERR_OPTYPE; ++ } ++ } else if (subtype == ECDH_TYPE || ++ subtype == X25519_TYPE || subtype == X448_TYPE) { ++ switch(optype) { ++ case 0: //GENKEY ++ op_type = WCRYPTO_ECXDH_GEN_KEY; ++ break; ++ case 1: //COMPUTEKEY ++ op_type = WCRYPTO_ECXDH_COMPUTE_KEY; ++ break; ++ default: ++ HPRE_TST_PRT("failed to set ECDH op_type\n"); ++ HPRE_TST_PRT("ECDH GenKey: 0\n"); ++ HPRE_TST_PRT("ECDH ShareKey: 1\n"); ++ return ERR_OPTYPE; ++ } ++ } else if (subtype == ECDSA_TYPE) { ++ switch(optype) { ++ case 4: //Sign ++ op_type = WCRYPTO_ECDSA_SIGN; ++ break; ++ case 5: //Verf ++ op_type = WCRYPTO_ECDSA_VERIFY; ++ break; ++ default: ++ HPRE_TST_PRT("failed to set ECDSA op_type\n"); ++ HPRE_TST_PRT("ECDSA Sign: 4\n"); ++ HPRE_TST_PRT("ECDSA Verf: 5\n"); ++ return ERR_OPTYPE; ++ } ++ } ++ ++ return op_type; ++} ++ ++static int hpre_wd_param_parse(thread_data *tddata, struct acc_option *options) ++{ ++ u32 algtype = options->algtype; ++ u32 optype = 0; ++ u32 keysize = 0; ++ u32 mode = 0; ++ ++ if (algtype >= RSA_1024 && algtype <= RSA_4096_CRT) { ++ get_rsa_param(algtype, &keysize, &mode); ++ optype = get_rsa_optype(options->optype); ++ } else if (algtype <= DH_4096) { ++ get_dh_param(algtype, &keysize); ++ optype = get_dh_optype(options->optype); ++ } else if (algtype <= X448_ALG) { ++ get_ecc_param(algtype, &keysize); ++ optype = get_ecc_optype(options->subtype, options->optype); ++ } else { ++ HPRE_TST_PRT("failed to set hpre alg!\n"); ++ return -EINVAL; ++ } ++ ++ if (optype == ERR_OPTYPE) ++ return -EINVAL; ++ ++ /* HPRE package length is keybits */ ++ options->pktlen = keysize >> 3; ++ tddata->keybits = keysize; ++ tddata->kmode = mode; ++ tddata->optype = optype; ++ ++ HPRE_TST_PRT("%s to run %s task!\n", options->algclass, ++ alg_operations[options->optype]); ++ ++ return 0; ++} ++ ++static int hpre_wd_get_block(u32 algtype) ++{ ++ int block_size = 512; ++ ++ switch(algtype) { ++ case RSA_1024: ++ block_size = 1280; ++ break; ++ case RSA_2048: ++ block_size = 2560; ++ break; ++ case RSA_3072: ++ block_size = 3840; ++ break; ++ case RSA_4096: ++ block_size = 5120; ++ break; ++ case RSA_1024_CRT: ++ block_size = 1280; ++ break; ++ case RSA_2048_CRT: ++ block_size = 2560; ++ break; ++ case RSA_3072_CRT: ++ block_size = 3840; ++ break; ++ case RSA_4096_CRT: ++ block_size = 5120; ++ break; ++ case DH_768: ++ block_size = 1536; ++ break; ++ case DH_1024: ++ block_size = 2048; ++ break; ++ case DH_1536: ++ block_size = 3072; ++ break; ++ case DH_2048: ++ block_size = 4096; ++ break; ++ case DH_3072: ++ block_size = 6144; ++ break; ++ case DH_4096: ++ block_size = 8192; ++ break; ++ case ECDH_256: ++ block_size = 256; ++ break; ++ case ECDH_384: ++ block_size = 384; ++ break; ++ case ECDH_521: ++ block_size = 576; ++ break; ++ case ECDSA_256: ++ block_size = 256; ++ break; ++ case ECDSA_384: ++ block_size = 384; ++ break; ++ case ECDSA_521: ++ block_size = 576; ++ break; ++ case SM2_ALG: ++ block_size = 4352; ++ break; ++ case X25519_ALG: ++ block_size = 256; ++ break; ++ case X448_ALG: ++ block_size = 384; ++ break; ++ } ++ ++ return block_size; ++} ++ ++static int init_hpre_wd_queue(struct acc_option *options) ++{ ++ u32 blocksize = hpre_wd_get_block(options->algtype); ++ struct wd_blkpool_setup blksetup; ++ int i, j, ret; ++ ++ g_thread_queue.bd_res = malloc(g_thread_num * sizeof(struct thread_bd_res)); ++ if (!g_thread_queue.bd_res) { ++ HPRE_TST_PRT("malloc thread res memory fail!\n"); ++ return -ENOMEM; ++ } ++ ++ for (i = 0; i < g_thread_num; i++) { ++ g_thread_queue.bd_res[i].queue = malloc(sizeof(struct wd_queue)); ++ g_thread_queue.bd_res[i].queue->capa.alg = options->algclass; ++ // 0 is ENC, 1 is DEC ++ g_thread_queue.bd_res[i].queue->capa.priv.direction = options->optype; ++ /* nodemask need to be clean */ ++ g_thread_queue.bd_res[i].queue->node_mask = 0x0; ++ memset(g_thread_queue.bd_res[i].queue->dev_path, 0x0, PATH_STR_SIZE); ++ ++ ret = wd_request_queue(g_thread_queue.bd_res[i].queue); ++ if (ret) { ++ HPRE_TST_PRT("request queue %d fail!\n", i); ++ goto queue_out; ++ } ++ } ++ ++ // use no-sva pbuffer, MAX_BLOCK_NM at least 4 times of thread inside alloc ++ memset(&blksetup, 0, sizeof(blksetup)); ++ blksetup.block_size = blocksize; ++ blksetup.block_num = MAX_BLOCK_NM; ++ blksetup.align_size = ALIGN_SIZE; ++ // HPRE_TST_PRT("create pool memory: %d KB\n", (MAX_BLOCK_NM * blksetup.block_size) >> 10); ++ ++ for (j = 0; j < g_thread_num; j++) { ++ g_thread_queue.bd_res[j].pool = wd_blkpool_create(g_thread_queue.bd_res[j].queue, &blksetup); ++ if (!g_thread_queue.bd_res[j].pool) { ++ HPRE_TST_PRT("create %dth pool fail!\n", j); ++ ret = -ENOMEM; ++ goto pool_err; ++ } ++ } ++ ++ return 0; ++ ++pool_err: ++ for (j--; j >= 0; j--) ++ wd_blkpool_destroy(g_thread_queue.bd_res[j].pool); ++queue_out: ++ for (i--; i >= 0; i--) { ++ wd_release_queue(g_thread_queue.bd_res[i].queue); ++ free(g_thread_queue.bd_res[i].queue); ++ } ++ free(g_thread_queue.bd_res); ++ return ret; ++} ++ ++static void uninit_hpre_wd_queue(void) ++{ ++ int j; ++ ++ for (j = 0; j < g_thread_num; j++) { ++ wd_blkpool_destroy(g_thread_queue.bd_res[j].pool); ++ wd_release_queue(g_thread_queue.bd_res[j].queue); ++ } ++ ++ free(g_thread_queue.bd_res); ++} ++ ++/*-------------------------------uadk benchmark main code-------------------------------------*/ ++ ++void *hpre_wd_poll(void *data) ++{ ++ typedef int (*poll_ctx)(struct wd_queue *q, unsigned int num); ++ thread_data *pdata = (thread_data *)data; ++ u32 expt = ACC_QUEUE_SIZE * g_thread_num; ++ poll_ctx wd_poll_ctx = NULL; ++ struct wd_queue *queue; ++ u32 id = pdata->td_id; ++ u32 last_time = 2; // poll need one more recv time ++ u32 count = 0; ++ int recv = 0; ++ ++ if (id > g_thread_num) ++ return NULL; ++ ++ queue = g_thread_queue.bd_res[id].queue; ++ switch(pdata->subtype) { ++ case RSA_TYPE: ++ wd_poll_ctx = wcrypto_rsa_poll; ++ break; ++ case DH_TYPE: ++ wd_poll_ctx = wcrypto_dh_poll; ++ break; ++ case ECDH_TYPE: ++ case X25519_TYPE: ++ case X448_TYPE: ++ wd_poll_ctx = wcrypto_ecxdh_poll; ++ break; ++ case ECDSA_TYPE: ++ wd_poll_ctx = wcrypto_ecdsa_poll; ++ break; ++ case SM2_TYPE: ++ wd_poll_ctx = wcrypto_sm2_poll; ++ break; ++ default: ++ HPRE_TST_PRT("wd async poll interface is NULL!\n"); ++ return NULL; ++ } ++ ++ while (last_time) { ++ recv = wd_poll_ctx(queue, expt); ++ /* ++ * warpdrive async mode poll easy to 100% with small package. ++ * SEC_TST_PRT("warpdrive poll %d recv: %u!\n", i, recv); ++ */ ++ ++ if (unlikely(recv < 0)) { ++ HPRE_TST_PRT("poll ret: %u!\n", recv); ++ goto recv_error; ++ } ++ count += recv; ++ recv = 0; ++ ++ if (get_run_state() == 0) ++ last_time--; ++ } ++ ++recv_error: ++ add_recv_data(count, pdata->keybits >> 3); ++ ++ return NULL; ++} ++ ++static int get_rsa_key_from_sample(void *ctx, char *privkey_file, ++ char *crt_privkey_file, u32 key_bits, u32 is_crt) ++{ ++ struct wd_dtb wd_e, wd_d, wd_n, wd_dq, wd_dp, wd_qinv, wd_q, wd_p; ++ int e_bytes, d_bytes, n_bytes, q_bytes, p_bytes, qinv_bytes; ++ u8 *p, *q, *n, *e, *d, *dmp1, *dmq1, *iqmp; ++ int dq_bytes, dp_bytes, bits, wd_lenth; ++ u32 key_size = key_bits >> 3; ++ char *wd_mem; ++ int ret = 0; ++ ++ memset(&wd_e, 0, sizeof(wd_e)); ++ memset(&wd_d, 0, sizeof(wd_d)); ++ memset(&wd_n, 0, sizeof(wd_n)); ++ memset(&wd_dq, 0, sizeof(wd_dq)); ++ memset(&wd_dp, 0, sizeof(wd_dp)); ++ memset(&wd_qinv, 0, sizeof(wd_qinv)); ++ memset(&wd_q, 0, sizeof(wd_q)); ++ memset(&wd_p, 0, sizeof(wd_p)); ++ ++ bits = wcrypto_rsa_key_bits(ctx); ++ switch (bits) { ++ case 1024: ++ e = rsa_e_1024; ++ n = rsa_n_1024; ++ p = rsa_p_1024; ++ q = rsa_q_1024; ++ dmp1 = rsa_dp_1024; ++ dmq1 = rsa_dq_1024; ++ iqmp = rsa_qinv_1024; ++ d = rsa_d_1024; ++ e_bytes = ARRAY_SIZE(rsa_e_1024); ++ n_bytes = ARRAY_SIZE(rsa_n_1024); ++ q_bytes = ARRAY_SIZE(rsa_q_1024); ++ p_bytes = ARRAY_SIZE(rsa_p_1024); ++ dq_bytes = ARRAY_SIZE(rsa_dq_1024); ++ dp_bytes = ARRAY_SIZE(rsa_dp_1024); ++ qinv_bytes = ARRAY_SIZE(rsa_qinv_1024); ++ d_bytes = ARRAY_SIZE(rsa_d_1024); ++ break; ++ case 2048: ++ e = rsa_e_2048; ++ n = rsa_n_2048; ++ p = rsa_p_2048; ++ q = rsa_q_2048; ++ dmp1 = rsa_dp_2048; ++ dmq1 = rsa_dq_2048; ++ iqmp = rsa_qinv_2048; ++ d = rsa_d_2048; ++ e_bytes = ARRAY_SIZE(rsa_e_2048); ++ n_bytes = ARRAY_SIZE(rsa_n_2048); ++ q_bytes = ARRAY_SIZE(rsa_q_2048); ++ p_bytes = ARRAY_SIZE(rsa_p_2048); ++ dq_bytes = ARRAY_SIZE(rsa_dq_2048); ++ dp_bytes = ARRAY_SIZE(rsa_dp_2048); ++ qinv_bytes = ARRAY_SIZE(rsa_qinv_2048); ++ d_bytes = ARRAY_SIZE(rsa_d_2048); ++ break; ++ case 3072: ++ e = rsa_e_3072; ++ n = rsa_n_3072; ++ p = rsa_p_3072; ++ q = rsa_q_3072; ++ dmp1 = rsa_dp_3072; ++ dmq1 = rsa_dq_3072; ++ iqmp = rsa_qinv_3072; ++ d = rsa_d_3072; ++ e_bytes = ARRAY_SIZE(rsa_e_3072); ++ n_bytes = ARRAY_SIZE(rsa_n_3072); ++ q_bytes = ARRAY_SIZE(rsa_q_3072); ++ p_bytes = ARRAY_SIZE(rsa_p_3072); ++ dq_bytes = ARRAY_SIZE(rsa_dq_3072); ++ dp_bytes = ARRAY_SIZE(rsa_dp_3072); ++ qinv_bytes = ARRAY_SIZE(rsa_qinv_3072); ++ d_bytes = ARRAY_SIZE(rsa_d_3072); ++ break; ++ case 4096: ++ e = rsa_e_4096; ++ n = rsa_n_4096; ++ p = rsa_p_4096; ++ q = rsa_q_4096; ++ dmp1 = rsa_dp_4096; ++ dmq1 = rsa_dq_4096; ++ iqmp = rsa_qinv_4096; ++ d = rsa_d_4096; ++ e_bytes = ARRAY_SIZE(rsa_e_4096); ++ n_bytes = ARRAY_SIZE(rsa_n_4096); ++ q_bytes = ARRAY_SIZE(rsa_q_4096); ++ p_bytes = ARRAY_SIZE(rsa_p_4096); ++ dq_bytes = ARRAY_SIZE(rsa_dq_4096); ++ dp_bytes = ARRAY_SIZE(rsa_dp_4096); ++ qinv_bytes = ARRAY_SIZE(rsa_qinv_4096); ++ d_bytes = ARRAY_SIZE(rsa_d_4096); ++ break; ++ default: ++ HPRE_TST_PRT("invalid key bits = %d!\n", bits); ++ return -EINVAL; ++ } ++ ++ wd_lenth = e_bytes + n_bytes + q_bytes + p_bytes + dq_bytes + ++ dp_bytes + qinv_bytes + d_bytes; ++ wd_mem = malloc(wd_lenth); ++ if (!wd_mem) { ++ HPRE_TST_PRT("failed to alloc rsa key memory!\n"); ++ return -EINVAL; ++ } ++ ++ wd_e.data = wd_mem; ++ wd_n.data = wd_e.data + e_bytes; ++ ++ memcpy(wd_e.data, e, e_bytes); ++ wd_e.dsize = e_bytes; ++ memcpy(wd_n.data, n, n_bytes); ++ wd_n.dsize = n_bytes; ++ if (wcrypto_set_rsa_pubkey_params(ctx, &wd_e, &wd_n)) { ++ HPRE_TST_PRT("failed to set rsa pubkey!\n"); ++ ret = -EINVAL; ++ goto gen_fail; ++ } ++ ++ if (rsa_key_in) { ++ memcpy(rsa_key_in->e, e, e_bytes); ++ memcpy(rsa_key_in->p, p, p_bytes); ++ memcpy(rsa_key_in->q, q, q_bytes); ++ rsa_key_in->e_size = e_bytes; ++ rsa_key_in->p_size = p_bytes; ++ rsa_key_in->q_size = q_bytes; ++ } ++ ++ if (is_crt) { ++ wd_q.data = wd_n.data + n_bytes; ++ wd_p.data = wd_q.data + q_bytes; ++ wd_dq.data = wd_p.data + p_bytes; ++ wd_dp.data = wd_dq.data + dq_bytes; ++ wd_qinv.data = wd_dp.data + dp_bytes; ++ ++ /* CRT mode private key */ ++ wd_dq.dsize = dq_bytes; ++ memcpy(wd_dq.data, dmq1, dq_bytes); ++ ++ wd_dp.dsize = dp_bytes; ++ memcpy(wd_dp.data, dmp1, dp_bytes); ++ ++ wd_q.dsize = q_bytes; ++ memcpy(wd_q.data, q, q_bytes); ++ ++ wd_p.dsize = p_bytes; ++ memcpy(wd_p.data, p, p_bytes); ++ ++ wd_qinv.dsize = qinv_bytes; ++ memcpy(wd_qinv.data, iqmp, qinv_bytes); ++ ++ if (wcrypto_set_rsa_crt_prikey_params(ctx, &wd_dq, ++ &wd_dp, &wd_qinv, ++ &wd_q, &wd_p)) { ++ HPRE_TST_PRT("failed to set rsa crt prikey!\n"); ++ ret = -EINVAL; ++ goto gen_fail; ++ } ++ ++ ++ if (crt_privkey_file) { ++ memcpy(crt_privkey_file, wd_dq.data, (key_bits >> 4) * 5); ++ memcpy(crt_privkey_file + (key_bits >> 4) * 5, ++ wd_e.data, (key_bits >> 2)); ++ } ++ ++ } else { ++ //wd_rsa_get_prikey_params(prikey, &wd_d, &wd_n); ++ wd_d.data = wd_mem + (wd_lenth - d_bytes); ++ ++ /* common mode private key */ ++ wd_d.dsize = d_bytes; ++ memcpy(wd_d.data, d, d_bytes); ++ ++ if (wcrypto_set_rsa_prikey_params(ctx, &wd_d, &wd_n)) { ++ HPRE_TST_PRT("failed to set rsa prikey!\n"); ++ ret = -EINVAL; ++ goto gen_fail; ++ } ++ ++ if (privkey_file) { ++ memcpy(privkey_file, wd_d.data, key_size); ++ memcpy(privkey_file + key_size, wd_n.data, key_size); ++ memcpy(privkey_file + 2 * key_size, wd_e.data, key_size); ++ memcpy(privkey_file + 3 * key_size, wd_n.data, key_size); ++ } ++ } ++ ++gen_fail: ++ free(wd_mem); ++ ++ return ret; ++} ++ ++static int get_hpre_keygen_opdata(void *ctx, ++ struct wcrypto_rsa_op_data *opdata) ++{ ++ struct wcrypto_rsa_pubkey *pubkey; ++ struct wcrypto_rsa_prikey *prikey; ++ struct wd_dtb t_e, t_p, t_q; ++ struct wd_dtb *e, *p, *q; ++ ++ wcrypto_get_rsa_pubkey(ctx, &pubkey); ++ wcrypto_get_rsa_pubkey_params(pubkey, &e, NULL); ++ wcrypto_get_rsa_prikey(ctx, &prikey); ++ ++ if (wcrypto_rsa_is_crt(ctx)) { ++ wcrypto_get_rsa_crt_prikey_params(prikey, NULL , NULL, NULL, &q, &p); ++ } else { ++ e = &t_e; ++ p = &t_p; ++ q = &t_q; ++ e->data = rsa_key_in->e; ++ e->dsize = rsa_key_in->e_size; ++ p->data = rsa_key_in->p; ++ p->dsize = rsa_key_in->p_size; ++ q->data = rsa_key_in->q; ++ q->dsize = rsa_key_in->q_size; ++ } ++ ++ opdata->in = wcrypto_new_kg_in(ctx, e, p, q); ++ if (!opdata->in) { ++ HPRE_TST_PRT("failed to create rsa kgen in!\n"); ++ return -ENOMEM; ++ } ++ opdata->out = wcrypto_new_kg_out(ctx); ++ if (!opdata->out) { ++ HPRE_TST_PRT("failed to create rsa kgen out!\n"); ++ wcrypto_del_kg_in(ctx, opdata->in); ++ return -ENOMEM; ++ } ++ ++ return 0; ++} ++ ++static void *rsa_wd_sync_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ int key_size = pdata->keybits >> 3; ++ struct wcrypto_rsa_ctx_setup setup; ++ struct wcrypto_rsa_op_data opdata; ++ struct wd_queue *queue; ++ void *key_info = NULL; ++ void *ctx = NULL; ++ void *tag = NULL; ++ void *pool; ++ u32 count = 0; ++ int ret; ++ ++ memset(&setup, 0, sizeof(setup)); ++ memset(&opdata, 0, sizeof(opdata)); ++ pool = g_thread_queue.bd_res[pdata->td_id].pool; ++ queue = g_thread_queue.bd_res[pdata->td_id].queue; ++ ++ setup.br.alloc = (void *)wd_alloc_blk; ++ setup.br.free = (void *)wd_free_blk; ++ setup.br.iova_map = (void *)wd_blk_iova_map; ++ setup.br.iova_unmap = (void *)wd_blk_iova_unmap; ++ setup.br.get_bufsize = (void *)wd_blksize; ++ setup.br.usr = pool; ++ setup.key_bits = pdata->keybits; ++ setup.is_crt = pdata->kmode; ++ ++ ctx = wcrypto_create_rsa_ctx(queue, &setup); ++ if (!ctx) ++ return NULL; ++ ++ key_info = malloc(key_size * 16); ++ if (!key_info) { ++ HPRE_TST_PRT("failed to alloc RSA key info!\n"); ++ return NULL; ++ } ++ memset(key_info, 0, key_size * 16); ++ ++ rsa_key_in = malloc(2 * key_size + sizeof(struct hpre_rsa_key_in)); ++ if (!rsa_key_in) { ++ HPRE_TST_PRT("failed to alloc RSA key input param!\n"); ++ goto key_release; ++ } ++ rsa_key_in->e = rsa_key_in + 1; ++ rsa_key_in->p = rsa_key_in->e + key_size; ++ rsa_key_in->q = rsa_key_in->p + (key_size >> 1); ++ ++ ret = get_rsa_key_from_sample(ctx, key_info, key_info, ++ pdata->keybits, pdata->kmode); ++ if (ret) { ++ HPRE_TST_PRT("failed to get sample key data!\n"); ++ goto sample_release; ++ } ++ ++ opdata.in_bytes = key_size; ++ opdata.out_bytes = key_size; ++ opdata.op_type = pdata->optype; ++ if (opdata.op_type == WCRYPTO_RSA_GENKEY) { ++ ret = get_hpre_keygen_opdata(ctx, &opdata); ++ if (ret){ ++ HPRE_TST_PRT("failed to fill rsa key gen req!\n"); ++ goto sample_release; ++ } ++ } else { ++ opdata.in = wd_alloc_blk(pool); ++ if (!opdata.in) { ++ HPRE_TST_PRT("failed to alloc rsa in buffer!\n"); ++ goto sample_release; ++ } ++ memset(opdata.in, 0, opdata.in_bytes); ++ memcpy(opdata.in + key_size - sizeof(rsa_m), rsa_m, sizeof(rsa_m)); ++ ++ opdata.out = wd_alloc_blk(pool); ++ if (!opdata.out) { ++ HPRE_TST_PRT("failed to alloc rsa out buffer!\n"); ++ goto in_release; ++ } ++ } ++ ++ do { ++ ret = wcrypto_do_rsa(ctx, &opdata, tag); ++ if (ret || opdata.status) { ++ HPRE_TST_PRT("failed to do rsa task, status: %d\n", opdata.status); ++ goto out_release; ++ } ++ ++ count++; ++ if (get_run_state() == 0) ++ break; ++ } while(true); ++ ++ /* clean output buffer remainings in the last time operation */ ++ if (opdata.op_type == WCRYPTO_RSA_GENKEY) { ++ char *data; ++ int len; ++ ++ len = wcrypto_rsa_kg_out_data((void *)opdata.out, &data); ++ if (len < 0) { ++ HPRE_TST_PRT("failed to wd rsa get key gen out data!\n"); ++ goto out_release; ++ } ++ memset(data, 0, len); ++ ++ wcrypto_del_kg_in(ctx, opdata.in); ++ opdata.in = NULL; ++ wcrypto_del_kg_out(ctx, opdata.out); ++ opdata.out = NULL; ++ } ++ ++out_release: ++ if (opdata.out) ++ wd_free_blk(pool, opdata.out); ++in_release: ++ if (opdata.in) ++ wd_free_blk(pool, opdata.in); ++sample_release: ++ free(rsa_key_in); ++key_release: ++ free(key_info); ++ ++ wcrypto_del_rsa_ctx(ctx); ++ add_recv_data(count, key_size); ++ ++ return NULL; ++} ++ ++static void rsa_async_cb(const void *msg, void *tag) ++{ ++ //struct wcrypto_rsa_msg *massage = msg; ++ //struct rsa_async_tag *ptag = tag; ++ //u32 op_type = tag->op_type; ++ //void *ctx = tag->ctx; ++ ++ return; ++} ++ ++static void *rsa_wd_async_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ int key_size = pdata->keybits >> 3; ++ struct wcrypto_rsa_ctx_setup setup; ++ struct wcrypto_rsa_op_data opdata; ++ struct rsa_async_tag *tag = NULL; ++ struct wd_queue *queue; ++ void *key_info = NULL; ++ void *ctx = NULL; ++ int try_cnt = 0; ++ void *pool; ++ u32 count = 0; ++ int i, ret; ++ ++ memset(&setup, 0, sizeof(setup)); ++ memset(&opdata, 0, sizeof(opdata)); ++ pool = g_thread_queue.bd_res[pdata->td_id].pool; ++ queue = g_thread_queue.bd_res[pdata->td_id].queue; ++ ++ setup.cb = (void *)rsa_async_cb; ++ setup.br.alloc = (void *)wd_alloc_blk; ++ setup.br.free = (void *)wd_free_blk; ++ setup.br.iova_map = (void *)wd_blk_iova_map; ++ setup.br.iova_unmap = (void *)wd_blk_iova_unmap; ++ setup.br.get_bufsize = (void *)wd_blksize; ++ setup.br.usr = pool; ++ setup.key_bits = pdata->keybits; ++ setup.is_crt = pdata->kmode; ++ ++ ctx = wcrypto_create_rsa_ctx(queue, &setup); ++ if (!ctx) ++ return NULL; ++ ++ key_info = malloc(key_size * 16); ++ if (!key_info) { ++ HPRE_TST_PRT("failed to alloc RSA key info!\n"); ++ return NULL; ++ } ++ memset(key_info, 0, key_size * 16); ++ ++ rsa_key_in = malloc(2 * key_size + sizeof(struct hpre_rsa_key_in)); ++ if (!rsa_key_in) { ++ HPRE_TST_PRT("failed to alloc RSA key input param!\n"); ++ goto key_release; ++ } ++ rsa_key_in->e = rsa_key_in + 1; ++ rsa_key_in->p = rsa_key_in->e + key_size; ++ rsa_key_in->q = rsa_key_in->p + (key_size >> 1); ++ ++ ret = get_rsa_key_from_sample(ctx, key_info, key_info, ++ pdata->keybits, pdata->kmode); ++ if (ret) { ++ HPRE_TST_PRT("failed to get sample key data!\n"); ++ goto sample_release; ++ } ++ ++ opdata.in_bytes = key_size; ++ opdata.out_bytes = key_size; ++ opdata.op_type = pdata->optype; ++ if (opdata.op_type == WCRYPTO_RSA_GENKEY) { ++ ret = get_hpre_keygen_opdata(ctx, &opdata); ++ if (ret){ ++ HPRE_TST_PRT("failed to fill rsa key gen req!\n"); ++ goto sample_release; ++ } ++ } else { ++ opdata.in = wd_alloc_blk(pool); ++ if (!opdata.in) { ++ HPRE_TST_PRT("failed to alloc rsa in buffer!\n"); ++ goto sample_release; ++ } ++ memset(opdata.in, 0, opdata.in_bytes); ++ memcpy(opdata.in + key_size - sizeof(rsa_m), rsa_m, sizeof(rsa_m)); ++ ++ opdata.out = wd_alloc_blk(pool); ++ if (!opdata.out) { ++ HPRE_TST_PRT("failed to alloc rsa out buffer!\n"); ++ goto in_release; ++ } ++ } ++ ++ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); ++ if (!tag) { ++ HPRE_TST_PRT("failed to malloc rsa tag!\n"); ++ goto out_release; ++ } ++ ++ do { ++ if (get_run_state() == 0) ++ break; ++ ++ try_cnt = 0; ++ i = count % MAX_POOL_LENTH; ++ tag[i].ctx = ctx; ++ tag[i].cnt = i; ++ tag[i].optype = opdata.op_type; ++ ++ ret = wcrypto_do_rsa(ctx, &opdata, &tag[i]); ++ if (ret == -WD_EBUSY) { ++ usleep(SEND_USLEEP * try_cnt); ++ try_cnt++; ++ if (try_cnt > MAX_TRY_CNT) { ++ HPRE_TST_PRT("Test RSA send fail %d times!\n", MAX_TRY_CNT); ++ try_cnt = 0; ++ } ++ continue; ++ } else if (ret) { ++ HPRE_TST_PRT("failed to do rsa async task!\n"); ++ goto tag_release; ++ } ++ count++; ++ } while(true); ++ ++ /* clean output buffer remainings in the last time operation */ ++ if (opdata.op_type == WCRYPTO_RSA_GENKEY) { ++ char *data; ++ int len; ++ ++ len = wcrypto_rsa_kg_out_data((void *)opdata.out, &data); ++ if (len < 0) { ++ HPRE_TST_PRT("failed to wd rsa get key gen out data!\n"); ++ goto out_release; ++ } ++ memset(data, 0, len); ++ ++ wcrypto_del_kg_in(ctx, opdata.in); ++ opdata.in = NULL; ++ wcrypto_del_kg_out(ctx, opdata.out); ++ opdata.out = NULL; ++ } ++ ++tag_release: ++ free(tag); ++out_release: ++ if (opdata.out) ++ wd_free_blk(pool, opdata.out); ++in_release: ++ if (opdata.in) ++ wd_free_blk(pool, opdata.in); ++sample_release: ++ free(rsa_key_in); ++key_release: ++ free(key_info); ++ ++ while (1) { ++ if (get_recv_time() > 0) // wait Async mode finish recv ++ break; ++ usleep(SEND_USLEEP); ++ } ++ wcrypto_del_rsa_ctx(ctx); ++ ++ add_send_complete(); ++ ++ return NULL; ++} ++ ++static int get_dh_param_from_sample(struct hpre_dh_param *setup, ++ u32 key_bits, u8 is_g2) ++{ ++ setup->key_bits = key_bits; ++ ++ switch (key_bits) { ++ case 768: ++ setup->x = dh_xa_768; ++ setup->p = dh_p_768; ++ setup->except_pub_key = dh_except_b_pubkey_768; ++ setup->pub_key = dh_except_a_pubkey_768; ++ setup->share_key = dh_share_key_768; ++ setup->x_size = sizeof(dh_xa_768); ++ setup->p_size = sizeof(dh_p_768); ++ setup->except_pub_key_size = sizeof(dh_except_b_pubkey_768); ++ setup->pub_key_size = sizeof(dh_except_a_pubkey_768); ++ setup->share_key_size = sizeof(dh_share_key_768); ++ break; ++ case 1024: ++ setup->x = dh_xa_1024; ++ setup->p = dh_p_1024; ++ setup->except_pub_key = dh_except_b_pubkey_1024; ++ setup->pub_key = dh_except_a_pubkey_1024; ++ setup->share_key = dh_share_key_1024; ++ setup->x_size = sizeof(dh_xa_1024); ++ setup->p_size = sizeof(dh_p_1024); ++ setup->except_pub_key_size = sizeof(dh_except_b_pubkey_1024); ++ setup->pub_key_size = sizeof(dh_except_a_pubkey_1024); ++ setup->share_key_size = sizeof(dh_share_key_1024); ++ break; ++ case 1536: ++ setup->x = dh_xa_1536; ++ setup->p = dh_p_1536; ++ setup->except_pub_key = dh_except_b_pubkey_1536; ++ setup->pub_key = dh_except_a_pubkey_1536; ++ setup->share_key = dh_share_key_1536; ++ setup->x_size = sizeof(dh_xa_1536); ++ setup->p_size = sizeof(dh_p_1536); ++ setup->except_pub_key_size = sizeof(dh_except_b_pubkey_1536); ++ setup->pub_key_size = sizeof(dh_except_a_pubkey_1536); ++ setup->share_key_size = sizeof(dh_share_key_1536); ++ break; ++ case 2048: ++ setup->x = dh_xa_2048; ++ setup->p = dh_p_2048; ++ setup->except_pub_key = dh_except_b_pubkey_2048; ++ setup->pub_key = dh_except_a_pubkey_2048; ++ setup->share_key = dh_share_key_2048; ++ setup->x_size = sizeof(dh_xa_2048); ++ setup->p_size = sizeof(dh_p_2048); ++ setup->except_pub_key_size = sizeof(dh_except_b_pubkey_2048); ++ setup->pub_key_size = sizeof(dh_except_a_pubkey_2048); ++ setup->share_key_size = sizeof(dh_share_key_2048); ++ break; ++ case 3072: ++ setup->x = dh_xa_3072; ++ setup->p = dh_p_3072; ++ setup->except_pub_key = dh_except_b_pubkey_3072; ++ setup->pub_key = dh_except_a_pubkey_3072; ++ setup->share_key = dh_share_key_3072; ++ setup->x_size = sizeof(dh_xa_3072); ++ setup->p_size = sizeof(dh_p_3072); ++ setup->except_pub_key_size = sizeof(dh_except_b_pubkey_3072); ++ setup->pub_key_size = sizeof(dh_except_a_pubkey_3072); ++ setup->share_key_size = sizeof(dh_share_key_3072); ++ break; ++ case 4096: ++ setup->x = dh_xa_4096; ++ setup->p = dh_p_4096; ++ setup->except_pub_key = dh_except_b_pubkey_4096; ++ setup->pub_key = dh_except_a_pubkey_4096; ++ setup->share_key = dh_share_key_4096; ++ setup->x_size = sizeof(dh_xa_4096); ++ setup->p_size = sizeof(dh_p_4096); ++ setup->except_pub_key_size = sizeof(dh_except_b_pubkey_4096); ++ setup->pub_key_size = sizeof(dh_except_a_pubkey_4096); ++ setup->share_key_size = sizeof(dh_share_key_4096); ++ break; ++ default: ++ HPRE_TST_PRT("failed to find dh keybits %u\n", key_bits); ++ return -EINVAL; ++ } ++ ++ if (is_g2) { ++ setup->g = dh_g_2; ++ } else { ++ setup->g = dh_g_5; ++ } ++ setup->g_size = 1; ++ ++ return 0; ++} ++ ++static int get_dh_opdata_param(void *ctx, struct wcrypto_dh_op_data *opdata, ++ struct hpre_dh_param *setup, int key_size) ++{ ++ unsigned char *ag_bin = NULL; ++ void *pool = setup->pool; ++ struct wd_dtb ctx_g; ++ int ret; ++ ++ ag_bin = wd_alloc_blk(pool); ++ if (!ag_bin) ++ return -ENOMEM; ++ ++ memset(ag_bin, 0, 2 * key_size); ++ opdata->pv = ag_bin; ++ ++ opdata->x_p = wd_alloc_blk(pool); ++ if (!opdata->x_p) ++ goto ag_error; ++ ++ memset(opdata->x_p, 0, 2 * key_size); ++ ++ opdata->pri = wd_alloc_blk(pool); ++ if (!opdata->pri) ++ goto xp_error; ++ ++ memset(opdata->pri, 0, 2 * key_size); ++ opdata->pri_bytes = 2 * key_size; ++ ++ ctx_g.data = malloc(key_size); ++ if (!ctx_g.data) ++ goto ctx_release; ++ ++ if (setup->optype == WCRYPTO_DH_PHASE1) { // GEN1 ++ memcpy(opdata->x_p, setup->x, setup->x_size); ++ memcpy(opdata->x_p + key_size, setup->p, setup->p_size); ++ memcpy(ctx_g.data, setup->g, setup->g_size); ++ opdata->pbytes = setup->p_size; ++ opdata->xbytes = setup->x_size; ++ ctx_g.dsize = setup->g_size; ++ ctx_g.bsize = key_size; ++ ++ ret = wcrypto_set_dh_g(ctx, &ctx_g); ++ if (ret) ++ HPRE_TST_PRT("wd_dh_set_g run failed\n"); ++ } else { // GEN1 ++ memcpy(opdata->x_p, setup->x, setup->x_size); ++ memcpy(opdata->x_p + key_size, setup->p, setup->p_size); ++ memcpy(opdata->pv, setup->except_pub_key, setup->except_pub_key_size); ++ opdata->pbytes = setup->p_size; ++ opdata->xbytes = setup->x_size; ++ opdata->pvbytes = setup->except_pub_key_size; ++ } ++ ++ free(ctx_g.data); ++ ++ return 0; ++ ++ctx_release: ++ wd_free_blk(pool, opdata->pri); ++xp_error: ++ wd_free_blk(pool, opdata->x_p); ++ag_error: ++ wd_free_blk(pool, opdata->pv); ++ ++ return -ENOMEM; ++} ++ ++static void *dh_wd_sync_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ int key_size = pdata->keybits >> 3; ++ struct wcrypto_dh_ctx_setup dh_setup; ++ struct wcrypto_dh_op_data opdata; ++ struct hpre_dh_param setup; ++ struct wd_queue *queue; ++ void *ctx = NULL; ++ void *tag = NULL; ++ void *pool; ++ u32 count = 0; ++ int ret; ++ ++ memset(&dh_setup, 0, sizeof(dh_setup)); ++ memset(&opdata, 0, sizeof(opdata)); ++ ++ pool = g_thread_queue.bd_res[pdata->td_id].pool; ++ queue = g_thread_queue.bd_res[pdata->td_id].queue; ++ dh_setup.key_bits = pdata->keybits; ++ dh_setup.br.alloc = (void *)wd_alloc_blk; ++ dh_setup.br.free = (void *)wd_free_blk; ++ dh_setup.br.iova_map = (void *)wd_blk_iova_map; ++ dh_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; ++ dh_setup.br.get_bufsize = (void *)wd_blksize; ++ dh_setup.br.usr = pool; ++ if (pdata->optype == WCRYPTO_DH_PHASE2) ++ dh_setup.is_g2 = true; // G1 is 0; G2 is 1; ++ ++ ctx = wcrypto_create_dh_ctx(queue, &dh_setup); ++ if (!ctx) ++ return NULL; ++ ++ ret = get_dh_param_from_sample(&setup, pdata->keybits, pdata->kmode); ++ if (ret) ++ goto ctx_release; ++ ++ setup.optype = pdata->optype; ++ setup.pool = pool; ++ opdata.op_type = pdata->optype; ++ ret = get_dh_opdata_param(ctx, &opdata, &setup, key_size); ++ if (ret){ ++ HPRE_TST_PRT("failed to fill dh key gen req!\n"); ++ goto param_release; ++ } ++ ++ do { ++ ret = wcrypto_do_dh(ctx, &opdata, tag); ++ if (ret || opdata.status) { ++ HPRE_TST_PRT("failed to do dh task, status: %d\n", opdata.status); ++ goto param_release; ++ } ++ ++ count++; ++ if (get_run_state() == 0) ++ break; ++ } while(true); ++ ++param_release: ++ wd_free_blk(pool, opdata.x_p); ++ wd_free_blk(pool, opdata.pv); ++ wd_free_blk(pool, opdata.pri); ++ctx_release: ++ wcrypto_del_dh_ctx(ctx); ++ add_recv_data(count, key_size); ++ ++ return NULL; ++} ++ ++static void dh_async_cb(const void *msg, void *tag) ++{ ++ //struct wcrypto_dh_msg *massage = msg; ++ //struct rsa_async_tag *ptag = tag; ++ //u32 op_type = tag->op_type; ++ //void *ctx = tag->ctx; ++ ++ return; ++} ++ ++static void *dh_wd_async_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ int key_size = pdata->keybits >> 3; ++ struct wcrypto_dh_ctx_setup dh_setup; ++ struct wcrypto_dh_op_data opdata; ++ struct rsa_async_tag *tag = NULL; ++ struct hpre_dh_param setup; ++ struct wd_queue *queue; ++ void *ctx = NULL; ++ int try_cnt = 0; ++ void *pool; ++ u32 count = 0; ++ int i, ret; ++ ++ memset(&dh_setup, 0, sizeof(dh_setup)); ++ memset(&opdata, 0, sizeof(opdata)); ++ ++ pool = g_thread_queue.bd_res[pdata->td_id].pool; ++ queue = g_thread_queue.bd_res[pdata->td_id].queue; ++ dh_setup.key_bits = pdata->keybits; ++ dh_setup.br.alloc = (void *)wd_alloc_blk; ++ dh_setup.br.free = (void *)wd_free_blk; ++ dh_setup.br.iova_map = (void *)wd_blk_iova_map; ++ dh_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; ++ dh_setup.br.get_bufsize = (void *)wd_blksize; ++ dh_setup.cb = (void *)dh_async_cb; ++ dh_setup.br.usr = pool; ++ if (pdata->optype == WCRYPTO_DH_PHASE2) ++ dh_setup.is_g2 = true; // G1 is 0; G2 is 1; ++ ++ ctx = wcrypto_create_dh_ctx(queue, &dh_setup); ++ if (!ctx) ++ return NULL; ++ ++ ret = get_dh_param_from_sample(&setup, pdata->keybits, pdata->kmode); ++ if (ret) ++ goto ctx_release; ++ ++ setup.optype = pdata->optype; ++ setup.pool = pool; ++ opdata.op_type = pdata->optype; ++ ret = get_dh_opdata_param(ctx, &opdata, &setup, key_size); ++ if (ret){ ++ HPRE_TST_PRT("failed to fill dh key gen req!\n"); ++ goto param_release; ++ } ++ ++ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); ++ if (!tag) { ++ HPRE_TST_PRT("failed to malloc dh tag!\n"); ++ goto param_release; ++ } ++ ++ do { ++ if (get_run_state() == 0) ++ break; ++ ++ try_cnt = 0; ++ i = count % MAX_POOL_LENTH; ++ tag[i].ctx = ctx; ++ tag[i].cnt = i; ++ tag[i].optype = opdata.op_type; ++ ++ ret = wcrypto_do_dh(ctx, &opdata, &tag[i]); ++ if (ret == -WD_EBUSY) { ++ usleep(SEND_USLEEP * try_cnt); ++ try_cnt++; ++ if (try_cnt > MAX_TRY_CNT) { ++ HPRE_TST_PRT("Test DH send fail %d times!\n", MAX_TRY_CNT); ++ try_cnt = 0; ++ } ++ continue; ++ } else if (ret) { ++ HPRE_TST_PRT("failed to do rsa async task!\n"); ++ goto tag_release; ++ } ++ ++ count++; ++ } while(true); ++ ++tag_release: ++ free(tag); ++param_release: ++ wd_free_blk(pool, opdata.x_p); ++ wd_free_blk(pool, opdata.pv); ++ wd_free_blk(pool, opdata.pri); ++ctx_release: ++ while (1) { ++ if (get_recv_time() > 0) // wait Async mode finish recv ++ break; ++ usleep(SEND_USLEEP); ++ } ++ ++ wcrypto_del_dh_ctx(ctx); ++ add_send_complete(); ++ ++ return NULL; ++} ++ ++static int get_ecc_curve(struct hpre_ecc_setup *setup, u32 cid) ++{ ++ switch (cid) { ++ case 0: // secp128R1 ++ setup->nid = 706; ++ setup->curve_id = WCRYPTO_SECP128R1; ++ break; ++ case 1: // secp192K1 ++ setup->nid = 711; ++ setup->curve_id = WCRYPTO_SECP192K1; ++ break; ++ case 2: // secp256K1 ++ setup->nid = 714; ++ setup->curve_id = WCRYPTO_SECP256K1; ++ break; ++ case 3: // brainpoolP320R1 ++ setup->nid = 929; ++ setup->curve_id = WCRYPTO_BRAINPOOLP320R1; ++ break; ++ case 4: // brainpoolP384R1 ++ setup->nid = 931; ++ setup->curve_id = WCRYPTO_BRAINPOOLP384R1; ++ break; ++ case 5: // secp521R1 ++ setup->nid = 716; ++ setup->curve_id = WCRYPTO_SECP521R1; ++ break; ++ default: ++ HPRE_TST_PRT("failed to get ecc curve id!\n"); ++ return -EINVAL; ++ } ++ ++ return 0; ++} ++ ++static int get_ecc_key_param(struct wcrypto_ecc_curve *param, u32 key_bits) ++{ ++ u32 key_size = (key_bits + 7) / 8; ++ ++ switch (key_bits) { ++ case 128: ++ param->a.data = ecdh_a_secp128r1; ++ param->b.data = ecdh_b_secp128r1; ++ param->p.data = ecdh_p_secp128r1; ++ param->n.data = ecdh_n_secp128r1; ++ param->g.x.data = ecdh_g_secp128r1; ++ param->g.y.data = ecdh_g_secp128r1 + key_size; ++ case 192: ++ param->a.data = ecdh_a_secp192k1; ++ param->b.data = ecdh_b_secp192k1; ++ param->p.data = ecdh_p_secp192k1; ++ param->n.data = ecdh_n_secp192k1; ++ param->g.x.data = ecdh_g_secp192k1; ++ param->g.y.data = ecdh_g_secp192k1 + key_size; ++ case 224: ++ param->a.data = ecdh_a_secp224r1; ++ param->b.data = ecdh_b_secp224r1; ++ param->p.data = ecdh_p_secp224r1; ++ param->n.data = ecdh_n_secp224r1; ++ param->g.x.data = ecdh_g_secp224r1; ++ param->g.y.data = ecdh_g_secp224r1 + key_size; ++ case 256: ++ param->a.data = ecdh_a_secp256k1; ++ param->b.data = ecdh_b_secp256k1; ++ param->p.data = ecdh_p_secp256k1; ++ param->n.data = ecdh_n_secp256k1; ++ param->g.x.data = ecdh_g_secp256k1; ++ param->g.y.data = ecdh_g_secp256k1 + key_size; ++ case 320: ++ param->a.data = ecdh_a_secp320k1; ++ param->b.data = ecdh_b_secp320k1; ++ param->p.data = ecdh_p_secp320k1; ++ param->n.data = ecdh_n_secp320k1; ++ param->g.x.data = ecdh_g_secp320k1; ++ param->g.y.data = ecdh_g_secp320k1 + key_size; ++ case 384: ++ param->a.data = ecdh_a_secp384r1; ++ param->b.data = ecdh_b_secp384r1; ++ param->p.data = ecdh_p_secp384r1; ++ param->n.data = ecdh_n_secp384r1; ++ param->g.x.data = ecdh_g_secp384r1; ++ param->g.y.data = ecdh_g_secp384r1 + key_size; ++ case 521: ++ param->a.data = ecdh_a_secp521r1; ++ param->b.data = ecdh_b_secp521r1; ++ param->p.data = ecdh_p_secp521r1; ++ param->n.data = ecdh_n_secp521r1; ++ param->g.x.data = ecdh_g_secp521r1; ++ param->g.y.data = ecdh_g_secp521r1 + key_size; ++ default: ++ HPRE_TST_PRT("key_bits %d not find\n", key_bits); ++ return -EINVAL; ++ } ++ ++ param->a.bsize = key_size; ++ param->a.dsize = key_size; ++ param->b.bsize = key_size; ++ param->b.dsize = key_size; ++ param->p.bsize = key_size; ++ param->p.dsize = key_size; ++ param->n.bsize = key_size; ++ param->n.dsize = key_size; ++ param->g.x.bsize = key_size; ++ param->g.x.dsize = key_size; ++ param->g.y.bsize = key_size; ++ param->g.y.dsize = key_size; ++ ++ return 0; ++} ++ ++static int ecc_get_rand(char *out, size_t out_len, void *usr) ++{ ++ //int ret; ++ ++ get_rand_data((u8 *)out, out_len); ++ //ret = RAND_priv_bytes((void *)out, out_len); ++ //if (ret != 1) { ++ // HPRE_TST_PRT("failed to get ecc rand data:%d\n", ret); ++ // return -EINVAL; ++ //} ++ ++ return 0; ++} ++ ++static int ecc_compute_hash(const char *in, size_t in_len, ++ char *out, size_t out_len, void *usr) ++{ ++ /* perf test for none hash check */ ++ return 0; ++} ++ ++static int get_ecc_param_from_sample(struct hpre_ecc_setup *setup, ++ u32 subtype, u32 key_bits) ++{ ++ int key_size = (key_bits + 7) / 8; ++ u32 len; ++ ++ setup->key_bits = key_bits; ++ ++ if (setup->nid == 714 || key_bits == 256) { // NID_secp256k1 ++ /* sm2 */ ++ if (subtype == SM2_TYPE) { ++ setup->priv_key = sm2_priv; ++ setup->priv_key_size = sizeof(sm2_priv); ++ setup->pub_key = sm2_pubkey; ++ setup->pub_key_size = sizeof(sm2_pubkey); ++ ++ len = SM2_DG_SZ; ++ setup->msg = malloc(len); ++ if (!setup->msg) ++ return -1; ++ memset(setup->msg, 0xFF, len); ++ ++ if (true) { // for msg_sigest mode ++ memcpy(setup->msg, sm2_digest, sizeof(sm2_digest)); ++ setup->msg_size = sizeof(sm2_digest); ++ } else { ++ memcpy(setup->msg, sm2_plaintext, sizeof(sm2_plaintext)); ++ setup->msg_size = sizeof(sm2_plaintext); ++ } ++ ++ if (setup->msg_size > 512) { ++ setup->ciphertext = sm2_ciphertext_l; ++ setup->ciphertext_size = sizeof(sm2_ciphertext_l); ++ setup->plaintext = sm2_plaintext_l; ++ setup->plaintext_size = sizeof(sm2_plaintext_l); ++ } else { ++ setup->ciphertext = sm2_ciphertext; ++ setup->ciphertext_size = sizeof(sm2_ciphertext); ++ setup->plaintext = sm2_plaintext; ++ setup->plaintext_size = sizeof(sm2_plaintext); ++ } ++ ++ setup->k = sm2_k; ++ setup->k_size = sizeof(sm2_k); ++ setup->userid = sm2_id; ++ setup->userid_size = sizeof(sm2_id); ++ setup->sign = sm2_sign_data; ++ setup->sign_size = sizeof(sm2_sign_data); ++ ++ } else { ++ setup->priv_key = ecdh_da_secp256k1; ++ setup->except_pub_key = ecdh_except_b_pubkey_secp256k1; ++ setup->pub_key = ecdh_cp_pubkey_secp256k1; ++ setup->share_key = ecdh_cp_sharekey_secp256k1; ++ setup->priv_key_size = sizeof(ecdh_da_secp256k1); ++ setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp256k1); ++ setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp256k1); ++ setup->share_key_size = sizeof(ecdh_cp_sharekey_secp256k1); ++ ++ /* ecc sign */ ++ setup->msg = ecc_except_e_secp256k1; ++ setup->msg_size = sizeof(ecc_except_e_secp256k1); ++ setup->k = ecc_except_kinv_secp256k1; ++ setup->k_size = sizeof(ecc_except_kinv_secp256k1); ++ setup->rp = ecdh_cp_pubkey_secp256k1 + 1; ++ setup->rp_size = key_size; ++ ++ /* ecc verf */ ++ setup->sign = ecc_cp_sign_secp256k1; ++ setup->sign_size = sizeof(ecc_cp_sign_secp256k1); ++ } ++ } else if (setup->nid == 706 || key_bits == 128) { ++ setup->priv_key = ecdh_da_secp128r1; ++ setup->except_pub_key = ecdh_except_b_pubkey_secp128r1; ++ setup->pub_key = ecdh_cp_pubkey_secp128r1; ++ setup->share_key = ecdh_cp_sharekey_secp128r1; ++ setup->priv_key_size = sizeof(ecdh_da_secp128r1); ++ setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp128r1); ++ setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp128r1); ++ setup->share_key_size = sizeof(ecdh_cp_sharekey_secp128r1); ++ ++ /* ecc sign */ ++ setup->msg = ecc_except_e_secp128r1; ++ setup->msg_size = sizeof(ecc_except_e_secp128r1); ++ setup->k = ecc_except_kinv_secp128r1; ++ setup->k_size = sizeof(ecc_except_kinv_secp128r1); ++ setup->rp = ecdh_cp_pubkey_secp128r1 + 1; ++ setup->rp_size = key_size; ++ ++ /* ecc verf */ ++ setup->sign = ecc_cp_sign_secp128r1; ++ setup->sign_size = sizeof(ecc_cp_sign_secp128r1); ++ ++ } else if (setup->nid == 711 || key_bits == 192) { ++ setup->priv_key = ecdh_da_secp192k1; ++ setup->except_pub_key = ecdh_except_b_pubkey_secp192k1; ++ setup->pub_key = ecdh_cp_pubkey_secp192k1; ++ setup->share_key = ecdh_cp_sharekey_secp192k1; ++ setup->priv_key_size = sizeof(ecdh_da_secp192k1); ++ setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp192k1); ++ setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp192k1); ++ setup->share_key_size = sizeof(ecdh_cp_sharekey_secp192k1); ++ ++ /* ecc sign */ ++ setup->msg = ecc_except_e_secp192k1; ++ setup->msg_size = sizeof(ecc_except_e_secp192k1); ++ setup->k = ecc_except_kinv_secp192k1; ++ setup->k_size = sizeof(ecc_except_kinv_secp192k1); ++ setup->rp = ecdh_cp_pubkey_secp192k1 + 1; ++ setup->rp_size = key_size; ++ ++ /* ecc verf */ ++ setup->sign = ecc_cp_sign_secp256k1; ++ setup->sign_size = sizeof(ecc_cp_sign_secp256k1); ++ } else if (setup->nid == 712 || key_bits == 224) { ++ setup->priv_key = ecdh_da_secp224r1; ++ setup->except_pub_key = ecdh_except_b_pubkey_secp224r1; ++ setup->pub_key = ecdh_cp_pubkey_secp224r1; ++ setup->share_key = ecdh_cp_sharekey_secp224r1; ++ setup->priv_key_size = sizeof(ecdh_da_secp224r1); ++ setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp224r1); ++ setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp224r1); ++ setup->share_key_size = sizeof(ecdh_cp_sharekey_secp224r1); ++ } else if (setup->nid == 929 || key_bits == 320) { ++ setup->priv_key = ecdh_da_secp320k1; ++ setup->except_pub_key = ecdh_except_b_pubkey_secp320k1; ++ setup->pub_key = ecdh_cp_pubkey_secp320k1; ++ setup->share_key = ecdh_cp_sharekey_secp320k1; ++ setup->priv_key_size = sizeof(ecdh_da_secp320k1); ++ setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp320k1); ++ setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp320k1); ++ setup->share_key_size = sizeof(ecdh_cp_sharekey_secp320k1); ++ ++ /* ecc sign */ ++ setup->msg = ecc_except_e_secp320k1; ++ setup->msg_size = sizeof(ecc_except_e_secp320k1); ++ setup->k = ecc_except_kinv_secp320k1; ++ setup->k_size = sizeof(ecc_except_kinv_secp320k1); ++ setup->rp = ecdh_cp_pubkey_secp192k1 + 1; ++ setup->rp_size = key_size; ++ ++ /* ecc verf */ ++ setup->sign = ecc_cp_sign_secp256k1; ++ setup->sign_size = sizeof(ecc_cp_sign_secp256k1); ++ ++ } else if (setup->nid == 931 || key_bits == 384) { ++ setup->priv_key = ecdh_da_secp384r1; ++ setup->except_pub_key = ecdh_except_b_pubkey_secp384r1; ++ setup->pub_key = ecdh_cp_pubkey_secp384r1; ++ setup->share_key = ecdh_cp_sharekey_secp384r1; ++ setup->priv_key_size = sizeof(ecdh_da_secp384r1); ++ setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp384r1); ++ setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp384r1); ++ setup->share_key_size = sizeof(ecdh_cp_sharekey_secp384r1); ++ ++ /* ecc sign */ ++ setup->msg = ecc_except_e_secp384r1; ++ setup->msg_size = sizeof(ecc_except_e_secp384r1); ++ setup->k = ecc_except_kinv_secp384r1; ++ setup->k_size = sizeof(ecc_except_kinv_secp384r1); ++ setup->rp = ecdh_cp_pubkey_secp384r1 + 1; ++ setup->rp_size = key_size; ++ ++ /* ecc verf */ ++ setup->sign = ecc_cp_sign_secp256k1; ++ setup->sign_size = sizeof(ecc_cp_sign_secp256k1); ++ } else if (setup->nid == 716 || key_bits == 521) { ++ setup->priv_key = ecdh_da_secp521r1; ++ setup->except_pub_key = ecdh_except_b_pubkey_secp521r1; ++ setup->pub_key = ecdh_cp_pubkey_secp521r1; ++ setup->share_key = ecdh_cp_sharekey_secp521r1; ++ setup->priv_key_size = sizeof(ecdh_da_secp521r1); ++ setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp521r1); ++ setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp521r1); ++ setup->share_key_size = sizeof(ecdh_cp_sharekey_secp521r1); ++ ++ /* ecc sign */ ++ setup->msg = ecc_except_e_secp521r1; ++ setup->msg_size = sizeof(ecc_except_e_secp521r1); ++ setup->k = ecc_except_kinv_secp521r1; ++ setup->k_size = sizeof(ecc_except_kinv_secp521r1); ++ setup->rp = ecdh_cp_pubkey_secp521r1 + 1; ++ setup->rp_size = key_size; ++ ++ /* ecc verf */ ++ setup->sign = ecc_cp_sign_secp256k1; ++ setup->sign_size = sizeof(ecc_cp_sign_secp256k1); ++ ++ } else { ++ HPRE_TST_PRT("init test sess setup not find this bits %d or nid %d\n", ++ key_bits, setup->nid); ++ return -EINVAL; ++ } ++ ++ return 0; ++} ++ ++static int ecdsa_param_fill(void *ctx, struct wcrypto_ecc_op_data *opdata, ++ struct wcrypto_ecc_key *ecc_key, struct hpre_ecc_setup *setup, ++ thread_data *pdata) ++{ ++ int key_insize = (pdata->keybits + 7) / 8; ++ u32 optype = pdata->optype; ++ struct wcrypto_ecc_out *ecc_out = NULL; ++ struct wcrypto_ecc_in *ecc_in = NULL; ++ struct wcrypto_ecc_point pub; ++ struct wd_dtb d, e, k; ++ int ret = 0; ++ ++ if (optype == WCRYPTO_ECDSA_SIGN) {// Sign ++ ecc_out = wcrypto_new_ecdsa_sign_out(ctx); ++ if (!ecc_out) { ++ HPRE_TST_PRT("failed to get ecdsa out!\n"); ++ return -ENOMEM; ++ } ++ ++ d.data = (void *)setup->priv_key; ++ d.dsize = setup->priv_key_size; ++ d.bsize = setup->priv_key_size; ++ ret = wcrypto_set_ecc_prikey(ecc_key, &d); ++ if (ret) { ++ HPRE_TST_PRT("failed to set ecdsa prikey!\n"); ++ goto del_ecc_out; ++ } ++ ++ pub.x.data = (void *)setup->pub_key + 1; ++ pub.x.dsize = key_insize; ++ pub.x.bsize = key_insize; ++ pub.y.data = pub.x.data + key_insize; ++ pub.y.dsize = key_insize; ++ pub.y.bsize = key_insize; ++ ret = wcrypto_set_ecc_pubkey(ecc_key, &pub); ++ if (ret) { ++ HPRE_TST_PRT("failed to set ecdsa pubkey!\n"); ++ goto del_ecc_out; ++ } ++ ++ e.data = (void *)setup->msg; ++ e.dsize = setup->msg_size; ++ e.bsize = key_insize; ++ ++ k.data = (void *)setup->k; ++ k.dsize = setup->k_size; ++ k.bsize = key_insize; ++ ecc_in = wcrypto_new_ecdsa_sign_in(ctx, &e, &k); ++ if (!ecc_in) { ++ HPRE_TST_PRT("failed to get ecdsa sign in!\n"); ++ ret = -ENOMEM; ++ goto del_ecc_out; ++ } ++ ++ opdata->in = ecc_in; ++ opdata->out = ecc_out; ++ } else { // Verf ++ pub.x.data = (void *)setup->pub_key + 1; ++ pub.x.dsize = key_insize; ++ pub.x.bsize = key_insize; ++ pub.y.data = pub.x.data + key_insize; ++ pub.y.dsize = key_insize; ++ pub.y.bsize = key_insize; ++ ret = wcrypto_set_ecc_pubkey(ecc_key, &pub); ++ if (ret) { ++ HPRE_TST_PRT("failed to set ecdsa pubkey!\n"); ++ return -ENOMEM; ++ } ++ ++ e.data = (void *)setup->msg; ++ e.dsize = setup->msg_size; ++ e.bsize = key_insize; ++ ++ d.data = (void *)setup->sign; ++ d.dsize = key_insize; ++ d.bsize = key_insize; ++ k.data = d.data + key_insize; ++ k.dsize = key_insize; ++ k.bsize = key_insize; ++ ecc_in = wcrypto_new_ecdsa_verf_in(ctx, &e, &d, &k); ++ if (!ecc_in) { ++ HPRE_TST_PRT("failed to get ecdsa verf ecc in!\n"); ++ return -ENOMEM; ++ } ++ ++ opdata->in = ecc_in; ++ } ++ ++ return 0; ++del_ecc_out: ++ if (ecc_out) ++ (void)wcrypto_del_ecc_out(ctx, ecc_out); ++ return ret; ++} ++ ++static int sm2_param_fill(void *ctx, struct wcrypto_ecc_op_data *opdata, ++ struct hpre_ecc_setup *setup, thread_data *pdata) ++{ ++ int key_insize = (pdata->keybits + 7) / 8; ++ u32 optype = pdata->optype; ++ struct wcrypto_ecc_out *ecc_out = NULL; ++ struct wcrypto_ecc_in *ecc_in = NULL; ++ struct wcrypto_ecc_point tmp; ++ struct wd_dtb d, e, k; ++ ++ switch (optype) { ++ case WCRYPTO_SM2_SIGN:// Sign ++ ecc_out = wcrypto_new_sm2_sign_out(ctx); ++ if (!ecc_out) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); ++ return -ENOMEM; ++ } ++ ++ e.data = (void *)setup->msg; ++ e.dsize = setup->msg_size; ++ e.bsize = setup->msg_size; ++ k.data = (void *)setup->k; ++ k.dsize = setup->k_size; ++ k.bsize = key_insize; ++ ecc_in = wcrypto_new_sm2_sign_in(ctx, &e, &k, NULL, 1); ++ if (!ecc_in) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); ++ goto del_ecc_out; ++ } ++ opdata->in = ecc_in; ++ opdata->out = ecc_out; ++ break; ++ case WCRYPTO_SM2_VERIFY: // Verf ++ ecc_out = wcrypto_new_sm2_sign_out(ctx); ++ if (!ecc_out) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); ++ return -ENOMEM; ++ } ++ ++ e.data = (void *)setup->msg; ++ e.dsize = setup->msg_size; ++ e.bsize = key_insize; ++ d.data = (void *)setup->sign; ++ d.dsize = key_insize; ++ d.bsize = key_insize; ++ k.data = d.data + key_insize; ++ k.dsize = key_insize; ++ k.bsize = key_insize; ++ ecc_in = wcrypto_new_sm2_verf_in(ctx, &e, &d, &k, NULL, 1); ++ if (!ecc_in) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); ++ goto del_ecc_out; ++ } ++ ++ opdata->in = ecc_in; ++ opdata->out = ecc_out; ++ break; ++ case WCRYPTO_SM2_ENCRYPT: // Enc ++ ecc_out = wcrypto_new_sm2_enc_out(ctx, setup->msg_size); ++ if (!ecc_out) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); ++ return -ENOMEM; ++ } ++ ++ e.data = (void *)setup->plaintext; ++ e.dsize = setup->plaintext_size; ++ e.bsize = setup->plaintext_size; ++ k.data = (void *)setup->k; ++ k.dsize = setup->k_size; ++ k.bsize = key_insize; ++ ecc_in = wcrypto_new_sm2_enc_in(ctx, &e, &k); ++ if (!ecc_in) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); ++ goto del_ecc_out; ++ } ++ opdata->in = ecc_in; ++ opdata->out = ecc_out; ++ break; ++ case WCRYPTO_SM2_DECRYPT: // Dec ++ tmp.x.data = (void *)setup->ciphertext; ++ tmp.x.dsize = 32; ++ tmp.y.data = tmp.x.data + 32; ++ tmp.y.dsize = 32; ++ e.data = tmp.y.data + 32; ++ e.dsize = 32; ++ d.data = e.data + 32; ++ d.dsize = setup->ciphertext_size - 32 * 3; ++ ecc_in = wcrypto_new_sm2_dec_in(ctx, &tmp, &d, &e); ++ if (!ecc_in) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); ++ return -ENOMEM; ++ } ++ ++ ecc_out = wcrypto_new_sm2_dec_out(ctx, d.dsize); ++ if (!ecc_out) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); ++ goto del_ecc_in; ++ } ++ ++ opdata->in = ecc_in; ++ opdata->out = ecc_out; ++ break; ++ case WCRYPTO_SM2_KG: // KG ++ ecc_out = wcrypto_new_sm2_kg_out(ctx); ++ if (!ecc_out) { ++ HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); ++ return -ENOMEM; ++ } ++ ++ opdata->out = ecc_out; ++ break; ++ default: ++ HPRE_TST_PRT("failed to match sm2 optype!\n"); ++ return -ENOMEM; ++ } ++ ++ return 0; ++ ++del_ecc_in: ++ if (ecc_in) ++ (void)wcrypto_del_ecc_in(ctx, ecc_in); ++del_ecc_out: ++ if (ecc_out) ++ (void)wcrypto_del_ecc_out(ctx, ecc_out); ++ ++ return -ENOMEM; ++} ++ ++static int ecc_param_fill(void *ctx, struct wcrypto_ecc_op_data *opdata, ++ struct wcrypto_ecc_key *ecc_key, struct hpre_ecc_setup *setup, ++ thread_data *pdata) ++{ ++ int key_insize = (pdata->keybits + 7) / 8; ++ u32 subtype = pdata->subtype; ++ u32 optype = pdata->optype; ++ struct wcrypto_ecc_out *ecc_out = NULL; ++ struct wcrypto_ecc_in *ecc_in = NULL; ++ struct wcrypto_ecc_point tmp; ++ struct wd_dtb d; ++ int ret = 0; ++ ++ ecc_out = wcrypto_new_ecxdh_out(ctx); ++ if (!ecc_out) { ++ HPRE_TST_PRT("failed to alloc ecxdh out!\n"); ++ return -ENOMEM; ++ } ++ if (optype == WCRYPTO_ECXDH_GEN_KEY) { // gen ++ d.data = (void *)setup->priv_key; ++ d.dsize = setup->priv_key_size; ++ d.bsize = setup->priv_key_size; ++ ret = wcrypto_set_ecc_prikey(ecc_key, &d); ++ if (ret) { ++ HPRE_TST_PRT("failed to set ecc prikey!\n"); ++ goto del_ecc_out; ++ } ++ ++ opdata->out = ecc_out; ++ } else { // compute ++ if (subtype == ECDH_TYPE) ++ tmp.x.data = setup->except_pub_key; ++ else ++ tmp.x.data = setup->except_pub_key + 1; ++ tmp.x.bsize = key_insize; ++ tmp.x.dsize = key_insize; ++ tmp.y.data = tmp.x.data + key_insize; ++ tmp.y.bsize = key_insize; ++ tmp.y.dsize = key_insize; ++ ecc_in = wcrypto_new_ecxdh_in(ctx, &tmp); ++ if (!ecc_in) { ++ HPRE_TST_PRT("failed to get ecxdh sign in!\n"); ++ goto del_ecc_out; ++ } ++ ++ d.data = (void *)setup->priv_key; ++ d.dsize = setup->priv_key_size; ++ d.bsize = setup->priv_key_size; ++ ret = wcrypto_set_ecc_prikey(ecc_key, &d); ++ if (ret) { ++ HPRE_TST_PRT("failed to set ecc prikey!\n"); ++ goto del_ecc_out; ++ } ++ ++ opdata->in = ecc_in; ++ opdata->out = ecc_out; ++ } ++ ++ return 0; ++ ++del_ecc_out: ++ if (ecc_out) ++ (void)wcrypto_del_ecc_out(ctx, ecc_out); ++ ++ return ret; ++} ++ ++static void *ecc_wd_sync_run(void *arg) ++{ ++ typedef int (*wd_do)(void *ctx, struct wcrypto_ecc_op_data *opdata, ++ void *tag); ++ wd_do wcrypto_do_ecc = NULL; ++ thread_data *pdata = (thread_data *)arg; ++ int key_size = pdata->keybits >> 3; ++ u32 subtype = pdata->subtype; ++ struct wcrypto_ecc_ctx_setup ctx_setup; ++ struct wcrypto_ecc_op_data opdata; ++ struct wcrypto_ecc_curve param; ++ struct hpre_ecc_setup setup; ++ struct wcrypto_ecc_key *ecc_key; ++ struct wcrypto_ecc_point pbk; ++ struct wd_queue *queue; ++ struct wd_dtb prk; ++ void *ctx = NULL; ++ void *tag = NULL; ++ void *pool; ++ u32 cid = ECC_CURVE_ID; ++ u32 count = 0; ++ int ret; ++ ++ memset(&ctx_setup, 0, sizeof(ctx_setup)); ++ memset(¶m, 0, sizeof(param)); ++ memset(&opdata, 0, sizeof(opdata)); ++ ++ pool = g_thread_queue.bd_res[pdata->td_id].pool; ++ queue = g_thread_queue.bd_res[pdata->td_id].queue; ++ ++ memset(&setup, 0, sizeof(setup)); ++ if (subtype != X448_TYPE || subtype != X25519_TYPE) { ++ ret = get_ecc_curve(&setup, cid); ++ if (ret) ++ return NULL; ++ } ++ ++ ctx_setup.br.alloc = (void *)wd_alloc_blk; ++ ctx_setup.br.free = (void *)wd_free_blk; ++ ctx_setup.br.iova_map = (void *)wd_blk_iova_map; ++ ctx_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; ++ ctx_setup.br.get_bufsize = (void *)wd_blksize; ++ ctx_setup.br.usr = pool; ++ ++ ctx_setup.key_bits = pdata->keybits; ++ if (subtype == ECDH_TYPE || subtype == ECDSA_TYPE) { ++ if (cid > ECC_CURVE_ID) { ++ ctx_setup.cv.type = WCRYPTO_CV_CFG_PARAM; ++ get_ecc_key_param(¶m, pdata->keybits); ++ ctx_setup.cv.cfg.pparam = ¶m; ++ } else { ++ ctx_setup.cv.type = WCRYPTO_CV_CFG_ID; ++ ctx_setup.cv.cfg.id = setup.curve_id; ++ } ++ } ++ ++ ctx_setup.rand.cb = ecc_get_rand; ++ // set def setting; ++ ctx_setup.hash.cb = ecc_compute_hash; ++ ctx_setup.hash.type = WCRYPTO_HASH_SHA256; ++ ++ ret = get_ecc_param_from_sample(&setup, subtype, pdata->keybits); ++ if (ret) ++ return NULL; ++ ++ ctx = wcrypto_create_ecc_ctx(queue, &ctx_setup); ++ if (!ctx) ++ goto msg_release; ++ ++ prk.data = (void *)setup.priv_key; ++ prk.dsize = setup.priv_key_size; ++ prk.bsize = setup.priv_key_size; ++ pbk.x.data = (char *)setup.pub_key + 1; ++ pbk.x.dsize = key_size; ++ pbk.x.bsize = key_size; ++ pbk.y.data = pbk.x.data + key_size; ++ pbk.y.dsize = key_size; ++ pbk.y.bsize = key_size; ++ ++ ecc_key = wcrypto_get_ecc_key(ctx); ++ ret = wcrypto_set_ecc_prikey(ecc_key, &prk); ++ if (ret) { ++ HPRE_TST_PRT("failed to set ecc prikey!\n"); ++ goto sess_release; ++ } ++ ++ ret = wcrypto_set_ecc_pubkey(ecc_key, &pbk); ++ if (ret) { ++ HPRE_TST_PRT("failed to set ecc pubkey!\n"); ++ goto sess_release; ++ } ++ ++ opdata.op_type = pdata->optype; ++ switch (subtype) { ++ case ECDSA_TYPE: // ECC alg ++ ret = ecdsa_param_fill(ctx, &opdata, ecc_key, &setup, pdata); ++ if (ret) ++ goto src_release; ++ wcrypto_do_ecc = wcrypto_do_ecdsa; ++ break; ++ case SM2_TYPE: // SM2 alg ++ ret = sm2_param_fill(ctx, &opdata, &setup, pdata); ++ if (ret) ++ goto src_release; ++ wcrypto_do_ecc = wcrypto_do_sm2; ++ break; ++ default: // ECDH, X25519, X448 alg ++ ret = ecc_param_fill(ctx, &opdata, ecc_key, &setup, pdata); ++ if (ret) ++ goto src_release; ++ wcrypto_do_ecc = wcrypto_do_ecxdh; ++ break; ++ } ++ ++ do { ++ ret = wcrypto_do_ecc(ctx, &opdata, tag); ++ if (ret || opdata.status) { ++ HPRE_TST_PRT("failed to do ecc task, status: %d\n", opdata.status); ++ goto src_release; ++ } ++ ++ count++; ++ if (get_run_state() == 0) ++ break; ++ } while(true); ++ ++src_release: ++ if (opdata.in) ++ (void)wcrypto_del_ecc_in(ctx, opdata.in); ++ if (opdata.out) ++ (void)wcrypto_del_ecc_out(ctx, opdata.out); ++sess_release: ++ wcrypto_del_ecc_ctx(ctx); ++msg_release: ++ if (subtype == SM2_TYPE) ++ free(setup.msg); ++ add_recv_data(count, key_size); ++ ++ return NULL; ++} ++ ++static void ecc_async_cb(const void *msg, void *tag) ++{ ++ //struct wcrypto_ecc_msg *massage = msg; ++ //struct rsa_async_tag *ptag = tag; ++ //u32 op_type = tag->op_type; ++ //void *ctx = tag->ctx; ++ ++ return; ++} ++ ++static void *ecc_wd_async_run(void *arg) ++{ ++ typedef int (*wd_do)(void *ctx, struct wcrypto_ecc_op_data *opdata, ++ void *tag); ++ wd_do wcrypto_do_ecc = NULL; ++ thread_data *pdata = (thread_data *)arg; ++ int key_size = pdata->keybits >> 3; ++ u32 subtype = pdata->subtype; ++ struct rsa_async_tag *tag = NULL; ++ struct wcrypto_ecc_ctx_setup ctx_setup; ++ struct wcrypto_ecc_op_data opdata; ++ struct wcrypto_ecc_curve param; ++ struct hpre_ecc_setup setup; ++ struct wcrypto_ecc_key *ecc_key; ++ struct wcrypto_ecc_point pbk; ++ struct wd_queue *queue; ++ struct wd_dtb prk; ++ void *ctx = NULL; ++ int try_cnt = 0; ++ void *pool; ++ u32 cid = ECC_CURVE_ID; ++ u32 count = 0; ++ int i, ret; ++ ++ memset(&ctx_setup, 0, sizeof(ctx_setup)); ++ memset(¶m, 0, sizeof(param)); ++ memset(&opdata, 0, sizeof(opdata)); ++ ++ pool = g_thread_queue.bd_res[pdata->td_id].pool; ++ queue = g_thread_queue.bd_res[pdata->td_id].queue; ++ ++ memset(&setup, 0, sizeof(setup)); ++ if (subtype != X448_TYPE || subtype != X25519_TYPE) { ++ ret = get_ecc_curve(&setup, cid); ++ if (ret) ++ return NULL; ++ } ++ ++ ctx_setup.cb = (void *)ecc_async_cb; ++ ctx_setup.br.alloc = (void *)wd_alloc_blk; ++ ctx_setup.br.free = (void *)wd_free_blk; ++ ctx_setup.br.iova_map = (void *)wd_blk_iova_map; ++ ctx_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; ++ ctx_setup.br.get_bufsize = (void *)wd_blksize; ++ ctx_setup.br.usr = pool; ++ ++ ctx_setup.key_bits = pdata->keybits; ++ if (subtype == ECDH_TYPE || subtype == ECDSA_TYPE) { ++ if (cid > ECC_CURVE_ID) { ++ ctx_setup.cv.type = WCRYPTO_CV_CFG_PARAM; ++ get_ecc_key_param(¶m, pdata->keybits); ++ ctx_setup.cv.cfg.pparam = ¶m; ++ } else { ++ ctx_setup.cv.type = WCRYPTO_CV_CFG_ID; ++ ctx_setup.cv.cfg.id = setup.curve_id; ++ } ++ } ++ ++ ctx_setup.rand.cb = ecc_get_rand; ++ // set def setting; ++ ctx_setup.hash.cb = ecc_compute_hash; ++ ctx_setup.hash.type = WCRYPTO_HASH_SHA256; ++ ++ ret = get_ecc_param_from_sample(&setup, subtype, pdata->keybits); ++ if (ret) ++ return NULL; ++ ++ ctx = wcrypto_create_ecc_ctx(queue, &ctx_setup); ++ if (!ctx) ++ goto msg_release; ++ ++ prk.data = (void *)setup.priv_key; ++ prk.dsize = setup.priv_key_size; ++ prk.bsize = setup.priv_key_size; ++ pbk.x.data = (char *)setup.pub_key + 1; ++ pbk.x.dsize = key_size; ++ pbk.x.bsize = key_size; ++ pbk.y.data = pbk.x.data + key_size; ++ pbk.y.dsize = key_size; ++ pbk.y.bsize = key_size; ++ ++ ecc_key = wcrypto_get_ecc_key(ctx); ++ ret = wcrypto_set_ecc_prikey(ecc_key, &prk); ++ if (ret) { ++ HPRE_TST_PRT("failed to set ecc prikey!\n"); ++ goto sess_release; ++ } ++ ++ ret = wcrypto_set_ecc_pubkey(ecc_key, &pbk); ++ if (ret) { ++ HPRE_TST_PRT("failed to set ecc pubkey!\n"); ++ goto sess_release; ++ } ++ ++ opdata.op_type = pdata->optype; ++ switch (subtype) { ++ case ECDSA_TYPE: // ECC alg ++ ret = ecdsa_param_fill(ctx, &opdata, ecc_key, &setup, pdata); ++ if (ret) ++ goto src_release; ++ wcrypto_do_ecc = wcrypto_do_ecdsa; ++ break; ++ case SM2_TYPE: // SM2 alg ++ ret = sm2_param_fill(ctx, &opdata, &setup, pdata); ++ if (ret) ++ goto src_release; ++ wcrypto_do_ecc = wcrypto_do_sm2; ++ break; ++ default: // ECDH, X25519, X448 alg ++ ret = ecc_param_fill(ctx, &opdata, ecc_key, &setup, pdata); ++ if (ret) ++ goto src_release; ++ wcrypto_do_ecc = wcrypto_do_ecxdh; ++ break; ++ } ++ ++ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); ++ if (!tag) { ++ HPRE_TST_PRT("failed to malloc ecc tag!\n"); ++ goto src_release; ++ } ++ ++ do { ++ if (get_run_state() == 0) ++ break; ++ ++ try_cnt = 0; ++ i = count % MAX_POOL_LENTH; ++ tag[i].ctx = ctx; ++ tag[i].cnt = i; ++ tag[i].optype = opdata.op_type; ++ ++ ret = wcrypto_do_ecc(ctx, &opdata, &tag[i]); ++ if (ret == -WD_EBUSY) { ++ usleep(SEND_USLEEP * try_cnt); ++ try_cnt++; ++ if (try_cnt > MAX_TRY_CNT) { ++ HPRE_TST_PRT("Test ECC send fail %d times!\n", MAX_TRY_CNT); ++ try_cnt = 0; ++ } ++ continue; ++ } else if (ret) { ++ HPRE_TST_PRT("failed to do rsa async task!\n"); ++ goto tag_release; ++ } ++ count++; ++ } while(true); ++ ++tag_release: ++ free(tag); ++src_release: ++ if (opdata.in) ++ (void)wcrypto_del_ecc_in(ctx, opdata.in); ++ if (opdata.out) ++ (void)wcrypto_del_ecc_out(ctx, opdata.out); ++sess_release: ++ while (1) { ++ if (get_recv_time() > 0) // wait Async mode finish recv ++ break; ++ usleep(SEND_USLEEP); ++ } ++ ++ wcrypto_del_ecc_ctx(ctx); ++msg_release: ++ if (subtype == SM2_TYPE) ++ free(setup.msg); ++ add_send_complete(); ++ ++ return NULL; ++} ++ ++static int hpre_wd_sync_threads(struct acc_option *options) ++{ ++ typedef void *(*hpre_sync_run)(void *arg); ++ hpre_sync_run wd_hpre_sync_run = NULL; ++ thread_data threads_args[THREADS_NUM]; ++ thread_data threads_option; ++ pthread_t tdid[THREADS_NUM]; ++ int i, ret; ++ ++ /* alg param parse and set to thread data */ ++ threads_option.subtype = options->subtype; ++ threads_option.td_id = 0; ++ ret = hpre_wd_param_parse(&threads_option, options); ++ if (ret) ++ return ret; ++ ++ switch (options->subtype) { ++ case RSA_TYPE: ++ wd_hpre_sync_run = rsa_wd_sync_run; ++ break; ++ case DH_TYPE: ++ wd_hpre_sync_run = dh_wd_sync_run; ++ break; ++ case ECDH_TYPE: ++ case ECDSA_TYPE: ++ case SM2_TYPE: ++ case X25519_TYPE: ++ case X448_TYPE: ++ wd_hpre_sync_run = ecc_wd_sync_run; ++ break; ++ default: ++ HPRE_TST_PRT("failed to parse alg subtype on uninit!\n"); ++ return -EINVAL; ++ } ++ ++ for (i = 0; i < g_thread_num; i++) { ++ threads_args[i].subtype = threads_option.subtype; ++ threads_args[i].kmode = threads_option.kmode; ++ threads_args[i].keybits = threads_option.keybits; ++ threads_args[i].optype = threads_option.optype; ++ threads_args[i].td_id = i; ++ ret = pthread_create(&tdid[i], NULL, wd_hpre_sync_run, &threads_args[i]); ++ if (ret) { ++ HPRE_TST_PRT("Create sync thread fail!\n"); ++ goto sync_error; ++ } ++ } ++ ++ /* join thread */ ++ for (i = 0; i < g_thread_num; i++) { ++ ret = pthread_join(tdid[i], NULL); ++ if (ret) { ++ HPRE_TST_PRT("Join sync thread fail!\n"); ++ goto sync_error; ++ } ++ } ++ ++sync_error: ++ return ret; ++} ++ ++static int hpre_wd_async_threads(struct acc_option *options) ++{ ++ typedef void *(*hpre_async_run)(void *arg); ++ hpre_async_run wd_hpre_async_run = NULL; ++ thread_data threads_args[THREADS_NUM]; ++ thread_data threads_option; ++ pthread_t tdid[THREADS_NUM]; ++ pthread_t pollid[THREADS_NUM]; ++ int i, ret; ++ ++ /* alg param parse and set to thread data */ ++ threads_option.subtype = options->subtype; ++ threads_option.td_id = 0; ++ ret = hpre_wd_param_parse(&threads_option, options); ++ if (ret) ++ return ret; ++ ++ switch (options->subtype) { ++ case RSA_TYPE: ++ wd_hpre_async_run = rsa_wd_async_run; ++ break; ++ case DH_TYPE: ++ wd_hpre_async_run = dh_wd_async_run; ++ break; ++ case ECDH_TYPE: ++ case ECDSA_TYPE: ++ case SM2_TYPE: ++ case X25519_TYPE: ++ case X448_TYPE: ++ wd_hpre_async_run = ecc_wd_async_run; ++ break; ++ default: ++ HPRE_TST_PRT("failed to parse alg subtype on uninit!\n"); ++ return -EINVAL; ++ } ++ ++ for (i = 0; i < g_thread_num; i++) { ++ threads_args[i].subtype = threads_option.subtype; ++ threads_args[i].td_id = i; ++ /* poll thread */ ++ ret = pthread_create(&pollid[i], NULL, hpre_wd_poll, &threads_args[i]); ++ if (ret) { ++ HPRE_TST_PRT("Create poll thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++ for (i = 0; i < g_thread_num; i++) { ++ threads_args[i].subtype = threads_option.subtype; ++ threads_args[i].kmode = threads_option.kmode; ++ threads_args[i].keybits = threads_option.keybits; ++ threads_args[i].optype = threads_option.optype; ++ threads_args[i].td_id = i; ++ ret = pthread_create(&tdid[i], NULL, wd_hpre_async_run, &threads_args[i]); ++ if (ret) { ++ HPRE_TST_PRT("Create async thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++ /* join thread */ ++ for (i = 0; i < g_thread_num; i++) { ++ ret = pthread_join(tdid[i], NULL); ++ if (ret) { ++ HPRE_TST_PRT("Join async thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++ for (i = 0; i < g_thread_num; i++) { ++ ret = pthread_join(pollid[i], NULL); ++ if (ret) { ++ HPRE_TST_PRT("Join poll thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++async_error: ++ return ret; ++} ++ ++int hpre_wd_benchmark(struct acc_option *options) ++{ ++ u32 ptime; ++ int ret; ++ ++ g_thread_num = options->threads; ++ ++ if (options->optype >= (WCRYPTO_EC_OP_MAX - WCRYPTO_ECDSA_VERIFY)) { ++ HPRE_TST_PRT("HPRE optype error: %u\n", options->optype); ++ return -EINVAL; ++ } ++ ++ ret = init_hpre_wd_queue(options); ++ if (ret) ++ return ret; ++ ++ get_pid_cpu_time(&ptime); ++ time_start(options->times); ++ if (options->syncmode) ++ ret = hpre_wd_async_threads(options); ++ else ++ ret = hpre_wd_sync_threads(options); ++ cal_perfermance_data(options, ptime); ++ if (ret) ++ return ret; ++ ++ uninit_hpre_wd_queue(); ++ ++ return 0; ++} +diff --git a/uadk_tool/benchmark/hpre_wd_benchmark.h b/uadk_tool/benchmark/hpre_wd_benchmark.h +new file mode 100644 +index 0000000..0cc94a3 +--- /dev/null ++++ b/uadk_tool/benchmark/hpre_wd_benchmark.h +@@ -0,0 +1,6 @@ ++/* SPDX-License-Identifier: Apache-2.0 */ ++#ifndef HPRE_WD_BENCHMARK_H ++#define HPRE_WD_BENCHMARK_H ++ ++extern int hpre_wd_benchmark(struct acc_option *options); ++#endif /* HPRE_WD_BENCHMARK_H */ +-- +2.27.0 + diff --git a/0136-uadk_tool-Add-SVA-mode-test-function-to-ZIP-module.patch b/0136-uadk_tool-Add-SVA-mode-test-function-to-ZIP-module.patch new file mode 100644 index 0000000..6f5c3bb --- /dev/null +++ b/0136-uadk_tool-Add-SVA-mode-test-function-to-ZIP-module.patch @@ -0,0 +1,1296 @@ +From 51a4f8fdc43be6ce4243197c63654df5730d474a Mon Sep 17 00:00:00 2001 +From: Longfang Liu +Date: Mon, 18 Jul 2022 17:16:34 +0800 +Subject: [PATCH 150/183] uadk_tool: Add SVA mode test function to ZIP module + +Add performance test function of SVA mode for Zlib, +Gzip algorithm of ZIP module. + +Signed-off-by: Longfang Liu +--- + uadk_tool/benchmark/include/fse.h | 51 + + uadk_tool/benchmark/zip_uadk_benchmark.c | 1200 ++++++++++++++++++++++ + uadk_tool/benchmark/zip_uadk_benchmark.h | 6 + + 3 files changed, 1257 insertions(+) + create mode 100644 uadk_tool/benchmark/include/fse.h + create mode 100644 uadk_tool/benchmark/zip_uadk_benchmark.c + create mode 100644 uadk_tool/benchmark/zip_uadk_benchmark.h + +diff --git a/uadk_tool/benchmark/include/fse.h b/uadk_tool/benchmark/include/fse.h +new file mode 100644 +index 0000000..73c3eda +--- /dev/null ++++ b/uadk_tool/benchmark/include/fse.h +@@ -0,0 +1,51 @@ ++/* SPDX-License-Identifier: Apache-2.0 */ ++ ++#ifndef ZSTD_LZ77_FSE_H ++#define ZSTD_LZ77_FSE_H ++ ++#include ++#include ++ ++typedef struct ZSTD_CCtx_s ZSTD_CCtx; ++ ++typedef struct seqDef_s { ++ unsigned int offset; ++ unsigned short litLength; ++ unsigned short matchLength; ++} seqDef; ++ ++typedef struct COMP_4TUPLE_TAG_S { ++ char *litStart; /* literal start address */ ++ seqDef *sequencesStart; /* sequences start address */ ++ unsigned int litlen; /* literal effective data length */ ++ unsigned int seqnum; /* sequences array's elements numbers */ ++ unsigned int longLengthID; /* litlen overflow flag */ ++ unsigned int longLengthPos; /* litlen overflow index */ ++ char *additional_p; /* start address of additional data */ ++} COMP_TUPLE_TAG; ++ ++typedef struct ZSTD_inBuffer_s { ++ const void* src; /* < start of input buffer */ ++ size_t size; /* < size of input buffer */ ++ size_t pos; /* < position where reading stopped. Will be updated. Necessarily 0 <= pos <= size */ ++} ZSTD_inBuffer; ++ ++typedef struct ZSTD_outBuffer_s { ++ void* dst; /* < start of output buffer */ ++ size_t size; /* < size of output buffer */ ++ size_t pos; /* < position where writing stopped. Will be updated. Necessarily 0 <= pos <= size */ ++} ZSTD_outBuffer; ++ ++typedef enum { ++ ZSTD_e_continue = 0, /* collect more data, encoder decides when to output compressed result, for optimal compression ratio */ ++ ZSTD_e_flush = 1, /* flush any data provided so far */ ++ ZSTD_e_end = 2 /* flush any remaining data _and_ close current frame. */ ++} ZSTD_EndDirective; ++ ++/* the complete implementation code in libfse */ ++#ifdef ZLIB_FSE ++ZSTD_CCtx* zstd_soft_fse_init(unsigned int level); ++int zstd_soft_fse(void *Ftuple, ZSTD_inBuffer *input, ZSTD_outBuffer *output, ZSTD_CCtx * cctx, ZSTD_EndDirective cmode); ++#endif ++ ++#endif +diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c +new file mode 100644 +index 0000000..ba18e6d +--- /dev/null ++++ b/uadk_tool/benchmark/zip_uadk_benchmark.c +@@ -0,0 +1,1200 @@ ++/* SPDX-License-Identifier: Apache-2.0 */ ++ ++#include ++#include "uadk_benchmark.h" ++ ++#include "zip_uadk_benchmark.h" ++#include "include/wd_comp.h" ++#include "include/wd_sched.h" ++#include "include/fse.h" ++ ++#define ZIP_TST_PRT printf ++#define PATH_SIZE 64 ++#define ZIP_FILE "./zip" ++#define COMP_LEN_RATE 2 ++#define DECOMP_LEN_RATE 2 ++ ++struct uadk_bd { ++ u8 *src; ++ u8 *dst; ++ u32 src_len; ++ u32 dst_len; ++}; ++ ++struct bd_pool { ++ struct uadk_bd *bds; ++}; ++ ++struct thread_pool { ++ struct bd_pool *pool; ++} g_zip_pool; ++ ++enum ZIP_OP_MODE { ++ BLOCK_MODE, ++ STREAM_MODE ++}; ++ ++struct zip_async_tag { ++ handle_t sess; ++ u32 td_id; ++ u32 bd_idx; ++ u32 cm_len; ++ ZSTD_CCtx *cctx; ++}; ++ ++typedef struct uadk_thread_res { ++ u32 alg; ++ u32 mode; // block/stream ++ u32 optype; ++ u32 td_id; ++} thread_data; ++ ++struct zip_file_head { ++ u32 file_size; ++ u32 block_num; ++ u32 blk_sz[MAX_POOL_LENTH]; ++}; ++ ++static struct wd_ctx_config g_ctx_cfg; ++static struct wd_sched *g_sched; ++static unsigned int g_thread_num; ++static unsigned int g_ctxnum; ++static unsigned int g_pktlen; ++static unsigned int g_prefetch; ++ ++#ifndef ZLIB_FSE ++static ZSTD_CCtx* zstd_soft_fse_init(unsigned int level) ++{ ++ return NULL; ++} ++ ++static int zstd_soft_fse(void *Ftuple, ZSTD_inBuffer *input, ZSTD_outBuffer *output, ZSTD_CCtx * cctx, ZSTD_EndDirective cmode) ++{ ++ return input->size; ++} ++#endif ++ ++static int save_file_data(const char *alg, u32 pkg_len, u32 optype) ++{ ++ struct zip_file_head *fhead = NULL; ++ char file_path[PATH_SIZE]; ++ u32 total_file_size = 0; ++ double comp_rate = 0.0; ++ u32 full_size; ++ ssize_t size; ++ int j, fd; ++ int ret = 0; ++ ++ optype = optype % WD_DIR_MAX; ++ if (optype != WD_DIR_COMPRESS) //compress ++ return 0; ++ ++ ret = snprintf(file_path, PATH_SIZE, "%s_%u.%s", ZIP_FILE, pkg_len, alg); ++ if (ret < 0) ++ return -EINVAL; ++ ++ ret = access(file_path, F_OK); ++ if (!ret) { ++ ZIP_TST_PRT("compress data file: %s has exist!\n", file_path); ++ return 0; ++ } ++ ++ fd = open(file_path, O_WRONLY|O_CREAT, 0777); ++ if (fd < 0) { ++ ZIP_TST_PRT("compress data file open %s fail (%d)!\n", file_path, -errno); ++ return -ENODEV; ++ } ++ ++ fhead = malloc(sizeof(*fhead)); ++ if (!fhead) { ++ ZIP_TST_PRT("failed to alloc file head memory\n"); ++ ret = -ENOMEM; ++ goto fd_error; ++ } ++ ++ // init file head informations ++ for (j = 0; j < MAX_POOL_LENTH; j++) { ++ fhead->blk_sz[j] = g_zip_pool.pool[0].bds[j].dst_len; ++ total_file_size += fhead->blk_sz[j]; ++ } ++ fhead->block_num = MAX_POOL_LENTH; ++ fhead->file_size = total_file_size; ++ size = write(fd, fhead, sizeof(*fhead)); ++ if (size < 0) { ++ ZIP_TST_PRT("compress write file head failed: %lu!\n", size); ++ ret = -EINVAL; ++ goto write_error; ++ } ++ ++ // write data for one buffer one buffer to file line. ++ for (j = 0; j < MAX_POOL_LENTH; j++) { ++ size = write(fd, g_zip_pool.pool[0].bds[j].dst, ++ fhead->blk_sz[j]); ++ if (size < 0) { ++ ZIP_TST_PRT("compress write data error size: %lu!\n", size); ++ ret = -ENODEV; ++ break; ++ } ++ } ++ ++write_error: ++ free(fhead); ++fd_error: ++ close(fd); ++ ++ full_size = g_pktlen * MAX_POOL_LENTH; ++ comp_rate = (double) total_file_size / full_size; ++ ZIP_TST_PRT("compress data rate: %.1f%%!\n", comp_rate * 100); ++ ++ return ret; ++} ++ ++static int load_file_data(const char *alg, u32 pkg_len, u32 optype) ++{ ++ struct zip_file_head *fhead = NULL; ++ char file_path[PATH_SIZE]; ++ ssize_t size = 0xff; ++ int i, j, fd; ++ int ret; ++ ++ optype = optype % WD_DIR_MAX; ++ if (optype != WD_DIR_DECOMPRESS) //decompress ++ return 0; ++ ++ ret = snprintf(file_path, PATH_SIZE, "%s_%u.%s", ZIP_FILE, pkg_len, alg); ++ if (ret < 0) ++ return -EINVAL; ++ ++ ret = access(file_path, F_OK); ++ if (ret) { ++ ZIP_TST_PRT("Decompress data file: %s not exist!\n", file_path); ++ return -EINVAL; ++ } ++ ++ // read data from file ++ fd = open(file_path, O_RDONLY, 0); ++ if (fd < 0) { ++ ZIP_TST_PRT("Decompress data file open %s fail (%d)!\n", file_path, -errno); ++ return -ENODEV; ++ } ++ ++ fhead = malloc(sizeof(*fhead)); ++ if (!fhead) { ++ ZIP_TST_PRT("failed to alloc file head memory\n"); ++ ret = -ENOMEM; ++ goto fd_err; ++ } ++ size = read(fd, fhead, sizeof(*fhead)); ++ if (size < 0 || fhead->block_num != MAX_POOL_LENTH) { ++ ZIP_TST_PRT("failed to read file head\n"); ++ ret = -EINVAL; ++ goto read_err; ++ } ++ ++ // read data for one buffer one buffer from file line ++ for (j = 0; j < MAX_POOL_LENTH; j++) { ++ memset(g_zip_pool.pool[0].bds[j].src, 0x0, ++ g_zip_pool.pool[0].bds[j].src_len); ++ if (size != 0) { // zero size buffer no need to read; ++ size = read(fd, g_zip_pool.pool[0].bds[j].src, ++ fhead->blk_sz[j]); ++ if (size < 0) { ++ ZIP_TST_PRT("Decompress read data error size: %lu!\n", size); ++ ret = -EINVAL; ++ goto read_err; ++ } else if (size == 0) { ++ ZIP_TST_PRT("Read file to the end!"); ++ } ++ } ++ g_zip_pool.pool[0].bds[j].src_len = size; ++ } ++ ++ for (i = 1; i < g_thread_num; i++) { ++ for (j = 0; j < MAX_POOL_LENTH; j++) { ++ if (g_zip_pool.pool[0].bds[j].src_len) ++ memcpy(g_zip_pool.pool[i].bds[j].src, ++ g_zip_pool.pool[0].bds[j].src, ++ g_zip_pool.pool[0].bds[j].src_len); ++ g_zip_pool.pool[i].bds[j].src_len = ++ g_zip_pool.pool[0].bds[j].src_len; ++ } ++ } ++ ++read_err: ++ free(fhead); ++fd_err: ++ close(fd); ++ ++ return ret; ++} ++ ++static int zip_uadk_param_parse(thread_data *tddata, struct acc_option *options) ++{ ++ u32 algtype = options->algtype; ++ u32 optype = options->optype; ++ u8 mode = BLOCK_MODE; ++ u8 alg; ++ ++ if (optype >= WD_DIR_MAX << 1) { ++ ZIP_TST_PRT("Fail to get zip optype!\n"); ++ return -EINVAL; ++ } else if (optype >= WD_DIR_MAX) { ++ mode = STREAM_MODE; ++ } ++ ++ optype = optype % WD_DIR_MAX; ++ ++ switch(algtype) { ++ case ZLIB: ++ alg = WD_ZLIB; ++ break; ++ case GZIP: ++ alg = WD_GZIP; ++ break; ++ case DEFLATE: ++ alg = WD_DEFLATE; ++ break; ++ case LZ77_ZSTD: ++ alg = WD_LZ77_ZSTD; ++ if (optype == WD_DIR_DECOMPRESS) ++ ZIP_TST_PRT("Zip LZ77_ZSTD just support compress!\n"); ++ optype = WD_DIR_COMPRESS; ++ break; ++ default: ++ ZIP_TST_PRT("Fail to set zip alg\n"); ++ return -EINVAL; ++ } ++ ++ tddata->alg = alg; ++ tddata->mode = mode; ++ tddata->optype = optype; ++ ++ return 0; ++} ++ ++static int init_ctx_config(char *alg, int mode, int optype) ++{ ++ struct uacce_dev_list *list; ++ struct sched_params param; ++ int i, max_node; ++ int ret = 0; ++ ++ max_node = numa_max_node() + 1; ++ if (max_node <= 0) ++ return -EINVAL; ++ ++ list = wd_get_accel_list(alg); ++ if (!list) { ++ ZIP_TST_PRT("Fail to get %s device\n", alg); ++ return -ENODEV; ++ } ++ memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config)); ++ g_ctx_cfg.ctx_num = g_ctxnum; ++ g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx)); ++ if (!g_ctx_cfg.ctxs) ++ return -ENOMEM; ++ ++ g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 2, max_node, wd_comp_poll_ctx); ++ if (!g_sched) { ++ ZIP_TST_PRT("Fail to alloc sched!\n"); ++ goto out; ++ } ++ ++ /* If there is no numa, we defualt config to zero */ ++ if (list->dev->numa_id < 0) ++ list->dev->numa_id = 0; ++ ++ for (i = 0; i < g_ctxnum; i++) { ++ g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(list->dev); ++ g_ctx_cfg.ctxs[i].op_type = 0; // default op_type ++ g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode; ++ } ++ g_sched->name = SCHED_SINGLE; ++ ++ /* ++ * All contexts for 2 modes & 2 types. ++ * The test only uses one kind of contexts at the same time. ++ */ ++ optype = optype % WD_DIR_MAX; ++ param.numa_id = list->dev->numa_id; ++ param.type = optype; ++ param.mode = mode; ++ param.begin = 0; ++ param.end = g_ctxnum - 1; ++ ret = wd_sched_rr_instance(g_sched, ¶m); ++ if (ret) { ++ ZIP_TST_PRT("Fail to fill sched data!\n"); ++ goto out; ++ } ++ ++ /* init */ ++ ret = wd_comp_init(&g_ctx_cfg, g_sched); ++ if (ret) { ++ ZIP_TST_PRT("Fail to cipher ctx!\n"); ++ goto out; ++ } ++ ++ wd_free_list_accels(list); ++ ++ return 0; ++out: ++ free(g_ctx_cfg.ctxs); ++ wd_sched_rr_release(g_sched); ++ ++ return ret; ++} ++ ++static void uninit_ctx_config(void) ++{ ++ int i; ++ ++ /* uninit */ ++ wd_comp_uninit(); ++ ++ for (i = 0; i < g_ctx_cfg.ctx_num; i++) ++ wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); ++ free(g_ctx_cfg.ctxs); ++ wd_sched_rr_release(g_sched); ++} ++ ++static int init_uadk_bd_pool(u32 optype) ++{ ++ u32 outsize; ++ u32 insize; ++ int i, j; ++ ++ // make the block not align to 4K ++ optype = optype % WD_DIR_MAX; ++ if (optype == WD_DIR_COMPRESS) {//compress ++ insize = g_pktlen; ++ outsize = g_pktlen * COMP_LEN_RATE; ++ } else { // decompress ++ insize = g_pktlen; ++ outsize = g_pktlen * DECOMP_LEN_RATE; ++ } ++ ++ g_zip_pool.pool = malloc(g_thread_num * sizeof(struct bd_pool)); ++ if (!g_zip_pool.pool) { ++ ZIP_TST_PRT("init uadk pool alloc thread failed!\n"); ++ return -ENOMEM; ++ } else { ++ for (i = 0; i < g_thread_num; i++) { ++ g_zip_pool.pool[i].bds = malloc(MAX_POOL_LENTH * ++ sizeof(struct uadk_bd)); ++ if (!g_zip_pool.pool[i].bds) { ++ ZIP_TST_PRT("init uadk bds alloc failed!\n"); ++ goto malloc_error1; ++ } ++ for (j = 0; j < MAX_POOL_LENTH; j++) { ++ g_zip_pool.pool[i].bds[j].src = malloc(insize); ++ if (!g_zip_pool.pool[i].bds[j].src) ++ goto malloc_error2; ++ g_zip_pool.pool[i].bds[j].src_len = insize; ++ ++ g_zip_pool.pool[i].bds[j].dst = malloc(outsize); ++ if (!g_zip_pool.pool[i].bds[j].dst) ++ goto malloc_error3; ++ g_zip_pool.pool[i].bds[j].dst_len = outsize; ++ ++ get_rand_data(g_zip_pool.pool[i].bds[j].src, insize); ++ if (g_prefetch) ++ get_rand_data(g_zip_pool.pool[i].bds[j].dst, outsize); ++ } ++ } ++ } ++ ++ return 0; ++ ++malloc_error3: ++ free(g_zip_pool.pool[i].bds[j].src); ++malloc_error2: ++ for (j--; j >= 0; j--) { ++ free(g_zip_pool.pool[i].bds[j].src); ++ free(g_zip_pool.pool[i].bds[j].dst); ++ } ++malloc_error1: ++ for (i--; i >= 0; i--) { ++ for (j = 0; j < MAX_POOL_LENTH; j++) { ++ free(g_zip_pool.pool[i].bds[j].src); ++ free(g_zip_pool.pool[i].bds[j].dst); ++ } ++ free(g_zip_pool.pool[i].bds); ++ g_zip_pool.pool[i].bds = NULL; ++ } ++ free(g_zip_pool.pool); ++ g_zip_pool.pool = NULL; ++ ++ ZIP_TST_PRT("init uadk bd pool alloc failed!\n"); ++ return -ENOMEM; ++} ++ ++static void free_uadk_bd_pool(void) ++{ ++ int i, j; ++ ++ for (i = 0; i < g_thread_num; i++) { ++ if (g_zip_pool.pool[i].bds) { ++ for (j = 0; j < MAX_POOL_LENTH; j++) { ++ free(g_zip_pool.pool[i].bds[j].src); ++ free(g_zip_pool.pool[i].bds[j].dst); ++ } ++ } ++ free(g_zip_pool.pool[i].bds); ++ g_zip_pool.pool[i].bds = NULL; ++ } ++ free(g_zip_pool.pool); ++ g_zip_pool.pool = NULL; ++} ++ ++/*-------------------------------uadk benchmark main code-------------------------------------*/ ++static void *zip_lz77_async_cb(struct wd_comp_req *req, void *data) ++{ ++ struct zip_async_tag *tag = req->cb_param; ++ struct bd_pool *uadk_pool; ++ int td_id = tag->td_id; ++ int idx = tag->bd_idx; ++ ZSTD_inBuffer zstd_input; ++ ZSTD_outBuffer zstd_output; ++ ZSTD_CCtx *cctx = tag->cctx; ++ size_t fse_size; ++ ++ uadk_pool = &g_zip_pool.pool[td_id]; ++ uadk_pool->bds[idx].dst_len = req->dst_len; ++ ++ zstd_input.src = req->src; ++ zstd_input.size = req->src_len; ++ zstd_input.pos = 0; ++ zstd_output.dst = uadk_pool->bds[idx].dst; ++ zstd_output.size = tag->cm_len; ++ zstd_output.pos = 0; ++ fse_size = zstd_soft_fse(req->priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end); ++ ++ uadk_pool->bds[idx].dst_len = fse_size; ++ ++ return NULL; ++} ++ ++static void *zip_async_cb(struct wd_comp_req *req, void *data) ++{ ++ struct zip_async_tag *tag = req->cb_param; ++ struct bd_pool *uadk_pool; ++ int td_id = tag->td_id; ++ int idx = tag->bd_idx; ++ ++ uadk_pool = &g_zip_pool.pool[td_id]; ++ uadk_pool->bds[idx].dst_len = req->dst_len; ++ ++ return NULL; ++} ++ ++static void *zip_uadk_poll(void *data) ++{ ++ thread_data *pdata = (thread_data *)data; ++ u32 expt = ACC_QUEUE_SIZE * g_thread_num; ++ u32 id = pdata->td_id; ++ u32 last_time = 2; // poll need one more recv time ++ u32 count = 0; ++ u32 recv = 0; ++ int ret; ++ ++ if (id > g_ctxnum) ++ return NULL; ++ ++ while (last_time) { ++ ret = wd_comp_poll_ctx(id, expt, &recv); ++ count += recv; ++ recv = 0; ++ if (unlikely(ret != -WD_EAGAIN && ret < 0)) { ++ ZIP_TST_PRT("poll ret: %u!\n", ret); ++ goto recv_error; ++ } ++ ++ if (get_run_state() == 0) ++ last_time--; ++ } ++ ++recv_error: ++ add_recv_data(count, g_pktlen); ++ ++ return NULL; ++} ++ ++static void *zip_uadk_blk_lz77_sync_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ struct wd_comp_sess_setup comp_setup = {0}; ++ ZSTD_CCtx *cctx = zstd_soft_fse_init(15); ++ ZSTD_inBuffer zstd_input = {0}; ++ ZSTD_outBuffer zstd_output = {0}; ++ COMP_TUPLE_TAG *ftuple = NULL; ++ struct bd_pool *uadk_pool; ++ struct wd_comp_req creq; ++ char *hw_buff_out = NULL; ++ size_t fse_size; ++ handle_t h_sess; ++ u32 first_len = 0; ++ u32 out_len = 0; ++ u32 count = 0; ++ int ret, i = 0; ++ ++ if (pdata->td_id > g_thread_num) ++ return NULL; ++ ++ uadk_pool = &g_zip_pool.pool[pdata->td_id]; ++ memset(&comp_setup, 0, sizeof(comp_setup)); ++ memset(&creq, 0, sizeof(creq)); ++ ++ comp_setup.alg_type = pdata->alg; ++ comp_setup.op_type = pdata->optype; ++ comp_setup.comp_lv = WD_COMP_L8; ++ comp_setup.win_sz = WD_COMP_WS_8K; ++ h_sess = wd_comp_alloc_sess(&comp_setup); ++ if (!h_sess) ++ return NULL; ++ ++ creq.op_type = pdata->optype; ++ creq.src_len = g_pktlen; ++ out_len = uadk_pool->bds[0].dst_len; ++ ++ creq.cb = NULL; ++ creq.data_fmt = 0; ++ creq.status = 0; ++ ++ ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH); ++ if (!ftuple) ++ goto fse_err; ++ ++ hw_buff_out = malloc(out_len * MAX_POOL_LENTH); ++ if (!hw_buff_out) ++ goto hw_buff_err; ++ memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH); ++ ++ while(1) { ++ i = count % MAX_POOL_LENTH; ++ creq.src = uadk_pool->bds[i].src; ++ creq.dst = &hw_buff_out[i]; //temp out ++ creq.src_len = uadk_pool->bds[i].src_len; ++ creq.dst_len = out_len; ++ creq.priv = &ftuple[i]; ++ ++ ret = wd_do_comp_sync(h_sess, &creq); ++ if (ret || creq.status) ++ break; ++ ++ count++; ++ zstd_input.src = creq.src; ++ zstd_input.size = creq.src_len; ++ zstd_input.pos = 0; ++ zstd_output.dst = uadk_pool->bds[i].dst; ++ zstd_output.size = out_len; ++ zstd_output.pos = 0; ++ fse_size = zstd_soft_fse(creq.priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end); ++ ++ uadk_pool->bds[i].dst_len = fse_size; ++ if (unlikely(i == 0)) ++ first_len = fse_size; ++ if (get_run_state() == 0) ++ break; ++ } ++ ++hw_buff_err: ++ free(hw_buff_out); ++fse_err: ++ free(ftuple); ++ wd_comp_free_sess(h_sess); ++ ++ // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", ++ // MAX_POOL_LENTH, count, creq.dst_len); ++ if (pdata->optype == WD_DIR_COMPRESS) ++ add_recv_data(count, creq.src_len); ++ else ++ add_recv_data(count, first_len); ++ ++ return NULL; ++} ++ ++static void *zip_uadk_stm_lz77_sync_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ struct wd_comp_sess_setup comp_setup = {0}; ++ ZSTD_CCtx *cctx = zstd_soft_fse_init(15); ++ ZSTD_inBuffer zstd_input = {0}; ++ ZSTD_outBuffer zstd_output = {0}; ++ COMP_TUPLE_TAG *ftuple = NULL; ++ struct bd_pool *uadk_pool; ++ struct wd_comp_req creq; ++ char *hw_buff_out = NULL; ++ size_t fse_size; ++ handle_t h_sess; ++ u32 first_len = 0; ++ u32 out_len = 0; ++ u32 count = 0; ++ int ret, i = 0; ++ ++ if (pdata->td_id > g_thread_num) ++ return NULL; ++ ++ uadk_pool = &g_zip_pool.pool[pdata->td_id]; ++ memset(&comp_setup, 0, sizeof(comp_setup)); ++ memset(&creq, 0, sizeof(creq)); ++ ++ comp_setup.alg_type = pdata->alg; ++ comp_setup.op_type = pdata->optype; ++ comp_setup.comp_lv = WD_COMP_L8; ++ comp_setup.win_sz = WD_COMP_WS_8K; ++ h_sess = wd_comp_alloc_sess(&comp_setup); ++ if (!h_sess) ++ return NULL; ++ ++ creq.op_type = pdata->optype; ++ creq.src_len = g_pktlen; ++ out_len = uadk_pool->bds[0].dst_len; ++ ++ creq.cb = NULL; ++ creq.data_fmt = 0; ++ creq.status = 0; ++ ++ ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH); ++ if (!ftuple) ++ goto fse_err; ++ ++ hw_buff_out = malloc(out_len * MAX_POOL_LENTH); ++ if (!hw_buff_out) ++ goto hw_buff_err; ++ memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH); ++ ++ while(1) { ++ i = count % MAX_POOL_LENTH; ++ creq.src = uadk_pool->bds[i].src; ++ creq.dst = &hw_buff_out[i]; //temp out ++ creq.src_len = uadk_pool->bds[i].src_len; ++ creq.dst_len = out_len; ++ creq.priv = &ftuple[i]; ++ ++ ret = wd_do_comp_strm(h_sess, &creq); ++ if (ret < 0 || creq.status == WD_IN_EPARA) { ++ ZIP_TST_PRT("wd comp, invalid or incomplete data! " ++ "ret(%d), req.status(%u)\n", ret, creq.status); ++ break; ++ } ++ ++ count++; ++ zstd_input.src = creq.src; ++ zstd_input.size = creq.src_len; ++ zstd_input.pos = 0; ++ zstd_output.dst = uadk_pool->bds[i].dst; ++ zstd_output.size = out_len; ++ zstd_output.pos = 0; ++ fse_size = zstd_soft_fse(creq.priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end); ++ ++ uadk_pool->bds[i].dst_len = fse_size; ++ if (unlikely(i == 0)) ++ first_len = fse_size; ++ if (get_run_state() == 0) ++ break; ++ } ++ ++hw_buff_err: ++ free(hw_buff_out); ++fse_err: ++ free(ftuple); ++ wd_comp_free_sess(h_sess); ++ ++ // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", ++ // MAX_POOL_LENTH, count, creq.dst_len); ++ if (pdata->optype == WD_DIR_COMPRESS) ++ add_recv_data(count, creq.src_len); ++ else ++ add_recv_data(count, first_len); ++ ++ return NULL; ++} ++ ++static void *zip_uadk_blk_lz77_async_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ struct wd_comp_sess_setup comp_setup = {0}; ++ ZSTD_CCtx *cctx = zstd_soft_fse_init(15); ++ COMP_TUPLE_TAG *ftuple = NULL; ++ struct bd_pool *uadk_pool; ++ struct wd_comp_req creq; ++ struct zip_async_tag *tag; ++ char *hw_buff_out = NULL; ++ handle_t h_sess; ++ u32 out_len = 0; ++ u32 count = 0; ++ u32 try_cnt = 0; ++ int ret, i = 0; ++ ++ if (pdata->td_id > g_thread_num) ++ return NULL; ++ ++ uadk_pool = &g_zip_pool.pool[pdata->td_id]; ++ memset(&comp_setup, 0, sizeof(comp_setup)); ++ memset(&creq, 0, sizeof(creq)); ++ ++ comp_setup.alg_type = pdata->alg; ++ comp_setup.op_type = pdata->optype; ++ comp_setup.comp_lv = WD_COMP_L8; ++ comp_setup.win_sz = WD_COMP_WS_8K; ++ h_sess = wd_comp_alloc_sess(&comp_setup); ++ if (!h_sess) ++ return NULL; ++ ++ creq.op_type = pdata->optype; ++ creq.src_len = g_pktlen; ++ out_len = uadk_pool->bds[0].dst_len; ++ ++ creq.cb = zip_lz77_async_cb; ++ creq.data_fmt = 0; ++ creq.status = 0; ++ ++ ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH); ++ if (!ftuple) ++ goto fse_err; ++ ++ hw_buff_out = malloc(out_len * MAX_POOL_LENTH); ++ if (!hw_buff_out) ++ goto hw_buff_err; ++ memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH); ++ ++ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); ++ if (!tag) { ++ ZIP_TST_PRT("failed to malloc zip tag!\n"); ++ goto tag_err; ++ } ++ ++ while(1) { ++ if (get_run_state() == 0) ++ break; ++ ++ try_cnt = 0; ++ i = count % MAX_POOL_LENTH; ++ creq.src = uadk_pool->bds[i].src; ++ creq.dst = &hw_buff_out[i]; //temp out ++ creq.src_len = uadk_pool->bds[i].src_len; ++ creq.dst_len = out_len; ++ creq.priv = &ftuple[i]; ++ ++ tag[i].td_id = pdata->td_id; ++ tag[i].bd_idx = i; ++ tag[i].cm_len = out_len; ++ tag[i].cctx = cctx; ++ creq.cb_param = &tag[i]; ++ ++ ret = wd_do_comp_async(h_sess, &creq); ++ if (ret == -WD_EBUSY) { ++ usleep(SEND_USLEEP * try_cnt); ++ try_cnt++; ++ if (try_cnt > MAX_TRY_CNT) { ++ ZIP_TST_PRT("Test LZ77 compress send fail %d times!\n", MAX_TRY_CNT); ++ try_cnt = 0; ++ } ++ continue; ++ } else if (ret || creq.status) { ++ break; ++ } ++ count++; ++ } ++ ++ while (1) { ++ if (get_recv_time() > 0) // wait Async mode finish recv ++ break; ++ usleep(SEND_USLEEP); ++ } ++ ++tag_err: ++ free(tag); ++hw_buff_err: ++ free(hw_buff_out); ++fse_err: ++ free(ftuple); ++ wd_comp_free_sess(h_sess); ++ ++ // ZIP_TST_PRT("LZ77 valid pool len: %u, send count BD: %u, output len: %u!\n", ++ // MAX_POOL_LENTH, count, creq.dst_len); ++ ++ add_send_complete(); ++ ++ return NULL; ++} ++ ++static void *zip_uadk_blk_sync_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ struct wd_comp_sess_setup comp_setup = {0}; ++ struct bd_pool *uadk_pool; ++ struct wd_comp_req creq; ++ handle_t h_sess; ++ u32 out_len = 0; ++ u32 count = 0; ++ int ret, i = 0; ++ ++ if (pdata->td_id > g_thread_num) ++ return NULL; ++ ++ uadk_pool = &g_zip_pool.pool[pdata->td_id]; ++ memset(&comp_setup, 0, sizeof(comp_setup)); ++ memset(&creq, 0, sizeof(creq)); ++ ++ comp_setup.alg_type = pdata->alg; ++ comp_setup.op_type = pdata->optype; ++ comp_setup.comp_lv = WD_COMP_L8; ++ comp_setup.win_sz = WD_COMP_WS_8K; ++ h_sess = wd_comp_alloc_sess(&comp_setup); ++ if (!h_sess) ++ return NULL; ++ ++ creq.op_type = pdata->optype; ++ creq.src_len = g_pktlen; ++ out_len = uadk_pool->bds[0].dst_len; ++ ++ creq.cb = NULL; ++ creq.data_fmt = 0; ++ creq.priv = 0; ++ creq.status = 0; ++ ++ while(1) { ++ i = count % MAX_POOL_LENTH; ++ creq.src = uadk_pool->bds[i].src; ++ creq.dst = uadk_pool->bds[i].dst; ++ creq.src_len = uadk_pool->bds[i].src_len; ++ creq.dst_len = out_len; ++ ++ ret = wd_do_comp_sync(h_sess, &creq); ++ if (ret || creq.status) ++ break; ++ ++ count++; ++ uadk_pool->bds[i].dst_len = creq.dst_len; ++ if (get_run_state() == 0) ++ break; ++ } ++ wd_comp_free_sess(h_sess); ++ ++ //ZIP_TST_PRT("valid pool len: %u, send count BD: %u, input len: %u, output len: %u!\n", ++ // MAX_POOL_LENTH, count, creq.src_len, g_pktlen); ++ add_recv_data(count, g_pktlen); ++ ++ return NULL; ++} ++ ++static void *zip_uadk_stm_sync_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ struct wd_comp_sess_setup comp_setup = {0}; ++ struct bd_pool *uadk_pool; ++ struct wd_comp_req creq; ++ handle_t h_sess; ++ u32 out_len = 0; ++ u32 count = 0; ++ int ret, i = 0; ++ ++ if (pdata->td_id > g_thread_num) ++ return NULL; ++ ++ uadk_pool = &g_zip_pool.pool[pdata->td_id]; ++ memset(&comp_setup, 0, sizeof(comp_setup)); ++ memset(&creq, 0, sizeof(creq)); ++ ++ comp_setup.alg_type = pdata->alg; ++ comp_setup.op_type = pdata->optype; ++ comp_setup.comp_lv = WD_COMP_L8; ++ comp_setup.win_sz = WD_COMP_WS_8K; ++ h_sess = wd_comp_alloc_sess(&comp_setup); ++ if (!h_sess) ++ return NULL; ++ ++ creq.op_type = pdata->optype; ++ creq.src_len = g_pktlen; ++ out_len = uadk_pool->bds[0].dst_len; ++ ++ creq.cb = NULL; ++ creq.data_fmt = 0; ++ creq.priv = 0; ++ creq.status = 0; ++ ++ while(1) { ++ i = count % MAX_POOL_LENTH; ++ creq.src = uadk_pool->bds[i].src; ++ creq.dst = uadk_pool->bds[i].dst; ++ creq.src_len = uadk_pool->bds[i].src_len; ++ creq.dst_len = out_len; ++ ++ ret = wd_do_comp_strm(h_sess, &creq); ++ if (ret < 0 || creq.status == WD_IN_EPARA) { ++ ZIP_TST_PRT("wd comp, invalid or incomplete data! " ++ "ret(%d), req.status(%u)\n", ret, creq.status); ++ break; ++ } ++ ++ count++; ++ uadk_pool->bds[i].dst_len = creq.dst_len; ++ ++ if (get_run_state() == 0) ++ break; ++ } ++ wd_comp_free_sess(h_sess); ++ ++ // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", ++ // MAX_POOL_LENTH, count, creq.dst_len); ++ add_recv_data(count, g_pktlen); ++ ++ return NULL; ++} ++ ++static void *zip_uadk_blk_async_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ struct wd_comp_sess_setup comp_setup = {0}; ++ struct bd_pool *uadk_pool; ++ struct zip_async_tag *tag; ++ struct wd_comp_req creq; ++ handle_t h_sess; ++ int try_cnt = 0; ++ u32 out_len = 0; ++ u32 count = 0; ++ int ret, i = 0; ++ ++ if (pdata->td_id > g_thread_num) ++ return NULL; ++ ++ uadk_pool = &g_zip_pool.pool[pdata->td_id]; ++ memset(&comp_setup, 0, sizeof(comp_setup)); ++ memset(&creq, 0, sizeof(creq)); ++ ++ comp_setup.alg_type = pdata->alg; ++ comp_setup.op_type = pdata->optype; ++ comp_setup.comp_lv = WD_COMP_L8; ++ comp_setup.win_sz = WD_COMP_WS_8K; ++ h_sess = wd_comp_alloc_sess(&comp_setup); ++ if (!h_sess) ++ return NULL; ++ ++ creq.op_type = pdata->optype; ++ creq.src_len = g_pktlen; ++ out_len = uadk_pool->bds[0].dst_len; ++ ++ creq.cb = zip_async_cb; ++ creq.data_fmt = 0; ++ creq.priv = 0; ++ creq.status = 0; ++ ++ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); ++ if (!tag) { ++ ZIP_TST_PRT("failed to malloc zip tag!\n"); ++ wd_comp_free_sess(h_sess); ++ return NULL; ++ } ++ ++ while(1) { ++ if (get_run_state() == 0) ++ break; ++ ++ try_cnt = 0; ++ i = count % MAX_POOL_LENTH; ++ creq.src = uadk_pool->bds[i].src; ++ creq.dst = uadk_pool->bds[i].dst; ++ creq.src_len = uadk_pool->bds[i].src_len; ++ creq.dst_len = out_len; ++ ++ tag[i].td_id = pdata->td_id; ++ tag[i].bd_idx = i; ++ creq.cb_param = &tag[i]; ++ ++ ret = wd_do_comp_async(h_sess, &creq); ++ if (ret == -WD_EBUSY) { ++ usleep(SEND_USLEEP * try_cnt); ++ try_cnt++; ++ if (try_cnt > MAX_TRY_CNT) { ++ ZIP_TST_PRT("Test compress send fail %d times!\n", MAX_TRY_CNT); ++ try_cnt = 0; ++ } ++ continue; ++ } else if (ret || creq.status) { ++ break; ++ } ++ count++; ++ } ++ ++ while (1) { ++ if (get_recv_time() > 0) // wait Async mode finish recv ++ break; ++ usleep(SEND_USLEEP); ++ } ++ ++ free(tag); ++ wd_comp_free_sess(h_sess); ++ ++ // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", ++ // MAX_POOL_LENTH, count, creq.dst_len); ++ ++ add_send_complete(); ++ ++ return NULL; ++} ++ ++static int zip_uadk_sync_threads(struct acc_option *options) ++{ ++ typedef void *(*zip_sync_run)(void *arg); ++ zip_sync_run uadk_zip_sync_run = NULL; ++ thread_data threads_args[THREADS_NUM]; ++ thread_data threads_option; ++ pthread_t tdid[THREADS_NUM]; ++ int i, ret; ++ ++ /* alg param parse and set to thread data */ ++ ret = zip_uadk_param_parse(&threads_option, options); ++ if (ret) ++ return ret; ++ ++ if (threads_option.mode == 1) {// stream mode ++ if (threads_option.alg == LZ77_ZSTD) ++ uadk_zip_sync_run = zip_uadk_stm_lz77_sync_run; ++ else ++ uadk_zip_sync_run = zip_uadk_stm_sync_run; ++ } else { ++ if (threads_option.alg == LZ77_ZSTD) ++ uadk_zip_sync_run = zip_uadk_blk_lz77_sync_run; ++ else ++ uadk_zip_sync_run = zip_uadk_blk_sync_run; ++ } ++ for (i = 0; i < g_thread_num; i++) { ++ threads_args[i].alg = threads_option.alg; ++ threads_args[i].mode = threads_option.mode; ++ threads_args[i].optype = threads_option.optype; ++ threads_args[i].td_id = i; ++ ret = pthread_create(&tdid[i], NULL, uadk_zip_sync_run, &threads_args[i]); ++ if (ret) { ++ ZIP_TST_PRT("Create sync thread fail!\n"); ++ goto sync_error; ++ } ++ } ++ ++ /* join thread */ ++ for (i = 0; i < g_thread_num; i++) { ++ ret = pthread_join(tdid[i], NULL); ++ if (ret) { ++ ZIP_TST_PRT("Join sync thread fail!\n"); ++ goto sync_error; ++ } ++ } ++ ++sync_error: ++ return ret; ++} ++ ++static int zip_uadk_async_threads(struct acc_option *options) ++{ ++ typedef void *(*zip_async_run)(void *arg); ++ zip_async_run uadk_zip_async_run = NULL; ++ thread_data threads_args[THREADS_NUM]; ++ thread_data threads_option; ++ pthread_t tdid[THREADS_NUM]; ++ pthread_t pollid[THREADS_NUM]; ++ int i, ret; ++ ++ /* alg param parse and set to thread data */ ++ ret = zip_uadk_param_parse(&threads_option, options); ++ if (ret) ++ return ret; ++ ++ if (threads_option.mode == STREAM_MODE) {// stream mode ++ ZIP_TST_PRT("Stream mode can't support async mode!\n"); ++ return 0; ++ } ++ ++ if (threads_option.alg == LZ77_ZSTD) ++ uadk_zip_async_run = zip_uadk_blk_lz77_async_run; ++ else ++ uadk_zip_async_run = zip_uadk_blk_async_run; ++ ++ for (i = 0; i < g_ctxnum; i++) { ++ threads_args[i].td_id = i; ++ /* poll thread */ ++ ret = pthread_create(&pollid[i], NULL, zip_uadk_poll, &threads_args[i]); ++ if (ret) { ++ ZIP_TST_PRT("Create poll thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++ for (i = 0; i < g_thread_num; i++) { ++ threads_args[i].alg = threads_option.alg; ++ threads_args[i].mode = threads_option.mode; ++ threads_args[i].optype = threads_option.optype; ++ threads_args[i].td_id = i; ++ ret = pthread_create(&tdid[i], NULL, uadk_zip_async_run, &threads_args[i]); ++ if (ret) { ++ ZIP_TST_PRT("Create async thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++ /* join thread */ ++ for (i = 0; i < g_thread_num; i++) { ++ ret = pthread_join(tdid[i], NULL); ++ if (ret) { ++ ZIP_TST_PRT("Join async thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++ for (i = 0; i < g_ctxnum; i++) { ++ ret = pthread_join(pollid[i], NULL); ++ if (ret) { ++ ZIP_TST_PRT("Join poll thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++async_error: ++ return ret; ++} ++ ++int zip_uadk_benchmark(struct acc_option *options) ++{ ++ u32 ptime; ++ int ret; ++ ++ g_thread_num = options->threads; ++ g_pktlen = options->pktlen; ++ g_ctxnum = options->ctxnums; ++ g_prefetch = options->prefetch; ++ ++ if (options->optype >= WD_DIR_MAX * 2) { ++ ZIP_TST_PRT("ZIP optype error: %u\n", options->optype); ++ return -EINVAL; ++ } ++ ++ ret = init_ctx_config(options->algclass, options->syncmode, options->optype); ++ if (ret) ++ return ret; ++ ++ ret = init_uadk_bd_pool(options->optype); ++ if (ret) ++ return ret; ++ ++ ret = load_file_data(options->algname, options->pktlen, options->optype); ++ if (ret) ++ return ret; ++ ++ get_pid_cpu_time(&ptime); ++ time_start(options->times); ++ if (options->syncmode) ++ ret = zip_uadk_async_threads(options); ++ else ++ ret = zip_uadk_sync_threads(options); ++ cal_perfermance_data(options, ptime); ++ if (ret) ++ return ret; ++ ++ ret = save_file_data(options->algname, options->pktlen, options->optype); ++ if (ret) ++ return ret; ++ ++ free_uadk_bd_pool(); ++ uninit_ctx_config(); ++ ++ return 0; ++} +diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.h b/uadk_tool/benchmark/zip_uadk_benchmark.h +new file mode 100644 +index 0000000..a3cfbc0 +--- /dev/null ++++ b/uadk_tool/benchmark/zip_uadk_benchmark.h +@@ -0,0 +1,6 @@ ++/* SPDX-License-Identifier: Apache-2.0 */ ++#ifndef ZIP_UADK_BENCHMARK_H ++#define ZIP_UADK_BENCHMARK_H ++ ++extern int zip_uadk_benchmark(struct acc_option *options); ++#endif /* ZIP_UADK_BENCHMARK_H */ +-- +2.27.0 + diff --git a/0137-uadk_tool-Add-NO-SVA-mode-test-function-for-ZIP-modu.patch b/0137-uadk_tool-Add-NO-SVA-mode-test-function-for-ZIP-modu.patch new file mode 100644 index 0000000..fee9e37 --- /dev/null +++ b/0137-uadk_tool-Add-NO-SVA-mode-test-function-for-ZIP-modu.patch @@ -0,0 +1,1295 @@ +From ffa9424facf439dc4990be891e2e84fa317eaf38 Mon Sep 17 00:00:00 2001 +From: Longfang Liu +Date: Mon, 18 Jul 2022 17:16:35 +0800 +Subject: [PATCH 151/183] uadk_tool: Add NO-SVA mode test function for ZIP + module + +Add NO-SVA mode performance test function for Zlib, +Gzip algorithm of ZIP module. + +Signed-off-by: Longfang Liu +--- + uadk_tool/benchmark/zip_wd_benchmark.c | 1257 ++++++++++++++++++++++++ + uadk_tool/benchmark/zip_wd_benchmark.h | 6 + + 2 files changed, 1263 insertions(+) + create mode 100644 uadk_tool/benchmark/zip_wd_benchmark.c + create mode 100644 uadk_tool/benchmark/zip_wd_benchmark.h + +diff --git a/uadk_tool/benchmark/zip_wd_benchmark.c b/uadk_tool/benchmark/zip_wd_benchmark.c +new file mode 100644 +index 0000000..0df78cd +--- /dev/null ++++ b/uadk_tool/benchmark/zip_wd_benchmark.c +@@ -0,0 +1,1257 @@ ++/* SPDX-License-Identifier: Apache-2.0 */ ++ ++#include ++#include "uadk_benchmark.h" ++ ++#include "zip_wd_benchmark.h" ++#include "v1/wd_comp.h" ++#include "v1/wd.h" ++#include "v1/wd_bmm.h" ++#include "v1/wd_util.h" ++#include "include/fse.h" ++ ++#define ZIP_TST_PRT printf ++#define PATH_SIZE 64 ++#define ZIP_FILE "./zip" ++#define WCRYPTO_DIR_MAX (WCRYPTO_INFLATE + 1) ++#define ALIGN_SIZE 64 ++ ++#define COMP_LEN_RATE 2 ++#define DECOMP_LEN_RATE 2 ++ ++#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) ++#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) ++ ++struct wd_bd { ++ u8 *src; ++ u8 *dst; ++ u32 src_len; ++ u32 dst_len; ++}; ++ ++struct thread_bd_res { ++ struct wd_queue *queue; ++ void *pool; ++ struct wd_bd *bds; ++}; ++ ++struct thread_queue_res { ++ struct thread_bd_res *bd_res; ++}; ++ ++static struct thread_queue_res g_thread_queue; ++ ++enum ZIP_OP_MODE { ++ BLOCK_MODE, ++ STREAM_MODE ++}; ++ ++struct zip_async_tag { ++ void *ctx; ++ u32 td_id; ++ u32 bd_idx; ++ u32 cm_len; ++ void *priv; ++ ZSTD_CCtx *cctx; ++}; ++ ++typedef struct uadk_thread_res { ++ u32 alg; ++ u32 mode; // block/stream ++ u32 optype; ++ u32 td_id; ++} thread_data; ++ ++struct zip_file_head { ++ u32 file_size; ++ u32 block_num; ++ u32 blk_sz[MAX_POOL_LENTH]; ++}; ++ ++static unsigned int g_thread_num; ++static unsigned int g_pktlen; ++ ++#ifndef ZLIB_FSE ++static ZSTD_CCtx* zstd_soft_fse_init(unsigned int level) ++{ ++ return NULL; ++} ++ ++static int zstd_soft_fse(void *Ftuple, ZSTD_inBuffer *input, ZSTD_outBuffer *output, ZSTD_CCtx * cctx, ZSTD_EndDirective cmode) ++{ ++ return input->size; ++} ++#endif ++ ++static int save_file_data(const char *alg, u32 pkg_len, u32 optype) ++{ ++ struct zip_file_head *fhead = NULL; ++ char file_path[PATH_SIZE]; ++ u32 total_file_size = 0; ++ double comp_rate = 0.0; ++ u32 full_size; ++ ssize_t size; ++ int j, fd; ++ int ret = 0; ++ ++ optype = optype % WCRYPTO_DIR_MAX; ++ if (optype != WCRYPTO_DEFLATE) //compress ++ return 0; ++ ++ ret = snprintf(file_path, PATH_SIZE, "%s_%u.%s", ZIP_FILE, pkg_len, alg); ++ if (ret < 0) ++ return -EINVAL; ++ ++ ret = access(file_path, F_OK); ++ if (!ret) { ++ ZIP_TST_PRT("compress data file: %s has exist!\n", file_path); ++ return 0; ++ } ++ ++ fd = open(file_path, O_WRONLY|O_CREAT, 0777); ++ if (fd < 0) { ++ ZIP_TST_PRT("compress data file open %s failed (%d)!\n", file_path, -errno); ++ return -ENODEV; ++ } ++ ++ fhead = malloc(sizeof(*fhead)); ++ if (!fhead) { ++ ZIP_TST_PRT("failed to alloc file head memory\n"); ++ ret = -ENOMEM; ++ goto fd_error; ++ } ++ ++ // init file head informations ++ for (j = 0; j < MAX_POOL_LENTH; j++) { ++ fhead->blk_sz[j] = g_thread_queue.bd_res[0].bds[j].dst_len; ++ total_file_size += fhead->blk_sz[j]; ++ } ++ fhead->block_num = MAX_POOL_LENTH; ++ fhead->file_size = total_file_size; ++ size = write(fd, fhead, sizeof(*fhead)); ++ if (size < 0) { ++ ZIP_TST_PRT("compress write file head failed: %lu!\n", size); ++ ret = -ENODEV; ++ goto write_error; ++ } ++ ++ // write data for one buffer one buffer to file line. ++ for (j = 0; j < MAX_POOL_LENTH; j++) { ++ size = write(fd, g_thread_queue.bd_res[0].bds[j].dst, ++ fhead->blk_sz[j]); ++ if (size < 0) { ++ ZIP_TST_PRT("compress write data error size: %lu!\n", size); ++ ret = -ENODEV; ++ break; ++ } ++ } ++ ++write_error: ++ free(fhead); ++fd_error: ++ close(fd); ++ ++ full_size = g_pktlen * MAX_POOL_LENTH; ++ comp_rate = (double) total_file_size / full_size; ++ ZIP_TST_PRT("compress data rate: %.1f%%!\n", comp_rate * 100); ++ ++ return ret; ++} ++ ++static int load_file_data(const char *alg, u32 pkg_len, u32 optype) ++{ ++ struct zip_file_head *fhead = NULL; ++ char file_path[PATH_SIZE]; ++ ssize_t size = 0xff; ++ int i, j, fd; ++ int ret; ++ ++ optype = optype % WCRYPTO_DIR_MAX; ++ if (optype != WCRYPTO_INFLATE) //decompress ++ return 0; ++ ++ ret = snprintf(file_path, PATH_SIZE, "%s_%u.%s", ZIP_FILE, pkg_len, alg); ++ if (ret < 0) ++ return -EINVAL; ++ ++ ret = access(file_path, F_OK); ++ if (ret) { ++ ZIP_TST_PRT("Decompress data file: %s not exist!\n", file_path); ++ return -EINVAL; ++ } ++ ++ // read data from file ++ fd = open(file_path, O_RDONLY, 0); ++ if (fd < 0) { ++ ZIP_TST_PRT("Decompress data file open %s fail (%d)!\n", file_path, -errno); ++ return -ENODEV; ++ } ++ ++ fhead = malloc(sizeof(*fhead)); ++ if (!fhead) { ++ ZIP_TST_PRT("failed to alloc file head memory\n"); ++ ret = -ENOMEM; ++ goto fd_err; ++ } ++ size = read(fd, fhead, sizeof(*fhead)); ++ if (size < 0 || fhead->block_num != MAX_POOL_LENTH) { ++ ZIP_TST_PRT("failed to read file head\n"); ++ ret = -EINVAL; ++ goto read_err; ++ } ++ ++ // read data for one buffer one buffer from file line ++ for (j = 0; j < MAX_POOL_LENTH; j++) { ++ memset(g_thread_queue.bd_res[0].bds[j].src, 0x0, ++ g_thread_queue.bd_res[0].bds[j].src_len); ++ if (size != 0) { // zero size buffer no need to read; ++ size = read(fd, g_thread_queue.bd_res[0].bds[j].src, ++ fhead->blk_sz[j]); ++ if (size < 0) { ++ ZIP_TST_PRT("Decompress read data error size: %lu!\n", size); ++ ret = -EINVAL; ++ goto read_err; ++ } else if (size == 0) { ++ ZIP_TST_PRT("Read file to the end!"); ++ } ++ } ++ g_thread_queue.bd_res[0].bds[j].src_len = size; ++ } ++ ++ for (i = 1; i < g_thread_num; i++) { ++ for (j = 0; j < MAX_POOL_LENTH; j++) { ++ if (g_thread_queue.bd_res[0].bds[j].src_len) ++ memcpy(g_thread_queue.bd_res[i].bds[j].src, ++ g_thread_queue.bd_res[0].bds[j].src, ++ g_thread_queue.bd_res[0].bds[j].src_len); ++ g_thread_queue.bd_res[i].bds[j].src_len = ++ g_thread_queue.bd_res[0].bds[j].src_len; ++ } ++ } ++ ++read_err: ++ free(fhead); ++fd_err: ++ close(fd); ++ ++ return ret; ++} ++ ++static int zip_wd_param_parse(thread_data *tddata, struct acc_option *options) ++{ ++ u32 algtype = options->algtype; ++ u32 optype = options->optype; ++ u8 mode = BLOCK_MODE; ++ u8 alg; ++ ++ if (optype >= WCRYPTO_DIR_MAX << 1) { ++ ZIP_TST_PRT("Fail to get zip optype!\n"); ++ return -EINVAL; ++ } else if (optype > WCRYPTO_INFLATE) { ++ mode = STREAM_MODE; ++ } ++ ++ optype = optype % WCRYPTO_DIR_MAX; ++ ++ switch(algtype) { ++ case ZLIB: ++ alg = WCRYPTO_ZLIB; ++ break; ++ case GZIP: ++ alg = WCRYPTO_GZIP; ++ break; ++ case DEFLATE: ++ alg = WCRYPTO_RAW_DEFLATE; ++ break; ++ case LZ77_ZSTD: ++ alg = WCRYPTO_LZ77_ZSTD; ++ if (optype == WCRYPTO_INFLATE) ++ ZIP_TST_PRT("Zip LZ77_ZSTD just support compress!\n"); ++ optype = WCRYPTO_DEFLATE; ++ break; ++ default: ++ ZIP_TST_PRT("Fail to set zip alg\n"); ++ return -EINVAL; ++ } ++ ++ tddata->alg = alg; ++ tddata->mode = mode; ++ tddata->optype = optype; ++ ++ return 0; ++} ++ ++static int init_zip_wd_queue(struct acc_option *options) ++{ ++ struct wd_blkpool_setup blksetup; ++ struct wd_bd *bds = NULL; ++ void *pool = NULL; ++ u32 outsize; ++ u32 insize; ++ u8 op_type; ++ int i, j; ++ int ret = 0; ++ ++ op_type = options->optype % WCRYPTO_DIR_MAX; ++ if (op_type == WCRYPTO_DEFLATE) {//compress ++ insize = g_pktlen; ++ outsize = g_pktlen * COMP_LEN_RATE; ++ } else { // decompress ++ insize = g_pktlen; ++ outsize = g_pktlen * DECOMP_LEN_RATE; ++ } ++ ++ g_thread_queue.bd_res = malloc(g_thread_num * sizeof(struct thread_bd_res)); ++ if (!g_thread_queue.bd_res) { ++ ZIP_TST_PRT("malloc thread res memory fail!\n"); ++ return -ENOMEM; ++ } ++ ++ for (i = 0; i < g_thread_num; i++) { ++ g_thread_queue.bd_res[i].queue = malloc(sizeof(struct wd_queue)); ++ g_thread_queue.bd_res[i].queue->capa.alg = options->algclass; ++ // 0 is compress, 1 is decompress ++ g_thread_queue.bd_res[i].queue->capa.priv.direction = op_type; ++ /* nodemask need to be clean */ ++ g_thread_queue.bd_res[i].queue->node_mask = 0x0; ++ memset(g_thread_queue.bd_res[i].queue->dev_path, 0x0, PATH_STR_SIZE); ++ ++ ret = wd_request_queue(g_thread_queue.bd_res[i].queue); ++ if (ret) { ++ ZIP_TST_PRT("request queue %d fail!\n", i); ++ ret = -EINVAL; ++ goto queue_out; ++ } ++ } ++ ++ // use no-sva pbuffer, MAX_BLOCK_NM at least 4 times of MAX_POOL_LENTH ++ memset(&blksetup, 0, sizeof(blksetup)); ++ outsize = ALIGN(outsize, ALIGN_SIZE); ++ blksetup.block_size = outsize; ++ blksetup.block_num = MAX_BLOCK_NM; ++ blksetup.align_size = ALIGN_SIZE; ++ // ZIP_TST_PRT("create pool memory: %d KB\n", (MAX_BLOCK_NM * blksetup.block_size) >> 10); ++ ++ for (j = 0; j < g_thread_num; j++) { ++ g_thread_queue.bd_res[j].pool = wd_blkpool_create(g_thread_queue.bd_res[j].queue, &blksetup); ++ if (!g_thread_queue.bd_res[j].pool) { ++ ZIP_TST_PRT("create %dth pool fail!\n", j); ++ ret = -ENOMEM; ++ goto pool_err; ++ } ++ pool = g_thread_queue.bd_res[j].pool; ++ ++ g_thread_queue.bd_res[j].bds = malloc(sizeof(struct wd_bd) * MAX_POOL_LENTH); ++ if (!g_thread_queue.bd_res[j].bds) ++ goto bds_error; ++ bds = g_thread_queue.bd_res[j].bds; ++ ++ for (i = 0; i < MAX_POOL_LENTH; i++) { ++ bds[i].src = wd_alloc_blk(pool); ++ if (!bds[i].src) { ++ ret = -ENOMEM; ++ goto blk_error2; ++ } ++ bds[i].src_len = insize; ++ ++ bds[i].dst = wd_alloc_blk(pool); ++ if (!bds[i].dst) { ++ ret = -ENOMEM; ++ goto blk_error3; ++ } ++ bds[i].dst_len = outsize; ++ ++ get_rand_data(bds[i].src, insize); ++ } ++ ++ } ++ ++ return 0; ++ ++blk_error3: ++ wd_free_blk(pool, bds[i].src); ++blk_error2: ++ for (i--; i >= 0; i--) { ++ wd_free_blk(pool, bds[i].src); ++ wd_free_blk(pool, bds[i].dst); ++ } ++bds_error: ++ wd_blkpool_destroy(g_thread_queue.bd_res[j].pool); ++pool_err: ++ for (j--; j >= 0; j--) { ++ pool = g_thread_queue.bd_res[j].pool; ++ bds = g_thread_queue.bd_res[j].bds; ++ for (i = 0; i < MAX_POOL_LENTH; i++) { ++ wd_free_blk(pool, bds[i].src); ++ wd_free_blk(pool, bds[i].dst); ++ } ++ free(bds); ++ wd_blkpool_destroy(pool); ++ } ++queue_out: ++ for (i--; i >= 0; i--) { ++ wd_release_queue(g_thread_queue.bd_res[i].queue); ++ free(g_thread_queue.bd_res[i].queue); ++ } ++ free(g_thread_queue.bd_res); ++ return ret; ++} ++ ++static void uninit_zip_wd_queue(void) ++{ ++ struct wd_bd *bds = NULL; ++ void *pool = NULL; ++ int j, i; ++ ++ for (j = 0; j < g_thread_num; j++) { ++ pool = g_thread_queue.bd_res[j].pool; ++ bds = g_thread_queue.bd_res[j].bds; ++ for (i = 0; i < MAX_POOL_LENTH; i++) { ++ wd_free_blk(pool, bds[i].src); ++ wd_free_blk(pool, bds[i].dst); ++ } ++ ++ free(bds); ++ wd_blkpool_destroy(pool); ++ wd_release_queue(g_thread_queue.bd_res[j].queue); ++ } ++ ++ free(g_thread_queue.bd_res); ++} ++ ++/*-------------------------------uadk benchmark main code-------------------------------------*/ ++static void zip_lz77_async_cb(const void *message, void *data) ++{ ++ const struct wcrypto_comp_msg *cbmsg = message; ++ struct zip_async_tag *tag = data; ++ ZSTD_CCtx *cctx = tag->cctx; ++ ZSTD_inBuffer zstd_input; ++ ZSTD_outBuffer zstd_output; ++ struct wd_bd *bd_pool; ++ int td_id = tag->td_id; ++ int idx = tag->bd_idx; ++ size_t fse_size; ++ ++ bd_pool = g_thread_queue.bd_res[td_id].bds; ++ bd_pool[idx].dst_len = cbmsg->produced; ++ ++ zstd_input.src = cbmsg->src; ++ zstd_input.size = cbmsg->in_size; ++ zstd_input.pos = 0; ++ zstd_output.dst = bd_pool[idx].dst; ++ zstd_output.size = tag->cm_len; ++ zstd_output.pos = 0; ++ fse_size = zstd_soft_fse(tag->priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end); ++ ++ bd_pool[idx].dst_len = fse_size; ++} ++ ++static void zip_async_cb(const void *message, void *data) ++{ ++ const struct wcrypto_comp_msg *cbmsg = message; ++ struct zip_async_tag *tag = data; ++ struct wd_bd *bd_pool; ++ int td_id = tag->td_id; ++ int idx = tag->bd_idx; ++ ++ bd_pool = g_thread_queue.bd_res[td_id].bds; ++ bd_pool[idx].dst_len = cbmsg->produced; ++} ++ ++static void *zip_wd_poll(void *data) ++{ ++ thread_data *pdata = (thread_data *)data; ++ u32 expt = ACC_QUEUE_SIZE * g_thread_num; ++ struct wd_queue *queue; ++ u32 id = pdata->td_id; ++ u32 last_time = 2; // poll need one more recv time ++ u32 count = 0; ++ int recv = 0; ++ ++ if (id > g_thread_num) ++ return NULL; ++ ++ queue = g_thread_queue.bd_res[id].queue; ++ while (last_time) { ++ recv = wcrypto_comp_poll(queue, expt); ++ if (unlikely(recv != -WD_EAGAIN && recv < 0)) { ++ ZIP_TST_PRT("poll ret: %u!\n", recv); ++ goto recv_error; ++ } ++ ++ count += recv; ++ recv = 0; ++ ++ if (get_run_state() == 0) ++ last_time--; ++ } ++ ++recv_error: ++ add_recv_data(count, g_pktlen); ++ ++ return NULL; ++} ++ ++static void *zip_wd_blk_lz77_sync_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ ZSTD_CCtx *cctx = zstd_soft_fse_init(15); ++ ZSTD_inBuffer zstd_input = {0}; ++ ZSTD_outBuffer zstd_output = {0}; ++ COMP_TUPLE_TAG *ftuple = NULL; ++ struct wcrypto_comp_ctx_setup comp_setup; ++ struct wcrypto_comp_op_data opdata; ++ struct wcrypto_comp_ctx *ctx; ++ struct wd_queue *queue; ++ struct wd_bd *bd_pool; ++ u8 *hw_buff_out = NULL; ++ size_t fse_size; ++ u32 first_len = 0; ++ u32 out_len = 0; ++ u32 count = 0; ++ int ret, i = 0; ++ ++ if (pdata->td_id > g_thread_num) ++ return NULL; ++ ++ bd_pool = g_thread_queue.bd_res[pdata->td_id].bds; ++ queue = g_thread_queue.bd_res[pdata->td_id].queue; ++ memset(&comp_setup, 0, sizeof(comp_setup)); ++ memset(&opdata, 0, sizeof(opdata)); ++ ++ comp_setup.br.alloc = (void *)wd_alloc_blk; ++ comp_setup.br.free = (void *)wd_free_blk; ++ comp_setup.br.iova_map = (void *)wd_blk_iova_map; ++ comp_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; ++ comp_setup.br.get_bufsize = (void *)wd_blksize; ++ comp_setup.br.usr = g_thread_queue.bd_res[pdata->td_id].pool; ++ ++ comp_setup.alg_type = pdata->alg; ++ comp_setup.op_type = pdata->optype; ++ comp_setup.comp_lv = WCRYPTO_COMP_L8; ++ comp_setup.win_size = WCRYPTO_COMP_WS_8K; ++ comp_setup.stream_mode = WCRYPTO_COMP_STATELESS; ++ ++ ctx = wcrypto_create_comp_ctx(queue, &comp_setup); ++ if (!ctx) ++ return NULL; ++ ++ opdata.stream_pos = WCRYPTO_COMP_STREAM_NEW; ++ opdata.alg_type = pdata->alg; ++ opdata.priv = NULL; ++ opdata.status = 0; ++ if (pdata->optype == WCRYPTO_INFLATE) ++ opdata.flush = WCRYPTO_SYNC_FLUSH; ++ else ++ opdata.flush = WCRYPTO_FINISH; ++ ++ out_len = bd_pool[0].dst_len; ++ ++ ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH); ++ if (!ftuple) ++ goto fse_err; ++ ++ hw_buff_out = malloc(out_len * MAX_POOL_LENTH); ++ if (!hw_buff_out) ++ goto hw_buff_err; ++ memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH); ++ ++ while(1) { ++ i = count % MAX_POOL_LENTH; ++ opdata.in = bd_pool[i].src; ++ opdata.out = &hw_buff_out[i]; //temp out ++ opdata.in_len = bd_pool[i].src_len; ++ opdata.avail_out = out_len; ++ opdata.priv = &ftuple[i]; ++ ++ ret = wcrypto_do_comp(ctx, &opdata, NULL); ++ if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE || ++ opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) ++ break; ++ ++ count++; ++ zstd_input.src = opdata.in; ++ zstd_input.size = opdata.in_len; ++ zstd_input.pos = 0; ++ zstd_output.dst = bd_pool[i].dst; ++ zstd_output.size = out_len; ++ zstd_output.pos = 0; ++ fse_size = zstd_soft_fse(opdata.priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end); ++ ++ bd_pool[i].dst_len = fse_size; ++ if (unlikely(i == 0)) ++ first_len = fse_size; ++ if (get_run_state() == 0) ++ break; ++ } ++ ++hw_buff_err: ++ free(hw_buff_out); ++fse_err: ++ free(ftuple); ++ wcrypto_del_comp_ctx(ctx); ++ ++ // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", ++ // MAX_POOL_LENTH, count, opdata.produced); ++ if (pdata->optype == WCRYPTO_DEFLATE) ++ add_recv_data(count, opdata.in_len); ++ else ++ add_recv_data(count, first_len); ++ ++ return NULL; ++} ++ ++static void *zip_wd_stm_lz77_sync_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ ZSTD_CCtx *cctx = zstd_soft_fse_init(15); ++ ZSTD_inBuffer zstd_input = {0}; ++ ZSTD_outBuffer zstd_output = {0}; ++ COMP_TUPLE_TAG *ftuple = NULL; ++ struct wcrypto_comp_ctx_setup comp_setup; ++ struct wcrypto_comp_op_data opdata; ++ struct wcrypto_comp_ctx *ctx; ++ struct wd_queue *queue; ++ struct wd_bd *bd_pool; ++ u8 *hw_buff_out = NULL; ++ size_t fse_size; ++ u32 first_len = 0; ++ u32 out_len = 0; ++ u32 count = 0; ++ int ret, i = 0; ++ ++ if (pdata->td_id > g_thread_num) ++ return NULL; ++ ++ bd_pool = g_thread_queue.bd_res[pdata->td_id].bds; ++ queue = g_thread_queue.bd_res[pdata->td_id].queue; ++ memset(&comp_setup, 0, sizeof(comp_setup)); ++ memset(&opdata, 0, sizeof(opdata)); ++ ++ comp_setup.br.alloc = (void *)wd_alloc_blk; ++ comp_setup.br.free = (void *)wd_free_blk; ++ comp_setup.br.iova_map = (void *)wd_blk_iova_map; ++ comp_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; ++ comp_setup.br.get_bufsize = (void *)wd_blksize; ++ comp_setup.br.usr = g_thread_queue.bd_res[pdata->td_id].pool; ++ ++ comp_setup.alg_type = pdata->alg; ++ comp_setup.op_type = pdata->optype; ++ comp_setup.comp_lv = WCRYPTO_COMP_L8; ++ comp_setup.win_size = WCRYPTO_COMP_WS_8K; ++ comp_setup.stream_mode = WCRYPTO_COMP_STATEFUL; ++ ++ ctx = wcrypto_create_comp_ctx(queue, &comp_setup); ++ if (!ctx) ++ return NULL; ++ ++ opdata.stream_pos = WCRYPTO_COMP_STREAM_NEW; ++ opdata.alg_type = pdata->alg; ++ opdata.priv = NULL; ++ opdata.status = 0; ++ if (pdata->optype == WCRYPTO_INFLATE) ++ opdata.flush = WCRYPTO_SYNC_FLUSH; ++ else ++ opdata.flush = WCRYPTO_FINISH; ++ ++ out_len = bd_pool[0].dst_len; ++ ++ ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH); ++ if (!ftuple) ++ goto fse_err; ++ ++ hw_buff_out = malloc(out_len * MAX_POOL_LENTH); ++ if (!hw_buff_out) ++ goto hw_buff_err; ++ memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH); ++ ++ while(1) { ++ i = count % MAX_POOL_LENTH; ++ opdata.in = bd_pool[i].src; ++ opdata.out = &hw_buff_out[i]; //temp out ++ opdata.in_len = bd_pool[i].src_len; ++ opdata.avail_out = out_len; ++ opdata.priv = &ftuple[i]; ++ ++ ret = wcrypto_do_comp(ctx, &opdata, NULL); ++ if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE || ++ opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) { ++ ZIP_TST_PRT("wd comp, invalid or incomplete data! " ++ "ret(%d), req.status(%u)\n", ret, opdata.status); ++ break; ++ } ++ ++ count++; ++ zstd_input.src = opdata.in; ++ zstd_input.size = opdata.in_len; ++ zstd_input.pos = 0; ++ zstd_output.dst = opdata.out; ++ zstd_output.size = out_len; ++ zstd_output.pos = 0; ++ fse_size = zstd_soft_fse(opdata.priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end); ++ ++ bd_pool[i].dst_len = fse_size; ++ if (unlikely(i == 0)) ++ first_len = fse_size; ++ if (get_run_state() == 0) ++ break; ++ } ++ ++hw_buff_err: ++ free(hw_buff_out); ++fse_err: ++ free(ftuple); ++ wcrypto_del_comp_ctx(ctx); ++ ++ // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", ++ // MAX_POOL_LENTH, count, opdata.produced); ++ if (pdata->optype == WCRYPTO_DEFLATE) ++ add_recv_data(count, opdata.in_len); ++ else ++ add_recv_data(count, first_len); ++ ++ return NULL; ++} ++ ++static void *zip_wd_blk_lz77_async_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ ZSTD_CCtx *cctx = zstd_soft_fse_init(15); ++ COMP_TUPLE_TAG *ftuple = NULL; ++ struct wcrypto_comp_ctx_setup comp_setup; ++ struct wcrypto_comp_op_data opdata; ++ struct wcrypto_comp_ctx *ctx; ++ struct zip_async_tag *tag; ++ u8 *hw_buff_out = NULL; ++ struct wd_queue *queue; ++ struct wd_bd *bd_pool; ++ u32 out_len = 0; ++ u32 count = 0; ++ u32 try_cnt = 0; ++ int ret, i = 0; ++ ++ if (pdata->td_id > g_thread_num) ++ return NULL; ++ ++ bd_pool = g_thread_queue.bd_res[pdata->td_id].bds; ++ queue = g_thread_queue.bd_res[pdata->td_id].queue; ++ memset(&comp_setup, 0, sizeof(comp_setup)); ++ memset(&opdata, 0, sizeof(opdata)); ++ ++ comp_setup.br.alloc = (void *)wd_alloc_blk; ++ comp_setup.br.free = (void *)wd_free_blk; ++ comp_setup.br.iova_map = (void *)wd_blk_iova_map; ++ comp_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; ++ comp_setup.br.get_bufsize = (void *)wd_blksize; ++ comp_setup.br.usr = g_thread_queue.bd_res[pdata->td_id].pool; ++ ++ comp_setup.alg_type = pdata->alg; ++ comp_setup.op_type = pdata->optype; ++ comp_setup.comp_lv = WCRYPTO_COMP_L8; ++ comp_setup.win_size = WCRYPTO_COMP_WS_8K; ++ comp_setup.stream_mode = WCRYPTO_COMP_STATELESS; ++ comp_setup.cb = zip_lz77_async_cb; ++ ++ ctx = wcrypto_create_comp_ctx(queue, &comp_setup); ++ if (!ctx) ++ return NULL; ++ ++ opdata.stream_pos = WCRYPTO_COMP_STREAM_NEW; ++ opdata.alg_type = pdata->alg; ++ opdata.priv = NULL; ++ opdata.status = 0; ++ if (pdata->optype == WCRYPTO_INFLATE) ++ opdata.flush = WCRYPTO_SYNC_FLUSH; ++ else ++ opdata.flush = WCRYPTO_FINISH; ++ ++ out_len = bd_pool[0].dst_len; ++ ++ ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH); ++ if (!ftuple) ++ goto fse_err; ++ ++ hw_buff_out = malloc(out_len * MAX_POOL_LENTH); ++ if (!hw_buff_out) ++ goto hw_buff_err; ++ memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH); ++ ++ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); ++ if (!tag) { ++ ZIP_TST_PRT("failed to malloc zip tag!\n"); ++ goto tag_err; ++ } ++ ++ while(1) { ++ if (get_run_state() == 0) ++ break; ++ ++ try_cnt = 0; ++ i = count % MAX_POOL_LENTH; ++ opdata.in = bd_pool[i].src; ++ opdata.out = &hw_buff_out[i]; //temp out ++ opdata.in_len = bd_pool[i].src_len; ++ opdata.avail_out = out_len; ++ opdata.priv = &ftuple[i]; ++ ++ tag[i].td_id = pdata->td_id; ++ tag[i].ctx = ctx; ++ tag[i].td_id = pdata->td_id; ++ tag[i].cm_len = out_len; ++ tag[i].cctx = cctx; ++ tag[i].priv = opdata.priv; ++ ++ ret = wcrypto_do_comp(ctx, &opdata, &tag[i]); ++ if (ret == -WD_EBUSY) { ++ usleep(SEND_USLEEP * try_cnt); ++ try_cnt++; ++ if (try_cnt > MAX_TRY_CNT) { ++ ZIP_TST_PRT("Test LZ77 compress send fail %d times!\n", MAX_TRY_CNT); ++ try_cnt = 0; ++ } ++ continue; ++ } else if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE || ++ opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) { ++ break; ++ } ++ count++; ++ } ++ ++ while (1) { ++ if (get_recv_time() > 0) // wait Async mode finish recv ++ break; ++ usleep(SEND_USLEEP); ++ } ++ ++tag_err: ++ free(tag); ++hw_buff_err: ++ free(hw_buff_out); ++fse_err: ++ free(ftuple); ++ wcrypto_del_comp_ctx(ctx); ++ ++ // ZIP_TST_PRT("LZ77 valid pool len: %u, send count BD: %u, output len: %u!\n", ++ // MAX_POOL_LENTH, count, opdata.produced); ++ ++ add_send_complete(); ++ ++ return NULL; ++} ++ ++static void *zip_wd_blk_sync_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ struct wcrypto_comp_ctx_setup comp_setup; ++ struct wcrypto_comp_op_data opdata; ++ struct wcrypto_comp_ctx *ctx; ++ struct wd_queue *queue; ++ struct wd_bd *bd_pool; ++ u32 out_len = 0; ++ u32 count = 0; ++ int ret, i = 0; ++ ++ if (pdata->td_id > g_thread_num) ++ return NULL; ++ ++ bd_pool = g_thread_queue.bd_res[pdata->td_id].bds; ++ queue = g_thread_queue.bd_res[pdata->td_id].queue; ++ memset(&comp_setup, 0, sizeof(comp_setup)); ++ memset(&opdata, 0, sizeof(opdata)); ++ ++ comp_setup.br.alloc = (void *)wd_alloc_blk; ++ comp_setup.br.free = (void *)wd_free_blk; ++ comp_setup.br.iova_map = (void *)wd_blk_iova_map; ++ comp_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; ++ comp_setup.br.get_bufsize = (void *)wd_blksize; ++ comp_setup.br.usr = g_thread_queue.bd_res[pdata->td_id].pool; ++ ++ comp_setup.alg_type = pdata->alg; ++ comp_setup.op_type = pdata->optype; ++ comp_setup.comp_lv = WCRYPTO_COMP_L8; ++ comp_setup.win_size = WCRYPTO_COMP_WS_8K; ++ comp_setup.stream_mode = WCRYPTO_COMP_STATELESS; ++ ++ ctx = wcrypto_create_comp_ctx(queue, &comp_setup); ++ if (!ctx) ++ return NULL; ++ ++ opdata.stream_pos = WCRYPTO_COMP_STREAM_NEW; ++ opdata.alg_type = pdata->alg; ++ opdata.priv = NULL; ++ opdata.status = 0; ++ if (pdata->optype == WCRYPTO_INFLATE) ++ opdata.flush = WCRYPTO_SYNC_FLUSH; ++ else ++ opdata.flush = WCRYPTO_FINISH; ++ ++ out_len = bd_pool[0].dst_len; ++ ++ while(1) { ++ i = count % MAX_POOL_LENTH; ++ opdata.in = bd_pool[i].src; ++ opdata.out = bd_pool[i].dst; ++ opdata.in_len = bd_pool[i].src_len; ++ opdata.avail_out = out_len; ++ ++ ret = wcrypto_do_comp(ctx, &opdata, NULL); ++ if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE || ++ opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) ++ break; ++ ++ count++; ++ bd_pool[i].dst_len = opdata.produced; ++ if (get_run_state() == 0) ++ break; ++ } ++ wcrypto_del_comp_ctx(ctx); ++ ++ // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", ++ // MAX_POOL_LENTH, count, opdata.produced); ++ add_recv_data(count, g_pktlen); ++ ++ return NULL; ++} ++ ++static void *zip_wd_stm_sync_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ struct wcrypto_comp_ctx_setup comp_setup; ++ struct wcrypto_comp_op_data opdata; ++ struct wcrypto_comp_ctx *ctx; ++ struct wd_queue *queue; ++ struct wd_bd *bd_pool; ++ u32 out_len = 0; ++ u32 count = 0; ++ int ret, i = 0; ++ ++ if (pdata->td_id > g_thread_num) ++ return NULL; ++ ++ bd_pool = g_thread_queue.bd_res[pdata->td_id].bds; ++ queue = g_thread_queue.bd_res[pdata->td_id].queue; ++ memset(&comp_setup, 0, sizeof(comp_setup)); ++ memset(&opdata, 0, sizeof(opdata)); ++ ++ comp_setup.br.alloc = (void *)wd_alloc_blk; ++ comp_setup.br.free = (void *)wd_free_blk; ++ comp_setup.br.iova_map = (void *)wd_blk_iova_map; ++ comp_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; ++ comp_setup.br.get_bufsize = (void *)wd_blksize; ++ comp_setup.br.usr = g_thread_queue.bd_res[pdata->td_id].pool; ++ ++ comp_setup.alg_type = pdata->alg; ++ comp_setup.op_type = pdata->optype; ++ comp_setup.comp_lv = WCRYPTO_COMP_L8; ++ comp_setup.win_size = WCRYPTO_COMP_WS_8K; ++ comp_setup.stream_mode = WCRYPTO_COMP_STATEFUL; ++ ++ ctx = wcrypto_create_comp_ctx(queue, &comp_setup); ++ if (!ctx) ++ return NULL; ++ ++ opdata.stream_pos = WCRYPTO_COMP_STREAM_NEW; ++ opdata.alg_type = pdata->alg; ++ opdata.priv = NULL; ++ opdata.status = 0; ++ if (pdata->optype == WCRYPTO_INFLATE) ++ opdata.flush = WCRYPTO_SYNC_FLUSH; ++ else ++ opdata.flush = WCRYPTO_FINISH; ++ ++ out_len = bd_pool[0].dst_len; ++ ++ while(1) { ++ i = count % MAX_POOL_LENTH; ++ opdata.in = bd_pool[i].src; ++ opdata.out = bd_pool[i].dst; ++ opdata.in_len = bd_pool[i].src_len; ++ opdata.avail_out = out_len; ++ ++ ret = wcrypto_do_comp(ctx, &opdata, NULL); ++ if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE || ++ opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) { ++ ZIP_TST_PRT("wd comp, invalid or incomplete data! " ++ "ret(%d), req.status(%u)\n", ret, opdata.status); ++ break; ++ } ++ ++ count++; ++ bd_pool[i].dst_len = opdata.produced; ++ if (get_run_state() == 0) ++ break; ++ } ++ wcrypto_del_comp_ctx(ctx); ++ ++ // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", ++ // MAX_POOL_LENTH, count, opdata.produced); ++ add_recv_data(count, g_pktlen); ++ ++ return NULL; ++ ++} ++ ++static void *zip_wd_blk_async_run(void *arg) ++{ ++ thread_data *pdata = (thread_data *)arg; ++ struct wcrypto_comp_ctx_setup comp_setup; ++ struct wcrypto_comp_op_data opdata; ++ struct wcrypto_comp_ctx *ctx; ++ struct zip_async_tag *tag; ++ struct wd_queue *queue; ++ struct wd_bd *bd_pool; ++ int try_cnt = 0; ++ u32 out_len = 0; ++ u32 count = 0; ++ int ret, i = 0; ++ ++ if (pdata->td_id > g_thread_num) ++ return NULL; ++ ++ bd_pool = g_thread_queue.bd_res[pdata->td_id].bds; ++ queue = g_thread_queue.bd_res[pdata->td_id].queue; ++ memset(&comp_setup, 0, sizeof(comp_setup)); ++ memset(&opdata, 0, sizeof(opdata)); ++ ++ comp_setup.br.alloc = (void *)wd_alloc_blk; ++ comp_setup.br.free = (void *)wd_free_blk; ++ comp_setup.br.iova_map = (void *)wd_blk_iova_map; ++ comp_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; ++ comp_setup.br.get_bufsize = (void *)wd_blksize; ++ comp_setup.br.usr = g_thread_queue.bd_res[pdata->td_id].pool; ++ ++ comp_setup.alg_type = pdata->alg; ++ comp_setup.op_type = pdata->optype; ++ comp_setup.comp_lv = WCRYPTO_COMP_L8; ++ comp_setup.win_size = WCRYPTO_COMP_WS_8K; ++ comp_setup.stream_mode = WCRYPTO_COMP_STATELESS; ++ comp_setup.cb = zip_async_cb; ++ ++ ctx = wcrypto_create_comp_ctx(queue, &comp_setup); ++ if (!ctx) ++ return NULL; ++ ++ opdata.stream_pos = WCRYPTO_COMP_STREAM_NEW; ++ opdata.alg_type = pdata->alg; ++ opdata.priv = NULL; ++ opdata.status = 0; ++ if (pdata->optype == WCRYPTO_INFLATE) ++ opdata.flush = WCRYPTO_SYNC_FLUSH; ++ else ++ opdata.flush = WCRYPTO_FINISH; ++ ++ out_len = bd_pool[0].dst_len; ++ tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); ++ if (!tag) { ++ ZIP_TST_PRT("failed to malloc zip tag!\n"); ++ goto tag_release; ++ } ++ ++ while(1) { ++ if (get_run_state() == 0) ++ break; ++ ++ i = count % MAX_POOL_LENTH; ++ opdata.in = bd_pool[i].src; ++ opdata.out = bd_pool[i].dst; ++ opdata.in_len = bd_pool[i].src_len; ++ opdata.avail_out = out_len; ++ ++ try_cnt = 0; ++ tag[i].ctx = ctx; ++ tag[i].td_id = pdata->td_id; ++ tag[i].bd_idx = i; ++ ++ ret = wcrypto_do_comp(ctx, &opdata, &tag[i]); ++ if (ret == -WD_EBUSY) { ++ usleep(SEND_USLEEP * try_cnt); ++ try_cnt++; ++ if (try_cnt > MAX_TRY_CNT) { ++ ZIP_TST_PRT("Test compress send fail %d times!\n", MAX_TRY_CNT); ++ try_cnt = 0; ++ } ++ continue; ++ } else if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE || ++ opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) { ++ break; ++ } ++ ++ count++; ++ } ++ ++ while (1) { ++ if (get_recv_time() > 0) // wait Async mode finish recv ++ break; ++ usleep(SEND_USLEEP); ++ } ++ ++tag_release: ++ free(tag); ++ wcrypto_del_comp_ctx(ctx); ++ ++ // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", ++ // MAX_POOL_LENTH, count, opdata.produced); ++ ++ add_send_complete(); ++ ++ return NULL; ++} ++ ++static int zip_wd_sync_threads(struct acc_option *options) ++{ ++ typedef void *(*zip_sync_run)(void *arg); ++ zip_sync_run wd_zip_sync_run = NULL; ++ thread_data threads_args[THREADS_NUM]; ++ thread_data threads_option; ++ pthread_t tdid[THREADS_NUM]; ++ int i, ret; ++ ++ /* alg param parse and set to thread data */ ++ ret = zip_wd_param_parse(&threads_option, options); ++ if (ret) ++ return ret; ++ ++ if (threads_option.mode == 1) {// stream mode ++ if (threads_option.alg == LZ77_ZSTD) ++ wd_zip_sync_run = zip_wd_stm_lz77_sync_run; ++ else ++ wd_zip_sync_run = zip_wd_stm_sync_run; ++ } else { ++ if (threads_option.alg == LZ77_ZSTD) ++ wd_zip_sync_run = zip_wd_blk_lz77_sync_run; ++ else ++ wd_zip_sync_run = zip_wd_blk_sync_run; ++ } ++ ++ for (i = 0; i < g_thread_num; i++) { ++ threads_args[i].alg = threads_option.alg; ++ threads_args[i].mode = threads_option.mode; ++ threads_args[i].optype = threads_option.optype; ++ threads_args[i].td_id = i; ++ ret = pthread_create(&tdid[i], NULL, wd_zip_sync_run, &threads_args[i]); ++ if (ret) { ++ ZIP_TST_PRT("Create sync thread fail!\n"); ++ goto sync_error; ++ } ++ } ++ ++ /* join thread */ ++ for (i = 0; i < g_thread_num; i++) { ++ ret = pthread_join(tdid[i], NULL); ++ if (ret) { ++ ZIP_TST_PRT("Join sync thread fail!\n"); ++ goto sync_error; ++ } ++ } ++ ++sync_error: ++ return ret; ++} ++ ++static int zip_wd_async_threads(struct acc_option *options) ++{ ++ typedef void *(*zip_async_run)(void *arg); ++ zip_async_run wd_zip_async_run = NULL; ++ thread_data threads_args[THREADS_NUM]; ++ thread_data threads_option; ++ pthread_t tdid[THREADS_NUM]; ++ pthread_t pollid[THREADS_NUM]; ++ int i, ret; ++ ++ /* alg param parse and set to thread data */ ++ ret = zip_wd_param_parse(&threads_option, options); ++ if (ret) ++ return ret; ++ ++ if (threads_option.mode == STREAM_MODE) {// stream mode ++ ZIP_TST_PRT("Stream mode can't support async mode!\n"); ++ return 0; ++ } ++ ++ if (threads_option.alg == LZ77_ZSTD) ++ wd_zip_async_run = zip_wd_blk_lz77_async_run; ++ else ++ wd_zip_async_run = zip_wd_blk_async_run; ++ ++ for (i = 0; i < g_thread_num; i++) { ++ threads_args[i].td_id = i; ++ /* poll thread */ ++ ret = pthread_create(&pollid[i], NULL, zip_wd_poll, &threads_args[i]); ++ if (ret) { ++ ZIP_TST_PRT("Create poll thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++ for (i = 0; i < g_thread_num; i++) { ++ threads_args[i].alg = threads_option.alg; ++ threads_args[i].mode = threads_option.mode; ++ threads_args[i].optype = threads_option.optype; ++ threads_args[i].td_id = i; ++ ret = pthread_create(&tdid[i], NULL, wd_zip_async_run, &threads_args[i]); ++ if (ret) { ++ ZIP_TST_PRT("Create async thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++ /* join thread */ ++ for (i = 0; i < g_thread_num; i++) { ++ ret = pthread_join(tdid[i], NULL); ++ if (ret) { ++ ZIP_TST_PRT("Join async thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++ for (i = 0; i < g_thread_num; i++) { ++ ret = pthread_join(pollid[i], NULL); ++ if (ret) { ++ ZIP_TST_PRT("Join poll thread fail!\n"); ++ goto async_error; ++ } ++ } ++ ++async_error: ++ return ret; ++} ++ ++int zip_wd_benchmark(struct acc_option *options) ++{ ++ u32 ptime; ++ int ret; ++ ++ g_thread_num = options->threads; ++ g_pktlen = options->pktlen; ++ ++ if (options->optype >= WCRYPTO_DIR_MAX * 2) { ++ ZIP_TST_PRT("ZIP optype error: %u\n", options->optype); ++ return -EINVAL; ++ } ++ ++ ret = init_zip_wd_queue(options); ++ if (ret) ++ return ret; ++ ++ ret = load_file_data(options->algname, options->pktlen, options->optype); ++ if (ret) ++ return ret; ++ ++ get_pid_cpu_time(&ptime); ++ time_start(options->times); ++ if (options->syncmode) ++ ret = zip_wd_async_threads(options); ++ else ++ ret = zip_wd_sync_threads(options); ++ cal_perfermance_data(options, ptime); ++ if (ret) ++ return ret; ++ ++ ret = save_file_data(options->algname, options->pktlen, options->optype); ++ if (ret) ++ return ret; ++ ++ uninit_zip_wd_queue(); ++ ++ return 0; ++} +diff --git a/uadk_tool/benchmark/zip_wd_benchmark.h b/uadk_tool/benchmark/zip_wd_benchmark.h +new file mode 100644 +index 0000000..86ef497 +--- /dev/null ++++ b/uadk_tool/benchmark/zip_wd_benchmark.h +@@ -0,0 +1,6 @@ ++/* SPDX-License-Identifier: Apache-2.0 */ ++#ifndef ZIP_WD_BENCHMARK_H ++#define ZIP_WD_BENCHMARK_H ++ ++extern int zip_wd_benchmark(struct acc_option *options); ++#endif /* ZIP_WD_BENCHMARK_H */ +-- +2.27.0 + diff --git a/0138-drv-qm-fix-spin-lock-destroy.patch b/0138-drv-qm-fix-spin-lock-destroy.patch new file mode 100644 index 0000000..5ca5617 --- /dev/null +++ b/0138-drv-qm-fix-spin-lock-destroy.patch @@ -0,0 +1,115 @@ +From 9c9794bda2151eb66432a099b028d28628a43406 Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +Signed-off-by: Weili Qian +--- + 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 + diff --git a/0139-drv-qm-modify-the-lock-for-send-and-receive-BD.patch b/0139-drv-qm-modify-the-lock-for-send-and-receive-BD.patch new file mode 100644 index 0000000..d4fc26c --- /dev/null +++ b/0139-drv-qm-modify-the-lock-for-send-and-receive-BD.patch @@ -0,0 +1,144 @@ +From 2004801f44c0b6259b051e5a55bde5c54306fd63 Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 + diff --git a/0140-uadk-v1-fix-goto-warning.patch b/0140-uadk-v1-fix-goto-warning.patch new file mode 100644 index 0000000..d9a2c1b --- /dev/null +++ b/0140-uadk-v1-fix-goto-warning.patch @@ -0,0 +1,475 @@ +From 746d250131c3727e658f11f37fbb0a8cb18d1b18 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0141-uadk-fix-comment-blank.patch b/0141-uadk-fix-comment-blank.patch new file mode 100644 index 0000000..aa7c0bf --- /dev/null +++ b/0141-uadk-fix-comment-blank.patch @@ -0,0 +1,68 @@ +From 28904d5266bc827b05ac1beb5e819878b56fc3f2 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0142-uadk-fix-different-name-in-declaration-and-definitio.patch b/0142-uadk-fix-different-name-in-declaration-and-definitio.patch new file mode 100644 index 0000000..f853509 --- /dev/null +++ b/0142-uadk-fix-different-name-in-declaration-and-definitio.patch @@ -0,0 +1,155 @@ +From 190cfeed8f1970f886e2fa3d9a7f45ad0a779966 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0143-uadk-fix-pointer-parameters-are-not-checked.patch b/0143-uadk-fix-pointer-parameters-are-not-checked.patch new file mode 100644 index 0000000..8c20c18 --- /dev/null +++ b/0143-uadk-fix-pointer-parameters-are-not-checked.patch @@ -0,0 +1,126 @@ +From 45be6faf148734bfcfe5ea1536cae3e4a434cd84 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0144-uadk-fix-cqe-phase.patch b/0144-uadk-fix-cqe-phase.patch new file mode 100644 index 0000000..f34e477 --- /dev/null +++ b/0144-uadk-fix-cqe-phase.patch @@ -0,0 +1,69 @@ +From 2563892aaab90d594b70251253f67efce378c491 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + #include + #include + #include +@@ -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 + #include + #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 + diff --git a/0145-uadk-v1-fix-include-file-order.patch b/0145-uadk-v1-fix-include-file-order.patch new file mode 100644 index 0000000..394a200 --- /dev/null +++ b/0145-uadk-v1-fix-include-file-order.patch @@ -0,0 +1,92 @@ +From e4459ddbe6b9423710208d0b086cd7a491aa0f55 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + #include + #include +-#include + #include + #include ++#include + + #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 + + #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 + + #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 + + #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 + + #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 + diff --git a/0146-uadk-fix-BufferOverFlow.patch b/0146-uadk-fix-BufferOverFlow.patch new file mode 100644 index 0000000..b94101b --- /dev/null +++ b/0146-uadk-fix-BufferOverFlow.patch @@ -0,0 +1,45 @@ +From 8b19ff4c4b243ca2b0adf9c19bc20c3b83c9c4b1 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0147-uadk-fix-macro-argument-warning.patch b/0147-uadk-fix-macro-argument-warning.patch new file mode 100644 index 0000000..3772710 --- /dev/null +++ b/0147-uadk-fix-macro-argument-warning.patch @@ -0,0 +1,44 @@ +From e3f943d0974bee65c8ab6ca16eff541a20a4fc5e Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0148-uadk-driver-init-should-check-ctx-num.patch b/0148-uadk-driver-init-should-check-ctx-num.patch new file mode 100644 index 0000000..109e13d --- /dev/null +++ b/0148-uadk-driver-init-should-check-ctx-num.patch @@ -0,0 +1,67 @@ +From c8025681d15bdfdee9cc00796b68f02f1cf85d67 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0149-uadk-fix-cast-pointer-problem.patch b/0149-uadk-fix-cast-pointer-problem.patch new file mode 100644 index 0000000..4a68a43 --- /dev/null +++ b/0149-uadk-fix-cast-pointer-problem.patch @@ -0,0 +1,104 @@ +From 3d84ae9b37c608a045322312a929839042d6b2a9 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0150-uadk-fix-function-params-usage.patch b/0150-uadk-fix-function-params-usage.patch new file mode 100644 index 0000000..d431391 --- /dev/null +++ b/0150-uadk-fix-function-params-usage.patch @@ -0,0 +1,60 @@ +From 1e1b1fce4977f41f1cb1a86d22aca43a18531efc Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0151-uadk-fix-size_t-usage.patch b/0151-uadk-fix-size_t-usage.patch new file mode 100644 index 0000000..7a5c9e7 --- /dev/null +++ b/0151-uadk-fix-size_t-usage.patch @@ -0,0 +1,30 @@ +From 76d36759e69f7ed303e8fbf42b46052383f86337 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0152-uadk-fix-atoi-usage.patch b/0152-uadk-fix-atoi-usage.patch new file mode 100644 index 0000000..77585d7 --- /dev/null +++ b/0152-uadk-fix-atoi-usage.patch @@ -0,0 +1,79 @@ +From 19c524e4be9fcd9af5145dde9e11725e4c7eb1c2 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0153-uadk-fix-lm-not-link-problem.patch b/0153-uadk-fix-lm-not-link-problem.patch new file mode 100644 index 0000000..3981342 --- /dev/null +++ b/0153-uadk-fix-lm-not-link-problem.patch @@ -0,0 +1,37 @@ +From 05a357678b603cd6d30cbedabfb981620b056eed Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0154-uadk-remove-unneed-comment-and-macro.patch b/0154-uadk-remove-unneed-comment-and-macro.patch new file mode 100644 index 0000000..a7bfec4 --- /dev/null +++ b/0154-uadk-remove-unneed-comment-and-macro.patch @@ -0,0 +1,47 @@ +From 2cb12ab4c85a8699635e75866ae4b0ff9881adc3 Mon Sep 17 00:00:00 2001 +From: Wenkai Lin +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 +--- + 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 + diff --git a/0155-drv-hpre-remove-repeatedly-included-header-file.patch b/0155-drv-hpre-remove-repeatedly-included-header-file.patch new file mode 100644 index 0000000..61c1b37 --- /dev/null +++ b/0155-drv-hpre-remove-repeatedly-included-header-file.patch @@ -0,0 +1,56 @@ +From fbdf545556c1fe85e5c35001af675ea0cb8ab968 Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 +-#include + #include +-#include +-#include +-#include +-#include +-#include +-#include ++#include + #include + #include ++#include + #include + #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 ++ + #include "../wd_rsa.h" + + #ifdef __cplusplus +-- +2.27.0 + diff --git a/0156-drv-hpre-add-hpre_result_check.patch b/0156-drv-hpre-add-hpre_result_check.patch new file mode 100644 index 0000000..4d31cbf --- /dev/null +++ b/0156-drv-hpre-add-hpre_result_check.patch @@ -0,0 +1,138 @@ +From 06d0a1a22e611a23f91573d125dc83295a2b0256 Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 + diff --git a/0157-drv-hpre-move-format-check-to-is_hpre_bin_fmt.patch b/0157-drv-hpre-move-format-check-to-is_hpre_bin_fmt.patch new file mode 100644 index 0000000..49505ff --- /dev/null +++ b/0157-drv-hpre-move-format-check-to-is_hpre_bin_fmt.patch @@ -0,0 +1,67 @@ +From 892ac1efc8dac5dfb0434c953c66d379533ea0f4 Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 + diff --git a/0158-drv-hpre-change-the-parameter-type.patch b/0158-drv-hpre-change-the-parameter-type.patch new file mode 100644 index 0000000..519e737 --- /dev/null +++ b/0158-drv-hpre-change-the-parameter-type.patch @@ -0,0 +1,55 @@ +From 8d53e4e7194addaf3e9831ba5f197440d0522ad0 Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 + diff --git a/0159-drv-hpre-remove-redundant-blank-line.patch b/0159-drv-hpre-remove-redundant-blank-line.patch new file mode 100644 index 0000000..9b4b31c --- /dev/null +++ b/0159-drv-hpre-remove-redundant-blank-line.patch @@ -0,0 +1,27 @@ +From d0300cca906531d85d025c1c17a3d845a0f45902 Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 + diff --git a/0160-drv-qm-add-unlikely-for-branch-prefetch.patch b/0160-drv-qm-add-unlikely-for-branch-prefetch.patch new file mode 100644 index 0000000..c6d1ed7 --- /dev/null +++ b/0160-drv-qm-add-unlikely-for-branch-prefetch.patch @@ -0,0 +1,71 @@ +From 3c59e2ada00a20ff8aec3fe13920cf155a63740c Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 + diff --git a/0161-drv-qm-remove-redundant-add-1.patch b/0161-drv-qm-remove-redundant-add-1.patch new file mode 100644 index 0000000..fbdda90 --- /dev/null +++ b/0161-drv-qm-remove-redundant-add-1.patch @@ -0,0 +1,28 @@ +From 16800a92f326560006d0480faacde3cf1d5d6cb2 Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 + diff --git a/0162-drv-qm-remove-useless-parameter-sq_head_index.patch b/0162-drv-qm-remove-useless-parameter-sq_head_index.patch new file mode 100644 index 0000000..999c5eb --- /dev/null +++ b/0162-drv-qm-remove-useless-parameter-sq_head_index.patch @@ -0,0 +1,41 @@ +From 913b0b03484eace681dd53a2fdf6a20e594f07d8 Mon Sep 17 00:00:00 2001 +From: Weili Qian +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 +--- + 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 + diff --git a/0163-uadk-add-wd_-alg-_get_msg.patch b/0163-uadk-add-wd_-alg-_get_msg.patch new file mode 100644 index 0000000..75d2f44 --- /dev/null +++ b/0163-uadk-add-wd_-alg-_get_msg.patch @@ -0,0 +1,106 @@ +From 282f78fc44dc216166ae463944d952f753f7c8b6 Mon Sep 17 00:00:00 2001 +From: Kai Ye +Date: Sat, 23 Jul 2022 10:49:04 +0800 +Subject: [PATCH 178/183] uadk: add wd__get_msg() + +Add wd__get_msg() for driver to obtain the sent +message by the user. + +Signed-off-by: Kai Ye +Signed-off-by: Weili Qian +--- + 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 + diff --git a/0164-drv-hpre-support-dump-BD-when-BD-checks-fail.patch b/0164-drv-hpre-support-dump-BD-when-BD-checks-fail.patch new file mode 100644 index 0000000..930a601 --- /dev/null +++ b/0164-drv-hpre-support-dump-BD-when-BD-checks-fail.patch @@ -0,0 +1,206 @@ +From 40bf83f1ee78c6cf28114ea93c2d93eb3a312c1e Mon Sep 17 00:00:00 2001 +From: Kai Ye +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 +Signed-off-by: Weili Qian +--- + 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 + diff --git a/0165-drv-hpre-bugfix-about-sm2-async-parsing-error.patch b/0165-drv-hpre-bugfix-about-sm2-async-parsing-error.patch new file mode 100644 index 0000000..2ee45bd --- /dev/null +++ b/0165-drv-hpre-bugfix-about-sm2-async-parsing-error.patch @@ -0,0 +1,129 @@ +From d2996f7251e18c164fc3faba909e4ab90361c2e3 Mon Sep 17 00:00:00 2001 +From: Zhiqi Song +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 +--- + 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 + diff --git a/0166-drv-hpre-bugfix-async-tag-of-rsa-and-dh.patch b/0166-drv-hpre-bugfix-async-tag-of-rsa-and-dh.patch new file mode 100644 index 0000000..e6d3d49 --- /dev/null +++ b/0166-drv-hpre-bugfix-async-tag-of-rsa-and-dh.patch @@ -0,0 +1,74 @@ +From 5e5bd0a4eb5a1bd794a4b6d8998bfaf40d98c808 Mon Sep 17 00:00:00 2001 +From: Zhiqi Song +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 +--- + 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 + diff --git a/0167-drv-hpre-cleanup-ecc-sqe-parsing-process.patch b/0167-drv-hpre-cleanup-ecc-sqe-parsing-process.patch new file mode 100644 index 0000000..4c3fc10 --- /dev/null +++ b/0167-drv-hpre-cleanup-ecc-sqe-parsing-process.patch @@ -0,0 +1,47 @@ +From 858b0598f933cbaa832bb0da85e003c63b366f5d Mon Sep 17 00:00:00 2001 +From: Zhiqi Song +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 +--- + 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 + diff --git a/warpdrive.spec b/warpdrive.spec index 0408301..d6a761b 100644 --- a/warpdrive.spec +++ b/warpdrive.spec @@ -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 2.3.21-6 +- libwd: backport the patch of uadk from 2.3.31 to 2.3.36 + * Mon Mar 21 2022 Yang Shen 2.3.21-5 - libwd: backport the patch of uadk from 2.3.28 to 2.3.31