[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

svn path=/branches/usb-bringup/; revision=51759
This commit is contained in:
Johannes Anderwald 2011-05-15 12:47:54 +00:00
parent e5f521c90a
commit 5c5f758afa
5 changed files with 80 additions and 29 deletions

View file

@ -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)
{

View file

@ -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
@ -110,10 +111,23 @@ USBSTOR_QueueAddIrp(
//
KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel);
//
// 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 @@ 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
@ -543,11 +561,41 @@ USBSTOR_StartIo(
//
ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
//
// 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 @@ USBSTOR_StartIo(
// start next request
//
IoStartNextPacket(DeviceObject, TRUE);
}

View file

@ -442,7 +442,7 @@ USBSTOR_SendRequest(
PFDO_DEVICE_EXTENSION FDODeviceExtension;
PIRP Irp;
PIO_STACK_LOCATION IoStack;
PULONG MdlVirtualAddress;
PUCHAR MdlVirtualAddress;
//
// first allocate irp context
@ -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,7 +962,7 @@ 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

View file

@ -148,8 +148,6 @@ USBSTOR_DispatchScsi(
PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
NTSTATUS Status;
//
// handle requests
//

View file

@ -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);