wlan_utility.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. /*
  2. * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /**
  17. * DOC: Contains mandatory API from legacy
  18. */
  19. #ifndef _WLAN_UTILITY_H_
  20. #define _WLAN_UTILITY_H_
  21. #include <qdf_types.h>
  22. #include <wlan_objmgr_psoc_obj.h>
  23. #include <wlan_objmgr_pdev_obj.h>
  24. #include <wlan_objmgr_vdev_obj.h>
  25. #define TGT_INVALID_SNR (0)
  26. #define TGT_MAX_SNR (TGT_NOISE_FLOOR_DBM * (-1))
  27. #define TGT_NOISE_FLOOR_DBM (-96)
  28. #define TGT_IS_VALID_SNR(x) ((x) >= 0 && (x) < TGT_MAX_SNR)
  29. #define TGT_IS_VALID_RSSI(x) ((x) != 0xFF)
  30. /**
  31. * struct wlan_vdev_ch_check_filter - vdev chan check filter object
  32. * @flag: matches or not
  33. * @vdev: vdev to be checked against all the active vdevs
  34. */
  35. struct wlan_vdev_ch_check_filter {
  36. uint8_t flag;
  37. struct wlan_objmgr_vdev *vdev;
  38. };
  39. /**
  40. * struct wlan_peer_count- vdev connected peer count
  41. * @opmode: QDF mode
  42. * @peer_count: peer count
  43. **/
  44. struct wlan_op_mode_peer_count {
  45. enum QDF_OPMODE opmode;
  46. uint16_t peer_count;
  47. };
  48. /**
  49. * wlan_chan_to_freq() - converts channel to frequency
  50. * @chan: channel number
  51. *
  52. * @return frequency of the channel
  53. */
  54. uint32_t wlan_chan_to_freq(uint8_t chan);
  55. /**
  56. * wlan_get_320_center_freq() - find center frequencies for 320Mhz channel
  57. * @freq: Primary frequency
  58. * @center_freq1: possible 1st center frequency
  59. * @center_freq2: possible 2nd center frequency
  60. *
  61. * return: void
  62. **/
  63. void
  64. wlan_get_320_center_freq(qdf_freq_t freq,
  65. qdf_freq_t *center_freq1,
  66. qdf_freq_t *center_freq2);
  67. /**
  68. * wlan_freq_to_chan() - converts frequency to channel
  69. * @freq: frequency
  70. *
  71. * Return: channel of frequency
  72. */
  73. uint8_t wlan_freq_to_chan(uint32_t freq);
  74. /**
  75. * wlan_is_ie_valid() - Determine if an IE sequence is valid
  76. * @ie: Pointer to the IE buffer
  77. * @ie_len: Length of the IE buffer @ie
  78. *
  79. * This function validates that the IE sequence is valid by verifying
  80. * that the sum of the lengths of the embedded elements match the
  81. * length of the sequence.
  82. *
  83. * Note well that a 0-length IE sequence is considered valid.
  84. *
  85. * Return: true if the IE sequence is valid, false if it is invalid
  86. */
  87. bool wlan_is_ie_valid(const uint8_t *ie, size_t ie_len);
  88. /**
  89. * wlan_get_ie_ptr_from_eid() - Find out ie from eid
  90. * @eid: element id
  91. * @ie: source ie address
  92. * @ie_len: source ie length
  93. *
  94. * Return: vendor ie address - success
  95. * NULL - failure
  96. */
  97. const uint8_t *wlan_get_ie_ptr_from_eid(uint8_t eid,
  98. const uint8_t *ie,
  99. int ie_len);
  100. /**
  101. * wlan_get_vendor_ie_ptr_from_oui() - Find out vendor ie
  102. * @oui: oui buffer
  103. * @oui_size: oui size
  104. * @ie: source ie address
  105. * @ie_len: source ie length
  106. *
  107. * This function find out vendor ie by pass source ie and vendor oui.
  108. *
  109. * Return: vendor ie address - success
  110. * NULL - failure
  111. */
  112. const uint8_t *wlan_get_vendor_ie_ptr_from_oui(const uint8_t *oui,
  113. uint8_t oui_size,
  114. const uint8_t *ie,
  115. uint16_t ie_len);
  116. /**
  117. * wlan_get_ext_ie_ptr_from_ext_id() - Find out ext ie
  118. * @oui: oui buffer
  119. * @oui_size: oui size
  120. * @ie: source ie address
  121. * @ie_len: source ie length
  122. *
  123. * This function find out ext ie from ext id (passed oui)
  124. *
  125. * Return: vendor ie address - success
  126. * NULL - failure
  127. */
  128. const uint8_t *wlan_get_ext_ie_ptr_from_ext_id(const uint8_t *oui,
  129. uint8_t oui_size,
  130. const uint8_t *ie,
  131. uint16_t ie_len);
  132. /**
  133. * wlan_is_emulation_platform() - check if platform is emulation based
  134. * @phy_version - psoc nif phy_version
  135. *
  136. * Return: boolean value based on platform type
  137. */
  138. bool wlan_is_emulation_platform(uint32_t phy_version);
  139. /**
  140. * wlan_get_pdev_id_from_vdev_id() - Helper func to derive pdev id from vdev_id
  141. * @psoc: psoc object
  142. * @vdev_id: vdev identifier
  143. * @dbg_id: object manager debug id
  144. *
  145. * This function is used to derive the pdev id from vdev id for a psoc
  146. *
  147. * Return : pdev_id - +ve integer for success and WLAN_INVALID_PDEV_ID
  148. * for failure
  149. */
  150. uint32_t wlan_get_pdev_id_from_vdev_id(struct wlan_objmgr_psoc *psoc,
  151. uint8_t vdev_id,
  152. wlan_objmgr_ref_dbgid dbg_id);
  153. /**
  154. * wlan_util_is_vdev_active() - Check for vdev active
  155. * @pdev: pdev pointer
  156. * @dbg_id: debug id for ref counting
  157. *
  158. * Return: QDF_STATUS_SUCCESS in case of vdev active
  159. * QDF_STATUS_E_INVAL, if dev is not active
  160. */
  161. QDF_STATUS wlan_util_is_vdev_active(struct wlan_objmgr_pdev *pdev,
  162. wlan_objmgr_ref_dbgid dbg_id);
  163. /**
  164. * wlan_vdev_is_up() - Check for vdev is in UP state
  165. * @vdev: vdev pointer
  166. *
  167. * Return: QDF_STATUS_SUCCESS, if vdev is in up, otherwise QDF_STATUS_E_FAILURE
  168. */
  169. QDF_STATUS wlan_vdev_is_up(struct wlan_objmgr_vdev *vdev);
  170. /**
  171. * wlan_util_pdev_vdevs_deschan_match() - function to check des channel matches
  172. * with other vdevs in pdev
  173. * @pdev: pdev object
  174. * @vdev: vdev object
  175. * @ref_id: object manager ref id
  176. *
  177. * This function checks the vdev desired channel with other vdev channels
  178. *
  179. * Return: QDF_STATUS_SUCCESS, if it matches, otherwise QDF_STATUS_E_FAILURE
  180. */
  181. QDF_STATUS wlan_util_pdev_vdevs_deschan_match(struct wlan_objmgr_pdev *pdev,
  182. struct wlan_objmgr_vdev *vdev,
  183. wlan_objmgr_ref_dbgid dbg_id);
  184. /**
  185. * wlan_util_change_map_index() - function to set/reset given index bit
  186. * @map: bitmpap
  187. * @id: bit index
  188. * @set: 1 for set, 0 of reset
  189. *
  190. * This function set/reset given index bit
  191. *
  192. * Return: void
  193. */
  194. void wlan_util_change_map_index(unsigned long *map, uint8_t id, uint8_t set);
  195. /**
  196. * wlan_util_map_index_is_set() - function to check whether given index bit is
  197. * set
  198. * @map: bitmpap
  199. * @id: bit index
  200. *
  201. * This function checks the given index bit is set
  202. *
  203. * Return: true, if bit is set, otherwise false
  204. */
  205. bool wlan_util_map_index_is_set(unsigned long *map, uint8_t id);
  206. /**
  207. * wlan_util_map_is_any_index_set() - Check if any bit is set in given bitmap
  208. * @map: bitmap
  209. * @nbytes: number of bytes in bitmap
  210. *
  211. * Return: true, if any of the bit is set, otherwise false
  212. */
  213. bool wlan_util_map_is_any_index_set(unsigned long *map, unsigned long nbytes);
  214. /**
  215. * wlan_pdev_chan_change_pending_vdevs() - function to test/set channel change
  216. * pending flag
  217. * @pdev: pdev object
  218. * @vdev_id_map: bitmap to derive channel change vdevs
  219. * @ref_id: object manager ref id
  220. *
  221. * This function test/set channel change pending flag
  222. *
  223. * Return: QDF_STATUS_SUCCESS, if it iterates through all vdevs,
  224. * otherwise QDF_STATUS_E_FAILURE
  225. */
  226. QDF_STATUS wlan_pdev_chan_change_pending_vdevs(struct wlan_objmgr_pdev *pdev,
  227. unsigned long *vdev_id_map,
  228. wlan_objmgr_ref_dbgid dbg_id);
  229. /**
  230. * wlan_pdev_chan_change_pending_vdevs_down() - function to test/set down
  231. * change pending flag
  232. * @pdev: pdev object
  233. * @vdev_id_map: bitmap to derive channel change vdevs
  234. * @ref_id: object manager ref id
  235. *
  236. * This function test/set channel change pending flag
  237. *
  238. * Return: QDF_STATUS_SUCCESS, if it iterates through all vdevs,
  239. * otherwise QDF_STATUS_E_FAILURE
  240. */
  241. QDF_STATUS wlan_pdev_chan_change_pending_vdevs_down(
  242. struct wlan_objmgr_pdev *pdev,
  243. unsigned long *vdev_id_map,
  244. wlan_objmgr_ref_dbgid dbg_id);
  245. /**
  246. * wlan_pdev_chan_change_pending_ap_vdevs_down() - function to test/set channel
  247. * change pending flag for AP VDEVs
  248. * @pdev: pdev object
  249. * @vdev_id_map: bitmap to derive channel change AP vdevs
  250. * @ref_id: object manager ref id
  251. *
  252. * This function test/set channel change pending flag for AP vdevs
  253. *
  254. * Return: QDF_STATUS_SUCCESS, if it iterates through all vdevs,
  255. * otherwise QDF_STATUS_E_FAILURE
  256. */
  257. QDF_STATUS wlan_pdev_chan_change_pending_ap_vdevs_down(
  258. struct wlan_objmgr_pdev *pdev,
  259. unsigned long *vdev_id_map,
  260. wlan_objmgr_ref_dbgid dbg_id);
  261. /**
  262. * wlan_chan_eq() - function to check whether both channels are same
  263. * @chan1: channel1 object
  264. * @chan2: channel2 object
  265. *
  266. * This function checks the chan1 and chan2 are same
  267. *
  268. * Return: QDF_STATUS_SUCCESS, if it matches, otherwise QDF_STATUS_E_FAILURE
  269. */
  270. QDF_STATUS wlan_chan_eq(struct wlan_channel *chan1, struct wlan_channel *chan2);
  271. /**
  272. * wlan_chan_copy() - function to copy channel
  273. * @tgt: target channel object
  274. * @src: src achannel object
  275. *
  276. * This function copies channel data from src to tgt
  277. *
  278. * Return: void
  279. */
  280. void wlan_chan_copy(struct wlan_channel *tgt, struct wlan_channel *src);
  281. /**
  282. * wlan_vdev_get_active_channel() - derives the vdev operating channel
  283. * @vdev: VDEV object
  284. *
  285. * This function checks vdev state and return the channel pointer accordingly
  286. *
  287. * Return: active channel, if vdev chan config is valid
  288. * NULL, if VDEV is in INIT or STOP state
  289. */
  290. struct wlan_channel *wlan_vdev_get_active_channel
  291. (struct wlan_objmgr_vdev *vdev);
  292. /**
  293. * wlan_get_connected_vdev_by_bssid() - check/get any vdev connected on bssid
  294. * @pdev: pdev object
  295. * @bssid: bssid to be checked
  296. * @vdev_id: vdev id
  297. *
  298. * This function will loop through all the vdev in psoc and find/return the
  299. * vdev which is connected to bssid provided.
  300. *
  301. * Return: bool
  302. */
  303. bool wlan_get_connected_vdev_by_bssid(struct wlan_objmgr_pdev *pdev,
  304. uint8_t *bssid, uint8_t *vdev_id);
  305. /**
  306. * wlan_util_stats_get_rssi() - API to get rssi in dbm
  307. * @db2dbm_enabled: If db2dbm capability is enabled
  308. * @bcn_snr: beacon snr
  309. * @dat_snr: data snr
  310. * @rssi: rssi
  311. *
  312. * This function gets the rssi based on db2dbm support. If this feature is
  313. * present in hw then it means firmware directly sends rssi and no converstion
  314. * is required. If this capablity is not present then host needs to convert
  315. * snr to rssi
  316. *
  317. * Return: None
  318. */
  319. void
  320. wlan_util_stats_get_rssi(bool db2dbm_enabled, int32_t bcn_snr, int32_t dat_snr,
  321. int8_t *rssi);
  322. /**
  323. * wlan_util_is_pdev_restart_progress() - Check if any vdev is in restart state
  324. * @pdev: pdev pointer
  325. * @dbg_id: module id
  326. *
  327. * Iterates through all vdevs, checks if any VDEV is in RESTART_PROGRESS
  328. * substate
  329. *
  330. * Return: QDF_STATUS_SUCCESS,if any vdev is in RESTART_PROGRESS substate
  331. * otherwise QDF_STATUS_E_FAILURE
  332. */
  333. QDF_STATUS wlan_util_is_pdev_restart_progress(struct wlan_objmgr_pdev *pdev,
  334. wlan_objmgr_ref_dbgid dbg_id);
  335. /**
  336. * wlan_util_is_pdev_scan_allowed() - Check for vdev is allowed to scan
  337. * @pdev: pdev pointer
  338. * @dbg_id: module id
  339. *
  340. * Iterates through all vdevs, checks if any VDEV is not either in S_INIT or in
  341. * S_UP state
  342. *
  343. * Return: QDF_STATUS_SUCCESS,if scan is allowed, otherwise QDF_STATUS_E_FAILURE
  344. */
  345. QDF_STATUS wlan_util_is_pdev_scan_allowed(struct wlan_objmgr_pdev *pdev,
  346. wlan_objmgr_ref_dbgid dbg_id);
  347. /**
  348. * wlan_util_get_peer_count_for_mode - This api gives vdev mode specific
  349. * peer count`
  350. * @pdev: PDEV object
  351. * @mode: Operation mode.
  352. *
  353. * Return: int- peer count for operating mode
  354. */
  355. uint16_t wlan_util_get_peer_count_for_mode(struct wlan_objmgr_pdev *pdev,
  356. enum QDF_OPMODE mode);
  357. /**
  358. * wlan_minidump_host_data - Data structure type logged in Minidump
  359. * @WLAN_MD_CP_EXT_PDEV - ol_ath_softc_net80211
  360. * @WLAN_MD_CP_EXT_PSOC - ol_ath_soc_softc
  361. * @WLAN_MD_CP_EXT_VDEV - ieee80211vap
  362. * @WLAN_MD_CP_EXT_PEER - ieee80211_node
  363. * @WLAN_MD_DP_SOC - dp_soc
  364. * @WLAN_MD_DP_PDEV - dp_pdev
  365. * @WLAN_MD_DP_VDEV - dp_vdev
  366. * @WLAN_MD_DP_PEER - dp_peer
  367. * @WLAN_MD_DP_SRNG_REO_DEST - dp_srng type for reo dest
  368. * @WLAN_MD_DP_SRNG_REO_EXCEPTION - dp_srng type for reo exception
  369. * @WLAN_MD_DP_SRNG_REO_CMD - dp_srng type for reo cmd
  370. * @WLAN_MD_DP_SRNG_RX_REL - dp_srng type for reo release
  371. * @WLAN_MD_DP_SRNG_REO_REINJECT - dp_srng type for reo reinject
  372. * @WLAN_MD_DP_SRNG_REO_STATUS - dp_srng type for reo status
  373. * @WLAN_MD_DP_SRNG_TCL_DATA - dp_srng type for tcl data
  374. * @WLAN_MD_DP_SRNG_TCL_STATUS - dp_srng type for tcl status
  375. * @WLAN_MD_DP_SRNG_TX_COMP - dp_srng type for tcl comp
  376. * @WLAN_MD_DP_SRNG_WBM_DESC_REL - dp_srng_type for wbm desc rel
  377. * @WLAN_MD_DP_SRNG_WBM_IDLE_LINK - dp_srng type for wbm idle link
  378. * @WLAN_MD_DP_LINK_DESC_BANK - Wbm link_desc_bank
  379. * @WLAN_MD_DP_SRNG_RXDMA_MON_STATUS - dp_srng type for rxdma mon status
  380. * @WLAN_MD_DP_SRNG_RXDMA_MON_BUF - dp_srng type for rxdma mon buf
  381. * @WLAN_MD_DP_SRNG_RXDMA_MON_DST - dp_srng type for rxdma mon dest
  382. * @WLAN_MD_DP_SRNG_RXDMA_MON_DESC - dp_srng type for rxdma mon desc
  383. * @WLAN_MD_DP_SRNG_RXDMA_ERR_DST - dp_srng type for rxdma err dst
  384. * @WLAN_MD_DP_HAL_SOC - hal_soc
  385. * @WLAN_MD_OBJMGR_PSOC - wlan_objmgr_psoc
  386. * @WLAN_MD_OBJMGR_PSOC_TGT_INFO - wlan_objmgr_tgt_psoc_info
  387. * @WLAN_MD_OBJMGR_PDEV - wlan_objmgr_pdev
  388. * @WLAN_MD_OBJMGR_PDEV_MLME - pdev_mlme
  389. * @WLAN_MD_OBJMGR_VDEV - wlan_objmgr_vdev
  390. * @WLAN_MD_OBJMGR_VDEV_MLME -vdev mlme
  391. * @WLAN_MD_OBJMGR_VDEV_SM - wlan_sm
  392. * @WLAN_MD_MAX - Max value
  393. */
  394. enum wlan_minidump_host_data {
  395. WLAN_MD_CP_EXT_PDEV,
  396. WLAN_MD_CP_EXT_PSOC,
  397. WLAN_MD_CP_EXT_VDEV,
  398. WLAN_MD_CP_EXT_PEER,
  399. WLAN_MD_DP_SOC,
  400. WLAN_MD_DP_PDEV,
  401. WLAN_MD_DP_VDEV,
  402. WLAN_MD_DP_PEER,
  403. WLAN_MD_DP_SRNG_REO_DEST,
  404. WLAN_MD_DP_SRNG_REO_EXCEPTION,
  405. WLAN_MD_DP_SRNG_REO_CMD,
  406. WLAN_MD_DP_SRNG_RX_REL,
  407. WLAN_MD_DP_SRNG_REO_REINJECT,
  408. WLAN_MD_DP_SRNG_REO_STATUS,
  409. WLAN_MD_DP_SRNG_TCL_DATA,
  410. WLAN_MD_DP_SRNG_TCL_CMD,
  411. WLAN_MD_DP_SRNG_TCL_STATUS,
  412. WLAN_MD_DP_SRNG_TX_COMP,
  413. WLAN_MD_DP_SRNG_WBM_DESC_REL,
  414. WLAN_MD_DP_SRNG_WBM_IDLE_LINK,
  415. WLAN_MD_DP_LINK_DESC_BANK,
  416. WLAN_MD_DP_SRNG_RXDMA_MON_STATUS,
  417. WLAN_MD_DP_SRNG_RXDMA_MON_BUF,
  418. WLAN_MD_DP_SRNG_RXDMA_MON_DST,
  419. WLAN_MD_DP_SRNG_RXDMA_MON_DESC,
  420. WLAN_MD_DP_SRNG_RXDMA_ERR_DST,
  421. WLAN_MD_DP_HAL_SOC,
  422. WLAN_MD_OBJMGR_PSOC,
  423. WLAN_MD_OBJMGR_PSOC_TGT_INFO,
  424. WLAN_MD_OBJMGR_PDEV,
  425. WLAN_MD_OBJMGR_PDEV_MLME,
  426. WLAN_MD_OBJMGR_VDEV,
  427. WLAN_MD_OBJMGR_VDEV_MLME,
  428. WLAN_MD_OBJMGR_VDEV_SM,
  429. WLAN_MD_MAX
  430. };
  431. /**
  432. * wlan_minidump_log() - Log memory address to be included in minidump
  433. * @start_addr: Start address of the memory to be dumped
  434. * @size: Size in bytes
  435. * @psoc_obj: Psoc Object
  436. * @type: Type of data structure
  437. * @name: String to identify this entry
  438. */
  439. void wlan_minidump_log(void *start_addr, const size_t size,
  440. void *psoc_obj,
  441. enum wlan_minidump_host_data type,
  442. const char *name);
  443. /**
  444. * wlan_minidump_remove() - Remove memory address from minidump
  445. * @start_addr: Start address of the memory previously added
  446. * @size: Size in bytes
  447. * @psoc_obj: Psoc Object
  448. * @type: Type of data structure
  449. * @name: String to identify this entry
  450. */
  451. void wlan_minidump_remove(void *start_addr, const size_t size,
  452. void *psoc_obj,
  453. enum wlan_minidump_host_data type,
  454. const char *name);
  455. #endif /* _WLAN_UTILITY_H_ */