hal_tx.h 36 KB

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