Skip to contentSkip to conversation

wifi: mt76: mt792x: make active monitor work

PATCH New Devin Wittmayer 1 participant 5 messages Nov 23

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover wifi: mt76: mt792x: make active monitor work

Before 7.3, an active monitor on MT7921, MT7922 and MT7925 never got a channel. Since 7.3, every mt792x refuses one.

Patch 3, Mark's change from the morrownr/mt76 tree, passes every mt792x monitor to the driver as its own interface, as MT7927 already does. Patches 1 and 2 keep the sniffer on for these monitors, and patch 4 offers active monitor again.

tested on MT7921AU and MT7925 over USB at both speeds, MT7922

                    over PCIe; MT7925 and MT7927 over PCIe on 7.3.5

active monitor hears the AP as well as a passive one
passive monitor unchanged once a channel is set; with none set, it
listens on the radio's current channel, as on MT7927
after a scan a monitor on MT7927 keeps capturing

Suspend with a monitor up needs Felix's mac80211 fixes [1].

v2: rebased on mt76; patch 2 also covers mt7925's power save code.

v1: https://lore.kernel.org/linux-wireless/[email protected]/
[1] https://lore.kernel.org/linux-wireless/[email protected]/

Devin Wittmayer (3):
wifi: mt76: mt7921: keep the sniffer on for real monitor vifs
wifi: mt76: mt7925: keep the sniffer on for real monitor vifs Revert "wifi: mt76: mt792x: do not advertise active monitor"

Mark Anthony Agarro (1):
wifi: mt76: mt792x: pass monitors to the driver as real vifs

 drivers/net/wireless/mediatek/mt76/mac80211.c |  5 +-
 drivers/net/wireless/mediatek/mt76/mt76.h     |  1 -
 .../wireless/mediatek/mt76/mt7921/debugfs.c   |  2 +-
 .../net/wireless/mediatek/mt76/mt7921/main.c  | 82 ++++++++++++++++++-
 .../net/wireless/mediatek/mt76/mt7921/mcu.c   |  5 +-
 .../wireless/mediatek/mt76/mt7921/testmode.c  |  4 +-
 .../wireless/mediatek/mt76/mt7925/debugfs.c   |  2 +-
 .../net/wireless/mediatek/mt76/mt7925/main.c  | 76 +++++++++++++++--
 .../wireless/mediatek/mt76/mt7925/testmode.c  |  4 +-
 drivers/net/wireless/mediatek/mt76/mt792x.h   | 10 +++
 .../net/wireless/mediatek/mt76/mt792x_core.c  |  6 +-
 11 files changed, 169 insertions(+), 28 deletions(-)

base-commit: afe54fd58a8781c1e96b81e42bbb67851a61ed18

Signature · 1 line
2.56.1
#1 lore raw

PATCH v2 1/4 wifi: mt76: mt7921: keep the sniffer on for real monitor vifs

mac80211 sets its monitor flag only for the virtual monitor. A monitor that reaches the driver as its own vif is not treated as one and goes deaf after a scan.

Count monitor vifs and treat one like the monitor flag. Start a new monitor's sniffer on the radio's current channel. Set it up again after a scan, and when another interface goes down, where mac80211 would add the virtual monitor back.

---
 .../wireless/mediatek/mt76/mt7921/debugfs.c   |  2 +-
 .../net/wireless/mediatek/mt76/mt7921/main.c  | 82 ++++++++++++++++++-
 .../net/wireless/mediatek/mt76/mt7921/mcu.c   |  5 +-
 .../wireless/mediatek/mt76/mt7921/testmode.c  |  4 +-
 drivers/net/wireless/mediatek/mt76/mt792x.h   | 10 +++
 5 files changed, 94 insertions(+), 9 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c +1 -1
index 14c70ffa9665..39c1c5e7853f 100644
@@ -199,7 +199,7 @@ mt7921_deep_sleep_set(void *data, u64 val)
 	if (pm->ds_enable_user == enable)
 		goto out;
 
-	monitor = !!(dev->mphy.hw->conf.flags & IEEE80211_CONF_MONITOR);
+	monitor = mt792x_monitor_active(dev);
 	pm->ds_enable_user = enable;
 	pm->ds_enable = enable && !monitor;
 	mt76_connac_mcu_set_deep_sleep(&dev->mt76, pm->ds_enable);
drivers/net/wireless/mediatek/mt76/mt7921/main.c +78 -4

125 lines not on this page · raw message

drivers/net/wireless/mediatek/mt76/mt7921/mcu.c +3 -2
index d973dea103db..68bb9526dd9e 100644
@@ -981,7 +981,7 @@ int mt7921_mcu_set_chan_info(struct mt792x_phy *phy, int cmd)
 		req.channel_band = chandef->chan->band;
 
 	if (cmd == MCU_EXT_CMD(SET_RX_PATH) ||
-	    (dev->mt76.hw->conf.flags & IEEE80211_CONF_MONITOR &&
+	    (mt792x_monitor_active(dev) &&
 	     !phy->mt76->offchannel))
 		req.switch_reason = CH_SWITCH_NORMAL;
 	else if (phy->mt76->offchannel)
@@ -1250,7 +1250,8 @@ int mt7921_mcu_set_sniffer(struct mt792x_dev *dev, struct ieee80211_vif *vif,
 int mt7921_mcu_config_sniffer(struct mt792x_vif *vif,
 			      struct ieee80211_chanctx_conf *ctx)
 {
-	struct cfg80211_chan_def *chandef = &ctx->def;
+	struct mt76_phy *mphy = vif->phy->mt76;
+	struct cfg80211_chan_def *chandef = ctx ? &ctx->def : &mphy->chandef;
 	int freq1 = chandef->center_freq1, freq2 = chandef->center_freq2;
 	static const u8 ch_band[] = {
 		[NL80211_BAND_2GHZ] = 1,
drivers/net/wireless/mediatek/mt76/mt7921/testmode.c +2 -2
index ce95b0db1428..7fd39538aeea 100644
@@ -121,7 +121,7 @@ int mt7921_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	int err;
 
 	if (!test_bit(MT76_STATE_RUNNING, &mphy->state) ||
-	    !(hw->conf.flags & IEEE80211_CONF_MONITOR))
+	    !mt792x_monitor_active(phy->dev))
 		return -ENOTCONN;
 
 	err = nla_parse_deprecated(tb, MT76_TM_ATTR_MAX, data, len,
@@ -158,7 +158,7 @@ int mt7921_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg,
 	int err;
 
 	if (!test_bit(MT76_STATE_RUNNING, &mphy->state) ||
-	    !(hw->conf.flags & IEEE80211_CONF_MONITOR) ||
+	    !mt792x_monitor_active(phy->dev) ||
 	    !mt76_testmode_enabled(mphy))
 		return -ENOTCONN;
 
drivers/net/wireless/mediatek/mt76/mt792x.h +10 -0
index 260abdc978f8..7bbbe7d059e5 100644
@@ -393,6 +393,7 @@ struct mt792x_dev {
 	u8 fw_features;
 	/* LED state last written to the GPIO, -1 if unknown */
 	s8 led_state;
+	u8 monitor_vifs;
 
 	struct mt76_connac_pm pm;
 	struct mt76_connac_coredump coredump;
@@ -571,6 +572,15 @@ mt792x_get_status_freq_info(struct mt76_rx_status *status, u8 chfreq)
 	status->freq = ieee80211_channel_to_frequency(chfreq, status->band);
 }
 
+/* A monitor that reaches the driver as its own vif does not set
+ * IEEE80211_CONF_MONITOR, so count those too.
+ */
+static inline bool mt792x_monitor_active(struct mt792x_dev *dev)
+{
+	return (mt76_hw(dev)->conf.flags & IEEE80211_CONF_MONITOR) ||
+	       dev->monitor_vifs;
+}
+
 static inline bool mt792x_dma_need_reinit(struct mt792x_dev *dev)
 {
 	return !mt76_get_field(dev, MT_WFDMA_DUMMY_CR, MT_WFDMA_NEED_REINIT);
Signature · 1 line
2.56.1
#2 lore raw

PATCH v2 2/4 wifi: mt76: mt7925: keep the sniffer on for real monitor vifs

In reply to Devin Wittmayer

mac80211 sets its monitor flag only for the virtual monitor. A monitor that reaches the driver as its own vif, as every monitor on MT7927 does, is not treated as one and goes deaf after a scan.

Count monitor vifs and treat one like the monitor flag. Start a new monitor's sniffer on the radio's current channel. Set it up again after a scan, and when another interface goes down, where mac80211 would add the virtual monitor back.

---
 .../wireless/mediatek/mt76/mt7925/debugfs.c   |  2 +-
 .../net/wireless/mediatek/mt76/mt7925/main.c  | 76 +++++++++++++++++--
 .../wireless/mediatek/mt76/mt7925/testmode.c  |  4 +-
 3 files changed, 72 insertions(+), 10 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/debugfs.c +1 -1
index 0c40741273a9..3739959283dc 100644
@@ -241,7 +241,7 @@ mt7925_deep_sleep_set(void *data, u64 val)
 	if (pm->ds_enable_user == enable)
 		goto out;
 
-	monitor = !!(dev->mphy.hw->conf.flags & IEEE80211_CONF_MONITOR);
+	monitor = mt792x_monitor_active(dev);
 	pm->ds_enable_user = enable;
 	pm->ds_enable = enable && !monitor;
 	mt7925_mcu_set_deep_sleep(dev, pm->ds_enable);
drivers/net/wireless/mediatek/mt76/mt7925/main.c +69 -7

135 lines not on this page · raw message

drivers/net/wireless/mediatek/mt76/mt7925/testmode.c +2 -2
index dbf1159effeb..0283bfc72779 100644
@@ -130,7 +130,7 @@ int mt7925_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	int err;
 
 	if (!test_bit(MT76_STATE_RUNNING, &mphy->state) ||
-	    !(hw->conf.flags & IEEE80211_CONF_MONITOR))
+	    !mt792x_monitor_active(phy->dev))
 		return -ENOTCONN;
 
 	err = nla_parse_deprecated(tb, MT76_TM_ATTR_MAX, data, len,
@@ -167,7 +167,7 @@ int mt7925_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg,
 	int err;
 
 	if (!test_bit(MT76_STATE_RUNNING, &mphy->state) ||
-	    !(hw->conf.flags & IEEE80211_CONF_MONITOR) ||
+	    !mt792x_monitor_active(phy->dev) ||
 	    !mt76_testmode_enabled(mphy))
 		return -ENOTCONN;
 
Signature · 1 line
2.56.1
#3 lore raw

PATCH v2 3/4 wifi: mt76: mt792x: pass monitors to the driver as real vifs

In reply to Devin Wittmayer

From: Mark Anthony Agarro <[email protected]>

An active monitor on mt7921, and on mt7925 other than MT7927, never gets a channel: its request goes to the shared virtual monitor, which it does not use.

Pass every mt792x monitor to the driver as its own vif, as MT7927 already does. Commit 55e95ce469d0 ("wifi: mt76: mt792x: improve monitor interface handling") did this and was reverted because capture stopped. Commit a7d35545c2ce ("wifi: mt76: mt7921: assert sniffer on chanctx change") and the previous two commits arm the sniffer it was missing.

---
 drivers/net/wireless/mediatek/mt76/mt792x_core.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mt792x_core.c +1 -4
index 7dddce02d600..3b27bfcbdb83 100644
@@ -891,10 +891,7 @@ int mt792x_init_wiphy(struct ieee80211_hw *hw)
 	ieee80211_hw_set(hw, HAS_RATE_CONTROL);
 	ieee80211_hw_set(hw, SUPPORTS_TX_ENCAP_OFFLOAD);
 	ieee80211_hw_set(hw, SUPPORTS_RX_DECAP_OFFLOAD);
-	if (is_mt7927(&dev->mt76))
-		ieee80211_hw_set(hw, NO_VIRTUAL_MONITOR);
-	else
-		ieee80211_hw_set(hw, WANT_MONITOR_VIF);
+	ieee80211_hw_set(hw, NO_VIRTUAL_MONITOR);
 	ieee80211_hw_set(hw, SUPPORTS_PS);
 	ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
 	ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
Signature · 1 line
2.56.1
#4 lore raw

PATCH v2 4/4 Revert "wifi: mt76: mt792x: do not advertise active monitor"

In reply to Devin Wittmayer

This reverts commit 6f6c9800e54c ("wifi: mt76: mt792x: do not advertise active monitor").

That commit hid active monitor, saying the firmware stops receiving in that mode. The monitor was missing a channel, which the previous commit gives it. Since 7.3, tools that ask for one, like owly and hcxdumptool -A, are refused.

Advertise it again. Without the previous commits a lone active monitor is accepted but hears nothing.

Fixes 6f6c9800e54c ("wifi: mt76: mt792x: do not advertise active monitor")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c    | 5 ++---
 drivers/net/wireless/mediatek/mt76/mt76.h        | 1 -
 drivers/net/wireless/mediatek/mt76/mt792x_core.c | 1 -
 3 files changed, 2 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +2 -3
index 948f9ed26095..cc551c7992ca 100644
@@ -449,9 +449,8 @@ mt76_phy_init(struct mt76_phy *phy, struct ieee80211_hw *hw)
 	SET_IEEE80211_DEV(hw, dev->dev);
 	SET_IEEE80211_PERM_ADDR(hw, phy->macaddr);
 
-	wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
-	if (!phy->no_active_monitor)
-		wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR;
+	wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR |
+			   NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
 	wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH |
 			WIPHY_FLAG_SUPPORTS_TDLS |
 			WIPHY_FLAG_AP_UAPSD;
drivers/net/wireless/mediatek/mt76/mt76.h +0 -1
index d82d22c14c9f..d122e59a5ffc 100644
@@ -883,7 +883,6 @@ struct mt76_phy {
 	struct cfg80211_chan_def main_chandef;
 	bool offchannel;
 	bool radar_enabled;
-	bool no_active_monitor;
 
 	struct delayed_work roc_work;
 	struct ieee80211_vif *roc_vif;
drivers/net/wireless/mediatek/mt76/mt792x_core.c +0 -1
index 3b27bfcbdb83..1cc4539845dd 100644
@@ -877,7 +877,6 @@ int mt792x_init_wiphy(struct ieee80211_hw *hw)
 
 	wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
 			   NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
-	phy->mt76->no_active_monitor = true;
 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SET_SCAN_DWELL);
 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_LEGACY);
 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_HT);
Signature · 1 line
2.56.1