libwd/0120-uadk-v1-cleanup-common-part-code-style.patch
Younger 5c995b2464 libwd - update some patches
Update some patches for 2203-SP3 only.

Signed-off-by: Yang Shen <shenyang39@huawei.com>
2024-05-24 09:59:01 +08:00

220 lines
6.8 KiB
Diff

From 25362ee741d1f304f9e5b45f47bf73bf46562a8d Mon Sep 17 00:00:00 2001
From: Zhiqi Song <songzhiqi1@huawei.com>
Date: Thu, 7 Dec 2023 19:19:06 +0800
Subject: [PATCH 120/123] uadk/v1: cleanup common part code style
Cleanup the following issues:
1. Add const to static variables that do not change.
2. Modify indentation and whitespace.
3. Put macro definitions at the beginning of the file.
4. Splitting judgment conditions to make it clearer.
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
---
v1/drv/hisi_qm_udrv.c | 16 ++++++++--------
v1/wd_adapter.c | 18 +++++++++---------
v1/wd_bmm.c | 13 ++++++-------
v1/wd_sgl.c | 27 ++++++++++++++++++++++-----
4 files changed, 45 insertions(+), 29 deletions(-)
diff --git a/v1/drv/hisi_qm_udrv.c b/v1/drv/hisi_qm_udrv.c
index 0ca38d2..03a875b 100644
--- a/v1/drv/hisi_qm_udrv.c
+++ b/v1/drv/hisi_qm_udrv.c
@@ -244,7 +244,7 @@ static int qm_set_queue_regions(struct wd_queue *q)
if (info->sq_base == MAP_FAILED) {
info->sq_base = NULL;
WD_ERR("mmap dus fail\n");
- return -ENOMEM;
+ return -WD_ENOMEM;
}
info->mmio_base = wd_drv_mmap_qfr(q, WD_UACCE_QFRT_MMIO, 0);
@@ -253,7 +253,7 @@ static int qm_set_queue_regions(struct wd_queue *q)
info->sq_base = NULL;
info->mmio_base = NULL;
WD_ERR("mmap mmio fail\n");
- return -ENOMEM;
+ return -WD_ENOMEM;
}
return 0;
@@ -439,7 +439,7 @@ static int qm_set_db_info(struct q_info *qinfo)
struct qm_queue_info *info = qinfo->priv;
if (strstr(qinfo->hw_type, HISI_QM_API_VER2_BASE) ||
- strstr(qinfo->hw_type, HISI_QM_API_VER3_BASE)) {
+ strstr(qinfo->hw_type, HISI_QM_API_VER3_BASE)) {
info->db = qm_db_v2;
info->doorbell_base = info->mmio_base + QM_V2_DOORBELL_OFFSET;
} else if (strstr(qinfo->hw_type, HISI_QM_API_VER_BASE)) {
@@ -447,7 +447,7 @@ static int qm_set_db_info(struct q_info *qinfo)
info->doorbell_base = info->mmio_base + QM_DOORBELL_OFFSET;
} else {
WD_ERR("hw version mismatch!\n");
- return -EINVAL;
+ return -WD_EINVAL;
}
return 0;
@@ -505,10 +505,10 @@ static int qm_set_queue_info(struct wd_queue *q)
ret = qm_set_queue_regions(q);
if (ret)
- return -EINVAL;
+ return -WD_EINVAL;
if (!info->sqe_size) {
WD_ERR("sqe size =%d err!\n", info->sqe_size);
- ret = -EINVAL;
+ ret = -WD_EINVAL;
goto err_with_regions;
}
info->cq_base = (void *)((uintptr_t)info->sq_base +
@@ -520,7 +520,7 @@ static int qm_set_queue_info(struct wd_queue *q)
ret = mprotect(info->cq_base, psize, PROT_READ);
if (ret) {
WD_ERR("cqe mprotect set err!\n");
- ret = -EINVAL;
+ ret = -WD_EINVAL;
goto err_with_regions;
}
@@ -549,7 +549,7 @@ int qm_init_queue(struct wd_queue *q)
{
struct q_info *qinfo = q->qinfo;
struct qm_queue_info *info;
- int ret = -ENOMEM;
+ int ret = -WD_ENOMEM;
info = calloc(1, sizeof(*info));
if (!info) {
diff --git a/v1/wd_adapter.c b/v1/wd_adapter.c
index 6e95562..d574200 100644
--- a/v1/wd_adapter.c
+++ b/v1/wd_adapter.c
@@ -28,7 +28,7 @@
#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
-static struct wd_drv_dio_if hw_dio_tbl[] = { {
+static const struct wd_drv_dio_if hw_dio_tbl[] = { {
.hw_type = "dummy_v1",
.open = dummy_set_queue_dio,
.close = dummy_unset_queue_dio,
@@ -155,13 +155,13 @@ void drv_free_slice(struct wd_queue *q)
struct q_info *qinfo = q->qinfo;
struct wd_ss_region *rgn;
- while (true) {
- rgn = TAILQ_FIRST(&qinfo->ss_list);
- if (!rgn)
- break;
- TAILQ_REMOVE(&qinfo->ss_list, rgn, next);
- free(rgn);
- }
+ while (true) {
+ rgn = TAILQ_FIRST(&qinfo->ss_list);
+ if (!rgn)
+ break;
+ TAILQ_REMOVE(&qinfo->ss_list, rgn, next);
+ free(rgn);
+ }
}
void drv_add_slice(struct wd_queue *q, struct wd_ss_region *rgn)
@@ -188,7 +188,7 @@ void drv_show_ss_slices(struct wd_queue *q)
int i = 0;
TAILQ_FOREACH(rgn, qinfo->head, next) {
- WD_ERR("slice-%d:size=0x%lx\n", i, rgn->size);
+ WD_ERR("slice-%d:size = 0x%lx\n", i, rgn->size);
i++;
}
}
diff --git a/v1/wd_bmm.c b/v1/wd_bmm.c
index c98c487..cdf5f0b 100644
--- a/v1/wd_bmm.c
+++ b/v1/wd_bmm.c
@@ -29,8 +29,12 @@
#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
-#define TAG_FREE 0x12345678 /* block is free */
-#define TAG_USED 0x87654321 /* block is busy */
+#define TAG_FREE 0x12345678 /* block is free */
+#define TAG_USED 0x87654321 /* block is busy */
+#define MAX_ALIGN_SIZE 0x1000 /* 4KB */
+#define MAX_BLOCK_SIZE 0x10000000 /* 256MB */
+#define BLK_BALANCE_SZ 0x100000ul
+#define NUM_TIMES(x) (87 * (x) / 100)
struct wd_blk_hd {
unsigned int blk_tag;
@@ -67,9 +71,6 @@ static struct wd_blk_hd *wd_blk_head(struct wd_blkpool *pool, void *blk)
static int pool_params_check(struct wd_blkpool_setup *setup)
{
-#define MAX_ALIGN_SIZE 0x1000 /* 4KB */
-#define MAX_BLOCK_SIZE 0x10000000 /* 256MB */
-
if (!setup->block_num || !setup->block_size ||
setup->block_size > MAX_BLOCK_SIZE) {
WD_ERR("Invalid block_size or block_num(%x, %u)!\n",
@@ -103,7 +104,6 @@ static int wd_pool_pre_layout(struct wd_queue *q,
if (!sp->br.alloc)
qinfo = q->qinfo;
-#define BLK_BALANCE_SZ 0x100000ul
ret = pool_params_check(sp);
if (ret)
return ret;
@@ -171,7 +171,6 @@ static int wd_pool_init(struct wd_queue *q, struct wd_blkpool *p)
* if dma_num <= (1 / 1.15) * user's block_num, we think the pool
* is created with failure.
*/
-#define NUM_TIMES(x) (87 * (x) / 100)
if (dma_num <= NUM_TIMES(p->setup.block_num)) {
WD_ERR("dma_num = %u, not enough.\n", dma_num);
return -WD_EINVAL;
diff --git a/v1/wd_sgl.c b/v1/wd_sgl.c
index 97e4b73..cb3b8ee 100644
--- a/v1/wd_sgl.c
+++ b/v1/wd_sgl.c
@@ -349,11 +349,28 @@ static int sgl_params_check(struct wd_sglpool_setup *setup)
struct wd_sglpool_setup *sp = setup;
__u32 buf_num_need;
- if (!sp->buf_num || !sp->sgl_num || !sp->sge_num_in_sgl ||
- !sp->buf_num_in_sgl || sp->buf_size < BUF_SIZE_MAX ||
- sp->buf_num_in_sgl > sp->sge_num_in_sgl ||
- sp->sgl_num > SGL_NUM_MAX || sp->sge_num_in_sgl > SGE_NUM_MAX) {
- WD_ERR("invalid size or num in sgl!\n");
+ if (!sp->sgl_num || sp->sgl_num > SGL_NUM_MAX) {
+ WD_ERR("invalid sgl_num, %u!\n", sp->sgl_num);
+ return -WD_EINVAL;
+ }
+
+ if (!sp->sge_num_in_sgl || sp->sge_num_in_sgl > SGE_NUM_MAX) {
+ WD_ERR("invlaid sge_num_in_sgl, %u\n!", sp->sge_num_in_sgl);
+ return -WD_EINVAL;
+ }
+
+ if (!sp->buf_num) {
+ WD_ERR("invalid buf_num, %u!\n", sp->buf_num);
+ return -WD_EINVAL;
+ }
+
+ if (sp->buf_size < BUF_SIZE_MAX) {
+ WD_ERR("invalid buf_size, %u!\n", sp->buf_size);
+ return -WD_EINVAL;
+ }
+
+ if (!sp->buf_num_in_sgl || sp->buf_num_in_sgl > sp->sge_num_in_sgl) {
+ WD_ERR("invalid buf_num_in_sgl, %u!\n", sp->buf_num_in_sgl);
return -WD_EINVAL;
}
--
2.31.1.windows.1