spectral_ioctl.h 16 KB

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