Skip to contentSkip to conversation

net: phy: improve genphy_c45_read_lpa

PATCH In review Heiner Kallweit 3 participants 6 messages Mar 31, 2019 – Apr 2, 2019

Subsystems (3)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

cover net: phy: improve genphy_c45_read_lpa

This series improves genphy_c45_read_lpa:
- Use clause 45 standard register / bit to detect link partner autoneg capability.
- Consider that lpa register values may be invalid if "autoneg complete" bit isn't set.

Heiner Kallweit (2):
net: phy: use c45 standard to detect link partner autoneg capability
net: phy: deal properly with autoneg incomplete in genphy_c45_read_lpa

 drivers/net/phy/phy-c45.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
Signature · 1 line
2.21.0
author maintainer
#1 lore raw

PATCH 1/2 net: phy: use c45 standard to detect link partner autoneg capability

Currently mii_lpa_mod_linkmode_lpa_t() checks bit LPA_LPACK to detect whether link partner supports autoneg. This doesn't work correctly at least on Aquantia AQCS109 when it negotiates 1000Base-T2 mode. The "link partner is autoneg-capable" bit as defined by clause 45 is set however. Better let's switch in general to use the clause 45 standard for link partner autoneg detection.

---
 drivers/net/phy/phy-c45.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/phy/phy-c45.c +8 -1
index 9e24d9569..666fbb0ee 100644
@@ -262,12 +262,19 @@ int genphy_c45_read_lpa(struct phy_device *phydev)
 {
 	int val;
 
+	val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_STAT1);
+	if (val < 0)
+		return val;
+
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->lp_advertising,
+			 val & MDIO_AN_STAT1_LPABLE);
+
 	/* Read the link partner's base page advertisement */
 	val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_LPA);
 	if (val < 0)
 		return val;
 
-	mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, val);
+	mii_adv_mod_linkmode_adv_t(phydev->lp_advertising, val);
 	phydev->pause = val & LPA_PAUSE_CAP ? 1 : 0;
 	phydev->asym_pause = val & LPA_PAUSE_ASYM ? 1 : 0;
 
Signature · 1 line
2.21.0
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH net-next 1/2] net: phy: use c45 standard to detect link partner autoneg capability

Quoted 8 lines · Heiner Kallweit

Currently mii_lpa_mod_linkmode_lpa_t() checks bit LPA_LPACK to detect whether link partner supports autoneg. This doesn't work correctly at least on Aquantia AQCS109 when it negotiates 1000Base-T2 mode. The "link partner is autoneg-capable" bit as defined by clause 45 is set however. Better let's switch in general to use the clause 45 standard for link partner autoneg detection.

Andrew

author maintainer
#3 lore raw

PATCH 2/2 net: phy: deal properly with autoneg incomplete in genphy_c45_read_lpa

In reply to Heiner Kallweit

The link partner advertisement registers are not guaranteed to contain valid values if autoneg is incomplete. Therefore, if MDIO_AN_STAT1_COMPLETE isn't set, let's clear all link partner capability bits. This also avoids unnecessary register reads if link is down and phylib is in polling mode.

---
 drivers/net/phy/phy-c45.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/phy/phy-c45.c +11 -0
index 666fbb0ee..05c3e87ff 100644
@@ -266,6 +266,17 @@ int genphy_c45_read_lpa(struct phy_device *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);
 
Signature · 1 line
2.21.0
maintainer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH net-next 2/2] net: phy: deal properly with autoneg incomplete in genphy_c45_read_lpa

Quoted 7 lines · Heiner Kallweit

The link partner advertisement registers are not guaranteed to contain valid values if autoneg is incomplete. Therefore, if MDIO_AN_STAT1_COMPLETE isn't set, let's clear all link partner capability bits. This also avoids unnecessary register reads if link is down and phylib is in polling mode.

Andrew

maintainer
#5 lore raw
In reply to Heiner Kallweit

From: Heiner Kallweit <[email protected]>
Date: Sun, 31 Mar 2019 19:51:45 +0200

Quoted 5 lines

This series improves genphy_c45_read_lpa:
- Use clause 45 standard register / bit to detect link partner autoneg capability.
- Consider that lpa register values may be invalid if "autoneg complete" bit isn't set.

Series applied, thanks Heiner.