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 */ 237 struct spectral_diag_stats { 238 uint64_t spectral_mismatch; 239 uint64_t spectral_sec80_sfft_insufflen; 240 uint64_t spectral_no_sec80_sfft; 241 uint64_t spectral_vhtseg1id_mismatch; 242 uint64_t spectral_vhtseg2id_mismatch; 243 }; 244 245 /** 246 * struct spectral_config - spectral config parameters 247 * @ss_fft_period: Skip interval for FFT reports 248 * @ss_period: Spectral scan period 249 * @ss_count: # of reports to return from ss_active 250 * @ss_short_report: Set to report only 1 set of FFT results 251 * @radar_bin_thresh_sel: Select threshold to classify strong bin for FFT 252 * @ss_spectral_pri: Priority, and are we doing a noise power cal ? 253 * @ss_fft_size: Defines the number of FFT data points to compute, 254 * defined as a log index num_fft_pts = 255 * 2^ss_fft_size 256 * @ss_gc_ena: Set, to enable targeted gain change before 257 * starting the spectral scan FFT 258 * @ss_restart_ena: Set, to enable abort of receive frames when in high 259 * priority and a spectral scan is queued 260 * @ss_noise_floor_ref: Noise floor reference number (signed) for the 261 * calculation of bin power (dBm) Though stored as an 262 * unsigned this should be treated as a signed 8-bit int. 263 * @ss_init_delay: Disallow spectral scan triggers after tx/rx packets 264 * by setting this delay value to roughly SIFS time 265 * period or greater Delay timer count in units of 0.25us 266 * @ss_nb_tone_thr: Number of strong bins (inclusive) per sub-channel, 267 * below which a signal is declared a narrowband tone 268 * @ss_str_bin_thr: Bin/max_bin ratio threshold over which a bin is 269 * declared strong (for spectral scan bandwidth analysis) 270 * @ss_wb_rpt_mode: Set this bit to report spectral scans as EXT_BLOCKER 271 * (phy_error=36), if none of the sub-channels are 272 * deemed narrowband 273 * @ss_rssi_rpt_mode: Set this bit to report spectral scans as EXT_BLOCKER 274 * (phy_error=36), if the ADC RSSI is below the 275 * threshold ss_rssi_thr 276 * @ss_rssi_thr: ADC RSSI must be greater than or equal to this 277 * threshold (signed Db) to ensure spectral scan 278 * reporting with normal phy error codes (please see 279 * ss_rssi_rpt_mode above).Though stored as an unsigned 280 * value, this should be treated as a signed 8-bit int 281 * @ss_pwr_format: Format of frequency bin magnitude for spectral scan 282 * triggered FFTs 0: linear magnitude 283 * 1: log magnitude (20*log10(lin_mag), 1/2 dB step size) 284 * @ss_rpt_mode: Format of per-FFT reports to software for spectral 285 * scan triggered FFTs 286 * 0: No FFT report (only pulse end summary) 287 * 1: 2-dword summary of metrics for each completed FFT 288 * 2: 2-dword summary + 1x-oversampled bins(in-band) per 289 * FFT 290 * 3: 2-dword summary + 2x-oversampled bins (all) per FFT 291 * @ss_bin_scale: Number of LSBs to shift out to scale the FFT bins 292 * for spectral scan triggered FFTs 293 * @ss_dbm_adj: Set (with ss_pwr_format=1), to report bin 294 * magnitudes 295 * converted to dBm power using the noisefloor 296 * calibration results 297 * @ss_chn_mask: Per chain enable mask to select input ADC for search 298 * FFT 299 * @ss_nf_cal: nf calibrated values for ctl+ext 300 * @ss_nf_pwr: nf pwr values for ctl+ext 301 * @ss_nf_temp_data: temperature data taken during nf scan 302 */ 303 struct spectral_config { 304 uint16_t ss_fft_period; 305 uint16_t ss_period; 306 uint16_t ss_count; 307 uint16_t ss_short_report; 308 uint8_t radar_bin_thresh_sel; 309 uint16_t ss_spectral_pri; 310 uint16_t ss_fft_size; 311 uint16_t ss_gc_ena; 312 uint16_t ss_restart_ena; 313 uint16_t ss_noise_floor_ref; 314 uint16_t ss_init_delay; 315 uint16_t ss_nb_tone_thr; 316 uint16_t ss_str_bin_thr; 317 uint16_t ss_wb_rpt_mode; 318 uint16_t ss_rssi_rpt_mode; 319 uint16_t ss_rssi_thr; 320 uint16_t ss_pwr_format; 321 uint16_t ss_rpt_mode; 322 uint16_t ss_bin_scale; 323 uint16_t ss_dbm_adj; 324 uint16_t ss_chn_mask; 325 int8_t ss_nf_cal[AH_MAX_CHAINS * 2]; 326 int8_t ss_nf_pwr[AH_MAX_CHAINS * 2]; 327 int32_t ss_nf_temp_data; 328 }; 329 330 /** 331 * struct spectral_scan_state - State of spectral scan 332 * @is_active: Is spectral scan active 333 * @is_enabled: Is spectral scan enabled 334 */ 335 struct spectral_scan_state { 336 uint8_t is_active; 337 uint8_t is_enabled; 338 }; 339 340 /** 341 * enum dcs_int_type - Interference type indicated by DCS 342 * @SPECTRAL_DCS_INT_NONE: No interference 343 * @SPECTRAL_DCS_INT_CW: CW interference 344 * @SPECTRAL_DCS_INT_WIFI: WLAN interference 345 */ 346 enum dcs_int_type { 347 SPECTRAL_DCS_INT_NONE, 348 SPECTRAL_DCS_INT_CW, 349 SPECTRAL_DCS_INT_WIFI 350 }; 351 352 /** 353 * struct interf_rsp - Interference record 354 * @interf_type: eINTERF_TYPE giving type of interference 355 * @interf_min_freq: Minimum frequency in MHz at which interference has been 356 * found 357 * @interf_max_freq: Maximum frequency in MHz at which interference has been 358 * found 359 * @advncd_spectral_cap: Advanced spectral capability 360 */ 361 struct interf_rsp { 362 uint8_t interf_type; 363 uint16_t interf_min_freq; 364 uint16_t interf_max_freq; 365 } __ATTRIB_PACKED; 366 367 /** 368 * struct interf_src_rsp - List of interference sources 369 * @count: Number of interference records 370 * @interf: Array of interference records 371 */ 372 struct interf_src_rsp { 373 uint16_t count; 374 struct interf_rsp interf[MAX_INTERF]; 375 } __ATTRIB_PACKED; 376 377 /** 378 * struct spectral_classifier_params - spectral classifier parameters 379 * @spectral_20_40_mode: Is AP in 20/40 mode? 380 * @spectral_dc_index: DC index 381 * @spectral_dc_in_mhz: DC in MHz 382 * @upper_chan_in_mhz: Upper channel in MHz 383 * @lower_chan_in_mhz: Lower channel in MHz 384 */ 385 struct spectral_classifier_params { 386 int spectral_20_40_mode; 387 int spectral_dc_index; 388 int spectral_dc_in_mhz; 389 int upper_chan_in_mhz; 390 int lower_chan_in_mhz; 391 } __ATTRIB_PACKED; 392 393 /** 394 * struct spectral_samp_data - Spectral Analysis Messaging Protocol Data format 395 * @spectral_data_len: Indicates the bin size 396 * @spectral_data_len_sec80: Indicates the bin size for secondary 80 segment 397 * @spectral_rssi: Indicates RSSI 398 * @spectral_rssi_sec80: Indicates RSSI for secondary 80 segment 399 * @spectral_combined_rssi: Indicates combined RSSI from all antennas 400 * @spectral_upper_rssi: Indicates RSSI of upper band 401 * @spectral_lower_rssi: Indicates RSSI of lower band 402 * @spectral_chain_ctl_rssi: RSSI for control channel, for all antennas 403 * @spectral_chain_ext_rssi: RSSI for extension channel, for all antennas 404 * @spectral_max_scale: Indicates scale factor 405 * @spectral_bwinfo: Indicates bandwidth info 406 * @spectral_tstamp: Indicates timestamp 407 * @spectral_max_index: Indicates the index of max magnitude 408 * @spectral_max_index_sec80: Indicates the index of max magnitude for secondary 409 * 80 segment 410 * @spectral_max_mag: Indicates the maximum magnitude 411 * @spectral_max_mag_sec80: Indicates the maximum magnitude for secondary 80 412 * segment 413 * @spectral_max_exp: Indicates the max exp 414 * @spectral_last_tstamp: Indicates the last time stamp 415 * @spectral_upper_max_index: Indicates the index of max mag in upper band 416 * @spectral_lower_max_index: Indicates the index of max mag in lower band 417 * @spectral_nb_upper: Not Used 418 * @spectral_nb_lower: Not Used 419 * @classifier_params: Indicates classifier parameters 420 * @bin_pwr_count: Indicates the number of FFT bins 421 * @lb_edge_extrabins: Number of extra bins on left band edge 422 * @rb_edge_extrabins: Number of extra bins on right band edge 423 * @bin_pwr_count_sec80: Indicates the number of FFT bins in secondary 80 424 * segment 425 * @bin_pwr: Contains FFT magnitudes 426 * @bin_pwr_sec80: Contains FFT magnitudes for the secondary 80 427 * segment 428 * @interf_list: List of interfernce sources 429 * @noise_floor: Indicates the current noise floor 430 * @noise_floor_sec80: Indicates the current noise floor for secondary 80 431 * segment 432 * @ch_width: Channel width 20/40/80/160 MHz 433 */ 434 struct spectral_samp_data { 435 int16_t spectral_data_len; 436 int16_t spectral_data_len_sec80; 437 int16_t spectral_rssi; 438 int16_t spectral_rssi_sec80; 439 int8_t spectral_combined_rssi; 440 int8_t spectral_upper_rssi; 441 int8_t spectral_lower_rssi; 442 int8_t spectral_chain_ctl_rssi[MAX_SPECTRAL_CHAINS]; 443 int8_t spectral_chain_ext_rssi[MAX_SPECTRAL_CHAINS]; 444 uint8_t spectral_max_scale; 445 int16_t spectral_bwinfo; 446 int32_t spectral_tstamp; 447 int16_t spectral_max_index; 448 int16_t spectral_max_index_sec80; 449 int16_t spectral_max_mag; 450 int16_t spectral_max_mag_sec80; 451 uint8_t spectral_max_exp; 452 int32_t spectral_last_tstamp; 453 int16_t spectral_upper_max_index; 454 int16_t spectral_lower_max_index; 455 uint8_t spectral_nb_upper; 456 uint8_t spectral_nb_lower; 457 struct spectral_classifier_params classifier_params; 458 uint16_t bin_pwr_count; 459 /* 460 * For 11ac chipsets prior to AR900B version 2.0, a max of 512 bins are 461 * delivered. However, there can be additional bins reported for 462 * AR900B version 2.0 and QCA9984 as described next: 463 * 464 * AR900B version 2.0: An additional tone is processed on the right 465 * hand side in order to facilitate detection of radar pulses out to 466 * the extreme band-edge of the channel frequency. 467 * Since the HW design processes four tones at a time, 468 * this requires one additional Dword to be added to the 469 * search FFT report. 470 * 471 * QCA9984: When spectral_scan_rpt_mode=2, i.e 2-dword summary + 472 * 1x-oversampled bins (in-band) per FFT, 473 * then 8 more bins (4 more on left side and 4 more on right side) 474 * are added. 475 */ 476 uint8_t lb_edge_extrabins; 477 uint8_t rb_edge_extrabins; 478 uint16_t bin_pwr_count_sec80; 479 uint8_t bin_pwr[MAX_NUM_BINS]; 480 uint8_t bin_pwr_sec80[MAX_NUM_BINS]; 481 struct interf_src_rsp interf_list; 482 int16_t noise_floor; 483 int16_t noise_floor_sec80; 484 uint32_t ch_width; 485 uint8_t spectral_agc_total_gain; 486 uint8_t spectral_agc_total_gain_sec80; 487 uint8_t spectral_gainchange; 488 uint8_t spectral_gainchange_sec80; 489 } __ATTRIB_PACKED; 490 491 /** 492 * struct spectral_samp_msg - Spectral SAMP message 493 * @signature: Validates the SAMP message 494 * @freq: Operating frequency in MHz 495 * @vhtop_ch_freq_seg1: VHT Segment 1 centre frequency in MHz 496 * @vhtop_ch_freq_seg2: VHT Segment 2 centre frequency in MHz 497 * @freq_loading: How busy was the channel 498 * @dcs_enabled: Whether DCS is enabled 499 * @int_type: Interference type indicated by DCS 500 * @macaddr: Indicates the device interface 501 * @samp_data: SAMP Data 502 */ 503 struct spectral_samp_msg { 504 uint32_t signature; 505 uint16_t freq; 506 uint16_t vhtop_ch_freq_seg1; 507 uint16_t vhtop_ch_freq_seg2; 508 uint16_t freq_loading; 509 uint16_t dcs_enabled; 510 enum dcs_int_type int_type; 511 uint8_t macaddr[6]; 512 struct spectral_samp_data samp_data; 513 } __ATTRIB_PACKED; 514 515 /* Forward declarations */ 516 struct wlan_objmgr_pdev; 517 518 /** 519 * struct spectral_nl_cb - Spectral Netlink callbacks 520 * @get_nbuff: Get the socket buffer to send the data to the application 521 * @send_nl_bcast: Send data to the application using netlink broadcast 522 * @send_nl_unicast: Send data to the application using netlink unicast 523 */ 524 struct spectral_nl_cb { 525 void *(*get_nbuff)(struct wlan_objmgr_pdev *pdev); 526 int (*send_nl_bcast)(struct wlan_objmgr_pdev *pdev); 527 int (*send_nl_unicast)(struct wlan_objmgr_pdev *pdev); 528 }; 529 530 #ifndef __KERNEL__ 531 532 static inline int16_t 533 spectral_pwfactor_max(int16_t pwfactor1, 534 int16_t pwfactor2) 535 { 536 return ((pwfactor1 > pwfactor2) ? pwfactor1 : pwfactor2); 537 } 538 539 /** 540 * get_spectral_scale_rssi_corr() - Compute RSSI correction factor for scaling 541 * @agc_total_gain_db: AGC total gain in dB steps 542 * @gen3_defmaxgain: Default max gain value of the gen III chipset 543 * @gen2_maxgain: Max gain value used by the reference gen II chipset 544 * @lowlevel_offset: Low level offset for scaling 545 * @inband_pwr: In band power in dB steps 546 * @rssi_thr: RSSI threshold for scaling 547 * 548 * Helper function to compute RSSI correction factor for Gen III linear format 549 * Spectral scaling. It is the responsibility of the caller to ensure that 550 * correct values are passed. 551 * 552 * Return: RSSI correction factor 553 */ 554 static inline int16_t 555 get_spectral_scale_rssi_corr(u_int8_t agc_total_gain_db, 556 u_int8_t gen3_defmaxgain, u_int8_t gen2_maxgain, 557 int16_t lowlevel_offset, int16_t inband_pwr, 558 int16_t rssi_thr) 559 { 560 return ((agc_total_gain_db < gen3_defmaxgain) ? 561 (gen2_maxgain - gen3_defmaxgain + lowlevel_offset) : 562 spectral_pwfactor_max((inband_pwr - rssi_thr), 0)); 563 } 564 565 /** 566 * spectral_scale_linear_to_gen2() - Scale linear bin value to gen II equivalent 567 * @gen3_binmag: Captured FFT bin value from the Spectral Search FFT report 568 * generated by the Gen III chipset 569 * @gen2_maxgain: Max gain value used by the reference gen II chipset 570 * @gen3_defmaxgain: Default max gain value of the gen III chipset 571 * @lowlevel_offset: Low level offset for scaling 572 * @inband_pwr: In band power in dB steps 573 * @rssi_thr: RSSI threshold for scaling 574 * @agc_total_gain_db: AGC total gain in dB steps 575 * @highlevel_offset: High level offset for scaling 576 * @gen2_bin_scale: Bin scale value used on reference gen II chipset 577 * @gen3_bin_scale: Bin scale value used on gen III chipset 578 * 579 * Helper function to scale a given gen III linear format bin value into an 580 * approximately equivalent gen II value. The scaled value can possibly be 581 * higher than 8 bits. If the caller is incapable of handling values larger 582 * than 8 bits, the caller can saturate the value at 255. This function does not 583 * carry out this saturation for the sake of flexibility so that callers 584 * interested in the larger values can avail of this. Also note it is the 585 * responsibility of the caller to ensure that correct values are passed. 586 * 587 * Return: Scaled bin value 588 */ 589 static inline u_int32_t 590 spectral_scale_linear_to_gen2(u_int8_t gen3_binmag, 591 u_int8_t gen2_maxgain, u_int8_t gen3_defmaxgain, 592 int16_t lowlevel_offset, int16_t inband_pwr, 593 int16_t rssi_thr, u_int8_t agc_total_gain_db, 594 int16_t highlevel_offset, u_int8_t gen2_bin_scale, 595 u_int8_t gen3_bin_scale) 596 { 597 return (gen3_binmag * 598 sqrt(pow(10, (((double)spectral_pwfactor_max(gen2_maxgain - 599 gen3_defmaxgain + lowlevel_offset - 600 get_spectral_scale_rssi_corr(agc_total_gain_db, 601 gen3_defmaxgain, 602 gen2_maxgain, 603 lowlevel_offset, 604 inband_pwr, 605 rssi_thr), 606 (agc_total_gain_db < gen3_defmaxgain) * 607 highlevel_offset)) / 10))) * 608 pow(2, (gen3_bin_scale - gen2_bin_scale))); 609 } 610 611 #endif /* __KERNEL__ */ 612 613 #ifdef WIN32 614 #pragma pack(pop, spectral) 615 #endif 616 #ifdef __ATTRIB_PACKED 617 #undef __ATTRIB_PACKED 618 #endif 619 620 #endif /* _WLAN_SPECTRAL_PUBLIC_STRUCTS_H_ */ 621