From: netdev-bot+sashiko@kernel.org
To: florian.fainelli@broadcom.com
Cc: netdev@vger.kernel.org, carlos.soto@broadcom.com,
justin.chen@broadcom.com, opendmb@gmail.com, nb@tipi-net.de,
bcm-kernel-feedback-list@broadcom.com, andrew@lunn.ch,
hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net,
edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
linux-kernel@vger.kernel.org, kudzo51@gmail.com
Subject: Re: [PATCH net-next v2 4/4] net: mdio: mdio-bcm-unimac: Add Clause 45 support
Date: Thu, 19 Nov 2026 00:37:27 +0000 [thread overview]
Message-ID: <179504864758.3136.4762946821848645256@kernel.org> (raw)
In-Reply-To: <20261116213449.1682731-5-florian.fainelli@broadcom.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 3
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] The new C45 sequence issues an ADDR frame followed by a
READ/WRITE frame through MDIO_CMD.
- [Medium] unimac_mdio_set_clause() (mdio-bcm-unimac.c:126-138) adds a
read-modify-write of MDIO_CFG to the MDIO access path, and that RMW is…
- [Low] This patch changes behaviour for existing users of the non-DT
(ACPI) GENET path more than the commit message says.
- [Low] The comment above MDIO_POLL_DELAY_US/MDIO_POLL_TIMEOUT_US (mdio-
bcm-unimac.c:45-48: 'A C45 access is two frames, so a 1ms timeout…
- [Low] The driver now enables C45 on every controller it binds.
--
net: mdio: mdio-bcm-unimac: Add Clause 45 support
This commit adds Clause 45 read/write callbacks to the UniMAC MDIO driver.
Each C45 access issues an ADDR cycle followed by a READ/WRITE cycle, and
MDIO_CFG is switched between C22 and C45 mode as needed. The BMSR
workaround read is also skipped for children compatible with
"ethernet-phy-ieee802.3-c45".
> diff --git a/drivers/net/mdio/mdio-bcm-unimac.c b/drivers/net/mdio/mdio-bcm-unimac.c
> index df267bb826966..6059b32580c54 100644
> --- a/drivers/net/mdio/mdio-bcm-unimac.c
> +++ b/drivers/net/mdio/mdio-bcm-unimac.c
[ ... ]
> @@ -96,7 +102,43 @@ static int unimac_mdio_poll(void *wait_func_data)
> MDIO_CMD);
> }
>
> -static int unimac_mdio_read(struct mii_bus *bus, int phy_id, int reg)
> +static u32 unimac_mdio_c45_devad(int devad)
> +{
> + return ((u32)devad << MDIO_DEVAD_SHIFT) & MDIO_DEVAD_MASK;
> +}
> +
> +static int unimac_mdio_addr_c45(struct unimac_mdio_priv *priv,
> + int phy_id, int devad, int reg)
> +{
> + u32 cmd;
> +
> + /* Prepare the addr c45 operation */
> + cmd = MDIO_ADDR_C45 | (phy_id << MDIO_PMD_SHIFT) |
> + unimac_mdio_c45_devad(devad) | (reg & MDIO_C45_REG_MASK);
> + unimac_mdio_writel(priv, cmd, MDIO_CMD);
> +
> + /* Start MDIO transaction */
> + unimac_mdio_start(priv);
> +
> + return priv->wait_func(priv->wait_func_data);
[Severity: Low]
This isn't a bug, but the timing comments added by the earlier patch in
this series ("Poll for completion at 1us granularity") describe one poll
that covers the whole two-frame C45 access:
/* A 64 bit MDIO frame takes ~25us at 2.5MHz and ~33us at the lowest MDIO
* clock the driver can program from a 250MHz reference clock. A C45 access is
* two frames, so a 1ms timeout leaves a wide margin.
*/
The same idea appears in unimac_mdio_poll():
/* C22 transactions should take ~25 usec, C45 transactions take about
* twice as long since they need an address and a data cycle.
*/
In this patch, wait_func is called once here for the ADDR frame. It is
called again for the READ/WRITE frame in unimac_mdio_do_read() and
unimac_mdio_do_write(). So each frame gets its own MDIO_POLL_TIMEOUT_US
budget.
Could those comments be updated to describe the per-frame wait?
> +}
> +
> +static void unimac_mdio_set_clause(struct unimac_mdio_priv *priv, bool is_c45)
> +{
> + u32 cfg = unimac_mdio_readl(priv, MDIO_CFG);
> + u32 new_cfg = cfg;
> +
> + if (is_c45)
> + new_cfg &= ~MDIO_C22;
> + else
> + new_cfg |= MDIO_C22;
> +
> + if (new_cfg != cfg)
> + unimac_mdio_writel(priv, new_cfg, MDIO_CFG);
[Severity: Medium]
This adds a read-modify-write of MDIO_CFG to the access path, and only
bus->mdio_lock serializes it. Can it race with the other writer of
MDIO_CFG?
unimac_mdio_clk_set() also does a read-modify-write of MDIO_CFG for the
clock divider. It is called from unimac_mdio_resume() without
bus->mdio_lock:
drivers/net/mdio/mdio-bcm-unimac.c:unimac_mdio_clk_set() {
...
reg = unimac_mdio_readl(priv, MDIO_CFG);
reg &= ~(MDIO_CLK_DIV_MASK << MDIO_CLK_DIV_SHIFT);
reg |= div << MDIO_CLK_DIV_SHIFT;
unimac_mdio_writel(priv, reg, MDIO_CFG);
...
}
The unimac-mdio device is a child of the MAC device, so the MAC resumes
first. GENET resume calls phy_start(). bcmasp_interface_resume() calls
phy_start() or phy_trigger_machine(). Either way the phylib state machine
is queued, and it can issue MDIO accesses while the PM core moves on to
unimac_mdio_resume().
This needs clock-frequency set in DT, and unimac_mdio_set_clause() has to
change the mode inside that window. Examples are the first C45 access
after the block was reset during suspend, or a bus with mixed C22/C45
traffic. In that case one of two updates can be lost:
- set_clause() writes back a stale CFG, which drops the divider that
clk_set() just restored. set_clause() only rewrites CFG on a mode
change, so the divider then stays at the hardware default until the
next resume.
- clk_set() writes back MDIO_C22 after set_clause() cleared it. The
following RD_C45/WR_C45 command is then issued in C22 mode.
Before this patch the access path never wrote MDIO_CFG. Does
unimac_mdio_clk_set() on the resume path now need to be serialized
against MDIO accesses?
> +}
[ ... ]
> @@ -107,8 +149,19 @@ static int unimac_mdio_read(struct mii_bus *bus, int phy_id, int reg)
> return ret;
>
> /* Prepare the read operation */
> - cmd = MDIO_RD_C22 | (phy_id << MDIO_PMD_SHIFT) |
> - (reg << MDIO_REG_SHIFT);
> + unimac_mdio_set_clause(priv, is_c45);
> + if (is_c45) {
> + ret = unimac_mdio_addr_c45(priv, phy_id, devad, reg);
> + if (ret)
> + goto out;
> +
> + cmd = MDIO_RD_C45 | (phy_id << MDIO_PMD_SHIFT) |
> + unimac_mdio_c45_devad(devad) |
> + (reg & MDIO_C45_REG_MASK);
[Severity: Medium]
When GENET instantiates this bus, is the ADDR frame guaranteed to be
finished at this point?
The only completion check is the return value of wait_func. For GENET,
wait_func is bcmgenet_mii_wait(), and it always returns 0:
drivers/net/ethernet/broadcom/genet/bcmmii.c:bcmgenet_mii_wait() {
...
wait_event_timeout(priv->wq,
!(bcmgenet_umac_readl(priv, UMAC_MDIO_CMD)
& MDIO_START_BUSY),
HZ / 100);
return 0;
}
The only wake_up(&priv->wq) is in bcmgenet_isr0(). It only fires when
bcmgenet_has_mdio_intr() is true, which excludes GENET v1/v2. It also
needs the IRQ, which is only requested in bcmgenet_open(). So during
probe, while the interface is down, or on v1/v2, the wait ends only on
the HZ / 100 timeout.
With HZ=100, the 32-bit ARM default, that timeout is one jiffy. It can
expire at the next tick, well inside the ~25-33us frame. With HZ below
100 the timeout is 0.
In that case RD_C45 (or WR_C45 in unimac_mdio_do_write()) is written
into MDIO_CMD and START_BUSY is set again while the ADDR frame is still
on the wire. Can this corrupt the address frame, or send the data/write
cycle to whatever register the PHY last latched?
For reads, a premature read-back of MDIO_CMD[15:0] would return the
register number from the command as if it were data.
bcmgenet_mii_wait() already returned early before this patch, which can
affect back-to-back C22 accesses. Here, though, the new "if (ret) goto
out" check can never fire for GENET.
[ ... ]
> @@ -301,6 +390,8 @@ static int unimac_mdio_probe(struct platform_device *pdev)
> bus->parent = &pdev->dev;
> bus->read = unimac_mdio_read;
> bus->write = unimac_mdio_write;
> + bus->read_c45 = unimac_mdio_read_c45;
> + bus->write_c45 = unimac_mdio_write_c45;
[Severity: Low]
The commit message says read_c45 enables a C45 scan of unmasked
addresses. Could it also describe what this means for the non-DT (ACPI)
GENET path?
On that path bcmgenet_mii_register() does:
else
ppd.phy_mask = ~0;
unimac_mdio_probe() turns this into bus->phy_mask = ~pdata->phy_mask,
which is 0. With np == NULL, of_mdiobus_register() calls
__mdiobus_register() directly, so the DT phy_mask = ~0 override never
runs. __mdiobus_register() then does:
if (!prevent_c45_scan && bus->read_c45) {
err = mdiobus_scan_bus_c45(bus);
This covers every address that has no C22 device.
bcmgenet_mii_probe() then attaches to phy_find_first(unimacbus), which is
the lowest-address phy_device. Suppose the C45 scan picks up something
at a lower address than the real PHY: a C22 PHY that answers ST=00
frames, or a bogus value read back early through bcmgenet_mii_wait().
Would that device be attached instead of the real PHY?
The scan also adds probe time. During probe nothing wakes priv->wq, so
each C45 frame waits out the full HZ / 100 timeout in
bcmgenet_mii_wait(). An empty address takes at least two frames, which
is 60 or more frames in total, or roughly 0.25-0.6s depending on HZ.
[Severity: Low]
read_c45/write_c45 are set unconditionally for every compatible in
unimac_mdio_ids[]:
- brcm,asp-v3.0-mdio, brcm,asp-v2.2-mdio, brcm,asp-v2.1-mdio
- brcm,bcm6846-mdio
- brcm,genet-mdio-v1 through v5
- brcm,unimac-mdio
They are also set for the GENET platform data instance.
unimac_mdio_set_clause() then clears MDIO_C22 in MDIO_CFG for C45
accesses.
Do all of these controller revisions implement the C45 ADDR/WR/RD opcodes
(0/1/3 in bits 27:26)? The match table has no per-compatible data, and
nothing checks the revision.
The MDIO_C22/MDIO_C45 CFG bit definitions go back to the original driver,
which suggests the block has a C45 mode. Nothing in the tree confirms
that for each listed revision, though.
On a revision without C45 support, these would now send unsupported
opcodes:
- the ACPI GENET C45 scan
- a DT child compatible with "ethernet-phy-ieee802.3-c45"
- a SIOCGMIIREG/SIOCSMIIREG ioctl with a C45 phy_id
Before this patch, those requests failed with -EOPNOTSUPP because
read_c45 was NULL.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116213449.1682731-1-florian.fainelli%40broadcom.com
next prev parent reply other threads:[~2026-11-19 0:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 21:34 [PATCH net-next v2 0/4] net: mdio: Clause 45 support for mdio-bcm-unimac Florian Fainelli
2026-11-16 21:34 ` [PATCH net-next v2 1/4] net: phy: Map C45 probe read errors to -ENODEV during bus scan Florian Fainelli
2026-11-17 9:33 ` Nicolai Buchwitz
2026-11-19 0:37 ` netdev-bot+sashiko
2026-11-19 0:48 ` Florian Fainelli
2026-11-16 21:34 ` [PATCH net-next v2 2/4] net: mdio: mdio-bcm-unimac: Define MDIO_OP_SHIFT Florian Fainelli
2026-11-16 21:34 ` [PATCH net-next v2 3/4] net: mdio: mdio-bcm-unimac: Poll for completion at 1us granularity Florian Fainelli
2026-11-16 21:34 ` [PATCH net-next v2 4/4] net: mdio: mdio-bcm-unimac: Add Clause 45 support Florian Fainelli
2026-11-17 12:36 ` Nicolai Buchwitz
2026-11-19 0:37 ` netdev-bot+sashiko [this message]
2026-11-19 0:53 ` Florian Fainelli
2026-11-16 22:38 ` [PATCH net-next v2 0/4] net: mdio: Clause 45 support for mdio-bcm-unimac Kordian Chmielewski
2026-11-17 12:36 ` Nicolai Buchwitz
2026-11-17 23:17 ` Florian Fainelli
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=179504864758.3136.4762946821848645256@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew@lunn.ch \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=carlos.soto@broadcom.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=florian.fainelli@broadcom.com \
--cc=hkallweit1@gmail.com \
--cc=justin.chen@broadcom.com \
--cc=kuba@kernel.org \
--cc=kudzo51@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=nb@tipi-net.de \
--cc=netdev@vger.kernel.org \
--cc=opendmb@gmail.com \
--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®