Author: cgutman
Date: Sat Apr 11 18:00:48 2009
New Revision: 40458
URL:
http://svn.reactos.org/svn/reactos?rev=40458&view=rev
Log:
- Revert 40446 and 40447
- More research needs to be done on when exactly we should be locking
Modified:
trunk/reactos/drivers/network/ndis/ndis/miniport.c
trunk/reactos/drivers/network/ndis/ndis/protocol.c
Modified: trunk/reactos/drivers/network/ndis/ndis/miniport.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/ndis/ndis/…
==============================================================================
--- trunk/reactos/drivers/network/ndis/ndis/miniport.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/ndis/ndis/miniport.c [iso-8859-1] Sat Apr 11 18:00:48
2009
@@ -355,9 +355,11 @@
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 @@
Request,
Status);
}
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+ KeLowerIrql(OldIrql);
}
VOID NTAPI
@@ -382,7 +384,6 @@
* Status = Status of send operation
*/
{
- PLOGICAL_ADAPTER Adapter = MiniportAdapterHandle;
PADAPTER_BINDING AdapterBinding;
KIRQL OldIrql;
@@ -390,12 +391,12 @@
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 @@
IN NDIS_STATUS Status,
IN UINT BytesTransferred)
{
- PLOGICAL_ADAPTER Adapter = MiniportAdapterHandle;
PADAPTER_BINDING AdapterBinding;
KIRQL OldIrql;
@@ -424,13 +424,13 @@
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);
}
@@ -605,7 +605,7 @@
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 @@
Size,
BytesWritten,
&BytesNeeded);
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+ KeLowerIrql(OldIrql);
/* FIXME: Wait in pending case! */
@@ -634,11 +634,11 @@
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 @@
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;
-
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+ KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
+
+ KeLowerIrql(OldIrql);
if (Status != NDIS_STATUS_PENDING) {
NdisMIndicateStatus(Adapter, NDIS_STATUS_RESET_END, NULL, 0);
@@ -852,9 +854,11 @@
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 @@
}
if (Status != NDIS_STATUS_PENDING) {
+ KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
Adapter->NdisMiniportBlock.PendingRequest = NULL;
- }
-
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+ KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
+ }
+
+ KeLowerIrql(OldIrql);
return Status;
}
@@ -903,10 +909,12 @@
{
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);
}
@@ -922,10 +930,12 @@
{
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 @@
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 @@
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 @@
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;
-
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+ if (NdisStatus == NDIS_STATUS_PENDING)
+ {
+ KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
+ Adapter->NdisMiniportBlock.ResetStatus = NDIS_STATUS_PENDING;
+ KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
+ }
+
+ KeLowerIrql(OldIrql);
if (NdisStatus != NDIS_STATUS_PENDING)
MiniResetComplete(Adapter, NdisStatus, AddressingReset);
Modified: trunk/reactos/drivers/network/ndis/ndis/protocol.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/ndis/ndis/…
==============================================================================
--- trunk/reactos/drivers/network/ndis/ndis/protocol.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/ndis/ndis/protocol.c [iso-8859-1] Sat Apr 11 18:00:48
2009
@@ -204,11 +204,13 @@
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 @@
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 @@
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 @@
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 @@
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 @@
return NDIS_STATUS_SUCCESS;
}
- KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
+ KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
Status =
(*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.TransferDataHandler)(
Packet,
@@ -414,7 +418,7 @@
ByteOffset,
BytesToTransfer);
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+ KeLowerIrql(OldIrql);
return Status;
}