Skip to contentSkip to conversation

wifi: mt76: mt7921: use the BSS chandef for ROC

PATCH New Emery Hsin 1 participant 3 messages Nov 29

Subsystems (2)
lore
Share & tools
lore

Emery Hsin

author
#0 lore raw

cover wifi: mt76: mt7921: use the BSS chandef for ROC

The mt7921 ROC request always carried a 20 MHz bandwidth, the center channel of the control channel and a secondary channel offset that was never set, even when joining a wider BSS channel.

Patch 1 moves the mt7925 chandef to firmware channel width mapping to mt792x so mt7921 can reuse it. Patch 2 fills the ROC request from the BSS channel context chandef on join, as mt7925 does, and from a 20 MHz no-HT chandef otherwise.

Emery Hsin (2):
wifi: mt76: mt792x: factor out FW channel width mapping
wifi: mt76: mt7921: use the BSS channel definition for ROC requests

 .../net/wireless/mediatek/mt76/mt7921/mcu.c   | 51 +++++++++++++++----
 .../net/wireless/mediatek/mt76/mt7925/mcu.c   | 22 +-------
 .../wireless/mediatek/mt76/mt7925/mt7925.h    | 11 ----
 drivers/net/wireless/mediatek/mt76/mt792x.h   | 12 +++++
 .../net/wireless/mediatek/mt76/mt792x_core.c  | 21 ++++++++
 5 files changed, 76 insertions(+), 41 deletions(-)
Signature · 1 line
2.45.2
author
#1 lore raw

PATCH 1/2 wifi: mt76: mt792x: factor out FW channel width mapping

mt7925 maps a chandef to the firmware channel width (ENUM_CHANNEL_WIDTH_T), which differs from CMD_CBW_*. Move the enum and the helper to mt792x so mt7921 can reuse them, and rename them accordingly.

No functional change.

---
 .../net/wireless/mediatek/mt76/mt7925/mcu.c   | 22 +------------------
 .../wireless/mediatek/mt76/mt7925/mt7925.h    | 11 ----------
 drivers/net/wireless/mediatek/mt76/mt792x.h   | 12 ++++++++++
 .../net/wireless/mediatek/mt76/mt792x_core.c  | 21 ++++++++++++++++++
 4 files changed, 34 insertions(+), 32 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +1 -21
index 0afe38348bc9..41ddcb516dc0 100644
@@ -1646,26 +1646,6 @@ mt7925_mcu_roc_chandef(struct mt792x_bss_conf *mconf,
 	cfg80211_chandef_create(chandef, chan, NL80211_CHAN_NO_HT);
 }
 
-static u8 mt7925_chandef_to_cw(const struct cfg80211_chan_def *chandef)
-{
-	static const u8 width_to_cw[] = {
-		[NL80211_CHAN_WIDTH_20_NOHT] = MT7925_CW_20_40MHZ,
-		[NL80211_CHAN_WIDTH_20] = MT7925_CW_20_40MHZ,
-		[NL80211_CHAN_WIDTH_40] = MT7925_CW_20_40MHZ,
-		[NL80211_CHAN_WIDTH_80] = MT7925_CW_80MHZ,
-		[NL80211_CHAN_WIDTH_160] = MT7925_CW_160MHZ,
-		[NL80211_CHAN_WIDTH_80P80] = MT7925_CW_80P80MHZ,
-		[NL80211_CHAN_WIDTH_5] = MT7925_CW_5MHZ,
-		[NL80211_CHAN_WIDTH_10] = MT7925_CW_10MHZ,
-		[NL80211_CHAN_WIDTH_320] = MT7925_CW_320MHZ,
-	};
-
-	if (chandef->width >= ARRAY_SIZE(width_to_cw))
-		return 0;
-
-	return width_to_cw[chandef->width];
-}
-
 int mt7925_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf,
 		       struct ieee80211_channel *chan, int duration,
 		       enum mt7925_roc_req type, u8 token_id)
@@ -1694,7 +1674,7 @@ int mt7925_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf,
 
 	mt7925_mcu_roc_chandef(mconf, chan, type, &chandef);
 	center_ch = ieee80211_frequency_to_channel(chandef.center_freq1);
-	bw = mt7925_chandef_to_cw(&chandef);
+	bw = mt792x_chandef_to_cw(&chandef);
 
 	req.roc.bw = bw;
 	req.roc.bw_from_ap = bw;
drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h +0 -11
index 09c2ba580e67..8d449cf36a2d 100644
@@ -63,17 +63,6 @@ enum {
 	UNI_ROC_NUM
 };
 
-/* FW ENUM_CHANNEL_WIDTH_T, which differs from CMD_CBW_* */
-enum mt7925_fw_chan_width {
-	MT7925_CW_20_40MHZ,
-	MT7925_CW_80MHZ,
-	MT7925_CW_160MHZ,
-	MT7925_CW_80P80MHZ,
-	MT7925_CW_5MHZ,
-	MT7925_CW_10MHZ,
-	MT7925_CW_320MHZ,
-};
-
 enum mt7925_roc_req {
 	MT7925_ROC_REQ_JOIN,
 	MT7925_ROC_REQ_ROC,
drivers/net/wireless/mediatek/mt76/mt792x.h +12 -0
index b6de25eccc43..9281e4aab80b 100644
@@ -112,6 +112,17 @@ enum mt792x_mlo_pm_state {
 	MT792x_MLO_CHANGED_PS,
 };
 
+/* FW ENUM_CHANNEL_WIDTH_T, which differs from CMD_CBW_* */
+enum mt792x_fw_chan_width {
+	MT792x_CW_20_40MHZ,
+	MT792x_CW_80MHZ,
+	MT792x_CW_160MHZ,
+	MT792x_CW_80P80MHZ,
+	MT792x_CW_5MHZ,
+	MT792x_CW_10MHZ,
+	MT792x_CW_320MHZ,
+};
+
 DECLARE_EWMA(avg_signal, 10, 8)
 
 struct mt792x_link_sta {
@@ -656,6 +667,7 @@ void mt792x_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 		    u64 timestamp);
 void mt792x_tx_worker(struct mt76_worker *w);
 void mt792x_roc_timer(struct timer_list *timer);
+u8 mt792x_chandef_to_cw(const struct cfg80211_chan_def *chandef);
 void mt792x_csa_timer(struct timer_list *timer);
 void mt792x_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 		  u32 queues, bool drop);
drivers/net/wireless/mediatek/mt76/mt792x_core.c +21 -0
index fc947dd38e81..fc96ea5805c5 100644
@@ -611,6 +611,27 @@ void mt792x_roc_timer(struct timer_list *timer)
 }
 EXPORT_SYMBOL_GPL(mt792x_roc_timer);
 
+u8 mt792x_chandef_to_cw(const struct cfg80211_chan_def *chandef)
+{
+	static const u8 width_to_cw[] = {
+		[NL80211_CHAN_WIDTH_20_NOHT] = MT792x_CW_20_40MHZ,
+		[NL80211_CHAN_WIDTH_20] = MT792x_CW_20_40MHZ,
+		[NL80211_CHAN_WIDTH_40] = MT792x_CW_20_40MHZ,
+		[NL80211_CHAN_WIDTH_80] = MT792x_CW_80MHZ,
+		[NL80211_CHAN_WIDTH_160] = MT792x_CW_160MHZ,
+		[NL80211_CHAN_WIDTH_80P80] = MT792x_CW_80P80MHZ,
+		[NL80211_CHAN_WIDTH_5] = MT792x_CW_5MHZ,
+		[NL80211_CHAN_WIDTH_10] = MT792x_CW_10MHZ,
+		[NL80211_CHAN_WIDTH_320] = MT792x_CW_320MHZ,
+	};
+
+	if (chandef->width >= ARRAY_SIZE(width_to_cw))
+		return 0;
+
+	return width_to_cw[chandef->width];
+}
+EXPORT_SYMBOL_GPL(mt792x_chandef_to_cw);
+
 void mt792x_csa_timer(struct timer_list *timer)
 {
 	struct mt792x_vif *mvif = timer_container_of(mvif, timer, csa_timer);
Signature · 1 line
2.45.2
author
#2 lore raw

PATCH 2/2 wifi: mt76: mt7921: use the BSS channel definition for ROC requests

In reply to Emery Hsin

The ROC request always carried a 20 MHz bandwidth and a secondary channel offset that was always 0. Use the chandef of the BSS channel context when joining on the BSS channel, and a 20 MHz no-HT chandef otherwise, as mt7925 does. Fill the bandwidth from the firmware channel width enum.

---
 .../net/wireless/mediatek/mt76/mt7921/mcu.c   | 51 +++++++++++++++----
 1 file changed, 42 insertions(+), 9 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7921/mcu.c +42 -9
index 77d3c07486cb..6171fa567d6b 100644
@@ -848,12 +848,29 @@ int mt7921_mcu_set_tx(struct mt792x_dev *dev, struct ieee80211_vif *vif)
 				 &req_mu, sizeof(req_mu), false);
 }
 
+static void
+mt7921_mcu_roc_chandef(struct mt792x_vif *vif, struct ieee80211_channel *chan,
+		       enum mt7921_roc_req type, struct cfg80211_chan_def *chandef)
+{
+	struct mt76_vif_link *mlink = &vif->bss_conf.mt76;
+
+	if (type == MT7921_ROC_REQ_JOIN && mlink->ctx &&
+	    mlink->ctx->def.chan == chan) {
+		*chandef = mlink->ctx->def;
+		return;
+	}
+
+	cfg80211_chandef_create(chandef, chan, NL80211_CHAN_NO_HT);
+}
+
 int mt7921_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_vif *vif,
 		       struct ieee80211_channel *chan, int duration,
 		       enum mt7921_roc_req type, u8 token_id)
 {
-	int center_ch = ieee80211_frequency_to_channel(chan->center_freq);
 	struct mt792x_dev *dev = phy->dev;
+	struct cfg80211_chan_def chandef;
+	int center_ch, pri40_freq;
+	u8 bw;
 	struct {
 		struct {
 			u8 rsv[4];
@@ -886,18 +903,34 @@ int mt7921_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_vif *vif,
 			.maxinterval = cpu_to_le32(duration),
 			.bss_idx = vif->bss_conf.mt76.idx,
 			.control_channel = chan->hw_value,
-			.bw = CMD_CBW_20MHZ,
-			.bw_from_ap = CMD_CBW_20MHZ,
-			.center_chan = center_ch,
-			.center_chan_from_ap = center_ch,
 			.dbdcband = 0xff, /* auto */
 		},
 	};
 
-	if (chan->hw_value < center_ch)
-		req.roc.sco = 1; /* SCA */
-	else if (chan->hw_value > center_ch)
-		req.roc.sco = 3; /* SCB */
+	mt7921_mcu_roc_chandef(vif, chan, type, &chandef);
+	center_ch = ieee80211_frequency_to_channel(chandef.center_freq1);
+	bw = mt792x_chandef_to_cw(&chandef);
+
+	req.roc.bw = bw;
+	req.roc.bw_from_ap = bw;
+	req.roc.center_chan = center_ch;
+	req.roc.center_chan_from_ap = center_ch;
+
+	if (chandef.center_freq2) {
+		u8 center_ch2 = ieee80211_frequency_to_channel(chandef.center_freq2);
+
+		req.roc.center_chan2 = center_ch2;
+		req.roc.center_chan2_from_ap = center_ch2;
+	}
+
+	if (nl80211_chan_width_to_mhz(chandef.width) >= 40) {
+		pri40_freq = cfg80211_chandef_primary(&chandef,
+						      NL80211_CHAN_WIDTH_40, NULL);
+		if (pri40_freq > 0)
+			req.roc.sco = chan->center_freq < pri40_freq ?
+				      IEEE80211_HT_PARAM_CHA_SEC_ABOVE :
+				      IEEE80211_HT_PARAM_CHA_SEC_BELOW;
+	}
 
 	switch (chan->band) {
 	case NL80211_BAND_6GHZ:
Signature · 1 line
2.45.2