jumpshot.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. * Driver for Lexar "Jumpshot" Compact Flash reader
  3. *
  4. * jumpshot driver v0.1:
  5. *
  6. * First release
  7. *
  8. * Current development and maintenance by:
  9. * (c) 2000 Jimmie Mayfield (mayfield+usb@sackheads.org)
  10. *
  11. * Many thanks to Robert Baruch for the SanDisk SmartMedia reader driver
  12. * which I used as a template for this driver.
  13. *
  14. * Some bugfixes and scatter-gather code by Gregory P. Smith
  15. * (greg-usb@electricrain.com)
  16. *
  17. * Fix for media change by Joerg Schneider (js@joergschneider.com)
  18. *
  19. * Developed with the assistance of:
  20. *
  21. * (C) 2002 Alan Stern <stern@rowland.org>
  22. *
  23. * This program is free software; you can redistribute it and/or modify it
  24. * under the terms of the GNU General Public License as published by the
  25. * Free Software Foundation; either version 2, or (at your option) any
  26. * later version.
  27. *
  28. * This program is distributed in the hope that it will be useful, but
  29. * WITHOUT ANY WARRANTY; without even the implied warranty of
  30. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  31. * General Public License for more details.
  32. *
  33. * You should have received a copy of the GNU General Public License along
  34. * with this program; if not, write to the Free Software Foundation, Inc.,
  35. * 675 Mass Ave, Cambridge, MA 02139, USA.
  36. */
  37. /*
  38. * This driver attempts to support the Lexar Jumpshot USB CompactFlash
  39. * reader. Like many other USB CompactFlash readers, the Jumpshot contains
  40. * a USB-to-ATA chip.
  41. *
  42. * This driver supports reading and writing. If you're truly paranoid,
  43. * however, you can force the driver into a write-protected state by setting
  44. * the WP enable bits in jumpshot_handle_mode_sense. See the comments
  45. * in that routine.
  46. */
  47. #include <linux/errno.h>
  48. #include <linux/module.h>
  49. #include <linux/slab.h>
  50. #include <scsi/scsi.h>
  51. #include <scsi/scsi_cmnd.h>
  52. #include "usb.h"
  53. #include "transport.h"
  54. #include "protocol.h"
  55. #include "debug.h"
  56. #include "scsiglue.h"
  57. #define DRV_NAME "ums-jumpshot"
  58. MODULE_DESCRIPTION("Driver for Lexar \"Jumpshot\" Compact Flash reader");
  59. MODULE_AUTHOR("Jimmie Mayfield <mayfield+usb@sackheads.org>");
  60. MODULE_LICENSE("GPL");
  61. /*
  62. * The table of devices
  63. */
  64. #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
  65. vendorName, productName, useProtocol, useTransport, \
  66. initFunction, flags) \
  67. { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
  68. .driver_info = (flags) }
  69. static struct usb_device_id jumpshot_usb_ids[] = {
  70. # include "unusual_jumpshot.h"
  71. { } /* Terminating entry */
  72. };
  73. MODULE_DEVICE_TABLE(usb, jumpshot_usb_ids);
  74. #undef UNUSUAL_DEV
  75. /*
  76. * The flags table
  77. */
  78. #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
  79. vendor_name, product_name, use_protocol, use_transport, \
  80. init_function, Flags) \
  81. { \
  82. .vendorName = vendor_name, \
  83. .productName = product_name, \
  84. .useProtocol = use_protocol, \
  85. .useTransport = use_transport, \
  86. .initFunction = init_function, \
  87. }
  88. static struct us_unusual_dev jumpshot_unusual_dev_list[] = {
  89. # include "unusual_jumpshot.h"
  90. { } /* Terminating entry */
  91. };
  92. #undef UNUSUAL_DEV
  93. struct jumpshot_info {
  94. unsigned long sectors; /* total sector count */
  95. unsigned long ssize; /* sector size in bytes */
  96. /* the following aren't used yet */
  97. unsigned char sense_key;
  98. unsigned long sense_asc; /* additional sense code */
  99. unsigned long sense_ascq; /* additional sense code qualifier */
  100. };
  101. static inline int jumpshot_bulk_read(struct us_data *us,
  102. unsigned char *data,
  103. unsigned int len)
  104. {
  105. if (len == 0)
  106. return USB_STOR_XFER_GOOD;
  107. usb_stor_dbg(us, "len = %d\n", len);
  108. return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
  109. data, len, NULL);
  110. }
  111. static inline int jumpshot_bulk_write(struct us_data *us,
  112. unsigned char *data,
  113. unsigned int len)
  114. {
  115. if (len == 0)
  116. return USB_STOR_XFER_GOOD;
  117. usb_stor_dbg(us, "len = %d\n", len);
  118. return usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
  119. data, len, NULL);
  120. }
  121. static int jumpshot_get_status(struct us_data *us)
  122. {
  123. int rc;
  124. if (!us)
  125. return USB_STOR_TRANSPORT_ERROR;
  126. // send the setup
  127. rc = usb_stor_ctrl_transfer(us, us->recv_ctrl_pipe,
  128. 0, 0xA0, 0, 7, us->iobuf, 1);
  129. if (rc != USB_STOR_XFER_GOOD)
  130. return USB_STOR_TRANSPORT_ERROR;
  131. if (us->iobuf[0] != 0x50) {
  132. usb_stor_dbg(us, "0x%2x\n", us->iobuf[0]);
  133. return USB_STOR_TRANSPORT_ERROR;
  134. }
  135. return USB_STOR_TRANSPORT_GOOD;
  136. }
  137. static int jumpshot_read_data(struct us_data *us,
  138. struct jumpshot_info *info,
  139. u32 sector,
  140. u32 sectors)
  141. {
  142. unsigned char *command = us->iobuf;
  143. unsigned char *buffer;
  144. unsigned char thistime;
  145. unsigned int totallen, alloclen;
  146. int len, result;
  147. unsigned int sg_offset = 0;
  148. struct scatterlist *sg = NULL;
  149. // we're working in LBA mode. according to the ATA spec,
  150. // we can support up to 28-bit addressing. I don't know if Jumpshot
  151. // supports beyond 24-bit addressing. It's kind of hard to test
  152. // since it requires > 8GB CF card.
  153. if (sector > 0x0FFFFFFF)
  154. return USB_STOR_TRANSPORT_ERROR;
  155. totallen = sectors * info->ssize;
  156. // Since we don't read more than 64 KB at a time, we have to create
  157. // a bounce buffer and move the data a piece at a time between the
  158. // bounce buffer and the actual transfer buffer.
  159. alloclen = min(totallen, 65536u);
  160. buffer = kmalloc(alloclen, GFP_NOIO);
  161. if (buffer == NULL)
  162. return USB_STOR_TRANSPORT_ERROR;
  163. do {
  164. // loop, never allocate or transfer more than 64k at once
  165. // (min(128k, 255*info->ssize) is the real limit)
  166. len = min(totallen, alloclen);
  167. thistime = (len / info->ssize) & 0xff;
  168. command[0] = 0;
  169. command[1] = thistime;
  170. command[2] = sector & 0xFF;
  171. command[3] = (sector >> 8) & 0xFF;
  172. command[4] = (sector >> 16) & 0xFF;
  173. command[5] = 0xE0 | ((sector >> 24) & 0x0F);
  174. command[6] = 0x20;
  175. // send the setup + command
  176. result = usb_stor_ctrl_transfer(us, us->send_ctrl_pipe,
  177. 0, 0x20, 0, 1, command, 7);
  178. if (result != USB_STOR_XFER_GOOD)
  179. goto leave;
  180. // read the result
  181. result = jumpshot_bulk_read(us, buffer, len);
  182. if (result != USB_STOR_XFER_GOOD)
  183. goto leave;
  184. usb_stor_dbg(us, "%d bytes\n", len);
  185. // Store the data in the transfer buffer
  186. usb_stor_access_xfer_buf(buffer, len, us->srb,
  187. &sg, &sg_offset, TO_XFER_BUF);
  188. sector += thistime;
  189. totallen -= len;
  190. } while (totallen > 0);
  191. kfree(buffer);
  192. return USB_STOR_TRANSPORT_GOOD;
  193. leave:
  194. kfree(buffer);
  195. return USB_STOR_TRANSPORT_ERROR;
  196. }
  197. static int jumpshot_write_data(struct us_data *us,
  198. struct jumpshot_info *info,
  199. u32 sector,
  200. u32 sectors)
  201. {
  202. unsigned char *command = us->iobuf;
  203. unsigned char *buffer;
  204. unsigned char thistime;
  205. unsigned int totallen, alloclen;
  206. int len, result, waitcount;
  207. unsigned int sg_offset = 0;
  208. struct scatterlist *sg = NULL;
  209. // we're working in LBA mode. according to the ATA spec,
  210. // we can support up to 28-bit addressing. I don't know if Jumpshot
  211. // supports beyond 24-bit addressing. It's kind of hard to test
  212. // since it requires > 8GB CF card.
  213. //
  214. if (sector > 0x0FFFFFFF)
  215. return USB_STOR_TRANSPORT_ERROR;
  216. totallen = sectors * info->ssize;
  217. // Since we don't write more than 64 KB at a time, we have to create
  218. // a bounce buffer and move the data a piece at a time between the
  219. // bounce buffer and the actual transfer buffer.
  220. alloclen = min(totallen, 65536u);
  221. buffer = kmalloc(alloclen, GFP_NOIO);
  222. if (buffer == NULL)
  223. return USB_STOR_TRANSPORT_ERROR;
  224. do {
  225. // loop, never allocate or transfer more than 64k at once
  226. // (min(128k, 255*info->ssize) is the real limit)
  227. len = min(totallen, alloclen);
  228. thistime = (len / info->ssize) & 0xff;
  229. // Get the data from the transfer buffer
  230. usb_stor_access_xfer_buf(buffer, len, us->srb,
  231. &sg, &sg_offset, FROM_XFER_BUF);
  232. command[0] = 0;
  233. command[1] = thistime;
  234. command[2] = sector & 0xFF;
  235. command[3] = (sector >> 8) & 0xFF;
  236. command[4] = (sector >> 16) & 0xFF;
  237. command[5] = 0xE0 | ((sector >> 24) & 0x0F);
  238. command[6] = 0x30;
  239. // send the setup + command
  240. result = usb_stor_ctrl_transfer(us, us->send_ctrl_pipe,
  241. 0, 0x20, 0, 1, command, 7);
  242. if (result != USB_STOR_XFER_GOOD)
  243. goto leave;
  244. // send the data
  245. result = jumpshot_bulk_write(us, buffer, len);
  246. if (result != USB_STOR_XFER_GOOD)
  247. goto leave;
  248. // read the result. apparently the bulk write can complete
  249. // before the jumpshot drive is finished writing. so we loop
  250. // here until we get a good return code
  251. waitcount = 0;
  252. do {
  253. result = jumpshot_get_status(us);
  254. if (result != USB_STOR_TRANSPORT_GOOD) {
  255. // I have not experimented to find the smallest value.
  256. //
  257. msleep(50);
  258. }
  259. } while ((result != USB_STOR_TRANSPORT_GOOD) && (waitcount < 10));
  260. if (result != USB_STOR_TRANSPORT_GOOD)
  261. usb_stor_dbg(us, "Gah! Waitcount = 10. Bad write!?\n");
  262. sector += thistime;
  263. totallen -= len;
  264. } while (totallen > 0);
  265. kfree(buffer);
  266. return result;
  267. leave:
  268. kfree(buffer);
  269. return USB_STOR_TRANSPORT_ERROR;
  270. }
  271. static int jumpshot_id_device(struct us_data *us,
  272. struct jumpshot_info *info)
  273. {
  274. unsigned char *command = us->iobuf;
  275. unsigned char *reply;
  276. int rc;
  277. if (!info)
  278. return USB_STOR_TRANSPORT_ERROR;
  279. command[0] = 0xE0;
  280. command[1] = 0xEC;
  281. reply = kmalloc(512, GFP_NOIO);
  282. if (!reply)
  283. return USB_STOR_TRANSPORT_ERROR;
  284. // send the setup
  285. rc = usb_stor_ctrl_transfer(us, us->send_ctrl_pipe,
  286. 0, 0x20, 0, 6, command, 2);
  287. if (rc != USB_STOR_XFER_GOOD) {
  288. usb_stor_dbg(us, "Gah! send_control for read_capacity failed\n");
  289. rc = USB_STOR_TRANSPORT_ERROR;
  290. goto leave;
  291. }
  292. // read the reply
  293. rc = jumpshot_bulk_read(us, reply, 512);
  294. if (rc != USB_STOR_XFER_GOOD) {
  295. rc = USB_STOR_TRANSPORT_ERROR;
  296. goto leave;
  297. }
  298. info->sectors = ((u32)(reply[117]) << 24) |
  299. ((u32)(reply[116]) << 16) |
  300. ((u32)(reply[115]) << 8) |
  301. ((u32)(reply[114]) );
  302. rc = USB_STOR_TRANSPORT_GOOD;
  303. leave:
  304. kfree(reply);
  305. return rc;
  306. }
  307. static int jumpshot_handle_mode_sense(struct us_data *us,
  308. struct scsi_cmnd * srb,
  309. int sense_6)
  310. {
  311. static unsigned char rw_err_page[12] = {
  312. 0x1, 0xA, 0x21, 1, 0, 0, 0, 0, 1, 0, 0, 0
  313. };
  314. static unsigned char cache_page[12] = {
  315. 0x8, 0xA, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0
  316. };
  317. static unsigned char rbac_page[12] = {
  318. 0x1B, 0xA, 0, 0x81, 0, 0, 0, 0, 0, 0, 0, 0
  319. };
  320. static unsigned char timer_page[8] = {
  321. 0x1C, 0x6, 0, 0, 0, 0
  322. };
  323. unsigned char pc, page_code;
  324. unsigned int i = 0;
  325. struct jumpshot_info *info = (struct jumpshot_info *) (us->extra);
  326. unsigned char *ptr = us->iobuf;
  327. pc = srb->cmnd[2] >> 6;
  328. page_code = srb->cmnd[2] & 0x3F;
  329. switch (pc) {
  330. case 0x0:
  331. usb_stor_dbg(us, "Current values\n");
  332. break;
  333. case 0x1:
  334. usb_stor_dbg(us, "Changeable values\n");
  335. break;
  336. case 0x2:
  337. usb_stor_dbg(us, "Default values\n");
  338. break;
  339. case 0x3:
  340. usb_stor_dbg(us, "Saves values\n");
  341. break;
  342. }
  343. memset(ptr, 0, 8);
  344. if (sense_6) {
  345. ptr[2] = 0x00; // WP enable: 0x80
  346. i = 4;
  347. } else {
  348. ptr[3] = 0x00; // WP enable: 0x80
  349. i = 8;
  350. }
  351. switch (page_code) {
  352. case 0x0:
  353. // vendor-specific mode
  354. info->sense_key = 0x05;
  355. info->sense_asc = 0x24;
  356. info->sense_ascq = 0x00;
  357. return USB_STOR_TRANSPORT_FAILED;
  358. case 0x1:
  359. memcpy(ptr + i, rw_err_page, sizeof(rw_err_page));
  360. i += sizeof(rw_err_page);
  361. break;
  362. case 0x8:
  363. memcpy(ptr + i, cache_page, sizeof(cache_page));
  364. i += sizeof(cache_page);
  365. break;
  366. case 0x1B:
  367. memcpy(ptr + i, rbac_page, sizeof(rbac_page));
  368. i += sizeof(rbac_page);
  369. break;
  370. case 0x1C:
  371. memcpy(ptr + i, timer_page, sizeof(timer_page));
  372. i += sizeof(timer_page);
  373. break;
  374. case 0x3F:
  375. memcpy(ptr + i, timer_page, sizeof(timer_page));
  376. i += sizeof(timer_page);
  377. memcpy(ptr + i, rbac_page, sizeof(rbac_page));
  378. i += sizeof(rbac_page);
  379. memcpy(ptr + i, cache_page, sizeof(cache_page));
  380. i += sizeof(cache_page);
  381. memcpy(ptr + i, rw_err_page, sizeof(rw_err_page));
  382. i += sizeof(rw_err_page);
  383. break;
  384. }
  385. if (sense_6)
  386. ptr[0] = i - 1;
  387. else
  388. ((__be16 *) ptr)[0] = cpu_to_be16(i - 2);
  389. usb_stor_set_xfer_buf(ptr, i, srb);
  390. return USB_STOR_TRANSPORT_GOOD;
  391. }
  392. static void jumpshot_info_destructor(void *extra)
  393. {
  394. // this routine is a placeholder...
  395. // currently, we don't allocate any extra blocks so we're okay
  396. }
  397. // Transport for the Lexar 'Jumpshot'
  398. //
  399. static int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us)
  400. {
  401. struct jumpshot_info *info;
  402. int rc;
  403. unsigned long block, blocks;
  404. unsigned char *ptr = us->iobuf;
  405. static unsigned char inquiry_response[8] = {
  406. 0x00, 0x80, 0x00, 0x01, 0x1F, 0x00, 0x00, 0x00
  407. };
  408. if (!us->extra) {
  409. us->extra = kzalloc(sizeof(struct jumpshot_info), GFP_NOIO);
  410. if (!us->extra)
  411. return USB_STOR_TRANSPORT_ERROR;
  412. us->extra_destructor = jumpshot_info_destructor;
  413. }
  414. info = (struct jumpshot_info *) (us->extra);
  415. if (srb->cmnd[0] == INQUIRY) {
  416. usb_stor_dbg(us, "INQUIRY - Returning bogus response\n");
  417. memcpy(ptr, inquiry_response, sizeof(inquiry_response));
  418. fill_inquiry_response(us, ptr, 36);
  419. return USB_STOR_TRANSPORT_GOOD;
  420. }
  421. if (srb->cmnd[0] == READ_CAPACITY) {
  422. info->ssize = 0x200; // hard coded 512 byte sectors as per ATA spec
  423. rc = jumpshot_get_status(us);
  424. if (rc != USB_STOR_TRANSPORT_GOOD)
  425. return rc;
  426. rc = jumpshot_id_device(us, info);
  427. if (rc != USB_STOR_TRANSPORT_GOOD)
  428. return rc;
  429. usb_stor_dbg(us, "READ_CAPACITY: %ld sectors, %ld bytes per sector\n",
  430. info->sectors, info->ssize);
  431. // build the reply
  432. //
  433. ((__be32 *) ptr)[0] = cpu_to_be32(info->sectors - 1);
  434. ((__be32 *) ptr)[1] = cpu_to_be32(info->ssize);
  435. usb_stor_set_xfer_buf(ptr, 8, srb);
  436. return USB_STOR_TRANSPORT_GOOD;
  437. }
  438. if (srb->cmnd[0] == MODE_SELECT_10) {
  439. usb_stor_dbg(us, "Gah! MODE_SELECT_10\n");
  440. return USB_STOR_TRANSPORT_ERROR;
  441. }
  442. if (srb->cmnd[0] == READ_10) {
  443. block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
  444. ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
  445. blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8]));
  446. usb_stor_dbg(us, "READ_10: read block 0x%04lx count %ld\n",
  447. block, blocks);
  448. return jumpshot_read_data(us, info, block, blocks);
  449. }
  450. if (srb->cmnd[0] == READ_12) {
  451. // I don't think we'll ever see a READ_12 but support it anyway...
  452. //
  453. block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
  454. ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
  455. blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) |
  456. ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9]));
  457. usb_stor_dbg(us, "READ_12: read block 0x%04lx count %ld\n",
  458. block, blocks);
  459. return jumpshot_read_data(us, info, block, blocks);
  460. }
  461. if (srb->cmnd[0] == WRITE_10) {
  462. block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
  463. ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
  464. blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8]));
  465. usb_stor_dbg(us, "WRITE_10: write block 0x%04lx count %ld\n",
  466. block, blocks);
  467. return jumpshot_write_data(us, info, block, blocks);
  468. }
  469. if (srb->cmnd[0] == WRITE_12) {
  470. // I don't think we'll ever see a WRITE_12 but support it anyway...
  471. //
  472. block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
  473. ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
  474. blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) |
  475. ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9]));
  476. usb_stor_dbg(us, "WRITE_12: write block 0x%04lx count %ld\n",
  477. block, blocks);
  478. return jumpshot_write_data(us, info, block, blocks);
  479. }
  480. if (srb->cmnd[0] == TEST_UNIT_READY) {
  481. usb_stor_dbg(us, "TEST_UNIT_READY\n");
  482. return jumpshot_get_status(us);
  483. }
  484. if (srb->cmnd[0] == REQUEST_SENSE) {
  485. usb_stor_dbg(us, "REQUEST_SENSE\n");
  486. memset(ptr, 0, 18);
  487. ptr[0] = 0xF0;
  488. ptr[2] = info->sense_key;
  489. ptr[7] = 11;
  490. ptr[12] = info->sense_asc;
  491. ptr[13] = info->sense_ascq;
  492. usb_stor_set_xfer_buf(ptr, 18, srb);
  493. return USB_STOR_TRANSPORT_GOOD;
  494. }
  495. if (srb->cmnd[0] == MODE_SENSE) {
  496. usb_stor_dbg(us, "MODE_SENSE_6 detected\n");
  497. return jumpshot_handle_mode_sense(us, srb, 1);
  498. }
  499. if (srb->cmnd[0] == MODE_SENSE_10) {
  500. usb_stor_dbg(us, "MODE_SENSE_10 detected\n");
  501. return jumpshot_handle_mode_sense(us, srb, 0);
  502. }
  503. if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
  504. /*
  505. * sure. whatever. not like we can stop the user from popping
  506. * the media out of the device (no locking doors, etc)
  507. */
  508. return USB_STOR_TRANSPORT_GOOD;
  509. }
  510. if (srb->cmnd[0] == START_STOP) {
  511. /*
  512. * this is used by sd.c'check_scsidisk_media_change to detect
  513. * media change
  514. */
  515. usb_stor_dbg(us, "START_STOP\n");
  516. /*
  517. * the first jumpshot_id_device after a media change returns
  518. * an error (determined experimentally)
  519. */
  520. rc = jumpshot_id_device(us, info);
  521. if (rc == USB_STOR_TRANSPORT_GOOD) {
  522. info->sense_key = NO_SENSE;
  523. srb->result = SUCCESS;
  524. } else {
  525. info->sense_key = UNIT_ATTENTION;
  526. srb->result = SAM_STAT_CHECK_CONDITION;
  527. }
  528. return rc;
  529. }
  530. usb_stor_dbg(us, "Gah! Unknown command: %d (0x%x)\n",
  531. srb->cmnd[0], srb->cmnd[0]);
  532. info->sense_key = 0x05;
  533. info->sense_asc = 0x20;
  534. info->sense_ascq = 0x00;
  535. return USB_STOR_TRANSPORT_FAILED;
  536. }
  537. static struct scsi_host_template jumpshot_host_template;
  538. static int jumpshot_probe(struct usb_interface *intf,
  539. const struct usb_device_id *id)
  540. {
  541. struct us_data *us;
  542. int result;
  543. result = usb_stor_probe1(&us, intf, id,
  544. (id - jumpshot_usb_ids) + jumpshot_unusual_dev_list,
  545. &jumpshot_host_template);
  546. if (result)
  547. return result;
  548. us->transport_name = "Lexar Jumpshot Control/Bulk";
  549. us->transport = jumpshot_transport;
  550. us->transport_reset = usb_stor_Bulk_reset;
  551. us->max_lun = 1;
  552. result = usb_stor_probe2(us);
  553. return result;
  554. }
  555. static struct usb_driver jumpshot_driver = {
  556. .name = DRV_NAME,
  557. .probe = jumpshot_probe,
  558. .disconnect = usb_stor_disconnect,
  559. .suspend = usb_stor_suspend,
  560. .resume = usb_stor_resume,
  561. .reset_resume = usb_stor_reset_resume,
  562. .pre_reset = usb_stor_pre_reset,
  563. .post_reset = usb_stor_post_reset,
  564. .id_table = jumpshot_usb_ids,
  565. .soft_unbind = 1,
  566. .no_dynamic_id = 1,
  567. };
  568. module_usb_stor_driver(jumpshot_driver, jumpshot_host_template, DRV_NAME);