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)|(USB_US_TYPE_STOR<<24) }
  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. US_DEBUGP("jumpshot_bulk_read: 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. US_DEBUGP("jumpshot_bulk_write: 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. US_DEBUGP("jumpshot_get_status: 0x%2x\n",
  130. us->iobuf[0]);
  131. return USB_STOR_TRANSPORT_ERROR;
  132. }
  133. return USB_STOR_TRANSPORT_GOOD;
  134. }
  135. static int jumpshot_read_data(struct us_data *us,
  136. struct jumpshot_info *info,
  137. u32 sector,
  138. u32 sectors)
  139. {
  140. unsigned char *command = us->iobuf;
  141. unsigned char *buffer;
  142. unsigned char thistime;
  143. unsigned int totallen, alloclen;
  144. int len, result;
  145. unsigned int sg_offset = 0;
  146. struct scatterlist *sg = NULL;
  147. // we're working in LBA mode. according to the ATA spec,
  148. // we can support up to 28-bit addressing. I don't know if Jumpshot
  149. // supports beyond 24-bit addressing. It's kind of hard to test
  150. // since it requires > 8GB CF card.
  151. if (sector > 0x0FFFFFFF)
  152. return USB_STOR_TRANSPORT_ERROR;
  153. totallen = sectors * info->ssize;
  154. // Since we don't read more than 64 KB at a time, we have to create
  155. // a bounce buffer and move the data a piece at a time between the
  156. // bounce buffer and the actual transfer buffer.
  157. alloclen = min(totallen, 65536u);
  158. buffer = kmalloc(alloclen, GFP_NOIO);
  159. if (buffer == NULL)
  160. return USB_STOR_TRANSPORT_ERROR;
  161. do {
  162. // loop, never allocate or transfer more than 64k at once
  163. // (min(128k, 255*info->ssize) is the real limit)
  164. len = min(totallen, alloclen);
  165. thistime = (len / info->ssize) & 0xff;
  166. command[0] = 0;
  167. command[1] = thistime;
  168. command[2] = sector & 0xFF;
  169. command[3] = (sector >> 8) & 0xFF;
  170. command[4] = (sector >> 16) & 0xFF;
  171. command[5] = 0xE0 | ((sector >> 24) & 0x0F);
  172. command[6] = 0x20;
  173. // send the setup + command
  174. result = usb_stor_ctrl_transfer(us, us->send_ctrl_pipe,
  175. 0, 0x20, 0, 1, command, 7);
  176. if (result != USB_STOR_XFER_GOOD)
  177. goto leave;
  178. // read the result
  179. result = jumpshot_bulk_read(us, buffer, len);
  180. if (result != USB_STOR_XFER_GOOD)
  181. goto leave;
  182. US_DEBUGP("jumpshot_read_data: %d bytes\n", len);
  183. // Store the data in the transfer buffer
  184. usb_stor_access_xfer_buf(buffer, len, us->srb,
  185. &sg, &sg_offset, TO_XFER_BUF);
  186. sector += thistime;
  187. totallen -= len;
  188. } while (totallen > 0);
  189. kfree(buffer);
  190. return USB_STOR_TRANSPORT_GOOD;
  191. leave:
  192. kfree(buffer);
  193. return USB_STOR_TRANSPORT_ERROR;
  194. }
  195. static int jumpshot_write_data(struct us_data *us,
  196. struct jumpshot_info *info,
  197. u32 sector,
  198. u32 sectors)
  199. {
  200. unsigned char *command = us->iobuf;
  201. unsigned char *buffer;
  202. unsigned char thistime;
  203. unsigned int totallen, alloclen;
  204. int len, result, waitcount;
  205. unsigned int sg_offset = 0;
  206. struct scatterlist *sg = NULL;
  207. // we're working in LBA mode. according to the ATA spec,
  208. // we can support up to 28-bit addressing. I don't know if Jumpshot
  209. // supports beyond 24-bit addressing. It's kind of hard to test
  210. // since it requires > 8GB CF card.
  211. //
  212. if (sector > 0x0FFFFFFF)
  213. return USB_STOR_TRANSPORT_ERROR;
  214. totallen = sectors * info->ssize;
  215. // Since we don't write more than 64 KB at a time, we have to create
  216. // a bounce buffer and move the data a piece at a time between the
  217. // bounce buffer and the actual transfer buffer.
  218. alloclen = min(totallen, 65536u);
  219. buffer = kmalloc(alloclen, GFP_NOIO);
  220. if (buffer == NULL)
  221. return USB_STOR_TRANSPORT_ERROR;
  222. do {
  223. // loop, never allocate or transfer more than 64k at once
  224. // (min(128k, 255*info->ssize) is the real limit)
  225. len = min(totallen, alloclen);
  226. thistime = (len / info->ssize) & 0xff;
  227. // Get the data from the transfer buffer
  228. usb_stor_access_xfer_buf(buffer, len, us->srb,
  229. &sg, &sg_offset, FROM_XFER_BUF);
  230. command[0] = 0;
  231. command[1] = thistime;
  232. command[2] = sector & 0xFF;
  233. command[3] = (sector >> 8) & 0xFF;
  234. command[4] = (sector >> 16) & 0xFF;
  235. command[5] = 0xE0 | ((sector >> 24) & 0x0F);
  236. command[6] = 0x30;
  237. // send the setup + command
  238. result = usb_stor_ctrl_transfer(us, us->send_ctrl_pipe,
  239. 0, 0x20, 0, 1, command, 7);
  240. if (result != USB_STOR_XFER_GOOD)
  241. goto leave;
  242. // send the data
  243. result = jumpshot_bulk_write(us, buffer, len);
  244. if (result != USB_STOR_XFER_GOOD)
  245. goto leave;
  246. // read the result. apparently the bulk write can complete
  247. // before the jumpshot drive is finished writing. so we loop
  248. // here until we get a good return code
  249. waitcount = 0;
  250. do {
  251. result = jumpshot_get_status(us);
  252. if (result != USB_STOR_TRANSPORT_GOOD) {
  253. // I have not experimented to find the smallest value.
  254. //
  255. msleep(50);
  256. }
  257. } while ((result != USB_STOR_TRANSPORT_GOOD) && (waitcount < 10));
  258. if (result != USB_STOR_TRANSPORT_GOOD)
  259. US_DEBUGP("jumpshot_write_data: Gah! Waitcount = 10. Bad write!?\n");
  260. sector += thistime;
  261. totallen -= len;
  262. } while (totallen > 0);
  263. kfree(buffer);
  264. return result;
  265. leave:
  266. kfree(buffer);
  267. return USB_STOR_TRANSPORT_ERROR;
  268. }
  269. static int jumpshot_id_device(struct us_data *us,
  270. struct jumpshot_info *info)
  271. {
  272. unsigned char *command = us->iobuf;
  273. unsigned char *reply;
  274. int rc;
  275. if (!info)
  276. return USB_STOR_TRANSPORT_ERROR;
  277. command[0] = 0xE0;
  278. command[1] = 0xEC;
  279. reply = kmalloc(512, GFP_NOIO);
  280. if (!reply)
  281. return USB_STOR_TRANSPORT_ERROR;
  282. // send the setup
  283. rc = usb_stor_ctrl_transfer(us, us->send_ctrl_pipe,
  284. 0, 0x20, 0, 6, command, 2);
  285. if (rc != USB_STOR_XFER_GOOD) {
  286. US_DEBUGP("jumpshot_id_device: Gah! "
  287. "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. US_DEBUGP("jumpshot_handle_mode_sense: Current values\n");
  331. break;
  332. case 0x1:
  333. US_DEBUGP("jumpshot_handle_mode_sense: Changeable values\n");
  334. break;
  335. case 0x2:
  336. US_DEBUGP("jumpshot_handle_mode_sense: Default values\n");
  337. break;
  338. case 0x3:
  339. US_DEBUGP("jumpshot_handle_mode_sense: 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. US_DEBUGP("jumpshot_transport: Gah! Can't allocate storage for jumpshot info struct!\n");
  411. return USB_STOR_TRANSPORT_ERROR;
  412. }
  413. us->extra_destructor = jumpshot_info_destructor;
  414. }
  415. info = (struct jumpshot_info *) (us->extra);
  416. if (srb->cmnd[0] == INQUIRY) {
  417. US_DEBUGP("jumpshot_transport: INQUIRY. Returning bogus response.\n");
  418. memcpy(ptr, inquiry_response, sizeof(inquiry_response));
  419. fill_inquiry_response(us, ptr, 36);
  420. return USB_STOR_TRANSPORT_GOOD;
  421. }
  422. if (srb->cmnd[0] == READ_CAPACITY) {
  423. info->ssize = 0x200; // hard coded 512 byte sectors as per ATA spec
  424. rc = jumpshot_get_status(us);
  425. if (rc != USB_STOR_TRANSPORT_GOOD)
  426. return rc;
  427. rc = jumpshot_id_device(us, info);
  428. if (rc != USB_STOR_TRANSPORT_GOOD)
  429. return rc;
  430. US_DEBUGP("jumpshot_transport: READ_CAPACITY: %ld sectors, %ld bytes per sector\n",
  431. info->sectors, info->ssize);
  432. // build the reply
  433. //
  434. ((__be32 *) ptr)[0] = cpu_to_be32(info->sectors - 1);
  435. ((__be32 *) ptr)[1] = cpu_to_be32(info->ssize);
  436. usb_stor_set_xfer_buf(ptr, 8, srb);
  437. return USB_STOR_TRANSPORT_GOOD;
  438. }
  439. if (srb->cmnd[0] == MODE_SELECT_10) {
  440. US_DEBUGP("jumpshot_transport: Gah! MODE_SELECT_10.\n");
  441. return USB_STOR_TRANSPORT_ERROR;
  442. }
  443. if (srb->cmnd[0] == READ_10) {
  444. block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
  445. ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
  446. blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8]));
  447. US_DEBUGP("jumpshot_transport: READ_10: read block 0x%04lx count %ld\n", 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. US_DEBUGP("jumpshot_transport: READ_12: read block 0x%04lx count %ld\n", 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. US_DEBUGP("jumpshot_transport: WRITE_10: write block 0x%04lx count %ld\n", block, blocks);
  465. return jumpshot_write_data(us, info, block, blocks);
  466. }
  467. if (srb->cmnd[0] == WRITE_12) {
  468. // I don't think we'll ever see a WRITE_12 but support it anyway...
  469. //
  470. block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
  471. ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
  472. blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) |
  473. ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9]));
  474. US_DEBUGP("jumpshot_transport: WRITE_12: write block 0x%04lx count %ld\n", block, blocks);
  475. return jumpshot_write_data(us, info, block, blocks);
  476. }
  477. if (srb->cmnd[0] == TEST_UNIT_READY) {
  478. US_DEBUGP("jumpshot_transport: TEST_UNIT_READY.\n");
  479. return jumpshot_get_status(us);
  480. }
  481. if (srb->cmnd[0] == REQUEST_SENSE) {
  482. US_DEBUGP("jumpshot_transport: 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. US_DEBUGP("jumpshot_transport: MODE_SENSE_6 detected\n");
  494. return jumpshot_handle_mode_sense(us, srb, 1);
  495. }
  496. if (srb->cmnd[0] == MODE_SENSE_10) {
  497. US_DEBUGP("jumpshot_transport: 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. US_DEBUGP("jumpshot_transport: 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. US_DEBUGP("jumpshot_transport: 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);