Skip to contentSkip to conversation

wifi: mt76: mt7925: undo the BSS of a failed interface add

PATCH In review Felix Fietkau 2 participants 21 messages Nov 23

Subsystems (2)
lore
Share & tools
lore

Felix Fietkau

author maintainer
#0 lore raw

PATCH 1/20 wifi: mt76: mt7925: undo the BSS of a failed interface add

mt7925_mac_link_bss_add() publishes the wcid of the interface and takes its vif_mask and omac_mask bits before it sends the firmware command, and it undoes that setup for an allocated link alone. When the command fails in mt7925_add_interface(), mac80211 calls no remove_interface, so dev->mt76.wcid[] keeps naming the wcid inside vif->drv_priv, which mac80211 frees with the interface, and the BSS index stays taken.

Undo the setup of the BSS in mt7925_add_interface() when the add published its wcid. A failure before that point sets nothing up, and the index it computed can belong to a P2P device. The add itself still leaves the BSS of the embedded link set up for mt7925_change_vif_links(), because the next association or mt7925_remove_interface() removes that BSS later.

Fixes ac03e5b82bc6 ("wifi: mt76: mt7925: Enhance mt7925_mac_link_bss_add to support MLO")
---
 .../net/wireless/mediatek/mt76/mt7925/main.c  | 27 ++++++++++++++-----
 1 file changed, 20 insertions(+), 7 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +20 -7
index d99d86bf5be8..0908c22c3dff 100644
@@ -376,6 +376,16 @@ static int mt7925_start(struct ieee80211_hw *hw)
 	return err;
 }
 
+static void mt7925_mac_link_bss_unwind(struct mt792x_dev *dev,
+				       struct mt792x_bss_conf *mconf,
+				       struct mt792x_link_sta *mlink)
+{
+	rcu_assign_pointer(dev->mt76.wcid[mlink->wcid.idx], NULL);
+	mt76_wcid_cleanup(&dev->mt76, &mlink->wcid);
+	dev->mt76.vif_mask &= ~BIT_ULL(mconf->mt76.idx);
+	mconf->vif->phy->omac_mask &= ~BIT_ULL(mconf->mt76.omac_idx);
+}
+
 static int mt7925_mac_link_bss_add(struct mt792x_dev *dev,
 				   struct ieee80211_bss_conf *link_conf,
 				   struct mt792x_link_sta *mlink)
@@ -449,12 +459,8 @@ 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);
-		}
+		if (mconf != &mvif->bss_conf)
+			mt7925_mac_link_bss_unwind(dev, mconf, mlink);
 		mt7925_p2p_bmc_remove(dev, mconf);
 		goto out;
 	}
@@ -496,8 +502,15 @@ mt7925_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
 	mvif->mlo_pm_state = MT792x_MLO_LINK_DISASSOC;
 
 	ret = mt7925_mac_link_bss_add(dev, &vif->bss_conf, &mvif->sta.deflink);
-	if (ret < 0)
+	if (ret < 0) {
+		struct mt76_wcid *wcid = &mvif->sta.deflink.wcid;
+
+		/* mac80211 calls no remove_interface after a failed add */
+		if (rcu_access_pointer(dev->mt76.wcid[wcid->idx]) == wcid)
+			mt7925_mac_link_bss_unwind(dev, &mvif->bss_conf,
+						   &mvif->sta.deflink);
 		goto out;
+	}
 
 	vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
 	if (phy->chip_cap & MT792x_CHIP_CAP_RSSI_NOTIFY_EVT_EN)
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 2/20 wifi: mt76: mt7925: keep the embedded link's BMC wcid after a failed add

When DEV_INFO fails for the embedded link in mt7925_change_vif_links(), mt7925_mac_link_bss_add() keeps the BSS of that link but frees its BMC wcid. The next association of a P2P client must allocate a new BMC wcid, and where none is free the add fails before it sets up the BSS, while mconf->mt76.idx and the deflink wcid index name a BSS that the interface no longer holds. mt7925_remove_interface() then removes that BSS index and wcid slot, which another interface can hold by then.

Keep the BMC wcid of the embedded link as long as its BSS, and free it together with the BSS where a failed add is undone.

Fixes 4dd53cf06f01 ("wifi: mt76: mt7925: give every P2P interface a BMC wcid of its own")
---
 drivers/net/wireless/mediatek/mt76/mt7925/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +1 -1
index 0908c22c3dff..b6eca78a5e51 100644
@@ -384,6 +384,7 @@ static void mt7925_mac_link_bss_unwind(struct mt792x_dev *dev,
 	mt76_wcid_cleanup(&dev->mt76, &mlink->wcid);
 	dev->mt76.vif_mask &= ~BIT_ULL(mconf->mt76.idx);
 	mconf->vif->phy->omac_mask &= ~BIT_ULL(mconf->mt76.omac_idx);
+	mt7925_p2p_bmc_remove(dev, mconf);
 }
 
 static int mt7925_mac_link_bss_add(struct mt792x_dev *dev,
@@ -461,7 +462,6 @@ static int mt7925_mac_link_bss_add(struct mt792x_dev *dev,
 	if (ret) {
 		if (mconf != &mvif->bss_conf)
 			mt7925_mac_link_bss_unwind(dev, mconf, mlink);
-		mt7925_p2p_bmc_remove(dev, mconf);
 		goto out;
 	}
 
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH 3/20 wifi: mt76: mt7915: read the PS sync state of mt7986 and mt7981

In reply to Felix Fietkau

mt7915_mcu_rx_ps_sync() reads the PS state at payload byte 1, as the mt7915 firmware sends it. The mt7986 and mt7981 firmware send a longer event. It holds the index as two 16-bit words and the state at payload byte 6. Byte 1 is always 0 in that layout.

Every event of these chips thus clears MT_WCID_FLAG_PS. The host then never throttles the TX of a station in power save.

Take the layout from the event length of the firmware, and drop an event that the buffer does not hold.

Fixes dc930cf883c8 ("wifi: mt76: mt7915: handle MCU PS sync events")
---
 .../net/wireless/mediatek/mt76/mt7915/mcu.c   | 20 +++++++++++++++++--
 .../net/wireless/mediatek/mt76/mt7915/mcu.h   | 10 ++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +18 -2
index 6e1c3e5e2fe9..02426feb6182 100644
@@ -411,16 +411,32 @@ mt7915_mcu_rx_bcc_notify(struct mt7915_dev *dev, struct sk_buff *skb)
 static void
 mt7915_mcu_rx_ps_sync(struct mt7915_dev *dev, struct sk_buff *skb)
 {
+	struct mt7915_mcu_ps_notify_v2 *p2 = (void *)skb->data;
 	struct mt7915_mcu_ps_notify *p = (void *)skb->data;
 	struct mt76_wcid *wcid;
 	u16 wcid_idx;
+	bool v2, ps;
+
+	/* the mt7986 and mt7981 firmware send the longer v2 layout */
+	v2 = le16_to_cpu(p->rxd.len) >=
+	     sizeof(*p2) - offsetof(struct mt76_connac2_mcu_rxd_hdr, len);
+	if (skb->len < (v2 ? sizeof(*p2) : sizeof(*p)))
+		return;
+
+	if (v2) {
+		wcid_idx = le16_to_cpu(p2->wtbl_lower) |
+			   (le16_to_cpu(p2->wtbl_higher) << 8);
+		ps = p2->ps_bit;
+	} else {
+		wcid_idx = p->wtbl_lower | (p->wtbl_higher << 8);
+		ps = p->ps_bit;
+	}
 
-	wcid_idx = p->wtbl_lower | (p->wtbl_higher << 8);
 	wcid = mt76_wcid_ptr(dev, wcid_idx);
 	if (!wcid || !wcid_to_sta(wcid))
 		return;
 
-	mt76_sta_ps_transition(&dev->mt76, wcid, !!p->ps_bit);
+	mt76_sta_ps_transition(&dev->mt76, wcid, ps);
 }
 
 static void
drivers/net/wireless/mediatek/mt76/mt7915/mcu.h +10 -0
index 76e39e899797..7dbe43200fb4 100644
@@ -63,6 +63,16 @@ struct mt7915_mcu_ps_notify {
 	u8 rsv;
 } __packed;
 
+struct mt7915_mcu_ps_notify_v2 {
+	struct mt76_connac2_mcu_rxd_hdr rxd;
+
+	__le16 wtbl_lower;
+	__le16 wtbl_higher;
+	__le16 rsv;
+	u8 ps_bit;
+	u8 rsv2;
+} __packed;
+
 struct mt7915_mcu_rdd_report {
 	struct mt76_connac2_mcu_rxd_hdr rxd;
 
Signature · 1 line
2.47.3
author maintainer
#3 lore raw

PATCH 4/20 wifi: mt76: mt7915: leave the BIP check of a group frame to mac80211

In reply to Felix Fietkau

mt7915_mac_fill_rx() sets RX_FLAG_DECRYPTED and RX_FLAG_IV_STRIPPED for every frame whose RXD carries a cipher. That includes a group addressed robust Management frame that the hardware matched with the IGTK. The MME of such a frame stays in place, and the driver installs the IGTK without an IPN.

With both flags, ieee80211_rx_h_decrypt() takes the frame as verified and checks neither the MIC nor the IPN. The firmware of mt7981 keeps no RX IPN. On mt7981, a station with PMF thus accepts a replayed group Deauthentication or Disassociation of its AP.

Do not report a frame with a BIP cipher as decrypted. mac80211 then selects the IGTK by the key id of the MME, and checks the IPN and the MIC. It also removes the MME. For an offloaded IGTK, it uses the CMAC key that it keeps.

Fixes e57b7901469f ("mt76: add mac80211 driver for MT7915 PCIe-based chipsets")
---
 drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +5 -2
index 5d1b5abc8fff..b7f86195af2d 100644
@@ -284,6 +284,7 @@ mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb,
 	u16 hdr_gap;
 	u16 seq_ctrl = 0;
 	__le16 fc = 0;
+	u8 sec_mode;
 	int idx;
 
 	memset(status, 0, sizeof(*status));
@@ -342,7 +343,9 @@ mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb,
 	if (rxd1 & MT_RXD1_NORMAL_TKIP_MIC_ERR)
 		status->flag |= RX_FLAG_MMIC_ERROR;
 
-	if (FIELD_GET(MT_RXD1_NORMAL_SEC_MODE, rxd1) != 0 &&
+	/* a BIP frame keeps its MME, for mac80211 to check MIC and IPN */
+	sec_mode = FIELD_GET(MT_RXD1_NORMAL_SEC_MODE, rxd1);
+	if (sec_mode != 0 && sec_mode != MT_CIPHER_BIP_CMAC_128 &&
 	    !(rxd1 & (MT_RXD1_NORMAL_CLM | MT_RXD1_NORMAL_CM))) {
 		status->flag |= RX_FLAG_DECRYPTED;
 		status->flag |= RX_FLAG_IV_STRIPPED;
@@ -372,7 +375,7 @@ mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb,
 		u8 *data = (u8 *)rxd;
 
 		if (status->flag & RX_FLAG_DECRYPTED) {
-			switch (FIELD_GET(MT_RXD1_NORMAL_SEC_MODE, rxd1)) {
+			switch (sec_mode) {
 			case MT_CIPHER_AES_CCMP:
 			case MT_CIPHER_CCMP_CCX:
 			case MT_CIPHER_CCMP_256:
Signature · 1 line
2.47.3
author maintainer
#4 lore raw

PATCH 5/20 wifi: mt76: mt7921: leave the BIP check of a group frame to mac80211

In reply to Felix Fietkau

mt7921_mac_fill_rx() sets RX_FLAG_DECRYPTED and RX_FLAG_IV_STRIPPED for every frame whose RXD carries a cipher. That includes a group addressed robust Management frame that the hardware matched with the IGTK. The MME of such a frame stays in place, and the driver installs the IGTK without an IPN.

With both flags, ieee80211_rx_h_decrypt() takes the frame as verified and checks neither the MIC nor the IPN. No check of the IPN in the hardware is known. A station with PMF can thus accept a replayed group Deauthentication or Disassociation of its AP.

Do not report a frame with a BIP cipher as decrypted. mac80211 then selects the IGTK by the key id of the MME, and checks the IPN and the MIC. It also removes the MME. For an offloaded IGTK, it uses the CMAC key that it keeps.

Fixes e0f9fdda81bd ("mt76: mt7921: add ieee80211_ops")
---
 drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7921/mac.c +5 -2
index 6f5e31489e2d..a2d577872566 100644
@@ -188,6 +188,7 @@ mt7921_mac_fill_rx(struct mt792x_dev *dev, struct sk_buff *skb)
 	u16 seq_ctrl = 0;
 	__le16 fc = 0;
 	u8 mode = 0;
+	u8 sec_mode;
 	int idx;
 
 	memset(status, 0, sizeof(*status));
@@ -247,7 +248,9 @@ mt7921_mac_fill_rx(struct mt792x_dev *dev, struct sk_buff *skb)
 	if (rxd1 & MT_RXD1_NORMAL_TKIP_MIC_ERR)
 		status->flag |= RX_FLAG_MMIC_ERROR;
 
-	if (FIELD_GET(MT_RXD1_NORMAL_SEC_MODE, rxd1) != 0 &&
+	/* a BIP frame keeps its MME, for mac80211 to check MIC and IPN */
+	sec_mode = FIELD_GET(MT_RXD1_NORMAL_SEC_MODE, rxd1);
+	if (sec_mode != 0 && sec_mode != MT_CIPHER_BIP_CMAC_128 &&
 	    !(rxd1 & (MT_RXD1_NORMAL_CLM | MT_RXD1_NORMAL_CM))) {
 		status->flag |= RX_FLAG_DECRYPTED;
 		status->flag |= RX_FLAG_IV_STRIPPED;
@@ -277,7 +280,7 @@ mt7921_mac_fill_rx(struct mt792x_dev *dev, struct sk_buff *skb)
 		u8 *data = (u8 *)rxd;
 
 		if (status->flag & RX_FLAG_DECRYPTED) {
-			switch (FIELD_GET(MT_RXD1_NORMAL_SEC_MODE, rxd1)) {
+			switch (sec_mode) {
 			case MT_CIPHER_AES_CCMP:
 			case MT_CIPHER_CCMP_CCX:
 			case MT_CIPHER_CCMP_256:
Signature · 1 line
2.47.3
author maintainer
#5 lore raw

PATCH 6/20 wifi: mt76: mt7925: leave the BIP check of a group frame to mac80211

In reply to Felix Fietkau

mt7925_mac_fill_rx() sets RX_FLAG_DECRYPTED and RX_FLAG_IV_STRIPPED for every frame whose RXD carries a cipher. That includes a group addressed robust Management frame that the hardware matched with the IGTK. The MME of such a frame stays in place, and the driver installs the IGTK without an IPN.

With both flags, ieee80211_rx_h_decrypt() takes the frame as verified and checks neither the MIC nor the IPN. No check of the IPN in the hardware is known. A station with PMF can thus accept a replayed group Deauthentication or Disassociation of its AP.

Do not report a frame with a BIP cipher as decrypted. mac80211 then selects the IGTK by the key id of the MME, and checks the IPN and the MIC. It also removes the MME. For an offloaded IGTK, it uses the CMAC key that it keeps.

Fixes c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")
---
 drivers/net/wireless/mediatek/mt76/mt7925/mac.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/mac.c +5 -2
index a99a2c497458..cc8ea0d37430 100644
@@ -423,6 +423,7 @@ mt7925_mac_fill_rx(struct mt792x_dev *dev, struct sk_buff *skb)
 	u8 mode = 0; /* , band_idx; */
 	u16 seq_ctrl = 0;
 	__le16 fc = 0;
+	u8 sec_mode;
 	int idx;
 
 	memset(status, 0, sizeof(*status));
@@ -478,7 +479,9 @@ mt7925_mac_fill_rx(struct mt792x_dev *dev, struct sk_buff *skb)
 	if (rxd1 & MT_RXD1_NORMAL_TKIP_MIC_ERR)
 		status->flag |= RX_FLAG_MMIC_ERROR;
 
-	if (FIELD_GET(MT_RXD2_NORMAL_SEC_MODE, rxd2) != 0 &&
+	/* a BIP frame keeps its MME, for mac80211 to check MIC and IPN */
+	sec_mode = FIELD_GET(MT_RXD2_NORMAL_SEC_MODE, rxd2);
+	if (sec_mode != 0 && sec_mode != MT_CIPHER_BIP_CMAC_128 &&
 	    !(rxd1 & (MT_RXD1_NORMAL_CLM | MT_RXD1_NORMAL_CM))) {
 		status->flag |= RX_FLAG_DECRYPTED;
 		status->flag |= RX_FLAG_IV_STRIPPED;
@@ -509,7 +512,7 @@ mt7925_mac_fill_rx(struct mt792x_dev *dev, struct sk_buff *skb)
 		u8 *data = (u8 *)rxd;
 
 		if (status->flag & RX_FLAG_DECRYPTED) {
-			switch (FIELD_GET(MT_RXD2_NORMAL_SEC_MODE, rxd2)) {
+			switch (sec_mode) {
 			case MT_CIPHER_AES_CCMP:
 			case MT_CIPHER_CCMP_CCX:
 			case MT_CIPHER_CCMP_256:
Signature · 1 line
2.47.3
author maintainer
#6 lore raw

PATCH 7/20 wifi: mt76: mt7615: leave the BIP check of a group frame to mac80211

In reply to Felix Fietkau

mt7615_mac_fill_rx() sets RX_FLAG_DECRYPTED and RX_FLAG_IV_STRIPPED for every frame whose RXD carries a cipher. That includes a group addressed robust Management frame that the hardware matched with the IGTK. The MME of such a frame stays in place, and the driver installs the IGTK without an IPN.

With both flags, ieee80211_rx_h_decrypt() takes the frame as verified and checks neither the MIC nor the IPN. No check of the IPN in the hardware is known. A station with PMF can thus accept a replayed group Deauthentication or Disassociation of its AP.

Do not report a frame with a BIP cipher as decrypted. mac80211 then selects the IGTK by the key id of the MME, and checks the IPN and the MIC. It also removes the MME. For an offloaded IGTK, it uses the CMAC key that it keeps.

Fixes 01cfc1b45421 ("mt76: mt7615: add BIP_CMAC_128 cipher support")
---
 drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +5 -2
index 8e81ebe3e2ca..0def4ba75817 100644
@@ -348,6 +348,7 @@ static int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb)
 	u8 chfreq, amsdu_info, qos_ctl = 0;
 	u16 seq_ctrl = 0;
 	__le16 fc = 0;
+	u8 sec_mode;
 
 	memset(status, 0, sizeof(*status));
 
@@ -397,7 +398,9 @@ static int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb)
 	if (rxd2 & MT_RXD2_NORMAL_TKIP_MIC_ERR)
 		status->flag |= RX_FLAG_MMIC_ERROR;
 
-	if (FIELD_GET(MT_RXD2_NORMAL_SEC_MODE, rxd2) != 0 &&
+	/* a BIP frame keeps its MME, for mac80211 to check MIC and IPN */
+	sec_mode = FIELD_GET(MT_RXD2_NORMAL_SEC_MODE, rxd2);
+	if (sec_mode != 0 && sec_mode != MT_CIPHER_BIP_CMAC_128 &&
 	    !(rxd2 & (MT_RXD2_NORMAL_CLM | MT_RXD2_NORMAL_CM))) {
 		status->flag |= RX_FLAG_DECRYPTED;
 		status->flag |= RX_FLAG_IV_STRIPPED;
@@ -427,7 +430,7 @@ static int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb)
 		u8 *data = (u8 *)rxd;
 
 		if (status->flag & RX_FLAG_DECRYPTED) {
-			switch (FIELD_GET(MT_RXD2_NORMAL_SEC_MODE, rxd2)) {
+			switch (sec_mode) {
 			case MT_CIPHER_AES_CCMP:
 			case MT_CIPHER_CCMP_CCX:
 			case MT_CIPHER_CCMP_256:
Signature · 1 line
2.47.3
author maintainer
#7 lore raw

PATCH 8/20 wifi: mt76: mt7925: use wcid_to_sta() in mt7925_mac_write_txwi_8023()

In reply to Felix Fietkau

mt7925_mac_write_txwi_8023() gets the station from the wcid with container_of(). This is only valid for the wcid at the start of struct mt792x_sta. The wcid of any other link of an MLO station is part of a separately allocated struct mt792x_link_sta. For such a wcid, the function reads sta->wme from memory in front of that allocation.

Use wcid_to_sta(), which follows wcid->def_wcid, like mt76_connac_pm_dequeue_skbs() does.

This is currently not reachable. mac80211 queues every 802.3 encapsulated frame of a station to a TXQ. The TXQs name the wcid at the start of struct mt792x_sta until mt7925_mac_sta_deflink_move() moves them to another link. That move does not happen, because mt7925_can_activate_links() keeps the default link of a station interface active, and an AP MLD on mt7925 has one link. Found by inspection.

---
 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 cc8ea0d37430..1adec01f6832 100644
@@ -686,7 +686,7 @@ mt7925_mac_write_txwi_8023(__le32 *txwi, struct sk_buff *skb,
 	if (wcid->sta) {
 		struct ieee80211_sta *sta;
 
-		sta = container_of((void *)wcid, struct ieee80211_sta, drv_priv);
+		sta = wcid_to_sta(wcid);
 		wmm = sta->wme;
 	}
 
Signature · 1 line
2.47.3
author maintainer
#8 lore raw

PATCH 9/20 wifi: mt76: log the firmware status of a failed MCU command

In reply to Felix Fietkau

mt7996 and the connac drivers turn a firmware status into an error without a log line. The kernel log thus does not show which command failed.

Log the command, its sequence number and the status, rate limited. Do not log the WLAN failure status of the connac drivers. The firmware also returns it for the deactivation of an inactive BSS.

---
 drivers/net/wireless/mediatek/mt76/mt7615/mcu.c      |  3 ++-
 drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h |  6 +++++-
 drivers/net/wireless/mediatek/mt76/mt7921/mcu.c      |  3 ++-
 drivers/net/wireless/mediatek/mt76/mt7925/mcu.c      |  3 ++-
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c      | 10 ++++++++--
 5 files changed, 19 insertions(+), 6 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/mcu.c +2 -1
index 1aa3380d8baf..3b4982660e61 100644
@@ -178,7 +178,8 @@ int mt7615_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 			return -EMSGSIZE;
 		skb_pull(skb, sizeof(*rxd));
 		event = (struct mt76_connac_mcu_uni_event *)skb->data;
-		ret = mt76_connac_mcu_status_err(le32_to_cpu(event->status));
+		ret = mt76_connac_mcu_status_err(mdev, cmd, seq,
+						 le32_to_cpu(event->status));
 	} else if (cmd == MCU_CE_QUERY(REG_READ)) {
 		struct mt76_connac_mcu_reg_event *event;
 
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h +5 -1
index cac47c8702e3..a39f90eeb1c2 100644
@@ -1961,7 +1961,7 @@ mt76_connac_mcu_get_wlan_idx(struct mt76_dev *dev, struct mt76_wcid *wcid,
 #define MT76_CONNAC_MCU_STATUS_WLAN_FAILURE	0xc0000001
 
 static inline int
-mt76_connac_mcu_status_err(u32 status)
+mt76_connac_mcu_status_err(struct mt76_dev *mdev, int cmd, int seq, u32 status)
 {
 	if (!status)
 		return 0;
@@ -1969,6 +1969,10 @@ mt76_connac_mcu_status_err(u32 status)
 	if (status == MT76_CONNAC_MCU_STATUS_WLAN_FAILURE)
 		return -ENOLINK;
 
+	dev_warn_ratelimited(mdev->dev,
+			     "Message %08x (seq %d) failed: firmware status 0x%x\n",
+			     cmd, seq, status);
+
 	return -EREMOTEIO;
 }
 
drivers/net/wireless/mediatek/mt76/mt7921/mcu.c +2 -1
index d973dea103db..77d3c07486cb 100644
@@ -66,7 +66,8 @@ int mt7921_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 		if (mcu_cmd != event->cid)
 			ret = -EAGAIN;
 		else
-			ret = mt76_connac_mcu_status_err(le32_to_cpu(event->status));
+			ret = mt76_connac_mcu_status_err(mdev, cmd, seq,
+							 le32_to_cpu(event->status));
 	} else if (cmd == MCU_CE_QUERY(REG_READ)) {
 		struct mt76_connac_mcu_reg_event *event;
 
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +2 -1
index 5514a5284af4..6afeb326e901 100644
@@ -81,7 +81,8 @@ int mt7925_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 		if (mcu_cmd != event->cid)
 			ret = -EAGAIN;
 		else
-			ret = mt76_connac_mcu_status_err(le32_to_cpu(event->status));
+			ret = mt76_connac_mcu_status_err(mdev, cmd, seq,
+							 le32_to_cpu(event->status));
 	} else {
 		skb_pull(skb, sizeof(*rxd));
 	}
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +8 -2
index ef48cad39d5e..33aace532222 100644
@@ -224,6 +224,7 @@ mt7996_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 	struct mt7996_mcu_uni_event *event;
 	int mcu_cmd = FIELD_GET(__MCU_CMD_FIELD_ID, cmd);
 	int ret = 0;
+	u32 status;
 
 	if (!skb) {
 		dev_err(mdev->dev, "Message %08x (seq %d) timeout\n",
@@ -258,11 +259,16 @@ mt7996_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 
 		skb_pull(skb, sizeof(*rxd));
 		event = (struct mt7996_mcu_uni_event *)skb->data;
+		status = le32_to_cpu(event->status);
 		/* skip invalid event */
-		if (mcu_cmd != le16_to_cpu(event->cid))
+		if (mcu_cmd != le16_to_cpu(event->cid)) {
 			ret = -EAGAIN;
-		else if (le32_to_cpu(event->status))
+		} else if (status) {
+			dev_warn_ratelimited(mdev->dev,
+					     "Message %08x (seq %d) cid %04x failed: firmware status 0x%x\n",
+					     cmd, seq, mcu_cmd, status);
 			ret = -EREMOTEIO;
+		}
 	} else {
 		skb_pull(skb, sizeof(struct mt7996_mcu_rxd));
 	}
Signature · 1 line
2.47.3
author maintainer
#9 lore raw

PATCH 10/20 wifi: mt76: mt7996: clear the ADM counters only in the airtime poll

In reply to Felix Fietkau

The driver clears the ADM counters of a WTBL entry with a read-modify-write of MT_WTBL_UPDATE. It does so at each vif link add, station link add and MLD link removal, and for every entry in mt7996_mac_init(). The WM firmware writes the same register at any time for its own WTBL updates. A host write that meets one in progress can change the entry or the word of that update.

Leave these clears to the firmware. It clears the counters of each entry at every WM start and at a station disconnect. At the MLD teardown it clears them for every link wcid of the peer group, which also holds a link that the driver removed earlier. A link that comes back keeps its wcid and its last read, and a new station link starts from a last read of 0.

Keep the clear of mt7996_mac_sta_poll() before a counter overflows, since nothing else clears the counters while a station stays connected. That clear keeps the race. The reads of the poll through the WTBL window keep a similar race on the window register.

Fixes 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices")
---
 drivers/net/wireless/mediatek/mt76/mt7996/init.c | 4 ----
 drivers/net/wireless/mediatek/mt76/mt7996/main.c | 6 +-----
 2 files changed, 1 insertion(+), 9 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/init.c +0 -4
index a6168f36794f..e82bc9cbc59e 100644
@@ -626,10 +626,6 @@ void mt7996_mac_init(struct mt7996_dev *dev)
 
 	mt76_clear(dev, MT_MDP_DCR2, MT_MDP_DCR2_RX_TRANS_SHORT);
 
-	for (i = 0; i < mt7996_wtbl_size(dev); i++)
-		mt7996_mac_wtbl_update(dev, i,
-				       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
-
 	if (IS_ENABLED(CONFIG_MT76_LEDS)) {
 		i = dev->mphy.leds.pin ? MT_LED_GPIO_MUX3 : MT_LED_GPIO_MUX2;
 		mt76_rmw_field(dev, i, MT_LED_GPIO_SEL_MASK, 4);
drivers/net/wireless/mediatek/mt76/mt7996/main.c +1 -5
index e883a58844e9..f2bc33db35fb 100644
@@ -450,8 +450,6 @@ int mt7996_vif_link_add(struct mt76_phy *mphy, struct ieee80211_vif *vif,
 	msta_link->wcid.tx_info |= MT_WCID_TX_INFO_SET;
 	mt76_wcid_init(&msta_link->wcid, band_idx);
 
-	mt7996_sta_link_airtime_clear(dev, msta_link);
-
 	if (vif->type != NL80211_IFTYPE_AP &&
 	    (!mlink->omac_idx || mlink->omac_idx > 3))
 		vif->offload_flags = 0;
@@ -1363,7 +1361,7 @@ mt7996_mac_sta_init_link(struct mt7996_dev *dev,
 
 	rcu_assign_pointer(msta->link[link_id], msta_link);
 
-	mt7996_sta_link_airtime_clear(dev, msta_link);
+	memset(msta_link->airtime_ac, 0, sizeof(msta_link->airtime_ac));
 
 	rcu_assign_pointer(dev->mt76.wcid[idx], &msta_link->wcid);
 	mt76_wcid_init(&msta_link->wcid, phy->mt76->band_idx);
@@ -1397,8 +1395,6 @@ void mt7996_mac_sta_remove_link(struct mt7996_dev *dev,
 	mt76_wcid_cleanup(&dev->mt76, &msta_link->wcid);
 
 	if (msta_link->wcid.link_valid) {
-		mt7996_sta_link_airtime_clear(dev, msta_link);
-
 		mt7996_sta_deflink_release(dev, sta, link_id);
 		msta_link->wcid.link_valid = false;
 		/* the firmware keeps the link pair of its last MLD setup */
Signature · 1 line
2.47.3
author maintainer
#10 lore raw

PATCH 11/20 wifi: mt76: mt7915: send mt7981 only the group units its firmware holds

In reply to Felix Fietkau

Since the mt7981 group pre-calibration size follows the vendor flash layout, mt7915_mcu_apply_group_cal() sends 144 units of 1024 bytes on mt7981. The group store of the mt7981 firmware holds 94 units, as on mt7986. Its handler checks neither the index nor the length of a chunk.

The units with index 94 to 143 thus overwrite 50 KiB of firmware memory behind the store. This happens at each probe of a board with group pre-calibration data.

Send only the units that the firmware stores. Keep the trailer and the DPD data at their offsets of the flash layout.

Fixes 2b660ee10a0c ("wifi: mt76: mt7915: fix mt7981 pre-calibration")
---
 .../wireless/mediatek/mt76/mt7915/eeprom.h    |  2 ++
 .../net/wireless/mediatek/mt76/mt7915/mcu.c   | 28 ++++++++++---------
 2 files changed, 17 insertions(+), 13 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h +2 -0
index 1dc285c72991..bfba4fce3f6d 100644
@@ -51,6 +51,8 @@ enum mt7915_eeprom_field {
 #define MT_EE_CAL_GROUP_SIZE_7976		(94 * MT_EE_CAL_UNIT + 16)
 #define MT_EE_CAL_GROUP_SIZE_7916_6G		(94 * MT_EE_CAL_UNIT + 16)
 #define MT_EE_CAL_GROUP_SIZE_7981		(144 * MT_EE_CAL_UNIT + 16)
+/* the mt7981 firmware stores fewer group units than its flash layout holds */
+#define MT_EE_CAL_GROUP_FW_UNITS_7981		94
 #define MT_EE_CAL_DPD_SIZE_V1			(54 * MT_EE_CAL_UNIT)
 #define MT_EE_CAL_DPD_SIZE_V2			(300 * MT_EE_CAL_UNIT)
 
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +15 -13
index 02426feb6182..e9a10606c6aa 100644
@@ -3105,33 +3105,35 @@ static int mt7915_mcu_set_pre_cal(struct mt7915_dev *dev, u8 idx,
 
 int mt7915_mcu_apply_group_cal(struct mt7915_dev *dev)
 {
-	u8 idx = 0, *cal = dev->cal, *eep = dev->mt76.eeprom.data;
-	u32 total = mt7915_get_cal_group_size(dev);
+	u8 idx, units, *cal = dev->cal, *eep = dev->mt76.eeprom.data;
+	u32 size = mt7915_get_cal_group_size(dev);
 	u32 offs = is_mt7915(&dev->mt76) ? MT_EE_DO_PRE_CAL : MT_EE_DO_PRE_CAL_V2;
+	u32 trailer = size % MT_EE_CAL_UNIT;
+	int ret;
 
 	if (!(eep[offs] & MT_EE_WIFI_CAL_GROUP))
 		return 0;
 
+	units = size / MT_EE_CAL_UNIT;
+	if (is_mt7981(&dev->mt76))
+		units = MT_EE_CAL_GROUP_FW_UNITS_7981;
+
 	/*
 	 * Items: Rx DCOC, RSSI DCOC, Tx TSSI DCOC, Tx LPFG
 	 * Tx FDIQ, Tx DCIQ, Rx FDIQ, Rx FIIQ, ADCDCOC
 	 */
-	while (total > 0) {
-		int ret, len;
-
-		len = min_t(u32, total, MT_EE_CAL_UNIT);
-
-		ret = mt7915_mcu_set_pre_cal(dev, idx, cal, len,
+	for (idx = 0; idx < units; idx++) {
+		ret = mt7915_mcu_set_pre_cal(dev, idx,
+					     cal + idx * MT_EE_CAL_UNIT,
+					     MT_EE_CAL_UNIT,
 					     MCU_EXT_CMD(GROUP_PRE_CAL_INFO));
 		if (ret)
 			return ret;
-
-		total -= len;
-		cal += len;
-		idx++;
 	}
 
-	return 0;
+	/* the trailer follows all units of the flash layout */
+	return mt7915_mcu_set_pre_cal(dev, idx, cal + size - trailer, trailer,
+				      MCU_EXT_CMD(GROUP_PRE_CAL_INFO));
 }
 
 static int mt7915_find_freq_idx(const u16 *freqs, int n_freqs, u16 cur)
Signature · 1 line
2.47.3
Tested-by on v1 11/20
#11 lore raw

Re: [PATCH mt76-next 11/20] wifi: mt76: mt7915: send mt7981 only the group units its firmware holds

Quoted 9 lines

Since the mt7981 group pre-calibration size follows the vendor flash layout, mt7915_mcu_apply_group_cal() sends 144 units of 1024 bytes on mt7981. The group store of the mt7981 firmware holds 94 units, as on mt7986. Its handler checks neither the index nor the length of a chunk.

The units with index 94 to 143 thus overwrite 50 KiB of firmware memory behind the store. This happens at each probe of a board with group pre-calibration data.

Quoted 5 lines

Send only the units that the firmware stores. Keep the trailer and the DPD data at their offsets of the flash layout.

Fixes 2b660ee10a0c ("wifi: mt76: mt7915: fix mt7981 pre-calibration")

Hi Felix,

Tested on Zyxel NWA50AX Pro(MT7981)

Best regards,
Zhi-Jun

Signature · 1 line
Zhi-Jun You <[email protected]>
author maintainer
#12 lore raw

PATCH 12/20 wifi: mt76: take the DFS state from the off-channel flag

In reply to Felix Fietkau

mt76_phy_dfs_state() gives MT_DFS_STATE_DISABLED while MT76_SCANNING is set, which a software scan holds for its whole length. The scan end sets the operating channel before drv_sw_scan_complete() clears the bit. So a software scan on a DFS channel leaves the radar detector off. A remain-on-channel sets no such bit, so the detector follows the radio to the ROC channel.

Give MT_DFS_STATE_DISABLED where the current channel is off the operating chandef, which phy->offchannel records at each channel set. The return to the operating chandef then starts the detector again in the same channel set. On mt7996 the detector now keeps running during a hardware scan dwell on the operating chandef. During a ROC off a DFS channel it is off, until mt76_roc_complete() starts it again.

Fixes 3f3064486b1a ("mt76: mt7915: fix/rewrite the dfs state handling logic")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 3 +--
 drivers/net/wireless/mediatek/mt76/scan.c     | 4 ----
 2 files changed, 1 insertion(+), 6 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +1 -2
index 948f9ed26095..e554f2eea7cc 100644
@@ -2225,8 +2225,7 @@ enum mt76_dfs_state mt76_phy_dfs_state(struct mt76_phy *phy)
 	struct ieee80211_hw *hw = phy->hw;
 	struct mt76_dev *dev = phy->dev;
 
-	if (dev->region == NL80211_DFS_UNSET ||
-	    test_bit(MT76_SCANNING, &phy->state))
+	if (dev->region == NL80211_DFS_UNSET || phy->offchannel)
 		return MT_DFS_STATE_DISABLED;
 
 	if (!phy->radar_enabled) {
drivers/net/wireless/mediatek/mt76/scan.c +0 -4
index 51b182ee99e2..0a5fea9e7454 100644
@@ -28,10 +28,6 @@ static void mt76_scan_phy_complete(struct mt76_phy *phy, bool abort)
 
 	clear_bit(MT76_SCANNING, &phy->state);
 
-	/* Re-program the operating channel even when the scan never left it:
-	 * any channel set during the scan ran with MT76_SCANNING held, which
-	 * left DFS radar detection disabled
-	 */
 	if (phy->main_chandef.chan &&
 	    !test_bit(MT76_MCU_RESET, &dev->phy.state)) {
 		bool offchannel = phy->offchannel;
Signature · 1 line
2.47.3
author maintainer
#13 lore raw

PATCH 13/20 wifi: mt76: read roc_phy and roc_link once without the mutex

In reply to Felix Fietkau

mt7996_tx() tests mvif->roc_phy and roc_phy->roc_link without a lock and loads each field again for its use, and mt76_vif_cleanup() does the same with roc_phy. mt76_roc_complete() clears both fields under dev->mutex, so a second load can return NULL, which mt7996_tx() and mt76_vif_cleanup() then dereference. mt7996_vif_link_roc_abort() also loads roc_phy before it takes dev->mutex.

Load roc_phy once with READ_ONCE() outside dev->mutex, and store it with WRITE_ONCE(). It points to a phy, which lives as long as the device. Make roc_link an RCU pointer, since mt7996_tx() reads it under the RCU read lock and an offchannel link is freed with kfree_rcu().

A ROC of another interface can start on the phy between the two loads. mt7996_tx() thus takes the wcid only from a link of its own interface.

Fixes a8f424c1287c ("wifi: mt76: add multi-radio remain_on_channel functions")
Fixes 69d54ce7491d ("wifi: mt76: mt7996: switch to single multi-radio wiphy")
---
 drivers/net/wireless/mediatek/mt76/channel.c   | 14 +++++++-------
 drivers/net/wireless/mediatek/mt76/mac80211.c  |  6 ++++--
 drivers/net/wireless/mediatek/mt76/mt76.h      |  2 +-
 .../net/wireless/mediatek/mt76/mt7996/main.c   | 18 ++++++++++--------
 4 files changed, 22 insertions(+), 18 deletions(-)
drivers/net/wireless/mediatek/mt76/channel.c +7 -7
index db2d6dfc12a9..6d9ca6dfecb7 100644
@@ -394,14 +394,14 @@ mt76_vif_roc_phy(struct mt76_dev *dev, struct ieee80211_vif *vif)
 
 void mt76_roc_complete(struct mt76_phy *phy)
 {
-	struct mt76_vif_link *mlink = phy->roc_link;
+	struct mt76_vif_link *mlink = mt76_dereference(phy->roc_link, phy->dev);
 	struct mt76_dev *dev = phy->dev;
 
 	if (!phy->roc_vif)
 		return;
 
 	if (mlink && mlink->mvif->roc_phy == phy)
-		mlink->mvif->roc_phy = NULL;
+		WRITE_ONCE(mlink->mvif->roc_phy, NULL);
 	if (phy->chanctx && phy->main_chandef.chan && phy->offchannel &&
 	    !test_bit(MT76_MCU_RESET, &dev->phy.state)) {
 		__mt76_set_channel(phy, &phy->main_chandef, false);
@@ -409,7 +409,7 @@ void mt76_roc_complete(struct mt76_phy *phy)
 	} else {
 		phy->offchannel = false;
 	}
-	phy->roc_link = NULL;
+	rcu_assign_pointer(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))
@@ -475,18 +475,18 @@ int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 		goto restart_mac_work;
 	}
 
-	mlink->mvif->roc_phy = phy;
+	WRITE_ONCE(mlink->mvif->roc_phy, phy);
 	phy->roc_vif = vif;
-	phy->roc_link = mlink;
+	rcu_assign_pointer(phy->roc_link, mlink);
 
 	offchannel = mt76_offchannel_chandef(phy, chan, &chandef);
 	if (offchannel)
 		mt76_offchannel_notify(phy, true);
 	ret = __mt76_set_channel(phy, &chandef, offchannel);
 	if (ret) {
-		mlink->mvif->roc_phy = NULL;
+		WRITE_ONCE(mlink->mvif->roc_phy, NULL);
 		phy->roc_vif = NULL;
-		phy->roc_link = NULL;
+		rcu_assign_pointer(phy->roc_link, NULL);
 		mt76_put_vif_phy_link(phy, vif, mlink);
 		goto out;
 	}
drivers/net/wireless/mediatek/mt76/mac80211.c +4 -2
index e554f2eea7cc..a42a950c20cb 100644
@@ -2247,11 +2247,13 @@ void mt76_vif_cleanup(struct mt76_dev *dev, 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;
 
 	rcu_assign_pointer(mvif->link[0], NULL);
 	mt76_abort_scan(dev);
-	if (mvif->roc_phy && mvif->roc_phy->roc_vif == vif)
-		mt76_abort_roc(mvif->roc_phy);
+	phy = READ_ONCE(mvif->roc_phy);
+	if (phy && phy->roc_vif == vif)
+		mt76_abort_roc(phy);
 }
 EXPORT_SYMBOL_GPL(mt76_vif_cleanup);
 
drivers/net/wireless/mediatek/mt76/mt76.h +1 -1
index d82d22c14c9f..648f79c4b6d0 100644
@@ -887,7 +887,7 @@ struct mt76_phy {
 
 	struct delayed_work roc_work;
 	struct ieee80211_vif *roc_vif;
-	struct mt76_vif_link *roc_link;
+	struct mt76_vif_link __rcu *roc_link;
 
 	struct delayed_work scan_work;
 	struct {
drivers/net/wireless/mediatek/mt76/mt7996/main.c +10 -8
index f2bc33db35fb..c39e0ac9176c 100644
@@ -2140,17 +2140,19 @@ static void mt7996_tx(struct ieee80211_hw *hw,
 	}
 
 	if (mvif) {
-		struct mt76_vif_link *mlink;
+		struct mt76_vif_link *mlink, *roc_link;
+		struct mt76_phy *roc_phy;
 
 		mlink = rcu_dereference(mvif->mt76.link[link_id]);
 		if (mlink && mlink->wcid)
 			wcid = mlink->wcid;
 
-		if (mvif->mt76.roc_phy &&
-		    (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN)) {
-			mphy = mvif->mt76.roc_phy;
-			if (mphy->roc_link)
-				wcid = mphy->roc_link->wcid;
+		roc_phy = READ_ONCE(mvif->mt76.roc_phy);
+		if (roc_phy && (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN)) {
+			mphy = roc_phy;
+			roc_link = rcu_dereference(roc_phy->roc_link);
+			if (roc_link && roc_link->mvif == &mvif->mt76)
+				wcid = roc_link->wcid;
 		} else if (mlink) {
 			mphy = mt76_vif_link_phy(mlink);
 		}
@@ -3081,7 +3083,7 @@ static void
 mt7996_vif_link_roc_abort(struct mt7996_dev *dev, struct ieee80211_vif *vif)
 {
 	struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
-	struct mt76_phy *phy = mvif->mt76.roc_phy;
+	struct mt76_phy *phy = READ_ONCE(mvif->mt76.roc_phy);
 	struct mt76_vif_link *mlink;
 	bool abort;
 
@@ -3089,7 +3091,7 @@ mt7996_vif_link_roc_abort(struct mt7996_dev *dev, struct ieee80211_vif *vif)
 		return;
 
 	mutex_lock(&dev->mt76.mutex);
-	mlink = phy->roc_link;
+	mlink = mt76_dereference(phy->roc_link, &dev->mt76);
 	abort = phy->roc_vif == vif && mlink && !mlink->offchannel;
 	mutex_unlock(&dev->mt76.mutex);
 
Signature · 1 line
2.47.3
author maintainer
#14 lore raw

PATCH 14/20 wifi: mt76: mt7996: add only the active links of a station MLD's peer

In reply to Felix Fietkau

mt7996_mac_sta_add() adds a station link for every link in sta->valid_links. After a full reset, ieee80211_reconfig() replays a station-mode MLD interface with only its lowest active link and no vif link for the others. The add of the AP station, which still holds every link of the association, then fails, and mac80211 warns in ieee80211_reconfig_stations(). The peer gets no PEER_MLD_INFO, and when mac80211 activates the other links, the lowest link stays active without a STA_REC.

Add only the links that are both valid and active, as drv_change_sta_links() does. The other links come back through change_sta_links, as after a normal association. An AP interface has all of its links active, so the stations of an AP MLD keep every link. A TDLS peer on a link that is not active at the add now gets no link there. Before this change, the add failed.

Fixes ace5d3b6b49e ("wifi: mt76: mt7996: improve hardware restart reliability")
---
 drivers/net/wireless/mediatek/mt76/mt7996/main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +4 -1
index c39e0ac9176c..5676379b2ca1 100644
@@ -1528,9 +1528,12 @@ mt7996_mac_sta_add(struct mt7996_dev *dev, struct ieee80211_vif *vif,
 {
 	struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
 	struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
-	unsigned long links = sta->valid_links ? sta->valid_links : BIT(0);
+	unsigned long links = BIT(0);
 	int err;
 
+	if (sta->valid_links)
+		links = sta->valid_links & vif->active_links;
+
 	mutex_lock(&dev->mt76.mutex);
 
 	msta->deflink_id = IEEE80211_LINK_UNSPECIFIED;
Signature · 1 line
2.47.3
author maintainer
#15 lore raw

PATCH 15/20 wifi: mt76: mt7996: resume the radar TX stop at an operating channel set

In reply to Felix Fietkau

After a radar detection the firmware stops the data TX of every BSS of the band. mt7996_mcu_rdd_resume_tx() lifts the stop only after a completed channel switch announcement or when the last interface goes down. A radar hit during a CAC ends with a new channel context and no CSA. Stations then associate on the new channel, but no EAPOL frame leaves, and a station interface on the band loses its data as well.

Send the resume when the driver sets the band to an operating channel where no subchannel is unavailable after a radar detection. The MediaTek feed sends it at the same place in its channel set. An off-channel set for a scan or a ROC sends none, since the resume also lifts the station pause of the firmware scan state. A scan or ROC set on the operating channel sends it. A failed resume keeps phy->rdd_tx_paused set, so a later channel set, channel switch or the removal of the last interface sends it again. A chandef with an unavailable subchannel sends none, so the band does not transmit on the channel of the hit again.

The test misses the time from the detection event until the mac80211 radar work marks the channel unavailable. The radar work does that after it cancels the CAC.

Fixes 45a09251d610 ("wifi: mt76: mt7996: fix the behavior of radar detection")
---
 .../net/wireless/mediatek/mt76/mt7996/main.c  | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +35 -0
index 5676379b2ca1..65b5012a0017 100644
@@ -754,6 +754,32 @@ static void mt7996_remove_interface(struct ieee80211_hw *hw,
 	}
 }
 
+static bool mt7996_chan_unavailable(struct ieee80211_channel *chan)
+{
+	return chan && (chan->flags & IEEE80211_CHAN_RADAR) &&
+	       chan->dfs_state == NL80211_DFS_UNAVAILABLE;
+}
+
+static bool
+mt7996_chandef_unavailable(struct wiphy *wiphy,
+			   const struct cfg80211_chan_def *chandef)
+{
+	int center[] = { chandef->center_freq1, chandef->center_freq2 };
+	int width = cfg80211_chandef_get_width(chandef);
+	int i, freq;
+
+	for (i = 0; i < ARRAY_SIZE(center) && center[i]; i++) {
+		for (freq = center[i] - width / 2 + 10;
+		     freq < center[i] + width / 2; freq += 20) {
+			if (mt7996_chan_unavailable(ieee80211_get_channel(wiphy,
+									  freq)))
+				return true;
+		}
+	}
+
+	return false;
+}
+
 int mt7996_set_channel(struct mt76_phy *mphy)
 {
 	struct mt7996_phy *phy = mphy->priv;
@@ -778,6 +804,15 @@ int mt7996_set_channel(struct mt76_phy *mphy)
 	if (ret)
 		goto out;
 
+	if (!mphy->offchannel && mphy->chanctx &&
+	    !mt7996_chandef_unavailable(mphy->hw->wiphy, &mphy->chandef)) {
+		ret = mt7996_mcu_rdd_resume_tx(phy);
+		if (ret)
+			dev_warn_once(phy->dev->mt76.dev,
+				      "failed to resume TX after radar: %d\n",
+				      ret);
+	}
+
 	ret = mt7996_dfs_init_radar_detector(phy);
 	mt7996_mac_cca_stats_reset(phy);
 
Signature · 1 line
2.47.3
author maintainer
#16 lore raw

PATCH 16/20 wifi: mt76: mt7996: divide by the full TWT wake interval

In reply to Felix Fietkau

mt7996_mac_add_twt_setup() passes the 64-bit wake interval of a TWT request as the 32-bit divisor of div_u64_rem(). An interval that is a multiple of 2^32 us thus gives a division by zero, which traps on x86 with the driver mutex held.

Any device in range can trigger this with one TWT Setup frame. The frame is not robust, so it is accepted with the address of any associated station. Neither mac80211 nor mt7996_mac_check_twt_req() bounds the exponent or the mantissa.

Divide by the full interval with div64_u64_rem().

Fixes 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices")
---
 drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +2 -3
index 229f797f4302..d724ac425b42 100644
@@ -3369,13 +3369,12 @@ void mt7996_mac_add_twt_setup(struct ieee80211_hw *hw,
 	if (sta_setup_cmd == TWT_SETUP_CMD_REQUEST ||
 	    sta_setup_cmd == TWT_SETUP_CMD_SUGGEST) {
 		u64 interval = (u64)le16_to_cpu(twt_agrt->mantissa) << exp;
-		u64 flow_tsf, curr_tsf;
-		u32 rem;
+		u64 flow_tsf, curr_tsf, rem;
 
 		flow->sched = true;
 		flow->start_tsf = mt7996_mac_twt_sched_list_add(dev, flow);
 		curr_tsf = __mt7996_get_tsf(hw, &msta->vif->deflink);
-		div_u64_rem(curr_tsf - flow->start_tsf, interval, &rem);
+		div64_u64_rem(curr_tsf - flow->start_tsf, interval, &rem);
 		flow_tsf = curr_tsf + interval - rem;
 		twt_agrt->twt = cpu_to_le64(flow_tsf);
 	} else {
Signature · 1 line
2.47.3
author maintainer
#17 lore raw

PATCH 17/20 wifi: mt76: mt7915: divide by the full TWT wake interval

In reply to Felix Fietkau

mt7915_mac_add_twt_setup() passes the 64-bit wake interval of a TWT request as the 32-bit divisor of div_u64_rem(). An interval that is a multiple of 2^32 us thus gives a division by zero, which traps on x86 with the driver mutex held.

Any device in range can trigger this with one TWT Setup frame. The frame is not robust, so it is accepted with the address of any associated station. Neither mac80211 nor mt7915_mac_check_twt_req() bounds the exponent or the mantissa.

Divide by the full interval with div64_u64_rem().

Fixes 3782b69d03e7 ("mt76: mt7915: introduce mt7915_mac_add_twt_setup routine")
---
 drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +2 -3
index b7f86195af2d..d444073af4ea 100644
@@ -2380,13 +2380,12 @@ void mt7915_mac_add_twt_setup(struct ieee80211_hw *hw,
 	if (sta_setup_cmd == TWT_SETUP_CMD_REQUEST ||
 	    sta_setup_cmd == TWT_SETUP_CMD_SUGGEST) {
 		u64 interval = (u64)le16_to_cpu(twt_agrt->mantissa) << exp;
-		u64 flow_tsf, curr_tsf;
-		u32 rem;
+		u64 flow_tsf, curr_tsf, rem;
 
 		flow->sched = true;
 		flow->start_tsf = mt7915_mac_twt_sched_list_add(dev, flow);
 		curr_tsf = __mt7915_get_tsf(hw, msta->vif);
-		div_u64_rem(curr_tsf - flow->start_tsf, interval, &rem);
+		div64_u64_rem(curr_tsf - flow->start_tsf, interval, &rem);
 		flow_tsf = curr_tsf + interval - rem;
 		twt_agrt->twt = cpu_to_le64(flow_tsf);
 	} else {
Signature · 1 line
2.47.3
author maintainer
#18 lore raw

PATCH 18/20 wifi: mt76: mt7996: send the SRG bitmaps in one block per band

In reply to Felix Fietkau

mt7996_mcu_set_obss_spr_bitmap() sends the SRG BSS colour and partial BSSID bitmaps as four arrays of two words, indexed by band. The firmware expects one block of four words for each of the three bands and refuses the shorter TLV, so no SRG bitmap reaches the hardware. On band 2 the driver also writes past the request on the stack. Reachable via mt7996_link_info_changed() for an enabled spatial reuse parameter set, with the sr_scene_detect module parameter off.

Send one block per band, holding the colour bitmap and then the partial BSSID bitmap, and fill the block of the band, like the other per-band arrays in mcu.h that take __MT_MAX_BAND entries.

Fixes cf6dc2db17fe ("wifi: mt76: mt7996: add support to configure spatial reuse parameter set")
---
 .../net/wireless/mediatek/mt76/mt7996/mcu.c    | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +10 -8
index 33aace532222..28f932fe049e 100644
@@ -5301,10 +5301,12 @@ mt7996_mcu_set_obss_spr_bitmap(struct mt7996_phy *phy,
 		__le16 tag;
 		__le16 len;
 
-		__le32 color_l[2];
-		__le32 color_h[2];
-		__le32 bssid_l[2];
-		__le32 bssid_h[2];
+		struct {
+			__le32 color_l;
+			__le32 color_h;
+			__le32 bssid_l;
+			__le32 bssid_h;
+		} __packed spr_bitmap[__MT_MAX_BAND];
 	} __packed req = {
 		.band_idx = phy->mt76->band_idx,
 		.tag = cpu_to_le16(UNI_CMD_SR_SET_SRG_BITMAP),
@@ -5313,16 +5315,16 @@ mt7996_mcu_set_obss_spr_bitmap(struct mt7996_phy *phy,
 	u32 bitmap;
 
 	memcpy(&bitmap, he_obss_pd->bss_color_bitmap, sizeof(bitmap));
-	req.color_l[req.band_idx] = cpu_to_le32(bitmap);
+	req.spr_bitmap[req.band_idx].color_l = cpu_to_le32(bitmap);
 
 	memcpy(&bitmap, he_obss_pd->bss_color_bitmap + 4, sizeof(bitmap));
-	req.color_h[req.band_idx] = cpu_to_le32(bitmap);
+	req.spr_bitmap[req.band_idx].color_h = cpu_to_le32(bitmap);
 
 	memcpy(&bitmap, he_obss_pd->partial_bssid_bitmap, sizeof(bitmap));
-	req.bssid_l[req.band_idx] = cpu_to_le32(bitmap);
+	req.spr_bitmap[req.band_idx].bssid_l = cpu_to_le32(bitmap);
 
 	memcpy(&bitmap, he_obss_pd->partial_bssid_bitmap + 4, sizeof(bitmap));
-	req.bssid_h[req.band_idx] = cpu_to_le32(bitmap);
+	req.spr_bitmap[req.band_idx].bssid_h = cpu_to_le32(bitmap);
 
 	return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(SR), &req,
 				 sizeof(req), true);
Signature · 1 line
2.47.3
author maintainer
#19 lore raw

PATCH 19/20 wifi: mt76: connac: set the band of an RX block ack scoreboard reset

In reply to Felix Fietkau

mt76_connac_mcu_wtbl_ba_tlv() leaves band_idx of the recipient WTBL_BA TLV at 0. The firmware takes the band of the RX block ack scoreboard reset from this field alone. A session start or stop of a station on band 1 thus resets the scoreboard entry of band 0. The entry on band 1 gets no reset.

Reachable via mt7915_ampdu_action() for every station of a band 1 phy.

Pass the band of the station's interface with the TLV. mt7615 keeps band 0, because its firmware's use of the field is not known.

Fixes e57b7901469f ("mt76: add mac80211 driver for MT7915 PCIe-based chipsets")
---
 drivers/net/wireless/mediatek/mt76/mt7615/mcu.c      | 8 ++++----
 drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c | 9 +++++----
 drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h | 4 ++--
 3 files changed, 11 insertions(+), 10 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/mcu.c +4 -4
index 3b4982660e61..e31fb63a5562 100644
@@ -796,7 +796,7 @@ mt7615_mcu_wtbl_tx_ba(struct mt7615_dev *dev,
 		return PTR_ERR(wtbl_hdr);
 
 	mt76_connac_mcu_wtbl_ba_tlv(&dev->mt76, skb, params, enable, true,
-				    NULL, wtbl_hdr);
+				    0, NULL, wtbl_hdr);
 
 	err = mt76_mcu_skb_send_msg(&dev->mt76, skb,
 				    MCU_EXT_CMD(WTBL_UPDATE), true);
@@ -844,7 +844,7 @@ mt7615_mcu_wtbl_rx_ba(struct mt7615_dev *dev,
 		return PTR_ERR(wtbl_hdr);
 
 	mt76_connac_mcu_wtbl_ba_tlv(&dev->mt76, skb, params, enable, false,
-				    NULL, wtbl_hdr);
+				    0, NULL, wtbl_hdr);
 
 	return mt76_mcu_skb_send_msg(&dev->mt76, skb,
 				     MCU_EXT_CMD(WTBL_UPDATE), true);
@@ -967,7 +967,7 @@ mt7615_mcu_sta_ba(struct mt7615_dev *dev,
 		return PTR_ERR(wtbl_hdr);
 
 	mt76_connac_mcu_wtbl_ba_tlv(&dev->mt76, skb, params, enable, tx,
-				    sta_wtbl, wtbl_hdr);
+				    0, sta_wtbl, wtbl_hdr);
 
 	return mt76_mcu_skb_send_msg(&dev->mt76, skb,
 				     MCU_EXT_CMD(STA_REC_UPDATE), true);
@@ -1201,7 +1201,7 @@ mt7615_mcu_uni_rx_ba(struct mt7615_dev *dev,
 		return PTR_ERR(wtbl_hdr);
 
 	mt76_connac_mcu_wtbl_ba_tlv(&dev->mt76, skb, params, enable, false,
-				    sta_wtbl, wtbl_hdr);
+				    0, sta_wtbl, wtbl_hdr);
 
 	return mt76_mcu_skb_send_msg(&dev->mt76, skb,
 				     MCU_UNI_CMD(STA_REC_UPDATE), true);
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +5 -4
index ce1b4ed5e0d1..a250007101d5 100644
@@ -1148,8 +1148,8 @@ EXPORT_SYMBOL_GPL(mt76_connac_mcu_sta_cmd);
 
 void mt76_connac_mcu_wtbl_ba_tlv(struct mt76_dev *dev, struct sk_buff *skb,
 				 struct ieee80211_ampdu_params *params,
-				 bool enable, bool tx, void *sta_wtbl,
-				 void *wtbl_tlv)
+				 bool enable, bool tx, u8 band_idx,
+				 void *sta_wtbl, void *wtbl_tlv)
 {
 	struct wtbl_ba *ba;
 	struct tlv *tlv;
@@ -1171,6 +1171,7 @@ void mt76_connac_mcu_wtbl_ba_tlv(struct mt76_dev *dev, struct sk_buff *skb,
 		ba->rst_ba_tid = params->tid;
 		ba->rst_ba_sel = RST_BA_MAC_TID_MATCH;
 		ba->rst_ba_sb = 1;
+		ba->band_idx = band_idx;
 	}
 
 	if (!is_connac_v1(dev)) {
@@ -1357,8 +1358,8 @@ int mt76_connac_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif_link *mvif,
 	if (IS_ERR(wtbl_hdr))
 		return PTR_ERR(wtbl_hdr);
 
-	mt76_connac_mcu_wtbl_ba_tlv(dev, skb, params, enable, tx, sta_wtbl,
-				    wtbl_hdr);
+	mt76_connac_mcu_wtbl_ba_tlv(dev, skb, params, enable, tx,
+				    mvif->band_idx, sta_wtbl, wtbl_hdr);
 
 	ret = mt76_connac_mcu_sta_wed_update(dev, skb);
 	if (ret) {
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h +2 -2
index a39f90eeb1c2..c5fb7e2adab1 100644
@@ -2053,8 +2053,8 @@ void mt76_connac_mcu_wtbl_ht_tlv(struct mt76_dev *dev, struct sk_buff *skb,
 				 void *wtbl_tlv, bool ht_ldpc, bool vht_ldpc);
 void mt76_connac_mcu_wtbl_ba_tlv(struct mt76_dev *dev, struct sk_buff *skb,
 				 struct ieee80211_ampdu_params *params,
-				 bool enable, bool tx, void *sta_wtbl,
-				 void *wtbl_tlv);
+				 bool enable, bool tx, u8 band_idx,
+				 void *sta_wtbl, void *wtbl_tlv);
 void mt76_connac_mcu_sta_ba_tlv(struct sk_buff *skb,
 				struct ieee80211_ampdu_params *params,
 				bool enable, bool tx);
Signature · 1 line
2.47.3
author maintainer
#20 lore raw

PATCH 20/20 wifi: mt76: mt7915: reset the CCA statistics of band 1 on mt7916

In reply to Felix Fietkau

mt7915_mac_cca_stats_reset() takes MT_WF_PHY_RX_CTRL1() on every chip, which spaces the bands 0x10000 apart as on MT7915. On mt7916, mt7981 and mt7986 the bands are 0x100000 apart.

A channel set of band 1 thus writes the statistics enable bits into a band 0 register. That register lies outside the RX control block. The restart of the band 1 counters at a channel set does not reach the band 1 register.

Use the MT7916 register form on the chips other than MT7915, as mt7915_mac_enable_nf() does.

Fixes 2e30db0dde61 ("mt76: mt7915: add device id for mt7916")
---
 drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +4 -1
index d444073af4ea..e9b1704d1289 100644
@@ -1099,8 +1099,11 @@ void mt7915_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
 void mt7915_mac_cca_stats_reset(struct mt7915_phy *phy)
 {
 	struct mt7915_dev *dev = phy->dev;
-	u32 reg = MT_WF_PHY_RX_CTRL1(phy->mt76->band_idx);
+	u8 band = phy->mt76->band_idx;
+	u32 reg;
 
+	reg = is_mt7915(&dev->mt76) ? MT_WF_PHY_RX_CTRL1(band) :
+				      MT_WF_PHY_RX_CTRL1_MT7916(band);
 	mt76_clear(dev, reg, MT_WF_PHY_RX_CTRL1_STSCNT_EN);
 	mt76_set(dev, reg, BIT(11) | BIT(9));
 }
Signature · 1 line
2.47.3