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