1247 lines
38 KiB
Diff
1247 lines
38 KiB
Diff
From 34ddd7607abcbc8de955eb68908bbbd09ef1d092 Mon Sep 17 00:00:00 2001
|
|
From: Younger <shenyang39@huawei.com>
|
|
Date: Sat, 9 Dec 2023 15:28:15 +0800
|
|
Subject: [PATCH 094/123] uadk - remove drivers alloc and free resources
|
|
|
|
Remove drivers alloc and free resources.
|
|
|
|
Signed-off-by: Yang Shen <shenyang39@huawei.com>
|
|
---
|
|
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, 174 insertions(+), 212 deletions(-)
|
|
|
|
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
|
|
index 2cb9a6b..d6c0a2a 100644
|
|
--- a/drv/hisi_comp.c
|
|
+++ b/drv/hisi_comp.c
|
|
@@ -785,30 +785,21 @@ static void hisi_zip_sqe_ops_adapt(handle_t h_qp)
|
|
}
|
|
}
|
|
|
|
-static int hisi_zip_init(struct wd_alg_driver *drv, void *conf)
|
|
+static int hisi_zip_init(void *conf, void *priv)
|
|
{
|
|
- 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;
|
|
}
|
|
|
|
- priv = malloc(sizeof(struct hisi_zip_ctx));
|
|
- if (!priv)
|
|
- return -WD_EINVAL;
|
|
-
|
|
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
|
|
+ memcpy(&zip_ctx->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;
|
|
@@ -826,7 +817,6 @@ static int hisi_zip_init(struct wd_alg_driver *drv, void *conf)
|
|
}
|
|
|
|
hisi_zip_sqe_ops_adapt(h_qp);
|
|
- drv->priv = priv;
|
|
|
|
return 0;
|
|
out:
|
|
@@ -834,28 +824,20 @@ 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(struct wd_alg_driver *drv)
|
|
+static void hisi_zip_exit(void *priv)
|
|
{
|
|
- struct hisi_zip_ctx *priv = (struct hisi_zip_ctx *)drv->priv;
|
|
- struct wd_ctx_config_internal *config = &priv->config;
|
|
+ struct hisi_zip_ctx *zip_ctx = (struct hisi_zip_ctx *)priv;
|
|
+ struct wd_ctx_config_internal *config = &zip_ctx->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,
|
|
@@ -935,7 +917,7 @@ static void free_hw_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
|
|
}
|
|
}
|
|
|
|
-static int hisi_zip_comp_send(struct wd_alg_driver *drv, handle_t ctx, void *comp_msg)
|
|
+static int hisi_zip_comp_send(handle_t ctx, void *comp_msg)
|
|
{
|
|
struct hisi_qp *qp = wd_ctx_get_priv(ctx);
|
|
struct wd_comp_msg *msg = comp_msg;
|
|
@@ -1075,7 +1057,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
|
|
return 0;
|
|
}
|
|
|
|
-static int hisi_zip_comp_recv(struct wd_alg_driver *drv, handle_t ctx, void *comp_msg)
|
|
+static int hisi_zip_comp_recv(handle_t ctx, void *comp_msg)
|
|
{
|
|
struct hisi_qp *qp = wd_ctx_get_priv(ctx);
|
|
struct wd_comp_msg *recv_msg = comp_msg;
|
|
@@ -1097,6 +1079,7 @@ static int hisi_zip_comp_recv(struct wd_alg_driver *drv, handle_t ctx, void *com
|
|
.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 61c7855..2f8a5d6 100644
|
|
--- a/drv/hisi_hpre.c
|
|
+++ b/drv/hisi_hpre.c
|
|
@@ -506,90 +506,60 @@ out:
|
|
return -WD_EINVAL;
|
|
}
|
|
|
|
-static int hpre_rsa_dh_init(struct wd_alg_driver *drv, void *conf)
|
|
+static int hpre_rsa_dh_init(void *conf, void *priv)
|
|
{
|
|
struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
|
|
- struct hisi_hpre_ctx *priv = (struct hisi_hpre_ctx *)drv->priv;
|
|
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)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, drv->priv, &qm_priv);
|
|
- if (ret) {
|
|
- free(drv->priv);
|
|
+ ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv);
|
|
+ if (ret)
|
|
return ret;
|
|
- }
|
|
|
|
return 0;
|
|
}
|
|
|
|
-static int hpre_ecc_init(struct wd_alg_driver *drv, void *conf)
|
|
+static int hpre_ecc_init(void *conf, void *priv)
|
|
{
|
|
struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
|
|
- struct hisi_hpre_ctx *priv = (struct hisi_hpre_ctx *)drv->priv;
|
|
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)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, drv->priv, &qm_priv);
|
|
- if (ret) {
|
|
- free(drv->priv);
|
|
+ ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv);
|
|
+ if (ret)
|
|
return ret;
|
|
- }
|
|
|
|
return 0;
|
|
}
|
|
|
|
-static void hpre_exit(struct wd_alg_driver *drv)
|
|
+static void hpre_exit(void *priv)
|
|
{
|
|
- struct hisi_hpre_ctx *priv = (struct hisi_hpre_ctx *)drv->priv;
|
|
- struct wd_ctx_config_internal *config = &priv->config;
|
|
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
|
|
+ struct wd_ctx_config_internal *config = &hpre_ctx->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(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
|
|
+static int rsa_send(handle_t ctx, void *rsa_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_rsa_msg *msg = rsa_msg;
|
|
@@ -645,7 +615,7 @@ static void hpre_result_check(struct hisi_hpre_sqe *hw_msg,
|
|
}
|
|
}
|
|
|
|
-static int rsa_recv(struct wd_alg_driver *drv, handle_t ctx, void *rsa_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;
|
|
@@ -743,7 +713,7 @@ static int dh_out_transfer(struct wd_dh_msg *msg,
|
|
return WD_SUCCESS;
|
|
}
|
|
|
|
-static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
|
|
+static int dh_send(handle_t ctx, void *dh_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_dh_msg *msg = dh_msg;
|
|
@@ -788,7 +758,7 @@ static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
|
|
return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
|
|
}
|
|
|
|
-static int dh_recv(struct wd_alg_driver *drv, 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;
|
|
@@ -1879,7 +1849,7 @@ free_dst:
|
|
return ret;
|
|
}
|
|
|
|
-static int ecc_send(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
|
|
+static int ecc_send(handle_t ctx, void *ecc_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_ecc_msg *msg = ecc_msg;
|
|
@@ -2451,7 +2421,7 @@ fail:
|
|
return ret;
|
|
}
|
|
|
|
-static int ecc_recv(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
|
|
+static int ecc_recv(handle_t ctx, void *ecc_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_ecc_msg *msg = ecc_msg;
|
|
@@ -2488,6 +2458,7 @@ 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,\
|
|
@@ -2511,6 +2482,7 @@ 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,
|
|
@@ -2526,6 +2498,7 @@ 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 03e7037..341e91a 100644
|
|
--- a/drv/hisi_sec.c
|
|
+++ b/drv/hisi_sec.c
|
|
@@ -536,8 +536,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(struct wd_alg_driver *drv, void *conf);
|
|
-static void hisi_sec_exit(struct wd_alg_driver *drv);
|
|
+static int hisi_sec_init(void *conf, void *priv);
|
|
+static void hisi_sec_exit(void *priv);
|
|
|
|
static int hisi_sec_get_usage(void *param)
|
|
{
|
|
@@ -550,6 +550,7 @@ 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,\
|
|
@@ -1092,7 +1093,7 @@ static int fill_cipher_bd2(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe)
|
|
return 0;
|
|
}
|
|
|
|
-int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg)
|
|
+int hisi_sec_cipher_send(handle_t ctx, void *cipher_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_cipher_msg *msg = cipher_msg;
|
|
@@ -1137,7 +1138,7 @@ int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *cipher_m
|
|
return 0;
|
|
}
|
|
|
|
-int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg)
|
|
+int hisi_sec_cipher_recv(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;
|
|
@@ -1295,7 +1296,7 @@ static int fill_cipher_bd3(struct wd_cipher_msg *msg, struct hisi_sec_sqe3 *sqe)
|
|
return 0;
|
|
}
|
|
|
|
-int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg)
|
|
+int hisi_sec_cipher_send_v3(handle_t ctx, void *cipher_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_cipher_msg *msg = cipher_msg;
|
|
@@ -1385,7 +1386,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(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg)
|
|
+int hisi_sec_cipher_recv_v3(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;
|
|
@@ -1658,7 +1659,7 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
|
|
return 0;
|
|
}
|
|
|
|
-int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
|
|
+int hisi_sec_digest_send(handle_t ctx, void *digest_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_digest_msg *msg = digest_msg;
|
|
@@ -1725,7 +1726,7 @@ put_sgl:
|
|
return ret;
|
|
}
|
|
|
|
-int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
|
|
+int hisi_sec_digest_recv(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;
|
|
@@ -1902,7 +1903,7 @@ static void fill_digest_v3_scene(struct hisi_sec_sqe3 *sqe,
|
|
sqe->bd_param |= (__u16)(de | scene);
|
|
}
|
|
|
|
-int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
|
|
+int hisi_sec_digest_send_v3(handle_t ctx, void *digest_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_digest_msg *msg = digest_msg;
|
|
@@ -2001,7 +2002,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(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
|
|
+int hisi_sec_digest_recv_v3(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;
|
|
@@ -2473,7 +2474,7 @@ int aead_msg_state_check(struct wd_aead_msg *msg)
|
|
return 0;
|
|
}
|
|
|
|
-int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg)
|
|
+int hisi_sec_aead_send(handle_t ctx, void *aead_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_aead_msg *msg = aead_msg;
|
|
@@ -2595,7 +2596,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(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg)
|
|
+int hisi_sec_aead_recv(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;
|
|
@@ -2857,7 +2858,7 @@ static int fill_aead_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe)
|
|
return 0;
|
|
}
|
|
|
|
-int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg)
|
|
+int hisi_sec_aead_send_v3(handle_t ctx, void *aead_msg)
|
|
{
|
|
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
|
|
struct wd_aead_msg *msg = aead_msg;
|
|
@@ -2957,7 +2958,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(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg)
|
|
+int hisi_sec_aead_recv_v3(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;
|
|
@@ -3029,29 +3030,20 @@ static void hisi_sec_driver_adapter(struct hisi_qp *qp)
|
|
}
|
|
}
|
|
|
|
-static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
|
|
+static int hisi_sec_init(void *conf, void *priv)
|
|
{
|
|
- 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++) {
|
|
@@ -3068,9 +3060,8 @@ static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
|
|
goto out;
|
|
config->ctxs[i].sqn = qm_priv.sqn;
|
|
}
|
|
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
|
|
+ memcpy(&sec_ctx->config, config, sizeof(struct wd_ctx_config_internal));
|
|
hisi_sec_driver_adapter((struct hisi_qp *)h_qp);
|
|
- drv->priv = priv;
|
|
|
|
return 0;
|
|
|
|
@@ -3079,29 +3070,26 @@ 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(struct wd_alg_driver *drv)
|
|
+static void hisi_sec_exit(void *priv)
|
|
{
|
|
- struct hisi_sec_ctx *priv = (struct hisi_sec_ctx *)drv->priv;
|
|
+ struct hisi_sec_ctx *sec_ctx = priv;
|
|
struct wd_ctx_config_internal *config;
|
|
handle_t h_qp;
|
|
__u32 i;
|
|
|
|
if (!priv) {
|
|
- /* return if already exit */
|
|
+ WD_ERR("invalid: input parameter is NULL!\n");
|
|
return;
|
|
}
|
|
|
|
- config = &priv->config;
|
|
+ config = &sec_ctx->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 f8b136e..e71a6f9 100644
|
|
--- a/include/wd_alg.h
|
|
+++ b/include/wd_alg.h
|
|
@@ -41,7 +41,8 @@ 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: pointer of priv ctx
|
|
+ * @priv_size: parameter memory size passed between the internal
|
|
+ * interfaces of the driver
|
|
* @fallback: soft calculation driver handle when performing soft
|
|
* calculation supplement
|
|
* @init: callback interface for initializing device drivers
|
|
@@ -60,36 +61,16 @@ struct wd_alg_driver {
|
|
int calc_type;
|
|
int queue_num;
|
|
int op_type_num;
|
|
- void *priv;
|
|
+ int priv_size;
|
|
handle_t fallback;
|
|
|
|
- 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 (*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 (*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 be9798c..0f35ccf 100644
|
|
--- a/include/wd_util.h
|
|
+++ b/include/wd_util.h
|
|
@@ -115,8 +115,8 @@ struct wd_ctx_attr {
|
|
};
|
|
|
|
struct wd_msg_handle {
|
|
- 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 (*send)(handle_t sess, void *msg);
|
|
+ int (*recv)(handle_t sess, void *msg);
|
|
};
|
|
|
|
struct wd_init_attrs {
|
|
@@ -361,7 +361,6 @@ 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.
|
|
@@ -370,8 +369,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_alg_driver *drv, struct wd_msg_handle *msg_handle,
|
|
- handle_t ctx, void *msg, __u64 *balance, bool epoll_en);
|
|
+int wd_handle_msg_sync(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.
|
|
@@ -469,13 +468,14 @@ 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);
|
|
+ struct wd_alg_driver *driver, void **drv_priv);
|
|
void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
|
|
- struct wd_alg_driver *driver);
|
|
+ struct wd_alg_driver *driver, void **drv_priv);
|
|
|
|
/**
|
|
* wd_dlopen_drv() - Open the dynamic library file of the device driver.
|
|
diff --git a/wd_aead.c b/wd_aead.c
|
|
index 87d61c3..20d1109 100644
|
|
--- a/wd_aead.c
|
|
+++ b/wd_aead.c
|
|
@@ -43,6 +43,7 @@ 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;
|
|
@@ -434,7 +435,8 @@ 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.driver,
|
|
+ &wd_aead_setting.priv);
|
|
if (ret)
|
|
goto out_clear_pool;
|
|
|
|
@@ -488,15 +490,13 @@ 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.driver,
|
|
+ &wd_aead_setting.priv);
|
|
}
|
|
|
|
void wd_aead_uninit(void)
|
|
{
|
|
- enum wd_status status;
|
|
-
|
|
- wd_alg_get_init(&wd_aead_setting.status, &status);
|
|
- if (status == WD_UNINIT)
|
|
+ if (!wd_aead_setting.priv)
|
|
return;
|
|
|
|
wd_aead_uninit_nolock();
|
|
@@ -612,10 +612,7 @@ out_uninit:
|
|
|
|
void wd_aead_uninit2(void)
|
|
{
|
|
- enum wd_status status;
|
|
-
|
|
- wd_alg_get_init(&wd_aead_setting.status, &status);
|
|
- if (status == WD_UNINIT)
|
|
+ if (!wd_aead_setting.priv)
|
|
return;
|
|
|
|
wd_aead_uninit_nolock();
|
|
@@ -705,8 +702,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(wd_aead_setting.driver, &msg_handle, ctx->ctx,
|
|
- msg, NULL, wd_aead_setting.config.epoll_en);
|
|
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL,
|
|
+ wd_aead_setting.config.epoll_en);
|
|
pthread_spin_unlock(&ctx->lock);
|
|
|
|
return ret;
|
|
@@ -781,7 +778,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_alg_driver_send(wd_aead_setting.driver, ctx->ctx, msg);
|
|
+ ret = wd_aead_setting.driver->send(ctx->ctx, msg);
|
|
if (unlikely(ret < 0)) {
|
|
if (ret != -WD_EBUSY)
|
|
WD_ERR("failed to send BD, hw is err!\n");
|
|
@@ -830,7 +827,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
|
ctx = config->ctxs + idx;
|
|
|
|
do {
|
|
- ret = wd_alg_driver_recv(wd_aead_setting.driver, ctx->ctx, &resp_msg);
|
|
+ ret = wd_aead_setting.driver->recv(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 58d34f7..76b9bad 100644
|
|
--- a/wd_cipher.c
|
|
+++ b/wd_cipher.c
|
|
@@ -60,6 +60,7 @@ 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;
|
|
@@ -323,7 +324,8 @@ 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.driver,
|
|
+ &wd_cipher_setting.priv);
|
|
if (ret)
|
|
goto out_clear_pool;
|
|
|
|
@@ -340,10 +342,9 @@ out_clear_ctx_config:
|
|
|
|
static int wd_cipher_common_uninit(void)
|
|
{
|
|
- enum wd_status status;
|
|
+ void *priv = wd_cipher_setting.priv;
|
|
|
|
- wd_alg_get_init(&wd_cipher_setting.status, &status);
|
|
- if (status == WD_UNINIT)
|
|
+ if (!priv)
|
|
return -WD_EINVAL;
|
|
|
|
/* uninit async request pool */
|
|
@@ -353,7 +354,8 @@ 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.driver,
|
|
+ &wd_cipher_setting.priv);
|
|
|
|
return 0;
|
|
}
|
|
@@ -619,8 +621,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(wd_cipher_setting.driver, &msg_handle, ctx->ctx,
|
|
- msg, NULL, wd_cipher_setting.config.epoll_en);
|
|
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL,
|
|
+ wd_cipher_setting.config.epoll_en);
|
|
pthread_spin_unlock(&ctx->lock);
|
|
|
|
return ret;
|
|
@@ -695,7 +697,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_alg_driver_send(wd_cipher_setting.driver, ctx->ctx, msg);
|
|
+ ret = wd_cipher_setting.driver->send(ctx->ctx, msg);
|
|
if (unlikely(ret < 0)) {
|
|
if (ret != -WD_EBUSY)
|
|
WD_ERR("wd cipher async send err!\n");
|
|
@@ -744,7 +746,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
|
ctx = config->ctxs + idx;
|
|
|
|
do {
|
|
- ret = wd_alg_driver_recv(wd_cipher_setting.driver, ctx->ctx, &resp_msg);
|
|
+ ret = wd_cipher_setting.driver->recv(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 6e71d35..b6fe85c 100644
|
|
--- a/wd_comp.c
|
|
+++ b/wd_comp.c
|
|
@@ -47,6 +47,7 @@ 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;
|
|
@@ -136,7 +137,8 @@ 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.driver,
|
|
+ &wd_comp_setting.priv);
|
|
if (ret)
|
|
goto out_clear_pool;
|
|
|
|
@@ -153,10 +155,9 @@ out_clear_ctx_config:
|
|
|
|
static int wd_comp_uninit_nolock(void)
|
|
{
|
|
- enum wd_status status;
|
|
+ void *priv = wd_comp_setting.priv;
|
|
|
|
- wd_alg_get_init(&wd_comp_setting.status, &status);
|
|
- if (status == WD_UNINIT)
|
|
+ if (!priv)
|
|
return -WD_EINVAL;
|
|
|
|
/* Uninit async request pool */
|
|
@@ -166,7 +167,8 @@ 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.driver,
|
|
+ &wd_comp_setting.priv);
|
|
|
|
return 0;
|
|
}
|
|
@@ -354,7 +356,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
|
ctx = config->ctxs + idx;
|
|
|
|
do {
|
|
- ret = wd_alg_driver_recv(wd_comp_setting.driver, ctx->ctx, &resp_msg);
|
|
+ ret = wd_comp_setting.driver->recv(ctx->ctx, &resp_msg);
|
|
if (unlikely(ret < 0)) {
|
|
if (ret == -WD_HW_EACCESS)
|
|
WD_ERR("wd comp recv hw error!\n");
|
|
@@ -588,8 +590,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(wd_comp_setting.driver, &msg_handle, ctx->ctx,
|
|
- msg, NULL, config->epoll_en);
|
|
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg,
|
|
+ NULL, config->epoll_en);
|
|
pthread_spin_unlock(&ctx->lock);
|
|
|
|
return ret;
|
|
@@ -843,7 +845,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_alg_driver_send(wd_comp_setting.driver, ctx->ctx, msg);
|
|
+ ret = wd_comp_setting.driver->send(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 40a52e5..157f7c6 100644
|
|
--- a/wd_dh.c
|
|
+++ b/wd_dh.c
|
|
@@ -34,6 +34,7 @@ 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;
|
|
@@ -110,7 +111,8 @@ 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.driver,
|
|
+ &wd_dh_setting.priv);
|
|
if (ret)
|
|
goto out_clear_pool;
|
|
|
|
@@ -127,13 +129,19 @@ 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.driver,
|
|
+ &wd_dh_setting.priv);
|
|
|
|
return 0;
|
|
}
|
|
@@ -356,8 +364,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(wd_dh_setting.driver, &msg_handle, ctx->ctx,
|
|
- &msg, &balance, wd_dh_setting.config.epoll_en);
|
|
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance,
|
|
+ wd_dh_setting.config.epoll_en);
|
|
pthread_spin_unlock(&ctx->lock);
|
|
if (unlikely(ret))
|
|
return ret;
|
|
@@ -401,7 +409,7 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req)
|
|
goto fail_with_msg;
|
|
msg->tag = mid;
|
|
|
|
- ret = wd_alg_driver_send(wd_dh_setting.driver, ctx->ctx, msg);
|
|
+ ret = wd_dh_setting.driver->send(ctx->ctx, msg);
|
|
if (unlikely(ret)) {
|
|
if (ret != -WD_EBUSY)
|
|
WD_ERR("failed to send dh BD, hw is err!\n");
|
|
@@ -452,7 +460,7 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
|
ctx = config->ctxs + idx;
|
|
|
|
do {
|
|
- ret = wd_alg_driver_recv(wd_dh_setting.driver, ctx->ctx, &rcv_msg);
|
|
+ ret = wd_dh_setting.driver->recv(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 2307bf1..e523331 100644
|
|
--- a/wd_digest.c
|
|
+++ b/wd_digest.c
|
|
@@ -50,6 +50,7 @@ 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;
|
|
@@ -249,7 +250,8 @@ 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.driver,
|
|
+ &wd_digest_setting.priv);
|
|
if (ret)
|
|
goto out_clear_pool;
|
|
|
|
@@ -303,15 +305,13 @@ 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.driver,
|
|
+ &wd_digest_setting.priv);
|
|
}
|
|
|
|
void wd_digest_uninit(void)
|
|
{
|
|
- enum wd_status status;
|
|
-
|
|
- wd_alg_get_init(&wd_digest_setting.status, &status);
|
|
- if (status == WD_UNINIT)
|
|
+ if (!wd_digest_setting.priv)
|
|
return;
|
|
|
|
wd_digest_uninit_nolock();
|
|
@@ -421,10 +421,7 @@ out_uninit:
|
|
|
|
void wd_digest_uninit2(void)
|
|
{
|
|
- enum wd_status status;
|
|
-
|
|
- wd_alg_get_init(&wd_digest_setting.status, &status);
|
|
- if (status == WD_UNINIT)
|
|
+ if (!wd_digest_setting.priv)
|
|
return;
|
|
|
|
wd_digest_uninit_nolock();
|
|
@@ -576,8 +573,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(wd_digest_setting.driver, &msg_handle, ctx->ctx,
|
|
- msg, NULL, wd_digest_setting.config.epoll_en);
|
|
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg,
|
|
+ NULL, wd_digest_setting.config.epoll_en);
|
|
pthread_spin_unlock(&ctx->lock);
|
|
if (unlikely(ret))
|
|
return ret;
|
|
@@ -666,7 +663,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_alg_driver_send(wd_digest_setting.driver, ctx->ctx, msg);
|
|
+ ret = wd_digest_setting.driver->send(ctx->ctx, msg);
|
|
if (unlikely(ret < 0)) {
|
|
if (ret != -WD_EBUSY)
|
|
WD_ERR("failed to send BD, hw is err!\n");
|
|
@@ -715,7 +712,8 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
|
ctx = config->ctxs + idx;
|
|
|
|
do {
|
|
- ret = wd_alg_driver_recv(wd_digest_setting.driver, ctx->ctx, &recv_msg);
|
|
+ ret = wd_digest_setting.driver->recv(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 4323e54..a1d4dae 100644
|
|
--- a/wd_ecc.c
|
|
+++ b/wd_ecc.c
|
|
@@ -65,6 +65,7 @@ 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;
|
|
@@ -173,7 +174,8 @@ 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.driver,
|
|
+ &wd_ecc_setting.priv);
|
|
if (ret)
|
|
goto out_clear_pool;
|
|
|
|
@@ -190,13 +192,19 @@ 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.driver,
|
|
+ &wd_ecc_setting.priv);
|
|
|
|
return 0;
|
|
}
|
|
@@ -1559,8 +1567,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(wd_ecc_setting.driver, &msg_handle, ctx->ctx, &msg,
|
|
- &balance, wd_ecc_setting.config.epoll_en);
|
|
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance,
|
|
+ wd_ecc_setting.config.epoll_en);
|
|
pthread_spin_unlock(&ctx->lock);
|
|
if (unlikely(ret))
|
|
return ret;
|
|
@@ -2237,7 +2245,7 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req)
|
|
goto fail_with_msg;
|
|
msg->tag = mid;
|
|
|
|
- ret = wd_alg_driver_send(wd_ecc_setting.driver, ctx->ctx, msg);
|
|
+ ret = wd_ecc_setting.driver->send(ctx->ctx, msg);
|
|
if (unlikely(ret)) {
|
|
if (ret != -WD_EBUSY)
|
|
WD_ERR("failed to send ecc BD, hw is err!\n");
|
|
@@ -2286,7 +2294,7 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
|
ctx = config->ctxs + idx;
|
|
|
|
do {
|
|
- ret = wd_alg_driver_recv(wd_ecc_setting.driver, ctx->ctx, &recv_msg);
|
|
+ ret = wd_ecc_setting.driver->recv(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 1813676..b986855 100644
|
|
--- a/wd_rsa.c
|
|
+++ b/wd_rsa.c
|
|
@@ -73,6 +73,7 @@ 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;
|
|
@@ -148,7 +149,8 @@ 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.driver,
|
|
+ &wd_rsa_setting.priv);
|
|
if (ret)
|
|
goto out_clear_pool;
|
|
|
|
@@ -165,13 +167,19 @@ 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.driver,
|
|
+ &wd_rsa_setting.priv);
|
|
|
|
return 0;
|
|
}
|
|
@@ -415,8 +423,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(wd_rsa_setting.driver, &msg_handle, ctx->ctx, &msg,
|
|
- &balance, wd_rsa_setting.config.epoll_en);
|
|
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance,
|
|
+ wd_rsa_setting.config.epoll_en);
|
|
pthread_spin_unlock(&ctx->lock);
|
|
if (unlikely(ret))
|
|
return ret;
|
|
@@ -460,7 +468,7 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req)
|
|
goto fail_with_msg;
|
|
msg->tag = mid;
|
|
|
|
- ret = wd_alg_driver_send(wd_rsa_setting.driver, ctx->ctx, msg);
|
|
+ ret = wd_rsa_setting.driver->send(ctx->ctx, msg);
|
|
if (unlikely(ret)) {
|
|
if (ret != -WD_EBUSY)
|
|
WD_ERR("failed to send rsa BD, hw is err!\n");
|
|
@@ -509,7 +517,7 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
|
|
ctx = config->ctxs + idx;
|
|
|
|
do {
|
|
- ret = wd_alg_driver_recv(wd_rsa_setting.driver, ctx->ctx, &recv_msg);
|
|
+ ret = wd_rsa_setting.driver->recv(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 bfa3af0..989c99a 100644
|
|
--- a/wd_util.c
|
|
+++ b/wd_util.c
|
|
@@ -1792,8 +1792,8 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en)
|
|
return 0;
|
|
}
|
|
|
|
-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)
|
|
+int wd_handle_msg_sync(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;
|
|
@@ -1802,7 +1802,7 @@ int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_hand
|
|
if (balance)
|
|
timeout = WD_RECV_MAX_CNT_SLEEP;
|
|
|
|
- ret = msg_handle->send(drv, ctx, msg);
|
|
+ ret = msg_handle->send(ctx, msg);
|
|
if (unlikely(ret < 0)) {
|
|
WD_ERR("failed to send msg to hw, ret = %d!\n", ret);
|
|
return ret;
|
|
@@ -1815,7 +1815,7 @@ int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_hand
|
|
WD_ERR("wd ctx wait timeout(%d)!\n", ret);
|
|
}
|
|
|
|
- ret = msg_handle->recv(drv, ctx, msg);
|
|
+ ret = msg_handle->recv(ctx, msg);
|
|
if (ret == -WD_EAGAIN) {
|
|
if (unlikely(rx_cnt++ >= timeout)) {
|
|
WD_ERR("failed to recv msg: timeout!\n");
|
|
@@ -1920,10 +1920,16 @@ 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)
|
|
+ struct wd_alg_driver *driver, void **drv_priv)
|
|
{
|
|
+ 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");
|
|
@@ -1931,7 +1937,7 @@ int wd_alg_init_driver(struct wd_ctx_config_internal *config,
|
|
goto err_alloc;
|
|
}
|
|
|
|
- ret = driver->init(driver, config);
|
|
+ ret = driver->init(config, priv);
|
|
if (ret < 0) {
|
|
WD_ERR("driver init failed.\n");
|
|
goto err_alloc;
|
|
@@ -1944,24 +1950,32 @@ 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)
|
|
+ struct wd_alg_driver *driver, void **drv_priv)
|
|
{
|
|
+ void *priv = *drv_priv;
|
|
|
|
- driver->exit(driver);
|
|
+ driver->exit(priv);
|
|
/* 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.31.1.windows.1
|
|
|