summaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/mediatek
diff options
context:
space:
mode:
authorLorenzo Bianconi <lorenzo@kernel.org>2023-06-28 09:07:16 +0200
committerFelix Fietkau <nbd@nbd.name>2023-07-26 11:36:14 +0200
commitc21a7f9f406bba3f7ee8ce788ef48592c8c3ba8f (patch)
treeb051470e3c969b8dc09fc4ad19e88c75eecfd384 /drivers/net/wireless/mediatek
parentwifi: mt76: mt7921: move hif_ops macro in mt792x.h (diff)
downloadlinux-c21a7f9f406bba3f7ee8ce788ef48592c8c3ba8f.tar.xz
linux-c21a7f9f406bba3f7ee8ce788ef48592c8c3ba8f.zip
wifi: mt76: mt7921: move shared runtime-pm code on mt792x-lib
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>
Diffstat (limited to 'drivers/net/wireless/mediatek')
-rw-r--r--drivers/net/wireless/mediatek/mt76/mt7921/init.c4
-rw-r--r--drivers/net/wireless/mediatek/mt76/mt7921/mac.c70
-rw-r--r--drivers/net/wireless/mediatek/mt76/mt7921/mcu.c44
-rw-r--r--drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h4
-rw-r--r--drivers/net/wireless/mediatek/mt76/mt7921/pci.c6
-rw-r--r--drivers/net/wireless/mediatek/mt76/mt7921/sdio.c6
-rw-r--r--drivers/net/wireless/mediatek/mt76/mt792x.h4
-rw-r--r--drivers/net/wireless/mediatek/mt76/mt792x_core.c44
-rw-r--r--drivers/net/wireless/mediatek/mt76/mt792x_mac.c72
9 files changed, 128 insertions, 126 deletions
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/init.c b/drivers/net/wireless/mediatek/mt76/mt7921/init.c
index 6b8e31110fdf..c47fb07fcb2e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/init.c
@@ -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);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
index 25d853a75a23..21f937454229 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
@@ -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;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
index 9bfa79893b10..bd40ca489447 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
@@ -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)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
index 86b8c98e3f69..4a3416a28711 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
@@ -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,
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c
index 7e9bb1879f9c..7419076b77cb 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c
@@ -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;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c b/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
index 84b388656941..dc1beb76df3e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
@@ -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;
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h
index 1c2829cd954d..470017f6f982 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x.h
+++ b/drivers/net/wireless/mediatek/mt76/mt792x.h
@@ -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 */
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_core.c b/drivers/net/wireless/mediatek/mt76/mt792x_core.c
index a4aa9694de7f..234aac4e3742 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x_core.c
+++ b/drivers/net/wireless/mediatek/mt76/mt792x_core.c
@@ -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>");
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_mac.c b/drivers/net/wireless/mediatek/mt76/mt792x_mac.c
index 9603c4eedb2b..5d1f8229fdc1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x_mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt792x_mac.c
@@ -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);