1 /* 2 * Copyright (c) 2011,2017-2018 The Linux Foundation. All rights reserved. 3 * 4 * 5 * Permission to use, copy, modify, and/or distribute this software for 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #include <qdf_types.h> 21 #include "wlan_dfs_ioctl.h" 22 #include <spectral_ioctl.h> 23 24 #ifndef __KERNEL__ 25 #include <math.h> 26 #endif /* __KERNEL__ */ 27 28 #ifndef _WLAN_SPECTRAL_PUBLIC_STRUCTS_H_ 29 #define _WLAN_SPECTRAL_PUBLIC_STRUCTS_H_ 30 31 #ifdef WIN32 32 #pragma pack(push, spectral, 1) 33 #define __ATTRIB_PACKED 34 #else 35 #ifndef __ATTRIB_PACKED 36 #define __ATTRIB_PACKED __attribute__ ((packed)) 37 #endif 38 #endif 39 40 #ifndef AH_MAX_CHAINS 41 #define AH_MAX_CHAINS 3 42 #endif 43 44 #define MAX_NUM_CHANNELS 255 45 #define MAX_SPECTRAL_CHAINS 3 46 #define MAX_NUM_BINS 520 47 #define SPECTRAL_PHYERR_PARAM_NOVAL 65535 48 /* 5 categories x (lower + upper) bands */ 49 #define MAX_INTERF 10 50 51 #ifdef SPECTRAL_USE_EMU_DEFAULTS 52 /* Use defaults from emulation */ 53 #define SPECTRAL_SCAN_ACTIVE_DEFAULT (0x0) 54 #define SPECTRAL_SCAN_ENABLE_DEFAULT (0x0) 55 #define SPECTRAL_SCAN_COUNT_DEFAULT (0x0) 56 #define SPECTRAL_SCAN_PERIOD_DEFAULT (250) 57 #define SPECTRAL_SCAN_PRIORITY_DEFAULT (0x1) 58 #define SPECTRAL_SCAN_FFT_SIZE_DEFAULT (0x7) 59 #define SPECTRAL_SCAN_GC_ENA_DEFAULT (0x1) 60 #define SPECTRAL_SCAN_RESTART_ENA_DEFAULT (0x0) 61 #define SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT (0xa0) 62 #define SPECTRAL_SCAN_INIT_DELAY_DEFAULT (0x50) 63 #define SPECTRAL_SCAN_NB_TONE_THR_DEFAULT (0xc) 64 #define SPECTRAL_SCAN_STR_BIN_THR_DEFAULT (0x7) 65 #define SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT (0x0) 66 #define SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT (0x1) 67 #define SPECTRAL_SCAN_RSSI_THR_DEFAULT (0xf) 68 #define SPECTRAL_SCAN_PWR_FORMAT_DEFAULT (0x1) 69 #define SPECTRAL_SCAN_RPT_MODE_DEFAULT (0x2) 70 #define SPECTRAL_SCAN_BIN_SCALE_DEFAULT (0x1) 71 #define SPECTRAL_SCAN_DBM_ADJ_DEFAULT (0x0) 72 #define SPECTRAL_SCAN_CHN_MASK_DEFAULT (0x1) 73 #else 74 /* 75 * Static default values for spectral state and configuration. 76 * These definitions should be treated as temporary. Ideally, 77 * we should get the defaults from firmware - this will be discussed. 78 * 79 * Use defaults from Spectral Hardware Micro-Architecture 80 * document (v1.0) 81 */ 82 #define SPECTRAL_SCAN_ACTIVE_DEFAULT (0) 83 #define SPECTRAL_SCAN_ENABLE_DEFAULT (0) 84 #define SPECTRAL_SCAN_COUNT_DEFAULT (0) 85 #define SPECTRAL_SCAN_PERIOD_GEN_I_DEFAULT (35) 86 #define SPECTRAL_SCAN_PERIOD_GEN_II_DEFAULT (35) 87 #define SPECTRAL_SCAN_PERIOD_GEN_III_DEFAULT (224) 88 #define SPECTRAL_SCAN_PRIORITY_DEFAULT (1) 89 #define SPECTRAL_SCAN_FFT_SIZE_DEFAULT (7) 90 #define SPECTRAL_SCAN_GC_ENA_DEFAULT (1) 91 #define SPECTRAL_SCAN_RESTART_ENA_DEFAULT (0) 92 #define SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT (-96) 93 #define SPECTRAL_SCAN_INIT_DELAY_DEFAULT (80) 94 #define SPECTRAL_SCAN_NB_TONE_THR_DEFAULT (12) 95 #define SPECTRAL_SCAN_STR_BIN_THR_DEFAULT (8) 96 #define SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT (0) 97 #define SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT (0) 98 #define SPECTRAL_SCAN_RSSI_THR_DEFAULT (0xf0) 99 #define SPECTRAL_SCAN_PWR_FORMAT_DEFAULT (0) 100 #define SPECTRAL_SCAN_RPT_MODE_DEFAULT (2) 101 #define SPECTRAL_SCAN_BIN_SCALE_DEFAULT (1) 102 #define SPECTRAL_SCAN_DBM_ADJ_DEFAULT (1) 103 #define SPECTRAL_SCAN_CHN_MASK_DEFAULT (1) 104 #endif /* SPECTRAL_USE_EMU_DEFAULTS */ 105 106 /* The below two definitions apply only to pre-11ac chipsets */ 107 #define SPECTRAL_SCAN_SHORT_REPORT_DEFAULT (1) 108 #define SPECTRAL_SCAN_FFT_PERIOD_DEFAULT (1) 109 110 /* 111 * Definitions to help in scaling of gen3 linear format Spectral bins to values 112 * similar to those from gen2 chipsets. 113 */ 114 115 /* 116 * Max gain for QCA9984. Since this chipset is a prime representative of gen2 117 * chipsets, it is chosen for this value. 118 */ 119 #define SPECTRAL_QCA9984_MAX_GAIN (78) 120 121 /* Temporary section for hard-coded values. These need to come from FW. */ 122 123 /* Max gain for IPQ8074 */ 124 #define SPECTRAL_IPQ8074_DEFAULT_MAX_GAIN_HARDCODE (62) 125 126 /* 127 * Section for values needing tuning per customer platform. These too may need 128 * to come from FW. To be considered as hard-coded for now. 129 */ 130 131 /* 132 * If customers have a different gain line up than QCA reference designs for 133 * IPQ8074 and/or QCA9984, they may have to tune the low level threshold and 134 * the RSSI threshold. 135 */ 136 #define SPECTRAL_SCALING_LOW_LEVEL_OFFSET (7) 137 #define SPECTRAL_SCALING_RSSI_THRESH (5) 138 139 /* 140 * If customers set the AGC backoff differently, they may have to tune the high 141 * level threshold. 142 */ 143 #define SPECTRAL_SCALING_HIGH_LEVEL_OFFSET (5) 144 145 /* End of section for values needing fine tuning. */ 146 /* End of temporary section for hard-coded values */ 147 148 /** 149 * enum wlan_cfg80211_spectral_vendorcmd_handler_idx - Indices to cfg80211 150 * spectral vendor command handlers 151 * @SPECTRAL_SCAN_START_HANDLER_IDX: Index to SPECTRAL_SCAN_START handler 152 * @SPECTRAL_SCAN_STOP_HANDLER_IDX: Index to SPECTRAL_SCAN_STOP handler 153 * @SPECTRAL_SCAN_GET_CONFIG_HANDLER_IDX: Index to SPECTRAL_SCAN_GET_CONFIG 154 * handler 155 * @SPECTRAL_SCAN_GET_DIAG_STATS_HANDLER_IDX: Index to 156 * SPECTRAL_SCAN_GET_DIAG_STATS handler 157 * @SPECTRAL_SCAN_GET_CAP_HANDLER_IDX: Index to SPECTRAL_SCAN_GET_CAP handler 158 * @SPECTRAL_SCAN_GET_STATUS_HANDLER_IDX: Index to SPECTRAL_SCAN_GET_STATUS 159 * handler 160 * @SPECTRAL_SCAN_VENDOR_CMD_HANDLER_MAX: Number of cfg80211 spectral 161 * vendor command handlers supported 162 */ 163 enum wlan_cfg80211_spectral_vendorcmd_handler_idx { 164 SPECTRAL_SCAN_START_HANDLER_IDX, 165 SPECTRAL_SCAN_STOP_HANDLER_IDX, 166 SPECTRAL_SCAN_GET_CONFIG_HANDLER_IDX, 167 SPECTRAL_SCAN_GET_DIAG_STATS_HANDLER_IDX, 168 SPECTRAL_SCAN_GET_CAP_HANDLER_IDX, 169 SPECTRAL_SCAN_GET_STATUS_HANDLER_IDX, 170 SPECTRAL_SCAN_VENDOR_CMD_HANDLER_MAX, 171 }; 172 173 /** 174 * enum spectral_debug - Spectral debug level 175 * @DEBUG_SPECTRAL: Minimal SPECTRAL debug 176 * @DEBUG_SPECTRAL1: Normal SPECTRAL debug 177 * @DEBUG_SPECTRAL2: Maximal SPECTRAL debug 178 * @DEBUG_SPECTRAL3: Matched filterID display 179 * @DEBUG_SPECTRAL4: One time dump of FFT report 180 */ 181 enum spectral_debug { 182 DEBUG_SPECTRAL = 0x00000100, 183 DEBUG_SPECTRAL1 = 0x00000200, 184 DEBUG_SPECTRAL2 = 0x00000400, 185 DEBUG_SPECTRAL3 = 0x00000800, 186 DEBUG_SPECTRAL4 = 0x00001000, 187 }; 188 189 /** 190 * enum spectral_capability_type - Spectral capability type 191 * @SPECTRAL_CAP_PHYDIAG: Phydiag capability 192 * @SPECTRAL_CAP_RADAR: Radar detection capability 193 * @SPECTRAL_CAP_SPECTRAL_SCAN: Spectral capability 194 * @SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN: Advanced spectral capability 195 */ 196 enum spectral_capability_type { 197 SPECTRAL_CAP_PHYDIAG, 198 SPECTRAL_CAP_RADAR, 199 SPECTRAL_CAP_SPECTRAL_SCAN, 200 SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN, 201 }; 202 203 /** 204 * struct spectral_chan_stats - channel status info 205 * @cycle_count: Cycle count 206 * @channel_load: Channel load 207 * @per: Period 208 * @noisefloor: Noise floor 209 * @comp_usablity: Computed usability 210 * @maxregpower: Maximum allowed regulatory power 211 * @comp_usablity_sec80: Computed usability of secondary 80 Mhz 212 * @maxregpower_sec80: Max regulatory power of secondary 80 Mhz 213 */ 214 struct spectral_chan_stats { 215 int cycle_count; 216 int channel_load; 217 int per; 218 int noisefloor; 219 uint16_t comp_usablity; 220 int8_t maxregpower; 221 uint16_t comp_usablity_sec80; 222 int8_t maxregpower_sec80; 223 }; 224 225 /** 226 * struct spectral_diag_stats - spectral diag stats 227 * @spectral_mismatch: Spectral TLV signature mismatches 228 * @spectral_sec80_sfft_insufflen: Insufficient length when parsing for 229 * Secondary 80 Search FFT report 230 * @spectral_no_sec80_sfft: Secondary 80 Search FFT report 231 * TLV not found 232 * @spectral_vhtseg1id_mismatch: VHT Operation Segment 1 ID 233 * mismatches in Search FFT report 234 * @spectral_vhtseg2id_mismatch: VHT Operation Segment 2 ID 235 * mismatches in Search FFT report 236 * @spectral_invalid_detector_id: Invalid detector id 237 */ 238 struct spectral_diag_stats { 239 uint64_t spectral_mismatch; 240 uint64_t spectral_sec80_sfft_insufflen; 241 uint64_t spectral_no_sec80_sfft; 242 uint64_t spectral_vhtseg1id_mismatch; 243 uint64_t spectral_vhtseg2id_mismatch; 244 uint64_t spectral_invalid_detector_id; 245 }; 246 247 /** 248 * struct spectral_config - spectral config parameters 249 * @ss_fft_period: Skip interval for FFT reports 250 * @ss_period: Spectral scan period 251 * @ss_count: # of reports to return from ss_active 252 * @ss_short_report: Set to report only 1 set of FFT results 253 * @radar_bin_thresh_sel: Select threshold to classify strong bin for FFT 254 * @ss_spectral_pri: Priority, and are we doing a noise power cal ? 255 * @ss_fft_size: Defines the number of FFT data points to compute, 256 * defined as a log index num_fft_pts = 257 * 2^ss_fft_size 258 * @ss_gc_ena: Set, to enable targeted gain change before 259 * starting the spectral scan FFT 260 * @ss_restart_ena: Set, to enable abort of receive frames when in high 261 * priority and a spectral scan is queued 262 * @ss_noise_floor_ref: Noise floor reference number (signed) for the 263 * calculation of bin power (dBm) Though stored as an 264 * unsigned this should be treated as a signed 8-bit int. 265 * @ss_init_delay: Disallow spectral scan triggers after tx/rx packets 266 * by setting this delay value to roughly SIFS time 267 * period or greater Delay timer count in units of 0.25us 268 * @ss_nb_tone_thr: Number of strong bins (inclusive) per sub-channel, 269 * below which a signal is declared a narrowband tone 270 * @ss_str_bin_thr: Bin/max_bin ratio threshold over which a bin is 271 * declared strong (for spectral scan bandwidth analysis) 272 * @ss_wb_rpt_mode: Set this bit to report spectral scans as EXT_BLOCKER 273 * (phy_error=36), if none of the sub-channels are 274 * deemed narrowband 275 * @ss_rssi_rpt_mode: Set this bit to report spectral scans as EXT_BLOCKER 276 * (phy_error=36), if the ADC RSSI is below the 277 * threshold ss_rssi_thr 278 * @ss_rssi_thr: ADC RSSI must be greater than or equal to this 279 * threshold (signed Db) to ensure spectral scan 280 * reporting with normal phy error codes (please see 281 * ss_rssi_rpt_mode above).Though stored as an unsigned 282 * value, this should be treated as a signed 8-bit int 283 * @ss_pwr_format: Format of frequency bin magnitude for spectral scan 284 * triggered FFTs 0: linear magnitude 285 * 1: log magnitude (20*log10(lin_mag), 1/2 dB step size) 286 * @ss_rpt_mode: Format of per-FFT reports to software for spectral 287 * scan triggered FFTs 288 * 0: No FFT report (only pulse end summary) 289 * 1: 2-dword summary of metrics for each completed FFT 290 * 2: 2-dword summary + 1x-oversampled bins(in-band) per 291 * FFT 292 * 3: 2-dword summary + 2x-oversampled bins (all) per FFT 293 * @ss_bin_scale: Number of LSBs to shift out to scale the FFT bins 294 * for spectral scan triggered FFTs 295 * @ss_dbm_adj: Set (with ss_pwr_format=1), to report bin 296 * magnitudes 297 * converted to dBm power using the noisefloor 298 * calibration results 299 * @ss_chn_mask: Per chain enable mask to select input ADC for search 300 * FFT 301 * @ss_nf_cal: nf calibrated values for ctl+ext 302 * @ss_nf_pwr: nf pwr values for ctl+ext 303 * @ss_nf_temp_data: temperature data taken during nf scan 304 */ 305 struct spectral_config { 306 uint16_t ss_fft_period; 307 uint16_t ss_period; 308 uint16_t ss_count; 309 uint16_t ss_short_report; 310 uint8_t radar_bin_thresh_sel; 311 uint16_t ss_spectral_pri; 312 uint16_t ss_fft_size; 313 uint16_t ss_gc_ena; 314 uint16_t ss_restart_ena; 315 uint16_t ss_noise_floor_ref; 316 uint16_t ss_init_delay; 317 uint16_t ss_nb_tone_thr; 318 uint16_t ss_str_bin_thr; 319 uint16_t ss_wb_rpt_mode; 320 uint16_t ss_rssi_rpt_mode; 321 uint16_t ss_rssi_thr; 322 uint16_t ss_pwr_format; 323 uint16_t ss_rpt_mode; 324 uint16_t ss_bin_scale; 325 uint16_t ss_dbm_adj; 326 uint16_t ss_chn_mask; 327 int8_t ss_nf_cal[AH_MAX_CHAINS * 2]; 328 int8_t ss_nf_pwr[AH_MAX_CHAINS * 2]; 329 int32_t ss_nf_temp_data; 330 }; 331 332 /** 333 * struct spectral_scan_state - State of spectral scan 334 * @is_active: Is spectral scan active 335 * @is_enabled: Is spectral scan enabled 336 */ 337 struct spectral_scan_state { 338 uint8_t is_active; 339 uint8_t is_enabled; 340 }; 341 342 /** 343 * enum dcs_int_type - Interference type indicated by DCS 344 * @SPECTRAL_DCS_INT_NONE: No interference 345 * @SPECTRAL_DCS_INT_CW: CW interference 346 * @SPECTRAL_DCS_INT_WIFI: WLAN interference 347 */ 348 enum dcs_int_type { 349 SPECTRAL_DCS_INT_NONE, 350 SPECTRAL_DCS_INT_CW, 351 SPECTRAL_DCS_INT_WIFI 352 }; 353 354 /** 355 * struct interf_rsp - Interference record 356 * @interf_type: eINTERF_TYPE giving type of interference 357 * @interf_min_freq: Minimum frequency in MHz at which interference has been 358 * found 359 * @interf_max_freq: Maximum frequency in MHz at which interference has been 360 * found 361 * @advncd_spectral_cap: Advanced spectral capability 362 */ 363 struct interf_rsp { 364 uint8_t interf_type; 365 uint16_t interf_min_freq; 366 uint16_t interf_max_freq; 367 } __ATTRIB_PACKED; 368 369 /** 370 * struct interf_src_rsp - List of interference sources 371 * @count: Number of interference records 372 * @interf: Array of interference records 373 */ 374 struct interf_src_rsp { 375 uint16_t count; 376 struct interf_rsp interf[MAX_INTERF]; 377 } __ATTRIB_PACKED; 378 379 /** 380 * struct spectral_classifier_params - spectral classifier parameters 381 * @spectral_20_40_mode: Is AP in 20/40 mode? 382 * @spectral_dc_index: DC index 383 * @spectral_dc_in_mhz: DC in MHz 384 * @upper_chan_in_mhz: Upper channel in MHz 385 * @lower_chan_in_mhz: Lower channel in MHz 386 */ 387 struct spectral_classifier_params { 388 int spectral_20_40_mode; 389 int spectral_dc_index; 390 int spectral_dc_in_mhz; 391 int upper_chan_in_mhz; 392 int lower_chan_in_mhz; 393 } __ATTRIB_PACKED; 394 395 /** 396 * struct spectral_samp_data - Spectral Analysis Messaging Protocol Data format 397 * @spectral_data_len: Indicates the bin size 398 * @spectral_data_len_sec80: Indicates the bin size for secondary 80 segment 399 * @spectral_rssi: Indicates RSSI 400 * @spectral_rssi_sec80: Indicates RSSI for secondary 80 segment 401 * @spectral_combined_rssi: Indicates combined RSSI from all antennas 402 * @spectral_upper_rssi: Indicates RSSI of upper band 403 * @spectral_lower_rssi: Indicates RSSI of lower band 404 * @spectral_chain_ctl_rssi: RSSI for control channel, for all antennas 405 * @spectral_chain_ext_rssi: RSSI for extension channel, for all antennas 406 * @spectral_max_scale: Indicates scale factor 407 * @spectral_bwinfo: Indicates bandwidth info 408 * @spectral_tstamp: Indicates timestamp 409 * @spectral_max_index: Indicates the index of max magnitude 410 * @spectral_max_index_sec80: Indicates the index of max magnitude for secondary 411 * 80 segment 412 * @spectral_max_mag: Indicates the maximum magnitude 413 * @spectral_max_mag_sec80: Indicates the maximum magnitude for secondary 80 414 * segment 415 * @spectral_max_exp: Indicates the max exp 416 * @spectral_last_tstamp: Indicates the last time stamp 417 * @spectral_upper_max_index: Indicates the index of max mag in upper band 418 * @spectral_lower_max_index: Indicates the index of max mag in lower band 419 * @spectral_nb_upper: Not Used 420 * @spectral_nb_lower: Not Used 421 * @classifier_params: Indicates classifier parameters 422 * @bin_pwr_count: Indicates the number of FFT bins 423 * @lb_edge_extrabins: Number of extra bins on left band edge 424 * @rb_edge_extrabins: Number of extra bins on right band edge 425 * @bin_pwr_count_sec80: Indicates the number of FFT bins in secondary 80 426 * segment 427 * @bin_pwr: Contains FFT magnitudes 428 * @bin_pwr_sec80: Contains FFT magnitudes for the secondary 80 429 * segment 430 * @interf_list: List of interfernce sources 431 * @noise_floor: Indicates the current noise floor 432 * @noise_floor_sec80: Indicates the current noise floor for secondary 80 433 * segment 434 * @ch_width: Channel width 20/40/80/160 MHz 435 */ 436 struct spectral_samp_data { 437 int16_t spectral_data_len; 438 int16_t spectral_data_len_sec80; 439 int16_t spectral_rssi; 440 int16_t spectral_rssi_sec80; 441 int8_t spectral_combined_rssi; 442 int8_t spectral_upper_rssi; 443 int8_t spectral_lower_rssi; 444 int8_t spectral_chain_ctl_rssi[MAX_SPECTRAL_CHAINS]; 445 int8_t spectral_chain_ext_rssi[MAX_SPECTRAL_CHAINS]; 446 uint8_t spectral_max_scale; 447 int16_t spectral_bwinfo; 448 int32_t spectral_tstamp; 449 int16_t spectral_max_index; 450 int16_t spectral_max_index_sec80; 451 int16_t spectral_max_mag; 452 int16_t spectral_max_mag_sec80; 453 uint8_t spectral_max_exp; 454 int32_t spectral_last_tstamp; 455 int16_t spectral_upper_max_index; 456 int16_t spectral_lower_max_index; 457 uint8_t spectral_nb_upper; 458 uint8_t spectral_nb_lower; 459 struct spectral_classifier_params classifier_params; 460 uint16_t bin_pwr_count; 461 /* 462 * For 11ac chipsets prior to AR900B version 2.0, a max of 512 bins are 463 * delivered. However, there can be additional bins reported for 464 * AR900B version 2.0 and QCA9984 as described next: 465 * 466 * AR900B version 2.0: An additional tone is processed on the right 467 * hand side in order to facilitate detection of radar pulses out to 468 * the extreme band-edge of the channel frequency. 469 * Since the HW design processes four tones at a time, 470 * this requires one additional Dword to be added to the 471 * search FFT report. 472 * 473 * QCA9984: When spectral_scan_rpt_mode=2, i.e 2-dword summary + 474 * 1x-oversampled bins (in-band) per FFT, 475 * then 8 more bins (4 more on left side and 4 more on right side) 476 * are added. 477 */ 478 uint8_t lb_edge_extrabins; 479 uint8_t rb_edge_extrabins; 480 uint16_t bin_pwr_count_sec80; 481 uint8_t bin_pwr[MAX_NUM_BINS]; 482 uint8_t bin_pwr_sec80[MAX_NUM_BINS]; 483 struct interf_src_rsp interf_list; 484 int16_t noise_floor; 485 int16_t noise_floor_sec80; 486 uint32_t ch_width; 487 uint8_t spectral_agc_total_gain; 488 uint8_t spectral_agc_total_gain_sec80; 489 uint8_t spectral_gainchange; 490 uint8_t spectral_gainchange_sec80; 491 } __ATTRIB_PACKED; 492 493 /** 494 * struct spectral_samp_msg - Spectral SAMP message 495 * @signature: Validates the SAMP message 496 * @freq: Operating frequency in MHz 497 * @vhtop_ch_freq_seg1: VHT Segment 1 centre frequency in MHz 498 * @vhtop_ch_freq_seg2: VHT Segment 2 centre frequency in MHz 499 * @freq_loading: How busy was the channel 500 * @dcs_enabled: Whether DCS is enabled 501 * @int_type: Interference type indicated by DCS 502 * @macaddr: Indicates the device interface 503 * @samp_data: SAMP Data 504 */ 505 struct spectral_samp_msg { 506 uint32_t signature; 507 uint16_t freq; 508 uint16_t vhtop_ch_freq_seg1; 509 uint16_t vhtop_ch_freq_seg2; 510 uint16_t freq_loading; 511 uint16_t dcs_enabled; 512 enum dcs_int_type int_type; 513 uint8_t macaddr[6]; 514 struct spectral_samp_data samp_data; 515 } __ATTRIB_PACKED; 516 517 /* Forward declarations */ 518 struct wlan_objmgr_pdev; 519 520 /** 521 * struct spectral_nl_cb - Spectral Netlink callbacks 522 * @get_nbuff: Get the socket buffer to send the data to the application 523 * @send_nl_bcast: Send data to the application using netlink broadcast 524 * @send_nl_unicast: Send data to the application using netlink unicast 525 */ 526 struct spectral_nl_cb { 527 void *(*get_nbuff)(struct wlan_objmgr_pdev *pdev); 528 int (*send_nl_bcast)(struct wlan_objmgr_pdev *pdev); 529 int (*send_nl_unicast)(struct wlan_objmgr_pdev *pdev); 530 void (*free_nbuff)(struct wlan_objmgr_pdev *pdev); 531 }; 532 533 #ifndef __KERNEL__ 534 535 static inline int16_t 536 spectral_pwfactor_max(int16_t pwfactor1, 537 int16_t pwfactor2) 538 { 539 return ((pwfactor1 > pwfactor2) ? pwfactor1 : pwfactor2); 540 } 541 542 /** 543 * get_spectral_scale_rssi_corr() - Compute RSSI correction factor for scaling 544 * @agc_total_gain_db: AGC total gain in dB steps 545 * @gen3_defmaxgain: Default max gain value of the gen III chipset 546 * @gen2_maxgain: Max gain value used by the reference gen II chipset 547 * @lowlevel_offset: Low level offset for scaling 548 * @inband_pwr: In band power in dB steps 549 * @rssi_thr: RSSI threshold for scaling 550 * 551 * Helper function to compute RSSI correction factor for Gen III linear format 552 * Spectral scaling. It is the responsibility of the caller to ensure that 553 * correct values are passed. 554 * 555 * Return: RSSI correction factor 556 */ 557 static inline int16_t 558 get_spectral_scale_rssi_corr(u_int8_t agc_total_gain_db, 559 u_int8_t gen3_defmaxgain, u_int8_t gen2_maxgain, 560 int16_t lowlevel_offset, int16_t inband_pwr, 561 int16_t rssi_thr) 562 { 563 return ((agc_total_gain_db < gen3_defmaxgain) ? 564 (gen2_maxgain - gen3_defmaxgain + lowlevel_offset) : 565 spectral_pwfactor_max((inband_pwr - rssi_thr), 0)); 566 } 567 568 /** 569 * spectral_scale_linear_to_gen2() - Scale linear bin value to gen II equivalent 570 * @gen3_binmag: Captured FFT bin value from the Spectral Search FFT report 571 * generated by the Gen III chipset 572 * @gen2_maxgain: Max gain value used by the reference gen II chipset 573 * @gen3_defmaxgain: Default max gain value of the gen III chipset 574 * @lowlevel_offset: Low level offset for scaling 575 * @inband_pwr: In band power in dB steps 576 * @rssi_thr: RSSI threshold for scaling 577 * @agc_total_gain_db: AGC total gain in dB steps 578 * @highlevel_offset: High level offset for scaling 579 * @gen2_bin_scale: Bin scale value used on reference gen II chipset 580 * @gen3_bin_scale: Bin scale value used on gen III chipset 581 * 582 * Helper function to scale a given gen III linear format bin value into an 583 * approximately equivalent gen II value. The scaled value can possibly be 584 * higher than 8 bits. If the caller is incapable of handling values larger 585 * than 8 bits, the caller can saturate the value at 255. This function does not 586 * carry out this saturation for the sake of flexibility so that callers 587 * interested in the larger values can avail of this. Also note it is the 588 * responsibility of the caller to ensure that correct values are passed. 589 * 590 * Return: Scaled bin value 591 */ 592 static inline u_int32_t 593 spectral_scale_linear_to_gen2(u_int8_t gen3_binmag, 594 u_int8_t gen2_maxgain, u_int8_t gen3_defmaxgain, 595 int16_t lowlevel_offset, int16_t inband_pwr, 596 int16_t rssi_thr, u_int8_t agc_total_gain_db, 597 int16_t highlevel_offset, u_int8_t gen2_bin_scale, 598 u_int8_t gen3_bin_scale) 599 { 600 return (gen3_binmag * 601 sqrt(pow(10, (((double)spectral_pwfactor_max(gen2_maxgain - 602 gen3_defmaxgain + lowlevel_offset - 603 get_spectral_scale_rssi_corr(agc_total_gain_db, 604 gen3_defmaxgain, 605 gen2_maxgain, 606 lowlevel_offset, 607 inband_pwr, 608 rssi_thr), 609 (agc_total_gain_db < gen3_defmaxgain) * 610 highlevel_offset)) / 10))) * 611 pow(2, (gen3_bin_scale - gen2_bin_scale))); 612 } 613 614 #endif /* __KERNEL__ */ 615 616 #ifdef WIN32 617 #pragma pack(pop, spectral) 618 #endif 619 #ifdef __ATTRIB_PACKED 620 #undef __ATTRIB_PACKED 621 #endif 622 623 #endif /* _WLAN_SPECTRAL_PUBLIC_STRUCTS_H_ */ 624