From: Aleksei Sviridkin <f@lex.la>
To: netdev@vger.kernel.org
Cc: andrew@lunn.ch, andrew+netdev@lunn.ch, hkallweit1@gmail.com,
linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
olteanv@gmail.com, Thangaraj.S@microchip.com,
UNGLinuxDriver@microchip.com, steve.glendinning@shawell.net,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Aleksei Sviridkin <f@lex.la>
Subject: [PATCH net v9 3/4] net: phy: take the interrupt back from the bus on detach
Date: Sat, 19 Sep 2026 04:53:25 +0300 [thread overview]
Message-ID: <20260919015326.499479-4-f@lex.la> (raw)
In-Reply-To: <20260919015326.499479-1-f@lex.la>
A PHY whose own driver is a module on a filesystem that is not mounted
when the MAC probes gets the generic driver first. phy_probe() replaces
phydev->irq with PHY_POLL because that driver has no interrupt support,
nothing puts it back, and the PHY polls for the rest of the uptime once
its real driver takes over. That is where an MT7981B board here
stands, with an Airoha EN8811H behind an MT7531 port and its driver on
the root filesystem: the devicetree gives the PHY interrupt 15, and
once the real driver has taken over the field reads -1.
Take the number back in phy_detach(), from mdiobus->irq[], which is
where phy_device_create() seeded phydev->irq from and where the bus that
described the interrupt still holds it.
Do it before device_release_driver() rather than after. That call
returns with the mdio device bindable and the device lock dropped, so
from then on a phy_probe() on another CPU is the other writer of this
field. Ahead of it the generic driver is still bound, and a driver
registering meanwhile is turned away with -EBUSY before it can reach
phy_probe().
Fixes: 00db8189d984 ("This patch adds a PHY Abstraction Layer to the Linux Kernel, enabling ethernet drivers to remain as ignorant as is reasonable of the connected PHY's design and operation details.")
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
---
Notes:
Found and measured on an MT7981B board with an MT7531 switch and an Airoha
EN8811H behind lan4, whose interrupt the devicetree describes and whose
driver is a module.
The one condition arranged for the run is that the PHY driver module loads
after the root filesystem rather than from the early boot list this
distribution normally puts it in. The distribution's own late-PHY handling
was also removed, that being the one patch which could have changed the
outcome; upstream has nothing like it. The kernel is still a distribution
one and its remaining patches to phylink and phy_device do run on these
paths - none of them writes phydev->irq.
DSA then sets the port up at 1.87 s, the generic driver is bound by hand,
phy_probe() replaces the interrupt with PHY_POLL, and phylink rejects
2500base-x against it:
lan4 (uninitialized): validation of 2500base-x ... failed: -EINVAL
lan4 (uninitialized): failed to connect to PHY: -EINVAL
The real driver arrives between 13.4 and 13.6 s depending on the boot, and
binds. phydev->irq then reads -1 without this patch and 15 with it, 15
being what the devicetree gave that PHY. The three switch ports alongside
read 79, 80 and 81 in both runs, so the reading distinguishes rather than
printing one answer. The field has no sysfs attribute of its own, so it was
read with a debug-only module parameter that walks the MDIO bus and prints
it.
drivers/net/phy/phy_device.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 94b2e85e00a3..8e6b399f95d6 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1959,6 +1959,9 @@ void phy_detach(struct phy_device *phydev)
if (phydev->mdio.dev.driver)
module_put(phydev->mdio.dev.driver->owner);
+ /* The release below can hand this field to a probe on another CPU. */
+ phydev->irq = phydev->mdio.bus->irq[phydev->mdio.addr];
+
/* If the device had no specific driver before (i.e. - it
* was using the generic driver), we unbind the device
* from the generic driver so that there's a chance a
--
2.53.0
next prev parent reply other threads:[~2026-09-19 1:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 1:53 [PATCH net v9 0/4] net: phy: keep a PHY interrupt across a generic bind cycle Aleksei Sviridkin
2026-09-19 1:53 ` [PATCH net v9 1/4] net: usb: lan78xx: register the PHY interrupt with the MDIO bus Aleksei Sviridkin
2026-09-23 2:26 ` netdev-bot+sashiko
2026-09-19 1:53 ` [PATCH net v9 2/4] net: usb: smsc95xx: " Aleksei Sviridkin
2026-09-19 1:53 ` Aleksei Sviridkin [this message]
2026-09-23 2:26 ` [PATCH net v9 3/4] net: phy: take the interrupt back from the bus on detach netdev-bot+sashiko
2026-09-19 1:53 ` [PATCH net v9 4/4] net: phy: restore the interrupt when the generic bind cycle fails Aleksei Sviridkin
2026-09-23 2:26 ` netdev-bot+sashiko
2026-09-22 11:03 ` [PATCH net v9 0/4] net: phy: keep a PHY interrupt across a generic bind cycle Aleksei Sviridkin
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=20260919015326.499479-4-f@lex.la \
--to=f@lex.la \
--cc=Thangaraj.S@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=steve.glendinning@shawell.net \
/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®