1. dump BD when BD checks fail. 2. some cleanups.
Kai Ye (2): uadk: add wd_<alg>_get_msg() drv/hpre: support dump BD when BD checks fail
Weili Qian (8): drv/hpre: remove repeatedly included header file drv/hpre: add hpre_result_check() drv/hpre: move format check to is_hpre_bin_fmt() drv/hpre: change the parameter type drv/hpre: remove redundant blank line drv/qm: add unlikely() for branch prefetch drv/qm: remove redundant add 1 drv/qm: remove useless parameter 'sq_head_index'
drv/hisi_hpre.c | 187 +++++++++++++++++++++++++-------------- drv/hisi_qm_udrv.c | 17 ++-- include/drv/wd_dh_drv.h | 1 + include/drv/wd_ecc_drv.h | 1 + include/drv/wd_rsa_drv.h | 3 + include/hisi_qm_udrv.h | 1 - wd_dh.c | 5 ++ wd_ecc.c | 5 ++ wd_rsa.c | 5 ++ 9 files changed, 149 insertions(+), 76 deletions(-)
Some header files have included in hisi_qm_udrv.h, remove them from hisi_hpre.c.
Signed-off-by: Weili Qian qianweili@huawei.com --- drv/hisi_hpre.c | 10 ++-------- include/drv/wd_rsa_drv.h | 2 ++ 2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index d503d84..16bb322 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -2,19 +2,13 @@ /* Copyright 2020-2021 Huawei Technologies Co.,Ltd. All rights reserved. */
#include <stdlib.h> -#include <unistd.h> #include <stdio.h> -#include <sys/mman.h> -#include <assert.h> -#include <string.h> -#include <stdint.h> -#include <fcntl.h> -#include <sys/stat.h> +#include <unistd.h> #include <sys/epoll.h> #include <sys/eventfd.h> +#include <sys/mman.h> #include <sys/types.h> #include "hisi_qm_udrv.h" -#include "wd.h" #include "../include/drv/wd_rsa_drv.h" #include "../include/drv/wd_dh_drv.h" #include "../include/drv/wd_ecc_drv.h" diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h index 28c3337..83f1af2 100644 --- a/include/drv/wd_rsa_drv.h +++ b/include/drv/wd_rsa_drv.h @@ -3,6 +3,8 @@ #ifndef __WD_RSA_DRV_H #define __WD_RSA_DRV_H
+#include <asm/types.h> + #include "../wd_rsa.h"
#ifdef __cplusplus
When process recv completed task from hardware, driver will check BD status. The check logic for ECC/DH/RSA is the same. Therefore, call hpre_resut_check() to check the BD status to reduce duplicate code.
Signed-off-by: Weili Qian qianweili@huawei.com --- drv/hisi_hpre.c | 75 ++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 45 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index 16bb322..cec1578 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -526,6 +526,25 @@ static int rsa_send(handle_t ctx, void *rsa_msg) return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt); }
+static void hpre_result_check(struct hisi_hpre_sqe *hw_msg, + __u8 *result) +{ + *result = WD_SUCCESS; + + if (hw_msg->done != HPRE_HW_TASK_DONE || + hw_msg->etype || hw_msg->etype1) { + WD_ERR("failed to do hpre task! done=0x%x, etype=0x%x, etype1=0x%x!\n", + hw_msg->done, hw_msg->etype, hw_msg->etype1); + if (hw_msg->etype1 & HPRE_HW_SVA_ERROR) + WD_ERR("failed to SVA prefetch: status=%u!\n", + hw_msg->sva_status); + if (hw_msg->done == HPRE_HW_TASK_INIT) + *result = WD_EINVAL; + else + *result = WD_IN_EPARA; + } +} + static int rsa_recv(handle_t ctx, void *rsa_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); @@ -542,25 +561,13 @@ static int rsa_recv(handle_t ctx, void *rsa_msg) if (ret) return ret;
- if (hw_msg.done != HPRE_HW_TASK_DONE || - hw_msg.etype || hw_msg.etype1) { - WD_ERR("failed to do rsa task! done=0x%x, etype=0x%x, etype1=0x%x!\n", - hw_msg.done, hw_msg.etype, hw_msg.etype1); - if (hw_msg.etype1 & HPRE_HW_SVA_ERROR) - WD_ERR("failed to SVA prefetch: status=%u!\n", - hw_msg.sva_status); - if (hw_msg.done == HPRE_HW_TASK_INIT) - msg->result = WD_EINVAL; - else - msg->result = WD_IN_EPARA; - } else { - msg->tag = LW_U16(hw_msg.low_tag); + msg->tag = LW_U16(hw_msg.low_tag); + hpre_result_check(&hw_msg, &msg->result); + if (!msg->result) { ret = rsa_out_transfer(msg, &hw_msg); if (ret) { WD_ERR("failed to transfer out rsa BD!\n"); msg->result = WD_OUT_EPARA; - } else { - msg->result = WD_SUCCESS; } }
@@ -691,25 +698,13 @@ static int dh_recv(handle_t ctx, void *dh_msg) if (ret) return ret;
- if (hw_msg.done != HPRE_HW_TASK_DONE || - hw_msg.etype || hw_msg.etype1) { - WD_ERR("failed to do dh task! done=0x%x, etype=0x%x, etype1=0x%x!\n", - hw_msg.done, hw_msg.etype, hw_msg.etype1); - if (hw_msg.etype1 & HPRE_HW_SVA_ERROR) - WD_ERR("failed to SVA prefetch: status=%u!\n", - hw_msg.sva_status); - if (hw_msg.done == HPRE_HW_TASK_INIT) - msg->result = WD_EINVAL; - else - msg->result = WD_IN_EPARA; - } else { - msg->tag = LW_U16(hw_msg.low_tag); + msg->tag = LW_U16(hw_msg.low_tag); + hpre_result_check(&hw_msg, &msg->result); + if (!msg->result) { ret = dh_out_transfer(msg, &hw_msg); if (ret) { WD_ERR("failed to transfer out dh BD!\n"); msg->result = WD_OUT_EPARA; - } else { - msg->result = WD_SUCCESS; } }
@@ -2186,26 +2181,16 @@ static int ecc_sqe_parse(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg) { int ret;
- if (hw_msg->done != HPRE_HW_TASK_DONE || - hw_msg->etype || hw_msg->etype1) { - WD_ERR("failed to do ecc task! done=0x%x, etype=0x%x, etype1=0x%x!\n", - hw_msg->done, hw_msg->etype, hw_msg->etype1); - if (hw_msg->etype1 & HPRE_HW_SVA_ERROR) - WD_ERR("failed to SVA prefetch: status=%u!\n", - hw_msg->sva_status); - - if (hw_msg->done == HPRE_HW_TASK_INIT) - ret = -WD_EINVAL; - else - ret = -WD_IN_EPARA; - } else { - msg->result = WD_SUCCESS; + msg->tag = LW_U16(hw_msg->low_tag); + hpre_result_check(hw_msg, &msg->result); + if (!msg->result) { ret = ecc_out_transfer(msg, hw_msg); if (ret) { msg->result = WD_OUT_EPARA; WD_ERR("failed to transfer out ecc BD, ret = %d!\n", ret); } - msg->tag = LW_U16(hw_msg->low_tag); + } else { + ret = -msg->result; }
return ret;
Move the check format from crypto_bin_to_hpre_bin() to is_hpre_bin_fmt(), all check are done by is_hpre_bin_fmt().
Signed-off-by: Weili Qian qianweili@huawei.com --- drv/hisi_hpre.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index cec1578..bb8b4ab 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -100,18 +100,24 @@ struct hisi_hpre_ctx { struct wd_ctx_config_internal config; };
-static bool is_hpre_bin_fmt(const char *data, int dsz, int bsz) +static bool is_hpre_bin_fmt(char *dst, const char *src, int dsz, int bsz) { - const char *temp = data + dsz; + const char *temp = src + dsz; int lens = bsz - dsz; int i = 0;
+ if (!lens) + return true; + while (i < lens) { - if (temp[i] && !data[i]) - return true; + if (temp[i] && !src[i]) + break; i++; }
+ if (dst == src && i != lens) + return true; + return false; }
@@ -119,7 +125,6 @@ static int crypto_bin_to_hpre_bin(char *dst, const char *src, __u32 b_size, __u32 d_size, const char *p_name) { int i = d_size - 1; - bool is_hpre_bin; int j;
if (!dst || !src || b_size <= 0 || d_size <= 0) { @@ -132,8 +137,7 @@ static int crypto_bin_to_hpre_bin(char *dst, const char *src, return -WD_EINVAL; }
- is_hpre_bin = is_hpre_bin_fmt(src, d_size, b_size); - if (b_size == d_size || (dst == src && is_hpre_bin)) + if (is_hpre_bin_fmt(dst, src, d_size, b_size)) return WD_SUCCESS;
for (j = b_size - 1; j >= 0; j--, i--) {
Change the function parameter type to '__u32' because the input value by callers is not less than 0.
Signed-off-by: Weili Qian qianweili@huawei.com --- drv/hisi_hpre.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index bb8b4ab..44b117f 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -100,7 +100,7 @@ struct hisi_hpre_ctx { struct wd_ctx_config_internal config; };
-static bool is_hpre_bin_fmt(char *dst, const char *src, int dsz, int bsz) +static bool is_hpre_bin_fmt(char *dst, const char *src, __u32 dsz, __u32 bsz) { const char *temp = src + dsz; int lens = bsz - dsz; @@ -127,7 +127,7 @@ static int crypto_bin_to_hpre_bin(char *dst, const char *src, int i = d_size - 1; int j;
- if (!dst || !src || b_size <= 0 || d_size <= 0) { + if (!dst || !src || !b_size || !d_size) { WD_ERR("invalid: %s trans to hpre bin parameters err!\n", p_name); return -WD_EINVAL; } @@ -150,14 +150,14 @@ static int crypto_bin_to_hpre_bin(char *dst, const char *src, return WD_SUCCESS; }
-static int hpre_bin_to_crypto_bin(char *dst, const char *src, int b_size, +static int hpre_bin_to_crypto_bin(char *dst, const char *src, __u32 b_size, const char *p_name) { int i, cnt; int j = 0; int k = 0;
- if (!dst || !src || b_size <= 0) { + if (!dst || !src || !b_size) { WD_ERR("invalid: %s trans to crypto bin parameters err!\n", p_name); return 0; }
This patch removes redundant blank line from the hpre driver.
Signed-off-by: Weili Qian qianweili@huawei.com --- drv/hisi_hpre.c | 1 - 1 file changed, 1 deletion(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index 44b117f..175483b 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -766,7 +766,6 @@ static int ecc_prepare_alg(struct wd_ecc_msg *msg, return 0; }
- static int trans_cv_param_to_hpre_bin(struct wd_dtb *p, struct wd_dtb *a, struct wd_dtb *b, struct wd_dtb *n, struct wd_ecc_point *g)
Add unlikely() on the route of doing request to improve branch prefetch success rate.
Signed-off-by: Weili Qian qianweili@huawei.com --- drv/hisi_qm_udrv.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c index da756c4..48cd8c0 100644 --- a/drv/hisi_qm_udrv.c +++ b/drv/hisi_qm_udrv.c @@ -441,12 +441,12 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count) __u16 free_num, send_num; __u16 tail;
- if (!qp || !req || !count) + if (unlikely(!qp || !req || !count)) return -WD_EINVAL;
q_info = &qp->q_info;
- if (wd_ioread32(q_info->ds_tx_base) == 1) { + if (unlikely(wd_ioread32(q_info->ds_tx_base) == 1)) { WD_ERR("wd queue hw error happened before qm send!\n"); return -WD_HW_EACCESS; } @@ -487,7 +487,7 @@ static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, void *resp)
if (q_info->cqc_phase == CQE_PHASE(cqe)) { j = CQE_SQ_HEAD_INDEX(cqe); - if (j >= QM_Q_DEPTH) { + if (unlikely(j >= QM_Q_DEPTH)) { pthread_spin_unlock(&q_info->rv_lock); WD_DEV_ERR(qp->h_ctx, "CQE_SQ_HEAD_INDEX(%u) error!\n", j); return -WD_EIO; @@ -525,14 +525,14 @@ int hisi_qm_recv(handle_t h_qp, void *resp, __u16 expect, __u16 *count) int recv_num = 0; int i, ret, offset;
- if (!resp || !qp || !count) + if (unlikely(!resp || !qp || !count)) return -WD_EINVAL;
- if (!expect) + if (unlikely(!expect)) return 0;
q_info = &qp->q_info; - if (wd_ioread32(q_info->ds_rx_base) == 1) { + if (unlikely(wd_ioread32(q_info->ds_rx_base) == 1)) { WD_DEV_ERR(qp->h_ctx, "wd queue hw error happened before qm receive!\n"); return -WD_HW_EACCESS; } @@ -546,7 +546,7 @@ int hisi_qm_recv(handle_t h_qp, void *resp, __u16 expect, __u16 *count) }
*count = recv_num++; - if (wd_ioread32(q_info->ds_rx_base) == 1) { + if (unlikely(wd_ioread32(q_info->ds_rx_base) == 1)) { WD_DEV_ERR(qp->h_ctx, "wd queue hw error happened in qm receive!\n"); return -WD_HW_EACCESS; }
The variable 'recv_num' is no longer used, remove redundant add 1;
Signed-off-by: Weili Qian qianweili@huawei.com --- drv/hisi_qm_udrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c index 48cd8c0..b1cb4f2 100644 --- a/drv/hisi_qm_udrv.c +++ b/drv/hisi_qm_udrv.c @@ -545,7 +545,7 @@ int hisi_qm_recv(handle_t h_qp, void *resp, __u16 expect, __u16 *count) recv_num++; }
- *count = recv_num++; + *count = recv_num; if (unlikely(wd_ioread32(q_info->ds_rx_base) == 1)) { WD_DEV_ERR(qp->h_ctx, "wd queue hw error happened in qm receive!\n"); return -WD_HW_EACCESS;
The 'sq_head_index' is operated by the accelerator hardware, and is useless to the driver. Therefore, remove 'sq_head_index'.
Signed-off-by: Weili Qian qianweili@huawei.com --- drv/hisi_qm_udrv.c | 1 - include/hisi_qm_udrv.h | 1 - 2 files changed, 2 deletions(-)
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c index b1cb4f2..71c4c25 100644 --- a/drv/hisi_qm_udrv.c +++ b/drv/hisi_qm_udrv.c @@ -510,7 +510,6 @@ static int hisi_qm_recv_single(struct hisi_qm_queue_info *q_info, void *resp)
/* only support one thread poll one queue, so no need protect */ q_info->cq_head_index = i; - q_info->sq_head_index = i;
__atomic_sub_fetch(&q_info->used_num, 1, __ATOMIC_RELAXED); pthread_spin_unlock(&q_info->rv_lock); diff --git a/include/hisi_qm_udrv.h b/include/hisi_qm_udrv.h index 92333ed..22dedf3 100644 --- a/include/hisi_qm_udrv.h +++ b/include/hisi_qm_udrv.h @@ -67,7 +67,6 @@ struct hisi_qm_queue_info { void *ds_rx_base; __u8 qp_mode; __u16 sq_tail_index; - __u16 sq_head_index; __u16 cq_head_index; __u16 sqn; __u16 qc_type;
From: Kai Ye yekai13@huawei.com
Add wd_<alg>_get_msg() for driver to obtain the sent message by the user.
Signed-off-by: Kai Ye yekai13@huawei.com Signed-off-by: Weili Qian qianweili@huawei.com --- include/drv/wd_dh_drv.h | 1 + include/drv/wd_ecc_drv.h | 1 + include/drv/wd_rsa_drv.h | 1 + wd_dh.c | 5 +++++ wd_ecc.c | 5 +++++ wd_rsa.c | 5 +++++ 6 files changed, 18 insertions(+)
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h index f8e3065..57f774d 100644 --- a/include/drv/wd_dh_drv.h +++ b/include/drv/wd_dh_drv.h @@ -36,6 +36,7 @@ struct wd_dh_driver {
void wd_dh_set_driver(struct wd_dh_driver *drv); struct wd_dh_driver *wd_dh_get_driver(void); +struct wd_dh_msg *wd_dh_get_msg(__u32 idx, __u32 tag);
#ifdef WD_STATIC_DRV #define WD_DH_SET_DRIVER(drv) \ diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h index 857da20..ddf5e5b 100644 --- a/include/drv/wd_ecc_drv.h +++ b/include/drv/wd_ecc_drv.h @@ -188,6 +188,7 @@ struct wd_ecc_driver {
void wd_ecc_set_driver(struct wd_ecc_driver *drv); struct wd_ecc_driver *wd_ecc_get_driver(void); +struct wd_ecc_msg *wd_ecc_get_msg(__u32 idx, __u32 tag);
#ifdef WD_STATIC_DRV #define WD_ECC_SET_DRIVER(drv) \ diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h index 83f1af2..108c2a3 100644 --- a/include/drv/wd_rsa_drv.h +++ b/include/drv/wd_rsa_drv.h @@ -61,6 +61,7 @@ struct wd_rsa_driver {
void wd_rsa_set_driver(struct wd_rsa_driver *drv); struct wd_rsa_driver *wd_rsa_get_driver(void); +struct wd_rsa_msg *wd_rsa_get_msg(__u32 idx, __u32 tag);
#ifdef WD_STATIC_DRV #define WD_RSA_SET_DRIVER(drv) \ diff --git a/wd_dh.c b/wd_dh.c index 461f04e..cfe294d 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -290,6 +290,11 @@ fail_with_msg: return ret; }
+struct wd_dh_msg *wd_dh_get_msg(__u32 idx, __u32 tag) +{ + return wd_find_msg_in_pool(&wd_dh_setting.pool, idx, tag); +} + int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count) { struct wd_ctx_config_internal *config = &wd_dh_setting.config; diff --git a/wd_ecc.c b/wd_ecc.c index 4cf287b..a550e1a 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -2119,6 +2119,11 @@ fail_with_msg: return ret; }
+struct wd_ecc_msg *wd_ecc_get_msg(__u32 idx, __u32 tag) +{ + return wd_find_msg_in_pool(&wd_ecc_setting.pool, idx, tag); +} + int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count) { struct wd_ctx_config_internal *config = &wd_ecc_setting.config; diff --git a/wd_rsa.c b/wd_rsa.c index e76da09..d65b01d 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -349,6 +349,11 @@ fail_with_msg: return ret; }
+struct wd_rsa_msg *wd_rsa_get_msg(__u32 idx, __u32 tag) +{ + return wd_find_msg_in_pool(&wd_rsa_setting.pool, idx, tag); +} + int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count) { struct wd_ctx_config_internal *config = &wd_rsa_setting.config;
From: Kai Ye yekai13@huawei.com
When BD parsing fails, BD can be dumped.
Signed-off-by: Kai Ye yekai13@huawei.com Signed-off-by: Weili Qian qianweili@huawei.com --- drv/hisi_hpre.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 5 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index 175483b..8aaa064 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -100,6 +100,27 @@ struct hisi_hpre_ctx { struct wd_ctx_config_internal config; };
+static void dump_hpre_msg(void *msg, const char *s) +{ + struct wd_rsa_msg *rsa_msg; + struct wd_ecc_msg *ecc_msg; + struct wd_dh_msg *dh_msg; + + WD_ERR("dump %s alg message after a task error occurs.\n", s); + + if (!strcmp(s, "rsa")) { + rsa_msg = (struct wd_rsa_msg *)msg; + WD_ERR("key_bytes:%u key_type:%u\n", rsa_msg->key_bytes, rsa_msg->key_type); + } else if (!strcmp(s, "ecc")) { + ecc_msg = (struct wd_ecc_msg *)msg; + WD_ERR("key_bytes:%u curve_id:%u\n", ecc_msg->key_bytes, ecc_msg->curve_id); + } else if (!strcmp(s, "dh")) { + dh_msg = (struct wd_dh_msg *)msg; + WD_ERR("gbytes:%u key_bytes:%u is_g2:%u\n", dh_msg->gbytes, + dh_msg->key_bytes, dh_msg->is_g2); + } +} + static bool is_hpre_bin_fmt(char *dst, const char *src, __u32 dsz, __u32 bsz) { const char *temp = src + dsz; @@ -552,8 +573,10 @@ static void hpre_result_check(struct hisi_hpre_sqe *hw_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; struct hisi_hpre_sqe hw_msg = {0}; struct wd_rsa_msg *msg = rsa_msg; + struct wd_rsa_msg *temp_msg; __u16 recv_cnt = 0; int ret;
@@ -566,6 +589,17 @@ static int rsa_recv(handle_t ctx, void *rsa_msg) return ret;
msg->tag = LW_U16(hw_msg.low_tag); + if (qp->q_info.qp_mode == CTX_MODE_ASYNC) { + temp_msg = wd_rsa_get_msg(qp->q_info.idx, msg->tag); + if (!temp_msg) { + WD_ERR("failed to get send msg! idx = %u, tag = %u.\n", + qp->q_info.idx, msg->tag); + return -WD_EINVAL; + } + } else { + temp_msg = msg; + } + hpre_result_check(&hw_msg, &msg->result); if (!msg->result) { ret = rsa_out_transfer(msg, &hw_msg); @@ -575,6 +609,9 @@ static int rsa_recv(handle_t ctx, void *rsa_msg) } }
+ if (unlikely(msg->result != WD_SUCCESS)) + dump_hpre_msg(temp_msg, "rsa"); + return 0; }
@@ -689,8 +726,10 @@ static int dh_send(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; struct wd_dh_msg *msg = dh_msg; struct hisi_hpre_sqe hw_msg = {0}; + struct wd_dh_msg *temp_msg; __u16 recv_cnt = 0; int ret;
@@ -703,6 +742,17 @@ static int dh_recv(handle_t ctx, void *dh_msg) return ret;
msg->tag = LW_U16(hw_msg.low_tag); + if (qp->q_info.qp_mode == CTX_MODE_ASYNC) { + temp_msg = wd_dh_get_msg(qp->q_info.idx, msg->tag); + if (!temp_msg) { + WD_ERR("failed to get send msg! idx = %u, tag = %u.\n", + qp->q_info.idx, msg->tag); + return -WD_EINVAL; + } + } else { + temp_msg = msg; + } + hpre_result_check(&hw_msg, &msg->result); if (!msg->result) { ret = dh_out_transfer(msg, &hw_msg); @@ -712,6 +762,9 @@ static int dh_recv(handle_t ctx, void *dh_msg) } }
+ if (unlikely(msg->result != WD_SUCCESS)) + dump_hpre_msg(temp_msg, "dh"); + return 0; }
@@ -2180,22 +2233,42 @@ static int sm2_convert_dec_out(struct wd_ecc_msg *src, return ret; }
-static int ecc_sqe_parse(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg) +static int ecc_sqe_parse(struct hisi_qp *qp, struct wd_ecc_msg *msg, + struct hisi_hpre_sqe *hw_msg) { + struct wd_ecc_msg *temp_msg; int ret;
msg->tag = LW_U16(hw_msg->low_tag); + if (qp->q_info.qp_mode == CTX_MODE_ASYNC) { + temp_msg = wd_ecc_get_msg(qp->q_info.idx, msg->tag); + if (!temp_msg) { + WD_ERR("failed to get send msg! idx = %u, tag = %u.\n", + qp->q_info.idx, msg->tag); + return -WD_EINVAL; + } + } else { + temp_msg = msg; + } + hpre_result_check(hw_msg, &msg->result); if (!msg->result) { ret = ecc_out_transfer(msg, hw_msg); if (ret) { msg->result = WD_OUT_EPARA; WD_ERR("failed to transfer out ecc BD, ret = %d!\n", ret); + goto dump_err_msg; } } else { ret = -msg->result; + goto dump_err_msg; }
+ return ret; + +dump_err_msg: + dump_hpre_msg(temp_msg, "ecc"); + return ret; }
@@ -2229,7 +2302,7 @@ static int parse_second_sqe(handle_t h_qp, dst = *(struct wd_ecc_msg **)((uintptr_t)data + hsz * ECDH_OUT_PARAM_NUM); hw_msg.low_tag = 0; /* use sync mode */ - ret = ecc_sqe_parse(dst, &hw_msg); + ret = ecc_sqe_parse((struct hisi_qp *)h_qp, dst, &hw_msg); msg->result = dst->result; *second = dst;
@@ -2255,7 +2328,7 @@ static int sm2_enc_parse(handle_t h_qp,
/* parse first sqe */ hw_msg->low_tag = 0; /* use sync mode */ - ret = ecc_sqe_parse(first, hw_msg); + ret = ecc_sqe_parse((struct hisi_qp *)h_qp, first, hw_msg); if (ret) { WD_ERR("failed to parse first BD, ret = %d!\n", ret); goto free_first; @@ -2299,7 +2372,7 @@ static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
/* parse first sqe */ hw_msg->low_tag = 0; /* use sync mode */ - ret = ecc_sqe_parse(dst, hw_msg); + ret = ecc_sqe_parse((struct hisi_qp *)ctx, dst, hw_msg); if (ret) { WD_ERR("failed to parse decode BD, ret = %d!\n", ret); goto fail; @@ -2342,7 +2415,7 @@ static int ecc_recv(handle_t ctx, void *ecc_msg) hw_msg.sm2_mlen == HPRE_SM2_DEC) return sm2_dec_parse(h_qp, msg, &hw_msg);
- return ecc_sqe_parse(msg, &hw_msg); + return ecc_sqe_parse((struct hisi_qp *)h_qp, msg, &hw_msg); }
static struct wd_ecc_driver ecc_hisi_hpre = {