dp_rx_mon_feature.c 20 KB

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