test:
digest: uadk_tool benchmark --alg aes-128-ecb --mode sva --opt 0 \ --sync --pktlen 1024 --seconds 1 --multi 1 --thread 1 uadk_tool benchmark --alg aes-128-ecb --mode sva --opt 0 \ --async --pktlen 1024 --seconds 1 --multi 1 --thread 1
cipher: uadk_tool benchmark --alg sm4-128-cbc --mode sva --opt 0 \ --sync --pktlen 1024 --seconds 1 --multi 1 --thread 1 uadk_tool benchmark --alg sm4-128-cbc --mode sva --opt 0 \ --async --pktlen 1024 --seconds 1 --multi 1 --thread 1
Signed-off-by: Zhangfei Gao zhangfei.gao@linaro.org --- drv/hisi_sec.c | 57 ++++++++++++++++++++++++++----------- include/drv/wd_cipher_drv.h | 2 ++ include/drv/wd_digest_drv.h | 2 ++ include/wd_cipher.h | 2 ++ include/wd_digest.h | 2 ++ libwd_crypto.map | 2 ++ wd_cipher.c | 52 +++++++++++++++++++++++++++++++-- wd_digest.c | 45 +++++++++++++++++++++++++++-- 8 files changed, 142 insertions(+), 22 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index a305985..1e5d7b2 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -916,10 +916,17 @@ static int fill_cipher_bd2_mode(struct wd_cipher_msg *msg, static void fill_cipher_bd2_addr(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe) { - sqe->type2.data_src_addr = (__u64)(uintptr_t)msg->in; - sqe->type2.data_dst_addr = (__u64)(uintptr_t)msg->out; - sqe->type2.c_ivin_addr = (__u64)(uintptr_t)msg->iv; - sqe->type2.c_key_addr = (__u64)(uintptr_t)msg->key; + if (msg->blkpool) { + sqe->type2.data_src_addr = (__u64)(uintptr_t)wd_blkpool_phy(msg->blkpool, msg->in); + sqe->type2.data_dst_addr = (__u64)(uintptr_t)wd_blkpool_phy(msg->blkpool, msg->out); + sqe->type2.c_ivin_addr = (__u64)(uintptr_t)wd_blkpool_phy(msg->blkpool, msg->iv); + sqe->type2.c_key_addr = (__u64)(uintptr_t)wd_blkpool_phy(msg->blkpool, msg->key); + } else { + sqe->type2.data_src_addr = (__u64)(uintptr_t)msg->in; + sqe->type2.data_dst_addr = (__u64)(uintptr_t)msg->out; + sqe->type2.c_ivin_addr = (__u64)(uintptr_t)msg->iv; + sqe->type2.c_key_addr = (__u64)(uintptr_t)msg->key; + } }
static void parse_cipher_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe, @@ -944,8 +951,6 @@ static void parse_cipher_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe, if (qp->q_info.qp_mode == CTX_MODE_ASYNC) { recv_msg->alg_type = WD_CIPHER; 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_cipher_get_msg(qp->q_info.idx, tag); if (!temp_msg) { recv_msg->result = WD_IN_EPARA; @@ -953,6 +958,8 @@ static void parse_cipher_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe, qp->q_info.idx, tag); return; } + recv_msg->in = temp_msg->in; + recv_msg->out = temp_msg->out; } else { /* The synchronization mode uses the same message */ temp_msg = recv_msg; @@ -1318,10 +1325,17 @@ static int fill_cipher_bd3_mode(struct wd_cipher_msg *msg, static void fill_cipher_bd3_addr(struct wd_cipher_msg *msg, struct hisi_sec_sqe3 *sqe) { - sqe->data_src_addr = (__u64)(uintptr_t)msg->in; - sqe->data_dst_addr = (__u64)(uintptr_t)msg->out; - sqe->no_scene.c_ivin_addr = (__u64)(uintptr_t)msg->iv; - sqe->c_key_addr = (__u64)(uintptr_t)msg->key; + if (msg->blkpool) { + sqe->data_src_addr = (__u64)(uintptr_t)wd_blkpool_phy(msg->blkpool, msg->in); + sqe->data_dst_addr = (__u64)(uintptr_t)wd_blkpool_phy(msg->blkpool, msg->out); + sqe->no_scene.c_ivin_addr = (__u64)(uintptr_t)wd_blkpool_phy(msg->blkpool, msg->iv); + sqe->c_key_addr = (__u64)(uintptr_t)wd_blkpool_phy(msg->blkpool, msg->key); + } else { + sqe->data_src_addr = (__u64)(uintptr_t)msg->in; + sqe->data_dst_addr = (__u64)(uintptr_t)msg->out; + sqe->no_scene.c_ivin_addr = (__u64)(uintptr_t)msg->iv; + sqe->c_key_addr = (__u64)(uintptr_t)msg->key; + } }
static int fill_cipher_bd3(struct wd_cipher_msg *msg, struct hisi_sec_sqe3 *sqe) @@ -1429,8 +1443,6 @@ static void parse_cipher_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, if (qp->q_info.qp_mode == CTX_MODE_ASYNC) { recv_msg->alg_type = WD_CIPHER; 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_cipher_get_msg(qp->q_info.idx, tag); if (!temp_msg) { recv_msg->result = WD_IN_EPARA; @@ -1438,6 +1450,8 @@ static void parse_cipher_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, qp->q_info.idx, tag); return; } + recv_msg->in = temp_msg->in; + recv_msg->out = temp_msg->out; } else { /* The synchronization mode uses the same message */ temp_msg = recv_msg; @@ -1597,7 +1611,6 @@ static void parse_digest_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe, if (qp->q_info.qp_mode == CTX_MODE_ASYNC) { recv_msg->alg_type = WD_DIGEST; recv_msg->data_fmt = get_data_fmt_v2(sqe->sds_sa_type); - recv_msg->in = (__u8 *)(uintptr_t)sqe->type2.data_src_addr; temp_msg = wd_digest_get_msg(qp->q_info.idx, recv_msg->tag); if (!temp_msg) { recv_msg->result = WD_IN_EPARA; @@ -1742,8 +1755,13 @@ static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *w
sqe.sds_sa_type |= (__u8)(de | scene); sqe.type2.alen_ivllen |= (__u32)msg->in_bytes; - sqe.type2.data_src_addr = (__u64)(uintptr_t)msg->in; - sqe.type2.mac_addr = (__u64)(uintptr_t)msg->out; + if (msg->blkpool) { + sqe.type2.data_src_addr = (__u64)(uintptr_t)wd_blkpool_phy(msg->blkpool, msg->in); + sqe.type2.mac_addr = (__u64)(uintptr_t)wd_blkpool_phy(msg->blkpool, msg->out); + } else { + sqe.type2.data_src_addr = (__u64)(uintptr_t)msg->in; + sqe.type2.mac_addr = (__u64)(uintptr_t)msg->out; + }
ret = fill_digest_bd2_alg(msg, &sqe); if (ret) @@ -1977,8 +1995,13 @@ static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void }
sqe.a_len_key = (__u32)msg->in_bytes; - sqe.data_src_addr = (__u64)(uintptr_t)msg->in; - sqe.mac_addr = (__u64)(uintptr_t)msg->out; + if (msg->blkpool) { + sqe.data_src_addr = (__u64)(uintptr_t)wd_blkpool_phy(msg->blkpool, msg->in); + sqe.mac_addr = (__u64)(uintptr_t)wd_blkpool_phy(msg->blkpool, msg->out); + } else { + sqe.data_src_addr = (__u64)(uintptr_t)msg->in; + sqe.mac_addr = (__u64)(uintptr_t)msg->out; + }
ret = fill_digest_bd3_alg(msg, &sqe); if (ret) diff --git a/include/drv/wd_cipher_drv.h b/include/drv/wd_cipher_drv.h index c6d8ddf..b0da45a 100644 --- a/include/drv/wd_cipher_drv.h +++ b/include/drv/wd_cipher_drv.h @@ -48,6 +48,8 @@ struct wd_cipher_msg { __u8 *in; /* output data pointer */ __u8 *out; + void *blkpool; + handle_t h_sgl_pool; };
struct wd_cipher_msg *wd_cipher_get_msg(__u32 idx, __u32 tag); diff --git a/include/drv/wd_digest_drv.h b/include/drv/wd_digest_drv.h index a55ef5b..5e693ae 100644 --- a/include/drv/wd_digest_drv.h +++ b/include/drv/wd_digest_drv.h @@ -59,6 +59,8 @@ struct wd_digest_msg { __u8 *partial_block; /* total of data for stream mode */ __u64 long_data_len; + void *blkpool; + handle_t h_sgl_pool; };
static inline enum hash_block_type get_hash_block_type(struct wd_digest_msg *msg) diff --git a/include/wd_cipher.h b/include/wd_cipher.h index d54f7fe..acb99a5 100644 --- a/include/wd_cipher.h +++ b/include/wd_cipher.h @@ -10,6 +10,7 @@ #include <dlfcn.h> #include <asm/types.h> #include "wd_alg_common.h" +#include "wd_bmm.h"
#ifdef __cplusplus extern "C" { @@ -220,6 +221,7 @@ void wd_cipher_ctx_num_uninit(void); int wd_cipher_get_env_param(__u32 node, __u32 type, __u32 mode, __u32 *num, __u8 *is_enable);
+void *wd_cipher_setup_blkpool(struct wd_blkpool_setup *setup); #ifdef __cplusplus } #endif diff --git a/include/wd_digest.h b/include/wd_digest.h index 6ce31f2..e130ea0 100644 --- a/include/wd_digest.h +++ b/include/wd_digest.h @@ -9,6 +9,7 @@ #include <dlfcn.h>
#include "wd_alg_common.h" +#include "wd_bmm.h"
#ifdef __cplusplus extern "C" { @@ -281,6 +282,7 @@ void wd_digest_ctx_num_uninit(void); int wd_digest_get_env_param(__u32 node, __u32 type, __u32 mode, __u32 *num, __u8 *is_enable);
+void *wd_digest_setup_blkpool(struct wd_blkpool_setup *setup); #ifdef __cplusplus } #endif diff --git a/libwd_crypto.map b/libwd_crypto.map index e8555c9..b430886 100644 --- a/libwd_crypto.map +++ b/libwd_crypto.map @@ -20,6 +20,7 @@ global: wd_cipher_set_driver; wd_cipher_get_driver; wd_cipher_get_msg; + wd_cipher_setup_blkpool;
wd_aead_init; wd_aead_uninit; @@ -66,6 +67,7 @@ global: wd_digest_set_driver; wd_digest_get_driver; wd_digest_get_msg; + wd_digest_setup_blkpool;
wd_rsa_is_crt; wd_rsa_get_key_bits; diff --git a/wd_cipher.c b/wd_cipher.c index 95d6eb6..4b0e637 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -66,6 +66,9 @@ struct wd_cipher_sess { unsigned char key[MAX_CIPHER_KEY_SIZE]; __u32 key_bytes; void *sched_key; + void *blkpool; + unsigned char *pool_key; + handle_t h_sgl_pool; };
struct wd_env_config wd_cipher_env_config; @@ -244,13 +247,36 @@ int wd_cipher_set_key(handle_t h_sess, const __u8 *key, __u32 key_len) }
sess->key_bytes = key_len; - memcpy(sess->key, key, key_len); + if (sess->pool_key) + memcpy(sess->pool_key, key, key_len); + else + memcpy(sess->key, key, key_len);
return 0; }
+void *wd_cipher_setup_blkpool(struct wd_blkpool_setup *setup) +{ + struct wd_ctx_config_internal *config = &wd_cipher_setting.config; + struct wd_ctx_internal *ctx = config->ctxs; + int ret; + + ret = wd_blkpool_setup(ctx->blkpool, setup); + if (ret) + return NULL; + + ctx->blkpool_mode = BLKPOOL_MODE_USER; + pthread_spin_lock(&ctx->lock); + if (ctx->h_sgl_pool == 0) + ctx->h_sgl_pool = wd_blkpool_create_sglpool(ctx->blkpool); + pthread_spin_unlock(&ctx->lock); + return ctx->blkpool; +} + handle_t wd_cipher_alloc_sess(struct wd_cipher_sess_setup *setup) { + struct wd_ctx_config_internal *config = &wd_cipher_setting.config; + struct wd_ctx_internal *ctx = config->ctxs; struct wd_cipher_sess *sess = NULL; bool ret;
@@ -289,6 +315,15 @@ handle_t wd_cipher_alloc_sess(struct wd_cipher_sess_setup *setup) goto free_sess; }
+ if (ctx->blkpool) { + sess->blkpool = ctx->blkpool; + sess->h_sgl_pool = ctx->h_sgl_pool; + + sess->pool_key = wd_blkpool_alloc(sess->blkpool, MAX_CIPHER_KEY_SIZE); + if (!sess->pool_key) + goto free_sess; + } + return (handle_t)sess;
free_sess: @@ -539,7 +574,10 @@ static void fill_request_msg(struct wd_cipher_msg *msg, msg->in_bytes = req->in_bytes; msg->out = req->dst; msg->out_bytes = req->out_bytes; - msg->key = sess->key; + if (sess->blkpool) + msg->key = sess->pool_key; + else + msg->key = sess->key; msg->key_bytes = sess->key_bytes; msg->iv = req->iv; msg->iv_bytes = req->iv_bytes; @@ -719,6 +757,11 @@ int wd_do_cipher_sync(handle_t h_sess, struct wd_cipher_req *req) wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx;
+ if (sess->blkpool) { + msg.blkpool = sess->blkpool; + msg.h_sgl_pool = sess->h_sgl_pool; + } + ret = send_recv_sync(ctx, &msg); req->state = msg.result;
@@ -759,6 +802,11 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req) fill_request_msg(msg, req, sess); msg->tag = msg_id;
+ if (sess->blkpool) { + msg->blkpool = sess->blkpool; + msg->h_sgl_pool = sess->h_sgl_pool; + } + ret = wd_alg_driver_send(wd_cipher_setting.driver, ctx->ctx, msg); if (unlikely(ret < 0)) { if (ret != -WD_EBUSY) diff --git a/wd_digest.c b/wd_digest.c index 4c1b0ca..696f1b0 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -68,6 +68,9 @@ struct wd_digest_sess { __u32 key_bytes; void *sched_key; struct wd_digest_stream_data stream_data; + void *blkpool; + unsigned char *pool_key; + handle_t h_sgl_pool; };
struct wd_env_config wd_digest_env_config; @@ -180,14 +183,38 @@ int wd_digest_set_key(handle_t h_sess, const __u8 *key, __u32 key_len) }
sess->key_bytes = key_len; - if (key_len) - memcpy(sess->key, key, key_len); + if (key_len) { + if (sess->pool_key) + memcpy(sess->pool_key, key, key_len); + else + memcpy(sess->key, key, key_len); + }
return 0; }
+void *wd_digest_setup_blkpool(struct wd_blkpool_setup *setup) +{ + struct wd_ctx_config_internal *config = &wd_digest_setting.config; + struct wd_ctx_internal *ctx = config->ctxs; + int ret; + + ret = wd_blkpool_setup(ctx->blkpool, setup); + if (ret) + return NULL; + + ctx->blkpool_mode = BLKPOOL_MODE_USER; + pthread_spin_lock(&ctx->lock); + if (ctx->h_sgl_pool == 0) + ctx->h_sgl_pool = wd_blkpool_create_sglpool(ctx->blkpool); + pthread_spin_unlock(&ctx->lock); + return ctx->blkpool; +} + handle_t wd_digest_alloc_sess(struct wd_digest_sess_setup *setup) { + struct wd_ctx_config_internal *config = &wd_digest_setting.config; + struct wd_ctx_internal *ctx = config->ctxs; struct wd_digest_sess *sess = NULL; bool ret;
@@ -222,6 +249,15 @@ handle_t wd_digest_alloc_sess(struct wd_digest_sess_setup *setup) goto err_sess; }
+ if (ctx->blkpool) { + sess->blkpool = ctx->blkpool; + sess->h_sgl_pool = ctx->h_sgl_pool; + + sess->pool_key = wd_blkpool_alloc(sess->blkpool, MAX_HMAC_KEY_SIZE); + if (!sess->pool_key) + goto err_sess; + } + return (handle_t)sess;
err_sess: @@ -589,7 +625,10 @@ static void fill_request_msg(struct wd_digest_msg *msg, msg->alg_type = WD_DIGEST; msg->alg = sess->alg; msg->mode = sess->mode; - msg->key = sess->key; + if (sess->blkpool) + msg->key = sess->pool_key; + else + msg->key = sess->key; msg->key_bytes = sess->key_bytes; msg->iv = req->iv; msg->in = req->in;