dp_rx_mon_status.c 25 KB

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