dp_full_mon.c 26 KB

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