Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / drivers / char / ftape / lowlevel / ftape-tracing.h
1 #ifndef _FTAPE_TRACING_H
2 #define _FTAPE_TRACING_H
3
4 /*
5  * Copyright (C) 1994-1996 Bas Laarhoven,
6  *           (C) 1996-1997 Claus-Justus Heine.
7
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2, or (at your option)
11  any later version.
12
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; see the file COPYING.  If not, write to
20  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22  *
23  * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-tracing.h,v $
24  * $Revision: 1.2 $
25  * $Date: 1997/10/05 19:18:28 $
26  *
27  *      This file contains definitions that eases the debugging of the
28  *      QIC-40/80/3010/3020 floppy-tape driver "ftape" for Linux.
29  */
30
31 #include <linux/kernel.h>
32
33 /*
34  *  Be very careful with TRACE_EXIT and TRACE_ABORT.
35  *
36  *  if (something) TRACE_EXIT error;
37  *
38  *  will NOT work. Use
39  *
40  *  if (something) {
41  *    TRACE_EXIT error;
42  *  }
43  *
44  *  instead. Maybe a bit dangerous, but save lots of lines of code.
45  */
46
47 #define LL_X "%d/%d KB"
48 #define LL(x) (unsigned int)((__u64)(x)>>10), (unsigned int)((x)&1023)
49
50 typedef enum {
51         ft_t_nil = -1,
52         ft_t_bug,
53         ft_t_err,
54         ft_t_warn,
55         ft_t_info,
56         ft_t_noise,
57         ft_t_flow,
58         ft_t_fdc_dma,
59         ft_t_data_flow,
60         ft_t_any
61 } ft_trace_t;
62
63 #ifdef  CONFIG_FT_NO_TRACE_AT_ALL
64 /*  the compiler will optimize away most TRACE() macros
65  */
66 #define FT_TRACE_TOP_LEVEL      ft_t_bug
67 #define TRACE_FUN(level)        do {} while(0)
68 #define TRACE_EXIT              return
69 #define TRACE(l, m, i...)                                               \
70 {                                                                       \
71         if ((ft_trace_t)(l) == FT_TRACE_TOP_LEVEL) {                    \
72                 printk(KERN_INFO"ftape%s(%s):\n"                        \
73                        KERN_INFO m".\n" ,__FILE__, __FUNCTION__ , ##i); \
74         }                                                               \
75 }
76 #define SET_TRACE_LEVEL(l)      if ((l) == (l)) do {} while(0)
77 #define TRACE_LEVEL             FT_TRACE_TOP_LEVEL
78
79 #else
80
81 #ifdef CONFIG_FT_NO_TRACE
82 /*  the compiler will optimize away many TRACE() macros
83  *  the ftape_simple_trace_call() function simply increments 
84  *  the function nest level.
85  */ 
86 #define FT_TRACE_TOP_LEVEL      ft_t_warn
87 #define TRACE_FUN(level)        ftape_function_nest_level++
88 #define TRACE_EXIT              ftape_function_nest_level--; return
89
90 #else
91 #ifdef CONFIG_FT_FULL_DEBUG
92 #define FT_TRACE_TOP_LEVEL ft_t_any
93 #else
94 #define FT_TRACE_TOP_LEVEL ft_t_flow
95 #endif
96 #define TRACE_FUN(level)                                        \
97         const ft_trace_t _tracing = level;                      \
98         if (ftape_tracing >= (ft_trace_t)(level) &&             \
99             (ft_trace_t)(level) <= FT_TRACE_TOP_LEVEL)          \
100                 ftape_trace_call(__FILE__, __FUNCTION__);       \
101         ftape_function_nest_level ++;
102
103 #define TRACE_EXIT                                              \
104         --ftape_function_nest_level;                            \
105         if (ftape_tracing >= (ft_trace_t)(_tracing) &&          \
106             (ft_trace_t)(_tracing) <= FT_TRACE_TOP_LEVEL)       \
107                 ftape_trace_exit(__FILE__, __FUNCTION__);       \
108         return
109
110 #endif
111
112 #define TRACE(l, m, i...)                                       \
113 {                                                               \
114         if (ftape_tracing >= (ft_trace_t)(l) &&                 \
115             (ft_trace_t)(l) <= FT_TRACE_TOP_LEVEL) {            \
116                 ftape_trace_log(__FILE__, __FUNCTION__);        \
117                 printk(m".\n" ,##i);                            \
118         }                                                       \
119 }
120
121 #define SET_TRACE_LEVEL(l)                              \
122 {                                                       \
123         if ((ft_trace_t)(l) <= FT_TRACE_TOP_LEVEL) {    \
124                 ftape_tracing = (ft_trace_t)(l);        \
125         } else {                                        \
126                 ftape_tracing = FT_TRACE_TOP_LEVEL;     \
127         }                                               \
128 }
129 #define TRACE_LEVEL                                                          \
130 ((ftape_tracing <= FT_TRACE_TOP_LEVEL) ? ftape_tracing : FT_TRACE_TOP_LEVEL)
131
132
133 /*      Global variables declared in tracing.c
134  */
135 extern ft_trace_t ftape_tracing;  /* sets default level */
136 extern int ftape_function_nest_level;
137
138 /*      Global functions declared in tracing.c
139  */
140 extern void ftape_trace_call(const char *file, const char *name);
141 extern void ftape_trace_exit(const char *file, const char *name);
142 extern void ftape_trace_log (const char *file, const char *name);
143
144 #endif /* !defined(CONFIG_FT_NO_TRACE_AT_ALL) */
145
146 /*
147  *   Abort with a message.
148  */
149 #define TRACE_ABORT(res, i...)                  \
150 {                                               \
151         TRACE(i);                               \
152         TRACE_EXIT res;                         \
153 }
154
155 /*   The following transforms the common "if(result < 0) ... " into a
156  *   one-liner.
157  */
158 #define _TRACE_CATCH(level, fun, action)                                \
159 {                                                                       \
160         int _res = (fun);                                               \
161         if (_res < 0) {                                                 \
162                 do { action /* */ ; } while(0);                         \
163                 TRACE_ABORT(_res, level, "%s failed: %d", #fun, _res);  \
164         }                                                               \
165 }
166
167 #define TRACE_CATCH(fun, fail) _TRACE_CATCH(ft_t_err, fun, fail)
168
169 /*  Abort the current function when signalled. This doesn't belong here,
170  *  but rather into ftape-rw.h (maybe)
171  */
172 #define FT_SIGNAL_EXIT(sig_mask)                                        \
173         if (sigtestsetmask(&current->pending.signal, sig_mask)) {       \
174                 TRACE_ABORT(-EINTR,                                     \
175                             ft_t_warn,                                  \
176                             "interrupted by non-blockable signal");     \
177         }
178
179 #endif /* _FTAPE_TRACING_H */