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