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