1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43#ifndef _USB_H_
44#define _USB_H_
45
46#include <linux/usb.h>
47#include <linux/usb_usual.h>
48#include <linux/blkdev.h>
49#include <linux/completion.h>
50#include <linux/mutex.h>
51#include <linux/workqueue.h>
52#include <scsi/scsi_host.h>
53
54struct us_data;
55struct scsi_cmnd;
56
57
58
59
60
61struct us_unusual_dev {
62 const char* vendorName;
63 const char* productName;
64 __u8 useProtocol;
65 __u8 useTransport;
66 int (*initFunction)(struct us_data *);
67};
68
69
70
71#define US_FLIDX_URB_ACTIVE 0
72#define US_FLIDX_SG_ACTIVE 1
73#define US_FLIDX_ABORTING 2
74#define US_FLIDX_DISCONNECTING 3
75#define US_FLIDX_RESETTING 4
76#define US_FLIDX_TIMED_OUT 5
77#define US_FLIDX_SCAN_PENDING 6
78#define US_FLIDX_REDO_READ10 7
79#define US_FLIDX_READ10_WORKED 8
80
81#define USB_STOR_STRING_LEN 32
82
83
84
85
86
87
88
89
90#define US_IOBUF_SIZE 64
91#define US_SENSE_SIZE 18
92
93typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
94typedef int (*trans_reset)(struct us_data*);
95typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*);
96typedef void (*extra_data_destructor)(void *);
97typedef void (*pm_hook)(struct us_data *, int);
98
99#define US_SUSPEND 0
100#define US_RESUME 1
101
102
103struct us_data {
104
105
106
107
108
109 struct mutex dev_mutex;
110 struct usb_device *pusb_dev;
111 struct usb_interface *pusb_intf;
112 struct us_unusual_dev *unusual_dev;
113 unsigned long fflags;
114 unsigned long dflags;
115 unsigned int send_bulk_pipe;
116 unsigned int recv_bulk_pipe;
117 unsigned int send_ctrl_pipe;
118 unsigned int recv_ctrl_pipe;
119 unsigned int recv_intr_pipe;
120
121
122 char *transport_name;
123 char *protocol_name;
124 __le32 bcs_signature;
125 u8 subclass;
126 u8 protocol;
127 u8 max_lun;
128
129 u8 ifnum;
130 u8 ep_bInterval;
131
132
133 trans_cmnd transport;
134 trans_reset transport_reset;
135 proto_cmnd proto_handler;
136
137
138 struct scsi_cmnd *srb;
139 unsigned int tag;
140 char scsi_name[32];
141
142
143 struct urb *current_urb;
144 struct usb_ctrlrequest *cr;
145 struct usb_sg_request current_sg;
146 unsigned char *iobuf;
147 dma_addr_t iobuf_dma;
148 struct task_struct *ctl_thread;
149
150
151 struct completion cmnd_ready;
152 struct completion notify;
153 wait_queue_head_t delay_wait;
154 struct delayed_work scan_dwork;
155
156
157 void *extra;
158 extra_data_destructor extra_destructor;
159#ifdef CONFIG_PM
160 pm_hook suspend_resume_hook;
161#endif
162
163
164 int use_last_sector_hacks;
165 int last_sector_retries;
166};
167
168
169static inline struct Scsi_Host *us_to_host(struct us_data *us) {
170 return container_of((void *) us, struct Scsi_Host, hostdata);
171}
172static inline struct us_data *host_to_us(struct Scsi_Host *host) {
173 return (struct us_data *) host->hostdata;
174}
175
176
177extern void fill_inquiry_response(struct us_data *us,
178 unsigned char *data, unsigned int data_len);
179
180
181
182
183
184#define scsi_unlock(host) spin_unlock_irq(host->host_lock)
185#define scsi_lock(host) spin_lock_irq(host->host_lock)
186
187
188#ifdef CONFIG_PM
189extern int usb_stor_suspend(struct usb_interface *iface, pm_message_t message);
190extern int usb_stor_resume(struct usb_interface *iface);
191extern int usb_stor_reset_resume(struct usb_interface *iface);
192#else
193#define usb_stor_suspend NULL
194#define usb_stor_resume NULL
195#define usb_stor_reset_resume NULL
196#endif
197
198extern int usb_stor_pre_reset(struct usb_interface *iface);
199extern int usb_stor_post_reset(struct usb_interface *iface);
200
201extern int usb_stor_probe1(struct us_data **pus,
202 struct usb_interface *intf,
203 const struct usb_device_id *id,
204 struct us_unusual_dev *unusual_dev,
205 struct scsi_host_template *sht);
206extern int usb_stor_probe2(struct us_data *us);
207extern void usb_stor_disconnect(struct usb_interface *intf);
208
209extern void usb_stor_adjust_quirks(struct usb_device *dev,
210 unsigned long *fflags);
211
212#define module_usb_stor_driver(__driver, __sht, __name) \
213static int __init __driver##_init(void) \
214{ \
215 usb_stor_host_template_init(&(__sht), __name, THIS_MODULE); \
216 return usb_register(&(__driver)); \
217} \
218module_init(__driver##_init); \
219static void __exit __driver##_exit(void) \
220{ \
221 usb_deregister(&(__driver)); \
222} \
223module_exit(__driver##_exit)
224
225#endif
226