dp_rx_mon_status.c 26 KB

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