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