blob: 979bc9b5ec5047606376f536703b4bd383fd51db [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>
27
28#include "mtk_eth_soc.h"
29#include "mtk_eth_dbg.h"
30
developer77d03a72021-06-06 00:06:00 +080031u32 hw_lro_agg_num_cnt[MTK_HW_LRO_RING_NUM][MTK_HW_LRO_MAX_AGG_CNT + 1];
32u32 hw_lro_agg_size_cnt[MTK_HW_LRO_RING_NUM][16];
33u32 hw_lro_tot_agg_cnt[MTK_HW_LRO_RING_NUM];
34u32 hw_lro_tot_flush_cnt[MTK_HW_LRO_RING_NUM];
35u32 hw_lro_agg_flush_cnt[MTK_HW_LRO_RING_NUM];
36u32 hw_lro_age_flush_cnt[MTK_HW_LRO_RING_NUM];
37u32 hw_lro_seq_flush_cnt[MTK_HW_LRO_RING_NUM];
38u32 hw_lro_timestamp_flush_cnt[MTK_HW_LRO_RING_NUM];
39u32 hw_lro_norule_flush_cnt[MTK_HW_LRO_RING_NUM];
40u32 mtk_hwlro_stats_ebl;
41static struct proc_dir_entry *proc_hw_lro_stats, *proc_hw_lro_auto_tlb;
42typedef int (*mtk_lro_dbg_func) (int par);
43
developerfd40db22021-04-29 10:08:25 +080044struct mtk_eth_debug {
45 struct dentry *root;
46};
47
48struct mtk_eth *g_eth;
49
50struct mtk_eth_debug eth_debug;
51
developer3957a912021-05-13 16:44:31 +080052void mt7530_mdio_w32(struct mtk_eth *eth, u16 reg, u32 val)
developerfd40db22021-04-29 10:08:25 +080053{
54 mutex_lock(&eth->mii_bus->mdio_lock);
55
56 _mtk_mdio_write(eth, 0x1f, 0x1f, (reg >> 6) & 0x3ff);
57 _mtk_mdio_write(eth, 0x1f, (reg >> 2) & 0xf, val & 0xffff);
58 _mtk_mdio_write(eth, 0x1f, 0x10, val >> 16);
59
60 mutex_unlock(&eth->mii_bus->mdio_lock);
61}
62
63u32 mt7530_mdio_r32(struct mtk_eth *eth, u32 reg)
64{
65 u16 high, low;
66
67 mutex_lock(&eth->mii_bus->mdio_lock);
68
69 _mtk_mdio_write(eth, 0x1f, 0x1f, (reg >> 6) & 0x3ff);
70 low = _mtk_mdio_read(eth, 0x1f, (reg >> 2) & 0xf);
71 high = _mtk_mdio_read(eth, 0x1f, 0x10);
72
73 mutex_unlock(&eth->mii_bus->mdio_lock);
74
75 return (high << 16) | (low & 0xffff);
76}
77
78void mtk_switch_w32(struct mtk_eth *eth, u32 val, unsigned reg)
79{
80 mtk_w32(eth, val, reg + 0x10000);
81}
82EXPORT_SYMBOL(mtk_switch_w32);
83
84u32 mtk_switch_r32(struct mtk_eth *eth, unsigned reg)
85{
86 return mtk_r32(eth, reg + 0x10000);
87}
88EXPORT_SYMBOL(mtk_switch_r32);
89
90static int mtketh_debug_show(struct seq_file *m, void *private)
91{
92 struct mtk_eth *eth = m->private;
93 struct mtk_mac *mac = 0;
developer77d03a72021-06-06 00:06:00 +080094 int i = 0;
developerfd40db22021-04-29 10:08:25 +080095
96 for (i = 0 ; i < MTK_MAX_DEVS ; i++) {
97 if (!eth->mac[i] ||
98 of_phy_is_fixed_link(eth->mac[i]->of_node))
99 continue;
100 mac = eth->mac[i];
101#if 0 //FIXME
102 while (j < 30) {
103 d = _mtk_mdio_read(eth, mac->phy_dev->addr, j);
104
105 seq_printf(m, "phy=%d, reg=0x%08x, data=0x%08x\n",
106 mac->phy_dev->addr, j, d);
107 j++;
108 }
109#endif
110 }
111 return 0;
112}
113
114static int mtketh_debug_open(struct inode *inode, struct file *file)
115{
116 return single_open(file, mtketh_debug_show, inode->i_private);
117}
118
119static const struct file_operations mtketh_debug_fops = {
120 .open = mtketh_debug_open,
121 .read = seq_read,
122 .llseek = seq_lseek,
123 .release = single_release,
124};
125
126static int mtketh_mt7530sw_debug_show(struct seq_file *m, void *private)
127{
128 struct mtk_eth *eth = m->private;
129 u32 offset, data;
130 int i;
131 struct mt7530_ranges {
132 u32 start;
133 u32 end;
134 } ranges[] = {
135 {0x0, 0xac},
136 {0x1000, 0x10e0},
137 {0x1100, 0x1140},
138 {0x1200, 0x1240},
139 {0x1300, 0x1340},
140 {0x1400, 0x1440},
141 {0x1500, 0x1540},
142 {0x1600, 0x1640},
143 {0x1800, 0x1848},
144 {0x1900, 0x1948},
145 {0x1a00, 0x1a48},
146 {0x1b00, 0x1b48},
147 {0x1c00, 0x1c48},
148 {0x1d00, 0x1d48},
149 {0x1e00, 0x1e48},
150 {0x1f60, 0x1ffc},
151 {0x2000, 0x212c},
152 {0x2200, 0x222c},
153 {0x2300, 0x232c},
154 {0x2400, 0x242c},
155 {0x2500, 0x252c},
156 {0x2600, 0x262c},
157 {0x3000, 0x3014},
158 {0x30c0, 0x30f8},
159 {0x3100, 0x3114},
160 {0x3200, 0x3214},
161 {0x3300, 0x3314},
162 {0x3400, 0x3414},
163 {0x3500, 0x3514},
164 {0x3600, 0x3614},
165 {0x4000, 0x40d4},
166 {0x4100, 0x41d4},
167 {0x4200, 0x42d4},
168 {0x4300, 0x43d4},
169 {0x4400, 0x44d4},
170 {0x4500, 0x45d4},
171 {0x4600, 0x46d4},
172 {0x4f00, 0x461c},
173 {0x7000, 0x7038},
174 {0x7120, 0x7124},
175 {0x7800, 0x7804},
176 {0x7810, 0x7810},
177 {0x7830, 0x7830},
178 {0x7a00, 0x7a7c},
179 {0x7b00, 0x7b04},
180 {0x7e00, 0x7e04},
181 {0x7ffc, 0x7ffc},
182 };
183
184 if (!mt7530_exist(eth))
185 return -EOPNOTSUPP;
186
187 if ((!eth->mac[0] || !of_phy_is_fixed_link(eth->mac[0]->of_node)) &&
188 (!eth->mac[1] || !of_phy_is_fixed_link(eth->mac[1]->of_node))) {
189 seq_puts(m, "no switch found\n");
190 return 0;
191 }
192
193 for (i = 0 ; i < ARRAY_SIZE(ranges) ; i++) {
194 for (offset = ranges[i].start;
195 offset <= ranges[i].end; offset += 4) {
196 data = mt7530_mdio_r32(eth, offset);
197 seq_printf(m, "mt7530 switch reg=0x%08x, data=0x%08x\n",
198 offset, data);
199 }
200 }
201
202 return 0;
203}
204
205static int mtketh_debug_mt7530sw_open(struct inode *inode, struct file *file)
206{
207 return single_open(file, mtketh_mt7530sw_debug_show, inode->i_private);
208}
209
210static const struct file_operations mtketh_debug_mt7530sw_fops = {
211 .open = mtketh_debug_mt7530sw_open,
212 .read = seq_read,
213 .llseek = seq_lseek,
214 .release = single_release,
215};
216
217static ssize_t mtketh_mt7530sw_debugfs_write(struct file *file,
218 const char __user *ptr,
219 size_t len, loff_t *off)
220{
221 struct mtk_eth *eth = file->private_data;
222 char buf[32], *token, *p = buf;
223 u32 reg, value, phy;
224 int ret;
225
226 if (!mt7530_exist(eth))
227 return -EOPNOTSUPP;
228
229 if (*off != 0)
230 return 0;
231
232 if (len > sizeof(buf) - 1)
233 len = sizeof(buf) - 1;
234
235 ret = strncpy_from_user(buf, ptr, len);
236 if (ret < 0)
237 return ret;
238 buf[len] = '\0';
239
240 token = strsep(&p, " ");
241 if (!token)
242 return -EINVAL;
243 if (kstrtoul(token, 16, (unsigned long *)&phy))
244 return -EINVAL;
245
246 token = strsep(&p, " ");
247 if (!token)
248 return -EINVAL;
249 if (kstrtoul(token, 16, (unsigned long *)&reg))
250 return -EINVAL;
251
252 token = strsep(&p, " ");
253 if (!token)
254 return -EINVAL;
255 if (kstrtoul(token, 16, (unsigned long *)&value))
256 return -EINVAL;
257
258 pr_info("%s:phy=%d, reg=0x%x, val=0x%x\n", __func__,
259 0x1f, reg, value);
260 mt7530_mdio_w32(eth, reg, value);
261 pr_info("%s:phy=%d, reg=0x%x, val=0x%x confirm..\n", __func__,
262 0x1f, reg, mt7530_mdio_r32(eth, reg));
263
264 return len;
265}
266
267static ssize_t mtketh_debugfs_write(struct file *file, const char __user *ptr,
268 size_t len, loff_t *off)
269{
270 struct mtk_eth *eth = file->private_data;
271 char buf[32], *token, *p = buf;
272 u32 reg, value, phy;
273 int ret;
274
275 if (*off != 0)
276 return 0;
277
278 if (len > sizeof(buf) - 1)
279 len = sizeof(buf) - 1;
280
281 ret = strncpy_from_user(buf, ptr, len);
282 if (ret < 0)
283 return ret;
284 buf[len] = '\0';
285
286 token = strsep(&p, " ");
287 if (!token)
288 return -EINVAL;
289 if (kstrtoul(token, 16, (unsigned long *)&phy))
290 return -EINVAL;
291
292 token = strsep(&p, " ");
293
294 if (!token)
295 return -EINVAL;
296 if (kstrtoul(token, 16, (unsigned long *)&reg))
297 return -EINVAL;
298
299 token = strsep(&p, " ");
300
301 if (!token)
302 return -EINVAL;
303 if (kstrtoul(token, 16, (unsigned long *)&value))
304 return -EINVAL;
305
306 pr_info("%s:phy=%d, reg=0x%x, val=0x%x\n", __func__,
307 phy, reg, value);
308
309 _mtk_mdio_write(eth, phy, reg, value);
310
311 pr_info("%s:phy=%d, reg=0x%x, val=0x%x confirm..\n", __func__,
312 phy, reg, _mtk_mdio_read(eth, phy, reg));
313
314 return len;
315}
316
317static ssize_t mtketh_debugfs_reset(struct file *file, const char __user *ptr,
318 size_t len, loff_t *off)
319{
320 struct mtk_eth *eth = file->private_data;
321
322 schedule_work(&eth->pending_work);
323 return len;
324}
325
326static const struct file_operations fops_reg_w = {
327 .owner = THIS_MODULE,
328 .open = simple_open,
329 .write = mtketh_debugfs_write,
330 .llseek = noop_llseek,
331};
332
333static const struct file_operations fops_eth_reset = {
334 .owner = THIS_MODULE,
335 .open = simple_open,
336 .write = mtketh_debugfs_reset,
337 .llseek = noop_llseek,
338};
339
340static const struct file_operations fops_mt7530sw_reg_w = {
341 .owner = THIS_MODULE,
342 .open = simple_open,
343 .write = mtketh_mt7530sw_debugfs_write,
344 .llseek = noop_llseek,
345};
346
347void mtketh_debugfs_exit(struct mtk_eth *eth)
348{
349 debugfs_remove_recursive(eth_debug.root);
350}
351
352int mtketh_debugfs_init(struct mtk_eth *eth)
353{
354 int ret = 0;
355
356 eth_debug.root = debugfs_create_dir("mtketh", NULL);
357 if (!eth_debug.root) {
358 dev_notice(eth->dev, "%s:err at %d\n", __func__, __LINE__);
359 ret = -ENOMEM;
360 }
361
362 debugfs_create_file("phy_regs", S_IRUGO,
363 eth_debug.root, eth, &mtketh_debug_fops);
364 debugfs_create_file("phy_reg_w", S_IFREG | S_IWUSR,
365 eth_debug.root, eth, &fops_reg_w);
366 debugfs_create_file("reset", S_IFREG | S_IWUSR,
367 eth_debug.root, eth, &fops_eth_reset);
368 if (mt7530_exist(eth)) {
369 debugfs_create_file("mt7530sw_regs", S_IRUGO,
370 eth_debug.root, eth,
371 &mtketh_debug_mt7530sw_fops);
372 debugfs_create_file("mt7530sw_reg_w", S_IFREG | S_IWUSR,
373 eth_debug.root, eth,
374 &fops_mt7530sw_reg_w);
375 }
376 return ret;
377}
378
379void mii_mgr_read_combine(struct mtk_eth *eth, u32 phy_addr, u32 phy_register,
380 u32 *read_data)
381{
382 if (mt7530_exist(eth) && phy_addr == 31)
383 *read_data = mt7530_mdio_r32(eth, phy_register);
384
385 else
386 *read_data = _mtk_mdio_read(eth, phy_addr, phy_register);
387}
388
developer3957a912021-05-13 16:44:31 +0800389void mii_mgr_write_combine(struct mtk_eth *eth, u16 phy_addr, u16 phy_register,
developerfd40db22021-04-29 10:08:25 +0800390 u32 write_data)
391{
392 if (mt7530_exist(eth) && phy_addr == 31)
393 mt7530_mdio_w32(eth, phy_register, write_data);
394
395 else
396 _mtk_mdio_write(eth, phy_addr, phy_register, write_data);
397}
398
developer3957a912021-05-13 16:44:31 +0800399static void mii_mgr_read_cl45(struct mtk_eth *eth, u16 port, u16 devad, u16 reg, u16 *data)
developerfd40db22021-04-29 10:08:25 +0800400{
401 mtk_cl45_ind_read(eth, port, devad, reg, data);
402}
403
developer3957a912021-05-13 16:44:31 +0800404static void mii_mgr_write_cl45(struct mtk_eth *eth, u16 port, u16 devad, u16 reg, u16 data)
developerfd40db22021-04-29 10:08:25 +0800405{
406 mtk_cl45_ind_write(eth, port, devad, reg, data);
407}
408
409int mtk_do_priv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
410{
411 struct mtk_mac *mac = netdev_priv(dev);
412 struct mtk_eth *eth = mac->hw;
413 struct mtk_mii_ioctl_data mii;
414 struct mtk_esw_reg reg;
developerba2d1eb2021-05-25 19:26:45 +0800415 u16 val;
developerfd40db22021-04-29 10:08:25 +0800416
417 switch (cmd) {
418 case MTKETH_MII_READ:
419 if (copy_from_user(&mii, ifr->ifr_data, sizeof(mii)))
420 goto err_copy;
421 mii_mgr_read_combine(eth, mii.phy_id, mii.reg_num,
422 &mii.val_out);
423 if (copy_to_user(ifr->ifr_data, &mii, sizeof(mii)))
424 goto err_copy;
425
426 return 0;
427 case MTKETH_MII_WRITE:
428 if (copy_from_user(&mii, ifr->ifr_data, sizeof(mii)))
429 goto err_copy;
430 mii_mgr_write_combine(eth, mii.phy_id, mii.reg_num,
431 mii.val_in);
developerfd40db22021-04-29 10:08:25 +0800432 return 0;
433 case MTKETH_MII_READ_CL45:
434 if (copy_from_user(&mii, ifr->ifr_data, sizeof(mii)))
435 goto err_copy;
developer3957a912021-05-13 16:44:31 +0800436 mii_mgr_read_cl45(eth,
437 mdio_phy_id_prtad(mii.phy_id),
438 mdio_phy_id_devad(mii.phy_id),
439 mii.reg_num,
developerba2d1eb2021-05-25 19:26:45 +0800440 &val);
441 mii.val_out = val;
developerfd40db22021-04-29 10:08:25 +0800442 if (copy_to_user(ifr->ifr_data, &mii, sizeof(mii)))
443 goto err_copy;
444
445 return 0;
446 case MTKETH_MII_WRITE_CL45:
447 if (copy_from_user(&mii, ifr->ifr_data, sizeof(mii)))
448 goto err_copy;
developerba2d1eb2021-05-25 19:26:45 +0800449 val = mii.val_in;
developer3957a912021-05-13 16:44:31 +0800450 mii_mgr_write_cl45(eth,
451 mdio_phy_id_prtad(mii.phy_id),
452 mdio_phy_id_devad(mii.phy_id),
453 mii.reg_num,
developerba2d1eb2021-05-25 19:26:45 +0800454 val);
developerfd40db22021-04-29 10:08:25 +0800455 return 0;
456 case MTKETH_ESW_REG_READ:
457 if (!mt7530_exist(eth))
458 return -EOPNOTSUPP;
459 if (copy_from_user(&reg, ifr->ifr_data, sizeof(reg)))
460 goto err_copy;
461 if (reg.off > REG_ESW_MAX)
462 return -EINVAL;
463 reg.val = mtk_switch_r32(eth, reg.off);
464
465 if (copy_to_user(ifr->ifr_data, &reg, sizeof(reg)))
466 goto err_copy;
467
468 return 0;
469 case MTKETH_ESW_REG_WRITE:
470 if (!mt7530_exist(eth))
471 return -EOPNOTSUPP;
472 if (copy_from_user(&reg, ifr->ifr_data, sizeof(reg)))
473 goto err_copy;
474 if (reg.off > REG_ESW_MAX)
475 return -EINVAL;
476 mtk_switch_w32(eth, reg.val, reg.off);
477
478 return 0;
479 default:
480 break;
481 }
482
483 return -EOPNOTSUPP;
484err_copy:
485 return -EFAULT;
486}
487
488int esw_cnt_read(struct seq_file *seq, void *v)
489{
490 unsigned int pkt_cnt = 0;
491 int i = 0;
492 struct mtk_eth *eth = g_eth;
493 unsigned int mib_base = MTK_GDM1_TX_GBCNT;
494
495 seq_puts(seq, "\n <<CPU>>\n");
496 seq_puts(seq, " |\n");
497 seq_puts(seq, "+-----------------------------------------------+\n");
498 seq_puts(seq, "| <<PSE>> |\n");
499 seq_puts(seq, "+-----------------------------------------------+\n");
500 seq_puts(seq, " |\n");
501 seq_puts(seq, "+-----------------------------------------------+\n");
502 seq_puts(seq, "| <<GDMA>> |\n");
503 seq_printf(seq, "| GDMA1_RX_GBCNT : %010u (Rx Good Bytes) |\n",
504 mtk_r32(eth, mib_base));
505 seq_printf(seq, "| GDMA1_RX_GPCNT : %010u (Rx Good Pkts) |\n",
506 mtk_r32(eth, mib_base+0x08));
507 seq_printf(seq, "| GDMA1_RX_OERCNT : %010u (overflow error) |\n",
508 mtk_r32(eth, mib_base+0x10));
509 seq_printf(seq, "| GDMA1_RX_FERCNT : %010u (FCS error) |\n",
510 mtk_r32(eth, mib_base+0x14));
511 seq_printf(seq, "| GDMA1_RX_SERCNT : %010u (too short) |\n",
512 mtk_r32(eth, mib_base+0x18));
513 seq_printf(seq, "| GDMA1_RX_LERCNT : %010u (too long) |\n",
514 mtk_r32(eth, mib_base+0x1C));
515 seq_printf(seq, "| GDMA1_RX_CERCNT : %010u (checksum error) |\n",
516 mtk_r32(eth, mib_base+0x20));
517 seq_printf(seq, "| GDMA1_RX_FCCNT : %010u (flow control) |\n",
518 mtk_r32(eth, mib_base+0x24));
519 seq_printf(seq, "| GDMA1_TX_SKIPCNT: %010u (about count) |\n",
520 mtk_r32(eth, mib_base+0x28));
521 seq_printf(seq, "| GDMA1_TX_COLCNT : %010u (collision count) |\n",
522 mtk_r32(eth, mib_base+0x2C));
523 seq_printf(seq, "| GDMA1_TX_GBCNT : %010u (Tx Good Bytes) |\n",
524 mtk_r32(eth, mib_base+0x30));
525 seq_printf(seq, "| GDMA1_TX_GPCNT : %010u (Tx Good Pkts) |\n",
526 mtk_r32(eth, mib_base+0x38));
527 seq_puts(seq, "| |\n");
528 seq_printf(seq, "| GDMA2_RX_GBCNT : %010u (Rx Good Bytes) |\n",
529 mtk_r32(eth, mib_base+0x40));
530 seq_printf(seq, "| GDMA2_RX_GPCNT : %010u (Rx Good Pkts) |\n",
531 mtk_r32(eth, mib_base+0x48));
532 seq_printf(seq, "| GDMA2_RX_OERCNT : %010u (overflow error) |\n",
533 mtk_r32(eth, mib_base+0x50));
534 seq_printf(seq, "| GDMA2_RX_FERCNT : %010u (FCS error) |\n",
535 mtk_r32(eth, mib_base+0x54));
536 seq_printf(seq, "| GDMA2_RX_SERCNT : %010u (too short) |\n",
537 mtk_r32(eth, mib_base+0x58));
538 seq_printf(seq, "| GDMA2_RX_LERCNT : %010u (too long) |\n",
539 mtk_r32(eth, mib_base+0x5C));
540 seq_printf(seq, "| GDMA2_RX_CERCNT : %010u (checksum error) |\n",
541 mtk_r32(eth, mib_base+0x60));
542 seq_printf(seq, "| GDMA2_RX_FCCNT : %010u (flow control) |\n",
543 mtk_r32(eth, mib_base+0x64));
544 seq_printf(seq, "| GDMA2_TX_SKIPCNT: %010u (skip) |\n",
545 mtk_r32(eth, mib_base+0x68));
546 seq_printf(seq, "| GDMA2_TX_COLCNT : %010u (collision) |\n",
547 mtk_r32(eth, mib_base+0x6C));
548 seq_printf(seq, "| GDMA2_TX_GBCNT : %010u (Tx Good Bytes) |\n",
549 mtk_r32(eth, mib_base+0x70));
550 seq_printf(seq, "| GDMA2_TX_GPCNT : %010u (Tx Good Pkts) |\n",
551 mtk_r32(eth, mib_base+0x78));
552 seq_puts(seq, "+-----------------------------------------------+\n");
553
554 if (!mt7530_exist(eth))
555 return 0;
556
557#define DUMP_EACH_PORT(base) \
558 do { \
559 for (i = 0; i < 7; i++) { \
560 pkt_cnt = mt7530_mdio_r32(eth, (base) + (i * 0x100));\
561 seq_printf(seq, "%8u ", pkt_cnt); \
562 } \
563 seq_puts(seq, "\n"); \
564 } while (0)
565
566 seq_printf(seq, "===================== %8s %8s %8s %8s %8s %8s %8s\n",
567 "Port0", "Port1", "Port2", "Port3", "Port4", "Port5",
568 "Port6");
569 seq_puts(seq, "Tx Drop Packet :");
570 DUMP_EACH_PORT(0x4000);
571 seq_puts(seq, "Tx CRC Error :");
572 DUMP_EACH_PORT(0x4004);
573 seq_puts(seq, "Tx Unicast Packet :");
574 DUMP_EACH_PORT(0x4008);
575 seq_puts(seq, "Tx Multicast Packet :");
576 DUMP_EACH_PORT(0x400C);
577 seq_puts(seq, "Tx Broadcast Packet :");
578 DUMP_EACH_PORT(0x4010);
579 seq_puts(seq, "Tx Collision Event :");
580 DUMP_EACH_PORT(0x4014);
581 seq_puts(seq, "Tx Pause Packet :");
582 DUMP_EACH_PORT(0x402C);
583 seq_puts(seq, "Rx Drop Packet :");
584 DUMP_EACH_PORT(0x4060);
585 seq_puts(seq, "Rx Filtering Packet :");
586 DUMP_EACH_PORT(0x4064);
587 seq_puts(seq, "Rx Unicast Packet :");
588 DUMP_EACH_PORT(0x4068);
589 seq_puts(seq, "Rx Multicast Packet :");
590 DUMP_EACH_PORT(0x406C);
591 seq_puts(seq, "Rx Broadcast Packet :");
592 DUMP_EACH_PORT(0x4070);
593 seq_puts(seq, "Rx Alignment Error :");
594 DUMP_EACH_PORT(0x4074);
595 seq_puts(seq, "Rx CRC Error :");
596 DUMP_EACH_PORT(0x4078);
597 seq_puts(seq, "Rx Undersize Error :");
598 DUMP_EACH_PORT(0x407C);
599 seq_puts(seq, "Rx Fragment Error :");
600 DUMP_EACH_PORT(0x4080);
601 seq_puts(seq, "Rx Oversize Error :");
602 DUMP_EACH_PORT(0x4084);
603 seq_puts(seq, "Rx Jabber Error :");
604 DUMP_EACH_PORT(0x4088);
605 seq_puts(seq, "Rx Pause Packet :");
606 DUMP_EACH_PORT(0x408C);
607 mt7530_mdio_w32(eth, 0x4fe0, 0xf0);
608 mt7530_mdio_w32(eth, 0x4fe0, 0x800000f0);
609
610 seq_puts(seq, "\n");
611
612 return 0;
613}
614
615static int switch_count_open(struct inode *inode, struct file *file)
616{
617 return single_open(file, esw_cnt_read, 0);
618}
619
620static const struct file_operations switch_count_fops = {
621 .owner = THIS_MODULE,
622 .open = switch_count_open,
623 .read = seq_read,
624 .llseek = seq_lseek,
625 .release = single_release
626};
627
628static struct proc_dir_entry *proc_tx_ring, *proc_rx_ring;
629
630int tx_ring_read(struct seq_file *seq, void *v)
631{
632 struct mtk_tx_ring *ring = &g_eth->tx_ring;
633 struct mtk_tx_dma *tx_ring;
634 int i = 0;
635
636 tx_ring =
637 kmalloc(sizeof(struct mtk_tx_dma) * MTK_DMA_SIZE, GFP_KERNEL);
638 if (!tx_ring) {
639 seq_puts(seq, " allocate temp tx_ring fail.\n");
640 return 0;
641 }
642
643 for (i = 0; i < MTK_DMA_SIZE; i++)
644 tx_ring[i] = ring->dma[i];
645
646 seq_printf(seq, "free count = %d\n", (int)atomic_read(&ring->free_count));
647 seq_printf(seq, "cpu next free: %d\n", (int)(ring->next_free - ring->dma));
648 seq_printf(seq, "cpu last free: %d\n", (int)(ring->last_free - ring->dma));
649 for (i = 0; i < MTK_DMA_SIZE; i++) {
650 dma_addr_t tmp = ring->phys + i * sizeof(*tx_ring);
651
652 seq_printf(seq, "%d (%pad): %08x %08x %08x %08x", i, &tmp,
653 *(int *)&tx_ring[i].txd1, *(int *)&tx_ring[i].txd2,
654 *(int *)&tx_ring[i].txd3, *(int *)&tx_ring[i].txd4);
655#if defined(CONFIG_MEDIATEK_NETSYS_V2)
656 seq_printf(seq, " %08x %08x %08x %08x",
657 *(int *)&tx_ring[i].txd5, *(int *)&tx_ring[i].txd6,
658 *(int *)&tx_ring[i].txd7, *(int *)&tx_ring[i].txd8);
659#endif
660 seq_printf(seq, "\n");
661 }
662
663 kfree(tx_ring);
664 return 0;
665}
666
667static int tx_ring_open(struct inode *inode, struct file *file)
668{
669 return single_open(file, tx_ring_read, NULL);
670}
671
672static const struct file_operations tx_ring_fops = {
673 .owner = THIS_MODULE,
674 .open = tx_ring_open,
675 .read = seq_read,
676 .llseek = seq_lseek,
677 .release = single_release
678};
679
680int rx_ring_read(struct seq_file *seq, void *v)
681{
682 struct mtk_rx_ring *ring = &g_eth->rx_ring[0];
683 struct mtk_rx_dma *rx_ring;
684
685 int i = 0;
686
687 rx_ring =
688 kmalloc(sizeof(struct mtk_rx_dma) * MTK_DMA_SIZE, GFP_KERNEL);
689 if (!rx_ring) {
690 seq_puts(seq, " allocate temp rx_ring fail.\n");
691 return 0;
692 }
693
694 for (i = 0; i < MTK_DMA_SIZE; i++)
695 rx_ring[i] = ring->dma[i];
696
697 seq_printf(seq, "next to read: %d\n",
698 NEXT_DESP_IDX(ring->calc_idx, MTK_DMA_SIZE));
699 for (i = 0; i < MTK_DMA_SIZE; i++) {
700 seq_printf(seq, "%d: %08x %08x %08x %08x", i,
701 *(int *)&rx_ring[i].rxd1, *(int *)&rx_ring[i].rxd2,
702 *(int *)&rx_ring[i].rxd3, *(int *)&rx_ring[i].rxd4);
developera2bdbd52021-05-31 19:10:17 +0800703#if defined(CONFIG_MEDIATEK_NETSYS_V2)
developerfd40db22021-04-29 10:08:25 +0800704 seq_printf(seq, " %08x %08x %08x %08x",
705 *(int *)&rx_ring[i].rxd5, *(int *)&rx_ring[i].rxd6,
706 *(int *)&rx_ring[i].rxd7, *(int *)&rx_ring[i].rxd8);
707#endif
708 seq_printf(seq, "\n");
709 }
710
711 kfree(rx_ring);
712 return 0;
713}
714
715static int rx_ring_open(struct inode *inode, struct file *file)
716{
717 return single_open(file, rx_ring_read, NULL);
718}
719
720static const struct file_operations rx_ring_fops = {
721 .owner = THIS_MODULE,
722 .open = rx_ring_open,
723 .read = seq_read,
724 .llseek = seq_lseek,
725 .release = single_release
726};
727
728int dbg_regs_read(struct seq_file *seq, void *v)
729{
730 struct mtk_eth *eth = g_eth;
731
732 seq_puts(seq, " <<PSE DEBUG REG DUMP>>\n");
733 seq_printf(seq, "| PSE_FQFC_CFG : %08x |\n",
734 mtk_r32(eth, MTK_PSE_FQFC_CFG));
735 seq_printf(seq, "| PSE_IQ_STA1 : %08x |\n",
736 mtk_r32(eth, MTK_PSE_IQ_STA(0)));
737 seq_printf(seq, "| PSE_IQ_STA2 : %08x |\n",
738 mtk_r32(eth, MTK_PSE_IQ_STA(1)));
739
developera2bdbd52021-05-31 19:10:17 +0800740 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
developerfd40db22021-04-29 10:08:25 +0800741 seq_printf(seq, "| PSE_IQ_STA3 : %08x |\n",
742 mtk_r32(eth, MTK_PSE_IQ_STA(2)));
743 seq_printf(seq, "| PSE_IQ_STA4 : %08x |\n",
744 mtk_r32(eth, MTK_PSE_IQ_STA(3)));
745 }
746
747 seq_printf(seq, "| PSE_OQ_STA1 : %08x |\n",
748 mtk_r32(eth, MTK_PSE_OQ_STA(0)));
749 seq_printf(seq, "| PSE_OQ_STA2 : %08x |\n",
750 mtk_r32(eth, MTK_PSE_OQ_STA(1)));
751
developera2bdbd52021-05-31 19:10:17 +0800752 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
developerfd40db22021-04-29 10:08:25 +0800753 seq_printf(seq, "| PSE_OQ_STA3 : %08x |\n",
754 mtk_r32(eth, MTK_PSE_OQ_STA(2)));
755 seq_printf(seq, "| PSE_OQ_STA4 : %08x |\n",
756 mtk_r32(eth, MTK_PSE_OQ_STA(3)));
757 }
758
759 seq_printf(seq, "| QDMA_FQ_CNT : %08x |\n",
760 mtk_r32(eth, MTK_QDMA_FQ_CNT));
761 seq_printf(seq, "| FE_PSE_FREE : %08x |\n",
762 mtk_r32(eth, MTK_FE_PSE_FREE));
763 seq_printf(seq, "| FE_DROP_FQ : %08x |\n",
764 mtk_r32(eth, MTK_FE_DROP_FQ));
765 seq_printf(seq, "| FE_DROP_FC : %08x |\n",
766 mtk_r32(eth, MTK_FE_DROP_FC));
767 seq_printf(seq, "| FE_DROP_PPE : %08x |\n",
768 mtk_r32(eth, MTK_FE_DROP_PPE));
769 seq_printf(seq, "| GDM1_IG_CTRL : %08x |\n",
770 mtk_r32(eth, MTK_GDMA_FWD_CFG(0)));
771 seq_printf(seq, "| GDM2_IG_CTRL : %08x |\n",
772 mtk_r32(eth, MTK_GDMA_FWD_CFG(1)));
773 seq_printf(seq, "| MAC_P1_MCR : %08x |\n",
774 mtk_r32(eth, MTK_MAC_MCR(0)));
775 seq_printf(seq, "| MAC_P2_MCR : %08x |\n",
776 mtk_r32(eth, MTK_MAC_MCR(1)));
777
developera2bdbd52021-05-31 19:10:17 +0800778 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
developerfd40db22021-04-29 10:08:25 +0800779 seq_printf(seq, "| FE_CDM1_FSM : %08x |\n",
780 mtk_r32(eth, MTK_FE_CDM1_FSM));
781 seq_printf(seq, "| FE_CDM2_FSM : %08x |\n",
782 mtk_r32(eth, MTK_FE_CDM2_FSM));
783 seq_printf(seq, "| FE_GDM1_FSM : %08x |\n",
784 mtk_r32(eth, MTK_FE_GDM1_FSM));
785 seq_printf(seq, "| FE_GDM2_FSM : %08x |\n",
786 mtk_r32(eth, MTK_FE_GDM2_FSM));
787 }
788
789 return 0;
790}
791
792static int dbg_regs_open(struct inode *inode, struct file *file)
793{
794 return single_open(file, dbg_regs_read, 0);
795}
796
797static const struct file_operations dbg_regs_fops = {
798 .owner = THIS_MODULE,
799 .open = dbg_regs_open,
800 .read = seq_read,
801 .llseek = seq_lseek,
developer77d03a72021-06-06 00:06:00 +0800802 .release = single_release
803};
804
805void hw_lro_stats_update(u32 ring_no, struct mtk_rx_dma *rxd)
806{
807 u32 idx, agg_cnt, agg_size;
808
809#if defined(CONFIG_MEDIATEK_NETSYS_V2)
810 idx = ring_no - 4;
811 agg_cnt = RX_DMA_GET_AGG_CNT_V2(rxd->rxd6);
812#else
813 idx = ring_no - 1;
814 agg_cnt = RX_DMA_GET_AGG_CNT(rxd->rxd2);
815#endif
816
817 agg_size = RX_DMA_GET_PLEN0(rxd->rxd2);
818
819 hw_lro_agg_size_cnt[idx][agg_size / 5000]++;
820 hw_lro_agg_num_cnt[idx][agg_cnt]++;
821 hw_lro_tot_flush_cnt[idx]++;
822 hw_lro_tot_agg_cnt[idx] += agg_cnt;
823}
824
825void hw_lro_flush_stats_update(u32 ring_no, struct mtk_rx_dma *rxd)
826{
827 u32 idx, flush_reason;
828
829#if defined(CONFIG_MEDIATEK_NETSYS_V2)
830 idx = ring_no - 4;
831 flush_reason = RX_DMA_GET_FLUSH_RSN_V2(rxd->rxd6);
832#else
833 idx = ring_no - 1;
834 flush_reason = RX_DMA_GET_REV(rxd->rxd2);
835#endif
836
837 if ((flush_reason & 0x7) == MTK_HW_LRO_AGG_FLUSH)
838 hw_lro_agg_flush_cnt[idx]++;
839 else if ((flush_reason & 0x7) == MTK_HW_LRO_AGE_FLUSH)
840 hw_lro_age_flush_cnt[idx]++;
841 else if ((flush_reason & 0x7) == MTK_HW_LRO_NOT_IN_SEQ_FLUSH)
842 hw_lro_seq_flush_cnt[idx]++;
843 else if ((flush_reason & 0x7) == MTK_HW_LRO_TIMESTAMP_FLUSH)
844 hw_lro_timestamp_flush_cnt[idx]++;
845 else if ((flush_reason & 0x7) == MTK_HW_LRO_NON_RULE_FLUSH)
846 hw_lro_norule_flush_cnt[idx]++;
847}
848
849ssize_t hw_lro_stats_write(struct file *file, const char __user *buffer,
850 size_t count, loff_t *data)
851{
852 memset(hw_lro_agg_num_cnt, 0, sizeof(hw_lro_agg_num_cnt));
853 memset(hw_lro_agg_size_cnt, 0, sizeof(hw_lro_agg_size_cnt));
854 memset(hw_lro_tot_agg_cnt, 0, sizeof(hw_lro_tot_agg_cnt));
855 memset(hw_lro_tot_flush_cnt, 0, sizeof(hw_lro_tot_flush_cnt));
856 memset(hw_lro_agg_flush_cnt, 0, sizeof(hw_lro_agg_flush_cnt));
857 memset(hw_lro_age_flush_cnt, 0, sizeof(hw_lro_age_flush_cnt));
858 memset(hw_lro_seq_flush_cnt, 0, sizeof(hw_lro_seq_flush_cnt));
859 memset(hw_lro_timestamp_flush_cnt, 0,
860 sizeof(hw_lro_timestamp_flush_cnt));
861 memset(hw_lro_norule_flush_cnt, 0, sizeof(hw_lro_norule_flush_cnt));
862
863 pr_info("clear hw lro cnt table\n");
864
865 return count;
866}
867
868int hw_lro_stats_read_v1(struct seq_file *seq, void *v)
869{
870 int i;
871
872 seq_puts(seq, "HW LRO statistic dump:\n");
873
874 /* Agg number count */
875 seq_puts(seq, "Cnt: RING1 | RING2 | RING3 | Total\n");
876 for (i = 0; i <= MTK_HW_LRO_MAX_AGG_CNT; i++) {
877 seq_printf(seq, " %d : %d %d %d %d\n",
878 i, hw_lro_agg_num_cnt[0][i],
879 hw_lro_agg_num_cnt[1][i], hw_lro_agg_num_cnt[2][i],
880 hw_lro_agg_num_cnt[0][i] + hw_lro_agg_num_cnt[1][i] +
881 hw_lro_agg_num_cnt[2][i]);
882 }
883
884 /* Total agg count */
885 seq_puts(seq, "Total agg: RING1 | RING2 | RING3 | Total\n");
886 seq_printf(seq, " %d %d %d %d\n",
887 hw_lro_tot_agg_cnt[0], hw_lro_tot_agg_cnt[1],
888 hw_lro_tot_agg_cnt[2],
889 hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
890 hw_lro_tot_agg_cnt[2]);
891
892 /* Total flush count */
893 seq_puts(seq, "Total flush: RING1 | RING2 | RING3 | Total\n");
894 seq_printf(seq, " %d %d %d %d\n",
895 hw_lro_tot_flush_cnt[0], hw_lro_tot_flush_cnt[1],
896 hw_lro_tot_flush_cnt[2],
897 hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
898 hw_lro_tot_flush_cnt[2]);
899
900 /* Avg agg count */
901 seq_puts(seq, "Avg agg: RING1 | RING2 | RING3 | Total\n");
902 seq_printf(seq, " %d %d %d %d\n",
903 (hw_lro_tot_flush_cnt[0]) ?
904 hw_lro_tot_agg_cnt[0] / hw_lro_tot_flush_cnt[0] : 0,
905 (hw_lro_tot_flush_cnt[1]) ?
906 hw_lro_tot_agg_cnt[1] / hw_lro_tot_flush_cnt[1] : 0,
907 (hw_lro_tot_flush_cnt[2]) ?
908 hw_lro_tot_agg_cnt[2] / hw_lro_tot_flush_cnt[2] : 0,
909 (hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
910 hw_lro_tot_flush_cnt[2]) ?
911 ((hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
912 hw_lro_tot_agg_cnt[2]) / (hw_lro_tot_flush_cnt[0] +
913 hw_lro_tot_flush_cnt[1] + hw_lro_tot_flush_cnt[2])) : 0);
914
915 /* Statistics of aggregation size counts */
916 seq_puts(seq, "HW LRO flush pkt len:\n");
917 seq_puts(seq, " Length | RING1 | RING2 | RING3 | Total\n");
918 for (i = 0; i < 15; i++) {
919 seq_printf(seq, "%d~%d: %d %d %d %d\n", i * 5000,
920 (i + 1) * 5000, hw_lro_agg_size_cnt[0][i],
921 hw_lro_agg_size_cnt[1][i], hw_lro_agg_size_cnt[2][i],
922 hw_lro_agg_size_cnt[0][i] +
923 hw_lro_agg_size_cnt[1][i] +
924 hw_lro_agg_size_cnt[2][i]);
925 }
926
927 seq_puts(seq, "Flush reason: RING1 | RING2 | RING3 | Total\n");
928 seq_printf(seq, "AGG timeout: %d %d %d %d\n",
929 hw_lro_agg_flush_cnt[0], hw_lro_agg_flush_cnt[1],
930 hw_lro_agg_flush_cnt[2],
931 (hw_lro_agg_flush_cnt[0] + hw_lro_agg_flush_cnt[1] +
932 hw_lro_agg_flush_cnt[2]));
933
934 seq_printf(seq, "AGE timeout: %d %d %d %d\n",
935 hw_lro_age_flush_cnt[0], hw_lro_age_flush_cnt[1],
936 hw_lro_age_flush_cnt[2],
937 (hw_lro_age_flush_cnt[0] + hw_lro_age_flush_cnt[1] +
938 hw_lro_age_flush_cnt[2]));
939
940 seq_printf(seq, "Not in-sequence: %d %d %d %d\n",
941 hw_lro_seq_flush_cnt[0], hw_lro_seq_flush_cnt[1],
942 hw_lro_seq_flush_cnt[2],
943 (hw_lro_seq_flush_cnt[0] + hw_lro_seq_flush_cnt[1] +
944 hw_lro_seq_flush_cnt[2]));
945
946 seq_printf(seq, "Timestamp: %d %d %d %d\n",
947 hw_lro_timestamp_flush_cnt[0],
948 hw_lro_timestamp_flush_cnt[1],
949 hw_lro_timestamp_flush_cnt[2],
950 (hw_lro_timestamp_flush_cnt[0] +
951 hw_lro_timestamp_flush_cnt[1] +
952 hw_lro_timestamp_flush_cnt[2]));
953
954 seq_printf(seq, "No LRO rule: %d %d %d %d\n",
955 hw_lro_norule_flush_cnt[0],
956 hw_lro_norule_flush_cnt[1],
957 hw_lro_norule_flush_cnt[2],
958 (hw_lro_norule_flush_cnt[0] +
959 hw_lro_norule_flush_cnt[1] +
960 hw_lro_norule_flush_cnt[2]));
961
962 return 0;
963}
964
965int hw_lro_stats_read_v2(struct seq_file *seq, void *v)
966{
967 int i;
968
969 seq_puts(seq, "HW LRO statistic dump:\n");
970
971 /* Agg number count */
972 seq_puts(seq, "Cnt: RING4 | RING5 | RING6 | RING7 Total\n");
973 for (i = 0; i <= MTK_HW_LRO_MAX_AGG_CNT; i++) {
974 seq_printf(seq,
975 " %d : %d %d %d %d %d\n",
976 i, hw_lro_agg_num_cnt[0][i], hw_lro_agg_num_cnt[1][i],
977 hw_lro_agg_num_cnt[2][i], hw_lro_agg_num_cnt[3][i],
978 hw_lro_agg_num_cnt[0][i] + hw_lro_agg_num_cnt[1][i] +
979 hw_lro_agg_num_cnt[2][i] + hw_lro_agg_num_cnt[3][i]);
980 }
981
982 /* Total agg count */
983 seq_puts(seq, "Total agg: RING4 | RING5 | RING6 | RING7 Total\n");
984 seq_printf(seq, " %d %d %d %d %d\n",
985 hw_lro_tot_agg_cnt[0], hw_lro_tot_agg_cnt[1],
986 hw_lro_tot_agg_cnt[2], hw_lro_tot_agg_cnt[3],
987 hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
988 hw_lro_tot_agg_cnt[2] + hw_lro_tot_agg_cnt[3]);
989
990 /* Total flush count */
991 seq_puts(seq, "Total flush: RING4 | RING5 | RING6 | RING7 Total\n");
992 seq_printf(seq, " %d %d %d %d %d\n",
993 hw_lro_tot_flush_cnt[0], hw_lro_tot_flush_cnt[1],
994 hw_lro_tot_flush_cnt[2], hw_lro_tot_flush_cnt[3],
995 hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
996 hw_lro_tot_flush_cnt[2] + hw_lro_tot_flush_cnt[3]);
997
998 /* Avg agg count */
999 seq_puts(seq, "Avg agg: RING4 | RING5 | RING6 | RING7 Total\n");
1000 seq_printf(seq, " %d %d %d %d %d\n",
1001 (hw_lro_tot_flush_cnt[0]) ?
1002 hw_lro_tot_agg_cnt[0] / hw_lro_tot_flush_cnt[0] : 0,
1003 (hw_lro_tot_flush_cnt[1]) ?
1004 hw_lro_tot_agg_cnt[1] / hw_lro_tot_flush_cnt[1] : 0,
1005 (hw_lro_tot_flush_cnt[2]) ?
1006 hw_lro_tot_agg_cnt[2] / hw_lro_tot_flush_cnt[2] : 0,
1007 (hw_lro_tot_flush_cnt[3]) ?
1008 hw_lro_tot_agg_cnt[3] / hw_lro_tot_flush_cnt[3] : 0,
1009 (hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1010 hw_lro_tot_flush_cnt[2] + hw_lro_tot_flush_cnt[3]) ?
1011 ((hw_lro_tot_agg_cnt[0] + hw_lro_tot_agg_cnt[1] +
1012 hw_lro_tot_agg_cnt[2] + hw_lro_tot_agg_cnt[3]) /
1013 (hw_lro_tot_flush_cnt[0] + hw_lro_tot_flush_cnt[1] +
1014 hw_lro_tot_flush_cnt[2] + hw_lro_tot_flush_cnt[3])) : 0);
1015
1016 /* Statistics of aggregation size counts */
1017 seq_puts(seq, "HW LRO flush pkt len:\n");
1018 seq_puts(seq, " Length | RING4 | RING5 | RING6 | RING7 Total\n");
1019 for (i = 0; i < 15; i++) {
1020 seq_printf(seq, "%d~%d: %d %d %d %d %d\n",
1021 i * 5000, (i + 1) * 5000,
1022 hw_lro_agg_size_cnt[0][i], hw_lro_agg_size_cnt[1][i],
1023 hw_lro_agg_size_cnt[2][i], hw_lro_agg_size_cnt[3][i],
1024 hw_lro_agg_size_cnt[0][i] +
1025 hw_lro_agg_size_cnt[1][i] +
1026 hw_lro_agg_size_cnt[2][i] +
1027 hw_lro_agg_size_cnt[3][i]);
1028 }
1029
1030 seq_puts(seq, "Flush reason: RING4 | RING5 | RING6 | RING7 Total\n");
1031 seq_printf(seq, "AGG timeout: %d %d %d %d %d\n",
1032 hw_lro_agg_flush_cnt[0], hw_lro_agg_flush_cnt[1],
1033 hw_lro_agg_flush_cnt[2], hw_lro_agg_flush_cnt[3],
1034 (hw_lro_agg_flush_cnt[0] + hw_lro_agg_flush_cnt[1] +
1035 hw_lro_agg_flush_cnt[2] + hw_lro_agg_flush_cnt[3]));
1036
1037 seq_printf(seq, "AGE timeout: %d %d %d %d %d\n",
1038 hw_lro_age_flush_cnt[0], hw_lro_age_flush_cnt[1],
1039 hw_lro_age_flush_cnt[2], hw_lro_age_flush_cnt[3],
1040 (hw_lro_age_flush_cnt[0] + hw_lro_age_flush_cnt[1] +
1041 hw_lro_age_flush_cnt[2] + hw_lro_age_flush_cnt[3]));
1042
1043 seq_printf(seq, "Not in-sequence: %d %d %d %d %d\n",
1044 hw_lro_seq_flush_cnt[0], hw_lro_seq_flush_cnt[1],
1045 hw_lro_seq_flush_cnt[2], hw_lro_seq_flush_cnt[3],
1046 (hw_lro_seq_flush_cnt[0] + hw_lro_seq_flush_cnt[1] +
1047 hw_lro_seq_flush_cnt[2] + hw_lro_seq_flush_cnt[3]));
1048
1049 seq_printf(seq, "Timestamp: %d %d %d %d %d\n",
1050 hw_lro_timestamp_flush_cnt[0],
1051 hw_lro_timestamp_flush_cnt[1],
1052 hw_lro_timestamp_flush_cnt[2],
1053 hw_lro_timestamp_flush_cnt[3],
1054 (hw_lro_timestamp_flush_cnt[0] +
1055 hw_lro_timestamp_flush_cnt[1] +
1056 hw_lro_timestamp_flush_cnt[2] +
1057 hw_lro_timestamp_flush_cnt[3]));
1058
1059 seq_printf(seq, "No LRO rule: %d %d %d %d %d\n",
1060 hw_lro_norule_flush_cnt[0],
1061 hw_lro_norule_flush_cnt[1],
1062 hw_lro_norule_flush_cnt[2],
1063 hw_lro_norule_flush_cnt[3],
1064 (hw_lro_norule_flush_cnt[0] +
1065 hw_lro_norule_flush_cnt[1] +
1066 hw_lro_norule_flush_cnt[2] +
1067 hw_lro_norule_flush_cnt[3]));
1068
1069 return 0;
1070}
1071
1072int hw_lro_stats_read_wrapper(struct seq_file *seq, void *v)
1073{
1074 struct mtk_eth *eth = g_eth;
1075
1076 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
1077 hw_lro_stats_read_v2(seq, v);
1078 else
1079 hw_lro_stats_read_v1(seq, v);
1080
1081 return 0;
1082}
1083
1084static int hw_lro_stats_open(struct inode *inode, struct file *file)
1085{
1086 return single_open(file, hw_lro_stats_read_wrapper, NULL);
1087}
1088
1089static const struct file_operations hw_lro_stats_fops = {
1090 .owner = THIS_MODULE,
1091 .open = hw_lro_stats_open,
1092 .read = seq_read,
1093 .llseek = seq_lseek,
1094 .write = hw_lro_stats_write,
developerfd40db22021-04-29 10:08:25 +08001095 .release = single_release
1096};
1097
developer77d03a72021-06-06 00:06:00 +08001098int hwlro_agg_cnt_ctrl(int cnt)
1099{
1100 int i;
1101
1102 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1103 SET_PDMA_RXRING_MAX_AGG_CNT(g_eth, i, cnt);
1104
1105 return 0;
1106}
1107
1108int hwlro_agg_time_ctrl(int time)
1109{
1110 int i;
1111
1112 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1113 SET_PDMA_RXRING_AGG_TIME(g_eth, i, time);
1114
1115 return 0;
1116}
1117
1118int hwlro_age_time_ctrl(int time)
1119{
1120 int i;
1121
1122 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1123 SET_PDMA_RXRING_AGE_TIME(g_eth, i, time);
1124
1125 return 0;
1126}
1127
1128int hwlro_threshold_ctrl(int bandwidth)
1129{
1130 SET_PDMA_LRO_BW_THRESHOLD(g_eth, bandwidth);
1131
1132 return 0;
1133}
1134
1135int hwlro_ring_enable_ctrl(int enable)
1136{
1137 int i;
1138
1139 pr_info("[%s] %s HW LRO rings\n", __func__, (enable) ? "Enable" : "Disable");
1140
1141 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++)
1142 SET_PDMA_RXRING_VALID(g_eth, i, enable);
1143
1144 return 0;
1145}
1146
1147int hwlro_stats_enable_ctrl(int enable)
1148{
1149 pr_info("[%s] %s HW LRO statistics\n", __func__, (enable) ? "Enable" : "Disable");
1150 mtk_hwlro_stats_ebl = enable;
1151
1152 return 0;
1153}
1154
1155static const mtk_lro_dbg_func lro_dbg_func[] = {
1156 [0] = hwlro_agg_cnt_ctrl,
1157 [1] = hwlro_agg_time_ctrl,
1158 [2] = hwlro_age_time_ctrl,
1159 [3] = hwlro_threshold_ctrl,
1160 [4] = hwlro_ring_enable_ctrl,
1161 [5] = hwlro_stats_enable_ctrl,
1162};
1163
1164ssize_t hw_lro_auto_tlb_write(struct file *file, const char __user *buffer,
1165 size_t count, loff_t *data)
1166{
1167 char buf[32];
1168 char *p_buf;
1169 char *p_token = NULL;
1170 char *p_delimiter = " \t";
1171 long x = 0, y = 0;
1172 int len = count;
1173 int ret;
1174
1175 if (len >= sizeof(buf)) {
1176 pr_info("Input handling fail!\n");
1177 len = sizeof(buf) - 1;
1178 return -1;
1179 }
1180
1181 if (copy_from_user(buf, buffer, len))
1182 return -EFAULT;
1183
1184 buf[len] = '\0';
1185
1186 p_buf = buf;
1187 p_token = strsep(&p_buf, p_delimiter);
1188 if (!p_token)
1189 x = 0;
1190 else
1191 ret = kstrtol(p_token, 10, &x);
1192
1193 p_token = strsep(&p_buf, "\t\n ");
1194 if (p_token)
1195 ret = kstrtol(p_token, 10, &y);
1196
1197 if (lro_dbg_func[x] && (ARRAY_SIZE(lro_dbg_func) > x))
1198 (*lro_dbg_func[x]) (y);
1199
1200 return count;
1201}
1202
1203void hw_lro_auto_tlb_dump_v1(struct seq_file *seq, u32 index)
1204{
1205 int i;
1206 struct mtk_lro_alt_v1 alt;
1207 __be32 addr;
1208 u32 tlb_info[9];
1209 u32 dw_len, cnt, priority;
1210 u32 entry;
1211
1212 if (index > 4)
1213 index = index - 1;
1214 entry = (index * 9) + 1;
1215
1216 /* read valid entries of the auto-learn table */
1217 mtk_w32(g_eth, entry, MTK_FE_ALT_CF8);
1218
1219 for (i = 0; i < 9; i++)
1220 tlb_info[i] = mtk_r32(g_eth, MTK_FE_ALT_SEQ_CFC);
1221
1222 memcpy(&alt, tlb_info, sizeof(struct mtk_lro_alt_v1));
1223
1224 dw_len = alt.alt_info7.dw_len;
1225 cnt = alt.alt_info6.cnt;
1226
1227 if (mtk_r32(g_eth, MTK_PDMA_LRO_CTRL_DW0) & MTK_LRO_ALT_PKT_CNT_MODE)
1228 priority = cnt; /* packet count */
1229 else
1230 priority = dw_len; /* byte count */
1231
1232 /* dump valid entries of the auto-learn table */
1233 if (index >= 4)
1234 seq_printf(seq, "\n===== TABLE Entry: %d (Act) =====\n", index);
1235 else
1236 seq_printf(seq, "\n===== TABLE Entry: %d (LRU) =====\n", index);
1237
1238 if (alt.alt_info8.ipv4) {
1239 addr = htonl(alt.alt_info1.sip0);
1240 seq_printf(seq, "SIP = %pI4 (IPv4)\n", &addr);
1241 } else {
1242 seq_printf(seq, "SIP = %08X:%08X:%08X:%08X (IPv6)\n",
1243 alt.alt_info4.sip3, alt.alt_info3.sip2,
1244 alt.alt_info2.sip1, alt.alt_info1.sip0);
1245 }
1246
1247 seq_printf(seq, "DIP_ID = %d\n", alt.alt_info8.dip_id);
1248 seq_printf(seq, "TCP SPORT = %d | TCP DPORT = %d\n",
1249 alt.alt_info0.stp, alt.alt_info0.dtp);
1250 seq_printf(seq, "VLAN_VID_VLD = %d\n", alt.alt_info6.vlan_vid_vld);
1251 seq_printf(seq, "VLAN1 = %d | VLAN2 = %d | VLAN3 = %d | VLAN4 =%d\n",
1252 (alt.alt_info5.vlan_vid0 & 0xfff),
1253 ((alt.alt_info5.vlan_vid0 >> 12) & 0xfff),
1254 ((alt.alt_info6.vlan_vid1 << 8) |
1255 ((alt.alt_info5.vlan_vid0 >> 24) & 0xfff)),
1256 ((alt.alt_info6.vlan_vid1 >> 4) & 0xfff));
1257 seq_printf(seq, "TPUT = %d | FREQ = %d\n", dw_len, cnt);
1258 seq_printf(seq, "PRIORITY = %d\n", priority);
1259}
1260
1261void hw_lro_auto_tlb_dump_v2(struct seq_file *seq, u32 index)
1262{
1263 int i;
1264 struct mtk_lro_alt_v2 alt;
1265 u32 score = 0, ipv4 = 0;
1266 u32 ipv6[4] = { 0 };
1267 u32 tlb_info[12];
1268
1269 /* read valid entries of the auto-learn table */
1270 mtk_w32(g_eth, index << MTK_LRO_ALT_INDEX_OFFSET, MTK_LRO_ALT_DBG);
1271
1272 for (i = 0; i < 11; i++)
1273 tlb_info[i] = mtk_r32(g_eth, MTK_LRO_ALT_DBG_DATA);
1274
1275 memcpy(&alt, tlb_info, sizeof(struct mtk_lro_alt_v2));
1276
1277 if (mtk_r32(g_eth, MTK_PDMA_LRO_CTRL_DW0) & MTK_LRO_ALT_PKT_CNT_MODE)
1278 score = 1; /* packet count */
1279 else
1280 score = 0; /* byte count */
1281
1282 /* dump valid entries of the auto-learn table */
1283 if (alt.alt_info0.valid) {
1284 if (index < 5)
1285 seq_printf(seq,
1286 "\n===== TABLE Entry: %d (onging) =====\n",
1287 index);
1288 else
1289 seq_printf(seq,
1290 "\n===== TABLE Entry: %d (candidate) =====\n",
1291 index);
1292
1293 if (alt.alt_info1.v4_valid) {
1294 ipv4 = (alt.alt_info4.sip0_h << 23) |
1295 alt.alt_info5.sip0_l;
1296 seq_printf(seq, "SIP = 0x%x: (IPv4)\n", ipv4);
1297
1298 ipv4 = (alt.alt_info8.dip0_h << 23) |
1299 alt.alt_info9.dip0_l;
1300 seq_printf(seq, "DIP = 0x%x: (IPv4)\n", ipv4);
1301 } else if (alt.alt_info1.v6_valid) {
1302 ipv6[3] = (alt.alt_info1.sip3_h << 23) |
1303 (alt.alt_info2.sip3_l << 9);
1304 ipv6[2] = (alt.alt_info2.sip2_h << 23) |
1305 (alt.alt_info3.sip2_l << 9);
1306 ipv6[1] = (alt.alt_info3.sip1_h << 23) |
1307 (alt.alt_info4.sip1_l << 9);
1308 ipv6[0] = (alt.alt_info4.sip0_h << 23) |
1309 (alt.alt_info5.sip0_l << 9);
1310 seq_printf(seq, "SIP = 0x%x:0x%x:0x%x:0x%x (IPv6)\n",
1311 ipv6[3], ipv6[2], ipv6[1], ipv6[0]);
1312
1313 ipv6[3] = (alt.alt_info5.dip3_h << 23) |
1314 (alt.alt_info6.dip3_l << 9);
1315 ipv6[2] = (alt.alt_info6.dip2_h << 23) |
1316 (alt.alt_info7.dip2_l << 9);
1317 ipv6[1] = (alt.alt_info7.dip1_h << 23) |
1318 (alt.alt_info8.dip1_l << 9);
1319 ipv6[0] = (alt.alt_info8.dip0_h << 23) |
1320 (alt.alt_info9.dip0_l << 9);
1321 seq_printf(seq, "DIP = 0x%x:0x%x:0x%x:0x%x (IPv6)\n",
1322 ipv6[3], ipv6[2], ipv6[1], ipv6[0]);
1323 }
1324
1325 seq_printf(seq, "TCP SPORT = %d | TCP DPORT = %d\n",
1326 (alt.alt_info9.sp_h << 7) | (alt.alt_info10.sp_l),
1327 alt.alt_info10.dp);
1328 }
1329}
1330
1331int hw_lro_auto_tlb_read(struct seq_file *seq, void *v)
1332{
1333 int i;
1334 u32 reg_val;
1335 u32 reg_op1, reg_op2, reg_op3, reg_op4;
1336 u32 agg_cnt, agg_time, age_time;
1337
1338 seq_puts(seq, "Usage of /proc/mtketh/hw_lro_auto_tlb:\n");
1339 seq_puts(seq, "echo [function] [setting] > /proc/mtketh/hw_lro_auto_tlb\n");
1340 seq_puts(seq, "Functions:\n");
1341 seq_puts(seq, "[0] = hwlro_agg_cnt_ctrl\n");
1342 seq_puts(seq, "[1] = hwlro_agg_time_ctrl\n");
1343 seq_puts(seq, "[2] = hwlro_age_time_ctrl\n");
1344 seq_puts(seq, "[3] = hwlro_threshold_ctrl\n");
1345 seq_puts(seq, "[4] = hwlro_ring_enable_ctrl\n");
1346 seq_puts(seq, "[5] = hwlro_stats_enable_ctrl\n\n");
1347
1348 if (MTK_HAS_CAPS(g_eth->soc->caps, MTK_NETSYS_V2)) {
1349 for (i = 1; i <= 8; i++)
1350 hw_lro_auto_tlb_dump_v2(seq, i);
1351 } else {
1352 /* Read valid entries of the auto-learn table */
1353 mtk_w32(g_eth, 0, MTK_FE_ALT_CF8);
1354 reg_val = mtk_r32(g_eth, MTK_FE_ALT_SEQ_CFC);
1355
1356 seq_printf(seq,
1357 "HW LRO Auto-learn Table: (MTK_FE_ALT_SEQ_CFC=0x%x)\n",
1358 reg_val);
1359
1360 for (i = 7; i >= 0; i--) {
1361 if (reg_val & (1 << i))
1362 hw_lro_auto_tlb_dump_v1(seq, i);
1363 }
1364 }
1365
1366 /* Read the agg_time/age_time/agg_cnt of LRO rings */
1367 seq_puts(seq, "\nHW LRO Ring Settings\n");
1368
1369 for (i = 1; i <= MTK_HW_LRO_RING_NUM; i++) {
1370 reg_op1 = mtk_r32(g_eth, MTK_LRO_CTRL_DW1_CFG(i));
1371 reg_op2 = mtk_r32(g_eth, MTK_LRO_CTRL_DW2_CFG(i));
1372 reg_op3 = mtk_r32(g_eth, MTK_LRO_CTRL_DW3_CFG(i));
1373 reg_op4 = mtk_r32(g_eth, MTK_PDMA_LRO_CTRL_DW2);
1374
1375 agg_cnt =
1376 ((reg_op3 & 0x3) << 6) |
1377 ((reg_op2 >> MTK_LRO_RING_AGG_CNT_L_OFFSET) & 0x3f);
1378 agg_time = (reg_op2 >> MTK_LRO_RING_AGG_TIME_OFFSET) & 0xffff;
1379 age_time =
1380 ((reg_op2 & 0x3f) << 10) |
1381 ((reg_op1 >> MTK_LRO_RING_AGE_TIME_L_OFFSET) & 0x3ff);
1382 seq_printf(seq,
1383 "Ring[%d]: MAX_AGG_CNT=%d, AGG_TIME=%d, AGE_TIME=%d, Threshold=%d\n",
1384 (MTK_HAS_CAPS(g_eth->soc->caps, MTK_NETSYS_V2))? i+3 : i,
1385 agg_cnt, agg_time, age_time, reg_op4);
1386 }
1387
1388 seq_puts(seq, "\n");
1389
1390 return 0;
1391}
1392
1393static int hw_lro_auto_tlb_open(struct inode *inode, struct file *file)
1394{
1395 return single_open(file, hw_lro_auto_tlb_read, NULL);
1396}
1397
1398static const struct file_operations hw_lro_auto_tlb_fops = {
1399 .owner = THIS_MODULE,
1400 .open = hw_lro_auto_tlb_open,
1401 .read = seq_read,
1402 .llseek = seq_lseek,
1403 .write = hw_lro_auto_tlb_write,
1404 .release = single_release
1405};
developerfd40db22021-04-29 10:08:25 +08001406
1407struct proc_dir_entry *proc_reg_dir;
1408static struct proc_dir_entry *proc_esw_cnt, *proc_dbg_regs;
1409
1410int debug_proc_init(struct mtk_eth *eth)
1411{
1412 g_eth = eth;
1413
1414 if (!proc_reg_dir)
1415 proc_reg_dir = proc_mkdir(PROCREG_DIR, NULL);
1416
1417 proc_tx_ring =
1418 proc_create(PROCREG_TXRING, 0, proc_reg_dir, &tx_ring_fops);
1419 if (!proc_tx_ring)
1420 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_TXRING);
1421
1422 proc_rx_ring =
1423 proc_create(PROCREG_RXRING, 0, proc_reg_dir, &rx_ring_fops);
1424 if (!proc_rx_ring)
1425 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_RXRING);
1426
1427 proc_esw_cnt =
1428 proc_create(PROCREG_ESW_CNT, 0, proc_reg_dir, &switch_count_fops);
1429 if (!proc_esw_cnt)
1430 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_ESW_CNT);
1431
1432 proc_dbg_regs =
1433 proc_create(PROCREG_DBG_REGS, 0, proc_reg_dir, &dbg_regs_fops);
1434 if (!proc_dbg_regs)
1435 pr_notice("!! FAIL to create %s PROC !!\n", PROCREG_DBG_REGS);
1436
developer77d03a72021-06-06 00:06:00 +08001437 if (g_eth->hwlro) {
1438 proc_hw_lro_stats =
1439 proc_create(PROCREG_HW_LRO_STATS, 0, proc_reg_dir,
1440 &hw_lro_stats_fops);
1441 if (!proc_hw_lro_stats)
1442 pr_info("!! FAIL to create %s PROC !!\n", PROCREG_HW_LRO_STATS);
1443
1444 proc_hw_lro_auto_tlb =
1445 proc_create(PROCREG_HW_LRO_AUTO_TLB, 0, proc_reg_dir,
1446 &hw_lro_auto_tlb_fops);
1447 if (!proc_hw_lro_auto_tlb)
1448 pr_info("!! FAIL to create %s PROC !!\n",
1449 PROCREG_HW_LRO_AUTO_TLB);
1450 }
1451
developerfd40db22021-04-29 10:08:25 +08001452 return 0;
1453}
1454
1455void debug_proc_exit(void)
1456{
1457 if (proc_tx_ring)
1458 remove_proc_entry(PROCREG_TXRING, proc_reg_dir);
1459 if (proc_rx_ring)
1460 remove_proc_entry(PROCREG_RXRING, proc_reg_dir);
1461
1462 if (proc_esw_cnt)
1463 remove_proc_entry(PROCREG_ESW_CNT, proc_reg_dir);
1464
1465 if (proc_reg_dir)
1466 remove_proc_entry(PROCREG_DIR, 0);
1467
1468 if (proc_dbg_regs)
1469 remove_proc_entry(PROCREG_DBG_REGS, proc_reg_dir);
developer77d03a72021-06-06 00:06:00 +08001470
1471 if (g_eth->hwlro) {
1472 if (proc_hw_lro_stats)
1473 remove_proc_entry(PROCREG_HW_LRO_STATS, proc_reg_dir);
1474
1475 if (proc_hw_lro_auto_tlb)
1476 remove_proc_entry(PROCREG_HW_LRO_AUTO_TLB, proc_reg_dir);
1477 }
developerfd40db22021-04-29 10:08:25 +08001478}
1479