[PATCH 01/13] uadk/tool: add init2 test for digest algs
From: Hao Fang <fanghao11@huawei.com> add testcase for init2 just use cmd --init 2. default or --init 1 for init interface. Signed-off-by: Hao Fang <fanghao11@huawei.com> --- uadk_tool/test/test_sec.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/uadk_tool/test/test_sec.c b/uadk_tool/test/test_sec.c index 5b552fa..0a28db6 100644 --- a/uadk_tool/test/test_sec.c +++ b/uadk_tool/test/test_sec.c @@ -1483,6 +1483,14 @@ static int digest_init2(int type, int mode) cparams.op_type_num = 1; cparams.ctx_set_num = ctx_set_num; + cparams.bmp = numa_allocate_nodemask(); + if (!cparams.bmp) { + WD_ERR("failed to create nodemask!\n"); + ret = -WD_ENOMEM; + goto out_freectx; + } + + numa_bitmask_setall(cparams.bmp); if (mode == CTX_MODE_SYNC) ctx_set_num->sync_ctx_num = g_ctxnum; @@ -1494,7 +1502,13 @@ static int digest_init2(int type, int mode) ret = wd_digest_init2("sm3", SCHED_POLICY_NONE, TASK_INSTR); else ret = wd_digest_init2_(digest_names[g_testalg], 0, 0, &cparams); + if (ret) + goto out_freebmp; + +out_freebmp: + numa_free_nodemask(cparams.bmp); +out_freectx: free(ctx_set_num); return ret; -- 2.33.0
From: Hao Fang <fanghao11@huawei.com> add testcase cmd --init 2 for init2. default or --init 1 for init. Signed-off-by: Hao Fang <fanghao11@huawei.com> --- uadk_tool/test/test_sec.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/uadk_tool/test/test_sec.c b/uadk_tool/test/test_sec.c index 0a28db6..462ba7a 100644 --- a/uadk_tool/test/test_sec.c +++ b/uadk_tool/test/test_sec.c @@ -2749,6 +2749,14 @@ static int aead_init2(int type, int mode) cparams.op_type_num = 1; cparams.ctx_set_num = ctx_set_num; + cparams.bmp = numa_allocate_nodemask(); + if (!cparams.bmp) { + WD_ERR("failed to create nodemask!\n"); + ret = -WD_ENOMEM; + goto out_freectx; + } + + numa_bitmask_setall(cparams.bmp); if (mode == CTX_MODE_SYNC) ctx_set_num->sync_ctx_num = g_ctxnum; @@ -2757,7 +2765,13 @@ static int aead_init2(int type, int mode) ctx_set_num->async_ctx_num = g_ctxnum; ret = wd_aead_init2_(aead_names[g_testalg], 0, 0, &cparams); + if (ret) + goto out_freebmp; +out_freebmp: + numa_free_nodemask(cparams.bmp); + +out_freectx: free(ctx_set_num); return ret; -- 2.33.0
From: Younger <shenyang39@huawei.com> In wd_deflate_init/wd_inflate_init, the wd_comp_init2_ will be called to initialize wd_comp. wd_comp_init2_ will return -WD_EEXIST if wd_comp initialized. Signed-off-by: Yang Shen <shenyang39@huawei.com> --- wd_zlibwrapper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wd_zlibwrapper.c b/wd_zlibwrapper.c index c153af1..4e20346 100644 --- a/wd_zlibwrapper.c +++ b/wd_zlibwrapper.c @@ -67,7 +67,7 @@ static int wd_zlib_uadk_init(void) ctx_set_num[i].sync_ctx_num = WD_DIR_MAX; ret = wd_comp_init2_("zlib", 0, 0, &cparams); - if (ret && ret != -WD_EEXIST) + if (ret && ret != -WD_EEXIST) { ret = Z_STREAM_ERROR; zlib_status = WD_ZLIB_INIT; -- 2.33.0
From: Yang Shen <shenyang39@huawei.com> The zlibwrapper is used for some users who want to use the uadk library without changing the app source code broad. They can change the app compression api only by calling the uadk zlibwrapper interface. But there are some limits left for uadk zlibwrapper use scenes. First, only some useful interfaces are realized. The zlibwrapper only support test compression and decompression. Second, the zlib library has multiple flush types. But the uadk compression now only support the Z_SYNC_FLUSH and Z_FINISH, others are illegal. Signed-off-by: Yang Shen <shenyang39@huawei.com> --- wd_zlibwrapper.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/wd_zlibwrapper.c b/wd_zlibwrapper.c index 4e20346..8f32f0f 100644 --- a/wd_zlibwrapper.c +++ b/wd_zlibwrapper.c @@ -62,6 +62,14 @@ static int wd_zlib_uadk_init(void) cparams.op_type_num = WD_DIR_MAX; cparams.ctx_set_num = ctx_set_num; + cparams.bmp = numa_allocate_nodemask(); + if (!cparams.bmp) { + WD_ERR("failed to create nodemask!\n"); + ret = Z_MEM_ERROR; + goto out_freectx; + } + + numa_bitmask_setall(cparams.bmp); for (i = 0; i < WD_DIR_MAX; i++) ctx_set_num[i].sync_ctx_num = WD_DIR_MAX; @@ -69,9 +77,16 @@ static int wd_zlib_uadk_init(void) ret = wd_comp_init2_("zlib", 0, 0, &cparams); if (ret && ret != -WD_EEXIST) { ret = Z_STREAM_ERROR; + goto out_freebmp; + } + ret = 0; zlib_status = WD_ZLIB_INIT; +out_freebmp: + numa_free_nodemask(cparams.bmp); + +out_freectx: free(ctx_set_num); return ret; -- 2.33.0
From: Longfang Liu <liulongfang@huawei.com> Added support for init2 performance test function for uadk_tools of comp module. Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- uadk_tool/benchmark/zip_uadk_benchmark.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c index 8573cdc..68b93cf 100644 --- a/uadk_tool/benchmark/zip_uadk_benchmark.c +++ b/uadk_tool/benchmark/zip_uadk_benchmark.c @@ -395,7 +395,16 @@ static int init_ctx_config2(struct acc_option *options) ZIP_TST_PRT("failed to do comp init2!\n"); else ret = wd_comp_init2_(alg_name, SCHED_POLICY_DEV, TASK_HW, &cparams); + if (ret) { + ZIP_TST_PRT("failed to do comp init2!\n"); + return ret; + } + + return 0; + +out_freectx: free(ctx_set_num); + return ret; } -- 2.33.0
From: Weili Qian <qianweili@huawei.com> Added support for init2 performance test function for uadk_tools of hpre module. And fix some code style issues. Signed-off-by: Weili Qian <qianweili@huawei.com> --- uadk_tool/benchmark/hpre_uadk_benchmark.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c index 549893c..65b68a9 100644 --- a/uadk_tool/benchmark/hpre_uadk_benchmark.c +++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c @@ -692,7 +692,7 @@ static int init_hpre_ctx_config2(struct acc_option *options) return wd_ecc_init2_(alg_name, SCHED_POLICY_DEV, TASK_HW, &cparams); default: HPRE_TST_PRT("failed to parse alg subtype on uninit2!\n"); - ret = -EINVAL; + return -EINVAL; } free(ctx_set_num); -- 2.33.0
From: Zhangfei Gao <zhangfei.gao@linaro.org> wd_xxx_init2 does not take para cparam, which take ctx number. So default ctx number is used with poor performance. numactl --cpubind=0 --membind=0 \ uadk_tool benchmark --alg sha512 --mode sva --opt 0 --async --pktlen 8192 \ --seconds 20 --multi 1 --thread 8 --ctxnum 8 --init2 sha512 8192Bytes 3982625.60KiB/s 497.8Kops 1292.90% after fix: numactl --cpubind=0 --membind=0 \ uadk_tool benchmark --alg sha512 --mode sva --opt 0 --async --pktlen 8192 \ --seconds 20 --multi 1 --thread 8 --ctxnum 8 --init2 sha512 8192Bytes 11276124.40KiB/s 1409.5Kops 1026.70% Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org> --- uadk_tool/benchmark/hpre_uadk_benchmark.c | 10 ++++++++++ uadk_tool/benchmark/sec_uadk_benchmark.c | 16 +++++++++++++--- uadk_tool/benchmark/uadk_benchmark.c | 2 +- uadk_tool/benchmark/zip_uadk_benchmark.c | 8 ++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c index 65b68a9..fa26a61 100644 --- a/uadk_tool/benchmark/hpre_uadk_benchmark.c +++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c @@ -663,6 +663,14 @@ static int init_hpre_ctx_config2(struct acc_option *options) cparams.op_type_num = 1; cparams.ctx_set_num = ctx_set_num; + cparams.bmp = numa_allocate_nodemask(); + if (!cparams.bmp) { + WD_ERR("failed to create nodemask!\n"); + ret = -WD_ENOMEM; + goto out_freectx; + } + + numa_bitmask_setall(cparams.bmp); if (mode == CTX_MODE_SYNC) ctx_set_num->sync_ctx_num = g_ctxnum; @@ -695,7 +703,9 @@ static int init_hpre_ctx_config2(struct acc_option *options) return -EINVAL; } +out_freectx: free(ctx_set_num); + return ret; } diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index d9d4d25..4a64c94 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -876,6 +876,14 @@ static int init_ctx_config2(struct acc_option *options) cparams.op_type_num = 1; cparams.ctx_set_num = ctx_set_num; + cparams.bmp = numa_allocate_nodemask(); + if (!cparams.bmp) { + WD_ERR("failed to create nodemask!\n"); + ret = -WD_ENOMEM; + goto out_freectx; + } + + numa_bitmask_setall(cparams.bmp); if (mode == CTX_MODE_SYNC) ctx_set_num->sync_ctx_num = g_ctxnum; @@ -913,11 +921,13 @@ static int init_ctx_config2(struct acc_option *options) if (ret) SEC_TST_PRT("failed to do digest init2!\n"); break; - default: - SEC_TST_PRT("failed to parse alg subtype on uninit2!\n"); - ret = -EINVAL; + } + if (ret) { + SEC_TST_PRT("failed to do cipher init2!\n"); + return ret; } +out_freectx: free(ctx_set_num); return ret; diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index e3fdda2..fd64f6c 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -337,7 +337,7 @@ void time_start(u32 seconds) void get_rand_data(u8 *addr, u32 size) { static __thread unsigned short rand_state[3] = {0}; - static __thread int initialized = 0; + static __thread int initialized = 0; static const uint32_t LCG_A = 1664525U; static const uint32_t LCG_C = 1013904223U; diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c index 68b93cf..2e7752b 100644 --- a/uadk_tool/benchmark/zip_uadk_benchmark.c +++ b/uadk_tool/benchmark/zip_uadk_benchmark.c @@ -379,6 +379,14 @@ static int init_ctx_config2(struct acc_option *options) cparams.op_type_num = WD_DIR_MAX; cparams.ctx_set_num = ctx_set_num; + cparams.bmp = numa_allocate_nodemask(); + if (!cparams.bmp) { + WD_ERR("failed to create nodemask!\n"); + ret = -WD_ENOMEM; + goto out_freectx; + } + + numa_bitmask_setall(cparams.bmp); for (int i = 0; i < WD_DIR_MAX; i++) { if (mode == CTX_MODE_SYNC) -- 2.33.0
From: Weili Qian <qianweili@huawei.com> The trng module is not required. Therefore, remove the trng module code. Signed-off-by: Weili Qian <qianweili@huawei.com> Signed-off-by: Qi Tao <taoqi10@huawei.com> --- Makefile.am | 6 +- configure.ac | 1 - uadk_tool/Makefile.am | 1 - uadk_tool/benchmark/trng_wd_benchmark.c | 333 ------------ uadk_tool/benchmark/trng_wd_benchmark.h | 7 - uadk_tool/benchmark/uadk_benchmark.c | 15 - uadk_tool/benchmark/uadk_benchmark.h | 1 - v1/drv/hisi_rng_udrv.c | 167 ------ v1/drv/hisi_rng_udrv.h | 40 -- v1/libwd.map | 5 - v1/test/Makefile.am | 1 - v1/test/hisi_trng_test/Makefile.am | 20 - v1/test/hisi_trng_test/test_hisi_trngk.c | 155 ------ v1/test/hisi_trng_test/test_hisi_trngp.c | 137 ----- v1/test/hisi_trng_test/test_hisi_trngu.c | 624 ----------------------- v1/wd.h | 2 +- v1/wd_adapter.c | 7 - v1/wd_rng.c | 296 ----------- v1/wd_rng.h | 76 --- 19 files changed, 3 insertions(+), 1891 deletions(-) delete mode 100644 uadk_tool/benchmark/trng_wd_benchmark.c delete mode 100644 uadk_tool/benchmark/trng_wd_benchmark.h delete mode 100644 v1/drv/hisi_rng_udrv.c delete mode 100644 v1/drv/hisi_rng_udrv.h delete mode 100644 v1/test/hisi_trng_test/Makefile.am delete mode 100755 v1/test/hisi_trng_test/test_hisi_trngk.c delete mode 100644 v1/test/hisi_trng_test/test_hisi_trngp.c delete mode 100755 v1/test/hisi_trng_test/test_hisi_trngu.c delete mode 100644 v1/wd_rng.c delete mode 100644 v1/wd_rng.h diff --git a/Makefile.am b/Makefile.am index d1a5953..7749613 100644 --- a/Makefile.am +++ b/Makefile.am @@ -49,9 +49,8 @@ uadk_driversdir=$(libdir)/uadk uadk_drivers_LTLIBRARIES=libhisi_sec.la libhisi_hpre.la libhisi_zip.la \ libisa_ce.la libisa_sve.la libhisi_dae.la libhisi_udma.la -libwd_la_SOURCES=wd.c wd_mempool.c wd_bmm.c wd_bmm.h wd.h wd_alg.c wd_alg.h \ +libwd_la_SOURCES=wd.c wd_mempool.c wd_bmm.c wd_bmm.h wd.h wd_alg.c wd_alg.h \ v1/wd.c v1/wd.h v1/wd_adapter.c v1/wd_adapter.h \ - v1/wd_rng.c v1/wd_rng.h \ v1/wd_rsa.c v1/wd_rsa.h \ v1/wd_aead.c v1/wd_aead.h \ v1/wd_dh.c v1/wd_dh.h \ @@ -68,8 +67,7 @@ libwd_la_SOURCES=wd.c wd_mempool.c wd_bmm.c wd_bmm.h wd.h wd_alg.c wd_alg.h \ v1/drv/hisi_zip_udrv.c v1/drv/hisi_zip_udrv.h \ v1/drv/hisi_zip_huf.c v1/drv/hisi_zip_huf.h \ v1/drv/hisi_hpre_udrv.c v1/drv/hisi_hpre_udrv.h \ - v1/drv/hisi_sec_udrv.c v1/drv/hisi_sec_udrv.h \ - v1/drv/hisi_rng_udrv.c v1/drv/hisi_rng_udrv.h + v1/drv/hisi_sec_udrv.c v1/drv/hisi_sec_udrv.h libwd_udma_la_SOURCES=wd_udma.h wd_udma_drv.h wd_udma.c \ wd_util.c wd_util.h wd_sched.c wd_sched.h wd.c wd.h diff --git a/configure.ac b/configure.ac index 95c9f67..eb5a211 100644 --- a/configure.ac +++ b/configure.ac @@ -109,7 +109,6 @@ AC_CONFIG_FILES([Makefile v1/test/bmm_test/Makefile v1/test/test_mm/Makefile v1/test/hisi_hpre_test/Makefile - v1/test/hisi_trng_test/Makefile v1/test/hisi_sec_test/Makefile v1/test/hisi_sec_test_sgl/Makefile v1/test/hisi_zip_test/Makefile diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am index 86b3064..9a1703d 100644 --- a/uadk_tool/Makefile.am +++ b/uadk_tool/Makefile.am @@ -17,7 +17,6 @@ uadk_tool_SOURCES=uadk_tool.c dfx/uadk_dfx.c dfx/uadk_dfx.h \ benchmark/hpre_wd_benchmark.c hpre_wd_benchmark.h \ benchmark/zip_uadk_benchmark.c benchmark/zip_uadk_benchmark.h \ benchmark/zip_wd_benchmark.c benchmark/zip_wd_benchmark.h \ - benchmark/trng_wd_benchmark.c benchmark/trng_wd_benchmark.h \ test/uadk_test.c test/uadk_test.h \ test/test_sec.c test/test_sec.h test/sec_template_tv.h diff --git a/uadk_tool/benchmark/trng_wd_benchmark.c b/uadk_tool/benchmark/trng_wd_benchmark.c deleted file mode 100644 index 2f058d4..0000000 --- a/uadk_tool/benchmark/trng_wd_benchmark.c +++ /dev/null @@ -1,333 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ - -#include <numa.h> -#include "uadk_benchmark.h" - -#include "trng_wd_benchmark.h" -#include "v1/wd.h" -#include "v1/wd_rng.h" - -struct thread_bd_res { - struct wd_queue *queue; - void *out; - __u32 in_bytes; -}; - -struct thread_queue_res { - struct thread_bd_res *bd_res; -}; - -struct wd_thread_res { - u32 td_id; - u32 pollid; -}; - -struct trng_async_tag { - void *ctx; - int optype; -}; - -static unsigned int g_thread_num; -static struct thread_queue_res g_thread_queue; - -static int init_trng_wd_queue(struct acc_option *options) -{ - int i, ret; - - g_thread_queue.bd_res = malloc(g_thread_num * sizeof(struct thread_bd_res)); - if (!g_thread_queue.bd_res) { - printf("failed to malloc thread res memory!\n"); - return -ENOMEM; - } - - for (i = 0; i < g_thread_num; i++) { - g_thread_queue.bd_res[i].queue = malloc(sizeof(struct wd_queue)); - if (!g_thread_queue.bd_res[i].queue) { - ret = -ENOMEM; - goto free_mem; - } - - g_thread_queue.bd_res[i].queue->capa.alg = options->algclass; - /* 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); - if (strlen(options->device) != 0) { - ret = snprintf(g_thread_queue.bd_res[i].queue->dev_path, - PATH_STR_SIZE, "%s", options->device); - if (ret < 0) { - WD_ERR("failed to copy dev file path!\n"); - return -WD_EINVAL; - } - } - - g_thread_queue.bd_res[i].in_bytes = options->pktlen; - g_thread_queue.bd_res[i].out = malloc(options->pktlen); - if (!g_thread_queue.bd_res[i].queue) { - free(g_thread_queue.bd_res[i].queue); - ret = -ENOMEM; - goto free_mem; - } - - ret = wd_request_queue(g_thread_queue.bd_res[i].queue); - if (ret) { - printf("failed to request queue %d, ret = %d!\n", i, ret); - free(g_thread_queue.bd_res[i].out); - free(g_thread_queue.bd_res[i].queue); - goto free_mem; - } - } - - return 0; - -free_mem: - for (i = i - 1; i >= 0; i--) { - wd_release_queue(g_thread_queue.bd_res[i].queue); - free(g_thread_queue.bd_res[i].out); - free(g_thread_queue.bd_res[i].queue); - } - - free(g_thread_queue.bd_res); - return ret; -} - -static void uninit_trng_wd_queue(void) -{ - int j; - - for (j = 0; j < g_thread_num; j++) { - wd_release_queue(g_thread_queue.bd_res[j].queue); - free(g_thread_queue.bd_res[j].out); - free(g_thread_queue.bd_res[j].queue); - } - - free(g_thread_queue.bd_res); -} - -static void *trng_wd_sync_run(void *arg) -{ - struct wd_thread_res *pdata = (struct wd_thread_res *)arg; - struct wcrypto_rng_ctx_setup trng_setup; - struct wcrypto_rng_op_data opdata; - struct wd_queue *queue; - void *ctx = NULL; - u32 count = 0; - int ret; - - queue = g_thread_queue.bd_res[pdata->td_id].queue; - ctx = wcrypto_create_rng_ctx(queue, &trng_setup); - if (!ctx) - return NULL; - - memset(&opdata, 0, sizeof(opdata)); - opdata.in_bytes = g_thread_queue.bd_res[pdata->td_id].in_bytes; - opdata.out = g_thread_queue.bd_res[pdata->td_id].out; - opdata.op_type = WCRYPTO_TRNG_GEN; - - do { - ret = wcrypto_do_rng(ctx, &opdata, NULL); - if (ret) { - printf("failed to do rng task, ret: %d\n", ret); - goto ctx_release; - } - - count++; - if (get_run_state() == 0) - break; - } while (true); - -ctx_release: - wcrypto_del_rng_ctx(ctx); - add_recv_data(count, opdata.in_bytes); - - return NULL; -} - -static void trng_wd_sync_threads(void) -{ - struct wd_thread_res threads_args[THREADS_NUM]; - pthread_t tdid[THREADS_NUM]; - int i, ret; - - for (i = 0; i < g_thread_num; i++) { - threads_args[i].td_id = i; - ret = pthread_create(&tdid[i], NULL, trng_wd_sync_run, &threads_args[i]); - if (ret) { - printf("failed to create sync thread!\n"); - return; - } - } - - /* join thread */ - for (i = 0; i < g_thread_num; i++) { - ret = pthread_join(tdid[i], NULL); - if (ret) { - printf("failed to join sync thread!\n"); - return; - } - } -} - -void *wd_trng_poll(void *data) -{ - struct wd_thread_res *pdata = (struct wd_thread_res *)data; - struct wd_queue *queue; - u32 last_time = 2; // poll need one more recv time - u32 count = 0; - u32 in_bytes; - int recv; - - in_bytes = g_thread_queue.bd_res[pdata->pollid].in_bytes; - queue = g_thread_queue.bd_res[pdata->pollid].queue; - - while (last_time) { - recv = wcrypto_rng_poll(queue, ACC_QUEUE_SIZE); - if (recv < 0) { - printf("failed to recv bd, ret: %d!\n", recv); - goto recv_error; - } - count += recv; - - if (get_run_state() == 0) - last_time--; - } - -recv_error: - add_recv_data(count, in_bytes); - - return NULL; -} - -static void *trng_async_cb(const void *msg, void *tag) -{ - return NULL; -} - -static void *wd_trng_async_run(void *arg) -{ - struct wd_thread_res *pdata = (struct wd_thread_res *)arg; - struct wcrypto_rng_ctx_setup trng_setup; - struct wcrypto_rng_op_data opdata; - struct trng_async_tag *tag = NULL; - struct wd_queue *queue; - void *ctx = NULL; - int ret, i; - - memset(&opdata, 0, sizeof(opdata)); - - queue = g_thread_queue.bd_res[pdata->td_id].queue; - trng_setup.cb = (void *)trng_async_cb; - - ctx = wcrypto_create_rng_ctx(queue, &trng_setup); - if (!ctx) - return NULL; - - opdata.in_bytes = g_thread_queue.bd_res[pdata->td_id].in_bytes; - opdata.out = g_thread_queue.bd_res[pdata->td_id].out; - opdata.op_type = WCRYPTO_TRNG_GEN; - - tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); - if (!tag) { - printf("failed to malloc dh tag!\n"); - goto free_ctx; - } - tag->ctx = ctx; - - do { - ret = wcrypto_do_rng(ctx, &opdata, tag); - if (ret && ret != -WD_EBUSY) { - printf("failed to send trng task, ret = %d!\n", ret); - break; - } - - if (get_run_state() == 0) - break; - } while (true); - - /* Release memory after all tasks are complete. */ - i = 0; - while (get_recv_time() != g_thread_num) { - if (i++ >= MAX_TRY_CNT) { - printf("failed to wait poll thread finish!\n"); - break; - } - - usleep(SEND_USLEEP); - } - - if (tag) - free(tag); -free_ctx: - wcrypto_del_rng_ctx(ctx); - add_send_complete(); - - return NULL; -} - -static void trng_wd_async_threads(void) -{ - struct wd_thread_res threads_args[THREADS_NUM]; - pthread_t tdid[THREADS_NUM]; - pthread_t pollid[THREADS_NUM]; - int i, ret; - - for (i = 0; i < g_thread_num; i++) { - threads_args[i].pollid = i; - /* poll thread */ - ret = pthread_create(&pollid[i], NULL, wd_trng_poll, &threads_args[i]); - if (ret) { - printf("failed to create poll thread!\n"); - return; - } - } - - for (i = 0; i < g_thread_num; i++) { - threads_args[i].td_id = i; - ret = pthread_create(&tdid[i], NULL, wd_trng_async_run, &threads_args[i]); - if (ret) { - printf("failed to create async thread!\n"); - return; - } - } - - /* join thread */ - for (i = 0; i < g_thread_num; i++) { - ret = pthread_join(tdid[i], NULL); - if (ret) { - printf("failed to join async thread!\n"); - return; - } - } - - for (i = 0; i < g_thread_num; i++) { - ret = pthread_join(pollid[i], NULL); - if (ret) { - printf("failed to join poll thread!\n"); - return; - } - } -} - -int trng_wd_benchmark(struct acc_option *options) -{ - u32 ptime; - int ret; - - signal(SIGSEGV, segmentfault_handler); - g_thread_num = options->threads; - - ret = init_trng_wd_queue(options); - if (ret) - return ret; - - get_pid_cpu_time(&ptime); - time_start(options->times); - if (options->syncmode) - trng_wd_async_threads(); - else - trng_wd_sync_threads(); - cal_perfermance_data(options, ptime); - - uninit_trng_wd_queue(); - - return 0; -} diff --git a/uadk_tool/benchmark/trng_wd_benchmark.h b/uadk_tool/benchmark/trng_wd_benchmark.h deleted file mode 100644 index 49453c8..0000000 --- a/uadk_tool/benchmark/trng_wd_benchmark.h +++ /dev/null @@ -1,7 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ - -#ifndef TRNG_WD_BENCHMARK_H -#define TRNG_WD_BENCHMARK_H - -extern int trng_wd_benchmark(struct acc_option *options); -#endif /* TRNG_WD_BENCHMARK_H */ diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index fd64f6c..09e99e2 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -16,8 +16,6 @@ #include "zip_uadk_benchmark.h" #include "zip_wd_benchmark.h" -#include "trng_wd_benchmark.h" - #define TABLE_SPACE_SIZE 8 /*----------------------------------------head struct--------------------------------------------------------*/ @@ -157,7 +155,6 @@ static struct acc_alg_item alg_options[] = { {"sha512", "sha512", SHA512_ALG}, {"sha512-224", "sha512-224", SHA512_224}, {"sha512-256", "sha512-256", SHA512_256}, - {"trng", "trng", TRNG}, {"", "", ALG_MAX} }; @@ -463,11 +460,6 @@ static void parse_alg_param(struct acc_option *option) option->acctype = HPRE_TYPE; option->subtype = X448_TYPE; break; - case TRNG: - snprintf(option->algclass, MAX_ALG_NAME, "%s", "trng"); - option->acctype = TRNG_TYPE; - option->subtype = DEFAULT_TYPE; - break; default: if (option->algtype <= RSA_4096_CRT) { snprintf(option->algclass, MAX_ALG_NAME, "%s", "rsa"); @@ -596,13 +588,6 @@ static int benchmark_run(struct acc_option *option) ret = zip_wd_benchmark(option); } break; - case TRNG_TYPE: - if (option->modetype == SVA_MODE) - ACC_TST_PRT("TRNG not support sva mode..\n"); - else if (option->modetype == NOSVA_MODE) - ret = trng_wd_benchmark(option); - - break; } return ret; diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index 9a0ad5e..83fd7fa 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -96,7 +96,6 @@ enum acc_type { SEC_TYPE, HPRE_TYPE, ZIP_TYPE, - TRNG_TYPE, }; enum acc_init_type { diff --git a/v1/drv/hisi_rng_udrv.c b/v1/drv/hisi_rng_udrv.c deleted file mode 100644 index 605ef27..0000000 --- a/v1/drv/hisi_rng_udrv.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2018-2019 Huawei Technologies Co.,Ltd.All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <stdlib.h> -#include <unistd.h> -#include <stdio.h> -#include <pthread.h> -#include <sys/mman.h> -#include <string.h> -#include <stdint.h> -#include <sys/epoll.h> -#include <sys/eventfd.h> -#include <sys/types.h> - -#include "hisi_rng_udrv.h" - -#define HISI_RNG_BYTES 4 -#define MAX_RETRY_COUNTS 8 -#define RNG_NUM_OFFSET 0x00F0 - -int rng_init_queue(struct wd_queue *q) -{ - struct q_info *qinfo = q->qinfo; - struct rng_queue_info *info; - int ret; - - info = calloc(1, sizeof(*info)); - if (!info) { - WD_ERR("no mem!\n"); - return -ENOMEM; - } - - ret = pthread_spin_init(&info->lock, PTHREAD_PROCESS_PRIVATE); - if (ret) { - free(info); - WD_ERR("failed to init rng qinfo lock!\n"); - return ret; - } - - qinfo->priv = info; - info->mmio_base = wd_drv_mmap_qfr(q, WD_UACCE_QFRT_MMIO, 0); - if (info->mmio_base == MAP_FAILED) { - info->mmio_base = NULL; - qinfo->priv = NULL; - pthread_spin_destroy(&info->lock); - free(info); - WD_ERR("mmap trng mmio fail\n"); - return -ENOMEM; - } - - return 0; -} - -void rng_uninit_queue(struct wd_queue *q) -{ - struct q_info *qinfo = q->qinfo; - struct rng_queue_info *info = qinfo->priv; - - wd_drv_unmmap_qfr(q, info->mmio_base, WD_UACCE_QFRT_MMIO, 0); - - free(qinfo->priv); - qinfo->priv = NULL; - pthread_spin_destroy(&info->lock); -} - -int rng_send(struct wd_queue *q, void **req, __u32 num) -{ - struct q_info *qinfo = q->qinfo; - struct rng_queue_info *info = qinfo->priv; - - pthread_spin_lock(&info->lock); - if (!info->req_cache[info->send_idx]) { - info->req_cache[info->send_idx] = req[0]; - info->send_idx++; - pthread_spin_unlock(&info->lock); - return 0; - } - pthread_spin_unlock(&info->lock); - - WD_ERR("queue is full!\n"); - return -WD_EBUSY; -} - -static int rng_read(struct rng_queue_info *info, struct wcrypto_rng_msg *msg) -{ - __u32 max = msg->in_bytes; - __u32 currsize = 0; - int recv_count = 0; - __u32 val; - - do { - val = wd_reg_read((void *)((uintptr_t)info->mmio_base + - RNG_NUM_OFFSET)); - if (!val) { - if (++recv_count > MAX_RETRY_COUNTS) { - WD_ERR("read random data timeout\n"); - break; - } - - usleep(1); - continue; - } - - recv_count = 0; - if (max - currsize >= HISI_RNG_BYTES) { - memcpy(msg->out + currsize, &val, HISI_RNG_BYTES); - currsize += HISI_RNG_BYTES; - if (currsize == max) - break; - continue; - } - - memcpy(msg->out + currsize, &val, max - currsize); - currsize = max; - } while (currsize < max); - - return currsize; -} - -int rng_recv(struct wd_queue *q, void **resp, __u32 num) -{ - struct q_info *qinfo = q->qinfo; - struct rng_queue_info *info = qinfo->priv; - __u16 usr = (__u16)(uintptr_t)*resp; - struct wcrypto_rng_msg *msg; - struct wcrypto_cb_tag *tag; - __u32 currsize = 0; - - pthread_spin_lock(&info->lock); - msg = info->req_cache[info->recv_idx]; - if (!msg) { - pthread_spin_unlock(&info->lock); - return 0; - } - - info->req_cache[info->recv_idx] = NULL; - info->recv_idx++; - pthread_spin_unlock(&info->lock); - - tag = (void *)(uintptr_t)msg->usr_tag; - if (usr && tag->ctx_id != usr) - return 0; - - currsize = rng_read(info, msg); - if (!currsize) { - WD_ERR("random data err!\n"); - return -WD_EINVAL; - } - - msg->out_bytes = currsize; - *resp = msg; - - return 1; -} diff --git a/v1/drv/hisi_rng_udrv.h b/v1/drv/hisi_rng_udrv.h deleted file mode 100644 index 3efa10e..0000000 --- a/v1/drv/hisi_rng_udrv.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2018-2019 Huawei Technologies Co.,Ltd.All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __HISI_RNG_UDRV_H__ -#define __HISI_RNG_UDRV_H__ - -#include <linux/types.h> -#include "v1/wd.h" -#include "v1/wd_util.h" -#include "v1/wd_rng.h" - -#define TRNG_Q_DEPTH 256 - -struct rng_queue_info { - void *mmio_base; - void *req_cache[TRNG_Q_DEPTH]; - __u8 send_idx; - __u8 recv_idx; - pthread_spinlock_t lock; -}; - -int rng_init_queue(struct wd_queue *q); -void rng_uninit_queue(struct wd_queue *q); -int rng_send(struct wd_queue *q, void **req, __u32 num); -int rng_recv(struct wd_queue *q, void **resp, __u32 num); - -#endif diff --git a/v1/libwd.map b/v1/libwd.map index d53201b..6c54479 100644 --- a/v1/libwd.map +++ b/v1/libwd.map @@ -133,11 +133,6 @@ global: wcrypto_rsa_poll; wcrypto_del_rsa_ctx; - wcrypto_create_rng_ctx; - wcrypto_del_rng_ctx; - wcrypto_do_rng; - wcrypto_rng_poll; - wd_sglpool_create; wd_sglpool_destroy; wd_alloc_sgl; diff --git a/v1/test/Makefile.am b/v1/test/Makefile.am index bd41cfe..6cbf79f 100644 --- a/v1/test/Makefile.am +++ b/v1/test/Makefile.am @@ -7,7 +7,6 @@ SUBDIRS+=hisi_zip_test endif SUBDIRS+=hisi_zip_test_sgl -SUBDIRS+=hisi_trng_test if HAVE_CRYPTO SUBDIRS+=hisi_hpre_test diff --git a/v1/test/hisi_trng_test/Makefile.am b/v1/test/hisi_trng_test/Makefile.am deleted file mode 100644 index b561585..0000000 --- a/v1/test/hisi_trng_test/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -AM_CFLAGS=-Wall -Werror -O0 -fno-strict-aliasing -I$(top_srcdir)/include -I$(srcdir) -pthread - -if HAVE_CRYPTO -bin_PROGRAMS=test_hisi_trngu_v1 test_hisi_trngk_v1 test_hisi_trngp_v1 - -test_hisi_trngu_v1_SOURCES=test_hisi_trngu.c -test_hisi_trngk_v1_SOURCES=test_hisi_trngk.c -test_hisi_trngp_v1_SOURCES=test_hisi_trngp.c - -if WD_STATIC_DRV -test_hisi_trngu_v1_LDADD=../../../.libs/libwd.la -test_hisi_trngk_v1_LDADD=../../../.libs/libwd.la -test_hisi_trngp_v1_LDADD=../../../.libs/libwd.la -else -test_hisi_trngu_v1_LDADD=../../../.libs/libwd.so -test_hisi_trngk_v1_LDADD=../../../.libs/libwd.so -test_hisi_trngp_v1_LDADD=../../../.libs/libwd.so -endif - -endif diff --git a/v1/test/hisi_trng_test/test_hisi_trngk.c b/v1/test/hisi_trng_test/test_hisi_trngk.c deleted file mode 100755 index ae719e5..0000000 --- a/v1/test/hisi_trng_test/test_hisi_trngk.c +++ /dev/null @@ -1,155 +0,0 @@ -#include <assert.h> -#include <stdio.h> -#include <string.h> -#include <fcntl.h> -#define __USE_GNU -#include <sched.h> -#include <pthread.h> -#include <sys/mman.h> -#include <sys/time.h> -#include <unistd.h> -#include <getopt.h> -#include <stdlib.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/time.h> -#include <semaphore.h> - - -struct thread_info -{ - pthread_t thread_id; - unsigned int size; - unsigned int num; - int addr; - -}; - -void *trng_thread(void *args) -{ - - int fd = -1; - int fd_w = -1; - int ret; - unsigned int input; - struct thread_info *tinfo = args; - input = tinfo->size; - unsigned int *data = (unsigned int*)malloc(sizeof(unsigned int) * input); - - if(!data) - return NULL; - - if (tinfo->addr == 0){ - -// printf("Now try to get %d bytes random number from /dev/hwrng.\n", input * 4); - fd = open ("/dev/hwrng", O_RDONLY); - } - else if (tinfo->addr == 1){ -// printf("Now try to get %d bytes random number from /dev/random.\n", input * 4); - fd = open ("/dev/random", O_RDONLY); - } - - if (fd <0 ) { - printf("can not open\n"); - return NULL; - } - - fd_w = open ("/root/trng_file", O_WRONLY|O_CREAT|O_APPEND,0777); - if (fd_w <0 ) { - printf("can not open trng_file\n"); - return NULL; - } - memset(data, 0, sizeof(int) * input); - ret = read(fd, data, input); - if (ret < 0) { - printf("read error %d\n", ret); - return NULL; - } - ret =write(fd_w,data,input); - if (ret < 0) { - printf("write error %d\n", ret); - return NULL; - } - - close(fd); - close(fd_w); - - return NULL; -} - - -void trng_test(int addr,int num,unsigned int si,int thread_num) -{ - - int i; - void *ret = NULL; - struct thread_info *tinfo; - tinfo = calloc(thread_num, sizeof(struct thread_info)); - - if (tinfo == NULL) - { - printf("calloc fail...\n"); - return; - } - - for (i = 0; i<thread_num; ++i) - { - tinfo[i].thread_id = i; - tinfo[i].addr = addr; - tinfo[i].num = num; - tinfo[i].size = si; - - if ((pthread_create(&tinfo[i].thread_id,NULL,trng_thread, (void *)&tinfo[i])) != 0) - { - return; - } - } - - for (i=0; i<thread_num; ++i) - { - if (pthread_join(tinfo[i].thread_id, &ret) != 0) - { - printf("thread is not exit....\n"); - return; - } - //printf("thread exit coid %d\n", (int *)ret); - free(ret); - } - free(tinfo); -} - - - - -int main (int argc, char* argv[]) { - - int opt; - int addr = 0, num = 0, thread_num = 0; - unsigned int si = 0; - - while ((opt = getopt(argc, argv, "hri:p:s:")) != -1) { - switch (opt) { - case 'h': - addr = 0; - break; - case 'r': - addr = 1; - break; - case 'i': - num = atoi(optarg); - break; - case 'p': - thread_num = atoi(optarg); - break; - case 's': - si = (unsigned int)atoi(optarg); - break; - default: - break; - } - } - - trng_test(addr,num,si,thread_num); - - return 0; -} diff --git a/v1/test/hisi_trng_test/test_hisi_trngp.c b/v1/test/hisi_trng_test/test_hisi_trngp.c deleted file mode 100644 index 2330b1e..0000000 --- a/v1/test/hisi_trng_test/test_hisi_trngp.c +++ /dev/null @@ -1,137 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/time.h> -#include <pthread.h> -#include <unistd.h> - -static int input; -static int thread_num; -struct thread_info -{ - pthread_t thread_id; - unsigned int size; - int num; -}; - -void *trng_thread(void *args) -{ - int j; - int fd = -1; - int data; - int ret; - struct thread_info *tinfo = args; - int si; - int num; - int size; - int fd_w = -1; - si = tinfo->size; - num = tinfo->num; - size=si/num; - printf("Now try to get bytes random number from /dev/random.\n"); - fd = open("/dev/random", O_RDONLY); - if (fd <0 ) { - printf("can not open\n"); - return NULL; - } - for (j = 0; j< size; j++) { - ret = read(fd, &data, 1); - if (ret < 0) { - printf("read error %d\n", ret); - return NULL; - } -// else if (ret < 1) -// goto rd_ag; -// if (!data) { -// printf("read data error!\n"); -// return data; -// } - printf("the read num:%x\n",data); - } - fd_w = open ("/root/trng_file", O_RDWR | O_CREAT |O_APPEND , 0777); - if (fd_w <0 ) { - printf("can not open trng_file\n"); - return NULL; - } - ret = write(fd_w,&data,size); - if (ret < 0) { - printf("write error %d\n", ret); - return NULL; - } - close(fd); - close(fd_w); - return NULL; -} - -void trng_test(int input,int thread_num) -{ - int i; - void *ret = NULL; - struct thread_info *tinfo; - tinfo = calloc(thread_num, sizeof(struct thread_info)); - if(tinfo == NULL) - { - printf("calloc fail...\n"); - return; - } - for(i = 0; i<thread_num; ++i) - { - tinfo[i].thread_id = i; - tinfo[i].num=thread_num; -// tinfo[i].addr = addr; -// tinfo[i].num = num; - tinfo[i].size = input; - if((pthread_create(&tinfo[i].thread_id,NULL,trng_thread, (void *)&tinfo[i])) != 0) - { - return; - } - } - - for(i=0; i<thread_num; ++i) - { - if(pthread_join(tinfo[i].thread_id, &ret) != 0) - { - printf("thread is not exit....\n"); - return; - } -// printf("thread exit coid %d\n", (int *)ret); - free(ret); - } - free(tinfo); -} - -int main (int argc, char* argv[]) -{ - struct timeval start_tval, end_tval; - float time,speed; - int fd_f=-1; - fd_f = open ("/root/trng_file", O_RDWR | O_CREAT |O_TRUNC, 0777); - if (fd_f <0 ) { - printf("can not open trng_file\n"); - return fd_f; - } - input = strtoul(argv[1], NULL, 10); - if (input <= 0){ - printf("input error!\n"); - return -1; - } - thread_num = strtoul((char *)argv[2], NULL, 10); - if (thread_num <= 0 || thread_num > 128) { - printf("Invalid threads num:%d!\n",thread_num); - printf("Now set threads num as 2\n"); - thread_num = 2; - } - gettimeofday(&start_tval, NULL); - trng_test(input,thread_num); - gettimeofday(&end_tval, NULL); - time = (float)((end_tval.tv_sec - start_tval.tv_sec) * 1000000 + - (end_tval.tv_usec - start_tval.tv_usec)); - speed = input/(time / 1000000); - printf("read random speed: %0.0f time\n", time); - printf("read random speed: %0.0f bytes/s\n", speed); - close(fd_f); - return 0; -} diff --git a/v1/test/hisi_trng_test/test_hisi_trngu.c b/v1/test/hisi_trng_test/test_hisi_trngu.c deleted file mode 100755 index 86aa8a9..0000000 --- a/v1/test/hisi_trng_test/test_hisi_trngu.c +++ /dev/null @@ -1,624 +0,0 @@ -/* - * Copyright 2019 Huawei Technologies Co.,Ltd.All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <stdio.h> -#include <string.h> -#include <fcntl.h> -#define __USE_GNU -#include <sched.h> -#include <pthread.h> -#include <sys/mman.h> -#include <sys/types.h> -#include <sys/syscall.h> -#include <sys/stat.h> -#include <sys/time.h> -#include <unistd.h> -#include <semaphore.h> - -#include "../../wd.h" -#include "../../wd_rng.h" - -#define RNG_TST_PRT printf -#define BN_ULONG unsigned long -#define TEST_MAX_THRD 128 -#define MAX_TRY_TIMES 10000 -#define LOG_INTVL_NUM 8 -#define TEST_CNT 10 - -static int q_num = 1; -static int ctx_num_per_q = 1; - -enum alg_op_type { - TRNG_GEN, - TRNG_AGEN, -}; - -struct trng_user_tag_info { - int pid; - int thread_id; -}; - -struct test_trng_pthread_dt { - int cpu_id; - int thread_num; - void *q; -}; - -static struct test_trng_pthread_dt test_thrds_data[TEST_MAX_THRD]; -static pthread_t system_test_thrds[TEST_MAX_THRD]; -static unsigned int g_input; - - -static inline int _get_cpu_id(int thr, __u64 core_mask) -{ - __u64 i; - int cnt = 0; - - for (i = 1; i < 64; i++) { - if (core_mask & (0x1ull << i)) { - if (thr == cnt) - return i; - cnt++; - } - } - - return 0; -} - -static inline int _get_one_bits(__u64 val) -{ - int count = 0; - - while (val) { - if (val % 2 == 1) - count++; - val = val / 2; - } - - return count; -} - -void *_trng_sys_test_thread(void *data) -{ - int ret, cpuid, i = 0; - struct test_trng_pthread_dt *pdata = data; - struct wcrypto_rng_ctx_setup setup; - struct wcrypto_rng_op_data opdata; - int pid = getpid(); - int thread_id = (int)syscall(__NR_gettid); - struct wd_queue *q; - int *out_data; - void *ctx = NULL; - void *tag = NULL; - - cpu_set_t mask; - CPU_ZERO(&mask); - cpuid = pdata->cpu_id; - q = pdata->q; - CPU_SET(cpuid, &mask); - - if (cpuid) { - ret = pthread_setaffinity_np(pthread_self(), - sizeof(mask), &mask); - if (ret < 0) { - RNG_TST_PRT("Proc-%d, thrd-%d:set affinity fail!\n", - pid, thread_id); - return NULL; - } - RNG_TST_PRT("Proc-%d, thrd-%d bind to cpu-%d!\n", - pid, thread_id, cpuid); - } - - memset(&setup, 0, sizeof(setup)); - memset(&opdata, 0, sizeof(opdata)); - ctx = wcrypto_create_rng_ctx(q, &setup); - if (!ctx) { - RNG_TST_PRT("Proc-%d, %d-TD:create %s ctx fail!\n", - pid, thread_id, q->capa.alg); - ret = -EINVAL; - goto fail_release; - } - - out_data = malloc(g_input); - if(!out_data) { - RNG_TST_PRT("malloc out_data memory fail!\n"); - } - RNG_TST_PRT("request queue fail5!\n"); - - while (1) { - opdata.in_bytes = g_input; - opdata.out = out_data; - ret = wcrypto_do_rng(ctx, &opdata, tag); - if (ret < 0) { - RNG_TST_PRT("Proc-%d, T-%d:trng %d fail!\n", pid, thread_id, i); - goto fail_release; - } - RNG_TST_PRT("the read data size %d!\n", opdata.out_bytes); - i++; - } -fail_release: - if (opdata.out) - free(opdata.out); - if (ctx) - wcrypto_del_rng_ctx(ctx); - return NULL; -} - - -static int trng_sys_test(int thread_num, __u64 lcore_mask, - __u64 hcore_mask) -{ - int i, ret, cnt = 0, j; - struct wd_queue *q; - int h_cpuid, qidx; - - q = malloc(q_num * sizeof(struct wd_queue)); - if (!q) { - RNG_TST_PRT("malloc q memory fail!\n"); - return -ENOMEM; - } - memset(q, 0, q_num * sizeof(struct wd_queue)); - - for (j = 0; j < q_num; j++) { - q[j].capa.alg = "trng"; - ret = wd_request_queue(&q[j]); - if (ret) { - RNG_TST_PRT("request queue %d fail!\n", j); - return ret; - } - } - RNG_TST_PRT("request queue fail!\n"); - if (_get_one_bits(lcore_mask) > 0) - cnt = _get_one_bits(lcore_mask); - else if (_get_one_bits(lcore_mask) == 0 && - _get_one_bits(hcore_mask) == 0) - cnt = thread_num; - - for (i = 0; i < cnt; i++) { - qidx = i / ctx_num_per_q; - test_thrds_data[i].q = &q[qidx]; - test_thrds_data[i].thread_num = thread_num; - test_thrds_data[i].cpu_id = _get_cpu_id(i, lcore_mask); - ret = pthread_create(&system_test_thrds[i], NULL, - _trng_sys_test_thread, &test_thrds_data[i]); - if (ret) { - RNG_TST_PRT("Create %dth thread fail!\n", i); - return ret; - } - } - RNG_TST_PRT("request queue fail2!\n"); - for (i = 0; i < thread_num - cnt; i++) { - h_cpuid = _get_cpu_id(i, hcore_mask); - if (h_cpuid > 0) - h_cpuid += 64; - - qidx = (i + cnt) / ctx_num_per_q; - test_thrds_data[i + cnt].q = &q[qidx]; - test_thrds_data[i + cnt].thread_num = thread_num; - test_thrds_data[i + cnt].cpu_id = h_cpuid; - ret = pthread_create(&system_test_thrds[i + cnt], NULL, - _trng_sys_test_thread, &test_thrds_data[i + cnt]); - if (ret) { - RNG_TST_PRT("Create %dth thread fail!\n", i); - return ret; - } - } - RNG_TST_PRT("request queue fail3!\n"); - for (i = 0; i < thread_num; i++) { - ret = pthread_join(system_test_thrds[i], NULL); - if (ret) { - RNG_TST_PRT("Join %dth thread fail!\n", i); - return ret; - } - } - free(q); - return 0; -} - - -static void _trng_cb(const void *message, void *tag) -{ - const struct wcrypto_rng_msg *msg = message; - struct trng_user_tag_info* pSwData = (struct trng_user_tag_info*)tag; - struct wcrypto_rng_op_data opdata; - int pid, threadId; - - if (NULL == pSwData) { - RNG_TST_PRT("pSwData NULL!\n"); - return; - } - memset(&opdata, 0, sizeof(opdata)); - - opdata.out = (void *)msg->out; - opdata.out_bytes = msg->out_bytes; - pid = pSwData->pid; - threadId = pSwData->thread_id; - RNG_TST_PRT("Proc-%d, %d-TD trng\n", pid, threadId); - RNG_TST_PRT("the random number size :%d\n", opdata.out_bytes); - - if (opdata.out) - free(opdata.out); - - if (pSwData) - free(pSwData); -} - -static void *_trng_asys_test_thread(void *data) -{ - int ret, cpuid; - struct test_trng_pthread_dt *pdata = data; - struct wd_queue *q = NULL; - cpu_set_t mask; - struct wcrypto_rng_ctx_setup setup; - struct wcrypto_rng_ctx *ctx = NULL; - struct trng_user_tag_info *tag = NULL; - struct wcrypto_rng_op_data opdata; - int pid = getpid(); - int thread_id = (int)syscall(__NR_gettid); - int *out_data; - int i = 0; - - CPU_ZERO(&mask); - cpuid = pdata->cpu_id; - q = (struct wd_queue *)pdata->q; - CPU_SET(cpuid, &mask); - - if (!q) { - RNG_TST_PRT("q null!\n"); - return NULL; - } - if (cpuid) { - ret = pthread_setaffinity_np(pthread_self(), - sizeof(mask), &mask); - if (ret < 0) { - RNG_TST_PRT("Proc-%d, thrd-%d:set affinity fail!\n", - pid, thread_id); - return NULL; - } - RNG_TST_PRT("Proc-%d, thrd-%d bind to cpu-%d!\n", - pid, thread_id, cpuid); - } - - q->capa.alg = "trng"; - memset(&setup, 0, sizeof(setup)); - memset(&opdata, 0, sizeof(opdata)); - setup.cb = _trng_cb; - ctx = wcrypto_create_rng_ctx(q, &setup); - if (!ctx) { - RNG_TST_PRT("Proc-%d, %d-TD:create %s ctx fail!\n", - pid, thread_id, q->capa.alg); - goto fail_release; - } - - while(1) { - tag = malloc(sizeof(struct trng_user_tag_info)); - if (!tag) { - RNG_TST_PRT("malloc tag fail!\n"); - goto fail_release; - } - - tag->pid = pid; - tag->thread_id = thread_id; - - out_data = malloc(g_input); - if(!out_data) { - RNG_TST_PRT("malloc fail\n"); - return 0; - } - - opdata.in_bytes = g_input; - opdata.out = out_data; - try_again: - ret = wcrypto_do_rng(ctx, &opdata, tag); - if (ret == -WD_EBUSY) { - usleep(100); - goto try_again; - } else if(ret) { - RNG_TST_PRT("Proc-%d, T-%d:trng %d fail!\n", pid, thread_id, i); - goto fail_release; - } - i++; - } -fail_release: - wcrypto_del_rng_ctx(ctx); - return NULL; -} - -static void* _trng_async_poll_test_thread(void *data) -{ - struct test_trng_pthread_dt *pdata = data; - struct wd_queue *q = pdata->q; - int ret, cpuid; - int pid = getpid(); - cpu_set_t mask; - int thread_id = (int)syscall(__NR_gettid); - - CPU_ZERO(&mask); - cpuid = pdata->cpu_id; - CPU_SET(cpuid, &mask); - if (cpuid) { - ret = pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask); - if (ret < 0) { - RNG_TST_PRT("Proc-%d, thrd-%d:set affinity fail!\n", - pid, thread_id); - return NULL; - } - RNG_TST_PRT("Proc-%d, poll thrd-%d bind to cpu-%d!\n", - pid, thread_id, cpuid); - } - - while (1) { - ret = wcrypto_rng_poll(q, 1); - if (ret < 0) { - break; - } - } - - return NULL; -} - -static int trng_asys_test(int thread_num, __u64 lcore_mask, __u64 hcore_mask) -{ - int i, ret, cnt = 0; - struct wd_queue q; - int h_cpuid; - - memset(&q, 0, sizeof(q)); - - q.capa.alg = "trng"; - ret = wd_request_queue(&q); - if (ret) { - RNG_TST_PRT("request queue fail!\n"); - return ret; - } - - if (_get_one_bits(lcore_mask) > 0) - cnt = _get_one_bits(lcore_mask); - else if (_get_one_bits(lcore_mask) == 0 && - _get_one_bits(hcore_mask) == 0) - cnt = thread_num; - - test_thrds_data[0].q= &q; - test_thrds_data[0].thread_num = 1; - test_thrds_data[0].cpu_id = _get_cpu_id(0, lcore_mask); - ret = pthread_create(&system_test_thrds[0], NULL, - _trng_async_poll_test_thread, &test_thrds_data[0]); - if (ret) { - RNG_TST_PRT("Create poll thread fail!\n"); - return ret; - } - - for (i = 1; i <= cnt; i++) { - test_thrds_data[i].q = &q; - test_thrds_data[i].thread_num = thread_num; - test_thrds_data[i].cpu_id = _get_cpu_id(i, lcore_mask); - ret = pthread_create(&system_test_thrds[i], NULL, - _trng_asys_test_thread, &test_thrds_data[i]); - if (ret) { - RNG_TST_PRT("Create %dth thread fail!\n", i); - return ret; - } - } - - for (i = 1; i <= thread_num - cnt; i++) { - h_cpuid = _get_cpu_id(i, hcore_mask); - if (h_cpuid > 0) - h_cpuid += 64; - test_thrds_data[i + cnt].q = &q; - test_thrds_data[i + cnt].thread_num = thread_num; - test_thrds_data[i + cnt].cpu_id = h_cpuid; - ret = pthread_create(&system_test_thrds[i + cnt], NULL, - _trng_asys_test_thread, &test_thrds_data[i + cnt]); - if (ret) { - RNG_TST_PRT("Create %dth thread fail!\n", i); - return ret; - } - } - - for (i = 0; i < thread_num; i++) { - ret = pthread_join(system_test_thrds[i], NULL); - if (ret) { - RNG_TST_PRT("Join %dth thread fail!\n", i); - return ret; - } - } - - wd_release_queue(&q); - return 0; - -} -int main(int argc, char *argv[]) -{ - struct wcrypto_rng_ctx *ctx; - struct wcrypto_rng_op_data opdata; - struct wcrypto_rng_ctx_setup setup; - enum alg_op_type alg_op_type = TRNG_GEN; - int thread_num, bits; - __u64 core_mask[2]; - struct wd_queue q; - void *tag = NULL; - int *data; - int ret; - int fd = -1; - int fd_w = -1; - if (!argv[1]) { - RNG_TST_PRT("pls printf the size of the random data!\n"); - return -WD_EINVAL; - } - g_input = (unsigned int)strtoul(argv[1], NULL, 10); - printf("g_input:%d\n",g_input); - //if (g_input <= 0){ - // printf("input error!\n"); - // return -WD_EINVAL; - //} - if (argv[2]) { - if(!strcmp(argv[2], "-system-gen")) { - alg_op_type = TRNG_GEN; - RNG_TST_PRT("Now doing system random number gen test!\n"); - } else if(!strcmp(argv[2], "-system-agen")) { - alg_op_type = TRNG_AGEN; - RNG_TST_PRT("Now doing system random number agen test!\n"); - } - - thread_num = strtoul((char *)argv[3], NULL, 10); - if (thread_num <= 0 || thread_num > TEST_MAX_THRD) { - RNG_TST_PRT("Invalid threads num:%d!\n", - thread_num); - RNG_TST_PRT("Now set threads num as 2\n"); - thread_num = 2; - } - - if (strcmp(argv[4], "-c")) { - RNG_TST_PRT("./test_hisi_trng --help get details\n"); - return -EINVAL; - } - if (argv[5][0] != '0' || argv[5][1] != 'x') { - RNG_TST_PRT("Err:coremask should be hex!\n"); - return -EINVAL; - } - - if (strlen(argv[5]) > 34) { - RNG_TST_PRT("Warning: coremask is cut!\n"); - argv[5][34] = 0; - } - - if (strlen(argv[5]) <= 18) { - core_mask[0] = strtoull(argv[5], NULL, 16); - if (core_mask[0] & 0x1) { - RNG_TST_PRT("Warn:cannot bind to core 0,\n"); - RNG_TST_PRT("now run without binding\n"); - core_mask[0] = 0x0; /* no binding */ - } - core_mask[1] = 0; - } else { - int offset = 0; - char *temp; - - offset = strlen(argv[5]) - 16; - core_mask[0] = strtoull(&argv[5][offset], NULL, 16); - if (core_mask[0] & 0x1) { - RNG_TST_PRT("Warn:cannot bind to core 0,\n"); - RNG_TST_PRT("now run without binding\n"); - core_mask[0] = 0x0; /* no binding */ - } - temp = malloc(64); - strcpy(temp, argv[5]); - temp[offset] = 0; - core_mask[1] = strtoull(temp, NULL, 16); - free(temp); - } - - bits = _get_one_bits(core_mask[0]); - bits += _get_one_bits(core_mask[1]); - if (thread_num > bits) { - RNG_TST_PRT("Coremask not covers all thrds,\n"); - RNG_TST_PRT("Bind first %d thrds!\n", bits); - } else if (thread_num < bits) { - RNG_TST_PRT("Coremask overflow,\n"); - RNG_TST_PRT("Just try to bind all thrds!\n"); - } - - if (argv[6]) { - ctx_num_per_q = strtoul(argv[6], NULL, 10); - if (ctx_num_per_q <= 0) { - RNG_TST_PRT("Invalid ctx num per queue:%s!\n", - argv[6]); - RNG_TST_PRT("Now ctx num per queue is set as 1!\n"); - ctx_num_per_q = 1; - } - } else { - RNG_TST_PRT("Now ctx num per queue is set as 1!\n"); - ctx_num_per_q = 1; - } - - q_num = (thread_num - 1) / ctx_num_per_q + 1; - - RNG_TST_PRT("Proc-%d: starts %d threads bind to %s\n", - getpid(), thread_num, argv[5]); - RNG_TST_PRT(" lcoremask=0x%llx, hcoremask=0x%llx\n", - core_mask[0], core_mask[1]); - if(alg_op_type == TRNG_GEN) - return trng_sys_test(thread_num, core_mask[0], - core_mask[1]); - - return trng_asys_test(thread_num, core_mask[0], - core_mask[1]); - } - - RNG_TST_PRT("Now try to get %d bytes random number.\n", g_input); - - data = malloc(g_input); - if (!data) { - RNG_TST_PRT("malloc data failed.\n"); - return -1; - } - - memset((void *)&q, 0, sizeof(q)); - memset(&setup, 0, sizeof(setup)); - memset(&opdata, 0, sizeof(opdata)); - - q.capa.alg = "trng"; - ret = wd_request_queue(&q); - if (ret) { - RNG_TST_PRT("request queue fail!\n"); - return ret; - } - ctx = wcrypto_create_rng_ctx(&q, &setup); - if (!ctx) { - ret = -ENOMEM; - RNG_TST_PRT("create trng ctx fail!\n"); - goto release_q; - } - - opdata.in_bytes = g_input; - opdata.out = data; - ret = wcrypto_do_rng(ctx, &opdata, tag); - if (ret != 1) { - RNG_TST_PRT("a wd_do_trng fail!\n"); - goto del_ctx; - } - - RNG_TST_PRT("random_data size= %d.\n", opdata.out_bytes); - fd_w = open ("/root/trng_file", O_RDWR|O_CREAT|O_TRUNC,0777); - if (fd_w <0 ) { - printf("can not open trng_file\n"); - return fd_w; - } - /*fd = open ("/dev/random", O_RDONLY); - if (fd <0 ) { - printf("can not open\n"); - return fd; - }*/ - /*ret = read(fd, data, g_input); - if (ret < 0) { - printf("read error %d\n", ret); - return ret; - }*/ - ret = write(fd_w,opdata.out,opdata.out_bytes); - if (ret < 0) { - printf("write error %d\n", ret); - return ret; - } - close(fd); - close(fd_w); -del_ctx: - wcrypto_del_rng_ctx(ctx); - -release_q: - wd_release_queue(&q); - free(data); - return ret; -} diff --git a/v1/wd.h b/v1/wd.h index 0132e25..35dcf31 100644 --- a/v1/wd.h +++ b/v1/wd.h @@ -184,7 +184,7 @@ struct wd_capa { * Other capabilities. * 0~15 bits: number of cookies that the user wants to allocate. * Optional, user can set value based on the number of requests and system memory, - * 1~1024 is valid. If the value is not set or invalid, the default value 64 (rng is 256) + * 1~1024 is valid. If the value is not set or invalid, the default value 64 * is used to initialize cookies. */ __u32 flags; diff --git a/v1/wd_adapter.c b/v1/wd_adapter.c index 1c9f656..df5368d 100644 --- a/v1/wd_adapter.c +++ b/v1/wd_adapter.c @@ -20,7 +20,6 @@ #include "v1/wd_util.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)) @@ -87,12 +86,6 @@ static const struct wd_drv_dio_if hw_dio_tbl[] = { { .init_sgl = qm_init_hwsgl_mem, .uninit_sgl = qm_uninit_hwsgl_mem, .sgl_merge = qm_merge_hwsgl, - }, { - .hw_type = "hisi-trng-v2", - .open = rng_init_queue, - .close = rng_uninit_queue, - .send = rng_send, - .recv = rng_recv, }, }; diff --git a/v1/wd_rng.c b/v1/wd_rng.c deleted file mode 100644 index 7a89cd1..0000000 --- a/v1/wd_rng.c +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright 2019 Huawei Technologies Co.,Ltd.All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <errno.h> - -#include <sys/types.h> -#include <sys/mman.h> - -#include "wd.h" -#include "wd_util.h" -#include "wd_rng.h" - -#define RNG_RESEND_CNT 8 -#define RNG_RECV_CNT 8 -#define WD_RNG_CTX_COOKIE_NUM 256 - -struct wcrypto_rng_cookie { - struct wcrypto_cb_tag tag; - struct wcrypto_rng_msg msg; -}; - -struct wcrypto_rng_ctx { - struct wd_cookie_pool pool; - unsigned long ctx_id; - struct wd_queue *q; - struct wcrypto_rng_ctx_setup setup; -}; - -static int wcrypto_setup_qinfo(struct wcrypto_rng_ctx_setup *setup, - struct wd_queue *q, __u32 *ctx_id) -{ - struct q_info *qinfo; - int ret = -WD_EINVAL; - - if (!q || !q->qinfo || !setup) { - WD_ERR("input parameter err!\n"); - return ret; - } - - if (strcmp(q->capa.alg, "trng")) { - WD_ERR("algorithm mismatch!\n"); - return ret; - } - qinfo = q->qinfo; - /* lock at ctx creating */ - wd_spinlock(&qinfo->qlock); - if (qinfo->ctx_num >= WD_MAX_CTX_NUM) { - WD_ERR("create too many trng ctx!\n"); - goto unlock; - } - - ret = wd_alloc_id(qinfo->ctx_id, WD_MAX_CTX_NUM, ctx_id, 0, - WD_MAX_CTX_NUM); - if (ret) { - WD_ERR("err: alloc ctx id fail!\n"); - goto unlock; - } - qinfo->ctx_num++; - ret = WD_SUCCESS; -unlock: - wd_unspinlock(&qinfo->qlock); - return ret; -} - -void *wcrypto_create_rng_ctx(struct wd_queue *q, - struct wcrypto_rng_ctx_setup *setup) -{ - struct wcrypto_rng_cookie *cookie; - struct wcrypto_rng_ctx *ctx; - struct q_info *qinfo; - __u32 cookies_num, i; - __u32 ctx_id = 0; - int ret; - - if (wcrypto_setup_qinfo(setup, q, &ctx_id)) - return NULL; - - ctx = calloc(1, sizeof(struct wcrypto_rng_ctx)); - if (!ctx) { - WD_ERR("alloc ctx memory fail!\n"); - goto free_ctx_id; - } - memcpy(&ctx->setup, setup, sizeof(*setup)); - ctx->q = q; - ctx->ctx_id = ctx_id + 1; - - cookies_num = wd_get_ctx_cookies_num(q->capa.flags, WD_RNG_CTX_COOKIE_NUM); - ret = wd_init_cookie_pool(&ctx->pool, - sizeof(struct wcrypto_rng_cookie), cookies_num); - if (ret) { - WD_ERR("fail to init cookie pool!\n"); - free(ctx); - goto free_ctx_id; - } - for (i = 0; i < cookies_num; i++) { - cookie = (void *)((uintptr_t)ctx->pool.cookies + - i * ctx->pool.cookies_size); - cookie->msg.alg_type = WCRYPTO_RNG; - cookie->tag.ctx = ctx; - cookie->tag.ctx_id = ctx->ctx_id; - cookie->msg.usr_tag = (uintptr_t)&cookie->tag; - } - - return ctx; - -free_ctx_id: - qinfo = q->qinfo; - wd_spinlock(&qinfo->qlock); - qinfo->ctx_num--; - wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, ctx_id, WD_MAX_CTX_NUM); - wd_unspinlock(&qinfo->qlock); - - return NULL; -} - -void wcrypto_del_rng_ctx(void *ctx) -{ - struct wcrypto_rng_ctx *cx; - struct q_info *qinfo; - - if (!ctx) { - WD_ERR("delete trng ctx is NULL!\n"); - return; - } - - cx = ctx; - qinfo = cx->q->qinfo; - - wd_uninit_cookie_pool(&cx->pool); - wd_spinlock(&qinfo->qlock); - if (qinfo->ctx_num <= 0) { - wd_unspinlock(&qinfo->qlock); - WD_ERR("repeat delete trng ctx!\n"); - return; - } - qinfo->ctx_num--; - wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, cx->ctx_id - 1, - WD_MAX_CTX_NUM); - wd_unspinlock(&qinfo->qlock); - - free(ctx); -} - -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; - - if (!q) { - WD_ERR("%s(): input parameter err!\n", __func__); - return -WD_EINVAL; - } - - do { - ret = wd_recv(q, (void **)&resp); - if (!ret) - break; - - if (ret < 0) { - WD_ERR("recv err at trng poll!\n"); - return ret; - } - - count++; - tag = (void *)(uintptr_t)resp->usr_tag; - ctx = tag->ctx; - ctx->setup.cb(resp, tag->tag); - wd_put_cookies(&ctx->pool, (void **)&tag, 1); - resp = NULL; - } while (--tmp); - - return count; -} - -static int wcrypto_do_prepare(struct wcrypto_rng_cookie **cookie_addr, - struct wcrypto_rng_op_data *opdata, - struct wcrypto_rng_msg **req_addr, - struct wcrypto_rng_ctx *ctxt, - void *tag) -{ - struct wcrypto_rng_cookie *cookie; - struct wcrypto_rng_msg *req; - int ret; - - if (unlikely(!ctxt || !opdata)) { - WD_ERR("invalid: rng input parameter err!\n"); - return -WD_EINVAL; - } - - if (unlikely((opdata->in_bytes && !opdata->out))) { - WD_ERR("invalid: dst addr is NULL when in_bytes is non-zero!!\n"); - return -WD_EINVAL; - } - - ret = wd_get_cookies(&ctxt->pool, (void **)&cookie, 1); - if (ret) - return ret; - - if (tag) { - if (!ctxt->setup.cb) { - WD_ERR("invalid: ctx call back is null!\n"); - wd_put_cookies(&ctxt->pool, (void **)&cookie, 1); - return -WD_EINVAL; - } - cookie->tag.tag = tag; - } - - req = &cookie->msg; - req->in_bytes = opdata->in_bytes; - req->out = opdata->out; - *cookie_addr = cookie; - *req_addr = req; - - return 0; -} - -int wcrypto_do_rng(void *ctx, struct wcrypto_rng_op_data *opdata, void *tag) -{ - struct wcrypto_rng_ctx *ctxt = ctx; - struct wcrypto_rng_cookie *cookie; - struct wcrypto_rng_msg *req; - struct wcrypto_rng_msg *resp; - uint32_t tx_cnt = 0; - uint32_t rx_cnt = 0; - int ret = 0; - - ret = wcrypto_do_prepare(&cookie, opdata, &req, ctxt, tag); - if (ret) - return ret; - - 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; - } - } while (true); - - if (tag) - return ret; - - resp = (void *)(uintptr_t)ctxt->ctx_id; - - 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; - } - } while (true); - - opdata->out_bytes = resp->out_bytes; - ret = WD_SUCCESS; -fail_with_cookie: - wd_put_cookies(&ctxt->pool, (void **)&cookie, 1); - return ret; -} diff --git a/v1/wd_rng.h b/v1/wd_rng.h deleted file mode 100644 index fcde26d..0000000 --- a/v1/wd_rng.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2019 Huawei Technologies Co.,Ltd.All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __WD_RNG_H -#define __WD_RNG_H - -#include "wd.h" -#include "wd_digest.h" -#include "wd_cipher.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct wcrypto_rng_ctx_setup { - wcrypto_cb cb; - __u16 data_fmt; /* Data format, denoted by enum wd_buff_type */ - enum wcrypto_type type; /* Please refer to the definition of enum */ - enum wcrypto_cipher_alg calg; /* DRBG cipher algorithm */ - enum wcrypto_cipher_mode cmode; /* DRBG cipher mode */ - enum wcrypto_digest_alg dalg; /* DRBG digest algorithm */ - enum wcrypto_digest_mode dmode; /* DRBG digest mode */ -}; - -struct wcrypto_rng_msg { - __u8 alg_type; /* Denoted by enum wcrypto_type */ - __u8 op_type; /* Denoted by enum wcrypto_rng_op_type */ - __u8 data_fmt; /* Data format, denoted by enum wd_buff_type */ - __u8 result; /* Data format, denoted by WD error code */ - __u8 *out; /* Result address */ - __u8 *in; /* Input address */ - __u32 out_bytes; /* output bytes */ - __u32 in_bytes; /* input bytes */ - __u64 usr_tag; /* user identifier */ -}; - -enum wcrypto_rng_op_type { - WCRYPTO_RNG_INVALID, /* Invalid RNG operational type */ - WCRYPTO_DRBG_RESEED, /* seed operation */ - WCRYPTO_DRBG_GEN, /* deterministic random number generation */ - WCRYPTO_TRNG_GEN, /* true random number generation */ -}; - -struct wcrypto_rng_op_data { - enum wcrypto_rng_op_type op_type; - __u32 status; /* Operation result status */ - void *in; /* input */ - void *out; /* output */ - __u32 in_bytes; /* input bytes */ - __u32 out_bytes; /* output bytes */ -}; - -void *wcrypto_create_rng_ctx(struct wd_queue *q, - struct wcrypto_rng_ctx_setup *setup); -void wcrypto_del_rng_ctx(void *ctx); -int wcrypto_do_rng(void *ctx, struct wcrypto_rng_op_data *opdata, void *tag); -int wcrypto_rng_poll(struct wd_queue *q, unsigned int num); - -#ifdef __cplusplus -} -#endif - -#endif -- 2.33.0
From: Zhangfei Gao <zhangfei.gao@linaro.org> Release 2.9 in 2025.6 Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org> Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- Makefile.am | 8 ++++---- configure.ac | 2 +- docs/ReleaseNotes.md | 8 ++++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Makefile.am b/Makefile.am index 7749613..251e92d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,13 +22,13 @@ endif # WITH_LOG_FILE # y = minor # z = revision MAJOR = 2 -MINOR = 8 +MINOR = 9 REVISION = 0 UADK_VERSION = -version-number ${MAJOR}:${MINOR}:${REVISION} -DAY = 1 -MONTH = Dec -YEAR = 2024 +DAY = 6 +MONTH = June +YEAR = 2025 AM_CFLAGS+= -DUADK_VERSION_NUMBER="\"UADK version: ${MAJOR}.${MINOR}.${REVISION}\"" AM_CFLAGS+= -DUADK_RELEASED_TIME="\"Released ${MONTH} ${DAY}, ${YEAR}\"" diff --git a/configure.ac b/configure.ac index eb5a211..fab3a94 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([uadk], [2.8], [liguozhu@hisilicon.com]) +AC_INIT([uadk], [2.9], [liguozhu@hisilicon.com]) AC_CONFIG_SRCDIR([wd.c]) AM_INIT_AUTOMAKE([1.10 no-define]) diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index 1db8aa6..61283a4 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -1,4 +1,12 @@ +# UADK Release v2.9 June 2025 + +## Features: +- Support hmac(sm3)-cbc(sm4) algorithm +- Add a high-performance mode for the ECC algorithm +- Removed trng algorithm +- Update CI testing tools + # UADK Release v2.8 Dec 2024 ## Features: -- 2.33.0
From: Haojian Zhuang <haojian.zhuang@linaro.org> Add a guideline on how to add a test case into sanity_test. Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org> --- docs/sanity_test.md | 86 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 docs/sanity_test.md diff --git a/docs/sanity_test.md b/docs/sanity_test.md new file mode 100644 index 0000000..e11c215 --- /dev/null +++ b/docs/sanity_test.md @@ -0,0 +1,86 @@ + +# Sanity Test Guide + +## Sanity Test Overview + +The sanity test focuses on functional validation of compression and encryption +features, utilizing UADK (User-space Accelerator Development Kit) to verify correct +behavior when hardware acceleration is available. To build this test suite, OpenSSL +must be installed, as it is a core dependency. + +**Usage** + +Users can execute the tests directly by running the script: +``` +$./test/sanity_test.sh +``` + +This provides a simple, one-command method to verify functionally. + + +## Add Test Case into Sanity Test + +The sanity test suite includes multiple test cases, and each result must be clearly +logged to identify any failures. To maintain consistency, developers must adhere to +the following guidelines when adding new test cases: + +### Test Execution and Logging + +The run_cmd() function will execute test commands with structured logging and result +tracking. For example: +``` +run_cmd "HW compress for gzip format in block mode" \ + uadk_tool test --m zip --alg 2 --in origin --out /tmp/ori.gz +``` + +**Command Structure Requirements** + +1. Function Prefix +All commands must begin with **run_cmd** to trigger the execution framework. + +2. Descriptive Comment +A quoted description explaining the test purpose (e.g., "Hw compress..."). + +3. Original Command +The actual command/arguments follow the description. + +**Logging and Tracking** + +Test Case ID: Automatically generated and displayed in logs. +Result Recording: Explicit pass/fail status. +Output Format: +``` +Command [5]: uadk_tool test --m zip --alg 2 --inf --in /tmp/ori.gz --out origin + Command passed (CMD: HW decompress for gzip format in block mode). +``` + +**Test Command Execution Control** + +The test framework provides two execution modes to accommodate different debugging +needs: + +1. Verbose Mode (run_cmd) + +Display full command output for debugging. +Example: + +``` +run_cmd "HW compress for gzip format in block mode" \ + uadk_tool test --m zip --alg 2 --in origin --out /tmp/ori.gz +``` + +2. Quiet Mode (run_cmd_quiet) + +Suppress command output. +Example: +``` +run_cmd_quiet "HW compress for gzip format in block mode" \ + uadk_tool test --m zip --alg 2 --in origin --out /tmp/ori.gz +``` + +**Test Summary Report** + +A test summary report is generated. +``` +Passed 46 test. Failed 0 test. +``` -- 2.33.0
From: Haojian Zhuang <haojian.zhuang@linaro.org> python2 is decrepated in some OS releases. Upgrade the script to python3. Since division is always return with float type in python3, force to use '//'. It could return with int type. Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org> --- test/list_loader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/list_loader.py b/test/list_loader.py index 7421158..a9da78d 100755 --- a/test/list_loader.py +++ b/test/list_loader.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 #-*- coding: utf-8 -*- import os @@ -20,7 +20,7 @@ class listcontent(object): def deflate(self, blk_sz): ifile_sz = os.path.getsize(self.ifile_nm) - count = (ifile_sz + int(blk_sz) - 1) / int(blk_sz) + count = (ifile_sz + int(blk_sz) - 1) // int(blk_sz) # Create array data = np.ndarray(count * 3, dtype=np.uint64) i = 0 -- 2.33.0
From: Haojian Zhuang <haojian.zhuang@linaro.org> In openeuler docker environment, although OpenSSL is compiled and installed into /usr/local/lib. It's not in the search path of pkg-config. So add it by manual in conf.sh. Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org> --- conf.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf.sh b/conf.sh index c361fbc..af5f787 100755 --- a/conf.sh +++ b/conf.sh @@ -11,8 +11,8 @@ if [[ $1 && $1 = "--static" ]] || [[ $2 && $2 = "--static" ]]; then COMPILE_TYPE="--enable-static --disable-shared --with-static_drv" fi - -ac_cv_func_malloc_0_nonnull=yes ac_cv_func_realloc_0_nonnull=yes ./configure \ +export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH +ac_cv_func_malloc_0_nonnull=yes ac_cv_func_realloc_0_nonnull=yes ./configure -v \ --enable-perf=yes \ --host aarch64-linux-gnu \ --target aarch64-linux-gnu \ -- 2.33.0
From: Zhangfei Gao <zhangfei.gao@linaro.org> Release 2.10 in 2025.12 Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org> Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- Makefile.am | 6 +++--- configure.ac | 2 +- docs/ReleaseNotes.md | 27 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index 251e92d..b38c5ce 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,12 +22,12 @@ endif # WITH_LOG_FILE # y = minor # z = revision MAJOR = 2 -MINOR = 9 +MINOR = 10 REVISION = 0 UADK_VERSION = -version-number ${MAJOR}:${MINOR}:${REVISION} -DAY = 6 -MONTH = June +DAY = 10 +MONTH = Dec YEAR = 2025 AM_CFLAGS+= -DUADK_VERSION_NUMBER="\"UADK version: ${MAJOR}.${MINOR}.${REVISION}\"" AM_CFLAGS+= -DUADK_RELEASED_TIME="\"Released ${MONTH} ${DAY}, ${YEAR}\"" diff --git a/configure.ac b/configure.ac index fab3a94..b0746ad 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([uadk], [2.9], [liguozhu@hisilicon.com]) +AC_INIT([uadk], [2.10], [liguozhu@hisilicon.com]) AC_CONFIG_SRCDIR([wd.c]) AM_INIT_AUTOMAKE([1.10 no-define]) diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index 61283a4..7b5bb55 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -1,4 +1,31 @@ +# UADK Release v2.10 Dec 2025 + +## Features: +- New Algorithms: Added LZ4, LZ77_only, AEAD (AES_256_GCM, etc.) +- Data Processing: Added data move (copy/init), hashagg max/min, and rehash operations +- Hardware Acceleration: Support for hash-agg,hash-join and gather algorithms +- NO-SVA Mode: + - Support for ZIP, SEC, and HPRE modules + - Unified memory pool for SVA/NO-SVA modes + - SGL memory support in NO-SVA mode +- Support device internal queue scheduling functionality for No-SVA mode +- Tooling: New SGL benchmarks, SVA/NO-SVA validation interfaces, and device ID tool +- Configuration: Added uadk.cnf for driver library management + +## Fixes: +- Memory: Fixed memory over-allocation and resource release issues +- Compression: Fixed ZSTD repcode handling and stream mode flushing +- Performance: Disabled SVA prefetch for packets >24KB +- Stability: Improved memory pool retry and error handling +- Code Quality: Fixed stack overflow, variable overflow, and cleanup warnings + + +# UADK Release v2.9.1 July 2025 + +## Fixes: +- Fix x86 build issues + # UADK Release v2.9 June 2025 ## Features: -- 2.33.0
participants (1)
-
ZongYu Wu