wifi: mt76: mt7921: move shared runtime-pm code on mt792x-lib
authorLorenzo Bianconi <lorenzo@kernel.org>
Wed, 28 Jun 2023 07:07:16 +0000 (15:07 +0800)
committerFelix Fietkau <nbd@nbd.name>
Wed, 26 Jul 2023 09:36:14 +0000 (11:36 +0200)
Moving hif_ops marcos in mt792x.h, we can move shared runtime-pm code
between mt7925 and mt7921 in mt792x-lib module.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7921/init.c
drivers/net/wireless/mediatek/mt76/mt7921/mac.c
drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
drivers/net/wireless/mediatek/mt76/mt7921/pci.c
drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
drivers/net/wireless/mediatek/mt76/mt792x.h
drivers/net/wireless/mediatek/mt76/mt792x_core.c
drivers/net/wireless/mediatek/mt76/mt792x_mac.c

index 6b8e31110fdfff32d84938f5a75226e2c7bc8035..c47fb07fcb2eaa5f09d781692316fdbfee26d4cc 100644 (file)
@@ -192,8 +192,8 @@ int mt7921_register_device(struct mt792x_dev *dev)
        dev->mt76.phy.priv = &dev->phy;
        dev->mt76.tx_worker.fn = mt792x_tx_worker;
 
-       INIT_DELAYED_WORK(&dev->pm.ps_work, mt7921_pm_power_save_work);
-       INIT_WORK(&dev->pm.wake_work, mt7921_pm_wake_work);
+       INIT_DELAYED_WORK(&dev->pm.ps_work, mt792x_pm_power_save_work);
+       INIT_WORK(&dev->pm.wake_work, mt792x_pm_wake_work);
        spin_lock_init(&dev->pm.wake.lock);
        mutex_init(&dev->pm.mutex);
        init_waitqueue_head(&dev->pm.wait);
index 25d853a75a234585c0228eccc0f699c0601275ce..21f93745422900d09e4aa4550aaf380264a48306 100644 (file)
@@ -699,76 +699,6 @@ void mt7921_mac_reset_work(struct work_struct *work)
        mt76_connac_power_save_sched(&dev->mt76.phy, pm);
 }
 
-void mt7921_pm_wake_work(struct work_struct *work)
-{
-       struct mt792x_dev *dev;
-       struct mt76_phy *mphy;
-
-       dev = (struct mt792x_dev *)container_of(work, struct mt792x_dev,
-                                               pm.wake_work);
-       mphy = dev->phy.mt76;
-
-       if (!mt7921_mcu_drv_pmctrl(dev)) {
-               struct mt76_dev *mdev = &dev->mt76;
-               int i;
-
-               if (mt76_is_sdio(mdev)) {
-                       mt76_connac_pm_dequeue_skbs(mphy, &dev->pm);
-                       mt76_worker_schedule(&mdev->sdio.txrx_worker);
-               } else {
-                       local_bh_disable();
-                       mt76_for_each_q_rx(mdev, i)
-                               napi_schedule(&mdev->napi[i]);
-                       local_bh_enable();
-                       mt76_connac_pm_dequeue_skbs(mphy, &dev->pm);
-                       mt76_connac_tx_cleanup(mdev);
-               }
-               if (test_bit(MT76_STATE_RUNNING, &mphy->state))
-                       ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
-                                                    MT792x_WATCHDOG_TIME);
-       }
-
-       ieee80211_wake_queues(mphy->hw);
-       wake_up(&dev->pm.wait);
-}
-
-void mt7921_pm_power_save_work(struct work_struct *work)
-{
-       struct mt792x_dev *dev;
-       unsigned long delta;
-       struct mt76_phy *mphy;
-
-       dev = (struct mt792x_dev *)container_of(work, struct mt792x_dev,
-                                               pm.ps_work.work);
-       mphy = dev->phy.mt76;
-
-       delta = dev->pm.idle_timeout;
-       if (test_bit(MT76_HW_SCANNING, &mphy->state) ||
-           test_bit(MT76_HW_SCHED_SCANNING, &mphy->state) ||
-           dev->fw_assert)
-               goto out;
-
-       if (mutex_is_locked(&dev->mt76.mutex))
-               /* if mt76 mutex is held we should not put the device
-                * to sleep since we are currently accessing device
-                * register map. We need to wait for the next power_save
-                * trigger.
-                */
-               goto out;
-
-       if (time_is_after_jiffies(dev->pm.last_activity + delta)) {
-               delta = dev->pm.last_activity + delta - jiffies;
-               goto out;
-       }
-
-       if (!mt7921_mcu_fw_pmctrl(dev)) {
-               cancel_delayed_work_sync(&mphy->mac_work);
-               return;
-       }
-out:
-       queue_delayed_work(dev->mt76.wq, &dev->pm.ps_work, delta);
-}
-
 void mt7921_coredump_work(struct work_struct *work)
 {
        struct mt792x_dev *dev;
index 9bfa79893b10e5fcfd69dfc31b4a5a03fa1a0f2a..bd40ca489447305f509683259cc68a28ba79f9be 100644 (file)
@@ -942,50 +942,6 @@ int mt7921_mcu_sta_update(struct mt792x_dev *dev, struct ieee80211_sta *sta,
        return mt76_connac_mcu_sta_cmd(&dev->mphy, &info);
 }
 
-int mt7921_mcu_drv_pmctrl(struct mt792x_dev *dev)
-{
-       struct mt76_phy *mphy = &dev->mt76.phy;
-       struct mt76_connac_pm *pm = &dev->pm;
-       int err = 0;
-
-       mutex_lock(&pm->mutex);
-
-       if (!test_bit(MT76_STATE_PM, &mphy->state))
-               goto out;
-
-       err = __mt792x_mcu_drv_pmctrl(dev);
-out:
-       mutex_unlock(&pm->mutex);
-
-       if (err)
-               mt792x_reset(&dev->mt76);
-
-       return err;
-}
-EXPORT_SYMBOL_GPL(mt7921_mcu_drv_pmctrl);
-
-int mt7921_mcu_fw_pmctrl(struct mt792x_dev *dev)
-{
-       struct mt76_phy *mphy = &dev->mt76.phy;
-       struct mt76_connac_pm *pm = &dev->pm;
-       int err = 0;
-
-       mutex_lock(&pm->mutex);
-
-       if (mt76_connac_skip_fw_pmctrl(mphy, pm))
-               goto out;
-
-       err = __mt792x_mcu_fw_pmctrl(dev);
-out:
-       mutex_unlock(&pm->mutex);
-
-       if (err)
-               mt792x_reset(&dev->mt76);
-
-       return err;
-}
-EXPORT_SYMBOL_GPL(mt7921_mcu_fw_pmctrl);
-
 int mt7921_mcu_set_beacon_filter(struct mt792x_dev *dev,
                                 struct ieee80211_vif *vif,
                                 bool enable)
index 86b8c98e3f6995d5ee6af1a8c344e7ecb9985509..4a3416a287112bba143d548385e836277ec33f6e 100644 (file)
@@ -297,10 +297,6 @@ int mt7921_mcu_uni_rx_ba(struct mt792x_dev *dev,
 void mt7921_scan_work(struct work_struct *work);
 void mt7921_roc_work(struct work_struct *work);
 int mt7921_mcu_uni_bss_ps(struct mt792x_dev *dev, struct ieee80211_vif *vif);
-int mt7921_mcu_drv_pmctrl(struct mt792x_dev *dev);
-int mt7921_mcu_fw_pmctrl(struct mt792x_dev *dev);
-void mt7921_pm_wake_work(struct work_struct *work);
-void mt7921_pm_power_save_work(struct work_struct *work);
 void mt7921_coredump_work(struct work_struct *work);
 int mt7921_get_txpwr_info(struct mt792x_dev *dev, struct mt7921_txpwr *txpwr);
 int mt7921_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
index 7e9bb1879f9c5e70c70ebb0fe903119d6b85b385..7419076b77cb99ac7994aef20da88cad62b82cd4 100644 (file)
@@ -337,7 +337,7 @@ static int mt7921_pci_suspend(struct device *device)
        cancel_delayed_work_sync(&pm->ps_work);
        cancel_work_sync(&pm->wake_work);
 
-       err = mt7921_mcu_drv_pmctrl(dev);
+       err = mt792x_mcu_drv_pmctrl(dev);
        if (err < 0)
                goto restore_suspend;
 
@@ -372,7 +372,7 @@ static int mt7921_pci_suspend(struct device *device)
        synchronize_irq(pdev->irq);
        tasklet_kill(&mdev->irq_tasklet);
 
-       err = mt7921_mcu_fw_pmctrl(dev);
+       err = mt792x_mcu_fw_pmctrl(dev);
        if (err)
                goto restore_napi;
 
@@ -406,7 +406,7 @@ static int mt7921_pci_resume(struct device *device)
        struct mt76_connac_pm *pm = &dev->pm;
        int i, err;
 
-       err = mt7921_mcu_drv_pmctrl(dev);
+       err = mt792x_mcu_drv_pmctrl(dev);
        if (err < 0)
                goto failed;
 
index 84b3886569419eb746ff3ad336b747ca7cce08c1..dc1beb76df3e16f8674dbc30338fa99c4906361b 100644 (file)
@@ -216,7 +216,7 @@ static int mt7921s_suspend(struct device *__dev)
        cancel_delayed_work_sync(&pm->ps_work);
        cancel_work_sync(&pm->wake_work);
 
-       err = mt7921_mcu_drv_pmctrl(dev);
+       err = mt792x_mcu_drv_pmctrl(dev);
        if (err < 0)
                goto restore_suspend;
 
@@ -244,7 +244,7 @@ static int mt7921s_suspend(struct device *__dev)
        mt76_worker_disable(&mdev->sdio.txrx_worker);
        mt76_worker_disable(&mdev->sdio.net_worker);
 
-       err = mt7921_mcu_fw_pmctrl(dev);
+       err = mt792x_mcu_fw_pmctrl(dev);
        if (err)
                goto restore_txrx_worker;
 
@@ -284,7 +284,7 @@ static int mt7921s_resume(struct device *__dev)
 
        clear_bit(MT76_STATE_SUSPEND, &mdev->phy.state);
 
-       err = mt7921_mcu_drv_pmctrl(dev);
+       err = mt792x_mcu_drv_pmctrl(dev);
        if (err < 0)
                goto failed;
 
index 1c2829cd954d2d667b85df42966a6cc9469055c1..470017f6f9829e742c148372a01b4994340455d2 100644 (file)
@@ -215,6 +215,8 @@ static inline bool mt792x_dma_need_reinit(struct mt792x_dev *dev)
 #define mt792x_mutex_release(dev)      \
        mt76_connac_mutex_release(&(dev)->mt76, &(dev)->pm)
 
+void mt792x_pm_wake_work(struct work_struct *work);
+void mt792x_pm_power_save_work(struct work_struct *work);
 void mt792x_reset(struct mt76_dev *mdev);
 void mt792x_update_channel(struct mt76_phy *mphy);
 void mt792x_mac_reset_counters(struct mt792x_phy *phy);
@@ -284,5 +286,7 @@ mt792x_get_mac80211_ops(struct device *dev,
                        const struct ieee80211_ops *mac80211_ops,
                        void *drv_data, u8 *fw_features);
 int mt792x_init_wcid(struct mt792x_dev *dev);
+int mt792x_mcu_drv_pmctrl(struct mt792x_dev *dev);
+int mt792x_mcu_fw_pmctrl(struct mt792x_dev *dev);
 
 #endif /* __MT7925_H */
index a4aa9694de7f6e84a2796b12a5cade09a10c1698..234aac4e37425986e2811867eea737e3ee4bb804 100644 (file)
@@ -692,5 +692,49 @@ int mt792x_init_wcid(struct mt792x_dev *dev)
 }
 EXPORT_SYMBOL_GPL(mt792x_init_wcid);
 
+int mt792x_mcu_drv_pmctrl(struct mt792x_dev *dev)
+{
+       struct mt76_phy *mphy = &dev->mt76.phy;
+       struct mt76_connac_pm *pm = &dev->pm;
+       int err = 0;
+
+       mutex_lock(&pm->mutex);
+
+       if (!test_bit(MT76_STATE_PM, &mphy->state))
+               goto out;
+
+       err = __mt792x_mcu_drv_pmctrl(dev);
+out:
+       mutex_unlock(&pm->mutex);
+
+       if (err)
+               mt792x_reset(&dev->mt76);
+
+       return err;
+}
+EXPORT_SYMBOL_GPL(mt792x_mcu_drv_pmctrl);
+
+int mt792x_mcu_fw_pmctrl(struct mt792x_dev *dev)
+{
+       struct mt76_phy *mphy = &dev->mt76.phy;
+       struct mt76_connac_pm *pm = &dev->pm;
+       int err = 0;
+
+       mutex_lock(&pm->mutex);
+
+       if (mt76_connac_skip_fw_pmctrl(mphy, pm))
+               goto out;
+
+       err = __mt792x_mcu_fw_pmctrl(dev);
+out:
+       mutex_unlock(&pm->mutex);
+
+       if (err)
+               mt792x_reset(&dev->mt76);
+
+       return err;
+}
+EXPORT_SYMBOL_GPL(mt792x_mcu_fw_pmctrl);
+
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo@kernel.org>");
index 9603c4eedb2bc1c90665a9c539b7401a54407943..5d1f8229fdc1daa0ba57afcd73673dbc6ad700b8 100644 (file)
@@ -311,3 +311,75 @@ void mt792x_mac_init_band(struct mt792x_dev *dev, u8 band)
        mt76_rmw(dev, MT_WTBLOFF_TOP_RSCR(band), mask, set);
 }
 EXPORT_SYMBOL_GPL(mt792x_mac_init_band);
+
+void mt792x_pm_wake_work(struct work_struct *work)
+{
+       struct mt792x_dev *dev;
+       struct mt76_phy *mphy;
+
+       dev = (struct mt792x_dev *)container_of(work, struct mt792x_dev,
+                                               pm.wake_work);
+       mphy = dev->phy.mt76;
+
+       if (!mt792x_mcu_drv_pmctrl(dev)) {
+               struct mt76_dev *mdev = &dev->mt76;
+               int i;
+
+               if (mt76_is_sdio(mdev)) {
+                       mt76_connac_pm_dequeue_skbs(mphy, &dev->pm);
+                       mt76_worker_schedule(&mdev->sdio.txrx_worker);
+               } else {
+                       local_bh_disable();
+                       mt76_for_each_q_rx(mdev, i)
+                               napi_schedule(&mdev->napi[i]);
+                       local_bh_enable();
+                       mt76_connac_pm_dequeue_skbs(mphy, &dev->pm);
+                       mt76_connac_tx_cleanup(mdev);
+               }
+               if (test_bit(MT76_STATE_RUNNING, &mphy->state))
+                       ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
+                                                    MT792x_WATCHDOG_TIME);
+       }
+
+       ieee80211_wake_queues(mphy->hw);
+       wake_up(&dev->pm.wait);
+}
+EXPORT_SYMBOL_GPL(mt792x_pm_wake_work);
+
+void mt792x_pm_power_save_work(struct work_struct *work)
+{
+       struct mt792x_dev *dev;
+       unsigned long delta;
+       struct mt76_phy *mphy;
+
+       dev = (struct mt792x_dev *)container_of(work, struct mt792x_dev,
+                                               pm.ps_work.work);
+       mphy = dev->phy.mt76;
+
+       delta = dev->pm.idle_timeout;
+       if (test_bit(MT76_HW_SCANNING, &mphy->state) ||
+           test_bit(MT76_HW_SCHED_SCANNING, &mphy->state) ||
+           dev->fw_assert)
+               goto out;
+
+       if (mutex_is_locked(&dev->mt76.mutex))
+               /* if mt76 mutex is held we should not put the device
+                * to sleep since we are currently accessing device
+                * register map. We need to wait for the next power_save
+                * trigger.
+                */
+               goto out;
+
+       if (time_is_after_jiffies(dev->pm.last_activity + delta)) {
+               delta = dev->pm.last_activity + delta - jiffies;
+               goto out;
+       }
+
+       if (!mt792x_mcu_fw_pmctrl(dev)) {
+               cancel_delayed_work_sync(&mphy->mac_work);
+               return;
+       }
+out:
+       queue_delayed_work(dev->mt76.wq, &dev->pm.ps_work, delta);
+}
+EXPORT_SYMBOL_GPL(mt792x_pm_power_save_work);