* [PATCH net-next v2 1/4] net: phy: Map C45 probe read errors to -ENODEV during bus scan
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 ` Florian Fainelli
2026-11-17 9:33 ` Nicolai Buchwitz
2026-11-19 0:37 ` netdev-bot+sashiko
2026-11-16 21:34 ` [PATCH net-next v2 2/4] net: mdio: mdio-bcm-unimac: Define MDIO_OP_SHIFT Florian Fainelli
` (5 subsequent siblings)
6 siblings, 2 replies; 14+ messages in thread
From: Florian Fainelli @ 2026-11-16 21:34 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Doug Berger, Nicolai Buchwitz,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, open list, Mlody12 mlody12
get_phy_c22_id() maps a bus read error of -EIO or -ENODEV to -ENODEV, so
that mdiobus_scan_bus_c22() carries on with the next address when nothing
answers. get_phy_c45_ids() only does so for phy_c45_probe_present(); a
failed read of the devices in package registers is turned into -EIO, which
mdiobus_scan_bus_c45() treats as fatal and which makes the whole
__mdiobus_register() fail.
MDIO controllers that report a read from an empty address as a bus error
(e.g. MDIO_READ_FAIL on the UniMAC MDIO block) and that provide read_c45()
with unmasked addresses therefore cannot be registered: the C45 scan fails
on the first empty address.
Let get_phy_c45_devs_in_pkg() return the bus error and apply the same
mapping as get_phy_c22_id() to the two places that look for a device at an
address: the loop over the MMDs and the MMD 0 fallback. Errors from the
reads of the per-MMD identifiers, which only happen once a device has
answered, are still reported as -EIO.
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
drivers/net/phy/phy_device.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index b39e945cebd7..4071041e1051 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -780,7 +780,7 @@ static int phy_c45_probe_present(struct mii_bus *bus, int prtad, int devad)
* Description: reads devices in package registers of a MMD at @dev_addr
* from PHY at @addr on @bus.
*
- * Returns: 0 on success, -EIO on failure.
+ * Returns: 0 on success, or the negative error code from the bus read.
*/
static int get_phy_c45_devs_in_pkg(struct mii_bus *bus, int addr, int dev_addr,
u32 *devices_in_package)
@@ -789,17 +789,30 @@ static int get_phy_c45_devs_in_pkg(struct mii_bus *bus, int addr, int dev_addr,
phy_reg = mdiobus_c45_read(bus, addr, dev_addr, MDIO_DEVS2);
if (phy_reg < 0)
- return -EIO;
+ return phy_reg;
*devices_in_package = phy_reg << 16;
phy_reg = mdiobus_c45_read(bus, addr, dev_addr, MDIO_DEVS1);
if (phy_reg < 0)
- return -EIO;
+ return phy_reg;
*devices_in_package |= phy_reg;
return 0;
}
+/* get_phy_c45_probe_err - map a bus error seen while looking for a device.
+ * @err: negative error code returned by a bus read
+ *
+ * Like get_phy_c22_id(), report -ENODEV when the bus read failed with -EIO or
+ * -ENODEV, which is how a controller signals that nothing answered at this
+ * address, so that bus scanning carries on with the next address. Anything
+ * else is reported as -EIO.
+ */
+static int get_phy_c45_probe_err(int err)
+{
+ return (err == -EIO || err == -ENODEV) ? -ENODEV : -EIO;
+}
+
/**
* get_phy_c45_ids - reads the specified addr for its 802.3-c45 IDs.
* @bus: the target MII bus
@@ -845,7 +858,8 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr,
}
phy_reg = get_phy_c45_devs_in_pkg(bus, addr, i, &devs_in_pkg);
if (phy_reg < 0)
- return -EIO;
+ /* returning -ENODEV doesn't stop bus scanning */
+ return get_phy_c45_probe_err(phy_reg);
}
if ((devs_in_pkg & 0x1fffffff) == 0x1fffffff) {
@@ -855,7 +869,7 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr,
*/
phy_reg = get_phy_c45_devs_in_pkg(bus, addr, 0, &devs_in_pkg);
if (phy_reg < 0)
- return -EIO;
+ return get_phy_c45_probe_err(phy_reg);
/* no device there, let's get out of here */
if ((devs_in_pkg & 0x1fffffff) == 0x1fffffff)
--
2.34.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH net-next v2 1/4] net: phy: Map C45 probe read errors to -ENODEV during bus scan
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
1 sibling, 0 replies; 14+ messages in thread
From: Nicolai Buchwitz @ 2026-11-17 9:33 UTC (permalink / raw)
To: Florian Fainelli
Cc: netdev, Doug Berger, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-kernel,
Mlody12 mlody12
On 16.11.2026 22:34, Florian Fainelli wrote:
> get_phy_c22_id() maps a bus read error of -EIO or -ENODEV to -ENODEV,
> so
> that mdiobus_scan_bus_c22() carries on with the next address when
> nothing
> answers. get_phy_c45_ids() only does so for phy_c45_probe_present(); a
> failed read of the devices in package registers is turned into -EIO,
> which
> mdiobus_scan_bus_c45() treats as fatal and which makes the whole
> __mdiobus_register() fail.
>
> MDIO controllers that report a read from an empty address as a bus
> error
> (e.g. MDIO_READ_FAIL on the UniMAC MDIO block) and that provide
> read_c45()
> with unmasked addresses therefore cannot be registered: the C45 scan
> fails
> on the first empty address.
>
> Let get_phy_c45_devs_in_pkg() return the bus error and apply the same
> mapping as get_phy_c22_id() to the two places that look for a device at
> an
> address: the loop over the MMDs and the MMD 0 fallback. Errors from the
> reads of the per-MMD identifiers, which only happen once a device has
> answered, are still reported as -EIO.
>
> Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
> [...]
Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de>
Thanks,
Nicolai
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net-next v2 1/4] net: phy: Map C45 probe read errors to -ENODEV during bus scan
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
1 sibling, 1 reply; 14+ messages in thread
From: netdev-bot+sashiko @ 2026-11-19 0:37 UTC (permalink / raw)
To: florian.fainelli
Cc: netdev, carlos.soto, justin.chen, opendmb, nb,
bcm-kernel-feedback-list, andrew, hkallweit1, linux, davem,
edumazet, kuba, pabeni, linux-kernel, kudzo51
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
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 get_phy_c45_ids() (drivers/net/phy/phy_device.c), the first
MMD loop (lines 859-862) now returns get_phy_c45_probe_err(phy_reg),…
- [Low] The patch fixes a real, user-visible failure but has no Fixes:
tag.
- [Low] The kernel-doc of the exported phy_get_c45_ids()
(drivers/net/phy/phy_device.c:1091-1096) still says it returns '%-EIO…
--
net: phy: Map C45 probe read errors to -ENODEV during bus scan
This commit makes get_phy_c45_devs_in_pkg() return the raw bus error. In
get_phy_c45_ids(), an -EIO or -ENODEV from the devices in package reads is
now mapped to -ENODEV. A C45 bus scan can then skip empty addresses on
controllers that report a read from an empty address as a bus error.
> Let get_phy_c45_devs_in_pkg() return the bus error and apply the same
> mapping as get_phy_c22_id() to the two places that look for a device at an
> address: the loop over the MMDs and the MMD 0 fallback. Errors from the
> reads of the per-MMD identifiers, which only happen once a device has
> answered, are still reported as -EIO.
>
> Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
[Severity: Low]
Should this carry a Fixes: tag?
Commit 17b447539408 ("net: phy: c45 scanning: Don't consider -ENODEV
fatal") was meant to make the C45 scan treat -ENODEV as non-fatal. It only
changed the phy_c45_probe_present() call, on the assumption that this was
the first place a read occurs.
In get_phy_c45_ids(), the first read for an address is actually the MMD 1
devices in package read. phy_c45_probe_present() only runs for MMD 30/31.
Commit 6f533abe7bbad2 already fixed a related problem in the same mapping
and carries Fixes: 17b447539408.
This can be hit in mainline today, without the rest of the series.
orion_mdio_xsmi_read_c45() in drivers/net/ethernet/marvell/mvmdio.c
returns -ENODEV for an invalid read:
dev_err(bus->parent, "XSMI bus read not valid\n");
return -ENODEV;
Take a DT child with "ethernet-phy-ieee802.3-c45" at an address where no
PHY is present. Before this patch the path was:
fwnode_mdiobus_register_phy()
get_phy_device(is_c45=true)
get_phy_c45_ids()
get_phy_c45_devs_in_pkg() -> -ENODEV, returned as -EIO
__of_mdiobus_parse_phys() treats anything other than -ENODEV as fatal and
unregisters the whole MDIO bus.
Without the tag, stable kernels that carry 17b447539408 and 6f533abe7bbad2
keep the half-applied behaviour.
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index b39e945cebd73..4071041e1051d 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
[ ... ]
> @@ -789,17 +789,30 @@ static int get_phy_c45_devs_in_pkg(struct mii_bus *bus, int addr, int dev_addr,
[ ... ]
> +/* get_phy_c45_probe_err - map a bus error seen while looking for a device.
> + * @err: negative error code returned by a bus read
> + *
> + * Like get_phy_c22_id(), report -ENODEV when the bus read failed with -EIO or
> + * -ENODEV, which is how a controller signals that nothing answered at this
> + * address, so that bus scanning carries on with the next address. Anything
> + * else is reported as -EIO.
> + */
> +static int get_phy_c45_probe_err(int err)
> +{
> + return (err == -EIO || err == -ENODEV) ? -ENODEV : -EIO;
> +}
> +
[ ... ]
> @@ -845,7 +858,8 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr,
> }
> phy_reg = get_phy_c45_devs_in_pkg(bus, addr, i, &devs_in_pkg);
> if (phy_reg < 0)
> - return -EIO;
> + /* returning -ENODEV doesn't stop bus scanning */
> + return get_phy_c45_probe_err(phy_reg);
> }
[Severity: Medium]
Can this early return skip a device that is present but does not drive
the bus on the first MMD probed?
On a controller that samples the pull-up, an MMD that does not respond
reads as 0xffff. The loop then moves on to the next MMD, and after that to
the MMD 0 fallback.
On a controller that checks turnaround, the same MMD now ends the probe of
the whole address with -ENODEV. Examples are UniMAC, which returns -EIO on
MDIO_READ_FAIL and gets read_c45 later in this series ("net: mdio:
mdio-bcm-unimac: Add Clause 45 support"), and mvmdio XSMI, which returns
-ENODEV when READ_VALID is clear.
A Cortina CS4315/CS4340 style PHY only uses MMD 0:
drivers/net/phy/cortina.c:cortina_read_reg() {
return mdiobus_c45_read(phydev->mdio.bus, phydev->mdio.addr, 0, regnum);
}
On these controllers, can the MMD 0 fallback below ever be reached for such
a PHY, given that the MMD 1 read fails first?
A device can also answer MMD 1 with devs_in_pkg == 0x0000, which means it
drove MDIO low, and then fail turnaround on MMD 2. That failure is also
mapped to -ENODEV here. This seems to go against the commit message:
Errors from the reads of the per-MMD identifiers, which only happen
once a device has answered, are still reported as -EIO.
mdiobus_scan_bus_c45() then swallows the error:
phydev = mdiobus_scan_c45(bus, i);
if (IS_ERR(phydev) && (PTR_ERR(phydev) != -ENODEV))
return PTR_ERR(phydev);
So the device is dropped with no message. Before this patch, bus
registration failed and the problem was visible.
Would it work to treat the bus error the same way as a 0xffff reply? That
would mean continuing the loop, trying MMD 0, and returning -ENODEV only if
nothing answered, instead of returning early.
> @@ -855,7 +869,7 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr,
> */
> phy_reg = get_phy_c45_devs_in_pkg(bus, addr, 0, &devs_in_pkg);
> if (phy_reg < 0)
> - return -EIO;
> + return get_phy_c45_probe_err(phy_reg);
[Severity: Low]
Does the kernel-doc of the exported phy_get_c45_ids() still match after
this change? The doc for get_phy_c45_devs_in_pkg() was updated, but this
one still says:
* Returns zero on success, %-EIO on bus access error, or %-ENODEV if
* the "devices in package" is invalid.
*/
int phy_get_c45_ids(struct phy_device *phydev)
Both call sites in get_phy_c45_ids() now go through
get_phy_c45_probe_err(). A real bus -EIO on a PHY that already exists
therefore comes back as -ENODEV.
phy_get_c45_ids() is not a bus scan. gpy_probe() in mxl-gpy.c calls it on a
bound PHY and returns the result as its probe status:
if (!phydev->is_c45) {
ret = phy_get_c45_ids(phydev);
if (ret < 0)
return ret;
}
call_driver_probe() logs -ENODEV only with dev_dbg(), as "rejects match".
-EIO gets a dev_err().
Would a real MDIO bus fault during gpy_probe() now turn into a silent
failure to bind?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116213449.1682731-1-florian.fainelli%40broadcom.com
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH net-next v2 1/4] net: phy: Map C45 probe read errors to -ENODEV during bus scan
2026-11-19 0:37 ` netdev-bot+sashiko
@ 2026-11-19 0:48 ` Florian Fainelli
0 siblings, 0 replies; 14+ messages in thread
From: Florian Fainelli @ 2026-11-19 0:48 UTC (permalink / raw)
To: netdev-bot+sashiko
Cc: netdev, carlos.soto, justin.chen, opendmb, nb,
bcm-kernel-feedback-list, andrew, hkallweit1, linux, davem,
edumazet, kuba, pabeni, linux-kernel, kudzo51
On 11/18/26 16:37, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · Low: 2
>
> 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 get_phy_c45_ids() (drivers/net/phy/phy_device.c), the first
> MMD loop (lines 859-862) now returns get_phy_c45_probe_err(phy_reg),…
> - [Low] The patch fixes a real, user-visible failure but has no Fixes:
> tag.
> - [Low] The kernel-doc of the exported phy_get_c45_ids()
> (drivers/net/phy/phy_device.c:1091-1096) still says it returns '%-EIO…
>
> --
>
> net: phy: Map C45 probe read errors to -ENODEV during bus scan
>
> This commit makes get_phy_c45_devs_in_pkg() return the raw bus error. In
> get_phy_c45_ids(), an -EIO or -ENODEV from the devices in package reads is
> now mapped to -ENODEV. A C45 bus scan can then skip empty addresses on
> controllers that report a read from an empty address as a bus error.
>
>> Let get_phy_c45_devs_in_pkg() return the bus error and apply the same
>> mapping as get_phy_c22_id() to the two places that look for a device at an
>> address: the loop over the MMDs and the MMD 0 fallback. Errors from the
>> reads of the per-MMD identifiers, which only happen once a device has
>> answered, are still reported as -EIO.
>>
>> Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
>
> [Severity: Low]
> Should this carry a Fixes: tag?
Agreed, v4 adds:
Fixes: 17b447539408 ("net: phy: c45 scanning: Don't consider
-ENODEV fatal")
>
> Commit 17b447539408 ("net: phy: c45 scanning: Don't consider -ENODEV
> fatal") was meant to make the C45 scan treat -ENODEV as non-fatal. It only
> changed the phy_c45_probe_present() call, on the assumption that this was
> the first place a read occurs.
>
> In get_phy_c45_ids(), the first read for an address is actually the MMD 1
> devices in package read. phy_c45_probe_present() only runs for MMD 30/31.
> Commit 6f533abe7bbad2 already fixed a related problem in the same mapping
> and carries Fixes: 17b447539408.
>
> This can be hit in mainline today, without the rest of the series.
> orion_mdio_xsmi_read_c45() in drivers/net/ethernet/marvell/mvmdio.c
> returns -ENODEV for an invalid read:
>
> dev_err(bus->parent, "XSMI bus read not valid\n");
> return -ENODEV;
>
> Take a DT child with "ethernet-phy-ieee802.3-c45" at an address where no
> PHY is present. Before this patch the path was:
>
> fwnode_mdiobus_register_phy()
> get_phy_device(is_c45=true)
> get_phy_c45_ids()
> get_phy_c45_devs_in_pkg() -> -ENODEV, returned as -EIO
>
> __of_mdiobus_parse_phys() treats anything other than -ENODEV as fatal and
> unregisters the whole MDIO bus.
>
> Without the tag, stable kernels that carry 17b447539408 and 6f533abe7bbad2
> keep the half-applied behaviour.
>
>> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
>> index b39e945cebd73..4071041e1051d 100644
>> --- a/drivers/net/phy/phy_device.c
>> +++ b/drivers/net/phy/phy_device.c
>
> [ ... ]
>
>> @@ -789,17 +789,30 @@ static int get_phy_c45_devs_in_pkg(struct mii_bus *bus, int addr, int dev_addr,
>
> [ ... ]
>
>> +/* get_phy_c45_probe_err - map a bus error seen while looking for a device.
>> + * @err: negative error code returned by a bus read
>> + *
>> + * Like get_phy_c22_id(), report -ENODEV when the bus read failed with -EIO or
>> + * -ENODEV, which is how a controller signals that nothing answered at this
>> + * address, so that bus scanning carries on with the next address. Anything
>> + * else is reported as -EIO.
>> + */
>> +static int get_phy_c45_probe_err(int err)
>> +{
>> + return (err == -EIO || err == -ENODEV) ? -ENODEV : -EIO;
>> +}
>> +
>
> [ ... ]
>
>> @@ -845,7 +858,8 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr,
>> }
>> phy_reg = get_phy_c45_devs_in_pkg(bus, addr, i, &devs_in_pkg);
>> if (phy_reg < 0)
>> - return -EIO;
>> + /* returning -ENODEV doesn't stop bus scanning */
>> + return get_phy_c45_probe_err(phy_reg);
>> }
>
> [Severity: Medium]
> Can this early return skip a device that is present but does not drive
> the bus on the first MMD probed?
Yes, this was a legitimate issue. A PHY that only responds on MMD 0
(Cortina CS4315/CS4340) would never reach the MMD 0 fallback on a
controller that checks turnaround (UniMAC, mvmdio XSMI), because the MMD
1 read would terminate the probe of the whole address.
In v4, a failed "devices in package" read in the MMD loop (-EIO or
-ENODEV) is handled like an all-Fs reply: the loop moves on to the next
MMD and then to the MMD 0 fallback, and -ENODEV is only returned if
nothing answered.
Any other error code is still returned as -EIO immediately, and errors
on the per-MMD identifier reads are still -EIO, as the commit message says.
For a device that answers MMD 1 with 0x0000 and then fails turnaround on
MMD 2, the probe now also continues to MMD 0 rather than returning right
away. If MMD 0 does not answer either, it is dropped with -ENODEV. That
device violates turnaround, so I think this is acceptable.
>
> On a controller that samples the pull-up, an MMD that does not respond
> reads as 0xffff. The loop then moves on to the next MMD, and after that to
> the MMD 0 fallback.
>
> On a controller that checks turnaround, the same MMD now ends the probe of
> the whole address with -ENODEV. Examples are UniMAC, which returns -EIO on
> MDIO_READ_FAIL and gets read_c45 later in this series ("net: mdio:
> mdio-bcm-unimac: Add Clause 45 support"), and mvmdio XSMI, which returns
> -ENODEV when READ_VALID is clear.
>
> A Cortina CS4315/CS4340 style PHY only uses MMD 0:
>
> drivers/net/phy/cortina.c:cortina_read_reg() {
> return mdiobus_c45_read(phydev->mdio.bus, phydev->mdio.addr, 0, regnum);
> }
>
> On these controllers, can the MMD 0 fallback below ever be reached for such
> a PHY, given that the MMD 1 read fails first?
>
> A device can also answer MMD 1 with devs_in_pkg == 0x0000, which means it
> drove MDIO low, and then fail turnaround on MMD 2. That failure is also
> mapped to -ENODEV here. This seems to go against the commit message:
>
> Errors from the reads of the per-MMD identifiers, which only happen
> once a device has answered, are still reported as -EIO.
>
> mdiobus_scan_bus_c45() then swallows the error:
>
> phydev = mdiobus_scan_c45(bus, i);
> if (IS_ERR(phydev) && (PTR_ERR(phydev) != -ENODEV))
> return PTR_ERR(phydev);
>
> So the device is dropped with no message. Before this patch, bus
> registration failed and the problem was visible.
>
> Would it work to treat the bus error the same way as a 0xffff reply? That
> would mean continuing the loop, trying MMD 0, and returning -ENODEV only if
> nothing answered, instead of returning early.
>
>> @@ -855,7 +869,7 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr,
>> */
>> phy_reg = get_phy_c45_devs_in_pkg(bus, addr, 0, &devs_in_pkg);
>> if (phy_reg < 0)
>> - return -EIO;
>> + return get_phy_c45_probe_err(phy_reg);
>
> [Severity: Low]
> Does the kernel-doc of the exported phy_get_c45_ids() still match after
> this change? The doc for get_phy_c45_devs_in_pkg() was updated, but this
> one still says:
>
> * Returns zero on success, %-EIO on bus access error, or %-ENODEV if
> * the "devices in package" is invalid.
> */
> int phy_get_c45_ids(struct phy_device *phydev)
>
> Both call sites in get_phy_c45_ids() now go through
> get_phy_c45_probe_err(). A real bus -EIO on a PHY that already exists
> therefore comes back as -ENODEV.
>
> phy_get_c45_ids() is not a bus scan. gpy_probe() in mxl-gpy.c calls it on a
> bound PHY and returns the result as its probe status:
>
> if (!phydev->is_c45) {
> ret = phy_get_c45_ids(phydev);
> if (ret < 0)
> return ret;
> }
>
> call_driver_probe() logs -ENODEV only with dev_dbg(), as "rejects match".
> -EIO gets a dev_err().
>
> Would a real MDIO bus fault during gpy_probe() now turn into a silent
> failure to bind?
>
It did not; v4 updates the kernel-doc of both get_phy_c45_ids() and
phy_get_c45_ids(). On the gpy_probe() concern: a bus -EIO while looking
for a device is now reported as -ENODEV, the same mapping that
phy_c45_probe_present() already gets in this function. gpy_probe() runs
on a PHY that the scan already found, so I don't think this is a
practical regression and I would rather keep one mapping in
get_phy_c45_ids() than split it by caller. Happy to move it into
get_phy_device(), as the C22 path does, if reviewers prefer.
pw-bot: cr
--
Florian
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next v2 2/4] net: mdio: mdio-bcm-unimac: Define MDIO_OP_SHIFT
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-16 21:34 ` 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
` (4 subsequent siblings)
6 siblings, 0 replies; 14+ messages in thread
From: Florian Fainelli @ 2026-11-16 21:34 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Andrew Lunn, Nicolai Buchwitz, Doug Berger,
Broadcom internal kernel review list, Heiner Kallweit,
Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, open list, Mlody12 mlody12
The MDIO_CMD operation code field starts at bit 26. Define
MDIO_OP_SHIFT for it and use it to build the opcodes instead of open
coding the shift.
While at it, rename MDIO_RD and MDIO_WR to MDIO_RD_C22 and MDIO_WR_C22 to
make it clear that these are the Clause 22 opcodes, in preparation for
adding the Clause 45 ones.
No functional change.
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de>
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
drivers/net/mdio/mdio-bcm-unimac.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/net/mdio/mdio-bcm-unimac.c b/drivers/net/mdio/mdio-bcm-unimac.c
index 80fb3b5b52ab..5f79f31220f2 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -21,8 +21,9 @@
#define MDIO_CMD 0x00
#define MDIO_START_BUSY (1 << 29)
#define MDIO_READ_FAIL (1 << 28)
-#define MDIO_RD (2 << 26)
-#define MDIO_WR (1 << 26)
+#define MDIO_OP_SHIFT 26
+#define MDIO_RD_C22 (2 << MDIO_OP_SHIFT)
+#define MDIO_WR_C22 (1 << MDIO_OP_SHIFT)
#define MDIO_PMD_SHIFT 21
#define MDIO_PMD_MASK 0x1F
#define MDIO_REG_SHIFT 16
@@ -99,7 +100,8 @@ static int unimac_mdio_read(struct mii_bus *bus, int phy_id, int reg)
return ret;
/* Prepare the read operation */
- cmd = MDIO_RD | (phy_id << MDIO_PMD_SHIFT) | (reg << MDIO_REG_SHIFT);
+ cmd = MDIO_RD_C22 | (phy_id << MDIO_PMD_SHIFT) |
+ (reg << MDIO_REG_SHIFT);
unimac_mdio_writel(priv, cmd, MDIO_CMD);
/* Start MDIO transaction */
@@ -139,7 +141,7 @@ static int unimac_mdio_write(struct mii_bus *bus, int phy_id,
return ret;
/* Prepare the write operation */
- cmd = MDIO_WR | (phy_id << MDIO_PMD_SHIFT) |
+ cmd = MDIO_WR_C22 | (phy_id << MDIO_PMD_SHIFT) |
(reg << MDIO_REG_SHIFT) | (0xffff & val);
unimac_mdio_writel(priv, cmd, MDIO_CMD);
--
2.34.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH net-next v2 3/4] net: mdio: mdio-bcm-unimac: Poll for completion at 1us granularity
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-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 ` Florian Fainelli
2026-11-16 21:34 ` [PATCH net-next v2 4/4] net: mdio: mdio-bcm-unimac: Add Clause 45 support Florian Fainelli
` (3 subsequent siblings)
6 siblings, 0 replies; 14+ messages in thread
From: Florian Fainelli @ 2026-11-16 21:34 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Andrew Lunn, Nicolai Buchwitz, Carlos Soto,
Doug Berger, Broadcom internal kernel review list,
Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, open list, Mlody12 mlody12
The current polling code unconditionally waits 30us, which was sized for
a ~25us Clause 22 transaction, and then polls MDIO_CMD with a sleep of up
to 2ms between samples.
Adding Clause 45 support means that every access becomes two back to back
transactions (an ADDR cycle followed by a READ/WRITE cycle), so a fixed
delay sized for a single C22 transaction is no longer meaningful, and a
sleep of up to 2ms between samples can add significant latency to each
access when the transaction has not completed at the first sample.
Instead, poll the MDIO_START_BUSY bit every microsecond so that the
completion is noticed as soon as it happens, regardless of the type of
transaction. This turns the wait into a busy wait, which is bounded by a
timeout reduced from 100ms to 1ms: a 64 bit MDIO frame takes about 33us at
the lowest MDIO clock the driver can program from a 250MHz reference clock,
so even a two frame C45 access completes well within that.
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de>
Co-developed-by: Carlos Soto <carlos.soto@broadcom.com>
Signed-off-by: Carlos Soto <carlos.soto@broadcom.com>
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
drivers/net/mdio/mdio-bcm-unimac.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/drivers/net/mdio/mdio-bcm-unimac.c b/drivers/net/mdio/mdio-bcm-unimac.c
index 5f79f31220f2..df267bb82696 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -6,8 +6,8 @@
*/
#include <linux/clk.h>
-#include <linux/delay.h>
#include <linux/io.h>
+#include <linux/iopoll.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
@@ -36,6 +36,13 @@
#define MDIO_CLK_DIV_MASK 0x3F
#define MDIO_SUPP_PREAMBLE (1 << 12)
+/* 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.
+ */
+#define MDIO_POLL_DELAY_US 1
+#define MDIO_POLL_TIMEOUT_US 1000
+
struct unimac_mdio_priv {
struct mii_bus *mii_bus;
void __iomem *base;
@@ -79,14 +86,14 @@ static int unimac_mdio_poll(void *wait_func_data)
struct unimac_mdio_priv *priv = wait_func_data;
u32 val;
- /*
- * C22 transactions should take ~25 usec, will need to adjust
- * if C45 support is added.
+ /* C22 transactions should take ~25 usec, C45 transactions take about
+ * twice as long since they need an address and a data cycle.
*/
- udelay(30);
-
- return read_poll_timeout(unimac_mdio_readl, val, !(val & MDIO_START_BUSY),
- 2000, 100000, false, priv, MDIO_CMD);
+ return read_poll_timeout_atomic(unimac_mdio_readl, val,
+ !(val & MDIO_START_BUSY),
+ MDIO_POLL_DELAY_US,
+ MDIO_POLL_TIMEOUT_US, false, priv,
+ MDIO_CMD);
}
static int unimac_mdio_read(struct mii_bus *bus, int phy_id, int reg)
--
2.34.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH net-next v2 4/4] net: mdio: mdio-bcm-unimac: Add Clause 45 support
2026-11-16 21:34 [PATCH net-next v2 0/4] net: mdio: Clause 45 support for mdio-bcm-unimac Florian Fainelli
` (2 preceding siblings ...)
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 ` Florian Fainelli
2026-11-17 12:36 ` Nicolai Buchwitz
2026-11-19 0:37 ` netdev-bot+sashiko
2026-11-16 22:38 ` [PATCH net-next v2 0/4] net: mdio: Clause 45 support for mdio-bcm-unimac Kordian Chmielewski
` (2 subsequent siblings)
6 siblings, 2 replies; 14+ messages in thread
From: Florian Fainelli @ 2026-11-16 21:34 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Carlos Soto, Justin Chen, Doug Berger,
Nicolai Buchwitz, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, open list,
Mlody12 mlody12
Add Clause 45 read/write support to the UniMAC MDIO bus controller driver
by implementing the read_c45/write_c45 bus callbacks. Each access performs
the two-step C45 sequence (ADDR cycle followed by a READ/WRITE cycle) under
the bus lock and switches MDIO_CFG between C22 and C45 mode as needed;
MDIO_CFG is only written when the mode actually changes.
Also skip the BMSR workaround read in unimac_mdio_reset() for children
compatible with "ethernet-phy-ieee802.3-c45", since such PHYs are not
expected to respond to C22 accesses.
Note that providing read_c45/write_c45 also makes the MDIO core scan for
C45 PHYs at registration time, on addresses that are not masked and do not
already have a C22 device.
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
Co-developed-by: Carlos Soto <carlos.soto@broadcom.com>
Signed-off-by: Carlos Soto <carlos.soto@broadcom.com>
Co-developed-by: Justin Chen <justin.chen@broadcom.com>
Signed-off-by: Justin Chen <justin.chen@broadcom.com>
---
drivers/net/mdio/mdio-bcm-unimac.c | 105 +++++++++++++++++++++++++++--
1 file changed, 98 insertions(+), 7 deletions(-)
diff --git a/drivers/net/mdio/mdio-bcm-unimac.c b/drivers/net/mdio/mdio-bcm-unimac.c
index df267bb82696..6059b32580c5 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -24,10 +24,16 @@
#define MDIO_OP_SHIFT 26
#define MDIO_RD_C22 (2 << MDIO_OP_SHIFT)
#define MDIO_WR_C22 (1 << MDIO_OP_SHIFT)
+#define MDIO_ADDR_C45 (0 << MDIO_OP_SHIFT)
+#define MDIO_WR_C45 (1 << MDIO_OP_SHIFT)
+#define MDIO_RD_C45 (3 << MDIO_OP_SHIFT)
#define MDIO_PMD_SHIFT 21
#define MDIO_PMD_MASK 0x1F
#define MDIO_REG_SHIFT 16
#define MDIO_REG_MASK 0x1F
+#define MDIO_DEVAD_SHIFT 16
+#define MDIO_DEVAD_MASK GENMASK(20, 16)
+#define MDIO_C45_REG_MASK GENMASK(15, 0)
#define MDIO_CFG 0x04
#define MDIO_C22 (1 << 0)
@@ -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);
+}
+
+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);
+}
+
+static int unimac_mdio_do_read(struct mii_bus *bus, int phy_id, int devad,
+ int reg, bool is_c45)
{
struct unimac_mdio_priv *priv = bus->priv;
int ret;
@@ -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);
+ } else {
+ cmd = MDIO_RD_C22 | (phy_id << MDIO_PMD_SHIFT) |
+ (reg << MDIO_REG_SHIFT);
+ }
unimac_mdio_writel(priv, cmd, MDIO_CMD);
/* Start MDIO transaction */
@@ -136,8 +189,8 @@ static int unimac_mdio_read(struct mii_bus *bus, int phy_id, int reg)
return ret;
}
-static int unimac_mdio_write(struct mii_bus *bus, int phy_id,
- int reg, u16 val)
+static int unimac_mdio_do_write(struct mii_bus *bus, int phy_id, int devad,
+ int reg, u16 val, bool is_c45)
{
struct unimac_mdio_priv *priv = bus->priv;
u32 cmd;
@@ -148,18 +201,50 @@ static int unimac_mdio_write(struct mii_bus *bus, int phy_id,
return ret;
/* Prepare the write operation */
- cmd = MDIO_WR_C22 | (phy_id << MDIO_PMD_SHIFT) |
- (reg << MDIO_REG_SHIFT) | (0xffff & val);
+ 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_WR_C45 | (phy_id << MDIO_PMD_SHIFT) |
+ unimac_mdio_c45_devad(devad) | (0xffff & val);
+ } else {
+ cmd = MDIO_WR_C22 | (phy_id << MDIO_PMD_SHIFT) |
+ (reg << MDIO_REG_SHIFT) | (0xffff & val);
+ }
unimac_mdio_writel(priv, cmd, MDIO_CMD);
unimac_mdio_start(priv);
ret = priv->wait_func(priv->wait_func_data);
+out:
clk_disable_unprepare(priv->clk);
return ret;
}
+static int unimac_mdio_read(struct mii_bus *bus, int phy_id, int reg)
+{
+ return unimac_mdio_do_read(bus, phy_id, 0, reg, false);
+}
+
+static int unimac_mdio_write(struct mii_bus *bus, int phy_id, int reg, u16 val)
+{
+ return unimac_mdio_do_write(bus, phy_id, 0, reg, val, false);
+}
+
+static int unimac_mdio_read_c45(struct mii_bus *bus, int addr, int dev, int reg)
+{
+ return unimac_mdio_do_read(bus, addr, dev, reg, true);
+}
+
+static int unimac_mdio_write_c45(struct mii_bus *bus, int addr, int dev,
+ int reg, u16 val)
+{
+ return unimac_mdio_do_write(bus, addr, dev, reg, val, true);
+}
+
/* Workaround for integrated BCM7xxx Gigabit PHYs which have a problem with
* their internal MDIO management controller making them fail to successfully
* be read from or written to for the first transaction. We insert a dummy
@@ -190,6 +275,10 @@ static int unimac_mdio_reset(struct mii_bus *bus)
if (addr < 0)
continue;
+ if (of_device_is_compatible(child,
+ "ethernet-phy-ieee802.3-c45"))
+ continue;
+
read_mask |= 1 << addr;
}
}
@@ -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;
bus->reset = unimac_mdio_reset;
snprintf(bus->id, MII_BUS_ID_SIZE, "%s-%d", pdev->name, pdev->id);
--
2.34.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH net-next v2 4/4] net: mdio: mdio-bcm-unimac: Add Clause 45 support
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
1 sibling, 0 replies; 14+ messages in thread
From: Nicolai Buchwitz @ 2026-11-17 12:36 UTC (permalink / raw)
To: Florian Fainelli
Cc: netdev, Carlos Soto, Justin Chen, Doug Berger,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, linux-kernel, Mlody12 mlody12
On 16.11.2026 22:34, Florian Fainelli wrote:
> Add Clause 45 read/write support to the UniMAC MDIO bus controller
> driver
> by implementing the read_c45/write_c45 bus callbacks. Each access
> performs
> the two-step C45 sequence (ADDR cycle followed by a READ/WRITE cycle)
> under
> the bus lock and switches MDIO_CFG between C22 and C45 mode as needed;
> MDIO_CFG is only written when the mode actually changes.
>
> Also skip the BMSR workaround read in unimac_mdio_reset() for children
> compatible with "ethernet-phy-ieee802.3-c45", since such PHYs are not
> expected to respond to C22 accesses.
>
> Note that providing read_c45/write_c45 also makes the MDIO core scan
> for
> C45 PHYs at registration time, on addresses that are not masked and do
> not
> already have a C22 device.
>
> Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
> Co-developed-by: Carlos Soto <carlos.soto@broadcom.com>
> Signed-off-by: Carlos Soto <carlos.soto@broadcom.com>
> Co-developed-by: Justin Chen <justin.chen@broadcom.com>
> Signed-off-by: Justin Chen <justin.chen@broadcom.com>
> [...]
Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de>
Thanks,
Nicolai
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net-next v2 4/4] net: mdio: mdio-bcm-unimac: Add Clause 45 support
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
2026-11-19 0:53 ` Florian Fainelli
1 sibling, 1 reply; 14+ messages in thread
From: netdev-bot+sashiko @ 2026-11-19 0:37 UTC (permalink / raw)
To: florian.fainelli
Cc: netdev, carlos.soto, justin.chen, opendmb, nb,
bcm-kernel-feedback-list, andrew, hkallweit1, linux, davem,
edumazet, kuba, pabeni, linux-kernel, kudzo51
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
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH net-next v2 4/4] net: mdio: mdio-bcm-unimac: Add Clause 45 support
2026-11-19 0:37 ` netdev-bot+sashiko
@ 2026-11-19 0:53 ` Florian Fainelli
0 siblings, 0 replies; 14+ messages in thread
From: Florian Fainelli @ 2026-11-19 0:53 UTC (permalink / raw)
To: netdev-bot+sashiko
Cc: netdev, carlos.soto, justin.chen, opendmb, nb,
bcm-kernel-feedback-list, andrew, hkallweit1, linux, davem,
edumazet, kuba, pabeni, linux-kernel, kudzo51
On 11/18/26 16:37, netdev-bot+sashiko@kernel.org wrote:
> 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.
This was a real problem for wait_func implementations that return 0
without the controller being idle (bcmgenet_mii_wait()). It is fixed in
the next version: unimac_mdio_addr_c45() now polls MDIO_CMD for
START_BUSY to clear after wait_func returns, so the READ/WRITE frame is
never started while the ADDR frame is still on the wire.
> - [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…
Also valid, and fixed in the next version: unimac_mdio_resume() now
takes bus->mdio_lock around unimac_mdio_clk_set(), so the two MDIO_CFG
read-modify-writes are serialized.
> - [Low] This patch changes behaviour for existing users of the non-DT
> (ACPI) GENET path more than the commit message says.
The C45 scan does run there, since that instance does not mask any
address. It only probes addresses that have no C22 device, so it cannot
take the place of the C22 PHY that phy_find_first() returns on those
systems. The commit message now says so. The scan is also cheaper than
it was, since patch 1 now stops after a failing MMD and goes straight to
the MMD 0 probe.
> - [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…
Reworded in the next version, along with the comment in
unimac_mdio_poll(), to say that the timeout applies to each frame.
> - [Low] The driver now enables C45 on every controller it binds.
AFAICT, all controller HW support C45 and have the definitions for the
bits we are using.
pw-bot: cr
--
Florian
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net-next v2 0/4] net: mdio: Clause 45 support for mdio-bcm-unimac
2026-11-16 21:34 [PATCH net-next v2 0/4] net: mdio: Clause 45 support for mdio-bcm-unimac Florian Fainelli
` (3 preceding siblings ...)
2026-11-16 21:34 ` [PATCH net-next v2 4/4] net: mdio: mdio-bcm-unimac: Add Clause 45 support Florian Fainelli
@ 2026-11-16 22:38 ` Kordian Chmielewski
2026-11-17 12:36 ` Nicolai Buchwitz
2026-11-17 23:17 ` Florian Fainelli
6 siblings, 0 replies; 14+ messages in thread
From: Kordian Chmielewski @ 2026-11-16 22:38 UTC (permalink / raw)
To: Florian Fainelli
Cc: netdev, Doug Berger, Nicolai Buchwitz,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, open list
On Mon, 16 Nov 2026 13:34:45 -0800, Florian Fainelli wrote:
> This patch series adds support for Clause 45 MDIO operations within the
> mdio-bcm-unimac driver.
Tested v2 on the same TP-Link Archer AX6000 (BCM4908) with OpenWrt and
Linux 6.18.55, again in place of our own C45 support. Patch 1 needed the
context of one hunk adjusted to apply there, because OpenWrt carries a
hack patch that adds a function right after get_phy_c45_devs_in_pkg();
the added and removed lines are unchanged.
The BCM54991E at address 0x1d, which our out-of-tree PHY driver switches
to C45 in probe, still takes its firmware over C45 and links at 1000
Mbit/s, the link comes back after ethtool -r, and 8400 C45 reads through
SIOCGMIIREG gave no errors.
This bus is registered from DT, so the C45 scan does not run on it. For
patch 1, a test module registered a bus without DT whose reads go to the
UniMAC bus and whose writes fail, with read_c45 set and phy_mask leaving
only three empty addresses. On this UniMAC, a C22 or C45 read from an
empty address fails with -EIO. With v1, get_phy_device() for C45
returned -EIO there and mdiobus_register() failed with -EIO. With v2 it
returns -ENODEV, and the bus registers with no PHY found, as it does
with C22 alone.
The new check in unimac_mdio_reset() still never matches here, as no
node on this bus has the ethernet-phy-ieee802.3-c45 compatible; the
PHY's node has only its ID compatible.
Tested-by: Kordian Chmielewski <kudzo51@gmail.com>
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH net-next v2 0/4] net: mdio: Clause 45 support for mdio-bcm-unimac
2026-11-16 21:34 [PATCH net-next v2 0/4] net: mdio: Clause 45 support for mdio-bcm-unimac Florian Fainelli
` (4 preceding siblings ...)
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
6 siblings, 0 replies; 14+ messages in thread
From: Nicolai Buchwitz @ 2026-11-17 12:36 UTC (permalink / raw)
To: Florian Fainelli
Cc: netdev, Doug Berger, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-kernel,
Mlody12 mlody12
On 16.11.2026 22:34, Florian Fainelli wrote:
> This patch series adds support for Clause 45 MDIO operations within the
> mdio-bcm-unimac driver. The series breaks things up in this way:
>
> - make the C45 bus scan done by the MDIO core carry on when nothing
> answers at an address, as the C22 scan already does
> - scope the existing defines to make it clear what is C22 vs. C45
> specific
> - rework the polling completion loop to be a tighter loop
> - add support for clause 45 operations
>
> Changes in v2:
>
> - add patch 1, since providing read_c45/write_c45 makes the MDIO core
> scan
> for C45 PHYs on all addresses that are not masked. On a bus
> registered
> without a device tree node (e.g.: GENET with ACPI) a read from an
> empty
> address fails with -EIO, which get_phy_c45_ids() passed up instead of
> mapping it to -ENODEV, and made the whole bus registration fail.
> Reported
> by Nicolai Buchwitz.
> - patches 2 and 3: collect Reviewed-by tags from Andrew Lunn and
> Nicolai
> Buchwitz, no code changes
> - patch 4: no code changes
>
> Florian Fainelli (4):
> net: phy: Map C45 probe read errors to -ENODEV during bus scan
> net: mdio: mdio-bcm-unimac: Define MDIO_OP_SHIFT
> net: mdio: mdio-bcm-unimac: Poll for completion at 1us granularity
> net: mdio: mdio-bcm-unimac: Add Clause 45 support
>
> drivers/net/mdio/mdio-bcm-unimac.c | 130 +++++++++++++++++++++++++----
> drivers/net/phy/phy_device.c | 24 ++++--
> 2 files changed, 134 insertions(+), 20 deletions(-)
For the series:
Tested-by: Nicolai Buchwitz <nb@tipi-net.de> # Raspberry Pi CM4
(BCM2711)
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH net-next v2 0/4] net: mdio: Clause 45 support for mdio-bcm-unimac
2026-11-16 21:34 [PATCH net-next v2 0/4] net: mdio: Clause 45 support for mdio-bcm-unimac Florian Fainelli
` (5 preceding siblings ...)
2026-11-17 12:36 ` Nicolai Buchwitz
@ 2026-11-17 23:17 ` Florian Fainelli
6 siblings, 0 replies; 14+ messages in thread
From: Florian Fainelli @ 2026-11-17 23:17 UTC (permalink / raw)
To: netdev
Cc: Doug Berger, Nicolai Buchwitz,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, open list, Mlody12 mlody12
On 11/16/26 13:34, Florian Fainelli wrote:
> This patch series adds support for Clause 45 MDIO operations within the
> mdio-bcm-unimac driver. The series breaks things up in this way:
>
> - make the C45 bus scan done by the MDIO core carry on when nothing
> answers at an address, as the C22 scan already does
> - scope the existing defines to make it clear what is C22 vs. C45
> specific
> - rework the polling completion loop to be a tighter loop
> - add support for clause 45 operations
>
> Changes in v2:
>
> - add patch 1, since providing read_c45/write_c45 makes the MDIO core scan
> for C45 PHYs on all addresses that are not masked. On a bus registered
> without a device tree node (e.g.: GENET with ACPI) a read from an empty
> address fails with -EIO, which get_phy_c45_ids() passed up instead of
> mapping it to -ENODEV, and made the whole bus registration fail. Reported
> by Nicolai Buchwitz.
> - patches 2 and 3: collect Reviewed-by tags from Andrew Lunn and Nicolai
> Buchwitz, no code changes
> - patch 4: no code changes
>
> Florian Fainelli (4):
> net: phy: Map C45 probe read errors to -ENODEV during bus scan
> net: mdio: mdio-bcm-unimac: Define MDIO_OP_SHIFT
> net: mdio: mdio-bcm-unimac: Poll for completion at 1us granularity
> net: mdio: mdio-bcm-unimac: Add Clause 45 support
>
> drivers/net/mdio/mdio-bcm-unimac.c | 130 +++++++++++++++++++++++++----
> drivers/net/phy/phy_device.c | 24 ++++--
> 2 files changed, 134 insertions(+), 20 deletions(-)
>
Sashiko pointed some valid issues commenting on v1, and has not reviewed
v2 yet which does not incorporate all of the feedback. There will be a
v3 submitted that incorporates the received feedback.
pw-bot: cr
--
Florian
^ permalink raw reply [flat|nested] 14+ messages in thread