dp_full_mon.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  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. if (dp_rx_mon_add_msdu_to_list(head_msdu, msdu,
  513. &last_msdu,
  514. rx_tlv_hdr, frag_len,
  515. l3_hdr_pad)
  516. != QDF_STATUS_SUCCESS) {
  517. dp_rx_mon_add_msdu_to_list_failure_handler(rx_tlv_hdr,
  518. pdev, &last_msdu, head_msdu,
  519. tail_msdu, __func__);
  520. drop_mpdu = true;
  521. goto next_msdu;
  522. }
  523. next_msdu:
  524. rx_buf_reaped++;
  525. dp_rx_add_to_free_desc_list(head_desc,
  526. tail_desc,
  527. rx_desc);
  528. QDF_TRACE(QDF_MODULE_ID_DP,
  529. QDF_TRACE_LEVEL_DEBUG,
  530. FL("%s total_len %u frag_len %u flags %u"),
  531. total_frag_len, frag_len,
  532. msdu_list.msdu_info[msdu_index].msdu_flags);
  533. }
  534. hal_rxdma_buff_addr_info_set(rx_link_buf_info,
  535. desc_info->link_desc.paddr,
  536. desc_info->link_desc.sw_cookie,
  537. desc_info->link_desc.rbm);
  538. /* Get next link desc VA from current link desc */
  539. hal_rx_mon_next_link_desc_get(link_desc_va,
  540. &desc_info->link_desc);
  541. /* return msdu link descriptor to WBM */
  542. if (dp_rx_monitor_link_desc_return(pdev,
  543. (hal_buff_addrinfo_t)rx_link_buf_info,
  544. mac_id,
  545. HAL_BM_ACTION_PUT_IN_IDLE_LIST)
  546. != QDF_STATUS_SUCCESS) {
  547. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  548. "dp_rx_monitor_link_desc_return failed");
  549. }
  550. }
  551. pdev->rx_mon_stats.dest_mpdu_done++;
  552. dp_rx_mon_init_tail_msdu(head_msdu, msdu, last_msdu, tail_msdu);
  553. dp_rx_mon_remove_raw_frame_fcs_len(head_msdu, tail_msdu);
  554. return rx_buf_reaped;
  555. }
  556. /*
  557. * dp_rx_mon_deliver_prev_ppdu () - Deliver previous PPDU
  558. *
  559. * @pdev: DP pdev handle
  560. * @int_ctx: interrupt context
  561. * @mac_id: lmac id
  562. * @quota: quota
  563. *
  564. * Return: remaining qouta
  565. */
  566. static inline uint32_t
  567. dp_rx_mon_deliver_prev_ppdu(struct dp_pdev *pdev,
  568. struct dp_intr *int_ctx,
  569. uint32_t mac_id,
  570. uint32_t quota)
  571. {
  572. struct dp_soc *soc = pdev->soc;
  573. struct hal_rx_mon_desc_info *desc_info = pdev->mon_desc;
  574. uint32_t work_done = 0, work = 0;
  575. bool deliver_ppdu = false;
  576. enum dp_mon_reap_status status;
  577. while (pdev->hold_mon_dest_ring) {
  578. status = dp_rx_mon_status_buf_validate(pdev, int_ctx, mac_id);
  579. switch (status) {
  580. case DP_MON_STATUS_NO_DMA:
  581. /* If DMA is not done for status ring entry,
  582. * hold on to monitor destination ring and
  583. * deliver current ppdu data once DMA is done.
  584. */
  585. pdev->hold_mon_dest_ring = true;
  586. break;
  587. case DP_MON_STATUS_LAG:
  588. /* If status_ppdu_id is lagging behind destination,
  589. * a. Hold on to destination ring
  590. * b. Drop status ppdus until ppdu id matches
  591. * c. Increment stats for ppdu_id mismatch and
  592. * status ppdu drop
  593. */
  594. pdev->hold_mon_dest_ring = true;
  595. pdev->rx_mon_stats.ppdu_id_mismatch++;
  596. pdev->rx_mon_stats.status_ppdu_drop++;
  597. break;
  598. case DP_MON_STATUS_LEAD:
  599. /* If status_ppdu_id is leading ahead destination,
  600. * a. Drop destination ring ppdu until ppdu_id matches
  601. * b. Unhold monitor destination ring so status ppdus
  602. * can be dropped.
  603. * c. Increment stats for ppdu_id mismatch and
  604. * destination ppdu drop
  605. */
  606. desc_info->drop_ppdu = true;
  607. pdev->hold_mon_dest_ring = false;
  608. pdev->rx_mon_stats.ppdu_id_mismatch++;
  609. pdev->rx_mon_stats.dest_ppdu_drop++;
  610. break;
  611. case DP_MON_STATUS_REPLENISH:
  612. /* If status ring hp entry is NULL, replenish it */
  613. work = dp_rx_mon_status_process(soc, int_ctx, mac_id, 1);
  614. break;
  615. case DP_MON_STATUS_MATCH:
  616. /* If status ppdu id matches with destnation,
  617. * unhold monitor destination ring and deliver ppdu
  618. */
  619. pdev->hold_mon_dest_ring = false;
  620. break;
  621. default:
  622. dp_err("mon reap status is not supported");
  623. }
  624. /* When status ring entry's DMA is not done or
  625. * status ring entry is replenished, ppdu status is not
  626. * available for radiotap construction, so return and
  627. * check for status on next interrupt
  628. */
  629. if ((status == DP_MON_STATUS_NO_DMA) ||
  630. (status == DP_MON_STATUS_REPLENISH)) {
  631. return work_done;
  632. }
  633. if (status == DP_MON_STATUS_LAG) {
  634. work = dp_rx_mon_status_process(soc, int_ctx, mac_id, 1);
  635. if (!work)
  636. return 0;
  637. work_done += work;
  638. }
  639. deliver_ppdu = true;
  640. }
  641. if (deliver_ppdu) {
  642. if (pdev->mon_desc->drop_ppdu) {
  643. dp_rx_mon_drop_ppdu(pdev, mac_id);
  644. return work_done;
  645. }
  646. work_done += dp_rx_mon_status_process(soc, int_ctx, mac_id,
  647. desc_info->status_buf_count);
  648. dp_rx_monitor_deliver_ppdu(soc, pdev, mac_id);
  649. }
  650. return work_done;
  651. }
  652. /**
  653. * dp_rx_mon_process () - Core brain processing for monitor mode
  654. *
  655. * This API processes monitor destination ring followed by monitor status ring
  656. * Called from bottom half (tasklet/NET_RX_SOFTIRQ)
  657. *
  658. * @soc: datapath soc context
  659. * @int_ctx: interrupt context
  660. * @mac_id: mac_id on which interrupt is received
  661. * @quota: Number of status ring entry that can be serviced in one shot.
  662. *
  663. * @Return: Number of reaped status ring entries
  664. */
  665. uint32_t dp_rx_mon_process(struct dp_soc *soc, struct dp_intr *int_ctx,
  666. uint32_t mac_id, uint32_t quota)
  667. {
  668. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  669. union dp_rx_desc_list_elem_t *head_desc = NULL;
  670. union dp_rx_desc_list_elem_t *tail_desc = NULL;
  671. uint32_t rx_bufs_reaped = 0;
  672. struct dp_mon_mpdu *mon_mpdu;
  673. struct cdp_pdev_mon_stats *rx_mon_stats;
  674. hal_rxdma_desc_t ring_desc;
  675. hal_soc_handle_t hal_soc;
  676. hal_ring_handle_t mon_dest_srng;
  677. qdf_nbuf_t head_msdu = NULL;
  678. qdf_nbuf_t tail_msdu = NULL;
  679. struct hal_rx_mon_desc_info *desc_info;
  680. int mac_for_pdev = mac_id;
  681. QDF_STATUS status;
  682. uint32_t work_done = 0;
  683. if (!pdev) {
  684. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  685. "pdev is null for mac_id = %d", mac_id);
  686. return work_done;
  687. }
  688. qdf_spin_lock_bh(&pdev->mon_lock);
  689. if (qdf_unlikely(!dp_soc_is_full_mon_enable(pdev))) {
  690. work_done += dp_rx_mon_status_process(soc, int_ctx,
  691. mac_id, quota);
  692. qdf_spin_unlock_bh(&pdev->mon_lock);
  693. return work_done;
  694. }
  695. desc_info = pdev->mon_desc;
  696. rx_mon_stats = &pdev->rx_mon_stats;
  697. work_done = dp_rx_mon_deliver_prev_ppdu(pdev, int_ctx, mac_id, quota);
  698. /* Do not proceed if work_done zero */
  699. if (!work_done && pdev->hold_mon_dest_ring) {
  700. qdf_spin_unlock_bh(&pdev->mon_lock);
  701. return work_done;
  702. }
  703. mon_dest_srng = dp_rxdma_get_mon_dst_ring(pdev, mac_for_pdev);
  704. if (qdf_unlikely(!mon_dest_srng ||
  705. !hal_srng_initialized(mon_dest_srng))) {
  706. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  707. FL("HAL Monitor Destination Ring Init Failed -- %pK"),
  708. mon_dest_srng);
  709. goto done1;
  710. }
  711. hal_soc = soc->hal_soc;
  712. qdf_assert_always(hal_soc && pdev);
  713. if (qdf_unlikely(dp_srng_access_start(int_ctx, soc, mon_dest_srng))) {
  714. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  715. FL("HAL Monitor Destination Ring access Failed -- %pK"),
  716. mon_dest_srng);
  717. goto done1;
  718. }
  719. /* Each entry in mon dest ring carries mpdu data
  720. * reap all msdus for a mpdu and form skb chain
  721. */
  722. while (qdf_likely(ring_desc =
  723. hal_srng_dst_peek(hal_soc, mon_dest_srng))) {
  724. head_msdu = NULL;
  725. tail_msdu = NULL;
  726. rx_bufs_reaped = dp_rx_mon_mpdu_reap(soc, pdev, mac_id,
  727. ring_desc, &head_msdu,
  728. &tail_msdu, &head_desc,
  729. &tail_desc);
  730. /* Assert if end_of_ppdu is zero and number of reaped buffers
  731. * are zero.
  732. */
  733. if (qdf_unlikely(!desc_info->end_of_ppdu && !rx_bufs_reaped)) {
  734. qdf_err("end_of_ppdu and rx_bufs_reaped are zero");
  735. }
  736. rx_mon_stats->mon_rx_bufs_reaped_dest += rx_bufs_reaped;
  737. /* replenish rx_bufs_reaped buffers back to
  738. * RxDMA Monitor buffer ring
  739. */
  740. if (rx_bufs_reaped) {
  741. status = dp_rx_buffers_replenish(soc, mac_id,
  742. dp_rxdma_get_mon_buf_ring(pdev,
  743. mac_for_pdev),
  744. dp_rx_get_mon_desc_pool(soc, mac_id,
  745. pdev->pdev_id),
  746. rx_bufs_reaped,
  747. &head_desc, &tail_desc);
  748. if (status != QDF_STATUS_SUCCESS)
  749. qdf_assert_always(0);
  750. rx_mon_stats->mon_rx_bufs_replenished_dest += rx_bufs_reaped;
  751. }
  752. head_desc = NULL;
  753. tail_desc = NULL;
  754. /* If end_of_ppdu is zero, it is a valid data mpdu
  755. * a. Add head_msdu and tail_msdu to mpdu list
  756. * b. continue reaping next SW_MONITOR_RING descriptor
  757. */
  758. if (!desc_info->end_of_ppdu) {
  759. /*
  760. * In case of rxdma error, MPDU is dropped
  761. * from sw_monitor_ring descriptor.
  762. * in this case, head_msdu remains NULL.
  763. * move srng to next and continue reaping next entry
  764. */
  765. if (!head_msdu) {
  766. ring_desc = hal_srng_dst_get_next(hal_soc,
  767. mon_dest_srng);
  768. continue;
  769. }
  770. /*
  771. * Prepare a MPDU object which holds chain of msdus
  772. * and MPDU specific status and add this is to
  773. * monitor mpdu queue
  774. */
  775. mon_mpdu = dp_rx_mon_prepare_mon_mpdu(pdev,
  776. head_msdu,
  777. tail_msdu);
  778. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  779. FL("Dest_srng: %pK MPDU_OBJ: %pK "
  780. "head_msdu: %pK tail_msdu: %pK -- "),
  781. mon_dest_srng,
  782. mon_mpdu,
  783. head_msdu,
  784. tail_msdu);
  785. TAILQ_INSERT_TAIL(&pdev->mon_mpdu_q,
  786. mon_mpdu,
  787. mpdu_list_elem);
  788. head_msdu = NULL;
  789. tail_msdu = NULL;
  790. ring_desc = hal_srng_dst_get_next(hal_soc,
  791. mon_dest_srng);
  792. continue;
  793. }
  794. /* It is observed sometimes that, ppdu_id, status_buf_addr
  795. * and link desc addr is NULL, this WAR is to handle same
  796. */
  797. if (!desc_info->ppdu_id && !desc_info->status_buf.paddr) {
  798. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  799. FL("ppdu_id: %d ring_entry: %pK"
  800. "status_buf_count: %d rxdma_push: %d"
  801. "rxdma_err: %d link_desc: %pK "),
  802. desc_info->ppdu_id, ring_desc,
  803. desc_info->status_buf_count,
  804. desc_info->rxdma_push_reason,
  805. desc_info->rxdma_error_code,
  806. desc_info->link_desc.paddr);
  807. goto next_entry;
  808. }
  809. /*
  810. * end_of_ppdu is one,
  811. * a. update ppdu_done stattistics
  812. * b. Replenish buffers back to mon buffer ring
  813. * c. reap status ring for a PPDU and deliver all mpdus
  814. * to upper layer
  815. */
  816. rx_mon_stats->dest_ppdu_done++;
  817. work_done += dp_rx_mon_reap_status_ring(soc, pdev, int_ctx,
  818. mac_id, quota, desc_info);
  819. /* Deliver all MPDUs for a PPDU */
  820. if (desc_info->drop_ppdu)
  821. dp_rx_mon_drop_ppdu(pdev, mac_id);
  822. else if (!pdev->hold_mon_dest_ring)
  823. dp_rx_monitor_deliver_ppdu(soc, pdev, mac_id);
  824. next_entry:
  825. hal_srng_dst_get_next(hal_soc, mon_dest_srng);
  826. break;
  827. }
  828. dp_srng_access_end(int_ctx, soc, mon_dest_srng);
  829. done1:
  830. qdf_spin_unlock_bh(&pdev->mon_lock);
  831. return work_done;
  832. }
  833. /**
  834. * dp_full_mon_attach() - attach full monitor mode
  835. * resources
  836. * @pdev: Datapath PDEV handle
  837. *
  838. * Return: void
  839. */
  840. void dp_full_mon_attach(struct dp_pdev *pdev)
  841. {
  842. struct dp_soc *soc = pdev->soc;
  843. if (!soc->full_mon_mode) {
  844. qdf_debug("Full monitor is not enabled");
  845. return;
  846. }
  847. pdev->mon_desc = qdf_mem_malloc(sizeof(struct hal_rx_mon_desc_info));
  848. if (!pdev->mon_desc) {
  849. qdf_err("Memory allocation failed for hal_rx_mon_desc_info ");
  850. return;
  851. }
  852. TAILQ_INIT(&pdev->mon_mpdu_q);
  853. }
  854. /**
  855. * dp_full_mon_detach() - detach full monitor mode
  856. * resources
  857. * @pdev: Datapath PDEV handle
  858. *
  859. * Return: void
  860. *
  861. */
  862. void dp_full_mon_detach(struct dp_pdev *pdev)
  863. {
  864. struct dp_soc *soc = pdev->soc;
  865. struct dp_mon_mpdu *mpdu = NULL;
  866. struct dp_mon_mpdu *temp_mpdu = NULL;
  867. if (!soc->full_mon_mode) {
  868. qdf_debug("Full monitor is not enabled");
  869. return;
  870. }
  871. if (pdev->mon_desc)
  872. qdf_mem_free(pdev->mon_desc);
  873. if (!TAILQ_EMPTY(&pdev->mon_mpdu_q)) {
  874. TAILQ_FOREACH_SAFE(mpdu,
  875. &pdev->mon_mpdu_q,
  876. mpdu_list_elem,
  877. temp_mpdu) {
  878. qdf_mem_free(mpdu);
  879. }
  880. }
  881. }
  882. #endif