Commit 5fc217a3 authored by David S. Miller's avatar David S. Miller

Merge branch 'mii_bmcr_encode_fixed'

Russell King says:

====================
net: introduce mii_bmcr_encode_fixed()

While converting the mv88e6xxx driver to phylink pcs, it has been
noticed that we've started to have repeated cases where we convert a
speed and duplex to a BMCR value.

Rather than open coding this in multiple locations, let's provide a
helper for this - in linux/mii.h. This helper not only takes care of
the standard 10, 100 and 1000Mbps encodings, but also includes
2500Mbps (which is the same as 1000Mbps) for those users who require
that encoding as well. Unknown speeds will be encoded to 10Mbps, and
non-full duplexes will be encoded as half duplex.

This series converts the existing users to the new helper, and the
mv88e6xxx conversion will add further users in the 6352 and 639x PCS
code.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 5d1d527c 449b7a15
...@@ -1081,23 +1081,7 @@ static void xpcs_link_up_sgmii(struct dw_xpcs *xpcs, unsigned int mode, ...@@ -1081,23 +1081,7 @@ static void xpcs_link_up_sgmii(struct dw_xpcs *xpcs, unsigned int mode,
if (phylink_autoneg_inband(mode)) if (phylink_autoneg_inband(mode))
return; return;
switch (speed) { val = mii_bmcr_encode_fixed(speed, duplex);
case SPEED_1000:
val = BMCR_SPEED1000;
break;
case SPEED_100:
val = BMCR_SPEED100;
break;
case SPEED_10:
val = BMCR_SPEED10;
break;
default:
return;
}
if (duplex == DUPLEX_FULL)
val |= BMCR_FULLDPLX;
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1, val); ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1, val);
if (ret) if (ret)
pr_err("%s: xpcs_write returned %pe\n", __func__, ERR_PTR(ret)); pr_err("%s: xpcs_write returned %pe\n", __func__, ERR_PTR(ret));
......
...@@ -1991,15 +1991,9 @@ static int m88e1510_loopback(struct phy_device *phydev, bool enable) ...@@ -1991,15 +1991,9 @@ static int m88e1510_loopback(struct phy_device *phydev, bool enable)
int err; int err;
if (enable) { if (enable) {
u16 bmcr_ctl = 0, mscr2_ctl = 0; u16 bmcr_ctl, mscr2_ctl = 0;
if (phydev->speed == SPEED_1000) bmcr_ctl = mii_bmcr_encode_fixed(phydev->speed, phydev->duplex);
bmcr_ctl = BMCR_SPEED1000;
else if (phydev->speed == SPEED_100)
bmcr_ctl = BMCR_SPEED100;
if (phydev->duplex == DUPLEX_FULL)
bmcr_ctl |= BMCR_FULLDPLX;
err = phy_write(phydev, MII_BMCR, bmcr_ctl); err = phy_write(phydev, MII_BMCR, bmcr_ctl);
if (err < 0) if (err < 0)
......
...@@ -2001,18 +2001,12 @@ EXPORT_SYMBOL(genphy_config_eee_advert); ...@@ -2001,18 +2001,12 @@ EXPORT_SYMBOL(genphy_config_eee_advert);
*/ */
int genphy_setup_forced(struct phy_device *phydev) int genphy_setup_forced(struct phy_device *phydev)
{ {
u16 ctl = 0; u16 ctl;
phydev->pause = 0; phydev->pause = 0;
phydev->asym_pause = 0; phydev->asym_pause = 0;
if (SPEED_1000 == phydev->speed) ctl = mii_bmcr_encode_fixed(phydev->speed, phydev->duplex);
ctl |= BMCR_SPEED1000;
else if (SPEED_100 == phydev->speed)
ctl |= BMCR_SPEED100;
if (DUPLEX_FULL == phydev->duplex)
ctl |= BMCR_FULLDPLX;
return phy_modify(phydev, MII_BMCR, return phy_modify(phydev, MII_BMCR,
~(BMCR_LOOPBACK | BMCR_ISOLATE | BMCR_PDOWN), ctl); ~(BMCR_LOOPBACK | BMCR_ISOLATE | BMCR_PDOWN), ctl);
...@@ -2614,13 +2608,7 @@ int genphy_loopback(struct phy_device *phydev, bool enable) ...@@ -2614,13 +2608,7 @@ int genphy_loopback(struct phy_device *phydev, bool enable)
u16 val, ctl = BMCR_LOOPBACK; u16 val, ctl = BMCR_LOOPBACK;
int ret; int ret;
if (phydev->speed == SPEED_1000) ctl |= mii_bmcr_encode_fixed(phydev->speed, phydev->duplex);
ctl |= BMCR_SPEED1000;
else if (phydev->speed == SPEED_100)
ctl |= BMCR_SPEED100;
if (phydev->duplex == DUPLEX_FULL)
ctl |= BMCR_FULLDPLX;
phy_modify(phydev, MII_BMCR, ~0, ctl); phy_modify(phydev, MII_BMCR, ~0, ctl);
......
...@@ -545,4 +545,39 @@ static inline u8 mii_resolve_flowctrl_fdx(u16 lcladv, u16 rmtadv) ...@@ -545,4 +545,39 @@ static inline u8 mii_resolve_flowctrl_fdx(u16 lcladv, u16 rmtadv)
return cap; return cap;
} }
/**
* mii_bmcr_encode_fixed - encode fixed speed/duplex settings to a BMCR value
* @speed: a SPEED_* value
* @duplex: a DUPLEX_* value
*
* Encode the speed and duplex to a BMCR value. 2500, 1000, 100 and 10 Mbps are
* supported. 2500Mbps is encoded to 1000Mbps. Other speeds are encoded as 10
* Mbps. Unknown duplex values are encoded to half-duplex.
*/
static inline u16 mii_bmcr_encode_fixed(int speed, int duplex)
{
u16 bmcr;
switch (speed) {
case SPEED_2500:
case SPEED_1000:
bmcr = BMCR_SPEED1000;
break;
case SPEED_100:
bmcr = BMCR_SPEED100;
break;
case SPEED_10:
default:
bmcr = BMCR_SPEED10;
break;
}
if (duplex == DUPLEX_FULL)
bmcr |= BMCR_FULLDPLX;
return bmcr;
}
#endif /* __LINUX_MII_H__ */ #endif /* __LINUX_MII_H__ */
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