dp_rx.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596
  1. /*
  2. * Copyright (c) 2016-2019 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "hal_hw_headers.h"
  19. #include "dp_types.h"
  20. #include "dp_rx.h"
  21. #include "dp_peer.h"
  22. #include "hal_rx.h"
  23. #include "hal_api.h"
  24. #include "qdf_nbuf.h"
  25. #ifdef MESH_MODE_SUPPORT
  26. #include "if_meta_hdr.h"
  27. #endif
  28. #include "dp_internal.h"
  29. #include "dp_rx_mon.h"
  30. #include "dp_ipa.h"
  31. #ifdef FEATURE_WDS
  32. #include "dp_txrx_wds.h"
  33. #endif
  34. #ifdef ATH_RX_PRI_SAVE
  35. #define DP_RX_TID_SAVE(_nbuf, _tid) \
  36. (qdf_nbuf_set_priority(_nbuf, _tid))
  37. #else
  38. #define DP_RX_TID_SAVE(_nbuf, _tid)
  39. #endif
  40. #ifdef DP_RX_DISABLE_NDI_MDNS_FORWARDING
  41. static inline
  42. bool dp_rx_check_ndi_mdns_fwding(struct dp_peer *ta_peer, qdf_nbuf_t nbuf)
  43. {
  44. if (ta_peer->vdev->opmode == wlan_op_mode_ndi &&
  45. qdf_nbuf_is_ipv6_mdns_pkt(nbuf)) {
  46. DP_STATS_INC(ta_peer, rx.intra_bss.mdns_no_fwd, 1);
  47. return false;
  48. }
  49. return true;
  50. }
  51. #else
  52. static inline
  53. bool dp_rx_check_ndi_mdns_fwding(struct dp_peer *ta_peer, qdf_nbuf_t nbuf)
  54. {
  55. return true;
  56. }
  57. #endif
  58. static inline bool dp_rx_check_ap_bridge(struct dp_vdev *vdev)
  59. {
  60. return vdev->ap_bridge_enabled;
  61. }
  62. #ifdef DUP_RX_DESC_WAR
  63. void dp_rx_dump_info_and_assert(struct dp_soc *soc,
  64. hal_ring_handle_t hal_ring,
  65. hal_ring_desc_t ring_desc,
  66. struct dp_rx_desc *rx_desc)
  67. {
  68. void *hal_soc = soc->hal_soc;
  69. hal_srng_dump_ring_desc(hal_soc, hal_ring, ring_desc);
  70. dp_rx_desc_dump(rx_desc);
  71. }
  72. #else
  73. void dp_rx_dump_info_and_assert(struct dp_soc *soc,
  74. hal_ring_handle_t hal_ring_hdl,
  75. hal_ring_desc_t ring_desc,
  76. struct dp_rx_desc *rx_desc)
  77. {
  78. hal_soc_handle_t hal_soc = soc->hal_soc;
  79. dp_rx_desc_dump(rx_desc);
  80. hal_srng_dump_ring_desc(hal_soc, hal_ring_hdl, ring_desc);
  81. hal_srng_dump_ring(hal_soc, hal_ring_hdl);
  82. qdf_assert_always(0);
  83. }
  84. #endif
  85. /*
  86. * dp_rx_buffers_replenish() - replenish rxdma ring with rx nbufs
  87. * called during dp rx initialization
  88. * and at the end of dp_rx_process.
  89. *
  90. * @soc: core txrx main context
  91. * @mac_id: mac_id which is one of 3 mac_ids
  92. * @dp_rxdma_srng: dp rxdma circular ring
  93. * @rx_desc_pool: Pointer to free Rx descriptor pool
  94. * @num_req_buffers: number of buffer to be replenished
  95. * @desc_list: list of descs if called from dp_rx_process
  96. * or NULL during dp rx initialization or out of buffer
  97. * interrupt.
  98. * @tail: tail of descs list
  99. * Return: return success or failure
  100. */
  101. QDF_STATUS dp_rx_buffers_replenish(struct dp_soc *dp_soc, uint32_t mac_id,
  102. struct dp_srng *dp_rxdma_srng,
  103. struct rx_desc_pool *rx_desc_pool,
  104. uint32_t num_req_buffers,
  105. union dp_rx_desc_list_elem_t **desc_list,
  106. union dp_rx_desc_list_elem_t **tail)
  107. {
  108. uint32_t num_alloc_desc;
  109. uint16_t num_desc_to_free = 0;
  110. struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(dp_soc, mac_id);
  111. uint32_t num_entries_avail;
  112. uint32_t count;
  113. int sync_hw_ptr = 1;
  114. qdf_dma_addr_t paddr;
  115. qdf_nbuf_t rx_netbuf;
  116. void *rxdma_ring_entry;
  117. union dp_rx_desc_list_elem_t *next;
  118. QDF_STATUS ret;
  119. void *rxdma_srng;
  120. rxdma_srng = dp_rxdma_srng->hal_srng;
  121. if (!rxdma_srng) {
  122. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  123. "rxdma srng not initialized");
  124. DP_STATS_INC(dp_pdev, replenish.rxdma_err, num_req_buffers);
  125. return QDF_STATUS_E_FAILURE;
  126. }
  127. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  128. "requested %d buffers for replenish", num_req_buffers);
  129. hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
  130. num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
  131. rxdma_srng,
  132. sync_hw_ptr);
  133. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  134. "no of available entries in rxdma ring: %d",
  135. num_entries_avail);
  136. if (!(*desc_list) && (num_entries_avail >
  137. ((dp_rxdma_srng->num_entries * 3) / 4))) {
  138. num_req_buffers = num_entries_avail;
  139. } else if (num_entries_avail < num_req_buffers) {
  140. num_desc_to_free = num_req_buffers - num_entries_avail;
  141. num_req_buffers = num_entries_avail;
  142. }
  143. if (qdf_unlikely(!num_req_buffers)) {
  144. num_desc_to_free = num_req_buffers;
  145. hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
  146. goto free_descs;
  147. }
  148. /*
  149. * if desc_list is NULL, allocate the descs from freelist
  150. */
  151. if (!(*desc_list)) {
  152. num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
  153. rx_desc_pool,
  154. num_req_buffers,
  155. desc_list,
  156. tail);
  157. if (!num_alloc_desc) {
  158. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  159. "no free rx_descs in freelist");
  160. DP_STATS_INC(dp_pdev, err.desc_alloc_fail,
  161. num_req_buffers);
  162. hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
  163. return QDF_STATUS_E_NOMEM;
  164. }
  165. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  166. "%d rx desc allocated", num_alloc_desc);
  167. num_req_buffers = num_alloc_desc;
  168. }
  169. count = 0;
  170. while (count < num_req_buffers) {
  171. rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
  172. RX_BUFFER_SIZE,
  173. RX_BUFFER_RESERVATION,
  174. RX_BUFFER_ALIGNMENT,
  175. FALSE);
  176. if (qdf_unlikely(!rx_netbuf)) {
  177. DP_STATS_INC(dp_pdev, replenish.nbuf_alloc_fail, 1);
  178. break;
  179. }
  180. ret = qdf_nbuf_map_single(dp_soc->osdev, rx_netbuf,
  181. QDF_DMA_FROM_DEVICE);
  182. if (qdf_unlikely(QDF_IS_STATUS_ERROR(ret))) {
  183. qdf_nbuf_free(rx_netbuf);
  184. DP_STATS_INC(dp_pdev, replenish.map_err, 1);
  185. continue;
  186. }
  187. paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
  188. dp_ipa_handle_rx_buf_smmu_mapping(dp_soc, rx_netbuf, true);
  189. /*
  190. * check if the physical address of nbuf->data is
  191. * less then 0x50000000 then free the nbuf and try
  192. * allocating new nbuf. We can try for 100 times.
  193. * this is a temp WAR till we fix it properly.
  194. */
  195. ret = check_x86_paddr(dp_soc, &rx_netbuf, &paddr, dp_pdev);
  196. if (ret == QDF_STATUS_E_FAILURE) {
  197. DP_STATS_INC(dp_pdev, replenish.x86_fail, 1);
  198. break;
  199. }
  200. count++;
  201. rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
  202. rxdma_srng);
  203. qdf_assert_always(rxdma_ring_entry);
  204. next = (*desc_list)->next;
  205. dp_rx_desc_prep(&((*desc_list)->rx_desc), rx_netbuf);
  206. /* rx_desc.in_use should be zero at this time*/
  207. qdf_assert_always((*desc_list)->rx_desc.in_use == 0);
  208. (*desc_list)->rx_desc.in_use = 1;
  209. dp_verbose_debug("rx_netbuf=%pK, buf=%pK, paddr=0x%llx, cookie=%d",
  210. rx_netbuf, qdf_nbuf_data(rx_netbuf),
  211. (unsigned long long)paddr,
  212. (*desc_list)->rx_desc.cookie);
  213. hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
  214. (*desc_list)->rx_desc.cookie,
  215. rx_desc_pool->owner);
  216. *desc_list = next;
  217. }
  218. hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
  219. dp_verbose_debug("replenished buffers %d, rx desc added back to free list %u",
  220. count, num_desc_to_free);
  221. DP_STATS_INC_PKT(dp_pdev, replenish.pkts, count,
  222. (RX_BUFFER_SIZE * count));
  223. free_descs:
  224. DP_STATS_INC(dp_pdev, buf_freelist, num_desc_to_free);
  225. /*
  226. * add any available free desc back to the free list
  227. */
  228. if (*desc_list)
  229. dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
  230. mac_id, rx_desc_pool);
  231. return QDF_STATUS_SUCCESS;
  232. }
  233. /*
  234. * dp_rx_deliver_raw() - process RAW mode pkts and hand over the
  235. * pkts to RAW mode simulation to
  236. * decapsulate the pkt.
  237. *
  238. * @vdev: vdev on which RAW mode is enabled
  239. * @nbuf_list: list of RAW pkts to process
  240. * @peer: peer object from which the pkt is rx
  241. *
  242. * Return: void
  243. */
  244. void
  245. dp_rx_deliver_raw(struct dp_vdev *vdev, qdf_nbuf_t nbuf_list,
  246. struct dp_peer *peer)
  247. {
  248. qdf_nbuf_t deliver_list_head = NULL;
  249. qdf_nbuf_t deliver_list_tail = NULL;
  250. qdf_nbuf_t nbuf;
  251. nbuf = nbuf_list;
  252. while (nbuf) {
  253. qdf_nbuf_t next = qdf_nbuf_next(nbuf);
  254. DP_RX_LIST_APPEND(deliver_list_head, deliver_list_tail, nbuf);
  255. DP_STATS_INC(vdev->pdev, rx_raw_pkts, 1);
  256. DP_STATS_INC_PKT(peer, rx.raw, 1, qdf_nbuf_len(nbuf));
  257. /*
  258. * reset the chfrag_start and chfrag_end bits in nbuf cb
  259. * as this is a non-amsdu pkt and RAW mode simulation expects
  260. * these bit s to be 0 for non-amsdu pkt.
  261. */
  262. if (qdf_nbuf_is_rx_chfrag_start(nbuf) &&
  263. qdf_nbuf_is_rx_chfrag_end(nbuf)) {
  264. qdf_nbuf_set_rx_chfrag_start(nbuf, 0);
  265. qdf_nbuf_set_rx_chfrag_end(nbuf, 0);
  266. }
  267. nbuf = next;
  268. }
  269. vdev->osif_rsim_rx_decap(vdev->osif_vdev, &deliver_list_head,
  270. &deliver_list_tail, (struct cdp_peer*) peer);
  271. vdev->osif_rx(vdev->osif_vdev, deliver_list_head);
  272. }
  273. #ifdef DP_LFR
  274. /*
  275. * In case of LFR, data of a new peer might be sent up
  276. * even before peer is added.
  277. */
  278. static inline struct dp_vdev *
  279. dp_get_vdev_from_peer(struct dp_soc *soc,
  280. uint16_t peer_id,
  281. struct dp_peer *peer,
  282. struct hal_rx_mpdu_desc_info mpdu_desc_info)
  283. {
  284. struct dp_vdev *vdev;
  285. uint8_t vdev_id;
  286. if (unlikely(!peer)) {
  287. if (peer_id != HTT_INVALID_PEER) {
  288. vdev_id = DP_PEER_METADATA_ID_GET(
  289. mpdu_desc_info.peer_meta_data);
  290. QDF_TRACE(QDF_MODULE_ID_DP,
  291. QDF_TRACE_LEVEL_DEBUG,
  292. FL("PeerID %d not found use vdevID %d"),
  293. peer_id, vdev_id);
  294. vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc,
  295. vdev_id);
  296. } else {
  297. QDF_TRACE(QDF_MODULE_ID_DP,
  298. QDF_TRACE_LEVEL_DEBUG,
  299. FL("Invalid PeerID %d"),
  300. peer_id);
  301. return NULL;
  302. }
  303. } else {
  304. vdev = peer->vdev;
  305. }
  306. return vdev;
  307. }
  308. #else
  309. static inline struct dp_vdev *
  310. dp_get_vdev_from_peer(struct dp_soc *soc,
  311. uint16_t peer_id,
  312. struct dp_peer *peer,
  313. struct hal_rx_mpdu_desc_info mpdu_desc_info)
  314. {
  315. if (unlikely(!peer)) {
  316. QDF_TRACE(QDF_MODULE_ID_DP,
  317. QDF_TRACE_LEVEL_DEBUG,
  318. FL("Peer not found for peerID %d"),
  319. peer_id);
  320. return NULL;
  321. } else {
  322. return peer->vdev;
  323. }
  324. }
  325. #endif
  326. #ifndef FEATURE_WDS
  327. static void
  328. dp_rx_da_learn(struct dp_soc *soc,
  329. uint8_t *rx_tlv_hdr,
  330. struct dp_peer *ta_peer,
  331. qdf_nbuf_t nbuf)
  332. {
  333. }
  334. #endif
  335. /*
  336. * dp_rx_intrabss_fwd() - Implements the Intra-BSS forwarding logic
  337. *
  338. * @soc: core txrx main context
  339. * @ta_peer : source peer entry
  340. * @rx_tlv_hdr : start address of rx tlvs
  341. * @nbuf : nbuf that has to be intrabss forwarded
  342. *
  343. * Return: bool: true if it is forwarded else false
  344. */
  345. static bool
  346. dp_rx_intrabss_fwd(struct dp_soc *soc,
  347. struct dp_peer *ta_peer,
  348. uint8_t *rx_tlv_hdr,
  349. qdf_nbuf_t nbuf)
  350. {
  351. uint16_t da_idx;
  352. uint16_t len;
  353. uint8_t is_frag;
  354. struct dp_peer *da_peer;
  355. struct dp_ast_entry *ast_entry;
  356. qdf_nbuf_t nbuf_copy;
  357. uint8_t tid = qdf_nbuf_get_tid_val(nbuf);
  358. uint8_t ring_id = QDF_NBUF_CB_RX_CTX_ID(nbuf);
  359. struct cdp_tid_rx_stats *tid_stats = &ta_peer->vdev->pdev->stats.
  360. tid_stats.tid_rx_stats[ring_id][tid];
  361. /* check if the destination peer is available in peer table
  362. * and also check if the source peer and destination peer
  363. * belong to the same vap and destination peer is not bss peer.
  364. */
  365. if ((qdf_nbuf_is_da_valid(nbuf) && !qdf_nbuf_is_da_mcbc(nbuf))) {
  366. da_idx = hal_rx_msdu_end_da_idx_get(soc->hal_soc, rx_tlv_hdr);
  367. ast_entry = soc->ast_table[da_idx];
  368. if (!ast_entry)
  369. return false;
  370. if (ast_entry->type == CDP_TXRX_AST_TYPE_DA) {
  371. ast_entry->is_active = TRUE;
  372. return false;
  373. }
  374. da_peer = ast_entry->peer;
  375. if (!da_peer)
  376. return false;
  377. /* TA peer cannot be same as peer(DA) on which AST is present
  378. * this indicates a change in topology and that AST entries
  379. * are yet to be updated.
  380. */
  381. if (da_peer == ta_peer)
  382. return false;
  383. if (da_peer->vdev == ta_peer->vdev && !da_peer->bss_peer) {
  384. len = QDF_NBUF_CB_RX_PKT_LEN(nbuf);
  385. is_frag = qdf_nbuf_is_frag(nbuf);
  386. memset(nbuf->cb, 0x0, sizeof(nbuf->cb));
  387. /* linearize the nbuf just before we send to
  388. * dp_tx_send()
  389. */
  390. if (qdf_unlikely(is_frag)) {
  391. if (qdf_nbuf_linearize(nbuf) == -ENOMEM)
  392. return false;
  393. nbuf = qdf_nbuf_unshare(nbuf);
  394. if (!nbuf) {
  395. DP_STATS_INC_PKT(ta_peer,
  396. rx.intra_bss.fail,
  397. 1,
  398. len);
  399. /* return true even though the pkt is
  400. * not forwarded. Basically skb_unshare
  401. * failed and we want to continue with
  402. * next nbuf.
  403. */
  404. tid_stats->fail_cnt[INTRABSS_DROP]++;
  405. return true;
  406. }
  407. }
  408. if (!dp_tx_send(dp_vdev_to_cdp_vdev(ta_peer->vdev),
  409. nbuf)) {
  410. DP_STATS_INC_PKT(ta_peer, rx.intra_bss.pkts, 1,
  411. len);
  412. return true;
  413. } else {
  414. DP_STATS_INC_PKT(ta_peer, rx.intra_bss.fail, 1,
  415. len);
  416. tid_stats->fail_cnt[INTRABSS_DROP]++;
  417. return false;
  418. }
  419. }
  420. }
  421. /* if it is a broadcast pkt (eg: ARP) and it is not its own
  422. * source, then clone the pkt and send the cloned pkt for
  423. * intra BSS forwarding and original pkt up the network stack
  424. * Note: how do we handle multicast pkts. do we forward
  425. * all multicast pkts as is or let a higher layer module
  426. * like igmpsnoop decide whether to forward or not with
  427. * Mcast enhancement.
  428. */
  429. else if (qdf_unlikely((qdf_nbuf_is_da_mcbc(nbuf) &&
  430. !ta_peer->bss_peer))) {
  431. if (!dp_rx_check_ndi_mdns_fwding(ta_peer, nbuf))
  432. goto end;
  433. nbuf_copy = qdf_nbuf_copy(nbuf);
  434. if (!nbuf_copy)
  435. goto end;
  436. len = QDF_NBUF_CB_RX_PKT_LEN(nbuf);
  437. memset(nbuf_copy->cb, 0x0, sizeof(nbuf_copy->cb));
  438. /* Set cb->ftype to intrabss FWD */
  439. qdf_nbuf_set_tx_ftype(nbuf_copy, CB_FTYPE_INTRABSS_FWD);
  440. if (dp_tx_send(dp_vdev_to_cdp_vdev(ta_peer->vdev), nbuf_copy)) {
  441. DP_STATS_INC_PKT(ta_peer, rx.intra_bss.fail, 1, len);
  442. tid_stats->fail_cnt[INTRABSS_DROP]++;
  443. qdf_nbuf_free(nbuf_copy);
  444. } else {
  445. DP_STATS_INC_PKT(ta_peer, rx.intra_bss.pkts, 1, len);
  446. tid_stats->intrabss_cnt++;
  447. }
  448. }
  449. end:
  450. /* return false as we have to still send the original pkt
  451. * up the stack
  452. */
  453. return false;
  454. }
  455. #ifdef MESH_MODE_SUPPORT
  456. /**
  457. * dp_rx_fill_mesh_stats() - Fills the mesh per packet receive stats
  458. *
  459. * @vdev: DP Virtual device handle
  460. * @nbuf: Buffer pointer
  461. * @rx_tlv_hdr: start of rx tlv header
  462. * @peer: pointer to peer
  463. *
  464. * This function allocated memory for mesh receive stats and fill the
  465. * required stats. Stores the memory address in skb cb.
  466. *
  467. * Return: void
  468. */
  469. void dp_rx_fill_mesh_stats(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  470. uint8_t *rx_tlv_hdr, struct dp_peer *peer)
  471. {
  472. struct mesh_recv_hdr_s *rx_info = NULL;
  473. uint32_t pkt_type;
  474. uint32_t nss;
  475. uint32_t rate_mcs;
  476. uint32_t bw;
  477. /* fill recv mesh stats */
  478. rx_info = qdf_mem_malloc(sizeof(struct mesh_recv_hdr_s));
  479. /* upper layers are resposible to free this memory */
  480. if (!rx_info) {
  481. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  482. "Memory allocation failed for mesh rx stats");
  483. DP_STATS_INC(vdev->pdev, mesh_mem_alloc, 1);
  484. return;
  485. }
  486. rx_info->rs_flags = MESH_RXHDR_VER1;
  487. if (qdf_nbuf_is_rx_chfrag_start(nbuf))
  488. rx_info->rs_flags |= MESH_RX_FIRST_MSDU;
  489. if (qdf_nbuf_is_rx_chfrag_end(nbuf))
  490. rx_info->rs_flags |= MESH_RX_LAST_MSDU;
  491. if (hal_rx_attn_msdu_get_is_decrypted(rx_tlv_hdr)) {
  492. rx_info->rs_flags |= MESH_RX_DECRYPTED;
  493. rx_info->rs_keyix = hal_rx_msdu_get_keyid(rx_tlv_hdr);
  494. if (vdev->osif_get_key)
  495. vdev->osif_get_key(vdev->osif_vdev,
  496. &rx_info->rs_decryptkey[0],
  497. &peer->mac_addr.raw[0],
  498. rx_info->rs_keyix);
  499. }
  500. rx_info->rs_rssi = hal_rx_msdu_start_get_rssi(rx_tlv_hdr);
  501. rx_info->rs_channel = hal_rx_msdu_start_get_freq(rx_tlv_hdr);
  502. pkt_type = hal_rx_msdu_start_get_pkt_type(rx_tlv_hdr);
  503. rate_mcs = hal_rx_msdu_start_rate_mcs_get(rx_tlv_hdr);
  504. bw = hal_rx_msdu_start_bw_get(rx_tlv_hdr);
  505. nss = hal_rx_msdu_start_nss_get(vdev->pdev->soc->hal_soc, rx_tlv_hdr);
  506. rx_info->rs_ratephy1 = rate_mcs | (nss << 0x8) | (pkt_type << 16) |
  507. (bw << 24);
  508. qdf_nbuf_set_rx_fctx_type(nbuf, (void *)rx_info, CB_FTYPE_MESH_RX_INFO);
  509. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_MED,
  510. FL("Mesh rx stats: flags %x, rssi %x, chn %x, rate %x, kix %x"),
  511. rx_info->rs_flags,
  512. rx_info->rs_rssi,
  513. rx_info->rs_channel,
  514. rx_info->rs_ratephy1,
  515. rx_info->rs_keyix);
  516. }
  517. /**
  518. * dp_rx_filter_mesh_packets() - Filters mesh unwanted packets
  519. *
  520. * @vdev: DP Virtual device handle
  521. * @nbuf: Buffer pointer
  522. * @rx_tlv_hdr: start of rx tlv header
  523. *
  524. * This checks if the received packet is matching any filter out
  525. * catogery and and drop the packet if it matches.
  526. *
  527. * Return: status(0 indicates drop, 1 indicate to no drop)
  528. */
  529. QDF_STATUS dp_rx_filter_mesh_packets(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  530. uint8_t *rx_tlv_hdr)
  531. {
  532. union dp_align_mac_addr mac_addr;
  533. struct dp_soc *soc = vdev->pdev->soc;
  534. if (qdf_unlikely(vdev->mesh_rx_filter)) {
  535. if (vdev->mesh_rx_filter & MESH_FILTER_OUT_FROMDS)
  536. if (hal_rx_mpdu_get_fr_ds(soc->hal_soc,
  537. rx_tlv_hdr))
  538. return QDF_STATUS_SUCCESS;
  539. if (vdev->mesh_rx_filter & MESH_FILTER_OUT_TODS)
  540. if (hal_rx_mpdu_get_to_ds(soc->hal_soc,
  541. rx_tlv_hdr))
  542. return QDF_STATUS_SUCCESS;
  543. if (vdev->mesh_rx_filter & MESH_FILTER_OUT_NODS)
  544. if (!hal_rx_mpdu_get_fr_ds(soc->hal_soc,
  545. rx_tlv_hdr) &&
  546. !hal_rx_mpdu_get_to_ds(soc->hal_soc,
  547. rx_tlv_hdr))
  548. return QDF_STATUS_SUCCESS;
  549. if (vdev->mesh_rx_filter & MESH_FILTER_OUT_RA) {
  550. if (hal_rx_mpdu_get_addr1(soc->hal_soc,
  551. rx_tlv_hdr,
  552. &mac_addr.raw[0]))
  553. return QDF_STATUS_E_FAILURE;
  554. if (!qdf_mem_cmp(&mac_addr.raw[0],
  555. &vdev->mac_addr.raw[0],
  556. QDF_MAC_ADDR_SIZE))
  557. return QDF_STATUS_SUCCESS;
  558. }
  559. if (vdev->mesh_rx_filter & MESH_FILTER_OUT_TA) {
  560. if (hal_rx_mpdu_get_addr2(soc->hal_soc,
  561. rx_tlv_hdr,
  562. &mac_addr.raw[0]))
  563. return QDF_STATUS_E_FAILURE;
  564. if (!qdf_mem_cmp(&mac_addr.raw[0],
  565. &vdev->mac_addr.raw[0],
  566. QDF_MAC_ADDR_SIZE))
  567. return QDF_STATUS_SUCCESS;
  568. }
  569. }
  570. return QDF_STATUS_E_FAILURE;
  571. }
  572. #else
  573. void dp_rx_fill_mesh_stats(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  574. uint8_t *rx_tlv_hdr, struct dp_peer *peer)
  575. {
  576. }
  577. QDF_STATUS dp_rx_filter_mesh_packets(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  578. uint8_t *rx_tlv_hdr)
  579. {
  580. return QDF_STATUS_E_FAILURE;
  581. }
  582. #endif
  583. #ifdef FEATURE_NAC_RSSI
  584. /**
  585. * dp_rx_nac_filter(): Function to perform filtering of non-associated
  586. * clients
  587. * @pdev: DP pdev handle
  588. * @rx_pkt_hdr: Rx packet Header
  589. *
  590. * return: dp_vdev*
  591. */
  592. static
  593. struct dp_vdev *dp_rx_nac_filter(struct dp_pdev *pdev,
  594. uint8_t *rx_pkt_hdr)
  595. {
  596. struct ieee80211_frame *wh;
  597. struct dp_neighbour_peer *peer = NULL;
  598. wh = (struct ieee80211_frame *)rx_pkt_hdr;
  599. if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) != IEEE80211_FC1_DIR_TODS)
  600. return NULL;
  601. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  602. TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
  603. neighbour_peer_list_elem) {
  604. if (qdf_mem_cmp(&peer->neighbour_peers_macaddr.raw[0],
  605. wh->i_addr2, QDF_MAC_ADDR_SIZE) == 0) {
  606. QDF_TRACE(
  607. QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  608. FL("NAC configuration matched for mac-%2x:%2x:%2x:%2x:%2x:%2x"),
  609. peer->neighbour_peers_macaddr.raw[0],
  610. peer->neighbour_peers_macaddr.raw[1],
  611. peer->neighbour_peers_macaddr.raw[2],
  612. peer->neighbour_peers_macaddr.raw[3],
  613. peer->neighbour_peers_macaddr.raw[4],
  614. peer->neighbour_peers_macaddr.raw[5]);
  615. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  616. return pdev->monitor_vdev;
  617. }
  618. }
  619. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  620. return NULL;
  621. }
  622. /**
  623. * dp_rx_process_invalid_peer(): Function to pass invalid peer list to umac
  624. * @soc: DP SOC handle
  625. * @mpdu: mpdu for which peer is invalid
  626. * @mac_id: mac_id which is one of 3 mac_ids(Assuming mac_id and
  627. * pool_id has same mapping)
  628. *
  629. * return: integer type
  630. */
  631. uint8_t dp_rx_process_invalid_peer(struct dp_soc *soc, qdf_nbuf_t mpdu,
  632. uint8_t mac_id)
  633. {
  634. struct dp_invalid_peer_msg msg;
  635. struct dp_vdev *vdev = NULL;
  636. struct dp_pdev *pdev = NULL;
  637. struct ieee80211_frame *wh;
  638. qdf_nbuf_t curr_nbuf, next_nbuf;
  639. uint8_t *rx_tlv_hdr = qdf_nbuf_data(mpdu);
  640. uint8_t *rx_pkt_hdr = hal_rx_pkt_hdr_get(rx_tlv_hdr);
  641. rx_pkt_hdr = hal_rx_pkt_hdr_get(rx_tlv_hdr);
  642. if (!HAL_IS_DECAP_FORMAT_RAW(soc->hal_soc, rx_tlv_hdr)) {
  643. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  644. "Drop decapped frames");
  645. goto free;
  646. }
  647. wh = (struct ieee80211_frame *)rx_pkt_hdr;
  648. if (!DP_FRAME_IS_DATA(wh)) {
  649. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  650. "NAWDS valid only for data frames");
  651. goto free;
  652. }
  653. if (qdf_nbuf_len(mpdu) < sizeof(struct ieee80211_frame)) {
  654. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  655. "Invalid nbuf length");
  656. goto free;
  657. }
  658. pdev = dp_get_pdev_for_mac_id(soc, mac_id);
  659. if (!pdev || qdf_unlikely(pdev->is_pdev_down)) {
  660. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  661. "PDEV %s", !pdev ? "not found" : "down");
  662. goto free;
  663. }
  664. if (pdev->filter_neighbour_peers) {
  665. /* Next Hop scenario not yet handle */
  666. vdev = dp_rx_nac_filter(pdev, rx_pkt_hdr);
  667. if (vdev) {
  668. dp_rx_mon_deliver(soc, pdev->pdev_id,
  669. pdev->invalid_peer_head_msdu,
  670. pdev->invalid_peer_tail_msdu);
  671. pdev->invalid_peer_head_msdu = NULL;
  672. pdev->invalid_peer_tail_msdu = NULL;
  673. return 0;
  674. }
  675. }
  676. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  677. if (qdf_mem_cmp(wh->i_addr1, vdev->mac_addr.raw,
  678. QDF_MAC_ADDR_SIZE) == 0) {
  679. goto out;
  680. }
  681. }
  682. if (!vdev) {
  683. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  684. "VDEV not found");
  685. goto free;
  686. }
  687. out:
  688. msg.wh = wh;
  689. qdf_nbuf_pull_head(mpdu, RX_PKT_TLVS_LEN);
  690. msg.nbuf = mpdu;
  691. msg.vdev_id = vdev->vdev_id;
  692. if (pdev->soc->cdp_soc.ol_ops->rx_invalid_peer)
  693. pdev->soc->cdp_soc.ol_ops->rx_invalid_peer(pdev->ctrl_pdev,
  694. &msg);
  695. free:
  696. /* Drop and free packet */
  697. curr_nbuf = mpdu;
  698. while (curr_nbuf) {
  699. next_nbuf = qdf_nbuf_next(curr_nbuf);
  700. qdf_nbuf_free(curr_nbuf);
  701. curr_nbuf = next_nbuf;
  702. }
  703. return 0;
  704. }
  705. /**
  706. * dp_rx_process_invalid_peer_wrapper(): Function to wrap invalid peer handler
  707. * @soc: DP SOC handle
  708. * @mpdu: mpdu for which peer is invalid
  709. * @mpdu_done: if an mpdu is completed
  710. * @mac_id: mac_id which is one of 3 mac_ids(Assuming mac_id and
  711. * pool_id has same mapping)
  712. *
  713. * return: integer type
  714. */
  715. void dp_rx_process_invalid_peer_wrapper(struct dp_soc *soc,
  716. qdf_nbuf_t mpdu, bool mpdu_done,
  717. uint8_t mac_id)
  718. {
  719. /* Only trigger the process when mpdu is completed */
  720. if (mpdu_done)
  721. dp_rx_process_invalid_peer(soc, mpdu, mac_id);
  722. }
  723. #else
  724. uint8_t dp_rx_process_invalid_peer(struct dp_soc *soc, qdf_nbuf_t mpdu,
  725. uint8_t mac_id)
  726. {
  727. qdf_nbuf_t curr_nbuf, next_nbuf;
  728. struct dp_pdev *pdev;
  729. struct dp_vdev *vdev = NULL;
  730. struct ieee80211_frame *wh;
  731. uint8_t *rx_tlv_hdr = qdf_nbuf_data(mpdu);
  732. uint8_t *rx_pkt_hdr = hal_rx_pkt_hdr_get(rx_tlv_hdr);
  733. wh = (struct ieee80211_frame *)rx_pkt_hdr;
  734. if (!DP_FRAME_IS_DATA(wh)) {
  735. QDF_TRACE_ERROR_RL(QDF_MODULE_ID_DP,
  736. "only for data frames");
  737. goto free;
  738. }
  739. if (qdf_nbuf_len(mpdu) < sizeof(struct ieee80211_frame)) {
  740. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  741. "Invalid nbuf length");
  742. goto free;
  743. }
  744. pdev = dp_get_pdev_for_mac_id(soc, mac_id);
  745. if (!pdev) {
  746. QDF_TRACE(QDF_MODULE_ID_DP,
  747. QDF_TRACE_LEVEL_ERROR,
  748. "PDEV not found");
  749. goto free;
  750. }
  751. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  752. DP_PDEV_ITERATE_VDEV_LIST(pdev, vdev) {
  753. if (qdf_mem_cmp(wh->i_addr1, vdev->mac_addr.raw,
  754. QDF_MAC_ADDR_SIZE) == 0) {
  755. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  756. goto out;
  757. }
  758. }
  759. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  760. if (!vdev) {
  761. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  762. "VDEV not found");
  763. goto free;
  764. }
  765. out:
  766. if (soc->cdp_soc.ol_ops->rx_invalid_peer)
  767. soc->cdp_soc.ol_ops->rx_invalid_peer(vdev->vdev_id, wh);
  768. free:
  769. /* reset the head and tail pointers */
  770. pdev = dp_get_pdev_for_mac_id(soc, mac_id);
  771. if (pdev) {
  772. pdev->invalid_peer_head_msdu = NULL;
  773. pdev->invalid_peer_tail_msdu = NULL;
  774. }
  775. /* Drop and free packet */
  776. curr_nbuf = mpdu;
  777. while (curr_nbuf) {
  778. next_nbuf = qdf_nbuf_next(curr_nbuf);
  779. qdf_nbuf_free(curr_nbuf);
  780. curr_nbuf = next_nbuf;
  781. }
  782. return 0;
  783. }
  784. void dp_rx_process_invalid_peer_wrapper(struct dp_soc *soc,
  785. qdf_nbuf_t mpdu, bool mpdu_done,
  786. uint8_t mac_id)
  787. {
  788. /* Process the nbuf */
  789. dp_rx_process_invalid_peer(soc, mpdu, mac_id);
  790. }
  791. #endif
  792. #ifdef RECEIVE_OFFLOAD
  793. /**
  794. * dp_rx_print_offload_info() - Print offload info from RX TLV
  795. * @soc: dp soc handle
  796. * @rx_tlv: RX TLV for which offload information is to be printed
  797. *
  798. * Return: None
  799. */
  800. static void dp_rx_print_offload_info(struct dp_soc *soc, uint8_t *rx_tlv)
  801. {
  802. dp_verbose_debug("----------------------RX DESC LRO/GRO----------------------");
  803. dp_verbose_debug("lro_eligible 0x%x", HAL_RX_TLV_GET_LRO_ELIGIBLE(rx_tlv));
  804. dp_verbose_debug("pure_ack 0x%x", HAL_RX_TLV_GET_TCP_PURE_ACK(rx_tlv));
  805. dp_verbose_debug("chksum 0x%x", hal_rx_tlv_get_tcp_chksum(soc->hal_soc,
  806. rx_tlv));
  807. dp_verbose_debug("TCP seq num 0x%x", HAL_RX_TLV_GET_TCP_SEQ(rx_tlv));
  808. dp_verbose_debug("TCP ack num 0x%x", HAL_RX_TLV_GET_TCP_ACK(rx_tlv));
  809. dp_verbose_debug("TCP window 0x%x", HAL_RX_TLV_GET_TCP_WIN(rx_tlv));
  810. dp_verbose_debug("TCP protocol 0x%x", HAL_RX_TLV_GET_TCP_PROTO(rx_tlv));
  811. dp_verbose_debug("TCP offset 0x%x", HAL_RX_TLV_GET_TCP_OFFSET(rx_tlv));
  812. dp_verbose_debug("toeplitz 0x%x", HAL_RX_TLV_GET_FLOW_ID_TOEPLITZ(rx_tlv));
  813. dp_verbose_debug("---------------------------------------------------------");
  814. }
  815. /**
  816. * dp_rx_fill_gro_info() - Fill GRO info from RX TLV into skb->cb
  817. * @soc: DP SOC handle
  818. * @rx_tlv: RX TLV received for the msdu
  819. * @msdu: msdu for which GRO info needs to be filled
  820. * @rx_ol_pkt_cnt: counter to be incremented for GRO eligible packets
  821. *
  822. * Return: None
  823. */
  824. static
  825. void dp_rx_fill_gro_info(struct dp_soc *soc, uint8_t *rx_tlv,
  826. qdf_nbuf_t msdu, uint32_t *rx_ol_pkt_cnt)
  827. {
  828. if (!wlan_cfg_is_gro_enabled(soc->wlan_cfg_ctx))
  829. return;
  830. /* Filling up RX offload info only for TCP packets */
  831. if (!HAL_RX_TLV_GET_TCP_PROTO(rx_tlv))
  832. return;
  833. *rx_ol_pkt_cnt = *rx_ol_pkt_cnt + 1;
  834. QDF_NBUF_CB_RX_LRO_ELIGIBLE(msdu) =
  835. HAL_RX_TLV_GET_LRO_ELIGIBLE(rx_tlv);
  836. QDF_NBUF_CB_RX_TCP_PURE_ACK(msdu) =
  837. HAL_RX_TLV_GET_TCP_PURE_ACK(rx_tlv);
  838. QDF_NBUF_CB_RX_TCP_CHKSUM(msdu) =
  839. hal_rx_tlv_get_tcp_chksum(soc->hal_soc,
  840. rx_tlv);
  841. QDF_NBUF_CB_RX_TCP_SEQ_NUM(msdu) =
  842. HAL_RX_TLV_GET_TCP_SEQ(rx_tlv);
  843. QDF_NBUF_CB_RX_TCP_ACK_NUM(msdu) =
  844. HAL_RX_TLV_GET_TCP_ACK(rx_tlv);
  845. QDF_NBUF_CB_RX_TCP_WIN(msdu) =
  846. HAL_RX_TLV_GET_TCP_WIN(rx_tlv);
  847. QDF_NBUF_CB_RX_TCP_PROTO(msdu) =
  848. HAL_RX_TLV_GET_TCP_PROTO(rx_tlv);
  849. QDF_NBUF_CB_RX_IPV6_PROTO(msdu) =
  850. HAL_RX_TLV_GET_IPV6(rx_tlv);
  851. QDF_NBUF_CB_RX_TCP_OFFSET(msdu) =
  852. HAL_RX_TLV_GET_TCP_OFFSET(rx_tlv);
  853. QDF_NBUF_CB_RX_FLOW_ID(msdu) =
  854. HAL_RX_TLV_GET_FLOW_ID_TOEPLITZ(rx_tlv);
  855. dp_rx_print_offload_info(soc, rx_tlv);
  856. }
  857. #else
  858. static void dp_rx_fill_gro_info(struct dp_soc *soc, uint8_t *rx_tlv,
  859. qdf_nbuf_t msdu, uint32_t *rx_ol_pkt_cnt)
  860. {
  861. }
  862. #endif /* RECEIVE_OFFLOAD */
  863. /**
  864. * dp_rx_adjust_nbuf_len() - set appropriate msdu length in nbuf.
  865. *
  866. * @nbuf: pointer to msdu.
  867. * @mpdu_len: mpdu length
  868. *
  869. * Return: returns true if nbuf is last msdu of mpdu else retuns false.
  870. */
  871. static inline bool dp_rx_adjust_nbuf_len(qdf_nbuf_t nbuf, uint16_t *mpdu_len)
  872. {
  873. bool last_nbuf;
  874. if (*mpdu_len > (RX_BUFFER_SIZE - RX_PKT_TLVS_LEN)) {
  875. qdf_nbuf_set_pktlen(nbuf, RX_BUFFER_SIZE);
  876. last_nbuf = false;
  877. } else {
  878. qdf_nbuf_set_pktlen(nbuf, (*mpdu_len + RX_PKT_TLVS_LEN));
  879. last_nbuf = true;
  880. }
  881. *mpdu_len -= (RX_BUFFER_SIZE - RX_PKT_TLVS_LEN);
  882. return last_nbuf;
  883. }
  884. /**
  885. * dp_rx_sg_create() - create a frag_list for MSDUs which are spread across
  886. * multiple nbufs.
  887. * @nbuf: pointer to the first msdu of an amsdu.
  888. * @rx_tlv_hdr: pointer to the start of RX TLV headers.
  889. *
  890. *
  891. * This function implements the creation of RX frag_list for cases
  892. * where an MSDU is spread across multiple nbufs.
  893. *
  894. * Return: returns the head nbuf which contains complete frag_list.
  895. */
  896. qdf_nbuf_t dp_rx_sg_create(qdf_nbuf_t nbuf, uint8_t *rx_tlv_hdr)
  897. {
  898. qdf_nbuf_t parent, next, frag_list;
  899. uint16_t frag_list_len = 0;
  900. uint16_t mpdu_len;
  901. bool last_nbuf;
  902. mpdu_len = hal_rx_msdu_start_msdu_len_get(rx_tlv_hdr);
  903. /*
  904. * this is a case where the complete msdu fits in one single nbuf.
  905. * in this case HW sets both start and end bit and we only need to
  906. * reset these bits for RAW mode simulator to decap the pkt
  907. */
  908. if (qdf_nbuf_is_rx_chfrag_start(nbuf) &&
  909. qdf_nbuf_is_rx_chfrag_end(nbuf)) {
  910. qdf_nbuf_set_pktlen(nbuf, mpdu_len + RX_PKT_TLVS_LEN);
  911. qdf_nbuf_pull_head(nbuf, RX_PKT_TLVS_LEN);
  912. return nbuf;
  913. }
  914. /*
  915. * This is a case where we have multiple msdus (A-MSDU) spread across
  916. * multiple nbufs. here we create a fraglist out of these nbufs.
  917. *
  918. * the moment we encounter a nbuf with continuation bit set we
  919. * know for sure we have an MSDU which is spread across multiple
  920. * nbufs. We loop through and reap nbufs till we reach last nbuf.
  921. */
  922. parent = nbuf;
  923. frag_list = nbuf->next;
  924. nbuf = nbuf->next;
  925. /*
  926. * set the start bit in the first nbuf we encounter with continuation
  927. * bit set. This has the proper mpdu length set as it is the first
  928. * msdu of the mpdu. this becomes the parent nbuf and the subsequent
  929. * nbufs will form the frag_list of the parent nbuf.
  930. */
  931. qdf_nbuf_set_rx_chfrag_start(parent, 1);
  932. last_nbuf = dp_rx_adjust_nbuf_len(parent, &mpdu_len);
  933. /*
  934. * this is where we set the length of the fragments which are
  935. * associated to the parent nbuf. We iterate through the frag_list
  936. * till we hit the last_nbuf of the list.
  937. */
  938. do {
  939. last_nbuf = dp_rx_adjust_nbuf_len(nbuf, &mpdu_len);
  940. qdf_nbuf_pull_head(nbuf, RX_PKT_TLVS_LEN);
  941. frag_list_len += qdf_nbuf_len(nbuf);
  942. if (last_nbuf) {
  943. next = nbuf->next;
  944. nbuf->next = NULL;
  945. break;
  946. }
  947. nbuf = nbuf->next;
  948. } while (!last_nbuf);
  949. qdf_nbuf_set_rx_chfrag_start(nbuf, 0);
  950. qdf_nbuf_append_ext_list(parent, frag_list, frag_list_len);
  951. parent->next = next;
  952. qdf_nbuf_pull_head(parent, RX_PKT_TLVS_LEN);
  953. return parent;
  954. }
  955. /**
  956. * dp_rx_compute_delay() - Compute and fill in all timestamps
  957. * to pass in correct fields
  958. *
  959. * @vdev: pdev handle
  960. * @tx_desc: tx descriptor
  961. * @tid: tid value
  962. * Return: none
  963. */
  964. void dp_rx_compute_delay(struct dp_vdev *vdev, qdf_nbuf_t nbuf)
  965. {
  966. uint8_t ring_id = QDF_NBUF_CB_RX_CTX_ID(nbuf);
  967. int64_t current_ts = qdf_ktime_to_ms(qdf_ktime_get());
  968. uint32_t to_stack = qdf_nbuf_get_timedelta_ms(nbuf);
  969. uint8_t tid = qdf_nbuf_get_tid_val(nbuf);
  970. uint32_t interframe_delay =
  971. (uint32_t)(current_ts - vdev->prev_rx_deliver_tstamp);
  972. dp_update_delay_stats(vdev->pdev, to_stack, tid,
  973. CDP_DELAY_STATS_REAP_STACK, ring_id);
  974. /*
  975. * Update interframe delay stats calculated at deliver_data_ol point.
  976. * Value of vdev->prev_rx_deliver_tstamp will be 0 for 1st frame, so
  977. * interframe delay will not be calculate correctly for 1st frame.
  978. * On the other side, this will help in avoiding extra per packet check
  979. * of vdev->prev_rx_deliver_tstamp.
  980. */
  981. dp_update_delay_stats(vdev->pdev, interframe_delay, tid,
  982. CDP_DELAY_STATS_RX_INTERFRAME, ring_id);
  983. vdev->prev_rx_deliver_tstamp = current_ts;
  984. }
  985. /**
  986. * dp_rx_drop_nbuf_list() - drop an nbuf list
  987. * @pdev: dp pdev reference
  988. * @buf_list: buffer list to be dropepd
  989. *
  990. * Return: int (number of bufs dropped)
  991. */
  992. static inline int dp_rx_drop_nbuf_list(struct dp_pdev *pdev,
  993. qdf_nbuf_t buf_list)
  994. {
  995. struct cdp_tid_rx_stats *stats = NULL;
  996. uint8_t tid = 0, ring_id = 0;
  997. int num_dropped = 0;
  998. qdf_nbuf_t buf, next_buf;
  999. buf = buf_list;
  1000. while (buf) {
  1001. ring_id = QDF_NBUF_CB_RX_CTX_ID(buf);
  1002. next_buf = qdf_nbuf_queue_next(buf);
  1003. tid = qdf_nbuf_get_tid_val(buf);
  1004. stats = &pdev->stats.tid_stats.tid_rx_stats[ring_id][tid];
  1005. stats->fail_cnt[INVALID_PEER_VDEV]++;
  1006. stats->delivered_to_stack--;
  1007. qdf_nbuf_free(buf);
  1008. buf = next_buf;
  1009. num_dropped++;
  1010. }
  1011. return num_dropped;
  1012. }
  1013. #ifdef PEER_CACHE_RX_PKTS
  1014. /**
  1015. * dp_rx_flush_rx_cached() - flush cached rx frames
  1016. * @peer: peer
  1017. * @drop: flag to drop frames or forward to net stack
  1018. *
  1019. * Return: None
  1020. */
  1021. void dp_rx_flush_rx_cached(struct dp_peer *peer, bool drop)
  1022. {
  1023. struct dp_peer_cached_bufq *bufqi;
  1024. struct dp_rx_cached_buf *cache_buf = NULL;
  1025. ol_txrx_rx_fp data_rx = NULL;
  1026. int num_buff_elem;
  1027. QDF_STATUS status;
  1028. if (qdf_atomic_inc_return(&peer->flush_in_progress) > 1) {
  1029. qdf_atomic_dec(&peer->flush_in_progress);
  1030. return;
  1031. }
  1032. qdf_spin_lock_bh(&peer->peer_info_lock);
  1033. if (peer->state >= OL_TXRX_PEER_STATE_CONN && peer->vdev->osif_rx)
  1034. data_rx = peer->vdev->osif_rx;
  1035. else
  1036. drop = true;
  1037. qdf_spin_unlock_bh(&peer->peer_info_lock);
  1038. bufqi = &peer->bufq_info;
  1039. qdf_spin_lock_bh(&bufqi->bufq_lock);
  1040. qdf_list_remove_front(&bufqi->cached_bufq,
  1041. (qdf_list_node_t **)&cache_buf);
  1042. while (cache_buf) {
  1043. num_buff_elem = QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(
  1044. cache_buf->buf);
  1045. bufqi->entries -= num_buff_elem;
  1046. qdf_spin_unlock_bh(&bufqi->bufq_lock);
  1047. if (drop) {
  1048. bufqi->dropped = dp_rx_drop_nbuf_list(peer->vdev->pdev,
  1049. cache_buf->buf);
  1050. } else {
  1051. /* Flush the cached frames to OSIF DEV */
  1052. status = data_rx(peer->vdev->osif_vdev, cache_buf->buf);
  1053. if (status != QDF_STATUS_SUCCESS)
  1054. bufqi->dropped = dp_rx_drop_nbuf_list(
  1055. peer->vdev->pdev,
  1056. cache_buf->buf);
  1057. }
  1058. qdf_mem_free(cache_buf);
  1059. cache_buf = NULL;
  1060. qdf_spin_lock_bh(&bufqi->bufq_lock);
  1061. qdf_list_remove_front(&bufqi->cached_bufq,
  1062. (qdf_list_node_t **)&cache_buf);
  1063. }
  1064. qdf_spin_unlock_bh(&bufqi->bufq_lock);
  1065. qdf_atomic_dec(&peer->flush_in_progress);
  1066. }
  1067. /**
  1068. * dp_rx_enqueue_rx() - cache rx frames
  1069. * @peer: peer
  1070. * @rx_buf_list: cache buffer list
  1071. *
  1072. * Return: None
  1073. */
  1074. static QDF_STATUS
  1075. dp_rx_enqueue_rx(struct dp_peer *peer, qdf_nbuf_t rx_buf_list)
  1076. {
  1077. struct dp_rx_cached_buf *cache_buf;
  1078. struct dp_peer_cached_bufq *bufqi = &peer->bufq_info;
  1079. int num_buff_elem;
  1080. QDF_TRACE_DEBUG_RL(QDF_MODULE_ID_TXRX, "bufq->curr %d bufq->drops %d",
  1081. bufqi->entries, bufqi->dropped);
  1082. if (!peer->valid) {
  1083. bufqi->dropped = dp_rx_drop_nbuf_list(peer->vdev->pdev,
  1084. rx_buf_list);
  1085. return QDF_STATUS_E_INVAL;
  1086. }
  1087. qdf_spin_lock_bh(&bufqi->bufq_lock);
  1088. if (bufqi->entries >= bufqi->thresh) {
  1089. bufqi->dropped = dp_rx_drop_nbuf_list(peer->vdev->pdev,
  1090. rx_buf_list);
  1091. qdf_spin_unlock_bh(&bufqi->bufq_lock);
  1092. return QDF_STATUS_E_RESOURCES;
  1093. }
  1094. qdf_spin_unlock_bh(&bufqi->bufq_lock);
  1095. num_buff_elem = QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(rx_buf_list);
  1096. cache_buf = qdf_mem_malloc_atomic(sizeof(*cache_buf));
  1097. if (!cache_buf) {
  1098. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1099. "Failed to allocate buf to cache rx frames");
  1100. bufqi->dropped = dp_rx_drop_nbuf_list(peer->vdev->pdev,
  1101. rx_buf_list);
  1102. return QDF_STATUS_E_NOMEM;
  1103. }
  1104. cache_buf->buf = rx_buf_list;
  1105. qdf_spin_lock_bh(&bufqi->bufq_lock);
  1106. qdf_list_insert_back(&bufqi->cached_bufq,
  1107. &cache_buf->node);
  1108. bufqi->entries += num_buff_elem;
  1109. qdf_spin_unlock_bh(&bufqi->bufq_lock);
  1110. return QDF_STATUS_SUCCESS;
  1111. }
  1112. static inline
  1113. bool dp_rx_is_peer_cache_bufq_supported(void)
  1114. {
  1115. return true;
  1116. }
  1117. #else
  1118. static inline
  1119. bool dp_rx_is_peer_cache_bufq_supported(void)
  1120. {
  1121. return false;
  1122. }
  1123. static inline QDF_STATUS
  1124. dp_rx_enqueue_rx(struct dp_peer *peer, qdf_nbuf_t rx_buf_list)
  1125. {
  1126. return QDF_STATUS_SUCCESS;
  1127. }
  1128. #endif
  1129. static inline void dp_rx_deliver_to_stack(struct dp_vdev *vdev,
  1130. struct dp_peer *peer,
  1131. qdf_nbuf_t nbuf_head,
  1132. qdf_nbuf_t nbuf_tail)
  1133. {
  1134. /*
  1135. * highly unlikely to have a vdev without a registered rx
  1136. * callback function. if so let us free the nbuf_list.
  1137. */
  1138. if (qdf_unlikely(!vdev->osif_rx)) {
  1139. if (dp_rx_is_peer_cache_bufq_supported())
  1140. dp_rx_enqueue_rx(peer, nbuf_head);
  1141. else
  1142. dp_rx_drop_nbuf_list(vdev->pdev, nbuf_head);
  1143. return;
  1144. }
  1145. if (qdf_unlikely(vdev->rx_decap_type == htt_cmn_pkt_type_raw) ||
  1146. (vdev->rx_decap_type == htt_cmn_pkt_type_native_wifi)) {
  1147. vdev->osif_rsim_rx_decap(vdev->osif_vdev, &nbuf_head,
  1148. &nbuf_tail, (struct cdp_peer *) peer);
  1149. }
  1150. vdev->osif_rx(vdev->osif_vdev, nbuf_head);
  1151. }
  1152. /**
  1153. * dp_rx_cksum_offload() - set the nbuf checksum as defined by hardware.
  1154. * @nbuf: pointer to the first msdu of an amsdu.
  1155. * @rx_tlv_hdr: pointer to the start of RX TLV headers.
  1156. *
  1157. * The ipsumed field of the skb is set based on whether HW validated the
  1158. * IP/TCP/UDP checksum.
  1159. *
  1160. * Return: void
  1161. */
  1162. static inline void dp_rx_cksum_offload(struct dp_pdev *pdev,
  1163. qdf_nbuf_t nbuf,
  1164. uint8_t *rx_tlv_hdr)
  1165. {
  1166. qdf_nbuf_rx_cksum_t cksum = {0};
  1167. bool ip_csum_err = hal_rx_attn_ip_cksum_fail_get(rx_tlv_hdr);
  1168. bool tcp_udp_csum_er = hal_rx_attn_tcp_udp_cksum_fail_get(rx_tlv_hdr);
  1169. if (qdf_likely(!ip_csum_err && !tcp_udp_csum_er)) {
  1170. cksum.l4_result = QDF_NBUF_RX_CKSUM_TCP_UDP_UNNECESSARY;
  1171. qdf_nbuf_set_rx_cksum(nbuf, &cksum);
  1172. } else {
  1173. DP_STATS_INCC(pdev, err.ip_csum_err, 1, ip_csum_err);
  1174. DP_STATS_INCC(pdev, err.tcp_udp_csum_err, 1, tcp_udp_csum_er);
  1175. }
  1176. }
  1177. /**
  1178. * dp_rx_msdu_stats_update() - update per msdu stats.
  1179. * @soc: core txrx main context
  1180. * @nbuf: pointer to the first msdu of an amsdu.
  1181. * @rx_tlv_hdr: pointer to the start of RX TLV headers.
  1182. * @peer: pointer to the peer object.
  1183. * @ring_id: reo dest ring number on which pkt is reaped.
  1184. * @tid_stats: per tid rx stats.
  1185. *
  1186. * update all the per msdu stats for that nbuf.
  1187. * Return: void
  1188. */
  1189. static void dp_rx_msdu_stats_update(struct dp_soc *soc,
  1190. qdf_nbuf_t nbuf,
  1191. uint8_t *rx_tlv_hdr,
  1192. struct dp_peer *peer,
  1193. uint8_t ring_id,
  1194. struct cdp_tid_rx_stats *tid_stats)
  1195. {
  1196. bool is_ampdu, is_not_amsdu;
  1197. uint32_t sgi, mcs, tid, nss, bw, reception_type, pkt_type;
  1198. struct dp_vdev *vdev = peer->vdev;
  1199. qdf_ether_header_t *eh;
  1200. uint16_t msdu_len = QDF_NBUF_CB_RX_PKT_LEN(nbuf);
  1201. is_not_amsdu = qdf_nbuf_is_rx_chfrag_start(nbuf) &
  1202. qdf_nbuf_is_rx_chfrag_end(nbuf);
  1203. DP_STATS_INC_PKT(peer, rx.rcvd_reo[ring_id], 1, msdu_len);
  1204. DP_STATS_INCC(peer, rx.non_amsdu_cnt, 1, is_not_amsdu);
  1205. DP_STATS_INCC(peer, rx.amsdu_cnt, 1, !is_not_amsdu);
  1206. DP_STATS_INCC(peer, rx.rx_retries, 1, qdf_nbuf_is_rx_retry_flag(nbuf));
  1207. tid_stats->msdu_cnt++;
  1208. if (qdf_unlikely(qdf_nbuf_is_da_mcbc(nbuf) &&
  1209. (vdev->rx_decap_type == htt_cmn_pkt_type_ethernet))) {
  1210. eh = (qdf_ether_header_t *)qdf_nbuf_data(nbuf);
  1211. DP_STATS_INC_PKT(peer, rx.multicast, 1, msdu_len);
  1212. tid_stats->mcast_msdu_cnt++;
  1213. if (QDF_IS_ADDR_BROADCAST(eh->ether_dhost)) {
  1214. DP_STATS_INC_PKT(peer, rx.bcast, 1, msdu_len);
  1215. tid_stats->bcast_msdu_cnt++;
  1216. }
  1217. }
  1218. /*
  1219. * currently we can return from here as we have similar stats
  1220. * updated at per ppdu level instead of msdu level
  1221. */
  1222. if (!soc->process_rx_status)
  1223. return;
  1224. is_ampdu = hal_rx_mpdu_info_ampdu_flag_get(rx_tlv_hdr);
  1225. DP_STATS_INCC(peer, rx.ampdu_cnt, 1, is_ampdu);
  1226. DP_STATS_INCC(peer, rx.non_ampdu_cnt, 1, !(is_ampdu));
  1227. sgi = hal_rx_msdu_start_sgi_get(rx_tlv_hdr);
  1228. mcs = hal_rx_msdu_start_rate_mcs_get(rx_tlv_hdr);
  1229. tid = qdf_nbuf_get_tid_val(nbuf);
  1230. bw = hal_rx_msdu_start_bw_get(rx_tlv_hdr);
  1231. reception_type = hal_rx_msdu_start_reception_type_get(soc->hal_soc,
  1232. rx_tlv_hdr);
  1233. nss = hal_rx_msdu_start_nss_get(soc->hal_soc, rx_tlv_hdr);
  1234. pkt_type = hal_rx_msdu_start_get_pkt_type(rx_tlv_hdr);
  1235. DP_STATS_INC(peer, rx.bw[bw], 1);
  1236. /*
  1237. * only if nss > 0 and pkt_type is 11N/AC/AX,
  1238. * then increase index [nss - 1] in array counter.
  1239. */
  1240. if (nss > 0 && (pkt_type == DOT11_N ||
  1241. pkt_type == DOT11_AC ||
  1242. pkt_type == DOT11_AX))
  1243. DP_STATS_INC(peer, rx.nss[nss - 1], 1);
  1244. DP_STATS_INC(peer, rx.sgi_count[sgi], 1);
  1245. DP_STATS_INCC(peer, rx.err.mic_err, 1,
  1246. hal_rx_mpdu_end_mic_err_get(rx_tlv_hdr));
  1247. DP_STATS_INCC(peer, rx.err.decrypt_err, 1,
  1248. hal_rx_mpdu_end_decrypt_err_get(rx_tlv_hdr));
  1249. DP_STATS_INC(peer, rx.wme_ac_type[TID_TO_WME_AC(tid)], 1);
  1250. DP_STATS_INC(peer, rx.reception_type[reception_type], 1);
  1251. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  1252. ((mcs >= MAX_MCS_11A) && (pkt_type == DOT11_A)));
  1253. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[mcs], 1,
  1254. ((mcs <= MAX_MCS_11A) && (pkt_type == DOT11_A)));
  1255. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  1256. ((mcs >= MAX_MCS_11B) && (pkt_type == DOT11_B)));
  1257. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[mcs], 1,
  1258. ((mcs <= MAX_MCS_11B) && (pkt_type == DOT11_B)));
  1259. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  1260. ((mcs >= MAX_MCS_11A) && (pkt_type == DOT11_N)));
  1261. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[mcs], 1,
  1262. ((mcs <= MAX_MCS_11A) && (pkt_type == DOT11_N)));
  1263. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  1264. ((mcs >= MAX_MCS_11AC) && (pkt_type == DOT11_AC)));
  1265. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[mcs], 1,
  1266. ((mcs <= MAX_MCS_11AC) && (pkt_type == DOT11_AC)));
  1267. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  1268. ((mcs >= MAX_MCS) && (pkt_type == DOT11_AX)));
  1269. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[mcs], 1,
  1270. ((mcs < MAX_MCS) && (pkt_type == DOT11_AX)));
  1271. if ((soc->process_rx_status) &&
  1272. hal_rx_attn_first_mpdu_get(rx_tlv_hdr)) {
  1273. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  1274. if (!vdev->pdev)
  1275. return;
  1276. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, vdev->pdev->soc,
  1277. &peer->stats, peer->peer_ids[0],
  1278. UPDATE_PEER_STATS,
  1279. vdev->pdev->pdev_id);
  1280. #endif
  1281. }
  1282. }
  1283. static inline bool is_sa_da_idx_valid(struct dp_soc *soc,
  1284. uint8_t *rx_tlv_hdr,
  1285. qdf_nbuf_t nbuf)
  1286. {
  1287. if ((qdf_nbuf_is_sa_valid(nbuf) &&
  1288. (hal_rx_msdu_end_sa_idx_get(soc->hal_soc, rx_tlv_hdr) >
  1289. wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx))) ||
  1290. (!qdf_nbuf_is_da_mcbc(nbuf) &&
  1291. qdf_nbuf_is_da_valid(nbuf) &&
  1292. (hal_rx_msdu_end_da_idx_get(soc->hal_soc, rx_tlv_hdr) >
  1293. wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx))))
  1294. return false;
  1295. return true;
  1296. }
  1297. #ifndef WDS_VENDOR_EXTENSION
  1298. int dp_wds_rx_policy_check(uint8_t *rx_tlv_hdr,
  1299. struct dp_vdev *vdev,
  1300. struct dp_peer *peer)
  1301. {
  1302. return 1;
  1303. }
  1304. #endif
  1305. #ifdef RX_DESC_DEBUG_CHECK
  1306. /**
  1307. * dp_rx_desc_nbuf_sanity_check - Add sanity check to catch REO rx_desc paddr
  1308. * corruption
  1309. *
  1310. * @ring_desc: REO ring descriptor
  1311. * @rx_desc: Rx descriptor
  1312. *
  1313. * Return: NONE
  1314. */
  1315. static inline
  1316. void dp_rx_desc_nbuf_sanity_check(hal_ring_desc_t ring_desc,
  1317. struct dp_rx_desc *rx_desc)
  1318. {
  1319. struct hal_buf_info hbi;
  1320. hal_rx_reo_buf_paddr_get(ring_desc, &hbi);
  1321. /* Sanity check for possible buffer paddr corruption */
  1322. qdf_assert_always((&hbi)->paddr ==
  1323. qdf_nbuf_get_frag_paddr(rx_desc->nbuf, 0));
  1324. }
  1325. #else
  1326. static inline
  1327. void dp_rx_desc_nbuf_sanity_check(hal_ring_desc_t ring_desc,
  1328. struct dp_rx_desc *rx_desc)
  1329. {
  1330. }
  1331. #endif
  1332. #ifdef WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT
  1333. static inline
  1334. bool dp_rx_reap_loop_pkt_limit_hit(struct dp_soc *soc, int num_reaped)
  1335. {
  1336. bool limit_hit = false;
  1337. struct wlan_cfg_dp_soc_ctxt *cfg = soc->wlan_cfg_ctx;
  1338. limit_hit =
  1339. (num_reaped >= cfg->rx_reap_loop_pkt_limit) ? true : false;
  1340. if (limit_hit)
  1341. DP_STATS_INC(soc, rx.reap_loop_pkt_limit_hit, 1)
  1342. return limit_hit;
  1343. }
  1344. static inline bool dp_rx_enable_eol_data_check(struct dp_soc *soc)
  1345. {
  1346. return soc->wlan_cfg_ctx->rx_enable_eol_data_check;
  1347. }
  1348. #else
  1349. static inline
  1350. bool dp_rx_reap_loop_pkt_limit_hit(struct dp_soc *soc, int num_reaped)
  1351. {
  1352. return false;
  1353. }
  1354. static inline bool dp_rx_enable_eol_data_check(struct dp_soc *soc)
  1355. {
  1356. return false;
  1357. }
  1358. #endif /* WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT */
  1359. /**
  1360. * dp_is_special_data() - check is the pkt special like eapol, dhcp, etc
  1361. *
  1362. * @nbuf: pkt skb pointer
  1363. *
  1364. * Return: true if matched, false if not
  1365. */
  1366. static inline
  1367. bool dp_is_special_data(qdf_nbuf_t nbuf)
  1368. {
  1369. if (qdf_nbuf_is_ipv4_arp_pkt(nbuf) ||
  1370. qdf_nbuf_is_ipv4_dhcp_pkt(nbuf) ||
  1371. qdf_nbuf_is_ipv4_eapol_pkt(nbuf) ||
  1372. qdf_nbuf_is_ipv6_dhcp_pkt(nbuf))
  1373. return true;
  1374. else
  1375. return false;
  1376. }
  1377. #ifdef DP_RX_PKT_NO_PEER_DELIVER
  1378. /**
  1379. * dp_rx_deliver_to_stack_no_peer() - try deliver rx data even if
  1380. * no corresbonding peer found
  1381. * @soc: core txrx main context
  1382. * @nbuf: pkt skb pointer
  1383. *
  1384. * This function will try to deliver some RX special frames to stack
  1385. * even there is no peer matched found. for instance, LFR case, some
  1386. * eapol data will be sent to host before peer_map done.
  1387. *
  1388. * Return: None
  1389. */
  1390. static inline
  1391. void dp_rx_deliver_to_stack_no_peer(struct dp_soc *soc, qdf_nbuf_t nbuf)
  1392. {
  1393. uint32_t peer_mdata;
  1394. uint16_t peer_id;
  1395. uint8_t vdev_id;
  1396. struct dp_vdev *vdev;
  1397. uint32_t l2_hdr_offset = 0;
  1398. uint16_t msdu_len = 0;
  1399. uint32_t pkt_len = 0;
  1400. uint8_t *rx_tlv_hdr;
  1401. peer_mdata = QDF_NBUF_CB_RX_PEER_ID(nbuf);
  1402. peer_id = DP_PEER_METADATA_PEER_ID_GET(peer_mdata);
  1403. if (peer_id > soc->max_peers)
  1404. goto deliver_fail;
  1405. vdev_id = DP_PEER_METADATA_ID_GET(peer_mdata);
  1406. vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  1407. if (!vdev || !vdev->osif_rx)
  1408. goto deliver_fail;
  1409. rx_tlv_hdr = qdf_nbuf_data(nbuf);
  1410. l2_hdr_offset =
  1411. hal_rx_msdu_end_l3_hdr_padding_get(soc->hal_soc, rx_tlv_hdr);
  1412. msdu_len = QDF_NBUF_CB_RX_PKT_LEN(nbuf);
  1413. pkt_len = msdu_len + l2_hdr_offset + RX_PKT_TLVS_LEN;
  1414. if (qdf_unlikely(qdf_nbuf_is_frag(nbuf))) {
  1415. qdf_nbuf_pull_head(nbuf, RX_PKT_TLVS_LEN);
  1416. } else {
  1417. qdf_nbuf_set_pktlen(nbuf, pkt_len);
  1418. qdf_nbuf_pull_head(nbuf,
  1419. RX_PKT_TLVS_LEN +
  1420. l2_hdr_offset);
  1421. }
  1422. /* only allow special frames */
  1423. if (!dp_is_special_data(nbuf))
  1424. goto deliver_fail;
  1425. vdev->osif_rx(vdev->osif_vdev, nbuf);
  1426. DP_STATS_INC(soc, rx.err.pkt_delivered_no_peer, 1);
  1427. return;
  1428. deliver_fail:
  1429. DP_STATS_INC_PKT(soc, rx.err.rx_invalid_peer, 1,
  1430. QDF_NBUF_CB_RX_PKT_LEN(nbuf));
  1431. qdf_nbuf_free(nbuf);
  1432. }
  1433. #else
  1434. static inline
  1435. void dp_rx_deliver_to_stack_no_peer(struct dp_soc *soc, qdf_nbuf_t nbuf)
  1436. {
  1437. DP_STATS_INC_PKT(soc, rx.err.rx_invalid_peer, 1,
  1438. QDF_NBUF_CB_RX_PKT_LEN(nbuf));
  1439. qdf_nbuf_free(nbuf);
  1440. }
  1441. #endif
  1442. /**
  1443. * dp_rx_srng_get_num_pending() - get number of pending entries
  1444. * @hal_soc: hal soc opaque pointer
  1445. * @hal_ring: opaque pointer to the HAL Rx Ring
  1446. * @num_entries: number of entries in the hal_ring.
  1447. * @near_full: pointer to a boolean. This is set if ring is near full.
  1448. *
  1449. * The function returns the number of entries in a destination ring which are
  1450. * yet to be reaped. The function also checks if the ring is near full.
  1451. * If more than half of the ring needs to be reaped, the ring is considered
  1452. * approaching full.
  1453. * The function useses hal_srng_dst_num_valid_locked to get the number of valid
  1454. * entries. It should not be called within a SRNG lock. HW pointer value is
  1455. * synced into cached_hp.
  1456. *
  1457. * Return: Number of pending entries if any
  1458. */
  1459. static
  1460. uint32_t dp_rx_srng_get_num_pending(hal_soc_handle_t hal_soc,
  1461. hal_ring_handle_t hal_ring_hdl,
  1462. uint32_t num_entries,
  1463. bool *near_full)
  1464. {
  1465. uint32_t num_pending = 0;
  1466. num_pending = hal_srng_dst_num_valid_locked(hal_soc,
  1467. hal_ring_hdl,
  1468. true);
  1469. if (num_entries && (num_pending >= num_entries >> 1))
  1470. *near_full = true;
  1471. else
  1472. *near_full = false;
  1473. return num_pending;
  1474. }
  1475. /**
  1476. * dp_rx_process() - Brain of the Rx processing functionality
  1477. * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
  1478. * @int_ctx: per interrupt context
  1479. * @hal_ring: opaque pointer to the HAL Rx Ring, which will be serviced
  1480. * @reo_ring_num: ring number (0, 1, 2 or 3) of the reo ring.
  1481. * @quota: No. of units (packets) that can be serviced in one shot.
  1482. *
  1483. * This function implements the core of Rx functionality. This is
  1484. * expected to handle only non-error frames.
  1485. *
  1486. * Return: uint32_t: No. of elements processed
  1487. */
  1488. uint32_t dp_rx_process(struct dp_intr *int_ctx, hal_ring_handle_t hal_ring_hdl,
  1489. uint8_t reo_ring_num, uint32_t quota)
  1490. {
  1491. hal_ring_desc_t ring_desc;
  1492. hal_soc_handle_t hal_soc;
  1493. struct dp_rx_desc *rx_desc = NULL;
  1494. qdf_nbuf_t nbuf, next;
  1495. bool near_full;
  1496. union dp_rx_desc_list_elem_t *head[MAX_PDEV_CNT];
  1497. union dp_rx_desc_list_elem_t *tail[MAX_PDEV_CNT];
  1498. uint32_t num_pending;
  1499. uint32_t rx_bufs_used = 0, rx_buf_cookie;
  1500. uint32_t l2_hdr_offset = 0;
  1501. uint16_t msdu_len = 0;
  1502. uint16_t peer_id;
  1503. struct dp_peer *peer;
  1504. struct dp_vdev *vdev;
  1505. uint32_t pkt_len = 0;
  1506. struct hal_rx_mpdu_desc_info mpdu_desc_info;
  1507. struct hal_rx_msdu_desc_info msdu_desc_info;
  1508. enum hal_reo_error_status error;
  1509. uint32_t peer_mdata;
  1510. uint8_t *rx_tlv_hdr;
  1511. uint32_t rx_bufs_reaped[MAX_PDEV_CNT];
  1512. uint8_t mac_id = 0;
  1513. struct dp_pdev *pdev;
  1514. struct dp_pdev *rx_pdev;
  1515. struct dp_srng *dp_rxdma_srng;
  1516. struct rx_desc_pool *rx_desc_pool;
  1517. struct dp_soc *soc = int_ctx->soc;
  1518. uint8_t ring_id = 0;
  1519. uint8_t core_id = 0;
  1520. struct cdp_tid_rx_stats *tid_stats;
  1521. qdf_nbuf_t nbuf_head;
  1522. qdf_nbuf_t nbuf_tail;
  1523. qdf_nbuf_t deliver_list_head;
  1524. qdf_nbuf_t deliver_list_tail;
  1525. uint32_t num_rx_bufs_reaped = 0;
  1526. uint32_t intr_id;
  1527. struct hif_opaque_softc *scn;
  1528. int32_t tid = 0;
  1529. bool is_prev_msdu_last = true;
  1530. uint32_t num_entries_avail = 0;
  1531. uint32_t rx_ol_pkt_cnt = 0;
  1532. uint32_t num_entries = 0;
  1533. DP_HIST_INIT();
  1534. qdf_assert_always(soc && hal_ring_hdl);
  1535. hal_soc = soc->hal_soc;
  1536. qdf_assert_always(hal_soc);
  1537. scn = soc->hif_handle;
  1538. hif_pm_runtime_mark_dp_rx_busy(scn);
  1539. intr_id = int_ctx->dp_intr_id;
  1540. num_entries = hal_srng_get_num_entries(hal_soc, hal_ring_hdl);
  1541. more_data:
  1542. /* reset local variables here to be re-used in the function */
  1543. nbuf_head = NULL;
  1544. nbuf_tail = NULL;
  1545. deliver_list_head = NULL;
  1546. deliver_list_tail = NULL;
  1547. peer = NULL;
  1548. vdev = NULL;
  1549. num_rx_bufs_reaped = 0;
  1550. qdf_mem_zero(rx_bufs_reaped, sizeof(rx_bufs_reaped));
  1551. qdf_mem_zero(&mpdu_desc_info, sizeof(mpdu_desc_info));
  1552. qdf_mem_zero(&msdu_desc_info, sizeof(msdu_desc_info));
  1553. qdf_mem_zero(head, sizeof(head));
  1554. qdf_mem_zero(tail, sizeof(tail));
  1555. if (qdf_unlikely(dp_srng_access_start(int_ctx, soc, hal_ring_hdl))) {
  1556. /*
  1557. * Need API to convert from hal_ring pointer to
  1558. * Ring Type / Ring Id combo
  1559. */
  1560. DP_STATS_INC(soc, rx.err.hal_ring_access_fail, 1);
  1561. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1562. FL("HAL RING Access Failed -- %pK"), hal_ring_hdl);
  1563. goto done;
  1564. }
  1565. /*
  1566. * start reaping the buffers from reo ring and queue
  1567. * them in per vdev queue.
  1568. * Process the received pkts in a different per vdev loop.
  1569. */
  1570. while (qdf_likely(quota &&
  1571. (ring_desc = hal_srng_dst_peek(hal_soc,
  1572. hal_ring_hdl)))) {
  1573. error = HAL_RX_ERROR_STATUS_GET(ring_desc);
  1574. ring_id = hal_srng_ring_id_get(hal_ring_hdl);
  1575. if (qdf_unlikely(error == HAL_REO_ERROR_DETECTED)) {
  1576. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1577. FL("HAL RING 0x%pK:error %d"), hal_ring_hdl, error);
  1578. DP_STATS_INC(soc, rx.err.hal_reo_error[ring_id], 1);
  1579. /* Don't know how to deal with this -- assert */
  1580. qdf_assert(0);
  1581. }
  1582. rx_buf_cookie = HAL_RX_REO_BUF_COOKIE_GET(ring_desc);
  1583. rx_desc = dp_rx_cookie_2_va_rxdma_buf(soc, rx_buf_cookie);
  1584. qdf_assert(rx_desc);
  1585. /*
  1586. * this is a unlikely scenario where the host is reaping
  1587. * a descriptor which it already reaped just a while ago
  1588. * but is yet to replenish it back to HW.
  1589. * In this case host will dump the last 128 descriptors
  1590. * including the software descriptor rx_desc and assert.
  1591. */
  1592. if (qdf_unlikely(!rx_desc->in_use)) {
  1593. DP_STATS_INC(soc, rx.err.hal_reo_dest_dup, 1);
  1594. dp_info_rl("Reaping rx_desc not in use!");
  1595. dp_rx_dump_info_and_assert(soc, hal_ring_hdl,
  1596. ring_desc, rx_desc);
  1597. /* ignore duplicate RX desc and continue to process */
  1598. /* Pop out the descriptor */
  1599. hal_srng_dst_get_next(hal_soc, hal_ring_hdl);
  1600. continue;
  1601. }
  1602. if (qdf_unlikely(!dp_rx_desc_check_magic(rx_desc))) {
  1603. dp_err("Invalid rx_desc cookie=%d", rx_buf_cookie);
  1604. DP_STATS_INC(soc, rx.err.rx_desc_invalid_magic, 1);
  1605. dp_rx_dump_info_and_assert(soc, hal_ring_hdl,
  1606. ring_desc, rx_desc);
  1607. }
  1608. dp_rx_desc_nbuf_sanity_check(ring_desc, rx_desc);
  1609. /* TODO */
  1610. /*
  1611. * Need a separate API for unmapping based on
  1612. * phyiscal address
  1613. */
  1614. qdf_nbuf_unmap_single(soc->osdev, rx_desc->nbuf,
  1615. QDF_DMA_FROM_DEVICE);
  1616. rx_desc->unmapped = 1;
  1617. core_id = smp_processor_id();
  1618. DP_STATS_INC(soc, rx.ring_packets[core_id][ring_id], 1);
  1619. /* Get MPDU DESC info */
  1620. hal_rx_mpdu_desc_info_get(ring_desc, &mpdu_desc_info);
  1621. /* Get MSDU DESC info */
  1622. hal_rx_msdu_desc_info_get(ring_desc, &msdu_desc_info);
  1623. if (mpdu_desc_info.mpdu_flags & HAL_MPDU_F_RETRY_BIT)
  1624. qdf_nbuf_set_rx_retry_flag(rx_desc->nbuf, 1);
  1625. if (qdf_unlikely(mpdu_desc_info.mpdu_flags &
  1626. HAL_MPDU_F_RAW_AMPDU)) {
  1627. /* previous msdu has end bit set, so current one is
  1628. * the new MPDU
  1629. */
  1630. if (is_prev_msdu_last) {
  1631. is_prev_msdu_last = false;
  1632. /* Get number of entries available in HW ring */
  1633. num_entries_avail =
  1634. hal_srng_dst_num_valid(hal_soc,
  1635. hal_ring_hdl, 1);
  1636. /* For new MPDU check if we can read complete
  1637. * MPDU by comparing the number of buffers
  1638. * available and number of buffers needed to
  1639. * reap this MPDU
  1640. */
  1641. if (((msdu_desc_info.msdu_len /
  1642. (RX_BUFFER_SIZE - RX_PKT_TLVS_LEN) + 1)) >
  1643. num_entries_avail)
  1644. break;
  1645. } else {
  1646. if (msdu_desc_info.msdu_flags &
  1647. HAL_MSDU_F_LAST_MSDU_IN_MPDU)
  1648. is_prev_msdu_last = true;
  1649. }
  1650. qdf_nbuf_set_raw_frame(rx_desc->nbuf, 1);
  1651. }
  1652. /* Pop out the descriptor*/
  1653. hal_srng_dst_get_next(hal_soc, hal_ring_hdl);
  1654. rx_bufs_reaped[rx_desc->pool_id]++;
  1655. peer_mdata = mpdu_desc_info.peer_meta_data;
  1656. QDF_NBUF_CB_RX_PEER_ID(rx_desc->nbuf) =
  1657. DP_PEER_METADATA_PEER_ID_GET(peer_mdata);
  1658. /*
  1659. * save msdu flags first, last and continuation msdu in
  1660. * nbuf->cb, also save mcbc, is_da_valid, is_sa_valid and
  1661. * length to nbuf->cb. This ensures the info required for
  1662. * per pkt processing is always in the same cache line.
  1663. * This helps in improving throughput for smaller pkt
  1664. * sizes.
  1665. */
  1666. if (msdu_desc_info.msdu_flags & HAL_MSDU_F_FIRST_MSDU_IN_MPDU)
  1667. qdf_nbuf_set_rx_chfrag_start(rx_desc->nbuf, 1);
  1668. if (msdu_desc_info.msdu_flags & HAL_MSDU_F_MSDU_CONTINUATION)
  1669. qdf_nbuf_set_rx_chfrag_cont(rx_desc->nbuf, 1);
  1670. if (msdu_desc_info.msdu_flags & HAL_MSDU_F_LAST_MSDU_IN_MPDU)
  1671. qdf_nbuf_set_rx_chfrag_end(rx_desc->nbuf, 1);
  1672. if (msdu_desc_info.msdu_flags & HAL_MSDU_F_DA_IS_MCBC)
  1673. qdf_nbuf_set_da_mcbc(rx_desc->nbuf, 1);
  1674. if (msdu_desc_info.msdu_flags & HAL_MSDU_F_DA_IS_VALID)
  1675. qdf_nbuf_set_da_valid(rx_desc->nbuf, 1);
  1676. if (msdu_desc_info.msdu_flags & HAL_MSDU_F_SA_IS_VALID)
  1677. qdf_nbuf_set_sa_valid(rx_desc->nbuf, 1);
  1678. qdf_nbuf_set_tid_val(rx_desc->nbuf,
  1679. HAL_RX_REO_QUEUE_NUMBER_GET(ring_desc));
  1680. QDF_NBUF_CB_RX_PKT_LEN(rx_desc->nbuf) = msdu_desc_info.msdu_len;
  1681. QDF_NBUF_CB_RX_CTX_ID(rx_desc->nbuf) = reo_ring_num;
  1682. DP_RX_LIST_APPEND(nbuf_head, nbuf_tail, rx_desc->nbuf);
  1683. /*
  1684. * if continuation bit is set then we have MSDU spread
  1685. * across multiple buffers, let us not decrement quota
  1686. * till we reap all buffers of that MSDU.
  1687. */
  1688. if (qdf_likely(!qdf_nbuf_is_rx_chfrag_cont(rx_desc->nbuf)))
  1689. quota -= 1;
  1690. dp_rx_add_to_free_desc_list(&head[rx_desc->pool_id],
  1691. &tail[rx_desc->pool_id],
  1692. rx_desc);
  1693. num_rx_bufs_reaped++;
  1694. if (dp_rx_reap_loop_pkt_limit_hit(soc, num_rx_bufs_reaped))
  1695. break;
  1696. }
  1697. done:
  1698. dp_srng_access_end(int_ctx, soc, hal_ring_hdl);
  1699. for (mac_id = 0; mac_id < MAX_PDEV_CNT; mac_id++) {
  1700. /*
  1701. * continue with next mac_id if no pkts were reaped
  1702. * from that pool
  1703. */
  1704. if (!rx_bufs_reaped[mac_id])
  1705. continue;
  1706. pdev = soc->pdev_list[mac_id];
  1707. dp_rxdma_srng = &pdev->rx_refill_buf_ring;
  1708. rx_desc_pool = &soc->rx_desc_buf[mac_id];
  1709. dp_rx_buffers_replenish(soc, mac_id, dp_rxdma_srng,
  1710. rx_desc_pool, rx_bufs_reaped[mac_id],
  1711. &head[mac_id], &tail[mac_id]);
  1712. }
  1713. dp_verbose_debug("replenished %u\n", rx_bufs_reaped[0]);
  1714. /* Peer can be NULL is case of LFR */
  1715. if (qdf_likely(peer))
  1716. vdev = NULL;
  1717. /*
  1718. * BIG loop where each nbuf is dequeued from global queue,
  1719. * processed and queued back on a per vdev basis. These nbufs
  1720. * are sent to stack as and when we run out of nbufs
  1721. * or a new nbuf dequeued from global queue has a different
  1722. * vdev when compared to previous nbuf.
  1723. */
  1724. nbuf = nbuf_head;
  1725. while (nbuf) {
  1726. next = nbuf->next;
  1727. rx_tlv_hdr = qdf_nbuf_data(nbuf);
  1728. /* Get TID from struct cb->tid_val, save to tid */
  1729. if (qdf_nbuf_is_rx_chfrag_start(nbuf))
  1730. tid = qdf_nbuf_get_tid_val(nbuf);
  1731. peer_mdata = QDF_NBUF_CB_RX_PEER_ID(nbuf);
  1732. peer_id = DP_PEER_METADATA_PEER_ID_GET(peer_mdata);
  1733. peer = dp_peer_find_by_id(soc, peer_id);
  1734. if (peer) {
  1735. QDF_NBUF_CB_DP_TRACE_PRINT(nbuf) = false;
  1736. qdf_dp_trace_set_track(nbuf, QDF_RX);
  1737. QDF_NBUF_CB_RX_DP_TRACE(nbuf) = 1;
  1738. QDF_NBUF_CB_RX_PACKET_TRACK(nbuf) =
  1739. QDF_NBUF_RX_PKT_DATA_TRACK;
  1740. }
  1741. rx_bufs_used++;
  1742. if (deliver_list_head && peer && (vdev != peer->vdev)) {
  1743. dp_rx_deliver_to_stack(vdev, peer, deliver_list_head,
  1744. deliver_list_tail);
  1745. deliver_list_head = NULL;
  1746. deliver_list_tail = NULL;
  1747. }
  1748. if (qdf_likely(peer)) {
  1749. vdev = peer->vdev;
  1750. } else {
  1751. nbuf->next = NULL;
  1752. dp_rx_deliver_to_stack_no_peer(soc, nbuf);
  1753. nbuf = next;
  1754. continue;
  1755. }
  1756. if (qdf_unlikely(!vdev)) {
  1757. qdf_nbuf_free(nbuf);
  1758. nbuf = next;
  1759. DP_STATS_INC(soc, rx.err.invalid_vdev, 1);
  1760. dp_peer_unref_del_find_by_id(peer);
  1761. continue;
  1762. }
  1763. rx_pdev = vdev->pdev;
  1764. DP_RX_TID_SAVE(nbuf, tid);
  1765. if (qdf_unlikely(rx_pdev->delay_stats_flag))
  1766. qdf_nbuf_set_timestamp(nbuf);
  1767. ring_id = QDF_NBUF_CB_RX_CTX_ID(nbuf);
  1768. tid_stats =
  1769. &rx_pdev->stats.tid_stats.tid_rx_stats[ring_id][tid];
  1770. /*
  1771. * Check if DMA completed -- msdu_done is the last bit
  1772. * to be written
  1773. */
  1774. if (qdf_unlikely(!qdf_nbuf_is_raw_frame(nbuf) &&
  1775. !hal_rx_attn_msdu_done_get(rx_tlv_hdr))) {
  1776. dp_err("MSDU DONE failure");
  1777. DP_STATS_INC(soc, rx.err.msdu_done_fail, 1);
  1778. hal_rx_dump_pkt_tlvs(hal_soc, rx_tlv_hdr,
  1779. QDF_TRACE_LEVEL_INFO);
  1780. tid_stats->fail_cnt[MSDU_DONE_FAILURE]++;
  1781. qdf_nbuf_free(nbuf);
  1782. qdf_assert(0);
  1783. nbuf = next;
  1784. continue;
  1785. }
  1786. DP_HIST_PACKET_COUNT_INC(vdev->pdev->pdev_id);
  1787. /*
  1788. * First IF condition:
  1789. * 802.11 Fragmented pkts are reinjected to REO
  1790. * HW block as SG pkts and for these pkts we only
  1791. * need to pull the RX TLVS header length.
  1792. * Second IF condition:
  1793. * The below condition happens when an MSDU is spread
  1794. * across multiple buffers. This can happen in two cases
  1795. * 1. The nbuf size is smaller then the received msdu.
  1796. * ex: we have set the nbuf size to 2048 during
  1797. * nbuf_alloc. but we received an msdu which is
  1798. * 2304 bytes in size then this msdu is spread
  1799. * across 2 nbufs.
  1800. *
  1801. * 2. AMSDUs when RAW mode is enabled.
  1802. * ex: 1st MSDU is in 1st nbuf and 2nd MSDU is spread
  1803. * across 1st nbuf and 2nd nbuf and last MSDU is
  1804. * spread across 2nd nbuf and 3rd nbuf.
  1805. *
  1806. * for these scenarios let us create a skb frag_list and
  1807. * append these buffers till the last MSDU of the AMSDU
  1808. * Third condition:
  1809. * This is the most likely case, we receive 802.3 pkts
  1810. * decapsulated by HW, here we need to set the pkt length.
  1811. */
  1812. if (qdf_unlikely(qdf_nbuf_is_frag(nbuf))) {
  1813. bool is_mcbc, is_sa_vld, is_da_vld;
  1814. is_mcbc = hal_rx_msdu_end_da_is_mcbc_get(soc->hal_soc,
  1815. rx_tlv_hdr);
  1816. is_sa_vld =
  1817. hal_rx_msdu_end_sa_is_valid_get(soc->hal_soc,
  1818. rx_tlv_hdr);
  1819. is_da_vld =
  1820. hal_rx_msdu_end_da_is_valid_get(soc->hal_soc,
  1821. rx_tlv_hdr);
  1822. qdf_nbuf_set_da_mcbc(nbuf, is_mcbc);
  1823. qdf_nbuf_set_da_valid(nbuf, is_da_vld);
  1824. qdf_nbuf_set_sa_valid(nbuf, is_sa_vld);
  1825. qdf_nbuf_pull_head(nbuf, RX_PKT_TLVS_LEN);
  1826. } else if (qdf_nbuf_is_raw_frame(nbuf)) {
  1827. msdu_len = QDF_NBUF_CB_RX_PKT_LEN(nbuf);
  1828. nbuf = dp_rx_sg_create(nbuf, rx_tlv_hdr);
  1829. DP_STATS_INC(vdev->pdev, rx_raw_pkts, 1);
  1830. DP_STATS_INC_PKT(peer, rx.raw, 1, msdu_len);
  1831. next = nbuf->next;
  1832. } else {
  1833. l2_hdr_offset =
  1834. hal_rx_msdu_end_l3_hdr_padding_get(soc->hal_soc,
  1835. rx_tlv_hdr);
  1836. msdu_len = QDF_NBUF_CB_RX_PKT_LEN(nbuf);
  1837. pkt_len = msdu_len + l2_hdr_offset + RX_PKT_TLVS_LEN;
  1838. qdf_nbuf_set_pktlen(nbuf, pkt_len);
  1839. qdf_nbuf_pull_head(nbuf,
  1840. RX_PKT_TLVS_LEN +
  1841. l2_hdr_offset);
  1842. }
  1843. /*
  1844. * process frame for mulitpass phrase processing
  1845. */
  1846. if (qdf_unlikely(vdev->multipass_en)) {
  1847. dp_rx_multipass_process(peer, nbuf, tid);
  1848. }
  1849. if (!dp_wds_rx_policy_check(rx_tlv_hdr, vdev, peer)) {
  1850. QDF_TRACE(QDF_MODULE_ID_DP,
  1851. QDF_TRACE_LEVEL_ERROR,
  1852. FL("Policy Check Drop pkt"));
  1853. tid_stats->fail_cnt[POLICY_CHECK_DROP]++;
  1854. /* Drop & free packet */
  1855. qdf_nbuf_free(nbuf);
  1856. /* Statistics */
  1857. nbuf = next;
  1858. dp_peer_unref_del_find_by_id(peer);
  1859. continue;
  1860. }
  1861. if (qdf_unlikely(peer && (peer->nawds_enabled) &&
  1862. (qdf_nbuf_is_da_mcbc(nbuf)) &&
  1863. (hal_rx_get_mpdu_mac_ad4_valid(soc->hal_soc,
  1864. rx_tlv_hdr) ==
  1865. false))) {
  1866. tid_stats->fail_cnt[NAWDS_MCAST_DROP]++;
  1867. DP_STATS_INC(peer, rx.nawds_mcast_drop, 1);
  1868. qdf_nbuf_free(nbuf);
  1869. nbuf = next;
  1870. dp_peer_unref_del_find_by_id(peer);
  1871. continue;
  1872. }
  1873. if (soc->process_rx_status)
  1874. dp_rx_cksum_offload(vdev->pdev, nbuf, rx_tlv_hdr);
  1875. /* Update the protocol tag in SKB based on CCE metadata */
  1876. dp_rx_update_protocol_tag(soc, vdev, nbuf, rx_tlv_hdr,
  1877. reo_ring_num, false, true);
  1878. /* Update the flow tag in SKB based on FSE metadata */
  1879. dp_rx_update_flow_tag(soc, vdev, nbuf, rx_tlv_hdr, true);
  1880. dp_rx_msdu_stats_update(soc, nbuf, rx_tlv_hdr, peer,
  1881. ring_id, tid_stats);
  1882. if (qdf_unlikely(vdev->mesh_vdev)) {
  1883. if (dp_rx_filter_mesh_packets(vdev, nbuf, rx_tlv_hdr)
  1884. == QDF_STATUS_SUCCESS) {
  1885. QDF_TRACE(QDF_MODULE_ID_DP,
  1886. QDF_TRACE_LEVEL_INFO_MED,
  1887. FL("mesh pkt filtered"));
  1888. tid_stats->fail_cnt[MESH_FILTER_DROP]++;
  1889. DP_STATS_INC(vdev->pdev, dropped.mesh_filter,
  1890. 1);
  1891. qdf_nbuf_free(nbuf);
  1892. nbuf = next;
  1893. dp_peer_unref_del_find_by_id(peer);
  1894. continue;
  1895. }
  1896. dp_rx_fill_mesh_stats(vdev, nbuf, rx_tlv_hdr, peer);
  1897. }
  1898. if (qdf_likely(vdev->rx_decap_type ==
  1899. htt_cmn_pkt_type_ethernet) &&
  1900. qdf_likely(!vdev->mesh_vdev)) {
  1901. /* WDS Destination Address Learning */
  1902. dp_rx_da_learn(soc, rx_tlv_hdr, peer, nbuf);
  1903. /* Due to HW issue, sometimes we see that the sa_idx
  1904. * and da_idx are invalid with sa_valid and da_valid
  1905. * bits set
  1906. *
  1907. * in this case we also see that value of
  1908. * sa_sw_peer_id is set as 0
  1909. *
  1910. * Drop the packet if sa_idx and da_idx OOB or
  1911. * sa_sw_peerid is 0
  1912. */
  1913. if (!is_sa_da_idx_valid(soc, rx_tlv_hdr, nbuf)) {
  1914. qdf_nbuf_free(nbuf);
  1915. nbuf = next;
  1916. DP_STATS_INC(soc, rx.err.invalid_sa_da_idx, 1);
  1917. dp_peer_unref_del_find_by_id(peer);
  1918. continue;
  1919. }
  1920. /* WDS Source Port Learning */
  1921. if (qdf_likely(vdev->wds_enabled))
  1922. dp_rx_wds_srcport_learn(soc, rx_tlv_hdr,
  1923. peer, nbuf);
  1924. /* Intrabss-fwd */
  1925. if (dp_rx_check_ap_bridge(vdev))
  1926. if (dp_rx_intrabss_fwd(soc,
  1927. peer,
  1928. rx_tlv_hdr,
  1929. nbuf)) {
  1930. nbuf = next;
  1931. dp_peer_unref_del_find_by_id(peer);
  1932. tid_stats->intrabss_cnt++;
  1933. continue; /* Get next desc */
  1934. }
  1935. }
  1936. dp_rx_fill_gro_info(soc, rx_tlv_hdr, nbuf, &rx_ol_pkt_cnt);
  1937. DP_RX_LIST_APPEND(deliver_list_head,
  1938. deliver_list_tail,
  1939. nbuf);
  1940. DP_STATS_INC_PKT(peer, rx.to_stack, 1,
  1941. QDF_NBUF_CB_RX_PKT_LEN(nbuf));
  1942. tid_stats->delivered_to_stack++;
  1943. nbuf = next;
  1944. dp_peer_unref_del_find_by_id(peer);
  1945. }
  1946. if (deliver_list_head && peer)
  1947. dp_rx_deliver_to_stack(vdev, peer, deliver_list_head,
  1948. deliver_list_tail);
  1949. if (dp_rx_enable_eol_data_check(soc) && rx_bufs_used) {
  1950. if (quota) {
  1951. num_pending =
  1952. dp_rx_srng_get_num_pending(hal_soc,
  1953. hal_ring_hdl,
  1954. num_entries,
  1955. &near_full);
  1956. if (num_pending) {
  1957. DP_STATS_INC(soc, rx.hp_oos2, 1);
  1958. if (!hif_exec_should_yield(scn, intr_id))
  1959. goto more_data;
  1960. if (qdf_unlikely(near_full)) {
  1961. DP_STATS_INC(soc, rx.near_full, 1);
  1962. goto more_data;
  1963. }
  1964. }
  1965. }
  1966. if (vdev && vdev->osif_gro_flush && rx_ol_pkt_cnt) {
  1967. vdev->osif_gro_flush(vdev->osif_vdev,
  1968. reo_ring_num);
  1969. }
  1970. }
  1971. /* Update histogram statistics by looping through pdev's */
  1972. DP_RX_HIST_STATS_PER_PDEV();
  1973. return rx_bufs_used; /* Assume no scale factor for now */
  1974. }
  1975. QDF_STATUS dp_rx_vdev_detach(struct dp_vdev *vdev)
  1976. {
  1977. QDF_STATUS ret;
  1978. if (vdev->osif_rx_flush) {
  1979. ret = vdev->osif_rx_flush(vdev->osif_vdev, vdev->vdev_id);
  1980. if (!ret) {
  1981. dp_err("Failed to flush rx pkts for vdev %d\n",
  1982. vdev->vdev_id);
  1983. return ret;
  1984. }
  1985. }
  1986. return QDF_STATUS_SUCCESS;
  1987. }
  1988. /**
  1989. * dp_rx_pdev_detach() - detach dp rx
  1990. * @pdev: core txrx pdev context
  1991. *
  1992. * This function will detach DP RX into main device context
  1993. * will free DP Rx resources.
  1994. *
  1995. * Return: void
  1996. */
  1997. void
  1998. dp_rx_pdev_detach(struct dp_pdev *pdev)
  1999. {
  2000. uint8_t pdev_id = pdev->pdev_id;
  2001. struct dp_soc *soc = pdev->soc;
  2002. struct rx_desc_pool *rx_desc_pool;
  2003. rx_desc_pool = &soc->rx_desc_buf[pdev_id];
  2004. if (rx_desc_pool->pool_size != 0) {
  2005. if (!dp_is_soc_reinit(soc))
  2006. dp_rx_desc_nbuf_and_pool_free(soc, pdev_id,
  2007. rx_desc_pool);
  2008. else
  2009. dp_rx_desc_nbuf_free(soc, rx_desc_pool);
  2010. }
  2011. return;
  2012. }
  2013. static QDF_STATUS
  2014. dp_pdev_nbuf_alloc_and_map(struct dp_soc *dp_soc, qdf_nbuf_t *nbuf,
  2015. struct dp_pdev *dp_pdev)
  2016. {
  2017. qdf_dma_addr_t paddr;
  2018. QDF_STATUS ret = QDF_STATUS_E_FAILURE;
  2019. *nbuf = qdf_nbuf_alloc(dp_soc->osdev, RX_BUFFER_SIZE,
  2020. RX_BUFFER_RESERVATION, RX_BUFFER_ALIGNMENT,
  2021. FALSE);
  2022. if (!(*nbuf)) {
  2023. dp_err("nbuf alloc failed");
  2024. DP_STATS_INC(dp_pdev, replenish.nbuf_alloc_fail, 1);
  2025. return ret;
  2026. }
  2027. ret = qdf_nbuf_map_single(dp_soc->osdev, *nbuf,
  2028. QDF_DMA_FROM_DEVICE);
  2029. if (qdf_unlikely(QDF_IS_STATUS_ERROR(ret))) {
  2030. qdf_nbuf_free(*nbuf);
  2031. dp_err("nbuf map failed");
  2032. DP_STATS_INC(dp_pdev, replenish.map_err, 1);
  2033. return ret;
  2034. }
  2035. paddr = qdf_nbuf_get_frag_paddr(*nbuf, 0);
  2036. ret = check_x86_paddr(dp_soc, nbuf, &paddr, dp_pdev);
  2037. if (ret == QDF_STATUS_E_FAILURE) {
  2038. qdf_nbuf_unmap_single(dp_soc->osdev, *nbuf,
  2039. QDF_DMA_FROM_DEVICE);
  2040. qdf_nbuf_free(*nbuf);
  2041. dp_err("nbuf check x86 failed");
  2042. DP_STATS_INC(dp_pdev, replenish.x86_fail, 1);
  2043. return ret;
  2044. }
  2045. return QDF_STATUS_SUCCESS;
  2046. }
  2047. QDF_STATUS
  2048. dp_pdev_rx_buffers_attach(struct dp_soc *dp_soc, uint32_t mac_id,
  2049. struct dp_srng *dp_rxdma_srng,
  2050. struct rx_desc_pool *rx_desc_pool,
  2051. uint32_t num_req_buffers)
  2052. {
  2053. struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(dp_soc, mac_id);
  2054. hal_ring_handle_t rxdma_srng = dp_rxdma_srng->hal_srng;
  2055. union dp_rx_desc_list_elem_t *next;
  2056. void *rxdma_ring_entry;
  2057. qdf_dma_addr_t paddr;
  2058. qdf_nbuf_t *rx_nbuf_arr;
  2059. uint32_t nr_descs, nr_nbuf = 0, nr_nbuf_total = 0;
  2060. uint32_t buffer_index, nbuf_ptrs_per_page;
  2061. qdf_nbuf_t nbuf;
  2062. QDF_STATUS ret;
  2063. int page_idx, total_pages;
  2064. union dp_rx_desc_list_elem_t *desc_list = NULL;
  2065. union dp_rx_desc_list_elem_t *tail = NULL;
  2066. if (qdf_unlikely(!rxdma_srng)) {
  2067. DP_STATS_INC(dp_pdev, replenish.rxdma_err, num_req_buffers);
  2068. return QDF_STATUS_E_FAILURE;
  2069. }
  2070. dp_debug("requested %u RX buffers for driver attach", num_req_buffers);
  2071. nr_descs = dp_rx_get_free_desc_list(dp_soc, mac_id, rx_desc_pool,
  2072. num_req_buffers, &desc_list, &tail);
  2073. if (!nr_descs) {
  2074. dp_err("no free rx_descs in freelist");
  2075. DP_STATS_INC(dp_pdev, err.desc_alloc_fail, num_req_buffers);
  2076. return QDF_STATUS_E_NOMEM;
  2077. }
  2078. dp_debug("got %u RX descs for driver attach", nr_descs);
  2079. /*
  2080. * Try to allocate pointers to the nbuf one page at a time.
  2081. * Take pointers that can fit in one page of memory and
  2082. * iterate through the total descriptors that need to be
  2083. * allocated in order of pages. Reuse the pointers that
  2084. * have been allocated to fit in one page across each
  2085. * iteration to index into the nbuf.
  2086. */
  2087. total_pages = (nr_descs * sizeof(*rx_nbuf_arr)) / PAGE_SIZE;
  2088. /*
  2089. * Add an extra page to store the remainder if any
  2090. */
  2091. if ((nr_descs * sizeof(*rx_nbuf_arr)) % PAGE_SIZE)
  2092. total_pages++;
  2093. rx_nbuf_arr = qdf_mem_malloc(PAGE_SIZE);
  2094. if (!rx_nbuf_arr) {
  2095. dp_err("failed to allocate nbuf array");
  2096. DP_STATS_INC(dp_pdev, replenish.rxdma_err, num_req_buffers);
  2097. QDF_BUG(0);
  2098. return QDF_STATUS_E_NOMEM;
  2099. }
  2100. nbuf_ptrs_per_page = PAGE_SIZE / sizeof(*rx_nbuf_arr);
  2101. for (page_idx = 0; page_idx < total_pages; page_idx++) {
  2102. qdf_mem_zero(rx_nbuf_arr, PAGE_SIZE);
  2103. for (nr_nbuf = 0; nr_nbuf < nbuf_ptrs_per_page; nr_nbuf++) {
  2104. /*
  2105. * The last page of buffer pointers may not be required
  2106. * completely based on the number of descriptors. Below
  2107. * check will ensure we are allocating only the
  2108. * required number of descriptors.
  2109. */
  2110. if (nr_nbuf_total >= nr_descs)
  2111. break;
  2112. ret = dp_pdev_nbuf_alloc_and_map(dp_soc,
  2113. &rx_nbuf_arr[nr_nbuf],
  2114. dp_pdev);
  2115. if (QDF_IS_STATUS_ERROR(ret))
  2116. break;
  2117. nr_nbuf_total++;
  2118. }
  2119. hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
  2120. for (buffer_index = 0; buffer_index < nr_nbuf; buffer_index++) {
  2121. rxdma_ring_entry =
  2122. hal_srng_src_get_next(dp_soc->hal_soc,
  2123. rxdma_srng);
  2124. qdf_assert_always(rxdma_ring_entry);
  2125. next = desc_list->next;
  2126. nbuf = rx_nbuf_arr[buffer_index];
  2127. paddr = qdf_nbuf_get_frag_paddr(nbuf, 0);
  2128. dp_rx_desc_prep(&desc_list->rx_desc, nbuf);
  2129. desc_list->rx_desc.in_use = 1;
  2130. hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
  2131. desc_list->rx_desc.cookie,
  2132. rx_desc_pool->owner);
  2133. dp_ipa_handle_rx_buf_smmu_mapping(dp_soc, nbuf, true);
  2134. desc_list = next;
  2135. }
  2136. hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
  2137. }
  2138. dp_info("filled %u RX buffers for driver attach", nr_nbuf_total);
  2139. qdf_mem_free(rx_nbuf_arr);
  2140. if (!nr_nbuf_total) {
  2141. dp_err("No nbuf's allocated");
  2142. QDF_BUG(0);
  2143. return QDF_STATUS_E_RESOURCES;
  2144. }
  2145. DP_STATS_INC_PKT(dp_pdev, replenish.pkts, nr_nbuf,
  2146. RX_BUFFER_SIZE * nr_nbuf_total);
  2147. return QDF_STATUS_SUCCESS;
  2148. }
  2149. /**
  2150. * dp_rx_attach() - attach DP RX
  2151. * @pdev: core txrx pdev context
  2152. *
  2153. * This function will attach a DP RX instance into the main
  2154. * device (SOC) context. Will allocate dp rx resource and
  2155. * initialize resources.
  2156. *
  2157. * Return: QDF_STATUS_SUCCESS: success
  2158. * QDF_STATUS_E_RESOURCES: Error return
  2159. */
  2160. QDF_STATUS
  2161. dp_rx_pdev_attach(struct dp_pdev *pdev)
  2162. {
  2163. uint8_t pdev_id = pdev->pdev_id;
  2164. struct dp_soc *soc = pdev->soc;
  2165. uint32_t rxdma_entries;
  2166. uint32_t rx_sw_desc_weight;
  2167. struct dp_srng *dp_rxdma_srng;
  2168. struct rx_desc_pool *rx_desc_pool;
  2169. QDF_STATUS ret_val;
  2170. if (wlan_cfg_get_dp_pdev_nss_enabled(pdev->wlan_cfg_ctx)) {
  2171. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2172. "nss-wifi<4> skip Rx refil %d", pdev_id);
  2173. return QDF_STATUS_SUCCESS;
  2174. }
  2175. pdev = soc->pdev_list[pdev_id];
  2176. dp_rxdma_srng = &pdev->rx_refill_buf_ring;
  2177. rxdma_entries = dp_rxdma_srng->num_entries;
  2178. soc->process_rx_status = CONFIG_PROCESS_RX_STATUS;
  2179. rx_desc_pool = &soc->rx_desc_buf[pdev_id];
  2180. rx_sw_desc_weight = wlan_cfg_get_dp_soc_rx_sw_desc_weight(soc->wlan_cfg_ctx);
  2181. dp_rx_desc_pool_alloc(soc, pdev_id,
  2182. rx_sw_desc_weight * rxdma_entries,
  2183. rx_desc_pool);
  2184. rx_desc_pool->owner = DP_WBM2SW_RBM;
  2185. /* For Rx buffers, WBM release ring is SW RING 3,for all pdev's */
  2186. ret_val = dp_rx_fst_attach(soc, pdev);
  2187. if ((ret_val != QDF_STATUS_SUCCESS) &&
  2188. (ret_val != QDF_STATUS_E_NOSUPPORT)) {
  2189. QDF_TRACE(QDF_MODULE_ID_ANY, QDF_TRACE_LEVEL_ERROR,
  2190. "RX Flow Search Table attach failed: pdev %d err %d",
  2191. pdev_id, ret_val);
  2192. return ret_val;
  2193. }
  2194. return dp_pdev_rx_buffers_attach(soc, pdev_id, dp_rxdma_srng,
  2195. rx_desc_pool, rxdma_entries - 1);
  2196. }
  2197. /*
  2198. * dp_rx_nbuf_prepare() - prepare RX nbuf
  2199. * @soc: core txrx main context
  2200. * @pdev: core txrx pdev context
  2201. *
  2202. * This function alloc & map nbuf for RX dma usage, retry it if failed
  2203. * until retry times reaches max threshold or succeeded.
  2204. *
  2205. * Return: qdf_nbuf_t pointer if succeeded, NULL if failed.
  2206. */
  2207. qdf_nbuf_t
  2208. dp_rx_nbuf_prepare(struct dp_soc *soc, struct dp_pdev *pdev)
  2209. {
  2210. uint8_t *buf;
  2211. int32_t nbuf_retry_count;
  2212. QDF_STATUS ret;
  2213. qdf_nbuf_t nbuf = NULL;
  2214. for (nbuf_retry_count = 0; nbuf_retry_count <
  2215. QDF_NBUF_ALLOC_MAP_RETRY_THRESHOLD;
  2216. nbuf_retry_count++) {
  2217. /* Allocate a new skb */
  2218. nbuf = qdf_nbuf_alloc(soc->osdev,
  2219. RX_BUFFER_SIZE,
  2220. RX_BUFFER_RESERVATION,
  2221. RX_BUFFER_ALIGNMENT,
  2222. FALSE);
  2223. if (!nbuf) {
  2224. DP_STATS_INC(pdev,
  2225. replenish.nbuf_alloc_fail, 1);
  2226. continue;
  2227. }
  2228. buf = qdf_nbuf_data(nbuf);
  2229. memset(buf, 0, RX_BUFFER_SIZE);
  2230. ret = qdf_nbuf_map_single(soc->osdev, nbuf,
  2231. QDF_DMA_FROM_DEVICE);
  2232. /* nbuf map failed */
  2233. if (qdf_unlikely(QDF_IS_STATUS_ERROR(ret))) {
  2234. qdf_nbuf_free(nbuf);
  2235. DP_STATS_INC(pdev, replenish.map_err, 1);
  2236. continue;
  2237. }
  2238. /* qdf_nbuf alloc and map succeeded */
  2239. break;
  2240. }
  2241. /* qdf_nbuf still alloc or map failed */
  2242. if (qdf_unlikely(nbuf_retry_count >=
  2243. QDF_NBUF_ALLOC_MAP_RETRY_THRESHOLD))
  2244. return NULL;
  2245. return nbuf;
  2246. }