dp_rx.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. #ifndef _DP_RX_H
  19. #define _DP_RX_H
  20. #include "hal_rx.h"
  21. #include "dp_tx.h"
  22. #include "dp_peer.h"
  23. #ifdef RXDMA_OPTIMIZATION
  24. #define RX_BUFFER_ALIGNMENT 128
  25. #else /* RXDMA_OPTIMIZATION */
  26. #define RX_BUFFER_ALIGNMENT 4
  27. #endif /* RXDMA_OPTIMIZATION */
  28. #define RX_BUFFER_SIZE 2048
  29. #define RX_BUFFER_RESERVATION 0
  30. #define DP_PEER_METADATA_PEER_ID_MASK 0x0000ffff
  31. #define DP_PEER_METADATA_PEER_ID_SHIFT 0
  32. #define DP_PEER_METADATA_VDEV_ID_MASK 0x00070000
  33. #define DP_PEER_METADATA_VDEV_ID_SHIFT 16
  34. #define DP_PEER_METADATA_PEER_ID_GET(_peer_metadata) \
  35. (((_peer_metadata) & DP_PEER_METADATA_PEER_ID_MASK) \
  36. >> DP_PEER_METADATA_PEER_ID_SHIFT)
  37. #define DP_PEER_METADATA_ID_GET(_peer_metadata) \
  38. (((_peer_metadata) & DP_PEER_METADATA_VDEV_ID_MASK) \
  39. >> DP_PEER_METADATA_VDEV_ID_SHIFT)
  40. /**
  41. * struct dp_rx_desc
  42. *
  43. * @nbuf : VA of the "skb" posted
  44. * @rx_buf_start : VA of the original Rx buffer, before
  45. * movement of any skb->data pointer
  46. * @cookie : index into the sw array which holds
  47. * the sw Rx descriptors
  48. * Cookie space is 21 bits:
  49. * lower 18 bits -- index
  50. * upper 3 bits -- pool_id
  51. * @pool_id : pool Id for which this allocated.
  52. * Can only be used if there is no flow
  53. * steering
  54. */
  55. struct dp_rx_desc {
  56. qdf_nbuf_t nbuf;
  57. uint8_t *rx_buf_start;
  58. uint32_t cookie;
  59. uint8_t pool_id;
  60. };
  61. #define RX_DESC_COOKIE_INDEX_SHIFT 0
  62. #define RX_DESC_COOKIE_INDEX_MASK 0x3ffff /* 18 bits */
  63. #define RX_DESC_COOKIE_POOL_ID_SHIFT 18
  64. #define RX_DESC_COOKIE_POOL_ID_MASK 0x1c0000
  65. #define DP_RX_DESC_COOKIE_POOL_ID_GET(_cookie) \
  66. (((_cookie) & RX_DESC_COOKIE_POOL_ID_MASK) >> \
  67. RX_DESC_COOKIE_POOL_ID_SHIFT)
  68. #define DP_RX_DESC_COOKIE_INDEX_GET(_cookie) \
  69. (((_cookie) & RX_DESC_COOKIE_INDEX_MASK) >> \
  70. RX_DESC_COOKIE_INDEX_SHIFT)
  71. /**
  72. * struct dp_rx_desc_list_elem_t
  73. *
  74. * @next : Next pointer to form free list
  75. * @rx_desc : DP Rx descriptor
  76. */
  77. union dp_rx_desc_list_elem_t {
  78. union dp_rx_desc_list_elem_t *next;
  79. struct dp_rx_desc rx_desc;
  80. };
  81. /**
  82. * dp_rx_cookie_2_va_rxdma_buf() - Converts cookie to a virtual address of
  83. * the Rx descriptor on Rx DMA source ring buffer
  84. * @soc: core txrx main context
  85. * @cookie: cookie used to lookup virtual address
  86. *
  87. * Return: void *: Virtual Address of the Rx descriptor
  88. */
  89. static inline
  90. void *dp_rx_cookie_2_va_rxdma_buf(struct dp_soc *soc, uint32_t cookie)
  91. {
  92. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  93. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  94. /* TODO */
  95. /* Add sanity for pool_id & index */
  96. return &(soc->rx_desc_buf[pool_id].array[index].rx_desc);
  97. }
  98. /**
  99. * dp_rx_cookie_2_va_mon_buf() - Converts cookie to a virtual address of
  100. * the Rx descriptor on monitor ring buffer
  101. * @soc: core txrx main context
  102. * @cookie: cookie used to lookup virtual address
  103. *
  104. * Return: void *: Virtual Address of the Rx descriptor
  105. */
  106. static inline
  107. void *dp_rx_cookie_2_va_mon_buf(struct dp_soc *soc, uint32_t cookie)
  108. {
  109. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  110. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  111. /* TODO */
  112. /* Add sanity for pool_id & index */
  113. return &(soc->rx_desc_mon[pool_id].array[index].rx_desc);
  114. }
  115. /**
  116. * dp_rx_cookie_2_va_mon_status() - Converts cookie to a virtual address of
  117. * the Rx descriptor on monitor status ring buffer
  118. * @soc: core txrx main context
  119. * @cookie: cookie used to lookup virtual address
  120. *
  121. * Return: void *: Virtual Address of the Rx descriptor
  122. */
  123. static inline
  124. void *dp_rx_cookie_2_va_mon_status(struct dp_soc *soc, uint32_t cookie)
  125. {
  126. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  127. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  128. /* TODO */
  129. /* Add sanity for pool_id & index */
  130. return &(soc->rx_desc_status[pool_id].array[index].rx_desc);
  131. }
  132. void dp_rx_add_desc_list_to_free_list(struct dp_soc *soc,
  133. union dp_rx_desc_list_elem_t **local_desc_list,
  134. union dp_rx_desc_list_elem_t **tail,
  135. uint16_t pool_id,
  136. struct rx_desc_pool *rx_desc_pool);
  137. uint16_t dp_rx_get_free_desc_list(struct dp_soc *soc, uint32_t pool_id,
  138. struct rx_desc_pool *rx_desc_pool,
  139. uint16_t num_descs,
  140. union dp_rx_desc_list_elem_t **desc_list,
  141. union dp_rx_desc_list_elem_t **tail);
  142. QDF_STATUS dp_rx_pdev_attach(struct dp_pdev *pdev);
  143. void dp_rx_pdev_detach(struct dp_pdev *pdev);
  144. uint32_t dp_rx_process(struct dp_soc *soc, void *hal_ring, uint32_t quota);
  145. uint32_t dp_rx_err_process(struct dp_soc *soc, void *hal_ring, uint32_t quota);
  146. uint32_t
  147. dp_rx_wbm_err_process(struct dp_soc *soc, void *hal_ring, uint32_t quota);
  148. QDF_STATUS dp_rx_desc_pool_alloc(struct dp_soc *soc,
  149. uint32_t pool_id,
  150. uint32_t pool_size,
  151. struct rx_desc_pool *rx_desc_pool);
  152. void dp_rx_desc_pool_free(struct dp_soc *soc,
  153. uint32_t pool_id,
  154. struct rx_desc_pool *rx_desc_pool);
  155. /**
  156. * dp_rx_add_to_free_desc_list() - Adds to a local free descriptor list
  157. *
  158. * @head: pointer to the head of local free list
  159. * @tail: pointer to the tail of local free list
  160. * @new: new descriptor that is added to the free list
  161. *
  162. * Return: void:
  163. */
  164. static inline
  165. void dp_rx_add_to_free_desc_list(union dp_rx_desc_list_elem_t **head,
  166. union dp_rx_desc_list_elem_t **tail,
  167. struct dp_rx_desc *new)
  168. {
  169. qdf_assert(head && new);
  170. new->nbuf = NULL;
  171. ((union dp_rx_desc_list_elem_t *)new)->next = *head;
  172. *head = (union dp_rx_desc_list_elem_t *)new;
  173. if (*tail == NULL)
  174. *tail = *head;
  175. }
  176. /**
  177. * dp_rx_wds_srcport_learn() - Add or update the STA PEER which
  178. * is behind the WDS repeater.
  179. *
  180. * @soc: core txrx main context
  181. * @rx_tlv_hdr: base address of RX TLV header
  182. * @ta_peer: WDS repeater peer
  183. * @nbuf: rx pkt
  184. *
  185. * Return: void:
  186. */
  187. #ifndef CONFIG_MCL
  188. static inline void
  189. dp_rx_wds_srcport_learn(struct dp_soc *soc,
  190. uint8_t *rx_tlv_hdr,
  191. struct dp_peer *ta_peer,
  192. qdf_nbuf_t nbuf)
  193. {
  194. uint16_t sa_sw_peer_id = hal_rx_msdu_end_sa_sw_peer_id_get(rx_tlv_hdr);
  195. uint32_t flags = IEEE80211_NODE_F_WDS_HM;
  196. uint32_t ret = 0;
  197. uint8_t wds_src_mac[IEEE80211_ADDR_LEN];
  198. memcpy(wds_src_mac, (qdf_nbuf_data(nbuf) + IEEE80211_ADDR_LEN),
  199. IEEE80211_ADDR_LEN);
  200. if (!hal_rx_msdu_end_sa_is_valid_get(rx_tlv_hdr)) {
  201. ret = soc->cdp_soc.ol_ops->peer_add_wds_entry(
  202. soc->osif_soc,
  203. wds_src_mac,
  204. ta_peer->mac_addr.raw,
  205. flags);
  206. } else if (sa_sw_peer_id != ta_peer->peer_ids[0]) {
  207. ret = soc->cdp_soc.ol_ops->peer_update_wds_entry(
  208. soc->osif_soc,
  209. wds_src_mac,
  210. ta_peer->mac_addr.raw,
  211. flags);
  212. }
  213. return;
  214. }
  215. #else
  216. static inline void
  217. dp_rx_wds_srcport_learn(struct dp_soc *soc,
  218. uint8_t *rx_tlv_hdr,
  219. struct dp_peer *ta_peer,
  220. qdf_nbuf_t nbuf)
  221. {
  222. }
  223. #endif
  224. uint8_t dp_rx_process_invalid_peer(struct dp_soc *soc, qdf_nbuf_t nbuf);
  225. #define DP_RX_LIST_APPEND(head, tail, elem) \
  226. do { \
  227. if (!(head)) { \
  228. (head) = (elem); \
  229. } else { \
  230. qdf_nbuf_set_next((tail), (elem)); \
  231. } \
  232. (tail) = (elem); \
  233. qdf_nbuf_set_next((tail), NULL); \
  234. } while (0)
  235. #ifndef BUILD_X86
  236. static inline int check_x86_paddr(struct dp_soc *dp_soc, qdf_nbuf_t *rx_netbuf,
  237. qdf_dma_addr_t *paddr, struct dp_pdev *pdev)
  238. {
  239. return QDF_STATUS_SUCCESS;
  240. }
  241. #else
  242. #define MAX_RETRY 100
  243. static inline int check_x86_paddr(struct dp_soc *dp_soc, qdf_nbuf_t *rx_netbuf,
  244. qdf_dma_addr_t *paddr, struct dp_pdev *pdev)
  245. {
  246. uint32_t nbuf_retry = 0;
  247. int32_t ret;
  248. const uint32_t x86_phy_addr = 0x50000000;
  249. /*
  250. * in M2M emulation platforms (x86) the memory below 0x50000000
  251. * is reserved for target use, so any memory allocated in this
  252. * region should not be used by host
  253. */
  254. do {
  255. if (qdf_likely(*paddr > x86_phy_addr))
  256. return QDF_STATUS_SUCCESS;
  257. else {
  258. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  259. "phy addr %p exceded 0x50000000 trying again\n",
  260. paddr);
  261. nbuf_retry++;
  262. if ((*rx_netbuf)) {
  263. qdf_nbuf_unmap_single(dp_soc->osdev, *rx_netbuf,
  264. QDF_DMA_BIDIRECTIONAL);
  265. /* Not freeing buffer intentionally.
  266. * Observed that same buffer is getting
  267. * re-allocated resulting in longer load time
  268. * WMI init timeout.
  269. * This buffer is anyway not useful so skip it.
  270. **/
  271. }
  272. *rx_netbuf = qdf_nbuf_alloc(pdev->osif_pdev,
  273. RX_BUFFER_SIZE,
  274. RX_BUFFER_RESERVATION,
  275. RX_BUFFER_ALIGNMENT,
  276. FALSE);
  277. if (qdf_unlikely(!(*rx_netbuf)))
  278. return QDF_STATUS_E_FAILURE;
  279. ret = qdf_nbuf_map_single(dp_soc->osdev, *rx_netbuf,
  280. QDF_DMA_BIDIRECTIONAL);
  281. if (qdf_unlikely(ret == QDF_STATUS_E_FAILURE)) {
  282. qdf_nbuf_free(*rx_netbuf);
  283. *rx_netbuf = NULL;
  284. continue;
  285. }
  286. *paddr = qdf_nbuf_get_frag_paddr(*rx_netbuf, 0);
  287. }
  288. } while (nbuf_retry < MAX_RETRY);
  289. if ((*rx_netbuf)) {
  290. qdf_nbuf_unmap_single(dp_soc->osdev, *rx_netbuf,
  291. QDF_DMA_BIDIRECTIONAL);
  292. qdf_nbuf_free(*rx_netbuf);
  293. }
  294. return QDF_STATUS_E_FAILURE;
  295. }
  296. #endif
  297. /**
  298. * dp_rx_cookie_2_link_desc_va() - Converts cookie to a virtual address of
  299. * the MSDU Link Descriptor
  300. * @soc: core txrx main context
  301. * @buf_info: buf_info include cookie that used to lookup virtual address of
  302. * link descriptor Normally this is just an index into a per SOC array.
  303. *
  304. * This is the VA of the link descriptor, that HAL layer later uses to
  305. * retrieve the list of MSDU's for a given MPDU.
  306. *
  307. * Return: void *: Virtual Address of the Rx descriptor
  308. */
  309. static inline
  310. void *dp_rx_cookie_2_link_desc_va(struct dp_soc *soc,
  311. struct hal_buf_info *buf_info)
  312. {
  313. void *link_desc_va;
  314. /* TODO */
  315. /* Add sanity for cookie */
  316. link_desc_va = soc->link_desc_banks[buf_info->sw_cookie].base_vaddr +
  317. (buf_info->paddr -
  318. soc->link_desc_banks[buf_info->sw_cookie].base_paddr);
  319. return link_desc_va;
  320. }
  321. /**
  322. * dp_rx_cookie_2_mon_link_desc_va() - Converts cookie to a virtual address of
  323. * the MSDU Link Descriptor
  324. * @pdev: core txrx pdev context
  325. * @buf_info: buf_info includes cookie that used to lookup virtual address of
  326. * link descriptor. Normally this is just an index into a per pdev array.
  327. *
  328. * This is the VA of the link descriptor in monitor mode destination ring,
  329. * that HAL layer later uses to retrieve the list of MSDU's for a given MPDU.
  330. *
  331. * Return: void *: Virtual Address of the Rx descriptor
  332. */
  333. static inline
  334. void *dp_rx_cookie_2_mon_link_desc_va(struct dp_pdev *pdev,
  335. struct hal_buf_info *buf_info)
  336. {
  337. void *link_desc_va;
  338. /* TODO */
  339. /* Add sanity for cookie */
  340. link_desc_va = pdev->link_desc_banks[buf_info->sw_cookie].base_vaddr +
  341. (buf_info->paddr -
  342. pdev->link_desc_banks[buf_info->sw_cookie].base_paddr);
  343. return link_desc_va;
  344. }
  345. /*
  346. * dp_rx_buffers_replenish() - replenish rxdma ring with rx nbufs
  347. * called during dp rx initialization
  348. * and at the end of dp_rx_process.
  349. *
  350. * @soc: core txrx main context
  351. * @mac_id: mac_id which is one of 3 mac_ids
  352. * @dp_rxdma_srng: dp rxdma circular ring
  353. * @rx_desc_pool: Poiter to free Rx descriptor pool
  354. * @num_req_buffers: number of buffer to be replenished
  355. * @desc_list: list of descs if called from dp_rx_process
  356. * or NULL during dp rx initialization or out of buffer
  357. * interrupt.
  358. * @tail: tail of descs list
  359. * @owner: who owns the nbuf (host, NSS etc...)
  360. * Return: return success or failure
  361. */
  362. QDF_STATUS dp_rx_buffers_replenish(struct dp_soc *dp_soc, uint32_t mac_id,
  363. struct dp_srng *dp_rxdma_srng,
  364. struct rx_desc_pool *rx_desc_pool,
  365. uint32_t num_req_buffers,
  366. union dp_rx_desc_list_elem_t **desc_list,
  367. union dp_rx_desc_list_elem_t **tail,
  368. uint8_t owner);
  369. /**
  370. * dp_rx_link_desc_return() - Return a MPDU link descriptor to HW
  371. * (WBM), following error handling
  372. *
  373. * @soc: core DP main context
  374. * @buf_addr_info: opaque pointer to the REO error ring descriptor
  375. * @buf_addr_info: void pointer to the buffer_addr_info
  376. * Return: QDF_STATUS
  377. */
  378. QDF_STATUS
  379. dp_rx_link_desc_buf_return(struct dp_soc *soc, struct dp_srng *dp_rxdma_srng,
  380. void *buf_addr_info);
  381. #endif /* _DP_RX_H */