dp_rx.h 42 KB

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