From 45f27e8b8c402c1f0bd6bd31301e9447f7a3ccb3 Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Sun, 8 May 2011 19:33:41 +0000 Subject: [PATCH] [USBEHCI_NEW] - Fix retrieving drive capacity - Fix ufi command structures svn path=/branches/usb-bringup/; revision=51649 --- drivers/usb/usbstor/disk.c | 2 +- drivers/usb/usbstor/scsi.c | 45 +++++++++++++++++++++++------ drivers/usb/usbstor/usbstor.h | 54 +++++++++++++++++++++++++++++++++-- 3 files changed, 89 insertions(+), 12 deletions(-) diff --git a/drivers/usb/usbstor/disk.c b/drivers/usb/usbstor/disk.c index f185385fdcf..4384c4fc591 100644 --- a/drivers/usb/usbstor/disk.c +++ b/drivers/usb/usbstor/disk.c @@ -97,7 +97,7 @@ USBSTOR_HandleExecuteSCSI( else { // - // failed to retrieve capacity + // failed to retrieve sense data // Irp->IoStatus.Information = 0; Request->SrbStatus = SRB_STATUS_ERROR; diff --git a/drivers/usb/usbstor/scsi.c b/drivers/usb/usbstor/scsi.c index 9706c138915..8b97c514ac3 100644 --- a/drivers/usb/usbstor/scsi.c +++ b/drivers/usb/usbstor/scsi.c @@ -410,7 +410,7 @@ USBSTOR_SendCapacityCmd( OUT PREAD_CAPACITY_DATA_EX CapacityDataEx, OUT PREAD_CAPACITY_DATA CapacityData) { - UFI_INQUIRY_CMD Cmd; + UFI_CAPACITY_CMD Cmd; CSW CSW; NTSTATUS Status; PUFI_CAPACITY_RESPONSE Response; @@ -438,9 +438,8 @@ USBSTOR_SendCapacityCmd( // initialize capacity cmd // RtlZeroMemory(&Cmd, sizeof(UFI_INQUIRY_CMD)); - Cmd.Code = SCSIOP_INQUIRY; + Cmd.Code = SCSIOP_READ_CAPACITY; Cmd.LUN = (PDODeviceExtension->LUN & MAX_LUN); - Cmd.AllocationLength = sizeof(UFI_INQUIRY_RESPONSE); // // now send capacity cmd @@ -472,9 +471,9 @@ USBSTOR_SendCapacityCmd( return Status; } - DPRINT1("LastLogicalBlockAddress %lu\n", Response->LastLogicalBlockAddress); - DPRINT1("BlockLength %lu\n", Response->BlockLength); - DPRINT1("Medium Length %lu\n", Response->BlockLength * Response->LastLogicalBlockAddress); + DPRINT1("LastLogicalBlockAddress %lu\n", NTOHL(Response->LastLogicalBlockAddress)); + DPRINT1("BlockLength %lu\n", NTOHL(Response->BlockLength)); + DPRINT1("Medium Length %lu\n", NTOHL(Response->BlockLength) * NTOHL(Response->LastLogicalBlockAddress)); // // store response @@ -536,6 +535,7 @@ USBSTOR_SendModeSenseCmd( PPDO_DEVICE_EXTENSION PDODeviceExtension; PCBW OutControl; PCDB pCDB; + PUFI_MODE_PARAMETER_HEADER Header; // // get SCSI command data block @@ -559,6 +559,18 @@ USBSTOR_SendModeSenseCmd( return STATUS_INSUFFICIENT_RESOURCES; } + // + // sanity check + // + + + // Supported pages + // MODE_PAGE_ERROR_RECOVERY + // MODE_PAGE_FLEXIBILE + // MODE_PAGE_LUN_MAPPING + // MODE_PAGE_FAULT_REPORTING + // MODE_SENSE_RETURN_ALL + // // initialize mode sense cmd // @@ -567,12 +579,15 @@ USBSTOR_SendModeSenseCmd( Cmd.LUN = (PDODeviceExtension->LUN & MAX_LUN); Cmd.PageCode = pCDB->MODE_SENSE.PageCode; Cmd.PC = pCDB->MODE_SENSE.Pc; - Cmd.AllocationLength = pCDB->MODE_SENSE.AllocationLength; + Cmd.AllocationLength = HTONS(pCDB->MODE_SENSE.AllocationLength); + + DPRINT1("PageCode %x\n", pCDB->MODE_SENSE.PageCode); + DPRINT1("PC %x\n", pCDB->MODE_SENSE.Pc); // // now send mode sense cmd // - Status = USBSTOR_SendCBW(DeviceObject, UFI_CAPACITY_CMD_LEN, (PUCHAR)&Cmd, Request->DataTransferLength, &OutControl); + Status = USBSTOR_SendCBW(DeviceObject, UFI_SENSE_CMD_LEN, (PUCHAR)&Cmd, Request->DataTransferLength, &OutControl); if (!NT_SUCCESS(Status)) { // @@ -599,6 +614,20 @@ USBSTOR_SendModeSenseCmd( return Status; } + Header = (PUFI_MODE_PARAMETER_HEADER)Response; + + // + // TODO: build layout + // + // first struct is the header + // MODE_PARAMETER_HEADER / _MODE_PARAMETER_HEADER10 + // + // followed by + // MODE_PARAMETER_BLOCK + // + // + DbgBreakPoint(); + // // send csw // diff --git a/drivers/usb/usbstor/usbstor.h b/drivers/usb/usbstor/usbstor.h index 78a8e8a51a8..a897a45f00b 100644 --- a/drivers/usb/usbstor/usbstor.h +++ b/drivers/usb/usbstor/usbstor.h @@ -63,7 +63,7 @@ typedef struct // #define USB_BULK_GET_MAX_LUN 0xFE - +#include typedef struct { ULONG Signature; // CBW signature @@ -75,6 +75,9 @@ typedef struct UCHAR CommandBlock[16]; }CBW, *PCBW; +C_ASSERT(sizeof(CBW) == 31); + + #define CBW_SIGNATURE 0x43425355 #define MAX_LUN 0xF @@ -114,7 +117,7 @@ typedef struct UCHAR Version; // contains version 0x00 UCHAR Format; // response format UCHAR Length; // additional length - USHORT Reserved; // reserved + UCHAR Reserved[3]; // reserved UCHAR Vendor[8]; // vendor identification string UCHAR Product[16]; // product identification string UCHAR Revision[4]; // product revision code @@ -149,6 +152,24 @@ typedef struct ULONG BlockLength; // block length in bytes }UFI_CAPACITY_RESPONSE, *PUFI_CAPACITY_RESPONSE; +C_ASSERT(sizeof(UFI_CAPACITY_RESPONSE) == 8); + +#define HTONS(n) (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8)) +#define NTOHS(n) (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8)) + +#define HTONL(n) (((((unsigned long)(n) & 0xFF)) << 24) | \ + ((((unsigned long)(n) & 0xFF00)) << 8) | \ + ((((unsigned long)(n) & 0xFF0000)) >> 8) | \ + ((((unsigned long)(n) & 0xFF000000)) >> 24)) + + +#define NTOHL(n) (((((unsigned long)(n) & 0xFF)) << 24) | \ + ((((unsigned long)(n) & 0xFF00)) << 8) | \ + ((((unsigned long)(n) & 0xFF0000)) >> 8) | \ + ((((unsigned long)(n) & 0xFF000000)) >> 24)) + + + //-------------------------------------------------------------------------------------------------------------------------------------------- // // UFI sense mode cmd @@ -164,7 +185,34 @@ typedef struct UCHAR Reserved1[3]; }UFI_SENSE_CMD, *PUFI_SENSE_CMD; -C_ASSERT(sizeof(UFI_CAPACITY_CMD) == 12); +C_ASSERT(sizeof(UFI_SENSE_CMD) == 12); + +#define UFI_SENSE_CMD_LEN (6) + +typedef struct +{ + USHORT ModeDataLength; // length of parameters for sense cmd + UCHAR MediumTypeCode; // 00 for mass storage, 0x94 for floppy + UCHAR WP:1; // write protect bit + UCHAR Reserved1:2; // reserved 00 + UCHAR DPOFUA:1; // should be zero + UCHAR Reserved2:4; // reserved + UCHAR Reserved[4]; // reserved +}UFI_MODE_PARAMETER_HEADER, *PUFI_MODE_PARAMETER_HEADER; + + +C_ASSERT(sizeof(UFI_MODE_PARAMETER_HEADER) == 8); + +typedef struct +{ + UCHAR PC; + UCHAR PageLength; + UCHAR Reserved1; + UCHAR ITM; + UCHAR Flags; + UCHAR Reserved[3]; +}UFI_TIMER_PROTECT_PAGE, *PUFI_TIMER_PROTECT_PAGE; +C_ASSERT(sizeof(UFI_TIMER_PROTECT_PAGE) == 8); //--------------------------------------------------------------------- //