- Linus: more PageDirty / swapcache handling
[davej-history.git] / drivers / usb / storage / usb.h
blobe0dac568d1f853e536ead54b3aec69ca352ac571
1 /* Driver for USB Mass Storage compliant devices
2 * Main Header File
4 * $Id: usb.h,v 1.11 2000/11/13 22:38:55 mdharm Exp $
6 * Current development and maintenance 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++;
80 struct us_data;
83 * Unusual device list definitions
86 struct us_unusual_dev {
87 /* we search the list based on these parameters */
88 __u16 idVendor;
89 __u16 idProduct;
90 __u16 bcdDeviceMin;
91 __u16 bcdDeviceMax;
93 /* the list specifies these parameters */
94 const char* vendorName;
95 const char* productName;
96 __u8 useProtocol;
97 __u8 useTransport;
98 int (*initFunction)(struct us_data *);
99 unsigned int flags;
102 /* Flag definitions */
103 #define US_FL_SINGLE_LUN 0x00000001 /* allow access to only LUN 0 */
104 #define US_FL_MODE_XLATE 0x00000002 /* translate _6 to _10 comands for
105 Win/MacOS compatibility */
106 #define US_FL_START_STOP 0x00000004 /* ignore START_STOP commands */
107 #define US_FL_IGNORE_SER 0x00000010 /* Ignore the serial number given */
108 #define US_FL_SCM_MULT_TARG 0x00000020 /* supports multiple targets */
110 #define USB_STOR_STRING_LEN 32
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*);
115 typedef void (*extra_data_destructor)(void *); /* extra data destructor */
117 /* we allocate one of these for every device that we remember */
118 struct us_data {
119 struct us_data *next; /* next device */
121 /* the device we're working with */
122 struct semaphore dev_semaphore; /* protect pusb_dev */
123 struct usb_device *pusb_dev; /* this usb_device */
125 unsigned int flags; /* from filter initially */
127 /* information about the device -- always good */
128 char vendor[USB_STOR_STRING_LEN];
129 char product[USB_STOR_STRING_LEN];
130 char serial[USB_STOR_STRING_LEN];
131 char *transport_name;
132 char *protocol_name;
133 u8 subclass;
134 u8 protocol;
135 u8 max_lun;
137 /* information about the device -- only good if device is attached */
138 u8 ifnum; /* interface number */
139 u8 ep_in; /* bulk in endpoint */
140 u8 ep_out; /* bulk out endpoint */
141 struct usb_endpoint_descriptor *ep_int; /* interrupt endpoint */
143 /* function pointers for this device */
144 trans_cmnd transport; /* transport function */
145 trans_reset transport_reset; /* transport device reset */
146 proto_cmnd proto_handler; /* protocol handler */
148 /* SCSI interfaces */
149 GUID(guid); /* unique dev id */
150 struct Scsi_Host *host; /* our dummy host data */
151 Scsi_Host_Template htmplt; /* own host template */
152 int host_number; /* to find us */
153 int host_no; /* allocated by scsi */
154 Scsi_Cmnd *srb; /* current srb */
156 /* thread information */
157 Scsi_Cmnd *queue_srb; /* the single queue slot */
158 int action; /* what to do */
159 int pid; /* control thread */
161 /* interrupt info for CBI devices -- only good if attached */
162 struct semaphore ip_waitq; /* for CBI interrupts */
163 atomic_t ip_wanted[1]; /* is an IRQ expected? */
165 /* interrupt communications data */
166 struct semaphore irq_urb_sem; /* to protect irq_urb */
167 struct urb *irq_urb; /* for USB int requests */
168 unsigned char irqbuf[2]; /* buffer for USB IRQ */
169 unsigned char irqdata[2]; /* data from USB IRQ */
171 /* control and bulk communications data */
172 struct semaphore current_urb_sem; /* to protect irq_urb */
173 struct urb *current_urb; /* non-int USB requests */
175 /* the waitqueue for sleeping the control thread */
176 wait_queue_head_t wqh; /* to sleep thread on */
178 /* mutual exclusion structures */
179 struct semaphore notify; /* thread begin/end */
180 struct semaphore queue_exclusion; /* to protect data structs */
181 struct us_unusual_dev *unusual_dev; /* If unusual device */
182 void *extra; /* Any extra data */
183 extra_data_destructor extra_destructor;/* extra data destructor */
186 /* The list of structures and the protective lock for them */
187 extern struct us_data *us_list;
188 extern struct semaphore us_list_semaphore;
190 /* The structure which defines our driver */
191 struct usb_driver usb_storage_driver;
193 /* Function to fill an inquiry response. See usb.c for details */
194 extern void fill_inquiry_response(struct us_data *us,
195 unsigned char *data, unsigned int data_len);
196 #endif