wlan_spectral_public_structs.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /*
  2. * Copyright (c) 2011,2017-2019 The Linux Foundation. All rights reserved.
  3. *
  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. #include <qdf_types.h>
  20. #include "wlan_dfs_ioctl.h"
  21. #include <spectral_ioctl.h>
  22. #ifndef __KERNEL__
  23. #include <math.h>
  24. #endif /* __KERNEL__ */
  25. #ifndef _WLAN_SPECTRAL_PUBLIC_STRUCTS_H_
  26. #define _WLAN_SPECTRAL_PUBLIC_STRUCTS_H_
  27. #ifndef AH_MAX_CHAINS
  28. #define AH_MAX_CHAINS 3
  29. #endif
  30. #define MAX_NUM_CHANNELS 255
  31. #define SPECTRAL_PHYERR_PARAM_NOVAL 65535
  32. #ifdef SPECTRAL_USE_EMU_DEFAULTS
  33. /* Use defaults from emulation */
  34. #define SPECTRAL_SCAN_ACTIVE_DEFAULT (0x0)
  35. #define SPECTRAL_SCAN_ENABLE_DEFAULT (0x0)
  36. #define SPECTRAL_SCAN_COUNT_DEFAULT (0x0)
  37. #define SPECTRAL_SCAN_PERIOD_DEFAULT (250)
  38. #define SPECTRAL_SCAN_PRIORITY_DEFAULT (0x1)
  39. #define SPECTRAL_SCAN_FFT_SIZE_DEFAULT (0x7)
  40. #define SPECTRAL_SCAN_GC_ENA_DEFAULT (0x1)
  41. #define SPECTRAL_SCAN_RESTART_ENA_DEFAULT (0x0)
  42. #define SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT (0xa0)
  43. #define SPECTRAL_SCAN_INIT_DELAY_DEFAULT (0x50)
  44. #define SPECTRAL_SCAN_NB_TONE_THR_DEFAULT (0xc)
  45. #define SPECTRAL_SCAN_STR_BIN_THR_DEFAULT (0x7)
  46. #define SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT (0x0)
  47. #define SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT (0x1)
  48. #define SPECTRAL_SCAN_RSSI_THR_DEFAULT (0xf)
  49. #define SPECTRAL_SCAN_PWR_FORMAT_DEFAULT (0x1)
  50. #define SPECTRAL_SCAN_RPT_MODE_DEFAULT (0x2)
  51. #define SPECTRAL_SCAN_BIN_SCALE_DEFAULT (0x1)
  52. #define SPECTRAL_SCAN_DBM_ADJ_DEFAULT (0x0)
  53. #define SPECTRAL_SCAN_CHN_MASK_DEFAULT (0x1)
  54. #else
  55. /*
  56. * Static default values for spectral state and configuration.
  57. * These definitions should be treated as temporary. Ideally,
  58. * we should get the defaults from firmware - this will be discussed.
  59. *
  60. * Use defaults from Spectral Hardware Micro-Architecture
  61. * document (v1.0)
  62. */
  63. #define SPECTRAL_SCAN_ACTIVE_DEFAULT (0)
  64. #define SPECTRAL_SCAN_ENABLE_DEFAULT (0)
  65. #define SPECTRAL_SCAN_COUNT_DEFAULT (0)
  66. #define SPECTRAL_SCAN_PERIOD_GEN_I_DEFAULT (35)
  67. #define SPECTRAL_SCAN_PERIOD_GEN_II_DEFAULT (35)
  68. #define SPECTRAL_SCAN_PERIOD_GEN_III_DEFAULT (224)
  69. #define SPECTRAL_SCAN_PRIORITY_DEFAULT (1)
  70. #define SPECTRAL_SCAN_FFT_SIZE_DEFAULT (7)
  71. #define SPECTRAL_SCAN_GC_ENA_DEFAULT (1)
  72. #define SPECTRAL_SCAN_RESTART_ENA_DEFAULT (0)
  73. #define SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT (-96)
  74. #define SPECTRAL_SCAN_INIT_DELAY_DEFAULT (80)
  75. #define SPECTRAL_SCAN_NB_TONE_THR_DEFAULT (12)
  76. #define SPECTRAL_SCAN_STR_BIN_THR_DEFAULT (8)
  77. #define SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT (0)
  78. #define SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT (0)
  79. #define SPECTRAL_SCAN_RSSI_THR_DEFAULT (0xf0)
  80. #define SPECTRAL_SCAN_PWR_FORMAT_DEFAULT (0)
  81. #define SPECTRAL_SCAN_RPT_MODE_DEFAULT (2)
  82. #define SPECTRAL_SCAN_BIN_SCALE_DEFAULT (1)
  83. #define SPECTRAL_SCAN_DBM_ADJ_DEFAULT (1)
  84. #define SPECTRAL_SCAN_CHN_MASK_DEFAULT (1)
  85. #endif /* SPECTRAL_USE_EMU_DEFAULTS */
  86. /* The below two definitions apply only to pre-11ac chipsets */
  87. #define SPECTRAL_SCAN_SHORT_REPORT_DEFAULT (1)
  88. #define SPECTRAL_SCAN_FFT_PERIOD_DEFAULT (1)
  89. /*
  90. * Definitions to help in scaling of gen3 linear format Spectral bins to values
  91. * similar to those from gen2 chipsets.
  92. */
  93. /*
  94. * Max gain for QCA9984. Since this chipset is a prime representative of gen2
  95. * chipsets, it is chosen for this value.
  96. */
  97. #define SPECTRAL_QCA9984_MAX_GAIN (78)
  98. /* Temporary section for hard-coded values. These need to come from FW. */
  99. /* Max gain for IPQ8074 */
  100. #define SPECTRAL_IPQ8074_DEFAULT_MAX_GAIN_HARDCODE (62)
  101. /*
  102. * Section for values needing tuning per customer platform. These too may need
  103. * to come from FW. To be considered as hard-coded for now.
  104. */
  105. /*
  106. * If customers have a different gain line up than QCA reference designs for
  107. * IPQ8074 and/or QCA9984, they may have to tune the low level threshold and
  108. * the RSSI threshold.
  109. */
  110. #define SPECTRAL_SCALING_LOW_LEVEL_OFFSET (7)
  111. #define SPECTRAL_SCALING_RSSI_THRESH (5)
  112. /*
  113. * If customers set the AGC backoff differently, they may have to tune the high
  114. * level threshold.
  115. */
  116. #define SPECTRAL_SCALING_HIGH_LEVEL_OFFSET (5)
  117. /* End of section for values needing fine tuning. */
  118. /* End of temporary section for hard-coded values */
  119. /**
  120. * enum wlan_cfg80211_spectral_vendorcmd_handler_idx - Indices to cfg80211
  121. * spectral vendor command handlers
  122. * @SPECTRAL_SCAN_START_HANDLER_IDX: Index to SPECTRAL_SCAN_START handler
  123. * @SPECTRAL_SCAN_STOP_HANDLER_IDX: Index to SPECTRAL_SCAN_STOP handler
  124. * @SPECTRAL_SCAN_GET_CONFIG_HANDLER_IDX: Index to SPECTRAL_SCAN_GET_CONFIG
  125. * handler
  126. * @SPECTRAL_SCAN_GET_DIAG_STATS_HANDLER_IDX: Index to
  127. * SPECTRAL_SCAN_GET_DIAG_STATS handler
  128. * @SPECTRAL_SCAN_GET_CAP_HANDLER_IDX: Index to SPECTRAL_SCAN_GET_CAP handler
  129. * @SPECTRAL_SCAN_GET_STATUS_HANDLER_IDX: Index to SPECTRAL_SCAN_GET_STATUS
  130. * handler
  131. * @SPECTRAL_SCAN_VENDOR_CMD_HANDLER_MAX: Number of cfg80211 spectral
  132. * vendor command handlers supported
  133. */
  134. enum wlan_cfg80211_spectral_vendorcmd_handler_idx {
  135. SPECTRAL_SCAN_START_HANDLER_IDX,
  136. SPECTRAL_SCAN_STOP_HANDLER_IDX,
  137. SPECTRAL_SCAN_GET_CONFIG_HANDLER_IDX,
  138. SPECTRAL_SCAN_GET_DIAG_STATS_HANDLER_IDX,
  139. SPECTRAL_SCAN_GET_CAP_HANDLER_IDX,
  140. SPECTRAL_SCAN_GET_STATUS_HANDLER_IDX,
  141. SPECTRAL_SCAN_VENDOR_CMD_HANDLER_MAX,
  142. };
  143. /**
  144. * enum spectral_debug - Spectral debug level
  145. * @DEBUG_SPECTRAL: Minimal SPECTRAL debug
  146. * @DEBUG_SPECTRAL1: Normal SPECTRAL debug
  147. * @DEBUG_SPECTRAL2: Maximal SPECTRAL debug
  148. * @DEBUG_SPECTRAL3: Matched filterID display
  149. * @DEBUG_SPECTRAL4: One time dump of FFT report
  150. */
  151. enum spectral_debug {
  152. DEBUG_SPECTRAL = 0x00000100,
  153. DEBUG_SPECTRAL1 = 0x00000200,
  154. DEBUG_SPECTRAL2 = 0x00000400,
  155. DEBUG_SPECTRAL3 = 0x00000800,
  156. DEBUG_SPECTRAL4 = 0x00001000,
  157. };
  158. /**
  159. * enum spectral_capability_type - Spectral capability type
  160. * @SPECTRAL_CAP_PHYDIAG: Phydiag capability
  161. * @SPECTRAL_CAP_RADAR: Radar detection capability
  162. * @SPECTRAL_CAP_SPECTRAL_SCAN: Spectral capability
  163. * @SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN: Advanced spectral capability
  164. */
  165. enum spectral_capability_type {
  166. SPECTRAL_CAP_PHYDIAG,
  167. SPECTRAL_CAP_RADAR,
  168. SPECTRAL_CAP_SPECTRAL_SCAN,
  169. SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN,
  170. };
  171. /**
  172. * struct spectral_chan_stats - channel status info
  173. * @cycle_count: Cycle count
  174. * @channel_load: Channel load
  175. * @per: Period
  176. * @noisefloor: Noise floor
  177. * @comp_usablity: Computed usability
  178. * @maxregpower: Maximum allowed regulatory power
  179. * @comp_usablity_sec80: Computed usability of secondary 80 Mhz
  180. * @maxregpower_sec80: Max regulatory power of secondary 80 Mhz
  181. */
  182. struct spectral_chan_stats {
  183. int cycle_count;
  184. int channel_load;
  185. int per;
  186. int noisefloor;
  187. uint16_t comp_usablity;
  188. int8_t maxregpower;
  189. uint16_t comp_usablity_sec80;
  190. int8_t maxregpower_sec80;
  191. };
  192. /**
  193. * struct spectral_diag_stats - spectral diag stats
  194. * @spectral_mismatch: Spectral TLV signature mismatches
  195. * @spectral_sec80_sfft_insufflen: Insufficient length when parsing for
  196. * Secondary 80 Search FFT report
  197. * @spectral_no_sec80_sfft: Secondary 80 Search FFT report
  198. * TLV not found
  199. * @spectral_vhtseg1id_mismatch: VHT Operation Segment 1 ID
  200. * mismatches in Search FFT report
  201. * @spectral_vhtseg2id_mismatch: VHT Operation Segment 2 ID
  202. * mismatches in Search FFT report
  203. * @spectral_invalid_detector_id: Invalid detector id
  204. */
  205. struct spectral_diag_stats {
  206. uint64_t spectral_mismatch;
  207. uint64_t spectral_sec80_sfft_insufflen;
  208. uint64_t spectral_no_sec80_sfft;
  209. uint64_t spectral_vhtseg1id_mismatch;
  210. uint64_t spectral_vhtseg2id_mismatch;
  211. uint64_t spectral_invalid_detector_id;
  212. };
  213. /**
  214. * struct spectral_scan_state - State of spectral scan
  215. * @is_active: Is spectral scan active
  216. * @is_enabled: Is spectral scan enabled
  217. */
  218. struct spectral_scan_state {
  219. uint8_t is_active;
  220. uint8_t is_enabled;
  221. };
  222. /* Forward declarations */
  223. struct wlan_objmgr_pdev;
  224. /**
  225. * struct spectral_nl_cb - Spectral Netlink callbacks
  226. * @get_nbuff: Get the socket buffer to send the data to the application
  227. * @send_nl_bcast: Send data to the application using netlink broadcast
  228. * @send_nl_unicast: Send data to the application using netlink unicast
  229. */
  230. struct spectral_nl_cb {
  231. void *(*get_nbuff)(struct wlan_objmgr_pdev *pdev);
  232. int (*send_nl_bcast)(struct wlan_objmgr_pdev *pdev);
  233. int (*send_nl_unicast)(struct wlan_objmgr_pdev *pdev);
  234. void (*free_nbuff)(struct wlan_objmgr_pdev *pdev);
  235. };
  236. #ifndef __KERNEL__
  237. static inline int16_t
  238. spectral_pwfactor_max(int16_t pwfactor1,
  239. int16_t pwfactor2)
  240. {
  241. return ((pwfactor1 > pwfactor2) ? pwfactor1 : pwfactor2);
  242. }
  243. /**
  244. * get_spectral_scale_rssi_corr() - Compute RSSI correction factor for scaling
  245. * @agc_total_gain_db: AGC total gain in dB steps
  246. * @gen3_defmaxgain: Default max gain value of the gen III chipset
  247. * @gen2_maxgain: Max gain value used by the reference gen II chipset
  248. * @lowlevel_offset: Low level offset for scaling
  249. * @inband_pwr: In band power in dB steps
  250. * @rssi_thr: RSSI threshold for scaling
  251. *
  252. * Helper function to compute RSSI correction factor for Gen III linear format
  253. * Spectral scaling. It is the responsibility of the caller to ensure that
  254. * correct values are passed.
  255. *
  256. * Return: RSSI correction factor
  257. */
  258. static inline int16_t
  259. get_spectral_scale_rssi_corr(u_int8_t agc_total_gain_db,
  260. u_int8_t gen3_defmaxgain, u_int8_t gen2_maxgain,
  261. int16_t lowlevel_offset, int16_t inband_pwr,
  262. int16_t rssi_thr)
  263. {
  264. return ((agc_total_gain_db < gen3_defmaxgain) ?
  265. (gen2_maxgain - gen3_defmaxgain + lowlevel_offset) :
  266. spectral_pwfactor_max((inband_pwr - rssi_thr), 0));
  267. }
  268. /**
  269. * spectral_scale_linear_to_gen2() - Scale linear bin value to gen II equivalent
  270. * @gen3_binmag: Captured FFT bin value from the Spectral Search FFT report
  271. * generated by the Gen III chipset
  272. * @gen2_maxgain: Max gain value used by the reference gen II chipset
  273. * @gen3_defmaxgain: Default max gain value of the gen III chipset
  274. * @lowlevel_offset: Low level offset for scaling
  275. * @inband_pwr: In band power in dB steps
  276. * @rssi_thr: RSSI threshold for scaling
  277. * @agc_total_gain_db: AGC total gain in dB steps
  278. * @highlevel_offset: High level offset for scaling
  279. * @gen2_bin_scale: Bin scale value used on reference gen II chipset
  280. * @gen3_bin_scale: Bin scale value used on gen III chipset
  281. *
  282. * Helper function to scale a given gen III linear format bin value into an
  283. * approximately equivalent gen II value. The scaled value can possibly be
  284. * higher than 8 bits. If the caller is incapable of handling values larger
  285. * than 8 bits, the caller can saturate the value at 255. This function does not
  286. * carry out this saturation for the sake of flexibility so that callers
  287. * interested in the larger values can avail of this. Also note it is the
  288. * responsibility of the caller to ensure that correct values are passed.
  289. *
  290. * Return: Scaled bin value
  291. */
  292. static inline u_int32_t
  293. spectral_scale_linear_to_gen2(u_int8_t gen3_binmag,
  294. u_int8_t gen2_maxgain, u_int8_t gen3_defmaxgain,
  295. int16_t lowlevel_offset, int16_t inband_pwr,
  296. int16_t rssi_thr, u_int8_t agc_total_gain_db,
  297. int16_t highlevel_offset, u_int8_t gen2_bin_scale,
  298. u_int8_t gen3_bin_scale)
  299. {
  300. return (gen3_binmag *
  301. sqrt(pow(10, (((double)spectral_pwfactor_max(gen2_maxgain -
  302. gen3_defmaxgain + lowlevel_offset -
  303. get_spectral_scale_rssi_corr(agc_total_gain_db,
  304. gen3_defmaxgain,
  305. gen2_maxgain,
  306. lowlevel_offset,
  307. inband_pwr,
  308. rssi_thr),
  309. (agc_total_gain_db < gen3_defmaxgain) *
  310. highlevel_offset)) / 10))) *
  311. pow(2, (gen3_bin_scale - gen2_bin_scale)));
  312. }
  313. #endif /* __KERNEL__ */
  314. #endif /* _WLAN_SPECTRAL_PUBLIC_STRUCTS_H_ */