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