Skip to content

Commit c0ec3c2

Browse files
lunndavem330
authored andcommitted
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3c1bcc8 commit c0ec3c2

File tree

10 files changed

+72
-41
lines changed

10 files changed

+72
-41
lines changed

drivers/net/phy/lxt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static int lxt973a2_read_status(struct phy_device *phydev)
177177
*/
178178
} while (lpa == adv && retry--);
179179

180-
phydev->lp_advertising = mii_lpa_to_ethtool_lpa_t(lpa);
180+
mii_lpa_to_linkmode_lpa_t(phydev->lp_advertising, lpa);
181181

182182
lpa &= adv;
183183

@@ -218,7 +218,7 @@ static int lxt973a2_read_status(struct phy_device *phydev)
218218
phydev->speed = SPEED_10;
219219

220220
phydev->pause = phydev->asym_pause = 0;
221-
phydev->lp_advertising = 0;
221+
linkmode_zero(phydev->lp_advertising);
222222
}
223223

224224
return 0;

drivers/net/phy/marvell.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,22 +1049,21 @@ static int m88e1145_config_init(struct phy_device *phydev)
10491049
}
10501050

10511051
/**
1052-
* fiber_lpa_to_ethtool_lpa_t
1052+
* fiber_lpa_to_linkmode_lpa_t
1053+
* @advertising: the linkmode advertisement settings
10531054
* @lpa: value of the MII_LPA register for fiber link
10541055
*
10551056
* A small helper function that translates MII_LPA
1056-
* bits to ethtool LP advertisement settings.
1057+
* bits to linkmode LP advertisement settings.
10571058
*/
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)
10591060
{
1060-
u32 result = 0;
1061-
10621061
if (lpa & LPA_FIBER_1000HALF)
1063-
result |= ADVERTISED_1000baseT_Half;
1062+
linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
1063+
advertising);
10641064
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);
10681067
}
10691068

10701069
/**
@@ -1140,17 +1139,16 @@ static int marvell_read_status_page_an(struct phy_device *phydev,
11401139
}
11411140

11421141
if (!fiber) {
1143-
phydev->lp_advertising =
1144-
mii_stat1000_to_ethtool_lpa_t(lpagb) |
1145-
mii_lpa_to_ethtool_lpa_t(lpa);
1142+
mii_lpa_to_linkmode_lpa_t(phydev->lp_advertising, lpa);
1143+
mii_stat1000_to_linkmode_lpa_t(phydev->lp_advertising, lpagb);
11461144

11471145
if (phydev->duplex == DUPLEX_FULL) {
11481146
phydev->pause = lpa & LPA_PAUSE_CAP ? 1 : 0;
11491147
phydev->asym_pause = lpa & LPA_PAUSE_ASYM ? 1 : 0;
11501148
}
11511149
} else {
11521150
/* The fiber link is only 1000M capable */
1153-
phydev->lp_advertising = fiber_lpa_to_ethtool_lpa_t(lpa);
1151+
fiber_lpa_to_linkmode_lpa_t(phydev->lp_advertising, lpa);
11541152

11551153
if (phydev->duplex == DUPLEX_FULL) {
11561154
if (!(lpa & LPA_PAUSE_FIBER)) {
@@ -1189,7 +1187,7 @@ static int marvell_read_status_page_fixed(struct phy_device *phydev)
11891187

11901188
phydev->pause = 0;
11911189
phydev->asym_pause = 0;
1192-
phydev->lp_advertising = 0;
1190+
linkmode_zero(phydev->lp_advertising);
11931191

11941192
return 0;
11951193
}

drivers/net/phy/marvell10g.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ static int mv3310_read_status(struct phy_device *phydev)
457457

458458
phydev->speed = SPEED_UNKNOWN;
459459
phydev->duplex = DUPLEX_UNKNOWN;
460-
phydev->lp_advertising = 0;
460+
linkmode_zero(phydev->lp_advertising);
461461
phydev->link = 0;
462462
phydev->pause = 0;
463463
phydev->asym_pause = 0;
@@ -490,7 +490,7 @@ static int mv3310_read_status(struct phy_device *phydev)
490490
if (val < 0)
491491
return val;
492492

493-
phydev->lp_advertising |= mii_stat1000_to_ethtool_lpa_t(val);
493+
mii_stat1000_to_linkmode_lpa_t(phydev->lp_advertising, val);
494494

495495
if (phydev->autoneg == AUTONEG_ENABLE)
496496
phy_resolve_aneg_linkmode(phydev);

drivers/net/phy/phy-c45.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ int genphy_c45_read_lpa(struct phy_device *phydev)
181181
if (val < 0)
182182
return val;
183183

184-
phydev->lp_advertising = mii_lpa_to_ethtool_lpa_t(val);
184+
mii_lpa_to_linkmode_lpa_t(phydev->lp_advertising, val);
185185
phydev->pause = val & LPA_PAUSE_CAP ? 1 : 0;
186186
phydev->asym_pause = val & LPA_PAUSE_ASYM ? 1 : 0;
187187

@@ -191,7 +191,8 @@ int genphy_c45_read_lpa(struct phy_device *phydev)
191191
return val;
192192

193193
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);
195196

196197
return 0;
197198
}

drivers/net/phy/phy-core.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,8 @@ size_t phy_speeds(unsigned int *speeds, size_t size,
199199
void phy_resolve_aneg_linkmode(struct phy_device *phydev)
200200
{
201201
__ETHTOOL_DECLARE_LINK_MODE_MASK(common);
202-
__ETHTOOL_DECLARE_LINK_MODE_MASK(lp);
203202

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);
207204

208205
if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT, common)) {
209206
phydev->speed = SPEED_10000;
@@ -235,9 +232,11 @@ void phy_resolve_aneg_linkmode(struct phy_device *phydev)
235232
}
236233

237234
if (phydev->duplex == DUPLEX_FULL) {
238-
phydev->pause = !!(phydev->lp_advertising & ADVERTISED_Pause);
239-
phydev->asym_pause = !!(phydev->lp_advertising &
240-
ADVERTISED_Asym_Pause);
235+
phydev->pause = linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT,
236+
phydev->lp_advertising);
237+
phydev->asym_pause = linkmode_test_bit(
238+
ETHTOOL_LINK_MODE_Asym_Pause_BIT,
239+
phydev->lp_advertising);
241240
}
242241
}
243242
EXPORT_SYMBOL_GPL(phy_resolve_aneg_linkmode);

drivers/net/phy/phy.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,7 @@ void phy_ethtool_ksettings_get(struct phy_device *phydev,
368368
{
369369
linkmode_copy(cmd->link_modes.supported, phydev->supported);
370370
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);
374372

375373
cmd->base.speed = phydev->speed;
376374
cmd->base.duplex = phydev->duplex;
@@ -549,7 +547,7 @@ int phy_start_aneg(struct phy_device *phydev)
549547
phy_sanitize_settings(phydev);
550548

551549
/* Invalidate LP advertising flags */
552-
phydev->lp_advertising = 0;
550+
linkmode_zero(phydev->lp_advertising);
553551

554552
err = phy_config_aneg(phydev);
555553
if (err < 0)
@@ -610,7 +608,7 @@ int phy_speed_down(struct phy_device *phydev, bool sync)
610608
return 0;
611609

612610
linkmode_copy(adv_old, phydev->advertising);
613-
ethtool_convert_legacy_u32_to_link_mode(adv, phydev->lp_advertising);
611+
linkmode_copy(adv, phydev->lp_advertising);
614612
linkmode_and(adv, adv, phydev->supported);
615613

616614
if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, adv) ||

drivers/net/phy/phy_device.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ int genphy_read_status(struct phy_device *phydev)
17021702
if (err)
17031703
return err;
17041704

1705-
phydev->lp_advertising = 0;
1705+
linkmode_zero(phydev->lp_advertising);
17061706

17071707
if (AUTONEG_ENABLE == phydev->autoneg) {
17081708
if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
@@ -1725,16 +1725,16 @@ int genphy_read_status(struct phy_device *phydev)
17251725
return -ENOLINK;
17261726
}
17271727

1728-
phydev->lp_advertising =
1729-
mii_stat1000_to_ethtool_lpa_t(lpagb);
1728+
mii_stat1000_to_linkmode_lpa_t(phydev->lp_advertising,
1729+
lpagb);
17301730
common_adv_gb = lpagb & adv << 2;
17311731
}
17321732

17331733
lpa = phy_read(phydev, MII_LPA);
17341734
if (lpa < 0)
17351735
return lpa;
17361736

1737-
phydev->lp_advertising |= mii_lpa_to_ethtool_lpa_t(lpa);
1737+
mii_lpa_to_linkmode_lpa_t(phydev->lp_advertising, lpa);
17381738

17391739
adv = phy_read(phydev, MII_ADVERTISE);
17401740
if (adv < 0)

drivers/net/phy/uPD60620.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static int upd60620_read_status(struct phy_device *phydev)
4747
return phy_state;
4848

4949
phydev->link = 0;
50-
phydev->lp_advertising = 0;
50+
linkmode_zero(phydev->lp_advertising);
5151
phydev->pause = 0;
5252
phydev->asym_pause = 0;
5353

@@ -70,8 +70,8 @@ static int upd60620_read_status(struct phy_device *phydev)
7070
if (phy_state < 0)
7171
return phy_state;
7272

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);
7575

7676
if (phydev->duplex == DUPLEX_FULL) {
7777
if (phy_state & LPA_PAUSE_CAP)

include/linux/mii.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,25 @@ static inline u32 mii_stat1000_to_ethtool_lpa_t(u32 lpa)
287287
return result;
288288
}
289289

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+
290309
/**
291310
* ethtool_adv_to_mii_adv_x
292311
* @ethadv: the ethtool advertisement settings
@@ -384,6 +403,23 @@ static inline void mii_adv_to_linkmode_adv_t(unsigned long *advertising,
384403
linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising);
385404
}
386405

406+
/**
407+
* mii_lpa_to_linkmode_lpa_t
408+
* @adv: value of the MII_LPA register
409+
*
410+
* A small helper function that translates MII_LPA bits, when in
411+
* 1000Base-T mode, to linkmode LP advertisement settings.
412+
*/
413+
static inline void mii_lpa_to_linkmode_lpa_t(unsigned long *lp_advertising,
414+
u32 lpa)
415+
{
416+
if (lpa & LPA_LPACK)
417+
linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
418+
lp_advertising);
419+
420+
mii_adv_to_linkmode_adv_t(lp_advertising, lpa);
421+
}
422+
387423
/**
388424
* linkmode_adv_to_lcl_adv_t
389425
* @advertising:pointer to linkmode advertising

include/linux/phy.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,7 @@ struct phy_device {
414414
/* See ethtool.h for more info */
415415
__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
416416
__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
417-
418-
u32 lp_advertising;
417+
__ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
419418

420419
/* Energy efficient ethernet modes which should be prohibited */
421420
u32 eee_broken_modes;

0 commit comments

Comments
 (0)