blob: 58e46a601decbe505eaaea660c257e8e2a5812c9 [file] [log] [blame]
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07001/*
2 * Debug.h
3 *
4 * Dynamic (runtime) debug framework implementation.
5 * -kaiwan.
6 */
7#ifndef _DEBUG_H
8#define _DEBUG_H
9#include <linux/string.h>
10#define NONE 0xFFFF
11
12typedef enum _BASE_TYPE
13{
14 BCM_BASE_TYPE_DEC,
15 BCM_BASE_TYPE_OCT,
16 BCM_BASE_TYPE_BIN,
17 BCM_BASE_TYPE_HEX,
18 BCM_BASE_TYPE_NONE,
19} BASE_TYPE, *PBASE_TYPE;
20
Stephen Hemminger2564a142010-10-29 08:11:12 -070021void bcm_print_buffer(UINT debug_level, const char *function_name,
22 const char *file_name, int line_number,
23 const unsigned char *buffer, int bufferlen, BASE_TYPE base);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070024
25
26//--------------------------------------------------------------------------------
27
28/* TYPE and SUBTYPE
29 * Define valid TYPE (or category or code-path, however you like to think of it)
30 * and SUBTYPE s.
31 * Type and SubType are treated as bitmasks.
32 */
33/*-----------------BEGIN TYPEs------------------------------------------*/
34#define DBG_TYPE_INITEXIT (1 << 0) // 1
35#define DBG_TYPE_TX (1 << 1) // 2
36#define DBG_TYPE_RX (1 << 2) // 4
37#define DBG_TYPE_OTHERS (1 << 3) // 8
38/*-----------------END TYPEs------------------------------------------*/
39#define NUMTYPES 4 // careful!
40
41/*-----------------BEGIN SUBTYPEs---------------------------------------*/
42
43/*-SUBTYPEs for TX : TYPE is DBG_TYPE_TX -----//
44 Transmit.c ,Arp.c, LeakyBucket.c, And Qos.c
45 total 17 macros */
46// Transmit.c
47#define TX 1
48#define MP_SEND (TX<<0)
49#define NEXT_SEND (TX<<1)
50#define TX_FIFO (TX<<2)
51#define TX_CONTROL (TX<<3)
52
53// Arp.c
54#define IP_ADDR (TX<<4)
55#define ARP_REQ (TX<<5)
56#define ARP_RESP (TX<<6)
57
58// dhcp.c
59//#define DHCP TX
60//#define DHCP_REQ (DHCP<<7)
61
62// Leakybucket.c
63#define TOKEN_COUNTS (TX<<8)
64#define CHECK_TOKENS (TX<<9)
65#define TX_PACKETS (TX<<10)
66#define TIMER (TX<<11)
67
68// Qos.c
69#define QOS TX
70#define QUEUE_INDEX (QOS<<12)
71#define IPV4_DBG (QOS<<13)
72#define IPV6_DBG (QOS<<14)
73#define PRUNE_QUEUE (QOS<<15)
74#define SEND_QUEUE (QOS<<16)
75
76//TX_Misc
77#define TX_OSAL_DBG (TX<<17)
78
79
80//--SUBTYPEs for ------INIT & EXIT---------------------
81/*------------ TYPE is DBG_TYPE_INITEXIT -----//
82DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */
83#define MP 1
84#define DRV_ENTRY (MP<<0)
85#define MP_INIT (MP<<1)
86#define READ_REG (MP<<3)
87#define DISPATCH (MP<<2)
88#define CLAIM_ADAP (MP<<4)
89#define REG_IO_PORT (MP<<5)
90#define INIT_DISP (MP<<6)
91#define RX_INIT (MP<<7)
92
93
94//-SUBTYPEs for --RX----------------------------------
95//------------RX : TYPE is DBG_TYPE_RX -----//
96// Receive.c
97#define RX 1
98#define RX_DPC (RX<<0)
99#define RX_CTRL (RX<<3)
100#define RX_DATA (RX<<4)
101#define MP_RETURN (RX<<1)
102#define LINK_MSG (RX<<2)
103
104
105//-SUBTYPEs for ----OTHER ROUTINES------------------
106//------------OTHERS : TYPE is DBG_TYPE_OTHER -----//
107// HaltnReset,CheckForHang,PnP,Misc,CmHost
108// total 12 macros
109#define OTHERS 1
110// ??ISR.C
111
112#define ISR OTHERS
113#define MP_DPC (ISR<<0)
114
115// HaltnReset.c
116#define HALT OTHERS
117#define MP_HALT (HALT<<1)
118#define CHECK_HANG (HALT<<2)
119#define MP_RESET (HALT<<3)
120#define MP_SHUTDOWN (HALT<<4)
121
122// pnp.c
123#define PNP OTHERS
124#define MP_PNP (PNP<<5)
125
126// Misc.c
127#define MISC OTHERS
128#define DUMP_INFO (MISC<<6)
129#define CLASSIFY (MISC<<7)
130#define LINK_UP_MSG (MISC<<8)
131#define CP_CTRL_PKT (MISC<<9)
132#define DUMP_CONTROL (MISC<<10)
133#define LED_DUMP_INFO (MISC<<11)
134
135// CmHost.c
136#define CMHOST OTHERS
137
138
139#define SERIAL (OTHERS<<12)
140#define IDLE_MODE (OTHERS<<13)
141
142#define WRM (OTHERS<<14)
143#define RDM (OTHERS<<15)
144
145// TODO - put PHS_SEND in Tx PHS_RECEIVE in Rx path ?
146#define PHS_SEND (OTHERS<<16)
147#define PHS_RECIEVE (OTHERS<<17)
148#define PHS_MODULE (OTHERS<<18)
149
150#define INTF_INIT (OTHERS<<19)
151#define INTF_ERR (OTHERS<<20)
152#define INTF_WARN (OTHERS<<21)
153#define INTF_NORM (OTHERS<<22)
154
155#define IRP_COMPLETION (OTHERS<<23)
156#define SF_DESCRIPTOR_CNTS (OTHERS<<24)
157#define PHS_DISPATCH (OTHERS << 25)
158#define OSAL_DBG (OTHERS << 26)
159#define NVM_RW (OTHERS << 27)
160
161#define HOST_MIBS (OTHERS << 28)
162#define CONN_MSG (CMHOST << 29)
163//#define OTHERS_MISC (OTHERS << 29) // ProcSupport.c
164/*-----------------END SUBTYPEs------------------------------------------*/
165
166
167/* Debug level
168 * We have 8 debug levels, in (numerical) increasing order of verbosity.
169 * IMP: Currently implementing ONLY DBG_LVL_ALL , i.e. , all debug prints will
170 * appear (of course, iff global debug flag is ON and we match the Type and SubType).
171 * Finer granularity debug levels are currently not in use, although the feature exists.
172 *
173 * Another way to say this:
174 * All the debug prints currently have 'debug_level' set to DBG_LVL_ALL .
175 * You can compile-time change that to any of the below, if you wish to. However, as of now, there's
176 * no dynamic facility to have the userspace 'TestApp' set debug_level. Slated for future expansion.
177 */
178#define BCM_ALL 7
179#define BCM_LOW 6
180#define BCM_PRINT 5
181#define BCM_NORMAL 4
182#define BCM_MEDIUM 3
183#define BCM_SCREAM 2
184#define BCM_ERR 1
185/* Not meant for developer in debug prints.
186 * To be used to disable all prints by setting the DBG_LVL_CURR to this value */
187#define BCM_NONE 0
188
189/* The current driver logging level.
190 * Everything at this level and (numerically) lower (meaning higher prio)
191 * is logged.
192* Replace 'BCM_ALL' in the DBG_LVL_CURR macro with the logging level desired.
193 * For eg. to set the logging level to 'errors only' use:
194 * #define DBG_LVL_CURR (BCM_ERR)
195 */
196
197#define DBG_LVL_CURR (BCM_ALL)
198#define DBG_LVL_ALL BCM_ALL
199
200/*---Userspace mapping of Debug State.
201 * Delibrately matches that of the Windows driver..
202 * The TestApp's ioctl passes this struct to us.
203 */
204typedef struct
205{
206 unsigned int Subtype, Type;
207 unsigned int OnOff;
208// unsigned int debug_level; /* future expansion */
209} __attribute__((packed)) USER_BCM_DBG_STATE;
210
211//---Kernel-space mapping of Debug State
212typedef struct _S_BCM_DEBUG_STATE {
213 UINT type;
214 /* A bitmap of 32 bits for Subtype per Type.
215 * Valid indexes in 'subtype' array are *only* 1,2,4 and 8,
216 * corresponding to valid Type values. Hence we use the 'Type' field
217 * as the index value, ignoring the array entries 0,3,5,6,7 !
218 */
219 UINT subtype[(NUMTYPES*2)+1];
220 UINT debug_level;
221} S_BCM_DEBUG_STATE;
222/* Instantiated in the Adapter structure */
223/* We'll reuse the debug level parameter to include a bit (the MSB) to indicate whether or not
224 * we want the function's name printed. */
225#define DBG_NO_FUNC_PRINT 1 << 31
226#define DBG_LVL_BITMASK 0xFF
227
228//--- Only for direct printk's; "hidden" to API.
229#define DBG_TYPE_PRINTK 3
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700230
Stephen Hemminger2564a142010-10-29 08:11:12 -0700231#define BCM_DEBUG_PRINT(Adapter, Type, SubType, dbg_level, string, args...) \
232 do { \
233 if (DBG_TYPE_PRINTK == Type) \
234 pr_info("%s:" string "\n", __func__, ##args); \
235 else if (Adapter && \
236 (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \
237 (Type & Adapter->stDebugState.type) && \
238 (SubType & Adapter->stDebugState.subtype[Type])) { \
239 if (dbg_level & DBG_NO_FUNC_PRINT) \
240 printk(KERN_DEBUG string, ##args); \
241 else \
242 printk(KERN_DEBUG "%s:" string "\n", __func__, ##args); \
243 } \
244 } while (0)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700245
246#define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level, buffer, bufferlen) do { \
Stephen Hemminger2564a142010-10-29 08:11:12 -0700247 if (DBG_TYPE_PRINTK == Type || \
248 (Adapter && \
249 (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \
250 (Type & Adapter->stDebugState.type) && \
251 (SubType & Adapter->stDebugState.subtype[Type]))) \
252 bcm_print_buffer(dbg_level, __func__, __FILE__, __LINE__, \
253 buffer, bufferlen, BCM_BASE_TYPE_HEX); \
254} while(0)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700255
256
257#define BCM_SHOW_DEBUG_BITMAP(Adapter) do { \
258 int i; \
259 for (i=0; i<(NUMTYPES*2)+1; i++) { \
260 if ((i == 1) || (i == 2) || (i == 4) || (i == 8)) { \
261 /* CAUTION! Forcefully turn on ALL debug paths and subpaths! \
262 Adapter->stDebugState.subtype[i] = 0xffffffff; */ \
263 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "subtype[%d] = 0x%08x\n", \
264 i, Adapter->stDebugState.subtype[i]); \
265 } \
266 } \
267} while (0)
268
269#endif
270