Skip to contentSkip to conversation

wifi: mt76: mt7925: free the vif links when all links go

PATCH In review Felix Fietkau 2 participants 22 messages Nov 20 – Nov 21

Subsystems (2)
lore
Share & tools
lore

Felix Fietkau

author maintainer
#0 lore raw

PATCH 1/20 wifi: mt76: mt7925: free the vif links when all links go

mac80211 clears vif->valid_links before it calls drv_change_vif_links() to remove all links of an interface. For an interface without valid links, mt792x_vif_to_link() and mt792x_sta_to_link() return the embedded default link, so mt7925_change_vif_links() takes every removed link for the default link. The other links thus leak at each disassociation of an MLO station that has an active link other than the default link.

Look the removed links up in the link arrays of the driver, which do not depend on vif->valid_links.

Fixes 69acd6d910b0 ("wifi: mt76: mt7925: add mt7925_change_vif_links")
---
 drivers/net/wireless/mediatek/mt76/mt7925/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +2 -2
index d7b359930b3c..d892434de54c 100644
@@ -2496,8 +2496,8 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	mt792x_mutex_acquire(dev);
 
 	for_each_set_bit(link_id, &rem, IEEE80211_MLD_MAX_NUM_LINKS) {
-		mconf = mt792x_vif_to_link(mvif, link_id);
-		mlink = mt792x_sta_to_link(&mvif->sta, link_id);
+		mconf = mt76_dereference(mvif->link_conf[link_id], &dev->mt76);
+		mlink = mt76_dereference(mvif->sta.link[link_id], &dev->mt76);
 
 		if (!mconf || !mlink)
 			continue;
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 2/20 wifi: mt76: mt7925: free removed vif links after an RCU grace period

mt7925_change_vif_links() frees the mconf and mlink of a removed link with devm_kfree() before it clears mvif->link_conf[] and mvif->sta.link[], and without a grace period. Readers such as mt7925_mcu_bss_absence_iter() hold RCU alone, so a change of the active links can cause a use after free. The error path of a link add frees the same way, and leaves dev->mt76.wcid[] naming the freed mlink.

Free the links with kfree_rcu() after every pointer to them is cleared, as mt7996_vif_link_free() does. On the error path, also remove the BSS of each link whose add completed, and make mt7925_mac_link_bss_add() undo its setup of an allocated link when the firmware command fails. The embedded link keeps its state until mt7925_remove_interface() releases it.

Fixes 69acd6d910b0 ("wifi: mt76: mt7925: add mt7925_change_vif_links")
Fixes ac03e5b82bc6 ("wifi: mt76: mt7925: Enhance mt7925_mac_link_bss_add to support MLO")
---
 .../net/wireless/mediatek/mt76/mt7925/main.c  | 70 ++++++++++++-------
 1 file changed, 45 insertions(+), 25 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +45 -25
index d892434de54c..1fac66e8c50a 100644
@@ -449,6 +449,12 @@ static int mt7925_mac_link_bss_add(struct mt792x_dev *dev,
 	ret = mt76_connac_mcu_uni_add_dev(&dev->mphy, link_conf, &mconf->mt76,
 					  &mlink->wcid, true);
 	if (ret) {
+		if (mconf != &mvif->bss_conf) {
+			rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
+			mt76_wcid_cleanup(&dev->mt76, &mlink->wcid);
+			dev->mt76.vif_mask &= ~BIT_ULL(mconf->mt76.idx);
+			mvif->phy->omac_mask &= ~BIT_ULL(mconf->mt76.omac_idx);
+		}
 		mt7925_p2p_bmc_remove(dev, mconf);
 		goto out;
 	}
@@ -2474,6 +2480,25 @@ static void mt7925_link_info_changed(struct ieee80211_hw *hw,
 	mt792x_mutex_release(dev);
 }
 
+static void
+mt7925_vif_link_remove(struct mt792x_dev *dev, struct mt792x_vif *mvif,
+		       unsigned int link_id, struct mt792x_bss_conf *mconf,
+		       struct mt792x_link_sta *mlink, bool bss_remove)
+{
+	rcu_assign_pointer(mvif->link_conf[link_id], NULL);
+	rcu_assign_pointer(mvif->sta.link[link_id], NULL);
+
+	if (bss_remove)
+		mt792x_mac_link_bss_remove(dev, mconf, mlink);
+
+	if (mconf != &mvif->bss_conf) {
+		mt7925_p2p_bmc_remove(dev, mconf);
+		kfree_rcu(mconf, mt76.rcu_head);
+	}
+	if (mlink != &mvif->sta.deflink)
+		kfree_rcu(mlink, rcu_head);
+}
+
 static int
 mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 			u16 old_links, u16 new_links,
@@ -2487,6 +2512,7 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
 	struct mt792x_phy *phy = mt792x_hw_phy(hw);
 	struct ieee80211_bss_conf *link_conf;
+	unsigned long added = 0;
 	unsigned int link_id;
 	int err;
 
@@ -2502,15 +2528,8 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 		if (!mconf || !mlink)
 			continue;
 
-		if (mconf != &mvif->bss_conf) {
-			mt792x_mac_link_bss_remove(dev, mconf, mlink);
-			mt7925_p2p_bmc_remove(dev, mconf);
-			devm_kfree(dev->mt76.dev, mconf);
-			devm_kfree(dev->mt76.dev, mlink);
-		}
-
-		rcu_assign_pointer(mvif->link_conf[link_id], NULL);
-		rcu_assign_pointer(mvif->sta.link[link_id], NULL);
+		mt7925_vif_link_remove(dev, mvif, link_id, mconf, mlink,
+				       mconf != &mvif->bss_conf);
 	}
 
 	for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) {
@@ -2519,13 +2538,13 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 			mconf = &mvif->bss_conf;
 			mlink = &mvif->sta.deflink;
 		} else {
-			mconf = devm_kzalloc(dev->mt76.dev, sizeof(*mconf),
-					     GFP_KERNEL);
-			mlink = devm_kzalloc(dev->mt76.dev, sizeof(*mlink),
-					     GFP_KERNEL);
+			mconf = kzalloc_obj(*mconf);
+			mlink = kzalloc_obj(*mlink);
 			if (!mconf || !mlink) {
-				mt792x_mutex_release(dev);
-				return -ENOMEM;
+				kfree(mconf);
+				kfree(mlink);
+				err = -ENOMEM;
+				goto free_unpublished;
 			}
 		}
 
@@ -2554,6 +2573,8 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 		if (err < 0)
 			goto free;
 
+		added |= BIT(link_id);
+
 		if (mconf != &mvif->bss_conf) {
 			err = mt7925_set_mlo_roc(phy, &mvif->bss_conf,
 						 vif->active_links);
@@ -2581,18 +2602,17 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	return 0;
 
 free:
+	for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS)
+		mt7925_vif_link_remove(dev, mvif, link_id, mconfs[link_id],
+				       mlinks[link_id], added & BIT(link_id));
+	goto out;
+
+free_unpublished:
 	for_each_set_bit(link_id, &add, IEEE80211_MLD_MAX_NUM_LINKS) {
-		rcu_assign_pointer(mvif->link_conf[link_id], NULL);
-		rcu_assign_pointer(mvif->sta.link[link_id], NULL);
-
-		if (mconfs[link_id] != &mvif->bss_conf) {
-			mt7925_p2p_bmc_remove(dev, mconfs[link_id]);
-			devm_kfree(dev->mt76.dev, mconfs[link_id]);
-		}
-		if (mlinks[link_id] != &mvif->sta.deflink)
-			devm_kfree(dev->mt76.dev, mlinks[link_id]);
+		kfree(mconfs[link_id]);
+		kfree(mlinks[link_id]);
 	}
-
+out:
 	mt792x_mutex_release(dev);
 
 	return err;
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH 3/20 wifi: mt76: remove a replayed station from the driver before the add

In reply to Felix Fietkau

A write to the mac80211 debugfs file "reset" leaves the stations of every interface other than a managed one in place. ieee80211_reconfig() then adds them again on their old drv_priv, and the sta_add of most drivers allocates a new WLAN index for them. The old index leaks, and its dev->wcid[] entry still points at the station after the station is freed.

Treat the replay of a station that the driver still holds as a removal followed by a fresh add. The driver holds a station whose sta flag is set or whose wcid is published, since a new station has a zeroed drv_priv. Unpublish the wcid for an RCU grace period first, as for a station that mac80211 destroys. The station keeps its count, since mac80211 removes it through the driver later, also if the add fails. mt76x0 and mt76x2 opt out, since their sta_add restores a replayed station.

Fixes c8846e101502 ("mt76: add driver for MT7603E and MT7628/7688")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 58 ++++++++++++++-----
 drivers/net/wireless/mediatek/mt76/mt76.h     |  1 +
 .../net/wireless/mediatek/mt76/mt76x0/pci.c   |  3 +-
 .../net/wireless/mediatek/mt76/mt76x0/usb.c   |  3 +-
 .../net/wireless/mediatek/mt76/mt76x2/pci.c   |  3 +-
 .../net/wireless/mediatek/mt76/mt76x2/usb.c   |  3 +-
 6 files changed, 52 insertions(+), 19 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +43 -15
index 2957f5694dc2..b8a568e0ae27 100644
@@ -1713,6 +1713,42 @@ void mt76_rx_poll_complete(struct mt76_dev *dev, enum mt76_rxq_id q,
 }
 EXPORT_SYMBOL_GPL(mt76_rx_poll_complete);
 
+static void
+mt76_sta_teardown(struct mt76_phy *phy, struct ieee80211_vif *vif,
+		  struct ieee80211_sta *sta)
+{
+	struct mt76_dev *dev = phy->dev;
+	struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
+	int i, idx = wcid->idx;
+
+	for (i = 0; i < ARRAY_SIZE(wcid->aggr); i++)
+		mt76_rx_aggr_stop(dev, wcid, i);
+
+	if (dev->drv->sta_remove)
+		dev->drv->sta_remove(dev, vif, sta);
+
+	mt76_wcid_cleanup(dev, wcid);
+
+	mt76_wcid_mask_clear(dev->wcid_mask, idx);
+}
+
+static void
+mt76_sta_replay_drop(struct mt76_phy *phy, struct ieee80211_vif *vif,
+		     struct ieee80211_sta *sta)
+{
+	struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
+	struct mt76_dev *dev = phy->dev;
+
+	spin_lock_bh(&dev->status_lock);
+	if (rcu_access_pointer(dev->wcid[wcid->idx]) == wcid)
+		rcu_assign_pointer(dev->wcid[wcid->idx], NULL);
+	spin_unlock_bh(&dev->status_lock);
+	synchronize_net();
+
+	mt76_sta_teardown(phy, vif, sta);
+	wcid->sta = 0;
+}
+
 static int
 mt76_sta_add(struct mt76_phy *phy, struct ieee80211_vif *vif,
 	     struct ieee80211_sta *sta)
@@ -1726,8 +1762,12 @@ mt76_sta_add(struct mt76_phy *phy, struct ieee80211_vif *vif,
 
 	mutex_lock(&dev->mutex);
 
-	/* drv_priv of a new station is zeroed, so only a replay has it set */
-	registered = wcid->sta;
+	published = rcu_dereference_protected(dev->wcid[wcid->idx],
+					      lockdep_is_held(&dev->mutex));
+	registered = wcid->sta || published == wcid;
+	if (registered && !(dev->drv->drv_flags & MT_DRV_KEEP_REPLAYED_STA))
+		mt76_sta_replay_drop(phy, vif, sta);
+
 	ret = dev->drv->sta_add(dev, vif, sta);
 	if (ret)
 		goto out;
@@ -1765,19 +1805,7 @@ mt76_sta_add(struct mt76_phy *phy, struct ieee80211_vif *vif,
 void __mt76_sta_remove(struct mt76_phy *phy, struct ieee80211_vif *vif,
 		       struct ieee80211_sta *sta)
 {
-	struct mt76_dev *dev = phy->dev;
-	struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
-	int i, idx = wcid->idx;
-
-	for (i = 0; i < ARRAY_SIZE(wcid->aggr); i++)
-		mt76_rx_aggr_stop(dev, wcid, i);
-
-	if (dev->drv->sta_remove)
-		dev->drv->sta_remove(dev, vif, sta);
-
-	mt76_wcid_cleanup(dev, wcid);
-
-	mt76_wcid_mask_clear(dev->wcid_mask, idx);
+	mt76_sta_teardown(phy, vif, sta);
 	phy->num_sta--;
 }
 EXPORT_SYMBOL_GPL(__mt76_sta_remove);
drivers/net/wireless/mediatek/mt76/mt76.h +1 -0
index 548632fe884a..ddada6834170 100644
@@ -541,6 +541,7 @@ struct mt76_hw_cap {
 #define MT_DRV_AMSDU_OFFLOAD		BIT(5)
 #define MT_DRV_IGNORE_TXS_FAILED	BIT(6)
 #define MT_DRV_HW_PS_BUFFERING		BIT(7)
+#define MT_DRV_KEEP_REPLAYED_STA	BIT(8)
 
 struct mt76_driver_ops {
 	u32 drv_flags;
drivers/net/wireless/mediatek/mt76/mt76x0/pci.c +2 -1
index 3c4948522c5b..49ff52fe2ccb 100644
@@ -158,7 +158,8 @@ mt76x0e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		.txwi_size = sizeof(struct mt76x02_txwi),
 		.drv_flags = MT_DRV_TX_ALIGNED4_SKBS |
 			     MT_DRV_SW_RX_AIRTIME |
-			     MT_DRV_IGNORE_TXS_FAILED,
+			     MT_DRV_IGNORE_TXS_FAILED |
+			     MT_DRV_KEEP_REPLAYED_STA,
 		.survey_flags = SURVEY_INFO_TIME_TX,
 		.update_survey = mt76x02_update_channel,
 		.set_channel = mt76x0_set_channel,
drivers/net/wireless/mediatek/mt76/mt76x0/usb.c +2 -1
index 2acce121fb14..f51a7e0d147f 100644
@@ -215,7 +215,8 @@ static int mt76x0u_probe(struct usb_interface *usb_intf,
 {
 	static const struct mt76_driver_ops drv_ops = {
 		.drv_flags = MT_DRV_SW_RX_AIRTIME |
-			     MT_DRV_IGNORE_TXS_FAILED,
+			     MT_DRV_IGNORE_TXS_FAILED |
+			     MT_DRV_KEEP_REPLAYED_STA,
 		.survey_flags = SURVEY_INFO_TIME_TX,
 		.update_survey = mt76x02_update_channel,
 		.set_channel = mt76x0_set_channel,
drivers/net/wireless/mediatek/mt76/mt76x2/pci.c +2 -1
index 491a32921a06..6df9f5110b7b 100644
@@ -23,7 +23,8 @@ mt76x2e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		.txwi_size = sizeof(struct mt76x02_txwi),
 		.drv_flags = MT_DRV_TX_ALIGNED4_SKBS |
 			     MT_DRV_SW_RX_AIRTIME |
-			     MT_DRV_IGNORE_TXS_FAILED,
+			     MT_DRV_IGNORE_TXS_FAILED |
+			     MT_DRV_KEEP_REPLAYED_STA,
 		.survey_flags = SURVEY_INFO_TIME_TX,
 		.update_survey = mt76x02_update_channel,
 		.set_channel = mt76x2e_set_channel,
drivers/net/wireless/mediatek/mt76/mt76x2/usb.c +2 -1
index ade15bddefc5..23b4e020c5b7 100644
@@ -34,7 +34,8 @@ static int mt76x2u_probe(struct usb_interface *intf,
 {
 	static const struct mt76_driver_ops drv_ops = {
 		.drv_flags = MT_DRV_SW_RX_AIRTIME |
-			     MT_DRV_IGNORE_TXS_FAILED,
+			     MT_DRV_IGNORE_TXS_FAILED |
+			     MT_DRV_KEEP_REPLAYED_STA,
 		.survey_flags = SURVEY_INFO_TIME_TX,
 		.update_survey = mt76x02_update_channel,
 		.set_channel = mt76x2u_set_channel,
Signature · 1 line
2.47.3
author maintainer
#3 lore raw

PATCH 4/20 wifi: mt76: mt7925: run the reset link replay under the wiphy lock

In reply to Felix Fietkau

mt7925_mac_reset_work() replays the links of each interface without the wiphy lock or dev->mt76.mutex, so a link can go while mt7925_vif_connect_iter() still uses it. For a station, the replay itself queues the disconnect that removes the links. The check that commit bd8b2ec83818 ("wifi: mt76: mt7925: fix crash in reset link replay") added only skips a link that is gone before the replay, so a use after free remains.

Run the replay as a wiphy work, with the mutex held. Every link change runs under the wiphy lock, so the links stay valid until the replay ends. The reset work cannot take the wiphy lock itself, since mt792x_stop() waits for it under that lock.

Fixes 14061994184d ("wifi: mt76: mt7925: add link handling in mt7925_vif_connect_iter")
---
 .../net/wireless/mediatek/mt76/mt7925/init.c  |  1 +
 .../net/wireless/mediatek/mt76/mt7925/mac.c   | 20 +++++++++++++++----
 .../net/wireless/mediatek/mt76/mt7925/main.c  |  1 +
 .../wireless/mediatek/mt76/mt7925/mt7925.h    |  1 +
 .../net/wireless/mediatek/mt76/mt7925/pci.c   |  1 +
 .../net/wireless/mediatek/mt76/mt7925/usb.c   |  1 +
 drivers/net/wireless/mediatek/mt76/mt792x.h   | 10 ++++++++++
 .../net/wireless/mediatek/mt76/mt792x_usb.c   |  2 ++
 8 files changed, 33 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/init.c +1 -0
index 5c81574e5283..ad51f71babd7 100644
@@ -320,6 +320,7 @@ int mt7925_register_device(struct mt792x_dev *dev)
 	skb_queue_head_init(&dev->coredump.msg_list);
 
 	INIT_WORK(&dev->reset_work, mt7925_mac_reset_work);
+	wiphy_work_init(&dev->reset_vif_work, mt7925_mac_reset_vif_work);
 	INIT_WORK(&dev->init_work, mt7925_init_work);
 	INIT_WORK(&dev->nan_deferred_work, mt7925_nan_deferred_work);
 	spin_lock_init(&dev->nan_deferred_lock);
drivers/net/wireless/mediatek/mt76/mt7925/mac.c +16 -4
index c342559a133b..30deb675c5ff 100644
@@ -1640,10 +1640,22 @@ void mt7925_mac_reset_work(struct work_struct *work)
 		return;
 
 	ieee80211_wake_queues(hw);
-	ieee80211_iterate_active_interfaces(hw,
-					    IEEE80211_IFACE_ITER_RESUME_ALL,
-					    mt7925_vif_connect_iter, NULL);
-	mt76_connac_power_save_sched(&dev->mt76.phy, pm);
+	wiphy_work_queue(hw->wiphy, &dev->reset_vif_work);
+}
+
+void mt7925_mac_reset_vif_work(struct wiphy *wiphy, struct wiphy_work *work)
+{
+	struct mt792x_dev *dev = container_of(work, struct mt792x_dev,
+					      reset_vif_work);
+
+	if (test_bit(MT76_REMOVED, &dev->mphy.state))
+		return;
+
+	mt792x_mutex_acquire(dev);
+	ieee80211_iterate_active_interfaces_mtx(mt76_hw(dev),
+						IEEE80211_IFACE_ITER_RESUME_ALL,
+						mt7925_vif_connect_iter, NULL);
+	mt792x_mutex_release(dev);
 
 	mt7925_regd_change(&dev->phy, "00");
 }
drivers/net/wireless/mediatek/mt76/mt7925/main.c +1 -0
index 1fac66e8c50a..61dc02e8aa68 100644
@@ -3063,6 +3063,7 @@ static void mt7925_stop(struct ieee80211_hw *hw, bool suspend)
 	cancel_delayed_work_sync(&dev->mlo_pm_work);
 
 	mt792x_stop(hw, suspend);
+	wiphy_work_cancel(hw->wiphy, &dev->reset_vif_work);
 }
 
 const struct ieee80211_ops mt7925_ops = {
drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h +1 -0
index 1710d97c5d25..228b74721ed7 100644
@@ -333,6 +333,7 @@ int mt7925_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 void mt7925_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 			   struct ieee80211_sta *sta);
 void mt7925_mac_reset_work(struct work_struct *work);
+void mt7925_mac_reset_vif_work(struct wiphy *wiphy, struct wiphy_work *work);
 int mt7925e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
 			   enum mt76_txq_id qid, struct mt76_wcid *wcid,
 			   struct ieee80211_sta *sta,
drivers/net/wireless/mediatek/mt76/mt7925/pci.c +1 -0
index 736457aa10bb..a7877c408736 100644
@@ -120,6 +120,7 @@ static void mt7925e_unregister_device(struct mt792x_dev *dev)
 	mt76_unregister_device(&dev->mt76);
 	set_bit(MT76_REMOVED, &dev->mphy.state);
 	cancel_work_sync(&dev->reset_work);
+	mt792x_reset_vif_work_cancel(dev);
 	mt76_for_each_q_rx(&dev->mt76, i)
 		napi_disable(&dev->mt76.napi[i]);
 	cancel_delayed_work_sync(&pm->ps_work);
drivers/net/wireless/mediatek/mt76/mt7925/usb.c +1 -0
index f97f787b2198..ee5306c29427 100644
@@ -154,6 +154,7 @@ static void mt7925u_stop(struct ieee80211_hw *hw, bool suspend)
 	cancel_delayed_work_sync(&dev->mlo_pm_work);
 
 	mt792xu_stop(hw, suspend);
+	wiphy_work_cancel(hw->wiphy, &dev->reset_vif_work);
 }
 
 static int mt7925u_probe(struct usb_interface *usb_intf,
drivers/net/wireless/mediatek/mt76/mt792x.h +10 -0
index c2d6ebb2ca3a..8dfe10cbb6d1 100644
@@ -374,6 +374,7 @@ struct mt792x_dev {
 	struct mt792x_phy phy;
 
 	struct work_struct reset_work;
+	struct wiphy_work reset_vif_work;
 	bool hw_full_reset:1;
 	bool hw_init_done:1;
 	bool fw_assert:1;
@@ -526,6 +527,15 @@ mt792x_hw_phy(struct ieee80211_hw *hw)
 	return phy->priv;
 }
 
+static inline void mt792x_reset_vif_work_cancel(struct mt792x_dev *dev)
+{
+	struct wiphy *wiphy = mt76_hw(dev)->wiphy;
+
+	wiphy_lock(wiphy);
+	wiphy_work_cancel(wiphy, &dev->reset_vif_work);
+	wiphy_unlock(wiphy);
+}
+
 static inline void
 mt792x_get_status_freq_info(struct mt76_rx_status *status, u8 chfreq)
 {
drivers/net/wireless/mediatek/mt76/mt792x_usb.c +2 -0
index feedb66d4b6e..d5a6fe33d09c 100644
@@ -524,6 +524,8 @@ void mt792xu_disconnect(struct usb_interface *usb_intf)
 	wake_up(&dev->mt76.mcu.wait);
 	skb_queue_purge(&dev->mt76.mcu.res_q);
 	cancel_work_sync(&dev->reset_work);
+	if (!is_connac2(&dev->mt76))
+		mt792x_reset_vif_work_cancel(dev);
 	mt792xu_cleanup(dev);
 	set_bit(MT76_REMOVED, &dev->mphy.state);
 
Signature · 1 line
2.47.3
author maintainer
#4 lore raw

PATCH 5/20 wifi: mt76: mt7925: take the mutex before the link_info_changed lookup

In reply to Felix Fietkau

mt7925_link_info_changed() looks up the driver link before it takes dev->mt76.mutex, which mt792x_vif_to_link() requires. The first link info change of an MLD interface thus triggers a suspicious RCU usage warning. The link stays valid, as its only writer, mt7925_change_vif_links(), runs under the wiphy lock that this op holds.

Look up the link under the mutex, like commit beec58f36983 ("wifi: mt76:
mt7925: resolve link after acquiring mt76 mutex") did for the station links, and like mt7996_link_info_changed() does.

Fixes 3fa01f055c41 ("wifi: mt76: mt7925: update rate index according to link id")
---
 drivers/net/wireless/mediatek/mt76/mt7925/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +2 -2
index 61dc02e8aa68..71e441f631d1 100644
@@ -2432,10 +2432,10 @@ static void mt7925_link_info_changed(struct ieee80211_hw *hw,
 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
 	struct mt792x_bss_conf *mconf;
 
-	mconf = mt792x_vif_to_link(mvif, info->link_id);
-
 	mt792x_mutex_acquire(dev);
 
+	mconf = mt792x_vif_to_link(mvif, info->link_id);
+
 	if (changed & BSS_CHANGED_ERP_SLOT) {
 		int slottime = info->use_short_slot ? 9 : 20;
 
Signature · 1 line
2.47.3
author maintainer
#5 lore raw

PATCH 6/20 wifi: mt76: mt7925: hold the mutex for the link lookup in conf_tx

In reply to Felix Fietkau

mt7925_conf_tx() looks up the driver link and writes its queue parameters without dev->mt76.mutex, which mt792x_vif_to_link() requires. The first queue setup of an MLD interface thus triggers a suspicious RCU usage warning. The link stays valid, as its only writer, mt7925_change_vif_links(), runs under the wiphy lock that this op holds.

Hold the mutex for the lookup and the write, like mt7603_conf_tx(). The op only writes driver memory, so it takes the mutex without a chip wakeup, like mt792x_assign_vif_chanctx().

Fixes 882b97c16ab8 ("wifi: mt76: mt7925: set Tx queue parameters according to link id")
---
 drivers/net/wireless/mediatek/mt76/mt7925/main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +5 -1
index 71e441f631d1..644591b994ec 100644
@@ -2149,16 +2149,20 @@ mt7925_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	       const struct ieee80211_tx_queue_params *params)
 {
 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
-	struct mt792x_bss_conf *mconf = mt792x_vif_to_link(mvif, link_id);
+	struct mt792x_dev *dev = mt792x_hw_dev(hw);
 	static const u8 mq_to_aci[] = {
 		    [IEEE80211_AC_VO] = 3,
 		    [IEEE80211_AC_VI] = 2,
 		    [IEEE80211_AC_BE] = 0,
 		    [IEEE80211_AC_BK] = 1,
 	};
+	struct mt792x_bss_conf *mconf;
 
+	mutex_lock(&dev->mt76.mutex);
+	mconf = mt792x_vif_to_link(mvif, link_id);
 	/* firmware uses access class index */
 	mconf->queue_params[mq_to_aci[queue]] = *params;
+	mutex_unlock(&dev->mt76.mutex);
 
 	return 0;
 }
Signature · 1 line
2.47.3
author maintainer
#6 lore raw

PATCH 7/20 wifi: mt76: mt7925: skip a polled link without a station

In reply to Felix Fietkau

Since the WCID teardown moved into mt7925_mac_link_sta_remove(), mt7925_mac_sta_remove_links() clears mlink->sta of a removed link while the link is still on sta_poll_list. On PCIe, mt7925_mac_sta_poll() runs from the TX free event without dev->mt76.mutex. It can thus take such a link off the list and dereference the NULL station.

Skip a polled link without a station.

Fixes 52f088a2e6bf ("wifi: mt76: mt7925: move WCID teardown into link_sta_remove()")
---
 drivers/net/wireless/mediatek/mt76/mt7925/mac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7925/mac.c +1 -1
index 30deb675c5ff..ca54d71db4c7 100644
@@ -90,7 +90,7 @@ static void mt7925_mac_sta_poll(struct mt792x_dev *dev)
 			memset(mlink->airtime_ac, 0, sizeof(mlink->airtime_ac));
 		}
 
-		if (!mlink->wcid.sta)
+		if (!msta || !mlink->wcid.sta)
 			continue;
 
 		sta = container_of((void *)msta, struct ieee80211_sta,
Signature · 1 line
2.47.3
author maintainer
#7 lore raw

PATCH 8/20 wifi: mt76: mt7925: skip a link without a link conf in the MLO PS update

In reply to Felix Fietkau

During a link removal, mvif->valid_links still holds the link after mac80211 cleared its link conf, until mt7925_change_vif_links() runs. mt7925_mlo_pm_work() runs without the wiphy lock, so mt7925_mlo_pm_iter() can pass the NULL link conf of such a link to mt7925_mcu_uni_bss_ps(), which dereferences it. Reachable through the power save update that mt7925_link_info_changed() schedules after a PS change of an MLO station.

Skip a link without a link conf, as mt7925_vif_connect_iter() does. A link conf that the iterator finds under dev->mt76.mutex stays valid, since mac80211 frees it only after mt7925_change_vif_links(), which takes the mutex.

While here, read the PS state and the links under the mutex that their writers hold.

Fixes 276a56883257 ("wifi: mt76: mt7925: update the power-saving flow")
---
 drivers/net/wireless/mediatek/mt76/mt7925/main.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +10 -5
index 644591b994ec..188e3ad06c37 100644
@@ -1736,19 +1736,24 @@ mt7925_mlo_pm_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
 {
 	struct mt792x_dev *dev = priv;
 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
-	unsigned long valid = ieee80211_vif_is_mld(vif) ?
-				    mvif->valid_links : BIT(0);
 	struct ieee80211_bss_conf *bss_conf;
+	unsigned long valid;
 	int i;
 
-	if (mvif->mlo_pm_state != MT792x_MLO_CHANGED_PS)
-		return;
-
 	mt792x_mutex_acquire(dev);
+
+	if (mvif->mlo_pm_state != MT792x_MLO_CHANGED_PS)
+		goto out;
+
+	valid = ieee80211_vif_is_mld(vif) ? mvif->valid_links : BIT(0);
 	for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) {
 		bss_conf = mt792x_vif_to_bss_conf(vif, i);
+		if (!bss_conf)
+			continue;
+
 		mt7925_mcu_uni_bss_ps(dev, bss_conf);
 	}
+out:
 	mt792x_mutex_release(dev);
 }
 
Signature · 1 line
2.47.3
author maintainer
#8 lore raw

PATCH 9/20 wifi: mt76: mt7925: restore the beacon filter when monitor mode ends

In reply to Felix Fietkau

mt7925_sniffer_interface_iter() turns the beacon filter of each running interface off when monitor mode starts, but not on again when it ends. An associated station then keeps the filter off while IEEE80211_VIF_BEACON_FILTER stays set, so mac80211 leaves beacon loss detection to the device.

When monitor mode ends, turn the filter of each associated station back on, unless runtime PM is off and a runtime PM write turned the filter off. Stations that are not associated stay off, since the firmware expects the filter only after the association.

Fixes c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")
---
 .../net/wireless/mediatek/mt76/mt7925/main.c  | 41 ++++++++++++-------
 1 file changed, 27 insertions(+), 14 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +27 -14
index 188e3ad06c37..d3b1f5e7850b 100644
@@ -916,29 +916,36 @@ static int mt7925_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 }
 
 static void
-mt7925_pm_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
+mt7925_vif_set_beacon_filter(struct mt792x_dev *dev, struct ieee80211_vif *vif,
+			     bool enable)
 {
-	struct mt792x_dev *dev = priv;
 	struct ieee80211_hw *hw = mt76_hw(dev);
-	bool pm_enable;
-	int err;
 
-	mt792x_mutex_acquire(dev);
+	if (mt7925_mcu_set_beacon_filter(dev, vif, enable) < 0)
+		return;
 
-	pm_enable = dev->pm.enable_user &&
-		    !(hw->conf.flags & IEEE80211_CONF_MONITOR);
-	err = mt7925_mcu_set_beacon_filter(dev, vif, pm_enable);
-	if (err < 0)
-		goto out;
-
-	if (pm_enable) {
+	if (enable) {
 		vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
 		ieee80211_hw_set(hw, CONNECTION_MONITOR);
 	} else {
 		vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER;
 		__clear_bit(IEEE80211_HW_CONNECTION_MONITOR, hw->flags);
 	}
-out:
+}
+
+static void
+mt7925_pm_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
+{
+	struct mt792x_dev *dev = priv;
+	struct ieee80211_hw *hw = mt76_hw(dev);
+	bool pm_enable;
+
+	mt792x_mutex_acquire(dev);
+
+	pm_enable = dev->pm.enable_user &&
+		    !(hw->conf.flags & IEEE80211_CONF_MONITOR);
+	mt7925_vif_set_beacon_filter(dev, vif, pm_enable);
+
 	mt792x_mutex_release(dev);
 }
 
@@ -956,8 +963,14 @@ mt7925_sniffer_interface_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
 
 	mt7925_mcu_set_deep_sleep(dev, pm->ds_enable);
 
-	if (monitor)
+	if (monitor) {
 		mt7925_mcu_set_beacon_filter(dev, vif, false);
+		return;
+	}
+
+	if (vif->cfg.assoc &&
+	    (pm->enable || (vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)))
+		mt7925_vif_set_beacon_filter(dev, vif, true);
 }
 
 void mt7925_set_runtime_pm(struct mt792x_dev *dev)
Signature · 1 line
2.47.3
author maintainer
#9 lore raw

PATCH 10/20 wifi: mt76: usb: do not park the TX worker again under MT76_RESET

In reply to Felix Fietkau

When the wait for pending TX in mt76u_stop_tx() times out, its cleanup parks the TX worker also where the caller parked it already. This is the case for mt792xu_disconnect(), which reaches mt76u_stop_tx() through mt76_unregister_device(), and for mt7921u_mac_reset() and mt7925u_mac_reset(). The second park triggers a WARN, and the cleanup then unparks the worker, which runs again during the teardown or the chip reset:

mt7925u 2-4:1.0: timed out waiting for pending tx

  WARNING: CPU: 1 PID: 15805 at kthread_park+0x73/0x90
  Call Trace:
   ...
   mt792xu_stop+0x15/0x30 [mt792x_usb]
   ...
   drv_stop+0x33/0xd0 [mac80211]
   ...
   ieee80211_unregister_hw+0x45/0x140 [mac80211]
   mt76_unregister_device+0x70/0xf0 [mt76]
   mt792xu_disconnect+0x7a/0x1c0 [mt792x_usb]
   ...

Park and unpark the worker in the cleanup only while MT76_RESET is clear, as mt792x_flush() does. Every caller that holds MT76_RESET has parked the worker already, or runs before mt76_register_device() starts it.

Fixes 7910bd565d8b ("wifi: mt76: mt792x: quiesce USB paths on disconnect")
Fixes 0d2afe09fad5 ("mt76: mt7921: add mt7921u driver")
Fixes c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")
---
 drivers/net/wireless/mediatek/mt76/usb.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/usb.c +6 -2
index be48a88a3ad0..9a701840d23a 100644
@@ -1070,6 +1070,7 @@ void mt76u_stop_tx(struct mt76_dev *dev)
 	if (!ret) {
 		struct mt76_queue_entry entry;
 		struct mt76_queue *q;
+		bool park;
 		int i, j;
 
 		dev_err(dev->dev, "timed out waiting for pending tx\n");
@@ -1083,7 +1084,9 @@ void mt76u_stop_tx(struct mt76_dev *dev)
 				usb_kill_urb(q->entry[j].urb);
 		}
 
-		mt76_worker_disable(&dev->tx_worker);
+		park = !test_bit(MT76_RESET, &dev->phy.state);
+		if (park)
+			mt76_worker_disable(&dev->tx_worker);
 
 		/* On device removal we maight queue skb's, but mt76u_tx_kick()
 		 * will fail to submit urb, cleanup those skb's manually.
@@ -1100,7 +1103,8 @@ void mt76u_stop_tx(struct mt76_dev *dev)
 			}
 		}
 
-		mt76_worker_enable(&dev->tx_worker);
+		if (park)
+			mt76_worker_enable(&dev->tx_worker);
 	}
 
 	cancel_work_sync(&dev->usb.stat_work);
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 10/20
#10 lore raw

Re: [PATCH mt76-next 10/20] wifi: mt76: usb: do not park the TX worker again under MT76_RESET

Quoted 26 lines

When the wait for pending TX in mt76u_stop_tx() times out, its cleanup parks the TX worker also where the caller parked it already. This is the case for mt792xu_disconnect(), which reaches mt76u_stop_tx() through mt76_unregister_device(), and for mt7921u_mac_reset() and mt7925u_mac_reset(). The second park triggers a WARN, and the cleanup then unparks the worker, which runs again during the teardown or the chip reset:

mt7925u 2-4:1.0: timed out waiting for pending tx

  WARNING: CPU: 1 PID: 15805 at kthread_park+0x73/0x90
  Call Trace:
   ...
   mt792xu_stop+0x15/0x30 [mt792x_usb]
   ...
   drv_stop+0x33/0xd0 [mac80211]
   ...
   ieee80211_unregister_hw+0x45/0x140 [mac80211]
   mt76_unregister_device+0x70/0xf0 [mt76]
   mt792xu_disconnect+0x7a/0x1c0 [mt792x_usb]
   ...

Park and unpark the worker in the cleanup only while MT76_RESET is clear, as mt792x_flush() does. Every caller that holds MT76_RESET has parked the worker already, or runs before mt76_register_device() starts it.

Quoted 4 lines
Fixes 7910bd565d8b ("wifi: mt76: mt792x: quiesce USB paths on disconnect")
Fixes 0d2afe09fad5 ("mt76: mt7921: add mt7921u driver")
Fixes c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")
Quoted 41 lines
---
 drivers/net/wireless/mediatek/mt76/usb.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/usb.c +6 -2
index be48a88a3ad0..9a701840d23a 100644
@@ -1070,6 +1070,7 @@ void mt76u_stop_tx(struct mt76_dev *dev)
 	if (!ret) {
 		struct mt76_queue_entry entry;
 		struct mt76_queue *q;
+		bool park;
 		int i, j;
 
 		dev_err(dev->dev, "timed out waiting for pending tx\n");
@@ -1083,7 +1084,9 @@ void mt76u_stop_tx(struct mt76_dev *dev)
 				usb_kill_urb(q->entry[j].urb);
 		}
 
-		mt76_worker_disable(&dev->tx_worker);
+		park = !test_bit(MT76_RESET, &dev->phy.state);
+		if (park)
+			mt76_worker_disable(&dev->tx_worker);
 
 		/* On device removal we maight queue skb's, but mt76u_tx_kick()
 		 * will fail to submit urb, cleanup those skb's manually.
@@ -1100,7 +1103,8 @@ void mt76u_stop_tx(struct mt76_dev *dev)
 			}
 		}
 
-		mt76_worker_enable(&dev->tx_worker);
+		if (park)
+			mt76_worker_enable(&dev->tx_worker);
 	}
 
 	cancel_work_sync(&dev->usb.stat_work);
Signature · 1 line
2.47.3
author maintainer
#11 lore raw

PATCH 11/20 wifi: mt76: mt7925: keep the default link in the active links

In reply to Felix Fietkau

Since commit 43aa4033eb18 ("wifi: mt76: mt7925: add mt7925_change_sta_links"), the driver removes the default link of an associated AP MLD, the association link, when mac80211 deactivates it. No other link takes its place, so the interface sends no data on the links that stay active. Reachable via an advertised TID-to-link mapping or an ML reconfiguration of the AP MLD.

Refuse an active link set without the default link while an MLD interface is associated. A move of the default link does not help, because the firmware sends the uplink of an MLD only on its association link. Where an advertised mapping or an ML reconfiguration of the AP MLD leaves that link out, mac80211 now disconnects instead.

Fixes 43aa4033eb18 ("wifi: mt76: mt7925: add mt7925_change_sta_links")
---
 drivers/net/wireless/mediatek/mt76/mt7925/main.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +13 -0
index d3b1f5e7850b..f8ad3bd16931 100644
@@ -2715,6 +2715,18 @@ mt7925_change_sta_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	return err;
 }
 
+static bool
+mt7925_can_activate_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+			  u16 active_links)
+{
+	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
+
+	if (!ieee80211_vif_is_mld(vif) || !vif->cfg.assoc)
+		return true;
+
+	return active_links & BIT(mvif->deflink_id);
+}
+
 static int
 mt7927_reconfig_band(struct mt792x_dev *dev, struct ieee80211_vif *vif,
 		     struct ieee80211_bss_conf *link_conf,
@@ -3148,6 +3160,7 @@ const struct ieee80211_ops mt7925_ops = {
 	.mgd_complete_tx = mt7925_mgd_complete_tx,
 	.vif_cfg_changed = mt7925_vif_cfg_changed,
 	.link_info_changed = mt7925_link_info_changed,
+	.can_activate_links = mt7925_can_activate_links,
 	.change_vif_links = mt7925_change_vif_links,
 	.change_sta_links = mt7925_change_sta_links,
 	.rfkill_poll = mt7925_rfkill_poll,
Signature · 1 line
2.47.3
author maintainer
#12 lore raw

PATCH 12/20 wifi: mt76: mt7925: read the monitor state under the mutex for deep sleep

In reply to Felix Fietkau

mt7925_deep_sleep_set() reads IEEE80211_CONF_MONITOR before it takes the mutex. The value can thus miss a monitor change that mt7925_config() applied under the mutex, and deep sleep can then go on while a monitor runs. Reachable via the deep-sleep file in debugfs.

Read the flag under the mutex, as mt7925_set_runtime_pm() does.

Fixes c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")
---
 drivers/net/wireless/mediatek/mt76/mt7925/debugfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7925/debugfs.c +2 -1
index d0677a24e080..6cfd3c4cac8c 100644
@@ -231,8 +231,8 @@ mt7925_deep_sleep_set(void *data, u64 val)
 {
 	struct mt792x_dev *dev = data;
 	struct mt76_connac_pm *pm = &dev->pm;
-	bool monitor = !!(dev->mphy.hw->conf.flags & IEEE80211_CONF_MONITOR);
 	bool enable = !!val;
+	bool monitor;
 
 	if (mt76_is_usb(&dev->mt76))
 		return -EOPNOTSUPP;
@@ -241,6 +241,7 @@ mt7925_deep_sleep_set(void *data, u64 val)
 	if (pm->ds_enable_user == enable)
 		goto out;
 
+	monitor = !!(dev->mphy.hw->conf.flags & IEEE80211_CONF_MONITOR);
 	pm->ds_enable_user = enable;
 	pm->ds_enable = enable && !monitor;
 	mt7925_mcu_set_deep_sleep(dev, pm->ds_enable);
Signature · 1 line
2.47.3
author maintainer
#13 lore raw

PATCH 13/20 wifi: mt76: clear roc_link before the ROC link is freed

In reply to Felix Fietkau

mt76_roc_complete() queues the free of the off-channel link while phy->roc_link still names it. An RCU reader that loads roc_link after that point can use the link after it is freed.

Clear roc_link before the free is queued, as the error path of mt76_remain_on_channel() does.

This is currently not reachable: the only lockless reader of roc_link, mt7996_tx(), finds the phy through mvif->roc_phy, which mt76_roc_complete() clears before the free. Found by inspection.

---
 drivers/net/wireless/mediatek/mt76/channel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/channel.c +2 -2
index 9638f65a679e..db2d6dfc12a9 100644
@@ -409,9 +409,9 @@ void mt76_roc_complete(struct mt76_phy *phy)
 	} else {
 		phy->offchannel = false;
 	}
-	mt76_put_vif_phy_link(phy, phy->roc_vif, phy->roc_link);
-	phy->roc_vif = NULL;
 	phy->roc_link = NULL;
+	mt76_put_vif_phy_link(phy, phy->roc_vif, mlink);
+	phy->roc_vif = NULL;
 	if (!test_bit(MT76_RESTART, &dev->phy.state))
 		ieee80211_remain_on_channel_expired(phy->hw);
 }
Signature · 1 line
2.47.3
author maintainer
#14 lore raw

PATCH 14/20 wifi: mt76: mt792x: handle all interfaces of a channel context

In reply to Felix Fietkau

Since commit f3898da2e86e ("wifi: mt76: mt792x: add struct mt792x_chanctx"), a channel context records only the link that was assigned to it last. Removing any link clears the record, but a switch of the recorded link to another context leaves it in place. A bandwidth change of a context that a station and an AP share thus reaches the firmware for at most one of them. After such a switch and the removal of that link, the next change of the old context is a use after free.

Walk the active interfaces when a channel context changes, as the driver did before that commit.

Fixes f3898da2e86e ("wifi: mt76: mt792x: add struct mt792x_chanctx")
---
 .../net/wireless/mediatek/mt76/mt7921/main.c  | 28 +++----
 .../net/wireless/mediatek/mt76/mt7925/main.c  | 83 +++++++++----------
 drivers/net/wireless/mediatek/mt76/mt792x.h   |  4 -
 .../net/wireless/mediatek/mt76/mt792x_core.c  |  5 --
 4 files changed, 53 insertions(+), 67 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7921/main.c +14 -14
index 6207a875996c..a89b4c7f2239 100644
@@ -1413,25 +1413,25 @@ mt7921_change_chanctx(struct ieee80211_hw *hw,
 		      struct ieee80211_chanctx_conf *ctx,
 		      u32 changed)
 {
-	struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv;
 	struct mt792x_phy *phy = mt792x_hw_phy(hw);
 	struct ieee80211_vif *vif;
-	struct mt792x_vif *mvif;
-
-	if (!mctx->bss_conf)
-		return;
-
-	mvif = container_of(mctx->bss_conf, struct mt792x_vif, bss_conf);
-	vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv);
 
 	mt792x_mutex_acquire(phy->dev);
-	if (vif->type == NL80211_IFTYPE_MONITOR) {
-		mt7921_mcu_set_sniffer(mvif->phy->dev, vif, true);
-		mt7921_mcu_config_sniffer(mvif, ctx);
-	} else {
-		mt76_connac_mcu_uni_set_chctx(mvif->phy->mt76, &mvif->bss_conf.mt76, ctx);
+	for_each_active_interface(vif, hw) {
+		struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
+
+		if (mvif->bss_conf.mt76.ctx != ctx)
+			continue;
+
+		if (vif->type == NL80211_IFTYPE_MONITOR) {
+			mt7921_mcu_set_sniffer(mvif->phy->dev, vif, true);
+			mt7921_mcu_config_sniffer(mvif, ctx);
+		} else {
+			mt76_connac_mcu_uni_set_chctx(mvif->phy->mt76,
+						      &mvif->bss_conf.mt76, ctx);
+		}
+		mt76_phy_chandef_set(mvif->phy->mt76, &ctx->def);
 	}
-	mt76_phy_chandef_set(mvif->phy->mt76, &ctx->def);
 	mt792x_mutex_release(phy->dev);
 }
 
drivers/net/wireless/mediatek/mt76/mt7925/main.c +39 -44

125 lines not on this page · raw message

drivers/net/wireless/mediatek/mt76/mt792x.h +0 -4
index 8dfe10cbb6d1..e37d901575e5 100644
@@ -163,10 +163,6 @@ struct mt792x_sta {
 
 DECLARE_EWMA(rssi, 10, 8);
 
-struct mt792x_chanctx {
-	struct mt792x_bss_conf *bss_conf;
-};
-
 struct mt792x_bss_conf {
 	struct mt76_vif_link mt76; /* must be first */
 	struct mt792x_vif *vif;
drivers/net/wireless/mediatek/mt76/mt792x_core.c +0 -5
index 2d39f18f4d43..5743c5437863 100644
@@ -503,13 +503,11 @@ int mt792x_assign_vif_chanctx(struct ieee80211_hw *hw,
 			      struct ieee80211_bss_conf *link_conf,
 			      struct ieee80211_chanctx_conf *ctx)
 {
-	struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv;
 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
 
 	mutex_lock(&dev->mt76.mutex);
 	mvif->bss_conf.mt76.ctx = ctx;
-	mctx->bss_conf = &mvif->bss_conf;
 	mt76_phy_chandef_set(&dev->mphy, &ctx->def);
 	mutex_unlock(&dev->mt76.mutex);
 
@@ -522,12 +520,10 @@ void mt792x_unassign_vif_chanctx(struct ieee80211_hw *hw,
 				 struct ieee80211_bss_conf *link_conf,
 				 struct ieee80211_chanctx_conf *ctx)
 {
-	struct mt792x_chanctx *mctx = (struct mt792x_chanctx *)ctx->drv_priv;
 	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
 
 	mutex_lock(&dev->mt76.mutex);
-	mctx->bss_conf = NULL;
 	mvif->bss_conf.mt76.ctx = NULL;
 	mutex_unlock(&dev->mt76.mutex);
 
@@ -810,7 +806,6 @@ int mt792x_init_wiphy(struct ieee80211_hw *hw)
 
 	hw->sta_data_size = sizeof(struct mt792x_sta);
 	hw->vif_data_size = sizeof(struct mt792x_vif);
-	hw->chanctx_data_size = sizeof(struct mt792x_chanctx);
 
 	if (dev->fw_features & MT792x_FW_CAP_CNM)
 		wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Signature · 1 line
2.47.3
author maintainer
#15 lore raw

PATCH 15/20 wifi: mt76: mt792x: set up the sniffer when a monitor gets its channel

In reply to Felix Fietkau

mt7921 and mt7925 tune the sniffer of a monitor only in change_chanctx. For the new channel context of a monitor, mac80211 calls change_chanctx only on a device with more than one RX chain. On a device with one RX chain, the sniffer thus stays off the channel of the monitor.

Set up the sniffer when the channel context is assigned.

Fixes 41ac53c899bd ("wifi: mt76: mt7921: introduce chanctx support")
Fixes c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")
---
 .../net/wireless/mediatek/mt76/mt7921/main.c  | 25 +++++++++++++++++--
 .../net/wireless/mediatek/mt76/mt7925/main.c  |  8 ++++--
 2 files changed, 29 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7921/main.c +23 -2
index a89b4c7f2239..9b13e9c25cf3 100644
@@ -1469,12 +1469,33 @@ static void mt7921_mgd_complete_tx(struct ieee80211_hw *hw,
 	mt7921_abort_roc(mvif->phy, mvif);
 }
 
+static int mt7921_assign_vif_chanctx(struct ieee80211_hw *hw,
+				     struct ieee80211_vif *vif,
+				     struct ieee80211_bss_conf *link_conf,
+				     struct ieee80211_chanctx_conf *ctx)
+{
+	struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
+	struct mt792x_dev *dev = mt792x_hw_dev(hw);
+	int ret;
+
+	ret = mt792x_assign_vif_chanctx(hw, vif, link_conf, ctx);
+	if (ret || vif->type != NL80211_IFTYPE_MONITOR)
+		return ret;
+
+	mt792x_mutex_acquire(dev);
+	mt7921_mcu_set_sniffer(dev, vif, true);
+	mt7921_mcu_config_sniffer(mvif, ctx);
+	mt792x_mutex_release(dev);
+
+	return 0;
+}
+
 static int mt7921_switch_vif_chanctx(struct ieee80211_hw *hw,
 				     struct ieee80211_vif_chanctx_switch *vifs,
 				     int n_vifs,
 				     enum ieee80211_chanctx_switch_mode mode)
 {
-	return mt792x_assign_vif_chanctx(hw, vifs->vif, vifs->link_conf,
+	return mt7921_assign_vif_chanctx(hw, vifs->vif, vifs->link_conf,
 					 vifs->new_ctx);
 }
 
@@ -1620,7 +1641,7 @@ const struct ieee80211_ops mt7921_ops = {
 	.add_chanctx = mt7921_add_chanctx,
 	.remove_chanctx = mt7921_remove_chanctx,
 	.change_chanctx = mt7921_change_chanctx,
-	.assign_vif_chanctx = mt792x_assign_vif_chanctx,
+	.assign_vif_chanctx = mt7921_assign_vif_chanctx,
 	.unassign_vif_chanctx = mt792x_unassign_vif_chanctx,
 	.mgd_prepare_tx = mt7921_mgd_prepare_tx,
 	.mgd_complete_tx = mt7921_mgd_complete_tx,
drivers/net/wireless/mediatek/mt76/mt7925/main.c +6 -2
index bd5375705e98..8c9c77bd97b6 100644
@@ -2760,7 +2760,7 @@ static int mt7925_assign_vif_chanctx(struct ieee80211_hw *hw,
 	struct mt792x_bss_conf *mconf;
 	u8 band_idx;
 
-	mutex_lock(&dev->mt76.mutex);
+	mt792x_mutex_acquire(dev);
 
 	if (ieee80211_vif_is_mld(vif)) {
 		mconf = mt792x_vif_to_link(mvif, link_conf->link_id);
@@ -2782,7 +2782,11 @@ static int mt7925_assign_vif_chanctx(struct ieee80211_hw *hw,
 
 	mconf->mt76.ctx = ctx;
 	mt76_phy_chandef_set(mvif->phy->mt76, &ctx->def);
-	mutex_unlock(&dev->mt76.mutex);
+	if (vif->type == NL80211_IFTYPE_MONITOR) {
+		mt7925_mcu_set_sniffer(dev, vif, true);
+		mt7925_mcu_config_sniffer(mvif, ctx);
+	}
+	mt792x_mutex_release(dev);
 
 	return 0;
 }
Signature · 1 line
2.47.3
author maintainer
#16 lore raw

PATCH 16/20 wifi: mt76: buffer Disassociation frames for stations in power save

In reply to Felix Fietkau

Since commit 3999d15cfcc7 ("wifi: mt76: fix queue assignment for disassoc packets"), a Disassociation frame to an associated station goes to the ALTX queue. The hardware sends ALTX frames at once, also to a station in power save. A sleeping station thus misses the frame and stays associated until it detects the disconnection by itself.

Send Disassociation frames on the AC queue like other bufferable MMPDUs, so that they wait until the station wakes. If the station does not wake, hostapd removes it when the wait for the TX status ends. Keep Deauthentication frames on the ALTX queue, so that hostapd removes a deauthenticated station at once.

Fixes 3999d15cfcc7 ("wifi: mt76: fix queue assignment for disassoc packets")
---
 drivers/net/wireless/mediatek/mt76/tx.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/wireless/mediatek/mt76/tx.c +0 -1
index 72d1021a940f..d8036466f495 100644
@@ -729,7 +729,6 @@ mt76_txq_schedule_pending_wcid(struct mt76_phy *phy, struct mt76_wcid *wcid,
 		    (!(wcid->tx_info & MT_WCID_TX_INFO_SET) ||
 		     !ieee80211_is_bufferable_mmpdu(skb) ||
 		     ieee80211_is_deauth(hdr->frame_control) ||
-		     ieee80211_is_disassoc(hdr->frame_control) ||
 		     head == &wcid->tx_offchannel))
 			qid = MT_TXQ_PSD;
 
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 16/20
#17 lore raw

Re: [PATCH mt76-next 16/20] wifi: mt76: buffer Disassociation frames for stations in power save

Quoted 6 lines

Since commit 3999d15cfcc7 ("wifi: mt76: fix queue assignment for disassoc packets"), a Disassociation frame to an associated station goes to the ALTX queue. The hardware sends ALTX frames at once, also to a station in power save. A sleeping station thus misses the frame and stays associated until it detects the disconnection by itself.

Quoted 8 lines

Send Disassociation frames on the AC queue like other bufferable MMPDUs, so that they wait until the station wakes. If the station does not wake, hostapd removes it when the wait for the TX status ends. Keep Deauthentication frames on the ALTX queue, so that hostapd removes a deauthenticated station at once.

Fixes 3999d15cfcc7 ("wifi: mt76: fix queue assignment for disassoc packets")
Quoted 20 lines
---
 drivers/net/wireless/mediatek/mt76/tx.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/wireless/mediatek/mt76/tx.c +0 -1
index 72d1021a940f..d8036466f495 100644
@@ -729,7 +729,6 @@ mt76_txq_schedule_pending_wcid(struct mt76_phy *phy, struct mt76_wcid *wcid,
 		    (!(wcid->tx_info & MT_WCID_TX_INFO_SET) ||
 		     !ieee80211_is_bufferable_mmpdu(skb) ||
 		     ieee80211_is_deauth(hdr->frame_control) ||
-		     ieee80211_is_disassoc(hdr->frame_control) ||
 		     head == &wcid->tx_offchannel))
 			qid = MT_TXQ_PSD;
 
Signature · 1 line
2.47.3
author maintainer
#18 lore raw

PATCH 17/20 wifi: mt76: mt7921: read the monitor state under the mutex for deep sleep

In reply to Felix Fietkau

mt7921_deep_sleep_set() reads IEEE80211_CONF_MONITOR before it takes the mutex. The value can thus miss a monitor change that mt7921_config() applied under the mutex, and deep sleep can then go on while a monitor runs. Reachable via the deep-sleep file in debugfs.

Read the flag under the mutex, as mt7925_deep_sleep_set() does.

Fixes 4ad65a54617c ("mt76: mt7921: toggle runtime-pm adding a monitor vif")
---
 drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c +2 -1
index 62bf33347e9e..14c70ffa9665 100644
@@ -189,8 +189,8 @@ mt7921_deep_sleep_set(void *data, u64 val)
 {
 	struct mt792x_dev *dev = data;
 	struct mt76_connac_pm *pm = &dev->pm;
-	bool monitor = !!(dev->mphy.hw->conf.flags & IEEE80211_CONF_MONITOR);
 	bool enable = !!val;
+	bool monitor;
 
 	if (mt76_is_usb(&dev->mt76))
 		return -EOPNOTSUPP;
@@ -199,6 +199,7 @@ mt7921_deep_sleep_set(void *data, u64 val)
 	if (pm->ds_enable_user == enable)
 		goto out;
 
+	monitor = !!(dev->mphy.hw->conf.flags & IEEE80211_CONF_MONITOR);
 	pm->ds_enable_user = enable;
 	pm->ds_enable = enable && !monitor;
 	mt76_connac_mcu_set_deep_sleep(&dev->mt76, pm->ds_enable);
Signature · 1 line
2.47.3
author maintainer
#19 lore raw

PATCH 18/20 wifi: mt76: mt7925: wake the device to unassign a channel context

In reply to Felix Fietkau

mt7925_unassign_vif_chanctx() takes the mutex with a plain mutex_lock() and sends mt7925_mcu_add_bss_info() for the default link of an MLD station without waking the device. With runtime PM on, the BSS removal can thus reach a device in power save. Reachable whenever mac80211 releases the channel context of the default link of an MLD station, for example at a disconnect.

Take the mutex with mt792x_mutex_acquire(), as
mt7925_assign_vif_chanctx() does.

Fixes 621e9e22b8d0 ("wifi: mt76: mt7925: add mt7925_[assign,unassign]_vif_chanctx")
---
 drivers/net/wireless/mediatek/mt76/mt7925/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +2 -2
index 8c9c77bd97b6..fa5628c06b04 100644
@@ -2800,7 +2800,7 @@ static void mt7925_unassign_vif_chanctx(struct ieee80211_hw *hw,
 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
 	struct mt792x_bss_conf *mconf;
 
-	mutex_lock(&dev->mt76.mutex);
+	mt792x_mutex_acquire(dev);
 
 	if (ieee80211_vif_is_mld(vif)) {
 		mconf = mt792x_vif_to_link(mvif, link_conf->link_id);
@@ -2814,7 +2814,7 @@ static void mt7925_unassign_vif_chanctx(struct ieee80211_hw *hw,
 	}
 
 	mconf->mt76.ctx = NULL;
-	mutex_unlock(&dev->mt76.mutex);
+	mt792x_mutex_release(dev);
 
 	if (link_conf->csa_active) {
 		timer_delete_sync(&mvif->csa_timer);
Signature · 1 line
2.47.3
author maintainer
#20 lore raw

PATCH 19/20 wifi: mt76: mt7996: keep the firmware log settings across a reload

In reply to Felix Fietkau

mt7996_mcu_init_firmware() turns the WM and WA firmware log off after each firmware load, while dev->fw_debug_wm, dev->fw_debug_wa and dev->fw_debug_bin keep the debugfs settings. Since the full system reset loads the firmware again, a reset silently stops firmware logging, and the debugfs files still report it as enabled.

Send the stored settings at each firmware load, and, where WM or WA logging is enabled, the other commands that the debugfs write sends. With logging off a load sends the same commands as before, so probe is unchanged.

Fixes 27015b6fbcca ("wifi: mt76: mt7996: enable full system reset support")
---
 .../wireless/mediatek/mt76/mt7996/debugfs.c   | 47 +-------------
 .../net/wireless/mediatek/mt76/mt7996/mcu.c   | 61 ++++++++++++++++++-
 .../wireless/mediatek/mt76/mt7996/mt7996.h    |  1 +
 3 files changed, 62 insertions(+), 47 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c +2 -45
index 8f1ef19c3876..2ca594618f3b 100644
@@ -306,47 +306,10 @@ static int
 mt7996_fw_debug_wm_set(void *data, u64 val)
 {
 	struct mt7996_dev *dev = data;
-	enum {
-		DEBUG_TXCMD = 62,
-		DEBUG_CMD_RPT_TX,
-		DEBUG_CMD_RPT_TRIG,
-		DEBUG_SPL,
-		DEBUG_RPT_RX,
-		DEBUG_RPT_RA = 68,
-	} debug;
-	bool tx, rx, en;
-	int ret;
 
 	dev->fw_debug_wm = val ? MCU_FW_LOG_TO_HOST : 0;
 
-	if (dev->fw_debug_bin)
-		val = MCU_FW_LOG_RELAY;
-	else
-		val = dev->fw_debug_wm;
-
-	tx = dev->fw_debug_wm || (dev->fw_debug_bin & BIT(1));
-	rx = dev->fw_debug_wm || (dev->fw_debug_bin & BIT(2));
-	en = dev->fw_debug_wm || (dev->fw_debug_bin & BIT(0));
-
-	ret = mt7996_mcu_fw_log_2_host(dev, MCU_FW_LOG_WM, val);
-	if (ret)
-		return ret;
-
-	for (debug = DEBUG_TXCMD; debug <= DEBUG_RPT_RA; debug++) {
-		if (debug == 67)
-			continue;
-
-		if (debug == DEBUG_RPT_RX)
-			val = en && rx;
-		else
-			val = en && tx;
-
-		ret = mt7996_mcu_fw_dbg_ctrl(dev, debug, val);
-		if (ret)
-			return ret;
-	}
-
-	return 0;
+	return mt7996_mcu_fw_debug_set(dev, MCU_FW_LOG_WM, false);
 }
 
 static int
@@ -366,16 +329,10 @@ static int
 mt7996_fw_debug_wa_set(void *data, u64 val)
 {
 	struct mt7996_dev *dev = data;
-	int ret;
 
 	dev->fw_debug_wa = val ? MCU_FW_LOG_TO_HOST : 0;
 
-	ret = mt7996_mcu_fw_log_2_host(dev, MCU_FW_LOG_WA, dev->fw_debug_wa);
-	if (ret)
-		return ret;
-
-	return mt7996_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET), MCU_WA_PARAM_PDMA_RX,
-				 !!dev->fw_debug_wa, 0);
+	return mt7996_mcu_fw_debug_set(dev, MCU_FW_LOG_WA, false);
 }
 
 static int
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +59 -2

77 lines not on this page · raw message

drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +1 -0
index 24048a5ede31..c50fd3c15728 100644
@@ -835,6 +835,7 @@ int mt7996_mcu_set_rro(struct mt7996_dev *dev, u16 tag, u16 val);
 int mt7996_mcu_wa_cmd(struct mt7996_dev *dev, int cmd, u32 a1, u32 a2, u32 a3);
 int mt7996_mcu_fw_log_2_host(struct mt7996_dev *dev, u8 type, u8 ctrl);
 int mt7996_mcu_fw_dbg_ctrl(struct mt7996_dev *dev, u32 module, u8 level);
+int mt7996_mcu_fw_debug_set(struct mt7996_dev *dev, u8 type, bool load);
 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);
Signature · 1 line
2.47.3
author maintainer
#21 lore raw

PATCH 20/20 wifi: mt76: mt7915: keep the firmware log settings across a reload

In reply to Felix Fietkau

mt7915_mcu_init_firmware() turns the WM and WA firmware log off after each firmware load, while dev->fw.debug_wm, dev->fw.debug_wa and dev->fw.debug_bin keep the debugfs settings. Since the full system reset loads the firmware again, a reset silently stops firmware logging, and the debugfs files still report it as enabled.

Send the stored settings at each firmware load, and, where WM or WA logging is enabled, the other commands and register writes that the debugfs write sends. With logging off a load sends the same commands as before, so probe is unchanged.

Fixes 8a55712d124f ("wifi: mt76: mt7915: enable full system reset support")
---
 .../wireless/mediatek/mt76/mt7915/debugfs.c   | 49 +--------------
 .../net/wireless/mediatek/mt76/mt7915/mcu.c   | 63 ++++++++++++++++++-
 .../wireless/mediatek/mt76/mt7915/mt7915.h    |  1 +
 3 files changed, 64 insertions(+), 49 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c +2 -47
index a4e95073001d..f69457b0154f 100644
@@ -495,50 +495,11 @@ static int
 mt7915_fw_debug_wm_set(void *data, u64 val)
 {
 	struct mt7915_dev *dev = data;
-	enum {
-		DEBUG_TXCMD = 62,
-		DEBUG_CMD_RPT_TX,
-		DEBUG_CMD_RPT_TRIG,
-		DEBUG_SPL,
-		DEBUG_RPT_RX,
-	} debug;
-	bool tx, rx, en;
 	int ret;
 
 	dev->fw.debug_wm = val ? MCU_FW_LOG_TO_HOST : 0;
 
-	if (dev->fw.debug_bin)
-		val = 16;
-	else
-		val = dev->fw.debug_wm;
-
-	tx = dev->fw.debug_wm || (dev->fw.debug_bin & BIT(1));
-	rx = dev->fw.debug_wm || (dev->fw.debug_bin & BIT(2));
-	en = dev->fw.debug_wm || (dev->fw.debug_bin & BIT(0));
-
-	ret = mt7915_mcu_fw_log_2_host(dev, MCU_FW_LOG_WM, val);
-	if (ret)
-		goto out;
-
-	for (debug = DEBUG_TXCMD; debug <= DEBUG_RPT_RX; debug++) {
-		if (debug == DEBUG_RPT_RX)
-			val = en && rx;
-		else
-			val = en && tx;
-
-		ret = mt7915_mcu_fw_dbg_ctrl(dev, debug, val);
-		if (ret)
-			goto out;
-	}
-
-	/* WM CPU info record control */
-	mt76_clear(dev, MT_CPU_UTIL_CTRL, BIT(0));
-	mt76_wr(dev, MT_DIC_CMD_REG_CMD, BIT(2) | BIT(13) |
-		(dev->fw.debug_wm ? 0 : BIT(0)));
-	mt76_wr(dev, MT_MCU_WM_CIRQ_IRQ_MASK_CLR_ADDR, BIT(5));
-	mt76_wr(dev, MT_MCU_WM_CIRQ_IRQ_SOFT_ADDR, BIT(5));
-
-out:
+	ret = mt7915_mcu_fw_debug_set(dev, MCU_FW_LOG_WM, false);
 	if (ret)
 		dev->fw.debug_wm = 0;
 
@@ -566,13 +527,7 @@ mt7915_fw_debug_wa_set(void *data, u64 val)
 
 	dev->fw.debug_wa = val ? MCU_FW_LOG_TO_HOST : 0;
 
-	ret = mt7915_mcu_fw_log_2_host(dev, MCU_FW_LOG_WA, dev->fw.debug_wa);
-	if (ret)
-		goto out;
-
-	ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
-				MCU_WA_PARAM_PDMA_RX, !!dev->fw.debug_wa, 0);
-out:
+	ret = mt7915_mcu_fw_debug_set(dev, MCU_FW_LOG_WA, false);
 	if (ret)
 		dev->fw.debug_wa = 0;
 
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +61 -2

78 lines not on this page · raw message

drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h +1 -0
index 1a0aeed5073e..afb856febe3a 100644
@@ -551,6 +551,7 @@ int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set)
 int mt7915_mcu_wa_cmd(struct mt7915_dev *dev, int cmd, u32 a1, u32 a2, u32 a3);
 int mt7915_mcu_fw_log_2_host(struct mt7915_dev *dev, u8 type, u8 ctrl);
 int mt7915_mcu_fw_dbg_ctrl(struct mt7915_dev *dev, u32 module, u8 level);
+int mt7915_mcu_fw_debug_set(struct mt7915_dev *dev, u8 type, bool load);
 void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb);
 void mt7915_mcu_exit(struct mt7915_dev *dev);
 
Signature · 1 line
2.47.3