spectral_ioctl.h 17 KB

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