1 // SPDX-License-Identifier: ISC
2 /*
3  * Copyright (c) 2013 Broadcom Corporation
4  */
5 #if !defined(BRCMF_TRACEPOINT_H_) || defined(TRACE_HEADER_MULTI_READ)
6 #define BRCMF_TRACEPOINT_H_
7 
8 #include <linux/types.h>
9 #include <linux/tracepoint.h>
10 
11 #ifndef CONFIG_BRCM_TRACING
12 
13 #undef TRACE_EVENT
14 #define TRACE_EVENT(name, proto, ...) \
15 static inline void trace_ ## name(proto) {}
16 
17 #undef DECLARE_EVENT_CLASS
18 #define DECLARE_EVENT_CLASS(...)
19 
20 #undef DEFINE_EVENT
21 #define DEFINE_EVENT(evt_class, name, proto, ...) \
22 static inline void trace_ ## name(proto) {}
23 
24 #endif /* CONFIG_BRCM_TRACING */
25 
26 #undef TRACE_SYSTEM
27 #define TRACE_SYSTEM	brcmfmac
28 
29 #define MAX_MSG_LEN		100
30 
31 TRACE_EVENT(brcmf_err,
32 	TP_PROTO(const char *func, struct va_format *vaf),
33 	TP_ARGS(func, vaf),
34 	TP_STRUCT__entry(
35 		__string(func, func)
36 		__vstring(msg, vaf->fmt, vaf->va)
37 	),
38 	TP_fast_assign(
39 		__assign_str(func, func);
40 		__assign_vstr(msg, vaf->fmt, vaf->va);
41 	),
42 	TP_printk("%s: %s", __get_str(func), __get_str(msg))
43 );
44 
45 TRACE_EVENT(brcmf_dbg,
46 	TP_PROTO(u32 level, const char *func, struct va_format *vaf),
47 	TP_ARGS(level, func, vaf),
48 	TP_STRUCT__entry(
49 		__field(u32, level)
50 		__string(func, func)
51 		__vstring(msg, vaf->fmt, vaf->va)
52 	),
53 	TP_fast_assign(
54 		__entry->level = level;
55 		__assign_str(func, func);
56 		__assign_vstr(msg, vaf->fmt, vaf->va);
57 	),
58 	TP_printk("%s: %s", __get_str(func), __get_str(msg))
59 );
60 
61 TRACE_EVENT(brcmf_hexdump,
62 	TP_PROTO(void *data, size_t len),
63 	TP_ARGS(data, len),
64 	TP_STRUCT__entry(
65 		__field(unsigned long, len)
66 		__field(unsigned long, addr)
67 		__dynamic_array(u8, hdata, len)
68 	),
69 	TP_fast_assign(
70 		__entry->len = len;
71 		__entry->addr = (unsigned long)data;
72 		memcpy(__get_dynamic_array(hdata), data, len);
73 	),
74 	TP_printk("hexdump [addr=%lx, length=%lu]", __entry->addr, __entry->len)
75 );
76 
77 TRACE_EVENT(brcmf_bcdchdr,
78 	TP_PROTO(void *data),
79 	TP_ARGS(data),
80 	TP_STRUCT__entry(
81 		__field(u8, flags)
82 		__field(u8, prio)
83 		__field(u8, flags2)
84 		__field(u32, siglen)
85 		__dynamic_array(u8, signal, *((u8 *)data + 3) * 4)
86 	),
87 	TP_fast_assign(
88 		__entry->flags = *(u8 *)data;
89 		__entry->prio = *((u8 *)data + 1);
90 		__entry->flags2 = *((u8 *)data + 2);
91 		__entry->siglen = *((u8 *)data + 3) * 4;
92 		memcpy(__get_dynamic_array(signal),
93 		       (u8 *)data + 4, __entry->siglen);
94 	),
95 	TP_printk("bcdc: prio=%d siglen=%d", __entry->prio, __entry->siglen)
96 );
97 
98 #ifndef SDPCM_RX
99 #define SDPCM_RX	0
100 #endif
101 #ifndef SDPCM_TX
102 #define SDPCM_TX	1
103 #endif
104 #ifndef SDPCM_GLOM
105 #define SDPCM_GLOM	2
106 #endif
107 
108 TRACE_EVENT(brcmf_sdpcm_hdr,
109 	TP_PROTO(u8 dir, void *data),
110 	TP_ARGS(dir, data),
111 	TP_STRUCT__entry(
112 		__field(u8, dir)
113 		__field(u16, len)
114 		__dynamic_array(u8, hdr, dir == SDPCM_GLOM ? 20 : 12)
115 	),
116 	TP_fast_assign(
117 		memcpy(__get_dynamic_array(hdr), data, dir == SDPCM_GLOM ? 20 : 12);
118 		__entry->len = *(u8 *)data | (*((u8 *)data + 1) << 8);
119 		__entry->dir = dir;
120 	),
121 	TP_printk("sdpcm: %s len %u, seq %d",
122 		  __entry->dir == SDPCM_RX ? "RX" : "TX",
123 		  __entry->len, ((u8 *)__get_dynamic_array(hdr))[4])
124 );
125 
126 #ifdef CONFIG_BRCM_TRACING
127 
128 #undef TRACE_INCLUDE_PATH
129 #define TRACE_INCLUDE_PATH .
130 #undef TRACE_INCLUDE_FILE
131 #define TRACE_INCLUDE_FILE tracepoint
132 
133 #include <trace/define_trace.h>
134 
135 #endif /* CONFIG_BRCM_TRACING */
136 
137 #endif /* BRCMF_TRACEPOINT_H_ */
138