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