mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yongzhao Chen <yongzhao.derek@gmail.com>
To: netdev@vger.kernel.org
Cc: Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next] net: phy: qca83xx: read resolved QCA8337 link status
Date: Tue, 29 Sep 2026 00:07:49 +0200	[thread overview]
Message-ID: <20260928220749.857-1-yongzhao.derek@gmail.com> (raw)

Read QCA8337's vendor status on each autonegotiated link check so the
reported speed matches the PHY after SmartSpeed changes negotiation.
Keep link down while that status is unresolved or encodes a reserved
speed; PHYLIB then notifies its consumers when valid status returns.
Forced mode continues to use the generic BMCR result.

Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Yongzhao Chen <yongzhao.derek@gmail.com>
Assisted-by: LLM
---
Andrew suggested this in his review of RFC v3 4/5, where he noted that
read_status should report the real speed from the vendor register.
Thanks, Andrew. I mentioned this change in the same thread:
https://lore.kernel.org/netdev/20260924234814.1734-1-yongzhao.derek@gmail.com/

It does not depend on the qca8k series and applies to net-next on its own.

Testing: a model test compiles this function with the real
genphy_read_status(), phy_resolve_aneg_pause(), phy_read_status() and
phy_check_link_status() and covers 10/100/1000 in both duplexes,
unresolved and reserved speed codes, a speed change while the link
stays up, forced mode, pause resolution and MDIO read errors. W=1
builds for arm64 are clean. The same function is in my OpenWrt Linux
6.18.52 build for a Redmi AX5400 (QCA8337), including the build used
to test the at803x IPQ5018 fixes. I have not injected a real SmartSpeed
downshift on a user port.

 drivers/net/phy/qcom/qca83xx.c | 49 ++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/drivers/net/phy/qcom/qca83xx.c b/drivers/net/phy/qcom/qca83xx.c
index bc70ed8efd8..b3f3183d4a4 100644
--- a/drivers/net/phy/qcom/qca83xx.c
+++ b/drivers/net/phy/qcom/qca83xx.c
@@ -92,6 +92,54 @@ static int qca83xx_probe(struct phy_device *phydev)
 	return 0;
 }
 
+static int qca8337_read_status(struct phy_device *phydev)
+{
+	int ret, ss;
+
+	ret = genphy_read_status(phydev);
+	if (ret)
+		return ret;
+	if (phydev->autoneg == AUTONEG_DISABLE)
+		return 0;
+
+	phydev->speed = SPEED_UNKNOWN;
+	phydev->duplex = DUPLEX_UNKNOWN;
+	phydev->pause = false;
+	phydev->asym_pause = false;
+	if (!phydev->link)
+		return 0;
+
+	/* SmartSpeed can make the actual speed differ from the advertised modes. */
+	ss = phy_read(phydev, AT803X_SPECIFIC_STATUS);
+	if (ss < 0)
+		return ss;
+	if (!(ss & AT803X_SS_SPEED_DUPLEX_RESOLVED)) {
+		phydev->link = 0;
+		return 0;
+	}
+
+	switch ((ss & AT803X_SS_SPEED_MASK) >> 14) {
+	case AT803X_SS_SPEED_10:
+		phydev->speed = SPEED_10;
+		break;
+	case AT803X_SS_SPEED_100:
+		phydev->speed = SPEED_100;
+		break;
+	case AT803X_SS_SPEED_1000:
+		phydev->speed = SPEED_1000;
+		break;
+	default:
+		phydev->link = 0;
+		return 0;
+	}
+
+	phydev->duplex = ss & AT803X_SS_DUPLEX ? DUPLEX_FULL : DUPLEX_HALF;
+	if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete)
+		phy_resolve_aneg_pause(phydev);
+
+	return 0;
+}
+
 static int qca83xx_config_init(struct phy_device *phydev)
 {
 	u8 switch_revision;
@@ -220,6 +268,7 @@ static struct phy_driver qca83xx_driver[] = {
 	.flags			= PHY_IS_INTERNAL,
 	.config_init		= qca83xx_config_init,
 	.soft_reset		= genphy_soft_reset,
+	.read_status		= qca8337_read_status,
 	.get_sset_count		= qca83xx_get_sset_count,
 	.get_strings		= qca83xx_get_strings,
 	.get_stats		= qca83xx_get_stats,

base-commit: 014d795c73837ea2339a4ea8e8f82c6e959b845d
-- 
2.43.0


             reply	other threads:[~2026-09-28 22:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 22:07 Yongzhao Chen [this message]
2026-09-29  0:40 ` Andrew Lunn
2026-09-30 21:23   ` Yongzhao Chen
2026-09-30 21:33     ` Andrew Lunn
2026-10-01 18:16       ` Yongzhao Chen
2026-10-01 18:46         ` Andrew Lunn
2026-10-02 20:35           ` Yongzhao Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260928220749.857-1-yongzhao.derek@gmail.com \
    --to=yongzhao.derek@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®