Skip to contentSkip to conversation

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

PATCH In review Rory Little 2 participants 7 messages Apr 30, 2025 – May 7, 2025

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

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

The previous series introduced a compiler warning in the first patch, due to an unused return value. This series fixes that.

v2:
- Catch and return error value from mt7996_init_radio_phy_debugfs.

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   |  78 +++++++++++
 .../net/wireless/mediatek/mt76/mt7996/main.c  | 125 +++++++++---------
 .../wireless/mediatek/mt76/mt7996/mt7996.h    |   9 +-
 3 files changed, 151 insertions(+), 61 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH v2 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   | 25 +++++++++++++++++++
 .../wireless/mediatek/mt76/mt7996/mt7996.h    |  2 ++
 2 files changed, 27 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c +25 -0
index 4a28db17a287..3548b2bd9b72 100644
@@ -842,9 +842,28 @@ 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)
 {
+	int err;
 	struct dentry *dir;
+	struct mt7996_phy *phy;
 
 	dir = mt76_register_debugfs_fops(&dev->mphy, NULL);
 	if (!dir)
@@ -877,6 +896,12 @@ int mt7996_init_debugfs(struct mt7996_dev *dev)
 
 	dev->debugfs_dir = dir;
 
+	mt7996_for_each_phy(dev, phy) {
+		err = mt7996_init_radio_phy_debugfs(phy);
+		if (err)
+			return err;
+	}
+
 	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.45.2
#2 lore raw

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

kernel test robot noticed the following build warnings:

Hi Rory,

kernel test robot noticed the following build warnings:

[auto build test WARNING on wireless-next/main]
[also build test WARNING on wireless/main linus/master v6.15-rc5 next-20250506] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rory-Little/wifi-mt76-mt7996-Add-per-radio-phy-debugfs-directories/20250501-072345
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main
patch link:    https://lore.kernel.org/r/20250430232225.3943242-2-rory%40candelatech.com
patch subject: [PATCH mt76 v2 1/4] wifi: mt76: mt7996: Add per-radio phy debugfs directories.
config: openrisc-allyesconfig (https://download.01.org/0day-ci/archive/20250507/[email protected]/config)
compiler: or1k-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250507/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c: In function 'mt7996_init_debugfs':

>> drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c:851:52: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
     851 |         snprintf(fname, sizeof(fname), "radio_phy%d", phy->mt76->band_idx);
         |                                                    ^
   In function 'mt7996_init_radio_phy_debugfs',
       inlined from 'mt7996_init_debugfs' at drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c:900:9:
   drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c:851:9: note: 'snprintf' output between 11 and 13 bytes into a destination of size 12
     851 |         snprintf(fname, sizeof(fname), "radio_phy%d", phy->mt76->band_idx);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +/snprintf +851 drivers/net/wireless/mediatek/mt76/mt7996/debugfs.c

841
842 DEFINE_DEBUGFS_ATTRIBUTE(fops_rf_regval, mt7996_rf_regval_get,
843 mt7996_rf_regval_set, "0x%08llx\n");
844
845 static int
846 mt7996_init_radio_phy_debugfs(struct mt7996_phy *phy)
847 {
848 struct dentry *dir;
849 char fname[12];
850

 > 851		snprintf(fname, sizeof(fname), "radio_phy%d", phy->mt76->band_idx);

852 dir = debugfs_create_dir(fname, phy->dev->debugfs_dir);
853
854 if (IS_ERR_OR_NULL(dir))
855 return -ENOMEM;
856
857 phy->debugfs_dir = dir;
858
859 return 0;
860 }
861

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw

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

Quoted 1 line

kernel test robot noticed the following build warnings:

My apologies for letting these slip through again. Before I resubmit a V3 - in hindsight dumping debugfs additions in with a refactor and two bugfixes was probably poor form on my part. Are there any parts of this series that are wanted upstream, and should I break those out into individual patches?

- Rory

#4 lore raw

PATCH v2 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 3548b2bd9b72..7703db507fe6 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.45.2
#5 lore raw

PATCH v2 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 7703db507fe6..0c840a251929 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.45.2
#6 lore raw

PATCH v2 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.45.2