xref: /linux/drivers/infiniband/hw/hfi1/trace_dbg.h (revision a4eb44a6435d6d8f9e642407a4a06f65eb90ca04)
1 /* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */
2 /*
3 * Copyright(c) 2015 - 2018 Intel Corporation.
4 */
5 
6 #if !defined(__HFI1_TRACE_EXTRA_H) || defined(TRACE_HEADER_MULTI_READ)
7 #define __HFI1_TRACE_EXTRA_H
8 
9 #include <linux/tracepoint.h>
10 #include <linux/trace_seq.h>
11 
12 #include "hfi.h"
13 
14 /*
15  * Note:
16  * This produces a REALLY ugly trace in the console output when the string is
17  * too long.
18  */
19 
20 #undef TRACE_SYSTEM
21 #define TRACE_SYSTEM hfi1_dbg
22 
23 #define MAX_MSG_LEN 512
24 
25 DECLARE_EVENT_CLASS(hfi1_trace_template,
26 		    TP_PROTO(const char *function, struct va_format *vaf),
27 		    TP_ARGS(function, vaf),
28 		    TP_STRUCT__entry(__string(function, function)
29 				     __dynamic_array(char, msg, MAX_MSG_LEN)
30 				     ),
31 		    TP_fast_assign(__assign_str(function, function);
32 				   WARN_ON_ONCE(vsnprintf
33 						(__get_dynamic_array(msg),
34 						 MAX_MSG_LEN, vaf->fmt,
35 						 *vaf->va) >=
36 						MAX_MSG_LEN);
37 				   ),
38 		    TP_printk("(%s) %s",
39 			      __get_str(function),
40 			      __get_str(msg))
41 );
42 
43 /*
44  * It may be nice to macroize the __hfi1_trace but the va_* stuff requires an
45  * actual function to work and can not be in a macro.
46  */
47 #define __hfi1_trace_def(lvl) \
48 void __printf(2, 3) __hfi1_trace_##lvl(const char *funct, char *fmt, ...); \
49 									\
50 DEFINE_EVENT(hfi1_trace_template, hfi1_ ##lvl,				\
51 	TP_PROTO(const char *function, struct va_format *vaf),		\
52 	TP_ARGS(function, vaf))
53 
54 #define __hfi1_trace_fn(lvl) \
55 void __printf(2, 3) __hfi1_trace_##lvl(const char *func, char *fmt, ...)\
56 {									\
57 	struct va_format vaf = {					\
58 		.fmt = fmt,						\
59 	};								\
60 	va_list args;							\
61 									\
62 	va_start(args, fmt);						\
63 	vaf.va = &args;							\
64 	trace_hfi1_ ##lvl(func, &vaf);					\
65 	va_end(args);							\
66 	return;								\
67 }
68 
69 /*
70  * To create a new trace level simply define it below and as a __hfi1_trace_fn
71  * in trace.c. This will create all the hooks for calling
72  * hfi1_cdbg(LVL, fmt, ...); as well as take care of all
73  * the debugfs stuff.
74  */
75 __hfi1_trace_def(AFFINITY);
76 __hfi1_trace_def(PKT);
77 __hfi1_trace_def(PROC);
78 __hfi1_trace_def(SDMA);
79 __hfi1_trace_def(LINKVERB);
80 __hfi1_trace_def(DEBUG);
81 __hfi1_trace_def(SNOOP);
82 __hfi1_trace_def(CNTR);
83 __hfi1_trace_def(PIO);
84 __hfi1_trace_def(DC8051);
85 __hfi1_trace_def(FIRMWARE);
86 __hfi1_trace_def(RCVCTRL);
87 __hfi1_trace_def(TID);
88 __hfi1_trace_def(MMU);
89 __hfi1_trace_def(IOCTL);
90 
91 #define hfi1_cdbg(which, fmt, ...) \
92 	__hfi1_trace_##which(__func__, fmt, ##__VA_ARGS__)
93 
94 #define hfi1_dbg(fmt, ...) \
95 	hfi1_cdbg(DEBUG, fmt, ##__VA_ARGS__)
96 
97 /*
98  * Define HFI1_EARLY_DBG at compile time or here to enable early trace
99  * messages. Do not check in an enablement for this.
100  */
101 
102 #ifdef HFI1_EARLY_DBG
103 #define hfi1_dbg_early(fmt, ...) \
104 	trace_printk(fmt, ##__VA_ARGS__)
105 #else
106 #define hfi1_dbg_early(fmt, ...)
107 #endif
108 
109 #endif /* __HFI1_TRACE_EXTRA_H */
110 
111 #undef TRACE_INCLUDE_PATH
112 #undef TRACE_INCLUDE_FILE
113 #define TRACE_INCLUDE_PATH .
114 #define TRACE_INCLUDE_FILE trace_dbg
115 #include <trace/define_trace.h>
116