Merge with Linux 2.4.0-test6-pre2.
[linux-2.6/linux-mips.git] / drivers / usb / storage / usb.h
blobb376d39eebc8e114cb84c0d734f148d616d5858a
1 /* Driver for USB Mass Storage compliant devices
2 * Main Header File
4 * $Id: usb.h,v 1.4 2000/07/28 20:14:49 groovyjava Exp $
6 * Current development and maintainance by:
7 * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
9 * Initial work by:
10 * (c) 1999 Michael Gee (michael@linuxspecific.com)
12 * This driver is based on the 'USB Mass Storage Class' document. This
13 * describes in detail the protocol used to communicate with such
14 * devices. Clearly, the designers had SCSI and ATAPI commands in
15 * mind when they created this document. The commands are all very
16 * similar to commands in the SCSI-II and ATAPI specifications.
18 * It is important to note that in a number of cases this class
19 * exhibits class-specific exemptions from the USB specification.
20 * Notably the usage of NAK, STALL and ACK differs from the norm, in
21 * that they are used to communicate wait, failed and OK on commands.
23 * Also, for certain devices, the interrupt endpoint is used to convey
24 * status of a command.
26 * Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more
27 * information about this driver.
29 * This program is free software; you can redistribute it and/or modify it
30 * under the terms of the GNU General Public License as published by the
31 * Free Software Foundation; either version 2, or (at your option) any
32 * later version.
34 * This program is distributed in the hope that it will be useful, but
35 * WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37 * General Public License for more details.
39 * You should have received a copy of the GNU General Public License along
40 * with this program; if not, write to the Free Software Foundation, Inc.,
41 * 675 Mass Ave, Cambridge, MA 02139, USA.
44 #ifndef _USB_H_
45 #define _USB_H_
47 #include <linux/usb.h>
48 #include <linux/blk.h>
49 #include <linux/smp_lock.h>
50 #include "scsi.h"
51 #include "hosts.h"
53 /*
54 * GUID definitions
57 #define GUID(x) __u32 x[3]
58 #define GUID_EQUAL(x, y) (x[0] == y[0] && x[1] == y[1] && x[2] == y[2])
59 #define GUID_CLEAR(x) x[0] = x[1] = x[2] = 0;
60 #define GUID_NONE(x) (!x[0] && !x[1] && !x[2])
61 #define GUID_FORMAT "%08x%08x%08x"
62 #define GUID_ARGS(x) x[0], x[1], x[2]
64 static inline void make_guid( __u32 *pg, __u16 vendor, __u16 product, char *serial)
66 pg[0] = (vendor << 16) | product;
67 pg[1] = pg[2] = 0;
68 while (*serial) {
69 pg[1] <<= 4;
70 pg[1] |= pg[2] >> 28;
71 pg[2] <<= 4;
72 if (*serial >= 'a')
73 *serial -= 'a' - 'A';
74 pg[2] |= (*serial <= '9' && *serial >= '0') ? *serial - '0'
75 : *serial - 'A' + 10;
76 serial++;
81 * Unusual device list definitions
84 struct us_unusual_dev {
85 /* we search the list based on these parameters */
86 __u16 idVendor;
87 __u16 idProduct;
88 __u16 bcdDeviceMin;
89 __u16 bcdDeviceMax;
91 /* the list specifies these parameters */
92 const char* name;
93 __u8 useProtocol;
94 __u8 useTransport;
95 unsigned int flags;
98 /* Flag definitions */
99 #define US_FL_SINGLE_LUN 0x00000001 /* allow access to only LUN 0 */
100 #define US_FL_MODE_XLATE 0x00000002 /* translate _6 to _10 comands for
101 Win/MacOS compatibility */
102 #define US_FL_START_STOP 0x00000004 /* ignore START_STOP commands */
103 #define US_FL_ALT_LENGTH 0x00000008 /* use the alternate algorithm for
104 us_transfer_length() */
105 #define US_FL_IGNORE_SER 0x00000010 /* Ignore the serial number given */
106 #define US_FL_NEED_INIT 0x00000020 /* Device needs initialization */
108 #define USB_STOR_STRING_LEN 32
110 struct us_data;
112 typedef int (*trans_cmnd)(Scsi_Cmnd*, struct us_data*);
113 typedef int (*trans_reset)(struct us_data*);
114 typedef void (*proto_cmnd)(Scsi_Cmnd*, struct us_data*);
116 /* we allocate one of these for every device that we remember */
117 struct us_data {
118 struct us_data *next; /* next device */
120 /* the device we're working with */
121 struct semaphore dev_semaphore; /* protect pusb_dev */
122 struct usb_device *pusb_dev; /* this usb_device */
124 unsigned int flags; /* from filter initially */
126 /* information about the device -- always good */
127 char vendor[USB_STOR_STRING_LEN];
128 char product[USB_STOR_STRING_LEN];
129 char serial[USB_STOR_STRING_LEN];
130 char *transport_name;
131 char *protocol_name;
132 u8 subclass;
133 u8 protocol;
134 u8 max_lun;
136 /* information about the device -- only good if device is attached */
137 u8 ifnum; /* interface number */
138 u8 ep_in; /* bulk in endpoint */
139 u8 ep_out; /* bulk out endpoint */
140 struct usb_endpoint_descriptor *ep_int; /* interrupt endpoint */
142 /* function pointers for this device */
143 trans_cmnd transport; /* transport function */
144 trans_reset transport_reset; /* transport device reset */
145 proto_cmnd proto_handler; /* protocol handler */
147 /* SCSI interfaces */
148 GUID(guid); /* unique dev id */
149 struct Scsi_Host *host; /* our dummy host data */
150 Scsi_Host_Template htmplt; /* own host template */
151 int host_number; /* to find us */
152 int host_no; /* allocated by scsi */
153 Scsi_Cmnd *srb; /* current srb */
155 /* thread information */
156 Scsi_Cmnd *queue_srb; /* the single queue slot */
157 int action; /* what to do */
158 int pid; /* control thread */
160 /* interrupt info for CBI devices -- only good if attached */
161 struct semaphore ip_waitq; /* for CBI interrupts */
162 int ip_wanted; /* is an IRQ expected? */
164 /* interrupt communications data */
165 struct semaphore irq_urb_sem; /* to protect irq_urb */
166 struct urb *irq_urb; /* for USB int requests */
167 unsigned char irqbuf[2]; /* buffer for USB IRQ */
169 /* control and bulk communications data */
170 struct semaphore current_urb_sem; /* to protect irq_urb */
171 struct urb *current_urb; /* non-int USB requests */
173 /* the waitqueue for sleeping the control thread */
174 wait_queue_head_t wqh; /* to sleep thread on */
176 /* mutual exclusion structures */
177 struct semaphore notify; /* thread begin/end */
178 struct semaphore queue_exclusion; /* to protect data structs */
179 void *extra; /* Any extra data */
180 void (*extra_destructor)(void *); /* extra data destructor */
183 /* The list of structures and the protective lock for them */
184 extern struct us_data *us_list;
185 extern struct semaphore us_list_semaphore;
187 #endif