dp_rx.h 29 KB

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