debuglib.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. *
  3. Copyright (c) Eicon Networks, 2002.
  4. *
  5. This source file is supplied for the use with
  6. Eicon Networks range of DIVA Server Adapters.
  7. *
  8. Eicon File Revision : 2.1
  9. *
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2, or (at your option)
  13. any later version.
  14. *
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY
  17. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. See the GNU General Public License for more details.
  19. *
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #if !defined(__DEBUGLIB_H__)
  26. #define __DEBUGLIB_H__
  27. #include <stdarg.h>
  28. /*
  29. * define global debug priorities
  30. */
  31. #define DL_LOG 0x00000001 /* always worth mentioning */
  32. #define DL_FTL 0x00000002 /* always sampled error */
  33. #define DL_ERR 0x00000004 /* any kind of error */
  34. #define DL_TRC 0x00000008 /* verbose information */
  35. #define DL_XLOG 0x00000010 /* old xlog info */
  36. #define DL_MXLOG 0x00000020 /* maestra xlog info */
  37. #define DL_FTL_MXLOG 0x00000021 /* fatal maestra xlog info */
  38. #define DL_EVL 0x00000080 /* special NT eventlog msg */
  39. #define DL_COMPAT (DL_MXLOG | DL_XLOG)
  40. #define DL_PRIOR_MASK (DL_EVL | DL_COMPAT | DL_TRC | DL_ERR | DL_FTL | DL_LOG)
  41. #define DLI_LOG 0x0100
  42. #define DLI_FTL 0x0200
  43. #define DLI_ERR 0x0300
  44. #define DLI_TRC 0x0400
  45. #define DLI_XLOG 0x0500
  46. #define DLI_MXLOG 0x0600
  47. #define DLI_FTL_MXLOG 0x0600
  48. #define DLI_EVL 0x0800
  49. /*
  50. * define OS (operating system interface) debuglevel
  51. */
  52. #define DL_REG 0x00000100 /* init/query registry */
  53. #define DL_MEM 0x00000200 /* memory management */
  54. #define DL_SPL 0x00000400 /* event/spinlock handling */
  55. #define DL_IRP 0x00000800 /* I/O request handling */
  56. #define DL_TIM 0x00001000 /* timer/watchdog handling */
  57. #define DL_BLK 0x00002000 /* raw data block contents */
  58. #define DL_OS_MASK (DL_BLK | DL_TIM | DL_IRP | DL_SPL | DL_MEM | DL_REG)
  59. #define DLI_REG 0x0900
  60. #define DLI_MEM 0x0A00
  61. #define DLI_SPL 0x0B00
  62. #define DLI_IRP 0x0C00
  63. #define DLI_TIM 0x0D00
  64. #define DLI_BLK 0x0E00
  65. /*
  66. * define ISDN (connection interface) debuglevel
  67. */
  68. #define DL_TAPI 0x00010000 /* debug TAPI interface */
  69. #define DL_NDIS 0x00020000 /* debug NDIS interface */
  70. #define DL_CONN 0x00040000 /* connection handling */
  71. #define DL_STAT 0x00080000 /* trace state machines */
  72. #define DL_SEND 0x00100000 /* trace raw xmitted data */
  73. #define DL_RECV 0x00200000 /* trace raw received data */
  74. #define DL_DATA (DL_SEND | DL_RECV)
  75. #define DL_ISDN_MASK (DL_DATA | DL_STAT | DL_CONN | DL_NDIS | DL_TAPI)
  76. #define DLI_TAPI 0x1100
  77. #define DLI_NDIS 0x1200
  78. #define DLI_CONN 0x1300
  79. #define DLI_STAT 0x1400
  80. #define DLI_SEND 0x1500
  81. #define DLI_RECV 0x1600
  82. /*
  83. * define some private (unspecified) debuglevel
  84. */
  85. #define DL_PRV0 0x01000000
  86. #define DL_PRV1 0x02000000
  87. #define DL_PRV2 0x04000000
  88. #define DL_PRV3 0x08000000
  89. #define DL_PRIV_MASK (DL_PRV0 | DL_PRV1 | DL_PRV2 | DL_PRV3)
  90. #define DLI_PRV0 0x1900
  91. #define DLI_PRV1 0x1A00
  92. #define DLI_PRV2 0x1B00
  93. #define DLI_PRV3 0x1C00
  94. #define DT_INDEX(x) ((x) & 0x000F)
  95. #define DL_INDEX(x) ((((x) >> 8) & 0x00FF) - 1)
  96. #define DLI_NAME(x) ((x) & 0xFF00)
  97. /*
  98. * Debug mask for kernel mode tracing, if set the output is also sent to
  99. * the system debug function. Requires that the project is compiled
  100. * with _KERNEL_DBG_PRINT_
  101. */
  102. #define DL_TO_KERNEL 0x40000000
  103. #ifdef DIVA_NO_DEBUGLIB
  104. #define myDbgPrint_LOG(x...) do { } while (0);
  105. #define myDbgPrint_FTL(x...) do { } while (0);
  106. #define myDbgPrint_ERR(x...) do { } while (0);
  107. #define myDbgPrint_TRC(x...) do { } while (0);
  108. #define myDbgPrint_MXLOG(x...) do { } while (0);
  109. #define myDbgPrint_EVL(x...) do { } while (0);
  110. #define myDbgPrint_REG(x...) do { } while (0);
  111. #define myDbgPrint_MEM(x...) do { } while (0);
  112. #define myDbgPrint_SPL(x...) do { } while (0);
  113. #define myDbgPrint_IRP(x...) do { } while (0);
  114. #define myDbgPrint_TIM(x...) do { } while (0);
  115. #define myDbgPrint_BLK(x...) do { } while (0);
  116. #define myDbgPrint_TAPI(x...) do { } while (0);
  117. #define myDbgPrint_NDIS(x...) do { } while (0);
  118. #define myDbgPrint_CONN(x...) do { } while (0);
  119. #define myDbgPrint_STAT(x...) do { } while (0);
  120. #define myDbgPrint_SEND(x...) do { } while (0);
  121. #define myDbgPrint_RECV(x...) do { } while (0);
  122. #define myDbgPrint_PRV0(x...) do { } while (0);
  123. #define myDbgPrint_PRV1(x...) do { } while (0);
  124. #define myDbgPrint_PRV2(x...) do { } while (0);
  125. #define myDbgPrint_PRV3(x...) do { } while (0);
  126. #define DBG_TEST(func, args) do { } while (0);
  127. #define DBG_EVL_ID(args) do { } while (0);
  128. #else /* DIVA_NO_DEBUGLIB */
  129. /*
  130. * define low level macros for formatted & raw debugging
  131. */
  132. #define DBG_DECL(func) extern void myDbgPrint_##func(char *, ...);
  133. DBG_DECL(LOG)
  134. DBG_DECL(FTL)
  135. DBG_DECL(ERR)
  136. DBG_DECL(TRC)
  137. DBG_DECL(MXLOG)
  138. DBG_DECL(FTL_MXLOG)
  139. extern void myDbgPrint_EVL(long, ...);
  140. DBG_DECL(REG)
  141. DBG_DECL(MEM)
  142. DBG_DECL(SPL)
  143. DBG_DECL(IRP)
  144. DBG_DECL(TIM)
  145. DBG_DECL(BLK)
  146. DBG_DECL(TAPI)
  147. DBG_DECL(NDIS)
  148. DBG_DECL(CONN)
  149. DBG_DECL(STAT)
  150. DBG_DECL(SEND)
  151. DBG_DECL(RECV)
  152. DBG_DECL(PRV0)
  153. DBG_DECL(PRV1)
  154. DBG_DECL(PRV2)
  155. DBG_DECL(PRV3)
  156. #ifdef _KERNEL_DBG_PRINT_
  157. /*
  158. * tracing to maint and kernel if selected in the trace mask.
  159. */
  160. #define DBG_TEST(func, args) \
  161. { if ((myDriverDebugHandle.dbgMask) & (unsigned long)DL_##func) \
  162. { \
  163. if ((myDriverDebugHandle.dbgMask) & DL_TO_KERNEL) \
  164. { DbgPrint args; DbgPrint("\r\n"); } \
  165. myDbgPrint_##func args; \
  166. } }
  167. #else
  168. /*
  169. * Standard tracing to maint driver.
  170. */
  171. #define DBG_TEST(func, args) \
  172. { if ((myDriverDebugHandle.dbgMask) & (unsigned long)DL_##func) \
  173. { myDbgPrint_##func args; \
  174. } }
  175. #endif
  176. /*
  177. * For event level debug use a separate define, the parameter are
  178. * different and cause compiler errors on some systems.
  179. */
  180. #define DBG_EVL_ID(args) \
  181. { if ((myDriverDebugHandle.dbgMask) & (unsigned long)DL_EVL) \
  182. { myDbgPrint_EVL args; \
  183. } }
  184. #endif /* DIVA_NO_DEBUGLIB */
  185. #define DBG_LOG(args) DBG_TEST(LOG, args)
  186. #define DBG_FTL(args) DBG_TEST(FTL, args)
  187. #define DBG_ERR(args) DBG_TEST(ERR, args)
  188. #define DBG_TRC(args) DBG_TEST(TRC, args)
  189. #define DBG_MXLOG(args) DBG_TEST(MXLOG, args)
  190. #define DBG_FTL_MXLOG(args) DBG_TEST(FTL_MXLOG, args)
  191. #define DBG_EVL(args) DBG_EVL_ID(args)
  192. #define DBG_REG(args) DBG_TEST(REG, args)
  193. #define DBG_MEM(args) DBG_TEST(MEM, args)
  194. #define DBG_SPL(args) DBG_TEST(SPL, args)
  195. #define DBG_IRP(args) DBG_TEST(IRP, args)
  196. #define DBG_TIM(args) DBG_TEST(TIM, args)
  197. #define DBG_BLK(args) DBG_TEST(BLK, args)
  198. #define DBG_TAPI(args) DBG_TEST(TAPI, args)
  199. #define DBG_NDIS(args) DBG_TEST(NDIS, args)
  200. #define DBG_CONN(args) DBG_TEST(CONN, args)
  201. #define DBG_STAT(args) DBG_TEST(STAT, args)
  202. #define DBG_SEND(args) DBG_TEST(SEND, args)
  203. #define DBG_RECV(args) DBG_TEST(RECV, args)
  204. #define DBG_PRV0(args) DBG_TEST(PRV0, args)
  205. #define DBG_PRV1(args) DBG_TEST(PRV1, args)
  206. #define DBG_PRV2(args) DBG_TEST(PRV2, args)
  207. #define DBG_PRV3(args) DBG_TEST(PRV3, args)
  208. /*
  209. * prototypes for debug register/deregister functions in "debuglib.c"
  210. */
  211. #ifdef DIVA_NO_DEBUGLIB
  212. #define DbgRegister(name, tag, mask) do { } while (0)
  213. #define DbgDeregister() do { } while (0)
  214. #define DbgSetLevel(mask) do { } while (0)
  215. #else
  216. extern DIVA_DI_PRINTF dprintf;
  217. extern int DbgRegister(char *drvName, char *drvTag, unsigned long dbgMask);
  218. extern void DbgDeregister(void);
  219. extern void DbgSetLevel(unsigned long dbgMask);
  220. #endif
  221. /*
  222. * driver internal structure for debug handling;
  223. * in client drivers this structure is maintained in "debuglib.c",
  224. * in the debug driver "debug.c" maintains a chain of such structs.
  225. */
  226. typedef struct _DbgHandle_ *pDbgHandle;
  227. typedef void (*DbgEnd)(pDbgHandle);
  228. typedef void (*DbgLog)(unsigned short, int, char *, va_list);
  229. typedef void (*DbgOld)(unsigned short, char *, va_list);
  230. typedef void (*DbgEv)(unsigned short, unsigned long, va_list);
  231. typedef void (*DbgIrq)(unsigned short, int, char *, va_list);
  232. typedef struct _DbgHandle_
  233. { char Registered; /* driver successfully registered */
  234. #define DBG_HANDLE_REG_NEW 0x01 /* this (new) structure */
  235. #define DBG_HANDLE_REG_OLD 0x7f /* old structure (see below) */
  236. char Version; /* version of this structure */
  237. #define DBG_HANDLE_VERSION 1 /* contains dbg_old function now */
  238. #define DBG_HANDLE_VER_EXT 2 /* pReserved points to extended info*/
  239. short id; /* internal id of registered driver */
  240. struct _DbgHandle_ *next; /* ptr to next registered driver */
  241. struct /*LARGE_INTEGER*/ {
  242. unsigned long LowPart;
  243. long HighPart;
  244. } regTime; /* timestamp for registration */
  245. void *pIrp; /* ptr to pending i/o request */
  246. unsigned long dbgMask; /* current debug mask */
  247. char drvName[128]; /* ASCII name of registered driver */
  248. char drvTag[64]; /* revision string */
  249. DbgEnd dbg_end; /* function for debug closing */
  250. DbgLog dbg_prt; /* function for debug appending */
  251. DbgOld dbg_old; /* function for old debug appending */
  252. DbgEv dbg_ev; /* function for Windows NT Eventlog */
  253. DbgIrq dbg_irq; /* function for irql checked debug */
  254. void *pReserved3;
  255. } _DbgHandle_;
  256. extern _DbgHandle_ myDriverDebugHandle;
  257. typedef struct _OldDbgHandle_
  258. { struct _OldDbgHandle_ *next;
  259. void *pIrp;
  260. long regTime[2];
  261. unsigned long dbgMask;
  262. short id;
  263. char drvName[78];
  264. DbgEnd dbg_end;
  265. DbgLog dbg_prt;
  266. } _OldDbgHandle_;
  267. /* the differences in DbgHandles
  268. old: tmp: new:
  269. 0 long next char Registered char Registered
  270. char filler char Version
  271. short id short id
  272. 4 long pIrp long regTime.lo long next
  273. 8 long regTime.lo long regTime.hi long regTime.lo
  274. 12 long regTime.hi long next long regTime.hi
  275. 16 long dbgMask long pIrp long pIrp
  276. 20 short id long dbgMask long dbgMask
  277. 22 char drvName[78] ..
  278. 24 .. char drvName[16] char drvName[16]
  279. 40 .. char drvTag[64] char drvTag[64]
  280. 100 void *dbg_end .. ..
  281. 104 void *dbg_prt void *dbg_end void *dbg_end
  282. 108 .. void *dbg_prt void *dbg_prt
  283. 112 .. .. void *dbg_old
  284. 116 .. .. void *dbg_ev
  285. 120 .. .. void *dbg_irq
  286. 124 .. .. void *pReserved3
  287. ( new->id == 0 && *((short *)&new->dbgMask) == -1 ) identifies "old",
  288. new->Registered and new->Version overlay old->next,
  289. new->next overlays old->pIrp, new->regTime matches old->regTime and
  290. thus these fields can be maintained in new struct whithout trouble;
  291. id, dbgMask, drvName, dbg_end and dbg_prt need special handling !
  292. */
  293. #define DBG_EXT_TYPE_CARD_TRACE 0x00000001
  294. typedef struct
  295. {
  296. unsigned long ExtendedType;
  297. union
  298. {
  299. /* DBG_EXT_TYPE_CARD_TRACE */
  300. struct
  301. {
  302. void (*MaskChangedNotify)(void *pContext);
  303. unsigned long ModuleTxtMask;
  304. unsigned long DebugLevel;
  305. unsigned long B_ChannelMask;
  306. unsigned long LogBufferSize;
  307. } CardTrace;
  308. } Data;
  309. } _DbgExtendedInfo_;
  310. #ifndef DIVA_NO_DEBUGLIB
  311. /* -------------------------------------------------------------
  312. Function used for xlog-style debug
  313. ------------------------------------------------------------- */
  314. #define XDI_USE_XLOG 1
  315. void xdi_dbg_xlog(char *x, ...);
  316. #endif /* DIVA_NO_DEBUGLIB */
  317. #endif /* __DEBUGLIB_H__ */