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