14273a380SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2e705c121SKalle Valo /******************************************************************************
3e705c121SKalle Valo  *
4e705c121SKalle Valo  * Copyright(c) 2009 - 2014 Intel Corporation. All rights reserved.
50c4cb731SJohannes Berg  * Copyright(C) 2016        Intel Deutschland GmbH
638bd7e58SMordechay Goodstein  * Copyright(c) 2018        Intel Corporation
7e705c121SKalle Valo  *****************************************************************************/
8e705c121SKalle Valo 
9e705c121SKalle Valo #ifndef __IWLWIFI_DEVICE_TRACE
10e705c121SKalle Valo #include <linux/skbuff.h>
11e705c121SKalle Valo #include <linux/ieee80211.h>
12e705c121SKalle Valo #include <net/cfg80211.h>
13e705c121SKalle Valo #include "iwl-trans.h"
14e705c121SKalle Valo #if !defined(__IWLWIFI_DEVICE_TRACE)
iwl_trace_data(struct sk_buff * skb)15e705c121SKalle Valo static inline bool iwl_trace_data(struct sk_buff *skb)
16e705c121SKalle Valo {
17e705c121SKalle Valo 	struct ieee80211_hdr *hdr = (void *)skb->data;
180c4cb731SJohannes Berg 	__le16 fc = hdr->frame_control;
190c4cb731SJohannes Berg 	int offs = 24; /* start with normal header length */
20e705c121SKalle Valo 
210c4cb731SJohannes Berg 	if (!ieee80211_is_data(fc))
22e705c121SKalle Valo 		return false;
230c4cb731SJohannes Berg 
240c4cb731SJohannes Berg 	/* Try to determine if the frame is EAPOL. This might have false
250c4cb731SJohannes Berg 	 * positives (if there's no RFC 1042 header and we compare to some
260c4cb731SJohannes Berg 	 * payload instead) but since we're only doing tracing that's not
270c4cb731SJohannes Berg 	 * a problem.
280c4cb731SJohannes Berg 	 */
290c4cb731SJohannes Berg 
300c4cb731SJohannes Berg 	if (ieee80211_has_a4(fc))
310c4cb731SJohannes Berg 		offs += 6;
320c4cb731SJohannes Berg 	if (ieee80211_is_data_qos(fc))
330c4cb731SJohannes Berg 		offs += 2;
340c4cb731SJohannes Berg 	/* don't account for crypto - these are unencrypted */
350c4cb731SJohannes Berg 
360c4cb731SJohannes Berg 	/* also account for the RFC 1042 header, of course */
370c4cb731SJohannes Berg 	offs += 6;
380c4cb731SJohannes Berg 
395462bcd8SEmmanuel Grumbach 	return skb->len <= offs + 2 ||
405462bcd8SEmmanuel Grumbach 		*(__be16 *)(skb->data + offs) != cpu_to_be16(ETH_P_PAE);
41e705c121SKalle Valo }
42e705c121SKalle Valo 
iwl_rx_trace_len(const struct iwl_trans * trans,void * rxbuf,size_t len,size_t * out_hdr_offset)43e705c121SKalle Valo static inline size_t iwl_rx_trace_len(const struct iwl_trans *trans,
4438bd7e58SMordechay Goodstein 				      void *rxbuf, size_t len,
4538bd7e58SMordechay Goodstein 				      size_t *out_hdr_offset)
46e705c121SKalle Valo {
47e705c121SKalle Valo 	struct iwl_cmd_header *cmd = (void *)((u8 *)rxbuf + sizeof(__le32));
4838bd7e58SMordechay Goodstein 	struct ieee80211_hdr *hdr = NULL;
4938bd7e58SMordechay Goodstein 	size_t hdr_offset;
50e705c121SKalle Valo 
51e705c121SKalle Valo 	if (cmd->cmd != trans->rx_mpdu_cmd)
52e705c121SKalle Valo 		return len;
53e705c121SKalle Valo 
5438bd7e58SMordechay Goodstein 	hdr_offset = sizeof(struct iwl_cmd_header) +
5538bd7e58SMordechay Goodstein 		     trans->rx_mpdu_cmd_hdr_size;
5638bd7e58SMordechay Goodstein 
5738bd7e58SMordechay Goodstein 	if (out_hdr_offset)
5838bd7e58SMordechay Goodstein 		*out_hdr_offset = hdr_offset;
5938bd7e58SMordechay Goodstein 
6038bd7e58SMordechay Goodstein 	hdr = (void *)((u8 *)cmd + hdr_offset);
61e705c121SKalle Valo 	if (!ieee80211_is_data(hdr->frame_control))
62e705c121SKalle Valo 		return len;
63e705c121SKalle Valo 	/* maybe try to identify EAPOL frames? */
64e705c121SKalle Valo 	return sizeof(__le32) + sizeof(*cmd) + trans->rx_mpdu_cmd_hdr_size +
65e705c121SKalle Valo 		ieee80211_hdrlen(hdr->frame_control);
66e705c121SKalle Valo }
67e705c121SKalle Valo #endif
68e705c121SKalle Valo 
69e705c121SKalle Valo #define __IWLWIFI_DEVICE_TRACE
70e705c121SKalle Valo 
71e705c121SKalle Valo #include <linux/tracepoint.h>
72e705c121SKalle Valo #include <linux/device.h>
73e705c121SKalle Valo 
74e705c121SKalle Valo 
75e705c121SKalle Valo #if !defined(CONFIG_IWLWIFI_DEVICE_TRACING) || defined(__CHECKER__)
76e705c121SKalle Valo #undef TRACE_EVENT
77e705c121SKalle Valo #define TRACE_EVENT(name, proto, ...) \
78e705c121SKalle Valo static inline void trace_ ## name(proto) {}
79e705c121SKalle Valo #undef DECLARE_EVENT_CLASS
80e705c121SKalle Valo #define DECLARE_EVENT_CLASS(...)
81e705c121SKalle Valo #undef DEFINE_EVENT
82e705c121SKalle Valo #define DEFINE_EVENT(evt_class, name, proto, ...) \
83e705c121SKalle Valo static inline void trace_ ## name(proto) {}
84e705c121SKalle Valo #endif
85e705c121SKalle Valo 
86e705c121SKalle Valo #define DEV_ENTRY	__string(dev, dev_name(dev))
87e705c121SKalle Valo #define DEV_ASSIGN	__assign_str(dev, dev_name(dev))
88e705c121SKalle Valo 
89e705c121SKalle Valo #include "iwl-devtrace-io.h"
90e705c121SKalle Valo #include "iwl-devtrace-ucode.h"
91e705c121SKalle Valo #include "iwl-devtrace-msg.h"
92e705c121SKalle Valo #include "iwl-devtrace-data.h"
93e705c121SKalle Valo #include "iwl-devtrace-iwlwifi.h"
94e705c121SKalle Valo 
95e705c121SKalle Valo #endif /* __IWLWIFI_DEVICE_TRACE */
96