Re: [PATCH net-next v3 4/4] net: mdio: mdio-bcm-unimac: Add Clause 45 support

From: Florian Fainelli

Date: Fri Nov 20 2026 - 00:15:16 EST




On 11/19/2026 6:34 PM, netdev-bot+sashiko@xxxxxxxxxx wrote:
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · 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).

- [Medium] In drivers/net/mdio/mdio-bcm-unimac.c, the patch's own comment
in unimac_mdio_addr_c45() says some wait_func implementations…
- [Low] The commit message does not mention the change to
unimac_mdio_resume() in drivers/net/mdio/mdio-bcm-unimac.c.

--

net: mdio: mdio-bcm-unimac: Add Clause 45 support

This adds Clause 45 read and write callbacks to the UniMAC MDIO driver.
Each access does an ADDR cycle followed by a READ or WRITE cycle, and
MDIO_CFG is switched between C22 and C45 mode as needed. It also skips the
BMSR workaround read 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..ec0f2e8070eeb 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c

[ ... ]

@@ -96,7 +102,53 @@ static int unimac_mdio_poll(void *wait_func_data)

[ ... ]

+ /* Some wait_func implementations (e.g.: bcmgenet_mii_wait()) return 0
+ * even when they timed out with the controller still busy. The data
+ * cycle must not be started before the ADDR cycle has completed, so
+ * make sure the controller is idle.
+ */
+ return unimac_mdio_poll(priv);
+}

[ ... ]

@@ -107,8 +159,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]
The comment in unimac_mdio_addr_c45() says bcmgenet_mii_wait() can return
0 while MDIO_START_BUSY is still set. The extra unimac_mdio_poll() runs
only after the ADDR cycle. Can the same early return happen on the C45
READ data cycle?

bcmgenet_mii_wait() returns 0 every time:

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;
}

At probe time, the GENET ISR that calls wake_up(&priv->wq) is not
installed yet, because request_irq() happens later in bcmgenet_open().
On v1/v2, UMAC_IRQ_MDIO_EVENT is not enabled at all. In both cases these
waits depend only on the timeout. With HZ=100 the timeout is one jiffy,
which can expire at the next tick.

The RD_C45 command places reg in MDIO_CMD[15:0]. After wait_func(),
unimac_mdio_do_read() does this without checking MDIO_START_BUSY:

cmd = unimac_mdio_readl(priv, MDIO_CMD);
...
ret = cmd & 0xffff;

If MDIO_CMD[15:0] still holds reg until the hardware writes the read
data, could an early return give the caller reg as the PHY data? This
would also happen before MDIO_READ_FAIL is latched. For example, a read
of MDIO_DEVS2 would return 6 and a read of MDIO_DEVS1 would return 5.
get_phy_c45_devs_in_pkg() could accept that as a plausible devs_in_pkg.

read_c45 is now set, and the non-DT GENET path leaves bus->phy_mask at 0.
So __mdiobus_register()->mdiobus_scan_bus_c45() issues these reads on
every address that has no C22 device. Could get_phy_c45_ids() then
register a bogus C45 PHY?

The write side looks similar. unimac_mdio_do_write() returns 0 after
wait_func() even if the C45 WRITE is still in flight. Could the next
access's unimac_mdio_set_clause() then flip the MDIO_C22 bit in MDIO_CFG,
or write its ADDR command to MDIO_CMD, while the previous frame is still
going out?

The C22 data cycle already returned early in the same way before this
patch. The reg-as-data result and the MDIO_CFG switch mid-frame are new,
though.

Would it make sense to have bcmgenet_mii_wait() return -ETIMEDOUT on
timeout, or to run the idle poll after every cycle and not only between
ADDR and DATA?

[ ... ]

@@ -336,8 +437,16 @@ static void unimac_mdio_remove(struct platform_device *pdev)
static int __maybe_unused unimac_mdio_resume(struct device *d)
{
struct unimac_mdio_priv *priv = dev_get_drvdata(d);
+ int ret;
+
+ /* MDIO_CFG is also modified by the MDIO accessors to switch between
+ * Clause 22 and Clause 45, which run under the bus lock.
+ */
+ mutex_lock(&priv->mii_bus->mdio_lock);
+ ret = unimac_mdio_clk_set(priv);
+ mutex_unlock(&priv->mii_bus->mdio_lock);

[Severity: Low]
This isn't a bug, but the commit message doesn't mention this change to
unimac_mdio_resume(). The resume callback now holds
priv->mii_bus->mdio_lock around unimac_mdio_clk_set(), because
unimac_mdio_set_clause() does a read-modify-write of MDIO_CFG, the same
register that holds the clock divider.

The message covers the C45 accessors, the BMSR workaround skip and the
C45 scan. Could it also describe this locking change in the resume path?

- return unimac_mdio_clk_set(priv);
+ return ret;
}


On the Medium: this one is valid, thanks. wait_func() implementations such as bcmgenet_mii_wait() can return 0 with MDIO_START_BUSY still set, and v3 only guarded the ADDR -> DATA transition. A C45 READ that returned early would hand back MDIO_CMD[15:0] (the register address) as read data, and the next access could switch MDIO_CFG or rewrite MDIO_CMD while the previous frame was still in flight.

v4 adds unimac_mdio_wait(), which calls wait_func() and then polls for the controller to go idle. It is used after the ADDR, READ and WRITE cycles, so the idle check no longer depends on the wait_func() implementation. I kept the fix in the unimac driver rather than changing
bcmgenet_mii_wait() to return -ETIMEDOUT.

Side effect, now spelled out in the commit message: C22 accesses use the
same helper, so a C22 cycle that times out on a busy controller now returns -ETIMEDOUT instead of silently returning stale data.

On the Low: the commit message now describes the locking added to unimac_mdio_resume().

pw-bot: cr
--
Florian