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