dp_full_mon.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. /*
  2. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "dp_types.h"
  17. #include "hal_rx.h"
  18. #include "hal_api.h"
  19. #include "qdf_trace.h"
  20. #include "qdf_nbuf.h"
  21. #include "hal_api_mon.h"
  22. #include "dp_rx.h"
  23. #include "dp_rx_mon.h"
  24. #include "dp_internal.h"
  25. #include "dp_htt.h"
  26. #include "dp_full_mon.h"
  27. #include "qdf_mem.h"
  28. #ifdef QCA_SUPPORT_FULL_MON
  29. uint32_t
  30. dp_rx_mon_status_process(struct dp_soc *soc,
  31. struct dp_intr *int_ctx,
  32. uint32_t mac_id,
  33. uint32_t quota);
  34. /*
  35. * dp_rx_mon_status_buf_validate () - Validate first monitor status buffer addr
  36. * against status buf addr given in monitor destination ring
  37. *
  38. * @pdev: DP pdev handle
  39. * @int_ctx: Interrupt context
  40. * @mac_id: lmac id
  41. *
  42. * Return: QDF_STATUS
  43. */
  44. static inline enum dp_mon_reap_status
  45. dp_rx_mon_status_buf_validate(struct dp_pdev *pdev,
  46. struct dp_intr *int_ctx,
  47. uint32_t mac_id)
  48. {
  49. struct dp_soc *soc = pdev->soc;
  50. hal_soc_handle_t hal_soc;
  51. void *mon_status_srng;
  52. void *ring_entry;
  53. uint32_t rx_buf_cookie;
  54. qdf_nbuf_t status_nbuf;
  55. struct dp_rx_desc *rx_desc;
  56. uint64_t buf_paddr;
  57. struct rx_desc_pool *rx_desc_pool;
  58. uint32_t tlv_tag;
  59. void *rx_tlv;
  60. struct hal_rx_ppdu_info *ppdu_info;
  61. enum dp_mon_reap_status status = DP_MON_STATUS_MATCH;
  62. QDF_STATUS buf_status;
  63. uint32_t ppdu_id_diff;
  64. mon_status_srng = soc->rxdma_mon_status_ring[mac_id].hal_srng;
  65. qdf_assert(mon_status_srng);
  66. if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
  67. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  68. "%s %d : HAL Monitor Status Ring Init Failed -- %pK",
  69. __func__, __LINE__, mon_status_srng);
  70. QDF_ASSERT(0);
  71. return status;
  72. }
  73. hal_soc = soc->hal_soc;
  74. qdf_assert(hal_soc);
  75. if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng))) {
  76. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  77. "%s %d : HAL SRNG access Failed -- %pK",
  78. __func__, __LINE__, mon_status_srng);
  79. QDF_ASSERT(0);
  80. return status;
  81. }
  82. ring_entry = hal_srng_src_peek_n_get_next(hal_soc, mon_status_srng);
  83. if (!ring_entry) {
  84. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  85. "%s %d : HAL SRNG entry is NULL srng:-- %pK",
  86. __func__, __LINE__, mon_status_srng);
  87. status = DP_MON_STATUS_REPLENISH;
  88. goto done;
  89. }
  90. ppdu_info = &pdev->ppdu_info;
  91. rx_desc_pool = &soc->rx_desc_status[mac_id];
  92. buf_paddr = (HAL_RX_BUFFER_ADDR_31_0_GET(ring_entry) |
  93. ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(ring_entry)) << 32));
  94. if (!buf_paddr) {
  95. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  96. "%s %d : buf addr is NULL -- %pK",
  97. __func__, __LINE__, mon_status_srng);
  98. status = DP_MON_STATUS_REPLENISH;
  99. goto done;
  100. }
  101. rx_buf_cookie = HAL_RX_BUF_COOKIE_GET(ring_entry);
  102. rx_desc = dp_rx_cookie_2_va_mon_status(soc, rx_buf_cookie);
  103. qdf_assert(rx_desc);
  104. status_nbuf = rx_desc->nbuf;
  105. qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
  106. QDF_DMA_FROM_DEVICE);
  107. rx_tlv = qdf_nbuf_data(status_nbuf);
  108. buf_status = hal_get_rx_status_done(rx_tlv);
  109. /* If status buffer DMA is not done,
  110. * hold on to mon destination ring.
  111. */
  112. if (buf_status != QDF_STATUS_SUCCESS) {
  113. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  114. FL("Monitor status ring: DMA is not done "
  115. "for nbuf: %pK buf_addr: %llx"),
  116. status_nbuf, buf_paddr);
  117. status = dp_rx_mon_handle_status_buf_done(pdev,
  118. mon_status_srng);
  119. if (status == DP_MON_STATUS_REPLENISH) {
  120. union dp_rx_desc_list_elem_t *desc_list = NULL;
  121. union dp_rx_desc_list_elem_t *tail = NULL;
  122. /* If this is DMA not done WAR case, unmap and
  123. * free buffer and current SW descriptor
  124. * and make buf_addr_info NULL, so that call to
  125. * dp_rx_mon_status_process() replenishes entry to
  126. * status ring
  127. */
  128. qdf_nbuf_unmap_nbytes_single(soc->osdev, status_nbuf,
  129. QDF_DMA_FROM_DEVICE,
  130. rx_desc_pool->buf_size);
  131. qdf_nbuf_free(status_nbuf);
  132. dp_rx_add_to_free_desc_list(&desc_list,
  133. &tail, rx_desc);
  134. dp_rx_add_desc_list_to_free_list(soc, &desc_list,
  135. &tail, mac_id, rx_desc_pool);
  136. hal_rxdma_buff_addr_info_set(
  137. ring_entry,
  138. 0, 0, HAL_RX_BUF_RBM_SW3_BM);
  139. }
  140. goto done;
  141. }
  142. qdf_nbuf_unmap_nbytes_single(soc->osdev, status_nbuf,
  143. QDF_DMA_FROM_DEVICE,
  144. rx_desc_pool->buf_size);
  145. rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
  146. tlv_tag = HAL_RX_GET_USER_TLV32_TYPE(rx_tlv);
  147. if (tlv_tag == WIFIRX_PPDU_START_E) {
  148. rx_tlv = (uint8_t *)rx_tlv + HAL_RX_TLV32_HDR_SIZE;
  149. pdev->mon_desc->status_ppdu_id =
  150. HAL_RX_GET(rx_tlv, RX_PPDU_START_0, PHY_PPDU_ID);
  151. pdev->status_buf_addr = buf_paddr;
  152. }
  153. if (pdev->mon_desc->ppdu_id < pdev->mon_desc->status_ppdu_id) {
  154. status = DP_MON_STATUS_LEAD;
  155. /* For wrap around case */
  156. ppdu_id_diff = pdev->mon_desc->status_ppdu_id -
  157. pdev->mon_desc->ppdu_id;
  158. if (ppdu_id_diff > DP_RX_MON_PPDU_ID_WRAP)
  159. status = DP_MON_STATUS_LAG;
  160. } else if (pdev->mon_desc->ppdu_id > pdev->mon_desc->status_ppdu_id) {
  161. status = DP_MON_STATUS_LAG;
  162. /* For wrap around case */
  163. ppdu_id_diff = pdev->mon_desc->ppdu_id -
  164. pdev->mon_desc->status_ppdu_id;
  165. if (ppdu_id_diff > DP_RX_MON_PPDU_ID_WRAP)
  166. status = DP_MON_STATUS_LEAD;
  167. }
  168. if ((pdev->mon_desc->status_buf.paddr != buf_paddr) ||
  169. (pdev->mon_desc->ppdu_id != pdev->mon_desc->status_ppdu_id)) {
  170. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  171. FL("Monitor: PPDU id or status buf_addr mismatch "
  172. "status_ppdu_id: %d dest_ppdu_id: %d "
  173. "status_addr: %llx status_buf_cookie: %d "
  174. "dest_addr: %llx tlv_tag: %d"
  175. " status_nbuf: %pK pdev->hold_mon_dest: %d"),
  176. pdev->mon_desc->status_ppdu_id,
  177. pdev->mon_desc->ppdu_id, pdev->status_buf_addr,
  178. rx_buf_cookie,
  179. pdev->mon_desc->status_buf.paddr, tlv_tag,
  180. status_nbuf, pdev->hold_mon_dest_ring);
  181. }
  182. done:
  183. hal_srng_access_end(hal_soc, mon_status_srng);
  184. return status;
  185. }
  186. /*
  187. * dp_rx_mon_prepare_mon_mpdu () - API to prepare dp_mon_mpdu object
  188. *
  189. * @pdev: DP pdev object
  190. * @head_msdu: Head msdu
  191. * @tail_msdu: Tail msdu
  192. *
  193. */
  194. static inline struct dp_mon_mpdu *
  195. dp_rx_mon_prepare_mon_mpdu(struct dp_pdev *pdev,
  196. qdf_nbuf_t head_msdu,
  197. qdf_nbuf_t tail_msdu)
  198. {
  199. struct dp_mon_mpdu *mon_mpdu = NULL;
  200. mon_mpdu = qdf_mem_malloc(sizeof(struct dp_mon_mpdu));
  201. if (!mon_mpdu) {
  202. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  203. FL("Monitor MPDU object allocation failed -- %pK"),
  204. pdev);
  205. qdf_assert_always(0);
  206. }
  207. mon_mpdu->head = head_msdu;
  208. mon_mpdu->tail = tail_msdu;
  209. mon_mpdu->rs_flags = pdev->ppdu_info.rx_status.rs_flags;
  210. mon_mpdu->ant_signal_db = pdev->ppdu_info.rx_status.ant_signal_db;
  211. mon_mpdu->is_stbc = pdev->ppdu_info.rx_status.is_stbc;
  212. mon_mpdu->sgi = pdev->ppdu_info.rx_status.sgi;
  213. mon_mpdu->beamformed = pdev->ppdu_info.rx_status.beamformed;
  214. return mon_mpdu;
  215. }
  216. static inline void
  217. dp_rx_mon_drop_ppdu(struct dp_pdev *pdev, uint32_t mac_id)
  218. {
  219. struct dp_mon_mpdu *mpdu = NULL;
  220. struct dp_mon_mpdu *temp_mpdu = NULL;
  221. qdf_nbuf_t mon_skb, skb_next;
  222. if (!TAILQ_EMPTY(&pdev->mon_mpdu_q)) {
  223. TAILQ_FOREACH_SAFE(mpdu,
  224. &pdev->mon_mpdu_q,
  225. mpdu_list_elem,
  226. temp_mpdu) {
  227. TAILQ_REMOVE(&pdev->mon_mpdu_q,
  228. mpdu, mpdu_list_elem);
  229. mon_skb = mpdu->head;
  230. while (mon_skb) {
  231. skb_next = qdf_nbuf_next(mon_skb);
  232. QDF_TRACE(QDF_MODULE_ID_DP,
  233. QDF_TRACE_LEVEL_DEBUG,
  234. "[%s][%d] mon_skb=%pK len %u"
  235. " __func__, __LINE__",
  236. mon_skb, mon_skb->len);
  237. qdf_nbuf_free(mon_skb);
  238. mon_skb = skb_next;
  239. }
  240. qdf_mem_free(mpdu);
  241. }
  242. }
  243. pdev->mon_desc->drop_ppdu = 0;
  244. }
  245. /*
  246. * dp_rx_monitor_deliver_ppdu () - API to deliver all MPDU for a MPDU
  247. * to upper layer stack
  248. *
  249. * @soc: DP soc handle
  250. * @pdev: pdev
  251. * @mac_id: lmac id
  252. */
  253. static inline QDF_STATUS
  254. dp_rx_monitor_deliver_ppdu(struct dp_soc *soc,
  255. struct dp_pdev *pdev,
  256. uint32_t mac_id)
  257. {
  258. struct dp_mon_mpdu *mpdu = NULL;
  259. struct dp_mon_mpdu *temp_mpdu = NULL;
  260. if (!TAILQ_EMPTY(&pdev->mon_mpdu_q)) {
  261. TAILQ_FOREACH_SAFE(mpdu,
  262. &pdev->mon_mpdu_q,
  263. mpdu_list_elem,
  264. temp_mpdu) {
  265. TAILQ_REMOVE(&pdev->mon_mpdu_q,
  266. mpdu, mpdu_list_elem);
  267. /* Check for IEEE80211_AMSDU_FLAG in mpdu
  268. * and set in pdev->ppdu_info.rx_status
  269. */
  270. HAL_RX_SET_MSDU_AGGREGATION(mpdu,
  271. &(pdev->ppdu_info.rx_status));
  272. pdev->ppdu_info.rx_status.ant_signal_db =
  273. mpdu->ant_signal_db;
  274. pdev->ppdu_info.rx_status.is_stbc = mpdu->is_stbc;
  275. pdev->ppdu_info.rx_status.sgi = mpdu->sgi;
  276. pdev->ppdu_info.rx_status.beamformed = mpdu->beamformed;
  277. dp_rx_mon_deliver(soc, mac_id,
  278. mpdu->head, mpdu->tail);
  279. qdf_mem_free(mpdu);
  280. }
  281. }
  282. return QDF_STATUS_SUCCESS;
  283. }
  284. /**
  285. * dp_rx_mon_reap_status_ring () - Reap status_buf_count of status buffers for
  286. * status ring.
  287. *
  288. * @soc: DP soc handle
  289. * @pdev: pdev
  290. * @int_ctx: interrupt context
  291. * @mac_id: mac id on which interrupt is received
  292. * @quota: number of status ring entries to be reaped
  293. * @desc_info: Rx ppdu desc info
  294. */
  295. static inline uint32_t
  296. dp_rx_mon_reap_status_ring(struct dp_soc *soc,
  297. struct dp_pdev *pdev,
  298. struct dp_intr *int_ctx,
  299. uint32_t mac_id,
  300. uint32_t quota,
  301. struct hal_rx_mon_desc_info *desc_info)
  302. {
  303. uint8_t status_buf_count;
  304. uint32_t work_done = 0;
  305. enum dp_mon_reap_status status;
  306. status_buf_count = desc_info->status_buf_count;
  307. desc_info->drop_ppdu = false;
  308. status = dp_rx_mon_status_buf_validate(pdev, int_ctx, mac_id);
  309. switch (status) {
  310. case DP_MON_STATUS_NO_DMA:
  311. /* If DMA is not done for status ring entry,
  312. * hold on to monitor destination ring and
  313. * deliver current ppdu data once DMA is done.
  314. */
  315. pdev->hold_mon_dest_ring = true;
  316. break;
  317. case DP_MON_STATUS_LAG:
  318. /* If status_ppdu_id is lagging behind destination,
  319. * a. Hold on to destination ring
  320. * b. Drop status ppdus until ppdu id matches
  321. * c. Increment stats for ppdu_id mismatch and
  322. * status ppdu drop
  323. */
  324. pdev->hold_mon_dest_ring = true;
  325. pdev->rx_mon_stats.ppdu_id_mismatch++;
  326. pdev->rx_mon_stats.status_ppdu_drop++;
  327. break;
  328. case DP_MON_STATUS_LEAD:
  329. /* If status_ppdu_id is leading ahead destination,
  330. * a. Drop destination ring ppdu until ppdu_id matches
  331. * b. Unhold monitor destination ring so status ppdus
  332. * can be dropped.
  333. * c. Increment stats for ppdu_id mismatch and
  334. * destination ppdu drop
  335. */
  336. desc_info->drop_ppdu = true;
  337. pdev->hold_mon_dest_ring = false;
  338. pdev->rx_mon_stats.ppdu_id_mismatch++;
  339. pdev->rx_mon_stats.dest_ppdu_drop++;
  340. break;
  341. case DP_MON_STATUS_REPLENISH:
  342. /* If status ring hp entry is NULL, replenish it */
  343. work_done = dp_rx_mon_status_process(soc, int_ctx, mac_id, 1);
  344. break;
  345. case DP_MON_STATUS_MATCH:
  346. /* If status ppdu id matches with destnation,
  347. * unhold monitor destination ring and deliver ppdu
  348. */
  349. pdev->hold_mon_dest_ring = false;
  350. break;
  351. default:
  352. dp_err("mon reap status is not supported");
  353. }
  354. /* If status ring is lagging behind detination ring,
  355. * reap only one status buffer
  356. */
  357. if (status == DP_MON_STATUS_LAG)
  358. status_buf_count = 1;
  359. if (status == DP_MON_STATUS_LAG ||
  360. status == DP_MON_STATUS_MATCH) {
  361. work_done = dp_rx_mon_status_process(soc,
  362. int_ctx,
  363. mac_id,
  364. status_buf_count);
  365. }
  366. return work_done;
  367. }
  368. /**
  369. * dp_rx_mon_mpdu_reap () - This API reaps a mpdu from mon dest ring descriptor
  370. * and returns link descriptor to HW (WBM)
  371. *
  372. * @soc: DP soc handle
  373. * @pdev: pdev
  374. * @mac_id: lmac id
  375. * @ring_desc: SW monitor ring desc
  376. * @head_msdu: nbuf pointing to first msdu in a chain
  377. * @tail_msdu: nbuf pointing to last msdu in a chain
  378. * @head_desc: head pointer to free desc list
  379. * @tail_desc: tail pointer to free desc list
  380. *
  381. * Return: number of reaped buffers
  382. */
  383. static inline uint32_t
  384. dp_rx_mon_mpdu_reap(struct dp_soc *soc, struct dp_pdev *pdev, uint32_t mac_id,
  385. void *ring_desc, qdf_nbuf_t *head_msdu,
  386. qdf_nbuf_t *tail_msdu,
  387. union dp_rx_desc_list_elem_t **head_desc,
  388. union dp_rx_desc_list_elem_t **tail_desc)
  389. {
  390. struct dp_rx_desc *rx_desc = NULL;
  391. struct hal_rx_msdu_list msdu_list;
  392. uint32_t rx_buf_reaped = 0;
  393. uint16_t num_msdus = 0, msdu_index, rx_hdr_tlv_len, l3_hdr_pad;
  394. uint32_t total_frag_len = 0, frag_len = 0;
  395. bool drop_mpdu = false;
  396. bool msdu_frag = false, is_first_msdu = true, is_frag_non_raw = false;
  397. void *link_desc_va;
  398. uint8_t *rx_tlv_hdr;
  399. qdf_nbuf_t msdu = NULL, last_msdu = NULL;
  400. uint32_t rx_link_buf_info[HAL_RX_BUFFINFO_NUM_DWORDS];
  401. struct hal_rx_mon_desc_info *desc_info;
  402. uint16_t prev_ppdu_id;
  403. struct rx_desc_pool *rx_desc_pool = NULL;
  404. desc_info = pdev->mon_desc;
  405. /* Restore previous ppdu_id to use it while doing
  406. * status buffer validation
  407. */
  408. prev_ppdu_id = pdev->mon_desc->status_ppdu_id;
  409. qdf_mem_zero(desc_info, sizeof(struct hal_rx_mon_desc_info));
  410. pdev->mon_desc->status_ppdu_id = prev_ppdu_id;
  411. /* Read SW Mon ring descriptor */
  412. hal_rx_sw_mon_desc_info_get((struct hal_soc *)soc->hal_soc,
  413. ring_desc,
  414. (void *)desc_info);
  415. /* If end_of_ppdu is 1, return*/
  416. if (desc_info->end_of_ppdu)
  417. return rx_buf_reaped;
  418. /* If there is rxdma error, drop mpdu */
  419. if (qdf_unlikely(dp_rx_mon_is_rxdma_error(desc_info)
  420. == QDF_STATUS_SUCCESS)) {
  421. drop_mpdu = true;
  422. pdev->rx_mon_stats.dest_mpdu_drop++;
  423. }
  424. /*
  425. * while loop iterates through all link descriptors and
  426. * reaps msdu_count number of msdus for one SW_MONITOR_RING descriptor
  427. * and forms nbuf queue.
  428. */
  429. while (desc_info->msdu_count && desc_info->link_desc.paddr) {
  430. link_desc_va = dp_rx_cookie_2_mon_link_desc(pdev,
  431. desc_info->link_desc,
  432. mac_id);
  433. qdf_assert_always(link_desc_va);
  434. hal_rx_msdu_list_get(soc->hal_soc,
  435. link_desc_va,
  436. &msdu_list,
  437. &num_msdus);
  438. for (msdu_index = 0; msdu_index < num_msdus; msdu_index++) {
  439. rx_desc = dp_rx_get_mon_desc(soc,
  440. msdu_list.sw_cookie[msdu_index]);
  441. qdf_assert_always(rx_desc);
  442. msdu = DP_RX_MON_GET_NBUF_FROM_DESC(rx_desc);
  443. if (rx_desc->unmapped == 0) {
  444. rx_desc_pool = dp_rx_get_mon_desc_pool(
  445. soc, mac_id, pdev->pdev_id);
  446. dp_rx_mon_buffer_unmap(soc, rx_desc,
  447. rx_desc_pool->buf_size);
  448. rx_desc->unmapped = 1;
  449. }
  450. if (drop_mpdu) {
  451. dp_rx_mon_buffer_free(rx_desc);
  452. msdu = NULL;
  453. /*
  454. * Dont rely on msdu_cnt in case of rxdma error
  455. * Dont decrement msdu_cnt
  456. */
  457. goto next_msdu;
  458. }
  459. rx_tlv_hdr = dp_rx_mon_get_buffer_data(rx_desc);
  460. if (is_first_msdu) {
  461. if (dp_rx_mon_alloc_parent_buffer(head_msdu)
  462. != QDF_STATUS_SUCCESS) {
  463. DP_STATS_INC(pdev,
  464. replenish.nbuf_alloc_fail,
  465. 1);
  466. qdf_frag_free(rx_tlv_hdr);
  467. QDF_TRACE(QDF_MODULE_ID_DP,
  468. QDF_TRACE_LEVEL_DEBUG,
  469. "[%s] failed to allocate parent buffer to hold all frag",
  470. __func__);
  471. drop_mpdu = true;
  472. desc_info->msdu_count--;
  473. goto next_msdu;
  474. }
  475. is_first_msdu = false;
  476. }
  477. if (hal_rx_desc_is_first_msdu(soc->hal_soc,
  478. rx_tlv_hdr))
  479. hal_rx_mon_hw_desc_get_mpdu_status(soc->hal_soc,
  480. rx_tlv_hdr,
  481. &pdev->ppdu_info.rx_status);
  482. /** If msdu is fragmented, spread across multiple
  483. * buffers
  484. * a. calculate len of each fragmented buffer
  485. * b. calculate the number of fragmented buffers for
  486. * a msdu and decrement one msdu_count
  487. */
  488. dp_rx_mon_parse_desc_buffer(soc,
  489. &(msdu_list.msdu_info[msdu_index]),
  490. &msdu_frag,
  491. &total_frag_len,
  492. &frag_len,
  493. &l3_hdr_pad,
  494. rx_tlv_hdr,
  495. &is_frag_non_raw, rx_tlv_hdr);
  496. if (!msdu_frag)
  497. desc_info->msdu_count--;
  498. rx_hdr_tlv_len = SIZE_OF_MONITOR_TLV;
  499. /*
  500. * HW structures call this L3 header padding.
  501. * this is actually the offset
  502. * from the buffer beginning where the L2
  503. * header begins.
  504. */
  505. /*******************************************************
  506. * RX_PACKET *
  507. * ----------------------------------------------------*
  508. | RX_PKT_TLVS | L3 Padding header | msdu data| |
  509. * ----------------------------------------------------*
  510. ******************************************************/
  511. dp_rx_mon_buffer_set_pktlen(msdu,
  512. rx_hdr_tlv_len +
  513. l3_hdr_pad +
  514. frag_len);
  515. dp_rx_mon_add_msdu_to_list(head_msdu, msdu, &last_msdu,
  516. rx_tlv_hdr, frag_len,
  517. l3_hdr_pad);
  518. next_msdu:
  519. rx_buf_reaped++;
  520. dp_rx_add_to_free_desc_list(head_desc,
  521. tail_desc,
  522. rx_desc);
  523. QDF_TRACE(QDF_MODULE_ID_DP,
  524. QDF_TRACE_LEVEL_DEBUG,
  525. FL("%s total_len %u frag_len %u flags %u"),
  526. total_frag_len, frag_len,
  527. msdu_list.msdu_info[msdu_index].msdu_flags);
  528. }
  529. hal_rxdma_buff_addr_info_set(rx_link_buf_info,
  530. desc_info->link_desc.paddr,
  531. desc_info->link_desc.sw_cookie,
  532. desc_info->link_desc.rbm);
  533. /* Get next link desc VA from current link desc */
  534. hal_rx_mon_next_link_desc_get(link_desc_va,
  535. &desc_info->link_desc);
  536. /* return msdu link descriptor to WBM */
  537. if (dp_rx_monitor_link_desc_return(pdev,
  538. (hal_buff_addrinfo_t)rx_link_buf_info,
  539. mac_id,
  540. HAL_BM_ACTION_PUT_IN_IDLE_LIST)
  541. != QDF_STATUS_SUCCESS) {
  542. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  543. "dp_rx_monitor_link_desc_return failed");
  544. }
  545. }
  546. pdev->rx_mon_stats.dest_mpdu_done++;
  547. dp_rx_mon_init_tail_msdu(msdu, last_msdu, tail_msdu);
  548. dp_rx_mon_remove_raw_frame_fcs_len(head_msdu);
  549. return rx_buf_reaped;
  550. }
  551. /*
  552. * dp_rx_mon_deliver_prev_ppdu () - Deliver previous PPDU
  553. *
  554. * @pdev: DP pdev handle
  555. * @int_ctx: interrupt context
  556. * @mac_id: lmac id
  557. * @quota: quota
  558. *
  559. * Return: remaining qouta
  560. */
  561. static inline uint32_t
  562. dp_rx_mon_deliver_prev_ppdu(struct dp_pdev *pdev,
  563. struct dp_intr *int_ctx,
  564. uint32_t mac_id,
  565. uint32_t quota)
  566. {
  567. struct dp_soc *soc = pdev->soc;
  568. struct hal_rx_mon_desc_info *desc_info = pdev->mon_desc;
  569. uint32_t work_done = 0, work = 0;
  570. bool deliver_ppdu = false;
  571. enum dp_mon_reap_status status;
  572. while (pdev->hold_mon_dest_ring) {
  573. status = dp_rx_mon_status_buf_validate(pdev, int_ctx, mac_id);
  574. switch (status) {
  575. case DP_MON_STATUS_NO_DMA:
  576. /* If DMA is not done for status ring entry,
  577. * hold on to monitor destination ring and
  578. * deliver current ppdu data once DMA is done.
  579. */
  580. pdev->hold_mon_dest_ring = true;
  581. break;
  582. case DP_MON_STATUS_LAG:
  583. /* If status_ppdu_id is lagging behind destination,
  584. * a. Hold on to destination ring
  585. * b. Drop status ppdus until ppdu id matches
  586. * c. Increment stats for ppdu_id mismatch and
  587. * status ppdu drop
  588. */
  589. pdev->hold_mon_dest_ring = true;
  590. pdev->rx_mon_stats.ppdu_id_mismatch++;
  591. pdev->rx_mon_stats.status_ppdu_drop++;
  592. break;
  593. case DP_MON_STATUS_LEAD:
  594. /* If status_ppdu_id is leading ahead destination,
  595. * a. Drop destination ring ppdu until ppdu_id matches
  596. * b. Unhold monitor destination ring so status ppdus
  597. * can be dropped.
  598. * c. Increment stats for ppdu_id mismatch and
  599. * destination ppdu drop
  600. */
  601. desc_info->drop_ppdu = true;
  602. pdev->hold_mon_dest_ring = false;
  603. pdev->rx_mon_stats.ppdu_id_mismatch++;
  604. pdev->rx_mon_stats.dest_ppdu_drop++;
  605. break;
  606. case DP_MON_STATUS_REPLENISH:
  607. /* If status ring hp entry is NULL, replenish it */
  608. work = dp_rx_mon_status_process(soc, int_ctx, mac_id, 1);
  609. break;
  610. case DP_MON_STATUS_MATCH:
  611. /* If status ppdu id matches with destnation,
  612. * unhold monitor destination ring and deliver ppdu
  613. */
  614. pdev->hold_mon_dest_ring = false;
  615. break;
  616. default:
  617. dp_err("mon reap status is not supported");
  618. }
  619. /* When status ring entry's DMA is not done or
  620. * status ring entry is replenished, ppdu status is not
  621. * available for radiotap construction, so return and
  622. * check for status on next interrupt
  623. */
  624. if ((status == DP_MON_STATUS_NO_DMA) ||
  625. (status == DP_MON_STATUS_REPLENISH)) {
  626. return work_done;
  627. }
  628. if (status == DP_MON_STATUS_LAG) {
  629. work = dp_rx_mon_status_process(soc, int_ctx, mac_id, 1);
  630. if (!work)
  631. return 0;
  632. work_done += work;
  633. }
  634. deliver_ppdu = true;
  635. }
  636. if (deliver_ppdu) {
  637. if (pdev->mon_desc->drop_ppdu) {
  638. dp_rx_mon_drop_ppdu(pdev, mac_id);
  639. return work_done;
  640. }
  641. work_done += dp_rx_mon_status_process(soc, int_ctx, mac_id,
  642. desc_info->status_buf_count);
  643. dp_rx_monitor_deliver_ppdu(soc, pdev, mac_id);
  644. }
  645. return work_done;
  646. }
  647. /**
  648. * dp_rx_mon_process () - Core brain processing for monitor mode
  649. *
  650. * This API processes monitor destination ring followed by monitor status ring
  651. * Called from bottom half (tasklet/NET_RX_SOFTIRQ)
  652. *
  653. * @soc: datapath soc context
  654. * @int_ctx: interrupt context
  655. * @mac_id: mac_id on which interrupt is received
  656. * @quota: Number of status ring entry that can be serviced in one shot.
  657. *
  658. * @Return: Number of reaped status ring entries
  659. */
  660. uint32_t dp_rx_mon_process(struct dp_soc *soc, struct dp_intr *int_ctx,
  661. uint32_t mac_id, uint32_t quota)
  662. {
  663. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  664. union dp_rx_desc_list_elem_t *head_desc = NULL;
  665. union dp_rx_desc_list_elem_t *tail_desc = NULL;
  666. uint32_t rx_bufs_reaped = 0;
  667. struct dp_mon_mpdu *mon_mpdu;
  668. struct cdp_pdev_mon_stats *rx_mon_stats;
  669. hal_rxdma_desc_t ring_desc;
  670. hal_soc_handle_t hal_soc;
  671. hal_ring_handle_t mon_dest_srng;
  672. qdf_nbuf_t head_msdu = NULL;
  673. qdf_nbuf_t tail_msdu = NULL;
  674. struct hal_rx_mon_desc_info *desc_info;
  675. int mac_for_pdev = mac_id;
  676. QDF_STATUS status;
  677. uint32_t work_done = 0;
  678. if (!pdev) {
  679. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  680. "pdev is null for mac_id = %d", mac_id);
  681. return work_done;
  682. }
  683. qdf_spin_lock_bh(&pdev->mon_lock);
  684. if (qdf_unlikely(!dp_soc_is_full_mon_enable(pdev))) {
  685. work_done += dp_rx_mon_status_process(soc, int_ctx,
  686. mac_id, quota);
  687. qdf_spin_unlock_bh(&pdev->mon_lock);
  688. return work_done;
  689. }
  690. desc_info = pdev->mon_desc;
  691. rx_mon_stats = &pdev->rx_mon_stats;
  692. work_done = dp_rx_mon_deliver_prev_ppdu(pdev, int_ctx, mac_id, quota);
  693. /* Do not proceed if work_done zero */
  694. if (!work_done && pdev->hold_mon_dest_ring) {
  695. qdf_spin_unlock_bh(&pdev->mon_lock);
  696. return work_done;
  697. }
  698. mon_dest_srng = dp_rxdma_get_mon_dst_ring(pdev, mac_for_pdev);
  699. if (qdf_unlikely(!mon_dest_srng ||
  700. !hal_srng_initialized(mon_dest_srng))) {
  701. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  702. FL("HAL Monitor Destination Ring Init Failed -- %pK"),
  703. mon_dest_srng);
  704. goto done1;
  705. }
  706. hal_soc = soc->hal_soc;
  707. qdf_assert_always(hal_soc && pdev);
  708. if (qdf_unlikely(dp_srng_access_start(int_ctx, soc, mon_dest_srng))) {
  709. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  710. FL("HAL Monitor Destination Ring access Failed -- %pK"),
  711. mon_dest_srng);
  712. goto done1;
  713. }
  714. /* Each entry in mon dest ring carries mpdu data
  715. * reap all msdus for a mpdu and form skb chain
  716. */
  717. while (qdf_likely(ring_desc =
  718. hal_srng_dst_peek(hal_soc, mon_dest_srng))) {
  719. head_msdu = NULL;
  720. tail_msdu = NULL;
  721. rx_bufs_reaped = dp_rx_mon_mpdu_reap(soc, pdev, mac_id,
  722. ring_desc, &head_msdu,
  723. &tail_msdu, &head_desc,
  724. &tail_desc);
  725. /* Assert if end_of_ppdu is zero and number of reaped buffers
  726. * are zero.
  727. */
  728. if (qdf_unlikely(!desc_info->end_of_ppdu && !rx_bufs_reaped)) {
  729. qdf_err("end_of_ppdu and rx_bufs_reaped are zero");
  730. }
  731. rx_mon_stats->mon_rx_bufs_reaped_dest += rx_bufs_reaped;
  732. /* replenish rx_bufs_reaped buffers back to
  733. * RxDMA Monitor buffer ring
  734. */
  735. if (rx_bufs_reaped) {
  736. status = dp_rx_buffers_replenish(soc, mac_id,
  737. dp_rxdma_get_mon_buf_ring(pdev,
  738. mac_for_pdev),
  739. dp_rx_get_mon_desc_pool(soc, mac_id,
  740. pdev->pdev_id),
  741. rx_bufs_reaped,
  742. &head_desc, &tail_desc);
  743. if (status != QDF_STATUS_SUCCESS)
  744. qdf_assert_always(0);
  745. rx_mon_stats->mon_rx_bufs_replenished_dest += rx_bufs_reaped;
  746. }
  747. head_desc = NULL;
  748. tail_desc = NULL;
  749. /* If end_of_ppdu is zero, it is a valid data mpdu
  750. * a. Add head_msdu and tail_msdu to mpdu list
  751. * b. continue reaping next SW_MONITOR_RING descriptor
  752. */
  753. if (!desc_info->end_of_ppdu) {
  754. /*
  755. * In case of rxdma error, MPDU is dropped
  756. * from sw_monitor_ring descriptor.
  757. * in this case, head_msdu remains NULL.
  758. * move srng to next and continue reaping next entry
  759. */
  760. if (!head_msdu) {
  761. ring_desc = hal_srng_dst_get_next(hal_soc,
  762. mon_dest_srng);
  763. continue;
  764. }
  765. /*
  766. * Prepare a MPDU object which holds chain of msdus
  767. * and MPDU specific status and add this is to
  768. * monitor mpdu queue
  769. */
  770. mon_mpdu = dp_rx_mon_prepare_mon_mpdu(pdev,
  771. head_msdu,
  772. tail_msdu);
  773. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  774. FL("Dest_srng: %pK MPDU_OBJ: %pK "
  775. "head_msdu: %pK tail_msdu: %pK -- "),
  776. mon_dest_srng,
  777. mon_mpdu,
  778. head_msdu,
  779. tail_msdu);
  780. TAILQ_INSERT_TAIL(&pdev->mon_mpdu_q,
  781. mon_mpdu,
  782. mpdu_list_elem);
  783. head_msdu = NULL;
  784. tail_msdu = NULL;
  785. ring_desc = hal_srng_dst_get_next(hal_soc,
  786. mon_dest_srng);
  787. continue;
  788. }
  789. /* It is observed sometimes that, ppdu_id, status_buf_addr
  790. * and link desc addr is NULL, this WAR is to handle same
  791. */
  792. if (!desc_info->ppdu_id && !desc_info->status_buf.paddr) {
  793. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  794. FL("ppdu_id: %d ring_entry: %pK"
  795. "status_buf_count: %d rxdma_push: %d"
  796. "rxdma_err: %d link_desc: %pK "),
  797. desc_info->ppdu_id, ring_desc,
  798. desc_info->status_buf_count,
  799. desc_info->rxdma_push_reason,
  800. desc_info->rxdma_error_code,
  801. desc_info->link_desc.paddr);
  802. goto next_entry;
  803. }
  804. /*
  805. * end_of_ppdu is one,
  806. * a. update ppdu_done stattistics
  807. * b. Replenish buffers back to mon buffer ring
  808. * c. reap status ring for a PPDU and deliver all mpdus
  809. * to upper layer
  810. */
  811. rx_mon_stats->dest_ppdu_done++;
  812. work_done += dp_rx_mon_reap_status_ring(soc, pdev, int_ctx,
  813. mac_id, quota, desc_info);
  814. /* Deliver all MPDUs for a PPDU */
  815. if (desc_info->drop_ppdu)
  816. dp_rx_mon_drop_ppdu(pdev, mac_id);
  817. else if (!pdev->hold_mon_dest_ring)
  818. dp_rx_monitor_deliver_ppdu(soc, pdev, mac_id);
  819. next_entry:
  820. hal_srng_dst_get_next(hal_soc, mon_dest_srng);
  821. break;
  822. }
  823. dp_srng_access_end(int_ctx, soc, mon_dest_srng);
  824. done1:
  825. qdf_spin_unlock_bh(&pdev->mon_lock);
  826. return work_done;
  827. }
  828. /**
  829. * dp_full_mon_attach() - attach full monitor mode
  830. * resources
  831. * @pdev: Datapath PDEV handle
  832. *
  833. * Return: void
  834. */
  835. void dp_full_mon_attach(struct dp_pdev *pdev)
  836. {
  837. struct dp_soc *soc = pdev->soc;
  838. if (!soc->full_mon_mode) {
  839. qdf_debug("Full monitor is not enabled");
  840. return;
  841. }
  842. pdev->mon_desc = qdf_mem_malloc(sizeof(struct hal_rx_mon_desc_info));
  843. if (!pdev->mon_desc) {
  844. qdf_err("Memory allocation failed for hal_rx_mon_desc_info ");
  845. return;
  846. }
  847. TAILQ_INIT(&pdev->mon_mpdu_q);
  848. }
  849. /**
  850. * dp_full_mon_detach() - detach full monitor mode
  851. * resources
  852. * @pdev: Datapath PDEV handle
  853. *
  854. * Return: void
  855. *
  856. */
  857. void dp_full_mon_detach(struct dp_pdev *pdev)
  858. {
  859. struct dp_soc *soc = pdev->soc;
  860. struct dp_mon_mpdu *mpdu = NULL;
  861. struct dp_mon_mpdu *temp_mpdu = NULL;
  862. if (!soc->full_mon_mode) {
  863. qdf_debug("Full monitor is not enabled");
  864. return;
  865. }
  866. if (pdev->mon_desc)
  867. qdf_mem_free(pdev->mon_desc);
  868. if (!TAILQ_EMPTY(&pdev->mon_mpdu_q)) {
  869. TAILQ_FOREACH_SAFE(mpdu,
  870. &pdev->mon_mpdu_q,
  871. mpdu_list_elem,
  872. temp_mpdu) {
  873. qdf_mem_free(mpdu);
  874. }
  875. }
  876. }
  877. #endif