4 * Dynamic (runtime) debug framework implementation.
9 #include <linux/string.h>
12 typedef enum _BASE_TYPE
19 } BASE_TYPE, *PBASE_TYPE;
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);
28 //--------------------------------------------------------------------------------
31 * Define valid TYPE (or category or code-path, however you like to think of it)
33 * Type and SubType are treated as bitmasks.
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!
43 /*-----------------BEGIN SUBTYPEs---------------------------------------*/
45 /*-SUBTYPEs for TX : TYPE is DBG_TYPE_TX -----//
46 Transmit.c ,Arp.c, LeakyBucket.c, And Qos.c
50 #define MP_SEND (TX<<0)
51 #define NEXT_SEND (TX<<1)
52 #define TX_FIFO (TX<<2)
53 #define TX_CONTROL (TX<<3)
56 #define IP_ADDR (TX<<4)
57 #define ARP_REQ (TX<<5)
58 #define ARP_RESP (TX<<6)
62 //#define DHCP_REQ (DHCP<<7)
65 #define TOKEN_COUNTS (TX<<8)
66 #define CHECK_TOKENS (TX<<9)
67 #define TX_PACKETS (TX<<10)
68 #define TIMER (TX<<11)
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)
79 #define TX_OSAL_DBG (TX<<17)
82 //--SUBTYPEs for ------INIT & EXIT---------------------
83 /*------------ TYPE is DBG_TYPE_INITEXIT -----//
84 DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */
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)
96 //-SUBTYPEs for --RX----------------------------------
97 //------------RX : TYPE is DBG_TYPE_RX -----//
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)
107 //-SUBTYPEs for ----OTHER ROUTINES------------------
108 //------------OTHERS : TYPE is DBG_TYPE_OTHER -----//
109 // HaltnReset,CheckForHang,PnP,Misc,CmHost
115 #define MP_DPC (ISR<<0)
119 #define MP_HALT (HALT<<1)
120 #define CHECK_HANG (HALT<<2)
121 #define MP_RESET (HALT<<3)
122 #define MP_SHUTDOWN (HALT<<4)
126 #define MP_PNP (PNP<<5)
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)
138 #define CMHOST OTHERS
141 #define SERIAL (OTHERS<<12)
142 #define IDLE_MODE (OTHERS<<13)
144 #define WRM (OTHERS<<14)
145 #define RDM (OTHERS<<15)
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)
152 #define INTF_INIT (OTHERS<<19)
153 #define INTF_ERR (OTHERS<<20)
154 #define INTF_WARN (OTHERS<<21)
155 #define INTF_NORM (OTHERS<<22)
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)
163 #define HOST_MIBS (OTHERS << 28)
164 #define CONN_MSG (CMHOST << 29)
165 //#define OTHERS_MISC (OTHERS << 29) // ProcSupport.c
166 /*-----------------END SUBTYPEs------------------------------------------*/
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.
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.
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 */
191 /* The current driver logging level.
192 * Everything at this level and (numerically) lower (meaning higher prio)
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)
199 #define DBG_LVL_CURR (BCM_ALL)
200 #define DBG_LVL_ALL BCM_ALL
202 /*---Userspace mapping of Debug State.
203 * Delibrately matches that of the Windows driver..
204 * The TestApp's ioctl passes this struct to us.
208 unsigned int Subtype, Type;
210 // unsigned int debug_level; /* future expansion */
211 } __attribute__((packed)) USER_BCM_DBG_STATE;
213 //---Kernel-space mapping of Debug State
214 typedef struct _S_BCM_DEBUG_STATE {
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 !
221 UINT subtype[(NUMTYPES*2)+1];
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
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
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); \
238 } else if (!Adapter) \
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); \
247 printk ("%s:" string, __FUNCTION__, ##args); \
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) \
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); \
265 bcm_print_buffer( dbg_level, __FUNCTION__, __FILE__, __LINE__, buffer, bufferlen, BCM_BASE_TYPE_HEX); \
271 #define BCM_SHOW_DEBUG_BITMAP(Adapter) do { \
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]); \