dp_rx_mon_feature.c 14 KB

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