dp_rx_mon_status.c 28 KB

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