From: Longfang Liu <liulongfang@huawei.com> This reverts commit 3fc344aa4f7c460269cd0d870fe388f01dfa22a2. --- drv/hash_mb/hash_mb.c | 45 +++++------ drv/hisi_comp.c | 32 +++----- drv/hisi_dae.c | 13 +--- drv/hisi_dae.h | 4 +- drv/hisi_dae_common.c | 28 +++---- drv/hisi_dae_join_gather.c | 21 ++---- drv/hisi_hpre.c | 76 +++++++------------ drv/hisi_sec.c | 123 +++++++++++++++---------------- drv/hisi_udma.c | 30 +++----- drv/isa_ce_sm3.c | 38 ++++------ drv/isa_ce_sm4.c | 41 ++++------- include/drv/wd_agg_drv.h | 3 +- include/drv/wd_ecc_drv.h | 5 +- include/drv/wd_join_gather_drv.h | 12 ++- include/wd_alg.h | 19 +++-- include/wd_util.h | 14 ++-- wd_aead.c | 37 ++++------ wd_agg.c | 15 ++-- wd_alg.c | 20 ----- wd_cipher.c | 20 ++--- wd_comp.c | 20 ++--- wd_dh.c | 22 +++--- wd_digest.c | 37 ++++------ wd_ecc.c | 26 ++++--- wd_join_gather.c | 28 +++---- wd_rsa.c | 22 +++--- wd_udma.c | 15 ++-- wd_util.c | 38 ++++++++-- 28 files changed, 351 insertions(+), 453 deletions(-) diff --git a/drv/hash_mb/hash_mb.c b/drv/hash_mb/hash_mb.c index bd412b2..5c0daf2 100644 --- a/drv/hash_mb/hash_mb.c +++ b/drv/hash_mb/hash_mb.c @@ -186,46 +186,34 @@ free_mb_queue: return ret; } -static int hash_mb_init(struct wd_alg_driver *drv, void *conf) +static int hash_mb_init(void *conf, void *priv) { struct wd_ctx_config_internal *config = conf; - struct hash_mb_ctx *priv; - int ret; + struct hash_mb_ctx *mb_ctx = priv; /* Fallback init is NULL */ - if (!drv || !conf) + if (!conf || !priv) return 0; - priv = malloc(sizeof(struct hash_mb_ctx)); - if (!priv) - return -WD_ENOMEM; - /* multibuff does not use epoll. */ config->epoll_en = 0; - memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal)); + memcpy(&mb_ctx->config, config, sizeof(struct wd_ctx_config_internal)); - ret = hash_mb_queue_init(config); - if (ret) { - free(priv); - return ret; - } - - drv->priv = priv; - - return WD_SUCCESS; + return hash_mb_queue_init(config); } -static void hash_mb_exit(struct wd_alg_driver *drv) +static void hash_mb_exit(void *priv) { - struct hash_mb_ctx *priv; + struct hash_mb_ctx *mb_ctx = priv; + struct wd_ctx_config_internal *config; - if (!drv || !drv->priv) + if (!priv) { + WD_ERR("invalid: input parameter is NULL!\n"); return; + } - priv = (struct hash_mb_ctx *)drv->priv; - hash_mb_queue_uninit(&priv->config, priv->config.ctx_num); - free(priv); - drv->priv = NULL; + config = &mb_ctx->config; + hash_mb_queue_uninit(config, config->ctx_num); } static void hash_mb_pad_data(struct hash_pad *hash_pad, __u8 *in, __u32 partial, @@ -267,7 +255,7 @@ static inline void hash_xor(__u8 *key_out, __u8 *key_in, __u32 key_len, __u8 xor if (i < key_len) key_out[i] = key_in[i] ^ xor_value; else - key_out[i] = xor_value; + key_out[i] = 0x0 ^ xor_value; } } @@ -555,7 +543,7 @@ static int hash_mb_check_param(struct hash_mb_queue *mb_queue, struct wd_digest_ return WD_SUCCESS; } -static int hash_mb_send(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg) +static int hash_mb_send(handle_t ctx, void *drv_msg) { struct wd_soft_ctx *s_ctx = (struct wd_soft_ctx *)ctx; struct hash_mb_queue *mb_queue = s_ctx->priv; @@ -776,7 +764,7 @@ static int hash_mb_do_jobs(struct hash_mb_queue *mb_queue) return WD_SUCCESS; } -static int hash_mb_recv(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg) +static int hash_mb_recv(handle_t ctx, void *drv_msg) { struct wd_soft_ctx *s_ctx = (struct wd_soft_ctx *)ctx; struct hash_mb_queue *mb_queue = s_ctx->priv; @@ -810,6 +798,7 @@ static int hash_mb_get_usage(void *param) .alg_name = (hash_alg_name),\ .calc_type = UADK_ALG_SVE_INSTR,\ .priority = 100,\ + .priv_size = sizeof(struct hash_mb_ctx),\ .queue_num = 1,\ .op_type_num = 1,\ .fallback = 0,\ diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c index a6b2947..be16b83 100644 --- a/drv/hisi_comp.c +++ b/drv/hisi_comp.c @@ -1414,11 +1414,11 @@ 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 wd_ctx_config_internal *config = conf; + struct hisi_zip_ctx *zip_ctx = (struct hisi_zip_ctx *)priv; struct hisi_qm_priv qm_priv; - struct hisi_zip_ctx *priv; handle_t h_qp = 0; handle_t h_ctx; __u32 i, j; @@ -1428,11 +1428,7 @@ static int hisi_zip_init(struct wd_alg_driver *drv, void *conf) 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; @@ -1450,7 +1446,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: @@ -1458,28 +1453,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 wd_ctx_config_internal *config; - struct hisi_zip_ctx *priv; + 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 (!drv || !drv->priv) - return; - - priv = (struct hisi_zip_ctx *)drv->priv; - 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 int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg, @@ -1534,7 +1521,7 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg, return 0; } -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; @@ -1722,7 +1709,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; @@ -1775,7 +1762,7 @@ static int hisi_zip_get_usage(void *param) return -WD_EINVAL; } - priv = (struct hisi_zip_ctx *)drv->priv; + priv = (struct hisi_zip_ctx *)drv->drv_data; if (!priv) return -WD_EACCES; @@ -1803,6 +1790,7 @@ static int hisi_zip_get_usage(void *param) .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_dae.c b/drv/hisi_dae.c index d86b9f6..4a1ac89 100644 --- a/drv/hisi_dae.c +++ b/drv/hisi_dae.c @@ -426,7 +426,7 @@ static int check_hashagg_param(struct wd_agg_msg *msg) return WD_SUCCESS; } -static int hashagg_send(struct wd_alg_driver *drv, handle_t ctx, void *hashagg_msg) +static int hashagg_send(handle_t ctx, void *hashagg_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct hisi_qp *qp = (struct hisi_qp *)h_qp; @@ -563,7 +563,7 @@ static void fill_hashagg_msg_task_err(struct dae_sqe *sqe, struct wd_agg_msg *ms } } -static int hashagg_recv(struct wd_alg_driver *drv, handle_t ctx, void *hashagg_msg) +static int hashagg_recv(handle_t ctx, void *hashagg_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct hisi_qp *qp = (struct hisi_qp *)h_qp; @@ -1214,17 +1214,11 @@ static void hashagg_sess_priv_uninit(struct wd_alg_driver *drv, void *priv) free(agg_ctx); } -static int hashagg_sess_priv_init(struct wd_alg_driver *drv, - struct wd_agg_sess_setup *setup, void **priv) +static int hashagg_sess_priv_init(struct wd_agg_sess_setup *setup, void **priv) { struct hashagg_ctx *agg_ctx; int ret; - if (!drv || !drv->priv) { - WD_ERR("invalid: dae drv is NULL!\n"); - return -WD_EINVAL; - } - if (!setup || !priv) { WD_ERR("invalid: dae sess priv is NULL!\n"); return -WD_EINVAL; @@ -1297,6 +1291,7 @@ static struct wd_alg_driver hashagg_driver = { .alg_name = "hashagg", .calc_type = UADK_ALG_HW, .priority = 100, + .priv_size = sizeof(struct hisi_dae_ctx), .queue_num = DAE_CTX_Q_NUM_DEF, .op_type_num = 1, .fallback = 0, diff --git a/drv/hisi_dae.h b/drv/hisi_dae.h index f82b13c..f8888b6 100644 --- a/drv/hisi_dae.h +++ b/drv/hisi_dae.h @@ -210,8 +210,8 @@ struct hisi_dae_ctx { struct wd_ctx_config_internal config; }; -void dae_exit(struct wd_alg_driver *drv); -int dae_init(struct wd_alg_driver *drv, void *conf); +void dae_exit(void *priv); +int dae_init(void *conf, void *priv); int dae_hash_table_init(struct hash_table_data *hw_table, struct hash_table_data *rehash_table, struct wd_dae_hash_table *hash_table, diff --git a/drv/hisi_dae_common.c b/drv/hisi_dae_common.c index c077d1d..216e424 100644 --- a/drv/hisi_dae_common.c +++ b/drv/hisi_dae_common.c @@ -308,11 +308,11 @@ update_table: return ret; } -int dae_init(struct wd_alg_driver *drv, void *conf) +int dae_init(void *conf, void *priv) { struct wd_ctx_config_internal *config = conf; + struct hisi_dae_ctx *dae_ctx = priv; struct hisi_qm_priv qm_priv; - struct hisi_dae_ctx *priv; handle_t h_qp = 0; handle_t h_ctx; __u32 i, j; @@ -323,10 +323,6 @@ int dae_init(struct wd_alg_driver *drv, void *conf) return -WD_EINVAL; } - priv = malloc(sizeof(struct hisi_dae_ctx)); - if (!priv) - return -WD_ENOMEM; - qm_priv.op_type = DAE_SQC_ALG_TYPE; qm_priv.sqe_size = sizeof(struct dae_sqe); /* Allocate qp for each context */ @@ -347,8 +343,7 @@ int dae_init(struct wd_alg_driver *drv, void *conf) if (ret) goto free_h_qp; } - memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal)); - drv->priv = priv; + memcpy(&dae_ctx->config, config, sizeof(struct wd_ctx_config_internal)); return WD_SUCCESS; @@ -362,22 +357,22 @@ out: hisi_qm_free_qp(h_qp); } } - free(priv); return ret; } -void dae_exit(struct wd_alg_driver *drv) +void dae_exit(void *priv) { struct wd_ctx_config_internal *config; - struct hisi_dae_ctx *priv; + struct hisi_dae_ctx *dae_ctx = priv; handle_t h_qp; __u32 i; - if (!drv || !drv->priv) + if (!priv) { + WD_ERR("invalid: input parameter is NULL!\n"); return; + } - priv = (struct hisi_dae_ctx *)drv->priv; - config = &priv->config; + config = &dae_ctx->config; for (i = 0; i < config->ctx_num; i++) { h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx); if (h_qp) { @@ -385,9 +380,6 @@ void dae_exit(struct wd_alg_driver *drv) hisi_qm_free_qp(h_qp); } } - - free(priv); - drv->priv = NULL; } int dae_get_usage(void *param) @@ -406,7 +398,7 @@ int dae_get_usage(void *param) return -WD_EINVAL; } - priv = (struct hisi_dae_ctx *)drv->priv; + priv = (struct hisi_dae_ctx *)drv->drv_data; if (!priv) return -WD_EACCES; diff --git a/drv/hisi_dae_join_gather.c b/drv/hisi_dae_join_gather.c index 8c45f57..43ed539 100644 --- a/drv/hisi_dae_join_gather.c +++ b/drv/hisi_dae_join_gather.c @@ -455,7 +455,7 @@ static int check_join_gather_param(struct wd_join_gather_msg *msg) return WD_SUCCESS; } -static int join_gather_send(struct wd_alg_driver *drv, handle_t ctx, void *send_msg) +static int join_gather_send(handle_t ctx, void *send_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct hisi_qp *qp = (struct hisi_qp *)h_qp; @@ -540,7 +540,7 @@ static void fill_join_gather_task_err(struct dae_sqe *sqe, struct wd_join_gather } } -static int join_gather_recv(struct wd_alg_driver *drv, handle_t hctx, void *recv_msg) +static int join_gather_recv(handle_t hctx, void *recv_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(hctx); struct hisi_qp *qp = (struct hisi_qp *)h_qp; @@ -892,7 +892,7 @@ static int join_gather_fill_ctx(struct join_gather_ctx *ctx, return WD_SUCCESS; } -static void join_gather_sess_priv_uninit(struct wd_alg_driver *drv, void *priv) +static void join_gather_sess_priv_uninit(void *priv) { struct join_gather_ctx *ctx = priv; @@ -904,17 +904,11 @@ static void join_gather_sess_priv_uninit(struct wd_alg_driver *drv, void *priv) free(ctx); } -static int join_gather_sess_priv_init(struct wd_alg_driver *drv, - struct wd_join_gather_sess_setup *setup, void **priv) +static int join_gather_sess_priv_init(struct wd_join_gather_sess_setup *setup, void **priv) { struct join_gather_ctx *ctx; int ret; - if (!drv || !drv->priv) { - WD_ERR("invalid: dae drv is NULL!\n"); - return -WD_EINVAL; - } - if (!setup || !priv) { WD_ERR("invalid: dae sess priv is NULL!\n"); return -WD_EINVAL; @@ -941,7 +935,7 @@ free_ctx: return ret; } -static int join_get_table_row_size(struct wd_alg_driver *drv, void *param) +static int join_get_table_row_size(void *param) { struct join_gather_ctx *ctx = param; @@ -951,7 +945,7 @@ static int join_get_table_row_size(struct wd_alg_driver *drv, void *param) return ctx->hash_table_row_size; } -static int gather_get_batch_row_size(struct wd_alg_driver *drv, void *param, +static int gather_get_batch_row_size(void *param, __u32 *row_size, __u32 size) { struct join_gather_ctx *ctx = param; @@ -967,8 +961,7 @@ static int gather_get_batch_row_size(struct wd_alg_driver *drv, void *param, return 0; } -static int join_hash_table_init(struct wd_alg_driver *drv, - struct wd_dae_hash_table *table, void *priv) +static int join_hash_table_init(struct wd_dae_hash_table *table, void *priv) { struct join_gather_ctx *ctx = priv; diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index 3c41826..7da8407 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -680,11 +680,11 @@ 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 *hpre_ctx = (struct hisi_hpre_ctx *)priv; struct hisi_qm_priv qm_priv; - struct hisi_hpre_ctx *priv; int ret; if (!config->ctx_num) { @@ -692,27 +692,19 @@ static int hpre_rsa_dh_init(struct wd_alg_driver *drv, void *conf) return -WD_EINVAL; } - priv = malloc(sizeof(struct hisi_hpre_ctx)); - if (!priv) - return -WD_EINVAL; - qm_priv.op_type = HPRE_HW_V2_ALG_TYPE; - ret = hpre_init_qm_priv(config, priv, &qm_priv); - if (ret) { - free(priv); + ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv); + if (ret) return ret; - } - - drv->priv = priv; return WD_SUCCESS; } -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 *hpre_ctx = (struct hisi_hpre_ctx *)priv; struct hisi_qm_priv qm_priv; - struct hisi_hpre_ctx *priv; int ret; if (!config->ctx_num) { @@ -720,44 +712,28 @@ static int hpre_ecc_init(struct wd_alg_driver *drv, void *conf) return -WD_EINVAL; } - priv = malloc(sizeof(struct hisi_hpre_ctx)); - if (!priv) - return -WD_EINVAL; - qm_priv.op_type = HPRE_HW_V3_ECC_ALG_TYPE; - ret = hpre_init_qm_priv(config, priv, &qm_priv); - if (ret) { - free(priv); + ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv); + if (ret) return ret; - } - - drv->priv = priv; return WD_SUCCESS; } -static void hpre_exit(struct wd_alg_driver *drv) +static void hpre_exit(void *priv) { - struct wd_ctx_config_internal *config; - struct hisi_hpre_ctx *priv; + 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 (!drv || !drv->priv) - return; - - priv = (struct hisi_hpre_ctx *)drv->priv; - 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 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; @@ -829,7 +805,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; @@ -949,7 +925,7 @@ static int dh_out_transfer(struct wd_dh_msg *msg, struct hisi_hpre_sqe *hw_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 map_info_cache cache = {0}; @@ -1020,7 +996,7 @@ dh_fail: return ret; } -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; @@ -2147,7 +2123,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; @@ -2743,7 +2719,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; @@ -2786,7 +2762,7 @@ static handle_t hpre_find_dev_qp(struct wd_alg_driver *drv, const char *dev_name handle_t qp = 0; __u32 i; - priv = (struct hisi_hpre_ctx *)drv->priv; + priv = (struct hisi_hpre_ctx *)drv->drv_data; if (!priv) return 0; @@ -2874,31 +2850,30 @@ static void ecc_sess_eops_uninit(struct wd_alg_driver *drv, void *params) free(params); } -static bool is_valid_hw_type(struct wd_alg_driver *drv) +static bool is_valid_hw_type(void *drv_priv) { struct hisi_hpre_ctx *hpre_ctx; struct hisi_qp *qp; - if (unlikely(!drv || !drv->priv)) + if (unlikely(!drv_priv)) return false; - hpre_ctx = (struct hisi_hpre_ctx *)drv->priv; + hpre_ctx = (struct hisi_hpre_ctx *)drv_priv; qp = (struct hisi_qp *)wd_ctx_get_priv(hpre_ctx->config.ctxs[0].ctx); if (!qp || qp->q_info.hw_type < HISI_QM_API_VER3_BASE) return false; return true; } -static void ecc_sess_eops_params_cfg(struct wd_alg_driver *drv, - struct wd_ecc_sess_setup *setup, - struct wd_ecc_curve *cv, void *params) +static void ecc_sess_eops_params_cfg(struct wd_ecc_sess_setup *setup, + struct wd_ecc_curve *cv, void *drv_priv, void *params) { __u8 data[SECP256R1_PARAM_SIZE] = SECG_P256_R1_PARAM; struct hpre_ecc_ctx *ecc_ctx = params; __u32 key_size; int ret; - if (!is_valid_hw_type(drv)) + if (!is_valid_hw_type(drv_priv)) return; if (!ecc_ctx) { @@ -2938,6 +2913,7 @@ static int hpre_ecc_get_extend_ops(void *ops) .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,\ @@ -2962,6 +2938,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, @@ -2977,6 +2954,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 c8b831c..fb9de2c 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -526,76 +526,76 @@ 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_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); -static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); -static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); -static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); +static int hisi_sec_cipher_send(handle_t ctx, void *wd_msg); +static int hisi_sec_cipher_recv(handle_t ctx, void *wd_msg); +static int hisi_sec_cipher_send_v3(handle_t ctx, void *wd_msg); +static int hisi_sec_cipher_recv_v3(handle_t ctx, void *wd_msg); -static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); -static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); -static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); -static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); +static int hisi_sec_digest_send(handle_t ctx, void *wd_msg); +static int hisi_sec_digest_recv(handle_t ctx, void *wd_msg); +static int hisi_sec_digest_send_v3(handle_t ctx, void *wd_msg); +static int hisi_sec_digest_recv_v3(handle_t ctx, void *wd_msg); -static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); -static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); -static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); -static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); +static int hisi_sec_aead_send(handle_t ctx, void *wd_msg); +static int hisi_sec_aead_recv(handle_t ctx, void *wd_msg); +static int hisi_sec_aead_send_v3(handle_t ctx, void *wd_msg); +static int hisi_sec_aead_recv_v3(handle_t ctx, void *wd_msg); -static int cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *msg) +static int cipher_send(handle_t ctx, void *msg) { struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx); if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE) - return hisi_sec_cipher_send(drv, ctx, msg); - return hisi_sec_cipher_send_v3(drv, ctx, msg); + return hisi_sec_cipher_send(ctx, msg); + return hisi_sec_cipher_send_v3(ctx, msg); } -static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) +static int cipher_recv(handle_t ctx, void *msg) { struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx); if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE) - return hisi_sec_cipher_recv(drv, ctx, msg); - return hisi_sec_cipher_recv_v3(drv, ctx, msg); + return hisi_sec_cipher_recv(ctx, msg); + return hisi_sec_cipher_recv_v3(ctx, msg); } -static int digest_send(struct wd_alg_driver *drv, handle_t ctx, void *msg) +static int digest_send(handle_t ctx, void *msg) { struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx); if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE) - return hisi_sec_digest_send(drv, ctx, msg); - return hisi_sec_digest_send_v3(drv, ctx, msg); + return hisi_sec_digest_send(ctx, msg); + return hisi_sec_digest_send_v3(ctx, msg); } -static int digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) +static int digest_recv(handle_t ctx, void *msg) { struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx); if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE) - return hisi_sec_digest_recv(drv, ctx, msg); - return hisi_sec_digest_recv_v3(drv, ctx, msg); + return hisi_sec_digest_recv(ctx, msg); + return hisi_sec_digest_recv_v3(ctx, msg); } -static int aead_send(struct wd_alg_driver *drv, handle_t ctx, void *msg) +static int aead_send(handle_t ctx, void *msg) { struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx); if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE) - return hisi_sec_aead_send(drv, ctx, msg); - return hisi_sec_aead_send_v3(drv, ctx, msg); + return hisi_sec_aead_send(ctx, msg); + return hisi_sec_aead_send_v3(ctx, msg); } -static int aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) +static int aead_recv(handle_t ctx, void *msg) { struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx); if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE) - return hisi_sec_aead_recv(drv, ctx, msg); - return hisi_sec_aead_recv_v3(drv, ctx, msg); + return hisi_sec_aead_recv(ctx, msg); + return hisi_sec_aead_recv_v3(ctx, msg); } static int hisi_sec_get_usage(void *param) @@ -614,7 +614,7 @@ static int hisi_sec_get_usage(void *param) return -WD_EINVAL; } - priv = (struct hisi_sec_ctx *)drv->priv; + priv = (struct hisi_sec_ctx *)drv->drv_data; if (!priv) return -WD_EACCES; @@ -638,8 +638,8 @@ static int hisi_sec_get_usage(void *param) static int eops_param_check(struct wd_alg_driver *drv, struct wd_mm_ops *mm_ops) { - if (!drv || !drv->priv) { - WD_ERR("invalid: aead drv or priv is NULL!\n"); + if (!drv || !drv->drv_data) { + WD_ERR("invalid: aead drv or data is NULL!\n"); return -WD_EINVAL; } @@ -680,7 +680,7 @@ static int aead_sess_eops_init(struct wd_alg_driver *drv, return -WD_ENOMEM; } - sec_ctx = (struct hisi_sec_ctx *)drv->priv; + sec_ctx = (struct hisi_sec_ctx *)drv->drv_data; qp = (struct hisi_qp *)wd_ctx_get_priv(sec_ctx->config.ctxs[0].ctx); sq_depth = qp->q_info.sq_depth; aiv_addr->aiv = mm_ops->alloc(mm_ops->usr, (__u32)sq_depth << AEAD_AIV_OFFSET); @@ -735,7 +735,7 @@ static void aead_sess_eops_uninit(struct wd_alg_driver *drv, return; } - sec_ctx = (struct hisi_sec_ctx *)drv->priv; + sec_ctx = (struct hisi_sec_ctx *)drv->drv_data; qp = (struct hisi_qp *)wd_ctx_get_priv(sec_ctx->config.ctxs[0].ctx); sq_depth = qp->q_info.sq_depth; @@ -793,6 +793,7 @@ static int sec_aead_get_extend_ops(void *ops) .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,\ @@ -1400,7 +1401,7 @@ static int fill_cipher_bd2(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe) return 0; } -static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) +static int hisi_sec_cipher_send(handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_cipher_msg *msg = wd_msg; @@ -1456,7 +1457,7 @@ static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *w return 0; } -static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) +int hisi_sec_cipher_recv(handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_cipher_msg *recv_msg = wd_msg; @@ -1693,7 +1694,7 @@ static void fill_sec_prefetch(__u8 data_fmt, __u32 len, __u16 hw_type, struct hi sqe->auth_mac_key |= (__u32)SEC_ENABLE_SVA_PREFETCH << SEC_SVA_PREFETCH_OFFSET; } -static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) +static int hisi_sec_cipher_send_v3(handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct hisi_qp *qp = (struct hisi_qp *)h_qp; @@ -1800,7 +1801,7 @@ static void parse_cipher_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, dump_sec_msg(temp_msg, "cipher"); } -static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) +int hisi_sec_cipher_recv_v3(handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_cipher_msg *recv_msg = wd_msg; @@ -2132,7 +2133,7 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type) return 0; } -static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) +static int hisi_sec_digest_send(handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_digest_msg *msg = wd_msg; @@ -2209,7 +2210,7 @@ put_sgl: return ret; } -static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) +int hisi_sec_digest_recv(handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_digest_msg *recv_msg = wd_msg; @@ -2473,7 +2474,7 @@ map_err: return -WD_ENOMEM; } -static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) +static int hisi_sec_digest_send_v3(handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct hisi_qp *qp = (struct hisi_qp *)h_qp; @@ -2587,7 +2588,7 @@ static void parse_digest_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, dump_sec_msg(temp_msg, "digest"); } -static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) +int hisi_sec_digest_recv_v3(handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_digest_msg *recv_msg = wd_msg; @@ -3216,7 +3217,7 @@ static int fill_aead_bd2_addr(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe, return aead_mem_nosva_map(msg, sqe, idx); } -static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) +static int hisi_sec_aead_send(handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct hisi_qp *qp = (struct hisi_qp *)h_qp; @@ -3347,7 +3348,7 @@ static void parse_aead_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe, dump_sec_msg(temp_msg, "aead"); } -static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) +int hisi_sec_aead_recv(handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_aead_msg *recv_msg = wd_msg; @@ -3744,7 +3745,7 @@ static int fill_aead_bd3_addr(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe return aead_mem_nosva_map_v3(msg, sqe, idx); } -static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) +static int hisi_sec_aead_send_v3(handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct hisi_qp *qp = (struct hisi_qp *)h_qp; @@ -3863,7 +3864,7 @@ static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, dump_sec_msg(temp_msg, "aead"); } -static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) +int hisi_sec_aead_recv_v3(handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct wd_aead_msg *recv_msg = wd_msg; @@ -3888,11 +3889,11 @@ static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void * return 0; } -static int hisi_sec_init(struct wd_alg_driver *drv, void *conf) +static int hisi_sec_init(void *conf, void *priv) { struct wd_ctx_config_internal *config = conf; + struct hisi_sec_ctx *sec_ctx = priv; struct hisi_qm_priv qm_priv; - struct hisi_sec_ctx *priv; handle_t h_qp = 0; handle_t h_ctx; __u32 i, j; @@ -3902,10 +3903,6 @@ static int hisi_sec_init(struct wd_alg_driver *drv, void *conf) 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++) { @@ -3922,8 +3919,7 @@ 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)); - drv->priv = priv; + memcpy(&sec_ctx->config, config, sizeof(struct wd_ctx_config_internal)); return 0; @@ -3936,25 +3932,24 @@ out: return -WD_EINVAL; } -static void hisi_sec_exit(struct wd_alg_driver *drv) +static void hisi_sec_exit(void *priv) { struct wd_ctx_config_internal *config; - struct hisi_sec_ctx *priv; + struct hisi_sec_ctx *sec_ctx = priv; handle_t h_qp; __u32 i; - if (!drv || !drv->priv) + if (!priv) { + WD_ERR("invalid: input parameter is NULL!\n"); return; + } - priv = (struct hisi_sec_ctx *)drv->priv; - 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; } #ifdef WD_STATIC_DRV diff --git a/drv/hisi_udma.c b/drv/hisi_udma.c index a9f5607..5c8a743 100644 --- a/drv/hisi_udma.c +++ b/drv/hisi_udma.c @@ -290,7 +290,7 @@ static void fill_init_value(struct udma_sqe *sqe, struct wd_udma_msg *msg) memset(&sqe->init_val, msg->value, sizeof(__u64)); } -static int udma_send(struct wd_alg_driver *drv, handle_t ctx, void *udma_msg) +static int udma_send(handle_t ctx, void *udma_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct hisi_qp *qp = (struct hisi_qp *)h_qp; @@ -342,7 +342,7 @@ static void dump_udma_msg(struct udma_sqe *sqe, struct wd_udma_msg *msg) "op_type:%u addr_num:%d.\n", msg->op_type, msg->addr_num); } -static int udma_recv(struct wd_alg_driver *drv, handle_t ctx, void *udma_msg) +static int udma_recv(handle_t ctx, void *udma_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); struct hisi_qp *qp = (struct hisi_qp *)h_qp; @@ -442,11 +442,11 @@ free_inter_addr: return ret; } -static int udma_init(struct wd_alg_driver *drv, void *conf) +static int udma_init(void *conf, void *priv) { struct wd_ctx_config_internal *config = conf; + struct hisi_udma_ctx *uctx = priv; struct hisi_qm_priv qm_priv; - struct hisi_udma_ctx *priv; handle_t h_qp = 0; handle_t h_ctx; __u32 i, j; @@ -457,10 +457,6 @@ static int udma_init(struct wd_alg_driver *drv, void *conf) return -WD_EINVAL; } - priv = malloc(sizeof(struct hisi_udma_ctx)); - if (!priv) - return -WD_ENOMEM; - qm_priv.op_type = UDMA_ALG_TYPE; qm_priv.sqe_size = sizeof(struct udma_sqe); /* Allocate qp for each context */ @@ -481,8 +477,7 @@ static int udma_init(struct wd_alg_driver *drv, void *conf) if (ret) goto free_h_qp; } - memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal)); - drv->priv = priv; + memcpy(&uctx->config, config, sizeof(struct wd_ctx_config_internal)); return WD_SUCCESS; free_h_qp: @@ -493,30 +488,26 @@ out: udma_uninit_qp_priv(h_qp); hisi_qm_free_qp(h_qp); } - free(priv); return ret; } -static void udma_exit(struct wd_alg_driver *drv) +static void udma_exit(void *priv) { struct wd_ctx_config_internal *config; - struct hisi_udma_ctx *priv; + struct hisi_udma_ctx *uctx = priv; handle_t h_qp; __u32 i; - if (!drv || !drv->priv) + if (!priv) return; - priv = (struct hisi_udma_ctx *)drv->priv; - config = &priv->config; + config = &uctx->config; for (i = 0; i < config->ctx_num; i++) { h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx); udma_uninit_qp_priv(h_qp); hisi_qm_free_qp(h_qp); } - free(priv); - drv->priv = NULL; } static int udma_get_usage(void *param) @@ -535,7 +526,7 @@ static int udma_get_usage(void *param) return -WD_EINVAL; } - priv = (struct hisi_udma_ctx *)drv->priv; + priv = (struct hisi_udma_ctx *)drv->drv_data; if (!priv) return -WD_EACCES; @@ -562,6 +553,7 @@ static struct wd_alg_driver udma_driver = { .alg_name = "udma", .calc_type = UADK_ALG_HW, .priority = 100, + .priv_size = sizeof(struct hisi_udma_ctx), .queue_num = UDMA_CTX_Q_NUM_DEF, .op_type_num = 1, .fallback = 0, diff --git a/drv/isa_ce_sm3.c b/drv/isa_ce_sm3.c index 8d23061..0ebaba5 100644 --- a/drv/isa_ce_sm3.c +++ b/drv/isa_ce_sm3.c @@ -24,10 +24,10 @@ typedef void (sm3_ce_block_fn)(__u32 word_reg[SM3_STATE_WORDS], const unsigned char *src, size_t blocks); -static int sm3_ce_drv_init(struct wd_alg_driver *drv, void *conf); -static void sm3_ce_drv_exit(struct wd_alg_driver *drv); -static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg); -static int sm3_ce_drv_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg); +static int sm3_ce_drv_init(void *conf, void *priv); +static void sm3_ce_drv_exit(void *priv); +static int sm3_ce_drv_send(handle_t ctx, void *digest_msg); +static int sm3_ce_drv_recv(handle_t ctx, void *digest_msg); static int sm3_ce_get_usage(void *param); static struct wd_alg_driver sm3_ce_alg_driver = { @@ -35,6 +35,7 @@ static struct wd_alg_driver sm3_ce_alg_driver = { .alg_name = "sm3", .calc_type = UADK_ALG_CE_INSTR, .priority = 200, + .priv_size = sizeof(struct sm3_ce_drv_ctx), .queue_num = 1, .op_type_num = 1, .fallback = 0, @@ -335,7 +336,7 @@ static int do_hmac_sm3_ce(struct wd_digest_msg *msg, __u8 *out_hmac) return WD_SUCCESS; } -static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg) +static int sm3_ce_drv_send(handle_t ctx, void *digest_msg) { struct wd_digest_msg *msg = (struct wd_digest_msg *)digest_msg; __u8 digest[SM3_DIGEST_SIZE] = {0}; @@ -370,39 +371,26 @@ static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest return ret; } -static int sm3_ce_drv_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg) +static int sm3_ce_drv_recv(handle_t ctx, void *digest_msg) { return WD_SUCCESS; } -static int sm3_ce_drv_init(struct wd_alg_driver *drv, void *conf) +static int sm3_ce_drv_init(void *conf, void *priv) { - struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf; - struct sm3_ce_drv_ctx *priv; + struct wd_ctx_config_internal *config = conf; + struct sm3_ce_drv_ctx *sctx = priv; /* Fallback init is NULL */ - if (!drv || !conf) + if (!conf || !conf) return 0; - priv = malloc(sizeof(struct sm3_ce_drv_ctx)); - if (!priv) - return -WD_ENOMEM; - config->epoll_en = 0; - memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal)); - drv->priv = priv; + memcpy(&sctx->config, config, sizeof(struct wd_ctx_config_internal)); return WD_SUCCESS; } -static void sm3_ce_drv_exit(struct wd_alg_driver *drv) +static void sm3_ce_drv_exit(void *priv) { - struct sm3_ce_drv_ctx *sctx; - - if (!drv || !drv->priv) - return; - - sctx = (struct sm3_ce_drv_ctx *)drv->priv; - free(sctx); - drv->priv = NULL; } diff --git a/drv/isa_ce_sm4.c b/drv/isa_ce_sm4.c index 52dca1f..504ef73 100644 --- a/drv/isa_ce_sm4.c +++ b/drv/isa_ce_sm4.c @@ -11,9 +11,10 @@ * Copyright 2024 Huawei Technologies Co.,Ltd. All rights reserved. */ +#include "wd_alg.h" #include "drv/wd_cipher_drv.h" -#include "wd_cipher.h" #include "isa_ce_sm4.h" +#include "wd_cipher.h" #define SM4_ENCRYPT 1 #define SM4_DECRYPT 0 @@ -31,36 +32,23 @@ ((p)[0] = (__u8)((v) >> 24), (p)[1] = (__u8)((v) >> 16), \ (p)[2] = (__u8)((v) >> 8), (p)[3] = (__u8)(v)) -static int isa_ce_init(struct wd_alg_driver *drv, void *conf) +static int isa_ce_init(void *conf, void *priv) { struct wd_ctx_config_internal *config = conf; - struct sm4_ce_drv_ctx *priv; + struct sm4_ce_drv_ctx *sctx = priv; /* Fallback init is NULL */ - if (!drv || !conf) + if (!conf || !priv) return 0; - priv = malloc(sizeof(struct sm4_ce_drv_ctx)); - if (!priv) - return -WD_EINVAL; - config->epoll_en = 0; - memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal)); - drv->priv = priv; + memcpy(&sctx->config, config, sizeof(struct wd_ctx_config_internal)); - return WD_SUCCESS; + return 0; } -static void isa_ce_exit(struct wd_alg_driver *drv) +static void isa_ce_exit(void *priv) { - struct sm4_ce_drv_ctx *sctx; - - if (!drv || !drv->priv) - return; - - sctx = (struct sm4_ce_drv_ctx *)drv->priv; - free(sctx); - drv->priv = NULL; } /* increment upper 96 bits of 128-bit counter by 1 */ @@ -334,7 +322,7 @@ static int sm4_xts_decrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rkey return 0; } -static int isa_ce_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) +static int isa_ce_cipher_send(handle_t ctx, void *wd_msg) { struct wd_cipher_msg *msg = wd_msg; struct SM4_KEY rkey; @@ -400,19 +388,19 @@ static int isa_ce_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_ return ret; } -static int isa_ce_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) +static int isa_ce_cipher_recv(handle_t ctx, void *wd_msg) { return 0; } -static int cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *msg) +static int cipher_send(handle_t ctx, void *msg) { - return isa_ce_cipher_send(drv, ctx, msg); + return isa_ce_cipher_send(ctx, msg); } -static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) +static int cipher_recv(handle_t ctx, void *msg) { - return isa_ce_cipher_recv(drv, ctx, msg); + return isa_ce_cipher_recv(ctx, msg); } #define GEN_CE_ALG_DRIVER(ce_alg_name, alg_type) \ @@ -421,6 +409,7 @@ static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) .alg_name = (ce_alg_name),\ .calc_type = UADK_ALG_CE_INSTR,\ .priority = 200,\ + .priv_size = sizeof(struct sm4_ce_drv_ctx),\ .op_type_num = 1,\ .fallback = 0,\ .init = isa_ce_init,\ diff --git a/include/drv/wd_agg_drv.h b/include/drv/wd_agg_drv.h index b26b25d..8952ee9 100644 --- a/include/drv/wd_agg_drv.h +++ b/include/drv/wd_agg_drv.h @@ -43,8 +43,7 @@ struct wd_agg_msg { struct wd_agg_ops { int (*get_row_size)(struct wd_alg_driver *drv, void *priv); - int (*sess_init)(struct wd_alg_driver *drv, - struct wd_agg_sess_setup *setup, void **priv); + int (*sess_init)(struct wd_agg_sess_setup *setup, void **priv); void (*sess_uninit)(struct wd_alg_driver *drv, void *priv); int (*hash_table_init)(struct wd_alg_driver *drv, struct wd_dae_hash_table *hash_table, void *priv); diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h index 48c422f..98ff28c 100644 --- a/include/drv/wd_ecc_drv.h +++ b/include/drv/wd_ecc_drv.h @@ -181,9 +181,8 @@ struct wd_ecc_out { struct wd_ecc_extend_ops { void *params; /* the params are passed to the following ops */ - void (*eops_params_cfg)(struct wd_alg_driver *drv, - struct wd_ecc_sess_setup *setup, - struct wd_ecc_curve *cv, void *params); + void (*eops_params_cfg)(struct wd_ecc_sess_setup *setup, + struct wd_ecc_curve *cv, void *drv_priv, void *params); int (*sess_init)(struct wd_alg_driver *drv, void **params); void (*sess_uninit)(struct wd_alg_driver *drv, void *params); }; diff --git a/include/drv/wd_join_gather_drv.h b/include/drv/wd_join_gather_drv.h index dbf4ee7..d7f136d 100644 --- a/include/drv/wd_join_gather_drv.h +++ b/include/drv/wd_join_gather_drv.h @@ -33,14 +33,12 @@ struct wd_join_gather_msg { }; struct wd_join_gather_ops { - int (*get_table_row_size)(struct wd_alg_driver *drv, void *priv); - int (*get_batch_row_size)(struct wd_alg_driver *drv, void *priv, + int (*get_table_row_size)(void *priv); + int (*get_batch_row_size)(void *priv, __u32 *batch_row_size, __u32 size); - int (*sess_init)(struct wd_alg_driver *drv, - struct wd_join_gather_sess_setup *setup, void **priv); - void (*sess_uninit)(struct wd_alg_driver *drv, void *priv); - int (*hash_table_init)(struct wd_alg_driver *drv, - struct wd_dae_hash_table *hash_table, void *priv); + int (*sess_init)(struct wd_join_gather_sess_setup *setup, void **priv); + void (*sess_uninit)(void *priv); + int (*hash_table_init)(struct wd_dae_hash_table *hash_table, void *priv); }; struct wd_join_gather_msg *wd_join_gather_get_msg(__u32 idx, __u32 tag); diff --git a/include/wd_alg.h b/include/wd_alg.h index 18503ca..885a5e3 100644 --- a/include/wd_alg.h +++ b/include/wd_alg.h @@ -19,6 +19,7 @@ extern "C" { #define handle_t uintptr_t #define ALG_NAME_SIZE 128 #define DEV_NAME_LEN 128 +typedef unsigned char __u8; /* * Macros related to arm platform: @@ -85,7 +86,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 @@ -105,13 +107,14 @@ struct wd_alg_driver { int calc_type; int queue_num; int op_type_num; - void *priv; + int priv_size; + int *drv_data; 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); int (*get_extend_ops)(void *ops); }; @@ -182,10 +185,6 @@ bool wd_drv_alg_support(const char *alg_name, void wd_enable_drv(struct wd_alg_driver *drv); void wd_disable_drv(struct wd_alg_driver *drv); -int wd_alg_driver_init(struct wd_alg_driver *drv, void *conf); -void wd_alg_driver_exit(struct wd_alg_driver *drv); -int wd_alg_driver_send(struct wd_alg_driver *drv, handle_t ctx, void *msg); -int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg); int wd_alg_get_dev_usage(const char *dev_name, const char *alg_type, __u8 op_type); int wd_get_alg_type(const char *alg_name, char *alg_type); diff --git a/include/wd_util.h b/include/wd_util.h index 2abceec..14985e2 100644 --- a/include/wd_util.h +++ b/include/wd_util.h @@ -120,8 +120,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 { @@ -378,7 +378,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. @@ -387,8 +386,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. @@ -486,13 +485,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 8467409..43bda73 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -34,6 +34,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; @@ -603,7 +604,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; @@ -652,30 +654,21 @@ out_clear_init: return ret; } -static int wd_aead_uninit_nolock(void) +static void wd_aead_uninit_nolock(void) { - enum wd_status status; - - wd_alg_get_init(&wd_aead_setting.status, &status); - if (status == WD_UNINIT) - return -WD_EINVAL; - 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); - - return 0; + wd_aead_setting.driver, + &wd_aead_setting.priv); } void wd_aead_uninit(void) { - int ret; - - ret = wd_aead_uninit_nolock(); - if (ret) + if (!wd_aead_setting.priv) return; + wd_aead_uninit_nolock(); wd_aead_close_driver(WD_TYPE_V1); wd_alg_clear_init(&wd_aead_setting.status); } @@ -781,12 +774,10 @@ out_uninit: void wd_aead_uninit2(void) { - int ret; - - ret = wd_aead_uninit_nolock(); - if (ret) + if (!wd_aead_setting.priv) return; + wd_aead_uninit_nolock(); wd_alg_attrs_uninit(&wd_aead_init_attrs); wd_alg_drv_unbind(wd_aead_setting.driver); wd_aead_close_driver(WD_TYPE_V2); @@ -875,8 +866,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; @@ -951,7 +942,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"); @@ -1001,7 +992,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_agg.c b/wd_agg.c index 8c54d10..66e9e0f 100644 --- a/wd_agg.c +++ b/wd_agg.c @@ -361,7 +361,7 @@ static int wd_agg_init_sess_priv(struct wd_agg_sess *sess, struct wd_agg_sess_se WD_ERR("failed to get session uninit ops!\n"); return -WD_EINVAL; } - ret = sess->ops.sess_init(wd_agg_setting.driver, setup, &sess->priv); + ret = sess->ops.sess_init(setup, &sess->priv); if (ret) { WD_ERR("failed to init session priv!\n"); return ret; @@ -595,7 +595,8 @@ static int wd_agg_alg_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret < 0) goto out_clear_sched; - ret = wd_alg_init_driver(&wd_agg_setting.config, wd_agg_setting.driver); + ret = wd_alg_init_driver(&wd_agg_setting.config, wd_agg_setting.driver, + &wd_agg_setting.priv); if (ret) goto out_clear_pool; @@ -624,7 +625,8 @@ static int wd_agg_alg_uninit(void) /* Unset config, sched, driver */ wd_clear_sched(&wd_agg_setting.sched); - wd_alg_uninit_driver(&wd_agg_setting.config, wd_agg_setting.driver); + wd_alg_uninit_driver(&wd_agg_setting.config, wd_agg_setting.driver, + &wd_agg_setting.priv); return WD_SUCCESS; } @@ -1101,8 +1103,7 @@ static int wd_agg_sync_job(struct wd_agg_sess *sess, struct wd_agg_req *req, msg_handle.recv = wd_agg_setting.driver->recv; pthread_spin_lock(&ctx->lock); - ret = wd_handle_msg_sync(wd_agg_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; @@ -1203,7 +1204,7 @@ static int wd_agg_async_job(struct wd_agg_sess *sess, struct wd_agg_req *req, bo else fill_request_msg_output(msg, req, sess, false); msg->tag = msg_id; - ret = wd_alg_driver_send(wd_agg_setting.driver, ctx->ctx, msg); + ret = wd_agg_setting.driver->send(ctx->ctx, msg); if (unlikely(ret < 0)) { if (ret != -WD_EBUSY) WD_ERR("wd agg async send err!\n"); @@ -1542,7 +1543,7 @@ static int wd_agg_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx; do { - ret = wd_alg_driver_recv(wd_agg_setting.driver, ctx->ctx, &resp_msg); + ret = wd_agg_setting.driver->recv(ctx->ctx, &resp_msg); if (ret == -WD_EAGAIN) { return ret; } else if (unlikely(ret < 0)) { diff --git a/wd_alg.c b/wd_alg.c index 1e4f14a..a1a0a79 100644 --- a/wd_alg.c +++ b/wd_alg.c @@ -465,26 +465,6 @@ void wd_release_drv(struct wd_alg_driver *drv) pthread_mutex_unlock(&mutex); } -int wd_alg_driver_init(struct wd_alg_driver *drv, void *conf) -{ - return drv->init(drv, conf); -} - -void wd_alg_driver_exit(struct wd_alg_driver *drv) -{ - drv->exit(drv); -} - -int wd_alg_driver_send(struct wd_alg_driver *drv, handle_t ctx, void *msg) -{ - return drv->send(drv, ctx, msg); -} - -int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) -{ - return drv->recv(drv, ctx, msg); -} - int wd_alg_get_dev_usage(const char *dev_name, const char *alg_type, __u8 alg_op_type) { struct wd_alg_list *pnext = alg_list_head.next; diff --git a/wd_cipher.c b/wd_cipher.c index 58656dc..53733a4 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -53,6 +53,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; @@ -379,7 +380,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; @@ -396,10 +398,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 */ @@ -409,7 +410,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; } @@ -720,8 +722,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, msg_handle.recv = wd_cipher_setting.driver->recv; wd_ctx_spin_lock(ctx, wd_cipher_setting.driver->calc_type); - 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); wd_ctx_spin_unlock(ctx, wd_cipher_setting.driver->calc_type); return ret; @@ -796,7 +798,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"); @@ -846,7 +848,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 c67b7f1..be08ee8 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -51,6 +51,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; @@ -172,7 +173,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; @@ -189,10 +191,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 */ @@ -202,7 +203,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; } @@ -382,7 +384,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"); @@ -685,8 +687,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; @@ -944,7 +946,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)) { if (ret != -WD_EBUSY) WD_ERR("wd comp send error, ret = %d!\n", ret); diff --git a/wd_dh.c b/wd_dh.c index 0c1372c..42a1805 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -36,6 +36,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; @@ -144,7 +145,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; @@ -161,11 +163,10 @@ out_clear_ctx_config: static int wd_dh_common_uninit(void) { - enum wd_status status; - - wd_alg_get_init(&wd_dh_setting.status, &status); - if (status == WD_UNINIT) + 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); @@ -173,7 +174,8 @@ static int wd_dh_common_uninit(void) /* 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 WD_SUCCESS; } @@ -390,8 +392,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; @@ -437,7 +439,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"); @@ -488,7 +490,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 0b37f8b..763eae5 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -42,6 +42,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; @@ -312,7 +313,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; @@ -361,29 +363,21 @@ out_clear_init: return ret; } -static int wd_digest_uninit_nolock(void) +static void wd_digest_uninit_nolock(void) { - enum wd_status status; - - wd_alg_get_init(&wd_digest_setting.status, &status); - if (status == WD_UNINIT) - return -WD_EINVAL; - 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); - return 0; + wd_digest_setting.driver, + &wd_digest_setting.priv); } void wd_digest_uninit(void) { - int ret; - - ret = wd_digest_uninit_nolock(); - if (ret) + if (!wd_digest_setting.priv) return; + wd_digest_uninit_nolock(); wd_digest_close_driver(WD_TYPE_V1); wd_alg_clear_init(&wd_digest_setting.status); } @@ -485,12 +479,10 @@ out_uninit: void wd_digest_uninit2(void) { - int ret; - - ret = wd_digest_uninit_nolock(); - if (ret) + if (!wd_digest_setting.priv) return; + wd_digest_uninit_nolock(); wd_alg_attrs_uninit(&wd_digest_init_attrs); wd_alg_drv_unbind(wd_digest_setting.driver); wd_digest_close_driver(WD_TYPE_V2); @@ -655,8 +647,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *ds msg_handle.recv = wd_digest_setting.driver->recv; wd_ctx_spin_lock(ctx, wd_digest_setting.driver->calc_type); - 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); wd_ctx_spin_unlock(ctx, wd_digest_setting.driver->calc_type); if (unlikely(ret)) return ret; @@ -750,7 +742,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"); @@ -800,7 +792,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 2c88d0a..900f36c 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -69,6 +69,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; @@ -210,7 +211,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; @@ -227,11 +229,10 @@ out_clear_ctx_config: static int wd_ecc_common_uninit(void) { - enum wd_status status; - - wd_alg_get_init(&wd_ecc_setting.status, &status); - if (status == WD_UNINIT) + 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); @@ -239,7 +240,8 @@ static int wd_ecc_common_uninit(void) /* 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 WD_SUCCESS; } @@ -1203,8 +1205,8 @@ static void wd_ecc_sess_eops_cfg(struct wd_ecc_sess_setup *setup, { if (sess->eops.sess_init && sess->eops.eops_params_cfg) { /* the config result does not impact task sucesss or failure */ - sess->eops.eops_params_cfg(wd_ecc_setting.driver, setup, sess->key.cv, - sess->eops.params); + sess->eops.eops_params_cfg(setup, sess->key.cv, + wd_ecc_setting.priv, sess->eops.params); } } @@ -1652,8 +1654,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; @@ -2339,7 +2341,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"); @@ -2389,7 +2391,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_join_gather.c b/wd_join_gather.c index 915c1b8..86190c4 100644 --- a/wd_join_gather.c +++ b/wd_join_gather.c @@ -410,13 +410,12 @@ static void wd_join_gather_uninit_sess(struct wd_join_gather_sess *sess) free(sess->gather_conf.batch_row_size); if (sess->ops.sess_uninit) - sess->ops.sess_uninit(wd_join_gather_setting.driver, sess->priv); + sess->ops.sess_uninit(sess->priv); } static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess, struct wd_join_gather_sess_setup *setup) { - struct wd_alg_driver *drv = wd_join_gather_setting.driver; __u32 array_size; int ret; @@ -425,7 +424,7 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess, WD_ERR("failed to get session uninit ops!\n"); return -WD_EINVAL; } - ret = sess->ops.sess_init(drv, setup, &sess->priv); + ret = sess->ops.sess_init(setup, &sess->priv); if (ret) { WD_ERR("failed to init session priv!\n"); return ret; @@ -433,7 +432,7 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess, } if (sess->ops.get_table_row_size && setup->alg != WD_GATHER) { - ret = sess->ops.get_table_row_size(drv, sess->priv); + ret = sess->ops.get_table_row_size(sess->priv); if (ret <= 0) { WD_ERR("failed to get hash table row size: %d!\n", ret); goto uninit; @@ -447,7 +446,7 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess, if (!sess->gather_conf.batch_row_size) goto uninit; - ret = sess->ops.get_batch_row_size(drv, sess->priv, + ret = sess->ops.get_batch_row_size(sess->priv, sess->gather_conf.batch_row_size, array_size); if (ret) { @@ -462,7 +461,7 @@ free_batch: free(sess->gather_conf.batch_row_size); uninit: if (sess->ops.sess_uninit) - sess->ops.sess_uninit(drv, sess->priv); + sess->ops.sess_uninit(sess->priv); return -WD_EINVAL; } @@ -656,8 +655,7 @@ int wd_join_set_hash_table(handle_t h_sess, struct wd_dae_hash_table *info) WD_INFO("info: extern hash table is NULL!\n"); if (sess->ops.hash_table_init) { - ret = sess->ops.hash_table_init(wd_join_gather_setting.driver, - info, sess->priv); + ret = sess->ops.hash_table_init(info, sess->priv); if (ret) goto out; } @@ -699,7 +697,9 @@ static int wd_join_gather_alg_init(struct wd_ctx_config *config, struct wd_sched if (ret < 0) goto out_clear_sched; - ret = wd_alg_init_driver(&wd_join_gather_setting.config, wd_join_gather_setting.driver); + ret = wd_alg_init_driver(&wd_join_gather_setting.config, + wd_join_gather_setting.driver, + &wd_join_gather_setting.priv); if (ret) goto out_clear_pool; @@ -728,7 +728,9 @@ static int wd_join_gather_alg_uninit(void) /* Unset config, sched, driver */ wd_clear_sched(&wd_join_gather_setting.sched); - wd_alg_uninit_driver(&wd_join_gather_setting.config, wd_join_gather_setting.driver); + wd_alg_uninit_driver(&wd_join_gather_setting.config, + wd_join_gather_setting.driver, + &wd_join_gather_setting.priv); return WD_SUCCESS; } @@ -1215,7 +1217,7 @@ static int wd_join_gather_sync_job(struct wd_join_gather_sess *sess, msg_handle.recv = setting->driver->recv; pthread_spin_lock(&ctx->lock); - ret = wd_handle_msg_sync(setting->driver, &msg_handle, ctx->ctx, + ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL, config->epoll_en); pthread_spin_unlock(&ctx->lock); @@ -1311,7 +1313,7 @@ static int wd_join_gather_async_job(struct wd_join_gather_sess *sess, fill_join_gather_msg(msg, req, sess); msg->tag = msg_id; - ret = wd_alg_driver_send(setting->driver, ctx->ctx, msg); + ret = wd_join_gather_setting.driver->send(ctx->ctx, msg); if (ret < 0) { if (ret != -WD_EBUSY) WD_ERR("wd join gather async send err!\n"); @@ -1781,7 +1783,7 @@ static int wd_join_gather_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx; do { - ret = wd_alg_driver_recv(wd_join_gather_setting.driver, ctx->ctx, &resp_msg); + ret = wd_join_gather_setting.driver->recv(ctx->ctx, &resp_msg); if (ret == -WD_EAGAIN) { return ret; } else if (ret < 0) { diff --git a/wd_rsa.c b/wd_rsa.c index bc78c6a..3e4d70d 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -77,6 +77,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; @@ -184,7 +185,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; @@ -201,11 +203,10 @@ out_clear_ctx_config: static int wd_rsa_common_uninit(void) { - enum wd_status status; - - wd_alg_get_init(&wd_rsa_setting.status, &status); - if (status == WD_UNINIT) + 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); @@ -213,7 +214,8 @@ static int wd_rsa_common_uninit(void) /* 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 WD_SUCCESS; } @@ -451,8 +453,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; @@ -498,7 +500,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"); @@ -548,7 +550,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_udma.c b/wd_udma.c index eebe495..341b533 100644 --- a/wd_udma.c +++ b/wd_udma.c @@ -22,6 +22,7 @@ static struct wd_udma_setting { struct wd_sched sched; struct wd_async_msg_pool pool; struct wd_alg_driver *driver; + void *priv; void *dlhandle; void *dlh_list; } wd_udma_setting; @@ -229,7 +230,7 @@ int wd_do_udma_sync(handle_t h_sess, struct wd_udma_req *req) msg_handle.send = wd_udma_setting.driver->send; msg_handle.recv = wd_udma_setting.driver->recv; pthread_spin_lock(&ctx->lock); - ret = wd_handle_msg_sync(wd_udma_setting.driver, &msg_handle, ctx->ctx, + ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, NULL, wd_udma_setting.config.epoll_en); pthread_spin_unlock(&ctx->lock); if (unlikely(ret)) @@ -276,7 +277,7 @@ int wd_do_udma_async(handle_t sess, struct wd_udma_req *req) fill_udma_msg(msg, req); msg->tag = mid; - ret = wd_alg_driver_send(wd_udma_setting.driver, ctx->ctx, msg); + ret = wd_udma_setting.driver->send(ctx->ctx, msg); if (unlikely(ret)) { if (ret != -WD_EBUSY) WD_ERR("failed to send udma BD, hw is err!\n"); @@ -314,7 +315,7 @@ static int wd_udma_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx; do { - ret = wd_alg_driver_recv(wd_udma_setting.driver, ctx->ctx, &rcv_msg); + ret = wd_udma_setting.driver->recv(ctx->ctx, &rcv_msg); if (ret == -WD_EAGAIN) { return ret; } else if (unlikely(ret)) { @@ -364,7 +365,9 @@ static void wd_udma_alg_uninit(void) wd_uninit_async_request_pool(&wd_udma_setting.pool); /* Unset config, sched, driver */ wd_clear_sched(&wd_udma_setting.sched); - wd_alg_uninit_driver(&wd_udma_setting.config, wd_udma_setting.driver); + wd_alg_uninit_driver(&wd_udma_setting.config, + wd_udma_setting.driver, + &wd_udma_setting.priv); } void wd_udma_uninit(void) @@ -405,7 +408,9 @@ static int wd_udma_alg_init(struct wd_ctx_config *config, struct wd_sched *sched if (ret < 0) goto out_clear_sched; - ret = wd_alg_init_driver(&wd_udma_setting.config, wd_udma_setting.driver); + ret = wd_alg_init_driver(&wd_udma_setting.config, + wd_udma_setting.driver, + &wd_udma_setting.priv); if (ret) goto out_clear_pool; diff --git a/wd_util.c b/wd_util.c index bf82fc1..0dc9a67 100644 --- a/wd_util.c +++ b/wd_util.c @@ -1878,8 +1878,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; @@ -1888,7 +1888,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; @@ -1901,7 +1901,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(ret < 0)) { WD_ERR("failed to recv msg: error = %d!\n", ret); @@ -1964,10 +1964,21 @@ 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; + if (!driver->priv_size) { + WD_ERR("invalid: driver priv ctx size is zero!\n"); + return -WD_EINVAL; + } + + /* 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"); @@ -1975,11 +1986,12 @@ 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; } + driver->drv_data = priv; if (driver->fallback) { ret = wd_alg_init_fallback((struct wd_alg_driver *)driver->fallback); @@ -1988,22 +2000,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) { - driver->exit(driver); + void *priv = *drv_priv; + + driver->exit(priv); /* Ctx config just need clear once */ wd_clear_ctx_config(config); if (driver->fallback) wd_alg_uninit_fallback((struct wd_alg_driver *)driver->fallback); + + if (priv) { + free(priv); + driver->drv_data = NULL; + *drv_priv = NULL; + } } void wd_dlclose_drv(void *dlh_list) -- 2.43.0