[PATCH net v8 4/5] net: phy: run a postponed PHY interrupt handler directly on resume
From: Igor Velkov via B4 Relay
Date: Sun Nov 22 2026 - 19:46:33 EST
From: Igor Velkov <iav@xxxxxx>
mdio_bus_phy_resume_irq() reruns a postponed interrupt with
irq_wake_thread(). A PHY interrupt behind a nested threaded interrupt
controller, such as an I2C or SPI GPIO expander, has no interrupt
thread, so irq_wake_thread() does nothing and the postponed interrupt
is lost: the PHY keeps its status latched and its INT line asserted.
For a PHY that the MDIO bus suspended, mdio_bus_phy_resume() calls
phy_init_hw() before the rerun, and config_intr() there acknowledges
the latched status in drivers such as realtek. A PHY that the bus did
not suspend, as with Wake-on-LAN enabled, gets no phy_init_hw() and
loses the interrupt today. A later patch brings PHYs with MAC-managed
PM under postponing, and stmmac, for one, does not call phy_init_hw()
on resume.
Call the PHY driver's handler from mdio_bus_phy_resume_irq(), as
phy_interrupt() does, unless the PHY has its interrupts disabled, as
after phy_free_interrupt(): on a shared line irq_rerun outlives the
free, and the handler would run on a PHY that no longer uses the line.
Hold irq_pm_lock across the call and
around phy_disable_interrupts() in phy_free_interrupt(), so that the
free waits for the handler, as free_irq() waits for the thread.
Fixes: 1758bde2e4aa ("net: phy: Don't trigger state machine while in suspend")
Signed-off-by: Igor Velkov <iav@xxxxxx>
---
drivers/net/phy/phy.c | 3 +--
drivers/net/phy/phy_device.c | 13 ++++++++++---
include/linux/phy.h | 2 +-
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 92ee4651bdbc..6cc94b525e09 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -1516,9 +1516,8 @@ EXPORT_SYMBOL(phy_request_interrupt);
*/
void phy_free_interrupt(struct phy_device *phydev)
{
- phy_disable_interrupts(phydev);
-
mutex_lock(&phydev->irq_pm_lock);
+ phy_disable_interrupts(phydev);
free_irq(phydev->irq, phydev);
/* free_irq() shuts down a line left without users and the next request
* resets its depth; mdio_bus_phy_resume_irq() enables a shared line.
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 2d2058c29f30..8bc394ff7d2d 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -355,12 +355,19 @@ static __maybe_unused void mdio_bus_phy_resume_irq(struct phy_device *phydev)
mutex_lock(&phydev->irq_pm_lock);
if (phy_interrupt_is_valid(phydev))
synchronize_irq(phydev->irq);
- /* The PHY may have fallen back to polling since it disabled the line */
+ /* The PHY may have fallen back to polling since it disabled the line,
+ * or freed its interrupt while another user keeps the line.
+ */
if (phydev->irq_rerun) {
phydev->irq_rerun = false;
enable_irq(phydev->irq_rerun_line);
- if (phydev->irq == phydev->irq_rerun_line)
- irq_wake_thread(phydev->irq, phydev);
+ /* A nested threaded line has no thread; we run the handler */
+ if (phydev->irq == phydev->irq_rerun_line &&
+ phydev->interrupts) {
+ mutex_lock(&phydev->lock);
+ phydev->drv->handle_interrupt(phydev);
+ mutex_unlock(&phydev->lock);
+ }
}
mutex_unlock(&phydev->irq_pm_lock);
}
diff --git a/include/linux/phy.h b/include/linux/phy.h
index d84f7d8bc9df..9253a07e84be 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -677,7 +677,7 @@ struct phy_oatc14_sqi_capability {
* @lock: Mutex for serialization access to PHY
* @irq_pm_lock: Held by the PM callbacks, and by the requesting and freeing
* of the interrupt where they test and clear @irq_rerun;
- * phy_interrupt() never takes it
+ * taken before @lock; phy_interrupt() never takes it
* @state_queue: Work queue for state machine
* @link_down_events: Number of times link was lost
* @shared: Pointer to private data shared by phys in one package
--
2.43.0