2 * Copyright (c) 2002-2007 Neterion, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <dev/nxge/include/xge-os-pal.h>
37 * __FUNCTION__ is, together with __PRETTY_FUNCTION__ or something similar,
38 * a gcc extension. we'll have to #ifdef around that, and provide some
39 * meaningful replacement for those, so to make some gcc versions happier
43 #define __func__ __FUNCTION__
49 #define XGE_DEBUG_FP_DEVICE 0x1
50 #define XGE_DEBUG_FP_CHANNEL 0x2
51 #define XGE_DEBUG_FP_FIFO 0x4
52 #define XGE_DEBUG_FP_RING 0x8
53 #define XGE_DEBUG_FP_ALL 0xff
57 * enum xge_debug_level_e
58 * @XGE_NONE: debug disabled
59 * @XGE_ERR: all errors going to be logged out
60 * @XGE_TRACE: all errors plus all kind of verbose tracing print outs
61 * going to be logged out. Very noisy.
63 * This enumeration going to be used to switch between different
64 * debug levels during runtime if DEBUG macro defined during
65 * compilation. If DEBUG macro not defined than code will be
68 typedef enum xge_debug_level_e {
74 #define XGE_DEBUG_MODULE_MASK_DEF 0x30000030
75 #define XGE_DEBUG_LEVEL_DEF XGE_ERR
77 #if defined(XGE_DEBUG_TRACE_MASK) || defined(XGE_DEBUG_ERR_MASK)
79 extern unsigned long *g_module_mask;
82 #ifndef XGE_DEBUG_TRACE_MASK
83 #define XGE_DEBUG_TRACE_MASK 0
86 #ifndef XGE_DEBUG_ERR_MASK
87 #define XGE_DEBUG_ERR_MASK 0
91 * @XGE_COMPONENT_HAL_CONFIG: do debug for xge core config module
92 * @XGE_COMPONENT_HAL_FIFO: do debug for xge core fifo module
93 * @XGE_COMPONENT_HAL_RING: do debug for xge core ring module
94 * @XGE_COMPONENT_HAL_CHANNEL: do debug for xge core channel module
95 * @XGE_COMPONENT_HAL_DEVICE: do debug for xge core device module
96 * @XGE_COMPONENT_HAL_DMQ: do debug for xge core DMQ module
97 * @XGE_COMPONENT_HAL_UMQ: do debug for xge core UMQ module
98 * @XGE_COMPONENT_HAL_SQ: do debug for xge core SQ module
99 * @XGE_COMPONENT_HAL_SRQ: do debug for xge core SRQ module
100 * @XGE_COMPONENT_HAL_CQRQ: do debug for xge core CRQ module
101 * @XGE_COMPONENT_HAL_POOL: do debug for xge core memory pool module
102 * @XGE_COMPONENT_HAL_BITMAP: do debug for xge core BITMAP module
103 * @XGE_COMPONENT_CORE: do debug for xge KMA core module
104 * @XGE_COMPONENT_OSDEP: do debug for xge KMA os dependent parts
105 * @XGE_COMPONENT_LL: do debug for xge link layer module
106 * @XGE_COMPONENT_ALL: activate debug for all modules with no exceptions
108 * This enumeration going to be used to distinguish modules
109 * or libraries during compilation and runtime. Makefile must declare
110 * XGE_DEBUG_MODULE_MASK macro and set it to proper value.
112 #define XGE_COMPONENT_HAL_CONFIG 0x00000001
113 #define XGE_COMPONENT_HAL_FIFO 0x00000002
114 #define XGE_COMPONENT_HAL_RING 0x00000004
115 #define XGE_COMPONENT_HAL_CHANNEL 0x00000008
116 #define XGE_COMPONENT_HAL_DEVICE 0x00000010
117 #define XGE_COMPONENT_HAL_MM 0x00000020
118 #define XGE_COMPONENT_HAL_QUEUE 0x00000040
119 #define XGE_COMPONENT_HAL_INTERRUPT 0x00000080
120 #define XGE_COMPONENT_HAL_STATS 0x00000100
122 /* space for CORE_XXX */
123 #define XGE_COMPONENT_OSDEP 0x10000000
124 #define XGE_COMPONENT_LL 0x20000000
125 #define XGE_COMPONENT_ALL 0xffffffff
127 #ifndef XGE_DEBUG_MODULE_MASK
128 #error "XGE_DEBUG_MODULE_MASK macro must be defined for DEBUG mode..."
132 #ifdef XGE_TRACE_INTO_CIRCULAR_ARR
133 #define xge_trace_aux(fmt) xge_os_vatrace(g_xge_os_tracebuf, fmt)
135 #define xge_trace_aux(fmt) xge_os_vaprintf(fmt)
140 * @level: level of debug verbosity.
141 * @fmt: printf like format string
143 * Provides logging facilities. Can be customized on per-module
144 * basis or/and with debug levels. Input parameters, except
145 * module and level, are the same as posix printf. This function
146 * may be compiled out if DEBUG macro was never defined.
147 * See also: xge_debug_level_e{}.
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 & *(unsigned int *)g_module_mask) { \
153 xge_trace_aux(fmt); \
158 #ifdef XGE_TRACE_INTO_CIRCULAR_ARR
159 #define xge_trace_aux(fmt...) xge_os_trace(g_xge_os_tracebuf, fmt)
161 #define xge_trace_aux(fmt...) xge_os_printf(fmt)
164 #define xge_debug(module, level, fmt...) { \
165 if (((level >= XGE_TRACE && ((module & XGE_DEBUG_TRACE_MASK) == module)) || \
166 (level >= XGE_ERR && ((module & XGE_DEBUG_ERR_MASK) == module))) && \
167 level >= *g_level && module & *(unsigned int *)g_module_mask) { \
168 xge_trace_aux(fmt); \
171 #endif /* __GNUC__ */
173 #if (XGE_COMPONENT_HAL_STATS & XGE_DEBUG_MODULE_MASK)
175 static inline void xge_debug_stats(xge_debug_level_e level, char *fmt, ...) {
176 u32 module = XGE_COMPONENT_HAL_STATS;
177 xge_debug(module, level, fmt);
180 #define xge_debug_stats(level, fmt...) \
181 xge_debug(XGE_COMPONENT_HAL_STATS, level, fmt)
182 #endif /* __GNUC__ */
185 static inline void xge_debug_stats(xge_debug_level_e level, char *fmt, ...) {}
187 #define xge_debug_stats(level, fmt...)
188 #endif /* __GNUC__ */
191 /* Interrupt Related */
192 #if (XGE_COMPONENT_HAL_INTERRUPT & XGE_DEBUG_MODULE_MASK)
194 static inline void xge_debug_interrupt(xge_debug_level_e level, char *fmt, ...) {
195 u32 module = XGE_COMPONENT_HAL_INTERRUPT;
196 xge_debug(module, level, fmt);
199 #define xge_debug_interrupt(level, fmt...) \
200 xge_debug(XGE_COMPONENT_HAL_INTERRUPT, level, fmt)
201 #endif /* __GNUC__ */
204 static inline void xge_debug_interrupt(xge_debug_level_e level, char *fmt, ...) {}
206 #define xge_debug_interrupt(level, fmt...)
207 #endif /* __GNUC__ */
210 #if (XGE_COMPONENT_HAL_QUEUE & XGE_DEBUG_MODULE_MASK)
212 static inline void xge_debug_queue(xge_debug_level_e level, char *fmt, ...) {
213 u32 module = XGE_COMPONENT_HAL_QUEUE;
214 xge_debug(module, level, fmt);
217 #define xge_debug_queue(level, fmt...) \
218 xge_debug(XGE_COMPONENT_HAL_QUEUE, level, fmt)
219 #endif /* __GNUC__ */
222 static inline void xge_debug_queue(xge_debug_level_e level, char *fmt,
225 #define xge_debug_queue(level, fmt...)
226 #endif /* __GNUC__ */
229 #if (XGE_COMPONENT_HAL_MM & XGE_DEBUG_MODULE_MASK)
231 static inline void xge_debug_mm(xge_debug_level_e level, char *fmt, ...)
233 u32 module = XGE_COMPONENT_HAL_MM;
234 xge_debug(module, level, fmt);
237 #define xge_debug_mm(level, fmt...) \
238 xge_debug(XGE_COMPONENT_HAL_MM, level, fmt)
239 #endif /* __GNUC__ */
242 static inline void xge_debug_mm(xge_debug_level_e level, char *fmt, ...)
245 #define xge_debug_mm(level, fmt...)
246 #endif /* __GNUC__ */
249 #if (XGE_COMPONENT_HAL_CONFIG & XGE_DEBUG_MODULE_MASK)
251 static inline void xge_debug_config(xge_debug_level_e level, char *fmt, ...) {
252 u32 module = XGE_COMPONENT_HAL_CONFIG;
253 xge_debug(module, level, fmt);
256 #define xge_debug_config(level, fmt...) \
257 xge_debug(XGE_COMPONENT_HAL_CONFIG, level, fmt)
258 #endif /* __GNUC__ */
261 static inline void xge_debug_config(xge_debug_level_e level, char *fmt,
264 #define xge_debug_config(level, fmt...)
265 #endif /* __GNUC__ */
268 #if (XGE_COMPONENT_HAL_FIFO & XGE_DEBUG_MODULE_MASK)
270 static inline void xge_debug_fifo(xge_debug_level_e level, char *fmt, ...) {
271 u32 module = XGE_COMPONENT_HAL_FIFO;
272 xge_debug(module, level, fmt);
275 #define xge_debug_fifo(level, fmt...) \
276 xge_debug(XGE_COMPONENT_HAL_FIFO, level, fmt)
277 #endif /* __GNUC__ */
280 static inline void xge_debug_fifo(xge_debug_level_e level, char *fmt, ...) {}
282 #define xge_debug_fifo(level, fmt...)
283 #endif /* __GNUC__ */
286 #if (XGE_COMPONENT_HAL_RING & XGE_DEBUG_MODULE_MASK)
288 static inline void xge_debug_ring(xge_debug_level_e level, char *fmt, ...) {
289 u32 module = XGE_COMPONENT_HAL_RING;
290 xge_debug(module, level, fmt);
293 #define xge_debug_ring(level, fmt...) \
294 xge_debug(XGE_COMPONENT_HAL_RING, level, fmt)
295 #endif /* __GNUC__ */
298 static inline void xge_debug_ring(xge_debug_level_e level, char *fmt, ...) {}
300 #define xge_debug_ring(level, fmt...)
301 #endif /* __GNUC__ */
304 #if (XGE_COMPONENT_HAL_CHANNEL & XGE_DEBUG_MODULE_MASK)
306 static inline void xge_debug_channel(xge_debug_level_e level, char *fmt, ...) {
307 u32 module = XGE_COMPONENT_HAL_CHANNEL;
308 xge_debug(module, level, fmt);
311 #define xge_debug_channel(level, fmt...) \
312 xge_debug(XGE_COMPONENT_HAL_CHANNEL, level, fmt)
313 #endif /* __GNUC__ */
316 static inline void xge_debug_channel(xge_debug_level_e level, char *fmt, ...) {}
318 #define xge_debug_channel(level, fmt...)
319 #endif /* __GNUC__ */
322 #if (XGE_COMPONENT_HAL_DEVICE & XGE_DEBUG_MODULE_MASK)
324 static inline void xge_debug_device(xge_debug_level_e level, char *fmt, ...) {
325 u32 module = XGE_COMPONENT_HAL_DEVICE;
326 xge_debug(module, level, fmt);
329 #define xge_debug_device(level, fmt...) \
330 xge_debug(XGE_COMPONENT_HAL_DEVICE, level, fmt)
331 #endif /* __GNUC__ */
334 static inline void xge_debug_device(xge_debug_level_e level, char *fmt, ...) {}
336 #define xge_debug_device(level, fmt...)
337 #endif /* __GNUC__ */
340 #if (XGE_COMPONENT_OSDEP & XGE_DEBUG_MODULE_MASK)
342 static inline void xge_debug_osdep(xge_debug_level_e level, char *fmt, ...) {
343 u32 module = XGE_COMPONENT_OSDEP;
344 xge_debug(module, level, fmt);
347 #define xge_debug_osdep(level, fmt...) \
348 xge_debug(XGE_COMPONENT_OSDEP, level, fmt)
349 #endif /* __GNUC__ */
352 static inline void xge_debug_osdep(xge_debug_level_e level, char *fmt, ...) {}
354 #define xge_debug_osdep(level, fmt...)
355 #endif /* __GNUC__ */
358 #if (XGE_COMPONENT_LL & XGE_DEBUG_MODULE_MASK)
360 static inline void xge_debug_ll(xge_debug_level_e level, char *fmt, ...)
362 u32 module = XGE_COMPONENT_LL;
363 xge_debug(module, level, fmt);
366 #define xge_debug_ll(level, fmt...) \
367 xge_debug(XGE_COMPONENT_LL, level, fmt)
368 #endif /* __GNUC__ */
371 static inline void xge_debug_ll(xge_debug_level_e level, char *fmt, ...) {}
373 #define xge_debug_ll(level, fmt...)
374 #endif /* __GNUC__ */
379 static inline void xge_debug_interrupt(xge_debug_level_e level, char *fmt, ...) {}
380 static inline void xge_debug_stats(xge_debug_level_e level, char *fmt, ...) {}
381 static inline void xge_debug_queue(xge_debug_level_e level, char *fmt, ...) {}
382 static inline void xge_debug_mm(xge_debug_level_e level, char *fmt, ...) {}
383 static inline void xge_debug_config(xge_debug_level_e level, char *fmt, ...) {}
384 static inline void xge_debug_fifo(xge_debug_level_e level, char *fmt, ...) {}
385 static inline void xge_debug_ring(xge_debug_level_e level, char *fmt, ...) {}
386 static inline void xge_debug_channel(xge_debug_level_e level, char *fmt, ...) {}
387 static inline void xge_debug_device(xge_debug_level_e level, char *fmt, ...) {}
388 static inline void xge_debug_hal(xge_debug_level_e level, char *fmt, ...) {}
389 static inline void xge_debug_osdep(xge_debug_level_e level, char *fmt, ...) {}
390 static inline void xge_debug_ll(xge_debug_level_e level, char *fmt, ...) {}
392 #endif /* end of XGE_DEBUG_*_MASK */
394 #ifdef XGE_DEBUG_ASSERT
398 * @test: C-condition to check
399 * @fmt: printf like format string
401 * This function implements traditional assert. By default assertions
402 * are enabled. It can be disabled by defining XGE_DEBUG_ASSERT macro in
406 #define xge_assert(test) { \
407 if (!(test)) xge_os_bug("bad cond: "#test" at %s:%d\n", \
408 __FILE__, __LINE__); }
410 #define xge_assert(test)
411 #endif /* end of XGE_DEBUG_ASSERT */
415 #endif /* XGE_DEBUG_H */