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
14 Nov '25
From: Longfang Liu <liulongfang(a)huawei.com>
Add kernel-state reserved memory handling functionality to the
uadk SVA framework to adapt to No-SVA features, including functions
for applying for and initializing reserved memory pools, applying for,
using, and releasing memory within the memory pool.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
Signed-off-by: Zongyu Wu <wuzongyu1(a)huawei.com>
---
Makefile.am | 9 +-
include/uacce.h | 7 +
include/wd.h | 23 +
include/wd_alg_common.h | 36 +-
include/wd_bmm.h | 44 ++
include/wd_internal.h | 70 +++
include/wd_util.h | 2 +
libwd.map | 14 +
wd.c | 38 +-
wd_bmm.c | 1057 +++++++++++++++++++++++++++++++++++++++
wd_util.c | 107 +++-
11 files changed, 1355 insertions(+), 52 deletions(-)
create mode 100644 include/wd_bmm.h
create mode 100644 include/wd_internal.h
create mode 100644 wd_bmm.c
diff --git a/Makefile.am b/Makefile.am
index f897533..0e1203a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -32,12 +32,13 @@ YEAR = 2025
AM_CFLAGS+= -DUADK_VERSION_NUMBER="\"UADK version: ${MAJOR}.${MINOR}.${REVISION}\""
AM_CFLAGS+= -DUADK_RELEASED_TIME="\"Released ${MONTH} ${DAY}, ${YEAR}\""
-pkginclude_HEADERS = include/wd.h include/wd_cipher.h include/wd_aead.h \
+pkginclude_HEADERS = include/wd.h include/wd_internal.h include/wd_cipher.h include/wd_aead.h \
include/wd_comp.h include/wd_dh.h include/wd_digest.h \
include/wd_rsa.h include/uacce.h include/wd_alg_common.h \
include/wd_ecc.h include/wd_sched.h include/wd_alg.h \
include/wd_zlibwrapper.h include/wd_dae.h include/wd_agg.h \
- include/wd_udma.h include/wd_join_gather.h
+ include/wd_udma.h include/wd_join_gather.h \
+ include/wd_bmm.h
nobase_pkginclude_HEADERS = v1/wd.h v1/wd_cipher.h v1/wd_aead.h v1/uacce.h v1/wd_dh.h \
v1/wd_digest.h v1/wd_rsa.h v1/wd_bmm.h
@@ -48,7 +49,7 @@ 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.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_rsa.c v1/wd_rsa.h \
v1/wd_aead.c v1/wd_aead.h \
@@ -126,7 +127,7 @@ libwd_comp_la_DEPENDENCIES = libwd.la
libhisi_zip_la_LIBADD = -ldl
-libwd_crypto_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma
+libwd_crypto_la_LIBADD = -lwd -ldl -lnuma -lm -lpthread
libwd_crypto_la_DEPENDENCIES = libwd.la
libwd_udma_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma -lm -lpthread
diff --git a/include/uacce.h b/include/uacce.h
index f7fae27..c6bb4fb 100644
--- a/include/uacce.h
+++ b/include/uacce.h
@@ -15,6 +15,12 @@ extern "C" {
#define UACCE_CMD_START _IO('W', 0)
#define UACCE_CMD_PUT_Q _IO('W', 1)
+#define UACCE_CMD_GET_SS_DMA _IOR('W', 3, unsigned long)
+
+/* Pass DMA SS region slice size by granularity 64KB */
+#define UACCE_GRAN_SIZE 0x10000ull
+#define UACCE_GRAN_SHIFT 16
+#define UACCE_GRAN_NUM_MASK 0xfffull
/**
* UACCE Device flags:
@@ -33,6 +39,7 @@ enum {
enum uacce_qfrt {
UACCE_QFRT_MMIO = 0, /* device mmio region */
UACCE_QFRT_DUS = 1, /* device user share */
+ UACCE_QFRT_SS, /* static share memory */
UACCE_QFRT_MAX,
};
diff --git a/include/wd.h b/include/wd.h
index b62d355..b97e5c7 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -38,6 +38,7 @@ typedef unsigned long long __u64;
/* Required compiler attributes */
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define handle_t uintptr_t
typedef struct wd_dev_mask wd_dev_mask_t;
@@ -115,6 +116,28 @@ enum wd_alg_type {
WD_AEAD,
};
+/* Memory APIs for UADK API Layer */
+typedef void *(*wd_alloc)(void *usr, size_t size);
+typedef void (*wd_free)(void *usr, void *va);
+
+ /* Memory VA to DMA address map and unmap */
+typedef void *(*wd_map)(void *usr, void *va, size_t sz);
+typedef void (*wd_unmap)(void *usr, void *va, void *dma, size_t sz);
+typedef __u32 (*wd_bufsize)(void *usr);
+
+/* Memory from user, it is given at ctx creating. */
+struct wd_mm_ops {
+ wd_alloc alloc; /* Memory allocation */
+ wd_free free; /* Memory free */
+ wd_map iova_map; /* Get iova from user space VA */
+
+ /* Destroy the mapping between the PA of VA and iova */
+ wd_unmap iova_unmap;
+ wd_bufsize get_bufsize; /* Optional */
+ void *usr; /* Data for the above operations */
+ bool sva_mode; /* Record whether the OS is SVA or No-SVA mode */
+};
+
/*
* If the actual size of data is inconsistent
* with dsize, undefined behavior occurs.
diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h
index fd77426..a294877 100644
--- a/include/wd_alg_common.h
+++ b/include/wd_alg_common.h
@@ -12,6 +12,7 @@
#include <numa.h>
#include "wd.h"
#include "wd_alg.h"
+#include "wd_internal.h"
#ifdef __cplusplus
extern "C" {
@@ -24,7 +25,6 @@ extern "C" {
#define BITS_TO_BYTES(bits) (((bits) + 7) >> 3)
#define BYTES_TO_BITS(bytes) ((bytes) << 3)
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define MAX_STR_LEN 256
#define CTX_TYPE_INVALID 9999
#define POLL_TIME 1000
@@ -60,6 +60,13 @@ enum wd_init_type {
WD_TYPE_V2,
};
+enum wd_mem_type {
+ UADK_MEM_AUTO,
+ UADK_MEM_USER,
+ UADK_MEM_PROXY,
+ UADK_MEM_MAX,
+};
+
/*
* struct wd_ctx - Define one ctx and related type.
* @ctx: The ctx itself.
@@ -132,27 +139,6 @@ struct wd_ctx_params {
struct wd_cap_config *cap;
};
-struct wd_soft_ctx {
- void *priv;
-};
-
-struct wd_ctx_internal {
- handle_t ctx;
- __u8 op_type;
- __u8 ctx_mode;
- __u16 sqn;
- pthread_spinlock_t lock;
-};
-
-struct wd_ctx_config_internal {
- __u32 ctx_num;
- int shmid;
- struct wd_ctx_internal *ctxs;
- void *priv;
- bool epoll_en;
- unsigned long *msg_cnt;
-};
-
/*
* struct wd_comp_sched - Define a scheduler.
* @name: Name of this scheduler.
@@ -181,12 +167,6 @@ struct wd_sched {
typedef int (*wd_alg_init)(struct wd_ctx_config *config, struct wd_sched *sched);
typedef int (*wd_alg_poll_ctx)(__u32 idx, __u32 expt, __u32 *count);
-struct wd_datalist {
- void *data;
- __u32 len;
- struct wd_datalist *next;
-};
-
#ifdef __cplusplus
}
#endif
diff --git a/include/wd_bmm.h b/include/wd_bmm.h
new file mode 100644
index 0000000..76b56a0
--- /dev/null
+++ b/include/wd_bmm.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/*
+ * Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved.
+ */
+
+#ifndef _WD_SVA_BMM_H
+#define _WD_SVA_BMM_H
+
+#include <stdint.h>
+#include "wd.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Memory pool creating parameters */
+struct wd_mempool_setup {
+ __u32 block_size; /* Block buffer size */
+ __u32 block_num; /* Block buffer number */
+ __u32 align_size; /* Block buffer starting address align size */
+ struct wd_mm_ops ops; /* memory from user if don't use UADK memory */
+};
+
+void *wd_mempool_alloc(handle_t h_ctx, struct wd_mempool_setup *setup);
+void wd_mempool_free(handle_t h_ctx, void *pool);
+void *wd_mem_alloc(void *pool, size_t size);
+void wd_mem_free(void *pool, void *buf);
+
+void *wd_mem_map(void *pool, void *buf, size_t sz);
+void wd_mem_unmap(void *pool, void *buf_dma, void *buf, size_t sz);
+int wd_get_free_num(void *pool, __u32 *free_num);
+int wd_get_fail_num(void *pool, __u32 *fail_num);
+__u32 wd_get_bufsize(void *pool);
+
+handle_t wd_find_ctx(const char *alg_name);
+void wd_remove_ctx_list(void);
+int wd_insert_ctx_list(handle_t h_ctx, char *alg_name);
+__u32 wd_get_dev_id(void *pool);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _WD_SVA_BMM_H */
diff --git a/include/wd_internal.h b/include/wd_internal.h
new file mode 100644
index 0000000..cd90ebf
--- /dev/null
+++ b/include/wd_internal.h
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/*
+ * Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved.
+ */
+
+#ifndef WD_INTERNAL_H
+#define WD_INTERNAL_H
+
+#include <pthread.h>
+#include <stdbool.h>
+#include "wd.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define DECIMAL_NUMBER 10
+#define MAX_FD_NUM 65535
+
+struct wd_ctx_h {
+ int fd;
+ char dev_path[MAX_DEV_NAME_LEN];
+ char *dev_name;
+ char *drv_name;
+ unsigned long qfrs_offs[UACCE_QFRT_MAX];
+ void *qfrs_base[UACCE_QFRT_MAX];
+ struct uacce_dev *dev;
+ void *priv;
+};
+
+struct wd_soft_ctx {
+ int fd;
+ void *priv;
+};
+
+struct wd_ce_ctx {
+ int fd;
+ char *drv_name;
+ void *priv;
+};
+
+struct wd_ctx_internal {
+ handle_t ctx;
+ __u8 op_type;
+ __u8 ctx_mode;
+ __u16 sqn;
+ pthread_spinlock_t lock;
+};
+
+struct wd_ctx_config_internal {
+ __u32 ctx_num;
+ int shmid;
+ struct wd_ctx_internal *ctxs;
+ void *priv;
+ bool epoll_en;
+ unsigned long *msg_cnt;
+ char *alg_name;
+};
+
+struct wd_datalist {
+ void *data;
+ __u32 len;
+ struct wd_datalist *next;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/include/wd_util.h b/include/wd_util.h
index 4a5204d..a337284 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -553,6 +553,8 @@ static inline void wd_ctx_spin_unlock(struct wd_ctx_internal *ctx, int type)
pthread_spin_unlock(&ctx->lock);
}
+int wd_mem_ops_init(handle_t h_ctx, struct wd_mm_ops *mm_ops, int mem_type);
+
#ifdef __cplusplus
}
#endif
diff --git a/libwd.map b/libwd.map
index 5522ec0..b1b90b3 100644
--- a/libwd.map
+++ b/libwd.map
@@ -49,5 +49,19 @@ global:
wd_enable_drv;
wd_disable_drv;
wd_get_alg_head;
+
+ wd_find_ctx;
+ wd_get_dev_id;
+ wd_remove_ctx_list;
+ wd_insert_ctx_list;
+ wd_mempool_alloc;
+ wd_mempool_free;
+ wd_mem_alloc;
+ wd_mem_free;
+ wd_mem_map;
+ wd_mem_unmap;
+ wd_get_free_num;
+ wd_get_fail_num;
+ wd_get_bufsize;
local: *;
};
diff --git a/wd.c b/wd.c
index c1cc282..3e867b6 100644
--- a/wd.c
+++ b/wd.c
@@ -20,6 +20,7 @@
#include "wd.h"
#include "wd_alg.h"
+#include "wd_internal.h"
#define SYS_CLASS_DIR "/sys/class/uacce"
#define FILE_MAX_SIZE (8 << 20)
@@ -33,16 +34,18 @@ enum UADK_LOG_LEVEL {
static int uadk_log_level = WD_LOG_INVALID;
-struct wd_ctx_h {
- int fd;
- char dev_path[MAX_DEV_NAME_LEN];
- char *dev_name;
- char *drv_name;
- unsigned long qfrs_offs[UACCE_QFRT_MAX];
- void *qfrs_base[UACCE_QFRT_MAX];
- struct uacce_dev *dev;
- void *priv;
-};
+static int wd_check_ctx_type(handle_t h_ctx)
+{
+ struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
+
+ /* A simple and efficient method to check the queue type */
+ if (ctx->fd < 0 || ctx->fd > MAX_FD_NUM) {
+ WD_INFO("Invalid: this ctx not HW ctx.\n");
+ return -WD_HW_EACCESS;
+ }
+
+ return 0;
+}
static void wd_parse_log_level(void)
{
@@ -446,7 +449,7 @@ void wd_release_ctx(handle_t h_ctx)
{
struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
- if (!ctx)
+ if (!ctx || wd_check_ctx_type(h_ctx))
return;
close(ctx->fd);
@@ -461,7 +464,7 @@ int wd_ctx_start(handle_t h_ctx)
struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
int ret;
- if (!ctx)
+ if (!ctx || wd_check_ctx_type(h_ctx))
return -WD_EINVAL;
ret = wd_ctx_set_io_cmd(h_ctx, UACCE_CMD_START, NULL);
@@ -527,6 +530,7 @@ void wd_ctx_unmap_qfr(handle_t h_ctx, enum uacce_qfrt qfrt)
unsigned long wd_ctx_get_region_size(handle_t h_ctx, enum uacce_qfrt qfrt)
{
struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
+
if (!ctx || qfrt >= UACCE_QFRT_MAX)
return 0;
return ctx->qfrs_offs[qfrt];
@@ -585,8 +589,16 @@ int wd_ctx_wait(handle_t h_ctx, __u16 ms)
int wd_is_sva(handle_t h_ctx)
{
struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
+ int ret;
- if (!ctx || !ctx->dev)
+ if (!ctx)
+ return -WD_EINVAL;
+
+ ret = wd_check_ctx_type(h_ctx);
+ if (ret)
+ return ret;
+
+ if (!ctx->dev)
return -WD_EINVAL;
if ((unsigned int)ctx->dev->flags & UACCE_DEV_SVA)
diff --git a/wd_bmm.c b/wd_bmm.c
new file mode 100644
index 0000000..21c46ca
--- /dev/null
+++ b/wd_bmm.c
@@ -0,0 +1,1057 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/*
+ * Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved.
+ */
+
+/* Block Memory Management (lib): Adapted for SVA mode */
+#define _GNU_SOURCE
+#include <dirent.h>
+#include <numa.h>
+#include <sched.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <sys/queue.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#include "wd_internal.h"
+#include "wd_bmm.h"
+#include "uacce.h"
+#include "wd.h"
+
+#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
+#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#define UACCE_DEV_IOMMU (1<<7)
+
+#define TAG_FREE 0x12345678 /* block is free */
+#define TAG_USED 0x87654321 /* block is busy */
+#define MAX_ALIGN_SIZE 0x1000 /* 4KB */
+#define MAX_BLOCK_SIZE 0x10000000 /* 256MB */
+#define BLK_BALANCE_SZ 0x100000ul
+#define NUM_TIMES(x) (87 * (x) / 100)
+
+#define BYTE_SIZE 8
+#define BIT_SHIFT 3
+
+struct wd_ss_region {
+ unsigned long long pa;
+ void *va;
+ size_t size;
+ TAILQ_ENTRY(wd_ss_region) next;
+};
+TAILQ_HEAD(wd_ss_region_list, wd_ss_region);
+
+struct ctx_info {
+ int fd;
+ int iommu_type;
+ void *ss_va;
+ size_t ss_mm_size;
+ struct wd_ss_region_list ss_list;
+ struct wd_ss_region_list *head;
+ unsigned long qfrs_offset[UACCE_QFRT_MAX];
+};
+
+struct wd_blk_hd {
+ unsigned int blk_tag;
+ unsigned int blk_num;
+ void *blk_dma;
+ void *blk;
+};
+
+struct wd_blkpool {
+ pthread_spinlock_t pool_lock;
+ unsigned int free_blk_num;
+ unsigned int alloc_failures;
+ struct ctx_info *cinfo;
+ struct wd_blk_hd *blk_array; // memory blk array
+ unsigned int total_blocks; // total blk numbers
+ unsigned char *free_bitmap; // free blk bitmap, 0 mean unused
+ unsigned int bitmap_size; // bitmap's memory size
+ void *usr_mem_start;
+ void *act_start;
+ unsigned int act_hd_sz;
+ unsigned int act_blk_sz;
+ unsigned long act_mem_sz;
+ unsigned int dev_id;
+ struct wd_mempool_setup setup;
+};
+
+struct mem_ctx_node {
+ char alg_name[CRYPTO_MAX_ALG_NAME];
+ handle_t h_ctx;
+ int numa_id;
+ bool used;
+ TAILQ_ENTRY(mem_ctx_node) list_node;
+};
+static TAILQ_HEAD(, mem_ctx_node) g_mem_ctx_list = TAILQ_HEAD_INITIALIZER(g_mem_ctx_list);
+static pthread_mutex_t g_mem_ctx_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+handle_t wd_find_ctx(const char *alg_name)
+{
+ struct mem_ctx_node *close_node = NULL;
+ struct mem_ctx_node *node;
+ int min_distance = 0xFFFF;
+ int cpu = sched_getcpu();
+ int nid = numa_node_of_cpu(cpu);
+ handle_t h_ctx = 0;
+ int numa_dis;
+
+ if (!alg_name) {
+ WD_ERR("Invalid: alg_name is NULL!\n");
+ return 0;
+ }
+
+ pthread_mutex_lock(&g_mem_ctx_mutex);
+ TAILQ_FOREACH(node, &g_mem_ctx_list, list_node) {
+ if (node->used == false && strstr(node->alg_name, alg_name)) {
+ if (node->numa_id == nid) {
+ h_ctx = node->h_ctx;
+ node->used = true;
+ break;
+ }
+
+ /* Query the queue with the shortest NUMA distance */
+ numa_dis = numa_distance(nid, node->numa_id);
+ if (numa_dis < min_distance) {
+ min_distance = numa_dis;
+ close_node = node;
+ }
+ }
+ }
+
+ /* If no ctx matching the NUMA ID, use the shortest distance instead ctx */
+ if (!h_ctx && close_node) {
+ h_ctx = close_node->h_ctx;
+ close_node->used = true;
+ }
+ pthread_mutex_unlock(&g_mem_ctx_mutex);
+
+ if (!h_ctx)
+ WD_ERR("Failed to find mem ctx for alg: %s\n", alg_name);
+
+ return h_ctx;
+}
+
+void wd_remove_ctx_list(void)
+{
+ struct mem_ctx_node *node;
+
+ pthread_mutex_lock(&g_mem_ctx_mutex);
+ /* Free all list node */
+ while ((node = TAILQ_FIRST(&g_mem_ctx_list)) != NULL) {
+ /* Use TAILQ_REMOVE to remove list node */
+ TAILQ_REMOVE(&g_mem_ctx_list, node, list_node);
+ free(node);
+ }
+
+ pthread_mutex_unlock(&g_mem_ctx_mutex);
+}
+
+int wd_insert_ctx_list(handle_t h_ctx, char *alg_name)
+{
+ struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
+ struct mem_ctx_node *new_node;
+ int numa_id;
+
+ if (!alg_name || !h_ctx) {
+ WD_ERR("Invalid: input params is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ /* A simple and efficient method to check the queue type */
+ if (ctx->fd < 0 || ctx->fd > MAX_FD_NUM) {
+ WD_INFO("Invalid ctx: this ctx not HW ctx.\n");
+ return 0;
+ }
+
+ numa_id = ctx->dev->numa_id;
+ new_node = malloc(sizeof(struct mem_ctx_node));
+ if (new_node) {
+ pthread_mutex_lock(&g_mem_ctx_mutex);
+ strncpy(new_node->alg_name, alg_name, CRYPTO_MAX_ALG_NAME - 1);
+ new_node->alg_name[CRYPTO_MAX_ALG_NAME - 1] = '\0';
+ new_node->numa_id = numa_id;
+ new_node->h_ctx = h_ctx;
+ new_node->used = false;
+ TAILQ_INSERT_TAIL(&g_mem_ctx_list, new_node, list_node);
+ pthread_mutex_unlock(&g_mem_ctx_mutex);
+ return 0;
+ }
+
+ return -WD_ENOMEM;
+}
+
+static void wd_free_slice(struct ctx_info *cinfo)
+{
+ struct wd_ss_region *rgn;
+
+ while (true) {
+ rgn = TAILQ_FIRST(&cinfo->ss_list);
+ if (!rgn)
+ break;
+ TAILQ_REMOVE(&cinfo->ss_list, rgn, next);
+ free(rgn);
+ }
+}
+
+static void wd_add_slice(struct ctx_info *cinfo, struct wd_ss_region *rgn)
+{
+ struct wd_ss_region *rg;
+
+ rg = TAILQ_LAST(&cinfo->ss_list, wd_ss_region_list);
+ if (rg) {
+ if (rg->pa + rg->size == rgn->pa) {
+ rg->size += rgn->size;
+ free(rgn);
+ return;
+ }
+ }
+
+ TAILQ_INSERT_TAIL(&cinfo->ss_list, rgn, next);
+}
+
+static void wd_show_ss_slices(struct ctx_info *cinfo)
+{
+ struct wd_ss_region *rgn;
+ int i = 0;
+
+ TAILQ_FOREACH(rgn, cinfo->head, next) {
+ WD_ERR("slice-%d:size = 0x%lx\n", i, rgn->size);
+ i++;
+ }
+}
+
+static void bitmap_set_bit(unsigned char *bitmap, unsigned int bit_index)
+{
+ if (!bitmap)
+ return;
+
+ bitmap[bit_index >> BIT_SHIFT] |= (1 << (bit_index % BYTE_SIZE));
+}
+
+static void bitmap_clear_bit(unsigned char *bitmap, unsigned int bit_index)
+{
+ if (!bitmap)
+ return;
+
+ bitmap[bit_index >> BIT_SHIFT] &= ~(1 << (bit_index % BYTE_SIZE));
+}
+
+static bool bitmap_test_bit(const unsigned char *bitmap, unsigned int bit_index)
+{
+ if (!bitmap)
+ return false;
+
+ /* bit is 1, it indicates that the block has already been used and is not free */
+ if ((bitmap[bit_index >> BIT_SHIFT] >> (bit_index % BYTE_SIZE)) & 0x1)
+ return false;
+
+ return true;
+}
+
+static void *wd_mmap_qfr(struct ctx_info *cinfo, enum uacce_qfrt qfrt, size_t size)
+{
+ off_t off;
+
+ off = qfrt * getpagesize();
+
+ return mmap(0, size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, cinfo->fd, off);
+}
+
+static void wd_unmap_reserve_mem(void *addr, size_t size)
+{
+ int ret;
+
+ if (!addr)
+ return;
+
+ ret = munmap(addr, size);
+ if (ret)
+ WD_ERR("wd qfr unmap failed!\n");
+}
+
+static void *wd_map_reserve_mem(struct wd_blkpool *pool, size_t size)
+{
+ struct ctx_info *cinfo = pool->cinfo;
+ struct wd_ss_region *rgn;
+ unsigned long info;
+ size_t tmp = size;
+ unsigned long i = 0;
+ void *ptr;
+ int ret = 1;
+
+ if (!cinfo) {
+ WD_ERR("ctx queue information is NULL!\n");
+ return NULL;
+ }
+
+ /* Make sure memory map granularity size align */
+ if (!cinfo->iommu_type)
+ tmp = ALIGN(tmp, UACCE_GRAN_SIZE);
+
+ ptr = wd_mmap_qfr(cinfo, UACCE_QFRT_SS, tmp);
+ if (ptr == MAP_FAILED) {
+ WD_ERR("wd drv mmap fail!(err = %d)\n", errno);
+ return NULL;
+ }
+
+ cinfo->ss_va = ptr;
+ cinfo->ss_mm_size = tmp;
+ tmp = 0;
+ while (ret > 0) {
+ info = i;
+ ret = ioctl(cinfo->fd, UACCE_CMD_GET_SS_DMA, &info);
+ if (ret < 0) {
+ wd_show_ss_slices(cinfo);
+ WD_ERR("get DMA fail!\n");
+ goto err_out;
+ }
+
+ rgn = malloc(sizeof(*rgn));
+ if (!rgn) {
+ WD_ERR("alloc ss region fail!\n");
+ goto err_out;
+ }
+ memset(rgn, 0, sizeof(*rgn));
+
+ if (cinfo->iommu_type)
+ rgn->size = cinfo->ss_mm_size;
+ else
+ rgn->size = (info & UACCE_GRAN_NUM_MASK) <<
+ UACCE_GRAN_SHIFT;
+ rgn->pa = info & (~UACCE_GRAN_NUM_MASK);
+ rgn->va = ptr + tmp;
+ tmp += rgn->size;
+ wd_add_slice(cinfo, rgn);
+
+ i++;
+ }
+
+ return ptr;
+
+err_out:
+ wd_free_slice(cinfo);
+ wd_unmap_reserve_mem(cinfo->ss_va, cinfo->ss_mm_size);
+
+ return NULL;
+}
+
+static int wd_pool_params_check(struct wd_mempool_setup *setup)
+{
+ if (!setup->block_num || !setup->block_size ||
+ setup->block_size > MAX_BLOCK_SIZE) {
+ WD_ERR("Invalid: block_size or block_num(%x, %u)!\n",
+ setup->block_size, setup->block_num);
+ return -WD_EINVAL;
+ }
+
+ /* Check parameters, and align_size must be 2^N */
+ if (setup->align_size <= 0x1 || setup->align_size > MAX_ALIGN_SIZE ||
+ (setup->align_size & (setup->align_size - 0x1))) {
+ WD_ERR("Invalid align_size.\n");
+ return -WD_EINVAL;
+ }
+
+ return WD_SUCCESS;
+}
+
+static int wd_ctx_info_init(struct wd_ctx_h *ctx, struct wd_blkpool *p)
+{
+ struct ctx_info *cinfo;
+
+ cinfo = calloc(1, sizeof(struct ctx_info));
+ if (!cinfo) {
+ WD_ERR("failed to alloc ctx info memory.\n");
+ return -WD_ENOMEM;
+ }
+
+ cinfo->fd = ctx->fd;
+ cinfo->iommu_type = (unsigned int)ctx->dev->flags & UACCE_DEV_IOMMU;
+ cinfo->head = &cinfo->ss_list;
+ TAILQ_INIT(&cinfo->ss_list);
+ (void)memcpy(cinfo->qfrs_offset, ctx->qfrs_offs,
+ sizeof(cinfo->qfrs_offset));
+ p->cinfo = (void *)cinfo;
+
+ return 0;
+}
+
+static int wd_pool_pre_layout(handle_t h_ctx,
+ struct wd_blkpool *p,
+ struct wd_mempool_setup *sp)
+{
+ struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
+ struct ctx_info *cinfo = NULL;
+ unsigned int asz;
+ int ret;
+
+ if (!ctx && !sp->ops.alloc) {
+ WD_ERR("ctx is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ if (!sp->ops.alloc) {
+ ret = wd_ctx_info_init(ctx, p);
+ if (ret) {
+ WD_ERR("failed to init ctx info.\n");
+ return ret;
+ }
+ cinfo = p->cinfo;
+ }
+
+ ret = wd_pool_params_check(sp);
+ if (ret) {
+ free(p->cinfo);
+ p->cinfo = NULL;
+ return ret;
+ }
+
+ asz = sp->align_size;
+
+ /* Get actual value by align */
+ p->act_hd_sz = ALIGN(sizeof(struct wd_blk_hd), asz);
+ p->act_blk_sz = ALIGN(sp->block_size, asz);
+ p->act_mem_sz = (p->act_hd_sz + p->act_blk_sz) *
+ (unsigned long)sp->block_num + asz;
+
+ /*
+ * When we use WD reserve memory and the blk_sz is larger than 1M,
+ * in order to ensure the mem_pool to be success,
+ * ensure that the allocated memory is an integer multiple of 1M.
+ */
+ if (!sp->ops.alloc && (cinfo && !cinfo->iommu_type))
+ p->act_mem_sz = ((p->act_mem_sz + BLK_BALANCE_SZ - 1) & ~(BLK_BALANCE_SZ - 1)) << 1;
+
+ return WD_SUCCESS;
+}
+
+/**
+ * wd_iova_map - Map virtual address to physical address
+ * @cinfo: context information
+ * @va: virtual address to map
+ * @sz: size of the mapping (not used in current implementation)
+ *
+ * When IOMMU is enabled, the PA is actually an IOVA; userspace still sees it
+ * as consistent and contiguous with the VA.
+ * When IOMMU is disabled, the PA refers to the kernel's physical address, which
+ * must be physically contiguous to be allocated by the kernel.
+ * Therefore, the PA address can be obtained from the offset of the VA.
+ *
+ */
+static void *wd_iova_map(struct ctx_info *cinfo, void *va, size_t sz)
+{
+ struct wd_ss_region *rgn;
+ unsigned long offset;
+ void *dma_addr;
+
+ if (!cinfo || !va) {
+ WD_ERR("wd iova map: parameter err!\n");
+ return NULL;
+ }
+
+ /* Search through all memory regions to find where va belongs */
+ TAILQ_FOREACH(rgn, cinfo->head, next) {
+ if (rgn->va <= va && va < rgn->va + rgn->size) {
+ /* Calculate offset within the region */
+ offset = (uintptr_t)va - (uintptr_t)rgn->va;
+ /* Add base physical address of the region */
+ dma_addr = (void *)((uintptr_t)rgn->pa + offset);
+ return dma_addr;
+ }
+ }
+
+ WD_ERR("wd iova map: va not found in any region\n");
+ return NULL;
+}
+
+/**
+ * wd_iova_unmap - Unmap physical address (no-op in non-IOMMU mode)
+ * @cinfo: context information
+ * @va: virtual address
+ * @dma: physical address
+ * @sz: size of the mapping (not used in current implementation)
+ *
+ * In non-IOMMU mode, this function does nothing as there's no need to unmap.
+ * In IOMMU mode, this would typically involve unmapping the DMA address.
+ */
+static void wd_iova_unmap(struct ctx_info *cinfo, void *va, void *dma, size_t sz)
+{
+ /* For no-iommu, dma-unmap doing nothing */
+}
+
+static void wd_pool_uninit(struct wd_blkpool *p)
+{
+ struct ctx_info *cinfo = p->cinfo;
+ struct wd_blk_hd *fhd = NULL;
+ unsigned long block_size;
+ unsigned int i;
+
+ block_size = (unsigned long)p->act_hd_sz + p->act_blk_sz;
+ /* Clean up the allocated resources. */
+ for (i = 0; i < p->total_blocks; i++) {
+ /* Release the previously allocated blocks. */
+ fhd = &p->blk_array[i];
+ wd_iova_unmap(cinfo, fhd->blk, fhd->blk_dma, block_size);
+ }
+
+ free(p->free_bitmap);
+ p->free_bitmap = NULL;
+ free(p->blk_array);
+ p->blk_array = NULL;
+}
+
+static int wd_pool_init(struct wd_blkpool *p)
+{
+ struct ctx_info *cinfo = p->cinfo;
+ __u32 blk_size = p->setup.block_size;
+ void *dma_start, *dma_end, *va;
+ struct wd_blk_hd *fhd = NULL;
+ struct wd_blk_hd *hd = NULL;
+ unsigned int i, j, act_num;
+ unsigned long block_size;
+ unsigned int dma_num = 0;
+
+ p->act_start = (void *)ALIGN((uintptr_t)p->usr_mem_start,
+ p->setup.align_size);
+
+ /* Calculate the actual number of allocatable blocks */
+ block_size = (unsigned long)(p->act_hd_sz + p->act_blk_sz);
+ if (block_size == 0) {
+ WD_ERR("Invalid block size with header.\n");
+ return -WD_EINVAL;
+ }
+ act_num = p->act_mem_sz / block_size;
+ if (!act_num) {
+ WD_ERR("Invalid memory size.\n");
+ return -WD_EINVAL;
+ }
+
+ /* Allocate block array */
+ p->blk_array = (struct wd_blk_hd *)malloc(act_num * sizeof(struct wd_blk_hd));
+ if (!p->blk_array) {
+ WD_ERR("Failed to allocate block array.\n");
+ return -WD_ENOMEM;
+ }
+
+ /* Allocate bitmap */
+ p->total_blocks = act_num;
+ p->bitmap_size = (act_num + BYTE_SIZE - 1) >> BIT_SHIFT;
+ p->free_bitmap = (unsigned char *)calloc(1, p->bitmap_size);
+ if (!p->free_bitmap) {
+ WD_ERR("Failed to allocate free bitmap.\n");
+ goto bitmap_error;
+ }
+
+ /* Initialize all blocks. */
+ for (i = 0; i < act_num; i++) {
+ /* Calculate the virtual address of the current block. */
+ va = (void *)((uintptr_t)p->act_start + block_size * i);
+
+ /* Get the physical address. */
+ dma_start = wd_iova_map(cinfo, va, 0);
+ dma_end = wd_iova_map(cinfo, va + blk_size - 1, 0);
+ if (!dma_start || !dma_end) {
+ WD_ERR("wd_iova_map err.\n");
+ /* Clean up the allocated resources. */
+ goto init_blk_error;
+ }
+
+ /* Check whether the physical addresses are contiguous. */
+ if ((uintptr_t)dma_end - (uintptr_t)dma_start != blk_size - 1) {
+ /* If OS kernel is not open SMMU, need to check dma address */
+ WD_INFO("wd dma address not continuous.\n");
+ /* Mark as unavailable, bit value is 1. */
+ bitmap_set_bit(p->free_bitmap, i);
+ continue;
+ }
+
+ /* Initialize the block. */
+ hd = &p->blk_array[i];
+ hd->blk_dma = dma_start;
+ hd->blk = va;
+ hd->blk_tag = TAG_FREE;
+ hd->blk_num = 0;
+
+ dma_num++;
+ }
+
+ /*
+ * if dma_num <= (1 / 1.15) * user's block_num, we think the pool
+ * is created with failure.
+ */
+ if (dma_num <= NUM_TIMES(p->setup.block_num)) {
+ WD_ERR("dma_num = %u, not enough.\n", dma_num);
+ goto init_blk_error;
+ }
+
+ p->free_blk_num = dma_num;
+ p->setup.block_num = dma_num;
+
+ return WD_SUCCESS;
+
+init_blk_error:
+ /* Clean up the allocated resources. */
+ for (j = 0; j < i; j++) {
+ /* Release the previously allocated blocks. */
+ fhd = &p->blk_array[j];
+ wd_iova_unmap(cinfo, fhd->blk, fhd->blk_dma, block_size);
+ }
+ free(p->free_bitmap);
+
+bitmap_error:
+ free(p->blk_array);
+
+ return -WD_ENOMEM;
+}
+
+static int usr_pool_init(struct wd_blkpool *p)
+{
+ struct wd_mempool_setup *sp = &p->setup;
+ __u32 blk_size = sp->block_size;
+ struct wd_blk_hd *hd = NULL;
+ __u32 i;
+
+ p->act_start = (void *)ALIGN((uintptr_t)p->usr_mem_start,
+ sp->align_size);
+ for (i = 0; i < sp->block_num; i++) {
+ hd = (void *)((uintptr_t)p->act_start + (p->act_hd_sz + p->act_blk_sz) * i);
+ hd->blk = (void *)((uintptr_t)hd + p->act_hd_sz);
+ hd->blk_dma = sp->ops.iova_map(sp->ops.usr, hd->blk, blk_size);
+ if (!hd->blk_dma) {
+ WD_ERR("failed to map usr blk.\n");
+ return -WD_ENOMEM;
+ }
+ hd->blk_tag = TAG_FREE;
+ }
+
+ p->free_blk_num = sp->block_num;
+
+ return WD_SUCCESS;
+}
+
+static int wd_parse_dev_id(char *dev_name)
+{
+ char *last_dash = NULL;
+ char *endptr;
+ int dev_id;
+
+ if (!dev_name)
+ return -WD_EINVAL;
+
+ /* Find the last '-' in the string. */
+ last_dash = strrchr(dev_name, '-');
+ if (!last_dash || *(last_dash + 1) == '\0')
+ return -WD_EINVAL;
+
+ /* Parse the following number */
+ dev_id = strtol(last_dash + 1, &endptr, DECIMAL_NUMBER);
+ /* Check whether it is truly all digits */
+ if (*endptr != '\0' || dev_id < 0)
+ return -WD_EINVAL;
+
+ return dev_id;
+}
+
+static int wd_mempool_init(handle_t h_ctx, struct wd_blkpool *pool,
+ struct wd_mempool_setup *setup)
+{
+ struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
+ struct ctx_info *cinfo = pool->cinfo;
+ void *addr = NULL;
+ int ret;
+
+ /* Use user's memory, and its ops alloc function */
+ if (setup->ops.alloc && setup->ops.free && setup->ops.iova_map) {
+ addr = setup->ops.alloc(setup->ops.usr, pool->act_mem_sz);
+ if (!addr) {
+ WD_ERR("failed to allocate memory in user pool.\n");
+ return -WD_EINVAL;
+ }
+
+ pool->usr_mem_start = addr;
+ if (usr_pool_init(pool)) {
+ WD_ERR("failed to initialize user pool.\n");
+ setup->ops.free(setup->ops.usr, addr);
+ return -WD_EINVAL;
+ }
+ } else {
+ /* Use wd to reserve memory */
+ addr = wd_map_reserve_mem(pool, pool->act_mem_sz);
+ if (!addr) {
+ WD_ERR("wd pool failed to reserve memory.\n");
+ return -WD_ENOMEM;
+ }
+
+ pool->usr_mem_start = addr;
+ if (wd_pool_init(pool)) {
+ WD_ERR("failed to initialize wd pool.\n");
+ goto err_out;
+ }
+ setup->block_num = pool->setup.block_num;
+ }
+
+ ret = wd_parse_dev_id(ctx->dev_path);
+ if (ret < 0) {
+ wd_pool_uninit(pool);
+ goto err_out;
+ }
+ pool->dev_id = ret;
+
+ return WD_SUCCESS;
+
+err_out:
+ if (pool->cinfo) {
+ wd_free_slice(cinfo);
+ wd_unmap_reserve_mem(cinfo->ss_va, cinfo->ss_mm_size);
+ pool->cinfo = NULL;
+ }
+ return -WD_EINVAL;
+}
+
+void *wd_mempool_alloc(handle_t h_ctx, struct wd_mempool_setup *setup)
+{
+ struct wd_blkpool *pool = NULL;
+ int ret;
+
+ if (!setup || !h_ctx) {
+ WD_ERR("Input param is NULL!\n");
+ return NULL;
+ }
+
+ ret = wd_is_sva(h_ctx);
+ if (ret < 0) {
+ WD_ERR("failed to check device ctx!\n");
+ return NULL;
+ } else if (ret == UACCE_DEV_SVA) {
+ WD_ERR("the device is SVA mode!\n");
+ return NULL;
+ }
+
+ pool = calloc(1, sizeof(*pool));
+ if (!pool) {
+ WD_ERR("failed to malloc pool.\n");
+ return NULL;
+ }
+ ret = pthread_spin_init(&pool->pool_lock, PTHREAD_PROCESS_PRIVATE);
+ if (ret)
+ goto err_pool_alloc;
+
+ memcpy(&pool->setup, setup, sizeof(pool->setup));
+
+ ret = wd_pool_pre_layout(h_ctx, pool, setup);
+ if (ret)
+ goto err_pool_layout;
+
+ ret = wd_mempool_init(h_ctx, pool, setup);
+ if (ret)
+ goto err_pool_init;
+
+ return pool;
+
+err_pool_init:
+ if (pool->cinfo) {
+ free(pool->cinfo);
+ pool->cinfo = NULL;
+ }
+err_pool_layout:
+ pthread_spin_destroy(&pool->pool_lock);
+err_pool_alloc:
+ free(pool);
+
+ return NULL;
+}
+
+void wd_mempool_free(handle_t h_ctx, void *pool)
+{
+ struct wd_mempool_setup *setup;
+ struct wd_blkpool *p = pool;
+
+ if (!p || !h_ctx) {
+ WD_ERR("pool destroy err, pool or ctx is NULL.\n");
+ return;
+ }
+
+ setup = &p->setup;
+ if (p->free_blk_num != setup->block_num) {
+ WD_ERR("Can not destroy blk pool, as it's in use.\n");
+ return;
+ }
+
+ if (setup->ops.free)
+ setup->ops.free(setup->ops.usr, p->usr_mem_start);
+
+ if (p->cinfo) {
+ /* Free block array memory */
+ if (p->blk_array)
+ free(p->blk_array);
+
+ if (p->free_bitmap)
+ free(p->free_bitmap);
+
+ wd_free_slice(p->cinfo);
+ wd_unmap_reserve_mem(p->cinfo->ss_va, p->cinfo->ss_mm_size);
+ free(p->cinfo);
+ p->cinfo = NULL;
+ }
+
+ pthread_spin_destroy(&p->pool_lock);
+ free(p);
+}
+
+void wd_mem_free(void *pool, void *buf)
+{
+ struct wd_blkpool *p = pool;
+ struct wd_blk_hd *current_hd;
+ struct wd_blk_hd *hd;
+ unsigned int current_idx;
+ unsigned int blk_idx;
+ unsigned long offset;
+ unsigned int i, num;
+ unsigned long sz;
+
+ if (unlikely(!p || !buf)) {
+ WD_ERR("free blk parameters err!\n");
+ return;
+ }
+
+ sz = p->act_hd_sz + p->act_blk_sz;
+ if (!sz) {
+ WD_ERR("memory pool blk size is zero!\n");
+ return;
+ }
+
+ if ((uintptr_t)buf < (uintptr_t)p->act_start) {
+ WD_ERR("free block addr is error.\n");
+ return;
+ }
+
+ /* Calculate the block index. */
+ offset = (unsigned long)((uintptr_t)buf - (uintptr_t)p->act_start);
+ blk_idx = offset / sz;
+
+ /* Check if the index is valid. */
+ if (blk_idx >= p->total_blocks) {
+ WD_ERR("Invalid block index<%u>.\n", blk_idx);
+ return;
+ }
+
+ /* Get the block header. */
+ hd = &p->blk_array[blk_idx];
+ num = hd->blk_num;
+
+ pthread_spin_lock(&p->pool_lock);
+ /* Release all related blocks. */
+ for (i = 0; i < num; i++) {
+ // Recalculate the index (since it is contiguous).
+ current_idx = blk_idx + i;
+ current_hd = &p->blk_array[current_idx];
+ current_hd->blk_tag = TAG_FREE;
+ current_hd->blk_num = 0;
+ bitmap_clear_bit(p->free_bitmap, current_idx);
+ }
+ p->free_blk_num += num;
+ pthread_spin_unlock(&p->pool_lock);
+}
+
+static int wd_find_contiguous_blocks(struct wd_blkpool *p,
+ unsigned int required_blocks,
+ unsigned int *start_block)
+{
+#define MAX_SKIP_ATTEMPTS 10
+ unsigned int consecutive_count = 0;
+ unsigned int skip_attempts = 0;
+ struct wd_blk_hd *hd, *tl;
+ unsigned int i;
+
+ if (required_blocks == 0 || required_blocks > p->total_blocks)
+ return -WD_EINVAL;
+
+ for (i = 0; i < p->total_blocks; i++) {
+ if (!bitmap_test_bit(p->free_bitmap, i)) {
+ consecutive_count = 0;
+ continue;
+ }
+
+ if (consecutive_count == 0)
+ *start_block = i;
+ consecutive_count++;
+
+ if (consecutive_count < required_blocks)
+ continue;
+
+ /* Check DMA contiguity only if more than one block is needed */
+ if (required_blocks > 1) {
+ hd = &p->blk_array[*start_block];
+ tl = &p->blk_array[*start_block + required_blocks - 1];
+
+ if (((uintptr_t)tl->blk_dma - (uintptr_t)hd->blk_dma) !=
+ ((uintptr_t)tl->blk - (uintptr_t)hd->blk)) {
+ /* Not contiguous, skip this start and try again */
+ if (++skip_attempts > MAX_SKIP_ATTEMPTS)
+ return -WD_ENOMEM;
+
+ i = *start_block; // will be incremented by loop
+ consecutive_count = 0;
+ continue;
+ }
+ }
+
+ /* Found and DMA is contiguous */
+ return WD_SUCCESS;
+ }
+
+ return -WD_ENOMEM;
+}
+
+void *wd_mem_alloc(void *pool, size_t size)
+{
+ unsigned int required_blocks;
+ unsigned int start_block = 0;
+ struct wd_blk_hd *hd = NULL;
+ struct wd_blkpool *p = pool;
+ unsigned int j;
+ int ret;
+
+ if (unlikely(!p || !size)) {
+ WD_ERR("blk alloc pool is null!\n");
+ return NULL;
+ }
+
+ if (!p->act_blk_sz) {
+ WD_ERR("blk pool is error!\n");
+ return NULL;
+ }
+
+ /* Calculate the number of blocks required. */
+ required_blocks = (size + p->act_blk_sz - 1) / p->act_blk_sz;
+ if (required_blocks > p->free_blk_num) {
+ p->alloc_failures++;
+ WD_ERR("Not enough free blocks.\n");
+ return NULL;
+ }
+
+ pthread_spin_lock(&p->pool_lock);
+ /* Find contiguous free blocks. */
+ ret = wd_find_contiguous_blocks(p, required_blocks, &start_block);
+ if (ret != 0) {
+ p->alloc_failures++;
+ pthread_spin_unlock(&p->pool_lock);
+ WD_ERR("Failed to find contiguous blocks.\n");
+ return NULL;
+ }
+
+ /* Mark all required blocks as used */
+ for (j = start_block; j < start_block + required_blocks; j++) {
+ p->blk_array[j].blk_tag = TAG_USED;
+ bitmap_set_bit(p->free_bitmap, j);
+ }
+
+ p->free_blk_num -= required_blocks;
+ hd = &p->blk_array[start_block];
+ hd->blk_num = required_blocks;
+ pthread_spin_unlock(&p->pool_lock);
+
+ return hd->blk;
+}
+
+void *wd_mem_map(void *pool, void *buf, size_t sz)
+{
+ struct wd_blkpool *p = pool;
+ struct wd_blk_hd *hd;
+ unsigned long offset;
+ unsigned long blk_sz;
+ unsigned long blk_idx;
+
+ if (unlikely(!pool || !buf)) {
+ WD_ERR("blk map err, pool is NULL!\n");
+ return NULL;
+ }
+
+ if (!sz || (uintptr_t)buf < (uintptr_t)p->act_start) {
+ WD_ERR("map buf addr is error.\n");
+ return NULL;
+ }
+ /* Calculate the block index. */
+ offset = (unsigned long)((uintptr_t)buf - (uintptr_t)p->act_start);
+ blk_sz = p->act_hd_sz + p->act_blk_sz;
+ blk_idx = offset / blk_sz;
+
+ /* Check if the index is valid. */
+ if (blk_idx >= p->total_blocks) {
+ WD_ERR("Invalid block index<%lu> in map.\n", blk_idx);
+ return NULL;
+ }
+
+ hd = &p->blk_array[blk_idx];
+ if (unlikely(hd->blk_tag != TAG_USED ||
+ (uintptr_t)buf < (uintptr_t)hd->blk)) {
+ WD_ERR("dma map fail!\n");
+ return NULL;
+ }
+
+ return (void *)((uintptr_t)hd->blk_dma + ((uintptr_t)buf -
+ (uintptr_t)hd->blk));
+}
+
+void wd_mem_unmap(void *pool, void *buf_dma, void *buf, size_t sz)
+{
+ /* do nothing at no-iommu mode */
+}
+
+int wd_get_free_num(void *pool, __u32 *free_num)
+{
+ struct wd_blkpool *p = pool;
+
+ if (!p || !free_num) {
+ WD_ERR("get_free_blk_num err, parameter err!\n");
+ return -WD_EINVAL;
+ }
+
+ *free_num = __atomic_load_n(&p->free_blk_num, __ATOMIC_RELAXED);
+
+ return WD_SUCCESS;
+}
+
+int wd_get_fail_num(void *pool, __u32 *fail_num)
+{
+ struct wd_blkpool *p = pool;
+
+ if (!p || !fail_num) {
+ WD_ERR("get_blk_alloc_failure err, pool is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ *fail_num = __atomic_load_n(&p->alloc_failures, __ATOMIC_RELAXED);
+
+ return WD_SUCCESS;
+}
+
+__u32 wd_get_bufsize(void *pool)
+{
+ struct wd_blkpool *p = pool;
+
+ if (!p) {
+ WD_ERR("get dev id is null!\n");
+ return 0;
+ }
+
+ return p->act_blk_sz;
+}
+
+__u32 wd_get_dev_id(void *pool)
+{
+ struct wd_blkpool *p = pool;
+
+ if (!p) {
+ WD_ERR("failed to get dev id!\n");
+ return 0;
+ }
+
+ return p->dev_id;
+}
+
diff --git a/wd_util.c b/wd_util.c
index e8a2934..d0d83eb 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -13,6 +13,8 @@
#include <ctype.h>
#include "wd_sched.h"
#include "wd_util.h"
+#include "wd_alg.h"
+#include "wd_bmm.h"
#define WD_ASYNC_DEF_POLL_NUM 1
#define WD_ASYNC_DEF_QUEUE_DEPTH 1024
@@ -100,11 +102,6 @@ struct acc_alg_item {
const char *algtype;
};
-struct wd_ce_ctx {
- char *drv_name;
- void *priv;
-};
-
static struct acc_alg_item alg_options[] = {
{"zlib", "zlib"},
{"gzip", "gzip"},
@@ -172,6 +169,93 @@ static struct acc_alg_item alg_options[] = {
{"", ""}
};
+static void *wd_internal_alloc(void *usr, size_t size)
+{
+ if (size != 0)
+ return malloc(size);
+ else
+ return NULL;
+}
+
+static void wd_internal_free(void *usr, void *va)
+{
+ if (va != NULL)
+ free(va);
+}
+
+static __u32 wd_mem_bufsize(void *usr)
+{
+ /* Malloc memory min size is 1 Byte */
+ return 1;
+}
+
+int wd_mem_ops_init(handle_t h_ctx, struct wd_mm_ops *mm_ops, int mem_type)
+{
+ int ret;
+
+ ret = wd_is_sva(h_ctx);
+ if (ret == UACCE_DEV_SVA || ret == -WD_HW_EACCESS) {
+ /*
+ * In software queue scenario, all memory is handled as virtual memory
+ * and processed in the same way as SVA mode
+ */
+ mm_ops->sva_mode = true;
+ } else if (!ret) {
+ mm_ops->sva_mode = false;
+ } else {
+ WD_ERR("failed to check ctx!\n");
+ return ret;
+ }
+
+ /*
+ * Under SVA mode, there is no need to consider the memory type;
+ * directly proceed with virtual memory handling
+ */
+ if (mm_ops->sva_mode) {
+ mm_ops->alloc = (void *)wd_internal_alloc;
+ mm_ops->free = (void *)wd_internal_free;
+ mm_ops->iova_map = NULL;
+ mm_ops->iova_unmap = NULL;
+ mm_ops->get_bufsize = (void *)wd_mem_bufsize;
+ mm_ops->usr = NULL;
+ return 0;
+ }
+
+ switch (mem_type) {
+ case UADK_MEM_AUTO:
+ /*
+ * The memory pool needs to be allocated according to
+ * the block size when it is first executed in the UADK
+ */
+ mm_ops->usr = NULL;
+ WD_ERR("automatic under No-SVA mode is not supported!\n");
+ return -WD_EINVAL;
+ case UADK_MEM_USER:
+ if (!mm_ops->alloc || !mm_ops->free || !mm_ops->iova_map ||
+ !mm_ops->iova_unmap || !mm_ops->usr) { // The user create a memory pool
+ WD_ERR("failed to check memory ops, some ops function is NULL!\n");
+ return -WD_EINVAL;
+ }
+ break;
+ case UADK_MEM_PROXY:
+ if (!mm_ops->usr) {
+ WD_ERR("failed to check memory pool!\n");
+ return -WD_EINVAL;
+ }
+ mm_ops->alloc = (void *)wd_mem_alloc;
+ mm_ops->free = (void *)wd_mem_free;
+ mm_ops->iova_map = (void *)wd_mem_map;
+ mm_ops->iova_unmap = (void *)wd_mem_unmap;
+ mm_ops->get_bufsize = (void *)wd_get_bufsize;
+ break;
+ default:
+ WD_ERR("failed to check memory type!\n");
+ return -WD_EINVAL;
+ }
+
+ return 0;
+}
+
static void clone_ctx_to_internal(struct wd_ctx *ctx,
struct wd_ctx_internal *ctx_in)
{
@@ -257,6 +341,12 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in,
WD_ERR("failed to init ctxs lock!\n");
goto err_out;
}
+
+ ret = wd_insert_ctx_list(cfg->ctxs[i].ctx, in->alg_name);
+ if (ret) {
+ WD_ERR("failed to add ctx to mem list!\n");
+ goto err_out;
+ }
}
in->ctxs = ctxs;
@@ -318,6 +408,7 @@ void wd_clear_ctx_config(struct wd_ctx_config_internal *in)
in->ctxs = NULL;
}
+ wd_remove_ctx_list();
wd_shm_delete(in);
}
@@ -2485,7 +2576,7 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l
/* If the ctx set number is 0, the initialization is skipped. */
if (!ctx_set_num)
- return 0;
+ return -WD_ENOPROC;
dev = wd_find_dev_by_numa(list, numa_id);
if (WD_IS_ERR(dev))
@@ -2573,7 +2664,9 @@ static int wd_init_ctx_and_sched(struct wd_init_attrs *attrs, struct bitmask *bm
for (j = 0; j < op_type_num; j++) {
ctx_nums = ctx_params->ctx_set_num[j];
ret = wd_init_ctx_set(attrs, list, idx, i, j);
- if (ret)
+ if (ret == -WD_ENOPROC)
+ continue;
+ else if (ret)
goto free_ctxs;
ret = wd_instance_sched_set(attrs->sched, ctx_nums, idx, i, j);
if (ret)
--
2.33.0
1
29
您好!
sig-AccLib 邀请您参加 2025-11-12 11:00 召开的Zoom会议
会议主题:【2025/11/12 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/83926110482?pwd=aEbqlYoZb2CHsaTYMRJs0YzjeUf7TY.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-12 11:00,
The subject of the conference is 【2025/11/12 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/83926110482?pwd=aEbqlYoZb2CHsaTYMRJs0YzjeUf7TY.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
您好!
sig-AccLib 邀请您参加 2025-10-29 11:00 召开的Zoom会议
会议主题:2025/10/29 AccLIb SIG 双周例会 11:00 - 12:00
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/81029452568?pwd=gFECql6wHjvNVBSmZO2bUBF7JiKvAX.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-10-29 11:00,
The subject of the conference is 2025/10/29 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/81029452568?pwd=gFECql6wHjvNVBSmZO2bUBF7JiKvAX.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
您好!
sig-AccLib 邀请您参加 2025-10-15 11:00 召开的Zoom会议
会议主题:【2025/10/15 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接: linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/83929445214?pwd=16oKu20KnPBdVaw4nLVb30eX4o93EB.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-10-15 11:00,
The subject of the conference is 【2025/10/15 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/83929445214?pwd=16oKu20KnPBdVaw4nLVb30eX4o93EB.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
27 Sep '25
Convert signed to unsigned in uadk drv bitwise operations
Signed-off-by: ZongYu Wu <wuzongyu1(a)huawei.com>
---
drv/hisi_comp_huf.c | 11 ++++++-----
v1/drv/hisi_zip_huf.c | 10 ++++++----
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/drv/hisi_comp_huf.c b/drv/hisi_comp_huf.c
index 3684a18..161fee4 100644
--- a/drv/hisi_comp_huf.c
+++ b/drv/hisi_comp_huf.c
@@ -76,7 +76,7 @@ static long read_bits(struct bit_reader *br, __u32 n)
if (br->cur_pos + n > br->total_bits)
return -WD_EINVAL;
- ret = (br->data >> br->cur_pos) & ((1L << n) - 1L);
+ ret = (br->data >> br->cur_pos) & ((1UL << n) - 1UL);
br->cur_pos += n;
return ret;
@@ -85,7 +85,7 @@ static long read_bits(struct bit_reader *br, __u32 n)
static int check_store_huffman_block(struct bit_reader *br)
{
__u32 pad, bit_len;
- long data;
+ unsigned long data;
bit_len = br->total_bits - br->cur_pos;
@@ -111,8 +111,8 @@ static int check_store_huffman_block(struct bit_reader *br)
static int check_fix_huffman_block(struct bit_reader *br)
{
- long bit, len_idx, dist_code, extra;
- long code, bits;
+ long bits, bit, len_idx, dist_code, extra;
+ unsigned long code, ubit;
while (br->cur_pos < br->total_bits) {
/* reads 7~9 bits to determine literal/length */
@@ -123,7 +123,8 @@ static int check_fix_huffman_block(struct bit_reader *br)
if (bit < 0)
return BLOCK_IS_INCOMPLETE;
- code = (code << 1) | bit;
+ ubit = bit;
+ code = (code << 1) | ubit;
bits++;
/*
diff --git a/v1/drv/hisi_zip_huf.c b/v1/drv/hisi_zip_huf.c
index 086fa9f..61f7ab7 100644
--- a/v1/drv/hisi_zip_huf.c
+++ b/v1/drv/hisi_zip_huf.c
@@ -76,7 +76,7 @@ static long read_bits(struct bit_reader *br, __u32 n)
if (br->cur_pos + n > br->total_bits)
return -WD_EINVAL;
- ret = (br->data >> br->cur_pos) & ((1L << n) - 1L);
+ ret = (br->data >> br->cur_pos) & ((1UL << n) - 1UL);
br->cur_pos += n;
return ret;
@@ -85,7 +85,7 @@ static long read_bits(struct bit_reader *br, __u32 n)
static int check_store_huffman_block(struct bit_reader *br)
{
__u32 pad, bits;
- long data;
+ unsigned long data;
bits = br->total_bits - br->cur_pos;
@@ -111,7 +111,8 @@ static int check_store_huffman_block(struct bit_reader *br)
static int check_fix_huffman_block(struct bit_reader *br)
{
- long bit, len_idx, dist_code, extra, code;
+ long bit, len_idx, dist_code, extra;
+ unsigned long code, ubit;
__u32 bits;
while (br->cur_pos < br->total_bits) {
@@ -123,7 +124,8 @@ static int check_fix_huffman_block(struct bit_reader *br)
if (bit < 0)
return HF_BLOCK_IS_INCOMPLETE;
- code = (code << 1) | bit;
+ ubit = bit;
+ code = (code << 1) | ubit;
bits++;
/*
--
2.33.0
1
2
[PATCH] uadk: fix the issue of excessive memory allocation in reserved memory
by ZongYu Wu 19 Sep '25
by ZongYu Wu 19 Sep '25
19 Sep '25
From: Chenghai Huang <huangchenghai2(a)huawei.com>
It just need to align with 1M, but here currently, memory of a size that
is a multiple of 1M has been requested.
Signed-off-by: Chenghai Huang <huangchenghai2(a)huawei.com>
---
v1/wd_bmm.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/v1/wd_bmm.c b/v1/wd_bmm.c
index cdf5f0b..c58484f 100644
--- a/v1/wd_bmm.c
+++ b/v1/wd_bmm.c
@@ -116,12 +116,13 @@ static int wd_pool_pre_layout(struct wd_queue *q,
p->act_mem_sz = (p->act_hd_sz + p->act_blk_sz) *
(unsigned long)sp->block_num + asz;
- /* When we use WD reserve memory and the blk_sz is larger than 1M,
+ /*
+ * When we use WD reserve memory and the blk_sz is larger than 1M,
* in order to ensure the mem_pool to be success,
- * we should to reserve more memory
+ * ensure that the allocated memory is an integer multiple of 1M.
*/
if (!sp->br.alloc && !qinfo->iommu_type)
- p->act_mem_sz *= (1 + p->act_blk_sz / BLK_BALANCE_SZ);
+ p->act_mem_sz = (p->act_mem_sz + BLK_BALANCE_SZ - 1) & ~(BLK_BALANCE_SZ - 1);
return WD_SUCCESS;
}
--
2.33.0
1
2
12 Sep '25
From: Wenkai Lin <linwenkai6(a)hisilicon.com>
There is an issue with the counter in the sec prefetch state machine,
when the length exceeding a certain number of pages may cause chaos,
and errors may carry over to the next operation. Now, when the packet
length exceeds 24KB(the hardware limit value), the prefetch is disabled.
Signed-off-by: Wenkai Lin <linwenkai6(a)hisilicon.com>
---
drv/hisi_sec.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 747d3a8..1e95ce5 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -48,6 +48,7 @@
#define SEC_SM4_XTS_GB_V3 0x1
#define SEC_AUTH_ALG_OFFSET_V3 15
#define SEC_SVA_PREFETCH_OFFSET 27
+#define SEC_SVA_PREFETCH_MAX_LEN 0x6000
#define SEC_ENABLE_SVA_PREFETCH 0x1
#define SEC_CIPHER_AUTH_V3 0xbf
#define SEC_AUTH_CIPHER_V3 0x40
@@ -1357,14 +1358,20 @@ static int fill_cipher_bd3(struct wd_cipher_msg *msg, struct hisi_sec_sqe3 *sqe)
return ret;
}
- sqe->auth_mac_key |= (__u32)SEC_ENABLE_SVA_PREFETCH << SEC_SVA_PREFETCH_OFFSET;
-
return 0;
}
+static void fill_sec_prefetch(__u8 data_fmt, __u32 len, __u16 hw_type, struct hisi_sec_sqe3 *sqe)
+{
+ if (hw_type >= HISI_QM_API_VER5_BASE ||
+ (data_fmt == WD_FLAT_BUF && len <= SEC_SVA_PREFETCH_MAX_LEN))
+ sqe->auth_mac_key |= (__u32)SEC_ENABLE_SVA_PREFETCH << SEC_SVA_PREFETCH_OFFSET;
+}
+
static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
struct wd_cipher_msg *msg = wd_msg;
struct hisi_sec_sqe3 sqe;
__u16 count = 0;
@@ -1380,6 +1387,8 @@ static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void
if (ret)
return ret;
+ fill_sec_prefetch(msg->data_fmt, msg->in_bytes, qp->q_info.hw_type, &sqe);
+
if (msg->data_fmt == WD_SGL_BUF) {
ret = hisi_sec_fill_sgl_v3(h_qp, &msg->in, &msg->out, &sqe,
msg->alg_type);
@@ -1950,6 +1959,7 @@ static void fill_digest_v3_scene(struct hisi_sec_sqe3 *sqe,
static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
struct wd_digest_msg *msg = wd_msg;
struct hisi_sec_sqe3 sqe;
__u16 count = 0;
@@ -1990,7 +2000,8 @@ static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void
hisi_set_msg_id(h_qp, &msg->tag);
sqe.tag = (__u64)(uintptr_t)msg->tag;
- sqe.auth_mac_key |= (__u32)SEC_ENABLE_SVA_PREFETCH << SEC_SVA_PREFETCH_OFFSET;
+
+ fill_sec_prefetch(msg->data_fmt, msg->in_bytes, qp->q_info.hw_type, &sqe);
ret = hisi_qm_send(h_qp, &sqe, 1, &count);
if (ret < 0) {
@@ -2912,7 +2923,6 @@ static int fill_aead_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe)
sqe->c_len_ivin = msg->in_bytes;
sqe->cipher_src_offset = msg->assoc_bytes;
sqe->a_len_key = msg->in_bytes + msg->assoc_bytes;
- sqe->auth_mac_key |= (__u32)SEC_ENABLE_SVA_PREFETCH << SEC_SVA_PREFETCH_OFFSET;
ret = fill_aead_bd3_alg(msg, sqe);
if (ret) {
@@ -2932,6 +2942,7 @@ static int fill_aead_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe)
static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
struct wd_aead_msg *msg = wd_msg;
struct hisi_sec_sqe3 sqe;
__u16 count = 0;
@@ -2955,6 +2966,9 @@ static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *
if (unlikely(ret))
return ret;
+ fill_sec_prefetch(msg->data_fmt, msg->in_bytes + msg->assoc_bytes,
+ qp->q_info.hw_type, &sqe);
+
if (msg->data_fmt == WD_SGL_BUF) {
ret = hisi_sec_fill_sgl_v3(h_qp, &msg->in, &msg->out, &sqe,
msg->alg_type);
--
2.33.0
1
0
您好!
sig-AccLib 邀请您参加 2025-09-03 11:00 召开的Zoom会议
会议主题:【2025/9/3 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接 linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/86320332510?pwd=naSQBzymGAEm87frSKnpAVAMyPl59N.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-09-03 11:00,
The subject of the conference is 【2025/9/3 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/86320332510?pwd=naSQBzymGAEm87frSKnpAVAMyPl59N.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
Remove nosva limitation to permit nosva run
Signed-off-by: Zhangfei Gao <zhangfei.gao(a)linaro.org>
---
wd.c | 4 ----
wd_alg.c | 44 +-------------------------------------------
wd_util.c | 4 ----
3 files changed, 1 insertion(+), 51 deletions(-)
diff --git a/wd.c b/wd.c
index 75a9469..5fa8feb 100644
--- a/wd.c
+++ b/wd.c
@@ -235,10 +235,6 @@ static int get_dev_info(struct uacce_dev *dev)
ret = get_int_attr(dev, "flags", &dev->flags);
if (ret < 0)
return ret;
- else if (!((unsigned int)dev->flags & UACCE_DEV_SVA)) {
- WD_ERR("skip none sva uacce device!\n");
- return -WD_ENODEV;
- }
ret = get_int_attr(dev, "region_mmio_size", &value);
if (ret < 0)
diff --git a/wd_alg.c b/wd_alg.c
index 08f0e2e..45619ba 100644
--- a/wd_alg.c
+++ b/wd_alg.c
@@ -23,47 +23,6 @@ static struct wd_alg_list alg_list_head;
static struct wd_alg_list *alg_list_tail = &alg_list_head;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-
-static bool wd_check_dev_sva(const char *dev_name)
-{
- char dev_path[PATH_MAX] = {'\0'};
- char buf[DEV_SVA_SIZE] = {'\0'};
- unsigned int val;
- ssize_t ret;
- int fd;
-
- ret = snprintf(dev_path, PATH_STR_SIZE, "%s/%s/%s", SYS_CLASS_DIR,
- dev_name, SVA_FILE_NAME);
- if (ret < 0) {
- WD_ERR("failed to snprintf, device name: %s!\n", dev_name);
- return false;
- }
-
- /**
- * The opened file is the specified device driver file.
- * no need for realpath processing.
- */
- fd = open(dev_path, O_RDONLY, 0);
- if (fd < 0) {
- WD_ERR("failed to open %s(%d)!\n", dev_path, -errno);
- return false;
- }
-
- ret = read(fd, buf, DEV_SVA_SIZE - 1);
- if (ret <= 0) {
- WD_ERR("failed to read anything at %s!\n", dev_path);
- close(fd);
- return false;
- }
- close(fd);
-
- val = strtol(buf, NULL, STR_DECIMAL);
- if (val & UACCE_DEV_SVA)
- return true;
-
- return false;
-}
-
static bool wd_check_accel_dev(const char *dev_name)
{
struct dirent *dev_dir;
@@ -80,8 +39,7 @@ static bool wd_check_accel_dev(const char *dev_name)
!strncmp(dev_dir->d_name, "..", LINUX_PRTDIR_SIZE))
continue;
- if (!strncmp(dev_dir->d_name, dev_name, strlen(dev_name)) &&
- wd_check_dev_sva(dev_dir->d_name)) {
+ if (!strncmp(dev_dir->d_name, dev_name, strlen(dev_name))) {
closedir(wd_class);
return true;
}
diff --git a/wd_util.c b/wd_util.c
index f1b27bf..9675098 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -1883,10 +1883,6 @@ int wd_init_param_check(struct wd_ctx_config *config, struct wd_sched *sched)
return -WD_EINVAL;
}
- if (!wd_is_sva(config->ctxs[0].ctx)) {
- WD_ERR("invalid: the mode is non sva, please check system!\n");
- return -WD_EINVAL;
- }
return 0;
}
--
2.25.1
2
10
21 Aug '25
From: lizhi <lizhi206(a)huawei.com>
On some Ubuntu systems, the gcc compiler disables the DATE and TIME
macros via the -Wdate-time flag during compilation.
To ensure the compilation timestamp feature remains functional,
this issue is addressed through the Makefile.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
---
uadk_tool/Makefile.am | 6 ++++++
uadk_tool/dfx/uadk_dfx.c | 6 +++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am
index 6fd9d95..9ae9fd7 100644
--- a/uadk_tool/Makefile.am
+++ b/uadk_tool/Makefile.am
@@ -1,10 +1,16 @@
ACLOCAL_AMFLAGS = -I m4 -I./include
AUTOMAKE_OPTIONS = foreign subdir-objects
+
+# get UADK build time
+BUILD_DATETIME := $(shell date -u +"%Y-%m-%d_%H:%M:%S")
+
AM_CFLAGS=-Wall -Werror -fno-strict-aliasing -I$(top_srcdir) -I$(top_srcdir)/benchmark/include \
-pthread
AM_CFLAGS += -fPIC -fPIE -pie -fstack-protector-strong -D_FORTIFY_SOURCE=2 \
-O2 -ftrapv -Wl,-z,now -Wl,-s
+AM_CFLAGS += -DUADK_BUILD_DATETIME=\"$(BUILD_DATETIME)\"
+
#AUTOMAKE_OPTIONS = subdir-objects
bin_PROGRAMS=uadk_tool
diff --git a/uadk_tool/dfx/uadk_dfx.c b/uadk_tool/dfx/uadk_dfx.c
index 9c54b7b..8afcb15 100644
--- a/uadk_tool/dfx/uadk_dfx.c
+++ b/uadk_tool/dfx/uadk_dfx.c
@@ -14,7 +14,11 @@
#include "include/wd.h"
#include "uadk_dfx.h"
-#define uadk_build_date() printf("built on: %s %s\n", __DATE__, __TIME__)
+#ifndef UADK_BUILD_DATETIME
+#define UADK_BUILD_DATETIME "unknown"
+#endif
+
+#define uadk_build_date() printf("built on: %s\n", UADK_BUILD_DATETIME)
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define PRIVILEGE_FLAG 0666
--
2.33.0
1
0
19 Aug '25
From: Longfang Liu <liulongfang(a)huawei.com>
After removing the shared queue memory allocation interface, the UADK
test tools must also eliminate the shared memory functionality.
For individual memory reservations, the wd_reserve_memory interface
should be used. When allocating memory for multiple queues, each queue
should independently request its own reserved memory allocation.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
---
v1/test/hisi_hpre_test/hpre_test_tools.c | 392 -----------------------
v1/test/hisi_zip_test_sgl/wd_sched_sgl.c | 310 +++++++++---------
v1/test/test_mm/test_wd_mem.c | 8 +-
v1/test/wd_sched.c | 247 +++++++-------
4 files changed, 300 insertions(+), 657 deletions(-)
diff --git a/v1/test/hisi_hpre_test/hpre_test_tools.c b/v1/test/hisi_hpre_test/hpre_test_tools.c
index 7f562f34..10a4ade9 100755
--- a/v1/test/hisi_hpre_test/hpre_test_tools.c
+++ b/v1/test/hisi_hpre_test/hpre_test_tools.c
@@ -644,317 +644,6 @@ int application_release_multiple_queue(char *dev, char *alg_type, unsigned int q
printf("application_release_multiple_queue test end!\n");
return 0;
}
-
-/***
-
-***/
-int hpre_dev_queue_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_node_queue_share(char *dev, unsigned int node, unsigned int share_node, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
- q.node_mask = node;
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- target_q.node_mask = node;
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on target q fail!\n");
- return 1;
- }
-
- ret = wd_share_reserved_memory(&q, &target_q);
-
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on share q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on share target q fail!\n");
- return 1;
- }
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_dev_queue_interact_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return ret;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- addr = wd_reserve_memory(&target_q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- //target_q
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
-/***
-
-***/
-int hpre_dev_queue_cross_proc_share(char *dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- pid_t pid;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size=0;
-
- pid = fork();
- if(pid < 0)
- {
- printf("Creation process failed, pid:%d\n",pid);
- return 1;
- }
- else if(pid == 0)
- {
- printf("child process:%d\n", pid);
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("request queue fail!\n");
- exit(1);
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("queue reserve memory fail!\n");
- exit(2);
- }
- printf("queue reserve memory success!\n");
- memset(addr, 0, memory_size);
- exit(0);
- }
- printf("parent process:%d\n", pid);
- pid_t wpid;
- int status = -1;
- wpid = waitpid(pid, &status, WUNTRACED | WCONTINUED);
- if( wpid < 0)
- {
- printf("exited, status=%d\n", WEXITSTATUS(status));
- return(status);
- }
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&target_q);
- wd_release_queue(&q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
/***
***/
@@ -1696,87 +1385,6 @@ int main(int arc, char *argv[])
return 1;
}
}
- else if(!strcmp(argv[1], "queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "node-queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示设备node
- argv[5] - 表示共享内存设备node
- argv[6] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- unsigned int node=0;
- node = strtoul(argv[4], NULL, 16);
- unsigned int share_node=0;
- share_node = strtoul(argv[5], NULL, 16);
- memory_size = strtoul(argv[6], NULL, 10);
-
- ret = hpre_node_queue_share(dev, node, share_node, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-interact-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //队列预留内存后作为共享的目标队列
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_interact_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-cross-proc-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示申请队列的预留内存大小
- ***/
- //跨进程进行队列共享
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- memory_size = strtoul(argv[4], NULL, 10);
- ret = hpre_dev_queue_cross_proc_share(dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
else if(!strcmp(argv[1], "mult-thread-queue"))
{
/***
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 31637565..7a3be22c 100644
--- a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
+++ b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
@@ -23,96 +23,33 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
- } else { /* use sgl */
- sched->msgs[i].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
- sched->msgs[i].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i, data_fmt);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- } else { /* use sgl */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_sgl(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_sgl(pool, sched->msgs[i].data_out);
- }
- wd_sglpool_destroy(pool);
- }
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
@@ -124,14 +61,6 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
struct wd_sglpool_setup sp;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -145,12 +74,22 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
+ return 0;
+ }
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
+ goto out_with_queues;
+ }
+
+ qinfo = sched->qs[i].qinfo;
pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -162,15 +101,18 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
qinfo->br.iova_map = (void *)wd_blk_iova_map;
qinfo->br.iova_unmap = (void *)wd_blk_iova_unmap;
qinfo->br.usr = pool;
- } else { /* use sgl*/
- memset(&sp, 0, sizeof(sp));
- sp.buf_size = sched->msg_data_size / 10;
- sp.align_size = 64;
- sp.sge_num_in_sgl = 60;
- sp.buf_num_in_sgl = sp.sge_num_in_sgl;
- sp.sgl_num = 3 * sched->msg_cache_num;
- sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
-
+ }
+ } else { /* use sgl*/
+ memset(&sp, 0, sizeof(sp));
+ sp.buf_size = sched->msg_data_size / 10;
+ sp.align_size = 64;
+ sp.sge_num_in_sgl = 60;
+ sp.buf_num_in_sgl = sp.sge_num_in_sgl;
+ sp.sgl_num = 3 * sched->msg_cache_num;
+ sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
pool = wd_sglpool_create(&sched->qs[0], &sp);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -189,17 +131,132 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
+
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ } else { /* use sgl */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_sgl(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_sgl(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
+
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
+ qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
+ flags = qinfo->dev_flags;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ } else { /* use sgl */
+ sched->msgs[j].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
+ sched->msgs[j].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ }
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j, data_fmt);
+ }
+ }
+
+ return 0;
+
+err_with_stat:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched, data_fmt);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
{
@@ -211,57 +268,22 @@ int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
if (ret < 0)
return -EINVAL;
- qinfo = sched->qs[0].qinfo;
- flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
- }
- }
- }
-
sched->cl = sched->msg_cache_num;
ret = __init_cache(sched, data_fmt);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched, data_fmt);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched, data_fmt);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched, data_fmt);
}
static int __sync_send(struct wd_scheduler *sched)
@@ -350,4 +372,4 @@ int wd_sched_work(struct wd_scheduler *sched, int remained)
}
return sched->cl;
-}
\ No newline at end of file
+}
diff --git a/v1/test/test_mm/test_wd_mem.c b/v1/test/test_mm/test_wd_mem.c
index 09824b99..e2eec60e 100644
--- a/v1/test/test_mm/test_wd_mem.c
+++ b/v1/test/test_mm/test_wd_mem.c
@@ -208,10 +208,10 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo1.q, &rsa_q);
+ ret = wd_request_queue(&pdata->qinfo1.q);
if (ret) {
wd_release_queue(&rsa_q);
- MMT_PRT("Proc-%d, thrd-%d:share mem on rsa queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:rsa queue fail!\n",
pid, thread_id);
return NULL;
}
@@ -226,9 +226,9 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo2.q, &zlib_q);
+ ret = wd_request_queue(&pdata->qinfo2.q);
if (ret) {
- MMT_PRT("Proc-%d, thrd-%d:share mem on zlib queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:zlib queue fail!\n",
pid, thread_id);
goto fail_release;
diff --git a/v1/test/wd_sched.c b/v1/test/wd_sched.c
index f5e46699..ce1d2604 100644
--- a/v1/test/wd_sched.c
+++ b/v1/test/wd_sched.c
@@ -22,94 +22,40 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched)
{
- int ret, i, j;
+ struct wd_blkpool_setup mm_setup;
unsigned int flags = 0;
struct q_info *qinfo;
- struct wd_blkpool_setup mm_setup;
+ int ret, i, j;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -120,18 +66,29 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
sched->ss_region = malloc(sched->ss_region_size);
if (!sched->ss_region) {
WD_ERR("fail to alloc sched ss region mem!\n");
+ return -ENOMEM;
+ }
+ return 0;
+ }
+
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
- pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
+
+ qinfo = sched->qs[i].qinfo;
+ pool = wd_blkpool_create(&sched->qs[i], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
ret = -ENOMEM;
+ wd_release_queue(&sched->qs[i]);
goto out_with_queues;
}
qinfo->br.alloc = (void *)wd_alloc_blk;
@@ -144,79 +101,135 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
-int wd_sched_init(struct wd_scheduler *sched)
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched)
{
- int ret, j, k;
- unsigned int flags;
struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
- ret = wd_sched_preinit(sched);
- if (ret < 0)
- return -EINVAL;
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_alloc;
}
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j);
}
}
- sched->cl = sched->msg_cache_num;
+ return 0;
+
+err_with_alloc:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
+
+int wd_sched_init(struct wd_scheduler *sched)
+{
+ int ret;
+ ret = wd_sched_preinit(sched);
+ if (ret < 0)
+ return -EINVAL;
+
+ sched->cl = sched->msg_cache_num;
ret = __init_cache(sched);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched);
}
static int __sync_send(struct wd_scheduler *sched)
--
2.33.0
1
0
From: Longfang Liu <liulongfang(a)huawei.com>
In the No-SVA mode of UADK, a feature was implemented to reserve
memory allocated for shared queues, which was exposed to external
users through the wd_share_reserved_memory interface.
After this functionality was removed from the kernel-space UACCE,
the corresponding external interface in UADK must also be deleted
to maintain consistency.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
---
v1/uacce.h | 1 -
v1/wd.c | 57 ++----------------------------------------------------
v1/wd.h | 2 --
3 files changed, 2 insertions(+), 58 deletions(-)
diff --git a/v1/uacce.h b/v1/uacce.h
index eef932c7..ffd576c1 100644
--- a/v1/uacce.h
+++ b/v1/uacce.h
@@ -79,7 +79,6 @@ enum uacce_qfrt {
* Optimization method since close fd may delay
*/
#define WD_UACCE_CMD_PUT_Q _IO('W', 1)
-#define WD_UACCE_CMD_SHARE_SVAS _IO('W', 2)
#define WD_UACCE_CMD_GET_SS_DMA _IOR('W', 3, unsigned long)
#endif
diff --git a/v1/wd.c b/v1/wd.c
index 13239b58..bab2712f 100644
--- a/v1/wd.c
+++ b/v1/wd.c
@@ -58,7 +58,6 @@ struct dev_info {
int node_id;
int numa_dis;
int flags;
- int ref;
int available_instances;
int iommu_type;
unsigned int weight;
@@ -531,7 +530,6 @@ static int get_queue_from_dev(struct wd_queue *q, const struct dev_info *dev)
qinfo->iommu_type = dev->iommu_type;
qinfo->dev_info = dev;
qinfo->head = &qinfo->ss_list;
- __atomic_clear(&qinfo->ref, __ATOMIC_RELEASE);
TAILQ_INIT(&qinfo->ss_list);
memcpy(qinfo->qfrs_offset, dev->qfrs_offset,
sizeof(qinfo->qfrs_offset));
@@ -618,23 +616,14 @@ err_with_dev:
void wd_release_queue(struct wd_queue *q)
{
- struct wd_ss_region_list *head;
- struct q_info *qinfo, *sqinfo;
+ struct q_info *qinfo;
if (!q || !q->qinfo) {
WD_ERR("release queue parameter error!\n");
return;
}
- qinfo = q->qinfo;
- if (__atomic_load_n(&qinfo->ref, __ATOMIC_RELAXED)) {
- WD_ERR("q(%s) is busy, release fail!\n", q->capa.alg);
- return;
- }
- head = qinfo->head;
- sqinfo = container_of(head, struct q_info, ss_list);
- if (sqinfo != qinfo) /* q_share */
- __atomic_sub_fetch(&sqinfo->ref, 1, __ATOMIC_RELAXED);
+ qinfo = q->qinfo;
if (ioctl(qinfo->fd, WD_UACCE_CMD_PUT_Q))
WD_ERR("failed to put queue!\n");
@@ -721,48 +710,6 @@ void *wd_reserve_memory(struct wd_queue *q, size_t size)
return drv_reserve_mem(q, size);
}
-int wd_share_reserved_memory(struct wd_queue *q,
- struct wd_queue *target_q)
-{
- const struct dev_info *info, *tgt_info;
- struct q_info *qinfo, *tqinfo;
- int ret;
-
- if (!q || !target_q || !q->qinfo || !target_q->qinfo) {
- WD_ERR("wd share reserved memory: parameter err!\n");
- return -WD_EINVAL;
- }
-
- qinfo = q->qinfo;
- tqinfo = target_q->qinfo;
- tgt_info = tqinfo->dev_info;
- info = qinfo->dev_info;
-
- /* Just share DMA memory from 'q' in NO-IOMMU mode */
- if (qinfo->iommu_type) {
- WD_ERR("IOMMU opened, not support share mem!\n");
- return -WD_EINVAL;
- }
-
- if (qinfo->iommu_type != tqinfo->iommu_type) {
- WD_ERR("IOMMU type mismatching as share mem!\n");
- return -WD_EINVAL;
- }
- if (info->node_id != tgt_info->node_id)
- WD_ERR("Warn: the 2 queues is not at the same node!\n");
-
- ret = ioctl(qinfo->fd, WD_UACCE_CMD_SHARE_SVAS, tqinfo->fd);
- if (ret) {
- WD_ERR("ioctl share dma memory fail!\n");
- return ret;
- }
-
- tqinfo->head = qinfo->head;
- __atomic_add_fetch(&qinfo->ref, 1, __ATOMIC_RELAXED);
-
- return 0;
-}
-
int wd_get_available_dev_num(const char *algorithm)
{
struct wd_queue q;
diff --git a/v1/wd.h b/v1/wd.h
index 79b8a2ad..35dcf31a 100644
--- a/v1/wd.h
+++ b/v1/wd.h
@@ -210,8 +210,6 @@ int wd_recv(struct wd_queue *q, void **resp);
int wd_wait(struct wd_queue *q, __u16 ms);
int wd_recv_sync(struct wd_queue *q, void **resp, __u16 ms);
void *wd_reserve_memory(struct wd_queue *q, size_t size);
-int wd_share_reserved_memory(struct wd_queue *q,
- struct wd_queue *target_q);
int wd_get_available_dev_num(const char *algorithm);
int wd_get_node_id(struct wd_queue *q);
void *wd_iova_map(struct wd_queue *q, void *va, size_t sz);
--
2.33.0
1
0
*** BLURB HERE ***
Chenghai Huang (7):
uadk: fix definition coding standard issues
uadk: add or remove some store buf condition judgments
uadk: add new alg called lz77_only
uadk: remove redundant checks on bit read results
uadk_tool: modify unrecv num in async benchmark test
uadk_tool: add lz77_only alg in zip benchmark test
uadk_tool: add lz4 alg in zip benchmark test
Longfang Liu (3):
uadk: resolve some code issues
uadk: removal of the Shared Memory Interface for Queues
uadk_tools: Removal of the Shared Memory Interface for Queues
Qi Tao (1):
uadk_tool: add aead algorithm
Qinxin Xia (3):
uadk: hisi_comp - abstract get sgl function and general deflate
functions
uadk: hisi_comp - support the new algorithm 'lz4'
uadk: wd_comp - support the new algorithm 'lz4'
Weili Qian (1):
uadk: support data move
Wenkai Lin (2):
uadk: fix for rehash invalid size
uadk: support hashjoin and gather algorithm
Zhushuai Yin (5):
uadk: Add max and min operations at the hash algorithm layer
uadk: hash agg adapter drv parameter
uadk:Add max,min,and rehash implementations
uadk:zip algorithm increases buffer len interception
uadk:fix dh prov segmentation issue
Makefile.am | 31 +-
drv/hisi_comp.c | 580 +++++--
drv/hisi_comp_huf.c | 11 +-
drv/hisi_dae.c | 827 +++-------
drv/hisi_dae.h | 229 +++
drv/hisi_dae_common.c | 387 +++++
drv/hisi_dae_join_gather.c | 1040 ++++++++++++
drv/hisi_qm_udrv.h | 3 +-
drv/hisi_udma.c | 566 +++++++
include/drv/wd_agg_drv.h | 10 +-
include/drv/wd_join_gather_drv.h | 52 +
include/drv/wd_udma_drv.h | 34 +
include/wd_agg.h | 9 +-
include/wd_alg.h | 4 +
include/wd_comp.h | 2 +
include/wd_dae.h | 12 +
include/wd_join_gather.h | 352 +++++
include/wd_udma.h | 124 ++
include/wd_util.h | 2 +
libwd_dae.map | 34 +-
uadk_tool/benchmark/sec_uadk_benchmark.c | 34 +
uadk_tool/benchmark/sec_wd_benchmark.c | 34 +
uadk_tool/benchmark/uadk_benchmark.c | 14 +
uadk_tool/benchmark/uadk_benchmark.h | 4 +
uadk_tool/benchmark/zip_uadk_benchmark.c | 24 +-
v1/drv/hisi_zip_huf.c | 11 +-
v1/drv/hisi_zip_udrv.c | 2 +-
v1/test/hisi_hpre_test/hpre_test_tools.c | 392 -----
v1/test/hisi_zip_test_sgl/wd_sched_sgl.c | 310 ++--
v1/test/test_mm/test_wd_mem.c | 8 +-
v1/test/wd_sched.c | 247 +--
v1/uacce.h | 1 -
v1/wd.c | 57 +-
v1/wd.h | 2 -
wd.c | 2 +-
wd_agg.c | 75 +-
wd_comp.c | 56 +-
wd_join_gather.c | 1823 ++++++++++++++++++++++
wd_sched.c | 3 +-
wd_udma.c | 511 ++++++
wd_util.c | 34 +-
41 files changed, 6435 insertions(+), 1518 deletions(-)
create mode 100644 drv/hisi_dae.h
create mode 100644 drv/hisi_dae_common.c
create mode 100644 drv/hisi_dae_join_gather.c
create mode 100644 drv/hisi_udma.c
create mode 100644 include/drv/wd_join_gather_drv.h
create mode 100644 include/drv/wd_udma_drv.h
create mode 100644 include/wd_join_gather.h
create mode 100644 include/wd_udma.h
create mode 100644 wd_join_gather.c
create mode 100644 wd_udma.c
--
2.33.0
1
22
From: Chenghai Huang <huangchenghai2(a)huawei.com>
Supports LZ77 encoding for LZ4 without additional offset
processing. The output includes literal and sequence (LitLength,
MatchLength, Offset).
Signed-off-by: Chenghai Huang <huangchenghai2(a)huawei.com>
---
drv/hisi_comp.c | 310 +++++++++++++++++++++++++++++++++++++---------
include/wd_comp.h | 1 +
wd_comp.c | 2 +-
wd_util.c | 1 +
4 files changed, 255 insertions(+), 59 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index 0c36301d..1c9f438f 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -84,6 +84,9 @@
#define OVERFLOW_DATA_SIZE 8
#define SEQ_DATA_SIZE_SHIFT 3
#define ZSTD_FREQ_DATA_SIZE 784
+#define ZSTD_MIN_OUT_SIZE 1000
+#define LZ77_MIN_OUT_SIZE 200
+#define PRICE_MIN_OUT_SIZE 4096
#define ZSTD_LIT_RESV_SIZE 16
#define REPCODE_SIZE 12
@@ -108,6 +111,8 @@ enum alg_type {
HW_GZIP,
HW_LZ77_ZSTD_PRICE = 0x42,
HW_LZ77_ZSTD,
+ HW_LZ77_ONLY = 0x40,
+ HW_LZ77_ONLY_PRICE,
};
enum hw_state {
@@ -616,31 +621,30 @@ static void fill_buf_addr_lz77_zstd(struct hisi_zip_sqe *sqe,
sqe->stream_ctx_addr_h = upper_32_bits(ctx_buf);
}
-static int fill_buf_lz77_zstd(handle_t h_qp, struct hisi_zip_sqe *sqe,
- struct wd_comp_msg *msg)
+static int lz77_zstd_buf_check(struct wd_comp_msg *msg)
{
- struct wd_comp_req *req = &msg->req;
- struct wd_lz77_zstd_data *data = req->priv;
__u32 in_size = msg->req.src_len;
- __u32 lits_size = in_size + ZSTD_LIT_RESV_SIZE;
__u32 out_size = msg->avail_out;
- void *ctx_buf = NULL;
+ __u32 lits_size = in_size + ZSTD_LIT_RESV_SIZE;
+ __u32 seq_avail_out = out_size - lits_size;
- if (unlikely(!data)) {
- WD_ERR("invalid: wd_lz77_zstd_data address is NULL!\n");
- return -WD_EINVAL;
+ if (unlikely(in_size > ZSTD_MAX_SIZE)) {
+ WD_ERR("invalid: in_len(%u) of lz77_zstd is out of range!\n", in_size);
+ return -WD_EINVAL;
}
- if (unlikely(in_size > ZSTD_MAX_SIZE)) {
- WD_ERR("invalid: in_len(%u) of lz77_zstd is out of range!\n",
- in_size);
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv < WD_COMP_L9 &&
+ seq_avail_out <= ZSTD_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum!\n",
+ out_size, ZSTD_MIN_OUT_SIZE + lits_size);
return -WD_EINVAL;
}
- if (unlikely(out_size > HZ_MAX_SIZE)) {
- WD_ERR("warning: avail_out(%u) is out of range , will set 8MB size max!\n",
- out_size);
- out_size = HZ_MAX_SIZE;
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv == WD_COMP_L9 &&
+ seq_avail_out <= PRICE_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum in price mode!\n",
+ out_size, PRICE_MIN_OUT_SIZE + lits_size);
+ return -WD_EINVAL;
}
/*
@@ -653,14 +657,92 @@ static int fill_buf_lz77_zstd(handle_t h_qp, struct hisi_zip_sqe *sqe,
return -WD_EINVAL;
}
+ return 0;
+}
+
+static int lz77_only_buf_check(struct wd_comp_msg *msg)
+{
+ __u32 in_size = msg->req.src_len;
+ __u32 out_size = msg->avail_out;
+ __u32 lits_size = in_size + ZSTD_LIT_RESV_SIZE;
+ __u32 seq_avail_out = out_size - lits_size;
+
+ /* lits_size need to be less than 8M when use pbuffer */
+ if (unlikely(lits_size > HZ_MAX_SIZE)) {
+ WD_ERR("invalid: in_len(%u) of lz77_only is out of range!\n", in_size);
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv < WD_COMP_L9 &&
+ seq_avail_out <= LZ77_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum!\n",
+ out_size, LZ77_MIN_OUT_SIZE + lits_size);
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv == WD_COMP_L9 &&
+ seq_avail_out <= PRICE_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum in price mode!\n",
+ out_size, PRICE_MIN_OUT_SIZE + lits_size);
+ return -WD_EINVAL;
+ }
+
+ /* For lz77_only, the hardware needs 32 Bytes buffer to output the dfx information */
+ if (unlikely(out_size < ZSTD_LIT_RESV_SIZE + lits_size)) {
+ WD_ERR("invalid: output is not enough, %u bytes are minimum!\n",
+ ZSTD_LIT_RESV_SIZE + lits_size);
+ return -WD_EINVAL;
+ }
+
+ return 0;
+}
+
+static int lz77_buf_check(struct wd_comp_msg *msg)
+{
+ enum wd_comp_alg_type alg_type = msg->alg_type;
+
+ if (alg_type == WD_LZ77_ZSTD)
+ return lz77_zstd_buf_check(msg);
+ else if (alg_type == WD_LZ77_ONLY)
+ return lz77_only_buf_check(msg);
+
+ return 0;
+}
+
+static int fill_buf_lz77_zstd(handle_t h_qp, struct hisi_zip_sqe *sqe,
+ struct wd_comp_msg *msg)
+{
+ struct wd_comp_req *req = &msg->req;
+ struct wd_lz77_zstd_data *data = req->priv;
+ __u32 in_size = msg->req.src_len;
+ __u32 lits_size = in_size + ZSTD_LIT_RESV_SIZE;
+ __u32 seq_avail_out = msg->avail_out - lits_size;
+ void *ctx_buf = NULL;
+ int ret;
+
+ if (unlikely(!data)) {
+ WD_ERR("invalid: wd_lz77_zstd_data address is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ ret = lz77_buf_check(msg);
+ if (ret)
+ return ret;
+
+ if (unlikely(seq_avail_out > HZ_MAX_SIZE)) {
+ WD_ERR("warning: sequence avail_out(%u) is out of range , will set 8MB size max!\n",
+ seq_avail_out);
+ seq_avail_out = HZ_MAX_SIZE;
+ }
+
if (msg->ctx_buf) {
ctx_buf = msg->ctx_buf + RSV_OFFSET;
- if (data->blk_type != COMP_BLK)
+ if (msg->alg_type == WD_LZ77_ZSTD && data->blk_type != COMP_BLK)
memcpy(ctx_buf + CTX_HW_REPCODE_OFFSET,
msg->ctx_buf + CTX_REPCODE2_OFFSET, REPCODE_SIZE);
}
- fill_buf_size_lz77_zstd(sqe, in_size, lits_size, out_size - lits_size);
+ fill_buf_size_lz77_zstd(sqe, in_size, lits_size, seq_avail_out);
fill_buf_addr_lz77_zstd(sqe, req->src, req->dst, req->dst + lits_size, ctx_buf);
@@ -685,6 +767,103 @@ static struct wd_datalist *get_seq_start_list(struct wd_comp_req *req)
return cur;
}
+static int lz77_zstd_buf_check_sgl(struct wd_comp_msg *msg, __u32 lits_size)
+{
+ __u32 in_size = msg->req.src_len;
+ __u32 out_size = msg->avail_out;
+ __u32 seq_avail_out;
+
+ if (unlikely(in_size > ZSTD_MAX_SIZE)) {
+ WD_ERR("invalid: in_len(%u) of lz77_zstd is out of range!\n", in_size);
+ return -WD_EINVAL;
+ }
+
+ /*
+ * For lz77_zstd, the hardware needs 784 Bytes buffer to output
+ * the frequency information about input data. The sequences
+ * and frequency data need to be written to an independent sgl
+ * splited from list_dst.
+ */
+ if (unlikely(lits_size < in_size + ZSTD_LIT_RESV_SIZE)) {
+ WD_ERR("invalid: output is not enough for literals, at least %u bytes!\n",
+ ZSTD_FREQ_DATA_SIZE + lits_size);
+ return -WD_EINVAL;
+ } else if (unlikely(out_size < ZSTD_FREQ_DATA_SIZE + lits_size)) {
+ WD_ERR("invalid: output is not enough for sequences, at least %u bytes more!\n",
+ ZSTD_FREQ_DATA_SIZE + lits_size - out_size);
+ return -WD_EINVAL;
+ }
+
+ seq_avail_out = out_size - lits_size;
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv < WD_COMP_L9 &&
+ seq_avail_out <= ZSTD_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum!\n",
+ out_size, ZSTD_MIN_OUT_SIZE + lits_size);
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv == WD_COMP_L9 &&
+ seq_avail_out <= PRICE_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum in price mode!\n",
+ out_size, PRICE_MIN_OUT_SIZE + lits_size);
+ return -WD_EINVAL;
+ }
+
+ return 0;
+}
+
+static int lz77_only_buf_check_sgl(struct wd_comp_msg *msg, __u32 lits_size)
+{
+ __u32 in_size = msg->req.src_len;
+ __u32 out_size = msg->avail_out;
+ __u32 seq_avail_out;
+
+ /*
+ * For lz77_only, the hardware needs 32 Bytes buffer to output
+ * the dfx information. The literals and sequences data need to be written
+ * to an independent sgl splited from list_dst.
+ */
+ if (unlikely(lits_size < in_size + ZSTD_LIT_RESV_SIZE)) {
+ WD_ERR("invalid: output is not enough for literals, at least %u bytes!\n",
+ ZSTD_LIT_RESV_SIZE + lits_size);
+ return -WD_EINVAL;
+ } else if (unlikely(out_size < ZSTD_LIT_RESV_SIZE + lits_size)) {
+ WD_ERR("invalid: output is not enough for sequences, at least %u bytes more!\n",
+ ZSTD_LIT_RESV_SIZE + lits_size - out_size);
+ return -WD_EINVAL;
+ }
+
+ seq_avail_out = out_size - lits_size;
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv < WD_COMP_L9 &&
+ seq_avail_out <= LZ77_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum!\n",
+ out_size, LZ77_MIN_OUT_SIZE + lits_size);
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv == WD_COMP_L9 &&
+ seq_avail_out <= PRICE_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum in price mode!\n",
+ out_size, PRICE_MIN_OUT_SIZE + lits_size);
+ return -WD_EINVAL;
+ }
+
+ return 0;
+}
+
+
+static int lz77_buf_check_sgl(struct wd_comp_msg *msg, __u32 lits_size)
+{
+ enum wd_comp_alg_type alg_type = msg->alg_type;
+
+ if (alg_type == WD_LZ77_ZSTD)
+ return lz77_zstd_buf_check_sgl(msg, lits_size);
+ else if (alg_type == WD_LZ77_ONLY)
+ return lz77_only_buf_check_sgl(msg, lits_size);
+
+ return 0;
+}
+
static int fill_buf_lz77_zstd_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
struct wd_comp_msg *msg)
{
@@ -698,12 +877,6 @@ static int fill_buf_lz77_zstd_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
__u32 lits_size;
int ret;
- if (unlikely(in_size > ZSTD_MAX_SIZE)) {
- WD_ERR("invalid: in_len(%u) of lz77_zstd is out of range!\n",
- in_size);
- return -WD_EINVAL;
- }
-
if (unlikely(!data)) {
WD_ERR("invalid: wd_lz77_zstd_data address is NULL!\n");
return -WD_EINVAL;
@@ -715,26 +888,15 @@ static int fill_buf_lz77_zstd_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
if (unlikely(!seq_start))
return -WD_EINVAL;
+ lits_size = hisi_qm_get_list_size(req->list_dst, seq_start);
+
+ ret = lz77_buf_check_sgl(msg, lits_size);
+ if (ret)
+ return ret;
+
data->literals_start = req->list_dst;
data->sequences_start = seq_start;
- /*
- * For lz77_zstd, the hardware needs 784 Bytes buffer to output
- * the frequency information about input data. The sequences
- * and frequency data need to be written to an independent sgl
- * splited from list_dst.
- */
- lits_size = hisi_qm_get_list_size(req->list_dst, seq_start);
- if (unlikely(lits_size < in_size + ZSTD_LIT_RESV_SIZE)) {
- WD_ERR("invalid: output is not enough for literals, %u bytes are minimum!\n",
- ZSTD_FREQ_DATA_SIZE + lits_size);
- return -WD_EINVAL;
- } else if (unlikely(out_size < ZSTD_FREQ_DATA_SIZE + lits_size)) {
- WD_ERR("invalid: output is not enough for sequences, at least %u bytes more!\n",
- ZSTD_FREQ_DATA_SIZE + lits_size - out_size);
- return -WD_EINVAL;
- }
-
fill_buf_size_lz77_zstd(sqe, in_size, lits_size, out_size - lits_size);
h_sgl_pool = hisi_qm_get_sglpool(h_qp);
@@ -824,6 +986,15 @@ static void fill_alg_lz77_zstd(struct hisi_zip_sqe *sqe)
sqe->dw9 = val;
}
+static void fill_alg_lz77_only(struct hisi_zip_sqe *sqe)
+{
+ __u32 val;
+
+ val = sqe->dw9 & ~HZ_REQ_TYPE_MASK;
+ val |= HW_LZ77_ONLY;
+ sqe->dw9 = val;
+}
+
static void fill_tag_v1(struct hisi_zip_sqe *sqe, __u32 tag)
{
sqe->dw13 = tag;
@@ -841,7 +1012,7 @@ static int fill_comp_level_deflate(struct hisi_zip_sqe *sqe, enum wd_comp_level
static int fill_comp_level_lz77_zstd(struct hisi_zip_sqe *sqe, enum wd_comp_level comp_lv)
{
- __u32 val;
+ __u32 val, alg;
switch (comp_lv) {
case WD_COMP_L8:
@@ -851,8 +1022,12 @@ static int fill_comp_level_lz77_zstd(struct hisi_zip_sqe *sqe, enum wd_comp_leve
*/
break;
case WD_COMP_L9:
+ alg = sqe->dw9 & HZ_REQ_TYPE_MASK;
val = sqe->dw9 & ~HZ_REQ_TYPE_MASK;
- val |= HW_LZ77_ZSTD_PRICE;
+ if (alg == HW_LZ77_ZSTD)
+ val |= HW_LZ77_ZSTD_PRICE;
+ else if (alg == HW_LZ77_ONLY)
+ val |= HW_LZ77_ONLY_PRICE;
sqe->dw9 = val;
break;
default:
@@ -911,18 +1086,22 @@ static void get_data_size_lz77_zstd(struct hisi_zip_sqe *sqe, enum wd_comp_op_ty
if (unlikely(!data))
return;
+ recv_msg->in_cons = sqe->consumed;
data->lit_num = sqe->comp_data_length;
data->seq_num = sqe->produced;
- data->lit_length_overflow_cnt = sqe->dw31 >> LITLEN_OVERFLOW_CNT_SHIFT;
- data->lit_length_overflow_pos = sqe->dw31 & LITLEN_OVERFLOW_POS_MASK;
- data->freq = data->sequences_start + (data->seq_num << SEQ_DATA_SIZE_SHIFT) +
- OVERFLOW_DATA_SIZE;
-
- if (ctx_buf) {
- memcpy(ctx_buf + CTX_REPCODE2_OFFSET,
- ctx_buf + CTX_REPCODE1_OFFSET, REPCODE_SIZE);
- memcpy(ctx_buf + CTX_REPCODE1_OFFSET,
- ctx_buf + RSV_OFFSET + CTX_HW_REPCODE_OFFSET, REPCODE_SIZE);
+
+ if (recv_msg->alg_type == WD_LZ77_ZSTD) {
+ data->lit_length_overflow_cnt = sqe->dw31 >> LITLEN_OVERFLOW_CNT_SHIFT;
+ data->lit_length_overflow_pos = sqe->dw31 & LITLEN_OVERFLOW_POS_MASK;
+ data->freq = data->sequences_start + (data->seq_num << SEQ_DATA_SIZE_SHIFT) +
+ OVERFLOW_DATA_SIZE;
+
+ if (ctx_buf) {
+ memcpy(ctx_buf + CTX_REPCODE2_OFFSET,
+ ctx_buf + CTX_REPCODE1_OFFSET, REPCODE_SIZE);
+ memcpy(ctx_buf + CTX_REPCODE1_OFFSET,
+ ctx_buf + RSV_OFFSET + CTX_HW_REPCODE_OFFSET, REPCODE_SIZE);
+ }
}
}
@@ -970,6 +1149,16 @@ struct hisi_zip_sqe_ops ops[] = { {
.fill_comp_level = fill_comp_level_lz77_zstd,
.get_data_size = get_data_size_lz77_zstd,
.get_tag = get_tag_v3,
+ }, {
+ .alg_name = "lz77_only",
+ .fill_buf[WD_FLAT_BUF] = fill_buf_lz77_zstd,
+ .fill_buf[WD_SGL_BUF] = fill_buf_lz77_zstd_sgl,
+ .fill_sqe_type = fill_sqe_type_v3,
+ .fill_alg = fill_alg_lz77_only,
+ .fill_tag = fill_tag_v3,
+ .fill_comp_level = fill_comp_level_lz77_zstd,
+ .get_data_size = get_data_size_lz77_zstd,
+ .get_tag = get_tag_v3,
}
};
@@ -1079,10 +1268,6 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
return -WD_EINVAL;
}
- ret = ops[alg_type].fill_comp_level(sqe, msg->comp_lv);
- if (unlikely(ret))
- return ret;
-
ret = ops[alg_type].fill_buf[msg->req.data_fmt]((handle_t)qp, sqe, msg);
if (unlikely(ret))
return ret;
@@ -1091,6 +1276,10 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
ops[alg_type].fill_alg(sqe);
+ ret = ops[alg_type].fill_comp_level(sqe, msg->comp_lv);
+ if (unlikely(ret))
+ return ret;
+
ops[alg_type].fill_tag(sqe, msg->tag);
state = (msg->stream_mode == WD_COMP_STATEFUL) ? HZ_STATEFUL :
@@ -1132,7 +1321,7 @@ static void free_hw_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
hw_sgl_out = VA_ADDR(sqe->dest_addr_h, sqe->dest_addr_l);
hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_out);
- if (alg_type == WD_LZ77_ZSTD) {
+ if (alg_type == WD_LZ77_ZSTD || alg_type == WD_LZ77_ONLY) {
hw_sgl_out = VA_ADDR(sqe->literals_addr_h,
sqe->literals_addr_l);
hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_out);
@@ -1190,6 +1379,10 @@ static int get_alg_type(__u32 type)
case HW_LZ77_ZSTD_PRICE:
alg_type = WD_LZ77_ZSTD;
break;
+ case HW_LZ77_ONLY:
+ case HW_LZ77_ONLY_PRICE:
+ alg_type = WD_LZ77_ONLY;
+ break;
default:
break;
}
@@ -1369,6 +1562,7 @@ static struct wd_alg_driver zip_alg_driver[] = {
GEN_ZIP_ALG_DRIVER("deflate"),
GEN_ZIP_ALG_DRIVER("lz77_zstd"),
+ GEN_ZIP_ALG_DRIVER("lz77_only"),
};
#ifdef WD_STATIC_DRV
diff --git a/include/wd_comp.h b/include/wd_comp.h
index 45994ff6..0012ef6b 100644
--- a/include/wd_comp.h
+++ b/include/wd_comp.h
@@ -20,6 +20,7 @@ enum wd_comp_alg_type {
WD_ZLIB,
WD_GZIP,
WD_LZ77_ZSTD,
+ WD_LZ77_ONLY,
WD_COMP_ALG_MAX,
};
diff --git a/wd_comp.c b/wd_comp.c
index 647c320e..8e47a32f 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -27,7 +27,7 @@
#define cpu_to_be32(x) swap_byte(x)
static const char *wd_comp_alg_name[WD_COMP_ALG_MAX] = {
- "zlib", "gzip", "deflate", "lz77_zstd"
+ "zlib", "gzip", "deflate", "lz77_zstd", "lz77_only"
};
struct wd_comp_sess {
diff --git a/wd_util.c b/wd_util.c
index 669743cb..f21b3236 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -107,6 +107,7 @@ static struct acc_alg_item alg_options[] = {
{"gzip", "gzip"},
{"deflate", "deflate"},
{"lz77_zstd", "lz77_zstd"},
+ {"lz77_only", "lz77_only"},
{"hashagg", "hashagg"},
{"udma", "udma"},
--
2.33.0
1
5
From: Longfang Liu <liulongfang(a)huawei.com>
In the No-SVA mode of UADK, a feature was implemented to reserve
memory allocated for shared queues, which was exposed to external
users through the wd_share_reserved_memory interface.
After this functionality was removed from the kernel-space UACCE,
the corresponding external interface in UADK must also be deleted
to maintain consistency.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
---
v1/uacce.h | 1 -
v1/wd.c | 57 ++----------------------------------------------------
v1/wd.h | 2 --
3 files changed, 2 insertions(+), 58 deletions(-)
diff --git a/v1/uacce.h b/v1/uacce.h
index eef932c7..ffd576c1 100644
--- a/v1/uacce.h
+++ b/v1/uacce.h
@@ -79,7 +79,6 @@ enum uacce_qfrt {
* Optimization method since close fd may delay
*/
#define WD_UACCE_CMD_PUT_Q _IO('W', 1)
-#define WD_UACCE_CMD_SHARE_SVAS _IO('W', 2)
#define WD_UACCE_CMD_GET_SS_DMA _IOR('W', 3, unsigned long)
#endif
diff --git a/v1/wd.c b/v1/wd.c
index 13239b58..bab2712f 100644
--- a/v1/wd.c
+++ b/v1/wd.c
@@ -58,7 +58,6 @@ struct dev_info {
int node_id;
int numa_dis;
int flags;
- int ref;
int available_instances;
int iommu_type;
unsigned int weight;
@@ -531,7 +530,6 @@ static int get_queue_from_dev(struct wd_queue *q, const struct dev_info *dev)
qinfo->iommu_type = dev->iommu_type;
qinfo->dev_info = dev;
qinfo->head = &qinfo->ss_list;
- __atomic_clear(&qinfo->ref, __ATOMIC_RELEASE);
TAILQ_INIT(&qinfo->ss_list);
memcpy(qinfo->qfrs_offset, dev->qfrs_offset,
sizeof(qinfo->qfrs_offset));
@@ -618,23 +616,14 @@ err_with_dev:
void wd_release_queue(struct wd_queue *q)
{
- struct wd_ss_region_list *head;
- struct q_info *qinfo, *sqinfo;
+ struct q_info *qinfo;
if (!q || !q->qinfo) {
WD_ERR("release queue parameter error!\n");
return;
}
- qinfo = q->qinfo;
- if (__atomic_load_n(&qinfo->ref, __ATOMIC_RELAXED)) {
- WD_ERR("q(%s) is busy, release fail!\n", q->capa.alg);
- return;
- }
- head = qinfo->head;
- sqinfo = container_of(head, struct q_info, ss_list);
- if (sqinfo != qinfo) /* q_share */
- __atomic_sub_fetch(&sqinfo->ref, 1, __ATOMIC_RELAXED);
+ qinfo = q->qinfo;
if (ioctl(qinfo->fd, WD_UACCE_CMD_PUT_Q))
WD_ERR("failed to put queue!\n");
@@ -721,48 +710,6 @@ void *wd_reserve_memory(struct wd_queue *q, size_t size)
return drv_reserve_mem(q, size);
}
-int wd_share_reserved_memory(struct wd_queue *q,
- struct wd_queue *target_q)
-{
- const struct dev_info *info, *tgt_info;
- struct q_info *qinfo, *tqinfo;
- int ret;
-
- if (!q || !target_q || !q->qinfo || !target_q->qinfo) {
- WD_ERR("wd share reserved memory: parameter err!\n");
- return -WD_EINVAL;
- }
-
- qinfo = q->qinfo;
- tqinfo = target_q->qinfo;
- tgt_info = tqinfo->dev_info;
- info = qinfo->dev_info;
-
- /* Just share DMA memory from 'q' in NO-IOMMU mode */
- if (qinfo->iommu_type) {
- WD_ERR("IOMMU opened, not support share mem!\n");
- return -WD_EINVAL;
- }
-
- if (qinfo->iommu_type != tqinfo->iommu_type) {
- WD_ERR("IOMMU type mismatching as share mem!\n");
- return -WD_EINVAL;
- }
- if (info->node_id != tgt_info->node_id)
- WD_ERR("Warn: the 2 queues is not at the same node!\n");
-
- ret = ioctl(qinfo->fd, WD_UACCE_CMD_SHARE_SVAS, tqinfo->fd);
- if (ret) {
- WD_ERR("ioctl share dma memory fail!\n");
- return ret;
- }
-
- tqinfo->head = qinfo->head;
- __atomic_add_fetch(&qinfo->ref, 1, __ATOMIC_RELAXED);
-
- return 0;
-}
-
int wd_get_available_dev_num(const char *algorithm)
{
struct wd_queue q;
diff --git a/v1/wd.h b/v1/wd.h
index 79b8a2ad..35dcf31a 100644
--- a/v1/wd.h
+++ b/v1/wd.h
@@ -210,8 +210,6 @@ int wd_recv(struct wd_queue *q, void **resp);
int wd_wait(struct wd_queue *q, __u16 ms);
int wd_recv_sync(struct wd_queue *q, void **resp, __u16 ms);
void *wd_reserve_memory(struct wd_queue *q, size_t size);
-int wd_share_reserved_memory(struct wd_queue *q,
- struct wd_queue *target_q);
int wd_get_available_dev_num(const char *algorithm);
int wd_get_node_id(struct wd_queue *q);
void *wd_iova_map(struct wd_queue *q, void *va, size_t sz);
--
2.33.0
1
1
From: Weili Qian <qianweili(a)huawei.com>
UADK supports hardware acceleration for the data move.
Currently, data copying and initialization are supported.
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
Makefile.am | 27 +-
drv/hisi_udma.c | 566 ++++++++++++++++++++++++++++++++++++++
include/drv/wd_udma_drv.h | 34 +++
include/wd_alg.h | 2 +
include/wd_udma.h | 124 +++++++++
include/wd_util.h | 1 +
libwd_dae.map | 15 +-
wd_udma.c | 511 ++++++++++++++++++++++++++++++++++
wd_util.c | 2 +
9 files changed, 1278 insertions(+), 4 deletions(-)
create mode 100644 drv/hisi_udma.c
create mode 100644 include/drv/wd_udma_drv.h
create mode 100644 include/wd_udma.h
create mode 100644 wd_udma.c
diff --git a/Makefile.am b/Makefile.am
index c4b9c526..df756f72 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -36,16 +36,17 @@ pkginclude_HEADERS = include/wd.h include/wd_cipher.h include/wd_aead.h \
include/wd_comp.h include/wd_dh.h include/wd_digest.h \
include/wd_rsa.h include/uacce.h include/wd_alg_common.h \
include/wd_ecc.h include/wd_sched.h include/wd_alg.h \
- include/wd_zlibwrapper.h include/wd_dae.h include/wd_agg.h
+ include/wd_zlibwrapper.h include/wd_dae.h include/wd_agg.h \
+ include/wd_udma.h
nobase_pkginclude_HEADERS = v1/wd.h v1/wd_cipher.h v1/wd_aead.h v1/uacce.h v1/wd_dh.h \
v1/wd_digest.h v1/wd_rsa.h v1/wd_bmm.h
-lib_LTLIBRARIES=libwd.la libwd_comp.la libwd_crypto.la libwd_dae.la
+lib_LTLIBRARIES=libwd.la libwd_comp.la libwd_crypto.la libwd_dae.la libwd_udma.la
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
+ libisa_ce.la libisa_sve.la libhisi_dae.la libhisi_udma.la
libwd_la_SOURCES=wd.c wd_mempool.c wd.h wd_alg.c wd_alg.h \
v1/wd.c v1/wd.h v1/wd_adapter.c v1/wd_adapter.h \
@@ -69,6 +70,9 @@ libwd_la_SOURCES=wd.c wd_mempool.c wd.h wd_alg.c wd_alg.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
+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
+
libwd_dae_la_SOURCES=wd_dae.h wd_agg.h wd_agg_drv.h wd_agg.c \
wd_util.c wd_util.h wd_sched.c wd_sched.h wd.c wd.h
@@ -110,6 +114,9 @@ endif
libhisi_dae_la_SOURCES=drv/hisi_dae.c drv/hisi_qm_udrv.c \
hisi_qm_udrv.h
+libhisi_udma_la_SOURCES=drv/hisi_udma.c drv/hisi_qm_udrv.c \
+ hisi_qm_udrv.h
+
if WD_STATIC_DRV
AM_CFLAGS += -DWD_STATIC_DRV -fPIC
AM_CFLAGS += -DWD_NO_LOG
@@ -124,6 +131,9 @@ libhisi_zip_la_LIBADD = -ldl
libwd_crypto_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma
libwd_crypto_la_DEPENDENCIES = libwd.la
+libwd_udma_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma -lm -lpthread
+libwd_udma_la_DEPENDENCIES = libwd.la
+
libwd_dae_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma
libwd_dae_la_DEPENDENCIES = libwd.la
@@ -139,6 +149,9 @@ libisa_ce_la_DEPENDENCIES = libwd.la libwd_crypto.la
libisa_sve_la_LIBADD = $(libwd_la_OBJECTS) $(libwd_crypto_la_OBJECTS)
libisa_sve_la_DEPENDENCIES = libwd.la libwd_crypto.la
+libhisi_udma_la_LIBADD = $(libwd_la_OBJECTS) $(libwd_udma_la_OBJECTS)
+libhisi_udma_la_DEPENDENCIES = libwd.la libwd_udma.la
+
libhisi_dae_la_LIBADD = $(libwd_la_OBJECTS) $(libwd_dae_la_OBJECTS)
libhisi_dae_la_DEPENDENCIES = libwd.la libwd_dae.la
@@ -160,6 +173,10 @@ libwd_crypto_la_LIBADD= -lwd -ldl -lnuma
libwd_crypto_la_LDFLAGS=$(UADK_VERSION) $(UADK_CRYPTO_SYMBOL) -lpthread
libwd_crypto_la_DEPENDENCIES= libwd.la
+libwd_udma_la_LIBADD= -lwd -ldl -lnuma -lm -lpthread
+libwd_udma_la_LDFLAGS=$(UADK_VERSION) $(UADK_DAE_SYMBOL)
+libwd_udma_la_DEPENDENCIES= libwd.la
+
libwd_dae_la_LIBADD= -lwd -ldl -lnuma -lm
libwd_dae_la_LDFLAGS=$(UADK_VERSION) $(UADK_DAE_SYMBOL)
libwd_dae_la_DEPENDENCIES= libwd.la
@@ -184,6 +201,10 @@ libisa_sve_la_LIBADD= -lwd -lwd_crypto
libisa_sve_la_LDFLAGS=$(UADK_VERSION)
libisa_sve_la_DEPENDENCIES= libwd.la libwd_crypto.la
+libhisi_udma_la_LIBADD= -lwd -lwd_udma
+libhisi_udma_la_LDFLAGS=$(UADK_VERSION)
+libhisi_udma_la_DEPENDENCIES= libwd.la libwd_udma.la
+
libhisi_dae_la_LIBADD= -lwd -lwd_dae
libhisi_dae_la_LDFLAGS=$(UADK_VERSION)
libhisi_dae_la_DEPENDENCIES= libwd.la libwd_dae.la
diff --git a/drv/hisi_udma.c b/drv/hisi_udma.c
new file mode 100644
index 00000000..57dae8cb
--- /dev/null
+++ b/drv/hisi_udma.c
@@ -0,0 +1,566 @@
+// SPDX-License-Identifier: Apache-2.0
+/* Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved. */
+
+#include <math.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/epoll.h>
+#include <sys/eventfd.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include "hisi_qm_udrv.h"
+#include "../include/drv/wd_udma_drv.h"
+
+#define BIT(nr) (1UL << (nr))
+#define UDMA_CTX_Q_NUM_DEF 1
+#define UDMA_TASK_TYPE 0x3
+#define UDMA_SQE_TYPE 0x1
+#define UDMA_ALG_TYPE 2
+/* Multi max data size is (16M -1) * 64 */
+#define UDMA_M_MAX_ADDR_SIZE 1073741760
+/* Single max data size is (16M - 1) */
+#define UDMA_S_MAX_ADDR_SIZE 16777215
+#define UDMA_MAX_ADDR_NUM 64
+#define UDMA_ADDR_NUM_SHIFT 6
+#define UDMA_MULTI_ADDR_EN BIT(14)
+#define UDMA_ADDR_NUM_SHIFT 6
+#define UDMA_SVA_PREFETCH_EN BIT(15)
+#define UDMA_ADDR_RESV_NUM 16
+#define UDMA_ADDR_ALIGN_SIZE 128
+
+enum {
+ DATA_MEMCPY = 0x0,
+ DATA_MEMSET = 0x7,
+};
+
+enum {
+ UDMA_TASK_DONE = 0x1,
+ UDMA_TASK_ERROR = 0x2,
+};
+
+struct udma_addr {
+ __u64 addr;
+ __u64 data_size;
+};
+
+struct udma_addr_array {
+ __u64 resv_addr[UDMA_ADDR_RESV_NUM];
+ struct udma_addr src_addr[UDMA_MAX_ADDR_NUM];
+ struct udma_addr dst_addr[UDMA_MAX_ADDR_NUM];
+};
+
+struct udma_sqe {
+ __u32 bd_type : 6;
+ __u32 resv1 : 2;
+ __u32 task_type : 6;
+ __u32 resv2 : 2;
+ __u32 task_type_ext : 6;
+ __u32 resv3 : 9;
+ __u32 bd_invlid : 1;
+ __u32 rsv4[2];
+ __u32 low_tag;
+ __u32 hi_tag;
+ /* The number of bytes to be copied or filled for single address. */
+ __u32 data_size;
+ __u32 rsv5;
+ /*
+ * 0 ~ 13 bits: reserved,
+ * 14 bit: single address or multi addresses,
+ * 15 bit: sva prefetch en.
+ */
+ __u16 dw0;
+ /*
+ * 0 ~5 bits: reserved,
+ * 6 ~ 13 bits: address num,
+ * 14 ~15 bits: reserved.
+ */
+ __u16 dw1;
+ __u64 init_val;
+ __u32 rsv6[12];
+ /* dst addr for single address task */
+ __u64 dst_addr;
+ __u32 rsv7[2];
+ /* src addr for single address task, addr array for multi addresses. */
+ __u64 addr_array;
+ __u32 done_flag : 3;
+ __u32 rsv8 : 1;
+ __u32 ext_err_type : 12;
+ __u32 err_type : 8;
+ __u32 wtype : 8;
+ __u32 rsv9[3];
+};
+
+struct udma_internal_addr {
+ struct udma_addr_array *addr_array;
+ __u8 *addr_status;
+ __u16 addr_count;
+ __u16 tail;
+};
+
+struct hisi_udma_ctx {
+ struct wd_ctx_config_internal config;
+};
+
+static int get_free_inter_addr(struct udma_internal_addr *inter_addr)
+{
+ __u16 addr_count = inter_addr->addr_count;
+ __u16 idx = inter_addr->tail;
+ __u16 cnt = 0;
+
+ if (unlikely(!addr_count)) {
+ WD_ERR("invalid: internal addr count is 0!\n");
+ return -WD_EINVAL;
+ }
+
+ while (__atomic_test_and_set(&inter_addr->addr_status[idx], __ATOMIC_ACQUIRE)) {
+ idx = (idx + 1) % addr_count;
+ cnt++;
+ if (cnt == addr_count)
+ return -WD_EBUSY;
+ }
+
+ inter_addr->tail = (idx + 1) % addr_count;
+
+ return idx;
+}
+
+static void put_inter_addr(struct udma_internal_addr *inter_addr, int idx)
+{
+ __atomic_clear(&inter_addr->addr_status[idx], __ATOMIC_RELEASE);
+}
+
+static int check_udma_param(struct wd_udma_msg *msg)
+{
+ int i;
+
+ if (unlikely(!msg)) {
+ WD_ERR("invalid: input udma msg is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(msg->addr_num > UDMA_MAX_ADDR_NUM)) {
+ WD_ERR("invalid: input addr_num is more than %d!\n", UDMA_MAX_ADDR_NUM);
+ return -WD_EINVAL;
+ }
+
+ /*
+ * When the single address length exceeds UDMA_S_MAX_ADDR_SIZE,
+ * the driver will split the address into multiple addresses and
+ * send them to the hardware.
+ */
+ if (msg->addr_num == 1) {
+ if (unlikely(msg->dst->data_size > UDMA_M_MAX_ADDR_SIZE)) {
+ WD_ERR("invalid: input size %lu is more than %d!\n",
+ msg->dst->data_size, UDMA_M_MAX_ADDR_SIZE);
+ return -WD_EINVAL;
+ }
+
+ return WD_SUCCESS;
+ }
+
+ for (i = 0; i < msg->addr_num; i++) {
+ if (unlikely(msg->dst[i].data_size > UDMA_S_MAX_ADDR_SIZE)) {
+ WD_ERR("invalid: addr %d input size %lu is more than %d!\n",
+ i, msg->dst[i].data_size, UDMA_S_MAX_ADDR_SIZE);
+ return -WD_EINVAL;
+ }
+ }
+
+ return WD_SUCCESS;
+}
+
+static void fill_long_size_memcpy_info(struct udma_sqe *sqe, struct wd_udma_msg *msg,
+ struct udma_addr_array *addr_array)
+{
+ __u32 addr_num = 0;
+ __u64 count;
+
+ for (count = 0; count < msg->src->data_size; count += UDMA_S_MAX_ADDR_SIZE) {
+ addr_array->src_addr[addr_num].addr = (__u64)(uintptr_t)msg->src->addr + count;
+ addr_array->dst_addr[addr_num].addr = (__u64)(uintptr_t)msg->dst->addr + count;
+ if (count + UDMA_S_MAX_ADDR_SIZE <= msg->src->data_size) {
+ addr_array->src_addr[addr_num].data_size = UDMA_S_MAX_ADDR_SIZE;
+ addr_array->dst_addr[addr_num].data_size = UDMA_S_MAX_ADDR_SIZE;
+ } else {
+ addr_array->src_addr[addr_num].data_size = msg->src->data_size - count;
+ addr_array->dst_addr[addr_num].data_size = msg->dst->data_size - count;
+ }
+ addr_num++;
+ }
+ sqe->dw1 |= (addr_num - 1) << UDMA_ADDR_NUM_SHIFT;
+}
+
+static void fill_long_size_memset_info(struct udma_sqe *sqe, struct wd_udma_msg *msg,
+ struct udma_addr_array *addr_array)
+{
+ __u32 addr_num = 0;
+ __u64 count;
+
+ for (count = 0; count < msg->dst->data_size; count += UDMA_S_MAX_ADDR_SIZE) {
+ addr_array->dst_addr[addr_num].addr = (__u64)(uintptr_t)msg->dst->addr + count;
+ if (count + UDMA_S_MAX_ADDR_SIZE <= msg->dst->data_size)
+ addr_array->dst_addr[addr_num].data_size = UDMA_S_MAX_ADDR_SIZE;
+ else
+ addr_array->dst_addr[addr_num].data_size = msg->dst->data_size - count;
+ addr_num++;
+ }
+
+ sqe->dw1 |= (addr_num - 1) << UDMA_ADDR_NUM_SHIFT;
+}
+
+static void fill_mulit_memset_addr_info(struct udma_sqe *sqe, struct wd_udma_msg *msg,
+ struct udma_addr_array *addr_array)
+{
+ int i;
+
+ for (i = 0; i < msg->addr_num; i++) {
+ addr_array->dst_addr[i].addr = (__u64)(uintptr_t)msg->dst[i].addr;
+ addr_array->dst_addr[i].data_size = (__u64)(uintptr_t)msg->dst[i].data_size;
+ }
+
+ sqe->dw1 |= ((__u32)msg->addr_num - 1) << UDMA_ADDR_NUM_SHIFT;
+}
+
+static void fill_multi_memcpy_addr_info(struct udma_sqe *sqe, struct wd_udma_msg *msg,
+ struct udma_addr_array *addr_array)
+{
+ int i;
+
+ for (i = 0; i < msg->addr_num; i++) {
+ addr_array->src_addr[i].addr = (__u64)(uintptr_t)msg->src[i].addr;
+ addr_array->src_addr[i].data_size = (__u64)(uintptr_t)msg->src[i].data_size;
+ addr_array->dst_addr[i].addr = (__u64)(uintptr_t)msg->dst[i].addr;
+ addr_array->dst_addr[i].data_size = (__u64)(uintptr_t)msg->dst[i].data_size;
+ }
+
+ sqe->dw1 |= ((__u32)msg->addr_num - 1) << UDMA_ADDR_NUM_SHIFT;
+}
+
+static void fill_multi_addr_info(struct udma_sqe *sqe, struct wd_udma_msg *msg,
+ struct udma_addr_array *addr_array)
+{
+ if (msg->addr_num == 1) {
+ if (msg->op_type == WD_UDMA_MEMCPY)
+ fill_long_size_memcpy_info(sqe, msg, addr_array);
+ else
+ fill_long_size_memset_info(sqe, msg, addr_array);
+ } else {
+ if (msg->op_type == WD_UDMA_MEMCPY)
+ fill_multi_memcpy_addr_info(sqe, msg, addr_array);
+ else
+ fill_mulit_memset_addr_info(sqe, msg, addr_array);
+ }
+
+ sqe->addr_array = (__u64)(uintptr_t)addr_array;
+ sqe->dw0 |= UDMA_MULTI_ADDR_EN;
+}
+
+static void fill_single_addr_info(struct udma_sqe *sqe, struct wd_udma_msg *msg)
+{
+ if (msg->op_type == WD_UDMA_MEMCPY)
+ sqe->addr_array = (__u64)(uintptr_t)msg->src->addr;
+ sqe->dst_addr = (__u64)(uintptr_t)msg->dst->addr;
+ sqe->data_size = msg->dst->data_size;
+}
+
+static void fill_udma_sqe_addr(struct udma_sqe *sqe, struct wd_udma_msg *msg,
+ struct udma_addr_array *addr_array)
+{
+ if (!addr_array)
+ fill_single_addr_info(sqe, msg);
+ else
+ fill_multi_addr_info(sqe, msg, addr_array);
+}
+
+static void fill_sqe_type(struct udma_sqe *sqe, struct wd_udma_msg *msg)
+{
+ sqe->bd_type = UDMA_SQE_TYPE;
+ sqe->task_type = UDMA_TASK_TYPE;
+ if (msg->op_type == WD_UDMA_MEMCPY)
+ sqe->task_type_ext = DATA_MEMCPY;
+ else
+ sqe->task_type_ext = DATA_MEMSET;
+}
+
+static void fill_init_value(struct udma_sqe *sqe, struct wd_udma_msg *msg)
+{
+ if (msg->op_type == WD_UDMA_MEMSET)
+ memset(&sqe->init_val, msg->value, sizeof(__u64));
+}
+
+static int udma_send(struct wd_alg_driver *drv, handle_t ctx, void *udma_msg)
+{
+ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ struct udma_internal_addr *inter_addr = qp->priv;
+ struct udma_addr_array *addr_array = NULL;
+ struct wd_udma_msg *msg = udma_msg;
+ struct udma_sqe sqe = {0};
+ __u16 send_cnt = 0;
+ int idx = 0;
+ int ret;
+
+ ret = check_udma_param(msg);
+ if (unlikely(ret))
+ return ret;
+
+ if (msg->addr_num > 1 || msg->dst->data_size > UDMA_S_MAX_ADDR_SIZE) {
+ idx = get_free_inter_addr(inter_addr);
+ if (idx < 0)
+ return -WD_EBUSY;
+
+ addr_array = &inter_addr->addr_array[idx];
+ memset(addr_array, 0, sizeof(struct udma_addr_array));
+ }
+
+ fill_sqe_type(&sqe, msg);
+ fill_init_value(&sqe, msg);
+ fill_udma_sqe_addr(&sqe, msg, addr_array);
+
+ hisi_set_msg_id(h_qp, &msg->tag);
+ sqe.low_tag = msg->tag;
+ sqe.hi_tag = (__u32)idx;
+ sqe.dw0 |= UDMA_SVA_PREFETCH_EN;
+
+ ret = hisi_qm_send(h_qp, &sqe, 1, &send_cnt);
+ if (unlikely(ret)) {
+ if (ret != -WD_EBUSY)
+ WD_ERR("failed to send to hardware, ret = %d!\n", ret);
+ if (addr_array)
+ put_inter_addr(inter_addr, idx);
+ return ret;
+ }
+
+ return WD_SUCCESS;
+}
+
+static void dump_udma_msg(struct udma_sqe *sqe, struct wd_udma_msg *msg)
+{
+ WD_ERR("dump UDMA message after a task error occurs.\n"
+ "op_type:%u addr_num:%d.\n", msg->op_type, msg->addr_num);
+}
+
+static int udma_recv(struct wd_alg_driver *drv, handle_t ctx, void *udma_msg)
+{
+ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ struct udma_internal_addr *inter_addr = qp->priv;
+ struct wd_udma_msg *msg = udma_msg;
+ struct wd_udma_msg *temp_msg = msg;
+ struct udma_sqe sqe = {0};
+ __u16 recv_cnt = 0;
+ int ret;
+
+ ret = hisi_qm_recv(h_qp, &sqe, 1, &recv_cnt);
+ if (ret)
+ return ret;
+
+ ret = hisi_check_bd_id(h_qp, msg->tag, sqe.low_tag);
+ if (ret)
+ goto out;
+
+ msg->tag = sqe.low_tag;
+ if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
+ temp_msg = wd_udma_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);
+ ret = -WD_EINVAL;
+ goto out;
+ }
+ }
+
+ msg->result = WD_SUCCESS;
+ if (sqe.done_flag != UDMA_TASK_DONE ||
+ sqe.err_type || sqe.ext_err_type || sqe.wtype) {
+ WD_ERR("failed to do udma task! done=0x%x, err_type=0x%x\n"
+ "ext_err_type=0x%x, wtype=0x%x!\n",
+ (__u32)sqe.done_flag, (__u32)sqe.err_type,
+ (__u32)sqe.ext_err_type, (__u32)sqe.wtype);
+ msg->result = WD_IN_EPARA;
+ }
+
+ if (unlikely(msg->result != WD_SUCCESS))
+ dump_udma_msg(&sqe, temp_msg);
+
+out:
+ if (sqe.dw0 & UDMA_MULTI_ADDR_EN)
+ put_inter_addr(inter_addr, sqe.hi_tag);
+ return ret;
+}
+
+static void udma_uninit_qp_priv(handle_t h_qp)
+{
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ struct udma_internal_addr *inter_addr;
+
+ if (!qp)
+ return;
+
+ inter_addr = (struct udma_internal_addr *)qp->priv;
+ if (!inter_addr)
+ return;
+
+ free(inter_addr->addr_array);
+ free(inter_addr->addr_status);
+ free(inter_addr);
+ qp->priv = NULL;
+}
+
+static int udma_init_qp_priv(handle_t h_qp)
+{
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ __u16 sq_depth = qp->q_info.sq_depth;
+ struct udma_internal_addr *inter_addr;
+ int ret = -WD_ENOMEM;
+
+ inter_addr = calloc(1, sizeof(struct udma_internal_addr));
+ if (!inter_addr)
+ return ret;
+
+ inter_addr->addr_status = calloc(1, sizeof(__u8) * sq_depth);
+ if (!inter_addr->addr_status)
+ goto free_inter_addr;
+
+ inter_addr->addr_array = aligned_alloc(UDMA_ADDR_ALIGN_SIZE,
+ sizeof(struct udma_addr_array) * sq_depth);
+ if (!inter_addr->addr_array)
+ goto free_addr_status;
+
+ inter_addr->addr_count = sq_depth;
+ qp->priv = inter_addr;
+
+ return WD_SUCCESS;
+
+free_addr_status:
+ free(inter_addr->addr_status);
+free_inter_addr:
+ free(inter_addr);
+
+ return ret;
+}
+
+static int udma_init(struct wd_alg_driver *drv, void *conf)
+{
+ struct wd_ctx_config_internal *config = conf;
+ struct hisi_qm_priv qm_priv;
+ struct hisi_udma_ctx *priv;
+ handle_t h_qp = 0;
+ handle_t h_ctx;
+ __u32 i, j;
+ int ret;
+
+ if (!config || !config->ctx_num) {
+ WD_ERR("invalid: udma init config is null or ctx num is 0!\n");
+ return -WD_EINVAL;
+ }
+
+ priv = malloc(sizeof(struct hisi_udma_ctx));
+ if (!priv)
+ return -WD_ENOMEM;
+
+ qm_priv.op_type = UDMA_ALG_TYPE;
+ qm_priv.sqe_size = sizeof(struct udma_sqe);
+ /* Allocate qp for each context */
+ for (i = 0; i < config->ctx_num; i++) {
+ h_ctx = config->ctxs[i].ctx;
+ qm_priv.qp_mode = config->ctxs[i].ctx_mode;
+ /* Setting the epoll en to 0 for ASYNC ctx */
+ qm_priv.epoll_en = (qm_priv.qp_mode == CTX_MODE_SYNC) ?
+ config->epoll_en : 0;
+ qm_priv.idx = i;
+ h_qp = hisi_qm_alloc_qp(&qm_priv, h_ctx);
+ if (!h_qp) {
+ ret = -WD_ENOMEM;
+ goto out;
+ }
+ config->ctxs[i].sqn = qm_priv.sqn;
+ ret = udma_init_qp_priv(h_qp);
+ if (ret)
+ goto free_h_qp;
+ }
+ memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
+ drv->priv = priv;
+
+ return WD_SUCCESS;
+free_h_qp:
+ hisi_qm_free_qp(h_qp);
+out:
+ for (j = 0; j < i; j++) {
+ h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[j].ctx);
+ udma_uninit_qp_priv(h_qp);
+ hisi_qm_free_qp(h_qp);
+ }
+ free(priv);
+ return ret;
+}
+
+static void udma_exit(struct wd_alg_driver *drv)
+{
+ struct wd_ctx_config_internal *config;
+ struct hisi_udma_ctx *priv;
+ handle_t h_qp;
+ __u32 i;
+
+ if (!drv || !drv->priv)
+ return;
+
+ priv = (struct hisi_udma_ctx *)drv->priv;
+ config = &priv->config;
+ for (i = 0; i < config->ctx_num; i++) {
+ h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
+ udma_uninit_qp_priv(h_qp);
+ hisi_qm_free_qp(h_qp);
+ }
+
+ free(priv);
+ drv->priv = NULL;
+}
+
+static int udma_get_usage(void *param)
+{
+ return 0;
+}
+
+static struct wd_alg_driver udma_driver = {
+ .drv_name = "hisi_zip",
+ .alg_name = "udma",
+ .calc_type = UADK_ALG_HW,
+ .priority = 100,
+ .queue_num = UDMA_CTX_Q_NUM_DEF,
+ .op_type_num = 1,
+ .fallback = 0,
+ .init = udma_init,
+ .exit = udma_exit,
+ .send = udma_send,
+ .recv = udma_recv,
+ .get_usage = udma_get_usage,
+};
+
+#ifdef WD_STATIC_DRV
+void hisi_udma_probe(void)
+#else
+static void __attribute__((constructor)) hisi_udma_probe(void)
+#endif
+{
+ int ret;
+
+ WD_INFO("Info: register UDMA alg drivers!\n");
+
+ ret = wd_alg_driver_register(&udma_driver);
+ if (ret && ret != -WD_ENODEV)
+ WD_ERR("failed to register UDMA driver, ret = %d!\n", ret);
+}
+
+#ifdef WD_STATIC_DRV
+void hisi_udma_remove(void)
+#else
+static void __attribute__((destructor)) hisi_udma_remove(void)
+#endif
+{
+ WD_INFO("Info: unregister UDMA alg drivers!\n");
+
+ wd_alg_driver_unregister(&udma_driver);
+}
diff --git a/include/drv/wd_udma_drv.h b/include/drv/wd_udma_drv.h
new file mode 100644
index 00000000..c8028f79
--- /dev/null
+++ b/include/drv/wd_udma_drv.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/* Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved. */
+
+#ifndef __WD_UDMA_DRV_H
+#define __WD_UDMA_DRV_H
+
+#include <asm/types.h>
+
+#include "../wd_udma.h"
+#include "../wd_util.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* udma message format */
+struct wd_udma_msg {
+ struct wd_udma_req req;
+ struct wd_data_addr *src;
+ struct wd_data_addr *dst;
+ int addr_num;
+ int value;
+ enum wd_udma_op_type op_type;
+ __u32 tag; /* User-defined request identifier */
+ __u8 result; /* alg op error code */
+};
+
+struct wd_udma_msg *wd_udma_get_msg(__u32 idx, __u32 tag);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __WD_UDMA_DRV_H */
diff --git a/include/wd_alg.h b/include/wd_alg.h
index aba855d6..441b3bef 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -204,11 +204,13 @@ void hisi_sec2_probe(void);
void hisi_hpre_probe(void);
void hisi_zip_probe(void);
void hisi_dae_probe(void);
+void hisi_udma_probe(void);
void hisi_sec2_remove(void);
void hisi_hpre_remove(void);
void hisi_zip_remove(void);
void hisi_dae_remove(void);
+void hisi_udma_remove(void);
#endif
diff --git a/include/wd_udma.h b/include/wd_udma.h
new file mode 100644
index 00000000..d8a7964e
--- /dev/null
+++ b/include/wd_udma.h
@@ -0,0 +1,124 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/*
+ * Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved.
+ */
+
+#ifndef __WD_UDMA_H
+#define __WD_UDMA_H
+
+#include <stdbool.h>
+
+#include "wd_alg_common.h"
+
+typedef void (*wd_udma_cb_t)(void *cb_param);
+
+/**
+ * wd_udma_op_type - Algorithm type of option.
+ */
+enum wd_udma_op_type {
+ WD_UDMA_MEMCPY,
+ WD_UDMA_MEMSET,
+ WD_UDMA_OP_MAX
+};
+
+/**
+ * wd_udma_sess_setup - udma session setup information.
+ * @sched_param: Parameters of the scheduling policy,
+ * usually allocated according to struct sched_params.
+ */
+struct wd_udma_sess_setup {
+ void *sched_param;
+};
+
+/**
+ * wd_data_addr - addr information of UDMA.
+ * @addr: Indicates the start address of the operation.
+ * @addr_size: Maximum size of the addr, in bytes.
+ * @count: Number of bytes to be set.
+ */
+struct wd_data_addr {
+ void *addr;
+ size_t addr_size;
+ size_t data_size;
+};
+
+/**
+ * wd_udma_req - udma operation request.
+ * @src: pointer to input address.
+ * @dst: pointer to output address, for WD_UDMA_MEMSET, only one of src and dst can be set.
+ * @addr_num: Number of address.
+ * @value: Value to be written for WD_UDMA_MEMSET.
+ * @op_type: udma operation type.
+ * @cb: Callback function.
+ * @cb_param: Parameters of the callback function.
+ * @state: operation result written back by the driver.
+ */
+struct wd_udma_req {
+ struct wd_data_addr *src;
+ struct wd_data_addr *dst;
+ int addr_num;
+ int value;
+ enum wd_udma_op_type op_type;
+ wd_udma_cb_t cb;
+ void *cb_param;
+ int status;
+};
+
+/**
+ * wd_udma_init() - A simplify interface to initializate ecc.
+ * To make the initializate simpler, ctx_params support set NULL.
+ * And then the function will set them as driver's default.
+ *
+ * @alg: The algorithm users want to use.
+ * @sched_type: The scheduling type users want to use.
+ * @task_type: Task types, including soft computing, hardware and hybrid computing.
+ * @ctx_params: The ctxs resources users want to use. Include per operation
+ * type ctx numbers and business process run numa.
+ *
+ * Return 0 if succeed and others if fail.
+ */
+int wd_udma_init(const char *alg, __u32 sched_type,
+ int task_type, struct wd_ctx_params *ctx_params);
+
+/**
+ * wd_udma_uninit() - Uninitialise ctx configuration and scheduler.
+ */
+void wd_udma_uninit(void);
+
+/**
+ * wd_udma_alloc_sess() - Allocate a wd udma session.
+ * @setup: Parameters to setup this session.
+ *
+ * Return 0 if failed.
+ */
+handle_t wd_udma_alloc_sess(struct wd_udma_sess_setup *setup);
+
+/**
+ * wd_udma_free_sess() - Free a wd udma session.
+ * @ sess: The sess to be freed.
+ */
+void wd_udma_free_sess(handle_t sess);
+
+/**
+ * wd_do_udma_sync() - Send a sync udma request.
+ * @h_sess: The session which request will be sent to.
+ * @req: Request.
+ */
+int wd_do_udma_sync(handle_t h_sess, struct wd_udma_req *req);
+
+/**
+ * wd_do_udma_async() - Send an async udma request.
+ * @sess: The session which request will be sent to.
+ * @req: Request.
+ */
+int wd_do_udma_async(handle_t h_sess, struct wd_udma_req *req);
+
+/**
+ * wd_udma_poll() - Poll finished request.
+ *
+ * This function will call poll_policy function which is registered to wd udma
+ * by user.
+ */
+int wd_udma_poll(__u32 expt, __u32 *count);
+
+#endif /* __WD_UDMA_H */
diff --git a/include/wd_util.h b/include/wd_util.h
index 9e9d4e35..bbb18a7c 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -42,6 +42,7 @@ enum wd_type {
WD_DH_TYPE,
WD_ECC_TYPE,
WD_AGG_TYPE,
+ WD_UDMA_TYPE,
WD_TYPE_MAX,
};
diff --git a/libwd_dae.map b/libwd_dae.map
index 4c51b856..6597ff98 100644
--- a/libwd_dae.map
+++ b/libwd_dae.map
@@ -1,4 +1,4 @@
-UADK_CRYPTO_2.0 {
+UADK_DAE_2.0 {
global:
wd_agg_alloc_sess;
wd_agg_free_sess;
@@ -17,5 +17,18 @@ global:
wd_sched_rr_instance;
wd_sched_rr_alloc;
wd_sched_rr_release;
+
+ wd_udma_alloc_sess;
+ wd_udma_free_sess;
+ wd_udma_init;
+ wd_udma_uninit;
+ wd_do_udma_sync;
+ wd_do_udma_async;
+ wd_udma_poll;
+ wd_udma_get_msg;
+
+ wd_sched_rr_instance;
+ wd_sched_rr_alloc;
+ wd_sched_rr_release;
local: *;
};
diff --git a/wd_udma.c b/wd_udma.c
new file mode 100644
index 00000000..7675df30
--- /dev/null
+++ b/wd_udma.c
@@ -0,0 +1,511 @@
+// SPDX-License-Identifier: Apache-2.0
+/*
+ * Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved.
+ */
+
+#include <stdlib.h>
+#include <pthread.h>
+#include <limits.h>
+#include "include/drv/wd_udma_drv.h"
+#include "wd_udma.h"
+
+struct wd_udma_sess {
+ const char *alg_name;
+ wd_dev_mask_t *dev_mask;
+ void *priv;
+ void *sched_key;
+};
+
+static struct wd_udma_setting {
+ enum wd_status status;
+ struct wd_ctx_config_internal config;
+ struct wd_sched sched;
+ struct wd_async_msg_pool pool;
+ struct wd_alg_driver *driver;
+ void *dlhandle;
+ void *dlh_list;
+} wd_udma_setting;
+
+static struct wd_init_attrs wd_udma_init_attrs;
+
+static void wd_udma_close_driver(void)
+{
+#ifndef WD_STATIC_DRV
+ wd_dlclose_drv(wd_udma_setting.dlh_list);
+ wd_udma_setting.dlh_list = NULL;
+#else
+ wd_release_drv(wd_udma_setting.driver);
+ hisi_udma_remove();
+#endif
+}
+
+static int wd_udma_open_driver(void)
+{
+#ifndef WD_STATIC_DRV
+ /*
+ * Driver lib file path could set by env param.
+ * then open tham by wd_dlopen_drv()
+ * use NULL means dynamic query path
+ */
+ wd_udma_setting.dlh_list = wd_dlopen_drv(NULL);
+ if (!wd_udma_setting.dlh_list) {
+ WD_ERR("fail to open driver lib files.\n");
+ return -WD_EINVAL;
+ }
+#else
+ hisi_udma_probe();
+#endif
+ return WD_SUCCESS;
+}
+
+void wd_udma_free_sess(handle_t sess)
+{
+ struct wd_udma_sess *sess_t = (struct wd_udma_sess *)sess;
+
+ if (!sess_t) {
+ WD_ERR("invalid: free udma sess param NULL!\n");
+ return;
+ }
+
+ if (sess_t->sched_key)
+ free(sess_t->sched_key);
+ free(sess_t);
+}
+
+handle_t wd_udma_alloc_sess(struct wd_udma_sess_setup *setup)
+{
+ struct wd_udma_sess *sess;
+
+ if (!setup) {
+ WD_ERR("invalid: alloc udma sess setup NULL!\n");
+ return (handle_t)0;
+ }
+
+ sess = calloc(1, sizeof(struct wd_udma_sess));
+ if (!sess)
+ return (handle_t)0;
+
+ sess->alg_name = "udma";
+ /* Some simple scheduler don't need scheduling parameters */
+ sess->sched_key = (void *)wd_udma_setting.sched.sched_init(
+ wd_udma_setting.sched.h_sched_ctx, setup->sched_param);
+ if (WD_IS_ERR(sess->sched_key)) {
+ WD_ERR("failed to init session schedule key!\n");
+ goto free_sess;
+ }
+
+ return (handle_t)sess;
+
+free_sess:
+ free(sess);
+ return (handle_t)0;
+}
+
+static int wd_udma_addr_check(struct wd_data_addr *data_addr)
+{
+ if (unlikely(!data_addr->addr)) {
+ WD_ERR("invalid: udma addr is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(!data_addr->data_size ||
+ data_addr->data_size > data_addr->addr_size)) {
+ WD_ERR("invalid: udma size is error, data_size %lu, addr_size is %lu!\n",
+ data_addr->data_size, data_addr->addr_size);
+ return -WD_EINVAL;
+ }
+
+ return WD_SUCCESS;
+}
+
+static int wd_udma_param_check(struct wd_udma_sess *sess,
+ struct wd_udma_req *req)
+{
+ struct wd_data_addr *src, *dst;
+ int i, ret;
+
+ if (unlikely(!sess || !req)) {
+ WD_ERR("invalid: input param NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(req->addr_num <= 0)) {
+ WD_ERR("invalid: addr num is error %d!\n", req->addr_num);
+ return -WD_EINVAL;
+ }
+
+ src = req->src;
+ dst = req->dst;
+ if (unlikely(req->op_type >= WD_UDMA_OP_MAX)) {
+ WD_ERR("invalid: op_type is error %u!\n", req->op_type);
+ return -WD_EINVAL;
+ } else if (unlikely(req->op_type == WD_UDMA_MEMCPY && (!src || !dst))) {
+ WD_ERR("invalid: memcpy src or dst is NULL!\n");
+ return -WD_EINVAL;
+ } else if (unlikely(req->op_type == WD_UDMA_MEMSET &&
+ ((!src && !dst) || (src && dst)))) {
+ WD_ERR("invalid: memset src and dst is error!\n");
+ return -WD_EINVAL;
+ }
+
+ if (req->op_type == WD_UDMA_MEMSET)
+ dst = !req->src ? req->dst : req->src;
+
+ for (i = 0; i < req->addr_num; i++) {
+ if (req->op_type == WD_UDMA_MEMCPY) {
+ ret = wd_udma_addr_check(&src[i]);
+ if (unlikely(ret)) {
+ WD_ERR("invalid: udma memcpy src addr is error!\n");
+ return -WD_EINVAL;
+ }
+
+ ret = wd_udma_addr_check(&dst[i]);
+ if (unlikely(ret)) {
+ WD_ERR("invalid: udma memcpy dst addr is error!\n");
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(dst[i].data_size != src[i].data_size)) {
+ WD_ERR("invalid: udma memcpy data_size is error!\n"
+ "src %lu, dst %lu!\n",
+ dst[i].data_size, src[i].data_size);
+ return -WD_EINVAL;
+ }
+ } else {
+ ret = wd_udma_addr_check(&dst[i]);
+ if (unlikely(ret)) {
+ WD_ERR("invalid: udma memset addr is error!\n");
+ return -WD_EINVAL;
+ }
+ }
+ }
+
+ return WD_SUCCESS;
+}
+
+static void fill_udma_msg(struct wd_udma_msg *msg, struct wd_udma_req *req)
+{
+ msg->result = WD_EINVAL;
+
+ memcpy(&msg->req, req, sizeof(*req));
+ msg->op_type = req->op_type;
+ msg->addr_num = req->addr_num;
+ msg->value = req->value;
+ if (req->op_type == WD_UDMA_MEMSET) {
+ msg->dst = !req->src ? req->dst : req->src;
+ } else {
+ msg->src = req->src;
+ msg->dst = req->dst;
+ }
+}
+
+int wd_do_udma_sync(handle_t h_sess, struct wd_udma_req *req)
+{
+ struct wd_ctx_config_internal *config = &wd_udma_setting.config;
+ handle_t h_sched_ctx = wd_udma_setting.sched.h_sched_ctx;
+ struct wd_udma_sess *sess_t = (struct wd_udma_sess *)h_sess;
+ struct wd_msg_handle msg_handle;
+ struct wd_ctx_internal *ctx;
+ struct wd_udma_msg msg = {0};
+ __u32 idx;
+ int ret;
+
+ ret = wd_udma_param_check(sess_t, req);
+ if (unlikely(ret))
+ return ret;
+
+ idx = wd_udma_setting.sched.pick_next_ctx(h_sched_ctx,
+ sess_t->sched_key,
+ CTX_MODE_SYNC);
+ ret = wd_check_ctx(config, CTX_MODE_SYNC, idx);
+ if (unlikely(ret))
+ return ret;
+
+ wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
+ ctx = config->ctxs + idx;
+
+ fill_udma_msg(&msg, req);
+
+ msg_handle.send = wd_udma_setting.driver->send;
+ msg_handle.recv = wd_udma_setting.driver->recv;
+ pthread_spin_lock(&ctx->lock);
+ ret = wd_handle_msg_sync(wd_udma_setting.driver, &msg_handle, ctx->ctx,
+ &msg, NULL, wd_udma_setting.config.epoll_en);
+ pthread_spin_unlock(&ctx->lock);
+ if (unlikely(ret))
+ return ret;
+
+ req->status = msg.result;
+
+ return GET_NEGATIVE(msg.result);
+}
+
+int wd_do_udma_async(handle_t sess, struct wd_udma_req *req)
+{
+ struct wd_ctx_config_internal *config = &wd_udma_setting.config;
+ handle_t h_sched_ctx = wd_udma_setting.sched.h_sched_ctx;
+ struct wd_udma_sess *sess_t = (struct wd_udma_sess *)sess;
+ struct wd_udma_msg *msg = NULL;
+ struct wd_ctx_internal *ctx;
+ int ret, mid;
+ __u32 idx;
+
+ ret = wd_udma_param_check(sess_t, req);
+ if (unlikely(ret))
+ return ret;
+
+ if (unlikely(!req->cb)) {
+ WD_ERR("invalid: udma input req cb is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ idx = wd_udma_setting.sched.pick_next_ctx(h_sched_ctx,
+ sess_t->sched_key,
+ CTX_MODE_ASYNC);
+ ret = wd_check_ctx(config, CTX_MODE_ASYNC, idx);
+ if (unlikely(ret))
+ return ret;
+ ctx = config->ctxs + idx;
+
+ mid = wd_get_msg_from_pool(&wd_udma_setting.pool, idx, (void **)&msg);
+ if (unlikely(mid < 0)) {
+ WD_ERR("failed to get msg from pool!\n");
+ return mid;
+ }
+
+ fill_udma_msg(msg, req);
+ msg->tag = mid;
+
+ ret = wd_alg_driver_send(wd_udma_setting.driver, ctx->ctx, msg);
+ if (unlikely(ret)) {
+ if (ret != -WD_EBUSY)
+ WD_ERR("failed to send udma BD, hw is err!\n");
+
+ goto fail_with_msg;
+ }
+
+ wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
+
+ return WD_SUCCESS;
+
+fail_with_msg:
+ wd_put_msg_to_pool(&wd_udma_setting.pool, idx, mid);
+
+ return ret;
+}
+
+static int wd_udma_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
+{
+ struct wd_ctx_config_internal *config = &wd_udma_setting.config;
+ struct wd_udma_msg rcv_msg = {0};
+ struct wd_ctx_internal *ctx;
+ struct wd_udma_req *req;
+ struct wd_udma_msg *msg;
+ __u32 rcv_cnt = 0;
+ __u32 tmp = expt;
+ int ret;
+
+ *count = 0;
+
+ ret = wd_check_ctx(config, CTX_MODE_ASYNC, idx);
+ if (ret)
+ return ret;
+
+ ctx = config->ctxs + idx;
+
+ do {
+ ret = wd_alg_driver_recv(wd_udma_setting.driver, ctx->ctx, &rcv_msg);
+ if (ret == -WD_EAGAIN) {
+ return ret;
+ } else if (unlikely(ret)) {
+ WD_ERR("failed to async recv, ret = %d!\n", ret);
+ *count = rcv_cnt;
+ wd_put_msg_to_pool(&wd_udma_setting.pool, idx,
+ rcv_msg.tag);
+ return ret;
+ }
+ rcv_cnt++;
+ msg = wd_find_msg_in_pool(&wd_udma_setting.pool, idx, rcv_msg.tag);
+ if (!msg) {
+ WD_ERR("failed to find udma msg!\n");
+ return -WD_EINVAL;
+ }
+
+ msg->req.status = rcv_msg.result;
+ req = &msg->req;
+ req->cb(req);
+ wd_put_msg_to_pool(&wd_udma_setting.pool, idx, rcv_msg.tag);
+ *count = rcv_cnt;
+ } while (--tmp);
+
+ return ret;
+}
+
+int wd_udma_poll(__u32 expt, __u32 *count)
+{
+ handle_t h_sched_ctx = wd_udma_setting.sched.h_sched_ctx;
+
+ if (unlikely(!count || !expt)) {
+ WD_ERR("invalid: udma poll count is NULL or expt is 0!\n");
+ return -WD_EINVAL;
+ }
+
+ return wd_udma_setting.sched.poll_policy(h_sched_ctx, expt, count);
+}
+
+static void wd_udma_clear_status(void)
+{
+ wd_alg_clear_init(&wd_udma_setting.status);
+}
+
+static void wd_udma_alg_uninit(void)
+{
+ /* Uninit async request pool */
+ wd_uninit_async_request_pool(&wd_udma_setting.pool);
+ /* Unset config, sched, driver */
+ wd_clear_sched(&wd_udma_setting.sched);
+ wd_alg_uninit_driver(&wd_udma_setting.config, wd_udma_setting.driver);
+}
+
+void wd_udma_uninit(void)
+{
+ enum wd_status status;
+
+ wd_alg_get_init(&wd_udma_setting.status, &status);
+ if (status == WD_UNINIT)
+ return;
+
+ wd_udma_alg_uninit();
+ wd_alg_attrs_uninit(&wd_udma_init_attrs);
+ wd_alg_drv_unbind(wd_udma_setting.driver);
+ wd_udma_close_driver();
+ wd_alg_clear_init(&wd_udma_setting.status);
+}
+
+static int wd_udma_alg_init(struct wd_ctx_config *config, struct wd_sched *sched)
+{
+ int ret;
+
+ ret = wd_set_epoll_en("WD_UDMA_EPOLL_EN", &wd_udma_setting.config.epoll_en);
+ if (ret < 0)
+ return ret;
+
+ ret = wd_init_ctx_config(&wd_udma_setting.config, config);
+ if (ret < 0)
+ return ret;
+
+ ret = wd_init_sched(&wd_udma_setting.sched, sched);
+ if (ret < 0)
+ goto out_clear_ctx_config;
+
+ /* Allocate async pool for every ctx */
+ ret = wd_init_async_request_pool(&wd_udma_setting.pool, config, WD_POOL_MAX_ENTRIES,
+ sizeof(struct wd_udma_msg));
+ if (ret < 0)
+ goto out_clear_sched;
+
+ ret = wd_alg_init_driver(&wd_udma_setting.config, wd_udma_setting.driver);
+ if (ret)
+ goto out_clear_pool;
+
+ return WD_SUCCESS;
+
+out_clear_pool:
+ wd_uninit_async_request_pool(&wd_udma_setting.pool);
+out_clear_sched:
+ wd_clear_sched(&wd_udma_setting.sched);
+out_clear_ctx_config:
+ wd_clear_ctx_config(&wd_udma_setting.config);
+ return ret;
+}
+
+int wd_udma_init(const char *alg, __u32 sched_type, int task_type,
+ struct wd_ctx_params *ctx_params)
+{
+ struct wd_ctx_nums udma_ctx_num[WD_UDMA_OP_MAX] = {0};
+ struct wd_ctx_params udma_ctx_params = {0};
+ int state, ret = -WD_EINVAL;
+
+ pthread_atfork(NULL, NULL, wd_udma_clear_status);
+
+ state = wd_alg_try_init(&wd_udma_setting.status);
+ if (state)
+ return state;
+
+ if (!alg || sched_type >= SCHED_POLICY_BUTT ||
+ task_type < 0 || task_type >= TASK_MAX_TYPE) {
+ WD_ERR("invalid: input param is wrong!\n");
+ goto out_clear_init;
+ }
+
+ if (strcmp(alg, "udma")) {
+ WD_ERR("invalid: the alg %s not support!\n", alg);
+ goto out_clear_init;
+ }
+
+ state = wd_udma_open_driver();
+ if (state)
+ goto out_clear_init;
+
+ while (ret) {
+ memset(&wd_udma_setting.config, 0, sizeof(struct wd_ctx_config_internal));
+
+ /* Get alg driver and dev name */
+ wd_udma_setting.driver = wd_alg_drv_bind(task_type, alg);
+ if (!wd_udma_setting.driver) {
+ WD_ERR("fail to bind a valid driver.\n");
+ ret = -WD_EINVAL;
+ goto out_dlopen;
+ }
+
+ udma_ctx_params.ctx_set_num = udma_ctx_num;
+ ret = wd_ctx_param_init(&udma_ctx_params, ctx_params,
+ wd_udma_setting.driver, WD_UDMA_TYPE, WD_UDMA_OP_MAX);
+ if (ret) {
+ if (ret == -WD_EAGAIN) {
+ wd_disable_drv(wd_udma_setting.driver);
+ wd_alg_drv_unbind(wd_udma_setting.driver);
+ continue;
+ }
+ goto out_driver;
+ }
+
+ wd_udma_init_attrs.alg = alg;
+ wd_udma_init_attrs.sched_type = sched_type;
+ wd_udma_init_attrs.driver = wd_udma_setting.driver;
+ wd_udma_init_attrs.ctx_params = &udma_ctx_params;
+ wd_udma_init_attrs.alg_init = wd_udma_alg_init;
+ wd_udma_init_attrs.alg_poll_ctx = wd_udma_poll_ctx;
+ ret = wd_alg_attrs_init(&wd_udma_init_attrs);
+ if (ret) {
+ if (ret == -WD_ENODEV) {
+ wd_disable_drv(wd_udma_setting.driver);
+ wd_alg_drv_unbind(wd_udma_setting.driver);
+ wd_ctx_param_uninit(&udma_ctx_params);
+ continue;
+ }
+ WD_ERR("failed to init alg attrs!\n");
+ goto out_params_uninit;
+ }
+ }
+
+ wd_alg_set_init(&wd_udma_setting.status);
+ wd_ctx_param_uninit(&udma_ctx_params);
+
+ return WD_SUCCESS;
+
+out_params_uninit:
+ wd_ctx_param_uninit(&udma_ctx_params);
+out_driver:
+ wd_alg_drv_unbind(wd_udma_setting.driver);
+out_dlopen:
+ wd_udma_close_driver();
+out_clear_init:
+ wd_alg_clear_init(&wd_udma_setting.status);
+ return ret;
+}
+
+struct wd_udma_msg *wd_udma_get_msg(__u32 idx, __u32 tag)
+{
+ return wd_find_msg_in_pool(&wd_udma_setting.pool, idx, tag);
+}
diff --git a/wd_util.c b/wd_util.c
index f1b27bf8..38d2d375 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -63,6 +63,7 @@ static const char *wd_env_name[WD_TYPE_MAX] = {
"WD_DH_CTX_NUM",
"WD_ECC_CTX_NUM",
"WD_AGG_CTX_NUM",
+ "WD_UDMA_CTX_NUM",
};
struct async_task {
@@ -107,6 +108,7 @@ static struct acc_alg_item alg_options[] = {
{"deflate", "deflate"},
{"lz77_zstd", "lz77_zstd"},
{"hashagg", "hashagg"},
+ {"udma", "udma"},
{"rsa", "rsa"},
{"dh", "dh"},
--
2.33.0
1
0
*** BLURB HERE ***
Chenghai Huang (9):
uadk: fix definition coding standard issues
uadk: add or remove some store buf condition judgments
uadk: add new alg called lz77_only
uadk: modify the condition for copying repcode
uadk: remove redundant checks on bit read results
uadk_tool: modify unrecv num in async benchmark test
uadk_tool: add lz77_only alg in zip benchmark test
uadk_tool: add lz4 alg in zip benchmark test
uadk: fix a sgl pool memery issue in lz77_only
Longfang Liu (1):
uadk: resolve some code issues
Qi Tao (1):
uadk_tool: add aead algorithm
Qinxin Xia (5):
uadk: hisi_comp - abstract get sgl function and general deflate
functions
uadk: hisi_comp - support the new algorithm 'lz4'
uadk: wd_comp - support the new algorithm 'lz4'
uadk: hisi_comp: reduce some invalid spaces.
uadk: rectify the incorrect boundary value judgment of LZ4
Weili Qian (1):
uadk: support data move
Wenkai Lin (9):
uadk: support hashjoin and gather algorithm
uadk: fix for build and probe index check
uadk: fix for check_key_cols_info
uadk: reduce repeated dae code
uadk: modify print info for wd_gather_get_batch_rowsize
uadk: fix for rehash invalid size
uadk: optimize for rehash performance
uadk: fix for the segment fault in gather param check
uadk: fix for the hashjoin task runtime error
Zhushuai Yin (6):
uadk: Add max and min operations at the hash algorithm layer
uadk: hash agg adapter drv parameter
uadk:Add max,min,and rehash implementations
uadk:zip algorithm increases buffer len interception
uadk: Fix the problem of failing to intercept the new comp stream
scene
uadk:fix dh prov segmentation issue
Makefile.am | 31 +-
drv/hisi_comp.c | 565 +++++--
drv/hisi_comp_huf.c | 11 +-
drv/hisi_dae.c | 826 +++-------
drv/hisi_dae.h | 229 +++
drv/hisi_dae_common.c | 387 +++++
drv/hisi_dae_join_gather.c | 1040 ++++++++++++
drv/hisi_qm_udrv.h | 3 +-
drv/hisi_udma.c | 566 +++++++
include/drv/wd_agg_drv.h | 10 +-
include/drv/wd_join_gather_drv.h | 52 +
include/drv/wd_udma_drv.h | 34 +
include/wd_agg.h | 9 +-
include/wd_alg.h | 4 +
include/wd_comp.h | 2 +
include/wd_dae.h | 12 +
include/wd_join_gather.h | 352 +++++
include/wd_udma.h | 124 ++
include/wd_util.h | 2 +
libwd_dae.map | 34 +-
uadk_tool/benchmark/sec_uadk_benchmark.c | 34 +
uadk_tool/benchmark/sec_wd_benchmark.c | 34 +
uadk_tool/benchmark/uadk_benchmark.c | 14 +
uadk_tool/benchmark/uadk_benchmark.h | 4 +
uadk_tool/benchmark/zip_uadk_benchmark.c | 24 +-
v1/drv/hisi_zip_huf.c | 11 +-
v1/drv/hisi_zip_udrv.c | 2 +-
wd.c | 2 +-
wd_agg.c | 76 +-
wd_comp.c | 56 +-
wd_join_gather.c | 1823 ++++++++++++++++++++++
wd_sched.c | 3 +-
wd_udma.c | 511 ++++++
wd_util.c | 34 +-
34 files changed, 6125 insertions(+), 796 deletions(-)
create mode 100644 drv/hisi_dae.h
create mode 100644 drv/hisi_dae_common.c
create mode 100644 drv/hisi_dae_join_gather.c
create mode 100644 drv/hisi_udma.c
create mode 100644 include/drv/wd_join_gather_drv.h
create mode 100644 include/drv/wd_udma_drv.h
create mode 100644 include/wd_join_gather.h
create mode 100644 include/wd_udma.h
create mode 100644 wd_join_gather.c
create mode 100644 wd_udma.c
--
2.33.0
1
32
From: JiangShui Yang <yangjiangshui(a)h-partners.com>
Chenghai Huang (1):
uadk_provider: add reset for part of ctx after final
Qi Tao (1):
uadk_provider/rsa: bugfix for rsa digest interface
Weili Qian (3):
uadk_engine/sm2: set the default user id
uadk_provider/sm2: delete duplicate applications sess
uadk_engine/digest: small packet directly uses soft computing
Wenkai Lin (2):
uadk_engine: optimize for sec cipher and digest init
uadk_engine/aead: fix for set key problem
Zhushuai Yin (3):
uadk_provider:Improved SM3 hmac performance
uadk_engine:Fix DH algorithm shared key comparison failure
uadk_provider/sm2:fix the issue of SM2 authentication failure
lizhi (2):
uadk_provider: clean up unused functions
uadk_prov: fix a cleancode issue
src/uadk_aead.c | 65 ++++++++++----------
src/uadk_async.c | 5 ++
src/uadk_async.h | 1 +
src/uadk_cipher.c | 98 +++++++++++++-----------------
src/uadk_dh.c | 8 ++-
src/uadk_digest.c | 120 ++++++++++++++++++-------------------
src/uadk_prov_der_writer.c | 69 ---------------------
src/uadk_prov_der_writer.h | 4 --
src/uadk_prov_digest.c | 29 ++++++---
src/uadk_prov_ffc.c | 3 +-
src/uadk_prov_hmac.c | 18 ++++--
src/uadk_prov_rsa.c | 107 +++++++++++++++++++++------------
src/uadk_prov_sm2.c | 108 +++++++++++++++++----------------
src/uadk_sm2.c | 95 +++++++++++++++--------------
14 files changed, 356 insertions(+), 374 deletions(-)
--
2.43.0
1
12
您好!
sig-AccLib 邀请您参加 2025-08-06 11:00 召开的Zoom会议
会议主题:2025/8/6 AccLIb SIG 双周例会 11:00 - 12:00
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/87414340535?pwd=sXcaBaZEpTqpKISlBDzkMyMwMfZKAh.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-08-06 11:00,
The subject of the conference is 2025/8/6 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/87414340535?pwd=sXcaBaZEpTqpKISlBDzkMyMwMfZKAh.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
doc
https://docs.qq.com/doc/DRVBtbVh6TkdaTFVB
memcpy
++ ./uadk_tool/uadk_tool benchmark --alg zlib --mode sva --opt 0 --sync --pktlen 1024
algname: length: perf: iops: CPU_rate:
zlib 1024Bytes 336851.00KiB/s 336.9Kops 293.67%
user pointer // --user
++ ./uadk_tool/uadk_tool benchmark --alg zlib --mode sva --user --opt 0 --sync --pktlen 1024
algname: length: perf: iops: CPU_rate:
zlib 1024Bytes 522916.00KiB/s 522.9Kops 299.67%
sgl // --sgl
++ ./uadk_tool/uadk_tool benchmark --alg zlib --mode sva --sgl --opt 0 --sync --pktlen 1024
algname: length: perf: iops: CPU_rate:
zlib 1024Bytes 415577.00KiB/s 415.6Kops 299.67%
Zhangfei Gao (7):
uadk: remove nosva limitation
uadk: add wd_reserve_mem & wd_is_noiommu for nosva
uadk: add blkpool
uadk: ctxs call wd_blkpool_new at init and delete blkpool at uninit
wd_comp: add wd_comp_setup_blkpool
wd_comp: support nosva case
uadk_tool: support nosva test
Makefile.am | 1 +
drv/hisi_comp.c | 98 ++-
drv/hisi_qm_udrv.c | 14 +-
drv/hisi_qm_udrv.h | 3 +-
drv/hisi_sec.c | 8 +-
include/drv/wd_comp_drv.h | 7 +
include/uacce.h | 6 +-
include/wd.h | 16 +
include/wd_alg_common.h | 9 +
include/wd_bmm.h | 66 ++
include/wd_comp.h | 2 +
libwd.map | 10 +
libwd_comp.map | 1 +
uadk_tool/benchmark/uadk_benchmark.c | 8 +
uadk_tool/benchmark/uadk_benchmark.h | 2 +
uadk_tool/benchmark/zip_uadk_benchmark.c | 146 ++++-
wd.c | 34 +-
wd_alg.c | 44 +-
wd_bmm.c | 739 +++++++++++++++++++++++
wd_comp.c | 84 +++
wd_util.c | 13 +-
21 files changed, 1213 insertions(+), 98 deletions(-)
create mode 100644 include/wd_bmm.h
create mode 100644 wd_bmm.c
--
2.25.1
1
7
您好!
sig-AccLib 邀请您参加 2025-07-23 11:00 召开的Zoom会议
会议主题:【2025/7/23 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/87687572460?pwd=vbbd91ASP0NR3Taa6E9bawp14QR0Qh.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-07-23 11:00,
The subject of the conference is 【2025/7/23 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/87687572460?pwd=vbbd91ASP0NR3Taa6E9bawp14QR0Qh.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
您好!
sig-AccLib 邀请您参加 2025-07-09 11:00 召开的Zoom会议
会议主题:【2025/7/9 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/87048823607?pwd=j9jXyW5hh2ztCnoasdV2LhPzSJRiiL.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-07-09 11:00,
The subject of the conference is 【2025/7/9 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/87048823607?pwd=j9jXyW5hh2ztCnoasdV2LhPzSJRiiL.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
您好!
sig-AccLib 邀请您参加 2025-06-25 11:00 召开的Zoom会议
会议主题:【2025/6/25 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/89107269981?pwd=fG5l7sJqKZ2oa8MLBvKEM95gjCeYzU.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-06-25 11:00,
The subject of the conference is 【2025/6/25 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/89107269981?pwd=fG5l7sJqKZ2oa8MLBvKEM95gjCeYzU.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
From: Chenghai Huang <huangchenghai2(a)huawei.com>
In the destructor, it need to check whether zlibwrapper has been
initialized, otherwise it will cause double free.
Signed-off-by: Chenghai Huang <huangchenghai2(a)huawei.com>
---
wd_zlibwrapper.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/wd_zlibwrapper.c b/wd_zlibwrapper.c
index a08db320..ea1667bb 100644
--- a/wd_zlibwrapper.c
+++ b/wd_zlibwrapper.c
@@ -299,5 +299,6 @@ int wd_inflate_end(z_streamp strm)
__attribute__ ((destructor)) static void wd_zlibwrapper_destory(void)
{
- wd_zlib_uadk_uninit();
+ if (zlib_status == WD_ZLIB_INIT)
+ wd_zlib_uadk_uninit();
}
--
2.33.0
1
0
From: Chenghai Huang <huangchenghai2(a)huawei.com>
---
wd_zlibwrapper.c | 47 +++++++++++++++++++++++++----------------------
1 file changed, 25 insertions(+), 22 deletions(-)
diff --git a/wd_zlibwrapper.c b/wd_zlibwrapper.c
index a08db32..7411455 100644
--- a/wd_zlibwrapper.c
+++ b/wd_zlibwrapper.c
@@ -24,6 +24,18 @@ enum uadk_init_status {
WD_ZLIB_INIT,
};
+enum alg_win_bits {
+ DEFLATE_MIN_WBITS = -15,
+ DEFLATE_4K_WBITS = 12,
+ DEFLATE_MAX_WBITS = -8,
+ ZLIB_MIN_WBITS = 8,
+ ZLIB_4K_WBITS = 12,
+ ZLIB_MAX_WBITS = 15,
+ GZIP_MIN_WBITS = 24,
+ GZIP_4K_WBITS = 28,
+ GZIP_MAX_WBITS = 31,
+};
+
static pthread_mutex_t wd_zlib_mutex = PTHREAD_MUTEX_INITIALIZER;
static int zlib_status;
@@ -88,28 +100,19 @@ static void wd_zlib_uadk_uninit(void)
static int wd_zlib_analy_alg(int windowbits, int *alg, int *windowsize)
{
- static const int ZLIB_MAX_WBITS = 15;
- static const int ZLIB_MIN_WBITS = 8;
- static const int GZIP_MAX_WBITS = 31;
- static const int GZIP_MIN_WBITS = 24;
- static const int DEFLATE_MAX_WBITS = -8;
- static const int DEFLATE_MIN_WBITS = -15;
- static const int WBINS_ZLIB_4K = 12;
- static const int WBINS_GZIP_4K = 28;
- static const int WBINS_DEFLATE_4K = 12;
-
- if ((windowbits >= ZLIB_MIN_WBITS) && (windowbits <= ZLIB_MAX_WBITS)) {
- *alg = WD_ZLIB;
- *windowsize = max(windowbits - WBINS_ZLIB_4K, WD_COMP_WS_4K);
- } else if ((windowbits >= GZIP_MIN_WBITS) && (windowbits <= GZIP_MAX_WBITS)) {
- *alg = WD_GZIP;
- *windowsize = max(windowbits - WBINS_GZIP_4K, WD_COMP_WS_4K);
- } else if ((windowbits >= DEFLATE_MIN_WBITS) && (windowbits <= DEFLATE_MAX_WBITS)) {
- *alg = WD_DEFLATE;
- windowbits = -windowbits;
- *windowsize = max(windowbits - WBINS_DEFLATE_4K, WD_COMP_WS_4K);
- } else {
- return Z_STREAM_ERROR;
+ switch (windowbits) {
+ case DEFLATE_MIN_WBITS ... DEFLATE_MAX_WBITS:
+ *alg = WD_DEFLATE;
+ windowbits = -windowbits;
+ *windowsize = max(windowbits - DEFLATE_4K_WBITS, WD_COMP_WS_4K);
+ case GZIP_MIN_WBITS ... GZIP_MAX_WBITS:
+ *alg = WD_GZIP;
+ *windowsize = max(windowbits - GZIP_4K_WBITS, WD_COMP_WS_4K);
+ case ZLIB_MIN_WBITS ... ZLIB_MAX_WBITS:
+ *alg = WD_ZLIB;
+ *windowsize = max(windowbits - ZLIB_4K_WBITS, WD_COMP_WS_4K);
+ default:
+ return Z_STREAM_ERROR;
}
*windowsize = *windowsize == WD_COMP_WS_24K ? WD_COMP_WS_32K : *windowsize;
--
2.33.0
1
0