jumpshot.c 18 KB

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