[PATCH RFC v4 07/15] net: pcs: xpcs: wait for SGMII AN to complete in-band

Jan Petrous via B4 Relay devnull+jan.petrous.oss.nxp.com at kernel.org
Wed Nov 25 01:33:49 PST 2026


From: "Jan Petrous (OSS)" <jan.petrous at oss.nxp.com>

With in-band SGMII, the S32G XPCS keeps the previous SGMII link word in
VR_MII_AN_INTR_STS until the next negotiation completes, so phylink can
latch a stale speed after the link partner changes speed.

Add DW_XPCS_QUIRK_SGMII_WAIT_AN: with in-band negotiation enabled,
report the link down until BMSR reports AN complete. Set it for S32G
only.

Signed-off-by: Jan Petrous (OSS) <jan.petrous at oss.nxp.com>
---
 drivers/net/pcs/pcs-xpcs.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c
index 71e5882f4b0b..65597c2d7a89 100644
--- a/drivers/net/pcs/pcs-xpcs.c
+++ b/drivers/net/pcs/pcs-xpcs.c
@@ -166,6 +166,11 @@ struct dw_xpcs_compat {
 #define DW_XPCS_QUIRK_NO_SOFT_RESET	BIT(0)
 /* VR_MII_EEE_MCTRL0/1 are not implemented */
 #define DW_XPCS_QUIRK_NO_EEE		BIT(1)
+/*
+ * With in-band SGMII, VR_MII_AN_INTR_STS keeps the previous SGMII word until
+ * the next negotiation completes; only trust it once BMSR reports AN complete
+ */
+#define DW_XPCS_QUIRK_SGMII_WAIT_AN	BIT(2)
 
 struct dw_xpcs_desc {
 	u32 id;
@@ -1081,6 +1086,7 @@ static int xpcs_get_state_c73(struct dw_xpcs *xpcs,
 }
 
 static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs,
+				    unsigned int neg_mode,
 				    struct phylink_link_state *state)
 {
 	int ret;
@@ -1092,6 +1098,16 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs,
 	state->duplex = DUPLEX_UNKNOWN;
 	state->pause = 0;
 
+	if (xpcs->desc->quirks & DW_XPCS_QUIRK_SGMII_WAIT_AN &&
+	    neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) {
+		ret = xpcs_read(xpcs, MDIO_MMD_VEND2, MII_BMSR);
+		if (ret < 0)
+			return ret;
+
+		if (!(ret & BMSR_ANEGCOMPLETE))
+			return 0;
+	}
+
 	/* For C37 SGMII mode, we check DW_VR_MII_AN_INTR_STS for link
 	 * status, speed and duplex.
 	 */
@@ -1218,7 +1234,7 @@ static void xpcs_get_state(struct phylink_pcs *pcs, unsigned int neg_mode,
 				"xpcs_get_state_c73", ERR_PTR(ret));
 		break;
 	case DW_AN_C37_SGMII:
-		ret = xpcs_get_state_c37_sgmii(xpcs, state);
+		ret = xpcs_get_state_c37_sgmii(xpcs, neg_mode, state);
 		if (ret)
 			dev_err(&xpcs->mdiodev->dev, "%s returned %pe\n",
 				"xpcs_get_state_c37_sgmii", ERR_PTR(ret));
@@ -1535,7 +1551,8 @@ static const struct dw_xpcs_desc xpcs_desc_list[] = {
 		.mask = DW_XPCS_ID_MASK,
 		.pma = NXP_S32G_XPCS_PMA_ID,
 		.compat = nxp_s32g_xpcs_compat,
-		.quirks = DW_XPCS_QUIRK_NO_SOFT_RESET | DW_XPCS_QUIRK_NO_EEE,
+		.quirks = DW_XPCS_QUIRK_NO_SOFT_RESET | DW_XPCS_QUIRK_NO_EEE |
+			  DW_XPCS_QUIRK_SGMII_WAIT_AN,
 	},
 };
 

-- 
2.55.0





More information about the linux-phy mailing list