hal_be_api_mon.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /*
  2. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef _HAL_BE_API_MON_H_
  18. #define _HAL_BE_API_MON_H_
  19. #ifdef QCA_MONITOR_2_0_SUPPORT
  20. #include <mon_ingress_ring.h>
  21. #include <mon_destination_ring.h>
  22. #include "hal_be_hw_headers.h"
  23. #include <mon_ingress_ring.h>
  24. #include <mon_destination_ring.h>
  25. #include <hal_be_hw_headers.h>
  26. #include "hal_api_mon.h"
  27. #include <hal_generic_api.h>
  28. #include <hal_generic_api.h>
  29. #include <hal_api_mon.h>
  30. #define HAL_MON_BUFFER_ADDR_INFO_0_BUFFER_ADDR_31_0_OFFSET 0x00000000
  31. #define HAL_MON_BUFFER_ADDR_INFO_0_BUFFER_ADDR_31_0_LSB 0
  32. #define HAL_MON_BUFFER_ADDR_INFO_0_BUFFER_ADDR_31_0_MASK 0xffffffff
  33. #define HAL_MON_BUFFER_ADDR_INFO_1_BUFFER_ADDR_39_32_OFFSET 0x00000004
  34. #define HAL_MON_BUFFER_ADDR_INFO_1_BUFFER_ADDR_39_32_LSB 0
  35. #define HAL_MON_BUFFER_ADDR_INFO_1_BUFFER_ADDR_39_32_MASK 0x000000ff
  36. #define HAL_MON_MON_INGRESS_RING_BUFFER_VIRT_ADDR_31_0_OFFSET 0x00000008
  37. #define HAL_MON_MON_INGRESS_RING_BUFFER_VIRT_ADDR_31_0_LSB 0
  38. #define HAL_MON_MON_INGRESS_RING_BUFFER_VIRT_ADDR_31_0_MSB 31
  39. #define HAL_MON_MON_INGRESS_RING_BUFFER_VIRT_ADDR_31_0_MASK 0xffffffff
  40. #define HAL_MON_MON_INGRESS_RING_BUFFER_VIRT_ADDR_63_32_OFFSET 0x0000000c
  41. #define HAL_MON_MON_INGRESS_RING_BUFFER_VIRT_ADDR_63_32_LSB 0
  42. #define HAL_MON_MON_INGRESS_RING_BUFFER_VIRT_ADDR_63_32_MSB 31
  43. #define HAL_MON_MON_INGRESS_RING_BUFFER_VIRT_ADDR_63_32_MASK 0xffffffff
  44. #define HAL_MON_PADDR_LO_SET(buff_addr_info, paddr_lo) \
  45. ((*(((unsigned int *) buff_addr_info) + \
  46. (HAL_MON_BUFFER_ADDR_INFO_0_BUFFER_ADDR_31_0_OFFSET >> 2))) = \
  47. ((paddr_lo) << HAL_MON_BUFFER_ADDR_INFO_0_BUFFER_ADDR_31_0_LSB) & \
  48. HAL_MON_BUFFER_ADDR_INFO_0_BUFFER_ADDR_31_0_MASK)
  49. #define HAL_MON_PADDR_HI_SET(buff_addr_info, paddr_hi) \
  50. ((*(((unsigned int *) buff_addr_info) + \
  51. (HAL_MON_BUFFER_ADDR_INFO_1_BUFFER_ADDR_39_32_OFFSET >> 2))) = \
  52. ((paddr_hi) << HAL_MON_BUFFER_ADDR_INFO_1_BUFFER_ADDR_39_32_LSB) & \
  53. HAL_MON_BUFFER_ADDR_INFO_1_BUFFER_ADDR_39_32_MASK)
  54. #define HAL_MON_VADDR_LO_SET(buff_addr_info, vaddr_lo) \
  55. ((*(((unsigned int *) buff_addr_info) + \
  56. (HAL_MON_MON_INGRESS_RING_BUFFER_VIRT_ADDR_31_0_OFFSET >> 2))) = \
  57. ((vaddr_lo) << HAL_MON_MON_INGRESS_RING_BUFFER_VIRT_ADDR_31_0_LSB) & \
  58. HAL_MON_MON_INGRESS_RING_BUFFER_VIRT_ADDR_31_0_MASK)
  59. #define HAL_MON_VADDR_HI_SET(buff_addr_info, vaddr_hi) \
  60. ((*(((unsigned int *) buff_addr_info) + \
  61. (HAL_MON_MON_INGRESS_RING_BUFFER_VIRT_ADDR_63_32_OFFSET >> 2))) = \
  62. ((vaddr_hi) << HAL_MON_MON_INGRESS_RING_BUFFER_VIRT_ADDR_63_32_LSB) & \
  63. HAL_MON_MON_INGRESS_RING_BUFFER_VIRT_ADDR_63_32_MASK)
  64. enum hal_dest_desc_end_reason {
  65. HAL_TX_MON_STATUS_BUFFER_FULL = 0,
  66. HAL_TX_MON_FLUSH_DETECTED,
  67. HAL_TX_MON_END_OF_PPDU,
  68. HAL_TX_MON_PPDU_TRUNCATED
  69. };
  70. /**
  71. * struct hal_mon_desc () - HAL Monitor descriptor
  72. *
  73. * @buf_addr: virtual buffer address
  74. * @ppdu_id: ppdu id
  75. * - TxMon fills scheduler id
  76. * - RxMON fills phy_ppdu_id
  77. * @end_offset: offset (units in 4 bytes) where status buffer ended
  78. * i.e offset of TLV + last TLV size
  79. * @end_reason: 0 - status buffer is full
  80. * 1 - flush detected
  81. * 2 - TX_FES_STATUS_END or RX_PPDU_END
  82. * 3 - PPDU truncated due to system error
  83. * @initiator: 1 - descriptor belongs to TX FES
  84. * 0 - descriptor belongs to TX RESPONSE
  85. * @empty_descriptor: 0 - this descriptor is written on a flush
  86. * or end of ppdu or end of status buffer
  87. * 1 - descriptor provided to indicate drop
  88. * @ring_id: ring id for debugging
  89. * @looping_count: count to indicate number of times producer
  90. * of entries has looped around the ring
  91. */
  92. struct hal_mon_desc {
  93. uint64_t buf_addr;
  94. uint32_t ppdu_id;
  95. uint32_t end_offset:12,
  96. reserved_3a:4,
  97. end_reason:2,
  98. initiator:1,
  99. empty_descriptor:1,
  100. ring_id:8,
  101. looping_count:4;
  102. };
  103. typedef struct hal_mon_desc *hal_mon_desc_t;
  104. /**
  105. * struct hal_mon_buf_addr_status () - HAL buffer address tlv get status
  106. *
  107. * @buf_addr_31_0: Lower 32 bits of virtual address of status buffer
  108. * @buf_addr_63_32: Upper 32 bits of virtual address of status buffer
  109. * @dma_length: DMA length
  110. * @msdu_continuation: is msdu size more than fragment size
  111. * @truncated: is msdu got truncated
  112. * @tlv_padding: tlv paddding
  113. */
  114. struct hal_mon_buf_addr_status {
  115. uint32_t buffer_virt_addr_31_0;
  116. uint32_t buffer_virt_addr_63_32;
  117. uint32_t dma_length:12,
  118. reserved_2a:4,
  119. msdu_continuation:1,
  120. truncated:1,
  121. reserved_2b:14;
  122. uint32_t tlv64_padding;
  123. };
  124. /**
  125. * hal_be_get_mon_dest_status() - Get monitor descriptor
  126. * @hal_soc_hdl: HAL Soc handle
  127. * @desc: HAL monitor descriptor
  128. *
  129. * Return: none
  130. */
  131. static inline void
  132. hal_be_get_mon_dest_status(hal_soc_handle_t hal_soc,
  133. void *hw_desc,
  134. struct hal_mon_desc *status)
  135. {
  136. struct mon_destination_ring *desc = hw_desc;
  137. status->buf_addr = HAL_RX_GET(desc, MON_DESTINATION_RING_STAT,
  138. BUF_VIRT_ADDR_31_0) |
  139. (((uint64_t)HAL_RX_GET(desc,
  140. MON_DESTINATION_RING_STAT,
  141. BUF_VIRT_ADDR_63_32)) << 32);
  142. status->ppdu_id = desc->ppdu_id;
  143. status->end_offset = desc->end_offset;
  144. status->end_reason = desc->end_reason;
  145. status->initiator = desc->initiator;
  146. status->empty_descriptor = desc->empty_descriptor;
  147. status->looping_count = desc->looping_count;
  148. }
  149. /**
  150. * hal_mon_buff_addr_info_set() - set desc address in cookie
  151. * @hal_soc_hdl: HAL Soc handle
  152. * @mon_entry: monitor srng
  153. * @desc: HAL monitor descriptor
  154. *
  155. * Return: none
  156. */
  157. static inline
  158. void hal_mon_buff_addr_info_set(hal_soc_handle_t hal_soc_hdl,
  159. void *mon_entry,
  160. void *mon_desc_addr,
  161. qdf_dma_addr_t phy_addr)
  162. {
  163. uint32_t paddr_lo = ((uintptr_t)phy_addr & 0x00000000ffffffff);
  164. uint32_t paddr_hi = ((uintptr_t)phy_addr & 0xffffffff00000000) >> 32;
  165. uint32_t vaddr_lo = ((uintptr_t)mon_desc_addr & 0x00000000ffffffff);
  166. uint32_t vaddr_hi = ((uintptr_t)mon_desc_addr & 0xffffffff00000000) >> 32;
  167. HAL_MON_PADDR_LO_SET(mon_entry, paddr_lo);
  168. HAL_MON_PADDR_HI_SET(mon_entry, paddr_hi);
  169. HAL_MON_VADDR_LO_SET(mon_entry, vaddr_lo);
  170. HAL_MON_VADDR_HI_SET(mon_entry, vaddr_hi);
  171. }
  172. /* TX monitor */
  173. #define TX_MON_STATUS_BUF_SIZE 2048
  174. #define HAL_INVALID_PPDU_ID 0xFFFFFFFF
  175. enum hal_tx_tlv_status {
  176. HAL_MON_TX_FES_SETUP,
  177. HAL_MON_TX_FES_STATUS_END,
  178. HAL_MON_RX_RESPONSE_REQUIRED_INFO,
  179. HAL_MON_RESPONSE_END_STATUS_INFO,
  180. HAL_MON_TX_PCU_PPDU_SETUP_INIT,
  181. HAL_MON_TX_MPDU_START,
  182. HAL_MON_TX_MSDU_START,
  183. HAL_MON_TX_BUFFER_ADDR,
  184. HAL_MON_TX_DATA,
  185. HAL_MON_TX_FES_STATUS_START,
  186. HAL_MON_TX_FES_STATUS_PROT,
  187. HAL_MON_TX_FES_STATUS_START_PROT,
  188. HAL_MON_TX_FES_STATUS_START_PPDU,
  189. HAL_MON_TX_FES_STATUS_USER_PPDU,
  190. HAL_MON_RX_FRAME_BITMAP_ACK,
  191. HAL_MON_RX_FRAME_BITMAP_BLOCK_ACK_256,
  192. HAL_MON_RX_FRAME_BITMAP_BLOCK_ACK_1K,
  193. HAL_MON_COEX_TX_STATUS,
  194. HAL_MON_MACTX_HE_SIG_A_SU,
  195. HAL_MON_MACTX_HE_SIG_A_MU_DL,
  196. HAL_MON_MACTX_HE_SIG_B1_MU,
  197. HAL_MON_MACTX_HE_SIG_B2_MU,
  198. HAL_MON_MACTX_HE_SIG_B2_OFDMA,
  199. HAL_MON_MACTX_L_SIG_A,
  200. HAL_MON_MACTX_L_SIG_B,
  201. HAL_MON_MACTX_HT_SIG,
  202. HAL_MON_MACTX_VHT_SIG_A,
  203. HAL_MON_MACTX_USER_DESC_PER_USER,
  204. HAL_MON_MACTX_USER_DESC_COMMON,
  205. HAL_MON_MACTX_PHY_DESC,
  206. HAL_MON_TX_STATUS_PPDU_NOT_DONE,
  207. };
  208. enum txmon_transmission_type {
  209. TXMON_SU_TRANSMISSION = 0,
  210. TXMON_MU_TRANSMISSION,
  211. TXMON_MU_SU_TRANSMISSION,
  212. TXMON_MU_MIMO_TRANSMISSION = 1,
  213. TXMON_MU_OFDMA_TRANMISSION
  214. };
  215. #define TXMON_HAL(hal_tx_ppdu_info, field) \
  216. hal_tx_ppdu_info->field
  217. #define TXMON_HAL_STATUS(hal_tx_ppdu_info, field) \
  218. hal_tx_ppdu_info->rx_status.field
  219. #define TXMON_HAL_USER(hal_tx_ppdu_info, user_id, field) \
  220. hal_tx_ppdu_info->rx_user_status[user_id].field
  221. #define TXMON_STATUS_INFO(hal_tx_status_info, field) \
  222. hal_tx_status_info->field
  223. struct hal_tx_status_info {
  224. uint8_t reception_type;
  225. uint8_t transmission_type;
  226. uint8_t medium_prot_type;
  227. void *buffer;
  228. uint32_t offset;
  229. uint32_t len_bytes;
  230. };
  231. struct hal_tx_ppdu_info {
  232. uint32_t ppdu_id;
  233. uint32_t num_users :8,
  234. is_used :1,
  235. is_data :1,
  236. reserved :23;
  237. uint32_t prot_tlv_status;
  238. struct mon_rx_status rx_status;
  239. struct mon_rx_user_status rx_user_status[];
  240. };
  241. /**
  242. * hal_tx_status_get_next_tlv() - get next tx status TLV
  243. * @tx_tlv: pointer to TLV header
  244. *
  245. * Return: pointer to next tlv info
  246. */
  247. static inline uint8_t*
  248. hal_tx_status_get_next_tlv(uint8_t *tx_tlv) {
  249. uint32_t tlv_len, tlv_tag;
  250. tlv_len = HAL_RX_GET_USER_TLV32_LEN(tx_tlv);
  251. tlv_tag = HAL_RX_GET_USER_TLV32_TYPE(tx_tlv);
  252. return (uint8_t *)(((unsigned long)(tx_tlv + tlv_len +
  253. HAL_RX_TLV32_HDR_SIZE + 3)) & (~3));
  254. }
  255. /**
  256. * hal_txmon_status_parse_tlv() - process transmit info TLV
  257. * @hal_soc: HAL soc handle
  258. * @data_ppdu_info: pointer to hal data ppdu info
  259. * @prot_ppdu_info: pointer to hal prot ppdu info
  260. * @data_status_info: pointer to data status info
  261. * @prot_status_info: pointer to prot status info
  262. * @tx_tlv_hdr: pointer to TLV header
  263. * @status_frag: pointer to status frag
  264. *
  265. * Return: HAL_TLV_STATUS_PPDU_NOT_DONE
  266. */
  267. static inline uint32_t
  268. hal_txmon_status_parse_tlv(hal_soc_handle_t hal_soc_hdl,
  269. void *data_ppdu_info,
  270. void *prot_ppdu_info,
  271. void *data_status_info,
  272. void *prot_status_info,
  273. void *tx_tlv_hdr,
  274. qdf_frag_t status_frag)
  275. {
  276. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  277. return hal_soc->ops->hal_txmon_status_parse_tlv(data_ppdu_info,
  278. prot_ppdu_info,
  279. data_status_info,
  280. prot_status_info,
  281. tx_tlv_hdr,
  282. status_frag);
  283. }
  284. /**
  285. * hal_txmon_status_get_num_users() - api to get num users from start of fes
  286. * window
  287. * @hal_soc: HAL soc handle
  288. * @tx_tlv_hdr: pointer to TLV header
  289. * @num_users: reference to number of user
  290. *
  291. * Return: status
  292. */
  293. static inline uint32_t
  294. hal_txmon_status_get_num_users(hal_soc_handle_t hal_soc_hdl,
  295. void *tx_tlv_hdr, uint8_t *num_users)
  296. {
  297. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  298. return hal_soc->ops->hal_txmon_status_get_num_users(tx_tlv_hdr,
  299. num_users);
  300. }
  301. /**
  302. * hal_txmon_status_free_buffer() - api to free status buffer
  303. * @hal_soc: HAL soc handle
  304. * @status_frag: qdf_frag_t buffer
  305. *
  306. * Return void
  307. */
  308. static inline void
  309. hal_txmon_status_free_buffer(hal_soc_handle_t hal_soc_hdl,
  310. qdf_frag_t status_frag)
  311. {
  312. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  313. if (hal_soc->ops->hal_txmon_status_free_buffer)
  314. hal_soc->ops->hal_txmon_status_free_buffer(status_frag);
  315. }
  316. /**
  317. * hal_tx_status_get_tlv_tag() - api to get tlv tag
  318. * @tx_tlv_hdr: pointer to TLV header
  319. *
  320. * Return tlv_tag
  321. */
  322. static inline uint32_t
  323. hal_tx_status_get_tlv_tag(void *tx_tlv_hdr)
  324. {
  325. uint32_t tlv_tag = 0;
  326. tlv_tag = HAL_RX_GET_USER_TLV32_TYPE(tx_tlv_hdr);
  327. return tlv_tag;
  328. }
  329. #endif /* QCA_MONITOR_2_0_SUPPORT */
  330. #endif /* _HAL_BE_API_MON_H_ */