dp_rx.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  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. #include "dp_internal.h"
  24. #ifdef RXDMA_OPTIMIZATION
  25. #define RX_BUFFER_ALIGNMENT 128
  26. #else /* RXDMA_OPTIMIZATION */
  27. #define RX_BUFFER_ALIGNMENT 4
  28. #endif /* RXDMA_OPTIMIZATION */
  29. #ifdef QCA_HOST2FW_RXBUF_RING
  30. #define DP_WBM2SW_RBM HAL_RX_BUF_RBM_SW1_BM
  31. #else
  32. #define DP_WBM2SW_RBM HAL_RX_BUF_RBM_SW3_BM
  33. #endif
  34. #define RX_BUFFER_SIZE 2048
  35. #define RX_BUFFER_RESERVATION 0
  36. #define DP_PEER_METADATA_PEER_ID_MASK 0x0000ffff
  37. #define DP_PEER_METADATA_PEER_ID_SHIFT 0
  38. #define DP_PEER_METADATA_VDEV_ID_MASK 0x00070000
  39. #define DP_PEER_METADATA_VDEV_ID_SHIFT 16
  40. #define DP_PEER_METADATA_PEER_ID_GET(_peer_metadata) \
  41. (((_peer_metadata) & DP_PEER_METADATA_PEER_ID_MASK) \
  42. >> DP_PEER_METADATA_PEER_ID_SHIFT)
  43. #define DP_PEER_METADATA_ID_GET(_peer_metadata) \
  44. (((_peer_metadata) & DP_PEER_METADATA_VDEV_ID_MASK) \
  45. >> DP_PEER_METADATA_VDEV_ID_SHIFT)
  46. #define DP_RX_DESC_MAGIC 0xdec0de
  47. /**
  48. * struct dp_rx_desc
  49. *
  50. * @nbuf : VA of the "skb" posted
  51. * @rx_buf_start : VA of the original Rx buffer, before
  52. * movement of any skb->data pointer
  53. * @cookie : index into the sw array which holds
  54. * the sw Rx descriptors
  55. * Cookie space is 21 bits:
  56. * lower 18 bits -- index
  57. * upper 3 bits -- pool_id
  58. * @pool_id : pool Id for which this allocated.
  59. * Can only be used if there is no flow
  60. * steering
  61. * @in_use rx_desc is in use
  62. * @unmapped used to mark rx_desc an unmapped if the corresponding
  63. * nbuf is already unmapped
  64. */
  65. struct dp_rx_desc {
  66. qdf_nbuf_t nbuf;
  67. uint8_t *rx_buf_start;
  68. uint32_t cookie;
  69. uint8_t pool_id;
  70. #ifdef RX_DESC_DEBUG_CHECK
  71. uint32_t magic;
  72. #endif
  73. uint8_t in_use:1,
  74. unmapped:1;
  75. };
  76. #define RX_DESC_COOKIE_INDEX_SHIFT 0
  77. #define RX_DESC_COOKIE_INDEX_MASK 0x3ffff /* 18 bits */
  78. #define RX_DESC_COOKIE_POOL_ID_SHIFT 18
  79. #define RX_DESC_COOKIE_POOL_ID_MASK 0x1c0000
  80. #define DP_RX_DESC_COOKIE_MAX \
  81. (RX_DESC_COOKIE_INDEX_MASK | RX_DESC_COOKIE_POOL_ID_MASK)
  82. #define DP_RX_DESC_COOKIE_POOL_ID_GET(_cookie) \
  83. (((_cookie) & RX_DESC_COOKIE_POOL_ID_MASK) >> \
  84. RX_DESC_COOKIE_POOL_ID_SHIFT)
  85. #define DP_RX_DESC_COOKIE_INDEX_GET(_cookie) \
  86. (((_cookie) & RX_DESC_COOKIE_INDEX_MASK) >> \
  87. RX_DESC_COOKIE_INDEX_SHIFT)
  88. /*
  89. *dp_rx_xor_block() - xor block of data
  90. *@b: destination data block
  91. *@a: source data block
  92. *@len: length of the data to process
  93. *
  94. *Returns: None
  95. */
  96. static inline void dp_rx_xor_block(uint8_t *b, const uint8_t *a, qdf_size_t len)
  97. {
  98. qdf_size_t i;
  99. for (i = 0; i < len; i++)
  100. b[i] ^= a[i];
  101. }
  102. /*
  103. *dp_rx_rotl() - rotate the bits left
  104. *@val: unsigned integer input value
  105. *@bits: number of bits
  106. *
  107. *Returns: Integer with left rotated by number of 'bits'
  108. */
  109. static inline uint32_t dp_rx_rotl(uint32_t val, int bits)
  110. {
  111. return (val << bits) | (val >> (32 - bits));
  112. }
  113. /*
  114. *dp_rx_rotr() - rotate the bits right
  115. *@val: unsigned integer input value
  116. *@bits: number of bits
  117. *
  118. *Returns: Integer with right rotated by number of 'bits'
  119. */
  120. static inline uint32_t dp_rx_rotr(uint32_t val, int bits)
  121. {
  122. return (val >> bits) | (val << (32 - bits));
  123. }
  124. /*
  125. * dp_set_rx_queue() - set queue_mapping in skb
  126. * @nbuf: skb
  127. * @queue_id: rx queue_id
  128. *
  129. * Return: void
  130. */
  131. #ifdef QCA_OL_RX_MULTIQ_SUPPORT
  132. static inline void dp_set_rx_queue(qdf_nbuf_t nbuf, uint8_t queue_id)
  133. {
  134. qdf_nbuf_record_rx_queue(nbuf, queue_id);
  135. return;
  136. }
  137. #else
  138. static inline void dp_set_rx_queue(qdf_nbuf_t nbuf, uint8_t queue_id)
  139. {
  140. }
  141. #endif
  142. /*
  143. *dp_rx_xswap() - swap the bits left
  144. *@val: unsigned integer input value
  145. *
  146. *Returns: Integer with bits swapped
  147. */
  148. static inline uint32_t dp_rx_xswap(uint32_t val)
  149. {
  150. return ((val & 0x00ff00ff) << 8) | ((val & 0xff00ff00) >> 8);
  151. }
  152. /*
  153. *dp_rx_get_le32_split() - get little endian 32 bits split
  154. *@b0: byte 0
  155. *@b1: byte 1
  156. *@b2: byte 2
  157. *@b3: byte 3
  158. *
  159. *Returns: Integer with split little endian 32 bits
  160. */
  161. static inline uint32_t dp_rx_get_le32_split(uint8_t b0, uint8_t b1, uint8_t b2,
  162. uint8_t b3)
  163. {
  164. return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24);
  165. }
  166. /*
  167. *dp_rx_get_le32() - get little endian 32 bits
  168. *@b0: byte 0
  169. *@b1: byte 1
  170. *@b2: byte 2
  171. *@b3: byte 3
  172. *
  173. *Returns: Integer with little endian 32 bits
  174. */
  175. static inline uint32_t dp_rx_get_le32(const uint8_t *p)
  176. {
  177. return dp_rx_get_le32_split(p[0], p[1], p[2], p[3]);
  178. }
  179. /*
  180. * dp_rx_put_le32() - put little endian 32 bits
  181. * @p: destination char array
  182. * @v: source 32-bit integer
  183. *
  184. * Returns: None
  185. */
  186. static inline void dp_rx_put_le32(uint8_t *p, uint32_t v)
  187. {
  188. p[0] = (v) & 0xff;
  189. p[1] = (v >> 8) & 0xff;
  190. p[2] = (v >> 16) & 0xff;
  191. p[3] = (v >> 24) & 0xff;
  192. }
  193. /* Extract michal mic block of data */
  194. #define dp_rx_michael_block(l, r) \
  195. do { \
  196. r ^= dp_rx_rotl(l, 17); \
  197. l += r; \
  198. r ^= dp_rx_xswap(l); \
  199. l += r; \
  200. r ^= dp_rx_rotl(l, 3); \
  201. l += r; \
  202. r ^= dp_rx_rotr(l, 2); \
  203. l += r; \
  204. } while (0)
  205. /**
  206. * struct dp_rx_desc_list_elem_t
  207. *
  208. * @next : Next pointer to form free list
  209. * @rx_desc : DP Rx descriptor
  210. */
  211. union dp_rx_desc_list_elem_t {
  212. union dp_rx_desc_list_elem_t *next;
  213. struct dp_rx_desc rx_desc;
  214. };
  215. /**
  216. * dp_rx_cookie_2_va_rxdma_buf() - Converts cookie to a virtual address of
  217. * the Rx descriptor on Rx DMA source ring buffer
  218. * @soc: core txrx main context
  219. * @cookie: cookie used to lookup virtual address
  220. *
  221. * Return: void *: Virtual Address of the Rx descriptor
  222. */
  223. static inline
  224. void *dp_rx_cookie_2_va_rxdma_buf(struct dp_soc *soc, uint32_t cookie)
  225. {
  226. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  227. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  228. struct rx_desc_pool *rx_desc_pool;
  229. if (qdf_unlikely(pool_id >= MAX_RXDESC_POOLS))
  230. return NULL;
  231. rx_desc_pool = &soc->rx_desc_buf[pool_id];
  232. if (qdf_unlikely(index >= rx_desc_pool->pool_size))
  233. return NULL;
  234. return &(soc->rx_desc_buf[pool_id].array[index].rx_desc);
  235. }
  236. /**
  237. * dp_rx_cookie_2_va_mon_buf() - Converts cookie to a virtual address of
  238. * the Rx descriptor on monitor ring buffer
  239. * @soc: core txrx main context
  240. * @cookie: cookie used to lookup virtual address
  241. *
  242. * Return: void *: Virtual Address of the Rx descriptor
  243. */
  244. static inline
  245. void *dp_rx_cookie_2_va_mon_buf(struct dp_soc *soc, uint32_t cookie)
  246. {
  247. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  248. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  249. /* TODO */
  250. /* Add sanity for pool_id & index */
  251. return &(soc->rx_desc_mon[pool_id].array[index].rx_desc);
  252. }
  253. /**
  254. * dp_rx_cookie_2_va_mon_status() - Converts cookie to a virtual address of
  255. * the Rx descriptor on monitor status ring buffer
  256. * @soc: core txrx main context
  257. * @cookie: cookie used to lookup virtual address
  258. *
  259. * Return: void *: Virtual Address of the Rx descriptor
  260. */
  261. static inline
  262. void *dp_rx_cookie_2_va_mon_status(struct dp_soc *soc, uint32_t cookie)
  263. {
  264. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  265. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  266. /* TODO */
  267. /* Add sanity for pool_id & index */
  268. return &(soc->rx_desc_status[pool_id].array[index].rx_desc);
  269. }
  270. void dp_rx_add_desc_list_to_free_list(struct dp_soc *soc,
  271. union dp_rx_desc_list_elem_t **local_desc_list,
  272. union dp_rx_desc_list_elem_t **tail,
  273. uint16_t pool_id,
  274. struct rx_desc_pool *rx_desc_pool);
  275. uint16_t dp_rx_get_free_desc_list(struct dp_soc *soc, uint32_t pool_id,
  276. struct rx_desc_pool *rx_desc_pool,
  277. uint16_t num_descs,
  278. union dp_rx_desc_list_elem_t **desc_list,
  279. union dp_rx_desc_list_elem_t **tail);
  280. QDF_STATUS dp_rx_pdev_attach(struct dp_pdev *pdev);
  281. void dp_rx_pdev_detach(struct dp_pdev *pdev);
  282. uint32_t
  283. dp_rx_process(struct dp_intr *int_ctx, void *hal_ring, uint8_t reo_ring_num,
  284. uint32_t quota);
  285. uint32_t dp_rx_err_process(struct dp_soc *soc, void *hal_ring, uint32_t quota);
  286. uint32_t
  287. dp_rx_wbm_err_process(struct dp_soc *soc, void *hal_ring, uint32_t quota);
  288. /**
  289. * dp_rx_sg_create() - create a frag_list for MSDUs which are spread across
  290. * multiple nbufs.
  291. * @nbuf: pointer to the first msdu of an amsdu.
  292. * @rx_tlv_hdr: pointer to the start of RX TLV headers.
  293. *
  294. * This function implements the creation of RX frag_list for cases
  295. * where an MSDU is spread across multiple nbufs.
  296. *
  297. * Return: returns the head nbuf which contains complete frag_list.
  298. */
  299. qdf_nbuf_t dp_rx_sg_create(qdf_nbuf_t nbuf, uint8_t *rx_tlv_hdr);
  300. QDF_STATUS dp_rx_desc_pool_alloc(struct dp_soc *soc,
  301. uint32_t pool_id,
  302. uint32_t pool_size,
  303. struct rx_desc_pool *rx_desc_pool);
  304. void dp_rx_desc_pool_free(struct dp_soc *soc,
  305. uint32_t pool_id,
  306. struct rx_desc_pool *rx_desc_pool);
  307. void dp_rx_deliver_raw(struct dp_vdev *vdev, qdf_nbuf_t nbuf_list,
  308. struct dp_peer *peer);
  309. /**
  310. * dp_rx_add_to_free_desc_list() - Adds to a local free descriptor list
  311. *
  312. * @head: pointer to the head of local free list
  313. * @tail: pointer to the tail of local free list
  314. * @new: new descriptor that is added to the free list
  315. *
  316. * Return: void:
  317. */
  318. static inline
  319. void dp_rx_add_to_free_desc_list(union dp_rx_desc_list_elem_t **head,
  320. union dp_rx_desc_list_elem_t **tail,
  321. struct dp_rx_desc *new)
  322. {
  323. qdf_assert(head && new);
  324. new->nbuf = NULL;
  325. new->in_use = 0;
  326. new->unmapped = 0;
  327. ((union dp_rx_desc_list_elem_t *)new)->next = *head;
  328. *head = (union dp_rx_desc_list_elem_t *)new;
  329. if (*tail == NULL)
  330. *tail = *head;
  331. }
  332. /**
  333. * dp_rx_wds_srcport_learn() - Add or update the STA PEER which
  334. * is behind the WDS repeater.
  335. *
  336. * @soc: core txrx main context
  337. * @rx_tlv_hdr: base address of RX TLV header
  338. * @ta_peer: WDS repeater peer
  339. * @nbuf: rx pkt
  340. *
  341. * Return: void:
  342. */
  343. #ifdef FEATURE_WDS
  344. static inline void
  345. dp_rx_wds_srcport_learn(struct dp_soc *soc,
  346. uint8_t *rx_tlv_hdr,
  347. struct dp_peer *ta_peer,
  348. qdf_nbuf_t nbuf)
  349. {
  350. uint16_t sa_sw_peer_id = hal_rx_msdu_end_sa_sw_peer_id_get(rx_tlv_hdr);
  351. uint32_t flags = IEEE80211_NODE_F_WDS_HM;
  352. uint32_t ret = 0;
  353. uint8_t wds_src_mac[IEEE80211_ADDR_LEN];
  354. struct dp_peer *sa_peer;
  355. struct dp_peer *wds_peer;
  356. struct dp_ast_entry *ast;
  357. uint16_t sa_idx;
  358. bool del_in_progress;
  359. uint8_t sa_is_valid;
  360. struct dp_neighbour_peer *neighbour_peer = NULL;
  361. struct dp_pdev *pdev = ta_peer->vdev->pdev;
  362. if (qdf_unlikely(!ta_peer))
  363. return;
  364. /* For AP mode : Do wds source port learning only if it is a
  365. * 4-address mpdu
  366. *
  367. * For STA mode : Frames from RootAP backend will be in 3-address mode,
  368. * till RootAP does the WDS source port learning; Hence in repeater/STA
  369. * mode, we enable learning even in 3-address mode , to avoid RootAP
  370. * backbone getting wrongly learnt as MEC on repeater
  371. */
  372. if (ta_peer->vdev->opmode != wlan_op_mode_sta) {
  373. if (!(qdf_nbuf_is_rx_chfrag_start(nbuf) &&
  374. hal_rx_get_mpdu_mac_ad4_valid(rx_tlv_hdr)))
  375. return;
  376. } else {
  377. /* For HKv2 Source port learing is not needed in STA mode
  378. * as we have support in HW
  379. */
  380. if (soc->ast_override_support)
  381. return;
  382. }
  383. memcpy(wds_src_mac, (qdf_nbuf_data(nbuf) + IEEE80211_ADDR_LEN),
  384. IEEE80211_ADDR_LEN);
  385. sa_is_valid = hal_rx_msdu_end_sa_is_valid_get(rx_tlv_hdr);
  386. if (qdf_unlikely(!sa_is_valid)) {
  387. ret = dp_peer_add_ast(soc,
  388. ta_peer,
  389. wds_src_mac,
  390. CDP_TXRX_AST_TYPE_WDS,
  391. flags);
  392. return;
  393. }
  394. /*
  395. * Get the AST entry from HW SA index and mark it as active
  396. */
  397. sa_idx = hal_rx_msdu_end_sa_idx_get(rx_tlv_hdr);
  398. qdf_spin_lock_bh(&soc->ast_lock);
  399. ast = soc->ast_table[sa_idx];
  400. qdf_spin_unlock_bh(&soc->ast_lock);
  401. if (!ast) {
  402. /*
  403. * In HKv1, it is possible that HW retains the AST entry in
  404. * GSE cache on 1 radio , even after the AST entry is deleted
  405. * (on another radio).
  406. *
  407. * Due to this, host might still get sa_is_valid indications
  408. * for frames with SA not really present in AST table.
  409. *
  410. * So we go ahead and send an add_ast command to FW in such
  411. * cases where sa is reported still as valid, so that FW will
  412. * invalidate this GSE cache entry and new AST entry gets
  413. * cached.
  414. */
  415. if (!soc->ast_override_support) {
  416. wds_peer = dp_peer_find_hash_find(soc, wds_src_mac,
  417. 0, DP_VDEV_ALL);
  418. if (wds_peer) {
  419. del_in_progress = wds_peer->delete_in_progress;
  420. dp_peer_unref_delete(wds_peer);
  421. if (!del_in_progress) {
  422. QDF_TRACE(QDF_MODULE_ID_DP,
  423. QDF_TRACE_LEVEL_DEBUG,
  424. "wds peer %pM found",
  425. wds_src_mac);
  426. QDF_TRACE(QDF_MODULE_ID_DP,
  427. QDF_TRACE_LEVEL_DEBUG,
  428. "No AST no Del in progress");
  429. }
  430. return;
  431. }
  432. ret = dp_peer_add_ast(soc,
  433. ta_peer,
  434. wds_src_mac,
  435. CDP_TXRX_AST_TYPE_WDS,
  436. flags);
  437. return;
  438. } else {
  439. /* In HKv2 smart monitor case, when NAC client is
  440. * added first and this client roams within BSS to
  441. * connect to RE, since we have an AST entry for
  442. * NAC we get sa_is_valid bit set. So we check if
  443. * smart monitor is enabled and send add_ast command
  444. * to FW.
  445. */
  446. if (pdev->neighbour_peers_added) {
  447. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  448. TAILQ_FOREACH(neighbour_peer,
  449. &pdev->neighbour_peers_list,
  450. neighbour_peer_list_elem) {
  451. if (!qdf_mem_cmp(&neighbour_peer->neighbour_peers_macaddr,
  452. wds_src_mac,
  453. DP_MAC_ADDR_LEN)) {
  454. ret = dp_peer_add_ast(soc,
  455. ta_peer,
  456. wds_src_mac,
  457. CDP_TXRX_AST_TYPE_WDS,
  458. flags);
  459. QDF_TRACE(QDF_MODULE_ID_DP,
  460. QDF_TRACE_LEVEL_INFO,
  461. "sa valid and nac roamed to wds");
  462. break;
  463. }
  464. }
  465. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  466. }
  467. return;
  468. }
  469. }
  470. if ((ast->type == CDP_TXRX_AST_TYPE_WDS_HM) ||
  471. (ast->type == CDP_TXRX_AST_TYPE_WDS_HM_SEC))
  472. return;
  473. /*
  474. * Ensure we are updating the right AST entry by
  475. * validating ast_idx.
  476. * There is a possibility we might arrive here without
  477. * AST MAP event , so this check is mandatory
  478. */
  479. if (ast->is_mapped && (ast->ast_idx == sa_idx))
  480. ast->is_active = TRUE;
  481. if (sa_sw_peer_id != ta_peer->peer_ids[0]) {
  482. sa_peer = ast->peer;
  483. if ((ast->type != CDP_TXRX_AST_TYPE_STATIC) &&
  484. (ast->type != CDP_TXRX_AST_TYPE_SELF) &&
  485. (ast->type != CDP_TXRX_AST_TYPE_STA_BSS)) {
  486. if (ast->pdev_id != ta_peer->vdev->pdev->pdev_id) {
  487. /* This case is when a STA roams from one
  488. * repeater to another repeater, but these
  489. * repeaters are connected to root AP on
  490. * different radios.
  491. * Ex: rptr1 connected to ROOT AP over 5G
  492. * and rptr2 connected to ROOT AP over 2G
  493. * radio
  494. */
  495. qdf_spin_lock_bh(&soc->ast_lock);
  496. dp_peer_del_ast(soc, ast);
  497. qdf_spin_unlock_bh(&soc->ast_lock);
  498. } else {
  499. /* this case is when a STA roams from one
  500. * reapter to another repeater, but inside
  501. * same radio.
  502. */
  503. qdf_spin_lock_bh(&soc->ast_lock);
  504. dp_peer_update_ast(soc, ta_peer, ast, flags);
  505. qdf_spin_unlock_bh(&soc->ast_lock);
  506. return;
  507. }
  508. }
  509. /*
  510. * Do not kickout STA if it belongs to a different radio.
  511. * For DBDC repeater, it is possible to arrive here
  512. * for multicast loopback frames originated from connected
  513. * clients and looped back (intrabss) by Root AP
  514. */
  515. if (ast->pdev_id != ta_peer->vdev->pdev->pdev_id) {
  516. return;
  517. }
  518. /*
  519. * Kickout, when direct associated peer(SA) roams
  520. * to another AP and reachable via TA peer
  521. */
  522. if ((sa_peer->vdev->opmode == wlan_op_mode_ap) &&
  523. !sa_peer->delete_in_progress) {
  524. sa_peer->delete_in_progress = true;
  525. if (soc->cdp_soc.ol_ops->peer_sta_kickout) {
  526. soc->cdp_soc.ol_ops->peer_sta_kickout(
  527. sa_peer->vdev->pdev->ctrl_pdev,
  528. wds_src_mac);
  529. }
  530. }
  531. }
  532. return;
  533. }
  534. #else
  535. static inline void
  536. dp_rx_wds_srcport_learn(struct dp_soc *soc,
  537. uint8_t *rx_tlv_hdr,
  538. struct dp_peer *ta_peer,
  539. qdf_nbuf_t nbuf)
  540. {
  541. }
  542. #endif
  543. uint8_t dp_rx_process_invalid_peer(struct dp_soc *soc, qdf_nbuf_t nbuf);
  544. void dp_rx_process_invalid_peer_wrapper(struct dp_soc *soc,
  545. qdf_nbuf_t mpdu, bool mpdu_done);
  546. void dp_rx_process_mic_error(struct dp_soc *soc, qdf_nbuf_t nbuf,
  547. uint8_t *rx_tlv_hdr, struct dp_peer *peer);
  548. #define DP_RX_LIST_APPEND(head, tail, elem) \
  549. do { \
  550. if (!(head)) { \
  551. (head) = (elem); \
  552. QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(head) = 1;\
  553. } else { \
  554. qdf_nbuf_set_next((tail), (elem)); \
  555. QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(head)++; \
  556. } \
  557. (tail) = (elem); \
  558. qdf_nbuf_set_next((tail), NULL); \
  559. } while (0)
  560. #ifndef BUILD_X86
  561. static inline int check_x86_paddr(struct dp_soc *dp_soc, qdf_nbuf_t *rx_netbuf,
  562. qdf_dma_addr_t *paddr, struct dp_pdev *pdev)
  563. {
  564. return QDF_STATUS_SUCCESS;
  565. }
  566. #else
  567. #define MAX_RETRY 100
  568. static inline int check_x86_paddr(struct dp_soc *dp_soc, qdf_nbuf_t *rx_netbuf,
  569. qdf_dma_addr_t *paddr, struct dp_pdev *pdev)
  570. {
  571. uint32_t nbuf_retry = 0;
  572. int32_t ret;
  573. const uint32_t x86_phy_addr = 0x50000000;
  574. /*
  575. * in M2M emulation platforms (x86) the memory below 0x50000000
  576. * is reserved for target use, so any memory allocated in this
  577. * region should not be used by host
  578. */
  579. do {
  580. if (qdf_likely(*paddr > x86_phy_addr))
  581. return QDF_STATUS_SUCCESS;
  582. else {
  583. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  584. "phy addr %pK exceeded 0x50000000 trying again",
  585. paddr);
  586. nbuf_retry++;
  587. if ((*rx_netbuf)) {
  588. qdf_nbuf_unmap_single(dp_soc->osdev, *rx_netbuf,
  589. QDF_DMA_BIDIRECTIONAL);
  590. /* Not freeing buffer intentionally.
  591. * Observed that same buffer is getting
  592. * re-allocated resulting in longer load time
  593. * WMI init timeout.
  594. * This buffer is anyway not useful so skip it.
  595. **/
  596. }
  597. *rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
  598. RX_BUFFER_SIZE,
  599. RX_BUFFER_RESERVATION,
  600. RX_BUFFER_ALIGNMENT,
  601. FALSE);
  602. if (qdf_unlikely(!(*rx_netbuf)))
  603. return QDF_STATUS_E_FAILURE;
  604. ret = qdf_nbuf_map_single(dp_soc->osdev, *rx_netbuf,
  605. QDF_DMA_BIDIRECTIONAL);
  606. if (qdf_unlikely(ret == QDF_STATUS_E_FAILURE)) {
  607. qdf_nbuf_free(*rx_netbuf);
  608. *rx_netbuf = NULL;
  609. continue;
  610. }
  611. *paddr = qdf_nbuf_get_frag_paddr(*rx_netbuf, 0);
  612. }
  613. } while (nbuf_retry < MAX_RETRY);
  614. if ((*rx_netbuf)) {
  615. qdf_nbuf_unmap_single(dp_soc->osdev, *rx_netbuf,
  616. QDF_DMA_BIDIRECTIONAL);
  617. qdf_nbuf_free(*rx_netbuf);
  618. }
  619. return QDF_STATUS_E_FAILURE;
  620. }
  621. #endif
  622. /**
  623. * dp_rx_cookie_2_link_desc_va() - Converts cookie to a virtual address of
  624. * the MSDU Link Descriptor
  625. * @soc: core txrx main context
  626. * @buf_info: buf_info include cookie that used to lookup virtual address of
  627. * link descriptor Normally this is just an index into a per SOC array.
  628. *
  629. * This is the VA of the link descriptor, that HAL layer later uses to
  630. * retrieve the list of MSDU's for a given MPDU.
  631. *
  632. * Return: void *: Virtual Address of the Rx descriptor
  633. */
  634. static inline
  635. void *dp_rx_cookie_2_link_desc_va(struct dp_soc *soc,
  636. struct hal_buf_info *buf_info)
  637. {
  638. void *link_desc_va;
  639. uint32_t bank_id = LINK_DESC_COOKIE_BANK_ID(buf_info->sw_cookie);
  640. /* TODO */
  641. /* Add sanity for cookie */
  642. link_desc_va = soc->link_desc_banks[bank_id].base_vaddr +
  643. (buf_info->paddr -
  644. soc->link_desc_banks[bank_id].base_paddr);
  645. return link_desc_va;
  646. }
  647. /**
  648. * dp_rx_cookie_2_mon_link_desc_va() - Converts cookie to a virtual address of
  649. * the MSDU Link Descriptor
  650. * @pdev: core txrx pdev context
  651. * @buf_info: buf_info includes cookie that used to lookup virtual address of
  652. * link descriptor. Normally this is just an index into a per pdev array.
  653. *
  654. * This is the VA of the link descriptor in monitor mode destination ring,
  655. * that HAL layer later uses to retrieve the list of MSDU's for a given MPDU.
  656. *
  657. * Return: void *: Virtual Address of the Rx descriptor
  658. */
  659. static inline
  660. void *dp_rx_cookie_2_mon_link_desc_va(struct dp_pdev *pdev,
  661. struct hal_buf_info *buf_info,
  662. int mac_id)
  663. {
  664. void *link_desc_va;
  665. int mac_for_pdev = dp_get_mac_id_for_mac(pdev->soc, mac_id);
  666. /* TODO */
  667. /* Add sanity for cookie */
  668. link_desc_va =
  669. pdev->link_desc_banks[mac_for_pdev][buf_info->sw_cookie].base_vaddr +
  670. (buf_info->paddr -
  671. pdev->link_desc_banks[mac_for_pdev][buf_info->sw_cookie].base_paddr);
  672. return link_desc_va;
  673. }
  674. /**
  675. * dp_rx_defrag_concat() - Concatenate the fragments
  676. *
  677. * @dst: destination pointer to the buffer
  678. * @src: source pointer from where the fragment payload is to be copied
  679. *
  680. * Return: QDF_STATUS
  681. */
  682. static inline QDF_STATUS dp_rx_defrag_concat(qdf_nbuf_t dst, qdf_nbuf_t src)
  683. {
  684. /*
  685. * Inside qdf_nbuf_cat, if it is necessary to reallocate dst
  686. * to provide space for src, the headroom portion is copied from
  687. * the original dst buffer to the larger new dst buffer.
  688. * (This is needed, because the headroom of the dst buffer
  689. * contains the rx desc.)
  690. */
  691. if (qdf_nbuf_cat(dst, src))
  692. return QDF_STATUS_E_DEFRAG_ERROR;
  693. return QDF_STATUS_SUCCESS;
  694. }
  695. /*
  696. * dp_rx_ast_set_active() - set the active flag of the astentry
  697. * corresponding to a hw index.
  698. * @soc: core txrx main context
  699. * @sa_idx: hw idx
  700. * @is_active: active flag
  701. *
  702. */
  703. #ifdef FEATURE_WDS
  704. static inline QDF_STATUS dp_rx_ast_set_active(struct dp_soc *soc, uint16_t sa_idx, bool is_active)
  705. {
  706. struct dp_ast_entry *ast;
  707. qdf_spin_lock_bh(&soc->ast_lock);
  708. ast = soc->ast_table[sa_idx];
  709. /*
  710. * Ensure we are updating the right AST entry by
  711. * validating ast_idx.
  712. * There is a possibility we might arrive here without
  713. * AST MAP event , so this check is mandatory
  714. */
  715. if (ast && ast->is_mapped && (ast->ast_idx == sa_idx)) {
  716. ast->is_active = is_active;
  717. qdf_spin_unlock_bh(&soc->ast_lock);
  718. return QDF_STATUS_SUCCESS;
  719. }
  720. qdf_spin_unlock_bh(&soc->ast_lock);
  721. return QDF_STATUS_E_FAILURE;
  722. }
  723. #else
  724. static inline QDF_STATUS dp_rx_ast_set_active(struct dp_soc *soc, uint16_t sa_idx, bool is_active)
  725. {
  726. return QDF_STATUS_SUCCESS;
  727. }
  728. #endif
  729. /*
  730. * check_qwrap_multicast_loopback() - Check if rx packet is a loopback packet.
  731. * In qwrap mode, packets originated from
  732. * any vdev should not loopback and
  733. * should be dropped.
  734. * @vdev: vdev on which rx packet is received
  735. * @nbuf: rx pkt
  736. *
  737. */
  738. #if ATH_SUPPORT_WRAP
  739. static inline bool check_qwrap_multicast_loopback(struct dp_vdev *vdev,
  740. qdf_nbuf_t nbuf)
  741. {
  742. struct dp_vdev *psta_vdev;
  743. struct dp_pdev *pdev = vdev->pdev;
  744. struct dp_soc *soc = pdev->soc;
  745. uint8_t *data = qdf_nbuf_data(nbuf);
  746. uint8_t i;
  747. for (i = 0; i < MAX_PDEV_CNT && soc->pdev_list[i]; i++) {
  748. pdev = soc->pdev_list[i];
  749. if (qdf_unlikely(vdev->proxysta_vdev)) {
  750. /* In qwrap isolation mode, allow loopback packets as all
  751. * packets go to RootAP and Loopback on the mpsta.
  752. */
  753. if (vdev->isolation_vdev)
  754. return false;
  755. TAILQ_FOREACH(psta_vdev, &pdev->vdev_list, vdev_list_elem) {
  756. if (qdf_unlikely(psta_vdev->proxysta_vdev &&
  757. !qdf_mem_cmp(psta_vdev->mac_addr.raw,
  758. &data[DP_MAC_ADDR_LEN], DP_MAC_ADDR_LEN))) {
  759. /* Drop packet if source address is equal to
  760. * any of the vdev addresses.
  761. */
  762. return true;
  763. }
  764. }
  765. }
  766. }
  767. return false;
  768. }
  769. #else
  770. static inline bool check_qwrap_multicast_loopback(struct dp_vdev *vdev,
  771. qdf_nbuf_t nbuf)
  772. {
  773. return false;
  774. }
  775. #endif
  776. /*
  777. * dp_rx_buffers_replenish() - replenish rxdma ring with rx nbufs
  778. * called during dp rx initialization
  779. * and at the end of dp_rx_process.
  780. *
  781. * @soc: core txrx main context
  782. * @mac_id: mac_id which is one of 3 mac_ids
  783. * @dp_rxdma_srng: dp rxdma circular ring
  784. * @rx_desc_pool: Pointer to free Rx descriptor pool
  785. * @num_req_buffers: number of buffer to be replenished
  786. * @desc_list: list of descs if called from dp_rx_process
  787. * or NULL during dp rx initialization or out of buffer
  788. * interrupt.
  789. * @tail: tail of descs list
  790. * Return: return success or failure
  791. */
  792. QDF_STATUS dp_rx_buffers_replenish(struct dp_soc *dp_soc, uint32_t mac_id,
  793. struct dp_srng *dp_rxdma_srng,
  794. struct rx_desc_pool *rx_desc_pool,
  795. uint32_t num_req_buffers,
  796. union dp_rx_desc_list_elem_t **desc_list,
  797. union dp_rx_desc_list_elem_t **tail);
  798. /**
  799. * dp_rx_link_desc_return() - Return a MPDU link descriptor to HW
  800. * (WBM), following error handling
  801. *
  802. * @soc: core DP main context
  803. * @buf_addr_info: opaque pointer to the REO error ring descriptor
  804. * @buf_addr_info: void pointer to the buffer_addr_info
  805. * @bm_action: put to idle_list or release to msdu_list
  806. * Return: QDF_STATUS
  807. */
  808. QDF_STATUS
  809. dp_rx_link_desc_return(struct dp_soc *soc, void *ring_desc, uint8_t bm_action);
  810. QDF_STATUS
  811. dp_rx_link_desc_buf_return(struct dp_soc *soc, struct dp_srng *dp_rxdma_srng,
  812. void *buf_addr_info, uint8_t bm_action);
  813. /**
  814. * dp_rx_link_desc_return_by_addr - Return a MPDU link descriptor to
  815. * (WBM) by address
  816. *
  817. * @soc: core DP main context
  818. * @link_desc_addr: link descriptor addr
  819. *
  820. * Return: QDF_STATUS
  821. */
  822. QDF_STATUS
  823. dp_rx_link_desc_return_by_addr(struct dp_soc *soc, void *link_desc_addr,
  824. uint8_t bm_action);
  825. uint32_t
  826. dp_rxdma_err_process(struct dp_soc *soc, uint32_t mac_id,
  827. uint32_t quota);
  828. void dp_rx_fill_mesh_stats(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  829. uint8_t *rx_tlv_hdr, struct dp_peer *peer);
  830. QDF_STATUS dp_rx_filter_mesh_packets(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  831. uint8_t *rx_tlv_hdr);
  832. int dp_wds_rx_policy_check(uint8_t *rx_tlv_hdr, struct dp_vdev *vdev,
  833. struct dp_peer *peer, int rx_mcast);
  834. qdf_nbuf_t
  835. dp_rx_nbuf_prepare(struct dp_soc *soc, struct dp_pdev *pdev);
  836. #endif /* _DP_RX_H */