- Revert 40446 and 40447
authorCameron Gutman <aicommander@gmail.com>
Sat, 11 Apr 2009 14:00:48 +0000 (14:00 +0000)
committerCameron Gutman <aicommander@gmail.com>
Sat, 11 Apr 2009 14:00:48 +0000 (14:00 +0000)
 - More research needs to be done on when exactly we should be locking

svn path=/trunk/; revision=40458

reactos/drivers/network/ndis/ndis/miniport.c
reactos/drivers/network/ndis/ndis/protocol.c

index 3f6863e..67d383e 100644 (file)
@@ -355,9 +355,11 @@ MiniRequestComplete(
 
     NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
 
-    KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
+    KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
 
+    KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
     Adapter->NdisMiniportBlock.PendingRequest = NULL;
+    KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
 
     if( MacBlock->Binding->RequestCompleteHandler ) {
         (*MacBlock->Binding->RequestCompleteHandler)(
@@ -365,7 +367,7 @@ MiniRequestComplete(
             Request,
             Status);
     }
-    KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+    KeLowerIrql(OldIrql);
 }
 
 VOID NTAPI
@@ -382,7 +384,6 @@ MiniSendComplete(
  *     Status            = Status of send operation
  */
 {
-    PLOGICAL_ADAPTER Adapter = MiniportAdapterHandle;
     PADAPTER_BINDING AdapterBinding;
     KIRQL OldIrql;
 
@@ -390,12 +391,12 @@ MiniSendComplete(
 
     AdapterBinding = (PADAPTER_BINDING)Packet->Reserved[0];
 
-    KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
+    KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
     (*AdapterBinding->ProtocolBinding->Chars.SendCompleteHandler)(
         AdapterBinding->NdisOpenBlock.ProtocolBindingContext,
         Packet,
         Status);
-    KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+    KeLowerIrql(OldIrql);
 }
 
 
@@ -416,7 +417,6 @@ MiniTransferDataComplete(
     IN  NDIS_STATUS     Status,
     IN  UINT            BytesTransferred)
 {
-    PLOGICAL_ADAPTER Adapter = MiniportAdapterHandle;
     PADAPTER_BINDING AdapterBinding;
     KIRQL OldIrql;
 
@@ -424,13 +424,13 @@ MiniTransferDataComplete(
 
     AdapterBinding = (PADAPTER_BINDING)Packet->Reserved[0];
 
-    KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
+    KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
     (*AdapterBinding->ProtocolBinding->Chars.TransferDataCompleteHandler)(
         AdapterBinding->NdisOpenBlock.ProtocolBindingContext,
         Packet,
         Status,
         BytesTransferred);
-    KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+    KeLowerIrql(OldIrql);
 }
 
 \f
@@ -605,7 +605,7 @@ MiniQueryInformation(
   NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
 
   /* call the miniport's queryinfo handler */
-  KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
+  KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
   NdisStatus = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.QueryInformationHandler)(
       Adapter->NdisMiniportBlock.MiniportAdapterContext,
       Oid,
@@ -613,7 +613,7 @@ MiniQueryInformation(
       Size,
       BytesWritten,
       &BytesNeeded);
-  KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+  KeLowerIrql(OldIrql);
 
   /* FIXME: Wait in pending case! */
 
@@ -634,11 +634,11 @@ MiniCheckForHang( PLOGICAL_ADAPTER Adapter )
    BOOLEAN Ret = FALSE;
    KIRQL OldIrql;
 
-   KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
+   KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
    if (Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.CheckForHangHandler)
        Ret = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.CheckForHangHandler)(
          Adapter->NdisMiniportBlock.MiniportAdapterContext);
-   KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+   KeLowerIrql(OldIrql);
 
    return Ret;
 }
@@ -667,14 +667,16 @@ MiniReset(
    NdisMIndicateStatus(Adapter, NDIS_STATUS_RESET_START, NULL, 0);
    NdisMIndicateStatusComplete(Adapter);
 
-   KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
+   KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
    Status = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.ResetHandler)(
             Adapter->NdisMiniportBlock.MiniportAdapterContext,
             AddressingReset);
 
+   KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
    Adapter->NdisMiniportBlock.ResetStatus = Status;
+   KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
 
-   KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+   KeLowerIrql(OldIrql);
 
    if (Status != NDIS_STATUS_PENDING) {
        NdisMIndicateStatus(Adapter, NDIS_STATUS_RESET_END, NULL, 0);
@@ -852,9 +854,11 @@ MiniDoRequest(
     KIRQL OldIrql;
     NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
 
-    KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
+    KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
 
+    KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
     Adapter->NdisMiniportBlock.PendingRequest = NdisRequest;
+    KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
 
     switch (NdisRequest->RequestType)
     {
@@ -883,10 +887,12 @@ MiniDoRequest(
     }
 
     if (Status != NDIS_STATUS_PENDING) {
+        KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
         Adapter->NdisMiniportBlock.PendingRequest = NULL;
+        KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
     }
 
-    KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+    KeLowerIrql(OldIrql);
     return Status;
 }
 
@@ -903,10 +909,12 @@ NdisMSetInformationComplete(
 {
   PLOGICAL_ADAPTER Adapter =
        (PLOGICAL_ADAPTER)MiniportAdapterHandle;
+  KIRQL OldIrql;
   ASSERT(Adapter);
-  /* This isn't a handler supplied by the miniport */
+  KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
   if (Adapter->NdisMiniportBlock.SetCompleteHandler)
      (Adapter->NdisMiniportBlock.SetCompleteHandler)(MiniportAdapterHandle, Status);
+  KeLowerIrql(OldIrql);
 }
 
 \f
@@ -922,10 +930,12 @@ NdisMQueryInformationComplete(
 {
     PLOGICAL_ADAPTER Adapter =
        (PLOGICAL_ADAPTER)MiniportAdapterHandle;
+    KIRQL OldIrql;
     ASSERT(Adapter);
-    /* This isn't a handler supplied by the miniport */
+    KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
     if( Adapter->NdisMiniportBlock.QueryCompleteHandler )
        (Adapter->NdisMiniportBlock.QueryCompleteHandler)(MiniportAdapterHandle, Status);
+    KeLowerIrql(OldIrql);
 }
 
 VOID
@@ -970,11 +980,13 @@ MiniportWorker(IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
                 else
                 {
                     /* SendPackets is called at DISPATCH_LEVEL for all serialized miniports */
-                    KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &RaiseOldIrql);
+                    KeRaiseIrql(DISPATCH_LEVEL, &RaiseOldIrql);
+                    {
                       NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's SendPackets handler\n"));
                       (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendPacketsHandler)(
                        Adapter->NdisMiniportBlock.MiniportAdapterContext, (PPNDIS_PACKET)&WorkItemContext, 1);
-                    KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, RaiseOldIrql);
+                    }
+                    KeLowerIrql(RaiseOldIrql);
 
                     NdisStatus = NDIS_GET_PACKET_STATUS((PNDIS_PACKET)WorkItemContext);
                     if( NdisStatus == NDIS_STATUS_RESOURCES ) {
@@ -996,13 +1008,13 @@ MiniportWorker(IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
                 else
                 {
                   /* Send is called at DISPATCH_LEVEL for all serialized miniports */
-                  KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &RaiseOldIrql);
+                  KeRaiseIrql(DISPATCH_LEVEL, &RaiseOldIrql);
                   NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's Send handler\n"));
                   NdisStatus = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendHandler)(
                                 Adapter->NdisMiniportBlock.MiniportAdapterContext, (PNDIS_PACKET)WorkItemContext,
                                 ((PNDIS_PACKET)WorkItemContext)->Private.Flags);
                   NDIS_DbgPrint(MAX_TRACE, ("back from miniport's send handler\n"));
-                  KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, RaiseOldIrql);
+                  KeLowerIrql(RaiseOldIrql);
                   if( NdisStatus == NDIS_STATUS_RESOURCES ) {
                       MiniQueueWorkItem(Adapter, WorkItemType, WorkItemContext, TRUE);
                       break;
@@ -1034,14 +1046,19 @@ MiniportWorker(IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
             NdisMIndicateStatus(Adapter, NDIS_STATUS_RESET_START, NULL, 0);
             NdisMIndicateStatusComplete(Adapter);
 
-            KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
+            KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
             NdisStatus = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.ResetHandler)(
                           Adapter->NdisMiniportBlock.MiniportAdapterContext,
                           &AddressingReset);
 
-            Adapter->NdisMiniportBlock.ResetStatus = NdisStatus;
+            if (NdisStatus == NDIS_STATUS_PENDING)
+            {
+                KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
+                Adapter->NdisMiniportBlock.ResetStatus = NDIS_STATUS_PENDING;
+                KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
+            }
 
-            KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+            KeLowerIrql(OldIrql);
 
             if (NdisStatus != NDIS_STATUS_PENDING)
                MiniResetComplete(Adapter, NdisStatus, AddressingReset);
index 1b59a63..34263d3 100644 (file)
@@ -204,11 +204,13 @@ proSendPacketToMiniport(PLOGICAL_ADAPTER Adapter, PNDIS_PACKET Packet)
              NdisStatus = NDIS_STATUS_PENDING;
         } else {
             /* SendPackets is called at DISPATCH_LEVEL for all serialized miniports */
-            KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &RaiseOldIrql);
+            KeRaiseIrql(DISPATCH_LEVEL, &RaiseOldIrql);
+            {
                NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's SendPackets handler\n"));
                (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendPacketsHandler)(
                 Adapter->NdisMiniportBlock.MiniportAdapterContext, &Packet, 1);
-            KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, RaiseOldIrql);
+            }
+            KeLowerIrql(RaiseOldIrql);
 
             NdisStatus = NDIS_GET_PACKET_STATUS(Packet);
             if (NdisStatus == NDIS_STATUS_RESOURCES) {
@@ -227,12 +229,12 @@ proSendPacketToMiniport(PLOGICAL_ADAPTER Adapter, PNDIS_PACKET Packet)
             NDIS_DbgPrint(MAX_TRACE, ("back from miniport's send handler\n"));
         } else {
             /* Send is called at DISPATCH_LEVEL for all serialized miniports */
-            KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &RaiseOldIrql);
+            KeRaiseIrql(DISPATCH_LEVEL, &RaiseOldIrql);
             NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's Send handler\n"));
             NdisStatus = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendHandler)(
                           Adapter->NdisMiniportBlock.MiniportAdapterContext, Packet, Packet->Private.Flags);
             NDIS_DbgPrint(MAX_TRACE, ("back from miniport's send handler\n"));
-            KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, RaiseOldIrql);
+            KeLowerIrql(RaiseOldIrql);
 
             if (NdisStatus == NDIS_STATUS_RESOURCES) {
                 MiniQueueWorkItem(Adapter, NdisWorkItemSend, Packet, TRUE);
@@ -272,6 +274,8 @@ ProSend(
   Adapter = AdapterBinding->Adapter;
 
   ASSERT(Adapter);
+
+  /* if the following is not true, KeRaiseIrql() below will break */
   ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
 
   /* XXX what is this crazy black magic? */
@@ -322,10 +326,10 @@ ProSendPackets(
        else
        {
           /* SendPackets is called at DISPATCH_LEVEL for all serialized miniports */
-          KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &RaiseOldIrql);
+          KeRaiseIrql(DISPATCH_LEVEL, &RaiseOldIrql);
           (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendPacketsHandler)(
            Adapter->NdisMiniportBlock.MiniportAdapterContext, PacketArray, NumberOfPackets);
-          KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, RaiseOldIrql);
+          KeLowerIrql(RaiseOldIrql);
           for (i = 0; i < NumberOfPackets; i++)
           {
              NdisStatus = NDIS_GET_PACKET_STATUS(PacketArray[i]);
@@ -349,15 +353,15 @@ ProSendPackets(
        else
        {
          /* Send is called at DISPATCH_LEVEL for all serialized miniports */
+         KeRaiseIrql(DISPATCH_LEVEL, &RaiseOldIrql);
          for (i = 0; i < NumberOfPackets; i++)
          {
-            KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &RaiseOldIrql);
             NdisStatus = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendHandler)(
                            Adapter->NdisMiniportBlock.MiniportAdapterContext, PacketArray[i], PacketArray[i]->Private.Flags);
-            KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, RaiseOldIrql);
             if (NdisStatus != NDIS_STATUS_PENDING)
                 MiniSendComplete(Adapter, PacketArray[i], NdisStatus);
          }
+         KeLowerIrql(RaiseOldIrql);
        }
      }
 }
@@ -404,7 +408,7 @@ ProTransferData(
         return NDIS_STATUS_SUCCESS;
     }
 
-    KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
+    KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
 
     Status = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.TransferDataHandler)(
         Packet,
@@ -414,7 +418,7 @@ ProTransferData(
         ByteOffset,
         BytesToTransfer);
 
-    KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+    KeLowerIrql(OldIrql);
 
     return Status;
 }