diff mbox series

PHY: Fix no autoneg corner case

Message ID m3plmhhx6d.fsf@t19.piap.pl (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series PHY: Fix no autoneg corner case | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 3 maintainers not CCed: andrew@lunn.ch linux@armlinux.org.uk hkallweit1@gmail.com
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
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: 4 this patch: 4
netdev/checkpatch warning CHECK: multiple assignments should be avoided
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 39 this patch: 39
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-11-27--12-00 (tests: 788)

Commit Message

Krzysztof Hałasa Nov. 27, 2024, 8:56 a.m. UTC
phydev->autoneg appears to indicate if autonegotiation is enabled or
not. Unfortunately it's initially set based on the supported capability
rather than the actual hw setting. While in most cases there is no
difference (i.e., autoneg is supported and on by default), certain
adapters (e.g. fiber optics) use fixed settings, configured in hardware.

Now autoneg flag is set only when it's supported and actually used.

Signed-off-by: Krzysztof Hałasa <khalasa@piap.pl>

Comments

Andrew Lunn Nov. 27, 2024, 5:37 p.m. UTC | #1
On Wed, Nov 27, 2024 at 09:56:42AM +0100, Krzysztof Hałasa wrote:
> phydev->autoneg appears to indicate if autonegotiation is enabled or
> not.

Correct.

> Unfortunately it's initially set based on the supported capability
> rather than the actual hw setting.

We need a clear definition of 'initially', and when does it actually
matter.

Initially, things like speed, duplex and set to UNKNOWN. They don't
make any sense until the link is up. phydev->advertise is set to
phydev->supported, so that we advertise all the capabilities of the
PHY. However, at probe, this does not really matter, it is only when
phy_start() is called is the hardware actually configured with what it
should advertise, or even if it should do auto-neg or not.

In the end, this might not matter.

> While in most cases there is no
> difference (i.e., autoneg is supported and on by default), certain
> adapters (e.g. fiber optics) use fixed settings, configured in hardware.

If the hardware is not capable of supporting autoneg, why is autoneg
in phydev->supported? To me, that is the real issue here.

	Andrew
diff mbox series

Patch

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 366cf3b2cbb0..6858f512558b 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -3453,7 +3453,7 @@  static int phy_probe(struct device *dev)
 	struct phy_device *phydev = to_phy_device(dev);
 	struct device_driver *drv = phydev->mdio.dev.driver;
 	struct phy_driver *phydrv = to_phy_driver(drv);
-	int err = 0;
+	int err = 0, bmcr;
 
 	phydev->drv = phydrv;
 
@@ -3495,8 +3495,12 @@  static int phy_probe(struct device *dev)
 	if (err)
 		goto out;
 
+	err = bmcr = phy_read(phydev, MII_BMCR);
+	if (err < 0)
+		goto out;
+
 	if (!linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
-			       phydev->supported))
+			       phydev->supported) || !(bmcr & BMCR_ANENABLE))
 		phydev->autoneg = 0;
 
 	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,