ChangeSet 1.1474.81.34, 2004/01/16 17:18:02-08:00, mdharm-usb@one-eyed-alien.net [PATCH] USB Storage: fix mode-sense handling for 10-byte commands This patch fixes sddr09 and sddr55 to suppor the MODE_SENSE_10 commands, which are the only variants used by sd.c drivers/usb/storage/sddr09.c | 16 +++++++++------- drivers/usb/storage/sddr55.c | 18 ++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff -Nru a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c --- a/drivers/usb/storage/sddr09.c Tue Jan 20 17:34:19 2004 +++ b/drivers/usb/storage/sddr09.c Tue Jan 20 17:34:19 2004 @@ -1387,8 +1387,9 @@ 0x00, 0x80, 0x00, 0x02, 0x1F, 0x00, 0x00, 0x00 }; - static unsigned char mode_page_01[16] = { - 0x0F, 0x00, 0, 0x00, + /* note: no block descriptor support */ + static unsigned char mode_page_01[19] = { + 0x00, 0x0F, 0x00, 0x0, 0x0, 0x0, 0x00, 0x01, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -1466,7 +1467,7 @@ return USB_STOR_TRANSPORT_GOOD; } - if (srb->cmnd[0] == MODE_SENSE) { + if (srb->cmnd[0] == MODE_SENSE_10) { int modepage = (srb->cmnd[2] & 0x3F); /* They ask for the Read/Write error recovery page, @@ -1477,8 +1478,8 @@ "mode page 0x%x\n", modepage); memcpy(ptr, mode_page_01, sizeof(mode_page_01)); - ptr[0] = sizeof(mode_page_01) - 1; - ptr[2] = (info->flags & SDDR09_WP) ? 0x80 : 0; + ((u16*)ptr)[0] = sizeof(mode_page_01) - 2; + ptr[3] = (info->flags & SDDR09_WP) ? 0x80 : 0; usb_stor_set_xfer_buf(ptr, sizeof(mode_page_01), srb); return USB_STOR_TRANSPORT_GOOD; } @@ -1519,8 +1520,9 @@ return sddr09_write_data(us, page, pages); } - // Pass TEST_UNIT_READY and REQUEST_SENSE through - + /* catch-all for all other commands, except + * pass TEST_UNIT_READY and REQUEST_SENSE through + */ if (srb->cmnd[0] != TEST_UNIT_READY && srb->cmnd[0] != REQUEST_SENSE) { sensekey = 0x05; /* illegal request */ diff -Nru a/drivers/usb/storage/sddr55.c b/drivers/usb/storage/sddr55.c --- a/drivers/usb/storage/sddr55.c Tue Jan 20 17:34:19 2004 +++ b/drivers/usb/storage/sddr55.c Tue Jan 20 17:34:19 2004 @@ -740,8 +740,9 @@ static unsigned char inquiry_response[8] = { 0x00, 0x80, 0x00, 0x02, 0x1F, 0x00, 0x00, 0x00 }; - static unsigned char mode_page_01[16] = { // write-protected for now - 0x03, 0x00, 0x80, 0x00, + // write-protected for now, no block descriptor support + static unsigned char mode_page_01[20] = { + 0x0, 0x12, 0x00, 0x80, 0x0, 0x0, 0x0, 0x0, 0x01, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -826,7 +827,8 @@ * the fact that only 250 out of every 256 are used */ info->max_log_blks = ((info->capacity >> (info->pageshift + info->blockshift)) / 256) * 250; - /* Last page in the card, adjust as we only use 250 out of every 256 pages */ + /* Last page in the card, adjust as we only use 250 out of + * every 256 pages */ capacity = (capacity / 256) * 250; capacity /= PAGESIZE; @@ -841,28 +843,24 @@ return USB_STOR_TRANSPORT_GOOD; } - if (srb->cmnd[0] == MODE_SENSE) { + if (srb->cmnd[0] == MODE_SENSE_10) { memcpy(ptr, mode_page_01, sizeof mode_page_01); - ptr[2] = (info->read_only || info->force_read_only) ? 0x80 : 0; + ptr[3] = (info->read_only || info->force_read_only) ? 0x80 : 0; + usb_stor_set_xfer_buf(ptr, sizeof(mode_page_01), srb); if ( (srb->cmnd[2] & 0x3F) == 0x01 ) { - US_DEBUGP( "SDDR55: Dummy up request for mode page 1\n"); - return USB_STOR_TRANSPORT_GOOD; } else if ( (srb->cmnd[2] & 0x3F) == 0x3F ) { - US_DEBUGP( "SDDR55: Dummy up request for all mode pages\n"); - return USB_STOR_TRANSPORT_GOOD; } set_sense_info (5, 0x24, 0); /* invalid field in command */ - return USB_STOR_TRANSPORT_FAILED; }