]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: enetc: add debugfs interface to dump MAC filter
authorWei Fang <wei.fang@nxp.com>
Tue, 6 May 2025 08:07:26 +0000 (16:07 +0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 9 May 2025 02:43:51 +0000 (19:43 -0700)
ENETC's MAC filter consists of hash MAC filter and exact MAC filter.
Hash MAC filter is a 64-bit entry hash table consisting of two 32-bit
registers. Exact MAC filter is implemented by configuring MAC address
filter table through command BD ring. The table is stored in ENETC's
internal memory and needs to be read through command BD ring. In order
to facilitate debugging, added a debugfs interface to get the relevant
information about MAC filter.

Signed-off-by: Wei Fang <wei.fang@nxp.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://patch.msgid.link/20250506080735.3444381-6-wei.fang@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/freescale/enetc/Makefile
drivers/net/ethernet/freescale/enetc/enetc.h
drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c [new file with mode: 0644]
drivers/net/ethernet/freescale/enetc/enetc4_debugfs.h [new file with mode: 0644]
drivers/net/ethernet/freescale/enetc/enetc4_pf.c

index 707a68e2697194ed767f1159281a01931f78fc7e..f1c5ad45fd76dc4600693f7f7ed54b8df3041b1b 100644 (file)
@@ -16,6 +16,7 @@ fsl-enetc-$(CONFIG_FSL_ENETC_QOS) += enetc_qos.o
 
 obj-$(CONFIG_NXP_ENETC4) += nxp-enetc4.o
 nxp-enetc4-y := enetc4_pf.o
+nxp-enetc4-$(CONFIG_DEBUG_FS) += enetc4_debugfs.o
 
 obj-$(CONFIG_FSL_ENETC_VF) += fsl-enetc-vf.o
 fsl-enetc-vf-y := enetc_vf.o
index 1573ff06fcf4895a690a51947a99fba809d7fad9..b53ecc882a90a02167331f9642c00aac63d13831 100644 (file)
@@ -304,6 +304,7 @@ struct enetc_si {
 
        struct workqueue_struct *workqueue;
        struct work_struct rx_mode_task;
+       struct dentry *debugfs_root;
 };
 
 #define ENETC_SI_ALIGN 32
diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c b/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c
new file mode 100644 (file)
index 0000000..1b1591d
--- /dev/null
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright 2025 NXP */
+
+#include <linux/device.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
+#include <linux/string_choices.h>
+
+#include "enetc_pf.h"
+#include "enetc4_debugfs.h"
+
+static void enetc_show_si_mac_hash_filter(struct seq_file *s, int i)
+{
+       struct enetc_si *si = s->private;
+       struct enetc_hw *hw = &si->hw;
+       u32 hash_h, hash_l;
+
+       hash_l = enetc_port_rd(hw, ENETC4_PSIUMHFR0(i));
+       hash_h = enetc_port_rd(hw, ENETC4_PSIUMHFR1(i));
+       seq_printf(s, "SI %d unicast MAC hash filter: 0x%08x%08x\n",
+                  i, hash_h, hash_l);
+
+       hash_l = enetc_port_rd(hw, ENETC4_PSIMMHFR0(i));
+       hash_h = enetc_port_rd(hw, ENETC4_PSIMMHFR1(i));
+       seq_printf(s, "SI %d multicast MAC hash filter: 0x%08x%08x\n",
+                  i, hash_h, hash_l);
+}
+
+static int enetc_mac_filter_show(struct seq_file *s, void *data)
+{
+       struct enetc_si *si = s->private;
+       struct enetc_hw *hw = &si->hw;
+       struct maft_entry_data maft;
+       struct enetc_pf *pf;
+       int i, err, num_si;
+       u32 val;
+
+       pf = enetc_si_priv(si);
+       num_si = pf->caps.num_vsi + 1;
+
+       val = enetc_port_rd(hw, ENETC4_PSIPMMR);
+       for (i = 0; i < num_si; i++) {
+               seq_printf(s, "SI %d Unicast Promiscuous mode: %s\n", i,
+                          str_enabled_disabled(PSIPMMR_SI_MAC_UP(i) & val));
+               seq_printf(s, "SI %d Multicast Promiscuous mode: %s\n", i,
+                          str_enabled_disabled(PSIPMMR_SI_MAC_MP(i) & val));
+       }
+
+       /* MAC hash filter table */
+       for (i = 0; i < num_si; i++)
+               enetc_show_si_mac_hash_filter(s, i);
+
+       if (!pf->num_mfe)
+               return 0;
+
+       /* MAC address filter table */
+       seq_puts(s, "MAC address filter table\n");
+       for (i = 0; i < pf->num_mfe; i++) {
+               memset(&maft, 0, sizeof(maft));
+               err = ntmp_maft_query_entry(&si->ntmp_user, i, &maft);
+               if (err)
+                       return err;
+
+               seq_printf(s, "Entry %d, MAC: %pM, SI bitmap: 0x%04x\n", i,
+                          maft.keye.mac_addr, le16_to_cpu(maft.cfge.si_bitmap));
+       }
+
+       return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(enetc_mac_filter);
+
+void enetc_create_debugfs(struct enetc_si *si)
+{
+       struct net_device *ndev = si->ndev;
+       struct dentry *root;
+
+       root = debugfs_create_dir(netdev_name(ndev), NULL);
+       if (IS_ERR(root))
+               return;
+
+       si->debugfs_root = root;
+
+       debugfs_create_file("mac_filter", 0444, root, si, &enetc_mac_filter_fops);
+}
+
+void enetc_remove_debugfs(struct enetc_si *si)
+{
+       debugfs_remove(si->debugfs_root);
+       si->debugfs_root = NULL;
+}
diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.h b/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.h
new file mode 100644 (file)
index 0000000..96caca3
--- /dev/null
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
+/* Copyright 2025 NXP */
+
+#ifndef __ENETC4_DEBUGFS_H
+#define __ENETC4_DEBUGFS_H
+
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+void enetc_create_debugfs(struct enetc_si *si);
+void enetc_remove_debugfs(struct enetc_si *si);
+#else
+static inline void enetc_create_debugfs(struct enetc_si *si)
+{
+}
+
+static inline void enetc_remove_debugfs(struct enetc_si *si)
+{
+}
+#endif
+
+#endif
index 7b801f6e9a31d64ebeb97bb16f235aeabe929847..db60354ea8d17221fe01e23e1f8b5f270b52bb2a 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/unaligned.h>
 
 #include "enetc_pf_common.h"
+#include "enetc4_debugfs.h"
 
 #define ENETC_SI_MAX_RING_NUM  8
 
@@ -1018,6 +1019,8 @@ static int enetc4_pf_probe(struct pci_dev *pdev,
        if (err)
                goto err_netdev_create;
 
+       enetc_create_debugfs(si);
+
        return 0;
 
 err_netdev_create:
@@ -1031,6 +1034,7 @@ static void enetc4_pf_remove(struct pci_dev *pdev)
        struct enetc_si *si = pci_get_drvdata(pdev);
        struct enetc_pf *pf = enetc_si_priv(si);
 
+       enetc_remove_debugfs(si);
        enetc4_pf_netdev_destroy(si);
        enetc4_pf_free(pf);
 }