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