Linux-2.4.0-test2
[davej-history.git] / drivers / usb / usb-storage.h
blob82475f094ad83970a8e2d24d840508ba004cba7d
1 /* Driver for USB mass storage - include file
3 * (c) 1999 Michael Gee (michael@linuxspecific.com)
4 * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
6 */
8 #include <linux/config.h>
10 #define USB_STORAGE "usb-storage.c: "
11 #define USB_STOR_STRING_LEN 32
13 #ifdef CONFIG_USB_STORAGE_DEBUG
14 void us_show_command(Scsi_Cmnd *srb);
15 #define US_DEBUGP(x...) printk( KERN_DEBUG USB_STORAGE ## x )
16 #define US_DEBUGPX(x...) printk( ## x )
17 #define US_DEBUG(x) x
18 #else
19 #define US_DEBUGP(x...)
20 #define US_DEBUGPX(x...)
21 #define US_DEBUG(x)
22 #endif
24 /* bit set if input */
25 extern unsigned char us_direction[256/8];
26 #define US_DIRECTION(x) ((us_direction[x>>3] >> (x & 7)) & 1)
28 /* Sub Classes */
30 #define US_SC_RBC 0x01 /* Typically, flash devices */
31 #define US_SC_8020 0x02 /* CD-ROM */
32 #define US_SC_QIC 0x03 /* QIC-157 Tapes */
33 #define US_SC_UFI 0x04 /* Floppy */
34 #define US_SC_8070 0x05 /* Removable media */
35 #define US_SC_SCSI 0x06 /* Transparent */
36 #define US_SC_MIN US_SC_RBC
37 #define US_SC_MAX US_SC_SCSI
39 /* Protocols */
41 #define US_PR_CBI 0x00 /* Control/Bulk/Interrupt */
42 #define US_PR_CB 0x01 /* Control/Bulk w/o interrupt */
43 #define US_PR_BULK 0x50 /* bulk only */
46 * Bulk only data structures
49 /* command block wrapper */
50 struct bulk_cb_wrap {
51 __u32 Signature; /* contains 'USBC' */
52 __u32 Tag; /* unique per command id */
53 __u32 DataTransferLength; /* size of data */
54 __u8 Flags; /* direction in bit 0 */
55 __u8 Lun; /* LUN normally 0 */
56 __u8 Length; /* of of the CDB */
57 __u8 CDB[16]; /* max command */
60 #define US_BULK_CB_WRAP_LEN 31
61 #define US_BULK_CB_SIGN 0x43425355 /*spells out USBC */
62 #define US_BULK_FLAG_IN 1
63 #define US_BULK_FLAG_OUT 0
65 /* command status wrapper */
66 struct bulk_cs_wrap {
67 __u32 Signature; /* should = 'USBS' */
68 __u32 Tag; /* same as original command */
69 __u32 Residue; /* amount not transferred */
70 __u8 Status; /* see below */
71 __u8 Filler[18];
74 #define US_BULK_CS_WRAP_LEN 13
75 #define US_BULK_CS_SIGN 0x53425355 /* spells out 'USBS' */
76 #define US_BULK_STAT_OK 0
77 #define US_BULK_STAT_FAIL 1
78 #define US_BULK_STAT_PHASE 2
80 /* bulk-only class specific requests */
81 #define US_BULK_RESET_REQUEST 0xff
82 #define US_BULK_GET_MAX_LUN 0xfe
85 * us_bulk_transfer() return codes
87 #define US_BULK_TRANSFER_GOOD 0 /* good transfer */
88 #define US_BULK_TRANSFER_SHORT 1 /* transfered less than expected */
89 #define US_BULK_TRANSFER_FAILED 2 /* transfer died in the middle */
90 #define US_BULK_TRANSFER_ABORTED 3 /* transfer canceled */
93 * Transport return codes
96 #define USB_STOR_TRANSPORT_GOOD 0 /* Transport good, command good */
97 #define USB_STOR_TRANSPORT_FAILED 1 /* Transport good, command failed */
98 #define USB_STOR_TRANSPORT_ERROR 2 /* Transport bad (i.e. device dead) */
99 #define USB_STOR_TRANSPORT_ABORTED 3 /* Transport aborted */
102 * CBI accept device specific command
105 #define US_CBI_ADSC 0
108 * GUID definitions
111 #define GUID(x) __u32 x[3]
112 #define GUID_EQUAL(x, y) (x[0] == y[0] && x[1] == y[1] && x[2] == y[2])
113 #define GUID_CLEAR(x) x[0] = x[1] = x[2] = 0;
114 #define GUID_NONE(x) (!x[0] && !x[1] && !x[2])
115 #define GUID_FORMAT "%08x%08x%08x"
116 #define GUID_ARGS(x) x[0], x[1], x[2]
118 static inline void make_guid( __u32 *pg, __u16 vendor, __u16 product, char *serial)
120 pg[0] = (vendor << 16) | product;
121 pg[1] = pg[2] = 0;
122 while (*serial) {
123 pg[1] <<= 4;
124 pg[1] |= pg[2] >> 28;
125 pg[2] <<= 4;
126 if (*serial >= 'a')
127 *serial -= 'a' - 'A';
128 pg[2] |= (*serial <= '9' && *serial >= '0') ? *serial - '0'
129 : *serial - 'A' + 10;
130 serial++;
135 * Unusual device list definitions
138 struct us_unusual_dev {
139 /* we search the list based on these parameters */
140 __u16 idVendor;
141 __u16 idProduct;
142 __u16 bcdDeviceMin;
143 __u16 bcdDeviceMax;
145 /* the list specifies these parameters */
146 const char* name;
147 __u8 useProtocol;
148 __u8 useTransport;
149 unsigned int flags;
152 /* Flag definitions */
153 #define US_FL_SINGLE_LUN 0x00000001 /* allow access to only LUN 0 */
154 #define US_FL_MODE_XLATE 0x00000002 /* translate _6 to _10 comands for
155 Win/MacOS compatibility */
156 #define US_FL_START_STOP 0x00000004 /* ignore START_STOP commands */
157 #define US_FL_ALT_LENGTH 0x00000008 /* use the alternate algorithm for
158 us_transfer_length() */
159 #define US_FL_IGNORE_SER 0x00000010 /* Ignore the serial number given */