net: phy: Add helper for advertise to lcl value
authorAndrew Lunn <andrew@lunn.ch>
Sat, 29 Sep 2018 21:04:13 +0000 (23:04 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 2 Oct 2018 05:55:36 +0000 (22:55 -0700)
Add a helper to convert the local advertising to an LCL capabilities,
which is then used to resolve pause flow control settings.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/mt7530.c
drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c
drivers/net/ethernet/freescale/fman/mac.c
drivers/net/ethernet/freescale/gianfar.c
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
drivers/net/ethernet/mediatek/mtk_eth_soc.c
drivers/net/ethernet/socionext/sni_ave.c
include/linux/mii.h

index 62e486652e622074b1ca1615e02a6cf029cc667b..a5de9bffe5bec940a83186d731bfe77ac23f97d3 100644 (file)
@@ -658,11 +658,7 @@ static void mt7530_adjust_link(struct dsa_switch *ds, int port,
                        if (phydev->asym_pause)
                                rmt_adv |= LPA_PAUSE_ASYM;
 
-                       if (phydev->advertising & ADVERTISED_Pause)
-                               lcl_adv |= ADVERTISE_PAUSE_CAP;
-                       if (phydev->advertising & ADVERTISED_Asym_Pause)
-                               lcl_adv |= ADVERTISE_PAUSE_ASYM;
-
+                       lcl_adv = ethtool_adv_to_lcl_adv_t(phydev->advertising);
                        flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
 
                        if (flowctrl & FLOW_CTRL_TX)
index 289129011b9fc3857bb2562a3a2e052c44ee0e18..a7e03e3ecc9340be35c5ebca5a482350487810a1 100644 (file)
@@ -1495,10 +1495,7 @@ static void xgbe_phy_phydev_flowctrl(struct xgbe_prv_data *pdata)
        if (!phy_data->phydev)
                return;
 
-       if (phy_data->phydev->advertising & ADVERTISED_Pause)
-               lcl_adv |= ADVERTISE_PAUSE_CAP;
-       if (phy_data->phydev->advertising & ADVERTISED_Asym_Pause)
-               lcl_adv |= ADVERTISE_PAUSE_ASYM;
+       lcl_adv = ethtool_adv_to_lcl_adv_t(phy_data->phydev->advertising);
 
        if (phy_data->phydev->pause) {
                XGBE_SET_LP_ADV(lks, Pause);
index a847b9c3b31a9a4e5c9c6f9734973c89d596e4c6..d79e4e009d637885271a1b7cdb29e9d24c7bbe02 100644 (file)
@@ -393,11 +393,7 @@ void fman_get_pause_cfg(struct mac_device *mac_dev, bool *rx_pause,
         */
 
        /* get local capabilities */
-       lcl_adv = 0;
-       if (phy_dev->advertising & ADVERTISED_Pause)
-               lcl_adv |= ADVERTISE_PAUSE_CAP;
-       if (phy_dev->advertising & ADVERTISED_Asym_Pause)
-               lcl_adv |= ADVERTISE_PAUSE_ASYM;
+       lcl_adv = ethtool_adv_to_lcl_adv_t(phy_dev->advertising);
 
        /* get link partner capabilities */
        rmt_adv = 0;
index 0bd21a49301672a37288e53ad776f1cd3a1ae9a2..3c8da1a18ba08cc7d266eff374363eaeb3faf47e 100644 (file)
@@ -3656,12 +3656,7 @@ static u32 gfar_get_flowctrl_cfg(struct gfar_private *priv)
                if (phydev->asym_pause)
                        rmt_adv |= LPA_PAUSE_ASYM;
 
-               lcl_adv = 0;
-               if (phydev->advertising & ADVERTISED_Pause)
-                       lcl_adv |= ADVERTISE_PAUSE_CAP;
-               if (phydev->advertising & ADVERTISED_Asym_Pause)
-                       lcl_adv |= ADVERTISE_PAUSE_ASYM;
-
+               lcl_adv = ethtool_adv_to_lcl_adv_t(phydev->advertising);
                flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
                if (flowctrl & FLOW_CTRL_TX)
                        val |= MACCFG1_TX_FLOW;
index 7c8b686b1ce18b3f9ca34db8ee46668c18c0fa88..c17ceeefa4534aefdb50792091d4f4c54d9460d4 100644 (file)
@@ -5006,11 +5006,7 @@ int hclge_cfg_flowctrl(struct hclge_dev *hdev)
        if (!phydev->link || !phydev->autoneg)
                return 0;
 
-       if (phydev->advertising & ADVERTISED_Pause)
-               local_advertising = ADVERTISE_PAUSE_CAP;
-
-       if (phydev->advertising & ADVERTISED_Asym_Pause)
-               local_advertising |= ADVERTISE_PAUSE_ASYM;
+       local_advertising = ethtool_adv_to_lcl_adv_t(phydev->advertising);
 
        if (phydev->pause)
                remote_advertising = LPA_PAUSE_CAP;
index cc1e9a96a43b27a234f89fd9e9d562e868db89f3..7dbfdac4067ad0ebaf1f4034948e6972589dfeb2 100644 (file)
@@ -243,11 +243,7 @@ static void mtk_phy_link_adjust(struct net_device *dev)
                if (dev->phydev->asym_pause)
                        rmt_adv |= LPA_PAUSE_ASYM;
 
-               if (dev->phydev->advertising & ADVERTISED_Pause)
-                       lcl_adv |= ADVERTISE_PAUSE_CAP;
-               if (dev->phydev->advertising & ADVERTISED_Asym_Pause)
-                       lcl_adv |= ADVERTISE_PAUSE_ASYM;
-
+               lcl_adv = ethtool_adv_to_lcl_adv_t(dev->phydev->advertising);
                flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
 
                if (flowctrl & FLOW_CTRL_TX)
index 2a156dcd45341214f74d0eb1c67490526f1d518f..6732f5cbde081052ce9e1c2417451118cadbff8f 100644 (file)
@@ -1116,11 +1116,8 @@ static void ave_phy_adjust_link(struct net_device *ndev)
                        rmt_adv |= LPA_PAUSE_CAP;
                if (phydev->asym_pause)
                        rmt_adv |= LPA_PAUSE_ASYM;
-               if (phydev->advertising & ADVERTISED_Pause)
-                       lcl_adv |= ADVERTISE_PAUSE_CAP;
-               if (phydev->advertising & ADVERTISED_Asym_Pause)
-                       lcl_adv |= ADVERTISE_PAUSE_ASYM;
 
+               lcl_adv = ethtool_adv_to_lcl_adv_t(phydev->advertising);
                cap = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
                if (cap & FLOW_CTRL_TX)
                        txcr |= AVE_TXCR_FLOCTR;
index 8c7da9473ad98f462144b9f353acc24247bf5257..9ed49c8261d07921dafb356712ac331e6fef0883 100644 (file)
@@ -334,6 +334,25 @@ static inline void mii_adv_to_linkmode_adv_t(unsigned long *advertising,
                linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising);
 }
 
+/**
+ * ethtool_adv_to_lcl_adv_t
+ * @advertising:pointer to ethtool advertising
+ *
+ * A small helper function that translates ethtool advertising to LVL
+ * pause capabilities.
+ */
+static inline u32 ethtool_adv_to_lcl_adv_t(u32 advertising)
+{
+       u32 lcl_adv = 0;
+
+       if (advertising & ADVERTISED_Pause)
+               lcl_adv |= ADVERTISE_PAUSE_CAP;
+       if (advertising & ADVERTISED_Asym_Pause)
+               lcl_adv |= ADVERTISE_PAUSE_ASYM;
+
+       return lcl_adv;
+}
+
 /**
  * mii_advertise_flowctrl - get flow control advertisement flags
  * @cap: Flow control capabilities (FLOW_CTRL_RX, FLOW_CTRL_TX or both)