1252 lines
38 KiB
Diff
1252 lines
38 KiB
Diff
From 3fc344aa4f7c460269cd0d870fe388f01dfa22a2 Mon Sep 17 00:00:00 2001
|
|
From: Zhangfei Gao <zhangfei.gao@linaro.org>
|
|
Date: Wed, 19 Jul 2023 02:15:50 +0000
|
|
Subject: [PATCH 09/26] drivers alloc and free resources by themself
|
|
|
|
A driver should alloc and free resources by himself instead of the
|
|
caller, considering multi-driver exists, the caller can not hold ctxs
|
|
for all drivers, so drv.init malloc private ctx and drv.exit free.
|
|
|
|
Add driver as para of alg ops, not only for getting private ctx, but
|
|
easier for multi-driver support.
|
|
|
|
Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
|
|
---
|
|
drv/hisi_comp.c | 35 ++++++++++++++++++-------
|
|
drv/hisi_hpre.c | 67 +++++++++++++++++++++++++++++++++--------------
|
|
drv/hisi_sec.c | 56 +++++++++++++++++++++++----------------
|
|
include/wd_alg.h | 33 ++++++++++++++++++-----
|
|
include/wd_util.h | 14 +++++-----
|
|
wd_aead.c | 25 ++++++++++--------
|
|
wd_cipher.c | 20 +++++++-------
|
|
wd_comp.c | 20 +++++++-------
|
|
wd_dh.c | 20 +++++---------
|
|
wd_digest.c | 26 +++++++++---------
|
|
wd_ecc.c | 20 +++++---------
|
|
wd_rsa.c | 20 +++++---------
|
|
wd_util.c | 30 ++++++---------------
|
|
13 files changed, 212 insertions(+), 174 deletions(-)
|
|
|
|
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
|
|
index d6c0a2a..2cb9a6b 100644
|
|
--- a/drv/hisi_comp.c
|
|
+++ b/drv/hisi_comp.c
|
|
@@ -785,21 +785,30 @@ static void hisi_zip_sqe_ops_adapt(handle_t h_qp)
|
|
}
|
|
}
|
|
|
|
-static int hisi_zip_init(void *conf, void *priv)
|
|
+static int hisi_zip_init(struct wd_alg_driver *drv, void *conf)
|
|
{
|
|
+ struct hisi_zip_ctx *priv = (struct hisi_zip_ctx *)drv->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;
|
|
handle_t h_qp = 0;
|
|
handle_t h_ctx;
|
|
__u32 i, j;
|
|
|
|
+ if (priv) {
|
|
+ /* return if already inited */
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
if (!config->ctx_num) {
|
|
WD_ERR("invalid: zip init config ctx num is 0!\n");
|
|
return -WD_EINVAL;
|
|
}
|
|
|
|
- memcpy(&zip_ctx->config, config, sizeof(struct wd_ctx_config_internal));
|
|
+ priv = malloc(sizeof(struct hisi_zip_ctx));
|
|
+ if (!priv)
|
|
+ return -WD_EINVAL;
|
|
+
|
|
+ memcpy(&priv->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;
|
|
@@ -817,6 +826,7 @@ static int hisi_zip_init(void *conf, void *priv)
|
|
}
|
|
|
|
hisi_zip_sqe_ops_adapt(h_qp);
|
|
+ drv->priv = priv;
|
|
|
|
return 0;
|
|
out:
|
|
@@ -824,20 +834,28 @@ 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(void *priv)
|
|
+static void hisi_zip_exit(struct wd_alg_driver *drv)
|
|
{
|
|
- struct hisi_zip_ctx *zip_ctx = (struct hisi_zip_ctx *)priv;
|
|
- struct wd_ctx_config_internal *config = &zip_ctx->config;
|
|
+ struct hisi_zip_ctx *priv = (struct hisi_zip_ctx *)drv->priv;
|
|
+ struct wd_ctx_config_internal *config = &priv->config;
|
|
handle_t h_qp;
|
|
__u32 i;
|
|
|
|
+ if (!priv) {
|
|
+ /* return if already exit */
|
|
+ return;
|
|
+ }
|
|
+
|
|
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,
|
|
@@ -917,7 +935,7 @@ static void free_hw_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
|
}
|
|
}
|
|
|
|
-static int hisi_zip_comp_send(handle_t ctx, void *comp_msg)
|
|
+static int hisi_zip_comp_send(struct wd_alg_driver *drv, handle_t ctx, void *comp_msg)
|
|
{
|
|
struct hisi_qp *qp = wd_ctx_get_priv(ctx);
|
|
struct wd_comp_msg *msg = comp_msg;
|
|
@@ -1057,7 +1075,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
|
|
return 0;
|
|
}
|
|
|
|
-static int hisi_zip_comp_recv(handle_t ctx, void *comp_msg)
|
|
+static int hisi_zip_comp_recv(struct wd_alg_driver *drv, handle_t ctx, void *comp_msg)
|
|
{
|
|
struct hisi_qp *qp = wd_ctx_get_priv(ctx);
|
|
struct wd_comp_msg *recv_msg = comp_msg;
|
|
@@ -1079,7 +1097,6 @@ static int hisi_zip_comp_recv(handle_t ctx, void *comp_msg)
|
|
.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_hpre.c b/drv/hisi_hpre.c
|
|
index d6fb30b..c7bb70e 100644
|
|
--- a/drv/hisi_hpre.c
|
|
+++ b/drv/hisi_hpre.c
|
|
@@ -497,60 +497,90 @@ out:
|
|
return -WD_EINVAL;
|
|
}
|
|
|
|
-static int hpre_rsa_dh_init(void *conf, void *priv)
|
|
+static int hpre_rsa_dh_init(struct wd_alg_driver *drv, void *conf)
|
|
{
|
|
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_hpre_ctx *priv = (struct hisi_hpre_ctx *)drv->priv;
|
|
struct hisi_qm_priv qm_priv;
|
|
int ret;
|
|
|
|
+ if (priv) {
|
|
+ /* return if already inited */
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
if (!config->ctx_num) {
|
|
WD_ERR("invalid: hpre rsa/dh init config ctx num is 0!\n");
|
|
return -WD_EINVAL;
|
|
}
|
|
|
|
+ drv->priv = malloc(sizeof(struct hisi_hpre_ctx));
|
|
+ if (!drv->priv)
|
|
+ return -WD_EINVAL;
|
|
+
|
|
qm_priv.op_type = HPRE_HW_V2_ALG_TYPE;
|
|
- ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv);
|
|
- if (ret)
|
|
+ ret = hpre_init_qm_priv(config, drv->priv, &qm_priv);
|
|
+ if (ret) {
|
|
+ free(drv->priv);
|
|
return ret;
|
|
+ }
|
|
|
|
return 0;
|
|
}
|
|
|
|
-static int hpre_ecc_init(void *conf, void *priv)
|
|
+static int hpre_ecc_init(struct wd_alg_driver *drv, void *conf)
|
|
{
|
|
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_hpre_ctx *priv = (struct hisi_hpre_ctx *)drv->priv;
|
|
struct hisi_qm_priv qm_priv;
|
|
int ret;
|
|
|
|
+ if (priv) {
|
|
+ /* return if already inited */
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
if (!config->ctx_num) {
|
|
WD_ERR("invalid: hpre ecc init config ctx num is 0!\n");
|
|
return -WD_EINVAL;
|
|
}
|
|
|
|
+ drv->priv = malloc(sizeof(struct hisi_hpre_ctx));
|
|
+ if (!drv->priv)
|
|
+ return -WD_EINVAL;
|
|
+
|
|
qm_priv.op_type = HPRE_HW_V3_ECC_ALG_TYPE;
|
|
- ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv);
|
|
- if (ret)
|
|
+ ret = hpre_init_qm_priv(config, drv->priv, &qm_priv);
|
|
+ if (ret) {
|
|
+ free(drv->priv);
|
|
return ret;
|
|
+ }
|
|
|
|
return 0;
|
|
}
|
|
|
|
-static void hpre_exit(void *priv)
|
|
+static void hpre_exit(struct wd_alg_driver *drv)
|
|
{
|
|
- struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
|
|
- struct wd_ctx_config_internal *config = &hpre_ctx->config;
|
|
+ struct hisi_hpre_ctx *priv = (struct hisi_hpre_ctx *)drv->priv;
|
|
+ struct wd_ctx_config_internal *config = &priv->config;
|
|
handle_t h_qp;
|
|
__u32 i;
|
|
|
|
+ if (!priv) {
|
|
+ /* return if already exit */
|
|
+ return;
|
|
+ }
|
|
+
|
|
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(handle_t ctx, void *rsa_msg)
|
|
+static int rsa_send(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_rsa_msg *msg = rsa_msg;
|
|
@@ -606,7 +636,7 @@ static void hpre_result_check(struct hisi_hpre_sqe *hw_msg,
|
|
}
|
|
}
|
|
|
|
-static int rsa_recv(handle_t ctx, void *rsa_msg)
|
|
+static int rsa_recv(struct wd_alg_driver *drv, 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;
|
|
@@ -704,7 +734,7 @@ static int dh_out_transfer(struct wd_dh_msg *msg,
|
|
return WD_SUCCESS;
|
|
}
|
|
|
|
-static int dh_send(handle_t ctx, void *dh_msg)
|
|
+static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_dh_msg *msg = dh_msg;
|
|
@@ -749,7 +779,7 @@ static int dh_send(handle_t ctx, void *dh_msg)
|
|
return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
|
|
}
|
|
|
|
-static int dh_recv(handle_t ctx, void *dh_msg)
|
|
+static int dh_recv(struct wd_alg_driver *drv, 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;
|
|
@@ -1840,7 +1870,7 @@ free_dst:
|
|
return ret;
|
|
}
|
|
|
|
-static int ecc_send(handle_t ctx, void *ecc_msg)
|
|
+static int ecc_send(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_ecc_msg *msg = ecc_msg;
|
|
@@ -2412,7 +2442,7 @@ fail:
|
|
return ret;
|
|
}
|
|
|
|
-static int ecc_recv(handle_t ctx, void *ecc_msg)
|
|
+static int ecc_recv(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_ecc_msg *msg = ecc_msg;
|
|
@@ -2449,7 +2479,6 @@ static int hpre_get_usage(void *param)
|
|
.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,\
|
|
@@ -2473,7 +2502,6 @@ 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,
|
|
@@ -2489,7 +2517,6 @@ 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 22a5e41..bc4c248 100644
|
|
--- a/drv/hisi_sec.c
|
|
+++ b/drv/hisi_sec.c
|
|
@@ -534,8 +534,8 @@ 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(void *conf, void *priv);
|
|
-static void hisi_sec_exit(void *priv);
|
|
+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_get_usage(void *param)
|
|
{
|
|
@@ -548,7 +548,6 @@ static int hisi_sec_get_usage(void *param)
|
|
.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,\
|
|
@@ -1091,7 +1090,7 @@ static int fill_cipher_bd2(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe)
|
|
return 0;
|
|
}
|
|
|
|
-int hisi_sec_cipher_send(handle_t ctx, void *cipher_msg)
|
|
+int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_cipher_msg *msg = cipher_msg;
|
|
@@ -1136,7 +1135,7 @@ int hisi_sec_cipher_send(handle_t ctx, void *cipher_msg)
|
|
return 0;
|
|
}
|
|
|
|
-int hisi_sec_cipher_recv(handle_t ctx, void *cipher_msg)
|
|
+int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_cipher_msg *recv_msg = cipher_msg;
|
|
@@ -1290,7 +1289,7 @@ static int fill_cipher_bd3(struct wd_cipher_msg *msg, struct hisi_sec_sqe3 *sqe)
|
|
return 0;
|
|
}
|
|
|
|
-int hisi_sec_cipher_send_v3(handle_t ctx, void *cipher_msg)
|
|
+int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_cipher_msg *msg = cipher_msg;
|
|
@@ -1380,7 +1379,7 @@ static void parse_cipher_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
|
|
dump_sec_msg(temp_msg, "cipher");
|
|
}
|
|
|
|
-int hisi_sec_cipher_recv_v3(handle_t ctx, void *cipher_msg)
|
|
+int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_cipher_msg *recv_msg = cipher_msg;
|
|
@@ -1651,7 +1650,7 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
|
|
return 0;
|
|
}
|
|
|
|
-int hisi_sec_digest_send(handle_t ctx, void *digest_msg)
|
|
+int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_digest_msg *msg = digest_msg;
|
|
@@ -1718,7 +1717,7 @@ put_sgl:
|
|
return ret;
|
|
}
|
|
|
|
-int hisi_sec_digest_recv(handle_t ctx, void *digest_msg)
|
|
+int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_digest_msg *recv_msg = digest_msg;
|
|
@@ -1895,7 +1894,7 @@ static void fill_digest_v3_scene(struct hisi_sec_sqe3 *sqe,
|
|
sqe->bd_param |= (__u16)(de | scene);
|
|
}
|
|
|
|
-int hisi_sec_digest_send_v3(handle_t ctx, void *digest_msg)
|
|
+int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_digest_msg *msg = digest_msg;
|
|
@@ -1994,7 +1993,7 @@ static void parse_digest_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
|
|
dump_sec_msg(temp_msg, "digest");
|
|
}
|
|
|
|
-int hisi_sec_digest_recv_v3(handle_t ctx, void *digest_msg)
|
|
+int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_digest_msg *recv_msg = digest_msg;
|
|
@@ -2466,7 +2465,7 @@ int aead_msg_state_check(struct wd_aead_msg *msg)
|
|
return 0;
|
|
}
|
|
|
|
-int hisi_sec_aead_send(handle_t ctx, void *aead_msg)
|
|
+int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_aead_msg *msg = aead_msg;
|
|
@@ -2588,7 +2587,7 @@ static bool soft_compute_check(struct hisi_qp *qp, struct wd_aead_msg *msg)
|
|
qp->q_info.qp_mode == CTX_MODE_SYNC;
|
|
}
|
|
|
|
-int hisi_sec_aead_recv(handle_t ctx, void *aead_msg)
|
|
+int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_aead_msg *recv_msg = aead_msg;
|
|
@@ -2850,7 +2849,7 @@ static int fill_aead_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe)
|
|
return 0;
|
|
}
|
|
|
|
-int hisi_sec_aead_send_v3(handle_t ctx, void *aead_msg)
|
|
+int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_aead_msg *msg = aead_msg;
|
|
@@ -2950,7 +2949,7 @@ static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
|
|
dump_sec_msg(temp_msg, "aead");
|
|
}
|
|
|
|
-int hisi_sec_aead_recv_v3(handle_t ctx, void *aead_msg)
|
|
+int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_aead_msg *recv_msg = aead_msg;
|
|
@@ -3022,20 +3021,29 @@ static void hisi_sec_driver_adapter(struct hisi_qp *qp)
|
|
}
|
|
}
|
|
|
|
-static int hisi_sec_init(void *conf, void *priv)
|
|
+static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
|
|
{
|
|
+ struct hisi_sec_ctx *priv = (struct hisi_sec_ctx *)drv->priv;
|
|
struct wd_ctx_config_internal *config = conf;
|
|
- struct hisi_sec_ctx *sec_ctx = priv;
|
|
struct hisi_qm_priv qm_priv;
|
|
handle_t h_qp = 0;
|
|
handle_t h_ctx;
|
|
__u32 i, j;
|
|
|
|
+ if (priv) {
|
|
+ /* return if already inited */
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
if (!config->ctx_num) {
|
|
WD_ERR("invalid: sec init config ctx num is 0!\n");
|
|
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++) {
|
|
@@ -3052,8 +3060,9 @@ static int hisi_sec_init(void *conf, void *priv)
|
|
goto out;
|
|
config->ctxs[i].sqn = qm_priv.sqn;
|
|
}
|
|
- memcpy(&sec_ctx->config, config, sizeof(struct wd_ctx_config_internal));
|
|
+ memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
|
|
hisi_sec_driver_adapter((struct hisi_qp *)h_qp);
|
|
+ drv->priv = priv;
|
|
|
|
return 0;
|
|
|
|
@@ -3062,26 +3071,29 @@ 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_sec_exit(void *priv)
|
|
+static void hisi_sec_exit(struct wd_alg_driver *drv)
|
|
{
|
|
- struct hisi_sec_ctx *sec_ctx = priv;
|
|
+ struct hisi_sec_ctx *priv = (struct hisi_sec_ctx *)drv->priv;
|
|
struct wd_ctx_config_internal *config;
|
|
handle_t h_qp;
|
|
__u32 i;
|
|
|
|
if (!priv) {
|
|
- WD_ERR("invalid: input parameter is NULL!\n");
|
|
+ /* return if already exit */
|
|
return;
|
|
}
|
|
|
|
- config = &sec_ctx->config;
|
|
+ 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 void __attribute__((constructor)) hisi_sec2_probe(void)
|
|
diff --git a/include/wd_alg.h b/include/wd_alg.h
|
|
index e71a6f9..f8b136e 100644
|
|
--- a/include/wd_alg.h
|
|
+++ b/include/wd_alg.h
|
|
@@ -41,8 +41,7 @@ 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_size: parameter memory size passed between the internal
|
|
- * interfaces of the driver
|
|
+ * @priv: pointer of priv ctx
|
|
* @fallback: soft calculation driver handle when performing soft
|
|
* calculation supplement
|
|
* @init: callback interface for initializing device drivers
|
|
@@ -61,16 +60,36 @@ struct wd_alg_driver {
|
|
int calc_type;
|
|
int queue_num;
|
|
int op_type_num;
|
|
- int priv_size;
|
|
+ void *priv;
|
|
handle_t fallback;
|
|
|
|
- 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 (*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 (*get_usage)(void *param);
|
|
};
|
|
|
|
+inline int wd_alg_driver_init(struct wd_alg_driver *drv, void *conf)
|
|
+{
|
|
+ return drv->init(drv, conf);
|
|
+}
|
|
+
|
|
+inline void wd_alg_driver_exit(struct wd_alg_driver *drv)
|
|
+{
|
|
+ drv->exit(drv);
|
|
+}
|
|
+
|
|
+inline int wd_alg_driver_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
|
|
+{
|
|
+ return drv->send(drv, ctx, msg);
|
|
+}
|
|
+
|
|
+inline int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
|
|
+{
|
|
+ return drv->recv(drv, ctx, msg);
|
|
+}
|
|
+
|
|
/**
|
|
* wd_alg_driver_register() - Register a device driver.
|
|
* @wd_alg_driver: a device driver that supports an algorithm.
|
|
diff --git a/include/wd_util.h b/include/wd_util.h
|
|
index 89016ab..144ba59 100644
|
|
--- a/include/wd_util.h
|
|
+++ b/include/wd_util.h
|
|
@@ -113,8 +113,8 @@ struct wd_ctx_attr {
|
|
};
|
|
|
|
struct wd_msg_handle {
|
|
- int (*send)(handle_t sess, void *msg);
|
|
- int (*recv)(handle_t sess, void *msg);
|
|
+ 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);
|
|
};
|
|
|
|
struct wd_init_attrs {
|
|
@@ -358,6 +358,7 @@ 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.
|
|
@@ -366,8 +367,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_msg_handle *msg_handle, handle_t ctx,
|
|
- void *msg, __u64 *balance, bool epoll_en);
|
|
+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);
|
|
|
|
/**
|
|
* wd_init_check() - Check input parameters for wd_<alg>_init.
|
|
@@ -464,14 +465,13 @@ 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, void **drv_priv);
|
|
+ struct wd_alg_driver *driver);
|
|
void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
|
|
- struct wd_alg_driver *driver, void **drv_priv);
|
|
+ struct wd_alg_driver *driver);
|
|
|
|
/**
|
|
* wd_dlopen_drv() - Open the dynamic library file of the device driver.
|
|
diff --git a/wd_aead.c b/wd_aead.c
|
|
index d9969f9..7c3f160 100644
|
|
--- a/wd_aead.c
|
|
+++ b/wd_aead.c
|
|
@@ -44,7 +44,6 @@ 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;
|
|
@@ -436,8 +435,7 @@ 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.priv);
|
|
+ wd_aead_setting.driver);
|
|
if (ret)
|
|
goto out_clear_pool;
|
|
|
|
@@ -492,13 +490,15 @@ static void wd_aead_uninit_nolock(void)
|
|
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,
|
|
- &wd_aead_setting.priv);
|
|
+ wd_aead_setting.driver);
|
|
}
|
|
|
|
void wd_aead_uninit(void)
|
|
{
|
|
- if (!wd_aead_setting.priv)
|
|
+ enum wd_status status;
|
|
+
|
|
+ wd_alg_get_init(&wd_aead_setting.status, &status);
|
|
+ if (status == WD_UNINIT)
|
|
return;
|
|
|
|
wd_aead_uninit_nolock();
|
|
@@ -615,7 +615,10 @@ out_uninit:
|
|
|
|
void wd_aead_uninit2(void)
|
|
{
|
|
- if (!wd_aead_setting.priv)
|
|
+ enum wd_status status;
|
|
+
|
|
+ wd_alg_get_init(&wd_aead_setting.status, &status);
|
|
+ if (status == WD_UNINIT)
|
|
return;
|
|
|
|
wd_aead_uninit_nolock();
|
|
@@ -701,8 +704,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(&msg_handle, ctx->ctx, msg, NULL,
|
|
- wd_aead_setting.config.epoll_en);
|
|
+ ret = wd_handle_msg_sync(wd_aead_setting.driver, &msg_handle, ctx->ctx,
|
|
+ msg, NULL, wd_aead_setting.config.epoll_en);
|
|
pthread_spin_unlock(&ctx->lock);
|
|
|
|
return ret;
|
|
@@ -777,7 +780,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_aead_setting.driver->send(ctx->ctx, msg);
|
|
+ ret = wd_alg_driver_send(wd_aead_setting.driver, ctx->ctx, msg);
|
|
if (unlikely(ret < 0)) {
|
|
if (ret != -WD_EBUSY)
|
|
WD_ERR("failed to send BD, hw is err!\n");
|
|
@@ -826,7 +829,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
|
ctx = config->ctxs + idx;
|
|
|
|
do {
|
|
- ret = wd_aead_setting.driver->recv(ctx->ctx, &resp_msg);
|
|
+ ret = wd_alg_driver_recv(wd_aead_setting.driver, ctx->ctx, &resp_msg);
|
|
if (ret == -WD_EAGAIN) {
|
|
return ret;
|
|
} else if (ret < 0) {
|
|
diff --git a/wd_cipher.c b/wd_cipher.c
|
|
index 85c32c1..adb6496 100644
|
|
--- a/wd_cipher.c
|
|
+++ b/wd_cipher.c
|
|
@@ -59,7 +59,6 @@ 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;
|
|
@@ -318,8 +317,7 @@ 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.priv);
|
|
+ wd_cipher_setting.driver);
|
|
if (ret)
|
|
goto out_clear_pool;
|
|
|
|
@@ -336,9 +334,10 @@ out_clear_ctx_config:
|
|
|
|
static int wd_cipher_common_uninit(void)
|
|
{
|
|
- void *priv = wd_cipher_setting.priv;
|
|
+ enum wd_status status;
|
|
|
|
- if (!priv)
|
|
+ wd_alg_get_init(&wd_cipher_setting.status, &status);
|
|
+ if (status == WD_UNINIT)
|
|
return -WD_EINVAL;
|
|
|
|
/* uninit async request pool */
|
|
@@ -348,8 +347,7 @@ 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.priv);
|
|
+ wd_cipher_setting.driver);
|
|
|
|
return 0;
|
|
}
|
|
@@ -616,8 +614,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx,
|
|
msg_handle.recv = wd_cipher_setting.driver->recv;
|
|
|
|
pthread_spin_lock(&ctx->lock);
|
|
- ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL,
|
|
- wd_cipher_setting.config.epoll_en);
|
|
+ ret = wd_handle_msg_sync(wd_cipher_setting.driver, &msg_handle, ctx->ctx,
|
|
+ msg, NULL, wd_cipher_setting.config.epoll_en);
|
|
pthread_spin_unlock(&ctx->lock);
|
|
|
|
return ret;
|
|
@@ -692,7 +690,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_cipher_setting.driver->send(ctx->ctx, msg);
|
|
+ ret = wd_alg_driver_send(wd_cipher_setting.driver, ctx->ctx, msg);
|
|
if (unlikely(ret < 0)) {
|
|
if (ret != -WD_EBUSY)
|
|
WD_ERR("wd cipher async send err!\n");
|
|
@@ -741,7 +739,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
|
ctx = config->ctxs + idx;
|
|
|
|
do {
|
|
- ret = wd_cipher_setting.driver->recv(ctx->ctx, &resp_msg);
|
|
+ ret = wd_alg_driver_recv(wd_cipher_setting.driver, 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 a8180c1..93c3031 100644
|
|
--- a/wd_comp.c
|
|
+++ b/wd_comp.c
|
|
@@ -48,7 +48,6 @@ 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;
|
|
@@ -139,8 +138,7 @@ 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.priv);
|
|
+ wd_comp_setting.driver);
|
|
if (ret)
|
|
goto out_clear_pool;
|
|
|
|
@@ -157,9 +155,10 @@ out_clear_ctx_config:
|
|
|
|
static int wd_comp_uninit_nolock(void)
|
|
{
|
|
- void *priv = wd_comp_setting.priv;
|
|
+ enum wd_status status;
|
|
|
|
- if (!priv)
|
|
+ wd_alg_get_init(&wd_comp_setting.status, &status);
|
|
+ if (status == WD_UNINIT)
|
|
return -WD_EINVAL;
|
|
|
|
/* Uninit async request pool */
|
|
@@ -169,8 +168,7 @@ 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.priv);
|
|
+ wd_comp_setting.driver);
|
|
|
|
return 0;
|
|
}
|
|
@@ -359,7 +357,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
|
ctx = config->ctxs + idx;
|
|
|
|
do {
|
|
- ret = wd_comp_setting.driver->recv(ctx->ctx, &resp_msg);
|
|
+ ret = wd_alg_driver_recv(wd_comp_setting.driver, ctx->ctx, &resp_msg);
|
|
if (unlikely(ret < 0)) {
|
|
if (ret == -WD_HW_EACCESS)
|
|
WD_ERR("wd comp recv hw error!\n");
|
|
@@ -594,8 +592,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(&msg_handle, ctx->ctx, msg,
|
|
- NULL, config->epoll_en);
|
|
+ ret = wd_handle_msg_sync(wd_comp_setting.driver, &msg_handle, ctx->ctx,
|
|
+ msg, NULL, config->epoll_en);
|
|
pthread_spin_unlock(&ctx->lock);
|
|
|
|
return ret;
|
|
@@ -849,7 +847,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_comp_setting.driver->send(ctx->ctx, msg);
|
|
+ ret = wd_alg_driver_send(wd_comp_setting.driver, ctx->ctx, msg);
|
|
if (unlikely(ret < 0)) {
|
|
WD_ERR("wd comp send error, ret = %d!\n", ret);
|
|
goto fail_with_msg;
|
|
diff --git a/wd_dh.c b/wd_dh.c
|
|
index 4a14737..50a1532 100644
|
|
--- a/wd_dh.c
|
|
+++ b/wd_dh.c
|
|
@@ -35,7 +35,6 @@ 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;
|
|
@@ -112,8 +111,7 @@ 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.priv);
|
|
+ wd_dh_setting.driver);
|
|
if (ret)
|
|
goto out_clear_pool;
|
|
|
|
@@ -130,19 +128,13 @@ out_clear_ctx_config:
|
|
|
|
static int wd_dh_common_uninit(void)
|
|
{
|
|
- 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);
|
|
|
|
/* 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.priv);
|
|
+ wd_dh_setting.driver);
|
|
|
|
return 0;
|
|
}
|
|
@@ -367,8 +359,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(&msg_handle, ctx->ctx, &msg, &balance,
|
|
- wd_dh_setting.config.epoll_en);
|
|
+ ret = wd_handle_msg_sync(wd_dh_setting.driver, &msg_handle, ctx->ctx,
|
|
+ &msg, &balance, wd_dh_setting.config.epoll_en);
|
|
pthread_spin_unlock(&ctx->lock);
|
|
if (unlikely(ret))
|
|
return ret;
|
|
@@ -412,7 +404,7 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req)
|
|
goto fail_with_msg;
|
|
msg->tag = mid;
|
|
|
|
- ret = wd_dh_setting.driver->send(ctx->ctx, msg);
|
|
+ ret = wd_alg_driver_send(wd_dh_setting.driver, ctx->ctx, msg);
|
|
if (unlikely(ret)) {
|
|
if (ret != -WD_EBUSY)
|
|
WD_ERR("failed to send dh BD, hw is err!\n");
|
|
@@ -463,7 +455,7 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
|
ctx = config->ctxs + idx;
|
|
|
|
do {
|
|
- ret = wd_dh_setting.driver->recv(ctx->ctx, &rcv_msg);
|
|
+ ret = wd_alg_driver_recv(wd_dh_setting.driver, 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 5370f45..c5dbeca 100644
|
|
--- a/wd_digest.c
|
|
+++ b/wd_digest.c
|
|
@@ -51,7 +51,6 @@ 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;
|
|
@@ -250,8 +249,7 @@ 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.priv);
|
|
+ wd_digest_setting.driver);
|
|
if (ret)
|
|
goto out_clear_pool;
|
|
|
|
@@ -306,13 +304,15 @@ static void wd_digest_uninit_nolock(void)
|
|
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,
|
|
- &wd_digest_setting.priv);
|
|
+ wd_digest_setting.driver);
|
|
}
|
|
|
|
void wd_digest_uninit(void)
|
|
{
|
|
- if (!wd_digest_setting.priv)
|
|
+ enum wd_status status;
|
|
+
|
|
+ wd_alg_get_init(&wd_digest_setting.status, &status);
|
|
+ if (status == WD_UNINIT)
|
|
return;
|
|
|
|
wd_digest_uninit_nolock();
|
|
@@ -423,7 +423,10 @@ out_uninit:
|
|
|
|
void wd_digest_uninit2(void)
|
|
{
|
|
- if (!wd_digest_setting.priv)
|
|
+ enum wd_status status;
|
|
+
|
|
+ wd_alg_get_init(&wd_digest_setting.status, &status);
|
|
+ if (status == WD_UNINIT)
|
|
return;
|
|
|
|
wd_digest_uninit_nolock();
|
|
@@ -563,8 +566,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *ds
|
|
msg_handle.recv = wd_digest_setting.driver->recv;
|
|
|
|
pthread_spin_lock(&ctx->lock);
|
|
- ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg,
|
|
- NULL, wd_digest_setting.config.epoll_en);
|
|
+ ret = wd_handle_msg_sync(wd_digest_setting.driver, &msg_handle, ctx->ctx,
|
|
+ msg, NULL, wd_digest_setting.config.epoll_en);
|
|
if (unlikely(ret))
|
|
goto out;
|
|
|
|
@@ -647,7 +650,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_digest_setting.driver->send(ctx->ctx, msg);
|
|
+ ret = wd_alg_driver_send(wd_digest_setting.driver, ctx->ctx, msg);
|
|
if (unlikely(ret < 0)) {
|
|
if (ret != -WD_EBUSY)
|
|
WD_ERR("failed to send BD, hw is err!\n");
|
|
@@ -696,8 +699,7 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
|
ctx = config->ctxs + idx;
|
|
|
|
do {
|
|
- ret = wd_digest_setting.driver->recv(ctx->ctx,
|
|
- &recv_msg);
|
|
+ ret = wd_alg_driver_recv(wd_digest_setting.driver, 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 1e042f0..9f83fea 100644
|
|
--- a/wd_ecc.c
|
|
+++ b/wd_ecc.c
|
|
@@ -68,7 +68,6 @@ 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;
|
|
@@ -178,8 +177,7 @@ 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.priv);
|
|
+ wd_ecc_setting.driver);
|
|
if (ret)
|
|
goto out_clear_pool;
|
|
|
|
@@ -196,19 +194,13 @@ out_clear_ctx_config:
|
|
|
|
static int wd_ecc_common_uninit(void)
|
|
{
|
|
- 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);
|
|
|
|
/* 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.priv);
|
|
+ wd_ecc_setting.driver);
|
|
|
|
return 0;
|
|
}
|
|
@@ -1572,8 +1564,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(&msg_handle, ctx->ctx, &msg, &balance,
|
|
- wd_ecc_setting.config.epoll_en);
|
|
+ ret = wd_handle_msg_sync(wd_ecc_setting.driver, &msg_handle, ctx->ctx, &msg,
|
|
+ &balance, wd_ecc_setting.config.epoll_en);
|
|
pthread_spin_unlock(&ctx->lock);
|
|
if (unlikely(ret))
|
|
return ret;
|
|
@@ -2250,7 +2242,7 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req)
|
|
goto fail_with_msg;
|
|
msg->tag = mid;
|
|
|
|
- ret = wd_ecc_setting.driver->send(ctx->ctx, msg);
|
|
+ ret = wd_alg_driver_send(wd_ecc_setting.driver, ctx->ctx, msg);
|
|
if (unlikely(ret)) {
|
|
if (ret != -WD_EBUSY)
|
|
WD_ERR("failed to send ecc BD, hw is err!\n");
|
|
@@ -2299,7 +2291,7 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
|
ctx = config->ctxs + idx;
|
|
|
|
do {
|
|
- ret = wd_ecc_setting.driver->recv(ctx->ctx, &recv_msg);
|
|
+ ret = wd_alg_driver_recv(wd_ecc_setting.driver, ctx->ctx, &recv_msg);
|
|
if (ret == -WD_EAGAIN) {
|
|
return ret;
|
|
} else if (ret < 0) {
|
|
diff --git a/wd_rsa.c b/wd_rsa.c
|
|
index 4bd1d30..19a590f 100644
|
|
--- a/wd_rsa.c
|
|
+++ b/wd_rsa.c
|
|
@@ -76,7 +76,6 @@ 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;
|
|
@@ -153,8 +152,7 @@ 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.priv);
|
|
+ wd_rsa_setting.driver);
|
|
if (ret)
|
|
goto out_clear_pool;
|
|
|
|
@@ -171,19 +169,13 @@ out_clear_ctx_config:
|
|
|
|
static int wd_rsa_common_uninit(void)
|
|
{
|
|
- 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);
|
|
|
|
/* 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.priv);
|
|
+ wd_rsa_setting.driver);
|
|
|
|
return 0;
|
|
}
|
|
@@ -429,8 +421,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(&msg_handle, ctx->ctx, &msg, &balance,
|
|
- wd_rsa_setting.config.epoll_en);
|
|
+ ret = wd_handle_msg_sync(wd_rsa_setting.driver, &msg_handle, ctx->ctx, &msg,
|
|
+ &balance, wd_rsa_setting.config.epoll_en);
|
|
pthread_spin_unlock(&ctx->lock);
|
|
if (unlikely(ret))
|
|
return ret;
|
|
@@ -474,7 +466,7 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req)
|
|
goto fail_with_msg;
|
|
msg->tag = mid;
|
|
|
|
- ret = wd_rsa_setting.driver->send(ctx->ctx, msg);
|
|
+ ret = wd_alg_driver_send(wd_rsa_setting.driver, ctx->ctx, msg);
|
|
if (unlikely(ret)) {
|
|
if (ret != -WD_EBUSY)
|
|
WD_ERR("failed to send rsa BD, hw is err!\n");
|
|
@@ -523,7 +515,7 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
|
ctx = config->ctxs + idx;
|
|
|
|
do {
|
|
- ret = wd_rsa_setting.driver->recv(ctx->ctx, &recv_msg);
|
|
+ ret = wd_alg_driver_recv(wd_rsa_setting.driver, ctx->ctx, &recv_msg);
|
|
if (ret == -WD_EAGAIN) {
|
|
return ret;
|
|
} else if (ret < 0) {
|
|
diff --git a/wd_util.c b/wd_util.c
|
|
index 3ce5f56..ef67f1f 100644
|
|
--- a/wd_util.c
|
|
+++ b/wd_util.c
|
|
@@ -1767,8 +1767,8 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en)
|
|
return 0;
|
|
}
|
|
|
|
-int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx,
|
|
- void *msg, __u64 *balance, bool epoll_en)
|
|
+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)
|
|
{
|
|
__u64 timeout = WD_RECV_MAX_CNT_NOSLEEP;
|
|
__u64 rx_cnt = 0;
|
|
@@ -1777,7 +1777,7 @@ int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx,
|
|
if (balance)
|
|
timeout = WD_RECV_MAX_CNT_SLEEP;
|
|
|
|
- ret = msg_handle->send(ctx, msg);
|
|
+ ret = msg_handle->send(drv, ctx, msg);
|
|
if (unlikely(ret < 0)) {
|
|
WD_ERR("failed to send msg to hw, ret = %d!\n", ret);
|
|
return ret;
|
|
@@ -1790,7 +1790,7 @@ int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx,
|
|
WD_ERR("wd ctx wait timeout(%d)!\n", ret);
|
|
}
|
|
|
|
- ret = msg_handle->recv(ctx, msg);
|
|
+ ret = msg_handle->recv(drv, ctx, msg);
|
|
if (ret == -WD_EAGAIN) {
|
|
if (unlikely(rx_cnt++ >= timeout)) {
|
|
WD_ERR("failed to recv msg: timeout!\n");
|
|
@@ -1895,16 +1895,10 @@ 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, void **drv_priv)
|
|
+ struct wd_alg_driver *driver)
|
|
{
|
|
- void *priv;
|
|
int ret;
|
|
|
|
- /* 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");
|
|
@@ -1912,7 +1906,7 @@ int wd_alg_init_driver(struct wd_ctx_config_internal *config,
|
|
goto err_alloc;
|
|
}
|
|
|
|
- ret = driver->init(config, priv);
|
|
+ ret = driver->init(driver, config);
|
|
if (ret < 0) {
|
|
WD_ERR("driver init failed.\n");
|
|
goto err_alloc;
|
|
@@ -1925,32 +1919,24 @@ 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, void **drv_priv)
|
|
+ struct wd_alg_driver *driver)
|
|
{
|
|
- void *priv = *drv_priv;
|
|
|
|
- driver->exit(priv);
|
|
+ driver->exit(driver);
|
|
/* Ctx config just need clear once */
|
|
if (driver->calc_type == UADK_ALG_HW)
|
|
wd_clear_ctx_config(config);
|
|
|
|
if (driver->fallback)
|
|
wd_alg_uninit_fallback((struct wd_alg_driver *)driver->fallback);
|
|
-
|
|
- if (priv) {
|
|
- free(priv);
|
|
- *drv_priv = NULL;
|
|
- }
|
|
}
|
|
|
|
void wd_dlclose_drv(void *dlh_list)
|
|
--
|
|
2.25.1
|
|
|