ReactOS 0.4.15-dev-7712-gbbbcd8e
hardware.c File Reference
#include "nic.h"
#include <debug.h>
Include dependency graph for hardware.c:

Go to the source code of this file.

Functions

static ULONG PacketFilterToMask (ULONG PacketFilter)
 
static ULONG RcvBufAllocationSize (E1000_RCVBUF_SIZE BufSize)
 
static ULONG RcvBufRegisterMask (E1000_RCVBUF_SIZE BufSize)
 
static BOOLEAN E1000ReadEeprom (IN PE1000_ADAPTER Adapter, IN UCHAR Address, USHORT *Result)
 
BOOLEAN E1000ValidateNvmChecksum (IN PE1000_ADAPTER Adapter)
 
BOOLEAN NTAPI NICRecognizeHardware (IN PE1000_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICInitializeAdapterResources (IN PE1000_ADAPTER Adapter, IN PNDIS_RESOURCE_LIST ResourceList)
 
NDIS_STATUS NTAPI NICAllocateIoResources (IN PE1000_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICRegisterInterrupts (IN PE1000_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICUnregisterInterrupts (IN PE1000_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICReleaseIoResources (IN PE1000_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICPowerOn (IN PE1000_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICSoftReset (IN PE1000_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICEnableTxRx (IN PE1000_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICDisableTxRx (IN PE1000_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICGetPermanentMacAddress (IN PE1000_ADAPTER Adapter, OUT PUCHAR MacAddress)
 
NDIS_STATUS NTAPI NICUpdateMulticastList (IN PE1000_ADAPTER Adapter)
 
NDIS_STATUS NTAPI NICApplyPacketFilter (IN PE1000_ADAPTER Adapter)
 
VOID NTAPI NICUpdateLinkStatus (IN PE1000_ADAPTER Adapter)
 

Variables

static USHORT SupportedDevices []
 

Function Documentation

◆ E1000ReadEeprom()

static BOOLEAN E1000ReadEeprom ( IN PE1000_ADAPTER  Adapter,
IN UCHAR  Address,
USHORT Result 
)
static

Definition at line 162 of file hardware.c.

163{
164 ULONG Value;
165 UINT n;
166
168
169 for (n = 0; n < MAX_EEPROM_READ_ATTEMPTS; ++n)
170 {
172
174
176 break;
177 }
178 if (!(Value & E1000_EERD_DONE))
179 {
180 NDIS_DbgPrint(MIN_TRACE, ("EEPROM Read incomplete\n"));
181 return FALSE;
182 }
184 return TRUE;
185}
#define MIN_TRACE
Definition: debug.h:14
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
FORCEINLINE VOID E1000ReadUlong(_In_ PE1000_ADAPTER Adapter, _In_ ULONG Address, _Out_ PULONG Value)
Definition: nic.h:209
FORCEINLINE VOID E1000WriteUlong(_In_ PE1000_ADAPTER Adapter, _In_ ULONG Address, _In_ ULONG Value)
Definition: nic.h:219
#define E1000_EERD_DONE
Definition: e1000hw.h:167
#define MAX_EEPROM_READ_ATTEMPTS
Definition: e1000hw.h:20
#define E1000_EERD_START
Definition: e1000hw.h:166
#define E1000_REG_EERD
Definition: e1000hw.h:116
#define E1000_EERD_DATA_SHIFT
Definition: e1000hw.h:169
#define E1000_EERD_ADDR_SHIFT
Definition: e1000hw.h:168
GLdouble n
Definition: glext.h:7729
unsigned int UINT
Definition: ndis.h:50
#define NdisStallExecution
Definition: ndis.h:4453
unsigned short USHORT
Definition: pedump.c:61
static WCHAR Address[46]
Definition: ping.c:68
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by E1000ValidateNvmChecksum(), and NICGetPermanentMacAddress().

◆ E1000ValidateNvmChecksum()

BOOLEAN E1000ValidateNvmChecksum ( IN PE1000_ADAPTER  Adapter)

Definition at line 187 of file hardware.c.

188{
189 USHORT Checksum = 0, Data;
190 UINT n;
191
192 /* 5.6.35 Checksum Word Calculation (Word 3Fh) */
193 for (n = 0; n <= E1000_NVM_REG_CHECKSUM; n++)
194 {
195 if (!E1000ReadEeprom(Adapter, n, &Data))
196 {
197 return FALSE;
198 }
199 Checksum += Data;
200 }
201
202 if (Checksum != NVM_MAGIC_SUM)
203 {
204 NDIS_DbgPrint(MIN_TRACE, ("EEPROM has an invalid checksum of 0x%x\n", (ULONG)Checksum));
205 return FALSE;
206 }
207
208 return TRUE;
209}
static BOOLEAN E1000ReadEeprom(IN PE1000_ADAPTER Adapter, IN UCHAR Address, USHORT *Result)
Definition: hardware.c:162
#define E1000_NVM_REG_CHECKSUM
Definition: e1000hw.h:227
#define NVM_MAGIC_SUM
Definition: e1000hw.h:228

Referenced by NICPowerOn().

◆ NICAllocateIoResources()

NDIS_STATUS NTAPI NICAllocateIoResources ( IN PE1000_ADAPTER  Adapter)

Definition at line 309 of file hardware.c.

311{
314 UINT n;
315
316 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
317
318 Status = NdisMRegisterIoPortRange((PVOID*)&Adapter->IoPort,
319 Adapter->AdapterHandle,
320 Adapter->IoPortAddress,
321 Adapter->IoPortLength);
323 {
324 NDIS_DbgPrint(MIN_TRACE, ("Unable to register IO port range (0x%x)\n", Status));
326 }
327
328 Status = NdisMMapIoSpace((PVOID*)&Adapter->IoBase,
329 Adapter->AdapterHandle,
330 Adapter->IoAddress,
331 Adapter->IoLength);
332
333
334 NdisMAllocateSharedMemory(Adapter->AdapterHandle,
336 FALSE,
337 (PVOID*)&Adapter->TransmitDescriptors,
338 &Adapter->TransmitDescriptorsPa);
339 if (Adapter->TransmitDescriptors == NULL)
340 {
341 NDIS_DbgPrint(MIN_TRACE, ("Unable to allocate transmit descriptors\n"));
343 }
344
345 for (n = 0; n < NUM_TRANSMIT_DESCRIPTORS; ++n)
346 {
347 PE1000_TRANSMIT_DESCRIPTOR Descriptor = Adapter->TransmitDescriptors + n;
348 Descriptor->Address = 0;
349 Descriptor->Length = 0;
350 }
351
352 NdisMAllocateSharedMemory(Adapter->AdapterHandle,
354 FALSE,
355 (PVOID*)&Adapter->ReceiveDescriptors,
356 &Adapter->ReceiveDescriptorsPa);
357 if (Adapter->ReceiveDescriptors == NULL)
358 {
359 NDIS_DbgPrint(MIN_TRACE, ("Unable to allocate receive descriptors\n"));
361 }
362
363 AllocationSize = RcvBufAllocationSize(Adapter->ReceiveBufferType);
364 ASSERT(Adapter->ReceiveBufferEntrySize == 0 || Adapter->ReceiveBufferEntrySize == AllocationSize);
365 Adapter->ReceiveBufferEntrySize = AllocationSize;
366
367 NdisMAllocateSharedMemory(Adapter->AdapterHandle,
368 Adapter->ReceiveBufferEntrySize * NUM_RECEIVE_DESCRIPTORS,
369 FALSE,
370 (PVOID*)&Adapter->ReceiveBuffer,
371 &Adapter->ReceiveBufferPa);
372
373 if (Adapter->ReceiveBuffer == NULL)
374 {
375 NDIS_DbgPrint(MIN_TRACE, ("Unable to allocate receive buffer\n"));
377 }
378
379 for (n = 0; n < NUM_RECEIVE_DESCRIPTORS; ++n)
380 {
381 PE1000_RECEIVE_DESCRIPTOR Descriptor = Adapter->ReceiveDescriptors + n;
382
384 Descriptor->Address = Adapter->ReceiveBufferPa.QuadPart + n * Adapter->ReceiveBufferEntrySize;
385 }
386
387 return NDIS_STATUS_SUCCESS;
388}
#define MAX_TRACE
Definition: debug.h:16
#define NULL
Definition: types.h:112
static ULONG RcvBufAllocationSize(E1000_RCVBUF_SIZE BufSize)
Definition: hardware.c:86
NDIS_STATUS EXPORT NdisMMapIoSpace(OUT PVOID *VirtualAddress, IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_PHYSICAL_ADDRESS PhysicalAddress, IN UINT Length)
Definition: io.c:774
NDIS_STATUS EXPORT NdisMRegisterIoPortRange(OUT PVOID *PortOffset, IN NDIS_HANDLE MiniportAdapterHandle, IN UINT InitialPort, IN UINT NumberOfPorts)
Definition: io.c:1018
VOID EXPORT NdisMAllocateSharedMemory(IN NDIS_HANDLE MiniportAdapterHandle, IN ULONG Length, IN BOOLEAN Cached, OUT PVOID *VirtualAddress, OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress)
Definition: memory.c:148
#define NUM_RECEIVE_DESCRIPTORS
Definition: e1000hw.h:109
#define NUM_TRANSMIT_DESCRIPTORS
Definition: e1000hw.h:108
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:322
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
int NDIS_STATUS
Definition: ntddndis.h:475
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342

Referenced by MiniportInitialize().

◆ NICApplyPacketFilter()

NDIS_STATUS NTAPI NICApplyPacketFilter ( IN PE1000_ADAPTER  Adapter)

Definition at line 724 of file hardware.c.

726{
727 ULONG FilterMask;
728
729 E1000ReadUlong(Adapter, E1000_REG_RCTL, &FilterMask);
730
731 FilterMask &= ~E1000_RCTL_FILTER_BITS;
732 FilterMask |= PacketFilterToMask(Adapter->PacketFilter);
733 E1000WriteUlong(Adapter, E1000_REG_RCTL, FilterMask);
734
735 return NDIS_STATUS_SUCCESS;
736}
static ULONG PacketFilterToMask(ULONG PacketFilter)
Definition: hardware.c:56
#define E1000_REG_RCTL
Definition: e1000hw.h:125

Referenced by MiniportSetInformation().

◆ NICDisableTxRx()

NDIS_STATUS NTAPI NICDisableTxRx ( IN PE1000_ADAPTER  Adapter)

Definition at line 641 of file hardware.c.

643{
644 ULONG Value;
645
646 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
647
649 Value &= ~E1000_TCTL_EN;
651
653 Value &= ~E1000_RCTL_EN;
655
656 return NDIS_STATUS_SUCCESS;
657}
#define E1000_REG_TCTL
Definition: e1000hw.h:126

Referenced by MiniportHalt().

◆ NICEnableTxRx()

NDIS_STATUS NTAPI NICEnableTxRx ( IN PE1000_ADAPTER  Adapter)

Definition at line 574 of file hardware.c.

576{
577 ULONG Value;
578
579 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
580 NDIS_DbgPrint(MID_TRACE, ("Setting up transmit.\n"));
581
582 /* Make sure the thing is disabled first. */
583 E1000WriteUlong(Adapter, E1000_REG_TCTL, 0);
584
585 /* Transmit descriptor ring buffer */
586 E1000WriteUlong(Adapter, E1000_REG_TDBAH, Adapter->TransmitDescriptorsPa.HighPart);
587 E1000WriteUlong(Adapter, E1000_REG_TDBAL, Adapter->TransmitDescriptorsPa.LowPart);
588
589 /* Transmit descriptor buffer size */
591
592 /* Transmit descriptor tail / head */
593 E1000WriteUlong(Adapter, E1000_REG_TDH, 0);
594 E1000WriteUlong(Adapter, E1000_REG_TDT, 0);
595 Adapter->CurrentTxDesc = 0;
596
597 /* Set up interrupt timers */
598 E1000WriteUlong(Adapter, E1000_REG_TADV, 96); // value is in 1.024 of usec
599 E1000WriteUlong(Adapter, E1000_REG_TIDV, 16);
600
602
604
605 NDIS_DbgPrint(MID_TRACE, ("Setting up receive.\n"));
606
607 /* Make sure the thing is disabled first. */
608 E1000WriteUlong(Adapter, E1000_REG_RCTL, 0);
609
610 /* Receive descriptor ring buffer */
611 E1000WriteUlong(Adapter, E1000_REG_RDBAH, Adapter->ReceiveDescriptorsPa.HighPart);
612 E1000WriteUlong(Adapter, E1000_REG_RDBAL, Adapter->ReceiveDescriptorsPa.LowPart);
613
614 /* Receive descriptor buffer size */
616
617 /* Receive descriptor tail / head */
618 E1000WriteUlong(Adapter, E1000_REG_RDH, 0);
620
621 /* Set up interrupt timers */
622 E1000WriteUlong(Adapter, E1000_REG_RADV, 96);
623 E1000WriteUlong(Adapter, E1000_REG_RDTR, 16);
624
625 /* Some defaults */
627
628 /* Receive buffer size */
629 Value |= RcvBufRegisterMask(Adapter->ReceiveBufferType);
630
631 /* Add our current packet filter */
632 Value |= PacketFilterToMask(Adapter->PacketFilter);
633
635
636 return NDIS_STATUS_SUCCESS;
637}
#define MID_TRACE
Definition: debug.h:15
static ULONG RcvBufRegisterMask(E1000_RCVBUF_SIZE BufSize)
Definition: hardware.c:102
#define E1000_TIPG_IPGT_DEF
Definition: e1000hw.h:215
#define E1000_REG_RDLEN
Definition: e1000hw.h:131
#define E1000_REG_RDBAH
Definition: e1000hw.h:130
#define E1000_REG_TDT
Definition: e1000hw.h:141
#define E1000_TCTL_PSP
Definition: e1000hw.h:212
#define E1000_REG_TDH
Definition: e1000hw.h:140
#define E1000_REG_RDBAL
Definition: e1000hw.h:129
#define E1000_REG_RDTR
Definition: e1000hw.h:134
#define E1000_REG_TDBAH
Definition: e1000hw.h:138
#define E1000_TIPG_IPGR2_DEF
Definition: e1000hw.h:217
#define E1000_REG_RDH
Definition: e1000hw.h:132
#define E1000_RCTL_EN
Definition: e1000hw.h:197
#define E1000_TCTL_EN
Definition: e1000hw.h:211
#define E1000_REG_TIDV
Definition: e1000hw.h:142
#define E1000_RCTL_SECRC
Definition: e1000hw.h:205
#define E1000_REG_TDLEN
Definition: e1000hw.h:139
#define E1000_REG_TIPG
Definition: e1000hw.h:127
#define E1000_REG_RADV
Definition: e1000hw.h:135
#define E1000_REG_TDBAL
Definition: e1000hw.h:137
#define E1000_TIPG_IPGR1_DEF
Definition: e1000hw.h:216
#define E1000_REG_TADV
Definition: e1000hw.h:143
#define E1000_REG_RDT
Definition: e1000hw.h:133

Referenced by MiniportInitialize().

◆ NICGetPermanentMacAddress()

NDIS_STATUS NTAPI NICGetPermanentMacAddress ( IN PE1000_ADAPTER  Adapter,
OUT PUCHAR  MacAddress 
)

Definition at line 661 of file hardware.c.

664{
665 USHORT AddrWord;
666 UINT n;
667
668 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
669
670 /* Should we read from RAL/RAH first? */
671 for (n = 0; n < (IEEE_802_ADDR_LENGTH / 2); ++n)
672 {
673 if (!E1000ReadEeprom(Adapter, (UCHAR)n, &AddrWord))
674 return NDIS_STATUS_FAILURE;
675 Adapter->PermanentMacAddress[n * 2 + 0] = AddrWord & 0xff;
676 Adapter->PermanentMacAddress[n * 2 + 1] = (AddrWord >> 8) & 0xff;
677 }
678
679#if 0
680 NDIS_DbgPrint(MIN_TRACE, ("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
681 Adapter->PermanentMacAddress[0],
682 Adapter->PermanentMacAddress[1],
683 Adapter->PermanentMacAddress[2],
684 Adapter->PermanentMacAddress[3],
685 Adapter->PermanentMacAddress[4],
686 Adapter->PermanentMacAddress[5]));
687#endif
688 return NDIS_STATUS_SUCCESS;
689}
#define IEEE_802_ADDR_LENGTH
Definition: e1000hw.h:11
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by MiniportInitialize().

◆ NICInitializeAdapterResources()

NDIS_STATUS NTAPI NICInitializeAdapterResources ( IN PE1000_ADAPTER  Adapter,
IN PNDIS_RESOURCE_LIST  ResourceList 
)

Definition at line 241 of file hardware.c.

244{
245 UINT n;
246 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
247
248 for (n = 0; n < ResourceList->Count; n++)
249 {
250 PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptor = ResourceList->PartialDescriptors + n;
251
252 switch (ResourceDescriptor->Type)
253 {
255 ASSERT(Adapter->IoPortAddress == 0);
256 ASSERT(ResourceDescriptor->u.Port.Start.HighPart == 0);
257
258 Adapter->IoPortAddress = ResourceDescriptor->u.Port.Start.LowPart;
259 Adapter->IoPortLength = ResourceDescriptor->u.Port.Length;
260
261 NDIS_DbgPrint(MID_TRACE, ("I/O port range is %p to %p\n",
262 Adapter->IoPortAddress,
263 Adapter->IoPortAddress + Adapter->IoPortLength));
264 break;
266 ASSERT(Adapter->InterruptVector == 0);
267 ASSERT(Adapter->InterruptLevel == 0);
268
269 Adapter->InterruptVector = ResourceDescriptor->u.Interrupt.Vector;
270 Adapter->InterruptLevel = ResourceDescriptor->u.Interrupt.Level;
271 Adapter->InterruptShared = (ResourceDescriptor->ShareDisposition == CmResourceShareShared);
272 Adapter->InterruptFlags = ResourceDescriptor->Flags;
273
274 NDIS_DbgPrint(MID_TRACE, ("IRQ vector is %d\n", Adapter->InterruptVector));
275 break;
277 /* Internal registers and memories (including PHY) */
278 if (ResourceDescriptor->u.Memory.Length == (128 * 1024))
279 {
280 ASSERT(Adapter->IoAddress.LowPart == 0);
281 ASSERT(ResourceDescriptor->u.Port.Start.HighPart == 0);
282
283
284 Adapter->IoAddress.QuadPart = ResourceDescriptor->u.Memory.Start.QuadPart;
285 Adapter->IoLength = ResourceDescriptor->u.Memory.Length;
286 NDIS_DbgPrint(MID_TRACE, ("Memory range is %I64x to %I64x\n",
287 Adapter->IoAddress.QuadPart,
288 Adapter->IoAddress.QuadPart + Adapter->IoLength));
289 }
290 break;
291
292 default:
293 NDIS_DbgPrint(MIN_TRACE, ("Unrecognized resource type: 0x%x\n", ResourceDescriptor->Type));
294 break;
295 }
296 }
297
298 if (Adapter->IoAddress.QuadPart == 0 || Adapter->IoPortAddress == 0 || Adapter->InterruptVector == 0)
299 {
300 NDIS_DbgPrint(MIN_TRACE, ("Adapter didn't receive enough resources\n"));
302 }
303
304 return NDIS_STATUS_SUCCESS;
305}
#define CmResourceTypeMemory
Definition: hwresource.cpp:125
#define CmResourceTypePort
Definition: hwresource.cpp:123
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@394::@397 Interrupt
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@394::@396 Port
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@394 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@394::@399 Memory
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309
@ CmResourceShareShared
Definition: cmtypes.h:243

Referenced by MiniportInitialize().

◆ NICPowerOn()

NDIS_STATUS NTAPI NICPowerOn ( IN PE1000_ADAPTER  Adapter)

Definition at line 509 of file hardware.c.

511{
513 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
514
515 Status = NICSoftReset(Adapter);
517 {
518 return Status;
519 }
520
521 if (!E1000ValidateNvmChecksum(Adapter))
522 {
524 }
525
526 return NDIS_STATUS_SUCCESS;
527}
NDIS_STATUS NTAPI NICSoftReset(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:531
BOOLEAN E1000ValidateNvmChecksum(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:187
#define NDIS_STATUS_INVALID_DATA
Definition: ndis.h:486

Referenced by MiniportInitialize().

◆ NICRecognizeHardware()

BOOLEAN NTAPI NICRecognizeHardware ( IN PE1000_ADAPTER  Adapter)

Definition at line 214 of file hardware.c.

216{
217 UINT n;
218 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
219
220 if (Adapter->VendorID != HW_VENDOR_INTEL)
221 {
222 NDIS_DbgPrint(MIN_TRACE, ("Unknown vendor: 0x%x\n", Adapter->VendorID));
223 return FALSE;
224 }
225
226 for (n = 0; n < ARRAYSIZE(SupportedDevices); ++n)
227 {
228 if (SupportedDevices[n] == Adapter->DeviceID)
229 {
230 return TRUE;
231 }
232 }
233
234 NDIS_DbgPrint(MIN_TRACE, ("Unknown device: 0x%x\n", Adapter->DeviceID));
235
236 return FALSE;
237}
#define HW_VENDOR_INTEL
Definition: builtin.c:4467
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
static USHORT SupportedDevices[]
Definition: hardware.c:14

Referenced by MiniportInitialize().

◆ NICRegisterInterrupts()

NDIS_STATUS NTAPI NICRegisterInterrupts ( IN PE1000_ADAPTER  Adapter)

Definition at line 392 of file hardware.c.

394{
396 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
397
398 Status = NdisMRegisterInterrupt(&Adapter->Interrupt,
399 Adapter->AdapterHandle,
400 Adapter->InterruptVector,
401 Adapter->InterruptLevel,
402 TRUE, // We always want ISR calls
403 Adapter->InterruptShared,
404 (Adapter->InterruptFlags & CM_RESOURCE_INTERRUPT_LATCHED) ?
406
408 {
409 Adapter->InterruptRegistered = TRUE;
410 }
411
412 return Status;
413}
NDIS_STATUS EXPORT NdisMRegisterInterrupt(OUT PNDIS_MINIPORT_INTERRUPT Interrupt, IN NDIS_HANDLE MiniportAdapterHandle, IN UINT InterruptVector, IN UINT InterruptLevel, IN BOOLEAN RequestIsr, IN BOOLEAN SharedInterrupt, IN NDIS_INTERRUPT_MODE InterruptMode)
Definition: io.c:941
#define NdisInterruptLatched
Definition: ndis.h:921
#define NdisInterruptLevelSensitive
Definition: ndis.h:920
#define CM_RESOURCE_INTERRUPT_LATCHED
Definition: cmtypes.h:144

Referenced by MiniportInitialize().

◆ NICReleaseIoResources()

NDIS_STATUS NTAPI NICReleaseIoResources ( IN PE1000_ADAPTER  Adapter)

Definition at line 433 of file hardware.c.

435{
436 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
437
438 if (Adapter->ReceiveDescriptors != NULL)
439 {
440 /* Disassociate our shared buffer before freeing it to avoid NIC-induced memory corruption */
441 if (Adapter->IoBase)
442 {
443 E1000WriteUlong(Adapter, E1000_REG_RDH, 0);
444 E1000WriteUlong(Adapter, E1000_REG_RDT, 0);
445 }
446
447 NdisMFreeSharedMemory(Adapter->AdapterHandle,
449 FALSE,
450 Adapter->ReceiveDescriptors,
451 Adapter->ReceiveDescriptorsPa);
452
453 Adapter->ReceiveDescriptors = NULL;
454 }
455
456 if (Adapter->ReceiveBuffer != NULL)
457 {
458 NdisMFreeSharedMemory(Adapter->AdapterHandle,
459 Adapter->ReceiveBufferEntrySize * NUM_RECEIVE_DESCRIPTORS,
460 FALSE,
461 Adapter->ReceiveBuffer,
462 Adapter->ReceiveBufferPa);
463
464 Adapter->ReceiveBuffer = NULL;
465 Adapter->ReceiveBufferEntrySize = 0;
466 }
467
468
469 if (Adapter->TransmitDescriptors != NULL)
470 {
471 /* Disassociate our shared buffer before freeing it to avoid NIC-induced memory corruption */
472 if (Adapter->IoBase)
473 {
474 E1000WriteUlong(Adapter, E1000_REG_TDH, 0);
475 E1000WriteUlong(Adapter, E1000_REG_TDT, 0);
476 }
477
478 NdisMFreeSharedMemory(Adapter->AdapterHandle,
480 FALSE,
481 Adapter->TransmitDescriptors,
482 Adapter->TransmitDescriptorsPa);
483
484 Adapter->TransmitDescriptors = NULL;
485 }
486
487
488
489 if (Adapter->IoPort)
490 {
491 NdisMDeregisterIoPortRange(Adapter->AdapterHandle,
492 Adapter->IoPortAddress,
493 Adapter->IoPortLength,
494 Adapter->IoPort);
495 }
496
497 if (Adapter->IoBase)
498 {
499 NdisMUnmapIoSpace(Adapter->AdapterHandle, Adapter->IoBase, Adapter->IoLength);
500 }
501
502
503 return NDIS_STATUS_SUCCESS;
504}
VOID EXPORT NdisMDeregisterIoPortRange(IN NDIS_HANDLE MiniportAdapterHandle, IN UINT InitialPort, IN UINT NumberOfPorts, IN PVOID PortOffset)
Definition: io.c:1093
VOID EXPORT NdisMUnmapIoSpace(IN NDIS_HANDLE MiniportAdapterHandle, IN PVOID VirtualAddress, IN UINT Length)
Definition: io.c:1139
VOID EXPORT NdisMFreeSharedMemory(IN NDIS_HANDLE MiniportAdapterHandle, IN ULONG Length, IN BOOLEAN Cached, IN PVOID VirtualAddress, IN NDIS_PHYSICAL_ADDRESS PhysicalAddress)
Definition: memory.c:215

Referenced by MiniportHalt().

◆ NICSoftReset()

NDIS_STATUS NTAPI NICSoftReset ( IN PE1000_ADAPTER  Adapter)

Definition at line 531 of file hardware.c.

533{
534 ULONG Value, ResetAttempts;
535 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
536
537 NICDisableInterrupts(Adapter);
538 E1000WriteUlong(Adapter, E1000_REG_RCTL, 0);
539 E1000WriteUlong(Adapter, E1000_REG_TCTL, 0);
541 /* Write this using IO port, some devices cannot ack this otherwise */
543
544
545 for (ResetAttempts = 0; ResetAttempts < MAX_RESET_ATTEMPTS; ResetAttempts++)
546 {
547 /* Wait 1us after reset (according to manual) */
550
551 if (!(Value & E1000_CTRL_RST))
552 {
553 NDIS_DbgPrint(MAX_TRACE, ("Device is back (%u)\n", ResetAttempts));
554
555 NICDisableInterrupts(Adapter);
556 /* Clear out interrupts (the register is cleared upon read) */
558
563
564 return NDIS_STATUS_SUCCESS;
565 }
566 }
567
568 NDIS_DbgPrint(MIN_TRACE, ("Device did not recover\n"));
569 return NDIS_STATUS_FAILURE;
570}
#define NICDisableInterrupts(Adapter)
Definition: 8390.h:159
FORCEINLINE VOID E1000WriteIoUlong(_In_ PE1000_ADAPTER Adapter, _In_ ULONG Address, _In_ ULONG Value)
Definition: nic.h:229
#define E1000_REG_ICR
Definition: e1000hw.h:119
#define E1000_CTRL_SLU
Definition: e1000hw.h:153
#define E1000_CTRL_RST
Definition: e1000hw.h:154
#define E1000_CTRL_LRST
Definition: e1000hw.h:151
#define E1000_CTRL_VME
Definition: e1000hw.h:155
#define MAX_RESET_ATTEMPTS
Definition: e1000hw.h:15
#define E1000_REG_CTRL
Definition: e1000hw.h:114
#define E1000_CTRL_ASDE
Definition: e1000hw.h:152

Referenced by MiniportInitialize(), and NICPowerOn().

◆ NICUnregisterInterrupts()

NDIS_STATUS NTAPI NICUnregisterInterrupts ( IN PE1000_ADAPTER  Adapter)

Definition at line 417 of file hardware.c.

419{
420 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
421
422 if (Adapter->InterruptRegistered)
423 {
424 NdisMDeregisterInterrupt(&Adapter->Interrupt);
425 Adapter->InterruptRegistered = FALSE;
426 }
427
428 return NDIS_STATUS_SUCCESS;
429}
VOID EXPORT NdisMDeregisterInterrupt(IN PNDIS_MINIPORT_INTERRUPT Interrupt)
Definition: io.c:700

Referenced by MiniportHalt().

◆ NICUpdateLinkStatus()

VOID NTAPI NICUpdateLinkStatus ( IN PE1000_ADAPTER  Adapter)

Definition at line 740 of file hardware.c.

742{
743 ULONG DeviceStatus;
744 SIZE_T SpeedIndex;
745 static ULONG SpeedValues[] = { 10, 100, 1000, 1000 };
746
747 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
748
749 E1000ReadUlong(Adapter, E1000_REG_STATUS, &DeviceStatus);
750 Adapter->MediaState = (DeviceStatus & E1000_STATUS_LU) ? NdisMediaStateConnected : NdisMediaStateDisconnected;
751 SpeedIndex = (DeviceStatus & E1000_STATUS_SPEEDMASK) >> E1000_STATUS_SPEEDSHIFT;
752 Adapter->LinkSpeedMbps = SpeedValues[SpeedIndex];
753}
#define E1000_STATUS_SPEEDSHIFT
Definition: e1000hw.h:161
#define E1000_STATUS_SPEEDMASK
Definition: e1000hw.h:162
#define E1000_REG_STATUS
Definition: e1000hw.h:115
#define E1000_STATUS_LU
Definition: e1000hw.h:160
@ NdisMediaStateConnected
Definition: ntddndis.h:470
@ NdisMediaStateDisconnected
Definition: ntddndis.h:471
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by MiniportHandleInterrupt(), MiniportInitialize(), and MiniportISR().

◆ NICUpdateMulticastList()

NDIS_STATUS NTAPI NICUpdateMulticastList ( IN PE1000_ADAPTER  Adapter)

Definition at line 693 of file hardware.c.

695{
696 UINT n;
697 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
698
699 // FIXME: Use 'Adapter->MulticastListSize'? Check the datasheet
700 for (n = 0; n < MAXIMUM_MULTICAST_ADDRESSES; ++n)
701 {
702 ULONG Ral = *(ULONG *)Adapter->MulticastList[n].MacAddress;
703 ULONG Rah = *(USHORT *)&Adapter->MulticastList[n].MacAddress[4];
704
705 if (Rah || Ral)
706 {
707 Rah |= E1000_RAH_AV;
708
709 E1000WriteUlong(Adapter, E1000_REG_RAL + (8*n), Ral);
710 E1000WriteUlong(Adapter, E1000_REG_RAH + (8*n), Rah);
711 }
712 else
713 {
714 E1000WriteUlong(Adapter, E1000_REG_RAH + (8*n), 0);
715 E1000WriteUlong(Adapter, E1000_REG_RAL + (8*n), 0);
716 }
717 }
718
719 return NDIS_STATUS_SUCCESS;
720}
#define MAXIMUM_MULTICAST_ADDRESSES
Definition: e1000hw.h:23
#define E1000_REG_RAH
Definition: e1000hw.h:147
#define E1000_REG_RAL
Definition: e1000hw.h:146
#define E1000_RAH_AV
Definition: e1000hw.h:221

Referenced by MiniportInitialize(), and MiniportSetInformation().

◆ PacketFilterToMask()

static ULONG PacketFilterToMask ( ULONG  PacketFilter)
static

Definition at line 56 of file hardware.c.

57{
58 ULONG FilterMask = 0;
59
60 if (PacketFilter & NDIS_PACKET_TYPE_ALL_MULTICAST)
61 {
62 /* Multicast Promiscuous Enabled */
63 FilterMask |= E1000_RCTL_MPE;
64 }
65 if (PacketFilter & NDIS_PACKET_TYPE_PROMISCUOUS)
66 {
67 /* Unicast Promiscuous Enabled */
68 FilterMask |= E1000_RCTL_UPE;
69 /* Multicast Promiscuous Enabled */
70 FilterMask |= E1000_RCTL_MPE;
71 }
72 if (PacketFilter & NDIS_PACKET_TYPE_MAC_FRAME)
73 {
74 /* Pass MAC Control Frames */
75 FilterMask |= E1000_RCTL_PMCF;
76 }
77 if (PacketFilter & NDIS_PACKET_TYPE_BROADCAST)
78 {
79 /* Broadcast Accept Mode */
80 FilterMask |= E1000_RCTL_BAM;
81 }
82
83 return FilterMask;
84}
#define E1000_RCTL_MPE
Definition: e1000hw.h:200
#define E1000_RCTL_BAM
Definition: e1000hw.h:201
#define E1000_RCTL_UPE
Definition: e1000hw.h:199
#define E1000_RCTL_PMCF
Definition: e1000hw.h:203
#define NDIS_PACKET_TYPE_PROMISCUOUS
Definition: ndis.h:668
#define NDIS_PACKET_TYPE_MAC_FRAME
Definition: ndis.h:674
#define NDIS_PACKET_TYPE_BROADCAST
Definition: ndis.h:666
#define NDIS_PACKET_TYPE_ALL_MULTICAST
Definition: ndis.h:665

Referenced by NICApplyPacketFilter(), and NICEnableTxRx().

◆ RcvBufAllocationSize()

static ULONG RcvBufAllocationSize ( E1000_RCVBUF_SIZE  BufSize)
static

Definition at line 86 of file hardware.c.

87{
88 static ULONG PredefSizes[4] = {
89 2048, 1024, 512, 256,
90 };
91 ULONG Size;
92
93 Size = PredefSizes[BufSize & E1000_RCVBUF_INDEXMASK];
95 {
96 ASSERT(BufSize != 2048);
97 Size *= 16;
98 }
99 return Size;
100}
#define BufSize
Definition: FsRtlTunnel.c:28
@ E1000_RCVBUF_RESERVED
Definition: e1000hw.h:45
@ E1000_RCVBUF_INDEXMASK
Definition: e1000hw.h:44
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by NICAllocateIoResources().

◆ RcvBufRegisterMask()

static ULONG RcvBufRegisterMask ( E1000_RCVBUF_SIZE  BufSize)
static

Definition at line 102 of file hardware.c.

103{
104 ULONG Mask = 0;
105
110
111 return Mask;
112}
#define E1000_RCTL_BSEX
Definition: e1000hw.h:204
#define E1000_RCTL_BSIZE_SHIFT
Definition: e1000hw.h:202
unsigned int Mask
Definition: fpcontrol.c:82

Referenced by NICEnableTxRx().

Variable Documentation

◆ SupportedDevices

USHORT SupportedDevices[]
static

Definition at line 14 of file hardware.c.

Referenced by NICRecognizeHardware().