wifi: mt76: mt7921: fix the unfinished command of regd_notifier before suspend
authorMing Yen Hsieh <mingyen.hsieh@mediatek.com>
Tue, 16 Jan 2024 02:48:57 +0000 (10:48 +0800)
committerFelix Fietkau <nbd@nbd.name>
Thu, 22 Feb 2024 08:55:19 +0000 (09:55 +0100)
Before entering suspend, we need to ensure that all MCU command are
completed. In some cases, such as with regd_notifier, there is a
chance that CLC commands, will be executed before suspend.

Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
Signed-off-by: Leon Yen <leon.yen@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7921/init.c
drivers/net/wireless/mediatek/mt76/mt7921/pci.c
drivers/net/wireless/mediatek/mt76/mt792x.h

index 48433c6d5e7d30e902a7659bd443641e672f9583..ef0c721d26e332b6d65485e52d144098a5aaef6a 100644 (file)
@@ -138,9 +138,14 @@ mt7921_regd_notifier(struct wiphy *wiphy,
        if (pm->suspended)
                return;
 
+       dev->regd_in_progress = true;
+
        mt792x_mutex_acquire(dev);
        mt7921_regd_update(dev);
        mt792x_mutex_release(dev);
+
+       dev->regd_in_progress = false;
+       wake_up(&dev->wait);
 }
 
 int mt7921_mac_init(struct mt792x_dev *dev)
@@ -261,6 +266,7 @@ int mt7921_register_device(struct mt792x_dev *dev)
        spin_lock_init(&dev->pm.wake.lock);
        mutex_init(&dev->pm.mutex);
        init_waitqueue_head(&dev->pm.wait);
+       init_waitqueue_head(&dev->wait);
        if (mt76_is_sdio(&dev->mt76))
                init_waitqueue_head(&dev->mt76.sdio.wait);
        spin_lock_init(&dev->pm.txq_lock);
index 82cf3ce90b52f1fc8a2716b8c43051c028cb2539..7037ef57651e1c66f23a37935feae00960182682 100644 (file)
@@ -410,6 +410,9 @@ static int mt7921_pci_suspend(struct device *device)
        if (err < 0)
                goto restore_suspend;
 
+       wait_event_timeout(dev->wait,
+                          !dev->regd_in_progress, 5 * HZ);
+
        err = mt76_connac_mcu_set_hif_suspend(mdev, true);
        if (err)
                goto restore_suspend;
index 3c897b34aaa79662b72c935a6b0b7b69ca621231..a8556de3d480dce94c2474688d2e397abacb32d6 100644 (file)
@@ -186,6 +186,8 @@ struct mt792x_dev {
        bool hw_init_done:1;
        bool fw_assert:1;
        bool has_eht:1;
+       bool regd_in_progress:1;
+       wait_queue_head_t wait;
 
        struct work_struct init_work;