dp_rx_mon_feature.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. /*
  2. * Copyright (c) 2017-2019 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 WLAN_RX_PKT_CAPTURE_ENH
  31. static inline void
  32. dp_rx_free_msdu_list(struct msdu_list *msdu_list)
  33. {
  34. qdf_nbuf_list_free(msdu_list->head);
  35. msdu_list->head = NULL;
  36. msdu_list->tail = NULL;
  37. msdu_list->sum_len = 0;
  38. }
  39. /**
  40. * dp_nbuf_set_data_and_len() - set nbuf data and len
  41. * @buf: Network buf instance
  42. * @data: pointer to nbuf data
  43. * @len: nbuf data length
  44. *
  45. * Return: none
  46. */
  47. static inline void
  48. dp_nbuf_set_data_and_len(qdf_nbuf_t buf, unsigned char *data,
  49. int len)
  50. {
  51. qdf_nbuf_set_data_pointer(buf, data);
  52. qdf_nbuf_set_len(buf, len);
  53. qdf_nbuf_set_tail_pointer(buf, len);
  54. }
  55. /*
  56. * dp_rx_populate_cdp_indication_mpdu_info() - Populate cdp rx indication
  57. * MPDU info structure
  58. * @pdev: pdev ctx
  59. * @ppdu_info: ppdu info structure from monitor status ring
  60. * @cdp_mpdu_info: cdp rx indication MPDU info structure
  61. * @user: user ID
  62. *
  63. * Return: none
  64. */
  65. void
  66. dp_rx_populate_cdp_indication_mpdu_info(
  67. struct dp_pdev *pdev,
  68. struct hal_rx_ppdu_info *ppdu_info,
  69. struct cdp_rx_indication_mpdu_info *cdp_mpdu_info,
  70. uint32_t user)
  71. {
  72. int i;
  73. struct mon_rx_user_status *rx_user_status;
  74. cdp_mpdu_info->ppdu_id = ppdu_info->com_info.ppdu_id;
  75. cdp_mpdu_info->channel = ppdu_info->rx_status.chan_num;
  76. cdp_mpdu_info->duration = ppdu_info->rx_status.duration;
  77. cdp_mpdu_info->timestamp = ppdu_info->rx_status.tsft;
  78. cdp_mpdu_info->bw = ppdu_info->rx_status.bw;
  79. if ((ppdu_info->rx_status.sgi == VHT_SGI_NYSM) &&
  80. (ppdu_info->rx_status.preamble_type == HAL_RX_PKT_TYPE_11AC))
  81. cdp_mpdu_info->gi = CDP_SGI_0_4_US;
  82. else
  83. cdp_mpdu_info->gi = ppdu_info->rx_status.sgi;
  84. cdp_mpdu_info->ldpc = ppdu_info->rx_status.ldpc;
  85. cdp_mpdu_info->preamble = ppdu_info->rx_status.preamble_type;
  86. cdp_mpdu_info->ppdu_type = ppdu_info->rx_status.reception_type;
  87. cdp_mpdu_info->rssi_comb = ppdu_info->rx_status.rssi_comb;
  88. cdp_mpdu_info->nf = ppdu_info->rx_status.chan_noise_floor;
  89. if (ppdu_info->rx_status.reception_type == HAL_RX_TYPE_MU_OFDMA) {
  90. rx_user_status = &ppdu_info->rx_user_status[user];
  91. cdp_mpdu_info->nss = rx_user_status->nss;
  92. cdp_mpdu_info->mcs = rx_user_status->mcs;
  93. cdp_mpdu_info->ofdma_info_valid =
  94. rx_user_status->ofdma_info_valid;
  95. cdp_mpdu_info->ofdma_ru_start_index =
  96. rx_user_status->dl_ofdma_ru_start_index;
  97. cdp_mpdu_info->ofdma_ru_width =
  98. rx_user_status->dl_ofdma_ru_width;
  99. } else {
  100. cdp_mpdu_info->nss = ppdu_info->rx_status.nss;
  101. cdp_mpdu_info->mcs = ppdu_info->rx_status.mcs;
  102. }
  103. cdp_mpdu_info->rate = ppdu_info->rx_status.rate;
  104. for (i = 0; i < MAX_CHAIN; i++)
  105. cdp_mpdu_info->per_chain_rssi[i] = ppdu_info->rx_status.rssi[i];
  106. }
  107. #ifdef WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG
  108. /*
  109. * dp_rx_mon_enh_capture_set_protocol_tag() - Tags the actual nbuf with
  110. * cached data read from TLV
  111. * @pdev: pdev structure
  112. * @ppdu_info: ppdu info structure from monitor status ring
  113. * @user_id: user ID on which the PPDU is received
  114. * @nbuf: packet buffer on which metadata have to be updated
  115. *
  116. * Return: none
  117. */
  118. static void
  119. dp_rx_mon_enh_capture_set_protocol_tag(struct dp_pdev *pdev,
  120. struct hal_rx_ppdu_info *ppdu_info,
  121. uint32_t user_id,
  122. qdf_nbuf_t nbuf)
  123. {
  124. uint32_t cce_metadata = 0;
  125. uint16_t protocol_tag = 0;
  126. if (user_id >= MAX_MU_USERS)
  127. return;
  128. /**
  129. * Since skb->cb is memset to 0, we can skip setting protocol tag to 0
  130. * in all the error paths.
  131. */
  132. cce_metadata = ppdu_info->rx_msdu_info[user_id].cce_metadata;
  133. /**
  134. * Received CCE metadata should be
  135. * within the valid limits
  136. */
  137. if (qdf_unlikely((cce_metadata < RX_PROTOCOL_TAG_START_OFFSET) ||
  138. (cce_metadata >= (RX_PROTOCOL_TAG_START_OFFSET
  139. + RX_PROTOCOL_TAG_MAX))))
  140. return;
  141. /**
  142. * The CCE metadata received is just the
  143. * packet_type + RX_PROTOCOL_TAG_START_OFFSET
  144. */
  145. cce_metadata -= RX_PROTOCOL_TAG_START_OFFSET;
  146. /**
  147. * Update the QDF packet with the user specified tag/metadata
  148. * by looking up tag value for received protocol type.
  149. */
  150. protocol_tag = pdev->rx_proto_tag_map[cce_metadata].tag;
  151. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
  152. "%s: Setting ProtoID:%d Tag %u", __func__,
  153. cce_metadata, protocol_tag);
  154. qdf_nbuf_set_rx_protocol_tag(nbuf, protocol_tag);
  155. }
  156. /*
  157. * dp_rx_mon_enh_capture_tag_protocol_type() - Support protocol tagging
  158. * for packets captured in enhanced capture mode
  159. * @pdev: pdev structure
  160. * @ppdu_info: ppdu info structure from monitor status ring
  161. * @user_id: user ID on which the PPDU is received
  162. * @nbuf: packet buffer on which tag should be updated
  163. *
  164. * Return: none
  165. */
  166. static void
  167. dp_rx_mon_enh_capture_tag_protocol_type(struct dp_pdev *pdev,
  168. struct hal_rx_ppdu_info *ppdu_info,
  169. uint32_t user_id, qdf_nbuf_t nbuf)
  170. {
  171. /**
  172. * Since skb->cb is memset to 0, we can skip setting protocol tag to 0
  173. * in all the error paths.
  174. */
  175. if (!pdev->is_rx_protocol_tagging_enabled)
  176. return;
  177. /**
  178. * It is assumed that we have already received RX Header/ MSDU
  179. * Start TLV for this MSDU.
  180. */
  181. dp_rx_mon_enh_capture_set_protocol_tag(pdev, ppdu_info,
  182. user_id, nbuf);
  183. /* Reset MSDU tag variables on completion of every MSDU tag */
  184. ppdu_info->rx_msdu_info[user_id].cce_metadata = 0;
  185. }
  186. /*
  187. * dp_rx_mon_enh_capture_set_protocol_tag_in_trailer - update msdu trailer
  188. * with protocol tag
  189. * @nbuf: packet buffer on which metadata have to be updated
  190. * @trailer: pointer to rx monitor-lite trailer
  191. *
  192. * Return: void
  193. */
  194. static inline
  195. void dp_rx_mon_enh_capture_set_protocol_tag_in_trailer(qdf_nbuf_t nbuf,
  196. void *trailer)
  197. {
  198. uint16_t protocol_tag = qdf_nbuf_get_rx_protocol_tag(nbuf);
  199. struct dp_rx_mon_enh_trailer_data *nbuf_trailer =
  200. (struct dp_rx_mon_enh_trailer_data *)trailer;
  201. if (protocol_tag != 0)
  202. nbuf_trailer->protocol_tag = protocol_tag;
  203. }
  204. #else
  205. static void
  206. dp_rx_mon_enh_capture_tag_protocol_type(struct dp_pdev *pdev,
  207. struct hal_rx_ppdu_info *ppdu_info,
  208. uint32_t user_id, qdf_nbuf_t nbuf)
  209. {
  210. }
  211. static void
  212. dp_rx_mon_enh_capture_set_protocol_tag(struct dp_pdev *pdev,
  213. struct hal_rx_ppdu_info *ppdu_info,
  214. uint32_t user_id, qdf_nbuf_t nbuf)
  215. {
  216. }
  217. static inline
  218. void dp_rx_mon_enh_capture_set_protocol_tag_in_trailer(qdf_nbuf_t nbuf,
  219. void *trailer)
  220. {
  221. }
  222. #endif /* WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG */
  223. /*
  224. * dp_rx_mon_enh_capture_update_trailer() - Update trailer with custom data
  225. * @pdev: pdev structure
  226. * @nbuf: packet buffer on which metadata have to be updated
  227. *
  228. * Return: return number of bytes updated in the tail
  229. */
  230. static inline
  231. uint16_t dp_rx_mon_enh_capture_update_trailer(struct dp_pdev *pdev,
  232. qdf_nbuf_t nbuf)
  233. {
  234. uint64_t trailer;
  235. uint8_t *dest;
  236. struct dp_rx_mon_enh_trailer_data *nbuf_trailer =
  237. (struct dp_rx_mon_enh_trailer_data *)&trailer;
  238. if (qdf_unlikely(qdf_nbuf_len(nbuf) < sizeof(trailer)))
  239. return 0;
  240. trailer = RX_MON_CAP_ENH_TRAILER;
  241. dp_rx_mon_enh_capture_set_protocol_tag_in_trailer(nbuf, nbuf_trailer);
  242. /**
  243. * Overwrite last 8 bytes of data with trailer. This is ok since we
  244. * do not care about the data in this debug mode.
  245. */
  246. qdf_nbuf_trim_tail(nbuf, sizeof(trailer));
  247. dest = qdf_nbuf_put_tail(nbuf, sizeof(trailer));
  248. if (qdf_likely(dest)) {
  249. qdf_mem_copy(dest, &trailer, sizeof(trailer));
  250. } else {
  251. dp_err("Unable to add tail room");
  252. return 0;
  253. }
  254. return sizeof(trailer);
  255. }
  256. /*
  257. * dp_rx_handle_enh_capture() - Deliver Rx enhanced capture data
  258. * @pdev: pdev ctx
  259. * @ppdu_info: ppdu info structure from monitor status ring
  260. *
  261. * Return: QDF status
  262. */
  263. QDF_STATUS
  264. dp_rx_handle_enh_capture(struct dp_soc *soc, struct dp_pdev *pdev,
  265. struct hal_rx_ppdu_info *ppdu_info)
  266. {
  267. qdf_nbuf_t mpdu_head;
  268. uint32_t user;
  269. qdf_nbuf_queue_t *mpdu_q;
  270. struct cdp_rx_indication_mpdu *mpdu_ind;
  271. struct cdp_rx_indication_mpdu_info *mpdu_info;
  272. struct msdu_list *msdu_list;
  273. user = 0;
  274. mpdu_q = &pdev->mpdu_q[user];
  275. while (!qdf_nbuf_is_queue_empty(mpdu_q) && user < MAX_MU_USERS) {
  276. msdu_list = &pdev->msdu_list[user];
  277. dp_rx_free_msdu_list(msdu_list);
  278. mpdu_ind = &pdev->mpdu_ind[user];
  279. mpdu_info = &mpdu_ind->mpdu_info;
  280. pdev->is_mpdu_hdr[user] = true;
  281. dp_rx_populate_cdp_indication_mpdu_info(
  282. pdev, &pdev->ppdu_info, mpdu_info, user);
  283. while ((mpdu_head = qdf_nbuf_queue_remove(mpdu_q))) {
  284. mpdu_ind->nbuf = mpdu_head;
  285. mpdu_info->fcs_err =
  286. QDF_NBUF_CB_RX_FCS_ERR(mpdu_head);
  287. dp_wdi_event_handler(WDI_EVENT_RX_MPDU,
  288. soc, mpdu_ind, HTT_INVALID_PEER,
  289. WDI_NO_VAL, pdev->pdev_id);
  290. }
  291. user++;
  292. mpdu_q = &pdev->mpdu_q[user];
  293. }
  294. return QDF_STATUS_SUCCESS;
  295. }
  296. /*
  297. * dp_rx_mon_enh_capture_process() - Rx enhanced capture mode
  298. * processing.
  299. * @pdev: pdev structure
  300. * @tlv_status: processed TLV status
  301. * @status_nbuf: monitor status ring buffer
  302. * @ppdu_info: ppdu info structure from monitor status ring
  303. * @nbuf_used: nbuf need a clone
  304. *
  305. * Return: none
  306. */
  307. void
  308. dp_rx_mon_enh_capture_process(struct dp_pdev *pdev, uint32_t tlv_status,
  309. qdf_nbuf_t status_nbuf,
  310. struct hal_rx_ppdu_info *ppdu_info,
  311. bool *nbuf_used)
  312. {
  313. qdf_nbuf_t nbuf;
  314. struct msdu_list *msdu_list;
  315. uint32_t user_id;
  316. struct dp_soc *soc;
  317. qdf_nbuf_t mpdu_head;
  318. if (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_DISABLED)
  319. return;
  320. user_id = ppdu_info->user_id;
  321. if (user_id >= MAX_MU_USERS)
  322. return;
  323. if ((tlv_status == HAL_TLV_STATUS_HEADER) && (
  324. (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU_MSDU) ||
  325. ((pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU) &&
  326. pdev->is_mpdu_hdr[user_id]))) {
  327. if (*nbuf_used) {
  328. nbuf = qdf_nbuf_clone(status_nbuf);
  329. } else {
  330. *nbuf_used = true;
  331. nbuf = status_nbuf;
  332. }
  333. if (!nbuf)
  334. return;
  335. /* Truncate 4 bytes containing PPDU ID */
  336. dp_nbuf_set_data_and_len(nbuf, ppdu_info->data,
  337. ppdu_info->hdr_len - 4);
  338. if (pdev->is_mpdu_hdr[user_id]) {
  339. soc = pdev->soc;
  340. mpdu_head = qdf_nbuf_alloc(soc->osdev,
  341. RX_ENH_CB_BUF_SIZE + RX_ENH_CB_BUF_RESERVATION,
  342. RX_ENH_CB_BUF_RESERVATION,
  343. RX_ENH_CB_BUF_ALIGNMENT,
  344. FALSE);
  345. if (mpdu_head == NULL)
  346. return;
  347. qdf_nbuf_queue_add(&pdev->mpdu_q[user_id],
  348. mpdu_head);
  349. pdev->is_mpdu_hdr[user_id] = false;
  350. }
  351. msdu_list = &pdev->msdu_list[user_id];
  352. if (!msdu_list->head)
  353. msdu_list->head = nbuf;
  354. else
  355. msdu_list->tail->next = nbuf;
  356. msdu_list->tail = nbuf;
  357. msdu_list->sum_len += qdf_nbuf_len(nbuf);
  358. }
  359. if (tlv_status == HAL_TLV_STATUS_MPDU_END) {
  360. msdu_list = &pdev->msdu_list[user_id];
  361. mpdu_head = qdf_nbuf_queue_last(&pdev->mpdu_q[user_id]);
  362. if (mpdu_head) {
  363. qdf_nbuf_append_ext_list(mpdu_head,
  364. msdu_list->head,
  365. msdu_list->sum_len);
  366. msdu_list->head = NULL;
  367. msdu_list->tail = NULL;
  368. msdu_list->sum_len = 0;
  369. QDF_NBUF_CB_RX_FCS_ERR(mpdu_head)
  370. = ppdu_info->fcs_err;
  371. } else {
  372. dp_rx_free_msdu_list(msdu_list);
  373. }
  374. pdev->is_mpdu_hdr[user_id] = true;
  375. }
  376. /* Tag the MSDU/MPDU if a cce_metadata is valid */
  377. if ((tlv_status == HAL_TLV_STATUS_MSDU_END) &&
  378. (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU_MSDU)) {
  379. /**
  380. * Proceed only if this is a data frame.
  381. * We could also rx probes, etc.
  382. */
  383. if (!(ppdu_info->nac_info.fc_valid &&
  384. (IEEE80211_FC0_TYPE_DATA ==
  385. (ppdu_info->nac_info.frame_control &
  386. IEEE80211_FC0_TYPE_MASK))))
  387. return;
  388. msdu_list = &pdev->msdu_list[user_id];
  389. qdf_assert_always(msdu_list->head);
  390. /**
  391. * Directly move the last MSDU and fetch the same.
  392. * The earlier MSDUs should already be tagged as the
  393. * packets are tagged at the end of every RX
  394. * MSDU.
  395. */
  396. nbuf = msdu_list->tail;
  397. /**
  398. * Set the protocol tag value from CCE metadata.
  399. */
  400. dp_rx_mon_enh_capture_tag_protocol_type(pdev, ppdu_info,
  401. user_id, nbuf);
  402. if (!pdev->is_rx_enh_capture_trailer_enabled)
  403. return;
  404. /**
  405. * Update necessary information in trailer (for debug purpose)
  406. */
  407. dp_rx_mon_enh_capture_update_trailer(pdev, nbuf);
  408. }
  409. }
  410. /*
  411. * dp_config_enh_rx_capture()- API to enable/disable enhanced rx capture
  412. * @pdev_handle: DP_PDEV handle
  413. * @val: user provided value
  414. *
  415. * Return: 0 for success. nonzero for failure.
  416. */
  417. QDF_STATUS
  418. dp_config_enh_rx_capture(struct cdp_pdev *pdev_handle, uint8_t val)
  419. {
  420. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  421. uint8_t rx_cap_mode = (val & RX_ENH_CAPTURE_MODE_MASK);
  422. bool is_mpdu_hdr = false;
  423. uint8_t user_id;
  424. if (pdev->mcopy_mode || (rx_cap_mode < CDP_RX_ENH_CAPTURE_DISABLED) ||
  425. (rx_cap_mode > CDP_RX_ENH_CAPTURE_MPDU_MSDU)) {
  426. dp_err("Invalid mode: %d", rx_cap_mode);
  427. return QDF_STATUS_E_INVAL;
  428. }
  429. dp_reset_monitor_mode(pdev_handle);
  430. pdev->rx_enh_capture_mode = rx_cap_mode;
  431. if (rx_cap_mode != CDP_RX_ENH_CAPTURE_DISABLED)
  432. is_mpdu_hdr = true;
  433. for (user_id = 0; user_id < MAX_MU_USERS; user_id++)
  434. pdev->is_mpdu_hdr[user_id] = is_mpdu_hdr;
  435. /* Use a bit from val to enable MSDU trailer for internal debug use */
  436. pdev->is_rx_enh_capture_trailer_enabled =
  437. (val & RX_ENH_CAPTURE_TRAILER_ENABLE_MASK) ? true : false;
  438. return dp_pdev_configure_monitor_rings(pdev);
  439. }
  440. #endif /* WLAN_RX_PKT_CAPTURE_ENH */