Skip to contentSkip to conversation

net: phy: fix PHY interface mask initialization and XPCS usage

PATCH Superseded Coia Prant 3 participants 6 messages Nov 2 – Nov 10

Subsystems (7)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Coia Prant

author maintainer
#0 lore raw

v3 cover net: phy: fix PHY interface mask initialization and XPCS usage

Changes since v2:
- Patch 1 (new): move DECLARE_PHY_INTERFACE_MASK_ZERO to core and fix the array size calculation.
- Patch 2: advertise 1000BASE-X, SGMII and QSGMII instead of only SGMII. Intersect the platform mask with the core mask using phy_interface_and().
- Add Fixes tag for the XPCS patch.

===

This series fixes issues related to the handling of the PHY interface mask (supported_interfaces) at the core level and in the XPCS driver.

Patch 1 fixes a hack in the txgbe driver. The local DECLARE_PHY_INTERFACE_MASK_ZERO() macro incorrectly used PHY_INTERFACE_MODE_MAX as the array length. Move it to include/linux/phy.h and base it on DECLARE_PHY_INTERFACE_MASK() so the bitmap is correctly sized while still being initialized to zero.

Patch 2 makes the XPCS supported_interfaces mask authoritative. The generic compat table advertises modes that a specific integration may not support. The Rockchip glue now builds a platform mask (1000BASE-X, SGMII, QSGMII) and intersects it with the inherited core mask. In addition, xpcs_find_compat() now checks supported_interfaces before looking up the compat table, ensuring the core respects the narrowed mask.

Note: checkpatch.pl reports "Macros with complex values should be enclosed in parentheses" for the new macro in Patch 1. This is a known false positive for declarative macros that expand to variable declarations; wrapping it would break compilation.
---
Coia Prant (2):
net: phy: move DECLARE_PHY_INTERFACE_MASK_ZERO to core
net: pcs: xpcs: make supported_interfaces authoritative

 drivers/net/ethernet/wangxun/txgbe/txgbe_type.h |  3 ---
 drivers/net/pcs/pcs-xpcs-rk.c                   | 10 ++++++++++
 drivers/net/pcs/pcs-xpcs.c                      |  3 +++
 include/linux/phy.h                             |  3 +++
 4 files changed, 16 insertions(+), 3 deletions(-)
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH v3 1/2 net: phy: move DECLARE_PHY_INTERFACE_MASK_ZERO to core

The txgbe driver currently defines DECLARE_PHY_INTERFACE_MASK_ZERO() locally, but incorrectly uses PHY_INTERFACE_MODE_MAX as the array length instead of BITS_TO_LONGS().

Move the macro to include/linux/phy.h and use DECLARE_PHY_INTERFACE_MASK() to properly size the bitmap, while still zeroing the stack variable.

Fixes 47f848aac4e7 ("net: txgbe: initialize PHY interface to 0")
---
 drivers/net/ethernet/wangxun/txgbe/txgbe_type.h | 3 ---
 include/linux/phy.h                             | 3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/wangxun/txgbe/txgbe_type.h +0 -3
index 757d1ce8d3ad..8071464c7b90 100644
@@ -315,9 +315,6 @@ void txgbe_up(struct wx *wx);
 int txgbe_setup_tc(struct net_device *dev, u8 tc);
 void txgbe_do_reset(struct net_device *netdev, bool reinit);
 
-#define DECLARE_PHY_INTERFACE_MASK_ZERO(name) \
-	unsigned long name[PHY_INTERFACE_MODE_MAX] = { 0, }
-
 #define TXGBE_LINK_SPEED_UNKNOWN        0
 #define TXGBE_LINK_SPEED_10GB_FULL      4
 #define TXGBE_LINK_SPEED_25GB_FULL      0x10
include/linux/phy.h +3 -0
index 21afc2082b17..43aba23109fa 100644
@@ -159,6 +159,9 @@ typedef enum {
 #define DECLARE_PHY_INTERFACE_MASK(name) \
 	DECLARE_BITMAP(name, PHY_INTERFACE_MODE_MAX)
 
+#define DECLARE_PHY_INTERFACE_MASK_ZERO(name) \
+	DECLARE_PHY_INTERFACE_MASK(name) = { 0, }
+
 static inline void phy_interface_zero(unsigned long *intf)
 {
 	bitmap_zero(intf, PHY_INTERFACE_MODE_MAX);
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH v3 2/2 net: pcs: xpcs: make supported_interfaces authoritative

In reply to Coia Prant

pcs.supported_interfaces is the mask of interfaces a given xpcs instance actually supports. The compat table describes what the Synopsys IP can do in general, but a specific integration may support a different subset: the RK3568 XPCS supports 1000BASE-X, SGMII and QSGMII in hardware, but does not implement the C73, 10GBASE-R or 2500BASE-X modes that the Synopsys compat table advertises.

However, xpcs_find_compat() only walks desc->compat[] and does not look at pcs.supported_interfaces. If a caller ever passes an interface outside the mask, the core would still find and configure a compat entry for it, contradicting the mask the glue already set. This was a known gap: the mask was written but never consulted by the core.

Fix both sides:

- In xpcs_find_compat(), return NULL when the interface is not in pcs.supported_interfaces, so the mask is authoritative for what the core will configure.
- In the Rockchip glue, build a platform mask with the three modes supported by RK3568 (1000BASE-X, SGMII, QSGMII) and intersect it with the core's supported_interfaces using phy_interface_and(). This narrows the mask inherited from the generic compat table so it reflects the actual SoC capabilities.

This is a logical inconsistency rather than a user-visible bug in a released kernel: the affected Rockchip platform is not present in any released version, and the MAC side forces the phy mode, so phylink does not normally pass an interface outside the mask. The patch makes the mask the single source of truth for both the core and the glue.

Fixes b9e7cb89aac8 ("net: pcs: xpcs: add Rockchip RK3568 platform glue driver")
---
 drivers/net/pcs/pcs-xpcs-rk.c | 10 ++++++++++
 drivers/net/pcs/pcs-xpcs.c    |  3 +++
 2 files changed, 13 insertions(+)
drivers/net/pcs/pcs-xpcs-rk.c +10 -0
index 6f0a110e32d2..25fdc9c6b72c 100644
@@ -483,6 +483,7 @@ struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int
 	struct platform_device *pdev;
 	struct dw_xpcs_rk *pxpcs;
 	struct dw_xpcs *xpcs;
+	DECLARE_PHY_INTERFACE_MASK_ZERO(supported_interfaces);
 
 	if (!of_device_is_available(pcs))
 		return ERR_PTR(-ENODEV);
@@ -536,6 +537,15 @@ struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int
 		return xpcs;
 	}
 
+	/*
+	 * The RK3568 XPCS supports 1000BASE-X, SGMII and QSGMII.
+	 */
+	__set_bit(PHY_INTERFACE_MODE_1000BASEX, supported_interfaces);
+	__set_bit(PHY_INTERFACE_MODE_SGMII, supported_interfaces);
+	__set_bit(PHY_INTERFACE_MODE_QSGMII, supported_interfaces);
+	phy_interface_and(xpcs->pcs.supported_interfaces, xpcs->pcs.supported_interfaces,
+			  supported_interfaces);
+
 	xpcs_config_eee_mult_fact(xpcs, pxpcs->eee_mult_fact);
 	put_device(&pdev->dev);
 	return xpcs;
drivers/net/pcs/pcs-xpcs.c +3 -0
index 6466e0ff2a98..46878a66064e 100644
@@ -169,6 +169,9 @@ xpcs_find_compat(struct dw_xpcs *xpcs, phy_interface_t interface)
 {
 	const struct dw_xpcs_compat *compat;
 
+	if (!test_bit(interface, xpcs->pcs.supported_interfaces))
+		return NULL;
+
 	for (compat = xpcs->desc->compat; compat->supported; compat++)
 		if (compat->interface == interface)
 			return compat;
Signature · 1 line
2.47.3
#5 lore raw
In reply to Coia Prant
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

maintainer
#3 lore raw

Re: [PATCH net v3 2/2] net: pcs: xpcs: make supported_interfaces authoritative

In reply to Coia Prant

drivers/net/pcs/pcs-xpcs-rk.c struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int · line 486

Quoted 9 lines · Coia Prant
drivers/net/pcs/pcs-xpcs-rk.c +1 -0
index 6f0a110e32d2..25fdc9c6b72c 100644
@@ -483,6 +483,7 @@ struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int
  	struct platform_device *pdev;
  	struct dw_xpcs_rk *pxpcs;
  	struct dw_xpcs *xpcs;
+	DECLARE_PHY_INTERFACE_MASK_ZERO(supported_interfaces);

Please respect the reverse christmas tree order above.

drivers/net/pcs/pcs-xpcs-rk.c struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int · line 545

Quoted 13 lines
drivers/net/pcs/pcs-xpcs-rk.c +6 -0
  	if (!of_device_is_available(pcs))
  		return ERR_PTR(-ENODEV);
@@ -536,6 +537,15 @@ struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int
  		return xpcs;
  	}
 
+	/*
+	 * The RK3568 XPCS supports 1000BASE-X, SGMII and QSGMII.
+	 */
+	__set_bit(PHY_INTERFACE_MODE_1000BASEX, supported_interfaces);
+	__set_bit(PHY_INTERFACE_MODE_SGMII, supported_interfaces);
+	__set_bit(PHY_INTERFACE_MODE_QSGMII, supported_interfaces);

Sashiko thinks this last statement is a no op:

https://netdev-ai.bots.linux.dev/sashiko/#/patchset/[email protected]

I don't think this is 'net' material, I suggest resubmitting for net-next.

/P

author maintainer
#4 lore raw

Re: [PATCH net v3 2/2] net: pcs: xpcs: make supported_interfaces authoritative

Quoted 30 lines · Paolo Abeni <[email protected]> 于2026年11月10日周二 22:41写道:

drivers/net/pcs/pcs-xpcs-rk.c struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int · line 486

Quoted 9 lines · Coia Prant
drivers/net/pcs/pcs-xpcs-rk.c +1 -0
index 6f0a110e32d2..25fdc9c6b72c 100644
@@ -483,6 +483,7 @@ struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int
      struct platform_device *pdev;
      struct dw_xpcs_rk *pxpcs;
      struct dw_xpcs *xpcs;
+     DECLARE_PHY_INTERFACE_MASK_ZERO(supported_interfaces);

Please respect the reverse christmas tree order above.

drivers/net/pcs/pcs-xpcs-rk.c struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int · line 545

Quoted 13 lines
drivers/net/pcs/pcs-xpcs-rk.c +6 -0
      if (!of_device_is_available(pcs))
              return ERR_PTR(-ENODEV);
@@ -536,6 +537,15 @@ struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int
              return xpcs;
      }
 
+     /*
+      * The RK3568 XPCS supports 1000BASE-X, SGMII and QSGMII.
+      */
+     __set_bit(PHY_INTERFACE_MODE_1000BASEX, supported_interfaces);
+     __set_bit(PHY_INTERFACE_MODE_SGMII, supported_interfaces);
+     __set_bit(PHY_INTERFACE_MODE_QSGMII, supported_interfaces);

Sashiko thinks this last statement is a no op:

Quoted 6 lines

https://netdev-ai.bots.linux.dev/sashiko/#/patchset/[email protected]

I don't think this is 'net' material, I suggest resubmitting for net-next.

/P

Hi Paolo,

Thanks for the review.

1. Reverse Christmas tree: My bad, I will move the DECLARE_PHY_INTERFACE_MASK_ZERO declaration to the top of the function to comply with the variable ordering.

2. QSGMII no-op: Sashiko is right, it is currently a no-op. The core's compat table does not have an entry for QSGMII, so the intersection (phy_interface_and) filters it out. This actually demonstrates the intended behavior perfectly: the glue reports what the hardware can do, and the core filters it based on what it actually supports. If the core adds QSGMII support in the future, the glue will automatically pick it up. I'll add a brief note in the commit message to clarify this.

3. Tree selection: Understood. I will rebase and resubmit the series for net-next.

Coia