dp_rx_mon_feature.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. * Copyright (c) 2017-2020 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. #include "wlan_cfg.h"
  31. #include "dp_htt.h"
  32. #include "dp_mon_filter.h"
  33. #ifdef WLAN_RX_PKT_CAPTURE_ENH
  34. static inline void
  35. dp_rx_free_msdu_list(struct msdu_list *msdu_list)
  36. {
  37. qdf_nbuf_list_free(msdu_list->head);
  38. msdu_list->head = NULL;
  39. msdu_list->tail = NULL;
  40. msdu_list->sum_len = 0;
  41. }
  42. /**
  43. * dp_nbuf_set_data_and_len() - set nbuf data and len
  44. * @buf: Network buf instance
  45. * @data: pointer to nbuf data
  46. * @len: nbuf data length
  47. *
  48. * Return: none
  49. */
  50. static inline void
  51. dp_nbuf_set_data_and_len(qdf_nbuf_t buf, unsigned char *data,
  52. int len)
  53. {
  54. qdf_nbuf_set_data_pointer(buf, data);
  55. qdf_nbuf_set_len(buf, len);
  56. qdf_nbuf_set_tail_pointer(buf, len);
  57. }
  58. /*
  59. * dp_rx_populate_cdp_indication_mpdu_info() - Populate cdp rx indication
  60. * MPDU info structure
  61. * @pdev: pdev ctx
  62. * @ppdu_info: ppdu info structure from monitor status ring
  63. * @cdp_mpdu_info: cdp rx indication MPDU info structure
  64. * @user: user ID
  65. *
  66. * Return: none
  67. */
  68. void
  69. dp_rx_populate_cdp_indication_mpdu_info(
  70. struct dp_pdev *pdev,
  71. struct hal_rx_ppdu_info *ppdu_info,
  72. struct cdp_rx_indication_mpdu_info *cdp_mpdu_info,
  73. uint32_t user)
  74. {
  75. int i;
  76. struct mon_rx_user_status *rx_user_status;
  77. cdp_mpdu_info->ppdu_id = ppdu_info->com_info.ppdu_id;
  78. cdp_mpdu_info->channel = ppdu_info->rx_status.chan_num;
  79. cdp_mpdu_info->duration = ppdu_info->rx_status.duration;
  80. cdp_mpdu_info->timestamp = ppdu_info->rx_status.tsft;
  81. cdp_mpdu_info->bw = ppdu_info->rx_status.bw;
  82. if ((ppdu_info->rx_status.sgi == VHT_SGI_NYSM) &&
  83. (ppdu_info->rx_status.preamble_type == HAL_RX_PKT_TYPE_11AC))
  84. cdp_mpdu_info->gi = CDP_SGI_0_4_US;
  85. else
  86. cdp_mpdu_info->gi = ppdu_info->rx_status.sgi;
  87. cdp_mpdu_info->ldpc = ppdu_info->rx_status.ldpc;
  88. cdp_mpdu_info->preamble = ppdu_info->rx_status.preamble_type;
  89. cdp_mpdu_info->ppdu_type = ppdu_info->rx_status.reception_type;
  90. cdp_mpdu_info->rssi_comb = ppdu_info->rx_status.rssi_comb;
  91. cdp_mpdu_info->nf = ppdu_info->rx_status.chan_noise_floor;
  92. if (ppdu_info->rx_status.reception_type == HAL_RX_TYPE_MU_OFDMA) {
  93. rx_user_status = &ppdu_info->rx_user_status[user];
  94. cdp_mpdu_info->nss = rx_user_status->nss;
  95. cdp_mpdu_info->mcs = rx_user_status->mcs;
  96. cdp_mpdu_info->mu_ul_info_valid =
  97. rx_user_status->mu_ul_info_valid;
  98. cdp_mpdu_info->ofdma_ru_start_index =
  99. rx_user_status->ofdma_ru_start_index;
  100. cdp_mpdu_info->ofdma_ru_width =
  101. rx_user_status->ofdma_ru_width;
  102. } else {
  103. cdp_mpdu_info->nss = ppdu_info->rx_status.nss;
  104. cdp_mpdu_info->mcs = ppdu_info->rx_status.mcs;
  105. }
  106. cdp_mpdu_info->rate = ppdu_info->rx_status.rate;
  107. for (i = 0; i < MAX_CHAIN; i++)
  108. cdp_mpdu_info->per_chain_rssi[i] = ppdu_info->rx_status.rssi[i];
  109. }
  110. #ifdef WLAN_SUPPORT_RX_FLOW_TAG
  111. /**
  112. * dp_rx_mon_enh_capture_set_flow_tag() - Tags the actual nbuf with
  113. * cached flow tag data read from TLV
  114. * @pdev: pdev structure
  115. * @ppdu_info: ppdu info structure from monitor status ring
  116. * @user_id: user ID on which the PPDU is received
  117. * @nbuf: packet buffer on which metadata have to be updated
  118. *
  119. * Return: None
  120. */
  121. void dp_rx_mon_enh_capture_set_flow_tag(struct dp_pdev *pdev,
  122. struct hal_rx_ppdu_info *ppdu_info,
  123. uint32_t user_id, qdf_nbuf_t nbuf)
  124. {
  125. struct dp_soc *soc = pdev->soc;
  126. uint16_t fse_metadata;
  127. if (user_id >= MAX_MU_USERS)
  128. return;
  129. if (qdf_likely(!wlan_cfg_is_rx_flow_tag_enabled(soc->wlan_cfg_ctx)))
  130. return;
  131. if (ppdu_info->rx_msdu_info[user_id].is_flow_idx_invalid)
  132. return;
  133. if (ppdu_info->rx_msdu_info[user_id].is_flow_idx_timeout)
  134. return;
  135. fse_metadata =
  136. (uint16_t)ppdu_info->rx_msdu_info[user_id].fse_metadata & 0xFFFF;
  137. /* update the skb->cb with the user-specified tag/metadata */
  138. qdf_nbuf_set_rx_flow_tag(nbuf, fse_metadata);
  139. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  140. "Setting flow tag %u for userID %u", fse_metadata, user_id);
  141. ppdu_info->rx_msdu_info[user_id].fse_metadata = 0;
  142. ppdu_info->rx_msdu_info[user_id].flow_idx = 0;
  143. ppdu_info->rx_msdu_info[user_id].is_flow_idx_timeout = false;
  144. ppdu_info->rx_msdu_info[user_id].is_flow_idx_invalid = false;
  145. }
  146. /**
  147. * dp_rx_mon_enh_capture_set_flow_tag_in_trailer - update msdu trailer
  148. * with flow tag
  149. * @nbuf: packet buffer on which metadata have to be updated
  150. * @trailer: pointer to rx monitor-lite trailer
  151. *
  152. * Return: None
  153. */
  154. static inline void dp_rx_mon_enh_capture_set_flow_tag_in_trailer(
  155. qdf_nbuf_t nbuf, void *trailer)
  156. {
  157. uint16_t flow_tag = qdf_nbuf_get_rx_flow_tag(nbuf);
  158. struct dp_rx_mon_enh_trailer_data *nbuf_trailer =
  159. (struct dp_rx_mon_enh_trailer_data *)trailer;
  160. if (!flow_tag)
  161. return;
  162. nbuf_trailer->flow_tag = flow_tag;
  163. }
  164. #else
  165. void dp_rx_mon_enh_capture_set_flow_tag(struct dp_pdev *pdev,
  166. struct hal_rx_ppdu_info *ppdu_info,
  167. uint32_t user_id, qdf_nbuf_t nbuf)
  168. {
  169. }
  170. static inline void dp_rx_mon_enh_capture_set_flow_tag_in_trailer(
  171. qdf_nbuf_t nbuf, void *trailer)
  172. {
  173. }
  174. #endif /* WLAN_SUPPORT_RX_FLOW_TAG */
  175. #ifdef WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG
  176. /*
  177. * dp_rx_mon_enh_capture_set_protocol_tag() - Tags the actual nbuf with
  178. * cached protocol tag data read from TLV
  179. * @pdev: pdev structure
  180. * @ppdu_info: ppdu info structure from monitor status ring
  181. * @user_id: user ID on which the PPDU is received
  182. * @nbuf: packet buffer on which metadata have to be updated
  183. *
  184. * Return: none
  185. */
  186. static void
  187. dp_rx_mon_enh_capture_set_protocol_tag(struct dp_pdev *pdev,
  188. struct hal_rx_ppdu_info *ppdu_info,
  189. uint32_t user_id,
  190. qdf_nbuf_t nbuf)
  191. {
  192. uint32_t cce_metadata = 0;
  193. uint16_t protocol_tag = 0;
  194. if (user_id >= MAX_MU_USERS)
  195. return;
  196. /**
  197. * Since skb->cb is memset to 0, we can skip setting protocol tag to 0
  198. * in all the error paths.
  199. */
  200. cce_metadata = ppdu_info->rx_msdu_info[user_id].cce_metadata;
  201. /**
  202. * Received CCE metadata should be
  203. * within the valid limits
  204. */
  205. if (qdf_unlikely((cce_metadata < RX_PROTOCOL_TAG_START_OFFSET) ||
  206. (cce_metadata >= (RX_PROTOCOL_TAG_START_OFFSET
  207. + RX_PROTOCOL_TAG_MAX))))
  208. return;
  209. /**
  210. * The CCE metadata received is just the
  211. * packet_type + RX_PROTOCOL_TAG_START_OFFSET
  212. */
  213. cce_metadata -= RX_PROTOCOL_TAG_START_OFFSET;
  214. /**
  215. * Update the QDF packet with the user specified tag/metadata
  216. * by looking up tag value for received protocol type.
  217. */
  218. protocol_tag = pdev->rx_proto_tag_map[cce_metadata].tag;
  219. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  220. "Setting ProtoID:%d Tag %u in mon nbuf",
  221. cce_metadata, protocol_tag);
  222. qdf_nbuf_set_rx_protocol_tag(nbuf, protocol_tag);
  223. }
  224. /*
  225. * dp_rx_mon_enh_capture_tag_protocol_type() - Support protocol tagging
  226. * for packets captured in enhanced capture mode
  227. * @pdev: pdev structure
  228. * @ppdu_info: ppdu info structure from monitor status ring
  229. * @user_id: user ID on which the PPDU is received
  230. * @nbuf: packet buffer on which tag should be updated
  231. *
  232. * Return: none
  233. */
  234. static void
  235. dp_rx_mon_enh_capture_tag_protocol_type(struct dp_pdev *pdev,
  236. struct hal_rx_ppdu_info *ppdu_info,
  237. uint32_t user_id, qdf_nbuf_t nbuf)
  238. {
  239. /**
  240. * Since skb->cb is memset to 0, we can skip setting protocol tag to 0
  241. * in all the error paths.
  242. */
  243. if (!pdev->is_rx_protocol_tagging_enabled)
  244. return;
  245. /**
  246. * It is assumed that we have already received RX Header/ MSDU
  247. * Start TLV for this MSDU.
  248. */
  249. dp_rx_mon_enh_capture_set_protocol_tag(pdev, ppdu_info,
  250. user_id, nbuf);
  251. /* Reset MSDU tag variables on completion of every MSDU tag */
  252. ppdu_info->rx_msdu_info[user_id].cce_metadata = 0;
  253. }
  254. /*
  255. * dp_rx_mon_enh_capture_set_protocol_tag_in_trailer - update msdu trailer
  256. * with protocol tag
  257. * @nbuf: packet buffer on which metadata have to be updated
  258. * @trailer: pointer to rx monitor-lite trailer
  259. *
  260. * Return: void
  261. */
  262. static inline
  263. void dp_rx_mon_enh_capture_set_protocol_tag_in_trailer(qdf_nbuf_t nbuf,
  264. void *trailer)
  265. {
  266. uint16_t protocol_tag = qdf_nbuf_get_rx_protocol_tag(nbuf);
  267. struct dp_rx_mon_enh_trailer_data *nbuf_trailer =
  268. (struct dp_rx_mon_enh_trailer_data *)trailer;
  269. if (protocol_tag != 0)
  270. nbuf_trailer->protocol_tag = protocol_tag;
  271. }
  272. #else
  273. static void
  274. dp_rx_mon_enh_capture_tag_protocol_type(struct dp_pdev *pdev,
  275. struct hal_rx_ppdu_info *ppdu_info,
  276. uint32_t user_id, qdf_nbuf_t nbuf)
  277. {
  278. }
  279. static void
  280. dp_rx_mon_enh_capture_set_protocol_tag(struct dp_pdev *pdev,
  281. struct hal_rx_ppdu_info *ppdu_info,
  282. uint32_t user_id, qdf_nbuf_t nbuf)
  283. {
  284. }
  285. static inline
  286. void dp_rx_mon_enh_capture_set_protocol_tag_in_trailer(qdf_nbuf_t nbuf,
  287. void *trailer)
  288. {
  289. }
  290. #endif /* WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG */
  291. /*
  292. * dp_rx_mon_enh_capture_update_trailer() - Update trailer with custom data
  293. * @pdev: pdev structure
  294. * @nbuf: packet buffer on which metadata have to be updated
  295. *
  296. * Return: return number of bytes updated in the tail
  297. */
  298. static inline
  299. uint16_t dp_rx_mon_enh_capture_update_trailer(struct dp_pdev *pdev,
  300. qdf_nbuf_t nbuf)
  301. {
  302. uint64_t trailer;
  303. uint8_t *dest;
  304. struct dp_soc *soc = pdev->soc;
  305. struct dp_rx_mon_enh_trailer_data *nbuf_trailer =
  306. (struct dp_rx_mon_enh_trailer_data *)&trailer;
  307. if (qdf_unlikely(qdf_nbuf_len(nbuf) < sizeof(trailer)))
  308. return 0;
  309. trailer = RX_MON_CAP_ENH_TRAILER;
  310. if (wlan_cfg_is_rx_mon_protocol_flow_tag_enabled(soc->wlan_cfg_ctx)) {
  311. dp_rx_mon_enh_capture_set_protocol_tag_in_trailer(nbuf,
  312. nbuf_trailer);
  313. dp_rx_mon_enh_capture_set_flow_tag_in_trailer(nbuf,
  314. nbuf_trailer);
  315. }
  316. /**
  317. * Overwrite last 8 bytes of data with trailer. This is ok since we
  318. * do not care about the data in this debug mode.
  319. */
  320. qdf_nbuf_trim_tail(nbuf, sizeof(trailer));
  321. dest = qdf_nbuf_put_tail(nbuf, sizeof(trailer));
  322. if (qdf_likely(dest)) {
  323. qdf_mem_copy(dest, &trailer, sizeof(trailer));
  324. } else {
  325. dp_err("Unable to add tail room");
  326. return 0;
  327. }
  328. return sizeof(trailer);
  329. }
  330. /**
  331. * dp_rx_enh_capture_is_peer_enabled() - Is peer based enh capture enabled.
  332. * @soc: core txrx main context
  333. * @ppdu_info: Structure for rx ppdu info
  334. * @user_id: user id for MU Rx packet
  335. *
  336. * Return: none
  337. */
  338. static inline bool
  339. dp_rx_enh_capture_is_peer_enabled(struct dp_soc *soc,
  340. struct hal_rx_ppdu_info *ppdu_info,
  341. uint32_t user_id)
  342. {
  343. struct dp_peer *peer;
  344. struct dp_ast_entry *ast_entry;
  345. uint32_t ast_index;
  346. ast_index = ppdu_info->rx_user_status[user_id].ast_index;
  347. if (ast_index < wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  348. ast_entry = soc->ast_table[ast_index];
  349. if (ast_entry) {
  350. peer = ast_entry->peer;
  351. if (peer && (peer->peer_ids[0] != HTT_INVALID_PEER))
  352. return peer->rx_cap_enabled;
  353. }
  354. }
  355. return false;
  356. }
  357. /*
  358. * dp_rx_handle_enh_capture() - Deliver Rx enhanced capture data
  359. * @pdev: pdev ctx
  360. * @ppdu_info: ppdu info structure from monitor status ring
  361. *
  362. * Return: QDF status
  363. */
  364. QDF_STATUS
  365. dp_rx_handle_enh_capture(struct dp_soc *soc, struct dp_pdev *pdev,
  366. struct hal_rx_ppdu_info *ppdu_info)
  367. {
  368. qdf_nbuf_t mpdu_head;
  369. uint32_t user;
  370. qdf_nbuf_queue_t *mpdu_q;
  371. struct cdp_rx_indication_mpdu *mpdu_ind;
  372. struct cdp_rx_indication_mpdu_info *mpdu_info;
  373. struct msdu_list *msdu_list;
  374. user = 0;
  375. mpdu_q = &pdev->mpdu_q[user];
  376. while (!qdf_nbuf_is_queue_empty(mpdu_q) && user < MAX_MU_USERS) {
  377. msdu_list = &pdev->msdu_list[user];
  378. dp_rx_free_msdu_list(msdu_list);
  379. pdev->is_mpdu_hdr[user] = true;
  380. if (pdev->rx_enh_capture_peer &&
  381. !dp_rx_enh_capture_is_peer_enabled(
  382. soc, ppdu_info, user)) {
  383. qdf_nbuf_queue_free(mpdu_q);
  384. } else {
  385. mpdu_ind = &pdev->mpdu_ind;
  386. mpdu_info = &mpdu_ind->mpdu_info;
  387. dp_rx_populate_cdp_indication_mpdu_info(
  388. pdev, &pdev->ppdu_info, mpdu_info, user);
  389. while ((mpdu_head = qdf_nbuf_queue_remove(mpdu_q))) {
  390. mpdu_ind->nbuf = mpdu_head;
  391. mpdu_info->fcs_err =
  392. QDF_NBUF_CB_RX_FCS_ERR(mpdu_head);
  393. dp_wdi_event_handler(WDI_EVENT_RX_MPDU,
  394. soc, mpdu_ind,
  395. HTT_INVALID_PEER,
  396. WDI_NO_VAL,
  397. pdev->pdev_id);
  398. }
  399. }
  400. user++;
  401. mpdu_q = &pdev->mpdu_q[user];
  402. }
  403. return QDF_STATUS_SUCCESS;
  404. }
  405. /*
  406. * dp_rx_mon_enh_capture_process() - Rx enhanced capture mode
  407. * processing.
  408. * @pdev: pdev structure
  409. * @tlv_status: processed TLV status
  410. * @status_nbuf: monitor status ring buffer
  411. * @ppdu_info: ppdu info structure from monitor status ring
  412. * @nbuf_used: nbuf need a clone
  413. *
  414. * Return: none
  415. */
  416. void
  417. dp_rx_mon_enh_capture_process(struct dp_pdev *pdev, uint32_t tlv_status,
  418. qdf_nbuf_t status_nbuf,
  419. struct hal_rx_ppdu_info *ppdu_info,
  420. bool *nbuf_used)
  421. {
  422. qdf_nbuf_t nbuf;
  423. struct msdu_list *msdu_list;
  424. uint32_t user_id;
  425. struct dp_soc *soc;
  426. qdf_nbuf_t mpdu_head;
  427. if (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_DISABLED)
  428. return;
  429. user_id = ppdu_info->user_id;
  430. if (user_id >= MAX_MU_USERS)
  431. return;
  432. if ((tlv_status == HAL_TLV_STATUS_HEADER) && (
  433. (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU_MSDU) ||
  434. ((pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU) &&
  435. pdev->is_mpdu_hdr[user_id]))) {
  436. if (*nbuf_used) {
  437. nbuf = qdf_nbuf_clone(status_nbuf);
  438. } else {
  439. *nbuf_used = true;
  440. nbuf = status_nbuf;
  441. }
  442. if (!nbuf)
  443. return;
  444. /* Truncate 4 bytes containing PPDU ID */
  445. dp_nbuf_set_data_and_len(nbuf, ppdu_info->data,
  446. ppdu_info->hdr_len - 4);
  447. if (pdev->is_mpdu_hdr[user_id]) {
  448. soc = pdev->soc;
  449. mpdu_head = qdf_nbuf_alloc(soc->osdev,
  450. RX_ENH_CB_BUF_SIZE + RX_ENH_CB_BUF_RESERVATION,
  451. RX_ENH_CB_BUF_RESERVATION,
  452. RX_ENH_CB_BUF_ALIGNMENT,
  453. FALSE);
  454. if (mpdu_head == NULL)
  455. return;
  456. qdf_nbuf_queue_add(&pdev->mpdu_q[user_id],
  457. mpdu_head);
  458. pdev->is_mpdu_hdr[user_id] = false;
  459. }
  460. msdu_list = &pdev->msdu_list[user_id];
  461. if (!msdu_list->head)
  462. msdu_list->head = nbuf;
  463. else
  464. msdu_list->tail->next = nbuf;
  465. msdu_list->tail = nbuf;
  466. msdu_list->sum_len += qdf_nbuf_len(nbuf);
  467. }
  468. if (tlv_status == HAL_TLV_STATUS_MPDU_END) {
  469. msdu_list = &pdev->msdu_list[user_id];
  470. mpdu_head = qdf_nbuf_queue_last(&pdev->mpdu_q[user_id]);
  471. if (mpdu_head) {
  472. qdf_nbuf_append_ext_list(mpdu_head,
  473. msdu_list->head,
  474. msdu_list->sum_len);
  475. msdu_list->head = NULL;
  476. msdu_list->tail = NULL;
  477. msdu_list->sum_len = 0;
  478. QDF_NBUF_CB_RX_FCS_ERR(mpdu_head)
  479. = ppdu_info->fcs_err;
  480. } else {
  481. dp_rx_free_msdu_list(msdu_list);
  482. }
  483. pdev->is_mpdu_hdr[user_id] = true;
  484. }
  485. /* Tag the MSDU/MPDU if a cce_metadata is valid */
  486. if ((tlv_status == HAL_TLV_STATUS_MSDU_END) &&
  487. (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU_MSDU)) {
  488. bool is_rx_mon_protocol_flow_tag_en;
  489. /**
  490. * Proceed only if this is a data frame.
  491. * We could also rx probes, etc.
  492. */
  493. if (!(ppdu_info->nac_info.fc_valid &&
  494. (IEEE80211_FC0_TYPE_DATA ==
  495. (ppdu_info->nac_info.frame_control &
  496. IEEE80211_FC0_TYPE_MASK))))
  497. return;
  498. msdu_list = &pdev->msdu_list[user_id];
  499. qdf_assert_always(msdu_list->head);
  500. /**
  501. * Directly move the last MSDU and fetch the same.
  502. * The earlier MSDUs should already be tagged as the
  503. * packets are tagged at the end of every RX
  504. * MSDU.
  505. */
  506. nbuf = msdu_list->tail;
  507. is_rx_mon_protocol_flow_tag_en =
  508. wlan_cfg_is_rx_mon_protocol_flow_tag_enabled(
  509. pdev->soc->wlan_cfg_ctx);
  510. if (is_rx_mon_protocol_flow_tag_en) {
  511. /* Set the protocol tag value from CCE metadata */
  512. dp_rx_mon_enh_capture_tag_protocol_type(pdev, ppdu_info,
  513. user_id, nbuf);
  514. /* Set the flow tag from FSE metadata */
  515. dp_rx_mon_enh_capture_set_flow_tag(pdev, ppdu_info,
  516. user_id, nbuf);
  517. }
  518. if (!pdev->is_rx_enh_capture_trailer_enabled)
  519. return;
  520. /**
  521. * Update necessary information in trailer (for debug purpose)
  522. */
  523. dp_rx_mon_enh_capture_update_trailer(pdev, nbuf);
  524. }
  525. }
  526. /*
  527. * dp_config_enh_rx_capture()- API to enable/disable enhanced rx capture
  528. * @pdev_handle: DP_PDEV handle
  529. * @val: user provided value
  530. *
  531. * Return: 0 for success. nonzero for failure.
  532. */
  533. QDF_STATUS
  534. dp_config_enh_rx_capture(struct dp_pdev *pdev, uint32_t val)
  535. {
  536. uint8_t rx_cap_mode = (val & CDP_RX_ENH_CAPTURE_MODE_MASK);
  537. uint32_t rx_enh_capture_peer;
  538. bool is_mpdu_hdr = false;
  539. uint8_t user_id;
  540. enum dp_mon_filter_action action = DP_MON_FILTER_SET;
  541. rx_enh_capture_peer =
  542. (val & CDP_RX_ENH_CAPTURE_PEER_MASK)
  543. >> CDP_RX_ENH_CAPTURE_PEER_LSB;
  544. if (pdev->mcopy_mode || (rx_cap_mode < CDP_RX_ENH_CAPTURE_DISABLED) ||
  545. (rx_cap_mode > CDP_RX_ENH_CAPTURE_MPDU_MSDU)) {
  546. dp_err("Invalid mode: %d", rx_cap_mode);
  547. return QDF_STATUS_E_INVAL;
  548. }
  549. if (rx_enh_capture_peer > CDP_RX_ENH_CAPTURE_PEER_ENABLED) {
  550. dp_err("Invalid peer filter %d", rx_enh_capture_peer);
  551. return QDF_STATUS_E_INVAL;
  552. }
  553. if ((pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_DISABLED) &&
  554. (rx_cap_mode == CDP_RX_ENH_CAPTURE_DISABLED)) {
  555. dp_err("Rx capture is already disabled %d", rx_cap_mode);
  556. return QDF_STATUS_E_INVAL;
  557. }
  558. /*
  559. * Store the monitor vdev if present. The monitor vdev will be restored
  560. * when the Rx enhance capture mode will be disabled.
  561. */
  562. if (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_DISABLED &&
  563. rx_cap_mode != CDP_RX_ENH_CAPTURE_DISABLED) {
  564. pdev->rx_enh_monitor_vdev = pdev->monitor_vdev;
  565. }
  566. /*
  567. * Disable the monitor mode and re-enable it later if enhance capture
  568. * gets enabled later.
  569. */
  570. dp_reset_monitor_mode((struct cdp_soc_t *)pdev->soc, pdev->pdev_id, 0);
  571. if (pdev->rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED &&
  572. rx_cap_mode == CDP_RX_ENH_CAPTURE_DISABLED) {
  573. pdev->monitor_vdev = pdev->rx_enh_monitor_vdev;
  574. pdev->rx_enh_monitor_vdev = NULL;
  575. action = DP_MON_FILTER_CLEAR;
  576. }
  577. pdev->rx_enh_capture_mode = rx_cap_mode;
  578. pdev->rx_enh_capture_peer = rx_enh_capture_peer;
  579. if (rx_cap_mode != CDP_RX_ENH_CAPTURE_DISABLED)
  580. is_mpdu_hdr = true;
  581. for (user_id = 0; user_id < MAX_MU_USERS; user_id++)
  582. pdev->is_mpdu_hdr[user_id] = is_mpdu_hdr;
  583. /* Use a bit from val to enable MSDU trailer for internal debug use */
  584. pdev->is_rx_enh_capture_trailer_enabled =
  585. (val & RX_ENH_CAPTURE_TRAILER_ENABLE_MASK) ? true : false;
  586. /*
  587. * Restore the monitor filters if previously monitor mode was enabled.
  588. */
  589. if (pdev->monitor_vdev) {
  590. pdev->monitor_configured = true;
  591. dp_mon_filter_setup_mon_mode(pdev);
  592. }
  593. /*
  594. * Clear up the monitor mode filters if the monitor mode is enabled.
  595. * Resotre the monitor mode filters once the Rx enhance capture is
  596. * disabled.
  597. */
  598. if (action == DP_MON_FILTER_SET)
  599. dp_mon_filter_setup_rx_enh_capture(pdev);
  600. else
  601. dp_mon_filter_reset_rx_enh_capture(pdev);
  602. return dp_mon_filter_update(pdev);
  603. }
  604. void
  605. dp_peer_set_rx_capture_enabled(struct dp_peer *peer, bool value)
  606. {
  607. peer->rx_cap_enabled = value;
  608. }
  609. #endif /* WLAN_RX_PKT_CAPTURE_ENH */