]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
net: phy: provide and use genphy_read_status_fixed()
authorRussell King <rmk+kernel@armlinux.org.uk>
Tue, 17 Dec 2019 13:39:16 +0000 (13:39 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 19 Dec 2019 20:52:34 +0000 (12:52 -0800)
There are two drivers and generic code which contain exactly the same
code to read the status of a PHY operating without autonegotiation
enabled. Rather than duplicate this code, provide a helper to read
this information.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Reviewed-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/phy/lxt.c
drivers/net/phy/marvell.c
drivers/net/phy/phy_device.c
include/linux/phy.h

index 30172852e36e62ab5790646698d45587f8f7fda5..fec58ad69e02c28c127b6ad82f7fb7721971175d 100644 (file)
@@ -192,22 +192,9 @@ static int lxt973a2_read_status(struct phy_device *phydev)
 
                phy_resolve_aneg_pause(phydev);
        } else {
-               int bmcr = phy_read(phydev, MII_BMCR);
-
-               if (bmcr < 0)
-                       return bmcr;
-
-               if (bmcr & BMCR_FULLDPLX)
-                       phydev->duplex = DUPLEX_FULL;
-               else
-                       phydev->duplex = DUPLEX_HALF;
-
-               if (bmcr & BMCR_SPEED1000)
-                       phydev->speed = SPEED_1000;
-               else if (bmcr & BMCR_SPEED100)
-                       phydev->speed = SPEED_100;
-               else
-                       phydev->speed = SPEED_10;
+               err = genphy_read_status_fixed(phydev);
+               if (err < 0)
+                       return err;
 
                phydev->pause = phydev->asym_pause = 0;
                linkmode_zero(phydev->lp_advertising);
index d807c3e5cc566eff2cd8d44a4615b4ccff0fdc66..5e49639dc8dd1dc4715ee078625287fcf34e7aa8 100644 (file)
@@ -1407,22 +1407,11 @@ static int marvell_read_status_page_an(struct phy_device *phydev,
 
 static int marvell_read_status_page_fixed(struct phy_device *phydev)
 {
-       int bmcr = phy_read(phydev, MII_BMCR);
-
-       if (bmcr < 0)
-               return bmcr;
-
-       if (bmcr & BMCR_FULLDPLX)
-               phydev->duplex = DUPLEX_FULL;
-       else
-               phydev->duplex = DUPLEX_HALF;
+       int err;
 
-       if (bmcr & BMCR_SPEED1000)
-               phydev->speed = SPEED_1000;
-       else if (bmcr & BMCR_SPEED100)
-               phydev->speed = SPEED_100;
-       else
-               phydev->speed = SPEED_10;
+       err = genphy_read_status_fixed(phydev);
+       if (err < 0)
+               return err;
 
        phydev->pause = 0;
        phydev->asym_pause = 0;
index c61f2295e21e572aa6ea73a34b2689e21609d0b9..ec19efe7ea993b1f06c34a0bd343efa8f0d8fa40 100644 (file)
@@ -1992,6 +1992,36 @@ int genphy_read_lpa(struct phy_device *phydev)
 }
 EXPORT_SYMBOL(genphy_read_lpa);
 
+/**
+ * genphy_read_status_fixed - read the link parameters for !aneg mode
+ * @phydev: target phy_device struct
+ *
+ * Read the current duplex and speed state for a PHY operating with
+ * autonegotiation disabled.
+ */
+int genphy_read_status_fixed(struct phy_device *phydev)
+{
+       int bmcr = phy_read(phydev, MII_BMCR);
+
+       if (bmcr < 0)
+               return bmcr;
+
+       if (bmcr & BMCR_FULLDPLX)
+               phydev->duplex = DUPLEX_FULL;
+       else
+               phydev->duplex = DUPLEX_HALF;
+
+       if (bmcr & BMCR_SPEED1000)
+               phydev->speed = SPEED_1000;
+       else if (bmcr & BMCR_SPEED100)
+               phydev->speed = SPEED_100;
+       else
+               phydev->speed = SPEED_10;
+
+       return 0;
+}
+EXPORT_SYMBOL(genphy_read_status_fixed);
+
 /**
  * genphy_read_status - check the link status and update current link state
  * @phydev: target phy_device struct
@@ -2026,22 +2056,9 @@ int genphy_read_status(struct phy_device *phydev)
        if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) {
                phy_resolve_aneg_linkmode(phydev);
        } else if (phydev->autoneg == AUTONEG_DISABLE) {
-               int bmcr = phy_read(phydev, MII_BMCR);
-
-               if (bmcr < 0)
-                       return bmcr;
-
-               if (bmcr & BMCR_FULLDPLX)
-                       phydev->duplex = DUPLEX_FULL;
-               else
-                       phydev->duplex = DUPLEX_HALF;
-
-               if (bmcr & BMCR_SPEED1000)
-                       phydev->speed = SPEED_1000;
-               else if (bmcr & BMCR_SPEED100)
-                       phydev->speed = SPEED_100;
-               else
-                       phydev->speed = SPEED_10;
+               err = genphy_read_status_fixed(phydev);
+               if (err < 0)
+                       return err;
        }
 
        return 0;
index 1c4f97d2631d390e682ae71fdbe30d842c304be2..b2105e0d72d3a84e5862b9d46a2e2373fd578666 100644 (file)
@@ -1100,6 +1100,7 @@ int __genphy_config_aneg(struct phy_device *phydev, bool changed);
 int genphy_aneg_done(struct phy_device *phydev);
 int genphy_update_link(struct phy_device *phydev);
 int genphy_read_lpa(struct phy_device *phydev);
+int genphy_read_status_fixed(struct phy_device *phydev);
 int genphy_read_status(struct phy_device *phydev);
 int genphy_suspend(struct phy_device *phydev);
 int genphy_resume(struct phy_device *phydev);