Linux USB
 help / color / mirror / Atom feed
* [PATCH net-next] net: usb: name usb ethernet mdio buses reliably
@ 2026-11-09 16:56 Blake Alexander via B4 Relay
  2026-11-10 17:02 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Blake Alexander via B4 Relay @ 2026-11-09 16:56 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Thangaraj Samynathan, UNGLinuxDriver
  Cc: linux-usb, netdev, linux-kernel, Blake Alexander

From: Blake Alexander <blake.alexander@airbus.com>

Embedded systems may utilize fixed USB ethernet controllers (such as the
LAN78xx series) which are soldered directly onto the board. Currently,
the MDIO bus names for USB ethernet devices are non-deterministic as
they rely on the USB bus and device numbers (e.g.
"usb-${bus_num}:${dev_num}").

For hot-pluggable devices a stable MDIO bus name cannot be assumed.
However, for systems using fixed devices, user-space configuration
scripts and tools require predictable bus names.

Use usb_make_path() to generate the MDIO bus name instead, ensuring a
predictable and deterministic bus naming scheme when attached at the
same position within the USB hierarchy.

Signed-off-by: Blake Alexander <blake.alexander@airbus.com>
---
 drivers/net/usb/asix_devices.c | 5 ++---
 drivers/net/usb/ax88172a.c     | 5 ++---
 drivers/net/usb/lan78xx.c      | 3 +--
 3 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index 293ef80c4e30..c752fa3868b8 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -680,9 +680,8 @@ static int ax88772_init_mdio(struct usbnet *dev)
 	priv->mdio->write = &asix_mdio_bus_write;
 	priv->mdio->name = "Asix MDIO Bus";
 	priv->mdio->phy_mask = ~(BIT(priv->phy_addr & 0x1f) | BIT(AX_EMBD_PHY_ADDR));
-	/* mii bus name is usb-<usb bus number>-<usb device number> */
-	snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
-		 dev->udev->bus->busnum, dev->udev->devnum);
+
+	usb_make_path(dev->udev, priv->mdio->id, MII_BUS_ID_SIZE);
 
 	ret = mdiobus_register(priv->mdio);
 	if (ret) {
diff --git a/drivers/net/usb/ax88172a.c b/drivers/net/usb/ax88172a.c
index f5036451f086..9f050de0cddb 100644
--- a/drivers/net/usb/ax88172a.c
+++ b/drivers/net/usb/ax88172a.c
@@ -73,9 +73,8 @@ static int ax88172a_init_mdio(struct usbnet *dev)
 	priv->mdio->read = &asix_mdio_bus_read;
 	priv->mdio->write = &asix_mdio_bus_write;
 	priv->mdio->name = "Asix MDIO Bus";
-	/* mii bus name is usb-<usb bus number>-<usb device number> */
-	snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
-		 dev->udev->bus->busnum, dev->udev->devnum);
+
+	usb_make_path(dev->udev, priv->mdio->id, MII_BUS_ID_SIZE);
 
 	ret = mdiobus_register(priv->mdio);
 	if (ret) {
diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index d73002b2c21a..153aa56b8e68 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -2117,8 +2117,7 @@ static int lan78xx_mdio_init(struct lan78xx_net *dev)
 	dev->mdiobus->name = "lan78xx-mdiobus";
 	dev->mdiobus->parent = &dev->udev->dev;
 
-	snprintf(dev->mdiobus->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
-		 dev->udev->bus->busnum, dev->udev->devnum);
+	usb_make_path(dev->udev, dev->mdiobus->id, MII_BUS_ID_SIZE);
 
 	switch (dev->chipid) {
 	case ID_REV_CHIP_ID_7800_:

---
base-commit: fa5196392691051963726787944db872420dfa75
change-id: 20261109-net-usb-mdio-naming-cb32f6805c36

Best regards,
--  
Blake Alexander <blake.alexander@airbus.com>



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] net: usb: name usb ethernet mdio buses reliably
  2026-11-09 16:56 [PATCH net-next] net: usb: name usb ethernet mdio buses reliably Blake Alexander via B4 Relay
@ 2026-11-10 17:02 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-10 17:02 UTC (permalink / raw)
  To: Blake Alexander; +Cc: linux-usb

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] net: usb: MDIO bus name collision via usb_make_path() on
  shared bus_name
- [Low] net: usb: missing usb_make_path() MDIO bus naming in
  smsc95xx_bind()
--

commit 29b6f41fcf0619fc5074a9aed4a761b5bff3fdf8
Author: Blake Alexander <blake.alexander@airbus.com>

net: usb: name usb ethernet mdio buses reliably

This commit replaces the "usb-%03d:%03d" MDIO bus naming in asix_devices,
ax88172a, and lan78xx with usb_make_path() so that USB Ethernet devices at
fixed topology positions receive deterministic MDIO bus names.

> diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
> index 293ef80c4e302..c752fa3868b81 100644
> --- a/drivers/net/usb/asix_devices.c
> +++ b/drivers/net/usb/asix_devices.c
> @@ -680,9 +680,8 @@ static int ax88772_init_mdio(struct usbnet *dev)
>  	priv->mdio->write = &asix_mdio_bus_write;
>  	priv->mdio->name = "Asix MDIO Bus";
>  	priv->mdio->phy_mask = ~(BIT(priv->phy_addr & 0x1f) | BIT(AX_EMBD_PHY_ADDR));
> -	/* mii bus name is usb-<usb bus number>-<usb device number> */
> -	snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
> -		 dev->udev->bus->busnum, dev->udev->devnum);
> +
> +	usb_make_path(dev->udev, priv->mdio->id, MII_BUS_ID_SIZE);
>  
>  	ret = mdiobus_register(priv->mdio);
>  	if (ret) {
> diff --git a/drivers/net/usb/ax88172a.c b/drivers/net/usb/ax88172a.c
> index f5036451f0869..9f050de0cddbd 100644
> --- a/drivers/net/usb/ax88172a.c
> +++ b/drivers/net/usb/ax88172a.c
> @@ -73,9 +73,8 @@ static int ax88172a_init_mdio(struct usbnet *dev)
>  	priv->mdio->read = &asix_mdio_bus_read;
>  	priv->mdio->write = &asix_mdio_bus_write;
>  	priv->mdio->name = "Asix MDIO Bus";
> -	/* mii bus name is usb-<usb bus number>-<usb device number> */
> -	snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
> -		 dev->udev->bus->busnum, dev->udev->devnum);
> +
> +	usb_make_path(dev->udev, priv->mdio->id, MII_BUS_ID_SIZE);
>  
>  	ret = mdiobus_register(priv->mdio);
>  	if (ret) {
> diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
> index d73002b2c21ac..153aa56b8e681 100644
> --- a/drivers/net/usb/lan78xx.c
> +++ b/drivers/net/usb/lan78xx.c
> @@ -2117,8 +2117,7 @@ static int lan78xx_mdio_init(struct lan78xx_net *dev)
>  	dev->mdiobus->name = "lan78xx-mdiobus";
>  	dev->mdiobus->parent = &dev->udev->dev;
>  
> -	snprintf(dev->mdiobus->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
> -		 dev->udev->bus->busnum, dev->udev->devnum);
> +	usb_make_path(dev->udev, dev->mdiobus->id, MII_BUS_ID_SIZE);
>  
>  	switch (dev->chipid) {
>  	case ID_REV_CHIP_ID_7800_:

[Severity: Medium]
Can usb_make_path() produce duplicate mii_bus->id strings across the USB
2.0 and USB 3.0 buses of an xHCI controller?

usb_make_path() formats "usb-%s-%s" from udev->bus->bus_name and
udev->devpath, omitting udev->bus->busnum.  Dual-roothub xHCI drivers
(such as xhci-pci and xhci-plat) register both the USB 2.0 main_hcd and
the USB 3.0 shared_hcd with the same controller device name as bus_name,
and number their roothub ports independently starting at 1:

drivers/usb/host/xhci-pci.c:xhci_pci_common_probe() {
	...
	xhci->shared_hcd = usb_create_shared_hcd(&xhci_pci_hc_driver, &dev->dev,
						 pci_name(dev), hcd);
}

When a USB 2.0 adapter on main_hcd and a SuperSpeed adapter (such as a
LAN7800) on shared_hcd sit at the same relative devpath (for example,
when USB 2.0 port N and USB 3.0 port N map to different physical
connectors or match behind downstream hubs), both receive the same
mii_bus->id.  __mdiobus_register() then fails with -EEXIST in
device_register(&bus->dev), causing probe or bind of the second network
interface to fail.

[Severity: Low]
Should smsc95xx_bind() also be updated to match the other USB Ethernet
MDIO bus drivers?

drivers/net/usb/smsc95xx.c:smsc95xx_bind() still formats
pdata->mdiobus->id using busnum and devnum, even though it already uses
usb_make_path() earlier in the same function for its IRQ domain fwnode:

drivers/net/usb/smsc95xx.c:smsc95xx_bind() {
	...
	snprintf(pdata->mdiobus->id, ARRAY_SIZE(pdata->mdiobus->id),
		 "usb-%03d:%03d", dev->udev->bus->busnum, dev->udev->devnum);
}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261109-net-usb-mdio-naming-v1-1-f4cca6737784@airbus.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-10 17:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-09 16:56 [PATCH net-next] net: usb: name usb ethernet mdio buses reliably Blake Alexander via B4 Relay
2026-11-10 17:02 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox