xref: /titanic_50/usr/src/uts/common/io/xge/hal/include/xge-debug.h (revision 7eced415e5dd557aef2d78483b5a7785f0e13670)
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  * Copyright (c) 2002-2006 Neterion, Inc.
22  */
23 
24 #ifndef XGE_DEBUG_H
25 #define XGE_DEBUG_H
26 
27 #include "xge-os-pal.h"
28 
29 __EXTERN_BEGIN_DECLS
30 
31 /*
32  * __FUNCTION__ is, together with __PRETTY_FUNCTION__ or something similar,
33  * a gcc extension. we'll have to #ifdef around that, and provide some
34  * meaningful replacement for those, so to make some gcc versions happier
35  */
36 #ifndef __func__
37 #ifdef __FUNCTION__
38 #define __func__ __FUNCTION__
39 #endif
40 #endif
41 
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	0x30000030
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 long *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_HAL_DMQ: do debug for xge core DMQ module
91  * @XGE_COMPONENT_HAL_UMQ: do debug for xge core UMQ module
92  * @XGE_COMPONENT_HAL_SQ: do debug for xge core SQ module
93  * @XGE_COMPONENT_HAL_SRQ: do debug for xge core SRQ module
94  * @XGE_COMPONENT_HAL_CQRQ: do debug for xge core CRQ module
95  * @XGE_COMPONENT_HAL_POOL: do debug for xge core memory pool module
96  * @XGE_COMPONENT_HAL_BITMAP: do debug for xge core BITMAP module
97  * @XGE_COMPONENT_CORE: do debug for xge KMA core module
98  * @XGE_COMPONENT_OSDEP: do debug for xge KMA os dependent parts
99  * @XGE_COMPONENT_LL: do debug for xge link layer module
100  * @XGE_COMPONENT_ALL: activate debug for all modules with no exceptions
101  *
102  * This enumeration going to be used to distinguish modules
103  * or libraries during compilation and runtime.  Makefile must declare
104  * XGE_DEBUG_MODULE_MASK macro and set it to proper value.
105  */
106 #define XGE_COMPONENT_HAL_CONFIG		0x00000001
107 #define	XGE_COMPONENT_HAL_FIFO			0x00000002
108 #define	XGE_COMPONENT_HAL_RING			0x00000004
109 #define	XGE_COMPONENT_HAL_CHANNEL		0x00000008
110 #define	XGE_COMPONENT_HAL_DEVICE		0x00000010
111 #define	XGE_COMPONENT_HAL_MM			0x00000020
112 #define	XGE_COMPONENT_HAL_QUEUE	        0x00000040
113 #define	XGE_COMPONENT_HAL_INTERRUPT     0x00000080
114 #define	XGE_COMPONENT_HAL_STATS	        0x00000100
115 
116 	/* space for CORE_XXX */
117 #define	XGE_COMPONENT_OSDEP			0x10000000
118 #define	XGE_COMPONENT_LL			0x20000000
119 #define	XGE_COMPONENT_ALL			0xffffffff
120 
121 #ifndef XGE_DEBUG_MODULE_MASK
122 #error "XGE_DEBUG_MODULE_MASK macro must be defined for DEBUG mode..."
123 #endif
124 
125 #ifndef __GNUC__
126 #ifdef XGE_TRACE_INTO_CIRCULAR_ARR
127         #define xge_trace_aux(fmt) xge_os_vatrace(g_xge_os_tracebuf, fmt)
128 #else
129         #define xge_trace_aux(fmt) xge_os_vaprintf(fmt)
130 #endif
131 
132 /**
133  * xge_debug
134  * @level: level of debug verbosity.
135  * @fmt: printf like format string
136  *
137  * Provides logging facilities. Can be customized on per-module
138  * basis or/and with debug levels. Input parameters, except
139  * module and level, are the same as posix printf. This function
140  * may be compiled out if DEBUG macro was never defined.
141  * See also: xge_debug_level_e{}.
142  */
143 #define xge_debug(module, level, fmt) { \
144 if (((level >= XGE_TRACE && ((module & XGE_DEBUG_TRACE_MASK) == module)) || \
145     (level >= XGE_ERR && ((module & XGE_DEBUG_ERR_MASK) == module))) && \
146     level >= *g_level && module & *(unsigned int *)g_module_mask) { \
147                 xge_trace_aux(fmt); \
148 	} \
149 }
150 #else /* __GNUC__ */
151 
152 #ifdef XGE_TRACE_INTO_CIRCULAR_ARR
153         #define xge_trace_aux(fmt...) xge_os_trace(g_xge_os_tracebuf, fmt)
154 #else
155         #define xge_trace_aux(fmt...) xge_os_printf(fmt)
156 #endif
157 
158 #define xge_debug(module, level, fmt...) { \
159 if (((level >= XGE_TRACE && ((module & XGE_DEBUG_TRACE_MASK) == module)) || \
160     (level >= XGE_ERR && ((module & XGE_DEBUG_ERR_MASK) == module))) && \
161     level >= *g_level && module & *(unsigned int *)g_module_mask) { \
162                 xge_trace_aux(fmt); \
163 	} \
164 }
165 #endif /* __GNUC__ */
166 
167 #if (XGE_COMPONENT_HAL_STATS & XGE_DEBUG_MODULE_MASK)
168 #ifndef __GNUC__
xge_debug_stats(xge_debug_level_e level,char * fmt,...)169 static inline void xge_debug_stats(xge_debug_level_e level, char *fmt, ...) {
170 	u32 module = XGE_COMPONENT_HAL_STATS;
171 	xge_debug(module, level, fmt);
172 }
173 #else /* __GNUC__ */
174 #define xge_debug_stats(level, fmt...) \
175 	xge_debug(XGE_COMPONENT_HAL_STATS, level, fmt)
176 #endif /* __GNUC__ */
177 #else
178 #ifndef __GNUC__
xge_debug_stats(xge_debug_level_e level,char * fmt,...)179 static inline void xge_debug_stats(xge_debug_level_e level, char *fmt, ...) {}
180 #else /* __GNUC__ */
181 #define xge_debug_stats(level, fmt...)
182 #endif /* __GNUC__ */
183 #endif
184 
185 /* Interrupt Related */
186 #if (XGE_COMPONENT_HAL_INTERRUPT & XGE_DEBUG_MODULE_MASK)
187 #ifndef __GNUC__
xge_debug_interrupt(xge_debug_level_e level,char * fmt,...)188 static inline void xge_debug_interrupt(xge_debug_level_e level, char *fmt, ...) {
189 	u32 module = XGE_COMPONENT_HAL_INTERRUPT;
190 	xge_debug(module, level, fmt);
191 }
192 #else /* __GNUC__ */
193 #define xge_debug_interrupt(level, fmt...) \
194 	xge_debug(XGE_COMPONENT_HAL_INTERRUPT, level, fmt)
195 #endif /* __GNUC__ */
196 #else
197 #ifndef __GNUC__
xge_debug_interrupt(xge_debug_level_e level,char * fmt,...)198 static inline void xge_debug_interrupt(xge_debug_level_e level, char *fmt, ...) {}
199 #else /* __GNUC__ */
200 #define xge_debug_interrupt(level, fmt...)
201 #endif /* __GNUC__ */
202 #endif
203 
204 #if (XGE_COMPONENT_HAL_QUEUE & XGE_DEBUG_MODULE_MASK)
205 #ifndef __GNUC__
xge_debug_queue(xge_debug_level_e level,char * fmt,...)206 static inline void xge_debug_queue(xge_debug_level_e level, char *fmt, ...) {
207 	u32 module = XGE_COMPONENT_HAL_QUEUE;
208 	xge_debug(module, level, fmt);
209 }
210 #else /* __GNUC__ */
211 #define xge_debug_queue(level, fmt...) \
212 	xge_debug(XGE_COMPONENT_HAL_QUEUE, level, fmt)
213 #endif /* __GNUC__ */
214 #else
215 #ifndef __GNUC__
xge_debug_queue(xge_debug_level_e level,char * fmt,...)216 static inline void xge_debug_queue(xge_debug_level_e level, char *fmt,
217 ...) {}
218 #else /* __GNUC__ */
219 #define xge_debug_queue(level, fmt...)
220 #endif /* __GNUC__ */
221 #endif
222 
223 #if (XGE_COMPONENT_HAL_MM & XGE_DEBUG_MODULE_MASK)
224 #ifndef __GNUC__
xge_debug_mm(xge_debug_level_e level,char * fmt,...)225 static inline void xge_debug_mm(xge_debug_level_e level, char *fmt, ...)
226 {
227 	u32 module = XGE_COMPONENT_HAL_MM;
228 	xge_debug(module, level, fmt);
229 }
230 #else /* __GNUC__ */
231 #define xge_debug_mm(level, fmt...) \
232 	xge_debug(XGE_COMPONENT_HAL_MM, level, fmt)
233 #endif /* __GNUC__ */
234 #else
235 #ifndef __GNUC__
xge_debug_mm(xge_debug_level_e level,char * fmt,...)236 static inline void xge_debug_mm(xge_debug_level_e level, char *fmt, ...)
237 {}
238 #else /* __GNUC__ */
239 #define xge_debug_mm(level, fmt...)
240 #endif /* __GNUC__ */
241 #endif
242 
243 #if (XGE_COMPONENT_HAL_CONFIG & XGE_DEBUG_MODULE_MASK)
244 #ifndef __GNUC__
xge_debug_config(xge_debug_level_e level,char * fmt,...)245 static inline void xge_debug_config(xge_debug_level_e level, char *fmt, ...) {
246 	u32 module = XGE_COMPONENT_HAL_CONFIG;
247 	xge_debug(module, level, fmt);
248 }
249 #else /* __GNUC__ */
250 #define xge_debug_config(level, fmt...) \
251 	xge_debug(XGE_COMPONENT_HAL_CONFIG, level, fmt)
252 #endif /* __GNUC__ */
253 #else
254 #ifndef __GNUC__
xge_debug_config(xge_debug_level_e level,char * fmt,...)255 static inline void xge_debug_config(xge_debug_level_e level, char *fmt,
256 ...) {}
257 #else /* __GNUC__ */
258 #define xge_debug_config(level, fmt...)
259 #endif /* __GNUC__ */
260 #endif
261 
262 #if (XGE_COMPONENT_HAL_FIFO & XGE_DEBUG_MODULE_MASK)
263 #ifndef __GNUC__
xge_debug_fifo(xge_debug_level_e level,char * fmt,...)264 static inline void xge_debug_fifo(xge_debug_level_e level, char *fmt, ...) {
265 	u32 module = XGE_COMPONENT_HAL_FIFO;
266 	xge_debug(module, level, fmt);
267 }
268 #else /* __GNUC__ */
269 #define xge_debug_fifo(level, fmt...) \
270 	xge_debug(XGE_COMPONENT_HAL_FIFO, level, fmt)
271 #endif /* __GNUC__ */
272 #else
273 #ifndef __GNUC__
xge_debug_fifo(xge_debug_level_e level,char * fmt,...)274 static inline void xge_debug_fifo(xge_debug_level_e level, char *fmt, ...) {}
275 #else /* __GNUC__ */
276 #define xge_debug_fifo(level, fmt...)
277 #endif /* __GNUC__ */
278 #endif
279 
280 #if (XGE_COMPONENT_HAL_RING & XGE_DEBUG_MODULE_MASK)
281 #ifndef __GNUC__
xge_debug_ring(xge_debug_level_e level,char * fmt,...)282 static inline void xge_debug_ring(xge_debug_level_e level, char *fmt, ...) {
283 	u32 module = XGE_COMPONENT_HAL_RING;
284 	xge_debug(module, level, fmt);
285 }
286 #else /* __GNUC__ */
287 #define xge_debug_ring(level, fmt...) \
288 	xge_debug(XGE_COMPONENT_HAL_RING, level, fmt)
289 #endif /* __GNUC__ */
290 #else
291 #ifndef __GNUC__
xge_debug_ring(xge_debug_level_e level,char * fmt,...)292 static inline void xge_debug_ring(xge_debug_level_e level, char *fmt, ...) {}
293 #else /* __GNUC__ */
294 #define xge_debug_ring(level, fmt...)
295 #endif /* __GNUC__ */
296 #endif
297 
298 #if (XGE_COMPONENT_HAL_CHANNEL & XGE_DEBUG_MODULE_MASK)
299 #ifndef __GNUC__
xge_debug_channel(xge_debug_level_e level,char * fmt,...)300 static inline void xge_debug_channel(xge_debug_level_e level, char *fmt, ...) {
301 	u32 module = XGE_COMPONENT_HAL_CHANNEL;
302 	xge_debug(module, level, fmt);
303 }
304 #else /* __GNUC__ */
305 #define xge_debug_channel(level, fmt...) \
306 	xge_debug(XGE_COMPONENT_HAL_CHANNEL, level, fmt)
307 #endif /* __GNUC__ */
308 #else
309 #ifndef __GNUC__
xge_debug_channel(xge_debug_level_e level,char * fmt,...)310 static inline void xge_debug_channel(xge_debug_level_e level, char *fmt, ...) {}
311 #else /* __GNUC__ */
312 #define xge_debug_channel(level, fmt...)
313 #endif /* __GNUC__ */
314 #endif
315 
316 #if (XGE_COMPONENT_HAL_DEVICE & XGE_DEBUG_MODULE_MASK)
317 #ifndef __GNUC__
xge_debug_device(xge_debug_level_e level,char * fmt,...)318 static inline void xge_debug_device(xge_debug_level_e level, char *fmt, ...) {
319 	u32 module = XGE_COMPONENT_HAL_DEVICE;
320 	xge_debug(module, level, fmt);
321 }
322 #else /* __GNUC__ */
323 #define xge_debug_device(level, fmt...) \
324 	xge_debug(XGE_COMPONENT_HAL_DEVICE, level, fmt)
325 #endif /* __GNUC__ */
326 #else
327 #ifndef __GNUC__
xge_debug_device(xge_debug_level_e level,char * fmt,...)328 static inline void xge_debug_device(xge_debug_level_e level, char *fmt, ...) {}
329 #else /* __GNUC__ */
330 #define xge_debug_device(level, fmt...)
331 #endif /* __GNUC__ */
332 #endif
333 
334 #if (XGE_COMPONENT_OSDEP & XGE_DEBUG_MODULE_MASK)
335 #ifndef __GNUC__
xge_debug_osdep(xge_debug_level_e level,char * fmt,...)336 static inline void xge_debug_osdep(xge_debug_level_e level, char *fmt, ...) {
337 	u32 module = XGE_COMPONENT_OSDEP;
338 	xge_debug(module, level, fmt);
339 }
340 #else /* __GNUC__ */
341 #define xge_debug_osdep(level, fmt...) \
342 	xge_debug(XGE_COMPONENT_OSDEP, level, fmt)
343 #endif /* __GNUC__ */
344 #else
345 #ifndef __GNUC__
xge_debug_osdep(xge_debug_level_e level,char * fmt,...)346 static inline void xge_debug_osdep(xge_debug_level_e level, char *fmt, ...) {}
347 #else /* __GNUC__ */
348 #define xge_debug_osdep(level, fmt...)
349 #endif /* __GNUC__ */
350 #endif
351 
352 #if (XGE_COMPONENT_LL & XGE_DEBUG_MODULE_MASK)
353 #ifndef __GNUC__
xge_debug_ll(xge_debug_level_e level,char * fmt,...)354 static inline void xge_debug_ll(xge_debug_level_e level, char *fmt, ...)
355 {
356 	u32 module = XGE_COMPONENT_LL;
357 	xge_debug(module, level, fmt);
358 }
359 #else /* __GNUC__ */
360 #define xge_debug_ll(level, fmt...) \
361 	xge_debug(XGE_COMPONENT_LL, level, fmt)
362 #endif /* __GNUC__ */
363 #else
364 #ifndef __GNUC__
xge_debug_ll(xge_debug_level_e level,char * fmt,...)365 static inline void xge_debug_ll(xge_debug_level_e level, char *fmt, ...) {}
366 #else /* __GNUC__ */
367 #define xge_debug_ll(level, fmt...)
368 #endif /* __GNUC__ */
369 #endif
370 
371 #else
372 
xge_debug_interrupt(xge_debug_level_e level,char * fmt,...)373 static inline void xge_debug_interrupt(xge_debug_level_e level, char *fmt, ...) {}
xge_debug_stats(xge_debug_level_e level,char * fmt,...)374 static inline void xge_debug_stats(xge_debug_level_e level, char *fmt, ...) {}
xge_debug_queue(xge_debug_level_e level,char * fmt,...)375 static inline void xge_debug_queue(xge_debug_level_e level, char *fmt, ...) {}
xge_debug_mm(xge_debug_level_e level,char * fmt,...)376 static inline void xge_debug_mm(xge_debug_level_e level, char *fmt, ...) {}
xge_debug_config(xge_debug_level_e level,char * fmt,...)377 static inline void xge_debug_config(xge_debug_level_e level, char *fmt, ...) {}
xge_debug_fifo(xge_debug_level_e level,char * fmt,...)378 static inline void xge_debug_fifo(xge_debug_level_e level, char *fmt, ...) {}
xge_debug_ring(xge_debug_level_e level,char * fmt,...)379 static inline void xge_debug_ring(xge_debug_level_e level, char *fmt, ...) {}
xge_debug_channel(xge_debug_level_e level,char * fmt,...)380 static inline void xge_debug_channel(xge_debug_level_e level, char *fmt, ...) {}
xge_debug_device(xge_debug_level_e level,char * fmt,...)381 static inline void xge_debug_device(xge_debug_level_e level, char *fmt, ...) {}
xge_debug_hal(xge_debug_level_e level,char * fmt,...)382 static inline void xge_debug_hal(xge_debug_level_e level, char *fmt, ...) {}
xge_debug_osdep(xge_debug_level_e level,char * fmt,...)383 static inline void xge_debug_osdep(xge_debug_level_e level, char *fmt, ...) {}
xge_debug_ll(xge_debug_level_e level,char * fmt,...)384 static inline void xge_debug_ll(xge_debug_level_e level, char *fmt, ...) {}
385 
386 #endif /* end of XGE_DEBUG_*_MASK */
387 
388 #ifdef XGE_DEBUG_ASSERT
389 
390 /**
391  * xge_assert
392  * @test: C-condition to check
393  * @fmt: printf like format string
394  *
395  * This function implements traditional assert. By default assertions
396  * are enabled. It can be disabled by defining XGE_DEBUG_ASSERT macro in
397  * compilation
398  * time.
399  */
400 #define xge_assert(test) { \
401         if (!(test)) xge_os_bug("bad cond: "#test" at %s:%d\n", \
402 	__FILE__, __LINE__); }
403 #else
404 #define xge_assert(test)
405 #endif /* end of XGE_DEBUG_ASSERT */
406 
407 __EXTERN_END_DECLS
408 
409 #endif /* XGE_DEBUG_H */
410