• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /************************************************************************************
2  * include/nuttx/usb/storage.h
3  *
4  *   Copyright (C) 2008-2011 Gregory Nutt. All rights reserved.
5  *   Author: Gregory Nutt <gnutt@nuttx.org>
6  *
7  * References:
8  *   "Universal Serial Bus Mass Storage Class, Specification Overview,"
9  *   Revision 1.2,  USB Implementer's Forum, June 23, 2003.
10  *
11  *   "Universal Serial Bus Mass Storage Class, Bulk-Only Transport,"
12  *   Revision 1.0, USB Implementer's Forum, September 31, 1999.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  *
18  * 1. Redistributions of source code must retain the above copyright
19  *    notice, this list of conditions and the following disclaimer.
20  * 2. Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in
22  *    the documentation and/or other materials provided with the
23  *    distribution.
24  * 3. Neither the name NuttX nor the names of its contributors may be
25  *    used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
35  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
36  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39  * POSSIBILITY OF SUCH DAMAGE.
40  *
41  ************************************************************************************/
42 
43 #ifndef __INCLUDE_NUTTX_USB_STORAGE_H
44 #define __INCLUDE_NUTTX_USB_STORAGE_H
45 
46 /************************************************************************************
47  * Included Files
48  ************************************************************************************/
49 
50 /************************************************************************************
51  * Pre-processor Definitions
52  ************************************************************************************/
53 
54 /* Mass storage requests */
55 
56 #define USBMSC_TYPE_SETUPIN  (USB_DIR_IN|UT_CLASS|UT_INTERFACE)
57 #define USBMSC_TYPE_SETUPOUT (USB_DIR_OUT|UT_CLASS|UT_INTERFACE)
58 
59 #define USBMSC_REQ_MSRESET           (0xff) /* Reset mass storage device and interface */
60 #define USBMSC_REQ_GETMAXLUN         (0xfe) /* Return number LUNs supported */
61 
62 /* Mass storage subclass codes */
63 
64 #define USBMSC_SUBCLASS_RBC          (0x01) /* Reduced block commands (e.g., flash devices) */
65 #define USBMSC_SUBCLASS_SFF1         (0x02) /* SFF-8020i/MMC-2 (ATAPI) (e.g., C/DVD) */
66 #define USBMSC_SUBCLASS_QIC          (0x03) /* QIC-157 (e.g., tape device) */
67 #define USBMSC_SUBCLASS_UFI          (0x04) /* e.g. floppy device */
68 #define USBMSC_SUBCLASS_SFF2         (0x05) /* SFF-8070i (e.g. floppy disk) */
69 #define USBMSC_SUBCLASS_SCSI         (0x06) /* SCSI transparent */
70 
71 #define UMASS_ATTACH_PRENAME         "/dev/sd"
72 #define MASS_NAME                    10
73 #define MAX_DEVICE                   5
74 
75 /* Mass storage transport protocols */
76 
77 #define USBMSC_PROTO_CBI0            (0x00) /* CBI transport with command completion interrupt */
78 #define USBMSC_PROTO_CBI1            (0x01) /* CBI transport without command completion interrupt */
79 #define USBMSC_PROTO_BULKONLY        (0x50) /* Bulk only transport */
80 
81 /* Common Block Wrapper (CBW) */
82 
83 #define USBMSC_CBW_SIZEOF            (31)
84 #define USBMSC_CBW_SIGNATURE         (0x43425355)   /*  Little endian USBC */
85 #define USBMSC_CBWFLAG_IN            (0x80)         /* Bit 7=1: Direction = IN */
86 
87 #define USBMSC_MAXCDBLEN             (16)           /* Max length of SCSI Command Data Block */
88 
89 /* Command Status Wrapper (CSW) */
90 
91 #define USBMSC_CSW_SIZEOF            (13)
92 #define USBMSC_CSW_SIGNATURE         (0x53425355)   /* Little endian 'USBS' */
93 #define USBMSC_CSWSTATUS_PASS        (0)
94 #define USBMSC_CSWSTATUS_FAIL        (1)
95 #define USBMSC_CSWSTATUS_PHASEERROR  (2)
96 
97 /************************************************************************************
98  * Public Types
99  ************************************************************************************/
100 
101 /* Command Block Wrapper (CBW) */
102 
103 struct usbmsc_cbw_s
104 {
105   uint8_t signature[4];           /* 'USBC' = 0x43425355 */
106   uint8_t tag[4];                 /* Depends on command id */
107   uint8_t datlen[4];              /* Number of bytes that host expects to transfer */
108   uint8_t flags;                  /* Bit 7: Direction=IN (other obsolete or reserved) */
109   uint8_t lun;                    /* LUN (normally 0) */
110   uint8_t cdblen;                 /* len of cdb[] */
111   uint8_t cdb[USBMSC_MAXCDBLEN];  /* Command Data Block */
112 };
113 
114 /* Command Status Wrapper (CSW) */
115 
116 struct usbmsc_csw_s
117 {
118   uint8_t signature[4];           /* 'USBS' = 0x53425355 */
119   uint8_t tag[4];                 /* Same tag as original command */
120   uint8_t residue[4];             /* Amount not transferred */
121   uint8_t status;                 /* Status of transfer */
122 };
123 
124 /************************************************************************************
125  * Public Data
126  ************************************************************************************/
127 
128 /************************************************************************************
129  * Public Functions
130  ************************************************************************************/
131 
132 #endif /* __INCLUDE_NUTTX_USB_STORAGE_H */