🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24099

Re: [PATCH] net: phy: motorcomm: add downshift tunable support for YT8531/YT8531S

#24099
From: netdev-bot+sashiko
Date: Sun, 29 Nov 2026 09:10
179 lines
14195 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The patch adds .get_tunable/.set_tunable to the PHY_ID_YT8531
  entry of motorcomm_phy_drvs[].
- [Medium] yt8531_set_downshift() commits the SADCR change by writing
  BMCR_RESET to the UTP-space BMCR with yt8521_modify_bmcr_paged(phydev,…
- [Low] In yt8521_modify_bmcr_paged(), if BMCR_RESET has not self-cleared
  after the ~500 iterations of usleep_range(1000,1100), the loop exits…

--

net: phy: motorcomm: add downshift tunable support for YT8531/YT8531S

This commit exposes the YT8531/YT8531S Speed Auto Downgrade feature as the
ETHTOOL_PHY_DOWNSHIFT tunable. The retry limit is written to the Speed Auto
Downgrade Control Register in the UTP space. It is then committed with a
UTP-space BMCR software reset through yt8521_modify_bmcr_paged().

> diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
> index a87e83fdf590c..08bf8441fbd4e 100644
> --- a/drivers/net/phy/motorcomm.c
> +++ b/drivers/net/phy/motorcomm.c

[ ... ]

> @@ -1205,6 +1208,96 @@ static int yt8521_probe(struct phy_device *phydev)

[ ... ]

> +static int yt8531_set_downshift(struct phy_device *phydev, u8 cnt)
> +{

[ ... ]

> +	/* 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);

[Severity: Medium]
Can this reset leave the copper side out of sync with what phylib thinks
the PHY is doing?

Under Clause 22, a BMCR reset puts the control register back to its
defaults: autoneg enabled, default speed/duplex, power down cleared.
genphy_soft_reset() handles this after the reset:

drivers/net/phy/phy_device.c:genphy_soft_reset() {
    ...
	phydev->suspended = 0;

	ret = phy_poll_reset(phydev);
	if (ret)
		return ret;

	/* BMCR may be reset to defaults */
	if (phydev->autoneg == AUTONEG_DISABLE)
		ret = genphy_setup_forced(phydev);
    ...
}

Here only the BMCR_RESET bit is polled. set_phy_tunable() only calls
drv->set_tunable under phydev->lock and does not re-run config_aneg.

Assuming the UTP BMCR reset behaves like a standard Clause 22 reset,
suppose the link was forced with "ethtool -s ethX autoneg off speed 100
duplex full" and the downshift tunable is set afterwards. Would the PHY go
back to autonegotiation while phylib still treats the link as forced?
Against a forced link partner, that could cause a duplex mismatch or no
link at all.

The suspend case is similar. After phy_stop(), the state machine calls
phy_suspend()->yt8521_suspend(), which sets BMCR_PDOWN in the UTP space.
If the tunable is changed while the interface is down, would PDOWN be
cleared and the copper side powered back up while phydev->suspended is
still set?

[Severity: Low]
What does the caller see if BMCR_RESET never self-clears? In
yt8521_modify_bmcr_paged(), the poll loop exits with ret still holding the
last BMCR value it read:

	if (set == BMCR_RESET) {
		while (max_cnt--) {
			usleep_range(1000, 1100);
			ret = __phy_read(phydev, MII_BMCR);
			if (ret < 0)
				goto err_restore_page;

			if (!(ret & BMCR_RESET))
				return phy_restore_page(phydev, old_page, 0);
		}
	}

err_restore_page:
	return phy_restore_page(phydev, old_page, ret);

phy_restore_page() returns a non-negative ret unchanged. The existing
caller, yt8521_modify_utp_fiber_bmcr(), turns that into 0. Here the
positive value goes straight back through set_phy_tunable() as the ioctl
return value.

ethtool only treats err < 0 as an error, so would a reset timeout be
reported as success? Would returning -ETIMEDOUT on that path make more
sense?

[ ... ]

> @@ -3280,6 +3373,8 @@ static struct phy_driver motorcomm_phy_drvs[] = {
>  	},
>  	{
>  		PHY_ID_MATCH_EXACT(PHY_ID_YT8531),
> +		.get_tunable	= yt8531_get_tunable,
> +		.set_tunable	= yt8531_set_tunable,
>  		.name		= "YT8531 Gigabit Ethernet",
>  		.probe		= yt8531_probe,
>  		.config_init	= yt8531_config_init,

[Severity: High]
Does the downshift tunable work at all on the YT8531? This entry has no
.read_page or .write_page callback, but both new callbacks use the paged
helpers:

yt8531_get_tunable()
  yt8531_get_downshift()
    phy_read_paged()
      phy_select_page()
        phy_save_page()
          __phy_read_page()

drivers/net/phy/phy-core.c:__phy_read_page() {
	if (WARN_ONCE(!phydev->drv->read_page, "read_page callback not available, PHY driver not loaded?\n"))
		return -EOPNOTSUPP;
    ...
}

The set path has the same problem. phy_modify_paged() and
yt8521_modify_bmcr_paged() both go through phy_select_page().

So on a YT8531 (non-S), every get or set would return -EOPNOTSUPP, and the
first call would print a WARN splat. The comment in
yt8531_set_downshift() says "Both helpers manage their own paged access
window", which does not seem to hold for this entry. The commit message
also mentions testing only on a YT8531S.

ETHTOOL_PHY_GTUNABLE is also on the list that skips the CAP_NET_ADMIN check
in __dev_ethtool(). That means an unprivileged "ethtool --get-phy-tunable
ethX downshift" can trigger the WARN, and on a panic_on_warn system that
panics the machine.

There are two possible fixes. If the 0xA000 space select register is
valid on the YT8531, the entry could get .read_page/.write_page.
Otherwise, the UTP-only YT8531 could use plain
phy_read()/phy_modify()/genphy_soft_reset() instead.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125085509.1844883-1-mjkchengke%40163.com
Technical Details
Message-ID: <179594341431.3146.13055685725510422390@kernel.org>
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-373428-linux-kernel-netdev=dewy.ru
References: <20261125085509.1844883-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-373428-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH] net: phy: motorcomm: add downshift tunable support for
 YT8531/YT8531S
Date: Sun, 29 Nov 2026 09:10:14 +0000
Organization: Usenet Network
Message-ID: <179594341431.3146.13055685725510422390@kernel.org>
References: <20261125085509.1844883-1-mjkchengke@163.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1138667"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:/USpzBiCqtZNJbUQA+9JaTPkkxY= sha256:MGtGe8dtKwZMansAOxn/V/zTlJf7ifVIrif6O+2AiyE=
	sha1:Tlc3sSg8Kg20l0uwUPigdEvZNqw= sha256:fgMgPH+T5WmgvPJJGqEAwYK0/tqPZiM5wDBceOL/qz8=
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 1BBD8125F96; Sun, 29 Nov 2026 12:10:33 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
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 2WLn3lGX5jku;
	Sun, 29 Nov 2026 12:10:29 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373428-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 9B22E125F94; Sun, 29 Nov 2026 12:10:19 +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 B708924160; Sun, 29 Nov 2026 09:10:16 +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=1795943416;
	b=qkqmZ56PsuG5HH/q5G4ybcNXz+lhAVXKk7Y01psJSuSNTTeSwx6HzNZQ29U+3HYW2ZiJ
	 2iVfkOnDiBf197xvgZD3LgTidTo7ck3tIDGr5zp7CIWsLZ+RKm7AAUFEsy0HSDZlATaII
	 FZc/jWLoZg6yJ4ihb3WAlQcHtVBlDGKU9LYpPNEzX6a0JYWNuYmO4iVCR7EP7qJGVRVTI
	 mg6fUo44T3j5uP4QspqrVcwG9RGIbVcgY82CvBZl4aF5SfZ0IPslAzJMnvoEgL3Kj6H1j
	 gpiYoRkfj4fpBPkfBC1ER4CudIOw7Un6YFdc2DAmFHIj6kYmkc/wNngSmv4J9FJaC4Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795943416;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=n0lw3/WmK69kymQ3ocGh/9cZq9bgYshVue1jd8rY/0s=;
	b=q59mAgQBedF+lWK7KdL8LS3ShNUnaGT5zObSq/rRUqkkNuuNQxYOiIPp2NXwmoV1K7fF
	 C4xVOjqd7gGbSDENFNQb7+Nm6KMSY19OSVCNe+lTp/B84I0XchYyxORicvkeZW4s7O3Wn
	 MoGQ8wwSnbqNGKVkXgrUHJooYzZsJfA/XKEIwSdQXn5cB0LybLEmhtcZFozXYLKh2dYGB
	 sj/t/+I1xR4nKYravwusTZqNosXgmmSmZ4hYYwHBKuCqqxyyLwLua1h5+jeMzKF5ruuWh
	 Pu3q/QckhdN6E3eJWSi0DjdfKf5xQcIJKyYG7+M1czDpVO8OJ1BkX8AovDySjzwfHHw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NbCU97Jk;
	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 8E51C606A32C;
	Sun, 29 Nov 2026 09:10:16 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NbCU97Jk
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795943415;
	b=b1hwT+5olh5b5PK5XI7sssAZQ8BH0rHO/edMyqBZ1SHr30fMBs6/RmL/N6nPLHSH3R3l
	 jcItlNGCCU8IjkgfE5SIlnIVyWEap1t2hSrCW/PFmm9PeDXTs+WI0HgaVvRB/5NsXyD0M
	 U2iZtmO2iT9tAudHIwHjgTCvhHgi+pWATCn8FbwzfHV8Mc/2yMdBKcpmQzmIOJpp0Go5S
	 LPkcHD65nR3rpqHwnVdkojQgGwfZzicmiuGRJ7tAdoG/8DaYwRjIToJPhlcwu2fb0wiLH
	 JroaCS1jlnFxAw6G5pa06cyiNBKpVW9D4gPuXKreoBNVlZsVQlTNHjKSOojfVyF8RAA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795943415;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=n0lw3/WmK69kymQ3ocGh/9cZq9bgYshVue1jd8rY/0s=;
	b=OPU22uGcr61/f9isYi6sQ4wj2vRQTeO1PI2DlHEkKBdIw5Ttww/2CeDCZz2yzImOYS/J
	 zPv1YMjPmg28JZGijVj2VdjdfwV42TXls/9GOvKJGpMzU1XZ6S1mboDAk6GGGFYPstNGG
	 oV8L0en/lqOXhNMK6LPYmgodHgBW3Y6mkzytIfbtJgEdk3IVRxK2Hta22nFhxFIb8f2yX
	 K48p8XwuOlFARkCr4YFaOQuerqwARE1a1NcWObtNrlM3UdKGtd2hiSZEDa9tHuFt6tflg
	 O/bwehH70qdlaN8GW70xOnD9h9BuzsqvdoYEkhzNQcgypz1b2NlTWsEHDzVYhUcXkpA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NbCU97Jk;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACD0F606A31C
	for <netdev@vger.kernel.org>; Sun, 29 Nov 2026 09:10:15 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5E081F00898;
	Sun, 29 Nov 2026 09:10:14 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795943415;
	bh=n0lw3/WmK69kymQ3ocGh/9cZq9bgYshVue1jd8rY/0s=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=NbCU97JkOx1Bz1A5k4e5wdeZAJdxMrq6JVAOLBDS/TNO1uyHQMrPQ9k5Wo2VgR95A
	 UVfjuuS6ClEKdNdkSBRFLq7sYyXJs4PYImqpR/GiSjcmvtR03K46J4Ot3qC1tOCW5l
	 KKO+DWJTGoNjS4Hr/XwYi43BZOk3iSppsZnAkn7XrK5M+APUkNMm73Kbg7uwBhYHqm
	 HZc2yl0b0H7IcoyVAeLWGiZU+ODlhWH9SFyeG3UmaJr6VVBf0Qm/dWmzJ/GDJTDY5g
	 wYSQGIMU9KgvlRuJf+CdzfhcvhrWczUcbzFyhQErq4hJw5DlcbZSPsq1HmpQMe9BsF
	 ijxEAOGVAn3wg==
X-Cc: Frank.Sae@motor-comm.com, netdev@vger.kernel.org, andrew@lunn.ch,
 hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net,
 edumazet@google.com, kuba@kernel.org, pabeni@redhat.com
X-In-Reply-To: <20261125085509.1844883-1-mjkchengke@163.com>
X-sashiko-severity: High
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