Skip to content

Commit 8d3dc3a

Browse files
Russell Kingdavem330
authored andcommitted
net: phy: extract link partner advertisement reading
Move reading the link partner advertisement out of genphy_read_status() into its own separate function. This will allow re-use of this code by PHY drivers that are able to read the resolved status from the PHY. Tested-by: tinywrkb <[email protected]> Signed-off-by: Russell King <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4cf6c57 commit 8d3dc3a

File tree

2 files changed

+41
-25
lines changed

2 files changed

+41
-25
lines changed

drivers/net/phy/phy_device.c

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,32 +1783,9 @@ int genphy_update_link(struct phy_device *phydev)
17831783
}
17841784
EXPORT_SYMBOL(genphy_update_link);
17851785

1786-
/**
1787-
* genphy_read_status - check the link status and update current link state
1788-
* @phydev: target phy_device struct
1789-
*
1790-
* Description: Check the link, then figure out the current state
1791-
* by comparing what we advertise with what the link partner
1792-
* advertises. Start by checking the gigabit possibilities,
1793-
* then move on to 10/100.
1794-
*/
1795-
int genphy_read_status(struct phy_device *phydev)
1786+
int genphy_read_lpa(struct phy_device *phydev)
17961787
{
1797-
int lpa, lpagb, err, old_link = phydev->link;
1798-
1799-
/* Update the link, but return if there was an error */
1800-
err = genphy_update_link(phydev);
1801-
if (err)
1802-
return err;
1803-
1804-
/* why bother the PHY if nothing can have changed */
1805-
if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
1806-
return 0;
1807-
1808-
phydev->speed = SPEED_UNKNOWN;
1809-
phydev->duplex = DUPLEX_UNKNOWN;
1810-
phydev->pause = 0;
1811-
phydev->asym_pause = 0;
1788+
int lpa, lpagb;
18121789

18131790
if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) {
18141791
if (phydev->is_gigabit_capable) {
@@ -1838,6 +1815,44 @@ int genphy_read_status(struct phy_device *phydev)
18381815
return lpa;
18391816

18401817
mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, lpa);
1818+
}
1819+
1820+
return 0;
1821+
}
1822+
EXPORT_SYMBOL(genphy_read_lpa);
1823+
1824+
/**
1825+
* genphy_read_status - check the link status and update current link state
1826+
* @phydev: target phy_device struct
1827+
*
1828+
* Description: Check the link, then figure out the current state
1829+
* by comparing what we advertise with what the link partner
1830+
* advertises. Start by checking the gigabit possibilities,
1831+
* then move on to 10/100.
1832+
*/
1833+
int genphy_read_status(struct phy_device *phydev)
1834+
{
1835+
int err, old_link = phydev->link;
1836+
1837+
/* Update the link, but return if there was an error */
1838+
err = genphy_update_link(phydev);
1839+
if (err)
1840+
return err;
1841+
1842+
/* why bother the PHY if nothing can have changed */
1843+
if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
1844+
return 0;
1845+
1846+
phydev->speed = SPEED_UNKNOWN;
1847+
phydev->duplex = DUPLEX_UNKNOWN;
1848+
phydev->pause = 0;
1849+
phydev->asym_pause = 0;
1850+
1851+
err = genphy_read_lpa(phydev);
1852+
if (err < 0)
1853+
return err;
1854+
1855+
if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) {
18411856
phy_resolve_aneg_linkmode(phydev);
18421857
} else if (phydev->autoneg == AUTONEG_DISABLE) {
18431858
int bmcr = phy_read(phydev, MII_BMCR);

include/linux/phy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@ int genphy_config_eee_advert(struct phy_device *phydev);
10761076
int __genphy_config_aneg(struct phy_device *phydev, bool changed);
10771077
int genphy_aneg_done(struct phy_device *phydev);
10781078
int genphy_update_link(struct phy_device *phydev);
1079+
int genphy_read_lpa(struct phy_device *phydev);
10791080
int genphy_read_status(struct phy_device *phydev);
10801081
int genphy_suspend(struct phy_device *phydev);
10811082
int genphy_resume(struct phy_device *phydev);

0 commit comments

Comments
 (0)