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);
24 #ifdef BCM_SHM_INTERFACE
25 #define CPE_VIRTUAL_ERROR_CODE_BASE_ADDR (0xBFC02E00 + 0x4C)
26 // ERROR codes for debugging
27 extern unsigned char u32ErrorCounter ;
28 #define ERROR_DEVICE_REMOVED 0x1
29 #define ERROR_LEADER_LENGTH_ZERO 0x2
30 #define ERROR_LEADER_LENGTH_CORRUPTED 0x3
31 #define ERROR_NO_SKBUFF 0x4
33 #define ERROR_DL_MODULE 0xaa000000
34 extern void CPE_ERROR_LOG(unsigned int module,unsigned int code);
41 //--------------------------------------------------------------------------------
44 * Define valid TYPE (or category or code-path, however you like to think of it)
46 * Type and SubType are treated as bitmasks.
48 /*-----------------BEGIN TYPEs------------------------------------------*/
49 #define DBG_TYPE_INITEXIT (1 << 0) // 1
50 #define DBG_TYPE_TX (1 << 1) // 2
51 #define DBG_TYPE_RX (1 << 2) // 4
52 #define DBG_TYPE_OTHERS (1 << 3) // 8
53 /*-----------------END TYPEs------------------------------------------*/
54 #define NUMTYPES 4 // careful!
56 /*-----------------BEGIN SUBTYPEs---------------------------------------*/
58 /*-SUBTYPEs for TX : TYPE is DBG_TYPE_TX -----//
59 Transmit.c ,Arp.c, LeakyBucket.c, And Qos.c
63 #define MP_SEND (TX<<0)
64 #define NEXT_SEND (TX<<1)
65 #define TX_FIFO (TX<<2)
66 #define TX_CONTROL (TX<<3)
69 #define IP_ADDR (TX<<4)
70 #define ARP_REQ (TX<<5)
71 #define ARP_RESP (TX<<6)
75 //#define DHCP_REQ (DHCP<<7)
78 #define TOKEN_COUNTS (TX<<8)
79 #define CHECK_TOKENS (TX<<9)
80 #define TX_PACKETS (TX<<10)
81 #define TIMER (TX<<11)
85 #define QUEUE_INDEX (QOS<<12)
86 #define IPV4_DBG (QOS<<13)
87 #define IPV6_DBG (QOS<<14)
88 #define PRUNE_QUEUE (QOS<<15)
89 #define SEND_QUEUE (QOS<<16)
92 #define TX_OSAL_DBG (TX<<17)
95 //--SUBTYPEs for ------INIT & EXIT---------------------
96 /*------------ TYPE is DBG_TYPE_INITEXIT -----//
97 DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */
99 #define DRV_ENTRY (MP<<0)
100 #define MP_INIT (MP<<1)
101 #define READ_REG (MP<<3)
102 #define DISPATCH (MP<<2)
103 #define CLAIM_ADAP (MP<<4)
104 #define REG_IO_PORT (MP<<5)
105 #define INIT_DISP (MP<<6)
106 #define RX_INIT (MP<<7)
109 //-SUBTYPEs for --RX----------------------------------
110 //------------RX : TYPE is DBG_TYPE_RX -----//
113 #define RX_DPC (RX<<0)
114 #define RX_CTRL (RX<<3)
115 #define RX_DATA (RX<<4)
116 #define MP_RETURN (RX<<1)
117 #define LINK_MSG (RX<<2)
120 //-SUBTYPEs for ----OTHER ROUTINES------------------
121 //------------OTHERS : TYPE is DBG_TYPE_OTHER -----//
122 // HaltnReset,CheckForHang,PnP,Misc,CmHost
128 #define MP_DPC (ISR<<0)
132 #define MP_HALT (HALT<<1)
133 #define CHECK_HANG (HALT<<2)
134 #define MP_RESET (HALT<<3)
135 #define MP_SHUTDOWN (HALT<<4)
139 #define MP_PNP (PNP<<5)
143 #define DUMP_INFO (MISC<<6)
144 #define CLASSIFY (MISC<<7)
145 #define LINK_UP_MSG (MISC<<8)
146 #define CP_CTRL_PKT (MISC<<9)
147 #define DUMP_CONTROL (MISC<<10)
148 #define LED_DUMP_INFO (MISC<<11)
151 #define CMHOST OTHERS
154 #define SERIAL (OTHERS<<12)
155 #define IDLE_MODE (OTHERS<<13)
157 #define WRM (OTHERS<<14)
158 #define RDM (OTHERS<<15)
160 // TODO - put PHS_SEND in Tx PHS_RECEIVE in Rx path ?
161 #define PHS_SEND (OTHERS<<16)
162 #define PHS_RECIEVE (OTHERS<<17)
163 #define PHS_MODULE (OTHERS<<18)
165 #define INTF_INIT (OTHERS<<19)
166 #define INTF_ERR (OTHERS<<20)
167 #define INTF_WARN (OTHERS<<21)
168 #define INTF_NORM (OTHERS<<22)
170 #define IRP_COMPLETION (OTHERS<<23)
171 #define SF_DESCRIPTOR_CNTS (OTHERS<<24)
172 #define PHS_DISPATCH (OTHERS << 25)
173 #define OSAL_DBG (OTHERS << 26)
174 #define NVM_RW (OTHERS << 27)
176 #define HOST_MIBS (OTHERS << 28)
177 #define CONN_MSG (CMHOST << 29)
178 //#define OTHERS_MISC (OTHERS << 29) // ProcSupport.c
179 /*-----------------END SUBTYPEs------------------------------------------*/
183 * We have 8 debug levels, in (numerical) increasing order of verbosity.
184 * IMP: Currently implementing ONLY DBG_LVL_ALL , i.e. , all debug prints will
185 * appear (of course, iff global debug flag is ON and we match the Type and SubType).
186 * Finer granularity debug levels are currently not in use, although the feature exists.
188 * Another way to say this:
189 * All the debug prints currently have 'debug_level' set to DBG_LVL_ALL .
190 * You can compile-time change that to any of the below, if you wish to. However, as of now, there's
191 * no dynamic facility to have the userspace 'TestApp' set debug_level. Slated for future expansion.
200 /* Not meant for developer in debug prints.
201 * To be used to disable all prints by setting the DBG_LVL_CURR to this value */
204 /* The current driver logging level.
205 * Everything at this level and (numerically) lower (meaning higher prio)
207 * Replace 'BCM_ALL' in the DBG_LVL_CURR macro with the logging level desired.
208 * For eg. to set the logging level to 'errors only' use:
209 * #define DBG_LVL_CURR (BCM_ERR)
212 #define DBG_LVL_CURR (BCM_ALL)
213 #define DBG_LVL_ALL BCM_ALL
215 /*---Userspace mapping of Debug State.
216 * Delibrately matches that of the Windows driver..
217 * The TestApp's ioctl passes this struct to us.
221 unsigned int Subtype, Type;
223 // unsigned int debug_level; /* future expansion */
224 } __attribute__((packed)) USER_BCM_DBG_STATE;
226 //---Kernel-space mapping of Debug State
227 typedef struct _S_BCM_DEBUG_STATE {
229 /* A bitmap of 32 bits for Subtype per Type.
230 * Valid indexes in 'subtype' array are *only* 1,2,4 and 8,
231 * corresponding to valid Type values. Hence we use the 'Type' field
232 * as the index value, ignoring the array entries 0,3,5,6,7 !
234 UINT subtype[(NUMTYPES*2)+1];
237 /* Instantiated in the Adapter structure */
238 /* We'll reuse the debug level parameter to include a bit (the MSB) to indicate whether or not
239 * we want the function's name printed. */
240 #define DBG_NO_FUNC_PRINT 1 << 31
241 #define DBG_LVL_BITMASK 0xFF
243 //--- Only for direct printk's; "hidden" to API.
244 #define DBG_TYPE_PRINTK 3
245 #define PRINTKS_ON 1 // "hidden" from API, set to 0 to turn off all printk's
247 #define BCM_DEBUG_PRINT(Adapter, Type, SubType, dbg_level, string, args...) do { \
248 if ((DBG_TYPE_PRINTK == Type) && (PRINTKS_ON)) { \
249 printk ("%s:" string, __FUNCTION__, ##args); \
251 } else if (!Adapter) \
254 if (((dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level) && \
255 ((Type & Adapter->stDebugState.type) && (SubType & Adapter->stDebugState.subtype[Type]))) { \
256 if (dbg_level & DBG_NO_FUNC_PRINT) \
257 printk (string, ##args); \
260 printk ("%s:" string, __FUNCTION__, ##args); \
267 #define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level, buffer, bufferlen) do { \
268 if ((DBG_TYPE_PRINTK == Type) && (PRINTKS_ON)) { \
269 bcm_print_buffer( dbg_level, __FUNCTION__, __FILE__, __LINE__, buffer, bufferlen, BCM_BASE_TYPE_HEX); \
270 } else if (!Adapter) \
273 if (((dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level) && \
274 ((Type & Adapter->stDebugState.type) && (SubType & Adapter->stDebugState.subtype[Type]))) { \
275 if (dbg_level & DBG_NO_FUNC_PRINT) \
276 bcm_print_buffer( dbg_level, NULL, NULL, __LINE__, buffer, bufferlen, BCM_BASE_TYPE_HEX); \
278 bcm_print_buffer( dbg_level, __FUNCTION__, __FILE__, __LINE__, buffer, bufferlen, BCM_BASE_TYPE_HEX); \
284 #define BCM_SHOW_DEBUG_BITMAP(Adapter) do { \
286 for (i=0; i<(NUMTYPES*2)+1; i++) { \
287 if ((i == 1) || (i == 2) || (i == 4) || (i == 8)) { \
288 /* CAUTION! Forcefully turn on ALL debug paths and subpaths! \
289 Adapter->stDebugState.subtype[i] = 0xffffffff; */ \
290 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "subtype[%d] = 0x%08x\n", \
291 i, Adapter->stDebugState.subtype[i]); \