Skip to contentSkip to conversation

wifi: rtw88: raise the TBTT hold time while beaconing

RFC PATCH In review Mehmet Fide 2 participants 3 messages Nov 19 – Nov 21 Realtek wireless driver (rtw88)

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 wifi: rtw88: raise the TBTT hold time while beaconing

From: Mehmet Fide <[email protected]>

rtw88 sets the hold time of REG_TBTT_PROHIBIT once at chip init, to 0x64 * 32 us = 3.2 ms, and keeps it while beaconing. A beacon that cannot start within the hold time after TBTT is not sent: on the air no beacon came later than 3.2 ms after its TBTT. On 2.4 GHz channel 6 a neighbour multi-BSS AP sends three beacons back to back, about 7.5 ms of air time. Each time its beacon period drifts across our TBTT, every ~157 s here, an RTL8822BU AP sends only 0-2 of 10 beacons per second for about 7 s.

The other Realtek drivers use a longer hold time while beaconing and write the init value back when beaconing stops: the vendor driver and rtl8xxxu 0x80 (4.1 ms), rtlwifi 0x1ff (16.4 ms). rtw8703b and rtw8723d define 0x80 for this but never use it.

Set the hold time to 0xff (8.2 ms) when beaconing starts and back to 0x64 when it stops, which also covers the off-channel periods in which mac80211 stops the beacon. In 330 s on channel 6 the RTL8822BU AP had 14 seconds with fewer than 6 of 10 beacons with 0x64 and none with 0xff; its beacons then went out up to 8.1 ms after TBTT.

---
RFC because I would like your view on the hardware before this goes further:

1. The captures suggest the MAC drops a beacon that cannot start within the hold time. Is that how it works, and does a longer hold time delay any other TX? iperf3 and ping through the AP were the same with 0x064, 0x0ff and 0x400.
2. Which value do you recommend while beaconing: a fixed one, or one derived from the beacon interval? With 0x0ff an RTL8821CU, a second RTL8821CU and an RTL8822CU had no such seconds either, but an RTL8822CE still had 6: its beacons were cut off at 8.2 ms.
3. The CSA series [1] downloads each countdown beacon 10 ms after TBTT, so a hold time above about 9 ms needs a later download there. If the reserved page is rewritten while a beacon still waits in the hold window, which beacon goes out, the old or the new one?

With [1] and 0x0ff, an RTL8822BU AP with a station made 128 countdowns of 5; the two that met the neighbour's beacons kept every count on the air, count beacons up to 5.0 ms late. Without this patch the one that did lost counts 2 and 1.

Tested on rtw-next with RTL8822BU, RTL8821CU and RTL8822CU (USB) and RTL8822CE (PCIe) as AP, lockdep on.

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

 drivers/net/wireless/realtek/rtw88/mac80211.c | 11 +++++++++--
 drivers/net/wireless/realtek/rtw88/reg.h      |  3 +++
 2 files changed, 12 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw88/mac80211.c +9 -2
index 3029fbdb288a..cb1deeffef71 100644
@@ -449,12 +449,19 @@ static void rtw_ops_bss_info_changed(struct ieee80211_hw *hw,
 	}
 
 	if (changed & BSS_CHANGED_BEACON_ENABLED) {
-		if (conf->enable_beacon)
+		if (conf->enable_beacon) {
 			rtw_write32_set(rtwdev, REG_FWHW_TXQ_CTRL,
 					BIT_EN_BCNQ_DL);
-		else
+			rtw_write32_mask(rtwdev, REG_TBTT_PROHIBIT,
+					 BIT_MASK_TBTT_HOLD_TIME_AP,
+					 TBTT_HOLD_TIME_BCN);
+		} else {
 			rtw_write32_clr(rtwdev, REG_FWHW_TXQ_CTRL,
 					BIT_EN_BCNQ_DL);
+			rtw_write32_mask(rtwdev, REG_TBTT_PROHIBIT,
+					 BIT_MASK_TBTT_HOLD_TIME_AP,
+					 TBTT_HOLD_TIME_STOP_BCN);
+		}
 	}
 	if (changed & BSS_CHANGED_CQM)
 		rtw_fw_beacon_filter_config(rtwdev, true, vif);
drivers/net/wireless/realtek/rtw88/reg.h +3 -0
index 877b82640e91..86cbe4e96b24 100644
@@ -491,6 +491,9 @@
 #define BIT_DIS_STBC_CFE	BIT(8)
 #define REG_TBTT_PROHIBIT	0x0540
 #define BIT_SHIFT_TBTT_HOLD_TIME_AP 8
+#define BIT_MASK_TBTT_HOLD_TIME_AP GENMASK(19, 8)
+#define TBTT_HOLD_TIME_STOP_BCN	0x064
+#define TBTT_HOLD_TIME_BCN	0x0ff
 #define REG_RD_NAV_NXT		0x0544
 #define REG_NAV_PROT_LEN	0x0546
 #define REG_BCN_CTRL		0x0550

base-commit: 0bdc579dbfc251a6b6838ee9459b6771b948c617

Signature · 1 line
2.56.0
#1 lore raw

Hi Mehmet,

Thanks for looking into this. Below are my thoughts.

November 19, 2026 at 11:29 AM, "Mehmet Fide" <[email protected]> wrote:

[ ... ]

Quoted 4 lines

1. The captures suggest the MAC drops a beacon that cannot start within the hold time. Is that how it works, and does a longer hold time delay any other TX? iperf3 and ping through the AP were the same with 0x064, 0x0ff and 0x400.

Your captures fit a beacon transmit deadline. The RTL8822CU vendor header says data queues can also wait during the hold, so I'd measure latency around TBTT under load.

Quoted 4 lines

2. Which value do you recommend while beaconing: a fixed one, or one derived from the beacon interval? With 0x0ff an RTL8821CU, a second RTL8821CU and an RTL8822CU had no such seconds either, but an RTL8822CE still had 6: its beacons were cut off at 8.2 ms.

I'd start with 0x0ff and cap it for short beacon intervals. At 10 TU that leaves 2.08 ms before the next TBTT. I'd measure beacon loss and data latency before raising it on RTL8822CE.

Quoted 4 lines

3. The CSA series [1] downloads each countdown beacon 10 ms after TBTT, so a hold time above about 9 ms needs a later download there. If the reserved page is rewritten while a beacon still waits in the hold window, which beacon goes out, the old or the new one?

I'd expect the old template if the MAC has already fetched it and still sends. Your v13 tests also saw missed beacons during a write.

At 100 TU a late CSA worker can pass rtw_fw_csa_hold() at 6 ms after TBTT, inside the 8.16 ms window. Could the guard account for the hold and beacon airtime before a rewrite or switch completion? It currently skips intervals of 20 ms or less.

[ ... ]

Quoted 16 lines
drivers/net/wireless/realtek/rtw88/mac80211.c +4 -2
index 3029fbdb288a..cb1deeffef71 100644
@@ -449,12 +449,19 @@ static void rtw_ops_bss_info_changed(struct ieee80211_hw *hw,
 	}
 
 	if (changed & BSS_CHANGED_BEACON_ENABLED) {
-		if (conf->enable_beacon)
+		if (conf->enable_beacon) {
 			rtw_write32_set(rtwdev, REG_FWHW_TXQ_CTRL,
 					BIT_EN_BCNQ_DL);
-		else
+			rtw_write32_mask(rtwdev, REG_TBTT_PROHIBIT,
+					 BIT_MASK_TBTT_HOLD_TIME_AP,
+					 TBTT_HOLD_TIME_BCN);

drivers/net/wireless/realtek/rtw88/mac80211.c static void rtw_ops_bss_info_changed(struct ieee80211_hw *hw, · line 467

Quoted 10 lines
drivers/net/wireless/realtek/rtw88/mac80211.c +5 -0
+		} else {
 			rtw_write32_clr(rtwdev, REG_FWHW_TXQ_CTRL,
 					BIT_EN_BCNQ_DL);
+			rtw_write32_mask(rtwdev, REG_TBTT_PROHIBIT,
+					 BIT_MASK_TBTT_HOLD_TIME_AP,
+					 TBTT_HOLD_TIME_STOP_BCN);
+		}
 	}
 	if (changed & BSS_CHANGED_CQM)
 		rtw_fw_beacon_filter_config(rtwdev, true, vif);

To me it looks like a station scan on RTL8822C can pause AP beacons through rtw_hw_scan_chan_switch() and rtw_core_enable_beacon(), leaving 0xff programmed. The vendor driver restores 0x64 on scan pause. Could we update the hold on scan pause and resume too?

Best regards,
Luka Gejak

#2 lore raw

Hi Luka,

Quoted 3 lines

Your captures fit a beacon transmit deadline. The RTL8822CU vendor header says data queues can also wait during the hold, so I'd measure latency around TBTT under load.

A station pinged the AP every 5 ms for 20 s, idle and with TCP in each direction, 0x064 and 0x0ff taking turns, on an RTL8822BU on channels 36 and 6 and an RTL8822CE on channel 6. Each ping was placed in the beacon interval from the sniffed beacons.

On channel 36 the idle median was 1.7 to 1.9 ms all through the first 10 ms after the TBTT, with both values. On channel 6, where the neighbour's beacons pass our TBTT, the RTL8822BU pings of the first 8 ms after it had a median of 3.4 to 6.7 ms with 0x0ff and 2.5 to 4.5 ms with 0x064, and 2.3 to 3.4 ms with both from 15 ms on. So data does wait there while the beacon waits for the medium. The RTL8822CE showed no such difference. Under TCP load the median was 20 to 80 ms from queueing, and neither the time after the TBTT nor the hold value stood out.

Quoted 3 lines

I'd start with 0x0ff and cap it for short beacon intervals. At 10 TU that leaves 2.08 ms before the next TBTT. I'd measure beacon loss and data latency before raising it on RTL8822CE.

v2 will use 0x0ff, capped at a quarter of the beacon interval but not below 0x064, and write it again when the interval changes. I will leave the RTL8822CE at that.

Quoted 7 lines

I'd expect the old template if the MAC has already fetched it and still sends. Your v13 tests also saw missed beacons during a write.

At 100 TU a late CSA worker can pass rtw_fw_csa_hold() at 6 ms after TBTT, inside the 8.16 ms window. Could the guard account for the hold and beacon airtime before a rewrite or switch completion? It currently skips intervals of 20 ms or less.

I have no measurement of which beacon goes out then. rtw_fw_write_data_rsvd_page() clears BIT_EN_BCN_FUNCTION for the download, so I would keep downloads out of that window. v14 of the CSA series scales its margins with the interval and runs no step less than 5 ms after a TBTT. That covers 0x064 and a beacon of about 200 bytes at 1 Mb/s, not 0x0ff, so v2 of this patch will make the guard the hold time plus the beacon airtime, and I will repeat the countdowns while the neighbour's beacons pass our TBTT.

Quoted 4 lines

To me it looks like a station scan on RTL8822C can pause AP beacons through rtw_hw_scan_chan_switch() and rtw_core_enable_beacon(), leaving 0xff programmed. The vendor driver restores 0x64 on scan pause. Could we update the hold on scan pause and resume too?

Yes. With this patch on an RTL8822CE and an RTL8822CU, a station scan next to the AP cleared BIT_EN_BCN_FUNCTION off channel while the hold stayed 0x0ff. v2 will also write the hold in rtw_core_enable_beacon():
0x064 when a scan pauses the beacons, the beaconing value when it resumes them.

Mehmet