blob: 3e9320050c881301f7924c0782c673d6dc942f16 [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
developer089e8852022-09-28 14:43:46 +0800927 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
928 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developere9356982022-07-04 09:03:20 +0800929 seq_printf(seq, " %08x %08x %08x %08x",
930 rx_ring->rxd5, rx_ring->rxd6,
931 rx_ring->rxd7, rx_ring->rxd8);
932 }
933
developerfd40db22021-04-29 10:08:25 +0800934 seq_printf(seq, "\n");
935 }
936
developerfd40db22021-04-29 10:08:25 +0800937 return 0;
938}
939
940static int rx_ring_open(struct inode *inode, struct file *file)
941{
942 return single_open(file, rx_ring_read, NULL);
943}
944
945static const struct file_operations rx_ring_fops = {
946 .owner = THIS_MODULE,
947 .open = rx_ring_open,
948 .read = seq_read,
949 .llseek = seq_lseek,
950 .release = single_release
951};
952
developer77f3fd42021-10-05 15:16:05 +0800953static inline u32 mtk_dbg_r32(u32 reg)
954{
955 void __iomem *virt_reg;
956 u32 val;
957
958 virt_reg = ioremap(reg, 32);
959 val = __raw_readl(virt_reg);
960 iounmap(virt_reg);
961
962 return val;
963}
964
developerfd40db22021-04-29 10:08:25 +0800965int dbg_regs_read(struct seq_file *seq, void *v)
966{
967 struct mtk_eth *eth = g_eth;
968
developer77f3fd42021-10-05 15:16:05 +0800969 seq_puts(seq, " <<DEBUG REG DUMP>>\n");
970
971 seq_printf(seq, "| FE_INT_STA : %08x |\n",
developer8051e042022-04-08 13:26:36 +0800972 mtk_r32(eth, MTK_FE_INT_STATUS));
developer089e8852022-09-28 14:43:46 +0800973 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
974 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
developer77f3fd42021-10-05 15:16:05 +0800975 seq_printf(seq, "| FE_INT_STA2 : %08x |\n",
developer8051e042022-04-08 13:26:36 +0800976 mtk_r32(eth, MTK_FE_INT_STATUS2));
developer77f3fd42021-10-05 15:16:05 +0800977
developerfd40db22021-04-29 10:08:25 +0800978 seq_printf(seq, "| PSE_FQFC_CFG : %08x |\n",
979 mtk_r32(eth, MTK_PSE_FQFC_CFG));
980 seq_printf(seq, "| PSE_IQ_STA1 : %08x |\n",
981 mtk_r32(eth, MTK_PSE_IQ_STA(0)));
982 seq_printf(seq, "| PSE_IQ_STA2 : %08x |\n",
983 mtk_r32(eth, MTK_PSE_IQ_STA(1)));
984
developer089e8852022-09-28 14:43:46 +0800985 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
986 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developerfd40db22021-04-29 10:08:25 +0800987 seq_printf(seq, "| PSE_IQ_STA3 : %08x |\n",
988 mtk_r32(eth, MTK_PSE_IQ_STA(2)));
989 seq_printf(seq, "| PSE_IQ_STA4 : %08x |\n",
990 mtk_r32(eth, MTK_PSE_IQ_STA(3)));
developer77f3fd42021-10-05 15:16:05 +0800991 seq_printf(seq, "| PSE_IQ_STA5 : %08x |\n",
992 mtk_r32(eth, MTK_PSE_IQ_STA(4)));
developer089e8852022-09-28 14:43:46 +0800993 seq_printf(seq, "| PSE_IQ_STA6 : %08x |\n",
994 mtk_r32(eth, MTK_PSE_IQ_STA(5)));
995 seq_printf(seq, "| PSE_IQ_STA7 : %08x |\n",
996 mtk_r32(eth, MTK_PSE_IQ_STA(6)));
997 seq_printf(seq, "| PSE_IQ_STA8 : %08x |\n",
998 mtk_r32(eth, MTK_PSE_IQ_STA(7)));
developerfd40db22021-04-29 10:08:25 +0800999 }
1000
1001 seq_printf(seq, "| PSE_OQ_STA1 : %08x |\n",
1002 mtk_r32(eth, MTK_PSE_OQ_STA(0)));
1003 seq_printf(seq, "| PSE_OQ_STA2 : %08x |\n",
1004 mtk_r32(eth, MTK_PSE_OQ_STA(1)));
1005
developer089e8852022-09-28 14:43:46 +08001006 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1007 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developerfd40db22021-04-29 10:08:25 +08001008 seq_printf(seq, "| PSE_OQ_STA3 : %08x |\n",
1009 mtk_r32(eth, MTK_PSE_OQ_STA(2)));
1010 seq_printf(seq, "| PSE_OQ_STA4 : %08x |\n",
1011 mtk_r32(eth, MTK_PSE_OQ_STA(3)));
developer77f3fd42021-10-05 15:16:05 +08001012 seq_printf(seq, "| PSE_OQ_STA5 : %08x |\n",
1013 mtk_r32(eth, MTK_PSE_OQ_STA(4)));
developer089e8852022-09-28 14:43:46 +08001014 seq_printf(seq, "| PSE_OQ_STA6 : %08x |\n",
1015 mtk_r32(eth, MTK_PSE_OQ_STA(5)));
1016 seq_printf(seq, "| PSE_OQ_STA7 : %08x |\n",
1017 mtk_r32(eth, MTK_PSE_OQ_STA(6)));
1018 seq_printf(seq, "| PSE_OQ_STA8 : %08x |\n",
1019 mtk_r32(eth, MTK_PSE_OQ_STA(7)));
developerfd40db22021-04-29 10:08:25 +08001020 }
1021
developer77f3fd42021-10-05 15:16:05 +08001022 seq_printf(seq, "| PDMA_CRX_IDX : %08x |\n",
1023 mtk_r32(eth, MTK_PRX_CRX_IDX0));
1024 seq_printf(seq, "| PDMA_DRX_IDX : %08x |\n",
1025 mtk_r32(eth, MTK_PRX_DRX_IDX0));
1026 seq_printf(seq, "| QDMA_CTX_IDX : %08x |\n",
1027 mtk_r32(eth, MTK_QTX_CTX_PTR));
1028 seq_printf(seq, "| QDMA_DTX_IDX : %08x |\n",
1029 mtk_r32(eth, MTK_QTX_DTX_PTR));
developerfd40db22021-04-29 10:08:25 +08001030 seq_printf(seq, "| QDMA_FQ_CNT : %08x |\n",
1031 mtk_r32(eth, MTK_QDMA_FQ_CNT));
developer089e8852022-09-28 14:43:46 +08001032 seq_printf(seq, "| QDMA_FWD_CNT : %08x |\n",
1033 mtk_r32(eth, MTK_QDMA_FWD_CNT));
1034 seq_printf(seq, "| QDMA_FSM : %08x |\n",
1035 mtk_r32(eth, MTK_QDMA_FSM));
developerfd40db22021-04-29 10:08:25 +08001036 seq_printf(seq, "| FE_PSE_FREE : %08x |\n",
1037 mtk_r32(eth, MTK_FE_PSE_FREE));
1038 seq_printf(seq, "| FE_DROP_FQ : %08x |\n",
1039 mtk_r32(eth, MTK_FE_DROP_FQ));
1040 seq_printf(seq, "| FE_DROP_FC : %08x |\n",
1041 mtk_r32(eth, MTK_FE_DROP_FC));
1042 seq_printf(seq, "| FE_DROP_PPE : %08x |\n",
1043 mtk_r32(eth, MTK_FE_DROP_PPE));
1044 seq_printf(seq, "| GDM1_IG_CTRL : %08x |\n",
1045 mtk_r32(eth, MTK_GDMA_FWD_CFG(0)));
1046 seq_printf(seq, "| GDM2_IG_CTRL : %08x |\n",
1047 mtk_r32(eth, MTK_GDMA_FWD_CFG(1)));
developer089e8852022-09-28 14:43:46 +08001048 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
1049 seq_printf(seq, "| GDM3_IG_CTRL : %08x |\n",
1050 mtk_r32(eth, MTK_GDMA_FWD_CFG(2)));
1051 }
developerfd40db22021-04-29 10:08:25 +08001052 seq_printf(seq, "| MAC_P1_MCR : %08x |\n",
1053 mtk_r32(eth, MTK_MAC_MCR(0)));
1054 seq_printf(seq, "| MAC_P2_MCR : %08x |\n",
1055 mtk_r32(eth, MTK_MAC_MCR(1)));
developer089e8852022-09-28 14:43:46 +08001056 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
1057 seq_printf(seq, "| MAC_P3_MCR : %08x |\n",
1058 mtk_r32(eth, MTK_MAC_MCR(2)));
1059 }
developer77f3fd42021-10-05 15:16:05 +08001060 seq_printf(seq, "| MAC_P1_FSM : %08x |\n",
1061 mtk_r32(eth, MTK_MAC_FSM(0)));
1062 seq_printf(seq, "| MAC_P2_FSM : %08x |\n",
1063 mtk_r32(eth, MTK_MAC_FSM(1)));
developer089e8852022-09-28 14:43:46 +08001064 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
1065 seq_printf(seq, "| MAC_P3_FSM : %08x |\n",
1066 mtk_r32(eth, MTK_MAC_FSM(2)));
1067 }
developerfd40db22021-04-29 10:08:25 +08001068
developer089e8852022-09-28 14:43:46 +08001069 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1070 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developerfd40db22021-04-29 10:08:25 +08001071 seq_printf(seq, "| FE_CDM1_FSM : %08x |\n",
1072 mtk_r32(eth, MTK_FE_CDM1_FSM));
1073 seq_printf(seq, "| FE_CDM2_FSM : %08x |\n",
1074 mtk_r32(eth, MTK_FE_CDM2_FSM));
developer77f3fd42021-10-05 15:16:05 +08001075 seq_printf(seq, "| FE_CDM3_FSM : %08x |\n",
1076 mtk_r32(eth, MTK_FE_CDM3_FSM));
1077 seq_printf(seq, "| FE_CDM4_FSM : %08x |\n",
1078 mtk_r32(eth, MTK_FE_CDM4_FSM));
developer089e8852022-09-28 14:43:46 +08001079 seq_printf(seq, "| FE_CDM5_FSM : %08x |\n",
1080 mtk_r32(eth, MTK_FE_CDM5_FSM));
1081 seq_printf(seq, "| FE_CDM6_FSM : %08x |\n",
1082 mtk_r32(eth, MTK_FE_CDM6_FSM));
developerfd40db22021-04-29 10:08:25 +08001083 seq_printf(seq, "| FE_GDM1_FSM : %08x |\n",
1084 mtk_r32(eth, MTK_FE_GDM1_FSM));
1085 seq_printf(seq, "| FE_GDM2_FSM : %08x |\n",
1086 mtk_r32(eth, MTK_FE_GDM2_FSM));
developer77f3fd42021-10-05 15:16:05 +08001087 seq_printf(seq, "| SGMII_EFUSE : %08x |\n",
1088 mtk_dbg_r32(MTK_SGMII_EFUSE));
1089 seq_printf(seq, "| SGMII0_RX_CNT : %08x |\n",
1090 mtk_dbg_r32(MTK_SGMII_FALSE_CARRIER_CNT(0)));
1091 seq_printf(seq, "| SGMII1_RX_CNT : %08x |\n",
1092 mtk_dbg_r32(MTK_SGMII_FALSE_CARRIER_CNT(1)));
1093 seq_printf(seq, "| WED_RTQM_GLO : %08x |\n",
1094 mtk_dbg_r32(MTK_WED_RTQM_GLO_CFG));
developerfd40db22021-04-29 10:08:25 +08001095 }
1096
developer8051e042022-04-08 13:26:36 +08001097 mtk_w32(eth, 0xffffffff, MTK_FE_INT_STATUS);
developer089e8852022-09-28 14:43:46 +08001098 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1099 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
developer8051e042022-04-08 13:26:36 +08001100 mtk_w32(eth, 0xffffffff, MTK_FE_INT_STATUS2);
developer77f3fd42021-10-05 15:16:05 +08001101
developerfd40db22021-04-29 10:08:25 +08001102 return 0;
1103}
1104
1105static int dbg_regs_open(struct inode *inode, struct file *file)
1106{
1107 return single_open(file, dbg_regs_read, 0);
1108}
1109
1110static const struct file_operations dbg_regs_fops = {
1111 .owner = THIS_MODULE,
1112 .open = dbg_regs_open,
1113 .read = seq_read,
1114 .llseek = seq_lseek,
developer77d03a72021-06-06 00:06:00 +08001115 .release = single_release
1116};
1117
developere9356982022-07-04 09:03:20 +08001118void hw_lro_stats_update(u32 ring_no, struct mtk_rx_dma_v2 *rxd)
developer77d03a72021-06-06 00:06:00 +08001119{
developere9356982022-07-04 09:03:20 +08001120 struct mtk_eth *eth = g_eth;
developer77d03a72021-06-06 00:06:00 +08001121 u32 idx, agg_cnt, agg_size;
1122
developer089e8852022-09-28 14:43:46 +08001123 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1124 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developere9356982022-07-04 09:03:20 +08001125 idx = ring_no - 4;
1126 agg_cnt = RX_DMA_GET_AGG_CNT_V2(rxd->rxd6);
1127 } else {
1128 idx = ring_no - 1;
1129 agg_cnt = RX_DMA_GET_AGG_CNT(rxd->rxd2);
1130 }
developer77d03a72021-06-06 00:06:00 +08001131
developer8b6f2402022-11-28 13:42:34 +08001132 if (idx >= MTK_HW_LRO_RING_NUM)
1133 return;
1134
developer77d03a72021-06-06 00:06:00 +08001135 agg_size = RX_DMA_GET_PLEN0(rxd->rxd2);
1136
1137 hw_lro_agg_size_cnt[idx][agg_size / 5000]++;
1138 hw_lro_agg_num_cnt[idx][agg_cnt]++;
1139 hw_lro_tot_flush_cnt[idx]++;
1140 hw_lro_tot_agg_cnt[idx] += agg_cnt;
1141}
1142
developere9356982022-07-04 09:03:20 +08001143void hw_lro_flush_stats_update(u32 ring_no, struct mtk_rx_dma_v2 *rxd)
developer77d03a72021-06-06 00:06:00 +08001144{
developere9356982022-07-04 09:03:20 +08001145 struct mtk_eth *eth = g_eth;
developer77d03a72021-06-06 00:06:00 +08001146 u32 idx, flush_reason;
1147
developer089e8852022-09-28 14:43:46 +08001148 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1149 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developere9356982022-07-04 09:03:20 +08001150 idx = ring_no - 4;
1151 flush_reason = RX_DMA_GET_FLUSH_RSN_V2(rxd->rxd6);
1152 } else {
1153 idx = ring_no - 1;
1154 flush_reason = RX_DMA_GET_REV(rxd->rxd2);
1155 }
developer77d03a72021-06-06 00:06:00 +08001156
developer8b6f2402022-11-28 13:42:34 +08001157 if (idx >= MTK_HW_LRO_RING_NUM)
1158 return;
1159
developer77d03a72021-06-06 00:06:00 +08001160 if ((flush_reason & 0x7) == MTK_HW_LRO_AGG_FLUSH)
1161 hw_lro_agg_flush_cnt[idx]++;
1162 else if ((flush_reason & 0x7) == MTK_HW_LRO_AGE_FLUSH)
1163 hw_lro_age_flush_cnt[idx]++;
1164 else if ((flush_reason & 0x7) == MTK_HW_LRO_NOT_IN_SEQ_FLUSH)
1165 hw_lro_seq_flush_cnt[idx]++;
1166 else if ((flush_reason & 0x7) == MTK_HW_LRO_TIMESTAMP_FLUSH)
1167 hw_lro_timestamp_flush_cnt[idx]++;
1168 else if ((flush_reason & 0x7) == MTK_HW_LRO_NON_RULE_FLUSH)
1169 hw_lro_norule_flush_cnt[idx]++;
1170}
1171
1172ssize_t hw_lro_stats_write(struct file *file, const char __user *buffer,
1173 size_t count, loff_t *data)
1174{
1175 memset(hw_lro_agg_num_cnt, 0, sizeof(hw_lro_agg_num_cnt));
1176 memset(hw_lro_agg_size_cnt, 0, sizeof(hw_lro_agg_size_cnt));
1177 memset(hw_lro_tot_agg_cnt, 0, sizeof(hw_lro_tot_agg_cnt));
1178 memset(hw_lro_tot_flush_cnt, 0, sizeof(hw_lro_tot_flush_cnt));
1179 memset(hw_lro_agg_flush_cnt, 0, sizeof(hw_lro_agg_flush_cnt));
1180 memset(hw_lro_age_flush_cnt, 0, sizeof(hw_lro_age_flush_cnt));
1181 memset(hw_lro_seq_flush_cnt, 0, sizeof(hw_lro_seq_flush_cnt));
1182 memset(hw_lro_timestamp_flush_cnt, 0,
1183 sizeof(hw_lro_timestamp_flush_cnt));
1184 memset(hw_lro_norule_flush_cnt, 0, sizeof(hw_lro_norule_flush_cnt));
1185
1186 pr_info("clear hw lro cnt table\n");
1187
1188 return count;
1189}
1190
1191int hw_lro_stats_read_v1(struct seq_file *seq, void *v)
1192{
1193 int i;
1194
1195 seq_puts(seq, "HW LRO statistic dump:\n");
1196
1197 /* Agg number count */
1198 seq_puts(seq, "Cnt: RING1 | RING2 | RING3 | Total\n");
1199 for (i = 0; i <= MTK_HW_LRO_MAX_AGG_CNT; i++) {
1200 seq_printf(seq, " %d : %d %d %d %d\n",
1201 i, hw_lro_agg_num_cnt[0][i],
1202 hw_lro_agg_num_cnt[1][i], hw_lro_agg_num_cnt[2][i],
1203 hw_lro_agg_num_cnt[0][i] + hw_lro_agg_num_cnt[1][i] +
1204 hw_lro_agg_num_cnt[2][i]);
1205 }
1206
1207 /* Total agg count */
1208 seq_puts(seq, "Total agg: RING1 | RING2 | RING3 | Total\n");
1209 seq_printf(seq, " %d %d %d %d\n",
1210 hw_lro_tot_agg_cnt[0], hw_lro_tot_agg_cnt[1],
1211 hw_lro_tot_agg_cnt[2],
1212 hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1213 hw_lro_tot_agg_cnt[2]);
1214
1215 /* Total flush count */
1216 seq_puts(seq, "Total flush: RING1 | RING2 | RING3 | Total\n");
1217 seq_printf(seq, " %d %d %d %d\n",
1218 hw_lro_tot_flush_cnt[0], hw_lro_tot_flush_cnt[1],
1219 hw_lro_tot_flush_cnt[2],
1220 hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1221 hw_lro_tot_flush_cnt[2]);
1222
1223 /* Avg agg count */
1224 seq_puts(seq, "Avg agg: RING1 | RING2 | RING3 | Total\n");
1225 seq_printf(seq, " %d %d %d %d\n",
1226 (hw_lro_tot_flush_cnt[0]) ?
1227 hw_lro_tot_agg_cnt[0] / hw_lro_tot_flush_cnt[0] : 0,
1228 (hw_lro_tot_flush_cnt[1]) ?
1229 hw_lro_tot_agg_cnt[1] / hw_lro_tot_flush_cnt[1] : 0,
1230 (hw_lro_tot_flush_cnt[2]) ?
1231 hw_lro_tot_agg_cnt[2] / hw_lro_tot_flush_cnt[2] : 0,
1232 (hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1233 hw_lro_tot_flush_cnt[2]) ?
1234 ((hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1235 hw_lro_tot_agg_cnt[2]) / (hw_lro_tot_flush_cnt[0] +
1236 hw_lro_tot_flush_cnt[1] + hw_lro_tot_flush_cnt[2])) : 0);
1237
1238 /* Statistics of aggregation size counts */
1239 seq_puts(seq, "HW LRO flush pkt len:\n");
1240 seq_puts(seq, " Length | RING1 | RING2 | RING3 | Total\n");
1241 for (i = 0; i < 15; i++) {
1242 seq_printf(seq, "%d~%d: %d %d %d %d\n", i * 5000,
1243 (i + 1) * 5000, hw_lro_agg_size_cnt[0][i],
1244 hw_lro_agg_size_cnt[1][i], hw_lro_agg_size_cnt[2][i],
1245 hw_lro_agg_size_cnt[0][i] +
1246 hw_lro_agg_size_cnt[1][i] +
1247 hw_lro_agg_size_cnt[2][i]);
1248 }
1249
1250 seq_puts(seq, "Flush reason: RING1 | RING2 | RING3 | Total\n");
1251 seq_printf(seq, "AGG timeout: %d %d %d %d\n",
1252 hw_lro_agg_flush_cnt[0], hw_lro_agg_flush_cnt[1],
1253 hw_lro_agg_flush_cnt[2],
1254 (hw_lro_agg_flush_cnt[0] + hw_lro_agg_flush_cnt[1] +
1255 hw_lro_agg_flush_cnt[2]));
1256
1257 seq_printf(seq, "AGE timeout: %d %d %d %d\n",
1258 hw_lro_age_flush_cnt[0], hw_lro_age_flush_cnt[1],
1259 hw_lro_age_flush_cnt[2],
1260 (hw_lro_age_flush_cnt[0] + hw_lro_age_flush_cnt[1] +
1261 hw_lro_age_flush_cnt[2]));
1262
1263 seq_printf(seq, "Not in-sequence: %d %d %d %d\n",
1264 hw_lro_seq_flush_cnt[0], hw_lro_seq_flush_cnt[1],
1265 hw_lro_seq_flush_cnt[2],
1266 (hw_lro_seq_flush_cnt[0] + hw_lro_seq_flush_cnt[1] +
1267 hw_lro_seq_flush_cnt[2]));
1268
1269 seq_printf(seq, "Timestamp: %d %d %d %d\n",
1270 hw_lro_timestamp_flush_cnt[0],
1271 hw_lro_timestamp_flush_cnt[1],
1272 hw_lro_timestamp_flush_cnt[2],
1273 (hw_lro_timestamp_flush_cnt[0] +
1274 hw_lro_timestamp_flush_cnt[1] +
1275 hw_lro_timestamp_flush_cnt[2]));
1276
1277 seq_printf(seq, "No LRO rule: %d %d %d %d\n",
1278 hw_lro_norule_flush_cnt[0],
1279 hw_lro_norule_flush_cnt[1],
1280 hw_lro_norule_flush_cnt[2],
1281 (hw_lro_norule_flush_cnt[0] +
1282 hw_lro_norule_flush_cnt[1] +
1283 hw_lro_norule_flush_cnt[2]));
1284
1285 return 0;
1286}
1287
1288int hw_lro_stats_read_v2(struct seq_file *seq, void *v)
1289{
1290 int i;
1291
1292 seq_puts(seq, "HW LRO statistic dump:\n");
1293
1294 /* Agg number count */
1295 seq_puts(seq, "Cnt: RING4 | RING5 | RING6 | RING7 Total\n");
1296 for (i = 0; i <= MTK_HW_LRO_MAX_AGG_CNT; i++) {
1297 seq_printf(seq,
1298 " %d : %d %d %d %d %d\n",
1299 i, hw_lro_agg_num_cnt[0][i], hw_lro_agg_num_cnt[1][i],
1300 hw_lro_agg_num_cnt[2][i], hw_lro_agg_num_cnt[3][i],
1301 hw_lro_agg_num_cnt[0][i] + hw_lro_agg_num_cnt[1][i] +
1302 hw_lro_agg_num_cnt[2][i] + hw_lro_agg_num_cnt[3][i]);
1303 }
1304
1305 /* Total agg count */
1306 seq_puts(seq, "Total agg: RING4 | RING5 | RING6 | RING7 Total\n");
1307 seq_printf(seq, " %d %d %d %d %d\n",
1308 hw_lro_tot_agg_cnt[0], hw_lro_tot_agg_cnt[1],
1309 hw_lro_tot_agg_cnt[2], hw_lro_tot_agg_cnt[3],
1310 hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1311 hw_lro_tot_agg_cnt[2] + hw_lro_tot_agg_cnt[3]);
1312
1313 /* Total flush count */
1314 seq_puts(seq, "Total flush: RING4 | RING5 | RING6 | RING7 Total\n");
1315 seq_printf(seq, " %d %d %d %d %d\n",
1316 hw_lro_tot_flush_cnt[0], hw_lro_tot_flush_cnt[1],
1317 hw_lro_tot_flush_cnt[2], hw_lro_tot_flush_cnt[3],
1318 hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1319 hw_lro_tot_flush_cnt[2] + hw_lro_tot_flush_cnt[3]);
1320
1321 /* Avg agg count */
1322 seq_puts(seq, "Avg agg: RING4 | RING5 | RING6 | RING7 Total\n");
1323 seq_printf(seq, " %d %d %d %d %d\n",
1324 (hw_lro_tot_flush_cnt[0]) ?
1325 hw_lro_tot_agg_cnt[0] / hw_lro_tot_flush_cnt[0] : 0,
1326 (hw_lro_tot_flush_cnt[1]) ?
1327 hw_lro_tot_agg_cnt[1] / hw_lro_tot_flush_cnt[1] : 0,
1328 (hw_lro_tot_flush_cnt[2]) ?
1329 hw_lro_tot_agg_cnt[2] / hw_lro_tot_flush_cnt[2] : 0,
1330 (hw_lro_tot_flush_cnt[3]) ?
1331 hw_lro_tot_agg_cnt[3] / hw_lro_tot_flush_cnt[3] : 0,
1332 (hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1333 hw_lro_tot_flush_cnt[2] + hw_lro_tot_flush_cnt[3]) ?
1334 ((hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1335 hw_lro_tot_agg_cnt[2] + hw_lro_tot_agg_cnt[3]) /
1336 (hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1337 hw_lro_tot_flush_cnt[2] + hw_lro_tot_flush_cnt[3])) : 0);
1338
1339 /* Statistics of aggregation size counts */
1340 seq_puts(seq, "HW LRO flush pkt len:\n");
1341 seq_puts(seq, " Length | RING4 | RING5 | RING6 | RING7 Total\n");
1342 for (i = 0; i < 15; i++) {
1343 seq_printf(seq, "%d~%d: %d %d %d %d %d\n",
1344 i * 5000, (i + 1) * 5000,
1345 hw_lro_agg_size_cnt[0][i], hw_lro_agg_size_cnt[1][i],
1346 hw_lro_agg_size_cnt[2][i], hw_lro_agg_size_cnt[3][i],
1347 hw_lro_agg_size_cnt[0][i] +
1348 hw_lro_agg_size_cnt[1][i] +
1349 hw_lro_agg_size_cnt[2][i] +
1350 hw_lro_agg_size_cnt[3][i]);
1351 }
1352
1353 seq_puts(seq, "Flush reason: RING4 | RING5 | RING6 | RING7 Total\n");
1354 seq_printf(seq, "AGG timeout: %d %d %d %d %d\n",
1355 hw_lro_agg_flush_cnt[0], hw_lro_agg_flush_cnt[1],
1356 hw_lro_agg_flush_cnt[2], hw_lro_agg_flush_cnt[3],
1357 (hw_lro_agg_flush_cnt[0] + hw_lro_agg_flush_cnt[1] +
1358 hw_lro_agg_flush_cnt[2] + hw_lro_agg_flush_cnt[3]));
1359
1360 seq_printf(seq, "AGE timeout: %d %d %d %d %d\n",
1361 hw_lro_age_flush_cnt[0], hw_lro_age_flush_cnt[1],
1362 hw_lro_age_flush_cnt[2], hw_lro_age_flush_cnt[3],
1363 (hw_lro_age_flush_cnt[0] + hw_lro_age_flush_cnt[1] +
1364 hw_lro_age_flush_cnt[2] + hw_lro_age_flush_cnt[3]));
1365
1366 seq_printf(seq, "Not in-sequence: %d %d %d %d %d\n",
1367 hw_lro_seq_flush_cnt[0], hw_lro_seq_flush_cnt[1],
1368 hw_lro_seq_flush_cnt[2], hw_lro_seq_flush_cnt[3],
1369 (hw_lro_seq_flush_cnt[0] + hw_lro_seq_flush_cnt[1] +
1370 hw_lro_seq_flush_cnt[2] + hw_lro_seq_flush_cnt[3]));
1371
1372 seq_printf(seq, "Timestamp: %d %d %d %d %d\n",
1373 hw_lro_timestamp_flush_cnt[0],
1374 hw_lro_timestamp_flush_cnt[1],
1375 hw_lro_timestamp_flush_cnt[2],
1376 hw_lro_timestamp_flush_cnt[3],
1377 (hw_lro_timestamp_flush_cnt[0] +
1378 hw_lro_timestamp_flush_cnt[1] +
1379 hw_lro_timestamp_flush_cnt[2] +
1380 hw_lro_timestamp_flush_cnt[3]));
1381
1382 seq_printf(seq, "No LRO rule: %d %d %d %d %d\n",
1383 hw_lro_norule_flush_cnt[0],
1384 hw_lro_norule_flush_cnt[1],
1385 hw_lro_norule_flush_cnt[2],
1386 hw_lro_norule_flush_cnt[3],
1387 (hw_lro_norule_flush_cnt[0] +
1388 hw_lro_norule_flush_cnt[1] +
1389 hw_lro_norule_flush_cnt[2] +
1390 hw_lro_norule_flush_cnt[3]));
1391
1392 return 0;
1393}
1394
1395int hw_lro_stats_read_wrapper(struct seq_file *seq, void *v)
1396{
1397 struct mtk_eth *eth = g_eth;
1398
developer089e8852022-09-28 14:43:46 +08001399 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1400 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
developer77d03a72021-06-06 00:06:00 +08001401 hw_lro_stats_read_v2(seq, v);
1402 else
1403 hw_lro_stats_read_v1(seq, v);
1404
1405 return 0;
1406}
1407
1408static int hw_lro_stats_open(struct inode *inode, struct file *file)
1409{
1410 return single_open(file, hw_lro_stats_read_wrapper, NULL);
1411}
1412
1413static const struct file_operations hw_lro_stats_fops = {
1414 .owner = THIS_MODULE,
1415 .open = hw_lro_stats_open,
1416 .read = seq_read,
1417 .llseek = seq_lseek,
1418 .write = hw_lro_stats_write,
developerfd40db22021-04-29 10:08:25 +08001419 .release = single_release
1420};
1421
developer77d03a72021-06-06 00:06:00 +08001422int hwlro_agg_cnt_ctrl(int cnt)
1423{
1424 int i;
1425
1426 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1427 SET_PDMA_RXRING_MAX_AGG_CNT(g_eth, i, cnt);
1428
1429 return 0;
1430}
1431
1432int hwlro_agg_time_ctrl(int time)
1433{
1434 int i;
1435
1436 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1437 SET_PDMA_RXRING_AGG_TIME(g_eth, i, time);
1438
1439 return 0;
1440}
1441
1442int hwlro_age_time_ctrl(int time)
1443{
1444 int i;
1445
1446 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1447 SET_PDMA_RXRING_AGE_TIME(g_eth, i, time);
1448
1449 return 0;
1450}
1451
1452int hwlro_threshold_ctrl(int bandwidth)
1453{
1454 SET_PDMA_LRO_BW_THRESHOLD(g_eth, bandwidth);
1455
1456 return 0;
1457}
1458
1459int hwlro_ring_enable_ctrl(int enable)
1460{
1461 int i;
1462
1463 pr_info("[%s] %s HW LRO rings\n", __func__, (enable) ? "Enable" : "Disable");
1464
1465 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1466 SET_PDMA_RXRING_VALID(g_eth, i, enable);
1467
1468 return 0;
1469}
1470
1471int hwlro_stats_enable_ctrl(int enable)
1472{
1473 pr_info("[%s] %s HW LRO statistics\n", __func__, (enable) ? "Enable" : "Disable");
1474 mtk_hwlro_stats_ebl = enable;
1475
1476 return 0;
1477}
1478
1479static const mtk_lro_dbg_func lro_dbg_func[] = {
1480 [0] = hwlro_agg_cnt_ctrl,
1481 [1] = hwlro_agg_time_ctrl,
1482 [2] = hwlro_age_time_ctrl,
1483 [3] = hwlro_threshold_ctrl,
1484 [4] = hwlro_ring_enable_ctrl,
1485 [5] = hwlro_stats_enable_ctrl,
1486};
1487
1488ssize_t hw_lro_auto_tlb_write(struct file *file, const char __user *buffer,
1489 size_t count, loff_t *data)
1490{
1491 char buf[32];
1492 char *p_buf;
1493 char *p_token = NULL;
1494 char *p_delimiter = " \t";
1495 long x = 0, y = 0;
developer4c32b7a2021-11-13 16:46:43 +08001496 u32 len = count;
developer77d03a72021-06-06 00:06:00 +08001497 int ret;
1498
1499 if (len >= sizeof(buf)) {
1500 pr_info("Input handling fail!\n");
developer77d03a72021-06-06 00:06:00 +08001501 return -1;
1502 }
1503
1504 if (copy_from_user(buf, buffer, len))
1505 return -EFAULT;
1506
1507 buf[len] = '\0';
1508
1509 p_buf = buf;
1510 p_token = strsep(&p_buf, p_delimiter);
1511 if (!p_token)
1512 x = 0;
1513 else
1514 ret = kstrtol(p_token, 10, &x);
1515
1516 p_token = strsep(&p_buf, "\t\n ");
1517 if (p_token)
1518 ret = kstrtol(p_token, 10, &y);
1519
1520 if (lro_dbg_func[x] && (ARRAY_SIZE(lro_dbg_func) > x))
1521 (*lro_dbg_func[x]) (y);
1522
1523 return count;
1524}
1525
1526void hw_lro_auto_tlb_dump_v1(struct seq_file *seq, u32 index)
1527{
1528 int i;
1529 struct mtk_lro_alt_v1 alt;
1530 __be32 addr;
1531 u32 tlb_info[9];
1532 u32 dw_len, cnt, priority;
1533 u32 entry;
1534
1535 if (index > 4)
1536 index = index - 1;
1537 entry = (index * 9) + 1;
1538
1539 /* read valid entries of the auto-learn table */
1540 mtk_w32(g_eth, entry, MTK_FE_ALT_CF8);
1541
1542 for (i = 0; i < 9; i++)
1543 tlb_info[i] = mtk_r32(g_eth, MTK_FE_ALT_SEQ_CFC);
1544
1545 memcpy(&alt, tlb_info, sizeof(struct mtk_lro_alt_v1));
1546
1547 dw_len = alt.alt_info7.dw_len;
1548 cnt = alt.alt_info6.cnt;
1549
1550 if (mtk_r32(g_eth, MTK_PDMA_LRO_CTRL_DW0) & MTK_LRO_ALT_PKT_CNT_MODE)
1551 priority = cnt; /* packet count */
1552 else
1553 priority = dw_len; /* byte count */
1554
1555 /* dump valid entries of the auto-learn table */
1556 if (index >= 4)
1557 seq_printf(seq, "\n===== TABLE Entry: %d (Act) =====\n", index);
1558 else
1559 seq_printf(seq, "\n===== TABLE Entry: %d (LRU) =====\n", index);
1560
1561 if (alt.alt_info8.ipv4) {
1562 addr = htonl(alt.alt_info1.sip0);
1563 seq_printf(seq, "SIP = %pI4 (IPv4)\n", &addr);
1564 } else {
1565 seq_printf(seq, "SIP = %08X:%08X:%08X:%08X (IPv6)\n",
1566 alt.alt_info4.sip3, alt.alt_info3.sip2,
1567 alt.alt_info2.sip1, alt.alt_info1.sip0);
1568 }
1569
1570 seq_printf(seq, "DIP_ID = %d\n", alt.alt_info8.dip_id);
1571 seq_printf(seq, "TCP SPORT = %d | TCP DPORT = %d\n",
1572 alt.alt_info0.stp, alt.alt_info0.dtp);
1573 seq_printf(seq, "VLAN_VID_VLD = %d\n", alt.alt_info6.vlan_vid_vld);
1574 seq_printf(seq, "VLAN1 = %d | VLAN2 = %d | VLAN3 = %d | VLAN4 =%d\n",
1575 (alt.alt_info5.vlan_vid0 & 0xfff),
1576 ((alt.alt_info5.vlan_vid0 >> 12) & 0xfff),
1577 ((alt.alt_info6.vlan_vid1 << 8) |
1578 ((alt.alt_info5.vlan_vid0 >> 24) & 0xfff)),
1579 ((alt.alt_info6.vlan_vid1 >> 4) & 0xfff));
1580 seq_printf(seq, "TPUT = %d | FREQ = %d\n", dw_len, cnt);
1581 seq_printf(seq, "PRIORITY = %d\n", priority);
1582}
1583
1584void hw_lro_auto_tlb_dump_v2(struct seq_file *seq, u32 index)
1585{
1586 int i;
1587 struct mtk_lro_alt_v2 alt;
1588 u32 score = 0, ipv4 = 0;
1589 u32 ipv6[4] = { 0 };
1590 u32 tlb_info[12];
1591
1592 /* read valid entries of the auto-learn table */
1593 mtk_w32(g_eth, index << MTK_LRO_ALT_INDEX_OFFSET, MTK_LRO_ALT_DBG);
1594
1595 for (i = 0; i < 11; i++)
1596 tlb_info[i] = mtk_r32(g_eth, MTK_LRO_ALT_DBG_DATA);
1597
1598 memcpy(&alt, tlb_info, sizeof(struct mtk_lro_alt_v2));
1599
1600 if (mtk_r32(g_eth, MTK_PDMA_LRO_CTRL_DW0) & MTK_LRO_ALT_PKT_CNT_MODE)
1601 score = 1; /* packet count */
1602 else
1603 score = 0; /* byte count */
1604
1605 /* dump valid entries of the auto-learn table */
1606 if (alt.alt_info0.valid) {
1607 if (index < 5)
1608 seq_printf(seq,
1609 "\n===== TABLE Entry: %d (onging) =====\n",
1610 index);
1611 else
1612 seq_printf(seq,
1613 "\n===== TABLE Entry: %d (candidate) =====\n",
1614 index);
1615
1616 if (alt.alt_info1.v4_valid) {
1617 ipv4 = (alt.alt_info4.sip0_h << 23) |
1618 alt.alt_info5.sip0_l;
1619 seq_printf(seq, "SIP = 0x%x: (IPv4)\n", ipv4);
1620
1621 ipv4 = (alt.alt_info8.dip0_h << 23) |
1622 alt.alt_info9.dip0_l;
1623 seq_printf(seq, "DIP = 0x%x: (IPv4)\n", ipv4);
1624 } else if (alt.alt_info1.v6_valid) {
1625 ipv6[3] = (alt.alt_info1.sip3_h << 23) |
1626 (alt.alt_info2.sip3_l << 9);
1627 ipv6[2] = (alt.alt_info2.sip2_h << 23) |
1628 (alt.alt_info3.sip2_l << 9);
1629 ipv6[1] = (alt.alt_info3.sip1_h << 23) |
1630 (alt.alt_info4.sip1_l << 9);
1631 ipv6[0] = (alt.alt_info4.sip0_h << 23) |
1632 (alt.alt_info5.sip0_l << 9);
1633 seq_printf(seq, "SIP = 0x%x:0x%x:0x%x:0x%x (IPv6)\n",
1634 ipv6[3], ipv6[2], ipv6[1], ipv6[0]);
1635
1636 ipv6[3] = (alt.alt_info5.dip3_h << 23) |
1637 (alt.alt_info6.dip3_l << 9);
1638 ipv6[2] = (alt.alt_info6.dip2_h << 23) |
1639 (alt.alt_info7.dip2_l << 9);
1640 ipv6[1] = (alt.alt_info7.dip1_h << 23) |
1641 (alt.alt_info8.dip1_l << 9);
1642 ipv6[0] = (alt.alt_info8.dip0_h << 23) |
1643 (alt.alt_info9.dip0_l << 9);
1644 seq_printf(seq, "DIP = 0x%x:0x%x:0x%x:0x%x (IPv6)\n",
1645 ipv6[3], ipv6[2], ipv6[1], ipv6[0]);
1646 }
1647
1648 seq_printf(seq, "TCP SPORT = %d | TCP DPORT = %d\n",
1649 (alt.alt_info9.sp_h << 7) | (alt.alt_info10.sp_l),
1650 alt.alt_info10.dp);
1651 }
1652}
1653
1654int hw_lro_auto_tlb_read(struct seq_file *seq, void *v)
1655{
1656 int i;
1657 u32 reg_val;
1658 u32 reg_op1, reg_op2, reg_op3, reg_op4;
1659 u32 agg_cnt, agg_time, age_time;
1660
1661 seq_puts(seq, "Usage of /proc/mtketh/hw_lro_auto_tlb:\n");
1662 seq_puts(seq, "echo [function] [setting] > /proc/mtketh/hw_lro_auto_tlb\n");
1663 seq_puts(seq, "Functions:\n");
1664 seq_puts(seq, "[0] = hwlro_agg_cnt_ctrl\n");
1665 seq_puts(seq, "[1] = hwlro_agg_time_ctrl\n");
1666 seq_puts(seq, "[2] = hwlro_age_time_ctrl\n");
1667 seq_puts(seq, "[3] = hwlro_threshold_ctrl\n");
1668 seq_puts(seq, "[4] = hwlro_ring_enable_ctrl\n");
1669 seq_puts(seq, "[5] = hwlro_stats_enable_ctrl\n\n");
1670
developer089e8852022-09-28 14:43:46 +08001671 if (MTK_HAS_CAPS(g_eth->soc->caps, MTK_NETSYS_V2) ||
1672 MTK_HAS_CAPS(g_eth->soc->caps, MTK_NETSYS_V3)) {
developer77d03a72021-06-06 00:06:00 +08001673 for (i = 1; i <= 8; i++)
1674 hw_lro_auto_tlb_dump_v2(seq, i);
1675 } else {
1676 /* Read valid entries of the auto-learn table */
1677 mtk_w32(g_eth, 0, MTK_FE_ALT_CF8);
1678 reg_val = mtk_r32(g_eth, MTK_FE_ALT_SEQ_CFC);
1679
1680 seq_printf(seq,
1681 "HW LRO Auto-learn Table: (MTK_FE_ALT_SEQ_CFC=0x%x)\n",
1682 reg_val);
1683
1684 for (i = 7; i >= 0; i--) {
1685 if (reg_val & (1 << i))
1686 hw_lro_auto_tlb_dump_v1(seq, i);
1687 }
1688 }
1689
1690 /* Read the agg_time/age_time/agg_cnt of LRO rings */
1691 seq_puts(seq, "\nHW LRO Ring Settings\n");
1692
1693 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++) {
1694 reg_op1 = mtk_r32(g_eth, MTK_LRO_CTRL_DW1_CFG(i));
1695 reg_op2 = mtk_r32(g_eth, MTK_LRO_CTRL_DW2_CFG(i));
1696 reg_op3 = mtk_r32(g_eth, MTK_LRO_CTRL_DW3_CFG(i));
1697 reg_op4 = mtk_r32(g_eth, MTK_PDMA_LRO_CTRL_DW2);
1698
1699 agg_cnt =
1700 ((reg_op3 & 0x3) << 6) |
1701 ((reg_op2 >> MTK_LRO_RING_AGG_CNT_L_OFFSET) & 0x3f);
1702 agg_time = (reg_op2 >> MTK_LRO_RING_AGG_TIME_OFFSET) & 0xffff;
1703 age_time =
1704 ((reg_op2 & 0x3f) << 10) |
1705 ((reg_op1 >> MTK_LRO_RING_AGE_TIME_L_OFFSET) & 0x3ff);
1706 seq_printf(seq,
1707 "Ring[%d]: MAX_AGG_CNT=%d, AGG_TIME=%d, AGE_TIME=%d, Threshold=%d\n",
developer089e8852022-09-28 14:43:46 +08001708 (MTK_HAS_CAPS(g_eth->soc->caps, MTK_NETSYS_V1)) ? i : i+3,
developer77d03a72021-06-06 00:06:00 +08001709 agg_cnt, agg_time, age_time, reg_op4);
1710 }
1711
1712 seq_puts(seq, "\n");
1713
1714 return 0;
1715}
1716
1717static int hw_lro_auto_tlb_open(struct inode *inode, struct file *file)
1718{
1719 return single_open(file, hw_lro_auto_tlb_read, NULL);
1720}
1721
1722static const struct file_operations hw_lro_auto_tlb_fops = {
1723 .owner = THIS_MODULE,
1724 .open = hw_lro_auto_tlb_open,
1725 .read = seq_read,
1726 .llseek = seq_lseek,
1727 .write = hw_lro_auto_tlb_write,
1728 .release = single_release
1729};
developerfd40db22021-04-29 10:08:25 +08001730
developer8051e042022-04-08 13:26:36 +08001731int reset_event_read(struct seq_file *seq, void *v)
1732{
1733 struct mtk_eth *eth = g_eth;
1734 struct mtk_reset_event reset_event = eth->reset_event;
1735
1736 seq_printf(seq, "[Event] [Count]\n");
1737 seq_printf(seq, " FQ Empty: %d\n",
1738 reset_event.count[MTK_EVENT_FQ_EMPTY]);
1739 seq_printf(seq, " TSO Fail: %d\n",
1740 reset_event.count[MTK_EVENT_TSO_FAIL]);
1741 seq_printf(seq, " TSO Illegal: %d\n",
1742 reset_event.count[MTK_EVENT_TSO_ILLEGAL]);
1743 seq_printf(seq, " TSO Align: %d\n",
1744 reset_event.count[MTK_EVENT_TSO_ALIGN]);
1745 seq_printf(seq, " RFIFO OV: %d\n",
1746 reset_event.count[MTK_EVENT_RFIFO_OV]);
1747 seq_printf(seq, " RFIFO UF: %d\n",
1748 reset_event.count[MTK_EVENT_RFIFO_UF]);
1749 seq_printf(seq, " Force: %d\n",
1750 reset_event.count[MTK_EVENT_FORCE]);
1751 seq_printf(seq, "----------------------------\n");
1752 seq_printf(seq, " Warm Cnt: %d\n",
1753 reset_event.count[MTK_EVENT_WARM_CNT]);
1754 seq_printf(seq, " Cold Cnt: %d\n",
1755 reset_event.count[MTK_EVENT_COLD_CNT]);
1756 seq_printf(seq, " Total Cnt: %d\n",
1757 reset_event.count[MTK_EVENT_TOTAL_CNT]);
1758
1759 return 0;
1760}
1761
1762static int reset_event_open(struct inode *inode, struct file *file)
1763{
1764 return single_open(file, reset_event_read, 0);
1765}
1766
1767ssize_t reset_event_write(struct file *file, const char __user *buffer,
1768 size_t count, loff_t *data)
1769{
1770 struct mtk_eth *eth = g_eth;
1771 struct mtk_reset_event *reset_event = &eth->reset_event;
1772
1773 memset(reset_event, 0, sizeof(struct mtk_reset_event));
1774 pr_info("MTK reset event counter is cleared !\n");
1775
1776 return count;
1777}
1778
1779static const struct file_operations reset_event_fops = {
1780 .owner = THIS_MODULE,
1781 .open = reset_event_open,
1782 .read = seq_read,
1783 .llseek = seq_lseek,
1784 .write = reset_event_write,
1785 .release = single_release
1786};
1787
1788
developerfd40db22021-04-29 10:08:25 +08001789struct proc_dir_entry *proc_reg_dir;
developer621ca6b2023-01-11 11:08:46 +08001790static struct proc_dir_entry *proc_esw_cnt, *proc_xfi_cnt,
1791 *proc_dbg_regs, *proc_reset_event;
developerfd40db22021-04-29 10:08:25 +08001792
1793int debug_proc_init(struct mtk_eth *eth)
1794{
1795 g_eth = eth;
1796
1797 if (!proc_reg_dir)
1798 proc_reg_dir = proc_mkdir(PROCREG_DIR, NULL);
1799
1800 proc_tx_ring =
1801 proc_create(PROCREG_TXRING, 0, proc_reg_dir, &tx_ring_fops);
1802 if (!proc_tx_ring)
1803 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_TXRING);
1804
developer8051e042022-04-08 13:26:36 +08001805 proc_hwtx_ring =
1806 proc_create(PROCREG_HWTXRING, 0, proc_reg_dir, &hwtx_ring_fops);
1807 if (!proc_hwtx_ring)
1808 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_HWTXRING);
1809
developerfd40db22021-04-29 10:08:25 +08001810 proc_rx_ring =
1811 proc_create(PROCREG_RXRING, 0, proc_reg_dir, &rx_ring_fops);
1812 if (!proc_rx_ring)
1813 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_RXRING);
1814
1815 proc_esw_cnt =
1816 proc_create(PROCREG_ESW_CNT, 0, proc_reg_dir, &switch_count_fops);
1817 if (!proc_esw_cnt)
1818 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_ESW_CNT);
1819
developer621ca6b2023-01-11 11:08:46 +08001820 if (MTK_HAS_CAPS(g_eth->soc->caps, MTK_NETSYS_V3)) {
1821 proc_xfi_cnt =
1822 proc_create(PROCREG_XFI_CNT, 0,
1823 proc_reg_dir, &xfi_count_fops);
1824 if (!proc_xfi_cnt)
1825 pr_notice("!! FAIL to create %s PROC !!\n",
1826 PROCREG_XFI_CNT);
1827 }
1828
developerfd40db22021-04-29 10:08:25 +08001829 proc_dbg_regs =
1830 proc_create(PROCREG_DBG_REGS, 0, proc_reg_dir, &dbg_regs_fops);
1831 if (!proc_dbg_regs)
1832 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_DBG_REGS);
1833
developer77d03a72021-06-06 00:06:00 +08001834 if (g_eth->hwlro) {
1835 proc_hw_lro_stats =
1836 proc_create(PROCREG_HW_LRO_STATS, 0, proc_reg_dir,
1837 &hw_lro_stats_fops);
1838 if (!proc_hw_lro_stats)
1839 pr_info("!! FAIL to create %s PROC !!\n", PROCREG_HW_LRO_STATS);
1840
1841 proc_hw_lro_auto_tlb =
1842 proc_create(PROCREG_HW_LRO_AUTO_TLB, 0, proc_reg_dir,
1843 &hw_lro_auto_tlb_fops);
1844 if (!proc_hw_lro_auto_tlb)
1845 pr_info("!! FAIL to create %s PROC !!\n",
1846 PROCREG_HW_LRO_AUTO_TLB);
1847 }
1848
developer8051e042022-04-08 13:26:36 +08001849 proc_reset_event =
1850 proc_create(PROCREG_RESET_EVENT, 0, proc_reg_dir, &reset_event_fops);
1851 if (!proc_reset_event)
1852 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_RESET_EVENT);
1853
developerfd40db22021-04-29 10:08:25 +08001854 return 0;
1855}
1856
1857void debug_proc_exit(void)
1858{
1859 if (proc_tx_ring)
1860 remove_proc_entry(PROCREG_TXRING, proc_reg_dir);
developer8051e042022-04-08 13:26:36 +08001861 if (proc_hwtx_ring)
1862 remove_proc_entry(PROCREG_HWTXRING, proc_reg_dir);
developerfd40db22021-04-29 10:08:25 +08001863 if (proc_rx_ring)
1864 remove_proc_entry(PROCREG_RXRING, proc_reg_dir);
1865
1866 if (proc_esw_cnt)
1867 remove_proc_entry(PROCREG_ESW_CNT, proc_reg_dir);
1868
developer621ca6b2023-01-11 11:08:46 +08001869 if (proc_xfi_cnt)
1870 remove_proc_entry(PROCREG_XFI_CNT, proc_reg_dir);
1871
developerfd40db22021-04-29 10:08:25 +08001872 if (proc_reg_dir)
1873 remove_proc_entry(PROCREG_DIR, 0);
1874
1875 if (proc_dbg_regs)
1876 remove_proc_entry(PROCREG_DBG_REGS, proc_reg_dir);
developer77d03a72021-06-06 00:06:00 +08001877
1878 if (g_eth->hwlro) {
1879 if (proc_hw_lro_stats)
1880 remove_proc_entry(PROCREG_HW_LRO_STATS, proc_reg_dir);
1881
1882 if (proc_hw_lro_auto_tlb)
1883 remove_proc_entry(PROCREG_HW_LRO_AUTO_TLB, proc_reg_dir);
1884 }
developer8051e042022-04-08 13:26:36 +08001885
1886 if (proc_reset_event)
1887 remove_proc_entry(PROCREG_RESET_EVENT, proc_reg_dir);
developerfd40db22021-04-29 10:08:25 +08001888}
1889