ReactOS 0.4.15-dev-7842-g558ab78
nic.h File Reference
#include <ndis.h>
#include "e1000hw.h"
Include dependency graph for nic.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _E1000_ADAPTER
 

Macros

#define E1000_TAG   '001e'
 
#define MAXIMUM_FRAME_SIZE   1522
 
#define RECEIVE_BUFFER_SIZE   2048
 
#define DRIVER_VERSION   1
 
#define DEFAULT_INTERRUPT_MASK   (E1000_IMS_LSC | E1000_IMS_TXDW | E1000_IMS_TXQE | E1000_IMS_RXDMT0 | E1000_IMS_RXT0 | E1000_IMS_TXD_LOW)
 

Typedefs

typedef struct _E1000_ADAPTER E1000_ADAPTER
 
typedef struct _E1000_ADAPTERPE1000_ADAPTER
 

Functions

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)
 
NDIS_STATUS NTAPI MiniportSend (_In_ NDIS_HANDLE MiniportAdapterContext, _In_ PNDIS_PACKET Packet, _In_ UINT Flags)
 
NDIS_STATUS NTAPI MiniportSetInformation (IN NDIS_HANDLE MiniportAdapterContext, IN NDIS_OID Oid, IN PVOID InformationBuffer, IN ULONG InformationBufferLength, OUT PULONG BytesRead, OUT PULONG BytesNeeded)
 
NDIS_STATUS NTAPI MiniportQueryInformation (IN NDIS_HANDLE MiniportAdapterContext, IN NDIS_OID Oid, IN PVOID InformationBuffer, IN ULONG InformationBufferLength, OUT PULONG BytesWritten, OUT PULONG BytesNeeded)
 
VOID NTAPI MiniportISR (OUT PBOOLEAN InterruptRecognized, OUT PBOOLEAN QueueMiniportHandleInterrupt, IN NDIS_HANDLE MiniportAdapterContext)
 
VOID NTAPI MiniportHandleInterrupt (IN NDIS_HANDLE MiniportAdapterContext)
 
FORCEINLINE VOID E1000ReadUlong (_In_ PE1000_ADAPTER Adapter, _In_ ULONG Address, _Out_ PULONG Value)
 
FORCEINLINE VOID E1000WriteUlong (_In_ PE1000_ADAPTER Adapter, _In_ ULONG Address, _In_ ULONG Value)
 
FORCEINLINE VOID E1000WriteIoUlong (_In_ PE1000_ADAPTER Adapter, _In_ ULONG Address, _In_ ULONG Value)
 
FORCEINLINE VOID NICApplyInterruptMask (_In_ PE1000_ADAPTER Adapter)
 
FORCEINLINE VOID NICDisableInterrupts (_In_ PE1000_ADAPTER Adapter)
 

Macro Definition Documentation

◆ DEFAULT_INTERRUPT_MASK

Definition at line 24 of file nic.h.

◆ DRIVER_VERSION

#define DRIVER_VERSION   1

Definition at line 22 of file nic.h.

◆ E1000_TAG

#define E1000_TAG   '001e'

Definition at line 17 of file nic.h.

◆ MAXIMUM_FRAME_SIZE

#define MAXIMUM_FRAME_SIZE   1522

Definition at line 19 of file nic.h.

◆ RECEIVE_BUFFER_SIZE

#define RECEIVE_BUFFER_SIZE   2048

Definition at line 20 of file nic.h.

Typedef Documentation

◆ E1000_ADAPTER

◆ PE1000_ADAPTER

Function Documentation

◆ E1000ReadUlong()

FORCEINLINE VOID E1000ReadUlong ( _In_ PE1000_ADAPTER  Adapter,
_In_ ULONG  Address,
_Out_ PULONG  Value 
)

Definition at line 209 of file nic.h.

213{
214 NdisReadRegisterUlong((PULONG)(Adapter->IoBase + Address), Value);
215}
#define NdisReadRegisterUlong(Register, Data)
Definition: ndis.h:4267
static WCHAR Address[46]
Definition: ping.c:68
uint32_t * PULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by E1000ReadEeprom(), MiniportHandleInterrupt(), MiniportISR(), NICApplyPacketFilter(), NICDisableTxRx(), NICSoftReset(), and NICUpdateLinkStatus().

◆ E1000WriteIoUlong()

FORCEINLINE VOID E1000WriteIoUlong ( _In_ PE1000_ADAPTER  Adapter,
_In_ ULONG  Address,
_In_ ULONG  Value 
)

Definition at line 229 of file nic.h.

233{
234 volatile ULONG Dummy;
235
236 NdisRawWritePortUlong((PULONG)(Adapter->IoPort), Address);
237 NdisReadRegisterUlong(Adapter->IoBase + E1000_REG_STATUS, &Dummy);
238 NdisRawWritePortUlong((PULONG)(Adapter->IoPort + 4), Value);
239}
#define E1000_REG_STATUS
Definition: e1000hw.h:115
#define NdisRawWritePortUlong(Port, Data)
Definition: ndis.h:4239
uint32_t ULONG
Definition: typedefs.h:59

Referenced by NICSoftReset().

◆ E1000WriteUlong()

◆ MiniportHandleInterrupt()

VOID NTAPI MiniportHandleInterrupt ( IN NDIS_HANDLE  MiniportAdapterContext)

Definition at line 46 of file interrupt.c.

48{
49 ULONG InterruptPending;
50 PE1000_ADAPTER Adapter = (PE1000_ADAPTER)MiniportAdapterContext;
51 volatile PE1000_TRANSMIT_DESCRIPTOR TransmitDescriptor;
52
53 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
54
55 InterruptPending = _InterlockedExchange(&Adapter->InterruptPending, 0);
56
57
58 /* Link State Changed */
59 if (InterruptPending & E1000_IMS_LSC)
60 {
62
63 InterruptPending &= ~E1000_IMS_LSC;
64 NDIS_DbgPrint(MAX_TRACE, ("Link status changed!.\n"));
65
66 NICUpdateLinkStatus(Adapter);
67
69
72 }
73
74 /* Handling receive interrupts */
75 if (InterruptPending & (E1000_IMS_RXDMT0 | E1000_IMS_RXT0))
76 {
77 volatile PE1000_RECEIVE_DESCRIPTOR ReceiveDescriptor;
78 PETH_HEADER EthHeader;
79 ULONG BufferOffset;
80 BOOLEAN bGotAny = FALSE;
81 ULONG RxDescHead, RxDescTail, CurrRxDesc;
82
83 /* Clear out these interrupts */
84 InterruptPending &= ~(E1000_IMS_RXDMT0 | E1000_IMS_RXT0);
85
86 E1000ReadUlong(Adapter, E1000_REG_RDH, &RxDescHead);
87 E1000ReadUlong(Adapter, E1000_REG_RDT, &RxDescTail);
88
89 while (((RxDescTail + 1) % NUM_RECEIVE_DESCRIPTORS) != RxDescHead)
90 {
91 CurrRxDesc = (RxDescTail + 1) % NUM_RECEIVE_DESCRIPTORS;
92 BufferOffset = CurrRxDesc * Adapter->ReceiveBufferEntrySize;
93 ReceiveDescriptor = Adapter->ReceiveDescriptors + CurrRxDesc;
94
95 /* Check if the hardware have released this descriptor (DD - Descriptor Done) */
96 if (!(ReceiveDescriptor->Status & E1000_RDESC_STATUS_DD))
97 {
98 /* No need to check descriptors after the first unfinished one */
99 break;
100 }
101
102 /* Ignoring these flags for now */
103 ReceiveDescriptor->Status &= ~(E1000_RDESC_STATUS_IXSM | E1000_RDESC_STATUS_PIF);
104
105 if (ReceiveDescriptor->Status != (E1000_RDESC_STATUS_EOP | E1000_RDESC_STATUS_DD))
106 {
107 NDIS_DbgPrint(MIN_TRACE, ("Unrecognized ReceiveDescriptor status flag: %u\n", ReceiveDescriptor->Status));
108 }
109
110 /* Make sure the receive indications are enabled */
111 if (!Adapter->PacketFilter)
112 {
113 goto NextReceiveDescriptor;
114 }
115
116 if (ReceiveDescriptor->Length != 0 && ReceiveDescriptor->Address != 0)
117 {
118 EthHeader = (PETH_HEADER)(Adapter->ReceiveBuffer + BufferOffset);
119
121 NULL,
122 (PCHAR)EthHeader,
123 sizeof(ETH_HEADER),
124 (PCHAR)(EthHeader + 1),
125 ReceiveDescriptor->Length - sizeof(ETH_HEADER),
126 ReceiveDescriptor->Length - sizeof(ETH_HEADER));
127
128 bGotAny = TRUE;
129 }
130 else
131 {
132 NDIS_DbgPrint(MIN_TRACE, ("Got a NULL descriptor"));
133 }
134
135NextReceiveDescriptor:
136 /* Give the descriptor back */
137 ReceiveDescriptor->Status = 0;
138
139 RxDescTail = CurrRxDesc;
140 }
141
142 if (bGotAny)
143 {
144 /* Write back new tail value */
145 E1000WriteUlong(Adapter, E1000_REG_RDT, RxDescTail);
146
147 NDIS_DbgPrint(MAX_TRACE, ("Rx done (RDH: %u, RDT: %u)\n", RxDescHead, RxDescTail));
148
150 }
151 }
152
153 /* Handling transmit interrupts */
154 if (InterruptPending & (E1000_IMS_TXD_LOW | E1000_IMS_TXDW | E1000_IMS_TXQE))
155 {
156 PNDIS_PACKET AckPackets[40] = {0};
157 ULONG NumPackets = 0, i;
158
159 /* Clear out these interrupts */
160 InterruptPending &= ~(E1000_IMS_TXD_LOW | E1000_IMS_TXDW | E1000_IMS_TXQE);
161
162 while ((Adapter->TxFull || Adapter->LastTxDesc != Adapter->CurrentTxDesc) && NumPackets < ARRAYSIZE(AckPackets))
163 {
164 TransmitDescriptor = Adapter->TransmitDescriptors + Adapter->LastTxDesc;
165
166 if (TransmitDescriptor->Status & E1000_TDESC_STATUS_DD)
167 {
168 if (Adapter->TransmitPackets[Adapter->LastTxDesc])
169 {
170 AckPackets[NumPackets++] = Adapter->TransmitPackets[Adapter->LastTxDesc];
171 Adapter->TransmitPackets[Adapter->LastTxDesc] = NULL;
172 TransmitDescriptor->Status = 0;
173 }
174
175 Adapter->LastTxDesc = (Adapter->LastTxDesc + 1) % NUM_TRANSMIT_DESCRIPTORS;
176 Adapter->TxFull = FALSE;
177 }
178 else
179 {
180 break;
181 }
182 }
183
184 if (NumPackets)
185 {
186 NDIS_DbgPrint(MAX_TRACE, ("Tx: (TDH: %u, TDT: %u)\n", Adapter->CurrentTxDesc, Adapter->LastTxDesc));
187 NDIS_DbgPrint(MAX_TRACE, ("Tx Done: %u packets to ack\n", NumPackets));
188
189 for (i = 0; i < NumPackets; ++i)
190 {
192 }
193 }
194 }
195
196 ASSERT(InterruptPending == 0);
197}
unsigned char BOOLEAN
#define MIN_TRACE
Definition: debug.h:14
#define MAX_TRACE
Definition: debug.h:16
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
struct _ETH_HEADER * PETH_HEADER
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
VOID NTAPI NICUpdateLinkStatus(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:740
struct _E1000_ADAPTER * PE1000_ADAPTER
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_IMS_RXDMT0
Definition: e1000hw.h:185
#define E1000_RDESC_STATUS_PIF
Definition: e1000hw.h:59
#define E1000_RDESC_STATUS_IXSM
Definition: e1000hw.h:60
#define E1000_IMS_TXQE
Definition: e1000hw.h:183
#define E1000_IMS_LSC
Definition: e1000hw.h:184
#define E1000_RDESC_STATUS_DD
Definition: e1000hw.h:62
#define E1000_IMS_TXD_LOW
Definition: e1000hw.h:187
#define E1000_IMS_TXDW
Definition: e1000hw.h:182
#define E1000_REG_RDH
Definition: e1000hw.h:132
#define E1000_TDESC_STATUS_DD
Definition: e1000hw.h:84
#define NUM_RECEIVE_DESCRIPTORS
Definition: e1000hw.h:109
#define E1000_RDESC_STATUS_EOP
Definition: e1000hw.h:61
#define NUM_TRANSMIT_DESCRIPTORS
Definition: e1000hw.h:108
#define E1000_IMS_RXT0
Definition: e1000hw.h:186
#define E1000_REG_RDT
Definition: e1000hw.h:133
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
long __cdecl _InterlockedExchange(_Interlocked_operand_ long volatile *_Target, long _Value)
#define ASSERT(a)
Definition: mode.c:44
#define NDIS_STATUS_MEDIA_CONNECT
Definition: ndis.h:361
#define NdisMEthIndicateReceiveComplete(MiniportAdapterHandle)
Definition: ndis.h:5482
#define NdisMIndicateStatusComplete(MiniportAdapterHandle)
Definition: ndis.h:5580
#define NdisMEthIndicateReceive(MiniportAdapterHandle, MiniportReceiveContext, HeaderBuffer, HeaderBufferSize, LookaheadBuffer, LookaheadBufferSize, PacketSize)
Definition: ndis.h:5458
#define NDIS_STATUS_MEDIA_DISCONNECT
Definition: ndis.h:362
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define NdisMSendComplete(MiniportAdapterHandle, Packet, Status)
Definition: ndis.h:5689
#define NdisMIndicateStatus(MiniportAdapterHandle, GeneralStatus, StatusBuffer, StatusBufferSize)
Definition: ndis.h:5570
@ NdisMediaStateConnected
Definition: ntddndis.h:470
Definition: lan.h:33
PE1000_RECEIVE_DESCRIPTOR ReceiveDescriptors
Definition: nic.h:85
ULONG LastTxDesc
Definition: nic.h:80
ULONG PacketFilter
Definition: nic.h:51
BOOLEAN TxFull
Definition: nic.h:81
ULONG ReceiveBufferEntrySize
Definition: nic.h:91
PE1000_TRANSMIT_DESCRIPTOR TransmitDescriptors
Definition: nic.h:74
ULONG MediaState
Definition: nic.h:50
PNDIS_PACKET TransmitPackets[NUM_TRANSMIT_DESCRIPTORS]
Definition: nic.h:77
NDIS_HANDLE AdapterHandle
Definition: nic.h:36
_Interlocked_ volatile LONG InterruptPending
Definition: nic.h:70
volatile PUCHAR ReceiveBuffer
Definition: nic.h:89
ULONG CurrentTxDesc
Definition: nic.h:79
char * PCHAR
Definition: typedefs.h:51

◆ MiniportISR()

VOID NTAPI MiniportISR ( OUT PBOOLEAN  InterruptRecognized,
OUT PBOOLEAN  QueueMiniportHandleInterrupt,
IN NDIS_HANDLE  MiniportAdapterContext 
)

Definition at line 16 of file interrupt.c.

20{
22 PE1000_ADAPTER Adapter = (PE1000_ADAPTER)MiniportAdapterContext;
23
24 /* Reading the interrupt acknowledges them */
26
27 Value &= Adapter->InterruptMask;
29
30 if (Value)
31 {
32 *InterruptRecognized = TRUE;
33 /* Mark the events pending service */
34 *QueueMiniportHandleInterrupt = TRUE;
35 }
36 else
37 {
38 /* This is not ours. */
39 *InterruptRecognized = FALSE;
40 *QueueMiniportHandleInterrupt = FALSE;
41 }
42}
#define E1000_REG_ICR
Definition: e1000hw.h:119
long _InterlockedOr(_Interlocked_operand_ long volatile *_Value, long _Mask)
LONG InterruptMask
Definition: nic.h:67

◆ MiniportQueryInformation()

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 at line 73 of file info.c.

80{
81 PE1000_ADAPTER Adapter = (PE1000_ADAPTER)MiniportAdapterContext;
82 ULONG copyLength;
83 PVOID copySource;
85 union _GENERIC_INFORMATION
86 {
89 ULONG64 Ulong64;
90 NDIS_MEDIUM Medium;
91 NDIS_PNP_CAPABILITIES PmCapabilities;
92 } GenericInfo;
93
95 copySource = &GenericInfo;
96 copyLength = sizeof(ULONG);
97
98 switch (Oid)
99 {
101 copySource = (PVOID)&SupportedOidList;
102 copyLength = sizeof(SupportedOidList);
103 break;
104
106 GenericInfo.Ulong = Adapter->PacketFilter;
107 break;
108
111 GenericInfo.Ulong = (ULONG)NdisHardwareStatusReady; //FIXME
112 break;
113
116 {
117 GenericInfo.Medium = NdisMedium802_3;
118 copyLength = sizeof(NDIS_MEDIUM);
119 break;
120 }
121
127 GenericInfo.Ulong = MAXIMUM_FRAME_SIZE - sizeof(ETH_HEADER);
128 break;
129
131 copySource = Adapter->MulticastList;
132 copyLength = Adapter->MulticastListSize * IEEE_802_ADDR_LENGTH;
133 break;
134
136 GenericInfo.Ulong = MAXIMUM_MULTICAST_ADDRESSES;
137 break;
138
140 GenericInfo.Ulong = Adapter->LinkSpeedMbps * 10000;
141 break;
142
144 GenericInfo.Ulong = MAXIMUM_FRAME_SIZE;
145 break;
146
148 GenericInfo.Ulong = RECEIVE_BUFFER_SIZE;
149 break;
150
152 /* The 3 bytes of the MAC address is the vendor ID */
153 GenericInfo.Ulong = 0;
154 GenericInfo.Ulong |= (Adapter->PermanentMacAddress[0] << 16);
155 GenericInfo.Ulong |= (Adapter->PermanentMacAddress[1] << 8);
156 GenericInfo.Ulong |= (Adapter->PermanentMacAddress[2] & 0xFF);
157 break;
158
160 {
161 static UCHAR vendorDesc[] = "ReactOS Team";
162 copySource = vendorDesc;
163 copyLength = sizeof(vendorDesc);
164 break;
165 }
166
168 GenericInfo.Ulong = DRIVER_VERSION;
169 break;
170
172 {
173 copyLength = sizeof(USHORT);
174 GenericInfo.Ushort = (NDIS_MINIPORT_MAJOR_VERSION << 8) + NDIS_MINIPORT_MINOR_VERSION;
175 break;
176 }
177
179 GenericInfo.Ulong = MAXIMUM_FRAME_SIZE;
180 break;
181
183 GenericInfo.Ulong = 1;
184 break;
185
187 GenericInfo.Ulong = NDIS_MAC_OPTION_RECEIVE_SERIALIZED |
191 break;
192
194 GenericInfo.Ulong = Adapter->MediaState;
195 break;
196
198 copySource = Adapter->MulticastList[0].MacAddress;
199 copyLength = IEEE_802_ADDR_LENGTH;
200 break;
201
203 copySource = Adapter->PermanentMacAddress;
204 copyLength = IEEE_802_ADDR_LENGTH;
205 break;
206
207 case OID_GEN_XMIT_OK:
208 case OID_GEN_RCV_OK:
212 {
213 GenericInfo.Ulong64 = NICQueryStatisticCounter(Adapter, Oid);
214
215 *BytesNeeded = sizeof(ULONG64);
216 if (InformationBufferLength >= sizeof(ULONG64))
217 {
218 *BytesWritten = sizeof(ULONG64);
219 NdisMoveMemory(InformationBuffer, copySource, sizeof(ULONG64));
220 }
221 else if (InformationBufferLength >= sizeof(ULONG))
222 {
223 *BytesWritten = sizeof(ULONG);
224 NdisMoveMemory(InformationBuffer, copySource, sizeof(ULONG));
225 }
226 else
227 {
228 *BytesWritten = 0;
230 }
231 return NDIS_STATUS_SUCCESS;
232 }
233
235 {
236 copyLength = sizeof(NDIS_PNP_CAPABILITIES);
237
238 status = NICFillPowerManagementCapabilities(Adapter, &GenericInfo.PmCapabilities);
239 break;
240 }
241
242 default:
243 NDIS_DbgPrint(MIN_TRACE, ("Unknown OID 0x%x(%s)\n", Oid, Oid2Str(Oid)));
245 break;
246 }
247
249 {
250 if (copyLength > InformationBufferLength)
251 {
252 *BytesNeeded = copyLength;
253 *BytesWritten = 0;
255 }
256 else
257 {
258 NdisMoveMemory(InformationBuffer, copySource, copyLength);
259 *BytesWritten = copyLength;
260 *BytesNeeded = copyLength;
261 }
262 }
263 else
264 {
265 *BytesWritten = 0;
266 *BytesNeeded = 0;
267 }
268
269 NDIS_DbgPrint(MAX_TRACE, ("Query OID 0x%x(%s): Completed with status 0x%x (%d, %d)\n",
270 Oid, Oid2Str(Oid), status, *BytesWritten, *BytesNeeded));
271 return status;
272}
const char * Oid2Str(IN NDIS_OID Oid)
Definition: debug.c:12
#define UNIMPLEMENTED_DBGBREAK(...)
Definition: debug.h:57
static NDIS_OID SupportedOidList[]
Definition: info.c:13
static ULONG64 NICQueryStatisticCounter(_In_ PE1000_ADAPTER Adapter, _In_ NDIS_OID Oid)
Definition: info.c:53
static NDIS_STATUS NICFillPowerManagementCapabilities(_In_ PE1000_ADAPTER Adapter, _Out_ PNDIS_PNP_CAPABILITIES Capabilities)
Definition: info.c:63
#define MAXIMUM_FRAME_SIZE
Definition: nic.h:19
#define RECEIVE_BUFFER_SIZE
Definition: nic.h:20
#define DRIVER_VERSION
Definition: nic.h:22
#define MAXIMUM_MULTICAST_ADDRESSES
Definition: e1000hw.h:23
#define IEEE_802_ADDR_LENGTH
Definition: e1000hw.h:11
unsigned __int64 ULONG64
Definition: imports.h:198
#define NDIS_STATUS_NOT_SUPPORTED
Definition: ndis.h:479
#define NDIS_MAC_OPTION_TRANSFERS_NOT_PEND
Definition: ndis.h:684
#define NDIS_MAC_OPTION_RECEIVE_SERIALIZED
Definition: ndis.h:683
#define NDIS_STATUS_BUFFER_TOO_SHORT
Definition: ndis.h:487
#define NDIS_MAC_OPTION_NO_LOOPBACK
Definition: ndis.h:685
#define NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA
Definition: ndis.h:682
#define NdisMoveMemory(Destination, Source, Length)
Definition: ndis.h:3896
enum _NDIS_MEDIUM NDIS_MEDIUM
#define OID_GEN_TRANSMIT_BLOCK_SIZE
Definition: ntddndis.h:242
#define OID_GEN_XMIT_OK
Definition: ntddndis.h:267
#define OID_GEN_MAXIMUM_TOTAL_SIZE
Definition: ntddndis.h:249
#define OID_GEN_XMIT_ERROR
Definition: ntddndis.h:269
#define OID_GEN_VENDOR_DRIVER_VERSION
Definition: ntddndis.h:254
#define OID_802_3_PERMANENT_ADDRESS
Definition: ntddndis.h:302
#define OID_GEN_LINK_SPEED
Definition: ntddndis.h:239
#define OID_GEN_VENDOR_ID
Definition: ntddndis.h:244
#define OID_GEN_CURRENT_PACKET_FILTER
Definition: ntddndis.h:246
#define OID_GEN_RCV_NO_BUFFER
Definition: ntddndis.h:271
#define OID_GEN_RECEIVE_BUFFER_SPACE
Definition: ntddndis.h:241
#define OID_802_3_MAXIMUM_LIST_SIZE
Definition: ntddndis.h:305
#define OID_GEN_DRIVER_VERSION
Definition: ntddndis.h:248
#define OID_802_3_CURRENT_ADDRESS
Definition: ntddndis.h:303
#define OID_802_3_MULTICAST_LIST
Definition: ntddndis.h:304
struct _NDIS_PNP_CAPABILITIES NDIS_PNP_CAPABILITIES
#define OID_GEN_TRANSMIT_BUFFER_SPACE
Definition: ntddndis.h:240
#define OID_GEN_MEDIA_SUPPORTED
Definition: ntddndis.h:235
@ NdisMedium802_3
Definition: ntddndis.h:188
#define OID_GEN_MAXIMUM_FRAME_SIZE
Definition: ntddndis.h:238
#define OID_GEN_MEDIA_IN_USE
Definition: ntddndis.h:236
#define OID_GEN_MEDIA_CONNECT_STATUS
Definition: ntddndis.h:252
#define OID_GEN_RCV_OK
Definition: ntddndis.h:268
#define OID_GEN_MAXIMUM_LOOKAHEAD
Definition: ntddndis.h:237
int NDIS_STATUS
Definition: ntddndis.h:475
#define OID_GEN_RCV_ERROR
Definition: ntddndis.h:270
@ NdisHardwareStatusReady
Definition: ntddndis.h:450
#define OID_PNP_CAPABILITIES
Definition: ntddndis.h:360
#define OID_GEN_CURRENT_LOOKAHEAD
Definition: ntddndis.h:247
#define OID_GEN_MAC_OPTIONS
Definition: ntddndis.h:251
#define OID_GEN_VENDOR_DESCRIPTION
Definition: ntddndis.h:245
#define OID_GEN_SUPPORTED_LIST
Definition: ntddndis.h:233
#define OID_GEN_RECEIVE_BLOCK_SIZE
Definition: ntddndis.h:243
#define OID_GEN_MAXIMUM_SEND_PACKETS
Definition: ntddndis.h:253
#define OID_GEN_HARDWARE_STATUS
Definition: ntddndis.h:234
unsigned short USHORT
Definition: pedump.c:61
ULONG LinkSpeedMbps
Definition: nic.h:49
ULONG MulticastListSize
Definition: nic.h:47
struct _E1000_ADAPTER::@989 MulticastList[MAXIMUM_MULTICAST_ADDRESSES]
UCHAR PermanentMacAddress[IEEE_802_ADDR_LENGTH]
Definition: nic.h:42
Definition: ps.c:97
void * PVOID
Definition: typedefs.h:50
unsigned short Ushort
Definition: utypes.h:44
unsigned long Ulong
Definition: utypes.h:42
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:960
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ MiniportSend()

NDIS_STATUS NTAPI MiniportSend ( _In_ NDIS_HANDLE  MiniportAdapterContext,
_In_ PNDIS_PACKET  Packet,
_In_ UINT  Flags 
)

Definition at line 49 of file send.c.

53{
54 PE1000_ADAPTER Adapter = (PE1000_ADAPTER)MiniportAdapterContext;
56 ULONG TransmitLength;
57 PHYSICAL_ADDRESS TransmitBuffer;
59
61
62 ASSERT(sgList != NULL);
63 ASSERT(sgList->NumberOfElements == 1);
64 ASSERT((sgList->Elements[0].Address.LowPart & 3) == 0);
65 ASSERT(sgList->Elements[0].Length <= MAXIMUM_FRAME_SIZE);
66
67 if (Adapter->TxFull)
68 {
69 NDIS_DbgPrint(MIN_TRACE, ("All TX descriptors are full\n"));
71 }
72
73 TransmitLength = sgList->Elements[0].Length;
74 TransmitBuffer = sgList->Elements[0].Address;
75 Adapter->TransmitPackets[Adapter->CurrentTxDesc] = Packet;
76
77 Status = NICTransmitPacket(Adapter, TransmitBuffer, TransmitLength);
79 {
80 NDIS_DbgPrint(MIN_TRACE, ("Transmit packet failed\n"));
81 return Status;
82 }
83
85}
static NDIS_STATUS NICTransmitPacket(_In_ PE1000_ADAPTER Adapter, _In_ PHYSICAL_ADDRESS PhysicalAddress, _In_ ULONG Length)
Definition: send.c:15
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
#define NDIS_PER_PACKET_INFO_FROM_PACKET(Packet, InfoType)
Definition: ndis.h:1351
@ ScatterGatherListPacketInfo
Definition: ndis.h:1183
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
struct _SCATTER_GATHER_LIST * PSCATTER_GATHER_LIST
Definition: iotypes.h:2204

Referenced by DriverEntry().

◆ MiniportSetInformation()

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 at line 276 of file info.c.

283{
284 PE1000_ADAPTER Adapter = (PE1000_ADAPTER)MiniportAdapterContext;
285 ULONG genericUlong;
287
289
290 switch (Oid)
291 {
293 if (InformationBufferLength < sizeof(ULONG))
294 {
295 *BytesRead = 0;
296 *BytesNeeded = sizeof(ULONG);
298 break;
299 }
300
301 NdisMoveMemory(&genericUlong, InformationBuffer, sizeof(ULONG));
302
303 if (genericUlong &
310 {
311 *BytesRead = sizeof(ULONG);
312 *BytesNeeded = sizeof(ULONG);
314 break;
315 }
316
317 if (Adapter->PacketFilter == genericUlong)
318 {
319 break;
320 }
321
322 Adapter->PacketFilter = genericUlong;
323
324 status = NICApplyPacketFilter(Adapter);
326 {
327 NDIS_DbgPrint(MIN_TRACE, ("Failed to apply new packet filter (0x%x)\n", status));
328 break;
329 }
330
331 break;
332
334 if (InformationBufferLength < sizeof(ULONG))
335 {
336 *BytesRead = 0;
337 *BytesNeeded = sizeof(ULONG);
339 break;
340 }
341
342 NdisMoveMemory(&genericUlong, InformationBuffer, sizeof(ULONG));
343
344 if (genericUlong > MAXIMUM_FRAME_SIZE - sizeof(ETH_HEADER))
345 {
347 }
348 else
349 {
350 // Ignore this...
351 }
352
353 break;
354
356 if (InformationBufferLength % IEEE_802_ADDR_LENGTH)
357 {
358 *BytesRead = 0;
359 *BytesNeeded = InformationBufferLength + (InformationBufferLength % IEEE_802_ADDR_LENGTH);
361 break;
362 }
363
364 if (InformationBufferLength > sizeof(Adapter->MulticastList))
365 {
366 *BytesNeeded = sizeof(Adapter->MulticastList);
367 *BytesRead = 0;
369 break;
370 }
371
372 NdisMoveMemory(Adapter->MulticastList, InformationBuffer, InformationBufferLength);
373
374 Adapter->MulticastListSize = InformationBufferLength / IEEE_802_ADDR_LENGTH;
375
376 NICUpdateMulticastList(Adapter);
377 break;
378
379 default:
380 NDIS_DbgPrint(MIN_TRACE, ("Unknown OID 0x%x(%s)\n", Oid, Oid2Str(Oid)));
382 *BytesRead = 0;
383 *BytesNeeded = 0;
384 break;
385 }
386
388 {
389 *BytesRead = InformationBufferLength;
390 *BytesNeeded = 0;
391 }
392
393 return status;
394}
NDIS_STATUS NTAPI NICApplyPacketFilter(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:724
NDIS_STATUS NTAPI NICUpdateMulticastList(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:693
#define NDIS_PACKET_TYPE_PROMISCUOUS
Definition: ndis.h:668
#define NDIS_STATUS_INVALID_DATA
Definition: ndis.h:486
#define NDIS_PACKET_TYPE_MAC_FRAME
Definition: ndis.h:674
#define NDIS_STATUS_INVALID_LENGTH
Definition: ndis.h:485
#define NDIS_PACKET_TYPE_BROADCAST
Definition: ndis.h:666
#define NDIS_PACKET_TYPE_MULTICAST
Definition: ndis.h:664
#define NDIS_PACKET_TYPE_DIRECTED
Definition: ndis.h:663
#define NDIS_PACKET_TYPE_ALL_MULTICAST
Definition: ndis.h:665
#define NDIS_STATUS_MULTICAST_FULL
Definition: ndis.h:473
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870

◆ 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}
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
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:322
GLdouble n
Definition: glext.h:7729
unsigned int UINT
Definition: ndis.h:50
#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().

◆ NICApplyInterruptMask()

FORCEINLINE VOID NICApplyInterruptMask ( _In_ PE1000_ADAPTER  Adapter)

Definition at line 243 of file nic.h.

245{
246 E1000WriteUlong(Adapter, E1000_REG_IMS, Adapter->InterruptMask /*| 0x1F6DC*/);
247}
#define E1000_REG_IMS
Definition: e1000hw.h:122

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().

◆ NICDisableInterrupts()

FORCEINLINE VOID NICDisableInterrupts ( _In_ PE1000_ADAPTER  Adapter)

Definition at line 251 of file nic.h.

253{
254 E1000WriteUlong(Adapter, E1000_REG_IMC, ~0);
255}
#define E1000_REG_IMC
Definition: e1000hw.h:123

◆ 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_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

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}
static BOOLEAN E1000ReadEeprom(IN PE1000_ADAPTER Adapter, IN UCHAR Address, USHORT *Result)
Definition: hardware.c:162
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465

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
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@393 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@393::@396 Interrupt
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@393::@398 Memory
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@393::@395 Port
_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

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
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_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
#define NdisStallExecution
Definition: ndis.h:4453

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_STATUS_LU
Definition: e1000hw.h:160
@ 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 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().