dp_rx_mon_status.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. /*
  2. * Copyright (c) 2017-2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "dp_types.h"
  19. #include "dp_rx.h"
  20. #include "dp_peer.h"
  21. #include "hal_rx.h"
  22. #include "hal_api.h"
  23. #include "qdf_trace.h"
  24. #include "qdf_nbuf.h"
  25. #include "hal_api_mon.h"
  26. #include "dp_rx_mon.h"
  27. #include "dp_internal.h"
  28. #include "qdf_mem.h" /* qdf_mem_malloc,free */
  29. /**
  30. * dp_rx_populate_cdp_indication_ppdu() - Populate cdp rx indication structure
  31. * @soc: core txrx main context
  32. * @ppdu_info: ppdu info structure from ppdu ring
  33. * @ppdu_nbuf: qdf nbuf abstraction for linux skb
  34. *
  35. * Return: none
  36. */
  37. #ifdef FEATURE_PERPKT_INFO
  38. static inline void
  39. dp_rx_populate_cdp_indication_ppdu(struct dp_soc *soc,
  40. struct hal_rx_ppdu_info *ppdu_info,
  41. qdf_nbuf_t ppdu_nbuf)
  42. {
  43. struct dp_peer *peer;
  44. struct dp_ast_entry *ast_entry;
  45. struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
  46. uint32_t ast_index;
  47. cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
  48. ast_index = ppdu_info->rx_status.ast_index;
  49. if (ast_index > (WLAN_UMAC_PSOC_MAX_PEERS * 2)) {
  50. cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
  51. return;
  52. }
  53. ast_entry = soc->ast_table[ast_index];
  54. if (!ast_entry) {
  55. cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
  56. return;
  57. }
  58. peer = ast_entry->peer;
  59. if (!peer || peer->peer_ids[0] == HTT_INVALID_PEER) {
  60. cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
  61. return;
  62. }
  63. qdf_mem_copy(cdp_rx_ppdu->mac_addr,
  64. peer->mac_addr.raw, DP_MAC_ADDR_LEN);
  65. cdp_rx_ppdu->first_data_seq_ctrl =
  66. ppdu_info->rx_status.first_data_seq_ctrl;
  67. cdp_rx_ppdu->peer_id = peer->peer_ids[0];
  68. cdp_rx_ppdu->vdev_id = peer->vdev->vdev_id;
  69. cdp_rx_ppdu->ppdu_id = ppdu_info->com_info.ppdu_id;
  70. cdp_rx_ppdu->duration = ppdu_info->rx_status.duration;
  71. cdp_rx_ppdu->u.bw = ppdu_info->rx_status.bw;
  72. cdp_rx_ppdu->tcp_msdu_count = ppdu_info->rx_status.tcp_msdu_count;
  73. cdp_rx_ppdu->udp_msdu_count = ppdu_info->rx_status.udp_msdu_count;
  74. cdp_rx_ppdu->other_msdu_count = ppdu_info->rx_status.other_msdu_count;
  75. cdp_rx_ppdu->u.nss = ppdu_info->rx_status.nss;
  76. cdp_rx_ppdu->u.mcs = ppdu_info->rx_status.mcs;
  77. cdp_rx_ppdu->u.gi = ppdu_info->rx_status.sgi;
  78. cdp_rx_ppdu->u.preamble = ppdu_info->rx_status.preamble_type;
  79. cdp_rx_ppdu->rssi = ppdu_info->rx_status.rssi_comb;
  80. cdp_rx_ppdu->timestamp = ppdu_info->com_info.ppdu_timestamp;
  81. cdp_rx_ppdu->channel = ppdu_info->rx_status.chan_freq;
  82. cdp_rx_ppdu->num_msdu = (cdp_rx_ppdu->tcp_msdu_count +
  83. cdp_rx_ppdu->udp_msdu_count +
  84. cdp_rx_ppdu->other_msdu_count);
  85. if (ppdu_info->com_info.mpdu_cnt_fcs_ok > 1)
  86. cdp_rx_ppdu->is_ampdu = 1;
  87. else
  88. cdp_rx_ppdu->is_ampdu = 0;
  89. cdp_rx_ppdu->tid = ppdu_info->rx_status.tid;
  90. }
  91. #else
  92. static inline void
  93. dp_rx_populate_cdp_indication_ppdu(struct dp_soc *soc,
  94. struct hal_rx_ppdu_info *ppdu_info,
  95. qdf_nbuf_t ppdu_nbuf)
  96. {
  97. }
  98. #endif
  99. /**
  100. * dp_rx_stats_update() - Update per-peer statistics
  101. * @soc: Datapath SOC handle
  102. * @peer: Datapath peer handle
  103. * @ppdu: PPDU Descriptor
  104. *
  105. * Return: None
  106. */
  107. #ifdef FEATURE_PERPKT_INFO
  108. static void dp_rx_stats_update(struct dp_soc *soc, struct dp_peer *peer,
  109. struct cdp_rx_indication_ppdu *ppdu)
  110. {
  111. struct dp_pdev *pdev = NULL;
  112. uint8_t mcs, preamble;
  113. uint16_t num_msdu;
  114. mcs = ppdu->u.mcs;
  115. preamble = ppdu->u.preamble;
  116. num_msdu = ppdu->num_msdu;
  117. if (!peer)
  118. return;
  119. pdev = peer->vdev->pdev;
  120. if (soc->process_rx_status)
  121. return;
  122. DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
  123. if ((preamble == DOT11_A) || (preamble == DOT11_B))
  124. ppdu->u.nss = 1;
  125. if (ppdu->u.nss)
  126. DP_STATS_INC(peer, rx.nss[ppdu->u.nss - 1], num_msdu);
  127. DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
  128. DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
  129. DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
  130. DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
  131. DP_STATS_UPD(peer, rx.rx_rate, mcs);
  132. DP_STATS_INCC(peer,
  133. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  134. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
  135. DP_STATS_INCC(peer,
  136. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  137. ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
  138. DP_STATS_INCC(peer,
  139. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  140. ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
  141. DP_STATS_INCC(peer,
  142. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  143. ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
  144. DP_STATS_INCC(peer,
  145. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  146. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
  147. DP_STATS_INCC(peer,
  148. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  149. ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
  150. DP_STATS_INCC(peer,
  151. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  152. ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
  153. DP_STATS_INCC(peer,
  154. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  155. ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
  156. DP_STATS_INCC(peer,
  157. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  158. ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
  159. DP_STATS_INCC(peer,
  160. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  161. ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
  162. DP_STATS_INC(peer, rx.wme_ac_type[TID_TO_WME_AC(ppdu->tid)], num_msdu);
  163. if (soc->cdp_soc.ol_ops->update_dp_stats) {
  164. soc->cdp_soc.ol_ops->update_dp_stats(pdev->osif_pdev,
  165. &peer->stats, ppdu->peer_id,
  166. UPDATE_PEER_STATS);
  167. dp_aggregate_vdev_stats(peer->vdev);
  168. }
  169. }
  170. #endif
  171. /**
  172. * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
  173. * @soc: core txrx main context
  174. * @pdev: pdev strcuture
  175. * @ppdu_info: structure for rx ppdu ring
  176. *
  177. * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
  178. * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
  179. */
  180. #ifdef FEATURE_PERPKT_INFO
  181. static inline QDF_STATUS
  182. dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
  183. struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
  184. {
  185. uint8_t size = 0;
  186. if (ppdu_info->first_msdu_payload == NULL)
  187. return QDF_STATUS_SUCCESS;
  188. if (pdev->am_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
  189. return QDF_STATUS_SUCCESS;
  190. pdev->am_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
  191. size = ppdu_info->first_msdu_payload - qdf_nbuf_data(nbuf);
  192. ppdu_info->first_msdu_payload = NULL;
  193. if (qdf_nbuf_pull_head(nbuf, size) == NULL)
  194. return QDF_STATUS_SUCCESS;
  195. dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
  196. nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
  197. return QDF_STATUS_E_ALREADY;
  198. }
  199. #else
  200. static inline QDF_STATUS
  201. dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
  202. struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
  203. {
  204. return QDF_STATUS_SUCCESS;
  205. }
  206. #endif
  207. /**
  208. * dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
  209. * @soc: core txrx main context
  210. * @pdev: pdev strcuture
  211. * @ppdu_info: structure for rx ppdu ring
  212. *
  213. * Return: none
  214. */
  215. #ifdef FEATURE_PERPKT_INFO
  216. static inline void
  217. dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
  218. struct hal_rx_ppdu_info *ppdu_info)
  219. {
  220. qdf_nbuf_t ppdu_nbuf;
  221. struct dp_peer *peer;
  222. struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
  223. ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
  224. sizeof(struct hal_rx_ppdu_info), 0, 0, FALSE);
  225. if (ppdu_nbuf) {
  226. dp_rx_populate_cdp_indication_ppdu(soc, ppdu_info, ppdu_nbuf);
  227. qdf_nbuf_put_tail(ppdu_nbuf,
  228. sizeof(struct cdp_rx_indication_ppdu));
  229. cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
  230. peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
  231. if (peer && cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
  232. dp_rx_stats_update(soc, peer, cdp_rx_ppdu);
  233. dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
  234. ppdu_nbuf, cdp_rx_ppdu->peer_id,
  235. WDI_NO_VAL, pdev->pdev_id);
  236. } else
  237. qdf_nbuf_free(ppdu_nbuf);
  238. }
  239. }
  240. #else
  241. static inline void
  242. dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
  243. struct hal_rx_ppdu_info *ppdu_info)
  244. {
  245. }
  246. #endif
  247. /**
  248. * dp_rx_mon_status_process_tlv() - Process status TLV in status
  249. * buffer on Rx status Queue posted by status SRNG processing.
  250. * @soc: core txrx main context
  251. * @mac_id: mac_id which is one of 3 mac_ids _ring
  252. *
  253. * Return: none
  254. */
  255. static inline void
  256. dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
  257. uint32_t quota)
  258. {
  259. struct dp_pdev *pdev = soc->pdev_list[mac_id];
  260. struct hal_rx_ppdu_info *ppdu_info;
  261. qdf_nbuf_t status_nbuf;
  262. uint8_t *rx_tlv;
  263. uint8_t *rx_tlv_start;
  264. uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
  265. QDF_STATUS am_copy_status = QDF_STATUS_SUCCESS;
  266. ppdu_info = &pdev->ppdu_info;
  267. if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
  268. return;
  269. while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
  270. status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
  271. rx_tlv = qdf_nbuf_data(status_nbuf);
  272. rx_tlv_start = rx_tlv;
  273. #ifndef REMOVE_PKT_LOG
  274. #if defined(WDI_EVENT_ENABLE)
  275. dp_wdi_event_handler(WDI_EVENT_RX_DESC, soc,
  276. status_nbuf, HTT_INVALID_PEER, WDI_NO_VAL, mac_id);
  277. #endif
  278. #endif
  279. if ((pdev->monitor_vdev != NULL) || (pdev->enhanced_stats_en)) {
  280. do {
  281. tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
  282. ppdu_info);
  283. rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
  284. if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
  285. break;
  286. } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
  287. }
  288. if (pdev->mcopy_mode) {
  289. am_copy_status = dp_rx_handle_mcopy_mode(soc,
  290. pdev, ppdu_info, status_nbuf);
  291. if (am_copy_status == QDF_STATUS_SUCCESS)
  292. qdf_nbuf_free(status_nbuf);
  293. } else {
  294. qdf_nbuf_free(status_nbuf);
  295. }
  296. if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
  297. if (pdev->enhanced_stats_en ||
  298. pdev->mcopy_mode)
  299. dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
  300. pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
  301. dp_rx_mon_dest_process(soc, mac_id, quota);
  302. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  303. pdev->ppdu_info.com_info.last_ppdu_id =
  304. pdev->ppdu_info.com_info.ppdu_id;
  305. }
  306. }
  307. return;
  308. }
  309. /*
  310. * dp_rx_mon_status_srng_process() - Process monitor status ring
  311. * post the status ring buffer to Rx status Queue for later
  312. * processing when status ring is filled with status TLV.
  313. * Allocate a new buffer to status ring if the filled buffer
  314. * is posted.
  315. *
  316. * @soc: core txrx main context
  317. * @mac_id: mac_id which is one of 3 mac_ids
  318. * @quota: No. of ring entry that can be serviced in one shot.
  319. * Return: uint32_t: No. of ring entry that is processed.
  320. */
  321. static inline uint32_t
  322. dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
  323. uint32_t quota)
  324. {
  325. struct dp_pdev *pdev = soc->pdev_list[mac_id];
  326. void *hal_soc;
  327. void *mon_status_srng;
  328. void *rxdma_mon_status_ring_entry;
  329. QDF_STATUS status;
  330. uint32_t work_done = 0;
  331. mon_status_srng = pdev->rxdma_mon_status_ring.hal_srng;
  332. qdf_assert(mon_status_srng);
  333. if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
  334. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  335. "%s %d : HAL Monitor Destination Ring Init Failed -- %pK\n",
  336. __func__, __LINE__, mon_status_srng);
  337. return work_done;
  338. }
  339. hal_soc = soc->hal_soc;
  340. qdf_assert(hal_soc);
  341. if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
  342. goto done;
  343. /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
  344. * BUFFER_ADDR_INFO STRUCT
  345. */
  346. while (qdf_likely((rxdma_mon_status_ring_entry =
  347. hal_srng_src_peek(hal_soc, mon_status_srng))
  348. && quota--)) {
  349. uint32_t rx_buf_cookie;
  350. qdf_nbuf_t status_nbuf;
  351. struct dp_rx_desc *rx_desc;
  352. uint8_t *status_buf;
  353. qdf_dma_addr_t paddr;
  354. uint64_t buf_addr;
  355. buf_addr =
  356. (HAL_RX_BUFFER_ADDR_31_0_GET(
  357. rxdma_mon_status_ring_entry) |
  358. ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
  359. rxdma_mon_status_ring_entry)) << 32));
  360. if (qdf_likely(buf_addr)) {
  361. rx_buf_cookie =
  362. HAL_RX_BUF_COOKIE_GET(
  363. rxdma_mon_status_ring_entry);
  364. rx_desc = dp_rx_cookie_2_va_mon_status(soc,
  365. rx_buf_cookie);
  366. qdf_assert(rx_desc);
  367. status_nbuf = rx_desc->nbuf;
  368. qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
  369. QDF_DMA_FROM_DEVICE);
  370. status_buf = qdf_nbuf_data(status_nbuf);
  371. status = hal_get_rx_status_done(status_buf);
  372. if (status != QDF_STATUS_SUCCESS) {
  373. QDF_TRACE(QDF_MODULE_ID_DP,
  374. QDF_TRACE_LEVEL_WARN,
  375. "[%s][%d] status not done",
  376. __func__, __LINE__);
  377. break;
  378. }
  379. qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
  380. qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
  381. QDF_DMA_FROM_DEVICE);
  382. /* Put the status_nbuf to queue */
  383. qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
  384. } else {
  385. union dp_rx_desc_list_elem_t *desc_list = NULL;
  386. union dp_rx_desc_list_elem_t *tail = NULL;
  387. struct rx_desc_pool *rx_desc_pool;
  388. uint32_t num_alloc_desc;
  389. rx_desc_pool = &soc->rx_desc_status[mac_id];
  390. num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
  391. rx_desc_pool,
  392. 1,
  393. &desc_list,
  394. &tail);
  395. rx_desc = &desc_list->rx_desc;
  396. }
  397. /* Allocate a new skb */
  398. status_nbuf = qdf_nbuf_alloc(soc->osdev, RX_BUFFER_SIZE,
  399. RX_BUFFER_RESERVATION, RX_BUFFER_ALIGNMENT, FALSE);
  400. status_buf = qdf_nbuf_data(status_nbuf);
  401. hal_clear_rx_status_done(status_buf);
  402. qdf_nbuf_map_single(soc->osdev, status_nbuf,
  403. QDF_DMA_BIDIRECTIONAL);
  404. paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
  405. rx_desc->nbuf = status_nbuf;
  406. rx_desc->in_use = 1;
  407. hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
  408. paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
  409. rxdma_mon_status_ring_entry =
  410. hal_srng_src_get_next(hal_soc, mon_status_srng);
  411. work_done++;
  412. }
  413. done:
  414. hal_srng_access_end(hal_soc, mon_status_srng);
  415. return work_done;
  416. }
  417. /*
  418. * dp_rx_mon_status_process() - Process monitor status ring and
  419. * TLV in status ring.
  420. *
  421. * @soc: core txrx main context
  422. * @mac_id: mac_id which is one of 3 mac_ids
  423. * @quota: No. of ring entry that can be serviced in one shot.
  424. * Return: uint32_t: No. of ring entry that is processed.
  425. */
  426. static inline uint32_t
  427. dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
  428. uint32_t work_done;
  429. work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
  430. quota -= work_done;
  431. dp_rx_mon_status_process_tlv(soc, mac_id, quota);
  432. return work_done;
  433. }
  434. /**
  435. * dp_mon_process() - Main monitor mode processing roution.
  436. * This call monitor status ring process then monitor
  437. * destination ring process.
  438. * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
  439. * @soc: core txrx main context
  440. * @mac_id: mac_id which is one of 3 mac_ids
  441. * @quota: No. of status ring entry that can be serviced in one shot.
  442. * Return: uint32_t: No. of ring entry that is processed.
  443. */
  444. uint32_t
  445. dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
  446. return dp_rx_mon_status_process(soc, mac_id, quota);
  447. }
  448. /**
  449. * dp_rx_pdev_mon_detach() - detach dp rx for status ring
  450. * @pdev: core txrx pdev context
  451. *
  452. * This function will detach DP RX status ring from
  453. * main device context. will free DP Rx resources for
  454. * status ring
  455. *
  456. * Return: QDF_STATUS_SUCCESS: success
  457. * QDF_STATUS_E_RESOURCES: Error return
  458. */
  459. QDF_STATUS
  460. dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev)
  461. {
  462. uint8_t pdev_id = pdev->pdev_id;
  463. struct dp_soc *soc = pdev->soc;
  464. struct rx_desc_pool *rx_desc_pool;
  465. rx_desc_pool = &soc->rx_desc_status[pdev_id];
  466. if (rx_desc_pool->pool_size != 0) {
  467. dp_rx_desc_pool_free(soc, pdev_id, rx_desc_pool);
  468. }
  469. return QDF_STATUS_SUCCESS;
  470. }
  471. /*
  472. * dp_rx_buffers_replenish() - replenish monitor status ring with
  473. * rx nbufs called during dp rx
  474. * monitor status ring initialization
  475. *
  476. * @soc: core txrx main context
  477. * @mac_id: mac_id which is one of 3 mac_ids
  478. * @dp_rxdma_srng: dp monitor status circular ring
  479. * @rx_desc_pool; Pointer to Rx descriptor pool
  480. * @num_req_buffers: number of buffer to be replenished
  481. * @desc_list: list of descs if called from dp rx monitor status
  482. * process or NULL during dp rx initialization or
  483. * out of buffer interrupt
  484. * @tail: tail of descs list
  485. * @owner: who owns the nbuf (host, NSS etc...)
  486. * Return: return success or failure
  487. */
  488. static inline
  489. QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
  490. uint32_t mac_id,
  491. struct dp_srng *dp_rxdma_srng,
  492. struct rx_desc_pool *rx_desc_pool,
  493. uint32_t num_req_buffers,
  494. union dp_rx_desc_list_elem_t **desc_list,
  495. union dp_rx_desc_list_elem_t **tail,
  496. uint8_t owner)
  497. {
  498. uint32_t num_alloc_desc;
  499. uint16_t num_desc_to_free = 0;
  500. uint32_t num_entries_avail;
  501. uint32_t count;
  502. int sync_hw_ptr = 1;
  503. qdf_dma_addr_t paddr;
  504. qdf_nbuf_t rx_netbuf;
  505. void *rxdma_ring_entry;
  506. union dp_rx_desc_list_elem_t *next;
  507. void *rxdma_srng;
  508. uint8_t *status_buf;
  509. rxdma_srng = dp_rxdma_srng->hal_srng;
  510. qdf_assert(rxdma_srng);
  511. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  512. "[%s][%d] requested %d buffers for replenish\n",
  513. __func__, __LINE__, num_req_buffers);
  514. /*
  515. * if desc_list is NULL, allocate the descs from freelist
  516. */
  517. if (!(*desc_list)) {
  518. num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
  519. rx_desc_pool,
  520. num_req_buffers,
  521. desc_list,
  522. tail);
  523. if (!num_alloc_desc) {
  524. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  525. "[%s][%d] no free rx_descs in freelist\n",
  526. __func__, __LINE__);
  527. return QDF_STATUS_E_NOMEM;
  528. }
  529. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  530. "[%s][%d] %d rx desc allocated\n", __func__, __LINE__,
  531. num_alloc_desc);
  532. num_req_buffers = num_alloc_desc;
  533. }
  534. hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
  535. num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
  536. rxdma_srng, sync_hw_ptr);
  537. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  538. "[%s][%d] no of availble entries in rxdma ring: %d\n",
  539. __func__, __LINE__, num_entries_avail);
  540. if (num_entries_avail < num_req_buffers) {
  541. num_desc_to_free = num_req_buffers - num_entries_avail;
  542. num_req_buffers = num_entries_avail;
  543. }
  544. for (count = 0; count < num_req_buffers; count++) {
  545. rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
  546. rxdma_srng);
  547. rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
  548. RX_BUFFER_SIZE,
  549. RX_BUFFER_RESERVATION,
  550. RX_BUFFER_ALIGNMENT,
  551. FALSE);
  552. status_buf = qdf_nbuf_data(rx_netbuf);
  553. hal_clear_rx_status_done(status_buf);
  554. memset(status_buf, 0, RX_BUFFER_SIZE);
  555. qdf_nbuf_map_single(dp_soc->osdev, rx_netbuf,
  556. QDF_DMA_BIDIRECTIONAL);
  557. paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
  558. next = (*desc_list)->next;
  559. (*desc_list)->rx_desc.nbuf = rx_netbuf;
  560. (*desc_list)->rx_desc.in_use = 1;
  561. hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
  562. (*desc_list)->rx_desc.cookie, owner);
  563. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  564. "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
  565. status_buf=%pK paddr=%pK\n",
  566. __func__, __LINE__, &(*desc_list)->rx_desc,
  567. (*desc_list)->rx_desc.cookie, rx_netbuf,
  568. status_buf, (void *)paddr);
  569. *desc_list = next;
  570. }
  571. hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
  572. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  573. "successfully replenished %d buffers\n", num_req_buffers);
  574. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  575. "%d rx desc added back to free list\n", num_desc_to_free);
  576. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  577. "[%s][%d] desc_list=%pK, tail=%pK rx_desc=%pK, cookie=%d\n",
  578. __func__, __LINE__, desc_list, tail, &(*desc_list)->rx_desc,
  579. (*desc_list)->rx_desc.cookie);
  580. /*
  581. * add any available free desc back to the free list
  582. */
  583. if (*desc_list) {
  584. dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
  585. mac_id, rx_desc_pool);
  586. }
  587. return QDF_STATUS_SUCCESS;
  588. }
  589. /**
  590. * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
  591. * @pdev: core txrx pdev context
  592. *
  593. * This function will attach a DP RX monitor status ring into pDEV
  594. * and replenish monitor status ring with buffer.
  595. *
  596. * Return: QDF_STATUS_SUCCESS: success
  597. * QDF_STATUS_E_RESOURCES: Error return
  598. */
  599. QDF_STATUS
  600. dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev) {
  601. uint8_t pdev_id = pdev->pdev_id;
  602. struct dp_soc *soc = pdev->soc;
  603. union dp_rx_desc_list_elem_t *desc_list = NULL;
  604. union dp_rx_desc_list_elem_t *tail = NULL;
  605. struct dp_srng *rxdma_srng;
  606. uint32_t rxdma_entries;
  607. struct rx_desc_pool *rx_desc_pool;
  608. QDF_STATUS status;
  609. rxdma_srng = &pdev->rxdma_mon_status_ring;
  610. rxdma_entries = rxdma_srng->alloc_size/hal_srng_get_entrysize(
  611. soc->hal_soc, RXDMA_MONITOR_STATUS);
  612. rx_desc_pool = &soc->rx_desc_status[pdev_id];
  613. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
  614. "%s: Mon RX Status Pool[%d] allocation size=%d\n",
  615. __func__, pdev_id, rxdma_entries);
  616. status = dp_rx_desc_pool_alloc(soc, pdev_id, rxdma_entries+1,
  617. rx_desc_pool);
  618. if (!QDF_IS_STATUS_SUCCESS(status)) {
  619. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  620. "%s: dp_rx_desc_pool_alloc() failed \n", __func__);
  621. return status;
  622. }
  623. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
  624. "%s: Mon RX Status Buffers Replenish pdev_id=%d\n",
  625. __func__, pdev_id);
  626. status = dp_rx_mon_status_buffers_replenish(soc, pdev_id, rxdma_srng,
  627. rx_desc_pool, rxdma_entries, &desc_list, &tail,
  628. HAL_RX_BUF_RBM_SW3_BM);
  629. if (!QDF_IS_STATUS_SUCCESS(status)) {
  630. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  631. "%s: dp_rx_buffers_replenish() failed \n", __func__);
  632. return status;
  633. }
  634. qdf_nbuf_queue_init(&pdev->rx_status_q);
  635. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  636. pdev->ppdu_info.com_info.last_ppdu_id = 0;
  637. qdf_mem_zero(&(pdev->ppdu_info.rx_status),
  638. sizeof(pdev->ppdu_info.rx_status));
  639. return QDF_STATUS_SUCCESS;
  640. }