1 /*
2 * Copyright(c) 2015, 2016 Intel Corporation.
3 *
4 * This file is provided under a dual BSD/GPLv2 license.  When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 *  - Redistributions of source code must retain the above copyright
25 *    notice, this list of conditions and the following disclaimer.
26 *  - Redistributions in binary form must reproduce the above copyright
27 *    notice, this list of conditions and the following disclaimer in
28 *    the documentation and/or other materials provided with the
29 *    distribution.
30 *  - Neither the name of Intel Corporation nor the names of its
31 *    contributors may be used to endorse or promote products derived
32 *    from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47 #if !defined(__HFI1_TRACE_EXTRA_H) || defined(TRACE_HEADER_MULTI_READ)
48 #define __HFI1_TRACE_EXTRA_H
49 
50 #include <linux/tracepoint.h>
51 #include <linux/trace_seq.h>
52 
53 #include "hfi.h"
54 
55 /*
56  * Note:
57  * This produces a REALLY ugly trace in the console output when the string is
58  * too long.
59  */
60 
61 #undef TRACE_SYSTEM
62 #define TRACE_SYSTEM hfi1_dbg
63 
64 #define MAX_MSG_LEN 512
65 
66 DECLARE_EVENT_CLASS(hfi1_trace_template,
67 		    TP_PROTO(const char *function, struct va_format *vaf),
68 		    TP_ARGS(function, vaf),
69 		    TP_STRUCT__entry(__string(function, function)
70 				     __dynamic_array(char, msg, MAX_MSG_LEN)
71 				     ),
72 		    TP_fast_assign(__assign_str(function, function);
73 				   WARN_ON_ONCE(vsnprintf
74 						(__get_dynamic_array(msg),
75 						 MAX_MSG_LEN, vaf->fmt,
76 						 *vaf->va) >=
77 						MAX_MSG_LEN);
78 				   ),
79 		    TP_printk("(%s) %s",
80 			      __get_str(function),
81 			      __get_str(msg))
82 );
83 
84 /*
85  * It may be nice to macroize the __hfi1_trace but the va_* stuff requires an
86  * actual function to work and can not be in a macro.
87  */
88 #define __hfi1_trace_def(lvl) \
89 void __hfi1_trace_##lvl(const char *funct, char *fmt, ...);		\
90 									\
91 DEFINE_EVENT(hfi1_trace_template, hfi1_ ##lvl,				\
92 	TP_PROTO(const char *function, struct va_format *vaf),		\
93 	TP_ARGS(function, vaf))
94 
95 #define __hfi1_trace_fn(lvl) \
96 void __hfi1_trace_##lvl(const char *func, char *fmt, ...)		\
97 {									\
98 	struct va_format vaf = {					\
99 		.fmt = fmt,						\
100 	};								\
101 	va_list args;							\
102 									\
103 	va_start(args, fmt);						\
104 	vaf.va = &args;							\
105 	trace_hfi1_ ##lvl(func, &vaf);					\
106 	va_end(args);							\
107 	return;								\
108 }
109 
110 /*
111  * To create a new trace level simply define it below and as a __hfi1_trace_fn
112  * in trace.c. This will create all the hooks for calling
113  * hfi1_cdbg(LVL, fmt, ...); as well as take care of all
114  * the debugfs stuff.
115  */
116 __hfi1_trace_def(PKT);
117 __hfi1_trace_def(PROC);
118 __hfi1_trace_def(SDMA);
119 __hfi1_trace_def(LINKVERB);
120 __hfi1_trace_def(DEBUG);
121 __hfi1_trace_def(SNOOP);
122 __hfi1_trace_def(CNTR);
123 __hfi1_trace_def(PIO);
124 __hfi1_trace_def(DC8051);
125 __hfi1_trace_def(FIRMWARE);
126 __hfi1_trace_def(RCVCTRL);
127 __hfi1_trace_def(TID);
128 __hfi1_trace_def(MMU);
129 __hfi1_trace_def(IOCTL);
130 
131 #define hfi1_cdbg(which, fmt, ...) \
132 	__hfi1_trace_##which(__func__, fmt, ##__VA_ARGS__)
133 
134 #define hfi1_dbg(fmt, ...) \
135 	hfi1_cdbg(DEBUG, fmt, ##__VA_ARGS__)
136 
137 /*
138  * Define HFI1_EARLY_DBG at compile time or here to enable early trace
139  * messages. Do not check in an enablement for this.
140  */
141 
142 #ifdef HFI1_EARLY_DBG
143 #define hfi1_dbg_early(fmt, ...) \
144 	trace_printk(fmt, ##__VA_ARGS__)
145 #else
146 #define hfi1_dbg_early(fmt, ...)
147 #endif
148 
149 #endif /* __HFI1_TRACE_EXTRA_H */
150 
151 #undef TRACE_INCLUDE_PATH
152 #undef TRACE_INCLUDE_FILE
153 #define TRACE_INCLUDE_PATH .
154 #define TRACE_INCLUDE_FILE trace_dbg
155 #include <trace/define_trace.h>
156