]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net: phy: improve pause handling
authorHeiner Kallweit <hkallweit1@gmail.com>
Wed, 1 May 2019 19:34:43 +0000 (21:34 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sat, 4 May 2019 04:47:55 +0000 (00:47 -0400)
When probing the phy device we set sym and asym pause in the "supported"
bitmap (unless the PHY tells us otherwise). However we don't know yet
whether the MAC supports pause. Simply copying phy->supported to
phy->advertising will trigger advertising pause, and that's not
what we want. Therefore add phy_advertise_supported() that copies all
modes but doesn't touch the pause bits.

In phy_support_(a)sym_pause we shouldn't set any bits in the supported
bitmap because we may set a bit the PHY intentionally disabled.
Effective pause support should be the AND-combined PHY and MAC pause
capabilities. If the MAC supports everything, then it's only relevant
what the PHY supports. If MAC supports sym pause only, then we have to
clear the asym bit in phydev->supported.
Copy the pause flags only and don't touch the modes, because a driver
may have intentionally removed a mode from phydev->advertising.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/fixed_phy.c
drivers/net/phy/phy-core.c
drivers/net/phy/phy_device.c
include/linux/phy.h

index 1acd8bfdb3bc30e7855e36eb18baee4cf9baf7c3..3ffe46df249ee2a482b748ac66a79ff31141690a 100644 (file)
@@ -301,7 +301,7 @@ static struct phy_device *__fixed_phy_register(unsigned int irq,
                                 phy->supported);
        }
 
-       linkmode_copy(phy->advertising, phy->supported);
+       phy_advertise_supported(phy);
 
        ret = phy_device_register(phy);
        if (ret) {
index 12ce671020a5dede2f484558152429f0c0d6e568..3daf0214a242fef77909852a7b9676d1fe287eb3 100644 (file)
@@ -228,7 +228,7 @@ int phy_set_max_speed(struct phy_device *phydev, u32 max_speed)
        if (err)
                return err;
 
-       linkmode_copy(phydev->advertising, phydev->supported);
+       phy_advertise_supported(phydev);
 
        return 0;
 }
index 2a2aaa5f3e74fd53a92da177dbd3548f227add0d..068ab750c9cee45bf8fb6c1c9788fe965f49976c 100644 (file)
@@ -1985,10 +1985,35 @@ EXPORT_SYMBOL(genphy_loopback);
 void phy_remove_link_mode(struct phy_device *phydev, u32 link_mode)
 {
        linkmode_clear_bit(link_mode, phydev->supported);
-       linkmode_copy(phydev->advertising, phydev->supported);
+       phy_advertise_supported(phydev);
 }
 EXPORT_SYMBOL(phy_remove_link_mode);
 
+static void phy_copy_pause_bits(unsigned long *dst, unsigned long *src)
+{
+       linkmode_mod_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, dst,
+               linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, src));
+       linkmode_mod_bit(ETHTOOL_LINK_MODE_Pause_BIT, dst,
+               linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT, src));
+}
+
+/**
+ * phy_advertise_supported - Advertise all supported modes
+ * @phydev: target phy_device struct
+ *
+ * Description: Called to advertise all supported modes, doesn't touch
+ * pause mode advertising.
+ */
+void phy_advertise_supported(struct phy_device *phydev)
+{
+       __ETHTOOL_DECLARE_LINK_MODE_MASK(new);
+
+       linkmode_copy(new, phydev->supported);
+       phy_copy_pause_bits(new, phydev->advertising);
+       linkmode_copy(phydev->advertising, new);
+}
+EXPORT_SYMBOL(phy_advertise_supported);
+
 /**
  * phy_support_sym_pause - Enable support of symmetrical pause
  * @phydev: target phy_device struct
@@ -1999,8 +2024,7 @@ EXPORT_SYMBOL(phy_remove_link_mode);
 void phy_support_sym_pause(struct phy_device *phydev)
 {
        linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported);
-       linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported);
-       linkmode_copy(phydev->advertising, phydev->supported);
+       phy_copy_pause_bits(phydev->advertising, phydev->supported);
 }
 EXPORT_SYMBOL(phy_support_sym_pause);
 
@@ -2012,9 +2036,7 @@ EXPORT_SYMBOL(phy_support_sym_pause);
  */
 void phy_support_asym_pause(struct phy_device *phydev)
 {
-       linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported);
-       linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported);
-       linkmode_copy(phydev->advertising, phydev->supported);
+       phy_copy_pause_bits(phydev->advertising, phydev->supported);
 }
 EXPORT_SYMBOL(phy_support_asym_pause);
 
@@ -2177,7 +2199,7 @@ static int phy_probe(struct device *dev)
                phydev->is_gigabit_capable = 1;
 
        of_set_phy_supported(phydev);
-       linkmode_copy(phydev->advertising, phydev->supported);
+       phy_advertise_supported(phydev);
 
        /* Get the EEE modes we want to prohibit. We will ask
         * the PHY stop advertising these mode later on
index 0f9552b17ee72390b6d764fac6ea4760fc75121c..4a03f8a46d33354fbc7589245fffbfc43b623083 100644 (file)
@@ -1154,6 +1154,7 @@ void phy_request_interrupt(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_advertise_supported(struct phy_device *phydev);
 void phy_support_sym_pause(struct phy_device *phydev);
 void phy_support_asym_pause(struct phy_device *phydev);
 void phy_set_sym_pause(struct phy_device *phydev, bool rx, bool tx,