dp_full_mon.c 26 KB

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