1
2
3#ifndef _USB_H_
4#define _USB_H_
5
6#include <linux/usb.h>
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>
12#include "common.h"
13
14struct us_data;
15struct scsi_cmnd;
16
17
18
19
20
21struct us_unusual_dev {
22 const char* vendorName;
23 const char* productName;
24 __u8 useProtocol;
25 __u8 useTransport;
26 int (*initFunction)(struct us_data *);
27};
28
29
30#define REG_CARD_STATUS 0xFF83
31#define REG_HW_TRAP1 0xFF89
32
33
34#define SS_SUCCESS 0x00
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
40
41
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
50
51#define FDIR_WRITE 0
52#define FDIR_READ 1
53
54typedef struct _SD_STATUS {
55 BYTE Insert:1;
56 BYTE Ready:1;
57 BYTE MediaChange:1;
58 BYTE IsMMC:1;
59 BYTE HiCapacity:1;
60 BYTE HiSpeed:1;
61 BYTE WtP:1;
62 BYTE Reserved:1;
63} SD_STATUS, *PSD_STATUS;
64
65typedef struct _MS_STATUS {
66 BYTE Insert:1;
67 BYTE Ready:1;
68 BYTE MediaChange:1;
69 BYTE IsMSPro:1;
70 BYTE IsMSPHG:1;
71 BYTE Reserved1:1;
72 BYTE WtP:1;
73 BYTE Reserved2:1;
74} MS_STATUS, *PMS_STATUS;
75
76typedef struct _SM_STATUS {
77 BYTE Insert:1;
78 BYTE Ready:1;
79 BYTE MediaChange:1;
80 BYTE Reserved:3;
81 BYTE WtP:1;
82 BYTE IsMS:1;
83} SM_STATUS, *PSM_STATUS;
84
85
86#define SD_BLOCK_LEN 9
87
88
89#define US_FLIDX_URB_ACTIVE 0
90#define US_FLIDX_SG_ACTIVE 1
91#define US_FLIDX_ABORTING 2
92#define US_FLIDX_DISCONNECTING 3
93#define US_FLIDX_RESETTING 4
94#define US_FLIDX_TIMED_OUT 5
95#define US_FLIDX_DONT_SCAN 6
96
97
98#define USB_STOR_STRING_LEN 32
99
100
101
102
103
104
105
106
107#define US_IOBUF_SIZE 64
108#define US_SENSE_SIZE 18
109
110typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
111typedef int (*trans_reset)(struct us_data*);
112typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*);
113typedef void (*extra_data_destructor)(void *);
114typedef void (*pm_hook)(struct us_data *, int);
115
116#define US_SUSPEND 0
117#define US_RESUME 1
118
119
120struct us_data {
121
122
123
124
125 struct mutex dev_mutex;
126 struct usb_device *pusb_dev;
127 struct usb_interface *pusb_intf;
128 struct us_unusual_dev *unusual_dev;
129 unsigned long fflags;
130 unsigned long dflags;
131 unsigned int send_bulk_pipe;
132 unsigned int recv_bulk_pipe;
133 unsigned int send_ctrl_pipe;
134 unsigned int recv_ctrl_pipe;
135 unsigned int recv_intr_pipe;
136
137
138 char *transport_name;
139 char *protocol_name;
140 __le32 bcs_signature;
141 u8 subclass;
142 u8 protocol;
143 u8 max_lun;
144
145 u8 ifnum;
146 u8 ep_bInterval;
147
148
149 trans_cmnd transport;
150 trans_reset transport_reset;
151 proto_cmnd proto_handler;
152
153
154 struct scsi_cmnd *srb;
155 unsigned int tag;
156
157
158 struct urb *current_urb;
159 struct usb_ctrlrequest *cr;
160 struct usb_sg_request current_sg;
161 unsigned char *iobuf;
162 unsigned char *sensebuf;
163 dma_addr_t cr_dma;
164 dma_addr_t iobuf_dma;
165 struct task_struct *ctl_thread;
166
167
168 struct completion cmnd_ready;
169 struct completion notify;
170 wait_queue_head_t delay_wait;
171 struct completion scanning_done;
172
173
174 void *extra;
175 extra_data_destructor extra_destructor;
176#ifdef CONFIG_PM
177 pm_hook suspend_resume_hook;
178#endif
179
180 SD_STATUS SD_Status;
181 MS_STATUS MS_Status;
182 SM_STATUS SM_Status;
183
184
185
186 WORD SD_Block_Mult;
187 BYTE SD_READ_BL_LEN;
188 WORD SD_C_SIZE;
189 BYTE SD_C_SIZE_MULT;
190
191
192 BYTE SD_SPEC_VER;
193 BYTE SD_CSD_VER;
194 BYTE SD20_HIGH_CAPACITY;
195 DWORD HC_C_SIZE;
196 BYTE MMC_SPEC_VER;
197 BYTE MMC_BusWidth;
198 BYTE MMC_HIGH_CAPACITY;
199
200
201 BOOLEAN MS_SWWP;
202 DWORD MSP_TotalBlock;
203
204 BOOLEAN MS_IsRWPage;
205 WORD MS_Model;
206
207
208 BYTE SM_DeviceID;
209 BYTE SM_CardID;
210
211 PBYTE testbuf;
212 BYTE BIN_FLAG;
213 DWORD bl_num;
214 int SrbStatus;
215
216
217 BOOLEAN Power_IsResum;
218};
219
220
221static inline struct Scsi_Host *us_to_host(struct us_data *us) {
222 return container_of((void *) us, struct Scsi_Host, hostdata);
223}
224static inline struct us_data *host_to_us(struct Scsi_Host *host) {
225 return (struct us_data *) host->hostdata;
226}
227
228
229extern void fill_inquiry_response(struct us_data *us,
230 unsigned char *data, unsigned int data_len);
231
232
233
234#define scsi_unlock(host) spin_unlock_irq(host->host_lock)
235#define scsi_lock(host) spin_lock_irq(host->host_lock)
236
237#endif
238