Skip to contentSkip to conversation

net: enetc: cleanups and improvements

PATCH RESEND Applied [email protected] 5 participants 31 messages Jul 20 – Jul 27

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v4 cover net: enetc: cleanups and improvements

From: Wei Fang <[email protected]>

The first group of patches (1, 2, 5-7) eliminates code duplication between the ENETC v1 and v4 drivers. Since both hardware generations share identical register layouts for MAC promiscuous mode, MAC hash filters, and VLAN promiscuous mode - differing only in register address offsets - common helper functions are extracted into enetc_pf_common.c and shared by both drivers.

Patch 3 converts ndo_set_rx_mode() to ndo_set_rx_mode_async(), removing the dedicated workqueue that was previously needed to defer MAC address list updates to a sleepable context.

Patch 4 replaces counter-based MAFT entry tracking with a bitmap, which keeps hardware and software state in sync and avoids partial failures during entry allocation.

Patches 8 and 9 fix phylink-related issues: removing invalid code from enetc4_pl_mac_link_up() and properly differentiating phylink capabilities between pseudo-MAC and standalone MAC.

The remaining patches (10-14) are minor cleanups: removing a redundant VLAN promiscuous mode initialization in probe, using the PCI device name for the debugfs directory, simplifying port speed configuration, removing a redundant num_vsi field, using alloc_etherdev_mqs() for the VF driver, and using kzalloc_flex() for a flexible array allocation.

---
v4 link: https://lore.kernel.org/imx/[email protected]/
v4:
1. Improve enetc4_set_si_msix_num()
2. Update commit messages
v3 link: https://lore.kernel.org/imx/[email protected]/
v2 link: https://lore.kernel.org/imx/[email protected]/
v1 link: https://lore.kernel.org/imx/[email protected]/
---

Claudiu Manoil (1):
net: enetc: differentiate phylink capabilities for pseudo-MAC and
standalone MAC

Wei Fang (13):
net: enetc: extract common helpers for MAC promiscuous mode setting
net: enetc: extract common helpers for MAC hash filter configuration
net: enetc: convert ndo_set_rx_mode() to ndo_set_rx_mode_async()
net: enetc: improve MAFT entry management with bitmap tracking
net: enetc: use PCI device name for debugfs directory
net: enetc: simplify enetc4_set_port_speed()
net: enetc: remove invalid code from enetc4_pl_mac_link_up()
net: enetc: open-code enetc4_set_default_si_vlan_promisc()
net: enetc: refactor SI VLAN promiscuous mode configuration
net: enetc: move enetc_set_si_vlan_promisc() to enetc_pf_common.c
net: enetc: remove redundant num_vsi field from enetc_port_caps
net: enetc: use alloc_etherdev_mqs() to create netdev for VF driver
net: enetc: use kzalloc_flex() for enetc_psfp_gate allocation

 drivers/net/ethernet/freescale/enetc/enetc.h  |   4 +-
 .../ethernet/freescale/enetc/enetc4_debugfs.c |  42 +-
 .../net/ethernet/freescale/enetc/enetc4_hw.h  |   6 +-
 .../net/ethernet/freescale/enetc/enetc4_pf.c  | 471 ++++++++----------
 .../ethernet/freescale/enetc/enetc_ethtool.c  |   2 +-
 .../net/ethernet/freescale/enetc/enetc_hw.h   |  12 +-
 .../net/ethernet/freescale/enetc/enetc_pf.c   |  94 +---
 .../net/ethernet/freescale/enetc/enetc_pf.h   |   6 -
 .../freescale/enetc/enetc_pf_common.c         | 150 +++++-
 .../freescale/enetc/enetc_pf_common.h         |   5 +
 .../net/ethernet/freescale/enetc/enetc_qos.c  |   4 +-
 .../net/ethernet/freescale/enetc/enetc_vf.c   |   9 +-
 include/linux/fsl/ntmp.h                      |   2 +
 13 files changed, 411 insertions(+), 396 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH RESEND v4 1/14 net: enetc: extract common helpers for MAC promiscuous mode setting

From: Wei Fang <[email protected]>

The PSIPMMR (Port Station Interface Promiscuous MAC Mode Register) in ENETC v4 has the same bit layout as the PSIPMR register in ENETC v1: bit n controls unicast promiscuous mode for SI n, and bit (n + 16) controls multicast promiscuous mode for SI n. The only difference between the two hardware generations is the register address offset.

Since the register functionality is identical, the MAC promiscuous mode setting code can be shared between ENETC v1 and v4 drivers.

Rename ENETC_PSIPMR to ENETC_PSIPMMR in enetc_hw.h to match the actual register name used in the reference manual, and extract two new common helper functions, enetc_set_si_uc_promisc() and enetc_set_si_mc_promisc(), into enetc_pf_common.c. These helpers select the correct register offset based on the hardware revision via is_enetc_rev1().

Remove the v4-specific enetc4_pf_set_si_mac_promisc() function from enetc4_pf.c and the duplicate PSIPMMR_SI_MAC_UP/MP macro definitions from enetc4_hw.h, as they are now superseded by the shared code.

---
 .../net/ethernet/freescale/enetc/enetc4_hw.h  |  2 -
 .../net/ethernet/freescale/enetc/enetc4_pf.c  | 21 +--------
 .../ethernet/freescale/enetc/enetc_ethtool.c  |  2 +-
 .../net/ethernet/freescale/enetc/enetc_hw.h   |  7 +--
 .../net/ethernet/freescale/enetc/enetc_pf.c   | 11 ++---
 .../freescale/enetc/enetc_pf_common.c         | 44 +++++++++++++++++++
 .../freescale/enetc/enetc_pf_common.h         |  2 +
 7 files changed, 56 insertions(+), 33 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc4_hw.h +0 -2
index f18437556a0e..6a8f2ed56017 100644
@@ -69,8 +69,6 @@
 
 /* Port Station interface promiscuous MAC mode register */
 #define ENETC4_PSIPMMR			0x200
-#define  PSIPMMR_SI_MAC_UP(a)		BIT(a) /* a = SI index */
-#define  PSIPMMR_SI_MAC_MP(a)		BIT((a) + 16)
 
 /* Port Station interface promiscuous VLAN mode register */
 #define ENETC4_PSIPVMR			0x204
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +2 -19
index 437a15bbb47b..304ec069654d 100644
@@ -75,24 +75,6 @@ static void enetc4_pf_get_si_primary_mac(struct enetc_hw *hw, int si,
 	put_unaligned_le16(lower, addr + 4);
 }
 
-static void enetc4_pf_set_si_mac_promisc(struct enetc_hw *hw, int si,
-					 bool uc_promisc, bool mc_promisc)
-{
-	u32 val = enetc_port_rd(hw, ENETC4_PSIPMMR);
-
-	if (uc_promisc)
-		val |= PSIPMMR_SI_MAC_UP(si);
-	else
-		val &= ~PSIPMMR_SI_MAC_UP(si);
-
-	if (mc_promisc)
-		val |= PSIPMMR_SI_MAC_MP(si);
-	else
-		val &= ~PSIPMMR_SI_MAC_MP(si);
-
-	enetc_port_wr(hw, ENETC4_PSIPMMR, val);
-}
-
 static void enetc4_pf_set_si_uc_hash_filter(struct enetc_hw *hw, int si,
 					    u64 hash)
 {
@@ -515,7 +497,8 @@ static void enetc4_psi_do_set_rx_mode(struct work_struct *work)
 		type = ENETC_MAC_FILTER_TYPE_ALL;
 	}
 
-	enetc4_pf_set_si_mac_promisc(hw, 0, uc_promisc, mc_promisc);
+	enetc_set_si_uc_promisc(si, 0, uc_promisc);
+	enetc_set_si_mc_promisc(si, 0, mc_promisc);
 
 	if (uc_promisc) {
 		enetc4_pf_set_si_uc_hash_filter(hw, 0, 0);
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +1 -1
index 71f376ef1be1..07b7832f2427 100644
@@ -29,7 +29,7 @@ static const u32 enetc_rxbdr_regs[] = {
 };
 
 static const u32 enetc_port_regs[] = {
-	ENETC_PMR, ENETC_PSR, ENETC_PSIPMR, ENETC_PSIPMAR0(0),
+	ENETC_PMR, ENETC_PSR, ENETC_PSIPMMR, ENETC_PSIPMAR0(0),
 	ENETC_PSIPMAR1(0), ENETC_PTXMBAR, ENETC_PCAPR0, ENETC_PCAPR1,
 	ENETC_PSICFGR0(0), ENETC_PRFSCAPR, ENETC_PTCMSDUR(0),
 	ENETC_PM0_CMD_CFG, ENETC_PM0_MAXFRM, ENETC_PM0_IF_MODE
drivers/net/ethernet/freescale/enetc/enetc_hw.h +4 -3
index bf99b65d7598..66bfda60da9c 100644
@@ -180,9 +180,10 @@ enum enetc_bdr_type {TX, RX};
 #define ENETC_PMR_PSPEED_1000M	BIT(9)
 #define ENETC_PMR_PSPEED_2500M	BIT(10)
 #define ENETC_PSR		0x0004 /* RO */
-#define ENETC_PSIPMR		0x0018
-#define ENETC_PSIPMR_SET_UP(n)	BIT(n) /* n = SI index */
-#define ENETC_PSIPMR_SET_MP(n)	BIT((n) + 16)
+#define ENETC_PSIPMMR		0x0018
+#define  PSIPMMR_SI_MAC_UP(n)	BIT(n) /* n = SI index */
+#define  PSIPMMR_SI_MAC_MP(n)	BIT((n) + 16)
+
 #define ENETC_PSIPVMR		0x001c
 #define ENETC_VLAN_PROMISC_MAP_ALL	0x7
 #define ENETC_PSIPVMR_SET_VP(simap)	((simap) & 0x7)
drivers/net/ethernet/freescale/enetc/enetc_pf.c +3 -8
index 2d687bb8c3a0..a97d2e2dd07b 100644
@@ -159,21 +159,17 @@ static void enetc_pf_set_rx_mode(struct net_device *ndev)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
 	struct enetc_pf *pf = enetc_si_priv(priv->si);
-	struct enetc_hw *hw = &priv->si->hw;
 	bool uprom = false, mprom = false;
 	struct enetc_mac_filter *filter;
 	struct netdev_hw_addr *ha;
-	u32 psipmr = 0;
 	bool em;
 
 	if (ndev->flags & IFF_PROMISC) {
 		/* enable promisc mode for SI0 (PF) */
-		psipmr = ENETC_PSIPMR_SET_UP(0) | ENETC_PSIPMR_SET_MP(0);
 		uprom = true;
 		mprom = true;
 	} else if (ndev->flags & IFF_ALLMULTI) {
 		/* enable multi cast promisc mode for SI0 (PF) */
-		psipmr = ENETC_PSIPMR_SET_MP(0);
 		mprom = true;
 	}
 
@@ -211,9 +207,8 @@ static void enetc_pf_set_rx_mode(struct net_device *ndev)
 		/* update PF entries */
 		enetc_sync_mac_filters(pf);
 
-	psipmr |= enetc_port_rd(hw, ENETC_PSIPMR) &
-		  ~(ENETC_PSIPMR_SET_UP(0) | ENETC_PSIPMR_SET_MP(0));
-	enetc_port_wr(hw, ENETC_PSIPMR, psipmr);
+	enetc_set_si_uc_promisc(priv->si, 0, uprom);
+	enetc_set_si_mc_promisc(priv->si, 0, mprom);
 }
 
 static void enetc_set_loopback(struct net_device *ndev, bool en)
@@ -474,7 +469,7 @@ static void enetc_configure_port(struct enetc_pf *pf)
 	pf->vlan_promisc_simap = ENETC_VLAN_PROMISC_MAP_ALL;
 	enetc_set_vlan_promisc(hw, pf->vlan_promisc_simap);
 
-	enetc_port_wr(hw, ENETC_PSIPMR, 0);
+	enetc_port_wr(hw, ENETC_PSIPMMR, 0);
 
 	/* enable port */
 	enetc_port_wr(hw, ENETC_PMR, ENETC_PMR_EN);
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +44 -0

50 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_pf_common.h +2 -0
index 57d2e0ebd2b0..a619fb8fed9c 100644
@@ -17,6 +17,8 @@ void enetc_set_default_rss_key(struct enetc_pf *pf);
 int enetc_vlan_rx_add_vid(struct net_device *ndev, __be16 prot, u16 vid);
 int enetc_vlan_rx_del_vid(struct net_device *ndev, __be16 prot, u16 vid);
 int enetc_init_sriov_resources(struct enetc_pf *pf);
+void enetc_set_si_uc_promisc(struct enetc_si *si, int si_id, bool promisc);
+void enetc_set_si_mc_promisc(struct enetc_si *si, int si_id, bool promisc);
 
 static inline u16 enetc_get_ip_revision(struct enetc_hw *hw)
 {
Signature · 1 line
2.34.1
Reviewed-by on v4 1/14
#2 lore raw

Re: [PATCH RESEND v4 net-next 01/14] net: enetc: extract common helpers for MAC promiscuous mode setting

Quoted 43 lines · On Mon, Jul 20, 2026 at 09:43:03AM +0800, [email protected] wrote:

From: Wei Fang <[email protected]>

The PSIPMMR (Port Station Interface Promiscuous MAC Mode Register) in ENETC v4 has the same bit layout as the PSIPMR register in ENETC v1: bit n controls unicast promiscuous mode for SI n, and bit (n + 16) controls multicast promiscuous mode for SI n. The only difference between the two hardware generations is the register address offset.

Since the register functionality is identical, the MAC promiscuous mode setting code can be shared between ENETC v1 and v4 drivers.

Rename ENETC_PSIPMR to ENETC_PSIPMMR in enetc_hw.h to match the actual register name used in the reference manual, and extract two new common helper functions, enetc_set_si_uc_promisc() and enetc_set_si_mc_promisc(), into enetc_pf_common.c. These helpers select the correct register offset based on the hardware revision via is_enetc_rev1().

Remove the v4-specific enetc4_pf_set_si_mac_promisc() function from enetc4_pf.c and the duplicate PSIPMMR_SI_MAC_UP/MP macro definitions from enetc4_hw.h, as they are now superseded by the shared code.

---
 .../net/ethernet/freescale/enetc/enetc4_hw.h  |  2 -
 .../net/ethernet/freescale/enetc/enetc4_pf.c  | 21 +--------
 .../ethernet/freescale/enetc/enetc_ethtool.c  |  2 +-
 .../net/ethernet/freescale/enetc/enetc_hw.h   |  7 +--
 .../net/ethernet/freescale/enetc/enetc_pf.c   | 11 ++---
 .../freescale/enetc/enetc_pf_common.c         | 44 +++++++++++++++++++
 .../freescale/enetc/enetc_pf_common.h         |  2 +
 7 files changed, 56 insertions(+), 33 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc4_hw.h +0 -2
index f18437556a0e..6a8f2ed56017 100644
@@ -69,8 +69,6 @@
 
 /* Port Station interface promiscuous MAC mode register */
 #define ENETC4_PSIPMMR			0x200
-#define  PSIPMMR_SI_MAC_UP(a)		BIT(a) /* a = SI index */
-#define  PSIPMMR_SI_MAC_MP(a)		BIT((a) + 16)

[...]

Quoted 5 lines
drivers/net/ethernet/freescale/enetc/enetc_hw.h +0 -0
index bf99b65d7598..66bfda60da9c 100644

drivers/net/ethernet/freescale/enetc/enetc_hw.h enum enetc_bdr_type {TX, RX}; · line 185

Quoted 9 lines
drivers/net/ethernet/freescale/enetc/enetc_hw.h +3 -3
@@ -180,9 +180,10 @@ enum enetc_bdr_type {TX, RX};
 #define ENETC_PMR_PSPEED_1000M	BIT(9)
 #define ENETC_PMR_PSPEED_2500M	BIT(10)
 #define ENETC_PSR		0x0004 /* RO */
-#define ENETC_PSIPMR		0x0018
-#define ENETC_PSIPMR_SET_UP(n)	BIT(n) /* n = SI index */
-#define ENETC_PSIPMR_SET_MP(n)	BIT((n) + 16)
+#define ENETC_PSIPMMR		0x0018
+#define  PSIPMMR_SI_MAC_UP(n)	BIT(n) /* n = SI index */
+#define  PSIPMMR_SI_MAC_MP(n)	BIT((n) + 16)

I probably would have fixed the leading spaces when copying/pasting the macro, but that seems like a nit.

I read the rest of the code a few times and it looks right to me.

#3 lore raw

PATCH RESEND v4 2/14 net: enetc: extract common helpers for MAC hash filter configuration

In reply to [email protected]

From: Wei Fang <[email protected]>

The PSIUMHFR and PSIMMHFR registers in ENETC v4 have the same bit layout as in ENETC v1. The only difference between the two hardware generations is the register address offsets.

Since the register functionality is identical, the MAC hash filter configuration code can be shared between the ENETC v1 and v4 drivers. Extract two new common helper functions, enetc_set_si_uc_hash_filter() and enetc_set_si_mc_hash_filter(), into enetc_pf_common.c. These helpers select the correct register offset based on the hardware revision via is_enetc_rev1().

Remove v1-specific enetc_clear_mac_ht_flt() and enetc_set_mac_ht_flt() from enetc_pf.c, and v4-specific enetc4_pf_set_si_uc_hash_filter() and enetc4_pf_set_si_mc_hash_filter() from enetc4_pf.c, as they are now superseded by the shared implementations.

---
 .../net/ethernet/freescale/enetc/enetc4_pf.c  | 43 +++++++---------
 .../net/ethernet/freescale/enetc/enetc_pf.c   | 51 +++++--------------
 .../freescale/enetc/enetc_pf_common.c         | 40 +++++++++++++++
 .../freescale/enetc/enetc_pf_common.h         |  2 +
 4 files changed, 73 insertions(+), 63 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +17 -26
index 304ec069654d..48a74db90ed5 100644
@@ -75,20 +75,6 @@ static void enetc4_pf_get_si_primary_mac(struct enetc_hw *hw, int si,
 	put_unaligned_le16(lower, addr + 4);
 }
 
-static void enetc4_pf_set_si_uc_hash_filter(struct enetc_hw *hw, int si,
-					    u64 hash)
-{
-	enetc_port_wr(hw, ENETC4_PSIUMHFR0(si), lower_32_bits(hash));
-	enetc_port_wr(hw, ENETC4_PSIUMHFR1(si), upper_32_bits(hash));
-}
-
-static void enetc4_pf_set_si_mc_hash_filter(struct enetc_hw *hw, int si,
-					    u64 hash)
-{
-	enetc_port_wr(hw, ENETC4_PSIMMHFR0(si), lower_32_bits(hash));
-	enetc_port_wr(hw, ENETC4_PSIMMHFR1(si), upper_32_bits(hash));
-}
-
 static void enetc4_pf_set_loopback(struct net_device *ndev, bool en)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
@@ -147,11 +133,12 @@ static int enetc4_pf_set_uc_exact_filter(struct enetc_pf *pf)
 	int max_num_mfe = pf->caps.mac_filter_num;
 	struct enetc_mac_filter mac_filter = {};
 	struct net_device *ndev = pf->si->ndev;
-	struct enetc_hw *hw = &pf->si->hw;
 	struct enetc_mac_addr *mac_tbl;
+	struct enetc_si *si = pf->si;
 	struct netdev_hw_addr *ha;
 	int i = 0, err;
 	int mac_cnt;
+	u64 hash;
 
 	netif_addr_lock_bh(ndev);
 
@@ -159,7 +146,7 @@ static int enetc4_pf_set_uc_exact_filter(struct enetc_pf *pf)
 	if (!mac_cnt) {
 		netif_addr_unlock_bh(ndev);
 		/* clear both MAC hash and exact filters */
-		enetc4_pf_set_si_uc_hash_filter(hw, 0, 0);
+		enetc_set_si_uc_hash_filter(si, 0, 0);
 		enetc4_pf_clear_maft_entries(pf);
 
 		return 0;
@@ -186,11 +173,13 @@ static int enetc4_pf_set_uc_exact_filter(struct enetc_pf *pf)
 	/* Set temporary unicast hash filters in case of Rx loss when
 	 * updating MAC address filter table
 	 */
-	enetc4_pf_set_si_uc_hash_filter(hw, 0, *mac_filter.mac_hash_table);
+	bitmap_to_arr64(&hash, mac_filter.mac_hash_table,
+			ENETC_MADDR_HASH_TBL_SZ);
+	enetc_set_si_uc_hash_filter(si, 0, hash);
 	enetc4_pf_clear_maft_entries(pf);
 
 	if (!enetc4_pf_add_maft_entries(pf, mac_tbl, i))
-		enetc4_pf_set_si_uc_hash_filter(hw, 0, 0);
+		enetc_set_si_uc_hash_filter(si, 0, 0);
 
 	kfree(mac_tbl);
 
@@ -206,8 +195,9 @@ static void enetc4_pf_set_mac_hash_filter(struct enetc_pf *pf, int type)
 {
 	struct net_device *ndev = pf->si->ndev;
 	struct enetc_mac_filter *mac_filter;
-	struct enetc_hw *hw = &pf->si->hw;
+	struct enetc_si *si = pf->si;
 	struct netdev_hw_addr *ha;
+	u64 hash;
 
 	netif_addr_lock_bh(ndev);
 	if (type & ENETC_MAC_FILTER_TYPE_UC) {
@@ -216,8 +206,9 @@ static void enetc4_pf_set_mac_hash_filter(struct enetc_pf *pf, int type)
 		netdev_for_each_uc_addr(ha, ndev)
 			enetc_add_mac_addr_ht_filter(mac_filter, ha->addr);
 
-		enetc4_pf_set_si_uc_hash_filter(hw, 0,
-						*mac_filter->mac_hash_table);
+		bitmap_to_arr64(&hash, mac_filter->mac_hash_table,
+				ENETC_MADDR_HASH_TBL_SZ);
+		enetc_set_si_uc_hash_filter(si, 0, hash);
 	}
 
 	if (type & ENETC_MAC_FILTER_TYPE_MC) {
@@ -226,8 +217,9 @@ static void enetc4_pf_set_mac_hash_filter(struct enetc_pf *pf, int type)
 		netdev_for_each_mc_addr(ha, ndev)
 			enetc_add_mac_addr_ht_filter(mac_filter, ha->addr);
 
-		enetc4_pf_set_si_mc_hash_filter(hw, 0,
-						*mac_filter->mac_hash_table);
+		bitmap_to_arr64(&hash, mac_filter->mac_hash_table,
+				ENETC_MADDR_HASH_TBL_SZ);
+		enetc_set_si_mc_hash_filter(si, 0, hash);
 	}
 	netif_addr_unlock_bh(ndev);
 }
@@ -480,7 +472,6 @@ static void enetc4_psi_do_set_rx_mode(struct work_struct *work)
 	struct enetc_si *si = container_of(work, struct enetc_si, rx_mode_task);
 	struct enetc_pf *pf = enetc_si_priv(si);
 	struct net_device *ndev = si->ndev;
-	struct enetc_hw *hw = &si->hw;
 	bool uc_promisc = false;
 	bool mc_promisc = false;
 	int type = 0;
@@ -501,12 +492,12 @@ static void enetc4_psi_do_set_rx_mode(struct work_struct *work)
 	enetc_set_si_mc_promisc(si, 0, mc_promisc);
 
 	if (uc_promisc) {
-		enetc4_pf_set_si_uc_hash_filter(hw, 0, 0);
+		enetc_set_si_uc_hash_filter(si, 0, 0);
 		enetc4_pf_clear_maft_entries(pf);
 	}
 
 	if (mc_promisc)
-		enetc4_pf_set_si_mc_hash_filter(hw, 0, 0);
+		enetc_set_si_mc_hash_filter(si, 0, 0);
 
 	/* Set new MAC filter */
 	enetc4_pf_set_mac_filter(pf, type);
drivers/net/ethernet/freescale/enetc/enetc_pf.c +14 -37

81 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +40 -0
index b0c0dc668e34..3597cb81a7cc 100644
@@ -131,6 +131,46 @@ void enetc_set_si_mc_promisc(struct enetc_si *si, int si_id, bool promisc)
 }
 EXPORT_SYMBOL_GPL(enetc_set_si_mc_promisc);
 
+void enetc_set_si_uc_hash_filter(struct enetc_si *si, int si_id, u64 hash)
+{
+	int psiumhfr0_off, psiumhfr1_off;
+	struct enetc_hw *hw = &si->hw;
+
+	if (is_enetc_rev1(si)) {
+		bool err = si->errata & ENETC_ERR_UCMCSWP;
+
+		psiumhfr0_off = ENETC_PSIUMHFR0(si_id, err);
+		psiumhfr1_off = ENETC_PSIUMHFR1(si_id);
+	} else {
+		psiumhfr0_off = ENETC4_PSIUMHFR0(si_id);
+		psiumhfr1_off = ENETC4_PSIUMHFR1(si_id);
+	}
+
+	enetc_port_wr(hw, psiumhfr0_off, lower_32_bits(hash));
+	enetc_port_wr(hw, psiumhfr1_off, upper_32_bits(hash));
+}
+EXPORT_SYMBOL_GPL(enetc_set_si_uc_hash_filter);
+
+void enetc_set_si_mc_hash_filter(struct enetc_si *si, int si_id, u64 hash)
+{
+	int psimmhfr0_off, psimmhfr1_off;
+	struct enetc_hw *hw = &si->hw;
+
+	if (is_enetc_rev1(si)) {
+		bool err = si->errata & ENETC_ERR_UCMCSWP;
+
+		psimmhfr0_off = ENETC_PSIMMHFR0(si_id, err);
+		psimmhfr1_off = ENETC_PSIMMHFR1(si_id);
+	} else {
+		psimmhfr0_off = ENETC4_PSIMMHFR0(si_id);
+		psimmhfr1_off = ENETC4_PSIMMHFR1(si_id);
+	}
+
+	enetc_port_wr(hw, psimmhfr0_off, lower_32_bits(hash));
+	enetc_port_wr(hw, psimmhfr1_off, upper_32_bits(hash));
+}
+EXPORT_SYMBOL_GPL(enetc_set_si_mc_hash_filter);
+
 void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
 			   const struct net_device_ops *ndev_ops)
 {
drivers/net/ethernet/freescale/enetc/enetc_pf_common.h +2 -0
index a619fb8fed9c..bf9029b0a017 100644
@@ -19,6 +19,8 @@ int enetc_vlan_rx_del_vid(struct net_device *ndev, __be16 prot, u16 vid);
 int enetc_init_sriov_resources(struct enetc_pf *pf);
 void enetc_set_si_uc_promisc(struct enetc_si *si, int si_id, bool promisc);
 void enetc_set_si_mc_promisc(struct enetc_si *si, int si_id, bool promisc);
+void enetc_set_si_uc_hash_filter(struct enetc_si *si, int si_id, u64 hash);
+void enetc_set_si_mc_hash_filter(struct enetc_si *si, int si_id, u64 hash);
 
 static inline u16 enetc_get_ip_revision(struct enetc_hw *hw)
 {
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH RESEND v4 net-next 02/14] net: enetc: extract common helpers for MAC hash filter configuration

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] In enetc_sync_mac_filters, falling back to hash table (HT) filtering after a failed exact match (EM) filter insertion reads corrupted data from a union, configuring an invalid hardware filter. --

--- Patch [2]: [PATCH RESEND v4 net-next 02/14] net: enetc: extract common helpers for MAC hash filter configuration --- commit 9f93708413c38f9e209ca579bcb44ec6059cbebf
Author: Wei Fang <[email protected]>

net: enetc: extract common helpers for MAC hash filter configuration

This commit extracts MAC hash filter configuration helpers to share code between the ENETC v1 and v4 drivers. It introduces enetc_set_si_uc_hash_filter and enetc_set_si_mc_hash_filter to replace duplicated hardware revision specific implementations.

Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.c +0 -0
index a97d2e2dd07b7..db2a800a7aaf0 100644

[ ... ]

Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.c +1 -1
@@ -135,7 +108,7 @@ static void enetc_sync_mac_filters(struct enetc_pf *pf)
 		if (em) {
 			int err;
 
-			enetc_clear_mac_ht_flt(si, 0, UC);
+			enetc_set_si_uc_hash_filter(si, 0, 0);
 
 			err = enetc_set_mac_flt_entry(si, pos, f->mac_addr,
 						      BIT(0));

drivers/net/ethernet/freescale/enetc/enetc_pf.c static void enetc_sync_mac_filters(struct enetc_pf *pf) · line 124

Quoted 5 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.c +2 -0
@@ -147,11 +120,15 @@ static void enetc_sync_mac_filters(struct enetc_pf *pf)
 				 err);
 		}
 
+		bitmap_to_arr64(&hash, f->mac_hash_table,
+				ENETC_MADDR_HASH_TBL_SZ);

[Severity: High]
This is a pre-existing issue, but does the fallback to hash table filtering here read corrupted data?

In struct enetc_mac_filter, mac_addr and mac_hash_table share the same memory space inside a union. When configuring an exact match filter, only mac_addr is populated.

If enetc_set_mac_flt_entry() fails, the code continues to this fallback path and reads from f->mac_hash_table. Since it is a union, wouldn't this just read the raw bytes of the MAC address (along with uninitialized padding) and interpret it as a hash bitmask?

Could this misconfigure the hardware MAC hash filter and lead to incorrect functional behavior and silent packet drops for unicast filtering?

Quoted 12 lines
drivers/net/ethernet/freescale/enetc/enetc_pf.c +5 -3
 		/* hash table filter, clear EM filter for UC entries */
-		if (i == UC)
+		if (i == UC) {
 			enetc_clear_mac_flt_entry(si, pos);
-
-		enetc_set_mac_ht_flt(si, 0, i, *f->mac_hash_table);
+			enetc_set_si_uc_hash_filter(si, 0, hash);
+		} else {
+			enetc_set_si_mc_hash_filter(si, 0, hash);
+		}
 	}
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

PATCH RESEND v4 3/14 net: enetc: convert ndo_set_rx_mode() to ndo_set_rx_mode_async()

In reply to [email protected]

From: Wei Fang <[email protected]>

The current ndo_set_rx_mode() is called under netif_addr_lock spinlock with BHs disabled, which prevents drivers from sleeping. To work around this limitation, the enetc driver uses a dedicated workqueue to defer MAC address list updates to a sleepable context.

Since commit 3554b4345d85 ("net: introduce ndo_set_rx_mode_async and netdev_rx_mode_work") introduced the ndo_set_rx_mode_async() callback, drivers can now handle address list updates directly in a sleepable context.

Therefore, convert the enetc driver to use ndo_set_rx_mode_async() and remove the dedicated workqueue and the deferred work item accordingly.

---
 drivers/net/ethernet/freescale/enetc/enetc.h  |   2 -
 .../net/ethernet/freescale/enetc/enetc4_pf.c  | 178 ++++++------------
 2 files changed, 58 insertions(+), 122 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.h +0 -2
index 04a5dd5ea6c7..06a9f1ee0970 100644
@@ -324,8 +324,6 @@ struct enetc_si {
 	const struct enetc_drvdata *drvdata;
 	const struct enetc_si_ops *ops;
 
-	struct workqueue_struct *workqueue;
-	struct work_struct rx_mode_task;
 	struct dentry *debugfs_root;
 	struct enetc_msg_swbd msg; /* Only valid for VSI */
 };
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +58 -120

287 lines not on this page · raw message

Signature · 1 line
2.34.1
#6 lore raw

PATCH RESEND v4 4/14 net: enetc: improve MAFT entry management with bitmap tracking

In reply to [email protected]

From: Wei Fang <[email protected]>

Replace the counter-based MAFT entry tracking (num_mfe/mac_filter_num) with a bitmap (maft_eid_bitmap) stored in struct ntmp_user, which is a more appropriate place for NTMP resource management.

The bitmap approach brings two improvements. First, the entry deletion in enetc4_pf_clear_maft_entries() now checks the return value of ntmp_maft_delete_entry() and only clears the corresponding bit on success, keeping hardware and software state in sync. Previously, the counter was reset unconditionally regardless of whether the hardware deletion actually succeeded.

Second, entry allocation in enetc4_pf_add_maft_entries() uses ntmp_lookup_free_eid() to find available IDs dynamically, with an upfront capacity check via bitmap_weight() to avoid partial failures.

The MAFT entry count is moved into ntmp_user.maft_num_entries and initialized once during enetc4_init_ntmp_user(). Helper functions enetc4_ntmp_bitmap_init() and enetc4_ntmp_bitmap_free() manage the bitmap lifetime. The debugfs show function is updated accordingly to iterate over set bits under rtnl_lock().

---
 .../ethernet/freescale/enetc/enetc4_debugfs.c | 30 ++++--
 .../net/ethernet/freescale/enetc/enetc4_pf.c  | 97 ++++++++++++++-----
 .../net/ethernet/freescale/enetc/enetc_pf.h   |  3 -
 include/linux/fsl/ntmp.h                      |  2 +
 4 files changed, 96 insertions(+), 36 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c +20 -10
index 1b1591dce73d..4a769d9e5679 100644
@@ -31,9 +31,11 @@ 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 ntmp_user *user;
 	struct enetc_pf *pf;
-	int i, err, num_si;
-	u32 val;
+	u32 val, entry_id;
+	int i, num_si;
+	int err = 0;
 
 	pf = enetc_si_priv(si);
 	num_si = pf->caps.num_vsi + 1;
@@ -50,22 +52,30 @@ static int enetc_mac_filter_show(struct seq_file *s, void *data)
 	for (i = 0; i < num_si; i++)
 		enetc_show_si_mac_hash_filter(s, i);
 
-	if (!pf->num_mfe)
-		return 0;
+	user = &si->ntmp_user;
+	rtnl_lock();
+
+	if (bitmap_empty(user->maft_eid_bitmap, user->maft_num_entries))
+		goto unlock_rtnl;
 
 	/* MAC address filter table */
 	seq_puts(s, "MAC address filter table\n");
-	for (i = 0; i < pf->num_mfe; i++) {
+	for_each_set_bit(entry_id, user->maft_eid_bitmap,
+			 user->maft_num_entries) {
 		memset(&maft, 0, sizeof(maft));
-		err = ntmp_maft_query_entry(&si->ntmp_user, i, &maft);
+		err = ntmp_maft_query_entry(user, entry_id, &maft);
 		if (err)
-			return err;
+			goto unlock_rtnl;
 
-		seq_printf(s, "Entry %d, MAC: %pM, SI bitmap: 0x%04x\n", i,
-			   maft.keye.mac_addr, le16_to_cpu(maft.cfge.si_bitmap));
+		seq_printf(s, "Entry %d, MAC: %pM, SI bitmap: 0x%04x\n",
+			   entry_id, maft.keye.mac_addr,
+			   le16_to_cpu(maft.cfge.si_bitmap));
 	}
 
-	return 0;
+unlock_rtnl:
+	rtnl_unlock();
+
+	return err;
 }
 DEFINE_SHOW_ATTRIBUTE(enetc_mac_filter);
 
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +74 -23

170 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_pf.h +0 -3
index 285b7e5c48fd..6f15f9ea1664 100644
@@ -22,7 +22,6 @@ struct enetc_port_caps {
 	int num_msix;
 	int num_rx_bdr;
 	int num_tx_bdr;
-	int mac_filter_num;
 };
 
 struct enetc_pf;
@@ -60,8 +59,6 @@ struct enetc_pf {
 
 	struct enetc_port_caps caps;
 	const struct enetc_pf_ops *ops;
-
-	int num_mfe;	/* number of mac address filter table entries */
 };
 
 #define phylink_to_enetc_pf(config) \
include/linux/fsl/ntmp.h +2 -0
index d3b6c476b91a..764ef2892608 100644
@@ -75,8 +75,10 @@ struct ntmp_user {
 	/* NTMP table bitmaps for resource management */
 	u32 ett_bitmap_size;
 	u32 ect_bitmap_size;
+	u16 maft_num_entries;
 	unsigned long *ett_gid_bitmap; /* only valid for switch */
 	unsigned long *ect_gid_bitmap; /* only valid for switch */
+	unsigned long *maft_eid_bitmap; /* only valid for ENETC */
 };
 
 struct maft_entry_data {
Signature · 1 line
2.34.1
#7 lore raw

PATCH RESEND v4 5/14 net: enetc: use PCI device name for debugfs directory

In reply to [email protected]

From: Wei Fang <[email protected]>

enetc_create_debugfs() is called right after register_netdev(), at which point ndev->name still holds the format "eth%d" (e.g., eth0) rather than the final assigned name (e.g., via udev rules).

Use pci_name() instead of netdev_name() to name the debugfs directory. The PCI device name is unique, stable, and available from the start, making it a more reliable identifier for the debugfs entry. Therefore, the observable debugfs path from something like /sys/kernel/debug/eth0/mac_filter to a PCI BDF-style path such as /sys/kernel/debug/0002:00:00.0/mac_filter.

---
 drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c +1 -2
index 4a769d9e5679..be378bf8f74d 100644
@@ -81,10 +81,9 @@ 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);
+	root = debugfs_create_dir(pci_name(si->pdev), NULL);
 	if (IS_ERR(root))
 		return;
 
Signature · 1 line
2.34.1
Reviewed-by on v4 5/14
#8 lore raw

Re: [PATCH RESEND v4 net-next 05/14] net: enetc: use PCI device name for debugfs directory

Quoted 24 lines · On Mon, Jul 20, 2026 at 09:43:07AM +0800, [email protected] wrote:

From: Wei Fang <[email protected]>

enetc_create_debugfs() is called right after register_netdev(), at which point ndev->name still holds the format "eth%d" (e.g., eth0) rather than the final assigned name (e.g., via udev rules).

Use pci_name() instead of netdev_name() to name the debugfs directory. The PCI device name is unique, stable, and available from the start, making it a more reliable identifier for the debugfs entry. Therefore, the observable debugfs path from something like /sys/kernel/debug/eth0/mac_filter to a PCI BDF-style path such as /sys/kernel/debug/0002:00:00.0/mac_filter.

---
 drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c +0 -0
index 4a769d9e5679..be378bf8f74d 100644
@@ -81,10 +81,9 @@ DEFINE_SHOW_ATTRIBUTE(enetc_mac_filter);
 

drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c DEFINE_SHOW_ATTRIBUTE(enetc_mac_filter); · line 89

Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c +1 -2
 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);
+	root = debugfs_create_dir(pci_name(si->pdev), NULL);
 	if (IS_ERR(root))
 		return;
 
#9 lore raw

PATCH RESEND v4 6/14 net: enetc: simplify enetc4_set_port_speed()

In reply to [email protected]

From: Wei Fang <[email protected]>

Since phylink may pass SPEED_UNKNOWN to mac_link_up, handle it explicitly by defaulting to SPEED_10, then replace the switch statement with a direct call to PCR_PSPEED_VAL(). Also update PCR_PSPEED_VAL() to use FIELD_PREP() for proper field masking instead of an open-coded shift.

---
 .../net/ethernet/freescale/enetc/enetc4_hw.h  |  2 +-
 .../net/ethernet/freescale/enetc/enetc4_pf.c  | 25 +++++++------------
 2 files changed, 10 insertions(+), 17 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc4_hw.h +1 -1
index 6a8f2ed56017..dea1fd0b8175 100644
@@ -148,7 +148,7 @@
 #define  PCR_L2DOSE			BIT(4)
 #define  PCR_TIMER_CS			BIT(8)
 #define  PCR_PSPEED			GENMASK(29, 16)
-#define  PCR_PSPEED_VAL(speed)		(((speed) / 10 - 1) << 16)
+#define  PCR_PSPEED_VAL(s)		FIELD_PREP(PCR_PSPEED, ((s) / 10 - 1))
 
 /* Port MAC address register 0/1 */
 #define ENETC4_PMAR0			0x4020
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +9 -16
index b966637572a7..f24269a48c26 100644
@@ -628,26 +628,19 @@ static void enetc4_set_port_speed(struct enetc_ndev_priv *priv, int speed)
 	u32 old_speed = priv->speed;
 	u32 val;
 
+	/* If the speed is unknown, use the minimum value */
+	if (speed == SPEED_UNKNOWN) {
+		speed = SPEED_10;
+		dev_warn(priv->dev, "Speed unknown, default is 10Mbps\n");
+	}
+
 	if (speed == old_speed)
 		return;
 
-	val = enetc_port_rd(&priv->si->hw, ENETC4_PCR);
-	val &= ~PCR_PSPEED;
-
-	switch (speed) {
-	case SPEED_100:
-	case SPEED_1000:
-	case SPEED_2500:
-	case SPEED_10000:
-		val |= (PCR_PSPEED & PCR_PSPEED_VAL(speed));
-		break;
-	case SPEED_10:
-	default:
-		val |= (PCR_PSPEED & PCR_PSPEED_VAL(SPEED_10));
-	}
-
-	priv->speed = speed;
+	val = enetc_port_rd(&priv->si->hw, ENETC4_PCR) & (~PCR_PSPEED);
+	val |= PCR_PSPEED_VAL(speed);
 	enetc_port_wr(&priv->si->hw, ENETC4_PCR, val);
+	priv->speed = speed;
 }
 
 static void enetc4_set_rgmii_mac(struct enetc_pf *pf, int speed, int duplex)
Signature · 1 line
2.34.1
#10 lore raw

PATCH RESEND v4 7/14 net: enetc: differentiate phylink capabilities for pseudo-MAC and standalone MAC

In reply to [email protected]

From: Claudiu Manoil <[email protected]>

The ENETC pseudo-MACs are proprietary internal links that do not implement any standard MII interface, so restrict their supported PHY interface modes to PHY_INTERFACE_MODE_INTERNAL only.

Since pseudo-MACs can operate at any speed between 10Mbps and 25Gbps in multiples of 10Mbps, set their MAC capabilities to cover the full range of standard full-duplex speeds: 10/100/1000/2500/5000/10000/ 20000/25000 Mbps.

For standalone ENETC (v4), expand the supported interface modes to include 10GBASER in addition to the existing RGMII, SGMII, 1000BASEX, 2500BASEX and USXGMII modes, with MAC capabilities up to 10G. MAC_1000 is replaced with MAC_1000FD to explicitly exclude 1000M half-duplex, which is not supported.

Note that 10GBASE-R mode of ENETC v4 has not supported yet, the current patch adds PHY_INTERFACE_MODE_10GBASER simply as preparation for the upcoming support of the 10GBASE-R mode.

---
 drivers/net/ethernet/freescale/enetc/enetc.h  |  2 +-
 .../net/ethernet/freescale/enetc/enetc4_pf.c  |  1 -
 .../freescale/enetc/enetc_pf_common.c         | 44 +++++++++++++------
 3 files changed, 32 insertions(+), 15 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.h +1 -1
index 06a9f1ee0970..8839cfb49bcf 100644
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
-/* Copyright 2017-2019 NXP */
+/* Copyright 2017-2019, 2025-2026 NXP */
 
 #include <linux/timer.h>
 #include <linux/pci.h>
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +0 -1
index f24269a48c26..75ee117e9b1d 100644
@@ -602,7 +602,6 @@ static void enetc4_mac_config(struct enetc_pf *pf, unsigned int mode,
 		val |= IFMODE_SGMII;
 		break;
 	case PHY_INTERFACE_MODE_10GBASER:
-	case PHY_INTERFACE_MODE_XGMII:
 	case PHY_INTERFACE_MODE_USXGMII:
 		val |= IFMODE_XGMII;
 		break;
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +31 -13

68 lines not on this page · raw message

Signature · 1 line
2.34.1
#11 lore raw

Re: [PATCH RESEND v4 net-next 07/14] net: enetc: differentiate phylink capabilities for pseudo-MAC and standalone MAC

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] The patch advertises PHY_INTERFACE_MODE_10GBASER as a supported interface to phylink despite the feature being incomplete and explicitly unsupported.

Pre-existing issues:
- [High] The hardware configuration function enetc4_mac_config() does not handle PHY_INTERFACE_MODE_1000BASEX, leading to runtime errors and an unconfigured MAC.
- [High] ENETC v4 fails to probe for any PCS-dependent PHY interface modes because enetc4_pf_ops lacks a create_pcs callback.
--

--- Patch [7]: [PATCH RESEND v4 net-next 07/14] net: enetc: differentiate phylink capabilities for pseudo-MAC and standalone MAC --- commit 87cae554b380c00e9f19136c8479811aa8887e05
Author: Claudiu Manoil <[email protected]>

net: enetc: differentiate phylink capabilities for pseudo-MAC and standalone MAC

This patch restricts ENETC pseudo-MACs to PHY_INTERFACE_MODE_INTERNAL while configuring standard full-duplex speeds. For standalone ENETC (v4), it updates the interface modes to include 10GBASER (as preparation) and explicit duplex capabilities.

drivers/net/ethernet/freescale/enetc/enetc4_pf.c static void enetc4_mac_config(struct enetc_pf *pf, unsigned int mode, · line 604

Quoted 8 lines
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +0 -0
index f24269a48c26b..75ee117e9b1df 100644
@@ -602,7 +602,6 @@ static void enetc4_mac_config(struct enetc_pf *pf, unsigned int mode,
 		val |= IFMODE_SGMII;
 		break;
 	case PHY_INTERFACE_MODE_10GBASER:

[Severity: High]
This isn't a bug introduced by this patch, but does enetc4_mac_config() in drivers/net/ethernet/freescale/enetc/enetc4_pf.c fail to handle PHY_INTERFACE_MODE_1000BASEX?

If phylink configures the MAC for 1000BASEX, which is advertised as supported, it looks like it will fall through to the default case here and leave the MAC unconfigured:

    default:
        dev_err(priv->dev, "Unsupported PHY mode:%d\n", phy_mode);
        return;
Quoted 8 lines
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +0 -1
-	case PHY_INTERFACE_MODE_XGMII:
 	case PHY_INTERFACE_MODE_USXGMII:
 		val |= IFMODE_XGMII;
 		break;
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +0 -0
index 3597cb81a7ccb..781b22198ca86 100644

[ ... ]

drivers/net/ethernet/freescale/enetc/enetc_pf_common.c static bool enetc_port_has_pcs(struct enetc_pf *pf) · line 364

Quoted 8 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +2 -1
@@ -359,7 +359,8 @@ static bool enetc_port_has_pcs(struct enetc_pf *pf)
 	return (pf->if_mode == PHY_INTERFACE_MODE_SGMII ||
 		pf->if_mode == PHY_INTERFACE_MODE_1000BASEX ||
 		pf->if_mode == PHY_INTERFACE_MODE_2500BASEX ||
-		pf->if_mode == PHY_INTERFACE_MODE_USXGMII);
+		pf->if_mode == PHY_INTERFACE_MODE_USXGMII ||
+		pf->if_mode == PHY_INTERFACE_MODE_10GBASER);
 }

[Severity: High]
This is a pre-existing issue, but does ENETC v4 fail to probe for any PCS-dependent interface modes?

Since enetc_port_has_pcs() returns true for SGMII, 1000BASEX, 2500BASEX, USXGMII, and now 10GBASER, enetc_imdio_create() will be called during probe.

However, enetc4_pf_ops in drivers/net/ethernet/freescale/enetc/enetc4_pf.c lacks a .create_pcs callback. Won't this trigger the check in enetc_imdio_create():

    if (!pf->ops->create_pcs) {
        dev_err(dev, "Creating PCS is not supported\n");
        return -EOPNOTSUPP;
    }

and cause the entire probe sequence to fail for these modes?

[ ... ]

Quoted 2 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +0 -0
@@ -400,25 +401,42 @@ int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node *node,
 {

[ ... ]

drivers/net/ethernet/freescale/enetc/enetc_pf_common.c int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node *node, · line 430

Quoted 5 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +5 -0
+		if (!is_enetc_rev1(priv->si)) {
+			mac_caps |= MAC_5000FD | MAC_10000FD;
+			__set_bit(PHY_INTERFACE_MODE_10GBASER,
+				  pf->phylink_config.supported_interfaces);
+		}

[Severity: High]
The commit message explicitly states that 10GBASE-R mode is not supported yet and is added simply as preparation.

Will advertising an unsupported interface mode to phylink in enetc_phylink_create() cause it to accept configurations for it, leading to a broken configuration state or a hard probe failure when it attempts to configure the MAC and PCS?

Quoted 12 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +9 -0
+
+		phy_interface_set_rgmii(pf->phylink_config.supported_interfaces);
+	} else {
+		mac_caps |= MAC_10FD | MAC_100FD | MAC_1000FD | MAC_2500FD |
+			    MAC_5000FD | MAC_10000FD | MAC_20000FD |
+			    MAC_25000FD;
+	}
+
+	pf->phylink_config.mac_capabilities = mac_caps;
 	phylink = phylink_create(&pf->phylink_config, of_fwnode_handle(node),
 				 pf->if_mode, ops);
 	if (IS_ERR(phylink)) {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#12 lore raw

RE: [PATCH RESEND v4 net-next 07/14] net: enetc: differentiate phylink capabilities for pseudo-MAC and standalone MAC

Quoted 15 lines

[ ... ]

Review int enetc_phylink_create(struct enetc_ndev_priv

Quoted 1 line
(quoted diff) +0 -0
@@ -400,25 +401,42 @@ int enetc_phylink_create(struct enetc_ndev_priv

*priv, struct device_node *node,

Quoted 1 line
(quoted diff) +0 -0
 {

[ ... ]

drivers/net/ethernet/freescale/enetc/enetc_pf_common.c int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node *node, · line 430

Quoted 5 lines
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +5 -0
+		if (!is_enetc_rev1(priv->si)) {
+			mac_caps |= MAC_5000FD | MAC_10000FD;
+			__set_bit(PHY_INTERFACE_MODE_10GBASER,
+				  pf->phylink_config.supported_interfaces);
+		}

[Severity: High]
The commit message explicitly states that 10GBASE-R mode is not supported yet and is added simply as preparation.

Quoted 5 lines

Will advertising an unsupported interface mode to phylink in enetc_phylink_create() cause it to accept configurations for it, leading to a broken configuration state or a hard probe failure when it attempts to configure the MAC and PCS?

As the commit message stated, this is simply preparation for 10GBASER mode. The probe should fail if the phy-mode is set to "10gbase-r", which is a normal behavior. No fixed are needed to be fixed for this.

#13 lore raw

PATCH RESEND v4 8/14 net: enetc: remove invalid code from enetc4_pl_mac_link_up()

In reply to [email protected]

From: Wei Fang <[email protected]>

When adding phylink MAC operations support to the NETC switch driver, Russell King pointed out several pieces of invalid logic in the .mac_link_up() implementation (see [1] and [2]):

1) Half-duplex backpressure is not supported by the kernel, Ethernet relies on packet dropping for congestion management.

2) phylink_autoneg_inband() is unnecessary, as RGMII in-band status is not supported.

3) TX and RX pause are disabled in half-duplex mode, so there is no need to override them in .mac_link_up().

The same invalid logic is also present in enetc4_pl_mac_link_up(), so remove the invalid code from it.

Given enetc4_set_hd_flow_control() is removed, pf->caps.half_duplex has also become useless and should therefore be removed as well.

---
 .../net/ethernet/freescale/enetc/enetc4_hw.h  |  2 -
 .../net/ethernet/freescale/enetc/enetc4_pf.c  | 38 +------------------
 .../net/ethernet/freescale/enetc/enetc_pf.h   |  1 -
 3 files changed, 1 insertion(+), 40 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc4_hw.h +0 -2
index dea1fd0b8175..09025e7a2a3a 100644
@@ -135,7 +135,6 @@
 #define ENETC4_PSIVHFR1(a)		((a) * 0x80 + 0x2064)
 
 #define ENETC4_PMCAPR			0x4004
-#define  PMCAPR_HD			BIT(8)
 #define  PMCAPR_FP			GENMASK(10, 9)
 
 /* Port capability register */
@@ -198,7 +197,6 @@
 #define  PM_CMD_CFG_CNT_FRM_EN		BIT(13)
 #define  PM_CMD_CFG_TXP			BIT(15)
 #define  PM_CMD_CFG_SEND_IDLE		BIT(16)
-#define  PM_CMD_CFG_HD_FCEN		BIT(18)
 #define  PM_CMD_CFG_SFD			BIT(21)
 #define  PM_CMD_CFG_TX_FLUSH		BIT(22)
 #define  PM_CMD_CFG_TX_LOWP_EN		BIT(23)
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +1 -37
index 75ee117e9b1d..859b02f5170a 100644
@@ -29,9 +29,6 @@ static void enetc4_get_port_caps(struct enetc_pf *pf)
 	val = enetc_port_rd(hw, ENETC4_ECAPR2);
 	pf->caps.num_rx_bdr = (val & ECAPR2_NUM_RX_BDR) >> 16;
 	pf->caps.num_tx_bdr = val & ECAPR2_NUM_TX_BDR;
-
-	val = enetc_port_rd(hw, ENETC4_PMCAPR);
-	pf->caps.half_duplex = (val & PMCAPR_HD) ? 1 : 0;
 }
 
 static void enetc4_get_psi_hw_features(struct enetc_si *si)
@@ -588,11 +585,6 @@ static void enetc4_mac_config(struct enetc_pf *pf, unsigned int mode,
 	case PHY_INTERFACE_MODE_RGMII_RXID:
 	case PHY_INTERFACE_MODE_RGMII_TXID:
 		val |= IFMODE_RGMII;
-		/* We need to enable auto-negotiation for the MAC
-		 * if its RGMII interface support In-Band status.
-		 */
-		if (phylink_autoneg_inband(mode))
-			val |= PM_IF_MODE_ENA;
 		break;
 	case PHY_INTERFACE_MODE_RMII:
 		val |= IFMODE_RMII;
@@ -695,22 +687,6 @@ static void enetc4_set_rmii_mac(struct enetc_pf *pf, int speed, int duplex)
 	enetc_port_mac_wr(si, ENETC4_PM_IF_MODE(0), val);
 }
 
-static void enetc4_set_hd_flow_control(struct enetc_pf *pf, bool enable)
-{
-	struct enetc_si *si = pf->si;
-	u32 old_val, val;
-
-	if (!pf->caps.half_duplex)
-		return;
-
-	old_val = enetc_port_mac_rd(si, ENETC4_PM_CMD_CFG(0));
-	val = u32_replace_bits(old_val, enable ? 1 : 0, PM_CMD_CFG_HD_FCEN);
-	if (val == old_val)
-		return;
-
-	enetc_port_mac_wr(si, ENETC4_PM_CMD_CFG(0), val);
-}
-
 static void enetc4_set_rx_pause(struct enetc_pf *pf, bool rx_pause)
 {
 	struct enetc_si *si = pf->si;
@@ -886,13 +862,11 @@ static void enetc4_pl_mac_link_up(struct phylink_config *config,
 	struct enetc_pf *pf = phylink_to_enetc_pf(config);
 	struct enetc_si *si = pf->si;
 	struct enetc_ndev_priv *priv;
-	bool hd_fc = false;
 
 	priv = netdev_priv(si->ndev);
 	enetc4_set_port_speed(priv, speed);
 
-	if (!phylink_autoneg_inband(mode) &&
-	    phy_interface_mode_is_rgmii(interface))
+	if (phy_interface_mode_is_rgmii(interface))
 		enetc4_set_rgmii_mac(pf, speed, duplex);
 
 	if (interface == PHY_INTERFACE_MODE_RMII)
@@ -904,18 +878,8 @@ static void enetc4_pl_mac_link_up(struct phylink_config *config,
 		 */
 		if (priv->active_offloads & ENETC_F_QBU)
 			tx_pause = false;
-	} else { /* DUPLEX_HALF */
-		if (tx_pause || rx_pause)
-			hd_fc = true;
-
-		/* As per 802.3 annex 31B, PAUSE frames are only supported
-		 * when the link is configured for full duplex operation.
-		 */
-		tx_pause = false;
-		rx_pause = false;
 	}
 
-	enetc4_set_hd_flow_control(pf, hd_fc);
 	enetc4_set_tx_pause(pf, priv->num_rx_rings, tx_pause);
 	enetc4_set_rx_pause(pf, rx_pause);
 	enetc4_mac_tx_enable(pf);
drivers/net/ethernet/freescale/enetc/enetc_pf.h +0 -1
index 6f15f9ea1664..7e886dc49997 100644
@@ -17,7 +17,6 @@ struct enetc_vf_state {
 };
 
 struct enetc_port_caps {
-	u32 half_duplex:1;
 	int num_vsi;
 	int num_msix;
 	int num_rx_bdr;
Signature · 1 line
2.34.1
#14 lore raw

PATCH RESEND v4 9/14 net: enetc: open-code enetc4_set_default_si_vlan_promisc()

In reply to [email protected]

From: Wei Fang <[email protected]>

The function enetc4_set_default_si_vlan_promisc() is only called once, from enetc4_configure_port_si(). Open-code the loop at the call site and remove the single-use wrapper.

---
 drivers/net/ethernet/freescale/enetc/enetc4_pf.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +3 -12
index 859b02f5170a..505e4abf6c37 100644
@@ -307,17 +307,6 @@ static void enetc4_pf_set_si_vlan_promisc(struct enetc_hw *hw, int si, bool en)
 	enetc_port_wr(hw, ENETC4_PSIPVMR, val);
 }
 
-static void enetc4_set_default_si_vlan_promisc(struct enetc_pf *pf)
-{
-	struct enetc_hw *hw = &pf->si->hw;
-	int num_si = pf->caps.num_vsi + 1;
-	int i;
-
-	/* enforce VLAN promiscuous mode for all SIs */
-	for (i = 0; i < num_si; i++)
-		enetc4_pf_set_si_vlan_promisc(hw, i, true);
-}
-
 /* Allocate the number of MSI-X vectors for per SI. */
 static void enetc4_set_si_msix_num(struct enetc_pf *pf)
 {
@@ -361,7 +350,9 @@ static void enetc4_configure_port_si(struct enetc_pf *pf)
 	/* Outer VLAN tag will be used for VLAN filtering */
 	enetc_port_wr(hw, ENETC4_PSIVLANFMR, PSIVLANFMR_VS);
 
-	enetc4_set_default_si_vlan_promisc(pf);
+	/* Enforce VLAN promiscuous mode for all SIs */
+	for (int i = 0; i < pf->caps.num_vsi + 1; i++)
+		enetc4_pf_set_si_vlan_promisc(hw, i, true);
 
 	/* Disable SI MAC multicast & unicast promiscuous */
 	enetc_port_wr(hw, ENETC4_PSIPMMR, 0);
Signature · 1 line
2.34.1
Reviewed-by on v4 9/14
#15 lore raw

Re: [PATCH RESEND v4 net-next 09/14] net: enetc: open-code enetc4_set_default_si_vlan_promisc()

Quoted 34 lines · On Mon, Jul 20, 2026 at 09:43:11AM +0800, [email protected] wrote:

From: Wei Fang <[email protected]>

The function enetc4_set_default_si_vlan_promisc() is only called once, from enetc4_configure_port_si(). Open-code the loop at the call site and remove the single-use wrapper.

---
 drivers/net/ethernet/freescale/enetc/enetc4_pf.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +0 -11
index 859b02f5170a..505e4abf6c37 100644
@@ -307,17 +307,6 @@ static void enetc4_pf_set_si_vlan_promisc(struct enetc_hw *hw, int si, bool en)
 	enetc_port_wr(hw, ENETC4_PSIPVMR, val);
 }
 
-static void enetc4_set_default_si_vlan_promisc(struct enetc_pf *pf)
-{
-	struct enetc_hw *hw = &pf->si->hw;
-	int num_si = pf->caps.num_vsi + 1;
-	int i;
-
-	/* enforce VLAN promiscuous mode for all SIs */
-	for (i = 0; i < num_si; i++)
-		enetc4_pf_set_si_vlan_promisc(hw, i, true);
-}
-
 /* Allocate the number of MSI-X vectors for per SI. */
 static void enetc4_set_si_msix_num(struct enetc_pf *pf)
 {

drivers/net/ethernet/freescale/enetc/enetc4_pf.c static void enetc4_configure_port_si(struct enetc_pf *pf) · line 358

Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +3 -1
@@ -361,7 +350,9 @@ static void enetc4_configure_port_si(struct enetc_pf *pf)
 	/* Outer VLAN tag will be used for VLAN filtering */
 	enetc_port_wr(hw, ENETC4_PSIVLANFMR, PSIVLANFMR_VS);
 
-	enetc4_set_default_si_vlan_promisc(pf);
+	/* Enforce VLAN promiscuous mode for all SIs */
+	for (int i = 0; i < pf->caps.num_vsi + 1; i++)
+		enetc4_pf_set_si_vlan_promisc(hw, i, true);
 
 	/* Disable SI MAC multicast & unicast promiscuous */
 	enetc_port_wr(hw, ENETC4_PSIPMMR, 0);
#16 lore raw

PATCH RESEND v4 10/14 net: enetc: refactor SI VLAN promiscuous mode configuration

In reply to [email protected]

From: Wei Fang <[email protected]>

Remove the enetc_set_vlan_promisc(), enetc_enable_si_vlan_promisc() and enetc_disable_si_vlan_promisc() functions, and introduce a new unified function enetc_set_si_vlan_promisc() to enable or disable VLAN promiscuous mode for a specific SI. This simplifies the logic and makes the interface more straightforward. The vlan_promisc_simap field in struct enetc_pf is no longer needed to track the current state.

As ENETC V4 only changes the address offset of PSIPVMR register compared to V1 without any functional difference, enetc_set_si_vlan_promisc() can be moved to enetc_pf_common.c in the future with minor adjustments to be reused by the ENETC V4 driver

---
 .../net/ethernet/freescale/enetc/enetc_hw.h   |  5 ++-
 .../net/ethernet/freescale/enetc/enetc_pf.c   | 36 ++++++++-----------
 .../net/ethernet/freescale/enetc/enetc_pf.h   |  1 -
 3 files changed, 16 insertions(+), 26 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_hw.h +2 -3
index 66bfda60da9c..16da732dc5de 100644
@@ -185,9 +185,8 @@ enum enetc_bdr_type {TX, RX};
 #define  PSIPMMR_SI_MAC_MP(n)	BIT((n) + 16)
 
 #define ENETC_PSIPVMR		0x001c
-#define ENETC_VLAN_PROMISC_MAP_ALL	0x7
-#define ENETC_PSIPVMR_SET_VP(simap)	((simap) & 0x7)
-#define ENETC_PSIPVMR_SET_VUTA(simap)	(((simap) & 0x7) << 16)
+#define  PSIPVMR_SI_VLAN_P(n)	BIT(n) /* n = SI index */
+
 #define ENETC_PSIPMAR0(n)	(0x0100 + (n) * 0x8) /* n = SI index */
 #define ENETC_PSIPMAR1(n)	(0x0104 + (n) * 0x8)
 #define ENETC_PVCLCTR		0x0208
drivers/net/ethernet/freescale/enetc/enetc_pf.c +14 -22
index db2a800a7aaf..afc02ed62c77 100644
@@ -42,24 +42,20 @@ static void enetc_pf_destroy_pcs(struct phylink_pcs *pcs)
 	lynx_pcs_destroy(pcs);
 }
 
-static void enetc_set_vlan_promisc(struct enetc_hw *hw, char si_map)
+static void enetc_set_si_vlan_promisc(struct enetc_si *si, int si_id,
+				      bool promisc)
 {
-	u32 val = enetc_port_rd(hw, ENETC_PSIPVMR);
+	struct enetc_hw *hw = &si->hw;
+	u32 val;
 
-	val &= ~ENETC_PSIPVMR_SET_VP(ENETC_VLAN_PROMISC_MAP_ALL);
-	enetc_port_wr(hw, ENETC_PSIPVMR, ENETC_PSIPVMR_SET_VP(si_map) | val);
-}
+	val = enetc_port_rd(hw, ENETC_PSIPVMR);
 
-static void enetc_enable_si_vlan_promisc(struct enetc_pf *pf, int si_idx)
-{
-	pf->vlan_promisc_simap |= BIT(si_idx);
-	enetc_set_vlan_promisc(&pf->si->hw, pf->vlan_promisc_simap);
-}
+	if (promisc)
+		val |= PSIPVMR_SI_VLAN_P(si_id);
+	else
+		val &= ~PSIPVMR_SI_VLAN_P(si_id);
 
-static void enetc_disable_si_vlan_promisc(struct enetc_pf *pf, int si_idx)
-{
-	pf->vlan_promisc_simap &= ~BIT(si_idx);
-	enetc_set_vlan_promisc(&pf->si->hw, pf->vlan_promisc_simap);
+	enetc_port_wr(hw, ENETC_PSIPVMR, val);
 }
 
 static void enetc_set_isol_vlan(struct enetc_hw *hw, int si, u16 vlan, u8 qos)
@@ -441,10 +437,9 @@ static void enetc_configure_port(struct enetc_pf *pf)
 
 	/* split up RFS entries */
 	enetc_port_assign_rfs_entries(pf->si);
-
 	/* enforce VLAN promisc mode for all SIs */
-	pf->vlan_promisc_simap = ENETC_VLAN_PROMISC_MAP_ALL;
-	enetc_set_vlan_promisc(hw, pf->vlan_promisc_simap);
+	for (int i = 0; i < pf->total_vfs + 1; i++)
+		enetc_set_si_vlan_promisc(pf->si, i, true);
 
 	enetc_port_wr(hw, ENETC_PSIPMMR, 0);
 
@@ -466,12 +461,9 @@ static int enetc_pf_set_features(struct net_device *ndev,
 	}
 
 	if (changed & NETIF_F_HW_VLAN_CTAG_FILTER) {
-		struct enetc_pf *pf = enetc_si_priv(priv->si);
+		bool promisc = !(features & NETIF_F_HW_VLAN_CTAG_FILTER);
 
-		if (!!(features & NETIF_F_HW_VLAN_CTAG_FILTER))
-			enetc_disable_si_vlan_promisc(pf, 0);
-		else
-			enetc_enable_si_vlan_promisc(pf, 0);
+		enetc_set_si_vlan_promisc(priv->si, 0, promisc);
 	}
 
 	if (changed & NETIF_F_LOOPBACK)
drivers/net/ethernet/freescale/enetc/enetc_pf.h +0 -1
index 7e886dc49997..1bd3063a3be3 100644
@@ -45,7 +45,6 @@ struct enetc_pf {
 	struct work_struct msg_task;
 	char msg_int_name[ENETC_INT_NAME_MAX];
 
-	char vlan_promisc_simap; /* bitmap of SIs in VLAN promisc mode */
 	DECLARE_BITMAP(vlan_ht_filter, ENETC_VLAN_HT_SIZE);
 	DECLARE_BITMAP(active_vlans, VLAN_N_VID);
 
Signature · 1 line
2.34.1
Reviewed-by on v4 10/14
#17 lore raw

Re: [PATCH RESEND v4 net-next 10/14] net: enetc: refactor SI VLAN promiscuous mode configuration

Quoted 26 lines · On Mon, Jul 20, 2026 at 09:43:12AM +0800, [email protected] wrote:

From: Wei Fang <[email protected]>

Remove the enetc_set_vlan_promisc(), enetc_enable_si_vlan_promisc() and enetc_disable_si_vlan_promisc() functions, and introduce a new unified function enetc_set_si_vlan_promisc() to enable or disable VLAN promiscuous mode for a specific SI. This simplifies the logic and makes the interface more straightforward. The vlan_promisc_simap field in struct enetc_pf is no longer needed to track the current state.

As ENETC V4 only changes the address offset of PSIPVMR register compared to V1 without any functional difference, enetc_set_si_vlan_promisc() can be moved to enetc_pf_common.c in the future with minor adjustments to be reused by the ENETC V4 driver

---
 .../net/ethernet/freescale/enetc/enetc_hw.h   |  5 ++-
 .../net/ethernet/freescale/enetc/enetc_pf.c   | 36 ++++++++-----------
 .../net/ethernet/freescale/enetc/enetc_pf.h   |  1 -
 3 files changed, 16 insertions(+), 26 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_hw.h +0 -0
index 66bfda60da9c..16da732dc5de 100644

drivers/net/ethernet/freescale/enetc/enetc_hw.h enum enetc_bdr_type {TX, RX}; · line 188

Quoted 7 lines
drivers/net/ethernet/freescale/enetc/enetc_hw.h +1 -3
@@ -185,9 +185,8 @@ enum enetc_bdr_type {TX, RX};
 #define  PSIPMMR_SI_MAC_MP(n)	BIT((n) + 16)
 
 #define ENETC_PSIPVMR		0x001c
-#define ENETC_VLAN_PROMISC_MAP_ALL	0x7
-#define ENETC_PSIPVMR_SET_VP(simap)	((simap) & 0x7)
-#define ENETC_PSIPVMR_SET_VUTA(simap)	(((simap) & 0x7) << 16)
+#define  PSIPVMR_SI_VLAN_P(n)	BIT(n) /* n = SI index */

I suppose it would have been nice to only have a single space after #define above.

The rest of the code looks right and I think the promisc logic is clearer, so:

maintainer
#18 lore raw

RE: [PATCH RESEND v4 net-next 10/14] net: enetc: refactor SI VLAN promiscuous mode configuration

Quoted 27 lines
Quoted 12 lines

Remove the enetc_set_vlan_promisc(), enetc_enable_si_vlan_promisc() and enetc_disable_si_vlan_promisc() functions, and introduce a new unified function enetc_set_si_vlan_promisc() to enable or disable VLAN promiscuous mode for a specific SI. This simplifies the logic and makes the interface more straightforward. The vlan_promisc_simap field in struct enetc_pf is no longer needed to track the current state.

As ENETC V4 only changes the address offset of PSIPVMR register compared to V1 without any functional difference, enetc_set_si_vlan_promisc() can be moved to enetc_pf_common.c in the future with minor adjustments to be reused by the ENETC V4 driver

Review

Quoted 8 lines
---
 .../net/ethernet/freescale/enetc/enetc_hw.h   |  5 ++-
 .../net/ethernet/freescale/enetc/enetc_pf.c   | 36 ++++++++-----------
 .../net/ethernet/freescale/enetc/enetc_pf.h   |  1 -
 3 files changed, 16 insertions(+), 26 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/freescale/enetc/enetc_hw.h

Quoted 6 lines

index 66bfda60da9c..16da732dc5de 100644

drivers/net/ethernet/freescale/enetc/enetc_hw.h +0 -0
@@ -185,9 +185,8 @@ enum enetc_bdr_type {TX, RX};
 #define  PSIPMMR_SI_MAC_MP(n)	BIT((n) + 16)
 
Quoted 8 lines

drivers/net/ethernet/freescale/enetc/enetc_hw.h enum enetc_bdr_type {TX, RX}; · line 188

Quoted 5 lines
drivers/net/ethernet/freescale/enetc/enetc_hw.h +1 -3
 #define ENETC_PSIPVMR		0x001c
-#define ENETC_VLAN_PROMISC_MAP_ALL	0x7
-#define ENETC_PSIPVMR_SET_VP(simap)	((simap) & 0x7)
-#define ENETC_PSIPVMR_SET_VUTA(simap)	(((simap) & 0x7) << 16)
+#define  PSIPVMR_SI_VLAN_P(n)	BIT(n) /* n = SI index */

I suppose it would have been nice to only have a single space after #define above.

I intentionally used two spaces for the macros that define the new register bit fields to distinguish them from the macros that define the register offsets, making the hierarchy clearer. :)

Quoted 4 lines

The rest of the code looks right and I think the promisc logic is clearer, so:

#19 lore raw

PATCH RESEND v4 11/14 net: enetc: move enetc_set_si_vlan_promisc() to enetc_pf_common.c

In reply to [email protected]

From: Wei Fang <[email protected]>

The PSIPVMR in ENETC v4 has the same bit layout and functionality as the PSIPVMR register in ENETC v1: bit n (n <= 15) controls VLAN promiscuous mode for SI n. The only difference between the two hardware generations is the register address offset.

Since the register functionality is identical, the VLAN promiscuous mode setting code can be shared between ENETC v1 and v4 drivers.

Move enetc_set_si_vlan_promisc() from enetc_pf.c to enetc_pf_common.c and export it so that it can be shared between the two drivers. Add a revision check using is_enetc_rev1() to select the correct register offset (ENETC_PSIPVMR for v1 and ENETC4_PSIPVMR for v4) while keeping the same logic.

Remove the v4-specific enetc4_pf_set_si_vlan_promisc() from enetc4_pf.c and replace its call site with the new common enetc_set_si_vlan_promisc() to eliminate code duplication.

---
 .../net/ethernet/freescale/enetc/enetc4_pf.c  | 17 ++------------
 .../net/ethernet/freescale/enetc/enetc_pf.c   | 16 --------------
 .../freescale/enetc/enetc_pf_common.c         | 22 +++++++++++++++++++
 .../freescale/enetc/enetc_pf_common.h         |  1 +
 4 files changed, 25 insertions(+), 31 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +2 -15
index 505e4abf6c37..cab79f81d6fe 100644
@@ -295,18 +295,6 @@ static void enetc4_allocate_si_rings(struct enetc_pf *pf)
 	enetc4_default_rings_allocation(pf);
 }
 
-static void enetc4_pf_set_si_vlan_promisc(struct enetc_hw *hw, int si, bool en)
-{
-	u32 val = enetc_port_rd(hw, ENETC4_PSIPVMR);
-
-	if (en)
-		val |= BIT(si);
-	else
-		val &= ~BIT(si);
-
-	enetc_port_wr(hw, ENETC4_PSIPVMR, val);
-}
-
 /* Allocate the number of MSI-X vectors for per SI. */
 static void enetc4_set_si_msix_num(struct enetc_pf *pf)
 {
@@ -352,7 +340,7 @@ static void enetc4_configure_port_si(struct enetc_pf *pf)
 
 	/* Enforce VLAN promiscuous mode for all SIs */
 	for (int i = 0; i < pf->caps.num_vsi + 1; i++)
-		enetc4_pf_set_si_vlan_promisc(hw, i, true);
+		enetc_set_si_vlan_promisc(pf->si, i, true);
 
 	/* Disable SI MAC multicast & unicast promiscuous */
 	enetc_port_wr(hw, ENETC4_PSIPMMR, 0);
@@ -518,12 +506,11 @@ static int enetc4_pf_set_features(struct net_device *ndev,
 {
 	netdev_features_t changed = ndev->features ^ features;
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
-	struct enetc_hw *hw = &priv->si->hw;
 
 	if (changed & NETIF_F_HW_VLAN_CTAG_FILTER) {
 		bool promisc_en = !(features & NETIF_F_HW_VLAN_CTAG_FILTER);
 
-		enetc4_pf_set_si_vlan_promisc(hw, 0, promisc_en);
+		enetc_set_si_vlan_promisc(priv->si, 0, promisc_en);
 	}
 
 	if (changed & NETIF_F_LOOPBACK)
drivers/net/ethernet/freescale/enetc/enetc_pf.c +0 -16
index afc02ed62c77..a509929f89f2 100644
@@ -42,22 +42,6 @@ static void enetc_pf_destroy_pcs(struct phylink_pcs *pcs)
 	lynx_pcs_destroy(pcs);
 }
 
-static void enetc_set_si_vlan_promisc(struct enetc_si *si, int si_id,
-				      bool promisc)
-{
-	struct enetc_hw *hw = &si->hw;
-	u32 val;
-
-	val = enetc_port_rd(hw, ENETC_PSIPVMR);
-
-	if (promisc)
-		val |= PSIPVMR_SI_VLAN_P(si_id);
-	else
-		val &= ~PSIPVMR_SI_VLAN_P(si_id);
-
-	enetc_port_wr(hw, ENETC_PSIPVMR, val);
-}
-
 static void enetc_set_isol_vlan(struct enetc_hw *hw, int si, u16 vlan, u8 qos)
 {
 	u32 val = 0;
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c +22 -0
index 781b22198ca8..d32a195a04c9 100644
@@ -171,6 +171,28 @@ void enetc_set_si_mc_hash_filter(struct enetc_si *si, int si_id, u64 hash)
 }
 EXPORT_SYMBOL_GPL(enetc_set_si_mc_hash_filter);
 
+void enetc_set_si_vlan_promisc(struct enetc_si *si, int si_id, bool promisc)
+{
+	struct enetc_hw *hw = &si->hw;
+	int psipvmr_off;
+	u32 val;
+
+	if (is_enetc_rev1(si))
+		psipvmr_off = ENETC_PSIPVMR;
+	else
+		psipvmr_off = ENETC4_PSIPVMR;
+
+	val = enetc_port_rd(hw, psipvmr_off);
+
+	if (promisc)
+		val |= PSIPVMR_SI_VLAN_P(si_id);
+	else
+		val &= ~PSIPVMR_SI_VLAN_P(si_id);
+
+	enetc_port_wr(hw, psipvmr_off, val);
+}
+EXPORT_SYMBOL_GPL(enetc_set_si_vlan_promisc);
+
 void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
 			   const struct net_device_ops *ndev_ops)
 {
drivers/net/ethernet/freescale/enetc/enetc_pf_common.h +1 -0
index bf9029b0a017..8243ce0de57f 100644
@@ -21,6 +21,7 @@ void enetc_set_si_uc_promisc(struct enetc_si *si, int si_id, bool promisc);
 void enetc_set_si_mc_promisc(struct enetc_si *si, int si_id, bool promisc);
 void enetc_set_si_uc_hash_filter(struct enetc_si *si, int si_id, u64 hash);
 void enetc_set_si_mc_hash_filter(struct enetc_si *si, int si_id, u64 hash);
+void enetc_set_si_vlan_promisc(struct enetc_si *si, int si_id, bool promisc);
 
 static inline u16 enetc_get_ip_revision(struct enetc_hw *hw)
 {
Signature · 1 line
2.34.1
Reviewed-by on v4 11/14
#20 lore raw

Re: [PATCH RESEND v4 net-next 11/14] net: enetc: move enetc_set_si_vlan_promisc() to enetc_pf_common.c

Quoted 20 lines · On Mon, Jul 20, 2026 at 09:43:13AM +0800, [email protected] wrote:

From: Wei Fang <[email protected]>

The PSIPVMR in ENETC v4 has the same bit layout and functionality as the PSIPVMR register in ENETC v1: bit n (n <= 15) controls VLAN promiscuous mode for SI n. The only difference between the two hardware generations is the register address offset.

Since the register functionality is identical, the VLAN promiscuous mode setting code can be shared between ENETC v1 and v4 drivers.

Move enetc_set_si_vlan_promisc() from enetc_pf.c to enetc_pf_common.c and export it so that it can be shared between the two drivers. Add a revision check using is_enetc_rev1() to select the correct register offset (ENETC_PSIPVMR for v1 and ENETC4_PSIPVMR for v4) while keeping the same logic.

Remove the v4-specific enetc4_pf_set_si_vlan_promisc() from enetc4_pf.c and replace its call site with the new common enetc_set_si_vlan_promisc() to eliminate code duplication.

Quoted 7 lines
---
 .../net/ethernet/freescale/enetc/enetc4_pf.c  | 17 ++------------
 .../net/ethernet/freescale/enetc/enetc_pf.c   | 16 --------------
 .../freescale/enetc/enetc_pf_common.c         | 22 +++++++++++++++++++
 .../freescale/enetc/enetc_pf_common.h         |  1 +
 4 files changed, 25 insertions(+), 31 deletions(-)
#21 lore raw

PATCH RESEND v4 12/14 net: enetc: remove redundant num_vsi field from enetc_port_caps

In reply to [email protected]

From: Wei Fang <[email protected]>

The num_vsi field in struct enetc_port_caps is populated by reading the NUM_VSI field of the ECAPR1 register, which reports the number of VSIs supported by the ENETC4 port. When CONFIG_PCI_IOV is enabled, this value always matches pf->total_vfs, which is obtained from the read-only PCI_SRIOV_TOTAL_VF register via pci_sriov_get_totalvfs() during probe. Both ECAPR1[NUM_VSI] and PCI_SRIOV_TOTAL_VF are derived from the same IERB register EaVFRIDAR[NUM_VF] (a 4-bit field), so they are guaranteed to be equal. When CONFIG_PCI_IOV is disabled, pci_sriov_get_totalvfs() returns 0, but this is benign since pci_enable_sriov() is also stubbed to return -ENODEV, so no VF can be created, and enetc4_enable_all_si() only enables the PF SI (PSI).

Since pf->total_vfs already reflects the number of VFs that can actually be used, and is the established convention in the sibling FSL_ENETC PF driver, there is no need to read and cache num_vsi separately in the port capabilities structure. Remove the num_vsi field from enetc_port_caps, and replace all uses of pf->caps.num_vsi with pf->total_vfs in the ring allocation, SI enable, and debugfs code paths. Note that in the MSI-X configuration, it is still necessary to obtain the actual number of VSIs from ECAPR1.

---
 .../ethernet/freescale/enetc/enetc4_debugfs.c | 13 ++-
 .../net/ethernet/freescale/enetc/enetc4_pf.c  | 86 ++++++++++++++-----
 .../net/ethernet/freescale/enetc/enetc_pf.h   |  1 -
 3 files changed, 68 insertions(+), 32 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c +5 -8
index be378bf8f74d..5029038bf99f 100644
@@ -28,17 +28,14 @@ static void enetc_show_si_mac_hash_filter(struct seq_file *s, int i)
 
 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 enetc_pf *pf = enetc_si_priv(s->private);
+	struct enetc_hw *hw = &pf->si->hw;
+	int num_si = pf->total_vfs + 1;
 	struct maft_entry_data maft;
 	struct ntmp_user *user;
-	struct enetc_pf *pf;
 	u32 val, entry_id;
-	int i, num_si;
 	int err = 0;
-
-	pf = enetc_si_priv(si);
-	num_si = pf->caps.num_vsi + 1;
+	int i;
 
 	val = enetc_port_rd(hw, ENETC4_PSIPMMR);
 	for (i = 0; i < num_si; i++) {
@@ -52,7 +49,7 @@ static int enetc_mac_filter_show(struct seq_file *s, void *data)
 	for (i = 0; i < num_si; i++)
 		enetc_show_si_mac_hash_filter(s, i);
 
-	user = &si->ntmp_user;
+	user = &pf->si->ntmp_user;
 	rtnl_lock();
 
 	if (bitmap_empty(user->maft_eid_bitmap, user->maft_num_entries))
drivers/net/ethernet/freescale/enetc/enetc4_pf.c +63 -23

138 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_pf.h +0 -1
index 1bd3063a3be3..56d23a8a11a0 100644
@@ -17,7 +17,6 @@ struct enetc_vf_state {
 };
 
 struct enetc_port_caps {
-	int num_vsi;
 	int num_msix;
 	int num_rx_bdr;
 	int num_tx_bdr;
Signature · 1 line
2.34.1
#22 lore raw

PATCH RESEND v4 13/14 net: enetc: use alloc_etherdev_mqs() to create netdev for VF driver

In reply to [email protected]

From: Wei Fang <[email protected]>

The VF driver uses alloc_etherdev_mq() with ENETC_MAX_NUM_TXQS as the queue count, which forces the TX and RX queue counts to be equal and uses a compile-time constant rather than the actual hardware capability.

After enetc_get_si_caps() is called, si->num_tx_rings and si->num_rx_rings reflect the actual number of rings assigned to the VF by the PF. For the ENETC VF on LS1028A and the upcoming i.MX95/94, their SoCs have no more than 6 CPUs, and the number of TX/RX rings allocated to the VF is less than 8.

Therefore, switch to alloc_etherdev_mqs() so that the TX and RX queue counts are set independently, each capped at ENETC_MAX_NUM_TXQS, based on the actual number of rings assigned to the VF by the PF.

Note that if future SoCs have more than 6 CPUs and more than 6 RX rings allocated to VFs, the size of the int_vector array in struct enetc_ndev_priv will need to be modified. Similarly, if more than 8 TX rings are allocated to each int_vector, ENETC_MAX_NUM_TXQS will also need to be modified.

---
 drivers/net/ethernet/freescale/enetc/enetc_vf.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/ethernet/freescale/enetc/enetc_vf.c +8 -1
index 9cdb0a4d6baf..7dcb4a0246f5 100644
@@ -317,7 +317,14 @@ static int enetc_vf_probe(struct pci_dev *pdev,
 
 	enetc_get_si_caps(si);
 
-	ndev = alloc_etherdev_mq(sizeof(*priv), ENETC_MAX_NUM_TXQS);
+	/* Currently, the supported SoCs have a max of 6 CPUs and the VFs
+	 * have less than 6 RX/TX rings. So no issues for these supported
+	 * SoCs, but for future SoCs which have more CPUs or more TX/RX
+	 * rings, all the related logic needs to be improved.
+	 */
+	ndev = alloc_etherdev_mqs(sizeof(*priv),
+				  min(si->num_tx_rings, ENETC_MAX_NUM_TXQS),
+				  min(si->num_rx_rings, ENETC_MAX_NUM_TXQS));
 	if (!ndev) {
 		err = -ENOMEM;
 		dev_err(&pdev->dev, "netdev creation failed\n");
Signature · 1 line
2.34.1
Reviewed-by on v4 13/14
#23 lore raw

Re: [PATCH RESEND v4 net-next 13/14] net: enetc: use alloc_etherdev_mqs() to create netdev for VF driver

Quoted 34 lines · On Mon, Jul 20, 2026 at 09:43:15AM +0800, [email protected] wrote:

From: Wei Fang <[email protected]>

The VF driver uses alloc_etherdev_mq() with ENETC_MAX_NUM_TXQS as the queue count, which forces the TX and RX queue counts to be equal and uses a compile-time constant rather than the actual hardware capability.

After enetc_get_si_caps() is called, si->num_tx_rings and si->num_rx_rings reflect the actual number of rings assigned to the VF by the PF. For the ENETC VF on LS1028A and the upcoming i.MX95/94, their SoCs have no more than 6 CPUs, and the number of TX/RX rings allocated to the VF is less than 8.

Therefore, switch to alloc_etherdev_mqs() so that the TX and RX queue counts are set independently, each capped at ENETC_MAX_NUM_TXQS, based on the actual number of rings assigned to the VF by the PF.

Note that if future SoCs have more than 6 CPUs and more than 6 RX rings allocated to VFs, the size of the int_vector array in struct enetc_ndev_priv will need to be modified. Similarly, if more than 8 TX rings are allocated to each int_vector, ENETC_MAX_NUM_TXQS will also need to be modified.

---
 drivers/net/ethernet/freescale/enetc/enetc_vf.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/ethernet/freescale/enetc/enetc_vf.c +0 -0
index 9cdb0a4d6baf..7dcb4a0246f5 100644
@@ -317,7 +317,14 @@ static int enetc_vf_probe(struct pci_dev *pdev,
 
 	enetc_get_si_caps(si);

drivers/net/ethernet/freescale/enetc/enetc_vf.c static int enetc_vf_probe(struct pci_dev *pdev, · line 327

Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc_vf.c +8 -1
 
-	ndev = alloc_etherdev_mq(sizeof(*priv), ENETC_MAX_NUM_TXQS);
+	/* Currently, the supported SoCs have a max of 6 CPUs and the VFs
+	 * have less than 6 RX/TX rings. So no issues for these supported
+	 * SoCs, but for future SoCs which have more CPUs or more TX/RX
+	 * rings, all the related logic needs to be improved.
+	 */
+	ndev = alloc_etherdev_mqs(sizeof(*priv),
+				  min(si->num_tx_rings, ENETC_MAX_NUM_TXQS),
+				  min(si->num_rx_rings, ENETC_MAX_NUM_TXQS));

Code looks right, but looks almost like a typo. I guess it would read nicer if ENETC_MAX_NUM_RXQS existed?

That said:

#24 lore raw

RE: [PATCH RESEND v4 net-next 13/14] net: enetc: use alloc_etherdev_mqs() to create netdev for VF driver

Quoted 46 lines · On Mon, Jul 20, 2026 at 09:43:15AM +0800, [email protected] wrote:
Quoted 22 lines

From: Wei Fang <[email protected]>

The VF driver uses alloc_etherdev_mq() with ENETC_MAX_NUM_TXQS as the queue count, which forces the TX and RX queue counts to be equal and uses a compile-time constant rather than the actual hardware capability.

After enetc_get_si_caps() is called, si->num_tx_rings and si->num_rx_rings reflect the actual number of rings assigned to the VF by the PF. For the ENETC VF on LS1028A and the upcoming i.MX95/94, their SoCs have no more than 6 CPUs, and the number of TX/RX rings allocated to the VF is less than 8.

Therefore, switch to alloc_etherdev_mqs() so that the TX and RX queue counts are set independently, each capped at ENETC_MAX_NUM_TXQS, based on the actual number of rings assigned to the VF by the PF.

Note that if future SoCs have more than 6 CPUs and more than 6 RX rings allocated to VFs, the size of the int_vector array in struct enetc_ndev_priv will need to be modified. Similarly, if more than 8 TX rings are allocated to each int_vector, ENETC_MAX_NUM_TXQS will also need to be modified.

Review

Quoted 6 lines
---
 drivers/net/ethernet/freescale/enetc/enetc_vf.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/freescale/enetc/enetc_vf.c

Quoted 5 lines

index 9cdb0a4d6baf..7dcb4a0246f5 100644

drivers/net/ethernet/freescale/enetc/enetc_vf.c +0 -0
@@ -317,7 +317,14 @@ static int enetc_vf_probe(struct pci_dev *pdev,
 

drivers/net/ethernet/freescale/enetc/enetc_vf.c static int enetc_vf_probe(struct pci_dev *pdev, · line 326

Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc_vf.c +7 -1
      enetc_get_si_caps(si);
 
-     ndev = alloc_etherdev_mq(sizeof(*priv), ENETC_MAX_NUM_TXQS);
+     /* Currently, the supported SoCs have a max of 6 CPUs and the VFs
+      * have less than 6 RX/TX rings. So no issues for these supported
+      * SoCs, but for future SoCs which have more CPUs or more TX/RX
+      * rings, all the related logic needs to be improved.
+      */
+     ndev = alloc_etherdev_mqs(sizeof(*priv),
+                               min(si->num_tx_rings,

ENETC_MAX_NUM_TXQS),

Quoted 5 lines

drivers/net/ethernet/freescale/enetc/enetc_vf.c static int enetc_vf_probe(struct pci_dev *pdev, · line 327

Quoted 1 line
drivers/net/ethernet/freescale/enetc/enetc_vf.c +1 -0
+                               min(si->num_rx_rings,

ENETC_MAX_NUM_TXQS));

Code looks right, but looks almost like a typo. I guess it would read nicer if ENETC_MAX_NUM_RXQS existed?

Yes, ENETC_MAX_NUM_RXQS is clearer. However, ENETC_MAX_NUM_RXQS does not exist; in fact, their values ​​are equal, and we plan to remove ENETC_MAX_NUM_TXQS later, so a new macro ENETC_MAX_NUM_RXQS was not added in this patch.

Quoted 4 lines

That said:

#25 lore raw

Re: [PATCH RESEND v4 net-next 13/14] net: enetc: use alloc_etherdev_mqs() to create netdev for VF driver

In reply to [email protected]
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Low] Passing 0 to alloc_etherdev_mqs() triggers a pr_err() inside the networking core if the hardware reports 0 rings.

Pre-existing issues:
- [Critical] Hardware-provided ring counts are not bounded against driver static array sizes, causing out-of-bounds writes. --

--- Patch [13]: [PATCH RESEND v4 net-next 13/14] net: enetc: use alloc_etherdev_mqs() to create netdev for VF driver --- commit 79eef0d032f82d691851f474deed33cca36dd548
Author: Wei Fang <[email protected]>

net: enetc: use alloc_etherdev_mqs() to create netdev for VF driver

This commit changes the VF driver to use alloc_etherdev_mqs() instead of alloc_etherdev_mq(), allowing TX and RX queue counts to be set independently based on the actual hardware capabilities up to ENETC_MAX_NUM_TXQS.

Quoted 7 lines
drivers/net/ethernet/freescale/enetc/enetc_vf.c +0 -0
index 9cdb0a4d6bafb..7dcb4a0246f52 100644
@@ -317,7 +317,14 @@ static int enetc_vf_probe(struct pci_dev *pdev,
 
 	enetc_get_si_caps(si);

drivers/net/ethernet/freescale/enetc/enetc_vf.c static int enetc_vf_probe(struct pci_dev *pdev, · line 327

Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc_vf.c +8 -1
 
-	ndev = alloc_etherdev_mq(sizeof(*priv), ENETC_MAX_NUM_TXQS);
+	/* Currently, the supported SoCs have a max of 6 CPUs and the VFs
+	 * have less than 6 RX/TX rings. So no issues for these supported
+	 * SoCs, but for future SoCs which have more CPUs or more TX/RX
+	 * rings, all the related logic needs to be improved.
+	 */
+	ndev = alloc_etherdev_mqs(sizeof(*priv),
+				  min(si->num_tx_rings, ENETC_MAX_NUM_TXQS),
+				  min(si->num_rx_rings, ENETC_MAX_NUM_TXQS));

[Severity: Low]
Does this code handle the case where the hardware reports 0 rings?

If si->num_tx_rings or si->num_rx_rings is 0, this passes 0 to alloc_etherdev_mqs(), which triggers a "Unable to allocate device with zero queues" pr_err() in the network core and returns NULL. The previous hardcoded ENETC_MAX_NUM_TXQS guaranteed a valid count.

Should there be a check to ensure the ring counts are at least 1?

[Severity: Critical]
This is a pre-existing issue, but is it possible for the hardware to report ring counts that exceed the internal array sizes, causing an out-of-bounds write?

Looking at enetc_init_si_rings_params(), the hardware-provided ring counts are assigned without validating them against the internal array bounds:

drivers/net/ethernet/freescale/enetc/enetc.c:enetc_init_si_rings_params() {
	...
	priv->num_tx_rings = si->num_tx_rings;
	priv->bdr_int_num = priv->num_rx_rings;
	...
}

Subsequently, enetc_alloc_msix() loops over these values and writes to the statically sized arrays in enetc_int_vector_init():

drivers/net/ethernet/freescale/enetc/enetc.c:enetc_int_vector_init() {
	...
	priv->tx_ring[idx] = bdr;
	...
}

A malicious or misconfigured PCI hypervisor or Physical Function (PF) could supply arbitrary values to the Virtual Function (VF) driver. If the hardware reports huge ring counts, this causes a buffer overflow on the heap when writing to priv->int_vector (size 6) and priv->tx_ring (size 16), which could lead to a panic or arbitrary code execution.

Could these values be strictly bounded against the array sizes during probe?

Quoted 3 lines
drivers/net/ethernet/freescale/enetc/enetc_vf.c +0 -0
 	if (!ndev) {
 		err = -ENOMEM;
 		dev_err(&pdev->dev, "netdev creation failed\n");
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
#26 lore raw

RE: [PATCH RESEND v4 net-next 13/14] net: enetc: use alloc_etherdev_mqs() to create netdev for VF driver

Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc_vf.c +3 -1
-	ndev = alloc_etherdev_mq(sizeof(*priv), ENETC_MAX_NUM_TXQS);
+	/* Currently, the supported SoCs have a max of 6 CPUs and the VFs
+	 * have less than 6 RX/TX rings. So no issues for these supported
+	 * SoCs, but for future SoCs which have more CPUs or more TX/RX
Quoted 9 lines

drivers/net/ethernet/freescale/enetc/enetc_vf.c static int enetc_vf_probe(struct pci_dev *pdev, · line 327

Quoted 5 lines
drivers/net/ethernet/freescale/enetc/enetc_vf.c +5 -0
+	 * rings, all the related logic needs to be improved.
+	 */
+	ndev = alloc_etherdev_mqs(sizeof(*priv),
+				  min(si->num_tx_rings, ENETC_MAX_NUM_TXQS),
+				  min(si->num_rx_rings, ENETC_MAX_NUM_TXQS));

[Severity: Low]
Does this code handle the case where the hardware reports 0 rings?

The number of rings cannot be zero; if it is, then it's a severe bug.

Quoted 6 lines

If si->num_tx_rings or si->num_rx_rings is 0, this passes 0 to alloc_etherdev_mqs(), which triggers a "Unable to allocate device with zero queues" pr_err() in the network core and returns NULL. The previous hardcoded ENETC_MAX_NUM_TXQS guaranteed a valid count.

Should there be a check to ensure the ring counts are at least 1?

#27 lore raw

PATCH RESEND v4 14/14 net: enetc: use kzalloc_flex() for enetc_psfp_gate allocation

In reply to [email protected]

From: Wei Fang <[email protected]>

Replace the open-coded struct_size() + kzalloc() pattern with the kzalloc_flex() helper when allocating struct enetc_psfp_gate. This removes the intermediate entries_size local variable and makes the allocation site more concise.

---
 drivers/net/ethernet/freescale/enetc/enetc_qos.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_qos.c +1 -3
index 7b17bca24f26..2aa0fcaafcd2 100644
@@ -1135,7 +1135,6 @@ static int enetc_psfp_parse_clsflower(struct enetc_ndev_priv *priv,
 	struct flow_action_entry *entry;
 	struct action_gate_entry *e;
 	u8 sfi_overwrite = 0;
-	int entries_size;
 	int i, err;
 
 	if (f->common.chain_index >= priv->psfp_cap.max_streamid) {
@@ -1242,8 +1241,7 @@ static int enetc_psfp_parse_clsflower(struct enetc_ndev_priv *priv,
 		goto free_filter;
 	}
 
-	entries_size = struct_size(sgi, entries, entryg->gate.num_entries);
-	sgi = kzalloc(entries_size, GFP_KERNEL);
+	sgi = kzalloc_flex(*sgi, entries, entryg->gate.num_entries);
 	if (!sgi) {
 		err = -ENOMEM;
 		goto free_filter;
Signature · 1 line
2.34.1
Reviewed-by on v4 14/14
#28 lore raw

Re: [PATCH RESEND v4 net-next 14/14] net: enetc: use kzalloc_flex() for enetc_psfp_gate allocation

Quoted 25 lines · On Mon, Jul 20, 2026 at 09:43:16AM +0800, [email protected] wrote:

From: Wei Fang <[email protected]>

Replace the open-coded struct_size() + kzalloc() pattern with the kzalloc_flex() helper when allocating struct enetc_psfp_gate. This removes the intermediate entries_size local variable and makes the allocation site more concise.

---
 drivers/net/ethernet/freescale/enetc/enetc_qos.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_qos.c +0 -1
index 7b17bca24f26..2aa0fcaafcd2 100644
@@ -1135,7 +1135,6 @@ static int enetc_psfp_parse_clsflower(struct enetc_ndev_priv *priv,
 	struct flow_action_entry *entry;
 	struct action_gate_entry *e;
 	u8 sfi_overwrite = 0;
-	int entries_size;
 	int i, err;
 
 	if (f->common.chain_index >= priv->psfp_cap.max_streamid) {

drivers/net/ethernet/freescale/enetc/enetc_qos.c static int enetc_psfp_parse_clsflower(struct enetc_ndev_priv *priv, · line 1247

Quoted 9 lines
drivers/net/ethernet/freescale/enetc/enetc_qos.c +1 -2
@@ -1242,8 +1241,7 @@ static int enetc_psfp_parse_clsflower(struct enetc_ndev_priv *priv,
 		goto free_filter;
 	}
 
-	entries_size = struct_size(sgi, entries, entryg->gate.num_entries);
-	sgi = kzalloc(entries_size, GFP_KERNEL);
+	sgi = kzalloc_flex(*sgi, entries, entryg->gate.num_entries);
 	if (!sgi) {
 		err = -ENOMEM;
 		goto free_filter;
#29 lore raw

Re: [PATCH RESEND v4 net-next 14/14] net: enetc: use kzalloc_flex() for enetc_psfp_gate allocation

In reply to [email protected]
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] List modifications in enetc_psfp_destroy_clsflower lack spinlock protection, leading to race conditions and potential Use-After-Free. --

--- Patch [14]: [PATCH RESEND v4 net-next 14/14] net: enetc: use kzalloc_flex() for enetc_psfp_gate allocation --- commit ac1613be27ea215665e4d0f49e1b480f054aa27f
Author: Wei Fang <[email protected]>

net: enetc: use kzalloc_flex() for enetc_psfp_gate allocation

This commit replaces the open-coded struct_size() + kzalloc() pattern with the kzalloc_flex() helper when allocating struct enetc_psfp_gate. This removes the intermediate entries_size local variable.

Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc_qos.c +0 -0
index 7b17bca24f260..2aa0fcaafcd23 100644

[ ... ]

drivers/net/ethernet/freescale/enetc/enetc_qos.c static int enetc_psfp_parse_clsflower(struct enetc_ndev_priv *priv, · line 1244

Quoted 7 lines
drivers/net/ethernet/freescale/enetc/enetc_qos.c +1 -2
@@ -1242,8 +1241,7 @@ static int enetc_psfp_parse_clsflower(struct enetc_ndev_priv *priv,
 		goto free_filter;
 	}
 
-	entries_size = struct_size(sgi, entries, entryg->gate.num_entries);
-	sgi = kzalloc(entries_size, GFP_KERNEL);
+	sgi = kzalloc_flex(*sgi, entries, entryg->gate.num_entries);

[Severity: High]
This is a pre-existing issue, but is it possible for concurrent TC commands to cause a use-after-free with the shared epsfp lists?

In enetc_psfp_destroy_clsflower(), remove_one_chain() is called:

    remove_one_chain(priv, filter);

This executes hlist_del(&filter->node) and kfree(filter) on the globally shared epsfp.stream_list without acquiring epsfp.psfp_lock.

Concurrently, enetc_psfp_get_stats() iterates this list locklessly:

    filter = enetc_get_stream_by_index(f->common.chain_index);

If a user issues "tc -s filter show" concurrently with "tc filter del", could the lockless iteration in enetc_psfp_get_stats() access the filter freed by remove_one_chain(), leading to memory corruption?

Additionally, does the unlocked deletion race with locked insertions in enetc_psfp_parse_clsflower() causing list corruption?

Quoted 3 lines
drivers/net/ethernet/freescale/enetc/enetc_qos.c +0 -0
 	if (!sgi) {
 		err = -ENOMEM;
 		goto free_filter;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
#30 lore raw
In reply to [email protected]
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Mon, 20 Jul 2026 09:43:02 +0800 you wrote:

From: Wei Fang <[email protected]>

The first group of patches (1, 2, 5-7) eliminates code duplication between the ENETC v1 and v4 drivers. Since both hardware generations share identical register layouts for MAC promiscuous mode, MAC hash filters, and VLAN promiscuous mode - differing only in register address offsets - common helper functions are extracted into enetc_pf_common.c and shared by both drivers.

[...]

Here is the summary with links:
- [RESEND,v4,net-next,01/14] net: enetc: extract common helpers for MAC promiscuous mode setting

    https://git.kernel.org/netdev/net-next/c/2557834ad0ff
  - [RESEND,v4,net-next,02/14] net: enetc: extract common helpers for MAC hash filter configuration
    https://git.kernel.org/netdev/net-next/c/0ce10770963e
  - [RESEND,v4,net-next,03/14] net: enetc: convert ndo_set_rx_mode() to ndo_set_rx_mode_async()
    https://git.kernel.org/netdev/net-next/c/debf0c7a34fa
  - [RESEND,v4,net-next,04/14] net: enetc: improve MAFT entry management with bitmap tracking
    https://git.kernel.org/netdev/net-next/c/6228fc9c2bbe
  - [RESEND,v4,net-next,05/14] net: enetc: use PCI device name for debugfs directory
    https://git.kernel.org/netdev/net-next/c/9db43e6f35db
  - [RESEND,v4,net-next,06/14] net: enetc: simplify enetc4_set_port_speed()
    https://git.kernel.org/netdev/net-next/c/c969fbc01d9e
  - [RESEND,v4,net-next,07/14] net: enetc: differentiate phylink capabilities for pseudo-MAC and standalone MAC
    https://git.kernel.org/netdev/net-next/c/7c9a6ae0edb2
  - [RESEND,v4,net-next,08/14] net: enetc: remove invalid code from enetc4_pl_mac_link_up()
    https://git.kernel.org/netdev/net-next/c/59bb3d62489c
  - [RESEND,v4,net-next,09/14] net: enetc: open-code enetc4_set_default_si_vlan_promisc()
    https://git.kernel.org/netdev/net-next/c/75e134261f61
  - [RESEND,v4,net-next,10/14] net: enetc: refactor SI VLAN promiscuous mode configuration
    https://git.kernel.org/netdev/net-next/c/f7c6dcd6444b
  - [RESEND,v4,net-next,11/14] net: enetc: move enetc_set_si_vlan_promisc() to enetc_pf_common.c
    https://git.kernel.org/netdev/net-next/c/ba07e3bef1b5
  - [RESEND,v4,net-next,12/14] net: enetc: remove redundant num_vsi field from enetc_port_caps
    https://git.kernel.org/netdev/net-next/c/75b136cf0f6f
  - [RESEND,v4,net-next,13/14] net: enetc: use alloc_etherdev_mqs() to create netdev for VF driver
    https://git.kernel.org/netdev/net-next/c/f0c1f31afd97
  - [RESEND,v4,net-next,14/14] net: enetc: use kzalloc_flex() for enetc_psfp_gate allocation
    https://git.kernel.org/netdev/net-next/c/18bf0ac84334

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html