datafab.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /* Driver for Datafab USB Compact Flash reader
  2. *
  3. * datafab driver v0.1:
  4. *
  5. * First release
  6. *
  7. * Current development and maintenance by:
  8. * (c) 2000 Jimmie Mayfield (mayfield+datafab@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. * Other contributors:
  19. * (c) 2002 Alan Stern <stern@rowland.org>
  20. *
  21. * This program is free software; you can redistribute it and/or modify it
  22. * under the terms of the GNU General Public License as published by the
  23. * Free Software Foundation; either version 2, or (at your option) any
  24. * later version.
  25. *
  26. * This program is distributed in the hope that it will be useful, but
  27. * WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  29. * General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU General Public License along
  32. * with this program; if not, write to the Free Software Foundation, Inc.,
  33. * 675 Mass Ave, Cambridge, MA 02139, USA.
  34. */
  35. /*
  36. * This driver attempts to support USB CompactFlash reader/writer devices
  37. * based on Datafab USB-to-ATA chips. It was specifically developed for the
  38. * Datafab MDCFE-B USB CompactFlash reader but has since been found to work
  39. * with a variety of Datafab-based devices from a number of manufacturers.
  40. * I've received a report of this driver working with a Datafab-based
  41. * SmartMedia device though please be aware that I'm personally unable to
  42. * test SmartMedia support.
  43. *
  44. * This driver supports reading and writing. If you're truly paranoid,
  45. * however, you can force the driver into a write-protected state by setting
  46. * the WP enable bits in datafab_handle_mode_sense(). See the comments
  47. * in that routine.
  48. */
  49. #include <linux/errno.h>
  50. #include <linux/slab.h>
  51. #include <scsi/scsi.h>
  52. #include <scsi/scsi_cmnd.h>
  53. #include "usb.h"
  54. #include "transport.h"
  55. #include "protocol.h"
  56. #include "debug.h"
  57. #include "datafab.h"
  58. static int datafab_determine_lun(struct us_data *us,
  59. struct datafab_info *info);
  60. static inline int
  61. datafab_bulk_read(struct us_data *us, unsigned char *data, unsigned int len) {
  62. if (len == 0)
  63. return USB_STOR_XFER_GOOD;
  64. US_DEBUGP("datafab_bulk_read: len = %d\n", len);
  65. return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
  66. data, len, NULL);
  67. }
  68. static inline int
  69. datafab_bulk_write(struct us_data *us, unsigned char *data, unsigned int len) {
  70. if (len == 0)
  71. return USB_STOR_XFER_GOOD;
  72. US_DEBUGP("datafab_bulk_write: len = %d\n", len);
  73. return usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
  74. data, len, NULL);
  75. }
  76. static int datafab_read_data(struct us_data *us,
  77. struct datafab_info *info,
  78. u32 sector,
  79. u32 sectors)
  80. {
  81. unsigned char *command = us->iobuf;
  82. unsigned char *buffer;
  83. unsigned char thistime;
  84. unsigned int totallen, alloclen;
  85. int len, result;
  86. unsigned int sg_offset = 0;
  87. struct scatterlist *sg = NULL;
  88. // we're working in LBA mode. according to the ATA spec,
  89. // we can support up to 28-bit addressing. I don't know if Datafab
  90. // supports beyond 24-bit addressing. It's kind of hard to test
  91. // since it requires > 8GB CF card.
  92. //
  93. if (sectors > 0x0FFFFFFF)
  94. return USB_STOR_TRANSPORT_ERROR;
  95. if (info->lun == -1) {
  96. result = datafab_determine_lun(us, info);
  97. if (result != USB_STOR_TRANSPORT_GOOD)
  98. return result;
  99. }
  100. totallen = sectors * info->ssize;
  101. // Since we don't read more than 64 KB at a time, we have to create
  102. // a bounce buffer and move the data a piece at a time between the
  103. // bounce buffer and the actual transfer buffer.
  104. alloclen = min(totallen, 65536u);
  105. buffer = kmalloc(alloclen, GFP_NOIO);
  106. if (buffer == NULL)
  107. return USB_STOR_TRANSPORT_ERROR;
  108. do {
  109. // loop, never allocate or transfer more than 64k at once
  110. // (min(128k, 255*info->ssize) is the real limit)
  111. len = min(totallen, alloclen);
  112. thistime = (len / info->ssize) & 0xff;
  113. command[0] = 0;
  114. command[1] = thistime;
  115. command[2] = sector & 0xFF;
  116. command[3] = (sector >> 8) & 0xFF;
  117. command[4] = (sector >> 16) & 0xFF;
  118. command[5] = 0xE0 + (info->lun << 4);
  119. command[5] |= (sector >> 24) & 0x0F;
  120. command[6] = 0x20;
  121. command[7] = 0x01;
  122. // send the read command
  123. result = datafab_bulk_write(us, command, 8);
  124. if (result != USB_STOR_XFER_GOOD)
  125. goto leave;
  126. // read the result
  127. result = datafab_bulk_read(us, buffer, len);
  128. if (result != USB_STOR_XFER_GOOD)
  129. goto leave;
  130. // Store the data in the transfer buffer
  131. usb_stor_access_xfer_buf(buffer, len, us->srb,
  132. &sg, &sg_offset, TO_XFER_BUF);
  133. sector += thistime;
  134. totallen -= len;
  135. } while (totallen > 0);
  136. kfree(buffer);
  137. return USB_STOR_TRANSPORT_GOOD;
  138. leave:
  139. kfree(buffer);
  140. return USB_STOR_TRANSPORT_ERROR;
  141. }
  142. static int datafab_write_data(struct us_data *us,
  143. struct datafab_info *info,
  144. u32 sector,
  145. u32 sectors)
  146. {
  147. unsigned char *command = us->iobuf;
  148. unsigned char *reply = us->iobuf;
  149. unsigned char *buffer;
  150. unsigned char thistime;
  151. unsigned int totallen, alloclen;
  152. int len, result;
  153. unsigned int sg_offset = 0;
  154. struct scatterlist *sg = NULL;
  155. // we're working in LBA mode. according to the ATA spec,
  156. // we can support up to 28-bit addressing. I don't know if Datafab
  157. // supports beyond 24-bit addressing. It's kind of hard to test
  158. // since it requires > 8GB CF card.
  159. //
  160. if (sectors > 0x0FFFFFFF)
  161. return USB_STOR_TRANSPORT_ERROR;
  162. if (info->lun == -1) {
  163. result = datafab_determine_lun(us, info);
  164. if (result != USB_STOR_TRANSPORT_GOOD)
  165. return result;
  166. }
  167. totallen = sectors * info->ssize;
  168. // Since we don't write more than 64 KB at a time, we have to create
  169. // a bounce buffer and move the data a piece at a time between the
  170. // bounce buffer and the actual transfer buffer.
  171. alloclen = min(totallen, 65536u);
  172. buffer = kmalloc(alloclen, GFP_NOIO);
  173. if (buffer == NULL)
  174. return USB_STOR_TRANSPORT_ERROR;
  175. do {
  176. // loop, never allocate or transfer more than 64k at once
  177. // (min(128k, 255*info->ssize) is the real limit)
  178. len = min(totallen, alloclen);
  179. thistime = (len / info->ssize) & 0xff;
  180. // Get the data from the transfer buffer
  181. usb_stor_access_xfer_buf(buffer, len, us->srb,
  182. &sg, &sg_offset, FROM_XFER_BUF);
  183. command[0] = 0;
  184. command[1] = thistime;
  185. command[2] = sector & 0xFF;
  186. command[3] = (sector >> 8) & 0xFF;
  187. command[4] = (sector >> 16) & 0xFF;
  188. command[5] = 0xE0 + (info->lun << 4);
  189. command[5] |= (sector >> 24) & 0x0F;
  190. command[6] = 0x30;
  191. command[7] = 0x02;
  192. // send the command
  193. result = datafab_bulk_write(us, command, 8);
  194. if (result != USB_STOR_XFER_GOOD)
  195. goto leave;
  196. // send the data
  197. result = datafab_bulk_write(us, buffer, len);
  198. if (result != USB_STOR_XFER_GOOD)
  199. goto leave;
  200. // read the result
  201. result = datafab_bulk_read(us, reply, 2);
  202. if (result != USB_STOR_XFER_GOOD)
  203. goto leave;
  204. if (reply[0] != 0x50 && reply[1] != 0) {
  205. US_DEBUGP("datafab_write_data: Gah! "
  206. "write return code: %02x %02x\n",
  207. reply[0], reply[1]);
  208. result = USB_STOR_TRANSPORT_ERROR;
  209. goto leave;
  210. }
  211. sector += thistime;
  212. totallen -= len;
  213. } while (totallen > 0);
  214. kfree(buffer);
  215. return USB_STOR_TRANSPORT_GOOD;
  216. leave:
  217. kfree(buffer);
  218. return USB_STOR_TRANSPORT_ERROR;
  219. }
  220. static int datafab_determine_lun(struct us_data *us,
  221. struct datafab_info *info)
  222. {
  223. // Dual-slot readers can be thought of as dual-LUN devices.
  224. // We need to determine which card slot is being used.
  225. // We'll send an IDENTIFY DEVICE command and see which LUN responds...
  226. //
  227. // There might be a better way of doing this?
  228. static unsigned char scommand[8] = { 0, 1, 0, 0, 0, 0xa0, 0xec, 1 };
  229. unsigned char *command = us->iobuf;
  230. unsigned char *buf;
  231. int count = 0, rc;
  232. if (!us || !info)
  233. return USB_STOR_TRANSPORT_ERROR;
  234. memcpy(command, scommand, 8);
  235. buf = kmalloc(512, GFP_NOIO);
  236. if (!buf)
  237. return USB_STOR_TRANSPORT_ERROR;
  238. US_DEBUGP("datafab_determine_lun: locating...\n");
  239. // we'll try 3 times before giving up...
  240. //
  241. while (count++ < 3) {
  242. command[5] = 0xa0;
  243. rc = datafab_bulk_write(us, command, 8);
  244. if (rc != USB_STOR_XFER_GOOD) {
  245. rc = USB_STOR_TRANSPORT_ERROR;
  246. goto leave;
  247. }
  248. rc = datafab_bulk_read(us, buf, 512);
  249. if (rc == USB_STOR_XFER_GOOD) {
  250. info->lun = 0;
  251. rc = USB_STOR_TRANSPORT_GOOD;
  252. goto leave;
  253. }
  254. command[5] = 0xb0;
  255. rc = datafab_bulk_write(us, command, 8);
  256. if (rc != USB_STOR_XFER_GOOD) {
  257. rc = USB_STOR_TRANSPORT_ERROR;
  258. goto leave;
  259. }
  260. rc = datafab_bulk_read(us, buf, 512);
  261. if (rc == USB_STOR_XFER_GOOD) {
  262. info->lun = 1;
  263. rc = USB_STOR_TRANSPORT_GOOD;
  264. goto leave;
  265. }
  266. msleep(20);
  267. }
  268. rc = USB_STOR_TRANSPORT_ERROR;
  269. leave:
  270. kfree(buf);
  271. return rc;
  272. }
  273. static int datafab_id_device(struct us_data *us,
  274. struct datafab_info *info)
  275. {
  276. // this is a variation of the ATA "IDENTIFY DEVICE" command...according
  277. // to the ATA spec, 'Sector Count' isn't used but the Windows driver
  278. // sets this bit so we do too...
  279. //
  280. static unsigned char scommand[8] = { 0, 1, 0, 0, 0, 0xa0, 0xec, 1 };
  281. unsigned char *command = us->iobuf;
  282. unsigned char *reply;
  283. int rc;
  284. if (!us || !info)
  285. return USB_STOR_TRANSPORT_ERROR;
  286. if (info->lun == -1) {
  287. rc = datafab_determine_lun(us, info);
  288. if (rc != USB_STOR_TRANSPORT_GOOD)
  289. return rc;
  290. }
  291. memcpy(command, scommand, 8);
  292. reply = kmalloc(512, GFP_NOIO);
  293. if (!reply)
  294. return USB_STOR_TRANSPORT_ERROR;
  295. command[5] += (info->lun << 4);
  296. rc = datafab_bulk_write(us, command, 8);
  297. if (rc != USB_STOR_XFER_GOOD) {
  298. rc = USB_STOR_TRANSPORT_ERROR;
  299. goto leave;
  300. }
  301. // we'll go ahead and extract the media capacity while we're here...
  302. //
  303. rc = datafab_bulk_read(us, reply, 512);
  304. if (rc == USB_STOR_XFER_GOOD) {
  305. // capacity is at word offset 57-58
  306. //
  307. info->sectors = ((u32)(reply[117]) << 24) |
  308. ((u32)(reply[116]) << 16) |
  309. ((u32)(reply[115]) << 8) |
  310. ((u32)(reply[114]) );
  311. rc = USB_STOR_TRANSPORT_GOOD;
  312. goto leave;
  313. }
  314. rc = USB_STOR_TRANSPORT_ERROR;
  315. leave:
  316. kfree(reply);
  317. return rc;
  318. }
  319. static int datafab_handle_mode_sense(struct us_data *us,
  320. struct scsi_cmnd * srb,
  321. int sense_6)
  322. {
  323. static unsigned char rw_err_page[12] = {
  324. 0x1, 0xA, 0x21, 1, 0, 0, 0, 0, 1, 0, 0, 0
  325. };
  326. static unsigned char cache_page[12] = {
  327. 0x8, 0xA, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0
  328. };
  329. static unsigned char rbac_page[12] = {
  330. 0x1B, 0xA, 0, 0x81, 0, 0, 0, 0, 0, 0, 0, 0
  331. };
  332. static unsigned char timer_page[8] = {
  333. 0x1C, 0x6, 0, 0, 0, 0
  334. };
  335. unsigned char pc, page_code;
  336. unsigned int i = 0;
  337. struct datafab_info *info = (struct datafab_info *) (us->extra);
  338. unsigned char *ptr = us->iobuf;
  339. // most of this stuff is just a hack to get things working. the
  340. // datafab reader doesn't present a SCSI interface so we
  341. // fudge the SCSI commands...
  342. //
  343. pc = srb->cmnd[2] >> 6;
  344. page_code = srb->cmnd[2] & 0x3F;
  345. switch (pc) {
  346. case 0x0:
  347. US_DEBUGP("datafab_handle_mode_sense: Current values\n");
  348. break;
  349. case 0x1:
  350. US_DEBUGP("datafab_handle_mode_sense: Changeable values\n");
  351. break;
  352. case 0x2:
  353. US_DEBUGP("datafab_handle_mode_sense: Default values\n");
  354. break;
  355. case 0x3:
  356. US_DEBUGP("datafab_handle_mode_sense: Saves values\n");
  357. break;
  358. }
  359. memset(ptr, 0, 8);
  360. if (sense_6) {
  361. ptr[2] = 0x00; // WP enable: 0x80
  362. i = 4;
  363. } else {
  364. ptr[3] = 0x00; // WP enable: 0x80
  365. i = 8;
  366. }
  367. switch (page_code) {
  368. default:
  369. // vendor-specific mode
  370. info->sense_key = 0x05;
  371. info->sense_asc = 0x24;
  372. info->sense_ascq = 0x00;
  373. return USB_STOR_TRANSPORT_FAILED;
  374. case 0x1:
  375. memcpy(ptr + i, rw_err_page, sizeof(rw_err_page));
  376. i += sizeof(rw_err_page);
  377. break;
  378. case 0x8:
  379. memcpy(ptr + i, cache_page, sizeof(cache_page));
  380. i += sizeof(cache_page);
  381. break;
  382. case 0x1B:
  383. memcpy(ptr + i, rbac_page, sizeof(rbac_page));
  384. i += sizeof(rbac_page);
  385. break;
  386. case 0x1C:
  387. memcpy(ptr + i, timer_page, sizeof(timer_page));
  388. i += sizeof(timer_page);
  389. break;
  390. case 0x3F: // retrieve all pages
  391. memcpy(ptr + i, timer_page, sizeof(timer_page));
  392. i += sizeof(timer_page);
  393. memcpy(ptr + i, rbac_page, sizeof(rbac_page));
  394. i += sizeof(rbac_page);
  395. memcpy(ptr + i, cache_page, sizeof(cache_page));
  396. i += sizeof(cache_page);
  397. memcpy(ptr + i, rw_err_page, sizeof(rw_err_page));
  398. i += sizeof(rw_err_page);
  399. break;
  400. }
  401. if (sense_6)
  402. ptr[0] = i - 1;
  403. else
  404. ((__be16 *) ptr)[0] = cpu_to_be16(i - 2);
  405. usb_stor_set_xfer_buf(ptr, i, srb);
  406. return USB_STOR_TRANSPORT_GOOD;
  407. }
  408. static void datafab_info_destructor(void *extra)
  409. {
  410. // this routine is a placeholder...
  411. // currently, we don't allocate any extra memory so we're okay
  412. }
  413. // Transport for the Datafab MDCFE-B
  414. //
  415. int datafab_transport(struct scsi_cmnd * srb, struct us_data *us)
  416. {
  417. struct datafab_info *info;
  418. int rc;
  419. unsigned long block, blocks;
  420. unsigned char *ptr = us->iobuf;
  421. static unsigned char inquiry_reply[8] = {
  422. 0x00, 0x80, 0x00, 0x01, 0x1F, 0x00, 0x00, 0x00
  423. };
  424. if (!us->extra) {
  425. us->extra = kzalloc(sizeof(struct datafab_info), GFP_NOIO);
  426. if (!us->extra) {
  427. US_DEBUGP("datafab_transport: Gah! "
  428. "Can't allocate storage for Datafab info struct!\n");
  429. return USB_STOR_TRANSPORT_ERROR;
  430. }
  431. us->extra_destructor = datafab_info_destructor;
  432. ((struct datafab_info *)us->extra)->lun = -1;
  433. }
  434. info = (struct datafab_info *) (us->extra);
  435. if (srb->cmnd[0] == INQUIRY) {
  436. US_DEBUGP("datafab_transport: INQUIRY. Returning bogus response");
  437. memcpy(ptr, inquiry_reply, sizeof(inquiry_reply));
  438. fill_inquiry_response(us, ptr, 36);
  439. return USB_STOR_TRANSPORT_GOOD;
  440. }
  441. if (srb->cmnd[0] == READ_CAPACITY) {
  442. info->ssize = 0x200; // hard coded 512 byte sectors as per ATA spec
  443. rc = datafab_id_device(us, info);
  444. if (rc != USB_STOR_TRANSPORT_GOOD)
  445. return rc;
  446. US_DEBUGP("datafab_transport: READ_CAPACITY: %ld sectors, %ld bytes per sector\n",
  447. info->sectors, info->ssize);
  448. // build the reply
  449. // we need the last sector, not the number of sectors
  450. ((__be32 *) ptr)[0] = cpu_to_be32(info->sectors - 1);
  451. ((__be32 *) ptr)[1] = cpu_to_be32(info->ssize);
  452. usb_stor_set_xfer_buf(ptr, 8, srb);
  453. return USB_STOR_TRANSPORT_GOOD;
  454. }
  455. if (srb->cmnd[0] == MODE_SELECT_10) {
  456. US_DEBUGP("datafab_transport: Gah! MODE_SELECT_10.\n");
  457. return USB_STOR_TRANSPORT_ERROR;
  458. }
  459. // don't bother implementing READ_6 or WRITE_6.
  460. //
  461. if (srb->cmnd[0] == READ_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. US_DEBUGP("datafab_transport: READ_10: read block 0x%04lx count %ld\n", block, blocks);
  466. return datafab_read_data(us, info, block, blocks);
  467. }
  468. if (srb->cmnd[0] == READ_12) {
  469. // we'll probably never see a READ_12 but we'll do 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. US_DEBUGP("datafab_transport: READ_12: read block 0x%04lx count %ld\n", block, blocks);
  476. return datafab_read_data(us, info, block, blocks);
  477. }
  478. if (srb->cmnd[0] == WRITE_10) {
  479. block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
  480. ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
  481. blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8]));
  482. US_DEBUGP("datafab_transport: WRITE_10: write block 0x%04lx count %ld\n", block, blocks);
  483. return datafab_write_data(us, info, block, blocks);
  484. }
  485. if (srb->cmnd[0] == WRITE_12) {
  486. // we'll probably never see a WRITE_12 but we'll do it anyway...
  487. //
  488. block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
  489. ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
  490. blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) |
  491. ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9]));
  492. US_DEBUGP("datafab_transport: WRITE_12: write block 0x%04lx count %ld\n", block, blocks);
  493. return datafab_write_data(us, info, block, blocks);
  494. }
  495. if (srb->cmnd[0] == TEST_UNIT_READY) {
  496. US_DEBUGP("datafab_transport: TEST_UNIT_READY.\n");
  497. return datafab_id_device(us, info);
  498. }
  499. if (srb->cmnd[0] == REQUEST_SENSE) {
  500. US_DEBUGP("datafab_transport: REQUEST_SENSE. Returning faked response\n");
  501. // this response is pretty bogus right now. eventually if necessary
  502. // we can set the correct sense data. so far though it hasn't been
  503. // necessary
  504. //
  505. memset(ptr, 0, 18);
  506. ptr[0] = 0xF0;
  507. ptr[2] = info->sense_key;
  508. ptr[7] = 11;
  509. ptr[12] = info->sense_asc;
  510. ptr[13] = info->sense_ascq;
  511. usb_stor_set_xfer_buf(ptr, 18, srb);
  512. return USB_STOR_TRANSPORT_GOOD;
  513. }
  514. if (srb->cmnd[0] == MODE_SENSE) {
  515. US_DEBUGP("datafab_transport: MODE_SENSE_6 detected\n");
  516. return datafab_handle_mode_sense(us, srb, 1);
  517. }
  518. if (srb->cmnd[0] == MODE_SENSE_10) {
  519. US_DEBUGP("datafab_transport: MODE_SENSE_10 detected\n");
  520. return datafab_handle_mode_sense(us, srb, 0);
  521. }
  522. if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
  523. // sure. whatever. not like we can stop the user from
  524. // popping the media out of the device (no locking doors, etc)
  525. //
  526. return USB_STOR_TRANSPORT_GOOD;
  527. }
  528. if (srb->cmnd[0] == START_STOP) {
  529. /* this is used by sd.c'check_scsidisk_media_change to detect
  530. media change */
  531. US_DEBUGP("datafab_transport: START_STOP.\n");
  532. /* the first datafab_id_device after a media change returns
  533. an error (determined experimentally) */
  534. rc = datafab_id_device(us, info);
  535. if (rc == USB_STOR_TRANSPORT_GOOD) {
  536. info->sense_key = NO_SENSE;
  537. srb->result = SUCCESS;
  538. } else {
  539. info->sense_key = UNIT_ATTENTION;
  540. srb->result = SAM_STAT_CHECK_CONDITION;
  541. }
  542. return rc;
  543. }
  544. US_DEBUGP("datafab_transport: Gah! Unknown command: %d (0x%x)\n",
  545. srb->cmnd[0], srb->cmnd[0]);
  546. info->sense_key = 0x05;
  547. info->sense_asc = 0x20;
  548. info->sense_ascq = 0x00;
  549. return USB_STOR_TRANSPORT_FAILED;
  550. }