This source file includes following definitions.
- cypress_atacb_passthrough
- cypress_probe
1
2
3
4
5
6
7
8
9 #include <linux/module.h>
10 #include <scsi/scsi.h>
11 #include <scsi/scsi_cmnd.h>
12 #include <scsi/scsi_eh.h>
13 #include <linux/ata.h>
14
15 #include "usb.h"
16 #include "protocol.h"
17 #include "scsiglue.h"
18 #include "debug.h"
19
20 #define DRV_NAME "ums-cypress"
21
22 MODULE_DESCRIPTION("SAT support for Cypress USB/ATA bridges with ATACB");
23 MODULE_AUTHOR("Matthieu Castet <castet.matthieu@free.fr>");
24 MODULE_LICENSE("GPL");
25 MODULE_IMPORT_NS(USB_STORAGE);
26
27
28
29
30 #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
31 vendorName, productName, useProtocol, useTransport, \
32 initFunction, flags) \
33 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
34 .driver_info = (flags) }
35
36 static struct usb_device_id cypress_usb_ids[] = {
37 # include "unusual_cypress.h"
38 { }
39 };
40 MODULE_DEVICE_TABLE(usb, cypress_usb_ids);
41
42 #undef UNUSUAL_DEV
43
44
45
46
47 #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
48 vendor_name, product_name, use_protocol, use_transport, \
49 init_function, Flags) \
50 { \
51 .vendorName = vendor_name, \
52 .productName = product_name, \
53 .useProtocol = use_protocol, \
54 .useTransport = use_transport, \
55 .initFunction = init_function, \
56 }
57
58 static struct us_unusual_dev cypress_unusual_dev_list[] = {
59 # include "unusual_cypress.h"
60 { }
61 };
62
63 #undef UNUSUAL_DEV
64
65
66
67
68
69
70
71
72
73 static void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us)
74 {
75 unsigned char save_cmnd[MAX_COMMAND_SIZE];
76
77 if (likely(srb->cmnd[0] != ATA_16 && srb->cmnd[0] != ATA_12)) {
78 usb_stor_transparent_scsi_command(srb, us);
79 return;
80 }
81
82 memcpy(save_cmnd, srb->cmnd, sizeof(save_cmnd));
83 memset(srb->cmnd, 0, MAX_COMMAND_SIZE);
84
85
86 if (save_cmnd[1] >> 5)
87 goto invalid_fld;
88
89 switch ((save_cmnd[1] >> 1) & 0xf) {
90 case 3:
91 case 4:
92 case 5:
93 break;
94 default:
95 goto invalid_fld;
96 }
97
98
99 srb->cmd_len = 16;
100
101 srb->cmnd[0] = 0x24;
102
103
104
105
106 srb->cmnd[1] = 0x24;
107
108 srb->cmnd[3] = 0xff - 1;
109
110
111
112 srb->cmnd[4] = 1;
113
114 if (save_cmnd[0] == ATA_16) {
115 srb->cmnd[ 6] = save_cmnd[ 4];
116 srb->cmnd[ 7] = save_cmnd[ 6];
117 srb->cmnd[ 8] = save_cmnd[ 8];
118 srb->cmnd[ 9] = save_cmnd[10];
119 srb->cmnd[10] = save_cmnd[12];
120 srb->cmnd[11] = save_cmnd[13];
121 srb->cmnd[12] = save_cmnd[14];
122
123 if (save_cmnd[1] & 0x01) {
124
125 if (save_cmnd[3] || save_cmnd[5] || save_cmnd[7] || save_cmnd[9]
126 || save_cmnd[11])
127 goto invalid_fld;
128 }
129 } else {
130 srb->cmnd[ 6] = save_cmnd[3];
131 srb->cmnd[ 7] = save_cmnd[4];
132 srb->cmnd[ 8] = save_cmnd[5];
133 srb->cmnd[ 9] = save_cmnd[6];
134 srb->cmnd[10] = save_cmnd[7];
135 srb->cmnd[11] = save_cmnd[8];
136 srb->cmnd[12] = save_cmnd[9];
137
138 }
139
140 if ((srb->cmnd[12] == ATA_CMD_SET_FEATURES)
141 && (srb->cmnd[6] == SETFEATURES_XFER))
142 goto invalid_fld;
143
144 if (srb->cmnd[12] == ATA_CMD_ID_ATA || srb->cmnd[12] == ATA_CMD_ID_ATAPI)
145 srb->cmnd[2] |= (1<<7);
146
147
148 usb_stor_transparent_scsi_command(srb, us);
149
150
151 if (srb->result == SAM_STAT_CHECK_CONDITION &&
152 memcmp(srb->sense_buffer, usb_stor_sense_invalidCDB,
153 sizeof(usb_stor_sense_invalidCDB)) == 0) {
154 usb_stor_dbg(us, "cypress atacb not supported ???\n");
155 goto end;
156 }
157
158
159
160
161
162 if ((srb->result != (DID_ERROR << 16) &&
163 srb->result != (DID_ABORT << 16)) &&
164 save_cmnd[2] & 0x20) {
165 struct scsi_eh_save ses;
166 unsigned char regs[8];
167 unsigned char *sb = srb->sense_buffer;
168 unsigned char *desc = sb + 8;
169 int tmp_result;
170
171
172 scsi_eh_prep_cmnd(srb, &ses, NULL, 0, sizeof(regs));
173
174
175
176
177
178
179 srb->cmd_len = 16;
180 srb->cmnd = ses.cmnd;
181 srb->cmnd[2] = 1;
182
183 usb_stor_transparent_scsi_command(srb, us);
184 memcpy(regs, srb->sense_buffer, sizeof(regs));
185 tmp_result = srb->result;
186 scsi_eh_restore_cmnd(srb, &ses);
187
188 if (tmp_result != SAM_STAT_GOOD)
189 goto invalid_fld;
190
191
192 memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
193
194
195 sb[1] = RECOVERED_ERROR;
196 sb[2] = 0;
197 sb[3] = 0x1D;
198
199
200
201
202
203
204
205
206
207 sb[0] = 0x72;
208 desc[0] = 0x09;
209
210
211 sb[7] = 14;
212 desc[1] = 12;
213
214
215 desc[ 2] = 0x00;
216 desc[ 3] = regs[1];
217 desc[ 5] = regs[2];
218 desc[ 7] = regs[3];
219 desc[ 9] = regs[4];
220 desc[11] = regs[5];
221 desc[12] = regs[6];
222 desc[13] = regs[7];
223
224 srb->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
225 }
226 goto end;
227 invalid_fld:
228 srb->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
229
230 memcpy(srb->sense_buffer,
231 usb_stor_sense_invalidCDB,
232 sizeof(usb_stor_sense_invalidCDB));
233 end:
234 memcpy(srb->cmnd, save_cmnd, sizeof(save_cmnd));
235 if (srb->cmnd[0] == ATA_12)
236 srb->cmd_len = 12;
237 }
238
239 static struct scsi_host_template cypress_host_template;
240
241 static int cypress_probe(struct usb_interface *intf,
242 const struct usb_device_id *id)
243 {
244 struct us_data *us;
245 int result;
246 struct usb_device *device;
247
248 result = usb_stor_probe1(&us, intf, id,
249 (id - cypress_usb_ids) + cypress_unusual_dev_list,
250 &cypress_host_template);
251 if (result)
252 return result;
253
254
255
256
257
258 device = interface_to_usbdev(intf);
259 if (device->descriptor.iManufacturer != 0x38 ||
260 device->descriptor.iProduct != 0x4e ||
261 device->descriptor.iSerialNumber != 0x64) {
262 us->protocol_name = "Transparent SCSI with Cypress ATACB";
263 us->proto_handler = cypress_atacb_passthrough;
264 } else {
265 us->protocol_name = "Transparent SCSI";
266 us->proto_handler = usb_stor_transparent_scsi_command;
267 }
268
269 result = usb_stor_probe2(us);
270 return result;
271 }
272
273 static struct usb_driver cypress_driver = {
274 .name = DRV_NAME,
275 .probe = cypress_probe,
276 .disconnect = usb_stor_disconnect,
277 .suspend = usb_stor_suspend,
278 .resume = usb_stor_resume,
279 .reset_resume = usb_stor_reset_resume,
280 .pre_reset = usb_stor_pre_reset,
281 .post_reset = usb_stor_post_reset,
282 .id_table = cypress_usb_ids,
283 .soft_unbind = 1,
284 .no_dynamic_id = 1,
285 };
286
287 module_usb_stor_driver(cypress_driver, cypress_host_template, DRV_NAME);