dp_rx.h 27 KB

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