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