dp_rx_mon_status.c 21 KB

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