blob: 5ad864557d1647bfdea15f4c6a35d61ac305efb3 [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;
268 u32 reg, value, phy;
269 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;
317 u32 reg, value, phy;
318 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:
381 if (atomic_read(&reset_lock) == 0)
382 atomic_inc(&reset_lock);
383 break;
384 case 1:
385 if (atomic_read(&force) == 0)
386 atomic_inc(&force);
387 schedule_work(&eth->pending_work);
388 break;
389 case 2:
390 if (atomic_read(&reset_lock) == 1)
391 atomic_dec(&reset_lock);
392 break;
393 default:
394 pr_info("Usage: echo [level] > /sys/kernel/debug/mtketh/reset\n");
395 pr_info("Commands: [level] \n");
396 pr_info(" 0 disable reset \n");
397 pr_info(" 1 force reset \n");
398 pr_info(" 2 enable reset\n");
399 break;
400 }
401 return count;
developerfd40db22021-04-29 10:08:25 +0800402}
403
404static const struct file_operations fops_reg_w = {
405 .owner = THIS_MODULE,
406 .open = simple_open,
407 .write = mtketh_debugfs_write,
408 .llseek = noop_llseek,
409};
410
411static const struct file_operations fops_eth_reset = {
412 .owner = THIS_MODULE,
413 .open = simple_open,
414 .write = mtketh_debugfs_reset,
415 .llseek = noop_llseek,
416};
417
418static const struct file_operations fops_mt7530sw_reg_w = {
419 .owner = THIS_MODULE,
420 .open = simple_open,
421 .write = mtketh_mt7530sw_debugfs_write,
422 .llseek = noop_llseek,
423};
424
425void mtketh_debugfs_exit(struct mtk_eth *eth)
426{
427 debugfs_remove_recursive(eth_debug.root);
428}
429
430int mtketh_debugfs_init(struct mtk_eth *eth)
431{
432 int ret = 0;
433
434 eth_debug.root = debugfs_create_dir("mtketh", NULL);
435 if (!eth_debug.root) {
436 dev_notice(eth->dev, "%s:err at %d\n", __func__, __LINE__);
437 ret = -ENOMEM;
438 }
439
440 debugfs_create_file("phy_regs", S_IRUGO,
441 eth_debug.root, eth, &mtketh_debug_fops);
442 debugfs_create_file("phy_reg_w", S_IFREG | S_IWUSR,
443 eth_debug.root, eth, &fops_reg_w);
444 debugfs_create_file("reset", S_IFREG | S_IWUSR,
445 eth_debug.root, eth, &fops_eth_reset);
446 if (mt7530_exist(eth)) {
447 debugfs_create_file("mt7530sw_regs", S_IRUGO,
448 eth_debug.root, eth,
449 &mtketh_debug_mt7530sw_fops);
450 debugfs_create_file("mt7530sw_reg_w", S_IFREG | S_IWUSR,
451 eth_debug.root, eth,
452 &fops_mt7530sw_reg_w);
453 }
454 return ret;
455}
456
457void mii_mgr_read_combine(struct mtk_eth *eth, u32 phy_addr, u32 phy_register,
458 u32 *read_data)
459{
460 if (mt7530_exist(eth) && phy_addr == 31)
461 *read_data = mt7530_mdio_r32(eth, phy_register);
462
463 else
developer089e8852022-09-28 14:43:46 +0800464 *read_data = mdiobus_read(eth->mii_bus, phy_addr, phy_register);
developerfd40db22021-04-29 10:08:25 +0800465}
466
developer3957a912021-05-13 16:44:31 +0800467void mii_mgr_write_combine(struct mtk_eth *eth, u16 phy_addr, u16 phy_register,
developerfd40db22021-04-29 10:08:25 +0800468 u32 write_data)
469{
470 if (mt7530_exist(eth) && phy_addr == 31)
471 mt7530_mdio_w32(eth, phy_register, write_data);
472
473 else
developer089e8852022-09-28 14:43:46 +0800474 mdiobus_write(eth->mii_bus, phy_addr, phy_register, write_data);
developerfd40db22021-04-29 10:08:25 +0800475}
476
developer3957a912021-05-13 16:44:31 +0800477static void mii_mgr_read_cl45(struct mtk_eth *eth, u16 port, u16 devad, u16 reg, u16 *data)
developerfd40db22021-04-29 10:08:25 +0800478{
developer089e8852022-09-28 14:43:46 +0800479 *data = mdiobus_read(eth->mii_bus, port, mdiobus_c45_addr(devad, reg));
developerfd40db22021-04-29 10:08:25 +0800480}
481
developer3957a912021-05-13 16:44:31 +0800482static void mii_mgr_write_cl45(struct mtk_eth *eth, u16 port, u16 devad, u16 reg, u16 data)
developerfd40db22021-04-29 10:08:25 +0800483{
developer089e8852022-09-28 14:43:46 +0800484 mdiobus_write(eth->mii_bus, port, mdiobus_c45_addr(devad, reg), data);
developerfd40db22021-04-29 10:08:25 +0800485}
486
487int mtk_do_priv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
488{
489 struct mtk_mac *mac = netdev_priv(dev);
490 struct mtk_eth *eth = mac->hw;
491 struct mtk_mii_ioctl_data mii;
492 struct mtk_esw_reg reg;
developerba2d1eb2021-05-25 19:26:45 +0800493 u16 val;
developerfd40db22021-04-29 10:08:25 +0800494
495 switch (cmd) {
496 case MTKETH_MII_READ:
497 if (copy_from_user(&mii, ifr->ifr_data, sizeof(mii)))
498 goto err_copy;
499 mii_mgr_read_combine(eth, mii.phy_id, mii.reg_num,
500 &mii.val_out);
501 if (copy_to_user(ifr->ifr_data, &mii, sizeof(mii)))
502 goto err_copy;
503
504 return 0;
505 case MTKETH_MII_WRITE:
506 if (copy_from_user(&mii, ifr->ifr_data, sizeof(mii)))
507 goto err_copy;
508 mii_mgr_write_combine(eth, mii.phy_id, mii.reg_num,
509 mii.val_in);
developerfd40db22021-04-29 10:08:25 +0800510 return 0;
511 case MTKETH_MII_READ_CL45:
512 if (copy_from_user(&mii, ifr->ifr_data, sizeof(mii)))
513 goto err_copy;
developer3957a912021-05-13 16:44:31 +0800514 mii_mgr_read_cl45(eth,
515 mdio_phy_id_prtad(mii.phy_id),
516 mdio_phy_id_devad(mii.phy_id),
517 mii.reg_num,
developerba2d1eb2021-05-25 19:26:45 +0800518 &val);
519 mii.val_out = val;
developerfd40db22021-04-29 10:08:25 +0800520 if (copy_to_user(ifr->ifr_data, &mii, sizeof(mii)))
521 goto err_copy;
522
523 return 0;
524 case MTKETH_MII_WRITE_CL45:
525 if (copy_from_user(&mii, ifr->ifr_data, sizeof(mii)))
526 goto err_copy;
developerba2d1eb2021-05-25 19:26:45 +0800527 val = mii.val_in;
developer3957a912021-05-13 16:44:31 +0800528 mii_mgr_write_cl45(eth,
529 mdio_phy_id_prtad(mii.phy_id),
530 mdio_phy_id_devad(mii.phy_id),
531 mii.reg_num,
developerba2d1eb2021-05-25 19:26:45 +0800532 val);
developerfd40db22021-04-29 10:08:25 +0800533 return 0;
534 case MTKETH_ESW_REG_READ:
535 if (!mt7530_exist(eth))
536 return -EOPNOTSUPP;
537 if (copy_from_user(&reg, ifr->ifr_data, sizeof(reg)))
538 goto err_copy;
539 if (reg.off > REG_ESW_MAX)
540 return -EINVAL;
541 reg.val = mtk_switch_r32(eth, reg.off);
542
543 if (copy_to_user(ifr->ifr_data, &reg, sizeof(reg)))
544 goto err_copy;
545
546 return 0;
547 case MTKETH_ESW_REG_WRITE:
548 if (!mt7530_exist(eth))
549 return -EOPNOTSUPP;
550 if (copy_from_user(&reg, ifr->ifr_data, sizeof(reg)))
551 goto err_copy;
552 if (reg.off > REG_ESW_MAX)
553 return -EINVAL;
554 mtk_switch_w32(eth, reg.val, reg.off);
555
556 return 0;
557 default:
558 break;
559 }
560
561 return -EOPNOTSUPP;
562err_copy:
563 return -EFAULT;
564}
565
developer089e8852022-09-28 14:43:46 +0800566static void gdm_reg_dump_v3(struct mtk_eth *eth, u32 gdm_id, u32 mib_base)
567{
568 pr_info("| GDMA%d_RX_GBCNT : %010u (Rx Good Bytes) |\n",
569 gdm_id, mtk_r32(eth, mib_base));
570 pr_info("| GDMA%d_RX_GPCNT : %010u (Rx Good Pkts) |\n",
571 gdm_id, mtk_r32(eth, mib_base + 0x08));
572 pr_info("| GDMA%d_RX_OERCNT : %010u (overflow error) |\n",
573 gdm_id, mtk_r32(eth, mib_base + 0x10));
574 pr_info("| GDMA%d_RX_FERCNT : %010u (FCS error) |\n",
575 gdm_id, mtk_r32(eth, mib_base + 0x14));
576 pr_info("| GDMA%d_RX_SERCNT : %010u (too short) |\n",
577 gdm_id, mtk_r32(eth, mib_base + 0x18));
578 pr_info("| GDMA%d_RX_LERCNT : %010u (too long) |\n",
579 gdm_id, mtk_r32(eth, mib_base + 0x1C));
580 pr_info("| GDMA%d_RX_CERCNT : %010u (checksum error) |\n",
581 gdm_id, mtk_r32(eth, mib_base + 0x20));
582 pr_info("| GDMA%d_RX_FCCNT : %010u (flow control) |\n",
583 gdm_id, mtk_r32(eth, mib_base + 0x24));
584 pr_info("| GDMA%d_RX_VDPCNT : %010u (VID drop) |\n",
585 gdm_id, mtk_r32(eth, mib_base + 0x28));
586 pr_info("| GDMA%d_RX_PFCCNT : %010u (priority flow control)\n",
587 gdm_id, mtk_r32(eth, mib_base + 0x2C));
588 pr_info("| GDMA%d_TX_GBCNT : %010u (Tx Good Bytes) |\n",
589 gdm_id, mtk_r32(eth, mib_base + 0x40));
590 pr_info("| GDMA%d_TX_GPCNT : %010u (Tx Good Pkts) |\n",
591 gdm_id, mtk_r32(eth, mib_base + 0x48));
592 pr_info("| GDMA%d_TX_SKIPCNT: %010u (abort count) |\n",
593 gdm_id, mtk_r32(eth, mib_base + 0x50));
594 pr_info("| GDMA%d_TX_COLCNT : %010u (collision count)|\n",
595 gdm_id, mtk_r32(eth, mib_base + 0x54));
596 pr_info("| GDMA%d_TX_OERCNT : %010u (overflow error) |\n",
597 gdm_id, mtk_r32(eth, mib_base + 0x58));
598 pr_info("| GDMA%d_TX_FCCNT : %010u (flow control) |\n",
599 gdm_id, mtk_r32(eth, mib_base + 0x60));
600 pr_info("| GDMA%d_TX_PFCCNT : %010u (priority flow control)\n",
601 gdm_id, mtk_r32(eth, mib_base + 0x64));
602 pr_info("| |\n");
603}
604
605static void gdm_reg_dump_v2(struct mtk_eth *eth, u32 gdm_id, u32 mib_base)
606{
607 pr_info("| GDMA%d_RX_GBCNT : %010u (Rx Good Bytes) |\n",
608 gdm_id, mtk_r32(eth, mib_base));
609 pr_info("| GDMA%d_RX_GPCNT : %010u (Rx Good Pkts) |\n",
610 gdm_id, mtk_r32(eth, mib_base + 0x08));
611 pr_info("| GDMA%d_RX_OERCNT : %010u (overflow error) |\n",
612 gdm_id, mtk_r32(eth, mib_base + 0x10));
613 pr_info("| GDMA%d_RX_FERCNT : %010u (FCS error) |\n",
614 gdm_id, mtk_r32(eth, mib_base + 0x14));
615 pr_info("| GDMA%d_RX_SERCNT : %010u (too short) |\n",
616 gdm_id, mtk_r32(eth, mib_base + 0x18));
617 pr_info("| GDMA%d_RX_LERCNT : %010u (too long) |\n",
618 gdm_id, mtk_r32(eth, mib_base + 0x1C));
619 pr_info("| GDMA%d_RX_CERCNT : %010u (checksum error) |\n",
620 gdm_id, mtk_r32(eth, mib_base + 0x20));
621 pr_info("| GDMA%d_RX_FCCNT : %010u (flow control) |\n",
622 gdm_id, mtk_r32(eth, mib_base + 0x24));
623 pr_info("| GDMA%d_TX_SKIPCNT: %010u (abort count) |\n",
624 gdm_id, mtk_r32(eth, mib_base + 0x28));
625 pr_info("| GDMA%d_TX_COLCNT : %010u (collision count) |\n",
626 gdm_id, mtk_r32(eth, mib_base + 0x2C));
627 pr_info("| GDMA%d_TX_GBCNT : %010u (Tx Good Bytes) |\n",
628 gdm_id, mtk_r32(eth, mib_base + 0x30));
629 pr_info("| GDMA%d_TX_GPCNT : %010u (Tx Good Pkts) |\n",
630 gdm_id, mtk_r32(eth, mib_base + 0x38));
631 pr_info("| |\n");
632}
633
634static void gdm_cnt_read(struct mtk_eth *eth)
635{
636 u32 i, mib_base;
637
638 pr_info("\n <<CPU>>\n");
639 pr_info(" |\n");
640 pr_info("+-----------------------------------------------+\n");
641 pr_info("| <<PSE>> |\n");
642 pr_info("+-----------------------------------------------+\n");
643 pr_info(" |\n");
644 pr_info("+-----------------------------------------------+\n");
645 pr_info("| <<GDMA>> |\n");
646
647 for (i = 0; i < MTK_MAC_COUNT; i++) {
648 mib_base = MTK_GDM1_TX_GBCNT + MTK_STAT_OFFSET * i;
649
650 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
651 gdm_reg_dump_v3(eth, i + 1, mib_base);
652 else
653 gdm_reg_dump_v2(eth, i + 1, mib_base);
654 }
655
656 pr_info("+-----------------------------------------------+\n");
657}
658
developer9ccff342022-10-13 18:28:54 +0800659void dump_each_port(struct seq_file *seq, struct mtk_eth *eth, u32 base)
660{
661 u32 pkt_cnt = 0;
662 int i = 0;
663
664 for (i = 0; i < 7; i++) {
665 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
666 if ((base == 0x402C) && (i == 6))
667 base = 0x408C;
668 else if ((base == 0x408C) && (i == 6))
669 base = 0x402C;
670 else
671 ;
672 }
673 pkt_cnt = mt7530_mdio_r32(eth, (base) + (i * 0x100));
674 seq_printf(seq, "%8u ", pkt_cnt);
675 }
676 seq_puts(seq, "\n");
677}
678
developerfd40db22021-04-29 10:08:25 +0800679int esw_cnt_read(struct seq_file *seq, void *v)
680{
681 unsigned int pkt_cnt = 0;
682 int i = 0;
683 struct mtk_eth *eth = g_eth;
developerfd40db22021-04-29 10:08:25 +0800684
developer089e8852022-09-28 14:43:46 +0800685 gdm_cnt_read(eth);
developerfd40db22021-04-29 10:08:25 +0800686
687 if (!mt7530_exist(eth))
688 return 0;
689
developer089e8852022-09-28 14:43:46 +0800690 mt798x_iomap();
691
developerfd40db22021-04-29 10:08:25 +0800692 seq_printf(seq, "===================== %8s %8s %8s %8s %8s %8s %8s\n",
693 "Port0", "Port1", "Port2", "Port3", "Port4", "Port5",
694 "Port6");
695 seq_puts(seq, "Tx Drop Packet :");
developer9ccff342022-10-13 18:28:54 +0800696 dump_each_port(seq, eth, 0x4000);
developerfd40db22021-04-29 10:08:25 +0800697 seq_puts(seq, "Tx CRC Error :");
developer9ccff342022-10-13 18:28:54 +0800698 dump_each_port(seq, eth, 0x4004);
developerfd40db22021-04-29 10:08:25 +0800699 seq_puts(seq, "Tx Unicast Packet :");
developer9ccff342022-10-13 18:28:54 +0800700 dump_each_port(seq, eth, 0x4008);
developerfd40db22021-04-29 10:08:25 +0800701 seq_puts(seq, "Tx Multicast Packet :");
developer9ccff342022-10-13 18:28:54 +0800702 dump_each_port(seq, eth, 0x400C);
developerfd40db22021-04-29 10:08:25 +0800703 seq_puts(seq, "Tx Broadcast Packet :");
developer9ccff342022-10-13 18:28:54 +0800704 dump_each_port(seq, eth, 0x4010);
developerfd40db22021-04-29 10:08:25 +0800705 seq_puts(seq, "Tx Collision Event :");
developer9ccff342022-10-13 18:28:54 +0800706 dump_each_port(seq, eth, 0x4014);
developerfd40db22021-04-29 10:08:25 +0800707 seq_puts(seq, "Tx Pause Packet :");
developer9ccff342022-10-13 18:28:54 +0800708 dump_each_port(seq, eth, 0x402C);
developerfd40db22021-04-29 10:08:25 +0800709 seq_puts(seq, "Rx Drop Packet :");
developer9ccff342022-10-13 18:28:54 +0800710 dump_each_port(seq, eth, 0x4060);
developerfd40db22021-04-29 10:08:25 +0800711 seq_puts(seq, "Rx Filtering Packet :");
developer9ccff342022-10-13 18:28:54 +0800712 dump_each_port(seq, eth, 0x4064);
developerfd40db22021-04-29 10:08:25 +0800713 seq_puts(seq, "Rx Unicast Packet :");
developer9ccff342022-10-13 18:28:54 +0800714 dump_each_port(seq, eth, 0x4068);
developerfd40db22021-04-29 10:08:25 +0800715 seq_puts(seq, "Rx Multicast Packet :");
developer9ccff342022-10-13 18:28:54 +0800716 dump_each_port(seq, eth, 0x406C);
developerfd40db22021-04-29 10:08:25 +0800717 seq_puts(seq, "Rx Broadcast Packet :");
developer9ccff342022-10-13 18:28:54 +0800718 dump_each_port(seq, eth, 0x4070);
developerfd40db22021-04-29 10:08:25 +0800719 seq_puts(seq, "Rx Alignment Error :");
developer9ccff342022-10-13 18:28:54 +0800720 dump_each_port(seq, eth, 0x4074);
developerfd40db22021-04-29 10:08:25 +0800721 seq_puts(seq, "Rx CRC Error :");
developer9ccff342022-10-13 18:28:54 +0800722 dump_each_port(seq, eth, 0x4078);
developerfd40db22021-04-29 10:08:25 +0800723 seq_puts(seq, "Rx Undersize Error :");
developer9ccff342022-10-13 18:28:54 +0800724 dump_each_port(seq, eth, 0x407C);
developerfd40db22021-04-29 10:08:25 +0800725 seq_puts(seq, "Rx Fragment Error :");
developer9ccff342022-10-13 18:28:54 +0800726 dump_each_port(seq, eth, 0x4080);
developerfd40db22021-04-29 10:08:25 +0800727 seq_puts(seq, "Rx Oversize Error :");
developer9ccff342022-10-13 18:28:54 +0800728 dump_each_port(seq, eth, 0x4084);
developerfd40db22021-04-29 10:08:25 +0800729 seq_puts(seq, "Rx Jabber Error :");
developer9ccff342022-10-13 18:28:54 +0800730 dump_each_port(seq, eth, 0x4088);
developerfd40db22021-04-29 10:08:25 +0800731 seq_puts(seq, "Rx Pause Packet :");
developer9ccff342022-10-13 18:28:54 +0800732 dump_each_port(seq, eth, 0x408C);
developerfd40db22021-04-29 10:08:25 +0800733 mt7530_mdio_w32(eth, 0x4fe0, 0xf0);
734 mt7530_mdio_w32(eth, 0x4fe0, 0x800000f0);
735
736 seq_puts(seq, "\n");
737
developer089e8852022-09-28 14:43:46 +0800738 mt798x_iounmap();
739
developerfd40db22021-04-29 10:08:25 +0800740 return 0;
741}
742
743static int switch_count_open(struct inode *inode, struct file *file)
744{
745 return single_open(file, esw_cnt_read, 0);
746}
747
748static const struct file_operations switch_count_fops = {
749 .owner = THIS_MODULE,
750 .open = switch_count_open,
751 .read = seq_read,
752 .llseek = seq_lseek,
753 .release = single_release
754};
755
developer8051e042022-04-08 13:26:36 +0800756static struct proc_dir_entry *proc_tx_ring, *proc_hwtx_ring, *proc_rx_ring;
developerfd40db22021-04-29 10:08:25 +0800757
758int tx_ring_read(struct seq_file *seq, void *v)
759{
developere9356982022-07-04 09:03:20 +0800760 struct mtk_eth *eth = g_eth;
developerfd40db22021-04-29 10:08:25 +0800761 struct mtk_tx_ring *ring = &g_eth->tx_ring;
developere9356982022-07-04 09:03:20 +0800762 struct mtk_tx_dma_v2 *tx_ring;
developerfd40db22021-04-29 10:08:25 +0800763 int i = 0;
764
developerfd40db22021-04-29 10:08:25 +0800765 seq_printf(seq, "free count = %d\n", (int)atomic_read(&ring->free_count));
766 seq_printf(seq, "cpu next free: %d\n", (int)(ring->next_free - ring->dma));
767 seq_printf(seq, "cpu last free: %d\n", (int)(ring->last_free - ring->dma));
768 for (i = 0; i < MTK_DMA_SIZE; i++) {
developere9356982022-07-04 09:03:20 +0800769 dma_addr_t tmp = ring->phys + i * eth->soc->txrx.txd_size;
770
771 tx_ring = ring->dma + i * eth->soc->txrx.txd_size;
developerfd40db22021-04-29 10:08:25 +0800772
773 seq_printf(seq, "%d (%pad): %08x %08x %08x %08x", i, &tmp,
developere9356982022-07-04 09:03:20 +0800774 tx_ring->txd1, tx_ring->txd2,
775 tx_ring->txd3, tx_ring->txd4);
776
developer089e8852022-09-28 14:43:46 +0800777 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
778 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developere9356982022-07-04 09:03:20 +0800779 seq_printf(seq, " %08x %08x %08x %08x",
780 tx_ring->txd5, tx_ring->txd6,
781 tx_ring->txd7, tx_ring->txd8);
782 }
783
developerfd40db22021-04-29 10:08:25 +0800784 seq_printf(seq, "\n");
785 }
786
developerfd40db22021-04-29 10:08:25 +0800787 return 0;
788}
789
790static int tx_ring_open(struct inode *inode, struct file *file)
791{
792 return single_open(file, tx_ring_read, NULL);
793}
794
795static const struct file_operations tx_ring_fops = {
796 .owner = THIS_MODULE,
797 .open = tx_ring_open,
798 .read = seq_read,
799 .llseek = seq_lseek,
800 .release = single_release
801};
802
developer8051e042022-04-08 13:26:36 +0800803int hwtx_ring_read(struct seq_file *seq, void *v)
804{
805 struct mtk_eth *eth = g_eth;
developere9356982022-07-04 09:03:20 +0800806 struct mtk_tx_dma_v2 *hwtx_ring;
developer8051e042022-04-08 13:26:36 +0800807 int i = 0;
808
developer8051e042022-04-08 13:26:36 +0800809 for (i = 0; i < MTK_DMA_SIZE; i++) {
developere9356982022-07-04 09:03:20 +0800810 dma_addr_t addr = eth->phy_scratch_ring + i * eth->soc->txrx.txd_size;
811
812 hwtx_ring = eth->scratch_ring + i * eth->soc->txrx.txd_size;
developer8051e042022-04-08 13:26:36 +0800813
814 seq_printf(seq, "%d (%pad): %08x %08x %08x %08x", i, &addr,
developere9356982022-07-04 09:03:20 +0800815 hwtx_ring->txd1, hwtx_ring->txd2,
816 hwtx_ring->txd3, hwtx_ring->txd4);
817
developer089e8852022-09-28 14:43:46 +0800818 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
819 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developere9356982022-07-04 09:03:20 +0800820 seq_printf(seq, " %08x %08x %08x %08x",
821 hwtx_ring->txd5, hwtx_ring->txd6,
822 hwtx_ring->txd7, hwtx_ring->txd8);
823 }
824
developer8051e042022-04-08 13:26:36 +0800825 seq_printf(seq, "\n");
826 }
827
developer8051e042022-04-08 13:26:36 +0800828 return 0;
829}
830
831static int hwtx_ring_open(struct inode *inode, struct file *file)
832{
833 return single_open(file, hwtx_ring_read, NULL);
834}
835
836static const struct file_operations hwtx_ring_fops = {
837 .owner = THIS_MODULE,
838 .open = hwtx_ring_open,
839 .read = seq_read,
840 .llseek = seq_lseek,
841 .release = single_release
842};
843
developerfd40db22021-04-29 10:08:25 +0800844int rx_ring_read(struct seq_file *seq, void *v)
845{
developere9356982022-07-04 09:03:20 +0800846 struct mtk_eth *eth = g_eth;
developerfd40db22021-04-29 10:08:25 +0800847 struct mtk_rx_ring *ring = &g_eth->rx_ring[0];
developere9356982022-07-04 09:03:20 +0800848 struct mtk_rx_dma_v2 *rx_ring;
developerfd40db22021-04-29 10:08:25 +0800849 int i = 0;
850
developerfd40db22021-04-29 10:08:25 +0800851 seq_printf(seq, "next to read: %d\n",
852 NEXT_DESP_IDX(ring->calc_idx, MTK_DMA_SIZE));
853 for (i = 0; i < MTK_DMA_SIZE; i++) {
developere9356982022-07-04 09:03:20 +0800854 rx_ring = ring->dma + i * eth->soc->txrx.rxd_size;
855
developerfd40db22021-04-29 10:08:25 +0800856 seq_printf(seq, "%d: %08x %08x %08x %08x", i,
developere9356982022-07-04 09:03:20 +0800857 rx_ring->rxd1, rx_ring->rxd2,
858 rx_ring->rxd3, rx_ring->rxd4);
859
developer089e8852022-09-28 14:43:46 +0800860 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
861 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developere9356982022-07-04 09:03:20 +0800862 seq_printf(seq, " %08x %08x %08x %08x",
863 rx_ring->rxd5, rx_ring->rxd6,
864 rx_ring->rxd7, rx_ring->rxd8);
865 }
866
developerfd40db22021-04-29 10:08:25 +0800867 seq_printf(seq, "\n");
868 }
869
developerfd40db22021-04-29 10:08:25 +0800870 return 0;
871}
872
873static int rx_ring_open(struct inode *inode, struct file *file)
874{
875 return single_open(file, rx_ring_read, NULL);
876}
877
878static const struct file_operations rx_ring_fops = {
879 .owner = THIS_MODULE,
880 .open = rx_ring_open,
881 .read = seq_read,
882 .llseek = seq_lseek,
883 .release = single_release
884};
885
developer77f3fd42021-10-05 15:16:05 +0800886static inline u32 mtk_dbg_r32(u32 reg)
887{
888 void __iomem *virt_reg;
889 u32 val;
890
891 virt_reg = ioremap(reg, 32);
892 val = __raw_readl(virt_reg);
893 iounmap(virt_reg);
894
895 return val;
896}
897
developerfd40db22021-04-29 10:08:25 +0800898int dbg_regs_read(struct seq_file *seq, void *v)
899{
900 struct mtk_eth *eth = g_eth;
901
developer77f3fd42021-10-05 15:16:05 +0800902 seq_puts(seq, " <<DEBUG REG DUMP>>\n");
903
904 seq_printf(seq, "| FE_INT_STA : %08x |\n",
developer8051e042022-04-08 13:26:36 +0800905 mtk_r32(eth, MTK_FE_INT_STATUS));
developer089e8852022-09-28 14:43:46 +0800906 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
907 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
developer77f3fd42021-10-05 15:16:05 +0800908 seq_printf(seq, "| FE_INT_STA2 : %08x |\n",
developer8051e042022-04-08 13:26:36 +0800909 mtk_r32(eth, MTK_FE_INT_STATUS2));
developer77f3fd42021-10-05 15:16:05 +0800910
developerfd40db22021-04-29 10:08:25 +0800911 seq_printf(seq, "| PSE_FQFC_CFG : %08x |\n",
912 mtk_r32(eth, MTK_PSE_FQFC_CFG));
913 seq_printf(seq, "| PSE_IQ_STA1 : %08x |\n",
914 mtk_r32(eth, MTK_PSE_IQ_STA(0)));
915 seq_printf(seq, "| PSE_IQ_STA2 : %08x |\n",
916 mtk_r32(eth, MTK_PSE_IQ_STA(1)));
917
developer089e8852022-09-28 14:43:46 +0800918 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
919 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developerfd40db22021-04-29 10:08:25 +0800920 seq_printf(seq, "| PSE_IQ_STA3 : %08x |\n",
921 mtk_r32(eth, MTK_PSE_IQ_STA(2)));
922 seq_printf(seq, "| PSE_IQ_STA4 : %08x |\n",
923 mtk_r32(eth, MTK_PSE_IQ_STA(3)));
developer77f3fd42021-10-05 15:16:05 +0800924 seq_printf(seq, "| PSE_IQ_STA5 : %08x |\n",
925 mtk_r32(eth, MTK_PSE_IQ_STA(4)));
developer089e8852022-09-28 14:43:46 +0800926 seq_printf(seq, "| PSE_IQ_STA6 : %08x |\n",
927 mtk_r32(eth, MTK_PSE_IQ_STA(5)));
928 seq_printf(seq, "| PSE_IQ_STA7 : %08x |\n",
929 mtk_r32(eth, MTK_PSE_IQ_STA(6)));
930 seq_printf(seq, "| PSE_IQ_STA8 : %08x |\n",
931 mtk_r32(eth, MTK_PSE_IQ_STA(7)));
developerfd40db22021-04-29 10:08:25 +0800932 }
933
934 seq_printf(seq, "| PSE_OQ_STA1 : %08x |\n",
935 mtk_r32(eth, MTK_PSE_OQ_STA(0)));
936 seq_printf(seq, "| PSE_OQ_STA2 : %08x |\n",
937 mtk_r32(eth, MTK_PSE_OQ_STA(1)));
938
developer089e8852022-09-28 14:43:46 +0800939 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
940 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developerfd40db22021-04-29 10:08:25 +0800941 seq_printf(seq, "| PSE_OQ_STA3 : %08x |\n",
942 mtk_r32(eth, MTK_PSE_OQ_STA(2)));
943 seq_printf(seq, "| PSE_OQ_STA4 : %08x |\n",
944 mtk_r32(eth, MTK_PSE_OQ_STA(3)));
developer77f3fd42021-10-05 15:16:05 +0800945 seq_printf(seq, "| PSE_OQ_STA5 : %08x |\n",
946 mtk_r32(eth, MTK_PSE_OQ_STA(4)));
developer089e8852022-09-28 14:43:46 +0800947 seq_printf(seq, "| PSE_OQ_STA6 : %08x |\n",
948 mtk_r32(eth, MTK_PSE_OQ_STA(5)));
949 seq_printf(seq, "| PSE_OQ_STA7 : %08x |\n",
950 mtk_r32(eth, MTK_PSE_OQ_STA(6)));
951 seq_printf(seq, "| PSE_OQ_STA8 : %08x |\n",
952 mtk_r32(eth, MTK_PSE_OQ_STA(7)));
developerfd40db22021-04-29 10:08:25 +0800953 }
954
developer77f3fd42021-10-05 15:16:05 +0800955 seq_printf(seq, "| PDMA_CRX_IDX : %08x |\n",
956 mtk_r32(eth, MTK_PRX_CRX_IDX0));
957 seq_printf(seq, "| PDMA_DRX_IDX : %08x |\n",
958 mtk_r32(eth, MTK_PRX_DRX_IDX0));
959 seq_printf(seq, "| QDMA_CTX_IDX : %08x |\n",
960 mtk_r32(eth, MTK_QTX_CTX_PTR));
961 seq_printf(seq, "| QDMA_DTX_IDX : %08x |\n",
962 mtk_r32(eth, MTK_QTX_DTX_PTR));
developerfd40db22021-04-29 10:08:25 +0800963 seq_printf(seq, "| QDMA_FQ_CNT : %08x |\n",
964 mtk_r32(eth, MTK_QDMA_FQ_CNT));
developer089e8852022-09-28 14:43:46 +0800965 seq_printf(seq, "| QDMA_FWD_CNT : %08x |\n",
966 mtk_r32(eth, MTK_QDMA_FWD_CNT));
967 seq_printf(seq, "| QDMA_FSM : %08x |\n",
968 mtk_r32(eth, MTK_QDMA_FSM));
developerfd40db22021-04-29 10:08:25 +0800969 seq_printf(seq, "| FE_PSE_FREE : %08x |\n",
970 mtk_r32(eth, MTK_FE_PSE_FREE));
971 seq_printf(seq, "| FE_DROP_FQ : %08x |\n",
972 mtk_r32(eth, MTK_FE_DROP_FQ));
973 seq_printf(seq, "| FE_DROP_FC : %08x |\n",
974 mtk_r32(eth, MTK_FE_DROP_FC));
975 seq_printf(seq, "| FE_DROP_PPE : %08x |\n",
976 mtk_r32(eth, MTK_FE_DROP_PPE));
977 seq_printf(seq, "| GDM1_IG_CTRL : %08x |\n",
978 mtk_r32(eth, MTK_GDMA_FWD_CFG(0)));
979 seq_printf(seq, "| GDM2_IG_CTRL : %08x |\n",
980 mtk_r32(eth, MTK_GDMA_FWD_CFG(1)));
developer089e8852022-09-28 14:43:46 +0800981 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
982 seq_printf(seq, "| GDM3_IG_CTRL : %08x |\n",
983 mtk_r32(eth, MTK_GDMA_FWD_CFG(2)));
984 }
developerfd40db22021-04-29 10:08:25 +0800985 seq_printf(seq, "| MAC_P1_MCR : %08x |\n",
986 mtk_r32(eth, MTK_MAC_MCR(0)));
987 seq_printf(seq, "| MAC_P2_MCR : %08x |\n",
988 mtk_r32(eth, MTK_MAC_MCR(1)));
developer089e8852022-09-28 14:43:46 +0800989 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
990 seq_printf(seq, "| MAC_P3_MCR : %08x |\n",
991 mtk_r32(eth, MTK_MAC_MCR(2)));
992 }
developer77f3fd42021-10-05 15:16:05 +0800993 seq_printf(seq, "| MAC_P1_FSM : %08x |\n",
994 mtk_r32(eth, MTK_MAC_FSM(0)));
995 seq_printf(seq, "| MAC_P2_FSM : %08x |\n",
996 mtk_r32(eth, MTK_MAC_FSM(1)));
developer089e8852022-09-28 14:43:46 +0800997 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
998 seq_printf(seq, "| MAC_P3_FSM : %08x |\n",
999 mtk_r32(eth, MTK_MAC_FSM(2)));
1000 }
developerfd40db22021-04-29 10:08:25 +08001001
developer089e8852022-09-28 14:43:46 +08001002 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1003 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developerfd40db22021-04-29 10:08:25 +08001004 seq_printf(seq, "| FE_CDM1_FSM : %08x |\n",
1005 mtk_r32(eth, MTK_FE_CDM1_FSM));
1006 seq_printf(seq, "| FE_CDM2_FSM : %08x |\n",
1007 mtk_r32(eth, MTK_FE_CDM2_FSM));
developer77f3fd42021-10-05 15:16:05 +08001008 seq_printf(seq, "| FE_CDM3_FSM : %08x |\n",
1009 mtk_r32(eth, MTK_FE_CDM3_FSM));
1010 seq_printf(seq, "| FE_CDM4_FSM : %08x |\n",
1011 mtk_r32(eth, MTK_FE_CDM4_FSM));
developer089e8852022-09-28 14:43:46 +08001012 seq_printf(seq, "| FE_CDM5_FSM : %08x |\n",
1013 mtk_r32(eth, MTK_FE_CDM5_FSM));
1014 seq_printf(seq, "| FE_CDM6_FSM : %08x |\n",
1015 mtk_r32(eth, MTK_FE_CDM6_FSM));
developerfd40db22021-04-29 10:08:25 +08001016 seq_printf(seq, "| FE_GDM1_FSM : %08x |\n",
1017 mtk_r32(eth, MTK_FE_GDM1_FSM));
1018 seq_printf(seq, "| FE_GDM2_FSM : %08x |\n",
1019 mtk_r32(eth, MTK_FE_GDM2_FSM));
developer77f3fd42021-10-05 15:16:05 +08001020 seq_printf(seq, "| SGMII_EFUSE : %08x |\n",
1021 mtk_dbg_r32(MTK_SGMII_EFUSE));
1022 seq_printf(seq, "| SGMII0_RX_CNT : %08x |\n",
1023 mtk_dbg_r32(MTK_SGMII_FALSE_CARRIER_CNT(0)));
1024 seq_printf(seq, "| SGMII1_RX_CNT : %08x |\n",
1025 mtk_dbg_r32(MTK_SGMII_FALSE_CARRIER_CNT(1)));
1026 seq_printf(seq, "| WED_RTQM_GLO : %08x |\n",
1027 mtk_dbg_r32(MTK_WED_RTQM_GLO_CFG));
developerfd40db22021-04-29 10:08:25 +08001028 }
1029
developer8051e042022-04-08 13:26:36 +08001030 mtk_w32(eth, 0xffffffff, MTK_FE_INT_STATUS);
developer089e8852022-09-28 14:43:46 +08001031 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1032 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
developer8051e042022-04-08 13:26:36 +08001033 mtk_w32(eth, 0xffffffff, MTK_FE_INT_STATUS2);
developer77f3fd42021-10-05 15:16:05 +08001034
developerfd40db22021-04-29 10:08:25 +08001035 return 0;
1036}
1037
1038static int dbg_regs_open(struct inode *inode, struct file *file)
1039{
1040 return single_open(file, dbg_regs_read, 0);
1041}
1042
1043static const struct file_operations dbg_regs_fops = {
1044 .owner = THIS_MODULE,
1045 .open = dbg_regs_open,
1046 .read = seq_read,
1047 .llseek = seq_lseek,
developer77d03a72021-06-06 00:06:00 +08001048 .release = single_release
1049};
1050
developere9356982022-07-04 09:03:20 +08001051void hw_lro_stats_update(u32 ring_no, struct mtk_rx_dma_v2 *rxd)
developer77d03a72021-06-06 00:06:00 +08001052{
developere9356982022-07-04 09:03:20 +08001053 struct mtk_eth *eth = g_eth;
developer77d03a72021-06-06 00:06:00 +08001054 u32 idx, agg_cnt, agg_size;
1055
developer089e8852022-09-28 14:43:46 +08001056 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1057 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developere9356982022-07-04 09:03:20 +08001058 idx = ring_no - 4;
1059 agg_cnt = RX_DMA_GET_AGG_CNT_V2(rxd->rxd6);
1060 } else {
1061 idx = ring_no - 1;
1062 agg_cnt = RX_DMA_GET_AGG_CNT(rxd->rxd2);
1063 }
developer77d03a72021-06-06 00:06:00 +08001064
1065 agg_size = RX_DMA_GET_PLEN0(rxd->rxd2);
1066
1067 hw_lro_agg_size_cnt[idx][agg_size / 5000]++;
1068 hw_lro_agg_num_cnt[idx][agg_cnt]++;
1069 hw_lro_tot_flush_cnt[idx]++;
1070 hw_lro_tot_agg_cnt[idx] += agg_cnt;
1071}
1072
developere9356982022-07-04 09:03:20 +08001073void hw_lro_flush_stats_update(u32 ring_no, struct mtk_rx_dma_v2 *rxd)
developer77d03a72021-06-06 00:06:00 +08001074{
developere9356982022-07-04 09:03:20 +08001075 struct mtk_eth *eth = g_eth;
developer77d03a72021-06-06 00:06:00 +08001076 u32 idx, flush_reason;
1077
developer089e8852022-09-28 14:43:46 +08001078 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1079 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developere9356982022-07-04 09:03:20 +08001080 idx = ring_no - 4;
1081 flush_reason = RX_DMA_GET_FLUSH_RSN_V2(rxd->rxd6);
1082 } else {
1083 idx = ring_no - 1;
1084 flush_reason = RX_DMA_GET_REV(rxd->rxd2);
1085 }
developer77d03a72021-06-06 00:06:00 +08001086
1087 if ((flush_reason & 0x7) == MTK_HW_LRO_AGG_FLUSH)
1088 hw_lro_agg_flush_cnt[idx]++;
1089 else if ((flush_reason & 0x7) == MTK_HW_LRO_AGE_FLUSH)
1090 hw_lro_age_flush_cnt[idx]++;
1091 else if ((flush_reason & 0x7) == MTK_HW_LRO_NOT_IN_SEQ_FLUSH)
1092 hw_lro_seq_flush_cnt[idx]++;
1093 else if ((flush_reason & 0x7) == MTK_HW_LRO_TIMESTAMP_FLUSH)
1094 hw_lro_timestamp_flush_cnt[idx]++;
1095 else if ((flush_reason & 0x7) == MTK_HW_LRO_NON_RULE_FLUSH)
1096 hw_lro_norule_flush_cnt[idx]++;
1097}
1098
1099ssize_t hw_lro_stats_write(struct file *file, const char __user *buffer,
1100 size_t count, loff_t *data)
1101{
1102 memset(hw_lro_agg_num_cnt, 0, sizeof(hw_lro_agg_num_cnt));
1103 memset(hw_lro_agg_size_cnt, 0, sizeof(hw_lro_agg_size_cnt));
1104 memset(hw_lro_tot_agg_cnt, 0, sizeof(hw_lro_tot_agg_cnt));
1105 memset(hw_lro_tot_flush_cnt, 0, sizeof(hw_lro_tot_flush_cnt));
1106 memset(hw_lro_agg_flush_cnt, 0, sizeof(hw_lro_agg_flush_cnt));
1107 memset(hw_lro_age_flush_cnt, 0, sizeof(hw_lro_age_flush_cnt));
1108 memset(hw_lro_seq_flush_cnt, 0, sizeof(hw_lro_seq_flush_cnt));
1109 memset(hw_lro_timestamp_flush_cnt, 0,
1110 sizeof(hw_lro_timestamp_flush_cnt));
1111 memset(hw_lro_norule_flush_cnt, 0, sizeof(hw_lro_norule_flush_cnt));
1112
1113 pr_info("clear hw lro cnt table\n");
1114
1115 return count;
1116}
1117
1118int hw_lro_stats_read_v1(struct seq_file *seq, void *v)
1119{
1120 int i;
1121
1122 seq_puts(seq, "HW LRO statistic dump:\n");
1123
1124 /* Agg number count */
1125 seq_puts(seq, "Cnt: RING1 | RING2 | RING3 | Total\n");
1126 for (i = 0; i <= MTK_HW_LRO_MAX_AGG_CNT; i++) {
1127 seq_printf(seq, " %d : %d %d %d %d\n",
1128 i, hw_lro_agg_num_cnt[0][i],
1129 hw_lro_agg_num_cnt[1][i], hw_lro_agg_num_cnt[2][i],
1130 hw_lro_agg_num_cnt[0][i] + hw_lro_agg_num_cnt[1][i] +
1131 hw_lro_agg_num_cnt[2][i]);
1132 }
1133
1134 /* Total agg count */
1135 seq_puts(seq, "Total agg: RING1 | RING2 | RING3 | Total\n");
1136 seq_printf(seq, " %d %d %d %d\n",
1137 hw_lro_tot_agg_cnt[0], hw_lro_tot_agg_cnt[1],
1138 hw_lro_tot_agg_cnt[2],
1139 hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1140 hw_lro_tot_agg_cnt[2]);
1141
1142 /* Total flush count */
1143 seq_puts(seq, "Total flush: RING1 | RING2 | RING3 | Total\n");
1144 seq_printf(seq, " %d %d %d %d\n",
1145 hw_lro_tot_flush_cnt[0], hw_lro_tot_flush_cnt[1],
1146 hw_lro_tot_flush_cnt[2],
1147 hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1148 hw_lro_tot_flush_cnt[2]);
1149
1150 /* Avg agg count */
1151 seq_puts(seq, "Avg agg: RING1 | RING2 | RING3 | Total\n");
1152 seq_printf(seq, " %d %d %d %d\n",
1153 (hw_lro_tot_flush_cnt[0]) ?
1154 hw_lro_tot_agg_cnt[0] / hw_lro_tot_flush_cnt[0] : 0,
1155 (hw_lro_tot_flush_cnt[1]) ?
1156 hw_lro_tot_agg_cnt[1] / hw_lro_tot_flush_cnt[1] : 0,
1157 (hw_lro_tot_flush_cnt[2]) ?
1158 hw_lro_tot_agg_cnt[2] / hw_lro_tot_flush_cnt[2] : 0,
1159 (hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1160 hw_lro_tot_flush_cnt[2]) ?
1161 ((hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1162 hw_lro_tot_agg_cnt[2]) / (hw_lro_tot_flush_cnt[0] +
1163 hw_lro_tot_flush_cnt[1] + hw_lro_tot_flush_cnt[2])) : 0);
1164
1165 /* Statistics of aggregation size counts */
1166 seq_puts(seq, "HW LRO flush pkt len:\n");
1167 seq_puts(seq, " Length | RING1 | RING2 | RING3 | Total\n");
1168 for (i = 0; i < 15; i++) {
1169 seq_printf(seq, "%d~%d: %d %d %d %d\n", i * 5000,
1170 (i + 1) * 5000, hw_lro_agg_size_cnt[0][i],
1171 hw_lro_agg_size_cnt[1][i], hw_lro_agg_size_cnt[2][i],
1172 hw_lro_agg_size_cnt[0][i] +
1173 hw_lro_agg_size_cnt[1][i] +
1174 hw_lro_agg_size_cnt[2][i]);
1175 }
1176
1177 seq_puts(seq, "Flush reason: RING1 | RING2 | RING3 | Total\n");
1178 seq_printf(seq, "AGG timeout: %d %d %d %d\n",
1179 hw_lro_agg_flush_cnt[0], hw_lro_agg_flush_cnt[1],
1180 hw_lro_agg_flush_cnt[2],
1181 (hw_lro_agg_flush_cnt[0] + hw_lro_agg_flush_cnt[1] +
1182 hw_lro_agg_flush_cnt[2]));
1183
1184 seq_printf(seq, "AGE timeout: %d %d %d %d\n",
1185 hw_lro_age_flush_cnt[0], hw_lro_age_flush_cnt[1],
1186 hw_lro_age_flush_cnt[2],
1187 (hw_lro_age_flush_cnt[0] + hw_lro_age_flush_cnt[1] +
1188 hw_lro_age_flush_cnt[2]));
1189
1190 seq_printf(seq, "Not in-sequence: %d %d %d %d\n",
1191 hw_lro_seq_flush_cnt[0], hw_lro_seq_flush_cnt[1],
1192 hw_lro_seq_flush_cnt[2],
1193 (hw_lro_seq_flush_cnt[0] + hw_lro_seq_flush_cnt[1] +
1194 hw_lro_seq_flush_cnt[2]));
1195
1196 seq_printf(seq, "Timestamp: %d %d %d %d\n",
1197 hw_lro_timestamp_flush_cnt[0],
1198 hw_lro_timestamp_flush_cnt[1],
1199 hw_lro_timestamp_flush_cnt[2],
1200 (hw_lro_timestamp_flush_cnt[0] +
1201 hw_lro_timestamp_flush_cnt[1] +
1202 hw_lro_timestamp_flush_cnt[2]));
1203
1204 seq_printf(seq, "No LRO rule: %d %d %d %d\n",
1205 hw_lro_norule_flush_cnt[0],
1206 hw_lro_norule_flush_cnt[1],
1207 hw_lro_norule_flush_cnt[2],
1208 (hw_lro_norule_flush_cnt[0] +
1209 hw_lro_norule_flush_cnt[1] +
1210 hw_lro_norule_flush_cnt[2]));
1211
1212 return 0;
1213}
1214
1215int hw_lro_stats_read_v2(struct seq_file *seq, void *v)
1216{
1217 int i;
1218
1219 seq_puts(seq, "HW LRO statistic dump:\n");
1220
1221 /* Agg number count */
1222 seq_puts(seq, "Cnt: RING4 | RING5 | RING6 | RING7 Total\n");
1223 for (i = 0; i <= MTK_HW_LRO_MAX_AGG_CNT; i++) {
1224 seq_printf(seq,
1225 " %d : %d %d %d %d %d\n",
1226 i, hw_lro_agg_num_cnt[0][i], hw_lro_agg_num_cnt[1][i],
1227 hw_lro_agg_num_cnt[2][i], hw_lro_agg_num_cnt[3][i],
1228 hw_lro_agg_num_cnt[0][i] + hw_lro_agg_num_cnt[1][i] +
1229 hw_lro_agg_num_cnt[2][i] + hw_lro_agg_num_cnt[3][i]);
1230 }
1231
1232 /* Total agg count */
1233 seq_puts(seq, "Total agg: RING4 | RING5 | RING6 | RING7 Total\n");
1234 seq_printf(seq, " %d %d %d %d %d\n",
1235 hw_lro_tot_agg_cnt[0], hw_lro_tot_agg_cnt[1],
1236 hw_lro_tot_agg_cnt[2], hw_lro_tot_agg_cnt[3],
1237 hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1238 hw_lro_tot_agg_cnt[2] + hw_lro_tot_agg_cnt[3]);
1239
1240 /* Total flush count */
1241 seq_puts(seq, "Total flush: RING4 | RING5 | RING6 | RING7 Total\n");
1242 seq_printf(seq, " %d %d %d %d %d\n",
1243 hw_lro_tot_flush_cnt[0], hw_lro_tot_flush_cnt[1],
1244 hw_lro_tot_flush_cnt[2], hw_lro_tot_flush_cnt[3],
1245 hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1246 hw_lro_tot_flush_cnt[2] + hw_lro_tot_flush_cnt[3]);
1247
1248 /* Avg agg count */
1249 seq_puts(seq, "Avg agg: RING4 | RING5 | RING6 | RING7 Total\n");
1250 seq_printf(seq, " %d %d %d %d %d\n",
1251 (hw_lro_tot_flush_cnt[0]) ?
1252 hw_lro_tot_agg_cnt[0] / hw_lro_tot_flush_cnt[0] : 0,
1253 (hw_lro_tot_flush_cnt[1]) ?
1254 hw_lro_tot_agg_cnt[1] / hw_lro_tot_flush_cnt[1] : 0,
1255 (hw_lro_tot_flush_cnt[2]) ?
1256 hw_lro_tot_agg_cnt[2] / hw_lro_tot_flush_cnt[2] : 0,
1257 (hw_lro_tot_flush_cnt[3]) ?
1258 hw_lro_tot_agg_cnt[3] / hw_lro_tot_flush_cnt[3] : 0,
1259 (hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1260 hw_lro_tot_flush_cnt[2] + hw_lro_tot_flush_cnt[3]) ?
1261 ((hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1262 hw_lro_tot_agg_cnt[2] + hw_lro_tot_agg_cnt[3]) /
1263 (hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1264 hw_lro_tot_flush_cnt[2] + hw_lro_tot_flush_cnt[3])) : 0);
1265
1266 /* Statistics of aggregation size counts */
1267 seq_puts(seq, "HW LRO flush pkt len:\n");
1268 seq_puts(seq, " Length | RING4 | RING5 | RING6 | RING7 Total\n");
1269 for (i = 0; i < 15; i++) {
1270 seq_printf(seq, "%d~%d: %d %d %d %d %d\n",
1271 i * 5000, (i + 1) * 5000,
1272 hw_lro_agg_size_cnt[0][i], hw_lro_agg_size_cnt[1][i],
1273 hw_lro_agg_size_cnt[2][i], hw_lro_agg_size_cnt[3][i],
1274 hw_lro_agg_size_cnt[0][i] +
1275 hw_lro_agg_size_cnt[1][i] +
1276 hw_lro_agg_size_cnt[2][i] +
1277 hw_lro_agg_size_cnt[3][i]);
1278 }
1279
1280 seq_puts(seq, "Flush reason: RING4 | RING5 | RING6 | RING7 Total\n");
1281 seq_printf(seq, "AGG timeout: %d %d %d %d %d\n",
1282 hw_lro_agg_flush_cnt[0], hw_lro_agg_flush_cnt[1],
1283 hw_lro_agg_flush_cnt[2], hw_lro_agg_flush_cnt[3],
1284 (hw_lro_agg_flush_cnt[0] + hw_lro_agg_flush_cnt[1] +
1285 hw_lro_agg_flush_cnt[2] + hw_lro_agg_flush_cnt[3]));
1286
1287 seq_printf(seq, "AGE timeout: %d %d %d %d %d\n",
1288 hw_lro_age_flush_cnt[0], hw_lro_age_flush_cnt[1],
1289 hw_lro_age_flush_cnt[2], hw_lro_age_flush_cnt[3],
1290 (hw_lro_age_flush_cnt[0] + hw_lro_age_flush_cnt[1] +
1291 hw_lro_age_flush_cnt[2] + hw_lro_age_flush_cnt[3]));
1292
1293 seq_printf(seq, "Not in-sequence: %d %d %d %d %d\n",
1294 hw_lro_seq_flush_cnt[0], hw_lro_seq_flush_cnt[1],
1295 hw_lro_seq_flush_cnt[2], hw_lro_seq_flush_cnt[3],
1296 (hw_lro_seq_flush_cnt[0] + hw_lro_seq_flush_cnt[1] +
1297 hw_lro_seq_flush_cnt[2] + hw_lro_seq_flush_cnt[3]));
1298
1299 seq_printf(seq, "Timestamp: %d %d %d %d %d\n",
1300 hw_lro_timestamp_flush_cnt[0],
1301 hw_lro_timestamp_flush_cnt[1],
1302 hw_lro_timestamp_flush_cnt[2],
1303 hw_lro_timestamp_flush_cnt[3],
1304 (hw_lro_timestamp_flush_cnt[0] +
1305 hw_lro_timestamp_flush_cnt[1] +
1306 hw_lro_timestamp_flush_cnt[2] +
1307 hw_lro_timestamp_flush_cnt[3]));
1308
1309 seq_printf(seq, "No LRO rule: %d %d %d %d %d\n",
1310 hw_lro_norule_flush_cnt[0],
1311 hw_lro_norule_flush_cnt[1],
1312 hw_lro_norule_flush_cnt[2],
1313 hw_lro_norule_flush_cnt[3],
1314 (hw_lro_norule_flush_cnt[0] +
1315 hw_lro_norule_flush_cnt[1] +
1316 hw_lro_norule_flush_cnt[2] +
1317 hw_lro_norule_flush_cnt[3]));
1318
1319 return 0;
1320}
1321
1322int hw_lro_stats_read_wrapper(struct seq_file *seq, void *v)
1323{
1324 struct mtk_eth *eth = g_eth;
1325
developer089e8852022-09-28 14:43:46 +08001326 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1327 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
developer77d03a72021-06-06 00:06:00 +08001328 hw_lro_stats_read_v2(seq, v);
1329 else
1330 hw_lro_stats_read_v1(seq, v);
1331
1332 return 0;
1333}
1334
1335static int hw_lro_stats_open(struct inode *inode, struct file *file)
1336{
1337 return single_open(file, hw_lro_stats_read_wrapper, NULL);
1338}
1339
1340static const struct file_operations hw_lro_stats_fops = {
1341 .owner = THIS_MODULE,
1342 .open = hw_lro_stats_open,
1343 .read = seq_read,
1344 .llseek = seq_lseek,
1345 .write = hw_lro_stats_write,
developerfd40db22021-04-29 10:08:25 +08001346 .release = single_release
1347};
1348
developer77d03a72021-06-06 00:06:00 +08001349int hwlro_agg_cnt_ctrl(int cnt)
1350{
1351 int i;
1352
1353 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1354 SET_PDMA_RXRING_MAX_AGG_CNT(g_eth, i, cnt);
1355
1356 return 0;
1357}
1358
1359int hwlro_agg_time_ctrl(int time)
1360{
1361 int i;
1362
1363 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1364 SET_PDMA_RXRING_AGG_TIME(g_eth, i, time);
1365
1366 return 0;
1367}
1368
1369int hwlro_age_time_ctrl(int time)
1370{
1371 int i;
1372
1373 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1374 SET_PDMA_RXRING_AGE_TIME(g_eth, i, time);
1375
1376 return 0;
1377}
1378
1379int hwlro_threshold_ctrl(int bandwidth)
1380{
1381 SET_PDMA_LRO_BW_THRESHOLD(g_eth, bandwidth);
1382
1383 return 0;
1384}
1385
1386int hwlro_ring_enable_ctrl(int enable)
1387{
1388 int i;
1389
1390 pr_info("[%s] %s HW LRO rings\n", __func__, (enable) ? "Enable" : "Disable");
1391
1392 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1393 SET_PDMA_RXRING_VALID(g_eth, i, enable);
1394
1395 return 0;
1396}
1397
1398int hwlro_stats_enable_ctrl(int enable)
1399{
1400 pr_info("[%s] %s HW LRO statistics\n", __func__, (enable) ? "Enable" : "Disable");
1401 mtk_hwlro_stats_ebl = enable;
1402
1403 return 0;
1404}
1405
1406static const mtk_lro_dbg_func lro_dbg_func[] = {
1407 [0] = hwlro_agg_cnt_ctrl,
1408 [1] = hwlro_agg_time_ctrl,
1409 [2] = hwlro_age_time_ctrl,
1410 [3] = hwlro_threshold_ctrl,
1411 [4] = hwlro_ring_enable_ctrl,
1412 [5] = hwlro_stats_enable_ctrl,
1413};
1414
1415ssize_t hw_lro_auto_tlb_write(struct file *file, const char __user *buffer,
1416 size_t count, loff_t *data)
1417{
1418 char buf[32];
1419 char *p_buf;
1420 char *p_token = NULL;
1421 char *p_delimiter = " \t";
1422 long x = 0, y = 0;
developer4c32b7a2021-11-13 16:46:43 +08001423 u32 len = count;
developer77d03a72021-06-06 00:06:00 +08001424 int ret;
1425
1426 if (len >= sizeof(buf)) {
1427 pr_info("Input handling fail!\n");
developer77d03a72021-06-06 00:06:00 +08001428 return -1;
1429 }
1430
1431 if (copy_from_user(buf, buffer, len))
1432 return -EFAULT;
1433
1434 buf[len] = '\0';
1435
1436 p_buf = buf;
1437 p_token = strsep(&p_buf, p_delimiter);
1438 if (!p_token)
1439 x = 0;
1440 else
1441 ret = kstrtol(p_token, 10, &x);
1442
1443 p_token = strsep(&p_buf, "\t\n ");
1444 if (p_token)
1445 ret = kstrtol(p_token, 10, &y);
1446
1447 if (lro_dbg_func[x] && (ARRAY_SIZE(lro_dbg_func) > x))
1448 (*lro_dbg_func[x]) (y);
1449
1450 return count;
1451}
1452
1453void hw_lro_auto_tlb_dump_v1(struct seq_file *seq, u32 index)
1454{
1455 int i;
1456 struct mtk_lro_alt_v1 alt;
1457 __be32 addr;
1458 u32 tlb_info[9];
1459 u32 dw_len, cnt, priority;
1460 u32 entry;
1461
1462 if (index > 4)
1463 index = index - 1;
1464 entry = (index * 9) + 1;
1465
1466 /* read valid entries of the auto-learn table */
1467 mtk_w32(g_eth, entry, MTK_FE_ALT_CF8);
1468
1469 for (i = 0; i < 9; i++)
1470 tlb_info[i] = mtk_r32(g_eth, MTK_FE_ALT_SEQ_CFC);
1471
1472 memcpy(&alt, tlb_info, sizeof(struct mtk_lro_alt_v1));
1473
1474 dw_len = alt.alt_info7.dw_len;
1475 cnt = alt.alt_info6.cnt;
1476
1477 if (mtk_r32(g_eth, MTK_PDMA_LRO_CTRL_DW0) & MTK_LRO_ALT_PKT_CNT_MODE)
1478 priority = cnt; /* packet count */
1479 else
1480 priority = dw_len; /* byte count */
1481
1482 /* dump valid entries of the auto-learn table */
1483 if (index >= 4)
1484 seq_printf(seq, "\n===== TABLE Entry: %d (Act) =====\n", index);
1485 else
1486 seq_printf(seq, "\n===== TABLE Entry: %d (LRU) =====\n", index);
1487
1488 if (alt.alt_info8.ipv4) {
1489 addr = htonl(alt.alt_info1.sip0);
1490 seq_printf(seq, "SIP = %pI4 (IPv4)\n", &addr);
1491 } else {
1492 seq_printf(seq, "SIP = %08X:%08X:%08X:%08X (IPv6)\n",
1493 alt.alt_info4.sip3, alt.alt_info3.sip2,
1494 alt.alt_info2.sip1, alt.alt_info1.sip0);
1495 }
1496
1497 seq_printf(seq, "DIP_ID = %d\n", alt.alt_info8.dip_id);
1498 seq_printf(seq, "TCP SPORT = %d | TCP DPORT = %d\n",
1499 alt.alt_info0.stp, alt.alt_info0.dtp);
1500 seq_printf(seq, "VLAN_VID_VLD = %d\n", alt.alt_info6.vlan_vid_vld);
1501 seq_printf(seq, "VLAN1 = %d | VLAN2 = %d | VLAN3 = %d | VLAN4 =%d\n",
1502 (alt.alt_info5.vlan_vid0 & 0xfff),
1503 ((alt.alt_info5.vlan_vid0 >> 12) & 0xfff),
1504 ((alt.alt_info6.vlan_vid1 << 8) |
1505 ((alt.alt_info5.vlan_vid0 >> 24) & 0xfff)),
1506 ((alt.alt_info6.vlan_vid1 >> 4) & 0xfff));
1507 seq_printf(seq, "TPUT = %d | FREQ = %d\n", dw_len, cnt);
1508 seq_printf(seq, "PRIORITY = %d\n", priority);
1509}
1510
1511void hw_lro_auto_tlb_dump_v2(struct seq_file *seq, u32 index)
1512{
1513 int i;
1514 struct mtk_lro_alt_v2 alt;
1515 u32 score = 0, ipv4 = 0;
1516 u32 ipv6[4] = { 0 };
1517 u32 tlb_info[12];
1518
1519 /* read valid entries of the auto-learn table */
1520 mtk_w32(g_eth, index << MTK_LRO_ALT_INDEX_OFFSET, MTK_LRO_ALT_DBG);
1521
1522 for (i = 0; i < 11; i++)
1523 tlb_info[i] = mtk_r32(g_eth, MTK_LRO_ALT_DBG_DATA);
1524
1525 memcpy(&alt, tlb_info, sizeof(struct mtk_lro_alt_v2));
1526
1527 if (mtk_r32(g_eth, MTK_PDMA_LRO_CTRL_DW0) & MTK_LRO_ALT_PKT_CNT_MODE)
1528 score = 1; /* packet count */
1529 else
1530 score = 0; /* byte count */
1531
1532 /* dump valid entries of the auto-learn table */
1533 if (alt.alt_info0.valid) {
1534 if (index < 5)
1535 seq_printf(seq,
1536 "\n===== TABLE Entry: %d (onging) =====\n",
1537 index);
1538 else
1539 seq_printf(seq,
1540 "\n===== TABLE Entry: %d (candidate) =====\n",
1541 index);
1542
1543 if (alt.alt_info1.v4_valid) {
1544 ipv4 = (alt.alt_info4.sip0_h << 23) |
1545 alt.alt_info5.sip0_l;
1546 seq_printf(seq, "SIP = 0x%x: (IPv4)\n", ipv4);
1547
1548 ipv4 = (alt.alt_info8.dip0_h << 23) |
1549 alt.alt_info9.dip0_l;
1550 seq_printf(seq, "DIP = 0x%x: (IPv4)\n", ipv4);
1551 } else if (alt.alt_info1.v6_valid) {
1552 ipv6[3] = (alt.alt_info1.sip3_h << 23) |
1553 (alt.alt_info2.sip3_l << 9);
1554 ipv6[2] = (alt.alt_info2.sip2_h << 23) |
1555 (alt.alt_info3.sip2_l << 9);
1556 ipv6[1] = (alt.alt_info3.sip1_h << 23) |
1557 (alt.alt_info4.sip1_l << 9);
1558 ipv6[0] = (alt.alt_info4.sip0_h << 23) |
1559 (alt.alt_info5.sip0_l << 9);
1560 seq_printf(seq, "SIP = 0x%x:0x%x:0x%x:0x%x (IPv6)\n",
1561 ipv6[3], ipv6[2], ipv6[1], ipv6[0]);
1562
1563 ipv6[3] = (alt.alt_info5.dip3_h << 23) |
1564 (alt.alt_info6.dip3_l << 9);
1565 ipv6[2] = (alt.alt_info6.dip2_h << 23) |
1566 (alt.alt_info7.dip2_l << 9);
1567 ipv6[1] = (alt.alt_info7.dip1_h << 23) |
1568 (alt.alt_info8.dip1_l << 9);
1569 ipv6[0] = (alt.alt_info8.dip0_h << 23) |
1570 (alt.alt_info9.dip0_l << 9);
1571 seq_printf(seq, "DIP = 0x%x:0x%x:0x%x:0x%x (IPv6)\n",
1572 ipv6[3], ipv6[2], ipv6[1], ipv6[0]);
1573 }
1574
1575 seq_printf(seq, "TCP SPORT = %d | TCP DPORT = %d\n",
1576 (alt.alt_info9.sp_h << 7) | (alt.alt_info10.sp_l),
1577 alt.alt_info10.dp);
1578 }
1579}
1580
1581int hw_lro_auto_tlb_read(struct seq_file *seq, void *v)
1582{
1583 int i;
1584 u32 reg_val;
1585 u32 reg_op1, reg_op2, reg_op3, reg_op4;
1586 u32 agg_cnt, agg_time, age_time;
1587
1588 seq_puts(seq, "Usage of /proc/mtketh/hw_lro_auto_tlb:\n");
1589 seq_puts(seq, "echo [function] [setting] > /proc/mtketh/hw_lro_auto_tlb\n");
1590 seq_puts(seq, "Functions:\n");
1591 seq_puts(seq, "[0] = hwlro_agg_cnt_ctrl\n");
1592 seq_puts(seq, "[1] = hwlro_agg_time_ctrl\n");
1593 seq_puts(seq, "[2] = hwlro_age_time_ctrl\n");
1594 seq_puts(seq, "[3] = hwlro_threshold_ctrl\n");
1595 seq_puts(seq, "[4] = hwlro_ring_enable_ctrl\n");
1596 seq_puts(seq, "[5] = hwlro_stats_enable_ctrl\n\n");
1597
developer089e8852022-09-28 14:43:46 +08001598 if (MTK_HAS_CAPS(g_eth->soc->caps, MTK_NETSYS_V2) ||
1599 MTK_HAS_CAPS(g_eth->soc->caps, MTK_NETSYS_V3)) {
developer77d03a72021-06-06 00:06:00 +08001600 for (i = 1; i <= 8; i++)
1601 hw_lro_auto_tlb_dump_v2(seq, i);
1602 } else {
1603 /* Read valid entries of the auto-learn table */
1604 mtk_w32(g_eth, 0, MTK_FE_ALT_CF8);
1605 reg_val = mtk_r32(g_eth, MTK_FE_ALT_SEQ_CFC);
1606
1607 seq_printf(seq,
1608 "HW LRO Auto-learn Table: (MTK_FE_ALT_SEQ_CFC=0x%x)\n",
1609 reg_val);
1610
1611 for (i = 7; i >= 0; i--) {
1612 if (reg_val & (1 << i))
1613 hw_lro_auto_tlb_dump_v1(seq, i);
1614 }
1615 }
1616
1617 /* Read the agg_time/age_time/agg_cnt of LRO rings */
1618 seq_puts(seq, "\nHW LRO Ring Settings\n");
1619
1620 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++) {
1621 reg_op1 = mtk_r32(g_eth, MTK_LRO_CTRL_DW1_CFG(i));
1622 reg_op2 = mtk_r32(g_eth, MTK_LRO_CTRL_DW2_CFG(i));
1623 reg_op3 = mtk_r32(g_eth, MTK_LRO_CTRL_DW3_CFG(i));
1624 reg_op4 = mtk_r32(g_eth, MTK_PDMA_LRO_CTRL_DW2);
1625
1626 agg_cnt =
1627 ((reg_op3 & 0x3) << 6) |
1628 ((reg_op2 >> MTK_LRO_RING_AGG_CNT_L_OFFSET) & 0x3f);
1629 agg_time = (reg_op2 >> MTK_LRO_RING_AGG_TIME_OFFSET) & 0xffff;
1630 age_time =
1631 ((reg_op2 & 0x3f) << 10) |
1632 ((reg_op1 >> MTK_LRO_RING_AGE_TIME_L_OFFSET) & 0x3ff);
1633 seq_printf(seq,
1634 "Ring[%d]: MAX_AGG_CNT=%d, AGG_TIME=%d, AGE_TIME=%d, Threshold=%d\n",
developer089e8852022-09-28 14:43:46 +08001635 (MTK_HAS_CAPS(g_eth->soc->caps, MTK_NETSYS_V1)) ? i : i+3,
developer77d03a72021-06-06 00:06:00 +08001636 agg_cnt, agg_time, age_time, reg_op4);
1637 }
1638
1639 seq_puts(seq, "\n");
1640
1641 return 0;
1642}
1643
1644static int hw_lro_auto_tlb_open(struct inode *inode, struct file *file)
1645{
1646 return single_open(file, hw_lro_auto_tlb_read, NULL);
1647}
1648
1649static const struct file_operations hw_lro_auto_tlb_fops = {
1650 .owner = THIS_MODULE,
1651 .open = hw_lro_auto_tlb_open,
1652 .read = seq_read,
1653 .llseek = seq_lseek,
1654 .write = hw_lro_auto_tlb_write,
1655 .release = single_release
1656};
developerfd40db22021-04-29 10:08:25 +08001657
developer8051e042022-04-08 13:26:36 +08001658int reset_event_read(struct seq_file *seq, void *v)
1659{
1660 struct mtk_eth *eth = g_eth;
1661 struct mtk_reset_event reset_event = eth->reset_event;
1662
1663 seq_printf(seq, "[Event] [Count]\n");
1664 seq_printf(seq, " FQ Empty: %d\n",
1665 reset_event.count[MTK_EVENT_FQ_EMPTY]);
1666 seq_printf(seq, " TSO Fail: %d\n",
1667 reset_event.count[MTK_EVENT_TSO_FAIL]);
1668 seq_printf(seq, " TSO Illegal: %d\n",
1669 reset_event.count[MTK_EVENT_TSO_ILLEGAL]);
1670 seq_printf(seq, " TSO Align: %d\n",
1671 reset_event.count[MTK_EVENT_TSO_ALIGN]);
1672 seq_printf(seq, " RFIFO OV: %d\n",
1673 reset_event.count[MTK_EVENT_RFIFO_OV]);
1674 seq_printf(seq, " RFIFO UF: %d\n",
1675 reset_event.count[MTK_EVENT_RFIFO_UF]);
1676 seq_printf(seq, " Force: %d\n",
1677 reset_event.count[MTK_EVENT_FORCE]);
1678 seq_printf(seq, "----------------------------\n");
1679 seq_printf(seq, " Warm Cnt: %d\n",
1680 reset_event.count[MTK_EVENT_WARM_CNT]);
1681 seq_printf(seq, " Cold Cnt: %d\n",
1682 reset_event.count[MTK_EVENT_COLD_CNT]);
1683 seq_printf(seq, " Total Cnt: %d\n",
1684 reset_event.count[MTK_EVENT_TOTAL_CNT]);
1685
1686 return 0;
1687}
1688
1689static int reset_event_open(struct inode *inode, struct file *file)
1690{
1691 return single_open(file, reset_event_read, 0);
1692}
1693
1694ssize_t reset_event_write(struct file *file, const char __user *buffer,
1695 size_t count, loff_t *data)
1696{
1697 struct mtk_eth *eth = g_eth;
1698 struct mtk_reset_event *reset_event = &eth->reset_event;
1699
1700 memset(reset_event, 0, sizeof(struct mtk_reset_event));
1701 pr_info("MTK reset event counter is cleared !\n");
1702
1703 return count;
1704}
1705
1706static const struct file_operations reset_event_fops = {
1707 .owner = THIS_MODULE,
1708 .open = reset_event_open,
1709 .read = seq_read,
1710 .llseek = seq_lseek,
1711 .write = reset_event_write,
1712 .release = single_release
1713};
1714
1715
developerfd40db22021-04-29 10:08:25 +08001716struct proc_dir_entry *proc_reg_dir;
developer8051e042022-04-08 13:26:36 +08001717static struct proc_dir_entry *proc_esw_cnt, *proc_dbg_regs, *proc_reset_event;
developerfd40db22021-04-29 10:08:25 +08001718
1719int debug_proc_init(struct mtk_eth *eth)
1720{
1721 g_eth = eth;
1722
1723 if (!proc_reg_dir)
1724 proc_reg_dir = proc_mkdir(PROCREG_DIR, NULL);
1725
1726 proc_tx_ring =
1727 proc_create(PROCREG_TXRING, 0, proc_reg_dir, &tx_ring_fops);
1728 if (!proc_tx_ring)
1729 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_TXRING);
1730
developer8051e042022-04-08 13:26:36 +08001731 proc_hwtx_ring =
1732 proc_create(PROCREG_HWTXRING, 0, proc_reg_dir, &hwtx_ring_fops);
1733 if (!proc_hwtx_ring)
1734 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_HWTXRING);
1735
developerfd40db22021-04-29 10:08:25 +08001736 proc_rx_ring =
1737 proc_create(PROCREG_RXRING, 0, proc_reg_dir, &rx_ring_fops);
1738 if (!proc_rx_ring)
1739 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_RXRING);
1740
1741 proc_esw_cnt =
1742 proc_create(PROCREG_ESW_CNT, 0, proc_reg_dir, &switch_count_fops);
1743 if (!proc_esw_cnt)
1744 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_ESW_CNT);
1745
1746 proc_dbg_regs =
1747 proc_create(PROCREG_DBG_REGS, 0, proc_reg_dir, &dbg_regs_fops);
1748 if (!proc_dbg_regs)
1749 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_DBG_REGS);
1750
developer77d03a72021-06-06 00:06:00 +08001751 if (g_eth->hwlro) {
1752 proc_hw_lro_stats =
1753 proc_create(PROCREG_HW_LRO_STATS, 0, proc_reg_dir,
1754 &hw_lro_stats_fops);
1755 if (!proc_hw_lro_stats)
1756 pr_info("!! FAIL to create %s PROC !!\n", PROCREG_HW_LRO_STATS);
1757
1758 proc_hw_lro_auto_tlb =
1759 proc_create(PROCREG_HW_LRO_AUTO_TLB, 0, proc_reg_dir,
1760 &hw_lro_auto_tlb_fops);
1761 if (!proc_hw_lro_auto_tlb)
1762 pr_info("!! FAIL to create %s PROC !!\n",
1763 PROCREG_HW_LRO_AUTO_TLB);
1764 }
1765
developer8051e042022-04-08 13:26:36 +08001766 proc_reset_event =
1767 proc_create(PROCREG_RESET_EVENT, 0, proc_reg_dir, &reset_event_fops);
1768 if (!proc_reset_event)
1769 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_RESET_EVENT);
1770
developerfd40db22021-04-29 10:08:25 +08001771 return 0;
1772}
1773
1774void debug_proc_exit(void)
1775{
1776 if (proc_tx_ring)
1777 remove_proc_entry(PROCREG_TXRING, proc_reg_dir);
developer8051e042022-04-08 13:26:36 +08001778 if (proc_hwtx_ring)
1779 remove_proc_entry(PROCREG_HWTXRING, proc_reg_dir);
developerfd40db22021-04-29 10:08:25 +08001780 if (proc_rx_ring)
1781 remove_proc_entry(PROCREG_RXRING, proc_reg_dir);
1782
1783 if (proc_esw_cnt)
1784 remove_proc_entry(PROCREG_ESW_CNT, proc_reg_dir);
1785
1786 if (proc_reg_dir)
1787 remove_proc_entry(PROCREG_DIR, 0);
1788
1789 if (proc_dbg_regs)
1790 remove_proc_entry(PROCREG_DBG_REGS, proc_reg_dir);
developer77d03a72021-06-06 00:06:00 +08001791
1792 if (g_eth->hwlro) {
1793 if (proc_hw_lro_stats)
1794 remove_proc_entry(PROCREG_HW_LRO_STATS, proc_reg_dir);
1795
1796 if (proc_hw_lro_auto_tlb)
1797 remove_proc_entry(PROCREG_HW_LRO_AUTO_TLB, proc_reg_dir);
1798 }
developer8051e042022-04-08 13:26:36 +08001799
1800 if (proc_reset_event)
1801 remove_proc_entry(PROCREG_RESET_EVENT, proc_reg_dir);
developerfd40db22021-04-29 10:08:25 +08001802}
1803