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