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