jumpshot.c 17 KB

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