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.

521 lines
14 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. PURPOSE.
  7. Module Name:
  8. Miniport.H
  9. Abstract:
  10. This module contains structure definitons and function prototypes.
  11. Revision History:
  12. Notes:
  13. --*/
  14. #ifndef _MINIPORT_H
  15. #define _MINIPORT_H
  16. #include <ndis.h>
  17. #if defined(NDIS50_MINIPORT)
  18. #define MP_NDIS_MAJOR_VERSION 5
  19. #define MP_NDIS_MINOR_VERSION 0
  20. #elif defined(NDIS51_MINIPORT)
  21. #define MP_NDIS_MAJOR_VERSION 5
  22. #define MP_NDIS_MINOR_VERSION 1
  23. #else
  24. #error Unsupported NDIS version
  25. #endif
  26. #define ETH_HEADER_SIZE 14
  27. #define ETH_MAX_DATA_SIZE 1500
  28. #define ETH_MAX_PACKET_SIZE ETH_HEADER_SIZE + ETH_MAX_DATA_SIZE
  29. #define ETH_MIN_PACKET_SIZE 60
  30. #define NIC_TAG ((ULONG)'NIMV')
  31. // media type, we use ethernet, change if necessary
  32. #define NIC_MEDIA_TYPE NdisMedium802_3
  33. // we use Internal, change to Pci, Isa, etc. properly
  34. #define NIC_INTERFACE_TYPE NdisInterfaceInternal
  35. // change to your company name instead of using Microsoft
  36. #define NIC_VENDOR_DESC "Microsoft"
  37. // Highest byte is the NIC byte plus three vendor bytes, they are normally
  38. // obtained from the NIC
  39. #define NIC_VENDOR_ID 0x00FFFFFF
  40. // Update the driver version number every time you release a new driver
  41. // The high word is the major version. The low word is the minor version.
  42. #define NIC_VENDOR_DRIVER_VERSION 0x00010000
  43. #define NIC_MAX_MCAST_LIST 32
  44. #define NIC_MAX_BUSY_SENDS 20
  45. #define NIC_MAX_SEND_PKTS 5
  46. #define NIC_MAX_BUSY_RECVS 20
  47. #define NIC_MAX_LOOKAHEAD ETH_MAX_DATA_SIZE
  48. #define NIC_BUFFER_SIZE ETH_MAX_PACKET_SIZE
  49. #define NIC_LINK_SPEED 1000000 // in 100 bps
  50. #define NIC_SUPPORTED_FILTERS ( \
  51. NDIS_PACKET_TYPE_DIRECTED | \
  52. NDIS_PACKET_TYPE_MULTICAST | \
  53. NDIS_PACKET_TYPE_BROADCAST | \
  54. NDIS_PACKET_TYPE_PROMISCUOUS | \
  55. NDIS_PACKET_TYPE_ALL_MULTICAST)
  56. #define fMP_RESET_IN_PROGRESS 0x00000001
  57. #define fMP_DISCONNECTED 0x00000002
  58. #define fMP_ADAPTER_HALT_IN_PROGRESS 0x00000004
  59. #define fMP_ADAPTER_SURPRISE_REMOVED 0x00000008
  60. #define fMP_ADAPTER_RECV_LOOKASIDE 0x00000010
  61. //
  62. // Buffer size passed in NdisMQueryAdapterResources
  63. // We should only need three adapter resources (IO, interrupt and memory),
  64. // Some devices get extra resources, so have room for 10 resources
  65. //
  66. #define NIC_RESOURCE_BUF_SIZE (sizeof(NDIS_RESOURCE_LIST) + \
  67. (10*sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)))
  68. //
  69. // Message verbosity: lower values indicate higher urgency
  70. //
  71. #define MP_LOUD 4
  72. #define MP_INFO 3
  73. #define MP_TRACE 2
  74. #define MP_WARNING 1
  75. #define MP_ERROR 0
  76. extern INT MPDebugLevel;
  77. #if DBG
  78. #define DEBUGP(Level, Fmt) \
  79. { \
  80. if (Level <= MPDebugLevel) \
  81. { \
  82. DbgPrint("NetVMini.SYS:"); \
  83. DbgPrint Fmt; \
  84. } \
  85. }
  86. #else
  87. #define DEBUGP(Level, Fmt)
  88. #endif
  89. #ifndef min
  90. #define min(_a, _b) (((_a) < (_b)) ? (_a) : (_b))
  91. #endif
  92. #ifndef max
  93. #define max(_a, _b) (((_a) > (_b)) ? (_a) : (_b))
  94. #endif
  95. //--------------------------------------
  96. // Utility macros
  97. //--------------------------------------
  98. #define MP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
  99. #define MP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
  100. #define MP_TEST_FLAG(_M, _F) (((_M)->Flags & (_F)) != 0)
  101. #define MP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
  102. #define MP_IS_READY(_M) (((_M)->Flags & \
  103. (fMP_DISCONNECTED | fMP_RESET_IN_PROGRESS | fMP_ADAPTER_HALT_IN_PROGRESS)) == 0)
  104. #define MP_INC_REF(_A) NdisInterlockedIncrement(&(_A)->RefCount)
  105. #define MP_DEC_REF(_A) {\
  106. NdisInterlockedDecrement(&(_A)->RefCount);\
  107. ASSERT(_A->RefCount >= 0);\
  108. if((_A)->RefCount == 0){\
  109. NdisSetEvent(&(_A)->RemoveEvent);\
  110. }\
  111. }
  112. #define MP_GET_REF(_A) ((_A)->RefCount)
  113. typedef struct _MP_GLOBAL_DATA
  114. {
  115. LIST_ENTRY AdapterList;
  116. NDIS_SPIN_LOCK Lock;
  117. } MP_GLOBAL_DATA, *PMP_GLOBAL_DATA;
  118. extern MP_GLOBAL_DATA GlobalData;
  119. // TCB (Transmit Control Block)
  120. typedef struct _TCB
  121. {
  122. LIST_ENTRY List;
  123. LONG Ref;
  124. PVOID Adapter;
  125. PNDIS_BUFFER Buffer;
  126. PNDIS_PACKET OrgSendPacket;
  127. PUCHAR pData;
  128. ULONG ulSize;
  129. UCHAR Data[NIC_BUFFER_SIZE];
  130. } TCB, *PTCB;
  131. // RCB (Receive Control Block)
  132. typedef struct _RCB
  133. {
  134. LIST_ENTRY List;
  135. PNDIS_PACKET Packet;
  136. } RCB, *PRCB;
  137. typedef struct _MP_ADAPTER
  138. {
  139. LIST_ENTRY List;
  140. LONG RefCount;
  141. NDIS_EVENT RemoveEvent;
  142. //
  143. // Keep track of various device objects.
  144. //
  145. #if defined(NDIS_WDM)
  146. PDEVICE_OBJECT Pdo;
  147. PDEVICE_OBJECT Fdo;
  148. PDEVICE_OBJECT NextDeviceObject;
  149. #endif
  150. NDIS_HANDLE AdapterHandle;
  151. ULONG Flags;
  152. UCHAR PermanentAddress[ETH_LENGTH_OF_ADDRESS];
  153. UCHAR CurrentAddress[ETH_LENGTH_OF_ADDRESS];
  154. //
  155. // Variables to track resources for the send operation
  156. //
  157. NDIS_HANDLE SendBufferPoolHandle;
  158. LIST_ENTRY SendFreeList;
  159. LIST_ENTRY SendWaitList;
  160. PUCHAR TCBMem;
  161. LONG nBusySend;
  162. UINT RegNumTcb;// number of transmit control blocks the registry says
  163. NDIS_SPIN_LOCK SendLock;
  164. //
  165. // Variables to track resources for the Reset operation
  166. //
  167. NDIS_TIMER ResetTimer;
  168. LONG nResetTimerCount;
  169. //
  170. // Variables to track resources for the Receive operation
  171. //
  172. NPAGED_LOOKASIDE_LIST RecvLookaside;
  173. LIST_ENTRY RecvFreeList;
  174. LIST_ENTRY RecvWaitList;
  175. NDIS_SPIN_LOCK RecvLock;
  176. LONG nBusyRecv;
  177. NDIS_HANDLE RecvPacketPoolHandle;
  178. NDIS_HANDLE RecvPacketPool; // not used
  179. NDIS_HANDLE RecvBufferPool; // not used
  180. NDIS_TIMER RecvTimer;
  181. //
  182. // Packet Filter and look ahead size.
  183. //
  184. ULONG PacketFilter;
  185. ULONG ulLookAhead;
  186. ULONG ulLinkSpeed;
  187. ULONG ulMaxBusySends;
  188. ULONG ulMaxBusyRecvs;
  189. // multicast list
  190. ULONG ulMCListSize;
  191. UCHAR MCList[NIC_MAX_MCAST_LIST][ETH_LENGTH_OF_ADDRESS];
  192. // Packet counts
  193. ULONG64 GoodTransmits;
  194. ULONG64 GoodReceives;
  195. ULONG NumTxSinceLastAdjust;
  196. // Count of transmit errors
  197. ULONG TxAbortExcessCollisions;
  198. ULONG TxLateCollisions;
  199. ULONG TxDmaUnderrun;
  200. ULONG TxLostCRS;
  201. ULONG TxOKButDeferred;
  202. ULONG OneRetry;
  203. ULONG MoreThanOneRetry;
  204. ULONG TotalRetries;
  205. ULONG TransmitFailuresOther;
  206. // Count of receive errors
  207. ULONG RcvCrcErrors;
  208. ULONG RcvAlignmentErrors;
  209. ULONG RcvResourceErrors;
  210. ULONG RcvDmaOverrunErrors;
  211. ULONG RcvCdtFrames;
  212. ULONG RcvRuntErrors;
  213. } MP_ADAPTER, *PMP_ADAPTER;
  214. //--------------------------------------
  215. // Miniport routines
  216. //--------------------------------------
  217. NDIS_STATUS
  218. DriverEntry(
  219. IN PVOID DriverObject,
  220. IN PVOID RegistryPath);
  221. NDIS_STATUS
  222. MPInitialize(
  223. OUT PNDIS_STATUS OpenErrorStatus,
  224. OUT PUINT SelectedMediumIndex,
  225. IN PNDIS_MEDIUM MediumArray,
  226. IN UINT MediumArraySize,
  227. IN NDIS_HANDLE MiniportAdapterHandle,
  228. IN NDIS_HANDLE WrapperConfigurationContext);
  229. VOID
  230. MPAllocateComplete(
  231. NDIS_HANDLE MiniportAdapterContext,
  232. IN PVOID VirtualAddress,
  233. IN PNDIS_PHYSICAL_ADDRESS PhysicalAddress,
  234. IN ULONG Length,
  235. IN PVOID Context);
  236. BOOLEAN
  237. MPCheckForHang(
  238. IN NDIS_HANDLE MiniportAdapterContext);
  239. VOID
  240. MPHalt(
  241. IN NDIS_HANDLE MiniportAdapterContext);
  242. VOID
  243. MPHandleInterrupt(
  244. IN NDIS_HANDLE MiniportAdapterContext);
  245. VOID
  246. MPUnload(
  247. IN PDRIVER_OBJECT DriverObject
  248. );
  249. VOID
  250. MPDisableInterrupt(
  251. IN PVOID Adapter);
  252. VOID
  253. MPEnableInterrupt(
  254. IN PVOID Adapter);
  255. VOID
  256. MPIsr(
  257. OUT PBOOLEAN InterruptRecognized,
  258. OUT PBOOLEAN QueueMiniportHandleInterrupt,
  259. IN NDIS_HANDLE MiniportAdapterContext);
  260. NDIS_STATUS
  261. MPQueryInformation(
  262. IN NDIS_HANDLE MiniportAdapterContext,
  263. IN NDIS_OID Oid,
  264. IN PVOID InformationBuffer,
  265. IN ULONG InformationBufferLength,
  266. OUT PULONG BytesWritten,
  267. OUT PULONG BytesNeeded);
  268. NDIS_STATUS
  269. MPReset(
  270. OUT PBOOLEAN AddressingReset,
  271. IN NDIS_HANDLE MiniportAdapterContext);
  272. VOID
  273. MPReturnPacket(
  274. IN NDIS_HANDLE MiniportAdapterContext,
  275. IN PNDIS_PACKET Packet);
  276. VOID
  277. MPSendPackets(
  278. IN NDIS_HANDLE MiniportAdapterContext,
  279. IN PPNDIS_PACKET PacketArray,
  280. IN UINT NumberOfPackets);
  281. NDIS_STATUS
  282. MPSetInformation(
  283. IN NDIS_HANDLE MiniportAdapterContext,
  284. IN NDIS_OID Oid,
  285. IN PVOID InformationBuffer,
  286. IN ULONG InformationBufferLength,
  287. OUT PULONG BytesRead,
  288. OUT PULONG BytesNeeded);
  289. VOID
  290. MPShutdown(
  291. IN NDIS_HANDLE MiniportAdapterContext);
  292. NDIS_STATUS
  293. NICSendPacket(
  294. PMP_ADAPTER Adapter,
  295. PNDIS_PACKET Pakcet);
  296. BOOLEAN
  297. NICCopyPacket(
  298. PMP_ADAPTER Adapter,
  299. PTCB pTCB,
  300. PNDIS_PACKET Packet);
  301. VOID
  302. NICQueuePacketForRecvIndication(
  303. PMP_ADAPTER Adapter,
  304. PTCB pTCB);
  305. VOID
  306. NICFreeRecvPacket(
  307. PMP_ADAPTER Adapter,
  308. PNDIS_PACKET Packet);
  309. VOID
  310. NICFreeSendTCB(
  311. IN PMP_ADAPTER Adapter,
  312. IN PTCB pTCB);
  313. VOID
  314. NICResetCompleteTimerDpc(
  315. IN PVOID SystemSpecific1,
  316. IN PVOID FunctionContext,
  317. IN PVOID SystemSpecific2,
  318. IN PVOID SystemSpecific3);
  319. VOID
  320. NICFreeQueuedSendPackets(
  321. PMP_ADAPTER Adapter
  322. );
  323. NDIS_STATUS
  324. NICInitializeAdapter(
  325. IN PMP_ADAPTER Adapter,
  326. IN NDIS_HANDLE WrapperConfigurationContext
  327. );
  328. NDIS_STATUS
  329. NICAllocAdapter(
  330. PMP_ADAPTER *Adapter
  331. );
  332. void
  333. NICFreeAdapter(
  334. PMP_ADAPTER Adapter
  335. );
  336. void
  337. NICAttachAdapter(
  338. PMP_ADAPTER Adapter
  339. );
  340. void
  341. NICDetachAdapter(
  342. PMP_ADAPTER Adapter
  343. );
  344. NDIS_STATUS
  345. NICReadRegParameters(
  346. PMP_ADAPTER Adapter,
  347. NDIS_HANDLE ConfigurationHandle);
  348. NDIS_STATUS
  349. NICGetStatsCounters(
  350. PMP_ADAPTER Adapter,
  351. NDIS_OID Oid,
  352. PULONG pCounter);
  353. NDIS_STATUS
  354. NICSetPacketFilter(
  355. IN PMP_ADAPTER Adapter,
  356. IN ULONG PacketFilter);
  357. NDIS_STATUS NICSetMulticastList(
  358. IN PMP_ADAPTER Adapter,
  359. IN PVOID InformationBuffer,
  360. IN ULONG InformationBufferLength,
  361. OUT PULONG pBytesRead,
  362. OUT PULONG pBytesNeeded
  363. );
  364. ULONG
  365. NICGetMediaConnectStatus(
  366. PMP_ADAPTER Adapter);
  367. #ifdef NDIS51_MINIPORT
  368. VOID
  369. MPCancelSendPackets(
  370. IN NDIS_HANDLE MiniportAdapterContext,
  371. IN PVOID CancelId
  372. );
  373. VOID MPPnPEventNotify(
  374. IN NDIS_HANDLE MiniportAdapterContext,
  375. IN NDIS_DEVICE_PNP_EVENT PnPEvent,
  376. IN PVOID InformationBuffer,
  377. IN ULONG InformationBufferLength
  378. );
  379. #endif
  380. VOID
  381. NICIndicateReceiveTimerDpc(
  382. IN PVOID SystemSpecific1,
  383. IN PVOID FunctionContext,
  384. IN PVOID SystemSpecific2,
  385. IN PVOID SystemSpecific3);
  386. BOOLEAN
  387. NICIsPacketTransmittable(
  388. PMP_ADAPTER Adapter,
  389. PNDIS_PACKET Packet
  390. );
  391. VOID
  392. NICFreeQueuedRecvPackets(
  393. PMP_ADAPTER Adapter
  394. );
  395. PUCHAR
  396. DbgGetOidName
  397. (ULONG oid
  398. );
  399. #if defined(IOCTL_INTERFACE)
  400. NDIS_STATUS
  401. NICRegisterDevice(
  402. VOID
  403. );
  404. NDIS_STATUS
  405. NICDeregisterDevice(
  406. VOID
  407. );
  408. NTSTATUS
  409. NICDispatch(
  410. IN PDEVICE_OBJECT DeviceObject,
  411. IN PIRP Irp
  412. );
  413. #else
  414. #define NICRegisterDevice()
  415. #define NICDeregisterDevice()
  416. #define NICDispatch()
  417. #endif
  418. #endif // _MINIPORT_H