mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 18:15:11 +00:00
[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:
parent
e5f521c90a
commit
5c5f758afa
5 changed files with 80 additions and 29 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -148,8 +148,6 @@ USBSTOR_DispatchScsi(
|
|||
PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
|
||||
//
|
||||
// handle requests
|
||||
//
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue