2011-05-14 18:09:00 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Universal Serial Bus Bulk Storage Driver
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: drivers/usb/usbstor/queue.c
|
|
|
|
* PURPOSE: USB block storage device driver.
|
|
|
|
* PROGRAMMERS:
|
|
|
|
* James Tabor
|
|
|
|
* Michael Martin (michael.martin@reactos.org)
|
|
|
|
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "usbstor.h"
|
|
|
|
|
|
|
|
VOID
|
|
|
|
USBSTOR_QueueInitialize(
|
|
|
|
PFDO_DEVICE_EXTENSION FDODeviceExtension)
|
|
|
|
{
|
2011-05-15 14:59:16 +00:00
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
ASSERT(FDODeviceExtension->Common.IsFDO);
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// initialize queue lock
|
|
|
|
//
|
|
|
|
KeInitializeSpinLock(&FDODeviceExtension->IrpListLock);
|
|
|
|
|
|
|
|
//
|
|
|
|
// initialize irp list head
|
|
|
|
//
|
|
|
|
InitializeListHead(&FDODeviceExtension->IrpListHead);
|
2012-01-31 15:59:59 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// initialize event
|
|
|
|
//
|
|
|
|
KeInitializeEvent(&FDODeviceExtension->NoPendingRequests, NotificationEvent, TRUE);
|
2011-05-14 18:09:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
USBSTOR_CancelIo(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get FDO device extension
|
|
|
|
//
|
|
|
|
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
|
|
|
|
ASSERT(FDODeviceExtension->Common.IsFDO);
|
|
|
|
|
2012-01-24 04:39:09 +00:00
|
|
|
//
|
|
|
|
// this IRP isn't in our list here
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// now release the cancel lock
|
|
|
|
//
|
|
|
|
IoReleaseCancelSpinLock(Irp->CancelIrql);
|
|
|
|
|
|
|
|
//
|
|
|
|
// set cancel status
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Status = STATUS_CANCELLED;
|
|
|
|
|
|
|
|
//
|
|
|
|
// now cancel the irp
|
|
|
|
//
|
2012-01-24 23:04:31 +00:00
|
|
|
USBSTOR_QueueTerminateRequest(DeviceObject, Irp);
|
2012-01-24 04:39:09 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2012-01-24 23:04:31 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// start the next one
|
|
|
|
//
|
|
|
|
USBSTOR_QueueNextRequest(DeviceObject);
|
2012-01-24 04:39:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
USBSTOR_Cancel(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get FDO device extension
|
|
|
|
//
|
|
|
|
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
|
|
|
|
ASSERT(FDODeviceExtension->Common.IsFDO);
|
|
|
|
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
|
|
|
// acquire irp list lock
|
|
|
|
//
|
|
|
|
KeAcquireSpinLockAtDpcLevel(&FDODeviceExtension->IrpListLock);
|
|
|
|
|
|
|
|
//
|
|
|
|
// remove the irp from the list
|
|
|
|
//
|
|
|
|
RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
|
|
|
|
|
|
|
|
//
|
|
|
|
// release irp list lock
|
|
|
|
//
|
2011-06-03 05:38:27 +00:00
|
|
|
KeReleaseSpinLockFromDpcLevel(&FDODeviceExtension->IrpListLock);
|
|
|
|
|
|
|
|
//
|
|
|
|
// now release the cancel lock
|
|
|
|
//
|
|
|
|
IoReleaseCancelSpinLock(Irp->CancelIrql);
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// set cancel status
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Status = STATUS_CANCELLED;
|
|
|
|
|
|
|
|
//
|
|
|
|
// now cancel the irp
|
|
|
|
//
|
2012-01-24 23:04:31 +00:00
|
|
|
USBSTOR_QueueTerminateRequest(DeviceObject, Irp);
|
2011-05-14 18:09:00 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2012-01-24 23:04:31 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// start the next one
|
|
|
|
//
|
|
|
|
USBSTOR_QueueNextRequest(DeviceObject);
|
2011-05-14 18:09:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
USBSTOR_QueueAddIrp(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
PDRIVER_CANCEL OldDriverCancel;
|
|
|
|
KIRQL OldLevel;
|
|
|
|
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
|
|
|
BOOLEAN IrpListFreeze;
|
2011-05-15 12:47:54 +00:00
|
|
|
BOOLEAN SrbProcessing;
|
2012-01-25 01:46:35 +00:00
|
|
|
PIO_STACK_LOCATION IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
PSCSI_REQUEST_BLOCK Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1;
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
// get FDO device extension
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
// sanity check
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
ASSERT(FDODeviceExtension->Common.IsFDO);
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// mark irp pending
|
|
|
|
//
|
|
|
|
IoMarkIrpPending(Irp);
|
|
|
|
|
|
|
|
//
|
|
|
|
// acquire lock
|
|
|
|
//
|
|
|
|
KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel);
|
|
|
|
|
|
|
|
//
|
2011-05-15 12:47:54 +00:00
|
|
|
// check if there are irp pending
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
2011-05-15 12:47:54 +00:00
|
|
|
SrbProcessing = FDODeviceExtension->IrpPendingCount != 0;
|
|
|
|
|
|
|
|
if (SrbProcessing)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// add irp to queue
|
|
|
|
//
|
|
|
|
InsertTailList(&FDODeviceExtension->IrpListHead, &Irp->Tail.Overlay.ListEntry);
|
2012-01-31 15:33:32 +00:00
|
|
|
}
|
2011-05-15 12:47:54 +00:00
|
|
|
|
2012-01-31 15:33:32 +00:00
|
|
|
//
|
|
|
|
// increment pending count
|
|
|
|
//
|
|
|
|
FDODeviceExtension->IrpPendingCount++;
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// clear the no requests pending event
|
|
|
|
//
|
|
|
|
KeClearEvent(&FDODeviceExtension->NoPendingRequests);
|
2011-05-14 18:09:00 +00:00
|
|
|
|
2011-06-03 05:38:27 +00:00
|
|
|
//
|
|
|
|
// check if queue is freezed
|
|
|
|
//
|
|
|
|
IrpListFreeze = FDODeviceExtension->IrpListFreeze;
|
|
|
|
|
|
|
|
//
|
|
|
|
// release list lock
|
|
|
|
//
|
|
|
|
KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// synchronize with cancellations by holding the cancel lock
|
|
|
|
//
|
|
|
|
IoAcquireCancelSpinLock(&Irp->CancelIrql);
|
|
|
|
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
|
|
|
// now set the driver cancel routine
|
|
|
|
//
|
2012-01-24 04:39:09 +00:00
|
|
|
if (SrbProcessing)
|
|
|
|
{
|
2012-01-25 01:46:35 +00:00
|
|
|
ASSERT(FDODeviceExtension->ActiveSrb != NULL);
|
|
|
|
|
2012-01-24 04:39:09 +00:00
|
|
|
OldDriverCancel = IoSetCancelRoutine(Irp, USBSTOR_Cancel);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-25 01:46:35 +00:00
|
|
|
ASSERT(FDODeviceExtension->ActiveSrb == NULL);
|
|
|
|
|
|
|
|
FDODeviceExtension->ActiveSrb = Request;
|
2012-01-24 04:39:09 +00:00
|
|
|
OldDriverCancel = IoSetCancelRoutine(Irp, USBSTOR_CancelIo);
|
|
|
|
}
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// check if the irp has already been cancelled
|
|
|
|
//
|
|
|
|
if (Irp->Cancel && OldDriverCancel == NULL)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// cancel irp
|
|
|
|
//
|
2012-01-24 04:39:09 +00:00
|
|
|
Irp->CancelRoutine(DeviceObject, Irp);
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// irp was cancelled
|
|
|
|
//
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2011-06-03 05:38:27 +00:00
|
|
|
// release the cancel lock
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
2011-06-03 05:38:27 +00:00
|
|
|
IoReleaseCancelSpinLock(Irp->CancelIrql);
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// if list is freezed, dont start this packet
|
|
|
|
//
|
2011-05-15 17:57:02 +00:00
|
|
|
DPRINT("IrpListFreeze: %lu IrpPendingCount %lu\n", IrpListFreeze, FDODeviceExtension->IrpPendingCount);
|
2011-05-15 12:47:54 +00:00
|
|
|
|
|
|
|
return (IrpListFreeze || SrbProcessing);
|
2011-05-14 18:09:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PIRP
|
|
|
|
USBSTOR_RemoveIrp(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject)
|
|
|
|
{
|
|
|
|
KIRQL OldLevel;
|
|
|
|
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
PIRP Irp = NULL;
|
|
|
|
|
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
// get FDO device extension
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
ASSERT(FDODeviceExtension->Common.IsFDO);
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// acquire lock
|
|
|
|
//
|
|
|
|
KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// check if list is empty
|
|
|
|
//
|
|
|
|
if (!IsListEmpty(&FDODeviceExtension->IrpListHead))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// remove entry
|
|
|
|
//
|
|
|
|
Entry = RemoveHeadList(&FDODeviceExtension->IrpListHead);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get offset to start of irp
|
|
|
|
//
|
|
|
|
Irp = (PIRP)CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// release list lock
|
|
|
|
//
|
|
|
|
KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// return result
|
|
|
|
//
|
|
|
|
return Irp;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
2012-01-31 15:33:32 +00:00
|
|
|
USBSTOR_QueueWaitForPendingRequests(
|
2011-05-14 18:09:00 +00:00
|
|
|
IN PDEVICE_OBJECT DeviceObject)
|
|
|
|
{
|
|
|
|
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
|
|
|
|
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
// get FDO device extension
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
2012-01-31 15:33:32 +00:00
|
|
|
// perform the wait
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
2012-01-31 15:33:32 +00:00
|
|
|
KeWaitForSingleObject(&FDODeviceExtension->NoPendingRequests,
|
|
|
|
Executive,
|
|
|
|
KernelMode,
|
|
|
|
FALSE,
|
|
|
|
NULL);
|
2011-05-14 18:09:00 +00:00
|
|
|
}
|
|
|
|
|
2011-05-15 14:59:16 +00:00
|
|
|
VOID
|
|
|
|
USBSTOR_QueueTerminateRequest(
|
|
|
|
IN PDEVICE_OBJECT FDODeviceObject,
|
2012-01-24 23:04:31 +00:00
|
|
|
IN PIRP Irp)
|
2011-05-15 14:59:16 +00:00
|
|
|
{
|
|
|
|
KIRQL OldLevel;
|
|
|
|
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
2012-01-24 23:04:31 +00:00
|
|
|
PIO_STACK_LOCATION IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
PSCSI_REQUEST_BLOCK Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1;
|
2011-05-15 14:59:16 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get FDO device extension
|
|
|
|
//
|
|
|
|
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)FDODeviceObject->DeviceExtension;
|
|
|
|
|
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
ASSERT(FDODeviceExtension->Common.IsFDO);
|
|
|
|
|
|
|
|
//
|
|
|
|
// acquire lock
|
|
|
|
//
|
|
|
|
KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// decrement pending irp count
|
|
|
|
//
|
|
|
|
FDODeviceExtension->IrpPendingCount--;
|
|
|
|
|
2012-01-24 23:04:31 +00:00
|
|
|
//
|
|
|
|
// check if this was our current active SRB
|
|
|
|
//
|
|
|
|
if (FDODeviceExtension->ActiveSrb == Request)
|
2011-05-15 14:59:16 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// indicate processing is completed
|
|
|
|
//
|
2012-01-24 23:04:31 +00:00
|
|
|
FDODeviceExtension->ActiveSrb = NULL;
|
2011-05-15 14:59:16 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 15:33:32 +00:00
|
|
|
//
|
|
|
|
// Set the event if nothing else is pending
|
|
|
|
//
|
|
|
|
if (FDODeviceExtension->IrpPendingCount == 0 &&
|
|
|
|
FDODeviceExtension->ActiveSrb == NULL)
|
|
|
|
{
|
|
|
|
KeSetEvent(&FDODeviceExtension->NoPendingRequests, IO_NO_INCREMENT, FALSE);
|
|
|
|
}
|
|
|
|
|
2011-05-15 14:59:16 +00:00
|
|
|
//
|
|
|
|
// release lock
|
|
|
|
//
|
|
|
|
KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-05-14 18:09:00 +00:00
|
|
|
VOID
|
|
|
|
USBSTOR_QueueNextRequest(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject)
|
|
|
|
{
|
2011-05-15 14:59:16 +00:00
|
|
|
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
2011-05-14 18:09:00 +00:00
|
|
|
PIRP Irp;
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
PSCSI_REQUEST_BLOCK Request;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get pdo device extension
|
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
ASSERT(FDODeviceExtension->Common.IsFDO);
|
2011-05-14 18:09:00 +00:00
|
|
|
|
2012-01-24 23:04:31 +00:00
|
|
|
//
|
|
|
|
// check first if there's already a request pending or the queue is frozen
|
|
|
|
//
|
|
|
|
if (FDODeviceExtension->ActiveSrb != NULL ||
|
|
|
|
FDODeviceExtension->IrpListFreeze)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no work to do yet
|
|
|
|
//
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
|
|
|
// remove first irp from list
|
|
|
|
//
|
|
|
|
Irp = USBSTOR_RemoveIrp(DeviceObject);
|
|
|
|
|
|
|
|
//
|
|
|
|
// is there an irp pending
|
|
|
|
//
|
|
|
|
if (!Irp)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no work to do
|
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
IoStartNextPacket(DeviceObject, TRUE);
|
2011-05-14 18:09:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// get current stack location
|
|
|
|
//
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get srb
|
|
|
|
//
|
|
|
|
Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1;
|
|
|
|
|
2011-05-15 14:59:16 +00:00
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
ASSERT(Request);
|
|
|
|
|
2012-01-24 23:04:31 +00:00
|
|
|
//
|
|
|
|
// set the active SRB
|
|
|
|
//
|
|
|
|
FDODeviceExtension->ActiveSrb = Request;
|
|
|
|
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
|
|
|
// start next packet
|
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
IoStartPacket(DeviceObject, Irp, &Request->QueueSortKey, USBSTOR_CancelIo);
|
|
|
|
|
|
|
|
//
|
|
|
|
// start next request
|
|
|
|
//
|
|
|
|
IoStartNextPacket(DeviceObject, TRUE);
|
2011-05-14 18:09:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
USBSTOR_QueueRelease(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject)
|
|
|
|
{
|
|
|
|
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
|
|
|
PIRP Irp;
|
|
|
|
KIRQL OldLevel;
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
PSCSI_REQUEST_BLOCK Request;
|
|
|
|
|
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
// get FDO device extension
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
ASSERT(FDODeviceExtension->Common.IsFDO);
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// acquire lock
|
|
|
|
//
|
|
|
|
KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// clear freezed status
|
|
|
|
//
|
|
|
|
FDODeviceExtension->IrpListFreeze = FALSE;
|
|
|
|
|
|
|
|
//
|
|
|
|
// release irp list lock
|
|
|
|
//
|
|
|
|
KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// grab newest irp
|
|
|
|
//
|
|
|
|
Irp = USBSTOR_RemoveIrp(DeviceObject);
|
|
|
|
|
|
|
|
//
|
|
|
|
// is there an irp
|
|
|
|
//
|
|
|
|
if (!Irp)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no irp
|
|
|
|
//
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// get current irp stack location
|
|
|
|
//
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get srb
|
|
|
|
//
|
|
|
|
Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1;
|
|
|
|
|
|
|
|
//
|
|
|
|
// start new packet
|
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
IoStartPacket(DeviceObject,
|
2011-05-14 18:09:00 +00:00
|
|
|
Irp,
|
|
|
|
&Request->QueueSortKey,
|
|
|
|
USBSTOR_CancelIo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
USBSTOR_StartIo(
|
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
|
|
|
{
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
|
|
|
PPDO_DEVICE_EXTENSION PDODeviceExtension;
|
|
|
|
KIRQL OldLevel;
|
|
|
|
NTSTATUS Status;
|
2011-05-15 12:47:54 +00:00
|
|
|
BOOLEAN ResetInProgress;
|
2011-05-14 18:09:00 +00:00
|
|
|
|
2011-05-15 17:57:02 +00:00
|
|
|
DPRINT("USBSTOR_StartIo\n");
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// get FDO device extension
|
|
|
|
//
|
|
|
|
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
ASSERT(FDODeviceExtension->Common.IsFDO);
|
|
|
|
|
|
|
|
//
|
|
|
|
// acquire cancel spinlock
|
|
|
|
//
|
|
|
|
IoAcquireCancelSpinLock(&OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// set cancel routine to zero
|
|
|
|
//
|
|
|
|
IoSetCancelRoutine(Irp, NULL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// check if the irp has been cancelled
|
|
|
|
//
|
|
|
|
if (Irp->Cancel)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// irp has been cancelled, release cancel spinlock
|
|
|
|
//
|
|
|
|
IoReleaseCancelSpinLock(OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// irp is cancelled
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Status = STATUS_CANCELLED;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
|
2012-01-24 23:04:31 +00:00
|
|
|
//
|
|
|
|
// terminate request
|
|
|
|
//
|
|
|
|
USBSTOR_QueueTerminateRequest(DeviceObject, Irp);
|
|
|
|
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
|
|
|
// complete request
|
|
|
|
//
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
|
|
|
//
|
2012-01-24 23:04:31 +00:00
|
|
|
// queue next request
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
2012-01-24 23:04:31 +00:00
|
|
|
USBSTOR_QueueNextRequest(DeviceObject);
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// release cancel spinlock
|
|
|
|
//
|
|
|
|
IoReleaseCancelSpinLock(OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// acquire lock
|
|
|
|
//
|
|
|
|
KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel);
|
|
|
|
|
|
|
|
//
|
2011-05-15 12:47:54 +00:00
|
|
|
// check reset is in progress
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
2011-05-15 12:47:54 +00:00
|
|
|
ResetInProgress = FDODeviceExtension->ResetInProgress;
|
|
|
|
ASSERT(ResetInProgress == FALSE);
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// release lock
|
|
|
|
//
|
|
|
|
KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get current irp stack location
|
|
|
|
//
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get pdo device extension
|
|
|
|
//
|
|
|
|
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension;
|
|
|
|
|
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
|
|
|
|
|
|
|
|
//
|
2011-05-15 12:47:54 +00:00
|
|
|
// is a reset in progress
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
2011-05-15 12:47:54 +00:00
|
|
|
if (ResetInProgress)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// hard reset is in progress
|
|
|
|
//
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = STATUS_DEVICE_DOES_NOT_EXIST;
|
2012-01-24 23:04:31 +00:00
|
|
|
USBSTOR_QueueTerminateRequest(DeviceObject, Irp);
|
2011-05-15 12:47:54 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2011-05-15 14:59:16 +00:00
|
|
|
return;
|
2011-05-15 12:47:54 +00:00
|
|
|
}
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
// execute scsi
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
Status = USBSTOR_HandleExecuteSCSI(IoStack->DeviceObject, Irp);
|
2011-05-14 18:09:00 +00:00
|
|
|
|
|
|
|
//
|
2011-05-15 14:59:16 +00:00
|
|
|
// FIXME: handle error
|
2011-05-14 18:09:00 +00:00
|
|
|
//
|
|
|
|
}
|