Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
usb.h
Go to the documentation of this file.
1 /* Driver for USB Mass Storage compliant devices
2  * Main Header File
3  *
4  * Current development and maintenance by:
5  * (c) 1999-2002 Matthew Dharm ([email protected])
6  *
7  * Initial work by:
8  * (c) 1999 Michael Gee ([email protected])
9  *
10  * This driver is based on the 'USB Mass Storage Class' document. This
11  * describes in detail the protocol used to communicate with such
12  * devices. Clearly, the designers had SCSI and ATAPI commands in
13  * mind when they created this document. The commands are all very
14  * similar to commands in the SCSI-II and ATAPI specifications.
15  *
16  * It is important to note that in a number of cases this class
17  * exhibits class-specific exemptions from the USB specification.
18  * Notably the usage of NAK, STALL and ACK differs from the norm, in
19  * that they are used to communicate wait, failed and OK on commands.
20  *
21  * Also, for certain devices, the interrupt endpoint is used to convey
22  * status of a command.
23  *
24  * Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more
25  * information about this driver.
26  *
27  * This program is free software; you can redistribute it and/or modify it
28  * under the terms of the GNU General Public License as published by the
29  * Free Software Foundation; either version 2, or (at your option) any
30  * later version.
31  *
32  * This program is distributed in the hope that it will be useful, but
33  * WITHOUT ANY WARRANTY; without even the implied warranty of
34  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35  * General Public License for more details.
36  *
37  * You should have received a copy of the GNU General Public License along
38  * with this program; if not, write to the Free Software Foundation, Inc.,
39  * 675 Mass Ave, Cambridge, MA 02139, USA.
40  */
41 
42 #ifndef _USB_H_
43 #define _USB_H_
44 
45 #include <linux/usb.h>
46 #include <linux/usb_usual.h>
47 #include <linux/blkdev.h>
48 #include <linux/completion.h>
49 #include <linux/mutex.h>
50 #include <linux/workqueue.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;
65  int (*initFunction)(struct us_data *);
66 };
67 
68 
69 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
70 #define US_FLIDX_URB_ACTIVE 0 /* current_urb is in use */
71 #define US_FLIDX_SG_ACTIVE 1 /* current_sg is in use */
72 #define US_FLIDX_ABORTING 2 /* abort is in progress */
73 #define US_FLIDX_DISCONNECTING 3 /* disconnect in progress */
74 #define US_FLIDX_RESETTING 4 /* device reset in progress */
75 #define US_FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */
76 #define US_FLIDX_SCAN_PENDING 6 /* scanning not yet done */
77 #define US_FLIDX_REDO_READ10 7 /* redo READ(10) command */
78 #define US_FLIDX_READ10_WORKED 8 /* previous READ(10) succeeded */
79 
80 #define USB_STOR_STRING_LEN 32
81 
82 /*
83  * We provide a DMA-mapped I/O buffer for use with small USB transfers.
84  * It turns out that CB[I] needs a 12-byte buffer and Bulk-only needs a
85  * 31-byte buffer. But Freecom needs a 64-byte buffer, so that's the
86  * size we'll allocate.
87  */
88 
89 #define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */
90 #define US_SENSE_SIZE 18 /* Size of the autosense data buffer */
91 
92 typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
93 typedef int (*trans_reset)(struct us_data*);
94 typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*);
95 typedef void (*extra_data_destructor)(void *); /* extra data destructor */
96 typedef void (*pm_hook)(struct us_data *, int); /* power management hook */
97 
98 #define US_SUSPEND 0
99 #define US_RESUME 1
100 
101 /* we allocate one of these for every device that we remember */
102 struct us_data {
103  /* The device we're working with
104  * It's important to note:
105  * (o) you must hold dev_mutex to change pusb_dev
106  */
107  struct mutex dev_mutex; /* protect pusb_dev */
108  struct usb_device *pusb_dev; /* this usb_device */
109  struct usb_interface *pusb_intf; /* this interface */
110  struct us_unusual_dev *unusual_dev; /* device-filter entry */
111  unsigned long fflags; /* fixed flags from filter */
112  unsigned long dflags; /* dynamic atomic bitflags */
113  unsigned int send_bulk_pipe; /* cached pipe values */
114  unsigned int recv_bulk_pipe;
115  unsigned int send_ctrl_pipe;
116  unsigned int recv_ctrl_pipe;
117  unsigned int recv_intr_pipe;
118 
119  /* information about the device */
120  char *transport_name;
121  char *protocol_name;
123  u8 subclass;
124  u8 protocol;
125  u8 max_lun;
126 
127  u8 ifnum; /* interface number */
128  u8 ep_bInterval; /* interrupt interval */
129 
130  /* function pointers for this device */
131  trans_cmnd transport; /* transport function */
132  trans_reset transport_reset; /* transport device reset */
133  proto_cmnd proto_handler; /* protocol handler */
134 
135  /* SCSI interfaces */
136  struct scsi_cmnd *srb; /* current srb */
137  unsigned int tag; /* current dCBWTag */
138  char scsi_name[32]; /* scsi_host name */
139 
140  /* control and bulk communications data */
141  struct urb *current_urb; /* USB requests */
142  struct usb_ctrlrequest *cr; /* control requests */
143  struct usb_sg_request current_sg; /* scatter-gather req. */
144  unsigned char *iobuf; /* I/O buffer */
145  dma_addr_t iobuf_dma; /* buffer DMA addresses */
146  struct task_struct *ctl_thread; /* the control thread */
147 
148  /* mutual exclusion and synchronization structures */
149  struct completion cmnd_ready; /* to sleep thread on */
150  struct completion notify; /* thread begin/end */
151  wait_queue_head_t delay_wait; /* wait during reset */
152  struct delayed_work scan_dwork; /* for async scanning */
153 
154  /* subdriver information */
155  void *extra; /* Any extra data */
156  extra_data_destructor extra_destructor;/* extra data destructor */
157 #ifdef CONFIG_PM
158  pm_hook suspend_resume_hook;
159 #endif
160 
161  /* hacks for READ CAPACITY bug handling */
164 };
165 
166 /* Convert between us_data and the corresponding Scsi_Host */
167 static inline struct Scsi_Host *us_to_host(struct us_data *us) {
168  return container_of((void *) us, struct Scsi_Host, hostdata);
169 }
170 static inline struct us_data *host_to_us(struct Scsi_Host *host) {
171  return (struct us_data *) host->hostdata;
172 }
173 
174 /* Function to fill an inquiry response. See usb.c for details */
175 extern void fill_inquiry_response(struct us_data *us,
176  unsigned char *data, unsigned int data_len);
177 
178 /* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
179  * single queue element srb for write access */
180 #define scsi_unlock(host) spin_unlock_irq(host->host_lock)
181 #define scsi_lock(host) spin_lock_irq(host->host_lock)
182 
183 /* General routines provided by the usb-storage standard core */
184 #ifdef CONFIG_PM
185 extern int usb_stor_suspend(struct usb_interface *iface, pm_message_t message);
186 extern int usb_stor_resume(struct usb_interface *iface);
187 extern int usb_stor_reset_resume(struct usb_interface *iface);
188 #else
189 #define usb_stor_suspend NULL
190 #define usb_stor_resume NULL
191 #define usb_stor_reset_resume NULL
192 #endif
193 
194 extern int usb_stor_pre_reset(struct usb_interface *iface);
195 extern int usb_stor_post_reset(struct usb_interface *iface);
196 
197 extern int usb_stor_probe1(struct us_data **pus,
198  struct usb_interface *intf,
199  const struct usb_device_id *id,
200  struct us_unusual_dev *unusual_dev);
201 extern int usb_stor_probe2(struct us_data *us);
202 extern void usb_stor_disconnect(struct usb_interface *intf);
203 
204 #endif