xref: /linux/drivers/usb/storage/usb.h (revision 3d5271f9883cba7b54762bc4fe027d4172f06db7)
1 /* Driver for USB Mass Storage compliant devices
2  * Main Header File
3  *
4  * $Id: usb.h,v 1.21 2002/04/21 02:57:59 mdharm Exp $
5  *
6  * Current development and maintenance by:
7  *   (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
8  *
9  * Initial work by:
10  *   (c) 1999 Michael Gee (michael@linuxspecific.com)
11  *
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.
17  *
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.
22  *
23  * Also, for certain devices, the interrupt endpoint is used to convey
24  * status of a command.
25  *
26  * Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more
27  * information about this driver.
28  *
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.
33  *
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.
38  *
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.
42  */
43 
44 #ifndef _USB_H_
45 #define _USB_H_
46 
47 #include <linux/usb.h>
48 #include <linux/blkdev.h>
49 #include <linux/smp_lock.h>
50 #include <linux/completion.h>
51 #include <scsi/scsi_host.h>
52 
53 struct us_data;
54 struct scsi_cmnd;
55 
56 /*
57  * Unusual device list definitions
58  */
59 
60 struct us_unusual_dev {
61 	const char* vendorName;
62 	const char* productName;
63 	__u8  useProtocol;
64 	__u8  useTransport;
65 	int (*initFunction)(struct us_data *);
66 	unsigned int flags;
67 };
68 
69 /*
70  * Static flag definitions.  We use this roundabout technique so that the
71  * proc_info() routine can automatically display a message for each flag.
72  */
73 #define US_DO_ALL_FLAGS						\
74 	US_FLAG(SINGLE_LUN,	0x00000001)			\
75 		/* allow access to only LUN 0 */		\
76 	US_FLAG(NEED_OVERRIDE,	0x00000002)			\
77 		/* unusual_devs entry is necessary */		\
78 	US_FLAG(SCM_MULT_TARG,	0x00000004)			\
79 		/* supports multiple targets */			\
80 	US_FLAG(FIX_INQUIRY,	0x00000008)			\
81 		/* INQUIRY response needs faking */		\
82 	US_FLAG(FIX_CAPACITY,	0x00000010)			\
83 		/* READ CAPACITY response too big */		\
84 	US_FLAG(IGNORE_RESIDUE,	0x00000020)			\
85 		/* reported residue is wrong */			\
86 	US_FLAG(BULK32,		0x00000040)			\
87 		/* Uses 32-byte CBW length */			\
88 	US_FLAG(NOT_LOCKABLE,	0x00000080)			\
89 		/* PREVENT/ALLOW not supported */		\
90 	US_FLAG(GO_SLOW,	0x00000100)			\
91 		/* Need delay after Command phase */		\
92 	US_FLAG(NO_WP_DETECT,	0x00000200)			\
93 		/* Don't check for write-protect */		\
94 
95 #define US_FLAG(name, value)	US_FL_##name = value ,
96 enum { US_DO_ALL_FLAGS };
97 #undef US_FLAG
98 
99 /* Dynamic flag definitions: used in set_bit() etc. */
100 #define US_FLIDX_URB_ACTIVE	18  /* 0x00040000  current_urb is in use  */
101 #define US_FLIDX_SG_ACTIVE	19  /* 0x00080000  current_sg is in use   */
102 #define US_FLIDX_ABORTING	20  /* 0x00100000  abort is in progress   */
103 #define US_FLIDX_DISCONNECTING	21  /* 0x00200000  disconnect in progress */
104 #define ABORTING_OR_DISCONNECTING	((1UL << US_FLIDX_ABORTING) | \
105 					 (1UL << US_FLIDX_DISCONNECTING))
106 #define US_FLIDX_RESETTING	22  /* 0x00400000  device reset in progress */
107 #define US_FLIDX_TIMED_OUT	23  /* 0x00800000  SCSI midlayer timed out  */
108 
109 
110 #define USB_STOR_STRING_LEN 32
111 
112 /*
113  * We provide a DMA-mapped I/O buffer for use with small USB transfers.
114  * It turns out that CB[I] needs a 12-byte buffer and Bulk-only needs a
115  * 31-byte buffer.  But Freecom needs a 64-byte buffer, so that's the
116  * size we'll allocate.
117  */
118 
119 #define US_IOBUF_SIZE		64	/* Size of the DMA-mapped I/O buffer */
120 #define US_SENSE_SIZE		18	/* Size of the autosense data buffer */
121 
122 typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
123 typedef int (*trans_reset)(struct us_data*);
124 typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*);
125 typedef void (*extra_data_destructor)(void *);	 /* extra data destructor   */
126 
127 /* we allocate one of these for every device that we remember */
128 struct us_data {
129 	/* The device we're working with
130 	 * It's important to note:
131 	 *    (o) you must hold dev_semaphore to change pusb_dev
132 	 */
133 	struct semaphore	dev_semaphore;	 /* protect pusb_dev */
134 	struct usb_device	*pusb_dev;	 /* this usb_device */
135 	struct usb_interface	*pusb_intf;	 /* this interface */
136 	struct us_unusual_dev   *unusual_dev;	 /* device-filter entry     */
137 	unsigned long		flags;		 /* from filter initially */
138 	unsigned int		send_bulk_pipe;	 /* cached pipe values */
139 	unsigned int		recv_bulk_pipe;
140 	unsigned int		send_ctrl_pipe;
141 	unsigned int		recv_ctrl_pipe;
142 	unsigned int		recv_intr_pipe;
143 
144 	/* information about the device */
145 	char			*transport_name;
146 	char			*protocol_name;
147 	__le32			bcs_signature;
148 	u8			subclass;
149 	u8			protocol;
150 	u8			max_lun;
151 
152 	u8			ifnum;		 /* interface number   */
153 	u8			ep_bInterval;	 /* interrupt interval */
154 
155 	/* function pointers for this device */
156 	trans_cmnd		transport;	 /* transport function	   */
157 	trans_reset		transport_reset; /* transport device reset */
158 	proto_cmnd		proto_handler;	 /* protocol handler	   */
159 
160 	/* SCSI interfaces */
161 	struct scsi_cmnd	*srb;		 /* current srb		*/
162 	unsigned int		tag;		 /* current dCBWTag	*/
163 
164 	/* control and bulk communications data */
165 	struct urb		*current_urb;	 /* USB requests	 */
166 	struct usb_ctrlrequest	*cr;		 /* control requests	 */
167 	struct usb_sg_request	current_sg;	 /* scatter-gather req.  */
168 	unsigned char		*iobuf;		 /* I/O buffer		 */
169 	unsigned char		*sensebuf;	 /* sense data buffer	 */
170 	dma_addr_t		cr_dma;		 /* buffer DMA addresses */
171 	dma_addr_t		iobuf_dma;
172 
173 	/* mutual exclusion and synchronization structures */
174 	struct semaphore	sema;		 /* to sleep thread on	    */
175 	struct completion	notify;		 /* thread begin/end	    */
176 	wait_queue_head_t	delay_wait;	 /* wait during scan, reset */
177 
178 	/* subdriver information */
179 	void			*extra;		 /* Any extra data          */
180 	extra_data_destructor	extra_destructor;/* extra data destructor   */
181 };
182 
183 /* Convert between us_data and the corresponding Scsi_Host */
184 static struct Scsi_Host inline *us_to_host(struct us_data *us) {
185 	return container_of((void *) us, struct Scsi_Host, hostdata);
186 }
187 static struct us_data inline *host_to_us(struct Scsi_Host *host) {
188 	return (struct us_data *) host->hostdata;
189 }
190 
191 /* Function to fill an inquiry response. See usb.c for details */
192 extern void fill_inquiry_response(struct us_data *us,
193 	unsigned char *data, unsigned int data_len);
194 
195 /* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
196  * single queue element srb for write access */
197 #define scsi_unlock(host)	spin_unlock_irq(host->host_lock)
198 #define scsi_lock(host)		spin_lock_irq(host->host_lock)
199 
200 
201 /* Vendor ID list for devices that require special handling */
202 #define USB_VENDOR_ID_GENESYS		0x05e3	/* Genesys Logic */
203 
204 #endif
205