dp_rx.c 53 KB

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