hal_tx.h 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. /*
  2. * Copyright (c) 2016-2018 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. #if !defined(HAL_TX_H)
  19. #define HAL_TX_H
  20. /*---------------------------------------------------------------------------
  21. Include files
  22. ---------------------------------------------------------------------------*/
  23. #include "hal_api.h"
  24. #include "wcss_version.h"
  25. #define WBM_RELEASE_RING_5_TX_RATE_STATS_OFFSET 0x00000014
  26. #define WBM_RELEASE_RING_5_TX_RATE_STATS_LSB 0
  27. #define WBM_RELEASE_RING_5_TX_RATE_STATS_MASK 0xffffffff
  28. /*---------------------------------------------------------------------------
  29. Preprocessor definitions and constants
  30. ---------------------------------------------------------------------------*/
  31. #define HAL_OFFSET(block, field) block ## _ ## field ## _OFFSET
  32. #define HAL_SET_FLD(desc, block , field) \
  33. (*(uint32_t *) ((uint8_t *) desc + HAL_OFFSET(block, field)))
  34. #define HAL_SET_FLD_OFFSET(desc, block , field, offset) \
  35. (*(uint32_t *) ((uint8_t *) desc + HAL_OFFSET(block, field) + (offset)))
  36. #define HAL_TX_DESC_SET_TLV_HDR(desc, tag, len) \
  37. do { \
  38. ((struct tlv_32_hdr *) desc)->tlv_tag = (tag); \
  39. ((struct tlv_32_hdr *) desc)->tlv_len = (len); \
  40. } while (0)
  41. #define HAL_TX_TCL_DATA_TAG WIFITCL_DATA_CMD_E
  42. #define HAL_TX_TCL_CMD_TAG WIFITCL_GSE_CMD_E
  43. #define HAL_TX_SM(block, field, value) \
  44. ((value << (block ## _ ## field ## _LSB)) & \
  45. (block ## _ ## field ## _MASK))
  46. #define HAL_TX_MS(block, field, value) \
  47. (((value) & (block ## _ ## field ## _MASK)) >> \
  48. (block ## _ ## field ## _LSB))
  49. #define HAL_TX_DESC_GET(desc, block, field) \
  50. HAL_TX_MS(block, field, HAL_SET_FLD(desc, block, field))
  51. #define HAL_TX_DESC_SUBBLOCK_GET(desc, block, sub, field) \
  52. HAL_TX_MS(sub, field, HAL_SET_FLD(desc, block, sub))
  53. #define HAL_TX_BUF_TYPE_BUFFER 0
  54. #define HAL_TX_BUF_TYPE_EXT_DESC 1
  55. #define HAL_TX_DESC_LEN_DWORDS (NUM_OF_DWORDS_TCL_DATA_CMD)
  56. #define HAL_TX_DESC_LEN_BYTES (NUM_OF_DWORDS_TCL_DATA_CMD * 4)
  57. #define HAL_TX_EXTENSION_DESC_LEN_DWORDS (NUM_OF_DWORDS_TX_MSDU_EXTENSION)
  58. #define HAL_TX_EXTENSION_DESC_LEN_BYTES (NUM_OF_DWORDS_TX_MSDU_EXTENSION * 4)
  59. #define HAL_TX_COMPLETION_DESC_LEN_DWORDS (NUM_OF_DWORDS_WBM_RELEASE_RING)
  60. #define HAL_TX_COMPLETION_DESC_LEN_BYTES (NUM_OF_DWORDS_WBM_RELEASE_RING*4)
  61. #define HAL_TX_BITS_PER_TID 3
  62. #define HAL_TX_TID_BITS_MASK ((1 << HAL_TX_BITS_PER_TID) - 1)
  63. #define HAL_TX_NUM_DSCP_PER_REGISTER 10
  64. #define HAL_MAX_HW_DSCP_TID_MAPS 2
  65. #define HAL_MAX_HW_DSCP_TID_MAPS_11AX 32
  66. #define HTT_META_HEADER_LEN_BYTES 64
  67. #define HAL_TX_EXT_DESC_WITH_META_DATA \
  68. (HTT_META_HEADER_LEN_BYTES + HAL_TX_EXTENSION_DESC_LEN_BYTES)
  69. /* Length of WBM release ring without the status words */
  70. #define HAL_TX_COMPLETION_DESC_BASE_LEN 12
  71. #define HAL_TX_COMP_RELEASE_SOURCE_TQM 0
  72. #define HAL_TX_COMP_RELEASE_SOURCE_FW 3
  73. /* Define a place-holder release reason for FW */
  74. #define HAL_TX_COMP_RELEASE_REASON_FW 99
  75. /*
  76. * Offset of HTT Tx Descriptor in WBM Completion
  77. * HTT Tx Desc structure is passed from firmware to host overlayed
  78. * on wbm_release_ring DWORDs 2,3 ,4 and 5for software based completions
  79. * (Exception frames and TQM bypass frames)
  80. */
  81. #define HAL_TX_COMP_HTT_STATUS_OFFSET 8
  82. #define HAL_TX_COMP_HTT_STATUS_LEN 16
  83. #define HAL_TX_BUF_TYPE_BUFFER 0
  84. #define HAL_TX_BUF_TYPE_EXT_DESC 1
  85. #define HAL_TX_EXT_DESC_BUF_OFFSET TX_MSDU_EXTENSION_6_BUF0_PTR_31_0_OFFSET
  86. #define HAL_TX_EXT_BUF_LOW_MASK TX_MSDU_EXTENSION_6_BUF0_PTR_31_0_MASK
  87. #define HAL_TX_EXT_BUF_HI_MASK TX_MSDU_EXTENSION_7_BUF0_PTR_39_32_MASK
  88. #define HAL_TX_EXT_BUF_LEN_MASK TX_MSDU_EXTENSION_7_BUF0_LEN_MASK
  89. #define HAL_TX_EXT_BUF_LEN_LSB TX_MSDU_EXTENSION_7_BUF0_LEN_LSB
  90. #define HAL_TX_EXT_BUF_WD_SIZE 2
  91. #define HAL_TX_DESC_ADDRX_EN 0x1
  92. #define HAL_TX_DESC_ADDRY_EN 0x2
  93. #define HAL_TX_DESC_DEFAULT_LMAC_ID 0x3
  94. enum hal_tx_ret_buf_manager {
  95. HAL_WBM_SW0_BM_ID = 3,
  96. HAL_WBM_SW1_BM_ID = 4,
  97. HAL_WBM_SW2_BM_ID = 5,
  98. HAL_WBM_SW3_BM_ID = 6,
  99. };
  100. /*---------------------------------------------------------------------------
  101. Structures
  102. ---------------------------------------------------------------------------*/
  103. /**
  104. * struct hal_tx_completion_status - HAL Tx completion descriptor contents
  105. * @status: frame acked/failed
  106. * @release_src: release source = TQM/FW
  107. * @ack_frame_rssi: RSSI of the received ACK or BA frame
  108. * @first_msdu: Indicates this MSDU is the first MSDU in AMSDU
  109. * @last_msdu: Indicates this MSDU is the last MSDU in AMSDU
  110. * @msdu_part_of_amsdu : Indicates this MSDU was part of an A-MSDU in MPDU
  111. * @bw: Indicates the BW of the upcoming transmission -
  112. * <enum 0 transmit_bw_20_MHz>
  113. * <enum 1 transmit_bw_40_MHz>
  114. * <enum 2 transmit_bw_80_MHz>
  115. * <enum 3 transmit_bw_160_MHz>
  116. * @pkt_type: Transmit Packet Type
  117. * @stbc: When set, STBC transmission rate was used
  118. * @ldpc: When set, use LDPC transmission rates
  119. * @sgi: <enum 0 0_8_us_sgi > Legacy normal GI
  120. * <enum 1 0_4_us_sgi > Legacy short GI
  121. * <enum 2 1_6_us_sgi > HE related GI
  122. * <enum 3 3_2_us_sgi > HE
  123. * @mcs: Transmit MCS Rate
  124. * @ofdma: Set when the transmission was an OFDMA transmission
  125. * @tones_in_ru: The number of tones in the RU used.
  126. * @tsf: Lower 32 bits of the TSF
  127. * @ppdu_id: TSF, snapshot of this value when transmission of the
  128. * PPDU containing the frame finished.
  129. * @transmit_cnt: Number of times this frame has been transmitted
  130. * @tid: TID of the flow or MPDU queue
  131. * @peer_id: Peer ID of the flow or MPDU queue
  132. */
  133. struct hal_tx_completion_status {
  134. uint8_t status;
  135. uint8_t release_src;
  136. uint8_t ack_frame_rssi;
  137. uint8_t first_msdu:1,
  138. last_msdu:1,
  139. msdu_part_of_amsdu:1;
  140. uint32_t bw:2,
  141. pkt_type:4,
  142. stbc:1,
  143. ldpc:1,
  144. sgi:2,
  145. mcs:4,
  146. ofdma:1,
  147. tones_in_ru:12,
  148. valid:1;
  149. uint32_t tsf;
  150. uint32_t ppdu_id;
  151. uint8_t transmit_cnt;
  152. uint8_t tid;
  153. uint16_t peer_id;
  154. };
  155. /**
  156. * struct hal_tx_desc_comp_s - hal tx completion descriptor contents
  157. * @desc: Transmit status information from descriptor
  158. */
  159. struct hal_tx_desc_comp_s {
  160. uint32_t desc[HAL_TX_COMPLETION_DESC_LEN_DWORDS];
  161. };
  162. /*
  163. * enum hal_tx_encrypt_type - Type of decrypt cipher used (valid only for RAW)
  164. * @HAL_TX_ENCRYPT_TYPE_WEP_40: WEP 40-bit
  165. * @HAL_TX_ENCRYPT_TYPE_WEP_10: WEP 10-bit
  166. * @HAL_TX_ENCRYPT_TYPE_TKIP_NO_MIC: TKIP without MIC
  167. * @HAL_TX_ENCRYPT_TYPE_WEP_128: WEP_128
  168. * @HAL_TX_ENCRYPT_TYPE_TKIP_WITH_MIC: TKIP_WITH_MIC
  169. * @HAL_TX_ENCRYPT_TYPE_WAPI: WAPI
  170. * @HAL_TX_ENCRYPT_TYPE_AES_CCMP_128: AES_CCMP_128
  171. * @HAL_TX_ENCRYPT_TYPE_NO_CIPHER: NO CIPHER
  172. * @HAL_TX_ENCRYPT_TYPE_AES_CCMP_256: AES_CCMP_256
  173. * @HAL_TX_ENCRYPT_TYPE_AES_GCMP_128: AES_GCMP_128
  174. * @HAL_TX_ENCRYPT_TYPE_AES_GCMP_256: AES_GCMP_256
  175. * @HAL_TX_ENCRYPT_TYPE_WAPI_GCM_SM4: WAPI GCM SM4
  176. */
  177. enum hal_tx_encrypt_type {
  178. HAL_TX_ENCRYPT_TYPE_WEP_40 = 0,
  179. HAL_TX_ENCRYPT_TYPE_WEP_104 = 1 ,
  180. HAL_TX_ENCRYPT_TYPE_TKIP_NO_MIC = 2,
  181. HAL_TX_ENCRYPT_TYPE_WEP_128 = 3,
  182. HAL_TX_ENCRYPT_TYPE_TKIP_WITH_MIC = 4,
  183. HAL_TX_ENCRYPT_TYPE_WAPI = 5,
  184. HAL_TX_ENCRYPT_TYPE_AES_CCMP_128 = 6,
  185. HAL_TX_ENCRYPT_TYPE_NO_CIPHER = 7,
  186. HAL_TX_ENCRYPT_TYPE_AES_CCMP_256 = 8,
  187. HAL_TX_ENCRYPT_TYPE_AES_GCMP_128 = 9,
  188. HAL_TX_ENCRYPT_TYPE_AES_GCMP_256 = 10,
  189. HAL_TX_ENCRYPT_TYPE_WAPI_GCM_SM4 = 11,
  190. };
  191. /*
  192. * enum hal_tx_encap_type - Encapsulation type that HW will perform
  193. * @HAL_TX_ENCAP_TYPE_RAW: Raw Packet Type
  194. * @HAL_TX_ENCAP_TYPE_NWIFI: Native WiFi Type
  195. * @HAL_TX_ENCAP_TYPE_ETHERNET: Ethernet
  196. * @HAL_TX_ENCAP_TYPE_802_3: 802.3 Frame
  197. */
  198. enum hal_tx_encap_type {
  199. HAL_TX_ENCAP_TYPE_RAW = 0,
  200. HAL_TX_ENCAP_TYPE_NWIFI = 1,
  201. HAL_TX_ENCAP_TYPE_ETHERNET = 2,
  202. HAL_TX_ENCAP_TYPE_802_3 = 3,
  203. };
  204. /**
  205. * enum hal_tx_tqm_release_reason - TQM Release reason codes
  206. *
  207. * @HAL_TX_TQM_RR_FRAME_ACKED : ACK of BA for it was received
  208. * @HAL_TX_TQM_RR_REM_CMD_REM : Remove cmd of type “Remove_mpdus” initiated
  209. * by SW
  210. * @HAL_TX_TQM_RR_REM_CMD_TX : Remove command of type Remove_transmitted_mpdus
  211. * initiated by SW
  212. * @HAL_TX_TQM_RR_REM_CMD_NOTX : Remove cmd of type Remove_untransmitted_mpdus
  213. * initiated by SW
  214. * @HAL_TX_TQM_RR_REM_CMD_AGED : Remove command of type “Remove_aged_mpdus” or
  215. * “Remove_aged_msdus” initiated by SW
  216. * @HAL_TX_TQM_RR_FW_REASON1 : Remove command where fw indicated that
  217. * remove reason is fw_reason1
  218. * @HAL_TX_TQM_RR_FW_REASON2 : Remove command where fw indicated that
  219. * remove reason is fw_reason2
  220. * @HAL_TX_TQM_RR_FW_REASON3 : Remove command where fw indicated that
  221. * remove reason is fw_reason3
  222. */
  223. enum hal_tx_tqm_release_reason {
  224. HAL_TX_TQM_RR_FRAME_ACKED,
  225. HAL_TX_TQM_RR_REM_CMD_REM,
  226. HAL_TX_TQM_RR_REM_CMD_TX,
  227. HAL_TX_TQM_RR_REM_CMD_NOTX,
  228. HAL_TX_TQM_RR_REM_CMD_AGED,
  229. HAL_TX_TQM_RR_FW_REASON1,
  230. HAL_TX_TQM_RR_FW_REASON2,
  231. HAL_TX_TQM_RR_FW_REASON3,
  232. };
  233. /* enum - Table IDs for 2 DSCP-TID mapping Tables that TCL H/W supports
  234. * @HAL_TX_DSCP_TID_MAP_TABLE_DEFAULT: Default DSCP-TID mapping table
  235. * @HAL_TX_DSCP_TID_MAP_TABLE_OVERRIDE: DSCP-TID map override table
  236. */
  237. enum hal_tx_dscp_tid_table_id {
  238. HAL_TX_DSCP_TID_MAP_TABLE_DEFAULT,
  239. HAL_TX_DSCP_TID_MAP_TABLE_OVERRIDE,
  240. };
  241. /*---------------------------------------------------------------------------
  242. Function declarations and documentation
  243. ---------------------------------------------------------------------------*/
  244. /*---------------------------------------------------------------------------
  245. TCL Descriptor accessor APIs
  246. ---------------------------------------------------------------------------*/
  247. /**
  248. * hal_tx_desc_set_buf_addr - Fill Buffer Address information in Tx Descriptor
  249. * @desc: Handle to Tx Descriptor
  250. * @paddr: Physical Address
  251. * @pool_id: Return Buffer Manager ID
  252. * @desc_id: Descriptor ID
  253. * @type: 0 - Address points to a MSDU buffer
  254. * 1 - Address points to MSDU extension descriptor
  255. *
  256. * Return: void
  257. */
  258. static inline void hal_tx_desc_set_buf_addr(void *desc,
  259. dma_addr_t paddr, uint8_t pool_id,
  260. uint32_t desc_id, uint8_t type)
  261. {
  262. /* Set buffer_addr_info.buffer_addr_31_0 */
  263. HAL_SET_FLD(desc, TCL_DATA_CMD_0, BUFFER_ADDR_INFO_BUF_ADDR_INFO) =
  264. HAL_TX_SM(BUFFER_ADDR_INFO_0, BUFFER_ADDR_31_0, paddr);
  265. /* Set buffer_addr_info.buffer_addr_39_32 */
  266. HAL_SET_FLD(desc, TCL_DATA_CMD_1,
  267. BUFFER_ADDR_INFO_BUF_ADDR_INFO) |=
  268. HAL_TX_SM(BUFFER_ADDR_INFO_1, BUFFER_ADDR_39_32,
  269. (((uint64_t) paddr) >> 32));
  270. /* Set buffer_addr_info.return_buffer_manager = pool id */
  271. HAL_SET_FLD(desc, TCL_DATA_CMD_1,
  272. BUFFER_ADDR_INFO_BUF_ADDR_INFO) |=
  273. HAL_TX_SM(BUFFER_ADDR_INFO_1,
  274. RETURN_BUFFER_MANAGER, (pool_id + HAL_WBM_SW0_BM_ID));
  275. /* Set buffer_addr_info.sw_buffer_cookie = desc_id */
  276. HAL_SET_FLD(desc, TCL_DATA_CMD_1,
  277. BUFFER_ADDR_INFO_BUF_ADDR_INFO) |=
  278. HAL_TX_SM(BUFFER_ADDR_INFO_1, SW_BUFFER_COOKIE, desc_id);
  279. /* Set Buffer or Ext Descriptor Type */
  280. HAL_SET_FLD(desc, TCL_DATA_CMD_2,
  281. BUF_OR_EXT_DESC_TYPE) |=
  282. HAL_TX_SM(TCL_DATA_CMD_2, BUF_OR_EXT_DESC_TYPE, type);
  283. }
  284. /**
  285. * hal_tx_desc_set_buf_length - Set Data length in bytes in Tx Descriptor
  286. * @desc: Handle to Tx Descriptor
  287. * @data_length: MSDU length in case of direct descriptor.
  288. * Length of link extension descriptor in case of Link extension
  289. * descriptor.Includes the length of Metadata
  290. * Return: None
  291. */
  292. static inline void hal_tx_desc_set_buf_length(void *desc,
  293. uint16_t data_length)
  294. {
  295. HAL_SET_FLD(desc, TCL_DATA_CMD_3, DATA_LENGTH) |=
  296. HAL_TX_SM(TCL_DATA_CMD_3, DATA_LENGTH, data_length);
  297. }
  298. /**
  299. * hal_tx_desc_set_buf_offset - Sets Packet Offset field in Tx descriptor
  300. * @desc: Handle to Tx Descriptor
  301. * @offset: Packet offset from Metadata in case of direct buffer descriptor.
  302. *
  303. * Return: void
  304. */
  305. static inline void hal_tx_desc_set_buf_offset(void *desc,
  306. uint8_t offset)
  307. {
  308. HAL_SET_FLD(desc, TCL_DATA_CMD_3, PACKET_OFFSET) |=
  309. HAL_TX_SM(TCL_DATA_CMD_3, PACKET_OFFSET, offset);
  310. }
  311. /**
  312. * hal_tx_desc_set_encap_type - Set encapsulation type in Tx Descriptor
  313. * @desc: Handle to Tx Descriptor
  314. * @encap_type: Encapsulation that HW will perform
  315. *
  316. * Return: void
  317. *
  318. */
  319. static inline void hal_tx_desc_set_encap_type(void *desc,
  320. enum hal_tx_encap_type encap_type)
  321. {
  322. HAL_SET_FLD(desc, TCL_DATA_CMD_2, ENCAP_TYPE) |=
  323. HAL_TX_SM(TCL_DATA_CMD_2, ENCAP_TYPE, encap_type);
  324. }
  325. /**
  326. * hal_tx_desc_set_encrypt_type - Sets the Encrypt Type in Tx Descriptor
  327. * @desc: Handle to Tx Descriptor
  328. * @type: Encrypt Type
  329. *
  330. * Return: void
  331. */
  332. static inline void hal_tx_desc_set_encrypt_type(void *desc,
  333. enum hal_tx_encrypt_type type)
  334. {
  335. HAL_SET_FLD(desc, TCL_DATA_CMD_2, ENCRYPT_TYPE) |=
  336. HAL_TX_SM(TCL_DATA_CMD_2, ENCRYPT_TYPE, type);
  337. }
  338. /**
  339. * hal_tx_desc_set_addr_search_flags - Enable AddrX and AddrY search flags
  340. * @desc: Handle to Tx Descriptor
  341. * @flags: Bit 0 - AddrY search enable, Bit 1 - AddrX search enable
  342. *
  343. * Return: void
  344. */
  345. static inline void hal_tx_desc_set_addr_search_flags(void *desc,
  346. uint8_t flags)
  347. {
  348. HAL_SET_FLD(desc, TCL_DATA_CMD_2, ADDRX_EN) |=
  349. HAL_TX_SM(TCL_DATA_CMD_2, ADDRX_EN, (flags & 0x1));
  350. HAL_SET_FLD(desc, TCL_DATA_CMD_2, ADDRY_EN) |=
  351. HAL_TX_SM(TCL_DATA_CMD_2, ADDRY_EN, (flags >> 1));
  352. }
  353. /**
  354. * hal_tx_desc_set_l4_checksum_en - Set TCP/IP checksum enable flags
  355. * Tx Descriptor for MSDU_buffer type
  356. * @desc: Handle to Tx Descriptor
  357. * @en: UDP/TCP over ipv4/ipv6 checksum enable flags (5 bits)
  358. *
  359. * Return: void
  360. */
  361. static inline void hal_tx_desc_set_l4_checksum_en(void *desc,
  362. uint8_t en)
  363. {
  364. HAL_SET_FLD(desc, TCL_DATA_CMD_3, IPV4_CHECKSUM_EN) |=
  365. (HAL_TX_SM(TCL_DATA_CMD_3, UDP_OVER_IPV4_CHECKSUM_EN, en) |
  366. HAL_TX_SM(TCL_DATA_CMD_3, UDP_OVER_IPV6_CHECKSUM_EN, en) |
  367. HAL_TX_SM(TCL_DATA_CMD_3, TCP_OVER_IPV4_CHECKSUM_EN, en) |
  368. HAL_TX_SM(TCL_DATA_CMD_3, TCP_OVER_IPV6_CHECKSUM_EN, en));
  369. }
  370. /**
  371. * hal_tx_desc_set_l3_checksum_en - Set IPv4 checksum enable flag in
  372. * Tx Descriptor for MSDU_buffer type
  373. * @desc: Handle to Tx Descriptor
  374. * @checksum_en_flags: ipv4 checksum enable flags
  375. *
  376. * Return: void
  377. */
  378. static inline void hal_tx_desc_set_l3_checksum_en(void *desc,
  379. uint8_t en)
  380. {
  381. HAL_SET_FLD(desc, TCL_DATA_CMD_3, IPV4_CHECKSUM_EN) |=
  382. HAL_TX_SM(TCL_DATA_CMD_3, IPV4_CHECKSUM_EN, en);
  383. }
  384. /**
  385. * hal_tx_desc_set_fw_metadata- Sets the metadata that is part of TCL descriptor
  386. * @desc:Handle to Tx Descriptor
  387. * @metadata: Metadata to be sent to Firmware
  388. *
  389. * Return: void
  390. */
  391. static inline void hal_tx_desc_set_fw_metadata(void *desc,
  392. uint16_t metadata)
  393. {
  394. HAL_SET_FLD(desc, TCL_DATA_CMD_2, TCL_CMD_NUMBER) |=
  395. HAL_TX_SM(TCL_DATA_CMD_2, TCL_CMD_NUMBER, metadata);
  396. }
  397. /**
  398. * hal_tx_desc_set_to_fw - Set To_FW bit in Tx Descriptor.
  399. * @desc:Handle to Tx Descriptor
  400. * @to_fw: if set, Forward packet to FW along with classification result
  401. *
  402. * Return: void
  403. */
  404. static inline void hal_tx_desc_set_to_fw(void *desc, uint8_t to_fw)
  405. {
  406. HAL_SET_FLD(desc, TCL_DATA_CMD_3, TO_FW) |=
  407. HAL_TX_SM(TCL_DATA_CMD_3, TO_FW, to_fw);
  408. }
  409. /**
  410. * hal_tx_desc_set_dscp_tid_table_id - Sets DSCP to TID conversion table ID
  411. * @desc: Handle to Tx Descriptor
  412. * @id: DSCP to tid conversion table to be used for this frame
  413. *
  414. * Return: void
  415. */
  416. #if !defined(QCA_WIFI_QCA6290_11AX)
  417. static inline void hal_tx_desc_set_dscp_tid_table_id(void *desc,
  418. uint8_t id)
  419. {
  420. HAL_SET_FLD(desc, TCL_DATA_CMD_3,
  421. DSCP_TO_TID_PRIORITY_TABLE_ID) |=
  422. HAL_TX_SM(TCL_DATA_CMD_3,
  423. DSCP_TO_TID_PRIORITY_TABLE_ID, id);
  424. }
  425. #else
  426. static inline void hal_tx_desc_set_dscp_tid_table_id(void *desc,
  427. uint8_t id)
  428. {
  429. HAL_SET_FLD(desc, TCL_DATA_CMD_5,
  430. DSCP_TID_TABLE_NUM) |=
  431. HAL_TX_SM(TCL_DATA_CMD_5,
  432. DSCP_TID_TABLE_NUM, id);
  433. }
  434. #endif
  435. /**
  436. * hal_tx_desc_set_mesh_en - Set mesh_enable flag in Tx descriptor
  437. * @desc: Handle to Tx Descriptor
  438. * @en: For raw WiFi frames, this indicates transmission to a mesh STA,
  439. * enabling the interpretation of the 'Mesh Control Present' bit
  440. * (bit 8) of QoS Control (otherwise this bit is ignored),
  441. * For native WiFi frames, this indicates that a 'Mesh Control' field
  442. * is present between the header and the LLC.
  443. *
  444. * Return: void
  445. */
  446. static inline void hal_tx_desc_set_mesh_en(void *desc, uint8_t en)
  447. {
  448. HAL_SET_FLD(desc, TCL_DATA_CMD_4, MESH_ENABLE) |=
  449. HAL_TX_SM(TCL_DATA_CMD_4, MESH_ENABLE, en);
  450. }
  451. /**
  452. * hal_tx_desc_set_hlos_tid - Set the TID value (override DSCP/PCP fields in
  453. * frame) to be used for Tx Frame
  454. * @desc: Handle to Tx Descriptor
  455. * @hlos_tid: HLOS TID
  456. *
  457. * Return: void
  458. */
  459. static inline void hal_tx_desc_set_hlos_tid(void *desc,
  460. uint8_t hlos_tid)
  461. {
  462. HAL_SET_FLD(desc, TCL_DATA_CMD_4, HLOS_TID) |=
  463. HAL_TX_SM(TCL_DATA_CMD_4, HLOS_TID, hlos_tid);
  464. HAL_SET_FLD(desc, TCL_DATA_CMD_4, HLOS_TID_OVERWRITE) |=
  465. HAL_TX_SM(TCL_DATA_CMD_4, HLOS_TID_OVERWRITE, 1);
  466. }
  467. #ifdef QCA_WIFI_QCA6290_11AX
  468. /**
  469. * hal_tx_desc_set_lmac_id - Set the lmac_id value
  470. * @desc: Handle to Tx Descriptor
  471. * @lmac_id: mac Id to ast matching
  472. * b00 – mac 0
  473. * b01 – mac 1
  474. * b10 – mac 2
  475. * b11 – all macs (legacy HK way)
  476. *
  477. * Return: void
  478. */
  479. static inline void hal_tx_desc_set_lmac_id(void *desc,
  480. uint8_t lmac_id)
  481. {
  482. HAL_SET_FLD(desc, TCL_DATA_CMD_4, LMAC_ID) |=
  483. HAL_TX_SM(TCL_DATA_CMD_4, LMAC_ID, lmac_id);
  484. }
  485. #else
  486. static inline void hal_tx_desc_set_lmac_id(void *desc,
  487. uint8_t lmac_id)
  488. {
  489. }
  490. #endif
  491. /**
  492. * hal_tx_desc_sync - Commit the descriptor to Hardware
  493. * @hal_tx_des_cached: Cached descriptor that software maintains
  494. * @hw_desc: Hardware descriptor to be updated
  495. */
  496. static inline void hal_tx_desc_sync(void *hal_tx_desc_cached,
  497. void *hw_desc)
  498. {
  499. qdf_mem_copy((hw_desc + sizeof(struct tlv_32_hdr)),
  500. hal_tx_desc_cached, 20);
  501. }
  502. /*---------------------------------------------------------------------------
  503. Tx MSDU Extension Descriptor accessor APIs
  504. ---------------------------------------------------------------------------*/
  505. /**
  506. * hal_tx_ext_desc_set_tso_enable() - Set TSO Enable Flag
  507. * @desc: Handle to Tx MSDU Extension Descriptor
  508. * @tso_en: bool value set to true if TSO is enabled
  509. *
  510. * Return: none
  511. */
  512. static inline void hal_tx_ext_desc_set_tso_enable(void *desc,
  513. uint8_t tso_en)
  514. {
  515. HAL_SET_FLD(desc, TX_MSDU_EXTENSION_0, TSO_ENABLE) |=
  516. HAL_TX_SM(TX_MSDU_EXTENSION_0, TSO_ENABLE, tso_en);
  517. }
  518. /**
  519. * hal_tx_ext_desc_set_tso_flags() - Set TSO Flags
  520. * @desc: Handle to Tx MSDU Extension Descriptor
  521. * @falgs: 32-bit word with all TSO flags consolidated
  522. *
  523. * Return: none
  524. */
  525. static inline void hal_tx_ext_desc_set_tso_flags(void *desc,
  526. uint32_t tso_flags)
  527. {
  528. HAL_SET_FLD_OFFSET(desc, TX_MSDU_EXTENSION_0, TSO_ENABLE, 0) =
  529. tso_flags;
  530. }
  531. /**
  532. * hal_tx_ext_desc_set_tcp_flags() - Enable HW Checksum offload
  533. * @desc: Handle to Tx MSDU Extension Descriptor
  534. * @tcp_flags: TCP flags {NS,CWR,ECE,URG,ACK,PSH, RST ,SYN,FIN}
  535. * @mask: TCP flag mask. Tcp_flag is inserted into the header
  536. * based on the mask, if tso is enabled
  537. *
  538. * Return: none
  539. */
  540. static inline void hal_tx_ext_desc_set_tcp_flags(void *desc,
  541. uint16_t tcp_flags,
  542. uint16_t mask)
  543. {
  544. HAL_SET_FLD(desc, TX_MSDU_EXTENSION_0, TCP_FLAG) |=
  545. ((HAL_TX_SM(TX_MSDU_EXTENSION_0, TCP_FLAG, tcp_flags)) |
  546. (HAL_TX_SM(TX_MSDU_EXTENSION_0, TCP_FLAG_MASK, mask)));
  547. }
  548. /**
  549. * hal_tx_ext_desc_set_msdu_length() - Set L2 and IP Lengths
  550. * @desc: Handle to Tx MSDU Extension Descriptor
  551. * @l2_len: L2 length for the msdu, if tso is enabled
  552. * @ip_len: IP length for the msdu, if tso is enabled
  553. *
  554. * Return: none
  555. */
  556. static inline void hal_tx_ext_desc_set_msdu_length(void *desc,
  557. uint16_t l2_len,
  558. uint16_t ip_len)
  559. {
  560. HAL_SET_FLD(desc, TX_MSDU_EXTENSION_1, L2_LENGTH) |=
  561. ((HAL_TX_SM(TX_MSDU_EXTENSION_1, L2_LENGTH, l2_len)) |
  562. (HAL_TX_SM(TX_MSDU_EXTENSION_1, IP_LENGTH, ip_len)));
  563. }
  564. /**
  565. * hal_tx_ext_desc_set_tcp_seq() - Set TCP Sequence number
  566. * @desc: Handle to Tx MSDU Extension Descriptor
  567. * @seq_num: Tcp_seq_number for the msdu, if tso is enabled
  568. *
  569. * Return: none
  570. */
  571. static inline void hal_tx_ext_desc_set_tcp_seq(void *desc,
  572. uint32_t seq_num)
  573. {
  574. HAL_SET_FLD(desc, TX_MSDU_EXTENSION_2, TCP_SEQ_NUMBER) |=
  575. ((HAL_TX_SM(TX_MSDU_EXTENSION_2, TCP_SEQ_NUMBER, seq_num)));
  576. }
  577. /**
  578. * hal_tx_ext_desc_set_ip_id() - Set IP Identification field
  579. * @desc: Handle to Tx MSDU Extension Descriptor
  580. * @id: IP Id field for the msdu, if tso is enabled
  581. *
  582. * Return: none
  583. */
  584. static inline void hal_tx_ext_desc_set_ip_id(void *desc,
  585. uint16_t id)
  586. {
  587. HAL_SET_FLD(desc, TX_MSDU_EXTENSION_3, IP_IDENTIFICATION) |=
  588. ((HAL_TX_SM(TX_MSDU_EXTENSION_3, IP_IDENTIFICATION, id)));
  589. }
  590. /**
  591. * hal_tx_ext_desc_set_buffer() - Set Buffer Pointer and Length for a fragment
  592. * @desc: Handle to Tx MSDU Extension Descriptor
  593. * @frag_num: Fragment number (value can be 0 to 5)
  594. * @paddr_lo: Lower 32-bit of Buffer Physical address
  595. * @paddr_hi: Upper 32-bit of Buffer Physical address
  596. * @length: Buffer Length
  597. *
  598. * Return: none
  599. */
  600. static inline void hal_tx_ext_desc_set_buffer(void *desc,
  601. uint8_t frag_num,
  602. uint32_t paddr_lo,
  603. uint16_t paddr_hi,
  604. uint16_t length)
  605. {
  606. HAL_SET_FLD_OFFSET(desc, TX_MSDU_EXTENSION_6, BUF0_PTR_31_0,
  607. (frag_num << 3)) |=
  608. ((HAL_TX_SM(TX_MSDU_EXTENSION_6, BUF0_PTR_31_0, paddr_lo)));
  609. HAL_SET_FLD_OFFSET(desc, TX_MSDU_EXTENSION_7, BUF0_PTR_39_32,
  610. (frag_num << 3)) |=
  611. ((HAL_TX_SM(TX_MSDU_EXTENSION_7, BUF0_PTR_39_32,
  612. (paddr_hi))));
  613. HAL_SET_FLD_OFFSET(desc, TX_MSDU_EXTENSION_7, BUF0_LEN,
  614. (frag_num << 3)) |=
  615. ((HAL_TX_SM(TX_MSDU_EXTENSION_7, BUF0_LEN, length)));
  616. }
  617. /**
  618. * hal_tx_ext_desc_set_buffer0_param() - Set Buffer 0 Pointer and Length
  619. * @desc: Handle to Tx MSDU Extension Descriptor
  620. * @paddr_lo: Lower 32-bit of Buffer Physical address
  621. * @paddr_hi: Upper 32-bit of Buffer Physical address
  622. * @length: Buffer 0 Length
  623. *
  624. * Return: none
  625. */
  626. static inline void hal_tx_ext_desc_set_buffer0_param(void *desc,
  627. uint32_t paddr_lo,
  628. uint16_t paddr_hi,
  629. uint16_t length)
  630. {
  631. HAL_SET_FLD(desc, TX_MSDU_EXTENSION_6, BUF0_PTR_31_0) |=
  632. ((HAL_TX_SM(TX_MSDU_EXTENSION_6, BUF0_PTR_31_0, paddr_lo)));
  633. HAL_SET_FLD(desc, TX_MSDU_EXTENSION_7, BUF0_PTR_39_32) |=
  634. ((HAL_TX_SM(TX_MSDU_EXTENSION_7,
  635. BUF0_PTR_39_32, paddr_hi)));
  636. HAL_SET_FLD(desc, TX_MSDU_EXTENSION_7, BUF0_LEN) |=
  637. ((HAL_TX_SM(TX_MSDU_EXTENSION_7, BUF0_LEN, length)));
  638. }
  639. /**
  640. * hal_tx_ext_desc_set_buffer1_param() - Set Buffer 1 Pointer and Length
  641. * @desc: Handle to Tx MSDU Extension Descriptor
  642. * @paddr_lo: Lower 32-bit of Buffer Physical address
  643. * @paddr_hi: Upper 32-bit of Buffer Physical address
  644. * @length: Buffer 1 Length
  645. *
  646. * Return: none
  647. */
  648. static inline void hal_tx_ext_desc_set_buffer1_param(void *desc,
  649. uint32_t paddr_lo,
  650. uint16_t paddr_hi,
  651. uint16_t length)
  652. {
  653. HAL_SET_FLD(desc, TX_MSDU_EXTENSION_8, BUF1_PTR_31_0) |=
  654. ((HAL_TX_SM(TX_MSDU_EXTENSION_8, BUF1_PTR_31_0, paddr_lo)));
  655. HAL_SET_FLD(desc, TX_MSDU_EXTENSION_9, BUF1_PTR_39_32) |=
  656. ((HAL_TX_SM(TX_MSDU_EXTENSION_9,
  657. BUF1_PTR_39_32, paddr_hi)));
  658. HAL_SET_FLD(desc, TX_MSDU_EXTENSION_9, BUF1_LEN) |=
  659. ((HAL_TX_SM(TX_MSDU_EXTENSION_9, BUF1_LEN, length)));
  660. }
  661. /**
  662. * hal_tx_ext_desc_set_buffer2_param() - Set Buffer 2 Pointer and Length
  663. * @desc: Handle to Tx MSDU Extension Descriptor
  664. * @paddr_lo: Lower 32-bit of Buffer Physical address
  665. * @paddr_hi: Upper 32-bit of Buffer Physical address
  666. * @length: Buffer 2 Length
  667. *
  668. * Return: none
  669. */
  670. static inline void hal_tx_ext_desc_set_buffer2_param(void *desc,
  671. uint32_t paddr_lo,
  672. uint16_t paddr_hi,
  673. uint16_t length)
  674. {
  675. HAL_SET_FLD(desc, TX_MSDU_EXTENSION_10, BUF2_PTR_31_0) |=
  676. ((HAL_TX_SM(TX_MSDU_EXTENSION_10, BUF2_PTR_31_0,
  677. paddr_lo)));
  678. HAL_SET_FLD(desc, TX_MSDU_EXTENSION_11, BUF2_PTR_39_32) |=
  679. ((HAL_TX_SM(TX_MSDU_EXTENSION_11, BUF2_PTR_39_32,
  680. paddr_hi)));
  681. HAL_SET_FLD(desc, TX_MSDU_EXTENSION_11, BUF2_LEN) |=
  682. ((HAL_TX_SM(TX_MSDU_EXTENSION_11, BUF2_LEN, length)));
  683. }
  684. /**
  685. * hal_tx_ext_desc_sync - Commit the descriptor to Hardware
  686. * @desc_cached: Cached descriptor that software maintains
  687. * @hw_desc: Hardware descriptor to be updated
  688. *
  689. * Return: none
  690. */
  691. static inline void hal_tx_ext_desc_sync(uint8_t *desc_cached,
  692. uint8_t *hw_desc)
  693. {
  694. qdf_mem_copy(&hw_desc[0], &desc_cached[0],
  695. HAL_TX_EXT_DESC_WITH_META_DATA);
  696. }
  697. /**
  698. * hal_tx_ext_desc_get_tso_enable() - Set TSO Enable Flag
  699. * @hal_tx_ext_desc: Handle to Tx MSDU Extension Descriptor
  700. *
  701. * Return: tso_enable value in the descriptor
  702. */
  703. static inline uint32_t hal_tx_ext_desc_get_tso_enable(void *hal_tx_ext_desc)
  704. {
  705. uint32_t *desc = (uint32_t *) hal_tx_ext_desc;
  706. return (*desc & TX_MSDU_EXTENSION_0_TSO_ENABLE_MASK) >>
  707. TX_MSDU_EXTENSION_0_TSO_ENABLE_LSB;
  708. }
  709. /*---------------------------------------------------------------------------
  710. WBM Descriptor accessor APIs for Tx completions
  711. ---------------------------------------------------------------------------*/
  712. /**
  713. * hal_tx_comp_get_desc_id() - Get TX descriptor id within comp descriptor
  714. * @hal_desc: completion ring descriptor pointer
  715. *
  716. * This function will tx descriptor id, cookie, within hardware completion
  717. * descriptor
  718. *
  719. * Return: cookie
  720. */
  721. static inline uint32_t hal_tx_comp_get_desc_id(void *hal_desc)
  722. {
  723. uint32_t comp_desc =
  724. *(uint32_t *) (((uint8_t *) hal_desc) +
  725. BUFFER_ADDR_INFO_1_SW_BUFFER_COOKIE_OFFSET);
  726. /* Cookie is placed on 2nd word */
  727. return (comp_desc & BUFFER_ADDR_INFO_1_SW_BUFFER_COOKIE_MASK) >>
  728. BUFFER_ADDR_INFO_1_SW_BUFFER_COOKIE_LSB;
  729. }
  730. /**
  731. * hal_tx_comp_get_paddr() - Get paddr within comp descriptor
  732. * @hal_desc: completion ring descriptor pointer
  733. *
  734. * This function will get buffer physical address within hardware completion
  735. * descriptor
  736. *
  737. * Return: Buffer physical address
  738. */
  739. static inline qdf_dma_addr_t hal_tx_comp_get_paddr(void *hal_desc)
  740. {
  741. uint32_t paddr_lo;
  742. uint32_t paddr_hi;
  743. paddr_lo = *(uint32_t *) (((uint8_t *) hal_desc) +
  744. BUFFER_ADDR_INFO_0_BUFFER_ADDR_31_0_OFFSET);
  745. paddr_hi = *(uint32_t *) (((uint8_t *) hal_desc) +
  746. BUFFER_ADDR_INFO_1_BUFFER_ADDR_39_32_OFFSET);
  747. paddr_hi = (paddr_hi & BUFFER_ADDR_INFO_1_BUFFER_ADDR_39_32_MASK) >>
  748. BUFFER_ADDR_INFO_1_BUFFER_ADDR_39_32_LSB;
  749. return (qdf_dma_addr_t) (paddr_lo | (((uint64_t) paddr_hi) << 32));
  750. }
  751. /**
  752. * hal_tx_comp_get_buffer_source() - Get buffer release source value
  753. * @hal_desc: completion ring descriptor pointer
  754. *
  755. * This function will get buffer release source from Tx completion descriptor
  756. *
  757. * Return: buffer release source
  758. */
  759. static inline uint32_t hal_tx_comp_get_buffer_source(void *hal_desc)
  760. {
  761. uint32_t comp_desc =
  762. *(uint32_t *) (((uint8_t *) hal_desc) +
  763. WBM_RELEASE_RING_2_RELEASE_SOURCE_MODULE_OFFSET);
  764. return (comp_desc & WBM_RELEASE_RING_2_RELEASE_SOURCE_MODULE_MASK) >>
  765. WBM_RELEASE_RING_2_RELEASE_SOURCE_MODULE_LSB;
  766. }
  767. /**
  768. * hal_tx_comp_get_buffer_type() - Buffer or Descriptor type
  769. * @hal_desc: completion ring descriptor pointer
  770. *
  771. * This function will return the type of pointer - buffer or descriptor
  772. *
  773. * Return: buffer type
  774. */
  775. static inline uint32_t hal_tx_comp_get_buffer_type(void *hal_desc)
  776. {
  777. uint32_t comp_desc =
  778. *(uint32_t *) (((uint8_t *) hal_desc) +
  779. WBM_RELEASE_RING_2_BUFFER_OR_DESC_TYPE_OFFSET);
  780. return (comp_desc & WBM_RELEASE_RING_2_BUFFER_OR_DESC_TYPE_MASK) >>
  781. WBM_RELEASE_RING_2_BUFFER_OR_DESC_TYPE_LSB;
  782. }
  783. /**
  784. * hal_tx_comp_get_release_reason() - TQM Release reason
  785. * @hal_desc: completion ring descriptor pointer
  786. *
  787. * This function will return the type of pointer - buffer or descriptor
  788. *
  789. * Return: buffer type
  790. */
  791. static inline uint8_t hal_tx_comp_get_release_reason(void *hal_desc)
  792. {
  793. uint32_t comp_desc =
  794. *(uint32_t *) (((uint8_t *) hal_desc) +
  795. WBM_RELEASE_RING_2_TQM_RELEASE_REASON_OFFSET);
  796. return (comp_desc & WBM_RELEASE_RING_2_TQM_RELEASE_REASON_MASK) >>
  797. WBM_RELEASE_RING_2_TQM_RELEASE_REASON_LSB;
  798. }
  799. /**
  800. * hal_tx_comp_get_status() - TQM Release reason
  801. * @hal_desc: completion ring Tx status
  802. *
  803. * This function will parse the WBM completion descriptor and populate in
  804. * HAL structure
  805. *
  806. * Return: none
  807. */
  808. #if defined(WCSS_VERSION) && \
  809. ((defined(CONFIG_WIN) && (WCSS_VERSION > 81)) || \
  810. (defined(CONFIG_MCL) && (WCSS_VERSION >= 72)))
  811. static inline void hal_tx_comp_get_status(void *desc,
  812. struct hal_tx_completion_status *ts)
  813. {
  814. uint8_t rate_stats_valid = 0;
  815. uint32_t rate_stats = 0;
  816. ts->ppdu_id = HAL_TX_DESC_GET(desc, WBM_RELEASE_RING_3,
  817. TQM_STATUS_NUMBER);
  818. ts->ack_frame_rssi = HAL_TX_DESC_GET(desc, WBM_RELEASE_RING_4,
  819. ACK_FRAME_RSSI);
  820. ts->first_msdu = HAL_TX_DESC_GET(desc, WBM_RELEASE_RING_4, FIRST_MSDU);
  821. ts->last_msdu = HAL_TX_DESC_GET(desc, WBM_RELEASE_RING_4, LAST_MSDU);
  822. ts->msdu_part_of_amsdu = HAL_TX_DESC_GET(desc, WBM_RELEASE_RING_4,
  823. MSDU_PART_OF_AMSDU);
  824. ts->peer_id = HAL_TX_DESC_GET(desc, WBM_RELEASE_RING_7, SW_PEER_ID);
  825. ts->tid = HAL_TX_DESC_GET(desc, WBM_RELEASE_RING_7, TID);
  826. ts->transmit_cnt = HAL_TX_DESC_GET(desc, WBM_RELEASE_RING_3,
  827. TRANSMIT_COUNT);
  828. rate_stats = HAL_TX_DESC_GET(desc, WBM_RELEASE_RING_5,
  829. TX_RATE_STATS);
  830. rate_stats_valid = HAL_TX_MS(TX_RATE_STATS_INFO_0,
  831. TX_RATE_STATS_INFO_VALID, rate_stats);
  832. ts->valid = rate_stats_valid;
  833. if (rate_stats_valid) {
  834. ts->bw = HAL_TX_MS(TX_RATE_STATS_INFO_0, TRANSMIT_BW,
  835. rate_stats);
  836. ts->pkt_type = HAL_TX_MS(TX_RATE_STATS_INFO_0,
  837. TRANSMIT_PKT_TYPE, rate_stats);
  838. ts->stbc = HAL_TX_MS(TX_RATE_STATS_INFO_0,
  839. TRANSMIT_STBC, rate_stats);
  840. ts->ldpc = HAL_TX_MS(TX_RATE_STATS_INFO_0, TRANSMIT_LDPC,
  841. rate_stats);
  842. ts->sgi = HAL_TX_MS(TX_RATE_STATS_INFO_0, TRANSMIT_SGI,
  843. rate_stats);
  844. ts->mcs = HAL_TX_MS(TX_RATE_STATS_INFO_0, TRANSMIT_MCS,
  845. rate_stats);
  846. ts->ofdma = HAL_TX_MS(TX_RATE_STATS_INFO_0, OFDMA_TRANSMISSION,
  847. rate_stats);
  848. ts->tones_in_ru = HAL_TX_MS(TX_RATE_STATS_INFO_0, TONES_IN_RU,
  849. rate_stats);
  850. }
  851. ts->release_src = hal_tx_comp_get_buffer_source(desc);
  852. ts->status = hal_tx_comp_get_release_reason(desc);
  853. ts->tsf = HAL_TX_DESC_GET(desc, WBM_RELEASE_RING_6,
  854. TX_RATE_STATS_INFO_TX_RATE_STATS);
  855. }
  856. #else
  857. static inline void hal_tx_comp_get_status(void *desc,
  858. struct hal_tx_completion_status *ts)
  859. {
  860. ts->ppdu_id = HAL_TX_DESC_GET(desc, WBM_RELEASE_RING_3,
  861. TQM_STATUS_NUMBER);
  862. ts->ack_frame_rssi = HAL_TX_DESC_GET(desc, WBM_RELEASE_RING_4,
  863. ACK_FRAME_RSSI);
  864. ts->first_msdu = HAL_TX_DESC_GET(desc, WBM_RELEASE_RING_4, FIRST_MSDU);
  865. ts->last_msdu = HAL_TX_DESC_GET(desc, WBM_RELEASE_RING_4, LAST_MSDU);
  866. ts->msdu_part_of_amsdu = HAL_TX_DESC_GET(desc, WBM_RELEASE_RING_4,
  867. MSDU_PART_OF_AMSDU);
  868. ts->release_src = hal_tx_comp_get_buffer_source(desc);
  869. ts->status = hal_tx_comp_get_release_reason(desc);
  870. }
  871. #endif
  872. /**
  873. * hal_tx_comp_desc_sync() - collect hardware descriptor contents
  874. * @hal_desc: hardware descriptor pointer
  875. * @comp: software descriptor pointer
  876. * @read_status: 0 - Do not read status words from descriptors
  877. * 1 - Enable reading of status words from descriptor
  878. *
  879. * This function will collect hardware release ring element contents and
  880. * translate to software descriptor content
  881. *
  882. * Return: none
  883. */
  884. static inline void hal_tx_comp_desc_sync(void *hw_desc,
  885. struct hal_tx_desc_comp_s *comp,
  886. bool read_status)
  887. {
  888. if (!read_status)
  889. qdf_mem_copy(comp, hw_desc, HAL_TX_COMPLETION_DESC_BASE_LEN);
  890. else
  891. qdf_mem_copy(comp, hw_desc, HAL_TX_COMPLETION_DESC_LEN_BYTES);
  892. }
  893. /**
  894. * hal_tx_comp_get_htt_desc() - Read the HTT portion of WBM Descriptor
  895. * @hal_desc: Hardware (WBM) descriptor pointer
  896. * @htt_desc: Software HTT descriptor pointer
  897. *
  898. * This function will read the HTT structure overlaid on WBM descriptor
  899. * into a cached software descriptor
  900. *
  901. */
  902. static inline void hal_tx_comp_get_htt_desc(void *hw_desc, uint8_t *htt_desc)
  903. {
  904. uint8_t *desc = hw_desc + HAL_TX_COMP_HTT_STATUS_OFFSET;
  905. qdf_mem_copy(htt_desc, desc, HAL_TX_COMP_HTT_STATUS_LEN);
  906. }
  907. #if !defined(QCA_WIFI_QCA6290_11AX)
  908. /**
  909. * hal_tx_set_dscp_tid_map_default() - Configure default DSCP to TID map table
  910. * @soc: HAL SoC context
  911. * @map: DSCP-TID mapping table
  912. * @id: mapping table ID - 0,1
  913. *
  914. * DSCP are mapped to 8 TID values using TID values programmed
  915. * in two set of mapping registers DSCP_TID1_MAP_<0 to 6> (id = 0)
  916. * and DSCP_TID2_MAP_<0 to 6> (id = 1)
  917. * Each mapping register has TID mapping for 10 DSCP values
  918. *
  919. * Return: none
  920. */
  921. static inline void hal_tx_set_dscp_tid_map(void *hal_soc, uint8_t *map,
  922. uint8_t id)
  923. {
  924. int i;
  925. uint32_t addr;
  926. uint32_t value;
  927. struct hal_soc *soc = (struct hal_soc *)hal_soc;
  928. if (id == HAL_TX_DSCP_TID_MAP_TABLE_DEFAULT) {
  929. addr =
  930. HWIO_TCL_R0_DSCP_TID1_MAP_0_ADDR(
  931. SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET);
  932. } else {
  933. addr =
  934. HWIO_TCL_R0_DSCP_TID2_MAP_0_ADDR(
  935. SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET);
  936. }
  937. for (i = 0; i < 64; i += 10) {
  938. value = (map[i] |
  939. (map[i+1] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_1_SHFT) |
  940. (map[i+2] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_2_SHFT) |
  941. (map[i+3] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_3_SHFT) |
  942. (map[i+4] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_4_SHFT) |
  943. (map[i+5] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_5_SHFT) |
  944. (map[i+6] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_6_SHFT) |
  945. (map[i+7] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_7_SHFT) |
  946. (map[i+8] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_8_SHFT) |
  947. (map[i+9] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_9_SHFT));
  948. HAL_REG_WRITE(soc, addr,
  949. (value & HWIO_TCL_R0_DSCP_TID1_MAP_1_RMSK));
  950. addr += 4;
  951. }
  952. }
  953. /**
  954. * hal_tx_update_dscp_tid() - Update the dscp tid map table as updated by user
  955. * @soc: HAL SoC context
  956. * @map: DSCP-TID mapping table
  957. * @id : MAP ID
  958. * @dscp: DSCP_TID map index
  959. *
  960. * Return: void
  961. */
  962. static inline void hal_tx_update_dscp_tid(void *hal_soc, uint8_t tid,
  963. uint8_t id, uint8_t dscp)
  964. {
  965. int index;
  966. uint32_t addr;
  967. uint32_t value;
  968. uint32_t regval;
  969. struct hal_soc *soc = (struct hal_soc *)hal_soc;
  970. if (id == HAL_TX_DSCP_TID_MAP_TABLE_DEFAULT)
  971. addr =
  972. HWIO_TCL_R0_DSCP_TID1_MAP_0_ADDR(
  973. SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET);
  974. else
  975. addr =
  976. HWIO_TCL_R0_DSCP_TID2_MAP_0_ADDR(
  977. SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET);
  978. index = dscp % HAL_TX_NUM_DSCP_PER_REGISTER;
  979. addr += 4 * (dscp/HAL_TX_NUM_DSCP_PER_REGISTER);
  980. value = tid << (HAL_TX_BITS_PER_TID * index);
  981. /* Read back previous DSCP TID config and update
  982. * with new config.
  983. */
  984. regval = HAL_REG_READ(soc, addr);
  985. regval &= ~(HAL_TX_TID_BITS_MASK << (HAL_TX_BITS_PER_TID * index));
  986. regval |= value;
  987. HAL_REG_WRITE(soc, addr,
  988. (regval & HWIO_TCL_R0_DSCP_TID1_MAP_1_RMSK));
  989. }
  990. #else
  991. #define DSCP_TID_TABLE_SIZE 24
  992. #define NUM_WORDS_PER_DSCP_TID_TABLE (DSCP_TID_TABLE_SIZE/4)
  993. /**
  994. * hal_tx_set_dscp_tid_map_default() - Configure default DSCP to TID map table
  995. * @soc: HAL SoC context
  996. * @map: DSCP-TID mapping table
  997. * @id: mapping table ID - 0-31
  998. *
  999. * DSCP are mapped to 8 TID values using TID values programmed
  1000. * in any of the 32 DSCP_TID_MAPS (id = 0-31).
  1001. *
  1002. * Return: none
  1003. */
  1004. static inline void hal_tx_set_dscp_tid_map(void *hal_soc, uint8_t *map,
  1005. uint8_t id)
  1006. {
  1007. int i;
  1008. uint32_t addr, cmn_reg_addr;
  1009. uint32_t value = 0, regval;
  1010. uint8_t val[DSCP_TID_TABLE_SIZE], cnt = 0;
  1011. struct hal_soc *soc = (struct hal_soc *)hal_soc;
  1012. if (id >= HAL_MAX_HW_DSCP_TID_MAPS_11AX) {
  1013. return;
  1014. }
  1015. cmn_reg_addr = HWIO_TCL_R0_CONS_RING_CMN_CTRL_REG_ADDR(
  1016. SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET);
  1017. addr = HWIO_TCL_R0_DSCP_TID_MAP_n_ADDR(
  1018. SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET,
  1019. id * NUM_WORDS_PER_DSCP_TID_TABLE);
  1020. /* Enable read/write access */
  1021. regval = HAL_REG_READ(soc, cmn_reg_addr);
  1022. regval |=
  1023. (1 << HWIO_TCL_R0_CONS_RING_CMN_CTRL_REG_DSCP_TID_MAP_PROGRAM_EN_SHFT);
  1024. HAL_REG_WRITE(soc, cmn_reg_addr, regval);
  1025. /* Write 8 (24 bits) DSCP-TID mappings in each interation */
  1026. for (i = 0; i < 64; i += 8) {
  1027. value = (map[i] |
  1028. (map[i+1] << 0x3) |
  1029. (map[i+2] << 0x6) |
  1030. (map[i+3] << 0x9) |
  1031. (map[i+4] << 0xc) |
  1032. (map[i+5] << 0xf) |
  1033. (map[i+6] << 0x12) |
  1034. (map[i+7] << 0x15));
  1035. qdf_mem_copy(&val[cnt], (void *)&value, 3);
  1036. cnt += 3;
  1037. }
  1038. for (i = 0; i < DSCP_TID_TABLE_SIZE; i += 4) {
  1039. regval = *(uint32_t *)(val + i);
  1040. HAL_REG_WRITE(soc, addr,
  1041. (regval & HWIO_TCL_R0_DSCP_TID_MAP_n_RMSK));
  1042. addr += 4;
  1043. }
  1044. /* Diasble read/write access */
  1045. regval = HAL_REG_READ(soc, cmn_reg_addr);
  1046. regval &=
  1047. ~(HWIO_TCL_R0_CONS_RING_CMN_CTRL_REG_DSCP_TID_MAP_PROGRAM_EN_BMSK);
  1048. HAL_REG_WRITE(soc, cmn_reg_addr, regval);
  1049. }
  1050. static inline void hal_tx_update_dscp_tid(void *hal_soc, uint8_t tid,
  1051. uint8_t id, uint8_t dscp)
  1052. {
  1053. int index;
  1054. uint32_t addr;
  1055. uint32_t value;
  1056. uint32_t regval;
  1057. struct hal_soc *soc = (struct hal_soc *)hal_soc;
  1058. addr = HWIO_TCL_R0_DSCP_TID_MAP_n_ADDR(
  1059. SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET, id);
  1060. index = dscp % HAL_TX_NUM_DSCP_PER_REGISTER;
  1061. addr += 4 * (dscp/HAL_TX_NUM_DSCP_PER_REGISTER);
  1062. value = tid << (HAL_TX_BITS_PER_TID * index);
  1063. regval = HAL_REG_READ(soc, addr);
  1064. regval &= ~(HAL_TX_TID_BITS_MASK << (HAL_TX_BITS_PER_TID * index));
  1065. regval |= value;
  1066. HAL_REG_WRITE(soc, addr,
  1067. (regval & HWIO_TCL_R0_DSCP_TID_MAP_n_RMSK));
  1068. }
  1069. #endif
  1070. /**
  1071. * hal_tx_init_data_ring() - Initialize all the TCL Descriptors in SRNG
  1072. * @hal_soc: Handle to HAL SoC structure
  1073. * @hal_srng: Handle to HAL SRNG structure
  1074. *
  1075. * Return: none
  1076. */
  1077. static inline void hal_tx_init_data_ring(void *hal_soc, void *hal_srng)
  1078. {
  1079. uint8_t *desc_addr;
  1080. struct hal_srng_params srng_params;
  1081. uint32_t desc_size;
  1082. uint32_t num_desc;
  1083. hal_get_srng_params(hal_soc, hal_srng, &srng_params);
  1084. desc_addr = (uint8_t *) srng_params.ring_base_vaddr;
  1085. desc_size = sizeof(struct tcl_data_cmd);
  1086. num_desc = srng_params.num_entries;
  1087. while (num_desc) {
  1088. HAL_TX_DESC_SET_TLV_HDR(desc_addr, HAL_TX_TCL_DATA_TAG,
  1089. desc_size);
  1090. desc_addr += (desc_size + sizeof(struct tlv_32_hdr));
  1091. num_desc--;
  1092. }
  1093. }
  1094. #endif /* HAL_TX_H */