xref: /linux/drivers/infiniband/hw/hfi1/trace_dbg.h (revision 9f2c9170934eace462499ba0bfe042cc72900173)
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 				     __vstring(msg, vaf->fmt, vaf->va)
30 				     ),
31 		    TP_fast_assign(__assign_str(function, function);
32 				   __assign_vstr(msg, vaf->fmt, vaf->va);
33 				   ),
34 		    TP_printk("(%s) %s",
35 			      __get_str(function),
36 			      __get_str(msg))
37 );
38 
39 /*
40  * It may be nice to macroize the __hfi1_trace but the va_* stuff requires an
41  * actual function to work and can not be in a macro.
42  */
43 #define __hfi1_trace_def(lvl) \
44 void __printf(2, 3) __hfi1_trace_##lvl(const char *funct, char *fmt, ...); \
45 									\
46 DEFINE_EVENT(hfi1_trace_template, hfi1_ ##lvl,				\
47 	TP_PROTO(const char *function, struct va_format *vaf),		\
48 	TP_ARGS(function, vaf))
49 
50 #define __hfi1_trace_fn(lvl) \
51 void __printf(2, 3) __hfi1_trace_##lvl(const char *func, char *fmt, ...)\
52 {									\
53 	struct va_format vaf = {					\
54 		.fmt = fmt,						\
55 	};								\
56 	va_list args;							\
57 									\
58 	va_start(args, fmt);						\
59 	vaf.va = &args;							\
60 	trace_hfi1_ ##lvl(func, &vaf);					\
61 	va_end(args);							\
62 	return;								\
63 }
64 
65 /*
66  * To create a new trace level simply define it below and as a __hfi1_trace_fn
67  * in trace.c. This will create all the hooks for calling
68  * hfi1_cdbg(LVL, fmt, ...); as well as take care of all
69  * the debugfs stuff.
70  */
71 __hfi1_trace_def(AFFINITY);
72 __hfi1_trace_def(PKT);
73 __hfi1_trace_def(PROC);
74 __hfi1_trace_def(SDMA);
75 __hfi1_trace_def(LINKVERB);
76 __hfi1_trace_def(DEBUG);
77 __hfi1_trace_def(SNOOP);
78 __hfi1_trace_def(CNTR);
79 __hfi1_trace_def(PIO);
80 __hfi1_trace_def(DC8051);
81 __hfi1_trace_def(FIRMWARE);
82 __hfi1_trace_def(RCVCTRL);
83 __hfi1_trace_def(TID);
84 __hfi1_trace_def(MMU);
85 __hfi1_trace_def(IOCTL);
86 
87 #define hfi1_cdbg(which, fmt, ...) \
88 	__hfi1_trace_##which(__func__, fmt, ##__VA_ARGS__)
89 
90 #define hfi1_dbg(fmt, ...) \
91 	hfi1_cdbg(DEBUG, fmt, ##__VA_ARGS__)
92 
93 /*
94  * Define HFI1_EARLY_DBG at compile time or here to enable early trace
95  * messages. Do not check in an enablement for this.
96  */
97 
98 #ifdef HFI1_EARLY_DBG
99 #define hfi1_dbg_early(fmt, ...) \
100 	trace_printk(fmt, ##__VA_ARGS__)
101 #else
102 #define hfi1_dbg_early(fmt, ...)
103 #endif
104 
105 #endif /* __HFI1_TRACE_EXTRA_H */
106 
107 #undef TRACE_INCLUDE_PATH
108 #undef TRACE_INCLUDE_FILE
109 #define TRACE_INCLUDE_PATH .
110 #define TRACE_INCLUDE_FILE trace_dbg
111 #include <trace/define_trace.h>
112