Leaked source code of windows server 2003
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.

403 lines
9.4 KiB

  1. /*
  2. ************************************************************************
  3. *
  4. * NSC.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 NSC_H
  16. #define NSC_H
  17. #include <ndis.h>
  18. #include "dmautil.h"
  19. #include <ntddndis.h> // defines OID's
  20. #include "settings.h"
  21. #include "comm.h"
  22. #include "sync.h"
  23. #include "newdong.h"
  24. #define NSC_MAJOR_VERSION 1
  25. #define NSC_MINOR_VERSION 11
  26. #define NSC_LETTER_VERSION 's'
  27. #define NDIS_MAJOR_VERSION 5
  28. #define NDIS_MINOR_VERSION 0
  29. extern ULONG DebugSpeed;
  30. #define TIMER_RESOLTION_IN_US (125)
  31. #define TIMER_PERIODS (10)
  32. #define RECEIVE_TIMEOUT (TIMER_RESOLTION_IN_US * TIMER_PERIODS)
  33. //
  34. // Registry Keywords.
  35. //
  36. #define CARDTYPE NDIS_STRING_CONST("BoardType")
  37. #define DONGLE_A_TYPE NDIS_STRING_CONST("Dongle_A_Type")
  38. #define DONGLE_B_TYPE NDIS_STRING_CONST("Dongle_B_Type")
  39. #define MAXCONNECTRATE NDIS_STRING_CONST("MaxConnectRate")
  40. //
  41. // bank 0
  42. //
  43. #define BANK_0 (0)
  44. #define TXD_RXD_OFFSET (0)
  45. #define LCR_BSR_OFFSET (3)
  46. #define LSR_OFFSET (5)
  47. #define ASCR_OFFSET (7)
  48. //
  49. // bank 2
  50. //
  51. #define BANK_2 (2)
  52. #define TXFLV_OFFSET (6)
  53. #define BANK_4 (4)
  54. #define TFRCCL_OFFSET (4)
  55. #define TFRCCH_OFFSET (4)
  56. #define BKSE (1 << 7)
  57. #define FRM_ST (5)
  58. #define RFRL_L (6)
  59. #define RFRL_H (7)
  60. #define ST_FIFO_LOST_FR (1 << 6)
  61. #define ST_FIFO_VALID (1 << 7)
  62. #define LSR_OE (1 << 1)
  63. #define LSR_TXRDY (1 << 5)
  64. #define LSR_TXEMP (1 << 6)
  65. #define LSR_FR_END (1 << 7)
  66. #define ASCR_TXUR (1 << 6)
  67. //
  68. // Valid value ranges for the DMA Channels.
  69. //
  70. #define VALID_DMACHANNELS {0xFF,0x0,0x1,0x3}
  71. #define FIR_INT_MASK 0x14
  72. //#define FIR_INT_MASK 0x50
  73. enum NSC_EXT_INTS {
  74. RXHDL_EV = (1 << 0),
  75. TXLDL_EV = (1 << 1),
  76. LS_EV = (1 << 2),
  77. MS_EV = (1 << 3),
  78. DMA_EV = (1 << 4),
  79. TXEMP_EV = (1 << 5),
  80. SFIF_EV = (1 << 6),
  81. TMR_EV = (1 << 7)
  82. };
  83. typedef struct DebugCounters {
  84. ULONG TxPacketsStarted;
  85. ULONG TxPacketsCompleted;
  86. ULONG ReceivedPackets;
  87. ULONG WindowSize;
  88. ULONG StatusFIFOOverflows;
  89. ULONG TxUnderruns;
  90. ULONG ReceiveFIFOOverflows;
  91. ULONG MissedPackets;
  92. ULONG ReceiveCRCErrors;
  93. ULONG ReturnPacketHandlerCalled;
  94. ULONG RxWindow;
  95. ULONG RxWindowMax;
  96. ULONG RxDPC_Window;
  97. ULONG RxDPC_WindowMax;
  98. ULONG RxDPC_G1_Count;
  99. } DebugCounters;
  100. /*
  101. * A receive buffer is either FREE (not holding anything) FULL
  102. * (holding undelivered data) or PENDING (holding data delivered
  103. * asynchronously)
  104. */
  105. typedef enum rcvbufferStates {
  106. STATE_FREE,
  107. STATE_FULL,
  108. STATE_PENDING
  109. } rcvBufferState;
  110. typedef struct {
  111. LIST_ENTRY listEntry;
  112. rcvBufferState state;
  113. PNDIS_PACKET packet;
  114. UINT dataLen;
  115. PUCHAR dataBuf;
  116. BOOLEAN isDmaBuf;
  117. } rcvBuffer;
  118. typedef struct _NSC_DMA_BUFFER_INFO {
  119. NDIS_HANDLE AdapterHandle;
  120. ULONG Length;
  121. PVOID VirtualAddress;
  122. NDIS_PHYSICAL_ADDRESS PhysicalAddress;
  123. BOOLEAN SharedAllocation;
  124. } NSC_DMA_BUFFER_INFO, *PNSC_DMA_BUFFER_INFO;
  125. typedef struct IrDevice {
  126. /*
  127. * This is the handle that the NDIS wrapper associates with a
  128. * connection. The handle that the miniport driver associates with
  129. * the connection is just an index into the devStates array).
  130. */
  131. NDIS_HANDLE ndisAdapterHandle;
  132. int CardType;
  133. /*
  134. * Current speed setting, in bits/sec.
  135. * (Note: this is updated when we ACTUALLY change the speed,
  136. * not when we get the request to change speed via
  137. * MiniportSetInformation).
  138. */
  139. UINT currentSpeed;
  140. // Current dongle setting, 0 for dongle A, 1 for dongle B
  141. // and so on.
  142. //
  143. UCHAR DonglesSupported;
  144. UCHAR currentDongle;
  145. UCHAR DongleTypes[2];
  146. UIR IrDongleResource;
  147. DongleParam Dingle[2];
  148. UINT AllowedSpeedMask;
  149. /*
  150. * This structure holds information about our ISR.
  151. * It is used to synchronize with the ISR.
  152. */
  153. BOOLEAN InterruptRegistered;
  154. NDIS_MINIPORT_INTERRUPT interruptObj;
  155. /*
  156. * Circular queue of pending receive buffers
  157. */
  158. #define NUM_RCV_BUFS 16
  159. // #define NEXT_RCV_BUF_INDEX(i) (((i)==NO_BUF_INDEX) ? 0 : (((i)+1)%NUM_RCV_BUFS))
  160. LIST_ENTRY rcvBufBuf; // Protected by SyncWithInterrupt
  161. LIST_ENTRY rcvBufFree; // Protected by SyncWithInterrupt
  162. LIST_ENTRY rcvBufFull; // Protected by SyncWithInterrupt
  163. LIST_ENTRY rcvBufPend; // Protected by QueueLock
  164. NDIS_SPIN_LOCK QueueLock;
  165. LIST_ENTRY SendQueue;
  166. PNDIS_PACKET CurrentPacket;
  167. BOOLEAN FirTransmitPending;
  168. BOOLEAN FirReceiveDmaActive;
  169. BOOLEAN TransmitIsIdle;
  170. BOOLEAN Halting;
  171. BOOLEAN TestingInterrupt;
  172. volatile BOOLEAN GotTestInterrupt;
  173. LONG PacketsSentToProtocol;
  174. NDIS_EVENT ReceiveStopped;
  175. NDIS_EVENT SendStoppedOnHalt;
  176. /*
  177. * Handle to NDIS packet pool, from which packets are
  178. * allocated.
  179. */
  180. NDIS_HANDLE packetPoolHandle;
  181. NDIS_HANDLE bufferPoolHandle;
  182. /*
  183. * mediaBusy is set TRUE any time that this miniport driver moves a
  184. * data frame. It can be reset by the protocol via
  185. * MiniportSetInformation and later checked via
  186. * MiniportQueryInformation to detect interleaving activity.
  187. */
  188. LONG RxInterrupts;
  189. BOOLEAN mediaBusy;
  190. BOOLEAN haveIndicatedMediaBusy;
  191. /*
  192. * nowReceiving is set while we are receiving a frame.
  193. * It (not mediaBusy) is returned to the protocol when the protocol
  194. * queries OID_MEDIA_BUSY
  195. */
  196. BOOLEAN nowReceiving;
  197. //
  198. // Interrupt Mask.
  199. //
  200. UCHAR FirIntMask;
  201. UCHAR LineStatus;
  202. UCHAR InterruptMask;
  203. UCHAR InterruptStatus;
  204. UCHAR AuxStatus;
  205. BOOLEAN ForceTurnAroundTimeout;
  206. #if DBG
  207. BOOLEAN WaitingForTurnAroundTimer;
  208. #endif
  209. /*
  210. * Current link speed information.
  211. */
  212. const baudRateInfo *linkSpeedInfo;
  213. /*
  214. * When speed is changed, we have to clear the send queue before
  215. * setting the new speed on the hardware.
  216. * These vars let us remember to do it.
  217. */
  218. PNDIS_PACKET lastPacketAtOldSpeed;
  219. BOOLEAN setSpeedAfterCurrentSendPacket;
  220. /*
  221. * Information on the COM port and send/receive FSM's.
  222. */
  223. comPortInfo portInfo;
  224. UINT hardwareStatus;
  225. /*
  226. * UIR Module ID.
  227. */
  228. int UIR_ModuleId;
  229. /*
  230. * Maintain statistical debug info.
  231. */
  232. UINT packetsRcvd;
  233. UINT packetsDropped;
  234. UINT packetsSent;
  235. UINT interruptCount;
  236. /*
  237. * DMA handles
  238. */
  239. NDIS_HANDLE DmaHandle;
  240. NDIS_HANDLE dmaBufferPoolHandle;
  241. PNDIS_BUFFER rcvDmaBuffer;
  242. PUCHAR dmaReadBuf;
  243. ULONG_PTR rcvDmaOffset;
  244. ULONG_PTR rcvDmaSize;
  245. ULONG_PTR rcvPktOffset;
  246. ULONG_PTR LastReadDMACount;
  247. PNDIS_BUFFER xmitDmaBuffer;
  248. // PUCHAR xmitDmaBufferVirtualAddress;
  249. NDIS_TIMER TurnaroundTimer;
  250. ULONG HangChk;
  251. BOOLEAN DiscardNextPacketSet;
  252. DMA_UTIL DmaUtil;
  253. NSC_DMA_BUFFER_INFO ReceiveDmaBufferInfo;
  254. NSC_DMA_BUFFER_INFO TransmitDmaBufferInfo;
  255. PUCHAR TransmitDmaBuffer;
  256. ULONG TransmitDmaLength;
  257. } IrDevice;
  258. /*
  259. * We use a pointer to the IrDevice structure as the miniport's device context.
  260. */
  261. #define CONTEXT_TO_DEV(__deviceContext) ((IrDevice *)(__deviceContext))
  262. #define DEV_TO_CONTEXT(__irdev) ((NDIS_HANDLE)(__irdev))
  263. #define ON TRUE
  264. #define OFF FALSE
  265. #include "externs.h"
  266. VOID
  267. SyncWriteBankReg(
  268. PNDIS_MINIPORT_INTERRUPT InterruptObject,
  269. PUCHAR PortBase,
  270. UINT BankNumber,
  271. UINT RegisterIndex,
  272. UCHAR Value
  273. );
  274. UCHAR
  275. SyncReadBankReg(
  276. PNDIS_MINIPORT_INTERRUPT InterruptObject,
  277. PUCHAR PortBase,
  278. UINT BankNumber,
  279. UINT RegisterIndex
  280. );
  281. VOID
  282. SyncSetInterruptMask(
  283. IrDevice *thisDev,
  284. BOOLEAN enable
  285. );
  286. BOOLEAN
  287. SyncGetFifoStatus(
  288. PNDIS_MINIPORT_INTERRUPT InterruptObject,
  289. PUCHAR PortBase,
  290. PUCHAR Status,
  291. PULONG Size
  292. );
  293. VOID
  294. ProcessSendQueue(
  295. IrDevice *thisDev
  296. );
  297. PVOID
  298. NscAllocateDmaBuffer(
  299. NDIS_HANDLE AdapterHandle,
  300. ULONG Size,
  301. PNSC_DMA_BUFFER_INFO DmaBufferInfo
  302. );
  303. VOID
  304. NscFreeDmaBuffer(
  305. PNSC_DMA_BUFFER_INFO DmaBufferInfo
  306. );
  307. #define WPP_CONTROL_GUIDS \
  308. WPP_DEFINE_CONTROL_GUID(CtlGuid,(57AC2B71,75CD,4043,9B00,B51674B0DC71), \
  309. WPP_DEFINE_BIT(DBG_LOG_ERROR) \
  310. WPP_DEFINE_BIT(DBG_LOG_INFO) \
  311. WPP_DEFINE_BIT(DBG_LOG_FIR) \
  312. WPP_DEFINE_BIT(DBG_LOG_SIR) \
  313. )
  314. #endif NSC_H