hal_li_tx.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. /*
  2. * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  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. #ifndef _HAL_LI_TX_H_
  20. #define _HAL_LI_TX_H_
  21. enum hal_li_tx_ret_buf_manager {
  22. HAL_LI_WBM_SW0_BM_ID = 3,
  23. HAL_LI_WBM_SW1_BM_ID = 4,
  24. HAL_LI_WBM_SW2_BM_ID = 5,
  25. HAL_LI_WBM_SW3_BM_ID = 6,
  26. HAL_LI_WBM_SW4_BM_ID = 7,
  27. };
  28. /*---------------------------------------------------------------------------
  29. * Function declarations and documentation
  30. * ---------------------------------------------------------------------------
  31. */
  32. /*---------------------------------------------------------------------------
  33. * TCL Descriptor accessor APIs
  34. * ---------------------------------------------------------------------------
  35. */
  36. /**
  37. * hal_tx_desc_set_buf_addr() - Fill Buffer Address information in Tx
  38. * Descriptor
  39. * @hal_soc_hdl: hal_soc handle
  40. * @desc: Handle to Tx Descriptor
  41. * @paddr: Physical Address
  42. * @pool_id: Return Buffer Manager ID
  43. * @desc_id: Descriptor ID
  44. * @type: 0 - Address points to a MSDU buffer
  45. * 1 - Address points to MSDU extension descriptor
  46. *
  47. * Return: void
  48. */
  49. static inline
  50. void hal_tx_desc_set_buf_addr(hal_soc_handle_t hal_soc_hdl, void *desc,
  51. dma_addr_t paddr,
  52. uint8_t pool_id, uint32_t desc_id,
  53. uint8_t type)
  54. {
  55. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  56. hal_soc->ops->hal_tx_desc_set_buf_addr(desc, paddr, pool_id,
  57. desc_id, type);
  58. }
  59. /**
  60. * hal_tx_desc_set_lmac_id_li() - Set the lmac_id value
  61. * @hal_soc_hdl: hal_soc handle
  62. * @desc: Handle to Tx Descriptor
  63. * @lmac_id: mac Id to ast matching
  64. * b00 – mac 0
  65. * b01 – mac 1
  66. * b10 – mac 2
  67. * b11 – all macs (legacy HK way)
  68. *
  69. * Return: void
  70. */
  71. static inline void hal_tx_desc_set_lmac_id_li(hal_soc_handle_t hal_soc_hdl,
  72. void *desc, uint8_t lmac_id)
  73. {
  74. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  75. hal_soc->ops->hal_tx_desc_set_lmac_id(desc, lmac_id);
  76. }
  77. /**
  78. * hal_tx_desc_set_search_type_li() - Set the search type value
  79. * @hal_soc_hdl: hal_soc handle
  80. * @desc: Handle to Tx Descriptor
  81. * @search_type: search type
  82. * 0 – Normal search
  83. * 1 – Index based address search
  84. * 2 – Index based flow search
  85. *
  86. * Return: void
  87. */
  88. static inline void hal_tx_desc_set_search_type_li(hal_soc_handle_t hal_soc_hdl,
  89. void *desc,
  90. uint8_t search_type)
  91. {
  92. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  93. hal_soc->ops->hal_tx_desc_set_search_type(desc, search_type);
  94. }
  95. /**
  96. * hal_tx_desc_set_search_index_li() - Set the search index value
  97. * @hal_soc_hdl: hal_soc handle
  98. * @desc: Handle to Tx Descriptor
  99. * @search_index: The index that will be used for index based address or
  100. * flow search. The field is valid when 'search_type' is
  101. * 1 0r 2
  102. *
  103. * Return: void
  104. */
  105. static inline void hal_tx_desc_set_search_index_li(hal_soc_handle_t hal_soc_hdl,
  106. void *desc,
  107. uint32_t search_index)
  108. {
  109. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  110. hal_soc->ops->hal_tx_desc_set_search_index(desc, search_index);
  111. }
  112. /**
  113. * hal_tx_desc_set_cache_set_num() - Set the cache-set-num value
  114. * @hal_soc_hdl: hal_soc handle
  115. * @desc: Handle to Tx Descriptor
  116. * @cache_num: Cache set number that should be used to cache the index
  117. * based search results, for address and flow search.
  118. * This value should be equal to LSB four bits of the hash value
  119. * of match data, in case of search index points to an entry
  120. * which may be used in content based search also. The value can
  121. * be anything when the entry pointed by search index will not be
  122. * used for content based search.
  123. *
  124. * Return: void
  125. */
  126. static inline void hal_tx_desc_set_cache_set_num(hal_soc_handle_t hal_soc_hdl,
  127. void *desc,
  128. uint8_t cache_num)
  129. {
  130. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  131. hal_soc->ops->hal_tx_desc_set_cache_set_num(desc, cache_num);
  132. }
  133. /**
  134. * hal_tx_desc_set_buf_length - Set Data length in bytes in Tx Descriptor
  135. * @desc: Handle to Tx Descriptor
  136. * @data_length: MSDU length in case of direct descriptor.
  137. * Length of link extension descriptor in case of Link extension
  138. * descriptor.Includes the length of Metadata
  139. * Return: None
  140. */
  141. static inline void hal_tx_desc_set_buf_length(void *desc,
  142. uint16_t data_length)
  143. {
  144. HAL_SET_FLD(desc, TCL_DATA_CMD_3, DATA_LENGTH) |=
  145. HAL_TX_SM(TCL_DATA_CMD_3, DATA_LENGTH, data_length);
  146. }
  147. /**
  148. * hal_tx_desc_set_buf_offset - Sets Packet Offset field in Tx descriptor
  149. * @desc: Handle to Tx Descriptor
  150. * @offset: Packet offset from Metadata in case of direct buffer descriptor.
  151. *
  152. * Return: void
  153. */
  154. static inline void hal_tx_desc_set_buf_offset(void *desc,
  155. uint8_t offset)
  156. {
  157. HAL_SET_FLD(desc, TCL_DATA_CMD_3, PACKET_OFFSET) |=
  158. HAL_TX_SM(TCL_DATA_CMD_3, PACKET_OFFSET, offset);
  159. }
  160. /**
  161. * hal_tx_desc_set_encap_type - Set encapsulation type in Tx Descriptor
  162. * @desc: Handle to Tx Descriptor
  163. * @encap_type: Encapsulation that HW will perform
  164. *
  165. * Return: void
  166. *
  167. */
  168. static inline void hal_tx_desc_set_encap_type(void *desc,
  169. enum hal_tx_encap_type encap_type)
  170. {
  171. HAL_SET_FLD(desc, TCL_DATA_CMD_2, ENCAP_TYPE) |=
  172. HAL_TX_SM(TCL_DATA_CMD_2, ENCAP_TYPE, encap_type);
  173. }
  174. /**
  175. * hal_tx_desc_set_encrypt_type - Sets the Encrypt Type in Tx Descriptor
  176. * @desc: Handle to Tx Descriptor
  177. * @type: Encrypt Type
  178. *
  179. * Return: void
  180. */
  181. static inline void hal_tx_desc_set_encrypt_type(void *desc,
  182. enum hal_tx_encrypt_type type)
  183. {
  184. HAL_SET_FLD(desc, TCL_DATA_CMD_2, ENCRYPT_TYPE) |=
  185. HAL_TX_SM(TCL_DATA_CMD_2, ENCRYPT_TYPE, type);
  186. }
  187. /**
  188. * hal_tx_desc_set_addr_search_flags - Enable AddrX and AddrY search flags
  189. * @desc: Handle to Tx Descriptor
  190. * @flags: Bit 0 - AddrY search enable, Bit 1 - AddrX search enable
  191. *
  192. * Return: void
  193. */
  194. static inline void hal_tx_desc_set_addr_search_flags(void *desc,
  195. uint8_t flags)
  196. {
  197. HAL_SET_FLD(desc, TCL_DATA_CMD_2, ADDRX_EN) |=
  198. HAL_TX_SM(TCL_DATA_CMD_2, ADDRX_EN, (flags & 0x1));
  199. HAL_SET_FLD(desc, TCL_DATA_CMD_2, ADDRY_EN) |=
  200. HAL_TX_SM(TCL_DATA_CMD_2, ADDRY_EN, (flags >> 1));
  201. }
  202. /**
  203. * hal_tx_desc_set_l4_checksum_en - Set TCP/IP checksum enable flags
  204. * Tx Descriptor for MSDU_buffer type
  205. * @desc: Handle to Tx Descriptor
  206. * @en: UDP/TCP over ipv4/ipv6 checksum enable flags (5 bits)
  207. *
  208. * Return: void
  209. */
  210. static inline void hal_tx_desc_set_l4_checksum_en(void *desc,
  211. uint8_t en)
  212. {
  213. HAL_SET_FLD(desc, TCL_DATA_CMD_3, IPV4_CHECKSUM_EN) |=
  214. (HAL_TX_SM(TCL_DATA_CMD_3, UDP_OVER_IPV4_CHECKSUM_EN, en) |
  215. HAL_TX_SM(TCL_DATA_CMD_3, UDP_OVER_IPV6_CHECKSUM_EN, en) |
  216. HAL_TX_SM(TCL_DATA_CMD_3, TCP_OVER_IPV4_CHECKSUM_EN, en) |
  217. HAL_TX_SM(TCL_DATA_CMD_3, TCP_OVER_IPV6_CHECKSUM_EN, en));
  218. }
  219. /**
  220. * hal_tx_desc_set_l3_checksum_en() - Set IPv4 checksum enable flag in
  221. * Tx Descriptor for MSDU_buffer type
  222. * @desc: Handle to Tx Descriptor
  223. * @en: ipv4 checksum enable flags
  224. *
  225. * Return: void
  226. */
  227. static inline void hal_tx_desc_set_l3_checksum_en(void *desc,
  228. uint8_t en)
  229. {
  230. HAL_SET_FLD(desc, TCL_DATA_CMD_3, IPV4_CHECKSUM_EN) |=
  231. HAL_TX_SM(TCL_DATA_CMD_3, IPV4_CHECKSUM_EN, en);
  232. }
  233. /**
  234. * hal_tx_desc_set_fw_metadata() - Sets the metadata that is part of
  235. * TCL descriptor
  236. * @desc:Handle to Tx Descriptor
  237. * @metadata: Metadata to be sent to Firmware
  238. *
  239. * Return: void
  240. */
  241. static inline void hal_tx_desc_set_fw_metadata(void *desc,
  242. uint16_t metadata)
  243. {
  244. HAL_SET_FLD(desc, TCL_DATA_CMD_2, TCL_CMD_NUMBER) |=
  245. HAL_TX_SM(TCL_DATA_CMD_2, TCL_CMD_NUMBER, metadata);
  246. }
  247. /**
  248. * hal_tx_desc_set_to_fw() - Set To_FW bit in Tx Descriptor.
  249. * @desc:Handle to Tx Descriptor
  250. * @to_fw: if set, Forward packet to FW along with classification result
  251. *
  252. * Return: void
  253. */
  254. static inline void hal_tx_desc_set_to_fw(void *desc, uint8_t to_fw)
  255. {
  256. HAL_SET_FLD(desc, TCL_DATA_CMD_3, TO_FW) |=
  257. HAL_TX_SM(TCL_DATA_CMD_3, TO_FW, to_fw);
  258. }
  259. /**
  260. * hal_tx_desc_set_mesh_en() - Set mesh_enable flag in Tx descriptor
  261. * @hal_soc_hdl: hal soc handle
  262. * @desc: Handle to Tx Descriptor
  263. * @en: For raw WiFi frames, this indicates transmission to a mesh STA,
  264. * enabling the interpretation of the 'Mesh Control Present' bit
  265. * (bit 8) of QoS Control (otherwise this bit is ignored),
  266. * For native WiFi frames, this indicates that a 'Mesh Control' field
  267. * is present between the header and the LLC.
  268. *
  269. * Return: void
  270. */
  271. static inline void hal_tx_desc_set_mesh_en(hal_soc_handle_t hal_soc_hdl,
  272. void *desc, uint8_t en)
  273. {
  274. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  275. hal_soc->ops->hal_tx_desc_set_mesh_en(desc, en);
  276. }
  277. /**
  278. * hal_tx_desc_set_hlos_tid() - Set the TID value (override DSCP/PCP fields in
  279. * frame) to be used for Tx Frame
  280. * @desc: Handle to Tx Descriptor
  281. * @hlos_tid: HLOS TID
  282. *
  283. * Return: void
  284. */
  285. static inline void hal_tx_desc_set_hlos_tid(void *desc,
  286. uint8_t hlos_tid)
  287. {
  288. HAL_SET_FLD(desc, TCL_DATA_CMD_4, HLOS_TID) |=
  289. HAL_TX_SM(TCL_DATA_CMD_4, HLOS_TID, hlos_tid);
  290. HAL_SET_FLD(desc, TCL_DATA_CMD_4, HLOS_TID_OVERWRITE) |=
  291. HAL_TX_SM(TCL_DATA_CMD_4, HLOS_TID_OVERWRITE, 1);
  292. }
  293. /**
  294. * hal_tx_desc_set_dscp_tid_table_id() - Sets DSCP to TID conversion table ID
  295. * @hal_soc_hdl: Handle to HAL SoC structure
  296. * @desc: Handle to Tx Descriptor
  297. * @id: DSCP to tid conversion table to be used for this frame
  298. *
  299. * Return: void
  300. */
  301. static inline
  302. void hal_tx_desc_set_dscp_tid_table_id(hal_soc_handle_t hal_soc_hdl,
  303. void *desc, uint8_t id)
  304. {
  305. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  306. hal_soc->ops->hal_tx_desc_set_dscp_tid_table_id(desc, id);
  307. }
  308. /**
  309. * hal_tx_desc_clear() - Clear the HW descriptor entry
  310. * @hw_desc: Hardware descriptor to be cleared
  311. *
  312. * Return: void
  313. */
  314. static inline void hal_tx_desc_clear(void *hw_desc)
  315. {
  316. qdf_mem_set(hw_desc + sizeof(struct tlv_32_hdr),
  317. HAL_TX_DESC_LEN_BYTES, 0);
  318. }
  319. /**
  320. * hal_tx_desc_sync() - Commit the descriptor to Hardware
  321. * @hal_tx_desc_cached: Cached descriptor that software maintains
  322. * @hw_desc: Hardware descriptor to be updated
  323. */
  324. static inline void hal_tx_desc_sync(void *hal_tx_desc_cached,
  325. void *hw_desc)
  326. {
  327. qdf_mem_copy((hw_desc + sizeof(struct tlv_32_hdr)),
  328. hal_tx_desc_cached, HAL_TX_DESC_LEN_BYTES);
  329. }
  330. /*---------------------------------------------------------------------------
  331. * WBM Descriptor accessor APIs for Tx completions
  332. *---------------------------------------------------------------------------
  333. */
  334. /**
  335. * hal_tx_get_wbm_sw0_bm_id() - Get the BM ID for first tx completion ring
  336. *
  337. * Return: BM ID for first tx completion ring
  338. */
  339. static inline uint32_t hal_tx_get_wbm_sw0_bm_id(void)
  340. {
  341. return HAL_LI_WBM_SW0_BM_ID;
  342. }
  343. /**
  344. * hal_tx_comp_get_desc_id() - Get TX descriptor id within comp descriptor
  345. * @hal_desc: completion ring descriptor pointer
  346. *
  347. * This function will tx descriptor id, cookie, within hardware completion
  348. * descriptor
  349. *
  350. * Return: cookie
  351. */
  352. static inline uint32_t hal_tx_comp_get_desc_id(void *hal_desc)
  353. {
  354. uint32_t comp_desc =
  355. *(uint32_t *)(((uint8_t *)hal_desc) +
  356. BUFFER_ADDR_INFO_1_SW_BUFFER_COOKIE_OFFSET);
  357. /* Cookie is placed on 2nd word */
  358. return (comp_desc & BUFFER_ADDR_INFO_1_SW_BUFFER_COOKIE_MASK) >>
  359. BUFFER_ADDR_INFO_1_SW_BUFFER_COOKIE_LSB;
  360. }
  361. /**
  362. * hal_tx_comp_get_paddr() - Get paddr within comp descriptor
  363. * @hal_desc: completion ring descriptor pointer
  364. *
  365. * This function will get buffer physical address within hardware completion
  366. * descriptor
  367. *
  368. * Return: Buffer physical address
  369. */
  370. static inline qdf_dma_addr_t hal_tx_comp_get_paddr(void *hal_desc)
  371. {
  372. uint32_t paddr_lo;
  373. uint32_t paddr_hi;
  374. paddr_lo = *(uint32_t *)(((uint8_t *)hal_desc) +
  375. BUFFER_ADDR_INFO_0_BUFFER_ADDR_31_0_OFFSET);
  376. paddr_hi = *(uint32_t *)(((uint8_t *)hal_desc) +
  377. BUFFER_ADDR_INFO_1_BUFFER_ADDR_39_32_OFFSET);
  378. paddr_hi = (paddr_hi & BUFFER_ADDR_INFO_1_BUFFER_ADDR_39_32_MASK) >>
  379. BUFFER_ADDR_INFO_1_BUFFER_ADDR_39_32_LSB;
  380. return (qdf_dma_addr_t)(paddr_lo | (((uint64_t)paddr_hi) << 32));
  381. }
  382. #endif /* _HAL_LI_TX_H_ */