Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

368 lines
9.6 KiB

  1. /*
  2. ************************************************************************
  3. *
  4. * SETTINGS.h
  5. *
  6. *
  7. * Portions Copyright (C) 1996-1998 National Semiconductor Corp.
  8. * All rights reserved.
  9. * Copyright (C) 1996-1998 Microsoft Corporation. All Rights Reserved.
  10. *
  11. *
  12. *
  13. *************************************************************************
  14. */
  15. #ifndef SETTINGS_H
  16. #define SETTINGS_H
  17. #include "dongle.h"
  18. #if DBG /* { */
  19. /*
  20. * The DBG_ADD_PKT_ID flag causes the miniport to add/delete a packet
  21. * id to each packet. This is only for debugging purposes; it makes
  22. * the miniport INCOMPATIBLE with all others.
  23. */
  24. //#define DBG_ADD_PKT_ID
  25. #ifdef DBG_ADD_PKT_ID
  26. extern BOOLEAN addPktIdOn;
  27. #endif
  28. typedef enum {
  29. DBG_ERR = (1 << 0),
  30. DBG_STAT = (1 << 1),
  31. DBG_MSG = (1 << 2),
  32. DBG_OUT = (1 << 2),
  33. DBG_BUF = (1 << 3),
  34. DBG_PACKET = (1 << 4),
  35. DBG_PKT = (1 << 4),
  36. // Added so we can look at an ndis buffer.
  37. DBG_NDIS_PACKET = (1 << 5),
  38. DBG_DUMPLOG = (1 << 6),
  39. DBG_LOG = (1 << 7),
  40. DBG_ALL = (DBG_ERR|DBG_STAT|DBG_MSG|DBG_BUF|DBG_PACKET),
  41. DBG_SIR_MODE = (1 << 8),
  42. DBG_FIR_MODE = (1 << 9),
  43. DBG_TX = (1 << 10),
  44. DBG_RX = (1 << 11),
  45. DBG_DMA = (1 << 12),
  46. DBG_ISR = (1 << 13),
  47. DBG_TRACE_TX = (1 << 14)
  48. };
  49. // extern ULONG _cdecl DbgPrint(PCHAR Format, ...);
  50. extern UINT dbgOpt;
  51. #define DBG_NDIS_RESULT_STR(_ndisResult) \
  52. ((PUCHAR) ((_ndisResult == NDIS_STATUS_SUCCESS) ? \
  53. "NDIS_STATUS_SUCCESS" : (_ndisResult == NDIS_STATUS_FAILURE) ? \
  54. "NDIS_STATUS_FAILURE" : (_ndisResult == NDIS_STATUS_PENDING) ? \
  55. "NDIS_STATUS_PENDING" : "NDIS_STATUS_???"))
  56. #define DBGPRINT(dbgprint_params_in_parens) \
  57. { \
  58. DbgPrint("NSC: "); \
  59. DbgPrint dbgprint_params_in_parens; \
  60. DbgPrint("\r\n"); \
  61. }
  62. #define DEBUGMSG(flags, dbgprint_params_in_parens) \
  63. if (dbgOpt & (flags)) \
  64. { \
  65. DbgPrint dbgprint_params_in_parens; \
  66. }
  67. #define DEBUGFIR(flags, dbgprint_params_in_parens) \
  68. if (dbgOpt & DBG_FIR_MODE && dbgOpt & (flags)) \
  69. { \
  70. DbgPrint dbgprint_params_in_parens; \
  71. }
  72. #define DBGOUT(dbgprint_params_in_parens) \
  73. if (dbgOpt & DBG_MSG) { \
  74. if ((DebugSpeed > MAX_SIR_SPEED) && \
  75. (dbgOpt & DBG_FIR_MODE)) { \
  76. DBGPRINT(dbgprint_params_in_parens); \
  77. } \
  78. else if (dbgOpt & DBG_SIR_MODE) { \
  79. DBGPRINT(dbgprint_params_in_parens); \
  80. } \
  81. }
  82. #define DBGERR(dbgprint_params_in_parens) \
  83. if (dbgOpt & DBG_ERR) { \
  84. if ((DebugSpeed > MAX_SIR_SPEED) && \
  85. (dbgOpt & DBG_FIR_MODE)) { \
  86. DBGPRINT(dbgprint_params_in_parens); \
  87. } \
  88. else if (dbgOpt & DBG_SIR_MODE) { \
  89. DBGPRINT(dbgprint_params_in_parens); \
  90. } \
  91. }
  92. #define DBGSTAT(dbgprint_params_in_parens) \
  93. if (dbgOpt & DBG_STAT) { \
  94. if ((DebugSpeed > MAX_SIR_SPEED) && \
  95. (dbgOpt & DBG_FIR_MODE)) { \
  96. DBGPRINT(dbgprint_params_in_parens); \
  97. } \
  98. else if (dbgOpt & DBG_SIR_MODE) { \
  99. DBGPRINT(dbgprint_params_in_parens); \
  100. } \
  101. }
  102. #define DBGPKT(dbgprint_params_in_parens) \
  103. if (dbgOpt & DBG_PACKET) { \
  104. if ((DebugSpeed > MAX_SIR_SPEED) && \
  105. (dbgOpt & DBG_FIR_MODE)) { \
  106. DBGPRINT(dbgprint_params_in_parens); \
  107. } \
  108. else if (dbgOpt & DBG_SIR_MODE) { \
  109. DBGPRINT(dbgprint_params_in_parens); \
  110. } \
  111. }
  112. #define DBG_D(i) DbgPrint("IRSIR:"#i"==%d\n", (i))
  113. #define DBG_X(x) DbgPrint("IRSIR:"#x"==0x%0*X\n", sizeof(x)*2, ((ULONG_PTR)(x))&((1<<(sizeof(x)*8))-1) )
  114. #define DBG_UNISTR(s) DbgPrint("IRSIR:"#s"==%wZ\n", (s))
  115. extern VOID DBG_NDIS_Buffer(PNDIS_BUFFER ndisBuf);
  116. #define DBG_NDIS_BUFFER(Ndis_buffer) \
  117. if (dbgOpt & DBG_NDIS_PACKET) { \
  118. if ((DebugSpeed > MAX_SIR_SPEED) && \
  119. (dbgOpt & DBG_FIR_MODE)) { \
  120. DBG_NDIS_Buffer(Ndis_buffer); \
  121. } \
  122. else if (dbgOpt & DBG_SIR_MODE) { \
  123. DBG_NDIS_Buffer(Ndis_buffer); \
  124. } \
  125. }
  126. extern VOID DBG_PrintBuf(PUCHAR bufptr, UINT buflen);
  127. #define DBGPRINTBUF(bufptr, buflen) \
  128. if (dbgOpt & DBG_BUF) { \
  129. if ((DebugSpeed > MAX_SIR_SPEED) && \
  130. (dbgOpt & DBG_FIR_MODE)) { \
  131. DBG_PrintBuf((PUCHAR)(bufptr), (UINT)(buflen)); \
  132. } \
  133. else if (dbgOpt & DBG_SIR_MODE) { \
  134. DBG_PrintBuf((PUCHAR)(bufptr), (UINT)(buflen)); \
  135. } \
  136. }
  137. /*
  138. * LOGGING stuff
  139. */
  140. struct logEntry {
  141. char *msg;
  142. LONGLONG usec;
  143. UINT val;
  144. };
  145. #define LOG_LENGTH 10000
  146. extern UINT dbgLogIndex;
  147. extern struct logEntry dbgLog[];
  148. #define LOG(logmsg, val) \
  149. { \
  150. if (dbgOpt & DBG_LOG) { \
  151. if ((DebugSpeed > MAX_SIR_SPEED) && \
  152. (dbgOpt & DBG_FIR_MODE)) { \
  153. LogEvent((logmsg), (UINT)(val)); \
  154. } \
  155. else if (dbgOpt & DBG_SIR_MODE) { \
  156. LogEvent((logmsg), (UINT)(val)); \
  157. } \
  158. } \
  159. else if (dbgOpt & DBG_DUMPLOG) { \
  160. if ((DebugSpeed > MAX_SIR_SPEED) && \
  161. (dbgOpt & DBG_FIR_MODE)) { \
  162. DumpLog(); \
  163. } \
  164. else if (dbgOpt & DBG_SIR_MODE) { \
  165. DumpLog(); \
  166. } \
  167. } \
  168. }
  169. #else /* } { */
  170. #define DbgBreakPoint()
  171. #define DBGOUT(dbgprint_params_in_parens)
  172. #define DBGERR(dbgprint_params_in_parens)
  173. #define DBGPRINTBUF(bufptr, buflen)
  174. #define DBGSTAT(dbgprint_params_in_parens)
  175. #define DBGPKT(dbgprint_params_in_parens)
  176. #define DBG_NDIS_RESULT_STR(_ndisResult)
  177. #define LOG(logmsg, val)
  178. #define DEBUGFIR(flags, dbgprint_params_in_parens)
  179. #define DEBUGMSG(flags, dbgprint_params_in_parens)
  180. #define DBG_D(i)
  181. #define DBG_X(x)
  182. #define DBG_UNISTR(s)
  183. #endif /* } #if DBG */
  184. enum baudRates {
  185. /* Slow IR */
  186. BAUDRATE_2400 = 0,
  187. BAUDRATE_9600,
  188. BAUDRATE_19200,
  189. BAUDRATE_38400,
  190. BAUDRATE_57600,
  191. BAUDRATE_115200,
  192. /* Medium IR */
  193. BAUDRATE_576000,
  194. BAUDRATE_1152000,
  195. /* Fast IR */
  196. BAUDRATE_4000000,
  197. NUM_BAUDRATES /* must be last */
  198. };
  199. #define DEFAULT_BAUDRATE BAUDRATE_115200
  200. #define ALL_SLOW_IRDA_SPEEDS ( \
  201. NDIS_IRDA_SPEED_2400 | NDIS_IRDA_SPEED_9600 | \
  202. NDIS_IRDA_SPEED_19200 | NDIS_IRDA_SPEED_38400 | \
  203. NDIS_IRDA_SPEED_57600 | NDIS_IRDA_SPEED_115200)
  204. #define ALL_IRDA_SPEEDS ( \
  205. ALL_SLOW_IRDA_SPEEDS | NDIS_IRDA_SPEED_1152K | NDIS_IRDA_SPEED_4M)
  206. #define MAX_SIR_SPEED 115200
  207. #define MIN_FIR_SPEED 4000000
  208. #define DEFAULT_BOFS_CODE BOFS_48
  209. #define MAX_NUM_EXTRA_BOFS 48
  210. #define DEFAULT_NUM_EXTRA_BOFS MAX_NUM_EXTRA_BOFS
  211. #define DEFAULT_TURNAROUND_usec 1000
  212. typedef struct {
  213. enum baudRates tableIndex;
  214. UINT bitsPerSec;
  215. UINT ndisCode; // bitmask element
  216. } baudRateInfo;
  217. #define DEFAULT_BAUD_RATE 9600
  218. /*
  219. * This is the largest IR packet size (counting _I_ field only,
  220. * and not counting ESC characters) that we handle.
  221. *
  222. * Note: There is an apparent bug with the NSC part. It cannot transfer
  223. * more than 2048 bytes TOTAL, including the 2-byte header. Unfortunately,
  224. * the actual frame size will be 2 bytes more than what we indicate to the
  225. * protocol. We will indicate 2046, but the protocol will actually jump down
  226. * to 1024, the next step down in frame sizes.
  227. */
  228. #define MAX_I_DATA_SIZE 2048
  229. //#define MAX_I_DATA_SIZE 1024
  230. #define MAX_NDIS_DATA_SIZE (IR_ADDR_SIZE+IR_CONTROL_SIZE+MAX_I_DATA_SIZE)
  231. #ifdef DBG_ADD_PKT_ID
  232. #pragma message("WARNING: INCOMPATIBLE DEBUG VERSION")
  233. #define MAX_RCV_DATA_SIZE (MAX_NDIS_DATA_SIZE+SLOW_IR_FCS_SIZE+2)
  234. #define MAX_DMA_XMIT_DATA_SIZE (MAX_NDIS_DATA_SIZE+SLOW_IR_FCS_SIZE+2)
  235. #else
  236. #define MAX_RCV_DATA_SIZE (MAX_NDIS_DATA_SIZE+SLOW_IR_FCS_SIZE)
  237. #define MAX_DMA_XMIT_DATA_SIZE (MAX_NDIS_DATA_SIZE+SLOW_IR_FCS_SIZE)
  238. #endif
  239. #define MAX_TX_PACKETS 7
  240. #define MAX_RX_PACKETS 7
  241. /*
  242. * We loop an extra time in the receive FSM in order to see EOF after the
  243. * last data byte; so we need some extra space in readBuf in case we then
  244. * get garbage instead.
  245. */
  246. #define RCV_BUFFER_SIZE (MAX_RCV_DATA_SIZE +4+sizeof(LIST_ENTRY))
  247. #define RCV_DMA_SIZE ((MAX_RX_PACKETS+2) * (MAX_RCV_DATA_SIZE + FAST_IR_FCS_SIZE))
  248. #define RCV_BUF_TO_LIST_ENTRY(b) ((PLIST_ENTRY)((PUCHAR)(b)-sizeof(LIST_ENTRY)))
  249. #define LIST_ENTRY_TO_RCV_BUF(e) ((PVOID)((PUCHAR)(e)+sizeof(LIST_ENTRY)))
  250. #if (RCV_DMA_SIZE > 0x10000)
  251. #error "RCV_DMA_SIZE can't span physical segments"
  252. #endif
  253. /*
  254. * We allocate buffers twice as large as the max rcv size to accomodate ESC
  255. * characters and BOFs, etc. Recall that in the worst possible case, the
  256. * data contains all BOF/EOF/ESC characters, in which case we must expand
  257. * it to twice its original size.
  258. */
  259. #define MAX_POSSIBLE_IR_PACKET_SIZE_FOR_DATA(dataLen) ( \
  260. (dataLen) * 2 + (MAX_NUM_EXTRA_BOFS + 1) * \
  261. SLOW_IR_BOF_SIZE + IR_ADDR_SIZE + IR_CONTROL_SIZE + \
  262. SLOW_IR_FCS_SIZE + SLOW_IR_EOF_SIZE)
  263. #define MAX_IRDA_DATA_SIZE \
  264. MAX_POSSIBLE_IR_PACKET_SIZE_FOR_DATA(MAX_I_DATA_SIZE)
  265. /*
  266. * When FCS is computed on an IR packet with FCS appended, the result
  267. * should be this constant.
  268. */
  269. #define GOOD_FCS ((USHORT) ~0xf0b8)
  270. /*
  271. * Sizes of IrLAP frame fields:
  272. * Beginning Of Frame (BOF)
  273. * End Of Frame (EOF)
  274. * Address
  275. * Control
  276. */
  277. #define IR_ADDR_SIZE 1
  278. #define IR_CONTROL_SIZE 1
  279. #define SLOW_IR_BOF_TYPE UCHAR
  280. #define SLOW_IR_BOF_SIZE sizeof(SLOW_IR_BOF_TYPE)
  281. #define SLOW_IR_EXTRA_BOF_TYPE UCHAR
  282. #define SLOW_IR_EXTRA_BOF_SIZE sizeof(SLOW_IR_EXTRA_BOF_TYPE)
  283. #define SLOW_IR_EOF_TYPE UCHAR
  284. #define SLOW_IR_EOF_SIZE sizeof(SLOW_IR_EOF_TYPE)
  285. #define SLOW_IR_FCS_TYPE USHORT
  286. #define SLOW_IR_FCS_SIZE sizeof(SLOW_IR_FCS_TYPE)
  287. #define SLOW_IR_BOF 0xC0
  288. /* don't use 0xFF, it breaks some HP printers! */
  289. #define SLOW_IR_EXTRA_BOF 0xC0
  290. #define SLOW_IR_EOF 0xC1
  291. #define SLOW_IR_ESC 0x7D
  292. #define SLOW_IR_ESC_COMP 0x20
  293. #define MEDIUM_IR_BOF 0x7E
  294. #define MEDIUM_IR_EOF 0x7E
  295. #define MEDIUM_IR_FCS_SIZE 2
  296. #define FAST_IR_FCS_SIZE 4
  297. #define FAST_IR_EOF_SIZE 1
  298. #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
  299. #define MAX(a,b) (((a) >= (b)) ? (a) : (b))
  300. #endif SETTINGS_H