RE: [PATCH v4 net-next 05/14] net: enetc: add debugfs interface to dump MAC filter
From: Wei Fang
Date: Mon Mar 17 2025 - 23:29:13 EST
> On Tue, Mar 11, 2025 at 01:38:21PM +0800, Wei Fang wrote:
> > diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c
> > b/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c
> > new file mode 100644
> > index 000000000000..3a660c80344a
> > --- /dev/null
> > +++ b/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c
> > @@ -0,0 +1,93 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/* Copyright 2025 NXP */
> > +
> > +#include <linux/device.h>
> > +#include <linux/debugfs.h>
> > +#include <linux/seq_file.h>
> > +
> > +#include "enetc_pf.h"
> > +#include "enetc4_debugfs.h"
> > +
> > +#define is_en(x) (x) ? "Enabled" : "Disabled"
>
> str_enabled_disabled()
Oh, good, I wondered if there was a general implementation in
the kernel, but I did not find one due to my limited knowledge.
Thanks!
>
> > +
> > +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);
>
> Maybe the ":" separator between the high and low 32 bits is clearer than "x".
I want it to be presented as a full 64-bit entry. If it is in the format
of "%08x:%08x", it may be difficult to understand which is the high
32-bit and which is the low 32-bit.
>
> > +
> > + 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 maft_entry_data maft_data;
> > + struct enetc_si *si = s->private;
> > + struct enetc_hw *hw = &si->hw;
> > + struct maft_keye_data *keye;
> > + 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, is_en(PSIPMMR_SI_MAC_UP(i) & val));
> > + seq_printf(s, "SI %d Multicast Promiscuous mode: %s\n",
> > + i, is_en(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, "Show MAC address filter table\n");
>
> The word "show" seems superfluous.
Okay, will remove it.
>
> > + for (i = 0; i < pf->num_mfe; i++) {
> > + memset(&maft_data, 0, sizeof(maft_data));
> > + err = ntmp_maft_query_entry(&si->ntmp.cbdrs, i, &maft_data);
> > + if (err)
> > + return err;
> > +
> > + keye = &maft_data.keye;
> > + seq_printf(s, "Entry %d, MAC: %pM, SI bitmap: 0x%04x\n", i,
> > + keye->mac_addr, le16_to_cpu(maft_data.cfge.si_bitmap));
> > + }
> > +
> > + return 0;
> > +}
> > +DEFINE_SHOW_ATTRIBUTE(enetc_mac_filter);