iwl-devtrace.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /******************************************************************************
  3. *
  4. * Copyright(c) 2009 - 2014 Intel Corporation. All rights reserved.
  5. * Copyright(C) 2016 Intel Deutschland GmbH
  6. * Copyright(c) 2018, 2023 Intel Corporation
  7. *****************************************************************************/
  8. #ifndef __IWLWIFI_DEVICE_TRACE
  9. #define __IWLWIFI_DEVICE_TRACE
  10. #include <linux/skbuff.h>
  11. #include <linux/ieee80211.h>
  12. #include <net/cfg80211.h>
  13. #include <net/mac80211.h>
  14. #include "iwl-trans.h"
  15. static inline bool iwl_trace_data(struct sk_buff *skb)
  16. {
  17. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  18. struct ieee80211_hdr *hdr = (void *)skb->data;
  19. __le16 fc = hdr->frame_control;
  20. int offs = 24; /* start with normal header length */
  21. if (!ieee80211_is_data(fc))
  22. return false;
  23. /* If upper layers wanted TX status it's an important frame */
  24. if (info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS)
  25. return false;
  26. /* Try to determine if the frame is EAPOL. This might have false
  27. * positives (if there's no RFC 1042 header and we compare to some
  28. * payload instead) but since we're only doing tracing that's not
  29. * a problem.
  30. */
  31. if (ieee80211_has_a4(fc))
  32. offs += 6;
  33. if (ieee80211_is_data_qos(fc))
  34. offs += 2;
  35. /* don't account for crypto - these are unencrypted */
  36. /* also account for the RFC 1042 header, of course */
  37. offs += 6;
  38. return skb->len <= offs + 2 ||
  39. *(__be16 *)(skb->data + offs) != cpu_to_be16(ETH_P_PAE);
  40. }
  41. static inline size_t iwl_rx_trace_len(const struct iwl_trans *trans,
  42. void *rxbuf, size_t len,
  43. size_t *out_hdr_offset)
  44. {
  45. struct iwl_cmd_header *cmd = (void *)((u8 *)rxbuf + sizeof(__le32));
  46. struct ieee80211_hdr *hdr = NULL;
  47. size_t hdr_offset;
  48. if (cmd->cmd != trans->rx_mpdu_cmd)
  49. return len;
  50. hdr_offset = sizeof(struct iwl_cmd_header) +
  51. trans->rx_mpdu_cmd_hdr_size;
  52. if (out_hdr_offset)
  53. *out_hdr_offset = hdr_offset;
  54. hdr = (void *)((u8 *)cmd + hdr_offset);
  55. if (!ieee80211_is_data(hdr->frame_control))
  56. return len;
  57. /* maybe try to identify EAPOL frames? */
  58. return sizeof(__le32) + sizeof(*cmd) + trans->rx_mpdu_cmd_hdr_size +
  59. ieee80211_hdrlen(hdr->frame_control);
  60. }
  61. #include <linux/tracepoint.h>
  62. #include <linux/device.h>
  63. #if !defined(CONFIG_IWLWIFI_DEVICE_TRACING) || defined(__CHECKER__)
  64. #undef TRACE_EVENT
  65. #define TRACE_EVENT(name, proto, ...) \
  66. static inline void trace_ ## name(proto) {}
  67. #undef DECLARE_EVENT_CLASS
  68. #define DECLARE_EVENT_CLASS(...)
  69. #undef DEFINE_EVENT
  70. #define DEFINE_EVENT(evt_class, name, proto, ...) \
  71. static inline void trace_ ## name(proto) {}
  72. #endif
  73. #define DEV_ENTRY __string(dev, dev_name(dev))
  74. #define DEV_ASSIGN __assign_str(dev)
  75. #include "iwl-devtrace-io.h"
  76. #include "iwl-devtrace-ucode.h"
  77. #include "iwl-devtrace-msg.h"
  78. #include "iwl-devtrace-data.h"
  79. #include "iwl-devtrace-iwlwifi.h"
  80. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  81. DECLARE_TRACEPOINT(iwlwifi_dev_rx);
  82. DECLARE_TRACEPOINT(iwlwifi_dev_rx_data);
  83. #endif
  84. void __trace_iwlwifi_dev_rx(struct iwl_trans *trans, void *pkt, size_t len);
  85. static inline void maybe_trace_iwlwifi_dev_rx(struct iwl_trans *trans,
  86. void *pkt, size_t len)
  87. {
  88. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  89. if (tracepoint_enabled(iwlwifi_dev_rx) ||
  90. tracepoint_enabled(iwlwifi_dev_rx_data))
  91. __trace_iwlwifi_dev_rx(trans, pkt, len);
  92. #endif
  93. }
  94. #endif /* __IWLWIFI_DEVICE_TRACE */