hal_li_tx.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*
  2. * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef _HAL_LI_TX_H_
  19. #define _HAL_LI_TX_H_
  20. enum hal_li_tx_ret_buf_manager {
  21. HAL_LI_WBM_SW0_BM_ID = 3,
  22. HAL_LI_WBM_SW1_BM_ID = 4,
  23. HAL_LI_WBM_SW2_BM_ID = 5,
  24. HAL_LI_WBM_SW3_BM_ID = 6,
  25. #ifdef IPA_WDI3_TX_TWO_PIPES
  26. HAL_LI_WBM_SW4_BM_ID = 7,
  27. #endif
  28. };
  29. /*---------------------------------------------------------------------------
  30. * Function declarations and documentation
  31. * ---------------------------------------------------------------------------
  32. */
  33. /*---------------------------------------------------------------------------
  34. * TCL Descriptor accessor APIs
  35. * ---------------------------------------------------------------------------
  36. */
  37. /**
  38. * hal_tx_desc_set_buf_length - Set Data length in bytes in Tx Descriptor
  39. * @desc: Handle to Tx Descriptor
  40. * @data_length: MSDU length in case of direct descriptor.
  41. * Length of link extension descriptor in case of Link extension
  42. * descriptor.Includes the length of Metadata
  43. * Return: None
  44. */
  45. static inline void hal_tx_desc_set_buf_length(void *desc,
  46. uint16_t data_length)
  47. {
  48. HAL_SET_FLD(desc, TCL_DATA_CMD_3, DATA_LENGTH) |=
  49. HAL_TX_SM(TCL_DATA_CMD_3, DATA_LENGTH, data_length);
  50. }
  51. /**
  52. * hal_tx_desc_set_buf_offset - Sets Packet Offset field in Tx descriptor
  53. * @desc: Handle to Tx Descriptor
  54. * @offset: Packet offset from Metadata in case of direct buffer descriptor.
  55. *
  56. * Return: void
  57. */
  58. static inline void hal_tx_desc_set_buf_offset(void *desc,
  59. uint8_t offset)
  60. {
  61. HAL_SET_FLD(desc, TCL_DATA_CMD_3, PACKET_OFFSET) |=
  62. HAL_TX_SM(TCL_DATA_CMD_3, PACKET_OFFSET, offset);
  63. }
  64. /**
  65. * hal_tx_desc_set_encap_type - Set encapsulation type in Tx Descriptor
  66. * @desc: Handle to Tx Descriptor
  67. * @encap_type: Encapsulation that HW will perform
  68. *
  69. * Return: void
  70. *
  71. */
  72. static inline void hal_tx_desc_set_encap_type(void *desc,
  73. enum hal_tx_encap_type encap_type)
  74. {
  75. HAL_SET_FLD(desc, TCL_DATA_CMD_2, ENCAP_TYPE) |=
  76. HAL_TX_SM(TCL_DATA_CMD_2, ENCAP_TYPE, encap_type);
  77. }
  78. /**
  79. * hal_tx_desc_set_encrypt_type - Sets the Encrypt Type in Tx Descriptor
  80. * @desc: Handle to Tx Descriptor
  81. * @type: Encrypt Type
  82. *
  83. * Return: void
  84. */
  85. static inline void hal_tx_desc_set_encrypt_type(void *desc,
  86. enum hal_tx_encrypt_type type)
  87. {
  88. HAL_SET_FLD(desc, TCL_DATA_CMD_2, ENCRYPT_TYPE) |=
  89. HAL_TX_SM(TCL_DATA_CMD_2, ENCRYPT_TYPE, type);
  90. }
  91. /**
  92. * hal_tx_desc_set_addr_search_flags - Enable AddrX and AddrY search flags
  93. * @desc: Handle to Tx Descriptor
  94. * @flags: Bit 0 - AddrY search enable, Bit 1 - AddrX search enable
  95. *
  96. * Return: void
  97. */
  98. static inline void hal_tx_desc_set_addr_search_flags(void *desc,
  99. uint8_t flags)
  100. {
  101. HAL_SET_FLD(desc, TCL_DATA_CMD_2, ADDRX_EN) |=
  102. HAL_TX_SM(TCL_DATA_CMD_2, ADDRX_EN, (flags & 0x1));
  103. HAL_SET_FLD(desc, TCL_DATA_CMD_2, ADDRY_EN) |=
  104. HAL_TX_SM(TCL_DATA_CMD_2, ADDRY_EN, (flags >> 1));
  105. }
  106. /**
  107. * hal_tx_desc_set_l4_checksum_en - Set TCP/IP checksum enable flags
  108. * Tx Descriptor for MSDU_buffer type
  109. * @desc: Handle to Tx Descriptor
  110. * @en: UDP/TCP over ipv4/ipv6 checksum enable flags (5 bits)
  111. *
  112. * Return: void
  113. */
  114. static inline void hal_tx_desc_set_l4_checksum_en(void *desc,
  115. uint8_t en)
  116. {
  117. HAL_SET_FLD(desc, TCL_DATA_CMD_3, IPV4_CHECKSUM_EN) |=
  118. (HAL_TX_SM(TCL_DATA_CMD_3, UDP_OVER_IPV4_CHECKSUM_EN, en) |
  119. HAL_TX_SM(TCL_DATA_CMD_3, UDP_OVER_IPV6_CHECKSUM_EN, en) |
  120. HAL_TX_SM(TCL_DATA_CMD_3, TCP_OVER_IPV4_CHECKSUM_EN, en) |
  121. HAL_TX_SM(TCL_DATA_CMD_3, TCP_OVER_IPV6_CHECKSUM_EN, en));
  122. }
  123. /**
  124. * hal_tx_desc_set_l3_checksum_en - Set IPv4 checksum enable flag in
  125. * Tx Descriptor for MSDU_buffer type
  126. * @desc: Handle to Tx Descriptor
  127. * @checksum_en_flags: ipv4 checksum enable flags
  128. *
  129. * Return: void
  130. */
  131. static inline void hal_tx_desc_set_l3_checksum_en(void *desc,
  132. uint8_t en)
  133. {
  134. HAL_SET_FLD(desc, TCL_DATA_CMD_3, IPV4_CHECKSUM_EN) |=
  135. HAL_TX_SM(TCL_DATA_CMD_3, IPV4_CHECKSUM_EN, en);
  136. }
  137. /**
  138. * hal_tx_desc_set_fw_metadata- Sets the metadata that is part of TCL descriptor
  139. * @desc:Handle to Tx Descriptor
  140. * @metadata: Metadata to be sent to Firmware
  141. *
  142. * Return: void
  143. */
  144. static inline void hal_tx_desc_set_fw_metadata(void *desc,
  145. uint16_t metadata)
  146. {
  147. HAL_SET_FLD(desc, TCL_DATA_CMD_2, TCL_CMD_NUMBER) |=
  148. HAL_TX_SM(TCL_DATA_CMD_2, TCL_CMD_NUMBER, metadata);
  149. }
  150. /**
  151. * hal_tx_desc_set_to_fw - Set To_FW bit in Tx Descriptor.
  152. * @desc:Handle to Tx Descriptor
  153. * @to_fw: if set, Forward packet to FW along with classification result
  154. *
  155. * Return: void
  156. */
  157. static inline void hal_tx_desc_set_to_fw(void *desc, uint8_t to_fw)
  158. {
  159. HAL_SET_FLD(desc, TCL_DATA_CMD_3, TO_FW) |=
  160. HAL_TX_SM(TCL_DATA_CMD_3, TO_FW, to_fw);
  161. }
  162. /**
  163. * hal_tx_desc_set_mesh_en - Set mesh_enable flag in Tx descriptor
  164. * @hal_soc_hdl: hal soc handle
  165. * @desc: Handle to Tx Descriptor
  166. * @en: For raw WiFi frames, this indicates transmission to a mesh STA,
  167. * enabling the interpretation of the 'Mesh Control Present' bit
  168. * (bit 8) of QoS Control (otherwise this bit is ignored),
  169. * For native WiFi frames, this indicates that a 'Mesh Control' field
  170. * is present between the header and the LLC.
  171. *
  172. * Return: void
  173. */
  174. static inline void hal_tx_desc_set_mesh_en(hal_soc_handle_t hal_soc_hdl,
  175. void *desc, uint8_t en)
  176. {
  177. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  178. hal_soc->ops->hal_tx_desc_set_mesh_en(desc, en);
  179. }
  180. /**
  181. * hal_tx_desc_set_hlos_tid - Set the TID value (override DSCP/PCP fields in
  182. * frame) to be used for Tx Frame
  183. * @desc: Handle to Tx Descriptor
  184. * @hlos_tid: HLOS TID
  185. *
  186. * Return: void
  187. */
  188. static inline void hal_tx_desc_set_hlos_tid(void *desc,
  189. uint8_t hlos_tid)
  190. {
  191. HAL_SET_FLD(desc, TCL_DATA_CMD_4, HLOS_TID) |=
  192. HAL_TX_SM(TCL_DATA_CMD_4, HLOS_TID, hlos_tid);
  193. HAL_SET_FLD(desc, TCL_DATA_CMD_4, HLOS_TID_OVERWRITE) |=
  194. HAL_TX_SM(TCL_DATA_CMD_4, HLOS_TID_OVERWRITE, 1);
  195. }
  196. /**
  197. * hal_tx_desc_set_dscp_tid_table_id() - Sets DSCP to TID conversion table ID
  198. * @hal_soc: Handle to HAL SoC structure
  199. * @desc: Handle to Tx Descriptor
  200. * @id: DSCP to tid conversion table to be used for this frame
  201. *
  202. * Return: void
  203. */
  204. static inline
  205. void hal_tx_desc_set_dscp_tid_table_id(hal_soc_handle_t hal_soc_hdl,
  206. void *desc, uint8_t id)
  207. {
  208. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  209. hal_soc->ops->hal_tx_desc_set_dscp_tid_table_id(desc, id);
  210. }
  211. /**
  212. * hal_tx_desc_sync - Commit the descriptor to Hardware
  213. * @hal_tx_des_cached: Cached descriptor that software maintains
  214. * @hw_desc: Hardware descriptor to be updated
  215. */
  216. static inline void hal_tx_desc_sync(void *hal_tx_desc_cached,
  217. void *hw_desc)
  218. {
  219. qdf_mem_copy((hw_desc + sizeof(struct tlv_32_hdr)),
  220. hal_tx_desc_cached, HAL_TX_DESC_LEN_BYTES);
  221. }
  222. /*---------------------------------------------------------------------------
  223. * WBM Descriptor accessor APIs for Tx completions
  224. *---------------------------------------------------------------------------
  225. */
  226. /**
  227. * hal_tx_get_wbm_sw0_bm_id() - Get the BM ID for first tx completion ring
  228. *
  229. * Return: BM ID for first tx completion ring
  230. */
  231. static inline uint32_t hal_tx_get_wbm_sw0_bm_id(void)
  232. {
  233. return HAL_LI_WBM_SW0_BM_ID;
  234. }
  235. /**
  236. * hal_tx_comp_get_desc_id() - Get TX descriptor id within comp descriptor
  237. * @hal_desc: completion ring descriptor pointer
  238. *
  239. * This function will tx descriptor id, cookie, within hardware completion
  240. * descriptor
  241. *
  242. * Return: cookie
  243. */
  244. static inline uint32_t hal_tx_comp_get_desc_id(void *hal_desc)
  245. {
  246. uint32_t comp_desc =
  247. *(uint32_t *)(((uint8_t *)hal_desc) +
  248. BUFFER_ADDR_INFO_1_SW_BUFFER_COOKIE_OFFSET);
  249. /* Cookie is placed on 2nd word */
  250. return (comp_desc & BUFFER_ADDR_INFO_1_SW_BUFFER_COOKIE_MASK) >>
  251. BUFFER_ADDR_INFO_1_SW_BUFFER_COOKIE_LSB;
  252. }
  253. /**
  254. * hal_tx_comp_get_paddr() - Get paddr within comp descriptor
  255. * @hal_desc: completion ring descriptor pointer
  256. *
  257. * This function will get buffer physical address within hardware completion
  258. * descriptor
  259. *
  260. * Return: Buffer physical address
  261. */
  262. static inline qdf_dma_addr_t hal_tx_comp_get_paddr(void *hal_desc)
  263. {
  264. uint32_t paddr_lo;
  265. uint32_t paddr_hi;
  266. paddr_lo = *(uint32_t *)(((uint8_t *)hal_desc) +
  267. BUFFER_ADDR_INFO_0_BUFFER_ADDR_31_0_OFFSET);
  268. paddr_hi = *(uint32_t *)(((uint8_t *)hal_desc) +
  269. BUFFER_ADDR_INFO_1_BUFFER_ADDR_39_32_OFFSET);
  270. paddr_hi = (paddr_hi & BUFFER_ADDR_INFO_1_BUFFER_ADDR_39_32_MASK) >>
  271. BUFFER_ADDR_INFO_1_BUFFER_ADDR_39_32_LSB;
  272. return (qdf_dma_addr_t)(paddr_lo | (((uint64_t)paddr_hi) << 32));
  273. }
  274. #endif /* _HAL_LI_TX_H_ */