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