spectral_ioctl.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. /*
  2. * Copyright (c) 2011, 2017-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #ifndef _SPECTRAL_IOCTL_H_
  20. #define _SPECTRAL_IOCTL_H_
  21. #include <wlan_dfs_ioctl.h>
  22. #ifndef AH_MAX_CHAINS
  23. #define AH_MAX_CHAINS 3
  24. #endif
  25. /* Compile time Assert */
  26. #define SPECTRAL_COMPILE_TIME_ASSERT(assertion_name, predicate) \
  27. typedef char assertion_name[(predicate) ? 1 : -1]
  28. /*
  29. * ioctl defines
  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. #define SPECTRAL_SET_DMA_DEBUG (DFS_LAST_IOCTL + 24)
  55. /*
  56. * Increase spectral sub version if struct spectral_samp_msg updated.
  57. */
  58. #define SPECTRAL_VERSION (3)
  59. #define SPECTRAL_SUB_VERSION (1)
  60. /*
  61. * ioctl parameter types
  62. */
  63. enum spectral_params {
  64. SPECTRAL_PARAM_FFT_PERIOD,
  65. SPECTRAL_PARAM_SCAN_PERIOD,
  66. SPECTRAL_PARAM_FFT_RECAPTURE,
  67. SPECTRAL_PARAM_SCAN_COUNT,
  68. SPECTRAL_PARAM_SHORT_REPORT,
  69. SPECTRAL_PARAM_SPECT_PRI,
  70. SPECTRAL_PARAM_FFT_SIZE,
  71. SPECTRAL_PARAM_GC_ENA,
  72. SPECTRAL_PARAM_RESTART_ENA,
  73. SPECTRAL_PARAM_NOISE_FLOOR_REF,
  74. SPECTRAL_PARAM_INIT_DELAY,
  75. SPECTRAL_PARAM_NB_TONE_THR,
  76. SPECTRAL_PARAM_STR_BIN_THR,
  77. SPECTRAL_PARAM_WB_RPT_MODE,
  78. SPECTRAL_PARAM_RSSI_RPT_MODE,
  79. SPECTRAL_PARAM_RSSI_THR,
  80. SPECTRAL_PARAM_PWR_FORMAT,
  81. SPECTRAL_PARAM_RPT_MODE,
  82. SPECTRAL_PARAM_BIN_SCALE,
  83. SPECTRAL_PARAM_DBM_ADJ,
  84. SPECTRAL_PARAM_CHN_MASK,
  85. SPECTRAL_PARAM_ACTIVE,
  86. SPECTRAL_PARAM_STOP,
  87. SPECTRAL_PARAM_ENABLE,
  88. SPECTRAL_PARAM_FREQUENCY,
  89. SPECTRAL_PARAM_CHAN_FREQUENCY,
  90. SPECTRAL_PARAM_CHAN_WIDTH,
  91. SPECTRAL_PARAM_MAX,
  92. };
  93. /**
  94. * enum spectral_report_mode: Spectral report mode
  95. * @SPECTRAL_REPORT_MODE_0: No FFT report (only spectral scan summary report)
  96. * @SPECTRAL_REPORT_MODE_1: FFT report header + spectral scan summary report
  97. * @SPECTRAL_REPORT_MODE_2: FFt report header + in-band bins per
  98. * FFT (half of the number of FFT bins), where the
  99. * FFT input is sampled at two times the channel
  100. * bandwidth + spectral scan summary report
  101. * @SPECTRAL_REPORT_MODE_3: FFT report header + all bins per FFT, where the FFT
  102. * input is sampled at two times the channel bandwidth
  103. * + spectral scan summary report
  104. * @SPECTRAL_REPORT_MODE_MAX: Max number of report modes
  105. */
  106. enum spectral_report_mode {
  107. SPECTRAL_REPORT_MODE_0,
  108. SPECTRAL_REPORT_MODE_1,
  109. SPECTRAL_REPORT_MODE_2,
  110. SPECTRAL_REPORT_MODE_3,
  111. SPECTRAL_REPORT_MODE_MAX,
  112. };
  113. /**
  114. * enum spectral_pwr_format: Spectral FFT bin pwr format
  115. * @SPECTRAL_PWR_FORMAT_LINEAR: Linear mode
  116. * @SPECTRAL_PWR_FORMAT_DBM: dBm mode
  117. */
  118. enum spectral_pwr_format {
  119. SPECTRAL_PWR_FORMAT_LINEAR = 0,
  120. SPECTRAL_PWR_FORMAT_DBM = 1,
  121. };
  122. /**
  123. * enum spectral_scan_priority: Spectral scan priority
  124. * @SPECTRAL_SCAN_PRIORITY_LOW: Low priority Spectral scan
  125. * @SPECTRAL_SCAN_PRIORITY_HIGH: High priority Spectral scan
  126. */
  127. enum spectral_scan_priority {
  128. SPECTRAL_SCAN_PRIORITY_LOW = 0,
  129. SPECTRAL_SCAN_PRIORITY_HIGH = 1,
  130. };
  131. /**
  132. * enum spectral_fft_size : FFT size values
  133. * @SPECTRAL_FFT_SIZE_INVALID: Invalid FFT size
  134. * @SPECTRAL_FFT_SIZE_1: FFT size 1
  135. * @SPECTRAL_FFT_SIZE_2: FFT size 2
  136. * @SPECTRAL_FFT_SIZE_3: FFT size 3
  137. * @SPECTRAL_FFT_SIZE_4: FFT size 4
  138. * @SPECTRAL_FFT_SIZE_5: FFT size 5
  139. * @SPECTRAL_FFT_SIZE_6: FFT size 6
  140. * @SPECTRAL_FFT_SIZE_7: FFT size 7
  141. * @SPECTRAL_FFT_SIZE_8: FFT size 8
  142. * @SPECTRAL_FFT_SIZE_9: FFT size 9
  143. * @SPECTRAL_FFT_SIZE_10: FFT size 10
  144. * @SPECTRAL_FFT_SIZE_MAX: Max number of FFT size
  145. */
  146. enum spectral_fft_size {
  147. SPECTRAL_FFT_SIZE_INVALID,
  148. SPECTRAL_FFT_SIZE_1,
  149. SPECTRAL_FFT_SIZE_2,
  150. SPECTRAL_FFT_SIZE_3,
  151. SPECTRAL_FFT_SIZE_4,
  152. SPECTRAL_FFT_SIZE_5,
  153. SPECTRAL_FFT_SIZE_6,
  154. SPECTRAL_FFT_SIZE_7,
  155. SPECTRAL_FFT_SIZE_8,
  156. SPECTRAL_FFT_SIZE_9,
  157. SPECTRAL_FFT_SIZE_10,
  158. SPECTRAL_FFT_SIZE_MAX,
  159. };
  160. /**
  161. * enum spectral_scan_mode - Spectral scan mode
  162. * @SPECTRAL_SCAN_MODE_NORMAL: Normal mode
  163. * @SPECTRAL_SCAN_MODE_AGILE: Agile mode
  164. * @SPECTRAL_SCAN_MODE_MAX: Max number of Spectral modes
  165. * @SPECTRAL_SCAN_MODE_INVALID: Invalid Spectral mode
  166. */
  167. enum spectral_scan_mode {
  168. SPECTRAL_SCAN_MODE_NORMAL,
  169. SPECTRAL_SCAN_MODE_AGILE,
  170. SPECTRAL_SCAN_MODE_MAX,
  171. SPECTRAL_SCAN_MODE_INVALID = 0xff,
  172. };
  173. /**
  174. * enum spectral_chan_width - Spectral-specific channel width enum
  175. * @SPECTRAL_CH_WIDTH_20MHZ: 20 mhz width
  176. * @SPECTRAL_CH_WIDTH_40MHZ: 40 mhz width
  177. * @SPECTRAL_CH_WIDTH_80MHZ: 80 mhz width
  178. * @SPECTRAL_CH_WIDTH_160MHZ: 160 mhz width
  179. * @SPECTRAL_CH_WIDTH_80P80MHZ: 80+80 mhz width
  180. * @SPECTRAL_CH_WIDTH_5MHZ: 5 mhz width
  181. * @SPECTRAL_CH_WIDTH_10MHZ: 10 mhz width
  182. * @SPECTRAL_CH_WIDTH_320MHZ: 320 mhz width
  183. * @SPECTRAL_CH_WIDTH_MAX: Max possible width
  184. * @SPECTRAL_CH_WIDTH_INVALID: invalid width
  185. */
  186. enum spectral_chan_width {
  187. SPECTRAL_CH_WIDTH_20MHZ,
  188. SPECTRAL_CH_WIDTH_40MHZ,
  189. SPECTRAL_CH_WIDTH_80MHZ,
  190. SPECTRAL_CH_WIDTH_160MHZ,
  191. SPECTRAL_CH_WIDTH_80P80MHZ,
  192. SPECTRAL_CH_WIDTH_320MHZ,
  193. SPECTRAL_CH_WIDTH_5MHZ,
  194. SPECTRAL_CH_WIDTH_10MHZ,
  195. SPECTRAL_CH_WIDTH_MAX,
  196. SPECTRAL_CH_WIDTH_INVALID,
  197. };
  198. struct spectral_ioctl_params {
  199. int16_t spectral_fft_period;
  200. int16_t pectral_period;
  201. int16_t spectral_count;
  202. uint16_t spectral_short_report;
  203. uint16_t spectral_pri;
  204. };
  205. /**
  206. * enum spectral_cap_hw_gen - Definitions for the Spectral hardware generation.
  207. * This corresponds to definitions in qca_wlan_vendor_spectral_scan_cap_hw_gen.
  208. * @SPECTRAL_CAP_HW_GEN_1: Generation 1
  209. * @SPECTRAL_CAP_HW_GEN_2: Generation 2
  210. * @SPECTRAL_CAP_HW_GEN_3: Generation 3
  211. */
  212. enum spectral_cap_hw_gen {
  213. SPECTRAL_CAP_HW_GEN_1 = 0,
  214. SPECTRAL_CAP_HW_GEN_2 = 1,
  215. SPECTRAL_CAP_HW_GEN_3 = 2,
  216. };
  217. /**
  218. * struct spectral_config_frequency - Spectral scan frequency
  219. * @cfreq1: Center frequency (in MHz) of the span of interest(primary 80 MHz
  220. * span for 80 + 80 agile scan request) or center frequency (in MHz)
  221. * of any WLAN channel in the span of interest.
  222. * @cfreq2: Applicable only for Agile Spectral scan request in 80+80 MHz mode.
  223. * For 80+80 mode it represents the center frequency (in MHz) of the
  224. * secondary 80 MHz span of interest or center frequency (in MHz) of
  225. * any WLAN channel in the secondary 80 MHz span of interest.
  226. */
  227. struct spectral_config_frequency {
  228. uint32_t cfreq1;
  229. uint32_t cfreq2;
  230. };
  231. /**
  232. * struct spectral_config - spectral config parameters
  233. * @ss_fft_period: Skip interval for FFT reports
  234. * @ss_period: Spectral scan period
  235. * @ss_recapture: Set this to allow FFT recapture if scan period > 52us
  236. * @ss_count: # of reports to return from ss_active
  237. * @ss_short_report: Set to report only 1 set of FFT results
  238. * @radar_bin_thresh_sel: Select threshold to classify strong bin for FFT
  239. * @ss_spectral_pri: Priority, and are we doing a noise power cal ?
  240. * @ss_fft_size: Defines the number of FFT data points to compute,
  241. * defined as a log index num_fft_pts =
  242. * 2^ss_fft_size
  243. * @ss_gc_ena: Set, to enable targeted gain change before
  244. * starting the spectral scan FFT
  245. * @ss_restart_ena: Set, to enable abort of receive frames when in high
  246. * priority and a spectral scan is queued
  247. * @ss_noise_floor_ref: Noise floor reference number (signed) for the
  248. * calculation of bin power (dBm) Though stored as an
  249. * unsigned this should be treated as a signed 8-bit int.
  250. * @ss_init_delay: Disallow spectral scan triggers after tx/rx packets
  251. * by setting this delay value to roughly SIFS time
  252. * period or greater Delay timer count in units of 0.25us
  253. * @ss_nb_tone_thr: Number of strong bins (inclusive) per sub-channel,
  254. * below which a signal is declared a narrowband tone
  255. * @ss_str_bin_thr: Bin/max_bin ratio threshold over which a bin is
  256. * declared strong (for spectral scan bandwidth analysis)
  257. * @ss_wb_rpt_mode: Set this bit to report spectral scans as EXT_BLOCKER
  258. * (phy_error=36), if none of the sub-channels are
  259. * deemed narrowband
  260. * @ss_rssi_rpt_mode: Set this bit to report spectral scans as EXT_BLOCKER
  261. * (phy_error=36), if the ADC RSSI is below the
  262. * threshold ss_rssi_thr
  263. * @ss_rssi_thr: ADC RSSI must be greater than or equal to this
  264. * threshold (signed Db) to ensure spectral scan
  265. * reporting with normal phy error codes (please see
  266. * ss_rssi_rpt_mode above).Though stored as an unsigned
  267. * value, this should be treated as a signed 8-bit int
  268. * @ss_pwr_format: Format of frequency bin magnitude for spectral scan
  269. * triggered FFTs 0: linear magnitude
  270. * 1: log magnitude (20*log10(lin_mag), 1/2 dB step size)
  271. * @ss_rpt_mode: Format of per-FFT reports to software for spectral
  272. * scan triggered FFTs
  273. * 0: No FFT report (only pulse end summary)
  274. * 1: 2-dword summary of metrics for each completed FFT
  275. * 2: 2-dword summary + 1x-oversampled bins(in-band) per
  276. * FFT
  277. * 3: 2-dword summary + 2x-oversampled bins (all) per FFT
  278. * @ss_bin_scale: Number of LSBs to shift out to scale the FFT bins
  279. * for spectral scan triggered FFTs
  280. * @ss_dbm_adj: Set (with ss_pwr_format=1), to report bin
  281. * magnitudes
  282. * converted to dBm power using the noisefloor
  283. * calibration results
  284. * @ss_chn_mask: Per chain enable mask to select input ADC for search
  285. * FFT
  286. * @ss_nf_cal: nf calibrated values for ctl+ext
  287. * @ss_nf_pwr: nf pwr values for ctl+ext
  288. * @ss_nf_temp_data: temperature data taken during nf scan
  289. * @ss_frequency: This specifies the frequency span over which Spectral
  290. * scan would be carried out. Its value depends on the
  291. * Spectral scan mode.
  292. * Normal mode:-
  293. * Not applicable. Spectral scan would happen in the
  294. * operating span.
  295. * Agile mode:-
  296. * cfreq1 represents the center frequency (in MHz) of
  297. * the span of interest(primary 80 MHz span for 80 + 80
  298. * agile scan request) or center frequency (in MHz) of
  299. * any WLAN channel in the span of interest. cfreq2 is
  300. * applicable only for Agile Spectral scan request in
  301. * 80+80 MHz mode. For 80+80 mode it represents the
  302. * center frequency (in MHz) of the secondary 80 MHz
  303. * span of interest or center frequency (in MHz) of
  304. * any WLAN channel in the secondary 80 MHz span of
  305. * interest.
  306. * @ss_bandwidth: Spectral scan bandwidth
  307. */
  308. struct spectral_config {
  309. uint16_t ss_fft_period;
  310. uint16_t ss_period;
  311. uint16_t ss_recapture;
  312. uint16_t ss_count;
  313. uint16_t ss_short_report;
  314. uint8_t radar_bin_thresh_sel;
  315. uint16_t ss_spectral_pri;
  316. uint16_t ss_fft_size;
  317. uint16_t ss_gc_ena;
  318. uint16_t ss_restart_ena;
  319. uint16_t ss_noise_floor_ref;
  320. uint16_t ss_init_delay;
  321. uint16_t ss_nb_tone_thr;
  322. uint16_t ss_str_bin_thr;
  323. uint16_t ss_wb_rpt_mode;
  324. uint16_t ss_rssi_rpt_mode;
  325. uint16_t ss_rssi_thr;
  326. uint16_t ss_pwr_format;
  327. uint16_t ss_rpt_mode;
  328. uint16_t ss_bin_scale;
  329. uint16_t ss_dbm_adj;
  330. uint16_t ss_chn_mask;
  331. int8_t ss_nf_cal[AH_MAX_CHAINS * 2];
  332. int8_t ss_nf_pwr[AH_MAX_CHAINS * 2];
  333. int32_t ss_nf_temp_data;
  334. struct spectral_config_frequency ss_frequency;
  335. uint16_t ss_bandwidth;
  336. };
  337. /**
  338. * struct spectral_caps - Spectral capabilities structure
  339. * @phydiag_cap: Phydiag capability
  340. * @radar_cap: Radar detection capability
  341. * @spectral_cap: Spectral capability
  342. * @advncd_spectral_cap: Advanced spectral capability
  343. * @hw_gen: Spectral hw generation as defined in spectral_cap_hw_gen
  344. * @is_scaling_params_populated: indicates whether scaling params is populated
  345. * @formula_id: formula_id
  346. * @low_level_offset: low_level_offset
  347. * @high_level_offset: high_level_offset
  348. * @rssi_thr: rssi_thr
  349. * @default_agc_max_gain: default_agc_max_gain
  350. * @agile_spectral_cap: agile Spectral capability for 20/40/80
  351. * @agile_spectral_cap_160: agile Spectral capability for 160 MHz
  352. * @agile_spectral_cap_80p80: agile Spectral capability for 80p80
  353. * @agile_spectral_cap_320: agile Spectral capability for 320 MHz
  354. * @num_detectors_20mhz: number of Spectral detectors in 20 MHz
  355. * @num_detectors_40mhz: number of Spectral detectors in 40 MHz
  356. * @num_detectors_80mhz: number of Spectral detectors in 80 MHz
  357. * @num_detectors_160mhz: number of Spectral detectors in 160 MHz
  358. * @num_detectors_80p80mhz: number of Spectral detectors in 80p80 MHz
  359. * @num_detectors_320mhz: number of Spectral detectors in 320 MHz
  360. */
  361. struct spectral_caps {
  362. uint8_t phydiag_cap;
  363. uint8_t radar_cap;
  364. uint8_t spectral_cap;
  365. uint8_t advncd_spectral_cap;
  366. uint32_t hw_gen;
  367. bool is_scaling_params_populated;
  368. uint16_t formula_id;
  369. int16_t low_level_offset;
  370. int16_t high_level_offset;
  371. int16_t rssi_thr;
  372. uint8_t default_agc_max_gain;
  373. bool agile_spectral_cap;
  374. bool agile_spectral_cap_160;
  375. bool agile_spectral_cap_80p80;
  376. bool agile_spectral_cap_320;
  377. uint32_t num_detectors_20mhz;
  378. uint32_t num_detectors_40mhz;
  379. uint32_t num_detectors_80mhz;
  380. uint32_t num_detectors_160mhz;
  381. uint32_t num_detectors_80p80mhz;
  382. uint32_t num_detectors_320mhz;
  383. };
  384. #define SPECTRAL_IOCTL_PARAM_NOVAL (65535)
  385. #define MAX_SPECTRAL_CHAINS (3)
  386. #define MAX_NUM_BINS (2048)
  387. #define MAX_NUM_BINS_PRI80 (1024)
  388. #define MAX_NUM_BINS_SEC80 (520)
  389. #define MAX_NUM_BINS_5MHZ (32)
  390. /* 5 categories x (lower + upper) bands */
  391. #define MAX_INTERF 10
  392. #define SPECTRAL_MAC_ADDR_SIZE (6)
  393. #define MAX_NUM_FREQ_SPANS (3)
  394. #define MAX_NUM_DETECTORS (2)
  395. #define MAX_SPECTRAL_PAYLOAD (3028)
  396. #define SPECTRAL_RECAPTURE_SCAN_PERIOD_THRESHOLD (52)
  397. /**
  398. * enum dcs_int_type - Interference type indicated by DCS
  399. * @SPECTRAL_DCS_INT_NONE: No interference
  400. * @SPECTRAL_DCS_INT_CW: CW interference
  401. * @SPECTRAL_DCS_INT_WIFI: WLAN interference
  402. */
  403. enum dcs_int_type {
  404. SPECTRAL_DCS_INT_NONE,
  405. SPECTRAL_DCS_INT_CW,
  406. SPECTRAL_DCS_INT_WIFI
  407. };
  408. /**
  409. * struct interf_rsp - Interference record
  410. * @interf_type: eINTERF_TYPE giving type of interference
  411. * @interf_min_freq: Minimum frequency in MHz at which interference has been
  412. * found
  413. * @interf_max_freq: Maximum frequency in MHz at which interference has been
  414. * found
  415. * @advncd_spectral_cap: Advanced spectral capability
  416. */
  417. struct interf_rsp {
  418. uint8_t interf_type;
  419. uint16_t interf_min_freq;
  420. uint16_t interf_max_freq;
  421. } __packed;
  422. /**
  423. * struct interf_src_rsp - List of interference sources
  424. * @count: Number of interference records
  425. * @interf: Array of interference records
  426. */
  427. struct interf_src_rsp {
  428. uint16_t count;
  429. struct interf_rsp interf[MAX_INTERF];
  430. } __packed;
  431. /**
  432. * struct spectral_classifier_params - spectral classifier parameters
  433. * @spectral_20_40_mode: Is AP in 20/40 mode?
  434. * @spectral_dc_index: DC index
  435. * @spectral_dc_in_mhz: DC in MHz
  436. * @upper_chan_in_mhz: Upper channel in MHz
  437. * @lower_chan_in_mhz: Lower channel in MHz
  438. */
  439. struct spectral_classifier_params {
  440. int spectral_20_40_mode;
  441. int spectral_dc_index;
  442. int spectral_dc_in_mhz;
  443. int upper_chan_in_mhz;
  444. int lower_chan_in_mhz;
  445. } __packed;
  446. #ifdef OPTIMIZED_SAMP_MESSAGE
  447. /**
  448. * struct samp_edge_extra_bin_info - Spectral edge extra bins Information
  449. * For 11ac chipsets prior to AR900B version 2.0, a max of 512 bins are
  450. * delivered. However, there can be additional bins reported for
  451. * AR900B version 2.0 and QCA9984 as described next:
  452. * AR900B version 2.0: An additional tone is processed on the right
  453. * hand side in order to facilitate detection of radar pulses out to
  454. * the extreme band-edge of the channel frequency.
  455. * Since the HW design processes four tones at a time,
  456. * this requires one additional Dword to be added to the
  457. * search FFT report.
  458. * QCA9984: When spectral_scan_rpt_mode=2, i.e 2-dword summary +
  459. * 1x-oversampled bins (in-band) per FFT,
  460. * then 8 more bins (4 more on left side and 4 more on right side)
  461. * are added.
  462. *
  463. * @num_bins: Number of edge extra bins
  464. * @start_bin_idx: Indicates the start index of extra bins
  465. */
  466. struct samp_edge_extra_bin_info {
  467. uint16_t num_bins;
  468. uint16_t start_bin_idx;
  469. } __packed;
  470. /* Compile time assert to check struct size is divisible by 4 Bytes */
  471. SPECTRAL_COMPILE_TIME_ASSERT(struct_samp_edge_extra_bin_size_4byte_assertion,
  472. (sizeof(struct samp_edge_extra_bin_info) % 4)
  473. == 0);
  474. /**
  475. * struct samp_detector_info - SAMP per-detector information
  476. * A detector here refers to the HW carrying out the Spectral scan, to
  477. * detect the presence of interferences.
  478. * @start_frequency: Indicates start frequency per-detector (in MHz)
  479. * @end_frequency: Indicates last frequency per-detector (in MHz)
  480. * @timestamp: Indicates Spectral HW timestamp (usec)
  481. * @last_tstamp: Indicates the last time stamp
  482. * @last_raw_timestamp: Previous FFT report's raw timestamp. In case of
  483. * 160Mhz it will be primary 80 segment's timestamp as both primary & secondary
  484. * segment's timestamp are expected to be almost equal.
  485. * @timestamp_war_offset: Offset calculated based on reset_delay and
  486. * last_raw_timestamp. It will be added to raw_timestamp to get timestamp.
  487. * @raw_timestamp: Actual FFT timestamp reported by HW
  488. * @reset_delay: Time gap between the last spectral report before reset and the
  489. * end of reset. It is provided by FW via direct DMA framework.
  490. * @left_edge_bins: Number of extra bins on left band edge
  491. * @right_edge_bins: Number of extra bins on right band edge
  492. * @start_bin_idx: Indicates the first bin index per-detector
  493. * @end_bin_idx: Indicates the last bin index per-detector
  494. * @max_index: Indicates the index of max magnitude
  495. * @max_magnitude: Indicates the maximum magnitude
  496. * @noise_floor: Indicates the current noise floor
  497. * @rssi: Indicates RSSI
  498. * @agc_total_gain:
  499. * @gainchange:
  500. * @pri80ind: Indication from hardware that the sample was received on the
  501. * primary 80 MHz segment. If this is set for smode = SPECTRAL_SCAN_MODE_AGILE,
  502. * it indicates that Spectral scan was carried out on pri80 instead of the
  503. * Agile frequency due to a channel switch - Software may choose to ignore
  504. * the sample in this case.
  505. * @is_sec80: Indicates whether the frequency span corresponds to pri80 or
  506. * sec80 (only applicable for 160/80p80 operating_bw for
  507. * smode SPECTRAL_SCAN_MODE_NORMAL)
  508. * @blanking_status: Indicates whether scan blanking was enabled during this
  509. * spectral report capture. This field is applicable only when scan blanking
  510. * feature is enabled. When scan blanking feature is disabled, this field
  511. * will be set to zero.
  512. * @padding_detector_info: padding bytes
  513. */
  514. struct samp_detector_info {
  515. uint32_t start_frequency;
  516. uint32_t end_frequency;
  517. uint32_t timestamp;
  518. uint32_t last_tstamp;
  519. uint32_t last_raw_timestamp;
  520. uint32_t timestamp_war_offset;
  521. uint32_t raw_timestamp;
  522. uint32_t reset_delay;
  523. struct samp_edge_extra_bin_info left_edge_bins;
  524. struct samp_edge_extra_bin_info right_edge_bins;
  525. uint16_t start_bin_idx;
  526. uint16_t end_bin_idx;
  527. uint16_t max_index;
  528. uint16_t max_magnitude;
  529. int16_t noise_floor;
  530. int8_t rssi;
  531. uint8_t agc_total_gain;
  532. uint8_t gainchange;
  533. uint8_t pri80ind;
  534. uint8_t is_sec80;
  535. uint8_t blanking_status;
  536. /* Padding bits to make struct size multiple of 4 bytes */
  537. uint8_t padding_detector_info[];
  538. } __packed;
  539. /* Compile time assert to check struct size is divisible by 4 Bytes */
  540. SPECTRAL_COMPILE_TIME_ASSERT(struct_samp_detector_info_size_4byte_assertion,
  541. (sizeof(struct samp_detector_info) % 4) == 0);
  542. /**
  543. * struct samp_freq_span_info - SAMP per-frequency span information
  544. * A frequency span here refers to a contiguous span of frequencies in which
  545. * Spectral scan and interference detection is carried out.
  546. * @detector_info: Per-detector Spectral information
  547. * @num_detectors: Number of detectors per span
  548. * @padding_span_info: padding bytes
  549. */
  550. struct samp_freq_span_info {
  551. struct samp_detector_info detector_info[MAX_NUM_DETECTORS];
  552. uint8_t num_detectors;
  553. /* Padding bits to make struct size multiple of 4 bytes */
  554. uint8_t padding_span_info[3];
  555. } __packed;
  556. /* Compile time assert to check struct size is divisible by 4 Bytes */
  557. SPECTRAL_COMPILE_TIME_ASSERT(struct_samp_freq_span_info_size_4byte_assertion,
  558. (sizeof(struct samp_freq_span_info) % 4) == 0);
  559. /**
  560. * struct spectral_samp_msg - Spectral SAMP message
  561. * @signature: Validates the SAMP message
  562. * @target_reset_count: Indicates the number of times target went through
  563. * reset routine after spectral was enabled.
  564. * @pri20_freq: Primary 20MHz operating frequency in MHz
  565. * @cfreq1: Segment 1 centre frequency in MHz
  566. * @cfreq2: For 80p80, indicates segment 2 centre frequency in MHz. For 160MHz,
  567. * indicates the center frequency of 160MHz span.
  568. * @sscan_cfreq1: Normal/Agile scan Center frequency for Segment 1
  569. * based on Spectral Scan mode.
  570. * @sscan_cfreq2: Normal/Agile scan Center frequency for Segment 2 in case of
  571. * 80p80, and for 160MHz center frequency of the 160MHz span based on Spectral
  572. * Scan mode.
  573. * @bin_pwr_count: Indicates the number of FFT bins
  574. * @freq_span_info: Spectral per-contiguous frequency span information
  575. * @spectral_upper_rssi: Indicates RSSI of upper band
  576. * @spectral_lower_rssi: Indicates RSSI of lower band
  577. * @spectral_chain_ctl_rssi: RSSI for control channel, for all antennas
  578. * @spectral_chain_ext_rssi: RSSI for extension channel, for all antennas
  579. * @macaddr: Indicates the device interface
  580. * @spectral_mode: Spectral scan mode
  581. * @operating_bw: Device's operating bandwidth. Values = enum phy_ch_width
  582. * @sscan_bw: Normal/Agile Scan BW based on Spectral scan mode.
  583. * Values = enum phy_ch_width
  584. * @fft_width: Indicates the number of bits representing an FFT bin
  585. * @dcs_enabled: Whether DCS is enabled
  586. * @int_type: Interference type indicated by DCS. Values = enum dcs_int_type
  587. * @num_freq_spans: Number of contiguous frequency spans in operating bandwidth
  588. * @bin_pwr: Contains FFT magnitudes
  589. */
  590. struct spectral_samp_msg {
  591. uint32_t signature;
  592. uint32_t target_reset_count;
  593. uint32_t pri20_freq;
  594. uint32_t cfreq1;
  595. uint32_t cfreq2;
  596. uint32_t sscan_cfreq1;
  597. uint32_t sscan_cfreq2;
  598. uint32_t bin_pwr_count;
  599. struct samp_freq_span_info freq_span_info[MAX_NUM_FREQ_SPANS];
  600. int8_t spectral_lower_rssi;
  601. int8_t spectral_upper_rssi;
  602. int8_t spectral_chain_ctl_rssi[MAX_SPECTRAL_CHAINS];
  603. int8_t spectral_chain_ext_rssi[MAX_SPECTRAL_CHAINS];
  604. uint8_t macaddr[SPECTRAL_MAC_ADDR_SIZE];
  605. uint8_t spectral_mode;
  606. uint8_t operating_bw;
  607. uint8_t sscan_bw;
  608. uint8_t fft_width;
  609. uint8_t dcs_enabled;
  610. uint8_t int_type;
  611. uint8_t num_freq_spans;
  612. uint8_t bin_pwr[]; /*This should be the last item in the structure*/
  613. } __packed;
  614. #else
  615. /**
  616. * struct spectral_samp_data - Spectral Analysis Messaging Protocol Data format
  617. * @spectral_data_len: Indicates the bin size
  618. * @spectral_data_len_sec80: Indicates the bin size for secondary 80 segment
  619. * @spectral_rssi: Indicates RSSI
  620. * @spectral_rssi_sec80: Indicates RSSI for secondary 80 segment
  621. * @spectral_combined_rssi: Indicates combined RSSI from all antennas
  622. * @spectral_upper_rssi: Indicates RSSI of upper band
  623. * @spectral_lower_rssi: Indicates RSSI of lower band
  624. * @spectral_chain_ctl_rssi: RSSI for control channel, for all antennas
  625. * @spectral_chain_ext_rssi: RSSI for extension channel, for all antennas
  626. * @spectral_max_scale: Indicates scale factor
  627. * @spectral_bwinfo: Indicates bandwidth info
  628. * @spectral_tstamp: Indicates timestamp
  629. * @spectral_max_index: Indicates the index of max magnitude
  630. * @spectral_max_index_sec80: Indicates the index of max magnitude for secondary
  631. * 80 segment
  632. * @spectral_max_mag: Indicates the maximum magnitude
  633. * @spectral_max_mag_sec80: Indicates the maximum magnitude for secondary 80
  634. * segment
  635. * @spectral_max_exp: Indicates the max exp
  636. * @spectral_last_tstamp: Indicates the last time stamp
  637. * @spectral_upper_max_index: Indicates the index of max mag in upper band
  638. * @spectral_lower_max_index: Indicates the index of max mag in lower band
  639. * @spectral_nb_upper: Not Used
  640. * @spectral_nb_lower: Not Used
  641. * @classifier_params: Indicates classifier parameters
  642. * @bin_pwr_count: Indicates the number of FFT bins
  643. * @lb_edge_extrabins: Number of extra bins on left band edge
  644. * @rb_edge_extrabins: Number of extra bins on right band edge
  645. * @bin_pwr_count_sec80: Indicates the number of FFT bins in secondary 80
  646. * segment
  647. * @bin_pwr: Contains FFT magnitudes
  648. * @bin_pwr_sec80: Contains FFT magnitudes for the secondary 80
  649. * segment
  650. * @interf_list: List of interference sources
  651. * @noise_floor: Indicates the current noise floor
  652. * @noise_floor_sec80: Indicates the current noise floor for secondary 80
  653. * segment
  654. * @ch_width: Channel width 20/40/80/160 MHz
  655. * @spectral_agc_total_gain:
  656. * @spectral_agc_total_gain_sec80:
  657. * @spectral_gainchange:
  658. * @spectral_gainchange_sec80:
  659. * @spectral_mode: Spectral scan mode
  660. * @spectral_pri80ind: Indication from hardware that the sample was
  661. * received on the primary 80 MHz segment. If this
  662. * is set when smode = SPECTRAL_SCAN_MODE_AGILE, it
  663. * indicates that Spectral was carried out on pri80
  664. * instead of the Agile frequency due to a
  665. * channel switch - Software may choose
  666. * to ignore the sample in this case.
  667. * @spectral_pri80ind_sec80: Indication from hardware that the sample was
  668. * received on the primary 80 MHz segment instead of
  669. * the secondary 80 MHz segment due to a channel
  670. * switch - Software may choose to ignore the sample
  671. * if this is set. Applicable only if smode =
  672. * SPECTRAL_SCAN_MODE_NORMAL and for 160/80+80 MHz
  673. * Spectral operation.
  674. * @last_raw_timestamp: Previous FFT report's raw timestamp. In case of
  675. * 160Mhz it will be primary 80 segment's timestamp
  676. * as both primary & secondary segment's timestamp
  677. * are expected to be almost equal.
  678. * @timestamp_war_offset: Offset calculated based on reset_delay and
  679. * last_raw_timestamp. It will be added to
  680. * raw_timestamp to get spectral_tstamp.
  681. * @raw_timestamp: Actual FFT timestamp reported by HW on primary
  682. * segment.
  683. * @raw_timestamp_sec80: Actual FFT timestamp reported by HW on sec80 MHz
  684. * segment.
  685. * @reset_delay: Time gap between the last spectral report before
  686. * reset and the end of reset. It is provided by FW
  687. * via direct DMA framework.
  688. * @target_reset_count: Indicates the number of times target went through
  689. * reset routine after spectral was enabled.
  690. * @agile_ch_width:
  691. * @bin_pwr_count_5mhz: Indicates the number of FFT bins in the extra
  692. * 5 MHz for 165 MHz/ Restricted 80p80 mode
  693. * @bin_pwr_5mhz: Contains FFT magnitudes corresponding to the extra
  694. * 5 MHz in 165 MHz/ Restricted 80p80 mode
  695. */
  696. struct spectral_samp_data {
  697. int16_t spectral_data_len;
  698. int16_t spectral_data_len_sec80;
  699. int16_t spectral_rssi;
  700. int16_t spectral_rssi_sec80;
  701. int8_t spectral_combined_rssi;
  702. int8_t spectral_upper_rssi;
  703. int8_t spectral_lower_rssi;
  704. int8_t spectral_chain_ctl_rssi[MAX_SPECTRAL_CHAINS];
  705. int8_t spectral_chain_ext_rssi[MAX_SPECTRAL_CHAINS];
  706. uint8_t spectral_max_scale;
  707. int16_t spectral_bwinfo;
  708. int32_t spectral_tstamp;
  709. int16_t spectral_max_index;
  710. int16_t spectral_max_index_sec80;
  711. int16_t spectral_max_mag;
  712. int16_t spectral_max_mag_sec80;
  713. uint8_t spectral_max_exp;
  714. int32_t spectral_last_tstamp;
  715. int16_t spectral_upper_max_index;
  716. int16_t spectral_lower_max_index;
  717. uint8_t spectral_nb_upper;
  718. uint8_t spectral_nb_lower;
  719. struct spectral_classifier_params classifier_params;
  720. uint16_t bin_pwr_count;
  721. /*
  722. * For 11ac chipsets prior to AR900B version 2.0, a max of 512 bins are
  723. * delivered. However, there can be additional bins reported for
  724. * AR900B version 2.0 and QCA9984 as described next:
  725. *
  726. * AR900B version 2.0: An additional tone is processed on the right
  727. * hand side in order to facilitate detection of radar pulses out to
  728. * the extreme band-edge of the channel frequency.
  729. * Since the HW design processes four tones at a time,
  730. * this requires one additional Dword to be added to the
  731. * search FFT report.
  732. *
  733. * QCA9984: When spectral_scan_rpt_mode=2, i.e 2-dword summary +
  734. * 1x-oversampled bins (in-band) per FFT,
  735. * then 8 more bins (4 more on left side and 4 more on right side)
  736. * are added.
  737. */
  738. uint8_t lb_edge_extrabins;
  739. uint8_t rb_edge_extrabins;
  740. uint16_t bin_pwr_count_sec80;
  741. uint8_t bin_pwr[MAX_NUM_BINS_PRI80];
  742. uint8_t bin_pwr_sec80[MAX_NUM_BINS_SEC80];
  743. struct interf_src_rsp interf_list;
  744. int16_t noise_floor;
  745. int16_t noise_floor_sec80;
  746. uint32_t ch_width;
  747. uint8_t spectral_agc_total_gain;
  748. uint8_t spectral_agc_total_gain_sec80;
  749. uint8_t spectral_gainchange;
  750. uint8_t spectral_gainchange_sec80;
  751. enum spectral_scan_mode spectral_mode;
  752. uint8_t spectral_pri80ind;
  753. uint8_t spectral_pri80ind_sec80;
  754. uint32_t last_raw_timestamp;
  755. uint32_t timestamp_war_offset;
  756. uint32_t raw_timestamp;
  757. uint32_t raw_timestamp_sec80;
  758. uint32_t reset_delay;
  759. uint32_t target_reset_count;
  760. uint32_t agile_ch_width;
  761. uint16_t bin_pwr_count_5mhz;
  762. uint8_t bin_pwr_5mhz[MAX_NUM_BINS_5MHZ];
  763. } __packed;
  764. /**
  765. * struct spectral_samp_msg - Spectral SAMP message
  766. * @signature: Validates the SAMP message
  767. * @freq: Operating frequency in MHz
  768. * @vhtop_ch_freq_seg1: VHT Segment 1 centre frequency in MHz
  769. * @vhtop_ch_freq_seg2: VHT Segment 2 centre frequency in MHz
  770. * @agile_freq1: Center frequency in MHz of the entire span(for 80+80 MHz
  771. * agile Scan it is primary 80 MHz span) across which
  772. * Agile Spectral is carried out. Applicable only for Agile
  773. * Spectral samples.
  774. * @agile_freq2: Center frequency in MHz of the secondary 80 MHz span
  775. * across which Agile Spectral is carried out. Applicable
  776. * only for Agile Spectral samples in 80+80 MHz mode.
  777. * @freq_loading: How busy was the channel
  778. * @dcs_enabled: Whether DCS is enabled
  779. * @int_type: Interference type indicated by DCS
  780. * @macaddr: Indicates the device interface
  781. * @samp_data: SAMP Data
  782. */
  783. struct spectral_samp_msg {
  784. uint32_t signature;
  785. uint16_t freq;
  786. uint16_t vhtop_ch_freq_seg1;
  787. uint16_t vhtop_ch_freq_seg2;
  788. uint16_t agile_freq1;
  789. uint16_t agile_freq2;
  790. uint16_t freq_loading;
  791. uint16_t dcs_enabled;
  792. enum dcs_int_type int_type;
  793. uint8_t macaddr[6];
  794. struct spectral_samp_data samp_data;
  795. } __packed;
  796. #endif /* OPTIMIZED_SAMP_MESSAGE */
  797. #endif