From: Wenkai Lin <linwenkai6@hisilicon.com> For data digest algorithms, the API layer needs to be adapted to the new UADK heterogeneous hybrid acceleration framework, thereby ensuring that hash algorithms and authentication algorithm acceleration functions can adapt to and support the new hybrid acceleration framework, while supporting the fusion of hardware acceleration, instruction acceleration, and vector acceleration capabilities. Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com> Signed-off-by: Zhushuai Yin <yinzhushuai@huawei.com> --- drv/hash_mb/hash_mb.c | 100 ++++++++++---------- drv/isa_ce_sm3.c | 46 ++++----- wd_digest.c | 212 ++++++++++++++++++++++++++---------------- 3 files changed, 210 insertions(+), 148 deletions(-) diff --git a/drv/hash_mb/hash_mb.c b/drv/hash_mb/hash_mb.c index bd412b2..e0f3fd0 100644 --- a/drv/hash_mb/hash_mb.c +++ b/drv/hash_mb/hash_mb.c @@ -6,6 +6,7 @@ #include <stdlib.h> #include <string.h> #include "hash_mb.h" +#include "../wd_drv.h" #define MIN(a, b) (((a) > (b)) ? (b) : (a)) #define IPAD_VALUE 0x36 @@ -109,12 +110,20 @@ static void hash_mb_queue_uninit(struct wd_ctx_config_internal *config, int ctx_ int i; for (i = 0; i < ctx_num; i++) { + if (strcmp(config->ctxs[i].drv->drv_name, "hash_mb") || + config->ctxs[i].drv->calc_type != UADK_ALG_SVE_INSTR) + continue; + ctx = (struct wd_soft_ctx *)config->ctxs[i].ctx; mb_queue = ctx->priv; + if (!mb_queue) + continue; + pthread_spin_destroy(&mb_queue->r_lock); hash_mb_uninit_poll_queue(&mb_queue->sm3_poll_queue); hash_mb_uninit_poll_queue(&mb_queue->md5_poll_queue); free(mb_queue); + ctx->priv = NULL; } } @@ -143,11 +152,16 @@ static int hash_mb_queue_init(struct wd_ctx_config_internal *config) int i, ret; for (i = 0; i < ctx_num; i++) { - mb_queue = calloc(1, sizeof(struct hash_mb_queue)); + if (strcmp(config->ctxs[i].drv->drv_name, "hash_mb") || + config->ctxs[i].drv->calc_type != UADK_ALG_SVE_INSTR) + continue; + + mb_queue = malloc(sizeof(struct hash_mb_queue)); if (!mb_queue) { ret = -WD_ENOMEM; goto free_mb_queue; } + memset(mb_queue, 0, sizeof(struct hash_mb_queue)); mb_queue->ctx_mode = config->ctxs[i].ctx_mode; ctx = (struct wd_soft_ctx *)config->ctxs[i].ctx; @@ -168,9 +182,6 @@ static int hash_mb_queue_init(struct wd_ctx_config_internal *config) mb_queue->sm3_poll_queue.ops = &sm3_ops; mb_queue->md5_poll_queue.ops = &md5_ops; - mb_queue->recv_head = NULL; - mb_queue->recv_tail = NULL; - mb_queue->complete_cnt = 0; } return WD_SUCCESS; @@ -186,46 +197,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 +266,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 +554,21 @@ 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 void hash_mb_add_finish_job(struct hash_mb_queue *mb_queue, struct hash_job *job) +{ + pthread_spin_lock(&mb_queue->r_lock); + if (mb_queue->complete_cnt) { + mb_queue->recv_tail->next = job; + mb_queue->recv_tail = job; + } else { + mb_queue->recv_head = job; + mb_queue->recv_tail = job; + } + mb_queue->complete_cnt++; + pthread_spin_unlock(&mb_queue->r_lock); +} + +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; @@ -597,8 +610,10 @@ static int hash_mb_send(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg) /* If block not need process, return directly. */ ret = hash_do_partial(poll_queue, d_msg, hash_job); if (ret == -WD_EAGAIN) { - if (mb_queue->ctx_mode == CTX_MODE_ASYNC) - free(hash_job); + if (mb_queue->ctx_mode == CTX_MODE_ASYNC) { + hash_job->msg = d_msg; + hash_mb_add_finish_job(mb_queue, hash_job); + } d_msg->result = WD_SUCCESS; return WD_SUCCESS; @@ -691,20 +706,6 @@ static struct hash_job *hash_mb_get_job(struct hash_mb_poll_queue *poll_queue) return job; } -static void hash_mb_add_finish_job(struct hash_mb_queue *mb_queue, struct hash_job *job) -{ - pthread_spin_lock(&mb_queue->r_lock); - if (mb_queue->complete_cnt) { - mb_queue->recv_tail->next = job; - mb_queue->recv_tail = job; - } else { - mb_queue->recv_head = job; - mb_queue->recv_tail = job; - } - mb_queue->complete_cnt++; - pthread_spin_unlock(&mb_queue->r_lock); -} - static struct hash_mb_poll_queue *hash_get_poll_queue(struct hash_mb_queue *mb_queue) { if (!mb_queue->sm3_poll_queue.job_num && @@ -776,7 +777,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 +811,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,\ @@ -818,6 +820,8 @@ static int hash_mb_get_usage(void *param) .send = hash_mb_send,\ .recv = hash_mb_recv,\ .get_usage = hash_mb_get_usage,\ + .alloc_ctx = wd_soft_alloc_ctx,\ + .free_ctx = wd_soft_free_ctx,\ } static struct wd_alg_driver hash_mb_driver[] = { diff --git a/drv/isa_ce_sm3.c b/drv/isa_ce_sm3.c index 627ab68..b41f6c5 100644 --- a/drv/isa_ce_sm3.c +++ b/drv/isa_ce_sm3.c @@ -338,8 +338,9 @@ 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_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; @@ -349,6 +350,10 @@ static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest 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; @@ -370,42 +375,41 @@ static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest ret = -WD_EINVAL; } + ret = wd_get_sqe_from_queue(sfctx, msg->tag); + if (ret) + return ret; + 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) { + 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; } -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 || !priv) 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/wd_digest.c b/wd_digest.c index e0341e6..2388346 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 *dlhandle; void *dlh_list; @@ -85,20 +84,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; @@ -132,14 +127,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; } @@ -217,6 +204,7 @@ static int digest_setup_memory_and_buffers(struct wd_digest_sess *sess, handle_t wd_digest_alloc_sess(struct wd_digest_sess_setup *setup) { struct wd_digest_sess *sess = NULL; + struct wd_sched_params params; bool ret; if (unlikely(!setup)) { @@ -237,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; @@ -255,6 +243,14 @@ handle_t wd_digest_alloc_sess(struct wd_digest_sess_setup *setup) goto err_key; } + /* Set compat filtering parameters for session-ctx matching */ + memset(¶ms, 0, sizeof(params)); + params.alg_name = sess->alg_name; + params.ctxs = wd_digest_setting.config.ctxs; + wd_digest_setting.sched.set_param( + wd_digest_setting.sched.h_sched_ctx, + sess->sched_key, ¶ms); + return (handle_t)sess; err_key: @@ -275,11 +271,19 @@ void wd_digest_free_sess(handle_t h_sess) wd_memset_zero(sess->key, sess->key_bytes); sess->mm_ops.free(sess->mm_ops.usr, sess->key); - if (sess->sched_key) - free(sess->sched_key); + if (sess->sched_key) { + if (wd_digest_setting.sched.sched_uninit) + wd_digest_setting.sched.sched_uninit( + wd_digest_setting.sched.h_sched_ctx, + (handle_t)sess->sched_key); + else + free(sess->sched_key); + } free(sess); } +static bool wd_digest_atfork_registered; + static void wd_digest_clear_status(void) { wd_alg_clear_init(&wd_digest_setting.status); @@ -311,15 +315,8 @@ 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); - if (ret) - goto out_clear_pool; - 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: @@ -328,11 +325,21 @@ 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); +} + int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched) { + __u32 drv_count = 0; int ret; - pthread_atfork(NULL, NULL, wd_digest_clear_status); + if (!wd_digest_atfork_registered) { + if (pthread_atfork(NULL, NULL, wd_digest_clear_status) == 0) + wd_digest_atfork_registered = true; + } ret = wd_alg_try_init(&wd_digest_setting.status); if (ret) @@ -342,6 +349,14 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_clear_init; + /* init1 path is HW-only; CE/SVE drivers require init2 */ + if (sched->sched_policy == SCHED_POLICY_NONE || + sched->sched_policy == SCHED_POLICY_SINGLE) { + WD_ERR("init1 does not support NONE/SINGLE schedulers, use init2\n"); + ret = -WD_EINVAL; + goto out_clear_init; + } + ret = wd_digest_open_driver(WD_TYPE_V1); if (ret) goto out_clear_init; @@ -350,10 +365,38 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched) if (ret) goto out_close_driver; + ret = wd_get_drv_array("digest", TASK_HW, "hisi_sec2", + &wd_digest_setting.config.drv_array, &drv_count); + if (ret) { + WD_ERR("failed to get driver array for digest!\n"); + goto out_common_uninit; + } + + wd_digest_setting.config.drv_count = drv_count; + ret = wd_ctx_bind_drivers(&wd_digest_setting.config, NULL, WD_TYPE_V1); + if (ret) { + WD_ERR("failed to bind driver!\n"); + goto out_free_drv_array; + } + + ret = wd_alg_init_driver(&wd_digest_setting.config); + if (ret) { + WD_ERR("failed to init digest driver!\n"); + goto out_unbind_drivers; + } + wd_alg_set_init(&wd_digest_setting.status); return 0; +out_unbind_drivers: + wd_ctx_unbind_drivers(&wd_digest_setting.config); +out_free_drv_array: + wd_put_drv_array(wd_digest_setting.config.drv_array, drv_count); + wd_digest_setting.config.drv_array = NULL; + wd_digest_setting.config.drv_count = 0; +out_common_uninit: + wd_digest_uninit_nolock(); out_close_driver: wd_digest_close_driver(WD_TYPE_V1); out_clear_init: @@ -361,29 +404,22 @@ out_clear_init: return ret; } -static int wd_digest_uninit_nolock(void) +void wd_digest_uninit(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; -} - -void wd_digest_uninit(void) -{ - int ret; - - ret = wd_digest_uninit_nolock(); - if (ret) + if (status != WD_INIT) return; + wd_alg_uninit_driver(&wd_digest_setting.config); + wd_ctx_unbind_drivers(&wd_digest_setting.config); + wd_put_drv_array(wd_digest_setting.config.drv_array, + wd_digest_setting.config.drv_count); + wd_digest_setting.config.drv_array = NULL; + wd_digest_setting.config.drv_count = 0; + + wd_digest_uninit_nolock(); wd_digest_close_driver(WD_TYPE_V1); wd_alg_clear_init(&wd_digest_setting.status); } @@ -404,8 +440,12 @@ int wd_digest_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_params digest_ctx_params = {0}; struct wd_ctx_nums digest_ctx_num = {0}; int state, ret = -WD_EINVAL; + int try_cnt = 0; - pthread_atfork(NULL, NULL, wd_digest_clear_status); + if (!wd_digest_atfork_registered) { + if (pthread_atfork(NULL, NULL, wd_digest_clear_status) == 0) + wd_digest_atfork_registered = true; + } state = wd_alg_try_init(&wd_digest_setting.status); if (state) @@ -428,38 +468,30 @@ 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; + if (try_cnt++ >= WD_INIT2_MAX_RETRY) { + WD_ERR("failed to init2 after %d retries.\n", + WD_INIT2_MAX_RETRY); + goto out_dlclose; } - + memset(&wd_digest_setting.config, 0, sizeof(struct wd_ctx_config_internal)); 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); + alg, 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); + if (ret == -WD_EAGAIN) 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; } @@ -467,16 +499,34 @@ int wd_digest_init2_(char *alg, __u32 sched_type, int task_type, goto out_params_uninit; } } + + ret = wd_ctx_bind_drivers(&wd_digest_setting.config, + wd_digest_init_attrs.ctx_config_internal, + WD_TYPE_V2); + if (ret) { + WD_ERR("failed to bind driver for digest!\n"); + goto out_common_uninit; + } + + ret = wd_alg_init_driver(&wd_digest_setting.config); + if (ret) { + WD_ERR("failed to init driver for digest!\n"); + goto out_unbind_drivers; + } + wd_alg_set_init(&wd_digest_setting.status); wd_ctx_param_uninit(&digest_ctx_params); return 0; +out_unbind_drivers: + wd_ctx_unbind_drivers(&wd_digest_setting.config); +out_common_uninit: + 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); @@ -485,14 +535,18 @@ out_uninit: void wd_digest_uninit2(void) { - int ret; + enum wd_status status; - ret = wd_digest_uninit_nolock(); - if (ret) + wd_alg_get_init(&wd_digest_setting.status, &status); + if (status != WD_INIT) return; + wd_alg_uninit_driver(&wd_digest_setting.config); + wd_ctx_unbind_drivers(&wd_digest_setting.config); + wd_digest_setting.config.drv_array = NULL; + wd_digest_setting.config.drv_count = 0; + 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); } @@ -651,13 +705,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); - ret = wd_handle_msg_sync(wd_digest_setting.driver, &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_lock(ctx, ctx->ctx_type); + ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, + NULL, wd_digest_setting.config.epoll_en); + wd_ctx_spin_unlock(ctx, ctx->ctx_type); if (unlikely(ret)) return ret; @@ -742,15 +796,13 @@ 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; - } + if (unlikely(msg_id < 0)) + return -WD_EBUSY; fill_request_msg(msg, req, dsess); msg->tag = msg_id; - ret = wd_alg_driver_send(wd_digest_setting.driver, 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"); @@ -797,7 +849,7 @@ 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 = ctx->drv->recv(ctx->ctx, &recv_msg); if (ret == -WD_EAGAIN) { return ret; } else if (ret < 0) { @@ -816,8 +868,10 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count) msg->req.state = recv_msg.result; req = &msg->req; - if (likely(req)) + if (likely(req->cb)) req->cb(req); + else + WD_ERR("invalid: digest callback is NULL, tag %u!\n", recv_msg.tag); wd_put_msg_to_pool(&wd_digest_setting.pool, idx, recv_msg.tag); -- 2.43.0