dp_rx_mon_status.c 28 KB

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