xref: /wlan-dirver/qca-wifi-host-cmn/umac/dfs/core/src/misc/dfs_nol.c (revision 8cfe6b10058a04cafb17eed051f2ddf11bee8931)
1 /*
2  * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2002-2010, Atheros Communications Inc.
4  * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: This file contains NOL related functionality, NOL being the non
21  * occupancy list. After radar has been detected in a particular channel,
22  * the channel cannot be used for a period of 30 minutes which is called
23  * the non occupancy. The NOL is basically a list of all the channels that
24  * radar has been detected on. Each channel has a 30 minute timer associated
25  * with it. This file contains the functionality to add a channel to the NOL,
26  * the NOL timer  function and the functionality to remove a channel from the
27  * NOL when its time is up.
28  */
29 
30 #include "../dfs.h"
31 #include "../dfs_channel.h"
32 #include "../dfs_ioctl_private.h"
33 #include "../dfs_zero_cac.h"
34 #include "../dfs_internal.h"
35 #include <qdf_time.h>
36 #include <wlan_dfs_mlme_api.h>
37 #include <wlan_objmgr_vdev_obj.h>
38 #include <wlan_dfs_utils_api.h>
39 #include <wlan_reg_services_api.h>
40 #if defined(WLAN_DFS_PARTIAL_OFFLOAD) && defined(HOST_DFS_SPOOF_TEST)
41 #include "../dfs_process_radar_found_ind.h"
42 #include "../dfs_partial_offload_radar.h"
43 #endif
44 #include <qdf_types.h>
45 
46 void dfs_set_update_nol_flag(struct wlan_dfs *dfs, bool val)
47 {
48 	dfs->update_nol = val;
49 }
50 
51 bool dfs_get_update_nol_flag(struct wlan_dfs *dfs)
52 {
53 	return dfs->update_nol;
54 }
55 
56 /**
57  * dfs_nol_elem_free_work_cb() -  Free NOL element
58  * @context: work context (wlan_dfs)
59  *
60  * Free the NOL element memory
61  */
62 static void dfs_nol_elem_free_work_cb(void *context)
63 {
64 	struct wlan_dfs *dfs = (struct wlan_dfs *)context;
65 	struct dfs_nolelem *nol_head;
66 
67 	while (true) {
68 		WLAN_DFSNOL_LOCK(dfs);
69 
70 		nol_head = TAILQ_FIRST(&dfs->dfs_nol_free_list);
71 		if (nol_head) {
72 			TAILQ_REMOVE(&dfs->dfs_nol_free_list, nol_head,
73 				     nolelem_list);
74 			WLAN_DFSNOL_UNLOCK(dfs);
75 			qdf_hrtimer_kill(&nol_head->nol_timer);
76 			qdf_mem_free(nol_head);
77 		} else {
78 			WLAN_DFSNOL_UNLOCK(dfs);
79 			break;
80 		}
81 	}
82 }
83 
84 void dfs_nol_attach(struct wlan_dfs *dfs)
85 {
86 	dfs->wlan_dfs_nol_timeout = DFS_NOL_TIMEOUT_S;
87 	qdf_create_work(NULL, &dfs->dfs_nol_elem_free_work,
88 			dfs_nol_elem_free_work_cb, dfs);
89 	TAILQ_INIT(&dfs->dfs_nol_free_list);
90 	dfs->dfs_use_nol = 1;
91 	WLAN_DFSNOL_LOCK_CREATE(dfs);
92 }
93 
94 void dfs_nol_detach(struct wlan_dfs *dfs)
95 {
96 	dfs_nol_timer_cleanup(dfs);
97 	qdf_flush_work(&dfs->dfs_nol_elem_free_work);
98 	qdf_destroy_work(NULL, &dfs->dfs_nol_elem_free_work);
99 	WLAN_DFSNOL_LOCK_DESTROY(dfs);
100 }
101 
102 /**
103  * dfs_nol_delete() - Delete the given frequency/chwidth from the NOL.
104  * @dfs: Pointer to wlan_dfs structure.
105  * @delfreq: Freq to delete.
106  * @delchwidth: Channel width to delete.
107  */
108 static void dfs_nol_delete(struct wlan_dfs *dfs,
109 		uint16_t delfreq,
110 		uint16_t delchwidth)
111 {
112 	struct dfs_nolelem *nol, **prev_next;
113 
114 	if (!dfs) {
115 		dfs_err(dfs, WLAN_DEBUG_DFS_ALWAYS,  "dfs is NULL");
116 		return;
117 	}
118 
119 	dfs_debug(dfs, WLAN_DEBUG_DFS_NOL,
120 		"remove channel=%d/%d MHz from NOL",
121 		 delfreq, delchwidth);
122 	prev_next = &(dfs->dfs_nol);
123 	nol = dfs->dfs_nol;
124 	while (nol) {
125 		if (nol->nol_freq == delfreq &&
126 			nol->nol_chwidth == delchwidth) {
127 			*prev_next = nol->nol_next;
128 			dfs_debug(dfs, WLAN_DEBUG_DFS_NOL,
129 				"removing channel %d/%dMHz from NOL tstamp=%d",
130 				 nol->nol_freq,
131 				nol->nol_chwidth,
132 				(qdf_system_ticks_to_msecs
133 				 (qdf_system_ticks()) / 1000));
134 			TAILQ_INSERT_TAIL(&dfs->dfs_nol_free_list,
135 						nol, nolelem_list);
136 			nol = *prev_next;
137 
138 			/* Update the NOL counter. */
139 			dfs->dfs_nol_count--;
140 
141 			/* Be paranoid! */
142 			if (dfs->dfs_nol_count < 0) {
143 				dfs_info(NULL, WLAN_DEBUG_DFS_ALWAYS, "dfs_nol_count < 0; eek!");
144 				dfs->dfs_nol_count = 0;
145 			}
146 
147 		} else {
148 			prev_next = &(nol->nol_next);
149 			nol = nol->nol_next;
150 		}
151 	}
152 }
153 
154 /**
155  * dfs_remove_from_nol() - Remove the freq from NOL list.
156  * @arg: argument of the timer
157  *
158  * When NOL times out, this function removes the channel from NOL list.
159  */
160 #ifdef CONFIG_CHAN_FREQ_API
161 
162 static enum qdf_hrtimer_restart_status
163 dfs_remove_from_nol(qdf_hrtimer_data_t *arg)
164 {
165 	struct wlan_dfs *dfs;
166 	uint16_t delfreq;
167 	uint16_t delchwidth;
168 	uint8_t chan;
169 	struct dfs_nolelem *nol_arg;
170 
171 	nol_arg = container_of(arg, struct dfs_nolelem, nol_timer);
172 	dfs = nol_arg->nol_dfs;
173 	delfreq = nol_arg->nol_freq;
174 	delchwidth = nol_arg->nol_chwidth;
175 
176 	/* Delete the given NOL entry. */
177 	DFS_NOL_DELETE_CHAN_LOCKED(dfs, delfreq, delchwidth);
178 
179 	utils_dfs_reg_update_nol_chan_for_freq(dfs->dfs_pdev_obj,
180 					       &delfreq, 1, DFS_NOL_RESET);
181 	/* Update the wireless stack with the new NOL. */
182 	dfs_nol_update(dfs);
183 
184 	dfs_mlme_nol_timeout_notification(dfs->dfs_pdev_obj);
185 	chan = utils_dfs_freq_to_chan(delfreq);
186 	utils_dfs_deliver_event(dfs->dfs_pdev_obj, delfreq,
187 				WLAN_EV_NOL_FINISHED);
188 	dfs_debug(dfs, WLAN_DEBUG_DFS_NOL,
189 		  "remove channel %d from nol", chan);
190 	utils_dfs_unmark_precac_nol_for_freq(dfs->dfs_pdev_obj, delfreq);
191 
192 	utils_dfs_save_nol(dfs->dfs_pdev_obj);
193 
194 	/*
195 	 * Check if a channel is configured by the user to which we have to
196 	 * switch after it's NOL expiry. If that is the case, change
197 	 * channel immediately.
198 	 *
199 	 * If a channel switch is required (indicated by the return value of
200 	 * dfs_switch_to_postnol_chan_if_nol_expired), return from this function
201 	 * without posting Start event to Agile SM. That will be taken care
202 	 * of, after VAP start.
203 	 */
204 	if (dfs_switch_to_postnol_chan_if_nol_expired(dfs))
205 		return QDF_HRTIMER_NORESTART;
206 	/*
207 	 * If BW Expand is enabled, check if the user configured channel is
208 	 * available. If it is available, STOP the AGILE SM and Restart the
209 	 * AGILE SM. This will clear any old preCAC/RCAC chan information.
210 	 */
211 	if (dfs_bwexpand_find_usr_cnf_chan(dfs)) {
212 		utils_dfs_agile_sm_deliver_evt(dfs->dfs_pdev_obj,
213 					       DFS_AGILE_SM_EV_AGILE_STOP);
214 		utils_dfs_agile_sm_deliver_evt(dfs->dfs_pdev_obj,
215 					       DFS_AGILE_SM_EV_AGILE_START);
216 	} else {
217 		/*
218 		 * In case of interCAC feature, check if the user configured
219 		 * desired channel is RCAC done or not.
220 		 * (AP operating on an intermediate channel as desired channel
221 		 * is still not CAC done). If the RCAC of the desired channel
222 		 * was interrupted by radar, initiate RCAC on NOL expiry
223 		 * of the channel.
224 		 *
225 		 * If rcac is not started by dfs_restart_rcac_on_nol_expiry()
226 		 * API initiate rcac start here.
227 		 */
228 		if (!dfs_restart_rcac_on_nol_expiry(dfs))
229 			utils_dfs_agile_sm_deliver_evt(dfs->dfs_pdev_obj,
230 						       DFS_AGILE_SM_EV_AGILE_START);
231 	}
232 	return QDF_HRTIMER_NORESTART;
233 }
234 #endif
235 
236 void dfs_print_nol(struct wlan_dfs *dfs)
237 {
238 	struct dfs_nolelem *nol;
239 	int i = 0;
240 	uint32_t diff_ms, remaining_sec;
241 
242 	if (!dfs) {
243 		dfs_err(dfs, WLAN_DEBUG_DFS_ALWAYS,  "dfs is NULL");
244 		return;
245 	}
246 
247 	nol = dfs->dfs_nol;
248 	dfs_debug(dfs, WLAN_DEBUG_DFS_NOL, "NOL");
249 	while (nol) {
250 		diff_ms = qdf_do_div(qdf_get_monotonic_boottime() -
251 				     nol->nol_start_us, 1000);
252 		if (nol->nol_timeout_ms > diff_ms)
253 			diff_ms = (nol->nol_timeout_ms - diff_ms);
254 		else
255 			diff_ms = 0;
256 		remaining_sec = diff_ms / 1000; /* Convert to seconds */
257 		dfs_info(NULL, WLAN_DEBUG_DFS_ALWAYS,
258 			"nol:%d channel=%d MHz width=%d MHz time left=%u seconds nol start_us=%llu",
259 			i++, nol->nol_freq,
260 			nol->nol_chwidth,
261 			remaining_sec,
262 			nol->nol_start_us);
263 		nol = nol->nol_next;
264 	}
265 }
266 
267 void dfs_print_nolhistory(struct wlan_dfs *dfs)
268 {
269 	struct dfs_channel *chan_list;
270 	int i, j;
271 	int nchans;
272 
273 	if (!dfs) {
274 		dfs_err(dfs, WLAN_DEBUG_DFS_ALWAYS,  "dfs is NULL");
275 		return;
276 	}
277 
278 	nchans = dfs_get_num_chans();
279 
280 	chan_list = qdf_mem_malloc(nchans * sizeof(*chan_list));
281 	if (!chan_list)
282 		return;
283 
284 	utils_dfs_get_nol_history_chan_list(dfs->dfs_pdev_obj,
285 					    (void *)chan_list, &nchans);
286 	if (!nchans) {
287 		dfs_err(dfs, WLAN_DEBUG_DFS_ALWAYS, "zero chans");
288 		qdf_mem_free(chan_list);
289 		return;
290 	}
291 
292 	for (i = 0, j = 0; i < nchans; i++, j++)
293 		dfs_info(NULL, WLAN_DEBUG_DFS_ALWAYS,
294 			 "nolhistory = %d channel = %d MHz",
295 			 j, chan_list[i].dfs_ch_freq);
296 
297 	qdf_mem_free(chan_list);
298 }
299 
300 void dfs_get_nol(struct wlan_dfs *dfs,
301 		struct dfsreq_nolelem *dfs_nol,
302 		int *nchan)
303 {
304 	struct dfs_nolelem *nol;
305 
306 	*nchan = 0;
307 
308 	if (!dfs) {
309 		dfs_err(dfs, WLAN_DEBUG_DFS_ALWAYS,  "dfs is NULL");
310 		return;
311 	}
312 
313 	nol = dfs->dfs_nol;
314 	while (nol) {
315 		dfs_nol[*nchan].nol_freq = nol->nol_freq;
316 		dfs_nol[*nchan].nol_chwidth = nol->nol_chwidth;
317 		dfs_nol[*nchan].nol_start_us = nol->nol_start_us;
318 		dfs_nol[*nchan].nol_timeout_ms = nol->nol_timeout_ms;
319 		++(*nchan);
320 		nol = nol->nol_next;
321 	}
322 }
323 
324 #ifdef CONFIG_CHAN_FREQ_API
325 void dfs_set_nol(struct wlan_dfs *dfs,
326 		 struct dfsreq_nolelem *dfs_nol,
327 		 int nchan)
328 {
329 #define TIME_IN_MS 1000
330 	uint32_t nol_time_lft_ms;
331 	struct dfs_channel chan;
332 	int i;
333 
334 	if (!dfs) {
335 		dfs_err(dfs, WLAN_DEBUG_DFS_ALWAYS,  "dfs is NULL");
336 		return;
337 	}
338 
339 	for (i = 0; i < nchan; i++) {
340 		nol_time_lft_ms = qdf_do_div(qdf_get_monotonic_boottime() -
341 					     dfs_nol[i].nol_start_us, 1000);
342 
343 		if (nol_time_lft_ms < dfs_nol[i].nol_timeout_ms) {
344 			chan.dfs_ch_freq = dfs_nol[i].nol_freq;
345 			chan.dfs_ch_flags = 0;
346 			chan.dfs_ch_flagext = 0;
347 			nol_time_lft_ms =
348 				(dfs_nol[i].nol_timeout_ms - nol_time_lft_ms);
349 
350 			DFS_NOL_ADD_CHAN_LOCKED(dfs, chan.dfs_ch_freq,
351 						(nol_time_lft_ms / TIME_IN_MS));
352 			utils_dfs_reg_update_nol_chan_for_freq(
353 						dfs->dfs_pdev_obj,
354 						&chan.dfs_ch_freq,
355 						1, DFS_NOL_SET);
356 		}
357 	}
358 #undef TIME_IN_MS
359 	dfs_nol_update(dfs);
360 }
361 #else
362 #endif
363 
364 void dfs_nol_addchan(struct wlan_dfs *dfs,
365 		uint16_t freq,
366 		uint32_t dfs_nol_timeout)
367 {
368 #define TIME_IN_MS 1000
369 #define TIME_IN_US (TIME_IN_MS * 1000)
370 	struct dfs_nolelem *nol, *elem, *prev;
371 	/* For now, assume all events are 20MHz wide. */
372 	int ch_width = 20;
373 
374 	if (!dfs) {
375 		dfs_err(dfs, WLAN_DEBUG_DFS_ALWAYS,  "dfs is NULL");
376 		return;
377 	}
378 	nol = dfs->dfs_nol;
379 	prev = dfs->dfs_nol;
380 	elem = NULL;
381 	while (nol) {
382 		if ((nol->nol_freq == freq) &&
383 				(nol->nol_chwidth == ch_width)) {
384 			nol->nol_start_us = qdf_get_monotonic_boottime();
385 			nol->nol_timeout_ms = dfs_nol_timeout * TIME_IN_MS;
386 
387 			dfs_debug(dfs, WLAN_DEBUG_DFS_NOL,
388 				"Update OS Ticks for NOL %d MHz / %d MHz",
389 				 nol->nol_freq, nol->nol_chwidth);
390 			qdf_hrtimer_cancel(&nol->nol_timer);
391 			qdf_hrtimer_start(&nol->nol_timer,
392 					  qdf_time_ms_to_ktime(
393 						nol->nol_timeout_ms),
394 					  QDF_HRTIMER_MODE_REL);
395 			return;
396 		}
397 		prev = nol;
398 		nol = nol->nol_next;
399 	}
400 
401 	/* Add a new element to the NOL. */
402 	elem = (struct dfs_nolelem *)qdf_mem_malloc(sizeof(struct dfs_nolelem));
403 	if (!elem)
404 		goto bad;
405 
406 	qdf_mem_zero(elem, sizeof(*elem));
407 	elem->nol_dfs = dfs;
408 	elem->nol_freq = freq;
409 	elem->nol_chwidth = ch_width;
410 	elem->nol_start_us = qdf_get_monotonic_boottime();
411 	elem->nol_timeout_ms = dfs_nol_timeout*TIME_IN_MS;
412 	elem->nol_next = NULL;
413 	if (prev) {
414 		prev->nol_next = elem;
415 	} else {
416 		/* This is the first element in the NOL. */
417 		dfs->dfs_nol = elem;
418 	}
419 
420 	qdf_hrtimer_init(&elem->nol_timer, dfs_remove_from_nol,
421 			 QDF_CLOCK_MONOTONIC, QDF_HRTIMER_MODE_REL,
422 			 QDF_CONTEXT_TASKLET);
423 	qdf_hrtimer_start(&elem->nol_timer,
424 			  qdf_time_ms_to_ktime(dfs_nol_timeout * TIME_IN_MS),
425 			  QDF_HRTIMER_MODE_REL);
426 
427 	/* Update the NOL counter. */
428 	dfs->dfs_nol_count++;
429 
430 	dfs_debug(dfs, WLAN_DEBUG_DFS_NOL,
431 		"new NOL channel %d MHz / %d MHz",
432 		 elem->nol_freq, elem->nol_chwidth);
433 	return;
434 
435 bad:
436 	dfs_debug(dfs, WLAN_DEBUG_DFS_NOL | WLAN_DEBUG_DFS,
437 		"failed to allocate memory for nol entry");
438 
439 #undef TIME_IN_MS
440 #undef TIME_IN_US
441 }
442 
443 void dfs_get_nol_chfreq_and_chwidth(struct dfsreq_nolelem *dfs_nol,
444 		uint32_t *nol_chfreq,
445 		uint32_t *nol_chwidth,
446 		int index)
447 {
448 	if (!dfs_nol)
449 		return;
450 
451 	*nol_chfreq = dfs_nol[index].nol_freq;
452 	*nol_chwidth = dfs_nol[index].nol_chwidth;
453 }
454 
455 void dfs_nol_update(struct wlan_dfs *dfs)
456 {
457 	struct dfsreq_nolelem *dfs_nol;
458 	int nlen;
459 
460 	if (!dfs->dfs_nol_count) {
461 		dfs_debug(dfs, WLAN_DEBUG_DFS_NOL, "dfs_nol_count is zero");
462 		dfs_mlme_clist_update(dfs->dfs_pdev_obj, NULL, 0);
463 		return;
464 	}
465 
466 	/*
467 	 * Allocate enough entries to store the NOL. At least on Linux
468 	 * (don't ask why), if you allocate a 0 entry array, the
469 	 * returned pointer is 0x10.  Make sure you're aware of this
470 	 * when you start debugging.
471 	 */
472 	dfs_nol = (struct dfsreq_nolelem *)qdf_mem_malloc(
473 		sizeof(struct dfsreq_nolelem) * dfs->dfs_nol_count);
474 
475 	/*
476 	 * XXX TODO: if this fails, just schedule a task to retry
477 	 * updating the NOL at a later stage.  That way the NOL
478 	 * update _DOES_ happen - hopefully the failure was just
479 	 * temporary.
480 	 */
481 	if (!dfs_nol)
482 		return;
483 
484 	DFS_GET_NOL_LOCKED(dfs, dfs_nol, &nlen);
485 
486 	/* Be suitably paranoid for now. */
487 	if (nlen != dfs->dfs_nol_count)
488 		dfs_info(NULL, WLAN_DEBUG_DFS_ALWAYS, "nlen (%d) != dfs->dfs_nol_count (%d)!",
489 			 nlen, dfs->dfs_nol_count);
490 
491 	/*
492 	 * Call the driver layer to have it recalculate the NOL flags
493 	 * for each driver/umac channel. If the list is empty, pass
494 	 * NULL instead of dfs_nol. The operating system may have some
495 	 * special representation for "malloc a 0 byte memory region"
496 	 * - for example, Linux 2.6.38-13 (ubuntu) returns 0x10 rather
497 	 * than a valid allocation (and is likely not NULL so the
498 	 * pointer doesn't match NULL checks in any later code.
499 	 */
500 	dfs_mlme_clist_update(dfs->dfs_pdev_obj,
501 			(nlen > 0) ? dfs_nol : NULL,
502 			nlen);
503 
504 	qdf_mem_free(dfs_nol);
505 }
506 
507 void dfs_nol_free_list(struct wlan_dfs *dfs)
508 {
509 	struct dfs_nolelem *nol = dfs->dfs_nol, *prev;
510 
511 	while (nol) {
512 		prev = nol;
513 		nol = nol->nol_next;
514 		qdf_mem_free(prev);
515 		/* Update the NOL counter. */
516 		dfs->dfs_nol_count--;
517 
518 		if (dfs->dfs_nol_count < 0) {
519 			dfs_err(dfs, WLAN_DEBUG_DFS_ALWAYS,  "dfs_nol_count < 0");
520 			ASSERT(0);
521 		}
522 	}
523 
524 	dfs->dfs_nol = NULL;
525 }
526 
527 #ifdef CONFIG_CHAN_FREQ_API
528 void dfs_nol_timer_cleanup(struct wlan_dfs *dfs)
529 {
530 	struct dfs_nolelem *nol;
531 	uint16_t nol_freq;
532 
533 	while (true) {
534 		WLAN_DFSNOL_LOCK(dfs);
535 
536 		nol = dfs->dfs_nol;
537 		if (nol) {
538 			dfs->dfs_nol = nol->nol_next;
539 			dfs->dfs_nol_count--;
540 			nol_freq = nol->nol_freq;
541 			WLAN_DFSNOL_UNLOCK(dfs);
542 			utils_dfs_reg_update_nol_chan_for_freq(
543 					dfs->dfs_pdev_obj,
544 					&nol_freq,
545 					1,
546 					DFS_NOL_RESET);
547 			qdf_hrtimer_kill(&nol->nol_timer);
548 			qdf_mem_free(nol);
549 		} else {
550 			WLAN_DFSNOL_UNLOCK(dfs);
551 			break;
552 		}
553 	}
554 }
555 #endif
556 
557 void dfs_nol_workqueue_cleanup(struct wlan_dfs *dfs)
558 {
559 	qdf_flush_work(&dfs->dfs_nol_elem_free_work);
560 }
561 
562 int dfs_get_use_nol(struct wlan_dfs *dfs)
563 {
564 	return dfs->dfs_use_nol;
565 }
566 
567 int dfs_get_nol_timeout(struct wlan_dfs *dfs)
568 {
569 	return dfs->wlan_dfs_nol_timeout;
570 }
571 
572 void dfs_getnol(struct wlan_dfs *dfs, void *dfs_nolinfo)
573 {
574 	struct dfsreq_nolinfo *nolinfo = (struct dfsreq_nolinfo *)dfs_nolinfo;
575 
576 	DFS_GET_NOL_LOCKED(dfs, nolinfo->dfs_nol, &(nolinfo->dfs_ch_nchans));
577 }
578 
579 #if !defined(MOBILE_DFS_SUPPORT)
580 #ifdef CONFIG_CHAN_FREQ_API
581 void dfs_clear_nolhistory(struct wlan_dfs *dfs)
582 {
583 	struct dfs_channel *chan_list;
584 	int nchans;
585 	bool sta_opmode;
586 	int i;
587 	qdf_freq_t *nol_freq_list = NULL;
588 	uint32_t num_nol_history_chans;
589 
590 	if (!dfs->dfs_is_stadfs_enabled)
591 		return;
592 
593 	sta_opmode = dfs_mlme_is_opmode_sta(dfs->dfs_pdev_obj);
594 	if (!sta_opmode)
595 		return;
596 
597 	nchans = dfs_get_num_chans();
598 
599 	if (!nchans) {
600 		dfs_err(dfs, WLAN_DEBUG_DFS_ALWAYS, "zero chans");
601 		return;
602 	}
603 
604 	chan_list = qdf_mem_malloc(nchans * sizeof(*chan_list));
605 	if (!chan_list)
606 		return;
607 
608 	utils_dfs_get_nol_history_chan_list(dfs->dfs_pdev_obj,
609 					    (void *)chan_list,
610 					    &num_nol_history_chans);
611 
612 	if (!num_nol_history_chans) {
613 		dfs_err(dfs, WLAN_DEBUG_DFS_ALWAYS, "zero chans");
614 		qdf_mem_free(chan_list);
615 		return;
616 	}
617 
618 	if (num_nol_history_chans > nchans)
619 		num_nol_history_chans = nchans;
620 
621 	nol_freq_list =
622 		qdf_mem_malloc(num_nol_history_chans * sizeof(qdf_freq_t));
623 
624 	if (!nol_freq_list) {
625 		dfs_err(dfs, WLAN_DEBUG_DFS_ALWAYS, "Unable to alloc memory for freq list");
626 		qdf_mem_free(chan_list);
627 		return;
628 	}
629 
630 	for (i = 0; i < num_nol_history_chans; i++)
631 		nol_freq_list[i] = chan_list[i].dfs_ch_freq;
632 
633 	utils_dfs_reg_update_nol_history_chan_for_freq(dfs->dfs_pdev_obj,
634 						       nol_freq_list,
635 						       num_nol_history_chans,
636 						       DFS_NOL_HISTORY_RESET);
637 	qdf_mem_free(chan_list);
638 	qdf_mem_free(nol_freq_list);
639 }
640 #endif
641 #endif
642 
643 #if defined(WLAN_DFS_PARTIAL_OFFLOAD) && defined(HOST_DFS_SPOOF_TEST) && \
644 	defined(CONFIG_CHAN_FREQ_API)
645 void dfs_remove_spoof_channel_from_nol(struct wlan_dfs *dfs)
646 {
647 	struct dfs_nolelem *nol;
648 	uint16_t freq_list[MAX_20MHZ_SUBCHANS];
649 	int i, nchans = 0;
650 
651 	nchans = dfs_get_bonding_channels_for_freq(dfs,
652 						   &dfs->dfs_radar_found_chan,
653 						   SEG_ID_PRIMARY,
654 						   DETECTOR_ID_0,
655 						   freq_list);
656 
657 	WLAN_DFSNOL_LOCK(dfs);
658 	for (i = 0; i < nchans && i < MAX_20MHZ_SUBCHANS; i++) {
659 		nol = dfs->dfs_nol;
660 		while (nol) {
661 			if (nol->nol_freq == freq_list[i]) {
662 				qdf_hrtimer_start(&nol->nol_timer,
663 						  qdf_time_ms_to_ktime(0),
664 						  QDF_HRTIMER_MODE_REL);
665 				break;
666 			}
667 			nol = nol->nol_next;
668 		}
669 	}
670 	WLAN_DFSNOL_UNLOCK(dfs);
671 
672 	utils_dfs_reg_update_nol_chan_for_freq(dfs->dfs_pdev_obj,
673 					     freq_list, nchans, DFS_NOL_RESET);
674 }
675 #endif
676