net: ethernet: Add helper to determine if pause configuration is supported
authorAndrew Lunn <andrew@lunn.ch>
Tue, 11 Sep 2018 23:53:19 +0000 (01:53 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 13 Sep 2018 03:24:21 +0000 (20:24 -0700)
Rather than have MAC drivers open code the test, add a helper in
phylib. This will help when we change the type of phydev->supported.

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>
drivers/net/ethernet/apm/xgene/xgene_enet_ethtool.c
drivers/net/ethernet/broadcom/tg3.c
drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c
drivers/net/ethernet/freescale/gianfar_ethtool.c
drivers/net/phy/phy_device.c
include/linux/phy.h

index dfe03afd00b05b65dbde319054a2e21280046cf3..78dd09b5beeb0f31fbf5ffb767fdaa5ceb7c882a 100644 (file)
@@ -312,9 +312,7 @@ static int xgene_set_pauseparam(struct net_device *ndev,
                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;
index b2a3d008e1dfea14c39e00ea5126210dd2680a5b..fb0e458e25b773c525ded4c4687c5811e38d3840 100644 (file)
@@ -12496,9 +12496,7 @@ static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam
 
                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;
index 1f8cdbc4378c13f97284a097a7cc147cf5e67ccd..5d0fdf667b8245e17510129d4fef2db0852e5452 100644 (file)
@@ -194,9 +194,7 @@ static int dpaa_set_pauseparam(struct net_device *net_dev,
                return -ENODEV;
        }
 
-       if (!(phydev->supported & SUPPORTED_Pause) ||
-           (!(phydev->supported & SUPPORTED_Asym_Pause) &&
-           (epause->rx_pause != epause->tx_pause)))
+       if (!phy_validate_pause(phydev, epause))
                return -EINVAL;
 
        /* The MAC should know how to handle PAUSE frame autonegotiation before
index 3545e8f715f24f8ea438f60a6730f277d526aa1c..d3662965f59df8e01d392cf4d69d495cb307345d 100644 (file)
@@ -507,9 +507,7 @@ static int gfar_spauseparam(struct net_device *dev,
        if (!phydev)
                return -ENODEV;
 
-       if (!(phydev->supported & SUPPORTED_Pause) ||
-           (!(phydev->supported & SUPPORTED_Asym_Pause) &&
-            (epause->rx_pause != epause->tx_pause)))
+       if (!phy_validate_pause(phydev, epause))
                return -EINVAL;
 
        priv->rx_pause_en = priv->tx_pause_en = 0;
index de95f1e072e9e17b8a3fcaee8c332ad5ed567892..af64a9320fb084d28d4703d3f4389f9b808be47a 100644 (file)
@@ -1863,6 +1863,26 @@ void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx)
 }
 EXPORT_SYMBOL(phy_set_asym_pause);
 
+/**
+ * phy_validate_pause - Test if the PHY/MAC support the pause configuration
+ * @phydev: phy_device struct
+ * @pp: requested pause configuration
+ *
+ * Description: Test if the PHY/MAC combination supports the Pause
+ * configuration the user is requesting. Returns True if it is
+ * supported, false otherwise.
+ */
+bool phy_validate_pause(struct phy_device *phydev,
+                       struct ethtool_pauseparam *pp)
+{
+       if (!(phydev->supported & SUPPORTED_Pause) ||
+           (!(phydev->supported & SUPPORTED_Asym_Pause) &&
+            pp->rx_pause != pp->tx_pause))
+               return false;
+       return true;
+}
+EXPORT_SYMBOL(phy_validate_pause);
+
 static void of_set_phy_supported(struct phy_device *phydev)
 {
        struct device_node *node = phydev->mdio.dev.of_node;
index 8521391ebb2010f8a987f0cd5c26863907fc85db..192a1fa0c73baf48d0af8919dc491bdcbb79673d 100644 (file)
@@ -1055,6 +1055,8 @@ void phy_support_asym_pause(struct phy_device *phydev);
 void phy_set_sym_pause(struct phy_device *phydev, bool rx, bool tx,
                       bool autoneg);
 void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx);
+bool phy_validate_pause(struct phy_device *phydev,
+                       struct ethtool_pauseparam *pp);
 
 int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask,
                       int (*run)(struct phy_device *));