dp_rx.h 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558
  1. /*
  2. * Copyright (c) 2016-2020 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. #ifndef RX_DATA_BUFFER_ALIGNMENT
  26. #define RX_DATA_BUFFER_ALIGNMENT 128
  27. #endif
  28. #ifndef RX_MONITOR_BUFFER_ALIGNMENT
  29. #define RX_MONITOR_BUFFER_ALIGNMENT 128
  30. #endif
  31. #else /* RXDMA_OPTIMIZATION */
  32. #define RX_DATA_BUFFER_ALIGNMENT 4
  33. #define RX_MONITOR_BUFFER_ALIGNMENT 4
  34. #endif /* RXDMA_OPTIMIZATION */
  35. #ifdef QCA_HOST2FW_RXBUF_RING
  36. #define DP_WBM2SW_RBM HAL_RX_BUF_RBM_SW1_BM
  37. /* RBM value used for re-injecting defragmented packets into REO */
  38. #define DP_DEFRAG_RBM HAL_RX_BUF_RBM_SW3_BM
  39. #else
  40. #define DP_WBM2SW_RBM HAL_RX_BUF_RBM_SW3_BM
  41. #define DP_DEFRAG_RBM DP_WBM2SW_RBM
  42. #endif /* QCA_HOST2FW_RXBUF_RING */
  43. #define RX_BUFFER_RESERVATION 0
  44. #define DP_PEER_METADATA_PEER_ID_MASK 0x0000ffff
  45. #define DP_PEER_METADATA_PEER_ID_SHIFT 0
  46. #define DP_PEER_METADATA_VDEV_ID_MASK 0x003f0000
  47. #define DP_PEER_METADATA_VDEV_ID_SHIFT 16
  48. #define DP_PEER_METADATA_PEER_ID_GET(_peer_metadata) \
  49. (((_peer_metadata) & DP_PEER_METADATA_PEER_ID_MASK) \
  50. >> DP_PEER_METADATA_PEER_ID_SHIFT)
  51. #define DP_PEER_METADATA_VDEV_ID_GET(_peer_metadata) \
  52. (((_peer_metadata) & DP_PEER_METADATA_VDEV_ID_MASK) \
  53. >> DP_PEER_METADATA_VDEV_ID_SHIFT)
  54. #define DP_RX_DESC_MAGIC 0xdec0de
  55. /**
  56. * enum dp_rx_desc_state
  57. *
  58. * @RX_DESC_REPLENISH: rx desc replenished
  59. * @RX_DESC_FREELIST: rx desc in freelist
  60. */
  61. enum dp_rx_desc_state {
  62. RX_DESC_REPLENISHED,
  63. RX_DESC_IN_FREELIST,
  64. };
  65. /**
  66. * struct dp_rx_desc_dbg_info
  67. *
  68. * @freelist_caller: name of the function that put the
  69. * the rx desc in freelist
  70. * @freelist_ts: timestamp when the rx desc is put in
  71. * a freelist
  72. * @replenish_caller: name of the function that last
  73. * replenished the rx desc
  74. * @replenish_ts: last replenish timestamp
  75. */
  76. struct dp_rx_desc_dbg_info {
  77. char freelist_caller[QDF_MEM_FUNC_NAME_SIZE];
  78. uint64_t freelist_ts;
  79. char replenish_caller[QDF_MEM_FUNC_NAME_SIZE];
  80. uint64_t replenish_ts;
  81. };
  82. /**
  83. * struct dp_rx_desc
  84. *
  85. * @nbuf : VA of the "skb" posted
  86. * @rx_buf_start : VA of the original Rx buffer, before
  87. * movement of any skb->data pointer
  88. * @paddr_buf_start : PA of the original Rx buffer, before
  89. * movement of any frag pointer
  90. * @cookie : index into the sw array which holds
  91. * the sw Rx descriptors
  92. * Cookie space is 21 bits:
  93. * lower 18 bits -- index
  94. * upper 3 bits -- pool_id
  95. * @pool_id : pool Id for which this allocated.
  96. * Can only be used if there is no flow
  97. * steering
  98. * @in_use rx_desc is in use
  99. * @unmapped used to mark rx_desc an unmapped if the corresponding
  100. * nbuf is already unmapped
  101. * @in_err_state : Nbuf sanity failed for this descriptor.
  102. */
  103. struct dp_rx_desc {
  104. qdf_nbuf_t nbuf;
  105. uint8_t *rx_buf_start;
  106. qdf_dma_addr_t paddr_buf_start;
  107. uint32_t cookie;
  108. uint8_t pool_id;
  109. #ifdef RX_DESC_DEBUG_CHECK
  110. uint32_t magic;
  111. struct dp_rx_desc_dbg_info *dbg_info;
  112. #endif
  113. uint8_t in_use:1,
  114. unmapped:1,
  115. in_err_state:1;
  116. };
  117. /* RX Descriptor Multi Page memory alloc related */
  118. #define DP_RX_DESC_OFFSET_NUM_BITS 8
  119. #define DP_RX_DESC_PAGE_ID_NUM_BITS 8
  120. #define DP_RX_DESC_POOL_ID_NUM_BITS 4
  121. #define DP_RX_DESC_PAGE_ID_SHIFT DP_RX_DESC_OFFSET_NUM_BITS
  122. #define DP_RX_DESC_POOL_ID_SHIFT \
  123. (DP_RX_DESC_OFFSET_NUM_BITS + DP_RX_DESC_PAGE_ID_NUM_BITS)
  124. #define RX_DESC_MULTI_PAGE_COOKIE_POOL_ID_MASK \
  125. (((1 << DP_RX_DESC_POOL_ID_NUM_BITS) - 1) << DP_RX_DESC_POOL_ID_SHIFT)
  126. #define RX_DESC_MULTI_PAGE_COOKIE_PAGE_ID_MASK \
  127. (((1 << DP_RX_DESC_PAGE_ID_NUM_BITS) - 1) << \
  128. DP_RX_DESC_PAGE_ID_SHIFT)
  129. #define RX_DESC_MULTI_PAGE_COOKIE_OFFSET_MASK \
  130. ((1 << DP_RX_DESC_OFFSET_NUM_BITS) - 1)
  131. #define DP_RX_DESC_MULTI_PAGE_COOKIE_GET_POOL_ID(_cookie) \
  132. (((_cookie) & RX_DESC_MULTI_PAGE_COOKIE_POOL_ID_MASK) >> \
  133. DP_RX_DESC_POOL_ID_SHIFT)
  134. #define DP_RX_DESC_MULTI_PAGE_COOKIE_GET_PAGE_ID(_cookie) \
  135. (((_cookie) & RX_DESC_MULTI_PAGE_COOKIE_PAGE_ID_MASK) >> \
  136. DP_RX_DESC_PAGE_ID_SHIFT)
  137. #define DP_RX_DESC_MULTI_PAGE_COOKIE_GET_OFFSET(_cookie) \
  138. ((_cookie) & RX_DESC_MULTI_PAGE_COOKIE_OFFSET_MASK)
  139. #define RX_DESC_COOKIE_INDEX_SHIFT 0
  140. #define RX_DESC_COOKIE_INDEX_MASK 0x3ffff /* 18 bits */
  141. #define RX_DESC_COOKIE_POOL_ID_SHIFT 18
  142. #define RX_DESC_COOKIE_POOL_ID_MASK 0x1c0000
  143. #define DP_RX_DESC_COOKIE_MAX \
  144. (RX_DESC_COOKIE_INDEX_MASK | RX_DESC_COOKIE_POOL_ID_MASK)
  145. #define DP_RX_DESC_COOKIE_POOL_ID_GET(_cookie) \
  146. (((_cookie) & RX_DESC_COOKIE_POOL_ID_MASK) >> \
  147. RX_DESC_COOKIE_POOL_ID_SHIFT)
  148. #define DP_RX_DESC_COOKIE_INDEX_GET(_cookie) \
  149. (((_cookie) & RX_DESC_COOKIE_INDEX_MASK) >> \
  150. RX_DESC_COOKIE_INDEX_SHIFT)
  151. #define dp_rx_add_to_free_desc_list(head, tail, new) \
  152. __dp_rx_add_to_free_desc_list(head, tail, new, __func__)
  153. #define dp_rx_buffers_replenish(soc, mac_id, rxdma_srng, rx_desc_pool, \
  154. num_buffers, desc_list, tail) \
  155. __dp_rx_buffers_replenish(soc, mac_id, rxdma_srng, rx_desc_pool, \
  156. num_buffers, desc_list, tail, __func__)
  157. #ifdef DP_RX_SPECIAL_FRAME_NEED
  158. /**
  159. * dp_rx_is_special_frame() - check is RX frame special needed
  160. *
  161. * @nbuf: RX skb pointer
  162. * @frame_mask: the mask for speical frame needed
  163. *
  164. * Check is RX frame wanted matched with mask
  165. *
  166. * Return: true - special frame needed, false - no
  167. */
  168. static inline
  169. bool dp_rx_is_special_frame(qdf_nbuf_t nbuf, uint32_t frame_mask)
  170. {
  171. if (((frame_mask & FRAME_MASK_IPV4_ARP) &&
  172. qdf_nbuf_is_ipv4_arp_pkt(nbuf)) ||
  173. ((frame_mask & FRAME_MASK_IPV4_DHCP) &&
  174. qdf_nbuf_is_ipv4_dhcp_pkt(nbuf)) ||
  175. ((frame_mask & FRAME_MASK_IPV4_EAPOL) &&
  176. qdf_nbuf_is_ipv4_eapol_pkt(nbuf)) ||
  177. ((frame_mask & FRAME_MASK_IPV6_DHCP) &&
  178. qdf_nbuf_is_ipv6_dhcp_pkt(nbuf)))
  179. return true;
  180. return false;
  181. }
  182. /**
  183. * dp_rx_deliver_special_frame() - Deliver the RX special frame to stack
  184. * if matches mask
  185. *
  186. * @soc: Datapath soc handler
  187. * @peer: pointer to DP peer
  188. * @nbuf: pointer to the skb of RX frame
  189. * @frame_mask: the mask for speical frame needed
  190. * @rx_tlv_hdr: start of rx tlv header
  191. *
  192. * note: Msdu_len must have been stored in QDF_NBUF_CB_RX_PKT_LEN(nbuf) and
  193. * single nbuf is expected.
  194. *
  195. * return: true - nbuf has been delivered to stack, false - not.
  196. */
  197. bool dp_rx_deliver_special_frame(struct dp_soc *soc, struct dp_peer *peer,
  198. qdf_nbuf_t nbuf, uint32_t frame_mask,
  199. uint8_t *rx_tlv_hdr);
  200. #else
  201. static inline
  202. bool dp_rx_is_special_frame(qdf_nbuf_t nbuf, uint32_t frame_mask)
  203. {
  204. return false;
  205. }
  206. static inline
  207. bool dp_rx_deliver_special_frame(struct dp_soc *soc, struct dp_peer *peer,
  208. qdf_nbuf_t nbuf, uint32_t frame_mask,
  209. uint8_t *rx_tlv_hdr)
  210. {
  211. return false;
  212. }
  213. #endif
  214. /* DOC: Offset to obtain LLC hdr
  215. *
  216. * In the case of Wifi parse error
  217. * to reach LLC header from beginning
  218. * of VLAN tag we need to skip 8 bytes.
  219. * Vlan_tag(4)+length(2)+length added
  220. * by HW(2) = 8 bytes.
  221. */
  222. #define DP_SKIP_VLAN 8
  223. /**
  224. * struct dp_rx_cached_buf - rx cached buffer
  225. * @list: linked list node
  226. * @buf: skb buffer
  227. */
  228. struct dp_rx_cached_buf {
  229. qdf_list_node_t node;
  230. qdf_nbuf_t buf;
  231. };
  232. /*
  233. *dp_rx_xor_block() - xor block of data
  234. *@b: destination data block
  235. *@a: source data block
  236. *@len: length of the data to process
  237. *
  238. *Returns: None
  239. */
  240. static inline void dp_rx_xor_block(uint8_t *b, const uint8_t *a, qdf_size_t len)
  241. {
  242. qdf_size_t i;
  243. for (i = 0; i < len; i++)
  244. b[i] ^= a[i];
  245. }
  246. /*
  247. *dp_rx_rotl() - rotate the bits left
  248. *@val: unsigned integer input value
  249. *@bits: number of bits
  250. *
  251. *Returns: Integer with left rotated by number of 'bits'
  252. */
  253. static inline uint32_t dp_rx_rotl(uint32_t val, int bits)
  254. {
  255. return (val << bits) | (val >> (32 - bits));
  256. }
  257. /*
  258. *dp_rx_rotr() - rotate the bits right
  259. *@val: unsigned integer input value
  260. *@bits: number of bits
  261. *
  262. *Returns: Integer with right rotated by number of 'bits'
  263. */
  264. static inline uint32_t dp_rx_rotr(uint32_t val, int bits)
  265. {
  266. return (val >> bits) | (val << (32 - bits));
  267. }
  268. /*
  269. * dp_set_rx_queue() - set queue_mapping in skb
  270. * @nbuf: skb
  271. * @queue_id: rx queue_id
  272. *
  273. * Return: void
  274. */
  275. #ifdef QCA_OL_RX_MULTIQ_SUPPORT
  276. static inline void dp_set_rx_queue(qdf_nbuf_t nbuf, uint8_t queue_id)
  277. {
  278. qdf_nbuf_record_rx_queue(nbuf, queue_id);
  279. return;
  280. }
  281. #else
  282. static inline void dp_set_rx_queue(qdf_nbuf_t nbuf, uint8_t queue_id)
  283. {
  284. }
  285. #endif
  286. /*
  287. *dp_rx_xswap() - swap the bits left
  288. *@val: unsigned integer input value
  289. *
  290. *Returns: Integer with bits swapped
  291. */
  292. static inline uint32_t dp_rx_xswap(uint32_t val)
  293. {
  294. return ((val & 0x00ff00ff) << 8) | ((val & 0xff00ff00) >> 8);
  295. }
  296. /*
  297. *dp_rx_get_le32_split() - get little endian 32 bits split
  298. *@b0: byte 0
  299. *@b1: byte 1
  300. *@b2: byte 2
  301. *@b3: byte 3
  302. *
  303. *Returns: Integer with split little endian 32 bits
  304. */
  305. static inline uint32_t dp_rx_get_le32_split(uint8_t b0, uint8_t b1, uint8_t b2,
  306. uint8_t b3)
  307. {
  308. return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24);
  309. }
  310. /*
  311. *dp_rx_get_le32() - get little endian 32 bits
  312. *@b0: byte 0
  313. *@b1: byte 1
  314. *@b2: byte 2
  315. *@b3: byte 3
  316. *
  317. *Returns: Integer with little endian 32 bits
  318. */
  319. static inline uint32_t dp_rx_get_le32(const uint8_t *p)
  320. {
  321. return dp_rx_get_le32_split(p[0], p[1], p[2], p[3]);
  322. }
  323. /*
  324. * dp_rx_put_le32() - put little endian 32 bits
  325. * @p: destination char array
  326. * @v: source 32-bit integer
  327. *
  328. * Returns: None
  329. */
  330. static inline void dp_rx_put_le32(uint8_t *p, uint32_t v)
  331. {
  332. p[0] = (v) & 0xff;
  333. p[1] = (v >> 8) & 0xff;
  334. p[2] = (v >> 16) & 0xff;
  335. p[3] = (v >> 24) & 0xff;
  336. }
  337. /* Extract michal mic block of data */
  338. #define dp_rx_michael_block(l, r) \
  339. do { \
  340. r ^= dp_rx_rotl(l, 17); \
  341. l += r; \
  342. r ^= dp_rx_xswap(l); \
  343. l += r; \
  344. r ^= dp_rx_rotl(l, 3); \
  345. l += r; \
  346. r ^= dp_rx_rotr(l, 2); \
  347. l += r; \
  348. } while (0)
  349. /**
  350. * struct dp_rx_desc_list_elem_t
  351. *
  352. * @next : Next pointer to form free list
  353. * @rx_desc : DP Rx descriptor
  354. */
  355. union dp_rx_desc_list_elem_t {
  356. union dp_rx_desc_list_elem_t *next;
  357. struct dp_rx_desc rx_desc;
  358. };
  359. #ifdef RX_DESC_MULTI_PAGE_ALLOC
  360. /**
  361. * dp_rx_desc_find() - find dp rx descriptor from page ID and offset
  362. * @page_id: Page ID
  363. * @offset: Offset of the descriptor element
  364. *
  365. * Return: RX descriptor element
  366. */
  367. union dp_rx_desc_list_elem_t *dp_rx_desc_find(uint16_t page_id, uint16_t offset,
  368. struct rx_desc_pool *rx_pool);
  369. static inline
  370. struct dp_rx_desc *dp_get_rx_desc_from_cookie(struct dp_soc *soc,
  371. struct rx_desc_pool *pool,
  372. uint32_t cookie)
  373. {
  374. uint8_t pool_id = DP_RX_DESC_MULTI_PAGE_COOKIE_GET_POOL_ID(cookie);
  375. uint16_t page_id = DP_RX_DESC_MULTI_PAGE_COOKIE_GET_PAGE_ID(cookie);
  376. uint8_t offset = DP_RX_DESC_MULTI_PAGE_COOKIE_GET_OFFSET(cookie);
  377. struct rx_desc_pool *rx_desc_pool;
  378. union dp_rx_desc_list_elem_t *rx_desc_elem;
  379. if (qdf_unlikely(pool_id >= MAX_RXDESC_POOLS))
  380. return NULL;
  381. rx_desc_pool = &pool[pool_id];
  382. rx_desc_elem = (union dp_rx_desc_list_elem_t *)
  383. (rx_desc_pool->desc_pages.cacheable_pages[page_id] +
  384. rx_desc_pool->elem_size * offset);
  385. return &rx_desc_elem->rx_desc;
  386. }
  387. /**
  388. * dp_rx_cookie_2_va_rxdma_buf() - Converts cookie to a virtual address of
  389. * the Rx descriptor on Rx DMA source ring buffer
  390. * @soc: core txrx main context
  391. * @cookie: cookie used to lookup virtual address
  392. *
  393. * Return: Pointer to the Rx descriptor
  394. */
  395. static inline
  396. struct dp_rx_desc *dp_rx_cookie_2_va_rxdma_buf(struct dp_soc *soc,
  397. uint32_t cookie)
  398. {
  399. return dp_get_rx_desc_from_cookie(soc, &soc->rx_desc_buf[0], cookie);
  400. }
  401. /**
  402. * dp_rx_cookie_2_va_mon_buf() - Converts cookie to a virtual address of
  403. * the Rx descriptor on monitor ring buffer
  404. * @soc: core txrx main context
  405. * @cookie: cookie used to lookup virtual address
  406. *
  407. * Return: Pointer to the Rx descriptor
  408. */
  409. static inline
  410. struct dp_rx_desc *dp_rx_cookie_2_va_mon_buf(struct dp_soc *soc,
  411. uint32_t cookie)
  412. {
  413. return dp_get_rx_desc_from_cookie(soc, &soc->rx_desc_mon[0], cookie);
  414. }
  415. /**
  416. * dp_rx_cookie_2_va_mon_status() - Converts cookie to a virtual address of
  417. * the Rx descriptor on monitor status ring buffer
  418. * @soc: core txrx main context
  419. * @cookie: cookie used to lookup virtual address
  420. *
  421. * Return: Pointer to the Rx descriptor
  422. */
  423. static inline
  424. struct dp_rx_desc *dp_rx_cookie_2_va_mon_status(struct dp_soc *soc,
  425. uint32_t cookie)
  426. {
  427. return dp_get_rx_desc_from_cookie(soc, &soc->rx_desc_status[0], cookie);
  428. }
  429. #else
  430. void dp_rx_desc_pool_init(struct dp_soc *soc, uint32_t pool_id,
  431. uint32_t pool_size,
  432. struct rx_desc_pool *rx_desc_pool);
  433. /**
  434. * dp_rx_cookie_2_va_rxdma_buf() - Converts cookie to a virtual address of
  435. * the Rx descriptor on Rx DMA source ring buffer
  436. * @soc: core txrx main context
  437. * @cookie: cookie used to lookup virtual address
  438. *
  439. * Return: void *: Virtual Address of the Rx descriptor
  440. */
  441. static inline
  442. void *dp_rx_cookie_2_va_rxdma_buf(struct dp_soc *soc, uint32_t cookie)
  443. {
  444. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  445. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  446. struct rx_desc_pool *rx_desc_pool;
  447. if (qdf_unlikely(pool_id >= MAX_RXDESC_POOLS))
  448. return NULL;
  449. rx_desc_pool = &soc->rx_desc_buf[pool_id];
  450. if (qdf_unlikely(index >= rx_desc_pool->pool_size))
  451. return NULL;
  452. return &(soc->rx_desc_buf[pool_id].array[index].rx_desc);
  453. }
  454. /**
  455. * dp_rx_cookie_2_va_mon_buf() - Converts cookie to a virtual address of
  456. * the Rx descriptor on monitor ring buffer
  457. * @soc: core txrx main context
  458. * @cookie: cookie used to lookup virtual address
  459. *
  460. * Return: void *: Virtual Address of the Rx descriptor
  461. */
  462. static inline
  463. void *dp_rx_cookie_2_va_mon_buf(struct dp_soc *soc, uint32_t cookie)
  464. {
  465. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  466. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  467. /* TODO */
  468. /* Add sanity for pool_id & index */
  469. return &(soc->rx_desc_mon[pool_id].array[index].rx_desc);
  470. }
  471. /**
  472. * dp_rx_cookie_2_va_mon_status() - Converts cookie to a virtual address of
  473. * the Rx descriptor on monitor status ring buffer
  474. * @soc: core txrx main context
  475. * @cookie: cookie used to lookup virtual address
  476. *
  477. * Return: void *: Virtual Address of the Rx descriptor
  478. */
  479. static inline
  480. void *dp_rx_cookie_2_va_mon_status(struct dp_soc *soc, uint32_t cookie)
  481. {
  482. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  483. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  484. /* TODO */
  485. /* Add sanity for pool_id & index */
  486. return &(soc->rx_desc_status[pool_id].array[index].rx_desc);
  487. }
  488. #endif /* RX_DESC_MULTI_PAGE_ALLOC */
  489. #ifdef DP_RX_DESC_COOKIE_INVALIDATE
  490. static inline QDF_STATUS
  491. dp_rx_cookie_check_and_invalidate(hal_ring_desc_t ring_desc)
  492. {
  493. if (qdf_unlikely(HAL_RX_REO_BUF_COOKIE_INVALID_GET(ring_desc)))
  494. return QDF_STATUS_E_FAILURE;
  495. HAL_RX_REO_BUF_COOKIE_INVALID_SET(ring_desc);
  496. return QDF_STATUS_SUCCESS;
  497. }
  498. #else
  499. static inline QDF_STATUS
  500. dp_rx_cookie_check_and_invalidate(hal_ring_desc_t ring_desc)
  501. {
  502. return QDF_STATUS_SUCCESS;
  503. }
  504. #endif
  505. QDF_STATUS dp_rx_desc_pool_is_allocated(struct rx_desc_pool *rx_desc_pool);
  506. QDF_STATUS dp_rx_desc_pool_alloc(struct dp_soc *soc,
  507. uint32_t pool_size,
  508. struct rx_desc_pool *rx_desc_pool);
  509. void dp_rx_desc_pool_init(struct dp_soc *soc, uint32_t pool_id,
  510. uint32_t pool_size,
  511. struct rx_desc_pool *rx_desc_pool);
  512. void dp_rx_pdev_mon_buf_buffers_free(struct dp_pdev *pdev, uint32_t mac_id);
  513. void dp_rx_add_desc_list_to_free_list(struct dp_soc *soc,
  514. union dp_rx_desc_list_elem_t **local_desc_list,
  515. union dp_rx_desc_list_elem_t **tail,
  516. uint16_t pool_id,
  517. struct rx_desc_pool *rx_desc_pool);
  518. uint16_t dp_rx_get_free_desc_list(struct dp_soc *soc, uint32_t pool_id,
  519. struct rx_desc_pool *rx_desc_pool,
  520. uint16_t num_descs,
  521. union dp_rx_desc_list_elem_t **desc_list,
  522. union dp_rx_desc_list_elem_t **tail);
  523. QDF_STATUS dp_rx_pdev_desc_pool_alloc(struct dp_pdev *pdev);
  524. void dp_rx_pdev_desc_pool_free(struct dp_pdev *pdev);
  525. QDF_STATUS dp_rx_pdev_desc_pool_init(struct dp_pdev *pdev);
  526. void dp_rx_pdev_desc_pool_deinit(struct dp_pdev *pdev);
  527. void dp_rx_desc_pool_deinit(struct dp_soc *soc,
  528. struct rx_desc_pool *rx_desc_pool);
  529. QDF_STATUS dp_rx_pdev_attach(struct dp_pdev *pdev);
  530. QDF_STATUS dp_rx_pdev_buffers_alloc(struct dp_pdev *pdev);
  531. void dp_rx_pdev_buffers_free(struct dp_pdev *pdev);
  532. void dp_rx_pdev_detach(struct dp_pdev *pdev);
  533. void dp_print_napi_stats(struct dp_soc *soc);
  534. /**
  535. * dp_rx_vdev_detach() - detach vdev from dp rx
  536. * @vdev: virtual device instance
  537. *
  538. * Return: QDF_STATUS_SUCCESS: success
  539. * QDF_STATUS_E_RESOURCES: Error return
  540. */
  541. QDF_STATUS dp_rx_vdev_detach(struct dp_vdev *vdev);
  542. uint32_t
  543. dp_rx_process(struct dp_intr *int_ctx, hal_ring_handle_t hal_ring_hdl,
  544. uint8_t reo_ring_num,
  545. uint32_t quota);
  546. /**
  547. * dp_rx_err_process() - Processes error frames routed to REO error ring
  548. * @int_ctx: pointer to DP interrupt context
  549. * @soc: core txrx main context
  550. * @hal_ring: opaque pointer to the HAL Rx Error Ring, which will be serviced
  551. * @quota: No. of units (packets) that can be serviced in one shot.
  552. *
  553. * This function implements error processing and top level demultiplexer
  554. * for all the frames routed to REO error ring.
  555. *
  556. * Return: uint32_t: No. of elements processed
  557. */
  558. uint32_t dp_rx_err_process(struct dp_intr *int_ctx, struct dp_soc *soc,
  559. hal_ring_handle_t hal_ring_hdl, uint32_t quota);
  560. /**
  561. * dp_rx_wbm_err_process() - Processes error frames routed to WBM release ring
  562. * @int_ctx: pointer to DP interrupt context
  563. * @soc: core txrx main context
  564. * @hal_ring: opaque pointer to the HAL Rx Error Ring, which will be serviced
  565. * @quota: No. of units (packets) that can be serviced in one shot.
  566. *
  567. * This function implements error processing and top level demultiplexer
  568. * for all the frames routed to WBM2HOST sw release ring.
  569. *
  570. * Return: uint32_t: No. of elements processed
  571. */
  572. uint32_t
  573. dp_rx_wbm_err_process(struct dp_intr *int_ctx, struct dp_soc *soc,
  574. hal_ring_handle_t hal_ring_hdl, uint32_t quota);
  575. /**
  576. * dp_rx_sg_create() - create a frag_list for MSDUs which are spread across
  577. * multiple nbufs.
  578. * @soc: core txrx main context
  579. * @nbuf: pointer to the first msdu of an amsdu.
  580. *
  581. * This function implements the creation of RX frag_list for cases
  582. * where an MSDU is spread across multiple nbufs.
  583. *
  584. * Return: returns the head nbuf which contains complete frag_list.
  585. */
  586. qdf_nbuf_t dp_rx_sg_create(struct dp_soc *soc, qdf_nbuf_t nbuf);
  587. /*
  588. * dp_rx_desc_nbuf_and_pool_free() - free the sw rx desc pool called during
  589. * de-initialization of wifi module.
  590. *
  591. * @soc: core txrx main context
  592. * @pool_id: pool_id which is one of 3 mac_ids
  593. * @rx_desc_pool: rx descriptor pool pointer
  594. *
  595. * Return: None
  596. */
  597. void dp_rx_desc_nbuf_and_pool_free(struct dp_soc *soc, uint32_t pool_id,
  598. struct rx_desc_pool *rx_desc_pool);
  599. /*
  600. * dp_rx_desc_nbuf_free() - free the sw rx desc nbufs called during
  601. * de-initialization of wifi module.
  602. *
  603. * @soc: core txrx main context
  604. * @pool_id: pool_id which is one of 3 mac_ids
  605. * @rx_desc_pool: rx descriptor pool pointer
  606. *
  607. * Return: None
  608. */
  609. void dp_rx_desc_nbuf_free(struct dp_soc *soc,
  610. struct rx_desc_pool *rx_desc_pool);
  611. #ifdef DP_RX_MON_MEM_FRAG
  612. /*
  613. * dp_rx_desc_frag_free() - free the sw rx desc frag called during
  614. * de-initialization of wifi module.
  615. *
  616. * @soc: core txrx main context
  617. * @rx_desc_pool: rx descriptor pool pointer
  618. *
  619. * Return: None
  620. */
  621. void dp_rx_desc_frag_free(struct dp_soc *soc,
  622. struct rx_desc_pool *rx_desc_pool);
  623. #else
  624. static inline
  625. void dp_rx_desc_frag_free(struct dp_soc *soc,
  626. struct rx_desc_pool *rx_desc_pool)
  627. {
  628. }
  629. #endif
  630. /*
  631. * dp_rx_desc_pool_free() - free the sw rx desc array called during
  632. * de-initialization of wifi module.
  633. *
  634. * @soc: core txrx main context
  635. * @rx_desc_pool: rx descriptor pool pointer
  636. *
  637. * Return: None
  638. */
  639. void dp_rx_desc_pool_free(struct dp_soc *soc,
  640. struct rx_desc_pool *rx_desc_pool);
  641. void dp_rx_deliver_raw(struct dp_vdev *vdev, qdf_nbuf_t nbuf_list,
  642. struct dp_peer *peer);
  643. #ifdef RX_DESC_DEBUG_CHECK
  644. /**
  645. * dp_rx_desc_paddr_sanity_check() - paddr sanity for ring desc vs rx_desc
  646. * @rx_desc: rx descriptor
  647. * @ring_paddr: paddr obatined from the ring
  648. *
  649. * Returns: QDF_STATUS
  650. */
  651. static inline
  652. bool dp_rx_desc_paddr_sanity_check(struct dp_rx_desc *rx_desc,
  653. uint64_t ring_paddr)
  654. {
  655. return (ring_paddr == qdf_nbuf_get_frag_paddr(rx_desc->nbuf, 0));
  656. }
  657. /*
  658. * dp_rx_desc_alloc_dbg_info() - Alloc memory for rx descriptor debug
  659. * structure
  660. * @rx_desc: rx descriptor pointer
  661. *
  662. * Return: None
  663. */
  664. static inline
  665. void dp_rx_desc_alloc_dbg_info(struct dp_rx_desc *rx_desc)
  666. {
  667. rx_desc->dbg_info = qdf_mem_malloc(sizeof(struct dp_rx_desc_dbg_info));
  668. }
  669. /*
  670. * dp_rx_desc_free_dbg_info() - Free rx descriptor debug
  671. * structure memory
  672. * @rx_desc: rx descriptor pointer
  673. *
  674. * Return: None
  675. */
  676. static inline
  677. void dp_rx_desc_free_dbg_info(struct dp_rx_desc *rx_desc)
  678. {
  679. qdf_mem_free(rx_desc->dbg_info);
  680. }
  681. /*
  682. * dp_rx_desc_update_dbg_info() - Update rx descriptor debug info
  683. * structure memory
  684. * @rx_desc: rx descriptor pointer
  685. *
  686. * Return: None
  687. */
  688. static
  689. void dp_rx_desc_update_dbg_info(struct dp_rx_desc *rx_desc,
  690. const char *func_name, uint8_t flag)
  691. {
  692. struct dp_rx_desc_dbg_info *info = rx_desc->dbg_info;
  693. if (!info)
  694. return;
  695. if (flag == RX_DESC_REPLENISHED) {
  696. qdf_str_lcopy(info->replenish_caller, func_name,
  697. QDF_MEM_FUNC_NAME_SIZE);
  698. info->replenish_ts = qdf_get_log_timestamp();
  699. } else {
  700. qdf_str_lcopy(info->freelist_caller, func_name,
  701. QDF_MEM_FUNC_NAME_SIZE);
  702. info->freelist_ts = qdf_get_log_timestamp();
  703. }
  704. }
  705. #else
  706. static inline
  707. bool dp_rx_desc_paddr_sanity_check(struct dp_rx_desc *rx_desc,
  708. uint64_t ring_paddr)
  709. {
  710. return true;
  711. }
  712. static inline
  713. void dp_rx_desc_alloc_dbg_info(struct dp_rx_desc *rx_desc)
  714. {
  715. }
  716. static inline
  717. void dp_rx_desc_free_dbg_info(struct dp_rx_desc *rx_desc)
  718. {
  719. }
  720. static inline
  721. void dp_rx_desc_update_dbg_info(struct dp_rx_desc *rx_desc,
  722. const char *func_name, uint8_t flag)
  723. {
  724. }
  725. #endif /* RX_DESC_DEBUG_CHECK */
  726. /**
  727. * dp_rx_add_to_free_desc_list() - Adds to a local free descriptor list
  728. *
  729. * @head: pointer to the head of local free list
  730. * @tail: pointer to the tail of local free list
  731. * @new: new descriptor that is added to the free list
  732. * @func_name: caller func name
  733. *
  734. * Return: void:
  735. */
  736. static inline
  737. void __dp_rx_add_to_free_desc_list(union dp_rx_desc_list_elem_t **head,
  738. union dp_rx_desc_list_elem_t **tail,
  739. struct dp_rx_desc *new, const char *func_name)
  740. {
  741. qdf_assert(head && new);
  742. new->nbuf = NULL;
  743. new->in_use = 0;
  744. ((union dp_rx_desc_list_elem_t *)new)->next = *head;
  745. *head = (union dp_rx_desc_list_elem_t *)new;
  746. /* reset tail if head->next is NULL */
  747. if (!*tail || !(*head)->next)
  748. *tail = *head;
  749. dp_rx_desc_update_dbg_info(new, func_name, RX_DESC_IN_FREELIST);
  750. }
  751. uint8_t dp_rx_process_invalid_peer(struct dp_soc *soc, qdf_nbuf_t nbuf,
  752. uint8_t mac_id);
  753. void dp_rx_process_invalid_peer_wrapper(struct dp_soc *soc,
  754. qdf_nbuf_t mpdu, bool mpdu_done, uint8_t mac_id);
  755. void dp_rx_process_mic_error(struct dp_soc *soc, qdf_nbuf_t nbuf,
  756. uint8_t *rx_tlv_hdr, struct dp_peer *peer);
  757. void dp_2k_jump_handle(struct dp_soc *soc, qdf_nbuf_t nbuf, uint8_t *rx_tlv_hdr,
  758. uint16_t peer_id, uint8_t tid);
  759. #define DP_RX_HEAD_APPEND(head, elem) \
  760. do { \
  761. qdf_nbuf_set_next((elem), (head)); \
  762. (head) = (elem); \
  763. } while (0)
  764. #define DP_RX_LIST_APPEND(head, tail, elem) \
  765. do { \
  766. if (!(head)) { \
  767. (head) = (elem); \
  768. QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(head) = 1;\
  769. } else { \
  770. qdf_nbuf_set_next((tail), (elem)); \
  771. QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(head)++; \
  772. } \
  773. (tail) = (elem); \
  774. qdf_nbuf_set_next((tail), NULL); \
  775. } while (0)
  776. #define DP_RX_MERGE_TWO_LIST(phead, ptail, chead, ctail) \
  777. do { \
  778. if (!(phead)) { \
  779. (phead) = (chead); \
  780. } else { \
  781. qdf_nbuf_set_next((ptail), (chead)); \
  782. QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(phead) += \
  783. QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(chead); \
  784. } \
  785. (ptail) = (ctail); \
  786. qdf_nbuf_set_next((ptail), NULL); \
  787. } while (0)
  788. /*for qcn9000 emulation the pcie is complete phy and no address restrictions*/
  789. #if !defined(BUILD_X86) || defined(QCA_WIFI_QCN9000)
  790. static inline int check_x86_paddr(struct dp_soc *dp_soc, qdf_nbuf_t *rx_netbuf,
  791. qdf_dma_addr_t *paddr, struct rx_desc_pool *rx_desc_pool)
  792. {
  793. return QDF_STATUS_SUCCESS;
  794. }
  795. #else
  796. #define MAX_RETRY 100
  797. static inline int check_x86_paddr(struct dp_soc *dp_soc, qdf_nbuf_t *rx_netbuf,
  798. qdf_dma_addr_t *paddr, struct rx_desc_pool *rx_desc_pool)
  799. {
  800. uint32_t nbuf_retry = 0;
  801. int32_t ret;
  802. const uint32_t x86_phy_addr = 0x50000000;
  803. /*
  804. * in M2M emulation platforms (x86) the memory below 0x50000000
  805. * is reserved for target use, so any memory allocated in this
  806. * region should not be used by host
  807. */
  808. do {
  809. if (qdf_likely(*paddr > x86_phy_addr))
  810. return QDF_STATUS_SUCCESS;
  811. else {
  812. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  813. "phy addr %pK exceeded 0x50000000 trying again",
  814. paddr);
  815. nbuf_retry++;
  816. if ((*rx_netbuf)) {
  817. qdf_nbuf_unmap_single(dp_soc->osdev, *rx_netbuf,
  818. QDF_DMA_FROM_DEVICE);
  819. /* Not freeing buffer intentionally.
  820. * Observed that same buffer is getting
  821. * re-allocated resulting in longer load time
  822. * WMI init timeout.
  823. * This buffer is anyway not useful so skip it.
  824. **/
  825. }
  826. *rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
  827. rx_desc_pool->buf_size,
  828. RX_BUFFER_RESERVATION,
  829. rx_desc_pool->buf_alignment,
  830. FALSE);
  831. if (qdf_unlikely(!(*rx_netbuf)))
  832. return QDF_STATUS_E_FAILURE;
  833. ret = qdf_nbuf_map_single(dp_soc->osdev, *rx_netbuf,
  834. QDF_DMA_FROM_DEVICE);
  835. if (qdf_unlikely(ret == QDF_STATUS_E_FAILURE)) {
  836. qdf_nbuf_free(*rx_netbuf);
  837. *rx_netbuf = NULL;
  838. continue;
  839. }
  840. *paddr = qdf_nbuf_get_frag_paddr(*rx_netbuf, 0);
  841. }
  842. } while (nbuf_retry < MAX_RETRY);
  843. if ((*rx_netbuf)) {
  844. qdf_nbuf_unmap_single(dp_soc->osdev, *rx_netbuf,
  845. QDF_DMA_FROM_DEVICE);
  846. qdf_nbuf_free(*rx_netbuf);
  847. }
  848. return QDF_STATUS_E_FAILURE;
  849. }
  850. #endif
  851. /**
  852. * dp_rx_cookie_2_link_desc_va() - Converts cookie to a virtual address of
  853. * the MSDU Link Descriptor
  854. * @soc: core txrx main context
  855. * @buf_info: buf_info includes cookie that is used to lookup
  856. * virtual address of link descriptor after deriving the page id
  857. * and the offset or index of the desc on the associatde page.
  858. *
  859. * This is the VA of the link descriptor, that HAL layer later uses to
  860. * retrieve the list of MSDU's for a given MPDU.
  861. *
  862. * Return: void *: Virtual Address of the Rx descriptor
  863. */
  864. static inline
  865. void *dp_rx_cookie_2_link_desc_va(struct dp_soc *soc,
  866. struct hal_buf_info *buf_info)
  867. {
  868. void *link_desc_va;
  869. struct qdf_mem_multi_page_t *pages;
  870. uint16_t page_id = LINK_DESC_COOKIE_PAGE_ID(buf_info->sw_cookie);
  871. pages = &soc->link_desc_pages;
  872. if (!pages)
  873. return NULL;
  874. if (qdf_unlikely(page_id >= pages->num_pages))
  875. return NULL;
  876. link_desc_va = pages->dma_pages[page_id].page_v_addr_start +
  877. (buf_info->paddr - pages->dma_pages[page_id].page_p_addr);
  878. return link_desc_va;
  879. }
  880. /**
  881. * dp_rx_cookie_2_mon_link_desc_va() - Converts cookie to a virtual address of
  882. * the MSDU Link Descriptor
  883. * @pdev: core txrx pdev context
  884. * @buf_info: buf_info includes cookie that used to lookup virtual address of
  885. * link descriptor. Normally this is just an index into a per pdev array.
  886. *
  887. * This is the VA of the link descriptor in monitor mode destination ring,
  888. * that HAL layer later uses to retrieve the list of MSDU's for a given MPDU.
  889. *
  890. * Return: void *: Virtual Address of the Rx descriptor
  891. */
  892. static inline
  893. void *dp_rx_cookie_2_mon_link_desc_va(struct dp_pdev *pdev,
  894. struct hal_buf_info *buf_info,
  895. int mac_id)
  896. {
  897. void *link_desc_va;
  898. struct qdf_mem_multi_page_t *pages;
  899. uint16_t page_id = LINK_DESC_COOKIE_PAGE_ID(buf_info->sw_cookie);
  900. pages = &pdev->soc->mon_link_desc_pages[mac_id];
  901. if (!pages)
  902. return NULL;
  903. if (qdf_unlikely(page_id >= pages->num_pages))
  904. return NULL;
  905. link_desc_va = pages->dma_pages[page_id].page_v_addr_start +
  906. (buf_info->paddr - pages->dma_pages[page_id].page_p_addr);
  907. return link_desc_va;
  908. }
  909. /**
  910. * dp_rx_defrag_concat() - Concatenate the fragments
  911. *
  912. * @dst: destination pointer to the buffer
  913. * @src: source pointer from where the fragment payload is to be copied
  914. *
  915. * Return: QDF_STATUS
  916. */
  917. static inline QDF_STATUS dp_rx_defrag_concat(qdf_nbuf_t dst, qdf_nbuf_t src)
  918. {
  919. /*
  920. * Inside qdf_nbuf_cat, if it is necessary to reallocate dst
  921. * to provide space for src, the headroom portion is copied from
  922. * the original dst buffer to the larger new dst buffer.
  923. * (This is needed, because the headroom of the dst buffer
  924. * contains the rx desc.)
  925. */
  926. if (!qdf_nbuf_cat(dst, src)) {
  927. /*
  928. * qdf_nbuf_cat does not free the src memory.
  929. * Free src nbuf before returning
  930. * For failure case the caller takes of freeing the nbuf
  931. */
  932. qdf_nbuf_free(src);
  933. return QDF_STATUS_SUCCESS;
  934. }
  935. return QDF_STATUS_E_DEFRAG_ERROR;
  936. }
  937. #ifndef FEATURE_WDS
  938. static inline QDF_STATUS dp_rx_ast_set_active(struct dp_soc *soc, uint16_t sa_idx, bool is_active)
  939. {
  940. return QDF_STATUS_SUCCESS;
  941. }
  942. static inline void
  943. dp_rx_wds_srcport_learn(struct dp_soc *soc,
  944. uint8_t *rx_tlv_hdr,
  945. struct dp_peer *ta_peer,
  946. qdf_nbuf_t nbuf,
  947. struct hal_rx_msdu_metadata msdu_metadata)
  948. {
  949. }
  950. #endif
  951. /*
  952. * dp_rx_desc_dump() - dump the sw rx descriptor
  953. *
  954. * @rx_desc: sw rx descriptor
  955. */
  956. static inline void dp_rx_desc_dump(struct dp_rx_desc *rx_desc)
  957. {
  958. dp_info("rx_desc->nbuf: %pK, rx_desc->cookie: %d, rx_desc->pool_id: %d, rx_desc->in_use: %d, rx_desc->unmapped: %d",
  959. rx_desc->nbuf, rx_desc->cookie, rx_desc->pool_id,
  960. rx_desc->in_use, rx_desc->unmapped);
  961. }
  962. /*
  963. * check_qwrap_multicast_loopback() - Check if rx packet is a loopback packet.
  964. * In qwrap mode, packets originated from
  965. * any vdev should not loopback and
  966. * should be dropped.
  967. * @vdev: vdev on which rx packet is received
  968. * @nbuf: rx pkt
  969. *
  970. */
  971. #if ATH_SUPPORT_WRAP
  972. static inline bool check_qwrap_multicast_loopback(struct dp_vdev *vdev,
  973. qdf_nbuf_t nbuf)
  974. {
  975. struct dp_vdev *psta_vdev;
  976. struct dp_pdev *pdev = vdev->pdev;
  977. uint8_t *data = qdf_nbuf_data(nbuf);
  978. if (qdf_unlikely(vdev->proxysta_vdev)) {
  979. /* In qwrap isolation mode, allow loopback packets as all
  980. * packets go to RootAP and Loopback on the mpsta.
  981. */
  982. if (vdev->isolation_vdev)
  983. return false;
  984. TAILQ_FOREACH(psta_vdev, &pdev->vdev_list, vdev_list_elem) {
  985. if (qdf_unlikely(psta_vdev->proxysta_vdev &&
  986. !qdf_mem_cmp(psta_vdev->mac_addr.raw,
  987. &data[QDF_MAC_ADDR_SIZE],
  988. QDF_MAC_ADDR_SIZE))) {
  989. /* Drop packet if source address is equal to
  990. * any of the vdev addresses.
  991. */
  992. return true;
  993. }
  994. }
  995. }
  996. return false;
  997. }
  998. #else
  999. static inline bool check_qwrap_multicast_loopback(struct dp_vdev *vdev,
  1000. qdf_nbuf_t nbuf)
  1001. {
  1002. return false;
  1003. }
  1004. #endif
  1005. #if defined(WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG) ||\
  1006. defined(WLAN_SUPPORT_RX_TAG_STATISTICS) ||\
  1007. defined(WLAN_SUPPORT_RX_FLOW_TAG)
  1008. #include "dp_rx_tag.h"
  1009. #endif
  1010. #ifndef WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG
  1011. /**
  1012. * dp_rx_update_protocol_tag() - Reads CCE metadata from the RX MSDU end TLV
  1013. * and set the corresponding tag in QDF packet
  1014. * @soc: core txrx main context
  1015. * @vdev: vdev on which the packet is received
  1016. * @nbuf: QDF pkt buffer on which the protocol tag should be set
  1017. * @rx_tlv_hdr: rBbase address where the RX TLVs starts
  1018. * @ring_index: REO ring number, not used for error & monitor ring
  1019. * @is_reo_exception: flag to indicate if rx from REO ring or exception ring
  1020. * @is_update_stats: flag to indicate whether to update stats or not
  1021. * Return: void
  1022. */
  1023. static inline void
  1024. dp_rx_update_protocol_tag(struct dp_soc *soc, struct dp_vdev *vdev,
  1025. qdf_nbuf_t nbuf, uint8_t *rx_tlv_hdr,
  1026. uint16_t ring_index,
  1027. bool is_reo_exception, bool is_update_stats)
  1028. {
  1029. }
  1030. #endif /* WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG */
  1031. #ifndef WLAN_SUPPORT_RX_FLOW_TAG
  1032. /**
  1033. * dp_rx_update_flow_tag() - Reads FSE metadata from the RX MSDU end TLV
  1034. * and set the corresponding tag in QDF packet
  1035. * @soc: core txrx main context
  1036. * @vdev: vdev on which the packet is received
  1037. * @nbuf: QDF pkt buffer on which the protocol tag should be set
  1038. * @rx_tlv_hdr: base address where the RX TLVs starts
  1039. * @is_update_stats: flag to indicate whether to update stats or not
  1040. *
  1041. * Return: void
  1042. */
  1043. static inline void
  1044. dp_rx_update_flow_tag(struct dp_soc *soc, struct dp_vdev *vdev,
  1045. qdf_nbuf_t nbuf, uint8_t *rx_tlv_hdr, bool update_stats)
  1046. {
  1047. }
  1048. #endif /* WLAN_SUPPORT_RX_FLOW_TAG */
  1049. #if !defined(WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG) &&\
  1050. !defined(WLAN_SUPPORT_RX_FLOW_TAG)
  1051. /**
  1052. * dp_rx_mon_update_protocol_flow_tag() - Performs necessary checks for monitor
  1053. * mode and then tags appropriate packets
  1054. * @soc: core txrx main context
  1055. * @vdev: pdev on which packet is received
  1056. * @msdu: QDF packet buffer on which the protocol tag should be set
  1057. * @rx_desc: base address where the RX TLVs start
  1058. * Return: void
  1059. */
  1060. static inline
  1061. void dp_rx_mon_update_protocol_flow_tag(struct dp_soc *soc,
  1062. struct dp_pdev *dp_pdev,
  1063. qdf_nbuf_t msdu, void *rx_desc)
  1064. {
  1065. }
  1066. #endif /* WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG || WLAN_SUPPORT_RX_FLOW_TAG */
  1067. /*
  1068. * dp_rx_buffers_replenish() - replenish rxdma ring with rx nbufs
  1069. * called during dp rx initialization
  1070. * and at the end of dp_rx_process.
  1071. *
  1072. * @soc: core txrx main context
  1073. * @mac_id: mac_id which is one of 3 mac_ids
  1074. * @dp_rxdma_srng: dp rxdma circular ring
  1075. * @rx_desc_pool: Pointer to free Rx descriptor pool
  1076. * @num_req_buffers: number of buffer to be replenished
  1077. * @desc_list: list of descs if called from dp_rx_process
  1078. * or NULL during dp rx initialization or out of buffer
  1079. * interrupt.
  1080. * @tail: tail of descs list
  1081. * @func_name: name of the caller function
  1082. * Return: return success or failure
  1083. */
  1084. QDF_STATUS __dp_rx_buffers_replenish(struct dp_soc *dp_soc, uint32_t mac_id,
  1085. struct dp_srng *dp_rxdma_srng,
  1086. struct rx_desc_pool *rx_desc_pool,
  1087. uint32_t num_req_buffers,
  1088. union dp_rx_desc_list_elem_t **desc_list,
  1089. union dp_rx_desc_list_elem_t **tail,
  1090. const char *func_name);
  1091. /*
  1092. * dp_pdev_rx_buffers_attach() - replenish rxdma ring with rx nbufs
  1093. * called during dp rx initialization
  1094. *
  1095. * @soc: core txrx main context
  1096. * @mac_id: mac_id which is one of 3 mac_ids
  1097. * @dp_rxdma_srng: dp rxdma circular ring
  1098. * @rx_desc_pool: Pointer to free Rx descriptor pool
  1099. * @num_req_buffers: number of buffer to be replenished
  1100. *
  1101. * Return: return success or failure
  1102. */
  1103. QDF_STATUS
  1104. dp_pdev_rx_buffers_attach(struct dp_soc *dp_soc, uint32_t mac_id,
  1105. struct dp_srng *dp_rxdma_srng,
  1106. struct rx_desc_pool *rx_desc_pool,
  1107. uint32_t num_req_buffers);
  1108. /**
  1109. * dp_rx_link_desc_return() - Return a MPDU link descriptor to HW
  1110. * (WBM), following error handling
  1111. *
  1112. * @soc: core DP main context
  1113. * @buf_addr_info: opaque pointer to the REO error ring descriptor
  1114. * @buf_addr_info: void pointer to the buffer_addr_info
  1115. * @bm_action: put to idle_list or release to msdu_list
  1116. *
  1117. * Return: QDF_STATUS_E_FAILURE for failure else QDF_STATUS_SUCCESS
  1118. */
  1119. QDF_STATUS
  1120. dp_rx_link_desc_return(struct dp_soc *soc, hal_ring_desc_t ring_desc,
  1121. uint8_t bm_action);
  1122. /**
  1123. * dp_rx_link_desc_return_by_addr - Return a MPDU link descriptor to
  1124. * (WBM) by address
  1125. *
  1126. * @soc: core DP main context
  1127. * @link_desc_addr: link descriptor addr
  1128. *
  1129. * Return: QDF_STATUS_E_FAILURE for failure else QDF_STATUS_SUCCESS
  1130. */
  1131. QDF_STATUS
  1132. dp_rx_link_desc_return_by_addr(struct dp_soc *soc,
  1133. hal_buff_addrinfo_t link_desc_addr,
  1134. uint8_t bm_action);
  1135. /**
  1136. * dp_rxdma_err_process() - RxDMA error processing functionality
  1137. * @soc: core txrx main contex
  1138. * @mac_id: mac id which is one of 3 mac_ids
  1139. * @hal_ring: opaque pointer to the HAL Rx Ring, which will be serviced
  1140. * @quota: No. of units (packets) that can be serviced in one shot.
  1141. *
  1142. * Return: num of buffers processed
  1143. */
  1144. uint32_t
  1145. dp_rxdma_err_process(struct dp_intr *int_ctx, struct dp_soc *soc,
  1146. uint32_t mac_id, uint32_t quota);
  1147. void dp_rx_fill_mesh_stats(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1148. uint8_t *rx_tlv_hdr, struct dp_peer *peer);
  1149. QDF_STATUS dp_rx_filter_mesh_packets(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1150. uint8_t *rx_tlv_hdr);
  1151. int dp_wds_rx_policy_check(uint8_t *rx_tlv_hdr, struct dp_vdev *vdev,
  1152. struct dp_peer *peer);
  1153. /*
  1154. * dp_rx_dump_info_and_assert() - dump RX Ring info and Rx Desc info
  1155. *
  1156. * @soc: core txrx main context
  1157. * @hal_ring: opaque pointer to the HAL Rx Ring, which will be serviced
  1158. * @ring_desc: opaque pointer to the RX ring descriptor
  1159. * @rx_desc: host rx descriptor
  1160. *
  1161. * Return: void
  1162. */
  1163. void dp_rx_dump_info_and_assert(struct dp_soc *soc,
  1164. hal_ring_handle_t hal_ring_hdl,
  1165. hal_ring_desc_t ring_desc,
  1166. struct dp_rx_desc *rx_desc);
  1167. void dp_rx_compute_delay(struct dp_vdev *vdev, qdf_nbuf_t nbuf);
  1168. #ifdef QCA_PEER_EXT_STATS
  1169. void dp_rx_compute_tid_delay(struct cdp_delay_tid_stats *stats,
  1170. qdf_nbuf_t nbuf);
  1171. #endif /* QCA_PEER_EXT_STATS */
  1172. #ifdef RX_DESC_DEBUG_CHECK
  1173. /**
  1174. * dp_rx_desc_check_magic() - check the magic value in dp_rx_desc
  1175. * @rx_desc: rx descriptor pointer
  1176. *
  1177. * Return: true, if magic is correct, else false.
  1178. */
  1179. static inline bool dp_rx_desc_check_magic(struct dp_rx_desc *rx_desc)
  1180. {
  1181. if (qdf_unlikely(rx_desc->magic != DP_RX_DESC_MAGIC))
  1182. return false;
  1183. rx_desc->magic = 0;
  1184. return true;
  1185. }
  1186. /**
  1187. * dp_rx_desc_prep() - prepare rx desc
  1188. * @rx_desc: rx descriptor pointer to be prepared
  1189. * @nbuf_frag_info_t: struct dp_rx_nbuf_frag_info *
  1190. *
  1191. * Note: assumption is that we are associating a nbuf which is mapped
  1192. *
  1193. * Return: none
  1194. */
  1195. static inline
  1196. void dp_rx_desc_prep(struct dp_rx_desc *rx_desc,
  1197. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1198. {
  1199. rx_desc->magic = DP_RX_DESC_MAGIC;
  1200. rx_desc->nbuf = (nbuf_frag_info_t->virt_addr).nbuf;
  1201. rx_desc->unmapped = 0;
  1202. }
  1203. /**
  1204. * dp_rx_desc_frag_prep() - prepare rx desc
  1205. * @rx_desc: rx descriptor pointer to be prepared
  1206. * @nbuf_frag_info_t: struct dp_rx_nbuf_frag_info *
  1207. *
  1208. * Note: assumption is that we frag address is mapped
  1209. *
  1210. * Return: none
  1211. */
  1212. #ifdef DP_RX_MON_MEM_FRAG
  1213. static inline
  1214. void dp_rx_desc_frag_prep(struct dp_rx_desc *rx_desc,
  1215. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1216. {
  1217. rx_desc->magic = DP_RX_DESC_MAGIC;
  1218. rx_desc->rx_buf_start =
  1219. (uint8_t *)((nbuf_frag_info_t->virt_addr).vaddr);
  1220. rx_desc->paddr_buf_start = nbuf_frag_info_t->paddr;
  1221. rx_desc->unmapped = 0;
  1222. }
  1223. #else
  1224. static inline
  1225. void dp_rx_desc_frag_prep(struct dp_rx_desc *rx_desc,
  1226. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1227. {
  1228. }
  1229. #endif /* DP_RX_MON_MEM_FRAG */
  1230. #else
  1231. static inline bool dp_rx_desc_check_magic(struct dp_rx_desc *rx_desc)
  1232. {
  1233. return true;
  1234. }
  1235. static inline
  1236. void dp_rx_desc_prep(struct dp_rx_desc *rx_desc,
  1237. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1238. {
  1239. rx_desc->nbuf = (nbuf_frag_info_t->virt_addr).nbuf;
  1240. rx_desc->unmapped = 0;
  1241. }
  1242. #ifdef DP_RX_MON_MEM_FRAG
  1243. static inline
  1244. void dp_rx_desc_frag_prep(struct dp_rx_desc *rx_desc,
  1245. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1246. {
  1247. rx_desc->rx_buf_start =
  1248. (uint8_t *)((nbuf_frag_info_t->virt_addr).vaddr);
  1249. rx_desc->paddr_buf_start = nbuf_frag_info_t->paddr;
  1250. rx_desc->unmapped = 0;
  1251. }
  1252. #else
  1253. static inline
  1254. void dp_rx_desc_frag_prep(struct dp_rx_desc *rx_desc,
  1255. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1256. {
  1257. }
  1258. #endif /* DP_RX_MON_MEM_FRAG */
  1259. #endif /* RX_DESC_DEBUG_CHECK */
  1260. void dp_rx_enable_mon_dest_frag(struct rx_desc_pool *rx_desc_pool,
  1261. bool is_mon_dest_desc);
  1262. void dp_rx_process_rxdma_err(struct dp_soc *soc, qdf_nbuf_t nbuf,
  1263. uint8_t *rx_tlv_hdr, struct dp_peer *peer,
  1264. uint8_t err_code, uint8_t mac_id);
  1265. #ifndef QCA_MULTIPASS_SUPPORT
  1266. static inline
  1267. bool dp_rx_multipass_process(struct dp_peer *peer, qdf_nbuf_t nbuf, uint8_t tid)
  1268. {
  1269. return false;
  1270. }
  1271. #else
  1272. bool dp_rx_multipass_process(struct dp_peer *peer, qdf_nbuf_t nbuf,
  1273. uint8_t tid);
  1274. #endif
  1275. #ifndef WLAN_RX_PKT_CAPTURE_ENH
  1276. static inline
  1277. QDF_STATUS dp_peer_set_rx_capture_enabled(struct dp_pdev *pdev,
  1278. struct dp_peer *peer_handle,
  1279. bool value, uint8_t *mac_addr)
  1280. {
  1281. return QDF_STATUS_SUCCESS;
  1282. }
  1283. #endif
  1284. /**
  1285. * dp_rx_deliver_to_stack() - deliver pkts to network stack
  1286. * Caller to hold peer refcount and check for valid peer
  1287. * @soc: soc
  1288. * @vdev: vdev
  1289. * @peer: peer
  1290. * @nbuf_head: skb list head
  1291. * @nbuf_tail: skb list tail
  1292. *
  1293. * Return: None
  1294. */
  1295. void dp_rx_deliver_to_stack(struct dp_soc *soc,
  1296. struct dp_vdev *vdev,
  1297. struct dp_peer *peer,
  1298. qdf_nbuf_t nbuf_head,
  1299. qdf_nbuf_t nbuf_tail);
  1300. #ifdef QCA_OL_RX_LOCK_LESS_ACCESS
  1301. /*
  1302. * dp_rx_ring_access_start()- Wrapper function to log access start of a hal ring
  1303. * @int_ctx: pointer to DP interrupt context
  1304. * @dp_soc - DP soc structure pointer
  1305. * @hal_ring_hdl - HAL ring handle
  1306. *
  1307. * Return: 0 on success; error on failure
  1308. */
  1309. static inline int
  1310. dp_rx_srng_access_start(struct dp_intr *int_ctx, struct dp_soc *soc,
  1311. hal_ring_handle_t hal_ring_hdl)
  1312. {
  1313. return hal_srng_access_start_unlocked(soc->hal_soc, hal_ring_hdl);
  1314. }
  1315. /*
  1316. * dp_rx_ring_access_end()- Wrapper function to log access end of a hal ring
  1317. * @int_ctx: pointer to DP interrupt context
  1318. * @dp_soc - DP soc structure pointer
  1319. * @hal_ring_hdl - HAL ring handle
  1320. *
  1321. * Return - None
  1322. */
  1323. static inline void
  1324. dp_rx_srng_access_end(struct dp_intr *int_ctx, struct dp_soc *soc,
  1325. hal_ring_handle_t hal_ring_hdl)
  1326. {
  1327. hal_srng_access_end_unlocked(soc->hal_soc, hal_ring_hdl);
  1328. }
  1329. #else
  1330. static inline int
  1331. dp_rx_srng_access_start(struct dp_intr *int_ctx, struct dp_soc *soc,
  1332. hal_ring_handle_t hal_ring_hdl)
  1333. {
  1334. return dp_srng_access_start(int_ctx, soc, hal_ring_hdl);
  1335. }
  1336. static inline void
  1337. dp_rx_srng_access_end(struct dp_intr *int_ctx, struct dp_soc *soc,
  1338. hal_ring_handle_t hal_ring_hdl)
  1339. {
  1340. dp_srng_access_end(int_ctx, soc, hal_ring_hdl);
  1341. }
  1342. #endif
  1343. /*
  1344. * dp_rx_wbm_sg_list_reset() - Initialize sg list
  1345. *
  1346. * This api should be called at soc init and afterevery sg processing.
  1347. *@soc: DP SOC handle
  1348. */
  1349. static inline void dp_rx_wbm_sg_list_reset(struct dp_soc *soc)
  1350. {
  1351. if (soc) {
  1352. soc->wbm_sg_param.wbm_is_first_msdu_in_sg = false;
  1353. soc->wbm_sg_param.wbm_sg_nbuf_head = NULL;
  1354. soc->wbm_sg_param.wbm_sg_nbuf_tail = NULL;
  1355. soc->wbm_sg_param.wbm_sg_desc_msdu_len = 0;
  1356. }
  1357. }
  1358. /*
  1359. * dp_rx_wbm_sg_list_deinit() - De-initialize sg list
  1360. *
  1361. * This api should be called in down path, to avoid any leak.
  1362. *@soc: DP SOC handle
  1363. */
  1364. static inline void dp_rx_wbm_sg_list_deinit(struct dp_soc *soc)
  1365. {
  1366. if (soc) {
  1367. if (soc->wbm_sg_param.wbm_sg_nbuf_head)
  1368. qdf_nbuf_list_free(soc->wbm_sg_param.wbm_sg_nbuf_head);
  1369. dp_rx_wbm_sg_list_reset(soc);
  1370. }
  1371. }
  1372. #ifdef WLAN_FEATURE_RX_PREALLOC_BUFFER_POOL
  1373. #define DP_RX_PROCESS_NBUF(soc, head, tail, ebuf_head, ebuf_tail, rx_desc) \
  1374. do { \
  1375. if (!soc->rx_buff_pool[rx_desc->pool_id].is_initialized) { \
  1376. DP_RX_LIST_APPEND(head, tail, rx_desc->nbuf); \
  1377. break; \
  1378. } \
  1379. DP_RX_LIST_APPEND(ebuf_head, ebuf_tail, rx_desc->nbuf); \
  1380. if (!qdf_nbuf_is_rx_chfrag_cont(rx_desc->nbuf)) { \
  1381. if (!dp_rx_buffer_pool_refill(soc, ebuf_head, \
  1382. rx_desc->pool_id)) \
  1383. DP_RX_MERGE_TWO_LIST(head, tail, \
  1384. ebuf_head, ebuf_tail);\
  1385. ebuf_head = NULL; \
  1386. ebuf_tail = NULL; \
  1387. } \
  1388. } while (0)
  1389. #else
  1390. #define DP_RX_PROCESS_NBUF(soc, head, tail, ebuf_head, ebuf_tail, rx_desc) \
  1391. DP_RX_LIST_APPEND(head, tail, rx_desc->nbuf)
  1392. #endif /* WLAN_FEATURE_RX_PREALLOC_BUFFER_POOL */
  1393. /*
  1394. * dp_rx_link_desc_refill_duplicate_check() - check if link desc duplicate
  1395. to refill
  1396. * @soc: DP SOC handle
  1397. * @buf_info: the last link desc buf info
  1398. * @ring_buf_info: current buf address pointor including link desc
  1399. *
  1400. * return: none.
  1401. */
  1402. void dp_rx_link_desc_refill_duplicate_check(
  1403. struct dp_soc *soc,
  1404. struct hal_buf_info *buf_info,
  1405. hal_buff_addrinfo_t ring_buf_info);
  1406. #endif /* _DP_RX_H */