xref: /linux/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c (revision 91ec2035134982b98fab0609a9fd8480e8217dc1)
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 
enetc_show_si_mac_hash_filter(struct seq_file * s,int i)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 
enetc_mac_filter_show(struct seq_file * s,void * data)29 static int enetc_mac_filter_show(struct seq_file *s, void *data)
30 {
31 	struct enetc_pf *pf = enetc_si_priv(s->private);
32 	struct enetc_hw *hw = &pf->si->hw;
33 	int num_si = pf->total_vfs + 1;
34 	struct maft_entry_data maft;
35 	struct ntmp_user *user;
36 	u32 val, entry_id;
37 	int err = 0;
38 	int i;
39 
40 	val = enetc_port_rd(hw, ENETC4_PSIPMMR);
41 	for (i = 0; i < num_si; i++) {
42 		seq_printf(s, "SI %d Unicast Promiscuous mode: %s\n", i,
43 			   str_enabled_disabled(PSIPMMR_SI_MAC_UP(i) & val));
44 		seq_printf(s, "SI %d Multicast Promiscuous mode: %s\n", i,
45 			   str_enabled_disabled(PSIPMMR_SI_MAC_MP(i) & val));
46 	}
47 
48 	/* MAC hash filter table */
49 	for (i = 0; i < num_si; i++)
50 		enetc_show_si_mac_hash_filter(s, i);
51 
52 	user = &pf->si->ntmp_user;
53 	rtnl_lock();
54 
55 	if (bitmap_empty(user->maft_eid_bitmap, user->maft_num_entries))
56 		goto unlock_rtnl;
57 
58 	/* MAC address filter table */
59 	seq_puts(s, "MAC address filter table\n");
60 	for_each_set_bit(entry_id, user->maft_eid_bitmap,
61 			 user->maft_num_entries) {
62 		memset(&maft, 0, sizeof(maft));
63 		err = ntmp_maft_query_entry(user, entry_id, &maft);
64 		if (err)
65 			goto unlock_rtnl;
66 
67 		seq_printf(s, "Entry %d, MAC: %pM, SI bitmap: 0x%04x\n",
68 			   entry_id, maft.keye.mac_addr,
69 			   le16_to_cpu(maft.cfge.si_bitmap));
70 	}
71 
72 unlock_rtnl:
73 	rtnl_unlock();
74 
75 	return err;
76 }
77 DEFINE_SHOW_ATTRIBUTE(enetc_mac_filter);
78 
enetc_create_debugfs(struct enetc_si * si)79 void enetc_create_debugfs(struct enetc_si *si)
80 {
81 	struct dentry *root;
82 
83 	root = debugfs_create_dir(pci_name(si->pdev), NULL);
84 	if (IS_ERR(root))
85 		return;
86 
87 	si->debugfs_root = root;
88 
89 	debugfs_create_file("mac_filter", 0444, root, si, &enetc_mac_filter_fops);
90 }
91 
enetc_remove_debugfs(struct enetc_si * si)92 void enetc_remove_debugfs(struct enetc_si *si)
93 {
94 	debugfs_remove(si->debugfs_root);
95 	si->debugfs_root = NULL;
96 }
97