1 /* 2 * Copyright (c) 2011, 2017-2019 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all 7 * copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef _SPECTRAL_IOCTL_H_ 20 #define _SPECTRAL_IOCTL_H_ 21 #include <wlan_dfs_ioctl.h> 22 23 #ifndef AH_MAX_CHAINS 24 #define AH_MAX_CHAINS 3 25 #endif 26 27 /* 28 * ioctl defines 29 */ 30 31 #define SPECTRAL_SET_CONFIG (DFS_LAST_IOCTL + 1) 32 #define SPECTRAL_GET_CONFIG (DFS_LAST_IOCTL + 2) 33 #define SPECTRAL_SHOW_INTERFERENCE (DFS_LAST_IOCTL + 3) 34 #define SPECTRAL_ENABLE_SCAN (DFS_LAST_IOCTL + 4) 35 #define SPECTRAL_DISABLE_SCAN (DFS_LAST_IOCTL + 5) 36 #define SPECTRAL_ACTIVATE_SCAN (DFS_LAST_IOCTL + 6) 37 #define SPECTRAL_STOP_SCAN (DFS_LAST_IOCTL + 7) 38 #define SPECTRAL_SET_DEBUG_LEVEL (DFS_LAST_IOCTL + 8) 39 #define SPECTRAL_IS_ACTIVE (DFS_LAST_IOCTL + 9) 40 #define SPECTRAL_IS_ENABLED (DFS_LAST_IOCTL + 10) 41 #define SPECTRAL_CLASSIFY_SCAN (DFS_LAST_IOCTL + 11) 42 #define SPECTRAL_GET_CLASSIFIER_CONFIG (DFS_LAST_IOCTL + 12) 43 #define SPECTRAL_EACS (DFS_LAST_IOCTL + 13) 44 #define SPECTRAL_ACTIVATE_FULL_SCAN (DFS_LAST_IOCTL + 14) 45 #define SPECTRAL_STOP_FULL_SCAN (DFS_LAST_IOCTL + 15) 46 #define SPECTRAL_GET_CAPABILITY_INFO (DFS_LAST_IOCTL + 16) 47 #define SPECTRAL_GET_DIAG_STATS (DFS_LAST_IOCTL + 17) 48 #define SPECTRAL_GET_CHAN_WIDTH (DFS_LAST_IOCTL + 18) 49 #define SPECTRAL_GET_CHANINFO (DFS_LAST_IOCTL + 19) 50 #define SPECTRAL_CLEAR_CHANINFO (DFS_LAST_IOCTL + 20) 51 #define SPECTRAL_SET_ICM_ACTIVE (DFS_LAST_IOCTL + 21) 52 #define SPECTRAL_GET_NOMINAL_NOISEFLOOR (DFS_LAST_IOCTL + 22) 53 #define SPECTRAL_GET_DEBUG_LEVEL (DFS_LAST_IOCTL + 23) 54 #define SPECTRAL_SET_DMA_DEBUG (DFS_LAST_IOCTL + 24) 55 56 /* 57 * ioctl parameter types 58 */ 59 enum spectral_params { 60 SPECTRAL_PARAM_FFT_PERIOD, 61 SPECTRAL_PARAM_SCAN_PERIOD, 62 SPECTRAL_PARAM_SCAN_COUNT, 63 SPECTRAL_PARAM_SHORT_REPORT, 64 SPECTRAL_PARAM_SPECT_PRI, 65 SPECTRAL_PARAM_FFT_SIZE, 66 SPECTRAL_PARAM_GC_ENA, 67 SPECTRAL_PARAM_RESTART_ENA, 68 SPECTRAL_PARAM_NOISE_FLOOR_REF, 69 SPECTRAL_PARAM_INIT_DELAY, 70 SPECTRAL_PARAM_NB_TONE_THR, 71 SPECTRAL_PARAM_STR_BIN_THR, 72 SPECTRAL_PARAM_WB_RPT_MODE, 73 SPECTRAL_PARAM_RSSI_RPT_MODE, 74 SPECTRAL_PARAM_RSSI_THR, 75 SPECTRAL_PARAM_PWR_FORMAT, 76 SPECTRAL_PARAM_RPT_MODE, 77 SPECTRAL_PARAM_BIN_SCALE, 78 SPECTRAL_PARAM_DBM_ADJ, 79 SPECTRAL_PARAM_CHN_MASK, 80 SPECTRAL_PARAM_ACTIVE, 81 SPECTRAL_PARAM_STOP, 82 SPECTRAL_PARAM_ENABLE, 83 SPECTRAL_PARAM_FREQUENCY, 84 SPECTRAL_PARAM_CHAN_FREQUENCY, 85 SPECTRAL_PARAM_CHAN_WIDTH, 86 SPECTRAL_PARAM_MAX, 87 }; 88 89 /** 90 * enum spectral_scan_mode - Spectral scan mode 91 * @SPECTRAL_SCAN_MODE_NORMAL: Normal mode 92 * @SPECTRAL_SCAN_MODE_AGILE: Agile mode 93 */ 94 enum spectral_scan_mode { 95 SPECTRAL_SCAN_MODE_NORMAL, 96 SPECTRAL_SCAN_MODE_AGILE, 97 SPECTRAL_SCAN_MODE_MAX, 98 }; 99 100 struct spectral_ioctl_params { 101 int16_t spectral_fft_period; 102 int16_t pectral_period; 103 int16_t spectral_count; 104 uint16_t spectral_short_report; 105 uint16_t spectral_pri; 106 }; 107 108 /** 109 * spectral_cap_hw_gen: Definitions for the Spectral hardware generation. 110 * This corresponds to definitions in qca_wlan_vendor_spectral_scan_cap_hw_gen. 111 * @SPECTRAL_CAP_HW_GEN_1: Generation 1 112 * @SPECTRAL_CAP_HW_GEN_2: Generation 2 113 * @SPECTRAL_CAP_HW_GEN_3: Generation 3 114 */ 115 enum spectral_cap_hw_gen { 116 SPECTRAL_CAP_HW_GEN_1 = 0, 117 SPECTRAL_CAP_HW_GEN_2 = 1, 118 SPECTRAL_CAP_HW_GEN_3 = 2, 119 }; 120 121 /** 122 * struct spectral_config - spectral config parameters 123 * @ss_fft_period: Skip interval for FFT reports 124 * @ss_period: Spectral scan period 125 * @ss_count: # of reports to return from ss_active 126 * @ss_short_report: Set to report only 1 set of FFT results 127 * @radar_bin_thresh_sel: Select threshold to classify strong bin for FFT 128 * @ss_spectral_pri: Priority, and are we doing a noise power cal ? 129 * @ss_fft_size: Defines the number of FFT data points to compute, 130 * defined as a log index num_fft_pts = 131 * 2^ss_fft_size 132 * @ss_gc_ena: Set, to enable targeted gain change before 133 * starting the spectral scan FFT 134 * @ss_restart_ena: Set, to enable abort of receive frames when in high 135 * priority and a spectral scan is queued 136 * @ss_noise_floor_ref: Noise floor reference number (signed) for the 137 * calculation of bin power (dBm) Though stored as an 138 * unsigned this should be treated as a signed 8-bit int. 139 * @ss_init_delay: Disallow spectral scan triggers after tx/rx packets 140 * by setting this delay value to roughly SIFS time 141 * period or greater Delay timer count in units of 0.25us 142 * @ss_nb_tone_thr: Number of strong bins (inclusive) per sub-channel, 143 * below which a signal is declared a narrowband tone 144 * @ss_str_bin_thr: Bin/max_bin ratio threshold over which a bin is 145 * declared strong (for spectral scan bandwidth analysis) 146 * @ss_wb_rpt_mode: Set this bit to report spectral scans as EXT_BLOCKER 147 * (phy_error=36), if none of the sub-channels are 148 * deemed narrowband 149 * @ss_rssi_rpt_mode: Set this bit to report spectral scans as EXT_BLOCKER 150 * (phy_error=36), if the ADC RSSI is below the 151 * threshold ss_rssi_thr 152 * @ss_rssi_thr: ADC RSSI must be greater than or equal to this 153 * threshold (signed Db) to ensure spectral scan 154 * reporting with normal phy error codes (please see 155 * ss_rssi_rpt_mode above).Though stored as an unsigned 156 * value, this should be treated as a signed 8-bit int 157 * @ss_pwr_format: Format of frequency bin magnitude for spectral scan 158 * triggered FFTs 0: linear magnitude 159 * 1: log magnitude (20*log10(lin_mag), 1/2 dB step size) 160 * @ss_rpt_mode: Format of per-FFT reports to software for spectral 161 * scan triggered FFTs 162 * 0: No FFT report (only pulse end summary) 163 * 1: 2-dword summary of metrics for each completed FFT 164 * 2: 2-dword summary + 1x-oversampled bins(in-band) per 165 * FFT 166 * 3: 2-dword summary + 2x-oversampled bins (all) per FFT 167 * @ss_bin_scale: Number of LSBs to shift out to scale the FFT bins 168 * for spectral scan triggered FFTs 169 * @ss_dbm_adj: Set (with ss_pwr_format=1), to report bin 170 * magnitudes 171 * converted to dBm power using the noisefloor 172 * calibration results 173 * @ss_chn_mask: Per chain enable mask to select input ADC for search 174 * FFT 175 * @ss_nf_cal: nf calibrated values for ctl+ext 176 * @ss_nf_pwr: nf pwr values for ctl+ext 177 * @ss_nf_temp_data: temperature data taken during nf scan 178 * @ss_frequency: This specifies the frequency span over which Spectral 179 * scan would be carried out. Its value depends on the 180 * Spectral scan mode. 181 * Normal mode:- 182 * Not applicable. Spectral scan would happen in the 183 * operating span. 184 * Agile mode:- 185 * Center frequency (in MHz) of the interested span 186 * or center frequency (in MHz) of any WLAN channel 187 * in the interested span. 188 */ 189 struct spectral_config { 190 uint16_t ss_fft_period; 191 uint16_t ss_period; 192 uint16_t ss_count; 193 uint16_t ss_short_report; 194 uint8_t radar_bin_thresh_sel; 195 uint16_t ss_spectral_pri; 196 uint16_t ss_fft_size; 197 uint16_t ss_gc_ena; 198 uint16_t ss_restart_ena; 199 uint16_t ss_noise_floor_ref; 200 uint16_t ss_init_delay; 201 uint16_t ss_nb_tone_thr; 202 uint16_t ss_str_bin_thr; 203 uint16_t ss_wb_rpt_mode; 204 uint16_t ss_rssi_rpt_mode; 205 uint16_t ss_rssi_thr; 206 uint16_t ss_pwr_format; 207 uint16_t ss_rpt_mode; 208 uint16_t ss_bin_scale; 209 uint16_t ss_dbm_adj; 210 uint16_t ss_chn_mask; 211 int8_t ss_nf_cal[AH_MAX_CHAINS * 2]; 212 int8_t ss_nf_pwr[AH_MAX_CHAINS * 2]; 213 int32_t ss_nf_temp_data; 214 uint32_t ss_frequency; 215 }; 216 217 /** 218 * struct spectral_caps - Spectral capabilities structure 219 * @phydiag_cap: Phydiag capability 220 * @radar_cap: Radar detection capability 221 * @spectral_cap: Spectral capability 222 * @advncd_spectral_cap: Advanced spectral capability 223 * @hw_gen: Spectral hw generation as defined in spectral_cap_hw_gen 224 * @is_scaling_params_populated: indicates whether scaling params is populated 225 * @formula_id: formula_id 226 * @low_level_offset: low_level_offset 227 * @high_level_offset: high_level_offset 228 * @rssi_thr: rssi_thr 229 * @default_agc_max_gain: default_agc_max_gain 230 * @agile_spectral_cap: agile Spectral capability for 20/40/80 231 * @agile_spectral_cap_160: agile Spectral capability for 160 MHz 232 * @agile_spectral_cap_80p80: agile Spectral capability for 80p80 233 */ 234 struct spectral_caps { 235 uint8_t phydiag_cap; 236 uint8_t radar_cap; 237 uint8_t spectral_cap; 238 uint8_t advncd_spectral_cap; 239 uint32_t hw_gen; 240 bool is_scaling_params_populated; 241 uint16_t formula_id; 242 int16_t low_level_offset; 243 int16_t high_level_offset; 244 int16_t rssi_thr; 245 uint8_t default_agc_max_gain; 246 bool agile_spectral_cap; 247 bool agile_spectral_cap_160; 248 bool agile_spectral_cap_80p80; 249 }; 250 251 #define SPECTRAL_IOCTL_PARAM_NOVAL (65535) 252 253 #define MAX_SPECTRAL_CHAINS 3 254 #define MAX_NUM_BINS 520 255 /* 5 categories x (lower + upper) bands */ 256 #define MAX_INTERF 10 257 258 /** 259 * enum dcs_int_type - Interference type indicated by DCS 260 * @SPECTRAL_DCS_INT_NONE: No interference 261 * @SPECTRAL_DCS_INT_CW: CW interference 262 * @SPECTRAL_DCS_INT_WIFI: WLAN interference 263 */ 264 enum dcs_int_type { 265 SPECTRAL_DCS_INT_NONE, 266 SPECTRAL_DCS_INT_CW, 267 SPECTRAL_DCS_INT_WIFI 268 }; 269 270 /** 271 * struct interf_rsp - Interference record 272 * @interf_type: eINTERF_TYPE giving type of interference 273 * @interf_min_freq: Minimum frequency in MHz at which interference has been 274 * found 275 * @interf_max_freq: Maximum frequency in MHz at which interference has been 276 * found 277 * @advncd_spectral_cap: Advanced spectral capability 278 */ 279 struct interf_rsp { 280 uint8_t interf_type; 281 uint16_t interf_min_freq; 282 uint16_t interf_max_freq; 283 } __packed; 284 285 /** 286 * struct interf_src_rsp - List of interference sources 287 * @count: Number of interference records 288 * @interf: Array of interference records 289 */ 290 struct interf_src_rsp { 291 uint16_t count; 292 struct interf_rsp interf[MAX_INTERF]; 293 } __packed; 294 295 /** 296 * struct spectral_classifier_params - spectral classifier parameters 297 * @spectral_20_40_mode: Is AP in 20/40 mode? 298 * @spectral_dc_index: DC index 299 * @spectral_dc_in_mhz: DC in MHz 300 * @upper_chan_in_mhz: Upper channel in MHz 301 * @lower_chan_in_mhz: Lower channel in MHz 302 */ 303 struct spectral_classifier_params { 304 int spectral_20_40_mode; 305 int spectral_dc_index; 306 int spectral_dc_in_mhz; 307 int upper_chan_in_mhz; 308 int lower_chan_in_mhz; 309 } __packed; 310 311 /** 312 * struct spectral_samp_data - Spectral Analysis Messaging Protocol Data format 313 * @spectral_data_len: Indicates the bin size 314 * @spectral_data_len_sec80: Indicates the bin size for secondary 80 segment 315 * @spectral_rssi: Indicates RSSI 316 * @spectral_rssi_sec80: Indicates RSSI for secondary 80 segment 317 * @spectral_combined_rssi: Indicates combined RSSI from all antennas 318 * @spectral_upper_rssi: Indicates RSSI of upper band 319 * @spectral_lower_rssi: Indicates RSSI of lower band 320 * @spectral_chain_ctl_rssi: RSSI for control channel, for all antennas 321 * @spectral_chain_ext_rssi: RSSI for extension channel, for all antennas 322 * @spectral_max_scale: Indicates scale factor 323 * @spectral_bwinfo: Indicates bandwidth info 324 * @spectral_tstamp: Indicates timestamp 325 * @spectral_max_index: Indicates the index of max magnitude 326 * @spectral_max_index_sec80: Indicates the index of max magnitude for secondary 327 * 80 segment 328 * @spectral_max_mag: Indicates the maximum magnitude 329 * @spectral_max_mag_sec80: Indicates the maximum magnitude for secondary 80 330 * segment 331 * @spectral_max_exp: Indicates the max exp 332 * @spectral_last_tstamp: Indicates the last time stamp 333 * @spectral_upper_max_index: Indicates the index of max mag in upper band 334 * @spectral_lower_max_index: Indicates the index of max mag in lower band 335 * @spectral_nb_upper: Not Used 336 * @spectral_nb_lower: Not Used 337 * @classifier_params: Indicates classifier parameters 338 * @bin_pwr_count: Indicates the number of FFT bins 339 * @lb_edge_extrabins: Number of extra bins on left band edge 340 * @rb_edge_extrabins: Number of extra bins on right band edge 341 * @bin_pwr_count_sec80: Indicates the number of FFT bins in secondary 80 342 * segment 343 * @bin_pwr: Contains FFT magnitudes 344 * @bin_pwr_sec80: Contains FFT magnitudes for the secondary 80 345 * segment 346 * @interf_list: List of interfernce sources 347 * @noise_floor: Indicates the current noise floor 348 * @noise_floor_sec80: Indicates the current noise floor for secondary 80 349 * segment 350 * @ch_width: Channel width 20/40/80/160 MHz 351 * @spectral_mode: Spectral scan mode 352 * @spectral_pri80ind: Indication from hardware that the sample was 353 * received on the primary 80 MHz segment. If this 354 * is set when smode = SPECTRAL_SCAN_MODE_AGILE, it 355 * indicates that Spectral was carried out on pri80 356 * instead of the Agile frequency due to a 357 * channel switch - Software may choose 358 * to ignore the sample in this case. 359 * @spectral_pri80ind_sec80: Indication from hardware that the sample was 360 * received on the primary 80 MHz segment instead of 361 * the secondary 80 MHz segment due to a channel 362 * switch - Software may choose to ignore the sample 363 * if this is set. Applicable only if smode = 364 * SPECTRAL_SCAN_MODE_NORMAL and for 160/80+80 MHz 365 * Spectral operation. 366 * @last_raw_timestamp: Previous FFT report's raw timestamp. In case of 367 * 160Mhz it will be primary 80 segment's timestamp 368 * as both primary & secondary segment's timestamp 369 * are expected to be almost equal. 370 * @timestamp_war_offset: Offset calculated based on reset_delay and 371 * last_raw_timestamp. It will be added to 372 * raw_timestamp to get spectral_tstamp. 373 * @raw_timestamp: Actual FFT timestamp reported by HW on primary 374 * segment. 375 * @raw_timestamp_sec80: Actual FFT timestamp reported by HW on sec80 MHz 376 * segment. 377 * @reset_delay: Time gap between the last spectral report before 378 * reset and the end of reset. It is provided by FW 379 * via direct DMA framework. 380 * @target_reset_count: Indicates the number of times target went through 381 * reset routine after spectral was enabled. 382 */ 383 struct spectral_samp_data { 384 int16_t spectral_data_len; 385 int16_t spectral_data_len_sec80; 386 int16_t spectral_rssi; 387 int16_t spectral_rssi_sec80; 388 int8_t spectral_combined_rssi; 389 int8_t spectral_upper_rssi; 390 int8_t spectral_lower_rssi; 391 int8_t spectral_chain_ctl_rssi[MAX_SPECTRAL_CHAINS]; 392 int8_t spectral_chain_ext_rssi[MAX_SPECTRAL_CHAINS]; 393 uint8_t spectral_max_scale; 394 int16_t spectral_bwinfo; 395 int32_t spectral_tstamp; 396 int16_t spectral_max_index; 397 int16_t spectral_max_index_sec80; 398 int16_t spectral_max_mag; 399 int16_t spectral_max_mag_sec80; 400 uint8_t spectral_max_exp; 401 int32_t spectral_last_tstamp; 402 int16_t spectral_upper_max_index; 403 int16_t spectral_lower_max_index; 404 uint8_t spectral_nb_upper; 405 uint8_t spectral_nb_lower; 406 struct spectral_classifier_params classifier_params; 407 uint16_t bin_pwr_count; 408 /* 409 * For 11ac chipsets prior to AR900B version 2.0, a max of 512 bins are 410 * delivered. However, there can be additional bins reported for 411 * AR900B version 2.0 and QCA9984 as described next: 412 * 413 * AR900B version 2.0: An additional tone is processed on the right 414 * hand side in order to facilitate detection of radar pulses out to 415 * the extreme band-edge of the channel frequency. 416 * Since the HW design processes four tones at a time, 417 * this requires one additional Dword to be added to the 418 * search FFT report. 419 * 420 * QCA9984: When spectral_scan_rpt_mode=2, i.e 2-dword summary + 421 * 1x-oversampled bins (in-band) per FFT, 422 * then 8 more bins (4 more on left side and 4 more on right side) 423 * are added. 424 */ 425 uint8_t lb_edge_extrabins; 426 uint8_t rb_edge_extrabins; 427 uint16_t bin_pwr_count_sec80; 428 uint8_t bin_pwr[MAX_NUM_BINS]; 429 uint8_t bin_pwr_sec80[MAX_NUM_BINS]; 430 struct interf_src_rsp interf_list; 431 int16_t noise_floor; 432 int16_t noise_floor_sec80; 433 uint32_t ch_width; 434 uint8_t spectral_agc_total_gain; 435 uint8_t spectral_agc_total_gain_sec80; 436 uint8_t spectral_gainchange; 437 uint8_t spectral_gainchange_sec80; 438 enum spectral_scan_mode spectral_mode; 439 uint8_t spectral_pri80ind; 440 uint8_t spectral_pri80ind_sec80; 441 uint32_t last_raw_timestamp; 442 uint32_t timestamp_war_offset; 443 uint32_t raw_timestamp; 444 uint32_t raw_timestamp_sec80; 445 uint32_t reset_delay; 446 uint32_t target_reset_count; 447 uint32_t agile_ch_width; 448 } __packed; 449 450 /** 451 * struct spectral_samp_msg - Spectral SAMP message 452 * @signature: Validates the SAMP message 453 * @freq: Operating frequency in MHz 454 * @vhtop_ch_freq_seg1: VHT Segment 1 centre frequency in MHz 455 * @vhtop_ch_freq_seg2: VHT Segment 2 centre frequency in MHz 456 * @agile_freq: Center frequency in MHz of the entire span across which 457 * Agile Spectral is carried out. Applicable only for Agile 458 * Spectral samples. 459 * @freq_loading: How busy was the channel 460 * @dcs_enabled: Whether DCS is enabled 461 * @int_type: Interference type indicated by DCS 462 * @macaddr: Indicates the device interface 463 * @samp_data: SAMP Data 464 */ 465 struct spectral_samp_msg { 466 uint32_t signature; 467 uint16_t freq; 468 uint16_t vhtop_ch_freq_seg1; 469 uint16_t vhtop_ch_freq_seg2; 470 uint16_t agile_freq; 471 uint16_t freq_loading; 472 uint16_t dcs_enabled; 473 enum dcs_int_type int_type; 474 uint8_t macaddr[6]; 475 struct spectral_samp_data samp_data; 476 } __packed; 477 478 #endif 479