Acc
Threads by month
- ----- 2026 -----
- April
- March
- 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
- 410 discussions
From: Weili Qian <qianweili(a)huawei.com>
The OpenSSL version macro is used to solve the compatibility issues
between the uadk provider and OpenSSL 3.5.
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
src/uadk_prov_ec_kmgmt.c | 13 ++++++++++++-
src/uadk_prov_ecdsa.c | 13 +++++++++++--
src/uadk_prov_ecx.c | 4 ++++
src/uadk_prov_pkey.h | 37 ++++++++++++++++++++++++++++++++++---
src/uadk_prov_rsa_enc.c | 5 ++++-
src/uadk_prov_rsa_sign.c | 7 +++++++
src/uadk_prov_sm2_sign.c | 14 +++++++++++---
7 files changed, 83 insertions(+), 10 deletions(-)
diff --git a/src/uadk_prov_ec_kmgmt.c b/src/uadk_prov_ec_kmgmt.c
index bd5cbd9..530929c 100644
--- a/src/uadk_prov_ec_kmgmt.c
+++ b/src/uadk_prov_ec_kmgmt.c
@@ -412,6 +412,7 @@ static void uadk_keymgmt_ec_gen_cleanup(void *genctx)
if (!gctx)
return;
+ OPENSSL_clear_free(gctx->dhkem_ikm, gctx->dhkem_ikmlen);
EC_GROUP_free(gctx->gen_group);
BN_free(gctx->p);
BN_free(gctx->a);
@@ -620,6 +621,13 @@ static int uadk_keymgmt_ec_gen_set_params(void *genctx, const OSSL_PARAM params[
if (!ret)
return ret;
+# if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ ret = ec_set_octet_param(OSSL_PKEY_PARAM_DHKEM_IKM, &gctx->dhkem_ikm,
+ &gctx->dhkem_ikmlen, params);
+ if (!ret)
+ return ret;
+# endif
+
return ec_set_octet_param(OSSL_PKEY_PARAM_EC_GENERATOR,
&gctx->gen, &gctx->gen_len, params);
}
@@ -640,8 +648,11 @@ static const OSSL_PARAM *uadk_keymgmt_ec_gen_settable_params(ossl_unused void *g
OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_EC_GENERATOR, NULL, 0),
OSSL_PARAM_BN(OSSL_PKEY_PARAM_EC_ORDER, NULL, 0),
OSSL_PARAM_BN(OSSL_PKEY_PARAM_EC_COFACTOR, NULL, 0),
- OSSL_PARAM_BN(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0),
OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_EC_SEED, NULL, 0),
+# if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_DHKEM_IKM, NULL, 0),
+# endif
+ OSSL_PARAM_BN(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0),
OSSL_PARAM_END
};
diff --git a/src/uadk_prov_ecdsa.c b/src/uadk_prov_ecdsa.c
index 3876488..44f64f6 100644
--- a/src/uadk_prov_ecdsa.c
+++ b/src/uadk_prov_ecdsa.c
@@ -53,7 +53,9 @@ struct ecdsa_ctx {
/* The Algorithm Identifier of the combined signature algorithm */
unsigned char aid_buf[MAX_ALGORITHM_ID_SIZE];
+#if OPENSSL_VERSION_NUMBER < 0x30400000L
unsigned char *aid;
+#endif
size_t aid_len;
size_t mdsize;
int operation;
@@ -174,6 +176,7 @@ err:
static void ecdsa_set_aid(struct ecdsa_ctx *ctx, int md_nid)
{
+ unsigned char *aid = NULL;
WPACKET pkt;
ctx->aid_len = 0;
@@ -181,9 +184,11 @@ static void ecdsa_set_aid(struct ecdsa_ctx *ctx, int md_nid)
ossl_DER_w_algorithmIdentifier_ECDSA_with_MD(&pkt, -1, ctx->ec, md_nid) &&
WPACKET_finish(&pkt)) {
WPACKET_get_total_written(&pkt, &ctx->aid_len);
- ctx->aid = WPACKET_get_curr(&pkt);
+ aid = WPACKET_get_curr(&pkt);
}
WPACKET_cleanup(&pkt);
+ if (aid && ctx->aid_len)
+ memmove(ctx->aid_buf, aid, ctx->aid_len);
}
/*
@@ -969,13 +974,17 @@ static int uadk_signature_ecdsa_digest_verify_final(void *vctx, const unsigned c
static int ecdsa_get_ctx_aid(struct ecdsa_ctx *ctx, OSSL_PARAM *params)
{
+ unsigned char *aid = NULL;
OSSL_PARAM *p;
+ if (ctx->aid_len)
+ aid = ctx->aid_buf;
+
p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
if (!p)
return UADK_P_SUCCESS;
- return OSSL_PARAM_set_octet_string(p, ctx->aid, ctx->aid_len);
+ return OSSL_PARAM_set_octet_string(p, aid, ctx->aid_len);
}
static int ecdsa_get_ctx_digest_size(struct ecdsa_ctx *ctx, OSSL_PARAM *params)
diff --git a/src/uadk_prov_ecx.c b/src/uadk_prov_ecx.c
index 7353836..69494cc 100644
--- a/src/uadk_prov_ecx.c
+++ b/src/uadk_prov_ecx.c
@@ -147,6 +147,10 @@ typedef struct {
char *propq;
ECX_KEY_TYPE type;
int selection;
+# if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ unsigned char *dhkem_ikm;
+ size_t dhkem_ikmlen;
+# endif
size_t keylen;
/* uadk sesssion */
handle_t sess;
diff --git a/src/uadk_prov_pkey.h b/src/uadk_prov_pkey.h
index e82df34..aa7a07b 100644
--- a/src/uadk_prov_pkey.h
+++ b/src/uadk_prov_pkey.h
@@ -121,6 +121,8 @@ struct ec_gen_ctx {
int selection;
int ecdh_mode;
EC_GROUP *gen_group;
+ unsigned char *dhkem_ikm;
+ size_t dhkem_ikmlen;
BIGNUM *priv_key;
};
@@ -129,12 +131,17 @@ typedef struct {
int id;
int name_id;
+#if OPENSSL_VERSION_NUMBER >= 0x30300000L
+ /* NID for the legacy alg if there is one */
+ int legacy_alg;
+# endif
char *type_name;
const char *description;
OSSL_PROVIDER *prov;
int refcnt;
+#if OPENSSL_VERSION_NUMBER < 0x30200000L
void *lock;
-
+# endif
/* Constructor(s), destructor, information */
OSSL_FUNC_keymgmt_new_fn *new_fun;
OSSL_FUNC_keymgmt_free_fn *free;
@@ -146,6 +153,10 @@ typedef struct {
/* Generation, a complex constructor */
OSSL_FUNC_keymgmt_gen_init_fn *gen_init;
OSSL_FUNC_keymgmt_gen_set_template_fn *gen_set_template;
+#if OPENSSL_VERSION_NUMBER >= 0x30400000L
+ OSSL_FUNC_keymgmt_gen_get_params_fn *gen_get_params;
+ OSSL_FUNC_keymgmt_gen_gettable_params_fn *gen_gettable_params;
+# endif
OSSL_FUNC_keymgmt_gen_set_params_fn *gen_set_params;
OSSL_FUNC_keymgmt_gen_settable_params_fn *gen_settable_params;
OSSL_FUNC_keymgmt_gen_fn *gen;
@@ -161,8 +172,14 @@ typedef struct {
/* Import and export routines */
OSSL_FUNC_keymgmt_import_fn *import;
OSSL_FUNC_keymgmt_import_types_fn *import_types;
+#if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ OSSL_FUNC_keymgmt_import_types_ex_fn *import_types_ex;
+# endif
OSSL_FUNC_keymgmt_export_fn *export_fun;
OSSL_FUNC_keymgmt_export_types_fn *export_types;
+#if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ OSSL_FUNC_keymgmt_export_types_ex_fn *export_types_ex;
+# endif
OSSL_FUNC_keymgmt_dup_fn *dup;
} UADK_PKEY_KEYMGMT;
@@ -228,13 +245,24 @@ typedef struct {
const char *description;
OSSL_PROVIDER *prov;
int refcnt;
+#if OPENSSL_VERSION_NUMBER < 0x30200000L
void *lock;
-
+#endif
OSSL_FUNC_signature_newctx_fn *newctx;
OSSL_FUNC_signature_sign_init_fn *sign_init;
OSSL_FUNC_signature_sign_fn *sign;
+#if OPENSSL_VERSION_NUMBER >= 0x30400000L
+ OSSL_FUNC_signature_sign_message_init_fn *sign_message_init;
+ OSSL_FUNC_signature_sign_message_update_fn *sign_message_update;
+ OSSL_FUNC_signature_sign_message_final_fn *sign_message_final;
+#endif
OSSL_FUNC_signature_verify_init_fn *verify_init;
OSSL_FUNC_signature_verify_fn *verify;
+#if OPENSSL_VERSION_NUMBER >= 0x30400000L
+ OSSL_FUNC_signature_verify_message_init_fn *verify_message_init;
+ OSSL_FUNC_signature_verify_message_update_fn *verify_message_update;
+ OSSL_FUNC_signature_verify_message_final_fn *verify_message_final;
+#endif
OSSL_FUNC_signature_verify_recover_init_fn *verify_recover_init;
OSSL_FUNC_signature_verify_recover_fn *verify_recover;
OSSL_FUNC_signature_digest_sign_init_fn *digest_sign_init;
@@ -330,8 +358,9 @@ typedef struct {
const char *description;
OSSL_PROVIDER *prov;
int refcnt;
+#if OPENSSL_VERSION_NUMBER < 0x30200000L
void *lock;
-
+#endif
OSSL_FUNC_asym_cipher_newctx_fn *newctx;
OSSL_FUNC_asym_cipher_encrypt_init_fn *encrypt_init;
OSSL_FUNC_asym_cipher_encrypt_fn *encrypt;
@@ -384,7 +413,9 @@ typedef struct {
const char *description;
OSSL_PROVIDER *prov;
int refcnt;
+#if OPENSSL_VERSION_NUMBER < 0x30200000L
void *lock;
+#endif
OSSL_FUNC_keyexch_newctx_fn *newctx;
OSSL_FUNC_keyexch_init_fn *init;
diff --git a/src/uadk_prov_rsa_enc.c b/src/uadk_prov_rsa_enc.c
index 50005f9..c0da4c9 100644
--- a/src/uadk_prov_rsa_enc.c
+++ b/src/uadk_prov_rsa_enc.c
@@ -44,7 +44,10 @@ struct PROV_RSA_ASYM_CTX {
/* TLS padding */
unsigned int client_version;
unsigned int alt_version;
-
+#if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ /* PKCS#1 v1.5 decryption mode */
+ unsigned int implicit_rejection;
+# endif
unsigned int soft : 1;
};
diff --git a/src/uadk_prov_rsa_sign.c b/src/uadk_prov_rsa_sign.c
index 4db3ab7..8483b2e 100644
--- a/src/uadk_prov_rsa_sign.c
+++ b/src/uadk_prov_rsa_sign.c
@@ -44,6 +44,9 @@ struct PROV_RSA_SIG_CTX {
*/
unsigned int flag_allow_md : 1;
unsigned int mgf1_md_set : 1;
+ unsigned int flag_allow_update : 1;
+ unsigned int flag_allow_final : 1;
+ unsigned int flag_allow_oneshot : 1;
/* main digest */
EVP_MD *md;
@@ -61,6 +64,10 @@ struct PROV_RSA_SIG_CTX {
int saltlen;
/* Minimum salt length or -1 if no PSS parameter restriction */
int min_saltlen;
+#if OPENSSL_VERSION_NUMBER >= 0x30400000L
+ unsigned char *sig;
+ size_t siglen;
+#endif
/* Temp buffer */
unsigned char *tbuf;
diff --git a/src/uadk_prov_sm2_sign.c b/src/uadk_prov_sm2_sign.c
index 27627c1..aa7049e 100644
--- a/src/uadk_prov_sm2_sign.c
+++ b/src/uadk_prov_sm2_sign.c
@@ -61,8 +61,10 @@ typedef struct {
/* The Algorithm Identifier of the combined signature algorithm */
unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE];
+#if OPENSSL_VERSION_NUMBER < 0x30400000L
unsigned char *aid;
- size_t aid_len;
+#endif
+ size_t aid_len;
/* main digest */
EVP_MD *md;
@@ -755,6 +757,7 @@ static int sm2_digest_signverify_init(void *vpsm2ctx, const char *mdname,
void *ec, const OSSL_PARAM params[])
{
PROV_SM2_SIGN_CTX *psm2ctx = (PROV_SM2_SIGN_CTX *)vpsm2ctx;
+ unsigned char *aid = NULL;
int md_nid;
WPACKET pkt;
@@ -784,9 +787,11 @@ static int sm2_digest_signverify_init(void *vpsm2ctx, const char *mdname,
ossl_DER_w_algorithmIdentifier_SM2_with_MD(&pkt, -1, psm2ctx->key, md_nid) &&
WPACKET_finish(&pkt)) {
WPACKET_get_total_written(&pkt, &psm2ctx->aid_len);
- psm2ctx->aid = WPACKET_get_curr(&pkt);
+ aid = WPACKET_get_curr(&pkt);
}
WPACKET_cleanup(&pkt);
+ if (aid && psm2ctx->aid_len)
+ memmove(psm2ctx->aid_buf, aid, psm2ctx->aid_len);
if (!EVP_DigestInit_ex2(psm2ctx->mdctx, psm2ctx->md, params)) {
UADK_ERR("failed to do digest init\n");
@@ -1240,6 +1245,7 @@ static const OSSL_PARAM *uadk_signature_sm2_gettable_ctx_params(ossl_unused void
static int uadk_signature_sm2_get_ctx_params(void *vpsm2ctx, OSSL_PARAM *params)
{
PROV_SM2_SIGN_CTX *psm2ctx = (PROV_SM2_SIGN_CTX *)vpsm2ctx;
+ unsigned char *aid = NULL;
OSSL_PARAM *p;
if (!psm2ctx) {
@@ -1247,8 +1253,10 @@ static int uadk_signature_sm2_get_ctx_params(void *vpsm2ctx, OSSL_PARAM *params)
return UADK_P_FAIL;
}
+ if (psm2ctx->aid_len)
+ aid = psm2ctx->aid_buf;
p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
- if (p && !OSSL_PARAM_set_octet_string(p, psm2ctx->aid, psm2ctx->aid_len)) {
+ if (p != NULL && !OSSL_PARAM_set_octet_string(p, aid, psm2ctx->aid_len)) {
UADK_ERR("failed to locate algorithm id\n");
return UADK_P_FAIL;
}
--
2.33.0
1
0
[PATCH 00/11] uadk: Fixing compression-related issues and functional enhancements
by ZongYu Wu 27 Apr '26
by ZongYu Wu 27 Apr '26
27 Apr '26
This patch set primarily fixes multiple issues related to compression in the uadk driver and adds some functional enhancements.
Main fixes include:
- Resolving the compression status issue when the storage buffer is not cleared
- Moving the tail packet append function to the hisi_comp.c file
- Removing redundant print information in v1/hisi_zip_udrv
- Fixing the hashjoin key alignment size issue
- Cleaning up wd_agg code
- Addressing some code parameter issues
- Fixing large number comparison issues
- Correcting the HPRE parameter comparison method
- Supporting empty final blocks in stream mode
- Fixing long timeout issues in synchronous mode when a device failure occurs.
Chenghai Huang (4):
uadk: clear the literal length in the ctx of all LZ77 algorithms
uadk: fix the status of compression when store buffer is not yet
cleared
uadk: move tail packet appending function to hisi_comp.c
uadk: delete redundant print messages for v1/hisi_zip_udrv
Longfang Liu (3):
uadk: bugfix some code parameter issues.
uadk: bugfix big number comparison issues
uadk: bugfix HPRE parameter comparison method
Wenkai Lin (2):
uadk: fix for hashjoin key align size
uadk: clean code for wd_agg
ZongYu Wu (1):
uadk: support empty final block for raw DEFLATE in stream mode
lizhi (1):
uadk/v1: fix long timeout of asymmetric algorithm in sync mode during
device failure
drv/hisi_comp.c | 111 +++++++++++++++++++++++++++++--------
drv/hisi_dae_join_gather.c | 2 +-
drv/hisi_hpre.c | 23 +++++---
drv/hisi_sec.c | 2 +-
include/drv/wd_comp_drv.h | 2 +
include/wd_internal.h | 2 +
libwd.map | 1 +
v1/drv/hisi_zip_udrv.c | 33 ++++-------
v1/wd_dh.c | 12 ++--
v1/wd_ecc.c | 12 ++--
v1/wd_rsa.c | 14 +++--
v1/wd_util.c | 31 +++++++++++
v1/wd_util.h | 2 +
wd.c | 19 +++++++
wd_aead.c | 4 +-
wd_agg.c | 34 ++++++------
wd_cipher.c | 2 +-
wd_comp.c | 72 +-----------------------
wd_join_gather.c | 2 +-
19 files changed, 218 insertions(+), 162 deletions(-)
--
2.33.0
1
11
From: Junchong Pan <panjunchong(a)h-partners.com>
Signed-off-by: Junchong Pan <panjunchong(a)h-partners.com>
---
Makefile.am | 2 +-
test/hisi_hpre_test/Makefile.am | 1 +
uadk_tool/Makefile.am | 14 +-
uadk_tool/benchmark/sec_soft3_benchmark.c | 1431 +++++++++++++++++++++
uadk_tool/benchmark/sec_soft3_benchmark.h | 8 +
uadk_tool/benchmark/uadk_benchmark.c | 18 +-
uadk_tool/test/comp_lib.c | 21 +-
uadk_tool/test/comp_lib.h | 10 +
uadk_tool/test/comp_main.c | 8 +-
uadk_tool/test/uadk_test.c | 4 +-
10 files changed, 1499 insertions(+), 18 deletions(-)
create mode 100644 uadk_tool/benchmark/sec_soft3_benchmark.c
create mode 100644 uadk_tool/benchmark/sec_soft3_benchmark.h
diff --git a/Makefile.am b/Makefile.am
index 84c97e9..fe619f3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,7 +3,7 @@ AUTOMAKE_OPTIONS = foreign subdir-objects
AM_CFLAGS=-std=gnu11 -Wall -Werror -Wextra -Wno-unused-parameter -Wfloat-equal \
-fno-common -fno-strict-aliasing -I$(top_srcdir)/include
AM_CFLAGS+=-fPIC -fPIE -pie -fstack-protector-strong -D_FORTIFY_SOURCE=2 \
- -O2 -ftrapv -Wl,-z,relro,-z,now -Wl,-s
+ -O0 -ftrapv -Wl,-z,relro,-z,now -g
AM_CFLAGS += -Wall -Wuninitialized -Wno-error -Wno-error=format -Wundef \
-Wunused -Wdate-time -Wfloat-equal -Wshadow -Wvla -Wdisabled-optimization \
-Wempty-body -Wignored-qualifiers -Wimplicit-fallthrough=3 -Wtype-limits \
diff --git a/test/hisi_hpre_test/Makefile.am b/test/hisi_hpre_test/Makefile.am
index 6cc8a37..e32ac95 100644
--- a/test/hisi_hpre_test/Makefile.am
+++ b/test/hisi_hpre_test/Makefile.am
@@ -14,5 +14,6 @@ endif
test_hisi_hpre_LDFLAGS=-Wl,-rpath,'/usr/local/lib'
if WITH_OPENSSL_DIR
AM_CFLAGS+= -DWITH_OPENSSL_DIR
+test_hisi_hpre_LDADD+= $(with_openssl_dir)/libcrypto.so.3
test_hisi_hpre_LDADD+= $(with_openssl_dir)/libcrypto_wd.so
endif
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am
index 6fd9d95..ee7dea4 100644
--- a/uadk_tool/Makefile.am
+++ b/uadk_tool/Makefile.am
@@ -1,9 +1,9 @@
ACLOCAL_AMFLAGS = -I m4 -I./include
AUTOMAKE_OPTIONS = foreign subdir-objects
-AM_CFLAGS=-Wall -Werror -fno-strict-aliasing -I$(top_srcdir) -I$(top_srcdir)/benchmark/include \
+AM_CFLAGS=-Wall -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
+-O0 -ftrapv -Wl,-z,now -g
#AUTOMAKE_OPTIONS = subdir-objects
@@ -50,14 +50,18 @@ endif
if WITH_OPENSSL_DIR
AM_CFLAGS+= -DWITH_OPENSSL_DIR -I$(with_openssl_dir)/include
+AM_CFLAGS+= -DHAVE_OPENSSL3=$(shell echo '#include <openssl/opensslv.h>' | \
+ $(CC) -E -I$(with_openssl_dir)/include - | grep 'OPENSSL_VERSION_MAJOR' | sed 's/#define OPENSSL_VERSION_MAJOR //')
+
+uadk_tool_SOURCES+=test/comp_main.c test/comp_main.h test/comp_lib.c test/comp_lib.h
+# uadk_tool_SOURCES+=benchmark/sec_soft_benchmark.c benchmark/sec_soft_benchmark.h
+uadk_tool_SOURCES+=benchmark/sec_soft3_benchmark.c benchmark/sec_soft3_benchmark.h
-uadk_tool_SOURCES+=benchmark/sec_soft_benchmark.c benchmark/sec_soft_benchmark.h \
- test/comp_main.c test/comp_main.h test/comp_lib.c test/comp_lib.h
if WD_STATIC_DRV
uadk_tool_LDADD+= $(with_openssl_dir)/libcrypto.a
else
-uadk_tool_LDADD+= $(with_openssl_dir)/libcrypto.so.1.1
+uadk_tool_LDADD+= $(with_openssl_dir)/libcrypto.so.3
endif
endif
diff --git a/uadk_tool/benchmark/sec_soft3_benchmark.c b/uadk_tool/benchmark/sec_soft3_benchmark.c
new file mode 100644
index 0000000..8d40074
--- /dev/null
+++ b/uadk_tool/benchmark/sec_soft3_benchmark.c
@@ -0,0 +1,1431 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+
+#define _GNU_SOURCE
+#include "openssl/async.h"
+#include "openssl/bn.h"
+#include "openssl/crypto.h"
+#include "openssl/engine.h"
+#include "openssl/err.h"
+#include "openssl/evp.h"
+#include "openssl/ossl_typ.h"
+#include "openssl/objects.h"
+#include "openssl/ssl.h"
+#include "openssl/provider.h"
+#include "openssl/x509.h"
+#include "openssl/param_build.h"
+
+#include "include/wd_cipher.h"
+#include "include/wd_digest.h"
+#include "sec_soft3_benchmark.h"
+
+#define SSL_TST_PRT printf
+#define ENV_STRING_LEN 256
+
+struct soft_bd {
+ u8 *src;
+ u8 *dst;
+};
+
+struct bd_pool {
+ struct soft_bd *bds;
+};
+
+struct thread_pool {
+ struct bd_pool *pool;
+ u8 *iv;
+ u8 *key;
+} g_soft_pool;
+
+typedef struct soft_thread_res {
+ const EVP_CIPHER *evp_cipher;
+ const EVP_MD *evp_md;
+ OSSL_PROVIDER *engine;
+ u32 subtype;
+ u32 mode;
+ u32 keysize;
+ u32 optype;
+ u32 td_id;
+ u32 engine_flag;
+ u32 sync_mode;
+} soft_thread;
+
+typedef struct soft_jobs_res {
+ const EVP_CIPHER *evp_cipher;
+ const EVP_MD *evp_md;
+ OSSL_PROVIDER *engine;
+ u32 subtype;
+ u32 mode;
+ u32 keysize;
+ u32 optype;
+ u32 td_id;
+ u32 jobid;
+} jobs_data;
+
+typedef struct soft_loop_args {
+ ASYNC_JOB *in_job;
+ ASYNC_WAIT_CTX *wait_ctx;
+ bool job_valid;
+} jobs_args;
+
+#define MAX_IVK_LENTH 64
+#define DEF_IVK_DATA 0xAA
+#define MAX_JOBS_NUM MAX_CTX_NUM
+
+static unsigned int g_thread_num;
+static unsigned int g_jobsnum;
+static unsigned int g_pktlen;
+
+static int init_soft_bd_pool(void)
+{
+ unsigned long step;
+ int fill_size;
+ int i, j;
+
+ // make the block not align to 4K
+ step = sizeof(char) * g_pktlen * 2;
+ if (g_pktlen > MAX_IVK_LENTH)
+ fill_size = MAX_IVK_LENTH;
+ else
+ fill_size = g_pktlen;
+
+ g_soft_pool.iv = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
+ g_soft_pool.key = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
+
+ g_soft_pool.pool = malloc(g_thread_num * sizeof(struct bd_pool));
+ if (!g_soft_pool.pool) {
+ SSL_TST_PRT("init openssl pool alloc thread failed!\n");
+ return -ENOMEM;
+ } else {
+ for (i = 0; i < g_thread_num; i++) {
+ g_soft_pool.pool[i].bds = malloc(MAX_POOL_LENTH *
+ sizeof(struct soft_bd));
+ if (!g_soft_pool.pool[i].bds) {
+ SSL_TST_PRT("init openssl bds alloc failed!\n");
+ goto malloc_error1;
+ }
+ for (j = 0; j < MAX_POOL_LENTH; j++) {
+ g_soft_pool.pool[i].bds[j].src = malloc(step);
+ if (!g_soft_pool.pool[i].bds[j].src)
+ goto malloc_error2;
+ g_soft_pool.pool[i].bds[j].dst = malloc(step);
+ if (!g_soft_pool.pool[i].bds[j].dst)
+ goto malloc_error3;
+
+ get_rand_data(g_soft_pool.pool[i].bds[j].src, fill_size);
+ }
+ }
+ }
+
+ return 0;
+
+malloc_error3:
+ free(g_soft_pool.pool[i].bds[j].src);
+malloc_error2:
+ for (j--; j >= 0; j--) {
+ free(g_soft_pool.pool[i].bds[j].src);
+ free(g_soft_pool.pool[i].bds[j].dst);
+ }
+malloc_error1:
+ for (i--; i >= 0; i--) {
+ for (j = 0; j < MAX_POOL_LENTH; j++) {
+ free(g_soft_pool.pool[i].bds[j].src);
+ free(g_soft_pool.pool[i].bds[j].dst);
+ }
+ free(g_soft_pool.pool[i].bds);
+ g_soft_pool.pool[i].bds = NULL;
+ }
+ free(g_soft_pool.pool);
+ g_soft_pool.pool = NULL;
+
+ free(g_soft_pool.iv);
+ free(g_soft_pool.key);
+
+ SSL_TST_PRT("init openssl bd pool alloc failed!\n");
+ return -ENOMEM;
+}
+
+static void free_soft_bd_pool(void)
+{
+ int i, j;
+
+ for (i = 0; i < g_thread_num; i++) {
+ if (g_soft_pool.pool[i].bds) {
+ for (j = 0; j < MAX_POOL_LENTH; j++) {
+ free(g_soft_pool.pool[i].bds[j].src);
+ free(g_soft_pool.pool[i].bds[j].dst);
+ }
+ }
+ free(g_soft_pool.pool[i].bds);
+ g_soft_pool.pool[i].bds = NULL;
+ }
+ free(g_soft_pool.pool);
+ g_soft_pool.pool = NULL;
+
+ free(g_soft_pool.iv);
+ free(g_soft_pool.key);
+}
+
+/*-------------------------------openssl benchmark main code-------------------------------------*/
+static int sec_soft_param_parse(soft_thread *tddata, struct acc_option *options)
+{
+ u32 algtype = options->algtype;
+ u32 optype = options->optype;
+ u8 keysize = 0;
+ u8 mode;
+
+ tddata->evp_cipher = NULL;
+ tddata->evp_md = NULL;
+
+ switch(algtype) {
+ case AES_128_ECB:
+ keysize = 16;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_aes_128_ecb();
+ break;
+ case AES_192_ECB:
+ keysize = 24;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_aes_192_ecb();
+ break;
+ case AES_256_ECB:
+ keysize = 32;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_aes_256_ecb();
+ break;
+ case AES_128_CBC:
+ keysize = 16;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_128_cbc();
+ break;
+ case AES_192_CBC:
+ keysize = 24;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_192_cbc();
+ break;
+ case AES_256_CBC:
+ keysize = 32;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_256_cbc();
+ break;
+ case AES_128_CTR:
+ keysize = 16;
+ mode = WD_CIPHER_CTR;
+ tddata->evp_cipher = EVP_aes_128_ctr();
+ break;
+ case AES_192_CTR:
+ keysize = 24;
+ mode = WD_CIPHER_CTR;
+ tddata->evp_cipher = EVP_aes_192_ctr();
+ break;
+ case AES_256_CTR:
+ keysize = 32;
+ mode = WD_CIPHER_CTR;
+ tddata->evp_cipher = EVP_aes_256_ctr();
+ break;
+ case AES_128_OFB:
+ keysize = 16;
+ mode = WD_CIPHER_OFB;
+ tddata->evp_cipher = EVP_aes_128_ofb();
+ break;
+ case AES_192_OFB:
+ keysize = 24;
+ mode = WD_CIPHER_OFB;
+ tddata->evp_cipher = EVP_aes_192_ofb();
+ break;
+ case AES_256_OFB:
+ keysize = 32;
+ mode = WD_CIPHER_OFB;
+ tddata->evp_cipher = EVP_aes_256_ofb();
+ break;
+ case AES_128_CFB:
+ keysize = 16;
+ mode = WD_CIPHER_CFB;
+ tddata->evp_cipher = EVP_aes_128_cfb();
+ break;
+ case AES_192_CFB:
+ keysize = 24;
+ mode = WD_CIPHER_CFB;
+ tddata->evp_cipher = EVP_aes_192_cfb();
+ break;
+ case AES_256_CFB:
+ keysize = 32;
+ mode = WD_CIPHER_CFB;
+ tddata->evp_cipher = EVP_aes_256_cfb();
+ break;
+ case AES_256_XTS:
+ keysize = 32;
+ mode = WD_CIPHER_XTS;
+ tddata->evp_cipher = EVP_aes_128_xts();
+ break;
+ case AES_512_XTS:
+ keysize = 64;
+ mode = WD_CIPHER_XTS;
+ tddata->evp_cipher = EVP_aes_256_xts();
+ break;
+ case DES3_128_ECB:
+ keysize = 16;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_des_ede_ecb();
+ break;
+ case DES3_192_ECB:
+ keysize = 24;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_des_ede3_ecb();
+ break;
+ case DES3_128_CBC:
+ keysize = 16;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_des_ede_cbc();
+ break;
+ case DES3_192_CBC:
+ keysize = 24;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_des_ede3_cbc();
+ break;
+#ifndef OPENSSL_NO_SM4
+ case SM4_128_ECB:
+ keysize = 16;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_sm4_ecb();
+ break;
+ case SM4_128_CBC:
+ keysize = 16;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_sm4_cbc();
+ break;
+ case SM4_128_CTR:
+ keysize = 16;
+ mode = WD_CIPHER_CTR;
+ tddata->evp_cipher = EVP_sm4_ctr();
+ break;
+ case SM4_128_OFB:
+ keysize = 16;
+ mode = WD_CIPHER_OFB;
+ tddata->evp_cipher = EVP_sm4_ofb();
+ break;
+ case SM4_128_CFB:
+ keysize = 16;
+ mode = WD_CIPHER_CFB;
+ tddata->evp_cipher = EVP_sm4_cfb128();
+ break;
+ case SM4_128_XTS:
+ keysize = 16;
+ mode = WD_CIPHER_XTS;
+ break;
+#endif
+ case AES_128_CCM:
+ keysize = 16;
+ mode = WD_CIPHER_CCM;
+ tddata->evp_cipher = EVP_aes_128_ccm();
+ break;
+ case AES_192_CCM:
+ keysize = 24;
+ mode = WD_CIPHER_CCM;
+ tddata->evp_cipher = EVP_aes_192_ccm();
+ break;
+ case AES_256_CCM:
+ keysize = 32;
+ mode = WD_CIPHER_CCM;
+ tddata->evp_cipher = EVP_aes_256_ccm();
+ break;
+ case AES_128_GCM:
+ keysize = 16;
+ mode = WD_CIPHER_GCM;
+ tddata->evp_cipher = EVP_aes_128_gcm();
+ break;
+ case AES_192_GCM:
+ keysize = 24;
+ mode = WD_CIPHER_GCM;
+ tddata->evp_cipher = EVP_aes_192_gcm();
+ break;
+ case AES_256_GCM:
+ keysize = 32;
+ mode = WD_CIPHER_GCM;
+ tddata->evp_cipher = EVP_aes_256_gcm();
+ break;
+ case AES_128_CBC_SHA256_HMAC:
+ keysize = 16;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_128_cbc();
+ break;
+ case AES_192_CBC_SHA256_HMAC:
+ keysize = 24;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_192_cbc();
+ break;
+ case AES_256_CBC_SHA256_HMAC:
+ keysize = 32;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_256_cbc();
+ break;
+#ifndef OPENSSL_NO_SM4
+ case SM4_128_CCM:
+ keysize = 16;
+ mode = WD_CIPHER_CCM;
+ break;
+ case SM4_128_GCM:
+ keysize = 16;
+ mode = WD_CIPHER_GCM;
+ break;
+#endif
+ case SM3_ALG: // digest mode is optype
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sm3();
+ break;
+ case MD5_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_md5();
+ break;
+ case SHA1_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha1();
+ break;
+ case SHA256_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha256();
+ break;
+ case SHA224_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha224();
+ break;
+ case SHA384_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha384();
+ break;
+ case SHA512_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha512();
+ break;
+ case SHA512_224:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha512_224();
+ break;
+ case SHA512_256:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha512_256();
+ break;
+ default:
+ SSL_TST_PRT("Fail to set sec alg\n");
+ return -EINVAL;
+ }
+
+ tddata->mode = mode;
+ tddata->keysize = keysize;
+ tddata->optype = options->optype;
+ tddata->subtype = options->subtype;
+
+ return 0;
+}
+
+static int sec_soft_cipher_jobfunc(void *args)
+{
+ jobs_data *jdata = (jobs_data *)args;
+ const EVP_CIPHER *evp_cipher = jdata->evp_cipher;
+ u32 optype = jdata->optype;
+ u32 jid = jdata->jobid;
+ struct bd_pool *soft_pool;
+ u8 *priv_iv, *priv_key;
+ int ret, outl, i;
+ EVP_CIPHER_CTX *ctx = NULL;
+ ASYNC_JOB *currjob;
+ u32 count = 0;
+ u8 *src, *dst;
+
+ currjob = ASYNC_get_current_job();
+ if (!currjob) {
+ SSL_TST_PRT("Error: not executing within a job\n");
+ return 0;
+ }
+
+ if (!evp_cipher) {
+ SSL_TST_PRT("Error: openssl not support!\n");
+ return 0;
+ }
+
+ if (jdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id %d out of range (max %d)\n", jdata->td_id, g_thread_num);
+ return 0;
+ }
+
+ soft_pool = &g_soft_pool.pool[jdata->td_id];
+ priv_iv = &g_soft_pool.iv[jdata->td_id];
+ priv_key = &g_soft_pool.key[jdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ ctx = EVP_CIPHER_CTX_new();
+ if (!ctx) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_new failed\n");
+ return 0;
+ }
+
+ OSSL_PARAM params[4];
+ size_t iv_len = EVP_CIPHER_get_iv_length(evp_cipher);
+
+ params[0] = OSSL_PARAM_construct_octet_string("key", priv_key, MAX_IVK_LENTH);
+ params[1] = OSSL_PARAM_construct_octet_string("iv", priv_iv, iv_len);
+ params[2] = OSSL_PARAM_construct_int("padding", 0);
+ params[3] = OSSL_PARAM_construct_end();
+
+ while (1) {
+ i = jid % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+ dst = soft_pool->bds[i].dst;
+
+ if (optype) {
+ EVP_DecryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, NULL);
+ EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_DecryptFinal_ex(ctx, dst, &outl);
+ } else {
+ EVP_EncryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, NULL);
+ EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_EncryptFinal_ex(ctx, dst, &outl);
+ }
+
+ ret = EVP_CIPHER_CTX_set_params(ctx, params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_set_params failed\n");
+ break;
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_CIPHER_CTX_free(ctx);
+
+ add_recv_data(count, g_pktlen);
+
+ return 0;
+}
+static int sec_soft_aead_jobfunc(void *args)
+{
+ jobs_data *jdata = (jobs_data *)args;
+ const EVP_CIPHER *evp_cipher = jdata->evp_cipher;
+ u32 optype = jdata->optype;
+ u32 jid = jdata->jobid;
+ struct bd_pool *soft_pool;
+ u8 *priv_iv, *priv_key;
+ int ret, outl, i;
+ EVP_CIPHER_CTX *ctx = NULL;
+ ASYNC_JOB *currjob;
+ u8 aad[13] = {0xcc};
+ u8 in_tag[12] = {0};
+ u8 out_tag[EVP_MAX_IV_LENGTH] = {0};
+ u32 count = 0;
+ u8 *src, *dst;
+ size_t taglen = 0;
+
+ currjob = ASYNC_get_current_job();
+ if (!currjob) {
+ SSL_TST_PRT("Error: not executing within a job\n");
+ return 0;
+ }
+
+ if (!evp_cipher) {
+ SSL_TST_PRT("Error: openssl not support!\n");
+ return 0;
+ }
+
+ if (jdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id %d out of range (max %d)\n", jdata->td_id, g_thread_num);
+ return 0;
+ }
+
+ soft_pool = &g_soft_pool.pool[jdata->td_id];
+ priv_iv = &g_soft_pool.iv[jdata->td_id];
+ priv_key = &g_soft_pool.key[jdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ ctx = EVP_CIPHER_CTX_new();
+ if (!ctx) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_new failed\n");
+ return 0;
+ }
+
+ while (1) {
+ i = jid % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+ dst = soft_pool->bds[i].dst;
+
+ OSSL_PARAM core_params[5];
+ int iv_len = EVP_CIPHER_get_iv_length(evp_cipher);
+ size_t key_len = MAX_IVK_LENTH;
+
+
+ memset(core_params, 0, sizeof(core_params));
+
+ core_params[0] = OSSL_PARAM_construct_octet_string("key", priv_key, key_len);
+ core_params[1] = OSSL_PARAM_construct_octet_string("iv", priv_iv, iv_len);
+
+ core_params[2] = OSSL_PARAM_construct_int("padding", 0);
+ core_params[3] = OSSL_PARAM_construct_end();
+
+ if (optype) {
+ EVP_DecryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, core_params);
+ EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_DecryptFinal_ex(ctx, dst + outl, &outl);
+ } else {
+ EVP_EncryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, core_params);
+ EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_EncryptFinal_ex(ctx, dst + outl, &outl);
+ }
+
+ if (jdata->mode == WD_CIPHER_CCM) {
+
+ taglen = 12;
+ OSSL_PARAM ccm_specific_params[3];
+ ccm_specific_params[0] = OSSL_PARAM_construct_size_t("taglen", &taglen);
+
+ int ccm_l = (iv_len - 1) - 1;
+ ccm_specific_params[1] = OSSL_PARAM_construct_int("L", &ccm_l);
+ ccm_specific_params[2] = OSSL_PARAM_construct_end();
+
+ ret = EVP_CIPHER_CTX_set_params(ctx, ccm_specific_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: CCM EVP_CIPHER_CTX_set_params failed\n");
+ break;
+ }
+ } else {
+
+ taglen = 16;
+ OSSL_PARAM gcm_specific_params[3];
+ gcm_specific_params[0] = OSSL_PARAM_construct_size_t("taglen", &taglen);
+
+ if (optype) {
+ gcm_specific_params[1] = OSSL_PARAM_construct_octet_string("tag", in_tag, sizeof(in_tag));
+ } else {
+ gcm_specific_params[1] = OSSL_PARAM_construct_octet_string("tag", out_tag, 0);
+ }
+ gcm_specific_params[2] = OSSL_PARAM_construct_end();
+
+ ret = EVP_CIPHER_CTX_set_params(ctx, gcm_specific_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: GCM EVP_CIPHER_CTX_set_params failed\n");
+ break;
+ }
+
+ OSSL_PARAM aad_params[] = {
+ OSSL_PARAM_construct_octet_string("aad", aad, sizeof(aad)),
+ OSSL_PARAM_construct_end()
+ };
+ ret = EVP_CIPHER_CTX_set_params(ctx, aad_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: GCM EVP_CIPHER_CTX_set_params(aad) failed\n");
+ break;
+ }
+ }
+
+ if (!optype && jdata->mode != WD_CIPHER_CCM) {
+ OSSL_PARAM get_tag_params[] = {
+ OSSL_PARAM_construct_octet_string("tag", out_tag, sizeof(out_tag)),
+ OSSL_PARAM_construct_end()
+ };
+ (void)EVP_CIPHER_CTX_get_params(ctx, get_tag_params);
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_CIPHER_CTX_free(ctx);
+ add_recv_data(count, g_pktlen);
+
+ return 0;
+}
+
+
+static int sec_soft_digest_jobfunc(void *args)
+{
+ jobs_data *jdata = (jobs_data *)args;
+ const EVP_MD *evp_md = jdata->evp_md;
+ u32 optype = jdata->optype;
+ u32 jid = jdata->jobid;
+ struct bd_pool *soft_pool;
+ u8 mac[EVP_MAX_MD_SIZE] = {0x00};
+ EVP_MD_CTX *md_ctx;
+ EVP_MAC *f_mac = NULL;
+ EVP_MAC_CTX *m_ctx = NULL;
+ ASYNC_JOB *currjob;
+ u32 ssl_size = 0;
+ u8 *priv_key, *src;
+ u32 count = 0;
+ size_t required_len = 0;
+ int i;
+
+ currjob = ASYNC_get_current_job();
+ if (!currjob) {
+ SSL_TST_PRT("Error: not executing within a job\n");
+ return 0;
+ }
+
+ if (!evp_md) {
+ SSL_TST_PRT("Error: openssl evp_md not support!\n");
+ return 0;
+ }
+
+ if (jdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id out of range\n");
+ return 0;
+ }
+
+ soft_pool = &g_soft_pool.pool[jdata->td_id];
+ priv_key = &g_soft_pool.key[jdata->td_id];
+
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ if (!optype) {
+ md_ctx = EVP_MD_CTX_new();
+ if (!md_ctx) {
+ SSL_TST_PRT("Error: EVP_MD_CTX_new failed\n");
+ return 0;
+ }
+
+ OSSL_PARAM params[3];
+ params[0] = OSSL_PARAM_construct_utf8_string("digest", (char *)EVP_MD_get0_name(evp_md), 0);
+ params[1] = OSSL_PARAM_construct_octet_string("key", priv_key, jdata->keysize);
+ params[2] = OSSL_PARAM_construct_end();
+
+ while (1) {
+ i = jid % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+
+ EVP_DigestInit_ex2(md_ctx, evp_md, params);
+ EVP_DigestUpdate(md_ctx, src, g_pktlen);
+ EVP_DigestFinal_ex(md_ctx, mac, &ssl_size);
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+ EVP_MD_CTX_free(md_ctx);
+
+ } else {
+ f_mac = EVP_MAC_fetch(NULL, "HMAC", NULL);
+ m_ctx = EVP_MAC_CTX_new(f_mac);
+ if (!m_ctx) {
+ SSL_TST_PRT("Error: EVP_MAC_CTX_new failed\n");
+ EVP_MAC_free(f_mac);
+ return 0;
+ }
+
+ OSSL_PARAM params[3];
+ params[0] = OSSL_PARAM_construct_utf8_string("digest", "SHA256", 0);
+ params[1] = OSSL_PARAM_construct_octet_string("key", priv_key, jdata->keysize);
+ params[2] = OSSL_PARAM_construct_end();
+
+ while (1) {
+ i = jid % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+
+ EVP_MAC_init(m_ctx, priv_key, jdata->keysize, params);
+ EVP_MAC_update(m_ctx, src, g_pktlen);
+ EVP_MAC_final(m_ctx, mac, &required_len, EVP_MAX_MD_SIZE);
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_MAC_CTX_free(m_ctx);
+ EVP_MAC_free(f_mac);
+ }
+
+ add_recv_data(count, g_pktlen);
+
+ return 0;
+}
+
+static void *sec_soft_async_run(void *arg)
+{
+ typedef int (*sec_soft_run)(void *arg);
+ sec_soft_run sec_soft_jobfunc = NULL;
+ soft_thread *pdata = (soft_thread *)arg;
+ jobs_args loop_jobs[MAX_JOBS_NUM];
+ OSSL_ASYNC_FD waitfd = 0;
+ jobs_data jobdata;
+ fd_set waitfdset;
+ size_t numfds = 0;
+ int i, j, k, ret;
+ int jobret = 0;
+ u32 valid_jobs = 0;
+ u32 jobs_num;
+
+ jobdata.evp_cipher = pdata->evp_cipher;
+ jobdata.evp_md = pdata->evp_md;
+ jobdata.keysize = pdata->keysize;
+ jobdata.mode = pdata->mode;
+ jobdata.optype = pdata->optype;
+ jobdata.subtype = pdata->subtype;
+ jobdata.td_id = pdata->td_id;
+ jobdata.engine = pdata->engine;
+
+ jobs_num = g_jobsnum;
+ if (jobs_num > MAX_JOBS_NUM) {
+ SSL_TST_PRT("Error: check async jobs num failed.\n");
+ return NULL;
+ }
+ memset(loop_jobs, 0x0, sizeof(jobs_args) * MAX_JOBS_NUM);
+
+ switch (pdata->subtype) {
+ case CIPHER_TYPE:
+ sec_soft_jobfunc = sec_soft_cipher_jobfunc;
+ break;
+ case AEAD_TYPE:
+ sec_soft_jobfunc = sec_soft_aead_jobfunc;
+ break;
+ case DIGEST_TYPE:
+ sec_soft_jobfunc = sec_soft_digest_jobfunc;
+ break;
+ }
+
+ /* one thread for one job */
+ for (i = 0; i < jobs_num; i++) {
+ loop_jobs[i].wait_ctx = ASYNC_WAIT_CTX_new();
+ if (!loop_jobs[i].wait_ctx) {
+ SSL_TST_PRT("Error: create ASYNC_WAIT_CTX failed\n");
+ goto async_error;
+ }
+
+ jobdata.jobid = i;
+ ret = ASYNC_start_job(&loop_jobs[i].in_job, loop_jobs[i].wait_ctx, &jobret,
+ sec_soft_jobfunc, (void *)&jobdata, sizeof(jobs_data));
+ switch(ret) {
+ case ASYNC_ERR:
+ SSL_TST_PRT("Error: start soft async job err.\n");
+ break;
+ case ASYNC_NO_JOBS:
+ SSL_TST_PRT("Error: can't get soft async job from job pool.\n");
+ break;
+ case ASYNC_PAUSE:
+ loop_jobs[i].job_valid = true;
+ valid_jobs++;
+ break;
+ case ASYNC_FINISH:
+ break;
+ default:
+ SSL_TST_PRT("Error: do soft async job err.\n");
+ }
+ }
+
+ j = valid_jobs;
+ while (j > 0) {
+ for (i = 0; i < jobs_num; i++) {
+ FD_ZERO(&waitfdset);
+ if (!loop_jobs[i].job_valid)
+ continue;
+
+ /* Wait for the job to be woken */
+ if (!ASYNC_WAIT_CTX_get_all_fds(loop_jobs[i].wait_ctx, NULL, &numfds) ||
+ numfds > 1) {
+ SSL_TST_PRT("Error: unexpected number of fds.\n");
+ continue;
+ }
+ ASYNC_WAIT_CTX_get_all_fds(loop_jobs[i].wait_ctx, &waitfd, &numfds);
+
+ FD_SET(waitfd, &waitfdset);
+ ret = select(waitfd + 1, &waitfdset, NULL, NULL, NULL);
+ if (ret == -1) {
+ SSL_TST_PRT("Error: select soft async job error.\n");
+ goto async_finish;
+ } else if (ret == 0 || (ret == -1 && errno == EINTR)) {
+ SSL_TST_PRT("Infor: select soft async job result continue.\n");
+ continue;
+ }
+
+ jobdata.jobid = i;
+ ret = ASYNC_start_job(&loop_jobs[i].in_job, loop_jobs[i].wait_ctx, &jobret,
+ sec_soft_jobfunc, (void *)&jobdata, sizeof(jobs_data));
+ switch(ret) {
+ case ASYNC_ERR:
+ loop_jobs[i].job_valid = false;
+ j--;
+ SSL_TST_PRT("Error: restart soft async job err.\n");
+ break;
+ case ASYNC_NO_JOBS:
+ SSL_TST_PRT("Error: can't get soft async job from job pool.\n");
+ break;
+ case ASYNC_PAUSE:
+ break;
+ case ASYNC_FINISH:
+ loop_jobs[i].job_valid = false;
+ j--;
+ break;
+ default:
+ SSL_TST_PRT("Error: do soft async job err.\n");
+ }
+ }
+ }
+
+async_finish:
+ i = jobs_num;
+async_error:
+ for (k = 0; k < i; k++)
+ ASYNC_WAIT_CTX_free(loop_jobs[k].wait_ctx);
+
+ add_send_complete();
+
+ return NULL;
+}
+
+static void *sec_soft_cipher_sync(void *arg)
+{
+ soft_thread *pdata = (soft_thread *)arg;
+ const EVP_CIPHER *evp_cipher = pdata->evp_cipher;
+ u32 optype = pdata->optype;
+ struct bd_pool *soft_pool;
+ u8 *priv_iv, *priv_key;
+ EVP_CIPHER_CTX *ctx = NULL;
+ u32 count = 0;
+ u8 *src, *dst;
+ int ret;
+ int outl = 0;
+
+ if (!evp_cipher) {
+ SSL_TST_PRT("Error: openssl not support!\n");
+ return NULL;
+ }
+
+ if (pdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id %d out of range (max %d)\n", pdata->td_id, g_thread_num);
+ return NULL;
+ }
+
+ soft_pool = &g_soft_pool.pool[pdata->td_id];
+ priv_iv = &g_soft_pool.iv[pdata->td_id];
+ priv_key = &g_soft_pool.key[pdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ ctx = EVP_CIPHER_CTX_new();
+ if (!ctx) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_new failed\n");
+ return NULL;
+ }
+
+ size_t iv_len = EVP_CIPHER_get_iv_length(evp_cipher);
+ size_t key_len = MAX_IVK_LENTH;
+
+ while (1) {
+ u32 local_count = count % MAX_POOL_LENTH;
+ src = soft_pool->bds[local_count].src;
+ dst = soft_pool->bds[local_count].dst;
+
+ if (optype) {
+ EVP_DecryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, NULL);
+ EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_CIPHER_CTX_set_padding(ctx, EVP_PADDING_ZERO);
+ EVP_DecryptFinal_ex(ctx, dst, &outl);
+ } else {
+ EVP_EncryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, NULL);
+ EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_CIPHER_CTX_set_padding(ctx, EVP_PADDING_ZERO);
+ EVP_EncryptFinal_ex(ctx, dst, &outl);
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_CIPHER_CTX_free(ctx);
+ cal_avg_latency(count);
+ add_recv_data(count, g_pktlen);
+
+ return NULL;
+}
+
+static void *sec_soft_aead_sync(void *arg)
+{
+ soft_thread *pdata = (soft_thread *)arg;
+ const EVP_CIPHER *evp_cipher = pdata->evp_cipher;
+ u32 optype = pdata->optype;
+ u32 mode = pdata->mode;
+ struct bd_pool *soft_pool;
+ u8 *priv_iv, *priv_key;
+ EVP_CIPHER_CTX *ctx = NULL;
+ u8 aad[13] = {0xcc};
+ u8 tag[12] = {0};
+ u8 out_tag[EVP_MAX_IV_LENGTH] = {0};
+ u32 count = 0;
+ u8 *src, *dst;
+ int ret, i;
+ int outl = 0;
+ size_t taglen = 0;
+ int ccm_l = 0;
+
+ if (!evp_cipher) {
+ SSL_TST_PRT("Error: openssl not support!\n");
+ return NULL;
+ }
+
+ if (pdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id out of range\n");
+ return NULL;
+ }
+
+ soft_pool = &g_soft_pool.pool[pdata->td_id];
+ priv_iv = &g_soft_pool.iv[pdata->td_id];
+ priv_key = &g_soft_pool.key[pdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ ctx = EVP_CIPHER_CTX_new();
+ if (!ctx) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_new failed\n");
+ return NULL;
+ }
+
+ while (1) {
+ i = count % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+ dst = soft_pool->bds[i].dst;
+
+ OSSL_PARAM params[10];
+ int param_idx = 0;
+
+ params[param_idx++] = OSSL_PARAM_construct_utf8_string("cipher", (char *)EVP_CIPHER_get0_name(evp_cipher), 0);
+ params[param_idx++] = OSSL_PARAM_construct_octet_string("key", priv_key, MAX_IVK_LENTH);
+ params[param_idx++] = OSSL_PARAM_construct_octet_string("iv", priv_iv, EVP_CIPHER_get_iv_length(evp_cipher));
+
+ if (mode == WD_CIPHER_CCM) {
+ taglen = 12;
+ params[param_idx++] = OSSL_PARAM_construct_size_t("taglen", &taglen);
+ ccm_l = (EVP_CIPHER_get_iv_length(evp_cipher) - 1) - 1;
+ params[param_idx++] = OSSL_PARAM_construct_int("ccm_l", &ccm_l);
+ } else {
+ taglen = 16;
+ params[param_idx++] = OSSL_PARAM_construct_size_t("taglen", &taglen);
+ ccm_l = (EVP_CIPHER_get_iv_length(evp_cipher) - 1) - 1;
+ params[param_idx++] = OSSL_PARAM_construct_int("ccm_l", &ccm_l);
+ }
+ params[param_idx++] = OSSL_PARAM_construct_end();
+
+ if (optype) {
+ ret = EVP_DecryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, params);
+ } else {
+ ret = EVP_EncryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, params);
+ }
+
+ if (optype) {
+ OSSL_PARAM tag_params[] = {
+ OSSL_PARAM_construct_octet_string("tag", tag, sizeof(tag)),
+ OSSL_PARAM_construct_end()
+ };
+ ret = EVP_CIPHER_CTX_set_params(ctx, tag_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_set_params(tag) failed on decrypt\n");
+ break;
+ }
+
+ OSSL_PARAM aad_params[] = {
+ OSSL_PARAM_construct_octet_string("aad", aad, sizeof(aad)),
+ OSSL_PARAM_construct_end()
+ };
+ ret = EVP_CIPHER_CTX_set_params(ctx, aad_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_set_params(aad) failed on decrypt\n");
+ break;
+ }
+
+ EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_DecryptFinal_ex(ctx, dst + outl, &outl);
+
+ } else {
+ OSSL_PARAM aad_params[] = {
+ OSSL_PARAM_construct_octet_string("aad", aad, sizeof(aad)),
+ OSSL_PARAM_construct_end()
+ };
+ ret = EVP_CIPHER_CTX_set_params(ctx, aad_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_set_params(aad) failed on encrypt\n");
+ break;
+ }
+
+ EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_EncryptFinal_ex(ctx, dst + outl, &outl);
+ }
+
+ if (!optype && mode != WD_CIPHER_CCM) {
+ OSSL_PARAM get_tag_params[] = {
+ OSSL_PARAM_construct_octet_string("tag", out_tag, sizeof(out_tag)),
+ OSSL_PARAM_construct_end()
+ };
+ (void)EVP_CIPHER_CTX_get_params(ctx, get_tag_params);
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_CIPHER_CTX_free(ctx);
+
+ cal_avg_latency(count);
+ add_recv_data(count, g_pktlen);
+
+ return NULL;
+}
+
+static void *sec_soft_digest_sync(void *arg)
+{
+ soft_thread *pdata = (soft_thread *)arg;
+ const EVP_CIPHER *evp_cipher = pdata->evp_cipher;
+ const EVP_MD *evp_md = pdata->evp_md;
+ u32 optype = pdata->optype;
+ u8 mac[EVP_MAX_MD_SIZE] = {0x00};
+ struct bd_pool *soft_pool;
+ EVP_MD_CTX *md_ctx = NULL;
+ EVP_MAC *f_mac = NULL;
+ EVP_MAC_CTX *m_ctx = NULL;
+ u8 *priv_key, *src;
+ size_t mac_size = 0;
+ u32 count = 0;
+ int i;
+ int ret = 0;
+ u32 ssl_size = 0;
+
+ if (!evp_cipher && !evp_md) {
+ SSL_TST_PRT("Error: openssl not support! No cipher or md provided.\n");
+ return NULL;
+ }
+
+ if (pdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id %d out of range (max %d)\n", pdata->td_id, g_thread_num);
+ return NULL;
+ }
+
+ soft_pool = &g_soft_pool.pool[pdata->td_id];
+ priv_key = &g_soft_pool.key[pdata->td_id];
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ if (!optype) {
+ md_ctx = EVP_MD_CTX_new();
+ if (!md_ctx) {
+ SSL_TST_PRT("Error: EVP_MD_CTX_new failed\n");
+ return NULL;
+ }
+
+ OSSL_PARAM digest_params[] = {
+ OSSL_PARAM_construct_utf8_string("digest", (char *)EVP_MD_get0_name(evp_md), 0),
+ OSSL_PARAM_construct_end()
+ };
+
+ while (1) {
+ i = count % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+
+ ret = EVP_DigestInit_ex2(md_ctx, evp_md, digest_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_DigestInit_ex2 failed\n");
+ break;
+ }
+
+ ret = EVP_DigestUpdate(md_ctx, src, g_pktlen);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_DigestUpdate failed\n");
+ break;
+ }
+
+ ret = EVP_DigestFinal_ex(md_ctx, mac, &ssl_size);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_DigestFinal_ex failed\n");
+ break;
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_MD_CTX_free(md_ctx);
+ } else {
+ f_mac = EVP_MAC_fetch(NULL, "HMAC", NULL);
+ if (!f_mac) {
+ SSL_TST_PRT("Error: EVP_MAC_fetch(HMAC) failed\n");
+ return NULL;
+ }
+
+ m_ctx = EVP_MAC_CTX_new(f_mac);
+ if (!m_ctx) {
+ SSL_TST_PRT("Error: EVP_MAC_CTX_new failed\n");
+ EVP_MAC_free(f_mac);
+ return NULL;
+ }
+
+ OSSL_PARAM mac_params[] = {
+ OSSL_PARAM_construct_utf8_string("digest", "SHA256", 0),
+ OSSL_PARAM_construct_octet_string("key", priv_key, pdata->keysize),
+ OSSL_PARAM_construct_end()
+ };
+
+ while (1) {
+ i = count % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+
+ ret = EVP_MAC_init(m_ctx, priv_key, pdata->keysize, mac_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_MAC_init failed\n");
+ break;
+ }
+
+ ret = EVP_MAC_update(m_ctx, src, g_pktlen);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_MAC_update failed\n");
+ break;
+ }
+
+ ret = EVP_MAC_final(m_ctx, mac, &mac_size, sizeof(mac));
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_MAC_final failed\n");
+ break;
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_MAC_CTX_free(m_ctx);
+ EVP_MAC_free(f_mac);
+ }
+
+ if(optype && !f_mac) {
+ return NULL;
+ }
+ if(!optype && !md_ctx) {
+ return NULL;
+ }
+
+ cal_avg_latency(count);
+ add_recv_data(count, g_pktlen);
+
+ return NULL;
+}
+
+static void uadk_engine_set_env(soft_thread *options)
+{
+ char env_string[ENV_STRING_LEN] = {0};
+ char *var_name = NULL;
+
+ switch(options->subtype) {
+ case CIPHER_TYPE:
+ var_name = "WD_CIPHER_CTX_NUM";
+ break;
+ case AEAD_TYPE:
+ var_name = "WD_CIPHER_CTX_NUM";
+ break;
+ case DIGEST_TYPE:
+ var_name = "WD_DIGEST_CTX_NUM";
+ break;
+ default:
+ return;
+ }
+
+ unsetenv(var_name);
+
+ /* uadk will request ctxs from env param */
+ if (options->sync_mode) // async mode
+ (void)snprintf(env_string, ENV_STRING_LEN, "%s%d%s%d%s",
+ "async:", g_jobsnum,"@0,async:", g_jobsnum, "@2");
+ else
+ (void)snprintf(env_string, ENV_STRING_LEN, "%s%d%s%d%s",
+ "sync:", g_jobsnum,"@0,sync:", g_jobsnum, "@2");
+ (void)setenv(var_name, env_string, 1);
+}
+
+static int uadk_provider_register(soft_thread *options, char *engine_name)
+{
+ if (!options->engine_flag)
+ return 0;
+
+ /* Set env param for uadk engine */
+ uadk_engine_set_env(options);
+ OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
+
+ options->engine = OSSL_PROVIDER_load(NULL, engine_name);
+ if (!options->engine) {
+ SSL_TST_PRT("setup uadk engine failed!\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static void uadk_provider_unregister(soft_thread *options)
+{
+ if (!options->engine_flag)
+ return;
+
+ if (options->engine) {
+ OSSL_PROVIDER_unload(options->engine);
+ options->engine = NULL;
+ }
+}
+
+int sec_soft_sync_threads(struct acc_option *options)
+{
+ typedef void *(*sec_sync_run)(void *arg);
+ sec_sync_run soft_sec_sync_run = NULL;
+ soft_thread threads_args[THREADS_NUM];
+ soft_thread threads_option;
+ pthread_t tdid[THREADS_NUM];
+ int i, ret;
+
+ /* Alg param parse and set to thread data */
+ ret = sec_soft_param_parse(&threads_option, options);
+ if (ret)
+ return ret;
+
+ threads_option.engine_flag = options->engine_flag;
+ threads_option.sync_mode = options->syncmode;
+ ret = uadk_provider_register(&threads_option, options->engine);
+ if (ret)
+ return ret;
+
+
+ switch (options->subtype) {
+ case CIPHER_TYPE:
+ SSL_TST_PRT(" --- CIPHER_TYPE\n");
+ soft_sec_sync_run = sec_soft_cipher_sync;
+ break;
+ case AEAD_TYPE:
+ SSL_TST_PRT(" --- AEAD_TYPE\n");
+ soft_sec_sync_run = sec_soft_aead_sync;
+ break;
+ case DIGEST_TYPE:
+ SSL_TST_PRT(" --- DIGEST_TYPE\n");
+ soft_sec_sync_run = sec_soft_digest_sync;
+ break;
+ }
+
+
+
+ for (i = 0; i < g_thread_num; i++) {
+ threads_args[i].evp_cipher = threads_option.evp_cipher;
+ threads_args[i].evp_md = threads_option.evp_md;
+ threads_args[i].subtype = threads_option.subtype;
+ threads_args[i].mode = threads_option.mode;
+ threads_args[i].keysize = threads_option.keysize;
+ threads_args[i].optype = threads_option.optype;
+ threads_args[i].td_id = i;
+ threads_args[i].engine_flag = options->engine_flag;
+ threads_args[i].engine = threads_option.engine;
+ ret = pthread_create(&tdid[i], NULL, soft_sec_sync_run, &threads_args[i]);
+ if (ret) {
+ SSL_TST_PRT("Create sync thread fail!\n");
+ goto sync_error;
+ }
+ }
+
+
+ /* Join thread */
+ for (i = 0; i < g_thread_num; i++) {
+ ret = pthread_join(tdid[i], NULL);
+ if (ret) {
+ SSL_TST_PRT("Join sync thread fail!\n");
+ goto sync_error;
+ }
+ }
+
+sync_error:
+ uadk_provider_unregister(&threads_option);
+ return ret;
+}
+
+int sec_soft_async_threads(struct acc_option *options)
+{
+ soft_thread threads_args[THREADS_NUM];
+ soft_thread threads_option;
+ pthread_t tdid[THREADS_NUM];
+ int i, ret;
+
+ /* Alg param parse and set to thread data */
+ ret = sec_soft_param_parse(&threads_option, options);
+ if (ret)
+ return ret;
+
+ threads_option.engine_flag = options->engine_flag;
+ threads_option.sync_mode = options->syncmode;
+ ret = uadk_provider_register(&threads_option, options->engine);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < g_thread_num; i++) {
+ threads_args[i].evp_cipher = threads_option.evp_cipher;
+ threads_args[i].evp_md = threads_option.evp_md;
+ threads_args[i].subtype = threads_option.subtype;
+ threads_args[i].mode = threads_option.mode;
+ threads_args[i].keysize = threads_option.keysize;
+ threads_args[i].optype = threads_option.optype;
+ threads_args[i].td_id = i;
+ threads_args[i].engine_flag = options->engine_flag;
+ threads_args[i].engine = threads_option.engine;
+ ret = pthread_create(&tdid[i], NULL, sec_soft_async_run, &threads_args[i]);
+ if (ret) {
+ SSL_TST_PRT("Create async thread fail!\n");
+ goto async_error;
+ }
+ }
+
+ /* Join thread */
+ for (i = 0; i < g_thread_num; i++) {
+ ret = pthread_join(tdid[i], NULL);
+ if (ret) {
+ SSL_TST_PRT("Join async thread fail!\n");
+ goto async_error;
+ }
+ }
+
+async_error:
+ uadk_provider_unregister(&threads_option);
+ return ret;
+}
+
+int sec_soft3_benchmark(struct acc_option *options)
+{
+ u32 ptime;
+ int ret;
+
+ signal(SIGSEGV, segmentfault_handler);
+ g_thread_num = options->threads;
+ g_pktlen = options->pktlen;
+ g_jobsnum = options->ctxnums;
+ if (options->optype > WD_CIPHER_DECRYPTION) {
+ SSL_TST_PRT("SEC optype error: %u\n", options->optype);
+ return -EINVAL;
+ }
+
+ ret = init_soft_bd_pool();
+ if (ret)
+ return ret;
+
+ get_pid_cpu_time(&ptime);
+ time_start(options->times);
+ if (options->syncmode)
+ ret = sec_soft_async_threads(options);
+ else
+ ret = sec_soft_sync_threads(options);
+ cal_perfermance_data(options, ptime);
+ if (ret)
+ return ret;
+
+ free_soft_bd_pool();
+
+ return 0;
+}
diff --git a/uadk_tool/benchmark/sec_soft3_benchmark.h b/uadk_tool/benchmark/sec_soft3_benchmark.h
new file mode 100644
index 0000000..f10bcb2
--- /dev/null
+++ b/uadk_tool/benchmark/sec_soft3_benchmark.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+#ifndef SEC_SOFT3_BENCHMARK_H
+#define SEC_SOFT3_BENCHMARK_H
+
+#include "uadk_benchmark.h"
+
+extern int sec_soft3_benchmark(struct acc_option *options);
+#endif /* SEC_SOFT_BENCHMARK_H */
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c
index d8f066f..756c3ad 100644
--- a/uadk_tool/benchmark/uadk_benchmark.c
+++ b/uadk_tool/benchmark/uadk_benchmark.c
@@ -8,7 +8,11 @@
#include "uadk_benchmark.h"
#include "sec_uadk_benchmark.h"
#include "sec_wd_benchmark.h"
-#include "sec_soft_benchmark.h"
+// # if OPENSSL_VERSION_NUMBER < 0x30000000L
+// #include "sec_soft_benchmark.h"
+// # else
+#include "sec_soft3_benchmark.h"
+// # endif
#include "hpre_uadk_benchmark.h"
#include "hpre_wd_benchmark.h"
@@ -568,11 +572,17 @@ static int benchmark_run(struct acc_option *option)
ret = sec_wd_benchmark(option);
}
usleep(20000);
-#ifdef HAVE_CRYPTO
+// #ifdef HAVE_CRYPTO
+// # if OPENSSL_VERSION_NUMBER < 0x30000000L
+// if (option->modetype == SOFT_MODE) {
+// ret = sec_soft_benchmark(option);
+// }
+// # else
if (option->modetype == SOFT_MODE) {
- ret = sec_soft_benchmark(option);
+ ret = sec_soft3_benchmark(option);
}
-#endif
+// # endif
+// #endif
break;
case HPRE_TYPE:
if (option->modetype == SVA_MODE) {
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c
index 014aa98..39bc526 100644
--- a/uadk_tool/test/comp_lib.c
+++ b/uadk_tool/test/comp_lib.c
@@ -10,6 +10,12 @@
#include <math.h>
#include <sys/mman.h>
#include <zlib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+// #include "openssl/md5.h"
+
+
#include "comp_lib.h"
@@ -255,9 +261,18 @@ int calculate_md5(comp_md5_t *md5, const void *buf, size_t len)
{
if (!md5 || !buf || !len)
return -EINVAL;
+
+# if OPENSSL_VERSION_NUMBER < 0x30000000L
MD5_Init(&md5->md5_ctx);
MD5_Update(&md5->md5_ctx, buf, len);
MD5_Final(md5->md, &md5->md5_ctx);
+# else
+ md5->ctx = EVP_MD_CTX_new();
+ EVP_DigestInit_ex2(md5->ctx, EVP_md5(), NULL);
+ EVP_DigestUpdate(md5->ctx, buf, len);
+ EVP_DigestFinal_ex(md5->ctx, md5->md, NULL);
+ EVP_MD_CTX_free(md5->ctx);
+# endif
return 0;
}
@@ -425,7 +440,7 @@ static int chunk_inflate(void *in, size_t in_sz, void *out, size_t *out_sz,
do {
ret = inflate(&strm, Z_NO_FLUSH);
if ((ret < 0) || (ret == Z_NEED_DICT)) {
- COMP_TST_PRT("zlib error %d - %s\n", ret, strm.msg);
+ COMP_TST_PRT("zlib error %d - %s %s\n", ret, strm.msg, __func__);
goto out;
}
if (!strm.avail_out) {
@@ -1319,7 +1334,7 @@ int hizip_check_output(void *buf, size_t size, size_t *checked,
do {
ret = inflate(&stream, Z_NO_FLUSH);
if (ret < 0 || ret == Z_NEED_DICT) {
- COMP_TST_PRT("zlib error %d - %s\n", ret, stream.msg);
+ COMP_TST_PRT("zlib error %d - %s %s\n", ret, stream.msg, __func__);
ret = -ENOSR;
break;
}
@@ -1387,7 +1402,7 @@ int zlib_deflate(void *output, unsigned int out_size,
do {
ret = deflate(&stream, Z_FINISH);
if (ret == Z_STREAM_ERROR || ret == Z_BUF_ERROR) {
- COMP_TST_PRT("zlib error %d - %s\n", ret, stream.msg);
+ COMP_TST_PRT("zlib error %d - %s %s\n", ret, stream.msg, __func__);
ret = -ENOSR;
break;
} else if (!stream.avail_in) {
diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h
index c37a226..9eb7a31 100644
--- a/uadk_tool/test/comp_lib.h
+++ b/uadk_tool/test/comp_lib.h
@@ -22,6 +22,12 @@
#include "include/wd_comp.h"
#include "include/wd_sched.h"
+# if OPENSSL_VERSION_NUMBER >= 0x30000000L
+#include "openssl/opensslv.h"
+#include "openssl/evp.h"
+#include "openssl/ossl_typ.h"
+# endif
+
#define SYS_ERR_COND(cond, msg, ...) \
do { \
if (cond) { \
@@ -120,7 +126,11 @@ struct test_options {
};
typedef struct _comp_md5_t {
+# if OPENSSL_VERSION_NUMBER < 0x30000000L
MD5_CTX md5_ctx;
+# else
+ EVP_MD_CTX *ctx;
+# endif
unsigned char md[MD5_DIGEST_LENGTH];
} comp_md5_t;
diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c
index 24f52d2..81b213a 100644
--- a/uadk_tool/test/comp_main.c
+++ b/uadk_tool/test/comp_main.c
@@ -86,7 +86,7 @@ static void *sw_dfl_hw_ifl(void *arg)
void *tbuf;
size_t tbuf_sz;
chunk_list_t *tlist;
- comp_md5_t final_md5 = {{0}};
+ comp_md5_t final_md5 = {0};
int i, ret;
__u32 tout_sz;
@@ -230,7 +230,7 @@ static void *hw_dfl_sw_ifl(void *arg)
void *tbuf;
size_t tbuf_sz;
chunk_list_t *tlist;
- comp_md5_t final_md5 = {{0}};
+ comp_md5_t final_md5 = {0};
int i, ret;
__u32 tmp_sz;
@@ -374,7 +374,7 @@ static void *hw_dfl_hw_ifl(void *arg)
void *tbuf;
size_t tbuf_sz;
chunk_list_t *tlist;
- comp_md5_t final_md5 = {{0}};
+ comp_md5_t final_md5 = {0};
int i, ret;
__u32 tmp_sz, tout_sz;
@@ -886,6 +886,7 @@ static int test_hw(struct test_options *opts, char *model)
goto out_src;
opts->total_len = statbuf.st_size;
info.in_size = opts->total_len;
+ COMP_TST_PRT("in_size : %d\n", info.in_size);
if (ifl_flag)
info.out_size = opts->total_len * INFLATION_RATIO;
else
@@ -898,6 +899,7 @@ static int test_hw(struct test_options *opts, char *model)
if (opts->is_file) {
ret = load_file_data(&info);
+ COMP_TST_PRT("file_size : %d\n", ret);
if (ret < 0)
goto out_buf;
} else {
diff --git a/uadk_tool/test/uadk_test.c b/uadk_tool/test/uadk_test.c
index 536861a..aa885d1 100644
--- a/uadk_tool/test/uadk_test.c
+++ b/uadk_tool/test/uadk_test.c
@@ -63,10 +63,10 @@ void acc_test_run(int argc, char *argv[])
(void)test_hpre_entry(argc, argv);
} else if (!strcmp(input_module, "sec")) {
(void)test_sec_entry(argc, argv);
-#ifdef HAVE_CRYPTO
+// #ifdef HAVE_CRYPTO
} else if (!strcmp(input_module, "zip")) {
(void)test_comp_entry(argc, argv);
-#endif
+// #endif
} else {
print_test_help();
printf("failed to parse module parameter!\n");
--
2.33.0
1
0
08 Apr '26
From: Longfang Liu <liulongfang(a)huawei.com>
This reverts commit 3fc344aa4f7c460269cd0d870fe388f01dfa22a2.
---
drv/hash_mb/hash_mb.c | 45 +++++------
drv/hisi_comp.c | 32 +++-----
drv/hisi_dae.c | 13 +---
drv/hisi_dae.h | 4 +-
drv/hisi_dae_common.c | 28 +++----
drv/hisi_dae_join_gather.c | 21 ++----
drv/hisi_hpre.c | 76 +++++++------------
drv/hisi_sec.c | 123 +++++++++++++++----------------
drv/hisi_udma.c | 30 +++-----
drv/isa_ce_sm3.c | 38 ++++------
drv/isa_ce_sm4.c | 41 ++++-------
include/drv/wd_agg_drv.h | 3 +-
include/drv/wd_ecc_drv.h | 5 +-
include/drv/wd_join_gather_drv.h | 12 ++-
include/wd_alg.h | 19 +++--
include/wd_util.h | 14 ++--
wd_aead.c | 37 ++++------
wd_agg.c | 15 ++--
wd_alg.c | 20 -----
wd_cipher.c | 20 ++---
wd_comp.c | 20 ++---
wd_dh.c | 22 +++---
wd_digest.c | 37 ++++------
wd_ecc.c | 26 ++++---
wd_join_gather.c | 28 +++----
wd_rsa.c | 22 +++---
wd_udma.c | 15 ++--
wd_util.c | 38 ++++++++--
28 files changed, 351 insertions(+), 453 deletions(-)
diff --git a/drv/hash_mb/hash_mb.c b/drv/hash_mb/hash_mb.c
index bd412b2..5c0daf2 100644
--- a/drv/hash_mb/hash_mb.c
+++ b/drv/hash_mb/hash_mb.c
@@ -186,46 +186,34 @@ free_mb_queue:
return ret;
}
-static int hash_mb_init(struct wd_alg_driver *drv, void *conf)
+static int hash_mb_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
- struct hash_mb_ctx *priv;
- int ret;
+ struct hash_mb_ctx *mb_ctx = priv;
/* Fallback init is NULL */
- if (!drv || !conf)
+ if (!conf || !priv)
return 0;
- priv = malloc(sizeof(struct hash_mb_ctx));
- if (!priv)
- return -WD_ENOMEM;
-
/* multibuff does not use epoll. */
config->epoll_en = 0;
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
+ memcpy(&mb_ctx->config, config, sizeof(struct wd_ctx_config_internal));
- ret = hash_mb_queue_init(config);
- if (ret) {
- free(priv);
- return ret;
- }
-
- drv->priv = priv;
-
- return WD_SUCCESS;
+ return hash_mb_queue_init(config);
}
-static void hash_mb_exit(struct wd_alg_driver *drv)
+static void hash_mb_exit(void *priv)
{
- struct hash_mb_ctx *priv;
+ struct hash_mb_ctx *mb_ctx = priv;
+ struct wd_ctx_config_internal *config;
- if (!drv || !drv->priv)
+ if (!priv) {
+ WD_ERR("invalid: input parameter is NULL!\n");
return;
+ }
- priv = (struct hash_mb_ctx *)drv->priv;
- hash_mb_queue_uninit(&priv->config, priv->config.ctx_num);
- free(priv);
- drv->priv = NULL;
+ config = &mb_ctx->config;
+ hash_mb_queue_uninit(config, config->ctx_num);
}
static void hash_mb_pad_data(struct hash_pad *hash_pad, __u8 *in, __u32 partial,
@@ -267,7 +255,7 @@ static inline void hash_xor(__u8 *key_out, __u8 *key_in, __u32 key_len, __u8 xor
if (i < key_len)
key_out[i] = key_in[i] ^ xor_value;
else
- key_out[i] = xor_value;
+ key_out[i] = 0x0 ^ xor_value;
}
}
@@ -555,7 +543,7 @@ static int hash_mb_check_param(struct hash_mb_queue *mb_queue, struct wd_digest_
return WD_SUCCESS;
}
-static int hash_mb_send(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg)
+static int hash_mb_send(handle_t ctx, void *drv_msg)
{
struct wd_soft_ctx *s_ctx = (struct wd_soft_ctx *)ctx;
struct hash_mb_queue *mb_queue = s_ctx->priv;
@@ -776,7 +764,7 @@ static int hash_mb_do_jobs(struct hash_mb_queue *mb_queue)
return WD_SUCCESS;
}
-static int hash_mb_recv(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg)
+static int hash_mb_recv(handle_t ctx, void *drv_msg)
{
struct wd_soft_ctx *s_ctx = (struct wd_soft_ctx *)ctx;
struct hash_mb_queue *mb_queue = s_ctx->priv;
@@ -810,6 +798,7 @@ static int hash_mb_get_usage(void *param)
.alg_name = (hash_alg_name),\
.calc_type = UADK_ALG_SVE_INSTR,\
.priority = 100,\
+ .priv_size = sizeof(struct hash_mb_ctx),\
.queue_num = 1,\
.op_type_num = 1,\
.fallback = 0,\
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index a6b2947..be16b83 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -1414,11 +1414,11 @@ static void hisi_zip_sqe_ops_adapt(handle_t h_qp)
}
}
-static int hisi_zip_init(struct wd_alg_driver *drv, void *conf)
+static int hisi_zip_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_zip_ctx *zip_ctx = (struct hisi_zip_ctx *)priv;
struct hisi_qm_priv qm_priv;
- struct hisi_zip_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -1428,11 +1428,7 @@ static int hisi_zip_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_zip_ctx));
- if (!priv)
- return -WD_EINVAL;
-
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
+ memcpy(&zip_ctx->config, config, sizeof(struct wd_ctx_config_internal));
/* allocate qp for each context */
for (i = 0; i < config->ctx_num; i++) {
h_ctx = config->ctxs[i].ctx;
@@ -1450,7 +1446,6 @@ static int hisi_zip_init(struct wd_alg_driver *drv, void *conf)
}
hisi_zip_sqe_ops_adapt(h_qp);
- drv->priv = priv;
return 0;
out:
@@ -1458,28 +1453,20 @@ out:
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[j].ctx);
hisi_qm_free_qp(h_qp);
}
- free(priv);
return -WD_EINVAL;
}
-static void hisi_zip_exit(struct wd_alg_driver *drv)
+static void hisi_zip_exit(void *priv)
{
- struct wd_ctx_config_internal *config;
- struct hisi_zip_ctx *priv;
+ struct hisi_zip_ctx *zip_ctx = (struct hisi_zip_ctx *)priv;
+ struct wd_ctx_config_internal *config = &zip_ctx->config;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
- return;
-
- priv = (struct hisi_zip_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);
hisi_qm_free_qp(h_qp);
}
- free(priv);
- drv->priv = NULL;
}
static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
@@ -1534,7 +1521,7 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
return 0;
}
-static int hisi_zip_comp_send(struct wd_alg_driver *drv, handle_t ctx, void *comp_msg)
+static int hisi_zip_comp_send(handle_t ctx, void *comp_msg)
{
struct hisi_qp *qp = wd_ctx_get_priv(ctx);
struct wd_comp_msg *msg = comp_msg;
@@ -1722,7 +1709,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
return 0;
}
-static int hisi_zip_comp_recv(struct wd_alg_driver *drv, handle_t ctx, void *comp_msg)
+static int hisi_zip_comp_recv(handle_t ctx, void *comp_msg)
{
struct hisi_qp *qp = wd_ctx_get_priv(ctx);
struct wd_comp_msg *recv_msg = comp_msg;
@@ -1775,7 +1762,7 @@ static int hisi_zip_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_zip_ctx *)drv->priv;
+ priv = (struct hisi_zip_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
@@ -1803,6 +1790,7 @@ static int hisi_zip_get_usage(void *param)
.alg_name = (zip_alg_name),\
.calc_type = UADK_ALG_HW,\
.priority = 100,\
+ .priv_size = sizeof(struct hisi_zip_ctx),\
.queue_num = ZIP_CTX_Q_NUM_DEF,\
.op_type_num = 2,\
.fallback = 0,\
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index d86b9f6..4a1ac89 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -426,7 +426,7 @@ static int check_hashagg_param(struct wd_agg_msg *msg)
return WD_SUCCESS;
}
-static int hashagg_send(struct wd_alg_driver *drv, handle_t ctx, void *hashagg_msg)
+static int hashagg_send(handle_t ctx, void *hashagg_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -563,7 +563,7 @@ static void fill_hashagg_msg_task_err(struct dae_sqe *sqe, struct wd_agg_msg *ms
}
}
-static int hashagg_recv(struct wd_alg_driver *drv, handle_t ctx, void *hashagg_msg)
+static int hashagg_recv(handle_t ctx, void *hashagg_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -1214,17 +1214,11 @@ static void hashagg_sess_priv_uninit(struct wd_alg_driver *drv, void *priv)
free(agg_ctx);
}
-static int hashagg_sess_priv_init(struct wd_alg_driver *drv,
- struct wd_agg_sess_setup *setup, void **priv)
+static int hashagg_sess_priv_init(struct wd_agg_sess_setup *setup, void **priv)
{
struct hashagg_ctx *agg_ctx;
int ret;
- if (!drv || !drv->priv) {
- WD_ERR("invalid: dae drv is NULL!\n");
- return -WD_EINVAL;
- }
-
if (!setup || !priv) {
WD_ERR("invalid: dae sess priv is NULL!\n");
return -WD_EINVAL;
@@ -1297,6 +1291,7 @@ static struct wd_alg_driver hashagg_driver = {
.alg_name = "hashagg",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_dae_ctx),
.queue_num = DAE_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
diff --git a/drv/hisi_dae.h b/drv/hisi_dae.h
index f82b13c..f8888b6 100644
--- a/drv/hisi_dae.h
+++ b/drv/hisi_dae.h
@@ -210,8 +210,8 @@ struct hisi_dae_ctx {
struct wd_ctx_config_internal config;
};
-void dae_exit(struct wd_alg_driver *drv);
-int dae_init(struct wd_alg_driver *drv, void *conf);
+void dae_exit(void *priv);
+int dae_init(void *conf, void *priv);
int dae_hash_table_init(struct hash_table_data *hw_table,
struct hash_table_data *rehash_table,
struct wd_dae_hash_table *hash_table,
diff --git a/drv/hisi_dae_common.c b/drv/hisi_dae_common.c
index c077d1d..216e424 100644
--- a/drv/hisi_dae_common.c
+++ b/drv/hisi_dae_common.c
@@ -308,11 +308,11 @@ update_table:
return ret;
}
-int dae_init(struct wd_alg_driver *drv, void *conf)
+int dae_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_dae_ctx *dae_ctx = priv;
struct hisi_qm_priv qm_priv;
- struct hisi_dae_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -323,10 +323,6 @@ int dae_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_dae_ctx));
- if (!priv)
- return -WD_ENOMEM;
-
qm_priv.op_type = DAE_SQC_ALG_TYPE;
qm_priv.sqe_size = sizeof(struct dae_sqe);
/* Allocate qp for each context */
@@ -347,8 +343,7 @@ int dae_init(struct wd_alg_driver *drv, void *conf)
if (ret)
goto free_h_qp;
}
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&dae_ctx->config, config, sizeof(struct wd_ctx_config_internal));
return WD_SUCCESS;
@@ -362,22 +357,22 @@ out:
hisi_qm_free_qp(h_qp);
}
}
- free(priv);
return ret;
}
-void dae_exit(struct wd_alg_driver *drv)
+void dae_exit(void *priv)
{
struct wd_ctx_config_internal *config;
- struct hisi_dae_ctx *priv;
+ struct hisi_dae_ctx *dae_ctx = priv;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
+ if (!priv) {
+ WD_ERR("invalid: input parameter is NULL!\n");
return;
+ }
- priv = (struct hisi_dae_ctx *)drv->priv;
- config = &priv->config;
+ config = &dae_ctx->config;
for (i = 0; i < config->ctx_num; i++) {
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
if (h_qp) {
@@ -385,9 +380,6 @@ void dae_exit(struct wd_alg_driver *drv)
hisi_qm_free_qp(h_qp);
}
}
-
- free(priv);
- drv->priv = NULL;
}
int dae_get_usage(void *param)
@@ -406,7 +398,7 @@ int dae_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_dae_ctx *)drv->priv;
+ priv = (struct hisi_dae_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
diff --git a/drv/hisi_dae_join_gather.c b/drv/hisi_dae_join_gather.c
index 8c45f57..43ed539 100644
--- a/drv/hisi_dae_join_gather.c
+++ b/drv/hisi_dae_join_gather.c
@@ -455,7 +455,7 @@ static int check_join_gather_param(struct wd_join_gather_msg *msg)
return WD_SUCCESS;
}
-static int join_gather_send(struct wd_alg_driver *drv, handle_t ctx, void *send_msg)
+static int join_gather_send(handle_t ctx, void *send_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -540,7 +540,7 @@ static void fill_join_gather_task_err(struct dae_sqe *sqe, struct wd_join_gather
}
}
-static int join_gather_recv(struct wd_alg_driver *drv, handle_t hctx, void *recv_msg)
+static int join_gather_recv(handle_t hctx, void *recv_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(hctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -892,7 +892,7 @@ static int join_gather_fill_ctx(struct join_gather_ctx *ctx,
return WD_SUCCESS;
}
-static void join_gather_sess_priv_uninit(struct wd_alg_driver *drv, void *priv)
+static void join_gather_sess_priv_uninit(void *priv)
{
struct join_gather_ctx *ctx = priv;
@@ -904,17 +904,11 @@ static void join_gather_sess_priv_uninit(struct wd_alg_driver *drv, void *priv)
free(ctx);
}
-static int join_gather_sess_priv_init(struct wd_alg_driver *drv,
- struct wd_join_gather_sess_setup *setup, void **priv)
+static int join_gather_sess_priv_init(struct wd_join_gather_sess_setup *setup, void **priv)
{
struct join_gather_ctx *ctx;
int ret;
- if (!drv || !drv->priv) {
- WD_ERR("invalid: dae drv is NULL!\n");
- return -WD_EINVAL;
- }
-
if (!setup || !priv) {
WD_ERR("invalid: dae sess priv is NULL!\n");
return -WD_EINVAL;
@@ -941,7 +935,7 @@ free_ctx:
return ret;
}
-static int join_get_table_row_size(struct wd_alg_driver *drv, void *param)
+static int join_get_table_row_size(void *param)
{
struct join_gather_ctx *ctx = param;
@@ -951,7 +945,7 @@ static int join_get_table_row_size(struct wd_alg_driver *drv, void *param)
return ctx->hash_table_row_size;
}
-static int gather_get_batch_row_size(struct wd_alg_driver *drv, void *param,
+static int gather_get_batch_row_size(void *param,
__u32 *row_size, __u32 size)
{
struct join_gather_ctx *ctx = param;
@@ -967,8 +961,7 @@ static int gather_get_batch_row_size(struct wd_alg_driver *drv, void *param,
return 0;
}
-static int join_hash_table_init(struct wd_alg_driver *drv,
- struct wd_dae_hash_table *table, void *priv)
+static int join_hash_table_init(struct wd_dae_hash_table *table, void *priv)
{
struct join_gather_ctx *ctx = priv;
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 3c41826..7da8407 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -680,11 +680,11 @@ out:
return -WD_EINVAL;
}
-static int hpre_rsa_dh_init(struct wd_alg_driver *drv, void *conf)
+static int hpre_rsa_dh_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
struct hisi_qm_priv qm_priv;
- struct hisi_hpre_ctx *priv;
int ret;
if (!config->ctx_num) {
@@ -692,27 +692,19 @@ static int hpre_rsa_dh_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_hpre_ctx));
- if (!priv)
- return -WD_EINVAL;
-
qm_priv.op_type = HPRE_HW_V2_ALG_TYPE;
- ret = hpre_init_qm_priv(config, priv, &qm_priv);
- if (ret) {
- free(priv);
+ ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv);
+ if (ret)
return ret;
- }
-
- drv->priv = priv;
return WD_SUCCESS;
}
-static int hpre_ecc_init(struct wd_alg_driver *drv, void *conf)
+static int hpre_ecc_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
struct hisi_qm_priv qm_priv;
- struct hisi_hpre_ctx *priv;
int ret;
if (!config->ctx_num) {
@@ -720,44 +712,28 @@ static int hpre_ecc_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_hpre_ctx));
- if (!priv)
- return -WD_EINVAL;
-
qm_priv.op_type = HPRE_HW_V3_ECC_ALG_TYPE;
- ret = hpre_init_qm_priv(config, priv, &qm_priv);
- if (ret) {
- free(priv);
+ ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv);
+ if (ret)
return ret;
- }
-
- drv->priv = priv;
return WD_SUCCESS;
}
-static void hpre_exit(struct wd_alg_driver *drv)
+static void hpre_exit(void *priv)
{
- struct wd_ctx_config_internal *config;
- struct hisi_hpre_ctx *priv;
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
+ struct wd_ctx_config_internal *config = &hpre_ctx->config;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
- return;
-
- priv = (struct hisi_hpre_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);
hisi_qm_free_qp(h_qp);
}
-
- free(priv);
- drv->priv = NULL;
}
-static int rsa_send(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
+static int rsa_send(handle_t ctx, void *rsa_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_rsa_msg *msg = rsa_msg;
@@ -829,7 +805,7 @@ static void hpre_result_check(struct hisi_hpre_sqe *hw_msg,
}
}
-static int rsa_recv(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
+static int rsa_recv(handle_t ctx, void *rsa_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -949,7 +925,7 @@ static int dh_out_transfer(struct wd_dh_msg *msg, struct hisi_hpre_sqe *hw_msg,
return WD_SUCCESS;
}
-static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
+static int dh_send(handle_t ctx, void *dh_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct map_info_cache cache = {0};
@@ -1020,7 +996,7 @@ dh_fail:
return ret;
}
-static int dh_recv(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
+static int dh_recv(handle_t ctx, void *dh_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -2147,7 +2123,7 @@ free_dst:
return ret;
}
-static int ecc_send(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
+static int ecc_send(handle_t ctx, void *ecc_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_ecc_msg *msg = ecc_msg;
@@ -2743,7 +2719,7 @@ fail:
return ret;
}
-static int ecc_recv(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
+static int ecc_recv(handle_t ctx, void *ecc_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_ecc_msg *msg = ecc_msg;
@@ -2786,7 +2762,7 @@ static handle_t hpre_find_dev_qp(struct wd_alg_driver *drv, const char *dev_name
handle_t qp = 0;
__u32 i;
- priv = (struct hisi_hpre_ctx *)drv->priv;
+ priv = (struct hisi_hpre_ctx *)drv->drv_data;
if (!priv)
return 0;
@@ -2874,31 +2850,30 @@ static void ecc_sess_eops_uninit(struct wd_alg_driver *drv, void *params)
free(params);
}
-static bool is_valid_hw_type(struct wd_alg_driver *drv)
+static bool is_valid_hw_type(void *drv_priv)
{
struct hisi_hpre_ctx *hpre_ctx;
struct hisi_qp *qp;
- if (unlikely(!drv || !drv->priv))
+ if (unlikely(!drv_priv))
return false;
- hpre_ctx = (struct hisi_hpre_ctx *)drv->priv;
+ hpre_ctx = (struct hisi_hpre_ctx *)drv_priv;
qp = (struct hisi_qp *)wd_ctx_get_priv(hpre_ctx->config.ctxs[0].ctx);
if (!qp || qp->q_info.hw_type < HISI_QM_API_VER3_BASE)
return false;
return true;
}
-static void ecc_sess_eops_params_cfg(struct wd_alg_driver *drv,
- struct wd_ecc_sess_setup *setup,
- struct wd_ecc_curve *cv, void *params)
+static void ecc_sess_eops_params_cfg(struct wd_ecc_sess_setup *setup,
+ struct wd_ecc_curve *cv, void *drv_priv, void *params)
{
__u8 data[SECP256R1_PARAM_SIZE] = SECG_P256_R1_PARAM;
struct hpre_ecc_ctx *ecc_ctx = params;
__u32 key_size;
int ret;
- if (!is_valid_hw_type(drv))
+ if (!is_valid_hw_type(drv_priv))
return;
if (!ecc_ctx) {
@@ -2938,6 +2913,7 @@ static int hpre_ecc_get_extend_ops(void *ops)
.alg_name = (hpre_alg_name),\
.calc_type = UADK_ALG_HW,\
.priority = 100,\
+ .priv_size = sizeof(struct hisi_hpre_ctx),\
.queue_num = HPRE_CTX_Q_NUM_DEF,\
.op_type_num = 1,\
.fallback = 0,\
@@ -2962,6 +2938,7 @@ static struct wd_alg_driver hpre_rsa_driver = {
.alg_name = "rsa",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_hpre_ctx),
.queue_num = HPRE_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
@@ -2977,6 +2954,7 @@ static struct wd_alg_driver hpre_dh_driver = {
.alg_name = "dh",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_hpre_ctx),
.queue_num = HPRE_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index c8b831c..fb9de2c 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -526,76 +526,76 @@ static __u32 g_sec_hmac_full_len[WD_DIGEST_TYPE_MAX] = {
SEC_HMAC_SHA512_MAC_LEN, SEC_HMAC_SHA512_224_MAC_LEN, SEC_HMAC_SHA512_256_MAC_LEN
};
-static int hisi_sec_init(struct wd_alg_driver *drv, void *conf);
-static void hisi_sec_exit(struct wd_alg_driver *drv);
+static int hisi_sec_init(void *conf, void *priv);
+static void hisi_sec_exit(void *priv);
-static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_send(handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_recv(handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_send_v3(handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_recv_v3(handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_send(handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_recv(handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_send_v3(handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_recv_v3(handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_send(handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_recv(handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_send_v3(handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_recv_v3(handle_t ctx, void *wd_msg);
-static int cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_send(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_cipher_send(drv, ctx, msg);
- return hisi_sec_cipher_send_v3(drv, ctx, msg);
+ return hisi_sec_cipher_send(ctx, msg);
+ return hisi_sec_cipher_send_v3(ctx, msg);
}
-static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_recv(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_cipher_recv(drv, ctx, msg);
- return hisi_sec_cipher_recv_v3(drv, ctx, msg);
+ return hisi_sec_cipher_recv(ctx, msg);
+ return hisi_sec_cipher_recv_v3(ctx, msg);
}
-static int digest_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int digest_send(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_digest_send(drv, ctx, msg);
- return hisi_sec_digest_send_v3(drv, ctx, msg);
+ return hisi_sec_digest_send(ctx, msg);
+ return hisi_sec_digest_send_v3(ctx, msg);
}
-static int digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int digest_recv(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_digest_recv(drv, ctx, msg);
- return hisi_sec_digest_recv_v3(drv, ctx, msg);
+ return hisi_sec_digest_recv(ctx, msg);
+ return hisi_sec_digest_recv_v3(ctx, msg);
}
-static int aead_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int aead_send(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_aead_send(drv, ctx, msg);
- return hisi_sec_aead_send_v3(drv, ctx, msg);
+ return hisi_sec_aead_send(ctx, msg);
+ return hisi_sec_aead_send_v3(ctx, msg);
}
-static int aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int aead_recv(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_aead_recv(drv, ctx, msg);
- return hisi_sec_aead_recv_v3(drv, ctx, msg);
+ return hisi_sec_aead_recv(ctx, msg);
+ return hisi_sec_aead_recv_v3(ctx, msg);
}
static int hisi_sec_get_usage(void *param)
@@ -614,7 +614,7 @@ static int hisi_sec_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_sec_ctx *)drv->priv;
+ priv = (struct hisi_sec_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
@@ -638,8 +638,8 @@ static int hisi_sec_get_usage(void *param)
static int eops_param_check(struct wd_alg_driver *drv, struct wd_mm_ops *mm_ops)
{
- if (!drv || !drv->priv) {
- WD_ERR("invalid: aead drv or priv is NULL!\n");
+ if (!drv || !drv->drv_data) {
+ WD_ERR("invalid: aead drv or data is NULL!\n");
return -WD_EINVAL;
}
@@ -680,7 +680,7 @@ static int aead_sess_eops_init(struct wd_alg_driver *drv,
return -WD_ENOMEM;
}
- sec_ctx = (struct hisi_sec_ctx *)drv->priv;
+ sec_ctx = (struct hisi_sec_ctx *)drv->drv_data;
qp = (struct hisi_qp *)wd_ctx_get_priv(sec_ctx->config.ctxs[0].ctx);
sq_depth = qp->q_info.sq_depth;
aiv_addr->aiv = mm_ops->alloc(mm_ops->usr, (__u32)sq_depth << AEAD_AIV_OFFSET);
@@ -735,7 +735,7 @@ static void aead_sess_eops_uninit(struct wd_alg_driver *drv,
return;
}
- sec_ctx = (struct hisi_sec_ctx *)drv->priv;
+ sec_ctx = (struct hisi_sec_ctx *)drv->drv_data;
qp = (struct hisi_qp *)wd_ctx_get_priv(sec_ctx->config.ctxs[0].ctx);
sq_depth = qp->q_info.sq_depth;
@@ -793,6 +793,7 @@ static int sec_aead_get_extend_ops(void *ops)
.alg_name = (sec_alg_name),\
.calc_type = UADK_ALG_HW,\
.priority = 100,\
+ .priv_size = sizeof(struct hisi_sec_ctx),\
.queue_num = SEC_CTX_Q_NUM_DEF,\
.op_type_num = 1,\
.fallback = 0,\
@@ -1400,7 +1401,7 @@ static int fill_cipher_bd2(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe)
return 0;
}
-static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_cipher_send(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_cipher_msg *msg = wd_msg;
@@ -1456,7 +1457,7 @@ static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *w
return 0;
}
-static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_cipher_recv(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_cipher_msg *recv_msg = wd_msg;
@@ -1693,7 +1694,7 @@ static void fill_sec_prefetch(__u8 data_fmt, __u32 len, __u16 hw_type, struct hi
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)
+static int hisi_sec_cipher_send_v3(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;
@@ -1800,7 +1801,7 @@ static void parse_cipher_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
dump_sec_msg(temp_msg, "cipher");
}
-static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_cipher_recv_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_cipher_msg *recv_msg = wd_msg;
@@ -2132,7 +2133,7 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
return 0;
}
-static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_digest_send(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_digest_msg *msg = wd_msg;
@@ -2209,7 +2210,7 @@ put_sgl:
return ret;
}
-static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_digest_recv(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_digest_msg *recv_msg = wd_msg;
@@ -2473,7 +2474,7 @@ map_err:
return -WD_ENOMEM;
}
-static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_digest_send_v3(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;
@@ -2587,7 +2588,7 @@ static void parse_digest_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
dump_sec_msg(temp_msg, "digest");
}
-static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_digest_recv_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_digest_msg *recv_msg = wd_msg;
@@ -3216,7 +3217,7 @@ static int fill_aead_bd2_addr(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe,
return aead_mem_nosva_map(msg, sqe, idx);
}
-static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_aead_send(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;
@@ -3347,7 +3348,7 @@ static void parse_aead_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe,
dump_sec_msg(temp_msg, "aead");
}
-static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_aead_recv(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_aead_msg *recv_msg = wd_msg;
@@ -3744,7 +3745,7 @@ static int fill_aead_bd3_addr(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe
return aead_mem_nosva_map_v3(msg, sqe, idx);
}
-static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_aead_send_v3(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;
@@ -3863,7 +3864,7 @@ static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
dump_sec_msg(temp_msg, "aead");
}
-static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_aead_recv_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_aead_msg *recv_msg = wd_msg;
@@ -3888,11 +3889,11 @@ static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *
return 0;
}
-static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
+static int hisi_sec_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_sec_ctx *sec_ctx = priv;
struct hisi_qm_priv qm_priv;
- struct hisi_sec_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -3902,10 +3903,6 @@ static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_sec_ctx));
- if (!priv)
- return -WD_EINVAL;
-
qm_priv.sqe_size = sizeof(struct hisi_sec_sqe);
/* allocate qp for each context */
for (i = 0; i < config->ctx_num; i++) {
@@ -3922,8 +3919,7 @@ static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
goto out;
config->ctxs[i].sqn = qm_priv.sqn;
}
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&sec_ctx->config, config, sizeof(struct wd_ctx_config_internal));
return 0;
@@ -3936,25 +3932,24 @@ out:
return -WD_EINVAL;
}
-static void hisi_sec_exit(struct wd_alg_driver *drv)
+static void hisi_sec_exit(void *priv)
{
struct wd_ctx_config_internal *config;
- struct hisi_sec_ctx *priv;
+ struct hisi_sec_ctx *sec_ctx = priv;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
+ if (!priv) {
+ WD_ERR("invalid: input parameter is NULL!\n");
return;
+ }
- priv = (struct hisi_sec_ctx *)drv->priv;
- config = &priv->config;
+ config = &sec_ctx->config;
for (i = 0; i < config->ctx_num; i++) {
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
hisi_qm_free_qp(h_qp);
}
- free(priv);
- drv->priv = NULL;
}
#ifdef WD_STATIC_DRV
diff --git a/drv/hisi_udma.c b/drv/hisi_udma.c
index a9f5607..5c8a743 100644
--- a/drv/hisi_udma.c
+++ b/drv/hisi_udma.c
@@ -290,7 +290,7 @@ static void fill_init_value(struct udma_sqe *sqe, struct wd_udma_msg *msg)
memset(&sqe->init_val, msg->value, sizeof(__u64));
}
-static int udma_send(struct wd_alg_driver *drv, handle_t ctx, void *udma_msg)
+static int udma_send(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;
@@ -342,7 +342,7 @@ static void dump_udma_msg(struct udma_sqe *sqe, struct wd_udma_msg *msg)
"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)
+static int udma_recv(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;
@@ -442,11 +442,11 @@ free_inter_addr:
return ret;
}
-static int udma_init(struct wd_alg_driver *drv, void *conf)
+static int udma_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_udma_ctx *uctx = priv;
struct hisi_qm_priv qm_priv;
- struct hisi_udma_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -457,10 +457,6 @@ static int udma_init(struct wd_alg_driver *drv, void *conf)
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 */
@@ -481,8 +477,7 @@ static int udma_init(struct wd_alg_driver *drv, void *conf)
if (ret)
goto free_h_qp;
}
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&uctx->config, config, sizeof(struct wd_ctx_config_internal));
return WD_SUCCESS;
free_h_qp:
@@ -493,30 +488,26 @@ out:
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)
+static void udma_exit(void *priv)
{
struct wd_ctx_config_internal *config;
- struct hisi_udma_ctx *priv;
+ struct hisi_udma_ctx *uctx = priv;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
+ if (!priv)
return;
- priv = (struct hisi_udma_ctx *)drv->priv;
- config = &priv->config;
+ config = &uctx->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)
@@ -535,7 +526,7 @@ static int udma_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_udma_ctx *)drv->priv;
+ priv = (struct hisi_udma_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
@@ -562,6 +553,7 @@ static struct wd_alg_driver udma_driver = {
.alg_name = "udma",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_udma_ctx),
.queue_num = UDMA_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
diff --git a/drv/isa_ce_sm3.c b/drv/isa_ce_sm3.c
index 8d23061..0ebaba5 100644
--- a/drv/isa_ce_sm3.c
+++ b/drv/isa_ce_sm3.c
@@ -24,10 +24,10 @@
typedef void (sm3_ce_block_fn)(__u32 word_reg[SM3_STATE_WORDS],
const unsigned char *src, size_t blocks);
-static int sm3_ce_drv_init(struct wd_alg_driver *drv, void *conf);
-static void sm3_ce_drv_exit(struct wd_alg_driver *drv);
-static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg);
-static int sm3_ce_drv_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg);
+static int sm3_ce_drv_init(void *conf, void *priv);
+static void sm3_ce_drv_exit(void *priv);
+static int sm3_ce_drv_send(handle_t ctx, void *digest_msg);
+static int sm3_ce_drv_recv(handle_t ctx, void *digest_msg);
static int sm3_ce_get_usage(void *param);
static struct wd_alg_driver sm3_ce_alg_driver = {
@@ -35,6 +35,7 @@ static struct wd_alg_driver sm3_ce_alg_driver = {
.alg_name = "sm3",
.calc_type = UADK_ALG_CE_INSTR,
.priority = 200,
+ .priv_size = sizeof(struct sm3_ce_drv_ctx),
.queue_num = 1,
.op_type_num = 1,
.fallback = 0,
@@ -335,7 +336,7 @@ static int do_hmac_sm3_ce(struct wd_digest_msg *msg, __u8 *out_hmac)
return WD_SUCCESS;
}
-static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
+static int sm3_ce_drv_send(handle_t ctx, void *digest_msg)
{
struct wd_digest_msg *msg = (struct wd_digest_msg *)digest_msg;
__u8 digest[SM3_DIGEST_SIZE] = {0};
@@ -370,39 +371,26 @@ static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest
return ret;
}
-static int sm3_ce_drv_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
+static int sm3_ce_drv_recv(handle_t ctx, void *digest_msg)
{
return WD_SUCCESS;
}
-static int sm3_ce_drv_init(struct wd_alg_driver *drv, void *conf)
+static int sm3_ce_drv_init(void *conf, void *priv)
{
- struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
- struct sm3_ce_drv_ctx *priv;
+ struct wd_ctx_config_internal *config = conf;
+ struct sm3_ce_drv_ctx *sctx = priv;
/* Fallback init is NULL */
- if (!drv || !conf)
+ if (!conf || !conf)
return 0;
- priv = malloc(sizeof(struct sm3_ce_drv_ctx));
- if (!priv)
- return -WD_ENOMEM;
-
config->epoll_en = 0;
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&sctx->config, config, sizeof(struct wd_ctx_config_internal));
return WD_SUCCESS;
}
-static void sm3_ce_drv_exit(struct wd_alg_driver *drv)
+static void sm3_ce_drv_exit(void *priv)
{
- struct sm3_ce_drv_ctx *sctx;
-
- if (!drv || !drv->priv)
- return;
-
- sctx = (struct sm3_ce_drv_ctx *)drv->priv;
- free(sctx);
- drv->priv = NULL;
}
diff --git a/drv/isa_ce_sm4.c b/drv/isa_ce_sm4.c
index 52dca1f..504ef73 100644
--- a/drv/isa_ce_sm4.c
+++ b/drv/isa_ce_sm4.c
@@ -11,9 +11,10 @@
* Copyright 2024 Huawei Technologies Co.,Ltd. All rights reserved.
*/
+#include "wd_alg.h"
#include "drv/wd_cipher_drv.h"
-#include "wd_cipher.h"
#include "isa_ce_sm4.h"
+#include "wd_cipher.h"
#define SM4_ENCRYPT 1
#define SM4_DECRYPT 0
@@ -31,36 +32,23 @@
((p)[0] = (__u8)((v) >> 24), (p)[1] = (__u8)((v) >> 16), \
(p)[2] = (__u8)((v) >> 8), (p)[3] = (__u8)(v))
-static int isa_ce_init(struct wd_alg_driver *drv, void *conf)
+static int isa_ce_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
- struct sm4_ce_drv_ctx *priv;
+ struct sm4_ce_drv_ctx *sctx = priv;
/* Fallback init is NULL */
- if (!drv || !conf)
+ if (!conf || !priv)
return 0;
- priv = malloc(sizeof(struct sm4_ce_drv_ctx));
- if (!priv)
- return -WD_EINVAL;
-
config->epoll_en = 0;
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&sctx->config, config, sizeof(struct wd_ctx_config_internal));
- return WD_SUCCESS;
+ return 0;
}
-static void isa_ce_exit(struct wd_alg_driver *drv)
+static void isa_ce_exit(void *priv)
{
- struct sm4_ce_drv_ctx *sctx;
-
- if (!drv || !drv->priv)
- return;
-
- sctx = (struct sm4_ce_drv_ctx *)drv->priv;
- free(sctx);
- drv->priv = NULL;
}
/* increment upper 96 bits of 128-bit counter by 1 */
@@ -334,7 +322,7 @@ static int sm4_xts_decrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rkey
return 0;
}
-static int isa_ce_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int isa_ce_cipher_send(handle_t ctx, void *wd_msg)
{
struct wd_cipher_msg *msg = wd_msg;
struct SM4_KEY rkey;
@@ -400,19 +388,19 @@ static int isa_ce_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_
return ret;
}
-static int isa_ce_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int isa_ce_cipher_recv(handle_t ctx, void *wd_msg)
{
return 0;
}
-static int cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_send(handle_t ctx, void *msg)
{
- return isa_ce_cipher_send(drv, ctx, msg);
+ return isa_ce_cipher_send(ctx, msg);
}
-static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_recv(handle_t ctx, void *msg)
{
- return isa_ce_cipher_recv(drv, ctx, msg);
+ return isa_ce_cipher_recv(ctx, msg);
}
#define GEN_CE_ALG_DRIVER(ce_alg_name, alg_type) \
@@ -421,6 +409,7 @@ static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
.alg_name = (ce_alg_name),\
.calc_type = UADK_ALG_CE_INSTR,\
.priority = 200,\
+ .priv_size = sizeof(struct sm4_ce_drv_ctx),\
.op_type_num = 1,\
.fallback = 0,\
.init = isa_ce_init,\
diff --git a/include/drv/wd_agg_drv.h b/include/drv/wd_agg_drv.h
index b26b25d..8952ee9 100644
--- a/include/drv/wd_agg_drv.h
+++ b/include/drv/wd_agg_drv.h
@@ -43,8 +43,7 @@ struct wd_agg_msg {
struct wd_agg_ops {
int (*get_row_size)(struct wd_alg_driver *drv, void *priv);
- int (*sess_init)(struct wd_alg_driver *drv,
- struct wd_agg_sess_setup *setup, void **priv);
+ int (*sess_init)(struct wd_agg_sess_setup *setup, void **priv);
void (*sess_uninit)(struct wd_alg_driver *drv, void *priv);
int (*hash_table_init)(struct wd_alg_driver *drv,
struct wd_dae_hash_table *hash_table, void *priv);
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index 48c422f..98ff28c 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -181,9 +181,8 @@ struct wd_ecc_out {
struct wd_ecc_extend_ops {
void *params; /* the params are passed to the following ops */
- void (*eops_params_cfg)(struct wd_alg_driver *drv,
- struct wd_ecc_sess_setup *setup,
- struct wd_ecc_curve *cv, void *params);
+ void (*eops_params_cfg)(struct wd_ecc_sess_setup *setup,
+ struct wd_ecc_curve *cv, void *drv_priv, void *params);
int (*sess_init)(struct wd_alg_driver *drv, void **params);
void (*sess_uninit)(struct wd_alg_driver *drv, void *params);
};
diff --git a/include/drv/wd_join_gather_drv.h b/include/drv/wd_join_gather_drv.h
index dbf4ee7..d7f136d 100644
--- a/include/drv/wd_join_gather_drv.h
+++ b/include/drv/wd_join_gather_drv.h
@@ -33,14 +33,12 @@ struct wd_join_gather_msg {
};
struct wd_join_gather_ops {
- int (*get_table_row_size)(struct wd_alg_driver *drv, void *priv);
- int (*get_batch_row_size)(struct wd_alg_driver *drv, void *priv,
+ int (*get_table_row_size)(void *priv);
+ int (*get_batch_row_size)(void *priv,
__u32 *batch_row_size, __u32 size);
- int (*sess_init)(struct wd_alg_driver *drv,
- struct wd_join_gather_sess_setup *setup, void **priv);
- void (*sess_uninit)(struct wd_alg_driver *drv, void *priv);
- int (*hash_table_init)(struct wd_alg_driver *drv,
- struct wd_dae_hash_table *hash_table, void *priv);
+ int (*sess_init)(struct wd_join_gather_sess_setup *setup, void **priv);
+ void (*sess_uninit)(void *priv);
+ int (*hash_table_init)(struct wd_dae_hash_table *hash_table, void *priv);
};
struct wd_join_gather_msg *wd_join_gather_get_msg(__u32 idx, __u32 tag);
diff --git a/include/wd_alg.h b/include/wd_alg.h
index 18503ca..885a5e3 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -19,6 +19,7 @@ extern "C" {
#define handle_t uintptr_t
#define ALG_NAME_SIZE 128
#define DEV_NAME_LEN 128
+typedef unsigned char __u8;
/*
* Macros related to arm platform:
@@ -85,7 +86,8 @@ enum alg_dev_type {
* execute the algorithm task
* @op_type_num: number of modes in which the device executes the
* algorithm business and requires queues to be executed separately
- * @priv: pointer of priv ctx
+ * @priv_size: parameter memory size passed between the internal
+ * interfaces of the driver
* @fallback: soft calculation driver handle when performing soft
* calculation supplement
* @init: callback interface for initializing device drivers
@@ -105,13 +107,14 @@ struct wd_alg_driver {
int calc_type;
int queue_num;
int op_type_num;
- void *priv;
+ int priv_size;
+ int *drv_data;
handle_t fallback;
- int (*init)(struct wd_alg_driver *drv, void *conf);
- void (*exit)(struct wd_alg_driver *drv);
- int (*send)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
- int (*recv)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
+ int (*init)(void *conf, void *priv);
+ void (*exit)(void *priv);
+ int (*send)(handle_t ctx, void *drv_msg);
+ int (*recv)(handle_t ctx, void *drv_msg);
int (*get_usage)(void *param);
int (*get_extend_ops)(void *ops);
};
@@ -182,10 +185,6 @@ bool wd_drv_alg_support(const char *alg_name,
void wd_enable_drv(struct wd_alg_driver *drv);
void wd_disable_drv(struct wd_alg_driver *drv);
-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);
diff --git a/include/wd_util.h b/include/wd_util.h
index 2abceec..14985e2 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -120,8 +120,8 @@ struct wd_ctx_attr {
};
struct wd_msg_handle {
- int (*send)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
- int (*recv)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
+ int (*send)(handle_t sess, void *msg);
+ int (*recv)(handle_t sess, void *msg);
};
struct wd_init_attrs {
@@ -378,7 +378,6 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en);
/**
* wd_handle_msg_sync() - recv msg from hardware
- * @drv: the driver to handle msg.
* @msg_handle: callback of msg handle ops.
* @ctx: the handle of context.
* @msg: the msg of task.
@@ -387,8 +386,8 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en);
*
* Return 0 if successful or less than 0 otherwise.
*/
-int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_handle,
- handle_t ctx, void *msg, __u64 *balance, bool epoll_en);
+int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx,
+ void *msg, __u64 *balance, bool epoll_en);
/**
* wd_init_check() - Check input parameters for wd_<alg>_init.
@@ -486,13 +485,14 @@ void wd_alg_drv_unbind(struct wd_alg_driver *drv);
* to the obtained queue resource and the applied driver.
* @config: device resources requested by the current algorithm.
* @driver: device driver for the current algorithm application.
+ * @drv_priv: the parameter pointer of the current device driver.
*
* Return 0 if succeed and other error number if fail.
*/
int wd_alg_init_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver);
+ struct wd_alg_driver *driver, void **drv_priv);
void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver);
+ struct wd_alg_driver *driver, void **drv_priv);
/**
* wd_dlopen_drv() - Open the dynamic library file of the device driver.
diff --git a/wd_aead.c b/wd_aead.c
index 8467409..43bda73 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -34,6 +34,7 @@ struct wd_aead_setting {
struct wd_sched sched;
struct wd_alg_driver *driver;
struct wd_async_msg_pool pool;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_aead_setting;
@@ -603,7 +604,8 @@ static int wd_aead_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_aead_setting.config,
- wd_aead_setting.driver);
+ wd_aead_setting.driver,
+ &wd_aead_setting.priv);
if (ret)
goto out_clear_pool;
@@ -652,30 +654,21 @@ out_clear_init:
return ret;
}
-static int wd_aead_uninit_nolock(void)
+static void wd_aead_uninit_nolock(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_aead_setting.status, &status);
- if (status == WD_UNINIT)
- return -WD_EINVAL;
-
wd_uninit_async_request_pool(&wd_aead_setting.pool);
wd_clear_sched(&wd_aead_setting.sched);
wd_alg_uninit_driver(&wd_aead_setting.config,
- wd_aead_setting.driver);
-
- return 0;
+ wd_aead_setting.driver,
+ &wd_aead_setting.priv);
}
void wd_aead_uninit(void)
{
- int ret;
-
- ret = wd_aead_uninit_nolock();
- if (ret)
+ if (!wd_aead_setting.priv)
return;
+ wd_aead_uninit_nolock();
wd_aead_close_driver(WD_TYPE_V1);
wd_alg_clear_init(&wd_aead_setting.status);
}
@@ -781,12 +774,10 @@ out_uninit:
void wd_aead_uninit2(void)
{
- int ret;
-
- ret = wd_aead_uninit_nolock();
- if (ret)
+ if (!wd_aead_setting.priv)
return;
+ wd_aead_uninit_nolock();
wd_alg_attrs_uninit(&wd_aead_init_attrs);
wd_alg_drv_unbind(wd_aead_setting.driver);
wd_aead_close_driver(WD_TYPE_V2);
@@ -875,8 +866,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx,
msg_handle.recv = wd_aead_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_aead_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, wd_aead_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL,
+ wd_aead_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
return ret;
@@ -951,7 +942,7 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req)
fill_request_msg(msg, req, sess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_aead_setting.driver, ctx->ctx, msg);
+ ret = wd_aead_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send BD, hw is err!\n");
@@ -1001,7 +992,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_aead_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_aead_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_agg.c b/wd_agg.c
index 8c54d10..66e9e0f 100644
--- a/wd_agg.c
+++ b/wd_agg.c
@@ -361,7 +361,7 @@ static int wd_agg_init_sess_priv(struct wd_agg_sess *sess, struct wd_agg_sess_se
WD_ERR("failed to get session uninit ops!\n");
return -WD_EINVAL;
}
- ret = sess->ops.sess_init(wd_agg_setting.driver, setup, &sess->priv);
+ ret = sess->ops.sess_init(setup, &sess->priv);
if (ret) {
WD_ERR("failed to init session priv!\n");
return ret;
@@ -595,7 +595,8 @@ static int wd_agg_alg_init(struct wd_ctx_config *config, struct wd_sched *sched)
if (ret < 0)
goto out_clear_sched;
- ret = wd_alg_init_driver(&wd_agg_setting.config, wd_agg_setting.driver);
+ ret = wd_alg_init_driver(&wd_agg_setting.config, wd_agg_setting.driver,
+ &wd_agg_setting.priv);
if (ret)
goto out_clear_pool;
@@ -624,7 +625,8 @@ static int wd_agg_alg_uninit(void)
/* Unset config, sched, driver */
wd_clear_sched(&wd_agg_setting.sched);
- wd_alg_uninit_driver(&wd_agg_setting.config, wd_agg_setting.driver);
+ wd_alg_uninit_driver(&wd_agg_setting.config, wd_agg_setting.driver,
+ &wd_agg_setting.priv);
return WD_SUCCESS;
}
@@ -1101,8 +1103,7 @@ static int wd_agg_sync_job(struct wd_agg_sess *sess, struct wd_agg_req *req,
msg_handle.recv = wd_agg_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_agg_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, config->epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL, config->epoll_en);
pthread_spin_unlock(&ctx->lock);
return ret;
@@ -1203,7 +1204,7 @@ static int wd_agg_async_job(struct wd_agg_sess *sess, struct wd_agg_req *req, bo
else
fill_request_msg_output(msg, req, sess, false);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_agg_setting.driver, ctx->ctx, msg);
+ ret = wd_agg_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("wd agg async send err!\n");
@@ -1542,7 +1543,7 @@ static int wd_agg_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_agg_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_agg_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (unlikely(ret < 0)) {
diff --git a/wd_alg.c b/wd_alg.c
index 1e4f14a..a1a0a79 100644
--- a/wd_alg.c
+++ b/wd_alg.c
@@ -465,26 +465,6 @@ void wd_release_drv(struct wd_alg_driver *drv)
pthread_mutex_unlock(&mutex);
}
-int wd_alg_driver_init(struct wd_alg_driver *drv, void *conf)
-{
- return drv->init(drv, conf);
-}
-
-void wd_alg_driver_exit(struct wd_alg_driver *drv)
-{
- drv->exit(drv);
-}
-
-int wd_alg_driver_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
-{
- return drv->send(drv, ctx, msg);
-}
-
-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;
diff --git a/wd_cipher.c b/wd_cipher.c
index 58656dc..53733a4 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -53,6 +53,7 @@ struct wd_cipher_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_cipher_setting;
@@ -379,7 +380,8 @@ static int wd_cipher_common_init(struct wd_ctx_config *config,
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_cipher_setting.config,
- wd_cipher_setting.driver);
+ wd_cipher_setting.driver,
+ &wd_cipher_setting.priv);
if (ret)
goto out_clear_pool;
@@ -396,10 +398,9 @@ out_clear_ctx_config:
static int wd_cipher_common_uninit(void)
{
- enum wd_status status;
+ void *priv = wd_cipher_setting.priv;
- wd_alg_get_init(&wd_cipher_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!priv)
return -WD_EINVAL;
/* uninit async request pool */
@@ -409,7 +410,8 @@ static int wd_cipher_common_uninit(void)
wd_clear_sched(&wd_cipher_setting.sched);
wd_alg_uninit_driver(&wd_cipher_setting.config,
- wd_cipher_setting.driver);
+ wd_cipher_setting.driver,
+ &wd_cipher_setting.priv);
return 0;
}
@@ -720,8 +722,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx,
msg_handle.recv = wd_cipher_setting.driver->recv;
wd_ctx_spin_lock(ctx, wd_cipher_setting.driver->calc_type);
- ret = wd_handle_msg_sync(wd_cipher_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, wd_cipher_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL,
+ wd_cipher_setting.config.epoll_en);
wd_ctx_spin_unlock(ctx, wd_cipher_setting.driver->calc_type);
return ret;
@@ -796,7 +798,7 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req)
fill_request_msg(msg, req, sess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_cipher_setting.driver, ctx->ctx, msg);
+ ret = wd_cipher_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("wd cipher async send err!\n");
@@ -846,7 +848,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_cipher_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_cipher_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN)
return ret;
else if (ret < 0) {
diff --git a/wd_comp.c b/wd_comp.c
index c67b7f1..be08ee8 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -51,6 +51,7 @@ struct wd_comp_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_comp_setting;
@@ -172,7 +173,8 @@ static int wd_comp_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_comp_setting.config,
- wd_comp_setting.driver);
+ wd_comp_setting.driver,
+ &wd_comp_setting.priv);
if (ret)
goto out_clear_pool;
@@ -189,10 +191,9 @@ out_clear_ctx_config:
static int wd_comp_uninit_nolock(void)
{
- enum wd_status status;
+ void *priv = wd_comp_setting.priv;
- wd_alg_get_init(&wd_comp_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!priv)
return -WD_EINVAL;
/* Uninit async request pool */
@@ -202,7 +203,8 @@ static int wd_comp_uninit_nolock(void)
wd_clear_sched(&wd_comp_setting.sched);
wd_alg_uninit_driver(&wd_comp_setting.config,
- wd_comp_setting.driver);
+ wd_comp_setting.driver,
+ &wd_comp_setting.priv);
return 0;
}
@@ -382,7 +384,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_comp_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_comp_setting.driver->recv(ctx->ctx, &resp_msg);
if (unlikely(ret < 0)) {
if (ret == -WD_HW_EACCESS)
WD_ERR("wd comp recv hw error!\n");
@@ -685,8 +687,8 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess,
msg_handle.recv = wd_comp_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_comp_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, config->epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg,
+ NULL, config->epoll_en);
pthread_spin_unlock(&ctx->lock);
return ret;
@@ -944,7 +946,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
msg->tag = tag;
msg->stream_mode = WD_COMP_STATELESS;
- ret = wd_alg_driver_send(wd_comp_setting.driver, ctx->ctx, msg);
+ ret = wd_comp_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("wd comp send error, ret = %d!\n", ret);
diff --git a/wd_dh.c b/wd_dh.c
index 0c1372c..42a1805 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -36,6 +36,7 @@ static struct wd_dh_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_dh_setting;
@@ -144,7 +145,8 @@ static int wd_dh_common_init(struct wd_ctx_config *config, struct wd_sched *sche
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_dh_setting.config,
- wd_dh_setting.driver);
+ wd_dh_setting.driver,
+ &wd_dh_setting.priv);
if (ret)
goto out_clear_pool;
@@ -161,11 +163,10 @@ out_clear_ctx_config:
static int wd_dh_common_uninit(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_dh_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!wd_dh_setting.priv) {
+ WD_ERR("invalid: repeat uninit dh!\n");
return -WD_EINVAL;
+ }
/* uninit async request pool */
wd_uninit_async_request_pool(&wd_dh_setting.pool);
@@ -173,7 +174,8 @@ static int wd_dh_common_uninit(void)
/* unset config, sched, driver */
wd_clear_sched(&wd_dh_setting.sched);
wd_alg_uninit_driver(&wd_dh_setting.config,
- wd_dh_setting.driver);
+ wd_dh_setting.driver,
+ &wd_dh_setting.priv);
return WD_SUCCESS;
}
@@ -390,8 +392,8 @@ int wd_do_dh_sync(handle_t sess, struct wd_dh_req *req)
msg_handle.recv = wd_dh_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_dh_setting.driver, &msg_handle, ctx->ctx,
- &msg, &balance, wd_dh_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance,
+ wd_dh_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
return ret;
@@ -437,7 +439,7 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req)
goto fail_with_msg;
msg->tag = mid;
- ret = wd_alg_driver_send(wd_dh_setting.driver, ctx->ctx, msg);
+ ret = wd_dh_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send dh BD, hw is err!\n");
@@ -488,7 +490,7 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_dh_setting.driver, ctx->ctx, &rcv_msg);
+ ret = wd_dh_setting.driver->recv(ctx->ctx, &rcv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (unlikely(ret)) {
diff --git a/wd_digest.c b/wd_digest.c
index 0b37f8b..763eae5 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -42,6 +42,7 @@ struct wd_digest_setting {
struct wd_sched sched;
struct wd_alg_driver *driver;
struct wd_async_msg_pool pool;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_digest_setting;
@@ -312,7 +313,8 @@ static int wd_digest_init_nolock(struct wd_ctx_config *config,
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_digest_setting.config,
- wd_digest_setting.driver);
+ wd_digest_setting.driver,
+ &wd_digest_setting.priv);
if (ret)
goto out_clear_pool;
@@ -361,29 +363,21 @@ out_clear_init:
return ret;
}
-static int wd_digest_uninit_nolock(void)
+static void wd_digest_uninit_nolock(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_digest_setting.status, &status);
- if (status == WD_UNINIT)
- return -WD_EINVAL;
-
wd_uninit_async_request_pool(&wd_digest_setting.pool);
wd_clear_sched(&wd_digest_setting.sched);
wd_alg_uninit_driver(&wd_digest_setting.config,
- wd_digest_setting.driver);
- return 0;
+ wd_digest_setting.driver,
+ &wd_digest_setting.priv);
}
void wd_digest_uninit(void)
{
- int ret;
-
- ret = wd_digest_uninit_nolock();
- if (ret)
+ if (!wd_digest_setting.priv)
return;
+ wd_digest_uninit_nolock();
wd_digest_close_driver(WD_TYPE_V1);
wd_alg_clear_init(&wd_digest_setting.status);
}
@@ -485,12 +479,10 @@ out_uninit:
void wd_digest_uninit2(void)
{
- int ret;
-
- ret = wd_digest_uninit_nolock();
- if (ret)
+ if (!wd_digest_setting.priv)
return;
+ wd_digest_uninit_nolock();
wd_alg_attrs_uninit(&wd_digest_init_attrs);
wd_alg_drv_unbind(wd_digest_setting.driver);
wd_digest_close_driver(WD_TYPE_V2);
@@ -655,8 +647,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *ds
msg_handle.recv = wd_digest_setting.driver->recv;
wd_ctx_spin_lock(ctx, wd_digest_setting.driver->calc_type);
- ret = wd_handle_msg_sync(wd_digest_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, wd_digest_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg,
+ NULL, wd_digest_setting.config.epoll_en);
wd_ctx_spin_unlock(ctx, wd_digest_setting.driver->calc_type);
if (unlikely(ret))
return ret;
@@ -750,7 +742,7 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req)
fill_request_msg(msg, req, dsess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_digest_setting.driver, ctx->ctx, msg);
+ ret = wd_digest_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send BD, hw is err!\n");
@@ -800,7 +792,8 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_digest_setting.driver, ctx->ctx, &recv_msg);
+ ret = wd_digest_setting.driver->recv(ctx->ctx,
+ &recv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_ecc.c b/wd_ecc.c
index 2c88d0a..900f36c 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -69,6 +69,7 @@ static struct wd_ecc_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_ecc_setting;
@@ -210,7 +211,8 @@ static int wd_ecc_common_init(struct wd_ctx_config *config, struct wd_sched *sch
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_ecc_setting.config,
- wd_ecc_setting.driver);
+ wd_ecc_setting.driver,
+ &wd_ecc_setting.priv);
if (ret)
goto out_clear_pool;
@@ -227,11 +229,10 @@ out_clear_ctx_config:
static int wd_ecc_common_uninit(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_ecc_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!wd_ecc_setting.priv) {
+ WD_ERR("invalid: repeat uninit ecc!\n");
return -WD_EINVAL;
+ }
/* uninit async request pool */
wd_uninit_async_request_pool(&wd_ecc_setting.pool);
@@ -239,7 +240,8 @@ static int wd_ecc_common_uninit(void)
/* unset config, sched, driver */
wd_clear_sched(&wd_ecc_setting.sched);
wd_alg_uninit_driver(&wd_ecc_setting.config,
- wd_ecc_setting.driver);
+ wd_ecc_setting.driver,
+ &wd_ecc_setting.priv);
return WD_SUCCESS;
}
@@ -1203,8 +1205,8 @@ static void wd_ecc_sess_eops_cfg(struct wd_ecc_sess_setup *setup,
{
if (sess->eops.sess_init && sess->eops.eops_params_cfg) {
/* the config result does not impact task sucesss or failure */
- sess->eops.eops_params_cfg(wd_ecc_setting.driver, setup, sess->key.cv,
- sess->eops.params);
+ sess->eops.eops_params_cfg(setup, sess->key.cv,
+ wd_ecc_setting.priv, sess->eops.params);
}
}
@@ -1652,8 +1654,8 @@ int wd_do_ecc_sync(handle_t h_sess, struct wd_ecc_req *req)
msg_handle.recv = wd_ecc_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_ecc_setting.driver, &msg_handle, ctx->ctx, &msg,
- &balance, wd_ecc_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance,
+ wd_ecc_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
return ret;
@@ -2339,7 +2341,7 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req)
goto fail_with_msg;
msg->tag = mid;
- ret = wd_alg_driver_send(wd_ecc_setting.driver, ctx->ctx, msg);
+ ret = wd_ecc_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send ecc BD, hw is err!\n");
@@ -2389,7 +2391,7 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_ecc_setting.driver, ctx->ctx, &recv_msg);
+ ret = wd_ecc_setting.driver->recv(ctx->ctx, &recv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_join_gather.c b/wd_join_gather.c
index 915c1b8..86190c4 100644
--- a/wd_join_gather.c
+++ b/wd_join_gather.c
@@ -410,13 +410,12 @@ static void wd_join_gather_uninit_sess(struct wd_join_gather_sess *sess)
free(sess->gather_conf.batch_row_size);
if (sess->ops.sess_uninit)
- sess->ops.sess_uninit(wd_join_gather_setting.driver, sess->priv);
+ sess->ops.sess_uninit(sess->priv);
}
static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
struct wd_join_gather_sess_setup *setup)
{
- struct wd_alg_driver *drv = wd_join_gather_setting.driver;
__u32 array_size;
int ret;
@@ -425,7 +424,7 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
WD_ERR("failed to get session uninit ops!\n");
return -WD_EINVAL;
}
- ret = sess->ops.sess_init(drv, setup, &sess->priv);
+ ret = sess->ops.sess_init(setup, &sess->priv);
if (ret) {
WD_ERR("failed to init session priv!\n");
return ret;
@@ -433,7 +432,7 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
}
if (sess->ops.get_table_row_size && setup->alg != WD_GATHER) {
- ret = sess->ops.get_table_row_size(drv, sess->priv);
+ ret = sess->ops.get_table_row_size(sess->priv);
if (ret <= 0) {
WD_ERR("failed to get hash table row size: %d!\n", ret);
goto uninit;
@@ -447,7 +446,7 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
if (!sess->gather_conf.batch_row_size)
goto uninit;
- ret = sess->ops.get_batch_row_size(drv, sess->priv,
+ ret = sess->ops.get_batch_row_size(sess->priv,
sess->gather_conf.batch_row_size,
array_size);
if (ret) {
@@ -462,7 +461,7 @@ free_batch:
free(sess->gather_conf.batch_row_size);
uninit:
if (sess->ops.sess_uninit)
- sess->ops.sess_uninit(drv, sess->priv);
+ sess->ops.sess_uninit(sess->priv);
return -WD_EINVAL;
}
@@ -656,8 +655,7 @@ int wd_join_set_hash_table(handle_t h_sess, struct wd_dae_hash_table *info)
WD_INFO("info: extern hash table is NULL!\n");
if (sess->ops.hash_table_init) {
- ret = sess->ops.hash_table_init(wd_join_gather_setting.driver,
- info, sess->priv);
+ ret = sess->ops.hash_table_init(info, sess->priv);
if (ret)
goto out;
}
@@ -699,7 +697,9 @@ static int wd_join_gather_alg_init(struct wd_ctx_config *config, struct wd_sched
if (ret < 0)
goto out_clear_sched;
- ret = wd_alg_init_driver(&wd_join_gather_setting.config, wd_join_gather_setting.driver);
+ ret = wd_alg_init_driver(&wd_join_gather_setting.config,
+ wd_join_gather_setting.driver,
+ &wd_join_gather_setting.priv);
if (ret)
goto out_clear_pool;
@@ -728,7 +728,9 @@ static int wd_join_gather_alg_uninit(void)
/* Unset config, sched, driver */
wd_clear_sched(&wd_join_gather_setting.sched);
- wd_alg_uninit_driver(&wd_join_gather_setting.config, wd_join_gather_setting.driver);
+ wd_alg_uninit_driver(&wd_join_gather_setting.config,
+ wd_join_gather_setting.driver,
+ &wd_join_gather_setting.priv);
return WD_SUCCESS;
}
@@ -1215,7 +1217,7 @@ static int wd_join_gather_sync_job(struct wd_join_gather_sess *sess,
msg_handle.recv = setting->driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(setting->driver, &msg_handle, ctx->ctx,
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx,
msg, NULL, config->epoll_en);
pthread_spin_unlock(&ctx->lock);
@@ -1311,7 +1313,7 @@ static int wd_join_gather_async_job(struct wd_join_gather_sess *sess,
fill_join_gather_msg(msg, req, sess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(setting->driver, ctx->ctx, msg);
+ ret = wd_join_gather_setting.driver->send(ctx->ctx, msg);
if (ret < 0) {
if (ret != -WD_EBUSY)
WD_ERR("wd join gather async send err!\n");
@@ -1781,7 +1783,7 @@ static int wd_join_gather_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_join_gather_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_join_gather_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_rsa.c b/wd_rsa.c
index bc78c6a..3e4d70d 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -77,6 +77,7 @@ static struct wd_rsa_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_rsa_setting;
@@ -184,7 +185,8 @@ static int wd_rsa_common_init(struct wd_ctx_config *config, struct wd_sched *sch
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_rsa_setting.config,
- wd_rsa_setting.driver);
+ wd_rsa_setting.driver,
+ &wd_rsa_setting.priv);
if (ret)
goto out_clear_pool;
@@ -201,11 +203,10 @@ out_clear_ctx_config:
static int wd_rsa_common_uninit(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_rsa_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!wd_rsa_setting.priv) {
+ WD_ERR("invalid: repeat uninit rsa!\n");
return -WD_EINVAL;
+ }
/* uninit async request pool */
wd_uninit_async_request_pool(&wd_rsa_setting.pool);
@@ -213,7 +214,8 @@ static int wd_rsa_common_uninit(void)
/* unset config, sched, driver */
wd_clear_sched(&wd_rsa_setting.sched);
wd_alg_uninit_driver(&wd_rsa_setting.config,
- wd_rsa_setting.driver);
+ wd_rsa_setting.driver,
+ &wd_rsa_setting.priv);
return WD_SUCCESS;
}
@@ -451,8 +453,8 @@ int wd_do_rsa_sync(handle_t h_sess, struct wd_rsa_req *req)
msg_handle.recv = wd_rsa_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_rsa_setting.driver, &msg_handle, ctx->ctx, &msg,
- &balance, wd_rsa_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance,
+ wd_rsa_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
return ret;
@@ -498,7 +500,7 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req)
goto fail_with_msg;
msg->tag = mid;
- ret = wd_alg_driver_send(wd_rsa_setting.driver, ctx->ctx, msg);
+ ret = wd_rsa_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send rsa BD, hw is err!\n");
@@ -548,7 +550,7 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_rsa_setting.driver, ctx->ctx, &recv_msg);
+ ret = wd_rsa_setting.driver->recv(ctx->ctx, &recv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_udma.c b/wd_udma.c
index eebe495..341b533 100644
--- a/wd_udma.c
+++ b/wd_udma.c
@@ -22,6 +22,7 @@ static struct wd_udma_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_udma_setting;
@@ -229,7 +230,7 @@ int wd_do_udma_sync(handle_t h_sess, struct wd_udma_req *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,
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx,
&msg, NULL, wd_udma_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
@@ -276,7 +277,7 @@ int wd_do_udma_async(handle_t sess, struct wd_udma_req *req)
fill_udma_msg(msg, req);
msg->tag = mid;
- ret = wd_alg_driver_send(wd_udma_setting.driver, ctx->ctx, msg);
+ ret = wd_udma_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send udma BD, hw is err!\n");
@@ -314,7 +315,7 @@ static int wd_udma_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_udma_setting.driver, ctx->ctx, &rcv_msg);
+ ret = wd_udma_setting.driver->recv(ctx->ctx, &rcv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (unlikely(ret)) {
@@ -364,7 +365,9 @@ static void wd_udma_alg_uninit(void)
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);
+ wd_alg_uninit_driver(&wd_udma_setting.config,
+ wd_udma_setting.driver,
+ &wd_udma_setting.priv);
}
void wd_udma_uninit(void)
@@ -405,7 +408,9 @@ static int wd_udma_alg_init(struct wd_ctx_config *config, struct wd_sched *sched
if (ret < 0)
goto out_clear_sched;
- ret = wd_alg_init_driver(&wd_udma_setting.config, wd_udma_setting.driver);
+ ret = wd_alg_init_driver(&wd_udma_setting.config,
+ wd_udma_setting.driver,
+ &wd_udma_setting.priv);
if (ret)
goto out_clear_pool;
diff --git a/wd_util.c b/wd_util.c
index bf82fc1..0dc9a67 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -1878,8 +1878,8 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en)
return 0;
}
-int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_handle,
- handle_t ctx, void *msg, __u64 *balance, bool epoll_en)
+int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx,
+ void *msg, __u64 *balance, bool epoll_en)
{
__u64 timeout = WD_RECV_MAX_CNT_NOSLEEP;
__u64 rx_cnt = 0;
@@ -1888,7 +1888,7 @@ int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_hand
if (balance)
timeout = WD_RECV_MAX_CNT_SLEEP;
- ret = msg_handle->send(drv, ctx, msg);
+ ret = msg_handle->send(ctx, msg);
if (unlikely(ret < 0)) {
WD_ERR("failed to send msg to hw, ret = %d!\n", ret);
return ret;
@@ -1901,7 +1901,7 @@ int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_hand
WD_ERR("wd ctx wait timeout(%d)!\n", ret);
}
- ret = msg_handle->recv(drv, ctx, msg);
+ ret = msg_handle->recv(ctx, msg);
if (ret != -WD_EAGAIN) {
if (unlikely(ret < 0)) {
WD_ERR("failed to recv msg: error = %d!\n", ret);
@@ -1964,10 +1964,21 @@ static void wd_alg_uninit_fallback(struct wd_alg_driver *fb_driver)
}
int wd_alg_init_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver)
+ struct wd_alg_driver *driver, void **drv_priv)
{
+ void *priv;
int ret;
+ if (!driver->priv_size) {
+ WD_ERR("invalid: driver priv ctx size is zero!\n");
+ return -WD_EINVAL;
+ }
+
+ /* Init ctx related resources in specific driver */
+ priv = calloc(1, driver->priv_size);
+ if (!priv)
+ return -WD_ENOMEM;
+
if (!driver->init) {
driver->fallback = 0;
WD_ERR("driver have no init interface.\n");
@@ -1975,11 +1986,12 @@ int wd_alg_init_driver(struct wd_ctx_config_internal *config,
goto err_alloc;
}
- ret = driver->init(driver, config);
+ ret = driver->init(config, priv);
if (ret < 0) {
WD_ERR("driver init failed.\n");
goto err_alloc;
}
+ driver->drv_data = priv;
if (driver->fallback) {
ret = wd_alg_init_fallback((struct wd_alg_driver *)driver->fallback);
@@ -1988,22 +2000,32 @@ int wd_alg_init_driver(struct wd_ctx_config_internal *config,
WD_ERR("soft alg driver init failed.\n");
}
}
+ *drv_priv = priv;
return 0;
err_alloc:
+ free(priv);
return ret;
}
void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver)
+ struct wd_alg_driver *driver, void **drv_priv)
{
- driver->exit(driver);
+ void *priv = *drv_priv;
+
+ driver->exit(priv);
/* Ctx config just need clear once */
wd_clear_ctx_config(config);
if (driver->fallback)
wd_alg_uninit_fallback((struct wd_alg_driver *)driver->fallback);
+
+ if (priv) {
+ free(priv);
+ driver->drv_data = NULL;
+ *drv_priv = NULL;
+ }
}
void wd_dlclose_drv(void *dlh_list)
--
2.43.0
1
18
08 Apr '26
From: Longfang Liu <liulongfang(a)huawei.com>
This reverts commit 3fc344aa4f7c460269cd0d870fe388f01dfa22a2.
---
drv/hash_mb/hash_mb.c | 45 +++++------
drv/hisi_comp.c | 32 +++-----
drv/hisi_dae.c | 13 +---
drv/hisi_dae.h | 4 +-
drv/hisi_dae_common.c | 28 +++----
drv/hisi_dae_join_gather.c | 21 ++----
drv/hisi_hpre.c | 76 +++++++------------
drv/hisi_sec.c | 123 +++++++++++++++----------------
drv/hisi_udma.c | 30 +++-----
drv/isa_ce_sm3.c | 38 ++++------
drv/isa_ce_sm4.c | 41 ++++-------
include/drv/wd_agg_drv.h | 3 +-
include/drv/wd_ecc_drv.h | 5 +-
include/drv/wd_join_gather_drv.h | 12 ++-
include/wd_alg.h | 19 +++--
include/wd_util.h | 14 ++--
wd_aead.c | 37 ++++------
wd_agg.c | 15 ++--
wd_alg.c | 20 -----
wd_cipher.c | 20 ++---
wd_comp.c | 20 ++---
wd_dh.c | 22 +++---
wd_digest.c | 37 ++++------
wd_ecc.c | 26 ++++---
wd_join_gather.c | 28 +++----
wd_rsa.c | 22 +++---
wd_udma.c | 15 ++--
wd_util.c | 38 ++++++++--
28 files changed, 351 insertions(+), 453 deletions(-)
diff --git a/drv/hash_mb/hash_mb.c b/drv/hash_mb/hash_mb.c
index bd412b2..5c0daf2 100644
--- a/drv/hash_mb/hash_mb.c
+++ b/drv/hash_mb/hash_mb.c
@@ -186,46 +186,34 @@ free_mb_queue:
return ret;
}
-static int hash_mb_init(struct wd_alg_driver *drv, void *conf)
+static int hash_mb_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
- struct hash_mb_ctx *priv;
- int ret;
+ struct hash_mb_ctx *mb_ctx = priv;
/* Fallback init is NULL */
- if (!drv || !conf)
+ if (!conf || !priv)
return 0;
- priv = malloc(sizeof(struct hash_mb_ctx));
- if (!priv)
- return -WD_ENOMEM;
-
/* multibuff does not use epoll. */
config->epoll_en = 0;
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
+ memcpy(&mb_ctx->config, config, sizeof(struct wd_ctx_config_internal));
- ret = hash_mb_queue_init(config);
- if (ret) {
- free(priv);
- return ret;
- }
-
- drv->priv = priv;
-
- return WD_SUCCESS;
+ return hash_mb_queue_init(config);
}
-static void hash_mb_exit(struct wd_alg_driver *drv)
+static void hash_mb_exit(void *priv)
{
- struct hash_mb_ctx *priv;
+ struct hash_mb_ctx *mb_ctx = priv;
+ struct wd_ctx_config_internal *config;
- if (!drv || !drv->priv)
+ if (!priv) {
+ WD_ERR("invalid: input parameter is NULL!\n");
return;
+ }
- priv = (struct hash_mb_ctx *)drv->priv;
- hash_mb_queue_uninit(&priv->config, priv->config.ctx_num);
- free(priv);
- drv->priv = NULL;
+ config = &mb_ctx->config;
+ hash_mb_queue_uninit(config, config->ctx_num);
}
static void hash_mb_pad_data(struct hash_pad *hash_pad, __u8 *in, __u32 partial,
@@ -267,7 +255,7 @@ static inline void hash_xor(__u8 *key_out, __u8 *key_in, __u32 key_len, __u8 xor
if (i < key_len)
key_out[i] = key_in[i] ^ xor_value;
else
- key_out[i] = xor_value;
+ key_out[i] = 0x0 ^ xor_value;
}
}
@@ -555,7 +543,7 @@ static int hash_mb_check_param(struct hash_mb_queue *mb_queue, struct wd_digest_
return WD_SUCCESS;
}
-static int hash_mb_send(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg)
+static int hash_mb_send(handle_t ctx, void *drv_msg)
{
struct wd_soft_ctx *s_ctx = (struct wd_soft_ctx *)ctx;
struct hash_mb_queue *mb_queue = s_ctx->priv;
@@ -776,7 +764,7 @@ static int hash_mb_do_jobs(struct hash_mb_queue *mb_queue)
return WD_SUCCESS;
}
-static int hash_mb_recv(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg)
+static int hash_mb_recv(handle_t ctx, void *drv_msg)
{
struct wd_soft_ctx *s_ctx = (struct wd_soft_ctx *)ctx;
struct hash_mb_queue *mb_queue = s_ctx->priv;
@@ -810,6 +798,7 @@ static int hash_mb_get_usage(void *param)
.alg_name = (hash_alg_name),\
.calc_type = UADK_ALG_SVE_INSTR,\
.priority = 100,\
+ .priv_size = sizeof(struct hash_mb_ctx),\
.queue_num = 1,\
.op_type_num = 1,\
.fallback = 0,\
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index a6b2947..be16b83 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -1414,11 +1414,11 @@ static void hisi_zip_sqe_ops_adapt(handle_t h_qp)
}
}
-static int hisi_zip_init(struct wd_alg_driver *drv, void *conf)
+static int hisi_zip_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_zip_ctx *zip_ctx = (struct hisi_zip_ctx *)priv;
struct hisi_qm_priv qm_priv;
- struct hisi_zip_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -1428,11 +1428,7 @@ static int hisi_zip_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_zip_ctx));
- if (!priv)
- return -WD_EINVAL;
-
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
+ memcpy(&zip_ctx->config, config, sizeof(struct wd_ctx_config_internal));
/* allocate qp for each context */
for (i = 0; i < config->ctx_num; i++) {
h_ctx = config->ctxs[i].ctx;
@@ -1450,7 +1446,6 @@ static int hisi_zip_init(struct wd_alg_driver *drv, void *conf)
}
hisi_zip_sqe_ops_adapt(h_qp);
- drv->priv = priv;
return 0;
out:
@@ -1458,28 +1453,20 @@ out:
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[j].ctx);
hisi_qm_free_qp(h_qp);
}
- free(priv);
return -WD_EINVAL;
}
-static void hisi_zip_exit(struct wd_alg_driver *drv)
+static void hisi_zip_exit(void *priv)
{
- struct wd_ctx_config_internal *config;
- struct hisi_zip_ctx *priv;
+ struct hisi_zip_ctx *zip_ctx = (struct hisi_zip_ctx *)priv;
+ struct wd_ctx_config_internal *config = &zip_ctx->config;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
- return;
-
- priv = (struct hisi_zip_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);
hisi_qm_free_qp(h_qp);
}
- free(priv);
- drv->priv = NULL;
}
static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
@@ -1534,7 +1521,7 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
return 0;
}
-static int hisi_zip_comp_send(struct wd_alg_driver *drv, handle_t ctx, void *comp_msg)
+static int hisi_zip_comp_send(handle_t ctx, void *comp_msg)
{
struct hisi_qp *qp = wd_ctx_get_priv(ctx);
struct wd_comp_msg *msg = comp_msg;
@@ -1722,7 +1709,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
return 0;
}
-static int hisi_zip_comp_recv(struct wd_alg_driver *drv, handle_t ctx, void *comp_msg)
+static int hisi_zip_comp_recv(handle_t ctx, void *comp_msg)
{
struct hisi_qp *qp = wd_ctx_get_priv(ctx);
struct wd_comp_msg *recv_msg = comp_msg;
@@ -1775,7 +1762,7 @@ static int hisi_zip_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_zip_ctx *)drv->priv;
+ priv = (struct hisi_zip_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
@@ -1803,6 +1790,7 @@ static int hisi_zip_get_usage(void *param)
.alg_name = (zip_alg_name),\
.calc_type = UADK_ALG_HW,\
.priority = 100,\
+ .priv_size = sizeof(struct hisi_zip_ctx),\
.queue_num = ZIP_CTX_Q_NUM_DEF,\
.op_type_num = 2,\
.fallback = 0,\
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index d86b9f6..4a1ac89 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -426,7 +426,7 @@ static int check_hashagg_param(struct wd_agg_msg *msg)
return WD_SUCCESS;
}
-static int hashagg_send(struct wd_alg_driver *drv, handle_t ctx, void *hashagg_msg)
+static int hashagg_send(handle_t ctx, void *hashagg_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -563,7 +563,7 @@ static void fill_hashagg_msg_task_err(struct dae_sqe *sqe, struct wd_agg_msg *ms
}
}
-static int hashagg_recv(struct wd_alg_driver *drv, handle_t ctx, void *hashagg_msg)
+static int hashagg_recv(handle_t ctx, void *hashagg_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -1214,17 +1214,11 @@ static void hashagg_sess_priv_uninit(struct wd_alg_driver *drv, void *priv)
free(agg_ctx);
}
-static int hashagg_sess_priv_init(struct wd_alg_driver *drv,
- struct wd_agg_sess_setup *setup, void **priv)
+static int hashagg_sess_priv_init(struct wd_agg_sess_setup *setup, void **priv)
{
struct hashagg_ctx *agg_ctx;
int ret;
- if (!drv || !drv->priv) {
- WD_ERR("invalid: dae drv is NULL!\n");
- return -WD_EINVAL;
- }
-
if (!setup || !priv) {
WD_ERR("invalid: dae sess priv is NULL!\n");
return -WD_EINVAL;
@@ -1297,6 +1291,7 @@ static struct wd_alg_driver hashagg_driver = {
.alg_name = "hashagg",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_dae_ctx),
.queue_num = DAE_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
diff --git a/drv/hisi_dae.h b/drv/hisi_dae.h
index f82b13c..f8888b6 100644
--- a/drv/hisi_dae.h
+++ b/drv/hisi_dae.h
@@ -210,8 +210,8 @@ struct hisi_dae_ctx {
struct wd_ctx_config_internal config;
};
-void dae_exit(struct wd_alg_driver *drv);
-int dae_init(struct wd_alg_driver *drv, void *conf);
+void dae_exit(void *priv);
+int dae_init(void *conf, void *priv);
int dae_hash_table_init(struct hash_table_data *hw_table,
struct hash_table_data *rehash_table,
struct wd_dae_hash_table *hash_table,
diff --git a/drv/hisi_dae_common.c b/drv/hisi_dae_common.c
index c077d1d..216e424 100644
--- a/drv/hisi_dae_common.c
+++ b/drv/hisi_dae_common.c
@@ -308,11 +308,11 @@ update_table:
return ret;
}
-int dae_init(struct wd_alg_driver *drv, void *conf)
+int dae_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_dae_ctx *dae_ctx = priv;
struct hisi_qm_priv qm_priv;
- struct hisi_dae_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -323,10 +323,6 @@ int dae_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_dae_ctx));
- if (!priv)
- return -WD_ENOMEM;
-
qm_priv.op_type = DAE_SQC_ALG_TYPE;
qm_priv.sqe_size = sizeof(struct dae_sqe);
/* Allocate qp for each context */
@@ -347,8 +343,7 @@ int dae_init(struct wd_alg_driver *drv, void *conf)
if (ret)
goto free_h_qp;
}
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&dae_ctx->config, config, sizeof(struct wd_ctx_config_internal));
return WD_SUCCESS;
@@ -362,22 +357,22 @@ out:
hisi_qm_free_qp(h_qp);
}
}
- free(priv);
return ret;
}
-void dae_exit(struct wd_alg_driver *drv)
+void dae_exit(void *priv)
{
struct wd_ctx_config_internal *config;
- struct hisi_dae_ctx *priv;
+ struct hisi_dae_ctx *dae_ctx = priv;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
+ if (!priv) {
+ WD_ERR("invalid: input parameter is NULL!\n");
return;
+ }
- priv = (struct hisi_dae_ctx *)drv->priv;
- config = &priv->config;
+ config = &dae_ctx->config;
for (i = 0; i < config->ctx_num; i++) {
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
if (h_qp) {
@@ -385,9 +380,6 @@ void dae_exit(struct wd_alg_driver *drv)
hisi_qm_free_qp(h_qp);
}
}
-
- free(priv);
- drv->priv = NULL;
}
int dae_get_usage(void *param)
@@ -406,7 +398,7 @@ int dae_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_dae_ctx *)drv->priv;
+ priv = (struct hisi_dae_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
diff --git a/drv/hisi_dae_join_gather.c b/drv/hisi_dae_join_gather.c
index 8c45f57..43ed539 100644
--- a/drv/hisi_dae_join_gather.c
+++ b/drv/hisi_dae_join_gather.c
@@ -455,7 +455,7 @@ static int check_join_gather_param(struct wd_join_gather_msg *msg)
return WD_SUCCESS;
}
-static int join_gather_send(struct wd_alg_driver *drv, handle_t ctx, void *send_msg)
+static int join_gather_send(handle_t ctx, void *send_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -540,7 +540,7 @@ static void fill_join_gather_task_err(struct dae_sqe *sqe, struct wd_join_gather
}
}
-static int join_gather_recv(struct wd_alg_driver *drv, handle_t hctx, void *recv_msg)
+static int join_gather_recv(handle_t hctx, void *recv_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(hctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -892,7 +892,7 @@ static int join_gather_fill_ctx(struct join_gather_ctx *ctx,
return WD_SUCCESS;
}
-static void join_gather_sess_priv_uninit(struct wd_alg_driver *drv, void *priv)
+static void join_gather_sess_priv_uninit(void *priv)
{
struct join_gather_ctx *ctx = priv;
@@ -904,17 +904,11 @@ static void join_gather_sess_priv_uninit(struct wd_alg_driver *drv, void *priv)
free(ctx);
}
-static int join_gather_sess_priv_init(struct wd_alg_driver *drv,
- struct wd_join_gather_sess_setup *setup, void **priv)
+static int join_gather_sess_priv_init(struct wd_join_gather_sess_setup *setup, void **priv)
{
struct join_gather_ctx *ctx;
int ret;
- if (!drv || !drv->priv) {
- WD_ERR("invalid: dae drv is NULL!\n");
- return -WD_EINVAL;
- }
-
if (!setup || !priv) {
WD_ERR("invalid: dae sess priv is NULL!\n");
return -WD_EINVAL;
@@ -941,7 +935,7 @@ free_ctx:
return ret;
}
-static int join_get_table_row_size(struct wd_alg_driver *drv, void *param)
+static int join_get_table_row_size(void *param)
{
struct join_gather_ctx *ctx = param;
@@ -951,7 +945,7 @@ static int join_get_table_row_size(struct wd_alg_driver *drv, void *param)
return ctx->hash_table_row_size;
}
-static int gather_get_batch_row_size(struct wd_alg_driver *drv, void *param,
+static int gather_get_batch_row_size(void *param,
__u32 *row_size, __u32 size)
{
struct join_gather_ctx *ctx = param;
@@ -967,8 +961,7 @@ static int gather_get_batch_row_size(struct wd_alg_driver *drv, void *param,
return 0;
}
-static int join_hash_table_init(struct wd_alg_driver *drv,
- struct wd_dae_hash_table *table, void *priv)
+static int join_hash_table_init(struct wd_dae_hash_table *table, void *priv)
{
struct join_gather_ctx *ctx = priv;
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 3c41826..7da8407 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -680,11 +680,11 @@ out:
return -WD_EINVAL;
}
-static int hpre_rsa_dh_init(struct wd_alg_driver *drv, void *conf)
+static int hpre_rsa_dh_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
struct hisi_qm_priv qm_priv;
- struct hisi_hpre_ctx *priv;
int ret;
if (!config->ctx_num) {
@@ -692,27 +692,19 @@ static int hpre_rsa_dh_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_hpre_ctx));
- if (!priv)
- return -WD_EINVAL;
-
qm_priv.op_type = HPRE_HW_V2_ALG_TYPE;
- ret = hpre_init_qm_priv(config, priv, &qm_priv);
- if (ret) {
- free(priv);
+ ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv);
+ if (ret)
return ret;
- }
-
- drv->priv = priv;
return WD_SUCCESS;
}
-static int hpre_ecc_init(struct wd_alg_driver *drv, void *conf)
+static int hpre_ecc_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
struct hisi_qm_priv qm_priv;
- struct hisi_hpre_ctx *priv;
int ret;
if (!config->ctx_num) {
@@ -720,44 +712,28 @@ static int hpre_ecc_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_hpre_ctx));
- if (!priv)
- return -WD_EINVAL;
-
qm_priv.op_type = HPRE_HW_V3_ECC_ALG_TYPE;
- ret = hpre_init_qm_priv(config, priv, &qm_priv);
- if (ret) {
- free(priv);
+ ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv);
+ if (ret)
return ret;
- }
-
- drv->priv = priv;
return WD_SUCCESS;
}
-static void hpre_exit(struct wd_alg_driver *drv)
+static void hpre_exit(void *priv)
{
- struct wd_ctx_config_internal *config;
- struct hisi_hpre_ctx *priv;
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
+ struct wd_ctx_config_internal *config = &hpre_ctx->config;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
- return;
-
- priv = (struct hisi_hpre_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);
hisi_qm_free_qp(h_qp);
}
-
- free(priv);
- drv->priv = NULL;
}
-static int rsa_send(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
+static int rsa_send(handle_t ctx, void *rsa_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_rsa_msg *msg = rsa_msg;
@@ -829,7 +805,7 @@ static void hpre_result_check(struct hisi_hpre_sqe *hw_msg,
}
}
-static int rsa_recv(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
+static int rsa_recv(handle_t ctx, void *rsa_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -949,7 +925,7 @@ static int dh_out_transfer(struct wd_dh_msg *msg, struct hisi_hpre_sqe *hw_msg,
return WD_SUCCESS;
}
-static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
+static int dh_send(handle_t ctx, void *dh_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct map_info_cache cache = {0};
@@ -1020,7 +996,7 @@ dh_fail:
return ret;
}
-static int dh_recv(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
+static int dh_recv(handle_t ctx, void *dh_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -2147,7 +2123,7 @@ free_dst:
return ret;
}
-static int ecc_send(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
+static int ecc_send(handle_t ctx, void *ecc_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_ecc_msg *msg = ecc_msg;
@@ -2743,7 +2719,7 @@ fail:
return ret;
}
-static int ecc_recv(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
+static int ecc_recv(handle_t ctx, void *ecc_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_ecc_msg *msg = ecc_msg;
@@ -2786,7 +2762,7 @@ static handle_t hpre_find_dev_qp(struct wd_alg_driver *drv, const char *dev_name
handle_t qp = 0;
__u32 i;
- priv = (struct hisi_hpre_ctx *)drv->priv;
+ priv = (struct hisi_hpre_ctx *)drv->drv_data;
if (!priv)
return 0;
@@ -2874,31 +2850,30 @@ static void ecc_sess_eops_uninit(struct wd_alg_driver *drv, void *params)
free(params);
}
-static bool is_valid_hw_type(struct wd_alg_driver *drv)
+static bool is_valid_hw_type(void *drv_priv)
{
struct hisi_hpre_ctx *hpre_ctx;
struct hisi_qp *qp;
- if (unlikely(!drv || !drv->priv))
+ if (unlikely(!drv_priv))
return false;
- hpre_ctx = (struct hisi_hpre_ctx *)drv->priv;
+ hpre_ctx = (struct hisi_hpre_ctx *)drv_priv;
qp = (struct hisi_qp *)wd_ctx_get_priv(hpre_ctx->config.ctxs[0].ctx);
if (!qp || qp->q_info.hw_type < HISI_QM_API_VER3_BASE)
return false;
return true;
}
-static void ecc_sess_eops_params_cfg(struct wd_alg_driver *drv,
- struct wd_ecc_sess_setup *setup,
- struct wd_ecc_curve *cv, void *params)
+static void ecc_sess_eops_params_cfg(struct wd_ecc_sess_setup *setup,
+ struct wd_ecc_curve *cv, void *drv_priv, void *params)
{
__u8 data[SECP256R1_PARAM_SIZE] = SECG_P256_R1_PARAM;
struct hpre_ecc_ctx *ecc_ctx = params;
__u32 key_size;
int ret;
- if (!is_valid_hw_type(drv))
+ if (!is_valid_hw_type(drv_priv))
return;
if (!ecc_ctx) {
@@ -2938,6 +2913,7 @@ static int hpre_ecc_get_extend_ops(void *ops)
.alg_name = (hpre_alg_name),\
.calc_type = UADK_ALG_HW,\
.priority = 100,\
+ .priv_size = sizeof(struct hisi_hpre_ctx),\
.queue_num = HPRE_CTX_Q_NUM_DEF,\
.op_type_num = 1,\
.fallback = 0,\
@@ -2962,6 +2938,7 @@ static struct wd_alg_driver hpre_rsa_driver = {
.alg_name = "rsa",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_hpre_ctx),
.queue_num = HPRE_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
@@ -2977,6 +2954,7 @@ static struct wd_alg_driver hpre_dh_driver = {
.alg_name = "dh",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_hpre_ctx),
.queue_num = HPRE_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index c8b831c..fb9de2c 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -526,76 +526,76 @@ static __u32 g_sec_hmac_full_len[WD_DIGEST_TYPE_MAX] = {
SEC_HMAC_SHA512_MAC_LEN, SEC_HMAC_SHA512_224_MAC_LEN, SEC_HMAC_SHA512_256_MAC_LEN
};
-static int hisi_sec_init(struct wd_alg_driver *drv, void *conf);
-static void hisi_sec_exit(struct wd_alg_driver *drv);
+static int hisi_sec_init(void *conf, void *priv);
+static void hisi_sec_exit(void *priv);
-static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_send(handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_recv(handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_send_v3(handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_recv_v3(handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_send(handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_recv(handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_send_v3(handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_recv_v3(handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_send(handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_recv(handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_send_v3(handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_recv_v3(handle_t ctx, void *wd_msg);
-static int cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_send(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_cipher_send(drv, ctx, msg);
- return hisi_sec_cipher_send_v3(drv, ctx, msg);
+ return hisi_sec_cipher_send(ctx, msg);
+ return hisi_sec_cipher_send_v3(ctx, msg);
}
-static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_recv(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_cipher_recv(drv, ctx, msg);
- return hisi_sec_cipher_recv_v3(drv, ctx, msg);
+ return hisi_sec_cipher_recv(ctx, msg);
+ return hisi_sec_cipher_recv_v3(ctx, msg);
}
-static int digest_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int digest_send(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_digest_send(drv, ctx, msg);
- return hisi_sec_digest_send_v3(drv, ctx, msg);
+ return hisi_sec_digest_send(ctx, msg);
+ return hisi_sec_digest_send_v3(ctx, msg);
}
-static int digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int digest_recv(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_digest_recv(drv, ctx, msg);
- return hisi_sec_digest_recv_v3(drv, ctx, msg);
+ return hisi_sec_digest_recv(ctx, msg);
+ return hisi_sec_digest_recv_v3(ctx, msg);
}
-static int aead_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int aead_send(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_aead_send(drv, ctx, msg);
- return hisi_sec_aead_send_v3(drv, ctx, msg);
+ return hisi_sec_aead_send(ctx, msg);
+ return hisi_sec_aead_send_v3(ctx, msg);
}
-static int aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int aead_recv(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_aead_recv(drv, ctx, msg);
- return hisi_sec_aead_recv_v3(drv, ctx, msg);
+ return hisi_sec_aead_recv(ctx, msg);
+ return hisi_sec_aead_recv_v3(ctx, msg);
}
static int hisi_sec_get_usage(void *param)
@@ -614,7 +614,7 @@ static int hisi_sec_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_sec_ctx *)drv->priv;
+ priv = (struct hisi_sec_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
@@ -638,8 +638,8 @@ static int hisi_sec_get_usage(void *param)
static int eops_param_check(struct wd_alg_driver *drv, struct wd_mm_ops *mm_ops)
{
- if (!drv || !drv->priv) {
- WD_ERR("invalid: aead drv or priv is NULL!\n");
+ if (!drv || !drv->drv_data) {
+ WD_ERR("invalid: aead drv or data is NULL!\n");
return -WD_EINVAL;
}
@@ -680,7 +680,7 @@ static int aead_sess_eops_init(struct wd_alg_driver *drv,
return -WD_ENOMEM;
}
- sec_ctx = (struct hisi_sec_ctx *)drv->priv;
+ sec_ctx = (struct hisi_sec_ctx *)drv->drv_data;
qp = (struct hisi_qp *)wd_ctx_get_priv(sec_ctx->config.ctxs[0].ctx);
sq_depth = qp->q_info.sq_depth;
aiv_addr->aiv = mm_ops->alloc(mm_ops->usr, (__u32)sq_depth << AEAD_AIV_OFFSET);
@@ -735,7 +735,7 @@ static void aead_sess_eops_uninit(struct wd_alg_driver *drv,
return;
}
- sec_ctx = (struct hisi_sec_ctx *)drv->priv;
+ sec_ctx = (struct hisi_sec_ctx *)drv->drv_data;
qp = (struct hisi_qp *)wd_ctx_get_priv(sec_ctx->config.ctxs[0].ctx);
sq_depth = qp->q_info.sq_depth;
@@ -793,6 +793,7 @@ static int sec_aead_get_extend_ops(void *ops)
.alg_name = (sec_alg_name),\
.calc_type = UADK_ALG_HW,\
.priority = 100,\
+ .priv_size = sizeof(struct hisi_sec_ctx),\
.queue_num = SEC_CTX_Q_NUM_DEF,\
.op_type_num = 1,\
.fallback = 0,\
@@ -1400,7 +1401,7 @@ static int fill_cipher_bd2(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe)
return 0;
}
-static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_cipher_send(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_cipher_msg *msg = wd_msg;
@@ -1456,7 +1457,7 @@ static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *w
return 0;
}
-static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_cipher_recv(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_cipher_msg *recv_msg = wd_msg;
@@ -1693,7 +1694,7 @@ static void fill_sec_prefetch(__u8 data_fmt, __u32 len, __u16 hw_type, struct hi
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)
+static int hisi_sec_cipher_send_v3(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;
@@ -1800,7 +1801,7 @@ static void parse_cipher_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
dump_sec_msg(temp_msg, "cipher");
}
-static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_cipher_recv_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_cipher_msg *recv_msg = wd_msg;
@@ -2132,7 +2133,7 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
return 0;
}
-static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_digest_send(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_digest_msg *msg = wd_msg;
@@ -2209,7 +2210,7 @@ put_sgl:
return ret;
}
-static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_digest_recv(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_digest_msg *recv_msg = wd_msg;
@@ -2473,7 +2474,7 @@ map_err:
return -WD_ENOMEM;
}
-static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_digest_send_v3(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;
@@ -2587,7 +2588,7 @@ static void parse_digest_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
dump_sec_msg(temp_msg, "digest");
}
-static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_digest_recv_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_digest_msg *recv_msg = wd_msg;
@@ -3216,7 +3217,7 @@ static int fill_aead_bd2_addr(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe,
return aead_mem_nosva_map(msg, sqe, idx);
}
-static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_aead_send(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;
@@ -3347,7 +3348,7 @@ static void parse_aead_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe,
dump_sec_msg(temp_msg, "aead");
}
-static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_aead_recv(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_aead_msg *recv_msg = wd_msg;
@@ -3744,7 +3745,7 @@ static int fill_aead_bd3_addr(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe
return aead_mem_nosva_map_v3(msg, sqe, idx);
}
-static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_aead_send_v3(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;
@@ -3863,7 +3864,7 @@ static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
dump_sec_msg(temp_msg, "aead");
}
-static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_aead_recv_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_aead_msg *recv_msg = wd_msg;
@@ -3888,11 +3889,11 @@ static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *
return 0;
}
-static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
+static int hisi_sec_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_sec_ctx *sec_ctx = priv;
struct hisi_qm_priv qm_priv;
- struct hisi_sec_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -3902,10 +3903,6 @@ static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_sec_ctx));
- if (!priv)
- return -WD_EINVAL;
-
qm_priv.sqe_size = sizeof(struct hisi_sec_sqe);
/* allocate qp for each context */
for (i = 0; i < config->ctx_num; i++) {
@@ -3922,8 +3919,7 @@ static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
goto out;
config->ctxs[i].sqn = qm_priv.sqn;
}
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&sec_ctx->config, config, sizeof(struct wd_ctx_config_internal));
return 0;
@@ -3936,25 +3932,24 @@ out:
return -WD_EINVAL;
}
-static void hisi_sec_exit(struct wd_alg_driver *drv)
+static void hisi_sec_exit(void *priv)
{
struct wd_ctx_config_internal *config;
- struct hisi_sec_ctx *priv;
+ struct hisi_sec_ctx *sec_ctx = priv;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
+ if (!priv) {
+ WD_ERR("invalid: input parameter is NULL!\n");
return;
+ }
- priv = (struct hisi_sec_ctx *)drv->priv;
- config = &priv->config;
+ config = &sec_ctx->config;
for (i = 0; i < config->ctx_num; i++) {
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
hisi_qm_free_qp(h_qp);
}
- free(priv);
- drv->priv = NULL;
}
#ifdef WD_STATIC_DRV
diff --git a/drv/hisi_udma.c b/drv/hisi_udma.c
index a9f5607..5c8a743 100644
--- a/drv/hisi_udma.c
+++ b/drv/hisi_udma.c
@@ -290,7 +290,7 @@ static void fill_init_value(struct udma_sqe *sqe, struct wd_udma_msg *msg)
memset(&sqe->init_val, msg->value, sizeof(__u64));
}
-static int udma_send(struct wd_alg_driver *drv, handle_t ctx, void *udma_msg)
+static int udma_send(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;
@@ -342,7 +342,7 @@ static void dump_udma_msg(struct udma_sqe *sqe, struct wd_udma_msg *msg)
"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)
+static int udma_recv(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;
@@ -442,11 +442,11 @@ free_inter_addr:
return ret;
}
-static int udma_init(struct wd_alg_driver *drv, void *conf)
+static int udma_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_udma_ctx *uctx = priv;
struct hisi_qm_priv qm_priv;
- struct hisi_udma_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -457,10 +457,6 @@ static int udma_init(struct wd_alg_driver *drv, void *conf)
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 */
@@ -481,8 +477,7 @@ static int udma_init(struct wd_alg_driver *drv, void *conf)
if (ret)
goto free_h_qp;
}
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&uctx->config, config, sizeof(struct wd_ctx_config_internal));
return WD_SUCCESS;
free_h_qp:
@@ -493,30 +488,26 @@ out:
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)
+static void udma_exit(void *priv)
{
struct wd_ctx_config_internal *config;
- struct hisi_udma_ctx *priv;
+ struct hisi_udma_ctx *uctx = priv;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
+ if (!priv)
return;
- priv = (struct hisi_udma_ctx *)drv->priv;
- config = &priv->config;
+ config = &uctx->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)
@@ -535,7 +526,7 @@ static int udma_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_udma_ctx *)drv->priv;
+ priv = (struct hisi_udma_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
@@ -562,6 +553,7 @@ static struct wd_alg_driver udma_driver = {
.alg_name = "udma",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_udma_ctx),
.queue_num = UDMA_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
diff --git a/drv/isa_ce_sm3.c b/drv/isa_ce_sm3.c
index 8d23061..0ebaba5 100644
--- a/drv/isa_ce_sm3.c
+++ b/drv/isa_ce_sm3.c
@@ -24,10 +24,10 @@
typedef void (sm3_ce_block_fn)(__u32 word_reg[SM3_STATE_WORDS],
const unsigned char *src, size_t blocks);
-static int sm3_ce_drv_init(struct wd_alg_driver *drv, void *conf);
-static void sm3_ce_drv_exit(struct wd_alg_driver *drv);
-static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg);
-static int sm3_ce_drv_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg);
+static int sm3_ce_drv_init(void *conf, void *priv);
+static void sm3_ce_drv_exit(void *priv);
+static int sm3_ce_drv_send(handle_t ctx, void *digest_msg);
+static int sm3_ce_drv_recv(handle_t ctx, void *digest_msg);
static int sm3_ce_get_usage(void *param);
static struct wd_alg_driver sm3_ce_alg_driver = {
@@ -35,6 +35,7 @@ static struct wd_alg_driver sm3_ce_alg_driver = {
.alg_name = "sm3",
.calc_type = UADK_ALG_CE_INSTR,
.priority = 200,
+ .priv_size = sizeof(struct sm3_ce_drv_ctx),
.queue_num = 1,
.op_type_num = 1,
.fallback = 0,
@@ -335,7 +336,7 @@ static int do_hmac_sm3_ce(struct wd_digest_msg *msg, __u8 *out_hmac)
return WD_SUCCESS;
}
-static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
+static int sm3_ce_drv_send(handle_t ctx, void *digest_msg)
{
struct wd_digest_msg *msg = (struct wd_digest_msg *)digest_msg;
__u8 digest[SM3_DIGEST_SIZE] = {0};
@@ -370,39 +371,26 @@ static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest
return ret;
}
-static int sm3_ce_drv_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
+static int sm3_ce_drv_recv(handle_t ctx, void *digest_msg)
{
return WD_SUCCESS;
}
-static int sm3_ce_drv_init(struct wd_alg_driver *drv, void *conf)
+static int sm3_ce_drv_init(void *conf, void *priv)
{
- struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
- struct sm3_ce_drv_ctx *priv;
+ struct wd_ctx_config_internal *config = conf;
+ struct sm3_ce_drv_ctx *sctx = priv;
/* Fallback init is NULL */
- if (!drv || !conf)
+ if (!conf || !conf)
return 0;
- priv = malloc(sizeof(struct sm3_ce_drv_ctx));
- if (!priv)
- return -WD_ENOMEM;
-
config->epoll_en = 0;
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&sctx->config, config, sizeof(struct wd_ctx_config_internal));
return WD_SUCCESS;
}
-static void sm3_ce_drv_exit(struct wd_alg_driver *drv)
+static void sm3_ce_drv_exit(void *priv)
{
- struct sm3_ce_drv_ctx *sctx;
-
- if (!drv || !drv->priv)
- return;
-
- sctx = (struct sm3_ce_drv_ctx *)drv->priv;
- free(sctx);
- drv->priv = NULL;
}
diff --git a/drv/isa_ce_sm4.c b/drv/isa_ce_sm4.c
index 52dca1f..504ef73 100644
--- a/drv/isa_ce_sm4.c
+++ b/drv/isa_ce_sm4.c
@@ -11,9 +11,10 @@
* Copyright 2024 Huawei Technologies Co.,Ltd. All rights reserved.
*/
+#include "wd_alg.h"
#include "drv/wd_cipher_drv.h"
-#include "wd_cipher.h"
#include "isa_ce_sm4.h"
+#include "wd_cipher.h"
#define SM4_ENCRYPT 1
#define SM4_DECRYPT 0
@@ -31,36 +32,23 @@
((p)[0] = (__u8)((v) >> 24), (p)[1] = (__u8)((v) >> 16), \
(p)[2] = (__u8)((v) >> 8), (p)[3] = (__u8)(v))
-static int isa_ce_init(struct wd_alg_driver *drv, void *conf)
+static int isa_ce_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
- struct sm4_ce_drv_ctx *priv;
+ struct sm4_ce_drv_ctx *sctx = priv;
/* Fallback init is NULL */
- if (!drv || !conf)
+ if (!conf || !priv)
return 0;
- priv = malloc(sizeof(struct sm4_ce_drv_ctx));
- if (!priv)
- return -WD_EINVAL;
-
config->epoll_en = 0;
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&sctx->config, config, sizeof(struct wd_ctx_config_internal));
- return WD_SUCCESS;
+ return 0;
}
-static void isa_ce_exit(struct wd_alg_driver *drv)
+static void isa_ce_exit(void *priv)
{
- struct sm4_ce_drv_ctx *sctx;
-
- if (!drv || !drv->priv)
- return;
-
- sctx = (struct sm4_ce_drv_ctx *)drv->priv;
- free(sctx);
- drv->priv = NULL;
}
/* increment upper 96 bits of 128-bit counter by 1 */
@@ -334,7 +322,7 @@ static int sm4_xts_decrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rkey
return 0;
}
-static int isa_ce_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int isa_ce_cipher_send(handle_t ctx, void *wd_msg)
{
struct wd_cipher_msg *msg = wd_msg;
struct SM4_KEY rkey;
@@ -400,19 +388,19 @@ static int isa_ce_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_
return ret;
}
-static int isa_ce_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int isa_ce_cipher_recv(handle_t ctx, void *wd_msg)
{
return 0;
}
-static int cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_send(handle_t ctx, void *msg)
{
- return isa_ce_cipher_send(drv, ctx, msg);
+ return isa_ce_cipher_send(ctx, msg);
}
-static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_recv(handle_t ctx, void *msg)
{
- return isa_ce_cipher_recv(drv, ctx, msg);
+ return isa_ce_cipher_recv(ctx, msg);
}
#define GEN_CE_ALG_DRIVER(ce_alg_name, alg_type) \
@@ -421,6 +409,7 @@ static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
.alg_name = (ce_alg_name),\
.calc_type = UADK_ALG_CE_INSTR,\
.priority = 200,\
+ .priv_size = sizeof(struct sm4_ce_drv_ctx),\
.op_type_num = 1,\
.fallback = 0,\
.init = isa_ce_init,\
diff --git a/include/drv/wd_agg_drv.h b/include/drv/wd_agg_drv.h
index b26b25d..8952ee9 100644
--- a/include/drv/wd_agg_drv.h
+++ b/include/drv/wd_agg_drv.h
@@ -43,8 +43,7 @@ struct wd_agg_msg {
struct wd_agg_ops {
int (*get_row_size)(struct wd_alg_driver *drv, void *priv);
- int (*sess_init)(struct wd_alg_driver *drv,
- struct wd_agg_sess_setup *setup, void **priv);
+ int (*sess_init)(struct wd_agg_sess_setup *setup, void **priv);
void (*sess_uninit)(struct wd_alg_driver *drv, void *priv);
int (*hash_table_init)(struct wd_alg_driver *drv,
struct wd_dae_hash_table *hash_table, void *priv);
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index 48c422f..98ff28c 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -181,9 +181,8 @@ struct wd_ecc_out {
struct wd_ecc_extend_ops {
void *params; /* the params are passed to the following ops */
- void (*eops_params_cfg)(struct wd_alg_driver *drv,
- struct wd_ecc_sess_setup *setup,
- struct wd_ecc_curve *cv, void *params);
+ void (*eops_params_cfg)(struct wd_ecc_sess_setup *setup,
+ struct wd_ecc_curve *cv, void *drv_priv, void *params);
int (*sess_init)(struct wd_alg_driver *drv, void **params);
void (*sess_uninit)(struct wd_alg_driver *drv, void *params);
};
diff --git a/include/drv/wd_join_gather_drv.h b/include/drv/wd_join_gather_drv.h
index dbf4ee7..d7f136d 100644
--- a/include/drv/wd_join_gather_drv.h
+++ b/include/drv/wd_join_gather_drv.h
@@ -33,14 +33,12 @@ struct wd_join_gather_msg {
};
struct wd_join_gather_ops {
- int (*get_table_row_size)(struct wd_alg_driver *drv, void *priv);
- int (*get_batch_row_size)(struct wd_alg_driver *drv, void *priv,
+ int (*get_table_row_size)(void *priv);
+ int (*get_batch_row_size)(void *priv,
__u32 *batch_row_size, __u32 size);
- int (*sess_init)(struct wd_alg_driver *drv,
- struct wd_join_gather_sess_setup *setup, void **priv);
- void (*sess_uninit)(struct wd_alg_driver *drv, void *priv);
- int (*hash_table_init)(struct wd_alg_driver *drv,
- struct wd_dae_hash_table *hash_table, void *priv);
+ int (*sess_init)(struct wd_join_gather_sess_setup *setup, void **priv);
+ void (*sess_uninit)(void *priv);
+ int (*hash_table_init)(struct wd_dae_hash_table *hash_table, void *priv);
};
struct wd_join_gather_msg *wd_join_gather_get_msg(__u32 idx, __u32 tag);
diff --git a/include/wd_alg.h b/include/wd_alg.h
index 18503ca..885a5e3 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -19,6 +19,7 @@ extern "C" {
#define handle_t uintptr_t
#define ALG_NAME_SIZE 128
#define DEV_NAME_LEN 128
+typedef unsigned char __u8;
/*
* Macros related to arm platform:
@@ -85,7 +86,8 @@ enum alg_dev_type {
* execute the algorithm task
* @op_type_num: number of modes in which the device executes the
* algorithm business and requires queues to be executed separately
- * @priv: pointer of priv ctx
+ * @priv_size: parameter memory size passed between the internal
+ * interfaces of the driver
* @fallback: soft calculation driver handle when performing soft
* calculation supplement
* @init: callback interface for initializing device drivers
@@ -105,13 +107,14 @@ struct wd_alg_driver {
int calc_type;
int queue_num;
int op_type_num;
- void *priv;
+ int priv_size;
+ int *drv_data;
handle_t fallback;
- int (*init)(struct wd_alg_driver *drv, void *conf);
- void (*exit)(struct wd_alg_driver *drv);
- int (*send)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
- int (*recv)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
+ int (*init)(void *conf, void *priv);
+ void (*exit)(void *priv);
+ int (*send)(handle_t ctx, void *drv_msg);
+ int (*recv)(handle_t ctx, void *drv_msg);
int (*get_usage)(void *param);
int (*get_extend_ops)(void *ops);
};
@@ -182,10 +185,6 @@ bool wd_drv_alg_support(const char *alg_name,
void wd_enable_drv(struct wd_alg_driver *drv);
void wd_disable_drv(struct wd_alg_driver *drv);
-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);
diff --git a/include/wd_util.h b/include/wd_util.h
index 2abceec..14985e2 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -120,8 +120,8 @@ struct wd_ctx_attr {
};
struct wd_msg_handle {
- int (*send)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
- int (*recv)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
+ int (*send)(handle_t sess, void *msg);
+ int (*recv)(handle_t sess, void *msg);
};
struct wd_init_attrs {
@@ -378,7 +378,6 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en);
/**
* wd_handle_msg_sync() - recv msg from hardware
- * @drv: the driver to handle msg.
* @msg_handle: callback of msg handle ops.
* @ctx: the handle of context.
* @msg: the msg of task.
@@ -387,8 +386,8 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en);
*
* Return 0 if successful or less than 0 otherwise.
*/
-int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_handle,
- handle_t ctx, void *msg, __u64 *balance, bool epoll_en);
+int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx,
+ void *msg, __u64 *balance, bool epoll_en);
/**
* wd_init_check() - Check input parameters for wd_<alg>_init.
@@ -486,13 +485,14 @@ void wd_alg_drv_unbind(struct wd_alg_driver *drv);
* to the obtained queue resource and the applied driver.
* @config: device resources requested by the current algorithm.
* @driver: device driver for the current algorithm application.
+ * @drv_priv: the parameter pointer of the current device driver.
*
* Return 0 if succeed and other error number if fail.
*/
int wd_alg_init_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver);
+ struct wd_alg_driver *driver, void **drv_priv);
void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver);
+ struct wd_alg_driver *driver, void **drv_priv);
/**
* wd_dlopen_drv() - Open the dynamic library file of the device driver.
diff --git a/wd_aead.c b/wd_aead.c
index 8467409..43bda73 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -34,6 +34,7 @@ struct wd_aead_setting {
struct wd_sched sched;
struct wd_alg_driver *driver;
struct wd_async_msg_pool pool;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_aead_setting;
@@ -603,7 +604,8 @@ static int wd_aead_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_aead_setting.config,
- wd_aead_setting.driver);
+ wd_aead_setting.driver,
+ &wd_aead_setting.priv);
if (ret)
goto out_clear_pool;
@@ -652,30 +654,21 @@ out_clear_init:
return ret;
}
-static int wd_aead_uninit_nolock(void)
+static void wd_aead_uninit_nolock(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_aead_setting.status, &status);
- if (status == WD_UNINIT)
- return -WD_EINVAL;
-
wd_uninit_async_request_pool(&wd_aead_setting.pool);
wd_clear_sched(&wd_aead_setting.sched);
wd_alg_uninit_driver(&wd_aead_setting.config,
- wd_aead_setting.driver);
-
- return 0;
+ wd_aead_setting.driver,
+ &wd_aead_setting.priv);
}
void wd_aead_uninit(void)
{
- int ret;
-
- ret = wd_aead_uninit_nolock();
- if (ret)
+ if (!wd_aead_setting.priv)
return;
+ wd_aead_uninit_nolock();
wd_aead_close_driver(WD_TYPE_V1);
wd_alg_clear_init(&wd_aead_setting.status);
}
@@ -781,12 +774,10 @@ out_uninit:
void wd_aead_uninit2(void)
{
- int ret;
-
- ret = wd_aead_uninit_nolock();
- if (ret)
+ if (!wd_aead_setting.priv)
return;
+ wd_aead_uninit_nolock();
wd_alg_attrs_uninit(&wd_aead_init_attrs);
wd_alg_drv_unbind(wd_aead_setting.driver);
wd_aead_close_driver(WD_TYPE_V2);
@@ -875,8 +866,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx,
msg_handle.recv = wd_aead_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_aead_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, wd_aead_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL,
+ wd_aead_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
return ret;
@@ -951,7 +942,7 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req)
fill_request_msg(msg, req, sess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_aead_setting.driver, ctx->ctx, msg);
+ ret = wd_aead_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send BD, hw is err!\n");
@@ -1001,7 +992,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_aead_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_aead_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_agg.c b/wd_agg.c
index 8c54d10..66e9e0f 100644
--- a/wd_agg.c
+++ b/wd_agg.c
@@ -361,7 +361,7 @@ static int wd_agg_init_sess_priv(struct wd_agg_sess *sess, struct wd_agg_sess_se
WD_ERR("failed to get session uninit ops!\n");
return -WD_EINVAL;
}
- ret = sess->ops.sess_init(wd_agg_setting.driver, setup, &sess->priv);
+ ret = sess->ops.sess_init(setup, &sess->priv);
if (ret) {
WD_ERR("failed to init session priv!\n");
return ret;
@@ -595,7 +595,8 @@ static int wd_agg_alg_init(struct wd_ctx_config *config, struct wd_sched *sched)
if (ret < 0)
goto out_clear_sched;
- ret = wd_alg_init_driver(&wd_agg_setting.config, wd_agg_setting.driver);
+ ret = wd_alg_init_driver(&wd_agg_setting.config, wd_agg_setting.driver,
+ &wd_agg_setting.priv);
if (ret)
goto out_clear_pool;
@@ -624,7 +625,8 @@ static int wd_agg_alg_uninit(void)
/* Unset config, sched, driver */
wd_clear_sched(&wd_agg_setting.sched);
- wd_alg_uninit_driver(&wd_agg_setting.config, wd_agg_setting.driver);
+ wd_alg_uninit_driver(&wd_agg_setting.config, wd_agg_setting.driver,
+ &wd_agg_setting.priv);
return WD_SUCCESS;
}
@@ -1101,8 +1103,7 @@ static int wd_agg_sync_job(struct wd_agg_sess *sess, struct wd_agg_req *req,
msg_handle.recv = wd_agg_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_agg_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, config->epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL, config->epoll_en);
pthread_spin_unlock(&ctx->lock);
return ret;
@@ -1203,7 +1204,7 @@ static int wd_agg_async_job(struct wd_agg_sess *sess, struct wd_agg_req *req, bo
else
fill_request_msg_output(msg, req, sess, false);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_agg_setting.driver, ctx->ctx, msg);
+ ret = wd_agg_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("wd agg async send err!\n");
@@ -1542,7 +1543,7 @@ static int wd_agg_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_agg_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_agg_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (unlikely(ret < 0)) {
diff --git a/wd_alg.c b/wd_alg.c
index 1e4f14a..a1a0a79 100644
--- a/wd_alg.c
+++ b/wd_alg.c
@@ -465,26 +465,6 @@ void wd_release_drv(struct wd_alg_driver *drv)
pthread_mutex_unlock(&mutex);
}
-int wd_alg_driver_init(struct wd_alg_driver *drv, void *conf)
-{
- return drv->init(drv, conf);
-}
-
-void wd_alg_driver_exit(struct wd_alg_driver *drv)
-{
- drv->exit(drv);
-}
-
-int wd_alg_driver_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
-{
- return drv->send(drv, ctx, msg);
-}
-
-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;
diff --git a/wd_cipher.c b/wd_cipher.c
index 58656dc..53733a4 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -53,6 +53,7 @@ struct wd_cipher_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_cipher_setting;
@@ -379,7 +380,8 @@ static int wd_cipher_common_init(struct wd_ctx_config *config,
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_cipher_setting.config,
- wd_cipher_setting.driver);
+ wd_cipher_setting.driver,
+ &wd_cipher_setting.priv);
if (ret)
goto out_clear_pool;
@@ -396,10 +398,9 @@ out_clear_ctx_config:
static int wd_cipher_common_uninit(void)
{
- enum wd_status status;
+ void *priv = wd_cipher_setting.priv;
- wd_alg_get_init(&wd_cipher_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!priv)
return -WD_EINVAL;
/* uninit async request pool */
@@ -409,7 +410,8 @@ static int wd_cipher_common_uninit(void)
wd_clear_sched(&wd_cipher_setting.sched);
wd_alg_uninit_driver(&wd_cipher_setting.config,
- wd_cipher_setting.driver);
+ wd_cipher_setting.driver,
+ &wd_cipher_setting.priv);
return 0;
}
@@ -720,8 +722,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx,
msg_handle.recv = wd_cipher_setting.driver->recv;
wd_ctx_spin_lock(ctx, wd_cipher_setting.driver->calc_type);
- ret = wd_handle_msg_sync(wd_cipher_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, wd_cipher_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL,
+ wd_cipher_setting.config.epoll_en);
wd_ctx_spin_unlock(ctx, wd_cipher_setting.driver->calc_type);
return ret;
@@ -796,7 +798,7 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req)
fill_request_msg(msg, req, sess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_cipher_setting.driver, ctx->ctx, msg);
+ ret = wd_cipher_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("wd cipher async send err!\n");
@@ -846,7 +848,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_cipher_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_cipher_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN)
return ret;
else if (ret < 0) {
diff --git a/wd_comp.c b/wd_comp.c
index c67b7f1..be08ee8 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -51,6 +51,7 @@ struct wd_comp_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_comp_setting;
@@ -172,7 +173,8 @@ static int wd_comp_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_comp_setting.config,
- wd_comp_setting.driver);
+ wd_comp_setting.driver,
+ &wd_comp_setting.priv);
if (ret)
goto out_clear_pool;
@@ -189,10 +191,9 @@ out_clear_ctx_config:
static int wd_comp_uninit_nolock(void)
{
- enum wd_status status;
+ void *priv = wd_comp_setting.priv;
- wd_alg_get_init(&wd_comp_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!priv)
return -WD_EINVAL;
/* Uninit async request pool */
@@ -202,7 +203,8 @@ static int wd_comp_uninit_nolock(void)
wd_clear_sched(&wd_comp_setting.sched);
wd_alg_uninit_driver(&wd_comp_setting.config,
- wd_comp_setting.driver);
+ wd_comp_setting.driver,
+ &wd_comp_setting.priv);
return 0;
}
@@ -382,7 +384,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_comp_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_comp_setting.driver->recv(ctx->ctx, &resp_msg);
if (unlikely(ret < 0)) {
if (ret == -WD_HW_EACCESS)
WD_ERR("wd comp recv hw error!\n");
@@ -685,8 +687,8 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess,
msg_handle.recv = wd_comp_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_comp_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, config->epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg,
+ NULL, config->epoll_en);
pthread_spin_unlock(&ctx->lock);
return ret;
@@ -944,7 +946,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
msg->tag = tag;
msg->stream_mode = WD_COMP_STATELESS;
- ret = wd_alg_driver_send(wd_comp_setting.driver, ctx->ctx, msg);
+ ret = wd_comp_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("wd comp send error, ret = %d!\n", ret);
diff --git a/wd_dh.c b/wd_dh.c
index 0c1372c..42a1805 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -36,6 +36,7 @@ static struct wd_dh_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_dh_setting;
@@ -144,7 +145,8 @@ static int wd_dh_common_init(struct wd_ctx_config *config, struct wd_sched *sche
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_dh_setting.config,
- wd_dh_setting.driver);
+ wd_dh_setting.driver,
+ &wd_dh_setting.priv);
if (ret)
goto out_clear_pool;
@@ -161,11 +163,10 @@ out_clear_ctx_config:
static int wd_dh_common_uninit(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_dh_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!wd_dh_setting.priv) {
+ WD_ERR("invalid: repeat uninit dh!\n");
return -WD_EINVAL;
+ }
/* uninit async request pool */
wd_uninit_async_request_pool(&wd_dh_setting.pool);
@@ -173,7 +174,8 @@ static int wd_dh_common_uninit(void)
/* unset config, sched, driver */
wd_clear_sched(&wd_dh_setting.sched);
wd_alg_uninit_driver(&wd_dh_setting.config,
- wd_dh_setting.driver);
+ wd_dh_setting.driver,
+ &wd_dh_setting.priv);
return WD_SUCCESS;
}
@@ -390,8 +392,8 @@ int wd_do_dh_sync(handle_t sess, struct wd_dh_req *req)
msg_handle.recv = wd_dh_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_dh_setting.driver, &msg_handle, ctx->ctx,
- &msg, &balance, wd_dh_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance,
+ wd_dh_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
return ret;
@@ -437,7 +439,7 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req)
goto fail_with_msg;
msg->tag = mid;
- ret = wd_alg_driver_send(wd_dh_setting.driver, ctx->ctx, msg);
+ ret = wd_dh_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send dh BD, hw is err!\n");
@@ -488,7 +490,7 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_dh_setting.driver, ctx->ctx, &rcv_msg);
+ ret = wd_dh_setting.driver->recv(ctx->ctx, &rcv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (unlikely(ret)) {
diff --git a/wd_digest.c b/wd_digest.c
index 0b37f8b..763eae5 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -42,6 +42,7 @@ struct wd_digest_setting {
struct wd_sched sched;
struct wd_alg_driver *driver;
struct wd_async_msg_pool pool;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_digest_setting;
@@ -312,7 +313,8 @@ static int wd_digest_init_nolock(struct wd_ctx_config *config,
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_digest_setting.config,
- wd_digest_setting.driver);
+ wd_digest_setting.driver,
+ &wd_digest_setting.priv);
if (ret)
goto out_clear_pool;
@@ -361,29 +363,21 @@ out_clear_init:
return ret;
}
-static int wd_digest_uninit_nolock(void)
+static void wd_digest_uninit_nolock(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_digest_setting.status, &status);
- if (status == WD_UNINIT)
- return -WD_EINVAL;
-
wd_uninit_async_request_pool(&wd_digest_setting.pool);
wd_clear_sched(&wd_digest_setting.sched);
wd_alg_uninit_driver(&wd_digest_setting.config,
- wd_digest_setting.driver);
- return 0;
+ wd_digest_setting.driver,
+ &wd_digest_setting.priv);
}
void wd_digest_uninit(void)
{
- int ret;
-
- ret = wd_digest_uninit_nolock();
- if (ret)
+ if (!wd_digest_setting.priv)
return;
+ wd_digest_uninit_nolock();
wd_digest_close_driver(WD_TYPE_V1);
wd_alg_clear_init(&wd_digest_setting.status);
}
@@ -485,12 +479,10 @@ out_uninit:
void wd_digest_uninit2(void)
{
- int ret;
-
- ret = wd_digest_uninit_nolock();
- if (ret)
+ if (!wd_digest_setting.priv)
return;
+ wd_digest_uninit_nolock();
wd_alg_attrs_uninit(&wd_digest_init_attrs);
wd_alg_drv_unbind(wd_digest_setting.driver);
wd_digest_close_driver(WD_TYPE_V2);
@@ -655,8 +647,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *ds
msg_handle.recv = wd_digest_setting.driver->recv;
wd_ctx_spin_lock(ctx, wd_digest_setting.driver->calc_type);
- ret = wd_handle_msg_sync(wd_digest_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, wd_digest_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg,
+ NULL, wd_digest_setting.config.epoll_en);
wd_ctx_spin_unlock(ctx, wd_digest_setting.driver->calc_type);
if (unlikely(ret))
return ret;
@@ -750,7 +742,7 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req)
fill_request_msg(msg, req, dsess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_digest_setting.driver, ctx->ctx, msg);
+ ret = wd_digest_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send BD, hw is err!\n");
@@ -800,7 +792,8 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_digest_setting.driver, ctx->ctx, &recv_msg);
+ ret = wd_digest_setting.driver->recv(ctx->ctx,
+ &recv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_ecc.c b/wd_ecc.c
index 2c88d0a..900f36c 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -69,6 +69,7 @@ static struct wd_ecc_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_ecc_setting;
@@ -210,7 +211,8 @@ static int wd_ecc_common_init(struct wd_ctx_config *config, struct wd_sched *sch
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_ecc_setting.config,
- wd_ecc_setting.driver);
+ wd_ecc_setting.driver,
+ &wd_ecc_setting.priv);
if (ret)
goto out_clear_pool;
@@ -227,11 +229,10 @@ out_clear_ctx_config:
static int wd_ecc_common_uninit(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_ecc_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!wd_ecc_setting.priv) {
+ WD_ERR("invalid: repeat uninit ecc!\n");
return -WD_EINVAL;
+ }
/* uninit async request pool */
wd_uninit_async_request_pool(&wd_ecc_setting.pool);
@@ -239,7 +240,8 @@ static int wd_ecc_common_uninit(void)
/* unset config, sched, driver */
wd_clear_sched(&wd_ecc_setting.sched);
wd_alg_uninit_driver(&wd_ecc_setting.config,
- wd_ecc_setting.driver);
+ wd_ecc_setting.driver,
+ &wd_ecc_setting.priv);
return WD_SUCCESS;
}
@@ -1203,8 +1205,8 @@ static void wd_ecc_sess_eops_cfg(struct wd_ecc_sess_setup *setup,
{
if (sess->eops.sess_init && sess->eops.eops_params_cfg) {
/* the config result does not impact task sucesss or failure */
- sess->eops.eops_params_cfg(wd_ecc_setting.driver, setup, sess->key.cv,
- sess->eops.params);
+ sess->eops.eops_params_cfg(setup, sess->key.cv,
+ wd_ecc_setting.priv, sess->eops.params);
}
}
@@ -1652,8 +1654,8 @@ int wd_do_ecc_sync(handle_t h_sess, struct wd_ecc_req *req)
msg_handle.recv = wd_ecc_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_ecc_setting.driver, &msg_handle, ctx->ctx, &msg,
- &balance, wd_ecc_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance,
+ wd_ecc_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
return ret;
@@ -2339,7 +2341,7 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req)
goto fail_with_msg;
msg->tag = mid;
- ret = wd_alg_driver_send(wd_ecc_setting.driver, ctx->ctx, msg);
+ ret = wd_ecc_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send ecc BD, hw is err!\n");
@@ -2389,7 +2391,7 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_ecc_setting.driver, ctx->ctx, &recv_msg);
+ ret = wd_ecc_setting.driver->recv(ctx->ctx, &recv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_join_gather.c b/wd_join_gather.c
index 915c1b8..86190c4 100644
--- a/wd_join_gather.c
+++ b/wd_join_gather.c
@@ -410,13 +410,12 @@ static void wd_join_gather_uninit_sess(struct wd_join_gather_sess *sess)
free(sess->gather_conf.batch_row_size);
if (sess->ops.sess_uninit)
- sess->ops.sess_uninit(wd_join_gather_setting.driver, sess->priv);
+ sess->ops.sess_uninit(sess->priv);
}
static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
struct wd_join_gather_sess_setup *setup)
{
- struct wd_alg_driver *drv = wd_join_gather_setting.driver;
__u32 array_size;
int ret;
@@ -425,7 +424,7 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
WD_ERR("failed to get session uninit ops!\n");
return -WD_EINVAL;
}
- ret = sess->ops.sess_init(drv, setup, &sess->priv);
+ ret = sess->ops.sess_init(setup, &sess->priv);
if (ret) {
WD_ERR("failed to init session priv!\n");
return ret;
@@ -433,7 +432,7 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
}
if (sess->ops.get_table_row_size && setup->alg != WD_GATHER) {
- ret = sess->ops.get_table_row_size(drv, sess->priv);
+ ret = sess->ops.get_table_row_size(sess->priv);
if (ret <= 0) {
WD_ERR("failed to get hash table row size: %d!\n", ret);
goto uninit;
@@ -447,7 +446,7 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
if (!sess->gather_conf.batch_row_size)
goto uninit;
- ret = sess->ops.get_batch_row_size(drv, sess->priv,
+ ret = sess->ops.get_batch_row_size(sess->priv,
sess->gather_conf.batch_row_size,
array_size);
if (ret) {
@@ -462,7 +461,7 @@ free_batch:
free(sess->gather_conf.batch_row_size);
uninit:
if (sess->ops.sess_uninit)
- sess->ops.sess_uninit(drv, sess->priv);
+ sess->ops.sess_uninit(sess->priv);
return -WD_EINVAL;
}
@@ -656,8 +655,7 @@ int wd_join_set_hash_table(handle_t h_sess, struct wd_dae_hash_table *info)
WD_INFO("info: extern hash table is NULL!\n");
if (sess->ops.hash_table_init) {
- ret = sess->ops.hash_table_init(wd_join_gather_setting.driver,
- info, sess->priv);
+ ret = sess->ops.hash_table_init(info, sess->priv);
if (ret)
goto out;
}
@@ -699,7 +697,9 @@ static int wd_join_gather_alg_init(struct wd_ctx_config *config, struct wd_sched
if (ret < 0)
goto out_clear_sched;
- ret = wd_alg_init_driver(&wd_join_gather_setting.config, wd_join_gather_setting.driver);
+ ret = wd_alg_init_driver(&wd_join_gather_setting.config,
+ wd_join_gather_setting.driver,
+ &wd_join_gather_setting.priv);
if (ret)
goto out_clear_pool;
@@ -728,7 +728,9 @@ static int wd_join_gather_alg_uninit(void)
/* Unset config, sched, driver */
wd_clear_sched(&wd_join_gather_setting.sched);
- wd_alg_uninit_driver(&wd_join_gather_setting.config, wd_join_gather_setting.driver);
+ wd_alg_uninit_driver(&wd_join_gather_setting.config,
+ wd_join_gather_setting.driver,
+ &wd_join_gather_setting.priv);
return WD_SUCCESS;
}
@@ -1215,7 +1217,7 @@ static int wd_join_gather_sync_job(struct wd_join_gather_sess *sess,
msg_handle.recv = setting->driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(setting->driver, &msg_handle, ctx->ctx,
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx,
msg, NULL, config->epoll_en);
pthread_spin_unlock(&ctx->lock);
@@ -1311,7 +1313,7 @@ static int wd_join_gather_async_job(struct wd_join_gather_sess *sess,
fill_join_gather_msg(msg, req, sess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(setting->driver, ctx->ctx, msg);
+ ret = wd_join_gather_setting.driver->send(ctx->ctx, msg);
if (ret < 0) {
if (ret != -WD_EBUSY)
WD_ERR("wd join gather async send err!\n");
@@ -1781,7 +1783,7 @@ static int wd_join_gather_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_join_gather_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_join_gather_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_rsa.c b/wd_rsa.c
index bc78c6a..3e4d70d 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -77,6 +77,7 @@ static struct wd_rsa_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_rsa_setting;
@@ -184,7 +185,8 @@ static int wd_rsa_common_init(struct wd_ctx_config *config, struct wd_sched *sch
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_rsa_setting.config,
- wd_rsa_setting.driver);
+ wd_rsa_setting.driver,
+ &wd_rsa_setting.priv);
if (ret)
goto out_clear_pool;
@@ -201,11 +203,10 @@ out_clear_ctx_config:
static int wd_rsa_common_uninit(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_rsa_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!wd_rsa_setting.priv) {
+ WD_ERR("invalid: repeat uninit rsa!\n");
return -WD_EINVAL;
+ }
/* uninit async request pool */
wd_uninit_async_request_pool(&wd_rsa_setting.pool);
@@ -213,7 +214,8 @@ static int wd_rsa_common_uninit(void)
/* unset config, sched, driver */
wd_clear_sched(&wd_rsa_setting.sched);
wd_alg_uninit_driver(&wd_rsa_setting.config,
- wd_rsa_setting.driver);
+ wd_rsa_setting.driver,
+ &wd_rsa_setting.priv);
return WD_SUCCESS;
}
@@ -451,8 +453,8 @@ int wd_do_rsa_sync(handle_t h_sess, struct wd_rsa_req *req)
msg_handle.recv = wd_rsa_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_rsa_setting.driver, &msg_handle, ctx->ctx, &msg,
- &balance, wd_rsa_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance,
+ wd_rsa_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
return ret;
@@ -498,7 +500,7 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req)
goto fail_with_msg;
msg->tag = mid;
- ret = wd_alg_driver_send(wd_rsa_setting.driver, ctx->ctx, msg);
+ ret = wd_rsa_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send rsa BD, hw is err!\n");
@@ -548,7 +550,7 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_rsa_setting.driver, ctx->ctx, &recv_msg);
+ ret = wd_rsa_setting.driver->recv(ctx->ctx, &recv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_udma.c b/wd_udma.c
index eebe495..341b533 100644
--- a/wd_udma.c
+++ b/wd_udma.c
@@ -22,6 +22,7 @@ static struct wd_udma_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_udma_setting;
@@ -229,7 +230,7 @@ int wd_do_udma_sync(handle_t h_sess, struct wd_udma_req *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,
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx,
&msg, NULL, wd_udma_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
@@ -276,7 +277,7 @@ int wd_do_udma_async(handle_t sess, struct wd_udma_req *req)
fill_udma_msg(msg, req);
msg->tag = mid;
- ret = wd_alg_driver_send(wd_udma_setting.driver, ctx->ctx, msg);
+ ret = wd_udma_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send udma BD, hw is err!\n");
@@ -314,7 +315,7 @@ static int wd_udma_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_udma_setting.driver, ctx->ctx, &rcv_msg);
+ ret = wd_udma_setting.driver->recv(ctx->ctx, &rcv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (unlikely(ret)) {
@@ -364,7 +365,9 @@ static void wd_udma_alg_uninit(void)
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);
+ wd_alg_uninit_driver(&wd_udma_setting.config,
+ wd_udma_setting.driver,
+ &wd_udma_setting.priv);
}
void wd_udma_uninit(void)
@@ -405,7 +408,9 @@ static int wd_udma_alg_init(struct wd_ctx_config *config, struct wd_sched *sched
if (ret < 0)
goto out_clear_sched;
- ret = wd_alg_init_driver(&wd_udma_setting.config, wd_udma_setting.driver);
+ ret = wd_alg_init_driver(&wd_udma_setting.config,
+ wd_udma_setting.driver,
+ &wd_udma_setting.priv);
if (ret)
goto out_clear_pool;
diff --git a/wd_util.c b/wd_util.c
index bf82fc1..0dc9a67 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -1878,8 +1878,8 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en)
return 0;
}
-int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_handle,
- handle_t ctx, void *msg, __u64 *balance, bool epoll_en)
+int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx,
+ void *msg, __u64 *balance, bool epoll_en)
{
__u64 timeout = WD_RECV_MAX_CNT_NOSLEEP;
__u64 rx_cnt = 0;
@@ -1888,7 +1888,7 @@ int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_hand
if (balance)
timeout = WD_RECV_MAX_CNT_SLEEP;
- ret = msg_handle->send(drv, ctx, msg);
+ ret = msg_handle->send(ctx, msg);
if (unlikely(ret < 0)) {
WD_ERR("failed to send msg to hw, ret = %d!\n", ret);
return ret;
@@ -1901,7 +1901,7 @@ int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_hand
WD_ERR("wd ctx wait timeout(%d)!\n", ret);
}
- ret = msg_handle->recv(drv, ctx, msg);
+ ret = msg_handle->recv(ctx, msg);
if (ret != -WD_EAGAIN) {
if (unlikely(ret < 0)) {
WD_ERR("failed to recv msg: error = %d!\n", ret);
@@ -1964,10 +1964,21 @@ static void wd_alg_uninit_fallback(struct wd_alg_driver *fb_driver)
}
int wd_alg_init_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver)
+ struct wd_alg_driver *driver, void **drv_priv)
{
+ void *priv;
int ret;
+ if (!driver->priv_size) {
+ WD_ERR("invalid: driver priv ctx size is zero!\n");
+ return -WD_EINVAL;
+ }
+
+ /* Init ctx related resources in specific driver */
+ priv = calloc(1, driver->priv_size);
+ if (!priv)
+ return -WD_ENOMEM;
+
if (!driver->init) {
driver->fallback = 0;
WD_ERR("driver have no init interface.\n");
@@ -1975,11 +1986,12 @@ int wd_alg_init_driver(struct wd_ctx_config_internal *config,
goto err_alloc;
}
- ret = driver->init(driver, config);
+ ret = driver->init(config, priv);
if (ret < 0) {
WD_ERR("driver init failed.\n");
goto err_alloc;
}
+ driver->drv_data = priv;
if (driver->fallback) {
ret = wd_alg_init_fallback((struct wd_alg_driver *)driver->fallback);
@@ -1988,22 +2000,32 @@ int wd_alg_init_driver(struct wd_ctx_config_internal *config,
WD_ERR("soft alg driver init failed.\n");
}
}
+ *drv_priv = priv;
return 0;
err_alloc:
+ free(priv);
return ret;
}
void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver)
+ struct wd_alg_driver *driver, void **drv_priv)
{
- driver->exit(driver);
+ void *priv = *drv_priv;
+
+ driver->exit(priv);
/* Ctx config just need clear once */
wd_clear_ctx_config(config);
if (driver->fallback)
wd_alg_uninit_fallback((struct wd_alg_driver *)driver->fallback);
+
+ if (priv) {
+ free(priv);
+ driver->drv_data = NULL;
+ *drv_priv = NULL;
+ }
}
void wd_dlclose_drv(void *dlh_list)
--
2.43.0
1
18
[PATCH OLK-5.10 0/2] crypto: hisilicon/qm - support querying the hardware fault status
by ZongYu Wu 31 Mar '26
by ZongYu Wu 31 Mar '26
31 Mar '26
From: JiangShui Yang <yangjiangshui(a)h-partners.com>
Zhushuai Yin (1):
crypto: hisilicon/qm - support querying the hardware fault status
through VFs
nieweiqiang (1):
crypto: hisilicon/qm - add concurrency protection for variable
err_threshold
drivers/crypto/hisilicon/qm.c | 129 ++++++++++++++++++++---
drivers/crypto/hisilicon/sec2/sec_main.c | 10 +-
drivers/crypto/hisilicon/zip/zip_main.c | 10 +-
3 files changed, 124 insertions(+), 25 deletions(-)
--
2.33.0
1
2
[PATCH OLK-6.6] crypto: hisilicon/qm - support querying the hardware fault status through VFs
by ZongYu Wu 26 Mar '26
by ZongYu Wu 26 Mar '26
26 Mar '26
From: Zhushuai Yin <yinzhushuai(a)huawei.com>
driver inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/8816
CVE: NA
----------------------------------------------------------------------
The problem that the VF device cannot obtain the isolation
status and isolation threshold of the device is resolved.
Signed-off-by: Zhushuai Yin <yinzhushuai(a)huawei.com>
Signed-off-by: JiangShui Yang <yangjiangshui(a)h-partners.com>
---
drivers/crypto/hisilicon/hpre/hpre_main.c | 10 +-
drivers/crypto/hisilicon/qm.c | 119 +++++++++++++++++++---
2 files changed, 111 insertions(+), 18 deletions(-)
diff --git a/drivers/crypto/hisilicon/hpre/hpre_main.c b/drivers/crypto/hisilicon/hpre/hpre_main.c
index 074b3424becf..bcc5bc02bb30 100644
--- a/drivers/crypto/hisilicon/hpre/hpre_main.c
+++ b/drivers/crypto/hisilicon/hpre/hpre_main.c
@@ -1613,12 +1613,10 @@ static int hpre_probe(struct pci_dev *pdev, const struct pci_device_id *id)
goto err_qm_del_list;
}
- if (qm->uacce) {
- ret = uacce_register(qm->uacce);
- if (ret) {
- pci_err(pdev, "failed to register uacce (%d)!\n", ret);
- goto err_with_alg_register;
- }
+ ret = qm_register_uacce(qm);
+ if (ret) {
+ pci_err(pdev, "failed to register uacce (%d)!\n", ret);
+ goto err_with_alg_register;
}
if (qm->fun_type == QM_HW_PF && vfs_num) {
diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
index ae7132a84e4a..7e7d4d3a79f0 100644
--- a/drivers/crypto/hisilicon/qm.c
+++ b/drivers/crypto/hisilicon/qm.c
@@ -252,6 +252,10 @@
#define QM_QOS_MAX_CIR_U 6
#define QM_AUTOSUSPEND_DELAY 3000
+/* qm isolation state mask */
+#define QM_ISOLATED_STATE BIT(31)
+#define QM_ISOLATED_THRESHOLD_MASK GENMASK(15, 0)
+
/* abnormal status value for stopping queue */
#define QM_STOP_QUEUE_FAIL 1
#define QM_DUMP_SQC_FAIL 3
@@ -292,6 +296,21 @@ enum qm_alg_type {
ALG_TYPE_1,
};
+/**
+ * @brief Message format for QM_VF_GET_ISOLATE and QM_PF_SET_ISOLATE commands
+ *
+ * These commands use a 32-bit command field (cmd) and 32-bit data field (data)
+ *
+ * @details
+ * Command behavior:
+ * - QM_VF_GET_ISOLATE: VF requests isolation status and threshold
+ * - QM_PF_SET_ISOLATE: PF sets isolation status and threshold
+ *
+ * Data field bit layout:
+ * - bit31 (MSB): Isolation status flag (1 = isolated, 0 = non-isolated)
+ * - bit15-0 (16 LSB): Isolation threshold value
+ * - bit30-16 (15 bits): Reserved
+ */
enum qm_ifc_cmd {
QM_PF_FLR_PREPARE = 0x01,
QM_PF_SRST_PREPARE,
@@ -302,6 +321,8 @@ enum qm_ifc_cmd {
QM_VF_START_FAIL,
QM_PF_SET_QOS,
QM_VF_GET_QOS,
+ QM_VF_GET_ISOLATE,
+ QM_PF_SET_ISOLATE
};
enum qm_basic_type {
@@ -1780,7 +1801,7 @@ static int qm_ping_single_vf(struct hisi_qm *qm, enum qm_ifc_cmd cmd, u32 data,
return ret;
}
-static int qm_ping_all_vfs(struct hisi_qm *qm, enum qm_ifc_cmd cmd)
+static int qm_ping_all_vfs(struct hisi_qm *qm, enum qm_ifc_cmd cmd, u32 data)
{
struct device *dev = &qm->pdev->dev;
u32 vfs_num = qm->vfs_num;
@@ -1789,7 +1810,7 @@ static int qm_ping_all_vfs(struct hisi_qm *qm, enum qm_ifc_cmd cmd)
int ret;
u32 i;
- ret = qm->ops->set_ifc_begin(qm, cmd, 0, QM_MB_PING_ALL_VFS);
+ ret = qm->ops->set_ifc_begin(qm, cmd, data, QM_MB_PING_ALL_VFS);
if (ret && cmd != QM_PF_FLR_PREPARE && cmd != QM_PF_SRST_PREPARE) {
dev_err(dev, "failed to send command(0x%x) to all vfs!\n", cmd);
qm->ops->set_ifc_end(qm);
@@ -2808,7 +2829,10 @@ static void qm_uacce_base_init(struct hisi_qm *qm)
else
mmio_page_nr = QM_QP_DB_INTERVAL / PAGE_SIZE;
- uacce->is_vf = pdev->is_virtfn;
+ if (qm->fun_type == QM_HW_PF)
+ uacce->is_vf = false;
+ else
+ uacce->is_vf = true;
uacce->priv = qm;
uacce->parent = &pdev->dev;
qm_get_xqc_depth(qm, &sq_depth, &cq_depth, QM_QP_DEPTH_CAP);
@@ -2898,6 +2922,7 @@ static enum uacce_dev_state hisi_qm_get_isolate_state(struct uacce_device *uacce
static int hisi_qm_isolate_threshold_write(struct uacce_device *uacce, u32 num)
{
struct hisi_qm *qm = uacce->priv;
+ int ret;
/* Must be set by PF */
if (uacce->is_vf)
@@ -2911,6 +2936,18 @@ static int hisi_qm_isolate_threshold_write(struct uacce_device *uacce, u32 num)
/* After the policy is updated, need to reset the hardware err list */
qm_hw_err_destroy(qm);
+
+ if (!qm->vfs_num) {
+ mutex_unlock(&qm->isolate_data.isolate_lock);
+ return 0;
+ }
+
+ /* Notifying all VFs to update after the PF sets a threshold. */
+ if (test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps)) {
+ ret = qm_ping_all_vfs(qm, QM_PF_SET_ISOLATE, qm->isolate_data.err_threshold);
+ if (ret)
+ dev_err(&qm->pdev->dev, "failed to send command to all VFs set isolate!\n");
+ }
mutex_unlock(&qm->isolate_data.isolate_lock);
return 0;
@@ -2921,7 +2958,7 @@ static u32 hisi_qm_isolate_threshold_read(struct uacce_device *uacce)
struct hisi_qm *qm = uacce->priv;
struct hisi_qm *pf_qm;
- if (uacce->is_vf) {
+ if (uacce->is_vf && !test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps)) {
pf_qm = pci_get_drvdata(pci_physfn(qm->pdev));
return pf_qm->isolate_data.err_threshold;
}
@@ -3004,10 +3041,19 @@ static int qm_alloc_uacce(struct hisi_qm *qm)
int qm_register_uacce(struct hisi_qm *qm)
{
+ int ret;
+
if (!qm->uacce)
return 0;
dev_info(&qm->pdev->dev, "qm register to uacce\n");
+
+ if (qm->fun_type == QM_HW_VF && test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps)) {
+ ret = qm_ping_pf(qm, QM_VF_GET_ISOLATE);
+ if (ret)
+ dev_err(&qm->pdev->dev, "failed to send cmd to PF to get isolate!\n");
+ }
+
return uacce_register(qm->uacce);
}
EXPORT_SYMBOL_GPL(qm_register_uacce);
@@ -4581,7 +4627,7 @@ static int qm_try_stop_vfs(struct hisi_qm *qm, enum qm_ifc_cmd cmd,
/* Kunpeng930 supports to notify VFs to stop before PF reset */
if (test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps)) {
- ret = qm_ping_all_vfs(qm, cmd);
+ ret = qm_ping_all_vfs(qm, cmd, 0);
if (ret)
pci_err(pdev, "failed to send command to all VFs before PF reset!\n");
} else {
@@ -4766,6 +4812,7 @@ static int qm_vf_reset_done(struct hisi_qm *qm)
static int qm_try_start_vfs(struct hisi_qm *qm, enum qm_ifc_cmd cmd)
{
struct pci_dev *pdev = qm->pdev;
+ u32 data;
int ret;
if (!qm->vfs_num)
@@ -4779,7 +4826,11 @@ static int qm_try_start_vfs(struct hisi_qm *qm, enum qm_ifc_cmd cmd)
/* Kunpeng930 supports to notify VFs to start after PF reset. */
if (test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps)) {
- ret = qm_ping_all_vfs(qm, cmd);
+ data = qm->isolate_data.err_threshold;
+ if (qm->isolate_data.is_isolate)
+ data |= QM_ISOLATED_STATE;
+ /* Broadcasting isolate info via RAS to all VFs. */
+ ret = qm_ping_all_vfs(qm, cmd, data);
if (ret)
pci_warn(pdev, "failed to send cmd to all VFs after PF reset!\n");
} else {
@@ -5247,10 +5298,22 @@ static void qm_pf_reset_vf_done(struct hisi_qm *qm)
qm_reset_bit_clear(qm);
}
-static int qm_wait_pf_reset_finish(struct hisi_qm *qm)
+static void qm_vf_update_isolate_info(struct hisi_qm *qm, u32 data)
+{
+ /* Updating the local isolation status. */
+ mutex_lock(&qm->isolate_data.isolate_lock);
+ if (data & QM_ISOLATED_STATE)
+ qm->isolate_data.is_isolate = true;
+ else
+ qm->isolate_data.is_isolate = false;
+ qm->isolate_data.err_threshold = data & QM_ISOLATED_THRESHOLD_MASK;
+ mutex_unlock(&qm->isolate_data.isolate_lock);
+}
+
+static int qm_wait_pf_reset_finish(struct hisi_qm *qm, enum qm_stop_reason stop_reason)
{
struct device *dev = &qm->pdev->dev;
- u32 val, cmd;
+ u32 val, cmd, data;
int ret;
/* Wait for reset to finish */
@@ -5267,7 +5330,7 @@ static int qm_wait_pf_reset_finish(struct hisi_qm *qm)
* Whether message is got successfully,
* VF needs to ack PF by clearing the interrupt.
*/
- ret = qm->ops->get_ifc(qm, &cmd, NULL, 0);
+ ret = qm->ops->get_ifc(qm, &cmd, &data, 0);
qm_clear_cmd_interrupt(qm, 0);
if (ret) {
dev_err(dev, "failed to get command from PF in reset done!\n");
@@ -5276,10 +5339,14 @@ static int qm_wait_pf_reset_finish(struct hisi_qm *qm)
if (cmd != QM_PF_RESET_DONE) {
dev_err(dev, "the command(0x%x) is not reset done!\n", cmd);
- ret = -EINVAL;
+ return -EINVAL;
}
- return ret;
+ /* The VF processes the device isolation information received from the RAS reset. */
+ if (stop_reason == QM_SOFT_RESET)
+ qm_vf_update_isolate_info(qm, data);
+
+ return 0;
}
static void qm_pf_reset_vf_process(struct hisi_qm *qm,
@@ -5294,7 +5361,7 @@ static void qm_pf_reset_vf_process(struct hisi_qm *qm,
qm_cmd_uninit(qm);
qm_pf_reset_vf_prepare(qm, stop_reason);
- ret = qm_wait_pf_reset_finish(qm);
+ ret = qm_wait_pf_reset_finish(qm, stop_reason);
if (ret)
goto err_get_status;
@@ -5306,11 +5373,32 @@ static void qm_pf_reset_vf_process(struct hisi_qm *qm,
return;
err_get_status:
+ if (stop_reason == QM_SOFT_RESET) {
+ /* Update local isolation status on PF-VF reset failure. */
+ mutex_lock(&qm->isolate_data.isolate_lock);
+ qm->isolate_data.is_isolate = true;
+ mutex_unlock(&qm->isolate_data.isolate_lock);
+ }
clear_bit(QM_DEVICE_DOWN, &qm->misc_ctl);
qm_cmd_init(qm);
qm_reset_bit_clear(qm);
}
+static void qm_vf_get_isolate_data(struct hisi_qm *qm, u32 fun_num)
+{
+ u32 data = qm->isolate_data.err_threshold;
+ struct device *dev = &qm->pdev->dev;
+ int ret;
+
+ if (qm->isolate_data.is_isolate)
+ data |= QM_ISOLATED_STATE;
+
+ ret = qm_ping_single_vf(qm, QM_PF_SET_ISOLATE, data, fun_num);
+ if (ret)
+ dev_err(dev, "failed to send command(0x%x) to VF(%u)!\n",
+ (unsigned int)QM_PF_SET_ISOLATE, fun_num);
+}
+
static void qm_handle_cmd_msg(struct hisi_qm *qm, u32 fun_num)
{
struct device *dev = &qm->pdev->dev;
@@ -5348,6 +5436,13 @@ static void qm_handle_cmd_msg(struct hisi_qm *qm, u32 fun_num)
case QM_PF_SET_QOS:
qm->mb_qos = data;
break;
+ case QM_VF_GET_ISOLATE:
+ /* Read the isolation policy of the PF during VF initialization. */
+ qm_vf_get_isolate_data(qm, fun_num);
+ break;
+ case QM_PF_SET_ISOLATE:
+ qm_vf_update_isolate_info(qm, data);
+ break;
default:
dev_err(dev, "unsupported command(0x%x) sent by function(%u)!\n", cmd, fun_num);
break;
--
2.43.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>
---
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