phy->n_beacon_vif is meant to count the AP, mesh and IBSS interfaces. When a station associates, mt7615_mac_set_beacon_filter() leaves the firmware's BSS power save and the other-BSS beacon drop in MT_WF_RFCR off if one is up, and debugfs refuses to enable runtime PM while one is. It was counted in mt7615_mac_set_beacon_filter(), called from add/remove_interface, until commit 4bec61d9fb96 ("mt76: mt7663: fix when beacon filter is being applied") moved that call to BSS_CHANGED_ASSOC, which only station interfaces get. The count has stayed 0 since: with an AP up, debugfs turns runtime PM on and off freely (seen on an mt7663s with a NetworkManager hotspot). Count the beaconing interfaces in add/remove_interface again, without the beacon filter MCU command that commit moved away, and clear the beacon drop when one comes up. A station that is already associated keeps its power save settings until it reassociates. Fixes: 4bec61d9fb96 ("mt76: mt7663: fix when beacon filter is being applied") Signed-off-by: Ryan Brue --- drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 15 --------------- drivers/net/wireless/mediatek/mt76/mt7615/main.c | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c index aad232c5a6fa..3d7128cdca8b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c @@ -2273,21 +2273,6 @@ int mt7615_mac_set_beacon_filter(struct mt7615_phy *phy, if (!mt7615_firmware_offload(dev)) return -EOPNOTSUPP; - switch (vif->type) { - case NL80211_IFTYPE_MONITOR: - return 0; - case NL80211_IFTYPE_MESH_POINT: - case NL80211_IFTYPE_ADHOC: - case NL80211_IFTYPE_AP: - if (enable) - phy->n_beacon_vif++; - else - phy->n_beacon_vif--; - fallthrough; - default: - break; - } - err = mt7615_mcu_set_bss_pm(dev, vif, !phy->n_beacon_vif); if (err) return err; diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/main.c b/drivers/net/wireless/mediatek/mt76/mt7615/main.c index 175e847f49ef..a7ffb3af9b9a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/main.c @@ -176,6 +176,18 @@ static int get_omac_idx(enum nl80211_iftype type, u64 mask) return -1; } +static bool mt7615_vif_sends_beacons(struct ieee80211_vif *vif) +{ + switch (vif->type) { + case NL80211_IFTYPE_AP: + case NL80211_IFTYPE_MESH_POINT: + case NL80211_IFTYPE_ADHOC: + return true; + default: + return false; + } +} + static int mt7615_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) { @@ -237,6 +249,15 @@ static int mt7615_add_interface(struct ieee80211_hw *hw, } ret = mt7615_mcu_add_dev_info(phy, vif, true); + if (ret) + goto out; + + /* a beaconing vif wants other BSSs' beacons and no runtime PM */ + if (mt7615_vif_sends_beacons(vif)) { + phy->n_beacon_vif++; + mt76_clear(dev, MT_WF_RFCR(ext_phy), + MT_WF_RFCR_DROP_OTHER_BEACON); + } out: mt7615_mutex_release(dev); @@ -267,6 +288,9 @@ static void mt7615_remove_interface(struct ieee80211_hw *hw, mt7615_mcu_add_dev_info(phy, vif, false); + if (mt7615_vif_sends_beacons(vif)) + phy->n_beacon_vif--; + rcu_assign_pointer(dev->mt76.wcid[idx], NULL); dev->mt76.vif_mask &= ~BIT_ULL(mvif->mt76.idx); -- 2.56.1 mt7615_mac_set_beacon_filter() sets MT_WF_RFCR_DROP_OTHER_BEACON in the RX filter register when a station interface associates, but not in phy->rxfilter. mt7615_configure_filter() writes phy->rxfilter to the same register as a whole, so the next filter update clears the bit again. mac80211 calls configure_filter right after association (the interface joins its IPv6 multicast groups), so in practice the drop is never in effect, and every beacon from every network on the channel goes to the host. Since commit 7124198ab1a4 ("mt76: mt7615: enable beacon filtering by default for offload fw"), mt7615_configure_filter() keeps the bit as phy->rxfilter has it, but nothing ever put it there. Set and clear the bit in phy->rxfilter as well, including where a beaconing interface comes up. With the bit now kept, set it only while the station is associated, so a disconnected station does not keep dropping beacons, and clear it while mac80211 asks for other BSSs' frames (FIF_OTHER_BSS or FIF_BCN_PRBRESP_PROMISC), as it does for a monitor interface. On an MT7663 SDIO module (mt7663s) associated in a busy 2.4 GHz band, MT_WF_RFCR read back 0x001ce302 (bit 11 clear) and mac80211 processed about 300 beacons a second. With the bit kept, that falls to the associated AP's, and the SDIO host's interrupt rate when idle from about 6200 to 3600 a second. Fixes: 83b9f42aea98 ("mt76: mt7615: enable beacon hw filter for runtime-pm") Signed-off-by: Ryan Brue --- drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 17 +++++++++++++---- drivers/net/wireless/mediatek/mt76/mt7615/main.c | 4 +++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c index 3d7128cdca8b..53a5cc48da6e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c @@ -2277,14 +2277,23 @@ int mt7615_mac_set_beacon_filter(struct mt7615_phy *phy, if (err) return err; - if (phy->n_beacon_vif) { + if (phy->n_beacon_vif) vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER; - mt76_clear(dev, MT_WF_RFCR(ext_phy), - MT_WF_RFCR_DROP_OTHER_BEACON); - } else { + else vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER; + + /* Drop other BSSs' beacons only while associated, and keep + * phy->rxfilter in sync: mt7615_configure_filter() writes it to + * MT_WF_RFCR as a whole. + */ + if (enable && !phy->n_beacon_vif) { + phy->rxfilter |= MT_WF_RFCR_DROP_OTHER_BEACON; mt76_set(dev, MT_WF_RFCR(ext_phy), MT_WF_RFCR_DROP_OTHER_BEACON); + } else { + phy->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_BEACON; + mt76_clear(dev, MT_WF_RFCR(ext_phy), + MT_WF_RFCR_DROP_OTHER_BEACON); } return 0; diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/main.c b/drivers/net/wireless/mediatek/mt76/mt7615/main.c index a7ffb3af9b9a..cc35880bef92 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/main.c @@ -255,6 +255,7 @@ static int mt7615_add_interface(struct ieee80211_hw *hw, /* a beaconing vif wants other BSSs' beacons and no runtime PM */ if (mt7615_vif_sends_beacons(vif)) { phy->n_beacon_vif++; + phy->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_BEACON; mt76_clear(dev, MT_WF_RFCR(ext_phy), MT_WF_RFCR_DROP_OTHER_BEACON); } @@ -539,7 +540,8 @@ static void mt7615_configure_filter(struct ieee80211_hw *hw, MT_WF_RFCR_DROP_UNWANTED_CTL | MT_WF_RFCR_DROP_STBC_MULTI); - if (phy->n_beacon_vif || !mt7615_firmware_offload(dev)) + if (phy->n_beacon_vif || !mt7615_firmware_offload(dev) || + (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))) phy->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_BEACON; MT76_FILTER(OTHER_BSS, MT_WF_RFCR_DROP_OTHER_TIM | -- 2.56.1 mt76s_tx_run_queue() schedules the status worker at its end whether or not it took anything off the queue. The txrx worker calls it for every data queue and the MCU queue on each pass, and makes a pass for every interrupt, so the status worker is woken on every pass and, on an idle link, almost always finds nothing to do. Schedule it only if the queue's first pointer moved, i.e. this call marked entries done, also when the SDIO write fails afterwards. Entries completed by an earlier call already scheduled it then. The loop stops at q->head, so it can't move first by a whole ring and leave it unchanged. On an MT7663 SDIO module (mt7663s) on an idle link, the status worker woke about 1100 times a second before and about 200 after. Signed-off-by: Ryan Brue --- drivers/net/wireless/mediatek/mt76/sdio_txrx.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c index 3f314e8e1e69..896d5060a558 100644 --- a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c +++ b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c @@ -247,6 +247,7 @@ static int mt76s_tx_run_queue(struct mt76_dev *dev, struct mt76_queue *q) int err, nframes = 0, len = 0, pse_sz = 0, ple_sz = 0; bool mcu = q == dev->q_mcu[MT_MCUQ_WM]; struct mt76_sdio *sdio = &dev->sdio; + u16 first = q->first; u8 pad; while (q->first != q->head) { @@ -263,11 +264,11 @@ static int mt76s_tx_run_queue(struct mt76_dev *dev, struct mt76_queue *q) err = __skb_grow(e->skb, roundup(e->skb->len, sdio->func->cur_blksize)); if (err) - return err; + goto out; err = __mt76s_xmit_queue(dev, e->skb->data, e->skb->len); if (err) - return err; + goto out; goto next; } @@ -303,13 +304,16 @@ static int mt76s_tx_run_queue(struct mt76_dev *dev, struct mt76_queue *q) memset(sdio->xmit_buf + len, 0, 4); err = __mt76s_xmit_queue(dev, sdio->xmit_buf, len + 4); if (err) - return err; + goto out; } mt76s_tx_update_quota(sdio, mcu, pse_sz, ple_sz); + err = nframes; - mt76_worker_schedule(&sdio->status_worker); +out: + if (q->first != first) + mt76_worker_schedule(&sdio->status_worker); - return nframes; + return err; } void mt76s_txrx_worker(struct mt76_sdio *sdio) -- 2.56.1 With runtime PM enabled, mt76_connac_power_save_sched() cancels the pending mac_work on every activity while the chip is awake, and only mt7615_pm_wake_work() queues it again. Disabling runtime PM through debugfs while the chip is awake leaves it cancelled: mt76_connac_pm_wake() has nothing to wake, so nothing queues mac_work, and the channel survey, MIB counters, SCS and the tx status timeout stay stopped until the next channel change, start or resume. Queue mac_work when runtime PM is turned off. On an mt7663s, counting mt7615_mac_work in a function trace of an idle link - 26 runs in 3 s with runtime PM off, none in 5 s with it on, and none after switching it off again until a reconnect changed the channel. With this change, 26-27 runs in 3 s right after switching it off (immediately after enabling it, and after 5 s of it). Fixes: b1bd7bb8121d ("mt76: connac: unschedule mac_work before going to sleep") Signed-off-by: Ryan Brue --- drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c index 83cffa94bc0e..630f29069aa0 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c @@ -127,6 +127,13 @@ mt7615_pm_set(void *data, u64 val) pm->enable = val; mt76_connac_power_save_sched(&dev->mphy, pm); + + /* With runtime PM on, mac_work is cancelled on activity and queued + * again only on wakeup: restart it when runtime PM goes off. + */ + if (!val && test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) + ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work, + mt7615_get_macwork_timeout(dev)); out: mutex_unlock(&dev->mt76.mutex); -- 2.56.1