dp_rx.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Copyright (c) 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. #ifndef _DP_RX_H
  19. #define _DP_RX_H
  20. #include "hal_rx.h"
  21. #include "dp_tx.h"
  22. #ifdef RXDMA_OPTIMIZATION
  23. #define RX_BUFFER_ALIGNMENT 128
  24. #else /* RXDMA_OPTIMIZATION */
  25. #define RX_BUFFER_ALIGNMENT 4
  26. #endif /* RXDMA_OPTIMIZATION */
  27. #define RX_BUFFER_SIZE 2048
  28. #define RX_BUFFER_RESERVATION 0
  29. #define DP_PEER_METADATA_PEER_ID_MASK 0x0000ffff
  30. #define DP_PEER_METADATA_PEER_ID_SHIFT 0
  31. #define DP_PEER_METADATA_VDEV_ID_MASK 0x00070000
  32. #define DP_PEER_METADATA_VDEV_ID_SHIFT 16
  33. #define DP_PEER_METADATA_PEER_ID_GET(_peer_metadata) \
  34. (((_peer_metadata) & DP_PEER_METADATA_PEER_ID_MASK) \
  35. >> DP_PEER_METADATA_PEER_ID_SHIFT)
  36. #define DP_PEER_METADATA_ID_GET(_peer_metadata) \
  37. (((_peer_metadata) & DP_PEER_METADATA_VDEV_ID_MASK) \
  38. >> DP_PEER_METADATA_VDEV_ID_SHIFT)
  39. /**
  40. * struct dp_rx_desc
  41. *
  42. * @nbuf : VA of the "skb" posted
  43. * @rx_buf_start : VA of the original Rx buffer, before
  44. * movement of any skb->data pointer
  45. * @cookie : index into the sw array which holds
  46. * the sw Rx descriptors
  47. * Cookie space is 21 bits:
  48. * lower 18 bits -- index
  49. * upper 3 bits -- pool_id
  50. * @pool_id : pool Id for which this allocated.
  51. * Can only be used if there is no flow
  52. * steering
  53. */
  54. struct dp_rx_desc {
  55. qdf_nbuf_t nbuf;
  56. uint8_t *rx_buf_start;
  57. uint16_t cookie;
  58. uint8_t pool_id;
  59. };
  60. #define RX_DESC_COOKIE_INDEX_SHIFT 0
  61. #define RX_DESC_COOKIE_INDEX_MASK 0x3ffff /* 18 bits */
  62. #define RX_DESC_COOKIE_POOL_ID_SHIFT 18
  63. #define RX_DESC_COOKIE_POOL_ID_MASK 0x1c0000
  64. #define DP_RX_DESC_COOKIE_POOL_ID_GET(_cookie) \
  65. (((_cookie) & RX_DESC_COOKIE_POOL_ID_MASK) >> \
  66. RX_DESC_COOKIE_POOL_ID_SHIFT)
  67. #define DP_RX_DESC_COOKIE_INDEX_GET(_cookie) \
  68. (((_cookie) & RX_DESC_COOKIE_INDEX_MASK) >> \
  69. RX_DESC_COOKIE_INDEX_SHIFT)
  70. /**
  71. * struct dp_rx_desc_list_elem_t
  72. *
  73. * @next : Next pointer to form free list
  74. * @rx_desc : DP Rx descriptor
  75. */
  76. union dp_rx_desc_list_elem_t {
  77. union dp_rx_desc_list_elem_t *next;
  78. struct dp_rx_desc rx_desc;
  79. };
  80. /**
  81. * dp_rx_cookie_2_va() - Converts cookie to a virtual address of
  82. * the Rx descriptor.
  83. * @soc: core txrx main context
  84. * @cookie: cookie used to lookup virtual address
  85. *
  86. * Return: void *: Virtual Address of the Rx descriptor
  87. */
  88. static inline
  89. void *dp_rx_cookie_2_va(struct dp_soc *soc, uint32_t cookie)
  90. {
  91. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  92. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  93. /* TODO */
  94. /* Add sanity for pool_id & index */
  95. return &(soc->rx_desc[pool_id].array[index].rx_desc);
  96. }
  97. void dp_rx_add_desc_list_to_free_list(struct dp_soc *soc,
  98. union dp_rx_desc_list_elem_t **local_desc_list,
  99. union dp_rx_desc_list_elem_t **tail,
  100. uint16_t pool_id);
  101. uint16_t dp_rx_get_free_desc_list(struct dp_soc *soc, uint32_t pool_id,
  102. uint16_t num_descs,
  103. union dp_rx_desc_list_elem_t **desc_list,
  104. union dp_rx_desc_list_elem_t **tail);
  105. QDF_STATUS dp_rx_desc_pool_alloc(struct dp_soc *soc, uint32_t pool_id);
  106. void dp_rx_desc_pool_free(struct dp_soc *soc, uint32_t pool_id);
  107. QDF_STATUS dp_rx_pdev_attach(struct dp_pdev *pdev);
  108. void dp_rx_pdev_detach(struct dp_pdev *pdev);
  109. QDF_STATUS dp_rx_buffers_replenish(struct dp_soc *dp_soc, uint32_t mac_id,
  110. uint32_t num_req_buffers,
  111. union dp_rx_desc_list_elem_t **desc_list,
  112. union dp_rx_desc_list_elem_t **tail,
  113. uint8_t owner);
  114. uint32_t dp_rx_process(struct dp_soc *soc, void *hal_ring, uint32_t quota);
  115. uint32_t dp_rx_err_process(struct dp_soc *soc, void *hal_ring, uint32_t quota);
  116. uint32_t
  117. dp_rx_wbm_err_process(struct dp_soc *soc, void *hal_ring, uint32_t quota);
  118. /**
  119. * dp_rx_add_to_free_desc_list() - Adds to a local free descriptor list
  120. *
  121. * @head: pointer to the head of local free list
  122. * @tail: pointer to the tail of local free list
  123. * @new: new descriptor that is added to the free list
  124. *
  125. * Return: void:
  126. */
  127. static inline
  128. void dp_rx_add_to_free_desc_list(union dp_rx_desc_list_elem_t **head,
  129. union dp_rx_desc_list_elem_t **tail,
  130. struct dp_rx_desc *new)
  131. {
  132. qdf_assert(head && new);
  133. new->nbuf = NULL;
  134. ((union dp_rx_desc_list_elem_t *)new)->next = *head;
  135. *head = (union dp_rx_desc_list_elem_t *)new;
  136. if (*tail == NULL)
  137. *tail = *head;
  138. }
  139. #define DP_RX_LIST_APPEND(head, tail, elem) \
  140. do { \
  141. if (!(head)) { \
  142. (head) = (elem); \
  143. } else { \
  144. qdf_nbuf_set_next((tail), (elem)); \
  145. } \
  146. (tail) = (elem); \
  147. qdf_nbuf_set_next((tail), NULL); \
  148. } while (0)
  149. #ifndef BUILD_X86
  150. static inline int check_x86_paddr(struct dp_soc *dp_soc, qdf_nbuf_t *rx_netbuf,
  151. qdf_dma_addr_t *paddr, struct dp_pdev *pdev)
  152. {
  153. return QDF_STATUS_SUCCESS;
  154. }
  155. #else
  156. #define MAX_RETRY 100
  157. static inline int check_x86_paddr(struct dp_soc *dp_soc, qdf_nbuf_t *rx_netbuf,
  158. qdf_dma_addr_t *paddr, struct dp_pdev *pdev)
  159. {
  160. uint32_t nbuf_retry = 0;
  161. int32_t ret;
  162. const uint32_t x86_phy_addr = 0x50000000;
  163. /*
  164. * in M2M emulation platforms (x86) the memory below 0x50000000
  165. * is reserved for target use, so any memory allocated in this
  166. * region should not be used by host
  167. */
  168. do {
  169. if (qdf_likely(*paddr > x86_phy_addr))
  170. return QDF_STATUS_SUCCESS;
  171. else {
  172. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  173. "phy addr %p exceded 0x50000000 trying again\n",
  174. paddr);
  175. nbuf_retry++;
  176. if ((*rx_netbuf)) {
  177. qdf_nbuf_unmap_single(dp_soc->osdev, *rx_netbuf,
  178. QDF_DMA_BIDIRECTIONAL);
  179. qdf_nbuf_free(*rx_netbuf);
  180. }
  181. *rx_netbuf = qdf_nbuf_alloc(pdev->osif_pdev,
  182. RX_BUFFER_SIZE,
  183. RX_BUFFER_RESERVATION,
  184. RX_BUFFER_ALIGNMENT,
  185. FALSE);
  186. if (qdf_unlikely(!(*rx_netbuf)))
  187. return QDF_STATUS_E_FAILURE;
  188. ret = qdf_nbuf_map_single(dp_soc->osdev, *rx_netbuf,
  189. QDF_DMA_BIDIRECTIONAL);
  190. if (qdf_unlikely(ret == QDF_STATUS_E_FAILURE)) {
  191. qdf_nbuf_free(*rx_netbuf);
  192. *rx_netbuf = NULL;
  193. continue;
  194. }
  195. *paddr = qdf_nbuf_get_frag_paddr(*rx_netbuf, 0);
  196. }
  197. } while (nbuf_retry < MAX_RETRY);
  198. if ((*rx_netbuf)) {
  199. qdf_nbuf_unmap_single(dp_soc->osdev, *rx_netbuf,
  200. QDF_DMA_BIDIRECTIONAL);
  201. qdf_nbuf_free(*rx_netbuf);
  202. }
  203. return QDF_STATUS_E_FAILURE;
  204. }
  205. #endif
  206. #endif /* _DP_RX_H */