wifi: rtw88: channel and control frame filter lost on interface restart
cover wifi: rtw88: channel and control frame filter lost on interface restart
Two fixes for rtw88, both with the same root cause: after an interface stop/start cycle the chip is reset by power_off()/power_on(), but mac80211 only calls config() and configure_filter() when its own state changes. After the cycle nothing has changed from mac80211's point of view, so neither the radio channel nor the control frame filter is reprogrammed.
The user-visible effect is that iw reports the configured channel while the adapter listens elsewhere, with no error anywhere. This makes an RTL8814AU look like broken hardware in monitor mode.
Patch 1 programs the channel in rtw_ops_start(). The IPS resume path already does this in rtw_ips_pwr_up(); only the ieee80211_ops::start() path was missing it. It is deliberately not placed in rtw_core_start() so that the IPS path, and its rtw_coex_ips_notify(COEX_IPS_LEAVE) ordering, is left untouched.
Patch 2 restores REG_RXFLTMAP1 in rtw_core_start(), next to the RCR restore that exists for the same reason. It applies on top of ed51a86b787f ("wifi: rtw88: Enable receiving control frames in monitor mode"), which enables the filter but does not restore it after the chip is powered back on.
Test setup
==========
Raspberry Pi 4B, aarch64, Ubuntu 26.04.1, kernel 7.0.0-1020-raspi, in-kernel rtw88 with ed51a86b787f backported. Two adapters on the same host, both in monitor mode on channel 6, captured in parallel:
- ALFA AWUS1900 RTL8814AU rtw88_8814au - Linksys WUSB6300 RTL8812AU rtw88_8812au
Isolating the channel defect. Six runs, full USB unbind/rebind between each, 25 s captures:
run sequence after "ip link up" frames 1 set channel 6 3 2 set channel 6 again 0 3 set channel 6 twice in a row 3 4 no set channel at all 3 5 set channel 11 - a real change 431 6 WUSB6300 control, same as run 1 2438
Only an actual channel change reaches the hardware.
Both patches applied, five consecutive down/up cycles, 25 s captures, total frames and control frames:
cycle AWUS1900 WUSB6300
1 6639 / 4556 2274 / 1506
2 9622 / 7754 2937 / 2214
3 6847 / 4985 2166 / 1475
4 7420 / 5542 2493 / 1789
5 7703 / 5250 2440 / 1625Without the patches the control counts are 0 on both adapters, and the AWUS1900 total drops to 0-4 from the first cycle on.
Also verified
=============
- rtw_set_channel() takes no lock and every caller already holds
rtwdev->mutex, so the added call in rtw_ops_start() is correctly
serialised.
- Station mode unaffected: scans return 28 then 34 BSS (AWUS1900),
10 then 11 (WUSB6300). - Three rmmod/insmod cycles, clean.
- dmesg: no WARNING, BUG, Oops or call trace.
- checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks.
- Build: no code warnings.
NOT verified
============
- PCI and SDIO paths. Patch 2 touches rtw_core_start(), shared by all bus types. Only USB was exercised; no PCI or SDIO hardware was available.
- lockdep. CONFIG_PROVE_LOCKING is not enabled on the test kernel, so the absence of a deadlock rests on code review and on use, not on instrumentation.
- Other chips. Only RTL8814AU and RTL8812AU were exercised. Patch 2 also concerns RTL8723D, RTL8703B and RTL8821A by construction.
- Bisection. The Fixes: tag on patch 1 was derived by reading the history, not by bisecting.
The series is based on mainline 69f80fef3153 (v7.3-rc7). Happy to rebase onto wireless/main if that is preferred.
Tooling disclosure
==================
Per Documentation/process/generated-content.rst: the diagnosis, the code and the commit messages in this series were produced by an AI coding assistant over an interactive session. I was investigating why an RTL8814AU adapter captured nothing in monitor mode while an RTL8812AU on the same host captured normally; the assistant proposed and discarded two incorrect hypotheses (USB power, then a first-configuration-only effect) before the measurement table above isolated the real mechanism. It then wrote the fixes, built them, and ran the tests listed here on the hardware described. All numbers quoted are from that hardware, not from the model.
I have read and understood both changes and I am taking responsibility for them; the Signed-off-by tags below are mine. Both patches also carry
The patches, the raw measurements and this summary are also at
https://github.com/jeremyfa55/rtw88-monitor-fixes
Jeremy Fareau (2):
wifi: rtw88: program the channel when the device is started
wifi: rtw88: restore the control frame filter when the device is
started
drivers/net/wireless/realtek/rtw88/mac80211.c | 16 ++++++++++++++-- drivers/net/wireless/realtek/rtw88/main.c | 8 ++++++++ drivers/net/wireless/realtek/rtw88/main.h | 1 + 3 files changed, 23 insertions(+), 2 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/2 wifi: rtw88: program the channel when the device is started
The chip is reset by power_off()/power_on(), but mac80211 only calls ieee80211_ops::config() when its own channel state changes. After a stop/start cycle, such as
ip link set <dev> down
ip link set <dev> up
the channel is unchanged from mac80211's point of view, so the radio is never reprogrammed. The device then listens on whatever channel the hardware came up on while iw reports the configured one, and receives almost nothing.
Observed with an RTL8814AU (ALFA AWUS1900) in monitor mode on an aarch64 host. A 25 s capture on channel 6 after a down/up cycle yields 3 frames, and 431 frames as soon as any real channel change is requested. An RTL8812AU (Linksys WUSB6300) on the same host, the same channel and the same second yields 2438 frames.
Program the channel in rtw_ops_start(), like rtw_ips_pwr_up() already does when leaving IPS.
--- drivers/net/wireless/realtek/rtw88/mac80211.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/wireless/realtek/rtw88/mac80211.c +11 -0
@@ -57,6 +57,17 @@ static int rtw_ops_start(struct ieee80211_hw *hw)mutex_lock (&rtwdev->mutex); ret =rtw_core_start (rtwdev); + +/* The chip is reset by power_off()/power_on(), but mac80211 only calls +* ieee80211_ops::config() when its own channel state changes. After a +* stop/start cycle the channel is unchanged from mac80211's point of +* view, so the radio would never be reprogrammed and the device would +* receive nothing. Program it here, like rtw_ips_pwr_up() already does +* when leaving IPS. +*/ +if (!ret && hw->conf.chandef.chan) +rtw_set_channel (rtwdev); +mutex_unlock (&rtwdev->mutex);return ret;
Signature · 1 line
2.43.0
Re: [PATCH wireless 1/2] wifi: rtw88: program the channel when the device is started
Quoted 7 lines · Jeremy Fareau
The chip is reset by power_off()/power_on(), but mac80211 only calls
ieee80211_ops::config()when its own channel state changes. After a stop/start cycle, such asip link set <dev> down
ip link set <dev> up
I don't think there is need to say what stop/start cycle is in commit message.
Quoted 27 lines
the channel is unchanged from mac80211's point of view, so the radio is never reprogrammed. The device then listens on whatever channel the hardware came up on while iw reports the configured one, and receives almost nothing.
Observed with an RTL8814AU (ALFA AWUS1900) in monitor mode on an aarch64 host. A 25 s capture on channel 6 after a down/up cycle yields 3 frames, and 431 frames as soon as any real channel change is requested. An RTL8812AU (Linksys WUSB6300) on the same host, the same channel and the same second yields 2438 frames.
Program the channel in
rtw_ops_start(), likertw_ips_pwr_up()already does when leaving IPS.Fixes e3037485c68e ("rtw88: new Realtek 802.11ac driver")Assisted-by LLMSigned-off-by Jeremy Fareau <[email protected]>--- drivers/net/wireless/realtek/rtw88/mac80211.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/net/wireless/realtek/rtw88/mac80211.c +0
-0@@ -57,6 +57,17 @@ static int rtw_ops_start(struct ieee80211_hw *hw)
drivers/net/wireless/realtek/rtw88/mac80211.c static int rtw_ops_start(struct ieee80211_hw *hw) · line 67
Quoted 10 lines
drivers/net/wireless/realtek/rtw88/mac80211.c +8
-0mutex_lock (&rtwdev->mutex); ret =rtw_core_start (rtwdev); + +/* The chip is reset by power_off()/power_on(), but mac80211 only calls +* ieee80211_ops::config() when its own channel state changes. After a +* stop/start cycle the channel is unchanged from mac80211's point of +* view, so the radio would never be reprogrammed and the device would +* receive nothing. Program it here, like rtw_ips_pwr_up() already does +* when leaving IPS. +*/
We don't use that comment style anymore. Change it to:
/*
* text
* text
*/
Also that comment is rather extensive, maybe shorten it to something like:
/*
* The chip is reset by power_off() and power_on(), but mac80211 won't
* call config() after stop/start since its channel state is unchanged.
* Reprogram the channel here, as rtw_ips_pwr_up() does.
*/
drivers/net/wireless/realtek/rtw88/mac80211.c static int rtw_ops_start(struct ieee80211_hw *hw) · line 73
Quoted 6 lines
drivers/net/wireless/realtek/rtw88/mac80211.c +3
-0+if (!ret && hw->conf.chandef.chan) +rtw_set_channel (rtwdev); +mutex_unlock (&rtwdev->mutex);return ret;
Besides that I noticed that there are many double spaces after punctuation in commit message, so please fix that too. And should this cc stable?
Best regards,
Luka Gejak
Ping-Ke Shih
maintainerRE: [PATCH wireless 1/2] wifi: rtw88: program the channel when the device is started
In reply to Jeremy FareauQuoted 9 lines · Jeremy Fareau
The chip is reset by power_off()/power_on(), but mac80211 only calls
ieee80211_ops::config()when its own channel state changes. After a stop/start cycle, such asip link set <dev> down
ip link set <dev> upthe channel is unchanged from mac80211's point of view, so the radio is never reprogrammed.
Not sure why you use 'program' I have never seen the term using to set channel.
Quoted 6 lines
The device then listens on whatever channel the
hardware came up on while iw reports the configured one, and receives almost nothing.Observed with an RTL8814AU (ALFA AWUS1900) in monitor mode on an aarch64 host.
Only monitor mode doesn't work as your expectation, right?
Quoted 23 lines
A 25 s capture on channel 6 after a down/up cycle yields
3 frames, and 431 frames as soon as any real channel change is requested. An RTL8812AU (Linksys WUSB6300) on the same host, the same channel and the same second yields 2438 frames.Program the channel in
rtw_ops_start(), likertw_ips_pwr_up()already does when leaving IPS.Fixes e3037485c68e ("rtw88: new Realtek 802.11ac driver")Assisted-by LLMSigned-off-by Jeremy Fareau <[email protected]>--- drivers/net/wireless/realtek/rtw88/mac80211.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/net/wireless/realtek/rtw88/mac80211.c +0
-0@@ -57,6 +57,17 @@ static int rtw_ops_start(struct ieee80211_hw *hw)mutex_lock (&rtwdev->mutex);
drivers/net/wireless/realtek/rtw88/mac80211.c static int rtw_ops_start(struct ieee80211_hw *hw) · line 68
Quoted 10 lines
drivers/net/wireless/realtek/rtw88/mac80211.c +9
-0ret =rtw_core_start (rtwdev); + +/* The chip is reset by power_off()/power_on(), but mac80211 only calls +* ieee80211_ops::config() when its own channel state changes. After a +* stop/start cycle the channel is unchanged from mac80211's point of +* view, so the radio would never be reprogrammed and the device would +* receive nothing. Program it here, like rtw_ips_pwr_up() already does +* when leaving IPS. +*/ +if (!ret && hw->conf.chandef.chan)
I think we can flag that it is working on monitor mode in rtw_ops_{add,remove,change}_interface and do set_channel() only if monitor mode.
I suppose we can have a name containing 'monitor_mode', so the comment is not necessary.
An existing flag is "rtwdev->hw->conf.flags & IEEE80211_CONF_MONITOR". I'm not sure if it is enough here.
Quoted 7 lines
drivers/net/wireless/realtek/rtw88/mac80211.c +2
-1+rtw_set_channel (rtwdev); +mutex_unlock (&rtwdev->mutex);return ret; --2.43.0
PATCH 2/2 wifi: rtw88: restore the control frame filter when the device is started
In reply to Jeremy FareauCommit ed51a86b787f ("wifi: rtw88: Enable receiving control frames in monitor mode") writes REG_RXFLTMAP1 from configure_filter(), but that register is reset to the chip default by the chip's mac_init() during power_on(). mac80211 only calls ieee80211_ops::configure_filter() when its own filter flags change, so after a stop/start cycle the flags are unchanged and the control frame filter silently reverts: monitor mode stops delivering control frames again.
Keep track of the value configure_filter() last asked for and restore it in rtw_core_start(), next to the RCR restore, which exists for the same reason.
Measured on an RTL8814AU and an RTL8812AU in monitor mode on channel 6, 40 s captures taken after a down/up cycle. Control frames go from 0 to 23184 and from 0 to 483 respectively; without this change both are 0.
--- drivers/net/wireless/realtek/rtw88/mac80211.c | 5 +++-- drivers/net/wireless/realtek/rtw88/main.c | 8 ++++++++ drivers/net/wireless/realtek/rtw88/main.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw88/mac80211.c +3 -2
@@ -300,9 +300,10 @@ static void rtw_ops_configure_filter(struct ieee80211_hw *hw,if (changed_flags &FIF_CONTROL ) {if (*new_flags &FIF_CONTROL ) -rtw_write16 (rtwdev,REG_RXFLTMAP1 ,0xffff ); + rtwdev->hal.rxfltmap1_cur =0xffff ;else -rtw_write16 (rtwdev,REG_RXFLTMAP1 , rtwdev->hal.rxfltmap1); + rtwdev->hal.rxfltmap1_cur = rtwdev->hal.rxfltmap1; +rtw_write16 (rtwdev,REG_RXFLTMAP1 , rtwdev->hal.rxfltmap1_cur); }if (changed_flags &FIF_ALLMULTI ) {if (*new_flags &FIF_ALLMULTI )
drivers/net/wireless/realtek/rtw88/main.c +8 -0
@@ -1528,6 +1528,14 @@ int rtw_core_start(struct rtw_dev *rtwdev)/* rcr reset after powered on */ rtw_write32 (rtwdev,REG_RCR , rtwdev->hal.rcr); +/* REG_RXFLTMAP1 is reset by the chip's mac_init() during power_on(), +* and mac80211 only calls ieee80211_ops::configure_filter() when its +* own filter flags change. After a stop/start cycle the flags are +* unchanged, so restore the value configure_filter() last asked for. +*/ +if (rtwdev->hal.rxfltmap1_cur) +rtw_write16 (rtwdev,REG_RXFLTMAP1 , rtwdev->hal.rxfltmap1_cur); +ieee80211_queue_delayed_work (rtwdev->hw, &rtwdev->watch_dog_work,RTW_WATCH_DOG_DELAY_TIME );
drivers/net/wireless/realtek/rtw88/main.h +1 -0
@@ -1964,6 +1964,7 @@ struct rtw_sar {struct rtw_hal {u32 rcr;u16 rxfltmap1; +u16 rxfltmap1_cur;u32 chip_version;u8 cut_version;
Signature · 1 line
2.43.0
Re: [PATCH wireless 2/2] wifi: rtw88: restore the control frame filter when the device is started
Quoted 12 lines · Jeremy Fareau
Commit
ed51a86b787f("wifi: rtw88: Enable receiving control frames in monitor mode") writesREG_RXFLTMAP1fromconfigure_filter(), but that register is reset to the chip default by the chip'smac_init()duringpower_on(). mac80211 only callsieee80211_ops::configure_filter()when its own filter flags change, so after a stop/start cycle the flags are unchanged and the control frame filter silently reverts: monitor mode stops delivering control frames again.Keep track of the value
configure_filter()last asked for and restore it inrtw_core_start(), next to the RCR restore, which exists for the same reason.
Quoted 5 lines
Measured on an RTL8814AU and an RTL8812AU in monitor mode on channel 6, 40 s captures taken after a down/up cycle. Control frames go from 0 to 23184 and from 0 to 483 respectively; without this change both are 0.
Fixes ed51a86b787f ("wifi: rtw88: Enable receiving control frames in monitor mode")
Please add Cc: [email protected]
Quoted 14 lines
Assisted-by LLMSigned-off-by Jeremy Fareau <[email protected]>--- drivers/net/wireless/realtek/rtw88/mac80211.c | 5 +++-- drivers/net/wireless/realtek/rtw88/main.c | 8 ++++++++ drivers/net/wireless/realtek/rtw88/main.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-)drivers/net/wireless/realtek/rtw88/mac80211.c +0
-0@@ -300,9 +300,10 @@ static void rtw_ops_configure_filter(struct ieee80211_hw *hw,
drivers/net/wireless/realtek/rtw88/mac80211.c static void rtw_ops_configure_filter(struct ieee80211_hw *hw, · line 308
Quoted 10 lines
drivers/net/wireless/realtek/rtw88/mac80211.c +3
-2if (changed_flags &FIF_CONTROL ) {if (*new_flags &FIF_CONTROL ) -rtw_write16 (rtwdev,REG_RXFLTMAP1 ,0xffff ); + rtwdev->hal.rxfltmap1_cur =0xffff ;else -rtw_write16 (rtwdev,REG_RXFLTMAP1 , rtwdev->hal.rxfltmap1); + rtwdev->hal.rxfltmap1_cur = rtwdev->hal.rxfltmap1; +rtw_write16 (rtwdev,REG_RXFLTMAP1 , rtwdev->hal.rxfltmap1_cur); }if (changed_flags &FIF_ALLMULTI ) {
I would change the new rxfltmap1_cur because hal->rxfltmap1 is not a constant. The beamforming code edits it and writes the register with the edited value:
bf.c:140 rtwdev->hal.rxfltmap1 &= ~BIT_RXFLTMAP1_BF_REPORT_POLL;
bf.c:141 rtw_write16(rtwdev, REG_RXFLTMAP1, rtwdev->hal.rxfltmap1);
bf.c:273 rtwdev->hal.rxfltmap1 |= BIT_RXFLTMAP1_BF;
bf.c:274 rtw_write16(rtwdev, REG_RXFLTMAP1, rtwdev->hal.rxfltmap1);So after this patch the driver keeps two cached copies of one register. On an 8822C in monitor mode, configure_filter() caches 0xffff while bf.c has cleared the report poll bit in hal->rxfltmap1, so the next stop/start restores 0xffff and undoes that. The reverse happens too: a request with FIF_CONTROL off caches hal->rxfltmap1 as it stands at that moment, and later bf.c edits are lost at the next restart.
I would keep one variable and add one flag instead of a second shadow value. It would remember whether control frames were requested, and then on restore it would rebuild the register from that flag and hal->rxfltmap1.
drivers/net/wireless/realtek/rtw88/main.c int rtw_core_start(struct rtw_dev *rtwdev) · line 1535
Quoted 13 lines
drivers/net/wireless/realtek/rtw88/main.c +5
-0@@ -1528,6 +1528,14 @@ int rtw_core_start(struct rtw_dev *rtwdev)/* rcr reset after powered on */ rtw_write32 (rtwdev,REG_RCR , rtwdev->hal.rcr); +/* REG_RXFLTMAP1 is reset by the chip's mac_init() during power_on(), +* and mac80211 only calls ieee80211_ops::configure_filter() when its +* own filter flags change. After a stop/start cycle the flags are +* unchanged, so restore the value configure_filter() last asked for. +*/
Comment style, same as in patch 1.
drivers/net/wireless/realtek/rtw88/main.c int rtw_core_start(struct rtw_dev *rtwdev) · line 1538
Quoted 3 lines
drivers/net/wireless/realtek/rtw88/main.c +3
-0+if (rtwdev->hal.rxfltmap1_cur) +rtw_write16 (rtwdev,REG_RXFLTMAP1 , rtwdev->hal.rxfltmap1_cur); +
A nit: this line doubles as "configure_filter has run". It only works because no chip has a zero default (0x400, 0x0FFF, 0xFFFF), so an explicit flag would not depend on that.
Best regards,
Luka Gejak
Ping-Ke Shih
maintainerRE: [PATCH wireless 2/2] wifi: rtw88: restore the control frame filter when the device is started
In reply to Jeremy FareauQuoted 2 lines · Jeremy Fareau
Commit
ed51a86b787f("wifi: rtw88: Enable receiving control frames in monitor mode") writesREG_RXFLTMAP1fromconfigure_filter(),
Using LLM is okay, but please reword yourself. I don't think this sentence is necessary.
Quoted 3 lines
but that
register is reset to the chip default by the chip'smac_init()duringpower_on().
Maybe the default value of rtwdev->hal.rxfltmap1 should be set at rtw_core_init()? But I don't have clear thought how to switch between normal and monitor modes (or even sta + monitor mode).
Quoted 4 lines
mac80211 only calls
ieee80211_ops::configure_filter()when
its own filter flags change, so after a stop/start cycle the flags are unchanged and the control frame filter silently reverts: monitor mode stops delivering control frames again.
This problem is also only encountered in monitor mode, right? Let's do it under monitor mode condition?
Quoted 24 lines
Keep track of the value
configure_filter()last asked for and restore it inrtw_core_start(), next to the RCR restore, which exists for the same reason.Measured on an RTL8814AU and an RTL8812AU in monitor mode on channel 6, 40 s captures taken after a down/up cycle. Control frames go from 0 to 23184 and from 0 to 483 respectively; without this change both are 0.
Fixes ed51a86b787f ("wifi: rtw88: Enable receiving control frames in monitor mode")Assisted-by LLMSigned-off-by Jeremy Fareau <[email protected]>--- drivers/net/wireless/realtek/rtw88/mac80211.c | 5 +++-- drivers/net/wireless/realtek/rtw88/main.c | 8 ++++++++ drivers/net/wireless/realtek/rtw88/main.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-)drivers/net/wireless/realtek/rtw88/mac80211.c +0
-0
drivers/net/wireless/realtek/rtw88/mac80211.c static void rtw_ops_configure_filter(struct ieee80211_hw *hw, · line 303
Quoted 4 lines
drivers/net/wireless/realtek/rtw88/mac80211.c +0
-1@@ -300,9 +300,10 @@ static void rtw_ops_configure_filter(struct ieee80211_hw *hw,if (changed_flags &FIF_CONTROL ) {if (*new_flags &FIF_CONTROL ) -rtw_write16 (rtwdev,REG_RXFLTMAP1 ,0xffff );
REG_RXFLTMAP1 should be 0xffff in monitor mode, right?
Maybe, just set the value in monitor mode. No need rxfltmap1_cur to store current value. Maintaining two variables is hard and confusing...
Quoted 8 lines
drivers/net/wireless/realtek/rtw88/mac80211.c +3
-1+ rtwdev->hal.rxfltmap1_cur =0xffff ; else -rtw_write16 (rtwdev,REG_RXFLTMAP1 , rtwdev->hal.rxfltmap1); + rtwdev->hal.rxfltmap1_cur = rtwdev->hal.rxfltmap1; +rtw_write16 (rtwdev,REG_RXFLTMAP1 , rtwdev->hal.rxfltmap1_cur); }if (changed_flags &FIF_ALLMULTI ) {if (*new_flags &FIF_ALLMULTI )