hal_be_tx.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. /*
  2. * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #ifndef _HAL_BE_TX_H_
  20. #define _HAL_BE_TX_H_
  21. #include "hal_be_hw_headers.h"
  22. #include "hal_tx.h"
  23. /* Number of TX banks reserved i.e, will not be used by host driver. */
  24. /* MAX_TCL_BANK reserved for FW use */
  25. #define HAL_TX_NUM_RESERVED_BANKS 1
  26. enum hal_be_tx_ret_buf_manager {
  27. HAL_BE_WBM_SW0_BM_ID = 5,
  28. HAL_BE_WBM_SW1_BM_ID = 6,
  29. HAL_BE_WBM_SW2_BM_ID = 7,
  30. HAL_BE_WBM_SW3_BM_ID = 8,
  31. HAL_BE_WBM_SW4_BM_ID = 9,
  32. HAL_BE_WBM_SW5_BM_ID = 10,
  33. HAL_BE_WBM_SW6_BM_ID = 11,
  34. };
  35. enum hal_tx_mcast_ctrl {
  36. /* mcast traffic exceptioned to FW
  37. * valid only for AP VAP default for AP
  38. */
  39. HAL_TX_MCAST_CTRL_FW_EXCEPTION = 0,
  40. /* mcast traffic dropped in TCL*/
  41. HAL_TX_MCAST_CTRL_DROP,
  42. /* MEC notification are enabled
  43. * valid only for client VAP
  44. */
  45. HAL_TX_MCAST_CTRL_MEC_NOTIFY,
  46. /* no special routing for mcast
  47. * valid for client vap when index search is enabled
  48. */
  49. HAL_TX_MCAST_CTRL_NO_SPECIAL,
  50. };
  51. /**
  52. * enum hal_tx_vdev_mismatch_notify
  53. * @HAL_TX_VDEV_MISMATCH_TQM_NOTIFY: vdev mismatch exception routed to TQM
  54. * @HAL_TX_VDEV_MISMATCH_FW_NOTIFY: vdev mismatch exception routed to FW
  55. */
  56. enum hal_tx_vdev_mismatch_notify {
  57. HAL_TX_VDEV_MISMATCH_TQM_NOTIFY = 0,
  58. HAL_TX_VDEV_MISMATCH_FW_NOTIFY,
  59. };
  60. /*---------------------------------------------------------------------------
  61. * Structures
  62. * ---------------------------------------------------------------------------
  63. */
  64. /**
  65. * struct hal_tx_bank_config - SW config bank params
  66. * @epd: EPD indication flag
  67. * @encap_type: encapsulation type
  68. * @encrypt_type: encrypt type
  69. * @src_buffer_swap: big-endia switch for packet buffer
  70. * @link_meta_swap: big-endian switch for link metadata
  71. * @index_lookup_enable: Enabel index lookup
  72. * @addrx_en: Address-X search
  73. * @addry_en: Address-Y search
  74. * @mesh_enable:mesh enable flag
  75. * @vdev_id_check_en: vdev id check
  76. * @pmac_id: mac id
  77. * @mcast_pkt_ctrl: mulitcast packet control
  78. * @val: value representing bank config
  79. */
  80. union hal_tx_bank_config {
  81. struct {
  82. uint32_t epd:1,
  83. encap_type:2,
  84. encrypt_type:4,
  85. src_buffer_swap:1,
  86. link_meta_swap:1,
  87. index_lookup_enable:1,
  88. addrx_en:1,
  89. addry_en:1,
  90. mesh_enable:2,
  91. vdev_id_check_en:1,
  92. pmac_id:2,
  93. mcast_pkt_ctrl:2,
  94. dscp_tid_map_id:6,
  95. reserved:7;
  96. };
  97. uint32_t val;
  98. };
  99. /**
  100. * struct hal_tx_cmn_config_ppe - SW config exception related parameters
  101. * @drop_prec_err - Exception drop_prec errors.
  102. * @fake_mac_hdr - Exception fake mac header.
  103. * @cpu_code_inv - Exception cpu code invalid.
  104. * @data_buff_err - Exception buffer length/offset erorors.
  105. * @l3_l4_err - Exception m3_l4 checksum errors
  106. * @data_offset_max - Maximum data offset allowed.
  107. * @data_len_max - Maximum data length allowed.
  108. */
  109. union hal_tx_cmn_config_ppe {
  110. struct {
  111. uint32_t drop_prec_err:1,
  112. fake_mac_hdr:1,
  113. cpu_code_inv:1,
  114. data_buff_err:1,
  115. l3_l4_err:1,
  116. data_offset_max:12,
  117. data_len_max:14;
  118. };
  119. uint32_t val;
  120. };
  121. /**
  122. * hal_tx_ppe_vp_config - SW config PPE VP table
  123. * @vp_num - Virtual port number
  124. * @pmac_id - Lmac ID
  125. * @bank_id: Bank ID correspondig to this I/F.
  126. * @vdev_id: VDEV ID of the I/F.
  127. * @search_idx_reg_num: Register number of this SI.
  128. * @use_ppe_int_pri: Use the PPE INT_PRI to TID table
  129. * @to_fw: Use FW
  130. * @drop_prec_enable: Enable precendance drop.
  131. */
  132. union hal_tx_ppe_vp_config {
  133. struct {
  134. uint32_t vp_num:8,
  135. pmac_id:2,
  136. bank_id:6,
  137. vdev_id:8,
  138. search_idx_reg_num:3,
  139. use_ppe_int_pri:1,
  140. to_fw:1,
  141. drop_prec_enable:1;
  142. };
  143. uint32_t val;
  144. };
  145. /**
  146. * hal_tx_cmn_ppe_idx_map_config: Use ppe index mapping table
  147. * @search_idx: Search index
  148. * @cache_set: Cache set number
  149. */
  150. union hal_tx_ppe_idx_map_config {
  151. struct {
  152. uint32_t search_idx:20,
  153. cache_set:4;
  154. };
  155. uint32_t val;
  156. };
  157. /**
  158. * hal_tx_ppe_pri2tid_map0_config : Configure ppe INT_PRI to tid map
  159. * @int_pri0: INT_PRI_0
  160. * @int_pri1: INT_PRI_1
  161. * @int_pri2: INT_PRI_2
  162. * @int_pri3: INT_PRI_3
  163. * @int_pri4: INT_PRI_4
  164. * @int_pri5: INT_PRI_5
  165. * @int_pri6: INT_PRI_6
  166. * @int_pri7: INT_PRI_7
  167. * @int_pri8: INT_PRI_8
  168. * @int_pri9: INT_PRI_9
  169. */
  170. union hal_tx_ppe_pri2tid_map0_config {
  171. struct {
  172. uint32_t int_pri0:3,
  173. int_pri1:3,
  174. int_pri2:3,
  175. int_pri3:3,
  176. int_pri4:3,
  177. int_pri5:3,
  178. int_pri6:3,
  179. int_pri7:3,
  180. int_pri8:3,
  181. int_pri9:3;
  182. };
  183. uint32_t val;
  184. };
  185. /**
  186. * hal_tx_ppe_pri2tid_map1_config : Configure ppe INT_PRI to tid map
  187. * @int_pri0: INT_PRI_10
  188. * @int_pri1: INT_PRI_11
  189. * @int_pri2: INT_PRI_12
  190. * @int_pri3: INT_PRI_13
  191. * @int_pri4: INT_PRI_14
  192. * @int_pri5: INT_PRI_15
  193. */
  194. union hal_tx_ppe_pri2tid_map1_config {
  195. struct {
  196. uint32_t int_pri10:3,
  197. int_pri11:3,
  198. int_pri12:3,
  199. int_pri13:3,
  200. int_pri14:3,
  201. int_pri15:3;
  202. };
  203. uint32_t val;
  204. };
  205. /*---------------------------------------------------------------------------
  206. * Function declarations and documentation
  207. * ---------------------------------------------------------------------------
  208. */
  209. /*---------------------------------------------------------------------------
  210. * TCL Descriptor accessor APIs
  211. *---------------------------------------------------------------------------
  212. */
  213. /**
  214. * hal_tx_desc_set_buf_length - Set Data length in bytes in Tx Descriptor
  215. * @desc: Handle to Tx Descriptor
  216. * @data_length: MSDU length in case of direct descriptor.
  217. * Length of link extension descriptor in case of Link extension
  218. * descriptor.Includes the length of Metadata
  219. * Return: None
  220. */
  221. static inline void hal_tx_desc_set_buf_length(void *desc,
  222. uint16_t data_length)
  223. {
  224. HAL_SET_FLD(desc, TCL_DATA_CMD, DATA_LENGTH) |=
  225. HAL_TX_SM(TCL_DATA_CMD, DATA_LENGTH, data_length);
  226. }
  227. /**
  228. * hal_tx_desc_set_buf_offset - Sets Packet Offset field in Tx descriptor
  229. * @desc: Handle to Tx Descriptor
  230. * @offset: Packet offset from Metadata in case of direct buffer descriptor.
  231. *
  232. * Return: void
  233. */
  234. static inline void hal_tx_desc_set_buf_offset(void *desc,
  235. uint8_t offset)
  236. {
  237. HAL_SET_FLD(desc, TCL_DATA_CMD, PACKET_OFFSET) |=
  238. HAL_TX_SM(TCL_DATA_CMD, PACKET_OFFSET, offset);
  239. }
  240. /**
  241. * hal_tx_desc_set_l4_checksum_en - Set TCP/IP checksum enable flags
  242. * Tx Descriptor for MSDU_buffer type
  243. * @desc: Handle to Tx Descriptor
  244. * @en: UDP/TCP over ipv4/ipv6 checksum enable flags (5 bits)
  245. *
  246. * Return: void
  247. */
  248. static inline void hal_tx_desc_set_l4_checksum_en(void *desc,
  249. uint8_t en)
  250. {
  251. HAL_SET_FLD(desc, TCL_DATA_CMD, IPV4_CHECKSUM_EN) |=
  252. (HAL_TX_SM(TCL_DATA_CMD, UDP_OVER_IPV4_CHECKSUM_EN, en) |
  253. HAL_TX_SM(TCL_DATA_CMD, UDP_OVER_IPV6_CHECKSUM_EN, en) |
  254. HAL_TX_SM(TCL_DATA_CMD, TCP_OVER_IPV4_CHECKSUM_EN, en) |
  255. HAL_TX_SM(TCL_DATA_CMD, TCP_OVER_IPV6_CHECKSUM_EN, en));
  256. }
  257. /**
  258. * hal_tx_desc_set_l3_checksum_en - Set IPv4 checksum enable flag in
  259. * Tx Descriptor for MSDU_buffer type
  260. * @desc: Handle to Tx Descriptor
  261. * @checksum_en_flags: ipv4 checksum enable flags
  262. *
  263. * Return: void
  264. */
  265. static inline void hal_tx_desc_set_l3_checksum_en(void *desc,
  266. uint8_t en)
  267. {
  268. HAL_SET_FLD(desc, TCL_DATA_CMD, IPV4_CHECKSUM_EN) |=
  269. HAL_TX_SM(TCL_DATA_CMD, IPV4_CHECKSUM_EN, en);
  270. }
  271. /**
  272. * hal_tx_desc_set_fw_metadata- Sets the metadata that is part of TCL descriptor
  273. * @desc:Handle to Tx Descriptor
  274. * @metadata: Metadata to be sent to Firmware
  275. *
  276. * Return: void
  277. */
  278. static inline void hal_tx_desc_set_fw_metadata(void *desc,
  279. uint16_t metadata)
  280. {
  281. HAL_SET_FLD(desc, TCL_DATA_CMD, TCL_CMD_NUMBER) |=
  282. HAL_TX_SM(TCL_DATA_CMD, TCL_CMD_NUMBER, metadata);
  283. }
  284. /**
  285. * hal_tx_desc_set_to_fw - Set To_FW bit in Tx Descriptor.
  286. * @desc:Handle to Tx Descriptor
  287. * @to_fw: if set, Forward packet to FW along with classification result
  288. *
  289. * Return: void
  290. */
  291. static inline void hal_tx_desc_set_to_fw(void *desc, uint8_t to_fw)
  292. {
  293. HAL_SET_FLD(desc, TCL_DATA_CMD, TO_FW) |=
  294. HAL_TX_SM(TCL_DATA_CMD, TO_FW, to_fw);
  295. }
  296. /**
  297. * hal_tx_desc_set_hlos_tid - Set the TID value (override DSCP/PCP fields in
  298. * frame) to be used for Tx Frame
  299. * @desc: Handle to Tx Descriptor
  300. * @hlos_tid: HLOS TID
  301. *
  302. * Return: void
  303. */
  304. static inline void hal_tx_desc_set_hlos_tid(void *desc,
  305. uint8_t hlos_tid)
  306. {
  307. HAL_SET_FLD(desc, TCL_DATA_CMD, HLOS_TID) |=
  308. HAL_TX_SM(TCL_DATA_CMD, HLOS_TID, hlos_tid);
  309. HAL_SET_FLD(desc, TCL_DATA_CMD, HLOS_TID_OVERWRITE) |=
  310. HAL_TX_SM(TCL_DATA_CMD, HLOS_TID_OVERWRITE, 1);
  311. }
  312. /**
  313. * hal_tx_desc_sync - Commit the descriptor to Hardware
  314. * @hal_tx_des_cached: Cached descriptor that software maintains
  315. * @hw_desc: Hardware descriptor to be updated
  316. */
  317. static inline void hal_tx_desc_sync(void *hal_tx_desc_cached,
  318. void *hw_desc)
  319. {
  320. qdf_mem_copy(hw_desc, hal_tx_desc_cached, HAL_TX_DESC_LEN_BYTES);
  321. }
  322. /**
  323. * hal_tx_desc_set_vdev_id - set vdev id to the descriptor to Hardware
  324. * @hal_tx_des_cached: Cached descriptor that software maintains
  325. * @vdev_id: vdev id
  326. */
  327. static inline void hal_tx_desc_set_vdev_id(void *desc, uint8_t vdev_id)
  328. {
  329. HAL_SET_FLD(desc, TCL_DATA_CMD, VDEV_ID) |=
  330. HAL_TX_SM(TCL_DATA_CMD, VDEV_ID, vdev_id);
  331. }
  332. /**
  333. * hal_tx_desc_set_bank_id - set bank id to the descriptor to Hardware
  334. * @hal_tx_des_cached: Cached descriptor that software maintains
  335. * @bank_id: bank id
  336. */
  337. static inline void hal_tx_desc_set_bank_id(void *desc, uint8_t bank_id)
  338. {
  339. HAL_SET_FLD(desc, TCL_DATA_CMD, BANK_ID) |=
  340. HAL_TX_SM(TCL_DATA_CMD, BANK_ID, bank_id);
  341. }
  342. /**
  343. * hal_tx_desc_set_tcl_cmd_type - set tcl command type to the descriptor
  344. * to Hardware
  345. * @hal_tx_des_cached: Cached descriptor that software maintains
  346. * @tcl_cmd_type: tcl command type
  347. */
  348. static inline void
  349. hal_tx_desc_set_tcl_cmd_type(void *desc, uint8_t tcl_cmd_type)
  350. {
  351. HAL_SET_FLD(desc, TCL_DATA_CMD, TCL_CMD_TYPE) |=
  352. HAL_TX_SM(TCL_DATA_CMD, TCL_CMD_TYPE, tcl_cmd_type);
  353. }
  354. /**
  355. * hal_tx_desc_set_lmac_id_be - set lmac id to the descriptor to Hardware
  356. * @hal_soc_hdl: hal soc handle
  357. * @hal_tx_des_cached: Cached descriptor that software maintains
  358. * @lmac_id: lmac id
  359. */
  360. static inline void
  361. hal_tx_desc_set_lmac_id_be(hal_soc_handle_t hal_soc_hdl, void *desc,
  362. uint8_t lmac_id)
  363. {
  364. HAL_SET_FLD(desc, TCL_DATA_CMD, PMAC_ID) |=
  365. HAL_TX_SM(TCL_DATA_CMD, PMAC_ID, lmac_id);
  366. }
  367. /**
  368. * hal_tx_desc_set_search_index_be - set search index to the
  369. * descriptor to Hardware
  370. * @hal_soc_hdl: hal soc handle
  371. * @hal_tx_des_cached: Cached descriptor that software maintains
  372. * @search_index: search index
  373. */
  374. static inline void
  375. hal_tx_desc_set_search_index_be(hal_soc_handle_t hal_soc_hdl, void *desc,
  376. uint32_t search_index)
  377. {
  378. HAL_SET_FLD(desc, TCL_DATA_CMD, SEARCH_INDEX) |=
  379. HAL_TX_SM(TCL_DATA_CMD, SEARCH_INDEX, search_index);
  380. }
  381. /**
  382. * hal_tx_desc_set_cache_set_num - set cache set num to the
  383. * descriptor to Hardware
  384. * @hal_soc_hdl: hal soc handle
  385. * @hal_tx_des_cached: Cached descriptor that software maintains
  386. * @cache_num: cache number
  387. */
  388. static inline void
  389. hal_tx_desc_set_cache_set_num(hal_soc_handle_t hal_soc_hdl, void *desc,
  390. uint8_t cache_num)
  391. {
  392. HAL_SET_FLD(desc, TCL_DATA_CMD, CACHE_SET_NUM) |=
  393. HAL_TX_SM(TCL_DATA_CMD, CACHE_SET_NUM, cache_num);
  394. }
  395. /*---------------------------------------------------------------------------
  396. * WBM Descriptor accessor APIs for Tx completions
  397. * ---------------------------------------------------------------------------
  398. */
  399. /**
  400. * hal_tx_get_wbm_sw0_bm_id() - Get the BM ID for first tx completion ring
  401. *
  402. * Return: BM ID for first tx completion ring
  403. */
  404. static inline uint32_t hal_tx_get_wbm_sw0_bm_id(void)
  405. {
  406. return HAL_BE_WBM_SW0_BM_ID;
  407. }
  408. /**
  409. * hal_tx_comp_get_desc_id() - Get TX descriptor id within comp descriptor
  410. * @hal_desc: completion ring descriptor pointer
  411. *
  412. * This function will tx descriptor id, cookie, within hardware completion
  413. * descriptor. For cases when cookie conversion is disabled, the sw_cookie
  414. * is present in the 2nd DWORD.
  415. *
  416. * Return: cookie
  417. */
  418. static inline uint32_t hal_tx_comp_get_desc_id(void *hal_desc)
  419. {
  420. uint32_t comp_desc =
  421. *(uint32_t *)(((uint8_t *)hal_desc) +
  422. BUFFER_ADDR_INFO_SW_BUFFER_COOKIE_OFFSET);
  423. /* Cookie is placed on 2nd word */
  424. return (comp_desc & BUFFER_ADDR_INFO_SW_BUFFER_COOKIE_MASK) >>
  425. BUFFER_ADDR_INFO_SW_BUFFER_COOKIE_LSB;
  426. }
  427. /**
  428. * hal_tx_comp_get_paddr() - Get paddr within comp descriptor
  429. * @hal_desc: completion ring descriptor pointer
  430. *
  431. * This function will get buffer physical address within hardware completion
  432. * descriptor
  433. *
  434. * Return: Buffer physical address
  435. */
  436. static inline qdf_dma_addr_t hal_tx_comp_get_paddr(void *hal_desc)
  437. {
  438. uint32_t paddr_lo;
  439. uint32_t paddr_hi;
  440. paddr_lo = *(uint32_t *)(((uint8_t *)hal_desc) +
  441. BUFFER_ADDR_INFO_BUFFER_ADDR_31_0_OFFSET);
  442. paddr_hi = *(uint32_t *)(((uint8_t *)hal_desc) +
  443. BUFFER_ADDR_INFO_BUFFER_ADDR_39_32_OFFSET);
  444. paddr_hi = (paddr_hi & BUFFER_ADDR_INFO_BUFFER_ADDR_39_32_MASK) >>
  445. BUFFER_ADDR_INFO_BUFFER_ADDR_39_32_LSB;
  446. return (qdf_dma_addr_t)(paddr_lo | (((uint64_t)paddr_hi) << 32));
  447. }
  448. #ifdef DP_HW_COOKIE_CONVERT_EXCEPTION
  449. /* HW set dowrd-2 bit30 to 1 if HW CC is done */
  450. #define HAL_WBM2SW_COMPLETION_RING_TX_CC_DONE_OFFSET 0x8
  451. #define HAL_WBM2SW_COMPLETION_RING_TX_CC_DONE_MASK 0x40000000
  452. #define HAL_WBM2SW_COMPLETION_RING_TX_CC_DONE_LSB 0x1E
  453. /**
  454. * hal_tx_comp_get_cookie_convert_done() - Get cookie conversion done flag
  455. * @hal_desc: completion ring descriptor pointer
  456. *
  457. * This function will get the bit value that indicate HW cookie
  458. * conversion done or not
  459. *
  460. * Return: 1 - HW cookie conversion done, 0 - not
  461. */
  462. static inline uint8_t hal_tx_comp_get_cookie_convert_done(void *hal_desc)
  463. {
  464. return HAL_TX_DESC_GET(hal_desc, HAL_WBM2SW_COMPLETION_RING_TX,
  465. CC_DONE);
  466. }
  467. #endif
  468. /**
  469. * hal_tx_comp_get_desc_va() - Get Desc virtual address within completion Desc
  470. * @hal_desc: completion ring descriptor pointer
  471. *
  472. * This function will get the TX Desc virtual address
  473. *
  474. * Return: TX desc virtual address
  475. */
  476. static inline uintptr_t hal_tx_comp_get_desc_va(void *hal_desc)
  477. {
  478. uint64_t va_from_desc;
  479. va_from_desc = HAL_TX_DESC_GET(hal_desc,
  480. WBM2SW_COMPLETION_RING_TX,
  481. BUFFER_VIRT_ADDR_31_0) |
  482. (((uint64_t)HAL_TX_DESC_GET(
  483. hal_desc,
  484. WBM2SW_COMPLETION_RING_TX,
  485. BUFFER_VIRT_ADDR_63_32)) << 32);
  486. return (uintptr_t)va_from_desc;
  487. }
  488. /*---------------------------------------------------------------------------
  489. * TX BANK register accessor APIs
  490. * ---------------------------------------------------------------------------
  491. */
  492. /**
  493. * hal_tx_get_num_tcl_banks() - Get number of banks for target
  494. *
  495. * Return: None
  496. */
  497. static inline uint8_t
  498. hal_tx_get_num_tcl_banks(hal_soc_handle_t hal_soc_hdl)
  499. {
  500. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  501. int hal_banks = 0;
  502. if (hal_soc->ops->hal_tx_get_num_tcl_banks) {
  503. hal_banks = hal_soc->ops->hal_tx_get_num_tcl_banks();
  504. hal_banks -= HAL_TX_NUM_RESERVED_BANKS;
  505. hal_banks = (hal_banks < 0) ? 0 : hal_banks;
  506. }
  507. return hal_banks;
  508. }
  509. /**
  510. * hal_tx_populate_bank_register() - populate the bank register with
  511. * the software configs.
  512. * @soc: HAL soc handle
  513. * @config: bank config
  514. * @bank_id: bank id to be configured
  515. *
  516. * Returns: None
  517. */
  518. #ifdef HWIO_TCL_R0_SW_CONFIG_BANK_n_MCAST_PACKET_CTRL_SHFT
  519. static inline void
  520. hal_tx_populate_bank_register(hal_soc_handle_t hal_soc_hdl,
  521. union hal_tx_bank_config *config,
  522. uint8_t bank_id)
  523. {
  524. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  525. uint32_t reg_addr, reg_val = 0;
  526. reg_addr = HWIO_TCL_R0_SW_CONFIG_BANK_n_ADDR(MAC_TCL_REG_REG_BASE,
  527. bank_id);
  528. reg_val |= (config->epd << HWIO_TCL_R0_SW_CONFIG_BANK_n_EPD_SHFT);
  529. reg_val |= (config->encap_type <<
  530. HWIO_TCL_R0_SW_CONFIG_BANK_n_ENCAP_TYPE_SHFT);
  531. reg_val |= (config->encrypt_type <<
  532. HWIO_TCL_R0_SW_CONFIG_BANK_n_ENCRYPT_TYPE_SHFT);
  533. reg_val |= (config->src_buffer_swap <<
  534. HWIO_TCL_R0_SW_CONFIG_BANK_n_SRC_BUFFER_SWAP_SHFT);
  535. reg_val |= (config->link_meta_swap <<
  536. HWIO_TCL_R0_SW_CONFIG_BANK_n_LINK_META_SWAP_SHFT);
  537. reg_val |= (config->index_lookup_enable <<
  538. HWIO_TCL_R0_SW_CONFIG_BANK_n_INDEX_LOOKUP_ENABLE_SHFT);
  539. reg_val |= (config->addrx_en <<
  540. HWIO_TCL_R0_SW_CONFIG_BANK_n_ADDRX_EN_SHFT);
  541. reg_val |= (config->addry_en <<
  542. HWIO_TCL_R0_SW_CONFIG_BANK_n_ADDRY_EN_SHFT);
  543. reg_val |= (config->mesh_enable <<
  544. HWIO_TCL_R0_SW_CONFIG_BANK_n_MESH_ENABLE_SHFT);
  545. reg_val |= (config->vdev_id_check_en <<
  546. HWIO_TCL_R0_SW_CONFIG_BANK_n_VDEV_ID_CHECK_EN_SHFT);
  547. reg_val |= (config->pmac_id <<
  548. HWIO_TCL_R0_SW_CONFIG_BANK_n_PMAC_ID_SHFT);
  549. reg_val |= (config->mcast_pkt_ctrl <<
  550. HWIO_TCL_R0_SW_CONFIG_BANK_n_MCAST_PACKET_CTRL_SHFT);
  551. HAL_REG_WRITE(hal_soc, reg_addr, reg_val);
  552. }
  553. #else
  554. static inline void
  555. hal_tx_populate_bank_register(hal_soc_handle_t hal_soc_hdl,
  556. union hal_tx_bank_config *config,
  557. uint8_t bank_id)
  558. {
  559. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  560. uint32_t reg_addr, reg_val = 0;
  561. reg_addr = HWIO_TCL_R0_SW_CONFIG_BANK_n_ADDR(MAC_TCL_REG_REG_BASE,
  562. bank_id);
  563. reg_val |= (config->epd << HWIO_TCL_R0_SW_CONFIG_BANK_n_EPD_SHFT);
  564. reg_val |= (config->encap_type <<
  565. HWIO_TCL_R0_SW_CONFIG_BANK_n_ENCAP_TYPE_SHFT);
  566. reg_val |= (config->encrypt_type <<
  567. HWIO_TCL_R0_SW_CONFIG_BANK_n_ENCRYPT_TYPE_SHFT);
  568. reg_val |= (config->src_buffer_swap <<
  569. HWIO_TCL_R0_SW_CONFIG_BANK_n_SRC_BUFFER_SWAP_SHFT);
  570. reg_val |= (config->link_meta_swap <<
  571. HWIO_TCL_R0_SW_CONFIG_BANK_n_LINK_META_SWAP_SHFT);
  572. reg_val |= (config->index_lookup_enable <<
  573. HWIO_TCL_R0_SW_CONFIG_BANK_n_INDEX_LOOKUP_ENABLE_SHFT);
  574. reg_val |= (config->addrx_en <<
  575. HWIO_TCL_R0_SW_CONFIG_BANK_n_ADDRX_EN_SHFT);
  576. reg_val |= (config->addry_en <<
  577. HWIO_TCL_R0_SW_CONFIG_BANK_n_ADDRY_EN_SHFT);
  578. reg_val |= (config->mesh_enable <<
  579. HWIO_TCL_R0_SW_CONFIG_BANK_n_MESH_ENABLE_SHFT);
  580. reg_val |= (config->vdev_id_check_en <<
  581. HWIO_TCL_R0_SW_CONFIG_BANK_n_VDEV_ID_CHECK_EN_SHFT);
  582. reg_val |= (config->pmac_id <<
  583. HWIO_TCL_R0_SW_CONFIG_BANK_n_PMAC_ID_SHFT);
  584. reg_val |= (config->dscp_tid_map_id <<
  585. HWIO_TCL_R0_SW_CONFIG_BANK_n_DSCP_TID_TABLE_NUM_SHFT);
  586. HAL_REG_WRITE(hal_soc, reg_addr, reg_val);
  587. }
  588. #endif
  589. #ifdef DP_TX_IMPLICIT_RBM_MAPPING
  590. #define RBM_MAPPING_BMSK HWIO_TCL_R0_RBM_MAPPING0_SW2TCL1_RING_BMSK
  591. #define RBM_MAPPING_SHFT HWIO_TCL_R0_RBM_MAPPING0_SW2TCL2_RING_SHFT
  592. #define RBM_PPE2TCL_OFFSET \
  593. (HWIO_TCL_R0_RBM_MAPPING0_PPE2TCL1_RING_SHFT >> 2)
  594. #define RBM_TCL_CMD_CREDIT_OFFSET \
  595. (HWIO_TCL_R0_RBM_MAPPING0_SW2TCL_CREDIT_RING_SHFT >> 2)
  596. /**
  597. * hal_tx_config_rbm_mapping_be() - Update return buffer manager ring id
  598. * @hal_soc: HAL SoC context
  599. * @hal_ring_hdl: Source ring pointer
  600. * @rbm_id: return buffer manager ring id
  601. *
  602. * Return: void
  603. */
  604. static inline void
  605. hal_tx_config_rbm_mapping_be(hal_soc_handle_t hal_soc_hdl,
  606. hal_ring_handle_t hal_ring_hdl,
  607. uint8_t rbm_id)
  608. {
  609. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  610. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  611. uint32_t reg_addr = 0;
  612. uint32_t reg_val = 0;
  613. uint32_t val = 0;
  614. uint8_t ring_num;
  615. enum hal_ring_type ring_type;
  616. ring_type = srng->ring_type;
  617. ring_num = hal_soc->hw_srng_table[ring_type].start_ring_id;
  618. ring_num = srng->ring_id - ring_num;
  619. reg_addr = HWIO_TCL_R0_RBM_MAPPING0_ADDR(MAC_TCL_REG_REG_BASE);
  620. if (ring_type == PPE2TCL)
  621. ring_num = ring_num + RBM_PPE2TCL_OFFSET;
  622. else if (ring_type == TCL_CMD_CREDIT)
  623. ring_num = ring_num + RBM_TCL_CMD_CREDIT_OFFSET;
  624. /* get current value stored in register address */
  625. val = HAL_REG_READ(hal_soc, reg_addr);
  626. /* mask out other stored value */
  627. val &= (~(RBM_MAPPING_BMSK << (RBM_MAPPING_SHFT * ring_num)));
  628. reg_val = val | ((RBM_MAPPING_BMSK & rbm_id) <<
  629. (RBM_MAPPING_SHFT * ring_num));
  630. /* write rbm mapped value to register address */
  631. HAL_REG_WRITE(hal_soc, reg_addr, reg_val);
  632. }
  633. #else
  634. static inline void
  635. hal_tx_config_rbm_mapping_be(hal_soc_handle_t hal_soc_hdl,
  636. hal_ring_handle_t hal_ring_hdl,
  637. uint8_t rbm_id)
  638. {
  639. }
  640. #endif
  641. /**
  642. * hal_tx_desc_set_buf_addr_be - Fill Buffer Address information in Tx Desc
  643. * @desc: Handle to Tx Descriptor
  644. * @paddr: Physical Address
  645. * @pool_id: Return Buffer Manager ID
  646. * @desc_id: Descriptor ID
  647. * @type: 0 - Address points to a MSDU buffer
  648. * 1 - Address points to MSDU extension descriptor
  649. *
  650. * Return: void
  651. */
  652. #ifdef DP_TX_IMPLICIT_RBM_MAPPING
  653. static inline void
  654. hal_tx_desc_set_buf_addr_be(hal_soc_handle_t hal_soc_hdl, void *desc,
  655. dma_addr_t paddr, uint8_t rbm_id,
  656. uint32_t desc_id, uint8_t type)
  657. {
  658. /* Set buffer_addr_info.buffer_addr_31_0 */
  659. HAL_SET_FLD(desc, TCL_DATA_CMD,
  660. BUF_ADDR_INFO_BUFFER_ADDR_31_0) =
  661. HAL_TX_SM(TCL_DATA_CMD, BUF_ADDR_INFO_BUFFER_ADDR_31_0, paddr);
  662. /* Set buffer_addr_info.buffer_addr_39_32 */
  663. HAL_SET_FLD(desc, TCL_DATA_CMD,
  664. BUF_ADDR_INFO_BUFFER_ADDR_39_32) |=
  665. HAL_TX_SM(TCL_DATA_CMD, BUF_ADDR_INFO_BUFFER_ADDR_39_32,
  666. (((uint64_t)paddr) >> 32));
  667. /* Set buffer_addr_info.sw_buffer_cookie = desc_id */
  668. HAL_SET_FLD(desc, TCL_DATA_CMD,
  669. BUF_ADDR_INFO_SW_BUFFER_COOKIE) |=
  670. HAL_TX_SM(TCL_DATA_CMD, BUF_ADDR_INFO_SW_BUFFER_COOKIE,
  671. desc_id);
  672. /* Set Buffer or Ext Descriptor Type */
  673. HAL_SET_FLD(desc, TCL_DATA_CMD,
  674. BUF_OR_EXT_DESC_TYPE) |=
  675. HAL_TX_SM(TCL_DATA_CMD, BUF_OR_EXT_DESC_TYPE, type);
  676. }
  677. #else
  678. static inline void
  679. hal_tx_desc_set_buf_addr_be(hal_soc_handle_t hal_soc_hdl, void *desc,
  680. dma_addr_t paddr, uint8_t rbm_id,
  681. uint32_t desc_id, uint8_t type)
  682. {
  683. /* Set buffer_addr_info.buffer_addr_31_0 */
  684. HAL_SET_FLD(desc, TCL_DATA_CMD,
  685. BUF_ADDR_INFO_BUFFER_ADDR_31_0) =
  686. HAL_TX_SM(TCL_DATA_CMD, BUF_ADDR_INFO_BUFFER_ADDR_31_0, paddr);
  687. /* Set buffer_addr_info.buffer_addr_39_32 */
  688. HAL_SET_FLD(desc, TCL_DATA_CMD,
  689. BUF_ADDR_INFO_BUFFER_ADDR_39_32) |=
  690. HAL_TX_SM(TCL_DATA_CMD, BUF_ADDR_INFO_BUFFER_ADDR_39_32,
  691. (((uint64_t)paddr) >> 32));
  692. /* Set buffer_addr_info.return_buffer_manager = rbm id */
  693. HAL_SET_FLD(desc, TCL_DATA_CMD,
  694. BUF_ADDR_INFO_RETURN_BUFFER_MANAGER) |=
  695. HAL_TX_SM(TCL_DATA_CMD,
  696. BUF_ADDR_INFO_RETURN_BUFFER_MANAGER, rbm_id);
  697. /* Set buffer_addr_info.sw_buffer_cookie = desc_id */
  698. HAL_SET_FLD(desc, TCL_DATA_CMD,
  699. BUF_ADDR_INFO_SW_BUFFER_COOKIE) |=
  700. HAL_TX_SM(TCL_DATA_CMD, BUF_ADDR_INFO_SW_BUFFER_COOKIE,
  701. desc_id);
  702. /* Set Buffer or Ext Descriptor Type */
  703. HAL_SET_FLD(desc, TCL_DATA_CMD,
  704. BUF_OR_EXT_DESC_TYPE) |=
  705. HAL_TX_SM(TCL_DATA_CMD, BUF_OR_EXT_DESC_TYPE, type);
  706. }
  707. #endif
  708. #ifdef HWIO_TCL_R0_VDEV_MCAST_PACKET_CTRL_MAP_n_VAL_SHFT
  709. #define HAL_TCL_VDEV_MCAST_PACKET_CTRL_REG_ID(vdev_id) (vdev_id >> 0x4)
  710. #define HAL_TCL_VDEV_MCAST_PACKET_CTRL_INDEX_IN_REG(vdev_id) (vdev_id & 0xF)
  711. #define HAL_TCL_VDEV_MCAST_PACKET_CTRL_MASK 0x3
  712. #define HAL_TCL_VDEV_MCAST_PACKET_CTRL_SHIFT 0x2
  713. /**
  714. * hal_tx_vdev_mcast_ctrl_set - set mcast_ctrl value
  715. * @hal_soc: HAL SoC context
  716. * @mcast_ctrl_val: mcast ctrl value for this VAP
  717. *
  718. * Return: void
  719. */
  720. static inline void
  721. hal_tx_vdev_mcast_ctrl_set(hal_soc_handle_t hal_soc_hdl,
  722. uint8_t vdev_id,
  723. uint8_t mcast_ctrl_val)
  724. {
  725. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  726. uint32_t reg_addr, reg_val = 0;
  727. uint32_t val;
  728. uint8_t reg_idx = HAL_TCL_VDEV_MCAST_PACKET_CTRL_REG_ID(vdev_id);
  729. uint8_t index_in_reg =
  730. HAL_TCL_VDEV_MCAST_PACKET_CTRL_INDEX_IN_REG(vdev_id);
  731. reg_addr =
  732. HWIO_TCL_R0_VDEV_MCAST_PACKET_CTRL_MAP_n_ADDR(MAC_TCL_REG_REG_BASE,
  733. reg_idx);
  734. val = HAL_REG_READ(hal_soc, reg_addr);
  735. /* mask out other stored value */
  736. val &= (~(HAL_TCL_VDEV_MCAST_PACKET_CTRL_MASK <<
  737. (HAL_TCL_VDEV_MCAST_PACKET_CTRL_SHIFT * index_in_reg)));
  738. reg_val = val |
  739. ((HAL_TCL_VDEV_MCAST_PACKET_CTRL_MASK & mcast_ctrl_val) <<
  740. (HAL_TCL_VDEV_MCAST_PACKET_CTRL_SHIFT * index_in_reg));
  741. HAL_REG_WRITE(hal_soc, reg_addr, reg_val);
  742. }
  743. #else
  744. static inline void
  745. hal_tx_vdev_mcast_ctrl_set(hal_soc_handle_t hal_soc_hdl,
  746. uint8_t vdev_id,
  747. uint8_t mcast_ctrl_val)
  748. {
  749. }
  750. #endif
  751. /**
  752. * hal_tx_vdev_mismatch_routing_set - set vdev mismatch exception routing
  753. * @hal_soc: HAL SoC context
  754. * @config: HAL_TX_VDEV_MISMATCH_TQM_NOTIFY - route via TQM
  755. * HAL_TX_VDEV_MISMATCH_FW_NOTIFY - route via FW
  756. *
  757. * Return: void
  758. */
  759. #ifdef HWIO_TCL_R0_CMN_CONFIG_VDEVID_MISMATCH_EXCEPTION_BMSK
  760. static inline void
  761. hal_tx_vdev_mismatch_routing_set(hal_soc_handle_t hal_soc_hdl,
  762. enum hal_tx_vdev_mismatch_notify config)
  763. {
  764. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  765. uint32_t reg_addr, reg_val = 0;
  766. uint32_t val = 0;
  767. reg_addr = HWIO_TCL_R0_CMN_CONFIG_ADDR(MAC_TCL_REG_REG_BASE);
  768. val = HAL_REG_READ(hal_soc, reg_addr);
  769. /* reset the corresponding bits in register */
  770. val &= (~(HWIO_TCL_R0_CMN_CONFIG_VDEVID_MISMATCH_EXCEPTION_BMSK));
  771. /* set config value */
  772. reg_val = val | (config <<
  773. HWIO_TCL_R0_CMN_CONFIG_VDEVID_MISMATCH_EXCEPTION_SHFT);
  774. HAL_REG_WRITE(hal_soc, reg_addr, reg_val);
  775. }
  776. #else
  777. static inline void
  778. hal_tx_vdev_mismatch_routing_set(hal_soc_handle_t hal_soc_hdl,
  779. enum hal_tx_vdev_mismatch_notify config)
  780. {
  781. }
  782. #endif
  783. #endif /* _HAL_BE_TX_H_ */