spectral_ioctl.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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. * @agile_spectral_cap_160: agile Spectral capability for 160 MHz
  219. * @agile_spectral_cap_80p80: agile Spectral capability for 80p80
  220. */
  221. struct spectral_caps {
  222. uint8_t phydiag_cap;
  223. uint8_t radar_cap;
  224. uint8_t spectral_cap;
  225. uint8_t advncd_spectral_cap;
  226. uint32_t hw_gen;
  227. bool is_scaling_params_populated;
  228. uint16_t formula_id;
  229. int16_t low_level_offset;
  230. int16_t high_level_offset;
  231. int16_t rssi_thr;
  232. uint8_t default_agc_max_gain;
  233. bool agile_spectral_cap;
  234. bool agile_spectral_cap_160;
  235. bool agile_spectral_cap_80p80;
  236. };
  237. #define SPECTRAL_IOCTL_PARAM_NOVAL (65535)
  238. #define MAX_SPECTRAL_CHAINS 3
  239. #define MAX_NUM_BINS 520
  240. /* 5 categories x (lower + upper) bands */
  241. #define MAX_INTERF 10
  242. /**
  243. * enum dcs_int_type - Interference type indicated by DCS
  244. * @SPECTRAL_DCS_INT_NONE: No interference
  245. * @SPECTRAL_DCS_INT_CW: CW interference
  246. * @SPECTRAL_DCS_INT_WIFI: WLAN interference
  247. */
  248. enum dcs_int_type {
  249. SPECTRAL_DCS_INT_NONE,
  250. SPECTRAL_DCS_INT_CW,
  251. SPECTRAL_DCS_INT_WIFI
  252. };
  253. /**
  254. * struct interf_rsp - Interference record
  255. * @interf_type: eINTERF_TYPE giving type of interference
  256. * @interf_min_freq: Minimum frequency in MHz at which interference has been
  257. * found
  258. * @interf_max_freq: Maximum frequency in MHz at which interference has been
  259. * found
  260. * @advncd_spectral_cap: Advanced spectral capability
  261. */
  262. struct interf_rsp {
  263. uint8_t interf_type;
  264. uint16_t interf_min_freq;
  265. uint16_t interf_max_freq;
  266. } __packed;
  267. /**
  268. * struct interf_src_rsp - List of interference sources
  269. * @count: Number of interference records
  270. * @interf: Array of interference records
  271. */
  272. struct interf_src_rsp {
  273. uint16_t count;
  274. struct interf_rsp interf[MAX_INTERF];
  275. } __packed;
  276. /**
  277. * struct spectral_classifier_params - spectral classifier parameters
  278. * @spectral_20_40_mode: Is AP in 20/40 mode?
  279. * @spectral_dc_index: DC index
  280. * @spectral_dc_in_mhz: DC in MHz
  281. * @upper_chan_in_mhz: Upper channel in MHz
  282. * @lower_chan_in_mhz: Lower channel in MHz
  283. */
  284. struct spectral_classifier_params {
  285. int spectral_20_40_mode;
  286. int spectral_dc_index;
  287. int spectral_dc_in_mhz;
  288. int upper_chan_in_mhz;
  289. int lower_chan_in_mhz;
  290. } __packed;
  291. /**
  292. * struct spectral_samp_data - Spectral Analysis Messaging Protocol Data format
  293. * @spectral_data_len: Indicates the bin size
  294. * @spectral_data_len_sec80: Indicates the bin size for secondary 80 segment
  295. * @spectral_rssi: Indicates RSSI
  296. * @spectral_rssi_sec80: Indicates RSSI for secondary 80 segment
  297. * @spectral_combined_rssi: Indicates combined RSSI from all antennas
  298. * @spectral_upper_rssi: Indicates RSSI of upper band
  299. * @spectral_lower_rssi: Indicates RSSI of lower band
  300. * @spectral_chain_ctl_rssi: RSSI for control channel, for all antennas
  301. * @spectral_chain_ext_rssi: RSSI for extension channel, for all antennas
  302. * @spectral_max_scale: Indicates scale factor
  303. * @spectral_bwinfo: Indicates bandwidth info
  304. * @spectral_tstamp: Indicates timestamp
  305. * @spectral_max_index: Indicates the index of max magnitude
  306. * @spectral_max_index_sec80: Indicates the index of max magnitude for secondary
  307. * 80 segment
  308. * @spectral_max_mag: Indicates the maximum magnitude
  309. * @spectral_max_mag_sec80: Indicates the maximum magnitude for secondary 80
  310. * segment
  311. * @spectral_max_exp: Indicates the max exp
  312. * @spectral_last_tstamp: Indicates the last time stamp
  313. * @spectral_upper_max_index: Indicates the index of max mag in upper band
  314. * @spectral_lower_max_index: Indicates the index of max mag in lower band
  315. * @spectral_nb_upper: Not Used
  316. * @spectral_nb_lower: Not Used
  317. * @classifier_params: Indicates classifier parameters
  318. * @bin_pwr_count: Indicates the number of FFT bins
  319. * @lb_edge_extrabins: Number of extra bins on left band edge
  320. * @rb_edge_extrabins: Number of extra bins on right band edge
  321. * @bin_pwr_count_sec80: Indicates the number of FFT bins in secondary 80
  322. * segment
  323. * @bin_pwr: Contains FFT magnitudes
  324. * @bin_pwr_sec80: Contains FFT magnitudes for the secondary 80
  325. * segment
  326. * @interf_list: List of interfernce sources
  327. * @noise_floor: Indicates the current noise floor
  328. * @noise_floor_sec80: Indicates the current noise floor for secondary 80
  329. * segment
  330. * @ch_width: Channel width 20/40/80/160 MHz
  331. * @spectral_mode: Spectral scan mode
  332. * @spectral_pri80ind: Indication from hardware that the sample was
  333. * received on the primary 80 MHz segment. If this
  334. * is set when smode = SPECTRAL_SCAN_MODE_AGILE, it
  335. * indicates that Spectral was carried out on pri80
  336. * instead of the Agile frequency due to a
  337. * channel switch - Software may choose
  338. * to ignore the sample in this case.
  339. * @spectral_pri80ind_sec80: Indication from hardware that the sample was
  340. * received on the primary 80 MHz segment instead of
  341. * the secondary 80 MHz segment due to a channel
  342. * switch - Software may choose to ignore the sample
  343. * if this is set. Applicable only if smode =
  344. * SPECTRAL_SCAN_MODE_NORMAL and for 160/80+80 MHz
  345. * Spectral operation.
  346. */
  347. struct spectral_samp_data {
  348. int16_t spectral_data_len;
  349. int16_t spectral_data_len_sec80;
  350. int16_t spectral_rssi;
  351. int16_t spectral_rssi_sec80;
  352. int8_t spectral_combined_rssi;
  353. int8_t spectral_upper_rssi;
  354. int8_t spectral_lower_rssi;
  355. int8_t spectral_chain_ctl_rssi[MAX_SPECTRAL_CHAINS];
  356. int8_t spectral_chain_ext_rssi[MAX_SPECTRAL_CHAINS];
  357. uint8_t spectral_max_scale;
  358. int16_t spectral_bwinfo;
  359. int32_t spectral_tstamp;
  360. int16_t spectral_max_index;
  361. int16_t spectral_max_index_sec80;
  362. int16_t spectral_max_mag;
  363. int16_t spectral_max_mag_sec80;
  364. uint8_t spectral_max_exp;
  365. int32_t spectral_last_tstamp;
  366. int16_t spectral_upper_max_index;
  367. int16_t spectral_lower_max_index;
  368. uint8_t spectral_nb_upper;
  369. uint8_t spectral_nb_lower;
  370. struct spectral_classifier_params classifier_params;
  371. uint16_t bin_pwr_count;
  372. /*
  373. * For 11ac chipsets prior to AR900B version 2.0, a max of 512 bins are
  374. * delivered. However, there can be additional bins reported for
  375. * AR900B version 2.0 and QCA9984 as described next:
  376. *
  377. * AR900B version 2.0: An additional tone is processed on the right
  378. * hand side in order to facilitate detection of radar pulses out to
  379. * the extreme band-edge of the channel frequency.
  380. * Since the HW design processes four tones at a time,
  381. * this requires one additional Dword to be added to the
  382. * search FFT report.
  383. *
  384. * QCA9984: When spectral_scan_rpt_mode=2, i.e 2-dword summary +
  385. * 1x-oversampled bins (in-band) per FFT,
  386. * then 8 more bins (4 more on left side and 4 more on right side)
  387. * are added.
  388. */
  389. uint8_t lb_edge_extrabins;
  390. uint8_t rb_edge_extrabins;
  391. uint16_t bin_pwr_count_sec80;
  392. uint8_t bin_pwr[MAX_NUM_BINS];
  393. uint8_t bin_pwr_sec80[MAX_NUM_BINS];
  394. struct interf_src_rsp interf_list;
  395. int16_t noise_floor;
  396. int16_t noise_floor_sec80;
  397. uint32_t ch_width;
  398. uint8_t spectral_agc_total_gain;
  399. uint8_t spectral_agc_total_gain_sec80;
  400. uint8_t spectral_gainchange;
  401. uint8_t spectral_gainchange_sec80;
  402. enum spectral_scan_mode spectral_mode;
  403. uint8_t spectral_pri80ind;
  404. uint8_t spectral_pri80ind_sec80;
  405. } __packed;
  406. /**
  407. * struct spectral_samp_msg - Spectral SAMP message
  408. * @signature: Validates the SAMP message
  409. * @freq: Operating frequency in MHz
  410. * @vhtop_ch_freq_seg1: VHT Segment 1 centre frequency in MHz
  411. * @vhtop_ch_freq_seg2: VHT Segment 2 centre frequency in MHz
  412. * @agile_freq: Center frequency in MHz of the entire span across which
  413. * Agile Spectral is carried out. Applicable only for Agile
  414. * Spectral samples.
  415. * @freq_loading: How busy was the channel
  416. * @dcs_enabled: Whether DCS is enabled
  417. * @int_type: Interference type indicated by DCS
  418. * @macaddr: Indicates the device interface
  419. * @samp_data: SAMP Data
  420. */
  421. struct spectral_samp_msg {
  422. uint32_t signature;
  423. uint16_t freq;
  424. uint16_t vhtop_ch_freq_seg1;
  425. uint16_t vhtop_ch_freq_seg2;
  426. uint16_t agile_freq;
  427. uint16_t freq_loading;
  428. uint16_t dcs_enabled;
  429. enum dcs_int_type int_type;
  430. uint8_t macaddr[6];
  431. struct spectral_samp_data samp_data;
  432. } __packed;
  433. #endif