OSDN Git Service

wifi: mt76: mt7921: fix channel switch fail in monitor mode
authorDeren Wu <deren.wu@mediatek.com>
Fri, 16 Dec 2022 11:04:38 +0000 (19:04 +0800)
committerFelix Fietkau <nbd@nbd.name>
Fri, 3 Feb 2023 13:47:16 +0000 (14:47 +0100)
When the chanctx enabled, IEEE80211_CONF_CHANGE_CHANNEL in .config()
would not be called anymore. mt76 cannot control RF channel for monitor.
Add monitor type set-channel flow in .change_chanctx().

Fixes: 41ac53c899bd ("wifi: mt76: mt7921: introduce chanctx support")
Reviewed-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7921/main.c
drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h

index 722df8e..cdb0d61 100644 (file)
@@ -1706,7 +1706,10 @@ static void mt7921_ctx_iter(void *priv, u8 *mac,
        if (ctx != mvif->ctx)
                return;
 
-       mt76_connac_mcu_uni_set_chctx(mvif->phy->mt76, &mvif->mt76, ctx);
+       if (vif->type & NL80211_IFTYPE_MONITOR)
+               mt7921_mcu_config_sniffer(mvif, ctx);
+       else
+               mt76_connac_mcu_uni_set_chctx(mvif->phy->mt76, &mvif->mt76, ctx);
 }
 
 static void
index 8930b5a..c4ca690 100644 (file)
@@ -1093,6 +1093,74 @@ int mt7921_mcu_set_sniffer(struct mt7921_dev *dev, struct ieee80211_vif *vif,
                                 true);
 }
 
+int mt7921_mcu_config_sniffer(struct mt7921_vif *vif,
+                             struct ieee80211_chanctx_conf *ctx)
+{
+       struct cfg80211_chan_def *chandef = &ctx->def;
+       int freq1 = chandef->center_freq1, freq2 = chandef->center_freq2;
+       const u8 ch_band[] = {
+               [NL80211_BAND_2GHZ] = 1,
+               [NL80211_BAND_5GHZ] = 2,
+               [NL80211_BAND_6GHZ] = 3,
+       };
+       const u8 ch_width[] = {
+               [NL80211_CHAN_WIDTH_20_NOHT] = 0,
+               [NL80211_CHAN_WIDTH_20] = 0,
+               [NL80211_CHAN_WIDTH_40] = 0,
+               [NL80211_CHAN_WIDTH_80] = 1,
+               [NL80211_CHAN_WIDTH_160] = 2,
+               [NL80211_CHAN_WIDTH_80P80] = 3,
+               [NL80211_CHAN_WIDTH_5] = 4,
+               [NL80211_CHAN_WIDTH_10] = 5,
+               [NL80211_CHAN_WIDTH_320] = 6,
+       };
+       struct {
+               struct {
+                       u8 band_idx;
+                       u8 pad[3];
+               } __packed hdr;
+               struct config_tlv {
+                       __le16 tag;
+                       __le16 len;
+                       u16 aid;
+                       u8 ch_band;
+                       u8 bw;
+                       u8 control_ch;
+                       u8 sco;
+                       u8 center_ch;
+                       u8 center_ch2;
+                       u8 drop_err;
+                       u8 pad[3];
+               } __packed tlv;
+       } __packed req = {
+               .hdr = {
+                       .band_idx = vif->mt76.band_idx,
+               },
+               .tlv = {
+                       .tag = cpu_to_le16(1),
+                       .len = cpu_to_le16(sizeof(req.tlv)),
+                       .control_ch = chandef->chan->hw_value,
+                       .center_ch = ieee80211_frequency_to_channel(freq1),
+                       .drop_err = 1,
+               },
+       };
+       if (chandef->chan->band < ARRAY_SIZE(ch_band))
+               req.tlv.ch_band = ch_band[chandef->chan->band];
+       if (chandef->width < ARRAY_SIZE(ch_width))
+               req.tlv.bw = ch_width[chandef->width];
+
+       if (freq2)
+               req.tlv.center_ch2 = ieee80211_frequency_to_channel(freq2);
+
+       if (req.tlv.control_ch < req.tlv.center_ch)
+               req.tlv.sco = 1; /* SCA */
+       else if (req.tlv.control_ch > req.tlv.center_ch)
+               req.tlv.sco = 3; /* SCB */
+
+       return mt76_mcu_send_msg(vif->phy->mt76->dev, MCU_UNI_CMD(SNIFFER),
+                                &req, sizeof(req), true);
+}
+
 int
 mt7921_mcu_uni_add_beacon_offload(struct mt7921_dev *dev,
                                  struct ieee80211_hw *hw,
index efff4d4..edfaeb7 100644 (file)
@@ -529,6 +529,8 @@ void mt7921_set_ipv6_ns_work(struct work_struct *work);
 
 int mt7921_mcu_set_sniffer(struct mt7921_dev *dev, struct ieee80211_vif *vif,
                           bool enable);
+int mt7921_mcu_config_sniffer(struct mt7921_vif *vif,
+                             struct ieee80211_chanctx_conf *ctx);
 
 int mt7921_usb_sdio_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
                                   enum mt76_txq_id qid, struct mt76_wcid *wcid,