dp_rx_mon_status.c 26 KB

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