xref: /wlan-dirver/qca-wifi-host-cmn/umac/dfs/core/src/dfs.h (revision fa47688f04ef001a6dcafaebdcc3c031f15ee75e)
1 /*
2  * Copyright (c) 2013, 2016-2019 The Linux Foundation.  All rights reserved.
3  * Copyright (c) 2005-2006 Atheros Communications, Inc.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 /**
19  * DOC: This file has main dfs structures.
20  */
21 
22 #ifndef _DFS_H_
23 #define _DFS_H_
24 
25 #include <qdf_types.h>       /* QDF_NBUF_EXEMPT_NO_EXEMPTION, etc. */
26 #include <qdf_net_types.h>   /* QDF_NBUF_EXEMPT_NO_EXEMPTION, etc. */
27 #include <qdf_nbuf.h>        /* qdf_nbuf_t, etc. */
28 #include <qdf_util.h>        /* qdf_assert */
29 #include <qdf_lock.h>        /* qdf_spinlock */
30 #include <qdf_time.h>
31 #include <qdf_timer.h>
32 
33 #include <wlan_dfs_ioctl.h>
34 #include "dfs_structs.h"
35 #include "dfs_channel.h"
36 #include "dfs_ioctl_private.h"
37 #include <i_qdf_types.h>     /* For qdf_packed*/
38 #include <queue.h>           /* For STAILQ_ENTRY */
39 #include <wlan_objmgr_psoc_obj.h>
40 #include <wlan_objmgr_pdev_obj.h>
41 #include <osdep.h>
42 
43 /* File Line and Submodule String */
44 #define FLSM(x, str)   #str " : " FL(x)
45 /* Cast to dfs type */
46 #define DC(x)  ((struct wlan_dfs *)(x))
47 
48 /**
49  * dfs_log: dfs logging using submodule MASKs and
50  * QDF trace level.
51  * The logging is controlled by two bitmasks:
52  * 1) submodule bitmask: sm
53  * 2) trace level masks: level
54  *
55  * @dfs: The dfs object pointer or NULL if dfs is not defined.
56  * @sm: Submodule BITMASK.
57  * @level: QDF trace level.
58  * @args...: Variable argument list.
59  *
60  * The submodule(sm) cannot be empty even if argument dfs is NULL.
61  * Else the macro will create a  compilation  error.
62  * One may provide WLAN_DEBUG_DFS_ALWAYS when  the argument dfs is NULL.
63  * Example:-
64  * dfs_log(NULL, WLAN_DEBUG_DFS_ALWAYS, QDF_TRACE_LEVEL_INFO,"Error pulse");
65  *
66  * Why DC(x) is required?
67  * Since NULL is defined as ((void *)(0)), if the argument "dfs"
68  * in a call to the macro "dfs_log" is NULL
69  * then during compilation (NULL)->dfs_debug_mask will dereference
70  * a (void *) type, which is illegal. Therefore, we need
71  * the cast: (DC(dfs))->dfs_debug_mask.
72  * Example:-
73  * dfs_log(NULL, WLAN_DEBUG_DFS, QDF_TRACE_LEVEL_INFO,"dfs is NULL");
74  */
75 #define dfs_log(dfs, sm, level, args...)  do {        \
76 	if (((dfs) == NULL) ||                            \
77 			((sm) == WLAN_DEBUG_DFS_ALWAYS) ||        \
78 			((sm) & ((DC(dfs))->dfs_debug_mask))) {   \
79 		QDF_TRACE(QDF_MODULE_ID_DFS, level, ## args); \
80 	}                                                 \
81 } while (0)
82 
83 #define dfs_logfl(dfs, level, sm, format, args...) \
84 	dfs_log(dfs, sm, level, FLSM(format, sm), ## args)
85 
86 #define dfs_alert(dfs, sm, format, args...) \
87 	dfs_logfl(dfs, QDF_TRACE_LEVEL_FATAL, sm, format, ## args)
88 
89 #define dfs_err(dfs, sm, format, args...) \
90 	dfs_logfl(dfs, QDF_TRACE_LEVEL_ERROR, sm, format, ## args)
91 
92 #define dfs_warn(dfs, sm, format, args...) \
93 	dfs_logfl(dfs, QDF_TRACE_LEVEL_WARN, sm, format, ## args)
94 
95 #define dfs_info(dfs, sm, format, args...) \
96 	dfs_logfl(dfs, QDF_TRACE_LEVEL_INFO, sm, format, ## args)
97 
98 #define dfs_debug(dfs, sm, format, args...) \
99 	dfs_logfl(dfs, QDF_TRACE_LEVEL_DEBUG, sm, format, ## args)
100 
101 #define DFS_MIN(a, b) ((a) < (b)?(a):(b))
102 #define DFS_MAX(a, b) ((a) > (b)?(a) : (b))
103 #define DFS_DIFF(a, b)(DFS_MAX(a, b) - DFS_MIN(a, b))
104 
105 /**
106  * Maximum number of radar events to be processed in a single iteration.
107  * Allows soft watchdog to run.
108  */
109 #define MAX_EVENTS 100
110 
111 /**
112  * Constants to use for chirping detection.
113  *
114  * All are unconverted as HW reports them.
115  *
116  * XXX Are these constants with or without fast clock 5GHz operation?
117  * XXX Peregrine reports pulses in microseconds, not hardware clocks!
118  */
119 
120 #define MAX_DUR_FOR_LOW_RSSI 4
121 
122 /**
123  * Cascade has issue with reported duration especially when there is a
124  * crossover of chirp from one segment to another. It may report a value
125  * of duration that is well below 50us for a valid FCC type 5 chirping
126  * pulse. For now changing minimum duration as a work around. This will
127  * affect all chips but since we detect chirp with Merlin+, we may be OK
128  * for now. We need a more robust solution for this.
129  */
130 #define MIN_BIN5_DUR_CAS            25 /* 50 * 1.25*/
131 #define MIN_BIN5_DUR_MICROSEC_CAS   20
132 #define MIN_BIN5_DUR                63 /* 50 * 1.25*/
133 #define MIN_BIN5_DUR_MICROSEC       50
134 #define MAYBE_BIN5_DUR              35 /* 28 * 1.25*/
135 #define MAYBE_BIN5_DUR_MICROSEC     28
136 
137 /* Conversion is already done using dfs->dur_multiplier */
138 #define MAX_BIN5_DUR                145   /* use 145 for osprey */
139 #define MAX_BIN5_DUR_MICROSEC       105
140 
141 #define DFS_MARGIN_EQUAL(a, b, margin)	((DFS_DIFF(a, b)) <= margin)
142 #define DFS_MAX_STAGGERED_BURSTS    3
143 
144 /**
145  * All filter thresholds in the radar filter tables are effective at a 50%
146  * channel loading.
147  */
148 #define DFS_CHAN_LOADING_THRESH     50
149 #define DFS_EXT_CHAN_LOADING_THRESH 30
150 #define DFS_DEFAULT_PRI_MARGIN      6
151 #define DFS_DEFAULT_FIXEDPATTERN_PRI_MARGIN	4
152 
153 #define WLAN_DFSQ_LOCK(_dfs)         qdf_spin_lock_bh(&(_dfs)->dfs_radarqlock)
154 #define WLAN_DFSQ_UNLOCK(_dfs)       qdf_spin_unlock_bh(&(_dfs)->dfs_radarqlock)
155 #define WLAN_DFSQ_LOCK_CREATE(_dfs)  qdf_spinlock_create( \
156 		&(_dfs)->dfs_radarqlock)
157 #define WLAN_DFSQ_LOCK_DESTROY(_dfs) qdf_spinlock_destroy( \
158 		&(_dfs)->dfs_radarqlock)
159 
160 #define WLAN_ARQ_LOCK(_dfs)          qdf_spin_lock_bh(&(_dfs)->dfs_arqlock)
161 #define WLAN_ARQ_UNLOCK(_dfs)        qdf_spin_unlock_bh(&(_dfs)->dfs_arqlock)
162 #define WLAN_ARQ_LOCK_CREATE(_dfs)   qdf_spinlock_create(&(_dfs)->dfs_arqlock)
163 #define WLAN_ARQ_LOCK_DESTROY(_dfs)  qdf_spinlock_destroy(&(_dfs)->dfs_arqlock)
164 
165 #define WLAN_DFSEVENTQ_LOCK(_dfs)         qdf_spin_lock_bh(&(_dfs)->dfs_eventqlock)
166 #define WLAN_DFSEVENTQ_UNLOCK(_dfs)       qdf_spin_unlock_bh( \
167 		&(_dfs)->dfs_eventqlock)
168 #define WLAN_DFSEVENTQ_LOCK_CREATE(_dfs)  qdf_spinlock_create( \
169 		&(_dfs)->dfs_eventqlock)
170 #define WLAN_DFSEVENTQ_LOCK_DESTROY(_dfs) qdf_spinlock_destroy( \
171 		&(_dfs)->dfs_eventqlock)
172 
173 #define WLAN_DFSNOL_LOCK(_dfs)         qdf_spin_lock_bh(&(_dfs)->dfs_nol_lock)
174 #define WLAN_DFSNOL_UNLOCK(_dfs)       qdf_spin_unlock_bh(&(_dfs)->dfs_nol_lock)
175 #define WLAN_DFSNOL_LOCK_CREATE(_dfs)  qdf_spinlock_create( \
176 		&(_dfs)->dfs_nol_lock)
177 #define WLAN_DFSNOL_LOCK_DESTROY(_dfs) qdf_spinlock_destroy( \
178 		&(_dfs)->dfs_nol_lock)
179 
180 #define PRECAC_LIST_LOCK(_dfs)         qdf_spin_lock_irqsave( \
181 		&(_dfs)->dfs_precac_lock)
182 #define PRECAC_LIST_UNLOCK(_dfs)       qdf_spin_unlock_irqrestore( \
183 		&(_dfs)->dfs_precac_lock)
184 #define PRECAC_LIST_LOCK_CREATE(_dfs)  qdf_spinlock_create( \
185 		&(_dfs)->dfs_precac_lock)
186 #define PRECAC_LIST_LOCK_DESTROY(_dfs) qdf_spinlock_destroy( \
187 		&(_dfs)->dfs_precac_lock)
188 
189 #define WLAN_DFS_DATA_STRUCT_LOCK(_dfs) \
190 	qdf_spin_lock_bh(&(_dfs)->dfs_data_struct_lock)
191 #define WLAN_DFS_DATA_STRUCT_UNLOCK(_dfs) \
192 	qdf_spin_unlock_bh(&(_dfs)->dfs_data_struct_lock)
193 #define WLAN_DFS_DATA_STRUCT_LOCK_CREATE(_dfs) \
194 	qdf_spinlock_create(&(_dfs)->dfs_data_struct_lock)
195 #define WLAN_DFS_DATA_STRUCT_LOCK_DESTROY(_dfs) \
196 	qdf_spinlock_destroy(&(_dfs)->dfs_data_struct_lock)
197 
198 /* Mask for time stamp from descriptor */
199 #define DFS_TSMASK    0xFFFFFFFF
200 /* Shift for time stamp from descriptor */
201 #define DFS_TSSHIFT   32
202 /* 64 bit TSF wrap value */
203 #define DFS_TSF_WRAP  0xFFFFFFFFFFFFFFFFULL
204 /* TS mask for 64 bit value */
205 #define DFS_64BIT_TSFMASK 0x0000000000007FFFULL
206 
207 #define DFS_AR_RADAR_RSSI_THR          5 /* in dB */
208 #define DFS_AR_RADAR_RESET_INT         1 /* in secs */
209 #define DFS_AR_RADAR_MAX_HISTORY       500
210 #define DFS_AR_REGION_WIDTH            128
211 #define DFS_AR_RSSI_THRESH_STRONG_PKTS 17 /* in dB */
212 #define DFS_AR_RSSI_DOUBLE_THRESHOLD   15 /* in dB */
213 #define DFS_AR_MAX_NUM_ACK_REGIONS     9
214 #define DFS_AR_ACK_DETECT_PAR_THRESH   20
215 #define DFS_AR_PKT_COUNT_THRESH        20
216 
217 #define DFS_MAX_DL_SIZE                64
218 #define DFS_MAX_DL_MASK                0x3F
219 
220 #define DFS_NOL_TIME DFS_NOL_TIMEOUT_US
221 /* 30 minutes in usecs */
222 
223 #define DFS_WAIT_TIME (60*1000000) /* 1 minute in usecs */
224 
225 #define DFS_DISABLE_TIME (3*60*1000000) /* 3 minutes in usecs */
226 
227 #define DFS_MAX_B5_SIZE 128
228 #define DFS_MAX_B5_MASK 0x0000007F /* 128 */
229 
230 /* Max number of overlapping filters */
231 #define DFS_MAX_RADAR_OVERLAP 16
232 
233 /* Max number of dfs events which can be q'd */
234 #define DFS_MAX_EVENTS 1024
235 
236 #define DFS_RADAR_EN       0x80000000 /* Radar detect is capable */
237 #define DFS_AR_EN          0x40000000 /* AR detect is capable */
238 /* Radar detect in second segment is capable */
239 #define DFS_SECOND_SEGMENT_RADAR_EN 0x20000000
240 #define DFS_MAX_RSSI_VALUE 0x7fffffff /* Max rssi value */
241 
242 #define DFS_BIN_MAX_PULSES 60 /* max num of pulses in a burst */
243 #define DFS_BIN5_PRI_LOWER_LIMIT 990 /* us */
244 
245 /**
246  * To cover the single pusle burst case, change from 2010 us to
247  * 2010000 us.
248  */
249 
250 /**
251  * This is reverted back to 2010 as larger value causes false
252  * bin5 detect (EV76432, EV76320)
253  */
254 #define DFS_BIN5_PRI_HIGHER_LIMIT 2010 /* us */
255 
256 #define DFS_BIN5_WIDTH_MARGIN 4 /* us */
257 #define DFS_BIN5_RSSI_MARGIN  5 /* dBm */
258 
259 /**
260  * Following threshold is not specified but should be
261  * okay statistically.
262  */
263 #define DFS_BIN5_BRI_LOWER_LIMIT 300000   /* us */
264 #define DFS_BIN5_BRI_UPPER_LIMIT 12000000 /* us */
265 
266 /* Max number of pulses kept in buffer */
267 #define DFS_MAX_PULSE_BUFFER_SIZE   1024
268 #define DFS_MAX_PULSE_BUFFER_MASK   0x3ff
269 
270 #define DFS_FAST_CLOCK_MULTIPLIER    (800/11)
271 #define DFS_NO_FAST_CLOCK_MULTIPLIER (80)
272 #define DFS_BIG_SIDX 10000
273 
274 /* Min value of valid psidx diff */
275 #define DFS_MIN_PSIDX_DIFF 4
276 /* Max value of valid psidx diff */
277 #define DFS_MAX_PSIDX_DIFF 16
278 
279 /**
280  * Software use: channel interference used for as AR as well as RADAR
281  * interference detection.
282  */
283 #define CHANNEL_INTERFERENCE    0x01
284 
285 #define CHANNEL_2GHZ      0x00080 /* 2 GHz spectrum channel. */
286 #define CHANNEL_OFDM      0x00040 /* OFDM channel */
287 #define CHANNEL_TURBO     0x00010 /* Turbo Channel */
288 #define CHANNEL_108G (CHANNEL_2GHZ|CHANNEL_OFDM|CHANNEL_TURBO)
289 
290 /* qdf_packed - denotes structure is packed. */
291 #define qdf_packed __qdf_packed
292 
293 #define SEG_ID_PRIMARY         0
294 #define SEG_ID_SECONDARY       1
295 
296 /* MIN and MAX width for different regions */
297 #define REG0_MIN_WIDTH 33
298 #define REG0_MAX_WIDTH 38
299 #define REG1_MIN_WIDTH 39
300 #define REG1_MAX_WIDTH 44
301 #define REG2_MIN_WIDTH 53
302 #define REG2_MAX_WIDTH 58
303 #define REG3_MIN_WIDTH 126
304 #define REG3_MAX_WIDTH 140
305 #define REG4_MIN_WIDTH 141
306 #define REG4_MAX_WIDTH 160
307 #define REG5_MIN_WIDTH 189
308 #define REG5_MAX_WIDTH 210
309 #define REG6_MIN_WIDTH 360
310 #define REG6_MAX_WIDTH 380
311 #define REG7_MIN_WIDTH 257
312 #define REG7_MAX_WIDTH 270
313 #define REG8_MIN_WIDTH 295
314 #define REG8_MAX_WIDTH 302
315 
316 #define OVER_SAMPLING_FREQ 44000
317 #define SAMPLING_FREQ 40000
318 #define HUNDRED 100
319 #define NUM_BINS 128
320 #define THOUSAND 1000
321 
322 /* ETSI11_WORLD regdmn pair id */
323 #define ETSI11_WORLD_REGDMN_PAIR_ID 0x26
324 #define ETSI12_WORLD_REGDMN_PAIR_ID 0x28
325 #define ETSI13_WORLD_REGDMN_PAIR_ID 0x27
326 #define ETSI14_WORLD_REGDMN_PAIR_ID 0x29
327 
328 /* Array offset to ETSI legacy pulse */
329 #define ETSI_LEGACY_PULSE_ARR_OFFSET 2
330 
331 #define ETSI_RADAR_EN302_502_FREQ_LOWER 5725
332 #define ETSI_RADAR_EN302_502_FREQ_UPPER 5865
333 
334 #define DFS_NOL_ADD_CHAN_LOCKED(dfs, freq, timeout)         \
335 	do {                                                \
336 		WLAN_DFSNOL_LOCK(dfs);                      \
337 		dfs_nol_addchan(dfs, freq, timeout);        \
338 		WLAN_DFSNOL_UNLOCK(dfs);                    \
339 	} while (0)
340 
341 #define DFS_NOL_DELETE_CHAN_LOCKED(dfs, freq, chwidth)      \
342 	do {                                                \
343 		WLAN_DFSNOL_LOCK(dfs);                      \
344 		dfs_nol_delete(dfs, freq, chwidth);         \
345 		WLAN_DFSNOL_UNLOCK(dfs);                    \
346 	} while (0)
347 
348 #define DFS_GET_NOL_LOCKED(dfs, dfs_nol, nchan)             \
349 	do {                                                \
350 		WLAN_DFSNOL_LOCK(dfs);                      \
351 		dfs_get_nol(dfs, dfs_nol, nchan);           \
352 		WLAN_DFSNOL_UNLOCK(dfs);                    \
353 	} while (0)
354 
355 #define DFS_PRINT_NOL_LOCKED(dfs)                           \
356 	do {                                                \
357 		WLAN_DFSNOL_LOCK(dfs);                      \
358 		dfs_print_nol(dfs);                         \
359 		WLAN_DFSNOL_UNLOCK(dfs);                    \
360 	} while (0)
361 
362 #define DFS_NOL_FREE_LIST_LOCKED(dfs)                       \
363 	do {                                                \
364 		WLAN_DFSNOL_LOCK(dfs);                      \
365 		dfs_nol_free_list(dfs);                     \
366 		WLAN_DFSNOL_UNLOCK(dfs);                    \
367 	} while (0)
368 
369 /* Host sends the average parameters of the radar pulses and starts the status
370  * wait timer with this timeout.
371  */
372 #if defined(WLAN_DFS_PARTIAL_OFFLOAD) && defined(HOST_DFS_SPOOF_TEST)
373 #define HOST_DFS_STATUS_WAIT_TIMER_MS 200
374 #endif
375 
376 /*
377  * USENOL_DISABLE_NOL_HOST_AND_FW : Do not add radar hit channel to NOL
378  * in host and FW. Enable CSA on the same channel.
379  */
380 #define USENOL_DISABLE_NOL_HOST_AND_FW 0
381 /*
382  * USENOL_ENABLE_NOL_HOST_AND_FW : Add the radar hit channel to NOL in
383  * host and FW (in case of FO). NOL timer cannot be configured by the user
384  * as FW does not allow manipulating NOL timeout. If noltimeout is configured,
385  * (say 1 min) FW will not be intimated about the configuration and hence NOL
386  * timer may elapse at different instances in host (after 1 min) and FW (after
387  * default 30 min) which could lead to DFS Violation if host tries to come up
388  * on the channel after host NOL timeout (of 1 min) as the FW would still
389  * have the channel in NOL list.
390  */
391 #define USENOL_ENABLE_NOL_HOST_AND_FW 1
392 /*
393  * USENOL_ENABLE_NOL_HOST_DISABLE_NOL_FW : Add the radar hit channel to NOL
394  * in host. NOL timer can be configured by user. NOL in FW (for FO) is disabled.
395  */
396 #define USENOL_ENABLE_NOL_HOST_DISABLE_NOL_FW 2
397 
398 /**
399  * struct dfs_pulseparams - DFS pulse param structure.
400  * @p_time:        Time for start of pulse in usecs.
401  * @p_dur:         Duration of pulse in usecs.
402  * @p_rssi:        RSSI of pulse.
403  * @p_seg_id:      Segment id.
404  * @p_sidx:        Sidx value.
405  * @p_delta_peak:  Delta peak value.
406  * @p_psidx_diff:  The difference in the FFT peak index between the short FFT
407  *                 and the first long FFT.
408  * @p_seq_num:     Sequence number.
409  */
410 struct dfs_pulseparams {
411 	uint64_t p_time;
412 	uint8_t  p_dur;
413 	uint8_t  p_rssi;
414 	uint8_t  p_seg_id;
415 	int16_t  p_sidx;
416 	int8_t   p_delta_peak;
417 	int16_t  p_psidx_diff;
418 	uint32_t p_seq_num;
419 } qdf_packed;
420 
421 /**
422  * struct dfs_pulseline - Pulseline structure.
423  * @pl_elems[]:     array of pulses in delay line.
424  * @pl_firstelem:   Index of the first element.
425  * @pl_lastelem:    Index of the last element.
426  * @pl_numelems:    Number of elements in the delay line.
427  */
428 struct dfs_pulseline {
429 	struct dfs_pulseparams pl_elems[DFS_MAX_PULSE_BUFFER_SIZE];
430 	uint32_t pl_firstelem;
431 	uint32_t pl_lastelem;
432 	uint32_t pl_numelems;
433 } qdf_packed;
434 
435 #define DFS_EVENT_CHECKCHIRP  0x01 /* Whether to check the chirp flag */
436 #define DFS_EVENT_HW_CHIRP    0x02 /* hardware chirp */
437 #define DFS_EVENT_SW_CHIRP    0x04 /* software chirp */
438 /* Whether the event contains valid psidx diff value*/
439 #define DFS_EVENT_VALID_PSIDX_DIFF 0x08
440 
441 /* Use this only if the event has CHECKCHIRP set. */
442 #define DFS_EVENT_ISCHIRP(e) \
443 	((e)->re_flags & (DFS_EVENT_HW_CHIRP | DFS_EVENT_SW_CHIRP))
444 
445 /**
446  * Check if the given event is to be rejected as not possibly
447  * a chirp.  This means:
448  *   (a) it's a hardware or software checked chirp, and
449  *   (b) the HW/SW chirp bits are both 0.
450  */
451 #define DFS_EVENT_NOTCHIRP(e) \
452 	(((e)->re_flags & (DFS_EVENT_CHECKCHIRP)) && (!DFS_EVENT_ISCHIRP((e))))
453 
454 /**
455  * struct dfs_event - DFS event structure.
456  * @re_full_ts:          64-bit full timestamp from interrupt time.
457  * @re_ts:               Original 15 bit recv timestamp.
458  * @re_rssi:             Rssi of radar event.
459  * @re_dur:              Duration of radar pulse.
460  * @re_chanindex:        Channel of event.
461  * @re_flags:            Event flags.
462  * @re_freq:             Centre frequency of event, KHz.
463  * @re_freq_lo:          Lower bounds of frequency, KHz.
464  * @re_freq_hi:          Upper bounds of frequency, KHz.
465  * @re_seg_id:           HT80_80/HT160 use.
466  * @re_sidx:             Seg index.
467  * @re_freq_offset_khz:  Freq offset in KHz
468  * @re_peak_mag:         Peak mag.
469  * @re_total_gain:       Total gain.
470  * @re_mb_gain:          Mb gain.
471  * @re_relpwr_db:        Relpower in db.
472  * @re_delta_diff:       Delta diff.
473  * @re_delta_peak:       Delta peak.
474  * @re_psidx_diff:       Psidx diff.
475  * @re_list:             List of radar events.
476  */
477 struct dfs_event {
478 	uint64_t  re_full_ts;
479 	uint32_t  re_ts;
480 	uint8_t   re_rssi;
481 	uint8_t   re_dur;
482 	uint8_t   re_chanindex;
483 	uint8_t   re_flags;
484 	uint32_t  re_freq;
485 	uint32_t  re_freq_lo;
486 	uint32_t  re_freq_hi;
487 	uint8_t   re_seg_id;
488 	int       re_sidx;
489 	u_int     re_freq_offset_khz;
490 	int       re_peak_mag;
491 	int       re_total_gain;
492 	int       re_mb_gain;
493 	int       re_relpwr_db;
494 	uint8_t   re_delta_diff;
495 	int8_t    re_delta_peak;
496 	int16_t   re_psidx_diff;
497 
498 	STAILQ_ENTRY(dfs_event) re_list;
499 } qdf_packed;
500 
501 #define DFS_AR_MAX_ACK_RADAR_DUR   511
502 #define DFS_AR_MAX_NUM_PEAKS       3
503 #define DFS_AR_ARQ_SIZE            2048 /* 8K AR events for buffer size */
504 #define DFS_AR_ARQ_SEQSIZE         2049 /* Sequence counter wrap for AR */
505 
506 #define DFS_RADARQ_SIZE      512 /* 1K radar events for buffer size */
507 #define DFS_RADARQ_SEQSIZE   513 /* Sequence counter wrap for radar */
508 /* Number of radar channels we keep state for */
509 #define DFS_NUM_RADAR_STATES 64
510 /* Max number radar filters for each type */
511 #define DFS_MAX_NUM_RADAR_FILTERS 10
512 /* Number of different radar types */
513 #define DFS_MAX_RADAR_TYPES  32
514 /* Number of filter index table rows */
515 #define DFS_NUM_FT_IDX_TBL_ROWS  256
516 
517 /* RADAR filter pattern type 1*/
518 #define WLAN_DFS_RF_PATTERN_TYPE_1 1
519 
520 /**
521  * struct dfs_ar_state - DFS AR state structure.
522  * @ar_prevwidth:         Previous width.
523  * @ar_phyerrcount[]:     Phy error count.
524  * @ar_acksum:            Acksum.
525  * @ar_packetthreshold:   Thresh to determine traffic load.
526  * @ar_parthreshold:      Thresh to determine peak.
527  * @ar_radarrssi:         Rssi threshold for AR event.
528  * @ar_prevtimestamp:     Prev time stamp.
529  * @ar_peaklist[]:        Peak list.
530  */
531 struct dfs_ar_state {
532 	uint32_t ar_prevwidth;
533 	uint32_t ar_phyerrcount[DFS_AR_MAX_ACK_RADAR_DUR];
534 	uint32_t ar_acksum;
535 	uint32_t ar_packetthreshold;
536 	uint32_t ar_parthreshold;
537 	uint32_t ar_radarrssi;
538 	uint16_t ar_prevtimestamp;
539 	uint16_t ar_peaklist[DFS_AR_MAX_NUM_PEAKS];
540 };
541 
542 /**
543  * struct dfs_delayelem - Delay Element.
544  * @de_time:       Current "filter" time for start of pulse in usecs.
545  * @de_dur:        Duration of pulse in usecs.
546  * @de_rssi:       Rssi of pulse in dB.
547  * @de_ts:         Time stamp for this delay element.
548  * @de_seg_id:     Segment id for HT80_80/HT160 use.
549  * @de_sidx:       Sidx value.
550  * @de_delta_peak: Delta peak.
551  * @de_psidx_diff: Psidx diff.
552  * @de_seq_num:    Sequence number.
553  */
554 struct dfs_delayelem {
555 	uint32_t de_time;
556 	uint8_t  de_dur;
557 	uint8_t  de_rssi;
558 	uint64_t de_ts;
559 	uint8_t  de_seg_id;
560 	int16_t  de_sidx;
561 	int8_t   de_delta_peak;
562 	int16_t  de_psidx_diff;
563 	uint32_t de_seq_num;
564 } qdf_packed;
565 
566 /**
567  * struct dfs_delayline - DFS Delay Line.
568  * @dl_elems[]:    Array of pulses in delay line.
569  * @dl_last_ts:    Last timestamp the delay line was used (in usecs).
570  * @dl_firstelem:  Index of the first element.
571  * @dl_lastelem:   Index of the last element.
572  * @dl_numelems:   Number of elements in the delay line.
573  * The following is to handle fractional PRI pulses that can cause false
574  * detection.
575  * @dl_seq_num_start: Sequence number of first pulse that was part of
576  *                    threshold match.
577  * @dl_seq_num_stop:  Sequence number of last pulse that was part of threshold
578  *                    match.
579  * The following is required because the first pulse may or may not be in the
580  * delay line but we will find it iin the pulse line using dl_seq_num_second's
581  * diff_ts value.
582  * @dl_seq_num_second: Sequence number of second pulse that was part of
583  *                     threshold match.
584  * @dl_search_pri:     We need final search PRI to identify possible fractional
585  *                     PRI issue.
586  * @dl_min_sidx:       Minimum sidx value of pulses used to match thershold.
587  *                     Used for sidx spread check.
588  * @dl_max_sidx:       Maximum sidx value of pulses used to match thershold.
589  *                     Used for sidx spread check.
590  * @dl_delta_peak_match_count: Number of pulse in the delay line that had valid
591  *                             delta peak value.
592  * @dl_psidx_diff_match_count: Number of pulse in the delay line that had valid
593  *                             psidx diff value.
594  */
595 struct dfs_delayline {
596 	struct dfs_delayelem dl_elems[DFS_MAX_DL_SIZE];
597 	uint64_t dl_last_ts;
598 	uint32_t dl_firstelem;
599 	uint32_t dl_lastelem;
600 	uint32_t dl_numelems;
601 	uint32_t dl_seq_num_start;
602 	uint32_t dl_seq_num_stop;
603 	uint32_t dl_seq_num_second;
604 	uint32_t dl_search_pri;
605 	int16_t  dl_min_sidx;
606 	int8_t   dl_max_sidx;
607 	uint8_t  dl_delta_peak_match_count;
608 	uint8_t  dl_psidx_diff_match_count;
609 } qdf_packed;
610 
611 /**
612  * struct dfs_filter - Dfs filter.
613  * @rf_dl:              Delay line of pulses for this filter.
614  * @rf_numpulses:       Number of pulses in the filter.
615  * @rf_minpri:          Min pri to be considered for this filter.
616  * @rf_maxpri:          Max pri to be considered for this filter.
617  * @rf_threshold:       Match filter output threshold for radar detect.
618  * @rf_filterlen:       Length (in usecs) of the filter.
619  * @rf_patterntype:     Fixed or variable pattern type.
620  * @rf_fixed_pri_radar_pulse: indicates if it is a fixed pri pulse.
621  * @rf_mindur:          Min duration for this radar filter.
622  * @rf_maxdur:          Max duration for this radar filter.
623  * @rf_ignore_pri_window: Ignore pri window.
624  * @rf_pulseid:         Unique ID corresponding to the original filter ID.
625  * To reduce false detection, look at frequency spread. For now we will use
626  * sidx spread. But for HT160 frequency spread will be a better measure.
627  * @rf_sidx_spread:     Maximum SIDX value spread in a matched sequence
628  *                      excluding FCC Bin 5.
629  * @rf_check_delta_peak: Minimum allowed delta_peak value for a pulse to be
630  *                       considetred for this filter's match.
631  */
632 struct dfs_filter {
633 	struct dfs_delayline rf_dl;
634 	uint32_t  rf_numpulses;
635 	uint32_t  rf_minpri;
636 	uint32_t  rf_maxpri;
637 	uint32_t  rf_threshold;
638 	uint32_t  rf_filterlen;
639 	uint32_t  rf_patterntype;
640 	uint32_t  rf_fixed_pri_radar_pulse;
641 	uint32_t  rf_mindur;
642 	uint32_t  rf_maxdur;
643 	uint32_t  rf_ignore_pri_window;
644 	uint32_t  rf_pulseid;
645 	uint16_t  rf_sidx_spread;
646 	int8_t    rf_check_delta_peak;
647 } qdf_packed;
648 
649 /**
650  * struct dfs_filtertype - Structure of DFS Filter type.
651  * @ft_filters[]:      Array of ptrs storing addresses for struct of dfs_filter.
652  * @ft_filterdur:      Duration of pulse which specifies filter type.
653  * @ft_numfilters:     Num filters of this type.
654  * @ft_last_ts:        Last timestamp this filtertype was used (in usecs).
655  * @ft_mindur:         Min pulse duration to be considered for this filter type.
656  * @ft_maxdur:         Max pulse duration to be considered for this filter type.
657  * @ft_rssithresh:     Min rssi to be considered for this filter type.
658  * @ft_numpulses:      Num pulses in each filter of this type.
659  * @ft_patterntype:    Fixed or variable pattern type.
660  * @ft_minpri:         Min pri to be considered for this type.
661  * @ft_rssimargin:     Rssi threshold margin. In Turbo Mode HW reports rssi 3dB
662  *                     lower than in non TURBO mode. This will offset that diff.
663  */
664 struct dfs_filtertype {
665 	struct dfs_filter *ft_filters[DFS_MAX_NUM_RADAR_FILTERS];
666 	uint32_t  ft_filterdur;
667 	uint32_t  ft_numfilters;
668 	uint64_t  ft_last_ts;
669 	uint32_t  ft_mindur;
670 	uint32_t  ft_maxdur;
671 	uint32_t  ft_rssithresh;
672 	uint32_t  ft_numpulses;
673 	uint32_t  ft_patterntype;
674 	uint32_t  ft_minpri;
675 	uint32_t  ft_rssimargin;
676 };
677 
678 /**
679  * struct dfs_channel - Channel structure for dfs component.
680  * @dfs_ch_freq:                Frequency in Mhz.
681  * @dfs_ch_flags:               Channel flags.
682  * @dfs_ch_flagext:             Extended channel flags.
683  * @dfs_ch_ieee:                IEEE channel number.
684  * @dfs_ch_vhtop_ch_freq_seg1:  Channel Center frequency.
685  * @dfs_ch_vhtop_ch_freq_seg2:  Channel Center frequency applicable for 80+80MHz
686  *                          mode of operation.
687  */
688 struct dfs_channel {
689 	uint16_t       dfs_ch_freq;
690 	uint64_t       dfs_ch_flags;
691 	uint16_t       dfs_ch_flagext;
692 	uint8_t        dfs_ch_ieee;
693 	uint8_t        dfs_ch_vhtop_ch_freq_seg1;
694 	uint8_t        dfs_ch_vhtop_ch_freq_seg2;
695 };
696 
697 /**
698  * struct dfs_state - DFS state.
699  * @rs_chan:            Channel info.
700  * @rs_chanindex:       Channel index in radar structure.
701  * @rs_numradarevents:  Number of radar events.
702  * @rs_param:           Phy param.
703  */
704 struct dfs_state {
705 	struct dfs_channel rs_chan;
706 	uint8_t  rs_chanindex;
707 	uint32_t rs_numradarevents;
708 	struct wlan_dfs_phyerr_param rs_param;
709 };
710 
711 #define DFS_NOL_TIMEOUT_S  (30*60)    /* 30 minutes in seconds */
712 #define DFS_NOL_TIMEOUT_MS (DFS_NOL_TIMEOUT_S * 1000)
713 #define DFS_NOL_TIMEOUT_US (DFS_NOL_TIMEOUT_MS * 1000)
714 
715 /**
716  * struct dfs_nolelem - DFS NOL element.
717  * @nol_dfs           Back pointer to dfs object.
718  * @nol_freq:         Centre frequency.
719  * @nol_chwidth:      Event width (MHz).
720  * @nol_start_ticks:  NOL start time in OS ticks.
721  * @nol_timeout_ms:   NOL timeout value in msec.
722  * @nol_timer:        Per element NOL timer.
723  * @nol_next:         Next element pointer.
724  */
725 struct dfs_nolelem {
726 	TAILQ_ENTRY(dfs_nolelem) nolelem_list;
727 	struct wlan_dfs *nol_dfs;
728 	uint32_t       nol_freq;
729 	uint32_t       nol_chwidth;
730 	unsigned long  nol_start_ticks;
731 	uint32_t       nol_timeout_ms;
732 	os_timer_t     nol_timer;
733 	struct dfs_nolelem *nol_next;
734 } qdf_packed;
735 
736 
737 /**
738  * struct dfs_info - DFS Info.
739  * @rn_ftindex:            Number of different types of radars.
740  * @rn_lastfull_ts:        Last 64 bit timstamp from recv interrupt.
741  * @rn_last_ts:            last 15 bit ts from recv descriptor.
742  * @rn_last_unique_ts:     last unique 32 bit ts from recv descriptor.
743  * @rn_ts_prefix:          Prefix to prepend to 15 bit recv ts.
744  * @rn_numbin5radars:      Number of bin5 radar pulses to search for.
745  * @rn_fastdivGCval:       Value of fast diversity gc limit from init file.
746  * @rn_minrssithresh:      Min rssi for all radar types.
747  * @rn_maxpulsedur:        Max pulse width in TSF ticks.
748  * @dfs_ext_chan_busy:     Ext chan busy.
749  * @ext_chan_busy_ts:      Ext chan busy time.
750  * @dfs_bin5_chirp_ts:     Ext bin5 chrip time.
751  * @dfs_last_bin5_dur:     Last bin5 during.
752  */
753 struct dfs_info {
754 	uint32_t  rn_ftindex;
755 	uint64_t  rn_lastfull_ts;
756 	uint16_t  rn_last_ts;
757 	uint32_t  rn_last_unique_ts;
758 	uint64_t  rn_ts_prefix;
759 	uint32_t  rn_numbin5radars;
760 	uint32_t  rn_fastdivGCval;
761 	int32_t   rn_minrssithresh;
762 	uint32_t  rn_maxpulsedur;
763 	uint8_t   dfs_ext_chan_busy;
764 	uint64_t  ext_chan_busy_ts;
765 	uint64_t  dfs_bin5_chirp_ts;
766 	uint8_t   dfs_last_bin5_dur;
767 } qdf_packed;
768 
769 /**
770  * struct dfs_bin5elem - BIN5 elements.
771  * @be_ts:   Timestamp for the bin5 element.
772  * @be_rssi: Rssi for the bin5 element.
773  * @be_dur:  Duration of bin5 element.
774  */
775 struct dfs_bin5elem {
776 	uint64_t  be_ts;
777 	uint32_t  be_rssi;
778 	uint32_t  be_dur;
779 };
780 
781 /**
782  * struct dfs_bin5radars - BIN5 radars.
783  * @br_elems[]:    List of bin5 elems that fall within the time window.
784  * @br_firstelem:  Index of the first element.
785  * @br_lastelem:   Index of the last element.
786  * @br_numelems:   Number of elements in the delay line.
787  * @br_pulse:      Original info about bin5 pulse.
788  */
789 struct dfs_bin5radars {
790 	struct dfs_bin5elem br_elems[DFS_MAX_B5_SIZE];
791 	uint32_t  br_firstelem;
792 	uint32_t  br_lastelem;
793 	uint32_t  br_numelems;
794 	struct dfs_bin5pulse br_pulse;
795 };
796 
797 /**
798  * struct dfs_stats - DFS stats.
799  * @num_radar_detects:    Total num. of radar detects.
800  * @num_seg_two_radar_detects: Total num. of radar detected in secondary segment
801  * @total_phy_errors:     Total PHY errors.
802  * @owl_phy_errors:       OWL PHY errors.
803  * @pri_phy_errors:       Primary channel phy errors.
804  * @ext_phy_errors:       Extension channel phy errors.
805  * @dc_phy_errors:        DC PHY errors.
806  * @early_ext_phy_errors: Extension channel early radar found error.
807  * @bwinfo_errors:        Bogus bandwidth info received in descriptor.
808  * @datalen_discards:     data length at least three bytes of payload.
809  * @rssi_discards:        RSSI is not accurate.
810  * @last_reset_tstamp:    Last reset timestamp.
811  */
812 struct dfs_stats {
813 	uint32_t       num_radar_detects;
814 	uint32_t  num_seg_two_radar_detects;
815 	uint32_t  total_phy_errors;
816 	uint32_t  owl_phy_errors;
817 	uint32_t  pri_phy_errors;
818 	uint32_t  ext_phy_errors;
819 	uint32_t  dc_phy_errors;
820 	uint32_t  early_ext_phy_errors;
821 	uint32_t  bwinfo_errors;
822 	uint32_t  datalen_discards;
823 	uint32_t  rssi_discards;
824 	uint64_t  last_reset_tstamp;
825 };
826 
827 #define DFS_EVENT_LOG_SIZE      256
828 
829 /**
830  * struct dfs_event_log - DFS event log.
831  * @ts:               64-bit full timestamp from interrupt time.
832  * @diff_ts:          Diff timestamp.
833  * @rssi:             Rssi of radar event.
834  * @dur:              Duration of radar pulse.
835  * @is_chirp:         Chirp flag.
836  * @seg_id:           HT80_80/HT160 use.
837  * @sidx:             Seg index.
838  * @freq_offset_khz:  Freq offset in KHz
839  * @peak_mag:         Peak mag.
840  * @total_gain:       Total gain.
841  * @mb_gain:          Mb gain.
842  * @relpwr_db:        Relpower in db.
843  * @delta_diff:       Delta diff.
844  * @delta_peak:       Delta peak.
845  * @psidx_diff:       Psidx diff.
846  */
847 
848 struct dfs_event_log {
849 	uint64_t  ts;
850 	uint32_t  diff_ts;
851 	uint8_t   rssi;
852 	uint8_t   dur;
853 	int       is_chirp;
854 	uint8_t   seg_id;
855 	int       sidx;
856 	u_int     freq_offset_khz;
857 	int       peak_mag;
858 	int       total_gain;
859 	int       mb_gain;
860 	int       relpwr_db;
861 	uint8_t   delta_diff;
862 	int8_t    delta_peak;
863 	int16_t   psidx_diff;
864 };
865 
866 #define WLAN_DFS_RESET_TIME_S 7
867 #define WLAN_DFS_WAIT (60 + WLAN_DFS_RESET_TIME_S) /* 60 seconds */
868 #define WLAN_DFS_WAIT_MS ((WLAN_DFS_WAIT) * 1000)  /*in MS*/
869 
870 #define WLAN_DFS_WEATHER_CHANNEL_WAIT_MIN 10 /*10 minutes*/
871 #define WLAN_DFS_WEATHER_CHANNEL_WAIT_S (WLAN_DFS_WEATHER_CHANNEL_WAIT_MIN * 60)
872 #define WLAN_DFS_WEATHER_CHANNEL_WAIT_MS  \
873 	((WLAN_DFS_WEATHER_CHANNEL_WAIT_S) * 1000) /*in MS*/
874 
875 #define WLAN_DFS_WAIT_POLL_PERIOD 2  /* 2 seconds */
876 #define WLAN_DFS_WAIT_POLL_PERIOD_MS  \
877 	((WLAN_DFS_WAIT_POLL_PERIOD) * 1000)  /*in MS*/
878 
879 #define DFS_DEBUG_TIMEOUT_S     30 /* debug timeout is 30 seconds */
880 #define DFS_DEBUG_TIMEOUT_MS    (DFS_DEBUG_TIMEOUT_S * 1000)
881 
882 #define RSSI_POSSIBLY_FALSE              50
883 #define SEARCH_FFT_REPORT_PEAK_MAG_THRSH 40
884 
885 #define MIN_DFS_SUBCHAN_BW 20 /* Minimum bandwidth of each subchannel. */
886 
887 #define FREQ_OFFSET_BOUNDARY_FOR_80MHZ 40
888 
889 /**
890  * struct wlan_dfs -                 The main dfs structure.
891  * @dfs_debug_mask:                  Current debug bitmask.
892  * @dfs_curchan_radindex:            Current channel radar index.
893  * @dfs_extchan_radindex:            Extension channel radar index.
894  * @dfsdomain:                       Current DFS domain.
895  * @dfs_proc_phyerr:                 Flags for Phy Errs to process.
896  * @dfs_eventq:                      Q of free dfs event objects.
897  * @dfs_eventqlock:                  Lock for free dfs event list.
898  * @dfs_radarq:                      Q of radar events.
899  * @dfs_radarqlock:                  Lock for dfs q.
900  * @dfs_arq:                         Q of AR events.
901  * @dfs_arqlock:                     Lock for AR q.
902  * @dfs_ar_state:                    AR state.
903  * @dfs_radar[]:                     Per-Channel Radar detector state.
904  * @dfs_radarf[]:                    One filter for each radar pulse type.
905  * @dfs_rinfo:                       State vars for radar processing.
906  * @dfs_b5radars:                    Array of bin5 radar events.
907  * @dfs_ftindextable:                Map of radar durs to filter types.
908  * @dfs_nol:                         Non occupancy list for radar.
909  * @dfs_nol_count:                   How many items?
910  * @dfs_defaultparams:               Default phy params per radar state.
911  * @wlan_dfs_stats:                  DFS related stats.
912  * @pulses:                          Pulse history.
913  * @events:                          Events structure.
914  * @wlan_radar_tasksched:            Radar task is scheduled.
915  * @wlan_dfswait:                    Waiting on channel for radar detect.
916  * @wlan_dfstest:                    Test timer in progress.
917  * @dfs_caps:                        Object of wlan_dfs_caps structure.
918  * @wlan_dfstest_ieeechan:           IEEE chan num to return to after a dfs mute
919  *                                   test.
920  * @wlan_dfs_cac_time:               CAC period.
921  * @wlan_dfstesttime:                Time to stay off chan during dfs test.
922  * @wlan_dfswaittimer:               Dfs wait timer.
923  * @wlan_dfstesttimer:               Dfs mute test timer.
924  * @wlan_dfs_debug_timer:            Dfs debug timer.
925  * @dfs_bangradar_type:              Radar simulation type.
926  * @is_radar_found_on_secondary_seg: Radar on second segment.
927  * @dfs_radar_found_for_fo:          Radar found event for FO(Full Offload) is
928  *                                   received.
929  * @is_radar_during_precac:          Radar found during precac.
930  * @dfs_precac_lock:                 Lock to protect precac lists.
931  * @dfs_precac_enable:               Enable the precac.
932  * @dfs_precac_secondary_freq:       Second segment freq for precac.
933  * @dfs_precac_primary_freq:         Primary freq.
934  * @dfs_precac_timer_running:        Precac timer running.
935  * @dfs_defer_precac_channel_change: Defer precac channel change.
936  * @dfs_precac_preferred_chan:       Channel to change after precac.
937  * @dfs_precac_inter_chan:           Intermediate non-DFS channel used while
938  *                                   doing precac.
939  * @dfs_pre_cac_timeout_channel_change: Channel change due to precac timeout.
940  * @wlan_dfs_task_timer:             Dfs wait timer.
941  * @dur_multiplier:                  Duration multiplier.
942  * @wlan_dfs_isdfsregdomain:         True when AP is in DFS domain
943  * @wlan_dfs_false_rssi_thres:       False RSSI Threshold.
944  * @wlan_dfs_peak_mag:               Peak mag.
945  * @radar_log[]:                     Radar log.
946  * @dfs_event_log_count:             Event log count.
947  * @dfs_event_log_on:                Event log on.
948  * @dfs_phyerr_count:                Same as number of PHY radar interrupts.
949  * @dfs_phyerr_reject_count:         When TLV is supported, # of radar events
950  *                                   ignored after TLV is parsed.
951  * @dfs_phyerr_queued_count:         Number of radar events queued for matching
952  *                                   the filters.
953  * @dfs_phyerr_freq_min:             Phyerr min freq.
954  * @dfs_phyerr_freq_max:             Phyerr max freq.
955  * @dfs_phyerr_w53_counter:          Phyerr w53 counter.
956  * @dfs_pri_multiplier:              Allow pulse if they are within multiple of
957  *                                   PRI for the radar type.
958  * @wlan_dfs_nol_timeout:            NOL timeout.
959  * @update_nol:                      Update NOL.
960  * @dfs_seq_num:                     Sequence number.
961  * @dfs_nol_event[]:                 NOL event.
962  * @dfs_nol_timer:                   NOL list processing.
963  * @dfs_nol_free_list:               NOL free list.
964  * @dfs_nol_elem_free_work:          The work queue to free an NOL element.
965  * @dfs_cac_timer:                   CAC timer.
966  * @dfs_cac_valid_timer:             Ignore CAC when this timer is running.
967  * @dfs_cac_timeout_override:        Overridden cac timeout.
968  * @dfs_enable:                      DFS Enable.
969  * @dfs_cac_timer_running:           DFS CAC timer running.
970  * @dfs_ignore_dfs:                  Ignore DFS.
971  * @dfs_ignore_cac:                  Ignore CAC.
972  * @dfs_cac_valid:                   DFS CAC valid.
973  * @dfs_cac_valid_time:              Time for which CAC will be valid and will
974  *                                   not be re-done.
975  * @dfs_precac_timer:                PRECAC timer.
976  * @dfs_precac_timeout_override:     Overridden precac timeout.
977  * @dfs_num_precac_freqs:            Number of PreCAC VHT80 frequencies.
978  * @dfs_precac_required_list:        PreCAC required list.
979  * @dfs_precac_done_list:            PreCAC done list.
980  * @dfs_precac_nol_list:             PreCAC NOL List.
981  * @dfs_curchan:                     DFS current channel.
982  * @dfs_cac_started_chan:            CAC started channel.
983  * @dfs_pdev_obj:                    DFS pdev object.
984  * @dfs_is_offload_enabled:          Set if DFS offload enabled.
985  * @dfs_use_nol:                     Use the NOL when radar found(default: TRUE)
986  * @dfs_nol_lock:                    Lock to protect nol list.
987  * @tx_leakage_threshold:            Tx leakage threshold for dfs.
988  * @dfs_use_nol_subchannel_marking:  Use subchannel marking logic to add only
989  *                                   radar affected subchannel instead of all
990  *                                   bonding channels.
991  * @dfs_host_wait_timer:             The timer that is started from host after
992  *                                   sending the average radar parameters.
993  *                                   Before this timeout host expects its dfs
994  *                                   status from fw.
995  * @dfs_average_pri:                 Average pri value of the received radar
996  *                                   pulses.
997  * @dfs_average_duration:            Average duration of the received radar
998  *                                   pulses.
999  * @dfs_average_sidx:                Average sidx of the received radar pulses.
1000  * @dfs_is_host_wait_running:        Indicates if host dfs status wait timer is
1001  *                                   running.
1002  * @dfs_average_params_sent:         Indicates if host has sent the average
1003  *                                   radar parameters.
1004  * @dfs_no_res_from_fw:              Indicates no response from fw.
1005  * @dfs_spoof_check_failed:          Indicates if the spoof check has failed.
1006  * @dfs_spoof_test_done:             Indicates if the sppof test is done.
1007  * @dfs_status_timeout_override:     Used to change the timeout value of
1008  *                                   dfs_host_wait_timer.
1009  * @dfs_is_stadfs_enabled:           Is STADFS enabled.
1010  * @dfs_min_sidx:                    Minimum sidx of the received radar pulses.
1011  * @dfs_max_sidx:                    Maximum sidx of the received radar pulses.
1012  * @dfs_seg_id:                      Segment ID of the radar hit channel.
1013  * @dfs_is_chirp:                    Radar Chirp in pulse present or not.
1014  * @dfs_bw_reduced:                  DFS bandwidth reduced channel bit.
1015  * @dfs_freq_offset:                 Frequency offset where radar was found.
1016  * @dfs_cac_aborted:                 DFS cac is aborted.
1017  * @dfs_disable_radar_marking:       To mark or unmark NOL chan as radar hit.
1018  * @dfs_data_struct_lock:            DFS data structure lock. This is to protect
1019  *                                   all the filtering data structures. For
1020  *                                   example: dfs_bin5radars, dfs_filtertype,
1021  *                                   etc.
1022  * @dfs_nol_ie_bandwidth:            Minimum Bandwidth of subchannels that
1023  *                                   are added to NOL.
1024  * @dfs_nol_ie_startfreq:            The centre frequency of the starting
1025  *                                   subchannel in the current channel list
1026  *                                   to be sent in NOL IE with RCSA.
1027  * @dfs_nol_ie_bitmap:               The bitmap of radar affected subchannels
1028  *                                   in the current channel list
1029  *                                   to be sent in NOL IE with RCSA.
1030  * @dfs_is_rcsa_ie_sent              To send or to not send RCSA IE.
1031  * @dfs_is_nol_ie_sent               To send or to not send NOL IE.
1032  */
1033 struct wlan_dfs {
1034 	uint32_t       dfs_debug_mask;
1035 	int16_t        dfs_curchan_radindex;
1036 	int16_t        dfs_extchan_radindex;
1037 	uint32_t       dfsdomain;
1038 	uint32_t       dfs_proc_phyerr;
1039 
1040 	STAILQ_HEAD(, dfs_event) dfs_eventq;
1041 	qdf_spinlock_t dfs_eventqlock;
1042 
1043 	STAILQ_HEAD(, dfs_event) dfs_radarq;
1044 	qdf_spinlock_t dfs_radarqlock;
1045 
1046 	STAILQ_HEAD(, dfs_event) dfs_arq;
1047 	qdf_spinlock_t dfs_arqlock;
1048 
1049 	struct dfs_ar_state   dfs_ar_state;
1050 	struct dfs_state      dfs_radar[DFS_NUM_RADAR_STATES];
1051 	struct dfs_filtertype *dfs_radarf[DFS_MAX_RADAR_TYPES];
1052 	struct dfs_info       dfs_rinfo;
1053 	struct dfs_bin5radars *dfs_b5radars;
1054 	int8_t                **dfs_ftindextable;
1055 	struct dfs_nolelem    *dfs_nol;
1056 	int                   dfs_nol_count;
1057 	struct wlan_dfs_phyerr_param dfs_defaultparams;
1058 	struct dfs_stats      wlan_dfs_stats;
1059 	struct dfs_pulseline  *pulses;
1060 	struct dfs_event      *events;
1061 
1062 	uint32_t       wlan_radar_tasksched:1,
1063 				   wlan_dfswait:1,
1064 				   wlan_dfstest:1;
1065 	struct wlan_dfs_caps dfs_caps;
1066 	uint8_t        wlan_dfstest_ieeechan;
1067 	uint32_t       wlan_dfs_cac_time;
1068 	uint32_t       wlan_dfstesttime;
1069 	os_timer_t     wlan_dfswaittimer;
1070 	os_timer_t     wlan_dfstesttimer;
1071 	os_timer_t     wlan_dfs_debug_timer;
1072 	enum dfs_bangradar_types dfs_bangradar_type;
1073 	bool           is_radar_found_on_secondary_seg;
1074 	bool           dfs_radar_found_for_fo;
1075 	bool           is_radar_during_precac;
1076 	qdf_spinlock_t dfs_precac_lock;
1077 	bool           dfs_precac_enable;
1078 	uint8_t        dfs_precac_secondary_freq;
1079 	uint8_t        dfs_precac_primary_freq;
1080 	uint8_t        dfs_precac_timer_running;
1081 	uint8_t        dfs_defer_precac_channel_change;
1082 #ifdef WLAN_DFS_PRECAC_AUTO_CHAN_SUPPORT
1083 	uint8_t        dfs_precac_preferred_chan;
1084 	uint8_t        dfs_precac_inter_chan;
1085 #endif
1086 	uint8_t        dfs_pre_cac_timeout_channel_change:1;
1087 	os_timer_t     wlan_dfs_task_timer;
1088 	int            dur_multiplier;
1089 	uint16_t       wlan_dfs_isdfsregdomain;
1090 	int            wlan_dfs_false_rssi_thres;
1091 	int            wlan_dfs_peak_mag;
1092 	struct dfs_event_log radar_log[DFS_EVENT_LOG_SIZE];
1093 	int            dfs_event_log_count;
1094 	int            dfs_event_log_on;
1095 	int            dfs_phyerr_count;
1096 	int            dfs_phyerr_reject_count;
1097 	int            dfs_phyerr_queued_count;
1098 	int            dfs_phyerr_freq_min;
1099 	int            dfs_phyerr_freq_max;
1100 	int            dfs_phyerr_w53_counter;
1101 	int            dfs_pri_multiplier;
1102 	int            wlan_dfs_nol_timeout;
1103 	bool           update_nol;
1104 	uint32_t       dfs_seq_num;
1105 	int            dfs_nol_event[DFS_CHAN_MAX];
1106 	os_timer_t     dfs_nol_timer;
1107 
1108 	TAILQ_HEAD(, dfs_nolelem) dfs_nol_free_list;
1109 	qdf_work_t     dfs_nol_elem_free_work;
1110 
1111 	os_timer_t     dfs_cac_timer;
1112 	os_timer_t     dfs_cac_valid_timer;
1113 	int            dfs_cac_timeout_override;
1114 	uint8_t        dfs_enable:1,
1115 				   dfs_cac_timer_running:1,
1116 				   dfs_ignore_dfs:1,
1117 				   dfs_ignore_cac:1,
1118 				   dfs_cac_valid:1;
1119 	uint32_t       dfs_cac_valid_time;
1120 	os_timer_t     dfs_precac_timer;
1121 	int            dfs_precac_timeout_override;
1122 	uint8_t        dfs_num_precac_freqs;
1123 #if defined(WLAN_DFS_FULL_OFFLOAD) && defined(QCA_DFS_NOL_OFFLOAD)
1124 	uint8_t        dfs_disable_radar_marking;
1125 #endif
1126 	TAILQ_HEAD(, dfs_precac_entry) dfs_precac_required_list;
1127 	TAILQ_HEAD(, dfs_precac_entry) dfs_precac_done_list;
1128 	TAILQ_HEAD(, dfs_precac_entry) dfs_precac_nol_list;
1129 
1130 #ifdef QCA_SUPPORT_ETSI_PRECAC_DFS
1131 	TAILQ_HEAD(, dfs_etsi_precac_entry) dfs_etsiprecac_required_list;
1132 	TAILQ_HEAD(, dfs_etsi_precac_entry) dfs_etsiprecac_done_list;
1133 #endif
1134 
1135 	struct dfs_channel *dfs_curchan;
1136 	struct dfs_channel dfs_cac_started_chan;
1137 	struct wlan_objmgr_pdev *dfs_pdev_obj;
1138 	bool           dfs_is_offload_enabled;
1139 	int            dfs_use_nol;
1140 	qdf_spinlock_t dfs_nol_lock;
1141 	uint16_t tx_leakage_threshold;
1142 	bool dfs_use_nol_subchannel_marking;
1143 	uint8_t        dfs_spoof_test_done:1;
1144 #if defined(WLAN_DFS_PARTIAL_OFFLOAD) && defined(HOST_DFS_SPOOF_TEST)
1145 	os_timer_t     dfs_host_wait_timer;
1146 	uint32_t       dfs_average_pri;
1147 	uint32_t       dfs_average_duration;
1148 	uint32_t       dfs_average_sidx;
1149 	uint8_t        dfs_is_host_wait_running:1,
1150 				   dfs_average_params_sent:1,
1151 				   dfs_no_res_from_fw:1,
1152 				   dfs_spoof_check_failed:1;
1153 	struct dfs_channel dfs_radar_found_chan;
1154 	int            dfs_status_timeout_override;
1155 #endif
1156 	bool           dfs_is_stadfs_enabled;
1157 	int32_t        dfs_min_sidx;
1158 	int32_t        dfs_max_sidx;
1159 	uint8_t        dfs_seg_id;
1160 	uint8_t        dfs_is_chirp;
1161 	bool           dfs_bw_reduced;
1162 	int32_t        dfs_freq_offset;
1163 	bool           dfs_cac_aborted;
1164 	qdf_spinlock_t dfs_data_struct_lock;
1165 	uint8_t        dfs_nol_ie_bandwidth;
1166 	uint16_t       dfs_nol_ie_startfreq;
1167 	uint8_t        dfs_nol_ie_bitmap;
1168 	bool           dfs_is_rcsa_ie_sent;
1169 	bool           dfs_is_nol_ie_sent;
1170 };
1171 
1172 /**
1173  * struct dfs_soc_priv_obj - dfs private data
1174  * @psoc: pointer to PSOC object information
1175  * @pdev: pointer to PDEV object information
1176  * @dfs_is_phyerr_filter_offload: For some chip like Rome indicates too many
1177  *                                phyerr packets in a short time, which causes
1178  *                                OS hang. If this feild is configured as true,
1179  *                                FW will do the pre-check, filter out some
1180  *                                kinds of invalid phyerrors and indicate
1181  *                                radar detection related information to host.
1182  */
1183 struct dfs_soc_priv_obj {
1184 	struct wlan_objmgr_psoc *psoc;
1185 	struct wlan_objmgr_pdev *pdev;
1186 	bool dfs_is_phyerr_filter_offload;
1187 };
1188 
1189 /**
1190  * enum DFS debug - This should match the table from if_ath.c.
1191  * @WLAN_DEBUG_DFS:             Minimal DFS debug.
1192  * @WLAN_DEBUG_DFS1:            Normal DFS debug.
1193  * @WLAN_DEBUG_DFS2:            Maximal DFS debug.
1194  * @WLAN_DEBUG_DFS3:            Matched filterID display.
1195  * @WLAN_DEBUG_DFS_PHYERR:      Phy error parsing.
1196  * @WLAN_DEBUG_DFS_NOL:         NOL related entries.
1197  * @WLAN_DEBUG_DFS_PHYERR_SUM:  PHY error summary.
1198  * @WLAN_DEBUG_DFS_PHYERR_PKT:  PHY error payload.
1199  * @WLAN_DEBUG_DFS_BIN5:        BIN5 checks.
1200  * @WLAN_DEBUG_DFS_BIN5_FFT:    BIN5 FFT check.
1201  * @WLAN_DEBUG_DFS_BIN5_PULSE:  BIN5 pulse check.
1202  * @WLAN_DEBUG_DFS_FALSE_DET:   False detection debug related prints.
1203  * @WLAN_DEBUG_DFS_FALSE_DET2:  Second level check to confirm poisitive
1204  *                              detection.
1205  * @WLAN_DEBUG_DFS_RANDOM_CHAN: Random channel selection.
1206  */
1207 enum {
1208 	WLAN_DEBUG_DFS  = 0x00000100,
1209 	WLAN_DEBUG_DFS1 = 0x00000200,
1210 	WLAN_DEBUG_DFS2 = 0x00000400,
1211 	WLAN_DEBUG_DFS3 = 0x00000800,
1212 	WLAN_DEBUG_DFS_PHYERR = 0x00001000,
1213 	WLAN_DEBUG_DFS_NOL    = 0x00002000,
1214 	WLAN_DEBUG_DFS_PHYERR_SUM = 0x00004000,
1215 	WLAN_DEBUG_DFS_PHYERR_PKT = 0x00008000,
1216 	WLAN_DEBUG_DFS_BIN5       = 0x00010000,
1217 	WLAN_DEBUG_DFS_BIN5_FFT   = 0x00020000,
1218 	WLAN_DEBUG_DFS_BIN5_PULSE = 0x00040000,
1219 	WLAN_DEBUG_DFS_FALSE_DET  = 0x00080000,
1220 	WLAN_DEBUG_DFS_FALSE_DET2 = 0x00100000,
1221 	WLAN_DEBUG_DFS_RANDOM_CHAN = 0x00200000,
1222 	WLAN_DEBUG_DFS_MAX        = 0x80000000,
1223 	WLAN_DEBUG_DFS_ALWAYS     = WLAN_DEBUG_DFS_MAX
1224 };
1225 
1226 /**
1227  * enum host dfs spoof check status.
1228  * @HOST_DFS_CHECK_PASSED: Host indicates RADAR detected and the FW
1229  *                         confirms it to be spoof radar to host.
1230  * @HOST_DFS_CHECK_FAILED: Host doesn't indicate RADAR detected or spoof
1231  *                         radar parameters by
1232  *                         WMI_HOST_DFS_RADAR_FOUND_CMDID doesn't match.
1233  * @HOST_DFS_STATUS_CHECK_HW_RADAR: Host indicates RADAR detected and the
1234  *                             FW confirms it to be real HW radar to host.
1235  */
1236 #if defined(WLAN_DFS_PARTIAL_OFFLOAD) && defined(HOST_DFS_SPOOF_TEST)
1237 enum {
1238 	HOST_DFS_STATUS_CHECK_PASSED = 0,
1239 	HOST_DFS_STATUS_CHECK_FAILED = 1,
1240 	HOST_DFS_STATUS_CHECK_HW_RADAR = 2
1241 };
1242 #endif
1243 
1244 /**
1245  * struct dfs_phy_err - DFS phy error.
1246  * @fulltsf:             64-bit TSF as read from MAC.
1247  * @is_pri:              Detected on primary channel.
1248  * @is_ext:              Detected on extension channel.
1249  * @is_dc:               Detected at DC.
1250  * @is_early:            Early detect.
1251  * @do_check_chirp:      Whether to check hw_chirp/sw_chirp.
1252  * @is_hw_chirp:         Hardware-detected chirp.
1253  * @is_sw_chirp:         Software detected chirp.
1254  * @rs_tstamp:           32 bit TSF from RX descriptor (event).
1255  * @freq:                Centre frequency of event - KHz.
1256  * @freq_lo:             Lower bounds of frequency - KHz.
1257  * @freq_hi:             Upper bounds of frequency - KHz.
1258  * @rssi:                Pulse RSSI.
1259  * @dur:                 Pulse duration, raw (not uS).
1260  * @seg_id:              HT80_80/HT160 use.
1261  * @sidx:                Seg index.
1262  * @freq_offset_khz:     Freq offset in KHz.
1263  * @peak_mag:            Peak mag.
1264  * @total_gain:          Total gain.
1265  * @mb_gain:             Mb gain.
1266  * @relpwr_db:           Relpower in DB.
1267  * @pulse_delta_diff:    Pulse delta diff.
1268  * @pulse_delta_peak:    Pulse delta peak.
1269  * @pulse_psidx_diff:    Pulse psidx diff.
1270  *
1271  * Chirp notes!
1272  *
1273  * Pre-Sowl chips don't do FFT reports, so chirp pulses simply show up
1274  * as long duration pulses.
1275  *
1276  * The bin5 checking code would simply look for a chirp pulse of the correct
1277  * duration (within MIN_BIN5_DUR and MAX_BIN5_DUR) and add it to the "chirp"
1278  * pattern.
1279  *
1280  * For Sowl and later, an FFT was done on longer duration frames.  If those
1281  * frames looked like a chirp, their duration was adjusted to fall within
1282  * the chirp duration limits.  If the pulse failed the chirp test (it had
1283  * no FFT data or the FFT didn't meet the chirping requirements) then the
1284  * pulse duration was adjusted to be greater than MAX_BIN5_DUR, so it
1285  * would always fail chirp detection.
1286  *
1287  * This is pretty horrible.
1288  *
1289  * The eventual goal for chirp handling is thus:
1290  *
1291  * 1)In case someone ever wants to do chirp detection with this code on
1292  *   chips that don't support chirp detection, you can still do it based
1293  *   on pulse duration.  That's your problem to solve.
1294  *
1295  * 2)For chips that do hardware chirp detection or FFT, the "do_check_chirp"
1296  *   bit should be set.
1297  *
1298  * 3)Then, either is_hw_chirp or is_sw_chirp is set, indicating that
1299  *   the hardware or software post-processing of the chirp event found
1300  *   that indeed it was a chirp.
1301  *
1302  * 4)Finally, the bin5 code should just check whether the chirp bits are
1303  *   set and behave appropriately, falling back onto the duration checks
1304  *   if someone wishes to use this on older hardware (or with disabled
1305  *   FFTs, for whatever reason.)
1306  *
1307  * XXX TODO:
1308  *
1309  * 1)add duration in uS and raw duration, so the PHY error parsing
1310  *   code is responsible for doing the duration calculation;
1311  * 2)add ts in raw and corrected, so the PHY error parsing
1312  *   code is responsible for doing the offsetting, not the radar
1313  *   event code.
1314  */
1315 struct dfs_phy_err {
1316 	uint64_t fulltsf;
1317 	uint32_t is_pri:1,
1318 			 is_ext:1,
1319 			 is_dc:1,
1320 			 is_early:1,
1321 			 do_check_chirp:1,
1322 			 is_hw_chirp:1,
1323 			 is_sw_chirp:1;
1324 	uint32_t rs_tstamp;
1325 	uint32_t freq;
1326 	uint32_t freq_lo;
1327 	uint32_t freq_hi;
1328 	uint8_t  rssi;
1329 	uint8_t  dur;
1330 	uint8_t  seg_id;
1331 	int      sidx;
1332 	u_int    freq_offset_khz;
1333 	int      peak_mag;
1334 	int      total_gain;
1335 	int      mb_gain;
1336 	int      relpwr_db;
1337 	uint8_t  pulse_delta_diff;
1338 	int8_t   pulse_delta_peak;
1339 	int16_t  pulse_psidx_diff;
1340 };
1341 
1342 /**
1343  * struct rx_radar_status - Parsed radar status
1344  * @raw_tsf:           Raw tsf
1345  * @tsf_offset:        TSF offset.
1346  * @rssi:              RSSI.
1347  * @pulse_duration:    Pulse duration.
1348  * @is_chirp:          Is chirp.
1349  * @delta_peak:        Delta peak.
1350  * @delta_diff:        Delta diff.
1351  * @sidx:              Starting frequency.
1352  * @freq_offset:       Frequency offset.
1353  * @agc_total_gain:    AGC total gain.
1354  * @agc_mb_gain:       AGC MB gain.
1355  */
1356 struct rx_radar_status {
1357 	uint32_t raw_tsf;
1358 	uint32_t tsf_offset;
1359 	int      rssi;
1360 	int      pulse_duration;
1361 	int      is_chirp:1;
1362 	int      delta_peak;
1363 	int      delta_diff;
1364 	int      sidx;
1365 	int      freq_offset; /* in KHz */
1366 	int      agc_total_gain;
1367 	int      agc_mb_gain;
1368 };
1369 
1370 /**
1371  * struct rx_search_fft_report - FFT report.
1372  * @total_gain_db:     Total gain in Db.
1373  * @base_pwr_db:       Base power in Db.
1374  * @fft_chn_idx:       FFT channel index.
1375  * @peak_sidx:         Peak sidx.
1376  * @relpwr_db:         Real power in Db.
1377  * @avgpwr_db:         Average power in Db.
1378  * @peak_mag:          Peak Mag.
1379  * @num_str_bins_ib:   Num dtr BINs IB
1380  * @seg_id:            Segment ID
1381  */
1382 struct rx_search_fft_report {
1383 	uint32_t total_gain_db;
1384 	uint32_t base_pwr_db;
1385 	int      fft_chn_idx;
1386 	int      peak_sidx;
1387 	int      relpwr_db;
1388 	int      avgpwr_db;
1389 	int      peak_mag;
1390 	int      num_str_bins_ib;
1391 	int      seg_id;
1392 };
1393 
1394 /**
1395  * dfs_process_radarevent() - process the radar event generated for a pulse.
1396  * @dfs: Pointer to wlan_dfs structure.
1397  * @chan: Current channel.
1398  *
1399  * There is currently no way to specify that a radar event has occurred on
1400  * a specific channel, so the current methodology is to mark both the pri
1401  * and ext channels as being unavailable. This should be fixed for 802.11ac
1402  * or we'll quickly run out of valid channels to use.
1403  *
1404  * If Radar found, this marks the channel (and the extension channel, if HT40)
1405  * as having seen a radar event. It marks CHAN_INTERFERENCE and will add it to
1406  * the local NOL implementation. This is only done for 'usenol=1', as the other
1407  * two modes don't do radar notification or CAC/CSA/NOL; it just notes there
1408  * was a radar.
1409  */
1410 void  dfs_process_radarevent(struct wlan_dfs *dfs,
1411 		struct dfs_channel *chan);
1412 
1413 /**
1414  * dfs_nol_addchan() - Add channel to NOL.
1415  * @dfs: Pointer to wlan_dfs structure.
1416  * @freq: frequency to add to NOL.
1417  * @dfs_nol_timeout: NOL timeout.
1418  */
1419 void dfs_nol_addchan(struct wlan_dfs *dfs,
1420 		uint16_t freq,
1421 		uint32_t dfs_nol_timeout);
1422 
1423 /**
1424  * dfs_get_nol() - Get NOL.
1425  * @dfs: Pointer to wlan_dfs structure.
1426  * @dfs_nol: Pointer to dfsreq_nolelem structure to save the channels from NOL.
1427  * @nchan: Number of channels.
1428  */
1429 void dfs_get_nol(struct wlan_dfs *dfs,
1430 		struct dfsreq_nolelem *dfs_nol,
1431 		int *nchan);
1432 
1433 /**
1434  * dfs_set_nol() - Set NOL.
1435  * @dfs: Pointer to wlan_dfs structure.
1436  * @dfs_nol: Pointer to dfsreq_nolelem structure.
1437  * @nchan: Number of channels.
1438  */
1439 void dfs_set_nol(struct wlan_dfs *dfs,
1440 		struct dfsreq_nolelem *dfs_nol,
1441 		int nchan);
1442 
1443 /**
1444  * dfs_nol_update() - NOL update
1445  * @dfs: Pointer to wlan_dfs structure.
1446  *
1447  * Notify the driver/umac that it should update the channel radar/NOL flags
1448  * based on the current NOL list.
1449  */
1450 void dfs_nol_update(struct wlan_dfs *dfs);
1451 
1452 /**
1453  * dfs_nol_timer_cleanup() - NOL timer cleanup.
1454  * @dfs: Pointer to wlan_dfs structure.
1455  *
1456  * Cancels the NOL timer and frees the NOL elements.
1457  */
1458 void dfs_nol_timer_cleanup(struct wlan_dfs *dfs);
1459 
1460 /**
1461  * dfs_nol_timer_detach() - Free NOL timer.
1462  * @dfs: Pointer to wlan_dfs structure.
1463  */
1464 void dfs_nol_timer_detach(struct wlan_dfs *dfs);
1465 
1466 /**
1467  * dfs_nol_workqueue_cleanup() - Flushes NOL workqueue.
1468  * @dfs: Pointer to wlan_dfs structure.
1469  *
1470  * Flushes the NOL workqueue.
1471  */
1472 void dfs_nol_workqueue_cleanup(struct wlan_dfs *dfs);
1473 
1474 /**
1475  * dfs_retain_bin5_burst_pattern() - Retain the BIN5 burst pattern.
1476  * @dfs: Pointer to wlan_dfs structure.
1477  * @diff_ts: Timestamp diff.
1478  * @old_dur: Old duration.
1479  */
1480 uint8_t dfs_retain_bin5_burst_pattern(struct wlan_dfs *dfs,
1481 		uint32_t diff_ts,
1482 		uint8_t old_dur);
1483 
1484 /**
1485  * dfs_bin5_check_pulse() - BIN5 check pulse.
1486  * @dfs: Pointer to wlan_dfs structure.
1487  * @re: Pointer to dfs_event structure.
1488  * @br: Pointer to dfs_bin5radars structure.
1489  *
1490  * Reject the pulse if:
1491  * 1) It's outside the RSSI threshold;
1492  * 2) It's outside the pulse duration;
1493  * 3) It's been verified by HW/SW chirp checking
1494  *    and neither of those found a chirp.
1495  */
1496 int dfs_bin5_check_pulse(struct wlan_dfs *dfs,
1497 		struct dfs_event *re,
1498 		struct dfs_bin5radars *br);
1499 
1500 /**
1501  * dfs_bin5_addpulse() - BIN5 add pulse.
1502  * @dfs: Pointer to wlan_dfs structure.
1503  * @br: Pointer to dfs_bin5radars structure.
1504  * @re: Pointer to dfs_event structure.
1505  * @thists: Timestamp.
1506  */
1507 int dfs_bin5_addpulse(struct wlan_dfs *dfs,
1508 		struct dfs_bin5radars *br,
1509 		struct dfs_event *re,
1510 		uint64_t thists);
1511 
1512 /**
1513  * dfs_bin5_check() - BIN5 check.
1514  * @dfs: Pointer to wlan_dfs structure.
1515  *
1516  * If the dfs structure is NULL (which should be illegal if everyting is working
1517  * properly, then signify that a bin5 radar was found.
1518  */
1519 int dfs_bin5_check(struct wlan_dfs *dfs);
1520 
1521 /**
1522  * dfs_check_chirping() - Check chirping.
1523  * @dfs: Pointer to wlan_dfs structure.
1524  * @buf: Phyerr buffer
1525  * @datalen: Phyerr buf length
1526  * @is_ctl: detected on primary channel.
1527  * @is_ext: detected on extension channel.
1528  * @slope: Slope
1529  * @is_dc: DC found
1530  *
1531  * This examines the FFT data contained in the PHY error information to figure
1532  * out whether the pulse is moving across frequencies.
1533  */
1534 int dfs_check_chirping(struct wlan_dfs *dfs,
1535 		void *buf,
1536 		uint16_t datalen,
1537 		int is_ctl,
1538 		int is_ext,
1539 		int *slope,
1540 		int *is_dc);
1541 
1542 /**
1543  * dfs_get_random_bin5_dur() - Get random BIN5 duration.
1544  * @dfs: Pointer to wlan_dfs structure.
1545  * @tstamp: Timestamp.
1546  *
1547  * Chirping pulses may get cut off at DC and report lower durations.
1548  * This function will compute a suitable random duration for each pulse.
1549  * Duration must be between 50 and 100 us, but remember that in
1550  * wlan_process_phyerr() which calls this function, we are dealing with the
1551  * HW reported duration (unconverted). dfs_process_radarevent() will
1552  * actually convert the duration into the correct value.
1553  * This function doesn't take into account whether the hardware
1554  * is operating in 5GHz fast clock mode or not.
1555  * And this function doesn't take into account whether the hardware
1556  * is peregrine or not.
1557  */
1558 int dfs_get_random_bin5_dur(struct wlan_dfs *dfs,
1559 		uint64_t tstamp);
1560 
1561 /**
1562  * dfs_print_delayline() - Prints delayline.
1563  * @dfs: Pointer to wlan_dfs structure.
1564  * @dl: Pointer to dfs_delayline structure.
1565  */
1566 void dfs_print_delayline(struct wlan_dfs *dfs,
1567 		struct dfs_delayline *dl);
1568 
1569 /**
1570  * dfs_print_nol() - Print NOL elements.
1571  * @dfs: Pointer to wlan_dfs structure.
1572  */
1573 void dfs_print_nol(struct wlan_dfs *dfs);
1574 
1575 /**
1576  * dfs_print_filter() - Prints the filter.
1577  * @dfs: Pointer to wlan_dfs structure.
1578  * @rf: Pointer to dfs_filter structure.
1579  */
1580 void dfs_print_filter(struct wlan_dfs *dfs,
1581 		struct dfs_filter *rf);
1582 
1583 /**
1584  * dfs_getchanstate() - Get chan state.
1585  * @dfs: Pointer to wlan_dfs structure.
1586  * @index: To save the index of dfs_radar[]
1587  * @ext_chan_flag: Extension channel flag;
1588  */
1589 struct dfs_state *dfs_getchanstate(struct wlan_dfs *dfs,
1590 		uint8_t *index,
1591 		int ext_ch_flag);
1592 
1593 /**
1594  * dfs_round() - DFS found.
1595  * @val: Convert durations to TSF ticks.
1596  *
1597  * Return: TSF ticks.
1598  */
1599 uint32_t dfs_round(int32_t val);
1600 
1601 /**
1602  * dfs_reset_alldelaylines() - Reset alldelaylines.
1603  * @dfs: Pointer to wlan_dfs structure.
1604  */
1605 #if defined(WLAN_DFS_DIRECT_ATTACH) || defined(WLAN_DFS_PARTIAL_OFFLOAD)
1606 void dfs_reset_alldelaylines(struct wlan_dfs *dfs);
1607 #else
1608 static inline void dfs_reset_alldelaylines(struct wlan_dfs *dfs)
1609 {
1610 }
1611 #endif
1612 
1613 /**
1614  * dfs_reset_delayline() - Clear only a single delay line.
1615  * @dl: Pointer to dfs_delayline structure.
1616  */
1617 void dfs_reset_delayline(struct dfs_delayline *dl);
1618 
1619 /**
1620  * dfs_reset_filter_delaylines() - Reset filter delaylines.
1621  * @dft: Pointer to dfs_filtertype structure.
1622  */
1623 void dfs_reset_filter_delaylines(struct dfs_filtertype *dft);
1624 
1625 /**
1626  * dfs_reset_radarq() - Reset radar queue.
1627  * @dfs: Pointer to wlan_dfs structure.
1628  */
1629 #if defined(WLAN_DFS_DIRECT_ATTACH) || defined(WLAN_DFS_PARTIAL_OFFLOAD)
1630 void dfs_reset_radarq(struct wlan_dfs *dfs);
1631 #else
1632 static inline void dfs_reset_radarq(struct wlan_dfs *dfs)
1633 {
1634 }
1635 #endif
1636 
1637 /**
1638  * dfs_add_pulse() - Adds pulse to the queue.
1639  * @dfs: Pointer to wlan_dfs structure.
1640  * @rf: Pointer to dfs_filter structure.
1641  * @re: Pointer to dfs_event structure.
1642  * @deltaT: deltaT value.
1643  * @this_ts: Last time stamp.
1644  */
1645 void dfs_add_pulse(struct wlan_dfs *dfs,
1646 		struct dfs_filter *rf,
1647 		struct dfs_event *re,
1648 		uint32_t deltaT,
1649 		uint64_t this_ts);
1650 
1651 /**
1652  * dfs_bin_check() - BIN check
1653  * @dfs: Pointer to wlan_dfs structure.
1654  * @rf: Pointer to dfs_filter structure.
1655  * @deltaT: deltaT value.
1656  * @width: Width
1657  * @ext_chan_flag: Extension channel flag.
1658  */
1659 int dfs_bin_check(struct wlan_dfs *dfs,
1660 		struct dfs_filter *rf,
1661 		uint32_t deltaT,
1662 		uint32_t dur,
1663 		int ext_chan_flag);
1664 
1665 /**
1666  * dfs_bin_pri_check() - BIN PRI check
1667  * @dfs: Pointer to wlan_dfs structure.
1668  * @rf: Pointer to dfs_filter structure.
1669  * @dl: Pointer to dfs_delayline structure.
1670  * @score: Primary score.
1671  * @refpri: Current "filter" time for start of pulse in usecs.
1672  * @refdur: Duration value.
1673  * @ext_chan_flag: Extension channel flag.
1674  * @fundamentalpri: Highest PRI.
1675  */
1676 int dfs_bin_pri_check(struct wlan_dfs *dfs,
1677 		struct dfs_filter *rf,
1678 		struct dfs_delayline *dl,
1679 		uint32_t score,
1680 		uint32_t refpri,
1681 		uint32_t refdur,
1682 		int ext_chan_flag,
1683 		int fundamentalpri);
1684 
1685 /**
1686  * dfs_staggered_check() - Detection implementation for staggered PRIs.
1687  * @dfs: Pointer to wlan_dfs structure.
1688  * @rf: Pointer to dfs_filter structure.
1689  * @deltaT: Delta of the Timestamp.
1690  * @width: Duration of radar pulse.
1691  *
1692  * Return: 1 on success and 0 on failure.
1693  */
1694 int dfs_staggered_check(struct wlan_dfs *dfs,
1695 		struct dfs_filter *rf,
1696 		uint32_t deltaT,
1697 		uint32_t width);
1698 
1699 /**
1700  * dfs_get_pri_margin() - Get Primary margin.
1701  * @dfs: Pointer to wlan_dfs structure.
1702  * @is_extchan_detect: Extension channel detect.
1703  * @is_fixed_pattern: Fixed pattern.
1704  *
1705  * For the extension channel, if legacy traffic is present, we see a lot of
1706  * false alarms, so make the PRI margin narrower depending on the busy % for
1707  * the extension channel.
1708  *
1709  * Return: Returns pri_margin.
1710  */
1711 int dfs_get_pri_margin(struct wlan_dfs *dfs,
1712 		int is_extchan_detect,
1713 		int is_fixed_pattern);
1714 
1715 /**
1716  * dfs_get_filter_threshold() - Get filter threshold.
1717  * @dfs: Pointer to wlan_dfs structure.
1718  * @rf: Pointer to dfs_filter structure.
1719  * @is_extchan_detect: Extension channel detect.
1720  *
1721  * For the extension channel, if legacy traffic is present, we see a lot of
1722  * false alarms, so make the thresholds higher depending on the busy % for the
1723  * extension channel.
1724  *
1725  * Return: Returns threshold.
1726  */
1727 int dfs_get_filter_threshold(struct wlan_dfs *dfs,
1728 		struct dfs_filter *rf,
1729 		int is_extchan_detect);
1730 
1731 #if defined(QCA_MCL_DFS_SUPPORT)
1732 /**
1733  * dfs_process_ar_event() - Process the ar event.
1734  * @dfs: Pointer to wlan_dfs structure.
1735  * @chan: Current channel structure.
1736  */
1737 static inline void dfs_process_ar_event(struct wlan_dfs *dfs,
1738 					struct dfs_channel *chan)
1739 {
1740 }
1741 
1742 /**
1743  * dfs_reset_ar() - resets the ar state.
1744  * @dfs: pointer to wlan_dfs structure.
1745  */
1746 static inline void dfs_reset_ar(struct wlan_dfs *dfs)
1747 {
1748 }
1749 
1750 /**
1751  * dfs_reset_arq() - resets the ar queue.
1752  * @dfs: pointer to wlan_dfs structure.
1753  */
1754 static inline void dfs_reset_arq(struct wlan_dfs *dfs)
1755 {
1756 }
1757 
1758 #else
1759 void dfs_process_ar_event(struct wlan_dfs *dfs,
1760 			  struct dfs_channel *chan);
1761 
1762 void dfs_reset_ar(struct wlan_dfs *dfs);
1763 void dfs_reset_arq(struct wlan_dfs *dfs);
1764 #endif
1765 
1766 /**
1767  * dfs_is_radar_enabled() - check if radar detection is enabled.
1768  * @dfs: Pointer to wlan_dfs structure.
1769  * @ignore_dfs: if 1 then radar detection is disabled..
1770  */
1771 #if defined(WLAN_DFS_DIRECT_ATTACH) || defined(WLAN_DFS_PARTIAL_OFFLOAD)
1772 void dfs_is_radar_enabled(struct wlan_dfs *dfs,
1773 			  int *ignore_dfs);
1774 #else
1775 static inline void dfs_is_radar_enabled(struct wlan_dfs *dfs,
1776 					int *ignore_dfs)
1777 {
1778 }
1779 #endif
1780 
1781 /**
1782  * dfs_process_phyerr_bb_tlv() - Parses the PHY error and populates the
1783  *                               dfs_phy_err struct.
1784  * @dfs: Pointer to wlan_dfs structure.
1785  * @buf: Phyerr buffer
1786  * @datalen: Phyerr buf len
1787  * @rssi: RSSI
1788  * @ext_rssi: Extension RSSI.
1789  * @rs_tstamp: Time stamp.
1790  * @fulltsf: TSF64.
1791  * @e: Pointer to dfs_phy_err structure.
1792  *
1793  * Return: Returns 1.
1794  */
1795 int dfs_process_phyerr_bb_tlv(struct wlan_dfs *dfs,
1796 		void *buf,
1797 		uint16_t datalen,
1798 		uint8_t rssi,
1799 		uint8_t ext_rssi,
1800 		uint32_t rs_tstamp,
1801 		uint64_t fulltsf,
1802 		struct dfs_phy_err *e);
1803 
1804 /**
1805  * dfs_reset() - DFS reset
1806  * @dfs: Pointer to wlan_dfs structure.
1807  */
1808 void dfs_reset(struct wlan_dfs *dfs);
1809 
1810 /**
1811  * dfs_radar_enable() - Enables the radar.
1812  * @dfs: Pointer to wlan_dfs structure.
1813  * @no_cac: If no_cac is 0, it cancels the CAC.
1814  */
1815 #if defined(WLAN_DFS_DIRECT_ATTACH) || defined(WLAN_DFS_PARTIAL_OFFLOAD)
1816 void dfs_radar_enable(struct wlan_dfs *dfs,
1817 		int no_cac, uint32_t opmode);
1818 #else
1819 static inline void dfs_radar_enable(struct wlan_dfs *dfs,
1820 		int no_cac, uint32_t opmode)
1821 {
1822 }
1823 #endif
1824 
1825 /**
1826  * dfs_process_phyerr() - Process phyerr.
1827  * @dfs: Pointer to wlan_dfs structure.
1828  * @buf: Phyerr buffer.
1829  * @datalen: phyerr buffer length.
1830  * @r_rssi: RSSI.
1831  * @r_ext_rssi: Extension channel RSSI.
1832  * @r_rs_tstamp: Timestamp.
1833  * @r_fulltsf: TSF64.
1834  */
1835 #if defined(WLAN_DFS_DIRECT_ATTACH) || defined(WLAN_DFS_PARTIAL_OFFLOAD)
1836 void dfs_process_phyerr(struct wlan_dfs *dfs,
1837 		void *buf,
1838 		uint16_t datalen,
1839 		uint8_t r_rssi,
1840 		uint8_t r_ext_rssi,
1841 		uint32_t r_rs_tstamp,
1842 		uint64_t r_fulltsf);
1843 #else
1844 static inline void dfs_process_phyerr(struct wlan_dfs *dfs,
1845 		void *buf,
1846 		uint16_t datalen,
1847 		uint8_t r_rssi,
1848 		uint8_t r_ext_rssi,
1849 		uint32_t r_rs_tstamp,
1850 		uint64_t r_fulltsf)
1851 {
1852 }
1853 #endif
1854 
1855 #ifdef QCA_MCL_DFS_SUPPORT
1856 /**
1857  * dfs_process_phyerr_filter_offload() - Process radar event.
1858  * @dfs: Pointer to wlan_dfs structure.
1859  * @wlan_radar_event: Pointer to radar_event_info structure.
1860  *
1861  * Return: None
1862  */
1863 #if defined(WLAN_DFS_PARTIAL_OFFLOAD)
1864 void dfs_process_phyerr_filter_offload(struct wlan_dfs *dfs,
1865 		struct radar_event_info *wlan_radar_event);
1866 #else
1867 static inline void dfs_process_phyerr_filter_offload(
1868 		struct wlan_dfs *dfs,
1869 		struct radar_event_info *wlan_radar_event)
1870 {
1871 }
1872 #endif
1873 #endif
1874 
1875 /**
1876  * dfs_get_radars() - Based on the chipset, calls init radar table functions.
1877  * @dfs: Pointer to wlan_dfs structure.
1878  */
1879 #if defined(WLAN_DFS_DIRECT_ATTACH) || defined(WLAN_DFS_PARTIAL_OFFLOAD)
1880 void dfs_get_radars(struct wlan_dfs *dfs);
1881 #else
1882 static inline void dfs_get_radars(struct wlan_dfs *dfs)
1883 {
1884 }
1885 #endif
1886 
1887 /**
1888  * dfs_attach() - Wrapper function to allocate memory for wlan_dfs members.
1889  * @dfs: Pointer to wlan_dfs structure.
1890  */
1891 int dfs_attach(struct wlan_dfs *dfs);
1892 
1893 
1894 /**
1895  * dfs_create_object() - Creates DFS object.
1896  * @dfs: Pointer to wlan_dfs structure.
1897  */
1898 int dfs_create_object(struct wlan_dfs **dfs);
1899 
1900 /**
1901  * dfs_destroy_object() - Destroys the DFS object.
1902  * @dfs: Pointer to wlan_dfs structure.
1903  */
1904 void dfs_destroy_object(struct wlan_dfs *dfs);
1905 
1906 /**
1907  * dfs_detach() - Wrapper function to free dfs variables.
1908  * @dfs: Pointer to wlan_dfs structure.
1909  */
1910 void dfs_detach(struct wlan_dfs *dfs);
1911 
1912 /**
1913  * dfs_cac_valid_reset() - Cancels the dfs_cac_valid_timer timer.
1914  * @dfs: Pointer to wlan_dfs structure.
1915  * @prevchan_ieee: Prevchan number.
1916  * @prevchan_flags: Prevchan flags.
1917  */
1918 void dfs_cac_valid_reset(struct wlan_dfs *dfs,
1919 		uint8_t prevchan_ieee,
1920 		uint32_t prevchan_flags);
1921 
1922 /**
1923  * dfs_cac_stop() - Clear the AP CAC timer.
1924  * @dfs: Pointer to wlan_dfs structure.
1925  */
1926 void dfs_cac_stop(struct wlan_dfs *dfs);
1927 
1928 /**
1929  * dfs_cancel_cac_timer() - Cancels the CAC timer.
1930  * @dfs: Pointer to wlan_dfs structure.
1931  */
1932 void dfs_cancel_cac_timer(struct wlan_dfs *dfs);
1933 
1934 /**
1935  * dfs_start_cac_timer() - Starts the CAC timer.
1936  * @dfs: Pointer to wlan_dfs structure.
1937  */
1938 void dfs_start_cac_timer(struct wlan_dfs *dfs);
1939 
1940 /**
1941  * dfs_is_subset_channel() - Check if the new_chan is subset of the old_chan.
1942  * @dfs: Pointer to wlan_dfs structure.
1943  * @old_chan: Pointer to old channel.
1944  * @new_chan: Pointer to new channel.
1945  *
1946  * Return: true if the new channel is subset of or same as the old channel,
1947  * else false.
1948  */
1949 bool dfs_is_subset_channel(struct wlan_dfs *dfs,
1950 			   struct dfs_channel *old_chan,
1951 			   struct dfs_channel *new_chan);
1952 
1953 /**
1954  * dfs_is_curchan_subset_of_cac_started_chan() - Check if the dfs current
1955  * channel is subset of cac started channel.
1956  * @dfs: Pointer to wlan_dfs structure.
1957  *
1958  * If the current channel and the cac_started_chan is same or
1959  * if the current channel is subset of the cac_started_chan then
1960  * this function returns true.
1961  *
1962  * Return: true if current channel is same or subset of  cac started channel,
1963  * else false.
1964  */
1965 bool dfs_is_curchan_subset_of_cac_started_chan(struct wlan_dfs *dfs);
1966 
1967 /**
1968  * dfs_clear_cac_started_chan() - Clear dfs cac started channel.
1969  * @dfs: Pointer to wlan_dfs structure.
1970  */
1971 void dfs_clear_cac_started_chan(struct wlan_dfs *dfs);
1972 
1973 /**
1974  * dfs_set_update_nol_flag() - Sets update_nol flag.
1975  * @dfs: Pointer to wlan_dfs structure.
1976  * @val: update_nol flag.
1977  */
1978 void dfs_set_update_nol_flag(struct wlan_dfs *dfs,
1979 		bool val);
1980 
1981 /**
1982  * dfs_get_update_nol_flag() - Returns update_nol flag.
1983  * @dfs: Pointer to wlan_dfs structure.
1984  */
1985 bool dfs_get_update_nol_flag(struct wlan_dfs *dfs);
1986 
1987 /**
1988  * dfs_get_use_nol() - Get usenol.
1989  * @dfs: Pointer to wlan_dfs structure.
1990  */
1991 int dfs_get_use_nol(struct wlan_dfs *dfs);
1992 
1993 /**
1994  * dfs_get_nol_timeout() - Get NOL timeout.
1995  * @dfs: Pointer to wlan_dfs structure.
1996  */
1997 int dfs_get_nol_timeout(struct wlan_dfs *dfs);
1998 
1999 /**
2000  * dfs_is_ap_cac_timer_running() - Returns the dfs cac timer.
2001  * @dfs: Pointer to wlan_dfs structure.
2002  */
2003 int dfs_is_ap_cac_timer_running(struct wlan_dfs *dfs);
2004 
2005 /**
2006  * dfs_control()- Used to process ioctls related to DFS.
2007  * @dfs: Pointer to wlan_dfs structure.
2008  * @id: Command type.
2009  * @indata: Input buffer.
2010  * @insize: size of the input buffer.
2011  * @outdata: A buffer for the results.
2012  * @outsize: Size of the output buffer.
2013  */
2014 int dfs_control(struct wlan_dfs *dfs,
2015 		u_int id,
2016 		void *indata,
2017 		uint32_t insize,
2018 		void *outdata,
2019 		uint32_t *outsize);
2020 
2021 /**
2022  * dfs_getnol() - Wrapper function for dfs_get_nol()
2023  * @dfs: Pointer to wlan_dfs structure.
2024  * @dfs_nolinfo: Pointer to dfsreq_nolinfo structure.
2025  */
2026 void dfs_getnol(struct wlan_dfs *dfs,
2027 		void *dfs_nolinfo);
2028 
2029 /**
2030  * dfs_get_override_cac_timeout() -  Get override CAC timeout value.
2031  * @dfs: Pointer to DFS object.
2032  * @cac_timeout: Pointer to save the CAC timeout value.
2033  */
2034 int dfs_get_override_cac_timeout(struct wlan_dfs *dfs,
2035 		int *cac_timeout);
2036 
2037 /**
2038  * dfs_override_cac_timeout() -  Override the default CAC timeout.
2039  * @dfs: Pointer to DFS object.
2040  * @cac_timeout: CAC timeout value.
2041  */
2042 int dfs_override_cac_timeout(struct wlan_dfs *dfs,
2043 		int cac_timeout);
2044 
2045 /**
2046  * dfs_clear_nolhistory() - unmarks WLAN_CHAN_CLR_HISTORY_RADAR flag for
2047  *                          all the channels in dfs_ch_channels.
2048  * @dfs: Pointer to wlan_dfs structure.
2049  */
2050 void dfs_clear_nolhistory(struct wlan_dfs *dfs);
2051 
2052 /**
2053  * ol_if_dfs_configure() - Initialize the RADAR table for offload chipsets.
2054  * @dfs: Pointer to wlan_dfs structure.
2055  *
2056  * This is called during a channel change or regulatory domain
2057  * reset; in order to fetch the new configuration information and
2058  * program the DFS pattern matching module.
2059  *
2060  * Eventually this should be split into "fetch config" (which can
2061  * happen at regdomain selection time) and "configure DFS" (which
2062  * can happen at channel config time) so as to minimise overheads
2063  * when doing channel changes.  However, this'll do for now.
2064  */
2065 void ol_if_dfs_configure(struct wlan_dfs *dfs);
2066 
2067 /**
2068  * dfs_init_radar_filters() - Init Radar filters.
2069  * @dfs: Pointer to wlan_dfs structure.
2070  * @radar_info: Pointer to wlan_dfs_radar_tab_info structure.
2071  */
2072 int dfs_init_radar_filters(struct wlan_dfs *dfs,
2073 		struct wlan_dfs_radar_tab_info *radar_info);
2074 
2075 /**
2076  * dfs_get_radars_for_ar5212() - Initialize radar table for AR5212 chipsets.
2077  * @dfs: Pointer to wlan_dfs structure.
2078  */
2079 void dfs_get_radars_for_ar5212(struct wlan_dfs *dfs);
2080 
2081 /**
2082  * dfs_get_radars_for_ar5416() - Initialize radar table for AR5416 chipsets.
2083  * @dfs: Pointer to wlan_dfs structure.
2084  */
2085 void dfs_get_radars_for_ar5416(struct wlan_dfs *dfs);
2086 
2087 /**
2088  * dfs_get_radars_for_ar9300() - Initialize radar table for AR9300 chipsets.
2089  * @dfs: Pointer to wlan_dfs structure.
2090  */
2091 void dfs_get_radars_for_ar9300(struct wlan_dfs *dfs);
2092 
2093 /**
2094  * dfs_print_filters() - Print the filters.
2095  * @dfs: Pointer to wlan_dfs structure.
2096  */
2097 void dfs_print_filters(struct wlan_dfs *dfs);
2098 
2099 /**
2100  * dfs_clear_stats() - Clear stats.
2101  * @dfs: Pointer to wlan_dfs structure.
2102  */
2103 void dfs_clear_stats(struct wlan_dfs *dfs);
2104 
2105 /**
2106  * dfs_radar_disable() - Disables the radar.
2107  * @dfs: Pointer to wlan_dfs structure.
2108  */
2109 #if defined(WLAN_DFS_DIRECT_ATTACH) || defined(WLAN_DFS_PARTIAL_OFFLOAD)
2110 int dfs_radar_disable(struct wlan_dfs *dfs);
2111 #else
2112 static inline int dfs_radar_disable(struct wlan_dfs *dfs)
2113 {
2114 	return 0;
2115 }
2116 #endif
2117 
2118 /**
2119  * dfs_get_debug_info() - Get debug info.
2120  * @dfs: Pointer to wlan_dfs structure.
2121  * @data: void pointer to the data to save dfs_proc_phyerr.
2122  */
2123 int dfs_get_debug_info(struct wlan_dfs *dfs,
2124 		void *data);
2125 
2126 /**
2127  * dfs_cac_timer_init() - Initialize cac timers.
2128  * @dfs: Pointer to wlan_dfs structure.
2129  */
2130 void dfs_cac_timer_init(struct wlan_dfs *dfs);
2131 
2132 /**
2133  * dfs_cac_attach() - Initialize dfs cac variables.
2134  * @dfs: Pointer to wlan_dfs structure.
2135  */
2136 void dfs_cac_attach(struct wlan_dfs *dfs);
2137 
2138 /**
2139  * dfs_cac_timer_reset() - Cancel dfs cac timers.
2140  * @dfs: Pointer to wlan_dfs structure.
2141  */
2142 void dfs_cac_timer_reset(struct wlan_dfs *dfs);
2143 
2144 /**
2145  * dfs_cac_timer_detach() - Free dfs cac timers.
2146  * @dfs: Pointer to wlan_dfs structure.
2147  */
2148 void dfs_cac_timer_detach(struct wlan_dfs *dfs);
2149 
2150 /**
2151  * dfs_nol_timer_init() - Initialize NOL timers.
2152  * @dfs: Pointer to wlan_dfs structure.
2153  */
2154 void dfs_nol_timer_init(struct wlan_dfs *dfs);
2155 
2156 /**
2157  * dfs_nol_attach() - Initialize NOL variables.
2158  * @dfs: Pointer to wlan_dfs structure.
2159  */
2160 void dfs_nol_attach(struct wlan_dfs *dfs);
2161 
2162 /**
2163  * dfs_nol_detach() - Detach NOL variables.
2164  * @dfs: Pointer to wlan_dfs structure.
2165  */
2166 void dfs_nol_detach(struct wlan_dfs *dfs);
2167 
2168 /**
2169  * dfs_print_nolhistory() - Print NOL history.
2170  * @dfs: Pointer to wlan_dfs structure.
2171  */
2172 void dfs_print_nolhistory(struct wlan_dfs *dfs);
2173 
2174 /**
2175  * dfs_stacac_stop() - Clear the STA CAC timer.
2176  * @dfs: Pointer to wlan_dfs structure.
2177  */
2178 void dfs_stacac_stop(struct wlan_dfs *dfs);
2179 
2180 /**
2181  * dfs_find_precac_secondary_vht80_chan() - Get a VHT80 channel with the
2182  *                                          precac primary center frequency.
2183  * @dfs: Pointer to wlan_dfs structure.
2184  * @chan: Pointer to dfs channel structure.
2185  */
2186 void dfs_find_precac_secondary_vht80_chan(struct wlan_dfs *dfs,
2187 		struct dfs_channel *chan);
2188 
2189 #ifdef WLAN_DFS_PRECAC_AUTO_CHAN_SUPPORT
2190 /**
2191  * dfs_precac_csa() - Automatically switch the channel to the DFS channel
2192  *			on which PreCAC was completed without finding a RADAR.
2193  *			Use CSA with TBTT_COUNT to switch the channel.
2194  * @dfs: Pointer to dfs handler.
2195  *
2196  * Return: Void
2197  */
2198 void dfs_precac_csa(struct wlan_dfs *dfs);
2199 #endif
2200 
2201 /**
2202  * dfs_phyerr_param_copy() - Function to copy src buf to dest buf.
2203  * @dst: dest buf.
2204  * @src: src buf.
2205  */
2206 void dfs_phyerr_param_copy(struct wlan_dfs_phyerr_param *dst,
2207 		struct wlan_dfs_phyerr_param *src);
2208 
2209 /**
2210  * dfs_get_thresholds() - Get the threshold value.
2211  * @dfs: Pointer to wlan_dfs structure.
2212  * @param: Pointer to wlan_dfs_phyerr_param structure.
2213  */
2214 #if defined(WLAN_DFS_DIRECT_ATTACH) || defined(WLAN_DFS_PARTIAL_OFFLOAD)
2215 int dfs_get_thresholds(struct wlan_dfs *dfs,
2216 		struct wlan_dfs_phyerr_param *param);
2217 #else
2218 static inline int dfs_get_thresholds(struct wlan_dfs *dfs,
2219 		struct wlan_dfs_phyerr_param *param)
2220 {
2221 		return 0;
2222 }
2223 #endif
2224 
2225 /**
2226  * dfs_set_thresholds() - Sets the threshold value.
2227  * @dfs: Pointer to wlan_dfs structure.
2228  * @threshtype: DFS ioctl param type.
2229  * @value: Threshold value.
2230  */
2231 #if defined(WLAN_DFS_DIRECT_ATTACH) || defined(WLAN_DFS_PARTIAL_OFFLOAD)
2232 int dfs_set_thresholds(struct wlan_dfs *dfs,
2233 		const uint32_t threshtype,
2234 		const uint32_t value);
2235 #else
2236 static inline int dfs_set_thresholds(struct wlan_dfs *dfs,
2237 		const uint32_t threshtype,
2238 		const uint32_t value)
2239 {
2240 		return 0;
2241 }
2242 #endif
2243 
2244 /**
2245  * dfs_check_intersect_excl() - Check whether curfreq falls within lower_freq
2246  * and upper_freq, exclusively.
2247  * @low_freq : lower bound frequency value.
2248  * @high_freq: upper bound frequency value.
2249  * @chan_freq: Current frequency value to be checked.
2250  *
2251  * Return: returns true if overlap found, else returns false.
2252  */
2253 #if defined(WLAN_DFS_DIRECT_ATTACH) || defined(WLAN_DFS_PARTIAL_OFFLOAD)
2254 bool dfs_check_intersect_excl(int low_freq, int high_freq, int chan_freq);
2255 #else
2256 static inline bool dfs_check_intersect_excl(int low_freq, int high_freq,
2257 					    int chan_freq)
2258 {
2259 		return false;
2260 }
2261 #endif
2262 
2263 /**
2264  * dfs_check_etsi_overlap() - Check whether given frequency centre/channel
2265  * width entry overlap with frequency spread in any way.
2266  * @center_freq         : current channel centre frequency.
2267  * @chan_width          : current channel width.
2268  * @en302_502_freq_low  : overlap frequency lower bound.
2269  * @en302_502_freq_high : overlap frequency upper bound.
2270  *
2271  * Return: returns 1 if overlap found, else returns 0.
2272  */
2273 #if defined(WLAN_DFS_DIRECT_ATTACH) || defined(WLAN_DFS_PARTIAL_OFFLOAD)
2274 int dfs_check_etsi_overlap(int center_freq, int chan_width,
2275 			   int en302_502_freq_low, int en302_502_freq_high);
2276 #else
2277 static inline int dfs_check_etsi_overlap(int center_freq, int chan_width,
2278 					 int en302_502_freq_low,
2279 					 int en302_502_freq_high)
2280 {
2281 		return 0;
2282 }
2283 #endif
2284 
2285 /**
2286  * dfs_is_en302_502_applicable() - Check whether current channel frequecy spread
2287  *					overlaps with EN 302 502 radar type
2288  *					frequency range.
2289  *@dfs: Pointer to wlan_dfs structure.
2290  *
2291  * Return: returns true if overlap found, else returns false.
2292  */
2293 #if defined(WLAN_DFS_DIRECT_ATTACH) || defined(WLAN_DFS_PARTIAL_OFFLOAD)
2294 bool dfs_is_en302_502_applicable(struct wlan_dfs *dfs);
2295 #else
2296 static inline bool dfs_is_en302_502_applicable(struct wlan_dfs *dfs)
2297 {
2298 		return false;
2299 }
2300 #endif
2301 
2302 /**
2303  * dfs_set_current_channel() - Set DFS current channel.
2304  * @dfs: Pointer to wlan_dfs structure.
2305  * @dfs_ch_freq: Frequency in Mhz.
2306  * @dfs_ch_flags: Channel flags.
2307  * @dfs_ch_flagext: Extended channel flags.
2308  * @dfs_ch_ieee: IEEE channel number.
2309  * @dfs_ch_vhtop_ch_freq_seg1: Channel Center frequency1.
2310  * @dfs_ch_vhtop_ch_freq_seg2: Channel Center frequency2.
2311  */
2312 void dfs_set_current_channel(struct wlan_dfs *dfs,
2313 		uint16_t dfs_ch_freq,
2314 		uint64_t dfs_ch_flags,
2315 		uint16_t dfs_ch_flagext,
2316 		uint8_t dfs_ch_ieee,
2317 		uint8_t dfs_ch_vhtop_ch_freq_seg1,
2318 		uint8_t dfs_ch_vhtop_ch_freq_seg2);
2319 
2320 /**
2321  * dfs_get_nol_chfreq_and_chwidth() - Get channel freq and width from NOL list.
2322  * @dfs_nol: Pointer to NOL channel entry.
2323  * @nol_chfreq: Pointer to save channel frequency.
2324  * @nol_chwidth: Pointer to save channel width.
2325  * @index: Index to dfs_nol list.
2326  */
2327 void dfs_get_nol_chfreq_and_chwidth(struct dfsreq_nolelem *dfs_nol,
2328 		uint32_t *nol_chfreq,
2329 		uint32_t *nol_chwidth,
2330 		int index);
2331 
2332 /**
2333  * dfs_process_phyerr_owl() - Process an Owl-style phy error.
2334  * @dfs: Pointer to wlan_dfs structure.
2335  * @buf: Phyerr buffer
2336  * @datalen: Phyerr buf len
2337  * @rssi: RSSI
2338  * @ext_rssi: Extension RSSI.
2339  * @rs_tstamp: Time stamp.
2340  * @fulltsf: TSF64.
2341  * @e: Pointer to dfs_phy_err structure.
2342  *
2343  * Return: Returns 1.
2344  */
2345 int dfs_process_phyerr_owl(struct wlan_dfs *dfs,
2346 		void *buf,
2347 		uint16_t datalen,
2348 		uint8_t rssi,
2349 		uint8_t ext_rssi,
2350 		uint32_t rs_tstamp,
2351 		uint64_t fulltsf,
2352 		struct dfs_phy_err *e);
2353 
2354 /**
2355  * dfs_process_phyerr_sowl() -Process a Sowl/Howl style phy error.
2356  * @dfs: Pointer to wlan_dfs structure.
2357  * @buf: Phyerr buffer
2358  * @datalen: Phyerr buf len
2359  * @rssi: RSSI
2360  * @ext_rssi: Extension RSSI.
2361  * @rs_tstamp: Time stamp.
2362  * @fulltsf: TSF64.
2363  * @e: Pointer to dfs_phy_err structure.
2364  *
2365  * Return: Returns 1.
2366  */
2367 int dfs_process_phyerr_sowl(struct wlan_dfs *dfs,
2368 		void *buf,
2369 		uint16_t datalen,
2370 		uint8_t rssi,
2371 		uint8_t ext_rssi,
2372 		uint32_t rs_tstamp,
2373 		uint64_t fulltsf,
2374 		struct dfs_phy_err *e);
2375 
2376 /**
2377  * dfs_process_phyerr_merlin() - Process a Merlin/Osprey style phy error.
2378  *                               dfs_phy_err struct.
2379  * @dfs: Pointer to wlan_dfs structure.
2380  * @buf: Phyerr buffer
2381  * @datalen: Phyerr buf len
2382  * @rssi: RSSI
2383  * @ext_rssi: Extension RSSI.
2384  * @rs_tstamp: Time stamp.
2385  * @fulltsf: TSF64.
2386  * @e: Pointer to dfs_phy_err structure.
2387  *
2388  * Return: Returns 1.
2389  */
2390 int dfs_process_phyerr_merlin(struct wlan_dfs *dfs,
2391 		void *buf,
2392 		uint16_t datalen,
2393 		uint8_t rssi,
2394 		uint8_t ext_rssi,
2395 		uint32_t rs_tstamp,
2396 		uint64_t fulltsf,
2397 		struct dfs_phy_err *e);
2398 
2399 /*
2400  * __dfs_process_radarevent() - Continuation of process a radar event function.
2401  * @dfs: Pointer to wlan_dfs structure.
2402  * @ft: Pointer to dfs_filtertype structure.
2403  * @re: Pointer to dfs_event structure.
2404  * @this_ts: Timestamp.
2405  *
2406  * There is currently no way to specify that a radar event has occurred on
2407  * a specific channel, so the current methodology is to mark both the pri
2408  * and ext channels as being unavailable.  This should be fixed for 802.11ac
2409  * or we'll quickly run out of valid channels to use.
2410  *
2411  * Return: If a radar event is found, return 1.  Otherwise, return 0.
2412  */
2413 void __dfs_process_radarevent(struct wlan_dfs *dfs,
2414 		struct dfs_filtertype *ft,
2415 		struct dfs_event *re,
2416 		uint64_t this_ts,
2417 		int *found,
2418 		int *false_radar_found);
2419 
2420 /**
2421  * dfs_radar_found_action() - Radar found action
2422  * @dfs: Pointer to wlan_dfs structure.
2423  * @bangradar: true if radar is due to bangradar command.
2424  * @seg_id: Segment id.
2425  */
2426 void dfs_radar_found_action(struct wlan_dfs *dfs,
2427 			    bool bangradar,
2428 			    uint8_t seg_id);
2429 
2430 /**
2431  * bin5_rules_check_internal() - This is a extension of dfs_bin5_check().
2432  * @dfs: Pointer to wlan_dfs structure.
2433  * @br: Pointer to dfs_bin5radars structure.
2434  * @bursts: Bursts.
2435  * @numevents: Number of events.
2436  * @prev: prev index.
2437  * @i: Index.
2438  * @this: index to br_elems[]
2439  */
2440 void bin5_rules_check_internal(struct wlan_dfs *dfs,
2441 		struct dfs_bin5radars *br,
2442 		uint32_t *bursts,
2443 		uint32_t *numevents,
2444 		uint32_t prev,
2445 		uint32_t i,
2446 		uint32_t this,
2447 		int *index);
2448 
2449 /**
2450  * dfs_main_task_testtimer_init() - Initialize dfs task testtimer.
2451  * @dfs: Pointer to wlan_dfs structure.
2452  */
2453 void dfs_main_task_testtimer_init(struct wlan_dfs *dfs);
2454 
2455 /**
2456  * dfs_stop() - Clear dfs timers.
2457  * @dfs: Pointer to wlan_dfs structure.
2458  */
2459 void dfs_stop(struct wlan_dfs *dfs);
2460 
2461 /**
2462  * dfs_update_cur_chan_flags() - Update DFS channel flag and flagext.
2463  * @dfs: Pointer to wlan_dfs structure.
2464  * @flags: New channel flags
2465  * @flagext: New Extended flags
2466  */
2467 void dfs_update_cur_chan_flags(struct wlan_dfs *dfs,
2468 		uint64_t flags,
2469 		uint16_t flagext);
2470 
2471 /**
2472  * dfs_radarevent_basic_sanity() - Check basic sanity of the radar event
2473  * @dfs: Pointer to wlan_dfs structure.
2474  * @chan: Current channel.
2475  *
2476  * Return: If a radar event found on NON-DFS channel  return 0.  Otherwise,
2477  * return 1.
2478  */
2479 int dfs_radarevent_basic_sanity(struct wlan_dfs *dfs,
2480 		struct dfs_channel *chan);
2481 
2482 /**
2483  * wlan_psoc_get_dfs_txops() - Get dfs_tx_ops pointer
2484  * @psoc: Pointer to psoc structure.
2485  *
2486  * Return: Pointer to dfs_tx_ops.
2487  */
2488 struct wlan_lmac_if_dfs_tx_ops *
2489 wlan_psoc_get_dfs_txops(struct wlan_objmgr_psoc *psoc);
2490 
2491 /**
2492  * dfs_nol_free_list() - Free NOL elements.
2493  * @dfs: Pointer to wlan_dfs structure.
2494  */
2495 void dfs_nol_free_list(struct wlan_dfs *dfs);
2496 
2497 /**
2498  * dfs_second_segment_radar_disable() - Disables the second segment radar.
2499  * @dfs: Pointer to wlan_dfs structure.
2500  *
2501  * This is called when AP detects the radar, to (potentially) disable
2502  * the radar code.
2503  *
2504  * Return: returns 0.
2505  */
2506 int dfs_second_segment_radar_disable(struct wlan_dfs *dfs);
2507 
2508 /**
2509  * dfs_fetch_nol_ie_info() - Fill NOL information to be sent with RCSA.
2510  * @dfs                    - Pointer to wlan_dfs structure.
2511  * @nol_ie_bandwidth       - Minimum subchannel bandwidth.
2512  * @nol_ie_startfreq       - Radar affected channel list's first subchannel's
2513  *                         - centre frequency.
2514  * @nol_ie_bitmap          - NOL bitmap denoting affected subchannels.
2515  */
2516 void dfs_fetch_nol_ie_info(struct wlan_dfs *dfs, uint8_t *nol_ie_bandwidth,
2517 			   uint16_t *nol_ie_startfreq, uint8_t *nol_ie_bitmap);
2518 
2519 /**
2520  * dfs_set_rcsa_flags() - Set flags that are required for sending RCSA and
2521  * NOL IE.
2522  * @dfs: Pointer to wlan_dfs structure.
2523  * @is_rcsa_ie_sent: Boolean to check if RCSA IE should be sent or not.
2524  * @is_nol_ie_sent: Boolean to check if NOL IE should be sent or not.
2525  */
2526 void dfs_set_rcsa_flags(struct wlan_dfs *dfs, bool is_rcsa_ie_sent,
2527 			bool is_nol_ie_sent);
2528 
2529 /**
2530  * dfs_get_rcsa_flags() - Get flags that are required for sending RCSA and
2531  * NOL IE.
2532  * @dfs: Pointer to wlan_dfs structure.
2533  * @is_rcsa_ie_sent: Boolean to check if RCSA IE should be sent or not.
2534  * @is_nol_ie_sent: Boolean to check if NOL IE should be sent or not.
2535  */
2536 void dfs_get_rcsa_flags(struct wlan_dfs *dfs, bool *is_rcsa_ie_sent,
2537 			bool *is_nol_ie_sent);
2538 
2539 /**
2540  * dfs_process_nol_ie_bitmap() - Update NOL with external radar information.
2541  * @dfs               - Pointer to wlan_dfs structure.
2542  * @nol_ie_bandwidth  - Minimum subchannel bandwidth.
2543  * @nol_ie_starfreq   - Radar affected channel list's first subchannel's
2544  *                    - centre frequency.
2545  * @nol_ie_bitmap     - Bitmap denoting radar affected subchannels.
2546  *
2547  * Return: True if NOL IE should be propagated, else false.
2548  */
2549 bool dfs_process_nol_ie_bitmap(struct wlan_dfs *dfs, uint8_t nol_ie_bandwidth,
2550 			       uint16_t nol_ie_startfreq,
2551 			       uint8_t nol_ie_bitmap);
2552 
2553 /**
2554  * dfs_check_for_cac_start() - Check for DFS CAC start conditions.
2555  * @dfs: Pointer to wlan_dfs structure.
2556  * @continue_current_cac: If AP can start CAC then this variable indicates
2557  * whether to continue with the current CAC or restart the CAC. This variable
2558  * is valid only if this function returns true.
2559  *
2560  * Return: true if AP can start or continue the current CAC, else false.
2561  */
2562 bool dfs_check_for_cac_start(struct wlan_dfs *dfs,
2563 			     bool *continue_current_cac);
2564 
2565 /**
2566  * dfs_task_testtimer_reset() - stop dfs test timer.
2567  * @dfs: Pointer to wlan_dfs structure.
2568  */
2569 void dfs_task_testtimer_reset(struct wlan_dfs *dfs);
2570 
2571 /**
2572  * dfs_freq_is_in_nol() - check if given channel in nol list
2573  * @dfs: Pointer to wlan_dfs structure
2574  * @freq: channel frequency
2575  *
2576  * check if given channel in nol list.
2577  *
2578  * Return: true if channel in nol, false else
2579  */
2580 bool dfs_freq_is_in_nol(struct wlan_dfs *dfs, uint32_t freq);
2581 
2582 /**
2583  * dfs_task_testtimer_detach() - Free dfs test timer.
2584  * @dfs: Pointer to wlan_dfs structure.
2585  */
2586 void dfs_task_testtimer_detach(struct wlan_dfs *dfs);
2587 
2588 /**
2589  * dfs_timer_detach() - Free dfs timers.
2590  * @dfs: Pointer to wlan_dfs structure.
2591  */
2592 void dfs_timer_detach(struct wlan_dfs *dfs);
2593 
2594 /**
2595  * dfs_is_disable_radar_marking_set() - Check if radar marking is set on
2596  * NOL chan.
2597  * @dfs: Pointer to wlan_dfs structure.
2598  */
2599 #if defined(WLAN_DFS_FULL_OFFLOAD) && defined(QCA_DFS_NOL_OFFLOAD)
2600 int dfs_is_disable_radar_marking_set(struct wlan_dfs *dfs,
2601 				     bool *disable_radar_marking);
2602 #else
2603 static inline int dfs_is_disable_radar_marking_set(struct wlan_dfs *dfs,
2604 						   bool *disable_radar_marking)
2605 {
2606 	return QDF_STATUS_SUCCESS;
2607 }
2608 #endif
2609 /**
2610  * dfs_get_disable_radar_marking() - Get the value of disable radar marking.
2611  * @dfs: Pointer to wlan_dfs structure.
2612  */
2613 #if defined(WLAN_DFS_FULL_OFFLOAD) && defined(QCA_DFS_NOL_OFFLOAD)
2614 bool dfs_get_disable_radar_marking(struct wlan_dfs *dfs);
2615 #endif
2616 #endif  /* _DFS_H_ */
2617