dp_rx.h 29 KB

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