dp_rx_mon_dest.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963
  1. /*
  2. * Copyright (c) 2017-2020 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #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_trace.h"
  25. #include "qdf_nbuf.h"
  26. #include "hal_api_mon.h"
  27. #include "dp_rx_mon.h"
  28. #include "wlan_cfg.h"
  29. #include "dp_internal.h"
  30. #include "dp_rx_buffer_pool.h"
  31. #ifdef WLAN_TX_PKT_CAPTURE_ENH
  32. #include "dp_rx_mon_feature.h"
  33. static inline void
  34. dp_handle_tx_capture(struct dp_soc *soc, struct dp_pdev *pdev,
  35. qdf_nbuf_t mon_mpdu)
  36. {
  37. struct hal_rx_ppdu_info *ppdu_info = &pdev->ppdu_info;
  38. if (pdev->tx_capture_enabled
  39. == CDP_TX_ENH_CAPTURE_DISABLED)
  40. return;
  41. if ((ppdu_info->sw_frame_group_id ==
  42. HAL_MPDU_SW_FRAME_GROUP_CTRL_NDPA) ||
  43. (ppdu_info->sw_frame_group_id ==
  44. HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR))
  45. dp_handle_tx_capture_from_dest(soc, pdev, mon_mpdu);
  46. }
  47. static void
  48. dp_tx_capture_get_user_id(struct dp_pdev *dp_pdev, void *rx_desc_tlv)
  49. {
  50. if (dp_pdev->tx_capture_enabled
  51. != CDP_TX_ENH_CAPTURE_DISABLED)
  52. dp_pdev->ppdu_info.rx_info.user_id =
  53. HAL_RX_HW_DESC_MPDU_USER_ID(rx_desc_tlv);
  54. }
  55. #else
  56. static inline void
  57. dp_handle_tx_capture(struct dp_soc *soc, struct dp_pdev *pdev,
  58. qdf_nbuf_t mon_mpdu)
  59. {
  60. }
  61. static void
  62. dp_tx_capture_get_user_id(struct dp_pdev *dp_pdev, void *rx_desc_tlv)
  63. {
  64. }
  65. #endif
  66. /*
  67. * The protocol flow tag size
  68. * if DP_RX_MON_MEM_FRAG is enabled.
  69. */
  70. #ifdef DP_RX_MON_MEM_FRAG
  71. #if defined(WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG) ||\
  72. defined(WLAN_SUPPORT_RX_FLOW_TAG)
  73. #define DP_RX_MON_PF_TAG_TOT_LEN (64)
  74. #endif
  75. #endif
  76. /*
  77. * PPDU id is from 0 to 64k-1. PPDU id read from status ring and PPDU id
  78. * read from destination ring shall track each other. If the distance of
  79. * two ppdu id is less than 20000. It is assume no wrap around. Otherwise,
  80. * It is assume wrap around.
  81. */
  82. #define NOT_PPDU_ID_WRAP_AROUND 20000
  83. /*
  84. * The destination ring processing is stuck if the destrination is not
  85. * moving while status ring moves 16 ppdu. the destination ring processing
  86. * skips this destination ring ppdu as walkaround
  87. */
  88. #define MON_DEST_RING_STUCK_MAX_CNT 16
  89. /**
  90. * dp_rx_mon_link_desc_return() - Return a MPDU link descriptor to HW
  91. * (WBM), following error handling
  92. *
  93. * @dp_pdev: core txrx pdev context
  94. * @buf_addr_info: void pointer to monitor link descriptor buf addr info
  95. * Return: QDF_STATUS
  96. */
  97. QDF_STATUS
  98. dp_rx_mon_link_desc_return(struct dp_pdev *dp_pdev,
  99. hal_buff_addrinfo_t buf_addr_info, int mac_id)
  100. {
  101. struct dp_srng *dp_srng;
  102. hal_ring_handle_t hal_ring_hdl;
  103. hal_soc_handle_t hal_soc;
  104. QDF_STATUS status = QDF_STATUS_E_FAILURE;
  105. void *src_srng_desc;
  106. hal_soc = dp_pdev->soc->hal_soc;
  107. dp_srng = &dp_pdev->soc->rxdma_mon_desc_ring[mac_id];
  108. hal_ring_hdl = dp_srng->hal_srng;
  109. qdf_assert(hal_ring_hdl);
  110. if (qdf_unlikely(hal_srng_access_start(hal_soc, hal_ring_hdl))) {
  111. /* TODO */
  112. /*
  113. * Need API to convert from hal_ring pointer to
  114. * Ring Type / Ring Id combo
  115. */
  116. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  117. "%s %d : \
  118. HAL RING Access For WBM Release SRNG Failed -- %pK",
  119. __func__, __LINE__, hal_ring_hdl);
  120. goto done;
  121. }
  122. src_srng_desc = hal_srng_src_get_next(hal_soc, hal_ring_hdl);
  123. if (qdf_likely(src_srng_desc)) {
  124. /* Return link descriptor through WBM ring (SW2WBM)*/
  125. hal_rx_mon_msdu_link_desc_set(hal_soc,
  126. src_srng_desc, buf_addr_info);
  127. status = QDF_STATUS_SUCCESS;
  128. } else {
  129. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  130. "%s %d -- Monitor Link Desc WBM Release Ring Full",
  131. __func__, __LINE__);
  132. }
  133. done:
  134. hal_srng_access_end(hal_soc, hal_ring_hdl);
  135. return status;
  136. }
  137. /**
  138. * dp_rx_mon_mpdu_pop() - Return a MPDU link descriptor to HW
  139. * (WBM), following error handling
  140. *
  141. * @soc: core DP main context
  142. * @mac_id: mac id which is one of 3 mac_ids
  143. * @rxdma_dst_ring_desc: void pointer to monitor link descriptor buf addr info
  144. * @head_msdu: head of msdu to be popped
  145. * @tail_msdu: tail of msdu to be popped
  146. * @npackets: number of packet to be popped
  147. * @ppdu_id: ppdu id of processing ppdu
  148. * @head: head of descs list to be freed
  149. * @tail: tail of decs list to be freed
  150. *
  151. * Return: number of msdu in MPDU to be popped
  152. */
  153. static inline uint32_t
  154. dp_rx_mon_mpdu_pop(struct dp_soc *soc, uint32_t mac_id,
  155. hal_rxdma_desc_t rxdma_dst_ring_desc, qdf_nbuf_t *head_msdu,
  156. qdf_nbuf_t *tail_msdu, uint32_t *npackets, uint32_t *ppdu_id,
  157. union dp_rx_desc_list_elem_t **head,
  158. union dp_rx_desc_list_elem_t **tail)
  159. {
  160. struct dp_pdev *dp_pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  161. void *rx_desc_tlv;
  162. void *rx_msdu_link_desc;
  163. qdf_nbuf_t msdu;
  164. qdf_nbuf_t last;
  165. struct hal_rx_msdu_list msdu_list;
  166. uint16_t num_msdus;
  167. uint32_t rx_buf_size, rx_pkt_offset;
  168. struct hal_buf_info buf_info;
  169. uint32_t rx_bufs_used = 0;
  170. uint32_t msdu_ppdu_id, msdu_cnt;
  171. uint8_t *data = NULL;
  172. uint32_t i;
  173. uint32_t total_frag_len = 0, frag_len = 0;
  174. bool is_frag, is_first_msdu;
  175. bool drop_mpdu = false, is_frag_non_raw = false;
  176. uint8_t bm_action = HAL_BM_ACTION_PUT_IN_IDLE_LIST;
  177. qdf_dma_addr_t buf_paddr = 0;
  178. uint32_t rx_link_buf_info[HAL_RX_BUFFINFO_NUM_DWORDS];
  179. struct cdp_mon_status *rs;
  180. if (qdf_unlikely(!dp_pdev)) {
  181. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  182. "pdev is null for mac_id = %d", mac_id);
  183. return rx_bufs_used;
  184. }
  185. msdu = 0;
  186. last = NULL;
  187. hal_rx_reo_ent_buf_paddr_get(rxdma_dst_ring_desc, &buf_info, &msdu_cnt);
  188. rs = &dp_pdev->rx_mon_recv_status;
  189. rs->cdp_rs_rxdma_err = false;
  190. if ((hal_rx_reo_ent_rxdma_push_reason_get(rxdma_dst_ring_desc) ==
  191. HAL_RX_WBM_RXDMA_PSH_RSN_ERROR)) {
  192. uint8_t rxdma_err =
  193. hal_rx_reo_ent_rxdma_error_code_get(
  194. rxdma_dst_ring_desc);
  195. if (qdf_unlikely((rxdma_err == HAL_RXDMA_ERR_FLUSH_REQUEST) ||
  196. (rxdma_err == HAL_RXDMA_ERR_MPDU_LENGTH) ||
  197. (rxdma_err == HAL_RXDMA_ERR_OVERFLOW) ||
  198. (rxdma_err == HAL_RXDMA_ERR_FCS && dp_pdev->mcopy_mode))) {
  199. drop_mpdu = true;
  200. dp_pdev->rx_mon_stats.dest_mpdu_drop++;
  201. }
  202. rs->cdp_rs_rxdma_err = true;
  203. }
  204. is_frag = false;
  205. is_first_msdu = true;
  206. do {
  207. /* WAR for duplicate link descriptors received from HW */
  208. if (qdf_unlikely(dp_pdev->mon_last_linkdesc_paddr ==
  209. buf_info.paddr)) {
  210. dp_pdev->rx_mon_stats.dup_mon_linkdesc_cnt++;
  211. return rx_bufs_used;
  212. }
  213. rx_msdu_link_desc =
  214. dp_rx_cookie_2_mon_link_desc(dp_pdev,
  215. buf_info, mac_id);
  216. qdf_assert_always(rx_msdu_link_desc);
  217. hal_rx_msdu_list_get(soc->hal_soc, rx_msdu_link_desc,
  218. &msdu_list, &num_msdus);
  219. for (i = 0; i < num_msdus; i++) {
  220. uint16_t l2_hdr_offset;
  221. struct dp_rx_desc *rx_desc = NULL;
  222. struct rx_desc_pool *rx_desc_pool;
  223. rx_desc = dp_rx_get_mon_desc(soc,
  224. msdu_list.sw_cookie[i]);
  225. qdf_assert_always(rx_desc);
  226. msdu = DP_RX_MON_GET_NBUF_FROM_DESC(rx_desc);
  227. buf_paddr = dp_rx_mon_get_paddr_from_desc(rx_desc);
  228. /* WAR for duplicate buffers received from HW */
  229. if (qdf_unlikely(dp_pdev->mon_last_buf_cookie ==
  230. msdu_list.sw_cookie[i] ||
  231. DP_RX_MON_IS_BUFFER_ADDR_NULL(rx_desc) ||
  232. msdu_list.paddr[i] != buf_paddr ||
  233. !rx_desc->in_use)) {
  234. /* Skip duplicate buffer and drop subsequent
  235. * buffers in this MPDU
  236. */
  237. drop_mpdu = true;
  238. dp_pdev->rx_mon_stats.dup_mon_buf_cnt++;
  239. dp_pdev->mon_last_linkdesc_paddr =
  240. buf_info.paddr;
  241. continue;
  242. }
  243. if (rx_desc->unmapped == 0) {
  244. rx_desc_pool = dp_rx_get_mon_desc_pool(soc,
  245. mac_id,
  246. dp_pdev->pdev_id);
  247. dp_rx_mon_buffer_unmap(soc, rx_desc,
  248. rx_desc_pool->buf_size);
  249. rx_desc->unmapped = 1;
  250. }
  251. if (dp_rx_buffer_pool_refill(soc, msdu,
  252. rx_desc->pool_id)) {
  253. drop_mpdu = true;
  254. msdu = NULL;
  255. dp_pdev->mon_last_linkdesc_paddr =
  256. buf_info.paddr;
  257. goto next_msdu;
  258. }
  259. if (drop_mpdu) {
  260. dp_pdev->mon_last_linkdesc_paddr =
  261. buf_info.paddr;
  262. dp_rx_mon_buffer_free(rx_desc);
  263. msdu = NULL;
  264. goto next_msdu;
  265. }
  266. data = dp_rx_mon_get_buffer_data(rx_desc);
  267. rx_desc_tlv = HAL_RX_MON_DEST_GET_DESC(data);
  268. QDF_TRACE(QDF_MODULE_ID_DP,
  269. QDF_TRACE_LEVEL_DEBUG,
  270. "[%s] i=%d, ppdu_id=%x, num_msdus = %u",
  271. __func__, i, *ppdu_id, num_msdus);
  272. if (is_first_msdu) {
  273. if (!hal_rx_mpdu_start_tlv_tag_valid(
  274. soc->hal_soc,
  275. rx_desc_tlv)) {
  276. drop_mpdu = true;
  277. dp_rx_mon_buffer_free(rx_desc);
  278. msdu = NULL;
  279. dp_pdev->mon_last_linkdesc_paddr =
  280. buf_info.paddr;
  281. goto next_msdu;
  282. }
  283. msdu_ppdu_id = hal_rx_hw_desc_get_ppduid_get(
  284. soc->hal_soc,
  285. rx_desc_tlv,
  286. rxdma_dst_ring_desc);
  287. is_first_msdu = false;
  288. QDF_TRACE(QDF_MODULE_ID_DP,
  289. QDF_TRACE_LEVEL_DEBUG,
  290. "[%s] msdu_ppdu_id=%x",
  291. __func__, msdu_ppdu_id);
  292. if (*ppdu_id > msdu_ppdu_id)
  293. QDF_TRACE(QDF_MODULE_ID_DP,
  294. QDF_TRACE_LEVEL_DEBUG,
  295. "[%s][%d] ppdu_id=%d "
  296. "msdu_ppdu_id=%d",
  297. __func__, __LINE__, *ppdu_id,
  298. msdu_ppdu_id);
  299. if ((*ppdu_id < msdu_ppdu_id) && (
  300. (msdu_ppdu_id - *ppdu_id) <
  301. NOT_PPDU_ID_WRAP_AROUND)) {
  302. *ppdu_id = msdu_ppdu_id;
  303. return rx_bufs_used;
  304. } else if ((*ppdu_id > msdu_ppdu_id) && (
  305. (*ppdu_id - msdu_ppdu_id) >
  306. NOT_PPDU_ID_WRAP_AROUND)) {
  307. *ppdu_id = msdu_ppdu_id;
  308. return rx_bufs_used;
  309. }
  310. dp_tx_capture_get_user_id(dp_pdev,
  311. rx_desc_tlv);
  312. if (*ppdu_id == msdu_ppdu_id)
  313. dp_pdev->rx_mon_stats.ppdu_id_match++;
  314. else
  315. dp_pdev->rx_mon_stats.ppdu_id_mismatch
  316. ++;
  317. dp_pdev->mon_last_linkdesc_paddr =
  318. buf_info.paddr;
  319. if (dp_rx_mon_alloc_parent_buffer(head_msdu)
  320. != QDF_STATUS_SUCCESS) {
  321. DP_STATS_INC(dp_pdev,
  322. replenish.nbuf_alloc_fail,
  323. 1);
  324. qdf_frag_free(rx_desc_tlv);
  325. QDF_TRACE(QDF_MODULE_ID_DP,
  326. QDF_TRACE_LEVEL_DEBUG,
  327. "[%s] failed to allocate parent buffer to hold all frag",
  328. __func__);
  329. drop_mpdu = true;
  330. goto next_msdu;
  331. }
  332. }
  333. if (hal_rx_desc_is_first_msdu(soc->hal_soc,
  334. rx_desc_tlv))
  335. hal_rx_mon_hw_desc_get_mpdu_status(soc->hal_soc,
  336. rx_desc_tlv,
  337. &(dp_pdev->ppdu_info.rx_status));
  338. dp_rx_mon_parse_desc_buffer(soc,
  339. &(msdu_list.msdu_info[i]),
  340. &is_frag,
  341. &total_frag_len,
  342. &frag_len,
  343. &l2_hdr_offset,
  344. rx_desc_tlv,
  345. &is_frag_non_raw, data);
  346. if (!is_frag)
  347. msdu_cnt--;
  348. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  349. "%s total_len %u frag_len %u flags %u",
  350. __func__, total_frag_len, frag_len,
  351. msdu_list.msdu_info[i].msdu_flags);
  352. rx_pkt_offset = SIZE_OF_MONITOR_TLV;
  353. rx_buf_size = rx_pkt_offset + l2_hdr_offset
  354. + frag_len;
  355. dp_rx_mon_buffer_set_pktlen(msdu, rx_buf_size);
  356. #if 0
  357. /* Disble it.see packet on msdu done set to 0 */
  358. /*
  359. * Check if DMA completed -- msdu_done is the
  360. * last bit to be written
  361. */
  362. if (!hal_rx_attn_msdu_done_get(rx_desc_tlv)) {
  363. QDF_TRACE(QDF_MODULE_ID_DP,
  364. QDF_TRACE_LEVEL_ERROR,
  365. "%s:%d: Pkt Desc",
  366. __func__, __LINE__);
  367. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP,
  368. QDF_TRACE_LEVEL_ERROR,
  369. rx_desc_tlv, 128);
  370. qdf_assert_always(0);
  371. }
  372. #endif
  373. QDF_TRACE(QDF_MODULE_ID_DP,
  374. QDF_TRACE_LEVEL_DEBUG,
  375. "%s: rx_pkt_offset=%d, l2_hdr_offset=%d, msdu_len=%d, frag_len %u",
  376. __func__, rx_pkt_offset, l2_hdr_offset,
  377. msdu_list.msdu_info[i].msdu_len,
  378. frag_len);
  379. dp_rx_mon_add_msdu_to_list(head_msdu, msdu, &last,
  380. rx_desc_tlv, frag_len,
  381. l2_hdr_offset);
  382. next_msdu:
  383. dp_pdev->mon_last_buf_cookie = msdu_list.sw_cookie[i];
  384. rx_bufs_used++;
  385. dp_rx_add_to_free_desc_list(head,
  386. tail, rx_desc);
  387. }
  388. /*
  389. * Store the current link buffer into to the local
  390. * structure to be used for release purpose.
  391. */
  392. hal_rxdma_buff_addr_info_set(rx_link_buf_info, buf_info.paddr,
  393. buf_info.sw_cookie, buf_info.rbm);
  394. hal_rx_mon_next_link_desc_get(rx_msdu_link_desc, &buf_info);
  395. if (dp_rx_monitor_link_desc_return(dp_pdev,
  396. (hal_buff_addrinfo_t)
  397. rx_link_buf_info,
  398. mac_id,
  399. bm_action)
  400. != QDF_STATUS_SUCCESS)
  401. dp_err_rl("monitor link desc return failed");
  402. } while (buf_info.paddr && msdu_cnt);
  403. dp_rx_mon_init_tail_msdu(msdu, last, tail_msdu);
  404. dp_rx_mon_remove_raw_frame_fcs_len(head_msdu);
  405. return rx_bufs_used;
  406. }
  407. static inline
  408. void dp_rx_msdus_set_payload(struct dp_soc *soc, qdf_nbuf_t msdu)
  409. {
  410. uint8_t *data;
  411. uint32_t rx_pkt_offset, l2_hdr_offset;
  412. data = qdf_nbuf_data(msdu);
  413. rx_pkt_offset = SIZE_OF_MONITOR_TLV;
  414. l2_hdr_offset = hal_rx_msdu_end_l3_hdr_padding_get(soc->hal_soc, data);
  415. qdf_nbuf_pull_head(msdu, rx_pkt_offset + l2_hdr_offset);
  416. }
  417. #ifdef DP_RX_MON_MEM_FRAG
  418. /**
  419. * dp_rx_mon_frag_restitch_mpdu_from_msdus() - Restitch logic to
  420. * convert to 802.3 header and adjust frag memory pointing to
  421. * dot3 header and payload in case of Non-Raw frame.
  422. *
  423. * @soc: struct dp_soc *
  424. * @mac_id: MAC id
  425. * @head_msdu: MPDU containing all MSDU as a frag
  426. * @rx_status: struct cdp_mon_status *
  427. *
  428. * Return: Adjusted nbuf containing MPDU worth info.
  429. */
  430. static inline
  431. qdf_nbuf_t dp_rx_mon_frag_restitch_mpdu_from_msdus(struct dp_soc *soc,
  432. uint32_t mac_id,
  433. qdf_nbuf_t head_msdu,
  434. struct cdp_mon_status *rx_status)
  435. {
  436. uint32_t wifi_hdr_len, sec_hdr_len, msdu_llc_len,
  437. mpdu_buf_len, decap_hdr_pull_bytes, dir,
  438. is_amsdu, amsdu_pad, frag_size, tot_msdu_len;
  439. qdf_frag_t rx_desc, rx_src_desc, rx_dest_desc, frag_addr;
  440. char *hdr_desc;
  441. uint8_t num_frags, frags_iter, l2_hdr_offset;
  442. struct ieee80211_frame *wh;
  443. struct ieee80211_qoscntl *qos;
  444. struct dp_pdev *dp_pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  445. int16_t frag_page_offset = 0;
  446. struct hal_rx_mon_dest_buf_info buf_info;
  447. uint32_t pad_byte_pholder = 0;
  448. if (qdf_unlikely(!dp_pdev)) {
  449. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  450. "pdev is null for mac_id = %d", mac_id);
  451. return NULL;
  452. }
  453. qdf_mem_zero(&buf_info, sizeof(struct hal_rx_mon_dest_buf_info));
  454. if (!head_msdu)
  455. goto mpdu_stitch_fail;
  456. num_frags = qdf_nbuf_get_nr_frags(head_msdu);
  457. rx_desc = qdf_nbuf_get_frag_addr(head_msdu, 0) - SIZE_OF_MONITOR_TLV;
  458. if (HAL_RX_DESC_GET_MPDU_LENGTH_ERR(rx_desc)) {
  459. /* It looks like there is some issue on MPDU len err */
  460. /* Need further investigate if drop the packet */
  461. DP_STATS_INC(dp_pdev, dropped.mon_rx_drop, 1);
  462. return NULL;
  463. }
  464. /* Look for FCS error */
  465. rx_desc =
  466. qdf_nbuf_get_frag_addr(head_msdu,
  467. num_frags - 1) - SIZE_OF_MONITOR_TLV;
  468. rx_status->cdp_rs_fcs_err = HAL_RX_DESC_GET_MPDU_FCS_ERR(rx_desc);
  469. dp_pdev->ppdu_info.rx_status.rs_fcs_err =
  470. HAL_RX_DESC_GET_MPDU_FCS_ERR(rx_desc);
  471. rx_desc = qdf_nbuf_get_frag_addr(head_msdu, 0) - SIZE_OF_MONITOR_TLV;
  472. hal_rx_mon_dest_get_buffer_info_from_tlv(rx_desc, &buf_info);
  473. /* Easy case - The MSDU status indicates that this is a non-decapped
  474. * packet in RAW mode.
  475. */
  476. if (buf_info.is_decap_raw == 1)
  477. goto mpdu_stitch_done;
  478. l2_hdr_offset = DP_RX_MON_NONRAW_L2_HDR_PAD_BYTE;
  479. /* Decap mode:
  480. * Calculate the amount of header in decapped packet to knock off based
  481. * on the decap type and the corresponding number of raw bytes to copy
  482. * status header
  483. */
  484. hdr_desc = HAL_RX_DESC_GET_80211_HDR(rx_desc);
  485. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  486. "[%s][%d] decap format not raw",
  487. __func__, __LINE__);
  488. /* Base size */
  489. wifi_hdr_len = sizeof(struct ieee80211_frame);
  490. wh = (struct ieee80211_frame *)hdr_desc;
  491. dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
  492. if (dir == IEEE80211_FC1_DIR_DSTODS)
  493. wifi_hdr_len += 6;
  494. is_amsdu = 0;
  495. if (wh->i_fc[0] & QDF_IEEE80211_FC0_SUBTYPE_QOS) {
  496. qos = (struct ieee80211_qoscntl *)
  497. (hdr_desc + wifi_hdr_len);
  498. wifi_hdr_len += 2;
  499. is_amsdu = (qos->i_qos[0] & IEEE80211_QOS_AMSDU);
  500. }
  501. /*Calculate security header length based on 'Protected'
  502. * and 'EXT_IV' flag
  503. */
  504. if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
  505. char *iv = (char *)wh + wifi_hdr_len;
  506. if (iv[3] & KEY_EXTIV)
  507. sec_hdr_len = 8;
  508. else
  509. sec_hdr_len = 4;
  510. } else {
  511. sec_hdr_len = 0;
  512. }
  513. wifi_hdr_len += sec_hdr_len;
  514. /* MSDU related stuff LLC - AMSDU subframe header etc */
  515. msdu_llc_len = is_amsdu ? (14 + 8) : 8;
  516. mpdu_buf_len = wifi_hdr_len + msdu_llc_len;
  517. /* "Decap" header to remove from MSDU buffer */
  518. decap_hdr_pull_bytes = 14;
  519. amsdu_pad = 0;
  520. tot_msdu_len = 0;
  521. /*
  522. * keeping first MSDU ops outside of loop to avoid multiple
  523. * check handling
  524. */
  525. /* Construct src header */
  526. rx_src_desc = hdr_desc;
  527. /*
  528. * Update protocol and flow tag for MSDU
  529. * update frag index in ctx_idx field.
  530. * Reset head pointer data of nbuf before updating.
  531. */
  532. qdf_mem_zero(qdf_nbuf_head(head_msdu), DP_RX_MON_PF_TAG_TOT_LEN);
  533. QDF_NBUF_CB_RX_CTX_ID(head_msdu) = 0;
  534. dp_rx_mon_update_protocol_flow_tag(soc, dp_pdev, head_msdu, rx_desc);
  535. /* Construct destination address */
  536. frag_addr = qdf_nbuf_get_frag_addr(head_msdu, 0);
  537. frag_size = qdf_nbuf_get_frag_size_by_idx(head_msdu, 0);
  538. /* We will come here in 2 scenario:
  539. * 1. First MSDU of MPDU with single buffer
  540. * 2. First buffer of First MSDU of MPDU with continuation
  541. *
  542. * ------------------------------------------------------------
  543. * | SINGLE BUFFER (<= RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN)|
  544. * ------------------------------------------------------------
  545. *
  546. * ------------------------------------------------------------
  547. * | First BUFFER with Continuation | ... |
  548. * | (RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN) | |
  549. * ------------------------------------------------------------
  550. */
  551. pad_byte_pholder =
  552. (RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN) - frag_size;
  553. /* Construct destination address
  554. * --------------------------------------------------------------
  555. * | RX_PKT_TLV | L2_HDR_PAD | Decap HDR | Payload |
  556. * | | / |
  557. * | >Frag address points here / |
  558. * | \ / |
  559. * | \ This bytes needs to / |
  560. * | \ removed to frame pkt / |
  561. * | ----------------------- |
  562. * | | |
  563. * | | |
  564. * | WIFI +LLC HDR will be added here <-| |
  565. * | | | |
  566. * | >Dest addr will point | |
  567. * | somewhere in this area | |
  568. * --------------------------------------------------------------
  569. */
  570. rx_dest_desc =
  571. (frag_addr + decap_hdr_pull_bytes + l2_hdr_offset) -
  572. mpdu_buf_len;
  573. /* Add WIFI and LLC header for 1st MSDU of MPDU */
  574. qdf_mem_copy(rx_dest_desc, rx_src_desc, mpdu_buf_len);
  575. frag_page_offset =
  576. (decap_hdr_pull_bytes + l2_hdr_offset) - mpdu_buf_len;
  577. qdf_nbuf_move_frag_page_offset(head_msdu, 0, frag_page_offset);
  578. frag_size = qdf_nbuf_get_frag_size_by_idx(head_msdu, 0);
  579. if (buf_info.first_buffer && buf_info.last_buffer) {
  580. /* MSDU with single bufffer */
  581. amsdu_pad = frag_size & 0x3;
  582. amsdu_pad = amsdu_pad ? (4 - amsdu_pad) : 0;
  583. if (amsdu_pad <= pad_byte_pholder) {
  584. qdf_nbuf_trim_add_frag_size(head_msdu, 0, amsdu_pad,
  585. 0);
  586. amsdu_pad = 0;
  587. }
  588. } else {
  589. /*
  590. * First buffer of Continuation frame and hence
  591. * amsdu_padding doesn't need to be added
  592. * Increase tot_msdu_len so that amsdu_pad byte
  593. * will be calculated for last frame of MSDU
  594. */
  595. tot_msdu_len = frag_size;
  596. amsdu_pad = 0;
  597. }
  598. /* Here amsdu_pad byte will have some value if 1sf buffer was
  599. * Single buffer MSDU and dint had pholder to adjust amsdu padding
  600. * byte in the end
  601. * So dont initialize to ZERO here
  602. */
  603. pad_byte_pholder = 0;
  604. for (frags_iter = 1; frags_iter < num_frags; frags_iter++) {
  605. /* Construct destination address
  606. * ----------------------------------------------------------
  607. * | RX_PKT_TLV | L2_HDR_PAD | Decap HDR | Payload | Pad |
  608. * | | (First buffer) | | |
  609. * | | / / |
  610. * | >Frag address points here / / |
  611. * | \ / / |
  612. * | \ This bytes needs to / / |
  613. * | \ removed to frame pkt/ / |
  614. * | ---------------------- / |
  615. * | | / Add |
  616. * | | / amsdu pad |
  617. * | LLC HDR will be added here <-| | Byte for |
  618. * | | | | last frame |
  619. * | >Dest addr will point | | if space |
  620. * | somewhere in this area | | available |
  621. * | And amsdu_pad will be created if | | |
  622. * | dint get added in last buffer | | |
  623. * | (First Buffer) | | |
  624. * ----------------------------------------------------------
  625. */
  626. frag_addr = qdf_nbuf_get_frag_addr(head_msdu, frags_iter);
  627. rx_desc = frag_addr - SIZE_OF_MONITOR_TLV;
  628. /*
  629. * Update protocol and flow tag for MSDU
  630. * update frag index in ctx_idx field
  631. */
  632. QDF_NBUF_CB_RX_CTX_ID(head_msdu) = frags_iter;
  633. dp_rx_mon_update_protocol_flow_tag(soc, dp_pdev,
  634. head_msdu, rx_desc);
  635. /* Read buffer info from stored data in tlvs */
  636. hal_rx_mon_dest_get_buffer_info_from_tlv(rx_desc,
  637. &buf_info);
  638. frag_size = qdf_nbuf_get_frag_size_by_idx(head_msdu,
  639. frags_iter);
  640. /* If Middle buffer, dont add any header */
  641. if ((!buf_info.first_buffer) && (!buf_info.last_buffer)) {
  642. tot_msdu_len += frag_size;
  643. amsdu_pad = 0;
  644. pad_byte_pholder = 0;
  645. continue;
  646. }
  647. /* Calculate if current buffer has placeholder
  648. * to accommodate amsdu pad byte
  649. */
  650. pad_byte_pholder =
  651. (RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN) - frag_size;
  652. /*
  653. * We will come here only only three condition:
  654. * 1. Msdu with single Buffer
  655. * 2. First buffer in case MSDU is spread in multiple buffer
  656. * 3. Last buffer in case MSDU is spread in multiple buffer
  657. *
  658. * First buffER | Last buffer
  659. * Case 1: 1 | 1
  660. * Case 2: 1 | 0
  661. * Case 3: 0 | 1
  662. *
  663. * In 3rd case only l2_hdr_padding byte will be Zero and in
  664. * other case, It will be 2 Bytes.
  665. */
  666. if (buf_info.first_buffer)
  667. l2_hdr_offset = DP_RX_MON_NONRAW_L2_HDR_PAD_BYTE;
  668. else
  669. l2_hdr_offset = DP_RX_MON_RAW_L2_HDR_PAD_BYTE;
  670. if (buf_info.first_buffer) {
  671. /* Src addr from whre llc header needs to be copied */
  672. rx_src_desc = HAL_RX_DESC_GET_80211_HDR(rx_desc);
  673. /* Size of buffer with llc header */
  674. frag_size = frag_size -
  675. (l2_hdr_offset + decap_hdr_pull_bytes);
  676. frag_size += msdu_llc_len;
  677. /* Construct destination address */
  678. rx_dest_desc = frag_addr + decap_hdr_pull_bytes +
  679. l2_hdr_offset;
  680. rx_dest_desc = rx_dest_desc - (msdu_llc_len);
  681. qdf_mem_copy(rx_dest_desc, rx_src_desc, msdu_llc_len);
  682. /*
  683. * Calculate new page offset and create hole
  684. * if amsdu_pad required.
  685. */
  686. frag_page_offset = l2_hdr_offset +
  687. decap_hdr_pull_bytes;
  688. frag_page_offset = frag_page_offset -
  689. (msdu_llc_len + amsdu_pad);
  690. qdf_nbuf_move_frag_page_offset(head_msdu, frags_iter,
  691. frag_page_offset);
  692. tot_msdu_len = frag_size;
  693. /*
  694. * No amsdu padding required for first frame of
  695. * continuation buffer
  696. */
  697. if (!buf_info.last_buffer) {
  698. amsdu_pad = 0;
  699. continue;
  700. }
  701. } else {
  702. tot_msdu_len += frag_size;
  703. }
  704. /* Will reach to this place in only two case:
  705. * 1. Single buffer MSDU
  706. * 2. Last buffer of MSDU in case of multiple buffer MSDU
  707. */
  708. /* Check size of buffer if amsdu padding required */
  709. amsdu_pad = tot_msdu_len & 0x3;
  710. amsdu_pad = amsdu_pad ? (4 - amsdu_pad) : 0;
  711. /* Create placeholder if current bufer can
  712. * accommodate padding.
  713. */
  714. if (amsdu_pad <= pad_byte_pholder) {
  715. qdf_nbuf_trim_add_frag_size(head_msdu, frags_iter,
  716. amsdu_pad, 0);
  717. amsdu_pad = 0;
  718. }
  719. /* reset tot_msdu_len */
  720. tot_msdu_len = 0;
  721. }
  722. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  723. "%s %d head_msdu %pK head_msdu->len %u",
  724. __func__, __LINE__,
  725. head_msdu, head_msdu->len);
  726. mpdu_stitch_done:
  727. return head_msdu;
  728. mpdu_stitch_fail:
  729. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  730. "%s mpdu_stitch_fail head_msdu %pK", __func__, head_msdu);
  731. return NULL;
  732. }
  733. #endif
  734. static inline
  735. qdf_nbuf_t dp_rx_mon_restitch_mpdu_from_msdus(struct dp_soc *soc,
  736. uint32_t mac_id, qdf_nbuf_t head_msdu, qdf_nbuf_t last_msdu,
  737. struct cdp_mon_status *rx_status)
  738. {
  739. qdf_nbuf_t msdu, mpdu_buf, prev_buf, msdu_orig, head_frag_list;
  740. uint32_t decap_format, wifi_hdr_len, sec_hdr_len, msdu_llc_len,
  741. mpdu_buf_len, decap_hdr_pull_bytes, frag_list_sum_len, dir,
  742. is_amsdu, is_first_frag, amsdu_pad;
  743. void *rx_desc;
  744. char *hdr_desc;
  745. unsigned char *dest;
  746. struct ieee80211_frame *wh;
  747. struct ieee80211_qoscntl *qos;
  748. struct dp_pdev *dp_pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  749. head_frag_list = NULL;
  750. mpdu_buf = NULL;
  751. if (qdf_unlikely(!dp_pdev)) {
  752. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  753. "pdev is null for mac_id = %d", mac_id);
  754. return NULL;
  755. }
  756. /* The nbuf has been pulled just beyond the status and points to the
  757. * payload
  758. */
  759. if (!head_msdu)
  760. goto mpdu_stitch_fail;
  761. msdu_orig = head_msdu;
  762. rx_desc = qdf_nbuf_data(msdu_orig);
  763. if (HAL_RX_DESC_GET_MPDU_LENGTH_ERR(rx_desc)) {
  764. /* It looks like there is some issue on MPDU len err */
  765. /* Need further investigate if drop the packet */
  766. DP_STATS_INC(dp_pdev, dropped.mon_rx_drop, 1);
  767. return NULL;
  768. }
  769. rx_desc = qdf_nbuf_data(last_msdu);
  770. rx_status->cdp_rs_fcs_err = HAL_RX_DESC_GET_MPDU_FCS_ERR(rx_desc);
  771. dp_pdev->ppdu_info.rx_status.rs_fcs_err =
  772. HAL_RX_DESC_GET_MPDU_FCS_ERR(rx_desc);
  773. /* Fill out the rx_status from the PPDU start and end fields */
  774. /* HAL_RX_GET_PPDU_STATUS(soc, mac_id, rx_status); */
  775. rx_desc = qdf_nbuf_data(head_msdu);
  776. decap_format = HAL_RX_DESC_GET_DECAP_FORMAT(rx_desc);
  777. /* Easy case - The MSDU status indicates that this is a non-decapped
  778. * packet in RAW mode.
  779. */
  780. if (decap_format == HAL_HW_RX_DECAP_FORMAT_RAW) {
  781. /* Note that this path might suffer from headroom unavailabilty
  782. * - but the RX status is usually enough
  783. */
  784. dp_rx_msdus_set_payload(soc, head_msdu);
  785. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  786. "[%s][%d] decap format raw head %pK head->next %pK last_msdu %pK last_msdu->next %pK",
  787. __func__, __LINE__, head_msdu, head_msdu->next,
  788. last_msdu, last_msdu->next);
  789. mpdu_buf = head_msdu;
  790. prev_buf = mpdu_buf;
  791. frag_list_sum_len = 0;
  792. msdu = qdf_nbuf_next(head_msdu);
  793. is_first_frag = 1;
  794. while (msdu) {
  795. dp_rx_msdus_set_payload(soc, msdu);
  796. if (is_first_frag) {
  797. is_first_frag = 0;
  798. head_frag_list = msdu;
  799. }
  800. frag_list_sum_len += qdf_nbuf_len(msdu);
  801. /* Maintain the linking of the cloned MSDUS */
  802. qdf_nbuf_set_next_ext(prev_buf, msdu);
  803. /* Move to the next */
  804. prev_buf = msdu;
  805. msdu = qdf_nbuf_next(msdu);
  806. }
  807. qdf_nbuf_trim_tail(prev_buf, HAL_RX_FCS_LEN);
  808. /* If there were more fragments to this RAW frame */
  809. if (head_frag_list) {
  810. if (frag_list_sum_len <
  811. sizeof(struct ieee80211_frame_min_one)) {
  812. DP_STATS_INC(dp_pdev, dropped.mon_rx_drop, 1);
  813. return NULL;
  814. }
  815. frag_list_sum_len -= HAL_RX_FCS_LEN;
  816. qdf_nbuf_append_ext_list(mpdu_buf, head_frag_list,
  817. frag_list_sum_len);
  818. qdf_nbuf_set_next(mpdu_buf, NULL);
  819. }
  820. goto mpdu_stitch_done;
  821. }
  822. /* Decap mode:
  823. * Calculate the amount of header in decapped packet to knock off based
  824. * on the decap type and the corresponding number of raw bytes to copy
  825. * status header
  826. */
  827. rx_desc = qdf_nbuf_data(head_msdu);
  828. hdr_desc = HAL_RX_DESC_GET_80211_HDR(rx_desc);
  829. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  830. "[%s][%d] decap format not raw",
  831. __func__, __LINE__);
  832. /* Base size */
  833. wifi_hdr_len = sizeof(struct ieee80211_frame);
  834. wh = (struct ieee80211_frame *)hdr_desc;
  835. dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
  836. if (dir == IEEE80211_FC1_DIR_DSTODS)
  837. wifi_hdr_len += 6;
  838. is_amsdu = 0;
  839. if (wh->i_fc[0] & QDF_IEEE80211_FC0_SUBTYPE_QOS) {
  840. qos = (struct ieee80211_qoscntl *)
  841. (hdr_desc + wifi_hdr_len);
  842. wifi_hdr_len += 2;
  843. is_amsdu = (qos->i_qos[0] & IEEE80211_QOS_AMSDU);
  844. }
  845. /*Calculate security header length based on 'Protected'
  846. * and 'EXT_IV' flag
  847. * */
  848. if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
  849. char *iv = (char *)wh + wifi_hdr_len;
  850. if (iv[3] & KEY_EXTIV)
  851. sec_hdr_len = 8;
  852. else
  853. sec_hdr_len = 4;
  854. } else {
  855. sec_hdr_len = 0;
  856. }
  857. wifi_hdr_len += sec_hdr_len;
  858. /* MSDU related stuff LLC - AMSDU subframe header etc */
  859. msdu_llc_len = is_amsdu ? (14 + 8) : 8;
  860. mpdu_buf_len = wifi_hdr_len + msdu_llc_len;
  861. /* "Decap" header to remove from MSDU buffer */
  862. decap_hdr_pull_bytes = 14;
  863. /* Allocate a new nbuf for holding the 802.11 header retrieved from the
  864. * status of the now decapped first msdu. Leave enough headroom for
  865. * accomodating any radio-tap /prism like PHY header
  866. */
  867. mpdu_buf = qdf_nbuf_alloc(soc->osdev,
  868. MAX_MONITOR_HEADER + mpdu_buf_len,
  869. MAX_MONITOR_HEADER, 4, FALSE);
  870. if (!mpdu_buf)
  871. goto mpdu_stitch_done;
  872. /* Copy the MPDU related header and enc headers into the first buffer
  873. * - Note that there can be a 2 byte pad between heaader and enc header
  874. */
  875. prev_buf = mpdu_buf;
  876. dest = qdf_nbuf_put_tail(prev_buf, wifi_hdr_len);
  877. if (!dest)
  878. goto mpdu_stitch_fail;
  879. qdf_mem_copy(dest, hdr_desc, wifi_hdr_len);
  880. hdr_desc += wifi_hdr_len;
  881. #if 0
  882. dest = qdf_nbuf_put_tail(prev_buf, sec_hdr_len);
  883. adf_os_mem_copy(dest, hdr_desc, sec_hdr_len);
  884. hdr_desc += sec_hdr_len;
  885. #endif
  886. /* The first LLC len is copied into the MPDU buffer */
  887. frag_list_sum_len = 0;
  888. msdu_orig = head_msdu;
  889. is_first_frag = 1;
  890. amsdu_pad = 0;
  891. while (msdu_orig) {
  892. /* TODO: intra AMSDU padding - do we need it ??? */
  893. msdu = msdu_orig;
  894. if (is_first_frag) {
  895. head_frag_list = msdu;
  896. } else {
  897. /* Reload the hdr ptr only on non-first MSDUs */
  898. rx_desc = qdf_nbuf_data(msdu_orig);
  899. hdr_desc = HAL_RX_DESC_GET_80211_HDR(rx_desc);
  900. }
  901. /* Copy this buffers MSDU related status into the prev buffer */
  902. if (is_first_frag) {
  903. is_first_frag = 0;
  904. }
  905. /* Update protocol and flow tag for MSDU */
  906. dp_rx_mon_update_protocol_flow_tag(soc, dp_pdev,
  907. msdu_orig, rx_desc);
  908. dest = qdf_nbuf_put_tail(prev_buf,
  909. msdu_llc_len + amsdu_pad);
  910. if (!dest)
  911. goto mpdu_stitch_fail;
  912. dest += amsdu_pad;
  913. qdf_mem_copy(dest, hdr_desc, msdu_llc_len);
  914. dp_rx_msdus_set_payload(soc, msdu);
  915. /* Push the MSDU buffer beyond the decap header */
  916. qdf_nbuf_pull_head(msdu, decap_hdr_pull_bytes);
  917. frag_list_sum_len += msdu_llc_len + qdf_nbuf_len(msdu)
  918. + amsdu_pad;
  919. /* Set up intra-AMSDU pad to be added to start of next buffer -
  920. * AMSDU pad is 4 byte pad on AMSDU subframe */
  921. amsdu_pad = (msdu_llc_len + qdf_nbuf_len(msdu)) & 0x3;
  922. amsdu_pad = amsdu_pad ? (4 - amsdu_pad) : 0;
  923. /* TODO FIXME How do we handle MSDUs that have fraglist - Should
  924. * probably iterate all the frags cloning them along the way and
  925. * and also updating the prev_buf pointer
  926. */
  927. /* Move to the next */
  928. prev_buf = msdu;
  929. msdu_orig = qdf_nbuf_next(msdu_orig);
  930. }
  931. #if 0
  932. /* Add in the trailer section - encryption trailer + FCS */
  933. qdf_nbuf_put_tail(prev_buf, HAL_RX_FCS_LEN);
  934. frag_list_sum_len += HAL_RX_FCS_LEN;
  935. #endif
  936. frag_list_sum_len -= msdu_llc_len;
  937. /* TODO: Convert this to suitable adf routines */
  938. qdf_nbuf_append_ext_list(mpdu_buf, head_frag_list,
  939. frag_list_sum_len);
  940. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  941. "%s %d mpdu_buf %pK mpdu_buf->len %u",
  942. __func__, __LINE__,
  943. mpdu_buf, mpdu_buf->len);
  944. mpdu_stitch_done:
  945. /* Check if this buffer contains the PPDU end status for TSF */
  946. /* Need revist this code to see where we can get tsf timestamp */
  947. #if 0
  948. /* PPDU end TLV will be retrieved from monitor status ring */
  949. last_mpdu =
  950. (*(((u_int32_t *)&rx_desc->attention)) &
  951. RX_ATTENTION_0_LAST_MPDU_MASK) >>
  952. RX_ATTENTION_0_LAST_MPDU_LSB;
  953. if (last_mpdu)
  954. rx_status->rs_tstamp.tsf = rx_desc->ppdu_end.tsf_timestamp;
  955. #endif
  956. return mpdu_buf;
  957. mpdu_stitch_fail:
  958. if ((mpdu_buf) && (decap_format != HAL_HW_RX_DECAP_FORMAT_RAW)) {
  959. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  960. "%s mpdu_stitch_fail mpdu_buf %pK",
  961. __func__, mpdu_buf);
  962. /* Free the head buffer */
  963. qdf_nbuf_free(mpdu_buf);
  964. }
  965. return NULL;
  966. }
  967. #ifdef DP_RX_MON_MEM_FRAG
  968. #if defined(WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG) ||\
  969. defined(WLAN_SUPPORT_RX_FLOW_TAG)
  970. static inline
  971. void dp_rx_mon_update_pf_tag_to_buf_headroom(struct dp_soc *soc,
  972. struct dp_pdev *pdev,
  973. qdf_nbuf_t nbuf)
  974. {
  975. bool is_mon_protocol_flow_tag_enabled;
  976. if (qdf_unlikely(!soc || !pdev || !nbuf))
  977. return;
  978. /* Return if it dint came from mon Path */
  979. if (!qdf_nbuf_get_nr_frags(nbuf))
  980. return;
  981. is_mon_protocol_flow_tag_enabled =
  982. wlan_cfg_is_rx_mon_protocol_flow_tag_enabled(soc->wlan_cfg_ctx);
  983. if (qdf_unlikely(!is_mon_protocol_flow_tag_enabled))
  984. return;
  985. if (qdf_likely(!pdev->is_rx_protocol_tagging_enabled))
  986. return;
  987. if (qdf_unlikely(qdf_nbuf_headroom(nbuf) < DP_RX_MON_PF_TAG_TOT_LEN)) {
  988. dp_err("Nbuf avail Headroom[%d] < DP_RX_MON_PF_TAG_TOT_LEN[%d]",
  989. qdf_nbuf_headroom(nbuf), DP_RX_MON_PF_TAG_TOT_LEN);
  990. return;
  991. }
  992. qdf_nbuf_push_head(nbuf, DP_RX_MON_PF_TAG_TOT_LEN);
  993. qdf_mem_copy(qdf_nbuf_data(nbuf), qdf_nbuf_head(nbuf),
  994. DP_RX_MON_PF_TAG_TOT_LEN);
  995. qdf_nbuf_pull_head(nbuf, DP_RX_MON_PF_TAG_TOT_LEN);
  996. }
  997. #else
  998. static inline
  999. void dp_rx_mon_update_pf_tag_to_buf_headroom(struct dp_soc *soc,
  1000. struct dp_pdev *pdev,
  1001. qdf_nbuf_t nbuf)
  1002. {
  1003. }
  1004. #endif
  1005. #else
  1006. static inline
  1007. void dp_rx_mon_update_pf_tag_to_buf_headroom(struct dp_soc *soc,
  1008. struct dp_pdev *pdev,
  1009. qdf_nbuf_t nbuf)
  1010. {
  1011. }
  1012. #endif
  1013. /**
  1014. * dp_send_mgmt_packet_to_stack(): send indicataion to upper layers
  1015. *
  1016. * @soc: soc handle
  1017. * @nbuf: Mgmt packet
  1018. * @pdev: pdev handle
  1019. *
  1020. * Return: QDF_STATUS_SUCCESS on success
  1021. * QDF_STATUS_E_INVAL in error
  1022. */
  1023. #ifdef FEATURE_PERPKT_INFO
  1024. static inline QDF_STATUS dp_send_mgmt_packet_to_stack(struct dp_soc *soc,
  1025. qdf_nbuf_t nbuf,
  1026. struct dp_pdev *pdev)
  1027. {
  1028. uint32_t *nbuf_data;
  1029. struct ieee80211_frame *wh;
  1030. qdf_frag_t addr;
  1031. if (!nbuf)
  1032. return QDF_STATUS_E_INVAL;
  1033. /* Get addr pointing to80211 header */
  1034. addr = dp_rx_mon_get_nbuf_80211_hdr(nbuf);
  1035. if (qdf_unlikely(!addr)) {
  1036. qdf_nbuf_free(nbuf);
  1037. return QDF_STATUS_E_INVAL;
  1038. }
  1039. /*check if this is not a mgmt packet*/
  1040. wh = (struct ieee80211_frame *)addr;
  1041. if (((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) !=
  1042. IEEE80211_FC0_TYPE_MGT) &&
  1043. ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) !=
  1044. IEEE80211_FC0_TYPE_CTL)) {
  1045. qdf_nbuf_free(nbuf);
  1046. return QDF_STATUS_E_INVAL;
  1047. }
  1048. nbuf_data = (uint32_t *)qdf_nbuf_push_head(nbuf, 4);
  1049. if (!nbuf_data) {
  1050. QDF_TRACE(QDF_MODULE_ID_DP,
  1051. QDF_TRACE_LEVEL_ERROR,
  1052. FL("No headroom"));
  1053. qdf_nbuf_free(nbuf);
  1054. return QDF_STATUS_E_INVAL;
  1055. }
  1056. *nbuf_data = pdev->ppdu_info.com_info.ppdu_id;
  1057. dp_rx_mon_update_pf_tag_to_buf_headroom(soc, pdev, nbuf);
  1058. dp_wdi_event_handler(WDI_EVENT_RX_MGMT_CTRL, soc, nbuf,
  1059. HTT_INVALID_PEER,
  1060. WDI_NO_VAL, pdev->pdev_id);
  1061. return QDF_STATUS_SUCCESS;
  1062. }
  1063. #else
  1064. static inline QDF_STATUS dp_send_mgmt_packet_to_stack(struct dp_soc *soc,
  1065. qdf_nbuf_t nbuf,
  1066. struct dp_pdev *pdev)
  1067. {
  1068. return QDF_STATUS_SUCCESS;
  1069. }
  1070. #endif
  1071. /**
  1072. * dp_rx_extract_radiotap_info(): Extract and populate information in
  1073. * struct mon_rx_status type
  1074. * @rx_status: Receive status
  1075. * @mon_rx_status: Monitor mode status
  1076. *
  1077. * Returns: None
  1078. */
  1079. static inline
  1080. void dp_rx_extract_radiotap_info(struct cdp_mon_status *rx_status,
  1081. struct mon_rx_status *rx_mon_status)
  1082. {
  1083. rx_mon_status->tsft = rx_status->cdp_rs_tstamp.cdp_tsf;
  1084. rx_mon_status->chan_freq = rx_status->rs_freq;
  1085. rx_mon_status->chan_num = rx_status->rs_channel;
  1086. rx_mon_status->chan_flags = rx_status->rs_flags;
  1087. rx_mon_status->rate = rx_status->rs_datarate;
  1088. /* TODO: rx_mon_status->ant_signal_db */
  1089. /* TODO: rx_mon_status->nr_ant */
  1090. rx_mon_status->mcs = rx_status->cdf_rs_rate_mcs;
  1091. rx_mon_status->is_stbc = rx_status->cdp_rs_stbc;
  1092. rx_mon_status->sgi = rx_status->cdp_rs_sgi;
  1093. /* TODO: rx_mon_status->ldpc */
  1094. /* TODO: rx_mon_status->beamformed */
  1095. /* TODO: rx_mon_status->vht_flags */
  1096. /* TODO: rx_mon_status->vht_flag_values1 */
  1097. }
  1098. #ifdef DP_RX_MON_MEM_FRAG
  1099. static inline
  1100. qdf_nbuf_t dp_rx_mon_restitch_mpdu(struct dp_soc *soc, uint32_t mac_id,
  1101. qdf_nbuf_t head_msdu, qdf_nbuf_t tail_msdu,
  1102. struct cdp_mon_status *rs)
  1103. {
  1104. if (qdf_nbuf_get_nr_frags(head_msdu))
  1105. return dp_rx_mon_frag_restitch_mpdu_from_msdus(soc, mac_id,
  1106. head_msdu, rs);
  1107. else
  1108. return dp_rx_mon_restitch_mpdu_from_msdus(soc, mac_id,
  1109. head_msdu,
  1110. tail_msdu, rs);
  1111. }
  1112. #else
  1113. static inline
  1114. qdf_nbuf_t dp_rx_mon_restitch_mpdu(struct dp_soc *soc, uint32_t mac_id,
  1115. qdf_nbuf_t head_msdu, qdf_nbuf_t tail_msdu,
  1116. struct cdp_mon_status *rs)
  1117. {
  1118. return dp_rx_mon_restitch_mpdu_from_msdus(soc, mac_id, head_msdu,
  1119. tail_msdu, rs);
  1120. }
  1121. #endif
  1122. /*
  1123. * dp_rx_mon_deliver(): function to deliver packets to stack
  1124. * @soc: DP soc
  1125. * @mac_id: MAC ID
  1126. * @head_msdu: head of msdu list
  1127. * @tail_msdu: tail of msdu list
  1128. *
  1129. * Return: status: 0 - Success, non-zero: Failure
  1130. */
  1131. QDF_STATUS dp_rx_mon_deliver(struct dp_soc *soc, uint32_t mac_id,
  1132. qdf_nbuf_t head_msdu, qdf_nbuf_t tail_msdu)
  1133. {
  1134. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  1135. struct cdp_mon_status *rs = &pdev->rx_mon_recv_status;
  1136. qdf_nbuf_t mon_skb, skb_next;
  1137. qdf_nbuf_t mon_mpdu = NULL;
  1138. if (!pdev || (!pdev->monitor_vdev && !pdev->mcopy_mode))
  1139. goto mon_deliver_fail;
  1140. /* restitch mon MPDU for delivery via monitor interface */
  1141. mon_mpdu = dp_rx_mon_restitch_mpdu(soc, mac_id, head_msdu,
  1142. tail_msdu, rs);
  1143. /* monitor vap cannot be present when mcopy is enabled
  1144. * hence same skb can be consumed
  1145. */
  1146. if (pdev->mcopy_mode)
  1147. return dp_send_mgmt_packet_to_stack(soc, mon_mpdu, pdev);
  1148. if (mon_mpdu && pdev->monitor_vdev && pdev->monitor_vdev->osif_vdev &&
  1149. pdev->monitor_vdev->osif_rx_mon) {
  1150. pdev->ppdu_info.rx_status.ppdu_id =
  1151. pdev->ppdu_info.com_info.ppdu_id;
  1152. pdev->ppdu_info.rx_status.device_id = soc->device_id;
  1153. pdev->ppdu_info.rx_status.chan_noise_floor =
  1154. pdev->chan_noise_floor;
  1155. dp_handle_tx_capture(soc, pdev, mon_mpdu);
  1156. if (!qdf_nbuf_update_radiotap(&pdev->ppdu_info.rx_status,
  1157. mon_mpdu,
  1158. qdf_nbuf_headroom(mon_mpdu))) {
  1159. DP_STATS_INC(pdev, dropped.mon_radiotap_update_err, 1);
  1160. goto mon_deliver_fail;
  1161. }
  1162. dp_rx_mon_update_pf_tag_to_buf_headroom(soc, pdev, head_msdu);
  1163. pdev->monitor_vdev->osif_rx_mon(pdev->monitor_vdev->osif_vdev,
  1164. mon_mpdu,
  1165. &pdev->ppdu_info.rx_status);
  1166. } else {
  1167. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1168. "[%s][%d] mon_mpdu=%pK monitor_vdev %pK osif_vdev %pK"
  1169. , __func__, __LINE__, mon_mpdu, pdev->monitor_vdev,
  1170. (pdev->monitor_vdev ? pdev->monitor_vdev->osif_vdev
  1171. : NULL));
  1172. goto mon_deliver_fail;
  1173. }
  1174. return QDF_STATUS_SUCCESS;
  1175. mon_deliver_fail:
  1176. mon_skb = head_msdu;
  1177. while (mon_skb) {
  1178. skb_next = qdf_nbuf_next(mon_skb);
  1179. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1180. "[%s][%d] mon_skb=%pK len %u", __func__,
  1181. __LINE__, mon_skb, mon_skb->len);
  1182. qdf_nbuf_free(mon_skb);
  1183. mon_skb = skb_next;
  1184. }
  1185. return QDF_STATUS_E_INVAL;
  1186. }
  1187. /**
  1188. * dp_rx_mon_deliver_non_std()
  1189. * @soc: core txrx main contex
  1190. * @mac_id: MAC ID
  1191. *
  1192. * This function delivers the radio tap and dummy MSDU
  1193. * into user layer application for preamble only PPDU.
  1194. *
  1195. * Return: QDF_STATUS
  1196. */
  1197. QDF_STATUS dp_rx_mon_deliver_non_std(struct dp_soc *soc,
  1198. uint32_t mac_id)
  1199. {
  1200. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  1201. ol_txrx_rx_mon_fp osif_rx_mon;
  1202. qdf_nbuf_t dummy_msdu;
  1203. /* Sanity checking */
  1204. if (!pdev || !pdev->monitor_vdev || !pdev->monitor_vdev->osif_rx_mon)
  1205. goto mon_deliver_non_std_fail;
  1206. /* Generate a dummy skb_buff */
  1207. osif_rx_mon = pdev->monitor_vdev->osif_rx_mon;
  1208. dummy_msdu = qdf_nbuf_alloc(soc->osdev, MAX_MONITOR_HEADER,
  1209. MAX_MONITOR_HEADER, 4, FALSE);
  1210. if (!dummy_msdu)
  1211. goto allocate_dummy_msdu_fail;
  1212. qdf_nbuf_set_pktlen(dummy_msdu, 0);
  1213. qdf_nbuf_set_next(dummy_msdu, NULL);
  1214. pdev->ppdu_info.rx_status.ppdu_id =
  1215. pdev->ppdu_info.com_info.ppdu_id;
  1216. /* Apply the radio header to this dummy skb */
  1217. if (!qdf_nbuf_update_radiotap(&pdev->ppdu_info.rx_status, dummy_msdu,
  1218. qdf_nbuf_headroom(dummy_msdu))) {
  1219. DP_STATS_INC(pdev, dropped.mon_radiotap_update_err, 1);
  1220. qdf_nbuf_free(dummy_msdu);
  1221. goto mon_deliver_non_std_fail;
  1222. }
  1223. /* deliver to the user layer application */
  1224. osif_rx_mon(pdev->monitor_vdev->osif_vdev,
  1225. dummy_msdu, NULL);
  1226. /* Clear rx_status*/
  1227. qdf_mem_zero(&pdev->ppdu_info.rx_status,
  1228. sizeof(pdev->ppdu_info.rx_status));
  1229. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  1230. return QDF_STATUS_SUCCESS;
  1231. allocate_dummy_msdu_fail:
  1232. QDF_TRACE_DEBUG_RL(QDF_MODULE_ID_DP, "[%s][%d] mon_skb=%pK ",
  1233. __func__, __LINE__, dummy_msdu);
  1234. mon_deliver_non_std_fail:
  1235. return QDF_STATUS_E_INVAL;
  1236. }
  1237. void dp_rx_mon_dest_process(struct dp_soc *soc, struct dp_intr *int_ctx,
  1238. uint32_t mac_id, uint32_t quota)
  1239. {
  1240. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  1241. uint8_t pdev_id;
  1242. hal_rxdma_desc_t rxdma_dst_ring_desc;
  1243. hal_soc_handle_t hal_soc;
  1244. void *mon_dst_srng;
  1245. union dp_rx_desc_list_elem_t *head = NULL;
  1246. union dp_rx_desc_list_elem_t *tail = NULL;
  1247. uint32_t ppdu_id;
  1248. uint32_t rx_bufs_used;
  1249. uint32_t mpdu_rx_bufs_used;
  1250. int mac_for_pdev = mac_id;
  1251. struct cdp_pdev_mon_stats *rx_mon_stats;
  1252. if (!pdev) {
  1253. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1254. "pdev is null for mac_id = %d", mac_id);
  1255. return;
  1256. }
  1257. mon_dst_srng = dp_rxdma_get_mon_dst_ring(pdev, mac_for_pdev);
  1258. if (!mon_dst_srng || !hal_srng_initialized(mon_dst_srng)) {
  1259. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1260. "%s %d : HAL Monitor Destination Ring Init Failed -- %pK",
  1261. __func__, __LINE__, mon_dst_srng);
  1262. return;
  1263. }
  1264. hal_soc = soc->hal_soc;
  1265. qdf_assert((hal_soc && pdev));
  1266. qdf_spin_lock_bh(&pdev->mon_lock);
  1267. if (qdf_unlikely(dp_srng_access_start(int_ctx, soc, mon_dst_srng))) {
  1268. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1269. "%s %d : HAL Monitor Destination Ring access Failed -- %pK",
  1270. __func__, __LINE__, mon_dst_srng);
  1271. return;
  1272. }
  1273. pdev_id = pdev->pdev_id;
  1274. ppdu_id = pdev->ppdu_info.com_info.ppdu_id;
  1275. rx_bufs_used = 0;
  1276. rx_mon_stats = &pdev->rx_mon_stats;
  1277. while (qdf_likely(rxdma_dst_ring_desc =
  1278. hal_srng_dst_peek(hal_soc, mon_dst_srng))) {
  1279. qdf_nbuf_t head_msdu, tail_msdu;
  1280. uint32_t npackets;
  1281. head_msdu = (qdf_nbuf_t) NULL;
  1282. tail_msdu = (qdf_nbuf_t) NULL;
  1283. mpdu_rx_bufs_used =
  1284. dp_rx_mon_mpdu_pop(soc, mac_id,
  1285. rxdma_dst_ring_desc,
  1286. &head_msdu, &tail_msdu,
  1287. &npackets, &ppdu_id,
  1288. &head, &tail);
  1289. rx_bufs_used += mpdu_rx_bufs_used;
  1290. if (mpdu_rx_bufs_used)
  1291. pdev->mon_dest_ring_stuck_cnt = 0;
  1292. else
  1293. pdev->mon_dest_ring_stuck_cnt++;
  1294. if (pdev->mon_dest_ring_stuck_cnt >
  1295. MON_DEST_RING_STUCK_MAX_CNT) {
  1296. dp_info("destination ring stuck");
  1297. dp_info("ppdu_id status=%d dest=%d",
  1298. pdev->ppdu_info.com_info.ppdu_id, ppdu_id);
  1299. rx_mon_stats->mon_rx_dest_stuck++;
  1300. pdev->ppdu_info.com_info.ppdu_id = ppdu_id;
  1301. continue;
  1302. }
  1303. if (ppdu_id != pdev->ppdu_info.com_info.ppdu_id) {
  1304. rx_mon_stats->stat_ring_ppdu_id_hist[
  1305. rx_mon_stats->ppdu_id_hist_idx] =
  1306. pdev->ppdu_info.com_info.ppdu_id;
  1307. rx_mon_stats->dest_ring_ppdu_id_hist[
  1308. rx_mon_stats->ppdu_id_hist_idx] = ppdu_id;
  1309. rx_mon_stats->ppdu_id_hist_idx =
  1310. (rx_mon_stats->ppdu_id_hist_idx + 1) &
  1311. (MAX_PPDU_ID_HIST - 1);
  1312. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  1313. qdf_mem_zero(&(pdev->ppdu_info.rx_status),
  1314. sizeof(pdev->ppdu_info.rx_status));
  1315. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1316. "%s %d ppdu_id %x != ppdu_info.com_info.ppdu_id %x",
  1317. __func__, __LINE__,
  1318. ppdu_id, pdev->ppdu_info.com_info.ppdu_id);
  1319. break;
  1320. }
  1321. if (qdf_likely((head_msdu) &&
  1322. (DP_RX_MON_IS_MSDU_NOT_NULL(tail_msdu)))) {
  1323. rx_mon_stats->dest_mpdu_done++;
  1324. dp_rx_mon_deliver(soc, mac_id, head_msdu, tail_msdu);
  1325. }
  1326. rxdma_dst_ring_desc = hal_srng_dst_get_next(hal_soc,
  1327. mon_dst_srng);
  1328. }
  1329. dp_srng_access_end(int_ctx, soc, mon_dst_srng);
  1330. qdf_spin_unlock_bh(&pdev->mon_lock);
  1331. if (rx_bufs_used) {
  1332. rx_mon_stats->dest_ppdu_done++;
  1333. dp_rx_buffers_replenish(soc, mac_id,
  1334. dp_rxdma_get_mon_buf_ring(pdev,
  1335. mac_for_pdev),
  1336. dp_rx_get_mon_desc_pool(soc, mac_id,
  1337. pdev_id),
  1338. rx_bufs_used, &head, &tail);
  1339. }
  1340. }
  1341. QDF_STATUS
  1342. dp_rx_pdev_mon_buf_buffers_alloc(struct dp_pdev *pdev, uint32_t mac_id,
  1343. bool delayed_replenish)
  1344. {
  1345. uint8_t pdev_id = pdev->pdev_id;
  1346. struct dp_soc *soc = pdev->soc;
  1347. struct dp_srng *mon_buf_ring;
  1348. uint32_t num_entries;
  1349. struct rx_desc_pool *rx_desc_pool;
  1350. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1351. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx = soc->wlan_cfg_ctx;
  1352. mon_buf_ring = dp_rxdma_get_mon_buf_ring(pdev, mac_id);
  1353. num_entries = mon_buf_ring->num_entries;
  1354. rx_desc_pool = dp_rx_get_mon_desc_pool(soc, mac_id, pdev_id);
  1355. dp_debug("Mon RX Desc Pool[%d] entries=%u", pdev_id, num_entries);
  1356. /* Replenish RXDMA monitor buffer ring with 8 buffers only
  1357. * delayed_replenish_entries is actually 8 but when we call
  1358. * dp_pdev_rx_buffers_attach() we pass 1 less than 8, hence
  1359. * added 1 to delayed_replenish_entries to ensure we have 8
  1360. * entries. Once the monitor VAP is configured we replenish
  1361. * the complete RXDMA monitor buffer ring.
  1362. */
  1363. if (delayed_replenish) {
  1364. num_entries = soc_cfg_ctx->delayed_replenish_entries + 1;
  1365. status = dp_pdev_rx_buffers_attach(soc, mac_id, mon_buf_ring,
  1366. rx_desc_pool,
  1367. num_entries - 1);
  1368. } else {
  1369. union dp_rx_desc_list_elem_t *tail = NULL;
  1370. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1371. status = dp_rx_buffers_replenish(soc, mac_id,
  1372. mon_buf_ring,
  1373. rx_desc_pool,
  1374. num_entries,
  1375. &desc_list,
  1376. &tail);
  1377. }
  1378. return status;
  1379. }
  1380. static QDF_STATUS
  1381. dp_rx_pdev_mon_cmn_buffers_alloc(struct dp_pdev *pdev, int mac_id)
  1382. {
  1383. struct dp_soc *soc = pdev->soc;
  1384. uint8_t pdev_id = pdev->pdev_id;
  1385. int mac_for_pdev;
  1386. bool delayed_replenish;
  1387. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1388. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx = soc->wlan_cfg_ctx;
  1389. delayed_replenish = soc_cfg_ctx->delayed_replenish_entries ? 1 : 0;
  1390. mac_for_pdev = dp_get_lmac_id_for_pdev_id(pdev->soc, mac_id, pdev_id);
  1391. status = dp_rx_pdev_mon_status_buffers_alloc(pdev, mac_for_pdev);
  1392. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1393. dp_err("%s: dp_rx_pdev_mon_status_desc_pool_alloc() failed",
  1394. __func__);
  1395. goto fail;
  1396. }
  1397. if (!soc->wlan_cfg_ctx->rxdma1_enable)
  1398. return status;
  1399. status = dp_rx_pdev_mon_buf_buffers_alloc(pdev, mac_for_pdev,
  1400. delayed_replenish);
  1401. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1402. dp_err("%s: dp_rx_pdev_mon_buf_desc_pool_alloc() failed\n",
  1403. __func__);
  1404. goto mon_stat_buf_dealloc;
  1405. }
  1406. return status;
  1407. mon_stat_buf_dealloc:
  1408. dp_rx_pdev_mon_status_buffers_free(pdev, mac_for_pdev);
  1409. fail:
  1410. return status;
  1411. }
  1412. static void
  1413. dp_rx_pdev_mon_buf_desc_pool_init(struct dp_pdev *pdev, uint32_t mac_id)
  1414. {
  1415. uint8_t pdev_id = pdev->pdev_id;
  1416. struct dp_soc *soc = pdev->soc;
  1417. struct dp_srng *mon_buf_ring;
  1418. uint32_t num_entries;
  1419. struct rx_desc_pool *rx_desc_pool;
  1420. uint32_t rx_desc_pool_size;
  1421. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx = soc->wlan_cfg_ctx;
  1422. mon_buf_ring = &soc->rxdma_mon_buf_ring[mac_id];
  1423. num_entries = mon_buf_ring->num_entries;
  1424. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1425. dp_debug("Mon RX Desc buf Pool[%d] init entries=%u",
  1426. pdev_id, num_entries);
  1427. rx_desc_pool_size = wlan_cfg_get_dp_soc_rx_sw_desc_weight(soc_cfg_ctx) *
  1428. num_entries;
  1429. rx_desc_pool->owner = HAL_RX_BUF_RBM_SW3_BM;
  1430. rx_desc_pool->buf_size = RX_MONITOR_BUFFER_SIZE;
  1431. rx_desc_pool->buf_alignment = RX_MONITOR_BUFFER_ALIGNMENT;
  1432. /* Enable frag processing if feature is enabled */
  1433. dp_rx_enable_mon_dest_frag(rx_desc_pool, true);
  1434. dp_rx_desc_pool_init(soc, mac_id, rx_desc_pool_size, rx_desc_pool);
  1435. pdev->mon_last_linkdesc_paddr = 0;
  1436. pdev->mon_last_buf_cookie = DP_RX_DESC_COOKIE_MAX + 1;
  1437. /* Attach full monitor mode resources */
  1438. dp_full_mon_attach(pdev);
  1439. }
  1440. static void
  1441. dp_rx_pdev_mon_cmn_desc_pool_init(struct dp_pdev *pdev, int mac_id)
  1442. {
  1443. struct dp_soc *soc = pdev->soc;
  1444. uint32_t mac_for_pdev;
  1445. mac_for_pdev = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev->pdev_id);
  1446. dp_rx_pdev_mon_status_desc_pool_init(pdev, mac_for_pdev);
  1447. if (!soc->wlan_cfg_ctx->rxdma1_enable)
  1448. return;
  1449. dp_rx_pdev_mon_buf_desc_pool_init(pdev, mac_for_pdev);
  1450. dp_link_desc_ring_replenish(soc, mac_for_pdev);
  1451. }
  1452. static void
  1453. dp_rx_pdev_mon_buf_desc_pool_deinit(struct dp_pdev *pdev, uint32_t mac_id)
  1454. {
  1455. uint8_t pdev_id = pdev->pdev_id;
  1456. struct dp_soc *soc = pdev->soc;
  1457. struct rx_desc_pool *rx_desc_pool;
  1458. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1459. dp_debug("Mon RX Desc buf Pool[%d] deinit", pdev_id);
  1460. dp_rx_desc_pool_deinit(soc, rx_desc_pool);
  1461. /* Detach full monitor mode resources */
  1462. dp_full_mon_detach(pdev);
  1463. }
  1464. static void
  1465. dp_rx_pdev_mon_cmn_desc_pool_deinit(struct dp_pdev *pdev, int mac_id)
  1466. {
  1467. struct dp_soc *soc = pdev->soc;
  1468. uint8_t pdev_id = pdev->pdev_id;
  1469. int mac_for_pdev = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  1470. dp_rx_pdev_mon_status_desc_pool_deinit(pdev, mac_for_pdev);
  1471. if (!soc->wlan_cfg_ctx->rxdma1_enable)
  1472. return;
  1473. dp_rx_pdev_mon_buf_desc_pool_deinit(pdev, mac_for_pdev);
  1474. }
  1475. static void
  1476. dp_rx_pdev_mon_buf_desc_pool_free(struct dp_pdev *pdev, uint32_t mac_id)
  1477. {
  1478. uint8_t pdev_id = pdev->pdev_id;
  1479. struct dp_soc *soc = pdev->soc;
  1480. struct rx_desc_pool *rx_desc_pool;
  1481. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1482. dp_debug("Mon RX Buf Desc Pool Free pdev[%d]", pdev_id);
  1483. dp_rx_desc_pool_free(soc, rx_desc_pool);
  1484. }
  1485. static void
  1486. dp_rx_pdev_mon_cmn_desc_pool_free(struct dp_pdev *pdev, int mac_id)
  1487. {
  1488. struct dp_soc *soc = pdev->soc;
  1489. uint8_t pdev_id = pdev->pdev_id;
  1490. int mac_for_pdev = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  1491. dp_rx_pdev_mon_status_desc_pool_free(pdev, mac_for_pdev);
  1492. dp_rx_pdev_mon_buf_desc_pool_free(pdev, mac_for_pdev);
  1493. dp_hw_link_desc_pool_banks_free(soc, mac_for_pdev);
  1494. }
  1495. void dp_rx_pdev_mon_buf_buffers_free(struct dp_pdev *pdev, uint32_t mac_id)
  1496. {
  1497. uint8_t pdev_id = pdev->pdev_id;
  1498. struct dp_soc *soc = pdev->soc;
  1499. struct rx_desc_pool *rx_desc_pool;
  1500. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1501. dp_debug("Mon RX Buf buffers Free pdev[%d]", pdev_id);
  1502. if (rx_desc_pool->rx_mon_dest_frag_enable)
  1503. dp_rx_desc_frag_free(soc, rx_desc_pool);
  1504. else
  1505. dp_rx_desc_nbuf_free(soc, rx_desc_pool);
  1506. }
  1507. static QDF_STATUS
  1508. dp_rx_pdev_mon_buf_desc_pool_alloc(struct dp_pdev *pdev, uint32_t mac_id)
  1509. {
  1510. uint8_t pdev_id = pdev->pdev_id;
  1511. struct dp_soc *soc = pdev->soc;
  1512. struct dp_srng *mon_buf_ring;
  1513. uint32_t num_entries;
  1514. struct rx_desc_pool *rx_desc_pool;
  1515. uint32_t rx_desc_pool_size;
  1516. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx = soc->wlan_cfg_ctx;
  1517. mon_buf_ring = &soc->rxdma_mon_buf_ring[mac_id];
  1518. num_entries = mon_buf_ring->num_entries;
  1519. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1520. dp_debug("Mon RX Desc Pool[%d] entries=%u",
  1521. pdev_id, num_entries);
  1522. rx_desc_pool_size = wlan_cfg_get_dp_soc_rx_sw_desc_weight(soc_cfg_ctx) *
  1523. num_entries;
  1524. return dp_rx_desc_pool_alloc(soc, rx_desc_pool_size, rx_desc_pool);
  1525. }
  1526. static QDF_STATUS
  1527. dp_rx_pdev_mon_cmn_desc_pool_alloc(struct dp_pdev *pdev, int mac_id)
  1528. {
  1529. struct dp_soc *soc = pdev->soc;
  1530. uint8_t pdev_id = pdev->pdev_id;
  1531. uint32_t mac_for_pdev;
  1532. QDF_STATUS status;
  1533. mac_for_pdev = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  1534. /* Allocate sw rx descriptor pool for monitor status ring */
  1535. status = dp_rx_pdev_mon_status_desc_pool_alloc(pdev, mac_for_pdev);
  1536. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1537. dp_err("%s: dp_rx_pdev_mon_status_desc_pool_alloc() failed",
  1538. __func__);
  1539. goto fail;
  1540. }
  1541. if (!soc->wlan_cfg_ctx->rxdma1_enable)
  1542. return status;
  1543. /* Allocate sw rx descriptor pool for monitor RxDMA buffer ring */
  1544. status = dp_rx_pdev_mon_buf_desc_pool_alloc(pdev, mac_for_pdev);
  1545. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1546. dp_err("%s: dp_rx_pdev_mon_buf_desc_pool_alloc() failed\n",
  1547. __func__);
  1548. goto mon_status_dealloc;
  1549. }
  1550. /* Allocate link descriptors for the monitor link descriptor ring */
  1551. status = dp_hw_link_desc_pool_banks_alloc(soc, mac_for_pdev);
  1552. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1553. dp_err("%s: dp_hw_link_desc_pool_banks_alloc() failed",
  1554. __func__);
  1555. goto mon_buf_dealloc;
  1556. }
  1557. return status;
  1558. mon_buf_dealloc:
  1559. dp_rx_pdev_mon_buf_desc_pool_free(pdev, mac_for_pdev);
  1560. mon_status_dealloc:
  1561. dp_rx_pdev_mon_status_desc_pool_free(pdev, mac_for_pdev);
  1562. fail:
  1563. return status;
  1564. }
  1565. static void
  1566. dp_rx_pdev_mon_cmn_buffers_free(struct dp_pdev *pdev, int mac_id)
  1567. {
  1568. uint8_t pdev_id = pdev->pdev_id;
  1569. struct dp_soc *soc = pdev->soc;
  1570. int mac_for_pdev;
  1571. mac_for_pdev = dp_get_lmac_id_for_pdev_id(pdev->soc, mac_id, pdev_id);
  1572. dp_rx_pdev_mon_status_buffers_free(pdev, mac_for_pdev);
  1573. if (!soc->wlan_cfg_ctx->rxdma1_enable)
  1574. return;
  1575. dp_rx_pdev_mon_buf_buffers_free(pdev, mac_for_pdev);
  1576. }
  1577. QDF_STATUS
  1578. dp_rx_pdev_mon_desc_pool_alloc(struct dp_pdev *pdev)
  1579. {
  1580. QDF_STATUS status;
  1581. int mac_id, count;
  1582. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  1583. status = dp_rx_pdev_mon_cmn_desc_pool_alloc(pdev, mac_id);
  1584. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1585. QDF_TRACE(QDF_MODULE_ID_DP,
  1586. QDF_TRACE_LEVEL_ERROR, "%s: %d failed\n",
  1587. __func__, mac_id);
  1588. for (count = 0; count < mac_id; count++)
  1589. dp_rx_pdev_mon_cmn_desc_pool_free(pdev, count);
  1590. return status;
  1591. }
  1592. }
  1593. return status;
  1594. }
  1595. void
  1596. dp_rx_pdev_mon_desc_pool_init(struct dp_pdev *pdev)
  1597. {
  1598. int mac_id;
  1599. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++)
  1600. dp_rx_pdev_mon_cmn_desc_pool_init(pdev, mac_id);
  1601. qdf_spinlock_create(&pdev->mon_lock);
  1602. }
  1603. void
  1604. dp_rx_pdev_mon_desc_pool_deinit(struct dp_pdev *pdev)
  1605. {
  1606. int mac_id;
  1607. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++)
  1608. dp_rx_pdev_mon_cmn_desc_pool_deinit(pdev, mac_id);
  1609. qdf_spinlock_destroy(&pdev->mon_lock);
  1610. }
  1611. void dp_rx_pdev_mon_desc_pool_free(struct dp_pdev *pdev)
  1612. {
  1613. int mac_id;
  1614. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++)
  1615. dp_rx_pdev_mon_cmn_desc_pool_free(pdev, mac_id);
  1616. }
  1617. void
  1618. dp_rx_pdev_mon_buffers_free(struct dp_pdev *pdev)
  1619. {
  1620. int mac_id;
  1621. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++)
  1622. dp_rx_pdev_mon_cmn_buffers_free(pdev, mac_id);
  1623. }
  1624. QDF_STATUS
  1625. dp_rx_pdev_mon_buffers_alloc(struct dp_pdev *pdev)
  1626. {
  1627. int mac_id;
  1628. QDF_STATUS status;
  1629. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  1630. status = dp_rx_pdev_mon_cmn_buffers_alloc(pdev, mac_id);
  1631. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1632. QDF_TRACE(QDF_MODULE_ID_DP,
  1633. QDF_TRACE_LEVEL_ERROR, "%s: %d failed\n",
  1634. __func__, mac_id);
  1635. return status;
  1636. }
  1637. }
  1638. return status;
  1639. }