[PATCH net v10 1/4] net: usb: lan78xx: register the PHY interrupt with the MDIO bus
From: Aleksei Sviridkin
Date: Tue Sep 22 2026 - 11:29:34 EST
The interrupt this driver maps for its PHY is written only into
phydev->irq, while the bus table mdiobus->irq[] keeps reading PHY_POLL
for the same address. That table is where phylib records what the bus
described - phy_device_create() seeds phydev->irq from it - so the
number lives only as long as nothing else writes that one field.
Put it in the table before the bus is registered, so that the PHY the
scan creates is born with the number, and drop the write to phydev->irq
that phylib then makes by itself. Fill the whole table rather than one
entry: for 7801 the address is not known until the scan, and for the
other two phy_mask leaves only address 1 readable, so a loop costs less
than a second switch on the chip id. A devicetree PHY node still
overrides that.
Found going through the drivers that keep a PHY interrupt outside the
bus table, so that the restore on detach later in this series has a
number to hand back here as well.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@xxxxxx>
---
Notes:
Compile-tested only; I have no LAN78xx device.
No Fixes: tag on this one. On its own it fixes nothing - nothing reads the
bus table back until patch 3 - which is also why it sorts ahead of that
patch rather than after it.
lan78xx_setup_irq_domain() runs before lan78xx_mdio_init() in
lan78xx_bind(), so the number is already mapped where the table is filled.
The fill covers the whole table because only the 7801 case leaves the
address open until of_mdiobus_register() has scanned; 7800 and 7850 set
phy_mask a few lines above, so every entry but address 1 is unreachable
and writing them costs nothing.
The fill is a default rather than an override. For a PHY node that
describes an interrupt, fwnode_mdiobus_phy_device_register() writes the
devicetree number over the table entry, and into phydev->irq, once the
device exists. That inverts the old order, where the driver's own number
was written last and won. Neither in-tree lan78xx PHY node carries an
interrupts property, so nothing in tree changes, but a devicetree that
described one would now be believed.
Teardown order keeps the number live for as long as it is read:
lan78xx_disconnect() detaches the PHY through phylink_disconnect_phy(), and
lan78xx_unbind() calls lan78xx_remove_irq_domain() only afterwards.
drivers/net/usb/lan78xx.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index cb782d81d84f..d7472d894c8d 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -2092,6 +2092,7 @@ static int lan78xx_mdio_init(struct lan78xx_net *dev)
{
struct device_node *node;
int ret;
+ int i;
dev->mdiobus = mdiobus_alloc();
if (!dev->mdiobus) {
@@ -2118,6 +2119,10 @@ static int lan78xx_mdio_init(struct lan78xx_net *dev)
break;
}
+ if (dev->domain_data.phyirq > 0)
+ for (i = 0; i < PHY_MAX_ADDR; i++)
+ dev->mdiobus->irq[i] = dev->domain_data.phyirq;
+
node = of_get_child_by_name(dev->udev->dev.of_node, "mdio");
ret = of_mdiobus_register(dev->mdiobus, node);
of_node_put(node);
@@ -2892,13 +2897,6 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
return 0;
}
- /* if phyirq is not set, use polling mode in phylib */
- if (dev->domain_data.phyirq > 0)
- phydev->irq = dev->domain_data.phyirq;
- else
- phydev->irq = PHY_POLL;
- netdev_dbg(dev->net, "phydev->irq = %d\n", phydev->irq);
-
ret = phylink_connect_phy(dev->phylink, phydev);
if (ret) {
netdev_err(dev->net, "can't attach PHY to %s, error %pe\n",
--
2.53.0