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.
Unified · Split
| @@ -1723,10 +1723,8 @@ int genphy_update_link(struct phy_device *phydev) · 1722 unmodified lines | ||
| 1723 | 1723 | if (status < 0) |
| 1724 | 1724 | return status; |
| 1725 | 1725 | |
| 1726 | − if ((status & BMSR_LSTATUS) == 0) | |
| 1727 | − phydev->link = 0; | |
| 1728 | − else | |
| 1729 | − phydev->link = 1; | |
| 1726 | + phydev->link = status & BMSR_LSTATUS ? 1 : 0; | |
| 1727 | + phydev->autoneg_complete = status & BMSR_ANEGCOMPLETE ? 1 : 0; | |
| 1730 | 1728 | |
| 1731 | 1729 | return 0; |
| 1732 | 1730 | } |
| @@ -1757,7 +1755,7 @@ int genphy_read_status(struct phy_device *phydev) · 24 unmodified lines | ||
| 1757 | 1755 | |
| 1758 | 1756 | linkmode_zero(phydev->lp_advertising); |
| 1759 | 1757 | |
| 1760 | − if (phydev->autoneg == AUTONEG_ENABLE && phydev->link) { | |
| 1758 | + if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) { | |
| 1761 | 1759 | if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, |
| 1762 | 1760 | phydev->supported) || |
| 1763 | 1761 | linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, |
| @@ -390,6 +390,7 @@ struct phy_device { · 389 unmodified lines | ||
| 390 | 390 | unsigned autoneg:1; |
| 391 | 391 | /* The most recently read link state */ |
| 392 | 392 | unsigned link:1; |
| 393 | + unsigned autoneg_complete:1; | |
| 393 | 394 | |
| 394 | 395 | /* Interrupts are enabled */ |
| 395 | 396 | unsigned interrupts:1; |