diff mbox series

[net-next,v2,1/2] net: phy: move common code to separate genphy_c45_aneg_done_lp_clean() function

Message ID 20220608122322.772950-2-o.rempel@pengutronix.de (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: add remote fault support | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 1 maintainers not CCed: linux@armlinux.org.uk
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: line length of 82 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Oleksij Rempel June 8, 2022, 12:23 p.m. UTC
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@pengutronix.de>
---
 drivers/net/phy/phy-c45.c | 52 +++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 26 deletions(-)
diff mbox series

Patch

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);