blob: 69e92dbddeb257283fb4cc0a353aa55b469a23cb [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:
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++) {
developer8b6f2402022-11-28 13:42:34 +0800769 dma_addr_t tmp = ring->phys +
770 i * (dma_addr_t)eth->soc->txrx.txd_size;
developere9356982022-07-04 09:03:20 +0800771
772 tx_ring = ring->dma + i * eth->soc->txrx.txd_size;
developerfd40db22021-04-29 10:08:25 +0800773
774 seq_printf(seq, "%d (%pad): %08x %08x %08x %08x", i, &tmp,
developere9356982022-07-04 09:03:20 +0800775 tx_ring->txd1, tx_ring->txd2,
776 tx_ring->txd3, tx_ring->txd4);
777
developer089e8852022-09-28 14:43:46 +0800778 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
779 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developere9356982022-07-04 09:03:20 +0800780 seq_printf(seq, " %08x %08x %08x %08x",
781 tx_ring->txd5, tx_ring->txd6,
782 tx_ring->txd7, tx_ring->txd8);
783 }
784
developerfd40db22021-04-29 10:08:25 +0800785 seq_printf(seq, "\n");
786 }
787
developerfd40db22021-04-29 10:08:25 +0800788 return 0;
789}
790
791static int tx_ring_open(struct inode *inode, struct file *file)
792{
793 return single_open(file, tx_ring_read, NULL);
794}
795
796static const struct file_operations tx_ring_fops = {
797 .owner = THIS_MODULE,
798 .open = tx_ring_open,
799 .read = seq_read,
800 .llseek = seq_lseek,
801 .release = single_release
802};
803
developer8051e042022-04-08 13:26:36 +0800804int hwtx_ring_read(struct seq_file *seq, void *v)
805{
806 struct mtk_eth *eth = g_eth;
developere9356982022-07-04 09:03:20 +0800807 struct mtk_tx_dma_v2 *hwtx_ring;
developer8051e042022-04-08 13:26:36 +0800808 int i = 0;
809
developer8051e042022-04-08 13:26:36 +0800810 for (i = 0; i < MTK_DMA_SIZE; i++) {
developer8b6f2402022-11-28 13:42:34 +0800811 dma_addr_t addr = eth->phy_scratch_ring +
812 i * (dma_addr_t)eth->soc->txrx.txd_size;
developere9356982022-07-04 09:03:20 +0800813
814 hwtx_ring = eth->scratch_ring + i * eth->soc->txrx.txd_size;
developer8051e042022-04-08 13:26:36 +0800815
816 seq_printf(seq, "%d (%pad): %08x %08x %08x %08x", i, &addr,
developere9356982022-07-04 09:03:20 +0800817 hwtx_ring->txd1, hwtx_ring->txd2,
818 hwtx_ring->txd3, hwtx_ring->txd4);
819
developer089e8852022-09-28 14:43:46 +0800820 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
821 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developere9356982022-07-04 09:03:20 +0800822 seq_printf(seq, " %08x %08x %08x %08x",
823 hwtx_ring->txd5, hwtx_ring->txd6,
824 hwtx_ring->txd7, hwtx_ring->txd8);
825 }
826
developer8051e042022-04-08 13:26:36 +0800827 seq_printf(seq, "\n");
828 }
829
developer8051e042022-04-08 13:26:36 +0800830 return 0;
831}
832
833static int hwtx_ring_open(struct inode *inode, struct file *file)
834{
835 return single_open(file, hwtx_ring_read, NULL);
836}
837
838static const struct file_operations hwtx_ring_fops = {
839 .owner = THIS_MODULE,
840 .open = hwtx_ring_open,
841 .read = seq_read,
842 .llseek = seq_lseek,
843 .release = single_release
844};
845
developerfd40db22021-04-29 10:08:25 +0800846int rx_ring_read(struct seq_file *seq, void *v)
847{
developere9356982022-07-04 09:03:20 +0800848 struct mtk_eth *eth = g_eth;
developerfd40db22021-04-29 10:08:25 +0800849 struct mtk_rx_ring *ring = &g_eth->rx_ring[0];
developere9356982022-07-04 09:03:20 +0800850 struct mtk_rx_dma_v2 *rx_ring;
developerfd40db22021-04-29 10:08:25 +0800851 int i = 0;
852
developerfd40db22021-04-29 10:08:25 +0800853 seq_printf(seq, "next to read: %d\n",
854 NEXT_DESP_IDX(ring->calc_idx, MTK_DMA_SIZE));
855 for (i = 0; i < MTK_DMA_SIZE; i++) {
developere9356982022-07-04 09:03:20 +0800856 rx_ring = ring->dma + i * eth->soc->txrx.rxd_size;
857
developerfd40db22021-04-29 10:08:25 +0800858 seq_printf(seq, "%d: %08x %08x %08x %08x", i,
developere9356982022-07-04 09:03:20 +0800859 rx_ring->rxd1, rx_ring->rxd2,
860 rx_ring->rxd3, rx_ring->rxd4);
861
developer089e8852022-09-28 14:43:46 +0800862 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
863 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developere9356982022-07-04 09:03:20 +0800864 seq_printf(seq, " %08x %08x %08x %08x",
865 rx_ring->rxd5, rx_ring->rxd6,
866 rx_ring->rxd7, rx_ring->rxd8);
867 }
868
developerfd40db22021-04-29 10:08:25 +0800869 seq_printf(seq, "\n");
870 }
871
developerfd40db22021-04-29 10:08:25 +0800872 return 0;
873}
874
875static int rx_ring_open(struct inode *inode, struct file *file)
876{
877 return single_open(file, rx_ring_read, NULL);
878}
879
880static const struct file_operations rx_ring_fops = {
881 .owner = THIS_MODULE,
882 .open = rx_ring_open,
883 .read = seq_read,
884 .llseek = seq_lseek,
885 .release = single_release
886};
887
developer77f3fd42021-10-05 15:16:05 +0800888static inline u32 mtk_dbg_r32(u32 reg)
889{
890 void __iomem *virt_reg;
891 u32 val;
892
893 virt_reg = ioremap(reg, 32);
894 val = __raw_readl(virt_reg);
895 iounmap(virt_reg);
896
897 return val;
898}
899
developerfd40db22021-04-29 10:08:25 +0800900int dbg_regs_read(struct seq_file *seq, void *v)
901{
902 struct mtk_eth *eth = g_eth;
903
developer77f3fd42021-10-05 15:16:05 +0800904 seq_puts(seq, " <<DEBUG REG DUMP>>\n");
905
906 seq_printf(seq, "| FE_INT_STA : %08x |\n",
developer8051e042022-04-08 13:26:36 +0800907 mtk_r32(eth, MTK_FE_INT_STATUS));
developer089e8852022-09-28 14:43:46 +0800908 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
909 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
developer77f3fd42021-10-05 15:16:05 +0800910 seq_printf(seq, "| FE_INT_STA2 : %08x |\n",
developer8051e042022-04-08 13:26:36 +0800911 mtk_r32(eth, MTK_FE_INT_STATUS2));
developer77f3fd42021-10-05 15:16:05 +0800912
developerfd40db22021-04-29 10:08:25 +0800913 seq_printf(seq, "| PSE_FQFC_CFG : %08x |\n",
914 mtk_r32(eth, MTK_PSE_FQFC_CFG));
915 seq_printf(seq, "| PSE_IQ_STA1 : %08x |\n",
916 mtk_r32(eth, MTK_PSE_IQ_STA(0)));
917 seq_printf(seq, "| PSE_IQ_STA2 : %08x |\n",
918 mtk_r32(eth, MTK_PSE_IQ_STA(1)));
919
developer089e8852022-09-28 14:43:46 +0800920 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
921 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developerfd40db22021-04-29 10:08:25 +0800922 seq_printf(seq, "| PSE_IQ_STA3 : %08x |\n",
923 mtk_r32(eth, MTK_PSE_IQ_STA(2)));
924 seq_printf(seq, "| PSE_IQ_STA4 : %08x |\n",
925 mtk_r32(eth, MTK_PSE_IQ_STA(3)));
developer77f3fd42021-10-05 15:16:05 +0800926 seq_printf(seq, "| PSE_IQ_STA5 : %08x |\n",
927 mtk_r32(eth, MTK_PSE_IQ_STA(4)));
developer089e8852022-09-28 14:43:46 +0800928 seq_printf(seq, "| PSE_IQ_STA6 : %08x |\n",
929 mtk_r32(eth, MTK_PSE_IQ_STA(5)));
930 seq_printf(seq, "| PSE_IQ_STA7 : %08x |\n",
931 mtk_r32(eth, MTK_PSE_IQ_STA(6)));
932 seq_printf(seq, "| PSE_IQ_STA8 : %08x |\n",
933 mtk_r32(eth, MTK_PSE_IQ_STA(7)));
developerfd40db22021-04-29 10:08:25 +0800934 }
935
936 seq_printf(seq, "| PSE_OQ_STA1 : %08x |\n",
937 mtk_r32(eth, MTK_PSE_OQ_STA(0)));
938 seq_printf(seq, "| PSE_OQ_STA2 : %08x |\n",
939 mtk_r32(eth, MTK_PSE_OQ_STA(1)));
940
developer089e8852022-09-28 14:43:46 +0800941 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
942 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developerfd40db22021-04-29 10:08:25 +0800943 seq_printf(seq, "| PSE_OQ_STA3 : %08x |\n",
944 mtk_r32(eth, MTK_PSE_OQ_STA(2)));
945 seq_printf(seq, "| PSE_OQ_STA4 : %08x |\n",
946 mtk_r32(eth, MTK_PSE_OQ_STA(3)));
developer77f3fd42021-10-05 15:16:05 +0800947 seq_printf(seq, "| PSE_OQ_STA5 : %08x |\n",
948 mtk_r32(eth, MTK_PSE_OQ_STA(4)));
developer089e8852022-09-28 14:43:46 +0800949 seq_printf(seq, "| PSE_OQ_STA6 : %08x |\n",
950 mtk_r32(eth, MTK_PSE_OQ_STA(5)));
951 seq_printf(seq, "| PSE_OQ_STA7 : %08x |\n",
952 mtk_r32(eth, MTK_PSE_OQ_STA(6)));
953 seq_printf(seq, "| PSE_OQ_STA8 : %08x |\n",
954 mtk_r32(eth, MTK_PSE_OQ_STA(7)));
developerfd40db22021-04-29 10:08:25 +0800955 }
956
developer77f3fd42021-10-05 15:16:05 +0800957 seq_printf(seq, "| PDMA_CRX_IDX : %08x |\n",
958 mtk_r32(eth, MTK_PRX_CRX_IDX0));
959 seq_printf(seq, "| PDMA_DRX_IDX : %08x |\n",
960 mtk_r32(eth, MTK_PRX_DRX_IDX0));
961 seq_printf(seq, "| QDMA_CTX_IDX : %08x |\n",
962 mtk_r32(eth, MTK_QTX_CTX_PTR));
963 seq_printf(seq, "| QDMA_DTX_IDX : %08x |\n",
964 mtk_r32(eth, MTK_QTX_DTX_PTR));
developerfd40db22021-04-29 10:08:25 +0800965 seq_printf(seq, "| QDMA_FQ_CNT : %08x |\n",
966 mtk_r32(eth, MTK_QDMA_FQ_CNT));
developer089e8852022-09-28 14:43:46 +0800967 seq_printf(seq, "| QDMA_FWD_CNT : %08x |\n",
968 mtk_r32(eth, MTK_QDMA_FWD_CNT));
969 seq_printf(seq, "| QDMA_FSM : %08x |\n",
970 mtk_r32(eth, MTK_QDMA_FSM));
developerfd40db22021-04-29 10:08:25 +0800971 seq_printf(seq, "| FE_PSE_FREE : %08x |\n",
972 mtk_r32(eth, MTK_FE_PSE_FREE));
973 seq_printf(seq, "| FE_DROP_FQ : %08x |\n",
974 mtk_r32(eth, MTK_FE_DROP_FQ));
975 seq_printf(seq, "| FE_DROP_FC : %08x |\n",
976 mtk_r32(eth, MTK_FE_DROP_FC));
977 seq_printf(seq, "| FE_DROP_PPE : %08x |\n",
978 mtk_r32(eth, MTK_FE_DROP_PPE));
979 seq_printf(seq, "| GDM1_IG_CTRL : %08x |\n",
980 mtk_r32(eth, MTK_GDMA_FWD_CFG(0)));
981 seq_printf(seq, "| GDM2_IG_CTRL : %08x |\n",
982 mtk_r32(eth, MTK_GDMA_FWD_CFG(1)));
developer089e8852022-09-28 14:43:46 +0800983 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
984 seq_printf(seq, "| GDM3_IG_CTRL : %08x |\n",
985 mtk_r32(eth, MTK_GDMA_FWD_CFG(2)));
986 }
developerfd40db22021-04-29 10:08:25 +0800987 seq_printf(seq, "| MAC_P1_MCR : %08x |\n",
988 mtk_r32(eth, MTK_MAC_MCR(0)));
989 seq_printf(seq, "| MAC_P2_MCR : %08x |\n",
990 mtk_r32(eth, MTK_MAC_MCR(1)));
developer089e8852022-09-28 14:43:46 +0800991 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
992 seq_printf(seq, "| MAC_P3_MCR : %08x |\n",
993 mtk_r32(eth, MTK_MAC_MCR(2)));
994 }
developer77f3fd42021-10-05 15:16:05 +0800995 seq_printf(seq, "| MAC_P1_FSM : %08x |\n",
996 mtk_r32(eth, MTK_MAC_FSM(0)));
997 seq_printf(seq, "| MAC_P2_FSM : %08x |\n",
998 mtk_r32(eth, MTK_MAC_FSM(1)));
developer089e8852022-09-28 14:43:46 +0800999 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
1000 seq_printf(seq, "| MAC_P3_FSM : %08x |\n",
1001 mtk_r32(eth, MTK_MAC_FSM(2)));
1002 }
developerfd40db22021-04-29 10:08:25 +08001003
developer089e8852022-09-28 14:43:46 +08001004 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1005 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developerfd40db22021-04-29 10:08:25 +08001006 seq_printf(seq, "| FE_CDM1_FSM : %08x |\n",
1007 mtk_r32(eth, MTK_FE_CDM1_FSM));
1008 seq_printf(seq, "| FE_CDM2_FSM : %08x |\n",
1009 mtk_r32(eth, MTK_FE_CDM2_FSM));
developer77f3fd42021-10-05 15:16:05 +08001010 seq_printf(seq, "| FE_CDM3_FSM : %08x |\n",
1011 mtk_r32(eth, MTK_FE_CDM3_FSM));
1012 seq_printf(seq, "| FE_CDM4_FSM : %08x |\n",
1013 mtk_r32(eth, MTK_FE_CDM4_FSM));
developer089e8852022-09-28 14:43:46 +08001014 seq_printf(seq, "| FE_CDM5_FSM : %08x |\n",
1015 mtk_r32(eth, MTK_FE_CDM5_FSM));
1016 seq_printf(seq, "| FE_CDM6_FSM : %08x |\n",
1017 mtk_r32(eth, MTK_FE_CDM6_FSM));
developerfd40db22021-04-29 10:08:25 +08001018 seq_printf(seq, "| FE_GDM1_FSM : %08x |\n",
1019 mtk_r32(eth, MTK_FE_GDM1_FSM));
1020 seq_printf(seq, "| FE_GDM2_FSM : %08x |\n",
1021 mtk_r32(eth, MTK_FE_GDM2_FSM));
developer77f3fd42021-10-05 15:16:05 +08001022 seq_printf(seq, "| SGMII_EFUSE : %08x |\n",
1023 mtk_dbg_r32(MTK_SGMII_EFUSE));
1024 seq_printf(seq, "| SGMII0_RX_CNT : %08x |\n",
1025 mtk_dbg_r32(MTK_SGMII_FALSE_CARRIER_CNT(0)));
1026 seq_printf(seq, "| SGMII1_RX_CNT : %08x |\n",
1027 mtk_dbg_r32(MTK_SGMII_FALSE_CARRIER_CNT(1)));
1028 seq_printf(seq, "| WED_RTQM_GLO : %08x |\n",
1029 mtk_dbg_r32(MTK_WED_RTQM_GLO_CFG));
developerfd40db22021-04-29 10:08:25 +08001030 }
1031
developer8051e042022-04-08 13:26:36 +08001032 mtk_w32(eth, 0xffffffff, MTK_FE_INT_STATUS);
developer089e8852022-09-28 14:43:46 +08001033 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1034 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
developer8051e042022-04-08 13:26:36 +08001035 mtk_w32(eth, 0xffffffff, MTK_FE_INT_STATUS2);
developer77f3fd42021-10-05 15:16:05 +08001036
developerfd40db22021-04-29 10:08:25 +08001037 return 0;
1038}
1039
1040static int dbg_regs_open(struct inode *inode, struct file *file)
1041{
1042 return single_open(file, dbg_regs_read, 0);
1043}
1044
1045static const struct file_operations dbg_regs_fops = {
1046 .owner = THIS_MODULE,
1047 .open = dbg_regs_open,
1048 .read = seq_read,
1049 .llseek = seq_lseek,
developer77d03a72021-06-06 00:06:00 +08001050 .release = single_release
1051};
1052
developere9356982022-07-04 09:03:20 +08001053void hw_lro_stats_update(u32 ring_no, struct mtk_rx_dma_v2 *rxd)
developer77d03a72021-06-06 00:06:00 +08001054{
developere9356982022-07-04 09:03:20 +08001055 struct mtk_eth *eth = g_eth;
developer77d03a72021-06-06 00:06:00 +08001056 u32 idx, agg_cnt, agg_size;
1057
developer089e8852022-09-28 14:43:46 +08001058 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1059 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developere9356982022-07-04 09:03:20 +08001060 idx = ring_no - 4;
1061 agg_cnt = RX_DMA_GET_AGG_CNT_V2(rxd->rxd6);
1062 } else {
1063 idx = ring_no - 1;
1064 agg_cnt = RX_DMA_GET_AGG_CNT(rxd->rxd2);
1065 }
developer77d03a72021-06-06 00:06:00 +08001066
developer8b6f2402022-11-28 13:42:34 +08001067 if (idx >= MTK_HW_LRO_RING_NUM)
1068 return;
1069
developer77d03a72021-06-06 00:06:00 +08001070 agg_size = RX_DMA_GET_PLEN0(rxd->rxd2);
1071
1072 hw_lro_agg_size_cnt[idx][agg_size / 5000]++;
1073 hw_lro_agg_num_cnt[idx][agg_cnt]++;
1074 hw_lro_tot_flush_cnt[idx]++;
1075 hw_lro_tot_agg_cnt[idx] += agg_cnt;
1076}
1077
developere9356982022-07-04 09:03:20 +08001078void hw_lro_flush_stats_update(u32 ring_no, struct mtk_rx_dma_v2 *rxd)
developer77d03a72021-06-06 00:06:00 +08001079{
developere9356982022-07-04 09:03:20 +08001080 struct mtk_eth *eth = g_eth;
developer77d03a72021-06-06 00:06:00 +08001081 u32 idx, flush_reason;
1082
developer089e8852022-09-28 14:43:46 +08001083 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1084 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
developere9356982022-07-04 09:03:20 +08001085 idx = ring_no - 4;
1086 flush_reason = RX_DMA_GET_FLUSH_RSN_V2(rxd->rxd6);
1087 } else {
1088 idx = ring_no - 1;
1089 flush_reason = RX_DMA_GET_REV(rxd->rxd2);
1090 }
developer77d03a72021-06-06 00:06:00 +08001091
developer8b6f2402022-11-28 13:42:34 +08001092 if (idx >= MTK_HW_LRO_RING_NUM)
1093 return;
1094
developer77d03a72021-06-06 00:06:00 +08001095 if ((flush_reason & 0x7) == MTK_HW_LRO_AGG_FLUSH)
1096 hw_lro_agg_flush_cnt[idx]++;
1097 else if ((flush_reason & 0x7) == MTK_HW_LRO_AGE_FLUSH)
1098 hw_lro_age_flush_cnt[idx]++;
1099 else if ((flush_reason & 0x7) == MTK_HW_LRO_NOT_IN_SEQ_FLUSH)
1100 hw_lro_seq_flush_cnt[idx]++;
1101 else if ((flush_reason & 0x7) == MTK_HW_LRO_TIMESTAMP_FLUSH)
1102 hw_lro_timestamp_flush_cnt[idx]++;
1103 else if ((flush_reason & 0x7) == MTK_HW_LRO_NON_RULE_FLUSH)
1104 hw_lro_norule_flush_cnt[idx]++;
1105}
1106
1107ssize_t hw_lro_stats_write(struct file *file, const char __user *buffer,
1108 size_t count, loff_t *data)
1109{
1110 memset(hw_lro_agg_num_cnt, 0, sizeof(hw_lro_agg_num_cnt));
1111 memset(hw_lro_agg_size_cnt, 0, sizeof(hw_lro_agg_size_cnt));
1112 memset(hw_lro_tot_agg_cnt, 0, sizeof(hw_lro_tot_agg_cnt));
1113 memset(hw_lro_tot_flush_cnt, 0, sizeof(hw_lro_tot_flush_cnt));
1114 memset(hw_lro_agg_flush_cnt, 0, sizeof(hw_lro_agg_flush_cnt));
1115 memset(hw_lro_age_flush_cnt, 0, sizeof(hw_lro_age_flush_cnt));
1116 memset(hw_lro_seq_flush_cnt, 0, sizeof(hw_lro_seq_flush_cnt));
1117 memset(hw_lro_timestamp_flush_cnt, 0,
1118 sizeof(hw_lro_timestamp_flush_cnt));
1119 memset(hw_lro_norule_flush_cnt, 0, sizeof(hw_lro_norule_flush_cnt));
1120
1121 pr_info("clear hw lro cnt table\n");
1122
1123 return count;
1124}
1125
1126int hw_lro_stats_read_v1(struct seq_file *seq, void *v)
1127{
1128 int i;
1129
1130 seq_puts(seq, "HW LRO statistic dump:\n");
1131
1132 /* Agg number count */
1133 seq_puts(seq, "Cnt: RING1 | RING2 | RING3 | Total\n");
1134 for (i = 0; i <= MTK_HW_LRO_MAX_AGG_CNT; i++) {
1135 seq_printf(seq, " %d : %d %d %d %d\n",
1136 i, hw_lro_agg_num_cnt[0][i],
1137 hw_lro_agg_num_cnt[1][i], hw_lro_agg_num_cnt[2][i],
1138 hw_lro_agg_num_cnt[0][i] + hw_lro_agg_num_cnt[1][i] +
1139 hw_lro_agg_num_cnt[2][i]);
1140 }
1141
1142 /* Total agg count */
1143 seq_puts(seq, "Total agg: RING1 | RING2 | RING3 | Total\n");
1144 seq_printf(seq, " %d %d %d %d\n",
1145 hw_lro_tot_agg_cnt[0], hw_lro_tot_agg_cnt[1],
1146 hw_lro_tot_agg_cnt[2],
1147 hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1148 hw_lro_tot_agg_cnt[2]);
1149
1150 /* Total flush count */
1151 seq_puts(seq, "Total flush: RING1 | RING2 | RING3 | Total\n");
1152 seq_printf(seq, " %d %d %d %d\n",
1153 hw_lro_tot_flush_cnt[0], hw_lro_tot_flush_cnt[1],
1154 hw_lro_tot_flush_cnt[2],
1155 hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1156 hw_lro_tot_flush_cnt[2]);
1157
1158 /* Avg agg count */
1159 seq_puts(seq, "Avg agg: RING1 | RING2 | RING3 | Total\n");
1160 seq_printf(seq, " %d %d %d %d\n",
1161 (hw_lro_tot_flush_cnt[0]) ?
1162 hw_lro_tot_agg_cnt[0] / hw_lro_tot_flush_cnt[0] : 0,
1163 (hw_lro_tot_flush_cnt[1]) ?
1164 hw_lro_tot_agg_cnt[1] / hw_lro_tot_flush_cnt[1] : 0,
1165 (hw_lro_tot_flush_cnt[2]) ?
1166 hw_lro_tot_agg_cnt[2] / hw_lro_tot_flush_cnt[2] : 0,
1167 (hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1168 hw_lro_tot_flush_cnt[2]) ?
1169 ((hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1170 hw_lro_tot_agg_cnt[2]) / (hw_lro_tot_flush_cnt[0] +
1171 hw_lro_tot_flush_cnt[1] + hw_lro_tot_flush_cnt[2])) : 0);
1172
1173 /* Statistics of aggregation size counts */
1174 seq_puts(seq, "HW LRO flush pkt len:\n");
1175 seq_puts(seq, " Length | RING1 | RING2 | RING3 | Total\n");
1176 for (i = 0; i < 15; i++) {
1177 seq_printf(seq, "%d~%d: %d %d %d %d\n", i * 5000,
1178 (i + 1) * 5000, hw_lro_agg_size_cnt[0][i],
1179 hw_lro_agg_size_cnt[1][i], hw_lro_agg_size_cnt[2][i],
1180 hw_lro_agg_size_cnt[0][i] +
1181 hw_lro_agg_size_cnt[1][i] +
1182 hw_lro_agg_size_cnt[2][i]);
1183 }
1184
1185 seq_puts(seq, "Flush reason: RING1 | RING2 | RING3 | Total\n");
1186 seq_printf(seq, "AGG timeout: %d %d %d %d\n",
1187 hw_lro_agg_flush_cnt[0], hw_lro_agg_flush_cnt[1],
1188 hw_lro_agg_flush_cnt[2],
1189 (hw_lro_agg_flush_cnt[0] + hw_lro_agg_flush_cnt[1] +
1190 hw_lro_agg_flush_cnt[2]));
1191
1192 seq_printf(seq, "AGE timeout: %d %d %d %d\n",
1193 hw_lro_age_flush_cnt[0], hw_lro_age_flush_cnt[1],
1194 hw_lro_age_flush_cnt[2],
1195 (hw_lro_age_flush_cnt[0] + hw_lro_age_flush_cnt[1] +
1196 hw_lro_age_flush_cnt[2]));
1197
1198 seq_printf(seq, "Not in-sequence: %d %d %d %d\n",
1199 hw_lro_seq_flush_cnt[0], hw_lro_seq_flush_cnt[1],
1200 hw_lro_seq_flush_cnt[2],
1201 (hw_lro_seq_flush_cnt[0] + hw_lro_seq_flush_cnt[1] +
1202 hw_lro_seq_flush_cnt[2]));
1203
1204 seq_printf(seq, "Timestamp: %d %d %d %d\n",
1205 hw_lro_timestamp_flush_cnt[0],
1206 hw_lro_timestamp_flush_cnt[1],
1207 hw_lro_timestamp_flush_cnt[2],
1208 (hw_lro_timestamp_flush_cnt[0] +
1209 hw_lro_timestamp_flush_cnt[1] +
1210 hw_lro_timestamp_flush_cnt[2]));
1211
1212 seq_printf(seq, "No LRO rule: %d %d %d %d\n",
1213 hw_lro_norule_flush_cnt[0],
1214 hw_lro_norule_flush_cnt[1],
1215 hw_lro_norule_flush_cnt[2],
1216 (hw_lro_norule_flush_cnt[0] +
1217 hw_lro_norule_flush_cnt[1] +
1218 hw_lro_norule_flush_cnt[2]));
1219
1220 return 0;
1221}
1222
1223int hw_lro_stats_read_v2(struct seq_file *seq, void *v)
1224{
1225 int i;
1226
1227 seq_puts(seq, "HW LRO statistic dump:\n");
1228
1229 /* Agg number count */
1230 seq_puts(seq, "Cnt: RING4 | RING5 | RING6 | RING7 Total\n");
1231 for (i = 0; i <= MTK_HW_LRO_MAX_AGG_CNT; i++) {
1232 seq_printf(seq,
1233 " %d : %d %d %d %d %d\n",
1234 i, hw_lro_agg_num_cnt[0][i], hw_lro_agg_num_cnt[1][i],
1235 hw_lro_agg_num_cnt[2][i], hw_lro_agg_num_cnt[3][i],
1236 hw_lro_agg_num_cnt[0][i] + hw_lro_agg_num_cnt[1][i] +
1237 hw_lro_agg_num_cnt[2][i] + hw_lro_agg_num_cnt[3][i]);
1238 }
1239
1240 /* Total agg count */
1241 seq_puts(seq, "Total agg: RING4 | RING5 | RING6 | RING7 Total\n");
1242 seq_printf(seq, " %d %d %d %d %d\n",
1243 hw_lro_tot_agg_cnt[0], hw_lro_tot_agg_cnt[1],
1244 hw_lro_tot_agg_cnt[2], hw_lro_tot_agg_cnt[3],
1245 hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1246 hw_lro_tot_agg_cnt[2] + hw_lro_tot_agg_cnt[3]);
1247
1248 /* Total flush count */
1249 seq_puts(seq, "Total flush: RING4 | RING5 | RING6 | RING7 Total\n");
1250 seq_printf(seq, " %d %d %d %d %d\n",
1251 hw_lro_tot_flush_cnt[0], hw_lro_tot_flush_cnt[1],
1252 hw_lro_tot_flush_cnt[2], hw_lro_tot_flush_cnt[3],
1253 hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1254 hw_lro_tot_flush_cnt[2] + hw_lro_tot_flush_cnt[3]);
1255
1256 /* Avg agg count */
1257 seq_puts(seq, "Avg agg: RING4 | RING5 | RING6 | RING7 Total\n");
1258 seq_printf(seq, " %d %d %d %d %d\n",
1259 (hw_lro_tot_flush_cnt[0]) ?
1260 hw_lro_tot_agg_cnt[0] / hw_lro_tot_flush_cnt[0] : 0,
1261 (hw_lro_tot_flush_cnt[1]) ?
1262 hw_lro_tot_agg_cnt[1] / hw_lro_tot_flush_cnt[1] : 0,
1263 (hw_lro_tot_flush_cnt[2]) ?
1264 hw_lro_tot_agg_cnt[2] / hw_lro_tot_flush_cnt[2] : 0,
1265 (hw_lro_tot_flush_cnt[3]) ?
1266 hw_lro_tot_agg_cnt[3] / hw_lro_tot_flush_cnt[3] : 0,
1267 (hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1268 hw_lro_tot_flush_cnt[2] + hw_lro_tot_flush_cnt[3]) ?
1269 ((hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1270 hw_lro_tot_agg_cnt[2] + hw_lro_tot_agg_cnt[3]) /
1271 (hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1272 hw_lro_tot_flush_cnt[2] + hw_lro_tot_flush_cnt[3])) : 0);
1273
1274 /* Statistics of aggregation size counts */
1275 seq_puts(seq, "HW LRO flush pkt len:\n");
1276 seq_puts(seq, " Length | RING4 | RING5 | RING6 | RING7 Total\n");
1277 for (i = 0; i < 15; i++) {
1278 seq_printf(seq, "%d~%d: %d %d %d %d %d\n",
1279 i * 5000, (i + 1) * 5000,
1280 hw_lro_agg_size_cnt[0][i], hw_lro_agg_size_cnt[1][i],
1281 hw_lro_agg_size_cnt[2][i], hw_lro_agg_size_cnt[3][i],
1282 hw_lro_agg_size_cnt[0][i] +
1283 hw_lro_agg_size_cnt[1][i] +
1284 hw_lro_agg_size_cnt[2][i] +
1285 hw_lro_agg_size_cnt[3][i]);
1286 }
1287
1288 seq_puts(seq, "Flush reason: RING4 | RING5 | RING6 | RING7 Total\n");
1289 seq_printf(seq, "AGG timeout: %d %d %d %d %d\n",
1290 hw_lro_agg_flush_cnt[0], hw_lro_agg_flush_cnt[1],
1291 hw_lro_agg_flush_cnt[2], hw_lro_agg_flush_cnt[3],
1292 (hw_lro_agg_flush_cnt[0] + hw_lro_agg_flush_cnt[1] +
1293 hw_lro_agg_flush_cnt[2] + hw_lro_agg_flush_cnt[3]));
1294
1295 seq_printf(seq, "AGE timeout: %d %d %d %d %d\n",
1296 hw_lro_age_flush_cnt[0], hw_lro_age_flush_cnt[1],
1297 hw_lro_age_flush_cnt[2], hw_lro_age_flush_cnt[3],
1298 (hw_lro_age_flush_cnt[0] + hw_lro_age_flush_cnt[1] +
1299 hw_lro_age_flush_cnt[2] + hw_lro_age_flush_cnt[3]));
1300
1301 seq_printf(seq, "Not in-sequence: %d %d %d %d %d\n",
1302 hw_lro_seq_flush_cnt[0], hw_lro_seq_flush_cnt[1],
1303 hw_lro_seq_flush_cnt[2], hw_lro_seq_flush_cnt[3],
1304 (hw_lro_seq_flush_cnt[0] + hw_lro_seq_flush_cnt[1] +
1305 hw_lro_seq_flush_cnt[2] + hw_lro_seq_flush_cnt[3]));
1306
1307 seq_printf(seq, "Timestamp: %d %d %d %d %d\n",
1308 hw_lro_timestamp_flush_cnt[0],
1309 hw_lro_timestamp_flush_cnt[1],
1310 hw_lro_timestamp_flush_cnt[2],
1311 hw_lro_timestamp_flush_cnt[3],
1312 (hw_lro_timestamp_flush_cnt[0] +
1313 hw_lro_timestamp_flush_cnt[1] +
1314 hw_lro_timestamp_flush_cnt[2] +
1315 hw_lro_timestamp_flush_cnt[3]));
1316
1317 seq_printf(seq, "No LRO rule: %d %d %d %d %d\n",
1318 hw_lro_norule_flush_cnt[0],
1319 hw_lro_norule_flush_cnt[1],
1320 hw_lro_norule_flush_cnt[2],
1321 hw_lro_norule_flush_cnt[3],
1322 (hw_lro_norule_flush_cnt[0] +
1323 hw_lro_norule_flush_cnt[1] +
1324 hw_lro_norule_flush_cnt[2] +
1325 hw_lro_norule_flush_cnt[3]));
1326
1327 return 0;
1328}
1329
1330int hw_lro_stats_read_wrapper(struct seq_file *seq, void *v)
1331{
1332 struct mtk_eth *eth = g_eth;
1333
developer089e8852022-09-28 14:43:46 +08001334 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
1335 MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
developer77d03a72021-06-06 00:06:00 +08001336 hw_lro_stats_read_v2(seq, v);
1337 else
1338 hw_lro_stats_read_v1(seq, v);
1339
1340 return 0;
1341}
1342
1343static int hw_lro_stats_open(struct inode *inode, struct file *file)
1344{
1345 return single_open(file, hw_lro_stats_read_wrapper, NULL);
1346}
1347
1348static const struct file_operations hw_lro_stats_fops = {
1349 .owner = THIS_MODULE,
1350 .open = hw_lro_stats_open,
1351 .read = seq_read,
1352 .llseek = seq_lseek,
1353 .write = hw_lro_stats_write,
developerfd40db22021-04-29 10:08:25 +08001354 .release = single_release
1355};
1356
developer77d03a72021-06-06 00:06:00 +08001357int hwlro_agg_cnt_ctrl(int cnt)
1358{
1359 int i;
1360
1361 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1362 SET_PDMA_RXRING_MAX_AGG_CNT(g_eth, i, cnt);
1363
1364 return 0;
1365}
1366
1367int hwlro_agg_time_ctrl(int time)
1368{
1369 int i;
1370
1371 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1372 SET_PDMA_RXRING_AGG_TIME(g_eth, i, time);
1373
1374 return 0;
1375}
1376
1377int hwlro_age_time_ctrl(int time)
1378{
1379 int i;
1380
1381 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1382 SET_PDMA_RXRING_AGE_TIME(g_eth, i, time);
1383
1384 return 0;
1385}
1386
1387int hwlro_threshold_ctrl(int bandwidth)
1388{
1389 SET_PDMA_LRO_BW_THRESHOLD(g_eth, bandwidth);
1390
1391 return 0;
1392}
1393
1394int hwlro_ring_enable_ctrl(int enable)
1395{
1396 int i;
1397
1398 pr_info("[%s] %s HW LRO rings\n", __func__, (enable) ? "Enable" : "Disable");
1399
1400 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1401 SET_PDMA_RXRING_VALID(g_eth, i, enable);
1402
1403 return 0;
1404}
1405
1406int hwlro_stats_enable_ctrl(int enable)
1407{
1408 pr_info("[%s] %s HW LRO statistics\n", __func__, (enable) ? "Enable" : "Disable");
1409 mtk_hwlro_stats_ebl = enable;
1410
1411 return 0;
1412}
1413
1414static const mtk_lro_dbg_func lro_dbg_func[] = {
1415 [0] = hwlro_agg_cnt_ctrl,
1416 [1] = hwlro_agg_time_ctrl,
1417 [2] = hwlro_age_time_ctrl,
1418 [3] = hwlro_threshold_ctrl,
1419 [4] = hwlro_ring_enable_ctrl,
1420 [5] = hwlro_stats_enable_ctrl,
1421};
1422
1423ssize_t hw_lro_auto_tlb_write(struct file *file, const char __user *buffer,
1424 size_t count, loff_t *data)
1425{
1426 char buf[32];
1427 char *p_buf;
1428 char *p_token = NULL;
1429 char *p_delimiter = " \t";
1430 long x = 0, y = 0;
developer4c32b7a2021-11-13 16:46:43 +08001431 u32 len = count;
developer77d03a72021-06-06 00:06:00 +08001432 int ret;
1433
1434 if (len >= sizeof(buf)) {
1435 pr_info("Input handling fail!\n");
developer77d03a72021-06-06 00:06:00 +08001436 return -1;
1437 }
1438
1439 if (copy_from_user(buf, buffer, len))
1440 return -EFAULT;
1441
1442 buf[len] = '\0';
1443
1444 p_buf = buf;
1445 p_token = strsep(&p_buf, p_delimiter);
1446 if (!p_token)
1447 x = 0;
1448 else
1449 ret = kstrtol(p_token, 10, &x);
1450
1451 p_token = strsep(&p_buf, "\t\n ");
1452 if (p_token)
1453 ret = kstrtol(p_token, 10, &y);
1454
1455 if (lro_dbg_func[x] && (ARRAY_SIZE(lro_dbg_func) > x))
1456 (*lro_dbg_func[x]) (y);
1457
1458 return count;
1459}
1460
1461void hw_lro_auto_tlb_dump_v1(struct seq_file *seq, u32 index)
1462{
1463 int i;
1464 struct mtk_lro_alt_v1 alt;
1465 __be32 addr;
1466 u32 tlb_info[9];
1467 u32 dw_len, cnt, priority;
1468 u32 entry;
1469
1470 if (index > 4)
1471 index = index - 1;
1472 entry = (index * 9) + 1;
1473
1474 /* read valid entries of the auto-learn table */
1475 mtk_w32(g_eth, entry, MTK_FE_ALT_CF8);
1476
1477 for (i = 0; i < 9; i++)
1478 tlb_info[i] = mtk_r32(g_eth, MTK_FE_ALT_SEQ_CFC);
1479
1480 memcpy(&alt, tlb_info, sizeof(struct mtk_lro_alt_v1));
1481
1482 dw_len = alt.alt_info7.dw_len;
1483 cnt = alt.alt_info6.cnt;
1484
1485 if (mtk_r32(g_eth, MTK_PDMA_LRO_CTRL_DW0) & MTK_LRO_ALT_PKT_CNT_MODE)
1486 priority = cnt; /* packet count */
1487 else
1488 priority = dw_len; /* byte count */
1489
1490 /* dump valid entries of the auto-learn table */
1491 if (index >= 4)
1492 seq_printf(seq, "\n===== TABLE Entry: %d (Act) =====\n", index);
1493 else
1494 seq_printf(seq, "\n===== TABLE Entry: %d (LRU) =====\n", index);
1495
1496 if (alt.alt_info8.ipv4) {
1497 addr = htonl(alt.alt_info1.sip0);
1498 seq_printf(seq, "SIP = %pI4 (IPv4)\n", &addr);
1499 } else {
1500 seq_printf(seq, "SIP = %08X:%08X:%08X:%08X (IPv6)\n",
1501 alt.alt_info4.sip3, alt.alt_info3.sip2,
1502 alt.alt_info2.sip1, alt.alt_info1.sip0);
1503 }
1504
1505 seq_printf(seq, "DIP_ID = %d\n", alt.alt_info8.dip_id);
1506 seq_printf(seq, "TCP SPORT = %d | TCP DPORT = %d\n",
1507 alt.alt_info0.stp, alt.alt_info0.dtp);
1508 seq_printf(seq, "VLAN_VID_VLD = %d\n", alt.alt_info6.vlan_vid_vld);
1509 seq_printf(seq, "VLAN1 = %d | VLAN2 = %d | VLAN3 = %d | VLAN4 =%d\n",
1510 (alt.alt_info5.vlan_vid0 & 0xfff),
1511 ((alt.alt_info5.vlan_vid0 >> 12) & 0xfff),
1512 ((alt.alt_info6.vlan_vid1 << 8) |
1513 ((alt.alt_info5.vlan_vid0 >> 24) & 0xfff)),
1514 ((alt.alt_info6.vlan_vid1 >> 4) & 0xfff));
1515 seq_printf(seq, "TPUT = %d | FREQ = %d\n", dw_len, cnt);
1516 seq_printf(seq, "PRIORITY = %d\n", priority);
1517}
1518
1519void hw_lro_auto_tlb_dump_v2(struct seq_file *seq, u32 index)
1520{
1521 int i;
1522 struct mtk_lro_alt_v2 alt;
1523 u32 score = 0, ipv4 = 0;
1524 u32 ipv6[4] = { 0 };
1525 u32 tlb_info[12];
1526
1527 /* read valid entries of the auto-learn table */
1528 mtk_w32(g_eth, index << MTK_LRO_ALT_INDEX_OFFSET, MTK_LRO_ALT_DBG);
1529
1530 for (i = 0; i < 11; i++)
1531 tlb_info[i] = mtk_r32(g_eth, MTK_LRO_ALT_DBG_DATA);
1532
1533 memcpy(&alt, tlb_info, sizeof(struct mtk_lro_alt_v2));
1534
1535 if (mtk_r32(g_eth, MTK_PDMA_LRO_CTRL_DW0) & MTK_LRO_ALT_PKT_CNT_MODE)
1536 score = 1; /* packet count */
1537 else
1538 score = 0; /* byte count */
1539
1540 /* dump valid entries of the auto-learn table */
1541 if (alt.alt_info0.valid) {
1542 if (index < 5)
1543 seq_printf(seq,
1544 "\n===== TABLE Entry: %d (onging) =====\n",
1545 index);
1546 else
1547 seq_printf(seq,
1548 "\n===== TABLE Entry: %d (candidate) =====\n",
1549 index);
1550
1551 if (alt.alt_info1.v4_valid) {
1552 ipv4 = (alt.alt_info4.sip0_h << 23) |
1553 alt.alt_info5.sip0_l;
1554 seq_printf(seq, "SIP = 0x%x: (IPv4)\n", ipv4);
1555
1556 ipv4 = (alt.alt_info8.dip0_h << 23) |
1557 alt.alt_info9.dip0_l;
1558 seq_printf(seq, "DIP = 0x%x: (IPv4)\n", ipv4);
1559 } else if (alt.alt_info1.v6_valid) {
1560 ipv6[3] = (alt.alt_info1.sip3_h << 23) |
1561 (alt.alt_info2.sip3_l << 9);
1562 ipv6[2] = (alt.alt_info2.sip2_h << 23) |
1563 (alt.alt_info3.sip2_l << 9);
1564 ipv6[1] = (alt.alt_info3.sip1_h << 23) |
1565 (alt.alt_info4.sip1_l << 9);
1566 ipv6[0] = (alt.alt_info4.sip0_h << 23) |
1567 (alt.alt_info5.sip0_l << 9);
1568 seq_printf(seq, "SIP = 0x%x:0x%x:0x%x:0x%x (IPv6)\n",
1569 ipv6[3], ipv6[2], ipv6[1], ipv6[0]);
1570
1571 ipv6[3] = (alt.alt_info5.dip3_h << 23) |
1572 (alt.alt_info6.dip3_l << 9);
1573 ipv6[2] = (alt.alt_info6.dip2_h << 23) |
1574 (alt.alt_info7.dip2_l << 9);
1575 ipv6[1] = (alt.alt_info7.dip1_h << 23) |
1576 (alt.alt_info8.dip1_l << 9);
1577 ipv6[0] = (alt.alt_info8.dip0_h << 23) |
1578 (alt.alt_info9.dip0_l << 9);
1579 seq_printf(seq, "DIP = 0x%x:0x%x:0x%x:0x%x (IPv6)\n",
1580 ipv6[3], ipv6[2], ipv6[1], ipv6[0]);
1581 }
1582
1583 seq_printf(seq, "TCP SPORT = %d | TCP DPORT = %d\n",
1584 (alt.alt_info9.sp_h << 7) | (alt.alt_info10.sp_l),
1585 alt.alt_info10.dp);
1586 }
1587}
1588
1589int hw_lro_auto_tlb_read(struct seq_file *seq, void *v)
1590{
1591 int i;
1592 u32 reg_val;
1593 u32 reg_op1, reg_op2, reg_op3, reg_op4;
1594 u32 agg_cnt, agg_time, age_time;
1595
1596 seq_puts(seq, "Usage of /proc/mtketh/hw_lro_auto_tlb:\n");
1597 seq_puts(seq, "echo [function] [setting] > /proc/mtketh/hw_lro_auto_tlb\n");
1598 seq_puts(seq, "Functions:\n");
1599 seq_puts(seq, "[0] = hwlro_agg_cnt_ctrl\n");
1600 seq_puts(seq, "[1] = hwlro_agg_time_ctrl\n");
1601 seq_puts(seq, "[2] = hwlro_age_time_ctrl\n");
1602 seq_puts(seq, "[3] = hwlro_threshold_ctrl\n");
1603 seq_puts(seq, "[4] = hwlro_ring_enable_ctrl\n");
1604 seq_puts(seq, "[5] = hwlro_stats_enable_ctrl\n\n");
1605
developer089e8852022-09-28 14:43:46 +08001606 if (MTK_HAS_CAPS(g_eth->soc->caps, MTK_NETSYS_V2) ||
1607 MTK_HAS_CAPS(g_eth->soc->caps, MTK_NETSYS_V3)) {
developer77d03a72021-06-06 00:06:00 +08001608 for (i = 1; i <= 8; i++)
1609 hw_lro_auto_tlb_dump_v2(seq, i);
1610 } else {
1611 /* Read valid entries of the auto-learn table */
1612 mtk_w32(g_eth, 0, MTK_FE_ALT_CF8);
1613 reg_val = mtk_r32(g_eth, MTK_FE_ALT_SEQ_CFC);
1614
1615 seq_printf(seq,
1616 "HW LRO Auto-learn Table: (MTK_FE_ALT_SEQ_CFC=0x%x)\n",
1617 reg_val);
1618
1619 for (i = 7; i >= 0; i--) {
1620 if (reg_val & (1 << i))
1621 hw_lro_auto_tlb_dump_v1(seq, i);
1622 }
1623 }
1624
1625 /* Read the agg_time/age_time/agg_cnt of LRO rings */
1626 seq_puts(seq, "\nHW LRO Ring Settings\n");
1627
1628 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++) {
1629 reg_op1 = mtk_r32(g_eth, MTK_LRO_CTRL_DW1_CFG(i));
1630 reg_op2 = mtk_r32(g_eth, MTK_LRO_CTRL_DW2_CFG(i));
1631 reg_op3 = mtk_r32(g_eth, MTK_LRO_CTRL_DW3_CFG(i));
1632 reg_op4 = mtk_r32(g_eth, MTK_PDMA_LRO_CTRL_DW2);
1633
1634 agg_cnt =
1635 ((reg_op3 & 0x3) << 6) |
1636 ((reg_op2 >> MTK_LRO_RING_AGG_CNT_L_OFFSET) & 0x3f);
1637 agg_time = (reg_op2 >> MTK_LRO_RING_AGG_TIME_OFFSET) & 0xffff;
1638 age_time =
1639 ((reg_op2 & 0x3f) << 10) |
1640 ((reg_op1 >> MTK_LRO_RING_AGE_TIME_L_OFFSET) & 0x3ff);
1641 seq_printf(seq,
1642 "Ring[%d]: MAX_AGG_CNT=%d, AGG_TIME=%d, AGE_TIME=%d, Threshold=%d\n",
developer089e8852022-09-28 14:43:46 +08001643 (MTK_HAS_CAPS(g_eth->soc->caps, MTK_NETSYS_V1)) ? i : i+3,
developer77d03a72021-06-06 00:06:00 +08001644 agg_cnt, agg_time, age_time, reg_op4);
1645 }
1646
1647 seq_puts(seq, "\n");
1648
1649 return 0;
1650}
1651
1652static int hw_lro_auto_tlb_open(struct inode *inode, struct file *file)
1653{
1654 return single_open(file, hw_lro_auto_tlb_read, NULL);
1655}
1656
1657static const struct file_operations hw_lro_auto_tlb_fops = {
1658 .owner = THIS_MODULE,
1659 .open = hw_lro_auto_tlb_open,
1660 .read = seq_read,
1661 .llseek = seq_lseek,
1662 .write = hw_lro_auto_tlb_write,
1663 .release = single_release
1664};
developerfd40db22021-04-29 10:08:25 +08001665
developer8051e042022-04-08 13:26:36 +08001666int reset_event_read(struct seq_file *seq, void *v)
1667{
1668 struct mtk_eth *eth = g_eth;
1669 struct mtk_reset_event reset_event = eth->reset_event;
1670
1671 seq_printf(seq, "[Event] [Count]\n");
1672 seq_printf(seq, " FQ Empty: %d\n",
1673 reset_event.count[MTK_EVENT_FQ_EMPTY]);
1674 seq_printf(seq, " TSO Fail: %d\n",
1675 reset_event.count[MTK_EVENT_TSO_FAIL]);
1676 seq_printf(seq, " TSO Illegal: %d\n",
1677 reset_event.count[MTK_EVENT_TSO_ILLEGAL]);
1678 seq_printf(seq, " TSO Align: %d\n",
1679 reset_event.count[MTK_EVENT_TSO_ALIGN]);
1680 seq_printf(seq, " RFIFO OV: %d\n",
1681 reset_event.count[MTK_EVENT_RFIFO_OV]);
1682 seq_printf(seq, " RFIFO UF: %d\n",
1683 reset_event.count[MTK_EVENT_RFIFO_UF]);
1684 seq_printf(seq, " Force: %d\n",
1685 reset_event.count[MTK_EVENT_FORCE]);
1686 seq_printf(seq, "----------------------------\n");
1687 seq_printf(seq, " Warm Cnt: %d\n",
1688 reset_event.count[MTK_EVENT_WARM_CNT]);
1689 seq_printf(seq, " Cold Cnt: %d\n",
1690 reset_event.count[MTK_EVENT_COLD_CNT]);
1691 seq_printf(seq, " Total Cnt: %d\n",
1692 reset_event.count[MTK_EVENT_TOTAL_CNT]);
1693
1694 return 0;
1695}
1696
1697static int reset_event_open(struct inode *inode, struct file *file)
1698{
1699 return single_open(file, reset_event_read, 0);
1700}
1701
1702ssize_t reset_event_write(struct file *file, const char __user *buffer,
1703 size_t count, loff_t *data)
1704{
1705 struct mtk_eth *eth = g_eth;
1706 struct mtk_reset_event *reset_event = &eth->reset_event;
1707
1708 memset(reset_event, 0, sizeof(struct mtk_reset_event));
1709 pr_info("MTK reset event counter is cleared !\n");
1710
1711 return count;
1712}
1713
1714static const struct file_operations reset_event_fops = {
1715 .owner = THIS_MODULE,
1716 .open = reset_event_open,
1717 .read = seq_read,
1718 .llseek = seq_lseek,
1719 .write = reset_event_write,
1720 .release = single_release
1721};
1722
1723
developerfd40db22021-04-29 10:08:25 +08001724struct proc_dir_entry *proc_reg_dir;
developer8051e042022-04-08 13:26:36 +08001725static struct proc_dir_entry *proc_esw_cnt, *proc_dbg_regs, *proc_reset_event;
developerfd40db22021-04-29 10:08:25 +08001726
1727int debug_proc_init(struct mtk_eth *eth)
1728{
1729 g_eth = eth;
1730
1731 if (!proc_reg_dir)
1732 proc_reg_dir = proc_mkdir(PROCREG_DIR, NULL);
1733
1734 proc_tx_ring =
1735 proc_create(PROCREG_TXRING, 0, proc_reg_dir, &tx_ring_fops);
1736 if (!proc_tx_ring)
1737 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_TXRING);
1738
developer8051e042022-04-08 13:26:36 +08001739 proc_hwtx_ring =
1740 proc_create(PROCREG_HWTXRING, 0, proc_reg_dir, &hwtx_ring_fops);
1741 if (!proc_hwtx_ring)
1742 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_HWTXRING);
1743
developerfd40db22021-04-29 10:08:25 +08001744 proc_rx_ring =
1745 proc_create(PROCREG_RXRING, 0, proc_reg_dir, &rx_ring_fops);
1746 if (!proc_rx_ring)
1747 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_RXRING);
1748
1749 proc_esw_cnt =
1750 proc_create(PROCREG_ESW_CNT, 0, proc_reg_dir, &switch_count_fops);
1751 if (!proc_esw_cnt)
1752 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_ESW_CNT);
1753
1754 proc_dbg_regs =
1755 proc_create(PROCREG_DBG_REGS, 0, proc_reg_dir, &dbg_regs_fops);
1756 if (!proc_dbg_regs)
1757 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_DBG_REGS);
1758
developer77d03a72021-06-06 00:06:00 +08001759 if (g_eth->hwlro) {
1760 proc_hw_lro_stats =
1761 proc_create(PROCREG_HW_LRO_STATS, 0, proc_reg_dir,
1762 &hw_lro_stats_fops);
1763 if (!proc_hw_lro_stats)
1764 pr_info("!! FAIL to create %s PROC !!\n", PROCREG_HW_LRO_STATS);
1765
1766 proc_hw_lro_auto_tlb =
1767 proc_create(PROCREG_HW_LRO_AUTO_TLB, 0, proc_reg_dir,
1768 &hw_lro_auto_tlb_fops);
1769 if (!proc_hw_lro_auto_tlb)
1770 pr_info("!! FAIL to create %s PROC !!\n",
1771 PROCREG_HW_LRO_AUTO_TLB);
1772 }
1773
developer8051e042022-04-08 13:26:36 +08001774 proc_reset_event =
1775 proc_create(PROCREG_RESET_EVENT, 0, proc_reg_dir, &reset_event_fops);
1776 if (!proc_reset_event)
1777 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_RESET_EVENT);
1778
developerfd40db22021-04-29 10:08:25 +08001779 return 0;
1780}
1781
1782void debug_proc_exit(void)
1783{
1784 if (proc_tx_ring)
1785 remove_proc_entry(PROCREG_TXRING, proc_reg_dir);
developer8051e042022-04-08 13:26:36 +08001786 if (proc_hwtx_ring)
1787 remove_proc_entry(PROCREG_HWTXRING, proc_reg_dir);
developerfd40db22021-04-29 10:08:25 +08001788 if (proc_rx_ring)
1789 remove_proc_entry(PROCREG_RXRING, proc_reg_dir);
1790
1791 if (proc_esw_cnt)
1792 remove_proc_entry(PROCREG_ESW_CNT, proc_reg_dir);
1793
1794 if (proc_reg_dir)
1795 remove_proc_entry(PROCREG_DIR, 0);
1796
1797 if (proc_dbg_regs)
1798 remove_proc_entry(PROCREG_DBG_REGS, proc_reg_dir);
developer77d03a72021-06-06 00:06:00 +08001799
1800 if (g_eth->hwlro) {
1801 if (proc_hw_lro_stats)
1802 remove_proc_entry(PROCREG_HW_LRO_STATS, proc_reg_dir);
1803
1804 if (proc_hw_lro_auto_tlb)
1805 remove_proc_entry(PROCREG_HW_LRO_AUTO_TLB, proc_reg_dir);
1806 }
developer8051e042022-04-08 13:26:36 +08001807
1808 if (proc_reset_event)
1809 remove_proc_entry(PROCREG_RESET_EVENT, proc_reg_dir);
developerfd40db22021-04-29 10:08:25 +08001810}
1811