Add heterogeneous computing functions to the soft and hard computing drivers of UADK. Adapt the drivers to ensure that different devices can perform heterogeneous computing at the same time and provide acceleration functions.
In order to ensure normal compilation, some drivers have been processed with hac mode, and can be compiled directly through UADK_MK.SH
Signed-off-by: Longfang Liu liulongfang@huawei.com --- Makefile.am | 139 +++++++++++------------------------- drv/hash_mb/hash_mb.c | 8 +++ drv/hash_mb/hash_mb.h | 3 + drv/hisi_comp.c | 2 + drv/hisi_sec.c | 99 ++++++++++++------------- drv/isa_ce_sm3.c | 25 +++++++ drv/isa_ce_sm3.h | 3 + drv/isa_ce_sm4.c | 28 +++++++- drv/isa_ce_sm4.h | 5 +- include/drv/wd_comp_drv.h | 3 +- include/drv/wd_digest_drv.h | 3 +- uadk_mk.sh | 9 +++ 12 files changed, 170 insertions(+), 157 deletions(-) create mode 100644 uadk_mk.sh
diff --git a/Makefile.am b/Makefile.am index ba3308a..d9604b1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,9 +1,7 @@ ACLOCAL_AMFLAGS = -I m4 -I./include AUTOMAKE_OPTIONS = foreign subdir-objects -AM_CFLAGS=-Wall -Werror -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 -CLEANFILES = +AM_CFLAGS = -std=gnu11 -Wall -Werror -Wextra -Wno-unused-parameter -Wfloat-equal -I$(top_srcdir)/include +AM_CFLAGS += -g -O0 -fno-omit-frame-pointer -fPIC -fPIE -pie -fstack-protector-strong -ftrapv
if WITH_LOG_FILE AM_CFLAGS+=-DWITH_LOG_FILE="$(with_log_file)" @@ -22,77 +20,40 @@ endif # WITH_LOG_FILE # y = minor # z = revision MAJOR = 2 -MINOR = 7 -REVISION = 0 +MINOR = 3 +REVISION = 22 UADK_VERSION = -version-number ${MAJOR}:${MINOR}:${REVISION}
-DAY = 6 -MONTH = June -YEAR = 2024 +DAY = 7 +MONTH = Mar +YEAR = 2022 AM_CFLAGS+= -DUADK_VERSION_NUMBER=""UADK version: ${MAJOR}.${MINOR}.${REVISION}"" AM_CFLAGS+= -DUADK_RELEASED_TIME=""Released ${MONTH} ${DAY}, ${YEAR}""
-pkginclude_HEADERS = include/wd.h include/wd_cipher.h include/wd_aead.h \ - include/wd_comp.h include/wd_dh.h include/wd_digest.h \ - include/wd_rsa.h include/uacce.h include/wd_alg_common.h \ - include/wd_ecc.h include/wd_sched.h include/wd_alg.h \ - include/wd_zlibwrapper.h include/wd_dae.h include/wd_agg.h - -nobase_pkginclude_HEADERS = v1/wd.h v1/wd_cipher.h v1/wd_aead.h v1/uacce.h v1/wd_dh.h \ - v1/wd_digest.h v1/wd_rsa.h v1/wd_bmm.h - -lib_LTLIBRARIES=libwd.la libwd_comp.la libwd_crypto.la libwd_dae.la - -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 - -libwd_la_SOURCES=wd.c wd_mempool.c wd.h wd_alg.c wd_alg.h \ - v1/wd.c v1/wd.h v1/wd_adapter.c v1/wd_adapter.h \ - 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 \ - v1/wd_comp.c v1/wd_comp.h \ - v1/wd_cipher.c v1/wd_cipher.h \ - v1/wd_digest.c v1/wd_digest.h \ - v1/wd_util.c v1/wd_util.h \ - v1/wd_bmm.c v1/wd_bmm.h \ - v1/wd_ecc.c v1/wd_ecc.h \ - v1/wd_sgl.c v1/wd_sgl.h \ - v1/drv/hisi_qm_udrv.c v1/drv/hisi_qm_udrv.h \ - v1/drv/hisi_zip_udrv.c v1/drv/hisi_zip_udrv.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 - -libwd_dae_la_SOURCES=wd_dae.h wd_agg.h wd_agg_drv.h wd_agg.c \ - wd_util.c wd_util.h wd_sched.c wd_sched.h wd.c wd.h +include_HEADERS = include/wd.h include/wd_cipher.h include/wd_comp.h \ + include/uacce.h include/wd_alg_common.h \ + include/wd_sched.h include/wd_alg.h + +lib_LTLIBRARIES=libwd.la libwd_comp.la libwd_crypto.la libhisi_zip.la \ + libisa_ce.la libisa_sve.la libhisi_sec.la + +libwd_la_SOURCES=wd.c wd_mempool.c wd.h wd_alg.c wd_alg.h
libwd_comp_la_SOURCES=wd_comp.c wd_comp.h wd_comp_drv.h wd_util.c wd_util.h \ - wd_sched.c wd_sched.h wd.c wd.h wd_zlibwrapper.c + wd_sched.c wd_sched.h wd.c wd.h \ + wd_zlibwrapper.c wd_zlibwrapper.h
libhisi_zip_la_SOURCES=drv/hisi_comp.c hisi_comp.h drv/hisi_qm_udrv.c \ hisi_qm_udrv.h wd_comp_drv.h
libwd_crypto_la_SOURCES=wd_cipher.c wd_cipher.h wd_cipher_drv.h \ - wd_aead.c wd_aead.h wd_aead_drv.h \ - wd_rsa.c wd_rsa.h wd_rsa_drv.h \ - wd_dh.c wd_dh.h wd_dh_drv.h \ - wd_ecc.c wd_ecc.h wd_ecc_drv.h \ wd_digest.c wd_digest.h wd_digest_drv.h \ wd_util.c wd_util.h \ wd_sched.c wd_sched.h \ wd.c wd.h
-libhisi_sec_la_SOURCES=drv/hisi_sec.c drv/hisi_qm_udrv.c \ - lib/crypto/aes.c lib/crypto/galois.c \ - hisi_qm_udrv.h wd_cipher_drv.h wd_aead_drv.h aes.h galois.h - -libhisi_hpre_la_SOURCES=drv/hisi_hpre.c drv/hisi_qm_udrv.c \ - hisi_qm_udrv.h - -libisa_ce_la_SOURCES=arm_arch_ce.h drv/isa_ce_sm3.c drv/isa_ce_sm3_armv8.S isa_ce_sm3.h \ +libisa_ce_la_SOURCES=arm_arch_ce.h wd_cipher_drv.h drv/isa_ce_sm3.c \ + drv/isa_ce_sm3_armv8.S isa_ce_sm3.h \ drv/isa_ce_sm4.c drv/isa_ce_sm4_armv8.S drv/isa_ce_sm4.h
libisa_sve_la_SOURCES=drv/hash_mb/hash_mb.c wd_digest_drv.h drv/hash_mb/hash_mb.h \ @@ -101,75 +62,55 @@ libisa_sve_la_SOURCES=drv/hash_mb/hash_mb.c wd_digest_drv.h drv/hash_mb/hash_mb. drv/hash_mb/md5_sve_common.S drv/hash_mb/md5_mb_asimd_x1.S \ drv/hash_mb/md5_mb_asimd_x4.S drv/hash_mb/md5_mb_sve.S
-libhisi_dae_la_SOURCES=drv/hisi_dae.c drv/hisi_qm_udrv.c \ - hisi_qm_udrv.h +libhisi_sec_la_SOURCES=drv/hisi_sec.c drv/hisi_qm_udrv.c \ + hisi_qm_udrv.h wd_cipher_drv.h \ + lib/crypto/aes.c lib/crypto/galois.c aes.h galois.h
if WD_STATIC_DRV -AM_CFLAGS += -DWD_STATIC_DRV -fPIC +AM_CFLAGS += -DWD_STATIC_DRV AM_CFLAGS += -DWD_NO_LOG
-libwd_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma +libwd_la_LIBADD = $(libwd_la_OBJECTS) -lnuma -lpthread
-libwd_comp_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma +libwd_comp_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lpthread -lnuma libwd_comp_la_DEPENDENCIES = libwd.la
-libhisi_zip_la_LIBADD = -ldl +libhisi_zip_la_LIBADD = -ldl -lpthread
-libwd_crypto_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma +libwd_crypto_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma -lm -lpthread libwd_crypto_la_DEPENDENCIES = libwd.la
-libwd_dae_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma -libwd_dae_la_DEPENDENCIES = libwd.la - -libhisi_sec_la_LIBADD = $(libwd_la_OBJECTS) $(libwd_crypto_la_OBJECTS) -libhisi_sec_la_DEPENDENCIES = libwd.la libwd_crypto.la - -libhisi_hpre_la_LIBADD = $(libwd_la_OBJECTS) $(libwd_crypto_la_OBJECTS) -libhisi_hpre_la_DEPENDENCIES = libwd.la libwd_crypto.la - libisa_ce_la_LIBADD = $(libwd_la_OBJECTS) $(libwd_crypto_la_OBJECTS) libisa_ce_la_DEPENDENCIES = libwd.la libwd_crypto.la
libisa_sve_la_LIBADD = $(libwd_la_OBJECTS) $(libwd_crypto_la_OBJECTS) libisa_sve_la_DEPENDENCIES = libwd.la libwd_crypto.la
-libhisi_dae_la_LIBADD = $(libwd_la_OBJECTS) $(libwd_dae_la_OBJECTS) -libhisi_dae_la_DEPENDENCIES = libwd.la libwd_dae.la +libhisi_sec_la_LIBADD = $(libwd_la_OBJECTS) $(libwd_crypto_la_OBJECTS) $(libisa_ce_la_OBJECTS) $(libisa_sve_la_OBJECTS) +libhisi_sec_la_DEPENDENCIES = libwd.la libwd_crypto.la libisa_ce.la libisa_sve.la
else UADK_WD_SYMBOL= -Wl,--version-script,$(top_srcdir)/libwd.map UADK_CRYPTO_SYMBOL= -Wl,--version-script,$(top_srcdir)/libwd_crypto.map -UADK_DAE_SYMBOL= -Wl,--version-script,$(top_srcdir)/libwd_dae.map +#UADK_DAE_SYMBOL= -Wl,--version-script,$(top_srcdir)/libwd_dae.map UADK_COMP_SYMBOL= -Wl,--version-script,$(top_srcdir)/libwd_comp.map UADK_V1_SYMBOL= -Wl,--version-script,$(top_srcdir)/v1/libwd.map
libwd_la_LDFLAGS=$(UADK_VERSION) $(UADK_WD_SYMBOL) $(UADK_V1_SYMBOL) -libwd_la_LIBADD= -ldl -lnuma +libwd_la_LIBADD= -lnuma
-libwd_comp_la_LIBADD= -lwd -ldl -lnuma -libwd_comp_la_LDFLAGS=$(UADK_VERSION) $(UADK_COMP_SYMBOL) -lpthread +libwd_comp_la_LIBADD= -lwd -ldl -lpthread -lnuma +libwd_comp_la_LDFLAGS=$(UADK_VERSION) $(UADK_COMP_SYMBOL) libwd_comp_la_DEPENDENCIES= libwd.la
-libwd_crypto_la_LIBADD= -lwd -ldl -lnuma -libwd_crypto_la_LDFLAGS=$(UADK_VERSION) $(UADK_CRYPTO_SYMBOL) -lpthread +libwd_crypto_la_LIBADD= -lwd -ldl -lnuma -lm -lpthread +libwd_crypto_la_LDFLAGS=$(UADK_VERSION) $(UADK_CRYPTO_SYMBOL) libwd_crypto_la_DEPENDENCIES= libwd.la
-libwd_dae_la_LIBADD= -lwd -ldl -lnuma -libwd_dae_la_LDFLAGS=$(UADK_VERSION) $(UADK_DAE_SYMBOL) -libwd_dae_la_DEPENDENCIES= libwd.la - libhisi_zip_la_LIBADD= -lwd -ldl -lwd_comp libhisi_zip_la_LDFLAGS=$(UADK_VERSION) libhisi_zip_la_DEPENDENCIES= libwd.la libwd_comp.la
-libhisi_sec_la_LIBADD= -lwd -lwd_crypto -libhisi_sec_la_LDFLAGS=$(UADK_VERSION) -libhisi_sec_la_DEPENDENCIES= libwd.la libwd_crypto.la - -libhisi_hpre_la_LIBADD= -lwd -lwd_crypto -libhisi_hpre_la_LDFLAGS=$(UADK_VERSION) -libhisi_hpre_la_DEPENDENCIES= libwd.la libwd_crypto.la - libisa_ce_la_LIBADD= -lwd -lwd_crypto libisa_ce_la_LDFLAGS=$(UADK_VERSION) libisa_ce_la_DEPENDENCIES= libwd.la libwd_crypto.la @@ -178,14 +119,14 @@ libisa_sve_la_LIBADD= -lwd -lwd_crypto libisa_sve_la_LDFLAGS=$(UADK_VERSION) libisa_sve_la_DEPENDENCIES= libwd.la libwd_crypto.la
-libhisi_dae_la_LIBADD= -lwd -lwd_dae -libhisi_dae_la_LDFLAGS=$(UADK_VERSION) -libhisi_dae_la_DEPENDENCIES= libwd.la libwd_dae.la +libhisi_sec_la_LIBADD= -lwd -lwd_crypto +libhisi_sec_la_LDFLAGS=$(UADK_VERSION) +libhisi_sec_la_DEPENDENCIES= libwd.la libwd_crypto.la
endif # WD_STATIC_DRV
pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = lib/libwd_crypto.pc lib/libwd_comp.pc lib/libwd.pc -CLEANFILES += $(pkgconfig_DATA)
-SUBDIRS=. test v1/test uadk_tool sample +#SUBDIRS=. test v1/test uadk_tool sample +SUBDIRS=. uadk_tool \ No newline at end of file diff --git a/drv/hash_mb/hash_mb.c b/drv/hash_mb/hash_mb.c index 3f5b1a5..27a06a5 100644 --- a/drv/hash_mb/hash_mb.c +++ b/drv/hash_mb/hash_mb.c @@ -818,7 +818,11 @@ static struct wd_alg_driver hash_mb_driver[] = { GEN_HASH_ALG_DRIVER("md5"), };
+#ifdef WD_STATIC_DRV +void hash_mb_probe(void) +#else static void __attribute__((constructor)) hash_mb_probe(void) +#endif { unsigned long auxval = getauxval(AT_HWCAP); size_t alg_num = ARRAY_SIZE(hash_mb_driver); @@ -837,7 +841,11 @@ static void __attribute__((constructor)) hash_mb_probe(void) } }
+#ifdef WD_STATIC_DRV +void hash_mb_remove(void) +#else static void __attribute__((destructor)) hash_mb_remove(void) +#endif { unsigned long auxval = getauxval(AT_HWCAP); size_t alg_num = ARRAY_SIZE(hash_mb_driver); diff --git a/drv/hash_mb/hash_mb.h b/drv/hash_mb/hash_mb.h index aba5ec9..b81a819 100644 --- a/drv/hash_mb/hash_mb.h +++ b/drv/hash_mb/hash_mb.h @@ -54,6 +54,9 @@ void md5_mb_asimd_x4(struct hash_job *job1, struct hash_job *job2, void md5_mb_asimd_x1(struct hash_job *job, int len); int md5_mb_sve_max_lanes(void);
+void hash_mb_probe(void); +void hash_mb_remove(void); + #ifdef __cplusplus } #endif diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c index ffe8eac..62571e6 100644 --- a/drv/hisi_comp.c +++ b/drv/hisi_comp.c @@ -803,6 +803,8 @@ static int hisi_zip_init(void *conf, void *priv) memcpy(&zip_ctx->config, config, sizeof(struct wd_ctx_config_internal)); /* allocate qp for each context */ for (i = 0; i < config->ctx_num; i++) { + if (config->ctxs[i].ctx_type != UADK_CTX_HW) + continue; h_ctx = config->ctxs[i].ctx; qm_priv.sqe_size = sizeof(struct hisi_zip_sqe); qm_priv.op_type = config->ctxs[i].op_type; diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index f008c16..b33b64a 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -11,6 +11,10 @@ #include "wd_digest.h" #include "wd_aead.h"
+#include "isa_ce_sm4.h" +#include "isa_ce_sm3.h" +#include "hash_mb/hash_mb.h" + #define BIT(nr) (1UL << (nr)) #define SEC_DIGEST_ALG_OFFSET 11 #define WORD_ALIGNMENT_MASK 0x3 @@ -1567,7 +1571,7 @@ static int fill_digest_long_hash(handle_t h_qp, struct wd_digest_msg *msg, static void parse_digest_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe, struct wd_digest_msg *recv_msg) { - struct wd_digest_msg *temp_msg; + struct wd_digest_msg *temp_msg = NULL; __u16 done;
done = sqe->type2.done_flag & SEC_DONE_MASK; @@ -2002,7 +2006,7 @@ put_sgl: static void parse_digest_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, struct wd_digest_msg *recv_msg) { - struct wd_digest_msg *temp_msg; + struct wd_digest_msg *temp_msg = NULL; __u16 done;
done = sqe->done_flag & SEC_DONE_MASK; @@ -2260,9 +2264,9 @@ static int aead_len_check(struct wd_aead_msg *msg, enum sec_bd_type type) } }
- if (unlikely((__u64)msg->in_bytes + msg->assoc_bytes > MAX_INPUT_DATA_LEN)) { - WD_ERR("aead input data length is too long, size = %llu\n", - (__u64)msg->in_bytes + msg->assoc_bytes); + if (unlikely(msg->in_bytes + msg->assoc_bytes > MAX_INPUT_DATA_LEN)) { + WD_ERR("aead input data length is too long, size = %u\n", + msg->in_bytes + msg->assoc_bytes); return -WD_EINVAL; }
@@ -2521,11 +2525,6 @@ int aead_msg_state_check(struct wd_aead_msg *msg) } }
- if (unlikely(msg->msg_state != AEAD_MSG_BLOCK && msg->data_fmt == WD_SGL_BUF)) { - WD_ERR("invalid: sgl mode not supports stream mode!\n"); - return -WD_EINVAL; - } - return 0; }
@@ -2565,12 +2564,10 @@ static int hisi_sec_aead_send(handle_t ctx, void *wd_msg) fill_aead_bd2_addr(msg, &sqe);
ret = fill_stream_bd2(msg, &sqe); - if (ret == WD_SOFT_COMPUTING) { - ret = 0; - goto put_sgl; - } else if (unlikely(ret)) { - goto put_sgl; - } + if (ret == WD_SOFT_COMPUTING) + return 0; + else if (unlikely(ret)) + return ret;
hisi_set_msg_id(h_qp, &msg->tag); sqe.type2.tag = (__u16)msg->tag; @@ -2580,16 +2577,14 @@ static int hisi_sec_aead_send(handle_t ctx, void *wd_msg) if (ret != -WD_EBUSY) WD_ERR("aead send sqe is err(%d)!\n", ret);
- goto put_sgl; + if (msg->data_fmt == WD_SGL_BUF) + hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, + msg->out); + + return ret; }
return 0; - -put_sgl: - if (msg->data_fmt == WD_SGL_BUF) - hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out); - - return ret; }
static void update_stream_counter(struct wd_aead_msg *recv_msg) @@ -2610,7 +2605,7 @@ static void update_stream_counter(struct wd_aead_msg *recv_msg) static void parse_aead_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe, struct wd_aead_msg *recv_msg) { - struct wd_aead_msg *temp_msg; + struct wd_aead_msg *temp_msg = NULL; __u16 done, icv;
done = sqe->type2.done_flag & SEC_DONE_MASK; @@ -2631,7 +2626,7 @@ static void parse_aead_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe, recv_msg->data_fmt = get_data_fmt_v2(sqe->sds_sa_type); recv_msg->in = (__u8 *)(uintptr_t)sqe->type2.data_src_addr; recv_msg->out = (__u8 *)(uintptr_t)sqe->type2.data_dst_addr; - temp_msg = wd_aead_get_msg(qp->q_info.idx, recv_msg->tag); + //temp_msg = wd_aead_get_msg(qp->q_info.idx, recv_msg->tag); if (!temp_msg) { recv_msg->result = WD_IN_EPARA; WD_ERR("failed to get send msg! idx = %u, tag = %u.\n", @@ -2643,7 +2638,7 @@ static void parse_aead_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe, temp_msg = recv_msg; }
- update_stream_counter(temp_msg); + update_stream_counter(recv_msg);
if (unlikely(recv_msg->result != WD_SUCCESS)) dump_sec_msg(temp_msg, "aead"); @@ -2652,17 +2647,8 @@ static void parse_aead_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe, static bool soft_compute_check(struct hisi_qp *qp, struct wd_aead_msg *msg) { /* Asynchronous mode does not use the sent message, so ignores it */ - if (qp->q_info.qp_mode == CTX_MODE_ASYNC) - return false; - /* - * For aead gcm stream mode, due to some hardware limitations, - * the final message was not sent to hardware if the qm is - * not higher than v3 version or the input length of the - * message is 0, the software calculation has been executed. - */ - if (msg->msg_state == AEAD_MSG_END && msg->cmode == WD_CIPHER_GCM && - (qp->q_info.hw_type <= HISI_QM_API_VER3_BASE || !msg->in_bytes)) - return true; + if (msg->cmode == WD_CIPHER_GCM) + return (msg->msg_state == AEAD_MSG_END) && qp->q_info.qp_mode == CTX_MODE_SYNC;
return false; } @@ -2972,12 +2958,10 @@ static int hisi_sec_aead_send_v3(handle_t ctx, void *wd_msg) fill_aead_bd3_addr(msg, &sqe);
ret = fill_stream_bd3(h_qp, msg, &sqe); - if (ret == WD_SOFT_COMPUTING) { - ret = 0; - goto put_sgl; - } else if (unlikely(ret)) { - goto put_sgl; - } + if (ret == WD_SOFT_COMPUTING) + return 0; + else if (unlikely(ret)) + return ret;
hisi_set_msg_id(h_qp, &msg->tag); sqe.tag = msg->tag; @@ -2986,22 +2970,20 @@ static int hisi_sec_aead_send_v3(handle_t ctx, void *wd_msg) if (ret != -WD_EBUSY) WD_ERR("aead send sqe v3 is err(%d)!\n", ret);
- goto put_sgl; + if (msg->data_fmt == WD_SGL_BUF) + hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, + msg->out); + + return ret; }
return 0; - -put_sgl: - if (msg->data_fmt == WD_SGL_BUF) - hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out); - - return ret; }
static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, struct wd_aead_msg *recv_msg) { - struct wd_aead_msg *temp_msg; + struct wd_aead_msg *temp_msg = NULL; __u16 done, icv;
done = sqe->done_flag & SEC_DONE_MASK; @@ -3023,7 +3005,7 @@ static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, recv_msg->data_fmt = get_data_fmt_v3(sqe->bd_param); recv_msg->in = (__u8 *)(uintptr_t)sqe->data_src_addr; recv_msg->out = (__u8 *)(uintptr_t)sqe->data_dst_addr; - temp_msg = wd_aead_get_msg(qp->q_info.idx, recv_msg->tag); + //temp_msg = wd_aead_get_msg(qp->q_info.idx, recv_msg->tag); if (!temp_msg) { recv_msg->result = WD_IN_EPARA; WD_ERR("failed to get send msg! idx = %u, tag = %u.\n", @@ -3035,7 +3017,7 @@ static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, temp_msg = recv_msg; }
- update_stream_counter(temp_msg); + update_stream_counter(recv_msg);
if (unlikely(recv_msg->result != WD_SUCCESS)) dump_sec_msg(temp_msg, "aead"); @@ -3083,9 +3065,12 @@ static int hisi_sec_init(void *conf, void *priv) return -WD_EINVAL; }
+ WD_ERR("debug: call function: %s!\n", __func__); qm_priv.sqe_size = sizeof(struct hisi_sec_sqe); /* allocate qp for each context */ for (i = 0; i < config->ctx_num; i++) { + if (config->ctxs[i].ctx_type != UADK_CTX_HW) + continue; h_ctx = config->ctxs[i].ctx; /* setting the type is 0 for sqc_type */ qm_priv.op_type = 0; @@ -3164,6 +3149,10 @@ static void __attribute__((constructor)) hisi_sec2_probe(void) WD_ERR("Error: register SEC %s failed!\n", aead_alg_driver[i].alg_name); } + + isa_ce_probe(); + sm3_ce_probe(); + hash_mb_probe(); }
#ifdef WD_STATIC_DRV @@ -3187,5 +3176,9 @@ static void __attribute__((destructor)) hisi_sec2_remove(void) alg_num = ARRAY_SIZE(aead_alg_driver); for (i = 0; i < alg_num; i++) wd_alg_driver_unregister(&aead_alg_driver[i]); + + isa_ce_remove(); + sm3_ce_remove(); + hash_mb_remove(); }
diff --git a/drv/isa_ce_sm3.c b/drv/isa_ce_sm3.c index c8812df..fa0256c 100644 --- a/drv/isa_ce_sm3.c +++ b/drv/isa_ce_sm3.c @@ -44,7 +44,11 @@ static struct wd_alg_driver sm3_ce_alg_driver = { .get_usage = sm3_ce_get_usage, };
+#ifdef WD_STATIC_DRV +void sm3_ce_probe(void) +#else static void __attribute__((constructor)) sm3_ce_probe(void) +#endif { int ret;
@@ -54,7 +58,11 @@ static void __attribute__((constructor)) sm3_ce_probe(void) WD_ERR("Error: register SM3 CE failed!\n"); }
+#ifdef WD_STATIC_DRV +void sm3_ce_remove(void) +#else static void __attribute__((destructor)) sm3_ce_remove(void) +#endif { wd_alg_driver_unregister(&sm3_ce_alg_driver); } @@ -340,6 +348,7 @@ static int do_hmac_sm3_ce(struct wd_digest_msg *msg, __u8 *out_hmac)
static int sm3_ce_drv_send(handle_t ctx, void *digest_msg) { + struct wd_soft_ctx *sfctx = (struct wd_soft_ctx *)ctx; struct wd_digest_msg *msg = (struct wd_digest_msg *)digest_msg; __u8 digest[SM3_DIGEST_SIZE] = {0}; int ret; @@ -349,6 +358,10 @@ static int sm3_ce_drv_send(handle_t ctx, void *digest_msg) return -WD_EINVAL; }
+ ret = wd_queue_is_busy(sfctx); + if (ret) + return ret; + if (msg->data_fmt == WD_SGL_BUF) { WD_ERR("invalid: SM3 CE driver do not support sgl data format!\n"); return -WD_EINVAL; @@ -363,11 +376,23 @@ static int sm3_ce_drv_send(handle_t ctx, void *digest_msg) ret = -WD_EINVAL; }
+ ret = wd_get_sqe_from_queue(sfctx, msg->tag); + if (ret) + return ret; + return ret; }
static int sm3_ce_drv_recv(handle_t ctx, void *digest_msg) { + struct wd_soft_ctx *sfctx = (struct wd_soft_ctx *)ctx; + struct wd_digest_msg *msg = (struct wd_digest_msg *)digest_msg; + int ret; + + ret = wd_put_sqe_to_queue(sfctx, &msg->tag, &msg->result); + if (ret) + return ret; + return WD_SUCCESS; }
diff --git a/drv/isa_ce_sm3.h b/drv/isa_ce_sm3.h index 13edb0a..b3d8810 100644 --- a/drv/isa_ce_sm3.h +++ b/drv/isa_ce_sm3.h @@ -79,6 +79,9 @@ struct sm3_ce_drv_ctx { void sm3_ce_block_compress(__u32 word_reg[SM3_STATE_WORDS], const __u8 *src, size_t blocks);
+void sm3_ce_probe(void); +void sm3_ce_remove(void); + #ifdef __cplusplus } #endif diff --git a/drv/isa_ce_sm4.c b/drv/isa_ce_sm4.c index 6475246..1f54e1f 100644 --- a/drv/isa_ce_sm4.c +++ b/drv/isa_ce_sm4.c @@ -11,6 +11,7 @@ * Copyright 2023 Huawei Technologies Co.,Ltd. All rights reserved. */
+#include "wd_alg.h" #include "drv/wd_cipher_drv.h" #include "isa_ce_sm4.h" #include "wd_cipher.h" @@ -323,15 +324,20 @@ static int sm4_xts_decrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rkey
static int isa_ce_cipher_send(handle_t ctx, void *wd_msg) { + struct wd_soft_ctx *sfctx = (struct wd_soft_ctx *)ctx; struct wd_cipher_msg *msg = wd_msg; struct SM4_KEY rkey; int ret = 0;
- if (!msg) { + if (!msg || !ctx) { WD_ERR("invalid: input sm4 msg is NULL!\n"); return -WD_EINVAL; }
+ ret = wd_queue_is_busy(sfctx); + if (ret) + return ret; + if (msg->data_fmt == WD_SGL_BUF) { WD_ERR("invalid: SM4 CE driver do not support sgl data format!\n"); return -WD_EINVAL; @@ -384,11 +390,23 @@ static int isa_ce_cipher_send(handle_t ctx, void *wd_msg) return -WD_EINVAL; }
+ ret = wd_get_sqe_from_queue(sfctx, msg->tag); + if (ret) + return ret; + return ret; }
static int isa_ce_cipher_recv(handle_t ctx, void *wd_msg) { + struct wd_soft_ctx *sfctx = (struct wd_soft_ctx *)ctx; + struct wd_cipher_msg *msg = wd_msg; + int ret; + + ret = wd_put_sqe_to_queue(sfctx, &msg->tag, &msg->result); + if (ret) + return ret; + return 0; }
@@ -428,7 +446,11 @@ static struct wd_alg_driver cipher_alg_driver[] = { GEN_CE_ALG_DRIVER("ecb(sm4)", cipher), };
+#ifdef WD_STATIC_DRV +void isa_ce_probe(void) +#else static void __attribute__((constructor)) isa_ce_probe(void) +#endif { __u32 alg_num, i; int ret; @@ -444,7 +466,11 @@ static void __attribute__((constructor)) isa_ce_probe(void) } }
+#ifdef WD_STATIC_DRV +void isa_ce_remove(void) +#else static void __attribute__((destructor)) isa_ce_remove(void) +#endif { __u32 alg_num, i;
diff --git a/drv/isa_ce_sm4.h b/drv/isa_ce_sm4.h index 308619e..d9ce128 100644 --- a/drv/isa_ce_sm4.h +++ b/drv/isa_ce_sm4.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: Apache-2.0 */ -/* Copyright 2024 Huawei Technologies Co.,Ltd. All rights reserved. */ +/* Copyright 2023 Huawei Technologies Co.,Ltd. All rights reserved. */
#ifndef __SM4_CE_DRV_H #define __SM4_CE_DRV_H @@ -55,6 +55,9 @@ int sm4_v8_xts_decrypt(const unsigned char *in, unsigned char *out, size_t lengt const struct SM4_KEY *key, unsigned char *ivec, const struct SM4_KEY *key2);
+void isa_ce_probe(void); +void isa_ce_remove(void); + #ifdef __cplusplus } #endif diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h index 213cf2d..2b95716 100644 --- a/include/drv/wd_comp_drv.h +++ b/include/drv/wd_comp_drv.h @@ -6,9 +6,8 @@
#include <pthread.h> #include <asm/types.h> - +#include "../wd_alg_common.h" #include "../wd_comp.h" -#include "../wd_util.h"
#ifdef __cplusplus extern "C" { diff --git a/include/drv/wd_digest_drv.h b/include/drv/wd_digest_drv.h index a55ef5b..5e3e821 100644 --- a/include/drv/wd_digest_drv.h +++ b/include/drv/wd_digest_drv.h @@ -3,8 +3,9 @@ #ifndef __WD_DIGEST_DRV_H #define __WD_DIGEST_DRV_H
+#include <asm/types.h> + #include "../wd_digest.h" -#include "../wd_util.h"
#ifdef __cplusplus extern "C" { diff --git a/uadk_mk.sh b/uadk_mk.sh new file mode 100644 index 0000000..c69937c --- /dev/null +++ b/uadk_mk.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +make clean + +./autogen.sh + +./conf.sh --static + +make -j8