net: ethernet: Use phy_set_max_speed() to limit advertised speed
authorAndrew Lunn <andrew@lunn.ch>
Tue, 11 Sep 2018 23:53:11 +0000 (01:53 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 13 Sep 2018 03:24:20 +0000 (20:24 -0700)
Many Ethernet MAC drivers want to limit the PHY to only advertise a
maximum speed of 100Mbs or 1Gbps. Rather than using a mask, make use
of the helper function phy_set_max_speed().

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>
28 files changed:
drivers/net/ethernet/8390/ax88796.c
drivers/net/ethernet/aeroflex/greth.c
drivers/net/ethernet/agere/et131x.c
drivers/net/ethernet/allwinner/sun4i-emac.c
drivers/net/ethernet/altera/altera_tse_main.c
drivers/net/ethernet/amd/au1000_eth.c
drivers/net/ethernet/broadcom/bcm63xx_enet.c
drivers/net/ethernet/broadcom/genet/bcmmii.c
drivers/net/ethernet/broadcom/sb1250-mac.c
drivers/net/ethernet/broadcom/tg3.c
drivers/net/ethernet/cadence/macb_main.c
drivers/net/ethernet/cortina/gemini.c
drivers/net/ethernet/dnet.c
drivers/net/ethernet/ethoc.c
drivers/net/ethernet/freescale/fec_main.c
drivers/net/ethernet/freescale/ucc_geth.c
drivers/net/ethernet/lantiq_etop.c
drivers/net/ethernet/mediatek/mtk_eth_soc.c
drivers/net/ethernet/nxp/lpc_eth.c
drivers/net/ethernet/rdc/r6040.c
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
drivers/net/ethernet/smsc/smsc911x.c
drivers/net/ethernet/smsc/smsc9420.c
drivers/net/ethernet/socionext/sni_ave.c
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
drivers/net/ethernet/toshiba/tc35815.c
drivers/net/ethernet/xilinx/xilinx_emaclite.c
drivers/staging/mt7621-eth/mdio.c

index 2a0ddec1dd560f6bc55d430f2d6a2f934416bc2c..3dcc61821ed51222fa37daba9daf3c8f81d96f9d 100644 (file)
@@ -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);
index 4309be3724ad4548b871946c934206eaa2d2d3df..7c9348a26cbbea0ccea156a07197373ed76035ca 100644 (file)
@@ -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;
 
index 48220b6c600d38cd0d84b68d73ffb75b8ad10b01..ea34bcb868b57fba300df2d9d393aaa2ad82a926 100644 (file)
@@ -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);
index 3143de45baaad58bb08c0aad86711351a7cd39d7..e1acafa82214133044765421109a84ff2168dd91 100644 (file)
@@ -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;
index baca8f704a459530ce16c17a046d571a34ca416c..02921d877c08a7a93556db45a116d78ed2c485cd 100644 (file)
@@ -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
index 73ca8879ada7f944a21b31b232562928cde38fdc..7c1eb304c27ec84dc56fb337473c2c867af3669e 100644 (file)
@@ -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;
index 897302adc38ec16869609cccf6ddc8ee9941a3c7..2eee9459c2cfe88d55d1ea333ec754be03577eca 100644 (file)
@@ -890,14 +890,8 @@ 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;
+               phydev->supported |= SUPPORTED_Pause;
+               phy_set_max_speed(phydev, SPEED_100);
 
                if (priv->pause_auto && priv->pause_rx && priv->pause_tx)
                        phydev->advertising |= SUPPORTED_Pause;
index 4241ae928d4abb4f61d39344e93d08603a2d2c86..b11d58f1bf454645c36e583f2d0ea03021f085c2 100644 (file)
@@ -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;
index ef4a0c326736dc2518216b3aee4108e5ecf5133c..4ce4b097ec05f88fb184612c54fc34d9875872e0 100644 (file)
@@ -2357,15 +2357,8 @@ 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 |
+       phy_set_max_speed(phy_dev, SPEED_1000);
+       phy_dev->supported |= SUPPORTED_Pause |
                              SUPPORTED_Asym_Pause;
 
        phy_attached_info(phy_dev);
index e6f28c7942abf08da76f4eef87bce5f88a7b0334..cdc32724c9d909b2faa72ded299efda2205fbfb6 100644 (file)
@@ -2122,15 +2122,15 @@ 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 |
+                       phy_set_max_speed(phydev, SPEED_1000);
+                       phydev->supported &= (SUPPORTED_Pause |
                                              SUPPORTED_Asym_Pause);
                        break;
                }
                /* fallthru */
        case PHY_INTERFACE_MODE_MII:
-               phydev->supported &= (PHY_BASIC_FEATURES |
-                                     SUPPORTED_Pause |
+               phy_set_max_speed(phydev, SPEED_100);
+               phydev->supported &= (SUPPORTED_Pause |
                                      SUPPORTED_Asym_Pause);
                break;
        default:
index 16e4ef7d71855c7ed10905c3fdcf8d3a255f20c4..bd4095c3a0314f0217397a270a9a13b773264e2b 100644 (file)
@@ -544,9 +544,9 @@ 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;
index 1c9ad3630c7754b692079c19ffafec7c07922c80..2b46c0de90d0cf7352096ce31c4ffdd9d4f7bd12 100644 (file)
@@ -372,7 +372,7 @@ static int gmac_setup_phy(struct net_device *netdev)
                return -ENODEV;
        netdev->phydev = phy;
 
-       phy->supported &= PHY_GBIT_FEATURES;
+       phy_set_max_speed(phy, SPEED_1000);
        phy->supported |= SUPPORTED_Asym_Pause | SUPPORTED_Pause;
        phy->advertising = phy->supported;
 
index 5a847941c46b9175fbbc11e058134152b6bd97ef..08b7ad1594ce7e7504ac5192971edea0fc202931 100644 (file)
@@ -284,9 +284,9 @@ static int dnet_mii_probe(struct net_device *dev)
 
        /* mask with MAC supported features */
        if (bp->capabilities & DNET_HAS_GIGABIT)
-               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);
 
        phydev->supported |= SUPPORTED_Asym_Pause | SUPPORTED_Pause;
 
index 60da0499ad66c4db3b6b830259c3d9dbdecc7884..0f3e7f21c6fa59e363fc2ee779f2fd1943022642 100644 (file)
@@ -721,10 +721,7 @@ static int ethoc_mdio_probe(struct net_device *dev)
                return err;
        }
 
-       phy->advertising &= ~(ADVERTISED_1000baseT_Full |
-                             ADVERTISED_1000baseT_Half);
-       phy->supported &= ~(SUPPORTED_1000baseT_Full |
-                           SUPPORTED_1000baseT_Half);
+       phy_set_max_speed(phy, SPEED_100);
 
        return 0;
 }
index 2708297e7795929e798ee73e5f4cc2c1907be12d..5e849510c6897c5b2e17d3a4f85cc774da41c449 100644 (file)
@@ -1946,14 +1946,14 @@ static int fec_enet_mii_probe(struct net_device *ndev)
 
        /* mask with MAC supported features */
        if (fep->quirks & FEC_QUIRK_HAS_GBIT) {
-               phy_dev->supported &= PHY_GBIT_FEATURES;
+               phy_set_max_speed(phy_dev, 1000);
                phy_dev->supported &= ~SUPPORTED_1000baseT_Half;
 #if !defined(CONFIG_M5272)
                phy_dev->supported |= SUPPORTED_Pause;
 #endif
        }
        else
-               phy_dev->supported &= PHY_BASIC_FEATURES;
+               phy_set_max_speed(phy_dev, 100);
 
        phy_dev->advertising = phy_dev->supported;
 
index 22a817da861e3f62684123b26a81ae59944c22f3..9600837f21b8de7823122aabf185a1ceeda661c5 100644 (file)
@@ -1742,12 +1742,7 @@ static int init_phy(struct net_device *dev)
        if (priv->phy_interface == PHY_INTERFACE_MODE_SGMII)
                uec_configure_serdes(dev);
 
-       phydev->supported &= (SUPPORTED_MII |
-                             SUPPORTED_Autoneg |
-                             ADVERTISED_10baseT_Half |
-                             ADVERTISED_10baseT_Full |
-                             ADVERTISED_100baseT_Half |
-                             ADVERTISED_100baseT_Full);
+       phy_set_max_speed(phydev, SPEED_100);
 
        if (priv->max_speed == SPEED_1000)
                phydev->supported |= ADVERTISED_1000baseT_Full;
index 7a637b51c7d2302b63f2eb579adea4e0459e7430..7b25ba957d3f9ec02d2ffb5140dd22e6ee101691 100644 (file)
@@ -364,15 +364,8 @@ ltq_etop_mdio_probe(struct net_device *dev)
                return PTR_ERR(phydev);
        }
 
-       phydev->supported &= (SUPPORTED_10baseT_Half
-                             | SUPPORTED_10baseT_Full
-                             | SUPPORTED_100baseT_Half
-                             | SUPPORTED_100baseT_Full
-                             | SUPPORTED_Autoneg
-                             | SUPPORTED_MII
-                             | SUPPORTED_TP);
-
-       phydev->advertising = phydev->supported;
+       phy_set_max_speed(phydev, SPEED_100);
+
        phy_attached_info(phydev);
 
        return 0;
index b44bcfd85b05d63358ee4b8242a4312a9dbdf119..e93b5375504ba2da19588aae253b0b51305fee1f 100644 (file)
@@ -359,8 +359,8 @@ static int mtk_phy_connect(struct net_device *dev)
                dev->phydev->supported |=
                SUPPORTED_Pause | SUPPORTED_Asym_Pause;
 
-       dev->phydev->supported &= PHY_GBIT_FEATURES | SUPPORTED_Pause |
-                                  SUPPORTED_Asym_Pause;
+       phy_set_max_speed(dev->phydev, SPEED_1000);
+       dev->phydev->supported &= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
        dev->phydev->advertising = dev->phydev->supported |
                                    ADVERTISED_Autoneg;
        phy_start_aneg(dev->phydev);
index 08381ef8bdb481df81eb448b2f8ceda61c13ba8e..8b23d28484574db66d5778d2bae1b10c2ac42b45 100644 (file)
@@ -797,8 +797,7 @@ static int lpc_mii_probe(struct net_device *ndev)
                return PTR_ERR(phydev);
        }
 
-       /* mask with MAC supported features */
-       phydev->supported &= PHY_BASIC_FEATURES;
+       phy_set_max_speed(phydev, SPEED_100);
 
        phydev->advertising = phydev->supported;
 
index aa11b70b9ca48081bf2e78604d2d2ccad36a84cb..04aa592f35c36f9782d891c65e2c0d810c9fd4cf 100644 (file)
@@ -1024,16 +1024,8 @@ static int r6040_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_MII
-                               | SUPPORTED_TP);
-
-       phydev->advertising = phydev->supported;
+       phy_set_max_speed(phydev, SPEED_100);
+
        lp->old_link = 0;
        lp->old_duplex = -1;
 
index a9da1ad4b4f20434418b2ad0e831a904472e213a..690aee88f0eb0a892cebd4a324cfb9b6ecac4695 100644 (file)
@@ -298,8 +298,8 @@ static int sxgbe_init_phy(struct net_device *ndev)
        /* Stop Advertising 1000BASE Capability if interface is not GMII */
        if ((phy_iface == PHY_INTERFACE_MODE_MII) ||
            (phy_iface == PHY_INTERFACE_MODE_RMII))
-               phydev->advertising &= ~(SUPPORTED_1000baseT_Half |
-                                        SUPPORTED_1000baseT_Full);
+               phy_set_max_speed(phydev, SPEED_1000);
+
        if (phydev->phy_id == 0) {
                phy_disconnect(phydev);
                return -ENODEV;
index f0afb88d7bc2b02de3dc1054ec2ec5803f452a35..f84dbd0beb8e6284703be51e5f9e7dc3451da051 100644 (file)
@@ -1048,9 +1048,10 @@ static int smsc911x_mii_probe(struct net_device *dev)
 
        phy_attached_info(phydev);
 
+       phy_set_max_speed(phydev, SPEED_100);
+
        /* mask with MAC supported features */
-       phydev->supported &= (PHY_BASIC_FEATURES | SUPPORTED_Pause |
-                             SUPPORTED_Asym_Pause);
+       phydev->supported &= (SUPPORTED_Pause | SUPPORTED_Asym_Pause);
        phydev->advertising = phydev->supported;
 
        pdata->last_duplex = -1;
index 2fa3c1d03abc591f70ac857f2f3665e5e0ee143b..795f60d92611ef15c129720c25c629d2ff39284e 100644 (file)
@@ -1135,9 +1135,10 @@ static int smsc9420_mii_probe(struct net_device *dev)
                return PTR_ERR(phydev);
        }
 
+       phy_set_max_speed(phydev, SPEED_100);
+
        /* mask with MAC supported features */
-       phydev->supported &= (PHY_BASIC_FEATURES | SUPPORTED_Pause |
-                             SUPPORTED_Asym_Pause);
+       phydev->supported &= (SUPPORTED_Pause | SUPPORTED_Asym_Pause);
        phydev->advertising = phydev->supported;
 
        phy_attached_info(phydev);
index f7ecceeb1e280fcb71b48dfc282ba42f3800fb06..76ff364c40e907c0078a46d61250906af17b9b59 100644 (file)
@@ -1223,10 +1223,8 @@ static int ave_init(struct net_device *ndev)
        phy_ethtool_get_wol(phydev, &wol);
        device_set_wakeup_capable(&ndev->dev, !!wol.supported);
 
-       if (!phy_interface_is_rgmii(phydev)) {
-               phydev->supported &= ~PHY_GBIT_FEATURES;
-               phydev->supported |= PHY_BASIC_FEATURES;
-       }
+       if (!phy_interface_is_rgmii(phydev))
+               phy_set_max_speed(phydev, SPEED_100);
        phydev->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
 
        phy_attached_info(phydev);
index 9f458bb16f2a6edb6ab8cca33c00176b1cce1d67..3d7aec7a050bf28ce1baad80dbd00c04465b416c 100644 (file)
@@ -987,8 +987,7 @@ static int stmmac_init_phy(struct net_device *dev)
        if ((interface == PHY_INTERFACE_MODE_MII) ||
            (interface == PHY_INTERFACE_MODE_RMII) ||
                (max_speed < 1000 && max_speed > 0))
-               phydev->advertising &= ~(SUPPORTED_1000baseT_Half |
-                                        SUPPORTED_1000baseT_Full);
+               phy_set_max_speed(phydev, SPEED_100);
 
        /*
         * Half-duplex mode not supported with multiqueue
index cce9c9ed46aa9a8462080c5949bdb6621e247f0d..7163a8d10dba0bb5bb30299e7de1f1dce76fafc4 100644 (file)
@@ -628,7 +628,7 @@ static int tc_mii_probe(struct net_device *dev)
        phy_attached_info(phydev);
 
        /* mask with MAC supported features */
-       phydev->supported &= PHY_BASIC_FEATURES;
+       phy_set_max_speed(phydev, SPEED_100);
        dropmask = 0;
        if (options.speed == 10)
                dropmask |= SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full;
index 42f1f518dad6939300905f8b6218f4f31fabd212..46d3092b8aad72b87c2610cc7784279a1a1b1e32 100644 (file)
@@ -941,8 +941,7 @@ static int xemaclite_open(struct net_device *dev)
                }
 
                /* EmacLite doesn't support giga-bit speeds */
-               lp->phy_dev->supported &= (PHY_BASIC_FEATURES);
-               lp->phy_dev->advertising = lp->phy_dev->supported;
+               phy_set_max_speed(lp->phy_dev, SPEED_100);
 
                /* Don't advertise 1000BASE-T Full/Half duplex speeds */
                phy_write(lp->phy_dev, MII_CTRL1000, 0);
index 7ad0c41412057f72c29737f7f0819be2f39d57f8..2c6e1800a3fd2a018c56ccca95054f345a06db1c 100644 (file)
@@ -112,7 +112,7 @@ static void phy_init(struct mtk_eth *eth, struct mtk_mac *mac,
        phy->autoneg = AUTONEG_ENABLE;
        phy->speed = 0;
        phy->duplex = 0;
-       phy->supported &= PHY_BASIC_FEATURES;
+       phy_set_max_speed(phy, SPEED_100);
        phy->advertising = phy->supported | ADVERTISED_Autoneg;
 
        phy_start_aneg(phy);