4 * Copyright (C) 2004-2007 Vladislav Bolkhovitin <vst@vlnb.net>
7 * Contains macroses for execution tracing and error reporting
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, version 2
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 #ifndef __SCST_DEBUG_H
21 #define __SCST_DEBUG_H
23 #include <linux/autoconf.h> /* for CONFIG_* */
24 #include <linux/bug.h> /* for WARN_ON_ONCE */
26 #if !defined(EXTRACHECKS) && defined(CONFIG_SCSI_TARGET_EXTRACHECKS)
30 #if !defined(TRACING) && defined(CONFIG_SCSI_TARGET_TRACING)
34 #if !defined(DEBUG) && defined(CONFIG_SCSI_TARGET_DEBUG)
44 #ifndef CONFIG_DEBUG_BUGVERBOSE
46 printk(KERN_CRIT "BUG at %s:%d\n", \
47 __FILE__, __LINE__); \
54 #define sBUG_ON(p) do { \
56 printk(KERN_CRIT "BUG at %s:%d (%s)\n", \
57 __FILE__, __LINE__, #p); \
65 #define sBUG_ON(p) BUG_ON(p)
70 #define WARN_ON_ONCE(condition) ({ \
71 static int __warned; \
72 typeof(condition) __ret_warn_once = (condition); \
74 if (unlikely(__ret_warn_once)) \
79 unlikely(__ret_warn_once); \
84 #define EXTRACHECKS_BUG_ON(a) sBUG_ON(a)
85 #define EXTRACHECKS_WARN_ON(a) WARN_ON(a)
86 #define EXTRACHECKS_WARN_ON_ONCE(a) WARN_ON_ONCE(a)
88 #define EXTRACHECKS_BUG_ON(a)
89 #define EXTRACHECKS_WARN_ON(a)
90 #define EXTRACHECKS_WARN_ON_ONCE(a)
94 //# define LOG_FLAG KERN_DEBUG
95 # define LOG_FLAG KERN_INFO
96 # define INFO_FLAG KERN_INFO
97 # define ERROR_FLAG KERN_INFO
99 # define LOG_FLAG KERN_INFO
100 # define INFO_FLAG KERN_INFO
101 # define ERROR_FLAG KERN_ERR
104 #define CRIT_FLAG KERN_CRIT
108 #define TRACE_NULL 0x00000000
109 #define TRACE_DEBUG 0x00000001
110 #define TRACE_FUNCTION 0x00000002
111 #define TRACE_LINE 0x00000004
112 #define TRACE_PID 0x00000008
113 #define TRACE_ENTRYEXIT 0x00000010
114 #define TRACE_BUFF 0x00000020
115 #define TRACE_MEMORY 0x00000040
116 #define TRACE_SG_OP 0x00000080
117 #define TRACE_OUT_OF_MEM 0x00000100
118 #define TRACE_MINOR 0x00000200 /* less important events */
119 #define TRACE_MGMT 0x00000400
120 #define TRACE_MGMT_MINOR 0x00000800
121 #define TRACE_MGMT_DEBUG 0x00001000
122 #define TRACE_SCSI 0x00002000
123 #define TRACE_SPECIAL 0x00004000 /* filtering debug, etc */
124 #define TRACE_ALL 0xffffffff
125 /* Flags 0xXXXX0000 are local for users */
127 #define PRINT(log_flag, format, args...) printk("%s" format "\n", log_flag, ## args)
128 #define PRINTN(log_flag, format, args...) printk("%s" format, log_flag, ## args)
131 #define __LOG_PREFIX LOG_PREFIX
133 #define __LOG_PREFIX NULL
136 #if defined(DEBUG) || defined(TRACING)
139 #define ___unlikely(a) (a)
141 #define ___unlikely(a) unlikely(a)
144 extern int debug_print_prefix(unsigned long trace_flag, const char *log_level,
145 const char *prefix, const char *func, int line);
146 extern void debug_print_buffer(const char *log_level, const void *data,
149 #define TRACE(trace, format, args...) \
151 if (___unlikely(trace_flag & (trace))) { \
152 char *__tflag = LOG_FLAG; \
153 if (debug_print_prefix(trace_flag, __tflag, __LOG_PREFIX, \
154 __func__, __LINE__) > 0) { \
157 PRINT(NO_FLAG, "%s" format, __tflag, args); \
161 #define PRINT_BUFFER(message, buff, len) \
163 PRINT(NO_FLAG, "%s:", message); \
164 debug_print_buffer(INFO_FLAG, buff, len); \
167 #define PRINT_BUFF_FLAG(flag, message, buff, len) \
169 if (___unlikely(trace_flag & (flag))) { \
170 char *__tflag = INFO_FLAG; \
171 if (debug_print_prefix(trace_flag, __tflag, NULL, __func__,\
175 PRINT(NO_FLAG, "%s%s:", __tflag, message); \
176 debug_print_buffer(INFO_FLAG, buff, len); \
180 #else /* DEBUG || TRACING */
182 #define TRACE(trace, args...) {}
183 #define PRINT_BUFFER(message, buff, len) {}
184 #define PRINT_BUFF_FLAG(flag, message, buff, len) {}
186 #endif /* DEBUG || TRACING */
190 #define __TRACE(trace, format, args...) \
192 if (trace_flag & (trace)) { \
193 char *__tflag = LOG_FLAG; \
194 if (debug_print_prefix(trace_flag, __tflag, NULL, __func__,\
198 PRINT(NO_FLAG, "%s" format, __tflag, args); \
202 #define TRACE_MEM(args...) __TRACE(TRACE_MEMORY, args)
203 #define TRACE_SG(args...) __TRACE(TRACE_SG_OP, args)
204 #define TRACE_DBG(args...) __TRACE(TRACE_DEBUG, args)
205 #define TRACE_DBG_SPECIAL(args...) __TRACE(TRACE_DEBUG|TRACE_SPECIAL, args)
206 #define TRACE_MGMT_DBG(args...) __TRACE(TRACE_MGMT_DEBUG, args)
207 #define TRACE_MGMT_DBG_SPECIAL(args...) __TRACE(TRACE_MGMT_DEBUG|TRACE_SPECIAL, args)
209 #define TRACE_BUFFER(message, buff, len) \
211 if (trace_flag & TRACE_BUFF) { \
212 char *__tflag = LOG_FLAG; \
213 if (debug_print_prefix(trace_flag, __tflag, NULL, __func__, \
217 PRINT(NO_FLAG, "%s%s:", __tflag, message); \
218 debug_print_buffer(LOG_FLAG, buff, len); \
222 #define TRACE_BUFF_FLAG(flag, message, buff, len) \
224 if (trace_flag & (flag)) { \
225 char *__tflag = LOG_FLAG; \
226 if (debug_print_prefix(trace_flag, __tflag, NULL, __func__, \
230 PRINT(NO_FLAG, "%s%s:", __tflag, message); \
231 debug_print_buffer(LOG_FLAG, buff, len); \
235 #define PRINT_LOG_FLAG(log_flag, format, args...) \
237 char *__tflag = log_flag; \
238 if (debug_print_prefix(trace_flag, __tflag, __LOG_PREFIX, \
239 __func__, __LINE__) > 0) { \
242 PRINT(NO_FLAG, "%s" format, __tflag, args); \
245 #define PRINT_ERROR(format, args...) \
247 if (strcmp(ERROR_FLAG, LOG_FLAG)) { \
248 PRINT_LOG_FLAG(LOG_FLAG, "***ERROR*** " format, args); \
250 PRINT_LOG_FLAG(ERROR_FLAG, "***ERROR*** " format, args); \
253 #define PRINT_CRIT_ERROR(format, args...) \
255 /* if (strcmp(CRIT_FLAG, LOG_FLAG)) \
257 PRINT_LOG_FLAG(LOG_FLAG, "***CRITICAL ERROR*** " format, args); \
259 PRINT_LOG_FLAG(CRIT_FLAG, "***CRITICAL ERROR*** " format, args); \
262 #define PRINT_INFO(format, args...) \
264 if (strcmp(INFO_FLAG, LOG_FLAG)) { \
265 PRINT_LOG_FLAG(LOG_FLAG, format, args); \
267 PRINT_LOG_FLAG(INFO_FLAG, format, args); \
270 #define TRACE_ENTRY() \
272 if (trace_flag & TRACE_ENTRYEXIT) { \
273 if (trace_flag & TRACE_PID) { \
274 PRINT(LOG_FLAG, "[%d]: ENTRY %s", current->pid, \
278 PRINT(LOG_FLAG, "ENTRY %s", __func__); \
283 #define TRACE_EXIT() \
285 if (trace_flag & TRACE_ENTRYEXIT) { \
286 if (trace_flag & TRACE_PID) { \
287 PRINT(LOG_FLAG, "[%d]: EXIT %s", current->pid, \
291 PRINT(LOG_FLAG, "EXIT %s", __func__); \
296 #define TRACE_EXIT_RES(res) \
298 if (trace_flag & TRACE_ENTRYEXIT) { \
299 if (trace_flag & TRACE_PID) { \
300 PRINT(LOG_FLAG, "[%d]: EXIT %s: %ld", current->pid, \
301 __func__, (long)(res)); \
304 PRINT(LOG_FLAG, "EXIT %s: %ld", __func__, (long)(res)); \
309 #define TRACE_EXIT_HRES(res) \
311 if (trace_flag & TRACE_ENTRYEXIT) { \
312 if (trace_flag & TRACE_PID) { \
313 PRINT(LOG_FLAG, "[%d]: EXIT %s: 0x%lx", current->pid, \
314 __func__, (long)(res)); \
317 PRINT(LOG_FLAG, "EXIT %s: %lx", __func__, (long)(res)); \
324 #define TRACE_MEM(format, args...) {}
325 #define TRACE_SG(format, args...) {}
326 #define TRACE_DBG(format, args...) {}
327 #define TRACE_DBG_SPECIAL(format, args...) {}
328 #define TRACE_MGMT_DBG(format, args...) {}
329 #define TRACE_MGMT_DBG_SPECIAL(format, args...) {}
330 #define TRACE_BUFFER(message, buff, len) {}
331 #define TRACE_BUFF_FLAG(flag, message, buff, len) {}
332 #define TRACE_ENTRY() {}
333 #define TRACE_EXIT() {}
334 #define TRACE_EXIT_RES(res) {}
335 #define TRACE_EXIT_HRES(res) {}
339 #define PRINT_INFO(format, args...) \
341 PRINT(INFO_FLAG, "%s: " format, LOG_PREFIX, args); \
344 #define PRINT_ERROR(format, args...) \
346 PRINT(ERROR_FLAG, "%s: ***ERROR*** " \
347 format, LOG_PREFIX, args); \
350 #define PRINT_CRIT_ERROR(format, args...) \
352 PRINT(CRIT_FLAG, "%s: ***CRITICAL ERROR*** " \
353 format, LOG_PREFIX, args); \
358 #define PRINT_INFO(format, args...) \
360 PRINT(INFO_FLAG, format, args); \
363 #define PRINT_ERROR(format, args...) \
365 PRINT(ERROR_FLAG, "***ERROR*** " \
369 #define PRINT_CRIT_ERROR(format, args...) \
371 PRINT(CRIT_FLAG, "***CRITICAL ERROR*** " \
375 #endif /* LOG_PREFIX */
379 #if defined(DEBUG) && defined(CONFIG_DEBUG_SLAB)
380 #define SCST_SLAB_FLAGS (SLAB_RED_ZONE | SLAB_POISON)
382 #define SCST_SLAB_FLAGS 0L
385 #endif /* __SCST_DEBUG_H */