From patchwork Wed Nov 27 08:56:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Ha=C5=82asa?= X-Patchwork-Id: 13886718 X-Patchwork-Delegate: kuba@kernel.org Received: from ni.piap.pl (ni.piap.pl [195.187.100.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44EA0189919; Wed, 27 Nov 2024 08:56:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.187.100.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732697807; cv=none; b=R5K5SqLJgE2izY7Ka81b1sdpO5kuvEyPtTrJ/9joImVKpauCuWsbzPyD97BG1/Lx9ep0oUcZ/gUv1Shf94hpqrmxU5BBRrQsfTcccqw+q1GUNN+e/EzMW2mISjZVGEJyUADeT9bOcWfvt2Mqk6QAjBG1i5GsgAnmGZBqvqrFnF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732697807; c=relaxed/simple; bh=VIcHmDDOxRDLoUecxyIPqKRaoRticSvdvMburslHBy8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=rdNLJbOgPGrd33h5yXCrpgSE6V46O1MVw+OEWKM3fqpUK/kt2O9DQ/D3LzRTpoOJm9QSdTskOLHmDdsP5xOT9IHoqMh6C92O111tMWYrFfsPLM/THoW6tjFa1i7KtsHv6QM3DQ9EYzGP7rRU/qxaOrOlmpcc1hkHRpo8jpvpQ1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=piap.pl; spf=pass smtp.mailfrom=piap.pl; arc=none smtp.client-ip=195.187.100.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=piap.pl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=piap.pl Received: from t19.piap.pl (OSB1819.piap.pl [10.0.9.19]) by ni.piap.pl (Postfix) with ESMTPS id C95FDC3EEACB; Wed, 27 Nov 2024 09:56:42 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 ni.piap.pl C95FDC3EEACB From: =?utf-8?q?Krzysztof_Ha=C5=82asa?= To: netdev Cc: Oliver Neukum , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Jose Ignacio Tornos Martinez , Ming Lei Subject: [PATCH] PHY: Fix no autoneg corner case Sender: khalasa@piap.pl Date: Wed, 27 Nov 2024 09:56:42 +0100 Message-ID: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 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,