Skip to contentSkip to conversation

wifi: mt76: mt7996: rx filter fixes and improvements.

PATCH Superseded Rory Little 1 participant 5 messages Apr 16, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover wifi: mt76: mt7996: rx filter fixes and improvements.

Current rx filter logic can end up in different states depending on the order of interfaces added to the phy. These patches are primarily aimed at fixing that issue, as well as refactoring the logic to prevent issues like that from happening in the future.

The first two patches add per-radio-phy debugfs files for debugging the rxfilter member. The third contains the main refactor, and the fourth fixes another issue related to the order in which interfaces are added to the phy.

Rory Little (4):
wifi: mt76: mt7996: Add per-radio phy debugfs directories.
wifi: mt76: mt7996: Add debugfs file for rxfilter.
wifi: mt76: mt7996: Refactor of rx filter logic.
wifi: mt76: mt7996: Allow monitor enable if phy is already running.

 .../wireless/mediatek/mt76/mt7996/debugfs.c   |  74 +++++++++++
 .../net/wireless/mediatek/mt76/mt7996/main.c  | 125 +++++++++---------
 .../wireless/mediatek/mt76/mt7996/mt7996.h    |   9 +-
 3 files changed, 147 insertions(+), 61 deletions(-)
Signature · 1 line
2.48.1
#1 lore raw

PATCH 1/4 wifi: mt76: mt7996: Add per-radio phy debugfs directories.

These can be used instead of reporting just from the first phy, or using one file for all phys, as has been done previously.

---
 .../wireless/mediatek/mt76/mt7996/debugfs.c   | 21 +++++++++++++++++++
 .../wireless/mediatek/mt76/mt7996/mt7996.h    |  2 ++
 2 files changed, 23 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c +21 -0
index 4a28db17a287..d5503cfc0848 100644
@@ -842,9 +842,27 @@ mt7996_rf_regval_set(void *data, u64 val)
 DEFINE_DEBUGFS_ATTRIBUTE(fops_rf_regval, mt7996_rf_regval_get,
 			 mt7996_rf_regval_set, "0x%08llx\n");
 
+static int
+mt7996_init_radio_phy_debugfs(struct mt7996_phy *phy)
+{
+	struct dentry *dir;
+	char fname[12];
+
+	snprintf(fname, sizeof(fname), "radio_phy%d", phy->mt76->band_idx);
+	dir = debugfs_create_dir(fname, phy->dev->debugfs_dir);
+
+	if (IS_ERR_OR_NULL(dir))
+		return -ENOMEM;
+
+	phy->debugfs_dir = dir;
+
+	return 0;
+}
+
 int mt7996_init_debugfs(struct mt7996_dev *dev)
 {
 	struct dentry *dir;
+	struct mt7996_phy *phy;
 
 	dir = mt76_register_debugfs_fops(&dev->mphy, NULL);
 	if (!dir)
@@ -877,6 +895,9 @@ int mt7996_init_debugfs(struct mt7996_dev *dev)
 
 	dev->debugfs_dir = dir;
 
+	mt7996_for_each_phy(dev, phy)
+		mt7996_init_radio_phy_debugfs(phy);
+
 	return 0;
 }
 
drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +2 -0
index 43e646ed6094..3300b7c8e4d2 100644
@@ -296,6 +296,8 @@ struct mt7996_phy {
 
 	bool has_aux_rx;
 	bool counter_reset;
+
+	struct dentry *debugfs_dir;
 };
 
 struct mt7996_dev {
Signature · 1 line
2.48.1
#2 lore raw

PATCH 2/4 wifi: mt76: mt7996: Add debugfs file for rxfilter.

In reply to Rory Little

Will report both control registers, and list both the raw u32 value as well as reporting each flag in plain text.

---
 .../wireless/mediatek/mt76/mt7996/debugfs.c   | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c +44 -0
index d5503cfc0848..c16606792539 100644
@@ -842,6 +842,48 @@ mt7996_rf_regval_set(void *data, u64 val)
 DEFINE_DEBUGFS_ATTRIBUTE(fops_rf_regval, mt7996_rf_regval_get,
 			 mt7996_rf_regval_set, "0x%08llx\n");
 
+static int
+mt7996_rxfilter_show(struct seq_file *file, void *data)
+{
+	struct mt7996_phy *phy = file->private;
+
+	mutex_lock(&phy->dev->mt76.mutex);
+
+	seq_printf(file, "CR: 0x%08x\n", phy->rxfilter);
+
+#define MT7996_RFCR_PRINT(flag) do {			\
+		if (phy->rxfilter & MT_WF_RFCR_##flag)	\
+			seq_printf(file, #flag "\n");	\
+	} while (0)
+
+	MT7996_RFCR_PRINT(DROP_STBC_MULTI);
+	MT7996_RFCR_PRINT(DROP_FCSFAIL);
+	MT7996_RFCR_PRINT(DROP_PROBEREQ);
+	MT7996_RFCR_PRINT(DROP_MCAST);
+	MT7996_RFCR_PRINT(DROP_BCAST);
+	MT7996_RFCR_PRINT(DROP_MCAST_FILTERED);
+	MT7996_RFCR_PRINT(DROP_A3_MAC);
+	MT7996_RFCR_PRINT(DROP_A3_BSSID);
+	MT7996_RFCR_PRINT(DROP_A2_BSSID);
+	MT7996_RFCR_PRINT(DROP_OTHER_BEACON);
+	MT7996_RFCR_PRINT(DROP_FRAME_REPORT);
+	MT7996_RFCR_PRINT(DROP_CTL_RSV);
+	MT7996_RFCR_PRINT(DROP_CTS);
+	MT7996_RFCR_PRINT(DROP_RTS);
+	MT7996_RFCR_PRINT(DROP_DUPLICATE);
+	MT7996_RFCR_PRINT(DROP_OTHER_BSS);
+	MT7996_RFCR_PRINT(DROP_OTHER_UC);
+	MT7996_RFCR_PRINT(DROP_OTHER_TIM);
+	MT7996_RFCR_PRINT(DROP_NDPA);
+	MT7996_RFCR_PRINT(DROP_UNWANTED_CTL);
+
+	mutex_unlock(&phy->dev->mt76.mutex);
+
+	return 0;
+}
+
+DEFINE_SHOW_ATTRIBUTE(mt7996_rxfilter);
+
 static int
 mt7996_init_radio_phy_debugfs(struct mt7996_phy *phy)
 {
@@ -854,6 +896,8 @@ mt7996_init_radio_phy_debugfs(struct mt7996_phy *phy)
 	if (IS_ERR_OR_NULL(dir))
 		return -ENOMEM;
 
+	debugfs_create_file("rxfilter", 0400, dir, phy, &mt7996_rxfilter_fops);
+
 	phy->debugfs_dir = dir;
 
 	return 0;
Signature · 1 line
2.48.1
#3 lore raw

PATCH 3/4 wifi: mt76: mt7996: Refactor of rx filter logic.

In reply to Rory Little

The existing logic for configuring the rx filter is hard to follow and contained at least one sneaky bug: since mt7996_set_monitor(_, false) is only called when a monitor is removed, MT_WF_RFCR_DROP_OTHER_UC would not be configured on a fresh boot. This meant that the rxfilter was too verbose until a monitor had been added and removed. This refactor hopes to avoid sequence-of-action bugs like this by:

1. Placing all logic that directly alters the rx filter in one function, so that state does not need to be tracked across methods.
2. Explicitly tracking all values sent to the control registers within the radio phy, for easier debugging.
3. Realizing the rx filter control registers freshly every time that mt7996_phy_set_rxfilter() is called.

In order to perform goals (1) and (3), new state needed to be added to the radio phy to remember the mac80211 rxfilter flags that had been requested, and to track if the radio is acting as a monitor.

Since the existing MT76_FILTER macro could not handle all cases where the rxfilter needs to be configured, it was not used here.

Fixes 69d54ce7491d ("wifi: mt76: mt7996: switch to single multi-radio wiphy")
---
 .../wireless/mediatek/mt76/mt7996/debugfs.c   |  15 ++-
 .../net/wireless/mediatek/mt76/mt7996/main.c  | 114 +++++++++---------
 .../wireless/mediatek/mt76/mt7996/mt7996.h    |   7 +-
 3 files changed, 77 insertions(+), 59 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c +12 -3
index c16606792539..bb02878fd8a4 100644
@@ -849,12 +849,14 @@ mt7996_rxfilter_show(struct seq_file *file, void *data)
 
 	mutex_lock(&phy->dev->mt76.mutex);
 
-	seq_printf(file, "CR: 0x%08x\n", phy->rxfilter);
+	seq_printf(file, "CR: 0x%08x\n", phy->rxfilter.cr);
 
-#define MT7996_RFCR_PRINT(flag) do {			\
-		if (phy->rxfilter & MT_WF_RFCR_##flag)	\
+#define __MT7996_RXFILTER_PRINT(reg, flag) do {		\
+		if (phy->rxfilter.reg & (flag))		\
 			seq_printf(file, #flag "\n");	\
 	} while (0)
+#define MT7996_RFCR_PRINT(flag) __MT7996_RXFILTER_PRINT(cr, MT_WF_RFCR_##flag)
+#define MT7996_RFCR1_PRINT(flag) __MT7996_RXFILTER_PRINT(cr1, MT_WF_RFCR1_##flag)
 
 	MT7996_RFCR_PRINT(DROP_STBC_MULTI);
 	MT7996_RFCR_PRINT(DROP_FCSFAIL);
@@ -877,6 +879,13 @@ mt7996_rxfilter_show(struct seq_file *file, void *data)
 	MT7996_RFCR_PRINT(DROP_NDPA);
 	MT7996_RFCR_PRINT(DROP_UNWANTED_CTL);
 
+	seq_printf(file, "\nCR1: 0x%08x\n", phy->rxfilter.cr1);
+	MT7996_RFCR1_PRINT(DROP_ACK);
+	MT7996_RFCR1_PRINT(DROP_BF_POLL);
+	MT7996_RFCR1_PRINT(DROP_BA);
+	MT7996_RFCR1_PRINT(DROP_CFEND);
+	MT7996_RFCR1_PRINT(DROP_CFACK);
+
 	mutex_unlock(&phy->dev->mt76.mutex);
 
 	return 0;
drivers/net/wireless/mediatek/mt76/mt7996/main.c +59 -55

143 lines not on this page · raw message

drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h +6 -1
index 3300b7c8e4d2..2b2108f96255 100644
@@ -273,7 +273,12 @@ struct mt7996_phy {
 	u8 throttle_state;
 	u32 throttle_temp[2]; /* 0: critical high, 1: maximum */
 
-	u32 rxfilter;
+	bool monitor_enabled;
+	u32 mac80211_rxfilter_flags;
+	struct {
+		u32 cr;
+		u32 cr1;
+	} rxfilter; /* Rx filter control registers */
 	u64 omac_mask;
 
 	u16 noise;
Signature · 1 line
2.48.1
#4 lore raw

PATCH 4/4 wifi: mt76: mt7996: Allow monitor enable if phy is already running.

In reply to Rory Little

This path was being skipped if, for example, a monitor was created on a phy which already contained a station.

Fixes 69d54ce7491d ("wifi: mt76: mt7996: switch to single multi-radio wiphy")
---
 drivers/net/wireless/mediatek/mt76/mt7996/main.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +6 -5
index cbc9826320a7..16314fdc090c 100644
@@ -478,13 +478,14 @@ static int mt7996_add_interface(struct ieee80211_hw *hw,
 	for (i = 0; i < MT7996_MAX_RADIOS; i++) {
 		struct mt7996_phy *phy = dev->radio_phy[i];
 
-		if (!phy || !(wdev->radio_mask & BIT(i)) ||
-		    test_bit(MT76_STATE_RUNNING, &phy->mt76->state))
+		if (!phy || !(wdev->radio_mask & BIT(i)))
 			continue;
 
-		err = mt7996_run(phy);
-		if (err)
-			goto out;
+		if (!test_bit(MT76_STATE_RUNNING, &phy->mt76->state)) {
+			err = mt7996_run(phy);
+			if (err)
+				goto out;
+		}
 
 		if (vif->type == NL80211_IFTYPE_MONITOR)
 			mt7996_set_monitor(phy, true);
Signature · 1 line
2.48.1