Author: janderwald
Date: Tue May 10 23:26:56 2011
New Revision: 51671
URL:
http://svn.reactos.org/svn/reactos?rev=51671&view=rev
Log:
[USBSTOR]
- Partly implement test unit command
Modified:
branches/usb-bringup/drivers/usb/usbstor/disk.c
branches/usb-bringup/drivers/usb/usbstor/scsi.c
branches/usb-bringup/drivers/usb/usbstor/usbstor.h
Modified: branches/usb-bringup/drivers/usb/usbstor/disk.c
URL:
http://svn.reactos.org/svn/reactos/branches/usb-bringup/drivers/usb/usbstor…
==============================================================================
--- branches/usb-bringup/drivers/usb/usbstor/disk.c [iso-8859-1] (original)
+++ branches/usb-bringup/drivers/usb/usbstor/disk.c [iso-8859-1] Tue May 10 23:26:56 2011
@@ -125,13 +125,36 @@
else
{
//
- // failed to retrieve sense data
+ // failed to read
//
Irp->IoStatus.Information = 0;
Request->SrbStatus = SRB_STATUS_ERROR;
}
}
-
+ else if (pCDB->MODE_SENSE.OperationCode == SCSIOP_TEST_UNIT_READY)
+ {
+ DPRINT1("SCSIOP_TEST_UNIT_READY\n");
+
+ //
+ // send test unit command
+ //
+ Status = USBSTOR_SendTestUnitCmd(DeviceObject, Request);
+
+ if (NT_SUCCESS(Status))
+ {
+ //
+ // store returned info length
+ //
+ Request->SrbStatus = SRB_STATUS_SUCCESS;
+ }
+ else
+ {
+ //
+ // test unit command failed
+ //
+ Request->SrbStatus = SRB_STATUS_ERROR;
+ }
+ }
else
{
UNIMPLEMENTED;
@@ -421,7 +444,7 @@
DeviceDescriptor->Size = TotalLength;
DeviceDescriptor->DeviceType = InquiryData->DeviceType;
DeviceDescriptor->DeviceTypeModifier = (InquiryData->RMB & 0x7F);
- DeviceDescriptor->RemovableMedia = FALSE; //FIXME check if floppy
+ DeviceDescriptor->RemovableMedia = TRUE;
DeviceDescriptor->CommandQueueing = FALSE;
DeviceDescriptor->BusType = BusTypeUsb;
DeviceDescriptor->VendorIdOffset = sizeof(STORAGE_DEVICE_DESCRIPTOR) -
sizeof(UCHAR);
Modified: branches/usb-bringup/drivers/usb/usbstor/scsi.c
URL:
http://svn.reactos.org/svn/reactos/branches/usb-bringup/drivers/usb/usbstor…
==============================================================================
--- branches/usb-bringup/drivers/usb/usbstor/scsi.c [iso-8859-1] (original)
+++ branches/usb-bringup/drivers/usb/usbstor/scsi.c [iso-8859-1] Tue May 10 23:26:56 2011
@@ -632,7 +632,7 @@
// MODE_PARAMETER_BLOCK
//
//
- DbgBreakPoint();
+ UNIMPLEMENTED
//
// send csw
@@ -813,3 +813,77 @@
//
return Status;
}
+
+NTSTATUS
+USBSTOR_SendTestUnitCmd(
+ IN PDEVICE_OBJECT DeviceObject,
+ IN OUT PSCSI_REQUEST_BLOCK Request)
+{
+ UFI_TEST_UNIT_CMD Cmd;
+ CSW CSW;
+ NTSTATUS Status;
+ PVOID Response;
+ PPDO_DEVICE_EXTENSION PDODeviceExtension;
+ PCBW OutControl;
+ PCDB pCDB;
+ ULONG BlockCount;
+
+ //
+ // initialize test unit cmd
+ //
+ RtlZeroMemory(&Cmd, sizeof(UFI_TEST_UNIT_CMD));
+ Cmd.Code = SCSIOP_TEST_UNIT_READY;
+ Cmd.LUN = (PDODeviceExtension->LUN & MAX_LUN);
+
+ //
+ // no data should be transferred
+ //
+ ASSERT(Request->DataTransferLength == 0);
+
+ //
+ // now send test unit cmd
+ //
+ Status = USBSTOR_SendCBW(DeviceObject, UFI_TEST_UNIT_CMD_LEN, (PUCHAR)&Cmd, 0,
&OutControl);
+ if (!NT_SUCCESS(Status))
+ {
+ //
+ // failed to send CBW
+ //
+ DPRINT1("USBSTOR_SendReadCmd> USBSTOR_SendCBW failed with %x\n",
Status);
+ FreeItem(Response);
+ ASSERT(FALSE);
+ return Status;
+ }
+
+ //
+ // send csw
+ //
+ Status = USBSTOR_SendCSW(DeviceObject, OutControl, 512, &CSW);
+
+ DPRINT1("------------------------\n");
+ DPRINT1("CSW %p\n", &CSW);
+ DPRINT1("Signature %x\n", CSW.Signature);
+ DPRINT1("Tag %x\n", CSW.Tag);
+ DPRINT1("DataResidue %x\n", CSW.DataResidue);
+ DPRINT1("Status %x\n", CSW.Status);
+
+ //
+ // FIXME: handle error
+ //
+ ASSERT(CSW.Status == 0);
+ ASSERT(CSW.DataResidue == 0);
+
+ //
+ // free item
+ //
+ FreeItem(OutControl);
+
+ //
+ // FIXME: read sense buffer
+ //
+
+ //
+ // done
+ //
+ return Status;
+}
Modified: branches/usb-bringup/drivers/usb/usbstor/usbstor.h
URL:
http://svn.reactos.org/svn/reactos/branches/usb-bringup/drivers/usb/usbstor…
==============================================================================
--- branches/usb-bringup/drivers/usb/usbstor/usbstor.h [iso-8859-1] (original)
+++ branches/usb-bringup/drivers/usb/usbstor/usbstor.h [iso-8859-1] Tue May 10 23:26:56
2011
@@ -19,6 +19,22 @@
#define USB_STOR_TAG 'sbsu'
#define USB_MAXCHILDREN (16)
+
+
+#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))
+
NTSTATUS NTAPI
IoAttachDeviceToDeviceStackSafe(
IN PDEVICE_OBJECT SourceDevice,
@@ -56,6 +72,8 @@
UCHAR LUN;
// lun id
PVOID InquiryData;
// USB SCSI inquiry data
UCHAR Claimed;
// indicating if it has been claimed by upper driver
+ ULONG BlockLength;
// length of block
+ ULONG LastLogicBlockAddress;
// last block address
}PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
//
@@ -127,6 +145,24 @@
//--------------------------------------------------------------------------------------------------------------------------------------------
//
+// UFI read cmd
+//
+typedef struct
+{
+ UCHAR Code; // operation code
+ UCHAR LUN; // lun
+ ULONG LogicalBlockAddress; // logical block
address
+ UCHAR Reserved; // reserved 0x00
+ USHORT ContiguousLogicBlocks; // num of contiguous
logical blocks
+ UCHAR Reserved1[3]; // reserved 0x00
+}UFI_READ_CMD;
+
+C_ASSERT(sizeof(UFI_READ_CMD) == 12);
+
+#define UFI_READ_CMD_LEN (0xA)
+
+//--------------------------------------------------------------------------------------------------------------------------------------------
+//
// UFI read capacity cmd
//
typedef struct
@@ -153,22 +189,6 @@
}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))
-
-
//--------------------------------------------------------------------------------------------------------------------------------------------
//
@@ -214,6 +234,22 @@
}UFI_TIMER_PROTECT_PAGE, *PUFI_TIMER_PROTECT_PAGE;
C_ASSERT(sizeof(UFI_TIMER_PROTECT_PAGE) == 8);
+//--------------------------------------------------------------------------------------------------------------------------------------------
+//
+// UFI test unit command
+//
+
+typedef struct
+{
+ UCHAR Code; // operation code
0x00
+ UCHAR LUN; // lun
+ UCHAR Reserved[10]; // reserved 0x00
+}UFI_TEST_UNIT_CMD, *PUFI_TEST_UNIT_CMD;
+
+C_ASSERT(sizeof(UFI_TEST_UNIT_CMD) == 12);
+
+#define UFI_TEST_UNIT_CMD_LEN (6)
+
//---------------------------------------------------------------------
//
// fdo.c routines
@@ -318,6 +354,18 @@
IN OUT PSCSI_REQUEST_BLOCK Request,
OUT PULONG TransferBufferLength);
+NTSTATUS
+USBSTOR_SendReadCmd(
+ IN PDEVICE_OBJECT DeviceObject,
+ IN OUT PSCSI_REQUEST_BLOCK Request,
+ OUT PULONG TransferBufferLength);
+
+NTSTATUS
+USBSTOR_SendTestUnitCmd(
+ IN PDEVICE_OBJECT DeviceObject,
+ IN OUT PSCSI_REQUEST_BLOCK Request);
+
+
//---------------------------------------------------------------------
//
// disk.c routines