[mt76-next,1/2] wifi: mt76: mt792x: factor out FW channel width mapping

Emery Hsin emery.hsin at mediatek.com
Sun Nov 29 07:37:34 PST 2026


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.

Signed-off-by: Emery Hsin <emery.hsin at mediatek.com>
---
 .../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(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
index 0afe38348bc9..41ddcb516dc0 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
@@ -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;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
index 09c2ba580e67..8d449cf36a2d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h
@@ -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,
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h
index b6de25eccc43..9281e4aab80b 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x.h
+++ b/drivers/net/wireless/mediatek/mt76/mt792x.h
@@ -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);
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_core.c b/drivers/net/wireless/mediatek/mt76/mt792x_core.c
index fc947dd38e81..fc96ea5805c5 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x_core.c
+++ b/drivers/net/wireless/mediatek/mt76/mt792x_core.c
@@ -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);
-- 
2.45.2




More information about the linux-arm-kernel mailing list