xref: /illumos-gate/usr/src/uts/common/io/xge/hal/include/xge-debug.h (revision 76716eaced8d7659d4594350eb3f343c31fe2806)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  *  Copyright (c) 2002-2005 Neterion, Inc.
24  *  All right Reserved.
25  *
26  *  FileName :    xge-debug.h
27  *
28  *  Description:  debug facilities
29  *
30  *  Created:      6 May 2004
31  */
32 
33 #ifndef XGE_DEBUG_H
34 #define XGE_DEBUG_H
35 
36 #include "xge-os-pal.h"
37 
38 /* to make some gcc versions happier */
39 #ifndef __func__
40 #define __func__ __FUNCTION__
41 #endif
42 
43 #ifdef XGE_DEBUG_FP
44 #define XGE_DEBUG_FP_DEVICE	0x1
45 #define XGE_DEBUG_FP_CHANNEL	0x2
46 #define XGE_DEBUG_FP_FIFO	0x4
47 #define XGE_DEBUG_FP_RING	0x8
48 #endif
49 
50 /**
51  * enum xge_debug_level_e
52  * @XGE_NONE: debug disabled
53  * @XGE_ERR: all errors going to be logged out
54  * @XGE_TRACE: all errors plus all kind of verbose tracing print outs
55  *                 going to be logged out. Very noisy.
56  *
57  * This enumeration going to be used to switch between different
58  * debug levels during runtime if DEBUG macro defined during
59  * compilation. If DEBUG macro not defined than code will be
60  * compiled out.
61  */
62 typedef enum xge_debug_level_e {
63 	XGE_NONE   = 0,
64 	XGE_TRACE  = 1,
65 	XGE_ERR    = 2,
66 } xge_debug_level_e;
67 
68 #define XGE_DEBUG_MODULE_MASK_DEF	0x00003030
69 #define XGE_DEBUG_LEVEL_DEF		XGE_ERR
70 
71 #if defined(XGE_DEBUG_TRACE_MASK) || defined(XGE_DEBUG_ERR_MASK)
72 
73 extern unsigned int *g_module_mask;
74 extern int *g_level;
75 
76 #ifndef XGE_DEBUG_TRACE_MASK
77 #define XGE_DEBUG_TRACE_MASK 0
78 #endif
79 
80 #ifndef XGE_DEBUG_ERR_MASK
81 #define XGE_DEBUG_ERR_MASK 0
82 #endif
83 
84 /*
85  * @XGE_COMPONENT_HAL_CONFIG: do debug for xge core config module
86  * @XGE_COMPONENT_HAL_FIFO: do debug for xge core fifo module
87  * @XGE_COMPONENT_HAL_RING: do debug for xge core ring module
88  * @XGE_COMPONENT_HAL_CHANNEL: do debug for xge core channel module
89  * @XGE_COMPONENT_HAL_DEVICE: do debug for xge core device module
90  * @XGE_COMPONENT_CORE: do debug for xge KMA core module
91  * @XGE_COMPONENT_OSDEP: do debug for xge KMA os dependent parts
92  * @XGE_COMPONENT_LL: do debug for xge link layer module
93  * @XGE_COMPONENT_ALL: activate debug for all modules with no exceptions
94  *
95  * This enumeration going to be used to distinguish modules
96  * or libraries during compilation and runtime.  Makefile must declare
97  * XGE_DEBUG_MODULE_MASK macro and set it to proper value.
98  */
99 #define XGE_COMPONENT_HAL_CONFIG		0x1
100 #define	XGE_COMPONENT_HAL_FIFO			0x2
101 #define	XGE_COMPONENT_HAL_RING			0x4
102 #define	XGE_COMPONENT_HAL_CHANNEL		0x8
103 #define	XGE_COMPONENT_HAL_DEVICE		0x10
104 #define	XGE_COMPONENT_HAL_MM			0x20
105 #define	XGE_COMPONENT_HAL_QUEUE		        0x40
106 #define	XGE_COMPONENT_HAL_STATS		        0x100
107 	/* space for CORE_XXX */
108 #define	XGE_COMPONENT_OSDEP			0x1000
109 #define	XGE_COMPONENT_LL			0x2000
110 #define	XGE_COMPONENT_ALL			0xffffffff
111 
112 #ifndef XGE_DEBUG_MODULE_MASK
113 #error "XGE_DEBUG_MODULE_MASK macro must be defined for DEBUG mode..."
114 #endif
115 
116 #ifndef __GNUC__
117 #ifdef XGE_TRACE_INTO_CIRCULAR_ARR
118         #define xge_trace_aux(fmt) xge_os_vatrace(g_xge_os_tracebuf, fmt)
119 #else
120         #define xge_trace_aux(fmt) xge_os_vaprintf(fmt)
121 #endif
122 
123 /**
124  * xge_debug
125  * @level: level of debug verbosity.
126  * @fmt: printf like format string
127  *
128  * Provides logging facilities. Can be customized on per-module
129  * basis or/and with debug levels. Input parameters, except
130  * module and level, are the same as posix printf. This function
131  * may be compiled out if DEBUG macro was never defined.
132  * See also: xge_debug_level_e{}.
133  */
134 #define xge_debug(module, level, fmt) { \
135 if (((level >= XGE_TRACE && ((module & XGE_DEBUG_TRACE_MASK) == module)) || \
136     (level >= XGE_ERR && ((module & XGE_DEBUG_ERR_MASK) == module))) && \
137     level >= *g_level && module & *g_module_mask) { \
138                 xge_trace_aux(fmt); \
139 	} \
140 }
141 #else /* __GNUC__ */
142 
143 #ifdef XGE_TRACE_INTO_CIRCULAR_ARR
144         #define xge_trace_aux(fmt...) xge_os_trace(g_xge_os_tracebuf, fmt)
145 #else
146         #define xge_trace_aux(fmt...) xge_os_printf(fmt)
147 #endif
148 
149 #define xge_debug(module, level, fmt...) { \
150 if (((level >= XGE_TRACE && ((module & XGE_DEBUG_TRACE_MASK) == module)) || \
151     (level >= XGE_ERR && ((module & XGE_DEBUG_ERR_MASK) == module))) && \
152     level >= *g_level && module & *g_module_mask) { \
153                 xge_trace_aux(fmt); \
154 	} \
155 }
156 #endif /* __GNUC__ */
157 
158 #if (XGE_COMPONENT_HAL_STATS & XGE_DEBUG_MODULE_MASK)
159 #ifndef __GNUC__
160 static inline void xge_debug_stats(xge_debug_level_e level, char *fmt, ...) {
161 	u32 module = XGE_COMPONENT_HAL_STATS;
162 	xge_debug(module, level, fmt);
163 }
164 #else /* __GNUC__ */
165 #define xge_debug_stats(level, fmt...) \
166 	xge_debug(XGE_COMPONENT_HAL_STATS, level, fmt)
167 #endif /* __GNUC__ */
168 #else
169 #ifndef __GNUC__
170 static inline void xge_debug_stats(xge_debug_level_e level, char *fmt, ...) {}
171 #else /* __GNUC__ */
172 #define xge_debug_stats(level, fmt...)
173 #endif /* __GNUC__ */
174 #endif
175 
176 #if (XGE_COMPONENT_HAL_QUEUE & XGE_DEBUG_MODULE_MASK)
177 #ifndef __GNUC__
178 static inline void xge_debug_queue(xge_debug_level_e level, char *fmt, ...) {
179 	u32 module = XGE_COMPONENT_HAL_QUEUE;
180 	xge_debug(module, level, fmt);
181 }
182 #else /* __GNUC__ */
183 #define xge_debug_queue(level, fmt...) \
184 	xge_debug(XGE_COMPONENT_HAL_QUEUE, level, fmt)
185 #endif /* __GNUC__ */
186 #else
187 #ifndef __GNUC__
188 static inline void xge_debug_queue(xge_debug_level_e level, char *fmt,
189 ...) {}
190 #else /* __GNUC__ */
191 #define xge_debug_queue(level, fmt...)
192 #endif /* __GNUC__ */
193 #endif
194 
195 #if (XGE_COMPONENT_HAL_MM & XGE_DEBUG_MODULE_MASK)
196 #ifndef __GNUC__
197 static inline void xge_debug_mm(xge_debug_level_e level, char *fmt, ...)
198 {
199 	u32 module = XGE_COMPONENT_HAL_MM;
200 	xge_debug(module, level, fmt);
201 }
202 #else /* __GNUC__ */
203 #define xge_debug_mm(level, fmt...) \
204 	xge_debug(XGE_COMPONENT_HAL_MM, level, fmt)
205 #endif /* __GNUC__ */
206 #else
207 #ifndef __GNUC__
208 static inline void xge_debug_mm(xge_debug_level_e level, char *fmt, ...)
209 {}
210 #else /* __GNUC__ */
211 #define xge_debug_mm(level, fmt...)
212 #endif /* __GNUC__ */
213 #endif
214 
215 #if (XGE_COMPONENT_HAL_CONFIG & XGE_DEBUG_MODULE_MASK)
216 #ifndef __GNUC__
217 static inline void xge_debug_config(xge_debug_level_e level, char *fmt, ...) {
218 	u32 module = XGE_COMPONENT_HAL_CONFIG;
219 	xge_debug(module, level, fmt);
220 }
221 #else /* __GNUC__ */
222 #define xge_debug_config(level, fmt...) \
223 	xge_debug(XGE_COMPONENT_HAL_CONFIG, level, fmt)
224 #endif /* __GNUC__ */
225 #else
226 #ifndef __GNUC__
227 static inline void xge_debug_config(xge_debug_level_e level, char *fmt,
228 ...) {}
229 #else /* __GNUC__ */
230 #define xge_debug_config(level, fmt...)
231 #endif /* __GNUC__ */
232 #endif
233 
234 #if (XGE_COMPONENT_HAL_FIFO & XGE_DEBUG_MODULE_MASK)
235 #ifndef __GNUC__
236 static inline void xge_debug_fifo(xge_debug_level_e level, char *fmt, ...) {
237 	u32 module = XGE_COMPONENT_HAL_FIFO;
238 	xge_debug(module, level, fmt);
239 }
240 #else /* __GNUC__ */
241 #define xge_debug_fifo(level, fmt...) \
242 	xge_debug(XGE_COMPONENT_HAL_FIFO, level, fmt)
243 #endif /* __GNUC__ */
244 #else
245 #ifndef __GNUC__
246 static inline void xge_debug_fifo(xge_debug_level_e level, char *fmt, ...) {}
247 #else /* __GNUC__ */
248 #define xge_debug_fifo(level, fmt...)
249 #endif /* __GNUC__ */
250 #endif
251 
252 #if (XGE_COMPONENT_HAL_RING & XGE_DEBUG_MODULE_MASK)
253 #ifndef __GNUC__
254 static inline void xge_debug_ring(xge_debug_level_e level, char *fmt, ...) {
255 	u32 module = XGE_COMPONENT_HAL_RING;
256 	xge_debug(module, level, fmt);
257 }
258 #else /* __GNUC__ */
259 #define xge_debug_ring(level, fmt...) \
260 	xge_debug(XGE_COMPONENT_HAL_RING, level, fmt)
261 #endif /* __GNUC__ */
262 #else
263 #ifndef __GNUC__
264 static inline void xge_debug_ring(xge_debug_level_e level, char *fmt, ...) {}
265 #else /* __GNUC__ */
266 #define xge_debug_ring(level, fmt...)
267 #endif /* __GNUC__ */
268 #endif
269 
270 #if (XGE_COMPONENT_HAL_CHANNEL & XGE_DEBUG_MODULE_MASK)
271 #ifndef __GNUC__
272 static inline void xge_debug_channel(xge_debug_level_e level, char *fmt, ...) {
273 	u32 module = XGE_COMPONENT_HAL_CHANNEL;
274 	xge_debug(module, level, fmt);
275 }
276 #else /* __GNUC__ */
277 #define xge_debug_channel(level, fmt...) \
278 	xge_debug(XGE_COMPONENT_HAL_CHANNEL, level, fmt)
279 #endif /* __GNUC__ */
280 #else
281 #ifndef __GNUC__
282 static inline void xge_debug_channel(xge_debug_level_e level, char *fmt, ...) {}
283 #else /* __GNUC__ */
284 #define xge_debug_channel(level, fmt...)
285 #endif /* __GNUC__ */
286 #endif
287 
288 #if (XGE_COMPONENT_HAL_DEVICE & XGE_DEBUG_MODULE_MASK)
289 #ifndef __GNUC__
290 static inline void xge_debug_device(xge_debug_level_e level, char *fmt, ...) {
291 	u32 module = XGE_COMPONENT_HAL_DEVICE;
292 	xge_debug(module, level, fmt);
293 }
294 #else /* __GNUC__ */
295 #define xge_debug_device(level, fmt...) \
296 	xge_debug(XGE_COMPONENT_HAL_DEVICE, level, fmt)
297 #endif /* __GNUC__ */
298 #else
299 #ifndef __GNUC__
300 static inline void xge_debug_device(xge_debug_level_e level, char *fmt, ...) {}
301 #else /* __GNUC__ */
302 #define xge_debug_device(level, fmt...)
303 #endif /* __GNUC__ */
304 #endif
305 
306 #if (XGE_COMPONENT_OSDEP & XGE_DEBUG_MODULE_MASK)
307 #ifndef __GNUC__
308 static inline void xge_debug_osdep(xge_debug_level_e level, char *fmt, ...) {
309 	u32 module = XGE_COMPONENT_OSDEP;
310 	xge_debug(module, level, fmt);
311 }
312 #else /* __GNUC__ */
313 #define xge_debug_osdep(level, fmt...) \
314 	xge_debug(XGE_COMPONENT_OSDEP, level, fmt)
315 #endif /* __GNUC__ */
316 #else
317 #ifndef __GNUC__
318 static inline void xge_debug_osdep(xge_debug_level_e level, char *fmt, ...) {}
319 #else /* __GNUC__ */
320 #define xge_debug_osdep(level, fmt...)
321 #endif /* __GNUC__ */
322 #endif
323 
324 #if (XGE_COMPONENT_LL & XGE_DEBUG_MODULE_MASK)
325 #ifndef __GNUC__
326 static inline void xge_debug_ll(xge_debug_level_e level, char *fmt, ...)
327 {
328 	u32 module = XGE_COMPONENT_LL;
329 	xge_debug(module, level, fmt);
330 }
331 #else /* __GNUC__ */
332 #define xge_debug_ll(level, fmt...) \
333 	xge_debug(XGE_COMPONENT_LL, level, fmt)
334 #endif /* __GNUC__ */
335 #else
336 #ifndef __GNUC__
337 static inline void xge_debug_ll(xge_debug_level_e level, char *fmt, ...) {}
338 #else /* __GNUC__ */
339 #define xge_debug_ll(level, fmt...)
340 #endif /* __GNUC__ */
341 #endif
342 
343 #else
344 
345 static inline void xge_debug_stats(xge_debug_level_e level, char *fmt, ...) {}
346 static inline void xge_debug_queue(xge_debug_level_e level, char *fmt, ...) {}
347 static inline void xge_debug_mm(xge_debug_level_e level, char *fmt, ...) {}
348 static inline void xge_debug_config(xge_debug_level_e level, char *fmt, ...) {}
349 static inline void xge_debug_fifo(xge_debug_level_e level, char *fmt, ...) {}
350 static inline void xge_debug_ring(xge_debug_level_e level, char *fmt, ...) {}
351 static inline void xge_debug_channel(xge_debug_level_e level, char *fmt, ...) {}
352 static inline void xge_debug_device(xge_debug_level_e level, char *fmt, ...) {}
353 static inline void xge_debug_hal(xge_debug_level_e level, char *fmt, ...) {}
354 static inline void xge_debug_osdep(xge_debug_level_e level, char *fmt, ...) {}
355 static inline void xge_debug_ll(xge_debug_level_e level, char *fmt, ...) {}
356 
357 #endif /* end of XGE_DEBUG_*_MASK */
358 
359 #ifdef XGE_DEBUG_ASSERT
360 
361 /**
362  * xge_assert
363  * @test: C-condition to check
364  * @fmt: printf like format string
365  *
366  * This function implements traditional assert. By default assertions
367  * are enabled. It can be disabled by defining XGE_DEBUG_ASSERT macro in
368  * compilation
369  * time.
370  */
371 #define xge_assert(test) { \
372         if (!(test)) xge_os_bug("bad cond: "#test" at %s:%d\n", \
373 	__FILE__, __LINE__); }
374 #else
375 #define xge_assert(test)
376 #endif /* end of XGE_DEBUG_ASSERT */
377 
378 #endif /* XGE_DEBUG_H */
379