lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220608122322.772950-2-o.rempel@pengutronix.de>
Date:   Wed,  8 Jun 2022 14:23:21 +0200
From:   Oleksij Rempel <o.rempel@...gutronix.de>
To:     Andrew Lunn <andrew@...n.ch>,
        Heiner Kallweit <hkallweit1@...il.com>,
        "David S. Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>,
        Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>,
        Jonathan Corbet <corbet@....net>,
        Michal Kubecek <mkubecek@...e.cz>
Cc:     Oleksij Rempel <o.rempel@...gutronix.de>, kernel@...gutronix.de,
        linux-kernel@...r.kernel.org, netdev@...r.kernel.org
Subject: [PATCH net-next v2 1/2] net: phy: move common code to separate genphy_c45_aneg_done_lp_clean() function

We already have genphy_c45_aneg_done(), so make use of it and introduce
new function to clean up variables in case aneg is not done.

Signed-off-by: Oleksij Rempel <o.rempel@...gutronix.de>
---
 drivers/net/phy/phy-c45.c | 52 +++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c
index 29b1df03f3e8..c67bf3060173 100644
--- a/drivers/net/phy/phy-c45.c
+++ b/drivers/net/phy/phy-c45.c
@@ -452,6 +452,28 @@ int genphy_c45_read_link(struct phy_device *phydev)
 }
 EXPORT_SYMBOL_GPL(genphy_c45_read_link);
 
+/* Read the Clause 45 AN status register to check if autoneg is complete.
+ * If not, clean link mode flags.
+ */
+static int genphy_c45_aneg_done_lp_clean(struct phy_device *phydev)
+{
+	int val;
+
+	val = genphy_c45_aneg_done(phydev);
+	/* If < 0, there is an error. If > 0 aneg is done*/
+	if (val)
+		return val;
+
+	linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->lp_advertising);
+	mii_t1_adv_l_mod_linkmode_t(phydev->lp_advertising, 0);
+	mii_t1_adv_m_mod_linkmode_t(phydev->lp_advertising, 0);
+
+	phydev->pause = 0;
+	phydev->asym_pause = 0;
+
+	return 0;
+}
+
 /* Read the Clause 45 defined BASE-T1 AN (7.513) status register to check
  * if autoneg is complete. If so read the BASE-T1 Autonegotiation
  * Advertisement registers filling in the link partner advertisement,
@@ -461,21 +483,10 @@ static int genphy_c45_baset1_read_lpa(struct phy_device *phydev)
 {
 	int val;
 
-	val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_T1_STAT);
-	if (val < 0)
+	val = genphy_c45_aneg_done_lp_clean(phydev);
+	if (val <= 0)
 		return val;
 
-	if (!(val & MDIO_AN_STAT1_COMPLETE)) {
-		linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->lp_advertising);
-		mii_t1_adv_l_mod_linkmode_t(phydev->lp_advertising, 0);
-		mii_t1_adv_m_mod_linkmode_t(phydev->lp_advertising, 0);
-
-		phydev->pause = 0;
-		phydev->asym_pause = 0;
-
-		return 0;
-	}
-
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->lp_advertising, 1);
 
 	val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_T1_LP_L);
@@ -512,21 +523,10 @@ int genphy_c45_read_lpa(struct phy_device *phydev)
 	if (genphy_c45_baset1_able(phydev))
 		return genphy_c45_baset1_read_lpa(phydev);
 
-	val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_STAT1);
-	if (val < 0)
+	val = genphy_c45_aneg_done_lp_clean(phydev);
+	if (val <= 0)
 		return val;
 
-	if (!(val & MDIO_AN_STAT1_COMPLETE)) {
-		linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
-				   phydev->lp_advertising);
-		mii_10gbt_stat_mod_linkmode_lpa_t(phydev->lp_advertising, 0);
-		mii_adv_mod_linkmode_adv_t(phydev->lp_advertising, 0);
-		phydev->pause = 0;
-		phydev->asym_pause = 0;
-
-		return 0;
-	}
-
 	linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->lp_advertising,
 			 val & MDIO_AN_STAT1_LPABLE);
 
-- 
2.30.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ