Skip to content

Commit

Permalink
mt76: mt7663: fix a race between mt7615_mcu_drv_pmctrl and mt7615_mcu…
Browse files Browse the repository at this point in the history
…_fw_pmctrl

Introduce a mutex in order to avoid a race between mt7615_mcu_lp_drv_pmctrl and
mt7615_mcu_fw_pmctrl routines since they are run two independent works

Fixes: 1f54900 ("mt76: mt7615: do not request {driver,fw}_own if already granted")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
  • Loading branch information
Lorenzo Bianconi authored and Felix Fietkau committed Apr 21, 2021
1 parent fad90e4 commit 7cd740f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions drivers/net/wireless/mediatek/mt76/mt7615/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ void mt7615_init_device(struct mt7615_dev *dev)

INIT_DELAYED_WORK(&dev->pm.ps_work, mt7615_pm_power_save_work);
INIT_WORK(&dev->pm.wake_work, mt7615_pm_wake_work);
mutex_init(&dev->pm.mutex);
init_completion(&dev->pm.wake_cmpl);
spin_lock_init(&dev->pm.txq_lock);
set_bit(MT76_STATE_PM, &dev->mphy.state);
Expand Down
20 changes: 14 additions & 6 deletions drivers/net/wireless/mediatek/mt76/mt7615/mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,11 @@ static int mt7615_mcu_drv_pmctrl(struct mt7615_dev *dev)
static int mt7615_mcu_lp_drv_pmctrl(struct mt7615_dev *dev)
{
struct mt76_phy *mphy = &dev->mt76.phy;
int i;
int i, err = 0;

mutex_lock(&dev->pm.mutex);

if (!test_and_clear_bit(MT76_STATE_PM, &mphy->state))
if (!test_bit(MT76_STATE_PM, &mphy->state))
goto out;

for (i = 0; i < MT7615_DRV_OWN_RETRY_COUNT; i++) {
Expand All @@ -337,14 +339,16 @@ static int mt7615_mcu_lp_drv_pmctrl(struct mt7615_dev *dev)

if (i == MT7615_DRV_OWN_RETRY_COUNT) {
dev_err(dev->mt76.dev, "driver own failed\n");
set_bit(MT76_STATE_PM, &mphy->state);
return -EIO;
err = -EIO;
goto out;
}
clear_bit(MT76_STATE_PM, &mphy->state);

out:
dev->pm.last_activity = jiffies;
mutex_unlock(&dev->pm.mutex);

return 0;
return err;
}

static int mt7615_mcu_fw_pmctrl(struct mt7615_dev *dev)
Expand All @@ -353,8 +357,10 @@ static int mt7615_mcu_fw_pmctrl(struct mt7615_dev *dev)
int err = 0;
u32 addr;

mutex_lock(&dev->pm.mutex);

if (test_and_set_bit(MT76_STATE_PM, &mphy->state))
return 0;
goto out;

mt7622_trigger_hif_int(dev, true);

Expand All @@ -370,6 +376,8 @@ static int mt7615_mcu_fw_pmctrl(struct mt7615_dev *dev)
}

mt7622_trigger_hif_int(dev, false);
out:
mutex_unlock(&dev->pm.mutex);

return err;
}
Expand Down

0 comments on commit 7cd740f

Please sign in to comment.