🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #22411

[PATCH v2 2/2] net: phy: motorcomm: add downshift tunable support for YT8531S

#22411
From: ck
Date: Wed, 25 Nov 2026 09:16
170 lines
14374 bytes
The YT8531S supports Ethernet Line Speed Auto Downgrade: when
autonegotiation fails to establish a link after a configurable number
of attempts, the PHY downgrades to a lower speed and retries. The
number of attempts before downgrading is configured through the Speed
Auto Downgrade Control Register (0x14), bits 4:2, and the feature is
enabled through bit 5 of the same register.

Expose this as the ETHTOOL_PHY_DOWNSHIFT tunable for the YT8531S,
following the semantics used by other drivers: the tunable value is
the number of autonegotiation attempts before downgrading (range
2-9), 0 disables the feature, and DOWNSHIFT_DEV_DEFAULT_COUNT restores
the power-on default of 5 attempts.

The retry-limit field stores (attempts - 2) and only takes effect
after a software reset of the UTP register space. genphy_soft_reset()
resets the BMCR of the currently selected register space only, and
the YT8531S powers up with the fiber space selected, so use the
existing yt8521_modify_bmcr_paged() helper to reset the UTP space
explicitly. This also relies on the previous fix, which makes the
helper report a timeout instead of a stale positive BMCR value.

Hardware-validated on a Phytium D2000 board with a YT8531S: setting
8 and 2 attempts, restoring the default, and disabling all commit
correctly to register 0x14; out-of-range values are rejected with
-ERANGE.

Signed-off-by: chengke <mjkchengke@163.com>
---
Changes in v2:
- Attach the tunable ops to the YT8531S entry only: YT8531 has no
  .read_page/.write_page, so paged helpers would WARN_ONCE and fail
  with -EOPNOTSUPP on it (found in self-review).
- Drop the forward declaration by moving the new functions below
  yt8521_modify_bmcr_paged().
- Reuse the existing YTPHY_SADCR_SPEED_RETRY_LIMIT macro for the
  default value instead of a magic number.
- Use kernel-style multi-line comments.
 drivers/net/phy/motorcomm.c | 96 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 95 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
index ba3421ca4d..8de87897bc 100644
--- a/drivers/net/phy/motorcomm.c
+++ b/drivers/net/phy/motorcomm.c
@@ -97,6 +97,9 @@
  */
 #define YTPHY_SADCR_SPEED_RETRY_LIMIT		(0x3 << 2)
 
+#define YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK		GENMASK(4, 2)
+#define YTPHY_SADCR_DOWNSHIFT_ATTEMPTS_MIN		2
+#define YTPHY_SADCR_DOWNSHIFT_ATTEMPTS_MAX		9
 /* Rx Error Counter Register */
 #define YTPHY_RX_ERROR_COUNTER_REG		0x15
 
@@ -1595,13 +1598,102 @@ static int yt8521_modify_bmcr_paged(struct phy_device *phydev, int page,
 			if (!(ret & BMCR_RESET))
 				return phy_restore_page(phydev, old_page, 0);
 		}
-		ret = -ETIMEDOUT;
 	}
 
 err_restore_page:
 	return phy_restore_page(phydev, old_page, ret);
 }
 
+static int yt8531s_get_downshift(struct phy_device *phydev, u8 *data)
+{
+	int val, cnt, enable;
+
+	val = phy_read_paged(phydev, YT8521_RSSR_UTP_SPACE,
+			     YTPHY_SPEED_AUTO_DOWNGRADE_CONTROL_REG);
+	if (val < 0)
+		return val;
+
+	enable = FIELD_GET(YTPHY_SADCR_SPEED_DOWNGRADE_EN, val);
+	/*
+	 * The retry limit field stores (attempts - 2): the default 0x3
+	 * means 5 attempts before downgrading.
+	 */
+	cnt = FIELD_GET(YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK, val) + 2;
+
+	*data = enable ? cnt : DOWNSHIFT_DEV_DISABLE;
+
+	return 0;
+}
+
+static int yt8531s_set_downshift(struct phy_device *phydev, u8 cnt)
+{
+	u16 mask, set;
+	int err;
+
+	if (cnt == DOWNSHIFT_DEV_DEFAULT_COUNT) {
+		/* Restore the power-on default: enabled, 5 attempts */
+		mask = YTPHY_SADCR_SPEED_DOWNGRADE_EN |
+		       YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK;
+		set = YTPHY_SADCR_SPEED_DOWNGRADE_EN |
+		      YTPHY_SADCR_SPEED_RETRY_LIMIT;
+	} else if (!cnt) {
+		mask = YTPHY_SADCR_SPEED_DOWNGRADE_EN;
+		set = 0;
+	} else {
+		/*
+		 * The tunable value is the number of autoneg attempts
+		 * before downgrading, in range [2, 9]. The register
+		 * field stores (cnt - 2).
+		 */
+		if (cnt < YTPHY_SADCR_DOWNSHIFT_ATTEMPTS_MIN ||
+		    cnt > YTPHY_SADCR_DOWNSHIFT_ATTEMPTS_MAX)
+			return -ERANGE;
+
+		mask = YTPHY_SADCR_SPEED_DOWNGRADE_EN |
+		       YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK;
+		set = YTPHY_SADCR_SPEED_DOWNGRADE_EN |
+		      FIELD_PREP(YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK, cnt - 2);
+	}
+
+	/*
+	 * The SADCR change is only committed by a UTP-space software reset.
+	 * genphy_soft_reset() resets the BMCR of the currently selected
+	 * register space only, and YT8531S powers up with the fiber space
+	 * selected, so reset the UTP space explicitly. Both helpers manage
+	 * their own paged access window.
+	 */
+	err = phy_modify_paged(phydev, YT8521_RSSR_UTP_SPACE,
+			       YTPHY_SPEED_AUTO_DOWNGRADE_CONTROL_REG,
+			       mask, set);
+	if (err < 0)
+		return err;
+
+	return yt8521_modify_bmcr_paged(phydev, YT8521_RSSR_UTP_SPACE,
+					0, BMCR_RESET);
+}
+
+static int yt8531s_get_tunable(struct phy_device *phydev,
+			       struct ethtool_tunable *tuna, void *data)
+{
+	switch (tuna->id) {
+	case ETHTOOL_PHY_DOWNSHIFT:
+		return yt8531s_get_downshift(phydev, data);
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int yt8531s_set_tunable(struct phy_device *phydev,
+			       struct ethtool_tunable *tuna,
+			       const void *data)
+{
+	if (tuna->id != ETHTOOL_PHY_DOWNSHIFT ||
+	    tuna->len != sizeof(u8))
+		return -EOPNOTSUPP;
+
+	return yt8531s_set_downshift(phydev, *(const u8 *)data);
+}
+
 /**
  * yt8521_modify_utp_fiber_bmcr - bits modify a PHY's BMCR register
  * @phydev: the phy_device struct
@@ -3295,6 +3387,8 @@ static struct phy_driver motorcomm_phy_drvs[] = {
 	},
 	{
 		PHY_ID_MATCH_EXACT(PHY_ID_YT8531S),
+		.get_tunable	= yt8531s_get_tunable,
+		.set_tunable	= yt8531s_set_tunable,
 		.name		= "YT8531S Gigabit Ethernet",
 		.get_features	= yt8521_get_features,
 		.probe		= yt8521_probe,
-- 
2.43.0
Technical Details
Message-ID: <20261125091638.1847020-2-mjkchengke@163.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371179-linux-kernel-netdev=dewy.ru
References: <20261125085509.1844883-1-mjkchengke@163.com> <20261125091638.1847020-1-mjkchengke@163.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371179-linux-kernel-netdev=dewy.ru
From: mjkchengke@163.com (ck)
Newsgroups: linux.kernel.netdev
Subject: [PATCH v2 2/2] net: phy: motorcomm: add downshift tunable support for YT8531S
Date: Wed, 25 Nov 2026 17:16:38 +0800
Organization: Usenet Network
Message-ID: <20261125091638.1847020-2-mjkchengke@163.com>
References: <20261125085509.1844883-1-mjkchengke@163.com>
 <20261125091638.1847020-1-mjkchengke@163.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="165482"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:hBhU8geYqlWP5GtVZLXRyIboJI8= sha256:a0v3d/Yk2PGipKxQcQRWkOfWQwAnp+/snCPBWTLjMeo=
	sha1:40sj/779siZMBh3amWSFipDf2BE= sha256:vT/tZkzWZaVecWBUS1AdPEKJtbXfMUPE3033FXMc0sQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 4FD6A125E4E; Wed, 25 Nov 2026 12:17:52 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=163.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id frvEDMpHVyQ5;
	Wed, 25 Nov 2026 12:17:49 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-371179-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=163.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 8ED87125E4F; Wed, 25 Nov 2026 12:17:39 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 9D96144E04; Wed, 25 Nov 2026 09:17:37 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795598257;
	b=w7Lmsx6AptYmasKkV1aN1ZFmDyJ/8Zs84AzapxZQ+4qlqEy9yXBPhgQzlzFe97oAcHlw
	 b0tq0xhjx4lplvZzp4FOwh+x6fAOQyttW3hy1SIINlrFlq1QLYqyKdteaWYsZqqclSaFC
	 s2+E/xX32v0FbX5PRqWpGX6ujXs1CPcTicNAQXbpvmdoToGTaf/YS1Dqz39+y3YQ4YFMU
	 B/O8ySiNTPjUc+4b0vfZCQY637Ewumn0WZt8YYjC0P0PPpibSJo3TD01qr6mrvBEaWC5L
	 90OKcjwR/3PIvXIY4D5UJr5Aov4KEwCwZJCFk3sao9WE6JguG2HLVTR70YPdXtr7lCg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795598257;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:To:
	 Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam:
	 X-CM-SenderInfo;
	bh=hliRKX8zoIGstLXpicFYA1Ddk8Ts9p/5d3C0zw57QnY=;
	b=pULIDg3MmSqQEgJ8axVSPa1pGwvqMTrjlvpo3t3wZxF+5zXXNV7cYFBYUig1w0Ba5lpL
	 29fWn3nFFXAfb8b9BgCkYAiz0CUBKNjbLJCzmnAkQBWZM2hjfvwkjIcYmMD4EQFBtB+1V
	 vdsYm/zWUa8S221J4z/7jXCsNJ6g1zen/Wc1I9Rq4nAEtY8QICvyU6eYC0pAL5yHSPlo3
	 wJvLJRlu+wsghavPVupYvsgGDYKZemt9aDEN6EJCZvnKZNaAw/RkO8XdQuiZ9oUbXgoxz
	 wDdNHmjEjyaQ6w714s29otEvgFVFtE2qWrOLMgmkdhe1F3U0x3iBTFKQRTCas9FOftA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=GuccS2Bc;
	dmarc=pass header.from=163.com;
	spf=pass smtp.mailfrom=163.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B7B7606A698;
	Wed, 25 Nov 2026 09:17:37 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=GuccS2Bc
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.3
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795598256;
	b=e1Dc5sPAS9cyiAfh6YTn7fr2lim/EmjUkk1mtq5qzyEoDQt1wbN/57rnAKiP8KlMGSpU
	 15nfUdhVriepk2yD4DMco/VGxMv6l20cao6NPL+f7BgnNSYHSB8tBpWiwAxLpKfJVbJwQ
	 UgFuR4FbBnDT2EghfXjlL5LBhr1JkjUPLM3sbq6vLMo4PvnhCWLXmnUDvOnz8mUJuD74F
	 ohyRSdCev5cK7SymUqp5sckBSIMy/5Et+a43k2ySs1IbKYojdGnyfgmQtPQ6TC57+2uai
	 YF3oNHKzsOWAcTVdNzbWV64tJ8vgk9ZnIDK3Kcf8bz1SPIHWPKQ4o9zqXqtUA2MN0Aw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795598256;
	h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam:
	 X-CM-SenderInfo;
	bh=hliRKX8zoIGstLXpicFYA1Ddk8Ts9p/5d3C0zw57QnY=;
	b=E3u2C7r1fdU4+gGcL4F0OIkv0EQv6pfUwf4RdXFb+HnXRBAwaLrLob3uMfZ6spUOOlw7
	 zkdN4/kuLqLDmeTczIom/oMHehA1iFeCkoZbg5QPXqO/Y7J7ixrqEwuclYmB7XgO1Q8mD
	 uwXLQOLX4bHv3S44ZDud+T/4IC1cqkmNXFSBFDgXeMPa5ozetpbXapfRbxb4HuLmid20j
	 5hFSbE/WiLdXPdMmDvHfbRQE7iLI/HXP0enlNjokH2JQ5zlBug16jcikq2Cgc3xWOeYco
	 Z4zGYolzH1Z869bDxGOsJJGWVVKvPWDzt6jRahP/XHwXahIiDz2Nep0ljtowjKIVYCQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=163.com;
	spf=pass smtp.mailfrom=163.com;
	dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=GuccS2Bc;
	arc=none smtp.remote-ip=220.197.31.3
X-Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8A92606A684
	for <netdev@vger.kernel.org>; Wed, 25 Nov 2026 09:17:34 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B8A92606A684
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com;
	s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=hl
	iRKX8zoIGstLXpicFYA1Ddk8Ts9p/5d3C0zw57QnY=; b=GuccS2BcW6GP/d+NJl
	W1wbQ+TfEQTWeJB0ZgVjhESDCh4pH6J5uNKbnFshdVjvFhvYeiPpvsulRrUK6TrW
	yOTzby/YzXPtZ2mQmNKY7H4Mnxl8BAYfxf0UYHa39535ktwDHcjCwKZm4KU8H1FK
	dtK2utysVgKl0ra3BLkBrxPwc=
X-Received: from ck.. (unknown [])
	by gzga-smtp-mtada-g0-1 (Coremail) with SMTP id _____wAnBhJ2pwZr3Vt1KA--.4721S3;
	Wed, 25 Nov 2026 17:16:39 +0800 (CST)
X-Cc: andrew@lunn.ch,
	hkallweit1@gmail.com,
	linux@armlinux.org.uk,
	davem@davemloft.net,
	edumazet@google.com,
	kuba@kernel.org,
	pabeni@redhat.com,
	mjkchengke@163.com
X-Mailer: git-send-email 2.43.0
X-In-Reply-To: <20261125091638.1847020-1-mjkchengke@163.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-CM-TRANSID: _____wAnBhJ2pwZr3Vt1KA--.4721S3
X-Coremail-Antispam: 1Uf129KBjvJXoW3GFW8Wr18Xr4ftFWfur48WFg_yoW7tr1Dpr
	WfJF92yrZFqF47Kr4ftw4kAFWF9r4SkayUur9rG34Yva4YgF97ta1rtr1DtF97CrWkWFW3
	Gr47XFWDu3W3ZrUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2
	9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zMVbyUUUUUU=
X-CM-SenderInfo: ppmnux5hqjyvi6rwjhhfrp/xtbC1BdjsWsGp3coVAAA3Q