dp_li_rx.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /*
  2. * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2023 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 _DP_LI_RX_H_
  20. #define _DP_LI_RX_H_
  21. #include <dp_types.h>
  22. #include <dp_rx.h>
  23. #include "dp_li.h"
  24. /**
  25. * dp_rx_process_li() - Brain of the Rx processing functionality
  26. * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
  27. * @int_ctx: per interrupt context
  28. * @hal_ring_hdl: opaque pointer to the HAL Rx Ring, which will be serviced
  29. * @reo_ring_num: ring number (0, 1, 2 or 3) of the reo ring.
  30. * @quota: No. of units (packets) that can be serviced in one shot.
  31. *
  32. * This function implements the core of Rx functionality. This is
  33. * expected to handle only non-error frames.
  34. *
  35. * Return: uint32_t: No. of elements processed
  36. */
  37. uint32_t dp_rx_process_li(struct dp_intr *int_ctx,
  38. hal_ring_handle_t hal_ring_hdl, uint8_t reo_ring_num,
  39. uint32_t quota);
  40. /**
  41. * dp_rx_chain_msdus_li() - Function to chain all msdus of a mpdu
  42. * to pdev invalid peer list
  43. *
  44. * @soc: core DP main context
  45. * @nbuf: Buffer pointer
  46. * @rx_tlv_hdr: start of rx tlv header
  47. * @mac_id: mac id
  48. *
  49. * Return: bool: true for last msdu of mpdu
  50. */
  51. bool dp_rx_chain_msdus_li(struct dp_soc *soc, qdf_nbuf_t nbuf,
  52. uint8_t *rx_tlv_hdr, uint8_t mac_id);
  53. /**
  54. * dp_rx_desc_pool_init_li() - Initialize Rx Descriptor pool(s)
  55. * @soc: Handle to DP Soc structure
  56. * @rx_desc_pool: Rx descriptor pool handler
  57. * @pool_id: Rx descriptor pool ID
  58. *
  59. * Return: None
  60. */
  61. QDF_STATUS dp_rx_desc_pool_init_li(struct dp_soc *soc,
  62. struct rx_desc_pool *rx_desc_pool,
  63. uint32_t pool_id);
  64. /**
  65. * dp_rx_desc_pool_deinit_li() - De-initialize Rx Descriptor pool(s)
  66. * @soc: Handle to DP Soc structure
  67. * @rx_desc_pool: Rx descriptor pool handler
  68. * @pool_id: Rx descriptor pool ID
  69. *
  70. * Return: None
  71. */
  72. void dp_rx_desc_pool_deinit_li(struct dp_soc *soc,
  73. struct rx_desc_pool *rx_desc_pool,
  74. uint32_t pool_id);
  75. /**
  76. * dp_wbm_get_rx_desc_from_hal_desc_li() - Get corresponding Rx Desc
  77. * address from WBM ring Desc
  78. * @soc: Handle to DP Soc structure
  79. * @ring_desc: ring descriptor structure pointer
  80. * @r_rx_desc: pointer to a pointer of Rx Desc
  81. *
  82. * Return: QDF_STATUS_SUCCESS - succeeded, others - failed
  83. */
  84. QDF_STATUS dp_wbm_get_rx_desc_from_hal_desc_li(
  85. struct dp_soc *soc,
  86. void *ring_desc,
  87. struct dp_rx_desc **r_rx_desc);
  88. /**
  89. * dp_rx_get_reo_qdesc_addr_li(): API to get qdesc address of reo
  90. * entrance ring desc
  91. *
  92. * @hal_soc: Handle to HAL Soc structure
  93. * @dst_ring_desc: reo dest ring descriptor (used for Lithium DP)
  94. * @buf: pointer to the start of RX PKT TLV headers
  95. * @txrx_peer: pointer to txrx_peer
  96. * @tid: tid value
  97. *
  98. * Return: qdesc address in reo destination ring buffer
  99. */
  100. static inline
  101. uint64_t dp_rx_get_reo_qdesc_addr_li(hal_soc_handle_t hal_soc,
  102. uint8_t *dst_ring_desc,
  103. uint8_t *buf,
  104. struct dp_txrx_peer *txrx_peer,
  105. unsigned int tid)
  106. {
  107. return hal_rx_get_qdesc_addr(hal_soc, dst_ring_desc, buf);
  108. }
  109. /**
  110. * dp_rx_desc_cookie_2_va_li() - Convert RX Desc cookie ID to VA
  111. * @soc:Handle to DP Soc structure
  112. * @cookie: cookie used to lookup virtual address
  113. *
  114. * Return: Rx descriptor virtual address
  115. */
  116. static inline
  117. struct dp_rx_desc *dp_rx_desc_cookie_2_va_li(struct dp_soc *soc,
  118. uint32_t cookie)
  119. {
  120. return dp_rx_cookie_2_va_rxdma_buf(soc, cookie);
  121. }
  122. #define DP_PEER_METADATA_VDEV_ID_MASK 0x003f0000
  123. #define DP_PEER_METADATA_VDEV_ID_SHIFT 16
  124. #define DP_PEER_METADATA_OFFLOAD_MASK 0x01000000
  125. #define DP_PEER_METADATA_OFFLOAD_SHIFT 24
  126. #define DP_PEER_METADATA_VDEV_ID_GET_LI(_peer_metadata) \
  127. (((_peer_metadata) & DP_PEER_METADATA_VDEV_ID_MASK) \
  128. >> DP_PEER_METADATA_VDEV_ID_SHIFT)
  129. #define DP_PEER_METADATA_OFFLOAD_GET_LI(_peer_metadata) \
  130. (((_peer_metadata) & DP_PEER_METADATA_OFFLOAD_MASK) \
  131. >> DP_PEER_METADATA_OFFLOAD_SHIFT)
  132. static inline uint16_t
  133. dp_rx_peer_metadata_peer_id_get_li(struct dp_soc *soc, uint32_t peer_metadata)
  134. {
  135. struct htt_rx_peer_metadata_v0 *metadata =
  136. (struct htt_rx_peer_metadata_v0 *)&peer_metadata;
  137. return metadata->peer_id;
  138. }
  139. bool
  140. dp_rx_intrabss_handle_nawds_li(struct dp_soc *soc, struct dp_txrx_peer *ta_peer,
  141. qdf_nbuf_t nbuf_copy,
  142. struct cdp_tid_rx_stats *tid_stats,
  143. uint8_t link_id);
  144. #ifdef QCA_DP_RX_NBUF_AND_NBUF_DATA_PREFETCH
  145. static inline
  146. void dp_rx_prefetch_nbuf_data(qdf_nbuf_t nbuf, qdf_nbuf_t next)
  147. {
  148. struct rx_pkt_tlvs *pkt_tlvs;
  149. if (next) {
  150. /* prefetch skb->next and first few bytes of skb->cb */
  151. qdf_prefetch(next);
  152. /* skb->cb spread across 2 cache lines hence below prefetch */
  153. qdf_prefetch(&next->_skb_refdst);
  154. qdf_prefetch(&next->len);
  155. qdf_prefetch(&next->protocol);
  156. pkt_tlvs = (struct rx_pkt_tlvs *)next->data;
  157. /* sa_idx, da_idx, l3_pad in RX msdu_end TLV */
  158. qdf_prefetch(pkt_tlvs);
  159. /* msdu_done in RX attention TLV */
  160. qdf_prefetch(&pkt_tlvs->attn_tlv);
  161. /* fr_ds & to_ds in RX MPDU start TLV */
  162. if (qdf_nbuf_is_rx_chfrag_end(nbuf))
  163. qdf_prefetch(&pkt_tlvs->mpdu_start_tlv);
  164. }
  165. }
  166. #else
  167. static inline
  168. void dp_rx_prefetch_nbuf_data(qdf_nbuf_t nbuf, qdf_nbuf_t next)
  169. {
  170. }
  171. #endif
  172. #ifdef QCA_DP_RX_HW_SW_NBUF_DESC_PREFETCH
  173. /**
  174. * dp_rx_cookie_2_va_rxdma_buf_prefetch() - function to prefetch the SW desc
  175. * @soc: Handle to DP Soc structure
  176. * @cookie: cookie used to lookup virtual address
  177. *
  178. * Return: prefetched Rx descriptor virtual address
  179. */
  180. static inline
  181. void *dp_rx_cookie_2_va_rxdma_buf_prefetch(struct dp_soc *soc, uint32_t cookie)
  182. {
  183. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  184. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  185. struct rx_desc_pool *rx_desc_pool;
  186. void *prefetch_desc;
  187. if (qdf_unlikely(pool_id >= MAX_RXDESC_POOLS))
  188. return NULL;
  189. rx_desc_pool = &soc->rx_desc_buf[pool_id];
  190. if (qdf_unlikely(index >= rx_desc_pool->pool_size))
  191. return NULL;
  192. prefetch_desc = &soc->rx_desc_buf[pool_id].array[index].rx_desc;
  193. qdf_prefetch(prefetch_desc);
  194. return prefetch_desc;
  195. }
  196. /**
  197. * dp_rx_prefetch_hw_sw_nbuf_desc() - function to prefetch HW and SW desc
  198. * @soc: Handle to DP Soc structure
  199. * @hal_soc: Handle to HAL Soc structure
  200. * @num_entries: valid number of HW descriptors
  201. * @hal_ring_hdl: Destination ring pointer
  202. * @last_prefetched_hw_desc: pointer to the last prefetched HW descriptor
  203. * @last_prefetched_sw_desc: input & output param of last prefetch SW desc
  204. *
  205. * Return: None
  206. */
  207. static inline
  208. void dp_rx_prefetch_hw_sw_nbuf_desc(struct dp_soc *soc,
  209. hal_soc_handle_t hal_soc,
  210. uint32_t num_entries,
  211. hal_ring_handle_t hal_ring_hdl,
  212. hal_ring_desc_t *last_prefetched_hw_desc,
  213. struct dp_rx_desc **last_prefetched_sw_desc)
  214. {
  215. if (*last_prefetched_sw_desc) {
  216. qdf_prefetch((uint8_t *)(*last_prefetched_sw_desc)->nbuf);
  217. qdf_prefetch((uint8_t *)(*last_prefetched_sw_desc)->nbuf + 64);
  218. }
  219. if (num_entries) {
  220. *last_prefetched_sw_desc = dp_rx_cookie_2_va_rxdma_buf_prefetch(soc, HAL_RX_REO_BUF_COOKIE_GET(*last_prefetched_hw_desc));
  221. *last_prefetched_hw_desc = hal_srng_dst_prefetch_next_cached_desc(hal_soc,
  222. hal_ring_hdl,
  223. (uint8_t *)*last_prefetched_hw_desc);
  224. }
  225. }
  226. #else
  227. static inline
  228. void dp_rx_prefetch_hw_sw_nbuf_desc(struct dp_soc *soc,
  229. hal_soc_handle_t hal_soc,
  230. uint32_t quota,
  231. hal_ring_handle_t hal_ring_hdl,
  232. hal_ring_desc_t *last_prefetched_hw_desc,
  233. struct dp_rx_desc **last_prefetched_sw_desc)
  234. {
  235. }
  236. #endif
  237. static inline
  238. QDF_STATUS dp_peer_rx_reorder_queue_setup_li(struct dp_soc *soc,
  239. struct dp_peer *peer,
  240. uint32_t tid_bitmap,
  241. uint32_t ba_window_size)
  242. {
  243. int tid;
  244. struct dp_rx_tid *rx_tid;
  245. if (!soc->cdp_soc.ol_ops->peer_rx_reorder_queue_setup) {
  246. dp_peer_debug("peer_rx_reorder_queue_setup NULL");
  247. return QDF_STATUS_SUCCESS;
  248. }
  249. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  250. if (!(BIT(tid) & tid_bitmap))
  251. continue;
  252. rx_tid = &peer->rx_tid[tid];
  253. if (!rx_tid->hw_qdesc_paddr) {
  254. tid_bitmap &= ~BIT(tid);
  255. continue;
  256. }
  257. if (soc->cdp_soc.ol_ops->peer_rx_reorder_queue_setup(
  258. soc->ctrl_psoc,
  259. peer->vdev->pdev->pdev_id,
  260. peer->vdev->vdev_id,
  261. peer->mac_addr.raw, rx_tid->hw_qdesc_paddr, tid, tid,
  262. 1, ba_window_size)) {
  263. dp_peer_err("%pK: Fail to send reo q setup. tid %d",
  264. soc, tid);
  265. return QDF_STATUS_E_FAILURE;
  266. }
  267. if (!tid_bitmap) {
  268. dp_peer_err("tid_bitmap=0. All tids setup fail");
  269. return QDF_STATUS_E_FAILURE;
  270. }
  271. }
  272. return QDF_STATUS_SUCCESS;
  273. }
  274. /**
  275. * dp_rx_wbm_err_reap_desc_li() - Function to reap and replenish
  276. * WBM RX Error descriptors
  277. *
  278. * @int_ctx: pointer to DP interrupt context
  279. * @soc: core DP main context
  280. * @hal_ring_hdl: opaque pointer to the HAL Rx Error Ring, to be serviced
  281. * @quota: No. of units (packets) that can be serviced in one shot.
  282. * @rx_bufs_used: No. of descriptors reaped
  283. *
  284. * This function implements the core Rx functionality like reap and
  285. * replenish the RX error ring Descriptors, and create a nbuf list
  286. * out of it. It also reads wbm error information from descriptors
  287. * and update the nbuf tlv area.
  288. *
  289. * Return: qdf_nbuf_t: head pointer to the nbuf list created
  290. */
  291. qdf_nbuf_t
  292. dp_rx_wbm_err_reap_desc_li(struct dp_intr *int_ctx, struct dp_soc *soc,
  293. hal_ring_handle_t hal_ring_hdl, uint32_t quota,
  294. uint32_t *rx_bufs_used);
  295. /**
  296. * dp_rx_null_q_desc_handle_li() - Function to handle NULL Queue
  297. * descriptor violation on either a
  298. * REO or WBM ring
  299. *
  300. * @soc: core DP main context
  301. * @nbuf: buffer pointer
  302. * @rx_tlv_hdr: start of rx tlv header
  303. * @pool_id: mac id
  304. * @txrx_peer: txrx peer handle
  305. * @is_reo_exception: flag to check if the error is from REO or WBM
  306. * @link_id: link Id on which packet is received
  307. *
  308. * This function handles NULL queue descriptor violations arising out
  309. * a missing REO queue for a given peer or a given TID. This typically
  310. * may happen if a packet is received on a QOS enabled TID before the
  311. * ADDBA negotiation for that TID, when the TID queue is setup. Or
  312. * it may also happen for MC/BC frames if they are not routed to the
  313. * non-QOS TID queue, in the absence of any other default TID queue.
  314. * This error can show up both in a REO destination or WBM release ring.
  315. *
  316. * Return: QDF_STATUS_SUCCESS, if nbuf handled successfully. QDF status code
  317. * if nbuf could not be handled or dropped.
  318. */
  319. QDF_STATUS
  320. dp_rx_null_q_desc_handle_li(struct dp_soc *soc, qdf_nbuf_t nbuf,
  321. uint8_t *rx_tlv_hdr, uint8_t pool_id,
  322. struct dp_txrx_peer *txrx_peer,
  323. bool is_reo_exception,
  324. uint8_t link_id);
  325. #endif