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.

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