Author: cgutman
Date: Sat Nov 22 09:47:48 2008
New Revision: 37556
URL:
http://svn.reactos.org/svn/reactos?rev=37556&view=rev
Log:
- Don't store an invalid interrupt in the miniport block if IoConnectInterrupt fails
- Stop using MiniportBusy
- MiniQueueWorkItem can now be used to properly requeue a failed packet
- Change MiniDequeueWorkItem to dequeue the FirstPendingPacket if there is one
- Allocate the Lookahead buffer as needed
- Break apart ProSend
Modified:
branches/aicom-network-fixes/drivers/network/ndis/include/miniport.h
branches/aicom-network-fixes/drivers/network/ndis/ndis/io.c
branches/aicom-network-fixes/drivers/network/ndis/ndis/miniport.c
branches/aicom-network-fixes/drivers/network/ndis/ndis/protocol.c
Modified: branches/aicom-network-fixes/drivers/network/ndis/include/miniport.h
URL:
http://svn.reactos.org/svn/reactos/branches/aicom-network-fixes/drivers/net…
==============================================================================
--- branches/aicom-network-fixes/drivers/network/ndis/include/miniport.h [iso-8859-1]
(original)
+++ branches/aicom-network-fixes/drivers/network/ndis/include/miniport.h [iso-8859-1] Sat
Nov 22 09:47:48 2008
@@ -75,7 +75,6 @@
typedef struct _LOGICAL_ADAPTER
{
NDIS_MINIPORT_BLOCK NdisMiniportBlock; /* NDIS defined fields */
- BOOLEAN MiniportBusy; /* A MiniportXxx routine is
executing */
PNDIS_MINIPORT_WORK_ITEM WorkQueueHead; /* Head of work queue */
PNDIS_MINIPORT_WORK_ITEM WorkQueueTail; /* Tail of work queue */
LIST_ENTRY ListEntry; /* Entry on global list */
@@ -84,8 +83,6 @@
ULONG MediumHeaderSize; /* Size of medium header */
HARDWARE_ADDRESS Address; /* Hardware address of adapter
*/
ULONG AddressLength; /* Length of hardware address */
- PUCHAR LookaheadBuffer; /* Pointer to lookahead buffer
*/
- ULONG LookaheadLength; /* Length of lookahead buffer */
PMINIPORT_BUGCHECK_CONTEXT BugcheckContext; /* Adapter's shutdown handler
*/
} LOGICAL_ADAPTER, *PLOGICAL_ADAPTER;
@@ -130,12 +127,13 @@
PVOID Buffer,
PULONG BytesWritten);
-NDIS_STATUS
+VOID
FASTCALL
MiniQueueWorkItem(
PLOGICAL_ADAPTER Adapter,
NDIS_WORK_ITEM_TYPE WorkItemType,
- PVOID WorkItemContext);
+ PVOID WorkItemContext,
+ BOOLEAN Top);
NDIS_STATUS
FASTCALL
@@ -161,7 +159,9 @@
VOID
NTAPI
-MiniportWorker(IN PVOID WorkItem);
+MiniportWorker(
+ IN PDEVICE_OBJECT DeviceObject,
+ IN PVOID WorkItem);
VOID NTAPI
MiniSendComplete(
Modified: branches/aicom-network-fixes/drivers/network/ndis/ndis/io.c
URL:
http://svn.reactos.org/svn/reactos/branches/aicom-network-fixes/drivers/net…
==============================================================================
--- branches/aicom-network-fixes/drivers/network/ndis/ndis/io.c [iso-8859-1] (original)
+++ branches/aicom-network-fixes/drivers/network/ndis/ndis/io.c [iso-8859-1] Sat Nov 22
09:47:48 2008
@@ -551,6 +551,10 @@
{
NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
IoDisconnectInterrupt(Interrupt->InterruptObject);
+ Interrupt->Miniport->RegisteredInterrupts--;
+
+ if (Interrupt->Miniport->Interrupt == Interrupt)
+ Interrupt->Miniport->Interrupt = NULL;
}
@@ -780,8 +784,6 @@
Interrupt->IsrRequested = RequestIsr;
Interrupt->Miniport = &Adapter->NdisMiniportBlock;
- Adapter->NdisMiniportBlock.Interrupt = Interrupt;
-
MappedIRQ = HalGetInterruptVector(Adapter->NdisMiniportBlock.BusType,
Adapter->NdisMiniportBlock.BusNumber,
InterruptLevel, InterruptVector, &DIrql,
&Affinity);
@@ -793,8 +795,11 @@
NDIS_DbgPrint(MAX_TRACE, ("Leaving. Status (0x%X).\n", Status));
- if (NT_SUCCESS(Status))
- return NDIS_STATUS_SUCCESS;
+ if (NT_SUCCESS(Status)) {
+ Adapter->NdisMiniportBlock.Interrupt = Interrupt;
+ Adapter->NdisMiniportBlock.RegisteredInterrupts++;
+ return NDIS_STATUS_SUCCESS;
+ }
if (Status == STATUS_INSUFFICIENT_RESOURCES)
{
Modified: branches/aicom-network-fixes/drivers/network/ndis/ndis/miniport.c
URL:
http://svn.reactos.org/svn/reactos/branches/aicom-network-fixes/drivers/net…
==============================================================================
--- branches/aicom-network-fixes/drivers/network/ndis/ndis/miniport.c [iso-8859-1]
(original)
+++ branches/aicom-network-fixes/drivers/network/ndis/ndis/miniport.c [iso-8859-1] Sat Nov
22 09:47:48 2008
@@ -286,8 +286,6 @@
CurrentEntry = CurrentEntry->Flink;
}
- Adapter->MiniportBusy = FALSE;
-
KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
}
@@ -299,7 +297,6 @@
IN PNDIS_REQUEST Request,
IN NDIS_STATUS Status)
{
- PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)MiniportAdapterHandle;
PNDIS_REQUEST_MAC_BLOCK MacBlock = (PNDIS_REQUEST_MAC_BLOCK)Request->MacReserved;
KIRQL OldIrql;
@@ -312,9 +309,6 @@
Request,
Status);
}
- KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
- Adapter->MiniportBusy = FALSE;
- KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
KeLowerIrql(OldIrql);
}
@@ -332,7 +326,6 @@
* Status = Status of send operation
*/
{
- PLOGICAL_ADAPTER Adapter = MiniportAdapterHandle;
PADAPTER_BINDING AdapterBinding;
KIRQL OldIrql;
@@ -345,9 +338,6 @@
AdapterBinding->NdisOpenBlock.ProtocolBindingContext,
Packet,
Status);
- KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
- Adapter->MiniportBusy = FALSE;
- KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
KeLowerIrql(OldIrql);
}
@@ -369,7 +359,6 @@
IN NDIS_STATUS Status,
IN UINT BytesTransferred)
{
- PLOGICAL_ADAPTER Adapter = MiniportAdapterHandle;
PADAPTER_BINDING AdapterBinding;
KIRQL OldIrql;
@@ -382,9 +371,6 @@
AdapterBinding->NdisOpenBlock.ProtocolBindingContext,
Packet,
Status);
- KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
- Adapter->MiniportBusy = FALSE;
- KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
KeLowerIrql(OldIrql);
}
@@ -614,13 +600,6 @@
NDIS_STATUS Status;
KIRQL OldIrql;
- if (Adapter->MiniportBusy) {
- KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
- MiniQueueWorkItem(Adapter, NdisWorkItemResetRequested, NULL);
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
- return NDIS_STATUS_PENDING;
- }
-
NdisMIndicateStatus(Adapter, NDIS_STATUS_RESET_START, NULL, 0);
NdisMIndicateStatusComplete(Adapter);
@@ -633,10 +612,6 @@
if (Status != NDIS_STATUS_PENDING) {
NdisMIndicateStatus(Adapter, NDIS_STATUS_RESET_END, NULL, 0);
NdisMIndicateStatusComplete(Adapter);
- } else {
- KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
- Adapter->MiniportBusy = TRUE;
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
}
return Status;
@@ -662,72 +637,76 @@
}
-NDIS_STATUS
+VOID
FASTCALL
MiniQueueWorkItem(
PLOGICAL_ADAPTER Adapter,
NDIS_WORK_ITEM_TYPE WorkItemType,
- PVOID WorkItemContext)
+ PVOID WorkItemContext,
+ BOOLEAN Top)
/*
* FUNCTION: Queues a work item for execution at a later time
* ARGUMENTS:
* Adapter = Pointer to the logical adapter object to queue work item on
* WorkItemType = Type of work item to queue
* WorkItemContext = Pointer to context information for work item
- * NOTES:
- * Adapter lock must be held when called
* RETURNS:
* Status of operation
*/
{
PNDIS_MINIPORT_WORK_ITEM MiniportWorkItem;
- PNDIS_WORK_ITEM NdisWorkItem;
- PWORK_QUEUE_ITEM WorkQueueItem;
+ PIO_WORKITEM IoWorkItem;
+ KIRQL OldIrql;
NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
ASSERT(Adapter);
- ASSERT(KeGetCurrentIrql() >= DISPATCH_LEVEL);
-
- MiniportWorkItem = ExAllocatePool(NonPagedPool, sizeof(NDIS_MINIPORT_WORK_ITEM));
- if (!MiniportWorkItem)
- {
- NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
- return NDIS_STATUS_RESOURCES;
- }
-
- NdisWorkItem = ExAllocatePool(NonPagedPool, sizeof(NDIS_WORK_ITEM));
- if (!NdisWorkItem)
- {
- ExFreePool(MiniportWorkItem);
- return NDIS_STATUS_RESOURCES;
- }
-
- MiniportWorkItem->WorkItemType = WorkItemType;
- MiniportWorkItem->WorkItemContext = WorkItemContext;
-
- /* safe due to adapter lock held */
- MiniportWorkItem->Link.Next = NULL;
- if (!Adapter->WorkQueueHead)
- {
- Adapter->WorkQueueHead = MiniportWorkItem;
- Adapter->WorkQueueTail = MiniportWorkItem;
+
+ KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
+ if (Top)
+ {
+ if (WorkItemType == NdisWorkItemSend)
+ {
+ Adapter->NdisMiniportBlock.FirstPendingPacket = WorkItemContext;
+ }
+ else
+ {
+ //This should never happen
+ ASSERT(FALSE);
+ }
}
else
{
- Adapter->WorkQueueTail->Link.Next = (PSINGLE_LIST_ENTRY)MiniportWorkItem;
- Adapter->WorkQueueTail = MiniportWorkItem;
- }
-
- WorkQueueItem = (PWORK_QUEUE_ITEM)NdisWorkItem->WrapperReserved;
-
- NdisWorkItem->Context = Adapter;
-
- ExInitializeWorkItem(WorkQueueItem, MiniportWorker, NdisWorkItem);
-
- ExQueueWorkItem(WorkQueueItem, CriticalWorkQueue);
-
- return NDIS_STATUS_SUCCESS;
+ MiniportWorkItem = ExAllocatePool(NonPagedPool,
sizeof(NDIS_MINIPORT_WORK_ITEM));
+ if (!MiniportWorkItem)
+ {
+ KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
+ NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
+ return;
+ }
+
+ MiniportWorkItem->WorkItemType = WorkItemType;
+ MiniportWorkItem->WorkItemContext = WorkItemContext;
+
+ /* safe due to adapter lock held */
+ MiniportWorkItem->Link.Next = NULL;
+ if (!Adapter->WorkQueueHead)
+ {
+ Adapter->WorkQueueHead = MiniportWorkItem;
+ Adapter->WorkQueueTail = MiniportWorkItem;
+ }
+ else
+ {
+ Adapter->WorkQueueTail->Link.Next =
(PSINGLE_LIST_ENTRY)MiniportWorkItem;
+ Adapter->WorkQueueTail = MiniportWorkItem;
+ }
+ }
+
+ IoWorkItem = IoAllocateWorkItem(Adapter->NdisMiniportBlock.DeviceObject);
+ if (IoWorkItem)
+ IoQueueWorkItem(IoWorkItem, MiniportWorker, CriticalWorkQueue, IoWorkItem);
+
+ KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
}
@@ -751,26 +730,22 @@
*/
{
PNDIS_MINIPORT_WORK_ITEM MiniportWorkItem;
- PNDIS_WORK_ITEM NdisWorkItem;
- PWORK_QUEUE_ITEM WorkQueueItem;
-
+ PNDIS_PACKET Packet;
NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
- if (Adapter->MiniportBusy) {
- NDIS_DbgPrint(MID_TRACE, ("Waiting for miniport to become free.\n"));
- NdisWorkItem = ExAllocatePool(NonPagedPool, sizeof(NDIS_WORK_ITEM));
- if (!NdisWorkItem) return NDIS_STATUS_RESOURCES;
- WorkQueueItem = (PWORK_QUEUE_ITEM)NdisWorkItem->WrapperReserved;
- NdisWorkItem->Context = Adapter;
- ExInitializeWorkItem(WorkQueueItem, MiniportWorker, NdisWorkItem);
- ExQueueWorkItem(WorkQueueItem, CriticalWorkQueue);
- return NDIS_STATUS_FAILURE;
- }
-
MiniportWorkItem = Adapter->WorkQueueHead;
- if (MiniportWorkItem)
+ if ((Packet = Adapter->NdisMiniportBlock.FirstPendingPacket))
+ {
+ Adapter->NdisMiniportBlock.FirstPendingPacket = NULL;
+
+ *WorkItemType = NdisWorkItemSend;
+ *WorkItemContext = Packet;
+
+ return NDIS_STATUS_SUCCESS;
+ }
+ else if (MiniportWorkItem)
{
/* safe due to adapter lock held */
Adapter->WorkQueueHead =
(PNDIS_MINIPORT_WORK_ITEM)MiniportWorkItem->Link.Next;
@@ -783,12 +758,12 @@
ExFreePool(MiniportWorkItem);
- Adapter->MiniportBusy = TRUE;
-
return NDIS_STATUS_SUCCESS;
}
-
- return NDIS_STATUS_FAILURE;
+ else
+ {
+ return NDIS_STATUS_FAILURE;
+ }
}
@@ -808,8 +783,6 @@
NDIS_STATUS Status;
KIRQL OldIrql;
NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
-
- Adapter->NdisMiniportBlock.MediaRequest = NdisRequest;
KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
switch (NdisRequest->RequestType)
@@ -838,14 +811,29 @@
Status = NDIS_STATUS_FAILURE;
}
- if (Status == NDIS_STATUS_PENDING) {
- KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
- Adapter->MiniportBusy = TRUE;
- KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
- }
-
KeLowerIrql(OldIrql);
return Status;
+}
+
+
+/*
+ * @implemented
+ */
+#undef NdisMSetInformationComplete
+VOID
+EXPORT
+NdisMSetInformationComplete(
+ IN NDIS_HANDLE MiniportAdapterHandle,
+ IN NDIS_STATUS Status)
+{
+ PLOGICAL_ADAPTER Adapter =
+ (PLOGICAL_ADAPTER)MiniportAdapterHandle;
+ KIRQL OldIrql;
+ ASSERT(Adapter);
+ KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
+ if (Adapter->NdisMiniportBlock.SetCompleteHandler)
+ (Adapter->NdisMiniportBlock.SetCompleteHandler)(MiniportAdapterHandle, Status);
+ KeLowerIrql(OldIrql);
}
@@ -866,21 +854,21 @@
KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
if( Adapter->NdisMiniportBlock.QueryCompleteHandler )
(Adapter->NdisMiniportBlock.QueryCompleteHandler)(MiniportAdapterHandle, Status);
- KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
- Adapter->MiniportBusy = FALSE;
- KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
KeLowerIrql(OldIrql);
}
-VOID NTAPI MiniportWorker(IN PVOID WorkItem)
-{
- PNDIS_WORK_ITEM NdisWorkItem = WorkItem;
- PLOGICAL_ADAPTER Adapter = GET_LOGICAL_ADAPTER(NdisWorkItem->Context);
+VOID
+NTAPI
+MiniportWorker(IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
+{
+ PLOGICAL_ADAPTER Adapter = DeviceObject->DeviceExtension;
KIRQL OldIrql, RaiseOldIrql;
NDIS_STATUS NdisStatus;
PVOID WorkItemContext;
NDIS_WORK_ITEM_TYPE WorkItemType;
BOOLEAN AddressingReset;
+
+ IoFreeWorkItem((PIO_WORKITEM)Context);
KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
@@ -898,9 +886,7 @@
/*
* called by ProSend when protocols want to send packets to the miniport
*/
-#ifdef DBG
- MiniDisplayPacket((PNDIS_PACKET)WorkItemContext);
-#endif
+
if(Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendPacketsHandler)
{
if(Adapter->NdisMiniportBlock.Flags & NDIS_ATTRIBUTE_DESERIALIZE)
@@ -923,9 +909,7 @@
NdisStatus = NDIS_GET_PACKET_STATUS((PNDIS_PACKET)WorkItemContext);
if( NdisStatus == NDIS_STATUS_RESOURCES ) {
- KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock,
&OldIrql);
- MiniQueueWorkItem(Adapter, WorkItemType, WorkItemContext);
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock,
OldIrql);
+ MiniQueueWorkItem(Adapter, WorkItemType, WorkItemContext, TRUE);
break;
}
}
@@ -949,9 +933,7 @@
NDIS_DbgPrint(MAX_TRACE, ("back from miniport's send
handler\n"));
KeLowerIrql(RaiseOldIrql);
if( NdisStatus == NDIS_STATUS_RESOURCES ) {
- KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock,
&OldIrql);
- MiniQueueWorkItem(Adapter, WorkItemType, WorkItemContext);
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock,
OldIrql);
+ MiniQueueWorkItem(Adapter, WorkItemType, WorkItemContext, TRUE);
break;
}
}
@@ -1028,14 +1010,6 @@
break;
}
}
-
- if( NdisStatus != NDIS_STATUS_PENDING ) {
- KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
- Adapter->MiniportBusy = FALSE;
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
- }
-
- ExFreePool(WorkItem);
}
@@ -1433,15 +1407,6 @@
}
NDIS_DbgPrint(DEBUG_MINIPORT, ("CurLookaheadLength (0x%X).\n",
Adapter->NdisMiniportBlock.CurrentLookahead));
-
- if (Adapter->NdisMiniportBlock.MaximumLookahead != 0)
- {
- Adapter->LookaheadLength = Adapter->NdisMiniportBlock.MaximumLookahead +
Adapter->MediumHeaderSize;
- Adapter->LookaheadBuffer = ExAllocatePool(NonPagedPool,
Adapter->LookaheadLength);
-
- if (!Adapter->LookaheadBuffer)
- return NDIS_STATUS_RESOURCES;
- }
return STATUS_SUCCESS;
}
@@ -1721,12 +1686,6 @@
if (NdisStatus != NDIS_STATUS_SUCCESS)
{
NDIS_DbgPrint(MAX_TRACE, ("couldn't create filter (%x)\n",
NdisStatus));
- if (Adapter->LookaheadBuffer)
- {
- ExFreePool(Adapter->LookaheadBuffer);
- Adapter->LookaheadBuffer = NULL;
- }
- ExInterlockedRemoveEntryList( &Adapter->ListEntry, &AdapterListLock );
return NdisStatus;
}
@@ -1775,11 +1734,6 @@
(*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.HaltHandler)(Adapter);
- if (Adapter->LookaheadBuffer)
- {
- ExFreePool(Adapter->LookaheadBuffer);
- Adapter->LookaheadBuffer = NULL;
- }
if (Adapter->NdisMiniportBlock.AllocatedResources)
{
ExFreePool(Adapter->NdisMiniportBlock.AllocatedResources);
@@ -2183,29 +2137,6 @@
IN UINT BytesTransferred)
{
MiniTransferDataComplete(MiniportAdapterHandle, Packet, Status, BytesTransferred);
-}
-
-
-/*
- * @implemented
- */
-#undef NdisMSetInformationComplete
-VOID
-EXPORT
-NdisMSetInformationComplete(
- IN NDIS_HANDLE MiniportAdapterHandle,
- IN NDIS_STATUS Status)
-{
- PLOGICAL_ADAPTER Adapter =
- (PLOGICAL_ADAPTER)MiniportAdapterHandle;
- KIRQL OldIrql;
- ASSERT(Adapter);
- KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
- (Adapter->NdisMiniportBlock.SetCompleteHandler)(MiniportAdapterHandle, Status);
- KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
- Adapter->MiniportBusy = FALSE;
- KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
- KeLowerIrql(OldIrql);
}
Modified: branches/aicom-network-fixes/drivers/network/ndis/ndis/protocol.c
URL:
http://svn.reactos.org/svn/reactos/branches/aicom-network-fixes/drivers/net…
==============================================================================
--- branches/aicom-network-fixes/drivers/network/ndis/ndis/protocol.c [iso-8859-1]
(original)
+++ branches/aicom-network-fixes/drivers/network/ndis/ndis/protocol.c [iso-8859-1] Sat Nov
22 09:47:48 2008
@@ -20,6 +20,8 @@
LIST_ENTRY ProtocolListHead;
KSPIN_LOCK ProtocolListLock;
+#define WORKER_TEST 0
+
/*
* @implemented
@@ -68,6 +70,7 @@
UINT BufferedLength;
UINT PacketLength;
KIRQL OldIrql;
+ PUCHAR LookaheadBuffer;
NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
@@ -75,36 +78,34 @@
MiniDisplayPacket(Packet);
#endif
+ LookaheadBuffer = ExAllocatePool(NonPagedPool,
Adapter->NdisMiniportBlock.CurrentLookahead + Adapter->MediumHeaderSize);
+ if (!LookaheadBuffer)
+ return NDIS_STATUS_RESOURCES;
+
NdisQueryPacket(Packet, NULL, NULL, NULL, &PacketLength);
NDIS_DbgPrint(MAX_TRACE, ("acquiring miniport block lock\n"));
KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
{
- Adapter->NdisMiniportBlock.IndicatedPacket[KeGetCurrentProcessorNumber()] =
Packet;
- BufferedLength = CopyPacketToBuffer(Adapter->LookaheadBuffer, Packet, 0,
Adapter->NdisMiniportBlock.CurrentLookahead);
+ BufferedLength = CopyPacketToBuffer(LookaheadBuffer, Packet, 0,
Adapter->NdisMiniportBlock.CurrentLookahead);
}
KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
if (BufferedLength > Adapter->MediumHeaderSize)
{
/* XXX Change this to call SendPackets so we don't have to duplicate this wacky
logic */
- MiniIndicateData(Adapter, NULL, Adapter->LookaheadBuffer,
Adapter->MediumHeaderSize,
- &Adapter->LookaheadBuffer[Adapter->MediumHeaderSize], BufferedLength
- Adapter->MediumHeaderSize,
+ MiniIndicateData(Adapter, NULL, LookaheadBuffer, Adapter->MediumHeaderSize,
+ &LookaheadBuffer[Adapter->MediumHeaderSize], BufferedLength -
Adapter->MediumHeaderSize,
PacketLength - Adapter->MediumHeaderSize);
}
else
{
- MiniIndicateData(Adapter, NULL, Adapter->LookaheadBuffer,
Adapter->MediumHeaderSize, NULL, 0, 0);
- }
-
- NDIS_DbgPrint(MAX_TRACE, ("acquiring miniport block lock\n"));
- KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
- {
- Adapter->NdisMiniportBlock.IndicatedPacket[KeGetCurrentProcessorNumber()] =
NULL;
- }
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
-
- return STATUS_SUCCESS;
+ MiniIndicateData(Adapter, NULL, LookaheadBuffer, Adapter->MediumHeaderSize,
NULL, 0, 0);
+ }
+
+ ExFreePool(LookaheadBuffer);
+
+ return NDIS_STATUS_SUCCESS;
}
@@ -121,7 +122,6 @@
* Status of operation
*/
{
- KIRQL OldIrql;
PADAPTER_BINDING AdapterBinding;
PLOGICAL_ADAPTER Adapter;
PNDIS_REQUEST_MAC_BLOCK MacBlock =
(PNDIS_REQUEST_MAC_BLOCK)NdisRequest->MacReserved;
@@ -136,21 +136,12 @@
MacBlock->Binding = &AdapterBinding->NdisOpenBlock;
- /*
- * If the miniport is already busy, queue a workitem
- */
- NDIS_DbgPrint(MAX_TRACE, ("acquiring miniport block lock\n"));
- KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
- {
- if (Adapter->MiniportBusy) {
- MiniQueueWorkItem(Adapter, NdisWorkItemRequest, (PVOID)NdisRequest);
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
- return NDIS_STATUS_PENDING;
- }
- }
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, OldIrql);
-
+#if WORKER_TEST
+ MiniQueueWorkItem(Adapter, NdisWorkItemRequest, NdisRequest, FALSE);
+ return NDIS_STATUS_PENDING;
+#else
return MiniDoRequest(Adapter, NdisRequest);
+#endif
}
@@ -161,6 +152,74 @@
UNIMPLEMENTED
return NDIS_STATUS_FAILURE;
+}
+
+NDIS_STATUS
+proSendPacketToMiniport(PLOGICAL_ADAPTER Adapter, PNDIS_PACKET Packet)
+{
+#if WORKER_TEST
+ MiniQueueWorkItem(Adapter, NdisWorkItemSend, Packet, FALSE);
+ return NDIS_STATUS_PENDING;
+#else
+ KIRQL RaiseOldIrql;
+ NDIS_STATUS NdisStatus;
+
+ if(Adapter->NdisMiniportBlock.FirstPendingPacket) {
+ MiniQueueWorkItem(Adapter, NdisWorkItemSend, Packet, FALSE);
+ return NDIS_STATUS_PENDING;
+ }
+
+
if(Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendPacketsHandler)
+ {
+ if(Adapter->NdisMiniportBlock.Flags & NDIS_ATTRIBUTE_DESERIALIZE)
+ {
+ NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's SendPackets
handler\n"));
+
(*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendPacketsHandler)(
+ Adapter->NdisMiniportBlock.MiniportAdapterContext, &Packet, 1);
+ NdisStatus = NDIS_GET_PACKET_STATUS(Packet);
+ } else {
+ /* SendPackets is called at DISPATCH_LEVEL for all serialized miniports */
+ KeRaiseIrql(DISPATCH_LEVEL, &RaiseOldIrql);
+ {
+ NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's SendPackets
handler\n"));
+
(*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendPacketsHandler)(
+ Adapter->NdisMiniportBlock.MiniportAdapterContext, &Packet, 1);
+ }
+ KeLowerIrql(RaiseOldIrql);
+
+ NdisStatus = NDIS_GET_PACKET_STATUS(Packet);
+ if (NdisStatus == NDIS_STATUS_RESOURCES) {
+ MiniQueueWorkItem(Adapter, NdisWorkItemSend, Packet, TRUE);
+ NdisStatus = NDIS_STATUS_PENDING;
+ }
+ }
+
+ return NdisStatus;
+ } else {
+ if(Adapter->NdisMiniportBlock.Flags & NDIS_ATTRIBUTE_DESERIALIZE)
+ {
+ NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's Send
handler\n"));
+ NdisStatus =
(*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendHandler)(
+ Adapter->NdisMiniportBlock.MiniportAdapterContext, Packet,
0);
+ NDIS_DbgPrint(MAX_TRACE, ("back from miniport's send
handler\n"));
+ } else {
+ /* Send is called at DISPATCH_LEVEL for all serialized miniports */
+ KeRaiseIrql(DISPATCH_LEVEL, &RaiseOldIrql);
+ NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's Send
handler\n"));
+ NdisStatus =
(*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendHandler)(
+ Adapter->NdisMiniportBlock.MiniportAdapterContext, Packet,
0);
+ NDIS_DbgPrint(MAX_TRACE, ("back from miniport's send
handler\n"));
+ KeLowerIrql(RaiseOldIrql);
+
+ if (NdisStatus == NDIS_STATUS_RESOURCES) {
+ MiniQueueWorkItem(Adapter, NdisWorkItemSend, Packet, TRUE);
+ NdisStatus = NDIS_STATUS_PENDING;
+ }
+ }
+
+ return NdisStatus;
+ }
+#endif
}
@@ -176,15 +235,10 @@
* RETURNS:
* NDIS_STATUS_SUCCESS if the packet was successfully sent
* NDIS_STATUS_PENDING if the miniport was busy or a serialized miniport returned
NDIS_STATUS_RESOURCES
- * NOTES:
- * TODO:
- * - Break this up
- */
-{
- KIRQL SpinOldIrql, RaiseOldIrql;
+ */
+{
PADAPTER_BINDING AdapterBinding;
PLOGICAL_ADAPTER Adapter;
- NDIS_STATUS NdisStatus;
NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
@@ -210,83 +264,18 @@
* this is a loopback frame.
*/
- KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &SpinOldIrql);
-
if ((Adapter->NdisMiniportBlock.MacOptions & NDIS_MAC_OPTION_NO_LOOPBACK)
&&
MiniAdapterHasAddress(Adapter, Packet))
{
- if(Adapter->MiniportBusy) {
- MiniQueueWorkItem(Adapter, NdisWorkItemSendLoopback, Packet);
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, SpinOldIrql);
- return NDIS_STATUS_PENDING;
- }
-
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, SpinOldIrql);
-
+#if WORKER_TEST
+ MiniQueueWorkItem(Adapter, NdisWorkItemSendLoopback, Packet, FALSE);
+ return NDIS_STATUS_PENDING;
+#else
return ProIndicatePacket(Adapter, Packet);
+#endif
} else {
- if(Adapter->MiniportBusy) {
- MiniQueueWorkItem(Adapter, NdisWorkItemSend, Packet);
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, SpinOldIrql);
- return NDIS_STATUS_PENDING;
- }
-
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock, SpinOldIrql);
-
-
if(Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendPacketsHandler)
- {
- if(Adapter->NdisMiniportBlock.Flags & NDIS_ATTRIBUTE_DESERIALIZE)
- {
- NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's SendPackets
handler\n"));
-
(*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendPacketsHandler)(
- Adapter->NdisMiniportBlock.MiniportAdapterContext, &Packet, 1);
- NdisStatus = NDIS_GET_PACKET_STATUS(Packet);
- } else {
- /* SendPackets is called at DISPATCH_LEVEL for all serialized miniports
*/
- KeRaiseIrql(DISPATCH_LEVEL, &RaiseOldIrql);
- {
- NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's SendPackets
handler\n"));
-
(*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendPacketsHandler)(
- Adapter->NdisMiniportBlock.MiniportAdapterContext, &Packet,
1);
- }
- KeLowerIrql(RaiseOldIrql);
-
- NdisStatus = NDIS_GET_PACKET_STATUS(Packet);
- if( NdisStatus == NDIS_STATUS_RESOURCES ) {
- KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock,
&SpinOldIrql);
- MiniQueueWorkItem(Adapter, NdisWorkItemSend, Packet);
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock,
SpinOldIrql);
- NdisStatus = NDIS_STATUS_PENDING;
- }
- }
-
- return NdisStatus;
- } else {
- if(Adapter->NdisMiniportBlock.Flags & NDIS_ATTRIBUTE_DESERIALIZE)
- {
- NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's Send
handler\n"));
- NdisStatus =
(*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendHandler)(
- Adapter->NdisMiniportBlock.MiniportAdapterContext, Packet,
0);
- NDIS_DbgPrint(MAX_TRACE, ("back from miniport's send
handler\n"));
- } else {
- /* Send is called at DISPATCH_LEVEL for all serialized miniports */
- KeRaiseIrql(DISPATCH_LEVEL, &RaiseOldIrql);
- NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's Send
handler\n"));
- NdisStatus =
(*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendHandler)(
- Adapter->NdisMiniportBlock.MiniportAdapterContext, Packet,
0);
- NDIS_DbgPrint(MAX_TRACE, ("back from miniport's send
handler\n"));
- KeLowerIrql(RaiseOldIrql);
- if( NdisStatus == NDIS_STATUS_RESOURCES ) {
- KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock,
&SpinOldIrql);
- MiniQueueWorkItem(Adapter, NdisWorkItemSend, Packet);
- KeReleaseSpinLock(&Adapter->NdisMiniportBlock.Lock,
SpinOldIrql);
- NdisStatus = NDIS_STATUS_PENDING;
- }
- }
-
- return NdisStatus;
- }
- }
+ return proSendPacketToMiniport(Adapter, Packet);
+ }
}