dp_rx_mon_status.c 25 KB

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