48 #include <linux/errno.h>
49 #include <linux/module.h>
50 #include <linux/slab.h>
52 #include <scsi/scsi.h>
68 #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
69 vendorName, productName, useProtocol, useTransport, \
70 initFunction, flags) \
71 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
72 .driver_info = (flags) }
85 #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
86 vendor_name, product_name, use_protocol, use_transport, \
87 init_function, Flags) \
89 .vendorName = vendor_name, \
90 .productName = product_name, \
91 .useProtocol = use_protocol, \
92 .useTransport = use_transport, \
93 .initFunction = init_function, \
114 static inline int jumpshot_bulk_read(
struct us_data *us,
121 US_DEBUGP(
"jumpshot_bulk_read: len = %d\n", len);
127 static inline int jumpshot_bulk_write(
struct us_data *us,
134 US_DEBUGP(
"jumpshot_bulk_write: len = %d\n", len);
140 static int jumpshot_get_status(
struct us_data *us)
149 0, 0xA0, 0, 7, us->
iobuf, 1);
154 if (us->
iobuf[0] != 0x50) {
155 US_DEBUGP(
"jumpshot_get_status: 0x%2x\n",
163 static int jumpshot_read_data(
struct us_data *us,
170 unsigned char thistime;
171 unsigned int totallen, alloclen;
173 unsigned int sg_offset = 0;
181 if (sector > 0x0FFFFFFF)
184 totallen = sectors * info->
ssize;
190 alloclen =
min(totallen, 65536
u);
198 len =
min(totallen, alloclen);
199 thistime = (len / info->
ssize) & 0xff;
202 command[1] = thistime;
203 command[2] = sector & 0xFF;
204 command[3] = (sector >> 8) & 0xFF;
205 command[4] = (sector >> 16) & 0xFF;
207 command[5] = 0xE0 | ((sector >> 24) & 0x0F);
212 0, 0x20, 0, 1, command, 7);
217 result = jumpshot_bulk_read(us, buffer, len);
221 US_DEBUGP(
"jumpshot_read_data: %d bytes\n", len);
229 }
while (totallen > 0);
240 static int jumpshot_write_data(
struct us_data *us,
245 unsigned char *command = us->
iobuf;
247 unsigned char thistime;
248 unsigned int totallen, alloclen;
249 int len,
result, waitcount;
250 unsigned int sg_offset = 0;
258 if (sector > 0x0FFFFFFF)
261 totallen = sectors * info->
ssize;
267 alloclen =
min(totallen, 65536
u);
276 len =
min(totallen, alloclen);
277 thistime = (len / info->
ssize) & 0xff;
284 command[1] = thistime;
285 command[2] = sector & 0xFF;
286 command[3] = (sector >> 8) & 0xFF;
287 command[4] = (sector >> 16) & 0xFF;
289 command[5] = 0xE0 | ((sector >> 24) & 0x0F);
294 0, 0x20, 0, 1, command, 7);
299 result = jumpshot_bulk_write(us, buffer, len);
308 result = jumpshot_get_status(us);
317 US_DEBUGP(
"jumpshot_write_data: Gah! Waitcount = 10. Bad write!?\n");
321 }
while (totallen > 0);
331 static int jumpshot_id_device(
struct us_data *us,
334 unsigned char *command = us->
iobuf;
335 unsigned char *reply;
349 0, 0x20, 0, 6, command, 2);
353 "send_control for read_capacity failed\n");
359 rc = jumpshot_bulk_read(us, reply, 512);
366 ((
u32)(reply[116]) << 16) |
367 ((
u32)(reply[115]) << 8) |
368 ((
u32)(reply[114]) );
377 static int jumpshot_handle_mode_sense(
struct us_data *us,
381 static unsigned char rw_err_page[12] = {
382 0x1, 0xA, 0x21, 1, 0, 0, 0, 0, 1, 0, 0, 0
384 static unsigned char cache_page[12] = {
385 0x8, 0xA, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0
387 static unsigned char rbac_page[12] = {
388 0x1B, 0xA, 0, 0x81, 0, 0, 0, 0, 0, 0, 0, 0
390 static unsigned char timer_page[8] = {
391 0x1C, 0x6, 0, 0, 0, 0
398 pc = srb->
cmnd[2] >> 6;
399 page_code = srb->
cmnd[2] & 0x3F;
403 US_DEBUGP(
"jumpshot_handle_mode_sense: Current values\n");
406 US_DEBUGP(
"jumpshot_handle_mode_sense: Changeable values\n");
409 US_DEBUGP(
"jumpshot_handle_mode_sense: Default values\n");
412 US_DEBUGP(
"jumpshot_handle_mode_sense: Saves values\n");
434 memcpy(ptr + i, rw_err_page,
sizeof(rw_err_page));
435 i +=
sizeof(rw_err_page);
439 memcpy(ptr + i, cache_page,
sizeof(cache_page));
440 i +=
sizeof(cache_page);
444 memcpy(ptr + i, rbac_page,
sizeof(rbac_page));
445 i +=
sizeof(rbac_page);
449 memcpy(ptr + i, timer_page,
sizeof(timer_page));
450 i +=
sizeof(timer_page);
454 memcpy(ptr + i, timer_page,
sizeof(timer_page));
455 i +=
sizeof(timer_page);
456 memcpy(ptr + i, rbac_page,
sizeof(rbac_page));
457 i +=
sizeof(rbac_page);
458 memcpy(ptr + i, cache_page,
sizeof(cache_page));
459 i +=
sizeof(cache_page);
460 memcpy(ptr + i, rw_err_page,
sizeof(rw_err_page));
461 i +=
sizeof(rw_err_page);
475 static void jumpshot_info_destructor(
void *
extra)
489 unsigned long block, blocks;
490 unsigned char *ptr = us->
iobuf;
491 static unsigned char inquiry_response[8] = {
492 0x00, 0x80, 0x00, 0x01, 0x1F, 0x00, 0x00, 0x00
498 US_DEBUGP(
"jumpshot_transport: Gah! Can't allocate storage for jumpshot info struct!\n");
507 US_DEBUGP(
"jumpshot_transport: INQUIRY. Returning bogus response.\n");
508 memcpy(ptr, inquiry_response,
sizeof(inquiry_response));
516 rc = jumpshot_get_status(us);
520 rc = jumpshot_id_device(us, info);
524 US_DEBUGP(
"jumpshot_transport: READ_CAPACITY: %ld sectors, %ld bytes per sector\n",
537 US_DEBUGP(
"jumpshot_transport: Gah! MODE_SELECT_10.\n");
542 block = ((
u32)(srb->
cmnd[2]) << 24) | ((
u32)(srb->
cmnd[3]) << 16) |
547 US_DEBUGP(
"jumpshot_transport: READ_10: read block 0x%04lx count %ld\n", block, blocks);
548 return jumpshot_read_data(us, info, block, blocks);
554 block = ((
u32)(srb->
cmnd[2]) << 24) | ((
u32)(srb->
cmnd[3]) << 16) |
557 blocks = ((
u32)(srb->
cmnd[6]) << 24) | ((
u32)(srb->
cmnd[7]) << 16) |
560 US_DEBUGP(
"jumpshot_transport: READ_12: read block 0x%04lx count %ld\n", block, blocks);
561 return jumpshot_read_data(us, info, block, blocks);
565 block = ((
u32)(srb->
cmnd[2]) << 24) | ((
u32)(srb->
cmnd[3]) << 16) |
570 US_DEBUGP(
"jumpshot_transport: WRITE_10: write block 0x%04lx count %ld\n", block, blocks);
571 return jumpshot_write_data(us, info, block, blocks);
577 block = ((
u32)(srb->
cmnd[2]) << 24) | ((
u32)(srb->
cmnd[3]) << 16) |
580 blocks = ((
u32)(srb->
cmnd[6]) << 24) | ((
u32)(srb->
cmnd[7]) << 16) |
583 US_DEBUGP(
"jumpshot_transport: WRITE_12: write block 0x%04lx count %ld\n", block, blocks);
584 return jumpshot_write_data(us, info, block, blocks);
589 US_DEBUGP(
"jumpshot_transport: TEST_UNIT_READY.\n");
590 return jumpshot_get_status(us);
594 US_DEBUGP(
"jumpshot_transport: REQUEST_SENSE.\n");
608 US_DEBUGP(
"jumpshot_transport: MODE_SENSE_6 detected\n");
609 return jumpshot_handle_mode_sense(us, srb, 1);
613 US_DEBUGP(
"jumpshot_transport: MODE_SENSE_10 detected\n");
614 return jumpshot_handle_mode_sense(us, srb, 0);
627 US_DEBUGP(
"jumpshot_transport: START_STOP.\n");
630 rc = jumpshot_id_device(us, info);
641 US_DEBUGP(
"jumpshot_transport: Gah! Unknown command: %d (0x%x)\n",
656 (
id - jumpshot_usb_ids) + jumpshot_unusual_dev_list);
669 static struct usb_driver jumpshot_driver = {
670 .name =
"ums-jumpshot",
671 .probe = jumpshot_probe,
678 .id_table = jumpshot_usb_ids,