dp_full_mon.c 26 KB

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