]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
net: phy: improve phy_resolve_aneg_linkmode
authorHeiner Kallweit <hkallweit1@gmail.com>
Thu, 14 Feb 2019 21:15:31 +0000 (22:15 +0100)
committerDavid S. Miller <davem@davemloft.net>
Sun, 17 Feb 2019 23:21:38 +0000 (15:21 -0800)
We have the settings array of modes which is sorted based on aneg
priority. Instead of checking each mode manually let's simply iterate
over the sorted settings.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/phy-core.c

index de58a59815d5e2619e54af31c021ea6e354d9e87..5016cd5fd7c7595c4e7d0818d13337cf59bbab53 100644 (file)
@@ -421,45 +421,16 @@ void of_set_phy_eee_broken(struct phy_device *phydev)
 void phy_resolve_aneg_linkmode(struct phy_device *phydev)
 {
        __ETHTOOL_DECLARE_LINK_MODE_MASK(common);
+       int i;
 
        linkmode_and(common, phydev->lp_advertising, phydev->advertising);
 
-       if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT, common)) {
-               phydev->speed = SPEED_10000;
-               phydev->duplex = DUPLEX_FULL;
-       } else if (linkmode_test_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
-                                    common)) {
-               phydev->speed = SPEED_5000;
-               phydev->duplex = DUPLEX_FULL;
-       } else if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
-                                    common)) {
-               phydev->speed = SPEED_2500;
-               phydev->duplex = DUPLEX_FULL;
-       } else if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
-                                    common)) {
-               phydev->speed = SPEED_1000;
-               phydev->duplex = DUPLEX_FULL;
-       } else if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
-                                    common)) {
-               phydev->speed = SPEED_1000;
-               phydev->duplex = DUPLEX_HALF;
-       } else if (linkmode_test_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT,
-                                    common)) {
-               phydev->speed = SPEED_100;
-               phydev->duplex = DUPLEX_FULL;
-       } else if (linkmode_test_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT,
-                                    common)) {
-               phydev->speed = SPEED_100;
-               phydev->duplex = DUPLEX_HALF;
-       } else if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT,
-                                    common)) {
-               phydev->speed = SPEED_10;
-               phydev->duplex = DUPLEX_FULL;
-       } else if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT,
-                                    common)) {
-               phydev->speed = SPEED_10;
-               phydev->duplex = DUPLEX_HALF;
-       }
+       for (i = 0; i < ARRAY_SIZE(settings); i++)
+               if (test_bit(settings[i].bit, common)) {
+                       phydev->speed = settings[i].speed;
+                       phydev->duplex = settings[i].duplex;
+                       break;
+               }
 
        if (phydev->duplex == DUPLEX_FULL) {
                phydev->pause = linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT,