{
case SRB_FUNCTION_EXECUTE_SCSI:
{
- DPRINT1("SRB_FUNCTION_EXECUTE_SCSI\n");
+ DPRINT("SRB_FUNCTION_EXECUTE_SCSI\n");
//
// check if request is valid
//
// data is transferred with this irp
//
- if (Request->SrbFlags & (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT) == (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT) ||
+ if ((Request->SrbFlags & (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT) == (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT)) ||
Request->DataTransferLength == 0 ||
Irp->MdlAddress == NULL)
{
InitializeListHead(&FDODeviceExtension->IrpListHead);
}
-
VOID
NTAPI
USBSTOR_CancelIo(
PPDO_DEVICE_EXTENSION PDODeviceExtension;
PFDO_DEVICE_EXTENSION FDODeviceExtension;
BOOLEAN IrpListFreeze;
+ BOOLEAN SrbProcessing;
//
// get pdo device extension
//
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
//
// get FDO device extension
KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel);
//
- // add irp to queue
+ // check if there are irp pending
//
- InsertTailList(&FDODeviceExtension->IrpListHead, &Irp->Tail.Overlay.ListEntry);
+ SrbProcessing = FDODeviceExtension->IrpPendingCount != 0;
+
+ if (SrbProcessing)
+ {
+ //
+ // add irp to queue
+ //
+ InsertTailList(&FDODeviceExtension->IrpListHead, &Irp->Tail.Overlay.ListEntry);
+ }
+
+ //
+ // increment pending count
+ //
+ FDODeviceExtension->IrpPendingCount++;
//
// now set the driver cancel routine
//
// if list is freezed, dont start this packet
//
- return IrpListFreeze;
+ DPRINT1("IrpListFreeze: %lu IrpPendingCount %lu\n", IrpListFreeze, FDODeviceExtension->IrpPendingCount);
+
+ return (IrpListFreeze || SrbProcessing);
}
PIRP
PPDO_DEVICE_EXTENSION PDODeviceExtension;
KIRQL OldLevel;
NTSTATUS Status;
+ BOOLEAN ResetInProgress;
DPRINT1("USBSTOR_StartIo\n");
KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel);
//
- // remove irp from list
+ // check reset is in progress
//
- RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
+ ResetInProgress = FDODeviceExtension->ResetInProgress;
+ ASSERT(ResetInProgress == FALSE);
//
// release lock
ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
//
- // execute scsi
+ // is a reset in progress
//
- Status = USBSTOR_HandleExecuteSCSI(IoStack->DeviceObject, Irp);
+ if (ResetInProgress)
+ {
+ //
+ // hard reset is in progress
+ //
+ Irp->IoStatus.Information = 0;
+ Irp->IoStatus.Status = STATUS_DEVICE_DOES_NOT_EXIST;
+ IoCompleteRequest(Irp, IO_NO_INCREMENT);
+ }
+ else
+ {
+ //
+ // execute scsi
+ //
+ Status = USBSTOR_HandleExecuteSCSI(IoStack->DeviceObject, Irp);
+
+ //
+ // acquire lock
+ //
+ KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel);
+
+ //
+ // FIXME: synchronize with error handler
+ //
+ FDODeviceExtension->IrpPendingCount--;
+
+ //
+ // release lock
+ //
+ KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel);
+ }
//
// FIXME: synchronize action with error handling
// start next request
//
IoStartNextPacket(DeviceObject, TRUE);
-
}
PFDO_DEVICE_EXTENSION FDODeviceExtension;
PIRP Irp;
PIO_STACK_LOCATION IoStack;
- PULONG MdlVirtualAddress;
+ PUCHAR MdlVirtualAddress;
//
// first allocate irp context
if (OriginalRequest)
{
if ((OriginalRequest->MdlAddress != NULL) &&
- (Context->TransferData == NULL || Command[0] == SCSIOP_READ || Command[0] == SCSIOP_WRITE))
+ (Context->TransferData == NULL || Command[0] == SCSIOP_READ || Command[0] == SCSIOP_WRITE))
{
- //
- // Sanity check that the Mdl does describe the TransferData for read/write
- //
- if (CommandLength == UFI_READ_WRITE_CMD_LEN)
- {
- MdlVirtualAddress = MmGetMdlVirtualAddress(OriginalRequest->MdlAddress);
- ASSERT(MdlVirtualAddress == Context->TransferData);
- }
+ //
+ // Sanity check that the Mdl does describe the TransferData for read/write
+ //
+ if (CommandLength == UFI_READ_WRITE_CMD_LEN)
+ {
+ MdlVirtualAddress = MmGetMdlVirtualAddress(OriginalRequest->MdlAddress);
+ ASSERT(MdlVirtualAddress == Context->TransferData);
+ }
//
// I/O paging request
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
+#if 0
UFI_SENSE_CMD Cmd;
NTSTATUS Status;
PVOID Response;
PCBW OutControl;
PCDB pCDB;
PUFI_MODE_PARAMETER_HEADER Header;
-
+#endif
PIO_STACK_LOCATION IoStack;
PSCSI_REQUEST_BLOCK Request;
IN PIRP Irp)
{
UFI_READ_WRITE_CMD Cmd;
- NTSTATUS Status;
PPDO_DEVICE_EXTENSION PDODeviceExtension;
PCDB pCDB;
ULONG BlockCount;
PIO_STACK_LOCATION IoStack;
PSCSI_REQUEST_BLOCK Request;
- PVOID Buffer;
//
// get current stack location
//
// informal debug print
//
- DPRINT1("USBSTOR_SendReadWriteCmd DataTransferLength %x, BlockLength %x\n", Request->DataTransferLength, PDODeviceExtension->BlockLength);
+ DPRINT("USBSTOR_SendReadWriteCmd DataTransferLength %lu, BlockLength %lu\n", Request->DataTransferLength, PDODeviceExtension->BlockLength);
//
// sanity check
Cmd.LogicalBlockByte2 = pCDB->CDB10.LogicalBlockByte2;
Cmd.LogicalBlockByte3 = pCDB->CDB10.LogicalBlockByte3;
- DPRINT1("BlockAddress %x%x%x%x BlockCount %lu BlockLength %lu\n", Cmd.LogicalBlockByte0, Cmd.LogicalBlockByte1, Cmd.LogicalBlockByte2, Cmd.LogicalBlockByte3, BlockCount, PDODeviceExtension->BlockLength);
+ DPRINT1("USBSTOR_SendReadWriteCmd BlockAddress %x%x%x%x BlockCount %lu BlockLength %lu\n", Cmd.LogicalBlockByte0, Cmd.LogicalBlockByte1, Cmd.LogicalBlockByte2, Cmd.LogicalBlockByte3, BlockCount, PDODeviceExtension->BlockLength);
//
// send request
//
- return USBSTOR_SendRequest(DeviceObject, Irp, NULL, UFI_READ_WRITE_CMD_LEN, (PUCHAR)&Cmd, Request->DataTransferLength, (PUCHAR)Request->DataBuffer);
+ return USBSTOR_SendRequest(DeviceObject, Irp, NULL, UFI_READ_WRITE_CMD_LEN, (PUCHAR)&Cmd, Request->DataTransferLength, (PUCHAR)Request->DataBuffer);
}
NTSTATUS
PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
- NTSTATUS Status;
-
//
// handle requests
//
KSPIN_LOCK IrpListLock; // irp list lock
LIST_ENTRY IrpListHead; // irp list head
BOOLEAN IrpListFreeze; // if true the irp list is freezed
+ BOOLEAN ResetInProgress; // if hard reset is in progress
+ ULONG IrpPendingCount; // count of irp pending
}FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION;
typedef struct
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp);
+NTSTATUS
+USBSTOR_SendInquiryCmd(
+ IN PDEVICE_OBJECT DeviceObject);
+
//---------------------------------------------------------------------
//
// disk.c routines
VOID
USBSTOR_QueueInitialize(
PFDO_DEVICE_EXTENSION FDODeviceExtension);
+