jumpshot.c 18 KB

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