1b2292360Sliuzhongzhu // SPDX-License-Identifier: GPL-2.0+
2b2292360Sliuzhongzhu /* Copyright (c) 2018-2019 Hisilicon Limited. */
3b2292360Sliuzhongzhu
4b2292360Sliuzhongzhu #include <linux/debugfs.h>
5b2292360Sliuzhongzhu #include <linux/device.h>
6b2292360Sliuzhongzhu
7b2292360Sliuzhongzhu #include "hnae3.h"
85e69ea7eSYufeng Mo #include "hns3_debugfs.h"
9b2292360Sliuzhongzhu #include "hns3_enet.h"
10b2292360Sliuzhongzhu
11b2292360Sliuzhongzhu static struct dentry *hns3_dbgfs_root;
12b2292360Sliuzhongzhu
135e69ea7eSYufeng Mo static struct hns3_dbg_dentry_info hns3_dbg_dentry[] = {
145e69ea7eSYufeng Mo {
155e69ea7eSYufeng Mo .name = "tm"
165e69ea7eSYufeng Mo },
1777e91848SHuazhong Tan {
1877e91848SHuazhong Tan .name = "tx_bd_info"
1977e91848SHuazhong Tan },
2077e91848SHuazhong Tan {
2177e91848SHuazhong Tan .name = "rx_bd_info"
2277e91848SHuazhong Tan },
231556ea91SHuazhong Tan {
241556ea91SHuazhong Tan .name = "mac_list"
251556ea91SHuazhong Tan },
26d96b0e59SYufeng Mo {
27d96b0e59SYufeng Mo .name = "reg"
28d96b0e59SYufeng Mo },
29d2f737cfSHao Chen {
30d2f737cfSHao Chen .name = "queue"
31d2f737cfSHao Chen },
32b5a0b70dSHao Chen {
33b5a0b70dSHao Chen .name = "fd"
34b5a0b70dSHao Chen },
355e69ea7eSYufeng Mo /* keep common at the bottom and add new directory above */
365e69ea7eSYufeng Mo {
375e69ea7eSYufeng Mo .name = "common"
385e69ea7eSYufeng Mo },
395e69ea7eSYufeng Mo };
405e69ea7eSYufeng Mo
410c5c135cSHao Chen static int hns3_dbg_bd_file_init(struct hnae3_handle *handle, u32 cmd);
420c5c135cSHao Chen static int hns3_dbg_common_file_init(struct hnae3_handle *handle, u32 cmd);
435e69ea7eSYufeng Mo
445e69ea7eSYufeng Mo static struct hns3_dbg_cmd_info hns3_dbg_cmd[] = {
455e69ea7eSYufeng Mo {
465e69ea7eSYufeng Mo .name = "tm_nodes",
475e69ea7eSYufeng Mo .cmd = HNAE3_DBG_CMD_TM_NODES,
485e69ea7eSYufeng Mo .dentry = HNS3_DBG_DENTRY_TM,
495e69ea7eSYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
505e69ea7eSYufeng Mo .init = hns3_dbg_common_file_init,
515e69ea7eSYufeng Mo },
525e69ea7eSYufeng Mo {
535e69ea7eSYufeng Mo .name = "tm_priority",
545e69ea7eSYufeng Mo .cmd = HNAE3_DBG_CMD_TM_PRI,
555e69ea7eSYufeng Mo .dentry = HNS3_DBG_DENTRY_TM,
565e69ea7eSYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
575e69ea7eSYufeng Mo .init = hns3_dbg_common_file_init,
585e69ea7eSYufeng Mo },
595e69ea7eSYufeng Mo {
605e69ea7eSYufeng Mo .name = "tm_qset",
615e69ea7eSYufeng Mo .cmd = HNAE3_DBG_CMD_TM_QSET,
625e69ea7eSYufeng Mo .dentry = HNS3_DBG_DENTRY_TM,
635e69ea7eSYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
645e69ea7eSYufeng Mo .init = hns3_dbg_common_file_init,
655e69ea7eSYufeng Mo },
66c929bc2aSJiaran Zhang {
677679f28eSGuangbin Huang .name = "tm_map",
687679f28eSGuangbin Huang .cmd = HNAE3_DBG_CMD_TM_MAP,
697679f28eSGuangbin Huang .dentry = HNS3_DBG_DENTRY_TM,
707679f28eSGuangbin Huang .buf_len = HNS3_DBG_READ_LEN_1MB,
717679f28eSGuangbin Huang .init = hns3_dbg_common_file_init,
727679f28eSGuangbin Huang },
737679f28eSGuangbin Huang {
74cad7c215SGuangbin Huang .name = "tm_pg",
75cad7c215SGuangbin Huang .cmd = HNAE3_DBG_CMD_TM_PG,
76cad7c215SGuangbin Huang .dentry = HNS3_DBG_DENTRY_TM,
77cad7c215SGuangbin Huang .buf_len = HNS3_DBG_READ_LEN,
78cad7c215SGuangbin Huang .init = hns3_dbg_common_file_init,
79cad7c215SGuangbin Huang },
80cad7c215SGuangbin Huang {
81cad7c215SGuangbin Huang .name = "tm_port",
82cad7c215SGuangbin Huang .cmd = HNAE3_DBG_CMD_TM_PORT,
83cad7c215SGuangbin Huang .dentry = HNS3_DBG_DENTRY_TM,
84cad7c215SGuangbin Huang .buf_len = HNS3_DBG_READ_LEN,
85cad7c215SGuangbin Huang .init = hns3_dbg_common_file_init,
86cad7c215SGuangbin Huang },
87cad7c215SGuangbin Huang {
880e32038dSGuangbin Huang .name = "tc_sch_info",
890e32038dSGuangbin Huang .cmd = HNAE3_DBG_CMD_TC_SCH_INFO,
900e32038dSGuangbin Huang .dentry = HNS3_DBG_DENTRY_TM,
910e32038dSGuangbin Huang .buf_len = HNS3_DBG_READ_LEN,
920e32038dSGuangbin Huang .init = hns3_dbg_common_file_init,
930e32038dSGuangbin Huang },
940e32038dSGuangbin Huang {
956571ec2eSGuangbin Huang .name = "qos_pause_cfg",
966571ec2eSGuangbin Huang .cmd = HNAE3_DBG_CMD_QOS_PAUSE_CFG,
976571ec2eSGuangbin Huang .dentry = HNS3_DBG_DENTRY_TM,
986571ec2eSGuangbin Huang .buf_len = HNS3_DBG_READ_LEN,
996571ec2eSGuangbin Huang .init = hns3_dbg_common_file_init,
1006571ec2eSGuangbin Huang },
1016571ec2eSGuangbin Huang {
10228d3badaSGuangbin Huang .name = "qos_pri_map",
10328d3badaSGuangbin Huang .cmd = HNAE3_DBG_CMD_QOS_PRI_MAP,
10428d3badaSGuangbin Huang .dentry = HNS3_DBG_DENTRY_TM,
10528d3badaSGuangbin Huang .buf_len = HNS3_DBG_READ_LEN,
10628d3badaSGuangbin Huang .init = hns3_dbg_common_file_init,
10728d3badaSGuangbin Huang },
10828d3badaSGuangbin Huang {
109fddc02ebSGuangbin Huang .name = "qos_dscp_map",
110fddc02ebSGuangbin Huang .cmd = HNAE3_DBG_CMD_QOS_DSCP_MAP,
111fddc02ebSGuangbin Huang .dentry = HNS3_DBG_DENTRY_TM,
112fddc02ebSGuangbin Huang .buf_len = HNS3_DBG_READ_LEN,
113fddc02ebSGuangbin Huang .init = hns3_dbg_common_file_init,
114fddc02ebSGuangbin Huang },
115fddc02ebSGuangbin Huang {
11695b19586SGuangbin Huang .name = "qos_buf_cfg",
11795b19586SGuangbin Huang .cmd = HNAE3_DBG_CMD_QOS_BUF_CFG,
11895b19586SGuangbin Huang .dentry = HNS3_DBG_DENTRY_TM,
11995b19586SGuangbin Huang .buf_len = HNS3_DBG_READ_LEN,
12095b19586SGuangbin Huang .init = hns3_dbg_common_file_init,
12195b19586SGuangbin Huang },
12295b19586SGuangbin Huang {
123c929bc2aSJiaran Zhang .name = "dev_info",
124c929bc2aSJiaran Zhang .cmd = HNAE3_DBG_CMD_DEV_INFO,
125c929bc2aSJiaran Zhang .dentry = HNS3_DBG_DENTRY_COMMON,
126c929bc2aSJiaran Zhang .buf_len = HNS3_DBG_READ_LEN,
127c929bc2aSJiaran Zhang .init = hns3_dbg_common_file_init,
128c929bc2aSJiaran Zhang },
12977e91848SHuazhong Tan {
13077e91848SHuazhong Tan .name = "tx_bd_queue",
13177e91848SHuazhong Tan .cmd = HNAE3_DBG_CMD_TX_BD,
13277e91848SHuazhong Tan .dentry = HNS3_DBG_DENTRY_TX_BD,
13389f6bfb0SJie Wang .buf_len = HNS3_DBG_READ_LEN_5MB,
13477e91848SHuazhong Tan .init = hns3_dbg_bd_file_init,
13577e91848SHuazhong Tan },
13677e91848SHuazhong Tan {
13777e91848SHuazhong Tan .name = "rx_bd_queue",
13877e91848SHuazhong Tan .cmd = HNAE3_DBG_CMD_RX_BD,
13977e91848SHuazhong Tan .dentry = HNS3_DBG_DENTRY_RX_BD,
14077e91848SHuazhong Tan .buf_len = HNS3_DBG_READ_LEN_4MB,
14177e91848SHuazhong Tan .init = hns3_dbg_bd_file_init,
14277e91848SHuazhong Tan },
1431556ea91SHuazhong Tan {
1441556ea91SHuazhong Tan .name = "uc",
1451556ea91SHuazhong Tan .cmd = HNAE3_DBG_CMD_MAC_UC,
1461556ea91SHuazhong Tan .dentry = HNS3_DBG_DENTRY_MAC,
147c7a6e397SGuangbin Huang .buf_len = HNS3_DBG_READ_LEN_128KB,
1481556ea91SHuazhong Tan .init = hns3_dbg_common_file_init,
1491556ea91SHuazhong Tan },
1501556ea91SHuazhong Tan {
1511556ea91SHuazhong Tan .name = "mc",
1521556ea91SHuazhong Tan .cmd = HNAE3_DBG_CMD_MAC_MC,
1531556ea91SHuazhong Tan .dentry = HNS3_DBG_DENTRY_MAC,
1541556ea91SHuazhong Tan .buf_len = HNS3_DBG_READ_LEN,
1551556ea91SHuazhong Tan .init = hns3_dbg_common_file_init,
1561556ea91SHuazhong Tan },
1578ddfd9c4SYufeng Mo {
1588ddfd9c4SYufeng Mo .name = "mng_tbl",
1598ddfd9c4SYufeng Mo .cmd = HNAE3_DBG_CMD_MNG_TBL,
1608ddfd9c4SYufeng Mo .dentry = HNS3_DBG_DENTRY_COMMON,
1618ddfd9c4SYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
1628ddfd9c4SYufeng Mo .init = hns3_dbg_common_file_init,
1638ddfd9c4SYufeng Mo },
164d658ff34SYufeng Mo {
165d658ff34SYufeng Mo .name = "loopback",
166d658ff34SYufeng Mo .cmd = HNAE3_DBG_CMD_LOOPBACK,
167d658ff34SYufeng Mo .dentry = HNS3_DBG_DENTRY_COMMON,
168d658ff34SYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
169d658ff34SYufeng Mo .init = hns3_dbg_common_file_init,
170d658ff34SYufeng Mo },
1719149ca0fSJiaran Zhang {
1729149ca0fSJiaran Zhang .name = "interrupt_info",
1739149ca0fSJiaran Zhang .cmd = HNAE3_DBG_CMD_INTERRUPT_INFO,
1749149ca0fSJiaran Zhang .dentry = HNS3_DBG_DENTRY_COMMON,
1759149ca0fSJiaran Zhang .buf_len = HNS3_DBG_READ_LEN,
1769149ca0fSJiaran Zhang .init = hns3_dbg_common_file_init,
1779149ca0fSJiaran Zhang },
1781a7ff828SJiaran Zhang {
1791a7ff828SJiaran Zhang .name = "reset_info",
1801a7ff828SJiaran Zhang .cmd = HNAE3_DBG_CMD_RESET_INFO,
1811a7ff828SJiaran Zhang .dentry = HNS3_DBG_DENTRY_COMMON,
1821a7ff828SJiaran Zhang .buf_len = HNS3_DBG_READ_LEN,
1831a7ff828SJiaran Zhang .init = hns3_dbg_common_file_init,
1841a7ff828SJiaran Zhang },
1850b198b0dSJiaran Zhang {
1860b198b0dSJiaran Zhang .name = "imp_info",
1870b198b0dSJiaran Zhang .cmd = HNAE3_DBG_CMD_IMP_INFO,
1880b198b0dSJiaran Zhang .dentry = HNS3_DBG_DENTRY_COMMON,
1890b198b0dSJiaran Zhang .buf_len = HNS3_DBG_READ_LEN,
1900b198b0dSJiaran Zhang .init = hns3_dbg_common_file_init,
1910b198b0dSJiaran Zhang },
192e76e6886SJiaran Zhang {
193e76e6886SJiaran Zhang .name = "ncl_config",
194e76e6886SJiaran Zhang .cmd = HNAE3_DBG_CMD_NCL_CONFIG,
195e76e6886SJiaran Zhang .dentry = HNS3_DBG_DENTRY_COMMON,
196e76e6886SJiaran Zhang .buf_len = HNS3_DBG_READ_LEN_128KB,
197e76e6886SJiaran Zhang .init = hns3_dbg_common_file_init,
198e76e6886SJiaran Zhang },
199d96b0e59SYufeng Mo {
2007b07ab06SJiaran Zhang .name = "mac_tnl_status",
2017b07ab06SJiaran Zhang .cmd = HNAE3_DBG_CMD_MAC_TNL_STATUS,
2027b07ab06SJiaran Zhang .dentry = HNS3_DBG_DENTRY_COMMON,
2037b07ab06SJiaran Zhang .buf_len = HNS3_DBG_READ_LEN,
2047b07ab06SJiaran Zhang .init = hns3_dbg_common_file_init,
2057b07ab06SJiaran Zhang },
2067b07ab06SJiaran Zhang {
207d96b0e59SYufeng Mo .name = "bios_common",
208d96b0e59SYufeng Mo .cmd = HNAE3_DBG_CMD_REG_BIOS_COMMON,
209d96b0e59SYufeng Mo .dentry = HNS3_DBG_DENTRY_REG,
210d96b0e59SYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
211d96b0e59SYufeng Mo .init = hns3_dbg_common_file_init,
212d96b0e59SYufeng Mo },
213d96b0e59SYufeng Mo {
214d96b0e59SYufeng Mo .name = "ssu",
215d96b0e59SYufeng Mo .cmd = HNAE3_DBG_CMD_REG_SSU,
216d96b0e59SYufeng Mo .dentry = HNS3_DBG_DENTRY_REG,
217d96b0e59SYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
218d96b0e59SYufeng Mo .init = hns3_dbg_common_file_init,
219d96b0e59SYufeng Mo },
220d96b0e59SYufeng Mo {
221d96b0e59SYufeng Mo .name = "igu_egu",
222d96b0e59SYufeng Mo .cmd = HNAE3_DBG_CMD_REG_IGU_EGU,
223d96b0e59SYufeng Mo .dentry = HNS3_DBG_DENTRY_REG,
224d96b0e59SYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
225d96b0e59SYufeng Mo .init = hns3_dbg_common_file_init,
226d96b0e59SYufeng Mo },
227d96b0e59SYufeng Mo {
228d96b0e59SYufeng Mo .name = "rpu",
229d96b0e59SYufeng Mo .cmd = HNAE3_DBG_CMD_REG_RPU,
230d96b0e59SYufeng Mo .dentry = HNS3_DBG_DENTRY_REG,
231d96b0e59SYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
232d96b0e59SYufeng Mo .init = hns3_dbg_common_file_init,
233d96b0e59SYufeng Mo },
234d96b0e59SYufeng Mo {
235d96b0e59SYufeng Mo .name = "ncsi",
236d96b0e59SYufeng Mo .cmd = HNAE3_DBG_CMD_REG_NCSI,
237d96b0e59SYufeng Mo .dentry = HNS3_DBG_DENTRY_REG,
238d96b0e59SYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
239d96b0e59SYufeng Mo .init = hns3_dbg_common_file_init,
240d96b0e59SYufeng Mo },
241d96b0e59SYufeng Mo {
242d96b0e59SYufeng Mo .name = "rtc",
243d96b0e59SYufeng Mo .cmd = HNAE3_DBG_CMD_REG_RTC,
244d96b0e59SYufeng Mo .dentry = HNS3_DBG_DENTRY_REG,
245d96b0e59SYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
246d96b0e59SYufeng Mo .init = hns3_dbg_common_file_init,
247d96b0e59SYufeng Mo },
248d96b0e59SYufeng Mo {
249d96b0e59SYufeng Mo .name = "ppp",
250d96b0e59SYufeng Mo .cmd = HNAE3_DBG_CMD_REG_PPP,
251d96b0e59SYufeng Mo .dentry = HNS3_DBG_DENTRY_REG,
252d96b0e59SYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
253d96b0e59SYufeng Mo .init = hns3_dbg_common_file_init,
254d96b0e59SYufeng Mo },
255d96b0e59SYufeng Mo {
256d96b0e59SYufeng Mo .name = "rcb",
257d96b0e59SYufeng Mo .cmd = HNAE3_DBG_CMD_REG_RCB,
258d96b0e59SYufeng Mo .dentry = HNS3_DBG_DENTRY_REG,
259d96b0e59SYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
260d96b0e59SYufeng Mo .init = hns3_dbg_common_file_init,
261d96b0e59SYufeng Mo },
262d96b0e59SYufeng Mo {
263d96b0e59SYufeng Mo .name = "tqp",
264d96b0e59SYufeng Mo .cmd = HNAE3_DBG_CMD_REG_TQP,
265d96b0e59SYufeng Mo .dentry = HNS3_DBG_DENTRY_REG,
266c7a6e397SGuangbin Huang .buf_len = HNS3_DBG_READ_LEN_128KB,
267d96b0e59SYufeng Mo .init = hns3_dbg_common_file_init,
268d96b0e59SYufeng Mo },
269d96b0e59SYufeng Mo {
270d96b0e59SYufeng Mo .name = "mac",
271d96b0e59SYufeng Mo .cmd = HNAE3_DBG_CMD_REG_MAC,
272d96b0e59SYufeng Mo .dentry = HNS3_DBG_DENTRY_REG,
273d96b0e59SYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
274d96b0e59SYufeng Mo .init = hns3_dbg_common_file_init,
275d96b0e59SYufeng Mo },
276365e860aSYufeng Mo {
277365e860aSYufeng Mo .name = "dcb",
278365e860aSYufeng Mo .cmd = HNAE3_DBG_CMD_REG_DCB,
279365e860aSYufeng Mo .dentry = HNS3_DBG_DENTRY_REG,
280365e860aSYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
281365e860aSYufeng Mo .init = hns3_dbg_common_file_init,
282365e860aSYufeng Mo },
283d2f737cfSHao Chen {
284d2f737cfSHao Chen .name = "queue_map",
285d2f737cfSHao Chen .cmd = HNAE3_DBG_CMD_QUEUE_MAP,
286d2f737cfSHao Chen .dentry = HNS3_DBG_DENTRY_QUEUE,
287d2f737cfSHao Chen .buf_len = HNS3_DBG_READ_LEN,
288d2f737cfSHao Chen .init = hns3_dbg_common_file_init,
289d2f737cfSHao Chen },
290e44c495dSHao Chen {
291e44c495dSHao Chen .name = "rx_queue_info",
292e44c495dSHao Chen .cmd = HNAE3_DBG_CMD_RX_QUEUE_INFO,
293e44c495dSHao Chen .dentry = HNS3_DBG_DENTRY_QUEUE,
294e44c495dSHao Chen .buf_len = HNS3_DBG_READ_LEN_1MB,
295e44c495dSHao Chen .init = hns3_dbg_common_file_init,
296e44c495dSHao Chen },
297e44c495dSHao Chen {
298e44c495dSHao Chen .name = "tx_queue_info",
299e44c495dSHao Chen .cmd = HNAE3_DBG_CMD_TX_QUEUE_INFO,
300e44c495dSHao Chen .dentry = HNS3_DBG_DENTRY_QUEUE,
301e44c495dSHao Chen .buf_len = HNS3_DBG_READ_LEN_1MB,
302e44c495dSHao Chen .init = hns3_dbg_common_file_init,
303e44c495dSHao Chen },
304b5a0b70dSHao Chen {
305b5a0b70dSHao Chen .name = "fd_tcam",
306b5a0b70dSHao Chen .cmd = HNAE3_DBG_CMD_FD_TCAM,
307b5a0b70dSHao Chen .dentry = HNS3_DBG_DENTRY_FD,
308c7a6e397SGuangbin Huang .buf_len = HNS3_DBG_READ_LEN_1MB,
309b5a0b70dSHao Chen .init = hns3_dbg_common_file_init,
310b5a0b70dSHao Chen },
311058c3be9SYufeng Mo {
312058c3be9SYufeng Mo .name = "service_task_info",
313058c3be9SYufeng Mo .cmd = HNAE3_DBG_CMD_SERV_INFO,
314058c3be9SYufeng Mo .dentry = HNS3_DBG_DENTRY_COMMON,
315058c3be9SYufeng Mo .buf_len = HNS3_DBG_READ_LEN,
316058c3be9SYufeng Mo .init = hns3_dbg_common_file_init,
317058c3be9SYufeng Mo },
3180ca821daSJian Shen {
3190ca821daSJian Shen .name = "vlan_config",
3200ca821daSJian Shen .cmd = HNAE3_DBG_CMD_VLAN_CONFIG,
3210ca821daSJian Shen .dentry = HNS3_DBG_DENTRY_COMMON,
3220ca821daSJian Shen .buf_len = HNS3_DBG_READ_LEN,
3230ca821daSJian Shen .init = hns3_dbg_common_file_init,
3240ca821daSJian Shen },
325b34c157fSHuazhong Tan {
326b34c157fSHuazhong Tan .name = "ptp_info",
327b34c157fSHuazhong Tan .cmd = HNAE3_DBG_CMD_PTP_INFO,
328b34c157fSHuazhong Tan .dentry = HNS3_DBG_DENTRY_COMMON,
329b34c157fSHuazhong Tan .buf_len = HNS3_DBG_READ_LEN,
330b34c157fSHuazhong Tan .init = hns3_dbg_common_file_init,
331b34c157fSHuazhong Tan },
33203a92fe8SJian Shen {
33303a92fe8SJian Shen .name = "fd_counter",
33403a92fe8SJian Shen .cmd = HNAE3_DBG_CMD_FD_COUNTER,
33503a92fe8SJian Shen .dentry = HNS3_DBG_DENTRY_FD,
33603a92fe8SJian Shen .buf_len = HNS3_DBG_READ_LEN,
33703a92fe8SJian Shen .init = hns3_dbg_common_file_init,
33803a92fe8SJian Shen },
339d59daf6aSJian Shen {
340d59daf6aSJian Shen .name = "umv_info",
341d59daf6aSJian Shen .cmd = HNAE3_DBG_CMD_UMV_INFO,
342d59daf6aSJian Shen .dentry = HNS3_DBG_DENTRY_COMMON,
343d59daf6aSJian Shen .buf_len = HNS3_DBG_READ_LEN,
344d59daf6aSJian Shen .init = hns3_dbg_common_file_init,
345d59daf6aSJian Shen },
346850bfb91SHao Chen {
347850bfb91SHao Chen .name = "page_pool_info",
348850bfb91SHao Chen .cmd = HNAE3_DBG_CMD_PAGE_POOL_INFO,
349850bfb91SHao Chen .dentry = HNS3_DBG_DENTRY_COMMON,
350850bfb91SHao Chen .buf_len = HNS3_DBG_READ_LEN,
351850bfb91SHao Chen .init = hns3_dbg_common_file_init,
352850bfb91SHao Chen },
353c99fead7SHuazhong Tan {
354c99fead7SHuazhong Tan .name = "coalesce_info",
355c99fead7SHuazhong Tan .cmd = HNAE3_DBG_CMD_COAL_INFO,
356c99fead7SHuazhong Tan .dentry = HNS3_DBG_DENTRY_COMMON,
357c99fead7SHuazhong Tan .buf_len = HNS3_DBG_READ_LEN_1MB,
358c99fead7SHuazhong Tan .init = hns3_dbg_common_file_init,
359c99fead7SHuazhong Tan },
360c929bc2aSJiaran Zhang };
361c929bc2aSJiaran Zhang
362c929bc2aSJiaran Zhang static struct hns3_dbg_cap_info hns3_dbg_cap[] = {
363c929bc2aSJiaran Zhang {
364c929bc2aSJiaran Zhang .name = "support FD",
365c929bc2aSJiaran Zhang .cap_bit = HNAE3_DEV_SUPPORT_FD_B,
366c929bc2aSJiaran Zhang }, {
367c929bc2aSJiaran Zhang .name = "support GRO",
368c929bc2aSJiaran Zhang .cap_bit = HNAE3_DEV_SUPPORT_GRO_B,
369c929bc2aSJiaran Zhang }, {
370c929bc2aSJiaran Zhang .name = "support FEC",
371c929bc2aSJiaran Zhang .cap_bit = HNAE3_DEV_SUPPORT_FEC_B,
372c929bc2aSJiaran Zhang }, {
373c929bc2aSJiaran Zhang .name = "support UDP GSO",
374c929bc2aSJiaran Zhang .cap_bit = HNAE3_DEV_SUPPORT_UDP_GSO_B,
375c929bc2aSJiaran Zhang }, {
376c929bc2aSJiaran Zhang .name = "support PTP",
377c929bc2aSJiaran Zhang .cap_bit = HNAE3_DEV_SUPPORT_PTP_B,
378c929bc2aSJiaran Zhang }, {
379c929bc2aSJiaran Zhang .name = "support INT QL",
380c929bc2aSJiaran Zhang .cap_bit = HNAE3_DEV_SUPPORT_INT_QL_B,
381c929bc2aSJiaran Zhang }, {
382c929bc2aSJiaran Zhang .name = "support HW TX csum",
383c929bc2aSJiaran Zhang .cap_bit = HNAE3_DEV_SUPPORT_HW_TX_CSUM_B,
384c929bc2aSJiaran Zhang }, {
385c929bc2aSJiaran Zhang .name = "support UDP tunnel csum",
386c929bc2aSJiaran Zhang .cap_bit = HNAE3_DEV_SUPPORT_UDP_TUNNEL_CSUM_B,
387c929bc2aSJiaran Zhang }, {
388c929bc2aSJiaran Zhang .name = "support TX push",
389c929bc2aSJiaran Zhang .cap_bit = HNAE3_DEV_SUPPORT_TX_PUSH_B,
390c929bc2aSJiaran Zhang }, {
391c929bc2aSJiaran Zhang .name = "support imp-controlled PHY",
392c929bc2aSJiaran Zhang .cap_bit = HNAE3_DEV_SUPPORT_PHY_IMP_B,
393c929bc2aSJiaran Zhang }, {
394e65e9f5cSJiaran Zhang .name = "support imp-controlled RAS",
395e65e9f5cSJiaran Zhang .cap_bit = HNAE3_DEV_SUPPORT_RAS_IMP_B,
396e65e9f5cSJiaran Zhang }, {
397c929bc2aSJiaran Zhang .name = "support rxd advanced layout",
398c929bc2aSJiaran Zhang .cap_bit = HNAE3_DEV_SUPPORT_RXD_ADV_LAYOUT_B,
3992ba30662SJian Shen }, {
4002ba30662SJian Shen .name = "support port vlan bypass",
4012ba30662SJian Shen .cap_bit = HNAE3_DEV_SUPPORT_PORT_VLAN_BYPASS_B,
4022ba30662SJian Shen }, {
4032ba30662SJian Shen .name = "support modify vlan filter state",
4042ba30662SJian Shen .cap_bit = HNAE3_DEV_SUPPORT_VLAN_FLTR_MDF_B,
4052cb343b9SHao Lan }, {
4062cb343b9SHao Lan .name = "support FEC statistics",
4072cb343b9SHao Lan .cap_bit = HNAE3_DEV_SUPPORT_FEC_STATS_B,
4080f032f93SHao Chen }, {
4090f032f93SHao Chen .name = "support lane num",
4100f032f93SHao Chen .cap_bit = HNAE3_DEV_SUPPORT_LANE_NUM_B,
4113b064f54SHao Lan }, {
4123b064f54SHao Lan .name = "support wake on lan",
4133b064f54SHao Lan .cap_bit = HNAE3_DEV_SUPPORT_WOL_B,
4146d233612SHao Lan }, {
4156d233612SHao Lan .name = "support tm flush",
4166d233612SHao Lan .cap_bit = HNAE3_DEV_SUPPORT_TM_FLUSH_B,
4172ba30662SJian Shen }
4185e69ea7eSYufeng Mo };
4195e69ea7eSYufeng Mo
420c99fead7SHuazhong Tan static const struct hns3_dbg_item coal_info_items[] = {
421c99fead7SHuazhong Tan { "VEC_ID", 2 },
422c99fead7SHuazhong Tan { "ALGO_STATE", 2 },
423c99fead7SHuazhong Tan { "PROFILE_ID", 2 },
424c99fead7SHuazhong Tan { "CQE_MODE", 2 },
425c99fead7SHuazhong Tan { "TUNE_STATE", 2 },
426c99fead7SHuazhong Tan { "STEPS_LEFT", 2 },
427c99fead7SHuazhong Tan { "STEPS_RIGHT", 2 },
428c99fead7SHuazhong Tan { "TIRED", 2 },
429c99fead7SHuazhong Tan { "SW_GL", 2 },
430c99fead7SHuazhong Tan { "SW_QL", 2 },
431c99fead7SHuazhong Tan { "HW_GL", 2 },
432c99fead7SHuazhong Tan { "HW_QL", 2 },
433c99fead7SHuazhong Tan };
434c99fead7SHuazhong Tan
435c99fead7SHuazhong Tan static const char * const dim_cqe_mode_str[] = { "EQE", "CQE" };
436c99fead7SHuazhong Tan static const char * const dim_state_str[] = { "START", "IN_PROG", "APPLY" };
437c99fead7SHuazhong Tan static const char * const
438c99fead7SHuazhong Tan dim_tune_stat_str[] = { "ON_TOP", "TIRED", "RIGHT", "LEFT" };
439c99fead7SHuazhong Tan
hns3_dbg_fill_content(char * content,u16 len,const struct hns3_dbg_item * items,const char ** result,u16 size)44077e91848SHuazhong Tan static void hns3_dbg_fill_content(char *content, u16 len,
44177e91848SHuazhong Tan const struct hns3_dbg_item *items,
44277e91848SHuazhong Tan const char **result, u16 size)
44377e91848SHuazhong Tan {
4441cf3d556SHao Chen #define HNS3_DBG_LINE_END_LEN 2
44577e91848SHuazhong Tan char *pos = content;
4461cf3d556SHao Chen u16 item_len;
44777e91848SHuazhong Tan u16 i;
44877e91848SHuazhong Tan
4491cf3d556SHao Chen if (!len) {
4501cf3d556SHao Chen return;
4511cf3d556SHao Chen } else if (len <= HNS3_DBG_LINE_END_LEN) {
4521cf3d556SHao Chen *pos++ = '\0';
4531cf3d556SHao Chen return;
45477e91848SHuazhong Tan }
45577e91848SHuazhong Tan
4561cf3d556SHao Chen memset(content, ' ', len);
4571cf3d556SHao Chen len -= HNS3_DBG_LINE_END_LEN;
4581cf3d556SHao Chen
4591cf3d556SHao Chen for (i = 0; i < size; i++) {
4601cf3d556SHao Chen item_len = strlen(items[i].name) + items[i].interval;
4611cf3d556SHao Chen if (len < item_len)
4621cf3d556SHao Chen break;
4631cf3d556SHao Chen
4641cf3d556SHao Chen if (result) {
4651cf3d556SHao Chen if (item_len < strlen(result[i]))
4661cf3d556SHao Chen break;
4675e3d2061SHao Chen memcpy(pos, result[i], strlen(result[i]));
4681cf3d556SHao Chen } else {
4695e3d2061SHao Chen memcpy(pos, items[i].name, strlen(items[i].name));
4701cf3d556SHao Chen }
4711cf3d556SHao Chen pos += item_len;
4721cf3d556SHao Chen len -= item_len;
4731cf3d556SHao Chen }
47477e91848SHuazhong Tan *pos++ = '\n';
47577e91848SHuazhong Tan *pos++ = '\0';
47677e91848SHuazhong Tan }
47777e91848SHuazhong Tan
hns3_get_coal_info(struct hns3_enet_tqp_vector * tqp_vector,char ** result,int i,bool is_tx)478c99fead7SHuazhong Tan static void hns3_get_coal_info(struct hns3_enet_tqp_vector *tqp_vector,
479c99fead7SHuazhong Tan char **result, int i, bool is_tx)
480c99fead7SHuazhong Tan {
481c99fead7SHuazhong Tan unsigned int gl_offset, ql_offset;
482c99fead7SHuazhong Tan struct hns3_enet_coalesce *coal;
483c99fead7SHuazhong Tan unsigned int reg_val;
484c99fead7SHuazhong Tan unsigned int j = 0;
485c99fead7SHuazhong Tan struct dim *dim;
486c99fead7SHuazhong Tan bool ql_enable;
487c99fead7SHuazhong Tan
488c99fead7SHuazhong Tan if (is_tx) {
489c99fead7SHuazhong Tan coal = &tqp_vector->tx_group.coal;
490c99fead7SHuazhong Tan dim = &tqp_vector->tx_group.dim;
491c99fead7SHuazhong Tan gl_offset = HNS3_VECTOR_GL1_OFFSET;
492c99fead7SHuazhong Tan ql_offset = HNS3_VECTOR_TX_QL_OFFSET;
493c99fead7SHuazhong Tan ql_enable = tqp_vector->tx_group.coal.ql_enable;
494c99fead7SHuazhong Tan } else {
495c99fead7SHuazhong Tan coal = &tqp_vector->rx_group.coal;
496c99fead7SHuazhong Tan dim = &tqp_vector->rx_group.dim;
497c99fead7SHuazhong Tan gl_offset = HNS3_VECTOR_GL0_OFFSET;
498c99fead7SHuazhong Tan ql_offset = HNS3_VECTOR_RX_QL_OFFSET;
499c99fead7SHuazhong Tan ql_enable = tqp_vector->rx_group.coal.ql_enable;
500c99fead7SHuazhong Tan }
501c99fead7SHuazhong Tan
502c99fead7SHuazhong Tan sprintf(result[j++], "%d", i);
503*f79d985cSYonglong Liu sprintf(result[j++], "%s", dim->state < ARRAY_SIZE(dim_state_str) ?
504*f79d985cSYonglong Liu dim_state_str[dim->state] : "unknown");
505c99fead7SHuazhong Tan sprintf(result[j++], "%u", dim->profile_ix);
506*f79d985cSYonglong Liu sprintf(result[j++], "%s", dim->mode < ARRAY_SIZE(dim_cqe_mode_str) ?
507*f79d985cSYonglong Liu dim_cqe_mode_str[dim->mode] : "unknown");
508c99fead7SHuazhong Tan sprintf(result[j++], "%s",
509*f79d985cSYonglong Liu dim->tune_state < ARRAY_SIZE(dim_tune_stat_str) ?
510*f79d985cSYonglong Liu dim_tune_stat_str[dim->tune_state] : "unknown");
511c99fead7SHuazhong Tan sprintf(result[j++], "%u", dim->steps_left);
512c99fead7SHuazhong Tan sprintf(result[j++], "%u", dim->steps_right);
513c99fead7SHuazhong Tan sprintf(result[j++], "%u", dim->tired);
514c99fead7SHuazhong Tan sprintf(result[j++], "%u", coal->int_gl);
515c99fead7SHuazhong Tan sprintf(result[j++], "%u", coal->int_ql);
516c99fead7SHuazhong Tan reg_val = readl(tqp_vector->mask_addr + gl_offset) &
517c99fead7SHuazhong Tan HNS3_VECTOR_GL_MASK;
518c99fead7SHuazhong Tan sprintf(result[j++], "%u", reg_val);
519c99fead7SHuazhong Tan if (ql_enable) {
520c99fead7SHuazhong Tan reg_val = readl(tqp_vector->mask_addr + ql_offset) &
521c99fead7SHuazhong Tan HNS3_VECTOR_QL_MASK;
522c99fead7SHuazhong Tan sprintf(result[j++], "%u", reg_val);
523c99fead7SHuazhong Tan } else {
524c99fead7SHuazhong Tan sprintf(result[j++], "NA");
525c99fead7SHuazhong Tan }
526c99fead7SHuazhong Tan }
527c99fead7SHuazhong Tan
hns3_dump_coal_info(struct hnae3_handle * h,char * buf,int len,int * pos,bool is_tx)528c99fead7SHuazhong Tan static void hns3_dump_coal_info(struct hnae3_handle *h, char *buf, int len,
529c99fead7SHuazhong Tan int *pos, bool is_tx)
530c99fead7SHuazhong Tan {
531c99fead7SHuazhong Tan char data_str[ARRAY_SIZE(coal_info_items)][HNS3_DBG_DATA_STR_LEN];
532c99fead7SHuazhong Tan char *result[ARRAY_SIZE(coal_info_items)];
533c99fead7SHuazhong Tan struct hns3_enet_tqp_vector *tqp_vector;
534c99fead7SHuazhong Tan struct hns3_nic_priv *priv = h->priv;
535c99fead7SHuazhong Tan char content[HNS3_DBG_INFO_LEN];
536c99fead7SHuazhong Tan unsigned int i;
537c99fead7SHuazhong Tan
538c99fead7SHuazhong Tan for (i = 0; i < ARRAY_SIZE(coal_info_items); i++)
539c99fead7SHuazhong Tan result[i] = &data_str[i][0];
540c99fead7SHuazhong Tan
541c99fead7SHuazhong Tan *pos += scnprintf(buf + *pos, len - *pos,
542c99fead7SHuazhong Tan "%s interrupt coalesce info:\n",
543c99fead7SHuazhong Tan is_tx ? "tx" : "rx");
544c99fead7SHuazhong Tan hns3_dbg_fill_content(content, sizeof(content), coal_info_items,
545c99fead7SHuazhong Tan NULL, ARRAY_SIZE(coal_info_items));
546c99fead7SHuazhong Tan *pos += scnprintf(buf + *pos, len - *pos, "%s", content);
547c99fead7SHuazhong Tan
548c99fead7SHuazhong Tan for (i = 0; i < priv->vector_num; i++) {
549c99fead7SHuazhong Tan tqp_vector = &priv->tqp_vector[i];
550c99fead7SHuazhong Tan hns3_get_coal_info(tqp_vector, result, i, is_tx);
551c99fead7SHuazhong Tan hns3_dbg_fill_content(content, sizeof(content), coal_info_items,
552c99fead7SHuazhong Tan (const char **)result,
553c99fead7SHuazhong Tan ARRAY_SIZE(coal_info_items));
554c99fead7SHuazhong Tan *pos += scnprintf(buf + *pos, len - *pos, "%s", content);
555c99fead7SHuazhong Tan }
556c99fead7SHuazhong Tan }
557c99fead7SHuazhong Tan
hns3_dbg_coal_info(struct hnae3_handle * h,char * buf,int len)558c99fead7SHuazhong Tan static int hns3_dbg_coal_info(struct hnae3_handle *h, char *buf, int len)
559c99fead7SHuazhong Tan {
560c99fead7SHuazhong Tan int pos = 0;
561c99fead7SHuazhong Tan
562c99fead7SHuazhong Tan hns3_dump_coal_info(h, buf, len, &pos, true);
563c99fead7SHuazhong Tan pos += scnprintf(buf + pos, len - pos, "\n");
564c99fead7SHuazhong Tan hns3_dump_coal_info(h, buf, len, &pos, false);
565c99fead7SHuazhong Tan
566c99fead7SHuazhong Tan return 0;
567c99fead7SHuazhong Tan }
568c99fead7SHuazhong Tan
569907676b1SYunsheng Lin static const struct hns3_dbg_item tx_spare_info_items[] = {
570907676b1SYunsheng Lin { "QUEUE_ID", 2 },
571907676b1SYunsheng Lin { "COPYBREAK", 2 },
572907676b1SYunsheng Lin { "LEN", 7 },
573907676b1SYunsheng Lin { "NTU", 4 },
574907676b1SYunsheng Lin { "NTC", 4 },
575907676b1SYunsheng Lin { "LTC", 4 },
576907676b1SYunsheng Lin { "DMA", 17 },
577907676b1SYunsheng Lin };
578907676b1SYunsheng Lin
hns3_dbg_tx_spare_info(struct hns3_enet_ring * ring,char * buf,int len,u32 ring_num,int * pos)579907676b1SYunsheng Lin static void hns3_dbg_tx_spare_info(struct hns3_enet_ring *ring, char *buf,
580907676b1SYunsheng Lin int len, u32 ring_num, int *pos)
581907676b1SYunsheng Lin {
582907676b1SYunsheng Lin char data_str[ARRAY_SIZE(tx_spare_info_items)][HNS3_DBG_DATA_STR_LEN];
583907676b1SYunsheng Lin struct hns3_tx_spare *tx_spare = ring->tx_spare;
584907676b1SYunsheng Lin char *result[ARRAY_SIZE(tx_spare_info_items)];
585907676b1SYunsheng Lin char content[HNS3_DBG_INFO_LEN];
586907676b1SYunsheng Lin u32 i, j;
587907676b1SYunsheng Lin
588907676b1SYunsheng Lin if (!tx_spare) {
589907676b1SYunsheng Lin *pos += scnprintf(buf + *pos, len - *pos,
590907676b1SYunsheng Lin "tx spare buffer is not enabled\n");
591907676b1SYunsheng Lin return;
592907676b1SYunsheng Lin }
593907676b1SYunsheng Lin
594907676b1SYunsheng Lin for (i = 0; i < ARRAY_SIZE(tx_spare_info_items); i++)
595907676b1SYunsheng Lin result[i] = &data_str[i][0];
596907676b1SYunsheng Lin
597907676b1SYunsheng Lin *pos += scnprintf(buf + *pos, len - *pos, "tx spare buffer info\n");
598907676b1SYunsheng Lin hns3_dbg_fill_content(content, sizeof(content), tx_spare_info_items,
599907676b1SYunsheng Lin NULL, ARRAY_SIZE(tx_spare_info_items));
600907676b1SYunsheng Lin *pos += scnprintf(buf + *pos, len - *pos, "%s", content);
601907676b1SYunsheng Lin
602907676b1SYunsheng Lin for (i = 0; i < ring_num; i++) {
603907676b1SYunsheng Lin j = 0;
6041ec1968eSHao Chen sprintf(result[j++], "%u", i);
6051ec1968eSHao Chen sprintf(result[j++], "%u", ring->tx_copybreak);
6061ec1968eSHao Chen sprintf(result[j++], "%u", tx_spare->len);
6071ec1968eSHao Chen sprintf(result[j++], "%u", tx_spare->next_to_use);
6081ec1968eSHao Chen sprintf(result[j++], "%u", tx_spare->next_to_clean);
6091ec1968eSHao Chen sprintf(result[j++], "%u", tx_spare->last_to_clean);
610907676b1SYunsheng Lin sprintf(result[j++], "%pad", &tx_spare->dma);
611907676b1SYunsheng Lin hns3_dbg_fill_content(content, sizeof(content),
612907676b1SYunsheng Lin tx_spare_info_items,
613907676b1SYunsheng Lin (const char **)result,
614907676b1SYunsheng Lin ARRAY_SIZE(tx_spare_info_items));
615907676b1SYunsheng Lin *pos += scnprintf(buf + *pos, len - *pos, "%s", content);
616907676b1SYunsheng Lin }
617907676b1SYunsheng Lin }
618907676b1SYunsheng Lin
619e44c495dSHao Chen static const struct hns3_dbg_item rx_queue_info_items[] = {
620e44c495dSHao Chen { "QUEUE_ID", 2 },
621e44c495dSHao Chen { "BD_NUM", 2 },
622e44c495dSHao Chen { "BD_LEN", 2 },
623e44c495dSHao Chen { "TAIL", 2 },
624e44c495dSHao Chen { "HEAD", 2 },
625e44c495dSHao Chen { "FBDNUM", 2 },
6266754614aSJie Wang { "PKTNUM", 5 },
62799f6b5fbSYunsheng Lin { "COPYBREAK", 2 },
628e44c495dSHao Chen { "RING_EN", 2 },
629e44c495dSHao Chen { "RX_RING_EN", 2 },
630e44c495dSHao Chen { "BASE_ADDR", 10 },
631e44c495dSHao Chen };
632e44c495dSHao Chen
hns3_dump_rx_queue_info(struct hns3_enet_ring * ring,struct hnae3_ae_dev * ae_dev,char ** result,u32 index)633e44c495dSHao Chen static void hns3_dump_rx_queue_info(struct hns3_enet_ring *ring,
634e44c495dSHao Chen struct hnae3_ae_dev *ae_dev, char **result,
635e44c495dSHao Chen u32 index)
63657ceee2cSliuzhongzhu {
63757ceee2cSliuzhongzhu u32 base_add_l, base_add_h;
638e44c495dSHao Chen u32 j = 0;
639e44c495dSHao Chen
6401ec1968eSHao Chen sprintf(result[j++], "%u", index);
641e44c495dSHao Chen
6421ec1968eSHao Chen sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base +
643e44c495dSHao Chen HNS3_RING_RX_RING_BD_NUM_REG));
644e44c495dSHao Chen
6451ec1968eSHao Chen sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base +
646e44c495dSHao Chen HNS3_RING_RX_RING_BD_LEN_REG));
647e44c495dSHao Chen
6481ec1968eSHao Chen sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base +
649e44c495dSHao Chen HNS3_RING_RX_RING_TAIL_REG));
650e44c495dSHao Chen
6511ec1968eSHao Chen sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base +
652e44c495dSHao Chen HNS3_RING_RX_RING_HEAD_REG));
653e44c495dSHao Chen
6541ec1968eSHao Chen sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base +
655e44c495dSHao Chen HNS3_RING_RX_RING_FBDNUM_REG));
656e44c495dSHao Chen
6571ec1968eSHao Chen sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base +
658e44c495dSHao Chen HNS3_RING_RX_RING_PKTNUM_RECORD_REG));
6591ec1968eSHao Chen sprintf(result[j++], "%u", ring->rx_copybreak);
660e44c495dSHao Chen
6611ec1968eSHao Chen sprintf(result[j++], "%s", readl_relaxed(ring->tqp->io_base +
662e44c495dSHao Chen HNS3_RING_EN_REG) ? "on" : "off");
663e44c495dSHao Chen
664e44c495dSHao Chen if (hnae3_ae_dev_tqp_txrx_indep_supported(ae_dev))
6651ec1968eSHao Chen sprintf(result[j++], "%s", readl_relaxed(ring->tqp->io_base +
666e44c495dSHao Chen HNS3_RING_RX_EN_REG) ? "on" : "off");
667e44c495dSHao Chen else
6681ec1968eSHao Chen sprintf(result[j++], "%s", "NA");
669e44c495dSHao Chen
670e44c495dSHao Chen base_add_h = readl_relaxed(ring->tqp->io_base +
671e44c495dSHao Chen HNS3_RING_RX_RING_BASEADDR_H_REG);
672e44c495dSHao Chen base_add_l = readl_relaxed(ring->tqp->io_base +
673e44c495dSHao Chen HNS3_RING_RX_RING_BASEADDR_L_REG);
674e44c495dSHao Chen sprintf(result[j++], "0x%08x%08x", base_add_h, base_add_l);
675e44c495dSHao Chen }
676e44c495dSHao Chen
hns3_dbg_rx_queue_info(struct hnae3_handle * h,char * buf,int len)677e44c495dSHao Chen static int hns3_dbg_rx_queue_info(struct hnae3_handle *h,
678e44c495dSHao Chen char *buf, int len)
679e44c495dSHao Chen {
680e44c495dSHao Chen char data_str[ARRAY_SIZE(rx_queue_info_items)][HNS3_DBG_DATA_STR_LEN];
681e44c495dSHao Chen struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
682e44c495dSHao Chen char *result[ARRAY_SIZE(rx_queue_info_items)];
683e44c495dSHao Chen struct hns3_nic_priv *priv = h->priv;
684e44c495dSHao Chen char content[HNS3_DBG_INFO_LEN];
685e44c495dSHao Chen struct hns3_enet_ring *ring;
686e44c495dSHao Chen int pos = 0;
687e44c495dSHao Chen u32 i;
68857ceee2cSliuzhongzhu
6895f06b903SYunsheng Lin if (!priv->ring) {
6905f06b903SYunsheng Lin dev_err(&h->pdev->dev, "priv->ring is NULL\n");
69157ceee2cSliuzhongzhu return -EFAULT;
69257ceee2cSliuzhongzhu }
69357ceee2cSliuzhongzhu
694e44c495dSHao Chen for (i = 0; i < ARRAY_SIZE(rx_queue_info_items); i++)
695e44c495dSHao Chen result[i] = &data_str[i][0];
69657ceee2cSliuzhongzhu
697e44c495dSHao Chen hns3_dbg_fill_content(content, sizeof(content), rx_queue_info_items,
698e44c495dSHao Chen NULL, ARRAY_SIZE(rx_queue_info_items));
699e44c495dSHao Chen pos += scnprintf(buf + pos, len - pos, "%s", content);
700e44c495dSHao Chen for (i = 0; i < h->kinfo.num_tqps; i++) {
70157ceee2cSliuzhongzhu /* Each cycle needs to determine whether the instance is reset,
70257ceee2cSliuzhongzhu * to prevent reference to invalid memory. And need to ensure
70357ceee2cSliuzhongzhu * that the following code is executed within 100ms.
70457ceee2cSliuzhongzhu */
7057737f1fbSliuzhongzhu if (!test_bit(HNS3_NIC_STATE_INITED, &priv->state) ||
70657ceee2cSliuzhongzhu test_bit(HNS3_NIC_STATE_RESETTING, &priv->state))
70757ceee2cSliuzhongzhu return -EPERM;
70857ceee2cSliuzhongzhu
7095f06b903SYunsheng Lin ring = &priv->ring[(u32)(i + h->kinfo.num_tqps)];
710e44c495dSHao Chen hns3_dump_rx_queue_info(ring, ae_dev, result, i);
711e44c495dSHao Chen hns3_dbg_fill_content(content, sizeof(content),
712e44c495dSHao Chen rx_queue_info_items,
713e44c495dSHao Chen (const char **)result,
714e44c495dSHao Chen ARRAY_SIZE(rx_queue_info_items));
715e44c495dSHao Chen pos += scnprintf(buf + pos, len - pos, "%s", content);
716e44c495dSHao Chen }
71757ceee2cSliuzhongzhu
718e44c495dSHao Chen return 0;
719e44c495dSHao Chen }
72057ceee2cSliuzhongzhu
721e44c495dSHao Chen static const struct hns3_dbg_item tx_queue_info_items[] = {
722e44c495dSHao Chen { "QUEUE_ID", 2 },
723e44c495dSHao Chen { "BD_NUM", 2 },
724e44c495dSHao Chen { "TC", 2 },
725e44c495dSHao Chen { "TAIL", 2 },
726e44c495dSHao Chen { "HEAD", 2 },
727e44c495dSHao Chen { "FBDNUM", 2 },
728e44c495dSHao Chen { "OFFSET", 2 },
7296754614aSJie Wang { "PKTNUM", 5 },
730e44c495dSHao Chen { "RING_EN", 2 },
731e44c495dSHao Chen { "TX_RING_EN", 2 },
732e44c495dSHao Chen { "BASE_ADDR", 10 },
733e44c495dSHao Chen };
73457ceee2cSliuzhongzhu
hns3_dump_tx_queue_info(struct hns3_enet_ring * ring,struct hnae3_ae_dev * ae_dev,char ** result,u32 index)735e44c495dSHao Chen static void hns3_dump_tx_queue_info(struct hns3_enet_ring *ring,
736e44c495dSHao Chen struct hnae3_ae_dev *ae_dev, char **result,
737e44c495dSHao Chen u32 index)
738e44c495dSHao Chen {
739e44c495dSHao Chen u32 base_add_l, base_add_h;
740e44c495dSHao Chen u32 j = 0;
74157ceee2cSliuzhongzhu
7421ec1968eSHao Chen sprintf(result[j++], "%u", index);
7431ec1968eSHao Chen sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base +
744e44c495dSHao Chen HNS3_RING_TX_RING_BD_NUM_REG));
74557ceee2cSliuzhongzhu
7461ec1968eSHao Chen sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base +
747e44c495dSHao Chen HNS3_RING_TX_RING_TC_REG));
74857ceee2cSliuzhongzhu
7491ec1968eSHao Chen sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base +
750e44c495dSHao Chen HNS3_RING_TX_RING_TAIL_REG));
75157ceee2cSliuzhongzhu
7521ec1968eSHao Chen sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base +
753e44c495dSHao Chen HNS3_RING_TX_RING_HEAD_REG));
754e44c495dSHao Chen
7551ec1968eSHao Chen sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base +
756e44c495dSHao Chen HNS3_RING_TX_RING_FBDNUM_REG));
757e44c495dSHao Chen
7581ec1968eSHao Chen sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base +
759e44c495dSHao Chen HNS3_RING_TX_RING_OFFSET_REG));
760e44c495dSHao Chen
7611ec1968eSHao Chen sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base +
762e44c495dSHao Chen HNS3_RING_TX_RING_PKTNUM_RECORD_REG));
763e44c495dSHao Chen
7641ec1968eSHao Chen sprintf(result[j++], "%s", readl_relaxed(ring->tqp->io_base +
765e44c495dSHao Chen HNS3_RING_EN_REG) ? "on" : "off");
766e44c495dSHao Chen
767e44c495dSHao Chen if (hnae3_ae_dev_tqp_txrx_indep_supported(ae_dev))
7681ec1968eSHao Chen sprintf(result[j++], "%s", readl_relaxed(ring->tqp->io_base +
769e44c495dSHao Chen HNS3_RING_TX_EN_REG) ? "on" : "off");
770e44c495dSHao Chen else
7711ec1968eSHao Chen sprintf(result[j++], "%s", "NA");
772e44c495dSHao Chen
77357ceee2cSliuzhongzhu base_add_h = readl_relaxed(ring->tqp->io_base +
77457ceee2cSliuzhongzhu HNS3_RING_TX_RING_BASEADDR_H_REG);
77557ceee2cSliuzhongzhu base_add_l = readl_relaxed(ring->tqp->io_base +
77657ceee2cSliuzhongzhu HNS3_RING_TX_RING_BASEADDR_L_REG);
777e44c495dSHao Chen sprintf(result[j++], "0x%08x%08x", base_add_h, base_add_l);
778dbaae5bbSGuangbin Huang }
779dbaae5bbSGuangbin Huang
hns3_dbg_tx_queue_info(struct hnae3_handle * h,char * buf,int len)780e44c495dSHao Chen static int hns3_dbg_tx_queue_info(struct hnae3_handle *h,
781e44c495dSHao Chen char *buf, int len)
782e44c495dSHao Chen {
783e44c495dSHao Chen char data_str[ARRAY_SIZE(tx_queue_info_items)][HNS3_DBG_DATA_STR_LEN];
784e44c495dSHao Chen struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
785e44c495dSHao Chen char *result[ARRAY_SIZE(tx_queue_info_items)];
786e44c495dSHao Chen struct hns3_nic_priv *priv = h->priv;
787e44c495dSHao Chen char content[HNS3_DBG_INFO_LEN];
788e44c495dSHao Chen struct hns3_enet_ring *ring;
789e44c495dSHao Chen int pos = 0;
790e44c495dSHao Chen u32 i;
791e44c495dSHao Chen
792e44c495dSHao Chen if (!priv->ring) {
793e44c495dSHao Chen dev_err(&h->pdev->dev, "priv->ring is NULL\n");
794e44c495dSHao Chen return -EFAULT;
795e44c495dSHao Chen }
796e44c495dSHao Chen
797e44c495dSHao Chen for (i = 0; i < ARRAY_SIZE(tx_queue_info_items); i++)
798e44c495dSHao Chen result[i] = &data_str[i][0];
799e44c495dSHao Chen
800e44c495dSHao Chen hns3_dbg_fill_content(content, sizeof(content), tx_queue_info_items,
801e44c495dSHao Chen NULL, ARRAY_SIZE(tx_queue_info_items));
802e44c495dSHao Chen pos += scnprintf(buf + pos, len - pos, "%s", content);
803e44c495dSHao Chen
804e44c495dSHao Chen for (i = 0; i < h->kinfo.num_tqps; i++) {
805e44c495dSHao Chen /* Each cycle needs to determine whether the instance is reset,
806e44c495dSHao Chen * to prevent reference to invalid memory. And need to ensure
807e44c495dSHao Chen * that the following code is executed within 100ms.
808e44c495dSHao Chen */
809e44c495dSHao Chen if (!test_bit(HNS3_NIC_STATE_INITED, &priv->state) ||
810e44c495dSHao Chen test_bit(HNS3_NIC_STATE_RESETTING, &priv->state))
811e44c495dSHao Chen return -EPERM;
812e44c495dSHao Chen
813e44c495dSHao Chen ring = &priv->ring[i];
814e44c495dSHao Chen hns3_dump_tx_queue_info(ring, ae_dev, result, i);
815e44c495dSHao Chen hns3_dbg_fill_content(content, sizeof(content),
816e44c495dSHao Chen tx_queue_info_items,
817e44c495dSHao Chen (const char **)result,
818e44c495dSHao Chen ARRAY_SIZE(tx_queue_info_items));
819e44c495dSHao Chen pos += scnprintf(buf + pos, len - pos, "%s", content);
82057ceee2cSliuzhongzhu }
82157ceee2cSliuzhongzhu
822907676b1SYunsheng Lin hns3_dbg_tx_spare_info(ring, buf, len, h->kinfo.num_tqps, &pos);
823907676b1SYunsheng Lin
82457ceee2cSliuzhongzhu return 0;
82557ceee2cSliuzhongzhu }
82657ceee2cSliuzhongzhu
827d2f737cfSHao Chen static const struct hns3_dbg_item queue_map_items[] = {
828d2f737cfSHao Chen { "local_queue_id", 2 },
829d2f737cfSHao Chen { "global_queue_id", 2 },
830d2f737cfSHao Chen { "vector_id", 2 },
831d2f737cfSHao Chen };
832d2f737cfSHao Chen
hns3_dbg_queue_map(struct hnae3_handle * h,char * buf,int len)833d2f737cfSHao Chen static int hns3_dbg_queue_map(struct hnae3_handle *h, char *buf, int len)
8340c29d191Sliuzhongzhu {
835d2f737cfSHao Chen char data_str[ARRAY_SIZE(queue_map_items)][HNS3_DBG_DATA_STR_LEN];
836d2f737cfSHao Chen char *result[ARRAY_SIZE(queue_map_items)];
8370c29d191Sliuzhongzhu struct hns3_nic_priv *priv = h->priv;
838d2f737cfSHao Chen char content[HNS3_DBG_INFO_LEN];
839d2f737cfSHao Chen int pos = 0;
840d2f737cfSHao Chen int j;
841d2f737cfSHao Chen u32 i;
8420c29d191Sliuzhongzhu
8430c29d191Sliuzhongzhu if (!h->ae_algo->ops->get_global_queue_id)
8440c29d191Sliuzhongzhu return -EOPNOTSUPP;
8450c29d191Sliuzhongzhu
846d2f737cfSHao Chen for (i = 0; i < ARRAY_SIZE(queue_map_items); i++)
847d2f737cfSHao Chen result[i] = &data_str[i][0];
8480c29d191Sliuzhongzhu
849d2f737cfSHao Chen hns3_dbg_fill_content(content, sizeof(content), queue_map_items,
850d2f737cfSHao Chen NULL, ARRAY_SIZE(queue_map_items));
851d2f737cfSHao Chen pos += scnprintf(buf + pos, len - pos, "%s", content);
852d2f737cfSHao Chen for (i = 0; i < h->kinfo.num_tqps; i++) {
8535f06b903SYunsheng Lin if (!priv->ring || !priv->ring[i].tqp_vector)
8540c29d191Sliuzhongzhu continue;
855d2f737cfSHao Chen j = 0;
856d2f737cfSHao Chen sprintf(result[j++], "%u", i);
857d2f737cfSHao Chen sprintf(result[j++], "%u",
858d2f737cfSHao Chen h->ae_algo->ops->get_global_queue_id(h, i));
8595aea2da5SHao Chen sprintf(result[j++], "%d",
860d2f737cfSHao Chen priv->ring[i].tqp_vector->vector_irq);
861d2f737cfSHao Chen hns3_dbg_fill_content(content, sizeof(content), queue_map_items,
862d2f737cfSHao Chen (const char **)result,
863d2f737cfSHao Chen ARRAY_SIZE(queue_map_items));
864d2f737cfSHao Chen pos += scnprintf(buf + pos, len - pos, "%s", content);
8650c29d191Sliuzhongzhu }
8660c29d191Sliuzhongzhu
8670c29d191Sliuzhongzhu return 0;
8680c29d191Sliuzhongzhu }
8690c29d191Sliuzhongzhu
87077e91848SHuazhong Tan static const struct hns3_dbg_item rx_bd_info_items[] = {
87177e91848SHuazhong Tan { "BD_IDX", 3 },
87277e91848SHuazhong Tan { "L234_INFO", 2 },
87377e91848SHuazhong Tan { "PKT_LEN", 3 },
87477e91848SHuazhong Tan { "SIZE", 4 },
87577e91848SHuazhong Tan { "RSS_HASH", 4 },
87677e91848SHuazhong Tan { "FD_ID", 2 },
87777e91848SHuazhong Tan { "VLAN_TAG", 2 },
87877e91848SHuazhong Tan { "O_DM_VLAN_ID_FB", 2 },
87977e91848SHuazhong Tan { "OT_VLAN_TAG", 2 },
88077e91848SHuazhong Tan { "BD_BASE_INFO", 2 },
88177e91848SHuazhong Tan { "PTYPE", 2 },
88277e91848SHuazhong Tan { "HW_CSUM", 2 },
88377e91848SHuazhong Tan };
88477e91848SHuazhong Tan
hns3_dump_rx_bd_info(struct hns3_nic_priv * priv,struct hns3_desc * desc,char ** result,int idx)88577e91848SHuazhong Tan static void hns3_dump_rx_bd_info(struct hns3_nic_priv *priv,
88677e91848SHuazhong Tan struct hns3_desc *desc, char **result, int idx)
887122bedc5Sliuzhongzhu {
88877e91848SHuazhong Tan unsigned int j = 0;
889122bedc5Sliuzhongzhu
8901ec1968eSHao Chen sprintf(result[j++], "%d", idx);
89177e91848SHuazhong Tan sprintf(result[j++], "%#x", le32_to_cpu(desc->rx.l234_info));
8921ec1968eSHao Chen sprintf(result[j++], "%u", le16_to_cpu(desc->rx.pkt_len));
8931ec1968eSHao Chen sprintf(result[j++], "%u", le16_to_cpu(desc->rx.size));
89477e91848SHuazhong Tan sprintf(result[j++], "%#x", le32_to_cpu(desc->rx.rss_hash));
8951ec1968eSHao Chen sprintf(result[j++], "%u", le16_to_cpu(desc->rx.fd_id));
8961ec1968eSHao Chen sprintf(result[j++], "%u", le16_to_cpu(desc->rx.vlan_tag));
8971ec1968eSHao Chen sprintf(result[j++], "%u", le16_to_cpu(desc->rx.o_dm_vlan_id_fb));
8981ec1968eSHao Chen sprintf(result[j++], "%u", le16_to_cpu(desc->rx.ot_vlan_tag));
89977e91848SHuazhong Tan sprintf(result[j++], "%#x", le32_to_cpu(desc->rx.bd_base_info));
90077e91848SHuazhong Tan if (test_bit(HNS3_NIC_STATE_RXD_ADV_LAYOUT_ENABLE, &priv->state)) {
90177e91848SHuazhong Tan u32 ol_info = le32_to_cpu(desc->rx.ol_info);
902122bedc5Sliuzhongzhu
90377e91848SHuazhong Tan sprintf(result[j++], "%5lu", hnae3_get_field(ol_info,
90477e91848SHuazhong Tan HNS3_RXD_PTYPE_M,
90577e91848SHuazhong Tan HNS3_RXD_PTYPE_S));
90677e91848SHuazhong Tan sprintf(result[j++], "%7u", le16_to_cpu(desc->csum));
907b1533adaSHuazhong Tan } else {
90877e91848SHuazhong Tan sprintf(result[j++], "NA");
90977e91848SHuazhong Tan sprintf(result[j++], "NA");
91077e91848SHuazhong Tan }
911b1533adaSHuazhong Tan }
912b1533adaSHuazhong Tan
hns3_dbg_rx_bd_info(struct hns3_dbg_data * d,char * buf,int len)91377e91848SHuazhong Tan static int hns3_dbg_rx_bd_info(struct hns3_dbg_data *d, char *buf, int len)
91477e91848SHuazhong Tan {
91577e91848SHuazhong Tan char data_str[ARRAY_SIZE(rx_bd_info_items)][HNS3_DBG_DATA_STR_LEN];
91677e91848SHuazhong Tan struct hns3_nic_priv *priv = d->handle->priv;
91777e91848SHuazhong Tan char *result[ARRAY_SIZE(rx_bd_info_items)];
91877e91848SHuazhong Tan char content[HNS3_DBG_INFO_LEN];
91977e91848SHuazhong Tan struct hns3_enet_ring *ring;
92077e91848SHuazhong Tan struct hns3_desc *desc;
92177e91848SHuazhong Tan unsigned int i;
92277e91848SHuazhong Tan int pos = 0;
923122bedc5Sliuzhongzhu
92477e91848SHuazhong Tan if (d->qid >= d->handle->kinfo.num_tqps) {
92577e91848SHuazhong Tan dev_err(&d->handle->pdev->dev,
92677e91848SHuazhong Tan "queue%u is not in use\n", d->qid);
92777e91848SHuazhong Tan return -EINVAL;
92877e91848SHuazhong Tan }
929122bedc5Sliuzhongzhu
93077e91848SHuazhong Tan for (i = 0; i < ARRAY_SIZE(rx_bd_info_items); i++)
93177e91848SHuazhong Tan result[i] = &data_str[i][0];
932b1533adaSHuazhong Tan
93377e91848SHuazhong Tan pos += scnprintf(buf + pos, len - pos,
93477e91848SHuazhong Tan "Queue %u rx bd info:\n", d->qid);
93577e91848SHuazhong Tan hns3_dbg_fill_content(content, sizeof(content), rx_bd_info_items,
93677e91848SHuazhong Tan NULL, ARRAY_SIZE(rx_bd_info_items));
93777e91848SHuazhong Tan pos += scnprintf(buf + pos, len - pos, "%s", content);
93877e91848SHuazhong Tan
93977e91848SHuazhong Tan ring = &priv->ring[d->qid + d->handle->kinfo.num_tqps];
94077e91848SHuazhong Tan for (i = 0; i < ring->desc_num; i++) {
94177e91848SHuazhong Tan desc = &ring->desc[i];
94277e91848SHuazhong Tan
94377e91848SHuazhong Tan hns3_dump_rx_bd_info(priv, desc, result, i);
94477e91848SHuazhong Tan hns3_dbg_fill_content(content, sizeof(content),
94577e91848SHuazhong Tan rx_bd_info_items, (const char **)result,
94677e91848SHuazhong Tan ARRAY_SIZE(rx_bd_info_items));
94777e91848SHuazhong Tan pos += scnprintf(buf + pos, len - pos, "%s", content);
94877e91848SHuazhong Tan }
94977e91848SHuazhong Tan
95077e91848SHuazhong Tan return 0;
95177e91848SHuazhong Tan }
95277e91848SHuazhong Tan
95377e91848SHuazhong Tan static const struct hns3_dbg_item tx_bd_info_items[] = {
954630a6738SGuangbin Huang { "BD_IDX", 2 },
955630a6738SGuangbin Huang { "ADDRESS", 13 },
95677e91848SHuazhong Tan { "VLAN_TAG", 2 },
95777e91848SHuazhong Tan { "SIZE", 2 },
95877e91848SHuazhong Tan { "T_CS_VLAN_TSO", 2 },
95977e91848SHuazhong Tan { "OT_VLAN_TAG", 3 },
960630a6738SGuangbin Huang { "TV", 5 },
96177e91848SHuazhong Tan { "OLT_VLAN_LEN", 2 },
96277e91848SHuazhong Tan { "PAYLEN_OL4CS", 2 },
96377e91848SHuazhong Tan { "BD_FE_SC_VLD", 2 },
96477e91848SHuazhong Tan { "MSS_HW_CSUM", 0 },
96577e91848SHuazhong Tan };
96677e91848SHuazhong Tan
hns3_dump_tx_bd_info(struct hns3_desc * desc,char ** result,int idx)967ed1c6f35SPeiyang Wang static void hns3_dump_tx_bd_info(struct hns3_desc *desc, char **result, int idx)
96877e91848SHuazhong Tan {
96977e91848SHuazhong Tan unsigned int j = 0;
97077e91848SHuazhong Tan
9711ec1968eSHao Chen sprintf(result[j++], "%d", idx);
97277e91848SHuazhong Tan sprintf(result[j++], "%#llx", le64_to_cpu(desc->addr));
9731ec1968eSHao Chen sprintf(result[j++], "%u", le16_to_cpu(desc->tx.vlan_tag));
9741ec1968eSHao Chen sprintf(result[j++], "%u", le16_to_cpu(desc->tx.send_size));
97577e91848SHuazhong Tan sprintf(result[j++], "%#x",
97677e91848SHuazhong Tan le32_to_cpu(desc->tx.type_cs_vlan_tso_len));
9771ec1968eSHao Chen sprintf(result[j++], "%u", le16_to_cpu(desc->tx.outer_vlan_tag));
9781ec1968eSHao Chen sprintf(result[j++], "%u", le16_to_cpu(desc->tx.tv));
9791ec1968eSHao Chen sprintf(result[j++], "%u",
98077e91848SHuazhong Tan le32_to_cpu(desc->tx.ol_type_vlan_len_msec));
98177e91848SHuazhong Tan sprintf(result[j++], "%#x", le32_to_cpu(desc->tx.paylen_ol4cs));
98277e91848SHuazhong Tan sprintf(result[j++], "%#x", le16_to_cpu(desc->tx.bdtp_fe_sc_vld_ra_ri));
9831ec1968eSHao Chen sprintf(result[j++], "%u", le16_to_cpu(desc->tx.mss_hw_csum));
98477e91848SHuazhong Tan }
98577e91848SHuazhong Tan
hns3_dbg_tx_bd_info(struct hns3_dbg_data * d,char * buf,int len)98677e91848SHuazhong Tan static int hns3_dbg_tx_bd_info(struct hns3_dbg_data *d, char *buf, int len)
98777e91848SHuazhong Tan {
98877e91848SHuazhong Tan char data_str[ARRAY_SIZE(tx_bd_info_items)][HNS3_DBG_DATA_STR_LEN];
98977e91848SHuazhong Tan struct hns3_nic_priv *priv = d->handle->priv;
99077e91848SHuazhong Tan char *result[ARRAY_SIZE(tx_bd_info_items)];
99177e91848SHuazhong Tan char content[HNS3_DBG_INFO_LEN];
99277e91848SHuazhong Tan struct hns3_enet_ring *ring;
99377e91848SHuazhong Tan struct hns3_desc *desc;
99477e91848SHuazhong Tan unsigned int i;
99577e91848SHuazhong Tan int pos = 0;
99677e91848SHuazhong Tan
99777e91848SHuazhong Tan if (d->qid >= d->handle->kinfo.num_tqps) {
99877e91848SHuazhong Tan dev_err(&d->handle->pdev->dev,
99977e91848SHuazhong Tan "queue%u is not in use\n", d->qid);
100077e91848SHuazhong Tan return -EINVAL;
100177e91848SHuazhong Tan }
100277e91848SHuazhong Tan
100377e91848SHuazhong Tan for (i = 0; i < ARRAY_SIZE(tx_bd_info_items); i++)
100477e91848SHuazhong Tan result[i] = &data_str[i][0];
100577e91848SHuazhong Tan
100677e91848SHuazhong Tan pos += scnprintf(buf + pos, len - pos,
100777e91848SHuazhong Tan "Queue %u tx bd info:\n", d->qid);
100877e91848SHuazhong Tan hns3_dbg_fill_content(content, sizeof(content), tx_bd_info_items,
100977e91848SHuazhong Tan NULL, ARRAY_SIZE(tx_bd_info_items));
101077e91848SHuazhong Tan pos += scnprintf(buf + pos, len - pos, "%s", content);
101177e91848SHuazhong Tan
101277e91848SHuazhong Tan ring = &priv->ring[d->qid];
101377e91848SHuazhong Tan for (i = 0; i < ring->desc_num; i++) {
101477e91848SHuazhong Tan desc = &ring->desc[i];
101577e91848SHuazhong Tan
1016ed1c6f35SPeiyang Wang hns3_dump_tx_bd_info(desc, result, i);
101777e91848SHuazhong Tan hns3_dbg_fill_content(content, sizeof(content),
101877e91848SHuazhong Tan tx_bd_info_items, (const char **)result,
101977e91848SHuazhong Tan ARRAY_SIZE(tx_bd_info_items));
102077e91848SHuazhong Tan pos += scnprintf(buf + pos, len - pos, "%s", content);
102177e91848SHuazhong Tan }
1022122bedc5Sliuzhongzhu
1023122bedc5Sliuzhongzhu return 0;
1024122bedc5Sliuzhongzhu }
1025122bedc5Sliuzhongzhu
1026c929bc2aSJiaran Zhang static void
hns3_dbg_dev_caps(struct hnae3_handle * h,char * buf,int len,int * pos)1027c929bc2aSJiaran Zhang hns3_dbg_dev_caps(struct hnae3_handle *h, char *buf, int len, int *pos)
10289484e337SGuangbin Huang {
10299484e337SGuangbin Huang struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
10301026b153SHao Chen const char * const str[] = {"no", "yes"};
1031c929bc2aSJiaran Zhang unsigned long *caps = ae_dev->caps;
1032c929bc2aSJiaran Zhang u32 i, state;
10339484e337SGuangbin Huang
1034c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "dev capability:\n");
10359484e337SGuangbin Huang
1036c929bc2aSJiaran Zhang for (i = 0; i < ARRAY_SIZE(hns3_dbg_cap); i++) {
1037c929bc2aSJiaran Zhang state = test_bit(hns3_dbg_cap[i].cap_bit, caps);
1038c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "%s: %s\n",
1039c929bc2aSJiaran Zhang hns3_dbg_cap[i].name, str[state]);
10409484e337SGuangbin Huang }
10419484e337SGuangbin Huang
1042c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "\n");
1043c929bc2aSJiaran Zhang }
1044c929bc2aSJiaran Zhang
1045c929bc2aSJiaran Zhang static void
hns3_dbg_dev_specs(struct hnae3_handle * h,char * buf,int len,int * pos)1046c929bc2aSJiaran Zhang hns3_dbg_dev_specs(struct hnae3_handle *h, char *buf, int len, int *pos)
1047b4442ec5SGuangbin Huang {
1048b4442ec5SGuangbin Huang struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
1049b4442ec5SGuangbin Huang struct hnae3_dev_specs *dev_specs = &ae_dev->dev_specs;
1050b4442ec5SGuangbin Huang struct hnae3_knic_private_info *kinfo = &h->kinfo;
1051dd2bbc2eSJijie Shao struct net_device *dev = kinfo->netdev;
1052b4442ec5SGuangbin Huang
1053c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "dev_spec:\n");
1054c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "MAC entry num: %u\n",
1055c929bc2aSJiaran Zhang dev_specs->mac_entry_num);
1056c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "MNG entry num: %u\n",
1057c929bc2aSJiaran Zhang dev_specs->mng_entry_num);
1058c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "MAX non tso bd num: %u\n",
1059b4442ec5SGuangbin Huang dev_specs->max_non_tso_bd_num);
1060c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "RSS ind tbl size: %u\n",
1061b4442ec5SGuangbin Huang dev_specs->rss_ind_tbl_size);
1062c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "RSS key size: %u\n",
1063c929bc2aSJiaran Zhang dev_specs->rss_key_size);
1064c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "RSS size: %u\n",
1065c929bc2aSJiaran Zhang kinfo->rss_size);
1066c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "Allocated RSS size: %u\n",
1067c929bc2aSJiaran Zhang kinfo->req_rss_size);
1068c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos,
1069c929bc2aSJiaran Zhang "Task queue pairs numbers: %u\n",
1070c929bc2aSJiaran Zhang kinfo->num_tqps);
1071c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "RX buffer length: %u\n",
1072c929bc2aSJiaran Zhang kinfo->rx_buf_len);
1073c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "Desc num per TX queue: %u\n",
1074c929bc2aSJiaran Zhang kinfo->num_tx_desc);
1075c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "Desc num per RX queue: %u\n",
1076c929bc2aSJiaran Zhang kinfo->num_rx_desc);
1077c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos,
1078c929bc2aSJiaran Zhang "Total number of enabled TCs: %u\n",
107935244430SJian Shen kinfo->tc_info.num_tc);
1080c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "MAX INT QL: %u\n",
1081c929bc2aSJiaran Zhang dev_specs->int_ql_max);
1082c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "MAX INT GL: %u\n",
1083c929bc2aSJiaran Zhang dev_specs->max_int_gl);
1084c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "MAX TM RATE: %u\n",
1085c929bc2aSJiaran Zhang dev_specs->max_tm_rate);
1086c929bc2aSJiaran Zhang *pos += scnprintf(buf + *pos, len - *pos, "MAX QSET number: %u\n",
1087c929bc2aSJiaran Zhang dev_specs->max_qset_num);
1088e435a6b5SGuangbin Huang *pos += scnprintf(buf + *pos, len - *pos, "umv size: %u\n",
1089e435a6b5SGuangbin Huang dev_specs->umv_size);
10905c56ff48SGuangbin Huang *pos += scnprintf(buf + *pos, len - *pos, "mc mac size: %u\n",
10915c56ff48SGuangbin Huang dev_specs->mc_mac_size);
10924e4c03f6SGuangbin Huang *pos += scnprintf(buf + *pos, len - *pos, "MAC statistics number: %u\n",
10934e4c03f6SGuangbin Huang dev_specs->mac_stats_num);
1094dd2bbc2eSJijie Shao *pos += scnprintf(buf + *pos, len - *pos,
1095dd2bbc2eSJijie Shao "TX timeout threshold: %d seconds\n",
1096dd2bbc2eSJijie Shao dev->watchdog_timeo / HZ);
1097c929bc2aSJiaran Zhang }
1098c929bc2aSJiaran Zhang
hns3_dbg_dev_info(struct hnae3_handle * h,char * buf,int len)1099c929bc2aSJiaran Zhang static int hns3_dbg_dev_info(struct hnae3_handle *h, char *buf, int len)
1100c929bc2aSJiaran Zhang {
1101c929bc2aSJiaran Zhang int pos = 0;
1102c929bc2aSJiaran Zhang
1103c929bc2aSJiaran Zhang hns3_dbg_dev_caps(h, buf, len, &pos);
1104c929bc2aSJiaran Zhang
1105c929bc2aSJiaran Zhang hns3_dbg_dev_specs(h, buf, len, &pos);
1106c929bc2aSJiaran Zhang
1107c929bc2aSJiaran Zhang return 0;
1108b4442ec5SGuangbin Huang }
1109b4442ec5SGuangbin Huang
1110850bfb91SHao Chen static const struct hns3_dbg_item page_pool_info_items[] = {
1111850bfb91SHao Chen { "QUEUE_ID", 2 },
1112850bfb91SHao Chen { "ALLOCATE_CNT", 2 },
1113850bfb91SHao Chen { "FREE_CNT", 6 },
1114850bfb91SHao Chen { "POOL_SIZE(PAGE_NUM)", 2 },
1115850bfb91SHao Chen { "ORDER", 2 },
1116850bfb91SHao Chen { "NUMA_ID", 2 },
1117850bfb91SHao Chen { "MAX_LEN", 2 },
1118850bfb91SHao Chen };
1119850bfb91SHao Chen
hns3_dump_page_pool_info(struct hns3_enet_ring * ring,char ** result,u32 index)1120850bfb91SHao Chen static void hns3_dump_page_pool_info(struct hns3_enet_ring *ring,
1121850bfb91SHao Chen char **result, u32 index)
1122850bfb91SHao Chen {
1123850bfb91SHao Chen u32 j = 0;
1124850bfb91SHao Chen
1125850bfb91SHao Chen sprintf(result[j++], "%u", index);
11269c147917SHao Chen sprintf(result[j++], "%u",
11279c147917SHao Chen READ_ONCE(ring->page_pool->pages_state_hold_cnt));
11289fcadbaaSHao Chen sprintf(result[j++], "%d",
1129850bfb91SHao Chen atomic_read(&ring->page_pool->pages_state_release_cnt));
1130850bfb91SHao Chen sprintf(result[j++], "%u", ring->page_pool->p.pool_size);
1131850bfb91SHao Chen sprintf(result[j++], "%u", ring->page_pool->p.order);
1132850bfb91SHao Chen sprintf(result[j++], "%d", ring->page_pool->p.nid);
1133850bfb91SHao Chen sprintf(result[j++], "%uK", ring->page_pool->p.max_len / 1024);
1134850bfb91SHao Chen }
1135850bfb91SHao Chen
1136850bfb91SHao Chen static int
hns3_dbg_page_pool_info(struct hnae3_handle * h,char * buf,int len)1137850bfb91SHao Chen hns3_dbg_page_pool_info(struct hnae3_handle *h, char *buf, int len)
1138850bfb91SHao Chen {
1139850bfb91SHao Chen char data_str[ARRAY_SIZE(page_pool_info_items)][HNS3_DBG_DATA_STR_LEN];
1140850bfb91SHao Chen char *result[ARRAY_SIZE(page_pool_info_items)];
1141850bfb91SHao Chen struct hns3_nic_priv *priv = h->priv;
1142850bfb91SHao Chen char content[HNS3_DBG_INFO_LEN];
1143850bfb91SHao Chen struct hns3_enet_ring *ring;
1144850bfb91SHao Chen int pos = 0;
1145850bfb91SHao Chen u32 i;
1146850bfb91SHao Chen
1147850bfb91SHao Chen if (!priv->ring) {
1148850bfb91SHao Chen dev_err(&h->pdev->dev, "priv->ring is NULL\n");
1149850bfb91SHao Chen return -EFAULT;
1150850bfb91SHao Chen }
1151850bfb91SHao Chen
1152b8af344cSHao Chen if (!priv->ring[h->kinfo.num_tqps].page_pool) {
1153b8af344cSHao Chen dev_err(&h->pdev->dev, "page pool is not initialized\n");
1154b8af344cSHao Chen return -EFAULT;
1155b8af344cSHao Chen }
1156b8af344cSHao Chen
1157850bfb91SHao Chen for (i = 0; i < ARRAY_SIZE(page_pool_info_items); i++)
1158850bfb91SHao Chen result[i] = &data_str[i][0];
1159850bfb91SHao Chen
1160850bfb91SHao Chen hns3_dbg_fill_content(content, sizeof(content), page_pool_info_items,
1161850bfb91SHao Chen NULL, ARRAY_SIZE(page_pool_info_items));
1162850bfb91SHao Chen pos += scnprintf(buf + pos, len - pos, "%s", content);
1163850bfb91SHao Chen for (i = 0; i < h->kinfo.num_tqps; i++) {
1164850bfb91SHao Chen if (!test_bit(HNS3_NIC_STATE_INITED, &priv->state) ||
1165850bfb91SHao Chen test_bit(HNS3_NIC_STATE_RESETTING, &priv->state))
1166850bfb91SHao Chen return -EPERM;
1167850bfb91SHao Chen ring = &priv->ring[(u32)(i + h->kinfo.num_tqps)];
1168850bfb91SHao Chen hns3_dump_page_pool_info(ring, result, i);
1169850bfb91SHao Chen hns3_dbg_fill_content(content, sizeof(content),
1170850bfb91SHao Chen page_pool_info_items,
1171850bfb91SHao Chen (const char **)result,
1172850bfb91SHao Chen ARRAY_SIZE(page_pool_info_items));
1173850bfb91SHao Chen pos += scnprintf(buf + pos, len - pos, "%s", content);
1174850bfb91SHao Chen }
1175850bfb91SHao Chen
1176850bfb91SHao Chen return 0;
1177850bfb91SHao Chen }
1178850bfb91SHao Chen
hns3_dbg_get_cmd_index(struct hns3_dbg_data * dbg_data,u32 * index)117955649d56SYufeng Mo static int hns3_dbg_get_cmd_index(struct hns3_dbg_data *dbg_data, u32 *index)
11805e69ea7eSYufeng Mo {
11815e69ea7eSYufeng Mo u32 i;
11825e69ea7eSYufeng Mo
11835e69ea7eSYufeng Mo for (i = 0; i < ARRAY_SIZE(hns3_dbg_cmd); i++) {
118455649d56SYufeng Mo if (hns3_dbg_cmd[i].cmd == dbg_data->cmd) {
11855e69ea7eSYufeng Mo *index = i;
11865e69ea7eSYufeng Mo return 0;
11875e69ea7eSYufeng Mo }
11885e69ea7eSYufeng Mo }
11895e69ea7eSYufeng Mo
119055649d56SYufeng Mo dev_err(&dbg_data->handle->pdev->dev, "unknown command(%d)\n",
119155649d56SYufeng Mo dbg_data->cmd);
11925e69ea7eSYufeng Mo return -EINVAL;
11935e69ea7eSYufeng Mo }
11945e69ea7eSYufeng Mo
1195c929bc2aSJiaran Zhang static const struct hns3_dbg_func hns3_dbg_cmd_func[] = {
1196c929bc2aSJiaran Zhang {
1197d2f737cfSHao Chen .cmd = HNAE3_DBG_CMD_QUEUE_MAP,
1198d2f737cfSHao Chen .dbg_dump = hns3_dbg_queue_map,
1199d2f737cfSHao Chen },
1200d2f737cfSHao Chen {
1201c929bc2aSJiaran Zhang .cmd = HNAE3_DBG_CMD_DEV_INFO,
1202c929bc2aSJiaran Zhang .dbg_dump = hns3_dbg_dev_info,
1203c929bc2aSJiaran Zhang },
120477e91848SHuazhong Tan {
120577e91848SHuazhong Tan .cmd = HNAE3_DBG_CMD_TX_BD,
120677e91848SHuazhong Tan .dbg_dump_bd = hns3_dbg_tx_bd_info,
120777e91848SHuazhong Tan },
120877e91848SHuazhong Tan {
120977e91848SHuazhong Tan .cmd = HNAE3_DBG_CMD_RX_BD,
121077e91848SHuazhong Tan .dbg_dump_bd = hns3_dbg_rx_bd_info,
121177e91848SHuazhong Tan },
1212e44c495dSHao Chen {
1213e44c495dSHao Chen .cmd = HNAE3_DBG_CMD_RX_QUEUE_INFO,
1214e44c495dSHao Chen .dbg_dump = hns3_dbg_rx_queue_info,
1215e44c495dSHao Chen },
1216e44c495dSHao Chen {
1217e44c495dSHao Chen .cmd = HNAE3_DBG_CMD_TX_QUEUE_INFO,
1218e44c495dSHao Chen .dbg_dump = hns3_dbg_tx_queue_info,
1219e44c495dSHao Chen },
1220850bfb91SHao Chen {
1221850bfb91SHao Chen .cmd = HNAE3_DBG_CMD_PAGE_POOL_INFO,
1222850bfb91SHao Chen .dbg_dump = hns3_dbg_page_pool_info,
1223850bfb91SHao Chen },
1224c99fead7SHuazhong Tan {
1225c99fead7SHuazhong Tan .cmd = HNAE3_DBG_CMD_COAL_INFO,
1226c99fead7SHuazhong Tan .dbg_dump = hns3_dbg_coal_info,
1227c99fead7SHuazhong Tan },
1228c929bc2aSJiaran Zhang };
1229c929bc2aSJiaran Zhang
hns3_dbg_read_cmd(struct hns3_dbg_data * dbg_data,enum hnae3_dbg_cmd cmd,char * buf,int len)123077e91848SHuazhong Tan static int hns3_dbg_read_cmd(struct hns3_dbg_data *dbg_data,
12315e69ea7eSYufeng Mo enum hnae3_dbg_cmd cmd, char *buf, int len)
12325e69ea7eSYufeng Mo {
123377e91848SHuazhong Tan const struct hnae3_ae_ops *ops = dbg_data->handle->ae_algo->ops;
123477e91848SHuazhong Tan const struct hns3_dbg_func *cmd_func;
1235c929bc2aSJiaran Zhang u32 i;
1236c929bc2aSJiaran Zhang
1237c929bc2aSJiaran Zhang for (i = 0; i < ARRAY_SIZE(hns3_dbg_cmd_func); i++) {
123877e91848SHuazhong Tan if (cmd == hns3_dbg_cmd_func[i].cmd) {
123977e91848SHuazhong Tan cmd_func = &hns3_dbg_cmd_func[i];
124077e91848SHuazhong Tan if (cmd_func->dbg_dump)
124177e91848SHuazhong Tan return cmd_func->dbg_dump(dbg_data->handle, buf,
124277e91848SHuazhong Tan len);
124377e91848SHuazhong Tan else
124477e91848SHuazhong Tan return cmd_func->dbg_dump_bd(dbg_data, buf,
124577e91848SHuazhong Tan len);
124677e91848SHuazhong Tan }
1247c929bc2aSJiaran Zhang }
12485e69ea7eSYufeng Mo
12495e69ea7eSYufeng Mo if (!ops->dbg_read_cmd)
12505e69ea7eSYufeng Mo return -EOPNOTSUPP;
12515e69ea7eSYufeng Mo
125277e91848SHuazhong Tan return ops->dbg_read_cmd(dbg_data->handle, cmd, buf, len);
12535e69ea7eSYufeng Mo }
12545e69ea7eSYufeng Mo
hns3_dbg_read(struct file * filp,char __user * buffer,size_t count,loff_t * ppos)125504987ca1SGuangbin Huang static ssize_t hns3_dbg_read(struct file *filp, char __user *buffer,
125604987ca1SGuangbin Huang size_t count, loff_t *ppos)
125704987ca1SGuangbin Huang {
125877e91848SHuazhong Tan struct hns3_dbg_data *dbg_data = filp->private_data;
125977e91848SHuazhong Tan struct hnae3_handle *handle = dbg_data->handle;
126004987ca1SGuangbin Huang struct hns3_nic_priv *priv = handle->priv;
126104987ca1SGuangbin Huang ssize_t size = 0;
12625e69ea7eSYufeng Mo char **save_buf;
12635e69ea7eSYufeng Mo char *read_buf;
12645e69ea7eSYufeng Mo u32 index;
12655e69ea7eSYufeng Mo int ret;
126604987ca1SGuangbin Huang
126755649d56SYufeng Mo ret = hns3_dbg_get_cmd_index(dbg_data, &index);
12685e69ea7eSYufeng Mo if (ret)
12695e69ea7eSYufeng Mo return ret;
12705e69ea7eSYufeng Mo
12716dde452bSYufeng Mo mutex_lock(&handle->dbgfs_lock);
12729c9a0421SYufeng Mo save_buf = &handle->dbgfs_buf[index];
12735e69ea7eSYufeng Mo
12745e69ea7eSYufeng Mo if (!test_bit(HNS3_NIC_STATE_INITED, &priv->state) ||
12755e69ea7eSYufeng Mo test_bit(HNS3_NIC_STATE_RESETTING, &priv->state)) {
12765e69ea7eSYufeng Mo ret = -EBUSY;
12775e69ea7eSYufeng Mo goto out;
12785e69ea7eSYufeng Mo }
12795e69ea7eSYufeng Mo
12805e69ea7eSYufeng Mo if (*save_buf) {
12815e69ea7eSYufeng Mo read_buf = *save_buf;
12825e69ea7eSYufeng Mo } else {
12835e69ea7eSYufeng Mo read_buf = kvzalloc(hns3_dbg_cmd[index].buf_len, GFP_KERNEL);
12846dde452bSYufeng Mo if (!read_buf) {
12856dde452bSYufeng Mo ret = -ENOMEM;
12866dde452bSYufeng Mo goto out;
12876dde452bSYufeng Mo }
128804987ca1SGuangbin Huang
12895e69ea7eSYufeng Mo /* save the buffer addr until the last read operation */
12905e69ea7eSYufeng Mo *save_buf = read_buf;
129104987ca1SGuangbin Huang
12925e69ea7eSYufeng Mo /* get data ready for the first time to read */
129377e91848SHuazhong Tan ret = hns3_dbg_read_cmd(dbg_data, hns3_dbg_cmd[index].cmd,
12945e69ea7eSYufeng Mo read_buf, hns3_dbg_cmd[index].buf_len);
12955e69ea7eSYufeng Mo if (ret)
129604987ca1SGuangbin Huang goto out;
129704987ca1SGuangbin Huang }
129804987ca1SGuangbin Huang
129904987ca1SGuangbin Huang size = simple_read_from_buffer(buffer, count, ppos, read_buf,
130004987ca1SGuangbin Huang strlen(read_buf));
13016dde452bSYufeng Mo if (size > 0) {
13026dde452bSYufeng Mo mutex_unlock(&handle->dbgfs_lock);
13035e69ea7eSYufeng Mo return size;
13046dde452bSYufeng Mo }
130504987ca1SGuangbin Huang
130604987ca1SGuangbin Huang out:
13075e69ea7eSYufeng Mo /* free the buffer for the last read operation */
13085e69ea7eSYufeng Mo if (*save_buf) {
13095e69ea7eSYufeng Mo kvfree(*save_buf);
13105e69ea7eSYufeng Mo *save_buf = NULL;
13115e69ea7eSYufeng Mo }
13125e69ea7eSYufeng Mo
13136dde452bSYufeng Mo mutex_unlock(&handle->dbgfs_lock);
13145e69ea7eSYufeng Mo return ret;
131504987ca1SGuangbin Huang }
131604987ca1SGuangbin Huang
131704987ca1SGuangbin Huang static const struct file_operations hns3_dbg_fops = {
131804987ca1SGuangbin Huang .owner = THIS_MODULE,
131904987ca1SGuangbin Huang .open = simple_open,
132004987ca1SGuangbin Huang .read = hns3_dbg_read,
132104987ca1SGuangbin Huang };
132204987ca1SGuangbin Huang
hns3_dbg_bd_file_init(struct hnae3_handle * handle,u32 cmd)132377e91848SHuazhong Tan static int hns3_dbg_bd_file_init(struct hnae3_handle *handle, u32 cmd)
132477e91848SHuazhong Tan {
132577e91848SHuazhong Tan struct dentry *entry_dir;
132677e91848SHuazhong Tan struct hns3_dbg_data *data;
132777e91848SHuazhong Tan u16 max_queue_num;
132877e91848SHuazhong Tan unsigned int i;
132977e91848SHuazhong Tan
133077e91848SHuazhong Tan entry_dir = hns3_dbg_dentry[hns3_dbg_cmd[cmd].dentry].dentry;
133177e91848SHuazhong Tan max_queue_num = hns3_get_max_available_channels(handle);
133277e91848SHuazhong Tan data = devm_kzalloc(&handle->pdev->dev, max_queue_num * sizeof(*data),
133377e91848SHuazhong Tan GFP_KERNEL);
133477e91848SHuazhong Tan if (!data)
133577e91848SHuazhong Tan return -ENOMEM;
133677e91848SHuazhong Tan
133777e91848SHuazhong Tan for (i = 0; i < max_queue_num; i++) {
133877e91848SHuazhong Tan char name[HNS3_DBG_FILE_NAME_LEN];
133977e91848SHuazhong Tan
134077e91848SHuazhong Tan data[i].handle = handle;
134155649d56SYufeng Mo data[i].cmd = hns3_dbg_cmd[cmd].cmd;
134277e91848SHuazhong Tan data[i].qid = i;
134377e91848SHuazhong Tan sprintf(name, "%s%u", hns3_dbg_cmd[cmd].name, i);
134477e91848SHuazhong Tan debugfs_create_file(name, 0400, entry_dir, &data[i],
134577e91848SHuazhong Tan &hns3_dbg_fops);
134677e91848SHuazhong Tan }
134777e91848SHuazhong Tan
134877e91848SHuazhong Tan return 0;
134977e91848SHuazhong Tan }
135077e91848SHuazhong Tan
13515e69ea7eSYufeng Mo static int
hns3_dbg_common_file_init(struct hnae3_handle * handle,u32 cmd)13525e69ea7eSYufeng Mo hns3_dbg_common_file_init(struct hnae3_handle *handle, u32 cmd)
13535e69ea7eSYufeng Mo {
135477e91848SHuazhong Tan struct hns3_dbg_data *data;
13555e69ea7eSYufeng Mo struct dentry *entry_dir;
13565e69ea7eSYufeng Mo
135777e91848SHuazhong Tan data = devm_kzalloc(&handle->pdev->dev, sizeof(*data), GFP_KERNEL);
135877e91848SHuazhong Tan if (!data)
135977e91848SHuazhong Tan return -ENOMEM;
136077e91848SHuazhong Tan
136177e91848SHuazhong Tan data->handle = handle;
136255649d56SYufeng Mo data->cmd = hns3_dbg_cmd[cmd].cmd;
13635e69ea7eSYufeng Mo entry_dir = hns3_dbg_dentry[hns3_dbg_cmd[cmd].dentry].dentry;
13645e69ea7eSYufeng Mo debugfs_create_file(hns3_dbg_cmd[cmd].name, 0400, entry_dir,
136577e91848SHuazhong Tan data, &hns3_dbg_fops);
13665e69ea7eSYufeng Mo
13675e69ea7eSYufeng Mo return 0;
13685e69ea7eSYufeng Mo }
13695e69ea7eSYufeng Mo
hns3_dbg_init(struct hnae3_handle * handle)13705e69ea7eSYufeng Mo int hns3_dbg_init(struct hnae3_handle *handle)
1371b2292360Sliuzhongzhu {
137204987ca1SGuangbin Huang struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1373b2292360Sliuzhongzhu const char *name = pci_name(handle->pdev);
13745e69ea7eSYufeng Mo int ret;
13755e69ea7eSYufeng Mo u32 i;
1376b2292360Sliuzhongzhu
13779c9a0421SYufeng Mo handle->dbgfs_buf = devm_kcalloc(&handle->pdev->dev,
13789c9a0421SYufeng Mo ARRAY_SIZE(hns3_dbg_cmd),
13799c9a0421SYufeng Mo sizeof(*handle->dbgfs_buf),
13809c9a0421SYufeng Mo GFP_KERNEL);
13819c9a0421SYufeng Mo if (!handle->dbgfs_buf)
13829c9a0421SYufeng Mo return -ENOMEM;
13839c9a0421SYufeng Mo
13845e69ea7eSYufeng Mo hns3_dbg_dentry[HNS3_DBG_DENTRY_COMMON].dentry =
13855e69ea7eSYufeng Mo debugfs_create_dir(name, hns3_dbgfs_root);
13865e69ea7eSYufeng Mo handle->hnae3_dbgfs = hns3_dbg_dentry[HNS3_DBG_DENTRY_COMMON].dentry;
1387b2292360Sliuzhongzhu
13885e69ea7eSYufeng Mo for (i = 0; i < HNS3_DBG_DENTRY_COMMON; i++)
13895e69ea7eSYufeng Mo hns3_dbg_dentry[i].dentry =
13905e69ea7eSYufeng Mo debugfs_create_dir(hns3_dbg_dentry[i].name,
13915e69ea7eSYufeng Mo handle->hnae3_dbgfs);
13925e69ea7eSYufeng Mo
13936dde452bSYufeng Mo mutex_init(&handle->dbgfs_lock);
13946dde452bSYufeng Mo
13955e69ea7eSYufeng Mo for (i = 0; i < ARRAY_SIZE(hns3_dbg_cmd); i++) {
1396b34c157fSHuazhong Tan if ((hns3_dbg_cmd[i].cmd == HNAE3_DBG_CMD_TM_NODES &&
1397b34c157fSHuazhong Tan ae_dev->dev_version <= HNAE3_DEVICE_VERSION_V2) ||
1398b34c157fSHuazhong Tan (hns3_dbg_cmd[i].cmd == HNAE3_DBG_CMD_PTP_INFO &&
1399b34c157fSHuazhong Tan !test_bit(HNAE3_DEV_SUPPORT_PTP_B, ae_dev->caps)))
14005e69ea7eSYufeng Mo continue;
14015e69ea7eSYufeng Mo
14025e69ea7eSYufeng Mo if (!hns3_dbg_cmd[i].init) {
14035e69ea7eSYufeng Mo dev_err(&handle->pdev->dev,
14045e69ea7eSYufeng Mo "cmd %s lack of init func\n",
14055e69ea7eSYufeng Mo hns3_dbg_cmd[i].name);
14065e69ea7eSYufeng Mo ret = -EINVAL;
14075e69ea7eSYufeng Mo goto out;
14085e69ea7eSYufeng Mo }
14095e69ea7eSYufeng Mo
14105e69ea7eSYufeng Mo ret = hns3_dbg_cmd[i].init(handle, i);
14115e69ea7eSYufeng Mo if (ret) {
14125e69ea7eSYufeng Mo dev_err(&handle->pdev->dev, "failed to init cmd %s\n",
14135e69ea7eSYufeng Mo hns3_dbg_cmd[i].name);
14145e69ea7eSYufeng Mo goto out;
14155e69ea7eSYufeng Mo }
14165e69ea7eSYufeng Mo }
14175e69ea7eSYufeng Mo
14185e69ea7eSYufeng Mo return 0;
14195e69ea7eSYufeng Mo
14205e69ea7eSYufeng Mo out:
14215e69ea7eSYufeng Mo debugfs_remove_recursive(handle->hnae3_dbgfs);
14225e69ea7eSYufeng Mo handle->hnae3_dbgfs = NULL;
1423c295160bSHao Chen mutex_destroy(&handle->dbgfs_lock);
14245e69ea7eSYufeng Mo return ret;
1425b2292360Sliuzhongzhu }
1426b2292360Sliuzhongzhu
hns3_dbg_uninit(struct hnae3_handle * handle)1427b2292360Sliuzhongzhu void hns3_dbg_uninit(struct hnae3_handle *handle)
1428b2292360Sliuzhongzhu {
14295e69ea7eSYufeng Mo u32 i;
14305e69ea7eSYufeng Mo
1431c295160bSHao Chen debugfs_remove_recursive(handle->hnae3_dbgfs);
1432c295160bSHao Chen handle->hnae3_dbgfs = NULL;
1433c295160bSHao Chen
14345e69ea7eSYufeng Mo for (i = 0; i < ARRAY_SIZE(hns3_dbg_cmd); i++)
14359c9a0421SYufeng Mo if (handle->dbgfs_buf[i]) {
14369c9a0421SYufeng Mo kvfree(handle->dbgfs_buf[i]);
14379c9a0421SYufeng Mo handle->dbgfs_buf[i] = NULL;
14385e69ea7eSYufeng Mo }
14395e69ea7eSYufeng Mo
14406dde452bSYufeng Mo mutex_destroy(&handle->dbgfs_lock);
1441b2292360Sliuzhongzhu }
1442b2292360Sliuzhongzhu
hns3_dbg_register_debugfs(const char * debugfs_dir_name)1443b2292360Sliuzhongzhu void hns3_dbg_register_debugfs(const char *debugfs_dir_name)
1444b2292360Sliuzhongzhu {
1445b2292360Sliuzhongzhu hns3_dbgfs_root = debugfs_create_dir(debugfs_dir_name, NULL);
1446b2292360Sliuzhongzhu }
1447b2292360Sliuzhongzhu
hns3_dbg_unregister_debugfs(void)1448b2292360Sliuzhongzhu void hns3_dbg_unregister_debugfs(void)
1449b2292360Sliuzhongzhu {
1450b2292360Sliuzhongzhu debugfs_remove_recursive(hns3_dbgfs_root);
1451b2292360Sliuzhongzhu hns3_dbgfs_root = NULL;
1452b2292360Sliuzhongzhu }
1453