From: Wenkai Lin <linwenkai6@hisilicon.com> When the sgl pool is busy, the hisi_qm_get_hw_sgl function returns an error, causing the operation to fail. Now, this function returns the code -WD_EBUSY to inform the user to wait until the sgl pool is available again. Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com> --- drv/hisi_comp.c | 20 ++++++++++---------- drv/hisi_qm_udrv.c | 19 ++++++++++++------- drv/hisi_sec.c | 22 ++++++++-------------- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c index 36f3e3e..cf8d315 100644 --- a/drv/hisi_comp.c +++ b/drv/hisi_comp.c @@ -372,6 +372,7 @@ static int check_enable_store_buf(struct wd_comp_msg *msg, __u32 out_size, int h static int get_sgl_from_pool(handle_t h_qp, struct comp_sgl *c_sgl, struct wd_mm_ops *mm_ops) { handle_t h_sgl_pool; + int ret; h_sgl_pool = hisi_qm_get_sglpool(h_qp, mm_ops); if (unlikely(!h_sgl_pool)) { @@ -380,21 +381,19 @@ static int get_sgl_from_pool(handle_t h_qp, struct comp_sgl *c_sgl, struct wd_mm } c_sgl->in = hisi_qm_get_hw_sgl(h_sgl_pool, c_sgl->list_src); - if (unlikely(!c_sgl->in)) { - WD_ERR("failed to get hw sgl in!\n"); - return -WD_ENOMEM; - } + if (unlikely(WD_IS_ERR(c_sgl->in))) + return WD_PTR_ERR(c_sgl->in); c_sgl->out = hisi_qm_get_hw_sgl(h_sgl_pool, c_sgl->list_dst); - if (unlikely(!c_sgl->out)) { - WD_ERR("failed to get hw sgl out!\n"); + if (unlikely(WD_IS_ERR(c_sgl->out))) { + ret = WD_PTR_ERR(c_sgl->out); goto err_free_sgl_in; } if (c_sgl->seq_start) { c_sgl->out_seq = hisi_qm_get_hw_sgl(h_sgl_pool, c_sgl->seq_start); - if (unlikely(!c_sgl->out_seq)) { - WD_ERR("failed to get hw sgl out for sequences!\n"); + if (unlikely(WD_IS_ERR(c_sgl->out_seq))) { + ret = WD_PTR_ERR(c_sgl->out_seq); goto err_free_sgl_out; } } @@ -405,7 +404,7 @@ err_free_sgl_out: hisi_qm_put_hw_sgl(h_sgl_pool, c_sgl->out); err_free_sgl_in: hisi_qm_put_hw_sgl(h_sgl_pool, c_sgl->in); - return -WD_ENOMEM; + return ret; } static void free_hw_sgl(handle_t h_qp, struct comp_sgl *c_sgl, struct wd_mm_ops *mm_ops) @@ -1552,7 +1551,8 @@ static int hisi_zip_comp_send(struct wd_alg_driver *drv, handle_t ctx, void *com hisi_set_msg_id(h_qp, &msg->tag); ret = fill_zip_comp_sqe(qp, msg, &sqe); if (unlikely(ret < 0)) { - WD_ERR("failed to fill zip sqe, ret = %d!\n", ret); + if (ret != -WD_EBUSY) + WD_ERR("failed to fill zip sqe, ret = %d!\n", ret); return ret; } ret = hisi_qm_send(h_qp, &sqe, 1, &count); diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c index a47c596..6da9887 100644 --- a/drv/hisi_qm_udrv.c +++ b/drv/hisi_qm_udrv.c @@ -844,7 +844,7 @@ static struct hisi_sgl *hisi_qm_sgl_pop(struct hisi_sgl_pool *pool) if (pool->top == 0) { pthread_spin_unlock(&pool->lock); - WD_ERR("invalid: the sgl pool is empty!\n"); + WD_DEBUG("debug: the sgl pool is empty now!\n"); return NULL; } @@ -936,22 +936,23 @@ void *hisi_qm_get_hw_sgl(handle_t sgl_pool, struct wd_datalist *sgl) struct wd_datalist *tmp = sgl; struct hisi_sgl *head, *next, *cur; struct wd_mm_ops *mm_ops; + void *ret = NULL; __u32 i = 0; if (!pool || !sgl) { WD_ERR("invalid: hw sgl pool or sgl is NULL!\n"); - return NULL; + return WD_ERR_PTR(-WD_EINVAL); } if (pool->mm_ops && !pool->mm_ops->iova_map) { WD_ERR("invalid: mm_ops iova_map function is NULL!\n"); - return NULL; + return WD_ERR_PTR(-WD_EINVAL); } mm_ops = pool->mm_ops; head = hisi_qm_sgl_pop(pool); if (!head) - return NULL; + return WD_ERR_PTR(-WD_EBUSY); cur = head; tmp = sgl; @@ -964,6 +965,7 @@ void *hisi_qm_get_hw_sgl(handle_t sgl_pool, struct wd_datalist *sgl) if (tmp->len > HISI_MAX_SIZE_IN_SGE) { WD_ERR("invalid: the data len is %u!\n", tmp->len); + ret = WD_ERR_PTR(-WD_EINVAL); goto err_out; } @@ -975,6 +977,7 @@ void *hisi_qm_get_hw_sgl(handle_t sgl_pool, struct wd_datalist *sgl) if (!cur->sge_entries[i].buff) { WD_ERR("invalid: the iova map addr of sge is NULL!\n"); + ret = WD_ERR_PTR(-WD_EINVAL); goto err_out; } @@ -993,7 +996,7 @@ void *hisi_qm_get_hw_sgl(handle_t sgl_pool, struct wd_datalist *sgl) if (i == pool->sge_num && tmp->next) { next = hisi_qm_sgl_pop(pool); if (!next) { - WD_ERR("invalid: the sgl pool is not enough!\n"); + ret = WD_ERR_PTR(-WD_EBUSY); goto err_out; } if (mm_ops) @@ -1012,15 +1015,17 @@ void *hisi_qm_get_hw_sgl(handle_t sgl_pool, struct wd_datalist *sgl) } /* There is no data, recycle the hardware sgl head to pool */ - if (!head->entry_sum_in_chain) + if (!head->entry_sum_in_chain) { + ret = WD_ERR_PTR(-WD_EINVAL); goto err_out; + } hisi_qm_dump_sgl(head); return head; err_out: hisi_qm_put_hw_sgl(sgl_pool, head); - return NULL; + return ret; } handle_t hisi_qm_get_sglpool(handle_t h_qp, struct wd_mm_ops *mm_ops) diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index 53bf334..c8b831c 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -1305,20 +1305,17 @@ static int hisi_sec_fill_sgl(handle_t h_sgl_pool, __u8 **in, __u8 **out, void *hw_sgl_out; hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist *)(*in)); - if (!hw_sgl_in) { - WD_ERR("failed to get sgl in for hw_v2!\n"); - return -WD_EINVAL; - } + if (WD_IS_ERR(hw_sgl_in)) + return WD_PTR_ERR(hw_sgl_in); if (type == WD_DIGEST) { hw_sgl_out = *out; } else { hw_sgl_out = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist *)(*out)); - if (!hw_sgl_out) { - WD_ERR("failed to get hw sgl out for hw_v2!\n"); + if (WD_IS_ERR(hw_sgl_out)) { hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_in); - return -WD_EINVAL; + return WD_PTR_ERR(hw_sgl_out); } sqe->sdm_addr_type |= SEC_SGL_SDM_MASK; @@ -1338,10 +1335,8 @@ static int hisi_sec_fill_sgl_v3(handle_t h_sgl_pool, __u8 **in, __u8 **out, void *hw_sgl_out; hw_sgl_in = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist *)(*in)); - if (!hw_sgl_in) { - WD_ERR("failed to get sgl in for hw_v3!\n"); - return -WD_EINVAL; - } + if (WD_IS_ERR(hw_sgl_in)) + return WD_PTR_ERR(hw_sgl_in); if (type == WD_DIGEST) { hw_sgl_out = *out; @@ -1349,10 +1344,9 @@ static int hisi_sec_fill_sgl_v3(handle_t h_sgl_pool, __u8 **in, __u8 **out, } else { hw_sgl_out = hisi_qm_get_hw_sgl(h_sgl_pool, (struct wd_datalist *)(*out)); - if (!hw_sgl_out) { - WD_ERR("failed to get hw sgl out for hw_v3!\n"); + if (WD_IS_ERR(hw_sgl_out)) { hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_in); - return -WD_EINVAL; + return WD_PTR_ERR(hw_sgl_out); } /* -- 2.33.0