diff --git a/drivers/crypto/hisilicon/qm.h b/drivers/crypto/hisilicon/qm.h index b5df3e8bd9475862b5d4b07987358ef1d50a6181..b13aa364866d74d6de3332ab299cfec7da017dd8 100644 --- a/drivers/crypto/hisilicon/qm.h +++ b/drivers/crypto/hisilicon/qm.h @@ -80,6 +80,7 @@ QM_OF_FIFO_OF) #define QM_BASE_CE QM_ECC_1BIT +#define HISI_ACC_SGL_SGE_NR_MAX 255 #define QM_DFX_QN_SHIFT 16 #define CURRENT_FUN_MASK GENMASK(5, 0) diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c index 7e6f2895956dda637e63ae6f1e03a2807b68f41f..85c2bc36d82670d5c44bd012f9cd6b773c0ba548 100644 --- a/drivers/crypto/hisilicon/sgl.c +++ b/drivers/crypto/hisilicon/sgl.c @@ -3,13 +3,11 @@ #include #include #include +#include "qm.h" #define HISI_ACC_SGL_SGE_NR_MIN 1 -#define HISI_ACC_SGL_SGE_NR_MAX 255 -#define HISI_ACC_SGL_SGE_NR_DEF 10 #define HISI_ACC_SGL_NR_MAX 256 #define HISI_ACC_SGL_ALIGN_SIZE 64 -#define FORMAT_DECIMAL 10 #define HISI_ACC_MEM_BLOCK_NR 5 struct acc_hw_sge { @@ -58,7 +56,7 @@ struct hisi_acc_sgl_pool { struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev, u32 count, u32 sge_nr) { - u32 sgl_size, block_size, sgl_num_per_block, block_num, remain_sgl = 0; + u32 sgl_size, block_size, sgl_num_per_block, block_num, remain_sgl; struct hisi_acc_sgl_pool *pool; struct mem_block *block; u32 i, j; @@ -86,8 +84,10 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev, block[i].sgl = dma_alloc_coherent(dev, block_size, &block[i].sgl_dma, GFP_KERNEL); - if (!block[i].sgl) + if (!block[i].sgl) { + dev_err(dev, "Fail to allocate hw SG buffer!\n"); goto err_free_mem; + } block[i].size = block_size; } @@ -96,8 +96,10 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev, block[i].sgl = dma_alloc_coherent(dev, remain_sgl * sgl_size, &block[i].sgl_dma, GFP_KERNEL); - if (!block[i].sgl) + if (!block[i].sgl) { + dev_err(dev, "Fail to allocate remained hw SG buffer!\n"); goto err_free_mem; + } block[i].size = remain_sgl * sgl_size; } @@ -163,7 +165,7 @@ static struct hisi_acc_hw_sgl *acc_get_sgl(struct hisi_acc_sgl_pool *pool, return (void *)block[block_index].sgl + pool->sgl_size * offset; } -static void sgl_map_to_hw_sg(struct scatterlist *sgl, +static void sg_map_to_hw_sg(struct scatterlist *sgl, struct acc_hw_sge *hw_sge) { hw_sge->buf = sgl->dma_address; @@ -194,8 +196,10 @@ static void update_hw_sgl_sum_sge(struct hisi_acc_hw_sgl *hw_sgl, u16 sum) * This function builds hw sgl according input sgl, user can use hw_sgl_dma * as src/dst in its BD. Only support single hw sgl currently. */ -struct hisi_acc_hw_sgl *hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev, - struct scatterlist *sgl, struct hisi_acc_sgl_pool *pool, +struct hisi_acc_hw_sgl * +hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev, + struct scatterlist *sgl, + struct hisi_acc_sgl_pool *pool, u32 index, dma_addr_t *hw_sgl_dma) { struct hisi_acc_hw_sgl *curr_hw_sgl; @@ -208,15 +212,20 @@ struct hisi_acc_hw_sgl *hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev, return ERR_PTR(-EINVAL); sg_n = sg_nents(sgl); - if (sg_n > pool->sge_nr) + if (sg_n > pool->sge_nr) { + dev_err(dev, "the number of entries in input scatterlist is bigger than SGL pool setting.\n"); return ERR_PTR(-EINVAL); + } ret = dma_map_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL); - if (!ret) + if (!ret) { + dev_err(dev, "DMA mapping for SG error!\n"); return ERR_PTR(-EINVAL); + } curr_hw_sgl = acc_get_sgl(pool, index, &curr_sgl_dma); if (IS_ERR(curr_hw_sgl)) { + dev_err(dev, "Get SGL error!\n"); dma_unmap_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL); return ERR_PTR(-ENOMEM); } @@ -224,7 +233,7 @@ struct hisi_acc_hw_sgl *hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev, curr_hw_sge = curr_hw_sgl->sge_entries; for_each_sg(sgl, sg, sg_n, i) { - sgl_map_to_hw_sg(sg, curr_hw_sge); + sg_map_to_hw_sg(sg, curr_hw_sge); inc_hw_sgl_sge(curr_hw_sgl); curr_hw_sge++; } diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c b/drivers/crypto/hisilicon/zip/zip_crypto.c index 0ed5c0985416579af855c4f0a602c0bf5591d271..2b8dba73f5f0d7af4aaa82125370d32957864a24 100644 --- a/drivers/crypto/hisilicon/zip/zip_crypto.c +++ b/drivers/crypto/hisilicon/zip/zip_crypto.c @@ -152,18 +152,22 @@ static void hisi_zip_fill_sqe(struct hisi_zip_sqe *sqe, u8 req_type, static int hisi_zip_create_qp(struct hisi_qm *qm, struct hisi_zip_qp_ctx *ctx, int alg_type, int req_type) { + struct device *dev = &qm->pdev->dev; struct hisi_qp *qp; int ret; qp = hisi_qm_create_qp(qm, alg_type); - if (IS_ERR(qp)) + if (IS_ERR(qp)) { + dev_err(dev, "create qp failed!\n"); return PTR_ERR(qp); + } qp->req_type = req_type; qp->qp_ctx = ctx; ret = hisi_qm_start_qp(qp, 0); if (ret < 0) { + dev_err(dev, "start qp failed!\n"); hisi_qm_release_qp(qp); return ret; } @@ -398,19 +402,27 @@ static int hisi_zip_acomp_init(struct crypto_acomp *tfm) { const char *alg_name = crypto_tfm_alg_name(&tfm->base); struct hisi_zip_ctx *ctx = crypto_tfm_ctx(&tfm->base); + struct device *dev; int ret; ret = hisi_zip_ctx_init(ctx, COMP_NAME_TO_TYPE(alg_name)); - if (ret) + if (ret) { + pr_err("Init ctx failed!\n"); return ret; + } + dev = &ctx->qp_ctx[0].qp->qm->pdev->dev; ret = hisi_zip_create_req_q(ctx); - if (ret) + if (ret) { + dev_err(dev, "Create request queue failed!\n "); goto err_ctx_exit; + } ret = hisi_zip_create_sgl_pool(ctx); - if (ret) + if (ret) { + dev_err(dev, "Create sgl pool failed!\n "); goto err_release_req_q; + } hisi_zip_set_acomp_cb(ctx, hisi_zip_acomp_cb); @@ -440,8 +452,10 @@ static int add_comp_head(struct scatterlist *dst, u8 req_type) int ret; ret = sg_copy_from_buffer(dst, sg_nents(dst), head, head_size); - if (ret != head_size) + if (ret != head_size) { + pr_err("The head size of buffer is wrong!\n"); return -ENOMEM; + } return head_size; } @@ -563,14 +577,17 @@ static int hisi_zip_do_work(struct hisi_zip_req *req, req->hw_src = hisi_acc_sg_buf_map_to_hw_sgl(dev, req->src, pool, req->req_id << 1, &input); - if (IS_ERR(req->hw_src)) + if (IS_ERR(req->hw_src)) { + dev_err(dev, "the src map to hw SGL failed!\n"); return PTR_ERR(req->hw_src); + } req->dma_src = input; req->hw_dst = hisi_acc_sg_buf_map_to_hw_sgl(dev, req->dst, pool, (req->req_id << 1) + 1, &output); if (IS_ERR(req->hw_dst)) { + dev_err(dev, "the dst map to hw SGL failed!\n"); ret = PTR_ERR(req->hw_dst); goto err_unmap_input; } @@ -583,8 +600,10 @@ static int hisi_zip_do_work(struct hisi_zip_req *req, /* send command to start a task */ ret = hisi_qp_send(qp, zip_sqe); - if (ret < 0) + if (ret < 0) { + dev_dbg_ratelimited(dev, "send task message failed!\n"); goto err_unmap_output; + } return -EINPROGRESS; @@ -599,6 +618,7 @@ static int hisi_zip_acompress(struct acomp_req *acomp_req) { struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm); struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[QPC_COMP]; + struct device *dev = &qp_ctx->qp->qm->pdev->dev; struct hisi_zip_req *req; int head_size; int ret; @@ -609,12 +629,16 @@ static int hisi_zip_acompress(struct acomp_req *acomp_req) return -ENOMEM; req = hisi_zip_create_req(acomp_req, qp_ctx, head_size, true); - if (IS_ERR(req)) + if (IS_ERR(req)) { + dev_err_ratelimited(dev, "create request before compress failed!\n"); return PTR_ERR(req); + } ret = hisi_zip_do_work(req, qp_ctx); - if (ret != -EINPROGRESS) + if (ret != -EINPROGRESS) { + dev_err_ratelimited(dev, "do compress work failed!\n"); hisi_zip_remove_req(qp_ctx, req); + } return ret; } @@ -623,6 +647,7 @@ static int hisi_zip_adecompress(struct acomp_req *acomp_req) { struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm); struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[QPC_DECOMP]; + struct device *dev = &qp_ctx->qp->qm->pdev->dev; struct hisi_zip_req *req; int head_size; int ret; @@ -632,12 +657,16 @@ static int hisi_zip_adecompress(struct acomp_req *acomp_req) return -ENOMEM; req = hisi_zip_create_req(acomp_req, qp_ctx, head_size, false); - if (IS_ERR(req)) + if (IS_ERR(req)) { + dev_err_ratelimited(dev, "create request before decompress failed!\n"); return PTR_ERR(req); + } ret = hisi_zip_do_work(req, qp_ctx); - if (ret != -EINPROGRESS) + if (ret != -EINPROGRESS) { + dev_err_ratelimited(dev, "do decompress work failed!\n"); hisi_zip_remove_req(qp_ctx, req); + } return ret; }