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