xref: /illumos-gate/usr/src/uts/common/io/bnx/debug.h (revision eef4f27b)
1 /*
2  * Copyright 2014-2017 Cavium, Inc.
3  * The contents of this file are subject to the terms of the Common Development
4  * and Distribution License, v.1,  (the "License").
5  *
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the License at available
9  * at http://opensource.org/licenses/CDDL-1.0
10  *
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  */
14 
15 /*
16  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
17  */
18 
19 #ifndef _DEBUG_H
20 #define	_DEBUG_H
21 
22 
23 
24 /*
25  * Debug break and output routines.
26  */
27 
28 void
29 debug_break(void *ctx);
30 
31 void debug_msg(void *ctx, unsigned long level, char *file, unsigned long line,
32     char *msg, ...);
33 
34 void debug_msgx(void *ctx, unsigned long level, char *msg, ...);
35 
36 
37 
38 /*
39  * Debug macros
40  */
41 
42 /* Code paths. */
43 #define	CP_INIT			0x010000    /* Initialization */
44 #define	CP_SEND			0x020000    /* Transmit */
45 #define	CP_RCV			0x040000    /* Recieve */
46 #define	CP_INT			0x080000    /* Interrupt */
47 #define	CP_UINIT		0x100000    /* Unload */
48 #define	CP_RESET		0x200000    /* Reset */
49 #define	CP_GEN_BUF		0x400000    /* Generic buffer. */
50 #define	CP_ALL			0xffff0000  /* All code path */
51 
52 #define	CP_MASK			0xffff0000
53 
54 
55 /* Mess	ge levels. */
56 #define	LV_VERBOSE		0x03
57 #define	LV_INFORM		0x02
58 #define	LV_WARN			0x01
59 #define	LV_FATAL		0x00
60 
61 #define	LV_MASK			0xffff
62 
63 
64 /*
65  * Code path and messsage level combined.  These are the first argument
66  * of the DbgMessage macro.
67  */
68 
69 #define	VERBOSEi		(CP_INIT | LV_VERBOSE)
70 #define	INFORMi			(CP_INIT | LV_INFORM)
71 #define	WARNi			(CP_INIT | LV_WARN)
72 
73 #define	VERBOSEtx		(CP_SEND | LV_VERBOSE)
74 #define	INFORMtx		(CP_SEND | LV_INFORM)
75 #define	WARNtx			(CP_SEND | LV_WARN)
76 
77 #define	VERBOSErx		(CP_RCV | LV_VERBOSE)
78 #define	INFORMrx		(CP_RCV | LV_INFORM)
79 #define	WARNrx			(CP_RCV | LV_WARN)
80 
81 #define	VERBOSEint		(CP_INT | LV_VERBOSE)
82 #define	INFORMint		(CP_INT | LV_INFORM)
83 #define	WARNint			(CP_INT | LV_WARN)
84 
85 #define	VERBOSEu		(CP_UINIT | LV_VERBOSE)
86 #define	INFORMu			(CP_UINIT | LV_INFORM)
87 #define	WARNu			(CP_UINIT | LV_WARN)
88 
89 #define	VERBOSErs		(CP_RESET | LV_VERBOSE)
90 #define	INFORMrs		(CP_RESET | LV_INFORM)
91 #define	WARNrs			(CP_RESET | LV_WARN)
92 
93 #define	VERBOSEgb		(CP_GEN_BUF | LV_VERBOSE)
94 #define	INFORMgb		(CP_GEN_BUF | LV_INFORM)
95 #define	WARNgb			(CP_GEN_BUF | LV_WARN)
96 
97 
98 #define	FATAL			(CP_ALL | LV_FATAL)
99 #define	WARN			(CP_ALL | LV_WARN)
100 #define	INFORM			(CP_ALL | LV_INFORM)
101 #define	VERBOSE			(CP_ALL | LV_VERBOSE)
102 
103 
104 #if DBG
105 
106 /*
107  * These constants control the output of messages.
108  * Set your debug message output level and code path here.
109  */
110 #ifndef	DBG_MSG_CP
111 #define	DBG_MSG_CP		CP_ALL	/* Where to output messages. */
112 #endif
113 
114 #ifndef	DBG_MSG_LV
115 #define	DBG_MSG_LV		LV_VERBOSE	/* Level of message output. */
116 #endif
117 
118 
119 /* CSTYLED */
120 #define	STATIC
121 #define	DbgBreak(_c)		debug_break(_c)
122 
123 
124 #define	CODE_PATH(_m)		((_m) & DBG_MSG_CP)
125 #define	MSG_LEVEL(_m)		((_m) & LV_MASK)
126 #define	LOG_MSG(_m)		(CODE_PATH(_m) && \
127 				    MSG_LEVEL(_m) <= DBG_MSG_LV)
128 
129 
130 /* BEGIN CSTYLED */
131 #define	DbgMessage(_c, _m, _s)                                              \
132     if (LOG_MSG(_m))                                                        \
133     {                                                                       \
134         debug_msg(_c, _m, __FILE__, __LINE__, _s);                          \
135     }
136 #define	DbgMessage1(_c, _m, _s, _d1)                                        \
137     if (LOG_MSG(_m))                                                        \
138     {                                                                       \
139         debug_msg(_c, _m, __FILE__, __LINE__, _s, _d1);                     \
140     }
141 #define	DbgMessage2(_c, _m, _s, _d1, _d2)                                   \
142     if (LOG_MSG(_m))                                                        \
143     {                                                                       \
144         debug_msg(_c, _m, __FILE__, __LINE__, _s, _d1, _d2);                \
145     }
146 #define	DbgMessage3(_c, _m, _s, _d1, _d2, _d3)                              \
147     if (LOG_MSG(_m))                                                        \
148     {                                                                       \
149         debug_msg(_c, _m, __FILE__, __LINE__, _s, _d1, _d2, _d3);           \
150     }
151 #define	DbgMessage4(_c, _m, _s, _d1, _d2, _d3, _d4)                         \
152     if (LOG_MSG(_m))                                                        \
153     {                                                                       \
154         debug_msg(_c, _m, __FILE__, __LINE__, _s, _d1, _d2, _d3, _d4);      \
155     }
156 #define	DbgMessage5(_c, _m, _s, _d1, _d2, _d3, _d4, _d5)                    \
157     if (LOG_MSG(_m))                                                        \
158     {                                                                       \
159         debug_msg(_c, _m, __FILE__, __LINE__, _s, _d1, _d2, _d3, _d4, _d5); \
160     }
161 #define	DbgMessage6(_c, _m, _s, _d1, _d2, _d3, _d4, _d5, _d6)               \
162     if (LOG_MSG(_m))                                                        \
163     {                                                                       \
164         debug_msg(_c, _m, __FILE__, __LINE__, _s, _d1,_d2,_d3,_d4,_d5,_d6); \
165     }
166 
167 #define	DbgMessageX(_c, _m, _s)                                             \
168     if (LOG_MSG(_m))                                                        \
169     {                                                                       \
170         debug_msgx(_c, _m, _s);                                             \
171     }
172 #define	DbgMessageX1(_c, _m, _s, _d1)                                       \
173     if (LOG_MSG(_m))                                                        \
174     {                                                                       \
175         debug_msgx(_c, _m, _s, _d1);                                        \
176     }
177 #define	DbgMessageX2(_c, _m, _s, _d1, _d2)                                  \
178     if (LOG_MSG(_m))                                                        \
179     {                                                                       \
180         debug_msgx(_c, _m, _s, _d1, _d2);                                   \
181     }
182 #define	DbgMessageX3(_c, _m, _s, _d1, _d2, _d3)                             \
183     if (LOG_MSG(_m))                                                        \
184     {                                                                       \
185         debug_msgx(_c, _m, _s, _d1, _d2, _d3);                              \
186     }
187 #define	DbgMessageX4(_c, _m, _s, _d1, _d2, _d3, _d4)                        \
188     if (LOG_MSG(_m))                                                        \
189     {                                                                       \
190         debug_msgx(_c, _m, _s, _d1, _d2, _d3, _d4);                         \
191     }
192 #define	DbgMessageX5(_c, _m, _s, _d1, _d2, _d3, _d4, _d5)                   \
193     if (LOG_MSG(_m))                                                        \
194     {                                                                       \
195         debug_msgx(_c, _m, _s, _d1, _d2, _d3, _d4, _d5);                    \
196     }
197 #define	DbgMessageX6(_c, _m, _s, _d1, _d2, _d3, _d4, _d5, _d6)              \
198     if (LOG_MSG(_m))                                                        \
199     {                                                                       \
200         debug_msgx(_c, _m, _s, _d1,_d2,_d3,_d4,_d5,_d6);                    \
201     }
202 
203 #define	DbgBreakIf(_c)							\
204     if (_c)								\
205     {									\
206         debug_msg(NULL, FATAL, __FILE__, __LINE__, "if("#_c##")\n");	\
207         debug_break(NULL);						\
208     }
209 
210 #define	DbgBreakMsg(_m)	debug_msg(NULL, FATAL, __FILE__, __LINE__, _m); \
211     debug_break(NULL)
212 /* END CSTYLED */
213 
214 
215 #else
216 
217 /* CSTYLED */
218 #define	STATIC static
219 
220 #define	DbgBreak(_c)
221 
222 #define	DbgMessage(_c, _m, _s)
223 #define	DbgMessage1(_c, _m, _s, _d1)
224 #define	DbgMessage2(_c, _m, _s, _d1, _d2)
225 #define	DbgMessage3(_c, _m, _s, _d1, _d2, _d3)
226 #define	DbgMessage4(_c, _m, _s, _d1, _d2, _d3, _d4)
227 #define	DbgMessage5(_c, _m, _s, _d1, _d2, _d3, _d4, _d5)
228 #define	DbgMessage6(_c, _m, _s, _d1, _d2, _d3, _d4, _d5, _d6)
229 
230 #define	DbgMessageX(_c, _m, _s)
231 #define	DbgMessageX1(_c, _m, _s, _d1)
232 #define	DbgMessageX2(_c, _m, _s, _d1, _d2)
233 #define	DbgMessageX3(_c, _m, _s, _d1, _d2, _d3)
234 #define	DbgMessageX4(_c, _m, _s, _d1, _d2, _d3, _d4)
235 #define	DbgMessageX5(_c, _m, _s, _d1, _d2, _d3, _d4, _d5)
236 #define	DbgMessageX6(_c, _m, _s, _d1, _d2, _d3, _d4, _d5, _d6)
237 
238 #define	DbgBreakIf(_c)
239 #define	DbgBreakMsg(_m)
240 
241 #endif
242 
243 #endif /* _DEBUG_H */
244