Acc
Threads by month
- ----- 2026 -----
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- 1 participants
- 403 discussions
From: Weili Qian <qianweili(a)huawei.com>
The trng module is not required. Therefore, remove the trng module code.
Signed-off-by: Weili Qian <qianweili(a)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
1
0
From: Weili Qian <qianweili(a)huawei.com>
The trng module is not required. Therefore, remove the trng module code.
Signed-off-by: Weili Qian <qianweili(a)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
1
0
From: Weili Qian <qianweili(a)huawei.com>
The trng module is not required. Therefore, remove the trng module code.
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
Signed-off-by: Qi Tao <taoqi10(a)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
1
0
From: Hao Fang <fanghao11(a)huawei.com>
add testcase for init2 just use cmd --init 2.
default or --init 1 for init interface.
Signed-off-by: Hao Fang <fanghao11(a)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
1
12
12 Feb '26
From: Weili Qian <qianweili(a)huawei.com>
Fix the compilation failure of wd_alg.h, error log likes:
wd_alg.h:121:9: error: unknown type name ‘__u8’.
And improve code portability by including linux/types.h
instead of asm/types.h.
Upstream: YES
Feature or Bugfix:Bugfix
AR: AR20230722287656
DTS: DTS2026012302441
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
drv/hisi_comp.c | 2 +-
drv/hisi_comp_huf.c | 2 +-
drv/hisi_comp_huf.h | 2 +-
include/drv/wd_agg_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_ecc_drv.h | 2 +-
include/drv/wd_join_gather_drv.h | 2 +-
include/drv/wd_rsa_drv.h | 2 +-
include/drv/wd_udma_drv.h | 2 +-
include/wd.h | 6 ++----
include/wd_agg.h | 3 ++-
include/wd_alg.h | 1 +
include/wd_cipher.h | 3 ++-
include/wd_dae.h | 3 ++-
include/wd_join_gather.h | 3 ++-
include/wd_sched.h | 2 +-
include/wd_util.h | 2 +-
include/wd_zlibwrapper.h | 2 +-
20 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index 6758c02..7c449e0 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/* Copyright 2020-2021 Huawei Technologies Co.,Ltd. All rights reserved. */
-#include <asm/types.h>
+#include <linux/types.h>
#include "drv/wd_comp_drv.h"
#include "drv/hisi_comp_huf.h"
#include "hisi_qm_udrv.h"
diff --git a/drv/hisi_comp_huf.c b/drv/hisi_comp_huf.c
index 161fee4..c64c418 100644
--- a/drv/hisi_comp_huf.c
+++ b/drv/hisi_comp_huf.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/* Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved. */
-#include <asm/types.h>
+#include <linux/types.h>
#include "drv/hisi_comp_huf.h"
#include "wd_util.h"
diff --git a/drv/hisi_comp_huf.h b/drv/hisi_comp_huf.h
index 6585b7a..dde0ff4 100644
--- a/drv/hisi_comp_huf.h
+++ b/drv/hisi_comp_huf.h
@@ -4,7 +4,7 @@
#ifndef __HISI_COMP_HUF_H
#define __HISI_COMP_HUF_H
-#include <asm/types.h>
+#include <linux/types.h>
#ifdef __cplusplus
extern "C" {
diff --git a/include/drv/wd_agg_drv.h b/include/drv/wd_agg_drv.h
index 978c2d3..b26b25d 100644
--- a/include/drv/wd_agg_drv.h
+++ b/include/drv/wd_agg_drv.h
@@ -6,7 +6,7 @@
#ifndef __WD_AGG_DRV_H
#define __WD_AGG_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_agg.h"
#include "wd_util.h"
diff --git a/include/drv/wd_cipher_drv.h b/include/drv/wd_cipher_drv.h
index c0be0c3..458a8d8 100644
--- a/include/drv/wd_cipher_drv.h
+++ b/include/drv/wd_cipher_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_CIPHER_DRV_H
#define __WD_CIPHER_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_cipher.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h
index 95f7fb7..2311d79 100644
--- a/include/drv/wd_comp_drv.h
+++ b/include/drv/wd_comp_drv.h
@@ -5,7 +5,7 @@
#define __WD_COMP_DRV_H
#include <pthread.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_comp.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
index d2a6157..a46aa90 100644
--- a/include/drv/wd_dh_drv.h
+++ b/include/drv/wd_dh_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_DH_DRV_H
#define __WD_DH_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_dh.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index b123a9b..48c422f 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -5,7 +5,7 @@
#define __WD_ECC_DRV_H
#include <stdint.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_ecc.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_join_gather_drv.h b/include/drv/wd_join_gather_drv.h
index 80fb932..dbf4ee7 100644
--- a/include/drv/wd_join_gather_drv.h
+++ b/include/drv/wd_join_gather_drv.h
@@ -6,7 +6,7 @@
#ifndef __WD_JOIN_GATHER_DRV_H
#define __WD_JOIN_GATHER_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_join_gather.h"
#include "wd_util.h"
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
index c12f3e0..728abdf 100644
--- a/include/drv/wd_rsa_drv.h
+++ b/include/drv/wd_rsa_drv.h
@@ -3,7 +3,7 @@
#ifndef __WD_RSA_DRV_H
#define __WD_RSA_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_rsa.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_udma_drv.h b/include/drv/wd_udma_drv.h
index c8028f7..8c5edea 100644
--- a/include/drv/wd_udma_drv.h
+++ b/include/drv/wd_udma_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_UDMA_DRV_H
#define __WD_UDMA_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_udma.h"
#include "../wd_util.h"
diff --git a/include/wd.h b/include/wd.h
index 7e92e41..a468047 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -15,7 +15,8 @@
#include <string.h>
#include <syslog.h>
#include <unistd.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "uacce.h"
#ifdef __cplusplus
@@ -33,9 +34,6 @@ extern "C" {
#define CRYPTO_MAX_ALG_NAME 128
#define NUMA_NO_NODE (-1)
-typedef unsigned char __u8;
-typedef unsigned int __u32;
-typedef unsigned long long __u64;
/* Required compiler attributes */
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
diff --git a/include/wd_agg.h b/include/wd_agg.h
index fed08c5..b35c8c2 100644
--- a/include/wd_agg.h
+++ b/include/wd_agg.h
@@ -7,7 +7,8 @@
#define __WD_AGG_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_dae.h"
#ifdef __cplusplus
diff --git a/include/wd_alg.h b/include/wd_alg.h
index 7a3ae5f..18503ca 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -10,6 +10,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
+#include <linux/types.h>
#ifdef __cplusplus
extern "C" {
diff --git a/include/wd_cipher.h b/include/wd_cipher.h
index 1d82eac..a6f8be1 100644
--- a/include/wd_cipher.h
+++ b/include/wd_cipher.h
@@ -8,7 +8,8 @@
#define __WD_CIPHER_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_alg_common.h"
#ifdef __cplusplus
diff --git a/include/wd_dae.h b/include/wd_dae.h
index 64f17dc..3d7463e 100644
--- a/include/wd_dae.h
+++ b/include/wd_dae.h
@@ -8,7 +8,8 @@
#include <dlfcn.h>
#include <stdbool.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_alg_common.h"
#include "wd.h"
diff --git a/include/wd_join_gather.h b/include/wd_join_gather.h
index 4962ee3..44588b2 100644
--- a/include/wd_join_gather.h
+++ b/include/wd_join_gather.h
@@ -7,7 +7,8 @@
#define __WD_JOIN_GATHER_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_dae.h"
#ifdef __cplusplus
diff --git a/include/wd_sched.h b/include/wd_sched.h
index 949396e..5baecd3 100644
--- a/include/wd_sched.h
+++ b/include/wd_sched.h
@@ -6,7 +6,7 @@
#ifndef SCHED_SAMPLE_h
#define SCHED_SAMPLE_h
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_alg_common.h"
#ifdef __cplusplus
diff --git a/include/wd_util.h b/include/wd_util.h
index a337284..2abceec 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -11,7 +11,7 @@
#include <stdbool.h>
#include <sys/ipc.h>
#include <sys/shm.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd.h"
#include "wd_sched.h"
diff --git a/include/wd_zlibwrapper.h b/include/wd_zlibwrapper.h
index 978d1ed..80ba08f 100644
--- a/include/wd_zlibwrapper.h
+++ b/include/wd_zlibwrapper.h
@@ -6,7 +6,7 @@
#ifndef UADK_ZLIBWRAPPER_H
#define UADK_ZLIBWRAPPER_H
-#include <asm/types.h>
+#include <linux/types.h>
/*
* These APIs are used to replace the ZLIB library. So if you don't use them.
--
2.33.0
1
0
12 Feb '26
From: Weili Qian <qianweili(a)huawei.com>
Fix the compilation failure of wd_alg.h, error log likes:
wd_alg.h:121:9: error: unknown type name ‘__u8’.
And improve code portability by including linux/types.h
instead of asm/types.h.
Upstream: YES
Feature or Bugfix:Bugfix
AR: AR20230722287656
DTS: DTS2026012302441
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
drv/hisi_comp.c | 2 +-
drv/hisi_comp_huf.c | 2 +-
drv/hisi_comp_huf.h | 2 +-
include/drv/wd_agg_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_ecc_drv.h | 2 +-
include/drv/wd_join_gather_drv.h | 2 +-
include/drv/wd_rsa_drv.h | 2 +-
include/drv/wd_udma_drv.h | 2 +-
include/wd.h | 6 ++----
include/wd_agg.h | 3 ++-
include/wd_alg.h | 1 +
include/wd_cipher.h | 3 ++-
include/wd_dae.h | 3 ++-
include/wd_join_gather.h | 3 ++-
include/wd_sched.h | 2 +-
include/wd_util.h | 2 +-
include/wd_zlibwrapper.h | 2 +-
20 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index 6758c02..7c449e0 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/* Copyright 2020-2021 Huawei Technologies Co.,Ltd. All rights reserved. */
-#include <asm/types.h>
+#include <linux/types.h>
#include "drv/wd_comp_drv.h"
#include "drv/hisi_comp_huf.h"
#include "hisi_qm_udrv.h"
diff --git a/drv/hisi_comp_huf.c b/drv/hisi_comp_huf.c
index 161fee4..c64c418 100644
--- a/drv/hisi_comp_huf.c
+++ b/drv/hisi_comp_huf.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/* Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved. */
-#include <asm/types.h>
+#include <linux/types.h>
#include "drv/hisi_comp_huf.h"
#include "wd_util.h"
diff --git a/drv/hisi_comp_huf.h b/drv/hisi_comp_huf.h
index 6585b7a..dde0ff4 100644
--- a/drv/hisi_comp_huf.h
+++ b/drv/hisi_comp_huf.h
@@ -4,7 +4,7 @@
#ifndef __HISI_COMP_HUF_H
#define __HISI_COMP_HUF_H
-#include <asm/types.h>
+#include <linux/types.h>
#ifdef __cplusplus
extern "C" {
diff --git a/include/drv/wd_agg_drv.h b/include/drv/wd_agg_drv.h
index 978c2d3..b26b25d 100644
--- a/include/drv/wd_agg_drv.h
+++ b/include/drv/wd_agg_drv.h
@@ -6,7 +6,7 @@
#ifndef __WD_AGG_DRV_H
#define __WD_AGG_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_agg.h"
#include "wd_util.h"
diff --git a/include/drv/wd_cipher_drv.h b/include/drv/wd_cipher_drv.h
index c0be0c3..458a8d8 100644
--- a/include/drv/wd_cipher_drv.h
+++ b/include/drv/wd_cipher_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_CIPHER_DRV_H
#define __WD_CIPHER_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_cipher.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h
index 95f7fb7..2311d79 100644
--- a/include/drv/wd_comp_drv.h
+++ b/include/drv/wd_comp_drv.h
@@ -5,7 +5,7 @@
#define __WD_COMP_DRV_H
#include <pthread.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_comp.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
index d2a6157..a46aa90 100644
--- a/include/drv/wd_dh_drv.h
+++ b/include/drv/wd_dh_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_DH_DRV_H
#define __WD_DH_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_dh.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index b123a9b..48c422f 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -5,7 +5,7 @@
#define __WD_ECC_DRV_H
#include <stdint.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_ecc.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_join_gather_drv.h b/include/drv/wd_join_gather_drv.h
index 80fb932..dbf4ee7 100644
--- a/include/drv/wd_join_gather_drv.h
+++ b/include/drv/wd_join_gather_drv.h
@@ -6,7 +6,7 @@
#ifndef __WD_JOIN_GATHER_DRV_H
#define __WD_JOIN_GATHER_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_join_gather.h"
#include "wd_util.h"
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
index c12f3e0..728abdf 100644
--- a/include/drv/wd_rsa_drv.h
+++ b/include/drv/wd_rsa_drv.h
@@ -3,7 +3,7 @@
#ifndef __WD_RSA_DRV_H
#define __WD_RSA_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_rsa.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_udma_drv.h b/include/drv/wd_udma_drv.h
index c8028f7..8c5edea 100644
--- a/include/drv/wd_udma_drv.h
+++ b/include/drv/wd_udma_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_UDMA_DRV_H
#define __WD_UDMA_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_udma.h"
#include "../wd_util.h"
diff --git a/include/wd.h b/include/wd.h
index 7e92e41..a468047 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -15,7 +15,8 @@
#include <string.h>
#include <syslog.h>
#include <unistd.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "uacce.h"
#ifdef __cplusplus
@@ -33,9 +34,6 @@ extern "C" {
#define CRYPTO_MAX_ALG_NAME 128
#define NUMA_NO_NODE (-1)
-typedef unsigned char __u8;
-typedef unsigned int __u32;
-typedef unsigned long long __u64;
/* Required compiler attributes */
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
diff --git a/include/wd_agg.h b/include/wd_agg.h
index fed08c5..b35c8c2 100644
--- a/include/wd_agg.h
+++ b/include/wd_agg.h
@@ -7,7 +7,8 @@
#define __WD_AGG_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_dae.h"
#ifdef __cplusplus
diff --git a/include/wd_alg.h b/include/wd_alg.h
index 7a3ae5f..18503ca 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -10,6 +10,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
+#include <linux/types.h>
#ifdef __cplusplus
extern "C" {
diff --git a/include/wd_cipher.h b/include/wd_cipher.h
index 1d82eac..a6f8be1 100644
--- a/include/wd_cipher.h
+++ b/include/wd_cipher.h
@@ -8,7 +8,8 @@
#define __WD_CIPHER_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_alg_common.h"
#ifdef __cplusplus
diff --git a/include/wd_dae.h b/include/wd_dae.h
index 64f17dc..3d7463e 100644
--- a/include/wd_dae.h
+++ b/include/wd_dae.h
@@ -8,7 +8,8 @@
#include <dlfcn.h>
#include <stdbool.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_alg_common.h"
#include "wd.h"
diff --git a/include/wd_join_gather.h b/include/wd_join_gather.h
index 4962ee3..44588b2 100644
--- a/include/wd_join_gather.h
+++ b/include/wd_join_gather.h
@@ -7,7 +7,8 @@
#define __WD_JOIN_GATHER_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_dae.h"
#ifdef __cplusplus
diff --git a/include/wd_sched.h b/include/wd_sched.h
index 949396e..5baecd3 100644
--- a/include/wd_sched.h
+++ b/include/wd_sched.h
@@ -6,7 +6,7 @@
#ifndef SCHED_SAMPLE_h
#define SCHED_SAMPLE_h
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_alg_common.h"
#ifdef __cplusplus
diff --git a/include/wd_util.h b/include/wd_util.h
index a337284..2abceec 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -11,7 +11,7 @@
#include <stdbool.h>
#include <sys/ipc.h>
#include <sys/shm.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd.h"
#include "wd_sched.h"
diff --git a/include/wd_zlibwrapper.h b/include/wd_zlibwrapper.h
index 978d1ed..80ba08f 100644
--- a/include/wd_zlibwrapper.h
+++ b/include/wd_zlibwrapper.h
@@ -6,7 +6,7 @@
#ifndef UADK_ZLIBWRAPPER_H
#define UADK_ZLIBWRAPPER_H
-#include <asm/types.h>
+#include <linux/types.h>
/*
* These APIs are used to replace the ZLIB library. So if you don't use them.
--
2.33.0
1
0
From: Weili Qian <qianweili(a)huawei.com>
Fix the compilation failure of wd_alg.h, error log likes:
wd_alg.h:121:9: error: unknown type name ‘__u8’.
And improve code portability by including linux/types.h
instead of asm/types.h.
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
drv/hisi_comp.c | 2 +-
drv/hisi_comp_huf.c | 2 +-
drv/hisi_comp_huf.h | 2 +-
include/drv/wd_agg_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_ecc_drv.h | 2 +-
include/drv/wd_join_gather_drv.h | 2 +-
include/drv/wd_rsa_drv.h | 2 +-
include/drv/wd_udma_drv.h | 2 +-
include/wd.h | 6 ++----
include/wd_agg.h | 3 ++-
include/wd_alg.h | 1 +
include/wd_cipher.h | 3 ++-
include/wd_dae.h | 3 ++-
include/wd_join_gather.h | 3 ++-
include/wd_sched.h | 2 +-
include/wd_util.h | 2 +-
include/wd_zlibwrapper.h | 2 +-
20 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index cf8d315..a6b2947 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/* Copyright 2020-2021 Huawei Technologies Co.,Ltd. All rights reserved. */
-#include <asm/types.h>
+#include <linux/types.h>
#include "drv/wd_comp_drv.h"
#include "drv/hisi_comp_huf.h"
#include "hisi_qm_udrv.h"
diff --git a/drv/hisi_comp_huf.c b/drv/hisi_comp_huf.c
index 161fee4..c64c418 100644
--- a/drv/hisi_comp_huf.c
+++ b/drv/hisi_comp_huf.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/* Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved. */
-#include <asm/types.h>
+#include <linux/types.h>
#include "drv/hisi_comp_huf.h"
#include "wd_util.h"
diff --git a/drv/hisi_comp_huf.h b/drv/hisi_comp_huf.h
index 6585b7a..dde0ff4 100644
--- a/drv/hisi_comp_huf.h
+++ b/drv/hisi_comp_huf.h
@@ -4,7 +4,7 @@
#ifndef __HISI_COMP_HUF_H
#define __HISI_COMP_HUF_H
-#include <asm/types.h>
+#include <linux/types.h>
#ifdef __cplusplus
extern "C" {
diff --git a/include/drv/wd_agg_drv.h b/include/drv/wd_agg_drv.h
index 978c2d3..b26b25d 100644
--- a/include/drv/wd_agg_drv.h
+++ b/include/drv/wd_agg_drv.h
@@ -6,7 +6,7 @@
#ifndef __WD_AGG_DRV_H
#define __WD_AGG_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_agg.h"
#include "wd_util.h"
diff --git a/include/drv/wd_cipher_drv.h b/include/drv/wd_cipher_drv.h
index c0be0c3..458a8d8 100644
--- a/include/drv/wd_cipher_drv.h
+++ b/include/drv/wd_cipher_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_CIPHER_DRV_H
#define __WD_CIPHER_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_cipher.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h
index 95f7fb7..2311d79 100644
--- a/include/drv/wd_comp_drv.h
+++ b/include/drv/wd_comp_drv.h
@@ -5,7 +5,7 @@
#define __WD_COMP_DRV_H
#include <pthread.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_comp.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
index d2a6157..a46aa90 100644
--- a/include/drv/wd_dh_drv.h
+++ b/include/drv/wd_dh_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_DH_DRV_H
#define __WD_DH_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_dh.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index b123a9b..48c422f 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -5,7 +5,7 @@
#define __WD_ECC_DRV_H
#include <stdint.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_ecc.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_join_gather_drv.h b/include/drv/wd_join_gather_drv.h
index 80fb932..dbf4ee7 100644
--- a/include/drv/wd_join_gather_drv.h
+++ b/include/drv/wd_join_gather_drv.h
@@ -6,7 +6,7 @@
#ifndef __WD_JOIN_GATHER_DRV_H
#define __WD_JOIN_GATHER_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_join_gather.h"
#include "wd_util.h"
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
index c12f3e0..728abdf 100644
--- a/include/drv/wd_rsa_drv.h
+++ b/include/drv/wd_rsa_drv.h
@@ -3,7 +3,7 @@
#ifndef __WD_RSA_DRV_H
#define __WD_RSA_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_rsa.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_udma_drv.h b/include/drv/wd_udma_drv.h
index c8028f7..8c5edea 100644
--- a/include/drv/wd_udma_drv.h
+++ b/include/drv/wd_udma_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_UDMA_DRV_H
#define __WD_UDMA_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_udma.h"
#include "../wd_util.h"
diff --git a/include/wd.h b/include/wd.h
index 7e92e41..a468047 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -15,7 +15,8 @@
#include <string.h>
#include <syslog.h>
#include <unistd.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "uacce.h"
#ifdef __cplusplus
@@ -33,9 +34,6 @@ extern "C" {
#define CRYPTO_MAX_ALG_NAME 128
#define NUMA_NO_NODE (-1)
-typedef unsigned char __u8;
-typedef unsigned int __u32;
-typedef unsigned long long __u64;
/* Required compiler attributes */
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
diff --git a/include/wd_agg.h b/include/wd_agg.h
index fed08c5..b35c8c2 100644
--- a/include/wd_agg.h
+++ b/include/wd_agg.h
@@ -7,7 +7,8 @@
#define __WD_AGG_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_dae.h"
#ifdef __cplusplus
diff --git a/include/wd_alg.h b/include/wd_alg.h
index 7a3ae5f..18503ca 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -10,6 +10,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
+#include <linux/types.h>
#ifdef __cplusplus
extern "C" {
diff --git a/include/wd_cipher.h b/include/wd_cipher.h
index 1d82eac..a6f8be1 100644
--- a/include/wd_cipher.h
+++ b/include/wd_cipher.h
@@ -8,7 +8,8 @@
#define __WD_CIPHER_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_alg_common.h"
#ifdef __cplusplus
diff --git a/include/wd_dae.h b/include/wd_dae.h
index 64f17dc..3d7463e 100644
--- a/include/wd_dae.h
+++ b/include/wd_dae.h
@@ -8,7 +8,8 @@
#include <dlfcn.h>
#include <stdbool.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_alg_common.h"
#include "wd.h"
diff --git a/include/wd_join_gather.h b/include/wd_join_gather.h
index 4962ee3..44588b2 100644
--- a/include/wd_join_gather.h
+++ b/include/wd_join_gather.h
@@ -7,7 +7,8 @@
#define __WD_JOIN_GATHER_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_dae.h"
#ifdef __cplusplus
diff --git a/include/wd_sched.h b/include/wd_sched.h
index 949396e..5baecd3 100644
--- a/include/wd_sched.h
+++ b/include/wd_sched.h
@@ -6,7 +6,7 @@
#ifndef SCHED_SAMPLE_h
#define SCHED_SAMPLE_h
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_alg_common.h"
#ifdef __cplusplus
diff --git a/include/wd_util.h b/include/wd_util.h
index a337284..2abceec 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -11,7 +11,7 @@
#include <stdbool.h>
#include <sys/ipc.h>
#include <sys/shm.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd.h"
#include "wd_sched.h"
diff --git a/include/wd_zlibwrapper.h b/include/wd_zlibwrapper.h
index 978d1ed..80ba08f 100644
--- a/include/wd_zlibwrapper.h
+++ b/include/wd_zlibwrapper.h
@@ -6,7 +6,7 @@
#ifndef UADK_ZLIBWRAPPER_H
#define UADK_ZLIBWRAPPER_H
-#include <asm/types.h>
+#include <linux/types.h>
/*
* These APIs are used to replace the ZLIB library. So if you don't use them.
--
2.33.0
1
1
From: parm64 <parm64(a)huawei.com>
Weili Qian (9):
uadk_provider: set the default provider when initializing the uadk
provider
uadk_engine: release asynchronous resources before destroying
algorithm resources
uadk_provider: release asynchronous resources before destroying
algorithm resources
uadk_provider/sm2: move sm2 key generation into a separate file
uadk_provider/sm2: modify the return value of keygen
uadk_provider/sm2: remove unnecessary code
uadk_engine/ecc: remove unnecessary code
uadk_engine: fix compilation warnings
uadk_provider/sm2: split uadk_prov_sm2.c into 2 files
Zhushuai Yin (3):
uadk_provider: reduce lock scope during prov init to improve perf
uadk_engine: reduce lock scope during prov init to improve perf
uadk_provider: delete asynchronous redundancy declaration
lizhi (4):
uadk_provider: adapt uadk_provider with tls 1.3
uadk_provider: adapt rsa key management with pss padding mode
uadk_provider: adapt rsa pss key management with algorithm enable
configuration.
uadk_engine/ecc: fix memory leak in the ecx algorithm
src/Makefile.am | 4 +-
src/uadk_aead.c | 1 +
src/uadk_async.h | 1 -
src/uadk_cipher.c | 1 +
src/uadk_cipher_adapter.c | 2 +-
src/uadk_dh.c | 1 +
src/uadk_digest.c | 1 +
src/uadk_ec.c | 34 +-
src/uadk_ecx.c | 1 +
src/uadk_engine_init.c | 8 +-
src/uadk_pkey.c | 1 +
src/uadk_prov.h | 19 +-
src/uadk_prov_aead.c | 18 +-
src/uadk_prov_capabilities.c | 224 +++
src/uadk_prov_cipher.c | 70 +-
src/uadk_prov_dh.c | 66 +-
src/uadk_prov_digest.c | 18 +-
src/uadk_prov_ec_kmgmt.c | 19 +
src/uadk_prov_ecdh_exch.c | 33 +-
src/uadk_prov_ecx.c | 125 +-
src/uadk_prov_hmac.c | 24 +-
src/uadk_prov_init.c | 96 +-
src/uadk_prov_pkey.c | 14 +-
src/uadk_prov_pkey.h | 21 +-
src/uadk_prov_rsa.c | 14 +-
src/uadk_prov_rsa_enc.c | 34 +-
src/uadk_prov_rsa_kmgmt.c | 101 ++
src/uadk_prov_rsa_sign.c | 34 +-
src/uadk_prov_sm2.c | 3320 ----------------------------------
src/uadk_prov_sm2_enc.c | 860 +++++++++
src/uadk_prov_sm2_kmgmt.c | 505 ++++++
src/uadk_prov_sm2_sign.c | 1342 ++++++++++++++
src/uadk_rsa.c | 1 +
33 files changed, 3398 insertions(+), 3615 deletions(-)
create mode 100644 src/uadk_prov_capabilities.c
delete mode 100644 src/uadk_prov_sm2.c
create mode 100644 src/uadk_prov_sm2_enc.c
create mode 100644 src/uadk_prov_sm2_kmgmt.c
create mode 100644 src/uadk_prov_sm2_sign.c
--
2.43.0
1
16
From: Wenkai Lin <linwenkai6(a)hisilicon.com>
Adjusted the rehash descriptors counta_vld, agg_col_bit_map,
Agg_Oid, Agg_Out_Type, Col_Data_Type, and Col_Data_Info.
These descriptors are consistent with those generated by the
hash aggregation task. In addition, an extra 4 bytes are added
when calculating the row size to ensure that each hash table
contains 4 bytes of empty information.
Signed-off-by: Wenkai Lin <linwenkai6(a)hisilicon.com>
Signed-off-by: Zhushuai Yin <yinzhushuai(a)huawei.com>
---
drv/hisi_dae.c | 12 ++++++++----
drv/hisi_dae_join_gather.c | 7 +++++--
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index a6ee368..8fe6092 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -33,7 +33,6 @@
/* hash table */
#define HASH_TABLE_HEAD_TAIL_SIZE 8
-#define HASH_TABLE_EMPTY_SIZE 4
/* hash agg operations col max num */
#define DAE_AGG_COL_ALG_MAX_NUM 2
@@ -160,13 +159,18 @@ static void fill_hashagg_merge_output_order(struct dae_sqe *sqe, struct dae_ext_
{
struct hashagg_ctx *agg_ctx = msg->priv;
struct hashagg_col_data *cols_data = &agg_ctx->cols_data;
+ __u32 out_cols_num = cols_data->output_num;
struct hashagg_output_src *output_src;
__u32 offset = 0;
__u32 i;
- output_src = cols_data->rehash_output;
+ output_src = cols_data->normal_output;
+ if (cols_data->is_count_all) {
+ sqe->counta_vld = DAE_HASH_COUNT_ALL;
+ out_cols_num--;
+ }
- for (i = 0; i < cols_data->output_num; i++) {
+ for (i = 0; i < out_cols_num; i++) {
ext_sqe->out_from_in_idx |= (__u64)output_src[i].out_from_in_idx << offset;
ext_sqe->out_optype |= (__u64)output_src[i].out_optype << offset;
offset += DAE_COL_BIT_NUM;
@@ -370,7 +374,7 @@ static void fill_hashagg_merge_input_data(struct dae_sqe *sqe, struct dae_ext_sq
struct hashagg_ctx *agg_ctx = msg->priv;
struct hashagg_col_data *cols_data = &agg_ctx->cols_data;
- fill_hashagg_data_info(sqe, ext_sqe, cols_data->output_data, msg->agg_cols_num);
+ fill_hashagg_data_info(sqe, ext_sqe, cols_data->input_data, msg->agg_cols_num);
}
static void fill_hashagg_ext_addr(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
diff --git a/drv/hisi_dae_join_gather.c b/drv/hisi_dae_join_gather.c
index 92fae1a..8c45f57 100644
--- a/drv/hisi_dae_join_gather.c
+++ b/drv/hisi_dae_join_gather.c
@@ -19,7 +19,7 @@
#define PROBE_INDEX_ROW_SIZE 4
/* align size */
-#define DAE_KEY_ALIGN_SIZE 8
+#define DAE_KEY_ALIGN_SIZE 4
#define DAE_BREAKPOINT_SIZE 81920
#define DAE_ADDR_INDEX_SHIFT 1
@@ -28,7 +28,6 @@
#define HASH_TABLE_INDEX_NUM 1
#define HASH_TABLE_MAX_INDEX_NUM 15
#define HASH_TABLE_INDEX_SIZE 12
-#define HASH_TABLE_EMPTY_SIZE 4
#define GATHER_ROW_BATCH_EMPTY_SIZE 4
/* DAE hardware protocol data */
@@ -173,6 +172,9 @@ static void fill_join_table_data(struct dae_sqe *sqe, struct dae_addr_list *addr
}
sqe->table_row_size = ctx->hash_table_row_size;
+ /* Initialize these fields for hardware check*/
+ sqe->src_table_width = ctx->table_data.table_width;
+ sqe->dst_table_width = ctx->table_data.table_width;
if (table_data_src) {
sqe->src_table_width = table_data_src->table_width;
@@ -814,6 +816,7 @@ static int join_get_table_rowsize(struct join_gather_col_data *cols_data,
for (i = 0; i < key_num; i++)
row_count_size += get_data_type_size(key_data[i].hw_type, 0);
+ row_count_size += HASH_TABLE_EMPTY_SIZE;
row_count_size = ALIGN(row_count_size, DAE_KEY_ALIGN_SIZE);
row_count_size += HASH_TABLE_HEAD_TAIL_SIZE +
cols_data->index_num * HASH_TABLE_INDEX_SIZE;
--
2.33.0
1
4
06 Jan '26
From: Zhushuai Yin <yinzhushuai(a)huawei.com>
Due to changes in chip specifications, the hash agg 8B and 16B operations
have been reduced from 9 columns to 8 columns,requiring the driver to be
adapted accordingly.
Signed-off-by: Zhushuai Yin <yinzhushuai(a)huawei.com>
---
drv/hisi_dae.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index d7b34c2..a6ee368 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -673,7 +673,7 @@ static int agg_get_output_num(enum wd_dae_data_type type,
}
static int agg_output_num_check(struct wd_agg_col_info *agg_cols, __u32 cols_num,
- bool is_count_all, __u16 hw_type)
+ bool is_count_all)
{
__u32 size8 = 0, size16 = 0;
__u32 i, j, count_num;
@@ -691,8 +691,7 @@ static int agg_output_num_check(struct wd_agg_col_info *agg_cols, __u32 cols_num
if (is_count_all)
size8++;
- if (hw_type < HISI_QM_API_VER5_BASE &&
- (size8 > DAE_MAX_8B_COLS_NUM || size16 > DAE_MAX_16B_COLS_NUM)) {
+ if (size8 > DAE_MAX_8B_COLS_NUM || size16 > DAE_MAX_16B_COLS_NUM) {
WD_ERR("invalid: output col num 8B-16B %u-%u is more than support %d-%d !\n",
size8, size16, DAE_MAX_8B_COLS_NUM, DAE_MAX_16B_COLS_NUM);
return -WD_EINVAL;
@@ -708,7 +707,7 @@ static int agg_output_num_check(struct wd_agg_col_info *agg_cols, __u32 cols_num
return WD_SUCCESS;
}
-static int hashagg_init_param_check(struct wd_agg_sess_setup *setup, __u16 hw_type)
+static int hashagg_init_param_check(struct wd_agg_sess_setup *setup)
{
int ret;
@@ -735,7 +734,7 @@ static int hashagg_init_param_check(struct wd_agg_sess_setup *setup, __u16 hw_ty
return -WD_EINVAL;
return agg_output_num_check(setup->agg_cols_info, setup->agg_cols_num,
- setup->is_count_all, hw_type);
+ setup->is_count_all);
}
static int transfer_key_col_info(struct wd_key_col_info *key_cols,
@@ -1236,7 +1235,7 @@ static int hashagg_sess_priv_init(struct wd_alg_driver *drv,
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[0].ctx);
qp = (struct hisi_qp *)h_qp;
- ret = hashagg_init_param_check(setup, qp->q_info.hw_type);
+ ret = hashagg_init_param_check(setup);
if (ret)
return -WD_EINVAL;
--
2.33.0
1
0
06 Jan '26
From: Weili Qian <qianweili(a)huawei.com>
When looking up the corresponding driver by algorithm type,
since the driver does not save the algorithm type, it cannot
be directly obtained. Therefore, the algorithm type should be
saved during algorithm registration.
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
include/wd_alg.h | 2 ++
libwd.map | 1 +
wd_alg.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++
wd_util.c | 94 ++++--------------------------------------------
4 files changed, 102 insertions(+), 87 deletions(-)
diff --git a/include/wd_alg.h b/include/wd_alg.h
index 5ff73ca..848bdf1 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -145,6 +145,7 @@ struct wd_alg_list {
struct wd_alg_driver *drv;
struct wd_alg_list *next;
+ char alg_type[ALG_NAME_SIZE];
};
/*
@@ -178,6 +179,7 @@ int wd_alg_driver_init(struct wd_alg_driver *drv, void *conf);
void wd_alg_driver_exit(struct wd_alg_driver *drv);
int wd_alg_driver_send(struct wd_alg_driver *drv, handle_t ctx, void *msg);
int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg);
+int wd_get_alg_type(const char *alg_name, char *alg_type);
struct wd_alg_list *wd_get_alg_head(void);
diff --git a/libwd.map b/libwd.map
index 90eb5c5..5d732d0 100644
--- a/libwd.map
+++ b/libwd.map
@@ -53,6 +53,7 @@ global:
wd_alg_driver_exit;
wd_alg_driver_send;
wd_alg_driver_recv;
+ wd_get_alg_type;
wd_find_ctx;
wd_get_dev_id;
diff --git a/wd_alg.c b/wd_alg.c
index 9c7c0fd..919483b 100644
--- a/wd_alg.c
+++ b/wd_alg.c
@@ -24,6 +24,97 @@ static struct wd_alg_list *alg_list_tail = &alg_list_head;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+struct acc_alg_item {
+ const char *name;
+ const char *algtype;
+};
+
+static struct acc_alg_item alg_options[] = {
+ {"zlib", "zlib"},
+ {"gzip", "gzip"},
+ {"deflate", "deflate"},
+ {"lz77_zstd", "lz77_zstd"},
+ {"lz4", "lz4"},
+ {"lz77_only", "lz77_only"},
+ {"hashagg", "hashagg"},
+ {"udma", "udma"},
+ {"hashjoin", "hashjoin"},
+ {"gather", "gather"},
+ {"join-gather", "hashjoin"},
+
+ {"rsa", "rsa"},
+ {"dh", "dh"},
+ {"ecdh", "ecdh"},
+ {"x25519", "x25519"},
+ {"x448", "x448"},
+ {"ecdsa", "ecdsa"},
+ {"sm2", "sm2"},
+
+ {"ecb(aes)", "cipher"},
+ {"cbc(aes)", "cipher"},
+ {"xts(aes)", "cipher"},
+ {"ofb(aes)", "cipher"},
+ {"cfb(aes)", "cipher"},
+ {"ctr(aes)", "cipher"},
+ {"cbc-cs1(aes)", "cipher"},
+ {"cbc-cs2(aes)", "cipher"},
+ {"cbc-cs3(aes)", "cipher"},
+ {"ecb(sm4)", "cipher"},
+ {"xts(sm4)", "cipher"},
+ {"cbc(sm4)", "cipher"},
+ {"ofb(sm4)", "cipher"},
+ {"cfb(sm4)", "cipher"},
+ {"ctr(sm4)", "cipher"},
+ {"cbc-cs1(sm4)", "cipher"},
+ {"cbc-cs2(sm4)", "cipher"},
+ {"cbc-cs3(sm4)", "cipher"},
+ {"ecb(des)", "cipher"},
+ {"cbc(des)", "cipher"},
+ {"ecb(des3_ede)", "cipher"},
+ {"cbc(des3_ede)", "cipher"},
+
+ {"ccm(aes)", "aead"},
+ {"gcm(aes)", "aead"},
+ {"ccm(sm4)", "aead"},
+ {"gcm(sm4)", "aead"},
+ {"authenc(generic,cbc(aes))", "aead"},
+ {"authenc(generic,cbc(sm4))", "aead"},
+
+ {"sm3", "digest"},
+ {"md5", "digest"},
+ {"sha1", "digest"},
+ {"sha256", "digest"},
+ {"sha224", "digest"},
+ {"sha384", "digest"},
+ {"sha512", "digest"},
+ {"sha512-224", "digest"},
+ {"sha512-256", "digest"},
+ {"cmac(aes)", "digest"},
+ {"gmac(aes)", "digest"},
+ {"xcbc-mac-96(aes)", "digest"},
+ {"xcbc-prf-128(aes)", "digest"},
+ {"", ""}
+};
+
+int wd_get_alg_type(const char *alg_name, char *alg_type)
+{
+ __u64 i;
+
+ if (!alg_name || !alg_type) {
+ WD_ERR("invalid: alg_name or alg_type is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(alg_options); i++) {
+ if (strcmp(alg_name, alg_options[i].name) == 0) {
+ (void)strcpy(alg_type, alg_options[i].algtype);
+ return 0;
+ }
+ }
+
+ return -WD_EINVAL;
+}
+
static bool wd_check_accel_dev(const char *dev_name)
{
struct dirent *dev_dir;
@@ -182,6 +273,7 @@ int wd_alg_driver_register(struct wd_alg_driver *drv)
return -WD_ENOMEM;
}
+ (void)wd_get_alg_type(drv->alg_name, new_alg->alg_type);
strncpy(new_alg->alg_name, drv->alg_name, ALG_NAME_SIZE - 1);
strncpy(new_alg->drv_name, drv->drv_name, DEV_NAME_LEN - 1);
new_alg->priority = drv->priority;
diff --git a/wd_util.c b/wd_util.c
index 138a078..67a46a6 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -98,78 +98,6 @@ struct drv_lib_list {
struct drv_lib_list *next;
};
-struct acc_alg_item {
- const char *name;
- const char *algtype;
-};
-
-static struct acc_alg_item alg_options[] = {
- {"zlib", "zlib"},
- {"gzip", "gzip"},
- {"deflate", "deflate"},
- {"lz77_zstd", "lz77_zstd"},
- {"lz4", "lz4"},
- {"lz77_only", "lz77_only"},
- {"hashagg", "hashagg"},
- {"udma", "udma"},
- {"hashjoin", "hashjoin"},
- {"gather", "gather"},
- {"join-gather", "hashjoin"},
-
- {"rsa", "rsa"},
- {"dh", "dh"},
- {"ecdh", "ecdh"},
- {"x25519", "x25519"},
- {"x448", "x448"},
- {"ecdsa", "ecdsa"},
- {"sm2", "sm2"},
-
- {"ecb(aes)", "cipher"},
- {"cbc(aes)", "cipher"},
- {"xts(aes)", "cipher"},
- {"ofb(aes)", "cipher"},
- {"cfb(aes)", "cipher"},
- {"ctr(aes)", "cipher"},
- {"cbc-cs1(aes)", "cipher"},
- {"cbc-cs2(aes)", "cipher"},
- {"cbc-cs3(aes)", "cipher"},
- {"ecb(sm4)", "cipher"},
- {"xts(sm4)", "cipher"},
- {"cbc(sm4)", "cipher"},
- {"ofb(sm4)", "cipher"},
- {"cfb(sm4)", "cipher"},
- {"ctr(sm4)", "cipher"},
- {"cbc-cs1(sm4)", "cipher"},
- {"cbc-cs2(sm4)", "cipher"},
- {"cbc-cs3(sm4)", "cipher"},
- {"ecb(des)", "cipher"},
- {"cbc(des)", "cipher"},
- {"ecb(des3_ede)", "cipher"},
- {"cbc(des3_ede)", "cipher"},
-
- {"ccm(aes)", "aead"},
- {"gcm(aes)", "aead"},
- {"ccm(sm4)", "aead"},
- {"gcm(sm4)", "aead"},
- {"authenc(generic,cbc(aes))", "aead"},
- {"authenc(generic,cbc(sm4))", "aead"},
-
- {"sm3", "digest"},
- {"md5", "digest"},
- {"sha1", "digest"},
- {"sha256", "digest"},
- {"sha224", "digest"},
- {"sha384", "digest"},
- {"sha512", "digest"},
- {"sha512-224", "digest"},
- {"sha512-256", "digest"},
- {"cmac(aes)", "digest"},
- {"gmac(aes)", "digest"},
- {"xcbc-mac-96(aes)", "digest"},
- {"xcbc-prf-128(aes)", "digest"},
- {"", ""}
-};
-
static void *wd_internal_alloc(void *usr, size_t size)
{
if (size != 0)
@@ -2013,18 +1941,6 @@ int wd_init_param_check(struct wd_ctx_config *config, struct wd_sched *sched)
return 0;
}
-static void wd_get_alg_type(const char *alg_name, char *alg_type)
-{
- __u64 i;
-
- for (i = 0; i < ARRAY_SIZE(alg_options); i++) {
- if (strcmp(alg_name, alg_options[i].name) == 0) {
- (void)strcpy(alg_type, alg_options[i].algtype);
- break;
- }
- }
-}
-
static int wd_alg_init_fallback(struct wd_alg_driver *fb_driver)
{
if (!fb_driver->init) {
@@ -2175,7 +2091,7 @@ static int wd_env_set_ctx_nums(const char *alg_name, const char *name, const cha
char *left, *section, *start;
struct uacce_dev_list *list;
int is_comp;
- int ret = 0;
+ int ret;
/* COMP environment variable's format is different, mark it */
is_comp = strncmp(name, "WD_COMP_CTX_NUM", strlen(name)) ? 0 : 1;
@@ -2186,7 +2102,10 @@ static int wd_env_set_ctx_nums(const char *alg_name, const char *name, const cha
if (!start)
return -WD_ENOMEM;
- wd_get_alg_type(alg_name, alg_type);
+ ret = wd_get_alg_type(alg_name, alg_type);
+ if (ret)
+ return ret;
+
list = wd_get_accel_list(alg_type);
if (!list) {
WD_ERR("failed to get devices!\n");
@@ -3112,7 +3031,8 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs)
}
break;
case UADK_ALG_HW:
- wd_get_alg_type(alg, alg_type);
+ if (wd_get_alg_type(alg, alg_type))
+ return -WD_EINVAL;
(void)strcpy(attrs->alg, alg_type);
ctx_config = calloc(1, sizeof(*ctx_config));
--
2.33.0
1
4
您好!
sig-AccLib 邀请您参加 2025-12-24 11:00 召开的Zoom会议
会议主题:【2025/12/24 AccLIb SIG 双周例会 11:00 - 12:00】
会议链接:https://us06web.zoom.us/j/82679099901?pwd=rhb41PVIzL4V7ST8egX5bRqqq4Fag6.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-12-24 11:00,
The subject of the conference is 【2025/12/24 AccLIb SIG 双周例会 11:00 - 12:00】
You can join the meeting at https://us06web.zoom.us/j/82679099901?pwd=rhb41PVIzL4V7ST8egX5bRqqq4Fag6.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
18 Dec '25
From: parm64 <parm64(a)huawei.com>
Add support for multiple RSA padding modes with OpenSSL provider mechanism.
1. RSA_X931_PADDING and RSA_PKCS1_PSS_PADDING for signing and verification.
2. RSA_PKCS1_OAEP_PADDING and RSA_PKCS1_WITH_TLS_PADDING for encryption and
decryption.
Weili Qian (1):
uadk_provider/dh: set meth flags when new dh
Zhushuai Yin (2):
uadk_engine: fix the SM2 x25519 x448 err in OpenSSL3.0
uadk_provider: prov added compilation options
lizhi (8):
uadk_provider: split RSA algorithm into four functional components
uadk_provider: add some RSA utils functions to adapt RSA with several
padding modes
uadk_provider: adapt rsa signature operation with X931 and PKCS1_PSS
padding modes
uadk_provider: adapt rsa encryption operation with OAEP and
PKCS1_WITH_TLS padding modes
provider: optimize hardware version and availability queries using
global variables
uadk_provider: move several macro definitions to shared header file
uadk_engine: delete several unused functions
uadk_engine: fixup a bug in rsa X931 padding mode
src/Makefile.am | 9 +-
src/uadk_ecx.c | 152 +-
src/uadk_pkey.c | 2 +
src/uadk_pkey.h | 3 -
src/uadk_prov.h | 11 +-
src/uadk_prov_aead.c | 1 -
src/uadk_prov_cipher.c | 18 +-
src/uadk_prov_dh.c | 107 +-
src/uadk_prov_digest.c | 15 +-
src/uadk_prov_hmac.c | 122 +-
src/uadk_prov_init.c | 10 +-
src/uadk_prov_pkey.c | 13 +-
src/uadk_prov_pkey.h | 12 +-
src/uadk_prov_rsa.c | 2974 ++-----------------------------------
src/uadk_prov_rsa.h | 179 +++
src/uadk_prov_rsa_enc.c | 692 +++++++++
src/uadk_prov_rsa_kmgmt.c | 975 ++++++++++++
src/uadk_prov_rsa_sign.c | 1676 +++++++++++++++++++++
src/uadk_prov_rsa_utils.c | 138 ++
src/uadk_rsa.c | 4 +-
20 files changed, 4156 insertions(+), 2957 deletions(-)
create mode 100644 src/uadk_prov_rsa.h
create mode 100644 src/uadk_prov_rsa_enc.c
create mode 100644 src/uadk_prov_rsa_kmgmt.c
create mode 100644 src/uadk_prov_rsa_sign.c
create mode 100644 src/uadk_prov_rsa_utils.c
--
2.43.0
1
11
16 Dec '25
From: parm64 <parm64(a)huawei.com>
Add support for multiple RSA padding modes with OpenSSL provider mechanism.
1. RSA_X931_PADDING and RSA_PKCS1_PSS_PADDING for signing and verification.
2. RSA_PKCS1_OAEP_PADDING and RSA_PKCS1_WITH_TLS_PADDING for encryption and
decryption.
Weili Qian (1):
uadk_provider/dh: set meth flags when new dh
Zhushuai Yin (2):
uadk_engine: fix the SM2 x25519 x448 err in OpenSSL3.0
uadk_provider: prov added compilation options
lizhi (8):
uadk_provider: split RSA algorithm into four functional components
uadk_provider: add some RSA utils functions to adapt RSA with several
padding modes
uadk_provider: adapt rsa signature operation with X931 and PKCS1_PSS
padding modes
uadk_provider: adapt rsa encryption operation with OAEP and
PKCS1_WITH_TLS padding modes
provider: optimize hardware version and availability queries using
global variables
uadk_provider: move several macro definitions to shared header file
uadk_engine: delete several unused functions
uadk_engine: fixup a bug in rsa X931 padding mode
src/Makefile.am | 9 +-
src/uadk_ecx.c | 152 +-
src/uadk_pkey.c | 2 +
src/uadk_pkey.h | 3 -
src/uadk_prov.h | 11 +-
src/uadk_prov_aead.c | 1 -
src/uadk_prov_cipher.c | 18 +-
src/uadk_prov_dh.c | 107 +-
src/uadk_prov_digest.c | 15 +-
src/uadk_prov_hmac.c | 122 +-
src/uadk_prov_init.c | 10 +-
src/uadk_prov_pkey.c | 13 +-
src/uadk_prov_pkey.h | 12 +-
src/uadk_prov_rsa.c | 2974 ++-----------------------------------
src/uadk_prov_rsa.h | 179 +++
src/uadk_prov_rsa_enc.c | 692 +++++++++
src/uadk_prov_rsa_kmgmt.c | 975 ++++++++++++
src/uadk_prov_rsa_sign.c | 1676 +++++++++++++++++++++
src/uadk_prov_rsa_utils.c | 138 ++
src/uadk_rsa.c | 4 +-
20 files changed, 4156 insertions(+), 2957 deletions(-)
create mode 100644 src/uadk_prov_rsa.h
create mode 100644 src/uadk_prov_rsa_enc.c
create mode 100644 src/uadk_prov_rsa_kmgmt.c
create mode 100644 src/uadk_prov_rsa_sign.c
create mode 100644 src/uadk_prov_rsa_utils.c
--
2.43.0
1
11
From: Zhushuai Yin <yinzhushuai(a)huawei.com>
When the input is 0, the hardware will also access the
src address. In this case, src is NULL, which will cause
the hardware to report an error.
Signed-off-by: Zhushuai Yin <yinzhushuai(a)huawei.com>
---
drv/hisi_sec.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 1e95ce5..d19afe2 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -1751,7 +1751,11 @@ static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *w
sqe.sds_sa_type |= (__u8)(de | scene);
sqe.type2.alen_ivllen |= (__u32)msg->in_bytes;
- sqe.type2.data_src_addr = (__u64)(uintptr_t)msg->in;
+ /* avoid HW accessing address 0 when the pointer is NULL */
+ if (msg->in)
+ sqe.type2.data_src_addr = (__u64)(uintptr_t)msg->in;
+ else
+ sqe.type2.data_src_addr = (__u64)(uintptr_t)msg->out;
sqe.type2.mac_addr = (__u64)(uintptr_t)msg->out;
ret = fill_digest_bd2_alg(msg, &sqe);
@@ -1987,7 +1991,11 @@ static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void
}
sqe.a_len_key = (__u32)msg->in_bytes;
- sqe.data_src_addr = (__u64)(uintptr_t)msg->in;
+ /* avoid HW accessing address 0 when the pointer is NULL */
+ if (msg->in)
+ sqe.data_src_addr = (__u64)(uintptr_t)msg->in;
+ else
+ sqe.data_src_addr = (__u64)(uintptr_t)msg->out;
sqe.mac_addr = (__u64)(uintptr_t)msg->out;
ret = fill_digest_bd3_alg(msg, &sqe);
--
2.43.0
1
0
From: Zongyu Wu <wuzongyu1(a)huawei.com>
Fix compilation warning in the UADK module regarding an unused variable.
Signed-off-by: Zongyu Wu <wuzongyu1(a)huawei.com>
---
v1/test/hisi_zip_test_sgl/wd_sched_sgl.c | 8 ++---
v1/test/test_mm/test_wd_mem.c | 4 +--
v1/test/wd_sched.c | 1 -
wd_util.c | 42 ++++++++++++++++--------
4 files changed, 33 insertions(+), 22 deletions(-)
diff --git a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
index 7a3be22..21ec30c 100644
--- a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
+++ b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
@@ -27,7 +27,6 @@ static int wd_sched_pre_uninit(struct wd_scheduler *sched, int data_fmt)
{
unsigned int flags = 0;
struct q_info *qinfo;
- void *pool;
int i;
qinfo = sched->qs[0].qinfo;
@@ -54,12 +53,13 @@ static int wd_sched_pre_uninit(struct wd_scheduler *sched, int data_fmt)
static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
{
- int ret, i, j;
unsigned int flags = 0;
struct q_info *qinfo;
struct wd_blkpool_setup mm_setup;
struct wd_sglpool_setup sp;
void *pool;
+ int ret, j;
+ int i = 0;
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
@@ -260,9 +260,7 @@ err_with_msgs:
int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
{
- int ret, j, k;
- unsigned int flags;
- struct q_info *qinfo;
+ int ret;
ret = wd_sched_preinit(sched, data_fmt);
if (ret < 0)
diff --git a/v1/test/test_mm/test_wd_mem.c b/v1/test/test_mm/test_wd_mem.c
index e2eec60..a1f55db 100644
--- a/v1/test/test_mm/test_wd_mem.c
+++ b/v1/test/test_mm/test_wd_mem.c
@@ -208,7 +208,7 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_request_queue(&pdata->qinfo1.q);
+ ret = wd_request_queue(pdata->qinfo1.q);
if (ret) {
wd_release_queue(&rsa_q);
MMT_PRT("Proc-%d, thrd-%d:rsa queue fail!\n",
@@ -226,7 +226,7 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_request_queue(&pdata->qinfo2.q);
+ ret = wd_request_queue(pdata->qinfo2.q);
if (ret) {
MMT_PRT("Proc-%d, thrd-%d:zlib queue fail!\n",
pid, thread_id);
diff --git a/v1/test/wd_sched.c b/v1/test/wd_sched.c
index ce1d260..54f400a 100644
--- a/v1/test/wd_sched.c
+++ b/v1/test/wd_sched.c
@@ -26,7 +26,6 @@ static int wd_sched_pre_uninit(struct wd_scheduler *sched)
{
unsigned int flags = 0;
struct q_info *qinfo;
- void *pool;
int i;
qinfo = sched->qs[0].qinfo;
diff --git a/wd_util.c b/wd_util.c
index daa7309..138a078 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -2459,19 +2459,22 @@ static struct drv_lib_list *load_libraries_from_config(const char *config_path,
FILE *config_file;
int ret;
- path_buf = calloc(WD_PATH_DIR_NUM, PATH_MAX);
- if (!path_buf) {
- WD_ERR("fail to alloc memery for path_buf.\n");
- return NULL;
+ lib_path = calloc(1, PATH_MAX);
+ if (!lib_path) {
+ WD_ERR("Failed to alloc memery for lib_path.\n");
+ return head;
+ }
+
+ line = calloc(1, PATH_MAX);
+ if (!line) {
+ WD_ERR("Failed to alloc memery for lib_line.\n");
+ goto free_path;
}
- lib_path = path_buf;
- line = path_buf + PATH_MAX;
config_file = fopen(config_path, "r");
if (!config_file) {
WD_ERR("Failed to open config file: %s\n", config_path);
- free(path_buf);
- return NULL;
+ goto free_line;
}
/* Read config file line by line */
@@ -2486,8 +2489,12 @@ static struct drv_lib_list *load_libraries_from_config(const char *config_path,
create_lib_to_list(lib_path, &head);
}
- free(path_buf);
fclose(config_file);
+
+free_line:
+ free(line);
+free_path:
+ free(lib_path);
return head;
}
@@ -2533,15 +2540,21 @@ void *wd_dlopen_drv(const char *cust_lib_dir)
int ret, len;
DIR *wd_dir;
- path_buf = calloc(WD_PATH_DIR_NUM + 1, PATH_MAX);
+ path_buf = calloc(WD_PATH_DIR_NUM, PATH_MAX);
if (!path_buf) {
- WD_ERR("fail to alloc memory for path buffers.\n");
- return NULL;
+ WD_ERR("Failed to alloc memory for path_buf buffers.\n");
+ return head;
+ }
+
+ config_path = calloc(1, PATH_MAX);
+ if (!config_path) {
+ WD_ERR("Failed to alloc memory for config_path buffers.\n");
+ free(path_buf);
+ return head;
}
lib_dir_path = path_buf;
- config_path = path_buf + PATH_MAX;
- lib_path = config_path + PATH_MAX;
+ lib_path = path_buf + PATH_MAX;
if (!cust_lib_dir) {
ret = wd_get_lib_file_path(NULL, lib_dir_path, true);
@@ -2582,6 +2595,7 @@ close_dir:
closedir(wd_dir);
free_path:
free(path_buf);
+ free(config_path);
return (void *)head;
}
--
2.33.0
1
0
您好!
sig-AccLib 邀请您参加 2025-12-10 11:00 召开的Zoom会议
会议主题:【2025/12/10 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/89936554365?pwd=rGBVuuAFuM1aWG32BRhNs0fk2bya0a.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-12-10 11:00,
The subject of the conference is 【2025/12/10 AccLIb SIG 双周例会 11:00 - 12:00】
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/89936554365?pwd=rGBVuuAFuM1aWG32BRhNs0fk2bya0a.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
From: Weili Qian <qianweili(a)huawei.com>
UADK adds the ability to obtain device usage. When the device
is not bound to a driver, it retrieves the usage through sysfs
files. When the device is bound to a driver, it directly reads the
hardware registers to obtain the usage.
Upstream: Yes
AR: AR20230722287656
Feature or Bugfix: Feature
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
drv/hisi_comp.c | 39 +++++++++
drv/hisi_dae.c | 5 --
drv/hisi_dae.h | 1 +
drv/hisi_dae_common.c | 38 +++++++++
drv/hisi_dae_join_gather.c | 1 +
drv/hisi_hpre.c | 69 ++++++++++++++--
drv/hisi_qm_udrv.c | 36 +++++++++
drv/hisi_qm_udrv.h | 1 +
drv/hisi_sec.c | 35 +++++++-
drv/hisi_udma.c | 35 +++++++-
include/wd.h | 8 ++
include/wd_alg.h | 9 +++
libwd.map | 3 +
wd.c | 162 +++++++++++++++++++++++++++++++++++++
wd_alg.c | 124 ++++++++++++++++++++++++++++
wd_util.c | 93 ++-------------------
16 files changed, 560 insertions(+), 99 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index 65dcf8e..cad21fa 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -1755,6 +1755,44 @@ static int hisi_zip_comp_recv(struct wd_alg_driver *drv, handle_t ctx, void *com
return 0;
}
+static int hisi_zip_get_usage(void *param)
+{
+ struct hisi_dev_usage *zip_usage = (struct hisi_dev_usage *)param;
+ struct wd_alg_driver *drv = zip_usage->drv;
+ struct wd_ctx_config_internal *config;
+ struct hisi_zip_ctx *priv;
+ char *ctx_dev_name;
+ handle_t ctx = 0;
+ handle_t qp = 0;
+ __u32 i;
+
+ if (zip_usage->alg_op_type >= drv->op_type_num) {
+ WD_ERR("invalid: alg_op_type %u is error!\n", zip_usage->alg_op_type);
+ return -WD_EINVAL;
+ }
+
+ priv = (struct hisi_zip_ctx *)drv->priv;
+ if (!priv)
+ return -WD_EACCES;
+
+ config = &priv->config;
+ for (i = 0; i < config->ctx_num; i++) {
+ ctx_dev_name = wd_ctx_get_dev_name(config->ctxs[i].ctx);
+ if (!strcmp(zip_usage->dev_name, ctx_dev_name)) {
+ ctx = config->ctxs[i].ctx;
+ break;
+ }
+ }
+
+ if (ctx)
+ qp = (handle_t)wd_ctx_get_priv(ctx);
+
+ if (qp)
+ return hisi_qm_get_usage(qp, zip_usage->alg_op_type);
+
+ return -WD_EACCES;
+}
+
#define GEN_ZIP_ALG_DRIVER(zip_alg_name) \
{\
.drv_name = "hisi_zip",\
@@ -1768,6 +1806,7 @@ static int hisi_zip_comp_recv(struct wd_alg_driver *drv, handle_t ctx, void *com
.exit = hisi_zip_exit,\
.send = hisi_zip_comp_send,\
.recv = hisi_zip_comp_recv,\
+ .get_usage = hisi_zip_get_usage, \
}
static struct wd_alg_driver zip_alg_driver[] = {
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index 49387aa..d7b34c2 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -1283,11 +1283,6 @@ static int agg_hash_table_init(struct wd_alg_driver *drv,
hash_table, agg_ctx->row_size);
}
-static int dae_get_usage(void *param)
-{
- return 0;
-}
-
static int dae_get_extend_ops(void *ops)
{
struct wd_agg_ops *agg_ops = (struct wd_agg_ops *)ops;
diff --git a/drv/hisi_dae.h b/drv/hisi_dae.h
index 050b872..f82b13c 100644
--- a/drv/hisi_dae.h
+++ b/drv/hisi_dae.h
@@ -220,6 +220,7 @@ int get_free_ext_addr(struct dae_extend_addr *ext_addr);
void put_ext_addr(struct dae_extend_addr *ext_addr, int idx);
__u32 get_data_type_size(enum dae_data_type type, __u16 data_info);
int dae_decimal_precision_check(__u16 data_info, bool longdecimal);
+int dae_get_usage(void *param);
#ifdef __cplusplus
}
diff --git a/drv/hisi_dae_common.c b/drv/hisi_dae_common.c
index 5cfc105..c077d1d 100644
--- a/drv/hisi_dae_common.c
+++ b/drv/hisi_dae_common.c
@@ -389,3 +389,41 @@ void dae_exit(struct wd_alg_driver *drv)
free(priv);
drv->priv = NULL;
}
+
+int dae_get_usage(void *param)
+{
+ struct hisi_dev_usage *dae_usage = (struct hisi_dev_usage *)param;
+ struct wd_alg_driver *drv = dae_usage->drv;
+ struct wd_ctx_config_internal *config;
+ struct hisi_dae_ctx *priv;
+ char *ctx_dev_name;
+ handle_t ctx = 0;
+ handle_t qp = 0;
+ __u32 i;
+
+ if (dae_usage->alg_op_type >= drv->op_type_num) {
+ WD_ERR("invalid: alg_op_type %u is error!\n", dae_usage->alg_op_type);
+ return -WD_EINVAL;
+ }
+
+ priv = (struct hisi_dae_ctx *)drv->priv;
+ if (!priv)
+ return -WD_EACCES;
+
+ config = &priv->config;
+ for (i = 0; i < config->ctx_num; i++) {
+ ctx_dev_name = wd_ctx_get_dev_name(config->ctxs[i].ctx);
+ if (!strcmp(dae_usage->dev_name, ctx_dev_name)) {
+ ctx = config->ctxs[i].ctx;
+ break;
+ }
+ }
+
+ if (ctx)
+ qp = (handle_t)wd_ctx_get_priv(ctx);
+
+ if (qp)
+ return hisi_qm_get_usage(qp, DAE_SQC_ALG_TYPE);
+
+ return -WD_EACCES;
+}
diff --git a/drv/hisi_dae_join_gather.c b/drv/hisi_dae_join_gather.c
index 63c7670..92fae1a 100644
--- a/drv/hisi_dae_join_gather.c
+++ b/drv/hisi_dae_join_gather.c
@@ -1007,6 +1007,7 @@ static int join_gather_get_extend_ops(void *ops)
.send = join_gather_send,\
.recv = join_gather_recv,\
.get_extend_ops = join_gather_get_extend_ops,\
+ .get_usage = dae_get_usage,\
}
static struct wd_alg_driver join_gather_driver[] = {
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index f3f2451..3c41826 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -2777,9 +2777,68 @@ static int ecc_recv(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
return ecc_sqe_parse((struct hisi_qp *)h_qp, msg, &hw_msg);
}
-static int hpre_get_usage(void *param)
+static handle_t hpre_find_dev_qp(struct wd_alg_driver *drv, const char *dev_name)
{
- return WD_SUCCESS;
+ struct wd_ctx_config_internal *config;
+ struct hisi_hpre_ctx *priv;
+ char *ctx_dev_name;
+ handle_t ctx = 0;
+ handle_t qp = 0;
+ __u32 i;
+
+ priv = (struct hisi_hpre_ctx *)drv->priv;
+ if (!priv)
+ return 0;
+
+ config = &priv->config;
+ for (i = 0; i < config->ctx_num; i++) {
+ ctx_dev_name = wd_ctx_get_dev_name(config->ctxs[i].ctx);
+ if (!strcmp(ctx_dev_name, dev_name)) {
+ ctx = config->ctxs[i].ctx;
+ break;
+ }
+ }
+
+ if (ctx)
+ qp = (handle_t)wd_ctx_get_priv(ctx);
+
+ return qp;
+}
+
+static int hpre_ecc_get_usage(void *param)
+{
+ struct hisi_dev_usage *hpre_usage = (struct hisi_dev_usage *)param;
+ struct wd_alg_driver *drv = hpre_usage->drv;
+ handle_t qp;
+
+ if (hpre_usage->alg_op_type >= drv->op_type_num) {
+ WD_ERR("invalid: alg_op_type %u is error!\n", hpre_usage->alg_op_type);
+ return -WD_EINVAL;
+ }
+
+ qp = hpre_find_dev_qp(drv, hpre_usage->dev_name);
+ if (qp)
+ return hisi_qm_get_usage(qp, HPRE_HW_V3_ECC_ALG_TYPE);
+
+ return -WD_EACCES;
+}
+
+static int hpre_rsa_get_usage(void *param)
+{
+ struct hisi_dev_usage *hpre_usage = (struct hisi_dev_usage *)param;
+ struct wd_alg_driver *drv = hpre_usage->drv;
+ handle_t qp;
+
+ if (hpre_usage->alg_op_type >= drv->op_type_num) {
+ WD_ERR("invalid: alg_op_type %u is error!\n", hpre_usage->alg_op_type);
+ return -WD_EINVAL;
+ }
+
+ qp = hpre_find_dev_qp(drv, hpre_usage->dev_name);
+ if (qp)
+ return hisi_qm_get_usage(qp, HPRE_HW_V2_ALG_TYPE);
+
+ return -WD_EACCES;
}
static int ecc_sess_eops_init(struct wd_alg_driver *drv, void **params)
@@ -2886,7 +2945,7 @@ static int hpre_ecc_get_extend_ops(void *ops)
.exit = hpre_exit,\
.send = ecc_send,\
.recv = ecc_recv,\
- .get_usage = hpre_get_usage,\
+ .get_usage = hpre_ecc_get_usage,\
.get_extend_ops = hpre_ecc_get_extend_ops,\
}
@@ -2910,7 +2969,7 @@ static struct wd_alg_driver hpre_rsa_driver = {
.exit = hpre_exit,
.send = rsa_send,
.recv = rsa_recv,
- .get_usage = hpre_get_usage,
+ .get_usage = hpre_rsa_get_usage,
};
static struct wd_alg_driver hpre_dh_driver = {
@@ -2925,7 +2984,7 @@ static struct wd_alg_driver hpre_dh_driver = {
.exit = hpre_exit,
.send = dh_send,
.recv = dh_recv,
- .get_usage = hpre_get_usage,
+ .get_usage = hpre_rsa_get_usage,
};
#ifdef WD_STATIC_DRV
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 216b80a..4ddf8a8 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -42,6 +42,12 @@
#define ADDR_ALIGN_64(addr) ((((uintptr_t)(addr) >> 6) + 1) << 6)
+#define QM_TYPE_USAGE_OFFSET 0x1100
+#define QM_DEV_USAGE_OFFSET 16
+#define QM_CHANNEL_ADDR_INTRVL 0x4
+#define QM_MAX_DEV_USAGE 100
+#define QM_DEV_USAGE_RATE 100
+
struct hisi_qm_type {
__u16 qm_ver;
int qm_db_offs;
@@ -154,6 +160,36 @@ static struct hisi_qm_type qm_type[] = {
}
};
+int hisi_qm_get_usage(handle_t h_qp, __u8 type)
+{
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ struct hisi_qm_queue_info *q_info;
+ __u16 count, usage;
+ __u32 val;
+
+ if (!qp)
+ return -WD_EINVAL;
+
+ q_info = &qp->q_info;
+ if (q_info->hw_type < HISI_QM_API_VER5_BASE) {
+ WD_ERR("invalid: device not support get usage!\n");
+ return -WD_EINVAL;
+ }
+
+ val = wd_ioread32(q_info->mmio_base + QM_TYPE_USAGE_OFFSET +
+ type * QM_CHANNEL_ADDR_INTRVL);
+ count = val >> QM_DEV_USAGE_OFFSET;
+ if (!count) {
+ WD_ERR("failed to get dev count usage!\n");
+ return -WD_EINVAL;
+ }
+
+ usage = (__u16)val * QM_DEV_USAGE_RATE / count;
+ usage = usage > QM_MAX_DEV_USAGE ? QM_MAX_DEV_USAGE : usage;
+
+ return usage;
+}
+
static void hisi_qm_fill_sqe(const void *sqe, struct hisi_qm_queue_info *info,
__u16 tail, __u16 num)
{
diff --git a/drv/hisi_qm_udrv.h b/drv/hisi_qm_udrv.h
index f066881..a7222ce 100644
--- a/drv/hisi_qm_udrv.h
+++ b/drv/hisi_qm_udrv.h
@@ -210,6 +210,7 @@ int hisi_qm_get_free_sqe_num(handle_t h_qp);
*/
__u32 hisi_qm_get_list_size(struct wd_datalist *start_node,
struct wd_datalist *end_node);
+int hisi_qm_get_usage(handle_t h_qp, __u8 type);
#ifdef __cplusplus
}
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index e64fd5c..53bf334 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -600,7 +600,40 @@ static int aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
static int hisi_sec_get_usage(void *param)
{
- return 0;
+ struct hisi_dev_usage *sec_usage = (struct hisi_dev_usage *)param;
+ struct wd_alg_driver *drv = sec_usage->drv;
+ struct wd_ctx_config_internal *config;
+ struct hisi_sec_ctx *priv;
+ char *ctx_dev_name;
+ handle_t ctx = 0;
+ handle_t qp = 0;
+ __u32 i;
+
+ if (sec_usage->alg_op_type >= drv->op_type_num) {
+ WD_ERR("invalid: alg_op_type %u is error!\n", sec_usage->alg_op_type);
+ return -WD_EINVAL;
+ }
+
+ priv = (struct hisi_sec_ctx *)drv->priv;
+ if (!priv)
+ return -WD_EACCES;
+
+ config = &priv->config;
+ for (i = 0; i < config->ctx_num; i++) {
+ ctx_dev_name = wd_ctx_get_dev_name(config->ctxs[i].ctx);
+ if (!strcmp(sec_usage->dev_name, ctx_dev_name)) {
+ ctx = config->ctxs[i].ctx;
+ break;
+ }
+ }
+
+ if (ctx)
+ qp = (handle_t)wd_ctx_get_priv(ctx);
+
+ if (qp)
+ return hisi_qm_get_usage(qp, 0);
+
+ return -WD_EACCES;
}
static int eops_param_check(struct wd_alg_driver *drv, struct wd_mm_ops *mm_ops)
diff --git a/drv/hisi_udma.c b/drv/hisi_udma.c
index 37f0550..a9f5607 100644
--- a/drv/hisi_udma.c
+++ b/drv/hisi_udma.c
@@ -521,7 +521,40 @@ static void udma_exit(struct wd_alg_driver *drv)
static int udma_get_usage(void *param)
{
- return 0;
+ struct hisi_dev_usage *udma_usage = (struct hisi_dev_usage *)param;
+ struct wd_alg_driver *drv = udma_usage->drv;
+ struct wd_ctx_config_internal *config;
+ struct hisi_udma_ctx *priv;
+ char *ctx_dev_name;
+ handle_t ctx = 0;
+ handle_t qp = 0;
+ __u32 i;
+
+ if (udma_usage->alg_op_type >= drv->op_type_num) {
+ WD_ERR("invalid: alg_op_type %u is error!\n", udma_usage->alg_op_type);
+ return -WD_EINVAL;
+ }
+
+ priv = (struct hisi_udma_ctx *)drv->priv;
+ if (!priv)
+ return -WD_EACCES;
+
+ config = &priv->config;
+ for (i = 0; i < config->ctx_num; i++) {
+ ctx_dev_name = wd_ctx_get_dev_name(config->ctxs[i].ctx);
+ if (!strcmp(udma_usage->dev_name, ctx_dev_name)) {
+ ctx = config->ctxs[i].ctx;
+ break;
+ }
+ }
+
+ if (ctx)
+ qp = (handle_t)wd_ctx_get_priv(ctx);
+
+ if (qp)
+ return hisi_qm_get_usage(qp, UDMA_ALG_TYPE);
+
+ return -WD_EACCES;
}
static struct wd_alg_driver udma_driver = {
diff --git a/include/wd.h b/include/wd.h
index b97e5c7..abc745d 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -627,6 +627,14 @@ struct wd_capability {
struct wd_capability *wd_get_alg_cap(void);
void wd_release_alg_cap(struct wd_capability *head);
+/**
+ * wd_get_dev_usage() - Get the device bandwidth usage.
+ * @dev: Indicate device.
+ * @alg_name: Indicates the intention to query the bandwidth usage of the algorithm on the device.
+ * @alg_op_type: algorithm type.
+ */
+int wd_get_dev_usage(struct uacce_dev *dev, const char *alg_name, __u8 alg_op_type);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/wd_alg.h b/include/wd_alg.h
index 5ff73ca..878c595 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -115,6 +115,12 @@ struct wd_alg_driver {
int (*get_extend_ops)(void *ops);
};
+struct hisi_dev_usage {
+ struct wd_alg_driver *drv;
+ char *dev_name;
+ __u8 alg_op_type;
+};
+
/*
* wd_alg_driver_register() - Register a device driver.
* @wd_alg_driver: a device driver that supports an algorithm.
@@ -145,6 +151,7 @@ struct wd_alg_list {
struct wd_alg_driver *drv;
struct wd_alg_list *next;
+ char alg_type[ALG_NAME_SIZE];
};
/*
@@ -178,6 +185,8 @@ int wd_alg_driver_init(struct wd_alg_driver *drv, void *conf);
void wd_alg_driver_exit(struct wd_alg_driver *drv);
int wd_alg_driver_send(struct wd_alg_driver *drv, handle_t ctx, void *msg);
int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg);
+int wd_alg_get_dev_usage(const char *dev_name, const char *alg_type, __u8 op_type);
+int wd_get_alg_type(const char *alg_name, char *alg_type);
struct wd_alg_list *wd_get_alg_head(void);
diff --git a/libwd.map b/libwd.map
index 90eb5c5..1267a8d 100644
--- a/libwd.map
+++ b/libwd.map
@@ -22,6 +22,7 @@ global:
wd_ctx_set_io_cmd;
wd_ctx_get_region_size;
wd_ctx_get_dev_name;
+ wd_get_dev_usage;
wd_block_alloc;
wd_block_free;
@@ -53,6 +54,8 @@ global:
wd_alg_driver_exit;
wd_alg_driver_send;
wd_alg_driver_recv;
+ wd_alg_get_dev_usage;
+ wd_get_alg_type;
wd_find_ctx;
wd_get_dev_id;
diff --git a/wd.c b/wd.c
index 657fbae..7f26f84 100644
--- a/wd.c
+++ b/wd.c
@@ -23,6 +23,7 @@
#include "wd_internal.h"
#define SYS_CLASS_DIR "/sys/class/uacce"
#define FILE_MAX_SIZE (8 << 20)
+#define WD_DEV_USAGE_SIZE 256
enum UADK_LOG_LEVEL {
WD_LOG_NONE = 0,
@@ -34,6 +35,27 @@ enum UADK_LOG_LEVEL {
static int uadk_log_level = WD_LOG_INVALID;
+struct dev_usage_info {
+ char *dev_name;
+ __u8 alg_op_type;
+ int (*usage_parse_fn)(char *buf, const char *alg_name, __u8 alg_op_type);
+};
+
+static const char * const hpre_ecc_algs[] = {
+ "sm2",
+ "ecdh",
+ "x448",
+ "x25519",
+ "ecdsa"
+};
+
+static const char * const zip_dae_algs[] = {
+ "udma",
+ "hashagg",
+ "hashjoin",
+ "gather",
+};
+
static int wd_check_ctx_type(handle_t h_ctx)
{
struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
@@ -986,3 +1008,143 @@ alloc_err:
return NULL;
}
+static int wd_parse_usage_value(char *buf, const char *type_name)
+{
+ char *str;
+ int ret;
+
+ str = strstr(buf, type_name);
+ if (!str)
+ return -WD_EINVAL;
+
+ str += strlen(type_name);
+ ret = strtol(str, NULL, 10);
+ if (ret < 0)
+ WD_ERR("fail to get device usage value, ret %d!\n", ret);
+
+ return ret;
+}
+
+/*
+ * The format of the string obtained from sysfs is fixed
+ * and does not need to consider other scenarios.
+ */
+static int wd_zip_usage_parse_fn(char *buf, const char *alg_name, __u8 alg_op_type)
+{
+ size_t size = ARRAY_SIZE(zip_dae_algs);
+ size_t i;
+
+ for (i = 0; i < size; i++) {
+ if (!strcmp(alg_name, zip_dae_algs[i])) {
+ if (alg_op_type != 0) {
+ WD_ERR("invalid: alg_name %s alg_op_type error!\n", alg_name);
+ return -WD_EINVAL;
+ }
+ return wd_parse_usage_value(buf, "DAE: ");
+ }
+ }
+
+ if (alg_op_type == 0)
+ return wd_parse_usage_value(buf, "COMPRESS: ");
+
+ return wd_parse_usage_value(buf, "DECOMPRESS: ");
+}
+
+static int wd_sec_usage_parse_fn(char *buf, const char *alg_name, __u8 alg_op_type)
+{
+ return wd_parse_usage_value(buf, "SEC: ");
+}
+
+static int wd_hpre_usage_parse_fn(char *buf, const char *alg_name, __u8 alg_op_type)
+{
+ size_t size = ARRAY_SIZE(hpre_ecc_algs);
+ size_t i;
+
+ for (i = 0; i < size; i++) {
+ if (!strcmp(alg_name, hpre_ecc_algs[i]))
+ return wd_parse_usage_value(buf, "ECC: ");
+ }
+
+ return wd_parse_usage_value(buf, "RSA: ");
+}
+
+static const struct dev_usage_info dev_usage_parse[] = {
+ {
+ .dev_name = "hisi_zip",
+ .alg_op_type = 2,
+ .usage_parse_fn = wd_zip_usage_parse_fn
+ }, {
+ .dev_name = "hisi_sec",
+ .alg_op_type = 1,
+ .usage_parse_fn = wd_sec_usage_parse_fn
+ }, {
+ .dev_name = "hisi_hpre",
+ .alg_op_type = 1,
+ .usage_parse_fn = wd_hpre_usage_parse_fn
+ },
+};
+
+static int wd_parse_dev_usage(struct uacce_dev *dev, char *buf,
+ const char *alg_name, __u8 alg_op_type)
+{
+ size_t size = ARRAY_SIZE(dev_usage_parse);
+ size_t i;
+
+ for (i = 0; i < size; i++) {
+ if (strstr(dev->dev_root, dev_usage_parse[i].dev_name))
+ break;
+ }
+
+ if (i == size) {
+ WD_ERR("failed to find parse function!\n");
+ return -WD_EINVAL;
+ }
+
+ if (alg_op_type >= dev_usage_parse[i].alg_op_type) {
+ WD_ERR("invalid: alg_op_type %u is error!\n", alg_op_type);
+ return -WD_EINVAL;
+ }
+
+ return dev_usage_parse[i].usage_parse_fn(buf, alg_name, alg_op_type);
+}
+
+static int wd_read_dev_usage(struct uacce_dev *dev, const char *alg_name, __u8 alg_op_type)
+{
+ char buf[WD_DEV_USAGE_SIZE];
+ int ret;
+
+ ret = access_attr(dev->dev_root, "dev_usage", F_OK);
+ if (ret) {
+ WD_ERR("failed to access dev_usage!\n");
+ return ret;
+ }
+
+ ret = get_str_attr(dev, "dev_usage", buf, WD_DEV_USAGE_SIZE);
+ if (ret < 0)
+ return ret;
+
+ return wd_parse_dev_usage(dev, buf, alg_name, alg_op_type);
+}
+
+int wd_get_dev_usage(struct uacce_dev *dev, const char *alg_name, __u8 alg_op_type)
+{
+ char *dev_name;
+ int ret;
+
+ if (!dev || !alg_name) {
+ WD_ERR("invalid: dev or alg name is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ if (!dev_has_alg(dev->algs, alg_name)) {
+ WD_ERR("invalid: dev does not support alg %s!\n", alg_name);
+ return -WD_EINVAL;
+ }
+
+ dev_name = wd_get_accel_name(dev->char_dev_path, 0);
+ ret = wd_alg_get_dev_usage(dev_name, alg_name, alg_op_type);
+ if (ret == -WD_EACCES)
+ return wd_read_dev_usage(dev, alg_name, alg_op_type);
+
+ return ret;
+}
diff --git a/wd_alg.c b/wd_alg.c
index 9c7c0fd..c819d32 100644
--- a/wd_alg.c
+++ b/wd_alg.c
@@ -24,6 +24,97 @@ static struct wd_alg_list *alg_list_tail = &alg_list_head;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+struct acc_alg_item {
+ const char *name;
+ const char *algtype;
+};
+
+static struct acc_alg_item alg_options[] = {
+ {"zlib", "zlib"},
+ {"gzip", "gzip"},
+ {"deflate", "deflate"},
+ {"lz77_zstd", "lz77_zstd"},
+ {"lz4", "lz4"},
+ {"lz77_only", "lz77_only"},
+ {"hashagg", "hashagg"},
+ {"udma", "udma"},
+ {"hashjoin", "hashjoin"},
+ {"gather", "gather"},
+ {"join-gather", "hashjoin"},
+
+ {"rsa", "rsa"},
+ {"dh", "dh"},
+ {"ecdh", "ecdh"},
+ {"x25519", "x25519"},
+ {"x448", "x448"},
+ {"ecdsa", "ecdsa"},
+ {"sm2", "sm2"},
+
+ {"ecb(aes)", "cipher"},
+ {"cbc(aes)", "cipher"},
+ {"xts(aes)", "cipher"},
+ {"ofb(aes)", "cipher"},
+ {"cfb(aes)", "cipher"},
+ {"ctr(aes)", "cipher"},
+ {"cbc-cs1(aes)", "cipher"},
+ {"cbc-cs2(aes)", "cipher"},
+ {"cbc-cs3(aes)", "cipher"},
+ {"ecb(sm4)", "cipher"},
+ {"xts(sm4)", "cipher"},
+ {"cbc(sm4)", "cipher"},
+ {"ofb(sm4)", "cipher"},
+ {"cfb(sm4)", "cipher"},
+ {"ctr(sm4)", "cipher"},
+ {"cbc-cs1(sm4)", "cipher"},
+ {"cbc-cs2(sm4)", "cipher"},
+ {"cbc-cs3(sm4)", "cipher"},
+ {"ecb(des)", "cipher"},
+ {"cbc(des)", "cipher"},
+ {"ecb(des3_ede)", "cipher"},
+ {"cbc(des3_ede)", "cipher"},
+
+ {"ccm(aes)", "aead"},
+ {"gcm(aes)", "aead"},
+ {"ccm(sm4)", "aead"},
+ {"gcm(sm4)", "aead"},
+ {"authenc(generic,cbc(aes))", "aead"},
+ {"authenc(generic,cbc(sm4))", "aead"},
+
+ {"sm3", "digest"},
+ {"md5", "digest"},
+ {"sha1", "digest"},
+ {"sha256", "digest"},
+ {"sha224", "digest"},
+ {"sha384", "digest"},
+ {"sha512", "digest"},
+ {"sha512-224", "digest"},
+ {"sha512-256", "digest"},
+ {"cmac(aes)", "digest"},
+ {"gmac(aes)", "digest"},
+ {"xcbc-mac-96(aes)", "digest"},
+ {"xcbc-prf-128(aes)", "digest"},
+ {"", ""}
+};
+
+int wd_get_alg_type(const char *alg_name, char *alg_type)
+{
+ __u64 i;
+
+ if (!alg_name || !alg_type) {
+ WD_ERR("invalid: alg_name or alg_type is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(alg_options); i++) {
+ if (strcmp(alg_name, alg_options[i].name) == 0) {
+ (void)strcpy(alg_type, alg_options[i].algtype);
+ return 0;
+ }
+ }
+
+ return -WD_EINVAL;
+}
+
static bool wd_check_accel_dev(const char *dev_name)
{
struct dirent *dev_dir;
@@ -182,6 +273,7 @@ int wd_alg_driver_register(struct wd_alg_driver *drv)
return -WD_ENOMEM;
}
+ (void)wd_get_alg_type(drv->alg_name, new_alg->alg_type);
strncpy(new_alg->alg_name, drv->alg_name, ALG_NAME_SIZE - 1);
strncpy(new_alg->drv_name, drv->drv_name, DEV_NAME_LEN - 1);
new_alg->priority = drv->priority;
@@ -393,3 +485,35 @@ int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
return drv->recv(drv, ctx, msg);
}
+int wd_alg_get_dev_usage(const char *dev_name, const char *alg_type, __u8 alg_op_type)
+{
+ struct wd_alg_list *pnext = alg_list_head.next;
+ struct hisi_dev_usage dev_usage;
+ struct wd_alg_driver *drv;
+
+ if (!dev_name || !alg_type) {
+ WD_ERR("dev_name or alg_type is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ while (pnext) {
+ if (strstr(dev_name, pnext->drv_name) &&
+ !strcmp(alg_type, pnext->alg_type))
+ break;
+
+ pnext = pnext->next;
+ }
+
+ if (!pnext)
+ return -WD_EACCES;
+
+ drv = pnext->drv;
+ if (!drv->get_usage)
+ return -WD_EINVAL;
+
+ dev_usage.drv = drv;
+ dev_usage.alg_op_type = alg_op_type;
+ dev_usage.dev_name = dev_name;
+
+ return drv->get_usage(&dev_usage);
+}
diff --git a/wd_util.c b/wd_util.c
index daa7309..bec23f5 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -98,78 +98,6 @@ struct drv_lib_list {
struct drv_lib_list *next;
};
-struct acc_alg_item {
- const char *name;
- const char *algtype;
-};
-
-static struct acc_alg_item alg_options[] = {
- {"zlib", "zlib"},
- {"gzip", "gzip"},
- {"deflate", "deflate"},
- {"lz77_zstd", "lz77_zstd"},
- {"lz4", "lz4"},
- {"lz77_only", "lz77_only"},
- {"hashagg", "hashagg"},
- {"udma", "udma"},
- {"hashjoin", "hashjoin"},
- {"gather", "gather"},
- {"join-gather", "hashjoin"},
-
- {"rsa", "rsa"},
- {"dh", "dh"},
- {"ecdh", "ecdh"},
- {"x25519", "x25519"},
- {"x448", "x448"},
- {"ecdsa", "ecdsa"},
- {"sm2", "sm2"},
-
- {"ecb(aes)", "cipher"},
- {"cbc(aes)", "cipher"},
- {"xts(aes)", "cipher"},
- {"ofb(aes)", "cipher"},
- {"cfb(aes)", "cipher"},
- {"ctr(aes)", "cipher"},
- {"cbc-cs1(aes)", "cipher"},
- {"cbc-cs2(aes)", "cipher"},
- {"cbc-cs3(aes)", "cipher"},
- {"ecb(sm4)", "cipher"},
- {"xts(sm4)", "cipher"},
- {"cbc(sm4)", "cipher"},
- {"ofb(sm4)", "cipher"},
- {"cfb(sm4)", "cipher"},
- {"ctr(sm4)", "cipher"},
- {"cbc-cs1(sm4)", "cipher"},
- {"cbc-cs2(sm4)", "cipher"},
- {"cbc-cs3(sm4)", "cipher"},
- {"ecb(des)", "cipher"},
- {"cbc(des)", "cipher"},
- {"ecb(des3_ede)", "cipher"},
- {"cbc(des3_ede)", "cipher"},
-
- {"ccm(aes)", "aead"},
- {"gcm(aes)", "aead"},
- {"ccm(sm4)", "aead"},
- {"gcm(sm4)", "aead"},
- {"authenc(generic,cbc(aes))", "aead"},
- {"authenc(generic,cbc(sm4))", "aead"},
-
- {"sm3", "digest"},
- {"md5", "digest"},
- {"sha1", "digest"},
- {"sha256", "digest"},
- {"sha224", "digest"},
- {"sha384", "digest"},
- {"sha512", "digest"},
- {"sha512-224", "digest"},
- {"sha512-256", "digest"},
- {"cmac(aes)", "digest"},
- {"gmac(aes)", "digest"},
- {"xcbc-mac-96(aes)", "digest"},
- {"xcbc-prf-128(aes)", "digest"},
- {"", ""}
-};
-
static void *wd_internal_alloc(void *usr, size_t size)
{
if (size != 0)
@@ -2013,18 +1941,6 @@ int wd_init_param_check(struct wd_ctx_config *config, struct wd_sched *sched)
return 0;
}
-static void wd_get_alg_type(const char *alg_name, char *alg_type)
-{
- __u64 i;
-
- for (i = 0; i < ARRAY_SIZE(alg_options); i++) {
- if (strcmp(alg_name, alg_options[i].name) == 0) {
- (void)strcpy(alg_type, alg_options[i].algtype);
- break;
- }
- }
-}
-
static int wd_alg_init_fallback(struct wd_alg_driver *fb_driver)
{
if (!fb_driver->init) {
@@ -2175,7 +2091,7 @@ static int wd_env_set_ctx_nums(const char *alg_name, const char *name, const cha
char *left, *section, *start;
struct uacce_dev_list *list;
int is_comp;
- int ret = 0;
+ int ret;
/* COMP environment variable's format is different, mark it */
is_comp = strncmp(name, "WD_COMP_CTX_NUM", strlen(name)) ? 0 : 1;
@@ -2186,7 +2102,9 @@ static int wd_env_set_ctx_nums(const char *alg_name, const char *name, const cha
if (!start)
return -WD_ENOMEM;
- wd_get_alg_type(alg_name, alg_type);
+ ret = wd_get_alg_type(alg_name, alg_type);
+ if (ret)
+ return ret;
list = wd_get_accel_list(alg_type);
if (!list) {
WD_ERR("failed to get devices!\n");
@@ -3098,7 +3016,8 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs)
}
break;
case UADK_ALG_HW:
- wd_get_alg_type(alg, alg_type);
+ if (wd_get_alg_type(alg, alg_type))
+ return -WD_EINVAL;
(void)strcpy(attrs->alg, alg_type);
ctx_config = calloc(1, sizeof(*ctx_config));
--
2.33.0
1
7
您好!
sig-AccLib 邀请您参加 2025-11-26 11:00 召开的Zoom会议
会议主题:【2025/11/26 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/81738189438?pwd=pBbpGzVXKm85xvTcYVseW7cijBuaQp.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-11-26 11:00,
The subject of the conference is 【2025/11/26 AccLIb SIG 双周例会 11:00 - 12:00】
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/81738189438?pwd=pBbpGzVXKm85xvTcYVseW7cijBuaQp.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
18 Nov '25
From: lizhi <lizhi206(a)huawei.com>
The hpre v2 interface needs to support the no-sva business model
within the new evolution framework. This ensures that users
switching to the v2 interface can utilize both the sva mode
and the no-sva mode.
Signed-off-by: lizhi <lizhi206(a)huawei.com>
Signed-off-by: Zongyu Wu <wuzongyu1(a)huawei.com>
---
drv/hisi_comp.c | 3 +-
drv/hisi_hpre.c | 650 ++++++++++++++++++++++++++++-----------
drv/hisi_qm_udrv.c | 15 +-
include/drv/wd_dh_drv.h | 3 +
include/drv/wd_ecc_drv.h | 3 +
include/drv/wd_rsa_drv.h | 3 +
include/wd_dh.h | 2 +
include/wd_ecc.h | 2 +
include/wd_rsa.h | 2 +
wd_dh.c | 22 +-
wd_ecc.c | 53 ++--
wd_rsa.c | 56 +++-
12 files changed, 580 insertions(+), 234 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index 87d2103..8474e17 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -267,7 +267,8 @@ static __u32 copy_to_out(struct wd_comp_msg *msg, struct hisi_comp_buf *buf, __u
struct wd_comp_req *req = &msg->req;
struct wd_datalist *node = req->list_dst;
__u32 sgl_restlen, copy_len;
- __u32 len = 0, sgl_cplen = 0;
+ __u32 sgl_cplen = 0;
+ __u32 len = 0;
copy_len = total_len > req->dst_len ?
req->dst_len : total_len;
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 7ce842b..f3f2451 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -34,14 +34,17 @@
#define SM2_PONIT_SIZE 64
#define MAX_HASH_LENS BITS_TO_BYTES(521)
#define HW_PLAINTEXT_BYTES_MAX BITS_TO_BYTES(4096)
-#define HPRE_CTX_Q_NUM_DEF 1
+#define HPRE_CTX_Q_NUM_DEF 1
+#define MAP_PAIR_NUM_MAX 6
#define CRT_PARAMS_SZ(key_size) ((5 * (key_size)) >> 1)
#define CRT_GEN_PARAMS_SZ(key_size) ((7 * (key_size)) >> 1)
#define GEN_PARAMS_SZ(key_size) ((key_size) << 1)
#define CRT_PARAM_SZ(key_size) ((key_size) >> 1)
-#define WD_TRANS_FAIL 0
+#define GEN_PARAMS_SZ_UL(key_size) ((unsigned long)(key_size) << 1)
+#define DMA_ADDR(hi, lo) ((__u64)(((__u64)(hi) << 32) | (__u64)(lo)))
+#define WD_TRANS_FAIL 0
#define CURVE_PARAM_NUM 6
#define SECP256R1_KEY_SIZE 32
@@ -78,6 +81,21 @@ enum hpre_alg_name {
WD_ECC
};
+enum hpre_hw_msg_field {
+ HW_MSG_IN,
+ HW_MSG_OUT,
+ HW_MSG_KEY,
+};
+
+struct map_info_cache {
+ struct map_pair {
+ void *addr;
+ uintptr_t pa;
+ size_t size;
+ } pairs[MAP_PAIR_NUM_MAX];
+ size_t cnt;
+};
+
/* put vendor hardware message as a user interface is not suitable here */
struct hisi_hpre_sqe {
__u32 alg : 5;
@@ -113,12 +131,122 @@ struct hisi_hpre_sqe {
struct hisi_hpre_ctx {
struct wd_ctx_config_internal config;
+ struct wd_mm_ops *mm_ops;
+ handle_t rsv_mem_ctx;
};
struct hpre_ecc_ctx {
__u32 enable_hpcore;
};
+static void add_map_info(struct map_info_cache *cache, void *addr, uintptr_t dma, size_t size)
+{
+ /* The cnt is guaranteed not to exceed MAP_PAIR_NUM_MAX within hpre. */
+ cache->pairs[cache->cnt].addr = addr;
+ cache->pairs[cache->cnt].pa = dma;
+ cache->pairs[cache->cnt].size = size;
+ cache->cnt++;
+}
+
+static void unmap_addr_in_cache(struct wd_mm_ops *mm_ops, struct map_info_cache *cache)
+{
+ size_t i;
+
+ if (mm_ops->sva_mode)
+ return;
+
+ /* The cnt is guaranteed not to exceed MAP_PAIR_NUM_MAX within hpre. */
+ for (i = 0; i < cache->cnt; i++)
+ mm_ops->iova_unmap(mm_ops->usr, cache->pairs[i].addr,
+ (void *)cache->pairs[i].pa, cache->pairs[i].size);
+}
+
+static void unsetup_hw_msg_addr(struct wd_mm_ops *mm_ops, enum hpre_hw_msg_field t_type,
+ struct hisi_hpre_sqe *hw_msg, void *va, size_t data_sz)
+{
+ void *addr;
+
+ if (!mm_ops || mm_ops->sva_mode || !va || !data_sz)
+ return;
+
+ switch (t_type) {
+ case HW_MSG_KEY:
+ addr = VA_ADDR(hw_msg->hi_key, hw_msg->low_key);
+ break;
+ case HW_MSG_IN:
+ addr = VA_ADDR(hw_msg->hi_in, hw_msg->low_in);
+ break;
+ case HW_MSG_OUT:
+ addr = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
+ break;
+ default:
+ return;
+ }
+
+ if (!addr)
+ return;
+
+ mm_ops->iova_unmap(mm_ops->usr, va, (void *)addr, data_sz);
+}
+
+static uintptr_t select_addr_by_sva_mode(struct wd_mm_ops *mm_ops, void *data,
+ size_t data_sz, struct map_info_cache *cache)
+{
+ uintptr_t addr;
+
+ if (!mm_ops->sva_mode) {
+ addr = (uintptr_t)mm_ops->iova_map(mm_ops->usr, data, data_sz);
+ if (!addr) {
+ WD_ERR("Failed to get mappped DMA address for hardware.\n");
+ return 0;
+ }
+ add_map_info(cache, data, addr, data_sz);
+ } else {
+ addr = (uintptr_t)data;
+ }
+
+ return addr;
+}
+
+static void fill_hw_msg_addr(enum hpre_hw_msg_field t_type, struct hisi_hpre_sqe *hw_msg,
+ uintptr_t addr)
+{
+ switch (t_type) {
+ case HW_MSG_KEY:
+ hw_msg->low_key = LW_U32(addr);
+ hw_msg->hi_key = HI_U32(addr);
+ break;
+ case HW_MSG_IN:
+ hw_msg->low_in = LW_U32(addr);
+ hw_msg->hi_in = HI_U32(addr);
+ break;
+ case HW_MSG_OUT:
+ hw_msg->low_out = LW_U32(addr);
+ hw_msg->hi_out = HI_U32(addr);
+ break;
+ default:
+ return;
+ }
+}
+
+static int check_hpre_mem_params(struct wd_mm_ops *mm_ops, enum wd_mem_type mm_type)
+{
+ if (!mm_ops) {
+ WD_ERR("Memory operation functions are null.\n");
+ return -WD_EINVAL;
+ }
+
+ if (mm_type == UADK_MEM_AUTO && !mm_ops->sva_mode) {
+ WD_ERR("No-SVA in auto mode is not supported yet.\n");
+ return -WD_EINVAL;
+ } else if (mm_type > UADK_MEM_PROXY) {
+ WD_ERR("failed to check memory type.\n");
+ return -WD_EINVAL;
+ }
+
+ return WD_SUCCESS;
+}
+
static void dump_hpre_msg(void *msg, int alg)
{
struct wd_rsa_msg *rsa_msg;
@@ -269,7 +397,8 @@ static int fill_rsa_crt_prikey2(struct wd_rsa_prikey *prikey,
*data = wd_dq->data;
- return WD_SUCCESS;
+ return (int)(wd_dq->bsize + wd_qinv->bsize + wd_p->bsize +
+ wd_q->bsize + wd_dp->bsize);
}
static int fill_rsa_prikey1(struct wd_rsa_prikey *prikey, void **data)
@@ -292,7 +421,7 @@ static int fill_rsa_prikey1(struct wd_rsa_prikey *prikey, void **data)
*data = wd_d->data;
- return WD_SUCCESS;
+ return (int)(wd_n->bsize + wd_d->bsize);
}
static int fill_rsa_pubkey(struct wd_rsa_pubkey *pubkey, void **data)
@@ -315,7 +444,7 @@ static int fill_rsa_pubkey(struct wd_rsa_pubkey *pubkey, void **data)
*data = wd_e->data;
- return WD_SUCCESS;
+ return (int)(wd_n->bsize + wd_e->bsize);
}
static int fill_rsa_genkey_in(struct wd_rsa_kg_in *genkey)
@@ -378,22 +507,21 @@ static int rsa_out_transfer(struct wd_rsa_msg *msg,
{
struct wd_rsa_req *req = &msg->req;
struct wd_rsa_kg_out *key = req->dst;
+ struct wd_rsa_msg *target_msg;
__u16 kbytes = msg->key_bytes;
struct wd_dtb qinv, dq, dp;
struct wd_dtb d, n;
- void *data;
int ret;
- if (hw_msg->alg == HPRE_ALG_KG_CRT || hw_msg->alg == HPRE_ALG_KG_STD) {
- /* async */
- 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 {
- key = req->dst;
- }
+ target_msg = (struct wd_rsa_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct rsa send msg from hardware!\n");
+ return -WD_ADDR_ERR;
}
+ if (hw_msg->alg == HPRE_ALG_KG_CRT || hw_msg->alg == HPRE_ALG_KG_STD)
+ key = target_msg->req.dst;
+
msg->result = WD_SUCCESS;
if (hw_msg->alg == HPRE_ALG_KG_CRT) {
req->dst_bytes = CRT_GEN_PARAMS_SZ(kbytes);
@@ -424,37 +552,38 @@ static int rsa_out_transfer(struct wd_rsa_msg *msg,
return WD_SUCCESS;
}
-static int rsa_prepare_key(struct wd_rsa_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int rsa_prepare_key(struct wd_rsa_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
struct wd_rsa_req *req = &msg->req;
+ uintptr_t addr;
+ int ret, len;
void *data;
- int ret;
if (req->op_type == WD_RSA_SIGN) {
if (hw_msg->alg == HPRE_ALG_NC_CRT) {
- ret = fill_rsa_crt_prikey2((void *)msg->key, &data);
- if (ret)
- return ret;
+ len = fill_rsa_crt_prikey2((void *)msg->key, &data);
+ if (len <= 0)
+ return -WD_EINVAL;
} else {
- ret = fill_rsa_prikey1((void *)msg->key, &data);
- if (ret)
- return ret;
+ len = fill_rsa_prikey1((void *)msg->key, &data);
+ if (len <= 0)
+ return -WD_EINVAL;
hw_msg->alg = HPRE_ALG_NC_NCRT;
}
} else if (req->op_type == WD_RSA_VERIFY) {
- ret = fill_rsa_pubkey((void *)msg->key, &data);
- if (ret)
- return ret;
+ len = fill_rsa_pubkey((void *)msg->key, &data);
+ if (len <= 0)
+ return -WD_EINVAL;
hw_msg->alg = HPRE_ALG_NC_NCRT;
} else if (req->op_type == WD_RSA_GENKEY) {
ret = fill_rsa_genkey_in((void *)msg->key);
if (ret)
return ret;
- ret = wd_rsa_kg_in_data((void *)msg->key, (char **)&data);
- if (ret < 0) {
+ len = wd_rsa_kg_in_data((void *)msg->key, (char **)&data);
+ if (len < 0) {
WD_ERR("failed to get rsa gen key data!\n");
- return ret;
+ return -WD_EINVAL;
}
if (hw_msg->alg == HPRE_ALG_NC_CRT)
hw_msg->alg = HPRE_ALG_KG_CRT;
@@ -465,36 +594,53 @@ static int rsa_prepare_key(struct wd_rsa_msg *msg,
return -WD_EINVAL;
}
- hw_msg->low_key = LW_U32((uintptr_t)data);
- hw_msg->hi_key = HI_U32((uintptr_t)data);
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, len, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_KEY, hw_msg, addr);
- return WD_SUCCESS;
+ return ret;
}
-static int rsa_prepare_iot(struct wd_rsa_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int rsa_prepare_iot(struct wd_rsa_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
struct wd_rsa_req *req = &msg->req;
struct wd_rsa_kg_out *kout = req->dst;
int ret = WD_SUCCESS;
- void *out = NULL;
+ uintptr_t phy, out;
if (req->op_type != WD_RSA_GENKEY) {
- hw_msg->low_in = LW_U32((uintptr_t)req->src);
- hw_msg->hi_in = HI_U32((uintptr_t)req->src);
- out = req->dst;
+ phy = select_addr_by_sva_mode(msg->mm_ops, req->src, req->src_bytes, cache);
+ if (!phy)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_IN, hw_msg, phy);
+ phy = select_addr_by_sva_mode(msg->mm_ops, req->dst, req->dst_bytes, cache);
+ if (!phy)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_OUT, hw_msg, phy);
} else {
hw_msg->low_in = 0;
hw_msg->hi_in = 0;
ret = wd_rsa_kg_out_data(kout, (char **)&out);
if (ret < 0)
return ret;
- }
- hw_msg->low_out = LW_U32((uintptr_t)out);
- hw_msg->hi_out = HI_U32((uintptr_t)out);
+ if (!msg->mm_ops->sva_mode) {
+ phy = (uintptr_t)msg->mm_ops->iova_map(msg->mm_ops->usr, kout, ret);
+ if (!phy) {
+ WD_ERR("Failed to get DMA address for rsa output!\n");
+ return -WD_ENOMEM;
+ }
+ add_map_info(cache, kout, phy, ret);
+ out = phy + out - (uintptr_t)kout;
+ }
+
+ hw_msg->low_out = LW_U32(out);
+ hw_msg->hi_out = HI_U32(out);
+ }
- return ret;
+ return WD_SUCCESS;
}
static int hpre_init_qm_priv(struct wd_ctx_config_internal *config,
@@ -615,10 +761,17 @@ static int rsa_send(struct wd_alg_driver *drv, 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 map_info_cache cache = {0};
struct hisi_hpre_sqe hw_msg;
__u16 send_cnt = 0;
int ret;
+ ret = check_hpre_mem_params(msg->mm_ops, msg->mm_type);
+ if (ret) {
+ WD_ERR("rsa memory parmas is err, and ret is %d!\n", ret);
+ return ret;
+ }
+
memset(&hw_msg, 0, sizeof(struct hisi_hpre_sqe));
if (msg->key_type == WD_RSA_PRIKEY1 ||
@@ -631,21 +784,30 @@ static int rsa_send(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
hw_msg.task_len1 = msg->key_bytes / BYTE_BITS - 0x1;
- ret = rsa_prepare_key(msg, &hw_msg);
- if (ret < 0)
- return ret;
+ ret = rsa_prepare_key(msg, &hw_msg, &cache);
+ if (ret)
+ goto rsa_fail;
/* prepare in/out put */
- ret = rsa_prepare_iot(msg, &hw_msg);
- if (ret < 0)
- return ret;
+ ret = rsa_prepare_iot(msg, &hw_msg, &cache);
+ if (ret)
+ goto rsa_fail;
hisi_set_msg_id(h_qp, &msg->tag);
hw_msg.done = 0x1;
hw_msg.etype = 0x0;
- hw_msg.low_tag = msg->tag;
+ hw_msg.low_tag = LW_U32((uintptr_t)msg);
+ hw_msg.hi_tag = HI_U32((uintptr_t)msg);
- return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ ret = hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ if (unlikely(ret))
+ goto rsa_fail;
+
+ return ret;
+
+rsa_fail:
+ unmap_addr_in_cache(msg->mm_ops, &cache);
+ return ret;
}
static void hpre_result_check(struct hisi_hpre_sqe *hw_msg,
@@ -671,32 +833,29 @@ static int rsa_recv(struct wd_alg_driver *drv, 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 *target_msg;
struct wd_rsa_msg *msg = rsa_msg;
- struct wd_rsa_msg *temp_msg;
+ struct hisi_hpre_sqe hw_msg = {0};
+ size_t ilen = 0, olen = 0;
__u16 recv_cnt = 0;
+ __u16 kbytes;
int ret;
ret = hisi_qm_recv(h_qp, &hw_msg, 1, &recv_cnt);
if (ret < 0)
return ret;
- ret = hisi_check_bd_id(h_qp, msg->tag, hw_msg.low_tag);
+ target_msg = (struct wd_rsa_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
+ ret = hisi_check_bd_id(h_qp, msg->tag, target_msg->tag);
if (ret)
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;
- }
-
+ msg->tag = target_msg->tag;
hpre_result_check(&hw_msg, &msg->result);
if (!msg->result) {
ret = rsa_out_transfer(msg, &hw_msg, qp->q_info.qp_mode);
@@ -707,15 +866,36 @@ static int rsa_recv(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
}
if (unlikely(msg->result != WD_SUCCESS))
- dump_hpre_msg(temp_msg, WD_RSA);
+ dump_hpre_msg(target_msg, WD_RSA);
+
+ if (!target_msg->mm_ops->sva_mode) {
+ kbytes = target_msg->key_bytes;
+ if (hw_msg.alg == HPRE_ALG_KG_CRT) {
+ olen = CRT_GEN_PARAMS_SZ(kbytes);
+ ilen = GEN_PARAMS_SZ_UL(kbytes);
+ } else if (hw_msg.alg == HPRE_ALG_KG_STD) {
+ olen = GEN_PARAMS_SZ_UL(kbytes);
+ ilen = GEN_PARAMS_SZ_UL(kbytes);
+ } else {
+ olen = kbytes;
+ ilen = kbytes;
+ }
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_IN, &hw_msg,
+ target_msg->req.src, ilen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_OUT, &hw_msg,
+ target_msg->req.dst, olen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_KEY, &hw_msg,
+ target_msg->key, target_msg->key_bytes);
+ }
return WD_SUCCESS;
}
-static int fill_dh_xp_params(struct wd_dh_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int fill_dh_xp_params(struct wd_dh_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
struct wd_dh_req *req = &msg->req;
+ uintptr_t addr;
void *x, *p;
int ret;
@@ -735,26 +915,30 @@ static int fill_dh_xp_params(struct wd_dh_msg *msg,
return ret;
}
- hw_msg->low_key = LW_U32((uintptr_t)x);
- hw_msg->hi_key = HI_U32((uintptr_t)x);
+ addr = select_addr_by_sva_mode(msg->mm_ops, x, GEN_PARAMS_SZ_UL(msg->key_bytes), cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_KEY, hw_msg, addr);
- return WD_SUCCESS;
+ return ret;
}
-static int dh_out_transfer(struct wd_dh_msg *msg,
- struct hisi_hpre_sqe *hw_msg, __u8 qp_mode)
+static int dh_out_transfer(struct wd_dh_msg *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;
+ struct wd_dh_msg *target_msg;
void *out;
int ret;
- /* async */
- if (qp_mode == CTX_MODE_ASYNC)
- out = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
- else
- out = req->pri;
+ target_msg = (struct wd_dh_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+ out = target_msg->req.pri;
ret = hpre_bin_to_crypto_bin((char *)out,
(const char *)out, key_bytes, "dh out");
if (!ret)
@@ -768,12 +952,20 @@ static int dh_out_transfer(struct wd_dh_msg *msg,
static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct map_info_cache cache = {0};
struct wd_dh_msg *msg = dh_msg;
struct wd_dh_req *req = &msg->req;
struct hisi_hpre_sqe hw_msg;
__u16 send_cnt = 0;
+ uintptr_t addr;
int ret;
+ ret = check_hpre_mem_params(msg->mm_ops, msg->mm_type);
+ if (ret) {
+ WD_ERR("dh memory parmas is err, and ret is %d!\n", ret);
+ return ret;
+ }
+
memset(&hw_msg, 0, sizeof(struct hisi_hpre_sqe));
if (msg->is_g2 && req->op_type != WD_DH_PHASE2)
@@ -791,32 +983,50 @@ static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
WD_ERR("failed to transfer dh g para format to hpre bin!\n");
return ret;
}
-
- hw_msg.low_in = LW_U32((uintptr_t)msg->g);
- hw_msg.hi_in = HI_U32((uintptr_t)msg->g);
+ addr = select_addr_by_sva_mode(msg->mm_ops, msg->g, msg->key_bytes, &cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_IN, &hw_msg, addr);
}
- ret = fill_dh_xp_params(msg, &hw_msg);
- if (ret)
- return ret;
+ ret = fill_dh_xp_params(msg, &hw_msg, &cache);
+ if (ret) {
+ WD_ERR("failed to fill dh x or p para!\n");
+ goto dh_fail;
+ }
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;
hw_msg.etype = 0x0;
- hw_msg.low_tag = msg->tag;
- return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ hw_msg.low_tag = LW_U32((uintptr_t)msg);
+ hw_msg.hi_tag = HI_U32((uintptr_t)msg);
+
+ addr = select_addr_by_sva_mode(msg->mm_ops, req->pri, req->pri_bytes, &cache);
+ if (!addr) {
+ ret = -WD_ENOMEM;
+ goto dh_fail;
+ }
+ fill_hw_msg_addr(HW_MSG_OUT, &hw_msg, addr);
+
+ ret = hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ if (unlikely(ret))
+ goto dh_fail;
+
+ return ret;
+
+dh_fail:
+ unmap_addr_in_cache(msg->mm_ops, &cache);
+ return ret;
}
static int dh_recv(struct wd_alg_driver *drv, 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;
+ struct wd_dh_msg *msg = dh_msg;
+ struct wd_dh_msg *target_msg;
__u16 recv_cnt = 0;
int ret;
@@ -824,22 +1034,17 @@ static int dh_recv(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
if (ret < 0)
return ret;
- ret = hisi_check_bd_id(h_qp, msg->tag, hw_msg.low_tag);
+ target_msg = (struct wd_dh_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
+ ret = hisi_check_bd_id(h_qp, msg->tag, target_msg->tag);
if (ret)
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;
- }
-
+ msg->tag = target_msg->tag;
hpre_result_check(&hw_msg, &msg->result);
if (!msg->result) {
ret = dh_out_transfer(msg, &hw_msg, qp->q_info.qp_mode);
@@ -850,7 +1055,16 @@ static int dh_recv(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
}
if (unlikely(msg->result != WD_SUCCESS))
- dump_hpre_msg(temp_msg, WD_DH);
+ dump_hpre_msg(target_msg, WD_DH);
+
+ if (!target_msg->mm_ops->sva_mode) {
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_OUT, &hw_msg,
+ target_msg->req.pri, target_msg->req.pri_bytes);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_KEY, &hw_msg,
+ target_msg->req.x_p, GEN_PARAMS_SZ_UL(target_msg->key_bytes));
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_IN, &hw_msg,
+ target_msg->g, target_msg->key_bytes);
+ }
return WD_SUCCESS;
}
@@ -1081,30 +1295,49 @@ static bool is_prikey_used(__u8 op_type)
op_type == HPRE_SM2_DEC;
}
-static int ecc_prepare_key(struct wd_ecc_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static __u32 ecc_get_prikey_size(struct wd_ecc_msg *msg)
+{
+ if (msg->req.op_type == WD_SM2_SIGN ||
+ msg->req.op_type == WD_ECDSA_SIGN ||
+ msg->req.op_type == WD_SM2_DECRYPT)
+ return ECC_PRIKEY_SZ(msg->key_bytes);
+ else if (msg->curve_id == WD_X25519 ||
+ msg->curve_id == WD_X448)
+ return X_DH_HW_KEY_SZ(msg->key_bytes);
+ else
+ return ECDH_HW_KEY_SZ(msg->key_bytes);
+}
+
+static int ecc_prepare_key(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
void *data = NULL;
+ uintptr_t addr;
+ size_t ksz;
int ret;
if (is_prikey_used(msg->req.op_type)) {
+ ksz = ecc_get_prikey_size(msg);
ret = ecc_prepare_prikey((void *)msg->key, &data, msg->curve_id);
if (ret)
return ret;
} else {
+ ksz = ECC_PUBKEY_SZ(msg->key_bytes);
ret = ecc_prepare_pubkey((void *)msg->key, &data);
if (ret)
return ret;
}
- hw_msg->low_key = LW_U32((uintptr_t)data);
- hw_msg->hi_key = HI_U32((uintptr_t)data);
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, ksz, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_KEY, hw_msg, addr);
- return WD_SUCCESS;
+ return ret;
}
-static void ecc_get_io_len(__u32 atype, __u32 hsz, size_t *ilen,
- size_t *olen)
+static void ecc_get_io_len(__u32 atype, __u32 hsz,
+ size_t *ilen, size_t *olen)
{
if (atype == HPRE_ALG_ECDH_MULTIPLY) {
*olen = ECDH_OUT_PARAMS_SZ(hsz);
@@ -1467,12 +1700,12 @@ static int ecc_prepare_out(struct wd_ecc_msg *msg, void **data)
}
/* prepare in/out hw message */
-static int ecc_prepare_iot(struct wd_ecc_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int ecc_prepare_iot(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
+ size_t i_sz, o_sz;
void *data = NULL;
- size_t i_sz = 0;
- size_t o_sz = 0;
+ uintptr_t addr;
__u16 kbytes;
int ret;
@@ -1483,8 +1716,11 @@ static int ecc_prepare_iot(struct wd_ecc_msg *msg,
WD_ERR("failed to prepare ecc in!\n");
return ret;
}
- hw_msg->low_in = LW_U32((uintptr_t)data);
- hw_msg->hi_in = HI_U32((uintptr_t)data);
+
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, i_sz, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_IN, hw_msg, addr);
ret = ecc_prepare_out(msg, &data);
if (ret) {
@@ -1496,8 +1732,10 @@ static int ecc_prepare_iot(struct wd_ecc_msg *msg,
if (!data)
return WD_SUCCESS;
- hw_msg->low_out = LW_U32((uintptr_t)data);
- hw_msg->hi_out = HI_U32((uintptr_t)data);
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, o_sz, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_OUT, hw_msg, addr);
return WD_SUCCESS;
}
@@ -1613,7 +1851,7 @@ static struct wd_ecc_out *create_ecdh_out(struct wd_ecc_msg *msg)
return NULL;
}
- out = malloc(len);
+ out = msg->mm_ops->alloc(msg->mm_ops->usr, len);
if (!out) {
WD_ERR("failed to alloc out memory, sz = %u!\n", len);
return NULL;
@@ -1677,7 +1915,7 @@ static struct wd_ecc_msg *create_req(struct wd_ecc_msg *src, __u8 req_idx)
prikey = (struct wd_ecc_prikey *)(ecc_key + 1);
ecc_key->prikey = prikey;
- prikey->data = malloc(ECC_PRIKEY_SZ(src->key_bytes));
+ prikey->data = src->mm_ops->alloc(src->mm_ops->usr, ECC_PRIKEY_SZ(src->key_bytes));
if (unlikely(!prikey->data)) {
WD_ERR("failed to alloc prikey data!\n");
goto fail_alloc_key_data;
@@ -1696,7 +1934,7 @@ static struct wd_ecc_msg *create_req(struct wd_ecc_msg *src, __u8 req_idx)
return dst;
fail_set_prikey:
- free(prikey->data);
+ src->mm_ops->free(src->mm_ops->usr, prikey->data);
fail_alloc_key_data:
free(ecc_key);
fail_alloc_key:
@@ -1709,9 +1947,9 @@ static void free_req(struct wd_ecc_msg *msg)
{
struct wd_ecc_key *key = (void *)msg->key;
- free(key->prikey->data);
+ msg->mm_ops->free(msg->mm_ops->usr, key->prikey->data);
free(key);
- free(msg->req.dst);
+ msg->mm_ops->free(msg->mm_ops->usr, msg->req.dst);
free(msg);
}
@@ -1732,7 +1970,8 @@ static int split_req(struct wd_ecc_msg *src, struct wd_ecc_msg **dst)
return WD_SUCCESS;
}
-static int ecc_fill(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
+static int ecc_fill(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
__u32 hw_sz = get_hw_keysz(msg->key_bytes);
__u8 op_type = msg->req.op_type;
@@ -1757,39 +1996,42 @@ static int ecc_fill(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
return ret;
/* prepare key */
- ret = ecc_prepare_key(msg, hw_msg);
+ ret = ecc_prepare_key(msg, hw_msg, cache);
if (ret)
return ret;
/* prepare in/out put */
- ret = ecc_prepare_iot(msg, hw_msg);
+ ret = ecc_prepare_iot(msg, hw_msg, cache);
if (ret)
return ret;
hw_msg->done = 0x1;
hw_msg->etype = 0x0;
- hw_msg->low_tag = msg->tag;
+
+ hw_msg->low_tag = LW_U32((uintptr_t)msg);
+ hw_msg->hi_tag = HI_U32((uintptr_t)msg);
hw_msg->task_len1 = hw_sz / BYTE_BITS - 0x1;
return ret;
}
-static int ecc_general_send(handle_t ctx, struct wd_ecc_msg *msg)
+static int ecc_general_send(handle_t ctx, struct wd_ecc_msg *msg,
+ struct map_info_cache *cache)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_hpre_sqe hw_msg;
__u16 send_cnt = 0;
int ret;
- ret = ecc_fill(msg, &hw_msg);
+ ret = ecc_fill(msg, &hw_msg, cache);
if (ret)
return ret;
return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
}
-
-static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
+static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg,
+ struct map_info_cache *cache)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_sm2_enc_in *ein = msg->req.src;
@@ -1801,7 +2043,7 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
if (ein->plaintext.dsize <= HW_PLAINTEXT_BYTES_MAX &&
hash->type == WD_HASH_SM3)
- return ecc_general_send(ctx, msg);
+ return ecc_general_send(ctx, msg, cache);
if (unlikely(!ein->k_set)) {
WD_ERR("invalid: k not set!\n");
@@ -1824,13 +2066,13 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
return ret;
}
- ret = ecc_fill(msg_dst[0], &hw_msg[0]);
+ ret = ecc_fill(msg_dst[0], &hw_msg[0], cache);
if (unlikely(ret)) {
WD_ERR("failed to fill 1th sqe, ret = %d!\n", ret);
goto fail_fill_sqe;
}
- ret = ecc_fill(msg_dst[1], &hw_msg[1]);
+ ret = ecc_fill(msg_dst[1], &hw_msg[1], cache);
if (unlikely(ret)) {
WD_ERR("failed to fill 2th sqe, ret = %d!\n", ret);
goto fail_fill_sqe;
@@ -1855,7 +2097,8 @@ fail_fill_sqe:
return ret;
}
-static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg)
+static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg,
+ struct map_info_cache *cache)
{
struct wd_sm2_dec_in *din = (void *)msg->req.src;
struct wd_hash_mt *hash = &msg->hash;
@@ -1865,7 +2108,7 @@ static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg)
/* c2 data lens <= 4096 bit */
if (din->c2.dsize <= BITS_TO_BYTES(4096) &&
hash->type == WD_HASH_SM3)
- return ecc_general_send(ctx, msg);
+ return ecc_general_send(ctx, msg, cache);
if (unlikely(!hash->cb || hash->type >= WD_HASH_MAX)) {
WD_ERR("invalid: input hash type %u is error!\n", hash->type);
@@ -1891,14 +2134,14 @@ static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg)
goto free_dst;
}
- ret = ecc_general_send(ctx, dst);
+ ret = ecc_general_send(ctx, dst, cache);
if (unlikely(ret))
goto free_req_dst;
return ret;
free_req_dst:
- free(dst->req.dst);
+ msg->mm_ops->free(msg->mm_ops->usr, dst->req.dst);
free_dst:
free(dst);
return ret;
@@ -1908,14 +2151,37 @@ static int ecc_send(struct wd_alg_driver *drv, 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 map_info_cache cache = {0};
+ int ret;
+
+ ret = check_hpre_mem_params(msg->mm_ops, msg->mm_type);
+ if (ret) {
+ WD_ERR("ecc memory parmas is err, and ret is %d!\n", ret);
+ return ret;
+ }
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)
- return sm2_dec_send(ctx, msg);
+ if (msg->req.op_type == WD_SM2_ENCRYPT) {
+ ret = sm2_enc_send(ctx, msg, &cache);
+ if (ret)
+ goto ecc_fail;
+ return ret;
+ } else if (msg->req.op_type == WD_SM2_DECRYPT) {
+ ret = sm2_dec_send(ctx, msg, &cache);
+ if (ret)
+ goto ecc_fail;
+ return ret;
+ }
- return ecc_general_send(ctx, msg);
+ ret = ecc_general_send(ctx, msg, &cache);
+ if (ret)
+ goto ecc_fail;
+
+ return ret;
+
+ecc_fail:
+ unmap_addr_in_cache(msg->mm_ops, &cache);
+ return ret;
}
static int ecdh_out_transfer(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
@@ -2020,14 +2286,14 @@ 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, __u8 qp_mode)
{
+ struct wd_ecc_msg *target_msg;
int ret = -WD_EINVAL;
- void *va;
+
+ target_msg = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
/* async */
- 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);
- }
+ if (qp_mode == CTX_MODE_ASYNC)
+ msg->req.dst = target_msg->req.dst;
if (hw_msg->alg == HPRE_ALG_SM2_SIGN ||
hw_msg->alg == HPRE_ALG_ECDSA_SIGN)
@@ -2319,19 +2585,16 @@ static int sm2_convert_dec_out(struct wd_ecc_msg *src,
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;
+ struct wd_ecc_msg *target_msg;
+ size_t ilen = 0;
+ size_t olen = 0;
+ __u16 kbytes;
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;
+ target_msg = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct ecc send msg from hardware!\n");
+ return -WD_ADDR_ERR;
}
hpre_result_check(hw_msg, &msg->result);
@@ -2347,10 +2610,20 @@ static int ecc_sqe_parse(struct hisi_qp *qp, struct wd_ecc_msg *msg,
goto dump_err_msg;
}
- return ret;
+ return WD_SUCCESS;
dump_err_msg:
- dump_hpre_msg(temp_msg, WD_ECC);
+ kbytes = target_msg->key_bytes;
+ if (!target_msg->mm_ops->sva_mode) {
+ ecc_get_io_len(hw_msg->alg, kbytes, &ilen, &olen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_OUT, hw_msg,
+ target_msg->req.dst, olen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_KEY, hw_msg,
+ target_msg->key, kbytes);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_IN, hw_msg,
+ target_msg->req.src, ilen);
+ }
+ dump_hpre_msg(target_msg, WD_ECC);
return ret;
}
@@ -2363,8 +2636,6 @@ static int parse_second_sqe(handle_t h_qp,
struct wd_ecc_msg *dst;
__u16 recv_cnt = 0;
int cnt = 0;
- void *data;
- __u32 hsz;
int ret;
while (1) {
@@ -2380,10 +2651,12 @@ static int parse_second_sqe(handle_t h_qp,
break;
}
- data = VA_ADDR(hw_msg.hi_out, hw_msg.low_out);
- hsz = (hw_msg.task_len1 + 1) * BYTE_BITS;
- dst = *(struct wd_ecc_msg **)((uintptr_t)data +
- hsz * ECDH_OUT_PARAM_NUM);
+ dst = (struct wd_ecc_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!dst) {
+ WD_ERR("failed to get correct sm2 enc second send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
ret = ecc_sqe_parse((struct hisi_qp *)h_qp, dst, &hw_msg);
msg->result = dst->result;
*second = dst;
@@ -2394,19 +2667,17 @@ static int parse_second_sqe(handle_t h_qp,
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;
struct wd_ecc_msg *first;
struct wd_ecc_msg src;
- void *data;
- __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 +
- hsz * ECDH_OUT_PARAM_NUM);
+ first = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!first) {
+ WD_ERR("failed to get correct sm2 enc msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
memcpy(&src, first + 1, sizeof(src));
/* parse first sqe */
@@ -2440,17 +2711,15 @@ free_first:
static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
struct hisi_hpre_sqe *hw_msg)
{
- __u16 tag = LW_U16(hw_msg->low_tag);
struct wd_ecc_msg *dst;
struct wd_ecc_msg src;
- void *data;
- __u32 hsz;
int ret;
- data = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
- hsz = (hw_msg->task_len1 + 1) * BYTE_BITS;
- dst = *(struct wd_ecc_msg **)((uintptr_t)data +
- hsz * ECDH_OUT_PARAM_NUM);
+ dst = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!dst) {
+ WD_ERR("failed to get correct sm2 dec msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
memcpy(&src, dst + 1, sizeof(src));
/* parse first sqe */
@@ -2460,7 +2729,6 @@ static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
goto fail;
}
msg->result = dst->result;
- msg->tag = tag;
ret = sm2_convert_dec_out(&src, dst);
if (unlikely(ret)) {
@@ -2469,7 +2737,7 @@ static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
}
fail:
- free(dst->req.dst);
+ dst->mm_ops->free(dst->mm_ops->usr, dst->req.dst);
free(dst);
return ret;
@@ -2479,6 +2747,7 @@ static int ecc_recv(struct wd_alg_driver *drv, 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 wd_ecc_msg *target_msg;
struct hisi_hpre_sqe hw_msg;
__u16 recv_cnt = 0;
int ret;
@@ -2487,10 +2756,17 @@ static int ecc_recv(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
if (ret)
return ret;
- ret = hisi_check_bd_id(h_qp, msg->tag, hw_msg.low_tag);
+ target_msg = (struct wd_ecc_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
+ ret = hisi_check_bd_id(h_qp, msg->tag, target_msg->tag);
if (ret)
return ret;
+ msg->tag = target_msg->tag;
if (hw_msg.alg == HPRE_ALG_ECDH_MULTIPLY &&
hw_msg.sm2_mlen == HPRE_SM2_ENC)
return sm2_enc_parse(h_qp, msg, &hw_msg);
@@ -2549,7 +2825,7 @@ static bool is_valid_hw_type(struct wd_alg_driver *drv)
hpre_ctx = (struct hisi_hpre_ctx *)drv->priv;
qp = (struct hisi_qp *)wd_ctx_get_priv(hpre_ctx->config.ctxs[0].ctx);
- if (qp->q_info.hw_type < HISI_QM_API_VER3_BASE)
+ if (!qp || qp->q_info.hw_type < HISI_QM_API_VER3_BASE)
return false;
return true;
}
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 9251b4c..216b80a 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -473,7 +473,7 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
{
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
struct hisi_qm_queue_info *q_info;
- __u16 free_num, send_num;
+ __u16 free_num;
__u16 tail;
if (unlikely(!qp || !req || !count))
@@ -488,11 +488,14 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
return -WD_EBUSY;
}
- send_num = expect > free_num ? free_num : expect;
+ if (expect > free_num) {
+ pthread_spin_unlock(&q_info->sd_lock);
+ return -WD_EBUSY;
+ }
tail = q_info->sq_tail_index;
- hisi_qm_fill_sqe(req, q_info, tail, send_num);
- tail = (tail + send_num) % q_info->sq_depth;
+ hisi_qm_fill_sqe(req, q_info, tail, expect);
+ tail = (tail + expect) % q_info->sq_depth;
/*
* Before sending doorbell, check the queue status,
@@ -510,9 +513,9 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
q_info->sq_tail_index = tail;
/* Make sure used_num is changed before the next thread gets free sqe. */
- __atomic_add_fetch(&q_info->used_num, send_num, __ATOMIC_RELAXED);
+ __atomic_add_fetch(&q_info->used_num, expect, __ATOMIC_RELAXED);
pthread_spin_unlock(&q_info->sd_lock);
- *count = send_num;
+ *count = expect;
return 0;
}
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
index d205dc4..d2a6157 100644
--- a/include/drv/wd_dh_drv.h
+++ b/include/drv/wd_dh_drv.h
@@ -16,12 +16,15 @@ extern "C" {
/* DH message format */
struct wd_dh_msg {
struct wd_dh_req req;
+ struct wd_mm_ops *mm_ops;
+ enum wd_mem_type mm_type;
__u32 tag; /* User-defined request identifier */
void *g;
__u16 gbytes;
__u16 key_bytes; /* Input key bytes */
__u8 is_g2;
__u8 result; /* Data format, denoted by WD error code */
+ __u8 *rsv_out; /* reserved output data pointer */
};
struct wd_dh_msg *wd_dh_get_msg(__u32 idx, __u32 tag);
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index 6193c8b..b123a9b 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -48,6 +48,8 @@ extern "C" {
/* ECC message format */
struct wd_ecc_msg {
struct wd_ecc_req req;
+ struct wd_mm_ops *mm_ops;
+ enum wd_mem_type mm_type;
struct wd_hash_mt hash;
__u32 tag; /* User-defined request identifier */
__u8 *key; /* Input key VA, should be DMA buffer */
@@ -55,6 +57,7 @@ struct wd_ecc_msg {
__u8 curve_id; /* Ec curve denoted by enum wd_ecc_curve_type */
__u8 result; /* alg op error code */
void *drv_cfg; /* internal driver configuration */
+ __u8 *rsv_out; /* reserved output data pointer */
};
struct wd_ecc_pubkey {
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
index d231ecf..c12f3e0 100644
--- a/include/drv/wd_rsa_drv.h
+++ b/include/drv/wd_rsa_drv.h
@@ -42,11 +42,14 @@ struct wd_rsa_kg_out {
/* RSA message format */
struct wd_rsa_msg {
struct wd_rsa_req req;
+ struct wd_mm_ops *mm_ops;
+ enum wd_mem_type mm_type;
__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 */
__u8 *key; /* Input key VA pointer, should be DMA buffer */
+ __u8 *rsv_out; /* reserved output data pointer */
};
struct wd_rsa_msg *wd_rsa_get_msg(__u32 idx, __u32 tag);
diff --git a/include/wd_dh.h b/include/wd_dh.h
index afc2f7c..235c602 100644
--- a/include/wd_dh.h
+++ b/include/wd_dh.h
@@ -27,6 +27,8 @@ struct wd_dh_sess_setup {
__u16 key_bits; /* DH key bites */
bool is_g2; /* is g2 mode or not */
void *sched_param;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
struct wd_dh_req {
diff --git a/include/wd_ecc.h b/include/wd_ecc.h
index 6f670e2..18c1c0d 100644
--- a/include/wd_ecc.h
+++ b/include/wd_ecc.h
@@ -116,6 +116,8 @@ struct wd_ecc_sess_setup {
struct wd_rand_mt rand; /* rand method from user */
struct wd_hash_mt hash; /* hash method from user */
void *sched_param;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
struct wd_ecc_req {
diff --git a/include/wd_rsa.h b/include/wd_rsa.h
index 2f4e589..9c91432 100644
--- a/include/wd_rsa.h
+++ b/include/wd_rsa.h
@@ -60,6 +60,8 @@ struct wd_rsa_sess_setup {
__u16 key_bits; /* RSA key bits */
bool is_crt; /* CRT mode or not */
void *sched_param;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
bool wd_rsa_is_crt(handle_t sess);
diff --git a/wd_dh.c b/wd_dh.c
index 221322f..0c1372c 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -26,6 +26,8 @@ struct wd_dh_sess {
struct wd_dtb g;
struct wd_dh_sess_setup setup;
void *sched_key;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
static struct wd_dh_setting {
@@ -326,6 +328,8 @@ static int fill_dh_msg(struct wd_dh_msg *msg, struct wd_dh_req *req,
memcpy(&msg->req, req, sizeof(*req));
msg->result = WD_EINVAL;
msg->key_bytes = sess->key_size;
+ msg->mm_ops = &sess->mm_ops;
+ msg->mm_type = sess->mm_type;
if (unlikely(req->pri_bytes < sess->key_size)) {
WD_ERR("invalid: req pri bytes %hu is error!\n", req->pri_bytes);
@@ -581,6 +585,7 @@ void wd_dh_get_g(handle_t sess, struct wd_dtb **g)
handle_t wd_dh_alloc_sess(struct wd_dh_sess_setup *setup)
{
struct wd_dh_sess *sess;
+ int ret;
if (!setup) {
WD_ERR("invalid: alloc dh sess setup NULL!\n");
@@ -606,10 +611,19 @@ handle_t wd_dh_alloc_sess(struct wd_dh_sess_setup *setup)
memcpy(&sess->setup, setup, sizeof(*setup));
sess->key_size = setup->key_bits >> BYTE_BITS_SHIFT;
- sess->g.data = malloc(sess->key_size);
- if (!sess->g.data)
+ ret = wd_mem_ops_init(wd_dh_setting.config.ctxs[0].ctx, &setup->mm_ops, setup->mm_type);
+ if (ret) {
+ WD_ERR("failed to init memory ops!\n");
goto sess_err;
+ }
+ memcpy(&sess->mm_ops, &setup->mm_ops, sizeof(struct wd_mm_ops));
+ sess->mm_type = setup->mm_type;
+ sess->g.data = sess->mm_ops.alloc(sess->mm_ops.usr, sess->key_size);
+ if (!sess->g.data) {
+ WD_ERR("failed to malloc sess g param memory!\n");
+ goto sess_err;
+ }
sess->g.bsize = sess->key_size;
/* Some simple scheduler don't need scheduling parameters */
sess->sched_key = (void *)wd_dh_setting.sched.sched_init(
@@ -622,7 +636,7 @@ handle_t wd_dh_alloc_sess(struct wd_dh_sess_setup *setup)
return (handle_t)sess;
sched_err:
- free(sess->g.data);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->g.data);
sess_err:
free(sess);
return (handle_t)0;
@@ -638,7 +652,7 @@ void wd_dh_free_sess(handle_t sess)
}
if (sess_t->g.data)
- free(sess_t->g.data);
+ sess_t->mm_ops.free(sess_t->mm_ops.usr, sess_t->g.data);
if (sess_t->sched_key)
free(sess_t->sched_key);
diff --git a/wd_ecc.c b/wd_ecc.c
index b1971b9..2c88d0a 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -52,6 +52,8 @@ struct wd_ecc_sess {
struct wd_ecc_sess_setup setup;
struct wd_ecc_extend_ops eops;
void *sched_key;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
struct wd_ecc_curve_list {
@@ -494,7 +496,7 @@ static void release_ecc_prikey(struct wd_ecc_sess *sess)
struct wd_ecc_prikey *prikey = sess->key.prikey;
wd_memset_zero(prikey->data, prikey->size);
- free(prikey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, prikey->data);
free(prikey);
sess->key.prikey = NULL;
}
@@ -503,7 +505,7 @@ static void release_ecc_pubkey(struct wd_ecc_sess *sess)
{
struct wd_ecc_pubkey *pubkey = sess->key.pubkey;
- free(pubkey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, pubkey->data);
free(pubkey);
sess->key.pubkey = NULL;
}
@@ -522,7 +524,7 @@ static struct wd_ecc_prikey *create_ecc_prikey(struct wd_ecc_sess *sess)
}
dsz = ECC_PRIKEY_SZ(hsz);
- data = malloc(dsz);
+ data = sess->mm_ops.alloc(sess->mm_ops.usr, dsz);
if (!data) {
WD_ERR("failed to malloc prikey data, sz = %u!\n", dsz);
free(prikey);
@@ -551,7 +553,7 @@ static struct wd_ecc_pubkey *create_ecc_pubkey(struct wd_ecc_sess *sess)
}
dsz = ECC_PUBKEY_SZ(hsz);
- data = malloc(dsz);
+ data = sess->mm_ops.alloc(sess->mm_ops.usr, dsz);
if (!data) {
WD_ERR("failed to malloc pubkey data, sz = %u!\n", dsz);
free(pubkey);
@@ -570,7 +572,7 @@ static void release_ecc_in(struct wd_ecc_sess *sess,
struct wd_ecc_in *ecc_in)
{
wd_memset_zero(ecc_in->data, ecc_in->size);
- free(ecc_in);
+ sess->mm_ops.free(sess->mm_ops.usr, ecc_in);
}
static struct wd_ecc_in *create_ecc_in(struct wd_ecc_sess *sess, __u32 num)
@@ -585,7 +587,7 @@ static struct wd_ecc_in *create_ecc_in(struct wd_ecc_sess *sess, __u32 num)
hsz = get_key_bsz(sess->key_size);
len = sizeof(struct wd_ecc_in) + hsz * num;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc ecc in, sz = %u!\n", len);
return NULL;
@@ -613,7 +615,7 @@ static struct wd_ecc_in *create_sm2_sign_in(struct wd_ecc_sess *sess,
len = sizeof(struct wd_ecc_in)
+ ECC_SIGN_IN_PARAM_NUM * ksz + m_len;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc sm2 sign in, sz = %llu!\n", len);
return NULL;
@@ -653,7 +655,7 @@ static struct wd_ecc_in *create_sm2_enc_in(struct wd_ecc_sess *sess,
}
len = sizeof(struct wd_ecc_in) + ksz + m_len;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc sm2 enc in, sz = %llu!\n", len);
return NULL;
@@ -697,7 +699,7 @@ static void *create_sm2_ciphertext(struct wd_ecc_sess *sess, __u32 m_len,
*len = (__u64)st_sz + ECC_POINT_PARAM_NUM * (__u64)sess->key_size +
(__u64)m_len + (__u64)h_byts;
- start = malloc(*len);
+ start = sess->mm_ops.alloc(sess->mm_ops.usr, *len);
if (unlikely(!start)) {
WD_ERR("failed to alloc start, sz = %llu!\n", *len);
return NULL;
@@ -745,7 +747,7 @@ static struct wd_ecc_out *create_ecc_out(struct wd_ecc_sess *sess, __u32 num)
hsz = get_key_bsz(sess->key_size);
len = sizeof(struct wd_ecc_out) + hsz * num;
- out = malloc(len);
+ out = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!out) {
WD_ERR("failed to malloc out, sz = %u!\n", len);
return NULL;
@@ -1149,13 +1151,13 @@ static void del_sess_key(struct wd_ecc_sess *sess)
{
if (sess->key.prikey) {
wd_memset_zero(sess->key.prikey->data, sess->key.prikey->size);
- free(sess->key.prikey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->key.prikey->data);
free(sess->key.prikey);
sess->key.prikey = NULL;
}
if (sess->key.pubkey) {
- free(sess->key.pubkey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->key.pubkey->data);
free(sess->key.pubkey);
sess->key.pubkey = NULL;
}
@@ -1227,6 +1229,15 @@ handle_t wd_ecc_alloc_sess(struct wd_ecc_sess_setup *setup)
memcpy(&sess->setup, setup, sizeof(*setup));
sess->key_size = BITS_TO_BYTES(setup->key_bits);
+ /* Memory type set */
+ ret = wd_mem_ops_init(wd_ecc_setting.config.ctxs[0].ctx, &setup->mm_ops, setup->mm_type);
+ if (ret) {
+ WD_ERR("failed to init memory ops!\n");
+ goto sess_err;
+ }
+ memcpy(&sess->mm_ops, &setup->mm_ops, sizeof(struct wd_mm_ops));
+ sess->mm_type = setup->mm_type;
+
if (wd_ecc_setting.driver->get_extend_ops) {
ret = wd_ecc_setting.driver->get_extend_ops(&sess->eops);
if (ret) {
@@ -1508,9 +1519,10 @@ void wd_ecxdh_get_out_params(struct wd_ecc_out *out, struct wd_ecc_point **pbk)
void wd_ecc_del_in(handle_t sess, struct wd_ecc_in *in)
{
+ struct wd_ecc_sess *sess_t = (struct wd_ecc_sess *)sess;
__u32 bsz;
- if (!in) {
+ if (!sess_t || !in) {
WD_ERR("invalid: del ecc in parameter error!\n");
return;
}
@@ -1522,14 +1534,15 @@ void wd_ecc_del_in(handle_t sess, struct wd_ecc_in *in)
}
wd_memset_zero(in->data, bsz);
- free(in);
+ sess_t->mm_ops.free(sess_t->mm_ops.usr, in);
}
-void wd_ecc_del_out(handle_t sess, struct wd_ecc_out *out)
+void wd_ecc_del_out(handle_t sess, struct wd_ecc_out *out)
{
+ struct wd_ecc_sess *sess_t = (struct wd_ecc_sess *)sess;
__u32 bsz;
- if (!out) {
+ if (!sess_t || !out) {
WD_ERR("invalid: del ecc out parameter error!\n");
return;
}
@@ -1541,7 +1554,7 @@ void wd_ecc_del_out(handle_t sess, struct wd_ecc_out *out)
}
wd_memset_zero(out->data, bsz);
- free(out);
+ sess_t->mm_ops.free(sess_t->mm_ops.usr, out);
}
static int fill_ecc_msg(struct wd_ecc_msg *msg, struct wd_ecc_req *req,
@@ -1551,6 +1564,8 @@ static int fill_ecc_msg(struct wd_ecc_msg *msg, struct wd_ecc_req *req,
memcpy(&msg->req, req, sizeof(msg->req));
memcpy(&msg->hash, &sess->setup.hash, sizeof(msg->hash));
+ msg->mm_ops = &sess->mm_ops;
+ msg->mm_type = sess->mm_type;
msg->key_bytes = sess->key_size;
msg->curve_id = sess->setup.cv.cfg.id;
msg->drv_cfg = sess->eops.params;
@@ -1922,7 +1937,7 @@ static struct wd_ecc_in *create_sm2_verf_in(struct wd_ecc_sess *sess,
hsz = get_key_bsz(sess->key_size);
len = sizeof(struct wd_ecc_in) + ECC_VERF_IN_PARAM_NUM * hsz +
m_len;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc sm2 verf in, sz = %llu!\n", len);
return NULL;
@@ -2211,7 +2226,7 @@ struct wd_ecc_out *wd_sm2_new_dec_out(handle_t sess, __u32 plaintext_len)
}
len = sizeof(*ecc_out) + plaintext_len;
- ecc_out = malloc(len);
+ ecc_out = sess_t->mm_ops.alloc(sess_t->mm_ops.usr, len);
if (!ecc_out) {
WD_ERR("failed to malloc ecc_out, sz = %llu!\n", len);
return NULL;
diff --git a/wd_rsa.c b/wd_rsa.c
index cf9239c..bc78c6a 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -67,6 +67,8 @@ struct wd_rsa_sess {
struct wd_rsa_prikey *prikey;
struct wd_rsa_sess_setup setup;
void *sched_key;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
static struct wd_rsa_setting {
@@ -373,6 +375,8 @@ static int fill_rsa_msg(struct wd_rsa_msg *msg, struct wd_rsa_req *req,
memcpy(&msg->req, req, sizeof(*req));
msg->key_bytes = sess->key_size;
msg->result = WD_EINVAL;
+ msg->mm_ops = &sess->mm_ops;
+ msg->mm_type = sess->mm_type;
switch (msg->req.op_type) {
case WD_RSA_SIGN:
@@ -641,7 +645,7 @@ struct wd_rsa_kg_in *wd_rsa_new_kg_in(handle_t sess, struct wd_dtb *e,
}
kg_in_size = (int)GEN_PARAMS_SZ(c->key_size);
- kg_in = malloc(kg_in_size + sizeof(*kg_in));
+ kg_in = c->mm_ops.alloc(c->mm_ops.usr, kg_in_size + sizeof(*kg_in));
if (!kg_in) {
WD_ERR("failed to malloc kg_in memory!\n");
return NULL;
@@ -681,19 +685,16 @@ void wd_rsa_get_kg_in_params(struct wd_rsa_kg_in *kin, struct wd_dtb *e,
p->data = (void *)kin->p;
}
-static void del_kg(void *k)
+void wd_rsa_del_kg_in(handle_t sess, struct wd_rsa_kg_in *ki)
{
- if (!k) {
+ struct wd_rsa_sess *c = (struct wd_rsa_sess *)sess;
+
+ if (!c || !ki) {
WD_ERR("invalid: del key generate params err!\n");
return;
}
- free(k);
-}
-
-void wd_rsa_del_kg_in(handle_t sess, struct wd_rsa_kg_in *ki)
-{
- del_kg(ki);
+ c->mm_ops.free(c->mm_ops.usr, ki);
}
struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess)
@@ -719,7 +720,7 @@ struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess)
else
kg_out_size = (int)GEN_PARAMS_SZ(c->key_size);
- kg_out = malloc(kg_out_size + sizeof(*kg_out));
+ kg_out = c->mm_ops.alloc(c->mm_ops.usr, kg_out_size + sizeof(*kg_out));
if (!kg_out) {
WD_ERR("failed to malloc kg_out memory!\n");
return NULL;
@@ -741,13 +742,15 @@ struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess)
void wd_rsa_del_kg_out(handle_t sess, struct wd_rsa_kg_out *kout)
{
- if (!kout) {
+ struct wd_rsa_sess *c = (struct wd_rsa_sess *)sess;
+
+ if (!c || !kout) {
WD_ERR("invalid: param null at del kg out!\n");
return;
}
wd_memset_zero(kout->data, kout->size);
- del_kg(kout);
+ c->mm_ops.free(c->mm_ops.usr, kout);
}
void wd_rsa_get_kg_out_params(struct wd_rsa_kg_out *kout, struct wd_dtb *d,
@@ -804,6 +807,11 @@ void wd_rsa_set_kg_out_crt_psz(struct wd_rsa_kg_out *kout,
size_t dq_sz,
size_t dp_sz)
{
+ if (!kout) {
+ WD_ERR("invalid: input null when set kg out crt psz!\n");
+ return;
+ }
+
kout->qinvbytes = qinv_sz;
kout->dqbytes = dq_sz;
kout->dpbytes = dp_sz;
@@ -813,6 +821,11 @@ void wd_rsa_set_kg_out_psz(struct wd_rsa_kg_out *kout,
size_t d_sz,
size_t n_sz)
{
+ if (!kout) {
+ WD_ERR("invalid: input null when set kg out psz!\n");
+ return;
+ }
+
kout->dbytes = d_sz;
kout->nbytes = n_sz;
}
@@ -862,7 +875,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup,
if (setup->is_crt) {
len = sizeof(struct wd_rsa_prikey) +
(int)CRT_PARAMS_SZ(sess->key_size);
- sess->prikey = malloc(len);
+ sess->prikey = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!sess->prikey) {
WD_ERR("failed to alloc sess prikey2!\n");
return -WD_ENOMEM;
@@ -873,7 +886,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup,
} else {
len = sizeof(struct wd_rsa_prikey) +
(int)GEN_PARAMS_SZ(sess->key_size);
- sess->prikey = malloc(len);
+ sess->prikey = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!sess->prikey) {
WD_ERR("failed to alloc sess prikey1!\n");
return -WD_ENOMEM;
@@ -885,7 +898,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup,
len = sizeof(struct wd_rsa_pubkey) +
(int)GEN_PARAMS_SZ(sess->key_size);
- sess->pubkey = malloc(len);
+ sess->pubkey = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!sess->pubkey) {
free(sess->prikey);
WD_ERR("failed to alloc sess pubkey!\n");
@@ -912,8 +925,8 @@ static void del_sess_key(struct wd_rsa_sess *sess)
wd_memset_zero(prk->pkey.pkey2.data, CRT_PARAMS_SZ(sess->key_size));
else
wd_memset_zero(prk->pkey.pkey1.data, GEN_PARAMS_SZ(sess->key_size));
- free(sess->prikey);
- free(sess->pubkey);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->prikey);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->pubkey);
}
static void del_sess(struct wd_rsa_sess *c)
@@ -948,6 +961,15 @@ handle_t wd_rsa_alloc_sess(struct wd_rsa_sess_setup *setup)
memcpy(&sess->setup, setup, sizeof(*setup));
sess->key_size = setup->key_bits >> BYTE_BITS_SHIFT;
+ /* Memory type set */
+ ret = wd_mem_ops_init(wd_rsa_setting.config.ctxs[0].ctx, &setup->mm_ops, setup->mm_type);
+ if (ret) {
+ WD_ERR("failed to init memory ops!\n");
+ goto sess_err;
+ }
+
+ memcpy(&sess->mm_ops, &setup->mm_ops, sizeof(struct wd_mm_ops));
+ sess->mm_type = setup->mm_type;
ret = create_sess_key(setup, sess);
if (ret) {
WD_ERR("failed to create rsa sess keys!\n");
--
2.33.0
1
0
From: Wenkai Lin <linwenkai6(a)hisilicon.com>
Extract a common function fill_hashagg_data_info.
Signed-off-by: Wenkai Lin <linwenkai6(a)hisilicon.com>
Signed-off-by: Zongyu Wu <wuzongyu1(a)huawei.com>
---
drv/hisi_dae.c | 56 +++++++++++++++++++-------------------------------
1 file changed, 21 insertions(+), 35 deletions(-)
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index 4f4d13c..49387aa 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -26,7 +26,7 @@
#define DAE_VCHAR_OFFSET_SIZE 2
#define DAE_COL_BIT_NUM 4
#define DAE_AGG_START_COL 16
-#define DAE_HASHAGG_MAX_ROW_NUN 50000
+#define DAE_HASHAGG_MAX_ROW_NUM 50000
/* align size */
#define DAE_CHAR_ALIGN_SIZE 4
@@ -294,23 +294,8 @@ static void fill_hashagg_merge_key_data(struct dae_sqe *sqe, struct dae_ext_sqe
}
}
-static void fill_hashagg_normal_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
- struct hashagg_col_data *cols_data, __u32 agg_cols_num)
-{
- struct hw_agg_data *agg_data = cols_data->input_data;
- __u32 i;
-
- for (i = 0; i < agg_cols_num; i++) {
- sqe->agg_data_type[i] = agg_data[i].hw_type;
- sqe->agg_data_type[i] |= agg_data[i].sum_outtype << DAE_COL_BIT_NUM;
- ext_sqe->agg_data_info[i] = agg_data[i].data_info;
- }
-
- sqe->agg_col_bitmap = GENMASK(agg_cols_num + DAE_AGG_START_COL - 1, DAE_AGG_START_COL);
-}
-
-static void fill_hashagg_rehash_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
- struct hw_agg_data *agg_data, __u32 agg_cols_num)
+static void fill_hashagg_data_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
+ struct hw_agg_data *agg_data, __u32 agg_cols_num)
{
__u32 i;
@@ -344,14 +329,14 @@ static void fill_hashagg_input_data(struct dae_sqe *sqe, struct dae_ext_sqe *ext
hw_agg_addr = &addr_list->input_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.agg_cols;
agg_col_num = msg->agg_cols_num;
- fill_hashagg_normal_info(sqe, ext_sqe, cols_data, agg_col_num);
+ fill_hashagg_data_info(sqe, ext_sqe, agg_data, agg_col_num);
break;
case WD_AGG_REHASH_INPUT:
agg_data = cols_data->output_data;
hw_agg_addr = &addr_list->input_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.agg_cols;
agg_col_num = cols_data->output_num;
- fill_hashagg_rehash_info(sqe, ext_sqe, agg_data, agg_col_num);
+ fill_hashagg_data_info(sqe, ext_sqe, agg_data, agg_col_num);
break;
case WD_AGG_STREAM_OUTPUT:
case WD_AGG_REHASH_OUTPUT:
@@ -359,7 +344,7 @@ static void fill_hashagg_input_data(struct dae_sqe *sqe, struct dae_ext_sqe *ext
hw_agg_addr = &addr_list->output_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.out_agg_cols;
agg_col_num = cols_data->output_num;
- fill_hashagg_normal_info(sqe, ext_sqe, cols_data, cols_data->input_num);
+ fill_hashagg_data_info(sqe, ext_sqe, cols_data->input_data, cols_data->input_num);
break;
}
@@ -385,7 +370,7 @@ static void fill_hashagg_merge_input_data(struct dae_sqe *sqe, struct dae_ext_sq
struct hashagg_ctx *agg_ctx = msg->priv;
struct hashagg_col_data *cols_data = &agg_ctx->cols_data;
- fill_hashagg_rehash_info(sqe, ext_sqe, cols_data->output_data, msg->agg_cols_num);
+ fill_hashagg_data_info(sqe, ext_sqe, cols_data->output_data, msg->agg_cols_num);
}
static void fill_hashagg_ext_addr(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
@@ -422,26 +407,15 @@ static void fill_hashagg_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
static int check_hashagg_param(struct wd_agg_msg *msg)
{
- struct hashagg_col_data *cols_data;
- struct hashagg_ctx *agg_ctx;
-
if (!msg) {
WD_ERR("invalid: input hashagg msg is NULL!\n");
return -WD_EINVAL;
}
- agg_ctx = msg->priv;
- cols_data = &agg_ctx->cols_data;
- if (cols_data->output_num > DAE_MAX_OUTPUT_COLS) {
- WD_ERR("invalid: input hashagg output num %u is more than %d!\n",
- cols_data->output_num, DAE_MAX_OUTPUT_COLS);
- return -WD_EINVAL;
- }
-
if ((msg->pos == WD_AGG_STREAM_INPUT || msg->pos == WD_AGG_REHASH_INPUT) &&
- msg->row_count > DAE_HASHAGG_MAX_ROW_NUN) {
+ msg->row_count > DAE_HASHAGG_MAX_ROW_NUM) {
WD_ERR("invalid: input hashagg row count %u is more than %d!\n",
- msg->row_count, DAE_HASHAGG_MAX_ROW_NUN);
+ msg->row_count, DAE_HASHAGG_MAX_ROW_NUM);
return -WD_EINVAL;
}
@@ -1005,6 +979,7 @@ static int transfer_input_col_info(struct wd_agg_col_info *agg_cols,
struct hw_agg_data *user_output_data,
__u32 cols_num, __u32 *output_num)
{
+ __u32 tmp = *output_num;
__u32 i, j, k = 0;
int ret;
@@ -1013,7 +988,15 @@ static int transfer_input_col_info(struct wd_agg_col_info *agg_cols,
WD_ERR("invalid: col alg num(%u) more than 2!\n", agg_cols[i].col_alg_num);
return -WD_EINVAL;
}
+ tmp += agg_cols[i].col_alg_num;
+ }
+ if (tmp > DAE_MAX_OUTPUT_COLS) {
+ WD_ERR("invalid: output col num is more than %d!\n", DAE_MAX_OUTPUT_COLS);
+ return -WD_EINVAL;
+ }
+
+ for (i = 0; i < cols_num; i++) {
for (j = 0; j < agg_cols[i].col_alg_num; j++) {
ret = hashagg_check_input_data(&agg_cols[i], &user_input_data[i],
&user_output_data[k], j);
@@ -1137,6 +1120,9 @@ static int transfer_data_to_hw_type(struct hashagg_col_data *cols_data,
struct wd_agg_col_info *agg_cols = setup->agg_cols_info;
int ret;
+ if (setup->is_count_all)
+ cols_data->output_num++;
+
ret = transfer_input_col_info(agg_cols, user_input_data, user_output_data,
setup->agg_cols_num, &cols_data->output_num);
if (ret)
--
2.33.0
1
0
From: Wenkai Lin <linwenkai6(a)hisilicon.com>
Extract a common function fill_hashagg_data_info.
Signed-off-by: Wenkai Lin <linwenkai6(a)hisilicon.com>
Signed-off-by: Zongyu Wu <wuzongyu1(a)huawei.com>
---
drv/hisi_dae.c | 56 +++++++++++++++++++-------------------------------
1 file changed, 21 insertions(+), 35 deletions(-)
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index 4f4d13c..49387aa 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -26,7 +26,7 @@
#define DAE_VCHAR_OFFSET_SIZE 2
#define DAE_COL_BIT_NUM 4
#define DAE_AGG_START_COL 16
-#define DAE_HASHAGG_MAX_ROW_NUN 50000
+#define DAE_HASHAGG_MAX_ROW_NUM 50000
/* align size */
#define DAE_CHAR_ALIGN_SIZE 4
@@ -294,23 +294,8 @@ static void fill_hashagg_merge_key_data(struct dae_sqe *sqe, struct dae_ext_sqe
}
}
-static void fill_hashagg_normal_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
- struct hashagg_col_data *cols_data, __u32 agg_cols_num)
-{
- struct hw_agg_data *agg_data = cols_data->input_data;
- __u32 i;
-
- for (i = 0; i < agg_cols_num; i++) {
- sqe->agg_data_type[i] = agg_data[i].hw_type;
- sqe->agg_data_type[i] |= agg_data[i].sum_outtype << DAE_COL_BIT_NUM;
- ext_sqe->agg_data_info[i] = agg_data[i].data_info;
- }
-
- sqe->agg_col_bitmap = GENMASK(agg_cols_num + DAE_AGG_START_COL - 1, DAE_AGG_START_COL);
-}
-
-static void fill_hashagg_rehash_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
- struct hw_agg_data *agg_data, __u32 agg_cols_num)
+static void fill_hashagg_data_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
+ struct hw_agg_data *agg_data, __u32 agg_cols_num)
{
__u32 i;
@@ -344,14 +329,14 @@ static void fill_hashagg_input_data(struct dae_sqe *sqe, struct dae_ext_sqe *ext
hw_agg_addr = &addr_list->input_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.agg_cols;
agg_col_num = msg->agg_cols_num;
- fill_hashagg_normal_info(sqe, ext_sqe, cols_data, agg_col_num);
+ fill_hashagg_data_info(sqe, ext_sqe, agg_data, agg_col_num);
break;
case WD_AGG_REHASH_INPUT:
agg_data = cols_data->output_data;
hw_agg_addr = &addr_list->input_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.agg_cols;
agg_col_num = cols_data->output_num;
- fill_hashagg_rehash_info(sqe, ext_sqe, agg_data, agg_col_num);
+ fill_hashagg_data_info(sqe, ext_sqe, agg_data, agg_col_num);
break;
case WD_AGG_STREAM_OUTPUT:
case WD_AGG_REHASH_OUTPUT:
@@ -359,7 +344,7 @@ static void fill_hashagg_input_data(struct dae_sqe *sqe, struct dae_ext_sqe *ext
hw_agg_addr = &addr_list->output_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.out_agg_cols;
agg_col_num = cols_data->output_num;
- fill_hashagg_normal_info(sqe, ext_sqe, cols_data, cols_data->input_num);
+ fill_hashagg_data_info(sqe, ext_sqe, cols_data->input_data, cols_data->input_num);
break;
}
@@ -385,7 +370,7 @@ static void fill_hashagg_merge_input_data(struct dae_sqe *sqe, struct dae_ext_sq
struct hashagg_ctx *agg_ctx = msg->priv;
struct hashagg_col_data *cols_data = &agg_ctx->cols_data;
- fill_hashagg_rehash_info(sqe, ext_sqe, cols_data->output_data, msg->agg_cols_num);
+ fill_hashagg_data_info(sqe, ext_sqe, cols_data->output_data, msg->agg_cols_num);
}
static void fill_hashagg_ext_addr(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
@@ -422,26 +407,15 @@ static void fill_hashagg_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
static int check_hashagg_param(struct wd_agg_msg *msg)
{
- struct hashagg_col_data *cols_data;
- struct hashagg_ctx *agg_ctx;
-
if (!msg) {
WD_ERR("invalid: input hashagg msg is NULL!\n");
return -WD_EINVAL;
}
- agg_ctx = msg->priv;
- cols_data = &agg_ctx->cols_data;
- if (cols_data->output_num > DAE_MAX_OUTPUT_COLS) {
- WD_ERR("invalid: input hashagg output num %u is more than %d!\n",
- cols_data->output_num, DAE_MAX_OUTPUT_COLS);
- return -WD_EINVAL;
- }
-
if ((msg->pos == WD_AGG_STREAM_INPUT || msg->pos == WD_AGG_REHASH_INPUT) &&
- msg->row_count > DAE_HASHAGG_MAX_ROW_NUN) {
+ msg->row_count > DAE_HASHAGG_MAX_ROW_NUM) {
WD_ERR("invalid: input hashagg row count %u is more than %d!\n",
- msg->row_count, DAE_HASHAGG_MAX_ROW_NUN);
+ msg->row_count, DAE_HASHAGG_MAX_ROW_NUM);
return -WD_EINVAL;
}
@@ -1005,6 +979,7 @@ static int transfer_input_col_info(struct wd_agg_col_info *agg_cols,
struct hw_agg_data *user_output_data,
__u32 cols_num, __u32 *output_num)
{
+ __u32 tmp = *output_num;
__u32 i, j, k = 0;
int ret;
@@ -1013,7 +988,15 @@ static int transfer_input_col_info(struct wd_agg_col_info *agg_cols,
WD_ERR("invalid: col alg num(%u) more than 2!\n", agg_cols[i].col_alg_num);
return -WD_EINVAL;
}
+ tmp += agg_cols[i].col_alg_num;
+ }
+ if (tmp > DAE_MAX_OUTPUT_COLS) {
+ WD_ERR("invalid: output col num is more than %d!\n", DAE_MAX_OUTPUT_COLS);
+ return -WD_EINVAL;
+ }
+
+ for (i = 0; i < cols_num; i++) {
for (j = 0; j < agg_cols[i].col_alg_num; j++) {
ret = hashagg_check_input_data(&agg_cols[i], &user_input_data[i],
&user_output_data[k], j);
@@ -1137,6 +1120,9 @@ static int transfer_data_to_hw_type(struct hashagg_col_data *cols_data,
struct wd_agg_col_info *agg_cols = setup->agg_cols_info;
int ret;
+ if (setup->is_count_all)
+ cols_data->output_num++;
+
ret = transfer_input_col_info(agg_cols, user_input_data, user_output_data,
setup->agg_cols_num, &cols_data->output_num);
if (ret)
--
2.33.0
1
0
18 Nov '25
From: lizhi <lizhi206(a)huawei.com>
The hpre v2 interface needs to support the no-sva business model
within the new evolution framework. This ensures that users
switching to the v2 interface can utilize both the sva mode
and the no-sva mode.
Signed-off-by: lizhi <lizhi206(a)huawei.com>
Signed-off-by: Zongyu Wu <wuzongyu1(a)huawei.com>
---
drv/hisi_comp.c | 3 +-
drv/hisi_hpre.c | 650 ++++++++++++++++++++++++++++-----------
drv/hisi_qm_udrv.c | 15 +-
include/drv/wd_dh_drv.h | 3 +
include/drv/wd_ecc_drv.h | 3 +
include/drv/wd_rsa_drv.h | 3 +
include/wd_dh.h | 2 +
include/wd_ecc.h | 2 +
include/wd_rsa.h | 2 +
wd_dh.c | 22 +-
wd_ecc.c | 53 ++--
wd_rsa.c | 56 +++-
12 files changed, 580 insertions(+), 234 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index 87d2103..8474e17 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -267,7 +267,8 @@ static __u32 copy_to_out(struct wd_comp_msg *msg, struct hisi_comp_buf *buf, __u
struct wd_comp_req *req = &msg->req;
struct wd_datalist *node = req->list_dst;
__u32 sgl_restlen, copy_len;
- __u32 len = 0, sgl_cplen = 0;
+ __u32 sgl_cplen = 0;
+ __u32 len = 0;
copy_len = total_len > req->dst_len ?
req->dst_len : total_len;
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 7ce842b..f3f2451 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -34,14 +34,17 @@
#define SM2_PONIT_SIZE 64
#define MAX_HASH_LENS BITS_TO_BYTES(521)
#define HW_PLAINTEXT_BYTES_MAX BITS_TO_BYTES(4096)
-#define HPRE_CTX_Q_NUM_DEF 1
+#define HPRE_CTX_Q_NUM_DEF 1
+#define MAP_PAIR_NUM_MAX 6
#define CRT_PARAMS_SZ(key_size) ((5 * (key_size)) >> 1)
#define CRT_GEN_PARAMS_SZ(key_size) ((7 * (key_size)) >> 1)
#define GEN_PARAMS_SZ(key_size) ((key_size) << 1)
#define CRT_PARAM_SZ(key_size) ((key_size) >> 1)
-#define WD_TRANS_FAIL 0
+#define GEN_PARAMS_SZ_UL(key_size) ((unsigned long)(key_size) << 1)
+#define DMA_ADDR(hi, lo) ((__u64)(((__u64)(hi) << 32) | (__u64)(lo)))
+#define WD_TRANS_FAIL 0
#define CURVE_PARAM_NUM 6
#define SECP256R1_KEY_SIZE 32
@@ -78,6 +81,21 @@ enum hpre_alg_name {
WD_ECC
};
+enum hpre_hw_msg_field {
+ HW_MSG_IN,
+ HW_MSG_OUT,
+ HW_MSG_KEY,
+};
+
+struct map_info_cache {
+ struct map_pair {
+ void *addr;
+ uintptr_t pa;
+ size_t size;
+ } pairs[MAP_PAIR_NUM_MAX];
+ size_t cnt;
+};
+
/* put vendor hardware message as a user interface is not suitable here */
struct hisi_hpre_sqe {
__u32 alg : 5;
@@ -113,12 +131,122 @@ struct hisi_hpre_sqe {
struct hisi_hpre_ctx {
struct wd_ctx_config_internal config;
+ struct wd_mm_ops *mm_ops;
+ handle_t rsv_mem_ctx;
};
struct hpre_ecc_ctx {
__u32 enable_hpcore;
};
+static void add_map_info(struct map_info_cache *cache, void *addr, uintptr_t dma, size_t size)
+{
+ /* The cnt is guaranteed not to exceed MAP_PAIR_NUM_MAX within hpre. */
+ cache->pairs[cache->cnt].addr = addr;
+ cache->pairs[cache->cnt].pa = dma;
+ cache->pairs[cache->cnt].size = size;
+ cache->cnt++;
+}
+
+static void unmap_addr_in_cache(struct wd_mm_ops *mm_ops, struct map_info_cache *cache)
+{
+ size_t i;
+
+ if (mm_ops->sva_mode)
+ return;
+
+ /* The cnt is guaranteed not to exceed MAP_PAIR_NUM_MAX within hpre. */
+ for (i = 0; i < cache->cnt; i++)
+ mm_ops->iova_unmap(mm_ops->usr, cache->pairs[i].addr,
+ (void *)cache->pairs[i].pa, cache->pairs[i].size);
+}
+
+static void unsetup_hw_msg_addr(struct wd_mm_ops *mm_ops, enum hpre_hw_msg_field t_type,
+ struct hisi_hpre_sqe *hw_msg, void *va, size_t data_sz)
+{
+ void *addr;
+
+ if (!mm_ops || mm_ops->sva_mode || !va || !data_sz)
+ return;
+
+ switch (t_type) {
+ case HW_MSG_KEY:
+ addr = VA_ADDR(hw_msg->hi_key, hw_msg->low_key);
+ break;
+ case HW_MSG_IN:
+ addr = VA_ADDR(hw_msg->hi_in, hw_msg->low_in);
+ break;
+ case HW_MSG_OUT:
+ addr = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
+ break;
+ default:
+ return;
+ }
+
+ if (!addr)
+ return;
+
+ mm_ops->iova_unmap(mm_ops->usr, va, (void *)addr, data_sz);
+}
+
+static uintptr_t select_addr_by_sva_mode(struct wd_mm_ops *mm_ops, void *data,
+ size_t data_sz, struct map_info_cache *cache)
+{
+ uintptr_t addr;
+
+ if (!mm_ops->sva_mode) {
+ addr = (uintptr_t)mm_ops->iova_map(mm_ops->usr, data, data_sz);
+ if (!addr) {
+ WD_ERR("Failed to get mappped DMA address for hardware.\n");
+ return 0;
+ }
+ add_map_info(cache, data, addr, data_sz);
+ } else {
+ addr = (uintptr_t)data;
+ }
+
+ return addr;
+}
+
+static void fill_hw_msg_addr(enum hpre_hw_msg_field t_type, struct hisi_hpre_sqe *hw_msg,
+ uintptr_t addr)
+{
+ switch (t_type) {
+ case HW_MSG_KEY:
+ hw_msg->low_key = LW_U32(addr);
+ hw_msg->hi_key = HI_U32(addr);
+ break;
+ case HW_MSG_IN:
+ hw_msg->low_in = LW_U32(addr);
+ hw_msg->hi_in = HI_U32(addr);
+ break;
+ case HW_MSG_OUT:
+ hw_msg->low_out = LW_U32(addr);
+ hw_msg->hi_out = HI_U32(addr);
+ break;
+ default:
+ return;
+ }
+}
+
+static int check_hpre_mem_params(struct wd_mm_ops *mm_ops, enum wd_mem_type mm_type)
+{
+ if (!mm_ops) {
+ WD_ERR("Memory operation functions are null.\n");
+ return -WD_EINVAL;
+ }
+
+ if (mm_type == UADK_MEM_AUTO && !mm_ops->sva_mode) {
+ WD_ERR("No-SVA in auto mode is not supported yet.\n");
+ return -WD_EINVAL;
+ } else if (mm_type > UADK_MEM_PROXY) {
+ WD_ERR("failed to check memory type.\n");
+ return -WD_EINVAL;
+ }
+
+ return WD_SUCCESS;
+}
+
static void dump_hpre_msg(void *msg, int alg)
{
struct wd_rsa_msg *rsa_msg;
@@ -269,7 +397,8 @@ static int fill_rsa_crt_prikey2(struct wd_rsa_prikey *prikey,
*data = wd_dq->data;
- return WD_SUCCESS;
+ return (int)(wd_dq->bsize + wd_qinv->bsize + wd_p->bsize +
+ wd_q->bsize + wd_dp->bsize);
}
static int fill_rsa_prikey1(struct wd_rsa_prikey *prikey, void **data)
@@ -292,7 +421,7 @@ static int fill_rsa_prikey1(struct wd_rsa_prikey *prikey, void **data)
*data = wd_d->data;
- return WD_SUCCESS;
+ return (int)(wd_n->bsize + wd_d->bsize);
}
static int fill_rsa_pubkey(struct wd_rsa_pubkey *pubkey, void **data)
@@ -315,7 +444,7 @@ static int fill_rsa_pubkey(struct wd_rsa_pubkey *pubkey, void **data)
*data = wd_e->data;
- return WD_SUCCESS;
+ return (int)(wd_n->bsize + wd_e->bsize);
}
static int fill_rsa_genkey_in(struct wd_rsa_kg_in *genkey)
@@ -378,22 +507,21 @@ static int rsa_out_transfer(struct wd_rsa_msg *msg,
{
struct wd_rsa_req *req = &msg->req;
struct wd_rsa_kg_out *key = req->dst;
+ struct wd_rsa_msg *target_msg;
__u16 kbytes = msg->key_bytes;
struct wd_dtb qinv, dq, dp;
struct wd_dtb d, n;
- void *data;
int ret;
- if (hw_msg->alg == HPRE_ALG_KG_CRT || hw_msg->alg == HPRE_ALG_KG_STD) {
- /* async */
- 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 {
- key = req->dst;
- }
+ target_msg = (struct wd_rsa_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct rsa send msg from hardware!\n");
+ return -WD_ADDR_ERR;
}
+ if (hw_msg->alg == HPRE_ALG_KG_CRT || hw_msg->alg == HPRE_ALG_KG_STD)
+ key = target_msg->req.dst;
+
msg->result = WD_SUCCESS;
if (hw_msg->alg == HPRE_ALG_KG_CRT) {
req->dst_bytes = CRT_GEN_PARAMS_SZ(kbytes);
@@ -424,37 +552,38 @@ static int rsa_out_transfer(struct wd_rsa_msg *msg,
return WD_SUCCESS;
}
-static int rsa_prepare_key(struct wd_rsa_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int rsa_prepare_key(struct wd_rsa_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
struct wd_rsa_req *req = &msg->req;
+ uintptr_t addr;
+ int ret, len;
void *data;
- int ret;
if (req->op_type == WD_RSA_SIGN) {
if (hw_msg->alg == HPRE_ALG_NC_CRT) {
- ret = fill_rsa_crt_prikey2((void *)msg->key, &data);
- if (ret)
- return ret;
+ len = fill_rsa_crt_prikey2((void *)msg->key, &data);
+ if (len <= 0)
+ return -WD_EINVAL;
} else {
- ret = fill_rsa_prikey1((void *)msg->key, &data);
- if (ret)
- return ret;
+ len = fill_rsa_prikey1((void *)msg->key, &data);
+ if (len <= 0)
+ return -WD_EINVAL;
hw_msg->alg = HPRE_ALG_NC_NCRT;
}
} else if (req->op_type == WD_RSA_VERIFY) {
- ret = fill_rsa_pubkey((void *)msg->key, &data);
- if (ret)
- return ret;
+ len = fill_rsa_pubkey((void *)msg->key, &data);
+ if (len <= 0)
+ return -WD_EINVAL;
hw_msg->alg = HPRE_ALG_NC_NCRT;
} else if (req->op_type == WD_RSA_GENKEY) {
ret = fill_rsa_genkey_in((void *)msg->key);
if (ret)
return ret;
- ret = wd_rsa_kg_in_data((void *)msg->key, (char **)&data);
- if (ret < 0) {
+ len = wd_rsa_kg_in_data((void *)msg->key, (char **)&data);
+ if (len < 0) {
WD_ERR("failed to get rsa gen key data!\n");
- return ret;
+ return -WD_EINVAL;
}
if (hw_msg->alg == HPRE_ALG_NC_CRT)
hw_msg->alg = HPRE_ALG_KG_CRT;
@@ -465,36 +594,53 @@ static int rsa_prepare_key(struct wd_rsa_msg *msg,
return -WD_EINVAL;
}
- hw_msg->low_key = LW_U32((uintptr_t)data);
- hw_msg->hi_key = HI_U32((uintptr_t)data);
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, len, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_KEY, hw_msg, addr);
- return WD_SUCCESS;
+ return ret;
}
-static int rsa_prepare_iot(struct wd_rsa_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int rsa_prepare_iot(struct wd_rsa_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
struct wd_rsa_req *req = &msg->req;
struct wd_rsa_kg_out *kout = req->dst;
int ret = WD_SUCCESS;
- void *out = NULL;
+ uintptr_t phy, out;
if (req->op_type != WD_RSA_GENKEY) {
- hw_msg->low_in = LW_U32((uintptr_t)req->src);
- hw_msg->hi_in = HI_U32((uintptr_t)req->src);
- out = req->dst;
+ phy = select_addr_by_sva_mode(msg->mm_ops, req->src, req->src_bytes, cache);
+ if (!phy)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_IN, hw_msg, phy);
+ phy = select_addr_by_sva_mode(msg->mm_ops, req->dst, req->dst_bytes, cache);
+ if (!phy)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_OUT, hw_msg, phy);
} else {
hw_msg->low_in = 0;
hw_msg->hi_in = 0;
ret = wd_rsa_kg_out_data(kout, (char **)&out);
if (ret < 0)
return ret;
- }
- hw_msg->low_out = LW_U32((uintptr_t)out);
- hw_msg->hi_out = HI_U32((uintptr_t)out);
+ if (!msg->mm_ops->sva_mode) {
+ phy = (uintptr_t)msg->mm_ops->iova_map(msg->mm_ops->usr, kout, ret);
+ if (!phy) {
+ WD_ERR("Failed to get DMA address for rsa output!\n");
+ return -WD_ENOMEM;
+ }
+ add_map_info(cache, kout, phy, ret);
+ out = phy + out - (uintptr_t)kout;
+ }
+
+ hw_msg->low_out = LW_U32(out);
+ hw_msg->hi_out = HI_U32(out);
+ }
- return ret;
+ return WD_SUCCESS;
}
static int hpre_init_qm_priv(struct wd_ctx_config_internal *config,
@@ -615,10 +761,17 @@ static int rsa_send(struct wd_alg_driver *drv, 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 map_info_cache cache = {0};
struct hisi_hpre_sqe hw_msg;
__u16 send_cnt = 0;
int ret;
+ ret = check_hpre_mem_params(msg->mm_ops, msg->mm_type);
+ if (ret) {
+ WD_ERR("rsa memory parmas is err, and ret is %d!\n", ret);
+ return ret;
+ }
+
memset(&hw_msg, 0, sizeof(struct hisi_hpre_sqe));
if (msg->key_type == WD_RSA_PRIKEY1 ||
@@ -631,21 +784,30 @@ static int rsa_send(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
hw_msg.task_len1 = msg->key_bytes / BYTE_BITS - 0x1;
- ret = rsa_prepare_key(msg, &hw_msg);
- if (ret < 0)
- return ret;
+ ret = rsa_prepare_key(msg, &hw_msg, &cache);
+ if (ret)
+ goto rsa_fail;
/* prepare in/out put */
- ret = rsa_prepare_iot(msg, &hw_msg);
- if (ret < 0)
- return ret;
+ ret = rsa_prepare_iot(msg, &hw_msg, &cache);
+ if (ret)
+ goto rsa_fail;
hisi_set_msg_id(h_qp, &msg->tag);
hw_msg.done = 0x1;
hw_msg.etype = 0x0;
- hw_msg.low_tag = msg->tag;
+ hw_msg.low_tag = LW_U32((uintptr_t)msg);
+ hw_msg.hi_tag = HI_U32((uintptr_t)msg);
- return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ ret = hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ if (unlikely(ret))
+ goto rsa_fail;
+
+ return ret;
+
+rsa_fail:
+ unmap_addr_in_cache(msg->mm_ops, &cache);
+ return ret;
}
static void hpre_result_check(struct hisi_hpre_sqe *hw_msg,
@@ -671,32 +833,29 @@ static int rsa_recv(struct wd_alg_driver *drv, 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 *target_msg;
struct wd_rsa_msg *msg = rsa_msg;
- struct wd_rsa_msg *temp_msg;
+ struct hisi_hpre_sqe hw_msg = {0};
+ size_t ilen = 0, olen = 0;
__u16 recv_cnt = 0;
+ __u16 kbytes;
int ret;
ret = hisi_qm_recv(h_qp, &hw_msg, 1, &recv_cnt);
if (ret < 0)
return ret;
- ret = hisi_check_bd_id(h_qp, msg->tag, hw_msg.low_tag);
+ target_msg = (struct wd_rsa_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
+ ret = hisi_check_bd_id(h_qp, msg->tag, target_msg->tag);
if (ret)
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;
- }
-
+ msg->tag = target_msg->tag;
hpre_result_check(&hw_msg, &msg->result);
if (!msg->result) {
ret = rsa_out_transfer(msg, &hw_msg, qp->q_info.qp_mode);
@@ -707,15 +866,36 @@ static int rsa_recv(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
}
if (unlikely(msg->result != WD_SUCCESS))
- dump_hpre_msg(temp_msg, WD_RSA);
+ dump_hpre_msg(target_msg, WD_RSA);
+
+ if (!target_msg->mm_ops->sva_mode) {
+ kbytes = target_msg->key_bytes;
+ if (hw_msg.alg == HPRE_ALG_KG_CRT) {
+ olen = CRT_GEN_PARAMS_SZ(kbytes);
+ ilen = GEN_PARAMS_SZ_UL(kbytes);
+ } else if (hw_msg.alg == HPRE_ALG_KG_STD) {
+ olen = GEN_PARAMS_SZ_UL(kbytes);
+ ilen = GEN_PARAMS_SZ_UL(kbytes);
+ } else {
+ olen = kbytes;
+ ilen = kbytes;
+ }
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_IN, &hw_msg,
+ target_msg->req.src, ilen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_OUT, &hw_msg,
+ target_msg->req.dst, olen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_KEY, &hw_msg,
+ target_msg->key, target_msg->key_bytes);
+ }
return WD_SUCCESS;
}
-static int fill_dh_xp_params(struct wd_dh_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int fill_dh_xp_params(struct wd_dh_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
struct wd_dh_req *req = &msg->req;
+ uintptr_t addr;
void *x, *p;
int ret;
@@ -735,26 +915,30 @@ static int fill_dh_xp_params(struct wd_dh_msg *msg,
return ret;
}
- hw_msg->low_key = LW_U32((uintptr_t)x);
- hw_msg->hi_key = HI_U32((uintptr_t)x);
+ addr = select_addr_by_sva_mode(msg->mm_ops, x, GEN_PARAMS_SZ_UL(msg->key_bytes), cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_KEY, hw_msg, addr);
- return WD_SUCCESS;
+ return ret;
}
-static int dh_out_transfer(struct wd_dh_msg *msg,
- struct hisi_hpre_sqe *hw_msg, __u8 qp_mode)
+static int dh_out_transfer(struct wd_dh_msg *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;
+ struct wd_dh_msg *target_msg;
void *out;
int ret;
- /* async */
- if (qp_mode == CTX_MODE_ASYNC)
- out = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
- else
- out = req->pri;
+ target_msg = (struct wd_dh_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+ out = target_msg->req.pri;
ret = hpre_bin_to_crypto_bin((char *)out,
(const char *)out, key_bytes, "dh out");
if (!ret)
@@ -768,12 +952,20 @@ static int dh_out_transfer(struct wd_dh_msg *msg,
static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct map_info_cache cache = {0};
struct wd_dh_msg *msg = dh_msg;
struct wd_dh_req *req = &msg->req;
struct hisi_hpre_sqe hw_msg;
__u16 send_cnt = 0;
+ uintptr_t addr;
int ret;
+ ret = check_hpre_mem_params(msg->mm_ops, msg->mm_type);
+ if (ret) {
+ WD_ERR("dh memory parmas is err, and ret is %d!\n", ret);
+ return ret;
+ }
+
memset(&hw_msg, 0, sizeof(struct hisi_hpre_sqe));
if (msg->is_g2 && req->op_type != WD_DH_PHASE2)
@@ -791,32 +983,50 @@ static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
WD_ERR("failed to transfer dh g para format to hpre bin!\n");
return ret;
}
-
- hw_msg.low_in = LW_U32((uintptr_t)msg->g);
- hw_msg.hi_in = HI_U32((uintptr_t)msg->g);
+ addr = select_addr_by_sva_mode(msg->mm_ops, msg->g, msg->key_bytes, &cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_IN, &hw_msg, addr);
}
- ret = fill_dh_xp_params(msg, &hw_msg);
- if (ret)
- return ret;
+ ret = fill_dh_xp_params(msg, &hw_msg, &cache);
+ if (ret) {
+ WD_ERR("failed to fill dh x or p para!\n");
+ goto dh_fail;
+ }
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;
hw_msg.etype = 0x0;
- hw_msg.low_tag = msg->tag;
- return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ hw_msg.low_tag = LW_U32((uintptr_t)msg);
+ hw_msg.hi_tag = HI_U32((uintptr_t)msg);
+
+ addr = select_addr_by_sva_mode(msg->mm_ops, req->pri, req->pri_bytes, &cache);
+ if (!addr) {
+ ret = -WD_ENOMEM;
+ goto dh_fail;
+ }
+ fill_hw_msg_addr(HW_MSG_OUT, &hw_msg, addr);
+
+ ret = hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ if (unlikely(ret))
+ goto dh_fail;
+
+ return ret;
+
+dh_fail:
+ unmap_addr_in_cache(msg->mm_ops, &cache);
+ return ret;
}
static int dh_recv(struct wd_alg_driver *drv, 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;
+ struct wd_dh_msg *msg = dh_msg;
+ struct wd_dh_msg *target_msg;
__u16 recv_cnt = 0;
int ret;
@@ -824,22 +1034,17 @@ static int dh_recv(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
if (ret < 0)
return ret;
- ret = hisi_check_bd_id(h_qp, msg->tag, hw_msg.low_tag);
+ target_msg = (struct wd_dh_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
+ ret = hisi_check_bd_id(h_qp, msg->tag, target_msg->tag);
if (ret)
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;
- }
-
+ msg->tag = target_msg->tag;
hpre_result_check(&hw_msg, &msg->result);
if (!msg->result) {
ret = dh_out_transfer(msg, &hw_msg, qp->q_info.qp_mode);
@@ -850,7 +1055,16 @@ static int dh_recv(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
}
if (unlikely(msg->result != WD_SUCCESS))
- dump_hpre_msg(temp_msg, WD_DH);
+ dump_hpre_msg(target_msg, WD_DH);
+
+ if (!target_msg->mm_ops->sva_mode) {
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_OUT, &hw_msg,
+ target_msg->req.pri, target_msg->req.pri_bytes);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_KEY, &hw_msg,
+ target_msg->req.x_p, GEN_PARAMS_SZ_UL(target_msg->key_bytes));
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_IN, &hw_msg,
+ target_msg->g, target_msg->key_bytes);
+ }
return WD_SUCCESS;
}
@@ -1081,30 +1295,49 @@ static bool is_prikey_used(__u8 op_type)
op_type == HPRE_SM2_DEC;
}
-static int ecc_prepare_key(struct wd_ecc_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static __u32 ecc_get_prikey_size(struct wd_ecc_msg *msg)
+{
+ if (msg->req.op_type == WD_SM2_SIGN ||
+ msg->req.op_type == WD_ECDSA_SIGN ||
+ msg->req.op_type == WD_SM2_DECRYPT)
+ return ECC_PRIKEY_SZ(msg->key_bytes);
+ else if (msg->curve_id == WD_X25519 ||
+ msg->curve_id == WD_X448)
+ return X_DH_HW_KEY_SZ(msg->key_bytes);
+ else
+ return ECDH_HW_KEY_SZ(msg->key_bytes);
+}
+
+static int ecc_prepare_key(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
void *data = NULL;
+ uintptr_t addr;
+ size_t ksz;
int ret;
if (is_prikey_used(msg->req.op_type)) {
+ ksz = ecc_get_prikey_size(msg);
ret = ecc_prepare_prikey((void *)msg->key, &data, msg->curve_id);
if (ret)
return ret;
} else {
+ ksz = ECC_PUBKEY_SZ(msg->key_bytes);
ret = ecc_prepare_pubkey((void *)msg->key, &data);
if (ret)
return ret;
}
- hw_msg->low_key = LW_U32((uintptr_t)data);
- hw_msg->hi_key = HI_U32((uintptr_t)data);
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, ksz, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_KEY, hw_msg, addr);
- return WD_SUCCESS;
+ return ret;
}
-static void ecc_get_io_len(__u32 atype, __u32 hsz, size_t *ilen,
- size_t *olen)
+static void ecc_get_io_len(__u32 atype, __u32 hsz,
+ size_t *ilen, size_t *olen)
{
if (atype == HPRE_ALG_ECDH_MULTIPLY) {
*olen = ECDH_OUT_PARAMS_SZ(hsz);
@@ -1467,12 +1700,12 @@ static int ecc_prepare_out(struct wd_ecc_msg *msg, void **data)
}
/* prepare in/out hw message */
-static int ecc_prepare_iot(struct wd_ecc_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int ecc_prepare_iot(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
+ size_t i_sz, o_sz;
void *data = NULL;
- size_t i_sz = 0;
- size_t o_sz = 0;
+ uintptr_t addr;
__u16 kbytes;
int ret;
@@ -1483,8 +1716,11 @@ static int ecc_prepare_iot(struct wd_ecc_msg *msg,
WD_ERR("failed to prepare ecc in!\n");
return ret;
}
- hw_msg->low_in = LW_U32((uintptr_t)data);
- hw_msg->hi_in = HI_U32((uintptr_t)data);
+
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, i_sz, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_IN, hw_msg, addr);
ret = ecc_prepare_out(msg, &data);
if (ret) {
@@ -1496,8 +1732,10 @@ static int ecc_prepare_iot(struct wd_ecc_msg *msg,
if (!data)
return WD_SUCCESS;
- hw_msg->low_out = LW_U32((uintptr_t)data);
- hw_msg->hi_out = HI_U32((uintptr_t)data);
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, o_sz, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_OUT, hw_msg, addr);
return WD_SUCCESS;
}
@@ -1613,7 +1851,7 @@ static struct wd_ecc_out *create_ecdh_out(struct wd_ecc_msg *msg)
return NULL;
}
- out = malloc(len);
+ out = msg->mm_ops->alloc(msg->mm_ops->usr, len);
if (!out) {
WD_ERR("failed to alloc out memory, sz = %u!\n", len);
return NULL;
@@ -1677,7 +1915,7 @@ static struct wd_ecc_msg *create_req(struct wd_ecc_msg *src, __u8 req_idx)
prikey = (struct wd_ecc_prikey *)(ecc_key + 1);
ecc_key->prikey = prikey;
- prikey->data = malloc(ECC_PRIKEY_SZ(src->key_bytes));
+ prikey->data = src->mm_ops->alloc(src->mm_ops->usr, ECC_PRIKEY_SZ(src->key_bytes));
if (unlikely(!prikey->data)) {
WD_ERR("failed to alloc prikey data!\n");
goto fail_alloc_key_data;
@@ -1696,7 +1934,7 @@ static struct wd_ecc_msg *create_req(struct wd_ecc_msg *src, __u8 req_idx)
return dst;
fail_set_prikey:
- free(prikey->data);
+ src->mm_ops->free(src->mm_ops->usr, prikey->data);
fail_alloc_key_data:
free(ecc_key);
fail_alloc_key:
@@ -1709,9 +1947,9 @@ static void free_req(struct wd_ecc_msg *msg)
{
struct wd_ecc_key *key = (void *)msg->key;
- free(key->prikey->data);
+ msg->mm_ops->free(msg->mm_ops->usr, key->prikey->data);
free(key);
- free(msg->req.dst);
+ msg->mm_ops->free(msg->mm_ops->usr, msg->req.dst);
free(msg);
}
@@ -1732,7 +1970,8 @@ static int split_req(struct wd_ecc_msg *src, struct wd_ecc_msg **dst)
return WD_SUCCESS;
}
-static int ecc_fill(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
+static int ecc_fill(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
__u32 hw_sz = get_hw_keysz(msg->key_bytes);
__u8 op_type = msg->req.op_type;
@@ -1757,39 +1996,42 @@ static int ecc_fill(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
return ret;
/* prepare key */
- ret = ecc_prepare_key(msg, hw_msg);
+ ret = ecc_prepare_key(msg, hw_msg, cache);
if (ret)
return ret;
/* prepare in/out put */
- ret = ecc_prepare_iot(msg, hw_msg);
+ ret = ecc_prepare_iot(msg, hw_msg, cache);
if (ret)
return ret;
hw_msg->done = 0x1;
hw_msg->etype = 0x0;
- hw_msg->low_tag = msg->tag;
+
+ hw_msg->low_tag = LW_U32((uintptr_t)msg);
+ hw_msg->hi_tag = HI_U32((uintptr_t)msg);
hw_msg->task_len1 = hw_sz / BYTE_BITS - 0x1;
return ret;
}
-static int ecc_general_send(handle_t ctx, struct wd_ecc_msg *msg)
+static int ecc_general_send(handle_t ctx, struct wd_ecc_msg *msg,
+ struct map_info_cache *cache)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_hpre_sqe hw_msg;
__u16 send_cnt = 0;
int ret;
- ret = ecc_fill(msg, &hw_msg);
+ ret = ecc_fill(msg, &hw_msg, cache);
if (ret)
return ret;
return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
}
-
-static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
+static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg,
+ struct map_info_cache *cache)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_sm2_enc_in *ein = msg->req.src;
@@ -1801,7 +2043,7 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
if (ein->plaintext.dsize <= HW_PLAINTEXT_BYTES_MAX &&
hash->type == WD_HASH_SM3)
- return ecc_general_send(ctx, msg);
+ return ecc_general_send(ctx, msg, cache);
if (unlikely(!ein->k_set)) {
WD_ERR("invalid: k not set!\n");
@@ -1824,13 +2066,13 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
return ret;
}
- ret = ecc_fill(msg_dst[0], &hw_msg[0]);
+ ret = ecc_fill(msg_dst[0], &hw_msg[0], cache);
if (unlikely(ret)) {
WD_ERR("failed to fill 1th sqe, ret = %d!\n", ret);
goto fail_fill_sqe;
}
- ret = ecc_fill(msg_dst[1], &hw_msg[1]);
+ ret = ecc_fill(msg_dst[1], &hw_msg[1], cache);
if (unlikely(ret)) {
WD_ERR("failed to fill 2th sqe, ret = %d!\n", ret);
goto fail_fill_sqe;
@@ -1855,7 +2097,8 @@ fail_fill_sqe:
return ret;
}
-static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg)
+static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg,
+ struct map_info_cache *cache)
{
struct wd_sm2_dec_in *din = (void *)msg->req.src;
struct wd_hash_mt *hash = &msg->hash;
@@ -1865,7 +2108,7 @@ static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg)
/* c2 data lens <= 4096 bit */
if (din->c2.dsize <= BITS_TO_BYTES(4096) &&
hash->type == WD_HASH_SM3)
- return ecc_general_send(ctx, msg);
+ return ecc_general_send(ctx, msg, cache);
if (unlikely(!hash->cb || hash->type >= WD_HASH_MAX)) {
WD_ERR("invalid: input hash type %u is error!\n", hash->type);
@@ -1891,14 +2134,14 @@ static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg)
goto free_dst;
}
- ret = ecc_general_send(ctx, dst);
+ ret = ecc_general_send(ctx, dst, cache);
if (unlikely(ret))
goto free_req_dst;
return ret;
free_req_dst:
- free(dst->req.dst);
+ msg->mm_ops->free(msg->mm_ops->usr, dst->req.dst);
free_dst:
free(dst);
return ret;
@@ -1908,14 +2151,37 @@ static int ecc_send(struct wd_alg_driver *drv, 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 map_info_cache cache = {0};
+ int ret;
+
+ ret = check_hpre_mem_params(msg->mm_ops, msg->mm_type);
+ if (ret) {
+ WD_ERR("ecc memory parmas is err, and ret is %d!\n", ret);
+ return ret;
+ }
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)
- return sm2_dec_send(ctx, msg);
+ if (msg->req.op_type == WD_SM2_ENCRYPT) {
+ ret = sm2_enc_send(ctx, msg, &cache);
+ if (ret)
+ goto ecc_fail;
+ return ret;
+ } else if (msg->req.op_type == WD_SM2_DECRYPT) {
+ ret = sm2_dec_send(ctx, msg, &cache);
+ if (ret)
+ goto ecc_fail;
+ return ret;
+ }
- return ecc_general_send(ctx, msg);
+ ret = ecc_general_send(ctx, msg, &cache);
+ if (ret)
+ goto ecc_fail;
+
+ return ret;
+
+ecc_fail:
+ unmap_addr_in_cache(msg->mm_ops, &cache);
+ return ret;
}
static int ecdh_out_transfer(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
@@ -2020,14 +2286,14 @@ 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, __u8 qp_mode)
{
+ struct wd_ecc_msg *target_msg;
int ret = -WD_EINVAL;
- void *va;
+
+ target_msg = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
/* async */
- 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);
- }
+ if (qp_mode == CTX_MODE_ASYNC)
+ msg->req.dst = target_msg->req.dst;
if (hw_msg->alg == HPRE_ALG_SM2_SIGN ||
hw_msg->alg == HPRE_ALG_ECDSA_SIGN)
@@ -2319,19 +2585,16 @@ static int sm2_convert_dec_out(struct wd_ecc_msg *src,
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;
+ struct wd_ecc_msg *target_msg;
+ size_t ilen = 0;
+ size_t olen = 0;
+ __u16 kbytes;
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;
+ target_msg = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct ecc send msg from hardware!\n");
+ return -WD_ADDR_ERR;
}
hpre_result_check(hw_msg, &msg->result);
@@ -2347,10 +2610,20 @@ static int ecc_sqe_parse(struct hisi_qp *qp, struct wd_ecc_msg *msg,
goto dump_err_msg;
}
- return ret;
+ return WD_SUCCESS;
dump_err_msg:
- dump_hpre_msg(temp_msg, WD_ECC);
+ kbytes = target_msg->key_bytes;
+ if (!target_msg->mm_ops->sva_mode) {
+ ecc_get_io_len(hw_msg->alg, kbytes, &ilen, &olen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_OUT, hw_msg,
+ target_msg->req.dst, olen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_KEY, hw_msg,
+ target_msg->key, kbytes);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_IN, hw_msg,
+ target_msg->req.src, ilen);
+ }
+ dump_hpre_msg(target_msg, WD_ECC);
return ret;
}
@@ -2363,8 +2636,6 @@ static int parse_second_sqe(handle_t h_qp,
struct wd_ecc_msg *dst;
__u16 recv_cnt = 0;
int cnt = 0;
- void *data;
- __u32 hsz;
int ret;
while (1) {
@@ -2380,10 +2651,12 @@ static int parse_second_sqe(handle_t h_qp,
break;
}
- data = VA_ADDR(hw_msg.hi_out, hw_msg.low_out);
- hsz = (hw_msg.task_len1 + 1) * BYTE_BITS;
- dst = *(struct wd_ecc_msg **)((uintptr_t)data +
- hsz * ECDH_OUT_PARAM_NUM);
+ dst = (struct wd_ecc_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!dst) {
+ WD_ERR("failed to get correct sm2 enc second send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
ret = ecc_sqe_parse((struct hisi_qp *)h_qp, dst, &hw_msg);
msg->result = dst->result;
*second = dst;
@@ -2394,19 +2667,17 @@ static int parse_second_sqe(handle_t h_qp,
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;
struct wd_ecc_msg *first;
struct wd_ecc_msg src;
- void *data;
- __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 +
- hsz * ECDH_OUT_PARAM_NUM);
+ first = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!first) {
+ WD_ERR("failed to get correct sm2 enc msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
memcpy(&src, first + 1, sizeof(src));
/* parse first sqe */
@@ -2440,17 +2711,15 @@ free_first:
static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
struct hisi_hpre_sqe *hw_msg)
{
- __u16 tag = LW_U16(hw_msg->low_tag);
struct wd_ecc_msg *dst;
struct wd_ecc_msg src;
- void *data;
- __u32 hsz;
int ret;
- data = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
- hsz = (hw_msg->task_len1 + 1) * BYTE_BITS;
- dst = *(struct wd_ecc_msg **)((uintptr_t)data +
- hsz * ECDH_OUT_PARAM_NUM);
+ dst = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!dst) {
+ WD_ERR("failed to get correct sm2 dec msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
memcpy(&src, dst + 1, sizeof(src));
/* parse first sqe */
@@ -2460,7 +2729,6 @@ static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
goto fail;
}
msg->result = dst->result;
- msg->tag = tag;
ret = sm2_convert_dec_out(&src, dst);
if (unlikely(ret)) {
@@ -2469,7 +2737,7 @@ static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
}
fail:
- free(dst->req.dst);
+ dst->mm_ops->free(dst->mm_ops->usr, dst->req.dst);
free(dst);
return ret;
@@ -2479,6 +2747,7 @@ static int ecc_recv(struct wd_alg_driver *drv, 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 wd_ecc_msg *target_msg;
struct hisi_hpre_sqe hw_msg;
__u16 recv_cnt = 0;
int ret;
@@ -2487,10 +2756,17 @@ static int ecc_recv(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
if (ret)
return ret;
- ret = hisi_check_bd_id(h_qp, msg->tag, hw_msg.low_tag);
+ target_msg = (struct wd_ecc_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
+ ret = hisi_check_bd_id(h_qp, msg->tag, target_msg->tag);
if (ret)
return ret;
+ msg->tag = target_msg->tag;
if (hw_msg.alg == HPRE_ALG_ECDH_MULTIPLY &&
hw_msg.sm2_mlen == HPRE_SM2_ENC)
return sm2_enc_parse(h_qp, msg, &hw_msg);
@@ -2549,7 +2825,7 @@ static bool is_valid_hw_type(struct wd_alg_driver *drv)
hpre_ctx = (struct hisi_hpre_ctx *)drv->priv;
qp = (struct hisi_qp *)wd_ctx_get_priv(hpre_ctx->config.ctxs[0].ctx);
- if (qp->q_info.hw_type < HISI_QM_API_VER3_BASE)
+ if (!qp || qp->q_info.hw_type < HISI_QM_API_VER3_BASE)
return false;
return true;
}
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 9251b4c..216b80a 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -473,7 +473,7 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
{
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
struct hisi_qm_queue_info *q_info;
- __u16 free_num, send_num;
+ __u16 free_num;
__u16 tail;
if (unlikely(!qp || !req || !count))
@@ -488,11 +488,14 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
return -WD_EBUSY;
}
- send_num = expect > free_num ? free_num : expect;
+ if (expect > free_num) {
+ pthread_spin_unlock(&q_info->sd_lock);
+ return -WD_EBUSY;
+ }
tail = q_info->sq_tail_index;
- hisi_qm_fill_sqe(req, q_info, tail, send_num);
- tail = (tail + send_num) % q_info->sq_depth;
+ hisi_qm_fill_sqe(req, q_info, tail, expect);
+ tail = (tail + expect) % q_info->sq_depth;
/*
* Before sending doorbell, check the queue status,
@@ -510,9 +513,9 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
q_info->sq_tail_index = tail;
/* Make sure used_num is changed before the next thread gets free sqe. */
- __atomic_add_fetch(&q_info->used_num, send_num, __ATOMIC_RELAXED);
+ __atomic_add_fetch(&q_info->used_num, expect, __ATOMIC_RELAXED);
pthread_spin_unlock(&q_info->sd_lock);
- *count = send_num;
+ *count = expect;
return 0;
}
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
index d205dc4..d2a6157 100644
--- a/include/drv/wd_dh_drv.h
+++ b/include/drv/wd_dh_drv.h
@@ -16,12 +16,15 @@ extern "C" {
/* DH message format */
struct wd_dh_msg {
struct wd_dh_req req;
+ struct wd_mm_ops *mm_ops;
+ enum wd_mem_type mm_type;
__u32 tag; /* User-defined request identifier */
void *g;
__u16 gbytes;
__u16 key_bytes; /* Input key bytes */
__u8 is_g2;
__u8 result; /* Data format, denoted by WD error code */
+ __u8 *rsv_out; /* reserved output data pointer */
};
struct wd_dh_msg *wd_dh_get_msg(__u32 idx, __u32 tag);
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index 6193c8b..b123a9b 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -48,6 +48,8 @@ extern "C" {
/* ECC message format */
struct wd_ecc_msg {
struct wd_ecc_req req;
+ struct wd_mm_ops *mm_ops;
+ enum wd_mem_type mm_type;
struct wd_hash_mt hash;
__u32 tag; /* User-defined request identifier */
__u8 *key; /* Input key VA, should be DMA buffer */
@@ -55,6 +57,7 @@ struct wd_ecc_msg {
__u8 curve_id; /* Ec curve denoted by enum wd_ecc_curve_type */
__u8 result; /* alg op error code */
void *drv_cfg; /* internal driver configuration */
+ __u8 *rsv_out; /* reserved output data pointer */
};
struct wd_ecc_pubkey {
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
index d231ecf..c12f3e0 100644
--- a/include/drv/wd_rsa_drv.h
+++ b/include/drv/wd_rsa_drv.h
@@ -42,11 +42,14 @@ struct wd_rsa_kg_out {
/* RSA message format */
struct wd_rsa_msg {
struct wd_rsa_req req;
+ struct wd_mm_ops *mm_ops;
+ enum wd_mem_type mm_type;
__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 */
__u8 *key; /* Input key VA pointer, should be DMA buffer */
+ __u8 *rsv_out; /* reserved output data pointer */
};
struct wd_rsa_msg *wd_rsa_get_msg(__u32 idx, __u32 tag);
diff --git a/include/wd_dh.h b/include/wd_dh.h
index afc2f7c..235c602 100644
--- a/include/wd_dh.h
+++ b/include/wd_dh.h
@@ -27,6 +27,8 @@ struct wd_dh_sess_setup {
__u16 key_bits; /* DH key bites */
bool is_g2; /* is g2 mode or not */
void *sched_param;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
struct wd_dh_req {
diff --git a/include/wd_ecc.h b/include/wd_ecc.h
index 6f670e2..18c1c0d 100644
--- a/include/wd_ecc.h
+++ b/include/wd_ecc.h
@@ -116,6 +116,8 @@ struct wd_ecc_sess_setup {
struct wd_rand_mt rand; /* rand method from user */
struct wd_hash_mt hash; /* hash method from user */
void *sched_param;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
struct wd_ecc_req {
diff --git a/include/wd_rsa.h b/include/wd_rsa.h
index 2f4e589..9c91432 100644
--- a/include/wd_rsa.h
+++ b/include/wd_rsa.h
@@ -60,6 +60,8 @@ struct wd_rsa_sess_setup {
__u16 key_bits; /* RSA key bits */
bool is_crt; /* CRT mode or not */
void *sched_param;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
bool wd_rsa_is_crt(handle_t sess);
diff --git a/wd_dh.c b/wd_dh.c
index 221322f..0c1372c 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -26,6 +26,8 @@ struct wd_dh_sess {
struct wd_dtb g;
struct wd_dh_sess_setup setup;
void *sched_key;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
static struct wd_dh_setting {
@@ -326,6 +328,8 @@ static int fill_dh_msg(struct wd_dh_msg *msg, struct wd_dh_req *req,
memcpy(&msg->req, req, sizeof(*req));
msg->result = WD_EINVAL;
msg->key_bytes = sess->key_size;
+ msg->mm_ops = &sess->mm_ops;
+ msg->mm_type = sess->mm_type;
if (unlikely(req->pri_bytes < sess->key_size)) {
WD_ERR("invalid: req pri bytes %hu is error!\n", req->pri_bytes);
@@ -581,6 +585,7 @@ void wd_dh_get_g(handle_t sess, struct wd_dtb **g)
handle_t wd_dh_alloc_sess(struct wd_dh_sess_setup *setup)
{
struct wd_dh_sess *sess;
+ int ret;
if (!setup) {
WD_ERR("invalid: alloc dh sess setup NULL!\n");
@@ -606,10 +611,19 @@ handle_t wd_dh_alloc_sess(struct wd_dh_sess_setup *setup)
memcpy(&sess->setup, setup, sizeof(*setup));
sess->key_size = setup->key_bits >> BYTE_BITS_SHIFT;
- sess->g.data = malloc(sess->key_size);
- if (!sess->g.data)
+ ret = wd_mem_ops_init(wd_dh_setting.config.ctxs[0].ctx, &setup->mm_ops, setup->mm_type);
+ if (ret) {
+ WD_ERR("failed to init memory ops!\n");
goto sess_err;
+ }
+ memcpy(&sess->mm_ops, &setup->mm_ops, sizeof(struct wd_mm_ops));
+ sess->mm_type = setup->mm_type;
+ sess->g.data = sess->mm_ops.alloc(sess->mm_ops.usr, sess->key_size);
+ if (!sess->g.data) {
+ WD_ERR("failed to malloc sess g param memory!\n");
+ goto sess_err;
+ }
sess->g.bsize = sess->key_size;
/* Some simple scheduler don't need scheduling parameters */
sess->sched_key = (void *)wd_dh_setting.sched.sched_init(
@@ -622,7 +636,7 @@ handle_t wd_dh_alloc_sess(struct wd_dh_sess_setup *setup)
return (handle_t)sess;
sched_err:
- free(sess->g.data);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->g.data);
sess_err:
free(sess);
return (handle_t)0;
@@ -638,7 +652,7 @@ void wd_dh_free_sess(handle_t sess)
}
if (sess_t->g.data)
- free(sess_t->g.data);
+ sess_t->mm_ops.free(sess_t->mm_ops.usr, sess_t->g.data);
if (sess_t->sched_key)
free(sess_t->sched_key);
diff --git a/wd_ecc.c b/wd_ecc.c
index b1971b9..2c88d0a 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -52,6 +52,8 @@ struct wd_ecc_sess {
struct wd_ecc_sess_setup setup;
struct wd_ecc_extend_ops eops;
void *sched_key;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
struct wd_ecc_curve_list {
@@ -494,7 +496,7 @@ static void release_ecc_prikey(struct wd_ecc_sess *sess)
struct wd_ecc_prikey *prikey = sess->key.prikey;
wd_memset_zero(prikey->data, prikey->size);
- free(prikey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, prikey->data);
free(prikey);
sess->key.prikey = NULL;
}
@@ -503,7 +505,7 @@ static void release_ecc_pubkey(struct wd_ecc_sess *sess)
{
struct wd_ecc_pubkey *pubkey = sess->key.pubkey;
- free(pubkey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, pubkey->data);
free(pubkey);
sess->key.pubkey = NULL;
}
@@ -522,7 +524,7 @@ static struct wd_ecc_prikey *create_ecc_prikey(struct wd_ecc_sess *sess)
}
dsz = ECC_PRIKEY_SZ(hsz);
- data = malloc(dsz);
+ data = sess->mm_ops.alloc(sess->mm_ops.usr, dsz);
if (!data) {
WD_ERR("failed to malloc prikey data, sz = %u!\n", dsz);
free(prikey);
@@ -551,7 +553,7 @@ static struct wd_ecc_pubkey *create_ecc_pubkey(struct wd_ecc_sess *sess)
}
dsz = ECC_PUBKEY_SZ(hsz);
- data = malloc(dsz);
+ data = sess->mm_ops.alloc(sess->mm_ops.usr, dsz);
if (!data) {
WD_ERR("failed to malloc pubkey data, sz = %u!\n", dsz);
free(pubkey);
@@ -570,7 +572,7 @@ static void release_ecc_in(struct wd_ecc_sess *sess,
struct wd_ecc_in *ecc_in)
{
wd_memset_zero(ecc_in->data, ecc_in->size);
- free(ecc_in);
+ sess->mm_ops.free(sess->mm_ops.usr, ecc_in);
}
static struct wd_ecc_in *create_ecc_in(struct wd_ecc_sess *sess, __u32 num)
@@ -585,7 +587,7 @@ static struct wd_ecc_in *create_ecc_in(struct wd_ecc_sess *sess, __u32 num)
hsz = get_key_bsz(sess->key_size);
len = sizeof(struct wd_ecc_in) + hsz * num;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc ecc in, sz = %u!\n", len);
return NULL;
@@ -613,7 +615,7 @@ static struct wd_ecc_in *create_sm2_sign_in(struct wd_ecc_sess *sess,
len = sizeof(struct wd_ecc_in)
+ ECC_SIGN_IN_PARAM_NUM * ksz + m_len;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc sm2 sign in, sz = %llu!\n", len);
return NULL;
@@ -653,7 +655,7 @@ static struct wd_ecc_in *create_sm2_enc_in(struct wd_ecc_sess *sess,
}
len = sizeof(struct wd_ecc_in) + ksz + m_len;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc sm2 enc in, sz = %llu!\n", len);
return NULL;
@@ -697,7 +699,7 @@ static void *create_sm2_ciphertext(struct wd_ecc_sess *sess, __u32 m_len,
*len = (__u64)st_sz + ECC_POINT_PARAM_NUM * (__u64)sess->key_size +
(__u64)m_len + (__u64)h_byts;
- start = malloc(*len);
+ start = sess->mm_ops.alloc(sess->mm_ops.usr, *len);
if (unlikely(!start)) {
WD_ERR("failed to alloc start, sz = %llu!\n", *len);
return NULL;
@@ -745,7 +747,7 @@ static struct wd_ecc_out *create_ecc_out(struct wd_ecc_sess *sess, __u32 num)
hsz = get_key_bsz(sess->key_size);
len = sizeof(struct wd_ecc_out) + hsz * num;
- out = malloc(len);
+ out = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!out) {
WD_ERR("failed to malloc out, sz = %u!\n", len);
return NULL;
@@ -1149,13 +1151,13 @@ static void del_sess_key(struct wd_ecc_sess *sess)
{
if (sess->key.prikey) {
wd_memset_zero(sess->key.prikey->data, sess->key.prikey->size);
- free(sess->key.prikey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->key.prikey->data);
free(sess->key.prikey);
sess->key.prikey = NULL;
}
if (sess->key.pubkey) {
- free(sess->key.pubkey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->key.pubkey->data);
free(sess->key.pubkey);
sess->key.pubkey = NULL;
}
@@ -1227,6 +1229,15 @@ handle_t wd_ecc_alloc_sess(struct wd_ecc_sess_setup *setup)
memcpy(&sess->setup, setup, sizeof(*setup));
sess->key_size = BITS_TO_BYTES(setup->key_bits);
+ /* Memory type set */
+ ret = wd_mem_ops_init(wd_ecc_setting.config.ctxs[0].ctx, &setup->mm_ops, setup->mm_type);
+ if (ret) {
+ WD_ERR("failed to init memory ops!\n");
+ goto sess_err;
+ }
+ memcpy(&sess->mm_ops, &setup->mm_ops, sizeof(struct wd_mm_ops));
+ sess->mm_type = setup->mm_type;
+
if (wd_ecc_setting.driver->get_extend_ops) {
ret = wd_ecc_setting.driver->get_extend_ops(&sess->eops);
if (ret) {
@@ -1508,9 +1519,10 @@ void wd_ecxdh_get_out_params(struct wd_ecc_out *out, struct wd_ecc_point **pbk)
void wd_ecc_del_in(handle_t sess, struct wd_ecc_in *in)
{
+ struct wd_ecc_sess *sess_t = (struct wd_ecc_sess *)sess;
__u32 bsz;
- if (!in) {
+ if (!sess_t || !in) {
WD_ERR("invalid: del ecc in parameter error!\n");
return;
}
@@ -1522,14 +1534,15 @@ void wd_ecc_del_in(handle_t sess, struct wd_ecc_in *in)
}
wd_memset_zero(in->data, bsz);
- free(in);
+ sess_t->mm_ops.free(sess_t->mm_ops.usr, in);
}
-void wd_ecc_del_out(handle_t sess, struct wd_ecc_out *out)
+void wd_ecc_del_out(handle_t sess, struct wd_ecc_out *out)
{
+ struct wd_ecc_sess *sess_t = (struct wd_ecc_sess *)sess;
__u32 bsz;
- if (!out) {
+ if (!sess_t || !out) {
WD_ERR("invalid: del ecc out parameter error!\n");
return;
}
@@ -1541,7 +1554,7 @@ void wd_ecc_del_out(handle_t sess, struct wd_ecc_out *out)
}
wd_memset_zero(out->data, bsz);
- free(out);
+ sess_t->mm_ops.free(sess_t->mm_ops.usr, out);
}
static int fill_ecc_msg(struct wd_ecc_msg *msg, struct wd_ecc_req *req,
@@ -1551,6 +1564,8 @@ static int fill_ecc_msg(struct wd_ecc_msg *msg, struct wd_ecc_req *req,
memcpy(&msg->req, req, sizeof(msg->req));
memcpy(&msg->hash, &sess->setup.hash, sizeof(msg->hash));
+ msg->mm_ops = &sess->mm_ops;
+ msg->mm_type = sess->mm_type;
msg->key_bytes = sess->key_size;
msg->curve_id = sess->setup.cv.cfg.id;
msg->drv_cfg = sess->eops.params;
@@ -1922,7 +1937,7 @@ static struct wd_ecc_in *create_sm2_verf_in(struct wd_ecc_sess *sess,
hsz = get_key_bsz(sess->key_size);
len = sizeof(struct wd_ecc_in) + ECC_VERF_IN_PARAM_NUM * hsz +
m_len;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc sm2 verf in, sz = %llu!\n", len);
return NULL;
@@ -2211,7 +2226,7 @@ struct wd_ecc_out *wd_sm2_new_dec_out(handle_t sess, __u32 plaintext_len)
}
len = sizeof(*ecc_out) + plaintext_len;
- ecc_out = malloc(len);
+ ecc_out = sess_t->mm_ops.alloc(sess_t->mm_ops.usr, len);
if (!ecc_out) {
WD_ERR("failed to malloc ecc_out, sz = %llu!\n", len);
return NULL;
diff --git a/wd_rsa.c b/wd_rsa.c
index cf9239c..bc78c6a 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -67,6 +67,8 @@ struct wd_rsa_sess {
struct wd_rsa_prikey *prikey;
struct wd_rsa_sess_setup setup;
void *sched_key;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
static struct wd_rsa_setting {
@@ -373,6 +375,8 @@ static int fill_rsa_msg(struct wd_rsa_msg *msg, struct wd_rsa_req *req,
memcpy(&msg->req, req, sizeof(*req));
msg->key_bytes = sess->key_size;
msg->result = WD_EINVAL;
+ msg->mm_ops = &sess->mm_ops;
+ msg->mm_type = sess->mm_type;
switch (msg->req.op_type) {
case WD_RSA_SIGN:
@@ -641,7 +645,7 @@ struct wd_rsa_kg_in *wd_rsa_new_kg_in(handle_t sess, struct wd_dtb *e,
}
kg_in_size = (int)GEN_PARAMS_SZ(c->key_size);
- kg_in = malloc(kg_in_size + sizeof(*kg_in));
+ kg_in = c->mm_ops.alloc(c->mm_ops.usr, kg_in_size + sizeof(*kg_in));
if (!kg_in) {
WD_ERR("failed to malloc kg_in memory!\n");
return NULL;
@@ -681,19 +685,16 @@ void wd_rsa_get_kg_in_params(struct wd_rsa_kg_in *kin, struct wd_dtb *e,
p->data = (void *)kin->p;
}
-static void del_kg(void *k)
+void wd_rsa_del_kg_in(handle_t sess, struct wd_rsa_kg_in *ki)
{
- if (!k) {
+ struct wd_rsa_sess *c = (struct wd_rsa_sess *)sess;
+
+ if (!c || !ki) {
WD_ERR("invalid: del key generate params err!\n");
return;
}
- free(k);
-}
-
-void wd_rsa_del_kg_in(handle_t sess, struct wd_rsa_kg_in *ki)
-{
- del_kg(ki);
+ c->mm_ops.free(c->mm_ops.usr, ki);
}
struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess)
@@ -719,7 +720,7 @@ struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess)
else
kg_out_size = (int)GEN_PARAMS_SZ(c->key_size);
- kg_out = malloc(kg_out_size + sizeof(*kg_out));
+ kg_out = c->mm_ops.alloc(c->mm_ops.usr, kg_out_size + sizeof(*kg_out));
if (!kg_out) {
WD_ERR("failed to malloc kg_out memory!\n");
return NULL;
@@ -741,13 +742,15 @@ struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess)
void wd_rsa_del_kg_out(handle_t sess, struct wd_rsa_kg_out *kout)
{
- if (!kout) {
+ struct wd_rsa_sess *c = (struct wd_rsa_sess *)sess;
+
+ if (!c || !kout) {
WD_ERR("invalid: param null at del kg out!\n");
return;
}
wd_memset_zero(kout->data, kout->size);
- del_kg(kout);
+ c->mm_ops.free(c->mm_ops.usr, kout);
}
void wd_rsa_get_kg_out_params(struct wd_rsa_kg_out *kout, struct wd_dtb *d,
@@ -804,6 +807,11 @@ void wd_rsa_set_kg_out_crt_psz(struct wd_rsa_kg_out *kout,
size_t dq_sz,
size_t dp_sz)
{
+ if (!kout) {
+ WD_ERR("invalid: input null when set kg out crt psz!\n");
+ return;
+ }
+
kout->qinvbytes = qinv_sz;
kout->dqbytes = dq_sz;
kout->dpbytes = dp_sz;
@@ -813,6 +821,11 @@ void wd_rsa_set_kg_out_psz(struct wd_rsa_kg_out *kout,
size_t d_sz,
size_t n_sz)
{
+ if (!kout) {
+ WD_ERR("invalid: input null when set kg out psz!\n");
+ return;
+ }
+
kout->dbytes = d_sz;
kout->nbytes = n_sz;
}
@@ -862,7 +875,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup,
if (setup->is_crt) {
len = sizeof(struct wd_rsa_prikey) +
(int)CRT_PARAMS_SZ(sess->key_size);
- sess->prikey = malloc(len);
+ sess->prikey = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!sess->prikey) {
WD_ERR("failed to alloc sess prikey2!\n");
return -WD_ENOMEM;
@@ -873,7 +886,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup,
} else {
len = sizeof(struct wd_rsa_prikey) +
(int)GEN_PARAMS_SZ(sess->key_size);
- sess->prikey = malloc(len);
+ sess->prikey = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!sess->prikey) {
WD_ERR("failed to alloc sess prikey1!\n");
return -WD_ENOMEM;
@@ -885,7 +898,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup,
len = sizeof(struct wd_rsa_pubkey) +
(int)GEN_PARAMS_SZ(sess->key_size);
- sess->pubkey = malloc(len);
+ sess->pubkey = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!sess->pubkey) {
free(sess->prikey);
WD_ERR("failed to alloc sess pubkey!\n");
@@ -912,8 +925,8 @@ static void del_sess_key(struct wd_rsa_sess *sess)
wd_memset_zero(prk->pkey.pkey2.data, CRT_PARAMS_SZ(sess->key_size));
else
wd_memset_zero(prk->pkey.pkey1.data, GEN_PARAMS_SZ(sess->key_size));
- free(sess->prikey);
- free(sess->pubkey);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->prikey);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->pubkey);
}
static void del_sess(struct wd_rsa_sess *c)
@@ -948,6 +961,15 @@ handle_t wd_rsa_alloc_sess(struct wd_rsa_sess_setup *setup)
memcpy(&sess->setup, setup, sizeof(*setup));
sess->key_size = setup->key_bits >> BYTE_BITS_SHIFT;
+ /* Memory type set */
+ ret = wd_mem_ops_init(wd_rsa_setting.config.ctxs[0].ctx, &setup->mm_ops, setup->mm_type);
+ if (ret) {
+ WD_ERR("failed to init memory ops!\n");
+ goto sess_err;
+ }
+
+ memcpy(&sess->mm_ops, &setup->mm_ops, sizeof(struct wd_mm_ops));
+ sess->mm_type = setup->mm_type;
ret = create_sess_key(setup, sess);
if (ret) {
WD_ERR("failed to create rsa sess keys!\n");
--
2.33.0
1
2
From: Wenkai Lin <linwenkai6(a)hisilicon.com>
Extract a common function fill_hashagg_data_info.
Signed-off-by: Wenkai Lin <linwenkai6(a)hisilicon.com>
Signed-off-by: Zongyu Wu <wuzongyu1(a)huawei.com>
---
drv/hisi_dae.c | 56 +++++++++++++++++++-------------------------------
1 file changed, 21 insertions(+), 35 deletions(-)
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index 4f4d13c..49387aa 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -26,7 +26,7 @@
#define DAE_VCHAR_OFFSET_SIZE 2
#define DAE_COL_BIT_NUM 4
#define DAE_AGG_START_COL 16
-#define DAE_HASHAGG_MAX_ROW_NUN 50000
+#define DAE_HASHAGG_MAX_ROW_NUM 50000
/* align size */
#define DAE_CHAR_ALIGN_SIZE 4
@@ -294,23 +294,8 @@ static void fill_hashagg_merge_key_data(struct dae_sqe *sqe, struct dae_ext_sqe
}
}
-static void fill_hashagg_normal_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
- struct hashagg_col_data *cols_data, __u32 agg_cols_num)
-{
- struct hw_agg_data *agg_data = cols_data->input_data;
- __u32 i;
-
- for (i = 0; i < agg_cols_num; i++) {
- sqe->agg_data_type[i] = agg_data[i].hw_type;
- sqe->agg_data_type[i] |= agg_data[i].sum_outtype << DAE_COL_BIT_NUM;
- ext_sqe->agg_data_info[i] = agg_data[i].data_info;
- }
-
- sqe->agg_col_bitmap = GENMASK(agg_cols_num + DAE_AGG_START_COL - 1, DAE_AGG_START_COL);
-}
-
-static void fill_hashagg_rehash_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
- struct hw_agg_data *agg_data, __u32 agg_cols_num)
+static void fill_hashagg_data_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
+ struct hw_agg_data *agg_data, __u32 agg_cols_num)
{
__u32 i;
@@ -344,14 +329,14 @@ static void fill_hashagg_input_data(struct dae_sqe *sqe, struct dae_ext_sqe *ext
hw_agg_addr = &addr_list->input_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.agg_cols;
agg_col_num = msg->agg_cols_num;
- fill_hashagg_normal_info(sqe, ext_sqe, cols_data, agg_col_num);
+ fill_hashagg_data_info(sqe, ext_sqe, agg_data, agg_col_num);
break;
case WD_AGG_REHASH_INPUT:
agg_data = cols_data->output_data;
hw_agg_addr = &addr_list->input_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.agg_cols;
agg_col_num = cols_data->output_num;
- fill_hashagg_rehash_info(sqe, ext_sqe, agg_data, agg_col_num);
+ fill_hashagg_data_info(sqe, ext_sqe, agg_data, agg_col_num);
break;
case WD_AGG_STREAM_OUTPUT:
case WD_AGG_REHASH_OUTPUT:
@@ -359,7 +344,7 @@ static void fill_hashagg_input_data(struct dae_sqe *sqe, struct dae_ext_sqe *ext
hw_agg_addr = &addr_list->output_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.out_agg_cols;
agg_col_num = cols_data->output_num;
- fill_hashagg_normal_info(sqe, ext_sqe, cols_data, cols_data->input_num);
+ fill_hashagg_data_info(sqe, ext_sqe, cols_data->input_data, cols_data->input_num);
break;
}
@@ -385,7 +370,7 @@ static void fill_hashagg_merge_input_data(struct dae_sqe *sqe, struct dae_ext_sq
struct hashagg_ctx *agg_ctx = msg->priv;
struct hashagg_col_data *cols_data = &agg_ctx->cols_data;
- fill_hashagg_rehash_info(sqe, ext_sqe, cols_data->output_data, msg->agg_cols_num);
+ fill_hashagg_data_info(sqe, ext_sqe, cols_data->output_data, msg->agg_cols_num);
}
static void fill_hashagg_ext_addr(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
@@ -422,26 +407,15 @@ static void fill_hashagg_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
static int check_hashagg_param(struct wd_agg_msg *msg)
{
- struct hashagg_col_data *cols_data;
- struct hashagg_ctx *agg_ctx;
-
if (!msg) {
WD_ERR("invalid: input hashagg msg is NULL!\n");
return -WD_EINVAL;
}
- agg_ctx = msg->priv;
- cols_data = &agg_ctx->cols_data;
- if (cols_data->output_num > DAE_MAX_OUTPUT_COLS) {
- WD_ERR("invalid: input hashagg output num %u is more than %d!\n",
- cols_data->output_num, DAE_MAX_OUTPUT_COLS);
- return -WD_EINVAL;
- }
-
if ((msg->pos == WD_AGG_STREAM_INPUT || msg->pos == WD_AGG_REHASH_INPUT) &&
- msg->row_count > DAE_HASHAGG_MAX_ROW_NUN) {
+ msg->row_count > DAE_HASHAGG_MAX_ROW_NUM) {
WD_ERR("invalid: input hashagg row count %u is more than %d!\n",
- msg->row_count, DAE_HASHAGG_MAX_ROW_NUN);
+ msg->row_count, DAE_HASHAGG_MAX_ROW_NUM);
return -WD_EINVAL;
}
@@ -1005,6 +979,7 @@ static int transfer_input_col_info(struct wd_agg_col_info *agg_cols,
struct hw_agg_data *user_output_data,
__u32 cols_num, __u32 *output_num)
{
+ __u32 tmp = *output_num;
__u32 i, j, k = 0;
int ret;
@@ -1013,7 +988,15 @@ static int transfer_input_col_info(struct wd_agg_col_info *agg_cols,
WD_ERR("invalid: col alg num(%u) more than 2!\n", agg_cols[i].col_alg_num);
return -WD_EINVAL;
}
+ tmp += agg_cols[i].col_alg_num;
+ }
+ if (tmp > DAE_MAX_OUTPUT_COLS) {
+ WD_ERR("invalid: output col num is more than %d!\n", DAE_MAX_OUTPUT_COLS);
+ return -WD_EINVAL;
+ }
+
+ for (i = 0; i < cols_num; i++) {
for (j = 0; j < agg_cols[i].col_alg_num; j++) {
ret = hashagg_check_input_data(&agg_cols[i], &user_input_data[i],
&user_output_data[k], j);
@@ -1137,6 +1120,9 @@ static int transfer_data_to_hw_type(struct hashagg_col_data *cols_data,
struct wd_agg_col_info *agg_cols = setup->agg_cols_info;
int ret;
+ if (setup->is_count_all)
+ cols_data->output_num++;
+
ret = transfer_input_col_info(agg_cols, user_input_data, user_output_data,
setup->agg_cols_num, &cols_data->output_num);
if (ret)
--
2.33.0
1
0
From: parm64 <parm64(a)huawei.com>
Zhushuai Yin (6):
uadk_provider: fix spelling errors and incorrect return value issues
uadk_provider: prov supports dynamic algorithm cropping func
uadk_provider: provide log configuration functionality
uadk_provider:fix the issue of algorithm prohibition failure for DH
uadk_provider: fix issues that may cause encryption to fail
uadk_engine: fix the issue of incorrect engine use the V2 interface
ZongYu Wu (1):
uadk_engine: fix uadk prov module spelling error
lizhi (2):
uadk_provider: fix poll timeout in abnormal scenarios
uadk_engine: clean up unused functions
src/uadk_aead.c | 2 +-
src/uadk_async.c | 9 +-
src/uadk_cipher.c | 3 +-
src/uadk_cipher_adapter.c | 3 +-
src/uadk_dh.c | 3 +-
src/uadk_digest.c | 2 +-
src/uadk_ec.c | 2 +-
src/uadk_ecx.c | 18 --
src/uadk_engine_init.c | 11 +-
src/uadk_pkey.c | 3 +-
src/uadk_prov.h | 23 +-
src/uadk_prov_aead.c | 105 +++----
src/uadk_prov_cipher.c | 120 ++++----
src/uadk_prov_dh.c | 194 ++++++------
src/uadk_prov_digest.c | 78 ++---
src/uadk_prov_ec_kmgmt.c | 60 ++--
src/uadk_prov_ecdh_exch.c | 73 ++---
src/uadk_prov_ecdsa.c | 118 ++++----
src/uadk_prov_ecx.c | 162 +++++-----
src/uadk_prov_ffc.c | 9 +-
src/uadk_prov_hmac.c | 76 ++---
src/uadk_prov_init.c | 607 +++++++++++++++++++++++++++++++++++---
src/uadk_prov_packet.c | 5 +-
src/uadk_prov_pkey.c | 87 +++---
src/uadk_prov_pkey.h | 3 -
src/uadk_prov_rsa.c | 111 ++++---
src/uadk_prov_sm2.c | 474 ++++++++++++++---------------
src/uadk_rsa.c | 3 +-
src/uadk_sm2.c | 9 -
src/uadk_utils.c | 14 +
src/uadk_utils.h | 27 ++
uadk_provider.cnf | 27 ++
32 files changed, 1507 insertions(+), 934 deletions(-)
--
2.43.0
1
9