Skip to content

Commit 5f991f7

Browse files
lunndavem330
authored andcommitted
net: phy: Add helper for advertise to lcl value
Add a helper to convert the local advertising to an LCL capabilities, which is then used to resolve pause flow control settings. 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 edc7ccb commit 5f991f7

File tree

8 files changed

+26
-34
lines changed

8 files changed

+26
-34
lines changed

drivers/net/dsa/mt7530.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,7 @@ static void mt7530_adjust_link(struct dsa_switch *ds, int port,
658658
if (phydev->asym_pause)
659659
rmt_adv |= LPA_PAUSE_ASYM;
660660

661-
if (phydev->advertising & ADVERTISED_Pause)
662-
lcl_adv |= ADVERTISE_PAUSE_CAP;
663-
if (phydev->advertising & ADVERTISED_Asym_Pause)
664-
lcl_adv |= ADVERTISE_PAUSE_ASYM;
665-
661+
lcl_adv = ethtool_adv_to_lcl_adv_t(phydev->advertising);
666662
flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
667663

668664
if (flowctrl & FLOW_CTRL_TX)

drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,10 +1495,7 @@ static void xgbe_phy_phydev_flowctrl(struct xgbe_prv_data *pdata)
14951495
if (!phy_data->phydev)
14961496
return;
14971497

1498-
if (phy_data->phydev->advertising & ADVERTISED_Pause)
1499-
lcl_adv |= ADVERTISE_PAUSE_CAP;
1500-
if (phy_data->phydev->advertising & ADVERTISED_Asym_Pause)
1501-
lcl_adv |= ADVERTISE_PAUSE_ASYM;
1498+
lcl_adv = ethtool_adv_to_lcl_adv_t(phy_data->phydev->advertising);
15021499

15031500
if (phy_data->phydev->pause) {
15041501
XGBE_SET_LP_ADV(lks, Pause);

drivers/net/ethernet/freescale/fman/mac.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,7 @@ void fman_get_pause_cfg(struct mac_device *mac_dev, bool *rx_pause,
393393
*/
394394

395395
/* get local capabilities */
396-
lcl_adv = 0;
397-
if (phy_dev->advertising & ADVERTISED_Pause)
398-
lcl_adv |= ADVERTISE_PAUSE_CAP;
399-
if (phy_dev->advertising & ADVERTISED_Asym_Pause)
400-
lcl_adv |= ADVERTISE_PAUSE_ASYM;
396+
lcl_adv = ethtool_adv_to_lcl_adv_t(phy_dev->advertising);
401397

402398
/* get link partner capabilities */
403399
rmt_adv = 0;

drivers/net/ethernet/freescale/gianfar.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,12 +3656,7 @@ static u32 gfar_get_flowctrl_cfg(struct gfar_private *priv)
36563656
if (phydev->asym_pause)
36573657
rmt_adv |= LPA_PAUSE_ASYM;
36583658

3659-
lcl_adv = 0;
3660-
if (phydev->advertising & ADVERTISED_Pause)
3661-
lcl_adv |= ADVERTISE_PAUSE_CAP;
3662-
if (phydev->advertising & ADVERTISED_Asym_Pause)
3663-
lcl_adv |= ADVERTISE_PAUSE_ASYM;
3664-
3659+
lcl_adv = ethtool_adv_to_lcl_adv_t(phydev->advertising);
36653660
flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
36663661
if (flowctrl & FLOW_CTRL_TX)
36673662
val |= MACCFG1_TX_FLOW;

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5006,11 +5006,7 @@ int hclge_cfg_flowctrl(struct hclge_dev *hdev)
50065006
if (!phydev->link || !phydev->autoneg)
50075007
return 0;
50085008

5009-
if (phydev->advertising & ADVERTISED_Pause)
5010-
local_advertising = ADVERTISE_PAUSE_CAP;
5011-
5012-
if (phydev->advertising & ADVERTISED_Asym_Pause)
5013-
local_advertising |= ADVERTISE_PAUSE_ASYM;
5009+
local_advertising = ethtool_adv_to_lcl_adv_t(phydev->advertising);
50145010

50155011
if (phydev->pause)
50165012
remote_advertising = LPA_PAUSE_CAP;

drivers/net/ethernet/mediatek/mtk_eth_soc.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,7 @@ static void mtk_phy_link_adjust(struct net_device *dev)
243243
if (dev->phydev->asym_pause)
244244
rmt_adv |= LPA_PAUSE_ASYM;
245245

246-
if (dev->phydev->advertising & ADVERTISED_Pause)
247-
lcl_adv |= ADVERTISE_PAUSE_CAP;
248-
if (dev->phydev->advertising & ADVERTISED_Asym_Pause)
249-
lcl_adv |= ADVERTISE_PAUSE_ASYM;
250-
246+
lcl_adv = ethtool_adv_to_lcl_adv_t(dev->phydev->advertising);
251247
flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
252248

253249
if (flowctrl & FLOW_CTRL_TX)

drivers/net/ethernet/socionext/sni_ave.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,11 +1116,8 @@ static void ave_phy_adjust_link(struct net_device *ndev)
11161116
rmt_adv |= LPA_PAUSE_CAP;
11171117
if (phydev->asym_pause)
11181118
rmt_adv |= LPA_PAUSE_ASYM;
1119-
if (phydev->advertising & ADVERTISED_Pause)
1120-
lcl_adv |= ADVERTISE_PAUSE_CAP;
1121-
if (phydev->advertising & ADVERTISED_Asym_Pause)
1122-
lcl_adv |= ADVERTISE_PAUSE_ASYM;
11231119

1120+
lcl_adv = ethtool_adv_to_lcl_adv_t(phydev->advertising);
11241121
cap = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
11251122
if (cap & FLOW_CTRL_TX)
11261123
txcr |= AVE_TXCR_FLOCTR;

include/linux/mii.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,25 @@ static inline void mii_adv_to_linkmode_adv_t(unsigned long *advertising,
334334
linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising);
335335
}
336336

337+
/**
338+
* ethtool_adv_to_lcl_adv_t
339+
* @advertising:pointer to ethtool advertising
340+
*
341+
* A small helper function that translates ethtool advertising to LVL
342+
* pause capabilities.
343+
*/
344+
static inline u32 ethtool_adv_to_lcl_adv_t(u32 advertising)
345+
{
346+
u32 lcl_adv = 0;
347+
348+
if (advertising & ADVERTISED_Pause)
349+
lcl_adv |= ADVERTISE_PAUSE_CAP;
350+
if (advertising & ADVERTISED_Asym_Pause)
351+
lcl_adv |= ADVERTISE_PAUSE_ASYM;
352+
353+
return lcl_adv;
354+
}
355+
337356
/**
338357
* mii_advertise_flowctrl - get flow control advertisement flags
339358
* @cap: Flow control capabilities (FLOW_CTRL_RX, FLOW_CTRL_TX or both)

0 commit comments

Comments
 (0)