wifi: mt76: fix HE DCM max-RU capability encoding
Subsystems (2)
Felix Fietkau
maintainerPATCH 1/29 wifi: mt76: fix HE DCM max-RU capability encoding
sta_rec_he.dcm_rx_max_nss was assigned twice: the second assignment, sourced from HE PHY capability byte 8 (DCM max RU), overwrote the RX-NSS value and left dcm_max_ru at zero. Every associated HE station advertising DCM support was configured in firmware with a wrong dcm_rx_max_nss and a zero dcm_max_ru. Store the DCM max-RU value in dcm_max_ru as intended.
The same copy-paste error existed in both the shared connac2 path and the mt7915 path.
--- drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +1 -1
@@ -800,7 +800,7 @@ mt76_connac_mcu_sta_he_tlv(struct sk_buff *skb, struct ieee80211_sta *sta)HE_PHY (CAP3_DCM_MAX_CONST_RX_MASK , elem->phy_cap_info[3 ]); he->dcm_rx_max_nss =HE_PHY (CAP3_DCM_MAX_RX_NSS_2 , elem->phy_cap_info[3 ]); - he->dcm_rx_max_nss = + he->dcm_max_ru =HE_PHY (CAP8_DCM_MAX_RU_MASK , elem->phy_cap_info[8 ]); he->pkt_ext =2 ;
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +1 -1
@@ -900,7 +900,7 @@ mt7915_mcu_sta_he_tlv(struct sk_buff *skb, struct ieee80211_sta *sta,HE_PHY (CAP3_DCM_MAX_CONST_RX_MASK , elem->phy_cap_info[3 ]); he->dcm_rx_max_nss =HE_PHY (CAP3_DCM_MAX_RX_NSS_2 , elem->phy_cap_info[3 ]); - he->dcm_rx_max_nss = + he->dcm_max_ru =HE_PHY (CAP8_DCM_MAX_RU_MASK , elem->phy_cap_info[8 ]); he->pkt_ext =2 ;
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 2/29 wifi: mt76: mt7996: bound TLV walk in mt7996_mcu_get_chip_config
The response TLV loop advanced by tlv->len without a minimum, so a theoretical firmware response containing a zero-length TLV could spin forever, hanging the CPU during device probe.
The u32 payload was also read without bounds checking. Reject a short fixed field, stop on a TLV whose length underruns the header or overruns the skb.
--- drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +13 -3
@@ -4438,21 +4438,31 @@ int mt7996_mcu_get_chip_config(struct mt7996_dev *dev, u32 *cap)return ret;/* fixed field */ +if (skb->len <4 ) { +dev_kfree_skb (skb); +return -EINVAL ; + }skb_pull (skb,4 ); buf = skb->data; -while (buf - skb->data < skb->len) { +while (buf - skb->data +sizeof (struct tlv ) <= skb->len) {struct tlv *tlv = (struct tlv *)buf; +u16 tlv_len =le16_to_cpu (tlv->len); + +if (tlv_len <sizeof (*tlv) || + tlv_len > skb->len - (buf - skb->data)) +break ;switch (le16_to_cpu (tlv->tag)) {case UNI_EVENT_CHIP_CONFIG_EFUSE_VERSION : - *cap =le32_to_cpu (*(__le32 *)(buf +sizeof (*tlv))); +if (tlv_len >=sizeof (*tlv) +sizeof (__le32)) + *cap =le32_to_cpu (*(__le32 *)(buf +sizeof (*tlv)));break ;default :break ; } - buf +=le16_to_cpu (tlv->len); + buf += tlv_len; }dev_kfree_skb (skb);
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 3/29 wifi: mt76: fix out-of-bounds access in mmio copy helpers
In reply to Felix Fietkaumt76_mmio_write_copy() and mt76_mmio_read_copy() iterate up to ALIGN(len, 4), so a length that is not a multiple of four reads past the source buffer (write_copy) or writes past the destination (read_copy). Copy the aligned body in the loop and handle the remaining tail through a 4-byte bounce buffer, keeping the register access width unchanged.
--- drivers/net/wireless/mediatek/mt76/mmio.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mmio.c +16 -2
@@ -35,9 +35,16 @@ static void mt76_mmio_write_copy(struct mt76_dev *dev, u32 offset, {int i; -for (i =0 ; i <ALIGN (len,4 ); i +=4 ) +for (i =0 ; i +4 <= len; i +=4 )writel (get_unaligned_le32 (data + i), dev->mmio.regs + offset + i); + +if (i < len) { +u8 tmp[4 ] = {}; + +memcpy (tmp, data + i, len - i); +writel (get_unaligned_le32 (tmp), dev->mmio.regs + offset + i); + } } static void mt76_mmio_read_copy(struct mt76_dev *dev, u32 offset,
@@ -45,9 +52,16 @@ static void mt76_mmio_read_copy(struct mt76_dev *dev, u32 offset, {int i; -for (i =0 ; i <ALIGN (len,4 ); i +=4 ) +for (i =0 ; i +4 <= len; i +=4 )put_unaligned_le32 (readl (dev->mmio.regs + offset + i), data + i); + +if (i < len) { +u8 tmp[4 ]; + +put_unaligned_le32 (readl (dev->mmio.regs + offset + i), tmp); +memcpy (data + i, tmp, len - i); + } } static int mt76_mmio_wr_rp(struct mt76_dev *dev, u32 base,
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 4/29 wifi: mt76: mt7915: unwind state on add_interface failure
In reply to Felix FietkauWhen mt76_wcid_alloc() fails, mt7915_add_interface() returned without clearing the vif_mask/omac_mask bits it had already set, without removing the firmware dev info added earlier, and without clearing a monitor_vif pointer to the vif mac80211 is about to free. mac80211 does not call remove_interface() for a failed add, so the indices and firmware dev entry leaked permanently and testmode could dereference the stale monitor_vif. Add a proper error unwind.
--- drivers/net/wireless/mediatek/mt76/mt7915/main.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/main.c +11 -1
@@ -249,7 +249,7 @@ static int mt7915_add_interface(struct ieee80211_hw *hw, idx =mt76_wcid_alloc (dev->mt76.wcid_mask,mt7915_wtbl_size (dev));if (idx <0 ) { ret = -ENOSPC ; - goto out; + goto err; }INIT_LIST_HEAD (&mvif->sta.rc_list);
@@ -277,7 +277,17 @@ static int mt7915_add_interface(struct ieee80211_hw *hw,mt7915_mcu_add_sta (dev, vif,NULL ,CONN_STATE_PORT_SECURE , true);rcu_assign_pointer (dev->mt76.wcid[idx], &mvif->sta.wcid); +mutex_unlock (&dev->mt76.mutex); + +return 0 ; + +err: + dev->mt76.vif_mask &= ~BIT_ULL (mvif->mt76.idx); + phy->omac_mask &= ~BIT_ULL (mvif->mt76.omac_idx); +mt7915_mcu_add_dev_info (phy, vif, false); out: +if (phy->monitor_vif == vif) + phy->monitor_vif =NULL ;mutex_unlock (&dev->mt76.mutex);return ret;
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 5/29 wifi: mt76: mt7996: hold dev->mt76.mutex while disabling tx worker in SER
In reply to Felix Fietkaumt7996_mac_reset_work() parked the tx worker and disabled the RX/TX NAPIs before taking dev->mt76.mutex. mt76_worker_disable()/_enable() are plain kthread park/unpark, not refcounted, and __mt76_set_channel() toggles the same worker and the MT76_RESET bit under the mutex. An L1 SER racing a channel switch could therefore have the worker unparked and MT76_RESET cleared while the reset path resets the DMA rings, corrupting descriptors or tokens. Take the mutex before disabling the worker, as mt7915 does.
--- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +2 -2
@@ -2573,6 +2573,8 @@ void mt7996_mac_reset_work(struct work_struct *work)cancel_delayed_work_sync (&phy->mt76->mac_work); } +mutex_lock (&dev->mt76.mutex); +mt76_worker_disable (&dev->mt76.tx_worker);mt76_for_each_q_rx (&dev->mt76, i) { if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
@@ -2590,8 +2592,6 @@ void mt7996_mac_reset_work(struct work_struct *work) }napi_disable (&dev->mt76.tx_napi); -mutex_lock (&dev->mt76.mutex); -mt76_wr (dev,MT_MCU_INT_EVENT ,MT_MCU_INT_EVENT_DMA_STOPPED );if (mt7996_wait_reset_state (dev,MT_MCU_CMD_RESET_DONE )) {
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 6/29 wifi: mt76: decode the full VHT Rx STBC capability field
In reply to Felix FietkauThe Rx STBC subfield of the VHT capabilities is a 3-bit cumulative value, but the driver only tested the RXSTBC_1 bit when advertising the peer's Rx STBC support to firmware. A peer reporting Rx STBC of 2, 3 or 4 has that bit clear, so STBC was never used towards it. Test the full IEEE80211_VHT_CAP_RXSTBC_MASK, matching the HT path.
--- drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +1 -1
@@ -1617,7 +1617,7 @@ mt7915_mcu_sta_rate_ctrl_tlv(struct sk_buff *skb, struct mt7915_dev *dev, cap |=STA_CAP_VHT_SGI_160 ;if (sta->deflink.vht_cap.cap &IEEE80211_VHT_CAP_TXSTBC ) cap |=STA_CAP_VHT_TX_STBC ; -if (sta->deflink.vht_cap.cap &IEEE80211_VHT_CAP_RXSTBC_1 ) +if (sta->deflink.vht_cap.cap &IEEE80211_VHT_CAP_RXSTBC_MASK ) cap |=STA_CAP_VHT_RX_STBC ;if (mvif->cap.vht_ldpc && (sta->deflink.vht_cap.cap &IEEE80211_VHT_CAP_RXLDPC ))
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +1 -1
@@ -2476,7 +2476,7 @@ mt7996_mcu_sta_rate_ctrl_tlv(struct sk_buff *skb, struct mt7996_dev *dev, cap |=STA_CAP_VHT_SGI_160 ;if (link_sta->vht_cap.cap &IEEE80211_VHT_CAP_TXSTBC ) cap |=STA_CAP_VHT_TX_STBC ; -if (link_sta->vht_cap.cap &IEEE80211_VHT_CAP_RXSTBC_1 ) +if (link_sta->vht_cap.cap &IEEE80211_VHT_CAP_RXSTBC_MASK ) cap |=STA_CAP_VHT_RX_STBC ;if ((vif->type !=NL80211_IFTYPE_AP || link_conf->vht_ldpc) && (link_sta->vht_cap.cap &IEEE80211_VHT_CAP_RXLDPC ))
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 7/29 wifi: mt76: fix ER-SU 106-tone RU check in RX rate decode
In reply to Felix FietkauMT_PHY_TYPE_HE_EXT_SU is an enum value (9), not a bit flag, so the bitwise test "*mode & MT_PHY_TYPE_HE_EXT_SU" also matches OFDM, HT-GF and several HE/EHT modes. Only genuine ER-SU should be classified as a 106-tone RU at 40 MHz; use an equality comparison.
--- drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c +1 -1
@@ -1114,7 +1114,7 @@ int mt76_connac2_mac_fill_rx_rate(struct mt76_dev *dev,case IEEE80211_STA_RX_BW_20 :break ;case IEEE80211_STA_RX_BW_40 : -if (*mode &MT_PHY_TYPE_HE_EXT_SU && +if (*mode ==MT_PHY_TYPE_HE_EXT_SU && (idx &MT_PRXV_TX_ER_SU_106T )) { status->bw =RATE_INFO_BW_HE_RU ; status->he_ru =
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +1 -1
@@ -349,7 +349,7 @@ mt7996_mac_fill_rx_rate(struct mt7996_dev *dev,case IEEE80211_STA_RX_BW_20 :break ;case IEEE80211_STA_RX_BW_40 : -if (*mode &MT_PHY_TYPE_HE_EXT_SU && +if (*mode ==MT_PHY_TYPE_HE_EXT_SU && (idx &MT_PRXV_TX_ER_SU_106T )) { status->bw =RATE_INFO_BW_HE_RU ; status->he_ru =
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 8/29 wifi: mt76: mt7996: reserve space for the CSA-abort countdown TLV
In reply to Felix FietkauWhen a CSA countdown is active, mt7996_mcu_beacon_cntdwn() emits two bss_bcn_cntdwn_tlv entries (the CSA countdown and the CCA-abort BCC), but MT7996_BEACON_UPDATE_SIZE only reserved one. With MBSSID enabled and a near-maximum beacon template the extra 8 bytes could push the offload command past MT7996_MAX_BSS_OFFLOAD_SIZE and trigger skb_over_panic(). Reserve room for both countdown TLVs.
--- drivers/net/wireless/mediatek/mt76/mt7996/mcu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.h +1 -1
@@ -917,7 +917,7 @@ enum {#define MT7996_BEACON_UPDATE_SIZE (sizeof(struct bss_req_hdr) + \ sizeof(struct bss_bcn_content_tlv) + \ 4 + MT_TXD_SIZE + \ - sizeof(struct bss_bcn_cntdwn_tlv) + \ + sizeof(struct bss_bcn_cntdwn_tlv) * 2 + \ sizeof(struct bss_bcn_mbss_tlv))#define MT7996_MAX_BSS_OFFLOAD_SIZE 2048#define MT7996_MAX_BEACON_SIZE (MT7996_MAX_BSS_OFFLOAD_SIZE - \
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 9/29 wifi: mt76: mt7996: don't leak MLD group index on remap alloc failure
In reply to Felix Fietkaumt7996_change_vif_links() sets the mld_idx_mask group bit before allocating the remap index. If the remap allocation fails it jumped to the exit without clearing that bit, permanently consuming one of the 16 MLD group slots. Release the group bit on the error path.
--- drivers/net/wireless/mediatek/mt76/mt7996/main.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +1 -0
@@ -2458,6 +2458,7 @@ mt7996_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif, idx =get_free_idx (dev->mld_remap_idx_mask,0 ,15 ) -1 ;if (idx <0 ) { + dev->mld_idx_mask &= ~BIT_ULL (mvif->mld_group_idx); ret = -ENOSPC ; goto out; }
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 10/29 wifi: mt76: cancel reset and rc work on device unregister
In reply to Felix FietkauBoth drivers cancelled dump_work on unregister but left reset_work and rc_work to be flushed only by destroy_workqueue() in mt76_free_device(), which runs after the hw is unregistered and the hardware stopped. A reset_work that fires in that window calls ieee80211_restart_hw() and re-arms mac_work on an unregistered hw, and rc_work touches station state being torn down. Cancel both up front, alongside dump_work.
--- drivers/net/wireless/mediatek/mt76/mt7915/init.c | 2 ++ drivers/net/wireless/mediatek/mt76/mt7996/init.c | 2 ++ 2 files changed, 4 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7915/init.c +2 -0
@@ -1325,6 +1325,8 @@ int mt7915_register_device(struct mt7915_dev *dev)void mt7915_unregister_device (struct mt7915_dev *dev) {cancel_work_sync (&dev->dump_work); +cancel_work_sync (&dev->reset_work); +cancel_work_sync (&dev->rc_work);mt7915_unregister_ext_phy (dev);mt7915_coredump_unregister (dev);mt7915_unregister_thermal (&dev->phy);
drivers/net/wireless/mediatek/mt76/mt7996/init.c +2 -0
@@ -1806,6 +1806,8 @@ void mt7996_unregister_device(struct mt7996_dev *dev) {cancel_work_sync (&dev->dump_work);cancel_work_sync (&dev->wed_rro.work); +cancel_work_sync (&dev->reset_work); +cancel_work_sync (&dev->rc_work);mt7996_unregister_phy (mt7996_phy3 (dev));mt7996_unregister_phy (mt7996_phy2 (dev));mt7996_unregister_thermal (&dev->phy);
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 11/29 wifi: mt76: report data NSS for STBC frames in RX rate decode
In reply to Felix FietkauThe RX rate decoder set status->nss straight from the PRXV NSTS field, which for STBC frames is twice the data spatial-stream count. cfg80211 then reported a doubled RX bitrate in station dumps and radiotap. Halve nss for STBC, matching the TX status path.
--- drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c | 4 ++++ drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 4 ++++ 2 files changed, 8 insertions(+)
drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c +4 -0
@@ -1069,6 +1069,10 @@ int mt76_connac2_mac_fill_rx_rate(struct mt76_dev *dev, bw =FIELD_GET (MT_CRXV_FRAME_MODE , v2); } +/* the hardware reports NSTS; report the data NSS for STBC frames */ +if (stbc && nss >1 ) + nss >>=1 ; +switch (*mode) {case MT_PHY_TYPE_CCK : cck = true;
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +4 -0
@@ -294,6 +294,10 @@ mt7996_mac_fill_rx_rate(struct mt7996_dev *dev, dcm =FIELD_GET (MT_PRXV_DCM , v2); bw =FIELD_GET (MT_PRXV_FRAME_MODE , v2); +/* the hardware reports NSTS; report the data NSS for STBC frames */ +if (stbc && nss >1 ) + nss >>=1 ; +switch (*mode) {case MT_PHY_TYPE_CCK : cck = true;
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 12/29 wifi: mt76: mt7915: use little-endian for bss_info_ra wire fields
In reply to Felix Fietkautrain_up_high_thres, train_up_rule_rssi and low_traffic_thres were declared as host-native short in a firmware-facing TLV and assigned host-order constants, so on a big-endian host the firmware received byte-swapped rate-adaptation thresholds. Declare them __le16 and convert with cpu_to_le16().
--- drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 6 +++--- drivers/net/wireless/mediatek/mt76/mt7915/mcu.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +3 -3
@@ -576,9 +576,9 @@ mt7915_mcu_bss_ra_tlv(struct sk_buff *skb, struct ieee80211_vif *vif, ra->rx_streams = max_nss; ra->algo =4 ; ra->train_up_rule =2 ; - ra->train_up_high_thres =110 ; - ra->train_up_rule_rssi =-70 ; - ra->low_traffic_thres =2 ; + ra->train_up_high_thres =cpu_to_le16 (110 ); + ra->train_up_rule_rssi =cpu_to_le16 (-70 ); + ra->low_traffic_thres =cpu_to_le16 (2 ); ra->phy_cap =cpu_to_le32 (0xfdf ); ra->interval =cpu_to_le32 (500 ); ra->fast_interval =cpu_to_le32 (100 );
drivers/net/wireless/mediatek/mt76/mt7915/mcu.h +3 -3
@@ -318,9 +318,9 @@ struct bss_info_ra {u8 antenna_idx;u8 train_up_rule;u8 rsv[3 ]; -unsigned short train_up_high_thres; -short train_up_rule_rssi; -unsigned short low_traffic_thres; +__le16 train_up_high_thres; +__le16 train_up_rule_rssi; +__le16 low_traffic_thres;__le16 max_phyrate;__le32 phy_cap;__le32 interval;
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 13/29 wifi: mt76: mt7996: add missing rdd_idx check when enabling background radar
In reply to Felix FietkauFrom: StanleyYP Wang <[email protected]>
Add the missing rdd idx check (< 0) in mt7996_mcu_rdd_background_enable(). mt7996_get_rdd_idx() returns -1 for phys without 5 GHz support, and the negative index was passed to the RDD MCU command unchecked.
--- drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +3 -0
@@ -4016,6 +4016,9 @@ int mt7996_mcu_rdd_background_enable(struct mt7996_phy *phy,struct mt7996_dev *dev = phy->dev;int err, region, rdd_idx =mt7996_get_rdd_idx (phy, true); +if (rdd_idx <0 ) +return -EINVAL ; +if (!chandef) {/* disable offchain */ err =mt7996_mcu_rdd_cmd (dev,RDD_STOP , rdd_idx,0 );if (err)
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 14/29 wifi: mt76: only consume the WO drop bit on WED v2 devices
In reply to Felix FietkauThe RX path is handled by the WO MCU only on WED v2 hardware. On WED v3 the same buf1 bit does not carry drop information, so evaluating it there causes spurious RX drops.
--- drivers/net/wireless/mediatek/mt76/dma.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/dma.c +6 -1
@@ -547,8 +547,13 @@ mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx, t->ptr =NULL ;mt76_put_rxwi (dev, t); -if (drop) +#ifdef CONFIG_NET_MEDIATEK_SOC_WED +/* the WO MCU owns the RX path only on WED v2, on newer +* versions this buf1 bit carries no drop information +*/ +if (drop && dev->mmio.wed.version ==2 ) *drop |= !!(buf1 &MT_DMA_CTL_WO_DROP ); +#endif }else { dma_sync_single_for_cpu(dev->dma_dev, e->dma_addr[0], SKB_WITH_OVERHEAD(q->buf_size),
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 15/29 wifi: mt76: mt7996: add mcu command to set bssid mapping address
In reply to Felix FietkauFrom: Peter Chiu <[email protected]>
When receiving a 4 address non-AMSDU packet, there is no bssid in the address fields, which breaks powersave handling for 4-address peers. Set the mcu command to use A1 as bssid when receiving 4 address non-AMSDU packets on mt7992 and mt7990.
Also skip mt7996_mac_init_band() for invalid bands, so the command is only sent for bands that actually exist on the device.
--- .../net/wireless/mediatek/mt76/mt7996/init.c | 6 +++++ .../net/wireless/mediatek/mt76/mt7996/mcu.c | 26 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt7996/mcu.h | 1 + .../wireless/mediatek/mt76/mt7996/mt7996.h | 1 + 4 files changed, 34 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/init.c +6 -0
@@ -562,6 +562,9 @@ mt7996_mac_init_band(struct mt7996_dev *dev, u8 band) {u32 mask, set; +if (!mt7996_band_valid (dev, band)) +return ; +/* clear estimated value of EIFS for Rx duration & OBSS time */ mt76_wr (dev,MT_WF_RMAC_RSVD0 (band),MT_WF_RMAC_RSVD0_EIFS_CLR );
@@ -593,6 +596,9 @@ mt7996_mac_init_band(struct mt7996_dev *dev, u8 band)* MT_AGG_ACR_PPDU_TXS2H (PPDU format) even though ACR bit is set. */ mt76_set (dev,MT_AGG_ACR4 (band),MT_AGG_ACR_PPDU_TXS2H ); + +if (!is_mt7996 (&dev->mt76)) +mt7996_mcu_set_bssid_mapping_addr (&dev->mt76, band); }static void mt7996_mac_init_basic_rates (struct mt7996_dev *dev)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +26 -0
@@ -5042,6 +5042,32 @@ int mt7996_mcu_twt_agrt_update(struct mt7996_dev *dev, &req, sizeof(req), true); } +int mt7996_mcu_set_bssid_mapping_addr (struct mt76_dev *dev,u8 band_idx) +{ +enum { +BSSID_MAPPING_ADDR1 , +BSSID_MAPPING_ADDR2 , +BSSID_MAPPING_ADDR3 , + }; +struct { +u8 band_idx; +u8 _rsv1[3 ]; + +__le16 tag; +__le16 len; +u8 addr; +u8 _rsv2[3 ]; + } __packed req = { + .band_idx = band_idx, + .tag =cpu_to_le16 (UNI_BAND_CONFIG_BSSID_MAPPING_ADDR ), + .len =cpu_to_le16 (sizeof (req) -4 ), + .addr =BSSID_MAPPING_ADDR1 , + }; + +return mt76_mcu_send_msg (dev,MCU_WM_UNI_CMD (BAND_CONFIG ), + &req,sizeof (req), true); +} +int mt7996_mcu_set_rts_thresh (struct mt7996_phy *phy,u32 val) {struct {
drivers/net/wireless/mediatek/mt76/mt7996/mcu.h +1 -0
@@ -927,6 +927,7 @@ enum {UNI_BAND_CONFIG_RADIO_ENABLE ,UNI_BAND_CONFIG_RTS_THRESHOLD =0x08 ,UNI_BAND_CONFIG_MAC_ENABLE_CTRL =0x0c , + UNI_BAND_CONFIG_BSSID_MAPPING_ADDR = 0x12, }; enum {
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +1 -0
@@ -772,6 +772,7 @@ int mt7996_mcu_set_protection(struct mt7996_phy *phy, struct mt7996_vif_link *li u8 ht_mode, bool use_cts_prot);int mt7996_mcu_set_timing (struct mt7996_phy *phy,struct ieee80211_vif *vif,struct ieee80211_bss_conf *link_conf); +int mt7996_mcu_set_bssid_mapping_addr (struct mt76_dev *dev,u8 band_idx);int mt7996_mcu_get_chan_mib_info (struct mt7996_phy *phy,bool chan_switch);int mt7996_mcu_get_temperature (struct mt7996_phy *phy);int mt7996_mcu_set_thermal_throttling (struct mt7996_phy *phy,u8 state);
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 16/29 wifi: mt76: mt7996: leave PS when a 4-address connection is established
In reply to Felix FietkauFrom: Peter Chiu <[email protected]>
Because 4 address non-AMSDU packets do not have a bssid field, the hardware cannot get the bssid. Without the bssid, stations are not able to leave PS mode due to HW design. Wake up non-setup links when 4-address mode is established to prevent this issue.
mt7992 and mt7990 handle this via the BSSID mapping band config instead, so restrict the command to mt7996.
--- .../wireless/mediatek/mt76/mt76_connac_mcu.h | 1 + .../net/wireless/mediatek/mt76/mt7996/main.c | 8 ++++++++ .../net/wireless/mediatek/mt76/mt7996/mcu.c | 18 ++++++++++++++++++ .../net/wireless/mediatek/mt76/mt7996/mcu.h | 6 ++++++ .../net/wireless/mediatek/mt76/mt7996/mt7996.h | 2 ++ 5 files changed, 35 insertions(+)
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h +1 -0
@@ -867,6 +867,7 @@ enum {STA_REC_HDRT =0x28 ,STA_REC_EML_OP =0x29 ,STA_REC_HDR_TRANS =0x2B , +STA_REC_PS_LEAVE =0x45 , STA_REC_MAX_NUM };
drivers/net/wireless/mediatek/mt76/mt7996/main.c +8 -0
@@ -2067,6 +2067,14 @@ static void mt7996_sta_set_decap_offload(struct ieee80211_hw *hw,continue ;mt7996_mcu_wtbl_update_hdr_trans (dev, vif, link, msta_link); + +/* HW cannot derive the BSSID from 4-address non-AMSDU frames, +* so PS exit is missed on links other than the setup link. +* Let the firmware wake those links instead. +*/ +if (enabled && msta->deflink_id != link_id && +is_mt7996 (&dev->mt76)) +mt7996_mcu_ps_leave (dev, link, msta_link); }mutex_unlock (&dev->mt76.mutex);
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +18 -0
@@ -5184,6 +5184,24 @@ int mt7996_mcu_wtbl_update_hdr_trans(struct mt7996_dev *dev, MCU_WMWA_UNI_CMD(STA_REC_UPDATE), true); } +int mt7996_mcu_ps_leave (struct mt7996_dev *dev,struct mt7996_vif_link *link, +struct mt7996_sta_link *msta_link) +{ +struct sk_buff *skb; + + skb =__mt76_connac_mcu_alloc_sta_req (&dev->mt76, &link->mt76, + &msta_link->wcid, +MT7996_STA_UPDATE_MAX_SIZE ); +if (IS_ERR (skb)) +return PTR_ERR (skb); + +mt76_connac_mcu_add_tlv (skb,STA_REC_PS_LEAVE , +sizeof (struct sta_rec_ps_leave )); + +return mt76_mcu_skb_send_msg (&dev->mt76, skb, +MCU_WMWA_UNI_CMD (STA_REC_UPDATE ), true); +} +int mt7996_mcu_set_fixed_rate_table (struct mt7996_phy *phy,u8 table_idx,u16 rate_idx,bool beacon) {
drivers/net/wireless/mediatek/mt76/mt7996/mcu.h +6 -0
@@ -680,6 +680,12 @@ struct sta_rec_hdr_trans {u8 mesh; } __packed; +struct sta_rec_ps_leave { +__le16 tag; +__le16 len; +u8 __rsv[4 ]; +} __packed; +struct sta_rec_mld_setup {__le16 tag;__le16 len;
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +2 -0
@@ -928,6 +928,8 @@ int mt7996_mcu_wtbl_update_hdr_trans(struct mt7996_dev *dev,struct ieee80211_vif *vif, struct mt7996_vif_link *link, struct mt7996_sta_link *msta_link); +int mt7996_mcu_ps_leave (struct mt7996_dev *dev,struct mt7996_vif_link *link, +struct mt7996_sta_link *msta_link);int mt7996_mcu_cp_support (struct mt7996_dev *dev,u8 mode); int mt7996_mcu_set_emlsr_mode(struct mt7996_dev *dev, struct ieee80211_vif *vif,
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 17/29 wifi: mt76: mt7915: unlink TWT flow if the MCU rejects the agreement
In reply to Felix FietkauThe flow is added to dev->twt_list before sending the agreement to the firmware, but the error path leaves it linked while flowid_mask is never set. The flow slot can then be reused and memset while still on the list, corrupting twt_list, and station removal leaves a dangling entry behind that mt7915_mac_twt_sched_list_add() later walks.
--- drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +3 -1
@@ -2350,8 +2350,10 @@ void mt7915_mac_add_twt_setup(struct ieee80211_hw *hw, } flow->tsf =le64_to_cpu (twt_agrt->twt); -if (mt7915_mcu_twt_agrt_update (dev, msta->vif, flow,MCU_TWT_AGRT_ADD )) +if (mt7915_mcu_twt_agrt_update (dev, msta->vif, flow,MCU_TWT_AGRT_ADD )) { +list_del (&flow->list); goto unlock; + } setup_cmd =TWT_SETUP_CMD_ACCEPT ; dev->twt.table_mask |=BIT (table_id);
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 18/29 wifi: mt76: mt7996: skip key upload when adding an offchannel link
In reply to Felix FietkauNo hw keys are ever uploaded for scanning/roc links and the link remove path already skips the key iteration for them. The add path still runs it, and since mt7996_set_hw_key() resolves the target through mvif->link[link_id] rather than the offchannel link, starting a scan on another band re-uploads the group keys of the link sharing the same link_id, re-sending its BSS cipher info and, for BIGTK with beacon protection on an AP link, toggling its beacons off and on.
Skip the key iteration for offchannel links, mirroring the remove path.
--- drivers/net/wireless/mediatek/mt76/mt7996/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +2 -1
@@ -372,7 +372,8 @@ int mt7996_vif_link_add(struct mt76_phy *mphy, struct ieee80211_vif *vif, CONN_STATE_PORT_SECURE, true);rcu_assign_pointer (dev->mt76.wcid[idx], &msta_link->wcid); -ieee80211_iter_keys (mphy->hw, vif, mt7996_key_iter, &it); +if (!mlink->wcid->offchannel) +ieee80211_iter_keys (mphy->hw, vif, mt7996_key_iter, &it);if (!mlink->wcid->offchannel) { if (vif->txq &&
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 19/29 wifi: mt76: mt7996: wake MCU waiters before aborting scan in L1 SER
In reply to Felix FietkauThe L1 reset path calls mt76_abort_scan() between setting MT76_MCU_RESET and waking mcu.wait. A scan work blocked on an in-flight MCU command does not re-evaluate its wait condition until woken, so the cancel_delayed_work_sync() inside the abort sleeps out the full MCU timeout before recovery can proceed, adding several seconds of SER latency. mt7996_mac_full_reset() and the mt7915 counterpart already order the wake-up first.
Wake mcu.wait immediately after setting MT76_MCU_RESET so in-flight commands bail out before the abort synchronises against them.
--- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +1 -1
@@ -2567,8 +2567,8 @@ void mt7996_mac_reset_work(struct work_struct *work)set_bit (MT76_RESET , &dev->mphy.state);set_bit (MT76_MCU_RESET , &dev->mphy.state); -mt76_abort_scan (&dev->mt76);wake_up (&dev->mt76.mcu.wait); +mt76_abort_scan (&dev->mt76);cancel_work_sync (&dev->wed_rro.work);mt7996_for_each_phy (dev, phy) {
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 20/29 wifi: mt76: fix queue reg access when building WED and NPU together
In reply to Felix FietkauMove the offload specific parts of Q_READ/Q_WRITE into mt76_dma_handle_read/write, which return false to fall back to readl/writel. The WED and NPU #ifdefs now live inside those helpers instead of selecting between mutually exclusive macro definitions, so a kernel with both enabled supports both at runtime.
Also fixes the NPU path dereferencing a hardcoded q instead of the macro argument.
--- drivers/net/wireless/mediatek/mt76/dma.h | 110 ++++++++++++----------- 1 file changed, 57 insertions(+), 53 deletions(-)
drivers/net/wireless/mediatek/mt76/dma.h +57 -53
@@ -5,6 +5,8 @@#ifndef __MT76_DMA_H#define __MT76_DMA_H +#include <linux/regmap.h> +#define DMA_DUMMY_DATA ((void *)~0)#define MT_RING_SIZE 0x10
@@ -46,73 +48,75 @@#define MT_FCE_INFO_LEN 4#define MT_RX_RXWI_LEN 32 +static inline bool +mt76_dma_handle_read (struct mt76_queue *q,u32 offset,u32 *val) +{#if IS_ENABLED (CONFIG_NET_MEDIATEK_SOC_WED ) +if (q->flags &MT_QFLAG_WED ) { + *val =mtk_wed_device_reg_read (q->wed, q->wed_regs + offset); + +return true; + } +#endif +#if IS_ENABLED (CONFIG_MT76_NPU ) +if (q->flags &MT_QFLAG_NPU ) { +struct airoha_npu *npu; + + *val =0 ; +rcu_read_lock (); + npu =rcu_dereference (q->dev->mmio.npu); +if (npu) +regmap_read (npu->regmap, q->wed_regs + offset, val); +rcu_read_unlock (); + +return true; + } +#endif + +return false; +} + +static inline bool +mt76_dma_handle_write (struct mt76_queue *q,u32 offset,u32 val) +{ +#if IS_ENABLED (CONFIG_NET_MEDIATEK_SOC_WED ) +if (q->flags &MT_QFLAG_WED ) { +mtk_wed_device_reg_write (q->wed, q->wed_regs + offset, val); + +return true; + } +#endif +#if IS_ENABLED (CONFIG_MT76_NPU ) +if (q->flags &MT_QFLAG_NPU ) { +struct airoha_npu *npu; + +rcu_read_lock (); + npu =rcu_dereference (q->dev->mmio.npu); +if (npu) +regmap_write (npu->regmap, q->wed_regs + offset, val); +rcu_read_unlock (); + +return true; + } +#endif + +return false; +}#define Q_READ (_q, _field) ({ \ u32 _offset = offsetof(struct mt76_queue_regs, _field); \ u32 _val; \ - if ((_q)->flags & MT_QFLAG_WED) \ - _val = mtk_wed_device_reg_read((_q)->wed, \ - ((_q)->wed_regs + \ - _offset)); \ - else \ + if (!mt76_dma_handle_read(_q, _offset, &_val)) \ _val = readl(&(_q)->regs->_field); \ _val; \ })#define Q_WRITE (_q, _field, _val) do { \ u32 _offset = offsetof(struct mt76_queue_regs, _field); \ - if ((_q)->flags & MT_QFLAG_WED) \ - mtk_wed_device_reg_write((_q)->wed, \ - ((_q)->wed_regs + _offset), \ - _val); \ - else \ + if (!mt76_dma_handle_write(_q, _offset, _val)) \ writel(_val, &(_q)->regs->_field); \ } while (0) -#elif IS_ENABLED (CONFIG_MT76_NPU ) - -#define Q_READ (_q, _field) ({ \ - u32 _offset = offsetof(struct mt76_queue_regs, _field); \ - u32 _val = 0; \ - if ((_q)->flags & MT_QFLAG_NPU) { \ - struct airoha_npu *npu; \ - \ - rcu_read_lock(); \ - npu = rcu_dereference(q->dev->mmio.npu); \ - if (npu) \ - regmap_read(npu->regmap, \ - ((_q)->wed_regs + _offset), &_val); \ - rcu_read_unlock(); \ - } else { \ - _val = readl(&(_q)->regs->_field); \ - } \ - _val; \ -}) - -#define Q_WRITE (_q, _field, _val) do { \ - u32 _offset = offsetof(struct mt76_queue_regs, _field); \ - if ((_q)->flags & MT_QFLAG_NPU) { \ - struct airoha_npu *npu; \ - \ - rcu_read_lock(); \ - npu = rcu_dereference(q->dev->mmio.npu); \ - if (npu) \ - regmap_write(npu->regmap, \ - ((_q)->wed_regs + _offset), _val); \ - rcu_read_unlock(); \ - } else { \ - writel(_val, &(_q)->regs->_field); \ - } \ -} while (0) - -#else - -#define Q_READ (_q, _field) readl(&(_q)->regs->_field) -#define Q_WRITE (_q, _field, _val) writel(_val, &(_q)->regs->_field) - -#endif -struct mt76_desc {__le32 buf0;__le32 ctrl;
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 21/29 wifi: mt76: mt7996: select net_setup_tc handler at runtime
In reply to Felix FietkauFrom: Chad Monroe <[email protected]>
The net_setup_tc callback is chosen at compile time and the WED handler shadows the NPU one when CONFIG_NET_MEDIATEK_SOC_WED is enabled. mt76_wed_net_setup_tc() returns -EOPNOTSUPP without an active WED device, so on boards using the Airoha NPU with a WED enabled kernel the tc offload block is never bound and PPE flow offload for wireless traffic is silently disabled.
Dispatch on the active offload backend instead: use the WED handler when a WED device is attached and fall back to the NPU handler otherwise. Builds without MT76_NPU keep the old behavior through the mt76_npu_net_setup_tc() stub.
--- .../net/wireless/mediatek/mt76/mt7996/main.c | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +19 -4
@@ -2443,6 +2443,23 @@ mt7996_net_fill_forward_path(struct ieee80211_hw *hw,return 0 ; } +#if defined(CONFIG_NET_MEDIATEK_SOC_WED ) || defined(CONFIG_MT7996_NPU ) +static int +mt7996_net_setup_tc (struct ieee80211_hw *hw,struct ieee80211_vif *vif, +struct net_device *netdev,enum tc_setup_type type, +void *type_data) +{ +#ifdef CONFIG_NET_MEDIATEK_SOC_WED +struct mt7996_dev *dev =mt7996_hw_dev (hw); + +if (mtk_wed_device_active (&dev->mt76.mmio.wed)) +return mt76_wed_net_setup_tc (hw, vif, netdev, type, + type_data); +#endif +return mt76_npu_net_setup_tc (hw, vif, netdev, type, type_data); +} +#endif + static int mt7996_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 old_links, u16 new_links,
@@ -2570,10 +2587,8 @@ const struct ieee80211_ops mt7996_ops = {#endif .set_radar_background = mt7996_set_radar_background, .net_fill_forward_path = mt7996_net_fill_forward_path, -#ifdef CONFIG_NET_MEDIATEK_SOC_WED - .net_setup_tc = mt76_wed_net_setup_tc, -#elif defined(CONFIG_MT7996_NPU ) - .net_setup_tc = mt76_npu_net_setup_tc, +#if defined(CONFIG_NET_MEDIATEK_SOC_WED) || defined(CONFIG_MT7996_NPU) + .net_setup_tc = mt7996_net_setup_tc, #endif .change_vif_links = mt7996_change_vif_links, .change_sta_links = mt7996_mac_sta_change_links,
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 22/29 wifi: mt76: fix stuck TX queues after SER with no active interfaces
In reply to Felix FietkauFrom: Chad Monroe <[email protected]>
When a firmware watchdog triggers full SER recovery before any VAPs are up, mac80211 skips drv_reconfig_complete() because open_count is zero. This leaves the DRIVER queue stop reason set permanently, blocking all TX when interfaces eventually start.
--- drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 4 ++++ drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 2 ++ 2 files changed, 6 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +4 -0
@@ -1469,6 +1469,10 @@ mt7915_mac_full_reset(struct mt7915_dev *dev)mutex_unlock (&dev->mt76.mutex); +ieee80211_wake_queues (mt76_hw (dev)); +if (ext_phy) +ieee80211_wake_queues (ext_phy->hw); +ieee80211_restart_hw (mt76_hw (dev));if (ext_phy)ieee80211_restart_hw (ext_phy->hw);
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +2 -0
@@ -2512,6 +2512,8 @@ mt7996_mac_full_reset(struct mt7996_dev *dev)mutex_unlock (&dev->mt76.mutex); +ieee80211_wake_queues (mt76_hw (dev)); +ieee80211_restart_hw (mt76_hw (dev)); }
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 23/29 wifi: mt76: mt7615: fix NULL deref in mt7615_mac_set_rates
In reply to Felix Fietkaumt7615_tx() falls back to the vif BSS wcid when mac80211 hands a frame over without a station, e.g. while a station is being torn down, and to the global wcid when there is no vif either. Both tx_prepare_skb implementations derive a mt7615_sta from that wcid unconditionally and, if the rate control probe flag is set, pass it to mt7615_mac_set_rates(), which dereferences the NULL vif backpointer of the per-vif embedded sta:
Unable to handle kernel read from unreadable memory at virtual address 0000000000000002 ... pc : mt7615_mac_set_rates lr : mt7615_tx_prepare_skb
Neither entry is rate controlled by mac80211: the embedded sta has an empty rate set, and for the global wcid the container_of does not yield a valid mt7615_sta at all. Only resolve the sta for wcids that belong to a station.
--- drivers/net/wireless/mediatek/mt76/mt7615/pci_mac.c | 5 +++-- drivers/net/wireless/mediatek/mt76/mt7615/usb_sdio.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/pci_mac.c +3 -2
@@ -68,10 +68,11 @@ int mt7615_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,int pid, id;u8 *txwi = (u8 *)txwi_ptr;struct mt76_txwi_cache *t; -struct mt7615_sta *msta; +struct mt7615_sta *msta =NULL ;void *txp; - msta = wcid ? container_of(wcid, struct mt7615_sta, wcid) : NULL; +if (wcid && wcid->sta) + msta = container_of(wcid, struct mt7615_sta, wcid);if (!wcid) wcid = &dev->mt76.global_wcid;
drivers/net/wireless/mediatek/mt76/mt7615/usb_sdio.c +3 -2
@@ -187,10 +187,11 @@ int mt7663_usb_sdio_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,struct sk_buff *skb = tx_info->skb;struct ieee80211_tx_info *info =IEEE80211_SKB_CB (skb);struct ieee80211_key_conf *key = info->control.hw_key; -struct mt7615_sta *msta; +struct mt7615_sta *msta =NULL ;int pad, err, pktid; - msta = wcid ? container_of(wcid, struct mt7615_sta, wcid) : NULL; +if (wcid && wcid->sta) + msta = container_of(wcid, struct mt7615_sta, wcid);if (!wcid) wcid = &dev->mt76.global_wcid;
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 24/29 mt76: mt7915: trigger L1 SER on PLE MDP RIOC hang
In reply to Felix FietkauFrom: Chad Monroe <[email protected]>
WM firmware can enter a partial failure state where RX is hung.
Detect this condition by monitoring SER_PLE_ERR_1 for MDP_RIOC_HANG_ERR and trigger L1 SER to restore operation. Use transition detection on the error bit to fire only once per new occurrence, preventing an infinite SER loop when the bit remains set across checks.
--- drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 13 ++++++++++++- drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h | 1 + drivers/net/wireless/mediatek/mt76/mt7915/regs.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +12 -1
@@ -1934,7 +1934,7 @@ void mt7915_mac_update_stats(struct mt7915_phy *phy)static void mt7915_mac_severe_check (struct mt7915_phy *phy) {struct mt7915_dev *dev = phy->dev; -u32 trb; +u32 trb, ple_err;if (!phy->omac_mask)return ;
@@ -1954,6 +1954,17 @@ static void mt7915_mac_severe_check(struct mt7915_phy *phy) phy->mt76->band_idx); phy->trb_ts = trb; + + ple_err =mt76_rr (dev,MT_SWDEF_PLE1_STATS ); +if ((ple_err &MT_SWDEF_PLE1_MDP_RIOC_HANG_ERR ) && + !(dev->ple1_sts &MT_SWDEF_PLE1_MDP_RIOC_HANG_ERR )) { +dev_warn (dev->mt76.dev, +"band%d: PLE error 0x%x detected, triggering L1 SER\n" , + phy->mt76->band_idx, ple_err); +mt7915_mcu_set_ser (dev,SER_RECOVER ,SER_SET_RECOVER_L1 , + phy->mt76->band_idx); + } + dev->ple1_sts = ple_err; }void mt7915_mac_sta_rc_work (struct work_struct *work)
drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h +1 -0
@@ -296,6 +296,7 @@ struct mt7915_dev {spinlock_t reg_lock;u32 hw_pattern; +u32 ple1_sts;bool dbdc_support;bool flash_mode;
drivers/net/wireless/mediatek/mt76/mt7915/regs.h +1 -0
@@ -1044,6 +1044,7 @@ enum offs_rev {#define MT_SWDEF_SER_STATS MT_SWDEF(0x040)#define MT_SWDEF_PLE_STATS MT_SWDEF(0x044)#define MT_SWDEF_PLE1_STATS MT_SWDEF(0x048) +#define MT_SWDEF_PLE1_MDP_RIOC_HANG_ERR BIT(3)#define MT_SWDEF_PLE_AMSDU_STATS MT_SWDEF(0x04C)#define MT_SWDEF_PSE_STATS MT_SWDEF(0x050)#define MT_SWDEF_PSE1_STATS MT_SWDEF(0x054)
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 25/29 wifi: mt76: mt7996: free vif links after clearing wcid entries on full reset
In reply to Felix Fietkaumt7996_mac_reset_vif_iter() queues non-default vif links for kfree_rcu while dev->wcid[] still holds pointers to the wcid embedded in each freed link; mt76_reset_device() then dereferences those entries and runs mt76_wcid_cleanup() on them. If a grace period elapses in between, the cleanup operates on freed memory.
Run mt76_reset_device() first, so the wcid entries are cleaned up and cleared while the links are still valid.
--- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +1 -1
@@ -2485,10 +2485,10 @@ mt7996_mac_full_reset(struct mt7996_dev *dev) phy->omac_mask =0 ;ieee80211_iterate_stations_atomic (hw, mt7996_mac_reset_sta_iter, dev); +mt76_reset_device (&dev->mt76);ieee80211_iterate_active_interfaces_atomic (hw,IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER , mt7996_mac_reset_vif_iter, dev); -mt76_reset_device (&dev->mt76);INIT_LIST_HEAD (&dev->sta_rc_list);INIT_LIST_HEAD (&dev->twt_list);
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 26/29 wifi: mt76: mt7996: clear stale link state on full reset
In reply to Felix FietkauAfter a full chip reset, mac80211 reconfig replays interface, link and channel context setup. mt7996_vif_link_add() short-circuits when the link_id is still marked in mvif->valid_links, a state introduced for postponing link teardown to interface removal. The reset path frees the link structures without clearing those bits, so the replayed setup never re-creates dev_info/bss_info/STA records in the restarted firmware and never re-registers the link wcid, leaving the device inoperative.
The reset path also leaks every allocated MLD index: per-link indices and the per-vif group/remap indices are re-allocated from scratch during reconfig, but the old bits stay set in the masks, so repeated full resets exhaust the index space.
Clear valid_links in the reset vif iterator and reset the MLD index masks alongside the existing omac_mask clearing.
--- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +3 -0
@@ -2449,6 +2449,7 @@ mt7996_mac_reset_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)rcu_assign_pointer (mvif->link[i],NULL );kfree_rcu (mlink, rcu_head); } + mvif->valid_links =0 ;rcu_read_unlock (); }
@@ -2483,6 +2484,8 @@ mt7996_mac_full_reset(struct mt7996_dev *dev)mt7996_for_each_phy (dev, phy) phy->omac_mask =0 ; + dev->mld_idx_mask =0 ; + dev->mld_remap_idx_mask =0 ;ieee80211_iterate_stations_atomic (hw, mt7996_mac_reset_sta_iter, dev);mt76_reset_device (&dev->mt76);
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 27/29 wifi: mt76: set MT76_SCANNING when starting a hw scan
In reply to Felix FietkauThe scan state bit is cleared by mt76_scan_complete(), but nothing ever sets it: mt76_sw_scan() is only called for drivers without hw scan support. As a result, all MT76_SCANNING checks are inert for drivers using mt76_hw_scan(), including the DFS state handling in mt76_phy_dfs_state() and the guard against manually triggered radar detection while scanning.
Set the bit when the scan request is accepted. Since every channel programmed while scanning now evaluates the DFS state as disabled and stops the radar detector, re-program the operating channel at scan completion regardless of the off-channel state, after the scanning bit has been cleared. Otherwise a scan whose last visited channel was the operating channel, or one that returned to it early because of associated stations, would leave radar detection stopped until the next channel switch.
--- drivers/net/wireless/mediatek/mt76/scan.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/scan.c +10 -2
@@ -16,10 +16,17 @@ static void mt76_scan_complete(struct mt76_dev *dev, bool abort)clear_bit (MT76_SCANNING , &phy->state); -if (dev->scan.chan && phy->main_chandef.chan && phy->offchannel && +/* Re-program the operating channel even when the scan never left it: +* any channel set during the scan ran with MT76_SCANNING held, which +* left DFS radar detection disabled +*/ +if (phy->main_chandef.chan && !test_bit (MT76_MCU_RESET , &dev->phy.state)) { +bool offchannel = phy->offchannel; +mt76_set_channel (phy, &phy->main_chandef, false); -mt76_offchannel_notify (phy, false); +if (offchannel) +mt76_offchannel_notify (phy, false); }mt76_put_vif_phy_link (phy, dev->scan.vif, dev->scan.mlink);memset (&dev->scan,0 ,sizeof (dev->scan));
@@ -211,6 +218,7 @@ int mt76_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, dev->scan.vif = vif; dev->scan.phy = phy; dev->scan.mlink = mlink; +set_bit (MT76_SCANNING , &phy->state);ieee80211_queue_delayed_work (dev->phy.hw, &dev->scan_work,0 ); out:
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 28/29 wifi: mt76: serialize scan-link teardown with dev->mutex
In reply to Felix FietkauFrom: Chad Monroe <[email protected]>
The offchannel scan link is allocated in mt76_hw_scan() under dev->mutex, but torn down without it: mt76_scan_complete() runs from mt76_scan_work() on the mac80211 workqueue, or from mt76_abort_scan(), and calls mt76_put_vif_phy_link(), whose vif_link_remove clears the per-phy omac_mask and the device-wide vif_mask/mld_idx_mask with plain read-modify-write. A vif link add or remove for another interface, running concurrently under dev->mutex, can interleave with these unlocked writes and lose an update: a cleared bit belonging to a live link gets handed out again (two links sharing an omac/bss/wcid index, breaking own-MAC unicast RX for the first one), or a freed bit stays set until reboot and eventually exhausts the index space.
Take dev->mutex around the scan completion, mirroring the ROC teardown in mt76_roc_complete_work()/mt76_abort_roc(), and switch the channel restore to __mt76_set_channel() since the caller now holds the lock. mt76_abort_scan() keeps cancelling the scan work before taking the mutex, so the work-vs-abort ordering is unchanged.
--- drivers/net/wireless/mediatek/mt76/scan.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/scan.c +8 -1
@@ -11,6 +11,8 @@ static void mt76_scan_complete(struct mt76_dev *dev, bool abort) .aborted = abort, }; +lockdep_assert_held (&dev->mutex); +if (!phy)return ;
@@ -24,7 +26,7 @@ static void mt76_scan_complete(struct mt76_dev *dev, bool abort) !test_bit(MT76_MCU_RESET, &dev->phy.state)) {bool offchannel = phy->offchannel; -mt76_set_channel (phy, &phy->main_chandef, false); +__mt76_set_channel (phy, &phy->main_chandef, false);if (offchannel)mt76_offchannel_notify (phy, false); }
@@ -41,7 +43,10 @@ void mt76_abort_scan(struct mt76_dev *dev)spin_unlock_bh (&dev->scan_lock);cancel_delayed_work_sync (&dev->scan_work); + +mutex_lock (&dev->mutex);mt76_scan_complete (dev, true); +mutex_unlock (&dev->mutex); }EXPORT_SYMBOL_GPL (mt76_abort_scan);
@@ -139,7 +144,9 @@ void mt76_scan_work(struct work_struct *work) goto probe;if (dev->scan.chan_idx >= req->n_channels) { +mutex_lock (&dev->mutex);mt76_scan_complete (dev, false); +mutex_unlock (&dev->mutex);return ; }
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 29/29 wifi: mt76: mt7996: hold dev->mutex in remove_interface teardown
In reply to Felix FietkauFrom: Chad Monroe <[email protected]>
mt7996_remove_interface() destroys the remaining vif links, clearing omac_mask, vif_mask and mld_idx_mask, with only the wiphy mutex held. Those masks are modified under dev->mutex everywhere else, so the unlocked clears can race the scan-link teardown and the reset work and lose updates.
Take dev->mutex around the link destroy loop, matching mt7996_add_interface() and mt7915_remove_interface(). The mutex is released before mt76_vif_cleanup(), which aborts a pending scan and takes the mutex itself.
--- drivers/net/wireless/mediatek/mt76/mt7996/main.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +4 -0
@@ -606,6 +606,8 @@ static void mt7996_remove_interface(struct ieee80211_hw *hw,unsigned int link_id;int i; +mutex_lock (&dev->mt76.mutex); +/* Remove all active links */ for_each_set_bit (link_id, &rem_links,IEEE80211_MLD_MAX_NUM_LINKS ) {struct mt7996_vif_link *link;
@@ -622,6 +624,8 @@ static void mt7996_remove_interface(struct ieee80211_hw *hw,mt7996_vif_link_destroy (phy, link, vif,NULL ); } +mutex_unlock (&dev->mt76.mutex); +ieee80211_iterate_active_interfaces_mtx (hw,0 , mt7996_remove_iter, &rdata);mt76_vif_cleanup (&dev->mt76, vif);
Signature · 1 line
2.53.0