dp_full_mon.c 28 KB

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