RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / drivers / usb / storage / usb.h
blobbb2315abbc24246b1d510c0372fe2a794ffb1a15
1 /* Driver for USB Mass Storage compliant devices
2 * Main Header File
4 * $Id: usb.h,v 1.21 2002/04/21 02:57:59 mdharm Exp $
6 * Current development and maintenance by:
7 * (c) 1999-2002 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/usb_usual.h>
49 #include <linux/blkdev.h>
50 #include <linux/completion.h>
51 #include <linux/mutex.h>
52 #include <scsi/scsi_host.h>
54 struct us_data;
55 struct scsi_cmnd;
58 * Unusual device list definitions
61 struct us_unusual_dev {
62 const char* vendorName;
63 const char* productName;
64 __u8 useProtocol;
65 __u8 useTransport;
66 int (*initFunction)(struct us_data *);
70 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
71 #define US_FLIDX_URB_ACTIVE 0 /* current_urb is in use */
72 #define US_FLIDX_SG_ACTIVE 1 /* current_sg is in use */
73 #define US_FLIDX_ABORTING 2 /* abort is in progress */
74 #define US_FLIDX_DISCONNECTING 3 /* disconnect in progress */
75 #define US_FLIDX_RESETTING 4 /* device reset in progress */
76 #define US_FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */
77 #define US_FLIDX_DONT_SCAN 6 /* don't scan (disconnect) */
79 #define USB_STOR_STRING_LEN 32
82 * We provide a DMA-mapped I/O buffer for use with small USB transfers.
83 * It turns out that CB[I] needs a 12-byte buffer and Bulk-only needs a
84 * 31-byte buffer. But Freecom needs a 64-byte buffer, so that's the
85 * size we'll allocate.
88 #define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */
89 #define US_SENSE_SIZE 18 /* Size of the autosense data buffer */
91 typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
92 typedef int (*trans_reset)(struct us_data*);
93 typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*);
94 typedef void (*extra_data_destructor)(void *); /* extra data destructor */
95 typedef void (*pm_hook)(struct us_data *, int); /* power management hook */
97 #define US_SUSPEND 0
98 #define US_RESUME 1
100 /* we allocate one of these for every device that we remember */
101 struct us_data {
102 /* The device we're working with
103 * It's important to note:
104 * (o) you must hold dev_mutex to change pusb_dev
106 struct mutex dev_mutex; /* protect pusb_dev */
107 struct usb_device *pusb_dev; /* this usb_device */
108 struct usb_interface *pusb_intf; /* this interface */
109 struct us_unusual_dev *unusual_dev; /* device-filter entry */
110 unsigned long fflags; /* fixed flags from filter */
111 unsigned long dflags; /* dynamic atomic bitflags */
112 unsigned int send_bulk_pipe; /* cached pipe values */
113 unsigned int recv_bulk_pipe;
114 unsigned int send_ctrl_pipe;
115 unsigned int recv_ctrl_pipe;
116 unsigned int recv_intr_pipe;
118 /* information about the device */
119 char *transport_name;
120 char *protocol_name;
121 __le32 bcs_signature;
122 u8 subclass;
123 u8 protocol;
124 u8 max_lun;
126 u8 ifnum; /* interface number */
127 u8 ep_bInterval; /* interrupt interval */
129 /* function pointers for this device */
130 trans_cmnd transport; /* transport function */
131 trans_reset transport_reset; /* transport device reset */
132 proto_cmnd proto_handler; /* protocol handler */
134 /* SCSI interfaces */
135 struct scsi_cmnd *srb; /* current srb */
136 unsigned int tag; /* current dCBWTag */
138 /* control and bulk communications data */
139 struct urb *current_urb; /* USB requests */
140 struct usb_ctrlrequest *cr; /* control requests */
141 struct usb_sg_request current_sg; /* scatter-gather req. */
142 unsigned char *iobuf; /* I/O buffer */
143 dma_addr_t cr_dma; /* buffer DMA addresses */
144 dma_addr_t iobuf_dma;
145 struct task_struct *ctl_thread; /* the control thread */
147 /* mutual exclusion and synchronization structures */
148 struct completion cmnd_ready; /* to sleep thread on */
149 struct completion notify; /* thread begin/end */
150 wait_queue_head_t delay_wait; /* wait during scan, reset */
151 struct completion scanning_done; /* wait for scan thread */
153 /* subdriver information */
154 void *extra; /* Any extra data */
155 extra_data_destructor extra_destructor;/* extra data destructor */
156 #ifdef CONFIG_PM
157 pm_hook suspend_resume_hook;
158 #endif
160 /* hacks for READ CAPACITY bug handling */
161 int use_last_sector_hacks;
162 int last_sector_retries;
165 /* Convert between us_data and the corresponding Scsi_Host */
166 static inline struct Scsi_Host *us_to_host(struct us_data *us) {
167 return container_of((void *) us, struct Scsi_Host, hostdata);
169 static inline struct us_data *host_to_us(struct Scsi_Host *host) {
170 return (struct us_data *) host->hostdata;
173 /* Function to fill an inquiry response. See usb.c for details */
174 extern void fill_inquiry_response(struct us_data *us,
175 unsigned char *data, unsigned int data_len);
177 /* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
178 * single queue element srb for write access */
179 #define scsi_unlock(host) spin_unlock_irq(host->host_lock)
180 #define scsi_lock(host) spin_lock_irq(host->host_lock)
182 #endif