xref: /linux/drivers/net/wireless/realtek/rtw89/ps.c (revision d30c1683aaecb93d2ab95685dc4300a33d3cea7a)
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /* Copyright(c) 2019-2020  Realtek Corporation
3  */
4 
5 #include "chan.h"
6 #include "coex.h"
7 #include "core.h"
8 #include "debug.h"
9 #include "fw.h"
10 #include "mac.h"
11 #include "phy.h"
12 #include "ps.h"
13 #include "reg.h"
14 #include "ser.h"
15 #include "util.h"
16 
17 static int rtw89_fw_receive_lps_h2c_check(struct rtw89_dev *rtwdev, u8 macid)
18 {
19 	struct rtw89_mac_c2h_info c2h_info = {};
20 	u16 c2hreg_macid;
21 	u32 c2hreg_ret;
22 	int ret;
23 
24 	if (!RTW89_CHK_FW_FEATURE(LPS_DACK_BY_C2H_REG, &rtwdev->fw))
25 		return 0;
26 
27 	c2h_info.id = RTW89_FWCMD_C2HREG_FUNC_PS_LEAVE_ACK;
28 	ret = rtw89_fw_msg_reg(rtwdev, NULL, &c2h_info);
29 	if (ret)
30 		goto fw_fail;
31 
32 	c2hreg_macid = u32_get_bits(c2h_info.u.c2hreg[0],
33 				    RTW89_C2HREG_PS_LEAVE_ACK_MACID);
34 	c2hreg_ret = u32_get_bits(c2h_info.u.c2hreg[1], RTW89_C2HREG_PS_LEAVE_ACK_RET);
35 
36 	if (macid != c2hreg_macid || c2hreg_ret) {
37 		rtw89_warn(rtwdev, "rtw89: check lps h2c received by firmware fail\n");
38 		ret = -EINVAL;
39 		goto fw_fail;
40 	}
41 	rtwdev->ps_hang_cnt = 0;
42 
43 	return 0;
44 
45 fw_fail:
46 	rtwdev->ps_hang_cnt++;
47 	if (rtwdev->ps_hang_cnt >= RTW89_PS_HANG_MAX_CNT)
48 		rtw89_ser_notify(rtwdev, MAC_AX_ERR_ASSERTION);
49 
50 	return ret;
51 }
52 
53 static int rtw89_fw_leave_lps_check(struct rtw89_dev *rtwdev, u8 macid)
54 {
55 	const struct rtw89_mac_gen_def *mac = rtwdev->chip->mac_def;
56 	u32 pwr_en_bit = 0xE;
57 	u32 chk_msk = pwr_en_bit << (4 * macid);
58 	u32 polling;
59 	int ret;
60 
61 	ret = read_poll_timeout_atomic(rtw89_read32_mask, polling, !polling,
62 				       1000, 50000, false, rtwdev,
63 				       mac->ps_status, chk_msk);
64 	if (ret) {
65 		rtw89_info(rtwdev, "rtw89: failed to leave lps state\n");
66 
67 		rtwdev->ps_hang_cnt++;
68 		if (rtwdev->ps_hang_cnt >= RTW89_PS_HANG_MAX_CNT)
69 			rtw89_ser_notify(rtwdev, MAC_AX_ERR_ASSERTION);
70 
71 		return -EBUSY;
72 	}
73 
74 	rtwdev->ps_hang_cnt = 0;
75 
76 	return 0;
77 }
78 
79 static void rtw89_ps_power_mode_change_with_hci(struct rtw89_dev *rtwdev,
80 						bool enter)
81 {
82 	ieee80211_stop_queues(rtwdev->hw);
83 	rtwdev->hci.paused = true;
84 	flush_work(&rtwdev->txq_work);
85 	ieee80211_wake_queues(rtwdev->hw);
86 
87 	rtw89_hci_pause(rtwdev, true);
88 	rtw89_mac_power_mode_change(rtwdev, enter);
89 	rtw89_hci_switch_mode(rtwdev, enter);
90 	rtw89_hci_pause(rtwdev, false);
91 
92 	rtwdev->hci.paused = false;
93 
94 	if (!enter) {
95 		local_bh_disable();
96 		napi_schedule(&rtwdev->napi);
97 		local_bh_enable();
98 	}
99 }
100 
101 static void rtw89_ps_power_mode_change(struct rtw89_dev *rtwdev, bool enter)
102 {
103 	if (rtwdev->chip->low_power_hci_modes & BIT(rtwdev->ps_mode) &&
104 	    !test_bit(RTW89_FLAG_WOWLAN, rtwdev->flags))
105 		rtw89_ps_power_mode_change_with_hci(rtwdev, enter);
106 	else
107 		rtw89_mac_power_mode_change(rtwdev, enter);
108 }
109 
110 void __rtw89_enter_ps_mode(struct rtw89_dev *rtwdev)
111 {
112 	if (!rtwdev->ps_mode)
113 		return;
114 
115 	if (test_and_set_bit(RTW89_FLAG_LOW_POWER_MODE, rtwdev->flags))
116 		return;
117 
118 	rtw89_ps_power_mode_change(rtwdev, true);
119 }
120 
121 void __rtw89_leave_ps_mode(struct rtw89_dev *rtwdev)
122 {
123 	if (!rtwdev->ps_mode)
124 		return;
125 
126 	if (test_and_clear_bit(RTW89_FLAG_LOW_POWER_MODE, rtwdev->flags))
127 		rtw89_ps_power_mode_change(rtwdev, false);
128 }
129 
130 static void __rtw89_enter_lps_link(struct rtw89_dev *rtwdev,
131 				   struct rtw89_vif_link *rtwvif_link)
132 {
133 	struct rtw89_lps_parm lps_param = {
134 		.macid = rtwvif_link->mac_id,
135 		.psmode = RTW89_MAC_AX_PS_MODE_LEGACY,
136 		.lastrpwm = RTW89_LAST_RPWM_PS,
137 	};
138 
139 	rtw89_btc_ntfy_radio_state(rtwdev, BTC_RFCTRL_FW_CTRL);
140 	rtw89_fw_h2c_lps_parm(rtwdev, &lps_param);
141 
142 	if (RTW89_CHK_FW_FEATURE(BEACON_TRACKING, &rtwdev->fw))
143 		rtw89_fw_h2c_pwr_lvl(rtwdev, rtwvif_link);
144 }
145 
146 static void __rtw89_leave_lps(struct rtw89_dev *rtwdev,
147 			      struct rtw89_vif_link *rtwvif_link)
148 {
149 	struct rtw89_lps_parm lps_param = {
150 		.macid = rtwvif_link->mac_id,
151 		.psmode = RTW89_MAC_AX_PS_MODE_ACTIVE,
152 		.lastrpwm = RTW89_LAST_RPWM_ACTIVE,
153 	};
154 
155 	rtw89_fw_h2c_lps_parm(rtwdev, &lps_param);
156 	rtw89_fw_receive_lps_h2c_check(rtwdev, rtwvif_link->mac_id);
157 	rtw89_fw_leave_lps_check(rtwdev, rtwvif_link->mac_id);
158 	rtw89_btc_ntfy_radio_state(rtwdev, BTC_RFCTRL_WL_ON);
159 	rtw89_chip_digital_pwr_comp(rtwdev, rtwvif_link->phy_idx);
160 }
161 
162 void rtw89_leave_ps_mode(struct rtw89_dev *rtwdev)
163 {
164 	lockdep_assert_wiphy(rtwdev->hw->wiphy);
165 
166 	__rtw89_leave_ps_mode(rtwdev);
167 }
168 
169 void rtw89_enter_lps(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif,
170 		     bool ps_mode)
171 {
172 	struct rtw89_vif_link *rtwvif_link;
173 	bool can_ps_mode = true;
174 	unsigned int link_id;
175 
176 	lockdep_assert_wiphy(rtwdev->hw->wiphy);
177 
178 	if (test_and_set_bit(RTW89_FLAG_LEISURE_PS, rtwdev->flags))
179 		return;
180 
181 	rtw89_vif_for_each_link(rtwvif, rtwvif_link, link_id) {
182 		__rtw89_enter_lps_link(rtwdev, rtwvif_link);
183 
184 		if (rtwvif_link->wifi_role == RTW89_WIFI_ROLE_P2P_CLIENT)
185 			can_ps_mode = false;
186 	}
187 
188 	rtw89_fw_h2c_rf_ps_info(rtwdev, rtwvif);
189 
190 	if (RTW89_CHK_FW_FEATURE(LPS_CH_INFO, &rtwdev->fw))
191 		rtw89_fw_h2c_lps_ch_info(rtwdev, rtwvif);
192 	else
193 		rtw89_fw_h2c_lps_ml_cmn_info(rtwdev, rtwvif);
194 
195 	if (ps_mode && can_ps_mode)
196 		__rtw89_enter_ps_mode(rtwdev);
197 }
198 
199 static void rtw89_leave_lps_vif(struct rtw89_dev *rtwdev,
200 				struct rtw89_vif_link *rtwvif_link)
201 {
202 	if (rtwvif_link->wifi_role != RTW89_WIFI_ROLE_STATION &&
203 	    rtwvif_link->wifi_role != RTW89_WIFI_ROLE_P2P_CLIENT)
204 		return;
205 
206 	__rtw89_leave_lps(rtwdev, rtwvif_link);
207 }
208 
209 void rtw89_leave_lps(struct rtw89_dev *rtwdev)
210 {
211 	struct rtw89_vif_link *rtwvif_link;
212 	struct rtw89_vif *rtwvif;
213 	unsigned int link_id;
214 
215 	lockdep_assert_wiphy(rtwdev->hw->wiphy);
216 
217 	if (!test_and_clear_bit(RTW89_FLAG_LEISURE_PS, rtwdev->flags))
218 		return;
219 
220 	__rtw89_leave_ps_mode(rtwdev);
221 
222 	rtw89_phy_dm_reinit(rtwdev);
223 
224 	rtw89_for_each_rtwvif(rtwdev, rtwvif)
225 		rtw89_vif_for_each_link(rtwvif, rtwvif_link, link_id)
226 			rtw89_leave_lps_vif(rtwdev, rtwvif_link);
227 }
228 
229 void rtw89_enter_ips(struct rtw89_dev *rtwdev)
230 {
231 	struct rtw89_vif_link *rtwvif_link;
232 	struct rtw89_vif *rtwvif;
233 	unsigned int link_id;
234 
235 	set_bit(RTW89_FLAG_INACTIVE_PS, rtwdev->flags);
236 
237 	if (!test_bit(RTW89_FLAG_POWERON, rtwdev->flags))
238 		return;
239 
240 	rtw89_for_each_rtwvif(rtwdev, rtwvif)
241 		rtw89_vif_for_each_link(rtwvif, rtwvif_link, link_id)
242 			rtw89_mac_vif_deinit(rtwdev, rtwvif_link);
243 
244 	rtw89_core_stop(rtwdev);
245 }
246 
247 void rtw89_leave_ips(struct rtw89_dev *rtwdev)
248 {
249 	struct rtw89_vif_link *rtwvif_link;
250 	struct rtw89_vif *rtwvif;
251 	unsigned int link_id;
252 	int ret;
253 
254 	if (test_bit(RTW89_FLAG_POWERON, rtwdev->flags))
255 		return;
256 
257 	ret = rtw89_core_start(rtwdev);
258 	if (ret)
259 		rtw89_err(rtwdev, "failed to leave idle state\n");
260 
261 	rtw89_set_channel(rtwdev);
262 
263 	rtw89_for_each_rtwvif(rtwdev, rtwvif)
264 		rtw89_vif_for_each_link(rtwvif, rtwvif_link, link_id)
265 			rtw89_mac_vif_init(rtwdev, rtwvif_link);
266 
267 	clear_bit(RTW89_FLAG_INACTIVE_PS, rtwdev->flags);
268 }
269 
270 void rtw89_set_coex_ctrl_lps(struct rtw89_dev *rtwdev, bool btc_ctrl)
271 {
272 	if (btc_ctrl)
273 		rtw89_leave_lps(rtwdev);
274 }
275 
276 static void rtw89_tsf32_toggle(struct rtw89_dev *rtwdev,
277 			       struct rtw89_vif_link *rtwvif_link,
278 			       enum rtw89_p2pps_action act)
279 {
280 	if (act == RTW89_P2P_ACT_UPDATE || act == RTW89_P2P_ACT_REMOVE)
281 		return;
282 
283 	if (act == RTW89_P2P_ACT_INIT)
284 		rtw89_fw_h2c_tsf32_toggle(rtwdev, rtwvif_link, true);
285 	else if (act == RTW89_P2P_ACT_TERMINATE)
286 		rtw89_fw_h2c_tsf32_toggle(rtwdev, rtwvif_link, false);
287 }
288 
289 void rtw89_p2p_disable_all_noa(struct rtw89_dev *rtwdev,
290 			       struct rtw89_vif_link *rtwvif_link,
291 			       struct ieee80211_bss_conf *bss_conf)
292 {
293 	enum rtw89_p2pps_action act;
294 	u8 oppps_ctwindow;
295 	u8 noa_id;
296 
297 	rcu_read_lock();
298 
299 	if (!bss_conf)
300 		bss_conf = rtw89_vif_rcu_dereference_link(rtwvif_link, true);
301 
302 	oppps_ctwindow = bss_conf->p2p_noa_attr.oppps_ctwindow;
303 
304 	rcu_read_unlock();
305 
306 	if (rtwvif_link->last_noa_nr == 0)
307 		return;
308 
309 	for (noa_id = 0; noa_id < rtwvif_link->last_noa_nr; noa_id++) {
310 		if (noa_id == rtwvif_link->last_noa_nr - 1)
311 			act = RTW89_P2P_ACT_TERMINATE;
312 		else
313 			act = RTW89_P2P_ACT_REMOVE;
314 		rtw89_tsf32_toggle(rtwdev, rtwvif_link, act);
315 		rtw89_fw_h2c_p2p_act(rtwdev, rtwvif_link, NULL,
316 				     act, noa_id, oppps_ctwindow);
317 	}
318 }
319 
320 static void rtw89_p2p_update_noa(struct rtw89_dev *rtwdev,
321 				 struct rtw89_vif_link *rtwvif_link,
322 				 struct ieee80211_bss_conf *bss_conf)
323 {
324 	struct ieee80211_p2p_noa_desc *desc;
325 	enum rtw89_p2pps_action act;
326 	u8 noa_id;
327 
328 	for (noa_id = 0; noa_id < RTW89_P2P_MAX_NOA_NUM; noa_id++) {
329 		desc = &bss_conf->p2p_noa_attr.desc[noa_id];
330 		if (!desc->count || !desc->duration)
331 			break;
332 
333 		if (noa_id == 0)
334 			act = RTW89_P2P_ACT_INIT;
335 		else
336 			act = RTW89_P2P_ACT_UPDATE;
337 		rtw89_tsf32_toggle(rtwdev, rtwvif_link, act);
338 		rtw89_fw_h2c_p2p_act(rtwdev, rtwvif_link, desc, act, noa_id,
339 				     bss_conf->p2p_noa_attr.oppps_ctwindow);
340 	}
341 	rtwvif_link->last_noa_nr = noa_id;
342 }
343 
344 void rtw89_process_p2p_ps(struct rtw89_dev *rtwdev,
345 			  struct rtw89_vif_link *rtwvif_link,
346 			  struct ieee80211_bss_conf *bss_conf)
347 {
348 	rtw89_p2p_disable_all_noa(rtwdev, rtwvif_link, bss_conf);
349 	rtw89_p2p_update_noa(rtwdev, rtwvif_link, bss_conf);
350 }
351 
352 void rtw89_recalc_lps(struct rtw89_dev *rtwdev)
353 {
354 	struct ieee80211_vif *vif, *found_vif = NULL;
355 	struct rtw89_vif *rtwvif;
356 	enum rtw89_entity_mode mode;
357 	int count = 0;
358 
359 	mode = rtw89_get_entity_mode(rtwdev);
360 	if (mode == RTW89_ENTITY_MODE_MCC)
361 		goto disable_lps;
362 
363 	rtw89_for_each_rtwvif(rtwdev, rtwvif) {
364 		vif = rtwvif_to_vif(rtwvif);
365 
366 		if (vif->type != NL80211_IFTYPE_STATION) {
367 			count = 0;
368 			break;
369 		}
370 
371 		count++;
372 		found_vif = vif;
373 	}
374 
375 	if (count == 1 && found_vif->cfg.ps) {
376 		rtwdev->lps_enabled = true;
377 		return;
378 	}
379 
380 disable_lps:
381 	rtw89_leave_lps(rtwdev);
382 	rtwdev->lps_enabled = false;
383 }
384 
385 void rtw89_p2p_noa_renew(struct rtw89_vif_link *rtwvif_link)
386 {
387 	struct rtw89_p2p_noa_setter *setter = &rtwvif_link->p2p_noa;
388 	struct rtw89_p2p_noa_ie *ie = &setter->ie;
389 	struct rtw89_p2p_ie_head *p2p_head = &ie->p2p_head;
390 	struct rtw89_noa_attr_head *noa_head = &ie->noa_head;
391 
392 	if (setter->noa_count) {
393 		setter->noa_index++;
394 		setter->noa_count = 0;
395 	}
396 
397 	memset(ie, 0, sizeof(*ie));
398 
399 	p2p_head->eid = WLAN_EID_VENDOR_SPECIFIC;
400 	p2p_head->ie_len = 4 + sizeof(*noa_head);
401 	p2p_head->oui[0] = (WLAN_OUI_WFA >> 16) & 0xff;
402 	p2p_head->oui[1] = (WLAN_OUI_WFA >> 8) & 0xff;
403 	p2p_head->oui[2] = (WLAN_OUI_WFA >> 0) & 0xff;
404 	p2p_head->oui_type = WLAN_OUI_TYPE_WFA_P2P;
405 
406 	noa_head->attr_type = IEEE80211_P2P_ATTR_ABSENCE_NOTICE;
407 	noa_head->attr_len = cpu_to_le16(2);
408 	noa_head->index = setter->noa_index;
409 	noa_head->oppps_ctwindow = 0;
410 }
411 
412 void rtw89_p2p_noa_append(struct rtw89_vif_link *rtwvif_link,
413 			  const struct ieee80211_p2p_noa_desc *desc)
414 {
415 	struct rtw89_p2p_noa_setter *setter = &rtwvif_link->p2p_noa;
416 	struct rtw89_p2p_noa_ie *ie = &setter->ie;
417 	struct rtw89_p2p_ie_head *p2p_head = &ie->p2p_head;
418 	struct rtw89_noa_attr_head *noa_head = &ie->noa_head;
419 
420 	if (!desc->count || !desc->duration)
421 		return;
422 
423 	if (setter->noa_count >= RTW89_P2P_MAX_NOA_NUM)
424 		return;
425 
426 	p2p_head->ie_len += sizeof(*desc);
427 	le16_add_cpu(&noa_head->attr_len, sizeof(*desc));
428 
429 	ie->noa_desc[setter->noa_count++] = *desc;
430 }
431 
432 u8 rtw89_p2p_noa_fetch(struct rtw89_vif_link *rtwvif_link, void **data)
433 {
434 	struct rtw89_p2p_noa_setter *setter = &rtwvif_link->p2p_noa;
435 	struct rtw89_p2p_noa_ie *ie = &setter->ie;
436 	void *tail;
437 
438 	if (!setter->noa_count)
439 		return 0;
440 
441 	*data = ie;
442 	tail = ie->noa_desc + setter->noa_count;
443 	return tail - *data;
444 }
445 
446 static void rtw89_ps_noa_once_set_work(struct wiphy *wiphy, struct wiphy_work *work)
447 {
448 	struct rtw89_ps_noa_once_handler *noa_once =
449 		container_of(work, struct rtw89_ps_noa_once_handler, set_work.work);
450 
451 	lockdep_assert_wiphy(wiphy);
452 
453 	noa_once->in_duration = true;
454 }
455 
456 static void rtw89_ps_noa_once_clr_work(struct wiphy *wiphy, struct wiphy_work *work)
457 {
458 	struct rtw89_ps_noa_once_handler *noa_once =
459 		container_of(work, struct rtw89_ps_noa_once_handler, clr_work.work);
460 	struct rtw89_vif_link *rtwvif_link =
461 		container_of(noa_once, struct rtw89_vif_link, noa_once);
462 	struct rtw89_dev *rtwdev = rtwvif_link->rtwvif->rtwdev;
463 
464 	lockdep_assert_wiphy(wiphy);
465 
466 	rtw89_fw_h2c_set_bcn_fltr_cfg(rtwdev, rtwvif_link, true);
467 	noa_once->in_duration = false;
468 }
469 
470 void rtw89_p2p_noa_once_init(struct rtw89_vif_link *rtwvif_link)
471 {
472 	struct rtw89_ps_noa_once_handler *noa_once = &rtwvif_link->noa_once;
473 
474 	noa_once->in_duration = false;
475 	noa_once->tsf_begin = 0;
476 	noa_once->tsf_end = 0;
477 
478 	wiphy_delayed_work_init(&noa_once->set_work, rtw89_ps_noa_once_set_work);
479 	wiphy_delayed_work_init(&noa_once->clr_work, rtw89_ps_noa_once_clr_work);
480 }
481 
482 static void rtw89_p2p_noa_once_cancel(struct rtw89_vif_link *rtwvif_link)
483 {
484 	struct rtw89_ps_noa_once_handler *noa_once = &rtwvif_link->noa_once;
485 	struct rtw89_dev *rtwdev = rtwvif_link->rtwvif->rtwdev;
486 	struct wiphy *wiphy = rtwdev->hw->wiphy;
487 
488 	wiphy_delayed_work_cancel(wiphy, &noa_once->set_work);
489 	wiphy_delayed_work_cancel(wiphy, &noa_once->clr_work);
490 }
491 
492 void rtw89_p2p_noa_once_deinit(struct rtw89_vif_link *rtwvif_link)
493 {
494 	rtw89_p2p_noa_once_cancel(rtwvif_link);
495 	rtw89_p2p_noa_once_init(rtwvif_link);
496 }
497 
498 void rtw89_p2p_noa_once_recalc(struct rtw89_vif_link *rtwvif_link)
499 {
500 	struct rtw89_ps_noa_once_handler *noa_once = &rtwvif_link->noa_once;
501 	struct rtw89_dev *rtwdev = rtwvif_link->rtwvif->rtwdev;
502 	const struct ieee80211_p2p_noa_desc *noa_desc;
503 	struct wiphy *wiphy = rtwdev->hw->wiphy;
504 	struct ieee80211_bss_conf *bss_conf;
505 	u64 tsf_begin = U64_MAX, tsf_end;
506 	u64 set_delay_us = 0;
507 	u64 clr_delay_us = 0;
508 	u32 start_time;
509 	u32 interval;
510 	u32 duration;
511 	u64 tsf;
512 	int ret;
513 	int i;
514 
515 	lockdep_assert_wiphy(wiphy);
516 
517 	ret = rtw89_mac_port_get_tsf(rtwdev, rtwvif_link, &tsf);
518 	if (ret) {
519 		rtw89_warn(rtwdev, "%s: failed to get tsf\n", __func__);
520 		return;
521 	}
522 
523 	rcu_read_lock();
524 
525 	bss_conf = rtw89_vif_rcu_dereference_link(rtwvif_link, true);
526 
527 	for (i = 0; i < ARRAY_SIZE(bss_conf->p2p_noa_attr.desc); i++) {
528 		bool first = tsf_begin == U64_MAX;
529 		u64 tmp;
530 
531 		noa_desc = &bss_conf->p2p_noa_attr.desc[i];
532 		if (noa_desc->count == 0 || noa_desc->count == 255)
533 			continue;
534 
535 		start_time = le32_to_cpu(noa_desc->start_time);
536 		interval = le32_to_cpu(noa_desc->interval);
537 		duration = le32_to_cpu(noa_desc->duration);
538 
539 		if (unlikely(duration == 0 ||
540 			     (noa_desc->count > 1 && interval == 0)))
541 			continue;
542 
543 		tmp = start_time + interval * (noa_desc->count - 1) + duration;
544 		tmp = (tsf & GENMASK_ULL(63, 32)) + tmp;
545 		if (unlikely(tmp <= tsf))
546 			continue;
547 		tsf_end = first ? tmp : max(tsf_end, tmp);
548 
549 		tmp = (tsf & GENMASK_ULL(63, 32)) | start_time;
550 		tsf_begin = first ? tmp : min(tsf_begin, tmp);
551 	}
552 
553 	rcu_read_unlock();
554 
555 	if (tsf_begin == U64_MAX)
556 		return;
557 
558 	rtw89_p2p_noa_once_cancel(rtwvif_link);
559 
560 	if (noa_once->tsf_end > tsf) {
561 		tsf_begin = min(tsf_begin, noa_once->tsf_begin);
562 		tsf_end = max(tsf_end, noa_once->tsf_end);
563 	}
564 
565 	clr_delay_us = min_t(u64, tsf_end - tsf, UINT_MAX);
566 
567 	if (tsf_begin <= tsf) {
568 		noa_once->in_duration = true;
569 		goto out;
570 	}
571 
572 	set_delay_us = tsf_begin - tsf;
573 	if (unlikely(set_delay_us > UINT_MAX)) {
574 		rtw89_warn(rtwdev, "%s: unhandled begin\n", __func__);
575 		set_delay_us = 0;
576 		clr_delay_us = 0;
577 		rtw89_fw_h2c_set_bcn_fltr_cfg(rtwdev, rtwvif_link, true);
578 		noa_once->in_duration = false;
579 	}
580 
581 out:
582 	if (set_delay_us)
583 		wiphy_delayed_work_queue(wiphy, &noa_once->set_work,
584 					 usecs_to_jiffies(set_delay_us));
585 	if (clr_delay_us)
586 		wiphy_delayed_work_queue(wiphy, &noa_once->clr_work,
587 					 usecs_to_jiffies(clr_delay_us));
588 
589 	noa_once->tsf_begin = tsf_begin;
590 	noa_once->tsf_end = tsf_end;
591 }
592