dp_rx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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. "%s %d : Intra-BSS forwarding not implemented",
  150. __func__, __LINE__);
  151. return false;
  152. }
  153. /**
  154. * dp_rx_process() - Brain of the Rx processing functionality
  155. * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
  156. * @soc: core txrx main context
  157. * @hal_ring: opaque pointer to the HAL Rx Ring, which will be serviced
  158. * @quota: No. of units (packets) that can be serviced in one shot.
  159. *
  160. * This function implements the core of Rx functionality. This is
  161. * expected to handle only non-error frames.
  162. *
  163. * Return: uint32_t: No. of elements processed
  164. */
  165. uint32_t
  166. dp_rx_process(struct dp_soc *soc, void *hal_ring, uint32_t quota)
  167. {
  168. void *hal_soc;
  169. void *ring_desc;
  170. struct dp_rx_desc *rx_desc;
  171. qdf_nbuf_t nbuf;
  172. union dp_rx_desc_list_elem_t *head = NULL;
  173. union dp_rx_desc_list_elem_t *tail = NULL;
  174. bool is_term;
  175. uint32_t rx_bufs_used = 0, rx_buf_cookie, l2_hdr_offset;
  176. uint16_t peer_id;
  177. struct dp_peer *peer = NULL;
  178. struct hal_rx_msdu_desc_info msdu_desc_info;
  179. struct hal_rx_mpdu_desc_info mpdu_desc_info;
  180. qdf_nbuf_t head_msdu, tail_msdu;
  181. enum hal_reo_error_status error;
  182. uint32_t pkt_len;
  183. /* Debug -- Remove later */
  184. qdf_assert(soc && hal_ring);
  185. hal_soc = soc->hal_soc;
  186. /* Debug -- Remove later */
  187. qdf_assert(hal_soc);
  188. if (qdf_unlikely(hal_srng_access_start(hal_soc, hal_ring))) {
  189. /*
  190. * Need API to convert from hal_ring pointer to
  191. * Ring Type / Ring Id combo
  192. */
  193. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  194. "%s %d : HAL RING Access Failed -- %p\n",
  195. __func__, __LINE__, hal_ring);
  196. hal_srng_access_end(hal_soc, hal_ring);
  197. goto done;
  198. }
  199. head_msdu = tail_msdu = NULL;
  200. while (qdf_likely((ring_desc =
  201. hal_srng_dst_get_next(hal_soc, hal_ring))
  202. && quota--)) {
  203. error = HAL_RX_ERROR_STATUS_GET(ring_desc);
  204. if (qdf_unlikely(error == HAL_REO_ERROR_DETECTED)) {
  205. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  206. "%s %d : HAL RING 0x%p:error %d\n",
  207. __func__, __LINE__, hal_ring, error);
  208. /* Don't know how to deal with this -- assert */
  209. qdf_assert(0);
  210. }
  211. rx_buf_cookie = HAL_RX_REO_BUF_COOKIE_GET(ring_desc);
  212. rx_desc = dp_rx_cookie_2_va(soc, rx_buf_cookie);
  213. qdf_assert(rx_desc);
  214. rx_bufs_used++;
  215. /* Get MSDU DESC info */
  216. hal_rx_msdu_desc_info_get(ring_desc, &msdu_desc_info);
  217. nbuf = rx_desc->nbuf;
  218. /* TODO */
  219. /*
  220. * Need a separate API for unmapping based on
  221. * phyiscal address
  222. */
  223. qdf_nbuf_unmap_single(soc->osdev, nbuf,
  224. QDF_DMA_BIDIRECTIONAL);
  225. rx_desc->rx_buf_start = qdf_nbuf_data(nbuf);
  226. /*
  227. * HW structures call this L3 header padding -- even though
  228. * this is actually the offset from the buffer beginning
  229. * where the L2 header begins.
  230. */
  231. l2_hdr_offset =
  232. hal_rx_msdu_end_l3_hdr_padding_get(
  233. rx_desc->rx_buf_start);
  234. pkt_len = msdu_desc_info.msdu_len +
  235. l2_hdr_offset + RX_PKT_TLVS_LEN;
  236. /* Set length in nbuf */
  237. qdf_nbuf_set_pktlen(nbuf, pkt_len);
  238. /*
  239. * Check if DMA completed -- msdu_done is the last bit
  240. * to be written
  241. */
  242. if (!hal_rx_attn_msdu_done_get(rx_desc->rx_buf_start)) {
  243. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  244. "%s %d : HAL RING 0x%p\n",
  245. __func__, __LINE__, hal_ring);
  246. print_hex_dump(KERN_ERR,
  247. "\t Pkt Desc:", DUMP_PREFIX_NONE, 32, 4,
  248. rx_desc->rx_buf_start, 128, false);
  249. qdf_assert(0);
  250. }
  251. /*
  252. * Advance the packet start pointer by total size of
  253. * pre-header TLV's
  254. */
  255. qdf_nbuf_pull_head(nbuf, RX_PKT_TLVS_LEN);
  256. if (l2_hdr_offset)
  257. qdf_nbuf_pull_head(nbuf, l2_hdr_offset);
  258. /* TODO -- Remove -- Just for initial debug */
  259. print_hex_dump(KERN_ERR, "\t Pkt Buf:",
  260. DUMP_PREFIX_NONE, 32, 4,
  261. qdf_nbuf_data(nbuf), 128, false);
  262. /* Get the MPDU DESC info */
  263. hal_rx_mpdu_info_get(ring_desc, &mpdu_desc_info);
  264. /* TODO */
  265. /* WDS Source Port Learning */
  266. /* Intrabss-fwd */
  267. if (dp_rx_intrabss_fwd(soc, rx_desc,
  268. &msdu_desc_info, &mpdu_desc_info, &is_term))
  269. continue; /* Get next descriptor */
  270. peer_id = DP_PEER_METADATA_PEER_ID_GET(
  271. mpdu_desc_info.peer_meta_data);
  272. peer = dp_peer_find_by_id(soc, peer_id);
  273. /* TODO */
  274. /*
  275. * In case of roaming peer object may not be
  276. * immediately available -- need to handle this
  277. * Cannot drop these packets right away.
  278. */
  279. /* Peer lookup failed */
  280. if (!peer) {
  281. /* Drop & free packet */
  282. qdf_nbuf_free(rx_desc->nbuf);
  283. /* Statistics */
  284. /* Add free rx_desc to a free list */
  285. dp_rx_add_to_free_desc_list(&head, &tail, rx_desc);
  286. continue;
  287. }
  288. if (qdf_unlikely(!head_msdu))
  289. head_msdu = rx_desc->nbuf;
  290. else
  291. qdf_nbuf_set_next(tail_msdu, rx_desc->nbuf);
  292. tail_msdu = rx_desc->nbuf;
  293. dp_rx_add_to_free_desc_list(&head, &tail, rx_desc);
  294. }
  295. hal_srng_access_end(hal_soc, hal_ring);
  296. if (!head_msdu)
  297. return 0;
  298. /* Replenish buffers */
  299. /* Assume MAC id = 0, owner = 0 */
  300. dp_rx_buffers_replenish(soc, 0, rx_bufs_used, &head, &tail,
  301. HAL_RX_BUF_RBM_SW3_BM);
  302. qdf_nbuf_set_next(tail_msdu, NULL);
  303. /*
  304. * TODO - this assumes all packets reaped belong to one peer/vdev, which
  305. * may not be true, call this inside while loop for each change in vdev
  306. */
  307. if (qdf_likely(peer->vdev->osif_rx))
  308. peer->vdev->osif_rx(peer->vdev->osif_vdev, head_msdu);
  309. done:
  310. return rx_bufs_used; /* Assume no scale factor for now */
  311. }
  312. /**
  313. * dp_rx_detach() - detach dp rx
  314. * @soc: core txrx main context
  315. *
  316. * This function will detach DP RX into main device context
  317. * will free DP Rx resources.
  318. *
  319. * Return: void
  320. */
  321. void
  322. dp_rx_pdev_detach(struct dp_pdev *pdev)
  323. {
  324. uint8_t pdev_id = pdev->pdev_id;
  325. struct dp_soc *soc = pdev->soc;
  326. dp_rx_desc_pool_free(soc, pdev_id);
  327. qdf_spinlock_destroy(&soc->rx_desc_mutex[pdev_id]);
  328. }
  329. /**
  330. * dp_rx_attach() - attach DP RX
  331. * @soc: core txrx main context
  332. *
  333. * This function will attach a DP RX instance into the main
  334. * device (SOC) context. Will allocate dp rx resource and
  335. * initialize resources.
  336. *
  337. * Return: QDF_STATUS_SUCCESS: success
  338. * QDF_STATUS_E_RESOURCES: Error return
  339. */
  340. QDF_STATUS
  341. dp_rx_pdev_attach(struct dp_pdev *pdev)
  342. {
  343. uint8_t pdev_id = pdev->pdev_id;
  344. struct dp_soc *soc = pdev->soc;
  345. struct dp_srng rxdma_srng;
  346. uint32_t rxdma_entries;
  347. union dp_rx_desc_list_elem_t *desc_list = NULL;
  348. union dp_rx_desc_list_elem_t *tail = NULL;
  349. qdf_spinlock_create(&soc->rx_desc_mutex[pdev_id]);
  350. pdev = soc->pdev_list[pdev_id];
  351. rxdma_srng = pdev->rx_refill_buf_ring;
  352. rxdma_entries = rxdma_srng.alloc_size/hal_srng_get_entrysize(
  353. soc->hal_soc, RXDMA_BUF);
  354. dp_rx_desc_pool_alloc(soc, pdev_id);
  355. /* For Rx buffers, WBM release ring is SW RING 3,for all pdev's */
  356. dp_rx_buffers_replenish(soc, pdev_id, rxdma_entries,
  357. &desc_list, &tail, HAL_RX_BUF_RBM_SW3_BM);
  358. return QDF_STATUS_SUCCESS;
  359. }