wlan_spectral_public_structs.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /*
  2. * Copyright (c) 2011,2017-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. *
  6. * Permission to use, copy, modify, and/or distribute this software for
  7. * any purpose with or without fee is hereby granted, provided that the
  8. * above copyright notice and this permission notice appear in all
  9. * copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  12. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  13. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  14. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  15. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  16. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  17. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  18. * PERFORMANCE OF THIS SOFTWARE.
  19. */
  20. #include <qdf_types.h>
  21. #include "wlan_dfs_ioctl.h"
  22. #include <spectral_ioctl.h>
  23. #ifndef __KERNEL__
  24. #include <math.h>
  25. #endif /* __KERNEL__ */
  26. #ifndef _WLAN_SPECTRAL_PUBLIC_STRUCTS_H_
  27. #define _WLAN_SPECTRAL_PUBLIC_STRUCTS_H_
  28. #ifndef AH_MAX_CHAINS
  29. #define AH_MAX_CHAINS 3
  30. #endif
  31. #define MAX_NUM_CHANNELS 255
  32. #define SPECTRAL_PHYERR_PARAM_NOVAL 65535
  33. #ifdef SPECTRAL_USE_EMU_DEFAULTS
  34. /* Use defaults from emulation */
  35. #define SPECTRAL_SCAN_ACTIVE_DEFAULT (0x0)
  36. #define SPECTRAL_SCAN_ENABLE_DEFAULT (0x0)
  37. #define SPECTRAL_SCAN_COUNT_DEFAULT (0x0)
  38. #define SPECTRAL_SCAN_PERIOD_DEFAULT (250)
  39. #define SPECTRAL_SCAN_PRIORITY_DEFAULT (0x1)
  40. #define SPECTRAL_SCAN_FFT_SIZE_DEFAULT (0x7)
  41. #define SPECTRAL_SCAN_GC_ENA_DEFAULT (0x1)
  42. #define SPECTRAL_SCAN_RESTART_ENA_DEFAULT (0x0)
  43. #define SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT (0xa0)
  44. #define SPECTRAL_SCAN_INIT_DELAY_DEFAULT (0x50)
  45. #define SPECTRAL_SCAN_NB_TONE_THR_DEFAULT (0xc)
  46. #define SPECTRAL_SCAN_STR_BIN_THR_DEFAULT (0x7)
  47. #define SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT (0x0)
  48. #define SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT (0x1)
  49. #define SPECTRAL_SCAN_RSSI_THR_DEFAULT (0xf)
  50. #define SPECTRAL_SCAN_PWR_FORMAT_DEFAULT (0x1)
  51. #define SPECTRAL_SCAN_RPT_MODE_DEFAULT (0x2)
  52. #define SPECTRAL_SCAN_BIN_SCALE_DEFAULT (0x1)
  53. #define SPECTRAL_SCAN_DBM_ADJ_DEFAULT (0x0)
  54. #define SPECTRAL_SCAN_CHN_MASK_DEFAULT (0x1)
  55. #else
  56. /*
  57. * Static default values for spectral state and configuration.
  58. * These definitions should be treated as temporary. Ideally,
  59. * we should get the defaults from firmware - this will be discussed.
  60. *
  61. * Use defaults from Spectral Hardware Micro-Architecture
  62. * document (v1.0)
  63. */
  64. #define SPECTRAL_SCAN_ACTIVE_DEFAULT (0)
  65. #define SPECTRAL_SCAN_ENABLE_DEFAULT (0)
  66. #define SPECTRAL_SCAN_COUNT_DEFAULT (0)
  67. #define SPECTRAL_SCAN_PERIOD_GEN_I_DEFAULT (35)
  68. #define SPECTRAL_SCAN_PERIOD_GEN_II_DEFAULT (35)
  69. #define SPECTRAL_SCAN_PERIOD_GEN_III_DEFAULT (224)
  70. #define SPECTRAL_SCAN_PRIORITY_DEFAULT (1)
  71. #define SPECTRAL_SCAN_FFT_SIZE_DEFAULT (7)
  72. #define SPECTRAL_SCAN_GC_ENA_DEFAULT (1)
  73. #define SPECTRAL_SCAN_RESTART_ENA_DEFAULT (0)
  74. #define SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT (-96)
  75. #define SPECTRAL_SCAN_INIT_DELAY_DEFAULT (80)
  76. #define SPECTRAL_SCAN_NB_TONE_THR_DEFAULT (12)
  77. #define SPECTRAL_SCAN_STR_BIN_THR_DEFAULT (8)
  78. #define SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT (0)
  79. #define SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT (0)
  80. #define SPECTRAL_SCAN_RSSI_THR_DEFAULT (0xf0)
  81. #define SPECTRAL_SCAN_PWR_FORMAT_DEFAULT (0)
  82. #define SPECTRAL_SCAN_RPT_MODE_DEFAULT (2)
  83. #define SPECTRAL_SCAN_BIN_SCALE_DEFAULT (1)
  84. #define SPECTRAL_SCAN_DBM_ADJ_DEFAULT (1)
  85. #define SPECTRAL_SCAN_CHN_MASK_DEFAULT (1)
  86. #define SPECTRAL_SCAN_FREQUENCY_DEFAULT (0)
  87. #define SPECTRAL_FFT_RECAPTURE_DEFAULT (0)
  88. #endif /* SPECTRAL_USE_EMU_DEFAULTS */
  89. /* The below two definitions apply only to pre-11ac chipsets */
  90. #define SPECTRAL_SCAN_SHORT_REPORT_DEFAULT (1)
  91. #define SPECTRAL_SCAN_FFT_PERIOD_DEFAULT (1)
  92. /*
  93. * Definitions to help in scaling of gen3 linear format Spectral bins to values
  94. * similar to those from gen2 chipsets.
  95. */
  96. /*
  97. * Max gain for QCA9984. Since this chipset is a prime representative of gen2
  98. * chipsets, it is chosen for this value.
  99. */
  100. #define SPECTRAL_QCA9984_MAX_GAIN (78)
  101. /* Temporary section for hard-coded values. These need to come from FW. */
  102. /* Max gain for IPQ8074 */
  103. #define SPECTRAL_IPQ8074_DEFAULT_MAX_GAIN_HARDCODE (62)
  104. /*
  105. * Section for values needing tuning per customer platform. These too may need
  106. * to come from FW. To be considered as hard-coded for now.
  107. */
  108. /*
  109. * If customers have a different gain line up than QCA reference designs for
  110. * IPQ8074 and/or QCA9984, they may have to tune the low level threshold and
  111. * the RSSI threshold.
  112. */
  113. #define SPECTRAL_SCALING_LOW_LEVEL_OFFSET (7)
  114. #define SPECTRAL_SCALING_RSSI_THRESH (5)
  115. /*
  116. * If customers set the AGC backoff differently, they may have to tune the high
  117. * level threshold.
  118. */
  119. #define SPECTRAL_SCALING_HIGH_LEVEL_OFFSET (5)
  120. /* End of section for values needing fine tuning. */
  121. /* End of temporary section for hard-coded values */
  122. /**
  123. * enum spectral_msg_buf_type - Spectral message buffer type
  124. * @SPECTRAL_MSG_BUF_NEW: Allocate new buffer
  125. * @SPECTRAL_MSG_BUF_SAVED: Reuse last buffer, used for secondary segment report
  126. * in case of 160 MHz.
  127. */
  128. enum spectral_msg_buf_type {
  129. SPECTRAL_MSG_BUF_NEW,
  130. SPECTRAL_MSG_BUF_SAVED,
  131. SPECTRAL_MSG_BUF_TYPE_MAX,
  132. };
  133. /**
  134. * enum spectral_msg_type - Spectral SAMP message type
  135. * @SPECTRAL_MSG_NORMAL_MODE: Normal mode Spectral SAMP message
  136. * @SPECTRAL_MSG_AGILE_MODE: Agile mode Spectral SAMP message
  137. * @SPECTRAL_MSG_INTERFERENCE_NOTIFICATION: Interference notification to
  138. * external auto channel selection
  139. * entity
  140. * @SPECTRAL_MSG_TYPE_MAX: Spectral SAMP message type max
  141. */
  142. enum spectral_msg_type {
  143. SPECTRAL_MSG_NORMAL_MODE,
  144. SPECTRAL_MSG_AGILE_MODE,
  145. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  146. SPECTRAL_MSG_TYPE_MAX,
  147. };
  148. /**
  149. * enum spectral_debug - Spectral debug level
  150. * @DEBUG_SPECTRAL: Minimal SPECTRAL debug
  151. * @DEBUG_SPECTRAL1: Normal SPECTRAL debug
  152. * @DEBUG_SPECTRAL2: Maximal SPECTRAL debug
  153. * @DEBUG_SPECTRAL3: Matched filterID display
  154. * @DEBUG_SPECTRAL4: One time dump of FFT report
  155. */
  156. enum spectral_debug {
  157. DEBUG_SPECTRAL = 0x00000100,
  158. DEBUG_SPECTRAL1 = 0x00000200,
  159. DEBUG_SPECTRAL2 = 0x00000400,
  160. DEBUG_SPECTRAL3 = 0x00000800,
  161. DEBUG_SPECTRAL4 = 0x00001000,
  162. };
  163. /**
  164. * enum spectral_capability_type - Spectral capability type
  165. * @SPECTRAL_CAP_PHYDIAG: Phydiag capability
  166. * @SPECTRAL_CAP_RADAR: Radar detection capability
  167. * @SPECTRAL_CAP_SPECTRAL_SCAN: Spectral capability
  168. * @SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN: Advanced spectral capability
  169. */
  170. enum spectral_capability_type {
  171. SPECTRAL_CAP_PHYDIAG,
  172. SPECTRAL_CAP_RADAR,
  173. SPECTRAL_CAP_SPECTRAL_SCAN,
  174. SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN,
  175. };
  176. /**
  177. * enum spectral_cp_error_code - Spectral control path response code
  178. * @SPECTRAL_SCAN_RESP_ERR_INVALID: Invalid error identifier
  179. * @SPECTRAL_SCAN_RESP_ERR_PARAM_UNSUPPORTED: parameter unsupported
  180. * @SPECTRAL_SCAN_RESP_ERR_MODE_UNSUPPORTED: mode unsupported
  181. * @SPECTRAL_SCAN_RESP_ERR_PARAM_INVALID_VALUE: invalid parameter value
  182. * @SPECTRAL_SCAN_RESP_ERR_PARAM_NOT_INITIALIZED: parameter uninitialized
  183. */
  184. enum spectral_cp_error_code {
  185. SPECTRAL_SCAN_ERR_INVALID,
  186. SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED,
  187. SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED,
  188. SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE,
  189. SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED,
  190. };
  191. /**
  192. * enum spectral_dma_debug - Spectral DMA debug
  193. * @SPECTRAL_DMA_RING_DEBUG: Spectral DMA ring debug
  194. * @SPECTRAL_DMA_BUFFER_DEBUG: Spectral DMA buffer debug
  195. */
  196. enum spectral_dma_debug {
  197. SPECTRAL_DMA_RING_DEBUG,
  198. SPECTRAL_DMA_BUFFER_DEBUG,
  199. };
  200. struct wiphy;
  201. struct wlan_objmgr_pdev;
  202. struct wlan_objmgr_vdev;
  203. /**
  204. * struct spectral_cfg80211_vendor_cmd_handlers - Spectral vendor command
  205. * handlers
  206. * @wlan_cfg80211_spectral_scan_start: start scan handler
  207. * @wlan_cfg80211_spectral_scan_stop: stop scan handler
  208. * @wlan_cfg80211_spectral_scan_get_config: get config handler
  209. * @wlan_cfg80211_spectral_scan_get_diag_stats: get diag stats handler
  210. * @wlan_cfg80211_spectral_scan_get_cap: get capability handler
  211. * @wlan_cfg80211_spectral_scan_get_status: get status handler
  212. */
  213. struct spectral_cfg80211_vendor_cmd_handlers {
  214. int (*wlan_cfg80211_spectral_scan_start)(struct wiphy *wiphy,
  215. struct wlan_objmgr_pdev *pdev,
  216. struct wlan_objmgr_vdev *vdev,
  217. const void *data,
  218. int data_len);
  219. int (*wlan_cfg80211_spectral_scan_stop)(struct wiphy *wiphy,
  220. struct wlan_objmgr_pdev *pdev,
  221. struct wlan_objmgr_vdev *vdev,
  222. const void *data,
  223. int data_len);
  224. int (*wlan_cfg80211_spectral_scan_get_config)(
  225. struct wiphy *wiphy,
  226. struct wlan_objmgr_pdev *pdev,
  227. struct wlan_objmgr_vdev *vdev,
  228. const void *data,
  229. int data_len);
  230. int (*wlan_cfg80211_spectral_scan_get_diag_stats)(
  231. struct wiphy *wiphy,
  232. struct wlan_objmgr_pdev *pdev,
  233. struct wlan_objmgr_vdev *vdev,
  234. const void *data,
  235. int data_len);
  236. int (*wlan_cfg80211_spectral_scan_get_cap)(
  237. struct wiphy *wiphy,
  238. struct wlan_objmgr_pdev *pdev,
  239. struct wlan_objmgr_vdev *vdev,
  240. const void *data,
  241. int data_len);
  242. int (*wlan_cfg80211_spectral_scan_get_status)(
  243. struct wiphy *wiphy,
  244. struct wlan_objmgr_pdev *pdev,
  245. struct wlan_objmgr_vdev *vdev,
  246. const void *data,
  247. int data_len);
  248. };
  249. /**
  250. * struct spectral_cp_param - Spectral control path data structure which
  251. * contains parameter and its value
  252. * @id: Parameter ID
  253. * @value: Single parameter value
  254. * @freq: Spectral scan frequency
  255. */
  256. struct spectral_cp_param {
  257. uint32_t id;
  258. union {
  259. uint32_t value;
  260. struct spectral_config_frequency freq;
  261. };
  262. };
  263. /**
  264. * struct spectral_chan_stats - channel status info
  265. * @cycle_count: Cycle count
  266. * @channel_load: Channel load
  267. * @per: Period
  268. * @noisefloor: Noise floor
  269. * @comp_usablity: Computed usability
  270. * @maxregpower: Maximum allowed regulatory power
  271. * @comp_usablity_sec80: Computed usability of secondary 80 Mhz
  272. * @maxregpower_sec80: Max regulatory power of secondary 80 Mhz
  273. */
  274. struct spectral_chan_stats {
  275. int cycle_count;
  276. int channel_load;
  277. int per;
  278. int noisefloor;
  279. uint16_t comp_usablity;
  280. int8_t maxregpower;
  281. uint16_t comp_usablity_sec80;
  282. int8_t maxregpower_sec80;
  283. };
  284. /**
  285. * struct spectral_diag_stats - spectral diag stats
  286. * @spectral_mismatch: Spectral TLV signature mismatches
  287. * @spectral_sec80_sfft_insufflen: Insufficient length when parsing for
  288. * Secondary 80 Search FFT report
  289. * @spectral_no_sec80_sfft: Secondary 80 Search FFT report
  290. * TLV not found
  291. * @spectral_vhtseg1id_mismatch: VHT Operation Segment 1 ID
  292. * mismatches in Search FFT report
  293. * @spectral_vhtseg2id_mismatch: VHT Operation Segment 2 ID
  294. * mismatches in Search FFT report
  295. * @spectral_invalid_detector_id: Invalid detector id
  296. */
  297. struct spectral_diag_stats {
  298. uint64_t spectral_mismatch;
  299. uint64_t spectral_sec80_sfft_insufflen;
  300. uint64_t spectral_no_sec80_sfft;
  301. uint64_t spectral_vhtseg1id_mismatch;
  302. uint64_t spectral_vhtseg2id_mismatch;
  303. uint64_t spectral_invalid_detector_id;
  304. };
  305. /**
  306. * struct spectral_scan_state - State of spectral scan
  307. * @is_active: Is spectral scan active
  308. * @is_enabled: Is spectral scan enabled
  309. */
  310. struct spectral_scan_state {
  311. uint8_t is_active;
  312. uint8_t is_enabled;
  313. };
  314. /* Forward declarations */
  315. struct wlan_objmgr_pdev;
  316. /**
  317. * struct spectral_nl_cb - Spectral Netlink callbacks
  318. * @get_sbuff: Get the socket buffer to send the data to the application
  319. * @send_nl_bcast: Send data to the application using netlink broadcast
  320. * @send_nl_unicast: Send data to the application using netlink unicast
  321. * @free_sbuff: Free the socket buffer for a particular message type
  322. */
  323. struct spectral_nl_cb {
  324. void *(*get_sbuff)(struct wlan_objmgr_pdev *pdev,
  325. enum spectral_msg_type smsg_type,
  326. enum spectral_msg_buf_type buf_type);
  327. int (*send_nl_bcast)(struct wlan_objmgr_pdev *pdev,
  328. enum spectral_msg_type smsg_type);
  329. int (*send_nl_unicast)(struct wlan_objmgr_pdev *pdev,
  330. enum spectral_msg_type smsg_type);
  331. void (*free_sbuff)(struct wlan_objmgr_pdev *pdev,
  332. enum spectral_msg_type smsg_type);
  333. int (*convert_to_nl_ch_width)(uint8_t phy_chwidth);
  334. uint8_t (*convert_to_phy_ch_width)(uint8_t nl_chwidth);
  335. };
  336. /**
  337. * struct spectral_scan_config_request - Config request
  338. * @sscan_config: Spectral parameters
  339. * @sscan_err_code: Spectral scan error code
  340. */
  341. struct spectral_scan_config_request {
  342. struct spectral_config sscan_config;
  343. enum spectral_cp_error_code sscan_err_code;
  344. };
  345. /**
  346. * struct spectral_scan_action_request - Action request
  347. * @sscan_err_code: Spectral scan error code
  348. */
  349. struct spectral_scan_action_request {
  350. enum spectral_cp_error_code sscan_err_code;
  351. };
  352. /**
  353. * struct spectral_scan_get_caps_request - Get caps request
  354. * @sscan_caps: Spectral capabilities
  355. * @sscan_err_code: Spectral scan error code
  356. */
  357. struct spectral_scan_get_caps_request {
  358. struct spectral_caps sscan_caps;
  359. enum spectral_cp_error_code sscan_err_code;
  360. };
  361. /**
  362. * struct spectral_scan_get_diag_request - Get diag request
  363. * @sscan_diag: Spectral diag stats
  364. * @sscan_err_code: Spectral scan error code
  365. */
  366. struct spectral_scan_get_diag_request {
  367. struct spectral_diag_stats sscan_diag;
  368. enum spectral_cp_error_code sscan_err_code;
  369. };
  370. /**
  371. * struct spectral_scan_get_chan_width_request - Get channel width request
  372. * @chan_width: Channel width
  373. * @sscan_err_code: Spectral scan error code
  374. */
  375. struct spectral_scan_get_chan_width_request {
  376. uint32_t chan_width;
  377. enum spectral_cp_error_code sscan_err_code;
  378. };
  379. /**
  380. * struct spectral_scan_get_status_request - Get status request
  381. * @is_active: is Spectral scan active
  382. * @is_enabled: is Spectral scan enabled
  383. * @sscan_err_code: Spectral scan error code
  384. */
  385. struct spectral_scan_get_status_request {
  386. bool is_active;
  387. bool is_enabled;
  388. enum spectral_cp_error_code sscan_err_code;
  389. };
  390. /**
  391. * struct spectral_scan_debug_request - Get/set debug level request
  392. * @spectral_dbg_level: Spectral debug level
  393. * @sscan_err_code: Spectral scan error code
  394. */
  395. struct spectral_scan_debug_request {
  396. uint32_t spectral_dbg_level;
  397. enum spectral_cp_error_code sscan_err_code;
  398. };
  399. /**
  400. * struct spectral_scan_dma_debug_request - DMA debug request
  401. * @dma_debug_enable: Enable/disable @dma_debug_type
  402. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  403. * @sscan_err_code: Spectral scan error code
  404. */
  405. struct spectral_scan_dma_debug_request {
  406. bool dma_debug_enable;
  407. enum spectral_dma_debug dma_debug_type;
  408. enum spectral_cp_error_code sscan_err_code;
  409. };
  410. /**
  411. * struct spectral_cp_request - Spectral control path request
  412. * Creating request and extracting response has to
  413. * be atomic.
  414. * @ss_mode: Spectral scan mode
  415. * @req_id: Request identifier
  416. * @vdev_id: VDEV id
  417. * @dma_debug_req: Spectral DMA debug request
  418. */
  419. struct spectral_cp_request {
  420. enum spectral_scan_mode ss_mode;
  421. uint8_t req_id;
  422. uint8_t vdev_id;
  423. union {
  424. struct spectral_scan_config_request config_req;
  425. struct spectral_scan_action_request action_req;
  426. struct spectral_scan_get_caps_request caps_req;
  427. struct spectral_scan_get_diag_request diag_req;
  428. struct spectral_scan_get_chan_width_request chan_width_req;
  429. struct spectral_scan_get_status_request status_req;
  430. struct spectral_scan_debug_request debug_req;
  431. struct spectral_scan_dma_debug_request dma_debug_req;
  432. };
  433. };
  434. /**
  435. * struct spectral_data_stats - Spectral data stats
  436. * @spectral_rx_events: Number of Spectral rx events
  437. * @consume_spectral_calls: Number of consume_spectral_report() invocations
  438. * @fill_samp_msg_calls: Number of fill_samp_msg() invocations
  439. * @msgs_ready_for_user: Number of SAMP messages that are ready to be sent to
  440. * user-space
  441. * @msgs_queued_to_user: Number of SAMP messages queued to the user-space
  442. */
  443. struct spectral_data_stats {
  444. uint32_t spectral_rx_events;
  445. uint32_t consume_spectral_calls;
  446. uint32_t fill_samp_msg_calls;
  447. uint32_t msgs_ready_for_user;
  448. uint32_t msgs_queued_to_user;
  449. };
  450. #ifndef __KERNEL__
  451. static inline int16_t
  452. spectral_pwfactor_max(int16_t pwfactor1,
  453. int16_t pwfactor2)
  454. {
  455. return ((pwfactor1 > pwfactor2) ? pwfactor1 : pwfactor2);
  456. }
  457. /**
  458. * get_spectral_scale_rssi_corr() - Compute RSSI correction factor for scaling
  459. * @agc_total_gain_db: AGC total gain in dB steps
  460. * @gen3_defmaxgain: Default max gain value of the gen III chipset
  461. * @gen2_maxgain: Max gain value used by the reference gen II chipset
  462. * @lowlevel_offset: Low level offset for scaling
  463. * @inband_pwr: In band power in dB steps
  464. * @rssi_thr: RSSI threshold for scaling
  465. *
  466. * Helper function to compute RSSI correction factor for Gen III linear format
  467. * Spectral scaling. It is the responsibility of the caller to ensure that
  468. * correct values are passed.
  469. *
  470. * Return: RSSI correction factor
  471. */
  472. static inline int16_t
  473. get_spectral_scale_rssi_corr(u_int8_t agc_total_gain_db,
  474. u_int8_t gen3_defmaxgain, u_int8_t gen2_maxgain,
  475. int16_t lowlevel_offset, int16_t inband_pwr,
  476. int16_t rssi_thr)
  477. {
  478. return ((agc_total_gain_db < gen3_defmaxgain) ?
  479. (gen2_maxgain - gen3_defmaxgain + lowlevel_offset) :
  480. spectral_pwfactor_max((inband_pwr - rssi_thr), 0));
  481. }
  482. /**
  483. * spectral_scale_linear_to_gen2() - Scale linear bin value to gen II equivalent
  484. * @gen3_binmag: Captured FFT bin value from the Spectral Search FFT report
  485. * generated by the Gen III chipset
  486. * @gen2_maxgain: Max gain value used by the reference gen II chipset
  487. * @gen3_defmaxgain: Default max gain value of the gen III chipset
  488. * @lowlevel_offset: Low level offset for scaling
  489. * @inband_pwr: In band power in dB steps
  490. * @rssi_thr: RSSI threshold for scaling
  491. * @agc_total_gain_db: AGC total gain in dB steps
  492. * @highlevel_offset: High level offset for scaling
  493. * @gen2_bin_scale: Bin scale value used on reference gen II chipset
  494. * @gen3_bin_scale: Bin scale value used on gen III chipset
  495. *
  496. * Helper function to scale a given gen III linear format bin value into an
  497. * approximately equivalent gen II value. The scaled value can possibly be
  498. * higher than 8 bits. If the caller is incapable of handling values larger
  499. * than 8 bits, the caller can saturate the value at 255. This function does not
  500. * carry out this saturation for the sake of flexibility so that callers
  501. * interested in the larger values can avail of this. Also note it is the
  502. * responsibility of the caller to ensure that correct values are passed.
  503. *
  504. * Return: Scaled bin value
  505. */
  506. static inline u_int32_t
  507. spectral_scale_linear_to_gen2(u_int8_t gen3_binmag,
  508. u_int8_t gen2_maxgain, u_int8_t gen3_defmaxgain,
  509. int16_t lowlevel_offset, int16_t inband_pwr,
  510. int16_t rssi_thr, u_int8_t agc_total_gain_db,
  511. int16_t highlevel_offset, u_int8_t gen2_bin_scale,
  512. u_int8_t gen3_bin_scale)
  513. {
  514. return (gen3_binmag *
  515. sqrt(pow(10, (((double)spectral_pwfactor_max(gen2_maxgain -
  516. gen3_defmaxgain + lowlevel_offset -
  517. get_spectral_scale_rssi_corr(agc_total_gain_db,
  518. gen3_defmaxgain,
  519. gen2_maxgain,
  520. lowlevel_offset,
  521. inband_pwr,
  522. rssi_thr),
  523. (agc_total_gain_db < gen3_defmaxgain) *
  524. highlevel_offset)) / 10))) *
  525. pow(2, (gen3_bin_scale - gen2_bin_scale)));
  526. }
  527. #endif /* __KERNEL__ */
  528. #endif /* _WLAN_SPECTRAL_PUBLIC_STRUCTS_H_ */