Skip to content

Commit

Permalink
net: phy: consider latched link-down status in polling mode
Browse files Browse the repository at this point in the history
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Heiner Kallweit authored and David S. Miller committed Feb 9, 2019
1 parent 3e3e0cd commit 93c0970
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 8 additions & 2 deletions drivers/net/phy/phy-c45.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,15 @@ int genphy_c45_read_link(struct phy_device *phydev)
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;
Expand Down
13 changes: 9 additions & 4 deletions drivers/net/phy/phy_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 93c0970

Please sign in to comment.