Skip to content

Commit

Permalink
mt76: mt7921: fix a possible race enabling/disabling runtime-pm
Browse files Browse the repository at this point in the history
Fix a possible race enabling/disabling runtime-pm between
mt7921_pm_set() and mt7921_poll_rx() since mt7921_pm_wake_work()
always schedules rx-napi callback and it will trigger
mt7921_pm_power_save_work routine putting chip to in low-power state
during mt7921_pm_set processing.

Suggested-by: Deren Wu <deren.wu@mediatek.com>
Tested-by: Deren Wu <deren.wu@mediatek.com>
Fixes: 1d8efc7 ("mt76: mt7921: introduce Runtime PM support")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/0f3e075a2033dc05f09dab4059e5be8cbdccc239.1640094847.git.lorenzo@kernel.org
  • Loading branch information
LorenzoBianconi authored and Kalle Valo committed Dec 22, 2021
1 parent f31ee3c commit d430dff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 0 additions & 3 deletions drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ int mt76_connac_pm_wake(struct mt76_phy *phy, struct mt76_connac_pm *pm)
{
struct mt76_dev *dev = phy->dev;

if (!pm->enable)
return 0;

if (mt76_is_usb(dev))
return 0;

Expand Down
12 changes: 9 additions & 3 deletions drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ mt7921_pm_set(void *data, u64 val)
struct mt7921_dev *dev = data;
struct mt76_connac_pm *pm = &dev->pm;

mt7921_mutex_acquire(dev);
mutex_lock(&dev->mt76.mutex);

if (val == pm->enable)
goto out;
Expand All @@ -285,16 +285,22 @@ mt7921_pm_set(void *data, u64 val)
pm->stats.last_wake_event = jiffies;
pm->stats.last_doze_event = jiffies;
}
pm->enable = val;
/* make sure the chip is awake here and ps_work is scheduled
* just at end of the this routine.
*/
pm->enable = false;
mt76_connac_pm_wake(&dev->mphy, pm);

ieee80211_iterate_active_interfaces(mt76_hw(dev),
IEEE80211_IFACE_ITER_RESUME_ALL,
mt7921_pm_interface_iter, dev);

mt76_connac_mcu_set_deep_sleep(&dev->mt76, pm->ds_enable);

pm->enable = val;
mt76_connac_power_save_sched(&dev->mphy, pm);
out:
mt7921_mutex_release(dev);
mutex_unlock(&dev->mt76.mutex);

return 0;
}
Expand Down

0 comments on commit d430dff

Please sign in to comment.