wlan_spectral_public_structs.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. /*
  2. * Copyright (c) 2011,2017-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022-2023 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. * @SPECTRAL_MSG_BUF_TYPE_MAX: Max enumeration
  128. */
  129. enum spectral_msg_buf_type {
  130. SPECTRAL_MSG_BUF_NEW,
  131. SPECTRAL_MSG_BUF_SAVED,
  132. SPECTRAL_MSG_BUF_TYPE_MAX,
  133. };
  134. /**
  135. * enum spectral_msg_type - Spectral SAMP message type
  136. * @SPECTRAL_MSG_NORMAL_MODE: Normal mode Spectral SAMP message
  137. * @SPECTRAL_MSG_AGILE_MODE: Agile mode Spectral SAMP message
  138. * @SPECTRAL_MSG_INTERFERENCE_NOTIFICATION: Interference notification to
  139. * external auto channel selection
  140. * entity
  141. * @SPECTRAL_MSG_TYPE_MAX: Spectral SAMP message type max
  142. */
  143. enum spectral_msg_type {
  144. SPECTRAL_MSG_NORMAL_MODE,
  145. SPECTRAL_MSG_AGILE_MODE,
  146. SPECTRAL_MSG_INTERFERENCE_NOTIFICATION,
  147. SPECTRAL_MSG_TYPE_MAX,
  148. };
  149. /**
  150. * enum spectral_debug - Spectral debug level
  151. * @DEBUG_SPECTRAL: Minimal SPECTRAL debug
  152. * @DEBUG_SPECTRAL1: Normal SPECTRAL debug
  153. * @DEBUG_SPECTRAL2: Maximal SPECTRAL debug
  154. * @DEBUG_SPECTRAL3: Matched filterID display
  155. * @DEBUG_SPECTRAL4: One time dump of FFT report
  156. */
  157. enum spectral_debug {
  158. DEBUG_SPECTRAL = 0x00000100,
  159. DEBUG_SPECTRAL1 = 0x00000200,
  160. DEBUG_SPECTRAL2 = 0x00000400,
  161. DEBUG_SPECTRAL3 = 0x00000800,
  162. DEBUG_SPECTRAL4 = 0x00001000,
  163. };
  164. /**
  165. * enum spectral_capability_type - Spectral capability type
  166. * @SPECTRAL_CAP_PHYDIAG: Phydiag capability
  167. * @SPECTRAL_CAP_RADAR: Radar detection capability
  168. * @SPECTRAL_CAP_SPECTRAL_SCAN: Spectral capability
  169. * @SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN: Advanced spectral capability
  170. */
  171. enum spectral_capability_type {
  172. SPECTRAL_CAP_PHYDIAG,
  173. SPECTRAL_CAP_RADAR,
  174. SPECTRAL_CAP_SPECTRAL_SCAN,
  175. SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN,
  176. };
  177. /**
  178. * enum spectral_cp_error_code - Spectral control path response code
  179. * @SPECTRAL_SCAN_ERR_INVALID: Invalid error identifier
  180. * @SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED: parameter unsupported
  181. * @SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED: mode unsupported
  182. * @SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE: invalid parameter value
  183. * @SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED: parameter uninitialized
  184. */
  185. enum spectral_cp_error_code {
  186. SPECTRAL_SCAN_ERR_INVALID,
  187. SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED,
  188. SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED,
  189. SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE,
  190. SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED,
  191. };
  192. /**
  193. * enum spectral_dma_debug - Spectral DMA debug
  194. * @SPECTRAL_DMA_RING_DEBUG: Spectral DMA ring debug
  195. * @SPECTRAL_DMA_BUFFER_DEBUG: Spectral DMA buffer debug
  196. */
  197. enum spectral_dma_debug {
  198. SPECTRAL_DMA_RING_DEBUG,
  199. SPECTRAL_DMA_BUFFER_DEBUG,
  200. };
  201. struct wiphy;
  202. struct wlan_objmgr_pdev;
  203. struct wlan_objmgr_vdev;
  204. /**
  205. * struct spectral_cfg80211_vendor_cmd_handlers - Spectral vendor command
  206. * handlers
  207. * @wlan_cfg80211_spectral_scan_start: start scan handler
  208. * @wlan_cfg80211_spectral_scan_stop: stop scan handler
  209. * @wlan_cfg80211_spectral_scan_get_config: get config handler
  210. * @wlan_cfg80211_spectral_scan_get_diag_stats: get diag stats handler
  211. * @wlan_cfg80211_spectral_scan_get_cap: get capability handler
  212. * @wlan_cfg80211_spectral_scan_get_status: get status handler
  213. */
  214. struct spectral_cfg80211_vendor_cmd_handlers {
  215. int (*wlan_cfg80211_spectral_scan_start)(struct wiphy *wiphy,
  216. struct wlan_objmgr_pdev *pdev,
  217. struct wlan_objmgr_vdev *vdev,
  218. const void *data,
  219. int data_len);
  220. int (*wlan_cfg80211_spectral_scan_stop)(struct wiphy *wiphy,
  221. struct wlan_objmgr_pdev *pdev,
  222. struct wlan_objmgr_vdev *vdev,
  223. const void *data,
  224. int data_len);
  225. int (*wlan_cfg80211_spectral_scan_get_config)(
  226. struct wiphy *wiphy,
  227. struct wlan_objmgr_pdev *pdev,
  228. struct wlan_objmgr_vdev *vdev,
  229. const void *data,
  230. int data_len);
  231. int (*wlan_cfg80211_spectral_scan_get_diag_stats)(
  232. struct wiphy *wiphy,
  233. struct wlan_objmgr_pdev *pdev,
  234. struct wlan_objmgr_vdev *vdev,
  235. const void *data,
  236. int data_len);
  237. int (*wlan_cfg80211_spectral_scan_get_cap)(
  238. struct wiphy *wiphy,
  239. struct wlan_objmgr_pdev *pdev,
  240. struct wlan_objmgr_vdev *vdev,
  241. const void *data,
  242. int data_len);
  243. int (*wlan_cfg80211_spectral_scan_get_status)(
  244. struct wiphy *wiphy,
  245. struct wlan_objmgr_pdev *pdev,
  246. struct wlan_objmgr_vdev *vdev,
  247. const void *data,
  248. int data_len);
  249. };
  250. /**
  251. * struct spectral_cp_param - Spectral control path data structure which
  252. * contains parameter and its value
  253. * @id: Parameter ID
  254. * @value: Single parameter value
  255. * @freq: Spectral scan frequency
  256. */
  257. struct spectral_cp_param {
  258. uint32_t id;
  259. union {
  260. uint32_t value;
  261. struct spectral_config_frequency freq;
  262. };
  263. };
  264. /**
  265. * struct spectral_chan_stats - channel status info
  266. * @cycle_count: Cycle count
  267. * @channel_load: Channel load
  268. * @per: Period
  269. * @noisefloor: Noise floor
  270. * @comp_usablity: Computed usability
  271. * @maxregpower: Maximum allowed regulatory power
  272. * @comp_usablity_sec80: Computed usability of secondary 80 Mhz
  273. * @maxregpower_sec80: Max regulatory power of secondary 80 Mhz
  274. */
  275. struct spectral_chan_stats {
  276. int cycle_count;
  277. int channel_load;
  278. int per;
  279. int noisefloor;
  280. uint16_t comp_usablity;
  281. int8_t maxregpower;
  282. uint16_t comp_usablity_sec80;
  283. int8_t maxregpower_sec80;
  284. };
  285. /**
  286. * struct spectral_diag_stats - spectral diag stats
  287. * @spectral_mismatch: Spectral TLV signature mismatches
  288. * @spectral_sec80_sfft_insufflen: Insufficient length when parsing for
  289. * Secondary 80 Search FFT report
  290. * @spectral_no_sec80_sfft: Secondary 80 Search FFT report
  291. * TLV not found
  292. * @spectral_vhtseg1id_mismatch: VHT Operation Segment 1 ID
  293. * mismatches in Search FFT report
  294. * @spectral_vhtseg2id_mismatch: VHT Operation Segment 2 ID
  295. * mismatches in Search FFT report
  296. * @spectral_invalid_detector_id: Invalid detector id
  297. */
  298. struct spectral_diag_stats {
  299. uint64_t spectral_mismatch;
  300. uint64_t spectral_sec80_sfft_insufflen;
  301. uint64_t spectral_no_sec80_sfft;
  302. uint64_t spectral_vhtseg1id_mismatch;
  303. uint64_t spectral_vhtseg2id_mismatch;
  304. uint64_t spectral_invalid_detector_id;
  305. };
  306. /**
  307. * struct spectral_scan_state - State of spectral scan
  308. * @is_active: Is spectral scan active
  309. * @is_enabled: Is spectral scan enabled
  310. */
  311. struct spectral_scan_state {
  312. uint8_t is_active;
  313. uint8_t is_enabled;
  314. };
  315. /* Forward declarations */
  316. struct wlan_objmgr_pdev;
  317. /**
  318. * struct spectral_nl_cb - Spectral Netlink callbacks
  319. * @get_sbuff: Get the socket buffer to send the data to the application
  320. * @send_nl_bcast: Send data to the application using netlink broadcast
  321. * @send_nl_unicast: Send data to the application using netlink unicast
  322. * @free_sbuff: Free the socket buffer for a particular message type
  323. * @convert_to_nl_ch_width:
  324. * @convert_to_phy_ch_width:
  325. */
  326. struct spectral_nl_cb {
  327. void *(*get_sbuff)(struct wlan_objmgr_pdev *pdev,
  328. enum spectral_msg_type smsg_type,
  329. enum spectral_msg_buf_type buf_type);
  330. int (*send_nl_bcast)(struct wlan_objmgr_pdev *pdev,
  331. enum spectral_msg_type smsg_type);
  332. int (*send_nl_unicast)(struct wlan_objmgr_pdev *pdev,
  333. enum spectral_msg_type smsg_type);
  334. void (*free_sbuff)(struct wlan_objmgr_pdev *pdev,
  335. enum spectral_msg_type smsg_type);
  336. int (*convert_to_nl_ch_width)(uint8_t phy_chwidth);
  337. uint8_t (*convert_to_phy_ch_width)(uint8_t nl_chwidth);
  338. };
  339. /**
  340. * struct spectral_scan_config_request - Config request
  341. * @sscan_config: Spectral parameters
  342. * @sscan_err_code: Spectral scan error code
  343. */
  344. struct spectral_scan_config_request {
  345. struct spectral_config sscan_config;
  346. enum spectral_cp_error_code sscan_err_code;
  347. };
  348. /**
  349. * struct spectral_scan_action_request - Action request
  350. * @sscan_err_code: Spectral scan error code
  351. */
  352. struct spectral_scan_action_request {
  353. enum spectral_cp_error_code sscan_err_code;
  354. };
  355. /**
  356. * struct spectral_scan_get_caps_request - Get caps request
  357. * @sscan_caps: Spectral capabilities
  358. * @sscan_err_code: Spectral scan error code
  359. */
  360. struct spectral_scan_get_caps_request {
  361. struct spectral_caps sscan_caps;
  362. enum spectral_cp_error_code sscan_err_code;
  363. };
  364. /**
  365. * struct spectral_scan_get_diag_request - Get diag request
  366. * @sscan_diag: Spectral diag stats
  367. * @sscan_err_code: Spectral scan error code
  368. */
  369. struct spectral_scan_get_diag_request {
  370. struct spectral_diag_stats sscan_diag;
  371. enum spectral_cp_error_code sscan_err_code;
  372. };
  373. /**
  374. * struct spectral_scan_get_chan_width_request - Get channel width request
  375. * @chan_width: Channel width
  376. * @sscan_err_code: Spectral scan error code
  377. */
  378. struct spectral_scan_get_chan_width_request {
  379. uint32_t chan_width;
  380. enum spectral_cp_error_code sscan_err_code;
  381. };
  382. /**
  383. * struct spectral_scan_get_status_request - Get status request
  384. * @is_active: is Spectral scan active
  385. * @is_enabled: is Spectral scan enabled
  386. * @sscan_err_code: Spectral scan error code
  387. */
  388. struct spectral_scan_get_status_request {
  389. bool is_active;
  390. bool is_enabled;
  391. enum spectral_cp_error_code sscan_err_code;
  392. };
  393. /**
  394. * struct spectral_scan_debug_request - Get/set debug level request
  395. * @spectral_dbg_level: Spectral debug level
  396. * @sscan_err_code: Spectral scan error code
  397. */
  398. struct spectral_scan_debug_request {
  399. uint32_t spectral_dbg_level;
  400. enum spectral_cp_error_code sscan_err_code;
  401. };
  402. /**
  403. * struct spectral_scan_dma_debug_request - DMA debug request
  404. * @dma_debug_enable: Enable/disable @dma_debug_type
  405. * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
  406. * @sscan_err_code: Spectral scan error code
  407. */
  408. struct spectral_scan_dma_debug_request {
  409. bool dma_debug_enable;
  410. enum spectral_dma_debug dma_debug_type;
  411. enum spectral_cp_error_code sscan_err_code;
  412. };
  413. /**
  414. * struct spectral_cp_request - Spectral control path request
  415. * Creating request and extracting response has to
  416. * be atomic.
  417. * @ss_mode: Spectral scan mode
  418. * @req_id: Request identifier
  419. * @vdev_id: VDEV id
  420. * @config_req: Spectral scan config request
  421. * @action_req: Spectral scan action request
  422. * @caps_req: Spectral scan get caps request
  423. * @diag_req: Spectral scan get diag request
  424. * @chan_width_req:Spectral scan get chan width request
  425. * @status_req: Spectral scan get status request
  426. * @debug_req: Spectral scan debug request
  427. * @dma_debug_req: Spectral DMA debug request
  428. */
  429. struct spectral_cp_request {
  430. enum spectral_scan_mode ss_mode;
  431. uint8_t req_id;
  432. uint8_t vdev_id;
  433. union {
  434. struct spectral_scan_config_request config_req;
  435. struct spectral_scan_action_request action_req;
  436. struct spectral_scan_get_caps_request caps_req;
  437. struct spectral_scan_get_diag_request diag_req;
  438. struct spectral_scan_get_chan_width_request chan_width_req;
  439. struct spectral_scan_get_status_request status_req;
  440. struct spectral_scan_debug_request debug_req;
  441. struct spectral_scan_dma_debug_request dma_debug_req;
  442. };
  443. };
  444. /**
  445. * struct spectral_data_stats - Spectral data stats
  446. * @spectral_rx_events: Number of Spectral rx events
  447. * @consume_spectral_calls: Number of consume_spectral_report() invocations
  448. * @fill_samp_msg_calls: Number of fill_samp_msg() invocations
  449. * @msgs_ready_for_user: Number of SAMP messages that are ready to be sent to
  450. * user-space
  451. * @msgs_queued_to_user: Number of SAMP messages queued to the user-space
  452. */
  453. struct spectral_data_stats {
  454. uint32_t spectral_rx_events;
  455. uint32_t consume_spectral_calls;
  456. uint32_t fill_samp_msg_calls;
  457. uint32_t msgs_ready_for_user;
  458. uint32_t msgs_queued_to_user;
  459. };
  460. #ifndef __KERNEL__
  461. static inline int16_t
  462. spectral_pwfactor_max(int16_t pwfactor1,
  463. int16_t pwfactor2)
  464. {
  465. return ((pwfactor1 > pwfactor2) ? pwfactor1 : pwfactor2);
  466. }
  467. /**
  468. * get_spectral_scale_rssi_corr() - Compute RSSI correction factor for scaling
  469. * @agc_total_gain_db: AGC total gain in dB steps
  470. * @gen3_defmaxgain: Default max gain value of the gen III chipset
  471. * @gen2_maxgain: Max gain value used by the reference gen II chipset
  472. * @lowlevel_offset: Low level offset for scaling
  473. * @inband_pwr: In band power in dB steps
  474. * @rssi_thr: RSSI threshold for scaling
  475. *
  476. * Helper function to compute RSSI correction factor for Gen III linear format
  477. * Spectral scaling. It is the responsibility of the caller to ensure that
  478. * correct values are passed.
  479. *
  480. * Return: RSSI correction factor
  481. */
  482. static inline int16_t
  483. get_spectral_scale_rssi_corr(u_int8_t agc_total_gain_db,
  484. u_int8_t gen3_defmaxgain, u_int8_t gen2_maxgain,
  485. int16_t lowlevel_offset, int16_t inband_pwr,
  486. int16_t rssi_thr)
  487. {
  488. return ((agc_total_gain_db < gen3_defmaxgain) ?
  489. (gen2_maxgain - gen3_defmaxgain + lowlevel_offset) :
  490. spectral_pwfactor_max((inband_pwr - rssi_thr), 0));
  491. }
  492. /**
  493. * spectral_scale_linear_to_gen2() - Scale linear bin value to gen II equivalent
  494. * @gen3_binmag: Captured FFT bin value from the Spectral Search FFT report
  495. * generated by the Gen III chipset
  496. * @gen2_maxgain: Max gain value used by the reference gen II chipset
  497. * @gen3_defmaxgain: Default max gain value of the gen III chipset
  498. * @lowlevel_offset: Low level offset for scaling
  499. * @inband_pwr: In band power in dB steps
  500. * @rssi_thr: RSSI threshold for scaling
  501. * @agc_total_gain_db: AGC total gain in dB steps
  502. * @highlevel_offset: High level offset for scaling
  503. * @gen2_bin_scale: Bin scale value used on reference gen II chipset
  504. * @gen3_bin_scale: Bin scale value used on gen III chipset
  505. *
  506. * Helper function to scale a given gen III linear format bin value into an
  507. * approximately equivalent gen II value. The scaled value can possibly be
  508. * higher than 8 bits. If the caller is incapable of handling values larger
  509. * than 8 bits, the caller can saturate the value at 255. This function does not
  510. * carry out this saturation for the sake of flexibility so that callers
  511. * interested in the larger values can avail of this. Also note it is the
  512. * responsibility of the caller to ensure that correct values are passed.
  513. *
  514. * Return: Scaled bin value
  515. */
  516. static inline u_int32_t
  517. spectral_scale_linear_to_gen2(u_int8_t gen3_binmag,
  518. u_int8_t gen2_maxgain, u_int8_t gen3_defmaxgain,
  519. int16_t lowlevel_offset, int16_t inband_pwr,
  520. int16_t rssi_thr, u_int8_t agc_total_gain_db,
  521. int16_t highlevel_offset, u_int8_t gen2_bin_scale,
  522. u_int8_t gen3_bin_scale)
  523. {
  524. return (gen3_binmag *
  525. sqrt(pow(10, (((double)spectral_pwfactor_max(gen2_maxgain -
  526. gen3_defmaxgain + lowlevel_offset -
  527. get_spectral_scale_rssi_corr(agc_total_gain_db,
  528. gen3_defmaxgain,
  529. gen2_maxgain,
  530. lowlevel_offset,
  531. inband_pwr,
  532. rssi_thr),
  533. (agc_total_gain_db < gen3_defmaxgain) *
  534. highlevel_offset)) / 10))) *
  535. pow(2, (gen3_bin_scale - gen2_bin_scale)));
  536. }
  537. #endif /* __KERNEL__ */
  538. #endif /* _WLAN_SPECTRAL_PUBLIC_STRUCTS_H_ */