netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: phy: consider latched link-down status in polling mode
@ 2019-02-06 18:39 Heiner Kallweit
  2019-02-09  6:09 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Heiner Kallweit @ 2019-02-06 18:39 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli, David Miller
  Cc: netdev, Russell King - ARM Linux

The link status value latches link-down events. To get the current
status we read the register twice in genphy_update_link(). There's
a potential risk that we miss a link-down event in polling mode.
This may cause issues if the user e.g. connects his machine to a
different network.

On the other hand reading the latched value may cause issues in
interrupt mode. Following scenario:

- After boot link goes up
- phy_start() is called triggering an aneg restart, hence link goes
  down and link-down info is latched.
- After aneg has finished link goes up and triggers an interrupt.
  Interrupt handler reads link status, means it reads the latched
  "link is down" info. But there won't be another interrupt as long
  as link stays up, therefore phylib will never recognize that link
  is up.

Deal with both scenarios by reading the register twice in interrupt
mode only.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/phy-c45.c    | 10 ++++++++--
 drivers/net/phy/phy_device.c | 13 +++++++++----
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c
index c92d0fb7e..449f0f986 100644
--- a/drivers/net/phy/phy-c45.c
+++ b/drivers/net/phy/phy-c45.c
@@ -134,9 +134,15 @@ int genphy_c45_read_link(struct phy_device *phydev, u32 mmd_mask)
 		mmd_mask &= ~BIT(devad);
 
 		/* The link state is latched low so that momentary link
-		 * drops can be detected.  Do not double-read the status
-		 * register if the link is down.
+		 * drops can be detected. Do not double-read the status
+		 * in polling mode to detect such short link drops.
 		 */
+		if (!phy_polling_mode(phydev)) {
+			val = phy_read_mmd(phydev, devad, MDIO_STAT1);
+			if (val < 0)
+				return val;
+		}
+
 		val = phy_read_mmd(phydev, devad, MDIO_STAT1);
 		if (val < 0)
 			return val;
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 891e0178b..d490cd2a8 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1729,10 +1729,15 @@ int genphy_update_link(struct phy_device *phydev)
 {
 	int status;
 
-	/* Do a fake read */
-	status = phy_read(phydev, MII_BMSR);
-	if (status < 0)
-		return status;
+	/* The link state is latched low so that momentary link
+	 * drops can be detected. Do not double-read the status
+	 * in polling mode to detect such short link drops.
+	 */
+	if (!phy_polling_mode(phydev)) {
+		status = phy_read(phydev, MII_BMSR);
+		if (status < 0)
+			return status;
+	}
 
 	/* Read link and autonegotiation status */
 	status = phy_read(phydev, MII_BMSR);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] net: phy: consider latched link-down status in polling mode
  2019-02-06 18:39 [PATCH net-next] net: phy: consider latched link-down status in polling mode Heiner Kallweit
@ 2019-02-09  6:09 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-02-09  6:09 UTC (permalink / raw)
  To: hkallweit1; +Cc: andrew, f.fainelli, netdev, linux

From: Heiner Kallweit <hkallweit1@gmail.com>
Date: Wed, 6 Feb 2019 19:39:52 +0100

> The link status value latches link-down events. To get the current
> status we read the register twice in genphy_update_link(). There's
> a potential risk that we miss a link-down event in polling mode.
> This may cause issues if the user e.g. connects his machine to a
> different network.
> 
> On the other hand reading the latched value may cause issues in
> interrupt mode. Following scenario:
> 
> - After boot link goes up
> - phy_start() is called triggering an aneg restart, hence link goes
>   down and link-down info is latched.
> - After aneg has finished link goes up and triggers an interrupt.
>   Interrupt handler reads link status, means it reads the latched
>   "link is down" info. But there won't be another interrupt as long
>   as link stays up, therefore phylib will never recognize that link
>   is up.
> 
> Deal with both scenarios by reading the register twice in interrupt
> mode only.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-09  6:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-06 18:39 [PATCH net-next] net: phy: consider latched link-down status in polling mode Heiner Kallweit
2019-02-09  6:09 ` David Miller

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).