Skip to content

Commit

Permalink
net: phy: fix autoneg mismatch case in genphy_read_status
Browse files Browse the repository at this point in the history
The original patch didn't consider the case that autoneg process
finishes successfully but both link partners have no mode in common.
In this case there's no link, nevertheless we may be interested in
what the link partner advertised.

Like phydev->link we set phydev->autoneg_complete in
genphy_update_link() and use the stored value in genphy_read_status().
This way we don't have to read register BMSR again.

Fixes: b6163f1 ("net: phy: improve genphy_read_status")
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Heiner Kallweit authored and David S. Miller committed Apr 4, 2019
1 parent 49ffba3 commit 4950c2b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
8 changes: 3 additions & 5 deletions drivers/net/phy/phy_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -1723,10 +1723,8 @@ int genphy_update_link(struct phy_device *phydev)
if (status < 0)
return status;

if ((status & BMSR_LSTATUS) == 0)
phydev->link = 0;
else
phydev->link = 1;
phydev->link = status & BMSR_LSTATUS ? 1 : 0;
phydev->autoneg_complete = status & BMSR_ANEGCOMPLETE ? 1 : 0;

return 0;
}
Expand Down Expand Up @@ -1757,7 +1755,7 @@ int genphy_read_status(struct phy_device *phydev)

linkmode_zero(phydev->lp_advertising);

if (phydev->autoneg == AUTONEG_ENABLE && phydev->link) {
if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) {
if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
phydev->supported) ||
linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
Expand Down
1 change: 1 addition & 0 deletions include/linux/phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ struct phy_device {
unsigned autoneg:1;
/* The most recently read link state */
unsigned link:1;
unsigned autoneg_complete:1;

/* Interrupts are enabled */
unsigned interrupts:1;
Expand Down

0 comments on commit 4950c2b

Please sign in to comment.