Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: phy: Convert u32 phydev->lp_advertising to linkmode

Convert phy drivers to report the link partner advertised modes using
a linkmode bitmap. This allows them to report the higher speeds which
don't fit in a u32.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Andrew Lunn and committed by
David S. Miller
c0ec3c27 3c1bcc86

+72 -41
+2 -2
drivers/net/phy/lxt.c
··· 177 177 */ 178 178 } while (lpa == adv && retry--); 179 179 180 - phydev->lp_advertising = mii_lpa_to_ethtool_lpa_t(lpa); 180 + mii_lpa_to_linkmode_lpa_t(phydev->lp_advertising, lpa); 181 181 182 182 lpa &= adv; 183 183 ··· 218 218 phydev->speed = SPEED_10; 219 219 220 220 phydev->pause = phydev->asym_pause = 0; 221 - phydev->lp_advertising = 0; 221 + linkmode_zero(phydev->lp_advertising); 222 222 } 223 223 224 224 return 0;
+12 -14
drivers/net/phy/marvell.c
··· 1049 1049 } 1050 1050 1051 1051 /** 1052 - * fiber_lpa_to_ethtool_lpa_t 1052 + * fiber_lpa_to_linkmode_lpa_t 1053 + * @advertising: the linkmode advertisement settings 1053 1054 * @lpa: value of the MII_LPA register for fiber link 1054 1055 * 1055 1056 * A small helper function that translates MII_LPA 1056 - * bits to ethtool LP advertisement settings. 1057 + * bits to linkmode LP advertisement settings. 1057 1058 */ 1058 - static u32 fiber_lpa_to_ethtool_lpa_t(u32 lpa) 1059 + static void fiber_lpa_to_linkmode_lpa_t(unsigned long *advertising, u32 lpa) 1059 1060 { 1060 - u32 result = 0; 1061 - 1062 1061 if (lpa & LPA_FIBER_1000HALF) 1063 - result |= ADVERTISED_1000baseT_Half; 1062 + linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, 1063 + advertising); 1064 1064 if (lpa & LPA_FIBER_1000FULL) 1065 - result |= ADVERTISED_1000baseT_Full; 1066 - 1067 - return result; 1065 + linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, 1066 + advertising); 1068 1067 } 1069 1068 1070 1069 /** ··· 1139 1140 } 1140 1141 1141 1142 if (!fiber) { 1142 - phydev->lp_advertising = 1143 - mii_stat1000_to_ethtool_lpa_t(lpagb) | 1144 - mii_lpa_to_ethtool_lpa_t(lpa); 1143 + mii_lpa_to_linkmode_lpa_t(phydev->lp_advertising, lpa); 1144 + mii_stat1000_to_linkmode_lpa_t(phydev->lp_advertising, lpagb); 1145 1145 1146 1146 if (phydev->duplex == DUPLEX_FULL) { 1147 1147 phydev->pause = lpa & LPA_PAUSE_CAP ? 1 : 0; ··· 1148 1150 } 1149 1151 } else { 1150 1152 /* The fiber link is only 1000M capable */ 1151 - phydev->lp_advertising = fiber_lpa_to_ethtool_lpa_t(lpa); 1153 + fiber_lpa_to_linkmode_lpa_t(phydev->lp_advertising, lpa); 1152 1154 1153 1155 if (phydev->duplex == DUPLEX_FULL) { 1154 1156 if (!(lpa & LPA_PAUSE_FIBER)) { ··· 1187 1189 1188 1190 phydev->pause = 0; 1189 1191 phydev->asym_pause = 0; 1190 - phydev->lp_advertising = 0; 1192 + linkmode_zero(phydev->lp_advertising); 1191 1193 1192 1194 return 0; 1193 1195 }
+2 -2
drivers/net/phy/marvell10g.c
··· 457 457 458 458 phydev->speed = SPEED_UNKNOWN; 459 459 phydev->duplex = DUPLEX_UNKNOWN; 460 - phydev->lp_advertising = 0; 460 + linkmode_zero(phydev->lp_advertising); 461 461 phydev->link = 0; 462 462 phydev->pause = 0; 463 463 phydev->asym_pause = 0; ··· 490 490 if (val < 0) 491 491 return val; 492 492 493 - phydev->lp_advertising |= mii_stat1000_to_ethtool_lpa_t(val); 493 + mii_stat1000_to_linkmode_lpa_t(phydev->lp_advertising, val); 494 494 495 495 if (phydev->autoneg == AUTONEG_ENABLE) 496 496 phy_resolve_aneg_linkmode(phydev);
+3 -2
drivers/net/phy/phy-c45.c
··· 181 181 if (val < 0) 182 182 return val; 183 183 184 - phydev->lp_advertising = mii_lpa_to_ethtool_lpa_t(val); 184 + mii_lpa_to_linkmode_lpa_t(phydev->lp_advertising, val); 185 185 phydev->pause = val & LPA_PAUSE_CAP ? 1 : 0; 186 186 phydev->asym_pause = val & LPA_PAUSE_ASYM ? 1 : 0; 187 187 ··· 191 191 return val; 192 192 193 193 if (val & MDIO_AN_10GBT_STAT_LP10G) 194 - phydev->lp_advertising |= ADVERTISED_10000baseT_Full; 194 + linkmode_set_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT, 195 + phydev->lp_advertising); 195 196 196 197 return 0; 197 198 }
+6 -7
drivers/net/phy/phy-core.c
··· 199 199 void phy_resolve_aneg_linkmode(struct phy_device *phydev) 200 200 { 201 201 __ETHTOOL_DECLARE_LINK_MODE_MASK(common); 202 - __ETHTOOL_DECLARE_LINK_MODE_MASK(lp); 203 202 204 - ethtool_convert_legacy_u32_to_link_mode(lp, phydev->lp_advertising); 205 - 206 - linkmode_and(common, lp, phydev->advertising); 203 + linkmode_and(common, phydev->lp_advertising, phydev->advertising); 207 204 208 205 if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT, common)) { 209 206 phydev->speed = SPEED_10000; ··· 232 235 } 233 236 234 237 if (phydev->duplex == DUPLEX_FULL) { 235 - phydev->pause = !!(phydev->lp_advertising & ADVERTISED_Pause); 236 - phydev->asym_pause = !!(phydev->lp_advertising & 237 - ADVERTISED_Asym_Pause); 238 + phydev->pause = linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT, 239 + phydev->lp_advertising); 240 + phydev->asym_pause = linkmode_test_bit( 241 + ETHTOOL_LINK_MODE_Asym_Pause_BIT, 242 + phydev->lp_advertising); 238 243 } 239 244 } 240 245 EXPORT_SYMBOL_GPL(phy_resolve_aneg_linkmode);
+3 -5
drivers/net/phy/phy.c
··· 368 368 { 369 369 linkmode_copy(cmd->link_modes.supported, phydev->supported); 370 370 linkmode_copy(cmd->link_modes.advertising, phydev->advertising); 371 - 372 - ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.lp_advertising, 373 - phydev->lp_advertising); 371 + linkmode_copy(cmd->link_modes.lp_advertising, phydev->lp_advertising); 374 372 375 373 cmd->base.speed = phydev->speed; 376 374 cmd->base.duplex = phydev->duplex; ··· 547 549 phy_sanitize_settings(phydev); 548 550 549 551 /* Invalidate LP advertising flags */ 550 - phydev->lp_advertising = 0; 552 + linkmode_zero(phydev->lp_advertising); 551 553 552 554 err = phy_config_aneg(phydev); 553 555 if (err < 0) ··· 608 610 return 0; 609 611 610 612 linkmode_copy(adv_old, phydev->advertising); 611 - ethtool_convert_legacy_u32_to_link_mode(adv, phydev->lp_advertising); 613 + linkmode_copy(adv, phydev->lp_advertising); 612 614 linkmode_and(adv, adv, phydev->supported); 613 615 614 616 if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, adv) ||
+4 -4
drivers/net/phy/phy_device.c
··· 1702 1702 if (err) 1703 1703 return err; 1704 1704 1705 - phydev->lp_advertising = 0; 1705 + linkmode_zero(phydev->lp_advertising); 1706 1706 1707 1707 if (AUTONEG_ENABLE == phydev->autoneg) { 1708 1708 if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, ··· 1725 1725 return -ENOLINK; 1726 1726 } 1727 1727 1728 - phydev->lp_advertising = 1729 - mii_stat1000_to_ethtool_lpa_t(lpagb); 1728 + mii_stat1000_to_linkmode_lpa_t(phydev->lp_advertising, 1729 + lpagb); 1730 1730 common_adv_gb = lpagb & adv << 2; 1731 1731 } 1732 1732 ··· 1734 1734 if (lpa < 0) 1735 1735 return lpa; 1736 1736 1737 - phydev->lp_advertising |= mii_lpa_to_ethtool_lpa_t(lpa); 1737 + mii_lpa_to_linkmode_lpa_t(phydev->lp_advertising, lpa); 1738 1738 1739 1739 adv = phy_read(phydev, MII_ADVERTISE); 1740 1740 if (adv < 0)
+3 -3
drivers/net/phy/uPD60620.c
··· 47 47 return phy_state; 48 48 49 49 phydev->link = 0; 50 - phydev->lp_advertising = 0; 50 + linkmode_zero(phydev->lp_advertising); 51 51 phydev->pause = 0; 52 52 phydev->asym_pause = 0; 53 53 ··· 70 70 if (phy_state < 0) 71 71 return phy_state; 72 72 73 - phydev->lp_advertising 74 - = mii_lpa_to_ethtool_lpa_t(phy_state); 73 + mii_lpa_to_linkmode_lpa_t(phydev->lp_advertising, 74 + phy_state); 75 75 76 76 if (phydev->duplex == DUPLEX_FULL) { 77 77 if (phy_state & LPA_PAUSE_CAP)
+36
include/linux/mii.h
··· 288 288 } 289 289 290 290 /** 291 + * mii_stat1000_to_linkmode_lpa_t 292 + * @advertising: target the linkmode advertisement settings 293 + * @adv: value of the MII_STAT1000 register 294 + * 295 + * A small helper function that translates MII_STAT1000 bits, when in 296 + * 1000Base-T mode, to linkmode advertisement settings. 297 + */ 298 + static inline void mii_stat1000_to_linkmode_lpa_t(unsigned long *advertising, 299 + u32 lpa) 300 + { 301 + if (lpa & LPA_1000HALF) 302 + linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, 303 + advertising); 304 + if (lpa & LPA_1000FULL) 305 + linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, 306 + advertising); 307 + } 308 + 309 + /** 291 310 * ethtool_adv_to_mii_adv_x 292 311 * @ethadv: the ethtool advertisement settings 293 312 * ··· 401 382 linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertising); 402 383 if (adv & ADVERTISE_PAUSE_ASYM) 403 384 linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising); 385 + } 386 + 387 + /** 388 + * mii_lpa_to_linkmode_lpa_t 389 + * @adv: value of the MII_LPA register 390 + * 391 + * A small helper function that translates MII_LPA bits, when in 392 + * 1000Base-T mode, to linkmode LP advertisement settings. 393 + */ 394 + static inline void mii_lpa_to_linkmode_lpa_t(unsigned long *lp_advertising, 395 + u32 lpa) 396 + { 397 + if (lpa & LPA_LPACK) 398 + linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, 399 + lp_advertising); 400 + 401 + mii_adv_to_linkmode_adv_t(lp_advertising, lpa); 404 402 } 405 403 406 404 /**
+1 -2
include/linux/phy.h
··· 414 414 /* See ethtool.h for more info */ 415 415 __ETHTOOL_DECLARE_LINK_MODE_MASK(supported); 416 416 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising); 417 - 418 - u32 lp_advertising; 417 + __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising); 419 418 420 419 /* Energy efficient ethernet modes which should be prohibited */ 421 420 u32 eee_broken_modes;