| 1 |
|
| 2 | |
| 3 | * Driver for USB Mass Storage compliant devices
|
| 4 | * Main Header File
|
| 5 | *
|
| 6 | * Current development and maintenance by:
|
| 7 | * (c) 1999-2002 Matthew Dharm ([email protected])
|
| 8 | *
|
| 9 | * Initial work by:
|
| 10 | * (c) 1999 Michael Gee ([email protected])
|
| 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 |
|
| 27 | #ifndef _USB_H_
|
| 28 | #define _USB_H_
|
| 29 |
|
| 30 | #include <linux/usb.h>
|
| 31 | #include <linux/usb_usual.h>
|
| 32 | #include <linux/blkdev.h>
|
| 33 | #include <linux/completion.h>
|
| 34 | #include <linux/mutex.h>
|
| 35 | #include <linux/workqueue.h>
|
| 36 | #include <scsi/scsi_host.h>
|
| 37 |
|
| 38 | struct us_data;
|
| 39 | struct scsi_cmnd;
|
| 40 |
|
| 41 | |
| 42 | * Unusual device list definitions
|
| 43 |
|
| 44 |
|
| 45 | struct us_unusual_dev {
|
| 46 | const char* vendorName;
|
| 47 | const char* productName;
|
| 48 | __u8 useProtocol;
|
| 49 | __u8 useTransport;
|
| 50 | int (*initFunction)(struct us_data *);
|
| 51 | };
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 | #define US_FLIDX_URB_ACTIVE 0
|
| 56 | #define US_FLIDX_SG_ACTIVE 1
|
| 57 | #define US_FLIDX_ABORTING 2
|
| 58 | #define US_FLIDX_DISCONNECTING 3
|
| 59 | #define US_FLIDX_RESETTING 4
|
| 60 | #define US_FLIDX_TIMED_OUT 5
|
| 61 | #define US_FLIDX_SCAN_PENDING 6
|
| 62 | #define US_FLIDX_REDO_READ10 7
|
| 63 | #define US_FLIDX_READ10_WORKED 8
|
| 64 |
|
| 65 | #define USB_STOR_STRING_LEN 32
|
| 66 |
|
| 67 | |
| 68 | * We provide a DMA-mapped I/O buffer for use with small USB transfers.
|
| 69 | * It turns out that CB[I] needs a 12-byte buffer and Bulk-only needs a
|
| 70 | * 31-byte buffer. But Freecom needs a 64-byte buffer, so that's the
|
| 71 | * size we'll allocate.
|
| 72 |
|
| 73 |
|
| 74 | #define US_IOBUF_SIZE 64
|
| 75 | #define US_SENSE_SIZE 18
|
| 76 |
|
| 77 | typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
|
| 78 | typedef int (*trans_reset)(struct us_data*);
|
| 79 | typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*);
|
| 80 | typedef void (*extra_data_destructor)(void *);
|
| 81 | typedef void (*pm_hook)(struct us_data *, int);
|
| 82 |
|
| 83 | #define US_SUSPEND 0
|
| 84 | #define US_RESUME 1
|
| 85 |
|
| 86 |
|
| 87 | struct us_data {
|
| 88 | |
| 89 | * The device we're working with
|
| 90 | * It's important to note:
|
| 91 | * (o) you must hold dev_mutex to change pusb_dev
|
| 92 |
|
| 93 | struct mutex dev_mutex;
|
| 94 | struct usb_device *pusb_dev;
|
| 95 | struct usb_interface *pusb_intf;
|
| 96 | const struct us_unusual_dev *unusual_dev;
|
| 97 |
|
| 98 | u64 fflags;
|
| 99 | unsigned long dflags;
|
| 100 | unsigned int send_bulk_pipe;
|
| 101 | unsigned int recv_bulk_pipe;
|
| 102 | unsigned int send_ctrl_pipe;
|
| 103 | unsigned int recv_ctrl_pipe;
|
| 104 | unsigned int recv_intr_pipe;
|
| 105 |
|
| 106 |
|
| 107 | char *transport_name;
|
| 108 | char *protocol_name;
|
| 109 | __le32 bcs_signature;
|
| 110 | u8 subclass;
|
| 111 | u8 protocol;
|
| 112 | u8 max_lun;
|
| 113 |
|
| 114 | u8 ifnum;
|
| 115 | u8 ep_bInterval;
|
| 116 |
|
| 117 |
|
| 118 | trans_cmnd transport;
|
| 119 | trans_reset transport_reset;
|
| 120 | proto_cmnd proto_handler;
|
| 121 |
|
| 122 |
|
| 123 | struct scsi_cmnd *srb;
|
| 124 | unsigned int tag;
|
| 125 | char scsi_name[32];
|
| 126 |
|
| 127 |
|
| 128 | struct urb *current_urb;
|
| 129 | struct usb_ctrlrequest *cr;
|
| 130 | struct usb_sg_request current_sg;
|
| 131 | unsigned char *iobuf;
|
| 132 | dma_addr_t iobuf_dma;
|
| 133 | struct task_struct *ctl_thread;
|
| 134 |
|
| 135 |
|
| 136 | struct completion cmnd_ready;
|
| 137 | struct completion notify;
|
| 138 | wait_queue_head_t delay_wait;
|
| 139 | struct delayed_work scan_dwork;
|
| 140 |
|
| 141 |
|
| 142 | void *extra;
|
| 143 | extra_data_destructor extra_destructor;
|
| 144 | #ifdef CONFIG_PM
|
| 145 | pm_hook suspend_resume_hook;
|
| 146 | #endif
|
| 147 |
|
| 148 |
|
| 149 | int use_last_sector_hacks;
|
| 150 | int last_sector_retries;
|
| 151 | };
|
| 152 |
|
| 153 |
|
| 154 | static inline struct Scsi_Host *us_to_host(struct us_data *us) {
|
| 155 | return container_of((void *) us, struct Scsi_Host, hostdata);
|
| 156 | }
|
| 157 | static inline struct us_data *host_to_us(struct Scsi_Host *host) {
|
| 158 | return (struct us_data *) host->hostdata;
|
| 159 | }
|
| 160 |
|
| 161 |
|
| 162 | extern void fill_inquiry_response(struct us_data *us,
|
| 163 | unsigned char *data, unsigned int data_len);
|
| 164 |
|
| 165 | |
| 166 | * The scsi_lock() and scsi_unlock() macros protect the sm_state and the
|
| 167 | * single queue element srb for write access
|
| 168 |
|
| 169 | #define scsi_unlock(host) spin_unlock_irq(host->host_lock)
|
| 170 | #define scsi_lock(host) spin_lock_irq(host->host_lock)
|
| 171 |
|
| 172 |
|
| 173 | #ifdef CONFIG_PM
|
| 174 | extern int usb_stor_suspend(struct usb_interface *iface, pm_message_t message);
|
| 175 | extern int usb_stor_resume(struct usb_interface *iface);
|
| 176 | extern int usb_stor_reset_resume(struct usb_interface *iface);
|
| 177 | #else
|
| 178 | #define usb_stor_suspend NULL
|
| 179 | #define usb_stor_resume NULL
|
| 180 | #define usb_stor_reset_resume NULL
|
| 181 | #endif
|
| 182 |
|
| 183 | extern int usb_stor_pre_reset(struct usb_interface *iface);
|
| 184 | extern int usb_stor_post_reset(struct usb_interface *iface);
|
| 185 |
|
| 186 | extern int usb_stor_probe1(struct us_data **pus,
|
| 187 | struct usb_interface *intf,
|
| 188 | const struct usb_device_id *id,
|
| 189 | const struct us_unusual_dev *unusual_dev,
|
| 190 | const struct scsi_host_template *sht);
|
| 191 | extern int usb_stor_probe2(struct us_data *us);
|
| 192 | extern void usb_stor_disconnect(struct usb_interface *intf);
|
| 193 |
|
| 194 | extern void usb_stor_adjust_quirks(struct usb_device *dev,
|
| 195 | u64 *fflags);
|
| 196 |
|
| 197 | #define module_usb_stor_driver(__driver, __sht, __name) \
|
| 198 | static int __init __driver##_init(void) \
|
| 199 | { \
|
| 200 | usb_stor_host_template_init(&(__sht), __name, THIS_MODULE); \
|
| 201 | return usb_register(&(__driver)); \
|
| 202 | } \
|
| 203 | module_init(__driver##_init); \
|
| 204 | static void __exit __driver##_exit(void) \
|
| 205 | { \
|
| 206 | usb_deregister(&(__driver)); \
|
| 207 | } \
|
| 208 | module_exit(__driver##_exit)
|
| 209 |
|
| 210 | #endif
|