Skip to content

Commit

Permalink
Merge branch 'Preparing-for-phylib-linkmodes'
Browse files Browse the repository at this point in the history
Andrew Lunn says:

====================
Preparing for phylib linkmodes

phylib currently makes us of a u32 bitmap for advertising, supported,
and link partner capabilities. For a long time, this has been
sufficient, for devices up to 1Gbps. With more MAC/PHY combinations
now supporting speeds greater than 1Gbps, we have run out of
bits. There is the need to replace this u32 with an
__ETHTOOL_DECLARE_LINK_MODE_MASK, which makes use of linux's generic
bitmaps.

This patchset does some of the work preparing for this change. A few
cleanups are applied to PHY drivers. Some MAC drivers directly access
members of phydev which are going to change type. These patches adds
some helpers and swaps MAC drivers to use them, mostly dealing with
Pause configuration.

v3:
Reviewed-by: Florian Fainelli <[email protected]>
Add missing at in commit message
Change Subject of patch 5
Fix return in from phy_set_asym_pause
Fix kerneldoc in phy_set_pause

v2:
Fixup bad indentation in tg3.c
Rename phy_support_pause() to phy_support_sym_pause()
Also trigger autoneg if the advertising settings have changed.
Rename phy_set_pause() to phy_set_sym_pause()
Use the bcm63xx_enet.c logic, not fec_main.c for validating pause
====================

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Sep 13, 2018
2 parents eca09be + 22b7d29 commit 1566534
Show file tree
Hide file tree
Showing 47 changed files with 259 additions and 344 deletions.
4 changes: 1 addition & 3 deletions drivers/net/ethernet/8390/ax88796.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,7 @@ static int ax_mii_probe(struct net_device *dev)
return ret;
}

/* mask with MAC supported features */
phy_dev->supported &= PHY_BASIC_FEATURES;
phy_dev->advertising = phy_dev->supported;
phy_set_max_speed(phy_dev, SPEED_100);

netdev_info(dev, "PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
phy_dev->drv->name, phydev_name(phy_dev), phy_dev->irq);
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/ethernet/aeroflex/greth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1279,9 +1279,9 @@ static int greth_mdio_probe(struct net_device *dev)
}

if (greth->gbit_mac)
phy->supported &= PHY_GBIT_FEATURES;
phy_set_max_speed(phy, SPEED_1000);
else
phy->supported &= PHY_BASIC_FEATURES;
phy_set_max_speed(phy, SPEED_100);

phy->advertising = phy->supported;

Expand Down
12 changes: 2 additions & 10 deletions drivers/net/ethernet/agere/et131x.c
Original file line number Diff line number Diff line change
Expand Up @@ -3258,19 +3258,11 @@ static int et131x_mii_probe(struct net_device *netdev)
return PTR_ERR(phydev);
}

phydev->supported &= (SUPPORTED_10baseT_Half |
SUPPORTED_10baseT_Full |
SUPPORTED_100baseT_Half |
SUPPORTED_100baseT_Full |
SUPPORTED_Autoneg |
SUPPORTED_MII |
SUPPORTED_TP);
phy_set_max_speed(phydev, SPEED_100);

if (adapter->pdev->device != ET131X_PCI_DEVICE_ID_FAST)
phydev->supported |= SUPPORTED_1000baseT_Half |
SUPPORTED_1000baseT_Full;
phy_set_max_speed(phydev, SPEED_1000);

phydev->advertising = phydev->supported;
phydev->autoneg = AUTONEG_ENABLE;

phy_attached_info(phydev);
Expand Down
3 changes: 1 addition & 2 deletions drivers/net/ethernet/allwinner/sun4i-emac.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ static int emac_mdio_probe(struct net_device *dev)
}

/* mask with MAC supported features */
phydev->supported &= PHY_BASIC_FEATURES;
phydev->advertising = phydev->supported;
phy_set_max_speed(phydev, SPEED_100);

db->link = 0;
db->speed = 0;
Expand Down
5 changes: 1 addition & 4 deletions drivers/net/ethernet/altera/altera_tse_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,13 +835,10 @@ static int init_phy(struct net_device *dev)
}

/* Stop Advertising 1000BASE Capability if interface is not GMII
* Note: Checkpatch throws CHECKs for the camel case defines below,
* it's ok to ignore.
*/
if ((priv->phy_iface == PHY_INTERFACE_MODE_MII) ||
(priv->phy_iface == PHY_INTERFACE_MODE_RMII))
phydev->advertising &= ~(SUPPORTED_1000baseT_Half |
SUPPORTED_1000baseT_Full);
phy_set_max_speed(phydev, SPEED_100);

/* Broken HW is sometimes missing the pull-up resistor on the
* MDIO line, which results in reads to non-existent devices returning
Expand Down
12 changes: 1 addition & 11 deletions drivers/net/ethernet/amd/au1000_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,17 +564,7 @@ static int au1000_mii_probe(struct net_device *dev)
return PTR_ERR(phydev);
}

/* mask with MAC supported features */
phydev->supported &= (SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
| SUPPORTED_100baseT_Half
| SUPPORTED_100baseT_Full
| SUPPORTED_Autoneg
/* | SUPPORTED_Pause | SUPPORTED_Asym_Pause */
| SUPPORTED_MII
| SUPPORTED_TP);

phydev->advertising = phydev->supported;
phy_set_max_speed(phydev, SPEED_100);

aup->old_link = 0;
aup->old_speed = 0;
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,8 @@ static bool xgbe_phy_finisar_phy_quirks(struct xgbe_prv_data *pdata)
phy_write(phy_data->phydev, 0x00, 0x9140);

phy_data->phydev->supported = PHY_GBIT_FEATURES;
phy_data->phydev->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
phy_data->phydev->advertising = phy_data->phydev->supported;
phy_support_asym_pause(phy_data->phydev);

netif_dbg(pdata, drv, pdata->netdev,
"Finisar PHY quirk in place\n");
Expand Down Expand Up @@ -951,8 +951,8 @@ static bool xgbe_phy_belfuse_phy_quirks(struct xgbe_prv_data *pdata)
phy_write(phy_data->phydev, 0x00, reg & ~0x00800);

phy_data->phydev->supported = PHY_GBIT_FEATURES;
phy_data->phydev->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
phy_data->phydev->advertising = phy_data->phydev->supported;
phy_support_asym_pause(phy_data->phydev);

netif_dbg(pdata, drv, pdata->netdev,
"BelFuse PHY quirk in place\n");
Expand Down
30 changes: 5 additions & 25 deletions drivers/net/ethernet/apm/xgene/xgene_enet_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,45 +306,25 @@ static int xgene_set_pauseparam(struct net_device *ndev,
{
struct xgene_enet_pdata *pdata = netdev_priv(ndev);
struct phy_device *phydev = ndev->phydev;
u32 oldadv, newadv;

if (phy_interface_mode_is_rgmii(pdata->phy_mode) ||
pdata->phy_mode == PHY_INTERFACE_MODE_SGMII) {
if (!phydev)
return -EINVAL;

if (!(phydev->supported & SUPPORTED_Pause) ||
(!(phydev->supported & SUPPORTED_Asym_Pause) &&
pp->rx_pause != pp->tx_pause))
if (!phy_validate_pause(phydev, pp))
return -EINVAL;

pdata->pause_autoneg = pp->autoneg;
pdata->tx_pause = pp->tx_pause;
pdata->rx_pause = pp->rx_pause;

oldadv = phydev->advertising;
newadv = oldadv & ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
phy_set_asym_pause(phydev, pp->rx_pause, pp->tx_pause);

if (pp->rx_pause)
newadv |= ADVERTISED_Pause | ADVERTISED_Asym_Pause;

if (pp->tx_pause)
newadv ^= ADVERTISED_Asym_Pause;

if (oldadv ^ newadv) {
phydev->advertising = newadv;

if (phydev->autoneg)
return phy_start_aneg(phydev);

if (!pp->autoneg) {
pdata->mac_ops->flowctl_tx(pdata,
pdata->tx_pause);
pdata->mac_ops->flowctl_rx(pdata,
pdata->rx_pause);
}
if (!pp->autoneg) {
pdata->mac_ops->flowctl_tx(pdata, pdata->tx_pause);
pdata->mac_ops->flowctl_rx(pdata, pdata->rx_pause);
}

} else {
if (pp->autoneg)
return -EINVAL;
Expand Down
10 changes: 4 additions & 6 deletions drivers/net/ethernet/apm/xgene/xgene_enet_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,12 +895,10 @@ int xgene_enet_phy_connect(struct net_device *ndev)
}

pdata->phy_speed = SPEED_UNKNOWN;
phy_dev->supported &= ~SUPPORTED_10baseT_Half &
~SUPPORTED_100baseT_Half &
~SUPPORTED_1000baseT_Half;
phy_dev->supported |= SUPPORTED_Pause |
SUPPORTED_Asym_Pause;
phy_dev->advertising = phy_dev->supported;
phy_remove_link_mode(phy_dev, ETHTOOL_LINK_MODE_10baseT_Half_BIT);
phy_remove_link_mode(phy_dev, ETHTOOL_LINK_MODE_100baseT_Half_BIT);
phy_remove_link_mode(phy_dev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
phy_support_asym_pause(phy_dev);

return 0;
}
Expand Down
9 changes: 1 addition & 8 deletions drivers/net/ethernet/aurora/nb8800.c
Original file line number Diff line number Diff line change
Expand Up @@ -935,18 +935,11 @@ static void nb8800_pause_adv(struct net_device *dev)
{
struct nb8800_priv *priv = netdev_priv(dev);
struct phy_device *phydev = dev->phydev;
u32 adv = 0;

if (!phydev)
return;

if (priv->pause_rx)
adv |= ADVERTISED_Pause | ADVERTISED_Asym_Pause;
if (priv->pause_tx)
adv ^= ADVERTISED_Asym_Pause;

phydev->supported |= adv;
phydev->advertising |= adv;
phy_set_asym_pause(phydev, priv->pause_rx, priv->pause_tx);
}

static int nb8800_open(struct net_device *dev)
Expand Down
17 changes: 4 additions & 13 deletions drivers/net/ethernet/broadcom/bcm63xx_enet.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,19 +890,10 @@ static int bcm_enet_open(struct net_device *dev)
}

/* mask with MAC supported features */
phydev->supported &= (SUPPORTED_10baseT_Half |
SUPPORTED_10baseT_Full |
SUPPORTED_100baseT_Half |
SUPPORTED_100baseT_Full |
SUPPORTED_Autoneg |
SUPPORTED_Pause |
SUPPORTED_MII);
phydev->advertising = phydev->supported;

if (priv->pause_auto && priv->pause_rx && priv->pause_tx)
phydev->advertising |= SUPPORTED_Pause;
else
phydev->advertising &= ~SUPPORTED_Pause;
phy_support_sym_pause(phydev);
phy_set_max_speed(phydev, SPEED_100);
phy_set_sym_pause(phydev, priv->pause_rx, priv->pause_rx,
priv->pause_auto);

phy_attached_info(phydev);

Expand Down
9 changes: 4 additions & 5 deletions drivers/net/ethernet/broadcom/genet/bcmmii.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ int bcmgenet_mii_config(struct net_device *dev, bool init)

case PHY_INTERFACE_MODE_MII:
phy_name = "external MII";
phydev->supported &= PHY_BASIC_FEATURES;
phy_set_max_speed(phydev, SPEED_100);
bcmgenet_sys_writel(priv,
PORT_MODE_EXT_EPHY, SYS_PORT_CTRL);
break;
Expand All @@ -226,11 +226,10 @@ int bcmgenet_mii_config(struct net_device *dev, bool init)
* capabilities, use that knowledge to also configure the
* Reverse MII interface correctly.
*/
if ((dev->phydev->supported & PHY_BASIC_FEATURES) ==
PHY_BASIC_FEATURES)
port_ctrl = PORT_MODE_EXT_RVMII_25;
else
if (dev->phydev->supported & PHY_1000BT_FEATURES)
port_ctrl = PORT_MODE_EXT_RVMII_50;
else
port_ctrl = PORT_MODE_EXT_RVMII_25;
bcmgenet_sys_writel(priv, port_ctrl, SYS_PORT_CTRL);
break;

Expand Down
14 changes: 2 additions & 12 deletions drivers/net/ethernet/broadcom/sb1250-mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -2357,21 +2357,11 @@ static int sbmac_mii_probe(struct net_device *dev)
}

/* Remove any features not supported by the controller */
phy_dev->supported &= SUPPORTED_10baseT_Half |
SUPPORTED_10baseT_Full |
SUPPORTED_100baseT_Half |
SUPPORTED_100baseT_Full |
SUPPORTED_1000baseT_Half |
SUPPORTED_1000baseT_Full |
SUPPORTED_Autoneg |
SUPPORTED_MII |
SUPPORTED_Pause |
SUPPORTED_Asym_Pause;
phy_set_max_speed(phy_dev, SPEED_1000);
phy_support_asym_pause(phy_dev);

phy_attached_info(phy_dev);

phy_dev->advertising = phy_dev->supported;

sc->phy_dev = phy_dev;

return 0;
Expand Down
59 changes: 17 additions & 42 deletions drivers/net/ethernet/broadcom/tg3.c
Original file line number Diff line number Diff line change
Expand Up @@ -2122,16 +2122,14 @@ static int tg3_phy_init(struct tg3 *tp)
case PHY_INTERFACE_MODE_GMII:
case PHY_INTERFACE_MODE_RGMII:
if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) {
phydev->supported &= (PHY_GBIT_FEATURES |
SUPPORTED_Pause |
SUPPORTED_Asym_Pause);
phy_set_max_speed(phydev, SPEED_1000);
phy_support_asym_pause(phydev);
break;
}
/* fallthru */
case PHY_INTERFACE_MODE_MII:
phydev->supported &= (PHY_BASIC_FEATURES |
SUPPORTED_Pause |
SUPPORTED_Asym_Pause);
phy_set_max_speed(phydev, SPEED_100);
phy_support_asym_pause(phydev);
break;
default:
phy_disconnect(mdiobus_get_phy(tp->mdio_bus, tp->phy_addr));
Expand All @@ -2140,8 +2138,6 @@ static int tg3_phy_init(struct tg3 *tp)

tp->phy_flags |= TG3_PHYFLG_IS_CONNECTED;

phydev->advertising = phydev->supported;

phy_attached_info(phydev);

return 0;
Expand Down Expand Up @@ -12496,65 +12492,44 @@ static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam
tg3_warn_mgmt_link_flap(tp);

if (tg3_flag(tp, USE_PHYLIB)) {
u32 newadv;
struct phy_device *phydev;

phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr);

if (!(phydev->supported & SUPPORTED_Pause) ||
(!(phydev->supported & SUPPORTED_Asym_Pause) &&
(epause->rx_pause != epause->tx_pause)))
if (!phy_validate_pause(phydev, epause))
return -EINVAL;

tp->link_config.flowctrl = 0;
phy_set_asym_pause(phydev, epause->rx_pause, epause->tx_pause);
if (epause->rx_pause) {
tp->link_config.flowctrl |= FLOW_CTRL_RX;

if (epause->tx_pause) {
tp->link_config.flowctrl |= FLOW_CTRL_TX;
newadv = ADVERTISED_Pause;
} else
newadv = ADVERTISED_Pause |
ADVERTISED_Asym_Pause;
}
} else if (epause->tx_pause) {
tp->link_config.flowctrl |= FLOW_CTRL_TX;
newadv = ADVERTISED_Asym_Pause;
} else
newadv = 0;
}

if (epause->autoneg)
tg3_flag_set(tp, PAUSE_AUTONEG);
else
tg3_flag_clear(tp, PAUSE_AUTONEG);

if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) {
u32 oldadv = phydev->advertising &
(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
if (oldadv != newadv) {
phydev->advertising &=
~(ADVERTISED_Pause |
ADVERTISED_Asym_Pause);
phydev->advertising |= newadv;
if (phydev->autoneg) {
/*
* Always renegotiate the link to
* inform our link partner of our
* flow control settings, even if the
* flow control is forced. Let
* tg3_adjust_link() do the final
* flow control setup.
*/
return phy_start_aneg(phydev);
}
if (phydev->autoneg) {
/* phy_set_asym_pause() will
* renegotiate the link to inform our
* link partner of our flow control
* settings, even if the flow control
* is forced. Let tg3_adjust_link()
* do the final flow control setup.
*/
return 0;
}

if (!epause->autoneg)
tg3_setup_flow_control(tp, 0, 0);
} else {
tp->link_config.advertising &=
~(ADVERTISED_Pause |
ADVERTISED_Asym_Pause);
tp->link_config.advertising |= newadv;
}
} else {
int irq_sync = 0;
Expand Down
9 changes: 4 additions & 5 deletions drivers/net/ethernet/cadence/macb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,14 +544,13 @@ static int macb_mii_probe(struct net_device *dev)

/* mask with MAC supported features */
if (macb_is_gem(bp) && bp->caps & MACB_CAPS_GIGABIT_MODE_AVAILABLE)
phydev->supported &= PHY_GBIT_FEATURES;
phy_set_max_speed(phydev, SPEED_1000);
else
phydev->supported &= PHY_BASIC_FEATURES;
phy_set_max_speed(phydev, SPEED_100);

if (bp->caps & MACB_CAPS_NO_GIGABIT_HALF)
phydev->supported &= ~SUPPORTED_1000baseT_Half;

phydev->advertising = phydev->supported;
phy_remove_link_mode(phydev,
ETHTOOL_LINK_MODE_1000baseT_Half_BIT);

bp->link = 0;
bp->speed = 0;
Expand Down
Loading

0 comments on commit 1566534

Please sign in to comment.