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

net: phylink: simplify ksettings_set() implementation

Simplify the ksettings_set() implementation to look more like phylib's
implementation; use a switch() for validating the autoneg setting, and
use the linkmode_modify() helper to set the autoneg bit in the
advertisement mask.
Reviewed-by: default avatarIoana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7cceb599
...@@ -1314,25 +1314,24 @@ int phylink_ethtool_ksettings_set(struct phylink *pl, ...@@ -1314,25 +1314,24 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
__ETHTOOL_DECLARE_LINK_MODE_MASK(support); __ETHTOOL_DECLARE_LINK_MODE_MASK(support);
struct ethtool_link_ksettings our_kset; struct ethtool_link_ksettings our_kset;
struct phylink_link_state config; struct phylink_link_state config;
const struct phy_setting *s;
int ret; int ret;
ASSERT_RTNL(); ASSERT_RTNL();
if (kset->base.autoneg != AUTONEG_DISABLE &&
kset->base.autoneg != AUTONEG_ENABLE)
return -EINVAL;
linkmode_copy(support, pl->supported); linkmode_copy(support, pl->supported);
config = pl->link_config; config = pl->link_config;
config.an_enabled = kset->base.autoneg == AUTONEG_ENABLE;
/* Mask out unsupported advertisements */ /* Mask out unsupported advertisements, and force the autoneg bit */
linkmode_and(config.advertising, kset->link_modes.advertising, linkmode_and(config.advertising, kset->link_modes.advertising,
support); support);
linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, config.advertising,
config.an_enabled);
/* FIXME: should we reject autoneg if phy/mac does not support it? */ /* FIXME: should we reject autoneg if phy/mac does not support it? */
if (kset->base.autoneg == AUTONEG_DISABLE) { switch (kset->base.autoneg) {
const struct phy_setting *s; case AUTONEG_DISABLE:
/* Autonegotiation disabled, select a suitable speed and /* Autonegotiation disabled, select a suitable speed and
* duplex. * duplex.
*/ */
...@@ -1351,19 +1350,19 @@ int phylink_ethtool_ksettings_set(struct phylink *pl, ...@@ -1351,19 +1350,19 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
config.speed = s->speed; config.speed = s->speed;
config.duplex = s->duplex; config.duplex = s->duplex;
config.an_enabled = false; break;
__clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, config.advertising); case AUTONEG_ENABLE:
} else {
/* If we have a fixed link, refuse to enable autonegotiation */ /* If we have a fixed link, refuse to enable autonegotiation */
if (pl->cur_link_an_mode == MLO_AN_FIXED) if (pl->cur_link_an_mode == MLO_AN_FIXED)
return -EINVAL; return -EINVAL;
config.speed = SPEED_UNKNOWN; config.speed = SPEED_UNKNOWN;
config.duplex = DUPLEX_UNKNOWN; config.duplex = DUPLEX_UNKNOWN;
config.an_enabled = true; break;
__set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, config.advertising); default:
return -EINVAL;
} }
if (pl->phydev) { if (pl->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