ReactOS 0.4.15-dev-8119-g4fb2fdb
pcnet.c File Reference
#include "pcnet.h"
#include <debug.h>
Include dependency graph for pcnet.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 
static VOID NTAPI MiniportHandleInterrupt (IN NDIS_HANDLE MiniportAdapterContext)
 
static NDIS_STATUS MiQueryCard (IN PADAPTER Adapter)
 
static VOID MiFreeSharedMemory (PADAPTER Adapter)
 
static NDIS_STATUS MiAllocateSharedMemory (PADAPTER Adapter)
 
static VOID MiPrepareInitializationBlock (PADAPTER Adapter)
 
static BOOLEAN NTAPI MiSyncStop (IN PVOID SynchronizeContext)
 
static VOID NTAPI MiniportHalt (IN NDIS_HANDLE MiniportAdapterContext)
 
static BOOLEAN NTAPI MiSyncMediaDetection (IN PVOID SynchronizeContext)
 
static VOID NTAPI MiniportMediaDetectionTimer (IN PVOID SystemSpecific1, IN PVOID FunctionContext, IN PVOID SystemSpecific2, IN PVOID SystemSpecific3)
 
static VOID MiInitChip (PADAPTER Adapter)
 
VOID NTAPI MiniportShutdown (PVOID Context)
 
static 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)
 
static VOID NTAPI MiniportISR (OUT PBOOLEAN InterruptRecognized, OUT PBOOLEAN QueueMiniportHandleInterrupt, IN NDIS_HANDLE MiniportAdapterContext)
 
static NDIS_STATUS NTAPI MiniportReset (OUT PBOOLEAN AddressingReset, IN NDIS_HANDLE MiniportAdapterContext)
 
static BOOLEAN NTAPI MiSyncStartTransmit (IN PVOID SynchronizeContext)
 
static NDIS_STATUS NTAPI MiniportSend (IN NDIS_HANDLE MiniportAdapterContext, IN PNDIS_PACKET Packet, IN UINT Flags)
 
static ULONG NTAPI MiEthernetCrc (UCHAR *Address)
 
NDIS_STATUS NTAPI MiSetMulticast (PADAPTER Adapter, UCHAR *Addresses, UINT AddressCount)
 
BOOLEAN NTAPI MiGetMediaDuplex (PADAPTER Adapter)
 
UINT NTAPI MiGetMediaSpeed (PADAPTER Adapter)
 
NDIS_MEDIA_STATE NTAPI MiGetMediaState (PADAPTER Adapter)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 43 of file pcnet.c.

Function Documentation

◆ DriverEntry()

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

Definition at line 1327 of file pcnet.c.

1342{
1343 NDIS_HANDLE WrapperHandle;
1344 NDIS_MINIPORT_CHARACTERISTICS Characteristics;
1346
1347 RtlZeroMemory(&Characteristics, sizeof(Characteristics));
1348 Characteristics.MajorNdisVersion = NDIS_MINIPORT_MAJOR_VERSION;
1349 Characteristics.MinorNdisVersion = NDIS_MINIPORT_MINOR_VERSION;
1350 Characteristics.HaltHandler = MiniportHalt;
1351 Characteristics.HandleInterruptHandler = MiniportHandleInterrupt;
1352 Characteristics.InitializeHandler = MiniportInitialize;
1353 Characteristics.ISRHandler = MiniportISR;
1354 Characteristics.QueryInformationHandler = MiniportQueryInformation;
1355 Characteristics.ResetHandler = MiniportReset;
1356 Characteristics.SetInformationHandler = MiniportSetInformation;
1357 Characteristics.SendHandler = MiniportSend;
1358
1360 if (!WrapperHandle) return NDIS_STATUS_FAILURE;
1361
1362 Status = NdisMRegisterMiniport(WrapperHandle, &Characteristics, sizeof(Characteristics));
1364 {
1365 NdisTerminateWrapper(WrapperHandle, 0);
1366 return NDIS_STATUS_FAILURE;
1367 }
1368
1369 return NDIS_STATUS_SUCCESS;
1370}
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
Status
Definition: gdiplustypes.h:25
#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
static 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: pcnet.c:853
static VOID NTAPI MiniportISR(OUT PBOOLEAN InterruptRecognized, OUT PBOOLEAN QueueMiniportHandleInterrupt, IN NDIS_HANDLE MiniportAdapterContext)
Definition: pcnet.c:1050
static VOID NTAPI MiniportHalt(IN NDIS_HANDLE MiniportAdapterContext)
Definition: pcnet.c:570
static NDIS_STATUS NTAPI MiniportReset(OUT PBOOLEAN AddressingReset, IN NDIS_HANDLE MiniportAdapterContext)
Definition: pcnet.c:1103
static NDIS_STATUS NTAPI MiniportSend(IN NDIS_HANDLE MiniportAdapterContext, IN PNDIS_PACKET Packet, IN UINT Flags)
Definition: pcnet.c:1144
static VOID NTAPI MiniportHandleInterrupt(IN NDIS_HANDLE MiniportAdapterContext)
Definition: pcnet.c:54
#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

◆ MiAllocateSharedMemory()

static NDIS_STATUS MiAllocateSharedMemory ( PADAPTER  Adapter)
static

Definition at line 353 of file pcnet.c.

363{
364 PTRANSMIT_DESCRIPTOR TransmitDescriptor;
365 PRECEIVE_DESCRIPTOR ReceiveDescriptor;
367 ULONG i;
368 ULONG BufferCount = NUMBER_OF_BUFFERS;
369 ULONG LogBufferCount = LOG_NUMBER_OF_BUFFERS;
370
371 while (BufferCount != 0)
372 {
373 /* allocate the initialization block (we have this in the loop so we can use MiFreeSharedMemory) */
377 if(!Adapter->InitializationBlockVirt)
378 {
379 /* Buffer backoff won't help us here */
380 DPRINT1("insufficient resources\n");
382 }
383
384 if (((ULONG_PTR)Adapter->InitializationBlockVirt & 0x00000003) != 0)
385 {
386 DPRINT1("address 0x%x not dword-aligned\n", Adapter->InitializationBlockVirt);
388 }
389
391
392 /* allocate the transport descriptor ring */
393 Adapter->TransmitDescriptorRingLength = sizeof(TRANSMIT_DESCRIPTOR) * BufferCount;
396 if (!Adapter->TransmitDescriptorRingVirt)
397 {
398 DPRINT1("Backing off buffer count by %d buffers due to allocation failure\n", (BufferCount >> 1));
399 BufferCount = BufferCount >> 1;
400 LogBufferCount--;
401 MiFreeSharedMemory(Adapter);
402 continue;
403 }
404
405 if (((ULONG_PTR)Adapter->TransmitDescriptorRingVirt & 0x00000003) != 0)
406 {
407 DPRINT1("address 0x%x not dword-aligned\n", Adapter->TransmitDescriptorRingVirt);
409 }
410
412 RtlZeroMemory(Adapter->TransmitDescriptorRingVirt, sizeof(TRANSMIT_DESCRIPTOR) * BufferCount);
413
414 /* allocate the receive descriptor ring */
415 Adapter->ReceiveDescriptorRingLength = sizeof(RECEIVE_DESCRIPTOR) * BufferCount;
418 if (!Adapter->ReceiveDescriptorRingVirt)
419 {
420 DPRINT1("Backing off buffer count by %d buffers due to allocation failure\n", (BufferCount >> 1));
421 BufferCount = BufferCount >> 1;
422 LogBufferCount--;
423 MiFreeSharedMemory(Adapter);
424 continue;
425 }
426
427 if (((ULONG_PTR)Adapter->ReceiveDescriptorRingVirt & 0x00000003) != 0)
428 {
429 DPRINT1("address 0x%x not dword-aligned\n", Adapter->ReceiveDescriptorRingVirt);
431 }
432
434 RtlZeroMemory(Adapter->ReceiveDescriptorRingVirt, sizeof(RECEIVE_DESCRIPTOR) * BufferCount);
435
436 /* allocate transmit buffers */
437 Adapter->TransmitBufferLength = BUFFER_SIZE * BufferCount;
440 if(!Adapter->TransmitBufferPtrVirt)
441 {
442 DPRINT1("Backing off buffer count by %d buffers due to allocation failure\n", (BufferCount >> 1));
443 BufferCount = BufferCount >> 1;
444 LogBufferCount--;
445 MiFreeSharedMemory(Adapter);
446 continue;
447 }
448
449 if(((ULONG_PTR)Adapter->TransmitBufferPtrVirt & 0x00000003) != 0)
450 {
451 DPRINT1("address 0x%x not dword-aligned\n", Adapter->TransmitBufferPtrVirt);
453 }
454
456 RtlZeroMemory(Adapter->TransmitBufferPtrVirt, BUFFER_SIZE * BufferCount);
457
458 /* allocate receive buffers */
459 Adapter->ReceiveBufferLength = BUFFER_SIZE * BufferCount;
462 if(!Adapter->ReceiveBufferPtrVirt)
463 {
464 DPRINT1("Backing off buffer count by %d buffers due to allocation failure\n", (BufferCount >> 1));
465 BufferCount = BufferCount >> 1;
466 LogBufferCount--;
467 MiFreeSharedMemory(Adapter);
468 continue;
469 }
470
471 if (((ULONG_PTR)Adapter->ReceiveBufferPtrVirt & 0x00000003) != 0)
472 {
473 DPRINT1("address 0x%x not dword-aligned\n", Adapter->ReceiveBufferPtrVirt);
475 }
476
478 RtlZeroMemory(Adapter->ReceiveBufferPtrVirt, BUFFER_SIZE * BufferCount);
479
480 break;
481 }
482
483 if (!BufferCount)
484 {
485 DPRINT1("Failed to allocate adapter buffers\n");
487 }
488
489 Adapter->BufferCount = BufferCount;
490 Adapter->LogBufferCount = LogBufferCount;
491
492 /* initialize tx descriptors */
493 TransmitDescriptor = Adapter->TransmitDescriptorRingVirt;
494 for(i = 0; i < BufferCount; i++)
495 {
496 (TransmitDescriptor+i)->TBADR = Adapter->TransmitBufferPtrPhys.QuadPart + i * BUFFER_SIZE;
497 (TransmitDescriptor+i)->BCNT = 0xf000 | -BUFFER_SIZE; /* 2's compliment + set top 4 bits */
498 (TransmitDescriptor+i)->FLAGS = TD1_STP | TD1_ENP;
499 }
500
501 DPRINT("transmit ring initialized\n");
502
503 /* initialize rx */
504 ReceiveDescriptor = Adapter->ReceiveDescriptorRingVirt;
505 for(i = 0; i < BufferCount; i++)
506 {
507 (ReceiveDescriptor+i)->RBADR = Adapter->ReceiveBufferPtrPhys.QuadPart + i * BUFFER_SIZE;
508 (ReceiveDescriptor+i)->BCNT = 0xf000 | -BUFFER_SIZE; /* 2's compliment + set top 4 bits */
509 (ReceiveDescriptor+i)->FLAGS = RD_OWN;
510 }
511
512 DPRINT("receive ring initialized\n");
513
514 return NDIS_STATUS_SUCCESS;
515}
#define DPRINT1
Definition: precomp.h:8
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
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
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
ULONG FLAGS
Definition: mapi.h:36
#define BUFFER_SIZE
Definition: freeldrpage.c:26
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
static VOID MiFreeSharedMemory(PADAPTER Adapter)
Definition: pcnet.c:301
#define NUMBER_OF_BUFFERS
Definition: pcnet.h:152
#define LOG_NUMBER_OF_BUFFERS
Definition: pcnet.h:153
#define TD1_STP
Definition: pcnethw.h:399
struct _TRANSMIT_DESCRIPTOR TRANSMIT_DESCRIPTOR
struct _RECEIVE_DESCRIPTOR RECEIVE_DESCRIPTOR
#define RD_OWN
Definition: pcnethw.h:383
struct _INITIALIZATION_BLOCK INITIALIZATION_BLOCK
#define TD1_ENP
Definition: pcnethw.h:398
#define DPRINT
Definition: sndvol32.h:73
PHYSICAL_ADDRESS ReceiveDescriptorRingPhys
Definition: pcnet.h:97
PHYSICAL_ADDRESS TransmitDescriptorRingPhys
Definition: pcnet.h:87
ULONG InitializationBlockLength
Definition: pcnet.h:80
ULONG TransmitBufferLength
Definition: pcnet.h:90
ULONG ReceiveDescriptorRingLength
Definition: pcnet.h:95
ULONG LogBufferCount
Definition: pcnet.h:106
ULONG ReceiveBufferLength
Definition: pcnet.h:100
PRECEIVE_DESCRIPTOR ReceiveDescriptorRingVirt
Definition: pcnet.h:96
PHYSICAL_ADDRESS InitializationBlockPhys
Definition: pcnet.h:82
PHYSICAL_ADDRESS ReceiveBufferPtrPhys
Definition: pcnet.h:102
NDIS_HANDLE MiniportAdapterHandle
Definition: pcnet.h:61
PHYSICAL_ADDRESS TransmitBufferPtrPhys
Definition: pcnet.h:92
PINITIALIZATION_BLOCK InitializationBlockVirt
Definition: pcnet.h:81
ULONG TransmitDescriptorRingLength
Definition: pcnet.h:85
PTRANSMIT_DESCRIPTOR TransmitDescriptorRingVirt
Definition: pcnet.h:86
PCHAR ReceiveBufferPtrVirt
Definition: pcnet.h:101
ULONG BufferCount
Definition: pcnet.h:105
PCHAR TransmitBufferPtrVirt
Definition: pcnet.h:91
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098

Referenced by MiniportInitialize().

◆ MiEthernetCrc()

static ULONG NTAPI MiEthernetCrc ( UCHAR Address)
static

Definition at line 1235 of file pcnet.c.

1243{
1245 ULONG Value = ~0;
1246
1247 for (Length = 0; Length < 6; Length++)
1248 {
1249 Value ^= *Address++;
1250 for (Counter = 0; Counter < 8; Counter++)
1251 {
1252 Value >>= 1;
1253 Value ^= (Value & 1) * 0xedb88320;
1254 }
1255 }
1256
1257 return Value;
1258}
unsigned int UINT
Definition: ndis.h:50
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
static WCHAR Address[46]
Definition: ping.c:68
static LARGE_INTEGER Counter
Definition: clock.c:43
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by MiSetMulticast().

◆ MiFreeSharedMemory()

static VOID MiFreeSharedMemory ( PADAPTER  Adapter)
static

Definition at line 301 of file pcnet.c.

308{
310
311 if(Adapter->InitializationBlockVirt)
312 {
316 Adapter->InitializationBlockVirt = NULL;
317 }
318
319 if(Adapter->TransmitDescriptorRingVirt)
320 {
325 }
326
327 if(Adapter->ReceiveDescriptorRingVirt)
328 {
333 }
334
335 if(Adapter->TransmitBufferPtrVirt)
336 {
340 Adapter->TransmitBufferPtrVirt = NULL;
341 }
342
343 if(Adapter->ReceiveBufferPtrVirt)
344 {
348 Adapter->ReceiveBufferPtrVirt = NULL;
349 }
350}
#define NULL
Definition: types.h:112
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 MiAllocateSharedMemory(), MiniportHalt(), and MiniportInitialize().

◆ MiGetMediaDuplex()

BOOLEAN NTAPI MiGetMediaDuplex ( PADAPTER  Adapter)

Definition at line 1285 of file pcnet.c.

1286{
1287 ULONG Data;
1288
1291
1292 return (Data & BCR5_LEDOUT) != 0;
1293}
#define NdisRawReadPortUshort(Port, Data)
Definition: ndis.h:4191
#define NdisRawWritePortUshort(Port, Data)
Definition: ndis.h:4248
#define BCR5
Definition: pcnethw.h:140
#define RAP
Definition: pcnethw.h:48
#define BDP
Definition: pcnethw.h:49
#define BCR5_LEDOUT
Definition: pcnethw.h:285
ULONG_PTR PortOffset
Definition: pcnet.h:65

Referenced by MiInitChip(), and MiSyncMediaDetection().

◆ MiGetMediaSpeed()

UINT NTAPI MiGetMediaSpeed ( PADAPTER  Adapter)

Definition at line 1297 of file pcnet.c.

1298{
1299 ULONG Data;
1300
1303
1304 return Data & BCR6_LEDOUT ? 100 : 10;
1305}
#define BCR6
Definition: pcnethw.h:141
#define BCR6_LEDOUT
Definition: pcnethw.h:301

Referenced by MiInitChip(), and MiSyncMediaDetection().

◆ MiGetMediaState()

NDIS_MEDIA_STATE NTAPI MiGetMediaState ( PADAPTER  Adapter)

Definition at line 1309 of file pcnet.c.

1318{
1319 ULONG Data;
1323}
@ NdisMediaStateConnected
Definition: ntddndis.h:470
@ NdisMediaStateDisconnected
Definition: ntddndis.h:471
#define BCR4_LEDOUT
Definition: pcnethw.h:269
#define BCR4
Definition: pcnethw.h:139

Referenced by MiInitChip(), and MiSyncMediaDetection().

◆ MiInitChip()

static VOID MiInitChip ( PADAPTER  Adapter)
static

Definition at line 675 of file pcnet.c.

685{
686 USHORT Data = 0;
687
688 DPRINT("Called\n");
689
690 /*
691 * first reset the chip - 32-bit reset followed by 16-bit reset. if it's in 32-bit mode, it'll reset
692 * twice. if it's in 16-bit mode, the first read will be nonsense and the second will be a reset. the
693 * card is reset by reading from the reset register. on reset it's in 16-bit i/o mode.
694 */
697
698 /* stop the chip */
701
702 /* pause for 1ms so the chip will have time to reset */
704
705 DPRINT("chip stopped\n");
706
707 /* set the software style to 2 (32 bits) */
710
711 Data |= SW_STYLE_2;
712
714
715 /* set up csr4: auto transmit pad, disable polling, disable transmit interrupt, dmaplus */
718
719 Data |= CSR4_APAD_XMT | /* CSR4_DPOLL |*/ CSR4_TXSTRTM | CSR4_DMAPLUS;
721
722 /* set up bcr18: burst read/write enable */
725
728
729 /* set up csr1 and csr2 with init block */
733 NdisRawWritePortUshort(Adapter->PortOffset + RDP, (USHORT)(Adapter->InitializationBlockPhys.LowPart >> 16) & 0xffff);
734
735 DPRINT("programmed with init block\n");
736
737 /* Set mode to 0 */
738 Data = 0;
741
742 /* load init block and start the card */
745
746 /* Allow LED programming */
749
750 /* LED0 is configured for link status (on = up, off = down) */
753
754 /* LED1 is configured for link duplex (on = full, off = half) */
757
758 /* LED2 is configured for link speed (on = 100M, off = 10M) */
761
762 /* LED3 is configured for trasmit/receive activity */
765
766 Adapter->MediaState = MiGetMediaState(Adapter);
767 Adapter->FullDuplex = MiGetMediaDuplex(Adapter);
768 Adapter->MediaSpeed = MiGetMediaSpeed(Adapter);
769
770 DPRINT("card started\n");
771
772 Adapter->Flags &= ~RESET_IN_PROGRESS;
773}
#define NdisStallExecution
Definition: ndis.h:4453
NDIS_MEDIA_STATE NTAPI MiGetMediaState(PADAPTER Adapter)
Definition: pcnet.c:1309
BOOLEAN NTAPI MiGetMediaDuplex(PADAPTER Adapter)
Definition: pcnet.c:1285
UINT NTAPI MiGetMediaSpeed(PADAPTER Adapter)
Definition: pcnet.c:1297
#define BCR7
Definition: pcnethw.h:142
#define CSR0
Definition: pcnethw.h:63
#define BCR5_FDLSE
Definition: pcnethw.h:280
#define CSR0_STOP
Definition: pcnethw.h:155
#define BCR7_PSE
Definition: pcnethw.h:311
#define BCR2
Definition: pcnethw.h:138
#define CSR0_INIT
Definition: pcnethw.h:153
#define BCR2_LEDPE
Definition: pcnethw.h:252
#define CSR4_APAD_XMT
Definition: pcnethw.h:195
#define CSR4_DMAPLUS
Definition: pcnethw.h:198
#define BCR7_RCVE
Definition: pcnethw.h:306
#define CSR0_IENA
Definition: pcnethw.h:159
#define CSR4
Definition: pcnethw.h:67
#define BCR18
Definition: pcnethw.h:146
#define CSR2
Definition: pcnethw.h:65
#define CSR58
Definition: pcnethw.h:110
#define CSR0_STRT
Definition: pcnethw.h:154
#define SW_STYLE_2
Definition: pcnethw.h:59
#define BCR18_BWRITE
Definition: pcnethw.h:325
#define RESET32
Definition: pcnethw.h:44
#define BCR7_XMTE
Definition: pcnethw.h:308
#define BCR6_PSE
Definition: pcnethw.h:295
#define BCR5_PSE
Definition: pcnethw.h:279
#define CSR1
Definition: pcnethw.h:64
#define RESET16
Definition: pcnethw.h:40
#define RDP
Definition: pcnethw.h:37
#define CSR4_TXSTRTM
Definition: pcnethw.h:186
#define BCR18_BREADE
Definition: pcnethw.h:326
#define BCR4_LNKSTE
Definition: pcnethw.h:262
#define BCR6_E100
Definition: pcnethw.h:298
#define CSR15
Definition: pcnethw.h:77
#define BCR4_PSE
Definition: pcnethw.h:263
unsigned short USHORT
Definition: pedump.c:61
BOOLEAN FullDuplex
Definition: pcnet.h:69
UINT MediaSpeed
Definition: pcnet.h:68
ULONG Flags
Definition: pcnet.h:62
NDIS_MEDIA_STATE MediaState
Definition: pcnet.h:67
ULONG LowPart
Definition: typedefs.h:106

Referenced by MiniportInitialize().

◆ MiniportHalt()

static VOID NTAPI MiniportHalt ( IN NDIS_HANDLE  MiniportAdapterContext)
static

Definition at line 570 of file pcnet.c.

579{
580 PADAPTER Adapter = (PADAPTER)MiniportAdapterContext;
582
583 DPRINT("Called\n");
584 ASSERT(Adapter);
585
586 /* stop the media detection timer */
588
589 /* stop the chip */
591
592 /* deregister the interrupt */
594
595 /* deregister i/o port range */
597
598 /* deregister the shutdown routine */
600
601 /* free shared memory */
602 MiFreeSharedMemory(Adapter);
603
604 /* free map registers */
606
607 /* free the lock */
608 NdisFreeSpinLock(&Adapter->Lock);
609
610 /* free the adapter */
611 NdisFreeMemory(Adapter, 0, 0);
612}
unsigned char BOOLEAN
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 NdisMFreeMapRegisters(IN NDIS_HANDLE MiniportAdapterHandle)
Definition: io.c:721
VOID EXPORT NdisFreeMemory(IN PVOID VirtualAddress, IN UINT Length, IN UINT MemoryFlags)
Definition: memory.c:110
VOID EXPORT NdisMCancelTimer(IN PNDIS_MINIPORT_TIMER Timer, OUT PBOOLEAN TimerCancelled)
Definition: time.c:131
#define ASSERT(a)
Definition: mode.c:44
#define NdisFreeSpinLock(_SpinLock)
Definition: ndis.h:4097
_Out_ _At_ TimerCancelled PBOOLEAN TimerCancelled
Definition: ndis.h:2820
VOID EXPORT NdisMDeregisterAdapterShutdownHandler(IN NDIS_HANDLE MiniportHandle)
Definition: miniport.c:1517
BOOLEAN EXPORT NdisMSynchronizeWithInterrupt(IN PNDIS_MINIPORT_INTERRUPT Interrupt, IN PVOID SynchronizeFunction, IN PVOID SynchronizeContext)
Definition: miniport.c:2955
static BOOLEAN NTAPI MiSyncStop(IN PVOID SynchronizeContext)
Definition: pcnet.c:554
struct _ADAPTER * PADAPTER
#define NUMBER_OF_PORTS
Definition: pcnethw.h:34
Definition: pcnet.h:58
NDIS_SPIN_LOCK Lock
Definition: pcnet.h:59
ULONG IoBaseAddress
Definition: pcnet.h:64
NDIS_MINIPORT_TIMER MediaDetectionTimer
Definition: pcnet.h:70
NDIS_MINIPORT_INTERRUPT InterruptObject
Definition: pcnet.h:66

Referenced by DriverEntry().

◆ MiniportHandleInterrupt()

static VOID NTAPI MiniportHandleInterrupt ( IN NDIS_HANDLE  MiniportAdapterContext)
static

Definition at line 54 of file pcnet.c.

63{
64 PADAPTER Adapter = (PADAPTER)MiniportAdapterContext;
66 UINT i = 0;
67
68 DPRINT("Called\n");
69
71
73
76
77 DPRINT("CSR0 is 0x%x\n", Data);
78
79 while((Data & CSR0_INTR) && i++ < INTERRUPT_LIMIT)
80 {
81 /* Clear interrupt flags early to avoid race conditions. */
83
84 if(Data & CSR0_ERR)
85 {
87 if (Data & CSR0_CERR)
88 Adapter->Statistics.XmtCollisions++;
89 }
90 if(Data & CSR0_IDON)
91 {
92 DPRINT("IDON\n");
93 }
94 if(Data & CSR0_RINT)
95 {
96 BOOLEAN IndicatedData = FALSE;
97
98 DPRINT("receive interrupt\n");
99
100 while(1)
101 {
105
106 if(Descriptor->FLAGS & RD_OWN)
107 {
108 DPRINT("no more receive descriptors to process\n");
109 break;
110 }
111
112 if(Descriptor->FLAGS & RD_ERR)
113 {
114 DPRINT("receive descriptor error: 0x%x\n", Descriptor->FLAGS);
115 if (Descriptor->FLAGS & RD_BUFF)
116 Adapter->Statistics.RcvBufferErrors++;
117 if (Descriptor->FLAGS & RD_CRC)
118 Adapter->Statistics.RcvCrcErrors++;
119 if (Descriptor->FLAGS & RD_OFLO)
120 Adapter->Statistics.RcvOverflowErrors++;
121 if (Descriptor->FLAGS & RD_FRAM)
122 Adapter->Statistics.RcvFramingErrors++;
123 break;
124 }
125
126 if(!((Descriptor->FLAGS & RD_STP) && (Descriptor->FLAGS & RD_ENP)))
127 {
128 DPRINT("receive descriptor not start&end: 0x%x\n", Descriptor->FLAGS);
129 break;
130 }
131
133 ByteCount = Descriptor->MCNT & 0xfff;
134
135 DPRINT("Indicating a %d-byte packet (index %d)\n", ByteCount, Adapter->CurrentReceiveDescriptorIndex);
136
138
139 IndicatedData = TRUE;
140
142 Descriptor->RBADR = Adapter->ReceiveBufferPtrPhys.QuadPart +
144 Descriptor->BCNT = (-BUFFER_SIZE) | 0xf000;
145 Descriptor->FLAGS |= RD_OWN;
146
148 Adapter->CurrentReceiveDescriptorIndex %= Adapter->BufferCount;
149
150 Adapter->Statistics.RcvGoodFrames++;
151 }
152
153 if (IndicatedData)
155 }
156 if(Data & CSR0_TINT)
157 {
159
160 DPRINT("transmit interrupt\n");
161
162 while (Adapter->CurrentTransmitStartIndex !=
164 {
166
167 DPRINT("buffer %d flags %x flags2 %x\n",
169 Descriptor->FLAGS, Descriptor->FLAGS2);
170
171 if (Descriptor->FLAGS & TD1_OWN)
172 {
173 DPRINT("non-TXed buffer\n");
174 break;
175 }
176
177 if (Descriptor->FLAGS & TD1_STP)
178 {
179 if (Descriptor->FLAGS & TD1_ONE)
180 Adapter->Statistics.XmtOneRetry++;
181 else if (Descriptor->FLAGS & TD1_MORE)
183 }
184
185 if (Descriptor->FLAGS & TD1_ERR)
186 {
187 DPRINT("major error: %x\n", Descriptor->FLAGS2);
188 if (Descriptor->FLAGS2 & TD2_RTRY)
189 Adapter->Statistics.XmtRetryErrors++;
190 if (Descriptor->FLAGS2 & TD2_LCAR)
192 if (Descriptor->FLAGS2 & TD2_LCOL)
193 Adapter->Statistics.XmtLateCollisions++;
194 if (Descriptor->FLAGS2 & TD2_EXDEF)
196 if (Descriptor->FLAGS2 & TD2_UFLO)
198 if (Descriptor->FLAGS2 & TD2_BUFF)
199 Adapter->Statistics.XmtBufferErrors++;
200 break;
201 }
202
203 Adapter->CurrentTransmitStartIndex++;
204 Adapter->CurrentTransmitStartIndex %= Adapter->BufferCount;
205
206 Adapter->Statistics.XmtGoodFrames++;
207 }
209 }
211 {
212 DPRINT("UNHANDLED INTERRUPT CSR0 0x%x\n", Data);
213 }
214
216 }
217
218 /* re-enable interrupts */
220
222 DPRINT("CSR0 is now 0x%x\n", Data);
223
224 NdisDprReleaseSpinLock(&Adapter->Lock);
225}
Definition: bufpool.h:45
#define ASSERT_IRQL_EQUAL(x)
Definition: debug.h:43
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define NdisMEthIndicateReceiveComplete(MiniportAdapterHandle)
Definition: ndis.h:5482
#define NdisMEthIndicateReceive(MiniportAdapterHandle, MiniportReceiveContext, HeaderBuffer, HeaderBufferSize, LookaheadBuffer, LookaheadBufferSize, PacketSize)
Definition: ndis.h:5458
#define NdisMSendResourcesAvailable(MiniportAdapterHandle)
Definition: ndis.h:5702
#define NdisDprReleaseSpinLock(_SpinLock)
Definition: ndis.h:4133
#define NdisDprAcquireSpinLock(_SpinLock)
Definition: ndis.h:4124
#define INTERRUPT_LIMIT
Definition: ne2000.h:61
#define RD_BUFF
Definition: pcnethw.h:378
#define CSR0_RINT
Definition: pcnethw.h:163
#define TD1_ONE
Definition: pcnethw.h:401
#define CSR0_INTR
Definition: pcnethw.h:160
#define RD_ENP
Definition: pcnethw.h:376
#define TD1_ERR
Definition: pcnethw.h:406
#define TD2_EXDEF
Definition: pcnethw.h:413
#define RD_ERR
Definition: pcnethw.h:382
#define CSR0_CERR
Definition: pcnethw.h:166
#define TD2_BUFF
Definition: pcnethw.h:415
#define CSR0_IDON
Definition: pcnethw.h:161
#define CSR0_TINT
Definition: pcnethw.h:162
#define RD_OFLO
Definition: pcnethw.h:380
#define TD1_MORE
Definition: pcnethw.h:402
#define TD2_LCAR
Definition: pcnethw.h:411
#define CSR0_MERR
Definition: pcnethw.h:164
#define TD2_UFLO
Definition: pcnethw.h:414
#define RD_FRAM
Definition: pcnethw.h:381
#define TD1_OWN
Definition: pcnethw.h:407
#define CSR0_MISS
Definition: pcnethw.h:165
#define CSR0_BABL
Definition: pcnethw.h:167
#define CSR0_ERR
Definition: pcnethw.h:168
#define TD2_RTRY
Definition: pcnethw.h:410
#define RD_CRC
Definition: pcnethw.h:379
#define TD2_LCOL
Definition: pcnethw.h:412
#define RD_STP
Definition: pcnethw.h:377
ULONG XmtCollisions
Definition: pcnet.h:42
ULONG XmtOneRetry
Definition: pcnet.h:47
ULONG RcvCrcErrors
Definition: pcnet.h:51
ULONG XmtLossesOfCarrier
Definition: pcnet.h:41
ULONG RcvBufferErrors
Definition: pcnet.h:50
ULONG XmtGoodFrames
Definition: pcnet.h:39
ULONG RcvFramingErrors
Definition: pcnet.h:53
ULONG XmtBufferUnderflows
Definition: pcnet.h:45
ULONG RcvOverflowErrors
Definition: pcnet.h:52
ULONG RcvGoodFrames
Definition: pcnet.h:49
ULONG XmtLateCollisions
Definition: pcnet.h:43
ULONG XmtMoreThanOneRetry
Definition: pcnet.h:48
ULONG XmtBufferErrors
Definition: pcnet.h:46
ULONG XmtExcessiveDeferrals
Definition: pcnet.h:44
ULONG XmtRetryErrors
Definition: pcnet.h:40
ULONG CurrentReceiveDescriptorIndex
Definition: pcnet.h:71
ADAPTER_STATS Statistics
Definition: pcnet.h:108
ULONG CurrentTransmitStartIndex
Definition: pcnet.h:76
ULONG CurrentTransmitEndIndex
Definition: pcnet.h:77
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1099

Referenced by DriverEntry().

◆ MiniportInitialize()

static 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 
)
static

Definition at line 853 of file pcnet.c.

880{
881 UINT i = 0;
882 PADAPTER Adapter = 0;
884 BOOLEAN InterruptRegistered = FALSE, MapRegistersAllocated = FALSE;
886 UINT *RegNetworkAddress = 0;
887 UINT RegNetworkAddressLength = 0;
888
890
891 /* Pick a medium */
892 for(i = 0; i < MediumArraySize; i++)
893 if(MediumArray[i] == NdisMedium802_3)
894 break;
895
896 if(i == MediumArraySize)
897 {
899 DPRINT1("unsupported media\n");
901 return Status;
902 }
903
905
906 /* allocate our adapter struct */
907 Status = NdisAllocateMemoryWithTag((PVOID *)&Adapter, sizeof(ADAPTER), PCNET_TAG);
909 {
911 DPRINT1("Insufficient resources\n");
913 return Status;
914 }
915
916 RtlZeroMemory(Adapter, sizeof(ADAPTER));
917
918 Adapter->MiniportAdapterHandle = MiniportAdapterHandle;
919
920 /* register our adapter structwith ndis */
921 NdisMSetAttributesEx(Adapter->MiniportAdapterHandle, Adapter, 0, NDIS_ATTRIBUTE_BUS_MASTER, NdisInterfacePci);
922
923 do
924 {
925 /* Card-specific detection and setup */
926 Status = MiQueryCard(Adapter);
928 {
929 DPRINT1("MiQueryCard failed\n");
931 break;
932 }
933
934 /* register an IO port range */
935 Status = NdisMRegisterIoPortRange((PVOID*)&Adapter->PortOffset, Adapter->MiniportAdapterHandle,
936 (UINT)Adapter->IoBaseAddress, NUMBER_OF_PORTS);
938 {
939 DPRINT1("NdisMRegisterIoPortRange failed: 0x%x\n", Status);
940 break;
941 }
942
943 /* Allocate map registers */
944 Status = NdisMAllocateMapRegisters(Adapter->MiniportAdapterHandle, 0,
947 {
948 DPRINT1("NdisMAllocateMapRegisters failed: 0x%x\n", Status);
949 break;
950 }
951
952 MapRegistersAllocated = TRUE;
953
954 /* set up the interrupt */
955 Status = NdisMRegisterInterrupt(&Adapter->InterruptObject, Adapter->MiniportAdapterHandle, Adapter->InterruptVector,
956 Adapter->InterruptVector, TRUE, TRUE, NdisInterruptLevelSensitive);
958 {
959 DPRINT1("NdisMRegisterInterrupt failed: 0x%x\n", Status);
960 break;
961 }
962
963 InterruptRegistered = TRUE;
964
965 /* Allocate and initialize shared data structures */
968 {
970 DPRINT1("MiAllocateSharedMemory failed\n", Status);
971 break;
972 }
973
974 /* set up the initialization block */
976
977 /* see if someone set a network address manually */
980 {
981 NdisReadNetworkAddress(&Status, (PVOID *)&RegNetworkAddress, &RegNetworkAddressLength, ConfigurationHandle);
982 if(Status == NDIS_STATUS_SUCCESS && RegNetworkAddressLength == 6)
983 {
984 int i;
985 DPRINT("NdisReadNetworkAddress returned successfully, address %x:%x:%x:%x:%x:%x\n",
986 RegNetworkAddress[0], RegNetworkAddress[1], RegNetworkAddress[2], RegNetworkAddress[3],
987 RegNetworkAddress[4], RegNetworkAddress[5]);
988
989 for(i = 0; i < 6; i++)
990 Adapter->InitializationBlockVirt->PADR[i] = RegNetworkAddress[i];
991 }
992
994 }
995
996 DPRINT("Interrupt registered successfully\n");
997
998 /* Initialize and start the chip */
999 MiInitChip(Adapter);
1000
1001 NdisAllocateSpinLock(&Adapter->Lock);
1002
1004 }
1005 while(0);
1006
1007 if(Status != NDIS_STATUS_SUCCESS && Adapter)
1008 {
1009 DPRINT("Error; freeing stuff\n");
1010
1011 MiFreeSharedMemory(Adapter);
1012
1013 if(MapRegistersAllocated)
1014 NdisMFreeMapRegisters(Adapter->MiniportAdapterHandle);
1015
1016 if(Adapter->PortOffset)
1017 NdisMDeregisterIoPortRange(Adapter->MiniportAdapterHandle, Adapter->IoBaseAddress, NUMBER_OF_PORTS, (PVOID)Adapter->PortOffset);
1018
1019 if(InterruptRegistered)
1020 NdisMDeregisterInterrupt(&Adapter->InterruptObject);
1021
1022 NdisFreeMemory(Adapter, 0, 0);
1023 }
1024
1026 {
1027 NdisMInitializeTimer(&Adapter->MediaDetectionTimer,
1028 Adapter->MiniportAdapterHandle,
1030 Adapter);
1031 NdisMSetPeriodicTimer(&Adapter->MediaDetectionTimer,
1033 NdisMRegisterAdapterShutdownHandler(Adapter->MiniportAdapterHandle,
1034 Adapter,
1036 }
1037
1038#if DBG
1039 if(!MiTestCard(Adapter))
1040 ASSERT(0);
1041#endif
1042
1043 DPRINT("returning 0x%x\n", Status);
1045 return Status;
1046}
VOID EXPORT NdisCloseConfiguration(IN NDIS_HANDLE ConfigurationHandle)
Definition: config.c:136
VOID EXPORT NdisReadNetworkAddress(OUT PNDIS_STATUS Status, OUT PVOID *NetworkAddress, OUT PUINT NetworkAddressLength, IN NDIS_HANDLE ConfigurationHandle)
Definition: config.c:740
VOID EXPORT NdisOpenConfiguration(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE ConfigurationHandle, IN NDIS_HANDLE WrapperConfigurationContext)
Definition: config.c:197
NDIS_STATUS EXPORT NdisMAllocateMapRegisters(IN NDIS_HANDLE MiniportAdapterHandle, IN UINT DmaChannel, IN NDIS_DMA_SIZE DmaSize, IN ULONG BaseMapRegistersNeeded, IN ULONG MaximumBufferSize)
Definition: io.c:252
NDIS_STATUS EXPORT NdisMRegisterIoPortRange(OUT PVOID *PortOffset, IN NDIS_HANDLE MiniportAdapterHandle, IN UINT InitialPort, IN UINT NumberOfPorts)
Definition: io.c:1018
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 NdisMSetPeriodicTimer(IN PNDIS_MINIPORT_TIMER Timer, IN UINT MillisecondsPeriod)
Definition: time.c:226
VOID EXPORT NdisMInitializeTimer(IN OUT PNDIS_MINIPORT_TIMER Timer, IN NDIS_HANDLE MiniportAdapterHandle, IN PNDIS_TIMER_FUNCTION TimerFunction, IN PVOID FunctionContext)
Definition: time.c:192
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define NDIS_DMA_32BITS
Definition: ndis.h:881
#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
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE ConfigurationHandle
Definition: ndis.h:3945
#define NDIS_STATUS_UNSUPPORTED_MEDIA
Definition: ndis.h:490
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS OpenErrorStatus
Definition: ndis.h:6009
#define NDIS_STATUS_ADAPTER_NOT_FOUND
Definition: ndis.h:470
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
VOID EXPORT NdisMRegisterAdapterShutdownHandler(IN NDIS_HANDLE MiniportHandle, IN PVOID ShutdownContext, IN ADAPTER_SHUTDOWN_HANDLER ShutdownHandler)
Definition: miniport.c:1694
@ NdisMedium802_3
Definition: ntddndis.h:188
static VOID MiPrepareInitializationBlock(PADAPTER Adapter)
Definition: pcnet.c:518
VOID NTAPI MiniportShutdown(PVOID Context)
Definition: pcnet.c:841
static NDIS_STATUS MiAllocateSharedMemory(PADAPTER Adapter)
Definition: pcnet.c:353
static VOID NTAPI MiniportMediaDetectionTimer(IN PVOID SystemSpecific1, IN PVOID FunctionContext, IN PVOID SystemSpecific2, IN PVOID SystemSpecific3)
Definition: pcnet.c:645
static NDIS_STATUS MiQueryCard(IN PADAPTER Adapter)
Definition: pcnet.c:228
static VOID MiInitChip(PADAPTER Adapter)
Definition: pcnet.c:675
#define MEDIA_DETECTION_INTERVAL
Definition: pcnet.h:156
#define PCNET_TAG
Definition: pcnet.h:165

Referenced by DriverEntry().

◆ MiniportISR()

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

Definition at line 1050 of file pcnet.c.

1065{
1066 USHORT Data;
1067 USHORT Rap;
1068 PADAPTER Adapter = (PADAPTER)MiniportAdapterContext;
1069
1070 DPRINT("Called\n");
1071
1072 /* save the old RAP value */
1073 NdisRawReadPortUshort(Adapter->PortOffset + RAP, &Rap);
1074
1075 /* is this ours? */
1078
1079 if(!(Data & CSR0_INTR))
1080 {
1081 DPRINT("not our interrupt.\n");
1082 *InterruptRecognized = FALSE;
1083 *QueueMiniportHandleInterrupt = FALSE;
1084 }
1085 else
1086 {
1087 DPRINT("detected our interrupt\n");
1088
1089 /* disable interrupts */
1091 NdisRawWritePortUshort(Adapter->PortOffset + RDP, 0);
1092
1093 *InterruptRecognized = TRUE;
1094 *QueueMiniportHandleInterrupt = TRUE;
1095 }
1096
1097 /* restore the rap */
1098 NdisRawWritePortUshort(Adapter->PortOffset + RAP, Rap);
1099}

Referenced by DriverEntry().

◆ MiniportMediaDetectionTimer()

static VOID NTAPI MiniportMediaDetectionTimer ( IN PVOID  SystemSpecific1,
IN PVOID  FunctionContext,
IN PVOID  SystemSpecific2,
IN PVOID  SystemSpecific3 
)
static

Definition at line 645 of file pcnet.c.

657{
659
661
665 {
669 (PVOID)0, 0);
671 }
672}
#define NDIS_STATUS_MEDIA_CONNECT
Definition: ndis.h:361
#define NdisMIndicateStatusComplete(MiniportAdapterHandle)
Definition: ndis.h:5580
#define NDIS_STATUS_MEDIA_DISCONNECT
Definition: ndis.h:362
_In_ PVOID FunctionContext
Definition: ndis.h:637
#define NdisMIndicateStatus(MiniportAdapterHandle, GeneralStatus, StatusBuffer, StatusBufferSize)
Definition: ndis.h:5570
static BOOLEAN NTAPI MiSyncMediaDetection(IN PVOID SynchronizeContext)
Definition: pcnet.c:616

Referenced by MiniportInitialize().

◆ MiniportReset()

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

Definition at line 1103 of file pcnet.c.

1117{
1118 DPRINT("Called\n");
1119
1120 /* MiniportReset doesn't do anything at the moment... perhaps this should be fixed. */
1121
1122 *AddressingReset = FALSE;
1123 return NDIS_STATUS_SUCCESS;
1124}

Referenced by DriverEntry().

◆ MiniportSend()

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

Definition at line 1144 of file pcnet.c.

1160{
1161 PADAPTER Adapter = (PADAPTER)MiniportAdapterContext;
1163 PNDIS_BUFFER NdisBuffer;
1164 PVOID SourceBuffer;
1165 UINT TotalPacketLength, SourceLength, Position = 0;
1166
1167 DPRINT("Called\n");
1168
1170
1171 NdisDprAcquireSpinLock(&Adapter->Lock);
1172
1173 /* Check if we have free entry in our circular buffer. */
1174 if ((Adapter->CurrentTransmitEndIndex + 1 ==
1175 Adapter->CurrentTransmitStartIndex) ||
1176 (Adapter->CurrentTransmitEndIndex == Adapter->BufferCount - 1 &&
1177 Adapter->CurrentTransmitStartIndex == 0))
1178 {
1179 DPRINT1("No free space in circular buffer\n");
1180 NdisDprReleaseSpinLock(&Adapter->Lock);
1181 return NDIS_STATUS_RESOURCES;
1182 }
1183
1184 Desc = Adapter->TransmitDescriptorRingVirt + Adapter->CurrentTransmitEndIndex;
1185
1186 NdisQueryPacket(Packet, NULL, NULL, &NdisBuffer, &TotalPacketLength);
1187 ASSERT(TotalPacketLength <= BUFFER_SIZE);
1188
1189 DPRINT("TotalPacketLength: %x\n", TotalPacketLength);
1190
1191 while (NdisBuffer)
1192 {
1193 NdisQueryBuffer(NdisBuffer, &SourceBuffer, &SourceLength);
1194
1195 DPRINT("Buffer: %x Length: %x\n", SourceBuffer, SourceLength);
1196
1199 SourceBuffer, SourceLength);
1200
1201 Position += SourceLength;
1202
1203 NdisGetNextBuffer(NdisBuffer, &NdisBuffer);
1204 }
1205
1206#if DBG && 0
1207 {
1208 PUCHAR Ptr = Adapter->TransmitBufferPtrVirt +
1210 for (Position = 0; Position < TotalPacketLength; Position++)
1211 {
1212 if (Position % 16 == 0)
1213 DbgPrint("\n");
1214 DbgPrint("%x ", *Ptr++);
1215 }
1216 }
1217 DbgPrint("\n");
1218#endif
1219
1220 Adapter->CurrentTransmitEndIndex++;
1221 Adapter->CurrentTransmitEndIndex %= Adapter->BufferCount;
1222
1223 Desc->FLAGS = TD1_OWN | TD1_STP | TD1_ENP;
1224 Desc->BCNT = 0xf000 | -(INT)TotalPacketLength;
1225
1227
1228 NdisDprReleaseSpinLock(&Adapter->Lock);
1229
1230 return NDIS_STATUS_SUCCESS;
1231}
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
#define DbgPrint
Definition: hal.h:12
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
static __inline VOID NdisQueryPacket(IN PNDIS_PACKET Packet, OUT PUINT PhysicalBufferCount OPTIONAL, OUT PUINT BufferCount OPTIONAL, OUT PNDIS_BUFFER *FirstBuffer OPTIONAL, OUT PUINT TotalPacketLength OPTIONAL)
Definition: ndis.h:3593
MDL * PNDIS_BUFFER
Definition: ndis.h:343
#define NdisQueryBuffer(_Buffer, _VirtualAddress, _Length)
Definition: ndis.h:3029
static BOOLEAN NTAPI MiSyncStartTransmit(IN PVOID SynchronizeContext)
Definition: pcnet.c:1128
#define INT
Definition: polytest.cpp:20
static COORD Position
Definition: mouse.c:34
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
unsigned char * PUCHAR
Definition: typedefs.h:53

Referenced by DriverEntry().

◆ MiniportShutdown()

VOID NTAPI MiniportShutdown ( PVOID  Context)

Definition at line 841 of file pcnet.c.

842{
843 PADAPTER Adapter = Context;
844
845 DPRINT("Stopping the chip\n");
846
849}

Referenced by MiniportInitialize().

◆ MiPrepareInitializationBlock()

static VOID MiPrepareInitializationBlock ( PADAPTER  Adapter)
static

Definition at line 518 of file pcnet.c.

525{
526 ULONG i = 0;
527
529
530 /* read burned-in address from card */
531 for(i = 0; i < 6; i++)
533 DPRINT("MAC address: %02x-%02x-%02x-%02x-%02x-%02x\n",
534 Adapter->InitializationBlockVirt->PADR[0],
535 Adapter->InitializationBlockVirt->PADR[1],
536 Adapter->InitializationBlockVirt->PADR[2],
537 Adapter->InitializationBlockVirt->PADR[3],
538 Adapter->InitializationBlockVirt->PADR[4],
539 Adapter->InitializationBlockVirt->PADR[5]);
540
541 /* set up receive ring */
542 DPRINT("Receive ring physical address: 0x%x\n", Adapter->ReceiveDescriptorRingPhys);
544 Adapter->InitializationBlockVirt->RLEN = (Adapter->LogBufferCount << 4) & 0xf0;
545
546 /* set up transmit ring */
547 DPRINT("Transmit ring physical address: 0x%x\n", Adapter->TransmitDescriptorRingPhys);
549 Adapter->InitializationBlockVirt->TLEN = (Adapter->LogBufferCount << 4) & 0xf0;
550}
#define NdisRawReadPortUchar(Port, Data)
Definition: ndis.h:4173

Referenced by MiniportInitialize().

◆ MiQueryCard()

static NDIS_STATUS MiQueryCard ( IN PADAPTER  Adapter)
static

Definition at line 228 of file pcnet.c.

239{
240 ULONG buf32 = 0;
241 UCHAR buf8 = 0;
243
244 /* Detect the card in the configured slot */
245 Status = NdisReadPciSlotInformation(Adapter->MiniportAdapterHandle, 0, PCI_PCIID, &buf32, 4);
246 if(Status != 4)
247 {
249 DPRINT1("NdisReadPciSlotInformation failed\n");
250 return Status;
251 }
252
253 if(buf32 != PCI_ID)
254 {
256 DPRINT1("card in slot isn't our: 0x%x\n", 0, buf32);
257 return Status;
258 }
259
260 /* set busmaster and io space enable bits */
261 buf32 = PCI_BMEN | PCI_IOEN;
262 NdisWritePciSlotInformation(Adapter->MiniportAdapterHandle, 0, PCI_COMMAND, &buf32, 4);
263
264 /* get IO base physical address */
265 buf32 = 0;
266 Status = NdisReadPciSlotInformation(Adapter->MiniportAdapterHandle, 0, PCI_IOBAR, &buf32, 4);
267 if(Status != 4)
268 {
270 DPRINT1("NdisReadPciSlotInformation failed\n");
271 return Status;
272 }
273
274 if(!buf32)
275 {
276 DPRINT1("No base i/o address set\n");
277 return NDIS_STATUS_FAILURE;
278 }
279
280 buf32 &= ~1; /* even up address - comes out odd for some reason */
281
282 DPRINT("detected io address 0x%x\n", buf32);
283 Adapter->IoBaseAddress = buf32;
284
285 /* get interrupt vector */
286 Status = NdisReadPciSlotInformation(Adapter->MiniportAdapterHandle, 0, PCI_ILR, &buf8, 1);
287 if(Status != 1)
288 {
290 DPRINT1("NdisReadPciSlotInformation failed\n");
291 return Status;
292 }
293
294 DPRINT("interrupt: 0x%x\n", buf8);
295 Adapter->InterruptVector = buf8;
296
297 return NDIS_STATUS_SUCCESS;
298}
#define PCI_IOBAR
Definition: pci.h:40
#define PCI_PCIID
Definition: pci.h:29
#define PCI_BMEN
Definition: pci.h:51
#define PCI_ILR
Definition: pci.h:43
#define PCI_IOEN
Definition: pci.h:49
ULONG EXPORT NdisReadPciSlotInformation(IN NDIS_HANDLE NdisAdapterHandle, IN ULONG SlotNumber, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length)
Definition: hardware.c:180
ULONG EXPORT NdisWritePciSlotInformation(IN NDIS_HANDLE NdisAdapterHandle, IN ULONG SlotNumber, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length)
Definition: hardware.c:199
#define PCI_COMMAND
Definition: pcidef.h:26
#define PCI_ID
Definition: pcnethw.h:52
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by MiniportInitialize().

◆ MiSetMulticast()

NDIS_STATUS NTAPI MiSetMulticast ( PADAPTER  Adapter,
UCHAR Addresses,
UINT  AddressCount 
)

Definition at line 1262 of file pcnet.c.

1266{
1267 UINT Index;
1268 ULONG CrcIndex;
1269
1271 for (Index = 0; Index < AddressCount; Index++)
1272 {
1273 CrcIndex = MiEthernetCrc(Addresses) >> 26;
1274 Adapter->InitializationBlockVirt->LADR[CrcIndex >> 3] |= 1 << (CrcIndex & 15);
1275 Addresses += 6;
1276 }
1277
1278 /* FIXME: The specification mentions we need to reload the init block here. */
1279
1280 return NDIS_STATUS_SUCCESS;
1281}
#define NdisZeroMemory(Destination, Length)
Definition: ndis.h:3926
static ULONG NTAPI MiEthernetCrc(UCHAR *Address)
Definition: pcnet.c:1235
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by MiniportSetInformation().

◆ MiSyncMediaDetection()

static BOOLEAN NTAPI MiSyncMediaDetection ( IN PVOID  SynchronizeContext)
static

Definition at line 616 of file pcnet.c.

623{
625 NDIS_MEDIA_STATE MediaState = MiGetMediaState(Adapter);
626 UINT MediaSpeed = MiGetMediaSpeed(Adapter);
627 BOOLEAN FullDuplex = MiGetMediaDuplex(Adapter);
628
629 DPRINT("Called\n");
630 DPRINT("MediaState: %d\n", MediaState);
631 if (MediaState != Adapter->MediaState ||
632 MediaSpeed != Adapter->MediaSpeed ||
633 FullDuplex != Adapter->FullDuplex)
634 {
635 Adapter->MediaState = MediaState;
636 Adapter->MediaSpeed = MediaSpeed;
637 Adapter->FullDuplex = FullDuplex;
638 return TRUE;
639 }
640 return FALSE;
641}
enum _NDIS_MEDIA_STATE NDIS_MEDIA_STATE
_In_ PKSYNCHRONIZE_ROUTINE _In_opt_ __drv_aliasesMem PVOID SynchronizeContext
Definition: kefuncs.h:525

Referenced by MiniportMediaDetectionTimer().

◆ MiSyncStartTransmit()

static BOOLEAN NTAPI MiSyncStartTransmit ( IN PVOID  SynchronizeContext)
static

Definition at line 1128 of file pcnet.c.

1135{
1139 return TRUE;
1140}
#define CSR0_TDMD
Definition: pcnethw.h:156

Referenced by MiniportSend().

◆ MiSyncStop()

static BOOLEAN NTAPI MiSyncStop ( IN PVOID  SynchronizeContext)
static

Definition at line 554 of file pcnet.c.

561{
565 return TRUE;
566}

Referenced by MiniportHalt().