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