netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: netdev@vger.kernel.org, Andrew Lunn <andrew@lunn.ch>
Cc: "Jakub Kicinski" <kuba@kernel.org>,
	"David Miller" <davem@davemloft.net>,
	"Russell King" <rmk+kernel@armlinux.org.uk>,
	"Marek Behún" <kabel@kernel.org>
Subject: [PATCH net 2/3] net: dsa: mv88e6xxx: Fix reading sgmii link status register
Date: Wed, 10 Nov 2021 05:10:09 +0100	[thread overview]
Message-ID: <20211110041010.2402-2-kabel@kernel.org> (raw)
In-Reply-To: <20211110041010.2402-1-kabel@kernel.org>

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 <kabel@kernel.org>
---
 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


  reply	other threads:[~2021-11-10  4:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-10  4:10 [PATCH net 1/3] net: dsa: mv88e6xxx: Fix forcing speed & duplex when changing to 2500base-x mode Marek Behún
2021-11-10  4:10 ` Marek Behún [this message]
2021-11-10  4:10 ` [PATCH net 3/3] net: dsa: mv88e6xxx: Link in pcs_get_state() even if LP has AN disabled Marek Behún
2021-11-10  8:01 ` [PATCH net 1/3] net: dsa: mv88e6xxx: Fix forcing speed & duplex when changing to 2500base-x mode Russell King (Oracle)
2021-11-10 13:18 ` Andrew Lunn
2021-11-10 14:07   ` Marek Behún

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211110041010.2402-2-kabel@kernel.org \
    --to=kabel@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rmk+kernel@armlinux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).