Skip to content

Commit edc7ccb

Browse files
lunndavem330
authored andcommitted
net: phy: Add helper to convert MII ADV register to a linkmode
The phy_mii_ioctl can be used to write a value into the MII_ADVERTISE register in the PHY. Since this changes the state of the PHY, we need to make the same change to phydev->advertising. Add a helper which can convert the register value to a linkmode. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c4fabb8 commit edc7ccb

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

include/linux/mii.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,37 @@ static inline u32 mii_lpa_to_ethtool_lpa_x(u32 lpa)
303303
return result | mii_adv_to_ethtool_adv_x(lpa);
304304
}
305305

306+
/**
307+
* mii_adv_to_linkmode_adv_t
308+
* @advertising:pointer to destination link mode.
309+
* @adv: value of the MII_ADVERTISE register
310+
*
311+
* A small helper function that translates MII_ADVERTISE bits
312+
* to linkmode advertisement settings.
313+
*/
314+
static inline void mii_adv_to_linkmode_adv_t(unsigned long *advertising,
315+
u32 adv)
316+
{
317+
linkmode_zero(advertising);
318+
319+
if (adv & ADVERTISE_10HALF)
320+
linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT,
321+
advertising);
322+
if (adv & ADVERTISE_10FULL)
323+
linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT,
324+
advertising);
325+
if (adv & ADVERTISE_100HALF)
326+
linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT,
327+
advertising);
328+
if (adv & ADVERTISE_100FULL)
329+
linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT,
330+
advertising);
331+
if (adv & ADVERTISE_PAUSE_CAP)
332+
linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertising);
333+
if (adv & ADVERTISE_PAUSE_ASYM)
334+
linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising);
335+
}
336+
306337
/**
307338
* mii_advertise_flowctrl - get flow control advertisement flags
308339
* @cap: Flow control capabilities (FLOW_CTRL_RX, FLOW_CTRL_TX or both)

0 commit comments

Comments
 (0)