Amd64/misc 64bit fixes (#236)
[reactos.git] / drivers / network / ndis / ndis / io.c
index 33e84df..1775716 100644 (file)
@@ -13,7 +13,6 @@
 
 #include "ndissys.h"
 
-\f
 VOID NTAPI HandleDeferredProcessing(
     IN  PKDPC   Dpc,
     IN  PVOID   DeferredContext,
@@ -47,7 +46,6 @@ VOID NTAPI HandleDeferredProcessing(
   NDIS_DbgPrint(MAX_TRACE, ("Leaving.\n"));
 }
 
-\f
 BOOLEAN NTAPI ServiceRoutine(
     IN  PKINTERRUPT Interrupt,
     IN  PVOID       ServiceContext)
@@ -64,10 +62,16 @@ BOOLEAN NTAPI ServiceRoutine(
   BOOLEAN QueueMiniportHandleInterrupt = FALSE;
   PNDIS_MINIPORT_INTERRUPT NdisInterrupt = ServiceContext;
   PNDIS_MINIPORT_BLOCK NdisMiniportBlock = NdisInterrupt->Miniport;
+  BOOLEAN Initializing;
 
   NDIS_DbgPrint(MAX_TRACE, ("Called. Interrupt (0x%X)\n", NdisInterrupt));
 
-  if (NdisInterrupt->IsrRequested) {
+  /* Certain behavior differs if MiniportInitialize is executing when the interrupt is generated */
+  Initializing = (NdisMiniportBlock->PnPDeviceState != NdisPnPDeviceStarted);
+  NDIS_DbgPrint(MAX_TRACE, ("MiniportInitialize executing: %s\n", (Initializing ? "yes" : "no")));
+
+  /* MiniportISR is always called for interrupts during MiniportInitialize */
+  if ((Initializing) || (NdisInterrupt->IsrRequested) || (NdisInterrupt->SharedInterrupt)) {
       NDIS_DbgPrint(MAX_TRACE, ("Calling MiniportISR\n"));
       (*NdisMiniportBlock->DriverHandle->MiniportCharacteristics.ISRHandler)(
           &InterruptRecognized,
@@ -82,7 +86,8 @@ BOOLEAN NTAPI ServiceRoutine(
        InterruptRecognized = TRUE;
   }
 
-
+  /* TODO: Figure out if we should call this or not if Initializing is true. It appears
+   * that calling it fixes some NICs, but documentation is contradictory on it.  */
   if (QueueMiniportHandleInterrupt)
   {
       NDIS_DbgPrint(MAX_TRACE, ("Queuing DPC.\n"));
@@ -94,7 +99,6 @@ BOOLEAN NTAPI ServiceRoutine(
   return InterruptRecognized;
 }
 
-\f
 /*
  * @implemented
  */
@@ -109,7 +113,6 @@ NdisImmediateReadPortUchar(
   *Data = READ_PORT_UCHAR(UlongToPtr(Port)); // FIXME: What to do with WrapperConfigurationContext?
 }
 
-\f
 /*
  * @implemented
  */
@@ -124,7 +127,6 @@ NdisImmediateReadPortUlong(
   *Data = READ_PORT_ULONG(UlongToPtr(Port)); // FIXME: What to do with WrapperConfigurationContext?
 }
 
-\f
 /*
  * @implemented
  */
@@ -139,7 +141,6 @@ NdisImmediateReadPortUshort(
   *Data = READ_PORT_USHORT(UlongToPtr(Port)); // FIXME: What to do with WrapperConfigurationContext?
 }
 
-\f
 /*
  * @implemented
  */
@@ -154,7 +155,6 @@ NdisImmediateWritePortUchar(
   WRITE_PORT_UCHAR(UlongToPtr(Port), Data); // FIXME: What to do with WrapperConfigurationContext?
 }
 
-\f
 /*
  * @implemented
  */
@@ -169,7 +169,6 @@ NdisImmediateWritePortUlong(
   WRITE_PORT_ULONG(UlongToPtr(Port), Data); // FIXME: What to do with WrapperConfigurationContext?
 }
 
-\f
 /*
  * @implemented
  */
@@ -192,7 +191,7 @@ IO_ALLOCATION_ACTION NTAPI NdisSubordinateMapRegisterCallback (
 /*
  * FUNCTION: Called back during reservation of map registers
  * ARGUMENTS:
- *     DeviceObject: Device object of the deivce setting up DMA
+ *     DeviceObject: Device object of the device setting up DMA
  *     Irp: Reserved; must be ignored
  *     MapRegisterBase: Map registers assigned for transfer
  *     Context: LOGICAL_ADAPTER object of the requesting miniport
@@ -212,7 +211,8 @@ IO_ALLOCATION_ACTION NTAPI NdisSubordinateMapRegisterCallback (
     
     /* We have to hold the object open to keep our lock on the system DMA controller */
     return KeepObject;
-}\f
+}
+
 IO_ALLOCATION_ACTION NTAPI NdisBusMasterMapRegisterCallback (
     IN PDEVICE_OBJECT  DeviceObject,
     IN PIRP            Irp,
@@ -221,7 +221,7 @@ IO_ALLOCATION_ACTION NTAPI NdisBusMasterMapRegisterCallback (
 /*
  * FUNCTION: Called back during reservation of map registers
  * ARGUMENTS:
- *     DeviceObject: Device object of the deivce setting up DMA
+ *     DeviceObject: Device object of the device setting up DMA
  *     Irp: Reserved; must be ignored
  *     MapRegisterBase: Map registers assigned for transfer
  *     Context: LOGICAL_ADAPTER object of the requesting miniport
@@ -242,7 +242,8 @@ IO_ALLOCATION_ACTION NTAPI NdisBusMasterMapRegisterCallback (
 
   /* We're a bus master so we can go ahead and deallocate the object now */
   return DeallocateObjectKeepRegisters;
-}\f
+}
+
 /*
  * @implemented
  */
@@ -415,7 +416,7 @@ NdisMAllocateMapRegisters(
 
       NDIS_DbgPrint(MAX_TRACE, ("resetting event\n"));
 
-      KeResetEvent(&AllocationEvent);
+      KeClearEvent(&AllocationEvent);
     }
 
   NDIS_DbgPrint(MAX_TRACE, ("returning success\n"));
@@ -594,7 +595,7 @@ NdisMStartBufferPhysicalMapping(
  * NOTES:
  *     - Must be called at IRQL <= DISPATCH_LEVEL
  *     - The basic idea:  call IoMapTransfer() in a loop as many times as it takes
- *       in order to map all of the virtual memory to physical memoroy readable
+ *       in order to map all of the virtual memory to physical memory readable
  *       by the device
  *     - The caller supplies storage for the physical address array.
  */
@@ -635,7 +636,6 @@ NdisMStartBufferPhysicalMapping(
   *ArraySize = LoopCount;
 }
 
-\f
 /*
  * @implemented
  */
@@ -650,7 +650,7 @@ NdisMCompleteBufferPhysicalMapping(
  * ARGUMENTS:
  *     - MiniportAdapterHandle: handle originally input to MiniportInitialize
  *     - Buffer: NDIS_BUFFER to complete the mapping on
- *     - PhyscialMapRegister: the chosen map register
+ *     - PhysicalMapRegister: the chosen map register
  * NOTES:
  *     - May be called at IRQL <= DISPATCH_LEVEL
  */
@@ -673,7 +673,6 @@ NdisMCompleteBufferPhysicalMapping(
       Adapter->NdisMiniportBlock.MapRegisters[PhysicalMapRegister].WriteToDevice);
 }
 
-\f
 /*
  * @implemented
  */
@@ -693,7 +692,6 @@ NdisMDeregisterDmaChannel(
     ExFreePool(DmaBlock);
 }
 
-\f
 /*
  * @implemented
  */
@@ -715,7 +713,6 @@ NdisMDeregisterInterrupt(
         Interrupt->Miniport->Interrupt = NULL;
 }
 
-\f
 /*
  * @implemented
  */
@@ -769,7 +766,6 @@ NdisMFreeMapRegisters(
  ExFreePool(Adapter->NdisMiniportBlock.MapRegisters);
 }
 
-\f
 /*
  * @implemented
  */
@@ -822,7 +818,6 @@ NdisMMapIoSpace(
   return NDIS_STATUS_SUCCESS;
 }
 
-\f
 /*
  * @implemented
  */
@@ -840,7 +835,6 @@ NdisMReadDmaCounter(
   return AdapterObject->DmaOperations->ReadDmaCounter(AdapterObject);
 }
 
-\f
 /*
  * @implemented
  */
@@ -858,7 +852,6 @@ NdisMGetDmaAlignment(
   return AdapterObject->DmaOperations->GetDmaAlignment(AdapterObject);
 }
 
-\f
 /*
  * @implemented
  */
@@ -938,7 +931,8 @@ NdisAllocateDmaChannel(OUT PNDIS_STATUS            Status,
                                       FALSE,
                                       DmaDescription,
                                       MaximumLength);
-}\f
+}
+
 /*
  * @implemented
  */
@@ -1016,7 +1010,6 @@ NdisMRegisterInterrupt(
   return NDIS_STATUS_FAILURE;
 }
 
-\f
 /*
  * @implemented
  */
@@ -1200,7 +1193,7 @@ NdisMInitializeScatterGatherDma(
     DeviceDesc.Version = DEVICE_DESCRIPTION_VERSION;
     DeviceDesc.Master = TRUE;
     DeviceDesc.ScatterGather = TRUE;
-    DeviceDesc.Dma32BitAddresses = !Dma64BitAddresses;
+    DeviceDesc.Dma32BitAddresses = TRUE; // All callers support 32-bit addresses
     DeviceDesc.Dma64BitAddresses = Dma64BitAddresses;
     DeviceDesc.BusNumber = Adapter->NdisMiniportBlock.BusNumber;
     DeviceDesc.InterfaceType = Adapter->NdisMiniportBlock.BusType;
@@ -1264,4 +1257,3 @@ NdisFreeDmaChannel(
 
 
 /* EOF */
-