Skip to content

Commit 41124fa

Browse files
lunndavem330
authored andcommitted
net: ethernet: Add helper to remove a supported link mode
Some MAC hardware cannot support a subset of link modes. e.g. often 1Gbps Full duplex is supported, but Half duplex is not. Add a helper to remove such a link mode. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 04b7d41 commit 41124fa

File tree

9 files changed

+38
-14
lines changed

9 files changed

+38
-14
lines changed

drivers/net/ethernet/apm/xgene/xgene_enet_hw.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,9 @@ int xgene_enet_phy_connect(struct net_device *ndev)
895895
}
896896

897897
pdata->phy_speed = SPEED_UNKNOWN;
898-
phy_dev->supported &= ~SUPPORTED_10baseT_Half &
899-
~SUPPORTED_100baseT_Half &
900-
~SUPPORTED_1000baseT_Half;
898+
phy_remove_link_mode(phy_dev, ETHTOOL_LINK_MODE_10baseT_Half_BIT);
899+
phy_remove_link_mode(phy_dev, ETHTOOL_LINK_MODE_100baseT_Half_BIT);
900+
phy_remove_link_mode(phy_dev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
901901
phy_dev->supported |= SUPPORTED_Pause |
902902
SUPPORTED_Asym_Pause;
903903
phy_dev->advertising = phy_dev->supported;

drivers/net/ethernet/cadence/macb_main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,8 @@ static int macb_mii_probe(struct net_device *dev)
549549
phy_set_max_speed(phydev, SPEED_100);
550550

551551
if (bp->caps & MACB_CAPS_NO_GIGABIT_HALF)
552-
phydev->supported &= ~SUPPORTED_1000baseT_Half;
553-
554-
phydev->advertising = phydev->supported;
552+
phy_remove_link_mode(phydev,
553+
ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
555554

556555
bp->link = 0;
557556
bp->speed = 0;

drivers/net/ethernet/freescale/fec_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1947,7 +1947,8 @@ static int fec_enet_mii_probe(struct net_device *ndev)
19471947
/* mask with MAC supported features */
19481948
if (fep->quirks & FEC_QUIRK_HAS_GBIT) {
19491949
phy_set_max_speed(phy_dev, 1000);
1950-
phy_dev->supported &= ~SUPPORTED_1000baseT_Half;
1950+
phy_remove_link_mode(phy_dev,
1951+
ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
19511952
#if !defined(CONFIG_M5272)
19521953
phy_dev->supported |= SUPPORTED_Pause;
19531954
#endif

drivers/net/ethernet/microchip/lan743x_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ static int lan743x_phy_open(struct lan743x_adapter *adapter)
10131013
goto return_error;
10141014

10151015
/* MAC doesn't support 1000T Half */
1016-
phydev->supported &= ~SUPPORTED_1000baseT_Half;
1016+
phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
10171017

10181018
/* support both flow controls */
10191019
phy->fc_request_control = (FLOW_CTRL_RX | FLOW_CTRL_TX);

drivers/net/ethernet/renesas/ravb_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,8 @@ static int ravb_phy_init(struct net_device *ndev)
10741074
}
10751075

10761076
/* 10BASE is not supported */
1077-
phydev->supported &= ~PHY_10BT_FEATURES;
1077+
phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_10baseT_Half_BIT);
1078+
phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_10baseT_Full_BIT);
10781079

10791080
phy_attached_info(phydev);
10801081

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -993,10 +993,14 @@ static int stmmac_init_phy(struct net_device *dev)
993993
* Half-duplex mode not supported with multiqueue
994994
* half-duplex can only works with single queue
995995
*/
996-
if (tx_cnt > 1)
997-
phydev->supported &= ~(SUPPORTED_1000baseT_Half |
998-
SUPPORTED_100baseT_Half |
999-
SUPPORTED_10baseT_Half);
996+
if (tx_cnt > 1) {
997+
phy_remove_link_mode(phydev,
998+
ETHTOOL_LINK_MODE_10baseT_Half_BIT);
999+
phy_remove_link_mode(phydev,
1000+
ETHTOOL_LINK_MODE_100baseT_Half_BIT);
1001+
phy_remove_link_mode(phydev,
1002+
ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
1003+
}
10001004

10011005
/*
10021006
* Broken HW is sometimes missing the pull-up resistor on the

drivers/net/phy/phy_device.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,24 @@ int phy_set_max_speed(struct phy_device *phydev, u32 max_speed)
17651765
}
17661766
EXPORT_SYMBOL(phy_set_max_speed);
17671767

1768+
/**
1769+
* phy_remove_link_mode - Remove a supported link mode
1770+
* @phydev: phy_device structure to remove link mode from
1771+
* @link_mode: Link mode to be removed
1772+
*
1773+
* Description: Some MACs don't support all link modes which the PHY
1774+
* does. e.g. a 1G MAC often does not support 1000Half. Add a helper
1775+
* to remove a link mode.
1776+
*/
1777+
void phy_remove_link_mode(struct phy_device *phydev, u32 link_mode)
1778+
{
1779+
WARN_ON(link_mode > 31);
1780+
1781+
phydev->supported &= ~BIT(link_mode);
1782+
phydev->advertising = phydev->supported;
1783+
}
1784+
EXPORT_SYMBOL(phy_remove_link_mode);
1785+
17681786
static void of_set_phy_supported(struct phy_device *phydev)
17691787
{
17701788
struct device_node *node = phydev->mdio.dev.of_node;

drivers/net/usb/lan78xx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2166,7 +2166,7 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
21662166
}
21672167

21682168
/* MAC doesn't support 1000T Half */
2169-
phydev->supported &= ~SUPPORTED_1000baseT_Half;
2169+
phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
21702170

21712171
/* support both flow controls */
21722172
dev->fc_request_control = (FLOW_CTRL_RX | FLOW_CTRL_TX);

include/linux/phy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,7 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd);
10491049
int phy_start_interrupts(struct phy_device *phydev);
10501050
void phy_print_status(struct phy_device *phydev);
10511051
int phy_set_max_speed(struct phy_device *phydev, u32 max_speed);
1052+
void phy_remove_link_mode(struct phy_device *phydev, u32 link_mode);
10521053

10531054
int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask,
10541055
int (*run)(struct phy_device *));

0 commit comments

Comments
 (0)