ReactOS 0.4.15-dev-8135-g1bc6c90
ndis.c File Reference
#include "nic.h"
#include <debug.h>
Include dependency graph for ndis.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NDIS_STATUS NTAPI MiniportReset (OUT PBOOLEAN AddressingReset, IN NDIS_HANDLE MiniportAdapterContext)
 
NDIS_STATUS NTAPI MiniportSend (IN NDIS_HANDLE MiniportAdapterContext, IN PNDIS_PACKET Packet, IN UINT Flags)
 
VOID NTAPI MiniportHalt (IN NDIS_HANDLE MiniportAdapterContext)
 
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)
 
NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 

Variables

ULONG DebugTraceLevel = MIN_TRACE
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 24 of file ndis.c.

Function Documentation

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PUNICODE_STRING  RegistryPath 
)

Definition at line 483 of file ndis.c.

487{
488 NDIS_HANDLE wrapperHandle;
489 NDIS_MINIPORT_CHARACTERISTICS characteristics;
491
492 RtlZeroMemory(&characteristics, sizeof(characteristics));
493 characteristics.MajorNdisVersion = NDIS_MINIPORT_MAJOR_VERSION;
494 characteristics.MinorNdisVersion = NDIS_MINIPORT_MINOR_VERSION;
495 characteristics.CheckForHangHandler = NULL;
496 characteristics.DisableInterruptHandler = NULL;
497 characteristics.EnableInterruptHandler = NULL;
498 characteristics.HaltHandler = MiniportHalt;
499 characteristics.HandleInterruptHandler = MiniportHandleInterrupt;
500 characteristics.InitializeHandler = MiniportInitialize;
501 characteristics.ISRHandler = MiniportISR;
502 characteristics.QueryInformationHandler = MiniportQueryInformation;
503 characteristics.ReconfigureHandler = NULL;
504 characteristics.ResetHandler = MiniportReset;
505 characteristics.SendHandler = MiniportSend;
506 characteristics.SetInformationHandler = MiniportSetInformation;
507 characteristics.TransferDataHandler = NULL;
508 characteristics.ReturnPacketHandler = NULL;
509 characteristics.SendPacketsHandler = NULL;
510 characteristics.AllocateCompleteHandler = NULL;
511
513 if (!wrapperHandle)
514 {
515 return NDIS_STATUS_FAILURE;
516 }
517
518 status = NdisMRegisterMiniport(wrapperHandle, &characteristics, sizeof(characteristics));
520 {
521 NdisTerminateWrapper(wrapperHandle, 0);
522 return NDIS_STATUS_FAILURE;
523 }
524
525 return NDIS_STATUS_SUCCESS;
526}
#define NULL
Definition: types.h:112
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
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
NDIS_STATUS NTAPI MiniportSend(_In_ NDIS_HANDLE MiniportAdapterContext, _In_ PNDIS_PACKET Packet, _In_ UINT Flags)
Definition: send.c:49
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define NdisMInitializeWrapper(NdisWrapperHandle, SystemSpecific1, SystemSpecific2, SystemSpecific3)
Definition: ndis.h:5592
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
int NDIS_STATUS
Definition: ntddndis.h:475
Definition: ps.c:97
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_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

◆ MiniportHalt()

VOID NTAPI MiniportHalt ( IN NDIS_HANDLE  MiniportAdapterContext)

Definition at line 137 of file ndis.c.

140{
141 PRTL_ADAPTER adapter = (PRTL_ADAPTER)MiniportAdapterContext;
142
143 ASSERT(adapter != NULL);
144
145 //
146 // Interrupts need to stop first
147 //
148 if (adapter->InterruptRegistered != FALSE)
149 {
151 }
152
153 //
154 // If we have a mapped IO port range, we can talk to the NIC
155 //
156 if (adapter->IoBase != NULL)
157 {
158 if (adapter->ReceiveBuffer != NULL)
159 {
160 //
161 // Disassociate our shared buffer before freeing it to avoid
162 // NIC-induced memory corruption
163 //
165
166 NdisMFreeSharedMemory(adapter->MiniportAdapterHandle,
167 adapter->ReceiveBufferLength,
168 FALSE,
169 adapter->ReceiveBuffer,
170 adapter->ReceiveBufferPa);
171 }
172
173 if (adapter->RuntTxBuffers != NULL)
174 {
175 NdisMFreeSharedMemory(adapter->MiniportAdapterHandle,
177 FALSE,
178 adapter->RuntTxBuffers,
179 adapter->RuntTxBuffersPa);
180 }
181
182 //
183 // Unregister the IO range
184 //
185 NdisMDeregisterIoPortRange(adapter->MiniportAdapterHandle,
186 adapter->IoRangeStart,
187 adapter->IoRangeLength,
188 adapter->IoBase);
189 }
190
191 //
192 // Destroy the adapter context
193 //
194 NdisFreeMemory(adapter, sizeof(*adapter), 0);
195}
#define FALSE
Definition: types.h:117
NDIS_STATUS NTAPI NICRemoveReceiveBuffer(IN PRTL_ADAPTER Adapter)
Definition: hardware.c:88
VOID EXPORT NdisMDeregisterInterrupt(IN PNDIS_MINIPORT_INTERRUPT Interrupt)
Definition: io.c:700
VOID EXPORT NdisMDeregisterIoPortRange(IN NDIS_HANDLE MiniportAdapterHandle, IN UINT InitialPort, IN UINT NumberOfPorts, IN PVOID PortOffset)
Definition: io.c:1093
VOID EXPORT NdisFreeMemory(IN PVOID VirtualAddress, IN UINT Length, IN UINT MemoryFlags)
Definition: memory.c:110
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
return adapter
#define ASSERT(a)
Definition: mode.c:44
struct _RTL_ADAPTER * PRTL_ADAPTER
#define MINIMUM_FRAME_SIZE
Definition: nic.h:25
#define TX_DESC_COUNT
Definition: rtlhw.h:14

◆ MiniportInitialize()

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 at line 199 of file ndis.c.

207{
210 UINT i;
211 PNDIS_RESOURCE_LIST resourceList;
212 UINT resourceListSize;
213
214 //
215 // Make sure the medium is supported
216 //
217 for (i = 0; i < MediumArraySize; i++)
218 {
219 if (MediumArray[i] == NdisMedium802_3)
220 {
222 break;
223 }
224 }
225
226 if (i == MediumArraySize)
227 {
228 NDIS_DbgPrint(MIN_TRACE, ("802.3 medium was not found in the medium array\n"));
230 }
231
232 //
233 // Allocate our adapter context
234 //
236 sizeof(*adapter),
239 {
240 NDIS_DbgPrint(MIN_TRACE, ("Failed to allocate adapter context\n"));
242 }
243
244 RtlZeroMemory(adapter, sizeof(*adapter));
245 adapter->MiniportAdapterHandle = MiniportAdapterHandle;
247
248 //
249 // Notify NDIS of some characteristics of our NIC
250 //
252 adapter,
253 0,
256
257 //
258 // Get our resources for IRQ and IO base information
259 //
260 resourceList = NULL;
261 resourceListSize = 0;
264 resourceList,
265 &resourceListSize);
267 {
268 NDIS_DbgPrint(MIN_TRACE, ("Unexpected failure of NdisMQueryAdapterResources #1\n"));
270 goto Cleanup;
271 }
272
273 status = NdisAllocateMemoryWithTag((PVOID*)&resourceList,
274 resourceListSize,
277 {
278 NDIS_DbgPrint(MIN_TRACE, ("Failed to allocate resource list\n"));
279 goto Cleanup;
280 }
281
284 resourceList,
285 &resourceListSize);
287 {
288 NDIS_DbgPrint(MIN_TRACE, ("Unexpected failure of NdisMQueryAdapterResources #2\n"));
289 goto Cleanup;
290 }
291
292 ASSERT(resourceList->Version == 1);
293 ASSERT(resourceList->Revision == 1);
294
295 for (i = 0; i < resourceList->Count; i++)
296 {
297 switch (resourceList->PartialDescriptors[i].Type)
298 {
300 ASSERT(adapter->IoRangeStart == 0);
301
302 ASSERT(resourceList->PartialDescriptors[i].u.Port.Start.HighPart == 0);
303
304 adapter->IoRangeStart = resourceList->PartialDescriptors[i].u.Port.Start.LowPart;
305 adapter->IoRangeLength = resourceList->PartialDescriptors[i].u.Port.Length;
306
307 NDIS_DbgPrint(MID_TRACE, ("I/O port range is %p to %p\n",
308 adapter->IoRangeStart, adapter->IoRangeStart + adapter->IoRangeLength));
309 break;
310
312 ASSERT(adapter->InterruptVector == 0);
313 ASSERT(adapter->InterruptLevel == 0);
314
315 adapter->InterruptVector = resourceList->PartialDescriptors[i].u.Interrupt.Vector;
316 adapter->InterruptLevel = resourceList->PartialDescriptors[i].u.Interrupt.Level;
317 adapter->InterruptShared = (resourceList->PartialDescriptors[i].ShareDisposition == CmResourceShareShared);
318 adapter->InterruptFlags = resourceList->PartialDescriptors[i].Flags;
319
320 NDIS_DbgPrint(MID_TRACE, ("IRQ vector is %d\n", adapter->InterruptVector));
321 break;
322
323 default:
324 NDIS_DbgPrint(MIN_TRACE, ("Unrecognized resource type: 0x%x\n", resourceList->PartialDescriptors[i].Type));
325 break;
326 }
327 }
328
329 NdisFreeMemory(resourceList, resourceListSize, 0);
330 resourceList = NULL;
331
332 if (adapter->IoRangeStart == 0 || adapter->InterruptVector == 0)
333 {
334 NDIS_DbgPrint(MIN_TRACE, ("Adapter didn't receive enough resources\n"));
335 goto Cleanup;
336 }
337
338 //
339 // Allocate the DMA resources
340 //
342 FALSE, // RTL8139 only supports 32-bit addresses
345 {
346 NDIS_DbgPrint(MIN_TRACE, ("Unable to configure DMA\n"));
347 goto Cleanup;
348 }
349
350 adapter->ReceiveBufferLength = FULL_RECEIVE_BUFFER_SIZE;
352 adapter->ReceiveBufferLength,
353 FALSE,
354 (PVOID*)&adapter->ReceiveBuffer,
355 &adapter->ReceiveBufferPa);
356 if (adapter->ReceiveBuffer == NULL)
357 {
358 NDIS_DbgPrint(MIN_TRACE, ("Unable to allocate receive buffer\n"));
360 goto Cleanup;
361 }
362
365 FALSE,
366 (PVOID*)&adapter->RuntTxBuffers,
367 &adapter->RuntTxBuffersPa);
368 if (adapter->RuntTxBuffers == NULL)
369 {
370 NDIS_DbgPrint(MIN_TRACE, ("Unable to allocate runt TX buffer\n"));
372 goto Cleanup;
373 }
374
375 //
376 // Register the I/O port range and configure the NIC
377 //
380 adapter->IoRangeStart,
381 adapter->IoRangeLength);
383 {
384 NDIS_DbgPrint(MIN_TRACE, ("Unable to register IO port range (0x%x)\n", status));
385 goto Cleanup;
386 }
387
388 //
389 // Adapter setup
390 //
393 {
394 NDIS_DbgPrint(MIN_TRACE, ("Unable to power on NIC (0x%x)\n", status));
395 goto Cleanup;
396 }
397
400 {
401 NDIS_DbgPrint(MIN_TRACE, ("Unable to reset the NIC (0x%x)\n", status));
402 goto Cleanup;
403 }
404
405 status = NICGetPermanentMacAddress(adapter, adapter->PermanentMacAddress);
407 {
408 NDIS_DbgPrint(MIN_TRACE, ("Unable to get the fixed MAC address (0x%x)\n", status));
409 goto Cleanup;
410 }
411
412 RtlCopyMemory(adapter->CurrentMacAddress, adapter->PermanentMacAddress, IEEE_802_ADDR_LENGTH);
413
414 //
415 // Update link state and speed
416 //
418
421 {
422 NDIS_DbgPrint(MIN_TRACE, ("Unable to setup receive buffer (0x%x)\n", status));
423 goto Cleanup;
424 }
425
426 //
427 // We're ready to handle interrupts now
428 //
431 adapter->InterruptVector,
432 adapter->InterruptLevel,
433 TRUE, // We always want ISR calls
434 adapter->InterruptShared,
435 (adapter->InterruptFlags & CM_RESOURCE_INTERRUPT_LATCHED) ?
438 {
439 NDIS_DbgPrint(MIN_TRACE, ("Unable to register interrupt (0x%x)\n", status));
440 goto Cleanup;
441 }
442
443 adapter->InterruptRegistered = TRUE;
444
445 //
446 // Enable interrupts on the NIC
447 //
448 adapter->InterruptMask = DEFAULT_INTERRUPT_MASK;
451 {
452 NDIS_DbgPrint(MIN_TRACE, ("Unable to apply interrupt mask (0x%x)\n", status));
453 goto Cleanup;
454 }
455
456 //
457 // Turn on TX and RX now
458 //
461 {
462 NDIS_DbgPrint(MIN_TRACE, ("Unable to enable TX and RX (0x%x)\n", status));
463 goto Cleanup;
464 }
465
466 return NDIS_STATUS_SUCCESS;
467
468Cleanup:
469 if (resourceList != NULL)
470 {
471 NdisFreeMemory(resourceList, resourceListSize, 0);
472 }
473 if (adapter != NULL)
474 {
476 }
477
478 return status;
479}
#define MIN_TRACE
Definition: debug.h:14
#define MID_TRACE
Definition: debug.h:15
#define TRUE
Definition: types.h:120
static const WCHAR Cleanup[]
Definition: register.c:80
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
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
NDIS_STATUS NTAPI NICGetPermanentMacAddress(IN PE1000_ADAPTER Adapter, OUT PUCHAR MacAddress)
Definition: hardware.c:661
VOID NTAPI NICUpdateLinkStatus(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:740
NDIS_STATUS NTAPI NICRegisterReceiveBuffer(IN PRTL_ADAPTER Adapter)
Definition: hardware.c:75
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 NdisMRegisterIoPortRange(OUT PVOID *PortOffset, IN NDIS_HANDLE MiniportAdapterHandle, IN UINT InitialPort, IN UINT NumberOfPorts)
Definition: io.c:1018
NDIS_STATUS EXPORT NdisMInitializeScatterGatherDma(IN NDIS_HANDLE MiniportAdapterHandle, IN BOOLEAN Dma64BitAddresses, IN ULONG MaximumPhysicalMapping)
Definition: io.c:1169
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
NDIS_STATUS EXPORT NdisAllocateMemoryWithTag(OUT PVOID *VirtualAddress, IN UINT Length, IN ULONG Tag)
Definition: memory.c:21
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 MAXIMUM_FRAME_SIZE
Definition: nic.h:19
#define DEFAULT_INTERRUPT_MASK
Definition: nic.h:24
FORCEINLINE VOID NICApplyInterruptMask(_In_ PE1000_ADAPTER Adapter)
Definition: nic.h:243
#define IEEE_802_ADDR_LENGTH
Definition: e1000hw.h:11
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 CmResourceTypePort
Definition: hwresource.cpp:123
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
#define NdisInterruptLatched
Definition: ndis.h:921
unsigned int UINT
Definition: ndis.h:50
#define NDIS_ATTRIBUTE_BUS_MASTER
Definition: ndis.h:586
#define NdisInterruptLevelSensitive
Definition: ndis.h:920
#define NdisAllocateSpinLock(_SpinLock)
Definition: ndis.h:4088
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _Out_ PUINT SelectedMediumIndex
Definition: ndis.h:6011
_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
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
#define CM_RESOURCE_INTERRUPT_LATCHED
Definition: cmtypes.h:144
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
@ NdisMedium802_3
Definition: ntddndis.h:188
#define RESOURCE_LIST_TAG
Definition: nic.h:16
#define ADAPTER_TAG
Definition: nic.h:15
#define FULL_RECEIVE_BUFFER_SIZE
Definition: nic.h:22
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@396 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@396::@398 Port
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@396::@399 Interrupt
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: hwresource.cpp:119
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
@ CmResourceShareShared
Definition: cmtypes.h:243

◆ MiniportReset()

NDIS_STATUS NTAPI MiniportReset ( OUT PBOOLEAN  AddressingReset,
IN NDIS_HANDLE  MiniportAdapterContext 
)

Definition at line 31 of file ndis.c.

35{
36 *AddressingReset = FALSE;
38}

◆ MiniportSend()

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

Definition at line 42 of file ndis.c.

47{
48 PRTL_ADAPTER adapter = (PRTL_ADAPTER)MiniportAdapterContext;
52 ULONG transmitLength;
53 ULONG transmitBuffer;
54 PNDIS_BUFFER firstBuffer;
55 PVOID firstBufferVa;
56 UINT firstBufferLength, totalBufferLength;
57 PUCHAR runtBuffer;
58
59 ASSERT(sgList != NULL);
60
61 ASSERT(sgList->NumberOfElements == 1);
62 ASSERT(sgList->Elements[0].Address.HighPart == 0);
63 ASSERT((sgList->Elements[0].Address.LowPart & 3) == 0);
64 ASSERT(sgList->Elements[0].Length <= MAXIMUM_FRAME_SIZE);
65
66 NDIS_DbgPrint(MAX_TRACE, ("Sending %d byte packet\n", sgList->Elements[0].Length));
67
69
70 if (adapter->TxFull)
71 {
72 NDIS_DbgPrint(MIN_TRACE, ("All TX descriptors are full\n"));
75 }
76
77 NDIS_DbgPrint(MAX_TRACE, ("Sending packet on TX desc %d\n", adapter->CurrentTxDesc));
78
79 //
80 // If this is a runt, we need to pad it manually for the RTL8139
81 //
82 if (sgList->Elements[0].Length < MINIMUM_FRAME_SIZE)
83 {
84 transmitLength = MINIMUM_FRAME_SIZE;
85 transmitBuffer = adapter->RuntTxBuffersPa.LowPart +
86 (MINIMUM_FRAME_SIZE * adapter->CurrentTxDesc);
87
89 &firstBuffer,
90 &firstBufferVa,
91 &firstBufferLength,
92 &totalBufferLength,
94 if (firstBufferVa == NULL)
95 {
96 NDIS_DbgPrint(MIN_TRACE, ("Unable to get buffer from packet\n"));
99 }
100
101 ASSERT(firstBufferLength == totalBufferLength);
102
103 runtBuffer = adapter->RuntTxBuffers + (MINIMUM_FRAME_SIZE * adapter->CurrentTxDesc);
104 RtlCopyMemory(runtBuffer, firstBufferVa, firstBufferLength);
105 RtlFillMemory(runtBuffer + firstBufferLength, MINIMUM_FRAME_SIZE - firstBufferLength, 0x00);
106 }
107 else
108 {
109 transmitLength = sgList->Elements[0].Length;
110 transmitBuffer = sgList->Elements[0].Address.LowPart;
111 }
112
113 status = NICTransmitPacket(adapter, adapter->CurrentTxDesc, transmitBuffer, transmitLength);
115 {
116 NDIS_DbgPrint(MIN_TRACE, ("Transmit packet failed\n"));
118 return status;
119 }
120
121 adapter->CurrentTxDesc++;
122 adapter->CurrentTxDesc %= TX_DESC_COUNT;
123
124 if (adapter->CurrentTxDesc == adapter->DirtyTxDesc)
125 {
126 NDIS_DbgPrint(MID_TRACE, ("All TX descriptors are full now\n"));
127 adapter->TxFull = TRUE;
128 }
129
131
132 return NDIS_STATUS_SUCCESS;
133}
#define MAX_TRACE
Definition: debug.h:16
static NDIS_STATUS NICTransmitPacket(_In_ PE1000_ADAPTER Adapter, _In_ PHYSICAL_ADDRESS PhysicalAddress, _In_ ULONG Length)
Definition: send.c:15
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:599
@ NormalPagePriority
Definition: imports.h:56
#define NdisReleaseSpinLock(_SpinLock)
Definition: ndis.h:4115
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
#define NDIS_PER_PACKET_INFO_FROM_PACKET(Packet, InfoType)
Definition: ndis.h:1351
MDL * PNDIS_BUFFER
Definition: ndis.h:343
#define NdisGetFirstBufferFromPacketSafe(_Packet, _FirstBuffer, _FirstBufferVA, _FirstBufferLength, _TotalBufferLength, _Priority)
Definition: ndis.h:3056
@ ScatterGatherListPacketInfo
Definition: ndis.h:1183
#define NdisAcquireSpinLock(_SpinLock)
Definition: ndis.h:4106
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
struct _SCATTER_GATHER_LIST * PSCATTER_GATHER_LIST
Definition: iotypes.h:2204

Variable Documentation

◆ DebugTraceLevel

ULONG DebugTraceLevel = MIN_TRACE

Definition at line 27 of file ndis.c.