Implemented an initial version of USB mass storage device driver, supporting USB mass storage devices with SCSI interface and BBB protocol. It implements the ATA interface and registers diskovered LUNs with the disk driver.
96 lines
2.9 KiB
C
96 lines
2.9 KiB
C
/*
|
|
* Most of this source has been derived from the Linux and
|
|
* U-Boot USB Mass Storage driver implementations.
|
|
*
|
|
* Adapted for barebox:
|
|
* Copyright (c) 2011, AMK Drives & Controls Ltd.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License as
|
|
* published by the Free Software Foundation; either version 2 of
|
|
* the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
* MA 02111-1307 USA
|
|
*
|
|
*/
|
|
|
|
#ifndef _TRANSPORT_H_
|
|
#define _TRANSPORT_H_
|
|
|
|
#include <scsi.h>
|
|
|
|
/*
|
|
* Bulk only data structures
|
|
*/
|
|
|
|
/* command block wrapper */
|
|
struct bulk_cb_wrap {
|
|
__le32 Signature; /* contains 'USBC' */
|
|
__u32 Tag; /* unique per command id */
|
|
__le32 DataTransferLength; /* size of data */
|
|
__u8 Flags; /* direction in bit 7 */
|
|
__u8 Lun; /* LUN normally 0 */
|
|
__u8 Length; /* of of the CDB */
|
|
__u8 CDB[16]; /* max command */
|
|
};
|
|
|
|
#define US_BULK_CB_WRAP_LEN 31
|
|
#define US_BULK_CB_SIGN 0x43425355 /*spells out USBC */
|
|
#define US_BULK_FLAG_IN (1<<7)
|
|
#define US_BULK_FLAG_OUT (0<<7)
|
|
|
|
/* command status wrapper */
|
|
struct bulk_cs_wrap {
|
|
__le32 Signature; /* should = 'USBS' */
|
|
__u32 Tag; /* same as original command */
|
|
__le32 Residue; /* amount not transferred */
|
|
__u8 Status; /* see below */
|
|
__u8 Filler[18];
|
|
};
|
|
|
|
#define US_BULK_CS_WRAP_LEN 13
|
|
#define US_BULK_CS_SIGN 0x53425355 /* spells out 'USBS' */
|
|
#define US_BULK_STAT_OK 0
|
|
#define US_BULK_STAT_FAIL 1
|
|
#define US_BULK_STAT_PHASE 2
|
|
|
|
/* bulk-only class specific requests */
|
|
#define US_BULK_RESET_REQUEST 0xff
|
|
#define US_BULK_GET_MAX_LUN 0xfe
|
|
|
|
/*
|
|
* usb_stor_bulk_transfer_xxx() return codes, in order of severity
|
|
*/
|
|
|
|
#define USB_STOR_XFER_GOOD 0 /* good transfer */
|
|
#define USB_STOR_XFER_SHORT 1 /* transferred less than expected */
|
|
#define USB_STOR_XFER_STALLED 2 /* endpoint stalled */
|
|
#define USB_STOR_XFER_LONG 3 /* device tried to send too much */
|
|
#define USB_STOR_XFER_ERROR 4 /* transfer died in the middle */
|
|
|
|
/*
|
|
* Transport return codes
|
|
*/
|
|
|
|
#define USB_STOR_TRANSPORT_GOOD 0 /* Transport good, command good */
|
|
#define USB_STOR_TRANSPORT_FAILED 1 /* Transport good, command failed */
|
|
#define USB_STOR_TRANSPORT_NO_SENSE 2 /* Command failed, no auto-sense */
|
|
#define USB_STOR_TRANSPORT_ERROR 3 /* Transport bad (i.e. device dead) */
|
|
|
|
|
|
struct us_data;
|
|
|
|
extern int usb_stor_Bulk_transport(ccb *, struct us_data *);
|
|
extern int usb_stor_Bulk_max_lun(struct us_data *);
|
|
extern int usb_stor_Bulk_reset(struct us_data *);
|
|
|
|
#endif
|