From nobody Thu Apr 9 14:59:31 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCE17C433FE for ; Sat, 12 Nov 2022 02:19:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234527AbiKLCTV (ORCPT ); Fri, 11 Nov 2022 21:19:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbiKLCTJ (ORCPT ); Fri, 11 Nov 2022 21:19:09 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8847F31362; Fri, 11 Nov 2022 18:19:07 -0800 (PST) Received: from dggpeml500022.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4N8K4n6D98z15MWS; Sat, 12 Nov 2022 10:18:49 +0800 (CST) Received: from dggpeml100012.china.huawei.com (7.185.36.121) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 12 Nov 2022 10:19:05 +0800 Received: from huawei.com (10.67.165.24) by dggpeml100012.china.huawei.com (7.185.36.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 12 Nov 2022 10:19:05 +0800 From: Kai Ye To: CC: , , Subject: [PATCH v3 4/4] crypto: hisilicon/qm - the command dump process is modified Date: Sat, 12 Nov 2022 02:12:53 +0000 Message-ID: <20221112021253.34862-5-yekai13@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221112021253.34862-1-yekai13@huawei.com> References: <20221112021253.34862-1-yekai13@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml100012.china.huawei.com (7.185.36.121) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Reduce the function complexity by use the function table in the process of dumping queue. The function input parameters are unified. And maintainability is enhanced. Signed-off-by: Kai Ye --- drivers/crypto/hisilicon/debugfs.c | 130 ++++++++++++++++++++--------- 1 file changed, 90 insertions(+), 40 deletions(-) diff --git a/drivers/crypto/hisilicon/debugfs.c b/drivers/crypto/hisilicon/= debugfs.c index 13bec8b2d723..2cc1591949db 100644 --- a/drivers/crypto/hisilicon/debugfs.c +++ b/drivers/crypto/hisilicon/debugfs.c @@ -36,6 +36,12 @@ struct qm_dfx_item { u32 offset; }; =20 +struct qm_cmd_dump_item { + const char *cmd; + char *info_name; + int (*dump_fn)(struct hisi_qm *qm, char *cmd, char *info_name); +}; + static struct qm_dfx_item qm_dfx_files[] =3D { {"err_irq", offsetof(struct qm_dfx, err_irq_cnt)}, {"aeq_irq", offsetof(struct qm_dfx, aeq_irq_cnt)}, @@ -128,7 +134,7 @@ static void dump_show(struct hisi_qm *qm, void *info, } } =20 -static int qm_sqc_dump(struct hisi_qm *qm, const char *s) +static int qm_sqc_dump(struct hisi_qm *qm, char *s, char *name) { struct device *dev =3D &qm->pdev->dev; struct qm_sqc *sqc, *sqc_curr; @@ -162,14 +168,14 @@ static int qm_sqc_dump(struct hisi_qm *qm, const char= *s) goto free_ctx; } =20 - dump_show(qm, sqc, sizeof(*sqc), "SQC"); + dump_show(qm, sqc, sizeof(*sqc), name); =20 free_ctx: hisi_qm_ctx_free(qm, sizeof(*sqc), sqc, &sqc_dma); return 0; } =20 -static int qm_cqc_dump(struct hisi_qm *qm, const char *s) +static int qm_cqc_dump(struct hisi_qm *qm, char *s, char *name) { struct device *dev =3D &qm->pdev->dev; struct qm_cqc *cqc, *cqc_curr; @@ -203,26 +209,35 @@ static int qm_cqc_dump(struct hisi_qm *qm, const char= *s) goto free_ctx; } =20 - dump_show(qm, cqc, sizeof(*cqc), "CQC"); + dump_show(qm, cqc, sizeof(*cqc), name); =20 free_ctx: hisi_qm_ctx_free(qm, sizeof(*cqc), cqc, &cqc_dma); return 0; } =20 -static int qm_eqc_aeqc_dump(struct hisi_qm *qm, char *s, size_t size, - int cmd, char *name) +static int qm_eqc_aeqc_dump(struct hisi_qm *qm, char *s, char *name) { struct device *dev =3D &qm->pdev->dev; dma_addr_t xeqc_dma; + size_t size; void *xeqc; int ret; + u8 cmd; =20 if (strsep(&s, " ")) { dev_err(dev, "Please do not input extra characters!\n"); return -EINVAL; } =20 + if (!strcmp(name, "EQC")) { + cmd =3D QM_MB_CMD_EQC; + size =3D sizeof(struct qm_eqc); + } else { + cmd =3D QM_MB_CMD_AEQC; + size =3D sizeof(struct qm_aeqc); + } + xeqc =3D hisi_qm_ctx_alloc(qm, size, &xeqc_dma); if (IS_ERR(xeqc)) return PTR_ERR(xeqc); @@ -278,7 +293,7 @@ static int q_dump_param_parse(struct hisi_qm *qm, char = *s, return 0; } =20 -static int qm_sq_dump(struct hisi_qm *qm, char *s) +static int qm_sq_dump(struct hisi_qm *qm, char *s, char *name) { u16 sq_depth =3D qm->qp_array->cq_depth; void *sqe, *sqe_curr; @@ -300,14 +315,14 @@ static int qm_sq_dump(struct hisi_qm *qm, char *s) memset(sqe_curr + qm->debug.sqe_mask_offset, QM_SQE_ADDR_MASK, qm->debug.sqe_mask_len); =20 - dump_show(qm, sqe_curr, qm->sqe_size, "SQE"); + dump_show(qm, sqe_curr, qm->sqe_size, name); =20 kfree(sqe); =20 return 0; } =20 -static int qm_cq_dump(struct hisi_qm *qm, char *s) +static int qm_cq_dump(struct hisi_qm *qm, char *s, char *name) { struct qm_cqe *cqe_curr; struct hisi_qp *qp; @@ -320,15 +335,16 @@ static int qm_cq_dump(struct hisi_qm *qm, char *s) =20 qp =3D &qm->qp_array[qp_id]; cqe_curr =3D qp->cqe + cqe_id; - dump_show(qm, cqe_curr, sizeof(struct qm_cqe), "CQE"); + dump_show(qm, cqe_curr, sizeof(struct qm_cqe), name); =20 return 0; } =20 -static int qm_eq_aeq_dump(struct hisi_qm *qm, const char *s, - size_t size, char *name) +static int qm_eq_aeq_dump(struct hisi_qm *qm, char *s, char *name) { struct device *dev =3D &qm->pdev->dev; + u16 xeq_depth; + size_t size; void *xeqe; u32 xeqe_id; int ret; @@ -340,11 +356,16 @@ static int qm_eq_aeq_dump(struct hisi_qm *qm, const c= har *s, if (ret) return -EINVAL; =20 - if (!strcmp(name, "EQE") && xeqe_id >=3D qm->eq_depth) { - dev_err(dev, "Please input eqe num (0-%u)", qm->eq_depth - 1); - return -EINVAL; - } else if (!strcmp(name, "AEQE") && xeqe_id >=3D qm->aeq_depth) { - dev_err(dev, "Please input aeqe num (0-%u)", qm->eq_depth - 1); + if (!strcmp(name, "EQE")) { + xeq_depth =3D qm->eq_depth; + size =3D sizeof(struct qm_eqe); + } else { + xeq_depth =3D qm->aeq_depth; + size =3D sizeof(struct qm_aeqe); + } + + if (xeqe_id >=3D xeq_depth) { + dev_err(dev, "Please input eqe or aeqe num (0-%u)", xeq_depth - 1); return -EINVAL; } =20 @@ -388,11 +409,47 @@ static int qm_dbg_help(struct hisi_qm *qm, char *s) return 0; } =20 +static const struct qm_cmd_dump_item qm_cmd_dump_table[] =3D { + { + .cmd =3D "sqc", + .info_name =3D "SQC", + .dump_fn =3D qm_sqc_dump, + }, { + .cmd =3D "cqc", + .info_name =3D "CQC", + .dump_fn =3D qm_cqc_dump, + }, { + .cmd =3D "eqc", + .info_name =3D "EQC", + .dump_fn =3D qm_eqc_aeqc_dump, + }, { + .cmd =3D "aeqc", + .info_name =3D "AEQC", + .dump_fn =3D qm_eqc_aeqc_dump, + }, { + .cmd =3D "sq", + .info_name =3D "SQE", + .dump_fn =3D qm_sq_dump, + }, { + .cmd =3D "cq", + .info_name =3D "CQE", + .dump_fn =3D qm_cq_dump, + }, { + .cmd =3D "eq", + .info_name =3D "EQE", + .dump_fn =3D qm_eq_aeq_dump, + }, { + .cmd =3D "aeq", + .info_name =3D "AEQE", + .dump_fn =3D qm_eq_aeq_dump, + }, +}; + static int qm_cmd_write_dump(struct hisi_qm *qm, const char *cmd_buf) { struct device *dev =3D &qm->pdev->dev; char *presult, *s, *s_tmp; - int ret; + int table_size, i, ret; =20 s =3D kstrdup(cmd_buf, GFP_KERNEL); if (!s) @@ -405,31 +462,24 @@ static int qm_cmd_write_dump(struct hisi_qm *qm, cons= t char *cmd_buf) goto err_buffer_free; } =20 - if (!strcmp(presult, "sqc")) - ret =3D qm_sqc_dump(qm, s); - else if (!strcmp(presult, "cqc")) - ret =3D qm_cqc_dump(qm, s); - else if (!strcmp(presult, "eqc")) - ret =3D qm_eqc_aeqc_dump(qm, s, sizeof(struct qm_eqc), - QM_MB_CMD_EQC, "EQC"); - else if (!strcmp(presult, "aeqc")) - ret =3D qm_eqc_aeqc_dump(qm, s, sizeof(struct qm_aeqc), - QM_MB_CMD_AEQC, "AEQC"); - else if (!strcmp(presult, "sq")) - ret =3D qm_sq_dump(qm, s); - else if (!strcmp(presult, "cq")) - ret =3D qm_cq_dump(qm, s); - else if (!strcmp(presult, "eq")) - ret =3D qm_eq_aeq_dump(qm, s, sizeof(struct qm_eqe), "EQE"); - else if (!strcmp(presult, "aeq")) - ret =3D qm_eq_aeq_dump(qm, s, sizeof(struct qm_aeqe), "AEQE"); - else if (!strcmp(presult, "help")) + if (!strcmp(presult, "help")) { ret =3D qm_dbg_help(qm, s); - else - ret =3D -EINVAL; + goto err_buffer_free; + } =20 - if (ret) + table_size =3D ARRAY_SIZE(qm_cmd_dump_table); + for (i =3D 0; i < table_size; i++) { + if (!strcmp(presult, qm_cmd_dump_table[i].cmd)) { + ret =3D qm_cmd_dump_table[i].dump_fn(qm, s, + qm_cmd_dump_table[i].info_name); + break; + } + } + + if (i =3D=3D table_size) { dev_info(dev, "Please echo help\n"); + ret =3D -EINVAL; + } =20 err_buffer_free: kfree(s_tmp); --=20 2.17.1