]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/dev/bxe/bxe_debug.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / dev / bxe / bxe_debug.h
1 /*-
2  * Copyright (c) 2007-2011 Broadcom Corporation. All rights reserved.
3  *
4  *    Gary Zambrano <zambrano@broadcom.com>
5  *    David Christensen <davidch@broadcom.com>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of Broadcom Corporation nor the name of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written consent.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30  * THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33  /*$FreeBSD$*/
34
35 #ifndef _BXE_DEBUG_H
36 #define _BXE_DEBUG_H
37
38 extern uint32_t bxe_debug;
39
40 /*
41  * Debugging macros and definitions.
42  */
43
44 #define BXE_CP_LOAD                     0x00000001
45 #define BXE_CP_SEND                     0x00000002
46 #define BXE_CP_RECV                     0x00000004
47 #define BXE_CP_INTR                     0x00000008
48 #define BXE_CP_UNLOAD                   0x00000010
49 #define BXE_CP_RESET                    0x00000020
50 #define BXE_CP_IOCTL                    0x00000040
51 #define BXE_CP_STATS                    0x00000080
52 #define BXE_CP_MISC                     0x00000100
53 #define BXE_CP_PHY                      0x00000200
54 #define BXE_CP_RAMROD                   0x00000400
55 #define BXE_CP_NVRAM                    0x00000800
56 #define BXE_CP_REGS                     0x00001000
57 #define BXE_CP_TPA                      0x00002000
58 #define BXE_CP_ALL                      0x00FFFFFF
59 #define BXE_CP_MASK                     0x00FFFFFF
60
61 #define BXE_LEVEL_FATAL                 0x00000000
62 #define BXE_LEVEL_WARN                  0x01000000
63 #define BXE_LEVEL_INFO                  0x02000000
64 #define BXE_LEVEL_VERBOSE               0x03000000
65 #define BXE_LEVEL_EXTREME               0x04000000
66 #define BXE_LEVEL_INSANE                0x05000000
67
68 #define BXE_LEVEL_MASK                  0xFF000000
69
70 #define BXE_WARN_LOAD                   (BXE_CP_LOAD | BXE_LEVEL_WARN)
71 #define BXE_INFO_LOAD                   (BXE_CP_LOAD | BXE_LEVEL_INFO)
72 #define BXE_VERBOSE_LOAD                (BXE_CP_LOAD | BXE_LEVEL_VERBOSE)
73 #define BXE_EXTREME_LOAD                (BXE_CP_LOAD | BXE_LEVEL_EXTREME)
74 #define BXE_INSANE_LOAD                 (BXE_CP_LOAD | BXE_LEVEL_INSANE)
75
76 #define BXE_WARN_SEND                   (BXE_CP_SEND | BXE_LEVEL_WARN)
77 #define BXE_INFO_SEND                   (BXE_CP_SEND | BXE_LEVEL_INFO)
78 #define BXE_VERBOSE_SEND                (BXE_CP_SEND | BXE_LEVEL_VERBOSE)
79 #define BXE_EXTREME_SEND                (BXE_CP_SEND | BXE_LEVEL_EXTREME)
80 #define BXE_INSANE_SEND                 (BXE_CP_SEND | BXE_LEVEL_INSANE)
81
82 #define BXE_WARN_RECV                   (BXE_CP_RECV | BXE_LEVEL_WARN)
83 #define BXE_INFO_RECV                   (BXE_CP_RECV | BXE_LEVEL_INFO)
84 #define BXE_VERBOSE_RECV                (BXE_CP_RECV | BXE_LEVEL_VERBOSE)
85 #define BXE_EXTREME_RECV                (BXE_CP_RECV | BXE_LEVEL_EXTREME)
86 #define BXE_INSANE_RECV                 (BXE_CP_RECV | BXE_LEVEL_INSANE)
87
88 #define BXE_WARN_INTR                   (BXE_CP_INTR | BXE_LEVEL_WARN)
89 #define BXE_INFO_INTR                   (BXE_CP_INTR | BXE_LEVEL_INFO)
90 #define BXE_VERBOSE_INTR                (BXE_CP_INTR | BXE_LEVEL_VERBOSE)
91 #define BXE_EXTREME_INTR                (BXE_CP_INTR | BXE_LEVEL_EXTREME)
92 #define BXE_INSANE_INTR                 (BXE_CP_INTR | BXE_LEVEL_INSANE)
93
94 #define BXE_WARN_UNLOAD                 (BXE_CP_UNLOAD | BXE_LEVEL_WARN)
95 #define BXE_INFO_UNLOAD                 (BXE_CP_UNLOAD | BXE_LEVEL_INFO)
96 #define BXE_VERBOSE_UNLOAD              (BXE_CP_UNLOAD | BXE_LEVEL_VERBOSE)
97 #define BXE_EXTREME_UNLOAD              (BXE_CP_UNLOAD | BXE_LEVEL_EXTREME)
98 #define BXE_INSANE_UNLOAD               (BXE_CP_UNLOAD | BXE_LEVEL_INSANE)
99
100 #define BXE_WARN_RESET                  (BXE_CP_RESET | BXE_LEVEL_WARN)
101 #define BXE_INFO_RESET                  (BXE_CP_RESET | BXE_LEVEL_INFO)
102 #define BXE_VERBOSE_RESET               (BXE_CP_RESET | BXE_LEVEL_VERBOSE)
103 #define BXE_EXTREME_RESET               (BXE_CP_RESET | BXE_LEVEL_EXTREME)
104 #define BXE_INSANE_RESET                (BXE_CP_RESET | BXE_LEVEL_INSANE)
105
106 #define BXE_WARN_IOCTL                  (BXE_CP_IOCTL | BXE_LEVEL_WARN)
107 #define BXE_INFO_IOCTL                  (BXE_CP_IOCTL | BXE_LEVEL_INFO)
108 #define BXE_VERBOSE_IOCTL               (BXE_CP_IOCTL | BXE_LEVEL_VERBOSE)
109 #define BXE_EXTREME_IOCTL               (BXE_CP_IOCTL | BXE_LEVEL_EXTREME)
110 #define BXE_INSANE_IOCTL                (BXE_CP_IOCTL | BXE_LEVEL_INSANE)
111
112 #define BXE_WARN_STATS                  (BXE_CP_STATS | BXE_LEVEL_WARN)
113 #define BXE_INFO_STATS                  (BXE_CP_STATS | BXE_LEVEL_INFO)
114 #define BXE_VERBOSE_STATS               (BXE_CP_STATS | BXE_LEVEL_VERBOSE)
115 #define BXE_EXTREME_STATS               (BXE_CP_STATS | BXE_LEVEL_EXTREME)
116 #define BXE_INSANE_STATS                (BXE_CP_STATS | BXE_LEVEL_INSANE)
117
118 #define BXE_WARN_MISC                   (BXE_CP_MISC | BXE_LEVEL_WARN)
119 #define BXE_INFO_MISC                   (BXE_CP_MISC | BXE_LEVEL_INFO)
120 #define BXE_VERBOSE_MISC                (BXE_CP_MISC | BXE_LEVEL_VERBOSE)
121 #define BXE_EXTREME_MISC                (BXE_CP_MISC | BXE_LEVEL_EXTREME)
122 #define BXE_INSANE_MISC                 (BXE_CP_MISC | BXE_LEVEL_INSANE)
123
124 #define BXE_WARN_PHY                    (BXE_CP_PHY | BXE_LEVEL_WARN)
125 #define BXE_INFO_PHY                    (BXE_CP_PHY | BXE_LEVEL_INFO)
126 #define BXE_VERBOSE_PHY                 (BXE_CP_PHY | BXE_LEVEL_VERBOSE)
127 #define BXE_EXTREME_PHY                 (BXE_CP_PHY | BXE_LEVEL_EXTREME)
128 #define BXE_INSANE_PHY                  (BXE_CP_PHY | BXE_LEVEL_INSANE)
129
130 #define BXE_WARN_RAMROD                 (BXE_CP_RAMROD | BXE_LEVEL_WARN)
131 #define BXE_INFO_RAMROD                 (BXE_CP_RAMROD | BXE_LEVEL_INFO)
132 #define BXE_VERBOSE_RAMROD              (BXE_CP_RAMROD | BXE_LEVEL_VERBOSE)
133 #define BXE_EXTREME_RAMROD              (BXE_CP_RAMROD | BXE_LEVEL_EXTREME)
134 #define BXE_INSANE_RAMROD               (BXE_CP_RAMROD | BXE_LEVEL_INSANE)
135
136 #define BXE_WARN_NVRAM                  (BXE_CP_NVRAM | BXE_LEVEL_WARN)
137 #define BXE_INFO_NVRAM                  (BXE_CP_NVRAM | BXE_LEVEL_INFO)
138 #define BXE_VERBOSE_NVRAM               (BXE_CP_NVRAM | BXE_LEVEL_VERBOSE)
139 #define BXE_EXTREME_NVRAM               (BXE_CP_NVRAM | BXE_LEVEL_EXTREME)
140 #define BXE_INSANE_NVRAM                (BXE_CP_NVRAM | BXE_LEVEL_INSANE)
141
142 #define BXE_WARN_REGS                   (BXE_CP_REGS | BXE_LEVEL_WARN)
143 #define BXE_INFO_REGS                   (BXE_CP_REGS | BXE_LEVEL_INFO)
144 #define BXE_VERBOSE_REGS                (BXE_CP_REGS | BXE_LEVEL_VERBOSE)
145 #define BXE_EXTREME_REGS                (BXE_CP_REGS | BXE_LEVEL_EXTREME)
146 #define BXE_INSANE_REGS                 (BXE_CP_REGS | BXE_LEVEL_INSANE)
147
148 #define BXE_WARN_TPA                    (BXE_CP_TPA | BXE_LEVEL_WARN)
149 #define BXE_INFO_TPA                    (BXE_CP_TPA | BXE_LEVEL_INFO)
150 #define BXE_VERBOSE_TPA                 (BXE_CP_TPA | BXE_LEVEL_VERBOSE)
151 #define BXE_EXTREME_TPA                 (BXE_CP_TPA | BXE_LEVEL_EXTREME)
152 #define BXE_INSANE_TPA                  (BXE_CP_TPA | BXE_LEVEL_INSANE)
153
154 #define BXE_FATAL                       (BXE_CP_ALL | BXE_LEVEL_FATAL)
155 #define BXE_WARN                        (BXE_CP_ALL | BXE_LEVEL_WARN)
156 #define BXE_INFO                        (BXE_CP_ALL | BXE_LEVEL_INFO)
157 #define BXE_VERBOSE                     (BXE_CP_ALL | BXE_LEVEL_VERBOSE)
158 #define BXE_EXTREME                     (BXE_CP_ALL | BXE_LEVEL_EXTREME)
159 #define BXE_INSANE                      (BXE_CP_ALL | BXE_LEVEL_INSANE)
160
161 #define BXE_CODE_PATH(cp)               ((cp & BXE_CP_MASK) & bxe_debug)
162 #define BXE_MSG_LEVEL(lv)               ((lv & BXE_LEVEL_MASK) <= (bxe_debug & BXE_LEVEL_MASK))
163 #define BXE_LOG_MSG(m)                  (BXE_CODE_PATH(m) && BXE_MSG_LEVEL(m))
164
165
166 #ifdef BXE_DEBUG
167
168 /* Print a message based on the logging level and code path. */
169 #define DBPRINT(sc, level, format, args...)                             \
170         do {                                                            \
171                 if (BXE_LOG_MSG(level)) {                               \
172                         device_printf(sc->dev, format, ## args);        \
173                 }                                                       \
174         } while (0)
175
176 /* Runs a particular command when debugging is enabled. */
177 #define DBRUN(args...)                                                  \
178         do {                                                            \
179                 args;                                                   \
180         } while (0)
181
182 /* Runs a particular command based on the logging level. */
183 #define DBRUNLV(level, args...)                                         \
184         if (BXE_MSG_LEVEL(level)) {                                     \
185                 args;                                                   \
186         }
187
188 /* Runs a particular command based on the code path. */
189 #define DBRUNCP(cp, args...)                                            \
190         if (BXE_CODE_PATH(cp)) {                                        \
191                 args;                                                   \
192         }
193
194 /* Runs a particular command based on a condition. */
195 #define DBRUNIF(cond, args...)                                          \
196         if (cond) {                                                     \
197                 args;                                                   \
198         }
199
200 /* Runs a particular command based on the logging level and code path. */
201 #define DBRUNMSG(msg, args...)                                          \
202         if (BXE_LOG_MSG(msg)) {                                         \
203                 args;                                                   \
204         }
205
206 /* Announces function entry. */
207 #define DBENTER(cond)                                                   \
208         DBPRINT(sc, (cond), "%s(enter:%d)\n", __FUNCTION__, curcpu)
209
210 /* Announces function exit. */
211 #define DBEXIT(cond)                                                    \
212         DBPRINT(sc, (cond), "%s(exit:%d)\n", __FUNCTION__, curcpu)
213
214 /* Needed for random() function which is only used in debugging. */
215 #include <sys/random.h>
216
217 /* Returns FALSE in "defects" per 2^31 - 1 calls, otherwise returns TRUE. */
218 #define DB_RANDOMFALSE(defects)        (random() > defects)
219 #define DB_OR_RANDOMFALSE(defects)  || (random() > defects)
220 #define DB_AND_RANDOMFALSE(defects) && (random() > defects)
221
222 /* Returns TRUE in "defects" per 2^31 - 1 calls, otherwise returns FALSE. */
223 #define DB_RANDOMTRUE(defects)         (random() < defects)
224 #define DB_OR_RANDOMTRUE(defects)   || (random() < defects)
225 #define DB_AND_RANDOMTRUE(defects)  && (random() < defects)
226
227 #else
228
229 #define DBPRINT(...)
230 #define DBRUN(...)
231 #define DBRUNLV(...)
232 #define DBRUNCP(...)
233 #define DBRUNIF(...)
234 #define DBRUNMSG(...)
235 #define DBENTER(...)
236 #define DBENTER_UNLOCKED(...)
237 #define DBEXIT(...)
238 #define DBEXIT_UNLOCKED(...)
239 #define DB_RANDOMFALSE(...)
240 #define DB_OR_RANDOMFALSE(...)
241 #define DB_AND_RANDOMFALSE(...)
242 #define DB_RANDOMTRUE(...)
243 #define DB_OR_RANDOMTRUE(...)
244 #define DB_AND_RANDOMTRUE(...)
245
246 #endif /* BXE_DEBUG */
247
248 /* Generic bit decoding for printf("%b"). */
249 #define BXE_DWORD_PRINTFB       \
250         "\020"                                  \
251         "\40b31"                                \
252         "\37b30"                                \
253         "\36b29"                                \
254         "\35b28"                                \
255         "\34b27"                                \
256         "\33b26"                                \
257         "\32b25"                                \
258         "\31b24"                                \
259         "\30b23"                                \
260         "\27b22"                                \
261         "\26b21"                                \
262         "\25b20"                                \
263         "\24b19"                                \
264         "\23b18"                                \
265         "\22b17"                                \
266         "\21b16"                                \
267         "\20b15"                                \
268         "\17b14"                                \
269         "\16b13"                                \
270         "\15b12"                                \
271         "\14b11"                                \
272         "\13b10"                                \
273         "\12b9"                                 \
274         "\11b8"                                 \
275         "\10b7"                                 \
276         "\07b6"                                 \
277         "\06b5"                                 \
278         "\05b4"                                 \
279         "\04b3"                                 \
280         "\03b2"                                 \
281         "\02b1"                                 \
282         "\01b0"
283
284 /* Supported link settings bit decoding for printf("%b"). */
285 #define BXE_SUPPORTED_PRINTFB   \
286         "\020"                                          \
287         "\040b31"                                       \
288         "\037b30"                                       \
289         "\036b29"                                       \
290         "\035b28"                                       \
291         "\034b27"                                       \
292         "\033b26"                                       \
293         "\032b25"                                       \
294         "\031b24"                                       \
295         "\030b23"                                       \
296         "\027b22"                                       \
297         "\026b21"                                       \
298         "\025b20"                                       \
299         "\024b19"                                       \
300         "\023b18"                                       \
301         "\022b17"                                       \
302         "\02110000BaseT-Full"           \
303         "\0202500BaseX-Full"            \
304         "\017b14"                                       \
305         "\016b13"                                       \
306         "\015b12"                                       \
307         "\014Pause"                                     \
308         "\013Asym-Pause"                        \
309         "\012Autoneg"                           \
310         "\011Fiber"                                     \
311         "\010TP"                                        \
312         "\0071000BaseT-Full"            \
313         "\0061000BaseT-Half"            \
314         "\005100BaseTX-Full"            \
315         "\004100BaseTX-Half"            \
316         "\00310BaseT-Full"                      \
317         "\00210BaseT-Half"                      \
318         "\001b0"
319
320 /* Transmit BD TCP flags bit decoding for printf("%b"). */
321 #define BXE_ETH_TX_PARSE_BD_TCP_FLAGS_PRINTFB   \
322         "\020"                                                                          \
323         "\10CWR"                                                                        \
324         "\07ECE"                                                                        \
325         "\06URG"                                                                        \
326         "\05ACK"                                                                        \
327         "\04PSH"                                                                        \
328         "\03RST"                                                                        \
329         "\02SYN"                                                                        \
330         "\01FIN"
331
332 /* Parsing BD global data bit decoding for printf("%b"). */
333 #define BXE_ETH_TX_PARSE_BD_GLOBAL_DATA_PRINTFB \
334         "\020"                                                                          \
335         "\10NS"                                                                         \
336         "\07LLC_SNAP"                                                           \
337         "\06PSEUDO_CS_WO_LEN"                                           \
338         "\05CS_ANY"
339
340 /* Transmit BD flags bit decoding for printf("%b"). */
341 #define BXE_ETH_TX_BD_FLAGS_PRINTFB                             \
342         "\020"                                                                          \
343         "\10IPv6"                                                                       \
344         "\07LSO"                                                                        \
345         "\06HDR_POOL"                                                           \
346         "\05START"                                                                      \
347         "\04END"                                                                        \
348         "\03TCP_CSUM"                                                           \
349         "\02IP_CSUM"                                                            \
350         "\01VLAN"
351
352 /* Receive CQE error flags bit decoding for printf("%b"). */
353 #define BXE_ETH_FAST_PATH_RX_CQE_ERROR_FLAGS_PRINTFB    \
354         "\020"                                                                                          \
355         "\10RSRVD"                                                                                      \
356         "\07RSRVD"                                                                                      \
357         "\06END_FLAG"                                                                           \
358         "\05START_FLAG"                                                                         \
359         "\04L4_BAD_XSUM"                                                                        \
360         "\03IP_BAD_XSUM"                                                                        \
361         "\02PHY_DECODE_ERR"                                                                     \
362         "\01SP"
363
364 #endif /* _BXE_DEBUG_H */