ReactOS 0.4.15-dev-7931-gfd331f1
ndis.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Intel PRO/1000 Driver
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Driver entrypoint
5 * COPYRIGHT: Copyright 2013 Cameron Gutman (cameron.gutman@reactos.org)
6 * Copyright 2018 Mark Jansen (mark.jansen@reactos.org)
7 */
8
9#include "nic.h"
10
11#include <debug.h>
12
14
18 OUT PBOOLEAN AddressingReset,
19 IN NDIS_HANDLE MiniportAdapterContext)
20{
21 *AddressingReset = FALSE;
24}
25
26VOID
29 IN NDIS_HANDLE MiniportAdapterContext)
30{
31 PE1000_ADAPTER Adapter = (PE1000_ADAPTER)MiniportAdapterContext;
32
33 ASSERT(Adapter != NULL);
34
35 /* First disable sending / receiving */
36 NICDisableTxRx(Adapter);
37
38 /* Then unregister interrupts */
40
41 /* Finally, free other resources (Ports, IO ranges,...) */
42 NICReleaseIoResources(Adapter);
43
44 /* Destroy the adapter context */
45 NdisFreeMemory(Adapter, sizeof(*Adapter), 0);
46}
47
53 IN PNDIS_MEDIUM MediumArray,
57{
58 PE1000_ADAPTER Adapter;
60 UINT i;
62 UINT ResourceListSize;
63 PCI_COMMON_CONFIG PciConfig;
64
65 /* Make sure the medium is supported */
66 for (i = 0; i < MediumArraySize; i++)
67 {
68 if (MediumArray[i] == NdisMedium802_3)
69 {
71 break;
72 }
73 }
74
75 if (i == MediumArraySize)
76 {
77 NDIS_DbgPrint(MIN_TRACE, ("802.3 medium was not found in the medium array\n"));
79 }
80
82 ResourceListSize = 0;
83
84 /* Allocate our adapter context */
86 sizeof(*Adapter),
87 E1000_TAG);
89 {
90 NDIS_DbgPrint(MIN_TRACE, ("Failed to allocate adapter context (0x%x)\n", Status));
92 }
93
94 RtlZeroMemory(Adapter, sizeof(*Adapter));
96
97 /* Notify NDIS of some characteristics of our NIC */
99 Adapter,
100 0,
103
105 0,
107 &PciConfig, sizeof(PciConfig));
108
109 Adapter->VendorID = PciConfig.VendorID;
110 Adapter->DeviceID = PciConfig.DeviceID;
111
112 Adapter->SubsystemID = PciConfig.u.type0.SubSystemID;
113 Adapter->SubsystemVendorID = PciConfig.u.type0.SubVendorID;
114
115
116 if (!NICRecognizeHardware(Adapter))
117 {
118 NDIS_DbgPrint(MIN_TRACE, ("Hardware not recognized\n"));
120 goto Cleanup;
121 }
122
123 /* Get our resources for IRQ and IO base information */
127 &ResourceListSize);
129 {
130 NDIS_DbgPrint(MIN_TRACE, ("Unexpected failure of NdisMQueryAdapterResources (0x%x)\n", Status));
132 /* call NdisWriteErrorLogEntry */
133 goto Cleanup;
134 }
135
137 ResourceListSize,
138 E1000_TAG);
140 {
141 NDIS_DbgPrint(MIN_TRACE, ("Failed to allocate resource list (0x%x)\n", Status));
142 /* call NdisWriteErrorLogEntry */
143 goto Cleanup;
144 }
145
149 &ResourceListSize);
151 {
152 NDIS_DbgPrint(MIN_TRACE, ("Unexpected failure of NdisMQueryAdapterResources (0x%x)\n", Status));
153 /* call NdisWriteErrorLogEntry */
154 goto Cleanup;
155 }
156
157 ASSERT(ResourceList->Version == 1);
158 ASSERT(ResourceList->Revision == 1);
159
161
162 NdisFreeMemory(ResourceList, ResourceListSize, 0);
164
166 {
167 NDIS_DbgPrint(MIN_TRACE, ("Adapter didn't receive enough resources\n"));
168 goto Cleanup;
169 }
170
171 /* Allocate the DMA resources */
173 FALSE, // 64bit is supported but can be buggy
176 {
177 NDIS_DbgPrint(MIN_TRACE, ("Unable to configure DMA\n"));
179 goto Cleanup;
180 }
181
184 {
185 NDIS_DbgPrint(MIN_TRACE, ("Unable to allocate resources\n"));
187 goto Cleanup;
188 }
189
190 /* Adapter setup */
191 Status = NICPowerOn(Adapter);
193 {
194 NDIS_DbgPrint(MIN_TRACE, ("Unable to power on NIC (0x%x)\n", Status));
195 goto Cleanup;
196 }
197
198 Status = NICSoftReset(Adapter);
200 {
201 NDIS_DbgPrint(MIN_TRACE, ("Unable to reset the NIC (0x%x)\n", Status));
202 goto Cleanup;
203 }
204
207 {
208 NDIS_DbgPrint(MIN_TRACE, ("Unable to get the fixed MAC address (0x%x)\n", Status));
209 goto Cleanup;
210 }
211
212 RtlCopyMemory(Adapter->MulticastList[0].MacAddress, Adapter->PermanentMacAddress, IEEE_802_ADDR_LENGTH);
213
214 NICUpdateMulticastList(Adapter);
215
216 /* Update link state and speed */
217 NICUpdateLinkStatus(Adapter);
218
219 /* We're ready to handle interrupts now */
220 Status = NICRegisterInterrupts(Adapter);
222 {
223 NDIS_DbgPrint(MIN_TRACE, ("Unable to register interrupt (0x%x)\n", Status));
224 goto Cleanup;
225 }
226
227 /* Enable interrupts on the NIC */
229 NICApplyInterruptMask(Adapter);
230
231 /* Turn on TX and RX now */
232 Status = NICEnableTxRx(Adapter);
234 {
235 NDIS_DbgPrint(MIN_TRACE, ("Unable to enable TX and RX (0x%x)\n", Status));
236 goto Cleanup;
237 }
238
239 return NDIS_STATUS_SUCCESS;
240
241Cleanup:
242 if (ResourceList != NULL)
243 {
244 NdisFreeMemory(ResourceList, ResourceListSize, 0);
245 }
246
247 MiniportHalt(Adapter);
248
249 return Status;
250}
251
253NTAPI
257{
258 NDIS_HANDLE WrapperHandle;
259 NDIS_MINIPORT_CHARACTERISTICS Characteristics = { 0 };
261
262 Characteristics.MajorNdisVersion = NDIS_MINIPORT_MAJOR_VERSION;
263 Characteristics.MinorNdisVersion = NDIS_MINIPORT_MINOR_VERSION;
264 Characteristics.CheckForHangHandler = NULL;
265 Characteristics.DisableInterruptHandler = NULL;
266 Characteristics.EnableInterruptHandler = NULL;
267 Characteristics.HaltHandler = MiniportHalt;
268 Characteristics.HandleInterruptHandler = MiniportHandleInterrupt;
269 Characteristics.InitializeHandler = MiniportInitialize;
270 Characteristics.ISRHandler = MiniportISR;
271 Characteristics.QueryInformationHandler = MiniportQueryInformation;
272 Characteristics.ReconfigureHandler = NULL;
273 Characteristics.ResetHandler = MiniportReset;
274 Characteristics.SendHandler = MiniportSend;
275 Characteristics.SetInformationHandler = MiniportSetInformation;
276 Characteristics.TransferDataHandler = NULL;
277 Characteristics.ReturnPacketHandler = NULL;
278 Characteristics.SendPacketsHandler = NULL;
279 Characteristics.AllocateCompleteHandler = NULL;
280
282 if (!WrapperHandle)
283 {
284 return NDIS_STATUS_FAILURE;
285 }
286
287 Status = NdisMRegisterMiniport(WrapperHandle, &Characteristics, sizeof(Characteristics));
289 {
290 NdisTerminateWrapper(WrapperHandle, 0);
291 return NDIS_STATUS_FAILURE;
292 }
293
294 return NDIS_STATUS_SUCCESS;
295}
LONG NTSTATUS
Definition: precomp.h:26
#define MIN_TRACE
Definition: debug.h:14
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
static const WCHAR Cleanup[]
Definition: register.c:80
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
#define UNIMPLEMENTED_DBGBREAK(...)
Definition: debug.h:57
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
NDIS_STATUS NTAPI NICRegisterInterrupts(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:392
NDIS_STATUS NTAPI NICPowerOn(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:509
NDIS_STATUS NTAPI NICEnableTxRx(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:574
NDIS_STATUS NTAPI NICSoftReset(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:531
BOOLEAN NTAPI NICRecognizeHardware(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:214
NDIS_STATUS NTAPI NICGetPermanentMacAddress(IN PE1000_ADAPTER Adapter, OUT PUCHAR MacAddress)
Definition: hardware.c:661
NDIS_STATUS NTAPI NICAllocateIoResources(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:309
VOID NTAPI NICUpdateLinkStatus(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:740
NDIS_STATUS NTAPI NICReleaseIoResources(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:433
NDIS_STATUS NTAPI NICDisableTxRx(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:641
NDIS_STATUS NTAPI NICUpdateMulticastList(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:693
NDIS_STATUS NTAPI NICUnregisterInterrupts(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:417
NDIS_STATUS NTAPI NICInitializeAdapterResources(IN PE1000_ADAPTER Adapter, IN PNDIS_RESOURCE_LIST ResourceList)
Definition: hardware.c:241
NDIS_STATUS NTAPI MiniportSetInformation(IN NDIS_HANDLE MiniportAdapterContext, IN NDIS_OID Oid, IN PVOID InformationBuffer, IN ULONG InformationBufferLength, OUT PULONG BytesRead, OUT PULONG BytesNeeded)
Definition: info.c:276
NDIS_STATUS NTAPI MiniportQueryInformation(IN NDIS_HANDLE MiniportAdapterContext, IN NDIS_OID Oid, IN PVOID InformationBuffer, IN ULONG InformationBufferLength, OUT PULONG BytesWritten, OUT PULONG BytesNeeded)
Definition: info.c:73
VOID NTAPI MiniportISR(OUT PBOOLEAN InterruptRecognized, OUT PBOOLEAN QueueMiniportHandleInterrupt, IN NDIS_HANDLE MiniportAdapterContext)
Definition: interrupt.c:16
VOID NTAPI MiniportHandleInterrupt(IN NDIS_HANDLE MiniportAdapterContext)
Definition: interrupt.c:46
ULONG EXPORT NdisReadPciSlotInformation(IN NDIS_HANDLE NdisAdapterHandle, IN ULONG SlotNumber, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length)
Definition: hardware.c:180
VOID EXPORT NdisMQueryAdapterResources(OUT PNDIS_STATUS Status, IN NDIS_HANDLE WrapperConfigurationContext, OUT PNDIS_RESOURCE_LIST ResourceList, IN OUT PUINT BufferSize)
Definition: hardware.c:103
NDIS_STATUS EXPORT NdisMInitializeScatterGatherDma(IN NDIS_HANDLE MiniportAdapterHandle, IN BOOLEAN Dma64BitAddresses, IN ULONG MaximumPhysicalMapping)
Definition: io.c:1169
VOID EXPORT NdisFreeMemory(IN PVOID VirtualAddress, IN UINT Length, IN UINT MemoryFlags)
Definition: memory.c:110
NDIS_STATUS EXPORT NdisAllocateMemoryWithTag(OUT PVOID *VirtualAddress, IN UINT Length, IN ULONG Tag)
Definition: memory.c:21
ULONG DebugTraceLevel
Definition: ndis.c:13
NDIS_STATUS NTAPI MiniportInitialize(OUT PNDIS_STATUS OpenErrorStatus, OUT PUINT SelectedMediumIndex, IN PNDIS_MEDIUM MediumArray, IN UINT MediumArraySize, IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_HANDLE WrapperConfigurationContext)
Definition: ndis.c:50
VOID NTAPI MiniportHalt(IN NDIS_HANDLE MiniportAdapterContext)
Definition: ndis.c:28
NDIS_STATUS NTAPI MiniportReset(OUT PBOOLEAN AddressingReset, IN NDIS_HANDLE MiniportAdapterContext)
Definition: ndis.c:17
#define MAXIMUM_FRAME_SIZE
Definition: nic.h:19
struct _E1000_ADAPTER * PE1000_ADAPTER
#define DEFAULT_INTERRUPT_MASK
Definition: nic.h:24
NDIS_STATUS NTAPI MiniportSend(_In_ NDIS_HANDLE MiniportAdapterContext, _In_ PNDIS_PACKET Packet, _In_ UINT Flags)
Definition: send.c:49
FORCEINLINE VOID NICApplyInterruptMask(_In_ PE1000_ADAPTER Adapter)
Definition: nic.h:243
#define E1000_TAG
Definition: nic.h:17
#define IEEE_802_ADDR_LENGTH
Definition: e1000hw.h:11
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ASSERT(a)
Definition: mode.c:44
unsigned int * PUINT
Definition: ndis.h:50
unsigned int UINT
Definition: ndis.h:50
#define NDIS_ATTRIBUTE_BUS_MASTER
Definition: ndis.h:586
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _Out_ PUINT SelectedMediumIndex
Definition: ndis.h:6011
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _Out_ PUINT _In_ UINT MediumArraySize
Definition: ndis.h:6013
@ NdisInterfacePci
Definition: ndis.h:905
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _In_ NDIS_HANDLE WrapperConfigurationContext
Definition: ndis.h:3946
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
#define NDIS_STATUS_UNSUPPORTED_MEDIA
Definition: ndis.h:490
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS OpenErrorStatus
Definition: ndis.h:6009
#define NdisMInitializeWrapper(NdisWrapperHandle, SystemSpecific1, SystemSpecific2, SystemSpecific3)
Definition: ndis.h:5592
* PNDIS_STATUS
Definition: ndis.h:45
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
VOID EXPORT NdisMSetAttributesEx(IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_HANDLE MiniportAdapterContext, IN UINT CheckForHangTimeInSeconds OPTIONAL, IN ULONG AttributeFlags, IN NDIS_INTERFACE_TYPE AdapterType)
Definition: miniport.c:2883
NDIS_STATUS EXPORT NdisMRegisterMiniport(IN NDIS_HANDLE NdisWrapperHandle, IN PNDIS_MINIPORT_CHARACTERISTICS MiniportCharacteristics, IN UINT CharacteristicsLength)
Definition: miniport.c:2637
VOID EXPORT NdisTerminateWrapper(IN NDIS_HANDLE NdisWrapperHandle, IN PVOID SystemSpecific)
Definition: miniport.c:3012
enum _NDIS_MEDIUM * PNDIS_MEDIUM
@ NdisMedium802_3
Definition: ntddndis.h:188
int NDIS_STATUS
Definition: ntddndis.h:475
LONG InterruptMask
Definition: nic.h:67
USHORT SubsystemID
Definition: nic.h:39
struct _E1000_ADAPTER::@990 MulticastList[MAXIMUM_MULTICAST_ADDRESSES]
UCHAR PermanentMacAddress[IEEE_802_ADDR_LENGTH]
Definition: nic.h:42
USHORT DeviceID
Definition: nic.h:38
NDIS_HANDLE AdapterHandle
Definition: nic.h:36
USHORT SubsystemVendorID
Definition: nic.h:40
USHORT VendorID
Definition: nic.h:37
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
unsigned char * PBOOLEAN
Definition: typedefs.h:53
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309