OSDN Git Service

mt76: connac: add mt76_connac_power_save_sched in mt76_connac_pm_unref
authorLorenzo Bianconi <lorenzo@kernel.org>
Wed, 2 Jun 2021 21:25:28 +0000 (23:25 +0200)
committerFelix Fietkau <nbd@nbd.name>
Sat, 19 Jun 2021 07:22:48 +0000 (09:22 +0200)
Schedule power_save work running mt76_connac_pm_unref in order to reduce
power consumption

Tested-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7615/dma.c
drivers/net/wireless/mediatek/mt76/mt7615/main.c
drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c
drivers/net/wireless/mediatek/mt76/mt76_connac.h
drivers/net/wireless/mediatek/mt76/mt7921/dma.c
drivers/net/wireless/mediatek/mt76/mt7921/main.c

index 8004ae5..b618423 100644 (file)
@@ -81,7 +81,7 @@ static int mt7615_poll_tx(struct napi_struct *napi, int budget)
        if (napi_complete(napi))
                mt7615_irq_enable(dev, mt7615_tx_mcu_int_mask(dev));
 
-       mt76_connac_pm_unref(&dev->pm);
+       mt76_connac_pm_unref(&dev->mphy, &dev->pm);
 
        return 0;
 }
@@ -99,7 +99,7 @@ static int mt7615_poll_rx(struct napi_struct *napi, int budget)
                return 0;
        }
        done = mt76_dma_rx_poll(napi, budget);
-       mt76_connac_pm_unref(&dev->pm);
+       mt76_connac_pm_unref(&dev->mphy, &dev->pm);
 
        return done;
 }
index 7c9a55c..bd2f42e 100644 (file)
@@ -693,7 +693,7 @@ static void mt7615_sta_rate_tbl_update(struct ieee80211_hw *hw,
        msta->n_rates = i;
        if (mt76_connac_pm_ref(phy->mt76, &dev->pm)) {
                mt7615_mac_set_rates(phy, msta, NULL, msta->rates);
-               mt76_connac_pm_unref(&dev->pm);
+               mt76_connac_pm_unref(phy->mt76, &dev->pm);
        }
        spin_unlock_bh(&dev->mt76.lock);
 }
@@ -709,7 +709,7 @@ void mt7615_tx_worker(struct mt76_worker *w)
        }
 
        mt76_tx_worker_run(&dev->mt76);
-       mt76_connac_pm_unref(&dev->pm);
+       mt76_connac_pm_unref(&dev->mphy, &dev->pm);
 }
 
 static void mt7615_tx(struct ieee80211_hw *hw,
@@ -739,7 +739,7 @@ static void mt7615_tx(struct ieee80211_hw *hw,
 
        if (mt76_connac_pm_ref(mphy, &dev->pm)) {
                mt76_tx(mphy, control->sta, wcid, skb);
-               mt76_connac_pm_unref(&dev->pm);
+               mt76_connac_pm_unref(mphy, &dev->pm);
                return;
        }
 
index 261cff7..a2465b4 100644 (file)
@@ -98,7 +98,7 @@ mt7615_led_set_config(struct led_classdev *led_cdev,
        addr = mt7615_reg_map(dev, MT_LED_CTRL);
        mt76_wr(dev, addr, val);
 
-       mt76_connac_pm_unref(&dev->pm);
+       mt76_connac_pm_unref(&dev->mphy, &dev->pm);
 }
 
 static int
index 63c1d1a..0dfa099 100644 (file)
@@ -117,11 +117,15 @@ out:
 }
 
 static inline void
-mt76_connac_pm_unref(struct mt76_connac_pm *pm)
+mt76_connac_pm_unref(struct mt76_phy *phy, struct mt76_connac_pm *pm)
 {
        spin_lock_bh(&pm->wake.lock);
-       pm->wake.count--;
+
        pm->last_activity = jiffies;
+       if (--pm->wake.count == 0 &&
+           test_bit(MT76_STATE_MCU_RUNNING, &phy->state))
+               mt76_connac_power_save_sched(phy, pm);
+
        spin_unlock_bh(&pm->wake.lock);
 }
 
index 7fca7dc..5e745e9 100644 (file)
@@ -74,7 +74,7 @@ static int mt7921_poll_tx(struct napi_struct *napi, int budget)
        mt7921_tx_cleanup(dev);
        if (napi_complete(napi))
                mt7921_irq_enable(dev, MT_INT_TX_DONE_ALL);
-       mt76_connac_pm_unref(&dev->pm);
+       mt76_connac_pm_unref(&dev->mphy, &dev->pm);
 
        return 0;
 }
@@ -92,7 +92,7 @@ static int mt7921_poll_rx(struct napi_struct *napi, int budget)
                return 0;
        }
        done = mt76_dma_rx_poll(napi, budget);
-       mt76_connac_pm_unref(&dev->pm);
+       mt76_connac_pm_unref(&dev->mphy, &dev->pm);
 
        return done;
 }
index a6cf4a0..0cd519f 100644 (file)
@@ -679,7 +679,7 @@ void mt7921_tx_worker(struct mt76_worker *w)
        }
 
        mt76_txq_schedule_all(&dev->mphy);
-       mt76_connac_pm_unref(&dev->pm);
+       mt76_connac_pm_unref(&dev->mphy, &dev->pm);
 }
 
 static void mt7921_tx(struct ieee80211_hw *hw,
@@ -709,7 +709,7 @@ static void mt7921_tx(struct ieee80211_hw *hw,
 
        if (mt76_connac_pm_ref(mphy, &dev->pm)) {
                mt76_tx(mphy, control->sta, wcid, skb);
-               mt76_connac_pm_unref(&dev->pm);
+               mt76_connac_pm_unref(mphy, &dev->pm);
                return;
        }