From 3f8c058a07e7dd2c3287cdf9a541bbc2da260373 Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Fri, 13 May 2011 14:44:24 +0000 Subject: [PATCH] [USBSTOR] - Start implementing write command - Disabled for now as it causes corruptions svn path=/branches/usb-bringup/; revision=51695 --- drivers/usb/usbstor/disk.c | 8 +++---- drivers/usb/usbstor/scsi.c | 42 ++++++++++++++++++++++++++++------- drivers/usb/usbstor/usbstor.h | 8 +++---- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/drivers/usb/usbstor/disk.c b/drivers/usb/usbstor/disk.c index 9eafb7bedfd..099c0e1780a 100644 --- a/drivers/usb/usbstor/disk.c +++ b/drivers/usb/usbstor/disk.c @@ -50,14 +50,14 @@ USBSTOR_HandleExecuteSCSI( // Status = USBSTOR_SendModeSenseCmd(DeviceObject, Irp); } - else if (pCDB->MODE_SENSE.OperationCode == SCSIOP_READ) + else if (pCDB->MODE_SENSE.OperationCode == SCSIOP_READ /*|| pCDB->MODE_SENSE.OperationCode == SCSIOP_WRITE*/) { - DPRINT1("SCSIOP_READ DataTransferLength %lu\n", Request->DataTransferLength); + DPRINT1("SCSIOP_READ / SCSIOP_WRITE DataTransferLength %lu\n", Request->DataTransferLength); // - // send read command + // send read / write command // - Status = USBSTOR_SendReadCmd(DeviceObject, Irp); + Status = USBSTOR_SendReadWriteCmd(DeviceObject, Irp); } else if (pCDB->AsByte[0] == SCSIOP_MEDIUM_REMOVAL) { diff --git a/drivers/usb/usbstor/scsi.c b/drivers/usb/usbstor/scsi.c index fb0d44323ee..cb39572b62d 100644 --- a/drivers/usb/usbstor/scsi.c +++ b/drivers/usb/usbstor/scsi.c @@ -332,6 +332,8 @@ USBSTOR_CBWCompletionRoutine( { PIRP_CONTEXT Context; PIO_STACK_LOCATION IoStack; + UCHAR Code; + USBD_PIPE_HANDLE PipeHandle; DPRINT1("USBSTOR_CBWCompletionRoutine Irp %p Ctx %p\n", Irp, Ctx); @@ -350,13 +352,32 @@ USBSTOR_CBWCompletionRoutine( // if (Context->TransferDataLength) { + // + // get command code + // + Code = Context->cbw->CommandBlock[0]; + + if (Code == SCSIOP_WRITE) + { + // + // write request use bulk out pipe + // + PipeHandle = Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkOutPipeIndex].PipeHandle; + } + else + { + // + // default bulk in pipe + // + PipeHandle = Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle; + } + // // now initialize the urb for sending data // - UsbBuildInterruptOrBulkTransferRequest(&Context->Urb, sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER), - Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle, + PipeHandle, NULL, Context->TransferBufferMDL, Context->TransferDataLength, @@ -871,11 +892,11 @@ USBSTOR_SendModeSenseCmd( } NTSTATUS -USBSTOR_SendReadCmd( +USBSTOR_SendReadWriteCmd( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { - UFI_READ_CMD Cmd; + UFI_READ_WRITE_CMD Cmd; NTSTATUS Status; PPDO_DEVICE_EXTENSION PDODeviceExtension; PCDB pCDB; @@ -907,7 +928,12 @@ USBSTOR_SendReadCmd( // // informal debug print // - DPRINT1("USBSTOR_SendReadCmd DataTransferLength %x, BlockLength %x\n", Request->DataTransferLength, PDODeviceExtension->BlockLength); + DPRINT1("USBSTOR_SendReadWriteCmd DataTransferLength %x, BlockLength %x\n", Request->DataTransferLength, PDODeviceExtension->BlockLength); + + // + // sanity check + // + ASSERT(PDODeviceExtension->BlockLength); // // block count @@ -917,8 +943,8 @@ USBSTOR_SendReadCmd( // // initialize read cmd // - RtlZeroMemory(&Cmd, sizeof(UFI_READ_CMD)); - Cmd.Code = SCSIOP_READ; + RtlZeroMemory(&Cmd, sizeof(UFI_READ_WRITE_CMD)); + Cmd.Code = pCDB->AsByte[0]; Cmd.LUN = (PDODeviceExtension->LUN & MAX_LUN); Cmd.ContiguousLogicBlocks = _byteswap_ushort(BlockCount); Cmd.LogicalBlockByte0 = pCDB->CDB10.LogicalBlockByte0; @@ -931,7 +957,7 @@ USBSTOR_SendReadCmd( // // send request // - return USBSTOR_SendRequest(DeviceObject, Irp, NULL, UFI_READ_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.h b/drivers/usb/usbstor/usbstor.h index 7cc6d832948..e8374692b47 100644 --- a/drivers/usb/usbstor/usbstor.h +++ b/drivers/usb/usbstor/usbstor.h @@ -158,11 +158,11 @@ typedef struct UCHAR Reserved; // reserved 0x00 USHORT ContiguousLogicBlocks; // num of contiguous logical blocks UCHAR Reserved1[3]; // reserved 0x00 -}UFI_READ_CMD; +}UFI_READ_WRITE_CMD; -C_ASSERT(sizeof(UFI_READ_CMD) == 12); +C_ASSERT(sizeof(UFI_READ_WRITE_CMD) == 12); -#define UFI_READ_CMD_LEN (0xA) +#define UFI_READ_WRITE_CMD_LEN (0xA) //-------------------------------------------------------------------------------------------------------------------------------------------- // @@ -375,7 +375,7 @@ USBSTOR_SendModeSenseCmd( IN PIRP Irp); NTSTATUS -USBSTOR_SendReadCmd( +USBSTOR_SendReadWriteCmd( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);