[PATCH net v9 4/5] net: phy: run a postponed PHY interrupt handler directly on resume
Igor Velkov via B4 Relay
devnull+iav.iav.lv at kernel.org
Sun Nov 29 23:04:38 PST 2026
From: Igor Velkov <iav at iav.lv>
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, but only for a PHY that has its interrupt
requested: on a shared line irq_rerun outlives phy_free_interrupt(),
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.
The interrupts flag does not tell whether the interrupt is requested:
some drivers, such as dp83867 and micrel, set it in their resume
callbacks. Add irq_requested for that; only phy_request_interrupt() and
phy_free_interrupt() write it, under irq_pm_lock held across
request_threaded_irq() and free_irq().
Fixes: 1758bde2e4aa ("net: phy: Don't trigger state machine while in suspend")
Signed-off-by: Igor Velkov <iav at iav.lv>
---
drivers/net/phy/phy.c | 8 +++++---
drivers/net/phy/phy_device.c | 13 ++++++++++---
include/linux/phy.h | 7 +++++--
3 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index b91723867892..6dce49f01d2b 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -1488,11 +1488,13 @@ void phy_request_interrupt(struct phy_device *phydev)
mutex_lock(&phydev->irq_pm_lock);
if (phydev->irq_rerun && !irq_has_action(phydev->irq_rerun_line))
phydev->irq_rerun = false;
- mutex_unlock(&phydev->irq_pm_lock);
err = request_threaded_irq(phydev->irq, NULL, phy_interrupt,
IRQF_ONESHOT | IRQF_SHARED,
phydev_name(phydev), phydev);
+ phydev->irq_requested = !err;
+ mutex_unlock(&phydev->irq_pm_lock);
+
if (err) {
phydev_warn(phydev, "Error %d requesting IRQ %d, falling back to polling\n",
err, phydev->irq);
@@ -1516,10 +1518,10 @@ 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);
+ phydev->irq_requested = false;
/* 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..16b398794486 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->irq_requested) {
+ 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 42004e45fb3a..23d88cfa858b 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -653,6 +653,7 @@ struct phy_oatc14_sqi_capability {
* handling shall be postponed until PHY has resumed
* @irq_rerun: Set by the postponed interrupt that disabled the line
* @irq_rerun_line: The line the postponed interrupt disabled
+ * @irq_requested: Set while the PHY has its interrupt requested
* @default_timestamp: Flag indicating whether we are using the phy
* timestamp as the default one
* @interface: enum phy_interface_t value
@@ -677,6 +678,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;
+ * protects @irq_requested; taken before @lock;
* phy_interrupt() never takes it
* @state_queue: Work queue for state machine
* @link_down_events: Number of times link was lost
@@ -735,6 +737,7 @@ struct phy_device {
bool irq_suspended;
bool irq_rerun;
int irq_rerun_line;
+ bool irq_requested;
unsigned default_timestamp:1;
@@ -812,8 +815,8 @@ struct phy_device {
struct delayed_work state_queue;
struct mutex lock;
- /* Held where the PM callbacks and the requesting and freeing of the
- * interrupt test and clear irq_rerun
+ /* Protects irq_requested; held where the PM callbacks and the interrupt
+ * request and free paths test and clear irq_rerun
*/
struct mutex irq_pm_lock;
--
2.43.0
More information about the Linux-rockchip
mailing list