Revert "acx_pci_s_up(): enable IRQs only after the device is up"
[acx-mac80211.git] / log.c
blobf093ec9017e90a8e66bee1713d60d9c788fe5d2f
1 /*
2 * log.c: logging framework.
4 * This file should disappear some day, when the driver is known to work
5 * reliably. Until then, this will contain all logging routines used everywhere
6 * in the code.
8 * Copyright (c) 2008, the ACX100 project (http://acx100.sourceforge.net).
10 * See the README file for licensing conditions.
12 #include <linux/jiffies.h>
14 #include "acx_config.h"
15 #include "acx_log.h"
18 * Forward declarations
21 static void acx_dump_bytes(const char *prefix, const void *data,
22 ssize_t len);
24 static const char *const printk_levels[MAX_LOG_LEVEL + 1] = {
25 KERN_WARNING,
26 KERN_INFO,
27 KERN_DEBUG
30 /**
31 * acx_log: the logging function
32 * @level: what level to log (LOG_WARNING, LOG_INFO or LOG_DEBUG).
33 * @what: what channel to log (any of the L_* values defined in acx_log.h).
34 * @fmt: the format string, and its arguments if any.
38 void acx_log(int level, int what, const char *fmt, ...)
40 va_list args;
41 const char *printk_level;
43 if (level > ACX_LOG_LEVEL)
44 return;
45 if (!(what & ACX_DEFAULT_MSG))
46 return;
49 * FIXME: this shouldn't be necessary, but I don't rely on luck
51 if (level > MAX_LOG_LEVEL)
52 level = MAX_LOG_LEVEL;
54 printk_level = printk_levels[level];
55 va_start(args, fmt);
57 printk("%sacx: ", printk_level);
58 vprintk(fmt, args);
59 va_end(args);
61 return;
64 /**
65 * acx_log_dump(): logs a message, and dumps a buffer. Basically, this is
66 * acx_log(), and a call to acx_dump_bytes() below.
67 * @level: see acx_log().
68 * @what: see acx_log().
69 * @buf: the buffer to dump.
70 * @buflen: the length of the buffer to dump.
73 void acx_log_dump(int level, int what, const void *buf, ssize_t buflen,
74 const char *fmt, ...)
76 va_list args;
77 const char *printk_level;
79 if (level > ACX_LOG_LEVEL)
80 return;
81 if (!(what & ACX_DEFAULT_MSG))
82 return;
85 * FIXME: this shouldn't be necessary, but I don't rely on luck
87 if (level > MAX_LOG_LEVEL)
88 level = MAX_LOG_LEVEL;
90 printk_level = printk_levels[level];
91 va_start(args, fmt);
93 acx_log(level, what, fmt, args);
94 acx_dump_bytes(printk_level, buf, buflen);
96 /**
97 * acx_log_ratelimited: like acx_log(), but rate limited via printk_ratelimit().
99 void acx_log_ratelimited(int level, int what, const char *fmt, ...)
101 va_list args;
103 if (printk_ratelimit())
104 return;
106 va_start(args, fmt);
107 acx_log(level, what, fmt, args);
108 va_end(args);
112 * acx_dump_bytes: hex dump of a buffer
113 * @printk_prefix: the KERN_* char constant, passed to this function by
114 * acx_log().
115 * @buf: the buffer to dump.
116 * @buflen: the length of the buffer.
118 * This function is static: it's not supposed to be called from anywhere else
119 * than this file. There is no "acx:" prefix here.
121 static void acx_dump_bytes(const char *printk_prefix, const void *data,
122 ssize_t len)
124 const u8 *ptr = (const u8 *)data;
125 unsigned int size = 0;
127 * buf holds:
128 * - the printk prefix (3 bytes);
129 * - the size printed as "0x%08X" (10 bytes);
130 * - the following semicolon (1 bytes);
131 * - 16 bytes printed as " %02X" (48 bytes);
132 * - the final '\0' (1 byte).
134 char buf[63], *p;
136 printk("%s--- BEGIN DUMP (%d bytes) ---\n", printk_prefix,
137 (int) len);
139 if (len <= 0)
140 return;
142 goto inside;
144 do {
145 p += sprintf(p, " %02X", *ptr);
146 size++, ptr++;
147 if (size % 16)
148 continue;
149 printk("%s\n", buf);
150 inside:
151 p = buf;
152 p += sprintf(p, "%s0x%08X:", printk_prefix, size);
153 } while (size < len);
155 if (size % 16)
156 printk("%s\n", buf);
158 printk("%s--- END DUMP ---\n", printk_prefix);
161 * Only in case of heavy debugging
164 #if ACX_LOG_LEVEL == 2
167 * __function_enter_exit: display entering/exiting of a function
168 * @fname: the function name.
169 * @enter_exit: 0 on enter, 1 on exit, 2 on exit with return value to be
170 * printed.
171 * @retcode: the return code to be printed if enter_exit is 2.
174 #define DEBUG_TSC 0
176 #if DEBUG_TSC
177 #define TIMESTAMP(d) unsigned long d; rdtscl(d)
178 #else
179 #define TIMESTAMP(d) unsigned long d = jiffies
180 #endif
183 * MAX_INDENT is the size of the spaces[] string below.
185 #define MAX_INDENT 10
186 void __function_enter_exit(const char *fname, int enter_exit,
187 int retcode)
189 static int indent = 0;
190 static const char spaces[] = " ";
191 const char *p = spaces + MAX_INDENT;
193 * Note that we MUST "declare" TIMESTAMP last: in case DEBUG_TSC is set,
194 * an rdtscl() is done on the argument, and, well, that's C.
196 TIMESTAMP(stamp);
197 stamp = stamp % 1000000;
199 switch (enter_exit) {
200 case __FUNCTION_ENTER:
201 if (indent < MAX_INDENT)
202 indent++;
203 break;
204 case __FUNCTION_EXIT:
205 case __FUNCTION_EXIT_WITHARG:
206 /* Nothing */
207 break;
208 default: /* Meh? */
209 return;
212 p -= indent;
214 switch (enter_exit) {
215 case __FUNCTION_ENTER:
216 acx_log(LOG_DEBUG, L_FUNC, "%08ld %s-> %s\n",
217 stamp, p, fname);
218 break;
219 case __FUNCTION_EXIT:
220 acx_log(LOG_DEBUG, L_FUNC, "%08ld %s<- %s\n",
221 stamp, p, fname);
222 break;
223 case __FUNCTION_EXIT_WITHARG:
224 acx_log(LOG_DEBUG, L_FUNC, "%08ld %s<- %s: %08X\n",
225 stamp, p, fname, retcode);
229 * The below test is enough: we already sanitized away illegal values of
230 * enter_exit at the beginning.
232 if (enter_exit != __FUNCTION_ENTER)
233 indent--;
237 #endif /* ACX_LOG_LEVEL == 2 */