🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27249

Re: [PATCH net-next v5 2/3] net: mdio: Add Cortina CS7542 bus controller

#27249
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 04:49
196 lines
15842 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 3 · Low: 0

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).

- [Medium] cs75xx_mdio_probe() (drivers/net/mdio/mdio-cs75xx.c:96-98)
  keeps whatever MDC prescaler is in PER_MDIO_CFG[31:16] and never…
- [Medium] When cs75xx_mdio_wait() (drivers/net/mdio/mdio-cs75xx.c:31-41)
  times out, it returns -ETIMEDOUT and leaves the hardware alone.
- [Medium] net: mdio: cs75xx_mdio_wait() uses 1 us sleep in
  readl_poll_timeout()

--

net: mdio: Add Cortina CS7542 bus controller

This adds a platform driver for the Cortina CS7542 MDIO controller that
supports Clause 22 reads and writes. Probe enables the APB clock and
switches the controller to manual mode, keeping the firmware-configured
MDC prescaler. Bus allocation and registration use managed helpers.

> diff --git a/drivers/net/mdio/mdio-cs75xx.c b/drivers/net/mdio/mdio-cs75xx.c
> new file mode 100644
> index 0000000000000..0405723eb7932
> --- /dev/null
> +++ b/drivers/net/mdio/mdio-cs75xx.c

[ ... ]

> +static int cs75xx_mdio_wait(struct cs75xx_mdio *priv)
> +{
> +	u32 val;
> +	int ret;
> +
> +	ret = readl_poll_timeout(priv->base + PER_MDIO_CTRL, val,
> +				 val & MDIO_CTRL_DONE, 1, CS75XX_MDIO_TIMEOUT_US);
> +	if (!ret)
> +		writel(MDIO_CTRL_DONE, priv->base + PER_MDIO_CTRL);
> +	return ret;
> +}
> +
> +static int cs75xx_mdio_read(struct mii_bus *bus, int phy, int reg)
> +{
> +	struct cs75xx_mdio *priv = bus->priv;
> +	int ret;
> +
> +	writel(MDIO_CTRL_DONE, priv->base + PER_MDIO_CTRL);
> +	writel(MDIO_ADDR_READ | FIELD_PREP(MDIO_ADDR_REG, reg) |
> +	       FIELD_PREP(MDIO_ADDR_PHY, phy), priv->base + PER_MDIO_ADDR);
> +	writel(MDIO_CTRL_START, priv->base + PER_MDIO_CTRL);
> +	ret = cs75xx_mdio_wait(priv);
> +	if (ret)
> +		return ret;
> +	return readl(priv->base + PER_MDIO_RDDATA) & 0xffff;
> +}

[Severity: Medium]
cs75xx_mdio_wait() passes a sleep_us of 1 to readl_poll_timeout().
In poll_timeout_us() a non-zero sleep turns into
usleep_range((sleep_us >> 2) + 1, sleep_us), which here becomes
usleep_range(1, 1).

With min == max, usleep_range_state() computes a delta of 0. Every
poll iteration therefore arms an exact-deadline 1 us hrtimer with no
slack for coalescing, and then schedules out.

The first poll right after MDIO_CTRL_START will always see
MDIO_CTRL_DONE clear. The binding keeps the preamble, so a Clause 22
frame is 64 MDC cycles. That is at least 25.6 us at 2.5 MHz, and
longer with a slower firmware prescaler.

As a result, every cs75xx_mdio_read() and cs75xx_mdio_write() goes
through a run of back-to-back 1 us sleeps. Each one costs a clockevent
reprogram, a timer interrupt and a wakeup. On a timeout that could be
up to roughly 10,000 of them within CS75XX_MDIO_TIMEOUT_US.

This matters because the path runs on every PHY access. That includes
probe-time bus scanning and the once-a-second phy_state_machine()
polling for each PHY on the bus.

The comment above fsleep() in include/linux/delay.h notes that
hrtimer-based sleeps are not worth it at or below about 10 us. Most
drivers under drivers/net/mdio/ poll with an interval of 10 us or
more.

Would a sleep of 10 to 20 us work for this controller, given the
expected frame time at the inherited MDC rate? Or is there a reason
the 1 us interval is needed here?

[Severity: Medium]
What happens to the in-flight transaction when cs75xx_mdio_wait() times
out? It returns -ETIMEDOUT but does not abort the transfer, wait for it to
finish, or reset the engine. The controller may still be shifting the
frame out.

The next cs75xx_mdio_read() or cs75xx_mdio_write() does not check that the
controller is idle first. It clears DONE, rewrites PER_MDIO_ADDR (and
PER_MDIO_WRDATA for writes), then sets START. If the earlier transaction
finishes after that DONE clear:

  cs75xx_mdio_read(bus, phyA, regA)
    cs75xx_mdio_wait() -> -ETIMEDOUT, transfer still running

  cs75xx_mdio_read(bus, phyB, regB)
    writel(MDIO_CTRL_DONE, priv->base + PER_MDIO_CTRL);
    writel(... phyB/regB ..., priv->base + PER_MDIO_ADDR);
    writel(MDIO_CTRL_START, priv->base + PER_MDIO_CTRL);
                          <- phyA/regA transfer finishes, DONE set again
    cs75xx_mdio_wait() -> returns 0 immediately
    readl(priv->base + PER_MDIO_RDDATA) -> phyA/regA data

Could phylib then get the RDDATA from the earlier transaction as a valid
value for phyB/regB? In the same way, cs75xx_mdio_write() could return 0
for a write that never went out. Rewriting ADDR/WRDATA while the shifter
is busy might also corrupt the frame on the wire. This assumes DONE is
write-1-to-clear and that START has no effect while busy.

The inherited 16-bit prescaler makes this plausible. A large divisor can
slow MDC enough that a 64-bit Clause 22 frame takes longer than
CS75XX_MDIO_TIMEOUT_US (10 ms).

The commit message says:

    Report timeout errors directly without tracking a pending transaction.

That suggests nothing returns the controller to idle after a timeout.

Probe has a similar gap. It sets MDIO_CFG_MANUAL and clears DONE without
waiting for any auto-poll cycle that firmware may have left running.

Other MDIO drivers wait for idle before issuing a command.
ipq4019_mdio_read_c22() calls ipq4019_mdio_wait_busy() first, and
mscc_miim_read()/mscc_miim_write() call mscc_miim_wait_pending(). Does
this driver need a similar idle check, or an abort on timeout?

> +
> +static int cs75xx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
> +{

[ ... ]

> +	clk = devm_clk_get_enabled(dev, NULL);
> +	if (IS_ERR(clk))
> +		return dev_err_probe(dev, PTR_ERR(clk),
> +				     "failed to enable APB clock\n");
> +
> +	/*
> +	 * Select software-initiated accesses instead of automatic PHY polling.
> +	 * Read-modify-write preserves the firmware MDC prescaler in bits 31:16.
> +	 */
> +	cfg = readl(priv->base + PER_MDIO_CFG);
> +	cfg |= MDIO_CFG_MANUAL;
> +	writel(cfg, priv->base + PER_MDIO_CFG);
> +	writel(MDIO_CTRL_DONE, priv->base + PER_MDIO_CTRL);

[Severity: Medium]
Does anything make sure the prescaler inherited in PER_MDIO_CFG bits
31:16 gives a usable MDC? The APB clock is enabled, but clk_get_rate() is
never called. The driver therefore cannot tell whether the resulting MDC
is within the 2.5 MHz Clause 22 limit.

In several cases MDC is just whatever those bits hold:

  - the bootloader never set up MDIO
  - a kexec'd kernel inherited a different value
  - CFG was reset

If MDC is too fast, PHY accesses could be silently wrong. If it is too
slow, every access could time out. There are also no PM callbacks to
restore CFG or MDIO_CFG_MANUAL if register context is lost.

The companion patch "dt-bindings: net: Add Cortina CS7542 MDIO controller"
describes a "programmable 16-bit MDC prescaler". It references mdio.yaml
and disables only suppress-preamble. With unevaluatedProperties: false, a
DT that sets clock-frequency from mdio.yaml would still pass validation.
This driver then ignores that property and prints no message.

The commit message says:

    The firmware MDC prescaler is preserved; no clock-rate or divisor
    programming is introduced.

So leaving the divisor alone is a deliberate choice. If so, should the
binding also disallow clock-frequency, as it already does for
suppress-preamble? And should probe at least warn when the APB rate and
prescaler give an out-of-spec MDC?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-b4-cs7542-mdio-v5-0-c9b9b51bf58d%40gmail.com
Technical Details
Message-ID: <179644615714.3146.7992850630581806957@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mi.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377835-linux-kernel-netdev=dewy.ru
References: <20261204-b4-cs7542-mdio-v5-2-c9b9b51bf58d@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mi.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377835-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v5 2/3] net: mdio: Add Cortina CS7542 bus controller
Date: Sat, 05 Dec 2026 04:49:17 +0000
Organization: Usenet Network
Message-ID: <179644615714.3146.7992850630581806957@kernel.org>
References: <20261204-b4-cs7542-mdio-v5-2-c9b9b51bf58d@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2956186"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:WDP318qawQ8bxh+xt39KExNbzMM= sha256:mRzF25Nsh3LNkipSJItO6BbYwYG+sBXO7egPPlMzjkI=
	sha1:qkgQHSo/YBbpN7kuDA1X8UErmmM= sha256:xKJBy89GGLhQohYjeSOwU2M9TgyE+45ykQduC7oDeCQ=
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 CCFE6117D6D; Sat,  5 Dec 2026 07:49:38 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.541
X-Spam-Status: No, score=-3.541 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, 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 KjEQxbMlaR89;
	Sat,  5 Dec 2026 07:49:35 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377835-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 E122D117D6A; Sat,  5 Dec 2026 07:49:23 +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 089232C00A; Sat,  5 Dec 2026 04:49:20 +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=1796446159;
	b=MyOeTUHO6BUp1cx+eAiAkwqtb7mInlzDJyqkm4qEt9Zg9T57qzb8P6OX0dX7npV5oj7l
	 RDCi+cizv9dRRjG/36rCWIMmXifziZBO0h1W4jypb1Rwivqn7ykFYdLK2HYEZjRA7vHJp
	 aFNuss/gJgSHP19+SkFCwQtYGeq6x/8wclDVvmfRAfZJ4F2yeSPWTiMz2iZrPaNoJOsDh
	 ubQGevYpjn0ieHE0Vm9gDc/jWBgxM5zZlLySPLnSR4b2Q5m0vEolVYlCZV2fb5kr9Pjq9
	 D+p1i1Sk7B76NJCIMa0ctWN1wwopFgjVVMCL+iEZDMWVLzSqw4jHJsC2QzIbfVmeZKg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796446159;
	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=QNmrUx59pBpjxP7NbwQf9+jMFuyxMIUVxT2a+1/SXOU=;
	b=OpA8UgZGU7aN11iEwoIt9r1lduoUnBAVn5azF7gF5A0Cx4TrYvisdSKhKFp0ZNfdb56o
	 /e+9W32SGJn2CM8UtzFjW8ZFhxSjlWMO1KqKPNj2IkMleK6BvdtmbEByCBYGu6R5spY/s
	 TEdqQY+OSM8vG99MgtprSOSx/qay093Zvr9ntJibE8sRgfQRTx1ym8xeksySqJRCrq7oq
	 tT/5omXom3J8yDzHHIrNa1qAk2GSehyvuMfICC927rBymfpp45hgEaoxbtkR0Jg8UNpcl
	 gPA/b1uZptjyMWaJRdJIop/dMP8FtIbXur3W+z/ZrhmZJRupopRTBbrZ5gqcTBlEcrA==
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=K9exh3NY;
	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 ADE5D606A336;
	Sat,  5 Dec 2026 04:49:19 +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=K9exh3NY
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=1796446158;
	b=pDYhx9xoSdWDubkPKRTq5RVBf8Gq2Mk96s7ZtXa0687LVILa5nZf4E2+xIW2+ThvLjlq
	 f7Jt5ZYF2VQAtiMDVBf5v0C5Lm2VAnbuQBz8TYw3iGMsP6kT7o3KEVYxt640XTVqoM0No
	 gi0/hahVT1sHr5h4rWmIyDVXL10Paa9WbsWJDsqAMKXTioODiG5WWnTLjOqfV0FXtY+DS
	 1RY4vwH8DFKN3kjezjqJbyug0TB62zDDim0rTR5LhErQXE2eUemnyb1WjTEj2nPwqe2QP
	 svv0h8U/8oNaTkVYe+cP64typtG6+JF0EIMca0D38SUBIAxJRdaoLhrjTudQf1OMbkA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796446158;
	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=QNmrUx59pBpjxP7NbwQf9+jMFuyxMIUVxT2a+1/SXOU=;
	b=nRAq4bPAIBu7sr27irHiP/gJRkyQ28ZDNgaTizUojxArBgWFCLluse4KwkOeReWLvRrK
	 x2TP0rghxSFnvzgosZgEPm7XaC+7r2ikLOJM25pxjKY2ttiu19ix+EqTfPwJuC6IKgXbj
	 9XgNE9cw3Veczrdh5uVczsnDRmDcm+ht+/VC6XeSNYeXxuC5TKA4/6lgwsfEFu3vMX2Eq
	 dy46xnCiAbIrvvv3fDnhtRqb3Ay/bsHZvWxcw9+D3AcEXOdDJc52BrX62kDT5EN13LcTm
	 FpXc0fVdhYM0lqwiM5bnLmZdenkMuL2KDk6KN1j3DgYA+zrPkyQ7kz1RWAOM10pnM7Q==
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=K9exh3NY;
	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 CBFF7606A32D;
	Sat,  5 Dec 2026 04:49:18 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 977991F00936;
	Sat,  5 Dec 2026 04:49:17 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796446158;
	bh=QNmrUx59pBpjxP7NbwQf9+jMFuyxMIUVxT2a+1/SXOU=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=K9exh3NY18U2/2UUbp5vfEiSAcOYMT49SfJ5lzUIgxTTVwTUiKqgq1fiD7bqRwhdY
	 u8AvMSOh2wa+xAJND/jvIFDMH1NOq4q3F1Vtfn52WEnG/q1muxrNxW6jfCNg2yUiTc
	 pQ2ZyQ1rXqJrh2N7CdedmNrOi+WeSJBkKvg67bpBUwZPKwnl2bmkv+YCUc7pUFllXQ
	 s4kTM6XkHJm3qrN1zMEEH8QJTV/tkI3O+zF+8FKm1xA2mGZ6HKV8NOk0RqfAs/Xk1H
	 Lh5s4SqY++pUulg9CQlH/CRYnq9ruS4toKwLnr7yb5DxF73arOPXfxABHls+5U9Kat
	 a/XxKDqYbrHhQ==
X-Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
 pabeni@redhat.com, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
 andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk,
 andrew+netdev@lunn.ch, willemb@google.com, netdev@vger.kernel.org,
 devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
X-In-Reply-To: <20261204-b4-cs7542-mdio-v5-2-c9b9b51bf58d@gmail.com>
X-sashiko-severity: Medium
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