Skip to contentSkip to conversation

wifi: mt76: mt7925: keep the RX PN state of a station across a rekey

PATCH New Felix Fietkau 1 participant 18 messages Nov 25

Subsystems (2)
lore
Share & tools
lore

Felix Fietkau

author maintainer
#0 lore raw

PATCH 1/18 wifi: mt76: mt7925: keep the RX PN state of a station across a rekey

At a PTK rekey, mac80211 removes the old key before it sets the new one. mt7925_set_link_key() clears rx_check_pn at the removal of the old key. Until the new key arrives, mt76_check_ccmp_pn() thus skips the replay check for a frame that the hardware still decrypts.

Keep rx_check_pn of a station until its next key, like mt7996 does.

Fixes c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")
---
 drivers/net/wireless/mediatek/mt76/mt7925/main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +3 -3
index b7348e6f0290..c26d9982650f 100644
@@ -804,11 +804,11 @@ static int mt7925_set_link_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 	else
 		goto out;
 
-	if (sta)
-		mt76_wcid_key_link_setup(wcid, cmd == SET_KEY ? key : NULL);
-	else
+	if (!sta)
 		mt76_wcid_key_setup(&dev->mt76, wcid,
 				    cmd == SET_KEY ? key : NULL);
+	else if (cmd == SET_KEY)
+		mt76_wcid_key_link_setup(wcid, key);
 
 	err = mt7925_mcu_add_key(&dev->mt76, vif, &mlink->bip,
 				 key, MCU_UNI_CMD(STA_REC_UPDATE),
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 2/18 wifi: mt76: mt7915: hold the rate update of a station in power save

At each STA_REC_RA the firmware clears every stop reason of the TX queue of the wlan index. It also clears the power save reason, and it stops the queue again only at the next enter. mt7915_mac_sta_rc_work() sends STA_REC_RA for a sleeping station too, so its frames go out while it sleeps and are lost. Reachable via a channel width change, an Operating Mode Notification and mt7915_set_bitrate_mask().

Keep the update of a station in power save in the work. Send it when the PS state clears: at the leave, a TWT add or an L1 recovery. An SMPS change of a sleeping station waits too.

While the update waits, PS-Poll and U-APSD deliveries use the old rate state. Whether the hardware limits the width to the channel is not read. A fixed rate from user space reaches a sleeping station at its wake. An enter that the host did not see before the send can still restart the queue once.

Fixes e57b7901469f ("mt76: add mac80211 driver for MT7915 PCIe-based chipsets")
---
 .../net/wireless/mediatek/mt76/mt7915/mac.c   | 27 ++++++++++++++++++-
 .../net/wireless/mediatek/mt76/mt7915/mcu.c   |  4 +--
 .../wireless/mediatek/mt76/mt7915/mt7915.h    |  2 ++
 3 files changed, 30 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +26 -1
index 84f75526da58..e458661d750b 100644
@@ -1524,7 +1524,7 @@ mt7915_mac_reset_sta_ps(struct mt7915_dev *dev)
 		    !test_bit(MT_WCID_FLAG_PS, &wcid->flags))
 			continue;
 
-		mt76_sta_ps_transition(&dev->mt76, wcid, false);
+		mt7915_mac_sta_ps_transition(dev, wcid, false);
 	}
 	rcu_read_unlock();
 }
@@ -2074,6 +2074,10 @@ void mt7915_mac_sta_rc_work(struct work_struct *work)
 	while (!list_empty(&list)) {
 		msta = list_first_entry(&list, struct mt7915_sta, rc_list);
 		list_del_init(&msta->rc_list);
+
+		if (test_bit(MT_WCID_FLAG_PS, &msta->wcid.flags))
+			continue;
+
 		changed = msta->changed;
 		msta->changed = 0;
 		spin_unlock_bh(&dev->mt76.sta_poll_lock);
@@ -2097,6 +2101,27 @@ void mt7915_mac_sta_rc_work(struct work_struct *work)
 	mutex_unlock(&dev->mt76.mutex);
 }
 
+void mt7915_mac_sta_ps_transition(struct mt7915_dev *dev,
+				  struct mt76_wcid *wcid, bool ps)
+{
+	struct mt7915_sta *msta = container_of(wcid, struct mt7915_sta, wcid);
+	bool held;
+
+	mt76_sta_ps_transition(&dev->mt76, wcid, ps);
+	if (ps)
+		return;
+
+	spin_lock_bh(&dev->mt76.sta_poll_lock);
+	held = msta->changed && list_empty(&msta->rc_list);
+	if (held)
+		list_add_tail(&msta->rc_list, &dev->sta_rc_list);
+	spin_unlock_bh(&dev->mt76.sta_poll_lock);
+
+	if (held)
+		ieee80211_queue_work(mt76_phy_hw(&dev->mt76, wcid->phy_idx),
+				     &dev->rc_work);
+}
+
 void mt7915_mac_work(struct work_struct *work)
 {
 	struct mt7915_phy *phy;
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +2 -2
index 59042d043481..bb71e6437a62 100644
@@ -456,11 +456,11 @@ mt7915_mcu_rx_ps_sync(struct mt7915_dev *dev, struct sk_buff *skb)
 
 	if (path == MT7915_PS_SYNC_TWT || path == MT7915_PS_SYNC_TWT_MANY) {
 		if (ps)
-			mt76_sta_ps_transition(&dev->mt76, wcid, false);
+			mt7915_mac_sta_ps_transition(dev, wcid, false);
 		return;
 	}
 
-	mt76_sta_ps_transition(&dev->mt76, wcid, ps);
+	mt7915_mac_sta_ps_transition(dev, wcid, ps);
 }
 
 static void
drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h +2 -0
index cab0ed54ca84..42a59f9e3ba1 100644
@@ -613,6 +613,8 @@ void mt7915_mac_work(struct work_struct *work);
 void mt7915_mac_reset_work(struct work_struct *work);
 void mt7915_mac_dump_work(struct work_struct *work);
 void mt7915_mac_sta_rc_work(struct work_struct *work);
+void mt7915_mac_sta_ps_transition(struct mt7915_dev *dev,
+				  struct mt76_wcid *wcid, bool ps);
 void mt7915_mac_update_stats(struct mt7915_phy *phy);
 void mt7915_mac_twt_teardown_flow(struct mt7915_dev *dev,
 				  struct mt7915_sta *msta,
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH 3/18 wifi: mt76: mt7996: take the phy of a fixed rate from the station link

In reply to Felix Fietkau

mt7996_link_sta_fixed_rate_set() dereferenced the phy of link 0, which is NULL on an MLD that never had link 0. Commit 5806c91a3f0d ("wifi:
mt76: mt7996: Remove unnecessary phy filed in mt7996_vif_link struct") made it a refusal. Since then, an AP MLD that removed its link 0 refuses the fixed rate of each station link.

Take the phy of the interface link that the station link belongs to, like mt7996_sta_hw_queue_read() does. The write is then refused only where that link has no channel context.

Fixes feb06d455620 ("wifi: mt76: mt7996: support fixed rate for link station")
Fixes 5806c91a3f0d ("wifi: mt76: mt7996: Remove unnecessary phy filed in mt7996_vif_link struct")
---
 drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c +10 -1
index 2ca594618f3b..7c976ec20d10 100644
@@ -1035,14 +1035,23 @@ static ssize_t mt7996_link_sta_fixed_rate_set(struct file *file,
 #define LONG_PREAMBLE 1
 	struct ieee80211_link_sta *link_sta = file->private_data;
 	struct mt7996_sta *msta = (struct mt7996_sta *)link_sta->sta->drv_priv;
-	struct mt7996_phy *link_phy = mt7996_vif_link_phy(&msta->vif->deflink);
 	struct mt7996_sta_link *msta_link;
+	struct mt7996_phy *link_phy = NULL;
+	struct mt76_vif_link *mlink;
 	struct ra_rate phy = {};
 	struct mt7996_dev *dev;
 	char buf[100];
 	int ret;
 	u16 gi, ltf;
 
+	rcu_read_lock();
+	mlink = rcu_dereference(msta->vif->mt76.link[link_sta->link_id]);
+	if (mlink)
+		link_phy = mt7996_vif_link_phy(container_of(mlink,
+							    struct mt7996_vif_link,
+							    mt76));
+	rcu_read_unlock();
+
 	if (!link_phy)
 		return -EINVAL;
 
Signature · 1 line
2.47.3
author maintainer
#3 lore raw

PATCH 4/18 wifi: mt76: mt7915: keep the BF column count within the row count

In reply to Felix Fietkau

mt7915_mcu_sta_bfer_vht() sets nrow to 1 for a 160 MHz peer after it took ncol from the streams of the peer. mt7915_mcu_sta_bfer_he() does not limit ncol_gt_bw80, the column count above 80 MHz, by nrow_gt_bw80. The firmware refuses a STA_REC_BF with more columns than rows. A peer with more streams at 160 MHz than the row count gets no profile.

Limit the column count to the row count in both pairs, as the driver already does below 160 MHz.

Fixes 89029a85482c ("mt76: mt7915: add Tx beamformer support")
---
 drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +4 -1
index bb71e6437a62..d3842268a638 100644
@@ -1230,8 +1230,10 @@ mt7915_mcu_sta_bfer_vht(struct ieee80211_sta *sta, struct mt7915_phy *phy,
 		bf->ncol = min_t(u8, nss_mcs, bf->nrow);
 		bf->ibf_ncol = bf->ncol;
 
-		if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_160)
+		if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_160) {
 			bf->nrow = 1;
+			bf->ncol = min_t(u8, bf->ncol, bf->nrow);
+		}
 	} else {
 		bf->nrow = tx_ant;
 		bf->ncol = min_t(u8, nss_mcs, bf->nrow);
@@ -1299,6 +1301,7 @@ mt7915_mcu_sta_bfer_he(struct ieee80211_sta *sta,
 		     pe->phy_cap_info[4]);
 
 	bf->nrow_gt_bw80 = min_t(int, snd_dim, sts);
+	bf->ncol_gt_bw80 = min_t(u8, bf->ncol_gt_bw80, bf->nrow_gt_bw80);
 }
 
 static void
Signature · 1 line
2.47.3
author maintainer
#4 lore raw

PATCH 5/18 wifi: mt76: mt7996: report the tx power of the requested link

In reply to Felix Fietkau

mt7996_get_txpower() ignores its link_id and takes the phy of link 0. Every link of an MLD thus reports the tx power of the band of link 0. Where link 0 has no channel context, each link reports the power of the last radio of the interface. Reachable via the per-link tx power of NL80211_CMD_GET_INTERFACE.

Take the phy of the requested link, like mt7996_sta_hw_queue_read() does. A link without a channel context keeps the fallback to a radio of the interface. That fallback serves an interface without a channel.

Fixes 86db2c5d4ed3 ("wifi: mt76: mt7996: implement driver specific get_txpower function")
Fixes a9eae65d97f3 ("wifi: mt76: mt7996: Export MLO AP capabilities to mac80211")
---
 drivers/net/wireless/mediatek/mt76/mt7996/main.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +11 -1
index ac4f8b89bd90..bcae654a2b47 100644
@@ -985,11 +985,21 @@ mt7996_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 		   unsigned int link_id, int *dbm)
 {
 	struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
-	struct mt7996_phy *phy = mt7996_vif_link_phy(&mvif->deflink);
 	struct mt7996_dev *dev = mt7996_hw_dev(hw);
+	struct mt7996_phy *phy = NULL;
+	struct mt76_vif_link *mlink;
 	struct wireless_dev *wdev;
 	int n_chains, delta, i;
 
+	rcu_read_lock();
+	mlink = link_id ? rcu_dereference(mvif->mt76.link[link_id]) :
+			  &mvif->deflink.mt76;
+	if (mlink)
+		phy = mt7996_vif_link_phy(container_of(mlink,
+						       struct mt7996_vif_link,
+						       mt76));
+	rcu_read_unlock();
+
 	if (!phy) {
 		wdev = ieee80211_vif_to_wdev(vif);
 		for (i = 0; i < hw->wiphy->n_radio; i++)
Signature · 1 line
2.47.3
author maintainer
#5 lore raw

PATCH 6/18 wifi: mt76: mt7996: refuse an RF register offset above 12 bits

In reply to Felix Fietkau

mt7996_mcu_rf_regval() sends bits 23:0 of the register index as the offset. The firmware masks that offset to 12 bits and reports success. A debugfs access to a larger offset thus reads or writes another register.

Refuse an offset that the firmware cannot address, and correct the offset range in the debugfs comment.

Fixes 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices")
---
 drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c | 2 +-
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c     | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c +1 -1
index 7c976ec20d10..175adbcc186f 100644
@@ -879,7 +879,7 @@ mt7996_twt_stats(struct seq_file *s, void *data)
 }
 
 /* The index of RF registers use the generic regidx, combined with two parts:
- * WF selection [31:24] and offset [23:0].
+ * WF selection [31:24] and offset [11:0].
  */
 static int
 mt7996_rf_regval_get(void *data, u64 *val)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +4 -1
index 91129c1f5a5e..671bbb741a46 100644
@@ -5702,12 +5702,15 @@ int mt7996_mcu_rf_regval(struct mt7996_dev *dev, u32 regidx, u32 *val, bool set)
 		.len = cpu_to_le16(sizeof(req) - 4),
 
 		.idx = cpu_to_le16(u32_get_bits(regidx, GENMASK(31, 24))),
-		.ofs = cpu_to_le32(u32_get_bits(regidx, GENMASK(23, 0))),
+		.ofs = cpu_to_le32(u32_get_bits(regidx, GENMASK(11, 0))),
 		.data = set ? cpu_to_le32(*val) : 0,
 	};
 	struct sk_buff *skb;
 	int ret;
 
+	if (regidx & GENMASK(23, 12))
+		return -EINVAL;
+
 	if (set)
 		return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(REG_ACCESS),
 					 &req, sizeof(req), true);
Signature · 1 line
2.47.3
author maintainer
#6 lore raw

PATCH 7/18 wifi: mt76: mt7996: hold the mutex across the thermal protection store

In reply to Felix Fietkau

mt7996_thermal_temp_store() sends the disable and enable pair of the thermal protection without dev->mt76.mutex. The pair can thus interleave with another hwmon write or with mt7996_run(). The firmware refuses an enable of an active protection entry. A temp1_crit or temp1_max write can thus leave the thresholds of an earlier write in force.

Send the pair under the mutex, as mt7915_thermal_temp_store() does. mt7996_run() already sends it under the mutex.

Fixes 6879b2e94172 ("wifi: mt76: mt7996: add thermal sensor device support")
---
 drivers/net/wireless/mediatek/mt76/mt7996/init.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/init.c +1 -2
index e82bc9cbc59e..f05231ce81ff 100644
@@ -156,9 +156,8 @@ static ssize_t mt7996_thermal_temp_store(struct device *dev,
 	}
 
 	phy->throttle_temp[i - 1] = val;
-	mutex_unlock(&phy->dev->mt76.mutex);
-
 	ret = mt7996_mcu_set_thermal_protect(phy, true);
+	mutex_unlock(&phy->dev->mt76.mutex);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.47.3
author maintainer
#7 lore raw

PATCH 8/18 wifi: mt76: mt7996: wait for the answer of each state command

In reply to Felix Fietkau

An L1 SER can drop a state command that sits in the MCU ring without a wait. The firmware sends no answer then, so the driver keeps a state that the firmware does not have. The driver does not send the command again. These commands are sent without a wait:

- the stop of the background chain.
- the thermal duty levels and protection.
- the SKU power limit and the Beacon rate entry.

Wait for the answer of these commands. A lost answer then requests a full reset, as for any other state command. The firmware answers each of them.

A firmware error status now reaches the callers:

- mt7996_run() disables the radio, as for its other commands.
- the radar background op returns it before it records the chain.
- the hwmon and cooling device writes keep their old state.
- the rate table callers ignore it.

The firmware refuses a field out of range, which the driver does not send, and an enable of a thermal protection that is already enabled. The driver disables the protection before it enables it, under dev->mt76.mutex.

Fixes 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices")
Fixes 21f290884bc1 ("wifi: mt76: connac: add thermal protection support for mt7996")
Fixes 254ab81f3b82 ("wifi: mt76: connac: add beacon duplicate TX mode support for mt7996")
Fixes 267424ac63aa ("wifi: mt76: mt7996: enable the SKU power limit table")
---
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +6 -6
index 671bbb741a46..c3a41935967e 100644
@@ -4367,7 +4367,7 @@ mt7996_mcu_background_chain_ctrl(struct mt7996_phy *phy,
 	req.band = chandef ? chandef->chan->band == NL80211_BAND_5GHZ : 1;
 
 	return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(OFFCH_SCAN_CTRL),
-				 &req, sizeof(req), false);
+				 &req, sizeof(req), true);
 }
 
 int mt7996_mcu_rdd_background_enable(struct mt7996_phy *phy,
@@ -5073,7 +5073,7 @@ int mt7996_mcu_set_thermal_throttling(struct mt7996_phy *phy, u8 state)
 		state /= 2;
 
 		ret = mt76_mcu_send_msg(&phy->dev->mt76, MCU_WM_UNI_CMD(THERMAL),
-					&req, sizeof(req), false);
+					&req, sizeof(req), true);
 		if (ret)
 			return ret;
 	}
@@ -5105,7 +5105,7 @@ int mt7996_mcu_set_thermal_protect(struct mt7996_phy *phy, bool enable)
 	req.tag = cpu_to_le16(UNI_CMD_THERMAL_PROTECT_DISABLE);
 
 	ret = mt76_mcu_send_msg(&phy->dev->mt76, MCU_WM_UNI_CMD(THERMAL),
-				&req, sizeof(req) - sizeof(req.enable), false);
+				&req, sizeof(req) - sizeof(req.enable), true);
 	if (ret || !enable)
 		return ret;
 
@@ -5118,7 +5118,7 @@ int mt7996_mcu_set_thermal_protect(struct mt7996_phy *phy, bool enable)
 	req.len = cpu_to_le16(sizeof(req) - 4);
 
 	return mt76_mcu_send_msg(&phy->dev->mt76, MCU_WM_UNI_CMD(THERMAL),
-				 &req, sizeof(req), false);
+				 &req, sizeof(req), true);
 }
 
 int mt7996_mcu_set_ser(struct mt7996_dev *dev, u8 action, u8 val, u8 band)
@@ -5683,7 +5683,7 @@ int mt7996_mcu_set_fixed_rate_table(struct mt7996_phy *phy, u8 table_idx,
 	}
 
 	return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(FIXED_RATE_TABLE),
-				 &req, sizeof(req), false);
+				 &req, sizeof(req), true);
 }
 
 int mt7996_mcu_rf_regval(struct mt7996_dev *dev, u32 regidx, u32 *val, bool set)
@@ -5892,7 +5892,7 @@ int mt7996_mcu_set_tx_power_ctrl(struct mt7996_phy *phy, u8 power_ctrl_id, u8 da
 	}
 
 	return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(TXPOWER),
-				 &req, sizeof(req), false);
+				 &req, sizeof(req), true);
 }
 
 int mt7996_mcu_set_txpower_sku(struct mt7996_phy *phy)
Signature · 1 line
2.47.3
author maintainer
#8 lore raw

PATCH 9/18 wifi: mt76: mt7915: wait for the answer of the background chain control

In reply to Felix Fietkau

A command sent without a wait can sit in the MCU ring when an L1 SER starts. The recovery can then drop it with no answer. The driver keeps a state that the firmware does not have, and does not send the command again. The stop of the background chain is such a command.

Wait for the answer of the background chain control. A lost answer then requests a full reset, as for any other state command. The firmware answers it. The thermal duty levels and the thermal protection stay without a wait, since the firmware never answers them.

Fixes 39cdf080ce78 ("mt76: mt7915: introduce mt7915_set_radar_background routine")
---
 drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +1 -1
index d3842268a638..73bbeb1b4a8e 100644
@@ -2861,7 +2861,7 @@ mt7915_mcu_background_chain_ctrl(struct mt7915_phy *phy,
 	req.band = chandef ? chandef->chan->band == NL80211_BAND_5GHZ : 1;
 
 	return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(OFFCH_SCAN_CTRL),
-				 &req, sizeof(req), false);
+				 &req, sizeof(req), true);
 }
 
 int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy,
Signature · 1 line
2.47.3
author maintainer
#9 lore raw

PATCH 10/18 wifi: mt76: mt7996: bound the in-band discovery frame by its buffer

In reply to Felix Fietkau

mt7996_mcu_beacon_inband_discov() limits a FILS Discovery or unsolicited Probe Response template to MT7996_MAX_BEACON_SIZE. The firmware copies the frame into a smaller buffer per band and does not check the length. Since commit 79e788fcb204 ("wifi: mt76: mt7996:
change max beacon size") raised that limit above the buffer size, a longer template overwrites the discovery state of the band behind the buffer, up to the stored descriptor of the next band.

Refuse a template that does not fit the firmware buffer. The buffer size comes from the MT7996 firmware, and the driver uses it for MT7992 and MT7990 as well.

Fixes 79e788fcb204 ("wifi: mt76: mt7996: change max beacon size")
---
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 2 +-
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +1 -1
index c3a41935967e..4f0e59fc170e 100644
@@ -3529,7 +3529,7 @@ int mt7996_mcu_beacon_inband_discov(struct mt7996_dev *dev,
 		return -EINVAL;
 	}
 
-	if (skb->len > MT7996_MAX_BEACON_SIZE) {
+	if (skb->len > MT7996_MAX_INBAND_FRAME_SIZE) {
 		dev_err(dev->mt76.dev, "inband discovery size limit exceed\n");
 		dev_kfree_skb(rskb);
 		dev_kfree_skb(skb);
drivers/net/wireless/mediatek/mt76/mt7996/mcu.h +1 -0
index a97fbcce1d47..a39ed2dc9e65 100644
@@ -1026,6 +1026,7 @@ enum {
 #define MT7996_MAX_BSS_OFFLOAD_SIZE	2048
 #define MT7996_MAX_BEACON_SIZE		(MT7996_MAX_BSS_OFFLOAD_SIZE - \
 					 MT7996_BEACON_UPDATE_SIZE)
+#define MT7996_MAX_INBAND_FRAME_SIZE	1520
 
 enum {
 	UNI_BAND_CONFIG_RADIO_ENABLE,
Signature · 1 line
2.47.3
author maintainer
#10 lore raw

PATCH 11/18 wifi: mt76: mt7915: reset on an MCU timeout only once the hw is registered

In reply to Felix Fietkau

mt7915_mcu_parse_response() queues reset_work on every MCU timeout, also while mt7915_register_device() has not registered the hw yet. The work runs in parallel with the probe. The probe fails on the timeout and frees the device.

mt7915_mac_full_reset() ends with ieee80211_restart_hw() on a hw that was never registered. ieee80211_restart_work() then flushes a NULL local->workqueue or uses the local that ieee80211_free_hw() freed: an oops after the failed probe. Any command of mt7915_init_hardware() without an answer gets there, from the PCIe and the WMAC probe alike.

Only start the reset once recovery.hw_init_done is set, as mt7915_reset() and mt792x_reset() do. Before that, leave MT76_MCU_RESET clear, so that a timeout fails its command like any other error. A device whose probe goes on after a failed command can then still be reset after its registration.

Fixes 10f73bb3938f ("wifi: mt76: mt7915: reset the device after MCU timeout")
---
 drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +2 -1
index 73bbeb1b4a8e..8ac595779f88 100644
@@ -181,7 +181,8 @@ mt7915_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 			cmd, seq);
 
 		spin_lock_bh(&dev->mt76.lock);
-		if (!test_and_set_bit(MT76_MCU_RESET, &dev->mphy.state))
+		if (dev->recovery.hw_init_done &&
+		    !test_and_set_bit(MT76_MCU_RESET, &dev->mphy.state))
 			mt7915_mac_full_reset_queue(dev);
 		spin_unlock_bh(&dev->mt76.lock);
 
Signature · 1 line
2.47.3
author maintainer
#11 lore raw

PATCH 12/18 wifi: mt76: mt7996: reset on an MCU timeout only once the hw is registered

In reply to Felix Fietkau

mt7996_mcu_parse_response() queues reset_work on every MCU timeout, also while mt7996_register_device() has not registered the hw yet. The work runs in parallel with the probe. After a failed probe, mt76_free_device() waits for it when it destroys the workqueue. mt7996_mac_full_reset() then ends with ieee80211_restart_hw() on a hw that was never registered. ieee80211_restart_work() flushes a NULL local->workqueue or uses the local that ieee80211_free_hw() freed: an oops after the failed probe.

Only start the reset once recovery.hw_init_done is set, as mt7996_reset() does. Before that, leave MT76_MCU_RESET clear, so that a timeout fails its command like any other error.

After a failed read, mt7996_eeprom_load() falls back to the default EEPROM data and the probe goes on. With the bit set, every command of the registered device would then fail at once. No reset would clear the bit.

Fixes d2b860454ea2 ("wifi: mt76: mt7996: reset device after MCU message timeout")
---
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +2 -1
index 4f0e59fc170e..4e1164e3afa4 100644
@@ -246,7 +246,8 @@ mt7996_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 			cmd, seq);
 
 		spin_lock_bh(&dev->mt76.lock);
-		if (!test_and_set_bit(MT76_MCU_RESET, &dev->mphy.state))
+		if (dev->recovery.hw_init_done &&
+		    !test_and_set_bit(MT76_MCU_RESET, &dev->mphy.state))
 			mt7996_mac_full_reset_queue(dev);
 		spin_unlock_bh(&dev->mt76.lock);
 
Signature · 1 line
2.47.3
author maintainer
#12 lore raw

PATCH 13/18 wifi: mt76: mt7915: mask the LDPC bits of STA_REC_HT and STA_REC_VHT

In reply to Felix Fietkau

mt7915_mcu_sta_ht_tlv() and mt7915_mcu_sta_vht_tlv() send the HT and VHT capability words of the peer unchanged. The firmware picks LDPC for a TX rate from these words. Only STA_REC_RA masks them with the LDPC capability of the interface. Since commit 33eb14f10290 ("wifi: mt76:
mt7915: use mac80211 .sta_state op"), the update at authorisation sends these TLVs again without STA_REC_RA. An AP configured without LDPC thus sends LDPC frames to an LDPC peer.

Clear the LDPC bit of each word where the interface has no LDPC for that mode. The rate control and HE TLVs already do so.

Fixes 33eb14f10290 ("wifi: mt76: mt7915: use mac80211 .sta_state op")
---
 .../net/wireless/mediatek/mt76/mt7915/mcu.c   | 24 ++++++++++++++-----
 1 file changed, 18 insertions(+), 6 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +18 -6
index 8ac595779f88..5da3bfaa5c53 100644
@@ -1032,33 +1032,45 @@ mt7915_mcu_sta_muru_tlv(struct mt7915_dev *dev, struct sk_buff *skb,
 }
 
 static void
-mt7915_mcu_sta_ht_tlv(struct sk_buff *skb, struct ieee80211_sta *sta)
+mt7915_mcu_sta_ht_tlv(struct sk_buff *skb, struct ieee80211_vif *vif,
+		      struct ieee80211_sta *sta)
 {
+	struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
+	u16 cap = sta->deflink.ht_cap.cap;
 	struct sta_rec_ht *ht;
 	struct tlv *tlv;
 
 	if (!sta->deflink.ht_cap.ht_supported)
 		return;
 
+	if (!mvif->cap.ht_ldpc)
+		cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
+
 	tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_HT, sizeof(*ht));
 
 	ht = (struct sta_rec_ht *)tlv;
-	ht->ht_cap = cpu_to_le16(sta->deflink.ht_cap.cap);
+	ht->ht_cap = cpu_to_le16(cap);
 }
 
 static void
-mt7915_mcu_sta_vht_tlv(struct sk_buff *skb, struct ieee80211_sta *sta)
+mt7915_mcu_sta_vht_tlv(struct sk_buff *skb, struct ieee80211_vif *vif,
+		       struct ieee80211_sta *sta)
 {
+	struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
+	u32 cap = sta->deflink.vht_cap.cap;
 	struct sta_rec_vht *vht;
 	struct tlv *tlv;
 
 	if (!sta->deflink.vht_cap.vht_supported)
 		return;
 
+	if (!mvif->cap.vht_ldpc)
+		cap &= ~IEEE80211_VHT_CAP_RXLDPC;
+
 	tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_VHT, sizeof(*vht));
 
 	vht = (struct sta_rec_vht *)tlv;
-	vht->vht_cap = cpu_to_le32(sta->deflink.vht_cap.cap);
+	vht->vht_cap = cpu_to_le32(cap);
 	vht->vht_rx_mcs_map = sta->deflink.vht_cap.vht_mcs.rx_mcs_map;
 	vht->vht_tx_mcs_map = sta->deflink.vht_cap.vht_mcs.tx_mcs_map;
 }
@@ -1805,9 +1817,9 @@ int mt7915_mcu_add_sta(struct mt7915_dev *dev, struct ieee80211_vif *vif,
 		/* starec bfer */
 		mt7915_mcu_sta_bfer_tlv(dev, skb, vif, sta);
 		/* starec ht */
-		mt7915_mcu_sta_ht_tlv(skb, sta);
+		mt7915_mcu_sta_ht_tlv(skb, vif, sta);
 		/* starec vht */
-		mt7915_mcu_sta_vht_tlv(skb, sta);
+		mt7915_mcu_sta_vht_tlv(skb, vif, sta);
 		/* starec uapsd */
 		mt76_connac_mcu_sta_uapsd(skb, vif, sta);
 	}
Signature · 1 line
2.47.3
author maintainer
#13 lore raw

PATCH 14/18 wifi: mt76: mt7996: mask the LDPC bits of STA_REC_HT, _VHT and _HE_V2

In reply to Felix Fietkau

mt7996_mcu_sta_ht_tlv(), mt7996_mcu_sta_vht_tlv() and mt7996_mcu_sta_he_tlv() send the capability words of the peer unchanged, but an AP keeps its own LDPC setting in link_conf. The firmware takes the HE LDPC bit of the station from STA_REC_HE_V2, and STA_REC_RA picks LDPC for HE and EHT rates from that bit. An AP configured without LDPC thus sends HE and EHT frames with LDPC to an LDPC peer. STA_REC_HT and STA_REC_VHT also set the HT and VHT LDPC flags of the WTBL entry from the raw words, and STA_REC_RA never clears them.

On an AP interface, clear the LDPC bit of each word where link_conf has no LDPC for that mode. mt7996_mcu_sta_rate_ctrl_tlv() does the same for the VHT flag, mt7915_mcu_sta_he_tlv() for the HE flag. The EHT capabilities have no LDPC bit of their own; an EHT peer uses the HE bit.

Fixes 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices")
---
 .../net/wireless/mediatek/mt76/mt7996/mcu.c   | 30 ++++++++++++++-----
 1 file changed, 22 insertions(+), 8 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +22 -8
index 4e1164e3afa4..1c4bb5706d49 100644
@@ -1639,6 +1639,7 @@ int mt7996_mcu_add_rx_ba(struct mt7996_dev *dev,
 
 static void
 mt7996_mcu_sta_he_tlv(struct sk_buff *skb,
+		      struct ieee80211_bss_conf *link_conf,
 		      struct ieee80211_link_sta *link_sta,
 		      struct mt7996_vif_link *link)
 {
@@ -1660,6 +1661,9 @@ mt7996_mcu_sta_he_tlv(struct sk_buff *skb,
 		he->he_phy_cap[i] = elem->phy_cap_info[i];
 	}
 
+	if (link_conf->vif->type == NL80211_IFTYPE_AP && !link_conf->he_ldpc)
+		he->he_phy_cap[1] &= ~IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD;
+
 	mcs_map = link_sta->he_cap.he_mcs_nss_supp;
 	switch (link_sta->bandwidth) {
 	case IEEE80211_STA_RX_BW_160:
@@ -1742,18 +1746,23 @@ mt7996_mcu_sta_eht_tlv(struct sk_buff *skb,
 }
 
 static void
-mt7996_mcu_sta_ht_tlv(struct sk_buff *skb, struct ieee80211_link_sta *link_sta)
+mt7996_mcu_sta_ht_tlv(struct sk_buff *skb, struct ieee80211_bss_conf *link_conf,
+		      struct ieee80211_link_sta *link_sta)
 {
+	u16 cap = link_sta->ht_cap.cap;
 	struct sta_rec_ht_uni *ht;
 	struct tlv *tlv;
 
 	if (!link_sta->ht_cap.ht_supported)
 		return;
 
+	if (link_conf->vif->type == NL80211_IFTYPE_AP && !link_conf->ht_ldpc)
+		cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
+
 	tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_HT, sizeof(*ht));
 
 	ht = (struct sta_rec_ht_uni *)tlv;
-	ht->ht_cap = cpu_to_le16(link_sta->ht_cap.cap);
+	ht->ht_cap = cpu_to_le16(cap);
 	ht->ampdu_param = u8_encode_bits(link_sta->ht_cap.ampdu_factor,
 					 IEEE80211_HT_AMPDU_PARM_FACTOR) |
 			  u8_encode_bits(link_sta->ht_cap.ampdu_density,
@@ -1761,8 +1770,10 @@ mt7996_mcu_sta_ht_tlv(struct sk_buff *skb, struct ieee80211_link_sta *link_sta)
 }
 
 static void
-mt7996_mcu_sta_vht_tlv(struct sk_buff *skb, struct ieee80211_link_sta *link_sta)
+mt7996_mcu_sta_vht_tlv(struct sk_buff *skb, struct ieee80211_bss_conf *link_conf,
+		       struct ieee80211_link_sta *link_sta)
 {
+	u32 cap = link_sta->vht_cap.cap;
 	struct sta_rec_vht *vht;
 	struct tlv *tlv;
 
@@ -1770,10 +1781,13 @@ mt7996_mcu_sta_vht_tlv(struct sk_buff *skb, struct ieee80211_link_sta *link_sta)
 	if (!link_sta->he_6ghz_capa.capa && !link_sta->vht_cap.vht_supported)
 		return;
 
+	if (link_conf->vif->type == NL80211_IFTYPE_AP && !link_conf->vht_ldpc)
+		cap &= ~IEEE80211_VHT_CAP_RXLDPC;
+
 	tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_VHT, sizeof(*vht));
 
 	vht = (struct sta_rec_vht *)tlv;
-	vht->vht_cap = cpu_to_le32(link_sta->vht_cap.cap);
+	vht->vht_cap = cpu_to_le32(cap);
 	vht->vht_rx_mcs_map = link_sta->vht_cap.vht_mcs.rx_mcs_map;
 	vht->vht_tx_mcs_map = link_sta->vht_cap.vht_mcs.tx_mcs_map;
 }
@@ -2691,7 +2705,7 @@ int mt7996_mcu_add_rate_ctrl(struct mt7996_dev *dev, struct mt7996_sta *msta,
 	 * update sta_rec_he here.
 	 */
 	if (changed)
-		mt7996_mcu_sta_he_tlv(skb, link_sta, link);
+		mt7996_mcu_sta_he_tlv(skb, link_conf, link_sta, link);
 
 	/* sta_rec_ra accommodates BW, NSS and only MCS range format
 	 * i.e 0-{7,8,9} for VHT.
@@ -3046,16 +3060,16 @@ int mt7996_mcu_add_sta(struct mt7996_dev *dev,
 						link);
 		}
 		/* starec ht */
-		mt7996_mcu_sta_ht_tlv(skb, link_sta);
+		mt7996_mcu_sta_ht_tlv(skb, link_conf, link_sta);
 		/* starec vht */
-		mt7996_mcu_sta_vht_tlv(skb, link_sta);
+		mt7996_mcu_sta_vht_tlv(skb, link_conf, link_sta);
 		/* starec uapsd */
 		mt76_connac_mcu_sta_uapsd(skb, link_conf->vif, sta);
 		/* starec amsdu */
 		mt7996_mcu_sta_amsdu_tlv(dev, skb, link_conf->vif, link_sta,
 					 msta_link);
 		/* starec he */
-		mt7996_mcu_sta_he_tlv(skb, link_sta, link);
+		mt7996_mcu_sta_he_tlv(skb, link_conf, link_sta, link);
 		/* starec he 6g*/
 		mt7996_mcu_sta_he_6g_tlv(skb, link_sta);
 		/* starec eht */
Signature · 1 line
2.47.3
author maintainer
#14 lore raw

PATCH 15/18 wifi: mt76: mt7996: send HE_BASIC for each HE link of an MLD

In reply to Felix Fietkau

mt7996_mcu_add_bss_info() adds the UNI_BSS_INFO_HE_BASIC TLV only if vif->bss_conf.he_support is set, while the TLV itself reads the link conf. For an MLD, mac80211 sets he_support in the conf of each link and leaves vif->bss_conf alone. No link of an AP MLD or of a station MLD thus gets the tag. The firmware then never programs the TXOP duration RTS threshold of these BSSs, which only this tag writes.

Test he_support of the link conf, the conf the TLV takes its values from. An interface that is no MLD has vif->bss_conf as its link conf and keeps its behaviour.

Fixes 34a41bfbcb71 ("wifi: mt76: mt7996: prepare mt7996_mcu_add_dev/bss_info for MLO support")
Fixes a9eae65d97f3 ("wifi: mt76: mt7996: Export MLO AP capabilities to mac80211")
---
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +1 -1
index 1c4bb5706d49..df08c4bba0e7 100644
@@ -1388,7 +1388,7 @@ int mt7996_mcu_add_bss_info(struct mt7996_phy *phy, struct ieee80211_vif *vif,
 		mt7996_mcu_bss_txcmd_tlv(skb, true);
 		mt7996_mcu_bss_ifs_timing_tlv(skb, phy);
 
-		if (vif->bss_conf.he_support)
+		if (link_conf->he_support)
 			mt7996_mcu_bss_he_tlv(skb, vif, link_conf, phy);
 
 		/* this tag is necessary no matter if the vif is MLD */
Signature · 1 line
2.47.3
author maintainer
#15 lore raw

PATCH 16/18 wifi: mt76: restore the operating channel after a failed ROC start

In reply to Felix Fietkau

A remain-on-channel request whose channel set fails leaves the phy off channel on the ROC chandef. mac80211 ends such a request without a driver call. The band thus stays off channel until a later ROC or scan, a chanctx change or a full reset. Until then it sends no beacons and no station data, and the radar detector stays off.

Go back to the operating chandef and notify the return, as the end of a ROC does.

Fixes 6939b97ddad3 ("wifi: mt76: fix deadlock in remain-on-channel")
---
 drivers/net/wireless/mediatek/mt76/channel.c | 22 +++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/net/wireless/mediatek/mt76/channel.c +15 -7
index 6d9ca6dfecb7..b3c17f76b101 100644
@@ -392,6 +392,19 @@ mt76_vif_roc_phy(struct mt76_dev *dev, struct ieee80211_vif *vif)
 	return NULL;
 }
 
+static void mt76_roc_chandef_restore(struct mt76_phy *phy)
+{
+	struct mt76_dev *dev = phy->dev;
+
+	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);
+		mt76_offchannel_notify(phy, false);
+	} else {
+		phy->offchannel = false;
+	}
+}
+
 void mt76_roc_complete(struct mt76_phy *phy)
 {
 	struct mt76_vif_link *mlink = mt76_dereference(phy->roc_link, phy->dev);
@@ -402,13 +415,7 @@ void mt76_roc_complete(struct mt76_phy *phy)
 
 	if (mlink && mlink->mvif->roc_phy == phy)
 		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);
-		mt76_offchannel_notify(phy, false);
-	} else {
-		phy->offchannel = false;
-	}
+	mt76_roc_chandef_restore(phy);
 	rcu_assign_pointer(phy->roc_link, NULL);
 	mt76_put_vif_phy_link(phy, phy->roc_vif, mlink);
 	phy->roc_vif = NULL;
@@ -485,6 +492,7 @@ int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	ret = __mt76_set_channel(phy, &chandef, offchannel);
 	if (ret) {
 		WRITE_ONCE(mlink->mvif->roc_phy, NULL);
+		mt76_roc_chandef_restore(phy);
 		phy->roc_vif = NULL;
 		rcu_assign_pointer(phy->roc_link, NULL);
 		mt76_put_vif_phy_link(phy, vif, mlink);
Signature · 1 line
2.47.3
author maintainer
#16 lore raw

PATCH 17/18 wifi: mt76: mt7996: set the duplicate WTBL range again after a reset

In reply to Felix Fietkau

The firmware holds the duplicate WTBL range in RAM. A firmware load starts the range with a count of 0, which turns the feature off. mt7996_init_work() sets the range once at probe. mt7996_mac_restart() loads the firmware again without it, so a full reset leaves the feature off until the next probe.

Set the range again in each round of the full reset. Send it after the beamforming init as at probe, before the replay of the stations. Like the probe, go on if the firmware refuses it.

Fixes 7f3ec778593f ("wifi: mt76: mt7996: add duplicated WTBL command")
---
 drivers/net/wireless/mediatek/mt76/mt7996/init.c | 4 +---
 drivers/net/wireless/mediatek/mt76/mt7996/mac.c  | 2 ++
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c  | 3 +++
 3 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/init.c +1 -3
index f05231ce81ff..ec20fc8d823b 100644
@@ -792,9 +792,7 @@ static void mt7996_init_work(struct work_struct *work)
 	mt7996_mcu_set_eeprom(dev);
 	mt7996_mac_init(dev);
 	mt7996_txbf_init(dev);
-
-	if (!is_mt7990(&dev->mt76))
-		mt7996_mcu_set_dup_wtbl(dev);
+	mt7996_mcu_set_dup_wtbl(dev);
 }
 
 void mt7996_wfsys_reset(struct mt7996_dev *dev)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +2 -0
index 6d3061c64e30..62e16e3c989b 100644
@@ -2460,6 +2460,8 @@ mt7996_mac_restart(struct mt7996_dev *dev)
 	if (ret)
 		goto out;
 
+	mt7996_mcu_set_dup_wtbl(dev);
+
 	mt7996_for_each_phy(dev, phy) {
 		if (!test_bit(MT76_STATE_RUNNING, &phy->mt76->state))
 			continue;
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +3 -0
index df08c4bba0e7..f7c08bc4a588 100644
@@ -6024,6 +6024,9 @@ int mt7996_mcu_set_dup_wtbl(struct mt7996_dev *dev)
 		.num = cpu_to_le16(DUP_WTBL_NUM),
 	};
 
+	if (is_mt7990(&dev->mt76))
+		return 0;
+
 	return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(CHIP_CONFIG), &req,
 				 sizeof(req), true);
 }
Signature · 1 line
2.47.3
author maintainer
#17 lore raw

PATCH 18/18 wifi: mt76: mt7996: keep station wcids out of the duplicate WTBL range

In reply to Felix Fietkau

mt7996_mcu_set_dup_wtbl() places the duplicate WTBL range at the top of the station range. mt7996_global_wcid_init() and mt7996_mac_sta_init_link() still allocate wcids up to MT7996_WTBL_STA. The firmware repeats each WTBL write of a wcid below the range size on its duplicate entry. A station with an index in the range thus shares its WTBL entry with the duplicate of another station. On the largest tables the firmware also moves the range down, so the range it uses is not the one that the driver sends.

Send the base that the firmware uses, and allocate station wcids below it. This lowers the station capacity by the size of the range, and on the largest tables by a few more indexes. mt7990 gets no range, so its station range does not change.

Fixes 7f3ec778593f ("wifi: mt76: mt7996: add duplicated WTBL command")
---
 drivers/net/wireless/mediatek/mt76/mt7996/init.c   |  3 ++-
 drivers/net/wireless/mediatek/mt76/mt7996/main.c   |  5 +++--
 drivers/net/wireless/mediatek/mt76/mt7996/mcu.c    |  5 ++---
 drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h | 14 ++++++++++++++
 4 files changed, 21 insertions(+), 6 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/init.c +2 -1
index ec20fc8d823b..18eab0eaaaad 100644
@@ -1260,7 +1260,8 @@ static int mt7996_variant_fem_init(struct mt7996_dev *dev)
 
 int mt7996_global_wcid_init(struct mt7996_dev *dev)
 {
-	int idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7996_WTBL_STA);
+	int idx = mt76_wcid_alloc(dev->mt76.wcid_mask,
+				  mt7996_wtbl_sta_limit(dev));
 
 	if (idx)
 		return -ENOSPC;
drivers/net/wireless/mediatek/mt76/mt7996/main.c +3 -2
index bcae654a2b47..bcecd6558fda 100644
@@ -1378,7 +1378,7 @@ mt7996_mac_sta_init_link(struct mt7996_dev *dev,
 	if (!phy)
 		return -EINVAL;
 
-	idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7996_WTBL_STA);
+	idx = mt76_wcid_alloc(dev->mt76.wcid_mask, mt7996_wtbl_sta_limit(dev));
 	if (idx < 0)
 		return -ENOSPC;
 
@@ -3110,7 +3110,8 @@ mt7996_net_fill_forward_path(struct ieee80211_hw *hw,
 	if (!msta_link)
 		return -EIO;
 
-	if (!msta_link->wcid.sta || msta_link->wcid.idx > MT7996_WTBL_STA)
+	if (!msta_link->wcid.sta ||
+	    msta_link->wcid.idx >= mt7996_wtbl_sta_limit(dev))
 		return -EIO;
 
 	if (dev->hif2 &&
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +2 -3
index f7c08bc4a588..e4fd4b672e22 100644
@@ -6008,7 +6008,6 @@ int mt7996_mcu_cp_support(struct mt7996_dev *dev, u8 mode)
 
 int mt7996_mcu_set_dup_wtbl(struct mt7996_dev *dev)
 {
-#define DUP_WTBL_NUM	80
 	struct {
 		u8 _rsv[4];
 
@@ -6020,8 +6019,8 @@ int mt7996_mcu_set_dup_wtbl(struct mt7996_dev *dev)
 	} __packed req = {
 		.tag = cpu_to_le16(UNI_CHIP_CONFIG_DUP_WTBL),
 		.len = cpu_to_le16(sizeof(req) - 4),
-		.base = cpu_to_le16(MT7996_WTBL_STA - DUP_WTBL_NUM + 1),
-		.num = cpu_to_le16(DUP_WTBL_NUM),
+		.base = cpu_to_le16(mt7996_dup_wtbl_base(dev)),
+		.num = cpu_to_le16(MT7996_DUP_WTBL_NUM),
 	};
 
 	if (is_mt7990(&dev->mt76))
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +14 -0
index e6bf1151447f..1354bd82808c 100644
@@ -18,6 +18,7 @@
 #define MT7996_WTBL_RESERVED		(mt7996_wtbl_size(dev) - 1)
 #define MT7996_WTBL_STA			(MT7996_WTBL_RESERVED - \
 					 mt7996_max_interface_num(dev))
+#define MT7996_DUP_WTBL_NUM		80
 
 #define MT7996_WATCHDOG_TIME		(HZ / 10)
 #define MT7996_RESET_TIMEOUT		(30 * HZ)
@@ -872,6 +873,19 @@ static inline u16 mt7996_wtbl_size(struct mt7996_dev *dev)
 	return (dev->wtbl_size_group << 8) + MT7996_WTBL_BMC_SIZE;
 }
 
+static inline u16 mt7996_dup_wtbl_base(struct mt7996_dev *dev)
+{
+	return min_t(u16, MT7996_WTBL_STA + 1, 0x400) - MT7996_DUP_WTBL_NUM;
+}
+
+static inline u16 mt7996_wtbl_sta_limit(struct mt7996_dev *dev)
+{
+	if (is_mt7990(&dev->mt76))
+		return MT7996_WTBL_STA;
+
+	return mt7996_dup_wtbl_base(dev);
+}
+
 void mt7996_dual_hif_set_irq_mask(struct mt7996_dev *dev, bool write_reg,
 				  u32 clear, u32 set);
 
Signature · 1 line
2.47.3