spectral_ioctl.h 17 KB

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