Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 38 additions & 14 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
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
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 -ftrapv -Wl,-z,relro,-z,now

if WD_DEBUG
# Debug build: keep symbols, disable optimization and stripping for full stack traces
AM_CFLAGS+=-g -O0 -fno-omit-frame-pointer -DDEBUG
else
# Release build: optimize and strip symbols
AM_CFLAGS+=-O2 -D_FORTIFY_SOURCE=2 -Wl,-s
endif
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 \
-Wshift-negative-value -Wswitch-default -Wframe-larger-than=8192 -Wshift-overflow=2 \
-Wwrite-strings -Wmissing-format-attribute -Wformat-nonliteral -Wduplicated-cond \
-Wtrampolines -Wlogical-op -Wsuggest-attribute=format -Wduplicated-branches \
-Wmissing-include-dirs -Wformat-signedness -Wmissing-declarations -Wreturn-local-addr \
-Wredundant-decls -Wfloat-conversion -Wmissing-prototypes -Wstrict-prototypes

CLEANFILES =

if WITH_LOG_FILE
Expand Down Expand Up @@ -70,17 +87,19 @@ 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_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
wd_util.c wd_util.h wd_sched.c wd_sched.h wd.c wd.h

libwd_dae_la_SOURCES=wd_dae.h wd_agg.h wd_agg_drv.h wd_agg.c wd_join_gather.h wd_join_gather_drv.h wd_join_gather.c \
libwd_dae_la_SOURCES=wd_dae.h wd_agg.h wd_agg_drv.h wd_agg.c \
wd_join_gather.h wd_join_gather_drv.h wd_join_gather.c \
wd_util.c wd_util.h wd_sched.c wd_sched.h wd.c wd.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

libhisi_zip_la_SOURCES=drv/hisi_comp.c hisi_comp.h drv/hisi_qm_udrv.c \
drv/hisi_comp_huf.c drv/hisi_comp_huf.h \
hisi_qm_udrv.h wd_comp_drv.h
hisi_qm_udrv.h wd_comp_drv.h \
drv/wd_drv.h drv/wd_drv.c

libwd_crypto_la_SOURCES=wd_cipher.c wd_cipher.h wd_cipher_drv.h \
wd_aead.c wd_aead.h wd_aead_drv.h \
Expand All @@ -94,36 +113,41 @@ libwd_crypto_la_SOURCES=wd_cipher.c wd_cipher.h wd_cipher_drv.h \

libhisi_sec_la_SOURCES=drv/hisi_sec.c drv/hisi_qm_udrv.c \
lib/crypto/aes.c lib/crypto/sm4.c lib/crypto/galois.c \
hisi_qm_udrv.h wd_cipher_drv.h wd_aead_drv.h aes.h sm4.h galois.h
hisi_qm_udrv.h wd_cipher_drv.h wd_aead_drv.h aes.h sm4.h galois.h \
drv/wd_drv.h drv/wd_drv.c

libhisi_hpre_la_SOURCES=drv/hisi_hpre.c drv/hisi_qm_udrv.c \
hisi_qm_udrv.h
hisi_qm_udrv.h wd_rsa_drv.h wd_dh_drv.h wd_ecc_drv.h \
drv/wd_drv.h drv/wd_drv.c

if ARCH_ARM64
libisa_ce_la_SOURCES=arm_arch_ce.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
drv/isa_ce_sm4.c drv/isa_ce_sm4_armv8.S drv/isa_ce_sm4.h wd_util.c wd_util.h \
drv/wd_drv.h drv/wd_drv.c

libisa_sve_la_SOURCES=drv/hash_mb/hash_mb.c wd_digest_drv.h drv/hash_mb/hash_mb.h \
drv/hash_mb/sm3_sve_common.S drv/hash_mb/sm3_mb_asimd_x1.S \
drv/hash_mb/sm3_mb_asimd_x4.S drv/hash_mb/sm3_mb_sve.S \
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
drv/hash_mb/md5_mb_asimd_x4.S drv/hash_mb/md5_mb_sve.S \
drv/wd_drv.h drv/wd_drv.c
endif

libhisi_dae_la_SOURCES=drv/hisi_dae.c hisi_dae.h drv/hisi_qm_udrv.c \
hisi_qm_udrv.h drv/hisi_dae_join_gather.c drv/hisi_dae_common.c
hisi_qm_udrv.h drv/hisi_dae_join_gather.c drv/hisi_dae_common.c \
drv/wd_drv.h drv/wd_drv.c

libhisi_udma_la_SOURCES=drv/hisi_udma.c drv/hisi_qm_udrv.c \
hisi_qm_udrv.h
hisi_qm_udrv.h drv/wd_drv.h drv/wd_drv.c

if WD_STATIC_DRV
AM_CFLAGS += -DWD_STATIC_DRV -fPIC
AM_CFLAGS += -DWD_NO_LOG

libwd_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma -lpthread -lrt

libwd_comp_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma -lpthread
libwd_comp_la_DEPENDENCIES = libwd.la
libwd_comp_la_LIBADD = $(libwd_la_OBJECTS) $(libhisi_zip_la_OBJECTS) -ldl -lpthread -lnuma
libwd_comp_la_DEPENDENCIES = libwd.la libhisi_zip.la

libhisi_zip_la_LIBADD = -ldl -lpthread

Expand Down
19 changes: 13 additions & 6 deletions conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@

# Build UADK into static library
COMPILE_TYPE="--disable-static --enable-shared"
DEBUG_TYPE=""

# These two parameters could be in arbitary sequence
if [[ $1 && $1 = "--static" ]] || [[ $2 && $2 = "--static" ]]; then
echo "Configure to static compile!"
COMPILE_TYPE="--enable-static --disable-shared --with-static_drv"
fi
# These parameters could be in arbitary sequence
for arg in "$1" "$2" "$3"; do
if [[ $arg = "--static" ]]; then
echo "Configure to static compile!"
COMPILE_TYPE="--enable-static --disable-shared --with-static_drv"
elif [[ $arg = "--debug" ]]; then
echo "Configure to debug compile (with symbols, no optimization)!"
DEBUG_TYPE="--enable-debug=yes"
fi
done

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
ac_cv_func_malloc_0_nonnull=yes ac_cv_func_realloc_0_nonnull=yes ./configure -v \
--enable-perf=yes \
--host aarch64-linux-gnu \
--target aarch64-linux-gnu \
--includedir=/usr/local/include/ \
$COMPILE_TYPE
$COMPILE_TYPE \
$DEBUG_TYPE
10 changes: 10 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ AC_ARG_ENABLE([debug-log],
[debug_log=false]
)

AC_ARG_ENABLE([debug],
AS_HELP_STRING([--enable-debug], [build with -g -O0 and no symbol stripping for full stack traces]),
[ AS_IF([test "x$enable_debug" = "xyes"],
[wd_debug=true],
[wd_debug=false])
],
[wd_debug=false]
)
AM_CONDITIONAL([WD_DEBUG], [test "x$wd_debug" = "xtrue"])

AC_ARG_ENABLE([perf],
AS_HELP_STRING([--disble-perf], [enable measuring performance]),
[ AS_IF([test "x$enable_perf" = "xyes"],
Expand Down
100 changes: 52 additions & 48 deletions drv/hash_mb/hash_mb.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include "hash_mb.h"
#include "../wd_drv.h"

#define MIN(a, b) (((a) > (b)) ? (b) : (a))
#define IPAD_VALUE 0x36
Expand Down Expand Up @@ -109,12 +110,20 @@ static void hash_mb_queue_uninit(struct wd_ctx_config_internal *config, int ctx_
int i;

for (i = 0; i < ctx_num; i++) {
if (strcmp(config->ctxs[i].drv->drv_name, "hash_mb") ||
config->ctxs[i].drv->calc_type != UADK_ALG_SVE_INSTR)
continue;

ctx = (struct wd_soft_ctx *)config->ctxs[i].ctx;
mb_queue = ctx->priv;
if (!mb_queue)
continue;

pthread_spin_destroy(&mb_queue->r_lock);
hash_mb_uninit_poll_queue(&mb_queue->sm3_poll_queue);
hash_mb_uninit_poll_queue(&mb_queue->md5_poll_queue);
free(mb_queue);
ctx->priv = NULL;
}
}

Expand Down Expand Up @@ -143,11 +152,16 @@ static int hash_mb_queue_init(struct wd_ctx_config_internal *config)
int i, ret;

for (i = 0; i < ctx_num; i++) {
mb_queue = calloc(1, sizeof(struct hash_mb_queue));
if (strcmp(config->ctxs[i].drv->drv_name, "hash_mb") ||
config->ctxs[i].drv->calc_type != UADK_ALG_SVE_INSTR)
continue;

mb_queue = malloc(sizeof(struct hash_mb_queue));
if (!mb_queue) {
ret = -WD_ENOMEM;
goto free_mb_queue;
}
memset(mb_queue, 0, sizeof(struct hash_mb_queue));

mb_queue->ctx_mode = config->ctxs[i].ctx_mode;
ctx = (struct wd_soft_ctx *)config->ctxs[i].ctx;
Expand All @@ -168,9 +182,6 @@ static int hash_mb_queue_init(struct wd_ctx_config_internal *config)

mb_queue->sm3_poll_queue.ops = &sm3_ops;
mb_queue->md5_poll_queue.ops = &md5_ops;
mb_queue->recv_head = NULL;
mb_queue->recv_tail = NULL;
mb_queue->complete_cnt = 0;
}

return WD_SUCCESS;
Expand All @@ -186,46 +197,34 @@ static int hash_mb_queue_init(struct wd_ctx_config_internal *config)
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,
Expand Down Expand Up @@ -267,7 +266,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;
}
}

Expand Down Expand Up @@ -555,7 +554,21 @@ 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 void hash_mb_add_finish_job(struct hash_mb_queue *mb_queue, struct hash_job *job)
{
pthread_spin_lock(&mb_queue->r_lock);
if (mb_queue->complete_cnt) {
mb_queue->recv_tail->next = job;
mb_queue->recv_tail = job;
} else {
mb_queue->recv_head = job;
mb_queue->recv_tail = job;
}
mb_queue->complete_cnt++;
pthread_spin_unlock(&mb_queue->r_lock);
}

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;
Expand Down Expand Up @@ -597,8 +610,10 @@ static int hash_mb_send(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg)
/* If block not need process, return directly. */
ret = hash_do_partial(poll_queue, d_msg, hash_job);
if (ret == -WD_EAGAIN) {
if (mb_queue->ctx_mode == CTX_MODE_ASYNC)
free(hash_job);
if (mb_queue->ctx_mode == CTX_MODE_ASYNC) {
hash_job->msg = d_msg;
hash_mb_add_finish_job(mb_queue, hash_job);
}

d_msg->result = WD_SUCCESS;
return WD_SUCCESS;
Expand Down Expand Up @@ -691,20 +706,6 @@ static struct hash_job *hash_mb_get_job(struct hash_mb_poll_queue *poll_queue)
return job;
}

static void hash_mb_add_finish_job(struct hash_mb_queue *mb_queue, struct hash_job *job)
{
pthread_spin_lock(&mb_queue->r_lock);
if (mb_queue->complete_cnt) {
mb_queue->recv_tail->next = job;
mb_queue->recv_tail = job;
} else {
mb_queue->recv_head = job;
mb_queue->recv_tail = job;
}
mb_queue->complete_cnt++;
pthread_spin_unlock(&mb_queue->r_lock);
}

static struct hash_mb_poll_queue *hash_get_poll_queue(struct hash_mb_queue *mb_queue)
{
if (!mb_queue->sm3_poll_queue.job_num &&
Expand Down Expand Up @@ -776,7 +777,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;
Expand Down Expand Up @@ -810,6 +811,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,\
Expand All @@ -818,6 +820,8 @@ static int hash_mb_get_usage(void *param)
.send = hash_mb_send,\
.recv = hash_mb_recv,\
.get_usage = hash_mb_get_usage,\
.alloc_ctx = wd_soft_alloc_ctx,\
.free_ctx = wd_soft_free_ctx,\
}

static struct wd_alg_driver hash_mb_driver[] = {
Expand Down
Loading
Loading