1 /* Driver for SanDisk SDDR-55 SmartMedia reader
7 * Current development and maintenance by:
8 * (c) 2002 Simon Munton
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2, or (at your option) any
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <linux/jiffies.h>
26 #include <linux/errno.h>
27 #include <linux/module.h>
28 #include <linux/slab.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_cmnd.h>
34 #include "transport.h"
40 * The table of devices
42 #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
43 vendorName, productName, useProtocol, useTransport, \
44 initFunction, flags) \
45 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
46 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
48 struct usb_device_id sddr55_usb_ids[] = {
49 # include "unusual_sddr55.h"
50 { } /* Terminating entry */
52 MODULE_DEVICE_TABLE(usb, sddr55_usb_ids);
59 #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
60 vendor_name, product_name, use_protocol, use_transport, \
61 init_function, Flags) \
63 .vendorName = vendor_name, \
64 .productName = product_name, \
65 .useProtocol = use_protocol, \
66 .useTransport = use_transport, \
67 .initFunction = init_function, \
70 static struct us_unusual_dev sddr55_unusual_dev_list[] = {
71 # include "unusual_sddr55.h"
72 { } /* Terminating entry */
78 #define short_pack(lsb,msb) ( ((u16)(lsb)) | ( ((u16)(msb))<<8 ) )
79 #define LSB_of(s) ((s)&0xFF)
80 #define MSB_of(s) ((s)>>8)
83 #define set_sense_info(sk, asc, ascq) \
85 info->sense_data[2] = sk; \
86 info->sense_data[12] = asc; \
87 info->sense_data[13] = ascq; \
91 struct sddr55_card_info {
92 unsigned long capacity; /* Size of card in bytes */
93 int max_log_blks; /* maximum number of logical blocks */
94 int pageshift; /* log2 of pagesize */
95 int smallpageshift; /* 1 if pagesize == 256 */
96 int blocksize; /* Size of block in pages */
97 int blockshift; /* log2 of blocksize */
98 int blockmask; /* 2^blockshift - 1 */
99 int read_only; /* non zero if card is write protected */
100 int force_read_only; /* non zero if we find a map error*/
101 int *lba_to_pba; /* logical to physical map */
102 int *pba_to_lba; /* physical to logical map */
103 int fatal_error; /* set if we detect something nasty */
104 unsigned long last_access; /* number of jiffies since we last talked to device */
105 unsigned char sense_data[18];
109 #define NOT_ALLOCATED 0xffffffff
110 #define BAD_BLOCK 0xffff
111 #define CIS_BLOCK 0x400
112 #define UNUSED_BLOCK 0x3ff
115 sddr55_bulk_transport(struct us_data *us, int direction,
116 unsigned char *data, unsigned int len) {
117 struct sddr55_card_info *info = (struct sddr55_card_info *)us->extra;
118 unsigned int pipe = (direction == DMA_FROM_DEVICE) ?
119 us->recv_bulk_pipe : us->send_bulk_pipe;
122 return USB_STOR_XFER_GOOD;
123 info->last_access = jiffies;
124 return usb_stor_bulk_transfer_buf(us, pipe, data, len, NULL);
127 /* check if card inserted, if there is, update read_only status
128 * return non zero if no card
131 static int sddr55_status(struct us_data *us)
134 unsigned char *command = us->iobuf;
135 unsigned char *status = us->iobuf;
136 struct sddr55_card_info *info = (struct sddr55_card_info *)us->extra;
139 memset(command, 0, 8);
142 result = sddr55_bulk_transport(us,
143 DMA_TO_DEVICE, command, 8);
145 US_DEBUGP("Result for send_command in status %d\n",
148 if (result != USB_STOR_XFER_GOOD) {
149 set_sense_info (4, 0, 0); /* hardware error */
150 return USB_STOR_TRANSPORT_ERROR;
153 result = sddr55_bulk_transport(us,
154 DMA_FROM_DEVICE, status, 4);
156 /* expect to get short transfer if no card fitted */
157 if (result == USB_STOR_XFER_SHORT || result == USB_STOR_XFER_STALLED) {
158 /* had a short transfer, no card inserted, free map memory */
159 kfree(info->lba_to_pba);
160 kfree(info->pba_to_lba);
161 info->lba_to_pba = NULL;
162 info->pba_to_lba = NULL;
164 info->fatal_error = 0;
165 info->force_read_only = 0;
167 set_sense_info (2, 0x3a, 0); /* not ready, medium not present */
168 return USB_STOR_TRANSPORT_FAILED;
171 if (result != USB_STOR_XFER_GOOD) {
172 set_sense_info (4, 0, 0); /* hardware error */
173 return USB_STOR_TRANSPORT_FAILED;
176 /* check write protect status */
177 info->read_only = (status[0] & 0x20);
179 /* now read status */
180 result = sddr55_bulk_transport(us,
181 DMA_FROM_DEVICE, status, 2);
183 if (result != USB_STOR_XFER_GOOD) {
184 set_sense_info (4, 0, 0); /* hardware error */
187 return (result == USB_STOR_XFER_GOOD ?
188 USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_FAILED);
192 static int sddr55_read_data(struct us_data *us,
195 unsigned short sectors) {
197 int result = USB_STOR_TRANSPORT_GOOD;
198 unsigned char *command = us->iobuf;
199 unsigned char *status = us->iobuf;
200 struct sddr55_card_info *info = (struct sddr55_card_info *)us->extra;
201 unsigned char *buffer;
204 unsigned long address;
206 unsigned short pages;
207 unsigned int len, offset;
208 struct scatterlist *sg;
210 // Since we only read in one block at a time, we have to create
211 // a bounce buffer and move the data a piece at a time between the
212 // bounce buffer and the actual transfer buffer.
214 len = min((unsigned int) sectors, (unsigned int) info->blocksize >>
215 info->smallpageshift) * PAGESIZE;
216 buffer = kmalloc(len, GFP_NOIO);
218 return USB_STOR_TRANSPORT_ERROR; /* out of memory */
224 /* have we got to end? */
225 if (lba >= info->max_log_blks)
228 pba = info->lba_to_pba[lba];
230 // Read as many sectors as possible in this block
232 pages = min((unsigned int) sectors << info->smallpageshift,
233 info->blocksize - page);
234 len = pages << info->pageshift;
236 US_DEBUGP("Read %02X pages, from PBA %04X"
237 " (LBA %04X) page %02X\n",
238 pages, pba, lba, page);
240 if (pba == NOT_ALLOCATED) {
241 /* no pba for this lba, fill with zeroes */
242 memset (buffer, 0, len);
245 address = (pba << info->blockshift) + page;
248 command[1] = LSB_of(address>>16);
249 command[2] = LSB_of(address>>8);
250 command[3] = LSB_of(address);
254 command[6] = LSB_of(pages << (1 - info->smallpageshift));
258 result = sddr55_bulk_transport(us,
259 DMA_TO_DEVICE, command, 8);
261 US_DEBUGP("Result for send_command in read_data %d\n",
264 if (result != USB_STOR_XFER_GOOD) {
265 result = USB_STOR_TRANSPORT_ERROR;
270 result = sddr55_bulk_transport(us,
271 DMA_FROM_DEVICE, buffer, len);
273 if (result != USB_STOR_XFER_GOOD) {
274 result = USB_STOR_TRANSPORT_ERROR;
278 /* now read status */
279 result = sddr55_bulk_transport(us,
280 DMA_FROM_DEVICE, status, 2);
282 if (result != USB_STOR_XFER_GOOD) {
283 result = USB_STOR_TRANSPORT_ERROR;
287 /* check status for error */
288 if (status[0] == 0xff && status[1] == 0x4) {
289 set_sense_info (3, 0x11, 0);
290 result = USB_STOR_TRANSPORT_FAILED;
295 // Store the data in the transfer buffer
296 usb_stor_access_xfer_buf(buffer, len, us->srb,
297 &sg, &offset, TO_XFER_BUF);
301 sectors -= pages >> info->smallpageshift;
304 result = USB_STOR_TRANSPORT_GOOD;
312 static int sddr55_write_data(struct us_data *us,
315 unsigned short sectors) {
317 int result = USB_STOR_TRANSPORT_GOOD;
318 unsigned char *command = us->iobuf;
319 unsigned char *status = us->iobuf;
320 struct sddr55_card_info *info = (struct sddr55_card_info *)us->extra;
321 unsigned char *buffer;
324 unsigned int new_pba;
325 unsigned long address;
327 unsigned short pages;
329 unsigned int len, offset;
330 struct scatterlist *sg;
332 /* check if we are allowed to write */
333 if (info->read_only || info->force_read_only) {
334 set_sense_info (7, 0x27, 0); /* read only */
335 return USB_STOR_TRANSPORT_FAILED;
338 // Since we only write one block at a time, we have to create
339 // a bounce buffer and move the data a piece at a time between the
340 // bounce buffer and the actual transfer buffer.
342 len = min((unsigned int) sectors, (unsigned int) info->blocksize >>
343 info->smallpageshift) * PAGESIZE;
344 buffer = kmalloc(len, GFP_NOIO);
346 return USB_STOR_TRANSPORT_ERROR;
350 while (sectors > 0) {
352 /* have we got to end? */
353 if (lba >= info->max_log_blks)
356 pba = info->lba_to_pba[lba];
358 // Write as many sectors as possible in this block
360 pages = min((unsigned int) sectors << info->smallpageshift,
361 info->blocksize - page);
362 len = pages << info->pageshift;
364 // Get the data from the transfer buffer
365 usb_stor_access_xfer_buf(buffer, len, us->srb,
366 &sg, &offset, FROM_XFER_BUF);
368 US_DEBUGP("Write %02X pages, to PBA %04X"
369 " (LBA %04X) page %02X\n",
370 pages, pba, lba, page);
374 if (pba == NOT_ALLOCATED) {
375 /* no pba allocated for this lba, find a free pba to use */
377 int max_pba = (info->max_log_blks / 250 ) * 256;
381 /* set pba to first block in zone lba is in */
382 pba = (lba / 1000) * 1024;
384 US_DEBUGP("No PBA for LBA %04X\n",lba);
390 * Scan through the map looking for an unused block
391 * leave 16 unused blocks at start (or as many as
392 * possible) since the sddr55 seems to reuse a used
393 * block when it shouldn't if we don't leave space.
395 for (i = 0; i < max_pba; i++, pba++) {
396 if (info->pba_to_lba[pba] == UNUSED_BLOCK) {
398 if (found_count++ > 16)
407 US_DEBUGP("Couldn't find unallocated block\n");
409 set_sense_info (3, 0x31, 0); /* medium error */
410 result = USB_STOR_TRANSPORT_FAILED;
414 US_DEBUGP("Allocating PBA %04X for LBA %04X\n", pba, lba);
416 /* set writing to unallocated block flag */
420 address = (pba << info->blockshift) + page;
422 command[1] = LSB_of(address>>16);
423 command[2] = LSB_of(address>>8);
424 command[3] = LSB_of(address);
426 /* set the lba into the command, modulo 1000 */
427 command[0] = LSB_of(lba % 1000);
428 command[6] = MSB_of(lba % 1000);
430 command[4] |= LSB_of(pages >> info->smallpageshift);
435 result = sddr55_bulk_transport(us,
436 DMA_TO_DEVICE, command, 8);
438 if (result != USB_STOR_XFER_GOOD) {
439 US_DEBUGP("Result for send_command in write_data %d\n",
442 /* set_sense_info is superfluous here? */
443 set_sense_info (3, 0x3, 0);/* peripheral write error */
444 result = USB_STOR_TRANSPORT_FAILED;
449 result = sddr55_bulk_transport(us,
450 DMA_TO_DEVICE, buffer, len);
452 if (result != USB_STOR_XFER_GOOD) {
453 US_DEBUGP("Result for send_data in write_data %d\n",
456 /* set_sense_info is superfluous here? */
457 set_sense_info (3, 0x3, 0);/* peripheral write error */
458 result = USB_STOR_TRANSPORT_FAILED;
462 /* now read status */
463 result = sddr55_bulk_transport(us, DMA_FROM_DEVICE, status, 6);
465 if (result != USB_STOR_XFER_GOOD) {
466 US_DEBUGP("Result for get_status in write_data %d\n",
469 /* set_sense_info is superfluous here? */
470 set_sense_info (3, 0x3, 0);/* peripheral write error */
471 result = USB_STOR_TRANSPORT_FAILED;
475 new_pba = (status[3] + (status[4] << 8) + (status[5] << 16))
478 /* check status for error */
479 if (status[0] == 0xff && status[1] == 0x4) {
480 info->pba_to_lba[new_pba] = BAD_BLOCK;
482 set_sense_info (3, 0x0c, 0);
483 result = USB_STOR_TRANSPORT_FAILED;
487 US_DEBUGP("Updating maps for LBA %04X: old PBA %04X, new PBA %04X\n",
490 /* update the lba<->pba maps, note new_pba might be the same as pba */
491 info->lba_to_pba[lba] = new_pba;
492 info->pba_to_lba[pba] = UNUSED_BLOCK;
494 /* check that new_pba wasn't already being used */
495 if (info->pba_to_lba[new_pba] != UNUSED_BLOCK) {
496 printk(KERN_ERR "sddr55 error: new PBA %04X already in use for LBA %04X\n",
497 new_pba, info->pba_to_lba[new_pba]);
498 info->fatal_error = 1;
499 set_sense_info (3, 0x31, 0);
500 result = USB_STOR_TRANSPORT_FAILED;
504 /* update the pba<->lba maps for new_pba */
505 info->pba_to_lba[new_pba] = lba % 1000;
509 sectors -= pages >> info->smallpageshift;
511 result = USB_STOR_TRANSPORT_GOOD;
518 static int sddr55_read_deviceID(struct us_data *us,
519 unsigned char *manufacturerID,
520 unsigned char *deviceID) {
523 unsigned char *command = us->iobuf;
524 unsigned char *content = us->iobuf;
526 memset(command, 0, 8);
529 result = sddr55_bulk_transport(us, DMA_TO_DEVICE, command, 8);
531 US_DEBUGP("Result of send_control for device ID is %d\n",
534 if (result != USB_STOR_XFER_GOOD)
535 return USB_STOR_TRANSPORT_ERROR;
537 result = sddr55_bulk_transport(us,
538 DMA_FROM_DEVICE, content, 4);
540 if (result != USB_STOR_XFER_GOOD)
541 return USB_STOR_TRANSPORT_ERROR;
543 *manufacturerID = content[0];
544 *deviceID = content[1];
546 if (content[0] != 0xff) {
547 result = sddr55_bulk_transport(us,
548 DMA_FROM_DEVICE, content, 2);
551 return USB_STOR_TRANSPORT_GOOD;
555 static int sddr55_reset(struct us_data *us)
561 static unsigned long sddr55_get_capacity(struct us_data *us) {
563 unsigned char uninitialized_var(manufacturerID);
564 unsigned char uninitialized_var(deviceID);
566 struct sddr55_card_info *info = (struct sddr55_card_info *)us->extra;
568 US_DEBUGP("Reading capacity...\n");
570 result = sddr55_read_deviceID(us,
574 US_DEBUGP("Result of read_deviceID is %d\n",
577 if (result != USB_STOR_XFER_GOOD)
580 US_DEBUGP("Device ID = %02X\n", deviceID);
581 US_DEBUGP("Manuf ID = %02X\n", manufacturerID);
584 info->smallpageshift = 0;
585 info->blocksize = 16;
586 info->blockshift = 4;
587 info->blockmask = 15;
595 info->smallpageshift = 1;
601 info->smallpageshift = 1;
602 case 0x5d: // 5d is a ROM card with pagesize 512.
616 info->blocksize = 32;
617 info->blockshift = 5;
618 info->blockmask = 31;
622 info->blocksize = 32;
623 info->blockshift = 5;
624 info->blockmask = 31;
628 info->blocksize = 32;
629 info->blockshift = 5;
630 info->blockmask = 31;
634 info->blocksize = 32;
635 info->blockshift = 5;
636 info->blockmask = 31;
645 static int sddr55_read_map(struct us_data *us) {
647 struct sddr55_card_info *info = (struct sddr55_card_info *)(us->extra);
649 unsigned char *buffer;
650 unsigned char *command = us->iobuf;
653 unsigned short max_lba;
659 numblocks = info->capacity >> (info->blockshift + info->pageshift);
661 buffer = kmalloc( numblocks * 2, GFP_NOIO );
666 memset(command, 0, 8);
668 command[6] = numblocks * 2 / 256;
671 result = sddr55_bulk_transport(us, DMA_TO_DEVICE, command, 8);
673 if ( result != USB_STOR_XFER_GOOD) {
678 result = sddr55_bulk_transport(us, DMA_FROM_DEVICE, buffer, numblocks * 2);
680 if ( result != USB_STOR_XFER_GOOD) {
685 result = sddr55_bulk_transport(us, DMA_FROM_DEVICE, command, 2);
687 if ( result != USB_STOR_XFER_GOOD) {
692 kfree(info->lba_to_pba);
693 kfree(info->pba_to_lba);
694 info->lba_to_pba = kmalloc(numblocks*sizeof(int), GFP_NOIO);
695 info->pba_to_lba = kmalloc(numblocks*sizeof(int), GFP_NOIO);
697 if (info->lba_to_pba == NULL || info->pba_to_lba == NULL) {
698 kfree(info->lba_to_pba);
699 kfree(info->pba_to_lba);
700 info->lba_to_pba = NULL;
701 info->pba_to_lba = NULL;
706 memset(info->lba_to_pba, 0xff, numblocks*sizeof(int));
707 memset(info->pba_to_lba, 0xff, numblocks*sizeof(int));
709 /* set maximum lba */
710 max_lba = info->max_log_blks;
714 // Each block is 64 bytes of control data, so block i is located in
715 // scatterlist block i*64/128k = i*(2^6)*(2^-17) = i*(2^-11)
717 for (i=0; i<numblocks; i++) {
720 lba = short_pack(buffer[i * 2], buffer[i * 2 + 1]);
722 /* Every 1024 physical blocks ("zone"), the LBA numbers
723 * go back to zero, but are within a higher
724 * block of LBA's. Also, there is a maximum of
725 * 1000 LBA's per zone. In other words, in PBA
726 * 1024-2047 you will find LBA 0-999 which are
727 * really LBA 1000-1999. Yes, this wastes 24
728 * physical blocks per zone. Go figure.
729 * These devices can have blocks go bad, so there
730 * are 24 spare blocks to use when blocks do go bad.
733 /* SDDR55 returns 0xffff for a bad block, and 0x400 for the
734 * CIS block. (Is this true for cards 8MB or less??)
735 * Record these in the physical to logical map
738 info->pba_to_lba[i] = lba;
740 if (lba >= max_lba) {
744 if (info->lba_to_pba[lba + zone * 1000] != NOT_ALLOCATED &&
745 !info->force_read_only) {
747 "sddr55: map inconsistency at LBA %04X\n",
749 info->force_read_only = 1;
752 if (lba<0x10 || (lba>=0x3E0 && lba<0x3EF))
753 US_DEBUGP("LBA %04X <-> PBA %04X\n", lba, i);
755 info->lba_to_pba[lba + zone * 1000] = i;
763 static void sddr55_card_info_destructor(void *extra) {
764 struct sddr55_card_info *info = (struct sddr55_card_info *)extra;
769 kfree(info->lba_to_pba);
770 kfree(info->pba_to_lba);
775 * Transport for the Sandisk SDDR-55
777 static int sddr55_transport(struct scsi_cmnd *srb, struct us_data *us)
780 static unsigned char inquiry_response[8] = {
781 0x00, 0x80, 0x00, 0x02, 0x1F, 0x00, 0x00, 0x00
783 // write-protected for now, no block descriptor support
784 static unsigned char mode_page_01[20] = {
785 0x0, 0x12, 0x00, 0x80, 0x0, 0x0, 0x0, 0x0,
787 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
789 unsigned char *ptr = us->iobuf;
790 unsigned long capacity;
794 unsigned short pages;
795 struct sddr55_card_info *info;
799 sizeof(struct sddr55_card_info), GFP_NOIO);
801 return USB_STOR_TRANSPORT_ERROR;
802 us->extra_destructor = sddr55_card_info_destructor;
805 info = (struct sddr55_card_info *)(us->extra);
807 if (srb->cmnd[0] == REQUEST_SENSE) {
808 US_DEBUGP("SDDR55: request sense %02x/%02x/%02x\n", info->sense_data[2], info->sense_data[12], info->sense_data[13]);
810 memcpy (ptr, info->sense_data, sizeof info->sense_data);
813 usb_stor_set_xfer_buf (ptr, sizeof info->sense_data, srb);
814 memset (info->sense_data, 0, sizeof info->sense_data);
816 return USB_STOR_TRANSPORT_GOOD;
819 memset (info->sense_data, 0, sizeof info->sense_data);
821 /* Dummy up a response for INQUIRY since SDDR55 doesn't
822 respond to INQUIRY commands */
824 if (srb->cmnd[0] == INQUIRY) {
825 memcpy(ptr, inquiry_response, 8);
826 fill_inquiry_response(us, ptr, 36);
827 return USB_STOR_TRANSPORT_GOOD;
830 /* only check card status if the map isn't allocated, ie no card seen yet
831 * or if it's been over half a second since we last accessed it
833 if (info->lba_to_pba == NULL || time_after(jiffies, info->last_access + HZ/2)) {
835 /* check to see if a card is fitted */
836 result = sddr55_status (us);
838 result = sddr55_status (us);
840 set_sense_info (6, 0x28, 0); /* new media, set unit attention, not ready to ready */
842 return USB_STOR_TRANSPORT_FAILED;
846 /* if we detected a problem with the map when writing,
847 don't allow any more access */
848 if (info->fatal_error) {
850 set_sense_info (3, 0x31, 0);
851 return USB_STOR_TRANSPORT_FAILED;
854 if (srb->cmnd[0] == READ_CAPACITY) {
856 capacity = sddr55_get_capacity(us);
859 set_sense_info (3, 0x30, 0); /* incompatible medium */
860 return USB_STOR_TRANSPORT_FAILED;
863 info->capacity = capacity;
865 /* figure out the maximum logical block number, allowing for
866 * the fact that only 250 out of every 256 are used */
867 info->max_log_blks = ((info->capacity >> (info->pageshift + info->blockshift)) / 256) * 250;
869 /* Last page in the card, adjust as we only use 250 out of
871 capacity = (capacity / 256) * 250;
873 capacity /= PAGESIZE;
876 ((__be32 *) ptr)[0] = cpu_to_be32(capacity);
877 ((__be32 *) ptr)[1] = cpu_to_be32(PAGESIZE);
878 usb_stor_set_xfer_buf(ptr, 8, srb);
882 return USB_STOR_TRANSPORT_GOOD;
885 if (srb->cmnd[0] == MODE_SENSE_10) {
887 memcpy(ptr, mode_page_01, sizeof mode_page_01);
888 ptr[3] = (info->read_only || info->force_read_only) ? 0x80 : 0;
889 usb_stor_set_xfer_buf(ptr, sizeof(mode_page_01), srb);
891 if ( (srb->cmnd[2] & 0x3F) == 0x01 ) {
893 "SDDR55: Dummy up request for mode page 1\n");
894 return USB_STOR_TRANSPORT_GOOD;
896 } else if ( (srb->cmnd[2] & 0x3F) == 0x3F ) {
898 "SDDR55: Dummy up request for all mode pages\n");
899 return USB_STOR_TRANSPORT_GOOD;
902 set_sense_info (5, 0x24, 0); /* invalid field in command */
903 return USB_STOR_TRANSPORT_FAILED;
906 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
909 "SDDR55: %s medium removal. Not that I can do"
910 " anything about it...\n",
911 (srb->cmnd[4]&0x03) ? "Prevent" : "Allow");
913 return USB_STOR_TRANSPORT_GOOD;
917 if (srb->cmnd[0] == READ_10 || srb->cmnd[0] == WRITE_10) {
919 page = short_pack(srb->cmnd[3], srb->cmnd[2]);
921 page |= short_pack(srb->cmnd[5], srb->cmnd[4]);
922 pages = short_pack(srb->cmnd[8], srb->cmnd[7]);
924 page <<= info->smallpageshift;
926 // convert page to block and page-within-block
928 lba = page >> info->blockshift;
929 page = page & info->blockmask;
931 // locate physical block corresponding to logical block
933 if (lba >= info->max_log_blks) {
935 US_DEBUGP("Error: Requested LBA %04X exceeds maximum "
936 "block %04X\n", lba, info->max_log_blks-1);
938 set_sense_info (5, 0x24, 0); /* invalid field in command */
940 return USB_STOR_TRANSPORT_FAILED;
943 pba = info->lba_to_pba[lba];
945 if (srb->cmnd[0] == WRITE_10) {
946 US_DEBUGP("WRITE_10: write block %04X (LBA %04X) page %01X"
948 pba, lba, page, pages);
950 return sddr55_write_data(us, lba, page, pages);
952 US_DEBUGP("READ_10: read block %04X (LBA %04X) page %01X"
954 pba, lba, page, pages);
956 return sddr55_read_data(us, lba, page, pages);
961 if (srb->cmnd[0] == TEST_UNIT_READY) {
962 return USB_STOR_TRANSPORT_GOOD;
965 if (srb->cmnd[0] == START_STOP) {
966 return USB_STOR_TRANSPORT_GOOD;
969 set_sense_info (5, 0x20, 0); /* illegal command */
971 return USB_STOR_TRANSPORT_FAILED; // FIXME: sense buffer?
975 static int sddr55_probe(struct usb_interface *intf,
976 const struct usb_device_id *id)
981 result = usb_stor_probe1(&us, intf, id,
982 (id - sddr55_usb_ids) + sddr55_unusual_dev_list);
986 us->transport_name = "SDDR55";
987 us->transport = sddr55_transport;
988 us->transport_reset = sddr55_reset;
991 result = usb_stor_probe2(us);
995 static struct usb_driver sddr55_driver = {
996 .name = "ums-sddr55",
997 .probe = sddr55_probe,
998 .disconnect = usb_stor_disconnect,
999 .suspend = usb_stor_suspend,
1000 .resume = usb_stor_resume,
1001 .reset_resume = usb_stor_reset_resume,
1002 .pre_reset = usb_stor_pre_reset,
1003 .post_reset = usb_stor_post_reset,
1004 .id_table = sddr55_usb_ids,
1008 static int __init sddr55_init(void)
1010 return usb_register(&sddr55_driver);
1013 static void __exit sddr55_exit(void)
1015 usb_deregister(&sddr55_driver);
1018 module_init(sddr55_init);
1019 module_exit(sddr55_exit);