Skip to content

Commit 19d849d

Browse files
T-Xrobimarko
authored andcommitted
realtek: add portmasks, vlan_profiles and vlans to debugfs
Prepare portmasks, vlan profiles and vlans for changes in upcoming patches by exporting them to debugfs for easier debugging and monitoring. Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue> Link: openwrt/openwrt#21872 Signed-off-by: Robert Marko <robimarko@gmail.com>
1 parent 5435ed7 commit 19d849d

8 files changed

Lines changed: 434 additions & 74 deletions

File tree

target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/debugfs.c

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,229 @@ static const struct file_operations l2_table_fops = {
360360
.release = single_release,
361361
};
362362

363+
static int rtldsa_pmsks_table_raw_show(struct seq_file *m, void *v)
364+
{
365+
struct rtl838x_switch_priv *priv = m->private;
366+
u64 all_ports;
367+
368+
mutex_lock(&priv->reg_mutex);
369+
370+
for (int i = 0; i < MAX_MC_PMASKS; i += 4) {
371+
seq_printf(m, "%04i: ", i);
372+
for (int j = 0; j < 4; j++) {
373+
bool is_set = test_bit(i + j, priv->mc_group_bm);
374+
seq_printf(m, " %c0x%016llx%c", is_set ? ' ' : '(',
375+
priv->r->read_mcast_pmask(i + j),
376+
is_set ? ' ' : ')');
377+
}
378+
seq_printf(m, "\n");
379+
}
380+
381+
all_ports = priv->r->read_mcast_pmask(MC_PMASK_ALL_PORTS_IDX);
382+
seq_printf(m, "MC_PMASK_ALL_PORTS (%i): 0x%016llx\n",
383+
MC_PMASK_ALL_PORTS_IDX, all_ports);
384+
385+
mutex_unlock(&priv->reg_mutex);
386+
387+
return 0;
388+
}
389+
390+
static int rtldsa_pmsks_table_raw_open(struct inode *inode, struct file *filp)
391+
{
392+
return single_open(filp, rtldsa_pmsks_table_raw_show, inode->i_private);
393+
}
394+
395+
static const struct file_operations rtldsa_pmsks_table_raw_fops = {
396+
.owner = THIS_MODULE,
397+
.open = rtldsa_pmsks_table_raw_open,
398+
.read = seq_read,
399+
.llseek = seq_lseek,
400+
.release = single_release,
401+
};
402+
403+
static int rtldsa_pmsks_table_show(struct seq_file *m, void *v)
404+
{
405+
struct rtl838x_switch_priv *priv = m->private;
406+
u64 ports;
407+
408+
mutex_lock(&priv->reg_mutex);
409+
410+
for (int i = 0; i < MC_PMASK_ALL_PORTS_IDX; i++) {
411+
if (!test_bit(i, priv->mc_group_bm))
412+
continue;
413+
414+
ports = priv->r->read_mcast_pmask(i);
415+
seq_printf(m, "%04i:", i);
416+
for (int j = 0; j < sizeof(ports)*8; j++)
417+
if (ports & BIT_ULL(j))
418+
seq_printf(m, " %i", j);
419+
seq_printf(m, "\n");
420+
}
421+
422+
ports = priv->r->read_mcast_pmask(MC_PMASK_ALL_PORTS_IDX);
423+
seq_printf(m, "MC_PMASK_ALL_PORTS (%i):", MC_PMASK_ALL_PORTS_IDX);
424+
for (int i = 0; i < sizeof(ports)*8; i++)
425+
if (ports & BIT_ULL(i))
426+
seq_printf(m, " %i", i);
427+
seq_printf(m, "\n");
428+
429+
mutex_unlock(&priv->reg_mutex);
430+
431+
return 0;
432+
}
433+
434+
static int rtldsa_pmsks_table_open(struct inode *inode, struct file *filp)
435+
{
436+
return single_open(filp, rtldsa_pmsks_table_show, inode->i_private);
437+
}
438+
439+
static const struct file_operations rtldsa_pmsks_table_fops = {
440+
.owner = THIS_MODULE,
441+
.open = rtldsa_pmsks_table_open,
442+
.read = seq_read,
443+
.llseek = seq_lseek,
444+
.release = single_release,
445+
};
446+
447+
static int rtldsa_vlan_profiles_show(struct seq_file *m, void *v)
448+
{
449+
struct rtl838x_switch_priv *priv = m->private;
450+
struct rtldsa_vlan_profile profile;
451+
int ret, profiles_max;
452+
453+
if (!priv->r->vlan_profile_get)
454+
return -ENOTSUPP;
455+
456+
profiles_max = max(RTL838X_VLAN_PROFILE_MAX, RTL839X_VLAN_PROFILE_MAX);
457+
profiles_max = max(profiles_max, RTL930X_VLAN_PROFILE_MAX);
458+
profiles_max = max(profiles_max, RTL931X_VLAN_PROFILE_MAX);
459+
460+
mutex_lock(&priv->reg_mutex);
461+
462+
seq_printf(m,
463+
"prof-idx: L2 learn | UNKN L2MC FLD PMSK (IDX) | UNKN IPMC FLD PMSK (IDX) | UNKN IPv6MC FLD PMSK (IDX)\n");
464+
for (int i = 0; i <= profiles_max; i++) {
465+
ret = priv->r->vlan_profile_get(i, &profile);
466+
if (ret < 0)
467+
break;
468+
469+
if (profile.pmsk_is_idx)
470+
seq_printf(m, "%i: %i %03i %03i %03i\n", i,
471+
profile.l2_learn,
472+
profile.unkn_mc_fld.pmsks_idx.l2,
473+
profile.unkn_mc_fld.pmsks_idx.ip,
474+
profile.unkn_mc_fld.pmsks_idx.ip6);
475+
else
476+
seq_printf(m, "%i: %i 0x%016llx 0x%016llx 0x%016llx\n", i,
477+
profile.l2_learn,
478+
profile.unkn_mc_fld.pmsks.l2,
479+
profile.unkn_mc_fld.pmsks.ip,
480+
profile.unkn_mc_fld.pmsks.ip6);
481+
}
482+
483+
mutex_unlock(&priv->reg_mutex);
484+
485+
return 0;
486+
}
487+
488+
static int rtldsa_vlan_profiles_open(struct inode *inode, struct file *filp)
489+
{
490+
return single_open(filp, rtldsa_vlan_profiles_show, inode->i_private);
491+
}
492+
493+
static const struct file_operations rtldsa_vlan_profiles_fops = {
494+
.owner = THIS_MODULE,
495+
.open = rtldsa_vlan_profiles_open,
496+
.read = seq_read,
497+
.llseek = seq_lseek,
498+
.release = single_release,
499+
};
500+
501+
static int rtldsa_vlan_table_raw_show(struct seq_file *m, void *v)
502+
{
503+
struct rtl838x_switch_priv *priv = m->private;
504+
struct rtl838x_vlan_info info;
505+
506+
if (!priv->r->vlan_tables_read)
507+
return -ENOTSUPP;
508+
509+
mutex_lock(&priv->reg_mutex);
510+
511+
seq_printf(m, "VID: profile-index untagged-ports member-ports\n");
512+
513+
for (int i = 0; i < MAX_VLANS; i++) {
514+
priv->r->vlan_tables_read(i, &info);
515+
516+
if (!info.member_ports)
517+
continue;
518+
519+
seq_printf(m, "%i: %2i 0x%016llx 0x%016llx\n", i,
520+
info.profile_id,
521+
info.untagged_ports,
522+
info.member_ports);
523+
}
524+
525+
mutex_unlock(&priv->reg_mutex);
526+
527+
return 0;
528+
}
529+
530+
static int rtldsa_vlan_table_raw_open(struct inode *inode, struct file *filp)
531+
{
532+
return single_open(filp, rtldsa_vlan_table_raw_show, inode->i_private);
533+
}
534+
535+
static const struct file_operations rtldsa_vlan_table_raw_fops = {
536+
.owner = THIS_MODULE,
537+
.open = rtldsa_vlan_table_raw_open,
538+
.read = seq_read,
539+
.llseek = seq_lseek,
540+
.release = single_release,
541+
};
542+
543+
544+
static int rtldsa_vlan_table_show(struct seq_file *m, void *v)
545+
{
546+
struct rtl838x_switch_priv *priv = m->private;
547+
struct rtl838x_vlan_info info;
548+
549+
if (!priv->r->vlan_tables_read)
550+
return -ENOTSUPP;
551+
552+
mutex_lock(&priv->reg_mutex);
553+
554+
for (int i = 0; i < MAX_VLANS; i++) {
555+
priv->r->vlan_tables_read(i, &info);
556+
557+
if (!info.member_ports)
558+
continue;
559+
560+
seq_printf(m, "%i: %i |", i, info.profile_id);
561+
for (int j = 0; j < sizeof(info.member_ports)*8; j++)
562+
if (info.member_ports & BIT_ULL(j))
563+
seq_printf(m, " %i%s", j,
564+
(info.untagged_ports & BIT_ULL(j)) ? "" : "t");
565+
seq_printf(m, "\n");
566+
}
567+
568+
mutex_unlock(&priv->reg_mutex);
569+
570+
return 0;
571+
}
572+
573+
static int rtldsa_vlan_table_open(struct inode *inode, struct file *filp)
574+
{
575+
return single_open(filp, rtldsa_vlan_table_show, inode->i_private);
576+
}
577+
578+
static const struct file_operations rtldsa_vlan_table_fops = {
579+
.owner = THIS_MODULE,
580+
.open = rtldsa_vlan_table_open,
581+
.read = seq_read,
582+
.llseek = seq_lseek,
583+
.release = single_release,
584+
};
585+
363586
static ssize_t age_out_read(struct file *filp, char __user *buffer, size_t count,
364587
loff_t *ppos)
365588
{
@@ -695,6 +918,21 @@ void rtl838x_dbgfs_init(struct rtl838x_switch_priv *priv)
695918

696919
debugfs_create_file("l2_table", 0400, rtl838x_dir, priv, &l2_table_fops);
697920

921+
debugfs_create_file("port_masks_table_raw", 0400, rtl838x_dir, priv,
922+
&rtldsa_pmsks_table_raw_fops);
923+
924+
debugfs_create_file("port_masks_table", 0400, rtl838x_dir, priv,
925+
&rtldsa_pmsks_table_fops);
926+
927+
debugfs_create_file("vlan_profiles", 0400, rtl838x_dir, priv,
928+
&rtldsa_vlan_profiles_fops);
929+
930+
debugfs_create_file("vlan_table_raw", 0400, rtl838x_dir, priv,
931+
&rtldsa_vlan_table_raw_fops);
932+
933+
debugfs_create_file("vlan_table", 0400, rtl838x_dir, priv,
934+
&rtldsa_vlan_table_fops);
935+
698936
return;
699937
err:
700938
rtl838x_dbgfs_cleanup(priv);
@@ -714,4 +952,19 @@ void rtl930x_dbgfs_init(struct rtl838x_switch_priv *priv)
714952
debugfs_create_file("drop_counters", 0400, dbg_dir, priv, &drop_counter_fops);
715953

716954
debugfs_create_file("l2_table", 0400, dbg_dir, priv, &l2_table_fops);
955+
956+
debugfs_create_file("port_masks_table_raw", 0400, dbg_dir, priv,
957+
&rtldsa_pmsks_table_raw_fops);
958+
959+
debugfs_create_file("port_masks_table", 0400, dbg_dir, priv,
960+
&rtldsa_pmsks_table_fops);
961+
962+
debugfs_create_file("vlan_profiles", 0400, dbg_dir, priv,
963+
&rtldsa_vlan_profiles_fops);
964+
965+
debugfs_create_file("vlan_table_raw", 0400, dbg_dir, priv,
966+
&rtldsa_vlan_table_raw_fops);
967+
968+
debugfs_create_file("vlan_table", 0400, dbg_dir, priv,
969+
&rtldsa_vlan_table_fops);
717970
}

target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,7 @@ static void rtldsa_vlan_setup(struct rtl838x_switch_priv *priv)
454454

455455
priv->r->vlan_profile_setup(0);
456456
priv->r->vlan_profile_setup(1);
457-
dev_info(priv->dev, "MC_PMASK_ALL_PORTS: %016llx\n", priv->r->read_mcast_pmask(MC_PMASK_ALL_PORTS_IDX));
458-
priv->r->vlan_profile_dump(0);
457+
priv->r->vlan_profile_dump(priv, 0);
459458

460459
info.fid = 0; /* Default Forwarding ID / MSTI */
461460
info.hash_uc_fid = false; /* Do not build the L2 lookup hash with FID, but VID */

target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl838x.c

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,29 @@ static void rtl838x_write_mcast_pmask(int idx, u64 portmask)
490490
rtl_table_release(q);
491491
}
492492

493+
static int
494+
rtldsa_838x_vlan_profile_get(int idx, struct rtldsa_vlan_profile *profile)
495+
{
496+
u32 p;
497+
498+
if (idx < 0 || idx > RTL838X_VLAN_PROFILE_MAX)
499+
return -EINVAL;
500+
501+
p = sw_r32(RTL838X_VLAN_PROFILE(idx));
502+
503+
*profile = (struct rtldsa_vlan_profile) {
504+
.l2_learn = RTL838X_VLAN_L2_LEARN_EN_R(p),
505+
.unkn_mc_fld.pmsks_idx = {
506+
.l2 = RTL838X_VLAN_L2_UNKN_MC_FLD_PMSK(p),
507+
.ip = RTL838X_VLAN_IP4_UNKN_MC_FLD_PMSK(p),
508+
.ip6 = RTL838X_VLAN_IP6_UNKN_MC_FLD_PMSK(p),
509+
},
510+
.pmsk_is_idx = 1,
511+
};
512+
513+
return 0;
514+
}
515+
493516
static void rtl838x_vlan_profile_setup(int profile)
494517
{
495518
u32 p = RTL838X_VLAN_L2_LEARN_EN(1) |
@@ -1683,6 +1706,20 @@ static void rtl838x_set_receive_management_action(int port, rma_ctrl_t type, act
16831706
}
16841707
}
16851708

1709+
static void
1710+
rtldsa_838x_vlan_profile_dump(struct rtl838x_switch_priv *priv, int idx)
1711+
{
1712+
struct rtldsa_vlan_profile p;
1713+
1714+
if (rtldsa_838x_vlan_profile_get(idx, &p) < 0)
1715+
return;
1716+
1717+
dev_dbg(priv->dev,
1718+
"VLAN profile %d: L2 learning: %d, UNKN L2MC FLD PMSK %d, UNKN IPMC FLD PMSK %d, UNKN IPv6MC FLD PMSK: %d\n", idx,
1719+
p.l2_learn, p.unkn_mc_fld.pmsks_idx.l2,
1720+
p.unkn_mc_fld.pmsks_idx.ip, p.unkn_mc_fld.pmsks_idx.ip6);
1721+
}
1722+
16861723
const struct rtldsa_config rtldsa_838x_cfg = {
16871724
.mask_port_reg_be = rtl838x_mask_port_reg,
16881725
.set_port_reg_be = rtl838x_set_port_reg,
@@ -1721,7 +1758,8 @@ const struct rtldsa_config rtldsa_838x_cfg = {
17211758
.vlan_set_tagged = rtl838x_vlan_set_tagged,
17221759
.vlan_set_untagged = rtl838x_vlan_set_untagged,
17231760
.mac_force_mode_ctrl = rtl838x_mac_force_mode_ctrl,
1724-
.vlan_profile_dump = rtl838x_vlan_profile_dump,
1761+
.vlan_profile_get = rtldsa_838x_vlan_profile_get,
1762+
.vlan_profile_dump = rtldsa_838x_vlan_profile_dump,
17251763
.vlan_profile_setup = rtl838x_vlan_profile_setup,
17261764
.vlan_fwd_on_inner = rtl838x_vlan_fwd_on_inner,
17271765
.set_vlan_igr_filter = rtl838x_set_igr_filter,
@@ -1794,20 +1832,3 @@ irqreturn_t rtl838x_switch_irq(int irq, void *dev_id)
17941832

17951833
return IRQ_HANDLED;
17961834
}
1797-
1798-
void rtl838x_vlan_profile_dump(int profile)
1799-
{
1800-
u32 p;
1801-
1802-
if (profile < 0 || profile > RTL838X_VLAN_PROFILE_MAX)
1803-
return;
1804-
1805-
p = sw_r32(RTL838X_VLAN_PROFILE(profile));
1806-
1807-
pr_debug("VLAN profile %d: L2 learning: %d, UNKN L2MC FLD PMSK %d, UNKN IPMC FLD PMSK %d, UNKN IPv6MC FLD PMSK: %d\n",
1808-
profile, RTL838X_VLAN_L2_LEARN_EN_R(p),
1809-
RTL838X_VLAN_L2_UNKN_MC_FLD_PMSK(p),
1810-
RTL838X_VLAN_IP4_UNKN_MC_FLD_PMSK(p),
1811-
RTL838X_VLAN_IP6_UNKN_MC_FLD_PMSK(p));
1812-
}
1813-

0 commit comments

Comments
 (0)