Skip to content

Commit 3945d94

Browse files
Jijie Shaokuba-moo
authored andcommitted
net: hns3: use seq_file for files in fd/ in debugfs
This patch use seq_file for the following nodes: fd_tcam/fd_counter Signed-off-by: Jijie Shao <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Acked-by: Arnd Bergmann <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 2363145 commit 3945d94

File tree

2 files changed

+20
-39
lines changed

2 files changed

+20
-39
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static struct hns3_dbg_cmd_info hns3_dbg_cmd[] = {
310310
.cmd = HNAE3_DBG_CMD_FD_TCAM,
311311
.dentry = HNS3_DBG_DENTRY_FD,
312312
.buf_len = HNS3_DBG_READ_LEN_1MB,
313-
.init = hns3_dbg_common_file_init,
313+
.init = hns3_dbg_common_init_t2,
314314
},
315315
{
316316
.name = "service_task_info",
@@ -338,7 +338,7 @@ static struct hns3_dbg_cmd_info hns3_dbg_cmd[] = {
338338
.cmd = HNAE3_DBG_CMD_FD_COUNTER,
339339
.dentry = HNS3_DBG_DENTRY_FD,
340340
.buf_len = HNS3_DBG_READ_LEN,
341-
.init = hns3_dbg_common_file_init,
341+
.init = hns3_dbg_common_init_t2,
342342
},
343343
{
344344
.name = "umv_info",

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,17 +2009,14 @@ static int hclge_dbg_dump_mng_table(struct hclge_dev *hdev, char *buf, int len)
20092009
return 0;
20102010
}
20112011

2012-
#define HCLGE_DBG_TCAM_BUF_SIZE 256
2013-
20142012
static int hclge_dbg_fd_tcam_read(struct hclge_dev *hdev, bool sel_x,
2015-
char *tcam_buf,
2013+
struct seq_file *s,
20162014
struct hclge_dbg_tcam_msg tcam_msg)
20172015
{
20182016
struct hclge_fd_tcam_config_1_cmd *req1;
20192017
struct hclge_fd_tcam_config_2_cmd *req2;
20202018
struct hclge_fd_tcam_config_3_cmd *req3;
20212019
struct hclge_desc desc[3];
2022-
int pos = 0;
20232020
int ret, i;
20242021
__le32 *req;
20252022

@@ -2041,27 +2038,23 @@ static int hclge_dbg_fd_tcam_read(struct hclge_dev *hdev, bool sel_x,
20412038
if (ret)
20422039
return ret;
20432040

2044-
pos += scnprintf(tcam_buf + pos, HCLGE_DBG_TCAM_BUF_SIZE - pos,
2045-
"read result tcam key %s(%u):\n", sel_x ? "x" : "y",
2046-
tcam_msg.loc);
2041+
seq_printf(s, "read result tcam key %s(%u):\n",
2042+
sel_x ? "x" : "y", tcam_msg.loc);
20472043

20482044
/* tcam_data0 ~ tcam_data1 */
20492045
req = (__le32 *)req1->tcam_data;
20502046
for (i = 0; i < 2; i++)
2051-
pos += scnprintf(tcam_buf + pos, HCLGE_DBG_TCAM_BUF_SIZE - pos,
2052-
"%08x\n", le32_to_cpu(*req++));
2047+
seq_printf(s, "%08x\n", le32_to_cpu(*req++));
20532048

20542049
/* tcam_data2 ~ tcam_data7 */
20552050
req = (__le32 *)req2->tcam_data;
20562051
for (i = 0; i < 6; i++)
2057-
pos += scnprintf(tcam_buf + pos, HCLGE_DBG_TCAM_BUF_SIZE - pos,
2058-
"%08x\n", le32_to_cpu(*req++));
2052+
seq_printf(s, "%08x\n", le32_to_cpu(*req++));
20592053

20602054
/* tcam_data8 ~ tcam_data12 */
20612055
req = (__le32 *)req3->tcam_data;
20622056
for (i = 0; i < 5; i++)
2063-
pos += scnprintf(tcam_buf + pos, HCLGE_DBG_TCAM_BUF_SIZE - pos,
2064-
"%08x\n", le32_to_cpu(*req++));
2057+
seq_printf(s, "%08x\n", le32_to_cpu(*req++));
20652058

20662059
return ret;
20672060
}
@@ -2085,34 +2078,28 @@ static int hclge_dbg_get_rules_location(struct hclge_dev *hdev, u16 *rule_locs)
20852078
return cnt;
20862079
}
20872080

2088-
static int hclge_dbg_dump_fd_tcam(struct hclge_dev *hdev, char *buf, int len)
2081+
static int hclge_dbg_dump_fd_tcam(struct seq_file *s, void *data)
20892082
{
2090-
u32 rule_num = hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_1];
2083+
struct hclge_dev *hdev = hclge_seq_file_to_hdev(s);
20912084
struct hclge_dbg_tcam_msg tcam_msg;
20922085
int i, ret, rule_cnt;
20932086
u16 *rule_locs;
2094-
char *tcam_buf;
2095-
int pos = 0;
2087+
u32 rule_num;
20962088

20972089
if (!hnae3_ae_dev_fd_supported(hdev->ae_dev)) {
20982090
dev_err(&hdev->pdev->dev,
20992091
"Only FD-supported dev supports dump fd tcam\n");
21002092
return -EOPNOTSUPP;
21012093
}
21022094

2095+
rule_num = hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_1];
21032096
if (!hdev->hclge_fd_rule_num || !rule_num)
21042097
return 0;
21052098

21062099
rule_locs = kcalloc(rule_num, sizeof(u16), GFP_KERNEL);
21072100
if (!rule_locs)
21082101
return -ENOMEM;
21092102

2110-
tcam_buf = kzalloc(HCLGE_DBG_TCAM_BUF_SIZE, GFP_KERNEL);
2111-
if (!tcam_buf) {
2112-
kfree(rule_locs);
2113-
return -ENOMEM;
2114-
}
2115-
21162103
rule_cnt = hclge_dbg_get_rules_location(hdev, rule_locs);
21172104
if (rule_cnt < 0) {
21182105
ret = rule_cnt;
@@ -2126,47 +2113,42 @@ static int hclge_dbg_dump_fd_tcam(struct hclge_dev *hdev, char *buf, int len)
21262113
tcam_msg.stage = HCLGE_FD_STAGE_1;
21272114
tcam_msg.loc = rule_locs[i];
21282115

2129-
ret = hclge_dbg_fd_tcam_read(hdev, true, tcam_buf, tcam_msg);
2116+
ret = hclge_dbg_fd_tcam_read(hdev, true, s, tcam_msg);
21302117
if (ret) {
21312118
dev_err(&hdev->pdev->dev,
21322119
"failed to get fd tcam key x, ret = %d\n", ret);
21332120
goto out;
21342121
}
21352122

2136-
pos += scnprintf(buf + pos, len - pos, "%s", tcam_buf);
2137-
2138-
ret = hclge_dbg_fd_tcam_read(hdev, false, tcam_buf, tcam_msg);
2123+
ret = hclge_dbg_fd_tcam_read(hdev, false, s, tcam_msg);
21392124
if (ret) {
21402125
dev_err(&hdev->pdev->dev,
21412126
"failed to get fd tcam key y, ret = %d\n", ret);
21422127
goto out;
21432128
}
21442129

2145-
pos += scnprintf(buf + pos, len - pos, "%s", tcam_buf);
21462130
}
21472131

21482132
out:
2149-
kfree(tcam_buf);
21502133
kfree(rule_locs);
21512134
return ret;
21522135
}
21532136

2154-
static int hclge_dbg_dump_fd_counter(struct hclge_dev *hdev, char *buf, int len)
2137+
static int hclge_dbg_dump_fd_counter(struct seq_file *s, void *data)
21552138
{
2139+
struct hclge_dev *hdev = hclge_seq_file_to_hdev(s);
21562140
u8 func_num = pci_num_vf(hdev->pdev) + 1; /* pf and enabled vf num */
21572141
struct hclge_fd_ad_cnt_read_cmd *req;
21582142
char str_id[HCLGE_DBG_ID_LEN];
21592143
struct hclge_desc desc;
2160-
int pos = 0;
21612144
int ret;
21622145
u64 cnt;
21632146
u8 i;
21642147

21652148
if (!hnae3_ae_dev_fd_supported(hdev->ae_dev))
21662149
return -EOPNOTSUPP;
21672150

2168-
pos += scnprintf(buf + pos, len - pos,
2169-
"func_id\thit_times\n");
2151+
seq_puts(s, "func_id\thit_times\n");
21702152

21712153
for (i = 0; i < func_num; i++) {
21722154
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_FD_CNT_OP, true);
@@ -2180,8 +2162,7 @@ static int hclge_dbg_dump_fd_counter(struct hclge_dev *hdev, char *buf, int len)
21802162
}
21812163
cnt = le64_to_cpu(req->cnt);
21822164
hclge_dbg_get_func_id_str(str_id, i);
2183-
pos += scnprintf(buf + pos, len - pos,
2184-
"%s\t%llu\n", str_id, cnt);
2165+
seq_printf(s, "%s\t%llu\n", str_id, cnt);
21852166
}
21862167

21872168
return 0;
@@ -3020,7 +3001,7 @@ static const struct hclge_dbg_func hclge_dbg_cmd_func[] = {
30203001
},
30213002
{
30223003
.cmd = HNAE3_DBG_CMD_FD_TCAM,
3023-
.dbg_dump = hclge_dbg_dump_fd_tcam,
3004+
.dbg_read_func = hclge_dbg_dump_fd_tcam,
30243005
},
30253006
{
30263007
.cmd = HNAE3_DBG_CMD_MAC_TNL_STATUS,
@@ -3036,7 +3017,7 @@ static const struct hclge_dbg_func hclge_dbg_cmd_func[] = {
30363017
},
30373018
{
30383019
.cmd = HNAE3_DBG_CMD_FD_COUNTER,
3039-
.dbg_dump = hclge_dbg_dump_fd_counter,
3020+
.dbg_read_func = hclge_dbg_dump_fd_counter,
30403021
},
30413022
{
30423023
.cmd = HNAE3_DBG_CMD_UMV_INFO,

0 commit comments

Comments
 (0)