2020-08-24 03:17:12

by Yang Shen

[permalink] [raw]
Subject: [PATCH RESEND 00/10] crypto: hisilicon/zip - misc clean up

This patchset make some clean up:
patch 1:remove useless parameters
patch 4:replace 'sprintf' with 'scnprintf'
patch 7:fix static check warning
and the rest patch fix some coding style

Resend this patch series because it depends on
https://patchwork.kernel.org/cover/11715927/
(crypto: hisilicon/qm - misc fixes).
Now the patch series(crypto: hisilicon/qm - misc fixes) has been applied.
So this patch series will apply against cryptodev.

Shukun Tan (1):
crypto: hisilicon/zip - modify debugfs interface parameters

Yang Shen (9):
crypto: hisilicon/zip - remove some useless parameters
crypto: hisilicon/zip - unify naming style for functions and macros
crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf'
crypto: hisilicon/zip - use a enum parameter instead of some macros
crypto: hisilicon/zip - add print for error branch
crypto: hisilicon/zip - fix static check warning
crypto: hisilicon/zip - move some private macros from 'zip.h' to
'zip_crypto.c'
crypto: hisilicon/zip - supplement some comments
crypto: hisilicon/zip - fix some coding styles

drivers/crypto/hisilicon/zip/zip.h | 15 ----
drivers/crypto/hisilicon/zip/zip_crypto.c | 126 ++++++++++++++++++++---------
drivers/crypto/hisilicon/zip/zip_main.c | 130 ++++++++++++++----------------
3 files changed, 148 insertions(+), 123 deletions(-)

--
2.7.4


2020-08-24 03:17:33

by Yang Shen

[permalink] [raw]
Subject: [PATCH RESEND 09/10] crypto: hisilicon/zip - supplement some comments

Supplement some comments.

Signed-off-by: Yang Shen <[email protected]>
Reviewed-by: Zhou Wang <[email protected]>
---
drivers/crypto/hisilicon/zip/zip_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
index 7697fa5..49fad18 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -285,7 +285,7 @@ static int hisi_zip_set_user_domain_and_cache(struct hisi_qm *qm)
writel(HZIP_DECOMP_CHECK_ENABLE | HZIP_ALL_COMP_DECOMP_EN,
base + HZIP_CLOCK_GATE_CTRL);

- /* enable sqc writeback */
+ /* enable sqc,cqc writeback */
writel(SQC_CACHE_ENABLE | CQC_CACHE_ENABLE | SQC_CACHE_WB_ENABLE |
CQC_CACHE_WB_ENABLE | FIELD_PREP(SQC_CACHE_WB_THRD, 1) |
FIELD_PREP(CQC_CACHE_WB_THRD, 1), base + QM_CACHE_CTL);
@@ -358,7 +358,7 @@ static int current_qm_write(struct ctrl_debug_file *file, u32 val)
if (val > qm->vfs_num)
return -EINVAL;

- /* Calculate curr_qm_qp_num and store */
+ /* According PF or VF Dev ID to calculation curr_qm_qp_num and store */
if (val == 0) {
qm->debug.curr_qm_qp_num = qm->qp_num;
} else {
--
2.7.4

2020-08-24 03:17:59

by Yang Shen

[permalink] [raw]
Subject: [PATCH RESEND 02/10] crypto: hisilicon/zip - unify naming style for functions and macros

1.Add prefix 'HZIP' for some macros
2.Add prefix 'hisi_zip' for some functions

Signed-off-by: Yang Shen <[email protected]>
Reviewed-by: Zhou Wang <[email protected]>
---
drivers/crypto/hisilicon/zip/zip_main.c | 35 +++++++++++++++++----------------
1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
index 445db04..058f744 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -29,18 +29,18 @@
#define DECOMP3_ENABLE BIT(5)
#define DECOMP4_ENABLE BIT(6)
#define DECOMP5_ENABLE BIT(7)
-#define ALL_COMP_DECOMP_EN (COMP0_ENABLE | COMP1_ENABLE | \
+#define HZIP_ALL_COMP_DECOMP_EN (COMP0_ENABLE | COMP1_ENABLE | \
DECOMP0_ENABLE | DECOMP1_ENABLE | \
DECOMP2_ENABLE | DECOMP3_ENABLE | \
DECOMP4_ENABLE | DECOMP5_ENABLE)
-#define DECOMP_CHECK_ENABLE BIT(16)
+#define HZIP_DECOMP_CHECK_ENABLE BIT(16)
#define HZIP_FSM_MAX_CNT 0x301008

#define HZIP_PORT_ARCA_CHE_0 0x301040
#define HZIP_PORT_ARCA_CHE_1 0x301044
#define HZIP_PORT_AWCA_CHE_0 0x301060
#define HZIP_PORT_AWCA_CHE_1 0x301064
-#define CACHE_ALL_EN 0xffffffff
+#define HZIP_CACHE_ALL_EN 0xffffffff

#define HZIP_BD_RUSER_32_63 0x301110
#define HZIP_SGL_RUSER_32_63 0x30111c
@@ -82,7 +82,7 @@
#define HZIP_PF_DEF_Q_BASE 0

#define HZIP_SOFT_CTRL_CNT_CLR_CE 0x301000
-#define SOFT_CTRL_CNT_CLR_CE_BIT BIT(0)
+#define HZIP_SOFT_CTRL_CNT_CLR_CE_BIT BIT(0)
#define HZIP_SOFT_CTRL_ZIP_CONTROL 0x30100C
#define HZIP_AXI_SHUTDOWN_ENABLE BIT(14)
#define HZIP_WR_PORT BIT(11)
@@ -264,10 +264,10 @@ static int hisi_zip_set_user_domain_and_cache(struct hisi_qm *qm)
writel(PEH_AXUSER_CFG_ENABLE, base + QM_PEH_AXUSER_CFG_ENABLE);

/* cache */
- writel(CACHE_ALL_EN, base + HZIP_PORT_ARCA_CHE_0);
- writel(CACHE_ALL_EN, base + HZIP_PORT_ARCA_CHE_1);
- writel(CACHE_ALL_EN, base + HZIP_PORT_AWCA_CHE_0);
- writel(CACHE_ALL_EN, base + HZIP_PORT_AWCA_CHE_1);
+ writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_ARCA_CHE_0);
+ writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_ARCA_CHE_1);
+ writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_AWCA_CHE_0);
+ writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_AWCA_CHE_1);

/* user domain configurations */
writel(AXUSER_BASE, base + HZIP_BD_RUSER_32_63);
@@ -283,7 +283,7 @@ static int hisi_zip_set_user_domain_and_cache(struct hisi_qm *qm)
}

/* let's open all compression/decompression cores */
- writel(DECOMP_CHECK_ENABLE | ALL_COMP_DECOMP_EN,
+ writel(HZIP_DECOMP_CHECK_ENABLE | HZIP_ALL_COMP_DECOMP_EN,
base + HZIP_CLOCK_GATE_CTRL);

/* enable sqc writeback */
@@ -390,7 +390,7 @@ static u32 clear_enable_read(struct ctrl_debug_file *file)
struct hisi_qm *qm = file_to_qm(file);

return readl(qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE) &
- SOFT_CTRL_CNT_CLR_CE_BIT;
+ HZIP_SOFT_CTRL_CNT_CLR_CE_BIT;
}

static int clear_enable_write(struct ctrl_debug_file *file, u32 val)
@@ -402,14 +402,14 @@ static int clear_enable_write(struct ctrl_debug_file *file, u32 val)
return -EINVAL;

tmp = (readl(qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE) &
- ~SOFT_CTRL_CNT_CLR_CE_BIT) | val;
+ ~HZIP_SOFT_CTRL_CNT_CLR_CE_BIT) | val;
writel(tmp, qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE);

return 0;
}

-static ssize_t ctrl_debug_read(struct file *filp, char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf,
+ size_t count, loff_t *pos)
{
struct ctrl_debug_file *file = filp->private_data;
char tbuf[HZIP_BUF_SIZE];
@@ -433,8 +433,9 @@ static ssize_t ctrl_debug_read(struct file *filp, char __user *buf,
return simple_read_from_buffer(buf, count, pos, tbuf, ret);
}

-static ssize_t ctrl_debug_write(struct file *filp, const char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t hisi_zip_ctrl_debug_write(struct file *filp,
+ const char __user *buf,
+ size_t count, loff_t *pos)
{
struct ctrl_debug_file *file = filp->private_data;
char tbuf[HZIP_BUF_SIZE];
@@ -483,8 +484,8 @@ static ssize_t ctrl_debug_write(struct file *filp, const char __user *buf,
static const struct file_operations ctrl_debug_fops = {
.owner = THIS_MODULE,
.open = simple_open,
- .read = ctrl_debug_read,
- .write = ctrl_debug_write,
+ .read = hisi_zip_ctrl_debug_read,
+ .write = hisi_zip_ctrl_debug_write,
};


--
2.7.4

2020-08-24 03:18:50

by Yang Shen

[permalink] [raw]
Subject: [PATCH RESEND 06/10] crypto: hisilicon/zip - add print for error branch

Add print for some error branches.

Signed-off-by: Yang Shen <[email protected]>
Reviewed-by: Zhou Wang <[email protected]>
---
drivers/crypto/hisilicon/zip/zip_crypto.c | 68 +++++++++++++++++++++++--------
drivers/crypto/hisilicon/zip/zip_main.c | 8 ++--
2 files changed, 56 insertions(+), 20 deletions(-)

diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c b/drivers/crypto/hisilicon/zip/zip_crypto.c
index c2ea849..7aa8a55 100644
--- a/drivers/crypto/hisilicon/zip/zip_crypto.c
+++ b/drivers/crypto/hisilicon/zip/zip_crypto.c
@@ -146,7 +146,7 @@ static int hisi_zip_start_qp(struct hisi_qp *qp, struct hisi_zip_qp_ctx *ctx,

ret = hisi_qm_start_qp(qp, 0);
if (ret < 0) {
- dev_err(dev, "start qp failed!\n");
+ dev_err(dev, "Start qp failed (%d)!\n", ret);
return ret;
}

@@ -169,7 +169,7 @@ static int hisi_zip_ctx_init(struct hisi_zip_ctx *hisi_zip_ctx, u8 req_type, int

ret = zip_create_qps(qps, HZIP_CTX_Q_NUM, node);
if (ret) {
- pr_err("Can not create zip qps!\n");
+ pr_err("Can not create zip qps (%d)!\n", ret);
return -ENODEV;
}

@@ -380,19 +380,28 @@ 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), tfm->base.node);
- if (ret)
+ if (ret) {
+ pr_err("Init ctx failed (%d)!\n", ret);
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 (%d)!\n", ret);
goto err_ctx_exit;
+ }

ret = hisi_zip_create_sgl_pool(ctx);
- if (ret)
+ if (ret) {
+ dev_err(dev, "Create sgl pool failed (%d)!\n", ret);
goto err_release_req_q;
+ }

hisi_zip_set_acomp_cb(ctx, hisi_zip_acomp_cb);

@@ -422,8 +431,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 (%d)!\n", ret);
return -ENOMEM;
+ }

return head_size;
}
@@ -445,7 +456,7 @@ static size_t get_comp_head_size(struct scatterlist *src, u8 req_type)
case HZIP_ALG_TYPE_GZIP:
return get_gzip_head_size(src);
default:
- pr_err("request type does not support!\n");
+ pr_err("Request type does not support!\n");
return -EINVAL;
}
}
@@ -464,7 +475,7 @@ static struct hisi_zip_req *hisi_zip_create_req(struct acomp_req *req,
req_id = find_first_zero_bit(req_q->req_bitmap, req_q->size);
if (req_id >= req_q->size) {
write_unlock(&req_q->req_lock);
- dev_dbg(&qp_ctx->qp->qm->pdev->dev, "req cache is full!\n");
+ dev_dbg(&qp_ctx->qp->qm->pdev->dev, "Req cache is full!\n");
return ERR_PTR(-EBUSY);
}
set_bit(req_id, req_q->req_bitmap);
@@ -504,14 +515,19 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,

req->hw_src = hisi_acc_sg_buf_map_to_hw_sgl(dev, a_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 (%ld)!\n",
+ PTR_ERR(req->hw_src));
return PTR_ERR(req->hw_src);
+ }
req->dma_src = input;

req->hw_dst = hisi_acc_sg_buf_map_to_hw_sgl(dev, a_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 (%ld)!\n",
+ PTR_ERR(req->hw_dst));
ret = PTR_ERR(req->hw_dst);
goto err_unmap_input;
}
@@ -527,6 +543,7 @@ static int hisi_zip_do_work(struct hisi_zip_req *req,
ret = hisi_qp_send(qp, &zip_sqe);
if (ret < 0) {
atomic64_inc(&dfx->send_busy_cnt);
+ dev_dbg_ratelimited(dev, "Send task message failed!\n");
goto err_unmap_output;
}

@@ -543,22 +560,32 @@ 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[HZIP_QPC_COMP];
+ struct device *dev = &qp_ctx->qp->qm->pdev->dev;
struct hisi_zip_req *req;
int head_size;
int ret;

/* let's output compression head now */
head_size = add_comp_head(acomp_req->dst, qp_ctx->qp->req_type);
- if (head_size < 0)
- return -ENOMEM;
+ if (head_size < 0) {
+ dev_err_ratelimited(dev, "Add comp head failed (%d)!\n",
+ head_size);
+ return head_size;
+ }

req = hisi_zip_create_req(acomp_req, qp_ctx, (size_t)head_size, true);
- if (IS_ERR(req))
+ if (IS_ERR(req)) {
+ dev_err_ratelimited(dev, "Create request before compress failed (%ld)!\n",
+ PTR_ERR(req));
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 (%d)!\n",
+ ret);
hisi_zip_remove_req(qp_ctx, req);
+ }

return ret;
}
@@ -567,6 +594,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[HZIP_QPC_DECOMP];
+ struct device *dev = &qp_ctx->qp->qm->pdev->dev;
struct hisi_zip_req *req;
size_t head_size;
int ret;
@@ -574,12 +602,18 @@ static int hisi_zip_adecompress(struct acomp_req *acomp_req)
head_size = get_comp_head_size(acomp_req->src, qp_ctx->qp->req_type);

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 (%ld)!\n",
+ PTR_ERR(req));
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 (%d)!\n",
+ ret);
hisi_zip_remove_req(qp_ctx, req);
+ }

return ret;
}
@@ -618,13 +652,13 @@ int hisi_zip_register_to_crypto(void)

ret = crypto_register_acomp(&hisi_zip_acomp_zlib);
if (ret) {
- pr_err("Zlib acomp algorithm registration failed\n");
+ pr_err("Zlib acomp algorithm registration failed (%d)!\n", ret);
return ret;
}

ret = crypto_register_acomp(&hisi_zip_acomp_gzip);
if (ret) {
- pr_err("Gzip acomp algorithm registration failed\n");
+ pr_err("Gzip acomp algorithm registration failed (%d)!\n", ret);
crypto_unregister_acomp(&hisi_zip_acomp_zlib);
}

diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
index 1883d1b..7697fa5 100644
--- a/drivers/crypto/hisilicon/zip/zip_main.c
+++ b/drivers/crypto/hisilicon/zip/zip_main.c
@@ -807,18 +807,20 @@ static int hisi_zip_probe(struct pci_dev *pdev, const struct pci_device_id *id)

ret = hisi_zip_debugfs_init(qm);
if (ret)
- dev_err(&pdev->dev, "Failed to init debugfs (%d)!\n", ret);
+ pci_err(pdev, "Failed to init debugfs (%d)!\n", ret);

ret = hisi_qm_alg_register(qm, &zip_devices);
if (ret < 0) {
- pci_err(pdev, "Failed to register driver to crypto.\n");
+ pci_err(pdev, "Failed to register driver to crypto!\n");
goto err_qm_stop;
}

if (qm->uacce) {
ret = uacce_register(qm->uacce);
- if (ret)
+ if (ret) {
+ pci_err(pdev, "Failed to register uacce (%d)!\n", ret);
goto err_qm_alg_unregister;
+ }
}

if (qm->fun_type == QM_HW_PF && vfs_num > 0) {
--
2.7.4