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