xref: /wlan-dirver/qca-wifi-host-cmn/umac/dfs/core/src/dfs.h (revision 7f898dfcc20c6ad27c946334cf5e432699aca714)
1 /*
2  * Copyright (c) 2013, 2016-2021 The Linux Foundation.  All rights reserved.
3  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  * Copyright (c) 2005-2006 Atheros Communications, Inc.
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 has main dfs structures.
21  */
22 
23 #ifndef _DFS_H_
24 #define _DFS_H_
25 
26 #include <qdf_types.h>       /* QDF_NBUF_EXEMPT_NO_EXEMPTION, etc. */
27 #include <qdf_net_types.h>   /* QDF_NBUF_EXEMPT_NO_EXEMPTION, etc. */
28 #include <qdf_nbuf.h>        /* qdf_nbuf_t, etc. */
29 #include <qdf_util.h>        /* qdf_assert */
30 #include <qdf_lock.h>        /* qdf_spinlock */
31 #include <qdf_time.h>
32 #include <qdf_timer.h>
33 #include <qdf_hrtimer.h>
34 #include <qdf_str.h>         /* qdf_str_lcopy */
35 
36 #include <wlan_dfs_ioctl.h>
37 #include "dfs_structs.h"
38 #include "dfs_channel.h"
39 #include "dfs_ioctl_private.h"
40 #include <i_qdf_types.h>     /* For qdf_packed*/
41 #include "queue.h"           /* For STAILQ_ENTRY */
42 #include <wlan_objmgr_psoc_obj.h>
43 #include <wlan_objmgr_pdev_obj.h>
44 #include <osdep.h>
45 #include <wlan_cmn.h>
46 #include "target_type.h"
47 #include <wlan_dfs_public_struct.h>
48 #include <reg_services_public_struct.h>
49 
50 /* File Line and Submodule String */
51 #define FLSM(x, str)   #str " : " FL(x)
52 /* Cast to dfs type */
53 #define DC(x)  ((struct wlan_dfs *)(x))
54 
55 /**
56  * dfs_log() - dfs logging using submodule MASKs and QDF trace level.
57  * @dfs: The dfs object pointer or NULL if dfs is not defined.
58  * @sm: Submodule BITMASK.
59  * @level: QDF trace level.
60  * @args: Variable argument list.
61  *
62  * The logging is controlled by two bitmasks:
63  * 1) submodule bitmask: sm
64  * 2) trace level masks: level
65  *
66  * The submodule(sm) cannot be empty even if argument dfs is NULL.
67  * Else the macro will create a  compilation  error.
68  * One may provide WLAN_DEBUG_DFS_ALWAYS when the argument @dfs is NULL.
69  *
70  * dfs_log(NULL, WLAN_DEBUG_DFS_ALWAYS, QDF_TRACE_LEVEL_INFO,"Error pulse");
71  *
72  * Why DC(x) is required?
73  * Since NULL is defined as ((void *)(0)), if the argument "dfs"
74  * in a call to the macro "dfs_log" is NULL
75  * then during compilation (NULL)->dfs_debug_mask will dereference
76  * a (void *) type, which is illegal. Therefore, we need
77  * the cast: (DC(dfs))->dfs_debug_mask.
78  *
79  * dfs_log(NULL, WLAN_DEBUG_DFS, QDF_TRACE_LEVEL_INFO,"dfs is NULL");
80  */
81 #define dfs_log(dfs, sm, level, args...)  do {        \
82 	if (((dfs) == NULL) ||                            \
83 			((sm) == WLAN_DEBUG_DFS_ALWAYS) ||        \
84 			((sm) & ((DC(dfs))->dfs_debug_mask))) {   \
85 		QDF_TRACE(QDF_MODULE_ID_DFS, level, ## args); \
86 	}                                                 \
87 } while (0)
88 
89 #define dfs_logfl(dfs, level, sm, format, args...) \
90 	dfs_log(dfs, sm, level, FLSM(format, sm), ## args)
91 
92 #define dfs_alert(dfs, sm, format, args...) \
93 	dfs_logfl(dfs, QDF_TRACE_LEVEL_FATAL, sm, format, ## args)
94 
95 #define dfs_err(dfs, sm, format, args...) \
96 	dfs_logfl(dfs, QDF_TRACE_LEVEL_ERROR, sm, format, ## args)
97 
98 #define dfs_warn(dfs, sm, format, args...) \
99 	dfs_logfl(dfs, QDF_TRACE_LEVEL_WARN, sm, format, ## args)
100 
101 #define dfs_info(dfs, sm, format, args...) \
102 	dfs_logfl(dfs, QDF_TRACE_LEVEL_INFO, sm, format, ## args)
103 
104 #define dfs_debug(dfs, sm, format, args...) \
105 	dfs_logfl(dfs, QDF_TRACE_LEVEL_DEBUG, sm, format, ## args)
106 
107 #define DFS_MIN(a, b) ((a) < (b)?(a):(b))
108 #define DFS_MAX(a, b) ((a) > (b)?(a) : (b))
109 #define DFS_DIFF(a, b)(DFS_MAX(a, b) - DFS_MIN(a, b))
110 
111 /*
112  * Maximum number of radar events to be processed in a single iteration.
113  * Allows soft watchdog to run.
114  */
115 #define MAX_EVENTS 100
116 
117 /*
118  * Constants to use for chirping detection.
119  *
120  * All are unconverted as HW reports them.
121  *
122  * XXX Are these constants with or without fast clock 5GHz operation?
123  * XXX Peregrine reports pulses in microseconds, not hardware clocks!
124  */
125 
126 #define MAX_DUR_FOR_LOW_RSSI 4
127 
128 /*
129  * Cascade has issue with reported duration especially when there is a
130  * crossover of chirp from one segment to another. It may report a value
131  * of duration that is well below 50us for a valid FCC type 5 chirping
132  * pulse. For now changing minimum duration as a work around. This will
133  * affect all chips but since we detect chirp with Merlin+, we may be OK
134  * for now. We need a more robust solution for this.
135  */
136 #define MIN_BIN5_DUR_CAS            25 /* 50 * 1.25*/
137 #define MIN_BIN5_DUR_MICROSEC_CAS   20
138 #define MIN_BIN5_DUR                63 /* 50 * 1.25*/
139 #define MIN_BIN5_DUR_MICROSEC       50
140 #define MAYBE_BIN5_DUR              35 /* 28 * 1.25*/
141 #define MAYBE_BIN5_DUR_MICROSEC     28
142 
143 /* Conversion is already done using dfs->dur_multiplier */
144 #define MAX_BIN5_DUR                145   /* use 145 for osprey */
145 #define MAX_BIN5_DUR_MICROSEC       105
146 
147 #define DFS_MARGIN_EQUAL(a, b, margin)	((DFS_DIFF(a, b)) <= margin)
148 #define DFS_MAX_STAGGERED_BURSTS    3
149 
150 /*
151  * All filter thresholds in the radar filter tables are effective at a 50%
152  * channel loading.
153  */
154 #define DFS_CHAN_LOADING_THRESH     50
155 #define DFS_EXT_CHAN_LOADING_THRESH 30
156 #define DFS_DEFAULT_PRI_MARGIN      6
157 #define DFS_DEFAULT_FIXEDPATTERN_PRI_MARGIN	4
158 
159 #define WLAN_DFSQ_LOCK(_dfs)         qdf_spin_lock_bh(&(_dfs)->dfs_radarqlock)
160 #define WLAN_DFSQ_UNLOCK(_dfs)       qdf_spin_unlock_bh(&(_dfs)->dfs_radarqlock)
161 #define WLAN_DFSQ_LOCK_CREATE(_dfs)  qdf_spinlock_create( \
162 		&(_dfs)->dfs_radarqlock)
163 #define WLAN_DFSQ_LOCK_DESTROY(_dfs) qdf_spinlock_destroy( \
164 		&(_dfs)->dfs_radarqlock)
165 
166 #define WLAN_ARQ_LOCK(_dfs)          qdf_spin_lock_bh(&(_dfs)->dfs_arqlock)
167 #define WLAN_ARQ_UNLOCK(_dfs)        qdf_spin_unlock_bh(&(_dfs)->dfs_arqlock)
168 #define WLAN_ARQ_LOCK_CREATE(_dfs)   qdf_spinlock_create(&(_dfs)->dfs_arqlock)
169 #define WLAN_ARQ_LOCK_DESTROY(_dfs)  qdf_spinlock_destroy(&(_dfs)->dfs_arqlock)
170 
171 #define WLAN_DFSEVENTQ_LOCK(_dfs)         qdf_spin_lock_bh(&(_dfs)->dfs_eventqlock)
172 #define WLAN_DFSEVENTQ_UNLOCK(_dfs)       qdf_spin_unlock_bh( \
173 		&(_dfs)->dfs_eventqlock)
174 #define WLAN_DFSEVENTQ_LOCK_CREATE(_dfs)  qdf_spinlock_create( \
175 		&(_dfs)->dfs_eventqlock)
176 #define WLAN_DFSEVENTQ_LOCK_DESTROY(_dfs) qdf_spinlock_destroy( \
177 		&(_dfs)->dfs_eventqlock)
178 
179 #define WLAN_DFSNOL_LOCK(_dfs)         qdf_spin_lock_bh(&(_dfs)->dfs_nol_lock)
180 #define WLAN_DFSNOL_UNLOCK(_dfs)       qdf_spin_unlock_bh(&(_dfs)->dfs_nol_lock)
181 #define WLAN_DFSNOL_LOCK_CREATE(_dfs)  qdf_spinlock_create( \
182 		&(_dfs)->dfs_nol_lock)
183 #define WLAN_DFSNOL_LOCK_DESTROY(_dfs) qdf_spinlock_destroy( \
184 		&(_dfs)->dfs_nol_lock)
185 
186 #define PRECAC_LIST_LOCK(_dfs)         qdf_spin_lock_irqsave( \
187 		&(_dfs)->dfs_precac_lock)
188 #define PRECAC_LIST_UNLOCK(_dfs)       qdf_spin_unlock_irqrestore( \
189 		&(_dfs)->dfs_precac_lock)
190 #define PRECAC_LIST_LOCK_CREATE(_dfs)  qdf_spinlock_create( \
191 		&(_dfs)->dfs_precac_lock)
192 #define PRECAC_LIST_LOCK_DESTROY(_dfs) qdf_spinlock_destroy( \
193 		&(_dfs)->dfs_precac_lock)
194 
195 #define WLAN_DFS_DATA_STRUCT_LOCK(_dfs) \
196 	qdf_spin_lock_bh(&(_dfs)->dfs_data_struct_lock)
197 #define WLAN_DFS_DATA_STRUCT_UNLOCK(_dfs) \
198 	qdf_spin_unlock_bh(&(_dfs)->dfs_data_struct_lock)
199 #define WLAN_DFS_DATA_STRUCT_LOCK_CREATE(_dfs) \
200 	qdf_spinlock_create(&(_dfs)->dfs_data_struct_lock)
201 #define WLAN_DFS_DATA_STRUCT_LOCK_DESTROY(_dfs) \
202 	qdf_spinlock_destroy(&(_dfs)->dfs_data_struct_lock)
203 
204 /* Wrappers to call MLME radar during mode switch lock. */
205 #define DFS_RADAR_MODE_SWITCH_LOCK(_dfs) \
206 	dfs_mlme_acquire_radar_mode_switch_lock((_dfs)->dfs_pdev_obj)
207 #define DFS_RADAR_MODE_SWITCH_UNLOCK(_dfs) \
208 	dfs_mlme_release_radar_mode_switch_lock((_dfs)->dfs_pdev_obj)
209 
210 /* Mask for time stamp from descriptor */
211 #define DFS_TSMASK    0xFFFFFFFF
212 /* Shift for time stamp from descriptor */
213 #define DFS_TSSHIFT   32
214 /* 64 bit TSF wrap value */
215 #define DFS_TSF_WRAP  0xFFFFFFFFFFFFFFFFULL
216 /* TS mask for 64 bit value */
217 #define DFS_64BIT_TSFMASK 0x0000000000007FFFULL
218 
219 #define DFS_AR_RADAR_RSSI_THR          5 /* in dB */
220 #define DFS_AR_RADAR_RESET_INT         1 /* in secs */
221 #define DFS_AR_RADAR_MAX_HISTORY       500
222 #define DFS_AR_REGION_WIDTH            128
223 #define DFS_AR_RSSI_THRESH_STRONG_PKTS 17 /* in dB */
224 #define DFS_AR_RSSI_DOUBLE_THRESHOLD   15 /* in dB */
225 #define DFS_AR_MAX_NUM_ACK_REGIONS     9
226 #define DFS_AR_ACK_DETECT_PAR_THRESH   20
227 #define DFS_AR_PKT_COUNT_THRESH        20
228 
229 #define DFS_MAX_DL_SIZE                64
230 #define DFS_MAX_DL_MASK                0x3F
231 
232 #define DFS_NOL_TIME DFS_NOL_TIMEOUT_US
233 /* 30 minutes in usecs */
234 
235 #define DFS_WAIT_TIME (60*1000000) /* 1 minute in usecs */
236 
237 #define DFS_DISABLE_TIME (3*60*1000000) /* 3 minutes in usecs */
238 
239 #define DFS_MAX_B5_SIZE 128
240 #define DFS_MAX_B5_MASK 0x0000007F /* 128 */
241 
242 /* Max number of overlapping filters */
243 #define DFS_MAX_RADAR_OVERLAP 16
244 
245 /* Max number of dfs events which can be q'd */
246 #define DFS_MAX_EVENTS 1024
247 
248 #define DFS_RADAR_EN       0x80000000 /* Radar detect is capable */
249 #define DFS_AR_EN          0x40000000 /* AR detect is capable */
250 /* Radar detect in second segment is capable */
251 #define DFS_SECOND_SEGMENT_RADAR_EN 0x20000000
252 #define DFS_MAX_RSSI_VALUE 0x7fffffff /* Max rssi value */
253 
254 #define DFS_BIN_MAX_PULSES 60 /* max num of pulses in a burst */
255 #define DFS_BIN5_PRI_LOWER_LIMIT 990 /* us */
256 
257 /*
258  * To cover the single pusle burst case, change from 2010 us to
259  * 2010000 us.
260  */
261 
262 /*
263  * This is reverted back to 2010 as larger value causes false
264  * bin5 detect (EV76432, EV76320)
265  */
266 #define DFS_BIN5_PRI_HIGHER_LIMIT 2010 /* us */
267 
268 #define DFS_BIN5_WIDTH_MARGIN 4 /* us */
269 #define DFS_BIN5_RSSI_MARGIN  5 /* dBm */
270 
271 /*
272  * Following threshold is not specified but should be
273  * okay statistically.
274  */
275 #define DFS_BIN5_BRI_LOWER_LIMIT 300000   /* us */
276 #define DFS_BIN5_BRI_UPPER_LIMIT 12000000 /* us */
277 
278 /* Max number of pulses kept in buffer */
279 #define DFS_MAX_PULSE_BUFFER_SIZE   1024
280 #define DFS_MAX_PULSE_BUFFER_MASK   0x3ff
281 
282 #define DFS_FAST_CLOCK_MULTIPLIER    (800/11)
283 #define DFS_NO_FAST_CLOCK_MULTIPLIER (80)
284 #define DFS_BIG_SIDX 10000
285 
286 /* Min value of valid psidx diff */
287 #define DFS_MIN_PSIDX_DIFF 4
288 /* Max value of valid psidx diff */
289 #define DFS_MAX_PSIDX_DIFF 16
290 
291 /*
292  * Software use: channel interference used for as AR as well as RADAR
293  * interference detection.
294  */
295 #define CHANNEL_INTERFERENCE    0x01
296 
297 /* qdf_packed - denotes structure is packed. */
298 #define qdf_packed __qdf_packed
299 
300 #define SEG_ID_PRIMARY         0
301 #define SEG_ID_SECONDARY       1
302 
303 /* MIN and MAX width for different regions */
304 #define REG0_MIN_WIDTH 33
305 #define REG0_MAX_WIDTH 38
306 #define REG1_MIN_WIDTH 39
307 #define REG1_MAX_WIDTH 44
308 #define REG2_MIN_WIDTH 53
309 #define REG2_MAX_WIDTH 58
310 #define REG3_MIN_WIDTH 126
311 #define REG3_MAX_WIDTH 140
312 #define REG4_MIN_WIDTH 141
313 #define REG4_MAX_WIDTH 160
314 #define REG5_MIN_WIDTH 189
315 #define REG5_MAX_WIDTH 210
316 #define REG6_MIN_WIDTH 360
317 #define REG6_MAX_WIDTH 380
318 #define REG7_MIN_WIDTH 257
319 #define REG7_MAX_WIDTH 270
320 #define REG8_MIN_WIDTH 295
321 #define REG8_MAX_WIDTH 302
322 
323 #define OVER_SAMPLING_FREQ 44000
324 #define SAMPLING_FREQ 40000
325 #define HUNDRED 100
326 #define NUM_BINS 128
327 #define THOUSAND 1000
328 
329 /* Array offset to ETSI legacy pulse */
330 #define ETSI_LEGACY_PULSE_ARR_OFFSET 4
331 
332 #define ETSI_RADAR_EN302_502_FREQ_LOWER 5725
333 #define ETSI_RADAR_EN302_502_FREQ_UPPER 5865
334 
335 #define DFS_NOL_ADD_CHAN_LOCKED(dfs, freq, timeout)         \
336 	do {                                                \
337 		WLAN_DFSNOL_LOCK(dfs);                      \
338 		dfs_nol_addchan(dfs, freq, timeout);        \
339 		WLAN_DFSNOL_UNLOCK(dfs);                    \
340 	} while (0)
341 
342 /*
343  * Free the NOL element in a thread. This is to avoid freeing the
344  * timer object from within timer callback function . The nol element
345  * contains the timer Object.
346  */
347 #define DFS_NOL_DELETE_CHAN_LOCKED(dfs, freq, chwidth)      \
348 	do {                                                \
349 		WLAN_DFSNOL_LOCK(dfs);                      \
350 		dfs_nol_delete(dfs, freq, chwidth);         \
351 		qdf_sched_work(NULL, &dfs->dfs_nol_elem_free_work); \
352 		WLAN_DFSNOL_UNLOCK(dfs);                    \
353 	} while (0)
354 
355 #define DFS_GET_NOL_LOCKED(dfs, dfs_nol, nchan)             \
356 	do {                                                \
357 		WLAN_DFSNOL_LOCK(dfs);                      \
358 		dfs_get_nol(dfs, dfs_nol, nchan);           \
359 		WLAN_DFSNOL_UNLOCK(dfs);                    \
360 	} while (0)
361 
362 #define DFS_PRINT_NOL_LOCKED(dfs)                           \
363 	do {                                                \
364 		WLAN_DFSNOL_LOCK(dfs);                      \
365 		dfs_print_nol(dfs);                         \
366 		WLAN_DFSNOL_UNLOCK(dfs);                    \
367 	} while (0)
368 
369 #define DFS_NOL_FREE_LIST_LOCKED(dfs)                       \
370 	do {                                                \
371 		WLAN_DFSNOL_LOCK(dfs);                      \
372 		dfs_nol_free_list(dfs);                     \
373 		WLAN_DFSNOL_UNLOCK(dfs);                    \
374 	} while (0)
375 
376 /* Host sends the average parameters of the radar pulses and starts the status
377  * wait timer with this timeout.
378  */
379 #if defined(WLAN_DFS_PARTIAL_OFFLOAD) && defined(HOST_DFS_SPOOF_TEST)
380 #define HOST_DFS_STATUS_WAIT_TIMER_MS 350
381 #endif
382 
383 /*
384  * USENOL_DISABLE_NOL_HOST_AND_FW : Do not add radar hit channel to NOL
385  * in host and FW. Enable CSA on the same channel.
386  */
387 #define USENOL_DISABLE_NOL_HOST_AND_FW 0
388 /*
389  * USENOL_ENABLE_NOL_HOST_AND_FW : Add the radar hit channel to NOL in
390  * host and FW (in case of FO). NOL timer cannot be configured by the user
391  * as FW does not allow manipulating NOL timeout. If noltimeout is configured,
392  * (say 1 min) FW will not be intimated about the configuration and hence NOL
393  * timer may elapse at different instances in host (after 1 min) and FW (after
394  * default 30 min) which could lead to DFS Violation if host tries to come up
395  * on the channel after host NOL timeout (of 1 min) as the FW would still
396  * have the channel in NOL list.
397  */
398 #define USENOL_ENABLE_NOL_HOST_AND_FW 1
399 /*
400  * USENOL_ENABLE_NOL_HOST_DISABLE_NOL_FW : Add the radar hit channel to NOL
401  * in host. NOL timer can be configured by user. NOL in FW (for FO) is disabled.
402  */
403 #define USENOL_ENABLE_NOL_HOST_DISABLE_NOL_FW 2
404 
405 /**
406  * enum detector_id - Detector ID values.
407  * @DETECTOR_ID_0: Detector ID 0 (Non Agile).
408  * @DETECTOR_ID_1: Detector ID 1 (Non Agile in 80p80MHz supported devices,
409  *                 Agile detector in true 160MHz supported devices).
410  * @DETECTOR_ID_2: Detector ID 2 (Agile detector in 80p80MHZ supported devices).
411  * @AGILE_DETECTOR_ID_TRUE_160MHZ:  Agile detector ID in true 160MHz devices.
412  * @AGILE_DETECTOR_11BE:  Agile detector ID in true 320 MHz devices.
413  * @AGILE_DETECTOR_ID_80P80: Agile detector ID in 80p80MHz supported devices.
414  * @INVALID_DETECTOR_ID: Invalid detector id.
415  */
416 enum detector_id {
417 	DETECTOR_ID_0,
418 	DETECTOR_ID_1,
419 	DETECTOR_ID_2,
420 	AGILE_DETECTOR_ID_TRUE_160MHZ = DETECTOR_ID_1,
421 	AGILE_DETECTOR_11BE = DETECTOR_ID_1,
422 	AGILE_DETECTOR_ID_80P80 = DETECTOR_ID_2,
423 	INVALID_DETECTOR_ID,
424 };
425 
426 /**
427  * struct dfs_pulseparams - DFS pulse param structure.
428  * @p_time:        Time for start of pulse in usecs.
429  * @p_dur:         Duration of pulse in usecs.
430  * @p_rssi:        RSSI of pulse.
431  * @p_seg_id:      Segment id.
432  * @p_sidx:        Sidx value.
433  * @p_delta_peak:  Delta peak value.
434  * @p_psidx_diff:  The difference in the FFT peak index between the short FFT
435  *                 and the first long FFT.
436  * @p_seq_num:     Sequence number.
437  */
438 struct dfs_pulseparams {
439 	uint64_t p_time;
440 	uint8_t  p_dur;
441 	uint8_t  p_rssi;
442 	uint8_t  p_seg_id;
443 	int16_t  p_sidx;
444 	int8_t   p_delta_peak;
445 	int16_t  p_psidx_diff;
446 	uint32_t p_seq_num;
447 } qdf_packed;
448 
449 /**
450  * struct dfs_pulseline - Pulseline structure.
451  * @pl_elems:       array of pulses in delay line.
452  * @pl_firstelem:   Index of the first element.
453  * @pl_lastelem:    Index of the last element.
454  * @pl_numelems:    Number of elements in the delay line.
455  */
456 struct dfs_pulseline {
457 	struct dfs_pulseparams pl_elems[DFS_MAX_PULSE_BUFFER_SIZE];
458 	uint32_t pl_firstelem;
459 	uint32_t pl_lastelem;
460 	uint32_t pl_numelems;
461 } qdf_packed;
462 
463 #define DFS_EVENT_CHECKCHIRP  0x01 /* Whether to check the chirp flag */
464 #define DFS_EVENT_HW_CHIRP    0x02 /* hardware chirp */
465 #define DFS_EVENT_SW_CHIRP    0x04 /* software chirp */
466 /* Whether the event contains valid psidx diff value*/
467 #define DFS_EVENT_VALID_PSIDX_DIFF 0x08
468 
469 /* Use this only if the event has CHECKCHIRP set. */
470 #define DFS_EVENT_ISCHIRP(e) \
471 	((e)->re_flags & (DFS_EVENT_HW_CHIRP | DFS_EVENT_SW_CHIRP))
472 
473 /**
474  * DFS_EVENT_NOTCHIRP() - Check if event can be a chirp
475  * @e: event
476  *
477  * Check if the given event is to be rejected as not possibly
478  * a chirp.  This means:
479  *   (a) it's a hardware or software checked chirp, and
480  *   (b) the HW/SW chirp bits are both 0.
481  */
482 #define DFS_EVENT_NOTCHIRP(e) \
483 	(((e)->re_flags & (DFS_EVENT_CHECKCHIRP)) && (!DFS_EVENT_ISCHIRP((e))))
484 
485 /**
486  * struct dfs_event - DFS event structure.
487  * @re_full_ts:          64-bit full timestamp from interrupt time.
488  * @re_ts:               Original 15 bit recv timestamp.
489  * @re_rssi:             Rssi of radar event.
490  * @re_dur:              Duration of radar pulse.
491  * @re_chanindex:        Channel of event.
492  * @re_flags:            Event flags.
493  * @re_freq:             Centre frequency of event, KHz.
494  * @re_freq_lo:          Lower bounds of frequency, KHz.
495  * @re_freq_hi:          Upper bounds of frequency, KHz.
496  * @re_seg_id:           HT80_80/HT160 use.
497  * @re_sidx:             Seg index.
498  * @re_freq_offset_khz:  Freq offset in KHz
499  * @re_peak_mag:         Peak mag.
500  * @re_total_gain:       Total gain.
501  * @re_mb_gain:          Mb gain.
502  * @re_relpwr_db:        Relpower in db.
503  * @re_delta_diff:       Delta diff.
504  * @re_delta_peak:       Delta peak.
505  * @re_psidx_diff:       Psidx diff.
506  * @re_list:             List of radar events.
507  */
508 struct dfs_event {
509 	uint64_t  re_full_ts;
510 	uint32_t  re_ts;
511 	uint8_t   re_rssi;
512 	uint8_t   re_dur;
513 	uint8_t   re_chanindex;
514 	uint8_t   re_flags;
515 	uint32_t  re_freq;
516 	uint32_t  re_freq_lo;
517 	uint32_t  re_freq_hi;
518 	uint8_t   re_seg_id;
519 	int       re_sidx;
520 	u_int     re_freq_offset_khz;
521 	int       re_peak_mag;
522 	int       re_total_gain;
523 	int       re_mb_gain;
524 	int       re_relpwr_db;
525 	uint8_t   re_delta_diff;
526 	int8_t    re_delta_peak;
527 	int16_t   re_psidx_diff;
528 
529 	STAILQ_ENTRY(dfs_event) re_list;
530 } qdf_packed;
531 
532 #define DFS_AR_MAX_ACK_RADAR_DUR   511
533 #define DFS_AR_MAX_NUM_PEAKS       3
534 #define DFS_AR_ARQ_SIZE            2048 /* 8K AR events for buffer size */
535 #define DFS_AR_ARQ_SEQSIZE         2049 /* Sequence counter wrap for AR */
536 
537 #define DFS_RADARQ_SIZE      512 /* 1K radar events for buffer size */
538 #define DFS_RADARQ_SEQSIZE   513 /* Sequence counter wrap for radar */
539 /* Number of radar channels we keep state for */
540 #define DFS_NUM_RADAR_STATES 64
541 /* Max number radar filters for each type */
542 #define DFS_MAX_NUM_RADAR_FILTERS 10
543 /* Number of different radar types */
544 #define DFS_MAX_RADAR_TYPES  32
545 /* Number of filter index table rows */
546 #define DFS_NUM_FT_IDX_TBL_ROWS  256
547 
548 /* RADAR filter pattern type 1*/
549 #define WLAN_DFS_RF_PATTERN_TYPE_1 1
550 
551 /**
552  * struct dfs_ar_state - DFS AR state structure.
553  * @ar_prevwidth:         Previous width.
554  * @ar_phyerrcount:       Phy error count.
555  * @ar_acksum:            Acksum.
556  * @ar_packetthreshold:   Thresh to determine traffic load.
557  * @ar_parthreshold:      Thresh to determine peak.
558  * @ar_radarrssi:         Rssi threshold for AR event.
559  * @ar_prevtimestamp:     Prev time stamp.
560  * @ar_peaklist:          Peak list.
561  */
562 struct dfs_ar_state {
563 	uint32_t ar_prevwidth;
564 	uint32_t ar_phyerrcount[DFS_AR_MAX_ACK_RADAR_DUR];
565 	uint32_t ar_acksum;
566 	uint32_t ar_packetthreshold;
567 	uint32_t ar_parthreshold;
568 	uint32_t ar_radarrssi;
569 	uint16_t ar_prevtimestamp;
570 	uint16_t ar_peaklist[DFS_AR_MAX_NUM_PEAKS];
571 };
572 
573 /**
574  * struct dfs_delayelem - Delay Element.
575  * @de_time:       Current "filter" time for start of pulse in usecs.
576  * @de_dur:        Duration of pulse in usecs.
577  * @de_rssi:       Rssi of pulse in dB.
578  * @de_ts:         Time stamp for this delay element.
579  * @de_seg_id:     Segment id for HT80_80/HT160 use.
580  * @de_sidx:       Sidx value.
581  * @de_delta_peak: Delta peak.
582  * @de_psidx_diff: Psidx diff.
583  * @de_seq_num:    Sequence number.
584  */
585 struct dfs_delayelem {
586 	uint32_t de_time;
587 	uint8_t  de_dur;
588 	uint8_t  de_rssi;
589 	uint64_t de_ts;
590 	uint8_t  de_seg_id;
591 	int16_t  de_sidx;
592 	int8_t   de_delta_peak;
593 	int16_t  de_psidx_diff;
594 	uint32_t de_seq_num;
595 } qdf_packed;
596 
597 /**
598  * struct dfs_delayline - DFS Delay Line.
599  * @dl_elems:      Array of pulses in delay line.
600  * @dl_last_ts:    Last timestamp the delay line was used (in usecs).
601  * @dl_firstelem:  Index of the first element.
602  * @dl_lastelem:   Index of the last element.
603  * @dl_numelems:   Number of elements in the delay line.
604  * The following is to handle fractional PRI pulses that can cause false
605  * detection.
606  * @dl_seq_num_start: Sequence number of first pulse that was part of
607  *                    threshold match.
608  * @dl_seq_num_stop:  Sequence number of last pulse that was part of threshold
609  *                    match.
610  * The following is required because the first pulse may or may not be in the
611  * delay line but we will find it iin the pulse line using dl_seq_num_second's
612  * diff_ts value.
613  * @dl_seq_num_second: Sequence number of second pulse that was part of
614  *                     threshold match.
615  * @dl_search_pri:     We need final search PRI to identify possible fractional
616  *                     PRI issue.
617  * @dl_min_sidx:       Minimum sidx value of pulses used to match thershold.
618  *                     Used for sidx spread check.
619  * @dl_max_sidx:       Maximum sidx value of pulses used to match thershold.
620  *                     Used for sidx spread check.
621  * @dl_delta_peak_match_count: Number of pulse in the delay line that had valid
622  *                             delta peak value.
623  * @dl_psidx_diff_match_count: Number of pulse in the delay line that had valid
624  *                             psidx diff value.
625  */
626 struct dfs_delayline {
627 	struct dfs_delayelem dl_elems[DFS_MAX_DL_SIZE];
628 	uint64_t dl_last_ts;
629 	uint32_t dl_firstelem;
630 	uint32_t dl_lastelem;
631 	uint32_t dl_numelems;
632 	uint32_t dl_seq_num_start;
633 	uint32_t dl_seq_num_stop;
634 	uint32_t dl_seq_num_second;
635 	uint32_t dl_search_pri;
636 	int16_t  dl_min_sidx;
637 	int8_t   dl_max_sidx;
638 	uint8_t  dl_delta_peak_match_count;
639 	uint8_t  dl_psidx_diff_match_count;
640 } qdf_packed;
641 
642 /**
643  * struct dfs_filter - Dfs filter.
644  * @rf_dl:              Delay line of pulses for this filter.
645  * @rf_numpulses:       Number of pulses in the filter.
646  * @rf_minpri:          Min pri to be considered for this filter.
647  * @rf_maxpri:          Max pri to be considered for this filter.
648  * @rf_threshold:       Match filter output threshold for radar detect.
649  * @rf_filterlen:       Length (in usecs) of the filter.
650  * @rf_patterntype:     Fixed or variable pattern type.
651  * @rf_fixed_pri_radar_pulse: indicates if it is a fixed pri pulse.
652  * @rf_mindur:          Min duration for this radar filter.
653  * @rf_maxdur:          Max duration for this radar filter.
654  * @rf_ignore_pri_window: Ignore pri window.
655  * @rf_pulseid:         Unique ID corresponding to the original filter ID.
656  * To reduce false detection, look at frequency spread. For now we will use
657  * sidx spread. But for HT160 frequency spread will be a better measure.
658  * @rf_sidx_spread:     Maximum SIDX value spread in a matched sequence
659  *                      excluding FCC Bin 5.
660  * @rf_check_delta_peak: Minimum allowed delta_peak value for a pulse to be
661  *                       considetred for this filter's match.
662  */
663 struct dfs_filter {
664 	struct dfs_delayline rf_dl;
665 	uint32_t  rf_numpulses;
666 	uint32_t  rf_minpri;
667 	uint32_t  rf_maxpri;
668 	uint32_t  rf_threshold;
669 	uint32_t  rf_filterlen;
670 	uint32_t  rf_patterntype;
671 	uint32_t  rf_fixed_pri_radar_pulse;
672 	uint32_t  rf_mindur;
673 	uint32_t  rf_maxdur;
674 	uint32_t  rf_ignore_pri_window;
675 	uint32_t  rf_pulseid;
676 	uint16_t  rf_sidx_spread;
677 	int8_t    rf_check_delta_peak;
678 } qdf_packed;
679 
680 /**
681  * struct dfs_filtertype - Structure of DFS Filter type.
682  * @ft_filters:        Array of ptrs storing addresses for struct of dfs_filter.
683  * @ft_filterdur:      Duration of pulse which specifies filter type.
684  * @ft_numfilters:     Num filters of this type.
685  * @ft_last_ts:        Last timestamp this filtertype was used (in usecs).
686  * @ft_mindur:         Min pulse duration to be considered for this filter type.
687  * @ft_maxdur:         Max pulse duration to be considered for this filter type.
688  * @ft_rssithresh:     Min rssi to be considered for this filter type.
689  * @ft_numpulses:      Num pulses in each filter of this type.
690  * @ft_patterntype:    Fixed or variable pattern type.
691  * @ft_minpri:         Min pri to be considered for this type.
692  * @ft_rssimargin:     Rssi threshold margin. In Turbo Mode HW reports rssi 3dB
693  *                     lower than in non TURBO mode. This will offset that diff.
694  */
695 struct dfs_filtertype {
696 	struct dfs_filter *ft_filters[DFS_MAX_NUM_RADAR_FILTERS];
697 	uint32_t  ft_filterdur;
698 	uint32_t  ft_numfilters;
699 	uint64_t  ft_last_ts;
700 	uint32_t  ft_mindur;
701 	uint32_t  ft_maxdur;
702 	uint32_t  ft_rssithresh;
703 	uint32_t  ft_numpulses;
704 	uint32_t  ft_patterntype;
705 	uint32_t  ft_minpri;
706 	uint32_t  ft_rssimargin;
707 };
708 
709 /**
710  * struct dfs_channel - Channel structure for dfs component.
711  * @dfs_ch_freq:                Frequency in Mhz.
712  * @dfs_ch_flags:               Channel flags.
713  * @dfs_ch_flagext:             Extended channel flags.
714  * @dfs_ch_ieee:                IEEE channel number.
715  * @dfs_ch_vhtop_ch_freq_seg1:  IEEE Channel Center of primary segment
716  * @dfs_ch_vhtop_ch_freq_seg2:  IEEE Channel Center applicable for 80+80MHz
717  *                              mode of operation.
718  * @dfs_ch_mhz_freq_seg1:       Channel center frequency of primary segment in
719  *                              MHZ.
720  * @dfs_ch_mhz_freq_seg2:       Channel center frequency of secondary segment
721  *                              in MHZ applicable only for 80+80MHZ mode of
722  *                              operation.
723  * @dfs_ch_punc_pattern:        Bitmap representing puncturing patterns.
724  * @dfs_internal_radar_pattern: Bitmap representing puncturing patterns caused
725  *                              by radar.
726  */
727 struct dfs_channel {
728 	uint16_t       dfs_ch_freq;
729 	uint64_t       dfs_ch_flags;
730 	uint16_t       dfs_ch_flagext;
731 	uint8_t        dfs_ch_ieee;
732 	uint8_t        dfs_ch_vhtop_ch_freq_seg1;
733 	uint8_t        dfs_ch_vhtop_ch_freq_seg2;
734 	uint16_t       dfs_ch_mhz_freq_seg1;
735 	uint16_t       dfs_ch_mhz_freq_seg2;
736 #ifdef WLAN_FEATURE_11BE
737 	/* If the bitmap is all 0 then nothing is punctured. If any bit is 1
738 	 * then corresponding 20MHz sub-channel is puntured. For example, for
739 	 * channel 100 (BW 240MHz), it will treated as a 320MHz channel and the
740 	 * bit-map will be b1111_0000_0000_0000 (where the most significant bit
741 	 * indicates the rightmost sub20channel and the least significant bit
742 	 * indicates the leftmost sub20channel).
743 	 */
744 	uint16_t       dfs_ch_punc_pattern;
745 #endif
746 };
747 
748 /**
749  * struct dfs_state - DFS state.
750  * @rs_chan:            Channel info.
751  * @rs_chanindex:       Channel index in radar structure.
752  * @rs_numradarevents:  Number of radar events.
753  * @rs_param:           Phy param.
754  */
755 struct dfs_state {
756 	struct dfs_channel rs_chan;
757 	uint8_t  rs_chanindex;
758 	uint32_t rs_numradarevents;
759 	struct wlan_dfs_phyerr_param rs_param;
760 };
761 
762 #define DFS_NOL_TIMEOUT_S  (30*60)    /* 30 minutes in seconds */
763 #define DFS_NOL_TIMEOUT_MS (DFS_NOL_TIMEOUT_S * 1000)
764 #define DFS_NOL_TIMEOUT_US (DFS_NOL_TIMEOUT_MS * 1000)
765 
766 /**
767  * struct dfs_nolelem - DFS NOL element.
768  * @nolelem_list:     NOL element list node
769  * @nol_dfs:          Back pointer to dfs object.
770  * @nol_freq:         Centre frequency.
771  * @nol_chwidth:      Event width (MHz).
772  * @nol_start_us:     NOL start time in us.
773  * @nol_timeout_ms:   NOL timeout value in msec.
774  * @nol_timer:        Per element NOL timer.
775  * @nol_next:         Next element pointer.
776  */
777 struct dfs_nolelem {
778 	TAILQ_ENTRY(dfs_nolelem) nolelem_list;
779 	struct wlan_dfs *nol_dfs;
780 	uint32_t       nol_freq;
781 	uint32_t       nol_chwidth;
782 	uint64_t       nol_start_us;
783 	uint32_t       nol_timeout_ms;
784 	qdf_hrtimer_data_t    nol_timer;
785 	struct dfs_nolelem *nol_next;
786 };
787 
788 
789 /**
790  * struct dfs_info - DFS Info.
791  * @rn_ftindex:            Number of different types of radars.
792  * @rn_lastfull_ts:        Last 64 bit timstamp from recv interrupt.
793  * @rn_last_ts:            last 15 bit ts from recv descriptor.
794  * @rn_last_unique_ts:     last unique 32 bit ts from recv descriptor.
795  * @rn_ts_prefix:          Prefix to prepend to 15 bit recv ts.
796  * @rn_numbin5radars:      Number of bin5 radar pulses to search for.
797  * @rn_fastdivGCval:       Value of fast diversity gc limit from init file.
798  * @rn_minrssithresh:      Min rssi for all radar types.
799  * @rn_maxpulsedur:        Max pulse width in TSF ticks.
800  * @dfs_ext_chan_busy:     Ext chan busy.
801  * @ext_chan_busy_ts:      Ext chan busy time.
802  * @dfs_bin5_chirp_ts:     Ext bin5 chrip time.
803  * @dfs_last_bin5_dur:     Last bin5 during.
804  */
805 struct dfs_info {
806 	uint32_t  rn_ftindex;
807 	uint64_t  rn_lastfull_ts;
808 	uint16_t  rn_last_ts;
809 	uint32_t  rn_last_unique_ts;
810 	uint64_t  rn_ts_prefix;
811 	uint32_t  rn_numbin5radars;
812 	uint32_t  rn_fastdivGCval;
813 	int32_t   rn_minrssithresh;
814 	uint32_t  rn_maxpulsedur;
815 	uint8_t   dfs_ext_chan_busy;
816 	uint64_t  ext_chan_busy_ts;
817 	uint64_t  dfs_bin5_chirp_ts;
818 	uint8_t   dfs_last_bin5_dur;
819 } qdf_packed;
820 
821 /**
822  * struct dfs_bin5elem - BIN5 elements.
823  * @be_ts:   Timestamp for the bin5 element.
824  * @be_rssi: Rssi for the bin5 element.
825  * @be_dur:  Duration of bin5 element.
826  */
827 struct dfs_bin5elem {
828 	uint64_t  be_ts;
829 	uint32_t  be_rssi;
830 	uint32_t  be_dur;
831 };
832 
833 /**
834  * struct dfs_bin5radars - BIN5 radars.
835  * @br_elems:      List of bin5 elems that fall within the time window.
836  * @br_firstelem:  Index of the first element.
837  * @br_lastelem:   Index of the last element.
838  * @br_numelems:   Number of elements in the delay line.
839  * @br_pulse:      Original info about bin5 pulse.
840  */
841 struct dfs_bin5radars {
842 	struct dfs_bin5elem br_elems[DFS_MAX_B5_SIZE];
843 	uint32_t  br_firstelem;
844 	uint32_t  br_lastelem;
845 	uint32_t  br_numelems;
846 	struct dfs_bin5pulse br_pulse;
847 };
848 
849 /**
850  * struct dfs_stats - DFS stats.
851  * @num_radar_detects:    Total num. of radar detects.
852  * @num_seg_two_radar_detects: Total num. of radar detected in secondary segment
853  * @total_phy_errors:     Total PHY errors.
854  * @owl_phy_errors:       OWL PHY errors.
855  * @pri_phy_errors:       Primary channel phy errors.
856  * @ext_phy_errors:       Extension channel phy errors.
857  * @dc_phy_errors:        DC PHY errors.
858  * @early_ext_phy_errors: Extension channel early radar found error.
859  * @bwinfo_errors:        Bogus bandwidth info received in descriptor.
860  * @datalen_discards:     data length at least three bytes of payload.
861  * @rssi_discards:        RSSI is not accurate.
862  * @last_reset_tstamp:    Last reset timestamp.
863  */
864 struct dfs_stats {
865 	uint32_t       num_radar_detects;
866 	uint32_t  num_seg_two_radar_detects;
867 	uint32_t  total_phy_errors;
868 	uint32_t  owl_phy_errors;
869 	uint32_t  pri_phy_errors;
870 	uint32_t  ext_phy_errors;
871 	uint32_t  dc_phy_errors;
872 	uint32_t  early_ext_phy_errors;
873 	uint32_t  bwinfo_errors;
874 	uint32_t  datalen_discards;
875 	uint32_t  rssi_discards;
876 	uint64_t  last_reset_tstamp;
877 };
878 
879 #define DFS_EVENT_LOG_SIZE      256
880 
881 /**
882  * struct dfs_event_log - DFS event log.
883  * @ts:               64-bit full timestamp from interrupt time.
884  * @diff_ts:          Diff timestamp.
885  * @rssi:             Rssi of radar event.
886  * @dur:              Duration of radar pulse.
887  * @is_chirp:         Chirp flag.
888  * @seg_id:           HT80_80/HT160 use.
889  * @sidx:             Seg index.
890  * @freq_offset_khz:  Freq offset in KHz
891  * @peak_mag:         Peak mag.
892  * @total_gain:       Total gain.
893  * @mb_gain:          Mb gain.
894  * @relpwr_db:        Relpower in db.
895  * @delta_diff:       Delta diff.
896  * @delta_peak:       Delta peak.
897  * @psidx_diff:       Psidx diff.
898  */
899 
900 struct dfs_event_log {
901 	uint64_t  ts;
902 	uint32_t  diff_ts;
903 	uint8_t   rssi;
904 	uint8_t   dur;
905 	int       is_chirp;
906 	uint8_t   seg_id;
907 	int       sidx;
908 	u_int     freq_offset_khz;
909 	int       peak_mag;
910 	int       total_gain;
911 	int       mb_gain;
912 	int       relpwr_db;
913 	uint8_t   delta_diff;
914 	int8_t    delta_peak;
915 	int16_t   psidx_diff;
916 };
917 
918 #define WLAN_DFS_WEATHER_CHANNEL_WAIT_MIN 10 /*10 minutes*/
919 #define WLAN_DFS_WEATHER_CHANNEL_WAIT_S (WLAN_DFS_WEATHER_CHANNEL_WAIT_MIN * 60)
920 #define WLAN_DFS_WEATHER_CHANNEL_WAIT_MS  \
921 	((WLAN_DFS_WEATHER_CHANNEL_WAIT_S) * 1000) /*in MS*/
922 
923 #define WLAN_DFS_WAIT_POLL_PERIOD 2  /* 2 seconds */
924 #define WLAN_DFS_WAIT_POLL_PERIOD_MS  \
925 	((WLAN_DFS_WAIT_POLL_PERIOD) * 1000)  /*in MS*/
926 
927 #define DFS_DEBUG_TIMEOUT_S     30 /* debug timeout is 30 seconds */
928 #define DFS_DEBUG_TIMEOUT_MS    (DFS_DEBUG_TIMEOUT_S * 1000)
929 
930 #define RSSI_POSSIBLY_FALSE              50
931 #define SEARCH_FFT_REPORT_PEAK_MAG_THRSH 40
932 
933 #define MIN_DFS_SUBCHAN_BW 20 /* Minimum bandwidth of each subchannel. */
934 
935 #define FREQ_OFFSET_BOUNDARY_FOR_80MHZ 40
936 
937 #define FREQ_OFFSET_BOUNDARY_FOR_160MHZ 80
938 
939 /**
940  * struct dfs_mode_switch_defer_params - Parameters storing DFS information
941  * before defer, as part of HW mode switch.
942  *
943  * @radar_params: Deferred radar parameters.
944  * @is_cac_completed: Boolean representing CAC completion event.
945  * @is_radar_detected: Boolean representing radar event.
946  */
947 struct dfs_mode_switch_defer_params {
948 	struct radar_found_info *radar_params;
949 	bool is_cac_completed;
950 	bool is_radar_detected;
951 };
952 
953 #ifdef QCA_SUPPORT_AGILE_DFS
954 #define DFS_PSOC_NO_IDX 0xFF
955 /**
956  * enum dfs_agile_sm_state - DFS AGILE SM states.
957  * @DFS_AGILE_S_INIT:     Default state or the start state of the Agile SM.
958  * @DFS_AGILE_S_RUNNING:  Agile Engine is being run.
959  * @DFS_AGILE_S_COMPLETE: The Agile Engine's minimum run is complete.
960  *                        However, it is still running. Used only for RCAC
961  *                        as RCAC needs to run continuously (uninterrupted)
962  *                        until the channel change.
963  * @DFS_AGILE_S_MAX:      Max (invalid) state.
964  */
965 enum dfs_agile_sm_state {
966 	DFS_AGILE_S_INIT,
967 	DFS_AGILE_S_RUNNING,
968 	DFS_AGILE_S_COMPLETE,
969 	DFS_AGILE_S_MAX,
970 };
971 
972 /**
973  * struct dfs_rcac_params - DFS Rolling CAC channel parameters.
974  * @rcac_pri_freq: Rolling CAC channel's primary frequency.
975  * @rcac_ch_params: Rolling CAC channel parameters.
976  */
977 struct dfs_rcac_params {
978 	qdf_freq_t rcac_pri_freq;
979 	struct ch_params rcac_ch_params;
980 };
981 
982 /**
983  * struct adfs_completion_params - Agile DFS completion parameters
984  * @ocac_status:   Off channel CAC completion status
985  * @center_freq1:  For 20/40/80/160Mhz, it is the center of the corresponding
986  *                 segment. For 80P80/165MHz, it is the center of the left
987  *                 80MHz.
988  * @center_freq2:  It is valid and non-zero only for 80P80/165MHz. It indicates
989  *                 the Center Frequency of the right 80MHz segment.
990  * @chan_width:    Channel Width
991  */
992 struct adfs_completion_params {
993 	enum ocac_status_type ocac_status;
994 	uint32_t center_freq1;
995 	uint32_t center_freq2;
996 	uint32_t chan_width;
997 };
998 #endif
999 
1000 #ifdef WLAN_DISP_CHAN_INFO
1001 /**
1002  * struct dfs_cacelem - CAC parameters of a DFS channel (20 MHz channel).
1003  * @cac_start_us: Time in microseconds when cac started (monotonic boot time).
1004  * @cac_completed_time: CAC completed time in ms (monotonic boot time).
1005  */
1006 struct dfs_cacelem {
1007 	uint64_t cac_start_us;
1008 	uint64_t cac_completed_time;
1009 };
1010 #endif
1011 
1012 #define DFS_PUNC_SM_SPIN_LOCK(_dfs_obj) \
1013 	qdf_spin_lock_bh(&((_dfs_obj)->dfs_punc_sm_lock))
1014 #define DFS_PUNC_SM_SPIN_UNLOCK(_dfs_obj) \
1015 	qdf_spin_unlock_bh(&((_dfs_obj)->dfs_punc_sm_lock))
1016 
1017 #define N_MAX_PUNC_SM 2
1018 
1019 /**
1020  * enum dfs_punc_sm_evt - DFS Puncturing SM events.
1021  * @DFS_PUNC_SM_EV_RADAR: Radar event on DFS puncturing SM.
1022  * @DFS_PUNC_SM_EV_NOL_EXPIRY: NOL expiry event on DFS puncturing SM.
1023  * @DFS_PUNC_SM_EV_CAC_EXPIRY: CAC expiry event on DFS puncturing SM.
1024  * @DFS_PUNC_SM_EV_STOP: STOP event on DFS puncturing SM.
1025  */
1026 enum dfs_punc_sm_evt {
1027 	DFS_PUNC_SM_EV_RADAR      = 0,
1028 	DFS_PUNC_SM_EV_NOL_EXPIRY = 1,
1029 	DFS_PUNC_SM_EV_CAC_EXPIRY = 2,
1030 	DFS_PUNC_SM_EV_STOP       = 3,
1031 };
1032 
1033 /**
1034  * enum dfs_punc_sm_state - DFS Puncturing SM states.
1035  * @DFS_S_UNPUNCTURED:    Default state or the start state of the puncturing SM.
1036  * @DFS_S_PUNCTURED:      DFS channel is punctured.
1037  * @DFS_S_CAC_WAIT:       The channel completed the NOL time and is waiting for
1038  *                        CAC completion.
1039  * @DFS_PUNCTURING_S_MAX: Max (invalid) state.
1040  */
1041 enum dfs_punc_sm_state {
1042 	DFS_S_UNPUNCTURED    = 0,
1043 	DFS_S_PUNCTURED      = 1,
1044 	DFS_S_CAC_WAIT       = 2,
1045 	DFS_PUNCTURING_S_MAX = 3,
1046 };
1047 
1048 /**
1049  * struct dfs_punc_obj -   DFS puncture object type. Each object represents one
1050  *                         set of continuous punctured-channels. These channels
1051  *                         were punctured by DFS component (NOT by other
1052  *                         components).
1053  * @punc_low_freq:         Low frequency of the continuous puncture object.
1054  * @punc_high_freq:        High frequency of the continuous puncture object.
1055  * @dfs_punc_cac_timer:    CAC timer for DFS unpuncturing for the puncture
1056  *                         object.
1057  * @dfs:                   Pointer to main DFS structure.
1058  * @dfs_punc_sm_hdl:       The handle for the state machine.
1059  * @dfs_punc_sm_cur_state: Current state of the Puncturing State Machine.
1060  * @dfs_punc_sm_lock:      Puncturing state machine lock.
1061  * @dfs_is_unpunctured:    Denotes the SM is unpunctured or not.
1062  */
1063 struct dfs_punc_obj {
1064 	qdf_freq_t punc_low_freq;
1065 	qdf_freq_t punc_high_freq;
1066 	qdf_hrtimer_data_t dfs_punc_cac_timer;
1067 	struct wlan_dfs *dfs;
1068 	struct wlan_sm *dfs_punc_sm_hdl;
1069 	enum dfs_punc_sm_state dfs_punc_sm_cur_state;
1070 	qdf_spinlock_t dfs_punc_sm_lock;
1071 	bool dfs_is_unpunctured;
1072 };
1073 
1074 /**
1075  * struct dfs_punc_unpunc - The type of the list of the DFS puncture objects.
1076  * @dfs_punc_arr:  Array of puncture objects.
1077  */
1078 struct dfs_punc_unpunc {
1079 	struct dfs_punc_obj dfs_punc_arr[N_MAX_PUNC_SM];
1080 };
1081 
1082 /*
1083  * NB: not using kernel-doc format since the kernel-doc script doesn't
1084  *     handle the TAILQ_HEAD() or STAILQ_HEAD() macros
1085  *
1086  * struct wlan_dfs -                 The main dfs structure.
1087  * @dfs_debug_mask:                  Current debug bitmask.
1088  * @dfs_curchan_radindex:            Current channel radar index.
1089  * @dfs_extchan_radindex:            Extension channel radar index.
1090  * @dfs_ar_state:                    AR state.
1091  * @dfs_radar:                       Per-Channel Radar detector state.
1092  * @dfs_radarf:                      One filter for each radar pulse type.
1093  * @dfs_rinfo:                       State vars for radar processing.
1094  * @dfs_b5radars:                    Array of bin5 radar events.
1095  * @dfs_ftindextable:                Map of radar durs to filter types.
1096  * @dfs_defaultparams:               Default phy params per radar state.
1097  * @events:                          Events structure.
1098  * @dfs_caps:                        Object of wlan_dfs_caps structure.
1099  * @wlan_dfs_task_timer:             Dfs wait timer.
1100  * @dur_multiplier:                  Duration multiplier.
1101  * @wlan_dfs_isdfsregdomain:         True when AP is in DFS domain
1102  * @dfs_phyerr_w53_counter:          Phyerr w53 counter.
1103  * @dfs_seq_num:                     Sequence number.
1104  * @dfs_min_sidx:                    Minimum sidx of the received radar pulses.
1105  * @dfs_max_sidx:                    Maximum sidx of the received radar pulses.
1106  * @dfs_data_struct_lock:            DFS data structure lock. This is to protect
1107  *                                   all the filtering data structures. For
1108  *                                   example: dfs_bin5radars, dfs_filtertype,
1109  *                                   etc.
1110  * @dfs_lowest_pri_limit:
1111  * @dfs_eventq:                      Q of free dfs event objects.
1112  * @dfs_radarq:                      Q of radar events.
1113  * @dfs_arq:                         Q of AR events.
1114  * @dfs_host_wait_timer:             The timer that is started from host after
1115  *                                   sending the average radar parameters.
1116  *                                   Before this timeout host expects its dfs
1117  *                                   status from fw.
1118  * @dfs_average_pri:                 Average pri value of the received radar
1119  *                                   pulses.
1120  * @dfs_average_duration:            Average duration of the received radar
1121  *                                   pulses.
1122  * @dfs_average_sidx:                Average sidx of the received radar pulses.
1123  * @dfs_is_host_wait_running:        Indicates if host dfs status wait timer is
1124  *                                   running.
1125  * @dfs_average_params_sent:         Indicates if host has sent the average
1126  *                                   radar parameters.
1127  * @dfs_no_res_from_fw:              Indicates no response from fw.
1128  * @dfs_spoof_check_failed:          Indicates if the spoof check has failed.
1129  * @dfs_radar_found_chan:            The channel on which radar was found.
1130  * @dfs_status_timeout_override:     Used to change the timeout value of
1131  *                                   dfs_host_wait_timer.
1132  * @dfs_allow_hw_pulses:             Allow/Block HW pulses. When synthetic
1133  *                                   pulses are injected, the HW pulses should
1134  *                                   be blocked and this variable should be
1135  *                                   false so that HW pulses and synthetic
1136  *                                   pulses do not get mixed up.
1137  * @dfsdomain:                       Current DFS domain.
1138  * @dfs_proc_phyerr:                 Flags for Phy Errs to process.
1139  * @dfs_eventqlock:                  Lock for free dfs event list.
1140  * @dfs_radarqlock:                  Lock for dfs q.
1141  * @dfs_arqlock:                     Lock for AR q.
1142  * @dfs_nol:                         Non occupancy list for radar.
1143  * @dfs_nol_count:                   How many items?
1144  * @wlan_dfs_stats:                  DFS related stats.
1145  * @pulses:                          Pulse history.
1146  * @wlan_radar_tasksched:            Radar task is scheduled.
1147  * @wlan_dfswait:                    Waiting on channel for radar detect.
1148  * @wlan_dfstest:                    Test timer in progress.
1149  * @wlan_dfstest_ieeechan:           IEEE chan num to return to after a dfs mute
1150  *                                   test.
1151  * @wlan_dfs_cac_time:               CAC period.
1152  * @wlan_dfstesttime:                Time to stay off chan during dfs test.
1153  * @wlan_dfstesttimer:               Dfs mute test timer.
1154  * @dfs_bangradar_type:              Radar simulation type.
1155  * @is_radar_found_on_secondary_seg: Radar on second segment.
1156  * @is_radar_during_precac:          Radar found during precac.
1157  * @dfs_precac_lock:                 Lock to protect precac lists.
1158  * @dfs_precac_secondary_freq_mhz:   Second segment freq in MHZ for precac.
1159  *                                   Applicable to only legacy chips.
1160  * @dfs_precac_primary_freq_mhz:     PreCAC Primary freq in MHZ applicable only
1161  *                                   to legacy chips.
1162  * @dfs_defer_precac_channel_change: Defer precac channel change.
1163  * @dfs_autoswitch_des_mode:         Desired PHY mode which has to be used
1164  *                                   after precac.
1165  * @dfs_autoswitch_chan:             Desired channel of dfs_channel structure
1166  *                                   which will be prioritized for preCAC.
1167  * @dfs_precac_inter_chan_freq:      Intermediate non-DFS freq used while
1168  *                                   doing precac.
1169  * @wlan_dfs_false_rssi_thres:       False RSSI Threshold.
1170  * @wlan_dfs_peak_mag:               Peak mag.
1171  * @radar_log:                       Radar log.
1172  * @dfs_event_log_count:             Event log count.
1173  * @dfs_event_log_on:                Event log on.
1174  * @dfs_phyerr_count:                Same as number of PHY radar interrupts.
1175  * @dfs_phyerr_reject_count:         When TLV is supported, # of radar events
1176  *                                   ignored after TLV is parsed.
1177  * @dfs_phyerr_queued_count:         Number of radar events queued for matching
1178  *                                   the filters.
1179  * @dfs_phyerr_freq_min:             Phyerr min freq.
1180  * @dfs_phyerr_freq_max:             Phyerr max freq.
1181  * @dfs_pri_multiplier:              Allow pulse if they are within multiple of
1182  *                                   PRI for the radar type.
1183  * @wlan_dfs_nol_timeout:            NOL timeout.
1184  * @update_nol:                      Update NOL.
1185  * @dfs_nol_free_list:               NOL free list.
1186  * @dfs_nol_elem_free_work:          The work queue to free an NOL element.
1187  * @dfs_cac_timer:                   CAC timer.
1188  * @dfs_cac_valid_timer:             Ignore CAC when this timer is running.
1189  * @dfs_cac_timeout_override:        Overridden cac timeout.
1190  * @dfs_enable:                      DFS Enable.
1191  * @dfs_cac_timer_running:           DFS CAC timer running.
1192  * @dfs_ignore_dfs:                  Ignore DFS.
1193  * @dfs_ignore_cac:                  Ignore CAC.
1194  * @dfs_cac_valid:                   DFS CAC valid.
1195  * @dfs_cac_valid_time:              Time for which CAC will be valid and will
1196  *                                   not be re-done.
1197  * @dfs_precac_timeout_override:     Overridden precac timeout.
1198  * @dfs_disable_radar_marking:       To mark or unmark NOL chan as radar hit.
1199  * @dfs_precac_list:                 PreCAC list (contains individual trees).
1200  * @dfs_precac_chwidth:              PreCAC channel width enum.
1201  * @dfs_curchan:                     DFS current channel.
1202  * @dfs_prevchan:                    DFS previous channel.
1203  * @dfs_cac_started_chan:            CAC started channel.
1204  * @dfs_pdev_obj:                    DFS pdev object.
1205  * @dfs_soc_obj:                     DFS soc object.
1206  * @dfs_psoc_idx:                    DFS psoc index
1207  * @adfs_completion_status:          Agile DFS completion parameters object.
1208  * @dfs_agile_precac_freq_mhz:       Freq in MHZ configured on Agile DFS engine.
1209  * @dfs_is_offload_enabled:          Set if DFS offload enabled.
1210  * @dfs_is_bangradar_320_supported:  Set if DFS 320MHZ enabled.
1211  * @dfs_is_radar_found_chan_freq_eq_center_freq:
1212  *                                   Set if chan_freq parameter of the radar
1213  *                                   found wmi event indicates channel center.
1214  * @dfs_use_nol:                     Use the NOL when radar found(default: TRUE)
1215  * @dfs_nol_lock:                    Lock to protect nol list.
1216  * @tx_leakage_threshold:            Tx leakage threshold for dfs.
1217  * @dfs_use_nol_subchannel_marking:  Use subchannel marking logic to add only
1218  *                                   radar affected subchannel instead of all
1219  *                                   bonding channels.
1220  * @dfs_spoof_test_done:             Indicates if the sppof test is done.
1221  * @dfs_is_stadfs_enabled:           Is STADFS enabled.
1222  * @dfs_seg_id:                      Segment ID of the radar hit channel.
1223  * @dfs_is_chirp:                    Radar Chirp in pulse present or not.
1224  * @dfs_bw_reduced:                  DFS bandwidth reduced channel bit.
1225  * @dfs_freq_offset:                 Frequency offset where radar was found.
1226  * @dfs_cac_aborted:                 DFS cac is aborted.
1227  * @dfs_nol_ie_bandwidth:            Minimum Bandwidth of subchannels that
1228  *                                   are added to NOL.
1229  * @dfs_nol_ie_startfreq:            The centre frequency of the starting
1230  *                                   subchannel in the current channel list
1231  *                                   to be sent in NOL IE with RCSA.
1232  * @dfs_nol_ie_bitmap:               The bitmap of radar affected subchannels
1233  *                                   in the current channel list
1234  *                                   to be sent in NOL IE with RCSA.
1235  * @dfs_is_rcsa_ie_sent:             To send or to not send RCSA IE.
1236  * @dfs_is_nol_ie_sent:              To send or to not send NOL IE.
1237  * @dfs_bw_expand_target_freq:       User configured Channel frequency for
1238  *                                   bandwidth expansion feature.
1239  * @dfs_bw_expand_des_mode:          User configured Channel Phymode for
1240  *                                   bandwidth expansion feature.
1241  * @dfs_use_bw_expand:               User configured value for enabling or
1242  *                                   disabling BW Expansion feature.
1243  * @dfs_use_puncture:                User configured value for enabling or
1244  *                                   disabling DFS puncturing feature.
1245  * @dfs_agile_precac_ucfg:           User configuration for agile preCAC.
1246  * @dfs_agile_rcac_ucfg:             User configuration for Rolling CAC.
1247  * @dfs_fw_adfs_support_320:         Target Agile DFS support for 320 BW.
1248  * @dfs_fw_adfs_support_non_160:     Target Agile DFS support for non-160 BWs.
1249  * @dfs_fw_adfs_support_160:         Target Agile DFS support for 160 BW.
1250  * @dfs_defer_params:                DFS deferred event parameters (allocated
1251  *                                   only for the duration of defer alone).
1252  * @dfs_agile_detector_id:           Agile detector ID for the DFS object.
1253  * @dfs_agile_rcac_freq_ucfg:        User programmed Rolling CAC frequency in
1254  *                                   MHZ.
1255  * @dfs_rcac_param:                  Primary frequency and Channel params of
1256  *                                   the selected RCAC channel.
1257  * @dfs_chan_postnol_freq:           Frequency the AP switches to, post NOL.
1258  * @dfs_chan_postnol_mode:           Phymode the AP switches to, post NOL.
1259  * @dfs_chan_postnol_cfreq2:         Secondary center frequency the AP
1260  *                                   switches to, post NOL.
1261  * @dfs_channel_state_array:         Stores the channel states like CAC STARTED,
1262  *                                   CAC REQUIRED, CAC COMPLETED, NOL,
1263  *                                   PRECAC STARTED, PRECAC COMPLETED etc. of
1264  *                                   all the DFS channels.
1265  * @dfs_cacelems:                    Stores the CAC related parameters of a
1266  *                                   channel such as: CAC started time, CAC
1267  *                                   completed time.
1268  * @dfs_punc_lst:                    List of DFS puncture objects.
1269  */
1270 struct wlan_dfs {
1271 	uint32_t       dfs_debug_mask;
1272 #ifdef WLAN_DFS_PARTIAL_OFFLOAD
1273 	int16_t        dfs_curchan_radindex;
1274 	int16_t        dfs_extchan_radindex;
1275 	struct dfs_ar_state   dfs_ar_state;
1276 	struct dfs_state      dfs_radar[DFS_NUM_RADAR_STATES];
1277 	struct dfs_filtertype *dfs_radarf[DFS_MAX_RADAR_TYPES];
1278 	struct dfs_info       dfs_rinfo;
1279 	struct dfs_bin5radars *dfs_b5radars;
1280 	int8_t                **dfs_ftindextable;
1281 	struct wlan_dfs_phyerr_param dfs_defaultparams;
1282 	struct dfs_event      *events;
1283 	struct wlan_dfs_caps dfs_caps;
1284 	qdf_timer_t    wlan_dfs_task_timer;
1285 	int            dur_multiplier;
1286 	uint16_t       wlan_dfs_isdfsregdomain;
1287 	int            dfs_phyerr_w53_counter;
1288 	uint32_t       dfs_seq_num;
1289 	int32_t        dfs_min_sidx;
1290 	int32_t        dfs_max_sidx;
1291 	qdf_spinlock_t dfs_data_struct_lock;
1292 	uint16_t       dfs_lowest_pri_limit;
1293 
1294 	STAILQ_HEAD(, dfs_event) dfs_eventq;
1295 	STAILQ_HEAD(, dfs_event) dfs_radarq;
1296 	STAILQ_HEAD(, dfs_event) dfs_arq;
1297 
1298 #ifdef HOST_DFS_SPOOF_TEST
1299 	qdf_timer_t    dfs_host_wait_timer;
1300 	uint32_t       dfs_average_pri;
1301 	uint32_t       dfs_average_duration;
1302 	uint32_t       dfs_average_sidx;
1303 	uint8_t        dfs_is_host_wait_running:1,
1304 				   dfs_average_params_sent:1,
1305 				   dfs_no_res_from_fw:1,
1306 				   dfs_spoof_check_failed:1;
1307 	struct dfs_channel dfs_radar_found_chan;
1308 	int            dfs_status_timeout_override;
1309 #endif
1310 #ifdef WLAN_DFS_SYNTHETIC_RADAR
1311 	bool           dfs_allow_hw_pulses;
1312 #endif
1313 #endif /* WLAN_DFS_PARTIAL_OFFLOAD */
1314 	uint32_t       dfsdomain;
1315 	uint32_t       dfs_proc_phyerr;
1316 
1317 	qdf_spinlock_t dfs_eventqlock;
1318 
1319 	qdf_spinlock_t dfs_radarqlock;
1320 
1321 	qdf_spinlock_t dfs_arqlock;
1322 	struct dfs_nolelem    *dfs_nol;
1323 	int                   dfs_nol_count;
1324 	struct dfs_stats      wlan_dfs_stats;
1325 	struct dfs_pulseline  *pulses;
1326 	uint32_t       wlan_radar_tasksched:1,
1327 		       wlan_dfswait:1,
1328 		       wlan_dfstest:1;
1329 	uint8_t        wlan_dfstest_ieeechan;
1330 	uint32_t       wlan_dfs_cac_time;
1331 	uint32_t       wlan_dfstesttime;
1332 	qdf_timer_t    wlan_dfstesttimer;
1333 	enum dfs_bangradar_types dfs_bangradar_type;
1334 	bool           is_radar_found_on_secondary_seg;
1335 	bool           is_radar_during_precac;
1336 	qdf_spinlock_t dfs_precac_lock;
1337 #ifdef CONFIG_CHAN_FREQ_API
1338 	uint16_t        dfs_precac_secondary_freq_mhz;
1339 	uint16_t        dfs_precac_primary_freq_mhz;
1340 #endif
1341 	uint8_t        dfs_defer_precac_channel_change;
1342 #ifdef WLAN_DFS_PRECAC_AUTO_CHAN_SUPPORT
1343 	enum wlan_phymode dfs_autoswitch_des_mode;
1344 #endif
1345 #ifdef WLAN_DFS_PRECAC_AUTO_CHAN_SUPPORT
1346 #ifdef CONFIG_CHAN_FREQ_API
1347 	struct dfs_channel *dfs_autoswitch_chan;
1348 	uint16_t       dfs_precac_inter_chan_freq;
1349 #endif
1350 #endif
1351 	int            wlan_dfs_false_rssi_thres;
1352 	int            wlan_dfs_peak_mag;
1353 	struct dfs_event_log radar_log[DFS_EVENT_LOG_SIZE];
1354 	int            dfs_event_log_count;
1355 	int            dfs_event_log_on;
1356 	int            dfs_phyerr_count;
1357 	int            dfs_phyerr_reject_count;
1358 	int            dfs_phyerr_queued_count;
1359 	int            dfs_phyerr_freq_min;
1360 	int            dfs_phyerr_freq_max;
1361 	int            dfs_pri_multiplier;
1362 	int            wlan_dfs_nol_timeout;
1363 	bool           update_nol;
1364 
1365 	TAILQ_HEAD(, dfs_nolelem) dfs_nol_free_list;
1366 	qdf_work_t     dfs_nol_elem_free_work;
1367 
1368 	qdf_hrtimer_data_t    dfs_cac_timer;
1369 	qdf_timer_t    dfs_cac_valid_timer;
1370 	int            dfs_cac_timeout_override;
1371 	uint8_t        dfs_enable:1,
1372 				   dfs_cac_timer_running:1,
1373 				   dfs_ignore_dfs:1,
1374 				   dfs_ignore_cac:1,
1375 				   dfs_cac_valid:1;
1376 	uint32_t       dfs_cac_valid_time;
1377 	int            dfs_precac_timeout_override;
1378 #if defined(WLAN_DFS_FULL_OFFLOAD) && defined(QCA_DFS_NOL_OFFLOAD)
1379 	uint8_t        dfs_disable_radar_marking;
1380 #endif
1381 	TAILQ_HEAD(, dfs_precac_entry) dfs_precac_list;
1382 	enum phy_ch_width dfs_precac_chwidth;
1383 
1384 	struct dfs_channel *dfs_curchan;
1385 	struct dfs_channel *dfs_prevchan;
1386 	struct dfs_channel dfs_cac_started_chan;
1387 	struct wlan_objmgr_pdev *dfs_pdev_obj;
1388 	struct dfs_soc_priv_obj *dfs_soc_obj;
1389 #if defined(QCA_SUPPORT_AGILE_DFS) || defined(ATH_SUPPORT_ZERO_CAC_DFS)
1390 	uint8_t dfs_psoc_idx;
1391 	struct adfs_completion_params adfs_completion_status;
1392 #endif
1393 #ifdef CONFIG_CHAN_FREQ_API
1394 	uint16_t       dfs_agile_precac_freq_mhz;
1395 #endif
1396 	bool           dfs_is_offload_enabled;
1397 	bool           dfs_is_bangradar_320_supported;
1398 	bool           dfs_is_radar_found_chan_freq_eq_center_freq;
1399 	int            dfs_use_nol;
1400 	qdf_spinlock_t dfs_nol_lock;
1401 	uint16_t tx_leakage_threshold;
1402 	bool dfs_use_nol_subchannel_marking;
1403 	uint8_t        dfs_spoof_test_done:1;
1404 	bool           dfs_is_stadfs_enabled;
1405 	uint8_t        dfs_seg_id;
1406 	uint8_t        dfs_is_chirp;
1407 	bool           dfs_bw_reduced;
1408 	int32_t        dfs_freq_offset;
1409 	bool           dfs_cac_aborted;
1410 #if defined(QCA_DFS_RCSA_SUPPORT)
1411 	uint8_t        dfs_nol_ie_bandwidth;
1412 	uint16_t       dfs_nol_ie_startfreq;
1413 	uint8_t        dfs_nol_ie_bitmap;
1414 	bool           dfs_is_rcsa_ie_sent;
1415 	bool           dfs_is_nol_ie_sent;
1416 #endif
1417 #if defined(QCA_DFS_BW_EXPAND)
1418 	qdf_freq_t      dfs_bw_expand_target_freq;
1419 	enum wlan_phymode dfs_bw_expand_des_mode;
1420 	bool           dfs_use_bw_expand;
1421 #endif
1422 	bool           dfs_use_puncture;
1423 	uint8_t        dfs_agile_precac_ucfg:1,
1424 #if defined(QCA_SUPPORT_ADFS_RCAC)
1425 		       dfs_agile_rcac_ucfg:1,
1426 #endif
1427 #ifdef WLAN_FEATURE_11BE
1428 		       dfs_fw_adfs_support_320:1,
1429 #endif
1430 		       dfs_fw_adfs_support_non_160:1,
1431 		       dfs_fw_adfs_support_160:1;
1432 	struct dfs_mode_switch_defer_params dfs_defer_params;
1433 	uint8_t        dfs_agile_detector_id;
1434 #if defined(QCA_SUPPORT_ADFS_RCAC)
1435 	uint16_t       dfs_agile_rcac_freq_ucfg;
1436 	struct dfs_rcac_params dfs_rcac_param;
1437 #endif
1438 #if defined(QCA_SUPPORT_DFS_CHAN_POSTNOL)
1439 	qdf_freq_t     dfs_chan_postnol_freq;
1440 	enum phy_ch_width dfs_chan_postnol_mode;
1441 	qdf_freq_t     dfs_chan_postnol_cfreq2;
1442 #endif
1443 #if defined(WLAN_DISP_CHAN_INFO)
1444 	enum channel_dfs_state dfs_channel_state_array[NUM_DFS_CHANS];
1445 	struct dfs_cacelem dfs_cacelems[NUM_DFS_CHANS];
1446 #endif /* WLAN_DISP_CHAN_INFO */
1447 #if defined(QCA_DFS_BW_PUNCTURE) && !defined(CONFIG_REG_CLIENT)
1448 	struct dfs_punc_unpunc dfs_punc_lst;
1449 #endif /* QCA_DFS_BW_PUNCTURE */
1450 #ifdef QCA_SUPPORT_AGILE_DFS
1451 #endif
1452 };
1453 
1454 #if defined(QCA_SUPPORT_AGILE_DFS) || defined(ATH_SUPPORT_ZERO_CAC_DFS)
1455 /**
1456  * struct wlan_dfs_priv - dfs private struct with agile capability info
1457  * @dfs: pointer to wlan_dfs object.
1458  * @agile_precac_active: agile precac active information for wlan_dfs_priv obj
1459  */
1460 struct wlan_dfs_priv {
1461 	struct wlan_dfs *dfs;
1462 	bool agile_precac_active;
1463 };
1464 #endif
1465 
1466 /**
1467  * struct dfs_soc_priv_obj - dfs private data
1468  * @psoc: pointer to PSOC object information
1469  * @pdev: pointer to PDEV object information
1470  * @dfs_is_phyerr_filter_offload: For some chip like Rome indicates too many
1471  *                                phyerr packets in a short time, which causes
1472  *                                OS hang. If this field is configured as true,
1473  *                                FW will do the pre-check, filter out some
1474  *                                kinds of invalid phyerrors and indicate
1475  *                                radar detection related information to host.
1476  * @dfs_priv: array of dfs private structs with agile capability info
1477  * @num_dfs_privs: array size of dfs private structs for given psoc.
1478  * @cur_agile_dfs_index: index of the current dfs object using the Agile Engine.
1479  *                 It is used to index struct wlan_dfs_priv dfs_priv[] array.
1480  * @dfs_precac_timer: agile precac timer
1481  * @dfs_precac_timer_running: precac timer running flag
1482  * @precac_state_started: true if pre-CAC has started
1483  * @ocac_status: Off channel CAC complete status
1484  * @dfs_psoc_nolinfo: dfs NOL data for all radios.
1485  * @dfs_rcac_timer: Agile RCAC (Rolling CAC) timer.
1486  * @dfs_agile_sm_hdl: The handle for the state machine that drives Agile
1487  *                    Engine.
1488  * @dfs_agile_sm_cur_state: Current state of the Agile State Machine.
1489  * @dfs_agile_sm_lock: Agile state machine lock.
1490  */
1491 struct dfs_soc_priv_obj {
1492 	struct wlan_objmgr_psoc *psoc;
1493 	struct wlan_objmgr_pdev *pdev;
1494 	bool dfs_is_phyerr_filter_offload;
1495 #if defined(QCA_SUPPORT_AGILE_DFS) || defined(ATH_SUPPORT_ZERO_CAC_DFS)
1496 	struct wlan_dfs_priv dfs_priv[WLAN_UMAC_MAX_PDEVS];
1497 	uint8_t num_dfs_privs;
1498 	uint8_t cur_agile_dfs_index;
1499 	qdf_hrtimer_data_t    dfs_precac_timer;
1500 	uint8_t dfs_precac_timer_running;
1501 	bool precac_state_started;
1502 	enum ocac_status_type ocac_status;
1503 #endif
1504 	struct dfsreq_nolinfo *dfs_psoc_nolinfo;
1505 #ifdef QCA_SUPPORT_ADFS_RCAC
1506 	qdf_hrtimer_data_t dfs_rcac_timer;
1507 #endif
1508 #ifdef QCA_SUPPORT_AGILE_DFS
1509 	struct wlan_sm *dfs_agile_sm_hdl;
1510 	enum dfs_agile_sm_state dfs_agile_sm_cur_state;
1511 	qdf_spinlock_t dfs_agile_sm_lock;
1512 #endif
1513 };
1514 
1515 /**
1516  * enum dfs_debug - This should match the table from if_ath.c.
1517  * @WLAN_DEBUG_DFS:             Minimal DFS debug.
1518  * @WLAN_DEBUG_DFS1:            Normal DFS debug.
1519  * @WLAN_DEBUG_DFS2:            Maximal DFS debug.
1520  * @WLAN_DEBUG_DFS3:            Matched filterID display.
1521  * @WLAN_DEBUG_DFS_PHYERR:      Phy error parsing.
1522  * @WLAN_DEBUG_DFS_NOL:         NOL related entries.
1523  * @WLAN_DEBUG_DFS_PHYERR_SUM:  PHY error summary.
1524  * @WLAN_DEBUG_DFS_PHYERR_PKT:  PHY error payload.
1525  * @WLAN_DEBUG_DFS_BIN5:        BIN5 checks.
1526  * @WLAN_DEBUG_DFS_BIN5_FFT:    BIN5 FFT check.
1527  * @WLAN_DEBUG_DFS_BIN5_PULSE:  BIN5 pulse check.
1528  * @WLAN_DEBUG_DFS_FALSE_DET:   False detection debug related prints.
1529  * @WLAN_DEBUG_DFS_FALSE_DET2:  Second level check to confirm poisitive
1530  *                              detection.
1531  * @WLAN_DEBUG_DFS_RANDOM_CHAN: Random channel selection.
1532  * @WLAN_DEBUG_DFS_AGILE:       Agile PreCAC/RCAC
1533  * @WLAN_DEBUG_DFS_PUNCTURING:  DFS puncturing and unpuncturing.
1534  * @WLAN_DEBUG_DFS_MAX:         Max flag
1535  * @WLAN_DEBUG_DFS_ALWAYS:      Always debug
1536  */
1537 enum dfs_debug {
1538 	WLAN_DEBUG_DFS  = 0x00000100,
1539 	WLAN_DEBUG_DFS1 = 0x00000200,
1540 	WLAN_DEBUG_DFS2 = 0x00000400,
1541 	WLAN_DEBUG_DFS3 = 0x00000800,
1542 	WLAN_DEBUG_DFS_PHYERR = 0x00001000,
1543 	WLAN_DEBUG_DFS_NOL    = 0x00002000,
1544 	WLAN_DEBUG_DFS_PHYERR_SUM = 0x00004000,
1545 	WLAN_DEBUG_DFS_PHYERR_PKT = 0x00008000,
1546 	WLAN_DEBUG_DFS_BIN5       = 0x00010000,
1547 	WLAN_DEBUG_DFS_BIN5_FFT   = 0x00020000,
1548 	WLAN_DEBUG_DFS_BIN5_PULSE = 0x00040000,
1549 	WLAN_DEBUG_DFS_FALSE_DET  = 0x00080000,
1550 	WLAN_DEBUG_DFS_FALSE_DET2 = 0x00100000,
1551 	WLAN_DEBUG_DFS_RANDOM_CHAN = 0x00200000,
1552 	WLAN_DEBUG_DFS_AGILE       = 0x00400000,
1553 	WLAN_DEBUG_DFS_PUNCTURING  = 0x00800000,
1554 	WLAN_DEBUG_DFS_MAX        = 0x80000000,
1555 	WLAN_DEBUG_DFS_ALWAYS     = WLAN_DEBUG_DFS_MAX
1556 };
1557 
1558 #if defined(WLAN_DFS_PARTIAL_OFFLOAD) && defined(HOST_DFS_SPOOF_TEST)
1559 /**
1560  * enum host_dfs_spoof_check_status - DFS spoof check status values
1561  * @HOST_DFS_STATUS_CHECK_PASSED: Host indicates RADAR detected and the FW
1562  *                                confirms it to be spoof radar to host.
1563  * @HOST_DFS_STATUS_CHECK_FAILED: Host doesn't indicate RADAR detected or spoof
1564  *                                radar parameters by
1565  *                                WMI_HOST_DFS_RADAR_FOUND_CMDID doesn't match.
1566  * @HOST_DFS_STATUS_CHECK_HW_RADAR: Host indicates RADAR detected and the FW
1567  *                                  confirms it to be real HW radar to host.
1568  */
1569 enum host_dfs_spoof_check_status {
1570 	HOST_DFS_STATUS_CHECK_PASSED = 0,
1571 	HOST_DFS_STATUS_CHECK_FAILED = 1,
1572 	HOST_DFS_STATUS_CHECK_HW_RADAR = 2
1573 };
1574 #endif
1575 
1576 /**
1577  * struct dfs_phy_err - DFS phy error.
1578  * @fulltsf:             64-bit TSF as read from MAC.
1579  * @is_pri:              Detected on primary channel.
1580  * @is_ext:              Detected on extension channel.
1581  * @is_dc:               Detected at DC.
1582  * @is_early:            Early detect.
1583  * @do_check_chirp:      Whether to check hw_chirp/sw_chirp.
1584  * @is_hw_chirp:         Hardware-detected chirp.
1585  * @is_sw_chirp:         Software detected chirp.
1586  * @rs_tstamp:           32 bit TSF from RX descriptor (event).
1587  * @freq:                Centre frequency of event - KHz.
1588  * @freq_lo:             Lower bounds of frequency - KHz.
1589  * @freq_hi:             Upper bounds of frequency - KHz.
1590  * @rssi:                Pulse RSSI.
1591  * @dur:                 Pulse duration, raw (not uS).
1592  * @seg_id:              HT80_80/HT160 use.
1593  * @sidx:                Seg index.
1594  * @freq_offset_khz:     Freq offset in KHz.
1595  * @peak_mag:            Peak mag.
1596  * @total_gain:          Total gain.
1597  * @mb_gain:             Mb gain.
1598  * @relpwr_db:           Relpower in DB.
1599  * @pulse_delta_diff:    Pulse delta diff.
1600  * @pulse_delta_peak:    Pulse delta peak.
1601  * @pulse_psidx_diff:    Pulse psidx diff.
1602  *
1603  * Chirp notes!
1604  *
1605  * Pre-Sowl chips don't do FFT reports, so chirp pulses simply show up
1606  * as long duration pulses.
1607  *
1608  * The bin5 checking code would simply look for a chirp pulse of the correct
1609  * duration (within MIN_BIN5_DUR and MAX_BIN5_DUR) and add it to the "chirp"
1610  * pattern.
1611  *
1612  * For Sowl and later, an FFT was done on longer duration frames.  If those
1613  * frames looked like a chirp, their duration was adjusted to fall within
1614  * the chirp duration limits.  If the pulse failed the chirp test (it had
1615  * no FFT data or the FFT didn't meet the chirping requirements) then the
1616  * pulse duration was adjusted to be greater than MAX_BIN5_DUR, so it
1617  * would always fail chirp detection.
1618  *
1619  * This is pretty horrible.
1620  *
1621  * The eventual goal for chirp handling is thus:
1622  *
1623  * 1)In case someone ever wants to do chirp detection with this code on
1624  *   chips that don't support chirp detection, you can still do it based
1625  *   on pulse duration.  That's your problem to solve.
1626  *
1627  * 2)For chips that do hardware chirp detection or FFT, the "do_check_chirp"
1628  *   bit should be set.
1629  *
1630  * 3)Then, either is_hw_chirp or is_sw_chirp is set, indicating that
1631  *   the hardware or software post-processing of the chirp event found
1632  *   that indeed it was a chirp.
1633  *
1634  * 4)Finally, the bin5 code should just check whether the chirp bits are
1635  *   set and behave appropriately, falling back onto the duration checks
1636  *   if someone wishes to use this on older hardware (or with disabled
1637  *   FFTs, for whatever reason.)
1638  *
1639  * XXX TODO:
1640  *
1641  * 1)add duration in uS and raw duration, so the PHY error parsing
1642  *   code is responsible for doing the duration calculation;
1643  * 2)add ts in raw and corrected, so the PHY error parsing
1644  *   code is responsible for doing the offsetting, not the radar
1645  *   event code.
1646  */
1647 struct dfs_phy_err {
1648 	uint64_t fulltsf;
1649 	uint32_t is_pri:1,
1650 			 is_ext:1,
1651 			 is_dc:1,
1652 			 is_early:1,
1653 			 do_check_chirp:1,
1654 			 is_hw_chirp:1,
1655 			 is_sw_chirp:1;
1656 	uint32_t rs_tstamp;
1657 	uint32_t freq;
1658 	uint32_t freq_lo;
1659 	uint32_t freq_hi;
1660 	uint8_t  rssi;
1661 	uint8_t  dur;
1662 	uint8_t  seg_id;
1663 	int      sidx;
1664 	u_int    freq_offset_khz;
1665 	int      peak_mag;
1666 	int      total_gain;
1667 	int      mb_gain;
1668 	int      relpwr_db;
1669 	uint8_t  pulse_delta_diff;
1670 	int8_t   pulse_delta_peak;
1671 	int16_t  pulse_psidx_diff;
1672 };
1673 
1674 /**
1675  * struct rx_radar_status - Parsed radar status
1676  * @raw_tsf:           Raw tsf
1677  * @tsf_offset:        TSF offset.
1678  * @rssi:              RSSI.
1679  * @pulse_duration:    Pulse duration.
1680  * @is_chirp:          Is chirp.
1681  * @delta_peak:        Delta peak.
1682  * @delta_diff:        Delta diff.
1683  * @sidx:              Starting frequency.
1684  * @freq_offset:       Frequency offset.
1685  * @agc_total_gain:    AGC total gain.
1686  * @agc_mb_gain:       AGC MB gain.
1687  */
1688 struct rx_radar_status {
1689 	uint32_t raw_tsf;
1690 	uint32_t tsf_offset;
1691 	int      rssi;
1692 	int      pulse_duration;
1693 	int      is_chirp:1;
1694 	int      delta_peak;
1695 	int      delta_diff;
1696 	int      sidx;
1697 	int      freq_offset; /* in KHz */
1698 	int      agc_total_gain;
1699 	int      agc_mb_gain;
1700 };
1701 
1702 /**
1703  * struct rx_search_fft_report - FFT report.
1704  * @total_gain_db:     Total gain in Db.
1705  * @base_pwr_db:       Base power in Db.
1706  * @fft_chn_idx:       FFT channel index.
1707  * @peak_sidx:         Peak sidx.
1708  * @relpwr_db:         Real power in Db.
1709  * @avgpwr_db:         Average power in Db.
1710  * @peak_mag:          Peak Mag.
1711  * @num_str_bins_ib:   Num dtr BINs IB
1712  * @seg_id:            Segment ID
1713  */
1714 struct rx_search_fft_report {
1715 	uint32_t total_gain_db;
1716 	uint32_t base_pwr_db;
1717 	int      fft_chn_idx;
1718 	int      peak_sidx;
1719 	int      relpwr_db;
1720 	int      avgpwr_db;
1721 	int      peak_mag;
1722 	int      num_str_bins_ib;
1723 	int      seg_id;
1724 };
1725 
1726 /**
1727  * dfs_process_radarevent() - process the radar event generated for a pulse.
1728  * @dfs: Pointer to wlan_dfs structure.
1729  * @chan: Current channel.
1730  *
1731  * There is currently no way to specify that a radar event has occurred on
1732  * a specific channel, so the current methodology is to mark both the pri
1733  * and ext channels as being unavailable. This should be fixed for 802.11ac
1734  * or we'll quickly run out of valid channels to use.
1735  *
1736  * If Radar found, this marks the channel (and the extension channel, if HT40)
1737  * as having seen a radar event. It marks CHAN_INTERFERENCE and will add it to
1738  * the local NOL implementation. This is only done for 'usenol=1', as the other
1739  * two modes don't do radar notification or CAC/CSA/NOL; it just notes there
1740  * was a radar.
1741  */
1742 void  dfs_process_radarevent(struct wlan_dfs *dfs,
1743 		struct dfs_channel *chan);
1744 
1745 /**
1746  * dfs_nol_addchan() - Add channel to NOL.
1747  * @dfs: Pointer to wlan_dfs structure.
1748  * @freq: frequency to add to NOL.
1749  * @dfs_nol_timeout: NOL timeout.
1750  */
1751 void dfs_nol_addchan(struct wlan_dfs *dfs,
1752 		uint16_t freq,
1753 		uint32_t dfs_nol_timeout);
1754 
1755 /**
1756  * dfs_get_nol() - Get NOL.
1757  * @dfs: Pointer to wlan_dfs structure.
1758  * @dfs_nol: Pointer to dfsreq_nolelem structure to save the channels from NOL.
1759  * @nchan: Number of channels.
1760  */
1761 void dfs_get_nol(struct wlan_dfs *dfs,
1762 		struct dfsreq_nolelem *dfs_nol,
1763 		int *nchan);
1764 
1765 /**
1766  * dfs_set_nol() - Set NOL.
1767  * @dfs: Pointer to wlan_dfs structure.
1768  * @dfs_nol: Pointer to dfsreq_nolelem structure.
1769  * @nchan: Number of channels.
1770  */
1771 void dfs_set_nol(struct wlan_dfs *dfs,
1772 		 struct dfsreq_nolelem *dfs_nol,
1773 		 int nchan);
1774 
1775 /**
1776  * dfs_nol_update() - NOL update
1777  * @dfs: Pointer to wlan_dfs structure.
1778  *
1779  * Notify the driver/umac that it should update the channel radar/NOL flags
1780  * based on the current NOL list.
1781  */
1782 void dfs_nol_update(struct wlan_dfs *dfs);
1783 
1784 /**
1785  * dfs_nol_timer_cleanup() - NOL timer cleanup.
1786  * @dfs: Pointer to wlan_dfs structure.
1787  *
1788  * Cancels the NOL timer and frees the NOL elements.
1789  */
1790 void dfs_nol_timer_cleanup(struct wlan_dfs *dfs);
1791 
1792 /**
1793  * dfs_nol_timer_detach() - Free NOL timer.
1794  * @dfs: Pointer to wlan_dfs structure.
1795  */
1796 void dfs_nol_timer_detach(struct wlan_dfs *dfs);
1797 
1798 /**
1799  * dfs_nol_workqueue_cleanup() - Flushes NOL workqueue.
1800  * @dfs: Pointer to wlan_dfs structure.
1801  *
1802  * Flushes the NOL workqueue.
1803  */
1804 void dfs_nol_workqueue_cleanup(struct wlan_dfs *dfs);
1805 
1806 /**
1807  * dfs_retain_bin5_burst_pattern() - Retain the BIN5 burst pattern.
1808  * @dfs: Pointer to wlan_dfs structure.
1809  * @diff_ts: Timestamp diff.
1810  * @old_dur: Old duration.
1811  */
1812 uint8_t dfs_retain_bin5_burst_pattern(struct wlan_dfs *dfs,
1813 		uint32_t diff_ts,
1814 		uint8_t old_dur);
1815 
1816 /**
1817  * dfs_bin5_check_pulse() - BIN5 check pulse.
1818  * @dfs: Pointer to wlan_dfs structure.
1819  * @re: Pointer to dfs_event structure.
1820  * @br: Pointer to dfs_bin5radars structure.
1821  *
1822  * Reject the pulse if:
1823  * 1) It's outside the RSSI threshold;
1824  * 2) It's outside the pulse duration;
1825  * 3) It's been verified by HW/SW chirp checking
1826  *    and neither of those found a chirp.
1827  */
1828 int dfs_bin5_check_pulse(struct wlan_dfs *dfs,
1829 		struct dfs_event *re,
1830 		struct dfs_bin5radars *br);
1831 
1832 /**
1833  * dfs_bin5_addpulse() - BIN5 add pulse.
1834  * @dfs: Pointer to wlan_dfs structure.
1835  * @br: Pointer to dfs_bin5radars structure.
1836  * @re: Pointer to dfs_event structure.
1837  * @thists: Timestamp.
1838  */
1839 int dfs_bin5_addpulse(struct wlan_dfs *dfs,
1840 		struct dfs_bin5radars *br,
1841 		struct dfs_event *re,
1842 		uint64_t thists);
1843 
1844 /**
1845  * dfs_bin5_check() - BIN5 check.
1846  * @dfs: Pointer to wlan_dfs structure.
1847  *
1848  * If the dfs structure is NULL (which should be illegal if everything is working
1849  * properly, then signify that a bin5 radar was found.
1850  */
1851 int dfs_bin5_check(struct wlan_dfs *dfs);
1852 
1853 /**
1854  * dfs_check_chirping() - Check chirping.
1855  * @dfs: Pointer to wlan_dfs structure.
1856  * @buf: Phyerr buffer
1857  * @datalen: Phyerr buf length
1858  * @is_ctl: detected on primary channel.
1859  * @is_ext: detected on extension channel.
1860  * @slope: Slope
1861  * @is_dc: DC found
1862  *
1863  * This examines the FFT data contained in the PHY error information to figure
1864  * out whether the pulse is moving across frequencies.
1865  */
1866 int dfs_check_chirping(struct wlan_dfs *dfs,
1867 		void *buf,
1868 		uint16_t datalen,
1869 		int is_ctl,
1870 		int is_ext,
1871 		int *slope,
1872 		int *is_dc);
1873 
1874 /**
1875  * dfs_get_random_bin5_dur() - Get random BIN5 duration.
1876  * @dfs: Pointer to wlan_dfs structure.
1877  * @tstamp: Timestamp.
1878  *
1879  * Chirping pulses may get cut off at DC and report lower durations.
1880  * This function will compute a suitable random duration for each pulse.
1881  * Duration must be between 50 and 100 us, but remember that in
1882  * wlan_process_phyerr() which calls this function, we are dealing with the
1883  * HW reported duration (unconverted). dfs_process_radarevent() will
1884  * actually convert the duration into the correct value.
1885  * This function doesn't take into account whether the hardware
1886  * is operating in 5GHz fast clock mode or not.
1887  * And this function doesn't take into account whether the hardware
1888  * is peregrine or not.
1889  */
1890 int dfs_get_random_bin5_dur(struct wlan_dfs *dfs,
1891 		uint64_t tstamp);
1892 
1893 /**
1894  * dfs_print_delayline() - Prints delayline.
1895  * @dfs: Pointer to wlan_dfs structure.
1896  * @dl: Pointer to dfs_delayline structure.
1897  */
1898 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
1899 void dfs_print_delayline(struct wlan_dfs *dfs,
1900 		struct dfs_delayline *dl);
1901 #else
1902 static inline
1903 void dfs_print_delayline(struct wlan_dfs *dfs, struct dfs_delayline *dl)
1904 {
1905 }
1906 #endif
1907 
1908 /**
1909  * dfs_print_nol() - Print NOL elements.
1910  * @dfs: Pointer to wlan_dfs structure.
1911  */
1912 void dfs_print_nol(struct wlan_dfs *dfs);
1913 
1914 /**
1915  * dfs_print_filter() - Prints the filter.
1916  * @dfs: Pointer to wlan_dfs structure.
1917  * @rf: Pointer to dfs_filter structure.
1918  */
1919 void dfs_print_filter(struct wlan_dfs *dfs,
1920 		struct dfs_filter *rf);
1921 
1922 /**
1923  * dfs_getchanstate() - Get chan state.
1924  * @dfs: Pointer to wlan_dfs structure.
1925  * @index: To save the index of dfs_radar[]
1926  * @ext_chan_flag: Extension channel flag;
1927  */
1928 struct dfs_state *dfs_getchanstate(struct wlan_dfs *dfs, uint8_t *index,
1929 				   int ext_chan_flag);
1930 
1931 /**
1932  * dfs_round() - DFS found.
1933  * @val: Convert durations to TSF ticks.
1934  *
1935  * Return: TSF ticks.
1936  */
1937 uint32_t dfs_round(int32_t val);
1938 
1939 /**
1940  * dfs_reset_alldelaylines() - Reset alldelaylines.
1941  * @dfs: Pointer to wlan_dfs structure.
1942  */
1943 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
1944 void dfs_reset_alldelaylines(struct wlan_dfs *dfs);
1945 #else
1946 static inline void dfs_reset_alldelaylines(struct wlan_dfs *dfs)
1947 {
1948 }
1949 #endif
1950 
1951 /**
1952  * dfs_reset_delayline() - Clear only a single delay line.
1953  * @dl: Pointer to dfs_delayline structure.
1954  */
1955 void dfs_reset_delayline(struct dfs_delayline *dl);
1956 
1957 /**
1958  * dfs_reset_filter_delaylines() - Reset filter delaylines.
1959  * @dft: Pointer to dfs_filtertype structure.
1960  */
1961 void dfs_reset_filter_delaylines(struct dfs_filtertype *dft);
1962 
1963 /**
1964  * dfs_reset_radarq() - Reset radar queue.
1965  * @dfs: Pointer to wlan_dfs structure.
1966  */
1967 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
1968 void dfs_reset_radarq(struct wlan_dfs *dfs);
1969 #else
1970 static inline void dfs_reset_radarq(struct wlan_dfs *dfs)
1971 {
1972 }
1973 #endif
1974 
1975 /**
1976  * dfs_add_pulse() - Adds pulse to the queue.
1977  * @dfs: Pointer to wlan_dfs structure.
1978  * @rf: Pointer to dfs_filter structure.
1979  * @re: Pointer to dfs_event structure.
1980  * @deltaT: deltaT value.
1981  * @this_ts: Last time stamp.
1982  */
1983 void dfs_add_pulse(struct wlan_dfs *dfs,
1984 		struct dfs_filter *rf,
1985 		struct dfs_event *re,
1986 		uint32_t deltaT,
1987 		uint64_t this_ts);
1988 
1989 /**
1990  * dfs_bin_check() - BIN check
1991  * @dfs: Pointer to wlan_dfs structure.
1992  * @rf: Pointer to dfs_filter structure.
1993  * @deltaT: deltaT value.
1994  * @width: Width
1995  * @ext_chan_flag: Extension channel flag.
1996  */
1997 int dfs_bin_check(struct wlan_dfs *dfs,
1998 		struct dfs_filter *rf,
1999 		uint32_t deltaT,
2000 		uint32_t width,
2001 		int ext_chan_flag);
2002 
2003 /**
2004  * dfs_bin_pri_check() - BIN PRI check
2005  * @dfs: Pointer to wlan_dfs structure.
2006  * @rf: Pointer to dfs_filter structure.
2007  * @dl: Pointer to dfs_delayline structure.
2008  * @score: Primary score.
2009  * @refpri: Current "filter" time for start of pulse in usecs.
2010  * @refdur: Duration value.
2011  * @ext_chan_flag: Extension channel flag.
2012  * @fundamentalpri: Highest PRI.
2013  */
2014 int dfs_bin_pri_check(struct wlan_dfs *dfs,
2015 		struct dfs_filter *rf,
2016 		struct dfs_delayline *dl,
2017 		uint32_t score,
2018 		uint32_t refpri,
2019 		uint32_t refdur,
2020 		int ext_chan_flag,
2021 		int fundamentalpri);
2022 
2023 /**
2024  * dfs_staggered_check() - Detection implementation for staggered PRIs.
2025  * @dfs: Pointer to wlan_dfs structure.
2026  * @rf: Pointer to dfs_filter structure.
2027  * @deltaT: Delta of the Timestamp.
2028  * @width: Duration of radar pulse.
2029  *
2030  * Return: 1 on success and 0 on failure.
2031  */
2032 int dfs_staggered_check(struct wlan_dfs *dfs,
2033 		struct dfs_filter *rf,
2034 		uint32_t deltaT,
2035 		uint32_t width);
2036 
2037 /**
2038  * dfs_get_pri_margin() - Get Primary margin.
2039  * @dfs: Pointer to wlan_dfs structure.
2040  * @is_extchan_detect: Extension channel detect.
2041  * @is_fixed_pattern: Fixed pattern.
2042  *
2043  * For the extension channel, if legacy traffic is present, we see a lot of
2044  * false alarms, so make the PRI margin narrower depending on the busy % for
2045  * the extension channel.
2046  *
2047  * Return: Returns pri_margin.
2048  */
2049 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
2050 int dfs_get_pri_margin(struct wlan_dfs *dfs,
2051 		int is_extchan_detect,
2052 		int is_fixed_pattern);
2053 #else
2054 static inline
2055 int dfs_get_pri_margin(struct wlan_dfs *dfs,
2056 		       int is_extchan_detect,
2057 		       int is_fixed_pattern)
2058 {
2059 	return 0;
2060 }
2061 #endif
2062 
2063 /**
2064  * dfs_get_filter_threshold() - Get filter threshold.
2065  * @dfs: Pointer to wlan_dfs structure.
2066  * @rf: Pointer to dfs_filter structure.
2067  * @is_extchan_detect: Extension channel detect.
2068  *
2069  * For the extension channel, if legacy traffic is present, we see a lot of
2070  * false alarms, so make the thresholds higher depending on the busy % for the
2071  * extension channel.
2072  *
2073  * Return: Returns threshold.
2074  */
2075 int dfs_get_filter_threshold(struct wlan_dfs *dfs,
2076 		struct dfs_filter *rf,
2077 		int is_extchan_detect);
2078 
2079 #if defined(MOBILE_DFS_SUPPORT)
2080 /**
2081  * dfs_process_ar_event() - Process the ar event.
2082  * @dfs: Pointer to wlan_dfs structure.
2083  * @chan: Current channel structure.
2084  */
2085 static inline void dfs_process_ar_event(struct wlan_dfs *dfs,
2086 					struct dfs_channel *chan)
2087 {
2088 }
2089 
2090 /**
2091  * dfs_reset_ar() - resets the ar state.
2092  * @dfs: pointer to wlan_dfs structure.
2093  */
2094 static inline void dfs_reset_ar(struct wlan_dfs *dfs)
2095 {
2096 }
2097 
2098 /**
2099  * dfs_reset_arq() - resets the ar queue.
2100  * @dfs: pointer to wlan_dfs structure.
2101  */
2102 static inline void dfs_reset_arq(struct wlan_dfs *dfs)
2103 {
2104 }
2105 
2106 #else
2107 void dfs_process_ar_event(struct wlan_dfs *dfs,
2108 			  struct dfs_channel *chan);
2109 
2110 void dfs_reset_ar(struct wlan_dfs *dfs);
2111 void dfs_reset_arq(struct wlan_dfs *dfs);
2112 #endif
2113 
2114 /**
2115  * dfs_is_radar_enabled() - check if radar detection is enabled.
2116  * @dfs: Pointer to wlan_dfs structure.
2117  * @ignore_dfs: if 1 then radar detection is disabled..
2118  */
2119 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
2120 void dfs_is_radar_enabled(struct wlan_dfs *dfs,
2121 			  int *ignore_dfs);
2122 #else
2123 static inline void dfs_is_radar_enabled(struct wlan_dfs *dfs,
2124 					int *ignore_dfs)
2125 {
2126 }
2127 #endif
2128 
2129 /**
2130  * dfs_process_phyerr_bb_tlv() - Parses the PHY error and populates the
2131  *                               dfs_phy_err struct.
2132  * @dfs: Pointer to wlan_dfs structure.
2133  * @buf: Phyerr buffer
2134  * @datalen: Phyerr buf len
2135  * @rssi: RSSI
2136  * @ext_rssi: Extension RSSI.
2137  * @rs_tstamp: Time stamp.
2138  * @fulltsf: TSF64.
2139  * @e: Pointer to dfs_phy_err structure.
2140  *
2141  * Return: Returns 1.
2142  */
2143 int dfs_process_phyerr_bb_tlv(struct wlan_dfs *dfs,
2144 		void *buf,
2145 		uint16_t datalen,
2146 		uint8_t rssi,
2147 		uint8_t ext_rssi,
2148 		uint32_t rs_tstamp,
2149 		uint64_t fulltsf,
2150 		struct dfs_phy_err *e);
2151 
2152 /**
2153  * dfs_reset() - DFS reset
2154  * @dfs: Pointer to wlan_dfs structure.
2155  */
2156 void dfs_reset(struct wlan_dfs *dfs);
2157 
2158 /**
2159  * dfs_radar_enable() - Enables the radar.
2160  * @dfs: Pointer to wlan_dfs structure.
2161  * @no_cac: If no_cac is 0, it cancels the CAC.
2162  * @opmode: Operational mode
2163  */
2164 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
2165 void dfs_radar_enable(struct wlan_dfs *dfs,
2166 		int no_cac, uint32_t opmode);
2167 #else
2168 static inline void dfs_radar_enable(struct wlan_dfs *dfs,
2169 		int no_cac, uint32_t opmode)
2170 {
2171 }
2172 #endif
2173 
2174 /**
2175  * dfs_process_phyerr() - Process phyerr.
2176  * @dfs: Pointer to wlan_dfs structure.
2177  * @buf: Phyerr buffer.
2178  * @datalen: phyerr buffer length.
2179  * @r_rssi: RSSI.
2180  * @r_ext_rssi: Extension channel RSSI.
2181  * @r_rs_tstamp: Timestamp.
2182  * @r_fulltsf: TSF64.
2183  */
2184 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
2185 void dfs_process_phyerr(struct wlan_dfs *dfs,
2186 		void *buf,
2187 		uint16_t datalen,
2188 		uint8_t r_rssi,
2189 		uint8_t r_ext_rssi,
2190 		uint32_t r_rs_tstamp,
2191 		uint64_t r_fulltsf);
2192 #else
2193 static inline void dfs_process_phyerr(struct wlan_dfs *dfs,
2194 		void *buf,
2195 		uint16_t datalen,
2196 		uint8_t r_rssi,
2197 		uint8_t r_ext_rssi,
2198 		uint32_t r_rs_tstamp,
2199 		uint64_t r_fulltsf)
2200 {
2201 }
2202 #endif
2203 
2204 #ifdef QCA_SUPPORT_DFS_CHAN_POSTNOL
2205 /**
2206  * dfs_switch_to_postnol_chan_if_nol_expired() - Find if NOL is expired
2207  * in the postNOL channel configured. If true, trigger channel change.
2208  * @dfs: Pointer to DFS of wlan_dfs structure.
2209  *
2210  * Return: True, if channel change is triggered, else false.
2211  */
2212 bool dfs_switch_to_postnol_chan_if_nol_expired(struct wlan_dfs *dfs);
2213 #else
2214 static inline bool
2215 dfs_switch_to_postnol_chan_if_nol_expired(struct wlan_dfs *dfs)
2216 {
2217 	return false;
2218 }
2219 #endif
2220 
2221 #ifdef MOBILE_DFS_SUPPORT
2222 /**
2223  * dfs_process_phyerr_filter_offload() - Process radar event.
2224  * @dfs: Pointer to wlan_dfs structure.
2225  * @wlan_radar_event: Pointer to radar_event_info structure.
2226  *
2227  * Return: None
2228  */
2229 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
2230 void dfs_process_phyerr_filter_offload(struct wlan_dfs *dfs,
2231 		struct radar_event_info *wlan_radar_event);
2232 #else
2233 static inline void dfs_process_phyerr_filter_offload(
2234 		struct wlan_dfs *dfs,
2235 		struct radar_event_info *wlan_radar_event)
2236 {
2237 }
2238 #endif
2239 #endif
2240 
2241 /**
2242  * dfs_get_radars() - Based on the chipset, calls init radar table functions.
2243  * @dfs: Pointer to wlan_dfs structure.
2244  */
2245 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
2246 void dfs_get_radars(struct wlan_dfs *dfs);
2247 #else
2248 static inline void dfs_get_radars(struct wlan_dfs *dfs)
2249 {
2250 }
2251 #endif
2252 
2253 /**
2254  * dfs_attach() - Wrapper function to allocate memory for wlan_dfs members.
2255  * @dfs: Pointer to wlan_dfs structure.
2256  */
2257 int dfs_attach(struct wlan_dfs *dfs);
2258 
2259 
2260 /**
2261  * dfs_create_object() - Creates DFS object.
2262  * @dfs: Pointer to wlan_dfs structure.
2263  */
2264 int dfs_create_object(struct wlan_dfs **dfs);
2265 
2266 /**
2267  * dfs_destroy_object() - Destroys the DFS object.
2268  * @dfs: Pointer to wlan_dfs structure.
2269  */
2270 void dfs_destroy_object(struct wlan_dfs *dfs);
2271 
2272 /**
2273  * dfs_detach() - Wrapper function to free dfs variables.
2274  * @dfs: Pointer to wlan_dfs structure.
2275  */
2276 void dfs_detach(struct wlan_dfs *dfs);
2277 
2278 #ifdef QCA_SUPPORT_DFS_CAC
2279 /**
2280  * dfs_stacac_stop() - Clear the STA CAC timer.
2281  * @dfs: Pointer to wlan_dfs structure.
2282  */
2283 void dfs_stacac_stop(struct wlan_dfs *dfs);
2284 
2285 /**
2286  * dfs_is_cac_required() - Check if DFS CAC is required for the current channel.
2287  * @dfs: Pointer to wlan_dfs structure.
2288  * @cur_chan: Pointer to current channel of dfs_channel structure.
2289  * @prev_chan: Pointer to previous channel of dfs_channel structure.
2290  * @continue_current_cac: If AP can start CAC then this variable indicates
2291  * whether to continue with the current CAC or restart the CAC. This variable
2292  * is valid only if this function returns true.
2293  * @is_vap_restart: Flag to indicate if vap is restarted/started.
2294  * True: VAP restart. False: VAP start
2295  *
2296  * Return: true if AP requires CAC or can continue current CAC, else false.
2297  */
2298 bool dfs_is_cac_required(struct wlan_dfs *dfs,
2299 			 struct dfs_channel *cur_chan,
2300 			 struct dfs_channel *prev_chan,
2301 			 bool *continue_current_cac,
2302 			 bool is_vap_restart);
2303 
2304 /**
2305  * dfs_update_cac_elements() - Fill the dfs_cacelem data structure based
2306  * on the dfs_ev events posted.
2307  * @dfs: Pointer to wlan_dfs structure.
2308  * @freq_list: Pointer to a list of frequencies in MHz
2309  * @num_chan: Number of frequencies
2310  * @dfs_chan: Pointer to dfs_channel
2311  * @dfs_ev: DFS events
2312  *
2313  * Return: QDF STATUS
2314  */
2315 #if defined(WLAN_DISP_CHAN_INFO)
2316 QDF_STATUS
2317 dfs_update_cac_elements(struct wlan_dfs *dfs, uint16_t *freq_list,
2318 			uint8_t num_chan, struct dfs_channel *dfs_chan,
2319 			enum WLAN_DFS_EVENTS dfs_ev);
2320 #else
2321 static inline QDF_STATUS
2322 dfs_update_cac_elements(struct wlan_dfs *dfs, uint16_t *freq_list,
2323 			uint8_t num_chan, struct dfs_channel *dfs_chan,
2324 			enum WLAN_DFS_EVENTS dfs_ev)
2325 {
2326 	return QDF_STATUS_SUCCESS;
2327 }
2328 #endif
2329 
2330 /**
2331  * dfs_send_dfs_events_for_chan() - Send CAC RESET events
2332  * @dfs: Pointer to wlan_dfs structure.
2333  * @chan: Pointer to dfs_channel structure.
2334  * @event: WLAN_DFS_EVENTS values
2335  */
2336 void dfs_send_dfs_events_for_chan(struct wlan_dfs *dfs,
2337 				  struct dfs_channel *chan,
2338 				  enum WLAN_DFS_EVENTS event);
2339 
2340 /**
2341  * dfs_cac_stop() - Clear the AP CAC timer.
2342  * @dfs: Pointer to wlan_dfs structure.
2343  */
2344 void dfs_cac_stop(struct wlan_dfs *dfs);
2345 
2346 /**
2347  * dfs_cancel_cac_timer() - Cancels the CAC timer.
2348  * @dfs: Pointer to wlan_dfs structure.
2349  */
2350 void dfs_cancel_cac_timer(struct wlan_dfs *dfs);
2351 
2352 /**
2353  * dfs_start_cac_timer() - Starts the CAC timer.
2354  * @dfs: Pointer to wlan_dfs structure.
2355  */
2356 void dfs_start_cac_timer(struct wlan_dfs *dfs);
2357 
2358 /**
2359  * dfs_cac_valid_reset_for_freq() - Cancels the dfs_cac_valid_timer timer.
2360  * @dfs: Pointer to wlan_dfs structure.
2361  * @prevchan_freq: Prevchan frequency
2362  * @prevchan_flags: Prevchan flags.
2363  */
2364 #ifdef CONFIG_CHAN_FREQ_API
2365 void dfs_cac_valid_reset_for_freq(struct wlan_dfs *dfs,
2366 				  uint16_t prevchan_freq,
2367 				  uint32_t prevchan_flags);
2368 #endif
2369 
2370 /**
2371  * dfs_get_override_cac_timeout() -  Get override CAC timeout value.
2372  * @dfs: Pointer to DFS object.
2373  * @cac_timeout: Pointer to save the CAC timeout value.
2374  */
2375 int dfs_get_override_cac_timeout(struct wlan_dfs *dfs,
2376 				 int *cac_timeout);
2377 
2378 /**
2379  * dfs_override_cac_timeout() -  Override the default CAC timeout.
2380  * @dfs: Pointer to DFS object.
2381  * @cac_timeout: CAC timeout value.
2382  */
2383 int dfs_override_cac_timeout(struct wlan_dfs *dfs,
2384 			     int cac_timeout);
2385 
2386 /**
2387  * dfs_is_ap_cac_timer_running() - Returns the dfs cac timer.
2388  * @dfs: Pointer to wlan_dfs structure.
2389  */
2390 int dfs_is_ap_cac_timer_running(struct wlan_dfs *dfs);
2391 
2392 /**
2393  * dfs_cac_timer_attach() - Initialize cac timers.
2394  * @dfs: Pointer to wlan_dfs structure.
2395  */
2396 void dfs_cac_timer_attach(struct wlan_dfs *dfs);
2397 
2398 /**
2399  * dfs_cac_timer_reset() - Cancel dfs cac timers.
2400  * @dfs: Pointer to wlan_dfs structure.
2401  */
2402 void dfs_cac_timer_reset(struct wlan_dfs *dfs);
2403 
2404 /**
2405  * dfs_cac_timer_detach() - Free dfs cac timers.
2406  * @dfs: Pointer to wlan_dfs structure.
2407  */
2408 void dfs_cac_timer_detach(struct wlan_dfs *dfs);
2409 
2410 /**
2411  * dfs_puncture_cac_timer_detach() - Free puncture cac timers.
2412  * @dfs: Pointer to wlan_dfs structure.
2413  */
2414 #if defined(QCA_DFS_BW_PUNCTURE) && !defined(CONFIG_REG_CLIENT)
2415 void dfs_puncture_cac_timer_detach(struct wlan_dfs *dfs);
2416 #else
2417 static inline
2418 void dfs_puncture_cac_timer_detach(struct wlan_dfs *dfs)
2419 {
2420 }
2421 #endif
2422 
2423 /**
2424  * dfs_deliver_cac_state_events() - Deliver the DFS CAC events namely
2425  * WLAN_EV_CAC_STARTED on cac started channel(current channel) and
2426  * WLAN_EV_CAC_RESET on previous dfs channel.
2427  *
2428  * @dfs: Pointer to wlan_dfs structure.
2429  */
2430 #if defined(WLAN_DISP_CHAN_INFO)
2431 void dfs_deliver_cac_state_events(struct wlan_dfs *dfs);
2432 #else
2433 static inline
2434 void dfs_deliver_cac_state_events(struct wlan_dfs *dfs)
2435 {
2436 }
2437 #endif
2438 #else
2439 static inline
2440 void dfs_stacac_stop(struct wlan_dfs *dfs)
2441 {
2442 }
2443 
2444 static inline QDF_STATUS
2445 dfs_update_cac_elements(struct wlan_dfs *dfs, uint16_t *freq_list,
2446 			uint8_t num_chan, struct dfs_channel *dfs_chan,
2447 			enum WLAN_DFS_EVENTS dfs_ev)
2448 {
2449 	return QDF_STATUS_SUCCESS;
2450 }
2451 
2452 static inline
2453 bool dfs_is_cac_required(struct wlan_dfs *dfs,
2454 			 struct dfs_channel *cur_chan,
2455 			 struct dfs_channel *prev_chan,
2456 			 bool *continue_current_cac,
2457 			 bool is_vap_restart)
2458 {
2459 	return false;
2460 }
2461 
2462 static inline
2463 void dfs_cac_stop(struct wlan_dfs *dfs)
2464 {
2465 }
2466 
2467 static inline
2468 void dfs_send_dfs_events_for_chan(struct wlan_dfs *dfs,
2469 				  struct dfs_channel *chan,
2470 				  enum WLAN_DFS_EVENTS event)
2471 {
2472 }
2473 
2474 static inline
2475 void dfs_cancel_cac_timer(struct wlan_dfs *dfs)
2476 {
2477 }
2478 
2479 static inline
2480 void dfs_start_cac_timer(struct wlan_dfs *dfs)
2481 {
2482 }
2483 
2484 #ifdef CONFIG_CHAN_FREQ_API
2485 static inline
2486 void dfs_cac_valid_reset_for_freq(struct wlan_dfs *dfs,
2487 				  uint16_t prevchan_freq,
2488 				  uint32_t prevchan_flags)
2489 {
2490 }
2491 #endif
2492 
2493 static inline
2494 int dfs_get_override_cac_timeout(struct wlan_dfs *dfs,
2495 				 int *cac_timeout)
2496 {
2497 	return 0;
2498 }
2499 
2500 static inline
2501 int dfs_override_cac_timeout(struct wlan_dfs *dfs,
2502 			     int cac_timeout)
2503 {
2504 	return 0;
2505 }
2506 
2507 static inline
2508 int dfs_is_ap_cac_timer_running(struct wlan_dfs *dfs)
2509 {
2510 	return 0;
2511 }
2512 
2513 static inline
2514 void dfs_cac_timer_attach(struct wlan_dfs *dfs)
2515 {
2516 }
2517 
2518 static inline
2519 void dfs_cac_timer_reset(struct wlan_dfs *dfs)
2520 {
2521 }
2522 
2523 static inline
2524 void dfs_cac_timer_detach(struct wlan_dfs *dfs)
2525 {
2526 }
2527 
2528 static inline
2529 void dfs_deliver_cac_state_events(struct wlan_dfs *dfs)
2530 {
2531 }
2532 
2533 static inline
2534 void dfs_puncture_cac_timer_detach(struct wlan_dfs *dfs)
2535 {
2536 }
2537 
2538 #endif
2539 /**
2540  * dfs_set_update_nol_flag() - Sets update_nol flag.
2541  * @dfs: Pointer to wlan_dfs structure.
2542  * @val: update_nol flag.
2543  */
2544 void dfs_set_update_nol_flag(struct wlan_dfs *dfs,
2545 		bool val);
2546 
2547 /**
2548  * dfs_get_update_nol_flag() - Returns update_nol flag.
2549  * @dfs: Pointer to wlan_dfs structure.
2550  */
2551 bool dfs_get_update_nol_flag(struct wlan_dfs *dfs);
2552 
2553 /**
2554  * dfs_get_use_nol() - Get usenol.
2555  * @dfs: Pointer to wlan_dfs structure.
2556  */
2557 int dfs_get_use_nol(struct wlan_dfs *dfs);
2558 
2559 /**
2560  * dfs_get_nol_timeout() - Get NOL timeout.
2561  * @dfs: Pointer to wlan_dfs structure.
2562  */
2563 int dfs_get_nol_timeout(struct wlan_dfs *dfs);
2564 
2565 /**
2566  * dfs_control()- Used to process ioctls related to DFS.
2567  * @dfs: Pointer to wlan_dfs structure.
2568  * @id: Command type.
2569  * @indata: Input buffer.
2570  * @insize: size of the input buffer.
2571  * @outdata: A buffer for the results.
2572  * @outsize: Size of the output buffer.
2573  */
2574 int dfs_control(struct wlan_dfs *dfs,
2575 		u_int id,
2576 		void *indata,
2577 		uint32_t insize,
2578 		void *outdata,
2579 		uint32_t *outsize);
2580 
2581 /**
2582  * dfs_getnol() - Wrapper function for dfs_get_nol()
2583  * @dfs: Pointer to wlan_dfs structure.
2584  * @dfs_nolinfo: Pointer to dfsreq_nolinfo structure.
2585  */
2586 void dfs_getnol(struct wlan_dfs *dfs,
2587 		void *dfs_nolinfo);
2588 
2589 /**
2590  * dfs_clear_nolhistory() - unmarks WLAN_CHAN_CLR_HISTORY_RADAR flag for
2591  *                          all the channels in dfs_ch_channels.
2592  * @dfs: Pointer to wlan_dfs structure.
2593  */
2594 #if !defined(MOBILE_DFS_SUPPORT)
2595 void dfs_clear_nolhistory(struct wlan_dfs *dfs);
2596 #else
2597 static inline void
2598 dfs_clear_nolhistory(struct wlan_dfs *dfs)
2599 {
2600 }
2601 #endif
2602 
2603 /**
2604  * ol_if_dfs_configure() - Initialize the RADAR table for offload chipsets.
2605  * @dfs: Pointer to wlan_dfs structure.
2606  *
2607  * This is called during a channel change or regulatory domain
2608  * reset; in order to fetch the new configuration information and
2609  * program the DFS pattern matching module.
2610  *
2611  * Eventually this should be split into "fetch config" (which can
2612  * happen at regdomain selection time) and "configure DFS" (which
2613  * can happen at channel config time) so as to minimise overheads
2614  * when doing channel changes.  However, this'll do for now.
2615  */
2616 void ol_if_dfs_configure(struct wlan_dfs *dfs);
2617 
2618 /**
2619  * dfs_init_radar_filters() - Init Radar filters.
2620  * @dfs: Pointer to wlan_dfs structure.
2621  * @radar_info: Pointer to wlan_dfs_radar_tab_info structure.
2622  */
2623 int dfs_init_radar_filters(struct wlan_dfs *dfs,
2624 		struct wlan_dfs_radar_tab_info *radar_info);
2625 
2626 /**
2627  * dfs_print_filters() - Print the filters.
2628  * @dfs: Pointer to wlan_dfs structure.
2629  */
2630 void dfs_print_filters(struct wlan_dfs *dfs);
2631 
2632 /**
2633  * dfs_clear_stats() - Clear stats.
2634  * @dfs: Pointer to wlan_dfs structure.
2635  */
2636 void dfs_clear_stats(struct wlan_dfs *dfs);
2637 
2638 /**
2639  * dfs_radar_disable() - Disables the radar.
2640  * @dfs: Pointer to wlan_dfs structure.
2641  */
2642 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
2643 int dfs_radar_disable(struct wlan_dfs *dfs);
2644 #else
2645 static inline int dfs_radar_disable(struct wlan_dfs *dfs)
2646 {
2647 	return 0;
2648 }
2649 #endif
2650 
2651 /**
2652  * dfs_get_debug_info() - Get debug info.
2653  * @dfs: Pointer to wlan_dfs structure.
2654  * @data: void pointer to the data to save dfs_proc_phyerr.
2655  */
2656 int dfs_get_debug_info(struct wlan_dfs *dfs,
2657 		void *data);
2658 
2659 
2660 /**
2661  * dfs_nol_timer_init() - Initialize NOL timers.
2662  * @dfs: Pointer to wlan_dfs structure.
2663  */
2664 void dfs_nol_timer_init(struct wlan_dfs *dfs);
2665 
2666 /**
2667  * dfs_nol_attach() - Initialize NOL variables.
2668  * @dfs: Pointer to wlan_dfs structure.
2669  */
2670 void dfs_nol_attach(struct wlan_dfs *dfs);
2671 
2672 /**
2673  * dfs_nol_detach() - Detach NOL variables.
2674  * @dfs: Pointer to wlan_dfs structure.
2675  */
2676 void dfs_nol_detach(struct wlan_dfs *dfs);
2677 
2678 /**
2679  * dfs_print_nolhistory() - Print NOL history.
2680  * @dfs: Pointer to wlan_dfs structure.
2681  */
2682 void dfs_print_nolhistory(struct wlan_dfs *dfs);
2683 
2684 /**
2685  * dfs_find_precac_secondary_vht80_chan() - Get a VHT80 channel with the
2686  *                                          precac primary center frequency.
2687  * @dfs: Pointer to wlan_dfs structure.
2688  * @chan: Pointer to dfs channel structure.
2689  */
2690 void dfs_find_precac_secondary_vht80_chan(struct wlan_dfs *dfs,
2691 		struct dfs_channel *chan);
2692 
2693 #ifdef WLAN_DFS_PRECAC_AUTO_CHAN_SUPPORT
2694 /**
2695  * dfs_precac_csa() - Automatically switch the channel to the DFS channel
2696  *			on which PreCAC was completed without finding a RADAR.
2697  *			Use CSA with TBTT_COUNT to switch the channel.
2698  * @dfs: Pointer to dfs handler.
2699  *
2700  * Return: Void
2701  */
2702 void dfs_precac_csa(struct wlan_dfs *dfs);
2703 #endif
2704 
2705 /**
2706  * dfs_phyerr_param_copy() - Function to copy src buf to dest buf.
2707  * @dst: dest buf.
2708  * @src: src buf.
2709  */
2710 void dfs_phyerr_param_copy(struct wlan_dfs_phyerr_param *dst,
2711 		struct wlan_dfs_phyerr_param *src);
2712 
2713 /**
2714  * dfs_get_thresholds() - Get the threshold value.
2715  * @dfs: Pointer to wlan_dfs structure.
2716  * @param: Pointer to wlan_dfs_phyerr_param structure.
2717  */
2718 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
2719 int dfs_get_thresholds(struct wlan_dfs *dfs,
2720 		struct wlan_dfs_phyerr_param *param);
2721 #else
2722 static inline int dfs_get_thresholds(struct wlan_dfs *dfs,
2723 		struct wlan_dfs_phyerr_param *param)
2724 {
2725 		return 0;
2726 }
2727 #endif
2728 
2729 /**
2730  * dfs_set_thresholds() - Sets the threshold value.
2731  * @dfs: Pointer to wlan_dfs structure.
2732  * @threshtype: DFS ioctl param type.
2733  * @value: Threshold value.
2734  */
2735 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
2736 int dfs_set_thresholds(struct wlan_dfs *dfs,
2737 		const uint32_t threshtype,
2738 		const uint32_t value);
2739 #else
2740 static inline int dfs_set_thresholds(struct wlan_dfs *dfs,
2741 		const uint32_t threshtype,
2742 		const uint32_t value)
2743 {
2744 		return 0;
2745 }
2746 #endif
2747 
2748 /**
2749  * dfs_check_intersect_excl() - Check whether curfreq falls within lower_freq
2750  * and upper_freq, exclusively.
2751  * @low_freq : lower bound frequency value.
2752  * @high_freq: upper bound frequency value.
2753  * @chan_freq: Current frequency value to be checked.
2754  *
2755  * Return: returns true if overlap found, else returns false.
2756  */
2757 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
2758 bool dfs_check_intersect_excl(int low_freq, int high_freq, int chan_freq);
2759 #else
2760 static inline bool dfs_check_intersect_excl(int low_freq, int high_freq,
2761 					    int chan_freq)
2762 {
2763 		return false;
2764 }
2765 #endif
2766 
2767 /**
2768  * dfs_check_etsi_overlap() - Check whether given frequency centre/channel
2769  * width entry overlap with frequency spread in any way.
2770  * @center_freq         : current channel centre frequency.
2771  * @chan_width          : current channel width.
2772  * @en302_502_freq_low  : overlap frequency lower bound.
2773  * @en302_502_freq_high : overlap frequency upper bound.
2774  *
2775  * Return: returns 1 if overlap found, else returns 0.
2776  */
2777 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
2778 int dfs_check_etsi_overlap(int center_freq, int chan_width,
2779 			   int en302_502_freq_low, int en302_502_freq_high);
2780 #else
2781 static inline int dfs_check_etsi_overlap(int center_freq, int chan_width,
2782 					 int en302_502_freq_low,
2783 					 int en302_502_freq_high)
2784 {
2785 		return 0;
2786 }
2787 #endif
2788 
2789 /**
2790  * dfs_is_en302_502_applicable() - Check whether current channel frequecy spread
2791  *					overlaps with EN 302 502 radar type
2792  *					frequency range.
2793  *@dfs: Pointer to wlan_dfs structure.
2794  *
2795  * Return: returns true if overlap found, else returns false.
2796  */
2797 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
2798 bool dfs_is_en302_502_applicable(struct wlan_dfs *dfs);
2799 #else
2800 static inline bool dfs_is_en302_502_applicable(struct wlan_dfs *dfs)
2801 {
2802 		return false;
2803 }
2804 #endif
2805 
2806 #ifdef CONFIG_CHAN_FREQ_API
2807 /**
2808  * dfs_set_current_channel_for_freq() - Set DFS current channel.
2809  * @dfs: Pointer to wlan_dfs structure.
2810  * @dfs_chan_freq: Frequency in Mhz.
2811  * @dfs_chan_flags: Channel flags.
2812  * @dfs_chan_flagext: Extended channel flags.
2813  * @dfs_chan_ieee: IEEE channel number.
2814  * @dfs_chan_vhtop_freq_seg1: Channel Center frequency1.
2815  * @dfs_chan_vhtop_freq_seg2: Channel Center frequency2.
2816  * @dfs_chan_mhz_freq_seg1: Channel center frequency of primary segment in MHZ.
2817  * @dfs_chan_mhz_freq_seg2: Channel center frequency of secondary segment in MHZ
2818  *                          applicable only for 80+80MHZ mode of operation.
2819  * @dfs_chan_op_puncture_bitmap: Static channel puncturing of current channel.
2820  * @is_channel_updated: boolean to represent channel update.
2821  */
2822 void dfs_set_current_channel_for_freq(struct wlan_dfs *dfs,
2823 				      uint16_t dfs_chan_freq,
2824 				      uint64_t dfs_chan_flags,
2825 				      uint16_t dfs_chan_flagext,
2826 				      uint8_t dfs_chan_ieee,
2827 				      uint8_t dfs_chan_vhtop_freq_seg1,
2828 				      uint8_t dfs_chan_vhtop_freq_seg2,
2829 				      uint16_t dfs_chan_mhz_freq_seg1,
2830 				      uint16_t dfs_chan_mhz_freq_seg2,
2831 				      uint16_t dfs_chan_op_puncture_bitmap,
2832 				      bool *is_channel_updated);
2833 #endif
2834 /**
2835  * dfs_get_nol_chfreq_and_chwidth() - Get channel freq and width from NOL list.
2836  * @dfs_nol: Pointer to NOL channel entry.
2837  * @nol_chfreq: Pointer to save channel frequency.
2838  * @nol_chwidth: Pointer to save channel width.
2839  * @index: Index to dfs_nol list.
2840  */
2841 void dfs_get_nol_chfreq_and_chwidth(struct dfsreq_nolelem *dfs_nol,
2842 		uint32_t *nol_chfreq,
2843 		uint32_t *nol_chwidth,
2844 		int index);
2845 
2846 /**
2847  * bin5_rules_check_internal() - This is a extension of dfs_bin5_check().
2848  * @dfs: Pointer to wlan_dfs structure.
2849  * @br: Pointer to dfs_bin5radars structure.
2850  * @bursts: Bursts.
2851  * @numevents: Number of events.
2852  * @prev: prev index.
2853  * @i: Index.
2854  * @this: index to br_elems[]
2855  * @index: index array.
2856  */
2857 void bin5_rules_check_internal(struct wlan_dfs *dfs,
2858 		struct dfs_bin5radars *br,
2859 		uint32_t *bursts,
2860 		uint32_t *numevents,
2861 		uint32_t prev,
2862 		uint32_t i,
2863 		uint32_t this,
2864 		int *index);
2865 
2866 /**
2867  * dfs_main_task_testtimer_init() - Initialize dfs task testtimer.
2868  * @dfs: Pointer to wlan_dfs structure.
2869  */
2870 void dfs_main_task_testtimer_init(struct wlan_dfs *dfs);
2871 
2872 /**
2873  * dfs_stop() - Clear dfs timers.
2874  * @dfs: Pointer to wlan_dfs structure.
2875  */
2876 void dfs_stop(struct wlan_dfs *dfs);
2877 
2878 /**
2879  * dfs_update_cur_chan_flags() - Update DFS channel flag and flagext.
2880  * @dfs: Pointer to wlan_dfs structure.
2881  * @flags: New channel flags
2882  * @flagext: New Extended flags
2883  */
2884 void dfs_update_cur_chan_flags(struct wlan_dfs *dfs,
2885 		uint64_t flags,
2886 		uint16_t flagext);
2887 
2888 /**
2889  * wlan_psoc_get_dfs_txops() - Get dfs_tx_ops pointer
2890  * @psoc: Pointer to psoc structure.
2891  *
2892  * Return: Pointer to dfs_tx_ops.
2893  */
2894 struct wlan_lmac_if_dfs_tx_ops *
2895 wlan_psoc_get_dfs_txops(struct wlan_objmgr_psoc *psoc);
2896 
2897 /**
2898  * dfs_nol_free_list() - Free NOL elements.
2899  * @dfs: Pointer to wlan_dfs structure.
2900  */
2901 void dfs_nol_free_list(struct wlan_dfs *dfs);
2902 
2903 /**
2904  * dfs_second_segment_radar_disable() - Disables the second segment radar.
2905  * @dfs: Pointer to wlan_dfs structure.
2906  *
2907  * This is called when AP detects the radar, to (potentially) disable
2908  * the radar code.
2909  *
2910  * Return: returns 0.
2911  */
2912 int dfs_second_segment_radar_disable(struct wlan_dfs *dfs);
2913 
2914 /**
2915  * dfs_fetch_nol_ie_info() - Fill NOL information to be sent with RCSA.
2916  * @dfs:                    Pointer to wlan_dfs structure.
2917  * @nol_ie_bandwidth:       Minimum subchannel bandwidth.
2918  * @nol_ie_startfreq:       Radar affected channel list's first subchannel's
2919  *                          centre frequency.
2920  * @nol_ie_bitmap:          NOL bitmap denoting affected subchannels.
2921  */
2922 #if defined(QCA_DFS_RCSA_SUPPORT)
2923 void dfs_fetch_nol_ie_info(struct wlan_dfs *dfs, uint8_t *nol_ie_bandwidth,
2924 			   uint16_t *nol_ie_startfreq, uint8_t *nol_ie_bitmap);
2925 #else
2926 static inline
2927 void dfs_fetch_nol_ie_info(struct wlan_dfs *dfs, uint8_t *nol_ie_bandwidth,
2928 			   uint16_t *nol_ie_startfreq, uint8_t *nol_ie_bitmap)
2929 {
2930 	*nol_ie_bandwidth = 0;
2931 	*nol_ie_startfreq = 0;
2932 	*nol_ie_bitmap = 0;
2933 }
2934 #endif
2935 
2936 /**
2937  * dfs_set_rcsa_flags() - Set flags that are required for sending RCSA and
2938  * NOL IE.
2939  * @dfs: Pointer to wlan_dfs structure.
2940  * @is_rcsa_ie_sent: Boolean to check if RCSA IE should be sent or not.
2941  * @is_nol_ie_sent: Boolean to check if NOL IE should be sent or not.
2942  */
2943 #if defined(QCA_DFS_RCSA_SUPPORT)
2944 void dfs_set_rcsa_flags(struct wlan_dfs *dfs, bool is_rcsa_ie_sent,
2945 			bool is_nol_ie_sent);
2946 #else
2947 static inline
2948 void dfs_set_rcsa_flags(struct wlan_dfs *dfs, bool is_rcsa_ie_sent,
2949 			bool is_nol_ie_sent)
2950 {
2951 }
2952 #endif
2953 
2954 /**
2955  * dfs_get_radar_bitmap_from_nolie() - Read the NOL IE bitmap of the RCSA
2956  * frame, puncture the nol infected channels and formulate the radar puncture
2957  * bitmap.
2958  * @dfs: Pointer to wlan_dfs structure.
2959  * @phymode: Phymode of enum wlan_phymode.
2960  * @nol_ie_start_freq: NOL IE start frequency
2961  * @nol_ie_bitmap: NOL bitmap
2962  *
2963  * Return: radar puncture bitmap
2964  */
2965 #if defined(WLAN_FEATURE_11BE) && defined(QCA_DFS_BW_PUNCTURE) && \
2966 	defined(QCA_DFS_RCSA_SUPPORT)
2967 uint16_t
2968 dfs_get_radar_bitmap_from_nolie(struct wlan_dfs *dfs,
2969 				enum wlan_phymode phymode,
2970 				qdf_freq_t nol_ie_start_freq,
2971 				uint8_t nol_ie_bitmap);
2972 #else
2973 static inline uint16_t
2974 dfs_get_radar_bitmap_from_nolie(struct wlan_dfs *dfs, enum wlan_phymode phymode,
2975 				qdf_freq_t nol_ie_start_freq,
2976 				uint8_t nol_ie_bitmap)
2977 {
2978 	return NO_SCHANS_PUNC;
2979 }
2980 #endif
2981 
2982 /**
2983  * dfs_get_rcsa_flags() - Get flags that are required for sending RCSA and
2984  * NOL IE.
2985  * @dfs: Pointer to wlan_dfs structure.
2986  * @is_rcsa_ie_sent: Boolean to check if RCSA IE should be sent or not.
2987  * @is_nol_ie_sent: Boolean to check if NOL IE should be sent or not.
2988  */
2989 #if defined(QCA_DFS_RCSA_SUPPORT)
2990 void dfs_get_rcsa_flags(struct wlan_dfs *dfs, bool *is_rcsa_ie_sent,
2991 			bool *is_nol_ie_sent);
2992 #else
2993 static inline
2994 void dfs_get_rcsa_flags(struct wlan_dfs *dfs, bool *is_rcsa_ie_sent,
2995 			bool *is_nol_ie_sent)
2996 {
2997 	*is_rcsa_ie_sent = false;
2998 	*is_nol_ie_sent = false;
2999 }
3000 #endif
3001 
3002 /**
3003  * dfs_process_nol_ie_bitmap() - Update NOL with external radar information.
3004  * @dfs:               Pointer to wlan_dfs structure.
3005  * @nol_ie_bandwidth:  Minimum subchannel bandwidth.
3006  * @nol_ie_startfreq:  Radar affected channel list's first subchannel's
3007  *                     centre frequency.
3008  * @nol_ie_bitmap:     Bitmap denoting radar affected subchannels.
3009  *
3010  * Return: True if NOL IE should be propagated, else false.
3011  */
3012 #if defined(QCA_DFS_RCSA_SUPPORT)
3013 bool dfs_process_nol_ie_bitmap(struct wlan_dfs *dfs, uint8_t nol_ie_bandwidth,
3014 			       uint16_t nol_ie_startfreq,
3015 			       uint8_t nol_ie_bitmap);
3016 #else
3017 static inline
3018 bool dfs_process_nol_ie_bitmap(struct wlan_dfs *dfs, uint8_t nol_ie_bandwidth,
3019 			       uint16_t nol_ie_startfreq,
3020 			       uint8_t nol_ie_bitmap)
3021 {
3022 	return false;
3023 }
3024 #endif
3025 
3026 /**
3027  * dfs_task_testtimer_reset() - stop dfs test timer.
3028  * @dfs: Pointer to wlan_dfs structure.
3029  */
3030 void dfs_task_testtimer_reset(struct wlan_dfs *dfs);
3031 
3032 /**
3033  * dfs_is_freq_in_nol() - check if given channel in nol list
3034  * @dfs: Pointer to wlan_dfs structure
3035  * @freq: channel frequency
3036  *
3037  * check if given channel in nol list.
3038  *
3039  * Return: true if channel in nol, false else
3040  */
3041 bool dfs_is_freq_in_nol(struct wlan_dfs *dfs, uint32_t freq);
3042 
3043 /**
3044  * dfs_task_testtimer_detach() - Free dfs test timer.
3045  * @dfs: Pointer to wlan_dfs structure.
3046  */
3047 void dfs_task_testtimer_detach(struct wlan_dfs *dfs);
3048 
3049 /**
3050  * dfs_timer_detach() - Free dfs timers.
3051  * @dfs: Pointer to wlan_dfs structure.
3052  */
3053 void dfs_timer_detach(struct wlan_dfs *dfs);
3054 
3055 /**
3056  * dfs_is_disable_radar_marking_set() - Check if radar marking is set on
3057  * NOL chan.
3058  * @dfs: Pointer to wlan_dfs structure.
3059  * @disable_radar_marking: Is radar marking disabled.
3060  */
3061 #if defined(WLAN_DFS_FULL_OFFLOAD) && defined(QCA_DFS_NOL_OFFLOAD)
3062 int dfs_is_disable_radar_marking_set(struct wlan_dfs *dfs,
3063 				     bool *disable_radar_marking);
3064 #else
3065 static inline int dfs_is_disable_radar_marking_set(struct wlan_dfs *dfs,
3066 						   bool *disable_radar_marking)
3067 {
3068 	return QDF_STATUS_SUCCESS;
3069 }
3070 #endif
3071 /**
3072  * dfs_get_disable_radar_marking() - Get the value of disable radar marking.
3073  * @dfs: Pointer to wlan_dfs structure.
3074  */
3075 #if defined(WLAN_DFS_FULL_OFFLOAD) && defined(QCA_DFS_NOL_OFFLOAD)
3076 bool dfs_get_disable_radar_marking(struct wlan_dfs *dfs);
3077 #else
3078 static inline bool dfs_get_disable_radar_marking(struct wlan_dfs *dfs)
3079 {
3080 	return false;
3081 }
3082 #endif
3083 
3084 /**
3085  * dfs_reset_agile_config() - Reset the ADFS config variables.
3086  * @dfs_soc: Pointer to dfs_soc_priv_obj.
3087  */
3088 #ifdef QCA_SUPPORT_AGILE_DFS
3089 void dfs_reset_agile_config(struct dfs_soc_priv_obj *dfs_soc);
3090 #endif
3091 
3092 /**
3093  * dfs_reinit_timers() - Reinit timers in DFS.
3094  * @dfs: Pointer to wlan_dfs.
3095  */
3096 int dfs_reinit_timers(struct wlan_dfs *dfs);
3097 
3098 /**
3099  * dfs_reset_dfs_prevchan() - Reset DFS previous channel structure.
3100  * @dfs: Pointer to wlan_dfs object.
3101  *
3102  * Return: None.
3103  */
3104 void dfs_reset_dfs_prevchan(struct wlan_dfs *dfs);
3105 
3106 /**
3107  * dfs_init_tmp_psoc_nol() - Init temporary psoc NOL structure.
3108  * @dfs: Pointer to wlan_dfs object.
3109  * @num_radios: Num of radios in the PSOC.
3110  *
3111  * Return: void.
3112  */
3113 void dfs_init_tmp_psoc_nol(struct wlan_dfs *dfs, uint8_t num_radios);
3114 
3115 /**
3116  * dfs_deinit_tmp_psoc_nol() - De-init temporary psoc NOL structure.
3117  * @dfs: Pointer to wlan_dfs object.
3118  *
3119  * Return: void.
3120  */
3121 void dfs_deinit_tmp_psoc_nol(struct wlan_dfs *dfs);
3122 
3123 /**
3124  * dfs_save_dfs_nol_in_psoc() - Save NOL data of given pdev.
3125  * @dfs: Pointer to wlan_dfs object.
3126  * @pdev_id: The pdev ID which will have the NOL data.
3127  *
3128  * Based on the frequency of the NOL channel, copy it to the target pdev_id
3129  * structure in psoc.
3130  *
3131  * Return: void.
3132  */
3133 void dfs_save_dfs_nol_in_psoc(struct wlan_dfs *dfs, uint8_t pdev_id);
3134 
3135 /**
3136  * dfs_reinit_nol_from_psoc_copy() - Reinit saved NOL data to corresponding
3137  * DFS object.
3138  * @dfs: Pointer to wlan_dfs object.
3139  * @pdev_id: pdev_id of the given dfs object.
3140  * @low_5ghz_freq: The low 5GHz frequency value of the target pdev id.
3141  * @high_5ghz_freq: The high 5GHz frequency value of the target pdev id.
3142  *
3143  * Return: void.
3144  */
3145 void dfs_reinit_nol_from_psoc_copy(struct wlan_dfs *dfs,
3146 				   uint8_t pdev_id,
3147 				   uint16_t low_5ghz_freq,
3148 				   uint16_t high_5ghz_freq);
3149 
3150 /**
3151  * dfs_is_hw_mode_switch_in_progress() - Check if HW mode switch in progress.
3152  * @dfs: Pointer to wlan_dfs object.
3153  *
3154  * Return: True if mode switch is in progress, else false.
3155  */
3156 #ifdef QCA_HW_MODE_SWITCH
3157 bool dfs_is_hw_mode_switch_in_progress(struct wlan_dfs *dfs);
3158 #else
3159 static inline
3160 bool dfs_is_hw_mode_switch_in_progress(struct wlan_dfs *dfs)
3161 {
3162 	return false;
3163 }
3164 #endif
3165 
3166 /**
3167  * dfs_start_mode_switch_defer_timer() - start mode switch defer timer.
3168  * @dfs: Pointer to wlan_dfs object.
3169  *
3170  * Return: void.
3171  */
3172 void dfs_start_mode_switch_defer_timer(struct wlan_dfs *dfs);
3173 
3174 /**
3175  * dfs_complete_deferred_tasks() - Process mode switch completion event and
3176  * handle deferred tasks.
3177  * @dfs: Pointer to wlan_dfs object.
3178  *
3179  * Return: void.
3180  */
3181 void dfs_complete_deferred_tasks(struct wlan_dfs *dfs);
3182 
3183 /**
3184  * dfs_process_cac_completion() - Process DFS CAC completion event.
3185  * @dfs: Pointer to wlan_dfs object.
3186  *
3187  * Return: void.
3188  */
3189 void dfs_process_cac_completion(struct wlan_dfs *dfs);
3190 
3191 #ifdef WLAN_DFS_TRUE_160MHZ_SUPPORT
3192 /**
3193  * dfs_is_true_160mhz_supported() - Find if true 160MHz is supported.
3194  * @dfs: Pointer to wlan_dfs object.
3195  *
3196  * Return: True if true 160MHz is supported, else false.
3197  */
3198 bool dfs_is_true_160mhz_supported(struct wlan_dfs *dfs);
3199 
3200 /**
3201  * dfs_is_restricted_80p80mhz_supported() - Find if restricted 80p80mhz is
3202  * supported.
3203  * @dfs: Pointer to wlan_dfs object.
3204  *
3205  * Return: True if restricted 160MHz is supported, else false.
3206  */
3207 bool dfs_is_restricted_80p80mhz_supported(struct wlan_dfs *dfs);
3208 #else
3209 static inline bool dfs_is_true_160mhz_supported(struct wlan_dfs *dfs)
3210 {
3211 	return false;
3212 }
3213 
3214 static inline bool dfs_is_restricted_80p80mhz_supported(struct wlan_dfs *dfs)
3215 {
3216 	return false;
3217 }
3218 #endif /* WLAN_DFS_TRUE_160MHZ_SUPPORT */
3219 
3220 /**
3221  * dfs_get_agile_detector_id() - Find the Agile detector ID for given DFS.
3222  * @dfs: Pointer to wlan_dfs object.
3223  *
3224  * Return: Agile detector value (uint8_t).
3225  */
3226 #ifdef QCA_SUPPORT_AGILE_DFS
3227 uint8_t dfs_get_agile_detector_id(struct wlan_dfs *dfs);
3228 #else
3229 static inline uint8_t dfs_get_agile_detector_id(struct wlan_dfs *dfs)
3230 {
3231 	return INVALID_DETECTOR_ID;
3232 }
3233 #endif
3234 
3235 /**
3236  * dfs_is_new_chan_subset_of_old_chan() - Find if new channel is subset of
3237  *                                        old channel.
3238  * @dfs: Pointer to wlan_dfs structure.
3239  * @new_chan: Pointer to new channel of dfs_channel structure.
3240  * @old_chan: Pointer to old channel of dfs_channel structure.
3241  *
3242  * Return: True if new channel is subset of old channel, else false.
3243  */
3244 bool dfs_is_new_chan_subset_of_old_chan(struct wlan_dfs *dfs,
3245 					struct dfs_channel *new_chan,
3246 					struct dfs_channel *old_chan);
3247 
3248 /**
3249  * dfs_find_dfs_sub_channels_for_freq() - Given a dfs channel, find its
3250  *                                        HT20 subset channels.
3251  * @dfs: Pointer to wlan_dfs structure.
3252  * @chan: Pointer to dfs_channel structure.
3253  * @subchan_arr: Pointer to subchannels array.
3254  *
3255  * Return: Number of sub channels.
3256  */
3257 uint8_t dfs_find_dfs_sub_channels_for_freq(struct  wlan_dfs *dfs,
3258 					   struct dfs_channel *chan,
3259 					   uint16_t *subchan_arr);
3260 
3261 /**
3262  * dfs_clear_cac_started_chan() - Clear dfs cac started channel.
3263  * @dfs: Pointer to wlan_dfs structure.
3264  */
3265 void dfs_clear_cac_started_chan(struct wlan_dfs *dfs);
3266 
3267 #ifdef QCA_DFS_BANGRADAR
3268 /**
3269  * dfs_bang_radar() - Handles all type of Bangradar.
3270  * @dfs: Pointer to wlan_dfs structure.
3271  * @indata: reference to input data
3272  * @insize:  input data size
3273  *
3274  */
3275 int dfs_bang_radar(struct wlan_dfs *dfs, void *indata, uint32_t insize);
3276 #else
3277 static inline int
3278 dfs_bang_radar(struct wlan_dfs *dfs, void *indata, uint32_t insize)
3279 {
3280 	return 0;
3281 }
3282 #endif
3283 
3284 #if defined(QCA_SUPPORT_DFS_CHAN_POSTNOL)
3285 void dfs_postnol_attach(struct wlan_dfs *dfs);
3286 #else
3287 static inline void dfs_postnol_attach(struct wlan_dfs *dfs)
3288 {
3289 }
3290 #endif
3291 
3292 #ifdef CONFIG_HOST_FIND_CHAN
3293 /**
3294  * wlan_is_chan_radar() - Checks if a given dfs channel is in NOL or not.
3295  * @dfs: Pointer to wlan_dfs structure.
3296  * @chan: Pointer to the dfs channel structure.
3297  *
3298  * Return: True if the channel has detected radar, else false.
3299  */
3300 bool wlan_is_chan_radar(struct wlan_dfs *dfs, struct dfs_channel *chan);
3301 
3302 /**
3303  * wlan_is_chan_history_radar() - Checks if a given dfs channel is in NOL
3304  * history or not.
3305  * @dfs: Pointer to wlan_dfs structure.
3306  * @chan: Pointer to the dfs channel structure.
3307  *
3308  * Return: True if the channel is marked as radar history, else false.
3309  */
3310 bool wlan_is_chan_history_radar(struct wlan_dfs *dfs, struct dfs_channel *chan);
3311 #else
3312 static inline bool
3313 wlan_is_chan_radar(struct wlan_dfs *dfs, struct dfs_channel *chan)
3314 {
3315 	return false;
3316 }
3317 
3318 static inline bool
3319 wlan_is_chan_history_radar(struct wlan_dfs *dfs, struct dfs_channel *chan)
3320 {
3321 	return false;
3322 }
3323 #endif /* CONFIG_HOST_FIND_CHAN */
3324 
3325 #if defined(QCA_SUPPORT_ADFS_RCAC) && \
3326 	defined(WLAN_DFS_PRECAC_AUTO_CHAN_SUPPORT) && \
3327 	defined(QCA_SUPPORT_AGILE_DFS)
3328 /**
3329  * dfs_restart_rcac_on_nol_expiry() - If the chosen desired channel is
3330  * radar infected during RCAC, trigger RCAC on desired channel after
3331  * NOL expiry.
3332  * @dfs: Pointer to wlan_dfs structure.
3333  *
3334  * Return: True if rcac is started, false otherwise
3335  */
3336 bool dfs_restart_rcac_on_nol_expiry(struct wlan_dfs *dfs);
3337 #else
3338 static inline bool
3339 dfs_restart_rcac_on_nol_expiry(struct wlan_dfs *dfs)
3340 {
3341 	return false;
3342 }
3343 #endif
3344 
3345 /**
3346  * dfs_chan_to_ch_width() - Outputs the channel width in MHz of the given input
3347  *                          dfs_channel.
3348  * @chan: Pointer to the input dfs_channel structure.
3349  *
3350  * Return: Channel width in MHz. (uint16) -EINVAL on invalid channel.
3351  */
3352 uint16_t dfs_chan_to_ch_width(struct dfs_channel *chan);
3353 #endif  /* _DFS_H_ */
3354