ReactOS 0.4.15-dev-7958-gcd0bb1a
pcnet.c
Go to the documentation of this file.
1/*
2 * ReactOS AMD PCNet Driver
3 *
4 * Copyright (C) 2003 Vizzini <vizzini@plasmic.com>
5 * Copyright (C) 2004 Filip Navara <navaraf@reactos.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * REVISIONS:
22 * 09-Sep-2003 vizzini - Created
23 * 10-Oct-2004 navaraf - Fix receive to work on VMware adapters (
24 * need to set busmaster bit on PCI).
25 * - Indicate receive completion.
26 * - Implement packet transmitting.
27 * - Don't read slot number from registry and
28 * report itself as NDIS 5.0 miniport.
29 * 11-Oct-2004 navaraf - Fix nasty bugs in halt code path.
30 * 17-Oct-2004 navaraf - Add multicast support.
31 * - Add media state detection support.
32 * - Protect the adapter context with spinlock
33 * and move code talking to card to inside
34 * NdisMSynchronizeWithInterrupt calls where
35 * necessary.
36 *
37 * NOTES:
38 * - this assumes a 32-bit machine
39 */
40
41#include "pcnet.h"
42
43#define NDEBUG
44#include <debug.h>
45
51
52static VOID
55 IN NDIS_HANDLE MiniportAdapterContext)
56/*
57 * FUNCTION: Handle an interrupt if told to by MiniportISR
58 * ARGUMENTS:
59 * MiniportAdapterContext: context specified to NdisMSetAttributes
60 * NOTES:
61 * - Called by NDIS at DISPATCH_LEVEL
62 */
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}
226
227static NDIS_STATUS
229 IN PADAPTER Adapter)
230/*
231 * FUNCTION: Detect the PCNET NIC in the configured slot and query its I/O address and interrupt vector
232 * ARGUMENTS:
233 * MiniportAdapterContext: context supplied to NdisMSetAttributes
234 * RETURNS:
235 * NDIS_STATUS_FAILURE on a general error
236 * NDIS_STATUS_ADAPTER_NOT_FOUND on not finding the adapter
237 * NDIS_STATUS_SUCCESS on succes
238 */
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}
299
300static VOID
302 PADAPTER Adapter)
303/*
304 * FUNCTION: Free all allocated shared memory
305 * ARGUMENTS:
306 * Adapter: pointer to the miniport's adapter struct
307 */
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}
351
352static NDIS_STATUS
354 PADAPTER Adapter)
355/*
356 * FUNCTION: Allocate all shared memory used by the miniport
357 * ARGUMENTS:
358 * Adapter: Pointer to the miniport's adapter object
359 * RETURNS:
360 * NDIS_STATUS_RESOURCES on insufficient memory
361 * NDIS_STATUS_SUCCESS on success
362 */
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}
516
517static VOID
519 PADAPTER Adapter)
520/*
521 * FUNCTION: Initialize the initialization block
522 * ARGUMENTS:
523 * Adapter: pointer to the miniport's adapter object
524 */
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}
551
552static BOOLEAN
553NTAPI
556/*
557 * FUNCTION: Stop the adapter
558 * ARGUMENTS:
559 * SynchronizeContext: Adapter context
560 */
561{
565 return TRUE;
566}
567
568static VOID
569NTAPI
571 IN NDIS_HANDLE MiniportAdapterContext)
572/*
573 * FUNCTION: Stop the adapter and release any per-adapter resources
574 * ARGUMENTS:
575 * MiniportAdapterContext: context specified to NdisMSetAttributes
576 * NOTES:
577 * - Called by NDIS at PASSIVE_LEVEL
578 */
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}
613
614static BOOLEAN
615NTAPI
618/*
619 * FUNCTION: Stop the adapter
620 * ARGUMENTS:
621 * SynchronizeContext: Adapter context
622 */
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}
642
643static VOID
644NTAPI
646 IN PVOID SystemSpecific1,
650/*
651 * FUNCTION: Periodically query media state
652 * ARGUMENTS:
653 * FunctionContext: Adapter context
654 * NOTES:
655 * - Called by NDIS at DISPATCH_LEVEL
656 */
657{
659
661
665 {
669 (PVOID)0, 0);
671 }
672}
673
674static VOID
676 PADAPTER Adapter)
677/*
678 * FUNCTION: Initialize and start the PCNET chip
679 * ARGUMENTS:
680 * Adapter: pointer to the miniport's adapter struct
681 * NOTES:
682 * - should be coded to detect failure and return an error
683 * - the vmware virtual lance chip doesn't support 32-bit i/o so don't do that.
684 */
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}
774
775#if DBG
776static BOOLEAN
777MiTestCard(
778 PADAPTER Adapter)
779/*
780 * FUNCTION: Test the NIC
781 * ARGUMENTS:
782 * Adapter: pointer to the miniport's adapter struct
783 * RETURNS:
784 * TRUE if the test succeeds
785 * FALSE otherwise
786 * NOTES:
787 * - this is where to add diagnostics. This is called
788 * at the very end of initialization.
789 */
790{
791 int i = 0;
792 UCHAR address[6];
793 USHORT Data = 0;
794
795 /* see if we can read/write now */
798 DPRINT("Port 0x%x RAP 0x%x CSR0 0x%x RDP 0x%x, Interrupt status register is 0x%x\n", Adapter->PortOffset, RAP, CSR0, RDP, Data);
799
800 /* read the BIA */
801 for(i = 0; i < 6; i++)
803
804 DPRINT("burned-in address: %02x:%02x:%02x:%02x:%02x:%02x\n", address[0], address[1], address[2], address[3], address[4], address[5]);
805 /* Read status flags from CSR0 */
808 DPRINT("CSR0: 0x%x\n", Data);
809
810 /* Read status flags from CSR3 */
813 DPRINT("CSR3: 0x%x\n", Data);
814
815 /* Read status flags from CSR4 */
818 DPRINT("CSR4: 0x%x\n", Data);
819
820 /* Read status flags from CSR5 */
823 DPRINT("CSR5: 0x%x\n", Data);
824
825 /* Read status flags from CSR6 */
828 DPRINT("CSR6: 0x%x\n", Data);
829
830 /* Read status flags from BCR4 */
833 DPRINT("BCR4: 0x%x\n", Data);
834
835 return TRUE;
836}
837#endif
838
839VOID
840NTAPI
842{
843 PADAPTER Adapter = Context;
844
845 DPRINT("Stopping the chip\n");
846
849}
850
851static NDIS_STATUS
852NTAPI
856 IN PNDIS_MEDIUM MediumArray,
860/*
861 * FUNCTION: Initialize a new miniport
862 * ARGUMENTS:
863 * OpenErrorStatus: pointer to a var to return status info in
864 * SelectedMediumIndex: index of the selected medium (will be NdisMedium802_3)
865 * MediumArray: array of media that we can pick from
866 * MediumArraySize: size of MediumArray
867 * MiniportAdapterHandle: NDIS-assigned handle for this miniport instance
868 * WrapperConfigurationContext: temporary NDIS-assigned handle for passing
869 * to configuration APIs
870 * RETURNS:
871 * NDIS_STATUS_SUCCESS on success
872 * NDIS_STATUS_FAILURE on general failure
873 * NDIS_STATUS_UNSUPPORTED_MEDIA on not finding 802_3 in the MediaArray
874 * NDIS_STATUS_RESOURCES on insufficient system resources
875 * NDIS_STATUS_ADAPTER_NOT_FOUND on not finding the adapter
876 * NOTES:
877 * - Called by NDIS at PASSIVE_LEVEL, once per detected card
878 * - Will int 3 on failure of MiTestCard if DBG=1
879 */
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
919
920 /* register our adapter structwith ndis */
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 */
938 {
939 DPRINT1("NdisMRegisterIoPortRange failed: 0x%x\n", Status);
940 break;
941 }
942
943 /* Allocate map registers */
947 {
948 DPRINT1("NdisMAllocateMapRegisters failed: 0x%x\n", Status);
949 break;
950 }
951
952 MapRegistersAllocated = TRUE;
953
954 /* set up the interrupt */
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)
1015
1016 if(Adapter->PortOffset)
1018
1019 if(InterruptRegistered)
1021
1022 NdisFreeMemory(Adapter, 0, 0);
1023 }
1024
1026 {
1028 Adapter->MiniportAdapterHandle,
1030 Adapter);
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}
1047
1048static VOID
1049NTAPI
1051 OUT PBOOLEAN InterruptRecognized,
1052 OUT PBOOLEAN QueueMiniportHandleInterrupt,
1053 IN NDIS_HANDLE MiniportAdapterContext)
1054/*
1055 * FUNCTION: Miniport interrupt service routine
1056 * ARGUMENTS:
1057 * InterruptRecognized: the interrupt was ours
1058 * QueueMiniportHandleInterrupt: whether to queue a DPC to handle this interrupt
1059 * MiniportAdapterContext: the context originally passed to NdisMSetAttributes
1060 * NOTES:
1061 * - called by NDIS at DIRQL
1062 * - by setting QueueMiniportHandleInterrupt to TRUE, MiniportHandleInterrupt
1063 * will be called
1064 */
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}
1100
1101static NDIS_STATUS
1102NTAPI
1104 OUT PBOOLEAN AddressingReset,
1105 IN NDIS_HANDLE MiniportAdapterContext)
1106/*
1107 * FUNCTION: Reset the miniport
1108 * ARGUMENTS:
1109 * AddressingReset: Whether or not we want NDIS to subsequently call MiniportSetInformation
1110 * to reset our addresses and filters
1111 * MiniportAdapterContext: context originally passed to NdisMSetAttributes
1112 * RETURNS:
1113 * NDIS_STATUS_SUCCESS on all requests
1114 * Notes:
1115 * - Called by NDIS at PASSIVE_LEVEL when it thinks we need a reset
1116 */
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}
1125
1126static BOOLEAN
1127NTAPI
1130/*
1131 * FUNCTION: Stop the adapter
1132 * ARGUMENTS:
1133 * SynchronizeContext: Adapter context
1134 */
1135{
1139 return TRUE;
1140}
1141
1142static NDIS_STATUS
1143NTAPI
1145 IN NDIS_HANDLE MiniportAdapterContext,
1147 IN UINT Flags)
1148/*
1149 * FUNCTION: Called by NDIS when it has a packet for the NIC to send out
1150 * ARGUMENTS:
1151 * MiniportAdapterContext: context originally input to NdisMSetAttributes
1152 * Packet: The NDIS_PACKET to be sent
1153 * Flags: Flags associated with Packet
1154 * RETURNS:
1155 * NDIS_STATUS_SUCCESS on processed requests
1156 * NDIS_STATUS_RESOURCES if there's no place in buffer ring
1157 * NOTES:
1158 * - Called by NDIS at DISPATCH_LEVEL
1159 */
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}
1232
1233static ULONG
1234NTAPI
1236/*
1237 * FUNCTION: Calculate Ethernet CRC32
1238 * ARGUMENTS:
1239 * Address: 6-byte ethernet address
1240 * RETURNS:
1241 * The calculated CRC32 value.
1242 */
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}
1259
1261NTAPI
1263 PADAPTER Adapter,
1264 UCHAR *Addresses,
1265 UINT AddressCount)
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}
1282
1283BOOLEAN
1284NTAPI
1286{
1287 ULONG Data;
1288
1291
1292 return (Data & BCR5_LEDOUT) != 0;
1293}
1294
1295UINT
1296NTAPI
1298{
1299 ULONG Data;
1300
1303
1304 return Data & BCR6_LEDOUT ? 100 : 10;
1305}
1306
1308NTAPI
1310/*
1311 * FUNCTION: Determine the link state
1312 * ARGUMENTS:
1313 * Adapter: Adapter context
1314 * RETURNS:
1315 * NdisMediaStateConnected if the cable is connected
1316 * NdisMediaStateDisconnected if the cable is disconnected
1317 */
1318{
1319 ULONG Data;
1323}
1324
1326NTAPI
1330/*
1331 * FUNCTION: Start this driver
1332 * ARGUMENTS:
1333 * DriverObject: Pointer to the system-allocated driver object
1334 * RegistryPath: Pointer to our SCM database entry
1335 * RETURNS:
1336 * NDIS_STATUS_SUCCESS on success
1337 * NDIS_STATUS_FAILURE on failure
1338 * NOTES:
1339 * - Called by the I/O manager when the driver starts at PASSIVE_LEVEL
1340 * - TODO: convert this to NTSTATUS return values
1341 */
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}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
#define ASSERT_IRQL_EQUAL(x)
Definition: debug.h:43
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
#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
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
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
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
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
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
VOID EXPORT NdisFreeMemory(IN PVOID VirtualAddress, IN UINT Length, IN UINT MemoryFlags)
Definition: memory.c:110
NDIS_STATUS EXPORT NdisAllocateMemoryWithTag(OUT PVOID *VirtualAddress, IN UINT Length, IN ULONG Tag)
Definition: memory.c:21
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
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
VOID EXPORT NdisMCancelTimer(IN PNDIS_MINIPORT_TIMER Timer, OUT PBOOLEAN TimerCancelled)
Definition: time.c:131
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 DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
Status
Definition: gdiplustypes.h:25
GLuint address
Definition: glext.h:9393
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 DbgPrint
Definition: hal.h:12
ULONG FLAGS
Definition: mapi.h:36
#define ASSERT(a)
Definition: mode.c:44
#define BUFFER_SIZE
Definition: freeldrpage.c:26
#define NDIS_DMA_32BITS
Definition: ndis.h:881
#define NdisRawReadPortUshort(Port, Data)
Definition: ndis.h:4191
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
#define NDIS_STATUS_MEDIA_CONNECT
Definition: ndis.h:361
#define NdisMEthIndicateReceiveComplete(MiniportAdapterHandle)
Definition: ndis.h:5482
#define NdisMIndicateStatusComplete(MiniportAdapterHandle)
Definition: ndis.h:5580
_In_ PVOID _In_ PVOID SystemSpecific2
Definition: ndis.h:638
#define NdisZeroMemory(Destination, Length)
Definition: ndis.h:3926
unsigned int * PUINT
Definition: ndis.h:50
#define NdisMEthIndicateReceive(MiniportAdapterHandle, MiniportReceiveContext, HeaderBuffer, HeaderBufferSize, LookaheadBuffer, LookaheadBufferSize, PacketSize)
Definition: ndis.h:5458
unsigned int UINT
Definition: ndis.h:50
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
#define NDIS_ATTRIBUTE_BUS_MASTER
Definition: ndis.h:586
#define NdisMSendResourcesAvailable(MiniportAdapterHandle)
Definition: ndis.h:5702
#define NdisDprReleaseSpinLock(_SpinLock)
Definition: ndis.h:4133
#define NDIS_STATUS_MEDIA_DISCONNECT
Definition: ndis.h:362
#define NdisInterruptLevelSensitive
Definition: ndis.h:920
#define NdisRawReadPortUchar(Port, Data)
Definition: ndis.h:4173
#define NdisAllocateSpinLock(_SpinLock)
Definition: ndis.h:4088
_In_ PVOID FunctionContext
Definition: ndis.h:637
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _Out_ PUINT SelectedMediumIndex
Definition: ndis.h:6011
#define NdisStallExecution
Definition: ndis.h:4453
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
MDL * PNDIS_BUFFER
Definition: ndis.h:343
_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
#define NdisDprAcquireSpinLock(_SpinLock)
Definition: ndis.h:4124
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
#define NdisQueryBuffer(_Buffer, _VirtualAddress, _Length)
Definition: ndis.h:3029
_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
#define NdisMInitializeWrapper(NdisWrapperHandle, SystemSpecific1, SystemSpecific2, SystemSpecific3)
Definition: ndis.h:5592
#define NdisFreeSpinLock(_SpinLock)
Definition: ndis.h:4097
* PNDIS_STATUS
Definition: ndis.h:45
#define NdisRawWritePortUshort(Port, Data)
Definition: ndis.h:4248
#define NdisMIndicateStatus(MiniportAdapterHandle, GeneralStatus, StatusBuffer, StatusBufferSize)
Definition: ndis.h:5570
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
_Out_ _At_ TimerCancelled PBOOLEAN TimerCancelled
Definition: ndis.h:2820
_In_ PVOID _In_ PVOID _In_ PVOID SystemSpecific3
Definition: ndis.h:639
#define INTERRUPT_LIMIT
Definition: ne2000.h:61
VOID EXPORT NdisMDeregisterAdapterShutdownHandler(IN NDIS_HANDLE MiniportHandle)
Definition: miniport.c:1517
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
BOOLEAN EXPORT NdisMSynchronizeWithInterrupt(IN PNDIS_MINIPORT_INTERRUPT Interrupt, IN PVOID SynchronizeFunction, IN PVOID SynchronizeContext)
Definition: miniport.c:2955
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
@ NdisMediaStateConnected
Definition: ntddndis.h:470
@ NdisMediaStateDisconnected
Definition: ntddndis.h:471
enum _NDIS_MEDIA_STATE NDIS_MEDIA_STATE
enum _NDIS_MEDIUM * PNDIS_MEDIUM
@ NdisMedium802_3
Definition: ntddndis.h:188
int NDIS_STATUS
Definition: ntddndis.h:475
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define PCI_COMMAND
Definition: pcidef.h:26
NDIS_MEDIA_STATE NTAPI MiGetMediaState(PADAPTER Adapter)
Definition: pcnet.c:1309
static VOID MiPrepareInitializationBlock(PADAPTER Adapter)
Definition: pcnet.c:518
VOID NTAPI MiniportShutdown(PVOID Context)
Definition: pcnet.c:841
static ULONG NTAPI MiEthernetCrc(UCHAR *Address)
Definition: pcnet.c:1235
static BOOLEAN NTAPI MiSyncMediaDetection(IN PVOID SynchronizeContext)
Definition: pcnet.c:616
static BOOLEAN NTAPI MiSyncStartTransmit(IN PVOID SynchronizeContext)
Definition: pcnet.c:1128
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 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 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 MiQueryCard(IN PADAPTER Adapter)
Definition: pcnet.c:228
static BOOLEAN NTAPI MiSyncStop(IN PVOID SynchronizeContext)
Definition: pcnet.c:554
NDIS_STATUS NTAPI MiSetMulticast(PADAPTER Adapter, UCHAR *Addresses, UINT AddressCount)
Definition: pcnet.c:1262
static VOID MiInitChip(PADAPTER Adapter)
Definition: pcnet.c:675
BOOLEAN NTAPI MiGetMediaDuplex(PADAPTER Adapter)
Definition: pcnet.c:1285
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
UINT NTAPI MiGetMediaSpeed(PADAPTER Adapter)
Definition: pcnet.c:1297
static VOID MiFreeSharedMemory(PADAPTER Adapter)
Definition: pcnet.c:301
#define MEDIA_DETECTION_INTERVAL
Definition: pcnet.h:156
#define NUMBER_OF_BUFFERS
Definition: pcnet.h:152
#define PCNET_TAG
Definition: pcnet.h:165
struct _ADAPTER * PADAPTER
#define LOG_NUMBER_OF_BUFFERS
Definition: pcnet.h:153
#define NUMBER_OF_PORTS
Definition: pcnethw.h:34
#define BCR7
Definition: pcnethw.h:142
#define RD_BUFF
Definition: pcnethw.h:378
#define CSR0_RINT
Definition: pcnethw.h:163
#define CSR0
Definition: pcnethw.h:63
#define TD1_ONE
Definition: pcnethw.h:401
#define BCR5_FDLSE
Definition: pcnethw.h:280
#define CSR0_INTR
Definition: pcnethw.h:160
#define CSR6
Definition: pcnethw.h:69
#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 BCR6
Definition: pcnethw.h:141
#define CSR4_APAD_XMT
Definition: pcnethw.h:195
#define CSR4_DMAPLUS
Definition: pcnethw.h:198
#define BCR7_RCVE
Definition: pcnethw.h:306
#define TD1_STP
Definition: pcnethw.h:399
#define RD_ENP
Definition: pcnethw.h:376
#define TD1_ERR
Definition: pcnethw.h:406
#define TD2_EXDEF
Definition: pcnethw.h:413
#define CSR0_IENA
Definition: pcnethw.h:159
#define BCR5
Definition: pcnethw.h:140
#define RD_ERR
Definition: pcnethw.h:382
#define CSR0_CERR
Definition: pcnethw.h:166
struct _TRANSMIT_DESCRIPTOR TRANSMIT_DESCRIPTOR
#define CSR4
Definition: pcnethw.h:67
#define BCR6_LEDOUT
Definition: pcnethw.h:301
#define BCR18
Definition: pcnethw.h:146
#define CSR2
Definition: pcnethw.h:65
#define CSR58
Definition: pcnethw.h:110
struct _RECEIVE_DESCRIPTOR RECEIVE_DESCRIPTOR
#define TD2_BUFF
Definition: pcnethw.h:415
#define RAP
Definition: pcnethw.h:48
#define CSR0_IDON
Definition: pcnethw.h:161
#define RD_OWN
Definition: pcnethw.h:383
#define CSR0_TINT
Definition: pcnethw.h:162
#define CSR0_STRT
Definition: pcnethw.h:154
#define BDP
Definition: pcnethw.h:49
struct _INITIALIZATION_BLOCK INITIALIZATION_BLOCK
#define TD1_ENP
Definition: pcnethw.h:398
#define SW_STYLE_2
Definition: pcnethw.h:59
#define RD_OFLO
Definition: pcnethw.h:380
#define CSR5
Definition: pcnethw.h:68
#define BCR18_BWRITE
Definition: pcnethw.h:325
#define TD1_MORE
Definition: pcnethw.h:402
#define TD2_LCAR
Definition: pcnethw.h:411
#define CSR0_MERR
Definition: pcnethw.h:164
#define RESET32
Definition: pcnethw.h:44
#define BCR7_XMTE
Definition: pcnethw.h:308
#define CSR0_TDMD
Definition: pcnethw.h:156
#define TD2_UFLO
Definition: pcnethw.h:414
#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 CSR3
Definition: pcnethw.h:66
#define RD_FRAM
Definition: pcnethw.h:381
#define BCR4_LEDOUT
Definition: pcnethw.h:269
#define PCI_ID
Definition: pcnethw.h:52
#define RDP
Definition: pcnethw.h:37
#define BCR5_LEDOUT
Definition: pcnethw.h:285
#define TD1_OWN
Definition: pcnethw.h:407
#define CSR0_MISS
Definition: pcnethw.h:165
#define CSR0_BABL
Definition: pcnethw.h:167
#define CSR4_TXSTRTM
Definition: pcnethw.h:186
#define BCR18_BREADE
Definition: pcnethw.h:326
#define BCR4_LNKSTE
Definition: pcnethw.h:262
#define CSR0_ERR
Definition: pcnethw.h:168
#define TD2_RTRY
Definition: pcnethw.h:410
#define BCR4
Definition: pcnethw.h:139
#define RD_CRC
Definition: pcnethw.h:379
#define TD2_LCOL
Definition: pcnethw.h:412
#define BCR6_E100
Definition: pcnethw.h:298
#define CSR15
Definition: pcnethw.h:77
#define RD_STP
Definition: pcnethw.h:377
#define BCR4_PSE
Definition: pcnethw.h:263
unsigned short USHORT
Definition: pedump.c:61
static WCHAR Address[46]
Definition: ping.c:68
#define INT
Definition: polytest.cpp:20
#define DPRINT
Definition: sndvol32.h:71
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
Definition: pcnet.h:58
PHYSICAL_ADDRESS ReceiveDescriptorRingPhys
Definition: pcnet.h:97
BOOLEAN FullDuplex
Definition: pcnet.h:69
PHYSICAL_ADDRESS TransmitDescriptorRingPhys
Definition: pcnet.h:87
NDIS_SPIN_LOCK Lock
Definition: pcnet.h:59
UINT MediaSpeed
Definition: pcnet.h:68
ULONG InitializationBlockLength
Definition: pcnet.h:80
ULONG IoBaseAddress
Definition: pcnet.h:64
ULONG InterruptVector
Definition: pcnet.h:63
ULONG CurrentReceiveDescriptorIndex
Definition: pcnet.h:71
ADAPTER_STATS Statistics
Definition: pcnet.h:108
NDIS_MINIPORT_TIMER MediaDetectionTimer
Definition: pcnet.h:70
ULONG TransmitBufferLength
Definition: pcnet.h:90
ULONG ReceiveDescriptorRingLength
Definition: pcnet.h:95
ULONG LogBufferCount
Definition: pcnet.h:106
ULONG ReceiveBufferLength
Definition: pcnet.h:100
ULONG Flags
Definition: pcnet.h:62
PRECEIVE_DESCRIPTOR ReceiveDescriptorRingVirt
Definition: pcnet.h:96
NDIS_MINIPORT_INTERRUPT InterruptObject
Definition: pcnet.h:66
PHYSICAL_ADDRESS InitializationBlockPhys
Definition: pcnet.h:82
NDIS_MEDIA_STATE MediaState
Definition: pcnet.h:67
PHYSICAL_ADDRESS ReceiveBufferPtrPhys
Definition: pcnet.h:102
ULONG CurrentTransmitStartIndex
Definition: pcnet.h:76
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
ULONG_PTR PortOffset
Definition: pcnet.h:65
PTRANSMIT_DESCRIPTOR TransmitDescriptorRingVirt
Definition: pcnet.h:86
ULONG CurrentTransmitEndIndex
Definition: pcnet.h:77
PCHAR ReceiveBufferPtrVirt
Definition: pcnet.h:101
ULONG BufferCount
Definition: pcnet.h:105
PCHAR TransmitBufferPtrVirt
Definition: pcnet.h:91
static LARGE_INTEGER Counter
Definition: clock.c:43
static COORD Position
Definition: mouse.c:34
unsigned char * PBOOLEAN
Definition: typedefs.h:53
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
char * PCHAR
Definition: typedefs.h:51
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1099
_In_ PKSYNCHRONIZE_ROUTINE _In_opt_ __drv_aliasesMem PVOID SynchronizeContext
Definition: kefuncs.h:525
unsigned char UCHAR
Definition: xmlstorage.h:181