Subject: [PATCH net 2/3] net: dsa: mv88e6xxx: Fix reading sgmii link status register

From: Marek Behún <[email-masked]>
Date: Wed, 10 Nov 2021 05:10:09 +0100

The documentation says this about the SerDes PHY register 4.2001.2:
  This register bit indicates when link was lost since the last
  read. For the current link status, read this register
  back-to-back.

Thus we need to read it twice to get the current value of the register.

The wrong value is read when phylink requests change from sgmii to
2500base-x mode, and link won't come up. This fixes the bug.

Fixes: a5a6858b793f ("net: dsa: mv88e6xxx: extend phylink to Serdes PHYs")
Signed-off-by: Marek Behún <[email-masked]>
---
 drivers/net/dsa/mv88e6xxx/serdes.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/net/dsa/mv88e6xxx/serdes.c b/drivers/net/dsa/mv88e6xxx/serdes.c
index 6ea003678798..bc198ef06745 100644
--- a/drivers/net/dsa/mv88e6xxx/serdes.c
+++ b/drivers/net/dsa/mv88e6xxx/serdes.c
@@ -1041,15 +1041,25 @@ static void mv88e6390_serdes_irq_link_sgmii(struct mv88e6xxx_chip *chip,
 	u16 bmsr;
 	int err;
 
-	/* If the link has dropped, we want to know about it. */
+	/* If the link has dropped, we want to know about it.
+	 * This register bit indicates when link was lost since the last read.
+	 * We need to read it twice to get the current value.
+	 */
 	err = mv88e6390_serdes_read(chip, lane, MDIO_MMD_PHYXS,
 				    MV88E6390_SGMII_BMSR, &bmsr);
-	if (err) {
-		dev_err(chip->dev, "can't read Serdes BMSR: %d\n", err);
-		return;
-	}
+	if (err)
+		goto err;
+
+	err = mv88e6390_serdes_read(chip, lane, MDIO_MMD_PHYXS,
+				    MV88E6390_SGMII_BMSR, &bmsr);
+	if (err)
+		goto err;
 
 	dsa_port_phylink_mac_change(chip->ds, port, !!(bmsr & BMSR_LSTATUS));
+
+	return;
+err:
+	dev_err(chip->dev, "can't read Serdes BMSR: %d\n", err);
 }
 
 static void mv88e6393x_serdes_irq_link_10g(struct mv88e6xxx_chip *chip,
-- 
2.32.0