dp_rx.h 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993
  1. /*
  2. * Copyright (c) 2016-2021 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_peer.h"
  22. #include "dp_internal.h"
  23. #ifdef RXDMA_OPTIMIZATION
  24. #ifndef RX_DATA_BUFFER_ALIGNMENT
  25. #define RX_DATA_BUFFER_ALIGNMENT 128
  26. #endif
  27. #ifndef RX_MONITOR_BUFFER_ALIGNMENT
  28. #define RX_MONITOR_BUFFER_ALIGNMENT 128
  29. #endif
  30. #else /* RXDMA_OPTIMIZATION */
  31. #define RX_DATA_BUFFER_ALIGNMENT 4
  32. #define RX_MONITOR_BUFFER_ALIGNMENT 4
  33. #endif /* RXDMA_OPTIMIZATION */
  34. #ifdef QCA_HOST2FW_RXBUF_RING
  35. #define DP_WBM2SW_RBM(sw0_bm_id) HAL_RX_BUF_RBM_SW1_BM(sw0_bm_id)
  36. /* RBM value used for re-injecting defragmented packets into REO */
  37. #define DP_DEFRAG_RBM(sw0_bm_id) HAL_RX_BUF_RBM_SW3_BM(sw0_bm_id)
  38. #else
  39. #define DP_WBM2SW_RBM(sw0_bm_id) HAL_RX_BUF_RBM_SW3_BM(sw0_bm_id)
  40. #define DP_DEFRAG_RBM(sw0_bm_id) DP_WBM2SW_RBM(sw0_bm_id)
  41. #endif /* QCA_HOST2FW_RXBUF_RING */
  42. #define RX_BUFFER_RESERVATION 0
  43. #define DP_PEER_METADATA_PEER_ID_MASK 0x0000ffff
  44. #define DP_PEER_METADATA_PEER_ID_SHIFT 0
  45. #define DP_PEER_METADATA_VDEV_ID_MASK 0x003f0000
  46. #define DP_PEER_METADATA_VDEV_ID_SHIFT 16
  47. #define DP_PEER_METADATA_OFFLOAD_MASK 0x01000000
  48. #define DP_PEER_METADATA_OFFLOAD_SHIFT 24
  49. #define DP_DEFAULT_NOISEFLOOR (-96)
  50. #define DP_PEER_METADATA_PEER_ID_GET(_peer_metadata) \
  51. (((_peer_metadata) & DP_PEER_METADATA_PEER_ID_MASK) \
  52. >> DP_PEER_METADATA_PEER_ID_SHIFT)
  53. #define DP_PEER_METADATA_VDEV_ID_GET(_peer_metadata) \
  54. (((_peer_metadata) & DP_PEER_METADATA_VDEV_ID_MASK) \
  55. >> DP_PEER_METADATA_VDEV_ID_SHIFT)
  56. #define DP_PEER_METADATA_OFFLOAD_GET(_peer_metadata) \
  57. (((_peer_metadata) & DP_PEER_METADATA_OFFLOAD_MASK) \
  58. >> DP_PEER_METADATA_OFFLOAD_SHIFT)
  59. #define DP_RX_DESC_MAGIC 0xdec0de
  60. #define dp_rx_alert(params...) QDF_TRACE_FATAL(QDF_MODULE_ID_DP_RX, params)
  61. #define dp_rx_err(params...) QDF_TRACE_ERROR(QDF_MODULE_ID_DP_RX, params)
  62. #define dp_rx_warn(params...) QDF_TRACE_WARN(QDF_MODULE_ID_DP_RX, params)
  63. #define dp_rx_info(params...) \
  64. __QDF_TRACE_FL(QDF_TRACE_LEVEL_INFO_HIGH, QDF_MODULE_ID_DP_RX, ## params)
  65. #define dp_rx_info_rl(params...) \
  66. __QDF_TRACE_RL(QDF_TRACE_LEVEL_INFO_HIGH, QDF_MODULE_ID_DP_RX, ## params)
  67. #define dp_rx_debug(params...) QDF_TRACE_DEBUG(QDF_MODULE_ID_DP_RX, params)
  68. /**
  69. * enum dp_rx_desc_state
  70. *
  71. * @RX_DESC_REPLENISH: rx desc replenished
  72. * @RX_DESC_FREELIST: rx desc in freelist
  73. */
  74. enum dp_rx_desc_state {
  75. RX_DESC_REPLENISHED,
  76. RX_DESC_IN_FREELIST,
  77. };
  78. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  79. /**
  80. * struct dp_rx_desc_dbg_info
  81. *
  82. * @freelist_caller: name of the function that put the
  83. * the rx desc in freelist
  84. * @freelist_ts: timestamp when the rx desc is put in
  85. * a freelist
  86. * @replenish_caller: name of the function that last
  87. * replenished the rx desc
  88. * @replenish_ts: last replenish timestamp
  89. * @prev_nbuf: previous nbuf info
  90. * @prev_nbuf_data_addr: previous nbuf data address
  91. */
  92. struct dp_rx_desc_dbg_info {
  93. char freelist_caller[QDF_MEM_FUNC_NAME_SIZE];
  94. uint64_t freelist_ts;
  95. char replenish_caller[QDF_MEM_FUNC_NAME_SIZE];
  96. uint64_t replenish_ts;
  97. qdf_nbuf_t prev_nbuf;
  98. uint8_t *prev_nbuf_data_addr;
  99. };
  100. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  101. /**
  102. * struct dp_rx_desc
  103. *
  104. * @nbuf : VA of the "skb" posted
  105. * @rx_buf_start : VA of the original Rx buffer, before
  106. * movement of any skb->data pointer
  107. * @paddr_buf_start : PA of the original Rx buffer, before
  108. * movement of any frag pointer
  109. * @cookie : index into the sw array which holds
  110. * the sw Rx descriptors
  111. * Cookie space is 21 bits:
  112. * lower 18 bits -- index
  113. * upper 3 bits -- pool_id
  114. * @pool_id : pool Id for which this allocated.
  115. * Can only be used if there is no flow
  116. * steering
  117. * @in_use rx_desc is in use
  118. * @unmapped used to mark rx_desc an unmapped if the corresponding
  119. * nbuf is already unmapped
  120. * @in_err_state : Nbuf sanity failed for this descriptor.
  121. * @nbuf_data_addr : VA of nbuf data posted
  122. */
  123. struct dp_rx_desc {
  124. qdf_nbuf_t nbuf;
  125. uint8_t *rx_buf_start;
  126. qdf_dma_addr_t paddr_buf_start;
  127. uint32_t cookie;
  128. uint8_t pool_id;
  129. #ifdef RX_DESC_DEBUG_CHECK
  130. uint32_t magic;
  131. uint8_t *nbuf_data_addr;
  132. struct dp_rx_desc_dbg_info *dbg_info;
  133. #endif
  134. uint8_t in_use:1,
  135. unmapped:1,
  136. in_err_state:1;
  137. };
  138. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  139. #ifdef ATH_RX_PRI_SAVE
  140. #define DP_RX_TID_SAVE(_nbuf, _tid) \
  141. (qdf_nbuf_set_priority(_nbuf, _tid))
  142. #else
  143. #define DP_RX_TID_SAVE(_nbuf, _tid)
  144. #endif
  145. /* RX Descriptor Multi Page memory alloc related */
  146. #define DP_RX_DESC_OFFSET_NUM_BITS 8
  147. #define DP_RX_DESC_PAGE_ID_NUM_BITS 8
  148. #define DP_RX_DESC_POOL_ID_NUM_BITS 4
  149. #define DP_RX_DESC_PAGE_ID_SHIFT DP_RX_DESC_OFFSET_NUM_BITS
  150. #define DP_RX_DESC_POOL_ID_SHIFT \
  151. (DP_RX_DESC_OFFSET_NUM_BITS + DP_RX_DESC_PAGE_ID_NUM_BITS)
  152. #define RX_DESC_MULTI_PAGE_COOKIE_POOL_ID_MASK \
  153. (((1 << DP_RX_DESC_POOL_ID_NUM_BITS) - 1) << DP_RX_DESC_POOL_ID_SHIFT)
  154. #define RX_DESC_MULTI_PAGE_COOKIE_PAGE_ID_MASK \
  155. (((1 << DP_RX_DESC_PAGE_ID_NUM_BITS) - 1) << \
  156. DP_RX_DESC_PAGE_ID_SHIFT)
  157. #define RX_DESC_MULTI_PAGE_COOKIE_OFFSET_MASK \
  158. ((1 << DP_RX_DESC_OFFSET_NUM_BITS) - 1)
  159. #define DP_RX_DESC_MULTI_PAGE_COOKIE_GET_POOL_ID(_cookie) \
  160. (((_cookie) & RX_DESC_MULTI_PAGE_COOKIE_POOL_ID_MASK) >> \
  161. DP_RX_DESC_POOL_ID_SHIFT)
  162. #define DP_RX_DESC_MULTI_PAGE_COOKIE_GET_PAGE_ID(_cookie) \
  163. (((_cookie) & RX_DESC_MULTI_PAGE_COOKIE_PAGE_ID_MASK) >> \
  164. DP_RX_DESC_PAGE_ID_SHIFT)
  165. #define DP_RX_DESC_MULTI_PAGE_COOKIE_GET_OFFSET(_cookie) \
  166. ((_cookie) & RX_DESC_MULTI_PAGE_COOKIE_OFFSET_MASK)
  167. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  168. #define RX_DESC_COOKIE_INDEX_SHIFT 0
  169. #define RX_DESC_COOKIE_INDEX_MASK 0x3ffff /* 18 bits */
  170. #define RX_DESC_COOKIE_POOL_ID_SHIFT 18
  171. #define RX_DESC_COOKIE_POOL_ID_MASK 0x1c0000
  172. #define DP_RX_DESC_COOKIE_MAX \
  173. (RX_DESC_COOKIE_INDEX_MASK | RX_DESC_COOKIE_POOL_ID_MASK)
  174. #define DP_RX_DESC_COOKIE_POOL_ID_GET(_cookie) \
  175. (((_cookie) & RX_DESC_COOKIE_POOL_ID_MASK) >> \
  176. RX_DESC_COOKIE_POOL_ID_SHIFT)
  177. #define DP_RX_DESC_COOKIE_INDEX_GET(_cookie) \
  178. (((_cookie) & RX_DESC_COOKIE_INDEX_MASK) >> \
  179. RX_DESC_COOKIE_INDEX_SHIFT)
  180. #define dp_rx_add_to_free_desc_list(head, tail, new) \
  181. __dp_rx_add_to_free_desc_list(head, tail, new, __func__)
  182. #define dp_rx_buffers_replenish(soc, mac_id, rxdma_srng, rx_desc_pool, \
  183. num_buffers, desc_list, tail) \
  184. __dp_rx_buffers_replenish(soc, mac_id, rxdma_srng, rx_desc_pool, \
  185. num_buffers, desc_list, tail, __func__)
  186. #ifdef DP_RX_SPECIAL_FRAME_NEED
  187. /**
  188. * dp_rx_is_special_frame() - check is RX frame special needed
  189. *
  190. * @nbuf: RX skb pointer
  191. * @frame_mask: the mask for speical frame needed
  192. *
  193. * Check is RX frame wanted matched with mask
  194. *
  195. * Return: true - special frame needed, false - no
  196. */
  197. static inline
  198. bool dp_rx_is_special_frame(qdf_nbuf_t nbuf, uint32_t frame_mask)
  199. {
  200. if (((frame_mask & FRAME_MASK_IPV4_ARP) &&
  201. qdf_nbuf_is_ipv4_arp_pkt(nbuf)) ||
  202. ((frame_mask & FRAME_MASK_IPV4_DHCP) &&
  203. qdf_nbuf_is_ipv4_dhcp_pkt(nbuf)) ||
  204. ((frame_mask & FRAME_MASK_IPV4_EAPOL) &&
  205. qdf_nbuf_is_ipv4_eapol_pkt(nbuf)) ||
  206. ((frame_mask & FRAME_MASK_IPV6_DHCP) &&
  207. qdf_nbuf_is_ipv6_dhcp_pkt(nbuf)))
  208. return true;
  209. return false;
  210. }
  211. /**
  212. * dp_rx_deliver_special_frame() - Deliver the RX special frame to stack
  213. * if matches mask
  214. *
  215. * @soc: Datapath soc handler
  216. * @peer: pointer to DP peer
  217. * @nbuf: pointer to the skb of RX frame
  218. * @frame_mask: the mask for speical frame needed
  219. * @rx_tlv_hdr: start of rx tlv header
  220. *
  221. * note: Msdu_len must have been stored in QDF_NBUF_CB_RX_PKT_LEN(nbuf) and
  222. * single nbuf is expected.
  223. *
  224. * return: true - nbuf has been delivered to stack, false - not.
  225. */
  226. bool dp_rx_deliver_special_frame(struct dp_soc *soc, struct dp_peer *peer,
  227. qdf_nbuf_t nbuf, uint32_t frame_mask,
  228. uint8_t *rx_tlv_hdr);
  229. #else
  230. static inline
  231. bool dp_rx_is_special_frame(qdf_nbuf_t nbuf, uint32_t frame_mask)
  232. {
  233. return false;
  234. }
  235. static inline
  236. bool dp_rx_deliver_special_frame(struct dp_soc *soc, struct dp_peer *peer,
  237. qdf_nbuf_t nbuf, uint32_t frame_mask,
  238. uint8_t *rx_tlv_hdr)
  239. {
  240. return false;
  241. }
  242. #endif
  243. /* DOC: Offset to obtain LLC hdr
  244. *
  245. * In the case of Wifi parse error
  246. * to reach LLC header from beginning
  247. * of VLAN tag we need to skip 8 bytes.
  248. * Vlan_tag(4)+length(2)+length added
  249. * by HW(2) = 8 bytes.
  250. */
  251. #define DP_SKIP_VLAN 8
  252. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  253. /**
  254. * struct dp_rx_cached_buf - rx cached buffer
  255. * @list: linked list node
  256. * @buf: skb buffer
  257. */
  258. struct dp_rx_cached_buf {
  259. qdf_list_node_t node;
  260. qdf_nbuf_t buf;
  261. };
  262. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  263. /*
  264. *dp_rx_xor_block() - xor block of data
  265. *@b: destination data block
  266. *@a: source data block
  267. *@len: length of the data to process
  268. *
  269. *Returns: None
  270. */
  271. static inline void dp_rx_xor_block(uint8_t *b, const uint8_t *a, qdf_size_t len)
  272. {
  273. qdf_size_t i;
  274. for (i = 0; i < len; i++)
  275. b[i] ^= a[i];
  276. }
  277. /*
  278. *dp_rx_rotl() - rotate the bits left
  279. *@val: unsigned integer input value
  280. *@bits: number of bits
  281. *
  282. *Returns: Integer with left rotated by number of 'bits'
  283. */
  284. static inline uint32_t dp_rx_rotl(uint32_t val, int bits)
  285. {
  286. return (val << bits) | (val >> (32 - bits));
  287. }
  288. /*
  289. *dp_rx_rotr() - rotate the bits right
  290. *@val: unsigned integer input value
  291. *@bits: number of bits
  292. *
  293. *Returns: Integer with right rotated by number of 'bits'
  294. */
  295. static inline uint32_t dp_rx_rotr(uint32_t val, int bits)
  296. {
  297. return (val >> bits) | (val << (32 - bits));
  298. }
  299. /*
  300. * dp_set_rx_queue() - set queue_mapping in skb
  301. * @nbuf: skb
  302. * @queue_id: rx queue_id
  303. *
  304. * Return: void
  305. */
  306. #ifdef QCA_OL_RX_MULTIQ_SUPPORT
  307. static inline void dp_set_rx_queue(qdf_nbuf_t nbuf, uint8_t queue_id)
  308. {
  309. qdf_nbuf_record_rx_queue(nbuf, queue_id);
  310. return;
  311. }
  312. #else
  313. static inline void dp_set_rx_queue(qdf_nbuf_t nbuf, uint8_t queue_id)
  314. {
  315. }
  316. #endif
  317. /*
  318. *dp_rx_xswap() - swap the bits left
  319. *@val: unsigned integer input value
  320. *
  321. *Returns: Integer with bits swapped
  322. */
  323. static inline uint32_t dp_rx_xswap(uint32_t val)
  324. {
  325. return ((val & 0x00ff00ff) << 8) | ((val & 0xff00ff00) >> 8);
  326. }
  327. /*
  328. *dp_rx_get_le32_split() - get little endian 32 bits split
  329. *@b0: byte 0
  330. *@b1: byte 1
  331. *@b2: byte 2
  332. *@b3: byte 3
  333. *
  334. *Returns: Integer with split little endian 32 bits
  335. */
  336. static inline uint32_t dp_rx_get_le32_split(uint8_t b0, uint8_t b1, uint8_t b2,
  337. uint8_t b3)
  338. {
  339. return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24);
  340. }
  341. /*
  342. *dp_rx_get_le32() - get little endian 32 bits
  343. *@b0: byte 0
  344. *@b1: byte 1
  345. *@b2: byte 2
  346. *@b3: byte 3
  347. *
  348. *Returns: Integer with little endian 32 bits
  349. */
  350. static inline uint32_t dp_rx_get_le32(const uint8_t *p)
  351. {
  352. return dp_rx_get_le32_split(p[0], p[1], p[2], p[3]);
  353. }
  354. /*
  355. * dp_rx_put_le32() - put little endian 32 bits
  356. * @p: destination char array
  357. * @v: source 32-bit integer
  358. *
  359. * Returns: None
  360. */
  361. static inline void dp_rx_put_le32(uint8_t *p, uint32_t v)
  362. {
  363. p[0] = (v) & 0xff;
  364. p[1] = (v >> 8) & 0xff;
  365. p[2] = (v >> 16) & 0xff;
  366. p[3] = (v >> 24) & 0xff;
  367. }
  368. /* Extract michal mic block of data */
  369. #define dp_rx_michael_block(l, r) \
  370. do { \
  371. r ^= dp_rx_rotl(l, 17); \
  372. l += r; \
  373. r ^= dp_rx_xswap(l); \
  374. l += r; \
  375. r ^= dp_rx_rotl(l, 3); \
  376. l += r; \
  377. r ^= dp_rx_rotr(l, 2); \
  378. l += r; \
  379. } while (0)
  380. /**
  381. * struct dp_rx_desc_list_elem_t
  382. *
  383. * @next : Next pointer to form free list
  384. * @rx_desc : DP Rx descriptor
  385. */
  386. union dp_rx_desc_list_elem_t {
  387. union dp_rx_desc_list_elem_t *next;
  388. struct dp_rx_desc rx_desc;
  389. };
  390. #ifdef RX_DESC_MULTI_PAGE_ALLOC
  391. /**
  392. * dp_rx_desc_find() - find dp rx descriptor from page ID and offset
  393. * @page_id: Page ID
  394. * @offset: Offset of the descriptor element
  395. *
  396. * Return: RX descriptor element
  397. */
  398. union dp_rx_desc_list_elem_t *dp_rx_desc_find(uint16_t page_id, uint16_t offset,
  399. struct rx_desc_pool *rx_pool);
  400. static inline
  401. struct dp_rx_desc *dp_get_rx_desc_from_cookie(struct dp_soc *soc,
  402. struct rx_desc_pool *pool,
  403. uint32_t cookie)
  404. {
  405. uint8_t pool_id = DP_RX_DESC_MULTI_PAGE_COOKIE_GET_POOL_ID(cookie);
  406. uint16_t page_id = DP_RX_DESC_MULTI_PAGE_COOKIE_GET_PAGE_ID(cookie);
  407. uint8_t offset = DP_RX_DESC_MULTI_PAGE_COOKIE_GET_OFFSET(cookie);
  408. struct rx_desc_pool *rx_desc_pool;
  409. union dp_rx_desc_list_elem_t *rx_desc_elem;
  410. if (qdf_unlikely(pool_id >= MAX_RXDESC_POOLS))
  411. return NULL;
  412. rx_desc_pool = &pool[pool_id];
  413. rx_desc_elem = (union dp_rx_desc_list_elem_t *)
  414. (rx_desc_pool->desc_pages.cacheable_pages[page_id] +
  415. rx_desc_pool->elem_size * offset);
  416. return &rx_desc_elem->rx_desc;
  417. }
  418. /**
  419. * dp_rx_cookie_2_va_rxdma_buf() - Converts cookie to a virtual address of
  420. * the Rx descriptor on Rx DMA source ring buffer
  421. * @soc: core txrx main context
  422. * @cookie: cookie used to lookup virtual address
  423. *
  424. * Return: Pointer to the Rx descriptor
  425. */
  426. static inline
  427. struct dp_rx_desc *dp_rx_cookie_2_va_rxdma_buf(struct dp_soc *soc,
  428. uint32_t cookie)
  429. {
  430. return dp_get_rx_desc_from_cookie(soc, &soc->rx_desc_buf[0], cookie);
  431. }
  432. /**
  433. * dp_rx_cookie_2_va_mon_buf() - Converts cookie to a virtual address of
  434. * the Rx descriptor on monitor ring buffer
  435. * @soc: core txrx main context
  436. * @cookie: cookie used to lookup virtual address
  437. *
  438. * Return: Pointer to the Rx descriptor
  439. */
  440. static inline
  441. struct dp_rx_desc *dp_rx_cookie_2_va_mon_buf(struct dp_soc *soc,
  442. uint32_t cookie)
  443. {
  444. return dp_get_rx_desc_from_cookie(soc, &soc->rx_desc_mon[0], cookie);
  445. }
  446. /**
  447. * dp_rx_cookie_2_va_mon_status() - Converts cookie to a virtual address of
  448. * the Rx descriptor on monitor status ring buffer
  449. * @soc: core txrx main context
  450. * @cookie: cookie used to lookup virtual address
  451. *
  452. * Return: Pointer to the Rx descriptor
  453. */
  454. static inline
  455. struct dp_rx_desc *dp_rx_cookie_2_va_mon_status(struct dp_soc *soc,
  456. uint32_t cookie)
  457. {
  458. return dp_get_rx_desc_from_cookie(soc, &soc->rx_desc_status[0], cookie);
  459. }
  460. #else
  461. void dp_rx_desc_pool_init(struct dp_soc *soc, uint32_t pool_id,
  462. uint32_t pool_size,
  463. struct rx_desc_pool *rx_desc_pool);
  464. /**
  465. * dp_rx_cookie_2_va_rxdma_buf() - Converts cookie to a virtual address of
  466. * the Rx descriptor on Rx DMA source ring buffer
  467. * @soc: core txrx main context
  468. * @cookie: cookie used to lookup virtual address
  469. *
  470. * Return: void *: Virtual Address of the Rx descriptor
  471. */
  472. static inline
  473. void *dp_rx_cookie_2_va_rxdma_buf(struct dp_soc *soc, uint32_t cookie)
  474. {
  475. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  476. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  477. struct rx_desc_pool *rx_desc_pool;
  478. if (qdf_unlikely(pool_id >= MAX_RXDESC_POOLS))
  479. return NULL;
  480. rx_desc_pool = &soc->rx_desc_buf[pool_id];
  481. if (qdf_unlikely(index >= rx_desc_pool->pool_size))
  482. return NULL;
  483. return &(soc->rx_desc_buf[pool_id].array[index].rx_desc);
  484. }
  485. /**
  486. * dp_rx_cookie_2_va_mon_buf() - Converts cookie to a virtual address of
  487. * the Rx descriptor on monitor ring buffer
  488. * @soc: core txrx main context
  489. * @cookie: cookie used to lookup virtual address
  490. *
  491. * Return: void *: Virtual Address of the Rx descriptor
  492. */
  493. static inline
  494. void *dp_rx_cookie_2_va_mon_buf(struct dp_soc *soc, uint32_t cookie)
  495. {
  496. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  497. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  498. /* TODO */
  499. /* Add sanity for pool_id & index */
  500. return &(soc->rx_desc_mon[pool_id].array[index].rx_desc);
  501. }
  502. /**
  503. * dp_rx_cookie_2_va_mon_status() - Converts cookie to a virtual address of
  504. * the Rx descriptor on monitor status ring buffer
  505. * @soc: core txrx main context
  506. * @cookie: cookie used to lookup virtual address
  507. *
  508. * Return: void *: Virtual Address of the Rx descriptor
  509. */
  510. static inline
  511. void *dp_rx_cookie_2_va_mon_status(struct dp_soc *soc, uint32_t cookie)
  512. {
  513. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  514. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  515. /* TODO */
  516. /* Add sanity for pool_id & index */
  517. return &(soc->rx_desc_status[pool_id].array[index].rx_desc);
  518. }
  519. #endif /* RX_DESC_MULTI_PAGE_ALLOC */
  520. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  521. static inline bool dp_rx_check_ap_bridge(struct dp_vdev *vdev)
  522. {
  523. return vdev->ap_bridge_enabled;
  524. }
  525. #ifdef DP_RX_DESC_COOKIE_INVALIDATE
  526. static inline QDF_STATUS
  527. dp_rx_cookie_check_and_invalidate(hal_ring_desc_t ring_desc)
  528. {
  529. if (qdf_unlikely(HAL_RX_REO_BUF_COOKIE_INVALID_GET(ring_desc)))
  530. return QDF_STATUS_E_FAILURE;
  531. HAL_RX_REO_BUF_COOKIE_INVALID_SET(ring_desc);
  532. return QDF_STATUS_SUCCESS;
  533. }
  534. /**
  535. * dp_rx_cookie_reset_invalid_bit() - Reset the invalid bit of the cookie
  536. * field in ring descriptor
  537. * @ring_desc: ring descriptor
  538. *
  539. * Return: None
  540. */
  541. static inline void
  542. dp_rx_cookie_reset_invalid_bit(hal_ring_desc_t ring_desc)
  543. {
  544. HAL_RX_REO_BUF_COOKIE_INVALID_RESET(ring_desc);
  545. }
  546. #else
  547. static inline QDF_STATUS
  548. dp_rx_cookie_check_and_invalidate(hal_ring_desc_t ring_desc)
  549. {
  550. return QDF_STATUS_SUCCESS;
  551. }
  552. static inline void
  553. dp_rx_cookie_reset_invalid_bit(hal_ring_desc_t ring_desc)
  554. {
  555. }
  556. #endif
  557. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  558. QDF_STATUS dp_rx_desc_pool_is_allocated(struct rx_desc_pool *rx_desc_pool);
  559. QDF_STATUS dp_rx_desc_pool_alloc(struct dp_soc *soc,
  560. uint32_t pool_size,
  561. struct rx_desc_pool *rx_desc_pool);
  562. void dp_rx_desc_pool_init(struct dp_soc *soc, uint32_t pool_id,
  563. uint32_t pool_size,
  564. struct rx_desc_pool *rx_desc_pool);
  565. void dp_rx_pdev_mon_buf_buffers_free(struct dp_pdev *pdev, uint32_t mac_id);
  566. void dp_rx_add_desc_list_to_free_list(struct dp_soc *soc,
  567. union dp_rx_desc_list_elem_t **local_desc_list,
  568. union dp_rx_desc_list_elem_t **tail,
  569. uint16_t pool_id,
  570. struct rx_desc_pool *rx_desc_pool);
  571. uint16_t dp_rx_get_free_desc_list(struct dp_soc *soc, uint32_t pool_id,
  572. struct rx_desc_pool *rx_desc_pool,
  573. uint16_t num_descs,
  574. union dp_rx_desc_list_elem_t **desc_list,
  575. union dp_rx_desc_list_elem_t **tail);
  576. QDF_STATUS dp_rx_pdev_desc_pool_alloc(struct dp_pdev *pdev);
  577. void dp_rx_pdev_desc_pool_free(struct dp_pdev *pdev);
  578. QDF_STATUS dp_rx_pdev_desc_pool_init(struct dp_pdev *pdev);
  579. void dp_rx_pdev_desc_pool_deinit(struct dp_pdev *pdev);
  580. void dp_rx_desc_pool_deinit(struct dp_soc *soc,
  581. struct rx_desc_pool *rx_desc_pool);
  582. QDF_STATUS dp_rx_pdev_attach(struct dp_pdev *pdev);
  583. QDF_STATUS dp_rx_pdev_buffers_alloc(struct dp_pdev *pdev);
  584. void dp_rx_pdev_buffers_free(struct dp_pdev *pdev);
  585. void dp_rx_pdev_detach(struct dp_pdev *pdev);
  586. void dp_print_napi_stats(struct dp_soc *soc);
  587. /**
  588. * dp_rx_vdev_detach() - detach vdev from dp rx
  589. * @vdev: virtual device instance
  590. *
  591. * Return: QDF_STATUS_SUCCESS: success
  592. * QDF_STATUS_E_RESOURCES: Error return
  593. */
  594. QDF_STATUS dp_rx_vdev_detach(struct dp_vdev *vdev);
  595. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  596. uint32_t
  597. dp_rx_process(struct dp_intr *int_ctx, hal_ring_handle_t hal_ring_hdl,
  598. uint8_t reo_ring_num,
  599. uint32_t quota);
  600. /**
  601. * dp_rx_err_process() - Processes error frames routed to REO error ring
  602. * @int_ctx: pointer to DP interrupt context
  603. * @soc: core txrx main context
  604. * @hal_ring: opaque pointer to the HAL Rx Error Ring, which will be serviced
  605. * @quota: No. of units (packets) that can be serviced in one shot.
  606. *
  607. * This function implements error processing and top level demultiplexer
  608. * for all the frames routed to REO error ring.
  609. *
  610. * Return: uint32_t: No. of elements processed
  611. */
  612. uint32_t dp_rx_err_process(struct dp_intr *int_ctx, struct dp_soc *soc,
  613. hal_ring_handle_t hal_ring_hdl, uint32_t quota);
  614. /**
  615. * dp_rx_wbm_err_process() - Processes error frames routed to WBM release ring
  616. * @int_ctx: pointer to DP interrupt context
  617. * @soc: core txrx main context
  618. * @hal_ring: opaque pointer to the HAL Rx Error Ring, which will be serviced
  619. * @quota: No. of units (packets) that can be serviced in one shot.
  620. *
  621. * This function implements error processing and top level demultiplexer
  622. * for all the frames routed to WBM2HOST sw release ring.
  623. *
  624. * Return: uint32_t: No. of elements processed
  625. */
  626. uint32_t
  627. dp_rx_wbm_err_process(struct dp_intr *int_ctx, struct dp_soc *soc,
  628. hal_ring_handle_t hal_ring_hdl, uint32_t quota);
  629. /**
  630. * dp_rx_sg_create() - create a frag_list for MSDUs which are spread across
  631. * multiple nbufs.
  632. * @soc: core txrx main context
  633. * @nbuf: pointer to the first msdu of an amsdu.
  634. *
  635. * This function implements the creation of RX frag_list for cases
  636. * where an MSDU is spread across multiple nbufs.
  637. *
  638. * Return: returns the head nbuf which contains complete frag_list.
  639. */
  640. qdf_nbuf_t dp_rx_sg_create(struct dp_soc *soc, qdf_nbuf_t nbuf);
  641. /*
  642. * dp_rx_desc_nbuf_and_pool_free() - free the sw rx desc pool called during
  643. * de-initialization of wifi module.
  644. *
  645. * @soc: core txrx main context
  646. * @pool_id: pool_id which is one of 3 mac_ids
  647. * @rx_desc_pool: rx descriptor pool pointer
  648. *
  649. * Return: None
  650. */
  651. void dp_rx_desc_nbuf_and_pool_free(struct dp_soc *soc, uint32_t pool_id,
  652. struct rx_desc_pool *rx_desc_pool);
  653. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  654. /*
  655. * dp_rx_desc_nbuf_free() - free the sw rx desc nbufs called during
  656. * de-initialization of wifi module.
  657. *
  658. * @soc: core txrx main context
  659. * @pool_id: pool_id which is one of 3 mac_ids
  660. * @rx_desc_pool: rx descriptor pool pointer
  661. *
  662. * Return: None
  663. */
  664. void dp_rx_desc_nbuf_free(struct dp_soc *soc,
  665. struct rx_desc_pool *rx_desc_pool);
  666. #ifdef DP_RX_MON_MEM_FRAG
  667. /*
  668. * dp_rx_desc_frag_free() - free the sw rx desc frag called during
  669. * de-initialization of wifi module.
  670. *
  671. * @soc: core txrx main context
  672. * @rx_desc_pool: rx descriptor pool pointer
  673. *
  674. * Return: None
  675. */
  676. void dp_rx_desc_frag_free(struct dp_soc *soc,
  677. struct rx_desc_pool *rx_desc_pool);
  678. #else
  679. static inline
  680. void dp_rx_desc_frag_free(struct dp_soc *soc,
  681. struct rx_desc_pool *rx_desc_pool)
  682. {
  683. }
  684. #endif
  685. /*
  686. * dp_rx_desc_pool_free() - free the sw rx desc array called during
  687. * de-initialization of wifi module.
  688. *
  689. * @soc: core txrx main context
  690. * @rx_desc_pool: rx descriptor pool pointer
  691. *
  692. * Return: None
  693. */
  694. void dp_rx_desc_pool_free(struct dp_soc *soc,
  695. struct rx_desc_pool *rx_desc_pool);
  696. void dp_rx_deliver_raw(struct dp_vdev *vdev, qdf_nbuf_t nbuf_list,
  697. struct dp_peer *peer);
  698. #ifdef RX_DESC_LOGGING
  699. /*
  700. * dp_rx_desc_alloc_dbg_info() - Alloc memory for rx descriptor debug
  701. * structure
  702. * @rx_desc: rx descriptor pointer
  703. *
  704. * Return: None
  705. */
  706. static inline
  707. void dp_rx_desc_alloc_dbg_info(struct dp_rx_desc *rx_desc)
  708. {
  709. rx_desc->dbg_info = qdf_mem_malloc(sizeof(struct dp_rx_desc_dbg_info));
  710. }
  711. /*
  712. * dp_rx_desc_free_dbg_info() - Free rx descriptor debug
  713. * structure memory
  714. * @rx_desc: rx descriptor pointer
  715. *
  716. * Return: None
  717. */
  718. static inline
  719. void dp_rx_desc_free_dbg_info(struct dp_rx_desc *rx_desc)
  720. {
  721. qdf_mem_free(rx_desc->dbg_info);
  722. }
  723. /*
  724. * dp_rx_desc_update_dbg_info() - Update rx descriptor debug info
  725. * structure memory
  726. * @rx_desc: rx descriptor pointer
  727. *
  728. * Return: None
  729. */
  730. static
  731. void dp_rx_desc_update_dbg_info(struct dp_rx_desc *rx_desc,
  732. const char *func_name, uint8_t flag)
  733. {
  734. struct dp_rx_desc_dbg_info *info = rx_desc->dbg_info;
  735. if (!info)
  736. return;
  737. if (flag == RX_DESC_REPLENISHED) {
  738. qdf_str_lcopy(info->replenish_caller, func_name,
  739. QDF_MEM_FUNC_NAME_SIZE);
  740. info->replenish_ts = qdf_get_log_timestamp();
  741. } else {
  742. qdf_str_lcopy(info->freelist_caller, func_name,
  743. QDF_MEM_FUNC_NAME_SIZE);
  744. info->freelist_ts = qdf_get_log_timestamp();
  745. info->prev_nbuf = rx_desc->nbuf;
  746. info->prev_nbuf_data_addr = rx_desc->nbuf_data_addr;
  747. rx_desc->nbuf_data_addr = NULL;
  748. }
  749. }
  750. #else
  751. static inline
  752. void dp_rx_desc_alloc_dbg_info(struct dp_rx_desc *rx_desc)
  753. {
  754. }
  755. static inline
  756. void dp_rx_desc_free_dbg_info(struct dp_rx_desc *rx_desc)
  757. {
  758. }
  759. static inline
  760. void dp_rx_desc_update_dbg_info(struct dp_rx_desc *rx_desc,
  761. const char *func_name, uint8_t flag)
  762. {
  763. }
  764. #endif /* RX_DESC_LOGGING */
  765. /**
  766. * dp_rx_add_to_free_desc_list() - Adds to a local free descriptor list
  767. *
  768. * @head: pointer to the head of local free list
  769. * @tail: pointer to the tail of local free list
  770. * @new: new descriptor that is added to the free list
  771. * @func_name: caller func name
  772. *
  773. * Return: void:
  774. */
  775. static inline
  776. void __dp_rx_add_to_free_desc_list(union dp_rx_desc_list_elem_t **head,
  777. union dp_rx_desc_list_elem_t **tail,
  778. struct dp_rx_desc *new, const char *func_name)
  779. {
  780. qdf_assert(head && new);
  781. dp_rx_desc_update_dbg_info(new, func_name, RX_DESC_IN_FREELIST);
  782. new->nbuf = NULL;
  783. new->in_use = 0;
  784. ((union dp_rx_desc_list_elem_t *)new)->next = *head;
  785. *head = (union dp_rx_desc_list_elem_t *)new;
  786. /* reset tail if head->next is NULL */
  787. if (!*tail || !(*head)->next)
  788. *tail = *head;
  789. }
  790. uint8_t dp_rx_process_invalid_peer(struct dp_soc *soc, qdf_nbuf_t nbuf,
  791. uint8_t mac_id);
  792. void dp_rx_process_invalid_peer_wrapper(struct dp_soc *soc,
  793. qdf_nbuf_t mpdu, bool mpdu_done, uint8_t mac_id);
  794. void dp_rx_process_mic_error(struct dp_soc *soc, qdf_nbuf_t nbuf,
  795. uint8_t *rx_tlv_hdr, struct dp_peer *peer);
  796. void dp_2k_jump_handle(struct dp_soc *soc, qdf_nbuf_t nbuf, uint8_t *rx_tlv_hdr,
  797. uint16_t peer_id, uint8_t tid);
  798. #define DP_RX_HEAD_APPEND(head, elem) \
  799. do { \
  800. qdf_nbuf_set_next((elem), (head)); \
  801. (head) = (elem); \
  802. } while (0)
  803. #define DP_RX_LIST_APPEND(head, tail, elem) \
  804. do { \
  805. if (!(head)) { \
  806. (head) = (elem); \
  807. QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(head) = 1;\
  808. } else { \
  809. qdf_nbuf_set_next((tail), (elem)); \
  810. QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(head)++; \
  811. } \
  812. (tail) = (elem); \
  813. qdf_nbuf_set_next((tail), NULL); \
  814. } while (0)
  815. #define DP_RX_MERGE_TWO_LIST(phead, ptail, chead, ctail) \
  816. do { \
  817. if (!(phead)) { \
  818. (phead) = (chead); \
  819. } else { \
  820. qdf_nbuf_set_next((ptail), (chead)); \
  821. QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(phead) += \
  822. QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(chead); \
  823. } \
  824. (ptail) = (ctail); \
  825. qdf_nbuf_set_next((ptail), NULL); \
  826. } while (0)
  827. #if defined(QCA_PADDR_CHECK_ON_3TH_PLATFORM)
  828. /*
  829. * on some third-party platform, the memory below 0x2000
  830. * is reserved for target use, so any memory allocated in this
  831. * region should not be used by host
  832. */
  833. #define MAX_RETRY 50
  834. #define DP_PHY_ADDR_RESERVED 0x2000
  835. #elif defined(BUILD_X86)
  836. /*
  837. * in M2M emulation platforms (x86) the memory below 0x50000000
  838. * is reserved for target use, so any memory allocated in this
  839. * region should not be used by host
  840. */
  841. #define MAX_RETRY 100
  842. #define DP_PHY_ADDR_RESERVED 0x50000000
  843. #endif
  844. #if defined(QCA_PADDR_CHECK_ON_3TH_PLATFORM) || defined(BUILD_X86)
  845. /**
  846. * dp_check_paddr() - check if current phy address is valid or not
  847. * @dp_soc: core txrx main context
  848. * @rx_netbuf: skb buffer
  849. * @paddr: physical address
  850. * @rx_desc_pool: struct of rx descriptor pool
  851. * check if the physical address of the nbuf->data is less
  852. * than DP_PHY_ADDR_RESERVED then free the nbuf and try
  853. * allocating new nbuf. We can try for 100 times.
  854. *
  855. * This is a temp WAR till we fix it properly.
  856. *
  857. * Return: success or failure.
  858. */
  859. static inline
  860. int dp_check_paddr(struct dp_soc *dp_soc,
  861. qdf_nbuf_t *rx_netbuf,
  862. qdf_dma_addr_t *paddr,
  863. struct rx_desc_pool *rx_desc_pool)
  864. {
  865. uint32_t nbuf_retry = 0;
  866. int32_t ret;
  867. if (qdf_likely(*paddr > DP_PHY_ADDR_RESERVED))
  868. return QDF_STATUS_SUCCESS;
  869. do {
  870. dp_debug("invalid phy addr 0x%llx, trying again",
  871. (uint64_t)(*paddr));
  872. nbuf_retry++;
  873. if ((*rx_netbuf)) {
  874. /* Not freeing buffer intentionally.
  875. * Observed that same buffer is getting
  876. * re-allocated resulting in longer load time
  877. * WMI init timeout.
  878. * This buffer is anyway not useful so skip it.
  879. *.Add such buffer to invalid list and free
  880. *.them when driver unload.
  881. **/
  882. qdf_nbuf_unmap_nbytes_single(dp_soc->osdev,
  883. *rx_netbuf,
  884. QDF_DMA_FROM_DEVICE,
  885. rx_desc_pool->buf_size);
  886. qdf_nbuf_queue_add(&dp_soc->invalid_buf_queue,
  887. *rx_netbuf);
  888. }
  889. *rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
  890. rx_desc_pool->buf_size,
  891. RX_BUFFER_RESERVATION,
  892. rx_desc_pool->buf_alignment,
  893. FALSE);
  894. if (qdf_unlikely(!(*rx_netbuf)))
  895. return QDF_STATUS_E_FAILURE;
  896. ret = qdf_nbuf_map_nbytes_single(dp_soc->osdev,
  897. *rx_netbuf,
  898. QDF_DMA_FROM_DEVICE,
  899. rx_desc_pool->buf_size);
  900. if (qdf_unlikely(ret == QDF_STATUS_E_FAILURE)) {
  901. qdf_nbuf_free(*rx_netbuf);
  902. *rx_netbuf = NULL;
  903. continue;
  904. }
  905. *paddr = qdf_nbuf_get_frag_paddr(*rx_netbuf, 0);
  906. if (qdf_likely(*paddr > DP_PHY_ADDR_RESERVED))
  907. return QDF_STATUS_SUCCESS;
  908. } while (nbuf_retry < MAX_RETRY);
  909. if ((*rx_netbuf)) {
  910. qdf_nbuf_unmap_nbytes_single(dp_soc->osdev,
  911. *rx_netbuf,
  912. QDF_DMA_FROM_DEVICE,
  913. rx_desc_pool->buf_size);
  914. qdf_nbuf_queue_add(&dp_soc->invalid_buf_queue,
  915. *rx_netbuf);
  916. }
  917. return QDF_STATUS_E_FAILURE;
  918. }
  919. #else
  920. static inline
  921. int dp_check_paddr(struct dp_soc *dp_soc,
  922. qdf_nbuf_t *rx_netbuf,
  923. qdf_dma_addr_t *paddr,
  924. struct rx_desc_pool *rx_desc_pool)
  925. {
  926. return QDF_STATUS_SUCCESS;
  927. }
  928. #endif
  929. /**
  930. * dp_rx_cookie_2_link_desc_va() - Converts cookie to a virtual address of
  931. * the MSDU Link Descriptor
  932. * @soc: core txrx main context
  933. * @buf_info: buf_info includes cookie that is used to lookup
  934. * virtual address of link descriptor after deriving the page id
  935. * and the offset or index of the desc on the associatde page.
  936. *
  937. * This is the VA of the link descriptor, that HAL layer later uses to
  938. * retrieve the list of MSDU's for a given MPDU.
  939. *
  940. * Return: void *: Virtual Address of the Rx descriptor
  941. */
  942. static inline
  943. void *dp_rx_cookie_2_link_desc_va(struct dp_soc *soc,
  944. struct hal_buf_info *buf_info)
  945. {
  946. void *link_desc_va;
  947. struct qdf_mem_multi_page_t *pages;
  948. uint16_t page_id = LINK_DESC_COOKIE_PAGE_ID(buf_info->sw_cookie);
  949. pages = &soc->link_desc_pages;
  950. if (!pages)
  951. return NULL;
  952. if (qdf_unlikely(page_id >= pages->num_pages))
  953. return NULL;
  954. link_desc_va = pages->dma_pages[page_id].page_v_addr_start +
  955. (buf_info->paddr - pages->dma_pages[page_id].page_p_addr);
  956. return link_desc_va;
  957. }
  958. /**
  959. * dp_rx_cookie_2_mon_link_desc_va() - Converts cookie to a virtual address of
  960. * the MSDU Link Descriptor
  961. * @pdev: core txrx pdev context
  962. * @buf_info: buf_info includes cookie that used to lookup virtual address of
  963. * link descriptor. Normally this is just an index into a per pdev array.
  964. *
  965. * This is the VA of the link descriptor in monitor mode destination ring,
  966. * that HAL layer later uses to retrieve the list of MSDU's for a given MPDU.
  967. *
  968. * Return: void *: Virtual Address of the Rx descriptor
  969. */
  970. static inline
  971. void *dp_rx_cookie_2_mon_link_desc_va(struct dp_pdev *pdev,
  972. struct hal_buf_info *buf_info,
  973. int mac_id)
  974. {
  975. void *link_desc_va;
  976. struct qdf_mem_multi_page_t *pages;
  977. uint16_t page_id = LINK_DESC_COOKIE_PAGE_ID(buf_info->sw_cookie);
  978. pages = &pdev->soc->mon_link_desc_pages[mac_id];
  979. if (!pages)
  980. return NULL;
  981. if (qdf_unlikely(page_id >= pages->num_pages))
  982. return NULL;
  983. link_desc_va = pages->dma_pages[page_id].page_v_addr_start +
  984. (buf_info->paddr - pages->dma_pages[page_id].page_p_addr);
  985. return link_desc_va;
  986. }
  987. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  988. /*
  989. * dp_rx_intrabss_fwd() - API for intrabss fwd. For EAPOL
  990. * pkt with DA not equal to vdev mac addr, fwd is not allowed.
  991. * @soc: core txrx main context
  992. * @ta_peer: source peer entry
  993. * @rx_tlv_hdr: start address of rx tlvs
  994. * @nbuf: nbuf that has to be intrabss forwarded
  995. * @msdu_metadata: msdu metadata
  996. *
  997. * Return: true if it is forwarded else false
  998. */
  999. bool dp_rx_intrabss_fwd(struct dp_soc *soc,
  1000. struct dp_peer *ta_peer,
  1001. uint8_t *rx_tlv_hdr,
  1002. qdf_nbuf_t nbuf,
  1003. struct hal_rx_msdu_metadata msdu_metadata);
  1004. #ifdef DISABLE_EAPOL_INTRABSS_FWD
  1005. /*
  1006. * dp_rx_intrabss_fwd_wrapper() - Wrapper API for intrabss fwd. For EAPOL
  1007. * pkt with DA not equal to vdev mac addr, fwd is not allowed.
  1008. * @soc: core txrx main context
  1009. * @ta_peer: source peer entry
  1010. * @rx_tlv_hdr: start address of rx tlvs
  1011. * @nbuf: nbuf that has to be intrabss forwarded
  1012. * @msdu_metadata: msdu metadata
  1013. *
  1014. * Return: true if it is forwarded else false
  1015. */
  1016. static inline
  1017. bool dp_rx_intrabss_fwd_wrapper(struct dp_soc *soc, struct dp_peer *ta_peer,
  1018. uint8_t *rx_tlv_hdr, qdf_nbuf_t nbuf,
  1019. struct hal_rx_msdu_metadata msdu_metadata)
  1020. {
  1021. if (qdf_unlikely(qdf_nbuf_is_ipv4_eapol_pkt(nbuf) &&
  1022. qdf_mem_cmp(qdf_nbuf_data(nbuf) +
  1023. QDF_NBUF_DEST_MAC_OFFSET,
  1024. ta_peer->vdev->mac_addr.raw,
  1025. QDF_MAC_ADDR_SIZE))) {
  1026. qdf_nbuf_free(nbuf);
  1027. DP_STATS_INC(soc, rx.err.intrabss_eapol_drop, 1);
  1028. return true;
  1029. }
  1030. return dp_rx_intrabss_fwd(soc, ta_peer, rx_tlv_hdr, nbuf,
  1031. msdu_metadata);
  1032. }
  1033. #define DP_RX_INTRABSS_FWD(soc, peer, rx_tlv_hdr, nbuf, msdu_metadata) \
  1034. dp_rx_intrabss_fwd_wrapper(soc, peer, rx_tlv_hdr, nbuf, \
  1035. msdu_metadata)
  1036. #else /* DISABLE_EAPOL_INTRABSS_FWD */
  1037. #define DP_RX_INTRABSS_FWD(soc, peer, rx_tlv_hdr, nbuf, msdu_metadata) \
  1038. dp_rx_intrabss_fwd(soc, peer, rx_tlv_hdr, nbuf, msdu_metadata)
  1039. #endif /* DISABLE_EAPOL_INTRABSS_FWD */
  1040. /**
  1041. * dp_rx_defrag_concat() - Concatenate the fragments
  1042. *
  1043. * @dst: destination pointer to the buffer
  1044. * @src: source pointer from where the fragment payload is to be copied
  1045. *
  1046. * Return: QDF_STATUS
  1047. */
  1048. static inline QDF_STATUS dp_rx_defrag_concat(qdf_nbuf_t dst, qdf_nbuf_t src)
  1049. {
  1050. /*
  1051. * Inside qdf_nbuf_cat, if it is necessary to reallocate dst
  1052. * to provide space for src, the headroom portion is copied from
  1053. * the original dst buffer to the larger new dst buffer.
  1054. * (This is needed, because the headroom of the dst buffer
  1055. * contains the rx desc.)
  1056. */
  1057. if (!qdf_nbuf_cat(dst, src)) {
  1058. /*
  1059. * qdf_nbuf_cat does not free the src memory.
  1060. * Free src nbuf before returning
  1061. * For failure case the caller takes of freeing the nbuf
  1062. */
  1063. qdf_nbuf_free(src);
  1064. return QDF_STATUS_SUCCESS;
  1065. }
  1066. return QDF_STATUS_E_DEFRAG_ERROR;
  1067. }
  1068. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  1069. #ifndef FEATURE_WDS
  1070. void dp_rx_da_learn(struct dp_soc *soc, uint8_t *rx_tlv_hdr,
  1071. struct dp_peer *ta_peer, qdf_nbuf_t nbuf);
  1072. static inline QDF_STATUS dp_rx_ast_set_active(struct dp_soc *soc, uint16_t sa_idx, bool is_active)
  1073. {
  1074. return QDF_STATUS_SUCCESS;
  1075. }
  1076. static inline void
  1077. dp_rx_wds_srcport_learn(struct dp_soc *soc,
  1078. uint8_t *rx_tlv_hdr,
  1079. struct dp_peer *ta_peer,
  1080. qdf_nbuf_t nbuf,
  1081. struct hal_rx_msdu_metadata msdu_metadata)
  1082. {
  1083. }
  1084. #endif
  1085. /*
  1086. * dp_rx_desc_dump() - dump the sw rx descriptor
  1087. *
  1088. * @rx_desc: sw rx descriptor
  1089. */
  1090. static inline void dp_rx_desc_dump(struct dp_rx_desc *rx_desc)
  1091. {
  1092. dp_info("rx_desc->nbuf: %pK, rx_desc->cookie: %d, rx_desc->pool_id: %d, rx_desc->in_use: %d, rx_desc->unmapped: %d",
  1093. rx_desc->nbuf, rx_desc->cookie, rx_desc->pool_id,
  1094. rx_desc->in_use, rx_desc->unmapped);
  1095. }
  1096. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  1097. /*
  1098. * check_qwrap_multicast_loopback() - Check if rx packet is a loopback packet.
  1099. * In qwrap mode, packets originated from
  1100. * any vdev should not loopback and
  1101. * should be dropped.
  1102. * @vdev: vdev on which rx packet is received
  1103. * @nbuf: rx pkt
  1104. *
  1105. */
  1106. #if ATH_SUPPORT_WRAP
  1107. static inline bool check_qwrap_multicast_loopback(struct dp_vdev *vdev,
  1108. qdf_nbuf_t nbuf)
  1109. {
  1110. struct dp_vdev *psta_vdev;
  1111. struct dp_pdev *pdev = vdev->pdev;
  1112. uint8_t *data = qdf_nbuf_data(nbuf);
  1113. if (qdf_unlikely(vdev->proxysta_vdev)) {
  1114. /* In qwrap isolation mode, allow loopback packets as all
  1115. * packets go to RootAP and Loopback on the mpsta.
  1116. */
  1117. if (vdev->isolation_vdev)
  1118. return false;
  1119. TAILQ_FOREACH(psta_vdev, &pdev->vdev_list, vdev_list_elem) {
  1120. if (qdf_unlikely(psta_vdev->proxysta_vdev &&
  1121. !qdf_mem_cmp(psta_vdev->mac_addr.raw,
  1122. &data[QDF_MAC_ADDR_SIZE],
  1123. QDF_MAC_ADDR_SIZE))) {
  1124. /* Drop packet if source address is equal to
  1125. * any of the vdev addresses.
  1126. */
  1127. return true;
  1128. }
  1129. }
  1130. }
  1131. return false;
  1132. }
  1133. #else
  1134. static inline bool check_qwrap_multicast_loopback(struct dp_vdev *vdev,
  1135. qdf_nbuf_t nbuf)
  1136. {
  1137. return false;
  1138. }
  1139. #endif
  1140. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  1141. #if defined(WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG) ||\
  1142. defined(WLAN_SUPPORT_RX_TAG_STATISTICS) ||\
  1143. defined(WLAN_SUPPORT_RX_FLOW_TAG)
  1144. #include "dp_rx_tag.h"
  1145. #endif
  1146. #ifndef WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG
  1147. /**
  1148. * dp_rx_update_protocol_tag() - Reads CCE metadata from the RX MSDU end TLV
  1149. * and set the corresponding tag in QDF packet
  1150. * @soc: core txrx main context
  1151. * @vdev: vdev on which the packet is received
  1152. * @nbuf: QDF pkt buffer on which the protocol tag should be set
  1153. * @rx_tlv_hdr: rBbase address where the RX TLVs starts
  1154. * @ring_index: REO ring number, not used for error & monitor ring
  1155. * @is_reo_exception: flag to indicate if rx from REO ring or exception ring
  1156. * @is_update_stats: flag to indicate whether to update stats or not
  1157. * Return: void
  1158. */
  1159. static inline void
  1160. dp_rx_update_protocol_tag(struct dp_soc *soc, struct dp_vdev *vdev,
  1161. qdf_nbuf_t nbuf, uint8_t *rx_tlv_hdr,
  1162. uint16_t ring_index,
  1163. bool is_reo_exception, bool is_update_stats)
  1164. {
  1165. }
  1166. /**
  1167. * dp_rx_err_cce_drop() - Reads CCE metadata from the RX MSDU end TLV
  1168. * and returns whether cce metadata matches
  1169. * @soc: core txrx main context
  1170. * @vdev: vdev on which the packet is received
  1171. * @nbuf: QDF pkt buffer on which the protocol tag should be set
  1172. * @rx_tlv_hdr: rBbase address where the RX TLVs starts
  1173. * Return: bool
  1174. */
  1175. static inline bool
  1176. dp_rx_err_cce_drop(struct dp_soc *soc, struct dp_vdev *vdev,
  1177. qdf_nbuf_t nbuf, uint8_t *rx_tlv_hdr)
  1178. {
  1179. return false;
  1180. }
  1181. #endif /* WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG */
  1182. #ifndef WLAN_SUPPORT_RX_FLOW_TAG
  1183. /**
  1184. * dp_rx_update_flow_tag() - Reads FSE metadata from the RX MSDU end TLV
  1185. * and set the corresponding tag in QDF packet
  1186. * @soc: core txrx main context
  1187. * @vdev: vdev on which the packet is received
  1188. * @nbuf: QDF pkt buffer on which the protocol tag should be set
  1189. * @rx_tlv_hdr: base address where the RX TLVs starts
  1190. * @is_update_stats: flag to indicate whether to update stats or not
  1191. *
  1192. * Return: void
  1193. */
  1194. static inline void
  1195. dp_rx_update_flow_tag(struct dp_soc *soc, struct dp_vdev *vdev,
  1196. qdf_nbuf_t nbuf, uint8_t *rx_tlv_hdr, bool update_stats)
  1197. {
  1198. }
  1199. #endif /* WLAN_SUPPORT_RX_FLOW_TAG */
  1200. #if !defined(WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG) &&\
  1201. !defined(WLAN_SUPPORT_RX_FLOW_TAG)
  1202. /**
  1203. * dp_rx_mon_update_protocol_flow_tag() - Performs necessary checks for monitor
  1204. * mode and then tags appropriate packets
  1205. * @soc: core txrx main context
  1206. * @vdev: pdev on which packet is received
  1207. * @msdu: QDF packet buffer on which the protocol tag should be set
  1208. * @rx_desc: base address where the RX TLVs start
  1209. * Return: void
  1210. */
  1211. static inline
  1212. void dp_rx_mon_update_protocol_flow_tag(struct dp_soc *soc,
  1213. struct dp_pdev *dp_pdev,
  1214. qdf_nbuf_t msdu, void *rx_desc)
  1215. {
  1216. }
  1217. #endif /* WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG || WLAN_SUPPORT_RX_FLOW_TAG */
  1218. /*
  1219. * dp_rx_buffers_replenish() - replenish rxdma ring with rx nbufs
  1220. * called during dp rx initialization
  1221. * and at the end of dp_rx_process.
  1222. *
  1223. * @soc: core txrx main context
  1224. * @mac_id: mac_id which is one of 3 mac_ids
  1225. * @dp_rxdma_srng: dp rxdma circular ring
  1226. * @rx_desc_pool: Pointer to free Rx descriptor pool
  1227. * @num_req_buffers: number of buffer to be replenished
  1228. * @desc_list: list of descs if called from dp_rx_process
  1229. * or NULL during dp rx initialization or out of buffer
  1230. * interrupt.
  1231. * @tail: tail of descs list
  1232. * @func_name: name of the caller function
  1233. * Return: return success or failure
  1234. */
  1235. QDF_STATUS __dp_rx_buffers_replenish(struct dp_soc *dp_soc, uint32_t mac_id,
  1236. struct dp_srng *dp_rxdma_srng,
  1237. struct rx_desc_pool *rx_desc_pool,
  1238. uint32_t num_req_buffers,
  1239. union dp_rx_desc_list_elem_t **desc_list,
  1240. union dp_rx_desc_list_elem_t **tail,
  1241. const char *func_name);
  1242. /*
  1243. * dp_pdev_rx_buffers_attach() - replenish rxdma ring with rx nbufs
  1244. * called during dp rx initialization
  1245. *
  1246. * @soc: core txrx main context
  1247. * @mac_id: mac_id which is one of 3 mac_ids
  1248. * @dp_rxdma_srng: dp rxdma circular ring
  1249. * @rx_desc_pool: Pointer to free Rx descriptor pool
  1250. * @num_req_buffers: number of buffer to be replenished
  1251. *
  1252. * Return: return success or failure
  1253. */
  1254. QDF_STATUS
  1255. dp_pdev_rx_buffers_attach(struct dp_soc *dp_soc, uint32_t mac_id,
  1256. struct dp_srng *dp_rxdma_srng,
  1257. struct rx_desc_pool *rx_desc_pool,
  1258. uint32_t num_req_buffers);
  1259. /**
  1260. * dp_rx_link_desc_return() - Return a MPDU link descriptor to HW
  1261. * (WBM), following error handling
  1262. *
  1263. * @soc: core DP main context
  1264. * @buf_addr_info: opaque pointer to the REO error ring descriptor
  1265. * @buf_addr_info: void pointer to the buffer_addr_info
  1266. * @bm_action: put to idle_list or release to msdu_list
  1267. *
  1268. * Return: QDF_STATUS_E_FAILURE for failure else QDF_STATUS_SUCCESS
  1269. */
  1270. QDF_STATUS
  1271. dp_rx_link_desc_return(struct dp_soc *soc, hal_ring_desc_t ring_desc,
  1272. uint8_t bm_action);
  1273. /**
  1274. * dp_rx_link_desc_return_by_addr - Return a MPDU link descriptor to
  1275. * (WBM) by address
  1276. *
  1277. * @soc: core DP main context
  1278. * @link_desc_addr: link descriptor addr
  1279. *
  1280. * Return: QDF_STATUS_E_FAILURE for failure else QDF_STATUS_SUCCESS
  1281. */
  1282. QDF_STATUS
  1283. dp_rx_link_desc_return_by_addr(struct dp_soc *soc,
  1284. hal_buff_addrinfo_t link_desc_addr,
  1285. uint8_t bm_action);
  1286. /**
  1287. * dp_rxdma_err_process() - RxDMA error processing functionality
  1288. * @soc: core txrx main contex
  1289. * @mac_id: mac id which is one of 3 mac_ids
  1290. * @hal_ring: opaque pointer to the HAL Rx Ring, which will be serviced
  1291. * @quota: No. of units (packets) that can be serviced in one shot.
  1292. *
  1293. * Return: num of buffers processed
  1294. */
  1295. uint32_t
  1296. dp_rxdma_err_process(struct dp_intr *int_ctx, struct dp_soc *soc,
  1297. uint32_t mac_id, uint32_t quota);
  1298. void dp_rx_fill_mesh_stats(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1299. uint8_t *rx_tlv_hdr, struct dp_peer *peer);
  1300. QDF_STATUS dp_rx_filter_mesh_packets(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1301. uint8_t *rx_tlv_hdr);
  1302. int dp_wds_rx_policy_check(uint8_t *rx_tlv_hdr, struct dp_vdev *vdev,
  1303. struct dp_peer *peer);
  1304. /*
  1305. * dp_rx_dump_info_and_assert() - dump RX Ring info and Rx Desc info
  1306. *
  1307. * @soc: core txrx main context
  1308. * @hal_ring: opaque pointer to the HAL Rx Ring, which will be serviced
  1309. * @ring_desc: opaque pointer to the RX ring descriptor
  1310. * @rx_desc: host rx descriptor
  1311. *
  1312. * Return: void
  1313. */
  1314. void dp_rx_dump_info_and_assert(struct dp_soc *soc,
  1315. hal_ring_handle_t hal_ring_hdl,
  1316. hal_ring_desc_t ring_desc,
  1317. struct dp_rx_desc *rx_desc);
  1318. void dp_rx_compute_delay(struct dp_vdev *vdev, qdf_nbuf_t nbuf);
  1319. #ifdef QCA_PEER_EXT_STATS
  1320. void dp_rx_compute_tid_delay(struct cdp_delay_tid_stats *stats,
  1321. qdf_nbuf_t nbuf);
  1322. #endif /* QCA_PEER_EXT_STATS */
  1323. #ifdef RX_DESC_DEBUG_CHECK
  1324. /**
  1325. * dp_rx_desc_check_magic() - check the magic value in dp_rx_desc
  1326. * @rx_desc: rx descriptor pointer
  1327. *
  1328. * Return: true, if magic is correct, else false.
  1329. */
  1330. static inline bool dp_rx_desc_check_magic(struct dp_rx_desc *rx_desc)
  1331. {
  1332. if (qdf_unlikely(rx_desc->magic != DP_RX_DESC_MAGIC))
  1333. return false;
  1334. rx_desc->magic = 0;
  1335. return true;
  1336. }
  1337. /**
  1338. * dp_rx_desc_prep() - prepare rx desc
  1339. * @rx_desc: rx descriptor pointer to be prepared
  1340. * @nbuf_frag_info_t: struct dp_rx_nbuf_frag_info *
  1341. *
  1342. * Note: assumption is that we are associating a nbuf which is mapped
  1343. *
  1344. * Return: none
  1345. */
  1346. static inline
  1347. void dp_rx_desc_prep(struct dp_rx_desc *rx_desc,
  1348. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1349. {
  1350. rx_desc->magic = DP_RX_DESC_MAGIC;
  1351. rx_desc->nbuf = (nbuf_frag_info_t->virt_addr).nbuf;
  1352. rx_desc->unmapped = 0;
  1353. rx_desc->nbuf_data_addr = (uint8_t *)qdf_nbuf_data(rx_desc->nbuf);
  1354. }
  1355. /**
  1356. * dp_rx_desc_frag_prep() - prepare rx desc
  1357. * @rx_desc: rx descriptor pointer to be prepared
  1358. * @nbuf_frag_info_t: struct dp_rx_nbuf_frag_info *
  1359. *
  1360. * Note: assumption is that we frag address is mapped
  1361. *
  1362. * Return: none
  1363. */
  1364. #ifdef DP_RX_MON_MEM_FRAG
  1365. static inline
  1366. void dp_rx_desc_frag_prep(struct dp_rx_desc *rx_desc,
  1367. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1368. {
  1369. rx_desc->magic = DP_RX_DESC_MAGIC;
  1370. rx_desc->rx_buf_start =
  1371. (uint8_t *)((nbuf_frag_info_t->virt_addr).vaddr);
  1372. rx_desc->paddr_buf_start = nbuf_frag_info_t->paddr;
  1373. rx_desc->unmapped = 0;
  1374. }
  1375. #else
  1376. static inline
  1377. void dp_rx_desc_frag_prep(struct dp_rx_desc *rx_desc,
  1378. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1379. {
  1380. }
  1381. #endif /* DP_RX_MON_MEM_FRAG */
  1382. /**
  1383. * dp_rx_desc_paddr_sanity_check() - paddr sanity for ring desc vs rx_desc
  1384. * @rx_desc: rx descriptor
  1385. * @ring_paddr: paddr obatined from the ring
  1386. *
  1387. * Returns: QDF_STATUS
  1388. */
  1389. static inline
  1390. bool dp_rx_desc_paddr_sanity_check(struct dp_rx_desc *rx_desc,
  1391. uint64_t ring_paddr)
  1392. {
  1393. return (ring_paddr == qdf_nbuf_get_frag_paddr(rx_desc->nbuf, 0));
  1394. }
  1395. #else
  1396. static inline bool dp_rx_desc_check_magic(struct dp_rx_desc *rx_desc)
  1397. {
  1398. return true;
  1399. }
  1400. static inline
  1401. void dp_rx_desc_prep(struct dp_rx_desc *rx_desc,
  1402. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1403. {
  1404. rx_desc->nbuf = (nbuf_frag_info_t->virt_addr).nbuf;
  1405. rx_desc->unmapped = 0;
  1406. }
  1407. #ifdef DP_RX_MON_MEM_FRAG
  1408. static inline
  1409. void dp_rx_desc_frag_prep(struct dp_rx_desc *rx_desc,
  1410. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1411. {
  1412. rx_desc->rx_buf_start =
  1413. (uint8_t *)((nbuf_frag_info_t->virt_addr).vaddr);
  1414. rx_desc->paddr_buf_start = nbuf_frag_info_t->paddr;
  1415. rx_desc->unmapped = 0;
  1416. }
  1417. #else
  1418. static inline
  1419. void dp_rx_desc_frag_prep(struct dp_rx_desc *rx_desc,
  1420. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1421. {
  1422. }
  1423. #endif /* DP_RX_MON_MEM_FRAG */
  1424. static inline
  1425. bool dp_rx_desc_paddr_sanity_check(struct dp_rx_desc *rx_desc,
  1426. uint64_t ring_paddr)
  1427. {
  1428. return true;
  1429. }
  1430. #endif /* RX_DESC_DEBUG_CHECK */
  1431. void dp_rx_enable_mon_dest_frag(struct rx_desc_pool *rx_desc_pool,
  1432. bool is_mon_dest_desc);
  1433. void dp_rx_process_rxdma_err(struct dp_soc *soc, qdf_nbuf_t nbuf,
  1434. uint8_t *rx_tlv_hdr, struct dp_peer *peer,
  1435. uint8_t err_code, uint8_t mac_id);
  1436. #ifndef QCA_MULTIPASS_SUPPORT
  1437. static inline
  1438. bool dp_rx_multipass_process(struct dp_peer *peer, qdf_nbuf_t nbuf, uint8_t tid)
  1439. {
  1440. return false;
  1441. }
  1442. #else
  1443. bool dp_rx_multipass_process(struct dp_peer *peer, qdf_nbuf_t nbuf,
  1444. uint8_t tid);
  1445. #endif
  1446. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  1447. #ifndef WLAN_RX_PKT_CAPTURE_ENH
  1448. static inline
  1449. QDF_STATUS dp_peer_set_rx_capture_enabled(struct dp_pdev *pdev,
  1450. struct dp_peer *peer_handle,
  1451. bool value, uint8_t *mac_addr)
  1452. {
  1453. return QDF_STATUS_SUCCESS;
  1454. }
  1455. #endif
  1456. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  1457. /**
  1458. * dp_rx_deliver_to_stack() - deliver pkts to network stack
  1459. * Caller to hold peer refcount and check for valid peer
  1460. * @soc: soc
  1461. * @vdev: vdev
  1462. * @peer: peer
  1463. * @nbuf_head: skb list head
  1464. * @nbuf_tail: skb list tail
  1465. *
  1466. * Return: None
  1467. */
  1468. void dp_rx_deliver_to_stack(struct dp_soc *soc,
  1469. struct dp_vdev *vdev,
  1470. struct dp_peer *peer,
  1471. qdf_nbuf_t nbuf_head,
  1472. qdf_nbuf_t nbuf_tail);
  1473. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  1474. #ifdef QCA_OL_RX_LOCK_LESS_ACCESS
  1475. /*
  1476. * dp_rx_ring_access_start()- Wrapper function to log access start of a hal ring
  1477. * @int_ctx: pointer to DP interrupt context
  1478. * @dp_soc - DP soc structure pointer
  1479. * @hal_ring_hdl - HAL ring handle
  1480. *
  1481. * Return: 0 on success; error on failure
  1482. */
  1483. static inline int
  1484. dp_rx_srng_access_start(struct dp_intr *int_ctx, struct dp_soc *soc,
  1485. hal_ring_handle_t hal_ring_hdl)
  1486. {
  1487. return hal_srng_access_start_unlocked(soc->hal_soc, hal_ring_hdl);
  1488. }
  1489. /*
  1490. * dp_rx_ring_access_end()- Wrapper function to log access end of a hal ring
  1491. * @int_ctx: pointer to DP interrupt context
  1492. * @dp_soc - DP soc structure pointer
  1493. * @hal_ring_hdl - HAL ring handle
  1494. *
  1495. * Return - None
  1496. */
  1497. static inline void
  1498. dp_rx_srng_access_end(struct dp_intr *int_ctx, struct dp_soc *soc,
  1499. hal_ring_handle_t hal_ring_hdl)
  1500. {
  1501. hal_srng_access_end_unlocked(soc->hal_soc, hal_ring_hdl);
  1502. }
  1503. #else
  1504. static inline int
  1505. dp_rx_srng_access_start(struct dp_intr *int_ctx, struct dp_soc *soc,
  1506. hal_ring_handle_t hal_ring_hdl)
  1507. {
  1508. return dp_srng_access_start(int_ctx, soc, hal_ring_hdl);
  1509. }
  1510. static inline void
  1511. dp_rx_srng_access_end(struct dp_intr *int_ctx, struct dp_soc *soc,
  1512. hal_ring_handle_t hal_ring_hdl)
  1513. {
  1514. dp_srng_access_end(int_ctx, soc, hal_ring_hdl);
  1515. }
  1516. #endif
  1517. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  1518. /*
  1519. * dp_rx_wbm_sg_list_reset() - Initialize sg list
  1520. *
  1521. * This api should be called at soc init and afterevery sg processing.
  1522. *@soc: DP SOC handle
  1523. */
  1524. static inline void dp_rx_wbm_sg_list_reset(struct dp_soc *soc)
  1525. {
  1526. if (soc) {
  1527. soc->wbm_sg_param.wbm_is_first_msdu_in_sg = false;
  1528. soc->wbm_sg_param.wbm_sg_nbuf_head = NULL;
  1529. soc->wbm_sg_param.wbm_sg_nbuf_tail = NULL;
  1530. soc->wbm_sg_param.wbm_sg_desc_msdu_len = 0;
  1531. }
  1532. }
  1533. /*
  1534. * dp_rx_wbm_sg_list_deinit() - De-initialize sg list
  1535. *
  1536. * This api should be called in down path, to avoid any leak.
  1537. *@soc: DP SOC handle
  1538. */
  1539. static inline void dp_rx_wbm_sg_list_deinit(struct dp_soc *soc)
  1540. {
  1541. if (soc) {
  1542. if (soc->wbm_sg_param.wbm_sg_nbuf_head)
  1543. qdf_nbuf_list_free(soc->wbm_sg_param.wbm_sg_nbuf_head);
  1544. dp_rx_wbm_sg_list_reset(soc);
  1545. }
  1546. }
  1547. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  1548. #ifdef WLAN_FEATURE_RX_PREALLOC_BUFFER_POOL
  1549. #define DP_RX_PROCESS_NBUF(soc, head, tail, ebuf_head, ebuf_tail, rx_desc) \
  1550. do { \
  1551. if (!soc->rx_buff_pool[rx_desc->pool_id].is_initialized) { \
  1552. DP_RX_LIST_APPEND(head, tail, rx_desc->nbuf); \
  1553. break; \
  1554. } \
  1555. DP_RX_LIST_APPEND(ebuf_head, ebuf_tail, rx_desc->nbuf); \
  1556. if (!qdf_nbuf_is_rx_chfrag_cont(rx_desc->nbuf)) { \
  1557. if (!dp_rx_buffer_pool_refill(soc, ebuf_head, \
  1558. rx_desc->pool_id)) \
  1559. DP_RX_MERGE_TWO_LIST(head, tail, \
  1560. ebuf_head, ebuf_tail);\
  1561. ebuf_head = NULL; \
  1562. ebuf_tail = NULL; \
  1563. } \
  1564. } while (0)
  1565. #else
  1566. #define DP_RX_PROCESS_NBUF(soc, head, tail, ebuf_head, ebuf_tail, rx_desc) \
  1567. DP_RX_LIST_APPEND(head, tail, rx_desc->nbuf)
  1568. #endif /* WLAN_FEATURE_RX_PREALLOC_BUFFER_POOL */
  1569. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  1570. /*
  1571. * dp_rx_link_desc_refill_duplicate_check() - check if link desc duplicate
  1572. to refill
  1573. * @soc: DP SOC handle
  1574. * @buf_info: the last link desc buf info
  1575. * @ring_buf_info: current buf address pointor including link desc
  1576. *
  1577. * return: none.
  1578. */
  1579. void dp_rx_link_desc_refill_duplicate_check(
  1580. struct dp_soc *soc,
  1581. struct hal_buf_info *buf_info,
  1582. hal_buff_addrinfo_t ring_buf_info);
  1583. #ifdef WLAN_FEATURE_PKT_CAPTURE_V2
  1584. /**
  1585. * dp_rx_deliver_to_pkt_capture() - deliver rx packet to packet capture
  1586. * @soc : dp_soc handle
  1587. * @pdev: dp_pdev handle
  1588. * @peer_id: peer_id of the peer for which completion came
  1589. * @ppdu_id: ppdu_id
  1590. * @netbuf: Buffer pointer
  1591. *
  1592. * This function is used to deliver rx packet to packet capture
  1593. */
  1594. void dp_rx_deliver_to_pkt_capture(struct dp_soc *soc, struct dp_pdev *pdev,
  1595. uint16_t peer_id, uint32_t is_offload,
  1596. qdf_nbuf_t netbuf);
  1597. void dp_rx_deliver_to_pkt_capture_no_peer(struct dp_soc *soc, qdf_nbuf_t nbuf,
  1598. uint32_t is_offload);
  1599. #else
  1600. static inline void
  1601. dp_rx_deliver_to_pkt_capture(struct dp_soc *soc, struct dp_pdev *pdev,
  1602. uint16_t peer_id, uint32_t is_offload,
  1603. qdf_nbuf_t netbuf)
  1604. {
  1605. }
  1606. static inline void
  1607. dp_rx_deliver_to_pkt_capture_no_peer(struct dp_soc *soc, qdf_nbuf_t nbuf,
  1608. uint32_t is_offload)
  1609. {
  1610. }
  1611. #endif
  1612. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  1613. #ifdef FEATURE_MEC
  1614. /**
  1615. * dp_rx_mcast_echo_check() - check if the mcast pkt is a loop
  1616. * back on same vap or a different vap.
  1617. * @soc: core DP main context
  1618. * @peer: dp peer handler
  1619. * @rx_tlv_hdr: start of the rx TLV header
  1620. * @nbuf: pkt buffer
  1621. *
  1622. * Return: bool (true if it is a looped back pkt else false)
  1623. *
  1624. */
  1625. bool dp_rx_mcast_echo_check(struct dp_soc *soc,
  1626. struct dp_peer *peer,
  1627. uint8_t *rx_tlv_hdr,
  1628. qdf_nbuf_t nbuf);
  1629. #else
  1630. static inline bool dp_rx_mcast_echo_check(struct dp_soc *soc,
  1631. struct dp_peer *peer,
  1632. uint8_t *rx_tlv_hdr,
  1633. qdf_nbuf_t nbuf)
  1634. {
  1635. return false;
  1636. }
  1637. #endif /* FEATURE_MEC */
  1638. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  1639. #ifdef RECEIVE_OFFLOAD
  1640. void dp_rx_fill_gro_info(struct dp_soc *soc, uint8_t *rx_tlv,
  1641. qdf_nbuf_t msdu, uint32_t *rx_ol_pkt_cnt);
  1642. #else
  1643. static inline
  1644. void dp_rx_fill_gro_info(struct dp_soc *soc, uint8_t *rx_tlv,
  1645. qdf_nbuf_t msdu, uint32_t *rx_ol_pkt_cnt)
  1646. {
  1647. }
  1648. #endif
  1649. void dp_rx_msdu_stats_update(struct dp_soc *soc, qdf_nbuf_t nbuf,
  1650. uint8_t *rx_tlv_hdr, struct dp_peer *peer,
  1651. uint8_t ring_id,
  1652. struct cdp_tid_rx_stats *tid_stats);
  1653. void dp_rx_deliver_to_stack_no_peer(struct dp_soc *soc, qdf_nbuf_t nbuf);
  1654. uint32_t dp_rx_srng_get_num_pending(hal_soc_handle_t hal_soc,
  1655. hal_ring_handle_t hal_ring_hdl,
  1656. uint32_t num_entries,
  1657. bool *near_full);
  1658. #ifdef WLAN_FEATURE_DP_RX_RING_HISTORY
  1659. void dp_rx_ring_record_entry(struct dp_soc *soc, uint8_t ring_num,
  1660. hal_ring_desc_t ring_desc);
  1661. #else
  1662. static inline void
  1663. dp_rx_ring_record_entry(struct dp_soc *soc, uint8_t ring_num,
  1664. hal_ring_desc_t ring_desc)
  1665. {
  1666. }
  1667. #endif
  1668. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  1669. #ifdef RX_DESC_SANITY_WAR
  1670. QDF_STATUS dp_rx_desc_sanity(struct dp_soc *soc, hal_soc_handle_t hal_soc,
  1671. hal_ring_handle_t hal_ring_hdl,
  1672. hal_ring_desc_t ring_desc,
  1673. struct dp_rx_desc *rx_desc);
  1674. #else
  1675. static inline
  1676. QDF_STATUS dp_rx_desc_sanity(struct dp_soc *soc, hal_soc_handle_t hal_soc,
  1677. hal_ring_handle_t hal_ring_hdl,
  1678. hal_ring_desc_t ring_desc,
  1679. struct dp_rx_desc *rx_desc)
  1680. {
  1681. return QDF_STATUS_SUCCESS;
  1682. }
  1683. #endif
  1684. #ifdef DP_RX_DROP_RAW_FRM
  1685. bool dp_rx_is_raw_frame_dropped(qdf_nbuf_t nbuf);
  1686. #else
  1687. static inline
  1688. bool dp_rx_is_raw_frame_dropped(qdf_nbuf_t nbuf)
  1689. {
  1690. return false;
  1691. }
  1692. #endif
  1693. #ifdef RX_DESC_DEBUG_CHECK
  1694. QDF_STATUS dp_rx_desc_nbuf_sanity_check(struct dp_soc *soc,
  1695. hal_ring_desc_t ring_desc,
  1696. struct dp_rx_desc *rx_desc);
  1697. #else
  1698. static inline
  1699. QDF_STATUS dp_rx_desc_nbuf_sanity_check(struct dp_soc *soc,
  1700. hal_ring_desc_t ring_desc,
  1701. struct dp_rx_desc *rx_desc)
  1702. {
  1703. return QDF_STATUS_SUCCESS;
  1704. }
  1705. #endif
  1706. #ifdef WLAN_DP_FEATURE_SW_LATENCY_MGR
  1707. void dp_rx_update_stats(struct dp_soc *soc, qdf_nbuf_t nbuf);
  1708. #else
  1709. static inline
  1710. void dp_rx_update_stats(struct dp_soc *soc, qdf_nbuf_t nbuf)
  1711. {
  1712. }
  1713. #endif
  1714. /**
  1715. * dp_rx_cksum_offload() - set the nbuf checksum as defined by hardware.
  1716. * @nbuf: pointer to the first msdu of an amsdu.
  1717. * @rx_tlv_hdr: pointer to the start of RX TLV headers.
  1718. *
  1719. * The ipsumed field of the skb is set based on whether HW validated the
  1720. * IP/TCP/UDP checksum.
  1721. *
  1722. * Return: void
  1723. */
  1724. static inline
  1725. void dp_rx_cksum_offload(struct dp_pdev *pdev,
  1726. qdf_nbuf_t nbuf,
  1727. uint8_t *rx_tlv_hdr)
  1728. {
  1729. qdf_nbuf_rx_cksum_t cksum = {0};
  1730. //TODO - Move this to ring desc api
  1731. //HAL_RX_MSDU_DESC_IP_CHKSUM_FAIL_GET
  1732. //HAL_RX_MSDU_DESC_TCP_UDP_CHKSUM_FAIL_GET
  1733. uint32_t ip_csum_err, tcp_udp_csum_er;
  1734. hal_rx_tlv_csum_err_get(pdev->soc->hal_soc, rx_tlv_hdr, &ip_csum_err,
  1735. &tcp_udp_csum_er);
  1736. if (qdf_likely(!ip_csum_err && !tcp_udp_csum_er)) {
  1737. cksum.l4_result = QDF_NBUF_RX_CKSUM_TCP_UDP_UNNECESSARY;
  1738. qdf_nbuf_set_rx_cksum(nbuf, &cksum);
  1739. } else {
  1740. DP_STATS_INCC(pdev, err.ip_csum_err, 1, ip_csum_err);
  1741. DP_STATS_INCC(pdev, err.tcp_udp_csum_err, 1, tcp_udp_csum_er);
  1742. }
  1743. }
  1744. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  1745. bool dp_rx_reap_loop_pkt_limit_hit(struct dp_soc *soc, int num_reaped);
  1746. bool dp_rx_enable_eol_data_check(struct dp_soc *soc);
  1747. void dp_rx_update_stats(struct dp_soc *soc, qdf_nbuf_t nbuf);
  1748. #ifdef QCA_SUPPORT_WDS_EXTENDED
  1749. /**
  1750. * dp_rx_is_list_ready() - Make different lists for 4-address
  1751. and 3-address frames
  1752. * @nbuf_head: skb list head
  1753. * @vdev: vdev
  1754. * @peer: peer
  1755. * @peer_id: peer id of new received frame
  1756. * @vdev_id: vdev_id of new received frame
  1757. *
  1758. * Return: true if peer_ids are different.
  1759. */
  1760. static inline bool
  1761. dp_rx_is_list_ready(qdf_nbuf_t nbuf_head,
  1762. struct dp_vdev *vdev,
  1763. struct dp_peer *peer,
  1764. uint16_t peer_id,
  1765. uint8_t vdev_id)
  1766. {
  1767. if (nbuf_head && peer && (peer->peer_id != peer_id))
  1768. return true;
  1769. return false;
  1770. }
  1771. #else
  1772. static inline bool
  1773. dp_rx_is_list_ready(qdf_nbuf_t nbuf_head,
  1774. struct dp_vdev *vdev,
  1775. struct dp_peer *peer,
  1776. uint16_t peer_id,
  1777. uint8_t vdev_id)
  1778. {
  1779. if (nbuf_head && vdev && (vdev->vdev_id != vdev_id))
  1780. return true;
  1781. return false;
  1782. }
  1783. #endif
  1784. #endif /* _DP_RX_H */