dp_rx_mon_feature.c 13 KB

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