mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 09:34:43 +00:00
[USBSTOR] Move PDO's Inquiry data and FDO's SCSI context
to their Device Extensions. This way the driver can better handle low memory situations
This commit is contained in:
parent
a9b97aeded
commit
94e61c3080
5 changed files with 113 additions and 148 deletions
|
@ -283,8 +283,7 @@ USBSTOR_HandleQueryProperty(
|
|||
ASSERT(FDODeviceExtension);
|
||||
ASSERT(FDODeviceExtension->Common.IsFDO);
|
||||
|
||||
InquiryData = PDODeviceExtension->InquiryData;
|
||||
ASSERT(InquiryData);
|
||||
InquiryData = (PINQUIRYDATA)&PDODeviceExtension->InquiryData;
|
||||
|
||||
// compute extra parameters length
|
||||
FieldLengthVendor = USBSTOR_GetFieldLength(InquiryData->VendorId, 8);
|
||||
|
@ -507,7 +506,7 @@ USBSTOR_HandleDeviceControl(
|
|||
|
||||
// Note: INQUIRYDATA structure is larger than INQUIRYDATABUFFERSIZE
|
||||
RtlZeroMemory(InquiryData, sizeof(INQUIRYDATA));
|
||||
RtlCopyMemory(InquiryData, PDODeviceExtension->InquiryData, INQUIRYDATABUFFERSIZE);
|
||||
RtlCopyMemory(InquiryData, &PDODeviceExtension->InquiryData, sizeof(PDODeviceExtension->InquiryData));
|
||||
|
||||
InquiryData->Versions = 0x04;
|
||||
InquiryData->ResponseDataFormat = 0x02; // some devices set this to 1
|
||||
|
|
|
@ -77,15 +77,15 @@ USBSTOR_ResetPipeWorkItemRoutine(
|
|||
IN PVOID Ctx)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
PIRP_CONTEXT Context = (PIRP_CONTEXT)Ctx;
|
||||
PFDO_DEVICE_EXTENSION FDODeviceExtension = (PFDO_DEVICE_EXTENSION)FdoDevice->DeviceExtension;
|
||||
PFDO_DEVICE_EXTENSION FDODeviceExtension = (PFDO_DEVICE_EXTENSION)Ctx;
|
||||
PIRP_CONTEXT Context = &FDODeviceExtension->CurrentIrpContext;
|
||||
|
||||
// clear stall on the corresponding pipe
|
||||
Status = USBSTOR_ResetPipeWithHandle(FDODeviceExtension->LowerDeviceObject, Context->Urb.UrbBulkOrInterruptTransfer.PipeHandle);
|
||||
DPRINT1("USBSTOR_ResetPipeWithHandle Status %x\n", Status);
|
||||
|
||||
// now resend the csw as the stall got cleared
|
||||
USBSTOR_SendCSWRequest(Context, Context->Irp);
|
||||
USBSTOR_SendCSWRequest(FDODeviceExtension, Context->Irp);
|
||||
}
|
||||
|
||||
VOID
|
||||
|
@ -133,15 +133,14 @@ USBSTOR_ResetDeviceWorkItemRoutine(
|
|||
VOID
|
||||
NTAPI
|
||||
USBSTOR_QueueResetPipe(
|
||||
IN PFDO_DEVICE_EXTENSION FDODeviceExtension,
|
||||
IN PIRP_CONTEXT Context)
|
||||
IN PFDO_DEVICE_EXTENSION FDODeviceExtension)
|
||||
{
|
||||
DPRINT("USBSTOR_QueueResetPipe\n");
|
||||
|
||||
IoQueueWorkItem(FDODeviceExtension->ResetDeviceWorkItem,
|
||||
USBSTOR_ResetPipeWorkItemRoutine,
|
||||
CriticalWorkQueue,
|
||||
Context);
|
||||
FDODeviceExtension);
|
||||
}
|
||||
|
||||
VOID
|
||||
|
|
|
@ -137,8 +137,7 @@ USBSTOR_PdoHandleQueryDeviceText(
|
|||
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
||||
|
||||
DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
||||
ASSERT(DeviceExtension->InquiryData);
|
||||
InquiryData = DeviceExtension->InquiryData;
|
||||
InquiryData = (PINQUIRYDATA)&DeviceExtension->InquiryData;
|
||||
|
||||
switch (IoStack->Parameters.QueryDeviceText.DeviceTextType)
|
||||
{
|
||||
|
@ -191,8 +190,7 @@ USBSTOR_PdoHandleQueryDeviceId(
|
|||
UNICODE_STRING DeviceId;
|
||||
|
||||
DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
||||
ASSERT(DeviceExtension->InquiryData);
|
||||
InquiryData = DeviceExtension->InquiryData;
|
||||
InquiryData = (PINQUIRYDATA)&DeviceExtension->InquiryData;
|
||||
|
||||
DeviceType = USBSTOR_GetDeviceType(InquiryData);
|
||||
|
||||
|
@ -282,7 +280,7 @@ USBSTOR_PdoHandleQueryHardwareId(
|
|||
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
||||
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension;
|
||||
ASSERT(FDODeviceExtension->DeviceDescriptor);
|
||||
InquiryData = PDODeviceExtension->InquiryData;
|
||||
InquiryData = (PINQUIRYDATA)&PDODeviceExtension->InquiryData;
|
||||
|
||||
DeviceType = USBSTOR_GetDeviceType(InquiryData);
|
||||
GenericType = USBSTOR_GetGenericType(InquiryData);
|
||||
|
@ -404,7 +402,7 @@ USBSTOR_PdoHandleQueryCompatibleId(
|
|||
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
||||
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension;
|
||||
ASSERT(FDODeviceExtension->DeviceDescriptor);
|
||||
DeviceType = USBSTOR_GetDeviceType(PDODeviceExtension->InquiryData);
|
||||
DeviceType = USBSTOR_GetDeviceType((PINQUIRYDATA)&PDODeviceExtension->InquiryData);
|
||||
|
||||
// format instance id
|
||||
Length = sprintf(Buffer, "USBSTOR\\%s", DeviceType) + 1;
|
||||
|
@ -573,10 +571,6 @@ USBSTOR_PdoHandlePnp(
|
|||
bDelete = FALSE;
|
||||
}
|
||||
|
||||
// clean up the device extension
|
||||
ASSERT(DeviceExtension->InquiryData);
|
||||
ExFreePoolWithTag(DeviceExtension->InquiryData, USB_STOR_TAG);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
|
@ -804,19 +798,10 @@ USBSTOR_FillInquiryData(
|
|||
IN PDEVICE_OBJECT PDODeviceObject)
|
||||
{
|
||||
NTSTATUS Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
PPDO_DEVICE_EXTENSION PDODeviceExtension;
|
||||
PPDO_DEVICE_EXTENSION PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDODeviceObject->DeviceExtension;
|
||||
CDB Cdb;
|
||||
ULONG DataTransferLength = INQUIRYDATABUFFERSIZE;
|
||||
PINQUIRYDATA InquiryData;
|
||||
|
||||
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDODeviceObject->DeviceExtension;
|
||||
InquiryData = ExAllocatePoolWithTag(NonPagedPool, INQUIRYDATABUFFERSIZE, USB_STOR_TAG);
|
||||
|
||||
if (!InquiryData)
|
||||
{
|
||||
DPRINT1("USBSTOR_FillInquiryData failed with %x\n", Status);
|
||||
return Status;
|
||||
}
|
||||
PINQUIRYDATA InquiryData = (PINQUIRYDATA)&PDODeviceExtension->InquiryData;
|
||||
|
||||
RtlZeroMemory(&Cdb, sizeof(Cdb));
|
||||
Cdb.CDB6INQUIRY.OperationCode = SCSIOP_INQUIRY;
|
||||
|
@ -827,7 +812,6 @@ USBSTOR_FillInquiryData(
|
|||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("USBSTOR_FillInquiryData failed with %x\n", Status);
|
||||
ExFreePoolWithTag(InquiryData, USB_STOR_TAG);
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
@ -846,7 +830,6 @@ USBSTOR_FillInquiryData(
|
|||
|
||||
DPRINT("Revision %c%c%c%c\n", InquiryData->ProductRevisionLevel[0], InquiryData->ProductRevisionLevel[1], InquiryData->ProductRevisionLevel[2], InquiryData->ProductRevisionLevel[3]);
|
||||
|
||||
PDODeviceExtension->InquiryData = InquiryData;
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
@ -859,6 +842,7 @@ USBSTOR_CreatePDO(
|
|||
NTSTATUS Status;
|
||||
PPDO_DEVICE_EXTENSION PDODeviceExtension;
|
||||
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
||||
PINQUIRYDATA InquiryData;
|
||||
|
||||
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
||||
|
||||
|
@ -874,6 +858,7 @@ USBSTOR_CreatePDO(
|
|||
PDO->StackSize = DeviceObject->StackSize;
|
||||
|
||||
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDO->DeviceExtension;
|
||||
InquiryData = (PINQUIRYDATA)&PDODeviceExtension->InquiryData;
|
||||
|
||||
// initialize device extension
|
||||
RtlZeroMemory(PDODeviceExtension, sizeof(PDO_DEVICE_EXTENSION));
|
||||
|
@ -899,8 +884,8 @@ USBSTOR_CreatePDO(
|
|||
return Status;
|
||||
}
|
||||
|
||||
if (PDODeviceExtension->InquiryData->DeviceType != DIRECT_ACCESS_DEVICE &&
|
||||
PDODeviceExtension->InquiryData->DeviceType != READ_ONLY_DIRECT_ACCESS_DEVICE)
|
||||
if (InquiryData->DeviceType != DIRECT_ACCESS_DEVICE &&
|
||||
InquiryData->DeviceType != READ_ONLY_DIRECT_ACCESS_DEVICE)
|
||||
{
|
||||
return STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
|
|
@ -65,10 +65,10 @@ USBSTOR_IssueBulkOrInterruptRequest(
|
|||
IN ULONG TransferBufferLength,
|
||||
IN PVOID TransferBuffer,
|
||||
IN PMDL TransferBufferMDL,
|
||||
IN PIO_COMPLETION_ROUTINE CompletionRoutine,
|
||||
IN PIRP_CONTEXT Context)
|
||||
IN PIO_COMPLETION_ROUTINE CompletionRoutine)
|
||||
{
|
||||
PIO_STACK_LOCATION NextStack;
|
||||
PIRP_CONTEXT Context = &FDODeviceExtension->CurrentIrpContext;
|
||||
|
||||
RtlZeroMemory(&Context->Urb, sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER));
|
||||
|
||||
|
@ -88,7 +88,7 @@ USBSTOR_IssueBulkOrInterruptRequest(
|
|||
|
||||
IoSetCompletionRoutine(Irp,
|
||||
CompletionRoutine,
|
||||
Context,
|
||||
FDODeviceExtension,
|
||||
TRUE,
|
||||
TRUE,
|
||||
TRUE);
|
||||
|
@ -107,9 +107,9 @@ USBSTOR_IsCSWValid(
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (Context->csw.Tag != PtrToUlong(&Context->csw))
|
||||
if (Context->csw.Tag != PtrToUlong(Context->Irp))
|
||||
{
|
||||
DPRINT1("[USBSTOR] Expected Tag %Ix but got %x\n", PtrToUlong(&Context->csw), Context->csw.Tag);
|
||||
DPRINT1("[USBSTOR] Expected Tag %Ix but got %x\n", PtrToUlong(Context->Irp), Context->csw.Tag);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -120,8 +120,7 @@ static
|
|||
NTSTATUS
|
||||
USBSTOR_IssueRequestSense(
|
||||
IN PFDO_DEVICE_EXTENSION FDODeviceExtension,
|
||||
IN PIRP Irp,
|
||||
IN PIRP_CONTEXT Context);
|
||||
IN PIRP Irp);
|
||||
|
||||
IO_COMPLETION_ROUTINE USBSTOR_CSWCompletionRoutine;
|
||||
|
||||
|
@ -138,13 +137,12 @@ USBSTOR_CSWCompletionRoutine(
|
|||
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
||||
PSCSI_REQUEST_BLOCK Request;
|
||||
|
||||
Context = (PIRP_CONTEXT)Ctx;
|
||||
|
||||
DPRINT("USBSTOR_CSWCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status);
|
||||
|
||||
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
||||
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension;
|
||||
FDODeviceExtension = Context->FDODeviceExtension;
|
||||
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)Ctx;
|
||||
Context = &FDODeviceExtension->CurrentIrpContext;
|
||||
Request = IoStack->Parameters.Scsi.Srb;
|
||||
ASSERT(Request);
|
||||
|
||||
|
@ -158,7 +156,7 @@ USBSTOR_CSWCompletionRoutine(
|
|||
++Context->StallRetryCount;
|
||||
|
||||
// clear stall and resend cbw
|
||||
USBSTOR_QueueResetPipe(FDODeviceExtension, Context);
|
||||
USBSTOR_QueueResetPipe(FDODeviceExtension);
|
||||
|
||||
return STATUS_MORE_PROCESSING_REQUIRED;
|
||||
}
|
||||
|
@ -211,7 +209,7 @@ USBSTOR_CSWCompletionRoutine(
|
|||
Request->SenseInfoBufferLength &&
|
||||
Request->SenseInfoBuffer)
|
||||
{
|
||||
USBSTOR_IssueRequestSense(FDODeviceExtension, Irp, Context);
|
||||
USBSTOR_IssueRequestSense(FDODeviceExtension, Irp);
|
||||
return STATUS_MORE_PROCESSING_REQUIRED;
|
||||
}
|
||||
|
||||
|
@ -224,7 +222,6 @@ USBSTOR_CSWCompletionRoutine(
|
|||
USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp);
|
||||
USBSTOR_QueueNextRequest(PDODeviceExtension->LowerDeviceObject);
|
||||
|
||||
ExFreePoolWithTag(Context, USB_STOR_TAG);
|
||||
return STATUS_CONTINUE_COMPLETION;
|
||||
|
||||
ResetRecovery:
|
||||
|
@ -238,24 +235,22 @@ ResetRecovery:
|
|||
USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp);
|
||||
USBSTOR_QueueResetDevice(FDODeviceExtension);
|
||||
|
||||
ExFreePoolWithTag(Context, USB_STOR_TAG);
|
||||
return STATUS_CONTINUE_COMPLETION;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
USBSTOR_SendCSWRequest(
|
||||
PIRP_CONTEXT Context,
|
||||
PFDO_DEVICE_EXTENSION FDODeviceExtension,
|
||||
PIRP Irp)
|
||||
{
|
||||
return USBSTOR_IssueBulkOrInterruptRequest(Context->FDODeviceExtension,
|
||||
return USBSTOR_IssueBulkOrInterruptRequest(FDODeviceExtension,
|
||||
Irp,
|
||||
Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle,
|
||||
FDODeviceExtension->InterfaceInformation->Pipes[FDODeviceExtension->BulkInPipeIndex].PipeHandle,
|
||||
USBD_TRANSFER_DIRECTION_IN,
|
||||
sizeof(CSW),
|
||||
&Context->csw,
|
||||
&FDODeviceExtension->CurrentIrpContext.csw,
|
||||
NULL,
|
||||
USBSTOR_CSWCompletionRoutine,
|
||||
Context);
|
||||
USBSTOR_CSWCompletionRoutine);
|
||||
}
|
||||
|
||||
IO_COMPLETION_ROUTINE USBSTOR_DataCompletionRoutine;
|
||||
|
@ -270,17 +265,19 @@ USBSTOR_DataCompletionRoutine(
|
|||
PIRP_CONTEXT Context;
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
PSCSI_REQUEST_BLOCK Request;
|
||||
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
||||
PPDO_DEVICE_EXTENSION PDODeviceExtension;
|
||||
|
||||
DPRINT("USBSTOR_DataCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status);
|
||||
|
||||
Context = (PIRP_CONTEXT)Ctx;
|
||||
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)Ctx;
|
||||
Context = &FDODeviceExtension->CurrentIrpContext;
|
||||
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
||||
Request = IoStack->Parameters.Scsi.Srb;
|
||||
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension;
|
||||
|
||||
// for Sense Request a partial MDL was already freed (if existed)
|
||||
if (Request == Context->FDODeviceExtension->ActiveSrb &&
|
||||
if (Request == FDODeviceExtension->ActiveSrb &&
|
||||
Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferMDL != Irp->MdlAddress)
|
||||
{
|
||||
IoFreeMdl(Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferMDL);
|
||||
|
@ -298,7 +295,7 @@ USBSTOR_DataCompletionRoutine(
|
|||
}
|
||||
|
||||
Request->DataTransferLength = Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferLength;
|
||||
USBSTOR_SendCSWRequest(Context, Irp);
|
||||
USBSTOR_SendCSWRequest(FDODeviceExtension, Irp);
|
||||
}
|
||||
else if (USBD_STATUS(Context->Urb.UrbHeader.Status) == USBD_STATUS(USBD_STATUS_STALL_PID))
|
||||
{
|
||||
|
@ -308,7 +305,7 @@ USBSTOR_DataCompletionRoutine(
|
|||
Request->DataTransferLength = Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferLength;
|
||||
|
||||
// clear stall and resend cbw
|
||||
USBSTOR_QueueResetPipe(Context->FDODeviceExtension, Context);
|
||||
USBSTOR_QueueResetPipe(FDODeviceExtension);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -317,9 +314,8 @@ USBSTOR_DataCompletionRoutine(
|
|||
Request->SrbStatus = SRB_STATUS_BUS_RESET;
|
||||
|
||||
USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp);
|
||||
USBSTOR_QueueResetDevice(Context->FDODeviceExtension);
|
||||
USBSTOR_QueueResetDevice(FDODeviceExtension);
|
||||
|
||||
ExFreePoolWithTag(Context, USB_STOR_TAG);
|
||||
return STATUS_CONTINUE_COMPLETION;
|
||||
}
|
||||
|
||||
|
@ -339,6 +335,7 @@ USBSTOR_CBWCompletionRoutine(
|
|||
PIO_STACK_LOCATION IoStack;
|
||||
PSCSI_REQUEST_BLOCK Request;
|
||||
PPDO_DEVICE_EXTENSION PDODeviceExtension;
|
||||
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
||||
USBD_PIPE_HANDLE PipeHandle;
|
||||
ULONG TransferFlags;
|
||||
PMDL Mdl = NULL;
|
||||
|
@ -346,7 +343,8 @@ USBSTOR_CBWCompletionRoutine(
|
|||
|
||||
DPRINT("USBSTOR_CBWCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status);
|
||||
|
||||
Context = (PIRP_CONTEXT)Ctx;
|
||||
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)Ctx;
|
||||
Context = &FDODeviceExtension->CurrentIrpContext;
|
||||
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
||||
Request = IoStack->Parameters.Scsi.Srb;
|
||||
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension;
|
||||
|
@ -358,10 +356,10 @@ USBSTOR_CBWCompletionRoutine(
|
|||
|
||||
// a request without the buffer AND not a sense request
|
||||
// for a sense request we provide just a TransferBuffer, an Mdl will be allocated by usbport (see below)
|
||||
if (!Irp->MdlAddress && Request == Context->FDODeviceExtension->ActiveSrb)
|
||||
if (!Irp->MdlAddress && Request == FDODeviceExtension->ActiveSrb)
|
||||
{
|
||||
Request->SrbStatus = SRB_STATUS_SUCCESS;
|
||||
USBSTOR_SendCSWRequest(Context, Irp);
|
||||
USBSTOR_SendCSWRequest(FDODeviceExtension, Irp);
|
||||
return STATUS_MORE_PROCESSING_REQUIRED;
|
||||
}
|
||||
|
||||
|
@ -369,12 +367,12 @@ USBSTOR_CBWCompletionRoutine(
|
|||
|
||||
if ((Request->SrbFlags & SRB_FLAGS_UNSPECIFIED_DIRECTION) == SRB_FLAGS_DATA_IN)
|
||||
{
|
||||
PipeHandle = Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle;
|
||||
PipeHandle = FDODeviceExtension->InterfaceInformation->Pipes[FDODeviceExtension->BulkInPipeIndex].PipeHandle;
|
||||
TransferFlags = USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK;
|
||||
}
|
||||
else if ((Request->SrbFlags & SRB_FLAGS_UNSPECIFIED_DIRECTION) == SRB_FLAGS_DATA_OUT)
|
||||
{
|
||||
PipeHandle = Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkOutPipeIndex].PipeHandle;
|
||||
PipeHandle = FDODeviceExtension->InterfaceInformation->Pipes[FDODeviceExtension->BulkOutPipeIndex].PipeHandle;
|
||||
TransferFlags = USBD_TRANSFER_DIRECTION_OUT;
|
||||
}
|
||||
else
|
||||
|
@ -385,7 +383,7 @@ USBSTOR_CBWCompletionRoutine(
|
|||
}
|
||||
|
||||
// if it is not a Sense Request
|
||||
if (Request == Context->FDODeviceExtension->ActiveSrb)
|
||||
if (Request == FDODeviceExtension->ActiveSrb)
|
||||
{
|
||||
if (MmGetMdlVirtualAddress(Irp->MdlAddress) == Request->DataBuffer)
|
||||
{
|
||||
|
@ -420,29 +418,27 @@ USBSTOR_CBWCompletionRoutine(
|
|||
TransferBuffer = Request->DataBuffer;
|
||||
}
|
||||
|
||||
USBSTOR_IssueBulkOrInterruptRequest(Context->FDODeviceExtension,
|
||||
USBSTOR_IssueBulkOrInterruptRequest(FDODeviceExtension,
|
||||
Irp,
|
||||
PipeHandle,
|
||||
TransferFlags,
|
||||
Request->DataTransferLength,
|
||||
TransferBuffer,
|
||||
Mdl,
|
||||
USBSTOR_DataCompletionRoutine,
|
||||
Context);
|
||||
USBSTOR_DataCompletionRoutine);
|
||||
|
||||
return STATUS_MORE_PROCESSING_REQUIRED;
|
||||
|
||||
ResetRecovery:
|
||||
Request = Context->FDODeviceExtension->ActiveSrb;
|
||||
Request = FDODeviceExtension->ActiveSrb;
|
||||
IoStack->Parameters.Scsi.Srb = Request;
|
||||
Irp->IoStatus.Information = 0;
|
||||
Irp->IoStatus.Status = STATUS_IO_DEVICE_ERROR;
|
||||
Request->SrbStatus = SRB_STATUS_BUS_RESET;
|
||||
|
||||
USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp);
|
||||
USBSTOR_QueueResetDevice(Context->FDODeviceExtension);
|
||||
USBSTOR_QueueResetDevice(FDODeviceExtension);
|
||||
|
||||
ExFreePoolWithTag(Context, USB_STOR_TAG);
|
||||
return STATUS_CONTINUE_COMPLETION;
|
||||
}
|
||||
|
||||
|
@ -461,12 +457,12 @@ static
|
|||
NTSTATUS
|
||||
USBSTOR_SendCBWRequest(
|
||||
IN PFDO_DEVICE_EXTENSION FDODeviceExtension,
|
||||
IN PIRP Irp,
|
||||
IN PIRP_CONTEXT Context)
|
||||
IN PIRP Irp)
|
||||
{
|
||||
PPDO_DEVICE_EXTENSION PDODeviceExtension;
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
PSCSI_REQUEST_BLOCK Request;
|
||||
PIRP_CONTEXT Context = &FDODeviceExtension->CurrentIrpContext;
|
||||
|
||||
RtlZeroMemory(&Context->cbw, sizeof(CBW));
|
||||
RtlZeroMemory(&Context->Urb, sizeof(URB));
|
||||
|
@ -475,8 +471,9 @@ USBSTOR_SendCBWRequest(
|
|||
PDODeviceExtension = IoStack->DeviceObject->DeviceExtension;
|
||||
Request = IoStack->Parameters.Scsi.Srb;
|
||||
|
||||
// Make a CBW structure from SCSI request block
|
||||
Context->cbw.Signature = CBW_SIGNATURE;
|
||||
Context->cbw.Tag = PtrToUlong(&Context->cbw);
|
||||
Context->cbw.Tag = PtrToUlong(Irp);
|
||||
Context->cbw.DataTransferLength = Request->DataTransferLength;
|
||||
Context->cbw.Flags = ((UCHAR)Request->SrbFlags & SRB_FLAGS_UNSPECIFIED_DIRECTION) << 1;
|
||||
Context->cbw.LUN = PDODeviceExtension->LUN;
|
||||
|
@ -489,7 +486,6 @@ USBSTOR_SendCBWRequest(
|
|||
|
||||
// initialize rest of context
|
||||
Context->Irp = Irp;
|
||||
Context->FDODeviceExtension = FDODeviceExtension;
|
||||
Context->StallRetryCount = 0;
|
||||
|
||||
return USBSTOR_IssueBulkOrInterruptRequest(
|
||||
|
@ -500,16 +496,14 @@ USBSTOR_SendCBWRequest(
|
|||
sizeof(CBW),
|
||||
&Context->cbw,
|
||||
NULL,
|
||||
USBSTOR_CBWCompletionRoutine,
|
||||
Context);
|
||||
USBSTOR_CBWCompletionRoutine);
|
||||
}
|
||||
|
||||
static
|
||||
NTSTATUS
|
||||
USBSTOR_IssueRequestSense(
|
||||
IN PFDO_DEVICE_EXTENSION FDODeviceExtension,
|
||||
IN PIRP Irp,
|
||||
IN PIRP_CONTEXT Context)
|
||||
IN PIRP Irp)
|
||||
{
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
PSCSI_REQUEST_BLOCK CurrentSrb;
|
||||
|
@ -518,7 +512,7 @@ USBSTOR_IssueRequestSense(
|
|||
DPRINT("USBSTOR_IssueRequestSense: \n");
|
||||
|
||||
CurrentSrb = FDODeviceExtension->ActiveSrb;
|
||||
SenseSrb = &Context->SenseSrb;
|
||||
SenseSrb = &FDODeviceExtension->CurrentIrpContext.SenseSrb;
|
||||
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
||||
IoStack->Parameters.Scsi.Srb = SenseSrb;
|
||||
|
||||
|
@ -541,7 +535,7 @@ USBSTOR_IssueRequestSense(
|
|||
SrbGetCdb(SenseSrb)->CDB6GENERIC.OperationCode = SCSIOP_REQUEST_SENSE;
|
||||
SrbGetCdb(SenseSrb)->AsByte[4] = CurrentSrb->SenseInfoBufferLength;
|
||||
|
||||
return USBSTOR_SendCBWRequest(FDODeviceExtension, Irp, Context);
|
||||
return USBSTOR_SendCBWRequest(FDODeviceExtension, Irp);
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
|
@ -549,13 +543,10 @@ USBSTOR_HandleExecuteSCSI(
|
|||
IN PDEVICE_OBJECT DeviceObject,
|
||||
IN PIRP Irp)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
PSCSI_REQUEST_BLOCK Request;
|
||||
PPDO_DEVICE_EXTENSION PDODeviceExtension;
|
||||
PIRP_CONTEXT Context;
|
||||
PPDO_DEVICE_EXTENSION PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
||||
|
||||
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
||||
ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
|
||||
|
||||
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
||||
|
@ -564,17 +555,7 @@ USBSTOR_HandleExecuteSCSI(
|
|||
DPRINT("USBSTOR_HandleExecuteSCSI Operation Code %x, Length %lu\n", SrbGetCdb(Request)->CDB10.OperationCode, Request->DataTransferLength);
|
||||
|
||||
// check that we're sending to the right LUN
|
||||
ASSERT(SrbGetCdb(Request)->CDB10.LogicalUnitNumber == (PDODeviceExtension->LUN & MAX_LUN));
|
||||
Context = ExAllocatePoolWithTag(NonPagedPool, sizeof(IRP_CONTEXT), USB_STOR_TAG);
|
||||
ASSERT(SrbGetCdb(Request)->CDB10.LogicalUnitNumber == PDODeviceExtension->LUN);
|
||||
|
||||
if (!Context)
|
||||
{
|
||||
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = USBSTOR_SendCBWRequest(PDODeviceExtension->LowerDeviceObject->DeviceExtension, Irp, Context);
|
||||
}
|
||||
|
||||
return Status;
|
||||
return USBSTOR_SendCBWRequest(PDODeviceExtension->LowerDeviceObject->DeviceExtension, Irp);
|
||||
}
|
||||
|
|
|
@ -61,6 +61,52 @@
|
|||
#define MAX_LUN 0xF
|
||||
#define USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH 0x10000
|
||||
|
||||
#define CBW_SIGNATURE 0x43425355
|
||||
#define CSW_SIGNATURE 0x53425355
|
||||
|
||||
#include <pshpack1.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ULONG Signature; // CBW signature
|
||||
ULONG Tag; // CBW Tag of operation
|
||||
ULONG DataTransferLength; // data transfer length
|
||||
UCHAR Flags; // CBW Flags endpoint direction
|
||||
UCHAR LUN; // lun unit
|
||||
UCHAR CommandBlockLength; // Command block length
|
||||
UCHAR CommandBlock[16];
|
||||
} CBW, *PCBW;
|
||||
|
||||
C_ASSERT(sizeof(CBW) == 31);
|
||||
|
||||
#define CSW_STATUS_COMMAND_PASSED 0x00
|
||||
#define CSW_STATUS_COMMAND_FAILED 0x01
|
||||
#define CSW_STATUS_PHASE_ERROR 0x02
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ULONG Signature; // CSW signature
|
||||
ULONG Tag; // CSW tag
|
||||
ULONG DataResidue; // CSW data transfer diff
|
||||
UCHAR Status; // CSW status
|
||||
} CSW, *PCSW;
|
||||
|
||||
#include <poppack.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PIRP Irp;
|
||||
ULONG ErrorIndex;
|
||||
ULONG StallRetryCount; // the number of retries after receiving USBD_STATUS_STALL_PID status
|
||||
union
|
||||
{
|
||||
CBW cbw;
|
||||
CSW csw;
|
||||
};
|
||||
URB Urb;
|
||||
SCSI_REQUEST_BLOCK SenseSrb;
|
||||
} IRP_CONTEXT, *PIRP_CONTEXT;
|
||||
|
||||
typedef struct __COMMON_DEVICE_EXTENSION__
|
||||
{
|
||||
BOOLEAN IsFDO;
|
||||
|
@ -99,6 +145,7 @@ typedef struct
|
|||
KSPIN_LOCK CommonLock;
|
||||
PIO_WORKITEM ResetDeviceWorkItem;
|
||||
ULONG Flags;
|
||||
IRP_CONTEXT CurrentIrpContext;
|
||||
}FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION;
|
||||
|
||||
typedef struct
|
||||
|
@ -108,57 +155,12 @@ typedef struct
|
|||
UCHAR LUN; // lun id
|
||||
BOOLEAN Claimed; // indicating if it has been claimed by upper driver
|
||||
PDEVICE_OBJECT LowerDeviceObject; // points to FDO
|
||||
PINQUIRYDATA InquiryData; // USB SCSI inquiry data
|
||||
PDEVICE_OBJECT *PDODeviceObject; // entry in pdo list
|
||||
PDEVICE_OBJECT Self; // self
|
||||
// the whole structure is not stored
|
||||
UCHAR InquiryData[INQUIRYDATABUFFERSIZE]; // USB SCSI inquiry data
|
||||
}PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
|
||||
|
||||
#define CBW_SIGNATURE 0x43425355
|
||||
#define CSW_SIGNATURE 0x53425355
|
||||
|
||||
#include <pshpack1.h>
|
||||
typedef struct
|
||||
{
|
||||
ULONG Signature; // CBW signature
|
||||
ULONG Tag; // CBW Tag of operation
|
||||
ULONG DataTransferLength; // data transfer length
|
||||
UCHAR Flags; // CBW Flags endpoint direction
|
||||
UCHAR LUN; // lun unit
|
||||
UCHAR CommandBlockLength; // Command block length
|
||||
UCHAR CommandBlock[16];
|
||||
}CBW, *PCBW;
|
||||
|
||||
C_ASSERT(sizeof(CBW) == 31);
|
||||
|
||||
#define CSW_STATUS_COMMAND_PASSED 0x00
|
||||
#define CSW_STATUS_COMMAND_FAILED 0x01
|
||||
#define CSW_STATUS_PHASE_ERROR 0x02
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ULONG Signature; // CSW signature
|
||||
ULONG Tag; // CSW tag
|
||||
ULONG DataResidue; // CSW data transfer diff
|
||||
UCHAR Status; // CSW status
|
||||
}CSW, *PCSW;
|
||||
|
||||
#include <poppack.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PIRP Irp;
|
||||
PFDO_DEVICE_EXTENSION FDODeviceExtension;
|
||||
ULONG ErrorIndex;
|
||||
ULONG StallRetryCount; // the number of retries after receiving USBD_STATUS_STALL_PID status
|
||||
union
|
||||
{
|
||||
CBW cbw;
|
||||
CSW csw;
|
||||
};
|
||||
URB Urb;
|
||||
SCSI_REQUEST_BLOCK SenseSrb;
|
||||
} IRP_CONTEXT, *PIRP_CONTEXT;
|
||||
|
||||
typedef struct _ERRORHANDLER_WORKITEM_DATA
|
||||
{
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
|
@ -267,7 +269,7 @@ USBSTOR_HandleExecuteSCSI(
|
|||
|
||||
NTSTATUS
|
||||
USBSTOR_SendCSWRequest(
|
||||
PIRP_CONTEXT Context,
|
||||
PFDO_DEVICE_EXTENSION FDODeviceExtension,
|
||||
PIRP Irp);
|
||||
|
||||
|
||||
|
@ -351,8 +353,7 @@ USBSTOR_TimerRoutine(
|
|||
VOID
|
||||
NTAPI
|
||||
USBSTOR_QueueResetPipe(
|
||||
IN PFDO_DEVICE_EXTENSION FDODeviceExtension,
|
||||
IN PIRP_CONTEXT Context);
|
||||
IN PFDO_DEVICE_EXTENSION FDODeviceExtension);
|
||||
|
||||
VOID
|
||||
NTAPI
|
||||
|
|
Loading…
Reference in a new issue