ReactOS  0.4.14-dev-552-g2fad488
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 
47 NTAPI
51 
52 static VOID
53 NTAPI
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;
65  USHORT Data;
66  UINT i = 0;
67 
68  DPRINT("Called\n");
69 
71 
72  NdisDprAcquireSpinLock(&Adapter->Lock);
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  {
86  DPRINT("error: %x\n", Data & (CSR0_MERR|CSR0_BABL|CSR0_CERR|CSR0_MISS));
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  {
103  PCHAR Buffer;
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 !=
163  Adapter->CurrentTransmitEndIndex)
164  {
166 
167  DPRINT("buffer %d flags %x flags2 %x\n",
168  Adapter->CurrentTransmitStartIndex,
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)
182  Adapter->Statistics.XmtMoreThanOneRetry++;
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)
191  Adapter->Statistics.XmtLossesOfCarrier++;
192  if (Descriptor->FLAGS2 & TD2_LCOL)
193  Adapter->Statistics.XmtLateCollisions++;
194  if (Descriptor->FLAGS2 & TD2_EXDEF)
196  if (Descriptor->FLAGS2 & TD2_UFLO)
197  Adapter->Statistics.XmtBufferUnderflows++;
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  }
210  if(Data & ~(CSR0_ERR | CSR0_IDON | CSR0_RINT | CSR0_TINT))
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 
227 static 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 
300 static 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  {
324  Adapter->TransmitDescriptorRingVirt = NULL;
325  }
326 
327  if(Adapter->ReceiveDescriptorRingVirt)
328  {
332  Adapter->ReceiveDescriptorRingVirt = NULL;
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 
352 static 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");
381  return NDIS_STATUS_RESOURCES;
382  }
383 
384  if (((ULONG_PTR)Adapter->InitializationBlockVirt & 0x00000003) != 0)
385  {
386  DPRINT1("address 0x%x not dword-aligned\n", Adapter->InitializationBlockVirt);
387  return NDIS_STATUS_RESOURCES;
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);
408  return NDIS_STATUS_RESOURCES;
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);
430  return NDIS_STATUS_RESOURCES;
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);
452  return NDIS_STATUS_RESOURCES;
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);
474  return NDIS_STATUS_RESOURCES;
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");
486  return NDIS_STATUS_RESOURCES;
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 
517 static 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 
552 static BOOLEAN
553 NTAPI
556 /*
557  * FUNCTION: Stop the adapter
558  * ARGUMENTS:
559  * SynchronizeContext: Adapter context
560  */
561 {
565  return TRUE;
566 }
567 
568 static VOID
569 NTAPI
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 
614 static BOOLEAN
615 NTAPI
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 
643 static VOID
644 NTAPI
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 {
658  PADAPTER Adapter = (PADAPTER)FunctionContext;
659 
661 
665  {
667  Adapter->MediaState == NdisMediaStateConnected ?
669  (PVOID)0, 0);
671  }
672 }
673 
674 static 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
776 static BOOLEAN
777 MiTestCard(
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++)
802  NdisRawReadPortUchar(Adapter->PortOffset + i, &address[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 
839 VOID
840 NTAPI
842 {
843  PADAPTER Adapter = Context;
844 
845  DPRINT("Stopping the chip\n");
846 
849 }
850 
851 static NDIS_STATUS
852 NTAPI
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 
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 */
966  Status = MiAllocateSharedMemory(Adapter);
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 }
1047 
1048 static VOID
1049 NTAPI
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? */
1077  NdisRawReadPortUshort(Adapter->PortOffset + RDP, &Data);
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 
1101 static NDIS_STATUS
1102 NTAPI
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 
1126 static BOOLEAN
1127 NTAPI
1130 /*
1131  * FUNCTION: Stop the adapter
1132  * ARGUMENTS:
1133  * SynchronizeContext: Adapter context
1134  */
1135 {
1139  return TRUE;
1140 }
1141 
1142 static NDIS_STATUS
1143 NTAPI
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;
1162  PTRANSMIT_DESCRIPTOR Desc;
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 
1233 static ULONG
1234 NTAPI
1236 /*
1237  * FUNCTION: Calculate Ethernet CRC32
1238  * ARGUMENTS:
1239  * Address: 6-byte ethernet address
1240  * RETURNS:
1241  * The calculated CRC32 value.
1242  */
1243 {
1244  UINT Counter, Length;
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 
1261 NTAPI
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 
1283 BOOLEAN
1284 NTAPI
1286 {
1287  ULONG Data;
1288 
1290  NdisRawReadPortUshort(Adapter->PortOffset + BDP, &Data);
1291 
1292  return (Data & BCR5_LEDOUT) != 0;
1293 }
1294 
1295 UINT
1296 NTAPI
1298 {
1299  ULONG Data;
1300 
1302  NdisRawReadPortUshort(Adapter->PortOffset + BDP, &Data);
1303 
1304  return Data & BCR6_LEDOUT ? 100 : 10;
1305 }
1306 
1308 NTAPI
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;
1321  NdisRawReadPortUshort(Adapter->PortOffset + BDP, &Data);
1323 }
1324 
1325 NTSTATUS
1326 NTAPI
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 
1359  NdisMInitializeWrapper(&WrapperHandle, DriverObject, RegistryPath, 0);
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 }
#define LOG_NUMBER_OF_BUFFERS
Definition: pcnet.h:153
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define BCR7_XMTE
Definition: pcnethw.h:308
signed char * PCHAR
Definition: retypes.h:7
#define CSR0_TINT
Definition: pcnethw.h:162
ADAPTER_STATS Statistics
Definition: pcnet.h:108
static VOID MiPrepareInitializationBlock(PADAPTER Adapter)
Definition: pcnet.c:518
#define NdisInterruptLevelSensitive
Definition: ndis.h:920
#define IN
Definition: typedefs.h:38
#define RD_BUFF
Definition: pcnethw.h:378
struct _TRANSMIT_DESCRIPTOR TRANSMIT_DESCRIPTOR
static VOID NTAPI MiniportISR(OUT PBOOLEAN InterruptRecognized, OUT PBOOLEAN QueueMiniportHandleInterrupt, IN NDIS_HANDLE MiniportAdapterContext)
Definition: pcnet.c:1050
#define TD1_ENP
Definition: pcnethw.h:398
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
ULONG XmtGoodFrames
Definition: pcnet.h:39
ULONG XmtLateCollisions
Definition: pcnet.h:43
Definition: pcnet.h:57
ULONG RcvFramingErrors
Definition: pcnet.h:53
VOID EXPORT NdisAllocateSpinLock(IN PNDIS_SPIN_LOCK SpinLock)
Definition: control.c:152
#define BCR18_BREADE
Definition: pcnethw.h:326
#define MEDIA_DETECTION_INTERVAL
Definition: pcnet.h:156
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
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS OpenErrorStatus
Definition: ndis.h:6008
#define PCI_ID
Definition: pcnethw.h:52
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define DbgPrint
Definition: loader.c:25
ULONG ReceiveDescriptorRingLength
Definition: pcnet.h:95
NDIS_STATUS EXPORT NdisAllocateMemoryWithTag(OUT PVOID *VirtualAddress, IN UINT Length, IN ULONG Tag)
Definition: memory.c:21
static ULONG NTAPI MiEthernetCrc(UCHAR *Address)
Definition: pcnet.c:1235
PTRANSMIT_DESCRIPTOR TransmitDescriptorRingVirt
Definition: pcnet.h:86
VOID EXPORT NdisMDeregisterAdapterShutdownHandler(IN NDIS_HANDLE MiniportHandle)
Definition: miniport.c:1517
PHYSICAL_ADDRESS TransmitDescriptorRingPhys
Definition: pcnet.h:87
#define CSR4
Definition: pcnethw.h:67
VOID EXPORT NdisDprReleaseSpinLock(IN PNDIS_SPIN_LOCK SpinLock)
Definition: control.c:187
#define NUMBER_OF_PORTS
Definition: pcnethw.h:34
VOID EXPORT NdisOpenConfiguration(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE ConfigurationHandle, IN NDIS_HANDLE WrapperConfigurationContext)
Definition: config.c:197
MDL * PNDIS_BUFFER
Definition: ndis.h:343
#define TD1_STP
Definition: pcnethw.h:399
#define ASSERT_IRQL_EQUAL(x)
Definition: debug.h:43
#define RESET32
Definition: pcnethw.h:44
NDIS_STATUS EXPORT NdisMRegisterIoPortRange(OUT PVOID *PortOffset, IN NDIS_HANDLE MiniportAdapterHandle, IN UINT InitialPort, IN UINT NumberOfPorts)
Definition: io.c:1018
#define NdisMEthIndicateReceiveComplete(MiniportAdapterHandle)
Definition: ndis.h:5482
static COORD Position
Definition: mouse.c:34
unsigned char * PUCHAR
Definition: retypes.h:3
#define BCR6
Definition: pcnethw.h:141
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
enum _NDIS_MEDIA_STATE NDIS_MEDIA_STATE
LONG NTSTATUS
Definition: precomp.h:26
#define INT
Definition: polytest.cpp:20
* PNDIS_STATUS
Definition: ndis.h:45
#define CSR1
Definition: pcnethw.h:64
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
ULONG TransmitBufferLength
Definition: pcnet.h:90
_In_ PVOID _In_ PVOID _In_ PVOID SystemSpecific3
Definition: ndis.h:637
static BOOLEAN NTAPI MiSyncStartTransmit(IN PVOID SynchronizeContext)
Definition: pcnet.c:1128
#define TD1_OWN
Definition: pcnethw.h:407
PRECEIVE_DESCRIPTOR ReceiveDescriptorRingVirt
Definition: pcnet.h:96
#define CSR4_APAD_XMT
Definition: pcnethw.h:195
_Out_ _At_ TimerCancelled PBOOLEAN TimerCancelled
Definition: ndis.h:2820
#define TD1_ONE
Definition: pcnethw.h:401
#define BCR5_PSE
Definition: pcnethw.h:279
#define BCR6_E100
Definition: pcnethw.h:298
#define TD1_ERR
Definition: pcnethw.h:406
#define BCR5_FDLSE
Definition: pcnethw.h:280
#define RAP
Definition: pcnethw.h:48
ULONG RcvBufferErrors
Definition: pcnet.h:50
PCHAR ReceiveBufferPtrVirt
Definition: pcnet.h:101
#define RD_FRAM
Definition: pcnethw.h:381
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _Out_ PUINT SelectedMediumIndex
Definition: ndis.h:6008
#define PCI_BMEN
Definition: pci.h:51
ULONG BufferCount
Definition: pcnet.h:105
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _Out_ PUINT _In_ UINT MediumArraySize
Definition: ndis.h:6013
#define NDIS_STATUS_UNSUPPORTED_MEDIA
Definition: ndis.h:490
struct _ADAPTER * PADAPTER
ULONG CurrentTransmitEndIndex
Definition: pcnet.h:77
#define BCR7
Definition: pcnethw.h:142
UINT MediaSpeed
Definition: pcnet.h:68
#define NdisRawReadPortUshort(Port, Data)
Definition: ndis.h:4191
#define PCNET_TAG
Definition: pcnet.h:165
ULONG RcvGoodFrames
Definition: pcnet.h:49
#define CSR0
Definition: pcnethw.h:63
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _In_ NDIS_HANDLE WrapperConfigurationContext
Definition: ndis.h:3944
static BOOLEAN NTAPI MiSyncMediaDetection(IN PVOID SynchronizeContext)
Definition: pcnet.c:616
#define BCR4_PSE
Definition: pcnethw.h:263
ULONG_PTR PortOffset
Definition: pcnet.h:65
NDIS_STATUS NTAPI MiSetMulticast(PADAPTER Adapter, UCHAR *Addresses, UINT AddressCount)
Definition: pcnet.c:1262
#define CSR0_IENA
Definition: pcnethw.h:159
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
NDIS_MINIPORT_TIMER MediaDetectionTimer
Definition: pcnet.h:70
#define BCR4
Definition: pcnethw.h:139
int NDIS_STATUS
Definition: ntddndis.h:471
uint32_t ULONG_PTR
Definition: typedefs.h:63
ULONG XmtRetryErrors
Definition: pcnet.h:40
_In_ PVOID FunctionContext
Definition: ndis.h:637
#define BCR6_LEDOUT
Definition: pcnethw.h:301
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
#define BCR2
Definition: pcnethw.h:138
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define CSR58
Definition: pcnethw.h:110
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 BCR7_RCVE
Definition: pcnethw.h:306
VOID EXPORT NdisDprAcquireSpinLock(IN PNDIS_SPIN_LOCK SpinLock)
Definition: control.c:169
struct _RECEIVE_DESCRIPTOR RECEIVE_DESCRIPTOR
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
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
ULONG LogBufferCount
Definition: pcnet.h:106
#define NdisRawWritePortUshort(Port, Data)
Definition: ndis.h:4248
static NDIS_STATUS MiAllocateSharedMemory(PADAPTER Adapter)
Definition: pcnet.c:353
#define CSR0_TDMD
Definition: pcnethw.h:156
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
#define BCR7_PSE
Definition: pcnethw.h:311
PHYSICAL_ADDRESS ReceiveBufferPtrPhys
Definition: pcnet.h:102
#define CSR15
Definition: pcnethw.h:77
#define PCI_IOBAR
Definition: pci.h:40
#define NDIS_DMA_32BITS
Definition: ndis.h:881
PHYSICAL_ADDRESS TransmitBufferPtrPhys
Definition: pcnet.h:92
unsigned char BOOLEAN
#define PCI_ILR
Definition: pci.h:43
#define CSR0_BABL
Definition: pcnethw.h:167
#define CSR2
Definition: pcnethw.h:65
smooth NULL
Definition: ftsmooth.c:416
#define RD_OFLO
Definition: pcnethw.h:380
static WCHAR Address[46]
Definition: ping.c:68
VOID EXPORT NdisFreeSpinLock(IN PNDIS_SPIN_LOCK SpinLock)
Definition: control.c:204
VOID EXPORT NdisMFreeMapRegisters(IN NDIS_HANDLE MiniportAdapterHandle)
Definition: io.c:721
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
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
#define TD2_UFLO
Definition: pcnethw.h:414
#define BCR5
Definition: pcnethw.h:140
#define CSR5
Definition: pcnethw.h:68
NDIS_SPIN_LOCK Lock
Definition: pcnet.h:59
ULONG InitializationBlockLength
Definition: pcnet.h:80
NDIS_MINIPORT_INTERRUPT InterruptObject
Definition: pcnet.h:66
VOID EXPORT NdisMIndicateStatusComplete(IN NDIS_HANDLE MiniportAdapterHandle)
Definition: miniport.c:1580
VOID EXPORT NdisCloseConfiguration(IN NDIS_HANDLE ConfigurationHandle)
Definition: config.c:136
#define CSR6
Definition: pcnethw.h:69
static BOOLEAN NTAPI MiSyncStop(IN PVOID SynchronizeContext)
Definition: pcnet.c:554
#define RD_CRC
Definition: pcnethw.h:379
NDIS_STATUS EXPORT NdisMRegisterInterrupt(OUT PNDIS_MINIPORT_INTERRUPT Interrupt, IN NDIS_HANDLE MiniportAdapterHandle, IN UINT InterruptVector, IN UINT InterruptLevel, IN BOOLEAN RequestIsr, IN BOOLEAN SharedInterrupt, IN NDIS_INTERRUPT_MODE InterruptMode)
Definition: io.c:941
#define CSR0_MERR
Definition: pcnethw.h:164
#define NDIS_STATUS_MEDIA_CONNECT
Definition: ndis.h:361
#define RD_OWN
Definition: pcnethw.h:383
#define RD_STP
Definition: pcnethw.h:377
#define BCR6_PSE
Definition: pcnethw.h:295
#define CSR4_DMAPLUS
Definition: pcnethw.h:198
VOID EXPORT NdisTerminateWrapper(IN NDIS_HANDLE NdisWrapperHandle, IN PVOID SystemSpecific)
Definition: miniport.c:3012
#define NDIS_ATTRIBUTE_BUS_MASTER
Definition: ndis.h:586
BOOLEAN NTAPI MiGetMediaDuplex(PADAPTER Adapter)
Definition: pcnet.c:1285
#define NdisMEthIndicateReceive(MiniportAdapterHandle, MiniportReceiveContext, HeaderBuffer, HeaderBufferSize, LookaheadBuffer, LookaheadBufferSize, PacketSize)
Definition: ndis.h:5458
#define CSR3
Definition: pcnethw.h:66
static VOID MiFreeSharedMemory(PADAPTER Adapter)
Definition: pcnet.c:301
#define CSR0_STOP
Definition: pcnethw.h:155
ULONG XmtCollisions
Definition: pcnet.h:42
ULONG XmtMoreThanOneRetry
Definition: pcnet.h:48
static NDIS_STATUS MiQueryCard(IN PADAPTER Adapter)
Definition: pcnet.c:228
ULONG XmtLossesOfCarrier
Definition: pcnet.h:41
static const UCHAR Index[8]
Definition: usbohci.c:18
GLuint address
Definition: glext.h:9393
#define CSR0_RINT
Definition: pcnethw.h:163
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ULONG RcvCrcErrors
Definition: pcnet.h:51
#define NDIS_STATUS_ADAPTER_NOT_FOUND
Definition: ndis.h:470
#define BCR18
Definition: pcnethw.h:146
NDIS_MEDIA_STATE NTAPI MiGetMediaState(PADAPTER Adapter)
Definition: pcnet.c:1309
#define TD2_LCOL
Definition: pcnethw.h:412
ULONG CurrentTransmitStartIndex
Definition: pcnet.h:76
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define PCI_PCIID
Definition: pci.h:29
NDIS_HANDLE MiniportAdapterHandle
Definition: pcnet.h:61
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
static VOID NTAPI MiniportHalt(IN NDIS_HANDLE MiniportAdapterContext)
Definition: pcnet.c:570
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1061
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE ConfigurationHandle
Definition: ndis.h:3944
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID EXPORT NdisReadNetworkAddress(OUT PNDIS_STATUS Status, OUT PVOID *NetworkAddress, OUT PUINT NetworkAddressLength, IN NDIS_HANDLE ConfigurationHandle)
Definition: config.c:740
char * PBOOLEAN
Definition: retypes.h:11
ULONG TransmitDescriptorRingLength
Definition: pcnet.h:85
static VOID NTAPI MiniportMediaDetectionTimer(IN PVOID SystemSpecific1, IN PVOID FunctionContext, IN PVOID SystemSpecific2, IN PVOID SystemSpecific3)
Definition: pcnet.c:645
NTSTATUS NTAPI DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
Definition: pcnet.c:1327
enum _NDIS_MEDIUM * PNDIS_MEDIUM
ULONG LowPart
Definition: typedefs.h:104
_In_ PVOID _In_ PVOID SystemSpecific2
Definition: ndis.h:637
ULONG CurrentReceiveDescriptorIndex
Definition: pcnet.h:71
#define CSR0_INTR
Definition: pcnethw.h:160
static NDIS_STATUS NTAPI MiniportSend(IN NDIS_HANDLE MiniportAdapterContext, IN PNDIS_PACKET Packet, IN UINT Flags)
Definition: pcnet.c:1144
#define NUMBER_OF_BUFFERS
Definition: pcnet.h:152
ULONG ReceiveBufferLength
Definition: pcnet.h:100
#define SW_STYLE_2
Definition: pcnethw.h:59
PHYSICAL_ADDRESS ReceiveDescriptorRingPhys
Definition: pcnet.h:97
struct _INITIALIZATION_BLOCK INITIALIZATION_BLOCK
#define TD2_RTRY
Definition: pcnethw.h:410
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define TD2_EXDEF
Definition: pcnethw.h:413
#define CSR0_ERR
Definition: pcnethw.h:168
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1061
Status
Definition: gdiplustypes.h:24
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:232
static VOID NTAPI MiniportHandleInterrupt(IN NDIS_HANDLE MiniportAdapterContext)
Definition: pcnet.c:54
#define PCI_IOEN
Definition: pci.h:49
#define INTERRUPT_LIMIT
Definition: ne2000.h:61
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define RESET16
Definition: pcnethw.h:40
#define RESET_IN_PROGRESS
Definition: pcnet.h:159
static VOID MiInitChip(PADAPTER Adapter)
Definition: pcnet.c:675
_In_ PKSYNCHRONIZE_ROUTINE _In_opt_ __drv_aliasesMem PVOID SynchronizeContext
Definition: kefuncs.h:549
ULONG XmtBufferUnderflows
Definition: pcnet.h:45
ULONG EXPORT NdisReadPciSlotInformation(IN NDIS_HANDLE NdisAdapterHandle, IN ULONG SlotNumber, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length)
Definition: hardware.c:180
ULONG XmtBufferErrors
Definition: pcnet.h:46
BOOLEAN EXPORT NdisMSynchronizeWithInterrupt(IN PNDIS_MINIPORT_INTERRUPT Interrupt, IN PVOID SynchronizeFunction, IN PVOID SynchronizeContext)
Definition: miniport.c:2955
PINITIALIZATION_BLOCK InitializationBlockVirt
Definition: pcnet.h:81
#define CSR0_CERR
Definition: pcnethw.h:166
ULONG RcvOverflowErrors
Definition: pcnet.h:52
unsigned short USHORT
Definition: pedump.c:61
VOID EXPORT NdisMSendResourcesAvailable(IN NDIS_HANDLE MiniportAdapterHandle)
Definition: miniport.c:2831
ULONG Flags
Definition: pcnet.h:62
#define TD2_BUFF
Definition: pcnethw.h:415
#define PCI_COMMAND
Definition: pcidef.h:26
ULONG XmtExcessiveDeferrals
Definition: pcnet.h:44
#define CSR0_IDON
Definition: pcnethw.h:161
unsigned int UINT
Definition: ndis.h:50
#define TD1_MORE
Definition: pcnethw.h:402
VOID EXPORT NdisMDeregisterIoPortRange(IN NDIS_HANDLE MiniportAdapterHandle, IN UINT InitialPort, IN UINT NumberOfPorts, IN PVOID PortOffset)
Definition: io.c:1093
#define RDP
Definition: pcnethw.h:37
static NDIS_STATUS NTAPI MiniportReset(OUT PBOOLEAN AddressingReset, IN NDIS_HANDLE MiniportAdapterContext)
Definition: pcnet.c:1103
#define DPRINT1
Definition: precomp.h:8
UINT NTAPI MiGetMediaSpeed(PADAPTER Adapter)
Definition: pcnet.c:1297
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
PHYSICAL_ADDRESS InitializationBlockPhys
Definition: pcnet.h:82
#define NdisZeroMemory(Destination, Length)
Definition: ndis.h:3926
static LARGE_INTEGER Counter
Definition: clock.c:43
#define BCR5_LEDOUT
Definition: pcnethw.h:285
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:953
#define BCR18_BWRITE
Definition: pcnethw.h:325
#define OUT
Definition: typedefs.h:39
#define CSR4_TXSTRTM
Definition: pcnethw.h:186
struct tagContext Context
Definition: acpixf.h:1030
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
unsigned int ULONG
Definition: retypes.h:1
VOID EXPORT NdisMRegisterAdapterShutdownHandler(IN NDIS_HANDLE MiniportHandle, IN PVOID ShutdownContext, IN ADAPTER_SHUTDOWN_HANDLER ShutdownHandler)
Definition: miniport.c:1694
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define RD_ERR
Definition: pcnethw.h:382
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define NdisMInitializeWrapper(NdisWrapperHandle, SystemSpecific1, SystemSpecific2, SystemSpecific3)
Definition: ndis.h:5592
VOID EXPORT NdisMSetPeriodicTimer(IN PNDIS_MINIPORT_TIMER Timer, IN UINT MillisecondsPeriod)
Definition: time.c:226
#define BCR2_LEDPE
Definition: pcnethw.h:252
#define CSR0_STRT
Definition: pcnethw.h:154
BOOLEAN FullDuplex
Definition: pcnet.h:69
ULONG IoBaseAddress
Definition: pcnet.h:64
#define BCR4_LNKSTE
Definition: pcnethw.h:262
VOID EXPORT NdisMCancelTimer(IN PNDIS_MINIPORT_TIMER Timer, OUT PBOOLEAN TimerCancelled)
Definition: time.c:131
#define NdisStallExecution
Definition: ndis.h:4453
#define NdisRawReadPortUchar(Port, Data)
Definition: ndis.h:4173
ULONG FLAGS
Definition: mapi.h:36
ULONG XmtOneRetry
Definition: pcnet.h:47
NDIS_STATUS EXPORT NdisMRegisterMiniport(IN NDIS_HANDLE NdisWrapperHandle, IN PNDIS_MINIPORT_CHARACTERISTICS MiniportCharacteristics, IN UINT CharacteristicsLength)
Definition: miniport.c:2637
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define CSR0_INIT
Definition: pcnethw.h:153
ULONG EXPORT NdisWritePciSlotInformation(IN NDIS_HANDLE NdisAdapterHandle, IN ULONG SlotNumber, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length)
Definition: hardware.c:199
VOID NTAPI MiniportShutdown(PVOID Context)
Definition: pcnet.c:841
NDIS_MEDIA_STATE MediaState
Definition: pcnet.h:67
#define BDP
Definition: pcnethw.h:49
#define RD_ENP
Definition: pcnethw.h:376
#define CSR0_MISS
Definition: pcnethw.h:165
VOID EXPORT NdisMDeregisterInterrupt(IN PNDIS_MINIPORT_INTERRUPT Interrupt)
Definition: io.c:700
PCHAR TransmitBufferPtrVirt
Definition: pcnet.h:91
VOID EXPORT NdisMIndicateStatus(IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_STATUS GeneralStatus, IN PVOID StatusBuffer, IN UINT StatusBufferSize)
Definition: miniport.c:1565
#define NDIS_STATUS_MEDIA_DISCONNECT
Definition: ndis.h:362
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465
VOID EXPORT NdisFreeMemory(IN PVOID VirtualAddress, IN UINT Length, IN UINT MemoryFlags)
Definition: memory.c:110
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
unsigned int * PUINT
Definition: ndis.h:50
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:51
LONGLONG QuadPart
Definition: typedefs.h:112
#define TD2_LCAR
Definition: pcnethw.h:411
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966
#define BCR4_LEDOUT
Definition: pcnethw.h:269