Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: filipp.dunsky@gmail.com
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
Subject: Re: [PATCH net-next v5 2/3] net: mdio: Add Cortina CS7542 bus controller
Date: Sat, 05 Dec 2026 04:49:17 +0000	[thread overview]
Message-ID: <179644615714.3146.7992850630581806957@kernel.org> (raw)
In-Reply-To: <20261204-b4-cs7542-mdio-v5-2-c9b9b51bf58d@gmail.com>

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

  parent reply	other threads:[~2026-12-05  4:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  3:57 [PATCH net-next v5 0/3] Add Cortina Systems CS7542 MDIO controller support Fil Dunsky via B4 Relay
2026-12-04  3:57 ` [PATCH net-next v5 1/3] dt-bindings: net: Add Cortina CS7542 MDIO controller Fil Dunsky via B4 Relay
2026-12-04  3:57 ` [PATCH net-next v5 2/3] net: mdio: Add Cortina CS7542 bus controller Fil Dunsky via B4 Relay
2026-12-04 13:31   ` Andrew Lunn
2026-12-05  4:49   ` netdev-bot+sashiko [this message]
2026-12-04  3:57 ` [PATCH net-next v5 3/3] MAINTAINERS: Add Cortina CS7542 MDIO controller entry Fil Dunsky via B4 Relay

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=179644615714.3146.7992850630581806957@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew@lunn.ch \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@kernel.org \
    --cc=filipp.dunsky@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    --cc=willemb@google.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