Skip to contentSkip to conversation

wifi: mt76: mt7996: limit the SKU TX power to the current channel

PATCH New Felix Fietkau 1 participant 16 messages Nov 18

Subsystems (2)
lore
Share & tools
lore

Felix Fietkau

author maintainer
#0 lore raw

PATCH 1/16 wifi: mt76: mt7996: limit the SKU TX power to the current channel

Since the switch to a single multi-radio wiphy, mt7996_mcu_set_txpower_sku() takes the TX power from phy->txpower instead of hw->conf.power_level. phy->txpower stays 0 until a BSS sets its TX power, so a scan or an offchannel operation before that gets the SKU limits of 0 dBm.

Take the maximum power of the current channel, limited by the TX power of the BSS once a BSS sets it. Mark a phy without a BSS TX power with INT_MIN, as mac80211 does for bss_conf.txpower, since 0 dBm is a valid TX power of a BSS.

Fixes 69d54ce7491d ("wifi: mt76: mt7996: switch to single multi-radio wiphy")
---
 drivers/net/wireless/mediatek/mt76/mt7996/init.c | 1 +
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c  | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/init.c +1 -0
index f44a3a8588d3..655023578b3e 100644
@@ -423,6 +423,7 @@ mt7996_init_wiphy_band(struct ieee80211_hw *hw, struct mt7996_phy *phy)
 
 	phy->slottime = 9;
 	phy->beacon_rate = -1;
+	phy->txpower = INT_MIN;
 	phy->rxfilter = MT_WF_RFCR_DROP_OTHER_UC;
 
 	if (phy->mt76->cap.has_2ghz) {
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +4 -1
index b082998a4170..57b16f1f5c1d 100644
@@ -5779,7 +5779,10 @@ int mt7996_mcu_set_txpower_sku(struct mt7996_phy *phy)
 	struct sk_buff *skb;
 	int i, tx_power;
 
-	tx_power = mt76_get_power_bound(mphy, phy->txpower);
+	tx_power = mphy->chandef.chan->max_power;
+	if (phy->txpower != INT_MIN)
+		tx_power = min(tx_power, phy->txpower);
+	tx_power = mt76_get_power_bound(mphy, tx_power);
 	tx_power = mt76_get_rate_power_limits(mphy, mphy->chandef.chan,
 					      &la, tx_power);
 	mphy->txpower_cur = tx_power;
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 2/16 wifi: mt76: use the link struct of a primary station link other than 0

mt76_offchannel_notify_iter(), mt76_rx_beacon_iter() and mt76_beacon_mon_iter() take vif->drv_priv for the link that equals mvif->deflink_id. vif->drv_priv is the link 0 struct, so this is only right while the primary link is link 0. A station MLD whose primary link is link 1 or higher uses the link 0 struct in place of its own:
that link sends no PM nullfunc before the radio leaves the channel, and its beacon loss monitor never runs.

mt76_vif_init() puts vif->drv_priv into mvif->link[0] for the lifetime of the interface, so take every link from mvif->link[], like mt7996 already does in its TX and RX paths.

Fixes 381733b3a14a ("wifi: mt76: send nullfunc PS frames on offchannel transitions")
Fixes 4df75606ece5 ("wifi: mt76: add per-link beacon monitoring for MLO")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +3 -12
index 12089dca01b2..5dbedbca838f 100644
@@ -2336,10 +2336,7 @@ mt76_offchannel_notify_iter(void *_data, u8 *mac, struct ieee80211_vif *vif)
 	}
 
 	for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
-		if (link_id == mvif->deflink_id)
-			mlink = (struct mt76_vif_link *)vif->drv_priv;
-		else
-			mlink = rcu_dereference(mvif->link[link_id]);
+		mlink = rcu_dereference(mvif->link[link_id]);
 		if (!mlink)
 			continue;
 		if (mt76_vif_link_phy(mlink) != data->phy)
@@ -2389,10 +2386,7 @@ static void mt76_rx_beacon_iter(void *_data, u8 *mac,
 	for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
 		struct ieee80211_bss_conf *link_conf;
 
-		if (link_id == mvif->deflink_id)
-			mlink = (struct mt76_vif_link *)vif->drv_priv;
-		else
-			mlink = rcu_dereference(mvif->link[link_id]);
+		mlink = rcu_dereference(mvif->link[link_id]);
 		if (!mlink || !READ_ONCE(mlink->beacon_mon_interval))
 			continue;
 
@@ -2450,10 +2444,7 @@ static void mt76_beacon_mon_iter(void *data, u8 *mac,
 	for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
 		u16 interval;
 
-		if (link_id == mvif->deflink_id)
-			mlink = (struct mt76_vif_link *)vif->drv_priv;
-		else
-			mlink = rcu_dereference(mvif->link[link_id]);
+		mlink = rcu_dereference(mvif->link[link_id]);
 		if (!mlink)
 			continue;
 
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH 3/16 wifi: mt76: refuse a scan or ROC on a radio during a channel switch

In reply to Felix Fietkau

mac80211 starts a scan or a remain-on-channel without a check for a channel switch in progress. On mt7996, mt7996_set_channel() then disables the beacons of the radio for the offchannel dwell and uploads them again on the return. During a CSA the upload carries the CSA template with its initial count, so each scan or ROC on the radio restarts the countdown in the firmware.

Refuse a scan or a ROC that needs a radio on which an AP, mesh or IBSS link has csa_active set. Station links are left out, since they only follow the channel switch of their AP and send no beacons.

Fixes f30906c55a40 ("wifi: mt76: mt7996: disable beacons when going offchannel")
---
 drivers/net/wireless/mediatek/mt76/channel.c | 48 ++++++++++++++++++++
 drivers/net/wireless/mediatek/mt76/mt76.h    |  1 +
 drivers/net/wireless/mediatek/mt76/scan.c    |  3 +-
 3 files changed, 51 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/channel.c +48 -0
index da111d37c4f5..7847aafdbabd 100644
@@ -313,6 +313,53 @@ void mt76_put_vif_phy_link(struct mt76_phy *phy, struct ieee80211_vif *vif,
 	kfree_rcu(mlink, rcu_head);
 }
 
+struct mt76_csa_active_data {
+	struct mt76_phy *phy;
+	bool active;
+};
+
+static void
+mt76_csa_active_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
+{
+	struct mt76_csa_active_data *data = priv;
+	struct ieee80211_bss_conf *link_conf;
+	struct mt76_vif_link *mlink;
+	unsigned int link_id;
+
+	switch (vif->type) {
+	case NL80211_IFTYPE_AP:
+	case NL80211_IFTYPE_MESH_POINT:
+	case NL80211_IFTYPE_ADHOC:
+		break;
+	default:
+		return;
+	}
+
+	for_each_vif_active_link(vif, link_conf, link_id) {
+		if (!link_conf->csa_active)
+			continue;
+
+		mlink = mt76_vif_link(data->phy->dev, vif, link_id);
+		if (mlink && mt76_vif_link_phy(mlink) == data->phy)
+			data->active = true;
+	}
+}
+
+bool mt76_phy_csa_active(struct mt76_phy *phy)
+{
+	struct mt76_csa_active_data data = {
+		.phy = phy,
+	};
+
+	lockdep_assert_held(&phy->dev->mutex);
+
+	ieee80211_iterate_active_interfaces_mtx(phy->hw,
+						IEEE80211_IFACE_ITER_NORMAL,
+						mt76_csa_active_iter, &data);
+
+	return data.active;
+}
+
 void mt76_roc_complete(struct mt76_phy *phy)
 {
 	struct mt76_vif_link *mlink = phy->roc_link;
@@ -379,6 +426,7 @@ int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	mutex_lock(&dev->mutex);
 
 	if (phy->roc_vif || mt76_phy_scanning(phy) ||
+	    mt76_phy_csa_active(phy) ||
 	    test_bit(MT76_MCU_RESET, &dev->phy.state) ||
 	    test_bit(MT76_RESTART, &dev->phy.state)) {
 		ret = -EBUSY;
drivers/net/wireless/mediatek/mt76/mt76.h +1 -0
index 8ebcd5365290..2a39729142af 100644
@@ -1905,6 +1905,7 @@ struct mt76_vif_link *mt76_get_vif_phy_link(struct mt76_phy *phy,
 					    struct ieee80211_vif *vif);
 void mt76_put_vif_phy_link(struct mt76_phy *phy, struct ieee80211_vif *vif,
 			   struct mt76_vif_link *mlink);
+bool mt76_phy_csa_active(struct mt76_phy *phy);
 void mt76_offchannel_notify(struct mt76_phy *phy, bool offchannel);
 
 /* usb */
drivers/net/wireless/mediatek/mt76/scan.c +2 -1
index 3271a2fa100d..51b182ee99e2 100644
@@ -276,7 +276,8 @@ int mt76_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	}
 
 	for_each_set_bit(i, &phy_mask, ARRAY_SIZE(dev->phys)) {
-		if (dev->phys[i]->roc_vif) {
+		if (dev->phys[i]->roc_vif ||
+		    mt76_phy_csa_active(dev->phys[i])) {
 			ret = -EBUSY;
 			goto out;
 		}
Signature · 1 line
2.47.3
author maintainer
#3 lore raw

PATCH 4/16 wifi: mt76: mt7996: keep RX running on a monitor with fcsfail

In reply to Felix Fietkau

mt7996_mcu_set_sniffer_mode() makes the firmware clear the upper bits of MT_WF_RFCR1, MT_WF_RFCR1_DROP_NO2ME_TF among them, so the band passes on trigger frames for other stations. With MT_WF_RFCR_DROP_FCSFAIL also clear, the band stops receiving after some FCS-failed frames:
rx_fifo_full_cnt rises, rx_mpdu_cnt freezes and the host gets no more frames from that band. Deleting the monitor does not recover it, and neither does a SER L3 RX abort or L4 MDP recovery; only a reboot does. Reachable through a monitor interface with the fcsfail flag.

Drop the trigger frames for other stations again while the band accepts FCS-failed frames. A monitor that drops FCS-failed frames still gets the trigger frames for other stations, as the firmware leaves the bit. Send the sniffer command before the filter write, so that the firmware does not overwrite the bit.

Fixes e48da5c9ca29 ("wifi: mt76: mt7996: fix monitor mode")
---
 drivers/net/wireless/mediatek/mt76/mt7996/main.c | 13 ++++++++++++-
 drivers/net/wireless/mediatek/mt76/mt7996/regs.h |  1 +
 2 files changed, 13 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +12 -1
index ba7a0553e34a..e6b81aa890f4 100644
@@ -610,6 +610,17 @@ static void mt7996_phy_set_rxfilter(struct mt7996_phy *phy)
 		mt76_set(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags);
 	else
 		mt76_clear(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags);
+
+	/* Firmware sniffer mode clears the drop of trigger frames for other
+	 * stations, and the band's RX stops where it accepts FCS-failed
+	 * frames without it.
+	 */
+	if (!(filter & MT_WF_RFCR_DROP_FCSFAIL))
+		mt76_set(dev, MT_WF_RFCR1(phy->mt76->band_idx),
+			 MT_WF_RFCR1_DROP_NO2ME_TF);
+	else if (!(filter & MT_WF_RFCR_DROP_OTHER_UC))
+		mt76_clear(dev, MT_WF_RFCR1(phy->mt76->band_idx),
+			   MT_WF_RFCR1_DROP_NO2ME_TF);
 }
 
 static bool mt7996_monitor_active(struct mt7996_dev *dev)
@@ -644,8 +655,8 @@ static void mt7996_set_monitor(struct mt7996_phy *phy, bool enabled)
 		       MT_DMA_DCR0_RXD_G5_EN, enabled);
 	mt76_rmw_field(dev, MT_MDP_DCR0,
 		       MT_MDP_DCR0_RX_HDR_TRANS_EN, !mt7996_monitor_active(dev));
-	mt7996_phy_set_rxfilter(phy);
 	mt7996_mcu_set_sniffer_mode(phy, enabled);
+	mt7996_phy_set_rxfilter(phy);
 }
 
 static int mt7996_add_interface(struct ieee80211_hw *hw,
drivers/net/wireless/mediatek/mt76/mt7996/regs.h +1 -0
index e82a281a773a..b89ac39ad7af 100644
@@ -426,6 +426,7 @@ enum offs_rev {
 #define MT_WF_RFCR1_DROP_BA			BIT(6)
 #define MT_WF_RFCR1_DROP_CFEND			BIT(7)
 #define MT_WF_RFCR1_DROP_CFACK			BIT(8)
+#define MT_WF_RFCR1_DROP_NO2ME_TF		BIT(22)
 
 #define MT_WF_RMAC_MIB_AIRTIME0(_band)		MT_WF_RMAC(_band, 0x0380)
 #define MT_WF_RMAC_MIB_RXTIME_CLR		BIT(31)
Signature · 1 line
2.47.3
author maintainer
#4 lore raw

PATCH 5/16 wifi: mt76: look up the BA session of a BlockAckReq on the primary link

In reply to Felix Fietkau

Since RX reordering moved to the primary link of an MLD peer, wcid->aggr of a secondary link stays empty, and mt76_rx_aggr_reorder() follows def_wcid to find the session. mt76_rx_aggr_check_ctl() does not. A BlockAckReq received on a secondary link therefore finds no session and releases nothing, and frames behind the hole wait for the reorder timeout.

Read the session from the primary link, as mt76_rx_aggr_reorder() does.

Fixes 6ccb6bb9bd7d ("wifi: mt76: mt7996: Use deflink for AMPDU rx reordering")
---
 drivers/net/wireless/mediatek/mt76/agg-rx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/agg-rx.c +1 -1
index 49721b4faab1..5e0adbfd36a6 100644
@@ -143,7 +143,7 @@ mt76_rx_aggr_check_ctl(struct sk_buff *skb, struct sk_buff_head *frames)
 
 	status->qos_ctl = tidno = le16_to_cpu(bar->control) >> 12;
 	seqno = IEEE80211_SEQ_TO_SN(le16_to_cpu(bar->start_seq_num));
-	tid = rcu_dereference(wcid->aggr[tidno]);
+	tid = rcu_dereference(mt76_wcid_primary(wcid)->aggr[tidno]);
 	if (!tid)
 		return;
 
Signature · 1 line
2.47.3
author maintainer
#5 lore raw

PATCH 6/16 wifi: mt76: free a replayed 802.3 frame with all its subframes

In reply to Felix Fietkau

mt76_check_ccmp_pn() marks a replayed frame with RX_FLAG_ONLY_MONITOR, as the drivers mark a frame with an ICV or MIC error. mac80211 honours the flag only in its monitor path. A frame in 802.3 format does not take that path, so such a frame reaches the network stack. The flag also sits on the first subframe of an A-MSDU only, and mac80211 does not check the other subframes, because the IV is stripped.

Free an 802.3 frame that is marked for monitor interfaces only, with all its subframes, and mark each subframe of such a frame in 802.11 format.

Fixes 3c1032e12217 ("mt76: allow receiving frames with invalid CCMP PN via monitor interfaces")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/net/wireless/mediatek/mt76/mac80211.c +12 -0
index 5dbedbca838f..a677c05abe46 100644
@@ -1629,9 +1629,17 @@ void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
 
 	spin_lock(&dev->rx_lock);
 	while ((skb = __skb_dequeue(frames)) != NULL) {
+		struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
 		struct sk_buff *nskb = skb_shinfo(skb)->frag_list;
+		bool only_monitor;
 
 		mt76_check_ccmp_pn(skb);
+		only_monitor = status->flag & RX_FLAG_ONLY_MONITOR;
+		if (only_monitor && (status->flag & RX_FLAG_8023)) {
+			dev_kfree_skb(skb);
+			continue;
+		}
+
 		skb_shinfo(skb)->frag_list = NULL;
 		mt76_rx_convert(dev, skb, &hw, &link_sta);
 		if (nskb)
@@ -1644,6 +1652,10 @@ void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
 			nskb = nskb->next;
 			skb->next = NULL;
 
+			status = (struct mt76_rx_status *)skb->cb;
+			if (only_monitor)
+				status->flag |= RX_FLAG_ONLY_MONITOR;
+
 			mt76_rx_convert(dev, skb, &hw, &link_sta);
 			if (nskb)
 				IEEE80211_SKB_RXCB(skb)->flag |= RX_FLAG_AMSDU_MORE;
Signature · 1 line
2.47.3
author maintainer
#6 lore raw

PATCH 7/16 wifi: mt76: keep one remain-on-channel request per interface

In reply to Felix Fietkau

mt76_remain_on_channel() only checks the target phy for a pending request, so an interface can hold requests on two phys while mvif->roc_phy names only one of them. mac80211 hands such a second request to the driver when a late expiry ends a request that the driver still runs. When the interface goes down, the other request is not aborted, and its completion uses the freed interface:

  Unable to handle kernel paging request at virtual address 0002001400000048
  pc : mt7996_mcu_add_bss_info+0x124/0x4d8 [mt7996e]
  Call trace:
   mt7996_mcu_add_bss_info+0x124/0x4d8 [mt7996e]
   mt7996_vif_link_remove+0x98/0x1fc [mt7996e]
   mt76_put_vif_phy_link+0x3c/0x58 [mt76]
   mt76_roc_complete+0x60/0xb0 [mt76]
   mt76_roc_complete_work+0x28/0x40 [mt76]

Allow one request per interface across all phys, and only clear mvif->roc_phy for the request it names.

Fixes a8f424c1287c ("wifi: mt76: add multi-radio remain_on_channel functions")
---
 drivers/net/wireless/mediatek/mt76/channel.c | 21 +++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/channel.c +18 -3
index 7847aafdbabd..0de7907b4fb4 100644
@@ -360,6 +360,21 @@ bool mt76_phy_csa_active(struct mt76_phy *phy)
 	return data.active;
 }
 
+static struct mt76_phy *
+mt76_vif_roc_phy(struct mt76_dev *dev, struct ieee80211_vif *vif)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(dev->phys); i++) {
+		struct mt76_phy *phy = dev->phys[i];
+
+		if (phy && phy->roc_vif == vif)
+			return phy;
+	}
+
+	return NULL;
+}
+
 void mt76_roc_complete(struct mt76_phy *phy)
 {
 	struct mt76_vif_link *mlink = phy->roc_link;
@@ -368,7 +383,7 @@ void mt76_roc_complete(struct mt76_phy *phy)
 	if (!phy->roc_vif)
 		return;
 
-	if (mlink)
+	if (mlink && mlink->mvif->roc_phy == phy)
 		mlink->mvif->roc_phy = NULL;
 	if (phy->chanctx && phy->main_chandef.chan && phy->offchannel &&
 	    !test_bit(MT76_MCU_RESET, &dev->phy.state)) {
@@ -425,8 +440,8 @@ int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 
 	mutex_lock(&dev->mutex);
 
-	if (phy->roc_vif || mt76_phy_scanning(phy) ||
-	    mt76_phy_csa_active(phy) ||
+	if (phy->roc_vif || mt76_vif_roc_phy(dev, vif) ||
+	    mt76_phy_scanning(phy) || mt76_phy_csa_active(phy) ||
 	    test_bit(MT76_MCU_RESET, &dev->phy.state) ||
 	    test_bit(MT76_RESTART, &dev->phy.state)) {
 		ret = -EBUSY;
Signature · 1 line
2.47.3
author maintainer
#7 lore raw

PATCH 8/16 wifi: mt76: mt7996: install station keys on a link without chanctx

In reply to Felix Fietkau

mt7996_set_hw_key() returns early for a link without a chanctx, also for the key of a station. Since commit e8c819df0243 ("wifi: mt76:
mt7996: Destroy active sta links in mt7996_mac_sta_remove()"), a station MLD whose active links were reduced keeps the station links of the inactive links. The hardware can name the WTBL of such a link for frames that arrive on another link. After a PTK rekey that WTBL keeps the old key, so the EAPOL M1 of the next rekey fails decryption and the AP deauthenticates the station.

Only skip keys without a station on such a link. The first of them updates the BSS of the link, which needs its phy, and the link uploads them when it gets a chanctx.

Fixes e8c819df0243 ("wifi: mt76: mt7996: Destroy active sta links in mt7996_mac_sta_remove()")
---
 drivers/net/wireless/mediatek/mt76/mt7996/main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +3 -3
index e6b81aa890f4..2c09351a56f3 100644
@@ -212,9 +212,6 @@ mt7996_set_hw_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 	if (!link)
 		return 0;
 
-	if (!mt7996_vif_link_phy(link))
-		return 0;
-
 	if (sta) {
 		struct mt7996_sta *msta;
 
@@ -226,6 +223,9 @@ mt7996_set_hw_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 		if (!msta_link->wcid.sta)
 			return -EOPNOTSUPP;
 	} else {
+		if (!mt7996_vif_link_phy(link))
+			return 0;
+
 		msta_link = &link->msta_link;
 	}
 	wcid_keyidx = &msta_link->wcid.hw_key_idx;
Signature · 1 line
2.47.3
author maintainer
#8 lore raw

PATCH 9/16 wifi: mt76: mt7996: keep the fw_mld_idx link in the MLD setup

In reply to Felix Fietkau

mt7996_mcu_sta_mld_setup_tlv() names the WTBL of msta->fw_mld_idx as the primary WTBL of the MLD peer, but lists the active links only. A station that deactivates the link it associated on, which holds that WTBL, and then adds another link thus gets a setup without its primary WTBL in the list. The firmware then counts the TX sequence numbers and PNs of at least TID 7 on the WTBL of a listed link, where both start again at 0, and the peer drops these frames as old in its reorder buffer, EAPOL-Key Requests included.

List the link of the primary WTBL as well, while its station link and vif link exist. The firmware record of the MLD still holds that link, since its deactivation sends no MLD setup.

Fixes 2f3d7e0ad329 ("wifi: mt76: mt7996: describe an MLD peer with the PEER_MLD command")
---
 .../net/wireless/mediatek/mt76/mt7996/mcu.c   | 29 ++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +28 -1
index 57b16f1f5c1d..627ca3e93e51 100644
@@ -2781,13 +2781,40 @@ int mt7996_mcu_mld_link_oper(struct mt7996_dev *dev,
 				     MCU_WMWA_UNI_CMD(BSS_INFO_UPDATE), true);
 }
 
+static unsigned long
+mt7996_mcu_sta_mld_setup_links(struct mt7996_dev *dev,
+			       struct ieee80211_vif *vif,
+			       struct ieee80211_sta *sta)
+{
+	struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
+	unsigned long links = mt7996_mac_sta_links(dev, vif, sta);
+	unsigned int link_id;
+
+	if (!msta->peer_mld_links)
+		return links;
+
+	for (link_id = 0; link_id < ARRAY_SIZE(msta->link); link_id++) {
+		struct mt7996_sta_link *msta_link;
+
+		msta_link = mt7996_sta_link_protected(dev, msta, link_id);
+		if (!msta_link || msta_link->wcid.idx != msta->fw_mld_idx)
+			continue;
+
+		if (mt7996_vif_link(dev, vif, link_id))
+			links |= BIT(link_id);
+		break;
+	}
+
+	return links;
+}
+
 static void
 mt7996_mcu_sta_mld_setup_tlv(struct mt7996_dev *dev, struct sk_buff *skb,
 			     struct ieee80211_vif *vif,
 			     struct ieee80211_sta *sta)
 {
+	unsigned long links = mt7996_mcu_sta_mld_setup_links(dev, vif, sta);
 	struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
-	unsigned long links = mt7996_mac_sta_links(dev, vif, sta);
 	unsigned int nlinks = hweight16(links);
 	struct mld_setup_link *mld_setup_link;
 	struct sta_rec_mld_setup *mld_setup;
Signature · 1 line
2.47.3
author maintainer
#9 lore raw

PATCH 10/16 wifi: mt76: keep mac_work running when a ROC request fails

In reply to Felix Fietkau

Since the cancel of mac_work moved in front of dev->mutex, mt76_remain_on_channel() cancels mac_work before it checks whether it can start the request. Only the set_channel op of the driver queues mac_work again. A request that the function refuses, or whose link setup fails, thus leaves mac_work stopped until the next channel change of the radio, for example a request during a channel switch. Until then, station links on the radio do not detect beacon loss.

Queue mac_work again on these paths if the radio is running. Run it at once, since only the driver knows its interval, and mac_work queues itself again with that interval. Leave it stopped when a reset refuses the request, since the reset queues mac_work again itself.

Fixes 6939b97ddad3 ("wifi: mt76: fix deadlock in remain-on-channel")
---
 drivers/net/wireless/mediatek/mt76/channel.c | 26 +++++++++++++++++---
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/channel.c +22 -4
index 0de7907b4fb4..23066307c92a 100644
@@ -29,6 +29,16 @@ mt76_phy_update_channel(struct mt76_phy *phy,
 	return __mt76_set_channel(phy, &phy->main_chandef, false);
 }
 
+static void mt76_phy_mac_work_restart(struct mt76_phy *phy)
+{
+	struct mt76_dev *dev = phy->dev;
+
+	if (test_bit(MT76_STATE_RUNNING, &phy->state) &&
+	    !test_bit(MT76_MCU_RESET, &dev->phy.state) &&
+	    !test_bit(MT76_RESTART, &dev->phy.state))
+		ieee80211_queue_delayed_work(phy->hw, &phy->mac_work, 0);
+}
+
 int mt76_add_chanctx(struct ieee80211_hw *hw,
 		     struct ieee80211_chanctx_conf *conf)
 {
@@ -440,18 +450,22 @@ int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 
 	mutex_lock(&dev->mutex);
 
-	if (phy->roc_vif || mt76_vif_roc_phy(dev, vif) ||
-	    mt76_phy_scanning(phy) || mt76_phy_csa_active(phy) ||
-	    test_bit(MT76_MCU_RESET, &dev->phy.state) ||
+	if (test_bit(MT76_MCU_RESET, &dev->phy.state) ||
 	    test_bit(MT76_RESTART, &dev->phy.state)) {
 		ret = -EBUSY;
 		goto out;
 	}
 
+	if (phy->roc_vif || mt76_vif_roc_phy(dev, vif) ||
+	    mt76_phy_scanning(phy) || mt76_phy_csa_active(phy)) {
+		ret = -EBUSY;
+		goto restart_mac_work;
+	}
+
 	mlink = mt76_get_vif_phy_link(phy, vif);
 	if (IS_ERR(mlink)) {
 		ret = PTR_ERR(mlink);
-		goto out;
+		goto restart_mac_work;
 	}
 
 	mlink->mvif->roc_phy = phy;
@@ -473,6 +487,10 @@ int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	ieee80211_queue_delayed_work(phy->hw, &phy->roc_work,
 				     msecs_to_jiffies(duration));
 
+	goto out;
+
+restart_mac_work:
+	mt76_phy_mac_work_restart(phy);
 out:
 	mutex_unlock(&dev->mutex);
 	return ret;
Signature · 1 line
2.47.3
author maintainer
#10 lore raw

PATCH 11/16 wifi: mt76: keep mac_work running when a chanctx switch fails

In reply to Felix Fietkau

mt76_switch_vif_chanctx() cancels mac_work of each radio whose channel context changes, before it takes dev->mutex. Only the set_channel op of the driver queues mac_work again. If the channel update or the link move of a vif fails, or a later vif names no radio, the function returns before it sets the channel of the other radios, and their mac_work stays stopped until their next channel change. Station links on these radios then do not detect beacon loss. Reachable via a channel switch of vifs on several radios whose MCU command fails.

Queue mac_work again for each radio whose channel the function did not set, as mt76_remain_on_channel() does for a request that it refuses.

Fixes 70869cc429ff ("wifi: mt76: fix handling channel context with different bands in mt76_switch_vif_chanctx()")
---
 drivers/net/wireless/mediatek/mt76/channel.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/channel.c +9 -2
index 23066307c92a..df655cc56349 100644
@@ -216,8 +216,10 @@ int mt76_switch_vif_chanctx(struct ieee80211_hw *hw,
 		else
 			phy = new_ctx->phy;
 
-		if (!phy)
-			return -EINVAL;
+		if (!phy) {
+			ret = -EINVAL;
+			goto restart_mac_work;
+		}
 
 		if (need_update[phy->band_idx])
 			continue;
@@ -273,6 +275,11 @@ int mt76_switch_vif_chanctx(struct ieee80211_hw *hw,
 out:
 	mutex_unlock(&dev->mutex);
 
+restart_mac_work:
+	for (i = 0; i < ARRAY_SIZE(need_update); i++)
+		if (need_update[i] && dev->phys[i])
+			mt76_phy_mac_work_restart(dev->phys[i]);
+
 	return ret;
 }
 EXPORT_SYMBOL_GPL(mt76_switch_vif_chanctx);
Signature · 1 line
2.47.3
author maintainer
#11 lore raw

PATCH 12/16 wifi: mt76: mt7925: install pairwise keys on station links added later

In reply to Felix Fietkau

mt7925_set_key() installs a pairwise key only on the links in msta->valid_links at the time of the call. mac80211 does not install it again when a link is added to the station later, because ieee80211_key_switch_links() only moves keys with a link ID. A link that mt7925_change_sta_links() adds after the key is installed thus has no key in its WTBL entry. Reachable via _ieee80211_set_active_links(), for example when the AP removes all active links of the client with ML reconfiguration and ieee80211_ml_reconf_work() activates another link.

Install the pairwise keys of the station on the links that mt7925_change_sta_links() adds, like mt7996_mac_sta_links_set_keys() does. Stop at the first key that fails and log it: a timed out MCU command already schedules a chip reset, and each further command can wait for its own timeout under the wiphy lock. Keep the links and return success, since ieee80211_sta_set_link_valid() drops a link on an error without telling the driver.

Fixes 43aa4033eb18 ("wifi: mt76: mt7925: add mt7925_change_sta_links")
---
 .../net/wireless/mediatek/mt76/mt7925/main.c  | 47 +++++++++++++++++++
 1 file changed, 47 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +47 -0
index 975c564236f9..b88d92f9aaf2 100644
@@ -2597,6 +2597,51 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	return err;
 }
 
+struct mt7925_key_iter_data {
+	struct ieee80211_sta *sta;
+	struct mt792x_link_sta *mlink;
+	unsigned int link_id;
+	int err;
+};
+
+static void
+mt7925_sta_key_iter(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+		    struct ieee80211_sta *sta, struct ieee80211_key_conf *key,
+		    void *data)
+{
+	struct mt7925_key_iter_data *it = data;
+
+	if (it->err || sta != it->sta || key->link_id >= 0)
+		return;
+
+	it->err = mt7925_set_link_key(hw, SET_KEY, vif, sta, key, it->link_id,
+				      it->mlink);
+}
+
+static void
+mt7925_mac_sta_links_set_keys(struct ieee80211_hw *hw,
+			      struct ieee80211_vif *vif,
+			      struct ieee80211_sta *sta, unsigned long links)
+{
+	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
+	struct mt7925_key_iter_data it = {
+		.sta = sta,
+	};
+	unsigned int link_id;
+
+	for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
+		it.link_id = link_id;
+		it.mlink = mt792x_sta_to_link(msta, link_id);
+		ieee80211_iter_keys(hw, vif, mt7925_sta_key_iter, &it);
+		if (it.err) {
+			dev_err(mt792x_hw_dev(hw)->mt76.dev,
+				"failed to set station keys on link %u: %d\n",
+				link_id, it.err);
+			return;
+		}
+	}
+}
+
 static int
 mt7925_change_sta_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 			struct ieee80211_sta *sta, u16 old_links, u16 new_links)
@@ -2619,6 +2664,8 @@ mt7925_change_sta_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	if (err < 0)
 		goto out;
 
+	mt7925_mac_sta_links_set_keys(hw, vif, sta, add);
+
 out:
 	mt792x_mutex_release(dev);
 
Signature · 1 line
2.47.3
author maintainer
#12 lore raw

PATCH 13/16 wifi: mt76: wait for a ROC completion in progress on cancel

In reply to Felix Fietkau

mt76_cancel_remain_on_channel() reads mvif->roc_phy and phy->roc_vif without dev->mutex, while mt76_roc_complete() clears both under the mutex before it reports the expiry. A cancel during a completion thus returns before the expiry reaches mac80211, and the late expiry ends the next request. ieee80211_cancel_roc() relies on the opposite:

Note that this assumes that by the time the driver returns from drv_cancel_remain_on_channel, it has completed all the processing of related notifications.

Look up the request of the interface under dev->mutex, so that a completion in progress has reported the expiry before the cancel returns.

Fixes a8f424c1287c ("wifi: mt76: add multi-radio remain_on_channel functions")
---
 drivers/net/wireless/mediatek/mt76/channel.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/wireless/mediatek/mt76/channel.c +8 -6
index df655cc56349..9638f65a679e 100644
@@ -507,14 +507,16 @@ EXPORT_SYMBOL_GPL(mt76_remain_on_channel);
 int mt76_cancel_remain_on_channel(struct ieee80211_hw *hw,
 				  struct ieee80211_vif *vif)
 {
-	struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv;
-	struct mt76_vif_data *mvif = mlink->mvif;
-	struct mt76_phy *phy = mvif->roc_phy;
+	struct mt76_phy *phy = hw->priv;
+	struct mt76_dev *dev = phy->dev;
 
-	if (!phy || phy->roc_vif != vif)
-		return 0;
+	/* a completion holds the mutex until it reported the expiry */
+	mutex_lock(&dev->mutex);
+	phy = mt76_vif_roc_phy(dev, vif);
+	mutex_unlock(&dev->mutex);
 
-	mt76_abort_roc(phy);
+	if (phy)
+		mt76_abort_roc(phy);
 
 	return 0;
 }
Signature · 1 line
2.47.3
author maintainer
#13 lore raw

PATCH 14/16 wifi: mt76: mt7925: keep the MLD record until the last link is removed

In reply to Felix Fietkau

mt7925_mcu_sta_cmd() adds STA_REC_MLD_OFF to the STA_REC of every link that mt7925_mac_link_sta_remove() removes. mt7925_change_sta_links() also removes single links of a station that keeps other links. A client then stops transmitting on the links it keeps: the device takes the frames from the host, but sends none of them on air. Reachable via _ieee80211_set_active_links(), for example when the AP removes an active link of the client with ML reconfiguration.

Only turn the MLD record off with the last link of the station, like mt7996_mac_sta_links_event() does. A station without MLO has one link at most and keeps STA_REC_MLD_OFF.

Fixes a5942a3979d6 ("wifi: mt76: mt7925: update mt7925_mcu_sta_update for MLO")
---
 drivers/net/wireless/mediatek/mt76/mt7925/mcu.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +10 -2
index f46fb08558f9..218815e64a81 100644
@@ -2347,9 +2347,17 @@ mt7925_mcu_sta_cmd(struct mt76_phy *phy,
 	}
 
 	if (!info->enable) {
+		struct mt792x_sta *msta;
+
+		msta = (struct mt792x_sta *)info->link_sta->sta->drv_priv;
 		mt7925_mcu_sta_remove_tlv(skb);
-		mt76_connac_mcu_add_tlv(skb, STA_REC_MLD_OFF,
-					sizeof(struct tlv));
+
+		/* One MLD record serves all links of the station, and the
+		 * caller drops the removed link from valid_links first.
+		 */
+		if (!msta->valid_links)
+			mt76_connac_mcu_add_tlv(skb, STA_REC_MLD_OFF,
+						sizeof(struct tlv));
 	} else {
 		if (!info->link_sta)
 			mlink = &mvif->sta.deflink;
Signature · 1 line
2.47.3
author maintainer
#14 lore raw

PATCH 15/16 wifi: mt76: mt7996: read a new MIB baseline after the firmware reload

In reply to Felix Fietkau

mt7996_mcu_get_chan_mib_info() adds the difference between the MIB airtime counters of the firmware and the baseline in phy->state_ts to the channel state. Since the full system reset was added, mt7996_mac_restart() loads the firmware again, which counts from zero, but reads no new baseline. The first survey update after the reset thus subtracts the counts of the old firmware, and the busy, rx and tx times of a survey dump can wrap below zero.

Read a new baseline for every running phy at the end of the restart. A phy that does not run reads it at its next start instead, since the reloaded firmware has not enabled its radio, and a failed query would fail the restart.

Fixes 27015b6fbcca ("wifi: mt76: mt7996: enable full system reset support")
---
 drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +12 -0
index c70e429ab419..8a8098f4fc82 100644
@@ -2430,6 +2430,18 @@ mt7996_mac_restart(struct mt7996_dev *dev)
 			goto out;
 	}
 
+	/* the reloaded firmware counts the MIB airtime from zero */
+	mt7996_for_each_phy(dev, phy) {
+		if (!test_bit(MT76_STATE_RUNNING, &phy->mt76->state)) {
+			phy->counter_reset = false;
+			continue;
+		}
+
+		ret = mt7996_mcu_get_chan_mib_info(phy, true);
+		if (ret)
+			goto out;
+	}
+
 out:
 	/* reset done */
 	mt7996_for_each_phy(dev, phy)
Signature · 1 line
2.47.3
author maintainer
#15 lore raw

PATCH 16/16 wifi: mt76: mt7915: read a new MIB baseline after the firmware reload

In reply to Felix Fietkau

mt7915_mcu_get_chan_mib_info() adds the difference between the MIB airtime counters of the firmware and the baseline in phy->state_ts to the channel state. Since the full system reset was added, mt7915_mac_restart() loads the firmware again, which counts from zero, but only the phy that mt7915_run() starts first reads a new baseline. On a DBDC chip the first survey update of the other phy after the reset thus subtracts the counts of the old firmware, and the busy, rx and tx times of a survey dump can wrap below zero.

Read a new baseline for each running phy at the end of a successful restart. A phy that does not run reads it at its first start instead, as on mt7996, since the reloaded firmware has not started it. This also gives the ext phy a baseline when it starts while the main phy runs.

Fixes 8a55712d124f ("wifi: mt76: mt7915: enable full system reset support")
---
 drivers/net/wireless/mediatek/mt76/mt7915/mac.c    | 11 +++++++++++
 drivers/net/wireless/mediatek/mt76/mt7915/main.c   |  4 +++-
 drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +11 -0
index b3d4abf6a9ed..24207880211e 100644
@@ -1404,6 +1404,17 @@ mt7915_mac_restart(struct mt7915_dev *dev)
 			goto out;
 	}
 
+	/* the reloaded firmware counts the MIB airtime from zero */
+	if (!run_main)
+		dev->phy.counter_reset = false;
+	else if (!ret)
+		ret = mt7915_mcu_get_chan_mib_info(&dev->phy, true);
+
+	if (phy2 && !run_ext)
+		phy2->counter_reset = false;
+	else if (run_ext && !ret)
+		ret = mt7915_mcu_get_chan_mib_info(phy2, true);
+
 out:
 	/* reset done */
 	clear_bit(MT76_RESET, &dev->mphy.state);
drivers/net/wireless/mediatek/mt76/mt7915/main.c +3 -1
index 8cf7fde1a197..7a2e759181ad 100644
@@ -87,8 +87,10 @@ int mt7915_run(struct ieee80211_hw *hw)
 		ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
 					     MT7915_WATCHDOG_TIME);
 
-	if (!running)
+	if (!running || !phy->counter_reset) {
 		mt7915_mac_reset_counters(phy);
+		phy->counter_reset = true;
+	}
 
 out:
 	return ret;
drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h +1 -0
index 30fb119ce872..ec1d10832b27 100644
@@ -227,6 +227,7 @@ struct mt7915_phy {
 	struct mt76_mib_stats mib;
 	struct mt76_channel_state state_ts;
 
+	bool counter_reset;
 	bool sku_limit_en:1;
 	bool sku_path_en:1;
 
Signature · 1 line
2.47.3