[PATCH 01/19] Revert "drivers alloc and free resources by themself"
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
From: Longfang Liu <liulongfang@huawei.com> Unify the software ctx and hardware ctx in uadk and merge them on the scheduler. Realize the function of software and hardware calculation together Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- include/wd.h | 5 - include/wd_alg.h | 35 +- include/wd_alg_common.h | 41 ++- include/wd_internal.h | 23 +- include/wd_sched.h | 1 + include/wd_util.h | 16 +- wd_alg.c | 63 ++-- wd_util.c | 757 ++++++++++++++++++++++++++-------------- 8 files changed, 622 insertions(+), 319 deletions(-) diff --git a/include/wd.h b/include/wd.h index a468047..6329528 100644 --- a/include/wd.h +++ b/include/wd.h @@ -104,11 +104,6 @@ typedef void (*wd_log)(const char *format, ...); #define WD_IS_ERR(h) ((uintptr_t)(h) > \ (uintptr_t)(-1000)) -enum wd_buff_type { - WD_FLAT_BUF, - WD_SGL_BUF, -}; - enum wd_alg_type { WD_CIPHER, WD_DIGEST, diff --git a/include/wd_alg.h b/include/wd_alg.h index 885a5e3..05e022c 100644 --- a/include/wd_alg.h +++ b/include/wd_alg.h @@ -64,14 +64,23 @@ typedef unsigned char __u8; # define HWCAP2_RNG (1 << 16) #endif -enum alg_dev_type { - UADK_ALG_SOFT = 0x0, +enum alg_priority { + UADK_ALG_HW = 0x0, UADK_ALG_CE_INSTR = 0x1, UADK_ALG_SVE_INSTR = 0x2, - UADK_ALG_HW = 0x3 + UADK_ALG_SOFT = 0x3 }; -/* +enum alg_drv_type { + ALG_DRV_HW = 0x0, + ALG_DRV_CE_INS, + ALG_DRV_SVE_INS, + ALG_DRV_SOFT, + ALG_DRV_INS, + ALG_DRV_FB, +}; + +/** * @drv_name: name of the current device driver * @alg_name: name of the algorithm supported by the driver * @priority: priority of the type of algorithm supported by the driver @@ -110,6 +119,7 @@ struct wd_alg_driver { int priv_size; int *drv_data; handle_t fallback; + int init_state; int (*init)(void *conf, void *priv); void (*exit)(void *priv); @@ -134,7 +144,7 @@ struct hisi_dev_usage { int wd_alg_driver_register(struct wd_alg_driver *drv); void wd_alg_driver_unregister(struct wd_alg_driver *drv); -/* +/** * @alg_name: name of the algorithm supported by the driver * @drv_name: name of the current device driver * @available: Indicates whether the current driver still has resources available @@ -158,25 +168,24 @@ struct wd_alg_list { char alg_type[ALG_NAME_SIZE]; }; -/* +/** * wd_request_drv() - Apply for an algorithm driver. * @alg_name: task algorithm name. - * @hw_mask: the flag of shield hardware device drivers. + * @drv_type: the type of shield hardware device drivers. * * Returns the applied algorithm driver, non means error. */ -struct wd_alg_driver *wd_request_drv(const char *alg_name, bool hw_mask); +struct wd_alg_driver *wd_request_drv(const char *alg_name, int drv_type); void wd_release_drv(struct wd_alg_driver *drv); -/* +/** * wd_drv_alg_support() - Check the algorithms supported by the driver. * @alg_name: task algorithm name. - * @drv: a device driver that supports an algorithm. + * @param: a device queue parameters. * * Return check result. */ -bool wd_drv_alg_support(const char *alg_name, - struct wd_alg_driver *drv); +bool wd_drv_alg_support(const char *alg_name, void *param); /* * wd_enable_drv() - Re-enable use of the current device driver. @@ -191,7 +200,7 @@ int wd_get_alg_type(const char *alg_name, char *alg_type); struct wd_alg_list *wd_get_alg_head(void); #ifdef WD_STATIC_DRV -/* +/** * duplicate drivers will be skipped when it register to alg_list */ void hisi_sec2_probe(void); diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h index a294877..0e5523f 100644 --- a/include/wd_alg_common.h +++ b/include/wd_alg_common.h @@ -42,6 +42,13 @@ extern "C" { /* Key size of digest */ #define MAX_HMAC_KEY_SIZE 128U +/* + * The maximum number of queue types + * required for similar algorithms + */ +#define MAX_CTX_OP_TYPE 4U +#define STATUS_ENABLE (void *)0x1 + enum alg_task_type { TASK_MIX = 0x0, TASK_HW, @@ -55,6 +62,11 @@ enum wd_ctx_mode { CTX_MODE_MAX, }; +enum wd_buff_type { + WD_FLAT_BUF, + WD_SGL_BUF, +}; + enum wd_init_type { WD_TYPE_V1, WD_TYPE_V2, @@ -69,7 +81,8 @@ enum wd_mem_type { /* * struct wd_ctx - Define one ctx and related type. - * @ctx: The ctx itself. + * @ctx: The ctx itself, the hardware queue is wd_ctx_h. + * The soft computing queue is wd_soft_ctx. * @op_type: Define the operation type of this specific ctx. * e.g. 0: compression; 1: decompression. * @ctx_mode: Define this ctx is used for synchronization of asynchronization @@ -79,9 +92,10 @@ struct wd_ctx { handle_t ctx; __u8 op_type; __u8 ctx_mode; + __u8 ctx_type; }; -/* +/** * struct wd_cap_config - Capabilities. * @ctx_msg_num: number of asynchronous msg pools that the user wants to allocate. * Optional, user can set ctx_msg_num based on the number of requests @@ -94,7 +108,7 @@ struct wd_cap_config { __u32 resv; }; -/* +/** * struct wd_ctx_config - Define a ctx set and its related attributes, which * will be used in the scope of current process. * @ctx_num: The ctx number in below ctx array. @@ -110,19 +124,34 @@ struct wd_ctx_config { struct wd_cap_config *cap; }; -/* +/* 0x0 mean calloc init value */ +enum wd_ctx_property { + UADK_CTX_HW = 0x0, + UADK_CTX_CE_INS = 0x1, + UADK_CTX_SVE_INS = 0x2, + UADK_CTX_SOFT = 0x3, + UADK_CTX_MAX +}; + +/** * struct wd_ctx_nums - Define the ctx sets numbers. * @sync_ctx_num: The ctx numbers which are used for sync mode for each * ctx sets. * @async_ctx_num: The ctx numbers which are used for async mode for each * ctx sets. + * @ctx_prop: Indicates the properties of the current queue + * @ctx_begin: The encoding starting position of the current device ctx + * @other_ctx: Other types of queues configured */ struct wd_ctx_nums { __u32 sync_ctx_num; __u32 async_ctx_num; + __u8 ctx_prop; + __u16 ctx_begin; + struct wd_ctx_nums *other_ctx; }; -/* +/** * struct wd_ctx_params - Define the ctx sets params which are used for init * algorithms. * @op_type_num: Used for index of ctx_set_num, the order is the same as @@ -140,7 +169,7 @@ struct wd_ctx_params { }; /* - * struct wd_comp_sched - Define a scheduler. + * struct wd_sched - Define a scheduler. * @name: Name of this scheduler. * @sched_policy: Method for scheduler to perform scheduling * @sched_init: inited the scheduler input parameters. diff --git a/include/wd_internal.h b/include/wd_internal.h index d899555..59046ae 100644 --- a/include/wd_internal.h +++ b/include/wd_internal.h @@ -17,6 +17,7 @@ extern "C" { #define DEVICE_REGION_MAX 16 #define DECIMAL_NUMBER 10 #define MAX_FD_NUM 65535 +#define MAX_SOFT_QUEUE_LENGTH 1024U struct wd_ctx_h { int fd; @@ -29,8 +30,24 @@ struct wd_ctx_h { void *priv; }; +struct wd_soft_sqe { + __u8 used; + __u8 result; + __u8 complete; + __u32 id; +}; + +/** + * default queue length set to 1024 + */ struct wd_soft_ctx { int fd; + pthread_spinlock_t slock; + __u32 head; + struct wd_soft_sqe qfifo[MAX_SOFT_QUEUE_LENGTH]; + pthread_spinlock_t rlock; + __u32 tail; + __u32 run_num; void *priv; }; @@ -41,11 +58,15 @@ struct wd_ce_ctx { }; struct wd_ctx_internal { - handle_t ctx; __u8 op_type; __u8 ctx_mode; + __u8 ctx_type; + __u8 ctx_used; + handle_t ctx; // if ctx is first will cause problem __u16 sqn; pthread_spinlock_t lock; + struct wd_alg_driver *drv; + void *drv_priv; }; struct wd_ctx_config_internal { diff --git a/include/wd_sched.h b/include/wd_sched.h index 5baecd3..71949f9 100644 --- a/include/wd_sched.h +++ b/include/wd_sched.h @@ -35,6 +35,7 @@ struct sched_params { __u32 begin; __u32 end; __u32 dev_id; + int ctx_prop; }; typedef int (*user_poll_func)(__u32 pos, __u32 expect, __u32 *count); diff --git a/include/wd_util.h b/include/wd_util.h index 14985e2..3be75d3 100644 --- a/include/wd_util.h +++ b/include/wd_util.h @@ -126,13 +126,14 @@ struct wd_msg_handle { struct wd_init_attrs { __u32 sched_type; + __u32 task_type; char alg[CRYPTO_MAX_ALG_NAME]; - struct wd_alg_driver *driver; struct wd_sched *sched; struct wd_ctx_params *ctx_params; struct wd_ctx_config *ctx_config; wd_alg_init alg_init; wd_alg_poll_ctx alg_poll_ctx; + struct wd_alg_driver *driver; //stub for old code }; /* @@ -173,6 +174,9 @@ void wd_clear_ctx_config(struct wd_ctx_config_internal *in); */ void wd_memset_zero(void *data, __u32 size); +int wd_ctx_drv_config(char *alg_name, struct wd_ctx_config_internal *ctx_config); +void wd_ctx_drv_deconfig(struct wd_ctx_config_internal *ctx_config); + /* * wd_init_async_request_pool() - Init async message pools. * @pool: Pointer of message pool. @@ -452,6 +456,10 @@ static inline void wd_alg_clear_init(enum wd_status *status) * * Return 0 if succeed and other error number if fail. */ +int wd_ctx_param_init_nw(struct wd_ctx_params *ctx_params, + struct wd_ctx_params *user_ctx_params, + char *alg, int task_type, enum wd_type type, + int max_op_type); int wd_ctx_param_init(struct wd_ctx_params *ctx_params, struct wd_ctx_params *user_ctx_params, struct wd_alg_driver *driver, @@ -472,12 +480,12 @@ void wd_alg_attrs_uninit(struct wd_init_attrs *attrs); /** * wd_alg_drv_bind() - Request the ctxs and initialize the sched_domain * with the given devices list, ctxs number and numa mask. - * @task_type: the type of task specified by the current algorithm. + * @ctx_type: the type of ctx specified by the current algorithm. * @alg_name: the name of the algorithm specified by the task. * * Return device driver if succeed and other NULL if fail. */ -struct wd_alg_driver *wd_alg_drv_bind(int task_type, const char *alg_name); +struct wd_alg_driver *wd_alg_drv_bind(__u8 ctx_prop, char *alg_name); void wd_alg_drv_unbind(struct wd_alg_driver *drv); /** @@ -489,6 +497,8 @@ void wd_alg_drv_unbind(struct wd_alg_driver *drv); * * Return 0 if succeed and other error number if fail. */ +int wd_alg_init_driver_nw(struct wd_ctx_config_internal *config); +void wd_alg_uninit_driver_nw(struct wd_ctx_config_internal *config); int wd_alg_init_driver(struct wd_ctx_config_internal *config, struct wd_alg_driver *driver, void **drv_priv); void wd_alg_uninit_driver(struct wd_ctx_config_internal *config, diff --git a/wd_alg.c b/wd_alg.c index a1a0a79..582a4a7 100644 --- a/wd_alg.c +++ b/wd_alg.c @@ -12,7 +12,7 @@ #include <sys/auxv.h> #include "wd.h" -#include "wd_alg.h" +#include "wd_alg_common.h" #define SYS_CLASS_DIR "/sys/class/uacce" #define SVA_FILE_NAME "flags" @@ -337,21 +337,26 @@ struct wd_alg_list *wd_get_alg_head(void) return &alg_list_head; } -bool wd_drv_alg_support(const char *alg_name, - struct wd_alg_driver *drv) +bool wd_drv_alg_support(const char *alg_name, void *param) { + struct wd_ctx_config_internal *config = param; struct wd_alg_list *head = &alg_list_head; struct wd_alg_list *pnext = head->next; + struct wd_alg_driver *drv; + __u32 i; - if (!alg_name || !drv) + if (!alg_name || !config) return false; - while (pnext) { - if (!strcmp(alg_name, pnext->alg_name) && - !strcmp(drv->drv_name, pnext->drv_name)) { - return true; + for (i = 0; i < config->ctx_num; i++) { + drv = config->ctxs[i].drv; + while (pnext) { + if (!strcmp(alg_name, pnext->alg_name) && + !strcmp(drv->drv_name, pnext->drv_name)) { + return true; + } + pnext = pnext->next; } - pnext = pnext->next; } return false; @@ -398,7 +403,7 @@ void wd_disable_drv(struct wd_alg_driver *drv) pthread_mutex_unlock(&mutex); } -struct wd_alg_driver *wd_request_drv(const char *alg_name, bool hw_mask) +struct wd_alg_driver *wd_request_drv(const char *alg_name, int drv_type) { struct wd_alg_list *head = &alg_list_head; struct wd_alg_list *pnext = head->next; @@ -419,18 +424,32 @@ struct wd_alg_driver *wd_request_drv(const char *alg_name, bool hw_mask) /* Check the list to get an best driver */ pthread_mutex_lock(&mutex); while (pnext) { - /* hw_mask true mean not to used hardware dev */ - if ((hw_mask && pnext->drv->calc_type == UADK_ALG_HW) || - (!hw_mask && pnext->drv->calc_type != UADK_ALG_HW)) { - pnext = pnext->next; - continue; - } - - if (!strcmp(alg_name, pnext->alg_name) && pnext->available && - pnext->drv->priority > tmp_priority) { - tmp_priority = pnext->drv->priority; - select_node = pnext; - drv = pnext->drv; + if (!strcmp(alg_name, pnext->alg_name) && pnext->available) { + /* HW driver mean to used hardware dev */ + if (drv_type == ALG_DRV_HW && pnext->drv->calc_type == UADK_ALG_HW) + select_node = pnext; + /* CE driver mean to used CE dev */ + else if (drv_type == ALG_DRV_CE_INS && pnext->drv->calc_type == UADK_ALG_CE_INSTR) + select_node = pnext; + /* SVE driver mean to used SVE dev */ + else if (drv_type == ALG_DRV_SVE_INS && pnext->drv->calc_type == UADK_ALG_SVE_INSTR) + select_node = pnext; + /* INS driver mean to used CE and SVE dev */ + else if (drv_type == ALG_DRV_INS && (pnext->drv->calc_type == UADK_ALG_CE_INSTR || + pnext->drv->calc_type == UADK_ALG_SVE_INSTR)) + select_node = pnext; + /* Soft driver mean to used Soft, CE and SVE dev */ + else if (drv_type == ALG_DRV_SOFT && pnext->drv->calc_type != UADK_ALG_HW) + select_node = pnext; + /* Fallback driver mean to used Soft or CE dev */ + else if (drv_type == ALG_DRV_FB && (pnext->drv->calc_type == UADK_ALG_SOFT || + pnext->drv->calc_type == UADK_ALG_CE_INSTR)) + select_node = pnext; + + if (select_node && select_node->drv->priority > tmp_priority) { + drv = select_node->drv; + tmp_priority = select_node->drv->priority; + } } pnext = pnext->next; } diff --git a/wd_util.c b/wd_util.c index 0dc9a67..a23152c 100644 --- a/wd_util.c +++ b/wd_util.c @@ -216,6 +216,7 @@ static void clone_ctx_to_internal(struct wd_ctx *ctx, ctx_in->ctx = ctx->ctx; ctx_in->op_type = ctx->op_type; ctx_in->ctx_mode = ctx->ctx_mode; + ctx_in->ctx_type = ctx->ctx_type; } static int wd_shm_create(struct wd_ctx_config_internal *in) @@ -285,9 +286,8 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in, for (i = 0; i < cfg->ctx_num; i++) { if (!cfg->ctxs[i].ctx) { - WD_ERR("invalid: ctx is NULL!\n"); - ret = -WD_EINVAL; - goto err_out; + WD_ERR("invalid: ctx<%u> is NULL!\n", i); + break; } clone_ctx_to_internal(cfg->ctxs + i, ctxs + i); ret = pthread_spin_init(&ctxs[i].lock, PTHREAD_PROCESS_SHARED); @@ -1847,7 +1847,7 @@ int wd_check_ctx(struct wd_ctx_config_internal *config, __u8 mode, __u32 idx) } ctx = config->ctxs + idx; - if (ctx->ctx_mode != mode) { + if (ctx->ctx_type == UADK_CTX_HW && ctx->ctx_mode != mode) { WD_ERR("invalid: ctx(%u) mode is %hhu!\n", idx, ctx->ctx_mode); return -WD_EINVAL; } @@ -1929,18 +1929,50 @@ int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx, int wd_init_param_check(struct wd_ctx_config *config, struct wd_sched *sched) { if (!config || !config->ctxs || !config->ctxs[0].ctx) { - WD_ERR("invalid: config or config->ctxs is NULL!\n"); + WD_ERR("invalid: wd_ctx_config is NULL!\n"); return -WD_EINVAL; } if (!sched) { - WD_ERR("invalid: sched is NULL!\n"); + WD_ERR("invalid: wd_sched is NULL!\n"); return -WD_EINVAL; } return 0; } +int wd_alg_try_init(enum wd_status *status) +{ + enum wd_status expected; + __u32 count = 0; + bool ret; + + /* + * Here is aimed to protect the security of the initialization interface + * in the multi-thread scenario. Only one thread can get the WD_INITING + * status to initialize algorithm. Other thread will wait for the result. + * And the algorithm initialization interfaces is a liner process. + * So the initing thread will return a result to notify other thread go on. + */ + do { + expected = WD_UNINIT; + ret = __atomic_compare_exchange_n(status, &expected, WD_INITING, true, + __ATOMIC_RELAXED, __ATOMIC_RELAXED); + if (expected == WD_INIT) { + WD_ERR("The algorithm has been initialized!\n"); + return -WD_EEXIST; + } + usleep(WD_INIT_SLEEP_UTIME); + + if (US2S(WD_INIT_SLEEP_UTIME * ++count) >= WD_INIT_RETRY_TIMEOUT) { + WD_ERR("The algorithm initialize wait timeout!\n"); + return -WD_ETIMEDOUT; + } + } while (!ret); + + return 0; +} + static int wd_alg_init_fallback(struct wd_alg_driver *fb_driver) { if (!fb_driver->init) { @@ -1948,6 +1980,7 @@ static int wd_alg_init_fallback(struct wd_alg_driver *fb_driver) return -WD_EINVAL; } + WD_ERR("debug: call function: %s!\n", __func__); fb_driver->init(NULL, NULL); return 0; @@ -1963,12 +1996,20 @@ static void wd_alg_uninit_fallback(struct wd_alg_driver *fb_driver) fb_driver->exit(NULL); } -int wd_alg_init_driver(struct wd_ctx_config_internal *config, - struct wd_alg_driver *driver, void **drv_priv) +static int wd_ctx_init_driver(struct wd_ctx_config_internal *config, + struct wd_ctx_internal *ctx_config) { - void *priv; + struct wd_alg_driver *driver = ctx_config->drv; + void *priv = ctx_config->drv_priv; int ret; + if (!driver) + return 0; + + /* Prevent repeated initialization */ + if (driver->init_state) + return 0; + if (!driver->priv_size) { WD_ERR("invalid: driver priv ctx size is zero!\n"); return -WD_EINVAL; @@ -1985,6 +2026,7 @@ int wd_alg_init_driver(struct wd_ctx_config_internal *config, ret = -WD_EINVAL; goto err_alloc; } + driver->init_state = 1; ret = driver->init(config, priv); if (ret < 0) { @@ -2000,21 +2042,30 @@ 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); + ctx_config->drv_priv = NULL; return ret; } -void wd_alg_uninit_driver(struct wd_ctx_config_internal *config, - struct wd_alg_driver *driver, void **drv_priv) +static void wd_ctx_uninit_driver(struct wd_ctx_config_internal *config, + struct wd_ctx_internal *ctx_config) { - void *priv = *drv_priv; + struct wd_alg_driver *driver = ctx_config->drv; + void *priv = ctx_config->drv_priv; + + if (!driver) + return; + + /* Prevent repeated uninitialization */ + if (!driver->init_state) + return; driver->exit(priv); + driver->init_state = 0; /* Ctx config just need clear once */ wd_clear_ctx_config(config); @@ -2024,10 +2075,53 @@ void wd_alg_uninit_driver(struct wd_ctx_config_internal *config, if (priv) { free(priv); driver->drv_data = NULL; - *drv_priv = NULL; + ctx_config->drv_priv = NULL; } } +int wd_alg_init_driver(struct wd_ctx_config_internal *config, + struct wd_alg_driver *driver, void **drv_priv) +{ + return 0; +} + +int wd_alg_init_driver_nw(struct wd_ctx_config_internal *config) +{ + __u32 i, j; + int ret; + + WD_ERR("debug: call function: %s!\n", __func__); + for (i = 0; i < config->ctx_num; i++) { + if (!config->ctxs[i].ctx) + continue; + ret = wd_ctx_init_driver(config, &config->ctxs[i]); + if (ret) + goto init_err; + } + + return 0; + +init_err: + for (j = 0; j < i; j++) + wd_ctx_uninit_driver(config, &config->ctxs[j]); + + return ret; +} + +void wd_alg_uninit_driver(struct wd_ctx_config_internal *config, + struct wd_alg_driver *driver, void **drv_priv) +{ +} + +void wd_alg_uninit_driver_nw(struct wd_ctx_config_internal *config) +{ + __u32 i; + + for (i = 0; i < config->ctx_num; i++) + wd_ctx_uninit_driver(config, &config->ctxs[i]); + +} + void wd_dlclose_drv(void *dlh_list) { struct drv_lib_list *dlhead = (struct drv_lib_list *)dlh_list; @@ -2178,6 +2272,61 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, numa_free_nodemask(ctx_params->bmp); return ret; } + } else { + /* environment variable is not set, try to use user_ctx_params first */ + if (user_ctx_params) { + copy_bitmask_to_bitmask(user_ctx_params->bmp, ctx_params->bmp); + if (user_ctx_params->op_type_num > (__u32)max_op_type) { + WD_ERR("fail to check user op type numbers.\n"); + numa_free_nodemask(ctx_params->bmp); + return -WD_EINVAL; + } + ctx_params->cap = user_ctx_params->cap; + ctx_params->ctx_set_num = user_ctx_params->ctx_set_num; + ctx_params->op_type_num = user_ctx_params->op_type_num; + + return 0; + } + } + + /* user_ctx_params is also not set, use defalut queue_num max_op_type */ + numa_bitmask_setall(ctx_params->bmp); + for (i = 0; i < max_op_type; i++) { + ctx_params->ctx_set_num[i].sync_ctx_num = max_op_type; + ctx_params->ctx_set_num[i].async_ctx_num = max_op_type; + } + + ctx_params->op_type_num = max_op_type; + + return 0; +} + +int wd_ctx_param_init_nw(struct wd_ctx_params *ctx_params, + struct wd_ctx_params *user_ctx_params, + char *alg, int task_type, enum wd_type type, + int max_op_type) +{ + const char *env_name = wd_env_name[type]; + const char *var_s; + int i, ret; + + ctx_params->bmp = numa_allocate_nodemask(); + if (!ctx_params->bmp) { + WD_ERR("fail to allocate nodemask.\n"); + return -WD_ENOMEM; + } + + /* Only hw driver support environment variable */ + var_s = secure_getenv(env_name); + if (var_s && strlen(var_s) && task_type <= TASK_HW) { + /* environment variable has the highest priority */ + ret = wd_env_set_ctx_nums(alg, env_name, var_s, + ctx_params, max_op_type); + if (ret) { + WD_ERR("fail to init ctx nums from %s!\n", env_name); + numa_free_nodemask(ctx_params->bmp); + return ret; + } } else { /* environment variable is not set, try to use user_ctx_params first */ if (user_ctx_params) { @@ -2540,48 +2689,57 @@ free_path: return (void *)head; } -struct wd_alg_driver *wd_alg_drv_bind(int task_type, const char *alg_name) +struct wd_alg_driver *wd_alg_drv_bind(__u8 ctx_prop, char *alg_name) { - struct wd_alg_driver *set_driver = NULL; + struct wd_alg_driver *fb_drv; struct wd_alg_driver *drv; - /* Get alg driver and dev name */ - switch (task_type) { - case TASK_INSTR: - drv = wd_request_drv(alg_name, true); + /* Get alg driver from ctx type and alg name */ + switch (ctx_prop) { + case UADK_CTX_HW: + drv = wd_request_drv(alg_name, ALG_DRV_HW); if (!drv) { - WD_ERR("no soft %s driver support\n", alg_name); + WD_ERR("no HW %s driver support\n", alg_name); return NULL; } - set_driver = drv; - set_driver->fallback = 0; + + fb_drv = wd_request_drv(alg_name, ALG_DRV_SOFT); + if (!fb_drv) + drv->fallback = 0; + else + drv->fallback = (handle_t)fb_drv; + break; - case TASK_HW: - case TASK_MIX: - drv = wd_request_drv(alg_name, false); + case UADK_CTX_CE_INS: + drv = wd_request_drv(alg_name, ALG_DRV_CE_INS); if (!drv) { - WD_ERR("no HW %s driver support\n", alg_name); + WD_ERR("no CE instr soft %s driver support\n", alg_name); return NULL; } - set_driver = drv; - set_driver->fallback = 0; - if (task_type == TASK_MIX) { - drv = wd_request_drv(alg_name, true); - if (!drv) { - set_driver->fallback = 0; - WD_ERR("no soft %s driver support\n", alg_name); - } else { - set_driver->fallback = (handle_t)drv; - WD_ERR("successful to get soft driver\n"); - } + drv->fallback = 0; + break; + case UADK_CTX_SVE_INS: + drv = wd_request_drv(alg_name, ALG_DRV_SVE_INS); + if (!drv) { + WD_ERR("no SVE instr soft %s driver support\n", alg_name); + return NULL; } + drv->fallback = 0; + break; + case UADK_CTX_SOFT: + drv = wd_request_drv(alg_name, ALG_DRV_SOFT); + if (!drv) { + WD_ERR("no instr soft %s driver support\n", alg_name); + return NULL; + } + drv->fallback = 0; break; default: - WD_ERR("task type error.\n"); - return NULL; + WD_ERR("ctx type error: %d.\n", ctx_prop); + return WD_ERR_PTR(-WD_ENODEV); } - return set_driver; + return drv; } void wd_alg_drv_unbind(struct wd_alg_driver *drv) @@ -2597,45 +2755,100 @@ void wd_alg_drv_unbind(struct wd_alg_driver *drv) wd_release_drv(drv); } -int wd_alg_try_init(enum wd_status *status) +static __u32 wd_ctxs_idx_init(struct wd_init_attrs *attrs, int numa_cnt, int task_type) { - enum wd_status expected; + struct wd_ctx_params *ctx_params = attrs->ctx_params; + int end = ctx_params->op_type_num; + struct wd_ctx_nums *ptr_ctx; __u32 count = 0; - bool ret; + int i, uidx; - do { - expected = WD_UNINIT; - ret = __atomic_compare_exchange_n(status, &expected, WD_INITING, true, - __ATOMIC_RELAXED, __ATOMIC_RELAXED); - if (expected == WD_INIT) { - WD_ERR("The algorithm has been initialized!\n"); - return -WD_EEXIST; - } - usleep(WD_INIT_SLEEP_UTIME); + if (ctx_params->op_type_num > MAX_CTX_OP_TYPE) { + WD_ERR("invalid: max ctx op type<%u> is wrong!\n", ctx_params->op_type_num); + return 0; + } - if (US2S(WD_INIT_SLEEP_UTIME * ++count) >= WD_INIT_RETRY_TIMEOUT) { - WD_ERR("The algorithm initialize wait timeout!\n"); - return -WD_ETIMEDOUT; + for (uidx = 0; uidx < UADK_CTX_MAX; uidx++) { + /* If it is a soft computing task, do not use HW queue */ + if (task_type == TASK_INSTR && uidx == UADK_CTX_HW) + continue; + for (i = 0; i < end; i++) { + ptr_ctx = &ctx_params->ctx_set_num[i]; + while (ptr_ctx) { + if (ptr_ctx->ctx_prop == uidx) { + ptr_ctx->ctx_begin = count; + if (uidx == UADK_CTX_HW) { + count += ptr_ctx->sync_ctx_num * numa_cnt; + count += ptr_ctx->async_ctx_num * numa_cnt; + } else { + count += ptr_ctx->sync_ctx_num; + count += ptr_ctx->async_ctx_num; + } + WD_ERR("optype<%d>, prop<%u>, begin<%u>, synx<%u>, async<%u>\n", + i, ptr_ctx->ctx_prop, ptr_ctx->ctx_begin, ptr_ctx->sync_ctx_num, ptr_ctx->async_ctx_num); + } + ptr_ctx = ptr_ctx->other_ctx; + } } - } while (!ret); + } - return 0; + return count; } -static __u32 wd_get_ctx_numbers(struct wd_ctx_params ctx_params, int end) +static struct wd_ctx_nums *wd_get_ctx_ptr(struct wd_ctx_params *ctx_params, + __u32 op_type, int ctx_prop) { - __u32 count = 0; - int i; + struct wd_ctx_nums *ptr_ctx; + + if (op_type > ctx_params->op_type_num) + return NULL; - for (i = 0; i < end; i++) { - count += ctx_params.ctx_set_num[i].sync_ctx_num; - count += ctx_params.ctx_set_num[i].async_ctx_num; + ptr_ctx = &ctx_params->ctx_set_num[op_type]; + while (ptr_ctx) { + if (ptr_ctx->ctx_prop == ctx_prop) + return ptr_ctx; + ptr_ctx = ptr_ctx->other_ctx; } - return count; + return NULL; +} + +void wd_ctx_drv_deconfig(struct wd_ctx_config_internal *ctx_config) +{ + __u32 i; + + // wd_dlclose_drv after this + for (i = 0; i < ctx_config->ctx_num; i++) + wd_alg_drv_unbind(ctx_config->ctxs[i].drv); + +} + +int wd_ctx_drv_config(char *alg_name, struct wd_ctx_config_internal *ctx_config) +{ + __u32 i, j; + + // wd_dlopen_drv before this + WD_ERR("debug: call function: %s!\n", __func__); + for (i = 0; i < ctx_config->ctx_num; i++) { + ctx_config->ctxs[i].drv = wd_alg_drv_bind(ctx_config->ctxs[i].ctx_type, alg_name); + if (WD_IS_ERR(ctx_config->ctxs[i].drv)) { + continue; + } else if (!ctx_config->ctxs[i].drv) { + WD_ERR("failed to bind %s driver.\n", alg_name); + goto bind_err; + } + } + + return 0; + +bind_err: + for (j = 0; j < i; j++) { + wd_alg_drv_unbind(ctx_config->ctxs[j].drv); + } + return -WD_EINVAL; } -static struct uacce_dev_list *wd_get_usable_list(struct uacce_dev_list *list, struct bitmask *bmp) +struct uacce_dev_list *wd_get_usable_list(struct uacce_dev_list *list, struct bitmask *bmp) { struct uacce_dev_list *p, *node, *result = NULL; struct uacce_dev *dev; @@ -2685,7 +2898,7 @@ out_free_list: return result; } -static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *list, +static int wd_init_hw_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *list, __u32 idx, int numa_id, __u32 op_type) { struct wd_ctx_nums ctx_nums = attrs->ctx_params->ctx_set_num[op_type]; @@ -2729,6 +2942,7 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l ctx_config->ctxs[i].ctx_mode = ((i - idx) < ctx_nums.sync_ctx_num) ? CTX_MODE_SYNC : CTX_MODE_ASYNC; + ctx_config->ctxs[i].ctx_type = UADK_CTX_HW; } return 0; @@ -2762,6 +2976,7 @@ static int wd_instance_sched_set(struct wd_init_attrs *attrs, struct wd_ctx_nums sparams.dev_id = dev_id; sparams.mode = i; sparams.begin = idx + ctx_nums.sync_ctx_num * i; + sparams.ctx_prop = UADK_CTX_HW; end = idx - 1 + ctx_nums.sync_ctx_num + ctx_nums.async_ctx_num * i; if (end < 0 || sparams.begin > (__u32)end) continue; @@ -2776,7 +2991,7 @@ out: return ret; } -static int wd_init_ctx_and_sched(struct wd_init_attrs *attrs, struct bitmask *bmp, +static int wd_hw_ctx_and_sched(struct wd_init_attrs *attrs, struct bitmask *bmp, struct uacce_dev_list *list) { struct wd_ctx_params *ctx_params = attrs->ctx_params; @@ -2790,7 +3005,7 @@ static int wd_init_ctx_and_sched(struct wd_init_attrs *attrs, struct bitmask *bm continue; for (j = 0; j < op_type_num; j++) { ctx_nums = ctx_params->ctx_set_num[j]; - ret = wd_init_ctx_set(attrs, list, idx, i, j); + ret = wd_init_hw_ctx_set(attrs, list, idx, i, j); if (ret == -WD_ENOPROC) continue; else if (ret) @@ -2821,30 +3036,118 @@ static void wd_init_device_nodemask(struct uacce_dev_list *list, struct bitmask } } -static int wd_alg_ctx_init(struct wd_init_attrs *attrs) +static int wd_alg_other_ctx_init(struct wd_init_attrs *attrs, int ctx_prop) +{ + struct wd_ctx_config *ctx_config = attrs->ctx_config; + struct wd_ctx_params *ctx_params = attrs->ctx_params; + struct wd_ctx_nums *ptr_ctxs; + struct wd_soft_ctx *sfctx; + struct sched_params sparams; + __u32 begin, end, ctx_num; + int sync_type, ret; + __u32 i, j, k; + + WD_ERR("debug: call function: %s!\n", __func__); + for (i = 0; i < ctx_params->op_type_num; i++) { + ptr_ctxs = wd_get_ctx_ptr(ctx_params, i, ctx_prop); + if (!ptr_ctxs) + continue; + + for (sync_type = CTX_MODE_SYNC; sync_type < CTX_MODE_MAX; sync_type++) { + if (sync_type == CTX_MODE_SYNC) { + ctx_num = ptr_ctxs->sync_ctx_num; + begin = ptr_ctxs->ctx_begin; + } else { + ctx_num = ptr_ctxs->async_ctx_num; + begin = ptr_ctxs->ctx_begin + ptr_ctxs->sync_ctx_num; + } + if (ctx_num == 0) + continue; + + end = begin + ctx_num; + for (j = begin; j < end; j++) { + ctx_config->ctxs[j].op_type = i; + ctx_config->ctxs[j].ctx_mode = sync_type; + ctx_config->ctxs[j].ctx_type = ctx_prop; + sfctx = calloc(1, sizeof(struct wd_soft_ctx)); + if (!sfctx) { + WD_ERR("failed to alloc ctx!\n"); + goto ctx_err; + } + ctx_config->ctxs[j].ctx = (handle_t)sfctx; + pthread_spin_init(&sfctx->slock, PTHREAD_PROCESS_SHARED); + pthread_spin_init(&sfctx->rlock, PTHREAD_PROCESS_SHARED); + } + + memset(&sparams, 0x0, sizeof(struct sched_params)); + sparams.begin = begin; + sparams.end = end - 1; + sparams.mode = sync_type; + sparams.numa_id = 0; + sparams.ctx_prop = ctx_prop; + ret = wd_sched_rr_instance(attrs->sched, &sparams); + if (ret) { + WD_ERR("fail to instance scheduler.\n"); + goto ctx_err; + } + } + } + + return WD_SUCCESS; + +ctx_err: + for (k = j; k >= begin; k--) { + free((struct wd_soft_ctx *)ctx_config->ctxs[k].ctx); + ctx_config->ctxs[k].ctx = 0; + } + + return -WD_ENOMEM; +} + +static int wd_alg_other_init(struct wd_init_attrs *attrs) +{ + struct wd_ctx_config *ctx_config = attrs->ctx_config; + struct wd_ctx_params *ctx_params = attrs->ctx_params; + __u32 ctx_set_num, op_type_num; + + WD_ERR("debug: call function: %s!\n", __func__); + op_type_num = ctx_params->op_type_num; + ctx_set_num = wd_ctxs_idx_init(attrs, 1, attrs->task_type); + if (!ctx_set_num || !op_type_num) { + WD_ERR("invalid: ctx_set_num is %u, op_type_num is %u!\n", + ctx_set_num, op_type_num); + return -WD_EINVAL; + } + + ctx_config->ctx_num = ctx_set_num; + ctx_config->ctxs = calloc(ctx_config->ctx_num, sizeof(struct wd_ctx)); + if (!ctx_config->ctxs) { + WD_ERR("failed to alloc ctxs!\n"); + return -WD_ENOMEM; + } + + return 0; +} + +static int wd_alg_hw_ctx_init(struct wd_init_attrs *attrs) { struct wd_ctx_config *ctx_config = attrs->ctx_config; struct wd_ctx_params *ctx_params = attrs->ctx_params; struct bitmask *used_bmp = ctx_params->bmp; struct uacce_dev_list *list, *used_list = NULL; + char alg_type[CRYPTO_MAX_ALG_NAME]; __u32 ctx_set_num, op_type_num; int numa_cnt, ret; - list = wd_get_accel_list(attrs->alg); + WD_ERR("debug: call function: %s!\n", __func__); + wd_get_alg_type(attrs->alg, alg_type); + + list = wd_get_accel_list(alg_type); if (!list) { WD_ERR("failed to get devices for alg: %s\n", attrs->alg); return -WD_ENODEV; } - op_type_num = ctx_params->op_type_num; - ctx_set_num = wd_get_ctx_numbers(*ctx_params, op_type_num); - if (!ctx_set_num || !op_type_num) { - WD_ERR("invalid: ctx_set_num is %u, op_type_num is %u!\n", - ctx_set_num, op_type_num); - ret = -WD_EINVAL; - goto out_freelist; - } - /* * Not every numa has a device. Therefore, the first thing is to * filter the devices in the selected numa node, and the second @@ -2858,7 +3161,6 @@ static int wd_alg_ctx_init(struct wd_init_attrs *attrs) } wd_init_device_nodemask(used_list, used_bmp); - numa_cnt = numa_bitmask_weight(used_bmp); if (!numa_cnt) { ret = numa_cnt; @@ -2866,7 +3168,17 @@ static int wd_alg_ctx_init(struct wd_init_attrs *attrs) goto out_freeusedlist; } - ctx_config->ctx_num = ctx_set_num * numa_cnt; + op_type_num = ctx_params->op_type_num; + ctx_set_num = wd_ctxs_idx_init(attrs, numa_cnt, attrs->task_type); + WD_ERR("ctx sum num is: %u, op_type num is: %u!\n", ctx_set_num, op_type_num); + if (!ctx_set_num || !op_type_num) { + WD_ERR("invalid: ctx_set_num is %u, op_type_num is %u!\n", + ctx_set_num, op_type_num); + ret = -WD_EINVAL; + goto out_freelist; + } + + ctx_config->ctx_num = ctx_set_num; ctx_config->ctxs = calloc(ctx_config->ctx_num, sizeof(struct wd_ctx)); if (!ctx_config->ctxs) { ret = -WD_ENOMEM; @@ -2874,7 +3186,7 @@ static int wd_alg_ctx_init(struct wd_init_attrs *attrs) goto out_freeusedlist; } - ret = wd_init_ctx_and_sched(attrs, used_bmp, used_list); + ret = wd_hw_ctx_and_sched(attrs, used_bmp, used_list); if (ret) free(ctx_config->ctxs); @@ -2886,224 +3198,145 @@ out_freelist: return ret; } -static int wd_alg_ce_ctx_init(struct wd_init_attrs *attrs) -{ - struct wd_ctx_config *ctx_config = attrs->ctx_config; - struct wd_ce_ctx *ctx; - - ctx_config->ctx_num = 1; - ctx_config->ctxs = calloc(ctx_config->ctx_num, sizeof(struct wd_ctx)); - if (!ctx_config->ctxs) { - WD_ERR("failed to alloc ctxs!\n"); - return -WD_ENOMEM; - } - - ctx = calloc(1, sizeof(struct wd_ce_ctx)); - if (!ctx) { - free(ctx_config->ctxs); - return -WD_ENOMEM; - } - ctx->fd = -1; - ctx_config->ctxs[0].ctx = (handle_t)ctx; - - return WD_SUCCESS; -} - -static void wd_alg_ce_ctx_uninit(struct wd_ctx_config *ctx_config) +static void wd_alg_ctxs_uninit(struct wd_ctx_config *ctx_config) { __u32 i; for (i = 0; i < ctx_config->ctx_num; i++) { if (ctx_config->ctxs[i].ctx) { - free((struct wd_ce_ctx *)ctx_config->ctxs[i].ctx); + if (ctx_config->ctxs[i].ctx_type == UADK_CTX_HW) + wd_release_ctx(ctx_config->ctxs[i].ctx); + else + free((struct wd_soft_ctx *)ctx_config->ctxs[i].ctx); ctx_config->ctxs[i].ctx = 0; } } - free(ctx_config->ctxs); -} - -static void wd_alg_ctx_uninit(struct wd_ctx_config *ctx_config) -{ - __u32 i; - - for (i = 0; i < ctx_config->ctx_num; i++) { - if (ctx_config->ctxs[i].ctx) { - wd_release_ctx(ctx_config->ctxs[i].ctx); - ctx_config->ctxs[i].ctx = 0; - } + if (ctx_config->ctxs) { + free(ctx_config->ctxs); + ctx_config->ctxs = 0; } - - free(ctx_config->ctxs); -} - -static int wd_alg_init_sve_ctx(struct wd_ctx_config *ctx_config) -{ - struct wd_soft_ctx *ctx_sync, *ctx_async; - - ctx_config->ctx_num = WD_SOFT_CTX_NUM; - ctx_config->ctxs = calloc(ctx_config->ctx_num, sizeof(struct wd_ctx)); - if (!ctx_config->ctxs) - return -WD_ENOMEM; - - ctx_sync = calloc(1, sizeof(struct wd_soft_ctx)); - if (!ctx_sync) - goto free_ctxs; - - ctx_sync->fd = -1; - ctx_config->ctxs[WD_SOFT_SYNC_CTX].op_type = 0; - ctx_config->ctxs[WD_SOFT_SYNC_CTX].ctx_mode = CTX_MODE_SYNC; - ctx_config->ctxs[WD_SOFT_SYNC_CTX].ctx = (handle_t)ctx_sync; - - ctx_async = calloc(1, sizeof(struct wd_soft_ctx)); - if (!ctx_async) - goto free_ctx_sync; - - ctx_async->fd = -1; - ctx_config->ctxs[WD_SOFT_ASYNC_CTX].op_type = 0; - ctx_config->ctxs[WD_SOFT_ASYNC_CTX].ctx_mode = CTX_MODE_ASYNC; - ctx_config->ctxs[WD_SOFT_ASYNC_CTX].ctx = (handle_t)ctx_async; - - return 0; - -free_ctx_sync: - free(ctx_sync); -free_ctxs: - free(ctx_config->ctxs); - return -WD_ENOMEM; -} - -static void wd_alg_uninit_sve_ctx(struct wd_ctx_config *ctx_config) -{ - free((struct wd_soft_ctx *)ctx_config->ctxs[WD_SOFT_ASYNC_CTX].ctx); - free((struct wd_soft_ctx *)ctx_config->ctxs[WD_SOFT_SYNC_CTX].ctx); - free(ctx_config->ctxs); } int wd_alg_attrs_init(struct wd_init_attrs *attrs) { wd_alg_poll_ctx alg_poll_func = attrs->alg_poll_ctx; wd_alg_init alg_init_func = attrs->alg_init; - __u32 sched_type = attrs->sched_type; struct wd_ctx_config *ctx_config = NULL; struct wd_sched *alg_sched = NULL; - char alg_type[CRYPTO_MAX_ALG_NAME]; - int driver_type = UADK_ALG_HW; - const char *alg = attrs->alg; - int ret = -WD_EINVAL; + struct wd_alg_driver *drv = NULL; + char *alg_name = attrs->alg; + __u32 op_type_num; + int ret = 0; if (!attrs->ctx_params) return -WD_EINVAL; - if (attrs->driver) - driver_type = attrs->driver->calc_type; - - switch (driver_type) { - case UADK_ALG_SOFT: - case UADK_ALG_CE_INSTR: - ctx_config = calloc(1, sizeof(*ctx_config)); - if (!ctx_config) { - WD_ERR("fail to alloc ctx config\n"); - return -WD_ENOMEM; - } - attrs->ctx_config = ctx_config; + WD_ERR("debug: call function: %s!\n", __func__); + ctx_config = calloc(1, sizeof(*ctx_config)); + if (!ctx_config) { + WD_ERR("fail to alloc ctx config\n"); + return -WD_ENOMEM; + } + attrs->ctx_config = ctx_config; - /* Use default sched_type to alloc scheduler */ - alg_sched = wd_sched_rr_alloc(SCHED_POLICY_NONE, 1, 1, alg_poll_func); - if (!alg_sched) { - WD_ERR("fail to alloc scheduler\n"); - goto out_ctx_config; - } + /* Get op_type_num */ + op_type_num = attrs->ctx_params->op_type_num; + if (!op_type_num) + goto out_ctx_config; - attrs->sched = alg_sched; + /* Use default sched_type to alloc scheduler */ + if (attrs->sched_type == SCHED_POLICY_DEV) + alg_sched = wd_sched_rr_alloc(attrs->sched_type, attrs->ctx_params->op_type_num, + DEVICE_REGION_MAX, alg_poll_func); + else + alg_sched = wd_sched_rr_alloc(attrs->sched_type, attrs->ctx_params->op_type_num, + numa_max_node() + 1, alg_poll_func); + if (!alg_sched) { + WD_ERR("fail to alloc scheduler\n"); + goto out_ctx_config; + } + attrs->sched = alg_sched; - ret = wd_alg_ce_ctx_init(attrs); + /* Initialize queues according to task type */ + switch (attrs->task_type) { + case TASK_HW: + ret = wd_alg_hw_ctx_init(attrs); if (ret) { - WD_ERR("fail to init ce ctx\n"); + WD_ERR("fail to init HW ctx\n"); goto out_freesched; } - ret = alg_init_func(ctx_config, alg_sched); - if (ret) - goto out_pre_init; - break; - case UADK_ALG_SVE_INSTR: - /* Use default sched_type to alloc scheduler */ - alg_sched = wd_sched_rr_alloc(SCHED_POLICY_SINGLE, 1, 1, alg_poll_func); - if (!alg_sched) { - WD_ERR("fail to alloc scheduler\n"); - return -WD_EINVAL; - } - attrs->sched = alg_sched; - - ctx_config = calloc(1, sizeof(*ctx_config)); - if (!ctx_config) { - WD_ERR("fail to alloc ctx config\n"); - goto out_freesched; - } - attrs->ctx_config = ctx_config; - - ret = wd_alg_init_sve_ctx(ctx_config); - if (ret) { - WD_ERR("fail to init sve ctx!\n"); - goto out_freesched; - } - - ctx_config->cap = attrs->ctx_params->cap; - ret = alg_init_func(ctx_config, alg_sched); + case TASK_MIX: + ret = wd_alg_hw_ctx_init(attrs); if (ret) { - wd_alg_uninit_sve_ctx(ctx_config); + WD_ERR("fail to init mix HW ctx\n"); goto out_freesched; } - break; - case UADK_ALG_HW: - if (wd_get_alg_type(alg, alg_type)) - return -WD_EINVAL; - (void)strcpy(attrs->alg, alg_type); - - ctx_config = calloc(1, sizeof(*ctx_config)); - if (!ctx_config) { - WD_ERR("fail to alloc ctx config\n"); - return -WD_ENOMEM; - } - attrs->ctx_config = ctx_config; - if (sched_type == SCHED_POLICY_DEV) - alg_sched = wd_sched_rr_alloc(sched_type, attrs->ctx_params->op_type_num, - DEVICE_REGION_MAX, alg_poll_func); - else - alg_sched = wd_sched_rr_alloc(sched_type, attrs->ctx_params->op_type_num, - numa_max_node() + 1, alg_poll_func); - if (!alg_sched) { - WD_ERR("fail to instance scheduler\n"); - goto out_ctx_config; + WD_ERR("debug: call function: %s!\n", __func__); + drv = wd_request_drv(alg_name, ALG_DRV_SOFT); + if (drv == NULL) { + WD_ERR("fail to find soft driver.\n"); + break; + } else if (drv->calc_type == UADK_ALG_CE_INSTR) { + ret = wd_alg_other_ctx_init(attrs, UADK_CTX_CE_INS); + if (ret) { + WD_ERR("fail to init ce ctx\n"); + goto out_ctx_init; + } + } else if (drv->calc_type == UADK_ALG_SVE_INSTR) { + ret = wd_alg_other_ctx_init(attrs, UADK_CTX_SVE_INS); + if (ret) { + WD_ERR("fail to init sve ctx\n"); + goto out_ctx_init; + } } - attrs->sched = alg_sched; - ret = wd_alg_ctx_init(attrs); + break; + /* Only pure soft queues */ + case TASK_INSTR: + ret = wd_alg_other_init(attrs); if (ret) { - WD_ERR("fail to init ctx\n"); + WD_ERR("fail to init other ctx.\n"); goto out_freesched; } - ctx_config->cap = attrs->ctx_params->cap; - ret = alg_init_func(ctx_config, alg_sched); - if (ret) - goto out_pre_init; + drv = wd_request_drv(alg_name, ALG_DRV_SOFT); + if (drv == NULL) { + WD_ERR("fail to find soft driver.\n"); + goto out_ctx_init; + } else if (drv->calc_type == UADK_ALG_CE_INSTR) { + ret = wd_alg_other_ctx_init(attrs, UADK_CTX_CE_INS); + if (ret) { + WD_ERR("fail to init ce ctx\n"); + goto out_ctx_init; + } + } else if (drv->calc_type == UADK_ALG_SVE_INSTR) { + ret = wd_alg_other_ctx_init(attrs, UADK_CTX_SVE_INS); + if (ret) { + WD_ERR("fail to init sve ctx\n"); + goto out_ctx_init; + } + } break; default: - WD_ERR("driver type error: %d\n", driver_type); + WD_ERR("driver type error: %d\n", drv->calc_type); return -WD_EINVAL; } + ctx_config->cap = attrs->ctx_params->cap; + ret = alg_init_func(ctx_config, alg_sched); + if (ret) + goto out_ctx_init; + + WD_ERR("---->ctx nums: %u\n", ctx_config->ctx_num); + return 0; -out_pre_init: - if (driver_type == UADK_ALG_CE_INSTR || driver_type == UADK_ALG_SOFT) - wd_alg_ce_ctx_uninit(ctx_config); - else - wd_alg_ctx_uninit(ctx_config); +out_ctx_init: + wd_alg_ctxs_uninit(ctx_config); out_freesched: wd_sched_rr_release(alg_sched); out_ctx_config: @@ -3116,27 +3349,13 @@ void wd_alg_attrs_uninit(struct wd_init_attrs *attrs) { struct wd_ctx_config *ctx_config = attrs->ctx_config; struct wd_sched *alg_sched = attrs->sched; - int driver_type = attrs->driver->calc_type; if (!ctx_config) { wd_sched_rr_release(alg_sched); return; } - switch (driver_type) { - case UADK_ALG_SOFT: - case UADK_ALG_CE_INSTR: - wd_alg_ce_ctx_uninit(ctx_config); - break; - case UADK_ALG_SVE_INSTR: - wd_alg_uninit_sve_ctx(ctx_config); - break; - case UADK_ALG_HW: - wd_alg_ctx_uninit(ctx_config); - break; - default: - break; - } + wd_alg_ctxs_uninit(ctx_config); free(ctx_config); wd_sched_rr_release(alg_sched); -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> After the uadk framework updates the heterogeneous scheduling function, the corresponding scheduler needs to add a new scheduling solution. Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- include/wd_sched.h | 8 +- wd_sched.c | 999 ++++++++++++++++++++++++++++++++++++++++++--- wd_util.c | 5 +- 3 files changed, 950 insertions(+), 62 deletions(-) diff --git a/include/wd_sched.h b/include/wd_sched.h index 71949f9..809ee6d 100644 --- a/include/wd_sched.h +++ b/include/wd_sched.h @@ -13,7 +13,7 @@ extern "C" { #endif -#define INVALID_POS 0xFFFFFFFF +#define INVALID_POS 0xFFFF /* The global policy type */ enum sched_policy_type { @@ -25,6 +25,12 @@ enum sched_policy_type { SCHED_POLICY_SINGLE, /* requests will be sent to ctxs and dev_id */ SCHED_POLICY_DEV, + /* Hard calculation and soft calculation interval loop call */ + SCHED_POLICY_LOOP, + /* Perform heterogeneous calculations through ctx of session key */ + SCHED_POLICY_HUNGRY, + /* Instructions to accelerate heterogeneous computing */ + SCHED_POLICY_INSTR, SCHED_POLICY_BUTT, }; diff --git a/wd_sched.c b/wd_sched.c index 19936fd..29a0f65 100644 --- a/wd_sched.c +++ b/wd_sched.c @@ -19,6 +19,14 @@ enum sched_region_mode { SCHED_MODE_BUTT }; +struct wd_sched_balancer { + int switch_slice; + __u32 hw_task_num; + __u32 sw_task_num; + __u32 hw_dfx_num; + __u32 sw_dfx_num; +}; + /* * sched_key - The key if schedule region. * @numa_id: The schedule numa region id. @@ -31,10 +39,14 @@ struct sched_key { int numa_id; __u8 type; __u8 mode; - __u32 sync_ctxid; - __u32 async_ctxid; __u32 dev_id; + __u8 ctx_prop; + __u16 sync_ctxid[UADK_CTX_MAX]; + __u16 async_ctxid[UADK_CTX_MAX]; + struct wd_sched_balancer balancer; + }; +#define LOOP_SWITH_TIME 5 /* * struct sched_ctx_range - define one ctx pos. @@ -59,16 +71,29 @@ struct sched_ctx_region { * two(e.g. comp and uncomp) the map[x][y]'s value is the ctx * begin and end pos. * @valid: the region used flag. + * @region_type: the region's property + * @next_info: next scheduling domain */ struct wd_sched_info { - struct sched_ctx_region *ctx_region[SCHED_MODE_BUTT]; + struct sched_ctx_region *ctx_region[SCHED_MODE_BUTT]; // default as HW ctxs bool valid; + int region_type; + struct wd_sched_info *next_info; }; +#define MAX_SKEY_REGION_NUM 64 struct dev_region_map { __u32 dev_id; __u32 region_id; }; + +/* + * The default value for NUMA_NUM_NODES is 2048, + * but in reality, most systems will not have such a large NUMA; + * they will typically have fewer than 64 nodes. + */ +#define MAX_NUMA_NODES (NUMA_NUM_NODES >> 5) + /* * wd_sched_ctx - define the context of the scheduler. * @policy: define the policy of the scheduler. @@ -84,11 +109,80 @@ struct wd_sched_ctx { __u16 numa_num; __u16 dev_num; user_poll_func poll_func; - int numa_map[NUMA_NUM_NODES]; + int numa_map[MAX_NUMA_NODES]; + + __u32 skey_num; + pthread_mutex_t skey_lock; + struct sched_key *skey[MAX_SKEY_REGION_NUM]; // supports up to 64 threads region + __u32 poll_tid[MAX_SKEY_REGION_NUM]; + struct wd_sched_balancer balancer; + struct dev_region_map dev_id_map[DEVICE_REGION_MAX]; - struct wd_sched_info sched_info[0]; + struct wd_sched_info sched_info[MAX_NUMA_NODES]; }; +#define nop() asm volatile("nop") +static void delay_us(int ustime) +{ + int cycle = 2600; // for 2.6GHz CPU + int i, j; + + for (i = 0; i < ustime; i++) { + for (j = 0; j < cycle; j++) + nop(); + } + usleep(1); +} + +static void sched_skey_param_init(struct wd_sched_ctx *sched_ctx, struct sched_key *skey) +{ + __u32 i; + + pthread_mutex_lock(&sched_ctx->skey_lock); + for (i = 0; i < MAX_SKEY_REGION_NUM; i++) { + if (sched_ctx->skey[i] == NULL) { + sched_ctx->skey[i] = skey; + sched_ctx->skey_num++; + pthread_mutex_unlock(&sched_ctx->skey_lock); + WD_ERR("success: get valid skey node[%u]!\n", i); + return; + } + } + pthread_mutex_unlock(&sched_ctx->skey_lock); + WD_ERR("invalid: skey node number is too much!\n"); +} + +static struct sched_key *sched_get_poll_skey(struct wd_sched_ctx *sched_ctx) +{ + __u32 tid = pthread_self(); + __u16 i, tidx = 0; + + /* Delay processing within 17us is performed */ + delay_us(tid % 17); + /* Set mapping relationship between the recv tid and the send skey id */ + for (i = 0; i < sched_ctx->skey_num; i++) { + if (sched_ctx->poll_tid[i] == tid) { + //WD_ERR("poll tid ---> skey id:<%u, %u>!\n", i, tid); + tidx = i; + break; + } else if (sched_ctx->poll_tid[i] == 0) { + pthread_mutex_lock(&sched_ctx->skey_lock); + if (sched_ctx->poll_tid[i] == 0) { + //WD_ERR("poll tid<%u> <---> skey id:<%u>!\n", i, tid); + sched_ctx->poll_tid[i] = tid; + tidx = i; + } else { + pthread_mutex_unlock(&sched_ctx->skey_lock); + return NULL; + } + pthread_mutex_unlock(&sched_ctx->skey_lock); + break; + } + } + + return sched_ctx->skey[tidx]; +} + static bool sched_key_valid(struct wd_sched_ctx *sched_ctx, const struct sched_key *key) { if (key->numa_id >= sched_ctx->numa_num || key->mode >= SCHED_MODE_BUTT || @@ -212,14 +306,15 @@ static handle_t session_sched_init(handle_t h_sched_ctx, void *sched_param) skey->numa_id = param->numa_id; } - if (skey->numa_id < 0) { - WD_ERR("failed to get valid sched numa region!\n"); - goto out; - } + //if (skey->numa_id < 0) { + // WD_ERR("failed to get valid sched numa region!\n"); + // goto out; + //} + skey->numa_id = 0; - skey->sync_ctxid = session_sched_init_ctx(sched_ctx, skey, CTX_MODE_SYNC); - skey->async_ctxid = session_sched_init_ctx(sched_ctx, skey, CTX_MODE_ASYNC); - if (skey->sync_ctxid == INVALID_POS && skey->async_ctxid == INVALID_POS) { + skey->sync_ctxid[0] = session_sched_init_ctx(sched_ctx, skey, CTX_MODE_SYNC); + skey->async_ctxid[0] = session_sched_init_ctx(sched_ctx, skey, CTX_MODE_ASYNC); + if (skey->sync_ctxid[0] == INVALID_POS && skey->async_ctxid[0] == INVALID_POS) { WD_ERR("failed to get valid sync_ctxid or async_ctxid!\n"); goto out; } @@ -251,8 +346,8 @@ static __u32 session_sched_pick_next_ctx(handle_t h_sched_ctx, void *sched_key, /* return in do task */ if (sched_mode == CTX_MODE_SYNC) - return key->sync_ctxid; - return key->async_ctxid; + return key->sync_ctxid[0]; + return key->async_ctxid[0]; } static int session_poll_region(struct wd_sched_ctx *sched_ctx, __u32 begin, @@ -327,7 +422,7 @@ static int session_sched_poll_policy(handle_t h_sched_ctx, __u32 expect, __u32 * return -WD_EINVAL; } - if (unlikely(sched_ctx->numa_num > NUMA_NUM_NODES)) { + if (unlikely(sched_ctx->numa_num > MAX_NUMA_NODES)) { WD_ERR("invalid: ctx's numa number is %u!\n", sched_ctx->numa_num); return -WD_EINVAL; } @@ -572,9 +667,9 @@ static handle_t session_dev_sched_init(handle_t h_sched_ctx, void *sched_param) skey->type = param->type; skey->dev_id = param->dev_id; - skey->sync_ctxid = session_dev_sched_init_ctx(sched_ctx, skey, CTX_MODE_SYNC); - skey->async_ctxid = session_dev_sched_init_ctx(sched_ctx, skey, CTX_MODE_ASYNC); - if (skey->sync_ctxid == INVALID_POS && skey->async_ctxid == INVALID_POS) { + skey->sync_ctxid[0] = session_dev_sched_init_ctx(sched_ctx, skey, CTX_MODE_SYNC); + skey->async_ctxid[0] = session_dev_sched_init_ctx(sched_ctx, skey, CTX_MODE_ASYNC); + if (skey->sync_ctxid[0] == INVALID_POS && skey->async_ctxid[0] == INVALID_POS) { WD_ERR("failed to get valid sync_ctxid or async_ctxid!\n"); goto out; } @@ -586,6 +681,668 @@ out: return (handle_t)(-WD_EINVAL); } +static struct sched_ctx_region *loop_get_near_region( + struct wd_sched_ctx *sched_ctx, const struct sched_key *key) +{ + struct wd_sched_info *sched_info, *demon_info; + int numa_id; + + /* If the key->numa_id is not exist, we should scan for a valid region */ + for (numa_id = 0; numa_id < sched_ctx->numa_num; numa_id++) { + sched_info = sched_ctx->sched_info + numa_id; + if (sched_info->valid) { + demon_info = sched_info; + while (demon_info) { + if (demon_info->valid) + return &demon_info->ctx_region[key->mode][key->type]; + demon_info = demon_info->next_info; + } + } + } + + return NULL; +} + +/* + * loop_get_ctx_range - Get ctx range from ctx_map by the wd comp arg + */ +static struct sched_ctx_region *loop_get_ctx_range( + struct wd_sched_ctx *sched_ctx, const struct sched_key *key) +{ + struct wd_sched_info *sched_region, *sched_info; + int ctx_prop = key->ctx_prop; + + if (key->numa_id < 0) + return loop_get_near_region(sched_ctx, key); + + sched_region = sched_ctx->sched_info; + sched_info = sched_region + key->numa_id; + while (sched_info) { + if (sched_info->valid && ctx_prop == sched_info->region_type && + sched_info->ctx_region[key->mode][key->type].valid) + return &sched_info->ctx_region[key->mode][key->type]; + sched_info = sched_info->next_info; + } + + WD_ERR("failed to get valid sched region!\n"); + return NULL; +} + +/* + * loop_sched_init_ctx - Get one ctx from ctxs by the sched_ctx and arg. + * @sched_ctx: Schedule ctx, reference the struct sample_sched_ctx. + * @sched_key: The key of schedule region. + * @sched_mode: The sched async/sync mode. + * + * The user must init the schedule info through wd_sched_rr_instance + */ +static __u32 loop_sched_init_ctx(struct wd_sched_ctx *sched_ctx, + struct sched_key *key, const int sched_mode) +{ + struct sched_ctx_region *region = NULL; + bool ret; + + key->mode = sched_mode; + ret = sched_key_valid(sched_ctx, key); + if (!ret) + return INVALID_POS; + + region = loop_get_ctx_range(sched_ctx, key); + if (!region) + return INVALID_POS; + + return sched_get_next_pos_rr(region, NULL); +} + +static handle_t loop_sched_init(handle_t h_sched_ctx, void *sched_param) +{ + struct wd_sched_ctx *sched_ctx = (struct wd_sched_ctx *)h_sched_ctx; + struct sched_params *param = (struct sched_params *)sched_param; + int cpu = sched_getcpu(); + int node = numa_node_of_cpu(cpu); + struct sched_key *skey; + int ctx_prop; + + if (node < 0) { + WD_ERR("invalid: failed to get numa node!\n"); + return (handle_t)(-WD_EINVAL); + } + + if (!sched_ctx) { + WD_ERR("invalid: sched ctx is NULL!\n"); + return (handle_t)(-WD_EINVAL); + } + + skey = malloc(sizeof(struct sched_key)); + if (!skey) { + WD_ERR("failed to alloc memory for session sched key!\n"); + return (handle_t)(-WD_ENOMEM); + } + + if (!param) { + memset(skey, 0, sizeof(struct sched_key)); + //skey->numa_id = sched_ctx->numa_map[node]; + skey->numa_id = 0; + skey->ctx_prop = UADK_CTX_HW; + WD_INFO("loop don't set scheduler parameters!\n"); + } else if (param->numa_id < 0) { + skey->type = param->type; + //skey->numa_id = sched_ctx->numa_map[node]; + skey->numa_id = 0; + skey->ctx_prop = param->ctx_prop; + } else { + skey->type = param->type; + skey->numa_id = param->numa_id; + skey->ctx_prop = param->ctx_prop; + } + + //if (skey->numa_id < 0) { + // WD_ERR("failed to get valid sched numa region!\n"); + // goto out; + //} + skey->numa_id = 0; + + memset(&skey->sync_ctxid, INVALID_POS, sizeof(__u32) * UADK_CTX_MAX); + memset(&skey->async_ctxid, INVALID_POS, sizeof(__u32) * UADK_CTX_MAX); + skey->sync_ctxid[0] = loop_sched_init_ctx(sched_ctx, skey, CTX_MODE_SYNC); + skey->async_ctxid[0] = loop_sched_init_ctx(sched_ctx, skey, CTX_MODE_ASYNC); + if (skey->sync_ctxid[0] == INVALID_POS && skey->async_ctxid[0] == INVALID_POS) { + WD_ERR("failed to get valid sync_ctxid or async_ctxid!\n"); + goto out; + } + WD_ERR("sync_ctxid is: %u; async_ctxid is: %u!\n", skey->sync_ctxid[0], skey->async_ctxid[0]); + ctx_prop = skey->ctx_prop; + skey->ctx_prop = UADK_CTX_CE_INS; + skey->sync_ctxid[UADK_CTX_CE_INS] = loop_sched_init_ctx(sched_ctx, skey, CTX_MODE_SYNC); + skey->async_ctxid[UADK_CTX_CE_INS] = loop_sched_init_ctx(sched_ctx, skey, CTX_MODE_ASYNC); + skey->ctx_prop = ctx_prop; + if (skey->sync_ctxid[1] == INVALID_POS && skey->async_ctxid[1] == INVALID_POS) { + WD_ERR("failed to get valid CE sync_ctxid or async_ctxid!\n"); + skey->sync_ctxid[1] = skey->sync_ctxid[0]; + skey->async_ctxid[1] = skey->async_ctxid[0]; + } + + WD_ERR("sw ctxid is: %u, %u!\n", skey->sync_ctxid[1], skey->async_ctxid[1]); + + return (handle_t)skey; + +out: + free(skey); + return (handle_t)(-WD_EINVAL); +} + +/* + * loop_sched_pick_next_ctx - Get one ctx from ctxs by the sched_ctx and arg. + * @sched_ctx: Schedule ctx, reference the struct sample_sched_ctx. + * @sched_key: The key of schedule region. + * @sched_mode: The sched async/sync mode. + * + * The user must init the schedule info through session_sched_init + */ +static __u32 loop_sched_pick_next_ctx(handle_t h_sched_ctx, void *sched_key, + const int sched_mode) +{ + struct wd_sched_ctx *sched_ctx = (struct wd_sched_ctx *)h_sched_ctx; + struct sched_key *key = (struct sched_key *)sched_key; + struct wd_sched_balancer *balancer = &sched_ctx->balancer; + + if (unlikely(!h_sched_ctx || !key)) { + WD_ERR("invalid: sched ctx or key is NULL!\n"); + return INVALID_POS; + } + + if (key->sync_ctxid[UADK_CTX_HW] == INVALID_POS || + key->async_ctxid[UADK_CTX_HW] == INVALID_POS) + return session_sched_pick_next_ctx(h_sched_ctx, sched_key, sched_mode); + + if (sched_mode == CTX_MODE_SYNC) { + if (balancer->switch_slice == LOOP_SWITH_TIME) { + balancer->switch_slice = 0; + balancer->hw_dfx_num++; + /* run in HW */ + return key->sync_ctxid[UADK_CTX_HW]; + } else { + balancer->switch_slice++; + /* run in soft CE */ + balancer->sw_dfx_num++; + return key->sync_ctxid[UADK_CTX_CE_INS]; + } + } + // Async mode + if (balancer->hw_task_num > balancer->sw_task_num >> 1) { + /* run in soft CE */ + balancer->sw_task_num++; + + return key->async_ctxid[UADK_CTX_CE_INS]; + } else { + /* run in HW */ + balancer->hw_task_num++; + + return key->async_ctxid[UADK_CTX_HW]; + } +} + +static int loop_poll_policy_rr(struct wd_sched_ctx *sched_ctx, int numa_id, + __u32 expect, __u32 *count) +{ + struct wd_sched_balancer *balancer = &sched_ctx->balancer; + struct wd_sched_info *sched_info, *cur_info, *pnext_info; + struct sched_ctx_region **region; + __u32 begin, end; + __u32 i; + int ret; + + sched_info = sched_ctx->sched_info; + cur_info = sched_info + numa_id; + pnext_info = cur_info; + while (pnext_info) { + if (!pnext_info->valid) { + pnext_info = pnext_info->next_info; + continue; + } + + region = pnext_info->ctx_region; + for (i = 0; i < sched_ctx->type_num; i++) { + if (!region[SCHED_MODE_ASYNC][i].valid) + continue; + + begin = region[SCHED_MODE_ASYNC][i].begin; + end = region[SCHED_MODE_ASYNC][i].end; + // WD_ERR("session_poll_policy_rr numa: %d, from %u ---> %u!\n", numa_id, begin, end); + ret = session_poll_region(sched_ctx, begin, end, expect, count); + if (unlikely(ret)) + return ret; + } + + /* run in HW */ + if (pnext_info->region_type == UADK_CTX_HW) { + if (balancer->hw_task_num > *count) + balancer->hw_task_num -= *count; + else + balancer->hw_task_num = 0; + balancer->hw_dfx_num += *count; + } else { + if (balancer->sw_task_num > *count) + balancer->sw_task_num -= *count; + else + balancer->sw_task_num = 0; + balancer->sw_dfx_num += *count; + } + + pnext_info = pnext_info->next_info; + } + + return 0; +} + +/* + * loop_poll_policy - The polling policy matches the pick next ctx. + * @sched_ctx: Schedule ctx, reference the struct sample_sched_ctx. + * @cfg: The global resoure info. + * @expect: User expect poll msg num. + * @count: The actually poll num. + * + * The user must init the schedule info through wd_sched_rr_instance, the + * func interval will not check the valid, becouse it will affect performance. + */ +static int loop_sched_poll_policy(handle_t h_sched_ctx, __u32 expect, __u32 *count) +{ + struct wd_sched_ctx *sched_ctx = (struct wd_sched_ctx *)h_sched_ctx; + struct wd_sched_info *sched_info; + __u32 loop_time = 0; + __u32 last_count = 0; + __u16 i; + int ret; + + if (unlikely(!count || !sched_ctx || !sched_ctx->poll_func)) { + WD_ERR("invalid: sched ctx or poll_func is NULL or count is zero!\n"); + return -WD_EINVAL; + } + + if (unlikely(sched_ctx->numa_num > MAX_NUMA_NODES)) { + WD_ERR("invalid: ctx's numa number is %u!\n", sched_ctx->numa_num); + return -WD_EINVAL; + } + + sched_info = sched_ctx->sched_info; + + /* + * Try different numa's ctx if we can't receive any + * package last time, it is more efficient. In most + * bad situation, poll ends after MAX_POLL_TIMES loop. + */ + while (++loop_time < MAX_POLL_TIMES) { + for (i = 0; i < sched_ctx->numa_num;) { + /* If current numa is not valid, find next. */ + if (!sched_info[i].valid) { + i++; + continue; + } + + last_count = *count; + ret = loop_poll_policy_rr(sched_ctx, i, expect, count); + if (unlikely(ret)) + return ret; + + if (expect == *count) + return 0; + + /* + * If no package is received, find next numa, + * otherwise, keep receiving packets at this node. + */ + if (last_count == *count) + i++; + } + } + + return 0; +} + +static handle_t skey_sched_init(handle_t h_sched_ctx, void *sched_param) +{ + struct wd_sched_ctx *sched_ctx = (struct wd_sched_ctx *)h_sched_ctx; + struct sched_params *param = (struct sched_params *)sched_param; + int cpu = sched_getcpu(); + int node = numa_node_of_cpu(cpu); + struct sched_key *skey; + int ctx_prop; + + if (node < 0) { + WD_ERR("invalid: failed to get numa node!\n"); + return (handle_t)(-WD_EINVAL); + } + + if (!sched_ctx) { + WD_ERR("invalid: sched ctx is NULL!\n"); + return (handle_t)(-WD_EINVAL); + } + + skey = malloc(sizeof(struct sched_key)); + if (!skey) { + WD_ERR("failed to alloc memory for session sched key!\n"); + return (handle_t)(-WD_ENOMEM); + } + + if (!param) { + memset(skey, 0, sizeof(struct sched_key)); + //skey->numa_id = sched_ctx->numa_map[node]; + skey->numa_id = 0; + skey->ctx_prop = UADK_CTX_HW; + WD_INFO("loop don't set scheduler parameters!\n"); + } else if (param->numa_id < 0) { + skey->type = param->type; + //skey->numa_id = sched_ctx->numa_map[node]; + skey->numa_id = 0; + skey->ctx_prop = param->ctx_prop; + } else { + skey->type = param->type; + skey->numa_id = param->numa_id; + skey->ctx_prop = param->ctx_prop; + } + + //if (skey->numa_id < 0) { + // WD_ERR("failed to get valid sched numa region!\n"); + // goto out; + //} + memset(&skey->balancer, 0x0, sizeof(struct wd_sched_balancer)); + skey->numa_id = 0; + + memset(&skey->sync_ctxid, INVALID_POS, sizeof(__u32) * UADK_CTX_MAX); + memset(&skey->async_ctxid, INVALID_POS, sizeof(__u32) * UADK_CTX_MAX); + skey->sync_ctxid[0] = loop_sched_init_ctx(sched_ctx, skey, CTX_MODE_SYNC); + skey->async_ctxid[0] = loop_sched_init_ctx(sched_ctx, skey, CTX_MODE_ASYNC); + if (skey->sync_ctxid[0] == INVALID_POS && skey->async_ctxid[0] == INVALID_POS) { + WD_ERR("failed to get valid sync_ctxid or async_ctxid!\n"); + goto out; + } + WD_ERR("sync_ctxid is: %u; async_ctxid is: %u!\n", skey->sync_ctxid[0], skey->async_ctxid[0]); + ctx_prop = skey->ctx_prop; + skey->ctx_prop = UADK_CTX_CE_INS; + skey->sync_ctxid[UADK_CTX_CE_INS] = loop_sched_init_ctx(sched_ctx, skey, CTX_MODE_SYNC); + skey->async_ctxid[UADK_CTX_CE_INS] = loop_sched_init_ctx(sched_ctx, skey, CTX_MODE_ASYNC); + skey->ctx_prop = ctx_prop; + if (skey->sync_ctxid[1] == INVALID_POS && skey->async_ctxid[1] == INVALID_POS) { + WD_ERR("failed to get valid CE sync_ctxid or async_ctxid!\n"); + skey->sync_ctxid[1] = skey->sync_ctxid[0]; + skey->async_ctxid[1] = skey->async_ctxid[0]; + } + + sched_skey_param_init(sched_ctx, skey); + WD_ERR("sw ctxid is: %u, %u!\n", skey->sync_ctxid[1], skey->async_ctxid[1]); + + return (handle_t)skey; + +out: + free(skey); + return (handle_t)(-WD_EINVAL); +} + +/* + * loop_sched_pick_next_ctx - Get one ctx from ctxs by the sched_ctx and arg. + * @sched_ctx: Schedule ctx, reference the struct sample_sched_ctx. + * @sched_key: The key of schedule region. + * @sched_mode: The sched async/sync mode. + * + * The user must init the schedule info through session_sched_init + */ +static __u32 skey_sched_pick_next_ctx(handle_t h_sched_ctx, void *sched_key, + const int sched_mode) +{ + struct sched_key *skey = (struct sched_key *)sched_key; + + if (unlikely(!h_sched_ctx || !skey)) { + WD_ERR("invalid: sched ctx or key is NULL!\n"); + return INVALID_POS; + } + + if (skey->sync_ctxid[UADK_CTX_HW] == INVALID_POS || + skey->async_ctxid[UADK_CTX_HW] == INVALID_POS) + return session_sched_pick_next_ctx(h_sched_ctx, sched_key, sched_mode); + + // Async mode + if (sched_mode == CTX_MODE_ASYNC) { + if (skey->balancer.hw_task_num > (skey->balancer.sw_task_num >> 1)) { + /* run in soft CE */ + skey->balancer.sw_task_num++; + return skey->async_ctxid[UADK_CTX_CE_INS]; + } else { + /* run in HW */ + skey->balancer.hw_task_num++; + return skey->async_ctxid[UADK_CTX_HW]; + } + } + + if (skey->balancer.switch_slice == LOOP_SWITH_TIME) { + skey->balancer.switch_slice = 0; + skey->balancer.hw_dfx_num++; + /* run in HW */ + return skey->sync_ctxid[UADK_CTX_HW]; + } else { + skey->balancer.switch_slice++; + skey->balancer.sw_dfx_num++; + /* run in soft CE */ + return skey->sync_ctxid[UADK_CTX_CE_INS]; + } +} + +static int skey_poll_ctx(struct wd_sched_ctx *sched_ctx, struct sched_key *skey, + __u32 expect, __u32 *count) +{ + __u32 hw_num = 0; + __u32 sw_num = 0; + __u32 poll_num; + int i, ret; + + /* + * Collect hardware messages first, multi-threading performance is better; + * Collect software packets first, single-thread performance is better + */ + for (i = UADK_CTX_MAX - 1; i >= 0; i--) { + if (skey->async_ctxid[i] == INVALID_POS) + continue; + + poll_num = 0; + ret = sched_ctx->poll_func(skey->async_ctxid[i], expect, &poll_num); + if ((ret < 0) && (ret != -EAGAIN)) + return ret; + else if (poll_num == 0) + continue; + + if (i == 0) + hw_num += poll_num; + else + sw_num += poll_num; + } + + *count = *count + hw_num + sw_num; + if (hw_num > 0) { + if (skey->balancer.hw_task_num > hw_num) + skey->balancer.hw_task_num -= hw_num; + else + skey->balancer.hw_task_num = 0; + skey->balancer.hw_dfx_num += hw_num; + } + if (sw_num > 0) { + if (skey->balancer.sw_task_num > sw_num) + skey->balancer.sw_task_num -= sw_num; + else + skey->balancer.sw_task_num = 0; + skey->balancer.sw_dfx_num += sw_num; + } + + return 0; +} + +/* + * loop_poll_policy - The polling policy matches the pick next ctx. + * @sched_ctx: Schedule ctx, reference the struct sample_sched_ctx. + * @cfg: The global resoure info. + * @expect: User expect poll msg num. + * @count: The actually poll num. + * + * The user must init the schedule info through wd_sched_rr_instance, the + * func interval will not check the valid, becouse it will affect performance. + */ +static int skey_sched_poll_policy(handle_t h_sched_ctx, __u32 expect, __u32 *count) +{ + struct wd_sched_ctx *sched_ctx = (struct wd_sched_ctx *)h_sched_ctx; + struct sched_key *skey; + int ret; + + if (unlikely(!count || !sched_ctx || !sched_ctx->poll_func)) { + WD_ERR("invalid: sched ctx or poll_func is NULL or count is zero!\n"); + return -WD_EINVAL; + } + + skey = sched_get_poll_skey(sched_ctx); + if (!skey) + return -WD_EAGAIN; + + ret = skey_poll_ctx(sched_ctx, skey, expect, count); + if (unlikely(ret)) + return ret; + + return 0; +} + +static handle_t instr_sched_init(handle_t h_sched_ctx, void *sched_param) +{ + struct wd_sched_ctx *sched_ctx = (struct wd_sched_ctx *)h_sched_ctx; + struct sched_params *param = (struct sched_params *)sched_param; + int cpu = sched_getcpu(); + int node = numa_node_of_cpu(cpu); + struct sched_key *skey; + + if (node < 0) { + WD_ERR("invalid: failed to get numa node!\n"); + return (handle_t)(-WD_EINVAL); + } + + if (!sched_ctx) { + WD_ERR("invalid: sched ctx is NULL!\n"); + return (handle_t)(-WD_EINVAL); + } + + skey = malloc(sizeof(struct sched_key)); + if (!skey) { + WD_ERR("failed to alloc memory for session sched key!\n"); + return (handle_t)(-WD_ENOMEM); + } + + if (!param) { + memset(skey, 0, sizeof(struct sched_key)); + //skey->numa_id = sched_ctx->numa_map[node]; + skey->numa_id = 0; + skey->ctx_prop = UADK_CTX_CE_INS; + WD_INFO("loop don't set scheduler parameters!\n"); + } else if (param->numa_id < 0) { + skey->type = param->type; + //skey->numa_id = sched_ctx->numa_map[node]; + skey->numa_id = 0; + skey->ctx_prop = param->ctx_prop; + } else { + skey->type = param->type; + skey->numa_id = param->numa_id; + skey->ctx_prop = param->ctx_prop; + } + + //if (skey->numa_id < 0) { + // WD_ERR("failed to get valid sched numa region!\n"); + // goto out; + //} + skey->numa_id = 0; + + memset(&skey->sync_ctxid, INVALID_POS, sizeof(__u32) * UADK_CTX_MAX); + memset(&skey->async_ctxid, INVALID_POS, sizeof(__u32) * UADK_CTX_MAX); + skey->sync_ctxid[UADK_CTX_CE_INS] = loop_sched_init_ctx(sched_ctx, skey, CTX_MODE_SYNC); + skey->async_ctxid[UADK_CTX_CE_INS] = loop_sched_init_ctx(sched_ctx, skey, CTX_MODE_ASYNC); + + sched_skey_param_init(sched_ctx, skey); + WD_ERR("sw ctxid is: %u, %u!\n", skey->sync_ctxid[1], skey->async_ctxid[1]); + + return (handle_t)skey; +} + +/* + * loop_sched_pick_next_ctx - Get one ctx from ctxs by the sched_ctx and arg. + * @sched_ctx: Schedule ctx, reference the struct sample_sched_ctx. + * @sched_key: The key of schedule region. + * @sched_mode: The sched async/sync mode. + * + * The user must init the schedule info through session_sched_init + */ +static __u32 instr_sched_pick_next_ctx(handle_t h_sched_ctx, void *sched_key, + const int sched_mode) +{ + struct sched_key *key = (struct sched_key *)sched_key; + + //if (unlikely(!h_sched_ctx || !key)) { + // WD_ERR("invalid: sched ctx or key is NULL!\n"); + // return INVALID_POS; + //} + + key->balancer.sw_dfx_num++; + if (sched_mode == CTX_MODE_SYNC) { + /* run in soft CE */ + return key->sync_ctxid[UADK_CTX_CE_INS]; + } + // Async mode + /* run in soft CE */ + return key->async_ctxid[UADK_CTX_CE_INS]; +} + +static int instr_poll_policy_rr(struct wd_sched_ctx *sched_ctx, struct sched_key *skey, + __u32 expect, __u32 *count) +{ + __u32 recv_cnt, ctx_id; + int ret; + + //WD_ERR("success: sched skey num: %u!\n", i); + recv_cnt = 0; + ctx_id = skey->async_ctxid[UADK_CTX_CE_INS]; + ret = sched_ctx->poll_func(ctx_id, expect, &recv_cnt); + if ((ret < 0) && (ret != -EAGAIN)) + return ret; + *count += recv_cnt; + //WD_ERR("success: sched recv task num: %u!\n", *count); + + return 0; +} + +/* + * loop_poll_policy - The polling policy matches the pick next ctx. + * @sched_ctx: Schedule ctx, reference the struct sample_sched_ctx. + * @cfg: The global resoure info. + * @expect: User expect poll msg num. + * @count: The actually poll num. + * + * The user must init the schedule info through wd_sched_rr_instance, the + * func interval will not check the valid, becouse it will affect performance. + */ +static int instr_sched_poll_policy(handle_t h_sched_ctx, __u32 expect, __u32 *count) +{ + struct wd_sched_ctx *sched_ctx = (struct wd_sched_ctx *)h_sched_ctx; + struct sched_key *skey; + int ret; + + if (unlikely(!count || !sched_ctx || !sched_ctx->poll_func)) { + WD_ERR("invalid: sched ctx or poll_func is NULL or count is zero!\n"); + return -WD_EINVAL; + } + + /* First poll the skey is NULL */ + skey = sched_get_poll_skey(sched_ctx); + if (!skey) + return -WD_EAGAIN; + + ret = instr_poll_policy_rr(sched_ctx, skey, expect, count); + if (unlikely(ret)) + return ret; + + return ret; +} + static struct wd_sched sched_table[SCHED_POLICY_BUTT] = { { .name = "RR scheduler", @@ -611,7 +1368,25 @@ static struct wd_sched sched_table[SCHED_POLICY_BUTT] = { .sched_init = session_dev_sched_init, .pick_next_ctx = session_sched_pick_next_ctx, .poll_policy = session_sched_poll_policy, - } + }, { + .name = "Loop scheduler", + .sched_policy = SCHED_POLICY_LOOP, + .sched_init = loop_sched_init, + .pick_next_ctx = loop_sched_pick_next_ctx, + .poll_policy = loop_sched_poll_policy, + }, { + .name = "Hungry scheduler", + .sched_policy = SCHED_POLICY_HUNGRY, + .sched_init = skey_sched_init, + .pick_next_ctx = skey_sched_pick_next_ctx, + .poll_policy = skey_sched_poll_policy, + }, { + .name = "Instr scheduler", + .sched_policy = SCHED_POLICY_INSTR, + .sched_init = instr_sched_init, + .pick_next_ctx = instr_sched_pick_next_ctx, + .poll_policy = instr_sched_poll_policy, + }, }; static int wd_sched_get_nearby_numa_id(struct wd_sched_info *sched_info, int node, int numa_num) @@ -704,12 +1479,38 @@ static int wd_instance_dev_region(struct wd_sched_ctx *sched_ctx, return WD_SUCCESS; } +static int wd_sched_region_instance(struct wd_sched_info *sched_info, + struct sched_params *param) +{ + struct wd_sched_info *next_info; + __u8 type, mode; + + type = param->type; + mode = param->mode; + next_info = sched_info; + while (next_info) { + if (next_info->region_type == param->ctx_prop) { + next_info->ctx_region[mode][type].begin = param->begin; + next_info->ctx_region[mode][type].end = param->end; + next_info->ctx_region[mode][type].last = param->begin; + next_info->ctx_region[mode][type].valid = true; + next_info->valid = true; + pthread_mutex_init(&next_info->ctx_region[mode][type].lock, NULL); + WD_ERR("instance numa<%d>, property<%d>, mode<%u>, type<%u> ctx: begin: %u ----> end: %u!\n", + param->numa_id, param->ctx_prop, mode, type, param->begin, param->end); + return 0; + } + next_info = next_info->next_info; + } + + return -WD_EINVAL; +} + int wd_sched_rr_instance(const struct wd_sched *sched, struct sched_params *param) { - struct wd_sched_info *sched_info = NULL; struct wd_sched_ctx *sched_ctx = NULL; __u8 type, mode; - int numa_id; + int numa_id, ret; if (!sched || !sched->h_sched_ctx || !param) { WD_ERR("invalid: sched or sched_params is NULL!\n"); @@ -748,62 +1549,97 @@ int wd_sched_rr_instance(const struct wd_sched *sched, struct sched_params *para if (sched_ctx->policy == SCHED_POLICY_DEV) return wd_instance_dev_region(sched_ctx, param); - sched_info = &sched_ctx->sched_info[numa_id]; - if (!sched_info->ctx_region[mode]) { + if (param->ctx_prop > UADK_CTX_SOFT) { + WD_ERR("invalid: sched_ctx's prop is %d\n", param->ctx_prop); + return -WD_EINVAL; + } + /* For older tools, the default setting is of the HW type. */ + if (param->ctx_prop < 0) + param->ctx_prop = UADK_CTX_HW; + + if (!sched_ctx->sched_info[numa_id].ctx_region[mode]) { WD_ERR("invalid: ctx_region is NULL, numa: %d, mode: %u!\n", numa_id, mode); return -WD_EINVAL; } - sched_info->ctx_region[mode][type].begin = param->begin; - sched_info->ctx_region[mode][type].end = param->end; - sched_info->ctx_region[mode][type].last = param->begin; - sched_info->ctx_region[mode][type].valid = true; - sched_info->valid = true; + ret = wd_sched_region_instance(&sched_ctx->sched_info[numa_id], param); + if (ret) { + WD_ERR("failed to instance ctx_region!\n"); + return ret; + } wd_sched_map_cpus_to_dev(sched_ctx); - pthread_mutex_init(&sched_info->ctx_region[mode][type].lock, NULL); return WD_SUCCESS; } -void wd_sched_rr_release(struct wd_sched *sched) +static void wd_sched_region_release(struct wd_sched_ctx *sched_ctx) { - struct wd_sched_info *sched_info; - struct wd_sched_ctx *sched_ctx; + struct wd_sched_info *sched_info, *next_info, *cur_info; int i, j, region_num; - if (!sched) + sched_info = sched_ctx->sched_info; + if (!sched_info) return; - sched_ctx = (struct wd_sched_ctx *)sched->h_sched_ctx; - if (!sched_ctx) - goto ctx_out; - /* In SCHED_POLICY_DEV mode, numa_num mean device numbers */ if (sched_ctx->policy == SCHED_POLICY_DEV) region_num = DEVICE_REGION_MAX; else region_num = sched_ctx->numa_num; - sched_info = sched_ctx->sched_info; - if (!sched_info) - goto info_out; - for (i = 0; i < region_num; i++) { - for (j = 0; j < SCHED_MODE_BUTT; j++) { - if (sched_info[i].ctx_region[j]) { - free(sched_info[i].ctx_region[j]); - sched_info[i].ctx_region[j] = NULL; + cur_info = &sched_info[i]; + while (cur_info) { + next_info = cur_info->next_info; + for (j = 0; j < SCHED_MODE_BUTT; j++) { + if (cur_info->ctx_region[j]) { + free(cur_info->ctx_region[j]); + cur_info->ctx_region[j] = NULL; + } } + /* First info region is alloced by sched ctx */ + if (cur_info->region_type != UADK_CTX_HW) + free(cur_info); + cur_info = next_info; } } +} + +void wd_sched_rr_release(struct wd_sched *sched) +{ + struct wd_sched_ctx *sched_ctx; + __u32 hw_dfx_num = 0; + __u32 sw_dfx_num = 0; + __u32 i; -info_out: + if (!sched) + return; + + sched_ctx = (struct wd_sched_ctx *)sched->h_sched_ctx; + if (!sched_ctx) + goto ctx_out; + + for (i = 0; i < sched_ctx->skey_num; i++) { + if (sched_ctx->skey[i] != NULL) { + hw_dfx_num += sched_ctx->skey[i]->balancer.hw_dfx_num; + sw_dfx_num += sched_ctx->skey[i]->balancer.sw_dfx_num; + } + sched_ctx->skey[i] = NULL; + } + hw_dfx_num += sched_ctx->balancer.hw_dfx_num; + sw_dfx_num += sched_ctx->balancer.sw_dfx_num; + sched_ctx->skey_num = 0; + /* Release sched dfx info */ + WD_ERR("scheduler balance hw task num: %u, sw task num: %u\n", + hw_dfx_num, sw_dfx_num); + + wd_sched_region_release(sched_ctx); free(sched_ctx); + ctx_out: free(sched); - return; } @@ -825,14 +1661,61 @@ static int numa_num_check(__u16 numa_num) return 0; } +static int wd_sched_region_init(struct wd_sched_ctx *sched_ctx, + __u8 type_num, __u16 numa_num) +{ + struct wd_sched_info *sched_info = sched_ctx->sched_info; + struct wd_sched_info *cur_info; + int i, j, k; + + for (i = 0; i < MAX_SKEY_REGION_NUM; i++) { + sched_ctx->skey[i] = NULL; + sched_ctx->poll_tid[i] = 0; + } + pthread_mutex_init(&sched_ctx->skey_lock, NULL); + sched_ctx->skey_num = 0; + memset(&sched_ctx->balancer, 0x0, sizeof(struct wd_sched_balancer)); + + for (i = 0; i < numa_num; i++) { + /* Init sched_info next list */ + cur_info = &sched_info[i]; + for (j = 0; j < UADK_CTX_MAX; j++) { + for (k = 0; k < SCHED_MODE_BUTT; k++) { + cur_info->ctx_region[k] = + calloc(1, sizeof(struct sched_ctx_region) * type_num); + if (!cur_info->ctx_region[k]) + goto sched_err; + } + cur_info->valid = false; + cur_info->region_type = j; + + /* The last node point to NULL */ + if (j == UADK_CTX_MAX - 1) { + cur_info->next_info = NULL; + break; + } + cur_info->next_info = calloc(1, sizeof(*cur_info)); + if (!cur_info) + goto sched_err; + cur_info = cur_info->next_info; + } + } + + return 0; + +sched_err: + wd_sched_region_release(sched_ctx); + + return -WD_EINVAL; +} + struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num, __u16 numa_num, user_poll_func func) { - struct wd_sched_info *sched_info; struct wd_sched_ctx *sched_ctx; struct wd_sched *sched; int region_num; - int i, j; + int i, ret; if (sched_type >= SCHED_POLICY_BUTT || !type_num) { WD_ERR("invalid: sched_type is %u or type_num is %u!\n", @@ -878,21 +1761,15 @@ struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num, sched_type == SCHED_POLICY_SINGLE) goto simple_ok; - sched_info = sched_ctx->sched_info; - for (i = 0; i < region_num; i++) { - for (j = 0; j < SCHED_MODE_BUTT; j++) { - sched_info[i].ctx_region[j] = - calloc(1, sizeof(struct sched_ctx_region) * type_num); - if (!sched_info[i].ctx_region[j]) - goto err_out; - } - } + ret = wd_sched_region_init(sched_ctx, type_num, numa_num); + if (ret) + goto ctx_out; simple_ok: sched_ctx->poll_func = func; sched_ctx->policy = sched_type; sched_ctx->type_num = type_num; - memset(sched_ctx->numa_map, -1, sizeof(int) * NUMA_NUM_NODES); + memset(sched_ctx->numa_map, -1, sizeof(int) * MAX_NUMA_NODES); sched->sched_init = sched_table[sched_type].sched_init; sched->pick_next_ctx = sched_table[sched_type].pick_next_ctx; @@ -902,7 +1779,9 @@ simple_ok: return sched; +ctx_out: + free(sched_ctx); err_out: - wd_sched_rr_release(sched); + free(sched); return NULL; } diff --git a/wd_util.c b/wd_util.c index a23152c..8e8260e 100644 --- a/wd_util.c +++ b/wd_util.c @@ -1323,6 +1323,7 @@ static int wd_sched_fill_table(struct wd_env_config_per_numa *config_numa, param.type = i; param.begin = ctx_table[mode][i].begin; param.end = ctx_table[mode][i].end; + param.ctx_prop = UADK_CTX_HW; ret = wd_sched_rr_instance(sched, ¶m); if (ret) return ret; @@ -2003,6 +2004,7 @@ static int wd_ctx_init_driver(struct wd_ctx_config_internal *config, void *priv = ctx_config->drv_priv; int ret; + WD_ERR("debug: call function: %s!\n", __func__); if (!driver) return 0; @@ -2057,7 +2059,8 @@ static void wd_ctx_uninit_driver(struct wd_ctx_config_internal *config, struct wd_alg_driver *driver = ctx_config->drv; void *priv = ctx_config->drv_priv; - if (!driver) + WD_ERR("debug: call function: %s!\n", __func__); + if (!driver || !priv) return; /* Prevent repeated uninitialization */ -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> After adapting the new heterogeneous hybrid acceleration function. The initialization of the device driver requires adaptation updates. In addition, the instruction acceleration algorithm driver needs to fully adapt to the synchronous and asynchronous mode of the uadk framework. Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- Makefile.am | 2 +- drv/hisi_comp.c | 3 ++ drv/hisi_dae_common.c | 3 ++ drv/hisi_hpre.c | 65 +++++++++++-------------------------- drv/hisi_sec.c | 3 ++ drv/hisi_udma.c | 3 ++ drv/isa_ce_sm3.c | 18 +++++++++- drv/isa_ce_sm4.c | 19 ++++++++++- include/drv/wd_digest_drv.h | 2 ++ include/drv/wd_ecc_drv.h | 2 +- include/wd_util.h | 4 +++ wd_ecc.c | 3 +- wd_util.c | 64 ++++++++++++++++++++++++++++++++++++ 13 files changed, 139 insertions(+), 52 deletions(-) diff --git a/Makefile.am b/Makefile.am index b38c5ce..e59fdb9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -101,7 +101,7 @@ libhisi_hpre_la_SOURCES=drv/hisi_hpre.c drv/hisi_qm_udrv.c \ if ARCH_ARM64 libisa_ce_la_SOURCES=arm_arch_ce.h drv/isa_ce_sm3.c drv/isa_ce_sm3_armv8.S isa_ce_sm3.h \ - drv/isa_ce_sm4.c drv/isa_ce_sm4_armv8.S drv/isa_ce_sm4.h + drv/isa_ce_sm4.c drv/isa_ce_sm4_armv8.S drv/isa_ce_sm4.h wd_util.c wd_util.h libisa_sve_la_SOURCES=drv/hash_mb/hash_mb.c wd_digest_drv.h drv/hash_mb/hash_mb.h \ drv/hash_mb/sm3_sve_common.S drv/hash_mb/sm3_mb_asimd_x1.S \ diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c index be16b83..50643d0 100644 --- a/drv/hisi_comp.c +++ b/drv/hisi_comp.c @@ -1431,6 +1431,9 @@ static int hisi_zip_init(void *conf, void *priv) memcpy(&zip_ctx->config, config, sizeof(struct wd_ctx_config_internal)); /* allocate qp for each context */ for (i = 0; i < config->ctx_num; i++) { + if (config->ctxs[i].ctx_type != UADK_CTX_HW || + !config->ctxs[i].ctx) + continue; h_ctx = config->ctxs[i].ctx; qm_priv.sqe_size = sizeof(struct hisi_zip_sqe); qm_priv.op_type = config->ctxs[i].op_type; diff --git a/drv/hisi_dae_common.c b/drv/hisi_dae_common.c index 216e424..74dc84f 100644 --- a/drv/hisi_dae_common.c +++ b/drv/hisi_dae_common.c @@ -327,6 +327,9 @@ int dae_init(void *conf, void *priv) qm_priv.sqe_size = sizeof(struct dae_sqe); /* Allocate qp for each context */ for (i = 0; i < config->ctx_num; i++) { + if (config->ctxs[i].ctx_type != UADK_CTX_HW || + !config->ctxs[i].ctx) + continue; h_ctx = config->ctxs[i].ctx; qm_priv.qp_mode = config->ctxs[i].ctx_mode; /* Setting the epoll en to 0 for ASYNC ctx */ diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index 7da8407..d8f3b53 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -133,9 +133,6 @@ struct hisi_hpre_ctx { struct wd_ctx_config_internal config; struct wd_mm_ops *mm_ops; handle_t rsv_mem_ctx; -}; - -struct hpre_ecc_ctx { __u32 enable_hpcore; }; @@ -656,6 +653,9 @@ static int hpre_init_qm_priv(struct wd_ctx_config_internal *config, qm_priv->sqe_size = sizeof(struct hisi_hpre_sqe); for (i = 0; i < config->ctx_num; i++) { + if (config->ctxs[i].ctx_type != UADK_CTX_HW || + !config->ctxs[i].ctx) + continue; h_ctx = config->ctxs[i].ctx; qm_priv->qp_mode = config->ctxs[i].ctx_mode; /* Setting the epoll en to 0 for ASYNC ctx */ @@ -1577,7 +1577,7 @@ static int u_is_in_p(struct wd_ecc_msg *msg) static int ecc_prepare_in(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg, void **data) { - struct hpre_ecc_ctx *ecc_ctx = msg->drv_cfg; + struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)msg->drv_cfg; int ret = -WD_EINVAL; switch (msg->req.op_type) { @@ -1590,11 +1590,11 @@ static int ecc_prepare_in(struct wd_ecc_msg *msg, ret = ecc_prepare_dh_gen_in(msg, hw_msg, data); break; case WD_ECXDH_GEN_KEY: - hw_msg->bd_rsv2 = ecc_ctx->enable_hpcore; + hw_msg->bd_rsv2 = hpre_ctx->enable_hpcore; ret = ecc_prepare_dh_gen_in(msg, hw_msg, data); break; case WD_ECXDH_COMPUTE_KEY: - hw_msg->bd_rsv2 = ecc_ctx->enable_hpcore; + hw_msg->bd_rsv2 = hpre_ctx->enable_hpcore; ret = ecc_prepare_dh_compute_in(msg, hw_msg, data); if (!ret && (msg->curve_id == WD_X25519 || msg->curve_id == WD_X448)) @@ -2817,39 +2817,6 @@ static int hpre_rsa_get_usage(void *param) return -WD_EACCES; } -static int ecc_sess_eops_init(struct wd_alg_driver *drv, void **params) -{ - struct hpre_ecc_ctx *ecc_ctx; - - if (!params) { - WD_ERR("invalid: extend ops init params address is NULL!\n"); - return -WD_EINVAL; - } - - if (*params) { - WD_ERR("invalid: extend ops init params repeatedly!\n"); - return -WD_EINVAL; - } - - ecc_ctx = calloc(1, sizeof(struct hpre_ecc_ctx)); - if (!ecc_ctx) - return -WD_ENOMEM; - - *params = ecc_ctx; - - return WD_SUCCESS; -} - -static void ecc_sess_eops_uninit(struct wd_alg_driver *drv, void *params) -{ - if (!params) { - WD_ERR("invalid: extend ops uninit params is NULL!\n"); - return; - } - - free(params); -} - static bool is_valid_hw_type(void *drv_priv) { struct hisi_hpre_ctx *hpre_ctx; @@ -2866,21 +2833,27 @@ static bool is_valid_hw_type(void *drv_priv) } static void ecc_sess_eops_params_cfg(struct wd_ecc_sess_setup *setup, - struct wd_ecc_curve *cv, void *drv_priv, void *params) + struct wd_ecc_curve *cv, void *priv) { __u8 data[SECP256R1_PARAM_SIZE] = SECG_P256_R1_PARAM; - struct hpre_ecc_ctx *ecc_ctx = params; + struct hisi_hpre_ctx *hpre_ctx; + struct hisi_qp *qp; __u32 key_size; int ret; - if (!is_valid_hw_type(drv_priv)) + if (unlikely(!priv)) return; - if (!ecc_ctx) { + hpre_ctx = (struct hisi_hpre_ctx *)priv; + if (!hpre_ctx) { WD_INFO("Info: eops config exits, but params is NULL!\n"); return; } + qp = (struct hisi_qp *)wd_ctx_get_priv(hpre_ctx->config.ctxs[0].ctx); + if (qp->q_info.hw_type < HISI_QM_API_VER3_BASE) + return; + if (strcmp(setup->alg, "ecdh")) return; @@ -2890,7 +2863,7 @@ static void ecc_sess_eops_params_cfg(struct wd_ecc_sess_setup *setup, ret = memcmp(data, cv->p.data, SECP256R1_PARAM_SIZE); if (!ret) - ecc_ctx->enable_hpcore = 1; + hpre_ctx->enable_hpcore = 1; } static int hpre_ecc_get_extend_ops(void *ops) @@ -2901,9 +2874,9 @@ static int hpre_ecc_get_extend_ops(void *ops) return -WD_EINVAL; ecc_ops->params = NULL; - ecc_ops->sess_init = ecc_sess_eops_init; + ecc_ops->sess_init = NULL; ecc_ops->eops_params_cfg = ecc_sess_eops_params_cfg; - ecc_ops->sess_uninit = ecc_sess_eops_uninit; + ecc_ops->sess_uninit = NULL; return WD_SUCCESS; } diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index fb9de2c..c2f73b1 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -3906,6 +3906,9 @@ static int hisi_sec_init(void *conf, void *priv) qm_priv.sqe_size = sizeof(struct hisi_sec_sqe); /* allocate qp for each context */ for (i = 0; i < config->ctx_num; i++) { + if (config->ctxs[i].ctx_type != UADK_CTX_HW || + !config->ctxs[i].ctx) + continue; h_ctx = config->ctxs[i].ctx; /* setting the type is 0 for sqc_type */ qm_priv.op_type = 0; diff --git a/drv/hisi_udma.c b/drv/hisi_udma.c index 5c8a743..62b83e7 100644 --- a/drv/hisi_udma.c +++ b/drv/hisi_udma.c @@ -461,6 +461,9 @@ static int udma_init(void *conf, void *priv) qm_priv.sqe_size = sizeof(struct udma_sqe); /* Allocate qp for each context */ for (i = 0; i < config->ctx_num; i++) { + if (config->ctxs[i].ctx_type != UADK_CTX_HW || + !config->ctxs[i].ctx) + continue; h_ctx = config->ctxs[i].ctx; qm_priv.qp_mode = config->ctxs[i].ctx_mode; /* Setting the epoll en to 0 for ASYNC ctx */ diff --git a/drv/isa_ce_sm3.c b/drv/isa_ce_sm3.c index 0ebaba5..9dbd0a8 100644 --- a/drv/isa_ce_sm3.c +++ b/drv/isa_ce_sm3.c @@ -17,7 +17,6 @@ #include "drv/isa_ce_sm3.h" #include "drv/wd_digest_drv.h" #include "wd_digest.h" -#include "wd_util.h" #define SM3_ALIGN_MASK 63U @@ -338,6 +337,7 @@ static int do_hmac_sm3_ce(struct wd_digest_msg *msg, __u8 *out_hmac) static int sm3_ce_drv_send(handle_t ctx, void *digest_msg) { + struct wd_soft_ctx *sfctx = (struct wd_soft_ctx *)ctx; struct wd_digest_msg *msg = (struct wd_digest_msg *)digest_msg; __u8 digest[SM3_DIGEST_SIZE] = {0}; int ret; @@ -347,6 +347,10 @@ static int sm3_ce_drv_send(handle_t ctx, void *digest_msg) return -WD_EINVAL; } + ret = wd_queue_is_busy(sfctx); + if (ret) + return ret; + if (msg->data_fmt == WD_SGL_BUF) { WD_ERR("invalid: SM3 CE driver do not support sgl data format!\n"); return -WD_EINVAL; @@ -368,11 +372,23 @@ static int sm3_ce_drv_send(handle_t ctx, void *digest_msg) ret = -WD_EINVAL; } + ret = wd_get_sqe_from_queue(sfctx, msg->tag); + if (ret) + return ret; + return ret; } static int sm3_ce_drv_recv(handle_t ctx, void *digest_msg) { + struct wd_soft_ctx *sfctx = (struct wd_soft_ctx *)ctx; + struct wd_digest_msg *msg = (struct wd_digest_msg *)digest_msg; + int ret; + + ret = wd_put_sqe_to_queue(sfctx, &msg->tag, &msg->result); + if (ret) + return ret; + return WD_SUCCESS; } diff --git a/drv/isa_ce_sm4.c b/drv/isa_ce_sm4.c index 504ef73..4c42693 100644 --- a/drv/isa_ce_sm4.c +++ b/drv/isa_ce_sm4.c @@ -324,15 +324,20 @@ static int sm4_xts_decrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rkey static int isa_ce_cipher_send(handle_t ctx, void *wd_msg) { + struct wd_soft_ctx *sfctx = (struct wd_soft_ctx *)ctx; struct wd_cipher_msg *msg = wd_msg; struct SM4_KEY rkey; int ret = 0; - if (!msg) { + if (!msg || !ctx) { WD_ERR("invalid: input sm4 msg is NULL!\n"); return -WD_EINVAL; } + ret = wd_queue_is_busy(sfctx); + if (ret) + return ret; + if (msg->data_fmt == WD_SGL_BUF) { WD_ERR("invalid: SM4 CE driver do not support sgl data format!\n"); return -WD_EINVAL; @@ -385,11 +390,23 @@ static int isa_ce_cipher_send(handle_t ctx, void *wd_msg) return -WD_EINVAL; } + ret = wd_get_sqe_from_queue(sfctx, msg->tag); + if (ret) + return ret; + return ret; } static int isa_ce_cipher_recv(handle_t ctx, void *wd_msg) { + struct wd_soft_ctx *sfctx = (struct wd_soft_ctx *)ctx; + struct wd_cipher_msg *msg = wd_msg; + int ret; + + ret = wd_put_sqe_to_queue(sfctx, &msg->tag, &msg->result); + if (ret) + return ret; + return 0; } diff --git a/include/drv/wd_digest_drv.h b/include/drv/wd_digest_drv.h index 12398f2..2711ab1 100644 --- a/include/drv/wd_digest_drv.h +++ b/include/drv/wd_digest_drv.h @@ -3,6 +3,8 @@ #ifndef __WD_DIGEST_DRV_H #define __WD_DIGEST_DRV_H +#include <asm/types.h> + #include "../wd_digest.h" #include "../wd_util.h" diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h index 98ff28c..899f593 100644 --- a/include/drv/wd_ecc_drv.h +++ b/include/drv/wd_ecc_drv.h @@ -182,7 +182,7 @@ 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_ecc_sess_setup *setup, - struct wd_ecc_curve *cv, void *drv_priv, void *params); + struct wd_ecc_curve *cv, void *priv); int (*sess_init)(struct wd_alg_driver *drv, void **params); void (*sess_uninit)(struct wd_alg_driver *drv, void *params); }; diff --git a/include/wd_util.h b/include/wd_util.h index 3be75d3..f226122 100644 --- a/include/wd_util.h +++ b/include/wd_util.h @@ -565,6 +565,10 @@ static inline void wd_ctx_spin_unlock(struct wd_ctx_internal *ctx, int type) int wd_mem_ops_init(handle_t h_ctx, struct wd_mm_ops *mm_ops, int mem_type); +int wd_queue_is_busy(struct wd_soft_ctx *sctx); +int wd_get_sqe_from_queue(struct wd_soft_ctx *sctx, __u32 tag_id); +int wd_put_sqe_to_queue(struct wd_soft_ctx *sctx, __u32 *tag_id, __u8 *result); + #ifdef __cplusplus } #endif diff --git a/wd_ecc.c b/wd_ecc.c index 900f36c..b7e5481 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -1205,8 +1205,7 @@ 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(setup, sess->key.cv, - wd_ecc_setting.priv, sess->eops.params); + sess->eops.eops_params_cfg(setup, sess->key.cv, wd_ecc_setting.priv); } } diff --git a/wd_util.c b/wd_util.c index 8e8260e..19bfcce 100644 --- a/wd_util.c +++ b/wd_util.c @@ -3363,3 +3363,67 @@ void wd_alg_attrs_uninit(struct wd_init_attrs *attrs) free(ctx_config); wd_sched_rr_release(alg_sched); } + +int wd_queue_is_busy(struct wd_soft_ctx *sctx) +{ + /* The queue is not used */ + if (sctx->run_num >= MAX_SOFT_QUEUE_LENGTH - 1) + return -WD_EBUSY; + + return 0; +} + +int wd_get_sqe_from_queue(struct wd_soft_ctx *sctx, __u32 tag_id) +{ + struct wd_soft_sqe *sqe = NULL; + + pthread_spin_lock(&sctx->slock); + sqe = &sctx->qfifo[sctx->head]; + if (!sqe->used && !sqe->complete) { // find the next not used sqe + sctx->head++; + if (unlikely(sctx->head == MAX_SOFT_QUEUE_LENGTH)) + sctx->head = 0; + + sqe->used = 1; + sqe->complete = 1; + sqe->id = tag_id; + sqe->result = 0; + __atomic_fetch_add(&sctx->run_num, 0x1, __ATOMIC_ACQUIRE); + pthread_spin_unlock(&sctx->slock); + } else { + pthread_spin_unlock(&sctx->slock); + return -WD_EBUSY; + } + + return 0; +} + +int wd_put_sqe_to_queue(struct wd_soft_ctx *sctx, __u32 *tag_id, __u8 *result) +{ + struct wd_soft_sqe *sqe = NULL; + + /* The queue is not used */ + if (sctx->run_num < 1) + return -WD_EAGAIN; + + if (pthread_spin_trylock(&sctx->rlock)) + return -WD_EAGAIN; + sqe = &sctx->qfifo[sctx->tail]; + if (sqe->used && sqe->complete) { // find a used sqe + sctx->tail++; + if (unlikely(sctx->tail == MAX_SOFT_QUEUE_LENGTH)) + sctx->tail = 0; + + *tag_id = sqe->id; + *result = sqe->result; + sqe->used = 0x0; + sqe->complete = 0x0; + __atomic_fetch_sub(&sctx->run_num, 0x1, __ATOMIC_ACQUIRE); + pthread_spin_unlock(&sctx->rlock); + } else { + pthread_spin_unlock(&sctx->rlock); + return -WD_EAGAIN; + } + + return 0; +} -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> After the uadk framework updates the heterogeneous scheduling function, the internal implementation functions of the aead algorithm need to be adapted and modified. Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- include/wd_internal.h | 1 + wd_aead.c | 158 ++++++++++++++++++++++-------------------- 2 files changed, 83 insertions(+), 76 deletions(-) diff --git a/include/wd_internal.h b/include/wd_internal.h index 59046ae..a67aaf5 100644 --- a/include/wd_internal.h +++ b/include/wd_internal.h @@ -66,6 +66,7 @@ struct wd_ctx_internal { __u16 sqn; pthread_spinlock_t lock; struct wd_alg_driver *drv; + void *extend_ops; void *drv_priv; }; diff --git a/wd_aead.c b/wd_aead.c index 43bda73..7ef7dca 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -32,7 +32,6 @@ struct wd_aead_setting { enum wd_status status; struct wd_ctx_config_internal config; struct wd_sched sched; - struct wd_alg_driver *driver; struct wd_async_msg_pool pool; void *priv; void *dlhandle; @@ -76,20 +75,16 @@ static void wd_aead_close_driver(int init_type) } if (wd_aead_setting.dlhandle) { - wd_release_drv(wd_aead_setting.driver); dlclose(wd_aead_setting.dlhandle); wd_aead_setting.dlhandle = NULL; } #else - wd_release_drv(wd_aead_setting.driver); hisi_sec2_remove(); #endif } static int wd_aead_open_driver(int init_type) { - struct wd_alg_driver *driver = NULL; - const char *alg_name = "gcm(aes)"; #ifndef WD_STATIC_DRV char lib_path[PATH_MAX]; int ret; @@ -123,14 +118,6 @@ static int wd_aead_open_driver(int init_type) if (init_type == WD_TYPE_V2) return WD_SUCCESS; #endif - driver = wd_request_drv(alg_name, false); - if (!driver) { - wd_aead_close_driver(WD_TYPE_V1); - WD_ERR("failed to get %s driver support\n", alg_name); - return -WD_EINVAL; - } - - wd_aead_setting.driver = driver; return WD_SUCCESS; } @@ -335,7 +322,7 @@ static struct wd_aead_sess *check_and_init_sess(struct wd_aead_sess_setup *setup sess->dalg = setup->dalg; sess->dmode = setup->dmode; - ret = wd_drv_alg_support(sess->alg_name, wd_aead_setting.driver); + ret = wd_drv_alg_support(sess->alg_name, &wd_aead_setting.config); if (!ret) { WD_ERR("failed to support this algorithm: %s!\n", sess->alg_name); free(sess); @@ -420,18 +407,38 @@ static void cleanup_session(struct wd_aead_sess *sess) static int wd_aead_sess_eops_init(struct wd_aead_sess *sess) { + struct wd_ctx_config_internal *config = &wd_aead_setting.config; + struct wd_aead_extend_ops *eops; + struct wd_alg_driver *drv; int ret; + __u32 i; - if (sess->eops.eops_aiv_init) { - if (!sess->eops.eops_aiv_uninit) { - WD_ERR("failed to get aead extend ops free in session!\n"); - return -WD_EINVAL; - } - ret = sess->eops.eops_aiv_init(wd_aead_setting.driver, &sess->mm_ops, - &sess->eops.params); - if (ret) { - WD_ERR("failed to init aead extend ops params in session!\n"); - return ret; + for (i = 0; i < config->ctx_num; i++) { + drv = config->ctxs[i].drv; + if (!drv->get_extend_ops) + continue; + + ret = drv->get_extend_ops(config->ctxs[i].extend_ops); + if (!ret && config->ctxs[i].extend_ops) { + eops = config->ctxs[i].extend_ops; + + if (!eops->eops_aiv_init) + continue; + + if (!sess->eops.eops_aiv_uninit) { + WD_ERR("failed to get aead extend ops free in session!\n"); + return -WD_EINVAL; + } + ret = sess->eops.eops_aiv_init(drv, &sess->mm_ops, + &sess->eops.params); + if (ret) { + WD_ERR("failed to init aead extend ops params in session!\n"); + return ret; + } + + memcpy(&sess->eops, eops, sizeof(*eops)); + sess->eops.params = drv; + break; } } @@ -440,8 +447,11 @@ static int wd_aead_sess_eops_init(struct wd_aead_sess *sess) static void wd_aead_sess_eops_uninit(struct wd_aead_sess *sess) { + struct wd_alg_driver *drv; + if (sess->eops.eops_aiv_uninit) { - sess->eops.eops_aiv_uninit(wd_aead_setting.driver, &sess->mm_ops, + drv = sess->eops.params; + sess->eops.eops_aiv_uninit(drv, &sess->mm_ops, sess->eops.params); sess->eops.params = NULL; } @@ -461,14 +471,6 @@ handle_t wd_aead_alloc_sess(struct wd_aead_sess_setup *setup) return (handle_t)0; } - if (wd_aead_setting.driver->get_extend_ops) { - ret = wd_aead_setting.driver->get_extend_ops(&sess->eops); - if (ret) { - WD_ERR("failed to get aead sess extend ops!\n"); - goto sess_err; - } - } - ret = wd_aead_sess_eops_init(sess); if (ret) { WD_ERR("failed to init aead sess extend eops!\n"); @@ -603,16 +605,9 @@ static int wd_aead_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc if (ret < 0) goto out_clear_sched; - ret = wd_alg_init_driver(&wd_aead_setting.config, - wd_aead_setting.driver, - &wd_aead_setting.priv); - if (ret) - goto out_clear_pool; - + wd_aead_setting.priv = STATUS_ENABLE; return 0; -out_clear_pool: - wd_uninit_async_request_pool(&wd_aead_setting.pool); out_clear_sched: wd_clear_sched(&wd_aead_setting.sched); out_clear_ctx_config: @@ -621,6 +616,13 @@ out_clear_ctx_config: return ret; } +static void wd_aead_uninit_nolock(void) +{ + wd_uninit_async_request_pool(&wd_aead_setting.pool); + wd_clear_sched(&wd_aead_setting.sched); + wd_aead_setting.priv = NULL; +} + int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched) { int ret; @@ -643,10 +645,21 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_close_driver; + ret = wd_ctx_drv_config("gcm(aes)", &wd_aead_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_aead_setting.config); + if (ret) + goto out_drv_deconfig; wd_alg_set_init(&wd_aead_setting.status); return 0; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_aead_setting.config); +out_uninit_nolock: + wd_aead_uninit_nolock(); out_close_driver: wd_aead_close_driver(WD_TYPE_V1); out_clear_init: @@ -654,20 +667,14 @@ out_clear_init: return ret; } -static void wd_aead_uninit_nolock(void) -{ - wd_uninit_async_request_pool(&wd_aead_setting.pool); - wd_clear_sched(&wd_aead_setting.sched); - wd_alg_uninit_driver(&wd_aead_setting.config, - wd_aead_setting.driver, - &wd_aead_setting.priv); -} - void wd_aead_uninit(void) { if (!wd_aead_setting.priv) return; + wd_alg_uninit_driver_nw(&wd_aead_setting.config); + wd_ctx_drv_deconfig(&wd_aead_setting.config); + wd_aead_uninit_nolock(); wd_aead_close_driver(WD_TYPE_V1); wd_alg_clear_init(&wd_aead_setting.status); @@ -717,38 +724,26 @@ int wd_aead_init2_(char *alg, __u32 sched_type, int task_type, while (ret != 0) { memset(&wd_aead_setting.config, 0, sizeof(struct wd_ctx_config_internal)); - - /* Get alg driver and dev name */ - wd_aead_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_aead_setting.driver) { - WD_ERR("failed to bind %s driver.\n", alg); - goto out_dlopen; - } - + /* Init ctx param and prepare for ctx request */ aead_ctx_params.ctx_set_num = aead_ctx_num; - ret = wd_ctx_param_init(&aead_ctx_params, ctx_params, - wd_aead_setting.driver, WD_AEAD_TYPE, - WD_DIGEST_CIPHER_DECRYPTION + 1); + ret = wd_ctx_param_init_nw(&aead_ctx_params, ctx_params, + alg, task_type, WD_AEAD_TYPE, WD_DIGEST_CIPHER_DECRYPTION + 1); if (ret) { if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_aead_setting.driver); - wd_alg_drv_unbind(wd_aead_setting.driver); continue; } - goto out_driver; + goto out_dlclose; } (void)strcpy(wd_aead_init_attrs.alg, alg); wd_aead_init_attrs.sched_type = sched_type; - wd_aead_init_attrs.driver = wd_aead_setting.driver; + wd_aead_init_attrs.task_type = task_type; wd_aead_init_attrs.ctx_params = &aead_ctx_params; wd_aead_init_attrs.alg_init = wd_aead_init_nolock; wd_aead_init_attrs.alg_poll_ctx = wd_aead_poll_ctx; ret = wd_alg_attrs_init(&wd_aead_init_attrs); if (ret) { if (ret == -WD_ENODEV) { - wd_disable_drv(wd_aead_setting.driver); - wd_alg_drv_unbind(wd_aead_setting.driver); wd_ctx_param_uninit(&aead_ctx_params); continue; } @@ -756,16 +751,27 @@ int wd_aead_init2_(char *alg, __u32 sched_type, int task_type, goto out_params_uninit; } } + ret = wd_ctx_drv_config(alg, &wd_aead_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_aead_setting.config); + if (ret) + goto out_drv_deconfig; + wd_alg_set_init(&wd_aead_setting.status); wd_ctx_param_uninit(&aead_ctx_params); return 0; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_aead_setting.config); +out_uninit_nolock: + wd_aead_uninit_nolock(); + wd_alg_attrs_uninit(&wd_aead_init_attrs); out_params_uninit: wd_ctx_param_uninit(&aead_ctx_params); -out_driver: - wd_alg_drv_unbind(wd_aead_setting.driver); -out_dlopen: +out_dlclose: wd_aead_close_driver(WD_TYPE_V2); out_uninit: wd_alg_clear_init(&wd_aead_setting.status); @@ -777,9 +783,9 @@ void wd_aead_uninit2(void) if (!wd_aead_setting.priv) return; + wd_ctx_drv_deconfig(&wd_aead_setting.config); 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); wd_alg_clear_init(&wd_aead_setting.status); } @@ -862,8 +868,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_msg_handle msg_handle; int ret; - msg_handle.send = wd_aead_setting.driver->send; - msg_handle.recv = wd_aead_setting.driver->recv; + msg_handle.send = ctx->drv->send; + msg_handle.recv = ctx->drv->recv; pthread_spin_lock(&ctx->lock); ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL, @@ -936,13 +942,13 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req) idx, (void **)&msg); if (unlikely(msg_id < 0)) { WD_ERR("failed to get msg from pool!\n"); - return msg_id; + return -WD_EBUSY; } fill_request_msg(msg, req, sess); msg->tag = msg_id; - ret = wd_aead_setting.driver->send(ctx->ctx, msg); + ret = ctx->drv->send(ctx->ctx, msg); if (unlikely(ret < 0)) { if (ret != -WD_EBUSY) WD_ERR("failed to send BD, hw is err!\n"); @@ -992,7 +998,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx; do { - ret = wd_aead_setting.driver->recv(ctx->ctx, &resp_msg); + ret = ctx->drv->recv(ctx->ctx, &resp_msg); if (ret == -WD_EAGAIN) { return ret; } else if (ret < 0) { -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> After the uadk framework updates the heterogeneous scheduling function, the internal implementation functions of the hash-agg algorithm need to be adapted and modified. Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- wd_agg.c | 173 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 103 insertions(+), 70 deletions(-) diff --git a/wd_agg.c b/wd_agg.c index 66e9e0f..ebc6e31 100644 --- a/wd_agg.c +++ b/wd_agg.c @@ -32,7 +32,6 @@ struct wd_agg_setting { struct wd_ctx_config_internal config; struct wd_sched sched; struct wd_async_msg_pool pool; - struct wd_alg_driver *driver; void *priv; void *dlhandle; void *dlh_list; @@ -78,7 +77,6 @@ static void wd_agg_close_driver(void) wd_dlclose_drv(wd_agg_setting.dlh_list); wd_agg_setting.dlh_list = NULL; #else - wd_release_drv(wd_agg_setting.driver); hisi_dae_remove(); #endif } @@ -354,29 +352,71 @@ out_key: static int wd_agg_init_sess_priv(struct wd_agg_sess *sess, struct wd_agg_sess_setup *setup) { - int ret; + struct wd_ctx_config_internal *config = &wd_agg_setting.config; + struct wd_alg_driver *drv; + struct wd_agg_ops *eops; + int ret, valid = 0; + __u32 i; - if (sess->ops.sess_init) { - if (!sess->ops.sess_uninit) { - WD_ERR("failed to get session uninit ops!\n"); - return -WD_EINVAL; - } - ret = sess->ops.sess_init(setup, &sess->priv); - if (ret) { - WD_ERR("failed to init session priv!\n"); - return ret; + for (i = 0; i < config->ctx_num; i++) { + drv = config->ctxs[i].drv; + if (!drv->get_extend_ops) + continue; + + ret = drv->get_extend_ops(config->ctxs[i].extend_ops); + if (!ret && config->ctxs[i].extend_ops) { + valid++; + eops = config->ctxs[i].extend_ops; + + if (eops->sess_init) { + if (!eops->sess_uninit) { + WD_ERR("failed to get session uninit ops!\n"); + return -WD_EINVAL; + } + ret = eops->sess_init(setup, &sess->priv); + if (ret) { + WD_ERR("failed to init session priv!\n"); + return ret; + } + } + + if (eops->get_row_size) { + ret = eops->get_row_size(drv, sess->priv); + if (ret <= 0) { + if (eops->sess_uninit) + eops->sess_uninit(drv, sess->priv); + WD_ERR("failed to get hash table row size: %d!\n", ret); + return ret; + } + /* This needs to be executed only once. */ + sess->hash_table.table_row_size = ret; + } } } - if (sess->ops.get_row_size) { - ret = sess->ops.get_row_size(wd_agg_setting.driver, sess->priv); - if (ret <= 0) { - if (sess->ops.sess_uninit) - sess->ops.sess_uninit(wd_agg_setting.driver, sess->priv); - WD_ERR("failed to get hash table row size: %d!\n", ret); - return -WD_EINVAL; - } - sess->hash_table.table_row_size = ret; + if (!valid) { + WD_ERR("failed to get agg extend ops!\n"); + return -WD_EINVAL; + } + + return WD_SUCCESS; +} + +static int wd_agg_uninit_sess_priv(struct wd_agg_sess *sess) +{ + struct wd_ctx_config_internal *config = &wd_agg_setting.config; + struct wd_agg_ops *eops; + __u32 i; + int ret; + + for (i = 0; i < config->ctx_num; i++) { + /* At this point, extends_ops has completed its initialization. */ + eops = config->ctxs[i].extend_ops; + if (!eops) + continue; + + if (eops->sess_uninit) + eops->sess_uninit(config->ctxs[i].drv, sess->priv); } return WD_SUCCESS; @@ -401,7 +441,7 @@ handle_t wd_agg_alloc_sess(struct wd_agg_sess_setup *setup) sess->agg_conf.out_cols_num = out_agg_cols_num; sess->alg_name = wd_agg_alg_name; - ret = wd_drv_alg_support(sess->alg_name, wd_agg_setting.driver); + ret = wd_drv_alg_support(sess->alg_name, &wd_agg_setting.config); if (!ret) { WD_ERR("failed to support agg algorithm: %s!\n", sess->alg_name); goto free_sess; @@ -415,14 +455,6 @@ handle_t wd_agg_alloc_sess(struct wd_agg_sess_setup *setup) goto free_sess; } - if (wd_agg_setting.driver->get_extend_ops) { - ret = wd_agg_setting.driver->get_extend_ops(&sess->ops); - if (ret) { - WD_ERR("failed to get agg extend ops!\n"); - goto free_key; - } - } - ret = wd_agg_init_sess_priv(sess, setup); if (ret) goto free_key; @@ -436,8 +468,7 @@ handle_t wd_agg_alloc_sess(struct wd_agg_sess_setup *setup) return (handle_t)sess; uninit_priv: - if (sess->ops.sess_uninit) - sess->ops.sess_uninit(wd_agg_setting.driver, sess->priv); + wd_agg_uninit_sess_priv(sess); free_key: free(sess->sched_key); free_sess: @@ -458,8 +489,7 @@ void wd_agg_free_sess(handle_t h_sess) free(sess->agg_conf.cols_info); free(sess->key_conf.data_size); - if (sess->ops.sess_uninit) - sess->ops.sess_uninit(wd_agg_setting.driver, sess->priv); + wd_agg_uninit_sess_priv(sess); if (sess->sched_key) free(sess->sched_key); @@ -509,8 +539,11 @@ static int wd_agg_check_sess_state(struct wd_agg_sess *sess, enum wd_agg_sess_st int wd_agg_set_hash_table(handle_t h_sess, struct wd_dae_hash_table *info) { struct wd_agg_sess *sess = (struct wd_agg_sess *)h_sess; + struct wd_ctx_config_internal *config = &wd_agg_setting.config; struct wd_dae_hash_table *hash_table, *rehash_table; enum wd_agg_sess_state expected; + struct wd_agg_ops *eops; + __u32 i; int ret; if (!sess || !info) { @@ -551,17 +584,23 @@ int wd_agg_set_hash_table(handle_t h_sess, struct wd_dae_hash_table *info) memcpy(rehash_table, hash_table, sizeof(struct wd_dae_hash_table)); memcpy(hash_table, info, sizeof(struct wd_dae_hash_table)); - if (sess->ops.hash_table_init) { - ret = sess->ops.hash_table_init(wd_agg_setting.driver, hash_table, sess->priv); - if (ret) { + for (i = 0; i < config->ctx_num; i++) { + /* At this point, extends_ops has completed its initialization process. */ + eops = config->ctxs[i].extend_ops; + if (!eops) + continue; + + /* Any single execution successful, exit immediately. */ + if (eops->hash_table_init) { + ret = eops->hash_table_init(config->ctxs[i].drv, hash_table, sess->priv); + if (!ret) + return WD_SUCCESS; + memcpy(hash_table, rehash_table, sizeof(struct wd_dae_hash_table)); memset(rehash_table, 0, sizeof(struct wd_dae_hash_table)); - goto out; } } - return WD_SUCCESS; - out: __atomic_store_n(&sess->state, expected, __ATOMIC_RELEASE); return ret; @@ -595,15 +634,10 @@ 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, - &wd_agg_setting.priv); - if (ret) - goto out_clear_pool; + wd_agg_setting.priv = STATUS_ENABLE; return WD_SUCCESS; -out_clear_pool: - wd_uninit_async_request_pool(&wd_agg_setting.pool); out_clear_sched: wd_clear_sched(&wd_agg_setting.sched); out_clear_ctx_config: @@ -621,12 +655,9 @@ static int wd_agg_alg_uninit(void) /* Uninit async request pool */ wd_uninit_async_request_pool(&wd_agg_setting.pool); - /* Unset config, sched, driver */ wd_clear_sched(&wd_agg_setting.sched); - - wd_alg_uninit_driver(&wd_agg_setting.config, wd_agg_setting.driver, - &wd_agg_setting.priv); + wd_agg_setting.priv = NULL; return WD_SUCCESS; } @@ -664,20 +695,12 @@ int wd_agg_init(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params while (ret != 0) { memset(&wd_agg_setting.config, 0, sizeof(struct wd_ctx_config_internal)); - /* Get alg driver and dev name */ - wd_agg_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_agg_setting.driver) { - WD_ERR("failed to bind %s driver.\n", alg); - goto out_dlopen; - } - + /* Init ctx param and prepare for ctx request */ agg_ctx_params.ctx_set_num = &agg_ctx_num; - ret = wd_ctx_param_init(&agg_ctx_params, ctx_params, wd_agg_setting.driver, + ret = wd_ctx_param_init_nw(&agg_ctx_params, ctx_params, alg, task_type, WD_AGG_TYPE, 1); if (ret) { if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_agg_setting.driver); - wd_alg_drv_unbind(wd_agg_setting.driver); continue; } goto out_driver; @@ -685,15 +708,13 @@ int wd_agg_init(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params (void)strcpy(wd_agg_init_attrs.alg, alg); wd_agg_init_attrs.sched_type = sched_type; - wd_agg_init_attrs.driver = wd_agg_setting.driver; + wd_agg_init_attrs.task_type = task_type; wd_agg_init_attrs.ctx_params = &agg_ctx_params; wd_agg_init_attrs.alg_init = wd_agg_alg_init; wd_agg_init_attrs.alg_poll_ctx = wd_agg_poll_ctx; ret = wd_alg_attrs_init(&wd_agg_init_attrs); if (ret) { if (ret == -WD_ENODEV) { - wd_disable_drv(wd_agg_setting.driver); - wd_alg_drv_unbind(wd_agg_setting.driver); wd_ctx_param_uninit(&agg_ctx_params); continue; } @@ -701,17 +722,27 @@ int wd_agg_init(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params goto out_params_uninit; } } + ret = wd_ctx_drv_config(alg, &wd_agg_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_agg_setting.config); + if (ret) + goto out_drv_deconfig; wd_alg_set_init(&wd_agg_setting.status); wd_ctx_param_uninit(&agg_ctx_params); return WD_SUCCESS; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_agg_setting.config); +out_uninit_nolock: + wd_agg_alg_uninit(); + wd_alg_attrs_uninit(&wd_agg_init_attrs); out_params_uninit: wd_ctx_param_uninit(&agg_ctx_params); out_driver: - wd_alg_drv_unbind(wd_agg_setting.driver); -out_dlopen: wd_agg_close_driver(); out_uninit: wd_alg_clear_init(&wd_agg_setting.status); @@ -726,8 +757,10 @@ void wd_agg_uninit(void) if (ret) return; + wd_alg_uninit_driver_nw(&wd_agg_setting.config); + wd_ctx_drv_deconfig(&wd_agg_setting.config); wd_alg_attrs_uninit(&wd_agg_init_attrs); - wd_alg_drv_unbind(wd_agg_setting.driver); + wd_agg_close_driver(); wd_alg_clear_init(&wd_agg_setting.status); } @@ -1099,8 +1132,8 @@ static int wd_agg_sync_job(struct wd_agg_sess *sess, struct wd_agg_req *req, wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx; - msg_handle.send = wd_agg_setting.driver->send; - msg_handle.recv = wd_agg_setting.driver->recv; + msg_handle.send = ctx->drv->send; + msg_handle.recv = ctx->drv->recv; pthread_spin_lock(&ctx->lock); ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL, config->epoll_en); @@ -1204,7 +1237,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_agg_setting.driver->send(ctx->ctx, msg); + ret = ctx->drv->send(ctx->ctx, msg); if (unlikely(ret < 0)) { if (ret != -WD_EBUSY) WD_ERR("wd agg async send err!\n"); @@ -1543,7 +1576,7 @@ static int wd_agg_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx; do { - ret = wd_agg_setting.driver->recv(ctx->ctx, &resp_msg); + ret = ctx->drv->recv(ctx->ctx, &resp_msg); if (ret == -WD_EAGAIN) { return ret; } else if (unlikely(ret < 0)) { -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> After the uadk framework updates the heterogeneous scheduling function, the internal implementation functions of the cipher algorithm need to be adapted and modified. Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- wd_cipher.c | 97 +++++++++++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 52 deletions(-) diff --git a/wd_cipher.c b/wd_cipher.c index 53733a4..af0173a 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -52,7 +52,6 @@ struct wd_cipher_setting { struct wd_ctx_config_internal config; struct wd_sched sched; struct wd_async_msg_pool pool; - struct wd_alg_driver *driver; void *priv; void *dlhandle; void *dlh_list; @@ -84,20 +83,16 @@ static void wd_cipher_close_driver(int init_type) } if (wd_cipher_setting.dlhandle) { - wd_release_drv(wd_cipher_setting.driver); dlclose(wd_cipher_setting.dlhandle); wd_cipher_setting.dlhandle = NULL; } #else - wd_release_drv(wd_cipher_setting.driver); hisi_sec2_remove(); #endif } static int wd_cipher_open_driver(int init_type) { - struct wd_alg_driver *driver = NULL; - const char *alg_name = "cbc(aes)"; #ifndef WD_STATIC_DRV char lib_path[PATH_MAX]; int ret; @@ -131,15 +126,6 @@ static int wd_cipher_open_driver(int init_type) if (init_type == WD_TYPE_V2) return WD_SUCCESS; #endif - driver = wd_request_drv(alg_name, false); - if (!driver) { - wd_cipher_close_driver(WD_TYPE_V1); - WD_ERR("failed to get %s driver support\n", alg_name); - return -WD_EINVAL; - } - - wd_cipher_setting.driver = driver; - return WD_SUCCESS; } @@ -302,7 +288,7 @@ handle_t wd_cipher_alloc_sess(struct wd_cipher_sess_setup *setup) } sess->alg_name = wd_cipher_alg_name[setup->alg][setup->mode]; - ret = wd_drv_alg_support(sess->alg_name, wd_cipher_setting.driver); + ret = wd_drv_alg_support(sess->alg_name, &wd_cipher_setting.config); if (!ret) { WD_ERR("failed to support this algorithm: %s!\n", sess->alg_name); goto free_sess; @@ -379,16 +365,10 @@ static int wd_cipher_common_init(struct wd_ctx_config *config, if (ret < 0) goto out_clear_sched; - ret = wd_alg_init_driver(&wd_cipher_setting.config, - wd_cipher_setting.driver, - &wd_cipher_setting.priv); - if (ret) - goto out_clear_pool; + wd_cipher_setting.priv = STATUS_ENABLE; return 0; -out_clear_pool: - wd_uninit_async_request_pool(&wd_cipher_setting.pool); out_clear_sched: wd_clear_sched(&wd_cipher_setting.sched); out_clear_ctx_config: @@ -408,10 +388,7 @@ static int wd_cipher_common_uninit(void) /* unset config, sched, driver */ wd_clear_sched(&wd_cipher_setting.sched); - - wd_alg_uninit_driver(&wd_cipher_setting.config, - wd_cipher_setting.driver, - &wd_cipher_setting.priv); + wd_cipher_setting.priv = NULL; return 0; } @@ -438,10 +415,22 @@ int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_close_driver; + ret = wd_ctx_drv_config("ecb(aes)", &wd_cipher_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_cipher_setting.config); + if (ret) + goto out_drv_deconfig; + wd_alg_set_init(&wd_cipher_setting.status); return 0; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_cipher_setting.config); +out_uninit_nolock: + wd_cipher_common_uninit(); out_close_driver: wd_cipher_close_driver(WD_TYPE_V1); out_clear_init: @@ -453,6 +442,9 @@ void wd_cipher_uninit(void) { int ret; + wd_alg_uninit_driver_nw(&wd_cipher_setting.config); + wd_ctx_drv_deconfig(&wd_cipher_setting.config); + ret = wd_cipher_common_uninit(); if (ret) return; @@ -493,37 +485,26 @@ int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_p while (ret != 0) { memset(&wd_cipher_setting.config, 0, sizeof(struct wd_ctx_config_internal)); - /* Get alg driver and dev name */ - wd_cipher_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_cipher_setting.driver) { - WD_ERR("failed to bind %s driver.\n", alg); - goto out_dlopen; - } - + /* Init ctx param and prepare for ctx request */ cipher_ctx_params.ctx_set_num = cipher_ctx_num; - ret = wd_ctx_param_init(&cipher_ctx_params, ctx_params, - wd_cipher_setting.driver, - WD_CIPHER_TYPE, WD_CIPHER_DECRYPTION + 1); + ret = wd_ctx_param_init_nw(&cipher_ctx_params, ctx_params, + alg, task_type, WD_CIPHER_TYPE, WD_CIPHER_DECRYPTION + 1); if (ret) { if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_cipher_setting.driver); - wd_alg_drv_unbind(wd_cipher_setting.driver); continue; } - goto out_driver; + goto out_dlclose; } (void)strcpy(wd_cipher_init_attrs.alg, alg); wd_cipher_init_attrs.sched_type = sched_type; - wd_cipher_init_attrs.driver = wd_cipher_setting.driver; + wd_cipher_init_attrs.task_type = task_type; wd_cipher_init_attrs.ctx_params = &cipher_ctx_params; wd_cipher_init_attrs.alg_init = wd_cipher_common_init; wd_cipher_init_attrs.alg_poll_ctx = wd_cipher_poll_ctx; ret = wd_alg_attrs_init(&wd_cipher_init_attrs); if (ret) { if (ret == -WD_ENODEV) { - wd_disable_drv(wd_cipher_setting.driver); - wd_alg_drv_unbind(wd_cipher_setting.driver); wd_ctx_param_uninit(&cipher_ctx_params); continue; } @@ -532,16 +513,28 @@ int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_p } } + WD_ERR("ctxs numbers: %u.\n", wd_cipher_setting.config.ctx_num); + ret = wd_ctx_drv_config(alg, &wd_cipher_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_cipher_setting.config); + if (ret) + goto out_drv_deconfig; + wd_alg_set_init(&wd_cipher_setting.status); wd_ctx_param_uninit(&cipher_ctx_params); return 0; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_cipher_setting.config); +out_uninit_nolock: + wd_cipher_common_uninit(); + wd_alg_attrs_uninit(&wd_cipher_init_attrs); out_params_uninit: wd_ctx_param_uninit(&cipher_ctx_params); -out_driver: - wd_alg_drv_unbind(wd_cipher_setting.driver); -out_dlopen: +out_dlclose: wd_cipher_close_driver(WD_TYPE_V2); out_uninit: wd_alg_clear_init(&wd_cipher_setting.status); @@ -552,12 +545,12 @@ void wd_cipher_uninit2(void) { int ret; + wd_ctx_drv_deconfig(&wd_cipher_setting.config); ret = wd_cipher_common_uninit(); if (ret) return; wd_alg_attrs_uninit(&wd_cipher_init_attrs); - wd_alg_drv_unbind(wd_cipher_setting.driver); wd_cipher_close_driver(WD_TYPE_V2); wd_alg_clear_init(&wd_cipher_setting.status); } @@ -718,13 +711,13 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_msg_handle msg_handle; int ret; - msg_handle.send = wd_cipher_setting.driver->send; - msg_handle.recv = wd_cipher_setting.driver->recv; + msg_handle.send = ctx->drv->send; + msg_handle.recv = ctx->drv->recv; - wd_ctx_spin_lock(ctx, wd_cipher_setting.driver->calc_type); + wd_ctx_spin_lock(ctx, UADK_ALG_HW); 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); + wd_ctx_spin_unlock(ctx, UADK_ALG_HW); return ret; } @@ -798,7 +791,7 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req) fill_request_msg(msg, req, sess); msg->tag = msg_id; - ret = wd_cipher_setting.driver->send(ctx->ctx, msg); + ret = ctx->drv->send(ctx->ctx, msg); if (unlikely(ret < 0)) { if (ret != -WD_EBUSY) WD_ERR("wd cipher async send err!\n"); @@ -848,7 +841,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx; do { - ret = wd_cipher_setting.driver->recv(ctx->ctx, &resp_msg); + ret = ctx->drv->recv(ctx->ctx, &resp_msg); if (ret == -WD_EAGAIN) return ret; else if (ret < 0) { -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> After the uadk framework updates the heterogeneous scheduling function, the internal implementation functions of the comp algorithm need to be adapted and modified. Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- include/drv/wd_comp_drv.h | 1 + include/wd_comp.h | 3 +- wd_comp.c | 91 ++++++++++++++++++--------------------- 3 files changed, 46 insertions(+), 49 deletions(-) diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h index 2311d79..93df870 100644 --- a/include/drv/wd_comp_drv.h +++ b/include/drv/wd_comp_drv.h @@ -7,6 +7,7 @@ #include <pthread.h> #include <linux/types.h> +#include "../wd_alg_common.h" #include "../wd_comp.h" #include "../wd_util.h" diff --git a/include/wd_comp.h b/include/wd_comp.h index 5d09536..8579f93 100644 --- a/include/wd_comp.h +++ b/include/wd_comp.h @@ -135,7 +135,8 @@ void wd_comp_uninit(void); * * Return 0 if succeed and others if fail. */ -int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params); +int wd_comp_init2_(const char *alg, __u32 sched_type, int task_type, + struct wd_ctx_params *ctx_params); #define wd_comp_init2(alg, sched_type, task_type) \ wd_comp_init2_(alg, sched_type, task_type, NULL) diff --git a/wd_comp.c b/wd_comp.c index be08ee8..596979b 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -50,7 +50,6 @@ struct wd_comp_setting { struct wd_ctx_config_internal config; struct wd_sched sched; struct wd_async_msg_pool pool; - struct wd_alg_driver *driver; void *priv; void *dlhandle; void *dlh_list; @@ -69,20 +68,16 @@ static void wd_comp_close_driver(int init_type) } if (wd_comp_setting.dlhandle) { - wd_release_drv(wd_comp_setting.driver); dlclose(wd_comp_setting.dlhandle); wd_comp_setting.dlhandle = NULL; } #else - wd_release_drv(wd_comp_setting.driver); hisi_zip_remove(); #endif } static int wd_comp_open_driver(int init_type) { - struct wd_alg_driver *driver = NULL; - const char *alg_name = "zlib"; #ifndef WD_STATIC_DRV char lib_path[PATH_MAX]; int ret; @@ -116,14 +111,6 @@ static int wd_comp_open_driver(int init_type) if (init_type == WD_TYPE_V2) return WD_SUCCESS; #endif - driver = wd_request_drv(alg_name, false); - if (!driver) { - wd_comp_close_driver(WD_TYPE_V1); - WD_ERR("failed to get %s driver support\n", alg_name); - return -WD_EINVAL; - } - - wd_comp_setting.driver = driver; return WD_SUCCESS; } @@ -152,8 +139,7 @@ static int wd_comp_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc { int ret; - ret = wd_set_epoll_en("WD_COMP_EPOLL_EN", - &wd_comp_setting.config.epoll_en); + ret = wd_set_epoll_en("WD_COMP_EPOLL_EN", &wd_comp_setting.config.epoll_en); if (ret < 0) return ret; @@ -172,16 +158,10 @@ static int wd_comp_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc if (ret < 0) goto out_clear_sched; - ret = wd_alg_init_driver(&wd_comp_setting.config, - wd_comp_setting.driver, - &wd_comp_setting.priv); - if (ret) - goto out_clear_pool; + wd_comp_setting.priv = STATUS_ENABLE; return 0; -out_clear_pool: - wd_uninit_async_request_pool(&wd_comp_setting.pool); out_clear_sched: wd_clear_sched(&wd_comp_setting.sched); out_clear_ctx_config: @@ -202,9 +182,7 @@ static int wd_comp_uninit_nolock(void) /* Unset config, sched, driver */ wd_clear_sched(&wd_comp_setting.sched); - wd_alg_uninit_driver(&wd_comp_setting.config, - wd_comp_setting.driver, - &wd_comp_setting.priv); + wd_comp_setting.priv = NULL; return 0; } @@ -231,10 +209,22 @@ int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_clear_driver; + ret = wd_ctx_drv_config("zlib", &wd_comp_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_comp_setting.config); + if (ret) + goto out_drv_deconfig; + wd_alg_set_init(&wd_comp_setting.status); return 0; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_comp_setting.config); +out_uninit_nolock: + wd_comp_uninit_nolock(); out_clear_driver: wd_comp_close_driver(WD_TYPE_V1); out_clear_init: @@ -246,6 +236,9 @@ void wd_comp_uninit(void) { int ret; + wd_alg_uninit_driver_nw(&wd_comp_setting.config); + wd_ctx_drv_deconfig(&wd_comp_setting.config); + ret = wd_comp_uninit_nolock(); if (ret) return; @@ -254,7 +247,8 @@ void wd_comp_uninit(void) wd_alg_clear_init(&wd_comp_setting.status); } -int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params *ctx_params) +int wd_comp_init2_(const char *alg, __u32 sched_type, int task_type, + struct wd_ctx_params *ctx_params) { struct wd_ctx_nums comp_ctx_num[WD_DIR_MAX] = {0}; struct wd_ctx_params comp_ctx_params = {0}; @@ -286,36 +280,26 @@ int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_par while (ret != 0) { memset(&wd_comp_setting.config, 0, sizeof(struct wd_ctx_config_internal)); - /* Get alg driver and dev name */ - wd_comp_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_comp_setting.driver) { - WD_ERR("failed to bind %s driver.\n", alg); - goto out_dlclose; - } - + /* Init ctx param and prepare for ctx request */ comp_ctx_params.ctx_set_num = comp_ctx_num; - ret = wd_ctx_param_init(&comp_ctx_params, ctx_params, - wd_comp_setting.driver, WD_COMP_TYPE, WD_DIR_MAX); + ret = wd_ctx_param_init_nw(&comp_ctx_params, ctx_params, + alg, task_type, WD_COMP_TYPE, WD_DIR_MAX); if (ret) { if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_comp_setting.driver); - wd_alg_drv_unbind(wd_comp_setting.driver); continue; } - goto out_unbind_drv; + goto out_dlclose; } (void)strcpy(wd_comp_init_attrs.alg, alg); wd_comp_init_attrs.sched_type = sched_type; - wd_comp_init_attrs.driver = wd_comp_setting.driver; + wd_comp_init_attrs.task_type = task_type; wd_comp_init_attrs.ctx_params = &comp_ctx_params; wd_comp_init_attrs.alg_init = wd_comp_init_nolock; wd_comp_init_attrs.alg_poll_ctx = wd_comp_poll_ctx; ret = wd_alg_attrs_init(&wd_comp_init_attrs); if (ret) { if (ret == -WD_ENODEV) { - wd_disable_drv(wd_comp_setting.driver); - wd_alg_drv_unbind(wd_comp_setting.driver); wd_ctx_param_uninit(&comp_ctx_params); continue; } @@ -324,15 +308,26 @@ int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_par } } + ret = wd_ctx_drv_config(alg, &wd_comp_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_comp_setting.config); + if (ret) + goto out_drv_deconfig; + wd_alg_set_init(&wd_comp_setting.status); wd_ctx_param_uninit(&comp_ctx_params); return 0; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_comp_setting.config); +out_uninit_nolock: + wd_comp_uninit_nolock(); + wd_alg_attrs_uninit(&wd_comp_init_attrs); out_params_uninit: wd_ctx_param_uninit(&comp_ctx_params); -out_unbind_drv: - wd_alg_drv_unbind(wd_comp_setting.driver); out_dlclose: wd_comp_close_driver(WD_TYPE_V2); out_uninit: @@ -344,12 +339,12 @@ void wd_comp_uninit2(void) { int ret; + wd_ctx_drv_deconfig(&wd_comp_setting.config); ret = wd_comp_uninit_nolock(); if (ret) return; wd_alg_attrs_uninit(&wd_comp_init_attrs); - wd_alg_drv_unbind(wd_comp_setting.driver); wd_comp_close_driver(WD_TYPE_V2); wd_alg_clear_init(&wd_comp_setting.status); } @@ -384,7 +379,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx; do { - ret = wd_comp_setting.driver->recv(ctx->ctx, &resp_msg); + ret = ctx->drv->recv(ctx->ctx, &resp_msg); if (unlikely(ret < 0)) { if (ret == -WD_HW_EACCESS) WD_ERR("wd comp recv hw error!\n"); @@ -683,8 +678,8 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess, wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx; - msg_handle.send = wd_comp_setting.driver->send; - msg_handle.recv = wd_comp_setting.driver->recv; + msg_handle.send = ctx->drv->send; + msg_handle.recv = ctx->drv->recv; pthread_spin_lock(&ctx->lock); ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, @@ -946,7 +941,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req) msg->tag = tag; msg->stream_mode = WD_COMP_STATELESS; - ret = wd_comp_setting.driver->send(ctx->ctx, msg); + ret = ctx->drv->send(ctx->ctx, msg); if (unlikely(ret < 0)) { if (ret != -WD_EBUSY) WD_ERR("wd comp send error, ret = %d!\n", ret); -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> After the uadk framework updates the heterogeneous scheduling function, the internal implementation functions of the dh algorithm need to be adapted and modified. Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- wd_dh.c | 87 ++++++++++++++++++++++++++------------------------------- 1 file changed, 40 insertions(+), 47 deletions(-) diff --git a/wd_dh.c b/wd_dh.c index 42a1805..48edc16 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -35,7 +35,6 @@ static struct wd_dh_setting { struct wd_ctx_config_internal config; struct wd_sched sched; struct wd_async_msg_pool pool; - struct wd_alg_driver *driver; void *priv; void *dlhandle; void *dlh_list; @@ -56,19 +55,15 @@ static void wd_dh_close_driver(int init_type) if (!wd_dh_setting.dlhandle) return; - wd_release_drv(wd_dh_setting.driver); dlclose(wd_dh_setting.dlhandle); wd_dh_setting.dlhandle = NULL; #else - wd_release_drv(wd_dh_setting.driver); hisi_hpre_remove(); #endif } static int wd_dh_open_driver(int init_type) { - struct wd_alg_driver *driver = NULL; - const char *alg_name = "dh"; #ifndef WD_STATIC_DRV char lib_path[PATH_MAX]; int ret; @@ -102,14 +97,6 @@ static int wd_dh_open_driver(int init_type) if (init_type == WD_TYPE_V2) return WD_SUCCESS; #endif - driver = wd_request_drv(alg_name, false); - if (!driver) { - wd_dh_close_driver(WD_TYPE_V1); - WD_ERR("failed to get %s driver support\n", alg_name); - return -WD_EINVAL; - } - - wd_dh_setting.driver = driver; return WD_SUCCESS; } @@ -144,16 +131,10 @@ static int wd_dh_common_init(struct wd_ctx_config *config, struct wd_sched *sche if (ret) goto out_clear_sched; - ret = wd_alg_init_driver(&wd_dh_setting.config, - wd_dh_setting.driver, - &wd_dh_setting.priv); - if (ret) - goto out_clear_pool; + wd_dh_setting.priv = STATUS_ENABLE; return WD_SUCCESS; -out_clear_pool: - wd_uninit_async_request_pool(&wd_dh_setting.pool); out_clear_sched: wd_clear_sched(&wd_dh_setting.sched); out_clear_ctx_config: @@ -173,9 +154,7 @@ 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.priv); + wd_dh_setting.priv = NULL; return WD_SUCCESS; } @@ -202,10 +181,22 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_close_driver; + ret = wd_ctx_drv_config("dh", &wd_dh_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_dh_setting.config); + if (ret) + goto out_drv_deconfig; + wd_alg_set_init(&wd_dh_setting.status); return WD_SUCCESS; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_dh_setting.config); +out_uninit_nolock: + wd_dh_common_uninit(); out_close_driver: wd_dh_close_driver(WD_TYPE_V1); out_clear_init: @@ -221,6 +212,9 @@ void wd_dh_uninit(void) if (ret) return; + wd_alg_uninit_driver_nw(&wd_dh_setting.config); + wd_ctx_drv_deconfig(&wd_dh_setting.config); + wd_dh_close_driver(WD_TYPE_V1); wd_alg_clear_init(&wd_dh_setting.status); } @@ -255,37 +249,25 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param while (ret) { memset(&wd_dh_setting.config, 0, sizeof(struct wd_ctx_config_internal)); - /* Get alg driver and dev name */ - wd_dh_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_dh_setting.driver) { - WD_ERR("fail to bind a valid driver.\n"); - ret = -WD_EINVAL; - goto out_dlopen; - } - + /* Init ctx param and prepare for ctx request */ dh_ctx_params.ctx_set_num = dh_ctx_num; - ret = wd_ctx_param_init(&dh_ctx_params, ctx_params, - wd_dh_setting.driver, WD_DH_TYPE, WD_DH_PHASE2); + ret = wd_ctx_param_init_nw(&dh_ctx_params, ctx_params, + alg, task_type, WD_DH_TYPE, WD_DH_PHASE2); if (ret) { - if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_dh_setting.driver); - wd_alg_drv_unbind(wd_dh_setting.driver); + if (ret == -WD_EAGAIN) continue; - } goto out_driver; } (void)strcpy(wd_dh_init_attrs.alg, alg); wd_dh_init_attrs.sched_type = sched_type; - wd_dh_init_attrs.driver = wd_dh_setting.driver; + wd_dh_init_attrs.task_type = task_type; wd_dh_init_attrs.ctx_params = &dh_ctx_params; wd_dh_init_attrs.alg_init = wd_dh_common_init; wd_dh_init_attrs.alg_poll_ctx = wd_dh_poll_ctx; ret = wd_alg_attrs_init(&wd_dh_init_attrs); if (ret) { if (ret == -WD_ENODEV) { - wd_disable_drv(wd_dh_setting.driver); - wd_alg_drv_unbind(wd_dh_setting.driver); wd_ctx_param_uninit(&dh_ctx_params); continue; } @@ -294,16 +276,27 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param } } + ret = wd_ctx_drv_config(alg, &wd_dh_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_dh_setting.config); + if (ret) + goto out_drv_deconfig; + wd_alg_set_init(&wd_dh_setting.status); wd_ctx_param_uninit(&dh_ctx_params); return WD_SUCCESS; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_dh_setting.config); +out_uninit_nolock: + wd_dh_common_uninit(); + wd_alg_attrs_uninit(&wd_dh_init_attrs); out_params_uninit: wd_ctx_param_uninit(&dh_ctx_params); out_driver: - wd_alg_drv_unbind(wd_dh_setting.driver); -out_dlopen: wd_dh_close_driver(WD_TYPE_V2); out_clear_init: wd_alg_clear_init(&wd_dh_setting.status); @@ -318,8 +311,8 @@ void wd_dh_uninit2(void) if (ret) return; + wd_ctx_drv_deconfig(&wd_dh_setting.config); wd_alg_attrs_uninit(&wd_dh_init_attrs); - wd_alg_drv_unbind(wd_dh_setting.driver); wd_dh_close_driver(WD_TYPE_V2); wd_alg_clear_init(&wd_dh_setting.status); } @@ -388,8 +381,8 @@ int wd_do_dh_sync(handle_t sess, struct wd_dh_req *req) if (unlikely(ret)) return ret; - msg_handle.send = wd_dh_setting.driver->send; - msg_handle.recv = wd_dh_setting.driver->recv; + msg_handle.send = ctx->drv->send; + msg_handle.recv = ctx->drv->recv; pthread_spin_lock(&ctx->lock); ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance, @@ -439,7 +432,7 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req) goto fail_with_msg; msg->tag = mid; - ret = wd_dh_setting.driver->send(ctx->ctx, msg); + ret = ctx->drv->send(ctx->ctx, msg); if (unlikely(ret)) { if (ret != -WD_EBUSY) WD_ERR("failed to send dh BD, hw is err!\n"); @@ -490,7 +483,7 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx; do { - ret = wd_dh_setting.driver->recv(ctx->ctx, &rcv_msg); + ret = ctx->drv->recv(ctx->ctx, &rcv_msg); if (ret == -WD_EAGAIN) { return ret; } else if (unlikely(ret)) { -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> After the uadk framework updates the heterogeneous scheduling function, the internal implementation functions of the digest algorithm need to be adapted and modified. Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- wd_digest.c | 106 +++++++++++++++++++++++++--------------------------- 1 file changed, 50 insertions(+), 56 deletions(-) diff --git a/wd_digest.c b/wd_digest.c index 763eae5..fc42796 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -40,7 +40,6 @@ struct wd_digest_setting { enum wd_status status; struct wd_ctx_config_internal config; struct wd_sched sched; - struct wd_alg_driver *driver; struct wd_async_msg_pool pool; void *priv; void *dlhandle; @@ -86,20 +85,16 @@ static void wd_digest_close_driver(int init_type) } if (wd_digest_setting.dlhandle) { - wd_release_drv(wd_digest_setting.driver); dlclose(wd_digest_setting.dlhandle); wd_digest_setting.dlhandle = NULL; } #else - wd_release_drv(wd_digest_setting.driver); hisi_sec2_remove(); #endif } static int wd_digest_open_driver(int init_type) { - struct wd_alg_driver *driver = NULL; - const char *alg_name = "sm3"; #ifndef WD_STATIC_DRV char lib_path[PATH_MAX]; int ret; @@ -133,14 +128,6 @@ static int wd_digest_open_driver(int init_type) if (init_type == WD_TYPE_V2) return WD_SUCCESS; #endif - driver = wd_request_drv(alg_name, false); - if (!driver) { - wd_digest_close_driver(WD_TYPE_V1); - WD_ERR("failed to get %s driver support\n", alg_name); - return -WD_EINVAL; - } - - wd_digest_setting.driver = driver; return WD_SUCCESS; } @@ -238,7 +225,7 @@ handle_t wd_digest_alloc_sess(struct wd_digest_sess_setup *setup) sess->alg_name = wd_digest_alg_name[setup->alg]; sess->alg = setup->alg; sess->mode = setup->mode; - ret = wd_drv_alg_support(sess->alg_name, wd_digest_setting.driver); + ret = wd_drv_alg_support(sess->alg_name, &wd_digest_setting.config); if (!ret) { WD_ERR("failed to support this algorithm: %s!\n", sess->alg_name); goto err_sess; @@ -312,16 +299,10 @@ static int wd_digest_init_nolock(struct wd_ctx_config *config, if (ret < 0) goto out_clear_sched; - ret = wd_alg_init_driver(&wd_digest_setting.config, - wd_digest_setting.driver, - &wd_digest_setting.priv); - if (ret) - goto out_clear_pool; + wd_digest_setting.priv = STATUS_ENABLE; return 0; -out_clear_pool: - wd_uninit_async_request_pool(&wd_digest_setting.pool); out_clear_sched: wd_clear_sched(&wd_digest_setting.sched); out_clear_ctx_config: @@ -330,6 +311,13 @@ out_clear_ctx_config: return ret; } +static void wd_digest_uninit_nolock(void) +{ + wd_uninit_async_request_pool(&wd_digest_setting.pool); + wd_clear_sched(&wd_digest_setting.sched); + wd_digest_setting.priv = NULL; +} + int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched) { int ret; @@ -352,10 +340,22 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_close_driver; + ret = wd_ctx_drv_config("sm3", &wd_digest_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_digest_setting.config); + if (ret) + goto out_drv_deconfig; + wd_alg_set_init(&wd_digest_setting.status); return 0; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_digest_setting.config); +out_uninit_nolock: + wd_digest_uninit_nolock(); out_close_driver: wd_digest_close_driver(WD_TYPE_V1); out_clear_init: @@ -363,20 +363,14 @@ out_clear_init: return ret; } -static void wd_digest_uninit_nolock(void) -{ - wd_uninit_async_request_pool(&wd_digest_setting.pool); - wd_clear_sched(&wd_digest_setting.sched); - wd_alg_uninit_driver(&wd_digest_setting.config, - wd_digest_setting.driver, - &wd_digest_setting.priv); -} - void wd_digest_uninit(void) { if (!wd_digest_setting.priv) return; + wd_alg_uninit_driver_nw(&wd_digest_setting.config); + wd_ctx_drv_deconfig(&wd_digest_setting.config); + wd_digest_uninit_nolock(); wd_digest_close_driver(WD_TYPE_V1); wd_alg_clear_init(&wd_digest_setting.status); @@ -424,36 +418,26 @@ int wd_digest_init2_(char *alg, __u32 sched_type, int task_type, while (ret != 0) { memset(&wd_digest_setting.config, 0, sizeof(struct wd_ctx_config_internal)); - /* Get alg driver and dev name */ - wd_digest_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_digest_setting.driver) { - WD_ERR("failed to bind %s driver.\n", alg); - goto out_dlopen; - } - + /* Init ctx param and prepare for ctx request */ digest_ctx_params.ctx_set_num = &digest_ctx_num; - ret = wd_ctx_param_init(&digest_ctx_params, ctx_params, - wd_digest_setting.driver, WD_DIGEST_TYPE, 1); + ret = wd_ctx_param_init_nw(&digest_ctx_params, ctx_params, + alg, task_type, WD_DIGEST_TYPE, 1); if (ret) { if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_digest_setting.driver); - wd_alg_drv_unbind(wd_digest_setting.driver); continue; } - goto out_driver; + goto out_dlclose; } (void)strcpy(wd_digest_init_attrs.alg, alg); wd_digest_init_attrs.sched_type = sched_type; - wd_digest_init_attrs.driver = wd_digest_setting.driver; + wd_digest_init_attrs.task_type = task_type; wd_digest_init_attrs.ctx_params = &digest_ctx_params; wd_digest_init_attrs.alg_init = wd_digest_init_nolock; wd_digest_init_attrs.alg_poll_ctx = wd_digest_poll_ctx; ret = wd_alg_attrs_init(&wd_digest_init_attrs); if (ret) { if (ret == -WD_ENODEV) { - wd_disable_drv(wd_digest_setting.driver); - wd_alg_drv_unbind(wd_digest_setting.driver); wd_ctx_param_uninit(&digest_ctx_params); continue; } @@ -461,16 +445,27 @@ int wd_digest_init2_(char *alg, __u32 sched_type, int task_type, goto out_params_uninit; } } + ret = wd_ctx_drv_config(alg, &wd_digest_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_digest_setting.config); + if (ret) + goto out_drv_deconfig; + wd_alg_set_init(&wd_digest_setting.status); wd_ctx_param_uninit(&digest_ctx_params); return 0; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_digest_setting.config); +out_uninit_nolock: + wd_digest_uninit_nolock(); + wd_alg_attrs_uninit(&wd_digest_init_attrs); out_params_uninit: wd_ctx_param_uninit(&digest_ctx_params); -out_driver: - wd_alg_drv_unbind(wd_digest_setting.driver); -out_dlopen: +out_dlclose: wd_digest_close_driver(WD_TYPE_V2); out_uninit: wd_alg_clear_init(&wd_digest_setting.status); @@ -482,9 +477,9 @@ void wd_digest_uninit2(void) if (!wd_digest_setting.priv) return; + wd_ctx_drv_deconfig(&wd_digest_setting.config); 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); wd_alg_clear_init(&wd_digest_setting.status); } @@ -643,13 +638,13 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *ds struct wd_msg_handle msg_handle; int ret; - msg_handle.send = wd_digest_setting.driver->send; - msg_handle.recv = wd_digest_setting.driver->recv; + msg_handle.send = ctx->drv->send; + msg_handle.recv = ctx->drv->recv; - wd_ctx_spin_lock(ctx, wd_digest_setting.driver->calc_type); + wd_ctx_spin_lock(ctx, UADK_ALG_HW); 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); + wd_ctx_spin_unlock(ctx, UADK_ALG_HW); if (unlikely(ret)) return ret; @@ -742,7 +737,7 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req) fill_request_msg(msg, req, dsess); msg->tag = msg_id; - ret = wd_digest_setting.driver->send(ctx->ctx, msg); + ret = ctx->drv->send(ctx->ctx, msg); if (unlikely(ret < 0)) { if (ret != -WD_EBUSY) WD_ERR("failed to send BD, hw is err!\n"); @@ -792,8 +787,7 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx; do { - ret = wd_digest_setting.driver->recv(ctx->ctx, - &recv_msg); + ret = ctx->drv->recv(ctx->ctx, &recv_msg); if (ret == -WD_EAGAIN) { return ret; } else if (ret < 0) { -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> After the uadk framework updates the heterogeneous scheduling function, the internal implementation functions of the ECC algorithm need to be adapted and modified. Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- drv/hisi_hpre.c | 5 +- include/drv/wd_ecc_drv.h | 5 +- wd_ecc.c | 164 ++++++++++++++++----------------------- 3 files changed, 69 insertions(+), 105 deletions(-) diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index d8f3b53..e9948a8 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -1577,7 +1577,7 @@ static int u_is_in_p(struct wd_ecc_msg *msg) static int ecc_prepare_in(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg, void **data) { - struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)msg->drv_cfg; + struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)msg->priv; int ret = -WD_EINVAL; switch (msg->req.op_type) { @@ -2873,10 +2873,7 @@ static int hpre_ecc_get_extend_ops(void *ops) if (!ecc_ops) return -WD_EINVAL; - ecc_ops->params = NULL; - ecc_ops->sess_init = NULL; ecc_ops->eops_params_cfg = ecc_sess_eops_params_cfg; - ecc_ops->sess_uninit = NULL; return WD_SUCCESS; } diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h index 899f593..471c96b 100644 --- a/include/drv/wd_ecc_drv.h +++ b/include/drv/wd_ecc_drv.h @@ -56,7 +56,7 @@ struct wd_ecc_msg { __u16 key_bytes; /* key bytes */ __u8 curve_id; /* Ec curve denoted by enum wd_ecc_curve_type */ __u8 result; /* alg op error code */ - void *drv_cfg; /* internal driver configuration */ + void *priv; /* internal driver configuration */ __u8 *rsv_out; /* reserved output data pointer */ }; @@ -180,11 +180,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_ecc_sess_setup *setup, struct wd_ecc_curve *cv, void *priv); - int (*sess_init)(struct wd_alg_driver *drv, void **params); - void (*sess_uninit)(struct wd_alg_driver *drv, void *params); }; struct wd_ecc_msg *wd_ecc_get_msg(__u32 idx, __u32 tag); diff --git a/wd_ecc.c b/wd_ecc.c index b7e5481..75507e8 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -50,7 +50,6 @@ struct wd_ecc_sess { __u32 key_size; struct wd_ecc_key key; struct wd_ecc_sess_setup setup; - struct wd_ecc_extend_ops eops; void *sched_key; struct wd_mm_ops mm_ops; enum wd_mem_type mm_type; @@ -68,7 +67,6 @@ static struct wd_ecc_setting { struct wd_ctx_config_internal config; struct wd_sched sched; struct wd_async_msg_pool pool; - struct wd_alg_driver *driver; void *priv; void *dlhandle; void *dlh_list; @@ -113,19 +111,15 @@ static void wd_ecc_close_driver(int init_type) if (!wd_ecc_setting.dlhandle) return; - wd_release_drv(wd_ecc_setting.driver); dlclose(wd_ecc_setting.dlhandle); wd_ecc_setting.dlhandle = NULL; #else - wd_release_drv(wd_ecc_setting.driver); hisi_hpre_remove(); #endif } static int wd_ecc_open_driver(int init_type) { - struct wd_alg_driver *driver = NULL; - const char *alg_name = "sm2"; #ifndef WD_STATIC_DRV char lib_path[PATH_MAX]; int ret; @@ -159,14 +153,6 @@ static int wd_ecc_open_driver(int init_type) if (init_type == WD_TYPE_V2) return WD_SUCCESS; #endif - driver = wd_request_drv(alg_name, false); - if (!driver) { - wd_ecc_close_driver(WD_TYPE_V1); - WD_ERR("failed to get %s driver support\n", alg_name); - return -WD_EINVAL; - } - - wd_ecc_setting.driver = driver; return WD_SUCCESS; } @@ -210,16 +196,10 @@ static int wd_ecc_common_init(struct wd_ctx_config *config, struct wd_sched *sch if (ret < 0) goto out_clear_sched; - ret = wd_alg_init_driver(&wd_ecc_setting.config, - wd_ecc_setting.driver, - &wd_ecc_setting.priv); - if (ret) - goto out_clear_pool; + wd_ecc_setting.priv = STATUS_ENABLE; return WD_SUCCESS; -out_clear_pool: - wd_uninit_async_request_pool(&wd_ecc_setting.pool); out_clear_sched: wd_clear_sched(&wd_ecc_setting.sched); out_clear_ctx_config: @@ -239,9 +219,7 @@ 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.priv); + wd_ecc_setting.priv = NULL; return WD_SUCCESS; } @@ -268,10 +246,22 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_close_driver; + ret = wd_ctx_drv_config("sm2", &wd_ecc_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_ecc_setting.config); + if (ret) + goto out_drv_deconfig; + wd_alg_set_init(&wd_ecc_setting.status); return WD_SUCCESS; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_ecc_setting.config); +out_uninit_nolock: + wd_ecc_common_uninit(); out_close_driver: wd_ecc_close_driver(WD_TYPE_V1); out_clear_init: @@ -283,6 +273,8 @@ void wd_ecc_uninit(void) { int ret; + wd_alg_uninit_driver_nw(&wd_ecc_setting.config); + wd_ctx_drv_deconfig(&wd_ecc_setting.config); ret = wd_ecc_common_uninit(); if (ret) return; @@ -323,37 +315,26 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para while (ret) { memset(&wd_ecc_setting.config, 0, sizeof(struct wd_ctx_config_internal)); - /* Get alg driver and dev name */ - wd_ecc_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_ecc_setting.driver) { - WD_ERR("failed to bind a valid driver!\n"); - ret = -WD_EINVAL; - goto out_dlopen; - } - + /* Init ctx param and prepare for ctx request */ ecc_ctx_params.ctx_set_num = ecc_ctx_num; - ret = wd_ctx_param_init(&ecc_ctx_params, ctx_params, - wd_ecc_setting.driver, WD_ECC_TYPE, WD_EC_OP_MAX); + ret = wd_ctx_param_init_nw(&ecc_ctx_params, ctx_params, + alg, task_type, WD_ECC_TYPE, WD_EC_OP_MAX); if (ret) { - if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_ecc_setting.driver); - wd_alg_drv_unbind(wd_ecc_setting.driver); + if (ret == -WD_EAGAIN) continue; - } + goto out_driver; } (void)strcpy(wd_ecc_init_attrs.alg, alg); wd_ecc_init_attrs.sched_type = sched_type; - wd_ecc_init_attrs.driver = wd_ecc_setting.driver; + wd_ecc_init_attrs.task_type = task_type; wd_ecc_init_attrs.ctx_params = &ecc_ctx_params; wd_ecc_init_attrs.alg_init = wd_ecc_common_init; wd_ecc_init_attrs.alg_poll_ctx = wd_ecc_poll_ctx; ret = wd_alg_attrs_init(&wd_ecc_init_attrs); if (ret) { if (ret == -WD_ENODEV) { - wd_disable_drv(wd_ecc_setting.driver); - wd_alg_drv_unbind(wd_ecc_setting.driver); wd_ctx_param_uninit(&ecc_ctx_params); continue; } @@ -362,16 +343,27 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para } } + ret = wd_ctx_drv_config(alg, &wd_ecc_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_ecc_setting.config); + if (ret) + goto out_drv_deconfig; + wd_alg_set_init(&wd_ecc_setting.status); wd_ctx_param_uninit(&ecc_ctx_params); return WD_SUCCESS; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_ecc_setting.config); +out_uninit_nolock: + wd_ecc_common_uninit(); + wd_alg_attrs_uninit(&wd_ecc_init_attrs); out_params_uninit: wd_ctx_param_uninit(&ecc_ctx_params); out_driver: - wd_alg_drv_unbind(wd_ecc_setting.driver); -out_dlopen: wd_ecc_close_driver(WD_TYPE_V2); out_clear_init: wd_alg_clear_init(&wd_ecc_setting.status); @@ -382,12 +374,12 @@ void wd_ecc_uninit2(void) { int ret; + wd_ctx_drv_deconfig(&wd_ecc_setting.config); ret = wd_ecc_common_uninit(); if (ret) return; wd_alg_attrs_uninit(&wd_ecc_init_attrs); - wd_alg_drv_unbind(wd_ecc_setting.driver); wd_ecc_close_driver(WD_TYPE_V2); wd_alg_clear_init(&wd_ecc_setting.status); } @@ -1174,39 +1166,34 @@ static void del_sess_key(struct wd_ecc_sess *sess) } } -static int wd_ecc_sess_eops_init(struct wd_ecc_sess *sess) +static void wd_ecc_sess_eops_cfg(struct wd_ecc_sess_setup *setup, + struct wd_ecc_sess *sess) { - int ret; + struct wd_ctx_config_internal *config = &wd_ecc_setting.config; + struct wd_ecc_extend_ops *eops; + struct wd_alg_driver *drv; + int ret, valide = 0; + __u32 i; + + for (i = 0; i < config->ctx_num; i++) { + drv = config->ctxs[i].drv; + if (!drv->get_extend_ops) + continue; + + ret = drv->get_extend_ops(config->ctxs[i].extend_ops); + if (!ret && config->ctxs[i].extend_ops) { + valide++; + eops = config->ctxs[i].extend_ops; + + if (!eops->eops_params_cfg) + continue; - if (sess->eops.sess_init) { - if (!sess->eops.sess_uninit) { - WD_ERR("failed to get extend ops in session!\n"); - return -WD_EINVAL; - } - ret = sess->eops.sess_init(wd_ecc_setting.driver, &sess->eops.params); - if (ret) { - WD_ERR("failed to init extend ops params in session!\n"); - return ret; + eops->eops_params_cfg(setup, sess->key.cv, config->ctxs[i].drv_priv); } } - return WD_SUCCESS; -} -static void wd_ecc_sess_eops_uninit(struct wd_ecc_sess *sess) -{ - if (sess->eops.sess_uninit) { - sess->eops.sess_uninit(wd_ecc_setting.driver, sess->eops.params); - sess->eops.params = NULL; - } -} - -static void wd_ecc_sess_eops_cfg(struct wd_ecc_sess_setup *setup, - struct wd_ecc_sess *sess) -{ - 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(setup, sess->key.cv, wd_ecc_setting.priv); - } + if (!valide) + WD_ERR("failed to get ecc extend ops!\n"); } handle_t wd_ecc_alloc_sess(struct wd_ecc_sess_setup *setup) @@ -1217,7 +1204,7 @@ handle_t wd_ecc_alloc_sess(struct wd_ecc_sess_setup *setup) if (setup_param_check(setup)) return (handle_t)0; - ret = wd_drv_alg_support(setup->alg, wd_ecc_setting.driver); + ret = wd_drv_alg_support(setup->alg, &wd_ecc_setting.config); if (!ret) { WD_ERR("failed to support this algorithm: %s!\n", setup->alg); return (handle_t)0; @@ -1239,24 +1226,10 @@ handle_t wd_ecc_alloc_sess(struct wd_ecc_sess_setup *setup) memcpy(&sess->mm_ops, &setup->mm_ops, sizeof(struct wd_mm_ops)); sess->mm_type = setup->mm_type; - if (wd_ecc_setting.driver->get_extend_ops) { - ret = wd_ecc_setting.driver->get_extend_ops(&sess->eops); - if (ret) { - WD_ERR("failed to get ecc sess extend ops!\n"); - goto sess_err; - } - } - - ret = wd_ecc_sess_eops_init(sess); - if (ret) { - WD_ERR("failed to init ecc sess extend eops!\n"); - goto sess_err; - } - ret = create_sess_key(setup, sess); if (ret) { WD_ERR("failed to create ecc sess keys!\n"); - goto eops_err; + goto sess_err; } wd_ecc_sess_eops_cfg(setup, sess); @@ -1273,8 +1246,6 @@ handle_t wd_ecc_alloc_sess(struct wd_ecc_sess_setup *setup) sched_err: del_sess_key(sess); -eops_err: - wd_ecc_sess_eops_uninit(sess); sess_err: free(sess); return (handle_t)0; @@ -1292,7 +1263,6 @@ void wd_ecc_free_sess(handle_t sess) if (sess_t->sched_key) free(sess_t->sched_key); del_sess_key(sess_t); - wd_ecc_sess_eops_uninit(sess_t); free(sess_t); } @@ -1569,7 +1539,6 @@ static int fill_ecc_msg(struct wd_ecc_msg *msg, struct wd_ecc_req *req, msg->mm_type = sess->mm_type; msg->key_bytes = sess->key_size; msg->curve_id = sess->setup.cv.cfg.id; - msg->drv_cfg = sess->eops.params; msg->result = WD_EINVAL; switch (req->op_type) { @@ -1649,8 +1618,9 @@ int wd_do_ecc_sync(handle_t h_sess, struct wd_ecc_req *req) if (unlikely(ret)) return ret; - msg_handle.send = wd_ecc_setting.driver->send; - msg_handle.recv = wd_ecc_setting.driver->recv; + msg_handle.send = ctx->drv->send; + msg_handle.recv = ctx->drv->recv; + msg.priv = ctx->drv_priv; pthread_spin_lock(&ctx->lock); ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance, @@ -2328,7 +2298,6 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req) return ret; ctx = config->ctxs + idx; - mid = wd_get_msg_from_pool(&wd_ecc_setting.pool, idx, (void **)&msg); if (unlikely(mid < 0)) { WD_ERR("failed to get msg from pool!\n"); @@ -2338,9 +2307,10 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req) ret = fill_ecc_msg(msg, req, (struct wd_ecc_sess *)sess); if (ret) goto fail_with_msg; + msg->priv = ctx->drv_priv; msg->tag = mid; - ret = wd_ecc_setting.driver->send(ctx->ctx, msg); + ret = ctx->drv->send(ctx->ctx, msg); if (unlikely(ret)) { if (ret != -WD_EBUSY) WD_ERR("failed to send ecc BD, hw is err!\n"); @@ -2390,7 +2360,7 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx; do { - ret = wd_ecc_setting.driver->recv(ctx->ctx, &recv_msg); + ret = ctx->drv->recv(ctx->ctx, &recv_msg); if (ret == -WD_EAGAIN) { return ret; } else if (ret < 0) { -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> After the uadk framework updates the heterogeneous scheduling function, the internal implementation functions of the rsa algorithm need to be adapted and modified. Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- wd_rsa.c | 87 ++++++++++++++++++++++++++------------------------------ 1 file changed, 40 insertions(+), 47 deletions(-) diff --git a/wd_rsa.c b/wd_rsa.c index 3e4d70d..1104c2a 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -76,7 +76,6 @@ static struct wd_rsa_setting { struct wd_ctx_config_internal config; struct wd_sched sched; struct wd_async_msg_pool pool; - struct wd_alg_driver *driver; void *priv; void *dlhandle; void *dlh_list; @@ -97,19 +96,15 @@ static void wd_rsa_close_driver(int init_type) if (!wd_rsa_setting.dlhandle) return; - wd_release_drv(wd_rsa_setting.driver); dlclose(wd_rsa_setting.dlhandle); wd_rsa_setting.dlhandle = NULL; #else - wd_release_drv(wd_rsa_setting.driver); hisi_hpre_remove(); #endif } static int wd_rsa_open_driver(int init_type) { - struct wd_alg_driver *driver = NULL; - const char *alg_name = "rsa"; #ifndef WD_STATIC_DRV char lib_path[PATH_MAX]; int ret; @@ -143,14 +138,6 @@ static int wd_rsa_open_driver(int init_type) if (init_type == WD_TYPE_V2) return WD_SUCCESS; #endif - driver = wd_request_drv(alg_name, false); - if (!driver) { - wd_rsa_close_driver(WD_TYPE_V1); - WD_ERR("failed to get %s driver support!\n", alg_name); - return -WD_EINVAL; - } - - wd_rsa_setting.driver = driver; return WD_SUCCESS; } @@ -184,16 +171,10 @@ static int wd_rsa_common_init(struct wd_ctx_config *config, struct wd_sched *sch if (ret < 0) goto out_clear_sched; - ret = wd_alg_init_driver(&wd_rsa_setting.config, - wd_rsa_setting.driver, - &wd_rsa_setting.priv); - if (ret) - goto out_clear_pool; + wd_rsa_setting.priv = STATUS_ENABLE; return WD_SUCCESS; -out_clear_pool: - wd_uninit_async_request_pool(&wd_rsa_setting.pool); out_clear_sched: wd_clear_sched(&wd_rsa_setting.sched); out_clear_ctx_config: @@ -213,9 +194,7 @@ 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.priv); + wd_rsa_setting.priv = NULL; return WD_SUCCESS; } @@ -242,10 +221,22 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_close_driver; + ret = wd_ctx_drv_config("rsa", &wd_rsa_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_rsa_setting.config); + if (ret) + goto out_drv_deconfig; + wd_alg_set_init(&wd_rsa_setting.status); return WD_SUCCESS; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_rsa_setting.config); +out_uninit_nolock: + wd_rsa_common_uninit(); out_close_driver: wd_rsa_close_driver(WD_TYPE_V1); out_clear_init: @@ -257,6 +248,8 @@ void wd_rsa_uninit(void) { int ret; + wd_alg_uninit_driver_nw(&wd_rsa_setting.config); + wd_ctx_drv_deconfig(&wd_rsa_setting.config); ret = wd_rsa_common_uninit(); if (ret) return; @@ -295,37 +288,26 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para while (ret) { memset(&wd_rsa_setting.config, 0, sizeof(struct wd_ctx_config_internal)); - /* Get alg driver and dev name */ - wd_rsa_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_rsa_setting.driver) { - WD_ERR("failed to bind a valid driver!\n"); - ret = -WD_EINVAL; - goto out_dlopen; - } - + /* Init ctx param and prepare for ctx request */ rsa_ctx_params.ctx_set_num = rsa_ctx_num; - ret = wd_ctx_param_init(&rsa_ctx_params, ctx_params, - wd_rsa_setting.driver, WD_RSA_TYPE, WD_RSA_GENKEY); + ret = wd_ctx_param_init_nw(&rsa_ctx_params, ctx_params, + alg, task_type, WD_RSA_TYPE, WD_RSA_GENKEY); if (ret) { - if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_rsa_setting.driver); - wd_alg_drv_unbind(wd_rsa_setting.driver); + if (ret == -WD_EAGAIN) continue; - } + goto out_driver; } (void)strcpy(wd_rsa_init_attrs.alg, alg); wd_rsa_init_attrs.sched_type = sched_type; - wd_rsa_init_attrs.driver = wd_rsa_setting.driver; + wd_rsa_init_attrs.task_type = task_type; wd_rsa_init_attrs.ctx_params = &rsa_ctx_params; wd_rsa_init_attrs.alg_init = wd_rsa_common_init; wd_rsa_init_attrs.alg_poll_ctx = wd_rsa_poll_ctx; ret = wd_alg_attrs_init(&wd_rsa_init_attrs); if (ret) { if (ret == -WD_ENODEV) { - wd_disable_drv(wd_rsa_setting.driver); - wd_alg_drv_unbind(wd_rsa_setting.driver); wd_ctx_param_uninit(&rsa_ctx_params); continue; } @@ -334,16 +316,27 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para } } + ret = wd_ctx_drv_config(alg, &wd_rsa_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_rsa_setting.config); + if (ret) + goto out_drv_deconfig; + wd_alg_set_init(&wd_rsa_setting.status); wd_ctx_param_uninit(&rsa_ctx_params); return WD_SUCCESS; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_rsa_setting.config); +out_uninit_nolock: + wd_rsa_common_uninit(); + wd_alg_attrs_uninit(&wd_rsa_init_attrs); out_params_uninit: wd_ctx_param_uninit(&rsa_ctx_params); out_driver: - wd_alg_drv_unbind(wd_rsa_setting.driver); -out_dlopen: wd_rsa_close_driver(WD_TYPE_V2); out_clear_init: wd_alg_clear_init(&wd_rsa_setting.status); @@ -354,12 +347,12 @@ void wd_rsa_uninit2(void) { int ret; + wd_ctx_drv_deconfig(&wd_rsa_setting.config); ret = wd_rsa_common_uninit(); if (ret) return; wd_alg_attrs_uninit(&wd_rsa_init_attrs); - wd_alg_drv_unbind(wd_rsa_setting.driver); wd_rsa_close_driver(WD_TYPE_V2); wd_alg_clear_init(&wd_rsa_setting.status); } @@ -449,8 +442,8 @@ int wd_do_rsa_sync(handle_t h_sess, struct wd_rsa_req *req) if (unlikely(ret)) return ret; - msg_handle.send = wd_rsa_setting.driver->send; - msg_handle.recv = wd_rsa_setting.driver->recv; + msg_handle.send = ctx->drv->send; + msg_handle.recv = ctx->drv->recv; pthread_spin_lock(&ctx->lock); ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance, @@ -500,7 +493,7 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req) goto fail_with_msg; msg->tag = mid; - ret = wd_rsa_setting.driver->send(ctx->ctx, msg); + ret = ctx->drv->send(ctx->ctx, msg); if (unlikely(ret)) { if (ret != -WD_EBUSY) WD_ERR("failed to send rsa BD, hw is err!\n"); @@ -550,7 +543,7 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx; do { - ret = wd_rsa_setting.driver->recv(ctx->ctx, &recv_msg); + ret = ctx->drv->recv(ctx->ctx, &recv_msg); if (ret == -WD_EAGAIN) { return ret; } else if (ret < 0) { -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> After the UADK framework updates the heterogeneous scheduling function, the internal implementation functions of the udma algorithm need to be adapted and modified. Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- wd_udma.c | 62 +++++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/wd_udma.c b/wd_udma.c index 341b533..d30f870 100644 --- a/wd_udma.c +++ b/wd_udma.c @@ -21,7 +21,6 @@ static struct wd_udma_setting { struct wd_ctx_config_internal config; struct wd_sched sched; struct wd_async_msg_pool pool; - struct wd_alg_driver *driver; void *priv; void *dlhandle; void *dlh_list; @@ -35,7 +34,6 @@ static void wd_udma_close_driver(void) wd_dlclose_drv(wd_udma_setting.dlh_list); wd_udma_setting.dlh_list = NULL; #else - wd_release_drv(wd_udma_setting.driver); hisi_udma_remove(); #endif } @@ -227,8 +225,8 @@ int wd_do_udma_sync(handle_t h_sess, struct wd_udma_req *req) fill_udma_msg(&msg, req); - msg_handle.send = wd_udma_setting.driver->send; - msg_handle.recv = wd_udma_setting.driver->recv; + msg_handle.send = ctx->drv->send; + msg_handle.recv = ctx->drv->recv; pthread_spin_lock(&ctx->lock); ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, NULL, wd_udma_setting.config.epoll_en); @@ -277,7 +275,7 @@ int wd_do_udma_async(handle_t sess, struct wd_udma_req *req) fill_udma_msg(msg, req); msg->tag = mid; - ret = wd_udma_setting.driver->send(ctx->ctx, msg); + ret = ctx->drv->send(ctx->ctx, msg); if (unlikely(ret)) { if (ret != -WD_EBUSY) WD_ERR("failed to send udma BD, hw is err!\n"); @@ -315,7 +313,7 @@ static int wd_udma_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx; do { - ret = wd_udma_setting.driver->recv(ctx->ctx, &rcv_msg); + ret = ctx->drv->recv(ctx->ctx, &rcv_msg); if (ret == -WD_EAGAIN) { return ret; } else if (unlikely(ret)) { @@ -365,9 +363,7 @@ 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_udma_setting.priv); + wd_udma_setting.priv = NULL; } void wd_udma_uninit(void) @@ -378,10 +374,14 @@ void wd_udma_uninit(void) if (status == WD_UNINIT) return; + wd_alg_uninit_driver_nw(&wd_udma_setting.config); + wd_ctx_drv_deconfig(&wd_udma_setting.config); + wd_udma_alg_uninit(); wd_alg_attrs_uninit(&wd_udma_init_attrs); - wd_alg_drv_unbind(wd_udma_setting.driver); + wd_udma_close_driver(); + wd_udma_setting.dlh_list = NULL; wd_alg_clear_init(&wd_udma_setting.status); } @@ -408,16 +408,10 @@ 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, - &wd_udma_setting.priv); - if (ret) - goto out_clear_pool; + wd_udma_setting.priv = STATUS_ENABLE; return WD_SUCCESS; -out_clear_pool: - wd_uninit_async_request_pool(&wd_udma_setting.pool); out_clear_sched: wd_clear_sched(&wd_udma_setting.sched); out_clear_ctx_config: @@ -456,21 +450,12 @@ int wd_udma_init(const char *alg, __u32 sched_type, int task_type, while (ret) { memset(&wd_udma_setting.config, 0, sizeof(struct wd_ctx_config_internal)); - /* Get alg driver and dev name */ - wd_udma_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_udma_setting.driver) { - WD_ERR("fail to bind a valid driver.\n"); - ret = -WD_EINVAL; - goto out_dlopen; - } - + /* Init ctx param and prepare for ctx request */ udma_ctx_params.ctx_set_num = udma_ctx_num; - ret = wd_ctx_param_init(&udma_ctx_params, ctx_params, - wd_udma_setting.driver, WD_UDMA_TYPE, WD_UDMA_OP_MAX); + ret = wd_ctx_param_init_nw(&udma_ctx_params, ctx_params, + alg, task_type, WD_UDMA_TYPE, WD_UDMA_OP_MAX); if (ret) { if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_udma_setting.driver); - wd_alg_drv_unbind(wd_udma_setting.driver); continue; } goto out_driver; @@ -478,15 +463,13 @@ int wd_udma_init(const char *alg, __u32 sched_type, int task_type, (void)strcpy(wd_udma_init_attrs.alg, alg); wd_udma_init_attrs.sched_type = sched_type; - wd_udma_init_attrs.driver = wd_udma_setting.driver; + wd_udma_init_attrs.task_type = task_type; wd_udma_init_attrs.ctx_params = &udma_ctx_params; wd_udma_init_attrs.alg_init = wd_udma_alg_init; wd_udma_init_attrs.alg_poll_ctx = wd_udma_poll_ctx; ret = wd_alg_attrs_init(&wd_udma_init_attrs); if (ret) { if (ret == -WD_ENODEV) { - wd_disable_drv(wd_udma_setting.driver); - wd_alg_drv_unbind(wd_udma_setting.driver); wd_ctx_param_uninit(&udma_ctx_params); continue; } @@ -495,16 +478,27 @@ int wd_udma_init(const char *alg, __u32 sched_type, int task_type, } } + ret = wd_ctx_drv_config(alg, &wd_udma_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_udma_setting.config); + if (ret) + goto out_drv_deconfig; + wd_alg_set_init(&wd_udma_setting.status); wd_ctx_param_uninit(&udma_ctx_params); return WD_SUCCESS; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_udma_setting.config); +out_uninit_nolock: + wd_udma_alg_uninit(); + wd_alg_attrs_uninit(&wd_udma_init_attrs); out_params_uninit: wd_ctx_param_uninit(&udma_ctx_params); out_driver: - wd_alg_drv_unbind(wd_udma_setting.driver); -out_dlopen: wd_udma_close_driver(); out_clear_init: wd_alg_clear_init(&wd_udma_setting.status); -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> After the uadk framework updates the heterogeneous scheduling function, the internal implementation functions of the hash-join and gather algorithm need to be adapted and modified. Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- wd_join_gather.c | 124 ++++++++++++++++++++++++++--------------------- 1 file changed, 69 insertions(+), 55 deletions(-) diff --git a/wd_join_gather.c b/wd_join_gather.c index 86190c4..52cd5f9 100644 --- a/wd_join_gather.c +++ b/wd_join_gather.c @@ -32,7 +32,6 @@ struct wd_join_gather_setting { struct wd_ctx_config_internal config; struct wd_sched sched; struct wd_async_msg_pool pool; - struct wd_alg_driver *driver; void *priv; void *dlhandle; void *dlh_list; @@ -79,7 +78,6 @@ static void wd_join_gather_close_driver(void) wd_dlclose_drv(wd_join_gather_setting.dlh_list); wd_join_gather_setting.dlh_list = NULL; #else - wd_release_drv(wd_join_gather_setting.driver); hisi_dae_join_gather_remove(); #endif } @@ -406,33 +404,64 @@ free_join: static void wd_join_gather_uninit_sess(struct wd_join_gather_sess *sess) { + struct wd_ctx_config_internal *config = &wd_join_gather_setting.config; + struct wd_join_gather_ops *eops; + __u32 i; + if (sess->gather_conf.batch_row_size) free(sess->gather_conf.batch_row_size); - if (sess->ops.sess_uninit) - sess->ops.sess_uninit(sess->priv); + for (i = 0; i < config->ctx_num; i++) { + /* At this point, extends_ops has completed its initialization. */ + eops = config->ctxs[i].extend_ops; + if (!eops) + continue; + + if (eops->sess_uninit) + eops->sess_uninit(sess->priv); + } } static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess, struct wd_join_gather_sess_setup *setup) { - __u32 array_size; + struct wd_ctx_config_internal *config = &wd_join_gather_setting.config; + struct wd_join_gather_ops *eops = NULL; + struct wd_alg_driver *drv; + __u32 i, array_size; int ret; - if (sess->ops.sess_init) { - if (!sess->ops.sess_uninit) { + for (i = 0; i < config->ctx_num; i++) { + drv = config->ctxs[i].drv; + if (!drv->get_extend_ops) + continue; + + ret = drv->get_extend_ops(config->ctxs[i].extend_ops); + if (!ret && config->ctxs[i].extend_ops) { + eops = config->ctxs[i].extend_ops; + break; + } + } + if (!eops) { + WD_ERR("failed to get extend ops!\n"); + return -WD_EINVAL; + } + + memcpy(&sess->ops, eops, sizeof(*eops)); + if (eops->sess_init) { + if (!eops->sess_uninit) { WD_ERR("failed to get session uninit ops!\n"); return -WD_EINVAL; } - ret = sess->ops.sess_init(setup, &sess->priv); + ret = eops->sess_init(setup, &sess->priv); if (ret) { WD_ERR("failed to init session priv!\n"); return ret; } } - if (sess->ops.get_table_row_size && setup->alg != WD_GATHER) { - ret = sess->ops.get_table_row_size(sess->priv); + if (eops->get_table_row_size && setup->alg != WD_GATHER) { + ret = eops->get_table_row_size(sess->priv); if (ret <= 0) { WD_ERR("failed to get hash table row size: %d!\n", ret); goto uninit; @@ -440,13 +469,13 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess, sess->hash_table.table_row_size = ret; } - if (sess->ops.get_batch_row_size && setup->alg != WD_JOIN) { + if (eops->get_batch_row_size && setup->alg != WD_JOIN) { array_size = setup->gather_table_num * sizeof(__u32); sess->gather_conf.batch_row_size = malloc(array_size); if (!sess->gather_conf.batch_row_size) goto uninit; - ret = sess->ops.get_batch_row_size(sess->priv, + ret = eops->get_batch_row_size(sess->priv, sess->gather_conf.batch_row_size, array_size); if (ret) { @@ -460,8 +489,8 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess, free_batch: free(sess->gather_conf.batch_row_size); uninit: - if (sess->ops.sess_uninit) - sess->ops.sess_uninit(sess->priv); + if (eops->sess_uninit) + eops->sess_uninit(sess->priv); return -WD_EINVAL; } @@ -485,7 +514,7 @@ handle_t wd_join_gather_alloc_sess(struct wd_join_gather_sess_setup *setup) sess->index_type = setup->index_type; sess->join_conf.key_output_enable = setup->join_table.key_output_enable; - ret = wd_drv_alg_support(wd_join_gather_alg[sess->alg], wd_join_gather_setting.driver); + ret = wd_drv_alg_support(wd_join_gather_alg[sess->alg], &wd_join_gather_setting.config); if (!ret) { WD_ERR("failed to check driver alg: %s!\n", wd_join_gather_alg[sess->alg]); goto free_sess; @@ -499,14 +528,6 @@ handle_t wd_join_gather_alloc_sess(struct wd_join_gather_sess_setup *setup) goto free_sess; } - if (wd_join_gather_setting.driver->get_extend_ops) { - ret = wd_join_gather_setting.driver->get_extend_ops(&sess->ops); - if (ret) { - WD_ERR("failed to get join gather extend ops!\n"); - goto free_key; - } - } - ret = wd_join_gather_init_sess(sess, setup); if (ret) goto free_key; @@ -697,16 +718,10 @@ 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, - &wd_join_gather_setting.priv); - if (ret) - goto out_clear_pool; + wd_join_gather_setting.priv = STATUS_ENABLE; return WD_SUCCESS; -out_clear_pool: - wd_uninit_async_request_pool(&wd_join_gather_setting.pool); out_clear_sched: wd_clear_sched(&wd_join_gather_setting.sched); out_clear_ctx_config: @@ -728,9 +743,7 @@ 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_join_gather_setting.priv); + wd_join_gather_setting.priv = NULL; return WD_SUCCESS; } @@ -769,21 +782,12 @@ int wd_join_gather_init(char *alg, __u32 sched_type, int task_type, while (ret != 0) { memset(&wd_join_gather_setting.config, 0, sizeof(struct wd_ctx_config_internal)); - /* Get alg driver and dev name */ - wd_join_gather_setting.driver = wd_alg_drv_bind(task_type, alg); - if (!wd_join_gather_setting.driver) { - WD_ERR("failed to bind %s driver.\n", alg); - goto out_dlopen; - } - + /* Init ctx param and prepare for ctx request */ join_gather_ctx_params.ctx_set_num = &join_gather_ctx_num; - ret = wd_ctx_param_init(&join_gather_ctx_params, ctx_params, - wd_join_gather_setting.driver, - WD_JOIN_GATHER_TYPE, 1); + ret = wd_ctx_param_init_nw(&join_gather_ctx_params, ctx_params, + alg, task_type, WD_JOIN_GATHER_TYPE, 1); if (ret) { if (ret == -WD_EAGAIN) { - wd_disable_drv(wd_join_gather_setting.driver); - wd_alg_drv_unbind(wd_join_gather_setting.driver); continue; } goto out_driver; @@ -791,15 +795,13 @@ int wd_join_gather_init(char *alg, __u32 sched_type, int task_type, (void)strcpy(wd_join_gather_init_attrs.alg, alg); wd_join_gather_init_attrs.sched_type = sched_type; - wd_join_gather_init_attrs.driver = wd_join_gather_setting.driver; + wd_join_gather_init_attrs.task_type = task_type; wd_join_gather_init_attrs.ctx_params = &join_gather_ctx_params; wd_join_gather_init_attrs.alg_init = wd_join_gather_alg_init; wd_join_gather_init_attrs.alg_poll_ctx = wd_join_gather_poll_ctx; ret = wd_alg_attrs_init(&wd_join_gather_init_attrs); if (ret) { if (ret == -WD_ENODEV) { - wd_disable_drv(wd_join_gather_setting.driver); - wd_alg_drv_unbind(wd_join_gather_setting.driver); wd_ctx_param_uninit(&join_gather_ctx_params); continue; } @@ -807,17 +809,27 @@ int wd_join_gather_init(char *alg, __u32 sched_type, int task_type, goto out_params_uninit; } } + ret = wd_ctx_drv_config(alg, &wd_join_gather_setting.config); + if (ret) + goto out_uninit_nolock; + + ret = wd_alg_init_driver_nw(&wd_join_gather_setting.config); + if (ret) + goto out_drv_deconfig; wd_alg_set_init(&wd_join_gather_setting.status); wd_ctx_param_uninit(&join_gather_ctx_params); return WD_SUCCESS; +out_drv_deconfig: + wd_ctx_drv_deconfig(&wd_join_gather_setting.config); +out_uninit_nolock: + wd_join_gather_alg_uninit(); + wd_alg_attrs_uninit(&wd_join_gather_init_attrs); out_params_uninit: wd_ctx_param_uninit(&join_gather_ctx_params); out_driver: - wd_alg_drv_unbind(wd_join_gather_setting.driver); -out_dlopen: wd_join_gather_close_driver(); out_uninit: wd_alg_clear_init(&wd_join_gather_setting.status); @@ -832,8 +844,10 @@ void wd_join_gather_uninit(void) if (ret) return; + wd_alg_uninit_driver_nw(&wd_join_gather_setting.config); + wd_ctx_drv_deconfig(&wd_join_gather_setting.config); wd_alg_attrs_uninit(&wd_join_gather_init_attrs); - wd_alg_drv_unbind(wd_join_gather_setting.driver); + wd_join_gather_close_driver(); wd_alg_clear_init(&wd_join_gather_setting.status); } @@ -1213,8 +1227,8 @@ static int wd_join_gather_sync_job(struct wd_join_gather_sess *sess, wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx; - msg_handle.send = setting->driver->send; - msg_handle.recv = setting->driver->recv; + msg_handle.send = ctx->drv->send; + msg_handle.recv = ctx->drv->recv; pthread_spin_lock(&ctx->lock); ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, @@ -1313,7 +1327,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_join_gather_setting.driver->send(ctx->ctx, msg); + ret = ctx->drv->send(ctx->ctx, msg); if (ret < 0) { if (ret != -WD_EBUSY) WD_ERR("wd join gather async send err!\n"); @@ -1783,7 +1797,7 @@ static int wd_join_gather_poll_ctx(__u32 idx, __u32 expt, __u32 *count) ctx = config->ctxs + idx; do { - ret = wd_join_gather_setting.driver->recv(ctx->ctx, &resp_msg); + ret = ctx->drv->recv(ctx->ctx, &resp_msg); if (ret == -WD_EAGAIN) { return ret; } else if (ret < 0) { -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> Add functionality to the UADK scheduler to schedule devices based on packet length and stream mode. This feature needs to be added at each algorithm layer, setting the current business's parameters when acquiring the ctx. allowing the scheduler to obtain these parameters and select the task queue accordingly. If it's stream mode, don't switch queues; if it's a small packet, use instruction acceleration directly Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- include/wd_alg_common.h | 3 + include/wd_internal.h | 6 ++ wd_sched.c | 138 +++++++++++++++++++++++++++++++--------- wd_util.c | 4 +- 4 files changed, 119 insertions(+), 32 deletions(-) diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h index 0e5523f..54b02e2 100644 --- a/include/wd_alg_common.h +++ b/include/wd_alg_common.h @@ -190,6 +190,9 @@ struct wd_sched { void *sched_key, const int sched_mode); int (*poll_policy)(handle_t h_sched_ctx, __u32 expect, __u32 *count); + void (*set_param)(handle_t h_sched_ctx, + void *sched_key, + void *sched_param); handle_t h_sched_ctx; }; diff --git a/include/wd_internal.h b/include/wd_internal.h index a67aaf5..5e8470a 100644 --- a/include/wd_internal.h +++ b/include/wd_internal.h @@ -86,6 +86,12 @@ struct wd_datalist { struct wd_datalist *next; }; +struct wd_sched_params { + __u32 pkt_size; + __u16 data_mode; //block mode or stream mode + __u16 prio_mode; +}; + #ifdef __cplusplus } #endif diff --git a/wd_sched.c b/wd_sched.c index 29a0f65..073108c 100644 --- a/wd_sched.c +++ b/wd_sched.c @@ -41,12 +41,19 @@ struct sched_key { __u8 mode; __u32 dev_id; __u8 ctx_prop; + __u16 is_stream; + __u16 prio_mode; + __u32 pkt_size; __u16 sync_ctxid[UADK_CTX_MAX]; __u16 async_ctxid[UADK_CTX_MAX]; + __u16 def_sync_ctxid; + __u16 def_async_ctxid; struct wd_sched_balancer balancer; }; -#define LOOP_SWITH_TIME 5 +#define LOOP_SWITH_STEP 1 +#define LOOP_SWITH_SLICE 10 +#define UADK_SWITH_PKT_SZ 2048 /* * struct sched_ctx_range - define one ctx pos. @@ -816,10 +823,11 @@ static handle_t loop_sched_init(handle_t h_sched_ctx, void *sched_param) skey->sync_ctxid[UADK_CTX_CE_INS] = loop_sched_init_ctx(sched_ctx, skey, CTX_MODE_SYNC); skey->async_ctxid[UADK_CTX_CE_INS] = loop_sched_init_ctx(sched_ctx, skey, CTX_MODE_ASYNC); skey->ctx_prop = ctx_prop; - if (skey->sync_ctxid[1] == INVALID_POS && skey->async_ctxid[1] == INVALID_POS) { + if (skey->sync_ctxid[UADK_CTX_CE_INS] == INVALID_POS && + skey->async_ctxid[UADK_CTX_CE_INS] == INVALID_POS) { WD_ERR("failed to get valid CE sync_ctxid or async_ctxid!\n"); - skey->sync_ctxid[1] = skey->sync_ctxid[0]; - skey->async_ctxid[1] = skey->async_ctxid[0]; + skey->sync_ctxid[UADK_CTX_CE_INS] = skey->sync_ctxid[0]; + skey->async_ctxid[UADK_CTX_CE_INS] = skey->async_ctxid[0]; } WD_ERR("sw ctxid is: %u, %u!\n", skey->sync_ctxid[1], skey->async_ctxid[1]); @@ -831,6 +839,25 @@ out: return (handle_t)(-WD_EINVAL); } +static __u32 wd_sched_special_pick(struct sched_key *key, int sched_mode) +{ + if (key->is_stream) { + if (key->pkt_size < UADK_SWITH_PKT_SZ) { + if (sched_mode == CTX_MODE_SYNC) + return key->sync_ctxid[UADK_CTX_CE_INS]; + else + return key->async_ctxid[UADK_CTX_CE_INS]; + } else { + if (sched_mode == CTX_MODE_SYNC) + return key->sync_ctxid[UADK_CTX_HW]; + else + return key->async_ctxid[UADK_CTX_HW]; + } + } + + return INVALID_POS; +} + /* * loop_sched_pick_next_ctx - Get one ctx from ctxs by the sched_ctx and arg. * @sched_ctx: Schedule ctx, reference the struct sample_sched_ctx. @@ -855,31 +882,43 @@ static __u32 loop_sched_pick_next_ctx(handle_t h_sched_ctx, void *sched_key, key->async_ctxid[UADK_CTX_HW] == INVALID_POS) return session_sched_pick_next_ctx(h_sched_ctx, sched_key, sched_mode); + if (key->is_stream) + return wd_sched_special_pick(key, sched_mode); + + // Small packets go directly through instruction acceleration + if (key->pkt_size != 0 && key->pkt_size < UADK_SWITH_PKT_SZ) { + if (sched_mode == CTX_MODE_SYNC) + return key->sync_ctxid[UADK_CTX_CE_INS]; + else + return key->async_ctxid[UADK_CTX_CE_INS]; + } + if (sched_mode == CTX_MODE_SYNC) { - if (balancer->switch_slice == LOOP_SWITH_TIME) { + if (balancer->switch_slice == LOOP_SWITH_SLICE) { balancer->switch_slice = 0; - balancer->hw_dfx_num++; + balancer->hw_dfx_num += LOOP_SWITH_STEP; /* run in HW */ - return key->sync_ctxid[UADK_CTX_HW]; + key->def_sync_ctxid = key->sync_ctxid[UADK_CTX_HW]; } else { balancer->switch_slice++; /* run in soft CE */ - balancer->sw_dfx_num++; - return key->sync_ctxid[UADK_CTX_CE_INS]; + balancer->sw_dfx_num += LOOP_SWITH_STEP; + key->def_sync_ctxid = key->sync_ctxid[UADK_CTX_CE_INS]; } + return key->def_sync_ctxid; } // Async mode - if (balancer->hw_task_num > balancer->sw_task_num >> 1) { + if (balancer->hw_task_num > balancer->sw_task_num) { /* run in soft CE */ - balancer->sw_task_num++; - - return key->async_ctxid[UADK_CTX_CE_INS]; + balancer->sw_task_num += LOOP_SWITH_STEP >> 1; + key->def_async_ctxid = key->async_ctxid[UADK_CTX_CE_INS]; } else { /* run in HW */ - balancer->hw_task_num++; - - return key->async_ctxid[UADK_CTX_HW]; + balancer->hw_task_num += LOOP_SWITH_STEP >> 2; + key->def_async_ctxid = key->async_ctxid[UADK_CTX_HW]; } + + return key->def_async_ctxid; } static int loop_poll_policy_rr(struct wd_sched_ctx *sched_ctx, int numa_id, @@ -1069,6 +1108,8 @@ static handle_t skey_sched_init(handle_t h_sched_ctx, void *sched_param) } sched_skey_param_init(sched_ctx, skey); + skey->def_sync_ctxid = skey->sync_ctxid[UADK_CTX_CE_INS]; + skey->def_async_ctxid = skey->async_ctxid[UADK_CTX_CE_INS]; WD_ERR("sw ctxid is: %u, %u!\n", skey->sync_ctxid[1], skey->async_ctxid[1]); return (handle_t)skey; @@ -1100,30 +1141,44 @@ static __u32 skey_sched_pick_next_ctx(handle_t h_sched_ctx, void *sched_key, skey->async_ctxid[UADK_CTX_HW] == INVALID_POS) return session_sched_pick_next_ctx(h_sched_ctx, sched_key, sched_mode); + if (skey->is_stream) + return wd_sched_special_pick(skey, sched_mode); + + // Small packets go directly through instruction acceleration + if (skey->pkt_size != 0 && skey->pkt_size < UADK_SWITH_PKT_SZ) { + if (sched_mode == CTX_MODE_SYNC) + return skey->sync_ctxid[UADK_CTX_CE_INS]; + else + return skey->async_ctxid[UADK_CTX_CE_INS]; + } + // Async mode if (sched_mode == CTX_MODE_ASYNC) { - if (skey->balancer.hw_task_num > (skey->balancer.sw_task_num >> 1)) { + if (skey->balancer.hw_task_num > (1024 + skey->balancer.sw_task_num >> 1)) { /* run in soft CE */ - skey->balancer.sw_task_num++; - return skey->async_ctxid[UADK_CTX_CE_INS]; + skey->balancer.sw_task_num += LOOP_SWITH_STEP; + skey->def_async_ctxid = skey->async_ctxid[UADK_CTX_CE_INS]; } else { /* run in HW */ - skey->balancer.hw_task_num++; - return skey->async_ctxid[UADK_CTX_HW]; + skey->balancer.hw_task_num += LOOP_SWITH_STEP; + skey->def_async_ctxid = skey->async_ctxid[UADK_CTX_HW]; } + return skey->def_async_ctxid; } - if (skey->balancer.switch_slice == LOOP_SWITH_TIME) { + if (skey->balancer.switch_slice >= LOOP_SWITH_SLICE) { skey->balancer.switch_slice = 0; - skey->balancer.hw_dfx_num++; + skey->balancer.hw_dfx_num += LOOP_SWITH_STEP >> 1; /* run in HW */ - return skey->sync_ctxid[UADK_CTX_HW]; + skey->def_sync_ctxid = skey->sync_ctxid[UADK_CTX_HW]; } else { skey->balancer.switch_slice++; - skey->balancer.sw_dfx_num++; + skey->balancer.sw_dfx_num += LOOP_SWITH_STEP >> 2; /* run in soft CE */ - return skey->sync_ctxid[UADK_CTX_CE_INS]; + skey->def_sync_ctxid = skey->sync_ctxid[UADK_CTX_CE_INS]; } + + return skey->def_sync_ctxid; } static int skey_poll_ctx(struct wd_sched_ctx *sched_ctx, struct sched_key *skey, @@ -1343,6 +1398,23 @@ static int instr_sched_poll_policy(handle_t h_sched_ctx, __u32 expect, __u32 *co return ret; } +static void wd_sched_set_param(handle_t h_sched_ctx, + void *sched_key, void *sched_param) +{ + struct wd_sched_params *params = (struct wd_sched_params *)sched_param; + struct sched_key *skey = (struct sched_key *)sched_key; + + skey->pkt_size = params->pkt_size; + skey->is_stream = params->data_mode; + skey->prio_mode = params->prio_mode; +} + +static void none_set_param(handle_t h_sched_ctx, + void *sched_key, void *sched_param) +{ + return; +} + static struct wd_sched sched_table[SCHED_POLICY_BUTT] = { { .name = "RR scheduler", @@ -1350,42 +1422,49 @@ static struct wd_sched sched_table[SCHED_POLICY_BUTT] = { .sched_init = session_sched_init, .pick_next_ctx = session_sched_pick_next_ctx, .poll_policy = session_sched_poll_policy, + .set_param = wd_sched_set_param, }, { .name = "None scheduler", .sched_policy = SCHED_POLICY_NONE, .sched_init = sched_none_init, .pick_next_ctx = sched_none_pick_next_ctx, .poll_policy = sched_none_poll_policy, + .set_param = wd_sched_set_param, }, { .name = "Single scheduler", .sched_policy = SCHED_POLICY_SINGLE, .sched_init = sched_single_init, .pick_next_ctx = sched_single_pick_next_ctx, .poll_policy = sched_single_poll_policy, + .set_param = wd_sched_set_param, }, { .name = "Device RR scheduler", .sched_policy = SCHED_POLICY_DEV, .sched_init = session_dev_sched_init, .pick_next_ctx = session_sched_pick_next_ctx, .poll_policy = session_sched_poll_policy, + .set_param = wd_sched_set_param, }, { .name = "Loop scheduler", .sched_policy = SCHED_POLICY_LOOP, .sched_init = loop_sched_init, .pick_next_ctx = loop_sched_pick_next_ctx, .poll_policy = loop_sched_poll_policy, + .set_param = wd_sched_set_param, }, { .name = "Hungry scheduler", .sched_policy = SCHED_POLICY_HUNGRY, .sched_init = skey_sched_init, .pick_next_ctx = skey_sched_pick_next_ctx, .poll_policy = skey_sched_poll_policy, + .set_param = wd_sched_set_param, }, { .name = "Instr scheduler", .sched_policy = SCHED_POLICY_INSTR, .sched_init = instr_sched_init, .pick_next_ctx = instr_sched_pick_next_ctx, .poll_policy = instr_sched_poll_policy, + .set_param = wd_sched_set_param, }, }; @@ -1549,12 +1628,8 @@ int wd_sched_rr_instance(const struct wd_sched *sched, struct sched_params *para if (sched_ctx->policy == SCHED_POLICY_DEV) return wd_instance_dev_region(sched_ctx, param); - if (param->ctx_prop > UADK_CTX_SOFT) { - WD_ERR("invalid: sched_ctx's prop is %d\n", param->ctx_prop); - return -WD_EINVAL; - } /* For older tools, the default setting is of the HW type. */ - if (param->ctx_prop < 0) + if (param->ctx_prop < 0 || param->ctx_prop > UADK_CTX_SOFT) param->ctx_prop = UADK_CTX_HW; if (!sched_ctx->sched_info[numa_id].ctx_region[mode]) { @@ -1776,6 +1851,7 @@ simple_ok: sched->poll_policy = sched_table[sched_type].poll_policy; sched->sched_policy = sched_type; sched->name = sched_table[sched_type].name; + sched->set_param = sched_table[sched_type].set_param; return sched; diff --git a/wd_util.c b/wd_util.c index 19bfcce..09c8f9a 100644 --- a/wd_util.c +++ b/wd_util.c @@ -320,7 +320,7 @@ err_shm_del: int wd_init_sched(struct wd_sched *in, struct wd_sched *from) { - if (!from->name || !from->sched_init || + if (!from->name || !from->sched_init || !from->set_param || !from->pick_next_ctx || !from->poll_policy) { WD_ERR("invalid: member of wd_sched is NULL!\n"); return -WD_EINVAL; @@ -331,6 +331,7 @@ int wd_init_sched(struct wd_sched *in, struct wd_sched *from) in->sched_init = from->sched_init; in->pick_next_ctx = from->pick_next_ctx; in->poll_policy = from->poll_policy; + in->set_param = from->set_param; return 0; } @@ -346,6 +347,7 @@ void wd_clear_sched(struct wd_sched *in) in->sched_init = NULL; in->pick_next_ctx = NULL; in->poll_policy = NULL; + in->set_param = NULL; } void wd_clear_ctx_config(struct wd_ctx_config_internal *in) -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> After adapting to uadk's heterogeneous scheduling framework, all uadk algorithms have completed functional adaptation. After the adaptation is completed, the old functions need to be deleted. Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- include/wd_util.h | 15 ++------ wd_aead.c | 8 ++--- wd_agg.c | 6 ++-- wd_cipher.c | 8 ++--- wd_comp.c | 8 ++--- wd_dh.c | 8 ++--- wd_digest.c | 8 ++--- wd_ecc.c | 8 ++--- wd_join_gather.c | 6 ++-- wd_rsa.c | 8 ++--- wd_udma.c | 6 ++-- wd_util.c | 91 ++++------------------------------------------- 12 files changed, 47 insertions(+), 133 deletions(-) diff --git a/include/wd_util.h b/include/wd_util.h index f226122..42270d9 100644 --- a/include/wd_util.h +++ b/include/wd_util.h @@ -133,7 +133,6 @@ struct wd_init_attrs { struct wd_ctx_config *ctx_config; wd_alg_init alg_init; wd_alg_poll_ctx alg_poll_ctx; - struct wd_alg_driver *driver; //stub for old code }; /* @@ -456,14 +455,10 @@ static inline void wd_alg_clear_init(enum wd_status *status) * * Return 0 if succeed and other error number if fail. */ -int wd_ctx_param_init_nw(struct wd_ctx_params *ctx_params, +int wd_ctx_param_init(struct wd_ctx_params *ctx_params, struct wd_ctx_params *user_ctx_params, char *alg, int task_type, enum wd_type type, int max_op_type); -int wd_ctx_param_init(struct wd_ctx_params *ctx_params, - struct wd_ctx_params *user_ctx_params, - struct wd_alg_driver *driver, - enum wd_type type, int max_op_type); void wd_ctx_param_uninit(struct wd_ctx_params *ctx_params); @@ -497,12 +492,8 @@ void wd_alg_drv_unbind(struct wd_alg_driver *drv); * * Return 0 if succeed and other error number if fail. */ -int wd_alg_init_driver_nw(struct wd_ctx_config_internal *config); -void wd_alg_uninit_driver_nw(struct wd_ctx_config_internal *config); -int wd_alg_init_driver(struct wd_ctx_config_internal *config, - struct wd_alg_driver *driver, void **drv_priv); -void wd_alg_uninit_driver(struct wd_ctx_config_internal *config, - struct wd_alg_driver *driver, void **drv_priv); +int wd_alg_init_driver(struct wd_ctx_config_internal *config); +void wd_alg_uninit_driver(struct wd_ctx_config_internal *config); /** * wd_dlopen_drv() - Open the dynamic library file of the device driver. diff --git a/wd_aead.c b/wd_aead.c index 7ef7dca..fcf23bb 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -649,7 +649,7 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_aead_setting.config); + ret = wd_alg_init_driver(&wd_aead_setting.config); if (ret) goto out_drv_deconfig; wd_alg_set_init(&wd_aead_setting.status); @@ -672,7 +672,7 @@ void wd_aead_uninit(void) if (!wd_aead_setting.priv) return; - wd_alg_uninit_driver_nw(&wd_aead_setting.config); + wd_alg_uninit_driver(&wd_aead_setting.config); wd_ctx_drv_deconfig(&wd_aead_setting.config); wd_aead_uninit_nolock(); @@ -726,7 +726,7 @@ int wd_aead_init2_(char *alg, __u32 sched_type, int task_type, memset(&wd_aead_setting.config, 0, sizeof(struct wd_ctx_config_internal)); /* Init ctx param and prepare for ctx request */ aead_ctx_params.ctx_set_num = aead_ctx_num; - ret = wd_ctx_param_init_nw(&aead_ctx_params, ctx_params, + ret = wd_ctx_param_init(&aead_ctx_params, ctx_params, alg, task_type, WD_AEAD_TYPE, WD_DIGEST_CIPHER_DECRYPTION + 1); if (ret) { if (ret == -WD_EAGAIN) { @@ -755,7 +755,7 @@ int wd_aead_init2_(char *alg, __u32 sched_type, int task_type, if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_aead_setting.config); + ret = wd_alg_init_driver(&wd_aead_setting.config); if (ret) goto out_drv_deconfig; diff --git a/wd_agg.c b/wd_agg.c index ebc6e31..f07642d 100644 --- a/wd_agg.c +++ b/wd_agg.c @@ -697,7 +697,7 @@ int wd_agg_init(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params /* Init ctx param and prepare for ctx request */ agg_ctx_params.ctx_set_num = &agg_ctx_num; - ret = wd_ctx_param_init_nw(&agg_ctx_params, ctx_params, alg, task_type, + ret = wd_ctx_param_init(&agg_ctx_params, ctx_params, alg, task_type, WD_AGG_TYPE, 1); if (ret) { if (ret == -WD_EAGAIN) { @@ -726,7 +726,7 @@ int wd_agg_init(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_agg_setting.config); + ret = wd_alg_init_driver(&wd_agg_setting.config); if (ret) goto out_drv_deconfig; @@ -757,7 +757,7 @@ void wd_agg_uninit(void) if (ret) return; - wd_alg_uninit_driver_nw(&wd_agg_setting.config); + wd_alg_uninit_driver(&wd_agg_setting.config); wd_ctx_drv_deconfig(&wd_agg_setting.config); wd_alg_attrs_uninit(&wd_agg_init_attrs); diff --git a/wd_cipher.c b/wd_cipher.c index af0173a..96bb21c 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -419,7 +419,7 @@ int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_cipher_setting.config); + ret = wd_alg_init_driver(&wd_cipher_setting.config); if (ret) goto out_drv_deconfig; @@ -442,7 +442,7 @@ void wd_cipher_uninit(void) { int ret; - wd_alg_uninit_driver_nw(&wd_cipher_setting.config); + wd_alg_uninit_driver(&wd_cipher_setting.config); wd_ctx_drv_deconfig(&wd_cipher_setting.config); ret = wd_cipher_common_uninit(); @@ -487,7 +487,7 @@ int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_p /* Init ctx param and prepare for ctx request */ cipher_ctx_params.ctx_set_num = cipher_ctx_num; - ret = wd_ctx_param_init_nw(&cipher_ctx_params, ctx_params, + ret = wd_ctx_param_init(&cipher_ctx_params, ctx_params, alg, task_type, WD_CIPHER_TYPE, WD_CIPHER_DECRYPTION + 1); if (ret) { if (ret == -WD_EAGAIN) { @@ -518,7 +518,7 @@ int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_p if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_cipher_setting.config); + ret = wd_alg_init_driver(&wd_cipher_setting.config); if (ret) goto out_drv_deconfig; diff --git a/wd_comp.c b/wd_comp.c index 596979b..b4cba28 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -213,7 +213,7 @@ int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_comp_setting.config); + ret = wd_alg_init_driver(&wd_comp_setting.config); if (ret) goto out_drv_deconfig; @@ -236,7 +236,7 @@ void wd_comp_uninit(void) { int ret; - wd_alg_uninit_driver_nw(&wd_comp_setting.config); + wd_alg_uninit_driver(&wd_comp_setting.config); wd_ctx_drv_deconfig(&wd_comp_setting.config); ret = wd_comp_uninit_nolock(); @@ -282,7 +282,7 @@ int wd_comp_init2_(const char *alg, __u32 sched_type, int task_type, /* Init ctx param and prepare for ctx request */ comp_ctx_params.ctx_set_num = comp_ctx_num; - ret = wd_ctx_param_init_nw(&comp_ctx_params, ctx_params, + ret = wd_ctx_param_init(&comp_ctx_params, ctx_params, alg, task_type, WD_COMP_TYPE, WD_DIR_MAX); if (ret) { if (ret == -WD_EAGAIN) { @@ -312,7 +312,7 @@ int wd_comp_init2_(const char *alg, __u32 sched_type, int task_type, if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_comp_setting.config); + ret = wd_alg_init_driver(&wd_comp_setting.config); if (ret) goto out_drv_deconfig; diff --git a/wd_dh.c b/wd_dh.c index 48edc16..e7322d1 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -185,7 +185,7 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_dh_setting.config); + ret = wd_alg_init_driver(&wd_dh_setting.config); if (ret) goto out_drv_deconfig; @@ -212,7 +212,7 @@ void wd_dh_uninit(void) if (ret) return; - wd_alg_uninit_driver_nw(&wd_dh_setting.config); + wd_alg_uninit_driver(&wd_dh_setting.config); wd_ctx_drv_deconfig(&wd_dh_setting.config); wd_dh_close_driver(WD_TYPE_V1); @@ -251,7 +251,7 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param /* Init ctx param and prepare for ctx request */ dh_ctx_params.ctx_set_num = dh_ctx_num; - ret = wd_ctx_param_init_nw(&dh_ctx_params, ctx_params, + ret = wd_ctx_param_init(&dh_ctx_params, ctx_params, alg, task_type, WD_DH_TYPE, WD_DH_PHASE2); if (ret) { if (ret == -WD_EAGAIN) @@ -280,7 +280,7 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_dh_setting.config); + ret = wd_alg_init_driver(&wd_dh_setting.config); if (ret) goto out_drv_deconfig; diff --git a/wd_digest.c b/wd_digest.c index fc42796..4d46cc5 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -344,7 +344,7 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_digest_setting.config); + ret = wd_alg_init_driver(&wd_digest_setting.config); if (ret) goto out_drv_deconfig; @@ -368,7 +368,7 @@ void wd_digest_uninit(void) if (!wd_digest_setting.priv) return; - wd_alg_uninit_driver_nw(&wd_digest_setting.config); + wd_alg_uninit_driver(&wd_digest_setting.config); wd_ctx_drv_deconfig(&wd_digest_setting.config); wd_digest_uninit_nolock(); @@ -420,7 +420,7 @@ int wd_digest_init2_(char *alg, __u32 sched_type, int task_type, /* Init ctx param and prepare for ctx request */ digest_ctx_params.ctx_set_num = &digest_ctx_num; - ret = wd_ctx_param_init_nw(&digest_ctx_params, ctx_params, + ret = wd_ctx_param_init(&digest_ctx_params, ctx_params, alg, task_type, WD_DIGEST_TYPE, 1); if (ret) { if (ret == -WD_EAGAIN) { @@ -449,7 +449,7 @@ int wd_digest_init2_(char *alg, __u32 sched_type, int task_type, if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_digest_setting.config); + ret = wd_alg_init_driver(&wd_digest_setting.config); if (ret) goto out_drv_deconfig; diff --git a/wd_ecc.c b/wd_ecc.c index 75507e8..3c4088b 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -250,7 +250,7 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_ecc_setting.config); + ret = wd_alg_init_driver(&wd_ecc_setting.config); if (ret) goto out_drv_deconfig; @@ -273,7 +273,7 @@ void wd_ecc_uninit(void) { int ret; - wd_alg_uninit_driver_nw(&wd_ecc_setting.config); + wd_alg_uninit_driver(&wd_ecc_setting.config); wd_ctx_drv_deconfig(&wd_ecc_setting.config); ret = wd_ecc_common_uninit(); if (ret) @@ -317,7 +317,7 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para /* Init ctx param and prepare for ctx request */ ecc_ctx_params.ctx_set_num = ecc_ctx_num; - ret = wd_ctx_param_init_nw(&ecc_ctx_params, ctx_params, + ret = wd_ctx_param_init(&ecc_ctx_params, ctx_params, alg, task_type, WD_ECC_TYPE, WD_EC_OP_MAX); if (ret) { if (ret == -WD_EAGAIN) @@ -347,7 +347,7 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_ecc_setting.config); + ret = wd_alg_init_driver(&wd_ecc_setting.config); if (ret) goto out_drv_deconfig; diff --git a/wd_join_gather.c b/wd_join_gather.c index 52cd5f9..0199f35 100644 --- a/wd_join_gather.c +++ b/wd_join_gather.c @@ -784,7 +784,7 @@ int wd_join_gather_init(char *alg, __u32 sched_type, int task_type, /* Init ctx param and prepare for ctx request */ join_gather_ctx_params.ctx_set_num = &join_gather_ctx_num; - ret = wd_ctx_param_init_nw(&join_gather_ctx_params, ctx_params, + ret = wd_ctx_param_init(&join_gather_ctx_params, ctx_params, alg, task_type, WD_JOIN_GATHER_TYPE, 1); if (ret) { if (ret == -WD_EAGAIN) { @@ -813,7 +813,7 @@ int wd_join_gather_init(char *alg, __u32 sched_type, int task_type, if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_join_gather_setting.config); + ret = wd_alg_init_driver(&wd_join_gather_setting.config); if (ret) goto out_drv_deconfig; @@ -844,7 +844,7 @@ void wd_join_gather_uninit(void) if (ret) return; - wd_alg_uninit_driver_nw(&wd_join_gather_setting.config); + wd_alg_uninit_driver(&wd_join_gather_setting.config); wd_ctx_drv_deconfig(&wd_join_gather_setting.config); wd_alg_attrs_uninit(&wd_join_gather_init_attrs); diff --git a/wd_rsa.c b/wd_rsa.c index 1104c2a..8606efb 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -225,7 +225,7 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_rsa_setting.config); + ret = wd_alg_init_driver(&wd_rsa_setting.config); if (ret) goto out_drv_deconfig; @@ -248,7 +248,7 @@ void wd_rsa_uninit(void) { int ret; - wd_alg_uninit_driver_nw(&wd_rsa_setting.config); + wd_alg_uninit_driver(&wd_rsa_setting.config); wd_ctx_drv_deconfig(&wd_rsa_setting.config); ret = wd_rsa_common_uninit(); if (ret) @@ -290,7 +290,7 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para /* Init ctx param and prepare for ctx request */ rsa_ctx_params.ctx_set_num = rsa_ctx_num; - ret = wd_ctx_param_init_nw(&rsa_ctx_params, ctx_params, + ret = wd_ctx_param_init(&rsa_ctx_params, ctx_params, alg, task_type, WD_RSA_TYPE, WD_RSA_GENKEY); if (ret) { if (ret == -WD_EAGAIN) @@ -320,7 +320,7 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_rsa_setting.config); + ret = wd_alg_init_driver(&wd_rsa_setting.config); if (ret) goto out_drv_deconfig; diff --git a/wd_udma.c b/wd_udma.c index d30f870..9db6d87 100644 --- a/wd_udma.c +++ b/wd_udma.c @@ -374,7 +374,7 @@ void wd_udma_uninit(void) if (status == WD_UNINIT) return; - wd_alg_uninit_driver_nw(&wd_udma_setting.config); + wd_alg_uninit_driver(&wd_udma_setting.config); wd_ctx_drv_deconfig(&wd_udma_setting.config); wd_udma_alg_uninit(); @@ -452,7 +452,7 @@ int wd_udma_init(const char *alg, __u32 sched_type, int task_type, /* Init ctx param and prepare for ctx request */ udma_ctx_params.ctx_set_num = udma_ctx_num; - ret = wd_ctx_param_init_nw(&udma_ctx_params, ctx_params, + ret = wd_ctx_param_init(&udma_ctx_params, ctx_params, alg, task_type, WD_UDMA_TYPE, WD_UDMA_OP_MAX); if (ret) { if (ret == -WD_EAGAIN) { @@ -482,7 +482,7 @@ int wd_udma_init(const char *alg, __u32 sched_type, int task_type, if (ret) goto out_uninit_nolock; - ret = wd_alg_init_driver_nw(&wd_udma_setting.config); + ret = wd_alg_init_driver(&wd_udma_setting.config); if (ret) goto out_drv_deconfig; diff --git a/wd_util.c b/wd_util.c index 09c8f9a..c76f39b 100644 --- a/wd_util.c +++ b/wd_util.c @@ -2084,13 +2084,7 @@ static void wd_ctx_uninit_driver(struct wd_ctx_config_internal *config, } } -int wd_alg_init_driver(struct wd_ctx_config_internal *config, - struct wd_alg_driver *driver, void **drv_priv) -{ - return 0; -} - -int wd_alg_init_driver_nw(struct wd_ctx_config_internal *config) +int wd_alg_init_driver(struct wd_ctx_config_internal *config) { __u32 i, j; int ret; @@ -2113,12 +2107,7 @@ init_err: return ret; } -void wd_alg_uninit_driver(struct wd_ctx_config_internal *config, - struct wd_alg_driver *driver, void **drv_priv) -{ -} - -void wd_alg_uninit_driver_nw(struct wd_ctx_config_internal *config) +void wd_alg_uninit_driver(struct wd_ctx_config_internal *config) { __u32 i; @@ -2253,8 +2242,8 @@ void wd_ctx_param_uninit(struct wd_ctx_params *ctx_params) int wd_ctx_param_init(struct wd_ctx_params *ctx_params, struct wd_ctx_params *user_ctx_params, - struct wd_alg_driver *driver, - enum wd_type type, int max_op_type) + char *alg, int task_type, enum wd_type type, + int max_op_type) { const char *env_name = wd_env_name[type]; const char *var_s; @@ -2268,9 +2257,9 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, /* Only hw driver support environment variable */ var_s = secure_getenv(env_name); - if (var_s && strlen(var_s) && driver->calc_type == UADK_ALG_HW) { + if (var_s && strlen(var_s) && task_type <= TASK_HW) { /* environment variable has the highest priority */ - ret = wd_env_set_ctx_nums(driver->alg_name, env_name, var_s, + ret = wd_env_set_ctx_nums(alg, env_name, var_s, ctx_params, max_op_type); if (ret) { WD_ERR("fail to init ctx nums from %s!\n", env_name); @@ -2294,83 +2283,17 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, } } - /* user_ctx_params is also not set, use defalut queue_num max_op_type */ + /* user_ctx_params is also not set, use driver's defalut queue_num */ numa_bitmask_setall(ctx_params->bmp); for (i = 0; i < max_op_type; i++) { ctx_params->ctx_set_num[i].sync_ctx_num = max_op_type; ctx_params->ctx_set_num[i].async_ctx_num = max_op_type; } - ctx_params->op_type_num = max_op_type; return 0; } -int wd_ctx_param_init_nw(struct wd_ctx_params *ctx_params, - struct wd_ctx_params *user_ctx_params, - char *alg, int task_type, enum wd_type type, - int max_op_type) -{ - const char *env_name = wd_env_name[type]; - const char *var_s; - int i, ret; - - ctx_params->bmp = numa_allocate_nodemask(); - if (!ctx_params->bmp) { - WD_ERR("fail to allocate nodemask.\n"); - return -WD_ENOMEM; - } - - /* Only hw driver support environment variable */ - var_s = secure_getenv(env_name); - if (var_s && strlen(var_s) && task_type <= TASK_HW) { - /* environment variable has the highest priority */ - ret = wd_env_set_ctx_nums(alg, env_name, var_s, - ctx_params, max_op_type); - if (ret) { - WD_ERR("fail to init ctx nums from %s!\n", env_name); - numa_free_nodemask(ctx_params->bmp); - return ret; - } - } else { - /* environment variable is not set, try to use user_ctx_params first */ - if (user_ctx_params) { - if (user_ctx_params->bmp) { - copy_bitmask_to_bitmask(user_ctx_params->bmp, ctx_params->bmp); - } else { - /* default value */ - numa_bitmask_setall(ctx_params->bmp); - } - ctx_params->cap = user_ctx_params->cap; - ctx_params->ctx_set_num = user_ctx_params->ctx_set_num; - ctx_params->op_type_num = user_ctx_params->op_type_num; - if (ctx_params->op_type_num > (__u32)max_op_type) { - WD_ERR("fail to check user op type numbers.\n"); - numa_free_nodemask(ctx_params->bmp); - return -WD_EINVAL; - } - - return 0; - } - - /* user_ctx_params is also not set, use driver's defalut queue_num */ - numa_bitmask_setall(ctx_params->bmp); - for (i = 0; i < driver->op_type_num; i++) { - ctx_params->ctx_set_num[i].sync_ctx_num = driver->queue_num; - ctx_params->ctx_set_num[i].async_ctx_num = driver->queue_num; - } - } - - ctx_params->op_type_num = driver->op_type_num; - if (ctx_params->op_type_num > (__u32)max_op_type) { - WD_ERR("fail to check driver op type numbers.\n"); - numa_free_nodemask(ctx_params->bmp); - return -WD_EAGAIN; - } - - return 0; -} - static void dladdr_empty(void) { } -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> Completed the update of uadk test tool function to adapt to heterogeneous scheduling function Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- uadk_tool/benchmark/sec_uadk_benchmark.c | 93 ++++++++++++++---------- uadk_tool/benchmark/uadk_benchmark.c | 3 +- uadk_tool/benchmark/uadk_benchmark.h | 1 + 3 files changed, 59 insertions(+), 38 deletions(-) diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index 4a64c94..dbf12cf 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -845,6 +845,7 @@ static void uninit_ctx_config2(int subtype) wd_aead_uninit2(); break; case DIGEST_TYPE: + case DIGEST_INSTR_TYPE: wd_digest_uninit2(); break; default: @@ -853,13 +854,15 @@ static void uninit_ctx_config2(int subtype) } } +struct wd_ctx_nums ctx_set_num[2]; +struct wd_ctx_nums ce_ctx_set_num[2]; +struct wd_cap_config cap; + static int init_ctx_config2(struct acc_option *options) { - struct wd_ctx_params cparams = {0}; - struct wd_ctx_nums *ctx_set_num; int subtype = options->subtype; - int mode = options->syncmode; char alg_name[MAX_ALG_NAME]; + struct wd_ctx_params ctx_params = {0}; int ret; ret = get_alg_name(options->algtype, alg_name); @@ -868,70 +871,77 @@ static int init_ctx_config2(struct acc_option *options) return -EINVAL; } - ctx_set_num = calloc(1, sizeof(*ctx_set_num)); - if (!ctx_set_num) { - WD_ERR("failed to alloc ctx_set_size!\n"); - return -WD_ENOMEM; - } - - cparams.op_type_num = 1; - cparams.ctx_set_num = ctx_set_num; - cparams.bmp = numa_allocate_nodemask(); - if (!cparams.bmp) { - WD_ERR("failed to create nodemask!\n"); - ret = -WD_ENOMEM; - goto out_freectx; - } - - numa_bitmask_setall(cparams.bmp); - - if (mode == CTX_MODE_SYNC) - ctx_set_num->sync_ctx_num = g_ctxnum; - else - ctx_set_num->async_ctx_num = g_ctxnum; + cap.ctx_msg_num = 1024; + // HW ctx set + ctx_set_num[0].sync_ctx_num = options->ctxnums; + ctx_set_num[0].async_ctx_num = options->ctxnums; + ctx_set_num[1].sync_ctx_num = options->ctxnums; + ctx_set_num[1].async_ctx_num = options->ctxnums; + // CE ctx set + ce_ctx_set_num[0].sync_ctx_num = options->ctxnums; + ce_ctx_set_num[0].async_ctx_num = options->ctxnums; + ce_ctx_set_num[0].ctx_prop = UADK_CTX_CE_INS; + ce_ctx_set_num[0].other_ctx = NULL; + ce_ctx_set_num[1].sync_ctx_num = options->ctxnums; + ce_ctx_set_num[1].async_ctx_num = options->ctxnums; + ce_ctx_set_num[1].ctx_prop = UADK_CTX_CE_INS; + ce_ctx_set_num[1].other_ctx = NULL; + + ctx_set_num[0].other_ctx = &ce_ctx_set_num[0]; + ctx_set_num[1].other_ctx = &ce_ctx_set_num[1]; + + ctx_params.op_type_num = 2; + ctx_params.bmp = numa_allocate_nodemask(); + numa_bitmask_setbit(ctx_params.bmp, 0); + numa_bitmask_setbit(ctx_params.bmp, 1); + ctx_params.cap = ∩ + ctx_params.ctx_set_num = &ctx_set_num[0]; /* init */ switch(subtype) { case CIPHER_TYPE: if (options->mem_type == UADK_AUTO) - ret = wd_cipher_init2_(alg_name, SCHED_POLICY_RR, TASK_HW, &cparams); + ret = wd_cipher_init2_(alg_name, SCHED_POLICY_HUNGRY, TASK_HW, &ctx_params); else - ret = wd_cipher_init2_(alg_name, SCHED_POLICY_DEV, TASK_HW, &cparams); + ret = wd_cipher_init2_(alg_name, SCHED_POLICY_DEV, TASK_HW, &ctx_params); if (ret) SEC_TST_PRT("failed to do cipher init2!\n"); break; case CIPHER_INSTR_TYPE: - ret = wd_cipher_init2(alg_name, SCHED_POLICY_NONE, TASK_INSTR); + ret = wd_cipher_init2(alg_name, SCHED_POLICY_INSTR, TASK_INSTR); if (ret) SEC_TST_PRT("failed to do cipher intruction init2!\n"); break; case AEAD_TYPE: if (options->mem_type == UADK_AUTO) - ret = wd_aead_init2_(alg_name, SCHED_POLICY_RR, TASK_HW, &cparams); + ret = wd_aead_init2_(alg_name, SCHED_POLICY_RR, TASK_HW, &ctx_params); else - ret = wd_aead_init2_(alg_name, SCHED_POLICY_DEV, TASK_HW, &cparams); + ret = wd_aead_init2_(alg_name, SCHED_POLICY_DEV, TASK_HW, &ctx_params); if (ret) SEC_TST_PRT("failed to do aead init2!\n"); break; case DIGEST_TYPE: - if (options->mem_type == UADK_AUTO) - ret = wd_digest_init2_(alg_name, SCHED_POLICY_RR, options->task_type, &cparams); - else - ret = wd_digest_init2_(alg_name, SCHED_POLICY_DEV, options->task_type, &cparams); + if (options->mem_type == UADK_AUTO) { + ctx_params.op_type_num = 1; + ret = wd_digest_init2_(alg_name, SCHED_POLICY_RR, options->task_type, &ctx_params); + } else + ret = wd_digest_init2_(alg_name, SCHED_POLICY_DEV, options->task_type, &ctx_params); if (ret) SEC_TST_PRT("failed to do digest init2!\n"); break; + case DIGEST_INSTR_TYPE: + ctx_params.op_type_num = 1; + ret = wd_digest_init2_(alg_name, SCHED_POLICY_INSTR, TASK_INSTR, &ctx_params); + if (ret) + SEC_TST_PRT("failed to do digest instruction init2!\n"); + break; } if (ret) { SEC_TST_PRT("failed to do cipher init2!\n"); return ret; } -out_freectx: - free(ctx_set_num); - return ret; - } static void get_aead_data(u8 *addr, u32 size) @@ -1715,6 +1725,12 @@ static void *sec_uadk_poll2(void *data) case DIGEST_TYPE: uadk_poll_policy = wd_digest_poll; break; + case CIPHER_INSTR_TYPE: + uadk_poll_policy = wd_cipher_poll; + break; + case DIGEST_INSTR_TYPE: + uadk_poll_policy = wd_digest_poll; + break; default: SEC_TST_PRT("<<<<<<async poll interface is NULL!\n"); return NULL; @@ -2362,6 +2378,7 @@ int sec_uadk_sync_threads(struct acc_option *options) uadk_sec_sync_run = sec_uadk_aead_sync; break; case DIGEST_TYPE: + case DIGEST_INSTR_TYPE: uadk_sec_sync_run = sec_uadk_digest_sync; break; default: @@ -2418,12 +2435,14 @@ int sec_uadk_async_threads(struct acc_option *options) switch (options->subtype) { case CIPHER_TYPE: + case CIPHER_INSTR_TYPE: uadk_sec_async_run = sec_uadk_cipher_async; break; case AEAD_TYPE: uadk_sec_async_run = sec_uadk_aead_async; break; case DIGEST_TYPE: + case DIGEST_INSTR_TYPE: uadk_sec_async_run = sec_uadk_digest_async; break; } diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index 09e99e2..bfab093 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -493,9 +493,10 @@ static void parse_alg_param(struct acc_option *option) option->subtype = DIGEST_TYPE; option->acctype = SEC_TYPE; if (option->modetype == INSTR_MODE) { - option->sched_type = SCHED_POLICY_NONE; + option->subtype = DIGEST_INSTR_TYPE; option->task_type = TASK_INSTR; } else if (option->modetype == MULTIBUF_MODE) { + option->subtype = DIGEST_INSTR_TYPE; option->sched_type = SCHED_POLICY_SINGLE; option->task_type = TASK_INSTR; } diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index 83fd7fa..816232b 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -117,6 +117,7 @@ enum alg_type { X25519_TYPE, X448_TYPE, CIPHER_INSTR_TYPE, + DIGEST_INSTR_TYPE, }; enum sync_type { -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> Remove redundant alert log messages indicating "get msg busy" for all asynchronous mode algorithmic workloads in UADK, which were causing repeated screen flooding. Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- wd_aead.c | 2 +- wd_agg.c | 4 ++-- wd_cipher.c | 4 ++-- wd_comp.c | 4 ++-- wd_dh.c | 4 ++-- wd_digest.c | 4 ++-- wd_ecc.c | 4 ++-- wd_join_gather.c | 4 ++-- wd_rsa.c | 4 ++-- wd_udma.c | 4 ++-- wd_util.c | 3 ++- 11 files changed, 21 insertions(+), 20 deletions(-) diff --git a/wd_aead.c b/wd_aead.c index fcf23bb..037cc40 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -941,7 +941,7 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req) msg_id = wd_get_msg_from_pool(&wd_aead_setting.pool, idx, (void **)&msg); if (unlikely(msg_id < 0)) { - WD_ERR("failed to get msg from pool!\n"); + //WD_ERR("failed to get msg from pool!\n"); return -WD_EBUSY; } diff --git a/wd_agg.c b/wd_agg.c index f07642d..4a97621 100644 --- a/wd_agg.c +++ b/wd_agg.c @@ -1228,8 +1228,8 @@ static int wd_agg_async_job(struct wd_agg_sess *sess, struct wd_agg_req *req, bo ctx = config->ctxs + idx; msg_id = wd_get_msg_from_pool(&wd_agg_setting.pool, idx, (void **)&msg); if (unlikely(msg_id < 0)) { - WD_ERR("failed to get agg msg from pool!\n"); - return msg_id; + //WD_ERR("failed to get agg msg from pool!\n"); + return -WD_EBUSY; } if (is_input) diff --git a/wd_cipher.c b/wd_cipher.c index 96bb21c..f8089a3 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -784,8 +784,8 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req) msg_id = wd_get_msg_from_pool(&wd_cipher_setting.pool, idx, (void **)&msg); if (unlikely(msg_id < 0)) { - WD_ERR("failed to get msg from pool!\n"); - return msg_id; + //WD_ERR("failed to get msg from pool!\n"); + return -WD_EBUSY; } fill_request_msg(msg, req, sess); diff --git a/wd_comp.c b/wd_comp.c index b4cba28..d4e22eb 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -934,8 +934,8 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req) tag = wd_get_msg_from_pool(&wd_comp_setting.pool, idx, (void **)&msg); if (unlikely(tag < 0)) { - WD_ERR("failed to get msg from pool!\n"); - return tag; + //WD_ERR("failed to get msg from pool!\n"); + return -WD_EBUSY; } fill_comp_msg(sess, msg, req); msg->tag = tag; diff --git a/wd_dh.c b/wd_dh.c index e7322d1..3395060 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -423,8 +423,8 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req) mid = wd_get_msg_from_pool(&wd_dh_setting.pool, idx, (void **)&msg); if (unlikely(mid < 0)) { - WD_ERR("failed to get msg from pool!\n"); - return mid; + //WD_ERR("failed to get msg from pool!\n"); + return -WD_EBUSY; } ret = fill_dh_msg(msg, req, (struct wd_dh_sess *)sess); diff --git a/wd_digest.c b/wd_digest.c index 4d46cc5..8e5bf94 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -730,8 +730,8 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req) msg_id = wd_get_msg_from_pool(&wd_digest_setting.pool, idx, (void **)&msg); if (unlikely(msg_id < 0)) { - WD_ERR("failed to get msg from pool!\n"); - return msg_id; + //WD_ERR("failed to get msg from pool!\n"); + return -WD_EBUSY; } fill_request_msg(msg, req, dsess); diff --git a/wd_ecc.c b/wd_ecc.c index 3c4088b..c31495f 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -2300,8 +2300,8 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req) ctx = config->ctxs + idx; mid = wd_get_msg_from_pool(&wd_ecc_setting.pool, idx, (void **)&msg); if (unlikely(mid < 0)) { - WD_ERR("failed to get msg from pool!\n"); - return mid; + //WD_ERR("failed to get msg from pool!\n"); + return -WD_EBUSY; } ret = fill_ecc_msg(msg, req, (struct wd_ecc_sess *)sess); diff --git a/wd_join_gather.c b/wd_join_gather.c index 0199f35..bd7d4d4 100644 --- a/wd_join_gather.c +++ b/wd_join_gather.c @@ -1321,8 +1321,8 @@ static int wd_join_gather_async_job(struct wd_join_gather_sess *sess, ctx = config->ctxs + idx; msg_id = wd_get_msg_from_pool(&setting->pool, idx, (void **)&msg); if (msg_id < 0) { - WD_ERR("failed to get join gather msg from pool!\n"); - return msg_id; + //WD_ERR("failed to get join gather msg from pool!\n"); + return -WD_EBUSY; } fill_join_gather_msg(msg, req, sess); diff --git a/wd_rsa.c b/wd_rsa.c index 8606efb..c020514 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -484,8 +484,8 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req) mid = wd_get_msg_from_pool(&wd_rsa_setting.pool, idx, (void **)&msg); if (unlikely(mid < 0)) { - WD_ERR("failed to get msg from pool!\n"); - return mid; + //WD_ERR("failed to get msg from pool!\n"); + return -WD_EBUSY; } ret = fill_rsa_msg(msg, req, (struct wd_rsa_sess *)sess); diff --git a/wd_udma.c b/wd_udma.c index 9db6d87..13c4331 100644 --- a/wd_udma.c +++ b/wd_udma.c @@ -268,8 +268,8 @@ int wd_do_udma_async(handle_t sess, struct wd_udma_req *req) mid = wd_get_msg_from_pool(&wd_udma_setting.pool, idx, (void **)&msg); if (unlikely(mid < 0)) { - WD_ERR("failed to get msg from pool!\n"); - return mid; + //WD_ERR("failed to get msg from pool!\n"); + return -WD_EBUSY; } fill_udma_msg(msg, req); diff --git a/wd_util.c b/wd_util.c index c76f39b..4830fd4 100644 --- a/wd_util.c +++ b/wd_util.c @@ -3203,7 +3203,7 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs) goto out_freesched; } - WD_ERR("debug: call function: %s!\n", __func__); + WD_ERR("TASK_MIX: call function: %s!\n", __func__); drv = wd_request_drv(alg_name, ALG_DRV_SOFT); if (drv == NULL) { WD_ERR("fail to find soft driver.\n"); @@ -3231,6 +3231,7 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs) goto out_freesched; } + WD_ERR("TASK_INSTR: call function: %s!\n", __func__); drv = wd_request_drv(alg_name, ALG_DRV_SOFT); if (drv == NULL) { WD_ERR("fail to find soft driver.\n"); -- 2.43.0
From: Longfang Liu <liulongfang@huawei.com> Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- include/wd.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/wd.h b/include/wd.h index 6329528..999af06 100644 --- a/include/wd.h +++ b/include/wd.h @@ -44,7 +44,8 @@ typedef struct wd_dev_mask wd_dev_mask_t; typedef void (*wd_log)(const char *format, ...); -#ifndef WD_NO_LOG +//#ifndef WD_NO_LOG +#if 0 #define WD_DEBUG(fmt, args...) \ do {\ openlog("uadk-debug", LOG_CONS | LOG_PID, LOG_LOCAL5);\ -- 2.43.0
participants (1)
-
ZongYu Wu