1 /* Driver for SanDisk SDDR-55 SmartMedia reader
9 * Current development and maintenance by:
10 * (c) 2002 Simon Munton
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2, or (at your option) any
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <linux/jiffies.h>
28 #include <linux/errno.h>
29 #include <linux/slab.h>
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_cmnd.h>
35 #include "transport.h"
41 #define short_pack(lsb,msb) ( ((u16)(lsb)) | ( ((u16)(msb))<<8 ) )
42 #define LSB_of(s) ((s)&0xFF)
43 #define MSB_of(s) ((s)>>8)
46 #define set_sense_info(sk, asc, ascq) \
48 info->sense_data[2] = sk; \
49 info->sense_data[12] = asc; \
50 info->sense_data[13] = ascq; \
54 struct sddr55_card_info
{
55 unsigned long capacity
; /* Size of card in bytes */
56 int max_log_blks
; /* maximum number of logical blocks */
57 int pageshift
; /* log2 of pagesize */
58 int smallpageshift
; /* 1 if pagesize == 256 */
59 int blocksize
; /* Size of block in pages */
60 int blockshift
; /* log2 of blocksize */
61 int blockmask
; /* 2^blockshift - 1 */
62 int read_only
; /* non zero if card is write protected */
63 int force_read_only
; /* non zero if we find a map error*/
64 int *lba_to_pba
; /* logical to physical map */
65 int *pba_to_lba
; /* physical to logical map */
66 int fatal_error
; /* set if we detect something nasty */
67 unsigned long last_access
; /* number of jiffies since we last talked to device */
68 unsigned char sense_data
[18];
72 #define NOT_ALLOCATED 0xffffffff
73 #define BAD_BLOCK 0xffff
74 #define CIS_BLOCK 0x400
75 #define UNUSED_BLOCK 0x3ff
78 sddr55_bulk_transport(struct us_data
*us
, int direction
,
79 unsigned char *data
, unsigned int len
) {
80 struct sddr55_card_info
*info
= (struct sddr55_card_info
*)us
->extra
;
81 unsigned int pipe
= (direction
== DMA_FROM_DEVICE
) ?
82 us
->recv_bulk_pipe
: us
->send_bulk_pipe
;
85 return USB_STOR_XFER_GOOD
;
86 info
->last_access
= jiffies
;
87 return usb_stor_bulk_transfer_buf(us
, pipe
, data
, len
, NULL
);
90 /* check if card inserted, if there is, update read_only status
91 * return non zero if no card
94 static int sddr55_status(struct us_data
*us
)
97 unsigned char *command
= us
->iobuf
;
98 unsigned char *status
= us
->iobuf
;
99 struct sddr55_card_info
*info
= (struct sddr55_card_info
*)us
->extra
;
102 memset(command
, 0, 8);
105 result
= sddr55_bulk_transport(us
,
106 DMA_TO_DEVICE
, command
, 8);
108 US_DEBUGP("Result for send_command in status %d\n",
111 if (result
!= USB_STOR_XFER_GOOD
) {
112 set_sense_info (4, 0, 0); /* hardware error */
113 return USB_STOR_TRANSPORT_ERROR
;
116 result
= sddr55_bulk_transport(us
,
117 DMA_FROM_DEVICE
, status
, 4);
119 /* expect to get short transfer if no card fitted */
120 if (result
== USB_STOR_XFER_SHORT
|| result
== USB_STOR_XFER_STALLED
) {
121 /* had a short transfer, no card inserted, free map memory */
122 kfree(info
->lba_to_pba
);
123 kfree(info
->pba_to_lba
);
124 info
->lba_to_pba
= NULL
;
125 info
->pba_to_lba
= NULL
;
127 info
->fatal_error
= 0;
128 info
->force_read_only
= 0;
130 set_sense_info (2, 0x3a, 0); /* not ready, medium not present */
131 return USB_STOR_TRANSPORT_FAILED
;
134 if (result
!= USB_STOR_XFER_GOOD
) {
135 set_sense_info (4, 0, 0); /* hardware error */
136 return USB_STOR_TRANSPORT_FAILED
;
139 /* check write protect status */
140 info
->read_only
= (status
[0] & 0x20);
142 /* now read status */
143 result
= sddr55_bulk_transport(us
,
144 DMA_FROM_DEVICE
, status
, 2);
146 if (result
!= USB_STOR_XFER_GOOD
) {
147 set_sense_info (4, 0, 0); /* hardware error */
150 return (result
== USB_STOR_XFER_GOOD
?
151 USB_STOR_TRANSPORT_GOOD
: USB_STOR_TRANSPORT_FAILED
);
155 static int sddr55_read_data(struct us_data
*us
,
158 unsigned short sectors
) {
160 int result
= USB_STOR_TRANSPORT_GOOD
;
161 unsigned char *command
= us
->iobuf
;
162 unsigned char *status
= us
->iobuf
;
163 struct sddr55_card_info
*info
= (struct sddr55_card_info
*)us
->extra
;
164 unsigned char *buffer
;
167 unsigned long address
;
169 unsigned short pages
;
170 unsigned int len
, offset
;
171 struct scatterlist
*sg
;
173 // Since we only read in one block at a time, we have to create
174 // a bounce buffer and move the data a piece at a time between the
175 // bounce buffer and the actual transfer buffer.
177 len
= min((unsigned int) sectors
, (unsigned int) info
->blocksize
>>
178 info
->smallpageshift
) * PAGESIZE
;
179 buffer
= kmalloc(len
, GFP_NOIO
);
181 return USB_STOR_TRANSPORT_ERROR
; /* out of memory */
187 /* have we got to end? */
188 if (lba
>= info
->max_log_blks
)
191 pba
= info
->lba_to_pba
[lba
];
193 // Read as many sectors as possible in this block
195 pages
= min((unsigned int) sectors
<< info
->smallpageshift
,
196 info
->blocksize
- page
);
197 len
= pages
<< info
->pageshift
;
199 US_DEBUGP("Read %02X pages, from PBA %04X"
200 " (LBA %04X) page %02X\n",
201 pages
, pba
, lba
, page
);
203 if (pba
== NOT_ALLOCATED
) {
204 /* no pba for this lba, fill with zeroes */
205 memset (buffer
, 0, len
);
208 address
= (pba
<< info
->blockshift
) + page
;
211 command
[1] = LSB_of(address
>>16);
212 command
[2] = LSB_of(address
>>8);
213 command
[3] = LSB_of(address
);
217 command
[6] = LSB_of(pages
<< (1 - info
->smallpageshift
));
221 result
= sddr55_bulk_transport(us
,
222 DMA_TO_DEVICE
, command
, 8);
224 US_DEBUGP("Result for send_command in read_data %d\n",
227 if (result
!= USB_STOR_XFER_GOOD
) {
228 result
= USB_STOR_TRANSPORT_ERROR
;
233 result
= sddr55_bulk_transport(us
,
234 DMA_FROM_DEVICE
, buffer
, len
);
236 if (result
!= USB_STOR_XFER_GOOD
) {
237 result
= USB_STOR_TRANSPORT_ERROR
;
241 /* now read status */
242 result
= sddr55_bulk_transport(us
,
243 DMA_FROM_DEVICE
, status
, 2);
245 if (result
!= USB_STOR_XFER_GOOD
) {
246 result
= USB_STOR_TRANSPORT_ERROR
;
250 /* check status for error */
251 if (status
[0] == 0xff && status
[1] == 0x4) {
252 set_sense_info (3, 0x11, 0);
253 result
= USB_STOR_TRANSPORT_FAILED
;
258 // Store the data in the transfer buffer
259 usb_stor_access_xfer_buf(buffer
, len
, us
->srb
,
260 &sg
, &offset
, TO_XFER_BUF
);
264 sectors
-= pages
>> info
->smallpageshift
;
267 result
= USB_STOR_TRANSPORT_GOOD
;
275 static int sddr55_write_data(struct us_data
*us
,
278 unsigned short sectors
) {
280 int result
= USB_STOR_TRANSPORT_GOOD
;
281 unsigned char *command
= us
->iobuf
;
282 unsigned char *status
= us
->iobuf
;
283 struct sddr55_card_info
*info
= (struct sddr55_card_info
*)us
->extra
;
284 unsigned char *buffer
;
287 unsigned int new_pba
;
288 unsigned long address
;
290 unsigned short pages
;
292 unsigned int len
, offset
;
293 struct scatterlist
*sg
;
295 /* check if we are allowed to write */
296 if (info
->read_only
|| info
->force_read_only
) {
297 set_sense_info (7, 0x27, 0); /* read only */
298 return USB_STOR_TRANSPORT_FAILED
;
301 // Since we only write one block at a time, we have to create
302 // a bounce buffer and move the data a piece at a time between the
303 // bounce buffer and the actual transfer buffer.
305 len
= min((unsigned int) sectors
, (unsigned int) info
->blocksize
>>
306 info
->smallpageshift
) * PAGESIZE
;
307 buffer
= kmalloc(len
, GFP_NOIO
);
309 return USB_STOR_TRANSPORT_ERROR
;
313 while (sectors
> 0) {
315 /* have we got to end? */
316 if (lba
>= info
->max_log_blks
)
319 pba
= info
->lba_to_pba
[lba
];
321 // Write as many sectors as possible in this block
323 pages
= min((unsigned int) sectors
<< info
->smallpageshift
,
324 info
->blocksize
- page
);
325 len
= pages
<< info
->pageshift
;
327 // Get the data from the transfer buffer
328 usb_stor_access_xfer_buf(buffer
, len
, us
->srb
,
329 &sg
, &offset
, FROM_XFER_BUF
);
331 US_DEBUGP("Write %02X pages, to PBA %04X"
332 " (LBA %04X) page %02X\n",
333 pages
, pba
, lba
, page
);
337 if (pba
== NOT_ALLOCATED
) {
338 /* no pba allocated for this lba, find a free pba to use */
340 int max_pba
= (info
->max_log_blks
/ 250 ) * 256;
344 /* set pba to first block in zone lba is in */
345 pba
= (lba
/ 1000) * 1024;
347 US_DEBUGP("No PBA for LBA %04X\n",lba
);
353 * Scan through the map looking for an unused block
354 * leave 16 unused blocks at start (or as many as
355 * possible) since the sddr55 seems to reuse a used
356 * block when it shouldn't if we don't leave space.
358 for (i
= 0; i
< max_pba
; i
++, pba
++) {
359 if (info
->pba_to_lba
[pba
] == UNUSED_BLOCK
) {
361 if (found_count
++ > 16)
370 US_DEBUGP("Couldn't find unallocated block\n");
372 set_sense_info (3, 0x31, 0); /* medium error */
373 result
= USB_STOR_TRANSPORT_FAILED
;
377 US_DEBUGP("Allocating PBA %04X for LBA %04X\n", pba
, lba
);
379 /* set writing to unallocated block flag */
383 address
= (pba
<< info
->blockshift
) + page
;
385 command
[1] = LSB_of(address
>>16);
386 command
[2] = LSB_of(address
>>8);
387 command
[3] = LSB_of(address
);
389 /* set the lba into the command, modulo 1000 */
390 command
[0] = LSB_of(lba
% 1000);
391 command
[6] = MSB_of(lba
% 1000);
393 command
[4] |= LSB_of(pages
>> info
->smallpageshift
);
398 result
= sddr55_bulk_transport(us
,
399 DMA_TO_DEVICE
, command
, 8);
401 if (result
!= USB_STOR_XFER_GOOD
) {
402 US_DEBUGP("Result for send_command in write_data %d\n",
405 /* set_sense_info is superfluous here? */
406 set_sense_info (3, 0x3, 0);/* peripheral write error */
407 result
= USB_STOR_TRANSPORT_FAILED
;
412 result
= sddr55_bulk_transport(us
,
413 DMA_TO_DEVICE
, buffer
, len
);
415 if (result
!= USB_STOR_XFER_GOOD
) {
416 US_DEBUGP("Result for send_data in write_data %d\n",
419 /* set_sense_info is superfluous here? */
420 set_sense_info (3, 0x3, 0);/* peripheral write error */
421 result
= USB_STOR_TRANSPORT_FAILED
;
425 /* now read status */
426 result
= sddr55_bulk_transport(us
, DMA_FROM_DEVICE
, status
, 6);
428 if (result
!= USB_STOR_XFER_GOOD
) {
429 US_DEBUGP("Result for get_status in write_data %d\n",
432 /* set_sense_info is superfluous here? */
433 set_sense_info (3, 0x3, 0);/* peripheral write error */
434 result
= USB_STOR_TRANSPORT_FAILED
;
438 new_pba
= (status
[3] + (status
[4] << 8) + (status
[5] << 16))
441 /* check status for error */
442 if (status
[0] == 0xff && status
[1] == 0x4) {
443 info
->pba_to_lba
[new_pba
] = BAD_BLOCK
;
445 set_sense_info (3, 0x0c, 0);
446 result
= USB_STOR_TRANSPORT_FAILED
;
450 US_DEBUGP("Updating maps for LBA %04X: old PBA %04X, new PBA %04X\n",
453 /* update the lba<->pba maps, note new_pba might be the same as pba */
454 info
->lba_to_pba
[lba
] = new_pba
;
455 info
->pba_to_lba
[pba
] = UNUSED_BLOCK
;
457 /* check that new_pba wasn't already being used */
458 if (info
->pba_to_lba
[new_pba
] != UNUSED_BLOCK
) {
459 printk(KERN_ERR
"sddr55 error: new PBA %04X already in use for LBA %04X\n",
460 new_pba
, info
->pba_to_lba
[new_pba
]);
461 info
->fatal_error
= 1;
462 set_sense_info (3, 0x31, 0);
463 result
= USB_STOR_TRANSPORT_FAILED
;
467 /* update the pba<->lba maps for new_pba */
468 info
->pba_to_lba
[new_pba
] = lba
% 1000;
472 sectors
-= pages
>> info
->smallpageshift
;
474 result
= USB_STOR_TRANSPORT_GOOD
;
481 static int sddr55_read_deviceID(struct us_data
*us
,
482 unsigned char *manufacturerID
,
483 unsigned char *deviceID
) {
486 unsigned char *command
= us
->iobuf
;
487 unsigned char *content
= us
->iobuf
;
489 memset(command
, 0, 8);
492 result
= sddr55_bulk_transport(us
, DMA_TO_DEVICE
, command
, 8);
494 US_DEBUGP("Result of send_control for device ID is %d\n",
497 if (result
!= USB_STOR_XFER_GOOD
)
498 return USB_STOR_TRANSPORT_ERROR
;
500 result
= sddr55_bulk_transport(us
,
501 DMA_FROM_DEVICE
, content
, 4);
503 if (result
!= USB_STOR_XFER_GOOD
)
504 return USB_STOR_TRANSPORT_ERROR
;
506 *manufacturerID
= content
[0];
507 *deviceID
= content
[1];
509 if (content
[0] != 0xff) {
510 result
= sddr55_bulk_transport(us
,
511 DMA_FROM_DEVICE
, content
, 2);
514 return USB_STOR_TRANSPORT_GOOD
;
518 int sddr55_reset(struct us_data
*us
) {
523 static unsigned long sddr55_get_capacity(struct us_data
*us
) {
525 <<<<<<< HEAD
:drivers
/usb
/storage
/sddr55
.c
526 unsigned char manufacturerID
;
527 unsigned char deviceID
;
529 unsigned char uninitialized_var(manufacturerID
);
530 unsigned char uninitialized_var(deviceID
);
531 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/storage
/sddr55
.c
533 struct sddr55_card_info
*info
= (struct sddr55_card_info
*)us
->extra
;
535 US_DEBUGP("Reading capacity...\n");
537 result
= sddr55_read_deviceID(us
,
541 US_DEBUGP("Result of read_deviceID is %d\n",
544 if (result
!= USB_STOR_XFER_GOOD
)
547 US_DEBUGP("Device ID = %02X\n", deviceID
);
548 US_DEBUGP("Manuf ID = %02X\n", manufacturerID
);
551 info
->smallpageshift
= 0;
552 info
->blocksize
= 16;
553 info
->blockshift
= 4;
554 info
->blockmask
= 15;
562 info
->smallpageshift
= 1;
568 info
->smallpageshift
= 1;
569 case 0x5d: // 5d is a ROM card with pagesize 512.
583 info
->blocksize
= 32;
584 info
->blockshift
= 5;
585 info
->blockmask
= 31;
589 info
->blocksize
= 32;
590 info
->blockshift
= 5;
591 info
->blockmask
= 31;
595 info
->blocksize
= 32;
596 info
->blockshift
= 5;
597 info
->blockmask
= 31;
601 info
->blocksize
= 32;
602 info
->blockshift
= 5;
603 info
->blockmask
= 31;
612 static int sddr55_read_map(struct us_data
*us
) {
614 struct sddr55_card_info
*info
= (struct sddr55_card_info
*)(us
->extra
);
616 unsigned char *buffer
;
617 unsigned char *command
= us
->iobuf
;
620 unsigned short max_lba
;
626 numblocks
= info
->capacity
>> (info
->blockshift
+ info
->pageshift
);
628 buffer
= kmalloc( numblocks
* 2, GFP_NOIO
);
633 memset(command
, 0, 8);
635 command
[6] = numblocks
* 2 / 256;
638 result
= sddr55_bulk_transport(us
, DMA_TO_DEVICE
, command
, 8);
640 if ( result
!= USB_STOR_XFER_GOOD
) {
645 result
= sddr55_bulk_transport(us
, DMA_FROM_DEVICE
, buffer
, numblocks
* 2);
647 if ( result
!= USB_STOR_XFER_GOOD
) {
652 result
= sddr55_bulk_transport(us
, DMA_FROM_DEVICE
, command
, 2);
654 if ( result
!= USB_STOR_XFER_GOOD
) {
659 kfree(info
->lba_to_pba
);
660 kfree(info
->pba_to_lba
);
661 info
->lba_to_pba
= kmalloc(numblocks
*sizeof(int), GFP_NOIO
);
662 info
->pba_to_lba
= kmalloc(numblocks
*sizeof(int), GFP_NOIO
);
664 if (info
->lba_to_pba
== NULL
|| info
->pba_to_lba
== NULL
) {
665 kfree(info
->lba_to_pba
);
666 kfree(info
->pba_to_lba
);
667 info
->lba_to_pba
= NULL
;
668 info
->pba_to_lba
= NULL
;
673 memset(info
->lba_to_pba
, 0xff, numblocks
*sizeof(int));
674 memset(info
->pba_to_lba
, 0xff, numblocks
*sizeof(int));
676 /* set maximum lba */
677 max_lba
= info
->max_log_blks
;
681 // Each block is 64 bytes of control data, so block i is located in
682 // scatterlist block i*64/128k = i*(2^6)*(2^-17) = i*(2^-11)
684 for (i
=0; i
<numblocks
; i
++) {
687 lba
= short_pack(buffer
[i
* 2], buffer
[i
* 2 + 1]);
689 /* Every 1024 physical blocks ("zone"), the LBA numbers
690 * go back to zero, but are within a higher
691 * block of LBA's. Also, there is a maximum of
692 * 1000 LBA's per zone. In other words, in PBA
693 * 1024-2047 you will find LBA 0-999 which are
694 * really LBA 1000-1999. Yes, this wastes 24
695 * physical blocks per zone. Go figure.
696 * These devices can have blocks go bad, so there
697 * are 24 spare blocks to use when blocks do go bad.
700 /* SDDR55 returns 0xffff for a bad block, and 0x400 for the
701 * CIS block. (Is this true for cards 8MB or less??)
702 * Record these in the physical to logical map
705 info
->pba_to_lba
[i
] = lba
;
707 if (lba
>= max_lba
) {
711 if (info
->lba_to_pba
[lba
+ zone
* 1000] != NOT_ALLOCATED
&&
712 !info
->force_read_only
) {
713 printk("sddr55: map inconsistency at LBA %04X\n", lba
+ zone
* 1000);
714 info
->force_read_only
= 1;
717 if (lba
<0x10 || (lba
>=0x3E0 && lba
<0x3EF))
718 US_DEBUGP("LBA %04X <-> PBA %04X\n", lba
, i
);
720 info
->lba_to_pba
[lba
+ zone
* 1000] = i
;
728 static void sddr55_card_info_destructor(void *extra
) {
729 struct sddr55_card_info
*info
= (struct sddr55_card_info
*)extra
;
734 kfree(info
->lba_to_pba
);
735 kfree(info
->pba_to_lba
);
740 * Transport for the Sandisk SDDR-55
742 int sddr55_transport(struct scsi_cmnd
*srb
, struct us_data
*us
)
745 static unsigned char inquiry_response
[8] = {
746 0x00, 0x80, 0x00, 0x02, 0x1F, 0x00, 0x00, 0x00
748 // write-protected for now, no block descriptor support
749 static unsigned char mode_page_01
[20] = {
750 0x0, 0x12, 0x00, 0x80, 0x0, 0x0, 0x0, 0x0,
752 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
754 unsigned char *ptr
= us
->iobuf
;
755 unsigned long capacity
;
759 unsigned short pages
;
760 struct sddr55_card_info
*info
;
764 sizeof(struct sddr55_card_info
), GFP_NOIO
);
766 return USB_STOR_TRANSPORT_ERROR
;
767 us
->extra_destructor
= sddr55_card_info_destructor
;
770 info
= (struct sddr55_card_info
*)(us
->extra
);
772 if (srb
->cmnd
[0] == REQUEST_SENSE
) {
773 US_DEBUGP("SDDR55: request sense %02x/%02x/%02x\n", info
->sense_data
[2], info
->sense_data
[12], info
->sense_data
[13]);
775 memcpy (ptr
, info
->sense_data
, sizeof info
->sense_data
);
778 usb_stor_set_xfer_buf (ptr
, sizeof info
->sense_data
, srb
);
779 memset (info
->sense_data
, 0, sizeof info
->sense_data
);
781 return USB_STOR_TRANSPORT_GOOD
;
784 memset (info
->sense_data
, 0, sizeof info
->sense_data
);
786 /* Dummy up a response for INQUIRY since SDDR55 doesn't
787 respond to INQUIRY commands */
789 if (srb
->cmnd
[0] == INQUIRY
) {
790 memcpy(ptr
, inquiry_response
, 8);
791 fill_inquiry_response(us
, ptr
, 36);
792 return USB_STOR_TRANSPORT_GOOD
;
795 /* only check card status if the map isn't allocated, ie no card seen yet
796 * or if it's been over half a second since we last accessed it
798 if (info
->lba_to_pba
== NULL
|| time_after(jiffies
, info
->last_access
+ HZ
/2)) {
800 /* check to see if a card is fitted */
801 result
= sddr55_status (us
);
803 result
= sddr55_status (us
);
805 set_sense_info (6, 0x28, 0); /* new media, set unit attention, not ready to ready */
807 return USB_STOR_TRANSPORT_FAILED
;
811 /* if we detected a problem with the map when writing,
812 don't allow any more access */
813 if (info
->fatal_error
) {
815 set_sense_info (3, 0x31, 0);
816 return USB_STOR_TRANSPORT_FAILED
;
819 if (srb
->cmnd
[0] == READ_CAPACITY
) {
821 capacity
= sddr55_get_capacity(us
);
824 set_sense_info (3, 0x30, 0); /* incompatible medium */
825 return USB_STOR_TRANSPORT_FAILED
;
828 info
->capacity
= capacity
;
830 /* figure out the maximum logical block number, allowing for
831 * the fact that only 250 out of every 256 are used */
832 info
->max_log_blks
= ((info
->capacity
>> (info
->pageshift
+ info
->blockshift
)) / 256) * 250;
834 /* Last page in the card, adjust as we only use 250 out of
836 capacity
= (capacity
/ 256) * 250;
838 capacity
/= PAGESIZE
;
841 ((__be32
*) ptr
)[0] = cpu_to_be32(capacity
);
842 ((__be32
*) ptr
)[1] = cpu_to_be32(PAGESIZE
);
843 usb_stor_set_xfer_buf(ptr
, 8, srb
);
847 return USB_STOR_TRANSPORT_GOOD
;
850 if (srb
->cmnd
[0] == MODE_SENSE_10
) {
852 memcpy(ptr
, mode_page_01
, sizeof mode_page_01
);
853 ptr
[3] = (info
->read_only
|| info
->force_read_only
) ? 0x80 : 0;
854 usb_stor_set_xfer_buf(ptr
, sizeof(mode_page_01
), srb
);
856 if ( (srb
->cmnd
[2] & 0x3F) == 0x01 ) {
858 "SDDR55: Dummy up request for mode page 1\n");
859 return USB_STOR_TRANSPORT_GOOD
;
861 } else if ( (srb
->cmnd
[2] & 0x3F) == 0x3F ) {
863 "SDDR55: Dummy up request for all mode pages\n");
864 return USB_STOR_TRANSPORT_GOOD
;
867 set_sense_info (5, 0x24, 0); /* invalid field in command */
868 return USB_STOR_TRANSPORT_FAILED
;
871 if (srb
->cmnd
[0] == ALLOW_MEDIUM_REMOVAL
) {
874 "SDDR55: %s medium removal. Not that I can do"
875 " anything about it...\n",
876 (srb
->cmnd
[4]&0x03) ? "Prevent" : "Allow");
878 return USB_STOR_TRANSPORT_GOOD
;
882 if (srb
->cmnd
[0] == READ_10
|| srb
->cmnd
[0] == WRITE_10
) {
884 page
= short_pack(srb
->cmnd
[3], srb
->cmnd
[2]);
886 page
|= short_pack(srb
->cmnd
[5], srb
->cmnd
[4]);
887 pages
= short_pack(srb
->cmnd
[8], srb
->cmnd
[7]);
889 page
<<= info
->smallpageshift
;
891 // convert page to block and page-within-block
893 lba
= page
>> info
->blockshift
;
894 page
= page
& info
->blockmask
;
896 // locate physical block corresponding to logical block
898 if (lba
>= info
->max_log_blks
) {
900 US_DEBUGP("Error: Requested LBA %04X exceeds maximum "
901 "block %04X\n", lba
, info
->max_log_blks
-1);
903 set_sense_info (5, 0x24, 0); /* invalid field in command */
905 return USB_STOR_TRANSPORT_FAILED
;
908 pba
= info
->lba_to_pba
[lba
];
910 if (srb
->cmnd
[0] == WRITE_10
) {
911 US_DEBUGP("WRITE_10: write block %04X (LBA %04X) page %01X"
913 pba
, lba
, page
, pages
);
915 return sddr55_write_data(us
, lba
, page
, pages
);
917 US_DEBUGP("READ_10: read block %04X (LBA %04X) page %01X"
919 pba
, lba
, page
, pages
);
921 return sddr55_read_data(us
, lba
, page
, pages
);
926 if (srb
->cmnd
[0] == TEST_UNIT_READY
) {
927 return USB_STOR_TRANSPORT_GOOD
;
930 if (srb
->cmnd
[0] == START_STOP
) {
931 return USB_STOR_TRANSPORT_GOOD
;
934 set_sense_info (5, 0x20, 0); /* illegal command */
936 return USB_STOR_TRANSPORT_FAILED
; // FIXME: sense buffer?