dp_rx.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. /*
  2. * Copyright (c) 2016-2018 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. #define DP_RX_DESC_MAGIC 0xdec0de
  41. /**
  42. * struct dp_rx_desc
  43. *
  44. * @nbuf : VA of the "skb" posted
  45. * @rx_buf_start : VA of the original Rx buffer, before
  46. * movement of any skb->data pointer
  47. * @cookie : index into the sw array which holds
  48. * the sw Rx descriptors
  49. * Cookie space is 21 bits:
  50. * lower 18 bits -- index
  51. * upper 3 bits -- pool_id
  52. * @pool_id : pool Id for which this allocated.
  53. * Can only be used if there is no flow
  54. * steering
  55. * @in_use rx_desc is in use
  56. * @unmapped used to mark rx_desc an unmapped if the corresponding
  57. * nbuf is already unmapped
  58. */
  59. struct dp_rx_desc {
  60. qdf_nbuf_t nbuf;
  61. uint8_t *rx_buf_start;
  62. uint32_t cookie;
  63. uint8_t pool_id;
  64. #ifdef RX_DESC_DEBUG_CHECK
  65. uint32_t magic;
  66. #endif
  67. uint8_t in_use:1,
  68. unmapped:1;
  69. };
  70. #define RX_DESC_COOKIE_INDEX_SHIFT 0
  71. #define RX_DESC_COOKIE_INDEX_MASK 0x3ffff /* 18 bits */
  72. #define RX_DESC_COOKIE_POOL_ID_SHIFT 18
  73. #define RX_DESC_COOKIE_POOL_ID_MASK 0x1c0000
  74. #define DP_RX_DESC_COOKIE_POOL_ID_GET(_cookie) \
  75. (((_cookie) & RX_DESC_COOKIE_POOL_ID_MASK) >> \
  76. RX_DESC_COOKIE_POOL_ID_SHIFT)
  77. #define DP_RX_DESC_COOKIE_INDEX_GET(_cookie) \
  78. (((_cookie) & RX_DESC_COOKIE_INDEX_MASK) >> \
  79. RX_DESC_COOKIE_INDEX_SHIFT)
  80. /*
  81. *dp_rx_xor_block() - xor block of data
  82. *@b: destination data block
  83. *@a: source data block
  84. *@len: length of the data to process
  85. *
  86. *Returns: None
  87. */
  88. static inline void dp_rx_xor_block(uint8_t *b, const uint8_t *a, qdf_size_t len)
  89. {
  90. qdf_size_t i;
  91. for (i = 0; i < len; i++)
  92. b[i] ^= a[i];
  93. }
  94. /*
  95. *dp_rx_rotl() - rotate the bits left
  96. *@val: unsigned integer input value
  97. *@bits: number of bits
  98. *
  99. *Returns: Integer with left rotated by number of 'bits'
  100. */
  101. static inline uint32_t dp_rx_rotl(uint32_t val, int bits)
  102. {
  103. return (val << bits) | (val >> (32 - bits));
  104. }
  105. /*
  106. *dp_rx_rotr() - rotate the bits right
  107. *@val: unsigned integer input value
  108. *@bits: number of bits
  109. *
  110. *Returns: Integer with right rotated by number of 'bits'
  111. */
  112. static inline uint32_t dp_rx_rotr(uint32_t val, int bits)
  113. {
  114. return (val >> bits) | (val << (32 - bits));
  115. }
  116. /*
  117. *dp_rx_xswap() - swap the bits left
  118. *@val: unsigned integer input value
  119. *
  120. *Returns: Integer with bits swapped
  121. */
  122. static inline uint32_t dp_rx_xswap(uint32_t val)
  123. {
  124. return ((val & 0x00ff00ff) << 8) | ((val & 0xff00ff00) >> 8);
  125. }
  126. /*
  127. *dp_rx_get_le32_split() - get little endian 32 bits split
  128. *@b0: byte 0
  129. *@b1: byte 1
  130. *@b2: byte 2
  131. *@b3: byte 3
  132. *
  133. *Returns: Integer with split little endian 32 bits
  134. */
  135. static inline uint32_t dp_rx_get_le32_split(uint8_t b0, uint8_t b1, uint8_t b2,
  136. uint8_t b3)
  137. {
  138. return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24);
  139. }
  140. /*
  141. *dp_rx_get_le32() - get little endian 32 bits
  142. *@b0: byte 0
  143. *@b1: byte 1
  144. *@b2: byte 2
  145. *@b3: byte 3
  146. *
  147. *Returns: Integer with little endian 32 bits
  148. */
  149. static inline uint32_t dp_rx_get_le32(const uint8_t *p)
  150. {
  151. return dp_rx_get_le32_split(p[0], p[1], p[2], p[3]);
  152. }
  153. /*
  154. * dp_rx_put_le32() - put little endian 32 bits
  155. * @p: destination char array
  156. * @v: source 32-bit integer
  157. *
  158. * Returns: None
  159. */
  160. static inline void dp_rx_put_le32(uint8_t *p, uint32_t v)
  161. {
  162. p[0] = (v) & 0xff;
  163. p[1] = (v >> 8) & 0xff;
  164. p[2] = (v >> 16) & 0xff;
  165. p[3] = (v >> 24) & 0xff;
  166. }
  167. /* Extract michal mic block of data */
  168. #define dp_rx_michael_block(l, r) \
  169. do { \
  170. r ^= dp_rx_rotl(l, 17); \
  171. l += r; \
  172. r ^= dp_rx_xswap(l); \
  173. l += r; \
  174. r ^= dp_rx_rotl(l, 3); \
  175. l += r; \
  176. r ^= dp_rx_rotr(l, 2); \
  177. l += r; \
  178. } while (0)
  179. /**
  180. * struct dp_rx_desc_list_elem_t
  181. *
  182. * @next : Next pointer to form free list
  183. * @rx_desc : DP Rx descriptor
  184. */
  185. union dp_rx_desc_list_elem_t {
  186. union dp_rx_desc_list_elem_t *next;
  187. struct dp_rx_desc rx_desc;
  188. };
  189. /**
  190. * dp_rx_cookie_2_va_rxdma_buf() - Converts cookie to a virtual address of
  191. * the Rx descriptor on Rx DMA source ring buffer
  192. * @soc: core txrx main context
  193. * @cookie: cookie used to lookup virtual address
  194. *
  195. * Return: void *: Virtual Address of the Rx descriptor
  196. */
  197. static inline
  198. void *dp_rx_cookie_2_va_rxdma_buf(struct dp_soc *soc, uint32_t cookie)
  199. {
  200. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  201. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  202. /* TODO */
  203. /* Add sanity for pool_id & index */
  204. return &(soc->rx_desc_buf[pool_id].array[index].rx_desc);
  205. }
  206. /**
  207. * dp_rx_cookie_2_va_mon_buf() - Converts cookie to a virtual address of
  208. * the Rx descriptor on monitor ring buffer
  209. * @soc: core txrx main context
  210. * @cookie: cookie used to lookup virtual address
  211. *
  212. * Return: void *: Virtual Address of the Rx descriptor
  213. */
  214. static inline
  215. void *dp_rx_cookie_2_va_mon_buf(struct dp_soc *soc, uint32_t cookie)
  216. {
  217. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  218. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  219. /* TODO */
  220. /* Add sanity for pool_id & index */
  221. return &(soc->rx_desc_mon[pool_id].array[index].rx_desc);
  222. }
  223. /**
  224. * dp_rx_cookie_2_va_mon_status() - Converts cookie to a virtual address of
  225. * the Rx descriptor on monitor status ring buffer
  226. * @soc: core txrx main context
  227. * @cookie: cookie used to lookup virtual address
  228. *
  229. * Return: void *: Virtual Address of the Rx descriptor
  230. */
  231. static inline
  232. void *dp_rx_cookie_2_va_mon_status(struct dp_soc *soc, uint32_t cookie)
  233. {
  234. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  235. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  236. /* TODO */
  237. /* Add sanity for pool_id & index */
  238. return &(soc->rx_desc_status[pool_id].array[index].rx_desc);
  239. }
  240. void dp_rx_add_desc_list_to_free_list(struct dp_soc *soc,
  241. union dp_rx_desc_list_elem_t **local_desc_list,
  242. union dp_rx_desc_list_elem_t **tail,
  243. uint16_t pool_id,
  244. struct rx_desc_pool *rx_desc_pool);
  245. uint16_t dp_rx_get_free_desc_list(struct dp_soc *soc, uint32_t pool_id,
  246. struct rx_desc_pool *rx_desc_pool,
  247. uint16_t num_descs,
  248. union dp_rx_desc_list_elem_t **desc_list,
  249. union dp_rx_desc_list_elem_t **tail);
  250. QDF_STATUS dp_rx_pdev_attach(struct dp_pdev *pdev);
  251. void dp_rx_pdev_detach(struct dp_pdev *pdev);
  252. uint32_t
  253. dp_rx_process(struct dp_intr *int_ctx, void *hal_ring, uint32_t quota);
  254. uint32_t dp_rx_err_process(struct dp_soc *soc, void *hal_ring, uint32_t quota);
  255. uint32_t
  256. dp_rx_wbm_err_process(struct dp_soc *soc, void *hal_ring, uint32_t quota);
  257. void
  258. dp_rx_sg_create(qdf_nbuf_t nbuf,
  259. uint8_t *rx_tlv_hdr,
  260. uint16_t *mpdu_len,
  261. bool *is_first_frag,
  262. uint16_t *frag_list_len,
  263. qdf_nbuf_t *head_frag_nbuf,
  264. qdf_nbuf_t *frag_list_head,
  265. qdf_nbuf_t *frag_list_tail);
  266. QDF_STATUS dp_rx_desc_pool_alloc(struct dp_soc *soc,
  267. uint32_t pool_id,
  268. uint32_t pool_size,
  269. struct rx_desc_pool *rx_desc_pool);
  270. void dp_rx_desc_pool_free(struct dp_soc *soc,
  271. uint32_t pool_id,
  272. struct rx_desc_pool *rx_desc_pool);
  273. void dp_rx_deliver_raw(struct dp_vdev *vdev, qdf_nbuf_t nbuf_list,
  274. struct dp_peer *peer);
  275. /**
  276. * dp_rx_add_to_free_desc_list() - Adds to a local free descriptor list
  277. *
  278. * @head: pointer to the head of local free list
  279. * @tail: pointer to the tail of local free list
  280. * @new: new descriptor that is added to the free list
  281. *
  282. * Return: void:
  283. */
  284. static inline
  285. void dp_rx_add_to_free_desc_list(union dp_rx_desc_list_elem_t **head,
  286. union dp_rx_desc_list_elem_t **tail,
  287. struct dp_rx_desc *new)
  288. {
  289. qdf_assert(head && new);
  290. new->nbuf = NULL;
  291. new->in_use = 0;
  292. new->unmapped = 0;
  293. ((union dp_rx_desc_list_elem_t *)new)->next = *head;
  294. *head = (union dp_rx_desc_list_elem_t *)new;
  295. if (*tail == NULL)
  296. *tail = *head;
  297. }
  298. /**
  299. * dp_rx_wds_srcport_learn() - Add or update the STA PEER which
  300. * is behind the WDS repeater.
  301. *
  302. * @soc: core txrx main context
  303. * @rx_tlv_hdr: base address of RX TLV header
  304. * @ta_peer: WDS repeater peer
  305. * @nbuf: rx pkt
  306. *
  307. * Return: void:
  308. */
  309. #ifdef FEATURE_WDS
  310. static inline void
  311. dp_rx_wds_srcport_learn(struct dp_soc *soc,
  312. uint8_t *rx_tlv_hdr,
  313. struct dp_peer *ta_peer,
  314. qdf_nbuf_t nbuf)
  315. {
  316. uint16_t sa_sw_peer_id = hal_rx_msdu_end_sa_sw_peer_id_get(rx_tlv_hdr);
  317. uint32_t flags = IEEE80211_NODE_F_WDS_HM;
  318. uint32_t ret = 0;
  319. uint8_t wds_src_mac[IEEE80211_ADDR_LEN];
  320. /* Do wds source port learning only if it is a 4-address mpdu */
  321. if (!(qdf_nbuf_is_rx_chfrag_start(nbuf) &&
  322. hal_rx_get_mpdu_mac_ad4_valid(rx_tlv_hdr)))
  323. return;
  324. memcpy(wds_src_mac, (qdf_nbuf_data(nbuf) + IEEE80211_ADDR_LEN),
  325. IEEE80211_ADDR_LEN);
  326. if (qdf_unlikely(!hal_rx_msdu_end_sa_is_valid_get(rx_tlv_hdr))) {
  327. ret = dp_peer_add_ast(soc,
  328. ta_peer,
  329. wds_src_mac,
  330. CDP_TXRX_AST_TYPE_WDS,
  331. flags);
  332. } else {
  333. /*
  334. * Get the AST entry from HW SA index and mark it as active
  335. */
  336. struct dp_ast_entry *ast;
  337. uint16_t sa_idx = hal_rx_msdu_end_sa_idx_get(rx_tlv_hdr);
  338. ast = soc->ast_table[sa_idx];
  339. /*
  340. * Ensure we are updating the right AST entry by
  341. * validating ast_idx.
  342. * There is a possibility we might arrive here without
  343. * AST MAP event , so this check is mandatory
  344. */
  345. if (ast && (ast->ast_idx == sa_idx)) {
  346. ast->is_active = TRUE;
  347. }
  348. if (ast && sa_sw_peer_id != ta_peer->peer_ids[0])
  349. dp_peer_update_ast(soc, ta_peer, ast, flags);
  350. }
  351. return;
  352. }
  353. #else
  354. static inline void
  355. dp_rx_wds_srcport_learn(struct dp_soc *soc,
  356. uint8_t *rx_tlv_hdr,
  357. struct dp_peer *ta_peer,
  358. qdf_nbuf_t nbuf)
  359. {
  360. }
  361. #endif
  362. uint8_t dp_rx_process_invalid_peer(struct dp_soc *soc, qdf_nbuf_t nbuf);
  363. void dp_rx_process_invalid_peer_wrapper(struct dp_soc *soc,
  364. qdf_nbuf_t mpdu, bool mpdu_done);
  365. void dp_rx_process_mic_error(struct dp_soc *soc, qdf_nbuf_t nbuf, uint8_t *rx_tlv_hdr);
  366. #define DP_RX_LIST_APPEND(head, tail, elem) \
  367. do { \
  368. if (!(head)) { \
  369. (head) = (elem); \
  370. } else { \
  371. qdf_nbuf_set_next((tail), (elem)); \
  372. } \
  373. (tail) = (elem); \
  374. qdf_nbuf_set_next((tail), NULL); \
  375. } while (0)
  376. #ifndef BUILD_X86
  377. static inline int check_x86_paddr(struct dp_soc *dp_soc, qdf_nbuf_t *rx_netbuf,
  378. qdf_dma_addr_t *paddr, struct dp_pdev *pdev)
  379. {
  380. return QDF_STATUS_SUCCESS;
  381. }
  382. #else
  383. #define MAX_RETRY 100
  384. static inline int check_x86_paddr(struct dp_soc *dp_soc, qdf_nbuf_t *rx_netbuf,
  385. qdf_dma_addr_t *paddr, struct dp_pdev *pdev)
  386. {
  387. uint32_t nbuf_retry = 0;
  388. int32_t ret;
  389. const uint32_t x86_phy_addr = 0x50000000;
  390. /*
  391. * in M2M emulation platforms (x86) the memory below 0x50000000
  392. * is reserved for target use, so any memory allocated in this
  393. * region should not be used by host
  394. */
  395. do {
  396. if (qdf_likely(*paddr > x86_phy_addr))
  397. return QDF_STATUS_SUCCESS;
  398. else {
  399. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  400. "phy addr %pK exceded 0x50000000 trying again\n",
  401. paddr);
  402. nbuf_retry++;
  403. if ((*rx_netbuf)) {
  404. qdf_nbuf_unmap_single(dp_soc->osdev, *rx_netbuf,
  405. QDF_DMA_BIDIRECTIONAL);
  406. /* Not freeing buffer intentionally.
  407. * Observed that same buffer is getting
  408. * re-allocated resulting in longer load time
  409. * WMI init timeout.
  410. * This buffer is anyway not useful so skip it.
  411. **/
  412. }
  413. *rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
  414. RX_BUFFER_SIZE,
  415. RX_BUFFER_RESERVATION,
  416. RX_BUFFER_ALIGNMENT,
  417. FALSE);
  418. if (qdf_unlikely(!(*rx_netbuf)))
  419. return QDF_STATUS_E_FAILURE;
  420. ret = qdf_nbuf_map_single(dp_soc->osdev, *rx_netbuf,
  421. QDF_DMA_BIDIRECTIONAL);
  422. if (qdf_unlikely(ret == QDF_STATUS_E_FAILURE)) {
  423. qdf_nbuf_free(*rx_netbuf);
  424. *rx_netbuf = NULL;
  425. continue;
  426. }
  427. *paddr = qdf_nbuf_get_frag_paddr(*rx_netbuf, 0);
  428. }
  429. } while (nbuf_retry < MAX_RETRY);
  430. if ((*rx_netbuf)) {
  431. qdf_nbuf_unmap_single(dp_soc->osdev, *rx_netbuf,
  432. QDF_DMA_BIDIRECTIONAL);
  433. qdf_nbuf_free(*rx_netbuf);
  434. }
  435. return QDF_STATUS_E_FAILURE;
  436. }
  437. #endif
  438. /**
  439. * dp_rx_cookie_2_link_desc_va() - Converts cookie to a virtual address of
  440. * the MSDU Link Descriptor
  441. * @soc: core txrx main context
  442. * @buf_info: buf_info include cookie that used to lookup virtual address of
  443. * link descriptor Normally this is just an index into a per SOC array.
  444. *
  445. * This is the VA of the link descriptor, that HAL layer later uses to
  446. * retrieve the list of MSDU's for a given MPDU.
  447. *
  448. * Return: void *: Virtual Address of the Rx descriptor
  449. */
  450. static inline
  451. void *dp_rx_cookie_2_link_desc_va(struct dp_soc *soc,
  452. struct hal_buf_info *buf_info)
  453. {
  454. void *link_desc_va;
  455. uint32_t bank_id = LINK_DESC_COOKIE_BANK_ID(buf_info->sw_cookie);
  456. /* TODO */
  457. /* Add sanity for cookie */
  458. link_desc_va = soc->link_desc_banks[bank_id].base_vaddr +
  459. (buf_info->paddr -
  460. soc->link_desc_banks[bank_id].base_paddr);
  461. return link_desc_va;
  462. }
  463. /**
  464. * dp_rx_cookie_2_mon_link_desc_va() - Converts cookie to a virtual address of
  465. * the MSDU Link Descriptor
  466. * @pdev: core txrx pdev context
  467. * @buf_info: buf_info includes cookie that used to lookup virtual address of
  468. * link descriptor. Normally this is just an index into a per pdev array.
  469. *
  470. * This is the VA of the link descriptor in monitor mode destination ring,
  471. * that HAL layer later uses to retrieve the list of MSDU's for a given MPDU.
  472. *
  473. * Return: void *: Virtual Address of the Rx descriptor
  474. */
  475. static inline
  476. void *dp_rx_cookie_2_mon_link_desc_va(struct dp_pdev *pdev,
  477. struct hal_buf_info *buf_info)
  478. {
  479. void *link_desc_va;
  480. /* TODO */
  481. /* Add sanity for cookie */
  482. link_desc_va = pdev->link_desc_banks[buf_info->sw_cookie].base_vaddr +
  483. (buf_info->paddr -
  484. pdev->link_desc_banks[buf_info->sw_cookie].base_paddr);
  485. return link_desc_va;
  486. }
  487. /**
  488. * dp_rx_defrag_concat() - Concatenate the fragments
  489. *
  490. * @dst: destination pointer to the buffer
  491. * @src: source pointer from where the fragment payload is to be copied
  492. *
  493. * Return: QDF_STATUS
  494. */
  495. static inline QDF_STATUS dp_rx_defrag_concat(qdf_nbuf_t dst, qdf_nbuf_t src)
  496. {
  497. /*
  498. * Inside qdf_nbuf_cat, if it is necessary to reallocate dst
  499. * to provide space for src, the headroom portion is copied from
  500. * the original dst buffer to the larger new dst buffer.
  501. * (This is needed, because the headroom of the dst buffer
  502. * contains the rx desc.)
  503. */
  504. if (qdf_nbuf_cat(dst, src))
  505. return QDF_STATUS_E_DEFRAG_ERROR;
  506. return QDF_STATUS_SUCCESS;
  507. }
  508. /*
  509. * dp_rx_ast_set_active() - set the active flag of the astentry
  510. * corresponding to a hw index.
  511. * @soc: core txrx main context
  512. * @sa_idx: hw idx
  513. * @is_active: active flag
  514. *
  515. */
  516. #ifdef FEATURE_WDS
  517. static inline QDF_STATUS dp_rx_ast_set_active(struct dp_soc *soc, uint16_t sa_idx, bool is_active)
  518. {
  519. struct dp_ast_entry *ast;
  520. qdf_spin_lock_bh(&soc->ast_lock);
  521. ast = soc->ast_table[sa_idx];
  522. /*
  523. * Ensure we are updating the right AST entry by
  524. * validating ast_idx.
  525. * There is a possibility we might arrive here without
  526. * AST MAP event , so this check is mandatory
  527. */
  528. if (ast && (ast->ast_idx == sa_idx)) {
  529. ast->is_active = is_active;
  530. qdf_spin_unlock_bh(&soc->ast_lock);
  531. return QDF_STATUS_SUCCESS;
  532. }
  533. qdf_spin_unlock_bh(&soc->ast_lock);
  534. return QDF_STATUS_E_FAILURE;
  535. }
  536. #else
  537. static inline QDF_STATUS dp_rx_ast_set_active(struct dp_soc *soc, uint16_t sa_idx, bool is_active)
  538. {
  539. return QDF_STATUS_SUCCESS;
  540. }
  541. #endif
  542. /*
  543. * check_qwrap_multicast_loopback() - Check if rx packet is a loopback packet.
  544. * In qwrap mode, packets originated from
  545. * any vdev should not loopback and
  546. * should be dropped.
  547. * @vdev: vdev on which rx packet is received
  548. * @nbuf: rx pkt
  549. *
  550. */
  551. #if ATH_SUPPORT_WRAP
  552. static inline bool check_qwrap_multicast_loopback(struct dp_vdev *vdev,
  553. qdf_nbuf_t nbuf)
  554. {
  555. struct dp_vdev *psta_vdev;
  556. struct dp_pdev *pdev = vdev->pdev;
  557. uint8_t *data = qdf_nbuf_data(nbuf);
  558. if (qdf_unlikely(vdev->proxysta_vdev)) {
  559. /* In qwrap isolation mode, allow loopback packets as all
  560. * packets go to RootAP and Loopback on the mpsta.
  561. */
  562. if (vdev->isolation_vdev)
  563. return false;
  564. TAILQ_FOREACH(psta_vdev, &pdev->vdev_list, vdev_list_elem) {
  565. if (qdf_unlikely(psta_vdev->proxysta_vdev &&
  566. !qdf_mem_cmp(psta_vdev->mac_addr.raw,
  567. &data[DP_MAC_ADDR_LEN], DP_MAC_ADDR_LEN))) {
  568. /* Drop packet if source address is equal to
  569. * any of the vdev addresses.
  570. */
  571. return true;
  572. }
  573. }
  574. }
  575. return false;
  576. }
  577. #else
  578. static inline bool check_qwrap_multicast_loopback(struct dp_vdev *vdev,
  579. qdf_nbuf_t nbuf)
  580. {
  581. return false;
  582. }
  583. #endif
  584. /*
  585. * dp_rx_buffers_replenish() - replenish rxdma ring with rx nbufs
  586. * called during dp rx initialization
  587. * and at the end of dp_rx_process.
  588. *
  589. * @soc: core txrx main context
  590. * @mac_id: mac_id which is one of 3 mac_ids
  591. * @dp_rxdma_srng: dp rxdma circular ring
  592. * @rx_desc_pool: Poiter to free Rx descriptor pool
  593. * @num_req_buffers: number of buffer to be replenished
  594. * @desc_list: list of descs if called from dp_rx_process
  595. * or NULL during dp rx initialization or out of buffer
  596. * interrupt.
  597. * @tail: tail of descs list
  598. * @owner: who owns the nbuf (host, NSS etc...)
  599. * Return: return success or failure
  600. */
  601. QDF_STATUS dp_rx_buffers_replenish(struct dp_soc *dp_soc, uint32_t mac_id,
  602. struct dp_srng *dp_rxdma_srng,
  603. struct rx_desc_pool *rx_desc_pool,
  604. uint32_t num_req_buffers,
  605. union dp_rx_desc_list_elem_t **desc_list,
  606. union dp_rx_desc_list_elem_t **tail,
  607. uint8_t owner);
  608. /**
  609. * dp_rx_link_desc_return() - Return a MPDU link descriptor to HW
  610. * (WBM), following error handling
  611. *
  612. * @soc: core DP main context
  613. * @buf_addr_info: opaque pointer to the REO error ring descriptor
  614. * @buf_addr_info: void pointer to the buffer_addr_info
  615. * @bm_action: put to idle_list or release to msdu_list
  616. * Return: QDF_STATUS
  617. */
  618. QDF_STATUS
  619. dp_rx_link_desc_return(struct dp_soc *soc, void *ring_desc, uint8_t bm_action);
  620. QDF_STATUS
  621. dp_rx_link_desc_buf_return(struct dp_soc *soc, struct dp_srng *dp_rxdma_srng,
  622. void *buf_addr_info, uint8_t bm_action);
  623. /**
  624. * dp_rx_link_desc_return_by_addr - Return a MPDU link descriptor to
  625. * (WBM) by address
  626. *
  627. * @soc: core DP main context
  628. * @link_desc_addr: link descriptor addr
  629. *
  630. * Return: QDF_STATUS
  631. */
  632. QDF_STATUS
  633. dp_rx_link_desc_return_by_addr(struct dp_soc *soc, void *link_desc_addr,
  634. uint8_t bm_action);
  635. uint32_t
  636. dp_rxdma_err_process(struct dp_soc *soc, uint32_t mac_id,
  637. uint32_t quota);
  638. void dp_rx_fill_mesh_stats(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  639. uint8_t *rx_tlv_hdr, struct dp_peer *peer);
  640. QDF_STATUS dp_rx_filter_mesh_packets(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  641. uint8_t *rx_tlv_hdr);
  642. int dp_wds_rx_policy_check(uint8_t *rx_tlv_hdr, struct dp_vdev *vdev,
  643. struct dp_peer *peer, int rx_mcast);
  644. qdf_nbuf_t
  645. dp_rx_nbuf_prepare(struct dp_soc *soc, struct dp_pdev *pdev);
  646. #endif /* _DP_RX_H */