Debug.h 7.0 KB

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