1 /* 2 * Copyright (c) 2013, 2016-2018 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2002-2010, 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 contains the functionality to process the radar event generated 20 * for a pulse. This will group together pulses and call various detection 21 * functions to figure out whether a valid radar has been detected. 22 */ 23 24 #include "../dfs.h" 25 #include "../dfs_zero_cac.h" 26 #include "../dfs_channel.h" 27 #include "../dfs_internal.h" 28 #include "../dfs_process_radar_found_ind.h" 29 #include "wlan_dfs_utils_api.h" 30 #include "wlan_dfs_lmac_api.h" 31 #include "../dfs_partial_offload_radar.h" 32 33 #define FREQ_5500_MHZ 5500 34 #define FREQ_5500_MHZ 5500 35 36 #define DFS_MAX_FREQ_SPREAD (1375 * 1) 37 #define DFS_LARGE_PRI_MULTIPLIER 4 38 #define DFS_W53_DEFAULT_PRI_MULTIPLIER 2 39 #define DFS_INVALID_PRI_LIMIT 100 /* should we use 135? */ 40 #define DFS_BIG_SIDX 10000 41 42 #define FRAC_PRI_SCORE_ARRAY_SIZE 40 43 44 static char debug_dup[33]; 45 static int debug_dup_cnt; 46 47 /** 48 * dfs_process_pulse_dur() - Process pulse duration. 49 * @dfs: Pointer to wlan_dfs structure. 50 * @re_dur: Duration. 51 * 52 * Convert the hardware provided duration to TSF ticks (usecs) taking the clock 53 * (fast or normal) into account. Legacy (pre-11n, Owl, Sowl, Howl) operate 54 * 5GHz using a 40MHz clock. Later 11n chips (Merlin, Osprey, etc) operate 55 * 5GHz using a 44MHz clock, so the reported pulse durations are different. 56 * Peregrine reports the pulse duration in microseconds regardless of the 57 * operating mode. (XXX TODO: verify this, obviously.) 58 * 59 * The hardware returns the duration in a variety of formats, 60 * so it's converted from the hardware format to TSF (usec) 61 * values here. 62 * XXX TODO: this should really be done when the PHY error 63 * is processed, rather than way out here.. 64 * 65 * 66 * Return: Returns the duration. 67 */ 68 static inline uint8_t dfs_process_pulse_dur(struct wlan_dfs *dfs, 69 uint8_t re_dur) 70 { 71 /* 72 * Short pulses are sometimes returned as having a duration of 0, 73 * so round those up to 1. 74 * XXX This holds true for BB TLV chips too, right? 75 */ 76 if (re_dur == 0) 77 return 1; 78 79 /* 80 * For BB TLV chips, the hardware always returns microsecond pulse 81 * durations. 82 */ 83 if (dfs->dfs_caps.wlan_chip_is_bb_tlv) 84 return re_dur; 85 86 /* 87 * This is for 11n and legacy chips, which may or may not use the 5GHz 88 * fast clock mode. 89 */ 90 /* Convert 0.8us durations to TSF ticks (usecs) */ 91 return (uint8_t)dfs_round((int32_t)((dfs->dur_multiplier)*re_dur)); 92 } 93 94 /* 95 * dfs_print_radar_events() - Prints the Radar events. 96 * @dfs: Pointer to wlan_dfs structure. 97 */ 98 static void dfs_print_radar_events(struct wlan_dfs *dfs) 99 { 100 int i; 101 102 dfs_info(dfs, WLAN_DEBUG_DFS_ALWAYS, "#Phyerr=%d, #false detect=%d, #queued=%d", 103 dfs->dfs_phyerr_count, dfs->dfs_phyerr_reject_count, 104 dfs->dfs_phyerr_queued_count); 105 106 dfs_info(dfs, WLAN_DEBUG_DFS_ALWAYS, "dfs_phyerr_freq_min=%d, dfs_phyerr_freq_max=%d", 107 dfs->dfs_phyerr_freq_min, dfs->dfs_phyerr_freq_max); 108 109 dfs_info(dfs, WLAN_DEBUG_DFS_ALWAYS, 110 "Total radar events detected=%d, entries in the radar queue follows:", 111 dfs->dfs_event_log_count); 112 113 for (i = 0; (i < DFS_EVENT_LOG_SIZE) && (i < dfs->dfs_event_log_count); 114 i++) { 115 dfs_debug(dfs, WLAN_DEBUG_DFS, 116 "ts=%llu diff_ts=%u rssi=%u dur=%u, is_chirp=%d, seg_id=%d, sidx=%d, freq_offset=%d.%dMHz, peak_mag=%d, total_gain=%d, mb_gain=%d, relpwr_db=%d, delta_diff=%d, delta_peak=%d, psidx_diff=%d", 117 dfs->radar_log[i].ts, dfs->radar_log[i].diff_ts, 118 dfs->radar_log[i].rssi, dfs->radar_log[i].dur, 119 dfs->radar_log[i].is_chirp, dfs->radar_log[i].seg_id, 120 dfs->radar_log[i].sidx, 121 (int)dfs->radar_log[i].freq_offset_khz/1000, 122 (int)abs(dfs->radar_log[i].freq_offset_khz)%1000, 123 dfs->radar_log[i].peak_mag, 124 dfs->radar_log[i].total_gain, 125 dfs->radar_log[i].mb_gain, 126 dfs->radar_log[i].relpwr_db, 127 dfs->radar_log[i].delta_diff, 128 dfs->radar_log[i].delta_peak, 129 dfs->radar_log[i].psidx_diff); 130 } 131 dfs->dfs_event_log_count = 0; 132 dfs->dfs_phyerr_count = 0; 133 dfs->dfs_phyerr_reject_count = 0; 134 dfs->dfs_phyerr_queued_count = 0; 135 dfs->dfs_phyerr_freq_min = 0x7fffffff; 136 dfs->dfs_phyerr_freq_max = 0; 137 } 138 139 /** 140 * dfs_confirm_radar() - This function checks for fractional PRI and jitter in 141 * sidx index to determine if the radar is real or not. 142 * @dfs: Pointer to dfs structure. 143 * @rf: Pointer to dfs_filter structure. 144 * @ext_chan_flag: ext chan flags. 145 */ 146 static int dfs_confirm_radar(struct wlan_dfs *dfs, 147 struct dfs_filter *rf, 148 int ext_chan_flag) 149 { 150 int i = 0; 151 int index; 152 struct dfs_delayline *dl = &rf->rf_dl; 153 struct dfs_delayelem *de; 154 uint64_t target_ts = 0; 155 struct dfs_pulseline *pl; 156 int start_index = 0, current_index, next_index; 157 unsigned char scores[FRAC_PRI_SCORE_ARRAY_SIZE]; 158 uint32_t pri_margin; 159 uint64_t this_diff_ts; 160 uint32_t search_bin; 161 162 unsigned char max_score = 0; 163 int max_score_index = 0; 164 165 pl = dfs->pulses; 166 167 OS_MEMZERO(scores, sizeof(scores)); 168 scores[0] = rf->rf_threshold; 169 170 pri_margin = dfs_get_pri_margin(dfs, ext_chan_flag, 171 (rf->rf_patterntype == 1)); 172 173 /* 174 * Look for the entry that matches dl_seq_num_second. 175 * we need the time stamp and diff_ts from there. 176 */ 177 178 for (i = 0; i < dl->dl_numelems; i++) { 179 index = (dl->dl_firstelem + i) & DFS_MAX_DL_MASK; 180 de = &dl->dl_elems[index]; 181 if (dl->dl_seq_num_second == de->de_seq_num) 182 target_ts = de->de_ts - de->de_time; 183 } 184 185 if (dfs->dfs_debug_mask & WLAN_DEBUG_DFS2) { 186 dfs_print_delayline(dfs, &rf->rf_dl); 187 188 /* print pulse line */ 189 dfs_debug(dfs, WLAN_DEBUG_DFS2, 190 "%s: Pulse Line\n", __func__); 191 for (i = 0; i < pl->pl_numelems; i++) { 192 index = (pl->pl_firstelem + i) & 193 DFS_MAX_PULSE_BUFFER_MASK; 194 dfs_debug(dfs, WLAN_DEBUG_DFS2, 195 "Elem %u: ts=%llu dur=%u, seq_num=%d, delta_peak=%d, psidx_diff=%d\n", 196 i, pl->pl_elems[index].p_time, 197 pl->pl_elems[index].p_dur, 198 pl->pl_elems[index].p_seq_num, 199 pl->pl_elems[index].p_delta_peak, 200 pl->pl_elems[index].p_psidx_diff); 201 } 202 } 203 204 /* 205 * Walk through the pulse line and find pulse with target_ts. 206 * Then continue until we find entry with seq_number dl_seq_num_stop. 207 */ 208 209 for (i = 0; i < pl->pl_numelems; i++) { 210 index = (pl->pl_firstelem + i) & DFS_MAX_PULSE_BUFFER_MASK; 211 if (pl->pl_elems[index].p_time == target_ts) { 212 dl->dl_seq_num_start = pl->pl_elems[index].p_seq_num; 213 start_index = index; /* save for future use */ 214 } 215 } 216 217 dfs_debug(dfs, WLAN_DEBUG_DFS2, 218 "%s: target_ts=%llu, dl_seq_num_start=%d, dl_seq_num_second=%d, dl_seq_num_stop=%d\n", 219 __func__, target_ts, dl->dl_seq_num_start, 220 dl->dl_seq_num_second, dl->dl_seq_num_stop); 221 222 current_index = start_index; 223 while (pl->pl_elems[current_index].p_seq_num < dl->dl_seq_num_stop) { 224 next_index = (current_index + 1) & DFS_MAX_PULSE_BUFFER_MASK; 225 this_diff_ts = pl->pl_elems[next_index].p_time - 226 pl->pl_elems[current_index].p_time; 227 228 /* Now update the score for this diff_ts */ 229 for (i = 1; i < FRAC_PRI_SCORE_ARRAY_SIZE; i++) { 230 search_bin = dl->dl_search_pri / (i + 1); 231 232 /* 233 * We do not give score to PRI that is lower then the 234 * limit. 235 */ 236 if (search_bin < DFS_INVALID_PRI_LIMIT) 237 break; 238 239 /* 240 * Increment the score if this_diff_ts belongs to this 241 * search_bin +/- margin. 242 */ 243 if ((this_diff_ts >= (search_bin - pri_margin)) && 244 (this_diff_ts <= 245 (search_bin + pri_margin))) { 246 /*increment score */ 247 scores[i]++; 248 } 249 } 250 current_index = next_index; 251 } 252 253 for (i = 0; i < FRAC_PRI_SCORE_ARRAY_SIZE; i++) 254 if (scores[i] > max_score) { 255 max_score = scores[i]; 256 max_score_index = i; 257 } 258 259 if (max_score_index != 0) { 260 dfs_debug(dfs, WLAN_DEBUG_DFS_ALWAYS, 261 "Rejecting Radar since Fractional PRI detected: searchpri=%d, threshold=%d, fractional PRI=%d, Fractional PRI score=%d", 262 dl->dl_search_pri, scores[0], 263 dl->dl_search_pri/(max_score_index + 1), 264 max_score); 265 return 0; 266 } 267 268 269 /* Check for frequency spread */ 270 if (dl->dl_min_sidx > pl->pl_elems[start_index].p_sidx) 271 dl->dl_min_sidx = pl->pl_elems[start_index].p_sidx; 272 273 if (dl->dl_max_sidx < pl->pl_elems[start_index].p_sidx) 274 dl->dl_max_sidx = pl->pl_elems[start_index].p_sidx; 275 276 if ((dl->dl_max_sidx - dl->dl_min_sidx) > rf->rf_sidx_spread) { 277 dfs_debug(dfs, WLAN_DEBUG_DFS_ALWAYS, 278 "Rejecting Radar since frequency spread is too large : min_sidx=%d, max_sidx=%d, rf_sidx_spread=%d", 279 dl->dl_min_sidx, dl->dl_max_sidx, 280 rf->rf_sidx_spread); 281 return 0; 282 } 283 284 if ((rf->rf_check_delta_peak) && 285 ((dl->dl_delta_peak_match_count + 286 dl->dl_psidx_diff_match_count - 1) < 287 rf->rf_threshold)) { 288 dfs_debug(dfs, WLAN_DEBUG_DFS_ALWAYS, 289 "Rejecting Radar since delta peak values are invalid : dl_delta_peak_match_count=%d, dl_psidx_diff_match_count=%d, rf_threshold=%d", 290 dl->dl_delta_peak_match_count, 291 dl->dl_psidx_diff_match_count, 292 rf->rf_threshold); 293 return 0; 294 } 295 dfs_debug(dfs, WLAN_DEBUG_DFS_FALSE_DET, "%s : dl->dl_min_sidx: %d , dl->dl_max_sidx :%d", 296 __func__, dl->dl_min_sidx, dl->dl_max_sidx); 297 298 dfs->dfs_freq_offset = DFS_SIDX_TO_FREQ_OFFSET((dl->dl_min_sidx + 299 dl->dl_max_sidx) / 2); 300 return 1; 301 } 302 303 /* 304 * dfs_reject_on_pri() - Rejecting on individual filter based on min PRI . 305 * @dfs: Pointer to wlan_dfs structure. 306 * @rf: Pointer to dfs_filter structure. 307 * @deltaT: deltaT value. 308 * @this_ts: Timestamp. 309 */ 310 static inline bool dfs_reject_on_pri( 311 struct wlan_dfs *dfs, 312 struct dfs_filter *rf, 313 uint64_t deltaT, 314 uint64_t this_ts) 315 { 316 if ((deltaT < rf->rf_minpri) && (deltaT != 0)) { 317 /* Second line of PRI filtering. */ 318 dfs_debug(dfs, WLAN_DEBUG_DFS2, 319 "filterID %d : Rejecting on individual filter min PRI deltaT=%lld rf->rf_minpri=%u", 320 rf->rf_pulseid, (uint64_t)deltaT, 321 rf->rf_minpri); 322 return 1; 323 } 324 325 if (rf->rf_ignore_pri_window > 0) { 326 if (deltaT < rf->rf_minpri) { 327 dfs_debug(dfs, WLAN_DEBUG_DFS2, 328 "filterID %d : Rejecting on individual filter max PRI deltaT=%lld rf->rf_minpri=%u", 329 rf->rf_pulseid, (uint64_t)deltaT, 330 rf->rf_minpri); 331 /* But update the last time stamp. */ 332 rf->rf_dl.dl_last_ts = this_ts; 333 return 1; 334 } 335 } else { 336 /* 337 * The HW may miss some pulses especially with 338 * high channel loading. This is true for Japan 339 * W53 where channel loaoding is 50%. Also for 340 * ETSI where channel loading is 30% this can 341 * be an issue too. To take care of missing 342 * pulses, we introduce pri_margin multiplie. 343 * This is normally 2 but can be higher for W53. 344 */ 345 346 if ((deltaT > (dfs->dfs_pri_multiplier * rf->rf_maxpri)) || 347 (deltaT < rf->rf_minpri)) { 348 dfs_debug(dfs, WLAN_DEBUG_DFS2, 349 "filterID %d : Rejecting on individual filter max PRI deltaT=%lld rf->rf_minpri=%u", 350 rf->rf_pulseid, (uint64_t) deltaT, 351 rf->rf_minpri); 352 /* But update the last time stamp. */ 353 rf->rf_dl.dl_last_ts = this_ts; 354 return 1; 355 } 356 } 357 358 return 0; 359 } 360 361 /** 362 * dfs_confirm_radar_check() - Do additioal check to conirm radar except for 363 * the staggered, chirp FCC Bin 5, frequency hopping indicated by 364 * rf_patterntype == 1. 365 * @dfs: Pointer to wlan_dfs structure. 366 * @rf: Pointer to dfs_filter structure. 367 * @ext_chan_event_flag: Extension channel event flag 368 * @found: Pointer to radar found flag (return value). 369 * @false_radar_found: Pointer to false radar found (return value). 370 */ 371 372 static inline void dfs_confirm_radar_check( 373 struct wlan_dfs *dfs, 374 struct dfs_filter *rf, 375 int ext_chan_event_flag, 376 int *found, 377 int *false_radar_found) 378 { 379 if (rf->rf_patterntype != 1) { 380 *found = dfs_confirm_radar(dfs, rf, ext_chan_event_flag); 381 *false_radar_found = (*found == 1) ? 0 : 1; 382 } 383 } 384 385 void __dfs_process_radarevent(struct wlan_dfs *dfs, 386 struct dfs_filtertype *ft, 387 struct dfs_event *re, 388 uint64_t this_ts, 389 int *found, 390 int *false_radar_found) 391 { 392 int p; 393 uint64_t deltaT = 0; 394 int ext_chan_event_flag = 0; 395 struct dfs_filter *rf = NULL; 396 int8_t ori_rf_check_delta_peak = 0; 397 398 for (p = 0, *found = 0; (p < ft->ft_numfilters) && 399 (!(*found)) && !(*false_radar_found); p++) { 400 rf = ft->ft_filters[p]; 401 if ((re->re_dur >= rf->rf_mindur) && 402 (re->re_dur <= rf->rf_maxdur)) { 403 /* The above check is probably not necessary. */ 404 deltaT = (this_ts < rf->rf_dl.dl_last_ts) ? 405 (int64_t)((DFS_TSF_WRAP - rf->rf_dl.dl_last_ts) + 406 this_ts + 1) : 407 this_ts - rf->rf_dl.dl_last_ts; 408 409 if (dfs_reject_on_pri(dfs, rf, deltaT, this_ts)) 410 continue; 411 412 dfs_add_pulse(dfs, rf, re, deltaT, this_ts); 413 414 /* 415 * If this is an extension channel event, flag it for 416 * false alarm reduction. 417 */ 418 if (re->re_chanindex == dfs->dfs_extchan_radindex) 419 ext_chan_event_flag = 1; 420 421 if (rf->rf_patterntype == 2) { 422 *found = dfs_staggered_check(dfs, rf, 423 (uint32_t) deltaT, re->re_dur); 424 } else { 425 *found = dfs_bin_check(dfs, rf, 426 (uint32_t) deltaT, re->re_dur, 427 ext_chan_event_flag); 428 429 if (*found) { 430 ori_rf_check_delta_peak = 431 rf->rf_check_delta_peak; 432 /* 433 * If FW does not send valid psidx_diff 434 * Do not do chirp check. 435 */ 436 if (rf->rf_check_delta_peak && 437 (!(re->re_flags & 438 DFS_EVENT_VALID_PSIDX_DIFF))) 439 rf->rf_check_delta_peak = false; 440 dfs_confirm_radar_check(dfs, 441 rf, ext_chan_event_flag, 442 found, 443 false_radar_found); 444 rf->rf_check_delta_peak = 445 ori_rf_check_delta_peak; 446 } 447 } 448 449 if (dfs->dfs_debug_mask & WLAN_DEBUG_DFS2) 450 if (rf->rf_patterntype != 451 WLAN_DFS_RF_PATTERN_TYPE_1) 452 dfs_print_delayline(dfs, &rf->rf_dl); 453 454 rf->rf_dl.dl_last_ts = this_ts; 455 } 456 } 457 458 if (*found) { 459 dfs_info(dfs, WLAN_DEBUG_DFS_ALWAYS, 460 "Found on channel minDur = %d, filterId = %d", 461 ft->ft_mindur, 462 rf != NULL ? rf->rf_pulseid : -1); 463 } 464 465 return; 466 } 467 468 /** 469 * dfs_cal_average_radar_parameters() - Calculate the average radar parameters. 470 * @dfs: Pointer to wlan_dfs structure. 471 */ 472 #if defined(WLAN_DFS_PARTIAL_OFFLOAD) && defined(HOST_DFS_SPOOF_TEST) 473 static void dfs_cal_average_radar_parameters(struct wlan_dfs *dfs) 474 { 475 int i, count = 0; 476 u_int32_t total_pri = 0; 477 u_int32_t total_duration = 0; 478 u_int32_t total_sidx = 0; 479 480 /* Calculating average PRI, Duration, SIDX from 481 * the 2nd pulse, ignoring the 1st pulse (radar_log[0]). 482 * This is because for the first pulse, the diff_ts will be 483 * (0 - current_ts) which will be a huge value. 484 * Average PRI computation will be wrong. FW returns a 485 * failure test result as PRI does not match their expected 486 * value. 487 */ 488 489 for (i = 1; (i < DFS_EVENT_LOG_SIZE) && (i < dfs->dfs_event_log_count); 490 i++) { 491 total_pri += dfs->radar_log[i].diff_ts; 492 total_duration += dfs->radar_log[i].dur; 493 total_sidx += dfs->radar_log[i].sidx; 494 count++; 495 } 496 497 if (count > 0) { 498 dfs->dfs_average_pri = total_pri / count; 499 dfs->dfs_average_duration = total_duration / count; 500 dfs->dfs_average_sidx = total_sidx / count; 501 502 dfs_info(dfs, WLAN_DEBUG_DFS2, 503 "Avg.PRI =%u, Avg.duration =%u Avg.sidx =%u", 504 dfs->dfs_average_pri, 505 dfs->dfs_average_duration, 506 dfs->dfs_average_sidx); 507 } 508 } 509 #else 510 static void dfs_cal_average_radar_parameters(struct wlan_dfs *dfs) 511 { 512 } 513 #endif 514 515 /** 516 * dfs_radarfound_reset_vars() - Reset dfs variables after radar found 517 * @dfs: Pointer to wlan_dfs structure. 518 * @rs: Pointer to dfs_state. 519 * @chan: Current channel. 520 * @seg_id: Segment id. 521 */ 522 static inline void dfs_radarfound_reset_vars( 523 struct wlan_dfs *dfs, 524 struct dfs_state *rs, 525 struct dfs_channel *chan, 526 uint8_t seg_id) 527 { 528 struct dfs_channel *thischan; 529 530 /* 531 * TODO: Instead of discarding the radar, create a workqueue 532 * if the channel change is happenning through userspace and 533 * process the radar event once the channel change is completed. 534 */ 535 536 /* Collect stats */ 537 dfs->wlan_dfs_stats.num_radar_detects++; 538 thischan = &rs->rs_chan; 539 if ((seg_id == SEG_ID_SECONDARY) && 540 (dfs_is_precac_timer_running(dfs))) 541 dfs->is_radar_during_precac = 1; 542 543 /* 544 * If event log is on then dump the radar event queue on 545 * filter match. This can be used to collect information 546 * on false radar detection. 547 */ 548 if (dfs->dfs_event_log_on) { 549 dfs_cal_average_radar_parameters(dfs); 550 dfs_print_radar_events(dfs); 551 } 552 553 dfs_reset_radarq(dfs); 554 dfs_reset_alldelaylines(dfs); 555 556 dfs_debug(dfs, WLAN_DEBUG_DFS1, 557 "Primary channel freq = %u flags=0x%x", 558 chan->dfs_ch_freq, chan->dfs_ch_flagext); 559 560 if (chan->dfs_ch_freq != thischan->dfs_ch_freq) 561 dfs_debug(dfs, WLAN_DEBUG_DFS1, 562 "Ext channel freq = %u flags=0x%x", 563 thischan->dfs_ch_freq, 564 thischan->dfs_ch_flagext); 565 566 dfs->dfs_phyerr_freq_min = 0x7fffffff; 567 dfs->dfs_phyerr_freq_max = 0; 568 dfs->dfs_phyerr_w53_counter = 0; 569 570 if (seg_id == SEG_ID_SECONDARY) { 571 dfs->wlan_dfs_stats.num_seg_two_radar_detects++; 572 dfs->is_radar_found_on_secondary_seg = 1; 573 } 574 } 575 576 /** 577 * dfs_handle_bangradar - Handle the case of bangradar 578 * @dfs: Pointer to wlan_dfs structure. 579 * @chan: Current channel. 580 * @rs: Pointer to dfs_state. 581 * Return: if bangradar then return 0. Otherwise, return 1. 582 */ 583 static inline int dfs_handle_bangradar( 584 struct wlan_dfs *dfs, 585 struct dfs_channel *chan, 586 struct dfs_state **rs, 587 uint8_t *seg_id, 588 int *retval) 589 { 590 591 if (dfs->dfs_bangradar) { 592 /* 593 * Bangradar will always simulate radar found on the primary 594 * channel. 595 */ 596 *rs = &dfs->dfs_radar[dfs->dfs_curchan_radindex]; 597 dfs_debug(dfs, WLAN_DEBUG_DFS, "bangradar"); 598 *retval = 1; 599 return 1; 600 } 601 602 if (dfs->dfs_second_segment_bangradar) { 603 if (dfs_is_precac_timer_running(dfs) || 604 WLAN_IS_CHAN_11AC_VHT160(chan) || 605 WLAN_IS_CHAN_11AC_VHT80_80(chan)) { 606 dfs->is_radar_found_on_secondary_seg = 1; 607 *rs = &dfs->dfs_radar[dfs->dfs_curchan_radindex]; 608 dfs_debug(dfs, WLAN_DEBUG_DFS, 609 "second segment bangradar on cfreq = %u", 610 dfs->dfs_precac_secondary_freq); 611 *retval = 1; 612 *seg_id = SEG_ID_SECONDARY; 613 } else { 614 dfs_debug(dfs, WLAN_DEBUG_DFS, 615 "Do not process the second segment bangradar"); 616 } 617 return 1; 618 } 619 620 return 0; 621 } 622 623 /** 624 * dfs_process_w53_pulses() - Prrocess w53 pulses 625 * @dfs: Pointer to wlan_dfs structure. 626 * 627 * For chips that support frequency information, we can relax PRI 628 * restriction if the frequency spread is narrow. 629 */ 630 static inline void dfs_process_w53_pulses( 631 struct wlan_dfs *dfs) 632 { 633 if ((dfs->dfs_phyerr_freq_max - dfs->dfs_phyerr_freq_min) < 634 DFS_MAX_FREQ_SPREAD) 635 dfs->dfs_pri_multiplier = DFS_LARGE_PRI_MULTIPLIER; 636 637 dfs_debug(dfs, WLAN_DEBUG_DFS1, 638 "w53_counter=%d, freq_max=%d, freq_min=%d, pri_multiplier=%d", 639 dfs->dfs_phyerr_w53_counter, 640 dfs->dfs_phyerr_freq_max, dfs->dfs_phyerr_freq_min, 641 dfs->dfs_pri_multiplier); 642 643 dfs->dfs_phyerr_freq_min = 0x7fffffff; 644 dfs->dfs_phyerr_freq_max = 0; 645 } 646 647 /** 648 * dfs_handle_missing_pulses - Handle the case of missing pulses 649 * @dfs: Pointer to wlan_dfs structure. 650 * @chan: Current channel. 651 * 652 * The HW may miss some pulses especially with high channel loading. 653 * This is true for Japan W53 where channel loaoding is 50%. Also 654 * for ETSI where channel loading is 30% this can be an issue too. 655 * To take care of missing pulses, we introduce pri_margin multiplie. 656 * This is normally 2 but can be higher for W53. 657 * Return: If not enough pulses return 0. Otherwise, return 1. 658 */ 659 static inline int dfs_handle_missing_pulses( 660 struct wlan_dfs *dfs, 661 struct dfs_channel *chan) 662 { 663 if ((dfs->dfsdomain == DFS_MKK4_DOMAIN) && 664 (dfs->dfs_caps.wlan_chip_is_bb_tlv) && 665 (chan->dfs_ch_freq < FREQ_5500_MHZ)) { 666 dfs->dfs_pri_multiplier = DFS_W53_DEFAULT_PRI_MULTIPLIER; 667 /* 668 * Do not process W53 pulses unless we have a minimum number 669 * of them. 670 */ 671 if (dfs->dfs_phyerr_w53_counter >= 5) 672 dfs_process_w53_pulses(dfs); 673 else 674 return 0; 675 } 676 677 dfs_debug(dfs, WLAN_DEBUG_DFS1, "pri_multiplier=%d", 678 dfs->dfs_pri_multiplier); 679 680 return 1; 681 } 682 683 /** 684 * dfs_is_radarq_empty - check if radarq is empty 685 * @dfs: Pointer to wlan_dfs structure. 686 * @empty: Pointer to empty 687 */ 688 static inline void dfs_is_radarq_empty( 689 struct wlan_dfs *dfs, 690 int *empty) 691 { 692 WLAN_DFSQ_LOCK(dfs); 693 *empty = STAILQ_EMPTY(&(dfs->dfs_radarq)); 694 WLAN_DFSQ_UNLOCK(dfs); 695 } 696 697 /** 698 * dfs_remove_event_from_radarq - remove event from radarq 699 * @dfs: Pointer to wlan_dfs structure. 700 * @event: Double pointer to the event structure 701 */ 702 static inline void dfs_remove_event_from_radarq( 703 struct wlan_dfs *dfs, 704 struct dfs_event **event) 705 { 706 WLAN_DFSQ_LOCK(dfs); 707 *event = STAILQ_FIRST(&(dfs->dfs_radarq)); 708 if (*event != NULL) 709 STAILQ_REMOVE_HEAD(&(dfs->dfs_radarq), re_list); 710 WLAN_DFSQ_UNLOCK(dfs); 711 } 712 713 /** 714 * dfs_return_event_to_eventq - return event to eventq 715 * @dfs: Pointer to wlan_dfs structure. 716 * @event: Pointer to the event structure 717 */ 718 static inline void dfs_return_event_to_eventq( 719 struct wlan_dfs *dfs, 720 struct dfs_event *event) 721 { 722 qdf_mem_zero(event, sizeof(struct dfs_event)); 723 WLAN_DFSEVENTQ_LOCK(dfs); 724 STAILQ_INSERT_TAIL(&(dfs->dfs_eventq), event, re_list); 725 WLAN_DFSEVENTQ_UNLOCK(dfs); 726 } 727 728 /** 729 * dfs_log_event - log dfs event 730 * @dfs: Pointer to wlan_dfs structure. 731 * @re: Pointer to dfs_event re 732 * @this_ts: Current time stamp 64bit 733 * @diff_ts: Difference between 2 timestamps 32bit 734 * @index: Index value. 735 */ 736 static inline void dfs_log_event( 737 struct wlan_dfs *dfs, 738 struct dfs_event *re, 739 uint64_t this_ts, 740 uint32_t diff_ts, 741 uint32_t index) 742 { 743 uint8_t i; 744 struct dfs_pulseline *pl = dfs->pulses; 745 746 if (dfs->dfs_event_log_on) { 747 i = dfs->dfs_event_log_count % DFS_EVENT_LOG_SIZE; 748 dfs->radar_log[i].ts = this_ts; 749 dfs->radar_log[i].diff_ts = diff_ts; 750 dfs->radar_log[i].rssi = (*re).re_rssi; 751 dfs->radar_log[i].dur = (*re).re_dur; 752 dfs->radar_log[i].seg_id = (*re).re_seg_id; 753 dfs->radar_log[i].sidx = (*re).re_sidx; 754 dfs->radar_log[i].freq_offset_khz = 755 (*re).re_freq_offset_khz; 756 dfs->radar_log[i].peak_mag = (*re).re_peak_mag; 757 dfs->radar_log[i].total_gain = (*re).re_total_gain; 758 dfs->radar_log[i].mb_gain = (*re).re_mb_gain; 759 dfs->radar_log[i].relpwr_db = (*re).re_relpwr_db; 760 dfs->radar_log[i].delta_diff = (*re).re_delta_diff; 761 dfs->radar_log[i].delta_peak = (*re).re_delta_peak; 762 dfs->radar_log[i].psidx_diff = (*re).re_psidx_diff; 763 dfs->radar_log[i].is_chirp = DFS_EVENT_NOTCHIRP(re) ? 764 0 : 1; 765 dfs->dfs_event_log_count++; 766 } 767 768 dfs->dfs_seq_num++; 769 pl->pl_elems[index].p_seq_num = dfs->dfs_seq_num; 770 } 771 772 /** 773 * dfs_check_if_nonbin5 - Check if radar, other than bin5, is found 774 * @dfs: Pointer to wlan_dfs structure. 775 * @re: Pointer to re (radar event) 776 * @rs: Double Pointer to rs (radar state) 777 * @this_ts: Current time stamp 64bit 778 * @diff_ts: Difference between 2 timestamps 32bit 779 * @found: Pointer to found. If radar found or not. 780 * @retval: Pointer to retval(return value). 781 * @false_radar_found: Pointer to false_radar_found(return value). 782 */ 783 static inline void dfs_check_if_nonbin5( 784 struct wlan_dfs *dfs, 785 struct dfs_event *re, 786 struct dfs_state **rs, 787 uint64_t this_ts, 788 uint32_t diff_ts, 789 int *found, 790 int *retval, 791 int *false_radar_found) 792 { 793 794 uint32_t tabledepth = 0; 795 struct dfs_filtertype *ft; 796 uint64_t deltaT; 797 798 dfs_debug(dfs, WLAN_DEBUG_DFS1, 799 " *** chan freq (%d): ts %llu dur %u rssi %u", 800 (*rs)->rs_chan.dfs_ch_freq, (uint64_t)this_ts, 801 (*re).re_dur, (*re).re_rssi); 802 803 while ((tabledepth < DFS_MAX_RADAR_OVERLAP) && 804 ((dfs->dfs_ftindextable[(*re).re_dur])[tabledepth] != 805 -1) && (!*retval) && !(*false_radar_found)) { 806 ft = dfs->dfs_radarf[((dfs->dfs_ftindextable[(*re).re_dur]) 807 [tabledepth])]; 808 dfs_debug(dfs, WLAN_DEBUG_DFS2, 809 " ** RD (%d): ts %x dur %u rssi %u", 810 (*rs)->rs_chan.dfs_ch_freq, (*re).re_ts, 811 (*re).re_dur, (*re).re_rssi); 812 813 if ((*re).re_rssi < ft->ft_rssithresh && 814 (*re).re_dur > MAX_DUR_FOR_LOW_RSSI) { 815 dfs_debug(dfs, WLAN_DEBUG_DFS2, 816 "Rejecting on rssi rssi=%u thresh=%u", 817 (*re).re_rssi, 818 ft->ft_rssithresh); 819 tabledepth++; 820 continue; 821 } 822 deltaT = this_ts - ft->ft_last_ts; 823 dfs_debug(dfs, WLAN_DEBUG_DFS2, 824 "deltaT = %lld (ts: 0x%llx) (last ts: 0x%llx)", 825 (uint64_t)deltaT, (uint64_t)this_ts, 826 (uint64_t)ft->ft_last_ts); 827 828 if ((deltaT < ft->ft_minpri) && (deltaT != 0)) { 829 /* 830 * This check is for the whole filter type. 831 * Individual filters will check this again. 832 * This is first line of filtering. 833 */ 834 dfs_debug(dfs, WLAN_DEBUG_DFS2, 835 "Rejecting on pri pri=%lld minpri=%u", 836 (uint64_t)deltaT, ft->ft_minpri); 837 tabledepth++; 838 continue; 839 } 840 841 __dfs_process_radarevent(dfs, ft, re, this_ts, found, 842 false_radar_found); 843 844 ft->ft_last_ts = this_ts; 845 *retval |= *found; 846 tabledepth++; 847 } 848 } 849 850 /** 851 * dfs_check_each_b5radar() - Check each bin5 radar 852 * @dfs: Pointer to wlan_dfs structure. 853 * @re: Pointer to re(radar event). 854 * @br: Pointer to dfs_bin5radars structure. 855 * @this_ts: Current time stamp 64bit. 856 * @diff_ts: Difference between 2 timestamps 32bit. 857 * @found: Pointer to found. If radar found or not. 858 */ 859 static inline void dfs_check_each_b5radar( 860 struct wlan_dfs *dfs, 861 struct dfs_event *re, 862 struct dfs_bin5radars *br, 863 uint64_t this_ts, 864 uint32_t diff_ts, 865 int *found) 866 { 867 if (dfs_bin5_check_pulse(dfs, re, br)) { 868 /* 869 * This is a valid Bin5 pulse, check if it belongs to a 870 * burst. 871 */ 872 (*re).re_dur = dfs_retain_bin5_burst_pattern(dfs, diff_ts, 873 (*re).re_dur); 874 /* 875 * Remember our computed duration for the next pulse in the 876 * burst (if needed). 877 */ 878 dfs->dfs_rinfo.dfs_bin5_chirp_ts = this_ts; 879 dfs->dfs_rinfo.dfs_last_bin5_dur = (*re).re_dur; 880 881 if (dfs_bin5_addpulse(dfs, br, re, this_ts)) 882 *found |= dfs_bin5_check(dfs); 883 } else { 884 dfs_debug(dfs, WLAN_DEBUG_DFS_BIN5_PULSE, 885 "not a BIN5 pulse (dur=%d)", (*re).re_dur); 886 } 887 } 888 889 /** 890 * dfs_check_if_bin5() - Check if bin5 radar is found 891 * @dfs: Pointer to wlan_dfs structure. 892 * @re: Pointer to re(radar event). 893 * @this_ts: Current time stamp 64bit. 894 * @diff_ts: Difference between 2 timestamps 32bit. 895 * @found: Pointer to found. If radar found or not. 896 */ 897 static inline void dfs_check_if_bin5( 898 struct wlan_dfs *dfs, 899 struct dfs_event *re, 900 uint64_t this_ts, 901 uint32_t diff_ts, 902 int *found) 903 { 904 int p; 905 906 /* BIN5 pulses are FCC and Japan specific. */ 907 if ((dfs->dfsdomain == DFS_FCC_DOMAIN) || 908 (dfs->dfsdomain == DFS_MKK4_DOMAIN)) { 909 for (p = 0; (p < dfs->dfs_rinfo.rn_numbin5radars) && (!*found); 910 p++) { 911 struct dfs_bin5radars *br; 912 913 br = &(dfs->dfs_b5radars[p]); 914 dfs_check_each_b5radar(dfs, re, br, this_ts, diff_ts, 915 found); 916 } 917 } 918 919 if (*found) 920 dfs_debug(dfs, WLAN_DEBUG_DFS, "Found bin5 radar"); 921 } 922 923 /** 924 * dfs_skip_the_event() - Skip the Radar event 925 * @dfs: Pointer to wlan_dfs structure. 926 * @re: Pointer to re(radar event). 927 * @rs: Pointer to dfs_state. 928 */ 929 static inline bool dfs_skip_the_event( 930 struct wlan_dfs *dfs, 931 struct dfs_event *re, 932 struct dfs_state **rs) 933 { 934 if ((*re).re_chanindex < DFS_NUM_RADAR_STATES) 935 (*rs) = &dfs->dfs_radar[(*re).re_chanindex]; 936 else 937 return 1; 938 939 if ((*rs)->rs_chan.dfs_ch_flagext & CHANNEL_INTERFERENCE) 940 return 1; 941 942 return 0; 943 } 944 945 /** 946 * dfs_check_ts_wrap() - dfs check for timestamp wrap. 947 * @dfs: Pointer to wlan_dfs structure. 948 * @re: Pointer to re(radar event). 949 * @deltafull_ts: Deltafull ts. 950 * 951 * Return: Deltafull ts. 952 */ 953 static inline uint64_t dfs_check_ts_wrap( 954 struct wlan_dfs *dfs, 955 struct dfs_event *re, 956 uint64_t deltafull_ts) 957 { 958 if (deltafull_ts > 959 ((uint64_t)((DFS_TSMASK - 960 dfs->dfs_rinfo.rn_last_ts) + 961 1 + (*re).re_ts))) 962 deltafull_ts -= 963 (DFS_TSMASK - dfs->dfs_rinfo.rn_last_ts) + 964 1 + (*re).re_ts; 965 966 return deltafull_ts; 967 } 968 969 /** 970 * dfs_calculate_ts_prefix() - Calculate deltafull ts value. 971 * @dfs: Pointer to wlan_dfs structure. 972 * @re: Pointer to re(radar event). 973 */ 974 static inline void dfs_calculate_ts_prefix( 975 struct wlan_dfs *dfs, 976 struct dfs_event *re) 977 { 978 uint64_t deltafull_ts; 979 980 if ((*re).re_ts <= dfs->dfs_rinfo.rn_last_ts) { 981 dfs->dfs_rinfo.rn_ts_prefix += (((uint64_t) 1) << DFS_TSSHIFT); 982 /* Now, see if it's been more than 1 wrap */ 983 deltafull_ts = (*re).re_full_ts - dfs->dfs_rinfo.rn_lastfull_ts; 984 deltafull_ts = dfs_check_ts_wrap(dfs, re, deltafull_ts); 985 deltafull_ts >>= DFS_TSSHIFT; 986 987 if (deltafull_ts > 1) 988 dfs->dfs_rinfo.rn_ts_prefix += 989 ((deltafull_ts - 1) << DFS_TSSHIFT); 990 } else { 991 deltafull_ts = (*re).re_full_ts - 992 dfs->dfs_rinfo.rn_lastfull_ts; 993 if (deltafull_ts > (uint64_t) DFS_TSMASK) { 994 deltafull_ts >>= DFS_TSSHIFT; 995 dfs->dfs_rinfo.rn_ts_prefix += 996 ((deltafull_ts - 1) << DFS_TSSHIFT); 997 } 998 } 999 } 1000 1001 /** 1002 * dfs_calculate_timestamps() - Calculate various timestamps 1003 * @dfs: Pointer to wlan_dfs structure. 1004 * @re: Pointer to re(radar event) 1005 * @this_ts : Pointer to this_ts (this timestamp) 1006 */ 1007 1008 static inline void dfs_calculate_timestamps( 1009 struct wlan_dfs *dfs, 1010 struct dfs_event *re, 1011 uint64_t *this_ts) 1012 { 1013 if (dfs->dfs_rinfo.rn_lastfull_ts == 0) { 1014 /* 1015 * Either not started, or 64-bit rollover exactly to 1016 * zero Just prepend zeros to the 15-bit ts. 1017 */ 1018 dfs->dfs_rinfo.rn_ts_prefix = 0; 1019 } else { 1020 /* WAR 23031- patch duplicate ts on very short pulses. 1021 * This pacth has two problems in linux environment. 1022 * 1)The time stamp created and hence PRI depends 1023 * entirely on the latency. If the latency is high, it 1024 * possibly can split two consecutive pulses in the 1025 * same burst so far away (the same amount of latency) 1026 * that make them look like they are from differenct 1027 * bursts. It is observed to happen too often. It sure 1028 * makes the detection fail. 1029 * 2)Even if the latency is not that bad, it simply 1030 * shifts the duplicate timestamps to a new duplicate 1031 * timestamp based on how they are processed. 1032 * This is not worse but not good either. 1033 * Take this pulse as a good one and create a probable 1034 * PRI later. 1035 */ 1036 if ((*re).re_dur == 0 && (*re).re_ts == 1037 dfs->dfs_rinfo.rn_last_unique_ts) { 1038 debug_dup[debug_dup_cnt++] = '1'; 1039 dfs_debug(dfs, WLAN_DEBUG_DFS1, "deltaT is 0"); 1040 } else { 1041 dfs->dfs_rinfo.rn_last_unique_ts = (*re).re_ts; 1042 debug_dup[debug_dup_cnt++] = '0'; 1043 } 1044 1045 if (debug_dup_cnt >= 32) 1046 debug_dup_cnt = 0; 1047 1048 dfs_calculate_ts_prefix(dfs, re); 1049 } 1050 1051 /* 1052 * At this stage rn_ts_prefix has either been blanked or 1053 * calculated, so it's safe to use. 1054 */ 1055 *this_ts = dfs->dfs_rinfo.rn_ts_prefix | ((uint64_t) (*re).re_ts); 1056 dfs->dfs_rinfo.rn_lastfull_ts = (*re).re_full_ts; 1057 dfs->dfs_rinfo.rn_last_ts = (*re).re_ts; 1058 } 1059 1060 /** 1061 * dfs_add_to_pulseline - Extract necessary items from dfs_event and 1062 * add it as pulse in the pulseline 1063 * @dfs: Pointer to wlan_dfs structure. 1064 * @re: Pointer to re(radar event) 1065 * @this_ts: Pointer to this_ts (this timestamp) 1066 * @diff_ts: Diff ts. 1067 * @index: Pointer to get index value. 1068 */ 1069 static inline void dfs_add_to_pulseline( 1070 struct wlan_dfs *dfs, 1071 struct dfs_event *re, 1072 uint64_t *this_ts, 1073 uint32_t *test_ts, 1074 uint32_t *diff_ts, 1075 uint32_t *index) 1076 { 1077 struct dfs_pulseline *pl; 1078 1079 /* 1080 * Calculate the start of the radar pulse. 1081 * 1082 * The TSF is stamped by the MAC upon reception of the event, 1083 * which is (typically?) at the end of the event. But the 1084 * pattern matching code expects the event timestamps to be at 1085 * the start of the event. So to fake it, we subtract the pulse 1086 * duration from the given TSF. This is done after the 64-bit 1087 * timestamp has been calculated so long pulses correctly 1088 * under-wrap the counter. Ie, if this was done on the 32 1089 * (or 15!) bit TSF when the TSF value is closed to 0, it will 1090 * underflow to 0xfffffXX, which would mess up the logical "OR" 1091 * operation done above. 1092 * This isn't valid for Peregrine as the hardware gives us the 1093 * actual TSF offset of the radar event, not just the MAC TSF 1094 * of the completed receive. 1095 * 1096 * XXX TODO: ensure that the TLV PHY error processing code will 1097 * correctly calculate the TSF to be the start of the radar 1098 * pulse. 1099 * 1100 * XXX TODO TODO: modify the TLV parsing code to subtract the 1101 * duration from the TSF, based on the current fast clock value. 1102 */ 1103 if ((!dfs->dfs_caps.wlan_chip_is_bb_tlv) && (*re).re_dur != 1) 1104 *this_ts -= (*re).re_dur; 1105 1106 pl = dfs->pulses; 1107 /* Save the pulse parameters in the pulse buffer(pulse line). */ 1108 *index = (pl->pl_lastelem + 1) & DFS_MAX_PULSE_BUFFER_MASK; 1109 1110 if (pl->pl_numelems == DFS_MAX_PULSE_BUFFER_SIZE) 1111 pl->pl_firstelem = (pl->pl_firstelem+1) & 1112 DFS_MAX_PULSE_BUFFER_MASK; 1113 else 1114 pl->pl_numelems++; 1115 1116 pl->pl_lastelem = *index; 1117 pl->pl_elems[*index].p_time = *this_ts; 1118 pl->pl_elems[*index].p_dur = (*re).re_dur; 1119 pl->pl_elems[*index].p_rssi = (*re).re_rssi; 1120 pl->pl_elems[*index].p_sidx = (*re).re_sidx; 1121 pl->pl_elems[*index].p_delta_peak = (*re).re_delta_peak; 1122 pl->pl_elems[*index].p_psidx_diff = (*re).re_psidx_diff; 1123 *diff_ts = (uint32_t)*this_ts - *test_ts; 1124 *test_ts = (uint32_t)*this_ts; 1125 1126 dfs_debug(dfs, WLAN_DEBUG_DFS1, 1127 "ts%u %u %u diff %u pl->pl_lastelem.p_time=%llu", 1128 (uint32_t)*this_ts, (*re).re_dur, 1129 (*re).re_rssi, *diff_ts, 1130 (uint64_t)pl->pl_elems[*index].p_time); 1131 } 1132 1133 /** 1134 * dfs_conditional_clear_delaylines - Clear delay lines to remove the 1135 * false pulses. 1136 * @dfs: Pointer to wlan_dfs structure. 1137 * @diff_ts: diff between timerstamps. 1138 * @this_ts: this timestamp value. 1139 * @re: Pointer to dfs_event structure. 1140 */ 1141 static inline void dfs_conditional_clear_delaylines( 1142 struct wlan_dfs *dfs, 1143 uint32_t diff_ts, 1144 uint64_t this_ts, 1145 struct dfs_event re) 1146 { 1147 struct dfs_pulseline *pl = dfs->pulses; 1148 uint32_t index; 1149 1150 /* If diff_ts is very small, we might be getting false pulse 1151 * detects due to heavy interference. We might be getting 1152 * spectral splatter from adjacent channel. In order to prevent 1153 * false alarms we clear the delay-lines. This might impact 1154 * positive detections under harsh environments, but helps with 1155 * false detects. 1156 */ 1157 1158 if (diff_ts < DFS_INVALID_PRI_LIMIT) { 1159 dfs->dfs_seq_num = 0; 1160 dfs_reset_alldelaylines(dfs); 1161 dfs_reset_radarq(dfs); 1162 1163 index = (pl->pl_lastelem + 1) & DFS_MAX_PULSE_BUFFER_MASK; 1164 if (pl->pl_numelems == DFS_MAX_PULSE_BUFFER_SIZE) 1165 pl->pl_firstelem = (pl->pl_firstelem+1) & 1166 DFS_MAX_PULSE_BUFFER_MASK; 1167 else 1168 pl->pl_numelems++; 1169 1170 pl->pl_lastelem = index; 1171 pl->pl_elems[index].p_time = this_ts; 1172 pl->pl_elems[index].p_dur = re.re_dur; 1173 pl->pl_elems[index].p_rssi = re.re_rssi; 1174 pl->pl_elems[index].p_sidx = re.re_sidx; 1175 pl->pl_elems[index].p_delta_peak = re.re_delta_peak; 1176 pl->pl_elems[index].p_psidx_diff = re.re_psidx_diff; 1177 dfs->dfs_seq_num++; 1178 pl->pl_elems[index].p_seq_num = dfs->dfs_seq_num; 1179 } 1180 } 1181 1182 /** 1183 * dfs_process_each_radarevent - remove each event from the dfs radar queue 1184 * and process it. 1185 * @dfs: Pointer to wlan_dfs structure. 1186 * @chan: Pointer to DFS current channel. 1187 * @rs: Pointer to dfs_state structure. 1188 * @seg_id: segment id. 1189 * @retval: pointer to retval. 1190 * @false_radar_found: pointer to false radar found. 1191 * 1192 * Return: If radar found then return 1 else return 0. 1193 */ 1194 static inline int dfs_process_each_radarevent( 1195 struct wlan_dfs *dfs, 1196 struct dfs_channel *chan, 1197 struct dfs_state **rs, 1198 uint8_t *seg_id, 1199 int *retval, 1200 int *false_radar_found) 1201 { 1202 struct dfs_event re, *event; 1203 int found, empty; 1204 int events_processed = 0; 1205 uint64_t this_ts; 1206 static uint32_t test_ts; 1207 static uint32_t diff_ts; 1208 uint32_t index; 1209 1210 dfs_is_radarq_empty(dfs, &empty); 1211 1212 while ((!empty) && (!*retval) && !(*false_radar_found) && 1213 (events_processed < MAX_EVENTS)) { 1214 dfs_remove_event_from_radarq(dfs, &event); 1215 if (!event) { 1216 empty = 1; 1217 break; 1218 } 1219 events_processed++; 1220 re = *event; 1221 1222 dfs_return_event_to_eventq(dfs, event); 1223 1224 *seg_id = re.re_seg_id; 1225 found = 0; 1226 if (dfs_skip_the_event(dfs, &re, rs)) { 1227 dfs_is_radarq_empty(dfs, &empty); 1228 continue; 1229 } 1230 1231 dfs_calculate_timestamps(dfs, &re, &this_ts); 1232 1233 re.re_dur = dfs_process_pulse_dur(dfs, re.re_dur); 1234 1235 dfs_add_to_pulseline(dfs, &re, &this_ts, &test_ts, &diff_ts, 1236 &index); 1237 1238 dfs_log_event(dfs, &re, this_ts, diff_ts, index); 1239 1240 dfs_conditional_clear_delaylines(dfs, diff_ts, this_ts, re); 1241 1242 found = 0; 1243 if (events_processed == 1) { 1244 dfs->dfs_min_sidx = (re).re_sidx; 1245 dfs->dfs_max_sidx = (re).re_sidx; 1246 } 1247 1248 dfs_check_if_bin5(dfs, &re, this_ts, diff_ts, &found); 1249 if (found) { 1250 *retval |= found; 1251 dfs->dfs_freq_offset = DFS_SIDX_TO_FREQ_OFFSET( 1252 (dfs->dfs_min_sidx + dfs->dfs_max_sidx) / 2); 1253 return 1; 1254 } 1255 1256 dfs_check_if_nonbin5(dfs, &re, rs, this_ts, diff_ts, &found, 1257 retval, false_radar_found); 1258 1259 dfs_is_radarq_empty(dfs, &empty); 1260 } 1261 1262 return 0; 1263 } 1264 1265 /** 1266 * dfs_false_radarfound_reset_vars () - Reset dfs variables after false radar 1267 * found. 1268 * @dfs: Pointer to wlan_dfs structure. 1269 */ 1270 static inline void dfs_false_radarfound_reset_vars( 1271 struct wlan_dfs *dfs) 1272 { 1273 dfs->dfs_seq_num = 0; 1274 dfs_reset_radarq(dfs); 1275 dfs_reset_alldelaylines(dfs); 1276 dfs->dfs_phyerr_freq_min = 0x7fffffff; 1277 dfs->dfs_phyerr_freq_max = 0; 1278 dfs->dfs_phyerr_w53_counter = 0; 1279 } 1280 1281 void dfs_radarfound_action_generic(struct wlan_dfs *dfs, uint8_t seg_id) 1282 { 1283 struct radar_found_info *radar_found; 1284 1285 radar_found = qdf_mem_malloc(sizeof(*radar_found)); 1286 if (!radar_found) { 1287 dfs_alert(dfs, WLAN_DEBUG_DFS_ALWAYS, 1288 "radar_found allocation failed"); 1289 return; 1290 } 1291 1292 qdf_mem_zero(radar_found, sizeof(*radar_found)); 1293 radar_found->segment_id = seg_id; 1294 radar_found->pdev_id = 1295 wlan_objmgr_pdev_get_pdev_id(dfs->dfs_pdev_obj); 1296 1297 dfs_process_radar_ind(dfs, radar_found); 1298 qdf_mem_free(radar_found); 1299 } 1300 1301 void dfs_radar_found_action(struct wlan_dfs *dfs, 1302 bool bangradar, 1303 uint8_t seg_id) 1304 { 1305 /* If Host DFS confirmation is supported, save the curchan as 1306 * radar found chan, send radar found indication along with 1307 * average radar parameters to FW and start the host status 1308 * wait timer. 1309 */ 1310 if (!bangradar && 1311 (utils_get_dfsdomain(dfs->dfs_pdev_obj) == DFS_FCC_DOMAIN) && 1312 lmac_is_host_dfs_check_support_enabled(dfs->dfs_pdev_obj) && 1313 (dfs->dfs_spoof_test_done ? dfs->dfs_use_nol : 1)) { 1314 dfs_radarfound_action_fcc(dfs, seg_id); 1315 } else { 1316 dfs_radarfound_action_generic(dfs, seg_id); 1317 } 1318 } 1319 1320 void dfs_process_radarevent( 1321 struct wlan_dfs *dfs, 1322 struct dfs_channel *chan) 1323 { 1324 struct dfs_state *rs = NULL; 1325 uint8_t seg_id = 0; 1326 int retval = 0; 1327 int false_radar_found = 0; 1328 bool bangradar = false; 1329 1330 if (!dfs_radarevent_basic_sanity(dfs, chan)) 1331 return; 1332 /* 1333 * TEST : Simulate radar bang, make sure we add the channel to NOL 1334 * (bug 29968) 1335 */ 1336 if (dfs_handle_bangradar(dfs, chan, &rs, &seg_id, &retval)) { 1337 if (retval) 1338 bangradar = true; 1339 goto dfsfound; 1340 } 1341 1342 if (!dfs_handle_missing_pulses(dfs, chan)) 1343 return; 1344 1345 dfs_process_each_radarevent(dfs, chan, &rs, &seg_id, &retval, 1346 &false_radar_found); 1347 1348 dfsfound: 1349 if (retval) { 1350 dfs_radarfound_reset_vars(dfs, rs, chan, seg_id); 1351 dfs_radar_found_action(dfs, bangradar, seg_id); 1352 } 1353 1354 if (false_radar_found) 1355 dfs_false_radarfound_reset_vars(dfs); 1356 } 1357