Commit 2a10ab04 authored by Russell King's avatar Russell King Committed by David S. Miller

net: phy: add genphy_check_and_restart_aneg()

Add a helper for restarting autonegotiation(), similar to the clause 45
variant.  Use it in __genphy_config_aneg()
Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent af006240
...@@ -1770,6 +1770,36 @@ int genphy_restart_aneg(struct phy_device *phydev) ...@@ -1770,6 +1770,36 @@ int genphy_restart_aneg(struct phy_device *phydev)
} }
EXPORT_SYMBOL(genphy_restart_aneg); EXPORT_SYMBOL(genphy_restart_aneg);
/**
* genphy_check_and_restart_aneg - Enable and restart auto-negotiation
* @phydev: target phy_device struct
* @restart: whether aneg restart is requested
*
* Check, and restart auto-negotiation if needed.
*/
int genphy_check_and_restart_aneg(struct phy_device *phydev, bool restart)
{
int ret = 0;
if (!restart) {
/* Advertisement hasn't changed, but maybe aneg was never on to
* begin with? Or maybe phy was isolated?
*/
ret = phy_read(phydev, MII_BMCR);
if (ret < 0)
return ret;
if (!(ret & BMCR_ANENABLE) || (ret & BMCR_ISOLATE))
restart = true;
}
if (restart)
ret = genphy_restart_aneg(phydev);
return ret;
}
EXPORT_SYMBOL(genphy_check_and_restart_aneg);
/** /**
* __genphy_config_aneg - restart auto-negotiation or write BMCR * __genphy_config_aneg - restart auto-negotiation or write BMCR
* @phydev: target phy_device struct * @phydev: target phy_device struct
...@@ -1795,23 +1825,7 @@ int __genphy_config_aneg(struct phy_device *phydev, bool changed) ...@@ -1795,23 +1825,7 @@ int __genphy_config_aneg(struct phy_device *phydev, bool changed)
else if (err) else if (err)
changed = true; changed = true;
if (!changed) { return genphy_check_and_restart_aneg(phydev, changed);
/* Advertisement hasn't changed, but maybe aneg was never on to
* begin with? Or maybe phy was isolated?
*/
int ctl = phy_read(phydev, MII_BMCR);
if (ctl < 0)
return ctl;
if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE))
changed = true; /* do restart aneg */
}
/* Only restart aneg if we are advertising something different
* than we were before.
*/
return changed ? genphy_restart_aneg(phydev) : 0;
} }
EXPORT_SYMBOL(__genphy_config_aneg); EXPORT_SYMBOL(__genphy_config_aneg);
......
...@@ -1094,6 +1094,7 @@ void phy_attached_info(struct phy_device *phydev); ...@@ -1094,6 +1094,7 @@ void phy_attached_info(struct phy_device *phydev);
int genphy_read_abilities(struct phy_device *phydev); int genphy_read_abilities(struct phy_device *phydev);
int genphy_setup_forced(struct phy_device *phydev); int genphy_setup_forced(struct phy_device *phydev);
int genphy_restart_aneg(struct phy_device *phydev); int genphy_restart_aneg(struct phy_device *phydev);
int genphy_check_and_restart_aneg(struct phy_device *phydev, bool restart);
int genphy_config_eee_advert(struct phy_device *phydev); int genphy_config_eee_advert(struct phy_device *phydev);
int __genphy_config_aneg(struct phy_device *phydev, bool changed); int __genphy_config_aneg(struct phy_device *phydev, bool changed);
int genphy_aneg_done(struct phy_device *phydev); int genphy_aneg_done(struct phy_device *phydev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment