hal_tx.h 34 KB

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