dp_rx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /*
  2. * Copyright (c) 2016 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 "dp_types.h"
  19. #include "dp_rx.h"
  20. #include "dp_peer.h"
  21. #include "hal_rx.h"
  22. #include "hal_api.h"
  23. #include "qdf_nbuf.h"
  24. #include <ieee80211.h>
  25. #ifdef RXDMA_OPTIMIZATION
  26. #define RX_BUFFER_ALIGNMENT 128
  27. #else /* RXDMA_OPTIMIZATION */
  28. #define RX_BUFFER_ALIGNMENT 4
  29. #endif /* RXDMA_OPTIMIZATION */
  30. #define RX_BUFFER_SIZE 2048
  31. #define RX_BUFFER_RESERVATION 0
  32. /*
  33. * dp_rx_buffers_replenish() - replenish rxdma ring with rx nbufs
  34. * called during dp rx initialization
  35. * and at the end of dp_rx_process.
  36. *
  37. * @soc: core txrx main context
  38. * @mac_id: mac_id which is one of 3 mac_ids
  39. * @desc_list: list of descs if called from dp_rx_process
  40. * or NULL during dp rx initialization or out of buffer
  41. * interrupt.
  42. * @owner: who owns the nbuf (host, NSS etc...)
  43. * Return: return success or failure
  44. */
  45. QDF_STATUS dp_rx_buffers_replenish(struct dp_soc *dp_soc, uint32_t mac_id,
  46. uint32_t num_req_buffers,
  47. union dp_rx_desc_list_elem_t **desc_list,
  48. union dp_rx_desc_list_elem_t **tail,
  49. uint8_t owner)
  50. {
  51. uint32_t num_alloc_desc;
  52. uint16_t num_desc_to_free = 0;
  53. struct dp_pdev *dp_pdev = dp_soc->pdev_list[mac_id];
  54. uint32_t num_entries_avail;
  55. uint32_t count;
  56. int sync_hw_ptr = 1;
  57. qdf_dma_addr_t paddr;
  58. qdf_nbuf_t rx_netbuf;
  59. void *rxdma_ring_entry;
  60. union dp_rx_desc_list_elem_t *next;
  61. struct dp_srng *dp_rxdma_srng = &dp_pdev->rx_refill_buf_ring;
  62. void *rxdma_srng = dp_rxdma_srng->hal_srng;
  63. if (!rxdma_srng) {
  64. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  65. "rxdma srng not initialized");
  66. return QDF_STATUS_E_FAILURE;
  67. }
  68. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  69. "requested %d buffers for replenish", num_req_buffers);
  70. /*
  71. * if desc_list is NULL, allocate the descs from freelist
  72. */
  73. if (!(*desc_list)) {
  74. num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
  75. num_req_buffers,
  76. desc_list,
  77. tail);
  78. if (!num_alloc_desc) {
  79. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  80. "no free rx_descs in freelist");
  81. return QDF_STATUS_E_NOMEM;
  82. }
  83. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  84. "%d rx desc allocated", num_alloc_desc);
  85. num_req_buffers = num_alloc_desc;
  86. }
  87. hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
  88. num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
  89. rxdma_srng,
  90. sync_hw_ptr);
  91. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  92. "no of availble entries in rxdma ring: %d",
  93. num_entries_avail);
  94. if (num_entries_avail < num_req_buffers) {
  95. num_desc_to_free = num_req_buffers - num_entries_avail;
  96. num_req_buffers = num_entries_avail;
  97. }
  98. for (count = 0; count < num_req_buffers; count++) {
  99. rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
  100. rxdma_srng);
  101. rx_netbuf = qdf_nbuf_alloc(dp_pdev->osif_pdev,
  102. RX_BUFFER_SIZE,
  103. RX_BUFFER_RESERVATION,
  104. RX_BUFFER_ALIGNMENT,
  105. FALSE);
  106. qdf_nbuf_map_single(dp_soc->osdev, rx_netbuf,
  107. QDF_DMA_BIDIRECTIONAL);
  108. paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
  109. next = (*desc_list)->next;
  110. (*desc_list)->rx_desc.nbuf = rx_netbuf;
  111. hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
  112. (*desc_list)->rx_desc.cookie,
  113. owner);
  114. *desc_list = next;
  115. }
  116. hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
  117. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  118. "successfully replenished %d buffers", num_req_buffers);
  119. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  120. "%d rx desc added back to free list", num_desc_to_free);
  121. /*
  122. * add any available free desc back to the free list
  123. */
  124. if (*desc_list)
  125. dp_rx_add_desc_list_to_free_list(dp_soc, desc_list,
  126. tail, mac_id);
  127. return QDF_STATUS_SUCCESS;
  128. }
  129. /**
  130. * dp_rx_intrabss_fwd() - Implements the Intra-BSS forwarding logic
  131. *
  132. * @soc: core txrx main context
  133. * @rx_desc : Rx descriptor
  134. * @msdu_ifno : place holder to store Rx MSDU Details from Rx desc
  135. * @osdu_ifno : place holder to store Rx MPDU Details from Rx desc
  136. * @is_term: Value filled in by this function, if logic determines this
  137. * to be a terminating packet
  138. *
  139. * Return: bool: true if it is forwarded else false
  140. */
  141. static bool
  142. dp_rx_intrabss_fwd(struct dp_soc *soc,
  143. struct dp_rx_desc *rx_desc,
  144. struct hal_rx_msdu_desc_info *msdu_info,
  145. struct hal_rx_mpdu_desc_info *mpdu_info,
  146. bool *is_term)
  147. {
  148. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  149. FL("Intra-BSS forwarding not implemented"));
  150. return false;
  151. }
  152. /**
  153. * dp_rx_process() - Brain of the Rx processing functionality
  154. * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
  155. * @soc: core txrx main context
  156. * @hal_ring: opaque pointer to the HAL Rx Ring, which will be serviced
  157. * @quota: No. of units (packets) that can be serviced in one shot.
  158. *
  159. * This function implements the core of Rx functionality. This is
  160. * expected to handle only non-error frames.
  161. *
  162. * Return: uint32_t: No. of elements processed
  163. */
  164. uint32_t
  165. dp_rx_process(struct dp_soc *soc, void *hal_ring, uint32_t quota)
  166. {
  167. void *hal_soc;
  168. void *ring_desc;
  169. struct dp_rx_desc *rx_desc;
  170. qdf_nbuf_t nbuf;
  171. union dp_rx_desc_list_elem_t *head = NULL;
  172. union dp_rx_desc_list_elem_t *tail = NULL;
  173. bool is_term;
  174. uint32_t rx_bufs_used = 0, rx_buf_cookie, l2_hdr_offset;
  175. uint16_t peer_id;
  176. struct dp_peer *peer = NULL;
  177. struct hal_rx_msdu_desc_info msdu_desc_info;
  178. struct hal_rx_mpdu_desc_info mpdu_desc_info;
  179. qdf_nbuf_t head_msdu, tail_msdu;
  180. enum hal_reo_error_status error;
  181. uint32_t pkt_len;
  182. /* Debug -- Remove later */
  183. qdf_assert(soc && hal_ring);
  184. hal_soc = soc->hal_soc;
  185. /* Debug -- Remove later */
  186. qdf_assert(hal_soc);
  187. if (qdf_unlikely(hal_srng_access_start(hal_soc, hal_ring))) {
  188. /*
  189. * Need API to convert from hal_ring pointer to
  190. * Ring Type / Ring Id combo
  191. */
  192. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  193. FL("HAL RING Access Failed -- %p"), hal_ring);
  194. hal_srng_access_end(hal_soc, hal_ring);
  195. goto done;
  196. }
  197. head_msdu = tail_msdu = NULL;
  198. while (qdf_likely((ring_desc =
  199. hal_srng_dst_get_next(hal_soc, hal_ring))
  200. && quota--)) {
  201. error = HAL_RX_ERROR_STATUS_GET(ring_desc);
  202. if (qdf_unlikely(error == HAL_REO_ERROR_DETECTED)) {
  203. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  204. FL("HAL RING 0x%p:error %d"), hal_ring, error);
  205. /* Don't know how to deal with this -- assert */
  206. qdf_assert(0);
  207. }
  208. rx_buf_cookie = HAL_RX_REO_BUF_COOKIE_GET(ring_desc);
  209. rx_desc = dp_rx_cookie_2_va(soc, rx_buf_cookie);
  210. qdf_assert(rx_desc);
  211. rx_bufs_used++;
  212. /* Get MSDU DESC info */
  213. hal_rx_msdu_desc_info_get(ring_desc, &msdu_desc_info);
  214. nbuf = rx_desc->nbuf;
  215. /* TODO */
  216. /*
  217. * Need a separate API for unmapping based on
  218. * phyiscal address
  219. */
  220. qdf_nbuf_unmap_single(soc->osdev, nbuf,
  221. QDF_DMA_BIDIRECTIONAL);
  222. rx_desc->rx_buf_start = qdf_nbuf_data(nbuf);
  223. /*
  224. * HW structures call this L3 header padding -- even though
  225. * this is actually the offset from the buffer beginning
  226. * where the L2 header begins.
  227. */
  228. l2_hdr_offset =
  229. hal_rx_msdu_end_l3_hdr_padding_get(
  230. rx_desc->rx_buf_start);
  231. pkt_len = msdu_desc_info.msdu_len +
  232. l2_hdr_offset + RX_PKT_TLVS_LEN;
  233. /* Set length in nbuf */
  234. qdf_nbuf_set_pktlen(nbuf, pkt_len);
  235. /*
  236. * Check if DMA completed -- msdu_done is the last bit
  237. * to be written
  238. */
  239. if (!hal_rx_attn_msdu_done_get(rx_desc->rx_buf_start)) {
  240. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  241. FL("HAL RING 0x%p"), hal_ring);
  242. print_hex_dump(KERN_ERR,
  243. "\t Pkt Desc:", DUMP_PREFIX_NONE, 32, 4,
  244. rx_desc->rx_buf_start, 128, false);
  245. qdf_assert(0);
  246. }
  247. /*
  248. * Advance the packet start pointer by total size of
  249. * pre-header TLV's
  250. */
  251. qdf_nbuf_pull_head(nbuf, RX_PKT_TLVS_LEN);
  252. if (l2_hdr_offset)
  253. qdf_nbuf_pull_head(nbuf, l2_hdr_offset);
  254. /* TODO -- Remove -- Just for initial debug */
  255. print_hex_dump(KERN_ERR, "\t Pkt Buf:",
  256. DUMP_PREFIX_NONE, 32, 4,
  257. qdf_nbuf_data(nbuf), 128, false);
  258. /* Get the MPDU DESC info */
  259. hal_rx_mpdu_info_get(ring_desc, &mpdu_desc_info);
  260. /* TODO */
  261. /* WDS Source Port Learning */
  262. /* Intrabss-fwd */
  263. if (dp_rx_intrabss_fwd(soc, rx_desc,
  264. &msdu_desc_info, &mpdu_desc_info, &is_term))
  265. continue; /* Get next descriptor */
  266. peer_id = DP_PEER_METADATA_PEER_ID_GET(
  267. mpdu_desc_info.peer_meta_data);
  268. peer = dp_peer_find_by_id(soc, peer_id);
  269. /* TODO */
  270. /*
  271. * In case of roaming peer object may not be
  272. * immediately available -- need to handle this
  273. * Cannot drop these packets right away.
  274. */
  275. /* Peer lookup failed */
  276. if (!peer) {
  277. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  278. FL("peer look-up failed peer id %d"), peer_id);
  279. /* Drop & free packet */
  280. qdf_nbuf_free(rx_desc->nbuf);
  281. /* Statistics */
  282. /* Add free rx_desc to a free list */
  283. dp_rx_add_to_free_desc_list(&head, &tail, rx_desc);
  284. continue;
  285. }
  286. if (qdf_unlikely(!head_msdu))
  287. head_msdu = rx_desc->nbuf;
  288. else
  289. qdf_nbuf_set_next(tail_msdu, rx_desc->nbuf);
  290. tail_msdu = rx_desc->nbuf;
  291. dp_rx_add_to_free_desc_list(&head, &tail, rx_desc);
  292. }
  293. hal_srng_access_end(hal_soc, hal_ring);
  294. if (!head_msdu)
  295. return 0;
  296. /* Replenish buffers */
  297. /* Assume MAC id = 0, owner = 0 */
  298. dp_rx_buffers_replenish(soc, 0, rx_bufs_used, &head, &tail,
  299. HAL_RX_BUF_RBM_SW3_BM);
  300. qdf_nbuf_set_next(tail_msdu, NULL);
  301. /*
  302. * TODO - this assumes all packets reaped belong to one peer/vdev, which
  303. * may not be true, call this inside while loop for each change in vdev
  304. */
  305. if (qdf_likely(peer->vdev->osif_rx))
  306. peer->vdev->osif_rx(peer->vdev->osif_vdev, head_msdu);
  307. done:
  308. return rx_bufs_used; /* Assume no scale factor for now */
  309. }
  310. /**
  311. * dp_rx_detach() - detach dp rx
  312. * @soc: core txrx main context
  313. *
  314. * This function will detach DP RX into main device context
  315. * will free DP Rx resources.
  316. *
  317. * Return: void
  318. */
  319. void
  320. dp_rx_pdev_detach(struct dp_pdev *pdev)
  321. {
  322. uint8_t pdev_id = pdev->pdev_id;
  323. struct dp_soc *soc = pdev->soc;
  324. dp_rx_desc_pool_free(soc, pdev_id);
  325. qdf_spinlock_destroy(&soc->rx_desc_mutex[pdev_id]);
  326. }
  327. /**
  328. * dp_rx_attach() - attach DP RX
  329. * @soc: core txrx main context
  330. *
  331. * This function will attach a DP RX instance into the main
  332. * device (SOC) context. Will allocate dp rx resource and
  333. * initialize resources.
  334. *
  335. * Return: QDF_STATUS_SUCCESS: success
  336. * QDF_STATUS_E_RESOURCES: Error return
  337. */
  338. QDF_STATUS
  339. dp_rx_pdev_attach(struct dp_pdev *pdev)
  340. {
  341. uint8_t pdev_id = pdev->pdev_id;
  342. struct dp_soc *soc = pdev->soc;
  343. struct dp_srng rxdma_srng;
  344. uint32_t rxdma_entries;
  345. union dp_rx_desc_list_elem_t *desc_list = NULL;
  346. union dp_rx_desc_list_elem_t *tail = NULL;
  347. qdf_spinlock_create(&soc->rx_desc_mutex[pdev_id]);
  348. pdev = soc->pdev_list[pdev_id];
  349. rxdma_srng = pdev->rx_refill_buf_ring;
  350. rxdma_entries = rxdma_srng.alloc_size/hal_srng_get_entrysize(
  351. soc->hal_soc, RXDMA_BUF);
  352. dp_rx_desc_pool_alloc(soc, pdev_id);
  353. /* For Rx buffers, WBM release ring is SW RING 3,for all pdev's */
  354. dp_rx_buffers_replenish(soc, pdev_id, rxdma_entries,
  355. &desc_list, &tail, HAL_RX_BUF_RBM_SW3_BM);
  356. return QDF_STATUS_SUCCESS;
  357. }