Skip to content

Commit e6fe5e1

Browse files
Jie Wangdavem330
authored andcommitted
net: hns3: refactor two hns3 debugfs functions
Use for statement to optimize some print work of function hclge_dbg_dump_rst_info() and hclge_dbg_dump_mac_enable_status() to improve code simplicity. Signed-off-by: Jie Wang <[email protected]> Signed-off-by: Guangbin Huang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e74a726 commit e6fe5e1

File tree

2 files changed

+48
-50
lines changed

2 files changed

+48
-50
lines changed

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

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,29 @@ hclge_dbg_dump_reg_common(struct hclge_dev *hdev,
258258
return 0;
259259
}
260260

261+
static const struct hclge_dbg_status_dfx_info hclge_dbg_mac_en_status[] = {
262+
{HCLGE_MAC_TX_EN_B, "mac_trans_en"},
263+
{HCLGE_MAC_RX_EN_B, "mac_rcv_en"},
264+
{HCLGE_MAC_PAD_TX_B, "pad_trans_en"},
265+
{HCLGE_MAC_PAD_RX_B, "pad_rcv_en"},
266+
{HCLGE_MAC_1588_TX_B, "1588_trans_en"},
267+
{HCLGE_MAC_1588_RX_B, "1588_rcv_en"},
268+
{HCLGE_MAC_APP_LP_B, "mac_app_loop_en"},
269+
{HCLGE_MAC_LINE_LP_B, "mac_line_loop_en"},
270+
{HCLGE_MAC_FCS_TX_B, "mac_fcs_tx_en"},
271+
{HCLGE_MAC_RX_OVERSIZE_TRUNCATE_B, "mac_rx_oversize_truncate_en"},
272+
{HCLGE_MAC_RX_FCS_STRIP_B, "mac_rx_fcs_strip_en"},
273+
{HCLGE_MAC_RX_FCS_B, "mac_rx_fcs_en"},
274+
{HCLGE_MAC_TX_UNDER_MIN_ERR_B, "mac_tx_under_min_err_en"},
275+
{HCLGE_MAC_TX_OVERSIZE_TRUNCATE_B, "mac_tx_oversize_truncate_en"}
276+
};
277+
261278
static int hclge_dbg_dump_mac_enable_status(struct hclge_dev *hdev, char *buf,
262279
int len, int *pos)
263280
{
264281
struct hclge_config_mac_mode_cmd *req;
265282
struct hclge_desc desc;
266-
u32 loop_en;
283+
u32 loop_en, i, offset;
267284
int ret;
268285

269286
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CONFIG_MAC_MODE, true);
@@ -278,39 +295,12 @@ static int hclge_dbg_dump_mac_enable_status(struct hclge_dev *hdev, char *buf,
278295
req = (struct hclge_config_mac_mode_cmd *)desc.data;
279296
loop_en = le32_to_cpu(req->txrx_pad_fcs_loop_en);
280297

281-
*pos += scnprintf(buf + *pos, len - *pos, "mac_trans_en: %#x\n",
282-
hnae3_get_bit(loop_en, HCLGE_MAC_TX_EN_B));
283-
*pos += scnprintf(buf + *pos, len - *pos, "mac_rcv_en: %#x\n",
284-
hnae3_get_bit(loop_en, HCLGE_MAC_RX_EN_B));
285-
*pos += scnprintf(buf + *pos, len - *pos, "pad_trans_en: %#x\n",
286-
hnae3_get_bit(loop_en, HCLGE_MAC_PAD_TX_B));
287-
*pos += scnprintf(buf + *pos, len - *pos, "pad_rcv_en: %#x\n",
288-
hnae3_get_bit(loop_en, HCLGE_MAC_PAD_RX_B));
289-
*pos += scnprintf(buf + *pos, len - *pos, "1588_trans_en: %#x\n",
290-
hnae3_get_bit(loop_en, HCLGE_MAC_1588_TX_B));
291-
*pos += scnprintf(buf + *pos, len - *pos, "1588_rcv_en: %#x\n",
292-
hnae3_get_bit(loop_en, HCLGE_MAC_1588_RX_B));
293-
*pos += scnprintf(buf + *pos, len - *pos, "mac_app_loop_en: %#x\n",
294-
hnae3_get_bit(loop_en, HCLGE_MAC_APP_LP_B));
295-
*pos += scnprintf(buf + *pos, len - *pos, "mac_line_loop_en: %#x\n",
296-
hnae3_get_bit(loop_en, HCLGE_MAC_LINE_LP_B));
297-
*pos += scnprintf(buf + *pos, len - *pos, "mac_fcs_tx_en: %#x\n",
298-
hnae3_get_bit(loop_en, HCLGE_MAC_FCS_TX_B));
299-
*pos += scnprintf(buf + *pos, len - *pos,
300-
"mac_rx_oversize_truncate_en: %#x\n",
301-
hnae3_get_bit(loop_en,
302-
HCLGE_MAC_RX_OVERSIZE_TRUNCATE_B));
303-
*pos += scnprintf(buf + *pos, len - *pos, "mac_rx_fcs_strip_en: %#x\n",
304-
hnae3_get_bit(loop_en, HCLGE_MAC_RX_FCS_STRIP_B));
305-
*pos += scnprintf(buf + *pos, len - *pos, "mac_rx_fcs_en: %#x\n",
306-
hnae3_get_bit(loop_en, HCLGE_MAC_RX_FCS_B));
307-
*pos += scnprintf(buf + *pos, len - *pos,
308-
"mac_tx_under_min_err_en: %#x\n",
309-
hnae3_get_bit(loop_en, HCLGE_MAC_TX_UNDER_MIN_ERR_B));
310-
*pos += scnprintf(buf + *pos, len - *pos,
311-
"mac_tx_oversize_truncate_en: %#x\n",
312-
hnae3_get_bit(loop_en,
313-
HCLGE_MAC_TX_OVERSIZE_TRUNCATE_B));
298+
for (i = 0; i < ARRAY_SIZE(hclge_dbg_mac_en_status); i++) {
299+
offset = hclge_dbg_mac_en_status[i].offset;
300+
*pos += scnprintf(buf + *pos, len - *pos, "%s: %#x\n",
301+
hclge_dbg_mac_en_status[i].message,
302+
hnae3_get_bit(loop_en, offset));
303+
}
314304

315305
return 0;
316306
}
@@ -1614,8 +1604,19 @@ static int hclge_dbg_dump_fd_counter(struct hclge_dev *hdev, char *buf, int len)
16141604
return 0;
16151605
}
16161606

1607+
static const struct hclge_dbg_status_dfx_info hclge_dbg_rst_info[] = {
1608+
{HCLGE_MISC_VECTOR_REG_BASE, "vector0 interrupt enable status"},
1609+
{HCLGE_MISC_RESET_STS_REG, "reset interrupt source"},
1610+
{HCLGE_MISC_VECTOR_INT_STS, "reset interrupt status"},
1611+
{HCLGE_RAS_PF_OTHER_INT_STS_REG, "RAS interrupt status"},
1612+
{HCLGE_GLOBAL_RESET_REG, "hardware reset status"},
1613+
{HCLGE_NIC_CSQ_DEPTH_REG, "handshake status"},
1614+
{HCLGE_FUN_RST_ING, "function reset status"}
1615+
};
1616+
16171617
int hclge_dbg_dump_rst_info(struct hclge_dev *hdev, char *buf, int len)
16181618
{
1619+
u32 i, offset;
16191620
int pos = 0;
16201621

16211622
pos += scnprintf(buf + pos, len - pos, "PF reset count: %u\n",
@@ -1634,22 +1635,14 @@ int hclge_dbg_dump_rst_info(struct hclge_dev *hdev, char *buf, int len)
16341635
hdev->rst_stats.reset_cnt);
16351636
pos += scnprintf(buf + pos, len - pos, "reset fail count: %u\n",
16361637
hdev->rst_stats.reset_fail_cnt);
1637-
pos += scnprintf(buf + pos, len - pos,
1638-
"vector0 interrupt enable status: 0x%x\n",
1639-
hclge_read_dev(&hdev->hw, HCLGE_MISC_VECTOR_REG_BASE));
1640-
pos += scnprintf(buf + pos, len - pos, "reset interrupt source: 0x%x\n",
1641-
hclge_read_dev(&hdev->hw, HCLGE_MISC_RESET_STS_REG));
1642-
pos += scnprintf(buf + pos, len - pos, "reset interrupt status: 0x%x\n",
1643-
hclge_read_dev(&hdev->hw, HCLGE_MISC_VECTOR_INT_STS));
1644-
pos += scnprintf(buf + pos, len - pos, "RAS interrupt status: 0x%x\n",
1645-
hclge_read_dev(&hdev->hw,
1646-
HCLGE_RAS_PF_OTHER_INT_STS_REG));
1647-
pos += scnprintf(buf + pos, len - pos, "hardware reset status: 0x%x\n",
1648-
hclge_read_dev(&hdev->hw, HCLGE_GLOBAL_RESET_REG));
1649-
pos += scnprintf(buf + pos, len - pos, "handshake status: 0x%x\n",
1650-
hclge_read_dev(&hdev->hw, HCLGE_NIC_CSQ_DEPTH_REG));
1651-
pos += scnprintf(buf + pos, len - pos, "function reset status: 0x%x\n",
1652-
hclge_read_dev(&hdev->hw, HCLGE_FUN_RST_ING));
1638+
1639+
for (i = 0; i < ARRAY_SIZE(hclge_dbg_rst_info); i++) {
1640+
offset = hclge_dbg_rst_info[i].offset;
1641+
pos += scnprintf(buf + pos, len - pos, "%s: 0x%x\n",
1642+
hclge_dbg_rst_info[i].message,
1643+
hclge_read_dev(&hdev->hw, offset));
1644+
}
1645+
16531646
pos += scnprintf(buf + pos, len - pos, "hdev state: 0x%lx\n",
16541647
hdev->state);
16551648

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ struct hclge_dbg_func {
9494
char *buf, int len);
9595
};
9696

97+
struct hclge_dbg_status_dfx_info {
98+
u32 offset;
99+
char message[HCLGE_DBG_MAX_DFX_MSG_LEN];
100+
};
101+
97102
static const struct hclge_dbg_dfx_message hclge_dbg_bios_common_reg[] = {
98103
{false, "Reserved"},
99104
{true, "BP_CPU_STATE"},

0 commit comments

Comments
 (0)