wlan_spectral_public_structs.h 19 KB

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