4 * Dynamic (runtime) debug framework implementation.
9 #include <linux/string.h>
12 typedef enum _BASE_TYPE
19 } BASE_TYPE, *PBASE_TYPE;
21 void 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);
26 //--------------------------------------------------------------------------------
29 * Define valid TYPE (or category or code-path, however you like to think of it)
31 * Type and SubType are treated as bitmasks.
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!
41 /*-----------------BEGIN SUBTYPEs---------------------------------------*/
43 /*-SUBTYPEs for TX : TYPE is DBG_TYPE_TX -----//
44 Transmit.c ,Arp.c, LeakyBucket.c, And Qos.c
48 #define MP_SEND (TX<<0)
49 #define NEXT_SEND (TX<<1)
50 #define TX_FIFO (TX<<2)
51 #define TX_CONTROL (TX<<3)
54 #define IP_ADDR (TX<<4)
55 #define ARP_REQ (TX<<5)
56 #define ARP_RESP (TX<<6)
60 //#define DHCP_REQ (DHCP<<7)
63 #define TOKEN_COUNTS (TX<<8)
64 #define CHECK_TOKENS (TX<<9)
65 #define TX_PACKETS (TX<<10)
66 #define TIMER (TX<<11)
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)
77 #define TX_OSAL_DBG (TX<<17)
80 //--SUBTYPEs for ------INIT & EXIT---------------------
81 /*------------ TYPE is DBG_TYPE_INITEXIT -----//
82 DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */
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)
94 //-SUBTYPEs for --RX----------------------------------
95 //------------RX : TYPE is DBG_TYPE_RX -----//
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)
105 //-SUBTYPEs for ----OTHER ROUTINES------------------
106 //------------OTHERS : TYPE is DBG_TYPE_OTHER -----//
107 // HaltnReset,CheckForHang,PnP,Misc,CmHost
113 #define MP_DPC (ISR<<0)
117 #define MP_HALT (HALT<<1)
118 #define CHECK_HANG (HALT<<2)
119 #define MP_RESET (HALT<<3)
120 #define MP_SHUTDOWN (HALT<<4)
124 #define MP_PNP (PNP<<5)
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)
136 #define CMHOST OTHERS
139 #define SERIAL (OTHERS<<12)
140 #define IDLE_MODE (OTHERS<<13)
142 #define WRM (OTHERS<<14)
143 #define RDM (OTHERS<<15)
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)
150 #define INTF_INIT (OTHERS<<19)
151 #define INTF_ERR (OTHERS<<20)
152 #define INTF_WARN (OTHERS<<21)
153 #define INTF_NORM (OTHERS<<22)
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)
161 #define HOST_MIBS (OTHERS << 28)
162 #define CONN_MSG (CMHOST << 29)
163 //#define OTHERS_MISC (OTHERS << 29) // ProcSupport.c
164 /*-----------------END SUBTYPEs------------------------------------------*/
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.
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.
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 */
189 /* The current driver logging level.
190 * Everything at this level and (numerically) lower (meaning higher prio)
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)
197 #define DBG_LVL_CURR (BCM_ALL)
198 #define DBG_LVL_ALL BCM_ALL
200 /*---Userspace mapping of Debug State.
201 * Delibrately matches that of the Windows driver..
202 * The TestApp's ioctl passes this struct to us.
206 unsigned int Subtype, Type;
208 // unsigned int debug_level; /* future expansion */
209 } __attribute__((packed)) USER_BCM_DBG_STATE;
211 //---Kernel-space mapping of Debug State
212 typedef struct _S_BCM_DEBUG_STATE {
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 !
219 UINT subtype[(NUMTYPES*2)+1];
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
228 //--- Only for direct printk's; "hidden" to API.
229 #define DBG_TYPE_PRINTK 3
231 #define BCM_DEBUG_PRINT(Adapter, Type, SubType, dbg_level, string, args...) \
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); \
242 printk(KERN_DEBUG "%s:" string "\n", __func__, ##args); \
246 #define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level, buffer, bufferlen) do { \
247 if (DBG_TYPE_PRINTK == Type || \
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); \
257 #define BCM_SHOW_DEBUG_BITMAP(Adapter) do { \
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]); \