wifi: mt76: mt7996: replace direct WTBL access with MCU for station statistics
Subsystems (2)
PATCH v3 1/1 wifi: mt76: mt7996: replace direct WTBL access with MCU for station statistics
Direct MMIO access to WTBL entries for airtime and RSSI statistics in mt7996_mac_sta_poll() races with firmware, causing warnings at mt7996_mac_wtbl_lmac_addr, MCU message timeouts, and firmware communication breakdown. The function was called from mt7996_mac_tx_free() on every TX-Free-Done event, compounding the issue with heavy CPU overhead.
Replace the direct WTBL polling with firmware MCU queries:
- Airtime: UNI_ALL_STA_TXRX_AIR_TIME via the existing all_sta_info MCU command, with a new handler in mt7996_mcu_rx_all_sta_info_event()
- RSSI: UNI_PER_STA_RSSI via new mt7996_mcu_get_per_sta_info() using MCU_WM_UNI_CMD(PER_STA_INFO)
Both queries run from mt7996_mac_work() every 5th tick under dev mutex, matching the pattern already used for TX rate, admission stats, and MSDU count reporting.
Remove mt7996_mac_sta_poll() and its airtime_ac tracking array entirely, along with the now-orphaned mt76_wcid_add_poll() producers in the RX status, TX free, and TX status paths that fed the removed consumer.
The per-sta-info response handler validates the firmware-returned entry count against what was requested and against the skb payload length before walking the response array, and uses bounds-checked mt76_wcid_ptr() for WLAN ID lookup. RSSI polling is batched in groups of PER_STA_INFO_MAX_NUM to cover the full WTBL capacity.
Vendor driver analysis (mt_wifi.ko from Xiaomi AX3000T MT7981 firmware) confirms the RCPI-to-RSSI conversion formula (rcpi - 220) / 2 and that the vendor never performs direct WTBL reads for statistics.
--- .../wireless/mediatek/mt76/mt76_connac_mcu.h | 7 + .../net/wireless/mediatek/mt76/mt7996/mac.c | 144 +----------------- .../net/wireless/mediatek/mt76/mt7996/mcu.c | 133 ++++++++++++++++ .../net/wireless/mediatek/mt76/mt7996/mcu.h | 25 +++ .../wireless/mediatek/mt76/mt7996/mt7996.h | 2 +- 5 files changed, 168 insertions(+), 143 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h +7 -0
@@ -1392,6 +1392,13 @@ enum { UNI_OFFLOAD_OFFLOAD_BMC_RPY_DETECT, }; +#define PER_STA_INFO_MAX_NUM 90 + +enum UNI_PER_STA_INFO_TAG { +UNI_PER_STA_RSSI , +UNI_PER_STA_MAX_NUM +}; +enum UNI_ALL_STA_INFO_TAG {UNI_ALL_STA_TXRX_RATE ,UNI_ALL_STA_TX_STAT ,
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +2 -142
192 lines not on this page · raw message
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +133 -0
145 lines not on this page · raw message
drivers/net/wireless/mediatek/mt76/mt7996/mcu.h +25 -0
@@ -220,6 +220,31 @@ struct mt7996_mcu_all_sta_info_event {__le32 tx_msdu_cnt;__le32 rx_msdu_cnt; } __packed, msdu_cnt); + +DECLARE_FLEX_ARRAY (struct { +__le16 wlan_idx; +u8 rsv[2 ]; +__le32 tx[IEEE80211_NUM_ACS ]; +__le32 rx[IEEE80211_NUM_ACS ]; + } __packed, airtime); + } __packed; +} __packed; + +struct mt7996_mcu_per_sta_info_event { +u8 rsv[4 ]; +__le16 tag; +__le16 len; +u8 more; +u8 rsv2; +__le16 sta_num; +u8 rsv3[4 ]; + +union { +DECLARE_FLEX_ARRAY (struct { +__le16 wlan_idx; +u8 rsv[2 ]; +u8 rcpi[4 ]; + } __packed, rssi); } __packed; } __packed;
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +1 -1
@@ -222,7 +222,6 @@ struct mt7996_sta_link {struct mt7996_sta *sta;struct list_head rc_list; -u32 airtime_ac[8 ];int ack_signal;struct ewma_avg_signal avg_ack_signal;
@@ -741,6 +740,7 @@ int mt7996_mcu_trigger_assert(struct mt7996_dev *dev);void mt7996_mcu_rx_event (struct mt7996_dev *dev,struct sk_buff *skb);void mt7996_mcu_exit (struct mt7996_dev *dev);int mt7996_mcu_get_all_sta_info (struct mt7996_phy *phy,u16 tag); +int mt7996_mcu_get_per_sta_info (struct mt7996_phy *phy,u16 tag);int mt7996_mcu_wed_rro_reset_sessions (struct mt7996_dev *dev,u16 id);int mt7996_mcu_set_sniffer_mode (struct mt7996_phy *phy,bool enabled);
Signature · 1 line
2.43.0