blob: c23f8684b60705e4803341efb32b98196f995c53 [file] [log] [blame]
developerfd40db22021-04-29 10:08:25 +08001/*
2 * Copyright (C) 2018 MediaTek Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * Copyright (C) 2009-2016 John Crispin <blogic@openwrt.org>
14 * Copyright (C) 2009-2016 Felix Fietkau <nbd@openwrt.org>
15 * Copyright (C) 2013-2016 Michael Lee <igvtee@gmail.com>
16 */
17
18#include <linux/trace_seq.h>
19#include <linux/seq_file.h>
20#include <linux/proc_fs.h>
21#include <linux/u64_stats_sync.h>
22#include <linux/dma-mapping.h>
23#include <linux/netdevice.h>
24#include <linux/ctype.h>
25#include <linux/debugfs.h>
26#include <linux/of_mdio.h>
developer089e8852022-09-28 14:43:46 +080027#include <linux/of_address.h>
developerfd40db22021-04-29 10:08:25 +080028
29#include "mtk_eth_soc.h"
30#include "mtk_eth_dbg.h"
developer8051e042022-04-08 13:26:36 +080031#include "mtk_eth_reset.h"
developerfd40db22021-04-29 10:08:25 +080032
developer77d03a72021-06-06 00:06:00 +080033u32 hw_lro_agg_num_cnt[MTK_HW_LRO_RING_NUM][MTK_HW_LRO_MAX_AGG_CNT + 1];
34u32 hw_lro_agg_size_cnt[MTK_HW_LRO_RING_NUM][16];
35u32 hw_lro_tot_agg_cnt[MTK_HW_LRO_RING_NUM];
36u32 hw_lro_tot_flush_cnt[MTK_HW_LRO_RING_NUM];
37u32 hw_lro_agg_flush_cnt[MTK_HW_LRO_RING_NUM];
38u32 hw_lro_age_flush_cnt[MTK_HW_LRO_RING_NUM];
39u32 hw_lro_seq_flush_cnt[MTK_HW_LRO_RING_NUM];
40u32 hw_lro_timestamp_flush_cnt[MTK_HW_LRO_RING_NUM];
41u32 hw_lro_norule_flush_cnt[MTK_HW_LRO_RING_NUM];
42u32 mtk_hwlro_stats_ebl;
43static struct proc_dir_entry *proc_hw_lro_stats, *proc_hw_lro_auto_tlb;
44typedef int (*mtk_lro_dbg_func) (int par);
45
developerfd40db22021-04-29 10:08:25 +080046struct mtk_eth_debug {
developer089e8852022-09-28 14:43:46 +080047 struct dentry *root;
48 void __iomem *base;
49 int direct_access;
developerfd40db22021-04-29 10:08:25 +080050};
51
52struct mtk_eth *g_eth;
53
54struct mtk_eth_debug eth_debug;
55
developer089e8852022-09-28 14:43:46 +080056int mt798x_iomap(void)
57{
58 struct device_node *np = NULL;
59
60 np = of_find_node_by_name(NULL, "switch0");
61 if (np) {
62 eth_debug.base = of_iomap(np, 0);
63 if (!eth_debug.base) {
64 pr_err("of_iomap failed\n");
65 of_node_put(np);
66 return -ENOMEM;
67 }
68
69 of_node_put(np);
70 eth_debug.direct_access = 1;
71 }
72
73 return 0;
74}
75
76int mt798x_iounmap(void)
77{
78 eth_debug.direct_access = 0;
79 if (eth_debug.base)
80 iounmap(eth_debug.base);
81
82 return 0;
83}
84
developer3957a912021-05-13 16:44:31 +080085void mt7530_mdio_w32(struct mtk_eth *eth, u16 reg, u32 val)
developerfd40db22021-04-29 10:08:25 +080086{
87 mutex_lock(&eth->mii_bus->mdio_lock);
88
developer089e8852022-09-28 14:43:46 +080089 if (eth_debug.direct_access)
90 __raw_writel(val, eth_debug.base + reg);
91 else {
92 _mtk_mdio_write(eth, 0x1f, 0x1f, (reg >> 6) & 0x3ff);
93 _mtk_mdio_write(eth, 0x1f, (reg >> 2) & 0xf, val & 0xffff);
94 _mtk_mdio_write(eth, 0x1f, 0x10, val >> 16);
95 }
developerfd40db22021-04-29 10:08:25 +080096
97 mutex_unlock(&eth->mii_bus->mdio_lock);
98}
99
100u32 mt7530_mdio_r32(struct mtk_eth *eth, u32 reg)
101{
102 u16 high, low;
developer089e8852022-09-28 14:43:46 +0800103 u32 ret;
developerfd40db22021-04-29 10:08:25 +0800104
105 mutex_lock(&eth->mii_bus->mdio_lock);
106
developer089e8852022-09-28 14:43:46 +0800107 if (eth_debug.direct_access) {
108 ret = __raw_readl(eth_debug.base + reg);
109 mutex_unlock(&eth->mii_bus->mdio_lock);
110 return ret;
111 }
developerfd40db22021-04-29 10:08:25 +0800112 _mtk_mdio_write(eth, 0x1f, 0x1f, (reg >> 6) & 0x3ff);
113 low = _mtk_mdio_read(eth, 0x1f, (reg >> 2) & 0xf);
114 high = _mtk_mdio_read(eth, 0x1f, 0x10);
115
116 mutex_unlock(&eth->mii_bus->mdio_lock);
117
118 return (high << 16) | (low & 0xffff);
119}
120
121void mtk_switch_w32(struct mtk_eth *eth, u32 val, unsigned reg)
122{
123 mtk_w32(eth, val, reg + 0x10000);
124}
125EXPORT_SYMBOL(mtk_switch_w32);
126
127u32 mtk_switch_r32(struct mtk_eth *eth, unsigned reg)
128{
129 return mtk_r32(eth, reg + 0x10000);
130}
131EXPORT_SYMBOL(mtk_switch_r32);
132
133static int mtketh_debug_show(struct seq_file *m, void *private)
134{
135 struct mtk_eth *eth = m->private;
136 struct mtk_mac *mac = 0;
developer77d03a72021-06-06 00:06:00 +0800137 int i = 0;
developerfd40db22021-04-29 10:08:25 +0800138
139 for (i = 0 ; i < MTK_MAX_DEVS ; i++) {
140 if (!eth->mac[i] ||
141 of_phy_is_fixed_link(eth->mac[i]->of_node))
142 continue;
143 mac = eth->mac[i];
144#if 0 //FIXME
145 while (j < 30) {
146 d = _mtk_mdio_read(eth, mac->phy_dev->addr, j);
147
148 seq_printf(m, "phy=%d, reg=0x%08x, data=0x%08x\n",
149 mac->phy_dev->addr, j, d);
150 j++;
151 }
152#endif
153 }
154 return 0;
155}
156
157static int mtketh_debug_open(struct inode *inode, struct file *file)
158{
159 return single_open(file, mtketh_debug_show, inode->i_private);
160}
161
162static const struct file_operations mtketh_debug_fops = {
developer089e8852022-09-28 14:43:46 +0800163 .owner = THIS_MODULE,
developerfd40db22021-04-29 10:08:25 +0800164 .open = mtketh_debug_open,
165 .read = seq_read,
166 .llseek = seq_lseek,
167 .release = single_release,
168};
169
170static int mtketh_mt7530sw_debug_show(struct seq_file *m, void *private)
171{
172 struct mtk_eth *eth = m->private;
173 u32 offset, data;
174 int i;
175 struct mt7530_ranges {
176 u32 start;
177 u32 end;
178 } ranges[] = {
179 {0x0, 0xac},
180 {0x1000, 0x10e0},
181 {0x1100, 0x1140},
182 {0x1200, 0x1240},
183 {0x1300, 0x1340},
184 {0x1400, 0x1440},
185 {0x1500, 0x1540},
186 {0x1600, 0x1640},
187 {0x1800, 0x1848},
188 {0x1900, 0x1948},
189 {0x1a00, 0x1a48},
190 {0x1b00, 0x1b48},
191 {0x1c00, 0x1c48},
192 {0x1d00, 0x1d48},
193 {0x1e00, 0x1e48},
194 {0x1f60, 0x1ffc},
195 {0x2000, 0x212c},
196 {0x2200, 0x222c},
197 {0x2300, 0x232c},
198 {0x2400, 0x242c},
199 {0x2500, 0x252c},
200 {0x2600, 0x262c},
201 {0x3000, 0x3014},
202 {0x30c0, 0x30f8},
203 {0x3100, 0x3114},
204 {0x3200, 0x3214},
205 {0x3300, 0x3314},
206 {0x3400, 0x3414},
207 {0x3500, 0x3514},
208 {0x3600, 0x3614},
209 {0x4000, 0x40d4},
210 {0x4100, 0x41d4},
211 {0x4200, 0x42d4},
212 {0x4300, 0x43d4},
213 {0x4400, 0x44d4},
214 {0x4500, 0x45d4},
215 {0x4600, 0x46d4},
216 {0x4f00, 0x461c},
217 {0x7000, 0x7038},
218 {0x7120, 0x7124},
219 {0x7800, 0x7804},
220 {0x7810, 0x7810},
221 {0x7830, 0x7830},
222 {0x7a00, 0x7a7c},
223 {0x7b00, 0x7b04},
224 {0x7e00, 0x7e04},
225 {0x7ffc, 0x7ffc},
226 };
227
228 if (!mt7530_exist(eth))
229 return -EOPNOTSUPP;
230
231 if ((!eth->mac[0] || !of_phy_is_fixed_link(eth->mac[0]->of_node)) &&
232 (!eth->mac[1] || !of_phy_is_fixed_link(eth->mac[1]->of_node))) {
233 seq_puts(m, "no switch found\n");
234 return 0;
235 }
236
237 for (i = 0 ; i < ARRAY_SIZE(ranges) ; i++) {
238 for (offset = ranges[i].start;
239 offset <= ranges[i].end; offset += 4) {
240 data = mt7530_mdio_r32(eth, offset);
241 seq_printf(m, "mt7530 switch reg=0x%08x, data=0x%08x\n",
242 offset, data);
243 }
244 }
245
246 return 0;
247}
248
249static int mtketh_debug_mt7530sw_open(struct inode *inode, struct file *file)
250{
251 return single_open(file, mtketh_mt7530sw_debug_show, inode->i_private);
252}
253
254static const struct file_operations mtketh_debug_mt7530sw_fops = {
developer089e8852022-09-28 14:43:46 +0800255 .owner = THIS_MODULE,
developerfd40db22021-04-29 10:08:25 +0800256 .open = mtketh_debug_mt7530sw_open,
257 .read = seq_read,
258 .llseek = seq_lseek,
259 .release = single_release,
260};
261
262static ssize_t mtketh_mt7530sw_debugfs_write(struct file *file,
263 const char __user *ptr,
264 size_t len, loff_t *off)
265{
266 struct mtk_eth *eth = file->private_data;
267 char buf[32], *token, *p = buf;
developer8b6f2402022-11-28 13:42:34 +0800268 unsigned long reg, value, phy;
developerfd40db22021-04-29 10:08:25 +0800269 int ret;
270
271 if (!mt7530_exist(eth))
272 return -EOPNOTSUPP;
273
274 if (*off != 0)
275 return 0;
276
277 if (len > sizeof(buf) - 1)
278 len = sizeof(buf) - 1;
279
280 ret = strncpy_from_user(buf, ptr, len);
281 if (ret < 0)
282 return ret;
283 buf[len] = '\0';
284
285 token = strsep(&p, " ");
286 if (!token)
287 return -EINVAL;
288 if (kstrtoul(token, 16, (unsigned long *)&phy))
289 return -EINVAL;
290
291 token = strsep(&p, " ");
292 if (!token)
293 return -EINVAL;
294 if (kstrtoul(token, 16, (unsigned long *)&reg))
295 return -EINVAL;
296
297 token = strsep(&p, " ");
298 if (!token)
299 return -EINVAL;
300 if (kstrtoul(token, 16, (unsigned long *)&value))
301 return -EINVAL;
302
303 pr_info("%s:phy=%d, reg=0x%x, val=0x%x\n", __func__,
304 0x1f, reg, value);
305 mt7530_mdio_w32(eth, reg, value);
306 pr_info("%s:phy=%d, reg=0x%x, val=0x%x confirm..\n", __func__,
307 0x1f, reg, mt7530_mdio_r32(eth, reg));
308
309 return len;
310}
311
312static ssize_t mtketh_debugfs_write(struct file *file, const char __user *ptr,
313 size_t len, loff_t *off)
314{
315 struct mtk_eth *eth = file->private_data;
316 char buf[32], *token, *p = buf;
developer8b6f2402022-11-28 13:42:34 +0800317 unsigned long reg, value, phy;
developerfd40db22021-04-29 10:08:25 +0800318 int ret;
319
320 if (*off != 0)
321 return 0;
322
323 if (len > sizeof(buf) - 1)
324 len = sizeof(buf) - 1;
325
326 ret = strncpy_from_user(buf, ptr, len);
327 if (ret < 0)
328 return ret;
329 buf[len] = '\0';
330
331 token = strsep(&p, " ");
332 if (!token)
333 return -EINVAL;
334 if (kstrtoul(token, 16, (unsigned long *)&phy))
335 return -EINVAL;
336
337 token = strsep(&p, " ");
338
339 if (!token)
340 return -EINVAL;
341 if (kstrtoul(token, 16, (unsigned long *)&reg))
342 return -EINVAL;
343
344 token = strsep(&p, " ");
345
346 if (!token)
347 return -EINVAL;
348 if (kstrtoul(token, 16, (unsigned long *)&value))
349 return -EINVAL;
350
351 pr_info("%s:phy=%d, reg=0x%x, val=0x%x\n", __func__,
352 phy, reg, value);
353
354 _mtk_mdio_write(eth, phy, reg, value);
355
356 pr_info("%s:phy=%d, reg=0x%x, val=0x%x confirm..\n", __func__,
357 phy, reg, _mtk_mdio_read(eth, phy, reg));
358
359 return len;
360}
361
362static ssize_t mtketh_debugfs_reset(struct file *file, const char __user *ptr,
363 size_t len, loff_t *off)
364{
365 struct mtk_eth *eth = file->private_data;
developerbd42c172022-07-18 17:51:30 +0800366 char buf[8] = "";
367 int count = len;
368 unsigned long dbg_level = 0;
369
370 len = min(count, sizeof(buf) - 1);
371 if (copy_from_user(buf, ptr, len))
372 return -EFAULT;
373
374 buf[len] = '\0';
375 if (kstrtoul(buf, 0, &dbg_level))
376 return -EINVAL;
developerfd40db22021-04-29 10:08:25 +0800377
developerbd42c172022-07-18 17:51:30 +0800378 switch(dbg_level)
379 {
380 case 0:
developer0baa6962023-01-31 14:25:23 +0800381 atomic_set(&force, 0);
developerbd42c172022-07-18 17:51:30 +0800382 break;
383 case 1:
developer0baa6962023-01-31 14:25:23 +0800384 if (atomic_read(&force) == 1)
developer37482a42022-12-26 13:31:13 +0800385 schedule_work(&eth->pending_work);
developer0baa6962023-01-31 14:25:23 +0800386 else
387 pr_info(" stat:disable\n");
developerbd42c172022-07-18 17:51:30 +0800388 break;
389 case 2:
developer0baa6962023-01-31 14:25:23 +0800390 atomic_set(&force, 1);
developerbd42c172022-07-18 17:51:30 +0800391 break;
developer37482a42022-12-26 13:31:13 +0800392 case 3:
developer0baa6962023-01-31 14:25:23 +0800393 if (atomic_read(&force) == 1) {
developer37482a42022-12-26 13:31:13 +0800394 mtk_reset_flag = MTK_FE_STOP_TRAFFIC;
395 schedule_work(&eth->pending_work);
396 } else
397 pr_info(" device resetting !!!\n");
398 break;
developerbd42c172022-07-18 17:51:30 +0800399 default:
400 pr_info("Usage: echo [level] > /sys/kernel/debug/mtketh/reset\n");
developer37482a42022-12-26 13:31:13 +0800401 pr_info("Commands: [level]\n");
402 pr_info(" 0 disable reset\n");
403 pr_info(" 1 FE and WDMA reset\n");
developerbd42c172022-07-18 17:51:30 +0800404 pr_info(" 2 enable reset\n");
developer37482a42022-12-26 13:31:13 +0800405 pr_info(" 3 FE reset\n");
developerbd42c172022-07-18 17:51:30 +0800406 break;
407 }
408 return count;
developerfd40db22021-04-29 10:08:25 +0800409}
410
411static const struct file_operations fops_reg_w = {
412 .owner = THIS_MODULE,
413 .open = simple_open,
414 .write = mtketh_debugfs_write,
415 .llseek = noop_llseek,
416};
417
418static const struct file_operations fops_eth_reset = {
419 .owner = THIS_MODULE,
420 .open = simple_open,
421 .write = mtketh_debugfs_reset,
422 .llseek = noop_llseek,
423};
424
425static const struct file_operations fops_mt7530sw_reg_w = {
426 .owner = THIS_MODULE,
427 .open = simple_open,
428 .write = mtketh_mt7530sw_debugfs_write,
429 .llseek = noop_llseek,
430};
431
432void mtketh_debugfs_exit(struct mtk_eth *eth)
433{
434 debugfs_remove_recursive(eth_debug.root);
435}
436
437int mtketh_debugfs_init(struct mtk_eth *eth)
438{
439 int ret = 0;
440
441 eth_debug.root = debugfs_create_dir("mtketh", NULL);
442 if (!eth_debug.root) {
443 dev_notice(eth->dev, "%s:err at %d\n", __func__, __LINE__);
444 ret = -ENOMEM;
445 }
446
447 debugfs_create_file("phy_regs", S_IRUGO,
448 eth_debug.root, eth, &mtketh_debug_fops);
449 debugfs_create_file("phy_reg_w", S_IFREG | S_IWUSR,
450 eth_debug.root, eth, &fops_reg_w);
451 debugfs_create_file("reset", S_IFREG | S_IWUSR,
452 eth_debug.root, eth, &fops_eth_reset);
453 if (mt7530_exist(eth)) {
454 debugfs_create_file("mt7530sw_regs", S_IRUGO,
455 eth_debug.root, eth,
456 &mtketh_debug_mt7530sw_fops);
457 debugfs_create_file("mt7530sw_reg_w", S_IFREG | S_IWUSR,
458 eth_debug.root, eth,
459 &fops_mt7530sw_reg_w);
460 }
461 return ret;
462}
463
464void mii_mgr_read_combine(struct mtk_eth *eth, u32 phy_addr, u32 phy_register,
465 u32 *read_data)
466{
467 if (mt7530_exist(eth) && phy_addr == 31)
468 *read_data = mt7530_mdio_r32(eth, phy_register);
469
470 else
developer089e8852022-09-28 14:43:46 +0800471 *read_data = mdiobus_read(eth->mii_bus, phy_addr, phy_register);
developerfd40db22021-04-29 10:08:25 +0800472}
473
developer3957a912021-05-13 16:44:31 +0800474void mii_mgr_write_combine(struct mtk_eth *eth, u16 phy_addr, u16 phy_register,
developerfd40db22021-04-29 10:08:25 +0800475 u32 write_data)
476{
477 if (mt7530_exist(eth) && phy_addr == 31)
478 mt7530_mdio_w32(eth, phy_register, write_data);
479
480 else
developer089e8852022-09-28 14:43:46 +0800481 mdiobus_write(eth->mii_bus, phy_addr, phy_register, write_data);
developerfd40db22021-04-29 10:08:25 +0800482}
483
developer3957a912021-05-13 16:44:31 +0800484static void mii_mgr_read_cl45(struct mtk_eth *eth, u16 port, u16 devad, u16 reg, u16 *data)
developerfd40db22021-04-29 10:08:25 +0800485{
developer089e8852022-09-28 14:43:46 +0800486 *data = mdiobus_read(eth->mii_bus, port, mdiobus_c45_addr(devad, reg));
developerfd40db22021-04-29 10:08:25 +0800487}
488
developer3957a912021-05-13 16:44:31 +0800489static void mii_mgr_write_cl45(struct mtk_eth *eth, u16 port, u16 devad, u16 reg, u16 data)
developerfd40db22021-04-29 10:08:25 +0800490{
developer089e8852022-09-28 14:43:46 +0800491 mdiobus_write(eth->mii_bus, port, mdiobus_c45_addr(devad, reg), data);
developerfd40db22021-04-29 10:08:25 +0800492}
493
494int mtk_do_priv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
495{
496 struct mtk_mac *mac = netdev_priv(dev);
497 struct mtk_eth *eth = mac->hw;
498 struct mtk_mii_ioctl_data mii;
499 struct mtk_esw_reg reg;
developerba2d1eb2021-05-25 19:26:45 +0800500 u16 val;
developerfd40db22021-04-29 10:08:25 +0800501
502 switch (cmd) {
503 case MTKETH_MII_READ:
504 if (copy_from_user(&mii, ifr->ifr_data, sizeof(mii)))
505 goto err_copy;
506 mii_mgr_read_combine(eth, mii.phy_id, mii.reg_num,
507 &mii.val_out);
508 if (copy_to_user(ifr->ifr_data, &mii, sizeof(mii)))
509 goto err_copy;
510
511 return 0;
512 case MTKETH_MII_WRITE:
513 if (copy_from_user(&mii, ifr->ifr_data, sizeof(mii)))
514 goto err_copy;
515 mii_mgr_write_combine(eth, mii.phy_id, mii.reg_num,
516 mii.val_in);
developerfd40db22021-04-29 10:08:25 +0800517 return 0;
518 case MTKETH_MII_READ_CL45:
519 if (copy_from_user(&mii, ifr->ifr_data, sizeof(mii)))
520 goto err_copy;
developer3957a912021-05-13 16:44:31 +0800521 mii_mgr_read_cl45(eth,
522 mdio_phy_id_prtad(mii.phy_id),
523 mdio_phy_id_devad(mii.phy_id),
524 mii.reg_num,
developerba2d1eb2021-05-25 19:26:45 +0800525 &val);
526 mii.val_out = val;
developerfd40db22021-04-29 10:08:25 +0800527 if (copy_to_user(ifr->ifr_data, &mii, sizeof(mii)))
528 goto err_copy;
529
530 return 0;
531 case MTKETH_MII_WRITE_CL45:
532 if (copy_from_user(&mii, ifr->ifr_data, sizeof(mii)))
533 goto err_copy;
developerba2d1eb2021-05-25 19:26:45 +0800534 val = mii.val_in;
developer3957a912021-05-13 16:44:31 +0800535 mii_mgr_write_cl45(eth,
536 mdio_phy_id_prtad(mii.phy_id),
537 mdio_phy_id_devad(mii.phy_id),
538 mii.reg_num,
developerba2d1eb2021-05-25 19:26:45 +0800539 val);
developerfd40db22021-04-29 10:08:25 +0800540 return 0;
541 case MTKETH_ESW_REG_READ:
542 if (!mt7530_exist(eth))
543 return -EOPNOTSUPP;
544 if (copy_from_user(&reg, ifr->ifr_data, sizeof(reg)))
545 goto err_copy;
546 if (reg.off > REG_ESW_MAX)
547 return -EINVAL;
548 reg.val = mtk_switch_r32(eth, reg.off);
549
550 if (copy_to_user(ifr->ifr_data, &reg, sizeof(reg)))
551 goto err_copy;
552
553 return 0;
554 case MTKETH_ESW_REG_WRITE:
555 if (!mt7530_exist(eth))
556 return -EOPNOTSUPP;
557 if (copy_from_user(&reg, ifr->ifr_data, sizeof(reg)))
558 goto err_copy;
559 if (reg.off > REG_ESW_MAX)
560 return -EINVAL;
561 mtk_switch_w32(eth, reg.val, reg.off);
562
563 return 0;
564 default:
565 break;
566 }
567
568 return -EOPNOTSUPP;
569err_copy:
570 return -EFAULT;
571}
572
developer089e8852022-09-28 14:43:46 +0800573static void gdm_reg_dump_v3(struct mtk_eth *eth, u32 gdm_id, u32 mib_base)
574{
575 pr_info("| GDMA%d_RX_GBCNT : %010u (Rx Good Bytes) |\n",
576 gdm_id, mtk_r32(eth, mib_base));
577 pr_info("| GDMA%d_RX_GPCNT : %010u (Rx Good Pkts) |\n",
578 gdm_id, mtk_r32(eth, mib_base + 0x08));
579 pr_info("| GDMA%d_RX_OERCNT : %010u (overflow error) |\n",
580 gdm_id, mtk_r32(eth, mib_base + 0x10));
581 pr_info("| GDMA%d_RX_FERCNT : %010u (FCS error) |\n",
582 gdm_id, mtk_r32(eth, mib_base + 0x14));
583 pr_info("| GDMA%d_RX_SERCNT : %010u (too short) |\n",
584 gdm_id, mtk_r32(eth, mib_base + 0x18));
585 pr_info("| GDMA%d_RX_LERCNT : %010u (too long) |\n",
586 gdm_id, mtk_r32(eth, mib_base + 0x1C));
587 pr_info("| GDMA%d_RX_CERCNT : %010u (checksum error) |\n",
588 gdm_id, mtk_r32(eth, mib_base + 0x20));
589 pr_info("| GDMA%d_RX_FCCNT : %010u (flow control) |\n",
590 gdm_id, mtk_r32(eth, mib_base + 0x24));
591 pr_info("| GDMA%d_RX_VDPCNT : %010u (VID drop) |\n",
592 gdm_id, mtk_r32(eth, mib_base + 0x28));
593 pr_info("| GDMA%d_RX_PFCCNT : %010u (priority flow control)\n",
594 gdm_id, mtk_r32(eth, mib_base + 0x2C));
595 pr_info("| GDMA%d_TX_GBCNT : %010u (Tx Good Bytes) |\n",
596 gdm_id, mtk_r32(eth, mib_base + 0x40));
597 pr_info("| GDMA%d_TX_GPCNT : %010u (Tx Good Pkts) |\n",
598 gdm_id, mtk_r32(eth, mib_base + 0x48));
599 pr_info("| GDMA%d_TX_SKIPCNT: %010u (abort count) |\n",
600 gdm_id, mtk_r32(eth, mib_base + 0x50));
601 pr_info("| GDMA%d_TX_COLCNT : %010u (collision count)|\n",
602 gdm_id, mtk_r32(eth, mib_base + 0x54));
603 pr_info("| GDMA%d_TX_OERCNT : %010u (overflow error) |\n",
604 gdm_id, mtk_r32(eth, mib_base + 0x58));
605 pr_info("| GDMA%d_TX_FCCNT : %010u (flow control) |\n",
606 gdm_id, mtk_r32(eth, mib_base + 0x60));
607 pr_info("| GDMA%d_TX_PFCCNT : %010u (priority flow control)\n",
608 gdm_id, mtk_r32(eth, mib_base + 0x64));
609 pr_info("| |\n");
610}
611
612static void gdm_reg_dump_v2(struct mtk_eth *eth, u32 gdm_id, u32 mib_base)
613{
614 pr_info("| GDMA%d_RX_GBCNT : %010u (Rx Good Bytes) |\n",
615 gdm_id, mtk_r32(eth, mib_base));
616 pr_info("| GDMA%d_RX_GPCNT : %010u (Rx Good Pkts) |\n",
617 gdm_id, mtk_r32(eth, mib_base + 0x08));
618 pr_info("| GDMA%d_RX_OERCNT : %010u (overflow error) |\n",
619 gdm_id, mtk_r32(eth, mib_base + 0x10));
620 pr_info("| GDMA%d_RX_FERCNT : %010u (FCS error) |\n",
621 gdm_id, mtk_r32(eth, mib_base + 0x14));
622 pr_info("| GDMA%d_RX_SERCNT : %010u (too short) |\n",
623 gdm_id, mtk_r32(eth, mib_base + 0x18));
624 pr_info("| GDMA%d_RX_LERCNT : %010u (too long) |\n",
625 gdm_id, mtk_r32(eth, mib_base + 0x1C));
626 pr_info("| GDMA%d_RX_CERCNT : %010u (checksum error) |\n",
627 gdm_id, mtk_r32(eth, mib_base + 0x20));
628 pr_info("| GDMA%d_RX_FCCNT : %010u (flow control) |\n",
629 gdm_id, mtk_r32(eth, mib_base + 0x24));
630 pr_info("| GDMA%d_TX_SKIPCNT: %010u (abort count) |\n",
631 gdm_id, mtk_r32(eth, mib_base + 0x28));
632 pr_info("| GDMA%d_TX_COLCNT : %010u (collision count) |\n",
633 gdm_id, mtk_r32(eth, mib_base + 0x2C));
634 pr_info("| GDMA%d_TX_GBCNT : %010u (Tx Good Bytes) |\n",
635 gdm_id, mtk_r32(eth, mib_base + 0x30));
636 pr_info("| GDMA%d_TX_GPCNT : %010u (Tx Good Pkts) |\n",
637 gdm_id, mtk_r32(eth, mib_base + 0x38));
638 pr_info("| |\n");
639}
640
641static void gdm_cnt_read(struct mtk_eth *eth)
642{
643 u32 i, mib_base;
644
645 pr_info("\n <<CPU>>\n");
646 pr_info(" |\n");
647 pr_info("+-----------------------------------------------+\n");
648 pr_info("| <<PSE>> |\n");
649 pr_info("+-----------------------------------------------+\n");
650 pr_info(" |\n");
651 pr_info("+-----------------------------------------------+\n");
652 pr_info("| <<GDMA>> |\n");
653
654 for (i = 0; i < MTK_MAC_COUNT; i++) {
655 mib_base = MTK_GDM1_TX_GBCNT + MTK_STAT_OFFSET * i;
656
657 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
658 gdm_reg_dump_v3(eth, i + 1, mib_base);
659 else
660 gdm_reg_dump_v2(eth, i + 1, mib_base);
661 }
662
663 pr_info("+-----------------------------------------------+\n");
664}
665
developer9ccff342022-10-13 18:28:54 +0800666void dump_each_port(struct seq_file *seq, struct mtk_eth *eth, u32 base)
667{
668 u32 pkt_cnt = 0;
669 int i = 0;
670
671 for (i = 0; i < 7; i++) {
672 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
673 if ((base == 0x402C) && (i == 6))
674 base = 0x408C;
675 else if ((base == 0x408C) && (i == 6))
676 base = 0x402C;
677 else
678 ;
679 }
680 pkt_cnt = mt7530_mdio_r32(eth, (base) + (i * 0x100));
681 seq_printf(seq, "%8u ", pkt_cnt);
682 }
683 seq_puts(seq, "\n");
684}
685
developerfd40db22021-04-29 10:08:25 +0800686int esw_cnt_read(struct seq_file *seq, void *v)
687{
688 unsigned int pkt_cnt = 0;
689 int i = 0;
690 struct mtk_eth *eth = g_eth;
developerfd40db22021-04-29 10:08:25 +0800691
developer089e8852022-09-28 14:43:46 +0800692 gdm_cnt_read(eth);
developerfd40db22021-04-29 10:08:25 +0800693
694 if (!mt7530_exist(eth))
695 return 0;
696
developer089e8852022-09-28 14:43:46 +0800697 mt798x_iomap();
698
developerfd40db22021-04-29 10:08:25 +0800699 seq_printf(seq, "===================== %8s %8s %8s %8s %8s %8s %8s\n",
700 "Port0", "Port1", "Port2", "Port3", "Port4", "Port5",
701 "Port6");
702 seq_puts(seq, "Tx Drop Packet :");
developer9ccff342022-10-13 18:28:54 +0800703 dump_each_port(seq, eth, 0x4000);
developerfd40db22021-04-29 10:08:25 +0800704 seq_puts(seq, "Tx CRC Error :");
developer9ccff342022-10-13 18:28:54 +0800705 dump_each_port(seq, eth, 0x4004);
developerfd40db22021-04-29 10:08:25 +0800706 seq_puts(seq, "Tx Unicast Packet :");
developer9ccff342022-10-13 18:28:54 +0800707 dump_each_port(seq, eth, 0x4008);
developerfd40db22021-04-29 10:08:25 +0800708 seq_puts(seq, "Tx Multicast Packet :");
developer9ccff342022-10-13 18:28:54 +0800709 dump_each_port(seq, eth, 0x400C);
developerfd40db22021-04-29 10:08:25 +0800710 seq_puts(seq, "Tx Broadcast Packet :");
developer9ccff342022-10-13 18:28:54 +0800711 dump_each_port(seq, eth, 0x4010);
developerfd40db22021-04-29 10:08:25 +0800712 seq_puts(seq, "Tx Collision Event :");
developer9ccff342022-10-13 18:28:54 +0800713 dump_each_port(seq, eth, 0x4014);
developerfd40db22021-04-29 10:08:25 +0800714 seq_puts(seq, "Tx Pause Packet :");
developer9ccff342022-10-13 18:28:54 +0800715 dump_each_port(seq, eth, 0x402C);
developerfd40db22021-04-29 10:08:25 +0800716 seq_puts(seq, "Rx Drop Packet :");
developer9ccff342022-10-13 18:28:54 +0800717 dump_each_port(seq, eth, 0x4060);
developerfd40db22021-04-29 10:08:25 +0800718 seq_puts(seq, "Rx Filtering Packet :");
developer9ccff342022-10-13 18:28:54 +0800719 dump_each_port(seq, eth, 0x4064);
developerfd40db22021-04-29 10:08:25 +0800720 seq_puts(seq, "Rx Unicast Packet :");
developer9ccff342022-10-13 18:28:54 +0800721 dump_each_port(seq, eth, 0x4068);
developerfd40db22021-04-29 10:08:25 +0800722 seq_puts(seq, "Rx Multicast Packet :");
developer9ccff342022-10-13 18:28:54 +0800723 dump_each_port(seq, eth, 0x406C);
developerfd40db22021-04-29 10:08:25 +0800724 seq_puts(seq, "Rx Broadcast Packet :");
developer9ccff342022-10-13 18:28:54 +0800725 dump_each_port(seq, eth, 0x4070);
developerfd40db22021-04-29 10:08:25 +0800726 seq_puts(seq, "Rx Alignment Error :");
developer9ccff342022-10-13 18:28:54 +0800727 dump_each_port(seq, eth, 0x4074);
developerfd40db22021-04-29 10:08:25 +0800728 seq_puts(seq, "Rx CRC Error :");
developer9ccff342022-10-13 18:28:54 +0800729 dump_each_port(seq, eth, 0x4078);
developerfd40db22021-04-29 10:08:25 +0800730 seq_puts(seq, "Rx Undersize Error :");
developer9ccff342022-10-13 18:28:54 +0800731 dump_each_port(seq, eth, 0x407C);
developerfd40db22021-04-29 10:08:25 +0800732 seq_puts(seq, "Rx Fragment Error :");
developer9ccff342022-10-13 18:28:54 +0800733 dump_each_port(seq, eth, 0x4080);
developerfd40db22021-04-29 10:08:25 +0800734 seq_puts(seq, "Rx Oversize Error :");
developer9ccff342022-10-13 18:28:54 +0800735 dump_each_port(seq, eth, 0x4084);
developerfd40db22021-04-29 10:08:25 +0800736 seq_puts(seq, "Rx Jabber Error :");
developer9ccff342022-10-13 18:28:54 +0800737 dump_each_port(seq, eth, 0x4088);
developerfd40db22021-04-29 10:08:25 +0800738 seq_puts(seq, "Rx Pause Packet :");
developer9ccff342022-10-13 18:28:54 +0800739 dump_each_port(seq, eth, 0x408C);
developerfd40db22021-04-29 10:08:25 +0800740 mt7530_mdio_w32(eth, 0x4fe0, 0xf0);
741 mt7530_mdio_w32(eth, 0x4fe0, 0x800000f0);
742
743 seq_puts(seq, "\n");
744
developer089e8852022-09-28 14:43:46 +0800745 mt798x_iounmap();
746
developerfd40db22021-04-29 10:08:25 +0800747 return 0;
748}
749
750static int switch_count_open(struct inode *inode, struct file *file)
751{
752 return single_open(file, esw_cnt_read, 0);
753}
754
755static const struct file_operations switch_count_fops = {
756 .owner = THIS_MODULE,
757 .open = switch_count_open,
758 .read = seq_read,
759 .llseek = seq_lseek,
760 .release = single_release
761};
762
developer621ca6b2023-01-11 11:08:46 +0800763void xfi_mib_dump(struct seq_file *seq, u32 gdm_id)
764{
765 struct mtk_eth *eth = g_eth;
766
767 PRINT_FORMATTED_XFI_MIB(seq, TX_PKT_CNT, GENMASK(31, 0));
768 PRINT_FORMATTED_XFI_MIB(seq, TX_ETH_CNT, GENMASK(31, 0));
769 PRINT_FORMATTED_XFI_MIB(seq, TX_PAUSE_CNT, GENMASK(15, 0));
770 PRINT_FORMATTED_XFI_MIB(seq, TX_BYTE_CNT, GENMASK(31, 0));
771 PRINT_FORMATTED_XFI_MIB64(seq, TX_UC_PKT_CNT);
772 PRINT_FORMATTED_XFI_MIB64(seq, TX_MC_PKT_CNT);
773 PRINT_FORMATTED_XFI_MIB64(seq, TX_BC_PKT_CNT);
774
775 PRINT_FORMATTED_XFI_MIB(seq, RX_PKT_CNT, GENMASK(31, 0));
776 PRINT_FORMATTED_XFI_MIB(seq, RX_ETH_CNT, GENMASK(31, 0));
777 PRINT_FORMATTED_XFI_MIB(seq, RX_PAUSE_CNT, GENMASK(15, 0));
778 PRINT_FORMATTED_XFI_MIB(seq, RX_LEN_ERR_CNT, GENMASK(15, 0));
779 PRINT_FORMATTED_XFI_MIB(seq, RX_CRC_ERR_CNT, GENMASK(15, 0));
780 PRINT_FORMATTED_XFI_MIB64(seq, RX_UC_PKT_CNT);
781 PRINT_FORMATTED_XFI_MIB64(seq, RX_MC_PKT_CNT);
782 PRINT_FORMATTED_XFI_MIB64(seq, RX_BC_PKT_CNT);
783 PRINT_FORMATTED_XFI_MIB(seq, RX_UC_DROP_CNT, GENMASK(31, 0));
784 PRINT_FORMATTED_XFI_MIB(seq, RX_BC_DROP_CNT, GENMASK(31, 0));
785 PRINT_FORMATTED_XFI_MIB(seq, RX_MC_DROP_CNT, GENMASK(31, 0));
786 PRINT_FORMATTED_XFI_MIB(seq, RX_ALL_DROP_CNT, GENMASK(31, 0));
787}
788
789int xfi_cnt_read(struct seq_file *seq, void *v)
790{
791 struct mtk_eth *eth = g_eth;
792 int i;
793
794 seq_puts(seq, "+------------------------------------+\n");
795 seq_puts(seq, "| <<XFI MAC>> |\n");
796
797 for (i = MTK_GMAC2_ID; i < MTK_GMAC_ID_MAX; i++) {
798 xfi_mib_dump(seq, i);
799 mtk_m32(eth, 0x1, 0x1, MTK_XFI_MIB_BASE(i) + MTK_XFI_CNT_CTRL);
800 seq_puts(seq, "| |\n");
801 }
802
803 seq_puts(seq, "+------------------------------------+\n");
804
805 return 0;
806}
807
808static int xfi_count_open(struct inode *inode, struct file *file)
809{
810 return single_open(file, xfi_cnt_read, 0);
811}
812
813static const struct file_operations xfi_count_fops = {
814 .owner = THIS_MODULE,
815 .open = xfi_count_open,
816 .read = seq_read,
817 .llseek = seq_lseek,
818 .release = single_release
819};
820
developer8051e042022-04-08 13:26:36 +0800821static struct proc_dir_entry *proc_tx_ring, *proc_hwtx_ring, *proc_rx_ring;
developerfd40db22021-04-29 10:08:25 +0800822
823int tx_ring_read(struct seq_file *seq, void *v)
824{
developere9356982022-07-04 09:03:20 +0800825 struct mtk_eth *eth = g_eth;
developerfd40db22021-04-29 10:08:25 +0800826 struct mtk_tx_ring *ring = &g_eth->tx_ring;
developere9356982022-07-04 09:03:20 +0800827 struct mtk_tx_dma_v2 *tx_ring;
developerfd40db22021-04-29 10:08:25 +0800828 int i = 0;
829
developerfd40db22021-04-29 10:08:25 +0800830 seq_printf(seq, "free count = %d\n", (int)atomic_read(&ring->free_count));
831 seq_printf(seq, "cpu next free: %d\n", (int)(ring->next_free - ring->dma));
832 seq_printf(seq, "cpu last free: %d\n", (int)(ring->last_free - ring->dma));
833 for (i = 0; i < MTK_DMA_SIZE; i++) {
developer8b6f2402022-11-28 13:42:34 +0800834 dma_addr_t tmp = ring->phys +
835 i * (dma_addr_t)eth->soc->txrx.txd_size;
developere9356982022-07-04 09:03:20 +0800836
837 tx_ring = ring->dma + i * eth->soc->txrx.txd_size;
developerfd40db22021-04-29 10:08:25 +0800838
839 seq_printf(seq, "%d (%pad): %08x %08x %08x %08x", i, &tmp,
developere9356982022-07-04 09:03:20 +0800840 tx_ring->txd1, tx_ring->txd2,
841 tx_ring->txd3, tx_ring->txd4);
842
developer089e8852022-09-28 14:43:46 +0800843 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
844 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developere9356982022-07-04 09:03:20 +0800845 seq_printf(seq, " %08x %08x %08x %08x",
846 tx_ring->txd5, tx_ring->txd6,
847 tx_ring->txd7, tx_ring->txd8);
848 }
849
developerfd40db22021-04-29 10:08:25 +0800850 seq_printf(seq, "\n");
851 }
852
developerfd40db22021-04-29 10:08:25 +0800853 return 0;
854}
855
856static int tx_ring_open(struct inode *inode, struct file *file)
857{
858 return single_open(file, tx_ring_read, NULL);
859}
860
861static const struct file_operations tx_ring_fops = {
862 .owner = THIS_MODULE,
863 .open = tx_ring_open,
864 .read = seq_read,
865 .llseek = seq_lseek,
866 .release = single_release
867};
868
developer8051e042022-04-08 13:26:36 +0800869int hwtx_ring_read(struct seq_file *seq, void *v)
870{
871 struct mtk_eth *eth = g_eth;
developere9356982022-07-04 09:03:20 +0800872 struct mtk_tx_dma_v2 *hwtx_ring;
developer8051e042022-04-08 13:26:36 +0800873 int i = 0;
874
developer8051e042022-04-08 13:26:36 +0800875 for (i = 0; i < MTK_DMA_SIZE; i++) {
developer8b6f2402022-11-28 13:42:34 +0800876 dma_addr_t addr = eth->phy_scratch_ring +
877 i * (dma_addr_t)eth->soc->txrx.txd_size;
developere9356982022-07-04 09:03:20 +0800878
879 hwtx_ring = eth->scratch_ring + i * eth->soc->txrx.txd_size;
developer8051e042022-04-08 13:26:36 +0800880
881 seq_printf(seq, "%d (%pad): %08x %08x %08x %08x", i, &addr,
developere9356982022-07-04 09:03:20 +0800882 hwtx_ring->txd1, hwtx_ring->txd2,
883 hwtx_ring->txd3, hwtx_ring->txd4);
884
developer089e8852022-09-28 14:43:46 +0800885 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
886 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developere9356982022-07-04 09:03:20 +0800887 seq_printf(seq, " %08x %08x %08x %08x",
888 hwtx_ring->txd5, hwtx_ring->txd6,
889 hwtx_ring->txd7, hwtx_ring->txd8);
890 }
891
developer8051e042022-04-08 13:26:36 +0800892 seq_printf(seq, "\n");
893 }
894
developer8051e042022-04-08 13:26:36 +0800895 return 0;
896}
897
898static int hwtx_ring_open(struct inode *inode, struct file *file)
899{
900 return single_open(file, hwtx_ring_read, NULL);
901}
902
903static const struct file_operations hwtx_ring_fops = {
904 .owner = THIS_MODULE,
905 .open = hwtx_ring_open,
906 .read = seq_read,
907 .llseek = seq_lseek,
908 .release = single_release
909};
910
developerfd40db22021-04-29 10:08:25 +0800911int rx_ring_read(struct seq_file *seq, void *v)
912{
developere9356982022-07-04 09:03:20 +0800913 struct mtk_eth *eth = g_eth;
developerfd40db22021-04-29 10:08:25 +0800914 struct mtk_rx_ring *ring = &g_eth->rx_ring[0];
developere9356982022-07-04 09:03:20 +0800915 struct mtk_rx_dma_v2 *rx_ring;
developerfd40db22021-04-29 10:08:25 +0800916 int i = 0;
917
developerfd40db22021-04-29 10:08:25 +0800918 seq_printf(seq, "next to read: %d\n",
919 NEXT_DESP_IDX(ring->calc_idx, MTK_DMA_SIZE));
920 for (i = 0; i < MTK_DMA_SIZE; i++) {
developere9356982022-07-04 09:03:20 +0800921 rx_ring = ring->dma + i * eth->soc->txrx.rxd_size;
922
developerfd40db22021-04-29 10:08:25 +0800923 seq_printf(seq, "%d: %08x %08x %08x %08x", i,
developere9356982022-07-04 09:03:20 +0800924 rx_ring->rxd1, rx_ring->rxd2,
925 rx_ring->rxd3, rx_ring->rxd4);
926
developer8ecd51b2023-03-13 11:28:28 +0800927 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_V2)) {
developere9356982022-07-04 09:03:20 +0800928 seq_printf(seq, " %08x %08x %08x %08x",
929 rx_ring->rxd5, rx_ring->rxd6,
930 rx_ring->rxd7, rx_ring->rxd8);
931 }
932
developerfd40db22021-04-29 10:08:25 +0800933 seq_printf(seq, "\n");
934 }
935
developerfd40db22021-04-29 10:08:25 +0800936 return 0;
937}
938
939static int rx_ring_open(struct inode *inode, struct file *file)
940{
941 return single_open(file, rx_ring_read, NULL);
942}
943
944static const struct file_operations rx_ring_fops = {
945 .owner = THIS_MODULE,
946 .open = rx_ring_open,
947 .read = seq_read,
948 .llseek = seq_lseek,
949 .release = single_release
950};
951
developer77f3fd42021-10-05 15:16:05 +0800952static inline u32 mtk_dbg_r32(u32 reg)
953{
954 void __iomem *virt_reg;
955 u32 val;
956
957 virt_reg = ioremap(reg, 32);
958 val = __raw_readl(virt_reg);
959 iounmap(virt_reg);
960
961 return val;
962}
963
developerfd40db22021-04-29 10:08:25 +0800964int dbg_regs_read(struct seq_file *seq, void *v)
965{
966 struct mtk_eth *eth = g_eth;
967
developer77f3fd42021-10-05 15:16:05 +0800968 seq_puts(seq, " <<DEBUG REG DUMP>>\n");
969
970 seq_printf(seq, "| FE_INT_STA : %08x |\n",
developer8051e042022-04-08 13:26:36 +0800971 mtk_r32(eth, MTK_FE_INT_STATUS));
developer089e8852022-09-28 14:43:46 +0800972 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
973 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
developer77f3fd42021-10-05 15:16:05 +0800974 seq_printf(seq, "| FE_INT_STA2 : %08x |\n",
developer8051e042022-04-08 13:26:36 +0800975 mtk_r32(eth, MTK_FE_INT_STATUS2));
developer77f3fd42021-10-05 15:16:05 +0800976
developerfd40db22021-04-29 10:08:25 +0800977 seq_printf(seq, "| PSE_FQFC_CFG : %08x |\n",
978 mtk_r32(eth, MTK_PSE_FQFC_CFG));
979 seq_printf(seq, "| PSE_IQ_STA1 : %08x |\n",
980 mtk_r32(eth, MTK_PSE_IQ_STA(0)));
981 seq_printf(seq, "| PSE_IQ_STA2 : %08x |\n",
982 mtk_r32(eth, MTK_PSE_IQ_STA(1)));
983
developer089e8852022-09-28 14:43:46 +0800984 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
985 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developerfd40db22021-04-29 10:08:25 +0800986 seq_printf(seq, "| PSE_IQ_STA3 : %08x |\n",
987 mtk_r32(eth, MTK_PSE_IQ_STA(2)));
988 seq_printf(seq, "| PSE_IQ_STA4 : %08x |\n",
989 mtk_r32(eth, MTK_PSE_IQ_STA(3)));
developer77f3fd42021-10-05 15:16:05 +0800990 seq_printf(seq, "| PSE_IQ_STA5 : %08x |\n",
991 mtk_r32(eth, MTK_PSE_IQ_STA(4)));
developer089e8852022-09-28 14:43:46 +0800992 seq_printf(seq, "| PSE_IQ_STA6 : %08x |\n",
993 mtk_r32(eth, MTK_PSE_IQ_STA(5)));
994 seq_printf(seq, "| PSE_IQ_STA7 : %08x |\n",
995 mtk_r32(eth, MTK_PSE_IQ_STA(6)));
996 seq_printf(seq, "| PSE_IQ_STA8 : %08x |\n",
997 mtk_r32(eth, MTK_PSE_IQ_STA(7)));
developerfd40db22021-04-29 10:08:25 +0800998 }
999
1000 seq_printf(seq, "| PSE_OQ_STA1 : %08x |\n",
1001 mtk_r32(eth, MTK_PSE_OQ_STA(0)));
1002 seq_printf(seq, "| PSE_OQ_STA2 : %08x |\n",
1003 mtk_r32(eth, MTK_PSE_OQ_STA(1)));
1004
developer089e8852022-09-28 14:43:46 +08001005 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1006 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developerfd40db22021-04-29 10:08:25 +08001007 seq_printf(seq, "| PSE_OQ_STA3 : %08x |\n",
1008 mtk_r32(eth, MTK_PSE_OQ_STA(2)));
1009 seq_printf(seq, "| PSE_OQ_STA4 : %08x |\n",
1010 mtk_r32(eth, MTK_PSE_OQ_STA(3)));
developer77f3fd42021-10-05 15:16:05 +08001011 seq_printf(seq, "| PSE_OQ_STA5 : %08x |\n",
1012 mtk_r32(eth, MTK_PSE_OQ_STA(4)));
developer089e8852022-09-28 14:43:46 +08001013 seq_printf(seq, "| PSE_OQ_STA6 : %08x |\n",
1014 mtk_r32(eth, MTK_PSE_OQ_STA(5)));
1015 seq_printf(seq, "| PSE_OQ_STA7 : %08x |\n",
1016 mtk_r32(eth, MTK_PSE_OQ_STA(6)));
1017 seq_printf(seq, "| PSE_OQ_STA8 : %08x |\n",
1018 mtk_r32(eth, MTK_PSE_OQ_STA(7)));
developerfd40db22021-04-29 10:08:25 +08001019 }
1020
developer77f3fd42021-10-05 15:16:05 +08001021 seq_printf(seq, "| PDMA_CRX_IDX : %08x |\n",
1022 mtk_r32(eth, MTK_PRX_CRX_IDX0));
1023 seq_printf(seq, "| PDMA_DRX_IDX : %08x |\n",
1024 mtk_r32(eth, MTK_PRX_DRX_IDX0));
1025 seq_printf(seq, "| QDMA_CTX_IDX : %08x |\n",
1026 mtk_r32(eth, MTK_QTX_CTX_PTR));
1027 seq_printf(seq, "| QDMA_DTX_IDX : %08x |\n",
1028 mtk_r32(eth, MTK_QTX_DTX_PTR));
developerfd40db22021-04-29 10:08:25 +08001029 seq_printf(seq, "| QDMA_FQ_CNT : %08x |\n",
1030 mtk_r32(eth, MTK_QDMA_FQ_CNT));
developer089e8852022-09-28 14:43:46 +08001031 seq_printf(seq, "| QDMA_FWD_CNT : %08x |\n",
1032 mtk_r32(eth, MTK_QDMA_FWD_CNT));
1033 seq_printf(seq, "| QDMA_FSM : %08x |\n",
1034 mtk_r32(eth, MTK_QDMA_FSM));
developerfd40db22021-04-29 10:08:25 +08001035 seq_printf(seq, "| FE_PSE_FREE : %08x |\n",
1036 mtk_r32(eth, MTK_FE_PSE_FREE));
1037 seq_printf(seq, "| FE_DROP_FQ : %08x |\n",
1038 mtk_r32(eth, MTK_FE_DROP_FQ));
1039 seq_printf(seq, "| FE_DROP_FC : %08x |\n",
1040 mtk_r32(eth, MTK_FE_DROP_FC));
1041 seq_printf(seq, "| FE_DROP_PPE : %08x |\n",
1042 mtk_r32(eth, MTK_FE_DROP_PPE));
1043 seq_printf(seq, "| GDM1_IG_CTRL : %08x |\n",
1044 mtk_r32(eth, MTK_GDMA_FWD_CFG(0)));
1045 seq_printf(seq, "| GDM2_IG_CTRL : %08x |\n",
1046 mtk_r32(eth, MTK_GDMA_FWD_CFG(1)));
developer089e8852022-09-28 14:43:46 +08001047 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
1048 seq_printf(seq, "| GDM3_IG_CTRL : %08x |\n",
1049 mtk_r32(eth, MTK_GDMA_FWD_CFG(2)));
1050 }
developerfd40db22021-04-29 10:08:25 +08001051 seq_printf(seq, "| MAC_P1_MCR : %08x |\n",
1052 mtk_r32(eth, MTK_MAC_MCR(0)));
1053 seq_printf(seq, "| MAC_P2_MCR : %08x |\n",
1054 mtk_r32(eth, MTK_MAC_MCR(1)));
developer089e8852022-09-28 14:43:46 +08001055 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
1056 seq_printf(seq, "| MAC_P3_MCR : %08x |\n",
1057 mtk_r32(eth, MTK_MAC_MCR(2)));
1058 }
developer77f3fd42021-10-05 15:16:05 +08001059 seq_printf(seq, "| MAC_P1_FSM : %08x |\n",
1060 mtk_r32(eth, MTK_MAC_FSM(0)));
1061 seq_printf(seq, "| MAC_P2_FSM : %08x |\n",
1062 mtk_r32(eth, MTK_MAC_FSM(1)));
developer089e8852022-09-28 14:43:46 +08001063 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
1064 seq_printf(seq, "| MAC_P3_FSM : %08x |\n",
1065 mtk_r32(eth, MTK_MAC_FSM(2)));
1066 }
developerfd40db22021-04-29 10:08:25 +08001067
developer089e8852022-09-28 14:43:46 +08001068 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1069 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developerfd40db22021-04-29 10:08:25 +08001070 seq_printf(seq, "| FE_CDM1_FSM : %08x |\n",
1071 mtk_r32(eth, MTK_FE_CDM1_FSM));
1072 seq_printf(seq, "| FE_CDM2_FSM : %08x |\n",
1073 mtk_r32(eth, MTK_FE_CDM2_FSM));
developer77f3fd42021-10-05 15:16:05 +08001074 seq_printf(seq, "| FE_CDM3_FSM : %08x |\n",
1075 mtk_r32(eth, MTK_FE_CDM3_FSM));
1076 seq_printf(seq, "| FE_CDM4_FSM : %08x |\n",
1077 mtk_r32(eth, MTK_FE_CDM4_FSM));
developer089e8852022-09-28 14:43:46 +08001078 seq_printf(seq, "| FE_CDM5_FSM : %08x |\n",
1079 mtk_r32(eth, MTK_FE_CDM5_FSM));
1080 seq_printf(seq, "| FE_CDM6_FSM : %08x |\n",
1081 mtk_r32(eth, MTK_FE_CDM6_FSM));
developerfd40db22021-04-29 10:08:25 +08001082 seq_printf(seq, "| FE_GDM1_FSM : %08x |\n",
1083 mtk_r32(eth, MTK_FE_GDM1_FSM));
1084 seq_printf(seq, "| FE_GDM2_FSM : %08x |\n",
1085 mtk_r32(eth, MTK_FE_GDM2_FSM));
developer77f3fd42021-10-05 15:16:05 +08001086 seq_printf(seq, "| SGMII_EFUSE : %08x |\n",
1087 mtk_dbg_r32(MTK_SGMII_EFUSE));
1088 seq_printf(seq, "| SGMII0_RX_CNT : %08x |\n",
1089 mtk_dbg_r32(MTK_SGMII_FALSE_CARRIER_CNT(0)));
1090 seq_printf(seq, "| SGMII1_RX_CNT : %08x |\n",
1091 mtk_dbg_r32(MTK_SGMII_FALSE_CARRIER_CNT(1)));
1092 seq_printf(seq, "| WED_RTQM_GLO : %08x |\n",
1093 mtk_dbg_r32(MTK_WED_RTQM_GLO_CFG));
developerfd40db22021-04-29 10:08:25 +08001094 }
1095
developer8051e042022-04-08 13:26:36 +08001096 mtk_w32(eth, 0xffffffff, MTK_FE_INT_STATUS);
developer089e8852022-09-28 14:43:46 +08001097 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1098 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
developer8051e042022-04-08 13:26:36 +08001099 mtk_w32(eth, 0xffffffff, MTK_FE_INT_STATUS2);
developer77f3fd42021-10-05 15:16:05 +08001100
developerfd40db22021-04-29 10:08:25 +08001101 return 0;
1102}
1103
1104static int dbg_regs_open(struct inode *inode, struct file *file)
1105{
1106 return single_open(file, dbg_regs_read, 0);
1107}
1108
1109static const struct file_operations dbg_regs_fops = {
1110 .owner = THIS_MODULE,
1111 .open = dbg_regs_open,
1112 .read = seq_read,
1113 .llseek = seq_lseek,
developer77d03a72021-06-06 00:06:00 +08001114 .release = single_release
1115};
1116
developere9356982022-07-04 09:03:20 +08001117void hw_lro_stats_update(u32 ring_no, struct mtk_rx_dma_v2 *rxd)
developer77d03a72021-06-06 00:06:00 +08001118{
developere9356982022-07-04 09:03:20 +08001119 struct mtk_eth *eth = g_eth;
developer77d03a72021-06-06 00:06:00 +08001120 u32 idx, agg_cnt, agg_size;
1121
developer8ecd51b2023-03-13 11:28:28 +08001122 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_V2)) {
developere9356982022-07-04 09:03:20 +08001123 idx = ring_no - 4;
1124 agg_cnt = RX_DMA_GET_AGG_CNT_V2(rxd->rxd6);
1125 } else {
1126 idx = ring_no - 1;
1127 agg_cnt = RX_DMA_GET_AGG_CNT(rxd->rxd2);
1128 }
developer77d03a72021-06-06 00:06:00 +08001129
developer8b6f2402022-11-28 13:42:34 +08001130 if (idx >= MTK_HW_LRO_RING_NUM)
1131 return;
1132
developer77d03a72021-06-06 00:06:00 +08001133 agg_size = RX_DMA_GET_PLEN0(rxd->rxd2);
1134
1135 hw_lro_agg_size_cnt[idx][agg_size / 5000]++;
1136 hw_lro_agg_num_cnt[idx][agg_cnt]++;
1137 hw_lro_tot_flush_cnt[idx]++;
1138 hw_lro_tot_agg_cnt[idx] += agg_cnt;
1139}
1140
developere9356982022-07-04 09:03:20 +08001141void hw_lro_flush_stats_update(u32 ring_no, struct mtk_rx_dma_v2 *rxd)
developer77d03a72021-06-06 00:06:00 +08001142{
developere9356982022-07-04 09:03:20 +08001143 struct mtk_eth *eth = g_eth;
developer77d03a72021-06-06 00:06:00 +08001144 u32 idx, flush_reason;
1145
developer8ecd51b2023-03-13 11:28:28 +08001146 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_V2)) {
developere9356982022-07-04 09:03:20 +08001147 idx = ring_no - 4;
1148 flush_reason = RX_DMA_GET_FLUSH_RSN_V2(rxd->rxd6);
1149 } else {
1150 idx = ring_no - 1;
1151 flush_reason = RX_DMA_GET_REV(rxd->rxd2);
1152 }
developer77d03a72021-06-06 00:06:00 +08001153
developer8b6f2402022-11-28 13:42:34 +08001154 if (idx >= MTK_HW_LRO_RING_NUM)
1155 return;
1156
developer77d03a72021-06-06 00:06:00 +08001157 if ((flush_reason & 0x7) == MTK_HW_LRO_AGG_FLUSH)
1158 hw_lro_agg_flush_cnt[idx]++;
1159 else if ((flush_reason & 0x7) == MTK_HW_LRO_AGE_FLUSH)
1160 hw_lro_age_flush_cnt[idx]++;
1161 else if ((flush_reason & 0x7) == MTK_HW_LRO_NOT_IN_SEQ_FLUSH)
1162 hw_lro_seq_flush_cnt[idx]++;
1163 else if ((flush_reason & 0x7) == MTK_HW_LRO_TIMESTAMP_FLUSH)
1164 hw_lro_timestamp_flush_cnt[idx]++;
1165 else if ((flush_reason & 0x7) == MTK_HW_LRO_NON_RULE_FLUSH)
1166 hw_lro_norule_flush_cnt[idx]++;
1167}
1168
1169ssize_t hw_lro_stats_write(struct file *file, const char __user *buffer,
1170 size_t count, loff_t *data)
1171{
1172 memset(hw_lro_agg_num_cnt, 0, sizeof(hw_lro_agg_num_cnt));
1173 memset(hw_lro_agg_size_cnt, 0, sizeof(hw_lro_agg_size_cnt));
1174 memset(hw_lro_tot_agg_cnt, 0, sizeof(hw_lro_tot_agg_cnt));
1175 memset(hw_lro_tot_flush_cnt, 0, sizeof(hw_lro_tot_flush_cnt));
1176 memset(hw_lro_agg_flush_cnt, 0, sizeof(hw_lro_agg_flush_cnt));
1177 memset(hw_lro_age_flush_cnt, 0, sizeof(hw_lro_age_flush_cnt));
1178 memset(hw_lro_seq_flush_cnt, 0, sizeof(hw_lro_seq_flush_cnt));
1179 memset(hw_lro_timestamp_flush_cnt, 0,
1180 sizeof(hw_lro_timestamp_flush_cnt));
1181 memset(hw_lro_norule_flush_cnt, 0, sizeof(hw_lro_norule_flush_cnt));
1182
1183 pr_info("clear hw lro cnt table\n");
1184
1185 return count;
1186}
1187
1188int hw_lro_stats_read_v1(struct seq_file *seq, void *v)
1189{
1190 int i;
1191
1192 seq_puts(seq, "HW LRO statistic dump:\n");
1193
1194 /* Agg number count */
1195 seq_puts(seq, "Cnt: RING1 | RING2 | RING3 | Total\n");
1196 for (i = 0; i <= MTK_HW_LRO_MAX_AGG_CNT; i++) {
1197 seq_printf(seq, " %d : %d %d %d %d\n",
1198 i, hw_lro_agg_num_cnt[0][i],
1199 hw_lro_agg_num_cnt[1][i], hw_lro_agg_num_cnt[2][i],
1200 hw_lro_agg_num_cnt[0][i] + hw_lro_agg_num_cnt[1][i] +
1201 hw_lro_agg_num_cnt[2][i]);
1202 }
1203
1204 /* Total agg count */
1205 seq_puts(seq, "Total agg: RING1 | RING2 | RING3 | Total\n");
1206 seq_printf(seq, " %d %d %d %d\n",
1207 hw_lro_tot_agg_cnt[0], hw_lro_tot_agg_cnt[1],
1208 hw_lro_tot_agg_cnt[2],
1209 hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1210 hw_lro_tot_agg_cnt[2]);
1211
1212 /* Total flush count */
1213 seq_puts(seq, "Total flush: RING1 | RING2 | RING3 | Total\n");
1214 seq_printf(seq, " %d %d %d %d\n",
1215 hw_lro_tot_flush_cnt[0], hw_lro_tot_flush_cnt[1],
1216 hw_lro_tot_flush_cnt[2],
1217 hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1218 hw_lro_tot_flush_cnt[2]);
1219
1220 /* Avg agg count */
1221 seq_puts(seq, "Avg agg: RING1 | RING2 | RING3 | Total\n");
1222 seq_printf(seq, " %d %d %d %d\n",
1223 (hw_lro_tot_flush_cnt[0]) ?
1224 hw_lro_tot_agg_cnt[0] / hw_lro_tot_flush_cnt[0] : 0,
1225 (hw_lro_tot_flush_cnt[1]) ?
1226 hw_lro_tot_agg_cnt[1] / hw_lro_tot_flush_cnt[1] : 0,
1227 (hw_lro_tot_flush_cnt[2]) ?
1228 hw_lro_tot_agg_cnt[2] / hw_lro_tot_flush_cnt[2] : 0,
1229 (hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1230 hw_lro_tot_flush_cnt[2]) ?
1231 ((hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1232 hw_lro_tot_agg_cnt[2]) / (hw_lro_tot_flush_cnt[0] +
1233 hw_lro_tot_flush_cnt[1] + hw_lro_tot_flush_cnt[2])) : 0);
1234
1235 /* Statistics of aggregation size counts */
1236 seq_puts(seq, "HW LRO flush pkt len:\n");
1237 seq_puts(seq, " Length | RING1 | RING2 | RING3 | Total\n");
1238 for (i = 0; i < 15; i++) {
1239 seq_printf(seq, "%d~%d: %d %d %d %d\n", i * 5000,
1240 (i + 1) * 5000, hw_lro_agg_size_cnt[0][i],
1241 hw_lro_agg_size_cnt[1][i], hw_lro_agg_size_cnt[2][i],
1242 hw_lro_agg_size_cnt[0][i] +
1243 hw_lro_agg_size_cnt[1][i] +
1244 hw_lro_agg_size_cnt[2][i]);
1245 }
1246
1247 seq_puts(seq, "Flush reason: RING1 | RING2 | RING3 | Total\n");
1248 seq_printf(seq, "AGG timeout: %d %d %d %d\n",
1249 hw_lro_agg_flush_cnt[0], hw_lro_agg_flush_cnt[1],
1250 hw_lro_agg_flush_cnt[2],
1251 (hw_lro_agg_flush_cnt[0] + hw_lro_agg_flush_cnt[1] +
1252 hw_lro_agg_flush_cnt[2]));
1253
1254 seq_printf(seq, "AGE timeout: %d %d %d %d\n",
1255 hw_lro_age_flush_cnt[0], hw_lro_age_flush_cnt[1],
1256 hw_lro_age_flush_cnt[2],
1257 (hw_lro_age_flush_cnt[0] + hw_lro_age_flush_cnt[1] +
1258 hw_lro_age_flush_cnt[2]));
1259
1260 seq_printf(seq, "Not in-sequence: %d %d %d %d\n",
1261 hw_lro_seq_flush_cnt[0], hw_lro_seq_flush_cnt[1],
1262 hw_lro_seq_flush_cnt[2],
1263 (hw_lro_seq_flush_cnt[0] + hw_lro_seq_flush_cnt[1] +
1264 hw_lro_seq_flush_cnt[2]));
1265
1266 seq_printf(seq, "Timestamp: %d %d %d %d\n",
1267 hw_lro_timestamp_flush_cnt[0],
1268 hw_lro_timestamp_flush_cnt[1],
1269 hw_lro_timestamp_flush_cnt[2],
1270 (hw_lro_timestamp_flush_cnt[0] +
1271 hw_lro_timestamp_flush_cnt[1] +
1272 hw_lro_timestamp_flush_cnt[2]));
1273
1274 seq_printf(seq, "No LRO rule: %d %d %d %d\n",
1275 hw_lro_norule_flush_cnt[0],
1276 hw_lro_norule_flush_cnt[1],
1277 hw_lro_norule_flush_cnt[2],
1278 (hw_lro_norule_flush_cnt[0] +
1279 hw_lro_norule_flush_cnt[1] +
1280 hw_lro_norule_flush_cnt[2]));
1281
1282 return 0;
1283}
1284
1285int hw_lro_stats_read_v2(struct seq_file *seq, void *v)
1286{
1287 int i;
1288
1289 seq_puts(seq, "HW LRO statistic dump:\n");
1290
1291 /* Agg number count */
1292 seq_puts(seq, "Cnt: RING4 | RING5 | RING6 | RING7 Total\n");
1293 for (i = 0; i <= MTK_HW_LRO_MAX_AGG_CNT; i++) {
1294 seq_printf(seq,
1295 " %d : %d %d %d %d %d\n",
1296 i, hw_lro_agg_num_cnt[0][i], hw_lro_agg_num_cnt[1][i],
1297 hw_lro_agg_num_cnt[2][i], hw_lro_agg_num_cnt[3][i],
1298 hw_lro_agg_num_cnt[0][i] + hw_lro_agg_num_cnt[1][i] +
1299 hw_lro_agg_num_cnt[2][i] + hw_lro_agg_num_cnt[3][i]);
1300 }
1301
1302 /* Total agg count */
1303 seq_puts(seq, "Total agg: RING4 | RING5 | RING6 | RING7 Total\n");
1304 seq_printf(seq, " %d %d %d %d %d\n",
1305 hw_lro_tot_agg_cnt[0], hw_lro_tot_agg_cnt[1],
1306 hw_lro_tot_agg_cnt[2], hw_lro_tot_agg_cnt[3],
1307 hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1308 hw_lro_tot_agg_cnt[2] + hw_lro_tot_agg_cnt[3]);
1309
1310 /* Total flush count */
1311 seq_puts(seq, "Total flush: RING4 | RING5 | RING6 | RING7 Total\n");
1312 seq_printf(seq, " %d %d %d %d %d\n",
1313 hw_lro_tot_flush_cnt[0], hw_lro_tot_flush_cnt[1],
1314 hw_lro_tot_flush_cnt[2], hw_lro_tot_flush_cnt[3],
1315 hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1316 hw_lro_tot_flush_cnt[2] + hw_lro_tot_flush_cnt[3]);
1317
1318 /* Avg agg count */
1319 seq_puts(seq, "Avg agg: RING4 | RING5 | RING6 | RING7 Total\n");
1320 seq_printf(seq, " %d %d %d %d %d\n",
1321 (hw_lro_tot_flush_cnt[0]) ?
1322 hw_lro_tot_agg_cnt[0] / hw_lro_tot_flush_cnt[0] : 0,
1323 (hw_lro_tot_flush_cnt[1]) ?
1324 hw_lro_tot_agg_cnt[1] / hw_lro_tot_flush_cnt[1] : 0,
1325 (hw_lro_tot_flush_cnt[2]) ?
1326 hw_lro_tot_agg_cnt[2] / hw_lro_tot_flush_cnt[2] : 0,
1327 (hw_lro_tot_flush_cnt[3]) ?
1328 hw_lro_tot_agg_cnt[3] / hw_lro_tot_flush_cnt[3] : 0,
1329 (hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1330 hw_lro_tot_flush_cnt[2] + hw_lro_tot_flush_cnt[3]) ?
1331 ((hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1332 hw_lro_tot_agg_cnt[2] + hw_lro_tot_agg_cnt[3]) /
1333 (hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1334 hw_lro_tot_flush_cnt[2] + hw_lro_tot_flush_cnt[3])) : 0);
1335
1336 /* Statistics of aggregation size counts */
1337 seq_puts(seq, "HW LRO flush pkt len:\n");
1338 seq_puts(seq, " Length | RING4 | RING5 | RING6 | RING7 Total\n");
1339 for (i = 0; i < 15; i++) {
1340 seq_printf(seq, "%d~%d: %d %d %d %d %d\n",
1341 i * 5000, (i + 1) * 5000,
1342 hw_lro_agg_size_cnt[0][i], hw_lro_agg_size_cnt[1][i],
1343 hw_lro_agg_size_cnt[2][i], hw_lro_agg_size_cnt[3][i],
1344 hw_lro_agg_size_cnt[0][i] +
1345 hw_lro_agg_size_cnt[1][i] +
1346 hw_lro_agg_size_cnt[2][i] +
1347 hw_lro_agg_size_cnt[3][i]);
1348 }
1349
1350 seq_puts(seq, "Flush reason: RING4 | RING5 | RING6 | RING7 Total\n");
1351 seq_printf(seq, "AGG timeout: %d %d %d %d %d\n",
1352 hw_lro_agg_flush_cnt[0], hw_lro_agg_flush_cnt[1],
1353 hw_lro_agg_flush_cnt[2], hw_lro_agg_flush_cnt[3],
1354 (hw_lro_agg_flush_cnt[0] + hw_lro_agg_flush_cnt[1] +
1355 hw_lro_agg_flush_cnt[2] + hw_lro_agg_flush_cnt[3]));
1356
1357 seq_printf(seq, "AGE timeout: %d %d %d %d %d\n",
1358 hw_lro_age_flush_cnt[0], hw_lro_age_flush_cnt[1],
1359 hw_lro_age_flush_cnt[2], hw_lro_age_flush_cnt[3],
1360 (hw_lro_age_flush_cnt[0] + hw_lro_age_flush_cnt[1] +
1361 hw_lro_age_flush_cnt[2] + hw_lro_age_flush_cnt[3]));
1362
1363 seq_printf(seq, "Not in-sequence: %d %d %d %d %d\n",
1364 hw_lro_seq_flush_cnt[0], hw_lro_seq_flush_cnt[1],
1365 hw_lro_seq_flush_cnt[2], hw_lro_seq_flush_cnt[3],
1366 (hw_lro_seq_flush_cnt[0] + hw_lro_seq_flush_cnt[1] +
1367 hw_lro_seq_flush_cnt[2] + hw_lro_seq_flush_cnt[3]));
1368
1369 seq_printf(seq, "Timestamp: %d %d %d %d %d\n",
1370 hw_lro_timestamp_flush_cnt[0],
1371 hw_lro_timestamp_flush_cnt[1],
1372 hw_lro_timestamp_flush_cnt[2],
1373 hw_lro_timestamp_flush_cnt[3],
1374 (hw_lro_timestamp_flush_cnt[0] +
1375 hw_lro_timestamp_flush_cnt[1] +
1376 hw_lro_timestamp_flush_cnt[2] +
1377 hw_lro_timestamp_flush_cnt[3]));
1378
1379 seq_printf(seq, "No LRO rule: %d %d %d %d %d\n",
1380 hw_lro_norule_flush_cnt[0],
1381 hw_lro_norule_flush_cnt[1],
1382 hw_lro_norule_flush_cnt[2],
1383 hw_lro_norule_flush_cnt[3],
1384 (hw_lro_norule_flush_cnt[0] +
1385 hw_lro_norule_flush_cnt[1] +
1386 hw_lro_norule_flush_cnt[2] +
1387 hw_lro_norule_flush_cnt[3]));
1388
1389 return 0;
1390}
1391
1392int hw_lro_stats_read_wrapper(struct seq_file *seq, void *v)
1393{
1394 struct mtk_eth *eth = g_eth;
1395
developer8ecd51b2023-03-13 11:28:28 +08001396 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_V2))
developer77d03a72021-06-06 00:06:00 +08001397 hw_lro_stats_read_v2(seq, v);
1398 else
1399 hw_lro_stats_read_v1(seq, v);
1400
1401 return 0;
1402}
1403
1404static int hw_lro_stats_open(struct inode *inode, struct file *file)
1405{
1406 return single_open(file, hw_lro_stats_read_wrapper, NULL);
1407}
1408
1409static const struct file_operations hw_lro_stats_fops = {
1410 .owner = THIS_MODULE,
1411 .open = hw_lro_stats_open,
1412 .read = seq_read,
1413 .llseek = seq_lseek,
1414 .write = hw_lro_stats_write,
developerfd40db22021-04-29 10:08:25 +08001415 .release = single_release
1416};
1417
developer77d03a72021-06-06 00:06:00 +08001418int hwlro_agg_cnt_ctrl(int cnt)
1419{
1420 int i;
1421
1422 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1423 SET_PDMA_RXRING_MAX_AGG_CNT(g_eth, i, cnt);
1424
1425 return 0;
1426}
1427
1428int hwlro_agg_time_ctrl(int time)
1429{
1430 int i;
1431
1432 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1433 SET_PDMA_RXRING_AGG_TIME(g_eth, i, time);
1434
1435 return 0;
1436}
1437
1438int hwlro_age_time_ctrl(int time)
1439{
1440 int i;
1441
1442 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1443 SET_PDMA_RXRING_AGE_TIME(g_eth, i, time);
1444
1445 return 0;
1446}
1447
1448int hwlro_threshold_ctrl(int bandwidth)
1449{
1450 SET_PDMA_LRO_BW_THRESHOLD(g_eth, bandwidth);
1451
1452 return 0;
1453}
1454
1455int hwlro_ring_enable_ctrl(int enable)
1456{
1457 int i;
1458
1459 pr_info("[%s] %s HW LRO rings\n", __func__, (enable) ? "Enable" : "Disable");
1460
1461 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1462 SET_PDMA_RXRING_VALID(g_eth, i, enable);
1463
1464 return 0;
1465}
1466
1467int hwlro_stats_enable_ctrl(int enable)
1468{
1469 pr_info("[%s] %s HW LRO statistics\n", __func__, (enable) ? "Enable" : "Disable");
1470 mtk_hwlro_stats_ebl = enable;
1471
1472 return 0;
1473}
1474
1475static const mtk_lro_dbg_func lro_dbg_func[] = {
1476 [0] = hwlro_agg_cnt_ctrl,
1477 [1] = hwlro_agg_time_ctrl,
1478 [2] = hwlro_age_time_ctrl,
1479 [3] = hwlro_threshold_ctrl,
1480 [4] = hwlro_ring_enable_ctrl,
1481 [5] = hwlro_stats_enable_ctrl,
1482};
1483
1484ssize_t hw_lro_auto_tlb_write(struct file *file, const char __user *buffer,
1485 size_t count, loff_t *data)
1486{
1487 char buf[32];
1488 char *p_buf;
1489 char *p_token = NULL;
1490 char *p_delimiter = " \t";
1491 long x = 0, y = 0;
developer4c32b7a2021-11-13 16:46:43 +08001492 u32 len = count;
developer77d03a72021-06-06 00:06:00 +08001493 int ret;
1494
1495 if (len >= sizeof(buf)) {
1496 pr_info("Input handling fail!\n");
developer77d03a72021-06-06 00:06:00 +08001497 return -1;
1498 }
1499
1500 if (copy_from_user(buf, buffer, len))
1501 return -EFAULT;
1502
1503 buf[len] = '\0';
1504
1505 p_buf = buf;
1506 p_token = strsep(&p_buf, p_delimiter);
1507 if (!p_token)
1508 x = 0;
1509 else
1510 ret = kstrtol(p_token, 10, &x);
1511
1512 p_token = strsep(&p_buf, "\t\n ");
1513 if (p_token)
1514 ret = kstrtol(p_token, 10, &y);
1515
1516 if (lro_dbg_func[x] && (ARRAY_SIZE(lro_dbg_func) > x))
1517 (*lro_dbg_func[x]) (y);
1518
1519 return count;
1520}
1521
1522void hw_lro_auto_tlb_dump_v1(struct seq_file *seq, u32 index)
1523{
1524 int i;
1525 struct mtk_lro_alt_v1 alt;
1526 __be32 addr;
1527 u32 tlb_info[9];
1528 u32 dw_len, cnt, priority;
1529 u32 entry;
1530
1531 if (index > 4)
1532 index = index - 1;
1533 entry = (index * 9) + 1;
1534
1535 /* read valid entries of the auto-learn table */
1536 mtk_w32(g_eth, entry, MTK_FE_ALT_CF8);
1537
1538 for (i = 0; i < 9; i++)
1539 tlb_info[i] = mtk_r32(g_eth, MTK_FE_ALT_SEQ_CFC);
1540
1541 memcpy(&alt, tlb_info, sizeof(struct mtk_lro_alt_v1));
1542
1543 dw_len = alt.alt_info7.dw_len;
1544 cnt = alt.alt_info6.cnt;
1545
1546 if (mtk_r32(g_eth, MTK_PDMA_LRO_CTRL_DW0) & MTK_LRO_ALT_PKT_CNT_MODE)
1547 priority = cnt; /* packet count */
1548 else
1549 priority = dw_len; /* byte count */
1550
1551 /* dump valid entries of the auto-learn table */
1552 if (index >= 4)
1553 seq_printf(seq, "\n===== TABLE Entry: %d (Act) =====\n", index);
1554 else
1555 seq_printf(seq, "\n===== TABLE Entry: %d (LRU) =====\n", index);
1556
1557 if (alt.alt_info8.ipv4) {
1558 addr = htonl(alt.alt_info1.sip0);
1559 seq_printf(seq, "SIP = %pI4 (IPv4)\n", &addr);
1560 } else {
1561 seq_printf(seq, "SIP = %08X:%08X:%08X:%08X (IPv6)\n",
1562 alt.alt_info4.sip3, alt.alt_info3.sip2,
1563 alt.alt_info2.sip1, alt.alt_info1.sip0);
1564 }
1565
1566 seq_printf(seq, "DIP_ID = %d\n", alt.alt_info8.dip_id);
1567 seq_printf(seq, "TCP SPORT = %d | TCP DPORT = %d\n",
1568 alt.alt_info0.stp, alt.alt_info0.dtp);
1569 seq_printf(seq, "VLAN_VID_VLD = %d\n", alt.alt_info6.vlan_vid_vld);
1570 seq_printf(seq, "VLAN1 = %d | VLAN2 = %d | VLAN3 = %d | VLAN4 =%d\n",
1571 (alt.alt_info5.vlan_vid0 & 0xfff),
1572 ((alt.alt_info5.vlan_vid0 >> 12) & 0xfff),
1573 ((alt.alt_info6.vlan_vid1 << 8) |
1574 ((alt.alt_info5.vlan_vid0 >> 24) & 0xfff)),
1575 ((alt.alt_info6.vlan_vid1 >> 4) & 0xfff));
1576 seq_printf(seq, "TPUT = %d | FREQ = %d\n", dw_len, cnt);
1577 seq_printf(seq, "PRIORITY = %d\n", priority);
1578}
1579
1580void hw_lro_auto_tlb_dump_v2(struct seq_file *seq, u32 index)
1581{
1582 int i;
1583 struct mtk_lro_alt_v2 alt;
1584 u32 score = 0, ipv4 = 0;
1585 u32 ipv6[4] = { 0 };
1586 u32 tlb_info[12];
1587
1588 /* read valid entries of the auto-learn table */
1589 mtk_w32(g_eth, index << MTK_LRO_ALT_INDEX_OFFSET, MTK_LRO_ALT_DBG);
1590
1591 for (i = 0; i < 11; i++)
1592 tlb_info[i] = mtk_r32(g_eth, MTK_LRO_ALT_DBG_DATA);
1593
1594 memcpy(&alt, tlb_info, sizeof(struct mtk_lro_alt_v2));
1595
1596 if (mtk_r32(g_eth, MTK_PDMA_LRO_CTRL_DW0) & MTK_LRO_ALT_PKT_CNT_MODE)
1597 score = 1; /* packet count */
1598 else
1599 score = 0; /* byte count */
1600
1601 /* dump valid entries of the auto-learn table */
1602 if (alt.alt_info0.valid) {
1603 if (index < 5)
1604 seq_printf(seq,
1605 "\n===== TABLE Entry: %d (onging) =====\n",
1606 index);
1607 else
1608 seq_printf(seq,
1609 "\n===== TABLE Entry: %d (candidate) =====\n",
1610 index);
1611
1612 if (alt.alt_info1.v4_valid) {
1613 ipv4 = (alt.alt_info4.sip0_h << 23) |
1614 alt.alt_info5.sip0_l;
1615 seq_printf(seq, "SIP = 0x%x: (IPv4)\n", ipv4);
1616
1617 ipv4 = (alt.alt_info8.dip0_h << 23) |
1618 alt.alt_info9.dip0_l;
1619 seq_printf(seq, "DIP = 0x%x: (IPv4)\n", ipv4);
1620 } else if (alt.alt_info1.v6_valid) {
1621 ipv6[3] = (alt.alt_info1.sip3_h << 23) |
1622 (alt.alt_info2.sip3_l << 9);
1623 ipv6[2] = (alt.alt_info2.sip2_h << 23) |
1624 (alt.alt_info3.sip2_l << 9);
1625 ipv6[1] = (alt.alt_info3.sip1_h << 23) |
1626 (alt.alt_info4.sip1_l << 9);
1627 ipv6[0] = (alt.alt_info4.sip0_h << 23) |
1628 (alt.alt_info5.sip0_l << 9);
1629 seq_printf(seq, "SIP = 0x%x:0x%x:0x%x:0x%x (IPv6)\n",
1630 ipv6[3], ipv6[2], ipv6[1], ipv6[0]);
1631
1632 ipv6[3] = (alt.alt_info5.dip3_h << 23) |
1633 (alt.alt_info6.dip3_l << 9);
1634 ipv6[2] = (alt.alt_info6.dip2_h << 23) |
1635 (alt.alt_info7.dip2_l << 9);
1636 ipv6[1] = (alt.alt_info7.dip1_h << 23) |
1637 (alt.alt_info8.dip1_l << 9);
1638 ipv6[0] = (alt.alt_info8.dip0_h << 23) |
1639 (alt.alt_info9.dip0_l << 9);
1640 seq_printf(seq, "DIP = 0x%x:0x%x:0x%x:0x%x (IPv6)\n",
1641 ipv6[3], ipv6[2], ipv6[1], ipv6[0]);
1642 }
1643
1644 seq_printf(seq, "TCP SPORT = %d | TCP DPORT = %d\n",
1645 (alt.alt_info9.sp_h << 7) | (alt.alt_info10.sp_l),
1646 alt.alt_info10.dp);
1647 }
1648}
1649
1650int hw_lro_auto_tlb_read(struct seq_file *seq, void *v)
1651{
1652 int i;
1653 u32 reg_val;
1654 u32 reg_op1, reg_op2, reg_op3, reg_op4;
1655 u32 agg_cnt, agg_time, age_time;
1656
1657 seq_puts(seq, "Usage of /proc/mtketh/hw_lro_auto_tlb:\n");
1658 seq_puts(seq, "echo [function] [setting] > /proc/mtketh/hw_lro_auto_tlb\n");
1659 seq_puts(seq, "Functions:\n");
1660 seq_puts(seq, "[0] = hwlro_agg_cnt_ctrl\n");
1661 seq_puts(seq, "[1] = hwlro_agg_time_ctrl\n");
1662 seq_puts(seq, "[2] = hwlro_age_time_ctrl\n");
1663 seq_puts(seq, "[3] = hwlro_threshold_ctrl\n");
1664 seq_puts(seq, "[4] = hwlro_ring_enable_ctrl\n");
1665 seq_puts(seq, "[5] = hwlro_stats_enable_ctrl\n\n");
1666
developer8ecd51b2023-03-13 11:28:28 +08001667 if (MTK_HAS_CAPS(g_eth->soc->caps, MTK_NETSYS_RX_V2)) {
developer77d03a72021-06-06 00:06:00 +08001668 for (i = 1; i <= 8; i++)
1669 hw_lro_auto_tlb_dump_v2(seq, i);
1670 } else {
1671 /* Read valid entries of the auto-learn table */
1672 mtk_w32(g_eth, 0, MTK_FE_ALT_CF8);
1673 reg_val = mtk_r32(g_eth, MTK_FE_ALT_SEQ_CFC);
1674
1675 seq_printf(seq,
1676 "HW LRO Auto-learn Table: (MTK_FE_ALT_SEQ_CFC=0x%x)\n",
1677 reg_val);
1678
1679 for (i = 7; i >= 0; i--) {
1680 if (reg_val & (1 << i))
1681 hw_lro_auto_tlb_dump_v1(seq, i);
1682 }
1683 }
1684
1685 /* Read the agg_time/age_time/agg_cnt of LRO rings */
1686 seq_puts(seq, "\nHW LRO Ring Settings\n");
1687
1688 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++) {
1689 reg_op1 = mtk_r32(g_eth, MTK_LRO_CTRL_DW1_CFG(i));
1690 reg_op2 = mtk_r32(g_eth, MTK_LRO_CTRL_DW2_CFG(i));
1691 reg_op3 = mtk_r32(g_eth, MTK_LRO_CTRL_DW3_CFG(i));
1692 reg_op4 = mtk_r32(g_eth, MTK_PDMA_LRO_CTRL_DW2);
1693
1694 agg_cnt =
1695 ((reg_op3 & 0x3) << 6) |
1696 ((reg_op2 >> MTK_LRO_RING_AGG_CNT_L_OFFSET) & 0x3f);
1697 agg_time = (reg_op2 >> MTK_LRO_RING_AGG_TIME_OFFSET) & 0xffff;
1698 age_time =
1699 ((reg_op2 & 0x3f) << 10) |
1700 ((reg_op1 >> MTK_LRO_RING_AGE_TIME_L_OFFSET) & 0x3ff);
1701 seq_printf(seq,
1702 "Ring[%d]: MAX_AGG_CNT=%d, AGG_TIME=%d, AGE_TIME=%d, Threshold=%d\n",
developer8ecd51b2023-03-13 11:28:28 +08001703 (MTK_HAS_CAPS(g_eth->soc->caps, MTK_NETSYS_RX_V2)) ?
1704 i : i+3,
developer77d03a72021-06-06 00:06:00 +08001705 agg_cnt, agg_time, age_time, reg_op4);
1706 }
1707
1708 seq_puts(seq, "\n");
1709
1710 return 0;
1711}
1712
1713static int hw_lro_auto_tlb_open(struct inode *inode, struct file *file)
1714{
1715 return single_open(file, hw_lro_auto_tlb_read, NULL);
1716}
1717
1718static const struct file_operations hw_lro_auto_tlb_fops = {
1719 .owner = THIS_MODULE,
1720 .open = hw_lro_auto_tlb_open,
1721 .read = seq_read,
1722 .llseek = seq_lseek,
1723 .write = hw_lro_auto_tlb_write,
1724 .release = single_release
1725};
developerfd40db22021-04-29 10:08:25 +08001726
developer8051e042022-04-08 13:26:36 +08001727int reset_event_read(struct seq_file *seq, void *v)
1728{
1729 struct mtk_eth *eth = g_eth;
1730 struct mtk_reset_event reset_event = eth->reset_event;
1731
1732 seq_printf(seq, "[Event] [Count]\n");
1733 seq_printf(seq, " FQ Empty: %d\n",
1734 reset_event.count[MTK_EVENT_FQ_EMPTY]);
1735 seq_printf(seq, " TSO Fail: %d\n",
1736 reset_event.count[MTK_EVENT_TSO_FAIL]);
1737 seq_printf(seq, " TSO Illegal: %d\n",
1738 reset_event.count[MTK_EVENT_TSO_ILLEGAL]);
1739 seq_printf(seq, " TSO Align: %d\n",
1740 reset_event.count[MTK_EVENT_TSO_ALIGN]);
1741 seq_printf(seq, " RFIFO OV: %d\n",
1742 reset_event.count[MTK_EVENT_RFIFO_OV]);
1743 seq_printf(seq, " RFIFO UF: %d\n",
1744 reset_event.count[MTK_EVENT_RFIFO_UF]);
1745 seq_printf(seq, " Force: %d\n",
1746 reset_event.count[MTK_EVENT_FORCE]);
1747 seq_printf(seq, "----------------------------\n");
1748 seq_printf(seq, " Warm Cnt: %d\n",
1749 reset_event.count[MTK_EVENT_WARM_CNT]);
1750 seq_printf(seq, " Cold Cnt: %d\n",
1751 reset_event.count[MTK_EVENT_COLD_CNT]);
1752 seq_printf(seq, " Total Cnt: %d\n",
1753 reset_event.count[MTK_EVENT_TOTAL_CNT]);
1754
1755 return 0;
1756}
1757
1758static int reset_event_open(struct inode *inode, struct file *file)
1759{
1760 return single_open(file, reset_event_read, 0);
1761}
1762
1763ssize_t reset_event_write(struct file *file, const char __user *buffer,
1764 size_t count, loff_t *data)
1765{
1766 struct mtk_eth *eth = g_eth;
1767 struct mtk_reset_event *reset_event = &eth->reset_event;
1768
1769 memset(reset_event, 0, sizeof(struct mtk_reset_event));
1770 pr_info("MTK reset event counter is cleared !\n");
1771
1772 return count;
1773}
1774
1775static const struct file_operations reset_event_fops = {
1776 .owner = THIS_MODULE,
1777 .open = reset_event_open,
1778 .read = seq_read,
1779 .llseek = seq_lseek,
1780 .write = reset_event_write,
1781 .release = single_release
1782};
1783
1784
developerfd40db22021-04-29 10:08:25 +08001785struct proc_dir_entry *proc_reg_dir;
developer621ca6b2023-01-11 11:08:46 +08001786static struct proc_dir_entry *proc_esw_cnt, *proc_xfi_cnt,
1787 *proc_dbg_regs, *proc_reset_event;
developerfd40db22021-04-29 10:08:25 +08001788
1789int debug_proc_init(struct mtk_eth *eth)
1790{
1791 g_eth = eth;
1792
1793 if (!proc_reg_dir)
1794 proc_reg_dir = proc_mkdir(PROCREG_DIR, NULL);
1795
1796 proc_tx_ring =
1797 proc_create(PROCREG_TXRING, 0, proc_reg_dir, &tx_ring_fops);
1798 if (!proc_tx_ring)
1799 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_TXRING);
1800
developer8051e042022-04-08 13:26:36 +08001801 proc_hwtx_ring =
1802 proc_create(PROCREG_HWTXRING, 0, proc_reg_dir, &hwtx_ring_fops);
1803 if (!proc_hwtx_ring)
1804 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_HWTXRING);
1805
developerfd40db22021-04-29 10:08:25 +08001806 proc_rx_ring =
1807 proc_create(PROCREG_RXRING, 0, proc_reg_dir, &rx_ring_fops);
1808 if (!proc_rx_ring)
1809 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_RXRING);
1810
1811 proc_esw_cnt =
1812 proc_create(PROCREG_ESW_CNT, 0, proc_reg_dir, &switch_count_fops);
1813 if (!proc_esw_cnt)
1814 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_ESW_CNT);
1815
developer621ca6b2023-01-11 11:08:46 +08001816 if (MTK_HAS_CAPS(g_eth->soc->caps, MTK_NETSYS_V3)) {
1817 proc_xfi_cnt =
1818 proc_create(PROCREG_XFI_CNT, 0,
1819 proc_reg_dir, &xfi_count_fops);
1820 if (!proc_xfi_cnt)
1821 pr_notice("!! FAIL to create %s PROC !!\n",
1822 PROCREG_XFI_CNT);
1823 }
1824
developerfd40db22021-04-29 10:08:25 +08001825 proc_dbg_regs =
1826 proc_create(PROCREG_DBG_REGS, 0, proc_reg_dir, &dbg_regs_fops);
1827 if (!proc_dbg_regs)
1828 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_DBG_REGS);
1829
developer77d03a72021-06-06 00:06:00 +08001830 if (g_eth->hwlro) {
1831 proc_hw_lro_stats =
1832 proc_create(PROCREG_HW_LRO_STATS, 0, proc_reg_dir,
1833 &hw_lro_stats_fops);
1834 if (!proc_hw_lro_stats)
1835 pr_info("!! FAIL to create %s PROC !!\n", PROCREG_HW_LRO_STATS);
1836
1837 proc_hw_lro_auto_tlb =
1838 proc_create(PROCREG_HW_LRO_AUTO_TLB, 0, proc_reg_dir,
1839 &hw_lro_auto_tlb_fops);
1840 if (!proc_hw_lro_auto_tlb)
1841 pr_info("!! FAIL to create %s PROC !!\n",
1842 PROCREG_HW_LRO_AUTO_TLB);
1843 }
1844
developer8051e042022-04-08 13:26:36 +08001845 proc_reset_event =
1846 proc_create(PROCREG_RESET_EVENT, 0, proc_reg_dir, &reset_event_fops);
1847 if (!proc_reset_event)
1848 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_RESET_EVENT);
1849
developerfd40db22021-04-29 10:08:25 +08001850 return 0;
1851}
1852
1853void debug_proc_exit(void)
1854{
1855 if (proc_tx_ring)
1856 remove_proc_entry(PROCREG_TXRING, proc_reg_dir);
developer8051e042022-04-08 13:26:36 +08001857 if (proc_hwtx_ring)
1858 remove_proc_entry(PROCREG_HWTXRING, proc_reg_dir);
developerfd40db22021-04-29 10:08:25 +08001859 if (proc_rx_ring)
1860 remove_proc_entry(PROCREG_RXRING, proc_reg_dir);
1861
1862 if (proc_esw_cnt)
1863 remove_proc_entry(PROCREG_ESW_CNT, proc_reg_dir);
1864
developer621ca6b2023-01-11 11:08:46 +08001865 if (proc_xfi_cnt)
1866 remove_proc_entry(PROCREG_XFI_CNT, proc_reg_dir);
1867
developerfd40db22021-04-29 10:08:25 +08001868 if (proc_reg_dir)
1869 remove_proc_entry(PROCREG_DIR, 0);
1870
1871 if (proc_dbg_regs)
1872 remove_proc_entry(PROCREG_DBG_REGS, proc_reg_dir);
developer77d03a72021-06-06 00:06:00 +08001873
1874 if (g_eth->hwlro) {
1875 if (proc_hw_lro_stats)
1876 remove_proc_entry(PROCREG_HW_LRO_STATS, proc_reg_dir);
1877
1878 if (proc_hw_lro_auto_tlb)
1879 remove_proc_entry(PROCREG_HW_LRO_AUTO_TLB, proc_reg_dir);
1880 }
developer8051e042022-04-08 13:26:36 +08001881
1882 if (proc_reset_event)
1883 remove_proc_entry(PROCREG_RESET_EVENT, proc_reg_dir);
developerfd40db22021-04-29 10:08:25 +08001884}
1885