dp_li_tx.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * Copyright (c) 2016-2021 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. #include "cdp_txrx_cmn_struct.h"
  19. #include "dp_types.h"
  20. #include "dp_tx.h"
  21. #include "dp_li_tx.h"
  22. #include "dp_tx_desc.h"
  23. #include <dp_internal.h>
  24. #include <dp_htt.h>
  25. #include <hal_li_api.h>
  26. #include <hal_li_tx.h>
  27. extern uint8_t sec_type_map[MAX_CDP_SEC_TYPE];
  28. void dp_tx_comp_get_params_from_hal_desc_li(struct dp_soc *soc,
  29. void *tx_comp_hal_desc,
  30. struct dp_tx_desc_s **r_tx_desc)
  31. {
  32. uint8_t pool_id;
  33. uint32_t tx_desc_id;
  34. tx_desc_id = hal_tx_comp_get_desc_id(tx_comp_hal_desc);
  35. pool_id = (tx_desc_id & DP_TX_DESC_ID_POOL_MASK) >>
  36. DP_TX_DESC_ID_POOL_OS;
  37. /* Find Tx descriptor */
  38. *r_tx_desc = dp_tx_desc_find(soc, pool_id,
  39. (tx_desc_id & DP_TX_DESC_ID_PAGE_MASK) >>
  40. DP_TX_DESC_ID_PAGE_OS,
  41. (tx_desc_id & DP_TX_DESC_ID_OFFSET_MASK) >>
  42. DP_TX_DESC_ID_OFFSET_OS);
  43. /* Pool id is not matching. Error */
  44. if ((*r_tx_desc)->pool_id != pool_id) {
  45. dp_tx_comp_alert("Tx Comp pool id %d not matched %d",
  46. pool_id, (*r_tx_desc)->pool_id);
  47. qdf_assert_always(0);
  48. }
  49. (*r_tx_desc)->peer_id = hal_tx_comp_get_peer_id(tx_comp_hal_desc);
  50. }
  51. #ifdef QCA_OL_TX_MULTIQ_SUPPORT
  52. /*
  53. * dp_tx_get_rbm_id()- Get the RBM ID for data transmission completion.
  54. * @dp_soc - DP soc structure pointer
  55. * @ring_id - Transmit Queue/ring_id to be used when XPS is enabled
  56. *
  57. * Return - HAL ring handle
  58. */
  59. #ifdef IPA_OFFLOAD
  60. static inline uint8_t dp_tx_get_rbm_id_li(struct dp_soc *soc,
  61. uint8_t ring_id)
  62. {
  63. return (ring_id + soc->wbm_sw0_bm_id);
  64. }
  65. #else
  66. static inline uint8_t dp_tx_get_rbm_id_li(struct dp_soc *soc,
  67. uint8_t ring_id)
  68. {
  69. return (ring_id ? soc->wbm_sw0_bm_id + (ring_id - 1) :
  70. HAL_WBM_SW2_BM_ID(soc->wbm_sw0_bm_id));
  71. }
  72. #endif
  73. #else
  74. static inline uint8_t dp_tx_get_rbm_id_li(struct dp_soc *soc,
  75. uint8_t ring_id)
  76. {
  77. return (ring_id + soc->wbm_sw0_bm_id);
  78. }
  79. #endif
  80. #if defined(CLEAR_SW2TCL_CONSUMED_DESC)
  81. /**
  82. * dp_tx_clear_consumed_hw_descs - Reset all the consumed Tx ring descs to 0
  83. *
  84. * @soc: DP soc handle
  85. * @hal_ring_hdl: Source ring pointer
  86. *
  87. * Return: void
  88. */
  89. static inline
  90. void dp_tx_clear_consumed_hw_descs(struct dp_soc *soc,
  91. hal_ring_handle_t hal_ring_hdl)
  92. {
  93. void *desc = hal_srng_src_get_next_consumed(soc->hal_soc, hal_ring_hdl);
  94. while (desc) {
  95. hal_tx_desc_clear(desc);
  96. desc = hal_srng_src_get_next_consumed(soc->hal_soc,
  97. hal_ring_hdl);
  98. }
  99. }
  100. #else
  101. static inline
  102. void dp_tx_clear_consumed_hw_descs(struct dp_soc *soc,
  103. hal_ring_handle_t hal_ring_hdl)
  104. {
  105. }
  106. #endif /* CLEAR_SW2TCL_CONSUMED_DESC */
  107. QDF_STATUS
  108. dp_tx_hw_enqueue_li(struct dp_soc *soc, struct dp_vdev *vdev,
  109. struct dp_tx_desc_s *tx_desc, uint16_t fw_metadata,
  110. struct cdp_tx_exception_metadata *tx_exc_metadata,
  111. struct dp_tx_msdu_info_s *msdu_info)
  112. {
  113. void *hal_tx_desc;
  114. uint32_t *hal_tx_desc_cached;
  115. int coalesce = 0;
  116. struct dp_tx_queue *tx_q = &msdu_info->tx_queue;
  117. uint8_t ring_id = tx_q->ring_id & DP_TX_QUEUE_MASK;
  118. uint8_t tid = msdu_info->tid;
  119. /*
  120. * Setting it initialization statically here to avoid
  121. * a memset call jump with qdf_mem_set call
  122. */
  123. uint8_t cached_desc[HAL_TX_DESC_LEN_BYTES] = { 0 };
  124. enum cdp_sec_type sec_type = ((tx_exc_metadata &&
  125. tx_exc_metadata->sec_type != CDP_INVALID_SEC_TYPE) ?
  126. tx_exc_metadata->sec_type : vdev->sec_type);
  127. /* Return Buffer Manager ID */
  128. uint8_t bm_id = dp_tx_get_rbm_id_li(soc, ring_id);
  129. hal_ring_handle_t hal_ring_hdl = NULL;
  130. QDF_STATUS status = QDF_STATUS_E_RESOURCES;
  131. if (!dp_tx_is_desc_id_valid(soc, tx_desc->id)) {
  132. dp_err_rl("Invalid tx desc id:%d", tx_desc->id);
  133. return QDF_STATUS_E_RESOURCES;
  134. }
  135. hal_tx_desc_cached = (void *)cached_desc;
  136. hal_tx_desc_set_buf_addr(soc->hal_soc, hal_tx_desc_cached,
  137. tx_desc->dma_addr, bm_id, tx_desc->id,
  138. (tx_desc->flags & DP_TX_DESC_FLAG_FRAG));
  139. hal_tx_desc_set_lmac_id_li(soc->hal_soc, hal_tx_desc_cached,
  140. vdev->lmac_id);
  141. hal_tx_desc_set_search_type_li(soc->hal_soc, hal_tx_desc_cached,
  142. vdev->search_type);
  143. hal_tx_desc_set_search_index_li(soc->hal_soc, hal_tx_desc_cached,
  144. vdev->bss_ast_idx);
  145. hal_tx_desc_set_dscp_tid_table_id(soc->hal_soc, hal_tx_desc_cached,
  146. vdev->dscp_tid_map_id);
  147. hal_tx_desc_set_encrypt_type(hal_tx_desc_cached,
  148. sec_type_map[sec_type]);
  149. hal_tx_desc_set_cache_set_num(soc->hal_soc, hal_tx_desc_cached,
  150. (vdev->bss_ast_hash & 0xF));
  151. hal_tx_desc_set_fw_metadata(hal_tx_desc_cached, fw_metadata);
  152. hal_tx_desc_set_buf_length(hal_tx_desc_cached, tx_desc->length);
  153. hal_tx_desc_set_buf_offset(hal_tx_desc_cached, tx_desc->pkt_offset);
  154. hal_tx_desc_set_encap_type(hal_tx_desc_cached, tx_desc->tx_encap_type);
  155. hal_tx_desc_set_addr_search_flags(hal_tx_desc_cached,
  156. vdev->hal_desc_addr_search_flags);
  157. if (tx_desc->flags & DP_TX_DESC_FLAG_TO_FW)
  158. hal_tx_desc_set_to_fw(hal_tx_desc_cached, 1);
  159. /* verify checksum offload configuration*/
  160. if (vdev->csum_enabled &&
  161. ((qdf_nbuf_get_tx_cksum(tx_desc->nbuf) ==
  162. QDF_NBUF_TX_CKSUM_TCP_UDP) ||
  163. qdf_nbuf_is_tso(tx_desc->nbuf))) {
  164. hal_tx_desc_set_l3_checksum_en(hal_tx_desc_cached, 1);
  165. hal_tx_desc_set_l4_checksum_en(hal_tx_desc_cached, 1);
  166. }
  167. if (tid != HTT_TX_EXT_TID_INVALID)
  168. hal_tx_desc_set_hlos_tid(hal_tx_desc_cached, tid);
  169. if (tx_desc->flags & DP_TX_DESC_FLAG_MESH)
  170. hal_tx_desc_set_mesh_en(soc->hal_soc, hal_tx_desc_cached, 1);
  171. if (qdf_unlikely(vdev->pdev->delay_stats_flag) ||
  172. qdf_unlikely(wlan_cfg_is_peer_ext_stats_enabled(soc->wlan_cfg_ctx)))
  173. tx_desc->timestamp = qdf_ktime_to_ms(qdf_ktime_real_get());
  174. dp_verbose_debug("length:%d , type = %d, dma_addr %llx, offset %d desc id %u",
  175. tx_desc->length,
  176. (tx_desc->flags & DP_TX_DESC_FLAG_FRAG),
  177. (uint64_t)tx_desc->dma_addr, tx_desc->pkt_offset,
  178. tx_desc->id);
  179. hal_ring_hdl = dp_tx_get_hal_ring_hdl(soc, ring_id);
  180. if (qdf_unlikely(dp_tx_hal_ring_access_start(soc, hal_ring_hdl))) {
  181. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  182. "%s %d : HAL RING Access Failed -- %pK",
  183. __func__, __LINE__, hal_ring_hdl);
  184. DP_STATS_INC(soc, tx.tcl_ring_full[ring_id], 1);
  185. DP_STATS_INC(vdev, tx_i.dropped.enqueue_fail, 1);
  186. return status;
  187. }
  188. dp_tx_clear_consumed_hw_descs(soc, hal_ring_hdl);
  189. /* Sync cached descriptor with HW */
  190. hal_tx_desc = hal_srng_src_get_next(soc->hal_soc, hal_ring_hdl);
  191. if (qdf_unlikely(!hal_tx_desc)) {
  192. dp_verbose_debug("TCL ring full ring_id:%d", ring_id);
  193. DP_STATS_INC(soc, tx.tcl_ring_full[ring_id], 1);
  194. DP_STATS_INC(vdev, tx_i.dropped.enqueue_fail, 1);
  195. goto ring_access_fail;
  196. }
  197. tx_desc->flags |= DP_TX_DESC_FLAG_QUEUED_TX;
  198. dp_vdev_peer_stats_update_protocol_cnt_tx(vdev, tx_desc->nbuf);
  199. hal_tx_desc_sync(hal_tx_desc_cached, hal_tx_desc);
  200. coalesce = dp_tx_attempt_coalescing(soc, vdev, tx_desc, tid);
  201. DP_STATS_INC_PKT(vdev, tx_i.processed, 1, tx_desc->length);
  202. dp_tx_update_stats(soc, tx_desc->nbuf);
  203. status = QDF_STATUS_SUCCESS;
  204. dp_tx_hw_desc_update_evt((uint8_t *)hal_tx_desc_cached,
  205. hal_ring_hdl, soc);
  206. ring_access_fail:
  207. dp_tx_ring_access_end_wrapper(soc, hal_ring_hdl, coalesce);
  208. return status;
  209. }
  210. QDF_STATUS dp_tx_desc_pool_init_li(struct dp_soc *soc,
  211. uint16_t num_elem,
  212. uint8_t pool_id)
  213. {
  214. uint32_t id, count, page_id, offset, pool_id_32;
  215. struct dp_tx_desc_s *tx_desc;
  216. struct dp_tx_desc_pool_s *tx_desc_pool;
  217. uint16_t num_desc_per_page;
  218. tx_desc_pool = &soc->tx_desc[pool_id];
  219. tx_desc = tx_desc_pool->freelist;
  220. count = 0;
  221. pool_id_32 = (uint32_t)pool_id;
  222. num_desc_per_page = tx_desc_pool->desc_pages.num_element_per_page;
  223. while (tx_desc) {
  224. page_id = count / num_desc_per_page;
  225. offset = count % num_desc_per_page;
  226. id = ((pool_id_32 << DP_TX_DESC_ID_POOL_OS) |
  227. (page_id << DP_TX_DESC_ID_PAGE_OS) | offset);
  228. tx_desc->id = id;
  229. tx_desc->pool_id = pool_id;
  230. tx_desc = tx_desc->next;
  231. count++;
  232. }
  233. return QDF_STATUS_SUCCESS;
  234. }
  235. void dp_tx_desc_pool_deinit_li(struct dp_soc *soc,
  236. struct dp_tx_desc_pool_s *tx_desc_pool,
  237. uint8_t pool_id)
  238. {
  239. }