diff --git a/drivers/usb/usbstor/disk.c b/drivers/usb/usbstor/disk.c index 96152c3afce..b42f9af461f 100644 --- a/drivers/usb/usbstor/disk.c +++ b/drivers/usb/usbstor/disk.c @@ -46,7 +46,7 @@ USBSTOR_HandleInternalDeviceControl( { case SRB_FUNCTION_EXECUTE_SCSI: { - DPRINT1("SRB_FUNCTION_EXECUTE_SCSI\n"); + DPRINT("SRB_FUNCTION_EXECUTE_SCSI\n"); // // check if request is valid @@ -56,7 +56,7 @@ USBSTOR_HandleInternalDeviceControl( // // 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) { diff --git a/drivers/usb/usbstor/queue.c b/drivers/usb/usbstor/queue.c index c726c7052a8..a7fffb0da9c 100644 --- a/drivers/usb/usbstor/queue.c +++ b/drivers/usb/usbstor/queue.c @@ -27,7 +27,6 @@ USBSTOR_QueueInitialize( InitializeListHead(&FDODeviceExtension->IrpListHead); } - VOID NTAPI USBSTOR_CancelIo( @@ -89,11 +88,13 @@ USBSTOR_QueueAddIrp( 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 @@ -111,9 +112,22 @@ USBSTOR_QueueAddIrp( 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 @@ -159,7 +173,9 @@ USBSTOR_QueueAddIrp( // // if list is freezed, dont start this packet // - return IrpListFreeze; + DPRINT1("IrpListFreeze: %lu IrpPendingCount %lu\n", IrpListFreeze, FDODeviceExtension->IrpPendingCount); + + return (IrpListFreeze || SrbProcessing); } PIRP @@ -442,6 +458,7 @@ USBSTOR_StartIo( PPDO_DEVICE_EXTENSION PDODeviceExtension; KIRQL OldLevel; NTSTATUS Status; + BOOLEAN ResetInProgress; DPRINT1("USBSTOR_StartIo\n"); @@ -519,9 +536,10 @@ USBSTOR_StartIo( 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 @@ -544,9 +562,39 @@ USBSTOR_StartIo( 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 @@ -557,5 +605,4 @@ USBSTOR_StartIo( // start next request // IoStartNextPacket(DeviceObject, TRUE); - } diff --git a/drivers/usb/usbstor/scsi.c b/drivers/usb/usbstor/scsi.c index 5611815c712..a7a997bf43a 100644 --- a/drivers/usb/usbstor/scsi.c +++ b/drivers/usb/usbstor/scsi.c @@ -442,7 +442,7 @@ USBSTOR_SendRequest( PFDO_DEVICE_EXTENSION FDODeviceExtension; PIRP Irp; PIO_STACK_LOCATION IoStack; - PULONG MdlVirtualAddress; + PUCHAR MdlVirtualAddress; // // first allocate irp context @@ -509,16 +509,16 @@ USBSTOR_SendRequest( 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 @@ -736,6 +736,7 @@ USBSTOR_SendModeSenseCmd( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { +#if 0 UFI_SENSE_CMD Cmd; NTSTATUS Status; PVOID Response; @@ -743,7 +744,7 @@ USBSTOR_SendModeSenseCmd( PCBW OutControl; PCDB pCDB; PUFI_MODE_PARAMETER_HEADER Header; - +#endif PIO_STACK_LOCATION IoStack; PSCSI_REQUEST_BLOCK Request; @@ -908,13 +909,11 @@ USBSTOR_SendReadWriteCmd( 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 @@ -939,7 +938,7 @@ USBSTOR_SendReadWriteCmd( // // 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 @@ -963,12 +962,12 @@ USBSTOR_SendReadWriteCmd( 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 diff --git a/drivers/usb/usbstor/usbstor.c b/drivers/usb/usbstor/usbstor.c index dc2d6e7bdd3..b7fba72d435 100644 --- a/drivers/usb/usbstor/usbstor.c +++ b/drivers/usb/usbstor/usbstor.c @@ -148,8 +148,6 @@ USBSTOR_DispatchScsi( PDEVICE_OBJECT DeviceObject, PIRP Irp) { - NTSTATUS Status; - // // handle requests // diff --git a/drivers/usb/usbstor/usbstor.h b/drivers/usb/usbstor/usbstor.h index a1938625b20..cebd43607cb 100644 --- a/drivers/usb/usbstor/usbstor.h +++ b/drivers/usb/usbstor/usbstor.h @@ -66,6 +66,8 @@ typedef struct 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 @@ -371,6 +373,10 @@ USBSTOR_HandleExecuteSCSI( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); +NTSTATUS +USBSTOR_SendInquiryCmd( + IN PDEVICE_OBJECT DeviceObject); + //--------------------------------------------------------------------- // // disk.c routines @@ -417,3 +423,4 @@ USBSTOR_CancelIo( VOID USBSTOR_QueueInitialize( PFDO_DEVICE_EXTENSION FDODeviceExtension); +