hrev47616 adds 2 changesets to branch 'master' old head: 22ea661b82e5e8921d1f65114fb0d8c07296aedc new head: 92d556084ca7f0e9472976a35aff6a21acf12fda overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=92d5560+%5E22ea661 ---------------------------------------------------------------------------- d9ecf5f: usb_disk: extract specs into a public header. 92d5560: USB_massbulk.h: use a proper naming for a public header. [ Jérôme Duval <jerome.duval@xxxxxxxxx> ] ---------------------------------------------------------------------------- 3 files changed, 76 insertions(+), 49 deletions(-) headers/os/drivers/usb/USB_massbulk.h | 48 ++++++++++++++++++++ .../drivers/disk/usb/usb_disk/usb_disk.cpp | 44 ++++++++++-------- .../kernel/drivers/disk/usb/usb_disk/usb_disk.h | 33 ++------------ ############################################################################ Commit: d9ecf5f373dab3ddaf7579c0b725705c7178d4b0 URL: http://cgit.haiku-os.org/haiku/commit/?id=d9ecf5f Author: Jérôme Duval <jerome.duval@xxxxxxxxx> Date: Thu Jul 31 20:43:48 2014 UTC usb_disk: extract specs into a public header. ---------------------------------------------------------------------------- diff --git a/headers/os/drivers/usb/USB_massbulk.h b/headers/os/drivers/usb/USB_massbulk.h new file mode 100644 index 0000000..e16632a --- /dev/null +++ b/headers/os/drivers/usb/USB_massbulk.h @@ -0,0 +1,48 @@ +/* + * Copyright 2014, Haiku Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _USB_MSC_H +#define _USB_MSC_H + + +// (Partial) USB Class Definitions for Mass Storage Devices (MSC), version 1.0 +// Reference: http://www.usb.org/developers/devclass_docs/usbmassbulk_10.pdf + + +#define USB_MASS_STORAGE_DEVICE_CLASS 0x08 + +#define CBW_SIGNATURE 0x43425355 +#define CBW_DATA_OUTPUT 0x00 +#define CBW_DATA_INPUT 0x80 + +#define CSW_SIGNATURE 0x53425355 +#define CSW_STATUS_COMMAND_PASSED 0x00 +#define CSW_STATUS_COMMAND_FAILED 0x01 +#define CSW_STATUS_PHASE_ERROR 0x02 + +#define REQUEST_MASS_STORAGE_RESET 0xff +#define REQUEST_GET_MAX_LUN 0xfe + + +typedef struct { + uint32 signature; + uint32 tag; + uint32 data_transfer_length; + uint8 flags; + uint8 lun; + uint8 command_block_length; + uint8 command_block[16]; +} _PACKED command_block_wrapper; + + +typedef struct { + uint32 signature; + uint32 tag; + uint32 data_residue; + uint8 status; +} _PACKED command_status_wrapper; + + +#endif + diff --git a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp index 0c0a7e4..d5613d1 100644 --- a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp +++ b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp @@ -709,7 +709,7 @@ usb_disk_device_added(usb_device newDevice, void **cookie) if (interface == NULL) continue; - if (interface->descr->interface_class == 0x08 /* mass storage */ + if (interface->descr->interface_class == USB_MASS_STORAGE_DEVICE_CLASS && (interface->descr->interface_subclass == 0x06 /* SCSI */ || interface->descr->interface_subclass == 0x02 /* ATAPI */ || interface->descr->interface_subclass == 0x05 /* ATAPI */) diff --git a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.h b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.h index 143a535..85b2bf9 100644 --- a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.h +++ b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.h @@ -5,27 +5,18 @@ * Authors: * Michael Lotz <mmlr@xxxxxxxx> */ - #ifndef _USB_DISK_H_ #define _USB_DISK_H_ + #include <lock.h> #include <USB3.h> +#include <usb/USB_massbulk.h> + -#define REQUEST_MASS_STORAGE_RESET 0xff -#define REQUEST_GET_MAX_LUN 0xfe #define MAX_LOGICAL_UNIT_NUMBER 15 #define ATAPI_COMMAND_LENGTH 12 -#define CBW_SIGNATURE 0x43425355 -#define CBW_DATA_OUTPUT 0x00 -#define CBW_DATA_INPUT 0x80 - -#define CSW_SIGNATURE 0x53425355 -#define CSW_STATUS_COMMAND_PASSED 0x00 -#define CSW_STATUS_COMMAND_FAILED 0x01 -#define CSW_STATUS_PHASE_ERROR 0x02 - #define SYNC_SUPPORT_RELOAD 5 typedef struct device_lun_s device_lun; @@ -81,22 +72,4 @@ struct device_lun_s { }; -typedef struct command_block_wrapper_s { - uint32 signature; - uint32 tag; - uint32 data_transfer_length; - uint8 flags; - uint8 lun; - uint8 command_block_length; - uint8 command_block[16]; -} _PACKED command_block_wrapper; - - -typedef struct command_status_wrapper_s { - uint32 signature; - uint32 tag; - uint32 data_residue; - uint8 status; -} _PACKED command_status_wrapper; - #endif // _USB_DISK_H_ ############################################################################ Revision: hrev47616 Commit: 92d556084ca7f0e9472976a35aff6a21acf12fda URL: http://cgit.haiku-os.org/haiku/commit/?id=92d5560 Author: Jérôme Duval <jerome.duval@xxxxxxxxx> Date: Sun Aug 3 16:39:35 2014 UTC USB_massbulk.h: use a proper naming for a public header. ---------------------------------------------------------------------------- diff --git a/headers/os/drivers/usb/USB_massbulk.h b/headers/os/drivers/usb/USB_massbulk.h index e16632a..39ef27a 100644 --- a/headers/os/drivers/usb/USB_massbulk.h +++ b/headers/os/drivers/usb/USB_massbulk.h @@ -10,19 +10,19 @@ // Reference: http://www.usb.org/developers/devclass_docs/usbmassbulk_10.pdf -#define USB_MASS_STORAGE_DEVICE_CLASS 0x08 +#define USB_MASS_STORAGE_DEVICE_CLASS 0x08 -#define CBW_SIGNATURE 0x43425355 -#define CBW_DATA_OUTPUT 0x00 -#define CBW_DATA_INPUT 0x80 +#define USB_MASSBULK_CBW_SIGNATURE 0x43425355 +#define USB_MASSBULK_CBW_DATA_OUTPUT 0x00 +#define USB_MASSBULK_CBW_DATA_INPUT 0x80 -#define CSW_SIGNATURE 0x53425355 -#define CSW_STATUS_COMMAND_PASSED 0x00 -#define CSW_STATUS_COMMAND_FAILED 0x01 -#define CSW_STATUS_PHASE_ERROR 0x02 +#define USB_MASSBULK_CSW_SIGNATURE 0x53425355 +#define USB_MASSBULK_CSW_STATUS_COMMAND_PASSED 0x00 +#define USB_MASSBULK_CSW_STATUS_COMMAND_FAILED 0x01 +#define USB_MASSBULK_CSW_STATUS_PHASE_ERROR 0x02 -#define REQUEST_MASS_STORAGE_RESET 0xff -#define REQUEST_GET_MAX_LUN 0xfe +#define USB_MASSBULK_REQUEST_MASS_STORAGE_RESET 0xff +#define USB_MASSBULK_REQUEST_GET_MAX_LUN 0xfe typedef struct { @@ -33,7 +33,7 @@ typedef struct { uint8 lun; uint8 command_block_length; uint8 command_block[16]; -} _PACKED command_block_wrapper; +} _PACKED usb_massbulk_command_block_wrapper; typedef struct { @@ -41,7 +41,7 @@ typedef struct { uint32 tag; uint32 data_residue; uint8 status; -} _PACKED command_status_wrapper; +} _PACKED usb_massbulk_command_status_wrapper; #endif diff --git a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp index d5613d1..093ad2a 100644 --- a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp +++ b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp @@ -133,7 +133,7 @@ void usb_disk_reset_recovery(disk_device *device); status_t usb_disk_transfer_data(disk_device *device, bool directionIn, void *data, size_t dataLength); status_t usb_disk_receive_csw(disk_device *device, - command_status_wrapper *status); + usb_massbulk_command_status_wrapper *status); status_t usb_disk_operation(device_lun *lun, uint8 operation, uint8 opLength, uint32 logicalBlockAddress, uint16 transferLength, void *data, size_t *dataLength, @@ -175,7 +175,7 @@ status_t usb_disk_mass_storage_reset(disk_device *device) { return gUSBModule->send_request(device->device, USB_REQTYPE_INTERFACE_OUT - | USB_REQTYPE_CLASS, REQUEST_MASS_STORAGE_RESET, 0x0000, + | USB_REQTYPE_CLASS, USB_MASSBULK_REQUEST_MASS_STORAGE_RESET, 0x0000, device->interface, 0, NULL, NULL); } @@ -188,9 +188,11 @@ usb_disk_get_max_lun(disk_device *device) // devices that do not support multiple LUNs may stall this request if (gUSBModule->send_request(device->device, USB_REQTYPE_INTERFACE_IN - | USB_REQTYPE_CLASS, REQUEST_GET_MAX_LUN, 0x0000, device->interface, - 1, &result, &actualLength) != B_OK || actualLength != 1) + | USB_REQTYPE_CLASS, USB_MASSBULK_REQUEST_GET_MAX_LUN, 0x0000, + device->interface, 1, &result, &actualLength) != B_OK + || actualLength != 1) { return 0; + } if (result > MAX_LOGICAL_UNIT_NUMBER) { // invalid max lun @@ -246,15 +248,17 @@ usb_disk_transfer_data(disk_device *device, bool directionIn, void *data, status_t -usb_disk_receive_csw(disk_device *device, command_status_wrapper *status) +usb_disk_receive_csw(disk_device *device, + usb_massbulk_command_status_wrapper *status) { status_t result = usb_disk_transfer_data(device, true, status, - sizeof(command_status_wrapper)); + sizeof(usb_massbulk_command_status_wrapper)); if (result != B_OK) return result; if (device->status != B_OK - || device->actual_length != sizeof(command_status_wrapper)) { + || device->actual_length + != sizeof(usb_massbulk_command_status_wrapper)) { // receiving the command status wrapper failed return B_ERROR; } @@ -275,11 +279,12 @@ usb_disk_operation(device_lun *lun, uint8 operation, uint8 opLength, directionIn ? 'y' : 'n'); disk_device *device = lun->device; - command_block_wrapper command; - command.signature = CBW_SIGNATURE; + usb_massbulk_command_block_wrapper command; + command.signature = USB_MASSBULK_CBW_SIGNATURE; command.tag = device->current_tag++; command.data_transfer_length = (dataLength != NULL ? *dataLength : 0); - command.flags = (directionIn ? CBW_DATA_INPUT : CBW_DATA_OUTPUT); + command.flags = (directionIn ? USB_MASSBULK_CBW_DATA_INPUT + : USB_MASSBULK_CBW_DATA_OUTPUT); command.lun = lun->logical_unit_number; command.command_block_length = device->is_atapi ? ATAPI_COMMAND_LENGTH : opLength; @@ -317,12 +322,12 @@ usb_disk_operation(device_lun *lun, uint8 operation, uint8 opLength, } status_t result = usb_disk_transfer_data(device, false, &command, - sizeof(command_block_wrapper)); + sizeof(usb_massbulk_command_block_wrapper)); if (result != B_OK) return result; if (device->status != B_OK || - device->actual_length != sizeof(command_block_wrapper)) { + device->actual_length != sizeof(usb_massbulk_command_block_wrapper)) { // sending the command block wrapper failed TRACE_ALWAYS("sending the command block wrapper failed: %s\n", strerror(device->status)); @@ -354,7 +359,7 @@ usb_disk_operation(device_lun *lun, uint8 operation, uint8 opLength, } } - command_status_wrapper status; + usb_massbulk_command_status_wrapper status; result = usb_disk_receive_csw(device, &status); if (result != B_OK) { // in case of a stall or error clear the stall and try again @@ -369,7 +374,8 @@ usb_disk_operation(device_lun *lun, uint8 operation, uint8 opLength, return result; } - if (status.signature != CSW_SIGNATURE || status.tag != command.tag) { + if (status.signature != USB_MASSBULK_CSW_SIGNATURE + || status.tag != command.tag) { // the command status wrapper is not valid TRACE_ALWAYS("command status wrapper is not valid: %#" B_PRIx32 "\n", status.signature); @@ -378,8 +384,8 @@ usb_disk_operation(device_lun *lun, uint8 operation, uint8 opLength, } switch (status.status) { - case CSW_STATUS_COMMAND_PASSED: - case CSW_STATUS_COMMAND_FAILED: + case USB_MASSBULK_CSW_STATUS_COMMAND_PASSED: + case USB_MASSBULK_CSW_STATUS_COMMAND_FAILED: { // The residue from "status.data_residue" is not maintained // correctly by some devices, so calculate it instead. @@ -395,7 +401,7 @@ usb_disk_operation(device_lun *lun, uint8 operation, uint8 opLength, } } - if (status.status == CSW_STATUS_COMMAND_PASSED) { + if (status.status == USB_MASSBULK_CSW_STATUS_COMMAND_PASSED) { // the operation is complete and has succeeded return B_OK; } else { @@ -413,7 +419,7 @@ usb_disk_operation(device_lun *lun, uint8 operation, uint8 opLength, } } - case CSW_STATUS_PHASE_ERROR: + case USB_MASSBULK_CSW_STATUS_PHASE_ERROR: { // a protocol or device error occured TRACE_ALWAYS("phase error in operation %#" B_PRIx8 "\n", operation);