dp_rx.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903
  1. /*
  2. * Copyright (c) 2016-2018 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. #ifdef RX_DESC_DEBUG_CHECK
  31. static inline void dp_rx_desc_prep(struct dp_rx_desc *rx_desc, qdf_nbuf_t nbuf)
  32. {
  33. rx_desc->magic = DP_RX_DESC_MAGIC;
  34. rx_desc->nbuf = nbuf;
  35. }
  36. #else
  37. static inline void dp_rx_desc_prep(struct dp_rx_desc *rx_desc, qdf_nbuf_t nbuf)
  38. {
  39. rx_desc->nbuf = nbuf;
  40. }
  41. #endif
  42. #ifdef CONFIG_WIN
  43. static inline bool dp_rx_check_ap_bridge(struct dp_vdev *vdev)
  44. {
  45. return vdev->ap_bridge_enabled;
  46. }
  47. #else
  48. static inline bool dp_rx_check_ap_bridge(struct dp_vdev *vdev)
  49. {
  50. if (vdev->opmode != wlan_op_mode_sta)
  51. return true;
  52. else
  53. return false;
  54. }
  55. #endif
  56. /*
  57. * dp_rx_buffers_replenish() - replenish rxdma ring with rx nbufs
  58. * called during dp rx initialization
  59. * and at the end of dp_rx_process.
  60. *
  61. * @soc: core txrx main context
  62. * @mac_id: mac_id which is one of 3 mac_ids
  63. * @dp_rxdma_srng: dp rxdma circular ring
  64. * @rx_desc_pool: Pointer to free Rx descriptor pool
  65. * @num_req_buffers: number of buffer to be replenished
  66. * @desc_list: list of descs if called from dp_rx_process
  67. * or NULL during dp rx initialization or out of buffer
  68. * interrupt.
  69. * @tail: tail of descs list
  70. * Return: return success or failure
  71. */
  72. QDF_STATUS dp_rx_buffers_replenish(struct dp_soc *dp_soc, uint32_t mac_id,
  73. struct dp_srng *dp_rxdma_srng,
  74. struct rx_desc_pool *rx_desc_pool,
  75. uint32_t num_req_buffers,
  76. union dp_rx_desc_list_elem_t **desc_list,
  77. union dp_rx_desc_list_elem_t **tail)
  78. {
  79. uint32_t num_alloc_desc;
  80. uint16_t num_desc_to_free = 0;
  81. struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(dp_soc, mac_id);
  82. uint32_t num_entries_avail;
  83. uint32_t count;
  84. int sync_hw_ptr = 1;
  85. qdf_dma_addr_t paddr;
  86. qdf_nbuf_t rx_netbuf;
  87. void *rxdma_ring_entry;
  88. union dp_rx_desc_list_elem_t *next;
  89. QDF_STATUS ret;
  90. void *rxdma_srng;
  91. rxdma_srng = dp_rxdma_srng->hal_srng;
  92. if (!rxdma_srng) {
  93. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  94. "rxdma srng not initialized");
  95. DP_STATS_INC(dp_pdev, replenish.rxdma_err, num_req_buffers);
  96. return QDF_STATUS_E_FAILURE;
  97. }
  98. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  99. "requested %d buffers for replenish", num_req_buffers);
  100. hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
  101. num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
  102. rxdma_srng,
  103. sync_hw_ptr);
  104. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  105. "no of available entries in rxdma ring: %d",
  106. num_entries_avail);
  107. if (!(*desc_list) && (num_entries_avail >
  108. ((dp_rxdma_srng->num_entries * 3) / 4))) {
  109. num_req_buffers = num_entries_avail;
  110. } else if (num_entries_avail < num_req_buffers) {
  111. num_desc_to_free = num_req_buffers - num_entries_avail;
  112. num_req_buffers = num_entries_avail;
  113. }
  114. if (qdf_unlikely(!num_req_buffers)) {
  115. num_desc_to_free = num_req_buffers;
  116. hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
  117. goto free_descs;
  118. }
  119. /*
  120. * if desc_list is NULL, allocate the descs from freelist
  121. */
  122. if (!(*desc_list)) {
  123. num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
  124. rx_desc_pool,
  125. num_req_buffers,
  126. desc_list,
  127. tail);
  128. if (!num_alloc_desc) {
  129. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  130. "no free rx_descs in freelist");
  131. DP_STATS_INC(dp_pdev, err.desc_alloc_fail,
  132. num_req_buffers);
  133. hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
  134. return QDF_STATUS_E_NOMEM;
  135. }
  136. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  137. "%d rx desc allocated", num_alloc_desc);
  138. num_req_buffers = num_alloc_desc;
  139. }
  140. count = 0;
  141. while (count < num_req_buffers) {
  142. rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
  143. RX_BUFFER_SIZE,
  144. RX_BUFFER_RESERVATION,
  145. RX_BUFFER_ALIGNMENT,
  146. FALSE);
  147. if (rx_netbuf == NULL) {
  148. DP_STATS_INC(dp_pdev, replenish.nbuf_alloc_fail, 1);
  149. continue;
  150. }
  151. ret = qdf_nbuf_map_single(dp_soc->osdev, rx_netbuf,
  152. QDF_DMA_BIDIRECTIONAL);
  153. if (qdf_unlikely(QDF_IS_STATUS_ERROR(ret))) {
  154. qdf_nbuf_free(rx_netbuf);
  155. DP_STATS_INC(dp_pdev, replenish.map_err, 1);
  156. continue;
  157. }
  158. paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
  159. /*
  160. * check if the physical address of nbuf->data is
  161. * less then 0x50000000 then free the nbuf and try
  162. * allocating new nbuf. We can try for 100 times.
  163. * this is a temp WAR till we fix it properly.
  164. */
  165. ret = check_x86_paddr(dp_soc, &rx_netbuf, &paddr, dp_pdev);
  166. if (ret == QDF_STATUS_E_FAILURE) {
  167. DP_STATS_INC(dp_pdev, replenish.x86_fail, 1);
  168. break;
  169. }
  170. count++;
  171. rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
  172. rxdma_srng);
  173. qdf_assert_always(rxdma_ring_entry);
  174. next = (*desc_list)->next;
  175. dp_rx_desc_prep(&((*desc_list)->rx_desc), rx_netbuf);
  176. (*desc_list)->rx_desc.in_use = 1;
  177. dp_debug("rx_netbuf=%pK, buf=%pK, paddr=0x%llx, cookie=%d",
  178. rx_netbuf, qdf_nbuf_data(rx_netbuf),
  179. (unsigned long long)paddr,
  180. (*desc_list)->rx_desc.cookie);
  181. hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
  182. (*desc_list)->rx_desc.cookie,
  183. rx_desc_pool->owner);
  184. *desc_list = next;
  185. }
  186. hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
  187. dp_debug("replenished buffers %d, rx desc added back to free list %u",
  188. num_req_buffers, num_desc_to_free);
  189. DP_STATS_INC_PKT(dp_pdev, replenish.pkts, num_req_buffers,
  190. (RX_BUFFER_SIZE * num_req_buffers));
  191. free_descs:
  192. DP_STATS_INC(dp_pdev, buf_freelist, num_desc_to_free);
  193. /*
  194. * add any available free desc back to the free list
  195. */
  196. if (*desc_list)
  197. dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
  198. mac_id, rx_desc_pool);
  199. return QDF_STATUS_SUCCESS;
  200. }
  201. /*
  202. * dp_rx_deliver_raw() - process RAW mode pkts and hand over the
  203. * pkts to RAW mode simulation to
  204. * decapsulate the pkt.
  205. *
  206. * @vdev: vdev on which RAW mode is enabled
  207. * @nbuf_list: list of RAW pkts to process
  208. * @peer: peer object from which the pkt is rx
  209. *
  210. * Return: void
  211. */
  212. void
  213. dp_rx_deliver_raw(struct dp_vdev *vdev, qdf_nbuf_t nbuf_list,
  214. struct dp_peer *peer)
  215. {
  216. qdf_nbuf_t deliver_list_head = NULL;
  217. qdf_nbuf_t deliver_list_tail = NULL;
  218. qdf_nbuf_t nbuf;
  219. nbuf = nbuf_list;
  220. while (nbuf) {
  221. qdf_nbuf_t next = qdf_nbuf_next(nbuf);
  222. DP_RX_LIST_APPEND(deliver_list_head, deliver_list_tail, nbuf);
  223. DP_STATS_INC(vdev->pdev, rx_raw_pkts, 1);
  224. DP_STATS_INC_PKT(peer, rx.raw, 1, qdf_nbuf_len(nbuf));
  225. /*
  226. * reset the chfrag_start and chfrag_end bits in nbuf cb
  227. * as this is a non-amsdu pkt and RAW mode simulation expects
  228. * these bit s to be 0 for non-amsdu pkt.
  229. */
  230. if (qdf_nbuf_is_rx_chfrag_start(nbuf) &&
  231. qdf_nbuf_is_rx_chfrag_end(nbuf)) {
  232. qdf_nbuf_set_rx_chfrag_start(nbuf, 0);
  233. qdf_nbuf_set_rx_chfrag_end(nbuf, 0);
  234. }
  235. nbuf = next;
  236. }
  237. vdev->osif_rsim_rx_decap(vdev->osif_vdev, &deliver_list_head,
  238. &deliver_list_tail, (struct cdp_peer*) peer);
  239. vdev->osif_rx(vdev->osif_vdev, deliver_list_head);
  240. }
  241. #ifdef DP_LFR
  242. /*
  243. * In case of LFR, data of a new peer might be sent up
  244. * even before peer is added.
  245. */
  246. static inline struct dp_vdev *
  247. dp_get_vdev_from_peer(struct dp_soc *soc,
  248. uint16_t peer_id,
  249. struct dp_peer *peer,
  250. struct hal_rx_mpdu_desc_info mpdu_desc_info)
  251. {
  252. struct dp_vdev *vdev;
  253. uint8_t vdev_id;
  254. if (unlikely(!peer)) {
  255. if (peer_id != HTT_INVALID_PEER) {
  256. vdev_id = DP_PEER_METADATA_ID_GET(
  257. mpdu_desc_info.peer_meta_data);
  258. QDF_TRACE(QDF_MODULE_ID_DP,
  259. QDF_TRACE_LEVEL_DEBUG,
  260. FL("PeerID %d not found use vdevID %d"),
  261. peer_id, vdev_id);
  262. vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc,
  263. vdev_id);
  264. } else {
  265. QDF_TRACE(QDF_MODULE_ID_DP,
  266. QDF_TRACE_LEVEL_DEBUG,
  267. FL("Invalid PeerID %d"),
  268. peer_id);
  269. return NULL;
  270. }
  271. } else {
  272. vdev = peer->vdev;
  273. }
  274. return vdev;
  275. }
  276. #else
  277. static inline struct dp_vdev *
  278. dp_get_vdev_from_peer(struct dp_soc *soc,
  279. uint16_t peer_id,
  280. struct dp_peer *peer,
  281. struct hal_rx_mpdu_desc_info mpdu_desc_info)
  282. {
  283. if (unlikely(!peer)) {
  284. QDF_TRACE(QDF_MODULE_ID_DP,
  285. QDF_TRACE_LEVEL_DEBUG,
  286. FL("Peer not found for peerID %d"),
  287. peer_id);
  288. return NULL;
  289. } else {
  290. return peer->vdev;
  291. }
  292. }
  293. #endif
  294. /**
  295. * dp_rx_da_learn() - Add AST entry based on DA lookup
  296. * This is a WAR for HK 1.0 and will
  297. * be removed in HK 2.0
  298. *
  299. * @soc: core txrx main context
  300. * @rx_tlv_hdr : start address of rx tlvs
  301. * @ta_peer : Transmitter peer entry
  302. * @nbuf : nbuf to retrieve destination mac for which AST will be added
  303. *
  304. */
  305. #ifdef FEATURE_WDS
  306. static void
  307. dp_rx_da_learn(struct dp_soc *soc,
  308. uint8_t *rx_tlv_hdr,
  309. struct dp_peer *ta_peer,
  310. qdf_nbuf_t nbuf)
  311. {
  312. /* For HKv2 DA port learing is not needed */
  313. if (qdf_likely(soc->ast_override_support))
  314. return;
  315. if (qdf_unlikely(!ta_peer))
  316. return;
  317. if (qdf_unlikely(ta_peer->vdev->opmode != wlan_op_mode_ap))
  318. return;
  319. if (qdf_unlikely(!hal_rx_msdu_end_da_is_valid_get(rx_tlv_hdr) &&
  320. !hal_rx_msdu_end_da_is_mcbc_get(rx_tlv_hdr))) {
  321. dp_peer_add_ast(soc,
  322. ta_peer,
  323. qdf_nbuf_data(nbuf),
  324. CDP_TXRX_AST_TYPE_DA,
  325. IEEE80211_NODE_F_WDS_HM);
  326. }
  327. }
  328. #else
  329. static void
  330. dp_rx_da_learn(struct dp_soc *soc,
  331. uint8_t *rx_tlv_hdr,
  332. struct dp_peer *ta_peer,
  333. qdf_nbuf_t nbuf)
  334. {
  335. }
  336. #endif
  337. /**
  338. * dp_rx_intrabss_fwd() - Implements the Intra-BSS forwarding logic
  339. *
  340. * @soc: core txrx main context
  341. * @ta_peer : source peer entry
  342. * @rx_tlv_hdr : start address of rx tlvs
  343. * @nbuf : nbuf that has to be intrabss forwarded
  344. *
  345. * Return: bool: true if it is forwarded else false
  346. */
  347. static bool
  348. dp_rx_intrabss_fwd(struct dp_soc *soc,
  349. struct dp_peer *ta_peer,
  350. uint8_t *rx_tlv_hdr,
  351. qdf_nbuf_t nbuf)
  352. {
  353. uint16_t da_idx;
  354. uint16_t len;
  355. struct dp_peer *da_peer;
  356. struct dp_ast_entry *ast_entry;
  357. qdf_nbuf_t nbuf_copy;
  358. /* check if the destination peer is available in peer table
  359. * and also check if the source peer and destination peer
  360. * belong to the same vap and destination peer is not bss peer.
  361. */
  362. if ((hal_rx_msdu_end_da_is_valid_get(rx_tlv_hdr) &&
  363. !hal_rx_msdu_end_da_is_mcbc_get(rx_tlv_hdr))) {
  364. da_idx = hal_rx_msdu_end_da_idx_get(soc->hal_soc, rx_tlv_hdr);
  365. ast_entry = soc->ast_table[da_idx];
  366. if (!ast_entry)
  367. return false;
  368. if (ast_entry->type == CDP_TXRX_AST_TYPE_DA) {
  369. ast_entry->is_active = TRUE;
  370. return false;
  371. }
  372. da_peer = ast_entry->peer;
  373. if (!da_peer)
  374. return false;
  375. /* TA peer cannot be same as peer(DA) on which AST is present
  376. * this indicates a change in topology and that AST entries
  377. * are yet to be updated.
  378. */
  379. if (da_peer == ta_peer)
  380. return false;
  381. if (da_peer->vdev == ta_peer->vdev && !da_peer->bss_peer) {
  382. memset(nbuf->cb, 0x0, sizeof(nbuf->cb));
  383. len = qdf_nbuf_len(nbuf);
  384. /* linearize the nbuf just before we send to
  385. * dp_tx_send()
  386. */
  387. if (qdf_unlikely(qdf_nbuf_get_ext_list(nbuf))) {
  388. if (qdf_nbuf_linearize(nbuf) == -ENOMEM)
  389. return false;
  390. nbuf = qdf_nbuf_unshare(nbuf);
  391. if (!nbuf) {
  392. DP_STATS_INC_PKT(ta_peer,
  393. rx.intra_bss.fail,
  394. 1,
  395. len);
  396. /* return true even though the pkt is
  397. * not forwarded. Basically skb_unshare
  398. * failed and we want to continue with
  399. * next nbuf.
  400. */
  401. return true;
  402. }
  403. }
  404. if (!dp_tx_send(ta_peer->vdev, nbuf)) {
  405. DP_STATS_INC_PKT(ta_peer, rx.intra_bss.pkts, 1,
  406. len);
  407. return true;
  408. } else {
  409. DP_STATS_INC_PKT(ta_peer, rx.intra_bss.fail, 1,
  410. len);
  411. return false;
  412. }
  413. }
  414. }
  415. /* if it is a broadcast pkt (eg: ARP) and it is not its own
  416. * source, then clone the pkt and send the cloned pkt for
  417. * intra BSS forwarding and original pkt up the network stack
  418. * Note: how do we handle multicast pkts. do we forward
  419. * all multicast pkts as is or let a higher layer module
  420. * like igmpsnoop decide whether to forward or not with
  421. * Mcast enhancement.
  422. */
  423. else if (qdf_unlikely((hal_rx_msdu_end_da_is_mcbc_get(rx_tlv_hdr) &&
  424. !ta_peer->bss_peer))) {
  425. nbuf_copy = qdf_nbuf_copy(nbuf);
  426. if (!nbuf_copy)
  427. return false;
  428. memset(nbuf_copy->cb, 0x0, sizeof(nbuf_copy->cb));
  429. len = qdf_nbuf_len(nbuf_copy);
  430. if (dp_tx_send(ta_peer->vdev, nbuf_copy)) {
  431. DP_STATS_INC_PKT(ta_peer, rx.intra_bss.fail, 1, len);
  432. qdf_nbuf_free(nbuf_copy);
  433. } else {
  434. DP_STATS_INC_PKT(ta_peer, rx.intra_bss.pkts, 1, len);
  435. }
  436. }
  437. /* return false as we have to still send the original pkt
  438. * up the stack
  439. */
  440. return false;
  441. }
  442. #ifdef MESH_MODE_SUPPORT
  443. /**
  444. * dp_rx_fill_mesh_stats() - Fills the mesh per packet receive stats
  445. *
  446. * @vdev: DP Virtual device handle
  447. * @nbuf: Buffer pointer
  448. * @rx_tlv_hdr: start of rx tlv header
  449. * @peer: pointer to peer
  450. *
  451. * This function allocated memory for mesh receive stats and fill the
  452. * required stats. Stores the memory address in skb cb.
  453. *
  454. * Return: void
  455. */
  456. void dp_rx_fill_mesh_stats(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  457. uint8_t *rx_tlv_hdr, struct dp_peer *peer)
  458. {
  459. struct mesh_recv_hdr_s *rx_info = NULL;
  460. uint32_t pkt_type;
  461. uint32_t nss;
  462. uint32_t rate_mcs;
  463. uint32_t bw;
  464. /* fill recv mesh stats */
  465. rx_info = qdf_mem_malloc(sizeof(struct mesh_recv_hdr_s));
  466. /* upper layers are resposible to free this memory */
  467. if (rx_info == NULL) {
  468. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  469. "Memory allocation failed for mesh rx stats");
  470. DP_STATS_INC(vdev->pdev, mesh_mem_alloc, 1);
  471. return;
  472. }
  473. rx_info->rs_flags = MESH_RXHDR_VER1;
  474. if (qdf_nbuf_is_rx_chfrag_start(nbuf))
  475. rx_info->rs_flags |= MESH_RX_FIRST_MSDU;
  476. if (qdf_nbuf_is_rx_chfrag_end(nbuf))
  477. rx_info->rs_flags |= MESH_RX_LAST_MSDU;
  478. if (hal_rx_attn_msdu_get_is_decrypted(rx_tlv_hdr)) {
  479. rx_info->rs_flags |= MESH_RX_DECRYPTED;
  480. rx_info->rs_keyix = hal_rx_msdu_get_keyid(rx_tlv_hdr);
  481. if (vdev->osif_get_key)
  482. vdev->osif_get_key(vdev->osif_vdev,
  483. &rx_info->rs_decryptkey[0],
  484. &peer->mac_addr.raw[0],
  485. rx_info->rs_keyix);
  486. }
  487. rx_info->rs_rssi = hal_rx_msdu_start_get_rssi(rx_tlv_hdr);
  488. rx_info->rs_channel = hal_rx_msdu_start_get_freq(rx_tlv_hdr);
  489. pkt_type = hal_rx_msdu_start_get_pkt_type(rx_tlv_hdr);
  490. rate_mcs = hal_rx_msdu_start_rate_mcs_get(rx_tlv_hdr);
  491. bw = hal_rx_msdu_start_bw_get(rx_tlv_hdr);
  492. nss = hal_rx_msdu_start_nss_get(vdev->pdev->soc->hal_soc, rx_tlv_hdr);
  493. rx_info->rs_ratephy1 = rate_mcs | (nss << 0x8) | (pkt_type << 16) |
  494. (bw << 24);
  495. qdf_nbuf_set_rx_fctx_type(nbuf, (void *)rx_info, CB_FTYPE_MESH_RX_INFO);
  496. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_MED,
  497. FL("Mesh rx stats: flags %x, rssi %x, chn %x, rate %x, kix %x"),
  498. rx_info->rs_flags,
  499. rx_info->rs_rssi,
  500. rx_info->rs_channel,
  501. rx_info->rs_ratephy1,
  502. rx_info->rs_keyix);
  503. }
  504. /**
  505. * dp_rx_filter_mesh_packets() - Filters mesh unwanted packets
  506. *
  507. * @vdev: DP Virtual device handle
  508. * @nbuf: Buffer pointer
  509. * @rx_tlv_hdr: start of rx tlv header
  510. *
  511. * This checks if the received packet is matching any filter out
  512. * catogery and and drop the packet if it matches.
  513. *
  514. * Return: status(0 indicates drop, 1 indicate to no drop)
  515. */
  516. QDF_STATUS dp_rx_filter_mesh_packets(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  517. uint8_t *rx_tlv_hdr)
  518. {
  519. union dp_align_mac_addr mac_addr;
  520. if (qdf_unlikely(vdev->mesh_rx_filter)) {
  521. if (vdev->mesh_rx_filter & MESH_FILTER_OUT_FROMDS)
  522. if (hal_rx_mpdu_get_fr_ds(rx_tlv_hdr))
  523. return QDF_STATUS_SUCCESS;
  524. if (vdev->mesh_rx_filter & MESH_FILTER_OUT_TODS)
  525. if (hal_rx_mpdu_get_to_ds(rx_tlv_hdr))
  526. return QDF_STATUS_SUCCESS;
  527. if (vdev->mesh_rx_filter & MESH_FILTER_OUT_NODS)
  528. if (!hal_rx_mpdu_get_fr_ds(rx_tlv_hdr)
  529. && !hal_rx_mpdu_get_to_ds(rx_tlv_hdr))
  530. return QDF_STATUS_SUCCESS;
  531. if (vdev->mesh_rx_filter & MESH_FILTER_OUT_RA) {
  532. if (hal_rx_mpdu_get_addr1(rx_tlv_hdr,
  533. &mac_addr.raw[0]))
  534. return QDF_STATUS_E_FAILURE;
  535. if (!qdf_mem_cmp(&mac_addr.raw[0],
  536. &vdev->mac_addr.raw[0],
  537. DP_MAC_ADDR_LEN))
  538. return QDF_STATUS_SUCCESS;
  539. }
  540. if (vdev->mesh_rx_filter & MESH_FILTER_OUT_TA) {
  541. if (hal_rx_mpdu_get_addr2(rx_tlv_hdr,
  542. &mac_addr.raw[0]))
  543. return QDF_STATUS_E_FAILURE;
  544. if (!qdf_mem_cmp(&mac_addr.raw[0],
  545. &vdev->mac_addr.raw[0],
  546. DP_MAC_ADDR_LEN))
  547. return QDF_STATUS_SUCCESS;
  548. }
  549. }
  550. return QDF_STATUS_E_FAILURE;
  551. }
  552. #else
  553. void dp_rx_fill_mesh_stats(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  554. uint8_t *rx_tlv_hdr, struct dp_peer *peer)
  555. {
  556. }
  557. QDF_STATUS dp_rx_filter_mesh_packets(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  558. uint8_t *rx_tlv_hdr)
  559. {
  560. return QDF_STATUS_E_FAILURE;
  561. }
  562. #endif
  563. #ifdef CONFIG_WIN
  564. /**
  565. * dp_rx_nac_filter(): Function to perform filtering of non-associated
  566. * clients
  567. * @pdev: DP pdev handle
  568. * @rx_pkt_hdr: Rx packet Header
  569. *
  570. * return: dp_vdev*
  571. */
  572. static
  573. struct dp_vdev *dp_rx_nac_filter(struct dp_pdev *pdev,
  574. uint8_t *rx_pkt_hdr)
  575. {
  576. struct ieee80211_frame *wh;
  577. struct dp_neighbour_peer *peer = NULL;
  578. wh = (struct ieee80211_frame *)rx_pkt_hdr;
  579. if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) != IEEE80211_FC1_DIR_TODS)
  580. return NULL;
  581. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  582. TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
  583. neighbour_peer_list_elem) {
  584. if (qdf_mem_cmp(&peer->neighbour_peers_macaddr.raw[0],
  585. wh->i_addr2, DP_MAC_ADDR_LEN) == 0) {
  586. QDF_TRACE(
  587. QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  588. FL("NAC configuration matched for mac-%2x:%2x:%2x:%2x:%2x:%2x"),
  589. peer->neighbour_peers_macaddr.raw[0],
  590. peer->neighbour_peers_macaddr.raw[1],
  591. peer->neighbour_peers_macaddr.raw[2],
  592. peer->neighbour_peers_macaddr.raw[3],
  593. peer->neighbour_peers_macaddr.raw[4],
  594. peer->neighbour_peers_macaddr.raw[5]);
  595. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  596. return pdev->monitor_vdev;
  597. }
  598. }
  599. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  600. return NULL;
  601. }
  602. /**
  603. * dp_rx_process_invalid_peer(): Function to pass invalid peer list to umac
  604. * @soc: DP SOC handle
  605. * @mpdu: mpdu for which peer is invalid
  606. *
  607. * return: integer type
  608. */
  609. uint8_t dp_rx_process_invalid_peer(struct dp_soc *soc, qdf_nbuf_t mpdu)
  610. {
  611. struct dp_invalid_peer_msg msg;
  612. struct dp_vdev *vdev = NULL;
  613. struct dp_pdev *pdev = NULL;
  614. struct ieee80211_frame *wh;
  615. uint8_t i;
  616. qdf_nbuf_t curr_nbuf, next_nbuf;
  617. uint8_t *rx_tlv_hdr = qdf_nbuf_data(mpdu);
  618. uint8_t *rx_pkt_hdr = hal_rx_pkt_hdr_get(rx_tlv_hdr);
  619. wh = (struct ieee80211_frame *)rx_pkt_hdr;
  620. if (!DP_FRAME_IS_DATA(wh)) {
  621. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  622. "NAWDS valid only for data frames");
  623. goto free;
  624. }
  625. if (qdf_nbuf_len(mpdu) < sizeof(struct ieee80211_frame)) {
  626. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  627. "Invalid nbuf length");
  628. goto free;
  629. }
  630. for (i = 0; i < MAX_PDEV_CNT; i++) {
  631. pdev = soc->pdev_list[i];
  632. if (!pdev) {
  633. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  634. "PDEV not found");
  635. continue;
  636. }
  637. if (pdev->filter_neighbour_peers) {
  638. /* Next Hop scenario not yet handle */
  639. vdev = dp_rx_nac_filter(pdev, rx_pkt_hdr);
  640. if (vdev) {
  641. dp_rx_mon_deliver(soc, i,
  642. pdev->invalid_peer_head_msdu,
  643. pdev->invalid_peer_tail_msdu);
  644. pdev->invalid_peer_head_msdu = NULL;
  645. pdev->invalid_peer_tail_msdu = NULL;
  646. return 0;
  647. }
  648. }
  649. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  650. if (qdf_mem_cmp(wh->i_addr1, vdev->mac_addr.raw,
  651. DP_MAC_ADDR_LEN) == 0) {
  652. goto out;
  653. }
  654. }
  655. }
  656. if (!vdev) {
  657. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  658. "VDEV not found");
  659. goto free;
  660. }
  661. out:
  662. msg.wh = wh;
  663. qdf_nbuf_pull_head(mpdu, RX_PKT_TLVS_LEN);
  664. msg.nbuf = mpdu;
  665. msg.vdev_id = vdev->vdev_id;
  666. if (pdev->soc->cdp_soc.ol_ops->rx_invalid_peer)
  667. pdev->soc->cdp_soc.ol_ops->rx_invalid_peer(pdev->ctrl_pdev,
  668. &msg);
  669. free:
  670. /* Drop and free packet */
  671. curr_nbuf = mpdu;
  672. while (curr_nbuf) {
  673. next_nbuf = qdf_nbuf_next(curr_nbuf);
  674. qdf_nbuf_free(curr_nbuf);
  675. curr_nbuf = next_nbuf;
  676. }
  677. return 0;
  678. }
  679. /**
  680. * dp_rx_process_invalid_peer_wrapper(): Function to wrap invalid peer handler
  681. * @soc: DP SOC handle
  682. * @mpdu: mpdu for which peer is invalid
  683. * @mpdu_done: if an mpdu is completed
  684. *
  685. * return: integer type
  686. */
  687. void dp_rx_process_invalid_peer_wrapper(struct dp_soc *soc,
  688. qdf_nbuf_t mpdu, bool mpdu_done)
  689. {
  690. /* Only trigger the process when mpdu is completed */
  691. if (mpdu_done)
  692. dp_rx_process_invalid_peer(soc, mpdu);
  693. }
  694. #else
  695. uint8_t dp_rx_process_invalid_peer(struct dp_soc *soc, qdf_nbuf_t mpdu)
  696. {
  697. qdf_nbuf_t curr_nbuf, next_nbuf;
  698. struct dp_pdev *pdev;
  699. uint8_t i;
  700. struct dp_vdev *vdev = NULL;
  701. struct ieee80211_frame *wh;
  702. uint8_t *rx_tlv_hdr = qdf_nbuf_data(mpdu);
  703. uint8_t *rx_pkt_hdr = hal_rx_pkt_hdr_get(rx_tlv_hdr);
  704. wh = (struct ieee80211_frame *)rx_pkt_hdr;
  705. if (!DP_FRAME_IS_DATA(wh)) {
  706. QDF_TRACE_ERROR_RL(QDF_MODULE_ID_DP,
  707. "only for data frames");
  708. goto free;
  709. }
  710. if (qdf_nbuf_len(mpdu) < sizeof(struct ieee80211_frame)) {
  711. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  712. "Invalid nbuf length");
  713. goto free;
  714. }
  715. for (i = 0; i < MAX_PDEV_CNT; i++) {
  716. pdev = soc->pdev_list[i];
  717. if (!pdev) {
  718. QDF_TRACE(QDF_MODULE_ID_DP,
  719. QDF_TRACE_LEVEL_ERROR,
  720. "PDEV not found");
  721. continue;
  722. }
  723. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  724. DP_PDEV_ITERATE_VDEV_LIST(pdev, vdev) {
  725. if (qdf_mem_cmp(wh->i_addr1, vdev->mac_addr.raw,
  726. DP_MAC_ADDR_LEN) == 0) {
  727. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  728. goto out;
  729. }
  730. }
  731. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  732. }
  733. if (NULL == vdev) {
  734. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  735. "VDEV not found");
  736. goto free;
  737. }
  738. out:
  739. if (soc->cdp_soc.ol_ops->rx_invalid_peer)
  740. soc->cdp_soc.ol_ops->rx_invalid_peer(vdev->vdev_id, wh);
  741. free:
  742. /* reset the head and tail pointers */
  743. for (i = 0; i < MAX_PDEV_CNT; i++) {
  744. pdev = soc->pdev_list[i];
  745. if (!pdev) {
  746. QDF_TRACE(QDF_MODULE_ID_DP,
  747. QDF_TRACE_LEVEL_ERROR,
  748. "PDEV not found");
  749. continue;
  750. }
  751. pdev->invalid_peer_head_msdu = NULL;
  752. pdev->invalid_peer_tail_msdu = NULL;
  753. }
  754. /* Drop and free packet */
  755. curr_nbuf = mpdu;
  756. while (curr_nbuf) {
  757. next_nbuf = qdf_nbuf_next(curr_nbuf);
  758. DP_STATS_INC_PKT(soc, rx.err.rx_invalid_peer, 1,
  759. qdf_nbuf_len(curr_nbuf));
  760. qdf_nbuf_free(curr_nbuf);
  761. curr_nbuf = next_nbuf;
  762. }
  763. return 0;
  764. }
  765. void dp_rx_process_invalid_peer_wrapper(struct dp_soc *soc,
  766. qdf_nbuf_t mpdu, bool mpdu_done)
  767. {
  768. /* Process the nbuf */
  769. dp_rx_process_invalid_peer(soc, mpdu);
  770. }
  771. #endif
  772. #ifdef RECEIVE_OFFLOAD
  773. /**
  774. * dp_rx_print_offload_info() - Print offload info from RX TLV
  775. * @rx_tlv: RX TLV for which offload information is to be printed
  776. *
  777. * Return: None
  778. */
  779. static void dp_rx_print_offload_info(uint8_t *rx_tlv)
  780. {
  781. dp_debug("----------------------RX DESC LRO/GRO----------------------");
  782. dp_debug("lro_eligible 0x%x", HAL_RX_TLV_GET_LRO_ELIGIBLE(rx_tlv));
  783. dp_debug("pure_ack 0x%x", HAL_RX_TLV_GET_TCP_PURE_ACK(rx_tlv));
  784. dp_debug("chksum 0x%x", HAL_RX_TLV_GET_TCP_CHKSUM(rx_tlv));
  785. dp_debug("TCP seq num 0x%x", HAL_RX_TLV_GET_TCP_SEQ(rx_tlv));
  786. dp_debug("TCP ack num 0x%x", HAL_RX_TLV_GET_TCP_ACK(rx_tlv));
  787. dp_debug("TCP window 0x%x", HAL_RX_TLV_GET_TCP_WIN(rx_tlv));
  788. dp_debug("TCP protocol 0x%x", HAL_RX_TLV_GET_TCP_PROTO(rx_tlv));
  789. dp_debug("TCP offset 0x%x", HAL_RX_TLV_GET_TCP_OFFSET(rx_tlv));
  790. dp_debug("toeplitz 0x%x", HAL_RX_TLV_GET_FLOW_ID_TOEPLITZ(rx_tlv));
  791. dp_debug("---------------------------------------------------------");
  792. }
  793. /**
  794. * dp_rx_fill_gro_info() - Fill GRO info from RX TLV into skb->cb
  795. * @soc: DP SOC handle
  796. * @rx_tlv: RX TLV received for the msdu
  797. * @msdu: msdu for which GRO info needs to be filled
  798. *
  799. * Return: None
  800. */
  801. static
  802. void dp_rx_fill_gro_info(struct dp_soc *soc, uint8_t *rx_tlv,
  803. qdf_nbuf_t msdu)
  804. {
  805. if (!wlan_cfg_is_gro_enabled(soc->wlan_cfg_ctx))
  806. return;
  807. /* Filling up RX offload info only for TCP packets */
  808. if (!HAL_RX_TLV_GET_TCP_PROTO(rx_tlv))
  809. return;
  810. QDF_NBUF_CB_RX_LRO_ELIGIBLE(msdu) =
  811. HAL_RX_TLV_GET_LRO_ELIGIBLE(rx_tlv);
  812. QDF_NBUF_CB_RX_TCP_PURE_ACK(msdu) =
  813. HAL_RX_TLV_GET_TCP_PURE_ACK(rx_tlv);
  814. QDF_NBUF_CB_RX_TCP_CHKSUM(msdu) =
  815. HAL_RX_TLV_GET_TCP_CHKSUM(rx_tlv);
  816. QDF_NBUF_CB_RX_TCP_SEQ_NUM(msdu) =
  817. HAL_RX_TLV_GET_TCP_SEQ(rx_tlv);
  818. QDF_NBUF_CB_RX_TCP_ACK_NUM(msdu) =
  819. HAL_RX_TLV_GET_TCP_ACK(rx_tlv);
  820. QDF_NBUF_CB_RX_TCP_WIN(msdu) =
  821. HAL_RX_TLV_GET_TCP_WIN(rx_tlv);
  822. QDF_NBUF_CB_RX_TCP_PROTO(msdu) =
  823. HAL_RX_TLV_GET_TCP_PROTO(rx_tlv);
  824. QDF_NBUF_CB_RX_IPV6_PROTO(msdu) =
  825. HAL_RX_TLV_GET_IPV6(rx_tlv);
  826. QDF_NBUF_CB_RX_TCP_OFFSET(msdu) =
  827. HAL_RX_TLV_GET_TCP_OFFSET(rx_tlv);
  828. QDF_NBUF_CB_RX_FLOW_ID(msdu) =
  829. HAL_RX_TLV_GET_FLOW_ID_TOEPLITZ(rx_tlv);
  830. dp_rx_print_offload_info(rx_tlv);
  831. }
  832. #else
  833. static void dp_rx_fill_gro_info(struct dp_soc *soc, uint8_t *rx_tlv,
  834. qdf_nbuf_t msdu)
  835. {
  836. }
  837. #endif /* RECEIVE_OFFLOAD */
  838. /**
  839. * dp_rx_adjust_nbuf_len() - set appropriate msdu length in nbuf.
  840. *
  841. * @nbuf: pointer to msdu.
  842. * @mpdu_len: mpdu length
  843. *
  844. * Return: returns true if nbuf is last msdu of mpdu else retuns false.
  845. */
  846. static inline bool dp_rx_adjust_nbuf_len(qdf_nbuf_t nbuf, uint16_t *mpdu_len)
  847. {
  848. bool last_nbuf;
  849. if (*mpdu_len >= (RX_BUFFER_SIZE - RX_PKT_TLVS_LEN)) {
  850. qdf_nbuf_set_pktlen(nbuf, RX_BUFFER_SIZE);
  851. last_nbuf = false;
  852. } else {
  853. qdf_nbuf_set_pktlen(nbuf, (*mpdu_len + RX_PKT_TLVS_LEN));
  854. last_nbuf = true;
  855. }
  856. *mpdu_len -= (RX_BUFFER_SIZE - RX_PKT_TLVS_LEN);
  857. return last_nbuf;
  858. }
  859. /**
  860. * dp_rx_sg_create() - create a frag_list for MSDUs which are spread across
  861. * multiple nbufs.
  862. * @nbuf: pointer to the first msdu of an amsdu.
  863. * @rx_tlv_hdr: pointer to the start of RX TLV headers.
  864. *
  865. *
  866. * This function implements the creation of RX frag_list for cases
  867. * where an MSDU is spread across multiple nbufs.
  868. *
  869. * Return: returns the head nbuf which contains complete frag_list.
  870. */
  871. qdf_nbuf_t dp_rx_sg_create(qdf_nbuf_t nbuf, uint8_t *rx_tlv_hdr)
  872. {
  873. qdf_nbuf_t parent, next, frag_list;
  874. uint16_t frag_list_len = 0;
  875. uint16_t mpdu_len;
  876. bool last_nbuf;
  877. mpdu_len = hal_rx_msdu_start_msdu_len_get(rx_tlv_hdr);
  878. /*
  879. * this is a case where the complete msdu fits in one single nbuf.
  880. * in this case HW sets both start and end bit and we only need to
  881. * reset these bits for RAW mode simulator to decap the pkt
  882. */
  883. if (qdf_nbuf_is_rx_chfrag_start(nbuf) &&
  884. qdf_nbuf_is_rx_chfrag_end(nbuf)) {
  885. qdf_nbuf_set_pktlen(nbuf, mpdu_len + RX_PKT_TLVS_LEN);
  886. qdf_nbuf_pull_head(nbuf, RX_PKT_TLVS_LEN);
  887. return nbuf;
  888. }
  889. /*
  890. * This is a case where we have multiple msdus (A-MSDU) spread across
  891. * multiple nbufs. here we create a fraglist out of these nbufs.
  892. *
  893. * the moment we encounter a nbuf with continuation bit set we
  894. * know for sure we have an MSDU which is spread across multiple
  895. * nbufs. We loop through and reap nbufs till we reach last nbuf.
  896. */
  897. parent = nbuf;
  898. frag_list = nbuf->next;
  899. nbuf = nbuf->next;
  900. /*
  901. * set the start bit in the first nbuf we encounter with continuation
  902. * bit set. This has the proper mpdu length set as it is the first
  903. * msdu of the mpdu. this becomes the parent nbuf and the subsequent
  904. * nbufs will form the frag_list of the parent nbuf.
  905. */
  906. qdf_nbuf_set_rx_chfrag_start(parent, 1);
  907. last_nbuf = dp_rx_adjust_nbuf_len(parent, &mpdu_len);
  908. /*
  909. * this is where we set the length of the fragments which are
  910. * associated to the parent nbuf. We iterate through the frag_list
  911. * till we hit the last_nbuf of the list.
  912. */
  913. do {
  914. last_nbuf = dp_rx_adjust_nbuf_len(nbuf, &mpdu_len);
  915. qdf_nbuf_pull_head(nbuf, RX_PKT_TLVS_LEN);
  916. frag_list_len += qdf_nbuf_len(nbuf);
  917. if (last_nbuf) {
  918. next = nbuf->next;
  919. nbuf->next = NULL;
  920. break;
  921. }
  922. nbuf = nbuf->next;
  923. } while (!last_nbuf);
  924. qdf_nbuf_set_rx_chfrag_start(nbuf, 0);
  925. qdf_nbuf_append_ext_list(parent, frag_list, frag_list_len);
  926. parent->next = next;
  927. qdf_nbuf_pull_head(parent, RX_PKT_TLVS_LEN);
  928. return parent;
  929. }
  930. static inline void dp_rx_deliver_to_stack(struct dp_vdev *vdev,
  931. struct dp_peer *peer,
  932. qdf_nbuf_t nbuf_head,
  933. qdf_nbuf_t nbuf_tail)
  934. {
  935. /*
  936. * highly unlikely to have a vdev without a registered rx
  937. * callback function. if so let us free the nbuf_list.
  938. */
  939. if (qdf_unlikely(!vdev->osif_rx)) {
  940. qdf_nbuf_t nbuf;
  941. do {
  942. nbuf = nbuf_head;
  943. nbuf_head = nbuf_head->next;
  944. qdf_nbuf_free(nbuf);
  945. } while (nbuf_head);
  946. return;
  947. }
  948. if (qdf_unlikely(vdev->rx_decap_type == htt_cmn_pkt_type_raw) ||
  949. (vdev->rx_decap_type == htt_cmn_pkt_type_native_wifi)) {
  950. vdev->osif_rsim_rx_decap(vdev->osif_vdev, &nbuf_head,
  951. &nbuf_tail, (struct cdp_peer *) peer);
  952. }
  953. vdev->osif_rx(vdev->osif_vdev, nbuf_head);
  954. }
  955. /**
  956. * dp_rx_cksum_offload() - set the nbuf checksum as defined by hardware.
  957. * @nbuf: pointer to the first msdu of an amsdu.
  958. * @rx_tlv_hdr: pointer to the start of RX TLV headers.
  959. *
  960. * The ipsumed field of the skb is set based on whether HW validated the
  961. * IP/TCP/UDP checksum.
  962. *
  963. * Return: void
  964. */
  965. static inline void dp_rx_cksum_offload(struct dp_pdev *pdev,
  966. qdf_nbuf_t nbuf,
  967. uint8_t *rx_tlv_hdr)
  968. {
  969. qdf_nbuf_rx_cksum_t cksum = {0};
  970. bool ip_csum_err = hal_rx_attn_ip_cksum_fail_get(rx_tlv_hdr);
  971. bool tcp_udp_csum_er = hal_rx_attn_tcp_udp_cksum_fail_get(rx_tlv_hdr);
  972. if (qdf_likely(!ip_csum_err && !tcp_udp_csum_er)) {
  973. cksum.l4_result = QDF_NBUF_RX_CKSUM_TCP_UDP_UNNECESSARY;
  974. qdf_nbuf_set_rx_cksum(nbuf, &cksum);
  975. } else {
  976. DP_STATS_INCC(pdev, err.ip_csum_err, 1, ip_csum_err);
  977. DP_STATS_INCC(pdev, err.tcp_udp_csum_err, 1, tcp_udp_csum_er);
  978. }
  979. }
  980. /**
  981. * dp_rx_msdu_stats_update() - update per msdu stats.
  982. * @soc: core txrx main context
  983. * @nbuf: pointer to the first msdu of an amsdu.
  984. * @rx_tlv_hdr: pointer to the start of RX TLV headers.
  985. * @peer: pointer to the peer object.
  986. * @ring_id: reo dest ring number on which pkt is reaped.
  987. *
  988. * update all the per msdu stats for that nbuf.
  989. * Return: void
  990. */
  991. static void dp_rx_msdu_stats_update(struct dp_soc *soc,
  992. qdf_nbuf_t nbuf,
  993. uint8_t *rx_tlv_hdr,
  994. struct dp_peer *peer,
  995. uint8_t ring_id)
  996. {
  997. bool is_ampdu, is_not_amsdu;
  998. uint16_t peer_id;
  999. uint32_t sgi, mcs, tid, nss, bw, reception_type, pkt_type;
  1000. struct dp_vdev *vdev = peer->vdev;
  1001. struct ether_header *eh;
  1002. uint16_t msdu_len = qdf_nbuf_len(nbuf);
  1003. peer_id = DP_PEER_METADATA_PEER_ID_GET(
  1004. hal_rx_mpdu_peer_meta_data_get(rx_tlv_hdr));
  1005. is_not_amsdu = qdf_nbuf_is_rx_chfrag_start(nbuf) &
  1006. qdf_nbuf_is_rx_chfrag_end(nbuf);
  1007. DP_STATS_INC_PKT(peer, rx.rcvd_reo[ring_id], 1, msdu_len);
  1008. DP_STATS_INCC(peer, rx.non_amsdu_cnt, 1, is_not_amsdu);
  1009. DP_STATS_INCC(peer, rx.amsdu_cnt, 1, !is_not_amsdu);
  1010. if (qdf_unlikely(hal_rx_msdu_end_da_is_mcbc_get(rx_tlv_hdr) &&
  1011. (vdev->rx_decap_type == htt_cmn_pkt_type_ethernet))) {
  1012. eh = (struct ether_header *)qdf_nbuf_data(nbuf);
  1013. DP_STATS_INC_PKT(peer, rx.multicast, 1, msdu_len);
  1014. if (IEEE80211_IS_BROADCAST(eh->ether_dhost)) {
  1015. DP_STATS_INC_PKT(peer, rx.bcast, 1, msdu_len);
  1016. }
  1017. }
  1018. /*
  1019. * currently we can return from here as we have similar stats
  1020. * updated at per ppdu level instead of msdu level
  1021. */
  1022. if (!soc->process_rx_status)
  1023. return;
  1024. is_ampdu = hal_rx_mpdu_info_ampdu_flag_get(rx_tlv_hdr);
  1025. DP_STATS_INCC(peer, rx.ampdu_cnt, 1, is_ampdu);
  1026. DP_STATS_INCC(peer, rx.non_ampdu_cnt, 1, !(is_ampdu));
  1027. sgi = hal_rx_msdu_start_sgi_get(rx_tlv_hdr);
  1028. mcs = hal_rx_msdu_start_rate_mcs_get(rx_tlv_hdr);
  1029. tid = hal_rx_mpdu_start_tid_get(soc->hal_soc, rx_tlv_hdr);
  1030. bw = hal_rx_msdu_start_bw_get(rx_tlv_hdr);
  1031. reception_type = hal_rx_msdu_start_reception_type_get(soc->hal_soc,
  1032. rx_tlv_hdr);
  1033. nss = hal_rx_msdu_start_nss_get(soc->hal_soc, rx_tlv_hdr);
  1034. pkt_type = hal_rx_msdu_start_get_pkt_type(rx_tlv_hdr);
  1035. /* Save tid to skb->priority */
  1036. DP_RX_TID_SAVE(nbuf, tid);
  1037. DP_STATS_INC(peer, rx.bw[bw], 1);
  1038. DP_STATS_INC(peer, rx.nss[nss], 1);
  1039. DP_STATS_INC(peer, rx.sgi_count[sgi], 1);
  1040. DP_STATS_INCC(peer, rx.err.mic_err, 1,
  1041. hal_rx_mpdu_end_mic_err_get(rx_tlv_hdr));
  1042. DP_STATS_INCC(peer, rx.err.decrypt_err, 1,
  1043. hal_rx_mpdu_end_decrypt_err_get(rx_tlv_hdr));
  1044. DP_STATS_INC(peer, rx.wme_ac_type[TID_TO_WME_AC(tid)], 1);
  1045. DP_STATS_INC(peer, rx.reception_type[reception_type], 1);
  1046. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  1047. ((mcs >= MAX_MCS_11A) && (pkt_type == DOT11_A)));
  1048. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[mcs], 1,
  1049. ((mcs <= MAX_MCS_11A) && (pkt_type == DOT11_A)));
  1050. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  1051. ((mcs >= MAX_MCS_11B) && (pkt_type == DOT11_B)));
  1052. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[mcs], 1,
  1053. ((mcs <= MAX_MCS_11B) && (pkt_type == DOT11_B)));
  1054. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  1055. ((mcs >= MAX_MCS_11A) && (pkt_type == DOT11_N)));
  1056. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[mcs], 1,
  1057. ((mcs <= MAX_MCS_11A) && (pkt_type == DOT11_N)));
  1058. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  1059. ((mcs >= MAX_MCS_11AC) && (pkt_type == DOT11_AC)));
  1060. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[mcs], 1,
  1061. ((mcs <= MAX_MCS_11AC) && (pkt_type == DOT11_AC)));
  1062. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  1063. ((mcs >= MAX_MCS) && (pkt_type == DOT11_AX)));
  1064. DP_STATS_INCC(peer, rx.pkt_type[pkt_type].mcs_count[mcs], 1,
  1065. ((mcs <= MAX_MCS) && (pkt_type == DOT11_AX)));
  1066. if ((soc->process_rx_status) &&
  1067. hal_rx_attn_first_mpdu_get(rx_tlv_hdr)) {
  1068. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  1069. if (!vdev->pdev)
  1070. return;
  1071. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, vdev->pdev->soc,
  1072. &peer->stats, peer_id,
  1073. UPDATE_PEER_STATS,
  1074. vdev->pdev->pdev_id);
  1075. #endif
  1076. }
  1077. }
  1078. #ifdef WDS_VENDOR_EXTENSION
  1079. int dp_wds_rx_policy_check(
  1080. uint8_t *rx_tlv_hdr,
  1081. struct dp_vdev *vdev,
  1082. struct dp_peer *peer,
  1083. int rx_mcast
  1084. )
  1085. {
  1086. struct dp_peer *bss_peer;
  1087. int fr_ds, to_ds, rx_3addr, rx_4addr;
  1088. int rx_policy_ucast, rx_policy_mcast;
  1089. if (vdev->opmode == wlan_op_mode_ap) {
  1090. TAILQ_FOREACH(bss_peer, &vdev->peer_list, peer_list_elem) {
  1091. if (bss_peer->bss_peer) {
  1092. /* if wds policy check is not enabled on this vdev, accept all frames */
  1093. if (!bss_peer->wds_ecm.wds_rx_filter) {
  1094. return 1;
  1095. }
  1096. break;
  1097. }
  1098. }
  1099. rx_policy_ucast = bss_peer->wds_ecm.wds_rx_ucast_4addr;
  1100. rx_policy_mcast = bss_peer->wds_ecm.wds_rx_mcast_4addr;
  1101. } else { /* sta mode */
  1102. if (!peer->wds_ecm.wds_rx_filter) {
  1103. return 1;
  1104. }
  1105. rx_policy_ucast = peer->wds_ecm.wds_rx_ucast_4addr;
  1106. rx_policy_mcast = peer->wds_ecm.wds_rx_mcast_4addr;
  1107. }
  1108. /* ------------------------------------------------
  1109. * self
  1110. * peer- rx rx-
  1111. * wds ucast mcast dir policy accept note
  1112. * ------------------------------------------------
  1113. * 1 1 0 11 x1 1 AP configured to accept ds-to-ds Rx ucast from wds peers, constraint met; so, accept
  1114. * 1 1 0 01 x1 0 AP configured to accept ds-to-ds Rx ucast from wds peers, constraint not met; so, drop
  1115. * 1 1 0 10 x1 0 AP configured to accept ds-to-ds Rx ucast from wds peers, constraint not met; so, drop
  1116. * 1 1 0 00 x1 0 bad frame, won't see it
  1117. * 1 0 1 11 1x 1 AP configured to accept ds-to-ds Rx mcast from wds peers, constraint met; so, accept
  1118. * 1 0 1 01 1x 0 AP configured to accept ds-to-ds Rx mcast from wds peers, constraint not met; so, drop
  1119. * 1 0 1 10 1x 0 AP configured to accept ds-to-ds Rx mcast from wds peers, constraint not met; so, drop
  1120. * 1 0 1 00 1x 0 bad frame, won't see it
  1121. * 1 1 0 11 x0 0 AP configured to accept from-ds Rx ucast from wds peers, constraint not met; so, drop
  1122. * 1 1 0 01 x0 0 AP configured to accept from-ds Rx ucast from wds peers, constraint not met; so, drop
  1123. * 1 1 0 10 x0 1 AP configured to accept from-ds Rx ucast from wds peers, constraint met; so, accept
  1124. * 1 1 0 00 x0 0 bad frame, won't see it
  1125. * 1 0 1 11 0x 0 AP configured to accept from-ds Rx mcast from wds peers, constraint not met; so, drop
  1126. * 1 0 1 01 0x 0 AP configured to accept from-ds Rx mcast from wds peers, constraint not met; so, drop
  1127. * 1 0 1 10 0x 1 AP configured to accept from-ds Rx mcast from wds peers, constraint met; so, accept
  1128. * 1 0 1 00 0x 0 bad frame, won't see it
  1129. *
  1130. * 0 x x 11 xx 0 we only accept td-ds Rx frames from non-wds peers in mode.
  1131. * 0 x x 01 xx 1
  1132. * 0 x x 10 xx 0
  1133. * 0 x x 00 xx 0 bad frame, won't see it
  1134. * ------------------------------------------------
  1135. */
  1136. fr_ds = hal_rx_mpdu_get_fr_ds(rx_tlv_hdr);
  1137. to_ds = hal_rx_mpdu_get_to_ds(rx_tlv_hdr);
  1138. rx_3addr = fr_ds ^ to_ds;
  1139. rx_4addr = fr_ds & to_ds;
  1140. if (vdev->opmode == wlan_op_mode_ap) {
  1141. if ((!peer->wds_enabled && rx_3addr && to_ds) ||
  1142. (peer->wds_enabled && !rx_mcast && (rx_4addr == rx_policy_ucast)) ||
  1143. (peer->wds_enabled && rx_mcast && (rx_4addr == rx_policy_mcast))) {
  1144. return 1;
  1145. }
  1146. } else { /* sta mode */
  1147. if ((!rx_mcast && (rx_4addr == rx_policy_ucast)) ||
  1148. (rx_mcast && (rx_4addr == rx_policy_mcast))) {
  1149. return 1;
  1150. }
  1151. }
  1152. return 0;
  1153. }
  1154. #else
  1155. int dp_wds_rx_policy_check(
  1156. uint8_t *rx_tlv_hdr,
  1157. struct dp_vdev *vdev,
  1158. struct dp_peer *peer,
  1159. int rx_mcast
  1160. )
  1161. {
  1162. return 1;
  1163. }
  1164. #endif
  1165. /**
  1166. * dp_rx_process() - Brain of the Rx processing functionality
  1167. * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
  1168. * @soc: core txrx main context
  1169. * @hal_ring: opaque pointer to the HAL Rx Ring, which will be serviced
  1170. * @reo_ring_num: ring number (0, 1, 2 or 3) of the reo ring.
  1171. * @quota: No. of units (packets) that can be serviced in one shot.
  1172. *
  1173. * This function implements the core of Rx functionality. This is
  1174. * expected to handle only non-error frames.
  1175. *
  1176. * Return: uint32_t: No. of elements processed
  1177. */
  1178. uint32_t dp_rx_process(struct dp_intr *int_ctx, void *hal_ring,
  1179. uint8_t reo_ring_num, uint32_t quota)
  1180. {
  1181. void *hal_soc;
  1182. void *ring_desc;
  1183. struct dp_rx_desc *rx_desc = NULL;
  1184. qdf_nbuf_t nbuf, next;
  1185. union dp_rx_desc_list_elem_t *head[MAX_PDEV_CNT] = { NULL };
  1186. union dp_rx_desc_list_elem_t *tail[MAX_PDEV_CNT] = { NULL };
  1187. uint32_t rx_bufs_used = 0, rx_buf_cookie;
  1188. uint32_t l2_hdr_offset = 0;
  1189. uint16_t msdu_len = 0;
  1190. uint16_t peer_id;
  1191. struct dp_peer *peer = NULL;
  1192. struct dp_vdev *vdev = NULL;
  1193. uint32_t pkt_len = 0;
  1194. struct hal_rx_mpdu_desc_info mpdu_desc_info = { 0 };
  1195. struct hal_rx_msdu_desc_info msdu_desc_info = { 0 };
  1196. enum hal_reo_error_status error;
  1197. uint32_t peer_mdata;
  1198. uint8_t *rx_tlv_hdr;
  1199. uint32_t rx_bufs_reaped[MAX_PDEV_CNT] = { 0 };
  1200. uint8_t mac_id = 0;
  1201. struct dp_pdev *pdev;
  1202. struct dp_srng *dp_rxdma_srng;
  1203. struct rx_desc_pool *rx_desc_pool;
  1204. struct dp_soc *soc = int_ctx->soc;
  1205. uint8_t ring_id = 0;
  1206. uint8_t core_id = 0;
  1207. qdf_nbuf_t nbuf_head = NULL;
  1208. qdf_nbuf_t nbuf_tail = NULL;
  1209. qdf_nbuf_t deliver_list_head = NULL;
  1210. qdf_nbuf_t deliver_list_tail = NULL;
  1211. DP_HIST_INIT();
  1212. /* Debug -- Remove later */
  1213. qdf_assert(soc && hal_ring);
  1214. hal_soc = soc->hal_soc;
  1215. /* Debug -- Remove later */
  1216. qdf_assert(hal_soc);
  1217. hif_pm_runtime_mark_last_busy(soc->osdev->dev);
  1218. if (qdf_unlikely(hal_srng_access_start(hal_soc, hal_ring))) {
  1219. /*
  1220. * Need API to convert from hal_ring pointer to
  1221. * Ring Type / Ring Id combo
  1222. */
  1223. DP_STATS_INC(soc, rx.err.hal_ring_access_fail, 1);
  1224. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1225. FL("HAL RING Access Failed -- %pK"), hal_ring);
  1226. hal_srng_access_end(hal_soc, hal_ring);
  1227. goto done;
  1228. }
  1229. /*
  1230. * start reaping the buffers from reo ring and queue
  1231. * them in per vdev queue.
  1232. * Process the received pkts in a different per vdev loop.
  1233. */
  1234. while (qdf_likely(quota)) {
  1235. ring_desc = hal_srng_dst_get_next(hal_soc, hal_ring);
  1236. /*
  1237. * in case HW has updated hp after we cached the hp
  1238. * ring_desc can be NULL even there are entries
  1239. * available in the ring. Update the cached_hp
  1240. * and reap the buffers available to read complete
  1241. * mpdu in one reap
  1242. *
  1243. * This is needed for RAW mode we have to read all
  1244. * msdus corresponding to amsdu in one reap to create
  1245. * SG list properly but due to mismatch in cached_hp
  1246. * and actual hp sometimes we are unable to read
  1247. * complete mpdu in one reap.
  1248. */
  1249. if (qdf_unlikely(!ring_desc)) {
  1250. hal_srng_access_start_unlocked(hal_soc, hal_ring);
  1251. ring_desc = hal_srng_dst_get_next(hal_soc, hal_ring);
  1252. if (!ring_desc)
  1253. break;
  1254. DP_STATS_INC(soc, rx.hp_oos, 1);
  1255. /*
  1256. * update TP here in case loop takes long,
  1257. * then the ring is easily full.
  1258. */
  1259. hal_srng_access_end_unlocked(hal_soc, hal_ring);
  1260. }
  1261. error = HAL_RX_ERROR_STATUS_GET(ring_desc);
  1262. ring_id = hal_srng_ring_id_get(hal_ring);
  1263. if (qdf_unlikely(error == HAL_REO_ERROR_DETECTED)) {
  1264. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1265. FL("HAL RING 0x%pK:error %d"), hal_ring, error);
  1266. DP_STATS_INC(soc, rx.err.hal_reo_error[ring_id], 1);
  1267. /* Don't know how to deal with this -- assert */
  1268. qdf_assert(0);
  1269. }
  1270. rx_buf_cookie = HAL_RX_REO_BUF_COOKIE_GET(ring_desc);
  1271. rx_desc = dp_rx_cookie_2_va_rxdma_buf(soc, rx_buf_cookie);
  1272. qdf_assert(rx_desc);
  1273. rx_bufs_reaped[rx_desc->pool_id]++;
  1274. /* TODO */
  1275. /*
  1276. * Need a separate API for unmapping based on
  1277. * phyiscal address
  1278. */
  1279. qdf_nbuf_unmap_single(soc->osdev, rx_desc->nbuf,
  1280. QDF_DMA_BIDIRECTIONAL);
  1281. core_id = smp_processor_id();
  1282. DP_STATS_INC(soc, rx.ring_packets[core_id][ring_id], 1);
  1283. /* Get MPDU DESC info */
  1284. hal_rx_mpdu_desc_info_get(ring_desc, &mpdu_desc_info);
  1285. hal_rx_mpdu_peer_meta_data_set(qdf_nbuf_data(rx_desc->nbuf),
  1286. mpdu_desc_info.peer_meta_data);
  1287. /* Get MSDU DESC info */
  1288. hal_rx_msdu_desc_info_get(ring_desc, &msdu_desc_info);
  1289. /*
  1290. * save msdu flags first, last and continuation msdu in
  1291. * nbuf->cb
  1292. */
  1293. if (msdu_desc_info.msdu_flags & HAL_MSDU_F_FIRST_MSDU_IN_MPDU)
  1294. qdf_nbuf_set_rx_chfrag_start(rx_desc->nbuf, 1);
  1295. if (msdu_desc_info.msdu_flags & HAL_MSDU_F_MSDU_CONTINUATION)
  1296. qdf_nbuf_set_rx_chfrag_cont(rx_desc->nbuf, 1);
  1297. if (msdu_desc_info.msdu_flags & HAL_MSDU_F_LAST_MSDU_IN_MPDU)
  1298. qdf_nbuf_set_rx_chfrag_end(rx_desc->nbuf, 1);
  1299. QDF_NBUF_CB_RX_CTX_ID(rx_desc->nbuf) = reo_ring_num;
  1300. DP_RX_LIST_APPEND(nbuf_head, nbuf_tail, rx_desc->nbuf);
  1301. /*
  1302. * if continuation bit is set then we have MSDU spread
  1303. * across multiple buffers, let us not decrement quota
  1304. * till we reap all buffers of that MSDU.
  1305. */
  1306. if (qdf_likely(!qdf_nbuf_is_rx_chfrag_cont(rx_desc->nbuf)))
  1307. quota -= 1;
  1308. dp_rx_add_to_free_desc_list(&head[rx_desc->pool_id],
  1309. &tail[rx_desc->pool_id],
  1310. rx_desc);
  1311. }
  1312. done:
  1313. hal_srng_access_end(hal_soc, hal_ring);
  1314. if (nbuf_tail)
  1315. QDF_NBUF_CB_RX_FLUSH_IND(nbuf_tail) = 1;
  1316. /* Update histogram statistics by looping through pdev's */
  1317. DP_RX_HIST_STATS_PER_PDEV();
  1318. for (mac_id = 0; mac_id < MAX_PDEV_CNT; mac_id++) {
  1319. /*
  1320. * continue with next mac_id if no pkts were reaped
  1321. * from that pool
  1322. */
  1323. if (!rx_bufs_reaped[mac_id])
  1324. continue;
  1325. pdev = soc->pdev_list[mac_id];
  1326. dp_rxdma_srng = &pdev->rx_refill_buf_ring;
  1327. rx_desc_pool = &soc->rx_desc_buf[mac_id];
  1328. dp_rx_buffers_replenish(soc, mac_id, dp_rxdma_srng,
  1329. rx_desc_pool, rx_bufs_reaped[mac_id],
  1330. &head[mac_id], &tail[mac_id]);
  1331. }
  1332. /* Peer can be NULL is case of LFR */
  1333. if (qdf_likely(peer != NULL))
  1334. vdev = NULL;
  1335. /*
  1336. * BIG loop where each nbuf is dequeued from global queue,
  1337. * processed and queued back on a per vdev basis. These nbufs
  1338. * are sent to stack as and when we run out of nbufs
  1339. * or a new nbuf dequeued from global queue has a different
  1340. * vdev when compared to previous nbuf.
  1341. */
  1342. nbuf = nbuf_head;
  1343. while (nbuf) {
  1344. next = nbuf->next;
  1345. rx_tlv_hdr = qdf_nbuf_data(nbuf);
  1346. /*
  1347. * Check if DMA completed -- msdu_done is the last bit
  1348. * to be written
  1349. */
  1350. if (qdf_unlikely(!hal_rx_attn_msdu_done_get(rx_tlv_hdr))) {
  1351. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1352. FL("MSDU DONE failure"));
  1353. hal_rx_dump_pkt_tlvs(hal_soc, rx_tlv_hdr,
  1354. QDF_TRACE_LEVEL_INFO);
  1355. qdf_assert(0);
  1356. }
  1357. peer_mdata = hal_rx_mpdu_peer_meta_data_get(rx_tlv_hdr);
  1358. peer_id = DP_PEER_METADATA_PEER_ID_GET(peer_mdata);
  1359. peer = dp_peer_find_by_id(soc, peer_id);
  1360. if (peer) {
  1361. QDF_NBUF_CB_DP_TRACE_PRINT(nbuf) = false;
  1362. qdf_dp_trace_set_track(nbuf, QDF_RX);
  1363. QDF_NBUF_CB_RX_DP_TRACE(nbuf) = 1;
  1364. QDF_NBUF_CB_RX_PACKET_TRACK(nbuf) =
  1365. QDF_NBUF_RX_PKT_DATA_TRACK;
  1366. }
  1367. rx_bufs_used++;
  1368. if (deliver_list_head && peer && (vdev != peer->vdev)) {
  1369. dp_rx_deliver_to_stack(vdev, peer, deliver_list_head,
  1370. deliver_list_tail);
  1371. deliver_list_head = NULL;
  1372. deliver_list_tail = NULL;
  1373. }
  1374. if (qdf_likely(peer != NULL)) {
  1375. vdev = peer->vdev;
  1376. } else {
  1377. DP_STATS_INC_PKT(soc, rx.err.rx_invalid_peer, 1,
  1378. qdf_nbuf_len(nbuf));
  1379. qdf_nbuf_free(nbuf);
  1380. nbuf = next;
  1381. continue;
  1382. }
  1383. if (qdf_unlikely(vdev == NULL)) {
  1384. qdf_nbuf_free(nbuf);
  1385. nbuf = next;
  1386. DP_STATS_INC(soc, rx.err.invalid_vdev, 1);
  1387. dp_peer_unref_del_find_by_id(peer);
  1388. continue;
  1389. }
  1390. DP_HIST_PACKET_COUNT_INC(vdev->pdev->pdev_id);
  1391. /*
  1392. * First IF condition:
  1393. * 802.11 Fragmented pkts are reinjected to REO
  1394. * HW block as SG pkts and for these pkts we only
  1395. * need to pull the RX TLVS header length.
  1396. * Second IF condition:
  1397. * The below condition happens when an MSDU is spread
  1398. * across multiple buffers. This can happen in two cases
  1399. * 1. The nbuf size is smaller then the received msdu.
  1400. * ex: we have set the nbuf size to 2048 during
  1401. * nbuf_alloc. but we received an msdu which is
  1402. * 2304 bytes in size then this msdu is spread
  1403. * across 2 nbufs.
  1404. *
  1405. * 2. AMSDUs when RAW mode is enabled.
  1406. * ex: 1st MSDU is in 1st nbuf and 2nd MSDU is spread
  1407. * across 1st nbuf and 2nd nbuf and last MSDU is
  1408. * spread across 2nd nbuf and 3rd nbuf.
  1409. *
  1410. * for these scenarios let us create a skb frag_list and
  1411. * append these buffers till the last MSDU of the AMSDU
  1412. * Third condition:
  1413. * This is the most likely case, we receive 802.3 pkts
  1414. * decapsulated by HW, here we need to set the pkt length.
  1415. */
  1416. if (qdf_unlikely(qdf_nbuf_get_ext_list(nbuf)))
  1417. qdf_nbuf_pull_head(nbuf, RX_PKT_TLVS_LEN);
  1418. else if (qdf_unlikely(vdev->rx_decap_type ==
  1419. htt_cmn_pkt_type_raw)) {
  1420. msdu_len = hal_rx_msdu_start_msdu_len_get(rx_tlv_hdr);
  1421. nbuf = dp_rx_sg_create(nbuf, rx_tlv_hdr);
  1422. DP_STATS_INC(vdev->pdev, rx_raw_pkts, 1);
  1423. DP_STATS_INC_PKT(peer, rx.raw, 1,
  1424. msdu_len);
  1425. next = nbuf->next;
  1426. } else {
  1427. l2_hdr_offset =
  1428. hal_rx_msdu_end_l3_hdr_padding_get(rx_tlv_hdr);
  1429. msdu_len = hal_rx_msdu_start_msdu_len_get(rx_tlv_hdr);
  1430. pkt_len = msdu_len + l2_hdr_offset + RX_PKT_TLVS_LEN;
  1431. qdf_nbuf_set_pktlen(nbuf, pkt_len);
  1432. qdf_nbuf_pull_head(nbuf,
  1433. RX_PKT_TLVS_LEN +
  1434. l2_hdr_offset);
  1435. }
  1436. if (!dp_wds_rx_policy_check(rx_tlv_hdr, vdev, peer,
  1437. hal_rx_msdu_end_da_is_mcbc_get(rx_tlv_hdr))) {
  1438. QDF_TRACE(QDF_MODULE_ID_DP,
  1439. QDF_TRACE_LEVEL_ERROR,
  1440. FL("Policy Check Drop pkt"));
  1441. /* Drop & free packet */
  1442. qdf_nbuf_free(nbuf);
  1443. /* Statistics */
  1444. nbuf = next;
  1445. dp_peer_unref_del_find_by_id(peer);
  1446. continue;
  1447. }
  1448. if (qdf_unlikely(peer && peer->bss_peer)) {
  1449. QDF_TRACE(QDF_MODULE_ID_DP,
  1450. QDF_TRACE_LEVEL_ERROR,
  1451. FL("received pkt with same src MAC"));
  1452. DP_STATS_INC_PKT(peer, rx.mec_drop, 1, msdu_len);
  1453. /* Drop & free packet */
  1454. qdf_nbuf_free(nbuf);
  1455. /* Statistics */
  1456. nbuf = next;
  1457. dp_peer_unref_del_find_by_id(peer);
  1458. continue;
  1459. }
  1460. if (qdf_unlikely(peer && (peer->nawds_enabled == true) &&
  1461. (hal_rx_msdu_end_da_is_mcbc_get(rx_tlv_hdr)) &&
  1462. (hal_rx_get_mpdu_mac_ad4_valid(rx_tlv_hdr) == false))) {
  1463. DP_STATS_INC(peer, rx.nawds_mcast_drop, 1);
  1464. qdf_nbuf_free(nbuf);
  1465. nbuf = next;
  1466. dp_peer_unref_del_find_by_id(peer);
  1467. continue;
  1468. }
  1469. dp_rx_cksum_offload(vdev->pdev, nbuf, rx_tlv_hdr);
  1470. dp_set_rx_queue(nbuf, ring_id);
  1471. /*
  1472. * HW structures call this L3 header padding --
  1473. * even though this is actually the offset from
  1474. * the buffer beginning where the L2 header
  1475. * begins.
  1476. */
  1477. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1478. FL("rxhash: flow id toeplitz: 0x%x"),
  1479. hal_rx_msdu_start_toeplitz_get(rx_tlv_hdr));
  1480. dp_rx_msdu_stats_update(soc, nbuf, rx_tlv_hdr, peer, ring_id);
  1481. if (qdf_unlikely(vdev->mesh_vdev)) {
  1482. if (dp_rx_filter_mesh_packets(vdev, nbuf,
  1483. rx_tlv_hdr)
  1484. == QDF_STATUS_SUCCESS) {
  1485. QDF_TRACE(QDF_MODULE_ID_DP,
  1486. QDF_TRACE_LEVEL_INFO_MED,
  1487. FL("mesh pkt filtered"));
  1488. DP_STATS_INC(vdev->pdev, dropped.mesh_filter,
  1489. 1);
  1490. qdf_nbuf_free(nbuf);
  1491. nbuf = next;
  1492. dp_peer_unref_del_find_by_id(peer);
  1493. continue;
  1494. }
  1495. dp_rx_fill_mesh_stats(vdev, nbuf, rx_tlv_hdr, peer);
  1496. }
  1497. #ifdef QCA_WIFI_NAPIER_EMULATION_DBG /* Debug code, remove later */
  1498. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1499. "p_id %d msdu_len %d hdr_off %d",
  1500. peer_id, msdu_len, l2_hdr_offset);
  1501. print_hex_dump(KERN_ERR,
  1502. "\t Pkt Data:", DUMP_PREFIX_NONE, 32, 4,
  1503. qdf_nbuf_data(nbuf), 128, false);
  1504. #endif /* NAPIER_EMULATION */
  1505. if (qdf_likely(vdev->rx_decap_type ==
  1506. htt_cmn_pkt_type_ethernet) &&
  1507. qdf_likely(!vdev->mesh_vdev)) {
  1508. /* WDS Destination Address Learning */
  1509. if (vdev->da_war_enabled)
  1510. dp_rx_da_learn(soc, rx_tlv_hdr, peer, nbuf);
  1511. /* WDS Source Port Learning */
  1512. if (vdev->wds_enabled)
  1513. dp_rx_wds_srcport_learn(soc, rx_tlv_hdr,
  1514. peer, nbuf);
  1515. /* Intrabss-fwd */
  1516. if (dp_rx_check_ap_bridge(vdev))
  1517. if (dp_rx_intrabss_fwd(soc,
  1518. peer,
  1519. rx_tlv_hdr,
  1520. nbuf)) {
  1521. nbuf = next;
  1522. dp_peer_unref_del_find_by_id(peer);
  1523. continue; /* Get next desc */
  1524. }
  1525. }
  1526. dp_rx_fill_gro_info(soc, rx_tlv_hdr, nbuf);
  1527. qdf_nbuf_cb_update_peer_local_id(nbuf, peer->local_id);
  1528. DP_RX_LIST_APPEND(deliver_list_head,
  1529. deliver_list_tail,
  1530. nbuf);
  1531. DP_STATS_INC_PKT(peer, rx.to_stack, 1,
  1532. qdf_nbuf_len(nbuf));
  1533. nbuf = next;
  1534. dp_peer_unref_del_find_by_id(peer);
  1535. }
  1536. if (deliver_list_head)
  1537. dp_rx_deliver_to_stack(vdev, peer, deliver_list_head,
  1538. deliver_list_tail);
  1539. return rx_bufs_used; /* Assume no scale factor for now */
  1540. }
  1541. /**
  1542. * dp_rx_detach() - detach dp rx
  1543. * @pdev: core txrx pdev context
  1544. *
  1545. * This function will detach DP RX into main device context
  1546. * will free DP Rx resources.
  1547. *
  1548. * Return: void
  1549. */
  1550. void
  1551. dp_rx_pdev_detach(struct dp_pdev *pdev)
  1552. {
  1553. uint8_t pdev_id = pdev->pdev_id;
  1554. struct dp_soc *soc = pdev->soc;
  1555. struct rx_desc_pool *rx_desc_pool;
  1556. rx_desc_pool = &soc->rx_desc_buf[pdev_id];
  1557. if (rx_desc_pool->pool_size != 0) {
  1558. dp_rx_desc_pool_free(soc, pdev_id, rx_desc_pool);
  1559. }
  1560. return;
  1561. }
  1562. /**
  1563. * dp_rx_attach() - attach DP RX
  1564. * @pdev: core txrx pdev context
  1565. *
  1566. * This function will attach a DP RX instance into the main
  1567. * device (SOC) context. Will allocate dp rx resource and
  1568. * initialize resources.
  1569. *
  1570. * Return: QDF_STATUS_SUCCESS: success
  1571. * QDF_STATUS_E_RESOURCES: Error return
  1572. */
  1573. QDF_STATUS
  1574. dp_rx_pdev_attach(struct dp_pdev *pdev)
  1575. {
  1576. uint8_t pdev_id = pdev->pdev_id;
  1577. struct dp_soc *soc = pdev->soc;
  1578. uint32_t rxdma_entries;
  1579. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1580. union dp_rx_desc_list_elem_t *tail = NULL;
  1581. struct dp_srng *dp_rxdma_srng;
  1582. struct rx_desc_pool *rx_desc_pool;
  1583. if (wlan_cfg_get_dp_pdev_nss_enabled(pdev->wlan_cfg_ctx)) {
  1584. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  1585. "nss-wifi<4> skip Rx refil %d", pdev_id);
  1586. return QDF_STATUS_SUCCESS;
  1587. }
  1588. pdev = soc->pdev_list[pdev_id];
  1589. dp_rxdma_srng = &pdev->rx_refill_buf_ring;
  1590. rxdma_entries = dp_rxdma_srng->num_entries;
  1591. soc->process_rx_status = CONFIG_PROCESS_RX_STATUS;
  1592. rx_desc_pool = &soc->rx_desc_buf[pdev_id];
  1593. dp_rx_desc_pool_alloc(soc, pdev_id,
  1594. DP_RX_DESC_ALLOC_MULTIPLIER * rxdma_entries,
  1595. rx_desc_pool);
  1596. rx_desc_pool->owner = DP_WBM2SW_RBM;
  1597. /* For Rx buffers, WBM release ring is SW RING 3,for all pdev's */
  1598. dp_rx_buffers_replenish(soc, pdev_id, dp_rxdma_srng, rx_desc_pool,
  1599. 0, &desc_list, &tail);
  1600. return QDF_STATUS_SUCCESS;
  1601. }
  1602. /*
  1603. * dp_rx_nbuf_prepare() - prepare RX nbuf
  1604. * @soc: core txrx main context
  1605. * @pdev: core txrx pdev context
  1606. *
  1607. * This function alloc & map nbuf for RX dma usage, retry it if failed
  1608. * until retry times reaches max threshold or succeeded.
  1609. *
  1610. * Return: qdf_nbuf_t pointer if succeeded, NULL if failed.
  1611. */
  1612. qdf_nbuf_t
  1613. dp_rx_nbuf_prepare(struct dp_soc *soc, struct dp_pdev *pdev)
  1614. {
  1615. uint8_t *buf;
  1616. int32_t nbuf_retry_count;
  1617. QDF_STATUS ret;
  1618. qdf_nbuf_t nbuf = NULL;
  1619. for (nbuf_retry_count = 0; nbuf_retry_count <
  1620. QDF_NBUF_ALLOC_MAP_RETRY_THRESHOLD;
  1621. nbuf_retry_count++) {
  1622. /* Allocate a new skb */
  1623. nbuf = qdf_nbuf_alloc(soc->osdev,
  1624. RX_BUFFER_SIZE,
  1625. RX_BUFFER_RESERVATION,
  1626. RX_BUFFER_ALIGNMENT,
  1627. FALSE);
  1628. if (nbuf == NULL) {
  1629. DP_STATS_INC(pdev,
  1630. replenish.nbuf_alloc_fail, 1);
  1631. continue;
  1632. }
  1633. buf = qdf_nbuf_data(nbuf);
  1634. memset(buf, 0, RX_BUFFER_SIZE);
  1635. ret = qdf_nbuf_map_single(soc->osdev, nbuf,
  1636. QDF_DMA_BIDIRECTIONAL);
  1637. /* nbuf map failed */
  1638. if (qdf_unlikely(QDF_IS_STATUS_ERROR(ret))) {
  1639. qdf_nbuf_free(nbuf);
  1640. DP_STATS_INC(pdev, replenish.map_err, 1);
  1641. continue;
  1642. }
  1643. /* qdf_nbuf alloc and map succeeded */
  1644. break;
  1645. }
  1646. /* qdf_nbuf still alloc or map failed */
  1647. if (qdf_unlikely(nbuf_retry_count >=
  1648. QDF_NBUF_ALLOC_MAP_RETRY_THRESHOLD))
  1649. return NULL;
  1650. return nbuf;
  1651. }