dp_rx_mon_status.c 24 KB

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