1 // Driver for USB Mass Storage compliant devices
7 #include <linux/usb_usual.h>
8 #include <linux/blkdev.h>
9 #include <linux/completion.h>
10 #include <linux/mutex.h>
11 #include <scsi/scsi_host.h>
18 * Unusual device list definitions
21 struct us_unusual_dev
{
22 const char* vendorName
;
23 const char* productName
;
26 int (*initFunction
)(struct us_data
*);
30 #define REG_CARD_STATUS 0xFF83
31 #define REG_HW_TRAP1 0xFF89
33 // SRB Status. Refers /usr/include/wine/wine/wnaspi32.h & SCSI sense key
34 #define SS_SUCCESS 0x00 // No Sense
35 #define SS_NOT_READY 0x02
36 #define SS_MEDIUM_ERR 0x03
37 #define SS_HW_ERR 0x04
38 #define SS_ILLEGAL_REQUEST 0x05
39 #define SS_UNIT_ATTENTION 0x06
42 #define SD_INIT1_PATTERN 1
43 #define SD_INIT2_PATTERN 2
44 #define SD_RW_PATTERN 3
45 #define MS_INIT_PATTERN 4
46 #define MSP_RW_PATTERN 5
47 #define MS_RW_PATTERN 6
48 #define SM_INIT_PATTERN 7
49 #define SM_RW_PATTERN 8
54 typedef struct _SD_STATUS
{
63 } SD_STATUS
, *PSD_STATUS
;
65 typedef struct _MS_STATUS
{
74 } MS_STATUS
, *PMS_STATUS
;
76 typedef struct _SM_STATUS
{
83 } SM_STATUS
, *PSM_STATUS
;
86 #define SD_BLOCK_LEN 9 // 2^9 = 512 Bytes, The HW maximum read/write data length
88 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
89 #define US_FLIDX_URB_ACTIVE 0 /* current_urb is in use */
90 #define US_FLIDX_SG_ACTIVE 1 /* current_sg is in use */
91 #define US_FLIDX_ABORTING 2 /* abort is in progress */
92 #define US_FLIDX_DISCONNECTING 3 /* disconnect in progress */
93 #define US_FLIDX_RESETTING 4 /* device reset in progress */
94 #define US_FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */
95 #define US_FLIDX_DONT_SCAN 6 /* don't scan (disconnect) */
98 #define USB_STOR_STRING_LEN 32
101 * We provide a DMA-mapped I/O buffer for use with small USB transfers.
102 * It turns out that CB[I] needs a 12-byte buffer and Bulk-only needs a
103 * 31-byte buffer. But Freecom needs a 64-byte buffer, so that's the
104 * size we'll allocate.
107 #define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */
108 #define US_SENSE_SIZE 18 /* Size of the autosense data buffer */
110 typedef int (*trans_cmnd
)(struct scsi_cmnd
*, struct us_data
*);
111 typedef int (*trans_reset
)(struct us_data
*);
112 typedef void (*proto_cmnd
)(struct scsi_cmnd
*, struct us_data
*);
113 typedef void (*extra_data_destructor
)(void *); /* extra data destructor */
114 typedef void (*pm_hook
)(struct us_data
*, int); /* power management hook */
119 /* we allocate one of these for every device that we remember */
121 /* The device we're working with
122 * It's important to note:
123 * (o) you must hold dev_mutex to change pusb_dev
125 struct mutex dev_mutex
; /* protect pusb_dev */
126 struct usb_device
*pusb_dev
; /* this usb_device */
127 struct usb_interface
*pusb_intf
; /* this interface */
128 struct us_unusual_dev
*unusual_dev
; /* device-filter entry */
129 unsigned long fflags
; /* fixed flags from filter */
130 unsigned long dflags
; /* dynamic atomic bitflags */
131 unsigned int send_bulk_pipe
; /* cached pipe values */
132 unsigned int recv_bulk_pipe
;
133 unsigned int send_ctrl_pipe
;
134 unsigned int recv_ctrl_pipe
;
135 unsigned int recv_intr_pipe
;
137 /* information about the device */
138 char *transport_name
;
140 __le32 bcs_signature
;
145 u8 ifnum
; /* interface number */
146 u8 ep_bInterval
; /* interrupt interval */
148 /* function pointers for this device */
149 trans_cmnd transport
; /* transport function */
150 trans_reset transport_reset
; /* transport device reset */
151 proto_cmnd proto_handler
; /* protocol handler */
153 /* SCSI interfaces */
154 struct scsi_cmnd
*srb
; /* current srb */
155 unsigned int tag
; /* current dCBWTag */
157 /* control and bulk communications data */
158 struct urb
*current_urb
; /* USB requests */
159 struct usb_ctrlrequest
*cr
; /* control requests */
160 struct usb_sg_request current_sg
; /* scatter-gather req. */
161 unsigned char *iobuf
; /* I/O buffer */
162 unsigned char *sensebuf
; /* sense data buffer */
163 dma_addr_t cr_dma
; /* buffer DMA addresses */
164 dma_addr_t iobuf_dma
;
165 struct task_struct
*ctl_thread
; /* the control thread */
167 /* mutual exclusion and synchronization structures */
168 struct completion cmnd_ready
; /* to sleep thread on */
169 struct completion notify
; /* thread begin/end */
170 wait_queue_head_t delay_wait
; /* wait during scan, reset */
171 struct completion scanning_done
; /* wait for scan thread */
173 /* subdriver information */
174 void *extra
; /* Any extra data */
175 extra_data_destructor extra_destructor
;/* extra data destructor */
177 pm_hook suspend_resume_hook
;
184 //----- SD Control Data ----------------
185 //SD_REGISTER SD_Regs;
194 BYTE SD20_HIGH_CAPACITY
;
198 BYTE MMC_HIGH_CAPACITY
;
200 //----- MS Control Data ----------------
202 DWORD MSP_TotalBlock
;
203 /* MS_LibControl MS_Lib; */
207 //----- SM Control Data ----------------
216 //------Power Managerment ---------------
217 BOOLEAN Power_IsResum
;
220 /* Convert between us_data and the corresponding Scsi_Host */
221 static inline struct Scsi_Host
*us_to_host(struct us_data
*us
) {
222 return container_of((void *) us
, struct Scsi_Host
, hostdata
);
224 static inline struct us_data
*host_to_us(struct Scsi_Host
*host
) {
225 return (struct us_data
*) host
->hostdata
;
228 /* Function to fill an inquiry response. See usb.c for details */
229 extern void fill_inquiry_response(struct us_data
*us
,
230 unsigned char *data
, unsigned int data_len
);
232 /* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
233 * single queue element srb for write access */
234 #define scsi_unlock(host) spin_unlock_irq(host->host_lock)
235 #define scsi_lock(host) spin_lock_irq(host->host_lock)