Skip to contentSkip to conversation

net: pcs: xpcs: make supported_interfaces authoritative

PATCH Superseded Coia Prant 2 participants 4 messages Oct 29 – Oct 30

Subsystems (6)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Coia Prant

author maintainer
#0 lore raw

PATCH v2 1/1 net: pcs: xpcs: make supported_interfaces authoritative

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 10G or 2500BASE-X modes that the Synopsys compat table advertises.

The Rockchip glue currently advertises only SGMII, since that is what the RK3568 MAC side supports today. 1000BASE-X and QSGMII can be added later when the MAC side gains support.

Without narrowing the mask, stmmac_phylink_setup() merges the PCS supported_interfaces into the MAC mask with phy_interface_or(), so the XPCS would contribute 1000BASE-X, 2500BASE-X, USXGMII and the 10G/25G modes to the combined set. The MAC side forces the phy modes and phylink start passes the mode explicitly, so this does not currently make phylink switch to an unsupported mode, but the combined mask still advertises interfaces the SoC cannot use.

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, clear the mask inherited from the compat table and advertise only SGMII, matching what the RK3568 integration exposes today.

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.

1000BASE-X and QSGMII can be enabled later when the MAC side supports them. The C73 10G and 2500BASE-X modes are not implemented on RK3568 and are cleared by the mask.

---
 drivers/net/pcs/pcs-xpcs-rk.c | 6 ++++++
 drivers/net/pcs/pcs-xpcs.c    | 3 +++
 2 files changed, 9 insertions(+)
drivers/net/pcs/pcs-xpcs-rk.c +6 -0
index 6f0a110e32d2..cc11a70d624f 100644
@@ -536,6 +536,12 @@ 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.
+	 */
+	phy_interface_zero(xpcs->pcs.supported_interfaces);
+	__set_bit(PHY_INTERFACE_MODE_SGMII, xpcs->pcs.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
maintainer
#1 lore raw

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

Quoted 5 lines
drivers/net/pcs/pcs-xpcs-rk.c +5 -0
+	/*
+	 * The RK3568 XPCS supports 1000BASE-X, SGMII and QSGMII.
+	 */
+	phy_interface_zero(xpcs->pcs.supported_interfaces);
+	__set_bit(PHY_INTERFACE_MODE_SGMII, xpcs->pcs.supported_interfaces);

The comment and the code does not really match. Why not set the other two interface modes as well?

Andrew

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

maintainer
#2 lore raw
In reply to Coia Prant
Quoted 11 lines · 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 10G or 2500BASE-X modes that the Synopsys compat table advertises.

The Rockchip glue currently advertises only SGMII, since that is what the RK3568 MAC side supports today. 1000BASE-X and QSGMII can be added later when the MAC side gains support.

Quoted 7 lines

Without narrowing the mask, stmmac_phylink_setup() merges the PCS supported_interfaces into the MAC mask with phy_interface_or(), so the XPCS would contribute 1000BASE-X, 2500BASE-X, USXGMII and the 10G/25G modes to the combined set. The MAC side forces the phy modes and phylink start passes the mode explicitly, so this does not currently make phylink switch to an unsupported mode, but the combined mask still advertises interfaces the SoC cannot use.

I don't know this code too well, but something does not feel right here. It might be due to the way stmmac does PCS with phylink, which is often considered broken.

What i would expect to happen is that each piece of hardware indicates what it can do, and then phylink finds the common modes.

So maybe stmmac_phylink_setup() is wrong when it ORs them together?

Maybe look at other MAC drivers using pcs and phylink.

Andrew

author maintainer
#3 lore raw
Quoted 24 lines · Andrew Lunn
Quoted 11 lines · 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 10G or 2500BASE-X modes that the Synopsys compat table advertises.

The Rockchip glue currently advertises only SGMII, since that is what the RK3568 MAC side supports today. 1000BASE-X and QSGMII can be added later when the MAC side gains support.

Quoted 7 lines

Without narrowing the mask, stmmac_phylink_setup() merges the PCS supported_interfaces into the MAC mask with phy_interface_or(), so the XPCS would contribute 1000BASE-X, 2500BASE-X, USXGMII and the 10G/25G modes to the combined set. The MAC side forces the phy modes and phylink start passes the mode explicitly, so this does not currently make phylink switch to an unsupported mode, but the combined mask still advertises interfaces the SoC cannot use.

I don't know this code too well, but something does not feel right here. It might be due to the way stmmac does PCS with phylink, which is often considered broken.

Quoted 8 lines

What i would expect to happen is that each piece of hardware indicates what it can do, and then phylink finds the common modes.

So maybe stmmac_phylink_setup() is wrong when it ORs them together?

Maybe look at other MAC drivers using pcs and phylink.

Andrew

Hi Andrew,

Thanks for the review. The comment is too terse, let me clarify the scope of this patch.

The RK3568 XPCS supports 1000BASE-X, SGMII and QSGMII in hardware, but the Rockchip glue advertises only SGMII for now because that is what the RK3568 MAC side supports today. 1000BASE-X and QSGMII can be added later when the MAC side gains support.

On the stmmac side: I agree the phy_interface_or() in stmmac_phylink_setup() is not the usual intersect model, and it is one of the reasons stmmac's PCS glue is often considered fragile. But the DWMAC binding requires phy-mode globally (snps,dwmac.yaml), so the dwmac-rk glue gets a fixed mode from DT and phylink start passes that mode explicitly. The OR-merged mask therefore does not currently make phylink switch to a mode the SoC cannot use.

I've only been touching this area for the last few months, so I'm guessing it may have been intentional. You might want to ask Russell King, who designed the original logic, for the rationale.

This patch only touches the PCS side. It makes supported_interfaces authoritative on the PCS instance, so xpcs_find_compat() does not configure an interface the glue has marked as unsupported. Reworking stmmac's OR-merge into a proper intersect model is a separate, larger topic, and I'd rather not mix it into this fix.

Coia