
From: lizhi <lizhi206@huawei.com> Add algorithm driver as a function parameter. Do not enable high-performance core if hardware version is not met. Signed-off-by: lizhi <lizhi206@huawei.com> Signed-off-by: Qi Tao <taoqi10@huawei.com> --- drv/hisi_hpre.c | 27 +++++++++++++++++++++++---- include/drv/wd_ecc_drv.h | 9 +++++---- wd_ecc.c | 7 ++++--- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index e0cd7424..7ce842b8 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -2506,7 +2506,7 @@ static int hpre_get_usage(void *param) return WD_SUCCESS; } -static int ecc_sess_eops_init(void **params) +static int ecc_sess_eops_init(struct wd_alg_driver *drv, void **params) { struct hpre_ecc_ctx *ecc_ctx; @@ -2529,7 +2529,7 @@ static int ecc_sess_eops_init(void **params) return WD_SUCCESS; } -static void ecc_sess_eops_uninit(void *params) +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"); @@ -2539,13 +2539,32 @@ static void ecc_sess_eops_uninit(void *params) free(params); } -static void ecc_sess_eops_params_cfg(struct wd_ecc_sess_setup *setup, +static bool is_valid_hw_type(struct wd_alg_driver *drv) +{ + struct hisi_hpre_ctx *hpre_ctx; + struct hisi_qp *qp; + + if (unlikely(!drv || !drv->priv)) + return false; + + hpre_ctx = (struct hisi_hpre_ctx *)drv->priv; + 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 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) { __u8 data[SECP256R1_PARAM_SIZE] = SECG_P256_R1_PARAM; struct hpre_ecc_ctx *ecc_ctx = params; __u32 key_size; - int ret = 0; + int ret; + + if (!is_valid_hw_type(drv)) + return; if (!ecc_ctx) { WD_INFO("Info: eops config exits, but params is NULL!\n"); diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h index 085bd4ae..6193c8be 100644 --- a/include/drv/wd_ecc_drv.h +++ b/include/drv/wd_ecc_drv.h @@ -178,10 +178,11 @@ 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 *params); - int (*sess_init)(void **params); - void (*sess_uninit)(void *params); + void (*eops_params_cfg)(struct wd_alg_driver *drv, + struct wd_ecc_sess_setup *setup, + struct wd_ecc_curve *cv, void *params); + 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 36e5206f..f47df652 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -1178,7 +1178,7 @@ static int wd_ecc_sess_eops_init(struct wd_ecc_sess *sess) WD_ERR("failed to get extend ops in session!\n"); return -WD_EINVAL; } - ret = sess->eops.sess_init(&sess->eops.params); + 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; @@ -1190,7 +1190,7 @@ static int wd_ecc_sess_eops_init(struct wd_ecc_sess *sess) static void wd_ecc_sess_eops_uninit(struct wd_ecc_sess *sess) { if (sess->eops.sess_uninit) { - sess->eops.sess_uninit(sess->eops.params); + sess->eops.sess_uninit(wd_ecc_setting.driver, sess->eops.params); sess->eops.params = NULL; } } @@ -1200,7 +1200,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(setup, sess->key.cv, sess->eops.params); + sess->eops.eops_params_cfg(wd_ecc_setting.driver, setup, sess->key.cv, + sess->eops.params); } } -- 2.33.0