xref: /linux/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c (revision fb7399cf2d0b33825b8039f95c45395c7deba25c)
1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright 2025 NXP */
3 
4 #include <linux/device.h>
5 #include <linux/debugfs.h>
6 #include <linux/seq_file.h>
7 #include <linux/string_choices.h>
8 
9 #include "enetc_pf.h"
10 #include "enetc4_debugfs.h"
11 
12 static void enetc_show_si_mac_hash_filter(struct seq_file *s, int i)
13 {
14 	struct enetc_si *si = s->private;
15 	struct enetc_hw *hw = &si->hw;
16 	u32 hash_h, hash_l;
17 
18 	hash_l = enetc_port_rd(hw, ENETC4_PSIUMHFR0(i));
19 	hash_h = enetc_port_rd(hw, ENETC4_PSIUMHFR1(i));
20 	seq_printf(s, "SI %d unicast MAC hash filter: 0x%08x%08x\n",
21 		   i, hash_h, hash_l);
22 
23 	hash_l = enetc_port_rd(hw, ENETC4_PSIMMHFR0(i));
24 	hash_h = enetc_port_rd(hw, ENETC4_PSIMMHFR1(i));
25 	seq_printf(s, "SI %d multicast MAC hash filter: 0x%08x%08x\n",
26 		   i, hash_h, hash_l);
27 }
28 
29 static int enetc_mac_filter_show(struct seq_file *s, void *data)
30 {
31 	struct enetc_si *si = s->private;
32 	struct enetc_hw *hw = &si->hw;
33 	struct maft_entry_data maft;
34 	struct enetc_pf *pf;
35 	int i, err, num_si;
36 	u32 val;
37 
38 	pf = enetc_si_priv(si);
39 	num_si = pf->caps.num_vsi + 1;
40 
41 	val = enetc_port_rd(hw, ENETC4_PSIPMMR);
42 	for (i = 0; i < num_si; i++) {
43 		seq_printf(s, "SI %d Unicast Promiscuous mode: %s\n", i,
44 			   str_enabled_disabled(PSIPMMR_SI_MAC_UP(i) & val));
45 		seq_printf(s, "SI %d Multicast Promiscuous mode: %s\n", i,
46 			   str_enabled_disabled(PSIPMMR_SI_MAC_MP(i) & val));
47 	}
48 
49 	/* MAC hash filter table */
50 	for (i = 0; i < num_si; i++)
51 		enetc_show_si_mac_hash_filter(s, i);
52 
53 	if (!pf->num_mfe)
54 		return 0;
55 
56 	/* MAC address filter table */
57 	seq_puts(s, "MAC address filter table\n");
58 	for (i = 0; i < pf->num_mfe; i++) {
59 		memset(&maft, 0, sizeof(maft));
60 		err = ntmp_maft_query_entry(&si->ntmp_user, i, &maft);
61 		if (err)
62 			return err;
63 
64 		seq_printf(s, "Entry %d, MAC: %pM, SI bitmap: 0x%04x\n", i,
65 			   maft.keye.mac_addr, le16_to_cpu(maft.cfge.si_bitmap));
66 	}
67 
68 	return 0;
69 }
70 DEFINE_SHOW_ATTRIBUTE(enetc_mac_filter);
71 
72 void enetc_create_debugfs(struct enetc_si *si)
73 {
74 	struct net_device *ndev = si->ndev;
75 	struct dentry *root;
76 
77 	root = debugfs_create_dir(netdev_name(ndev), NULL);
78 	if (IS_ERR(root))
79 		return;
80 
81 	si->debugfs_root = root;
82 
83 	debugfs_create_file("mac_filter", 0444, root, si, &enetc_mac_filter_fops);
84 }
85 
86 void enetc_remove_debugfs(struct enetc_si *si)
87 {
88 	debugfs_remove(si->debugfs_root);
89 	si->debugfs_root = NULL;
90 }
91