提交 4a1aab5f 编写于 作者: T tanshukun 提交者: Xie XiuQi

crypto/hisilicon/zip: Add some print info

driver inclusion
category: bugfix
bugzilla: NA
CVE: NA

Feature or Bugfix:Bugfix
Signed-off-by: Ntanshukun (A) <tanshukun1@huawei.com>
Reviewed-by: Nwangzhou <wangzhou1@hisilicon.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 bbb6bd79
...@@ -80,6 +80,7 @@ ...@@ -80,6 +80,7 @@
QM_OF_FIFO_OF) QM_OF_FIFO_OF)
#define QM_BASE_CE QM_ECC_1BIT #define QM_BASE_CE QM_ECC_1BIT
#define HISI_ACC_SGL_SGE_NR_MAX 255
#define QM_DFX_QN_SHIFT 16 #define QM_DFX_QN_SHIFT 16
#define CURRENT_FUN_MASK GENMASK(5, 0) #define CURRENT_FUN_MASK GENMASK(5, 0)
......
...@@ -3,13 +3,11 @@ ...@@ -3,13 +3,11 @@
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
#include "qm.h"
#define HISI_ACC_SGL_SGE_NR_MIN 1 #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_NR_MAX 256
#define HISI_ACC_SGL_ALIGN_SIZE 64 #define HISI_ACC_SGL_ALIGN_SIZE 64
#define FORMAT_DECIMAL 10
#define HISI_ACC_MEM_BLOCK_NR 5 #define HISI_ACC_MEM_BLOCK_NR 5
struct acc_hw_sge { struct acc_hw_sge {
...@@ -58,7 +56,7 @@ struct hisi_acc_sgl_pool { ...@@ -58,7 +56,7 @@ struct hisi_acc_sgl_pool {
struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev, struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
u32 count, u32 sge_nr) 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 hisi_acc_sgl_pool *pool;
struct mem_block *block; struct mem_block *block;
u32 i, j; u32 i, j;
...@@ -86,8 +84,10 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev, ...@@ -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_alloc_coherent(dev, block_size,
&block[i].sgl_dma, &block[i].sgl_dma,
GFP_KERNEL); GFP_KERNEL);
if (!block[i].sgl) if (!block[i].sgl) {
dev_err(dev, "Fail to allocate hw SG buffer!\n");
goto err_free_mem; goto err_free_mem;
}
block[i].size = block_size; block[i].size = block_size;
} }
...@@ -96,8 +96,10 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev, ...@@ -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_alloc_coherent(dev, remain_sgl * sgl_size,
&block[i].sgl_dma, &block[i].sgl_dma,
GFP_KERNEL); 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; goto err_free_mem;
}
block[i].size = remain_sgl * sgl_size; 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, ...@@ -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; 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) struct acc_hw_sge *hw_sge)
{ {
hw_sge->buf = sgl->dma_address; 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) ...@@ -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 * 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. * 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 hisi_acc_hw_sgl *
struct scatterlist *sgl, struct hisi_acc_sgl_pool *pool, 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) u32 index, dma_addr_t *hw_sgl_dma)
{ {
struct hisi_acc_hw_sgl *curr_hw_sgl; 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, ...@@ -208,15 +212,20 @@ struct hisi_acc_hw_sgl *hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev,
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
sg_n = sg_nents(sgl); 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); return ERR_PTR(-EINVAL);
}
ret = dma_map_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL); 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); return ERR_PTR(-EINVAL);
}
curr_hw_sgl = acc_get_sgl(pool, index, &curr_sgl_dma); curr_hw_sgl = acc_get_sgl(pool, index, &curr_sgl_dma);
if (IS_ERR(curr_hw_sgl)) { if (IS_ERR(curr_hw_sgl)) {
dev_err(dev, "Get SGL error!\n");
dma_unmap_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL); dma_unmap_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
...@@ -224,7 +233,7 @@ struct hisi_acc_hw_sgl *hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev, ...@@ -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; curr_hw_sge = curr_hw_sgl->sge_entries;
for_each_sg(sgl, sg, sg_n, i) { 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); inc_hw_sgl_sge(curr_hw_sgl);
curr_hw_sge++; curr_hw_sge++;
} }
......
...@@ -152,18 +152,22 @@ static void hisi_zip_fill_sqe(struct hisi_zip_sqe *sqe, u8 req_type, ...@@ -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, static int hisi_zip_create_qp(struct hisi_qm *qm, struct hisi_zip_qp_ctx *ctx,
int alg_type, int req_type) int alg_type, int req_type)
{ {
struct device *dev = &qm->pdev->dev;
struct hisi_qp *qp; struct hisi_qp *qp;
int ret; int ret;
qp = hisi_qm_create_qp(qm, alg_type); 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); return PTR_ERR(qp);
}
qp->req_type = req_type; qp->req_type = req_type;
qp->qp_ctx = ctx; qp->qp_ctx = ctx;
ret = hisi_qm_start_qp(qp, 0); ret = hisi_qm_start_qp(qp, 0);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "start qp failed!\n");
hisi_qm_release_qp(qp); hisi_qm_release_qp(qp);
return ret; return ret;
} }
...@@ -398,19 +402,27 @@ static int hisi_zip_acomp_init(struct crypto_acomp *tfm) ...@@ -398,19 +402,27 @@ static int hisi_zip_acomp_init(struct crypto_acomp *tfm)
{ {
const char *alg_name = crypto_tfm_alg_name(&tfm->base); const char *alg_name = crypto_tfm_alg_name(&tfm->base);
struct hisi_zip_ctx *ctx = crypto_tfm_ctx(&tfm->base); struct hisi_zip_ctx *ctx = crypto_tfm_ctx(&tfm->base);
struct device *dev;
int ret; int ret;
ret = hisi_zip_ctx_init(ctx, COMP_NAME_TO_TYPE(alg_name)); ret = hisi_zip_ctx_init(ctx, COMP_NAME_TO_TYPE(alg_name));
if (ret) if (ret) {
pr_err("Init ctx failed!\n");
return ret; return ret;
}
dev = &ctx->qp_ctx[0].qp->qm->pdev->dev;
ret = hisi_zip_create_req_q(ctx); ret = hisi_zip_create_req_q(ctx);
if (ret) if (ret) {
dev_err(dev, "Create request queue failed!\n ");
goto err_ctx_exit; goto err_ctx_exit;
}
ret = hisi_zip_create_sgl_pool(ctx); ret = hisi_zip_create_sgl_pool(ctx);
if (ret) if (ret) {
dev_err(dev, "Create sgl pool failed!\n ");
goto err_release_req_q; goto err_release_req_q;
}
hisi_zip_set_acomp_cb(ctx, hisi_zip_acomp_cb); 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) ...@@ -440,8 +452,10 @@ static int add_comp_head(struct scatterlist *dst, u8 req_type)
int ret; int ret;
ret = sg_copy_from_buffer(dst, sg_nents(dst), head, head_size); 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 -ENOMEM;
}
return head_size; return head_size;
} }
...@@ -563,14 +577,17 @@ static int hisi_zip_do_work(struct hisi_zip_req *req, ...@@ -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->hw_src = hisi_acc_sg_buf_map_to_hw_sgl(dev, req->src, pool,
req->req_id << 1, &input); 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); return PTR_ERR(req->hw_src);
}
req->dma_src = input; req->dma_src = input;
req->hw_dst = hisi_acc_sg_buf_map_to_hw_sgl(dev, req->dst, pool, req->hw_dst = hisi_acc_sg_buf_map_to_hw_sgl(dev, req->dst, pool,
(req->req_id << 1) + 1, (req->req_id << 1) + 1,
&output); &output);
if (IS_ERR(req->hw_dst)) { if (IS_ERR(req->hw_dst)) {
dev_err(dev, "the dst map to hw SGL failed!\n");
ret = PTR_ERR(req->hw_dst); ret = PTR_ERR(req->hw_dst);
goto err_unmap_input; goto err_unmap_input;
} }
...@@ -583,8 +600,10 @@ static int hisi_zip_do_work(struct hisi_zip_req *req, ...@@ -583,8 +600,10 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,
/* send command to start a task */ /* send command to start a task */
ret = hisi_qp_send(qp, zip_sqe); 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; goto err_unmap_output;
}
return -EINPROGRESS; return -EINPROGRESS;
...@@ -599,6 +618,7 @@ static int hisi_zip_acompress(struct acomp_req *acomp_req) ...@@ -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_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm);
struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[QPC_COMP]; 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; struct hisi_zip_req *req;
int head_size; int head_size;
int ret; int ret;
...@@ -609,12 +629,16 @@ static int hisi_zip_acompress(struct acomp_req *acomp_req) ...@@ -609,12 +629,16 @@ static int hisi_zip_acompress(struct acomp_req *acomp_req)
return -ENOMEM; return -ENOMEM;
req = hisi_zip_create_req(acomp_req, qp_ctx, head_size, true); 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); return PTR_ERR(req);
}
ret = hisi_zip_do_work(req, qp_ctx); 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); hisi_zip_remove_req(qp_ctx, req);
}
return ret; return ret;
} }
...@@ -623,6 +647,7 @@ static int hisi_zip_adecompress(struct acomp_req *acomp_req) ...@@ -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_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm);
struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[QPC_DECOMP]; 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; struct hisi_zip_req *req;
int head_size; int head_size;
int ret; int ret;
...@@ -632,12 +657,16 @@ static int hisi_zip_adecompress(struct acomp_req *acomp_req) ...@@ -632,12 +657,16 @@ static int hisi_zip_adecompress(struct acomp_req *acomp_req)
return -ENOMEM; return -ENOMEM;
req = hisi_zip_create_req(acomp_req, qp_ctx, head_size, false); 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); return PTR_ERR(req);
}
ret = hisi_zip_do_work(req, qp_ctx); 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); hisi_zip_remove_req(qp_ctx, req);
}
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册