Author: janderwald
Date: Sun May 15 12:47:54 2011
New Revision: 51759
URL:
http://svn.reactos.org/svn/reactos?rev=51759&view=rev
Log:
[USBSTOR]
- Silence warnings
- Silence traces
- Add asserts
- Add code to detect usb reset in progress. In that case cancel the request
- Add more code to synchronize urb action
- WIP, still hangs are observed
Modified:
branches/usb-bringup/drivers/usb/usbstor/disk.c
branches/usb-bringup/drivers/usb/usbstor/queue.c
branches/usb-bringup/drivers/usb/usbstor/scsi.c
branches/usb-bringup/drivers/usb/usbstor/usbstor.c
branches/usb-bringup/drivers/usb/usbstor/usbstor.h
Modified: branches/usb-bringup/drivers/usb/usbstor/disk.c
URL:
http://svn.reactos.org/svn/reactos/branches/usb-bringup/drivers/usb/usbstor…
==============================================================================
--- branches/usb-bringup/drivers/usb/usbstor/disk.c [iso-8859-1] (original)
+++ branches/usb-bringup/drivers/usb/usbstor/disk.c [iso-8859-1] Sun May 15 12:47:54 2011
@@ -46,7 +46,7 @@
{
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 @@
//
// 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)
{
Modified: branches/usb-bringup/drivers/usb/usbstor/queue.c
URL:
http://svn.reactos.org/svn/reactos/branches/usb-bringup/drivers/usb/usbstor…
==============================================================================
--- branches/usb-bringup/drivers/usb/usbstor/queue.c [iso-8859-1] (original)
+++ branches/usb-bringup/drivers/usb/usbstor/queue.c [iso-8859-1] Sun May 15 12:47:54
2011
@@ -27,7 +27,6 @@
InitializeListHead(&FDODeviceExtension->IrpListHead);
}
-
VOID
NTAPI
USBSTOR_CancelIo(
@@ -89,11 +88,13 @@
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 @@
KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel);
//
- // add irp to queue
- //
- InsertTailList(&FDODeviceExtension->IrpListHead,
&Irp->Tail.Overlay.ListEntry);
+ // check if there are irp pending
+ //
+ 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 @@
//
// 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 @@
PPDO_DEVICE_EXTENSION PDODeviceExtension;
KIRQL OldLevel;
NTSTATUS Status;
+ BOOLEAN ResetInProgress;
DPRINT1("USBSTOR_StartIo\n");
@@ -519,9 +536,10 @@
KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel);
//
- // remove irp from list
- //
- RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
+ // check reset is in progress
+ //
+ ResetInProgress = FDODeviceExtension->ResetInProgress;
+ ASSERT(ResetInProgress == FALSE);
//
// release lock
@@ -544,9 +562,39 @@
ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
//
- // execute scsi
- //
- Status = USBSTOR_HandleExecuteSCSI(IoStack->DeviceObject, Irp);
+ // is a reset in progress
+ //
+ 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 @@
// start next request
//
IoStartNextPacket(DeviceObject, TRUE);
-
-}
+}
Modified: branches/usb-bringup/drivers/usb/usbstor/scsi.c
URL:
http://svn.reactos.org/svn/reactos/branches/usb-bringup/drivers/usb/usbstor…
==============================================================================
--- branches/usb-bringup/drivers/usb/usbstor/scsi.c [iso-8859-1] (original)
+++ branches/usb-bringup/drivers/usb/usbstor/scsi.c [iso-8859-1] Sun May 15 12:47:54 2011
@@ -442,7 +442,7 @@
PFDO_DEVICE_EXTENSION FDODeviceExtension;
PIRP Irp;
PIO_STACK_LOCATION IoStack;
- PULONG MdlVirtualAddress;
+ PUCHAR MdlVirtualAddress;
//
// first allocate irp context
@@ -509,16 +509,16 @@
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 @@
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
+#if 0
UFI_SENSE_CMD Cmd;
NTSTATUS Status;
PVOID Response;
@@ -743,7 +744,7 @@
PCBW OutControl;
PCDB pCDB;
PUFI_MODE_PARAMETER_HEADER Header;
-
+#endif
PIO_STACK_LOCATION IoStack;
PSCSI_REQUEST_BLOCK Request;
@@ -908,13 +909,11 @@
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 @@
//
// 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 @@
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
Modified: branches/usb-bringup/drivers/usb/usbstor/usbstor.c
URL:
http://svn.reactos.org/svn/reactos/branches/usb-bringup/drivers/usb/usbstor…
==============================================================================
--- branches/usb-bringup/drivers/usb/usbstor/usbstor.c [iso-8859-1] (original)
+++ branches/usb-bringup/drivers/usb/usbstor/usbstor.c [iso-8859-1] Sun May 15 12:47:54
2011
@@ -148,8 +148,6 @@
PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
- NTSTATUS Status;
-
//
// handle requests
//
Modified: branches/usb-bringup/drivers/usb/usbstor/usbstor.h
URL:
http://svn.reactos.org/svn/reactos/branches/usb-bringup/drivers/usb/usbstor…
==============================================================================
--- branches/usb-bringup/drivers/usb/usbstor/usbstor.h [iso-8859-1] (original)
+++ branches/usb-bringup/drivers/usb/usbstor/usbstor.h [iso-8859-1] Sun May 15 12:47:54
2011
@@ -66,6 +66,8 @@
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 @@
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp);
+NTSTATUS
+USBSTOR_SendInquiryCmd(
+ IN PDEVICE_OBJECT DeviceObject);
+
//---------------------------------------------------------------------
//
// disk.c routines
@@ -417,3 +423,4 @@
VOID
USBSTOR_QueueInitialize(
PFDO_DEVICE_EXTENSION FDODeviceExtension);
+