net: ethernet: Add helper for MACs which support asym pause
authorAndrew Lunn <andrew@lunn.ch>
Tue, 11 Sep 2018 23:53:15 +0000 (01:53 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 13 Sep 2018 03:24:21 +0000 (20:24 -0700)
Rather than have the MAC drivers manipulate phydev members to indicate
they support Asym Pause, add a helper function.

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>
17 files changed:
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c
drivers/net/ethernet/apm/xgene/xgene_enet_hw.c
drivers/net/ethernet/broadcom/sb1250-mac.c
drivers/net/ethernet/broadcom/tg3.c
drivers/net/ethernet/cortina/gemini.c
drivers/net/ethernet/dnet.c
drivers/net/ethernet/faraday/ftgmac100.c
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
drivers/net/ethernet/freescale/gianfar.c
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
drivers/net/ethernet/mediatek/mtk_eth_soc.c
drivers/net/ethernet/microchip/lan743x_main.c
drivers/net/ethernet/smsc/smsc911x.c
drivers/net/ethernet/smsc/smsc9420.c
drivers/net/ethernet/socionext/sni_ave.c
drivers/net/phy/phy_device.c
include/linux/phy.h

index 3ceb4f95ca7cad95cc6fc03772b34b3df0b425b6..289129011b9fc3857bb2562a3a2e052c44ee0e18 100644 (file)
@@ -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");
@@ -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");
index 4831f9de59458a0c40b3d10ea655542fcf7fd5bb..e3560311711a5e8b8f032f998591333a26b55c7a 100644 (file)
@@ -898,9 +898,7 @@ int xgene_enet_phy_connect(struct net_device *ndev)
        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_dev->supported |= SUPPORTED_Pause |
-                             SUPPORTED_Asym_Pause;
-       phy_dev->advertising = phy_dev->supported;
+       phy_support_asym_pause(phy_dev);
 
        return 0;
 }
index 4ce4b097ec05f88fb184612c54fc34d9875872e0..53acbbb366374a4379d047fe1945c47fb4440d6e 100644 (file)
@@ -2358,13 +2358,10 @@ static int sbmac_mii_probe(struct net_device *dev)
 
        /* Remove any features not supported by the controller */
        phy_set_max_speed(phy_dev, SPEED_1000);
-       phy_dev->supported |= SUPPORTED_Pause |
-                             SUPPORTED_Asym_Pause;
+       phy_support_asym_pause(phy_dev);
 
        phy_attached_info(phy_dev);
 
-       phy_dev->advertising = phy_dev->supported;
-
        sc->phy_dev = phy_dev;
 
        return 0;
index eab00239a47a01fc2cd6222f3463d7654df6d5a3..193e990fac7adb295888320a9551896aa9ad9109 100644 (file)
@@ -2123,15 +2123,13 @@ static int tg3_phy_init(struct tg3 *tp)
        case PHY_INTERFACE_MODE_RGMII:
                if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) {
                        phy_set_max_speed(phydev, SPEED_1000);
-                       phydev->supported |= (SUPPORTED_Pause |
-                                             SUPPORTED_Asym_Pause);
+                       phy_support_asym_pause(phydev);
                        break;
                }
                /* fallthru */
        case PHY_INTERFACE_MODE_MII:
                phy_set_max_speed(phydev, SPEED_100);
-               phydev->supported |= (SUPPORTED_Pause |
-                                     SUPPORTED_Asym_Pause);
+               phy_support_asym_pause(phydev);
                break;
        default:
                phy_disconnect(mdiobus_get_phy(tp->mdio_bus, tp->phy_addr));
@@ -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;
index 2b46c0de90d0cf7352096ce31c4ffdd9d4f7bd12..ceec467f590d2a382447d087a9e16f7b0fb576de 100644 (file)
@@ -373,8 +373,7 @@ static int gmac_setup_phy(struct net_device *netdev)
        netdev->phydev = phy;
 
        phy_set_max_speed(phy, SPEED_1000);
-       phy->supported |= SUPPORTED_Asym_Pause | SUPPORTED_Pause;
-       phy->advertising = phy->supported;
+       phy_support_asym_pause(phy);
 
        /* set PHY interface type */
        switch (phy->interface) {
index 08b7ad1594ce7e7504ac5192971edea0fc202931..79521e27f0d1738c1d5d55449dfcc55ccff2da7e 100644 (file)
@@ -288,9 +288,7 @@ static int dnet_mii_probe(struct net_device *dev)
        else
                phy_set_max_speed(phydev, SPEED_100);
 
-       phydev->supported |= SUPPORTED_Asym_Pause | SUPPORTED_Pause;
-
-       phydev->advertising = phydev->supported;
+       phy_support_asym_pause(phydev);
 
        bp->link = 0;
        bp->speed = 0;
index ed6c76d20b45b2a38ccf87e63487e77a756812a3..3f319ee66ab4da70fd3f54a91cbe3e262d33d525 100644 (file)
@@ -1079,8 +1079,7 @@ static int ftgmac100_mii_probe(struct ftgmac100 *priv, phy_interface_t intf)
        /* Indicate that we support PAUSE frames (see comment in
         * Documentation/networking/phy.txt)
         */
-       phydev->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
-       phydev->advertising = phydev->supported;
+       phy_support_asym_pause(phydev);
 
        /* Display what we found */
        phy_attached_info(phydev);
index 783134f1b779387cc167b97c664e548bab53527a..a5131a510e8b55fcacc899957fe320f12de07f83 100644 (file)
@@ -2491,8 +2491,7 @@ static int dpaa_phy_init(struct net_device *net_dev)
 
        /* Remove any features not supported by the controller */
        phy_dev->supported &= mac_dev->if_support;
-       phy_dev->supported |= (SUPPORTED_Pause | SUPPORTED_Asym_Pause);
-       phy_dev->advertising = phy_dev->supported;
+       phy_support_asym_pause(phy_dev);
 
        mac_dev->phy_dev = phy_dev;
        net_dev->phydev = phy_dev;
index f27f9bae1a4ac02811590636f55d74dcb0568225..40a1a87cd3389ac98344edf166c4bc9fbb25dbf3 100644 (file)
@@ -1814,8 +1814,8 @@ static int init_phy(struct net_device *dev)
        phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
        phydev->advertising = phydev->supported;
 
-       /* Add support for flow control, but don't advertise it by default */
-       phydev->supported |= (SUPPORTED_Pause | SUPPORTED_Asym_Pause);
+       /* Add support for flow control */
+       phy_support_asym_pause(phydev);
 
        /* disable EEE autoneg, EEE not supported by eTSEC */
        memset(&edata, 0, sizeof(struct ethtool_eee));
index 05b15d254e3227817aebeea02e43c86efdbaacb6..24b1f2a0c32afc328cbdc82b67d5adb5fae916cc 100644 (file)
@@ -211,9 +211,7 @@ int hclge_mac_connect_phy(struct hclge_dev *hdev)
        }
 
        phydev->supported &= HCLGE_PHY_SUPPORTED_FEATURES;
-       phydev->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
-
-       phydev->advertising = phydev->supported;
+       phy_support_asym_pause(phydev);
 
        return 0;
 }
index db231bda7c2aa324f635ad77771736fb9ee9346e..cc1e9a96a43b27a234f89fd9e9d562e868db89f3 100644 (file)
@@ -355,12 +355,8 @@ static int mtk_phy_connect(struct net_device *dev)
        dev->phydev->speed = 0;
        dev->phydev->duplex = 0;
 
-       if (of_phy_is_fixed_link(mac->of_node))
-               dev->phydev->supported |=
-               SUPPORTED_Pause | SUPPORTED_Asym_Pause;
-
        phy_set_max_speed(dev->phydev, SPEED_1000);
-       dev->phydev->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
+       phy_support_asym_pause(dev->phydev);
        dev->phydev->advertising = dev->phydev->supported |
                                    ADVERTISED_Autoneg;
        phy_start_aneg(dev->phydev);
index 048307959c01ce6191b1188a356d1d8dfc64fd6d..b1a0e657febf110dd2ce6b304f3ea5493d5031aa 100644 (file)
@@ -999,7 +999,6 @@ static int lan743x_phy_open(struct lan743x_adapter *adapter)
        struct phy_device *phydev;
        struct net_device *netdev;
        int ret = -EIO;
-       u32 mii_adv;
 
        netdev = adapter->netdev;
        phydev = phy_find_first(adapter->mdiobus);
@@ -1016,10 +1015,8 @@ static int lan743x_phy_open(struct lan743x_adapter *adapter)
        phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
 
        /* support both flow controls */
+       phy_support_asym_pause(phydev);
        phy->fc_request_control = (FLOW_CTRL_RX | FLOW_CTRL_TX);
-       phydev->advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
-       mii_adv = (u32)mii_advertise_flowctrl(phy->fc_request_control);
-       phydev->advertising |= mii_adv_to_ethtool_adv_t(mii_adv);
        phy->fc_autoneg = phydev->autoneg;
 
        phy_start(phydev);
index 3e34bf53f0559611b474f65a7ab324031113898d..c009407618d92a36c88a623406a874dac149918f 100644 (file)
@@ -1051,8 +1051,7 @@ static int smsc911x_mii_probe(struct net_device *dev)
        phy_set_max_speed(phydev, SPEED_100);
 
        /* mask with MAC supported features */
-       phydev->supported |= (SUPPORTED_Pause | SUPPORTED_Asym_Pause);
-       phydev->advertising = phydev->supported;
+       phy_support_asym_pause(phydev);
 
        pdata->last_duplex = -1;
        pdata->last_carrier = -1;
index 326177384544963684f90acad925961752e09fe4..9b6366b201105face5f2177b48ddf9d101a126b4 100644 (file)
@@ -1138,8 +1138,7 @@ static int smsc9420_mii_probe(struct net_device *dev)
        phy_set_max_speed(phydev, SPEED_100);
 
        /* mask with MAC supported features */
-       phydev->supported |= (SUPPORTED_Pause | SUPPORTED_Asym_Pause);
-       phydev->advertising = phydev->supported;
+       phy_support_asym_pause(phydev);
 
        phy_attached_info(phydev);
 
index 76ff364c40e907c0078a46d61250906af17b9b59..a50720ec109c348b2ccd456896afb9f21790623e 100644 (file)
@@ -1225,7 +1225,8 @@ static int ave_init(struct net_device *ndev)
 
        if (!phy_interface_is_rgmii(phydev))
                phy_set_max_speed(phydev, SPEED_100);
-       phydev->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
+
+       phy_support_asym_pause(phydev);
 
        phy_attached_info(phydev);
 
index e9ca83a438b06dfc3a347dfadd09717ab7397ebb..a0646a66f0059ce0db794061c531568f3a31ef87 100644 (file)
@@ -1783,6 +1783,19 @@ void phy_remove_link_mode(struct phy_device *phydev, u32 link_mode)
 }
 EXPORT_SYMBOL(phy_remove_link_mode);
 
+/**
+ * phy_support_asym_pause - Enable support of asym pause
+ * @phydev: target phy_device struct
+ *
+ * Description: Called by the MAC to indicate is supports Asym Pause.
+ */
+void phy_support_asym_pause(struct phy_device *phydev)
+{
+       phydev->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
+       phydev->advertising = phydev->supported;
+}
+EXPORT_SYMBOL(phy_support_asym_pause);
+
 static void of_set_phy_supported(struct phy_device *phydev)
 {
        struct device_node *node = phydev->mdio.dev.of_node;
index 9c4c3eca8cf2d33ea54173c93c74526c2e501f5e..e2db819807c12ee0424aace47c34960c6c12093e 100644 (file)
@@ -1050,6 +1050,7 @@ int phy_start_interrupts(struct phy_device *phydev);
 void phy_print_status(struct phy_device *phydev);
 int phy_set_max_speed(struct phy_device *phydev, u32 max_speed);
 void phy_remove_link_mode(struct phy_device *phydev, u32 link_mode);
+void phy_support_asym_pause(struct phy_device *phydev);
 
 int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask,
                       int (*run)(struct phy_device *));