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