Commit 0dc08a35 authored by Matthew Dharm's avatar Matthew Dharm Committed by Greg Kroah-Hartman

[PATCH] USB Storage: sddr09 cleanups

This is the second of three patches to prepare the sddr09 subdriver for
conversion to the Sim-SCSI framework.  This patch (as595) updates the
code to use standard error values for return codes instead of our
special-purpose USB_STOR_TRANSPORT_... codes.  The reverse update is
then needed in the transport routine, but with the Sim-SCSI framework
that routine will go away.
Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Acked-by: default avatarAndries Brouwer <Andries.Brouwer@cwi.nl>
Signed-off-by: default avatarMatthew Dharm <mdharm-usb@one-eyed-alien.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent f5b8cb9c
...@@ -274,8 +274,11 @@ sddr09_send_command(struct us_data *us, ...@@ -274,8 +274,11 @@ sddr09_send_command(struct us_data *us,
rc = usb_stor_ctrl_transfer(us, pipe, request, requesttype, rc = usb_stor_ctrl_transfer(us, pipe, request, requesttype,
0, 0, xfer_data, xfer_len); 0, 0, xfer_data, xfer_len);
return (rc == USB_STOR_XFER_GOOD ? USB_STOR_TRANSPORT_GOOD : switch (rc) {
USB_STOR_TRANSPORT_ERROR); case USB_STOR_XFER_GOOD: return 0;
case USB_STOR_XFER_STALLED: return -EPIPE;
default: return -EIO;
}
} }
static int static int
...@@ -322,20 +325,12 @@ sddr09_request_sense(struct us_data *us, unsigned char *sensebuf, int buflen) { ...@@ -322,20 +325,12 @@ sddr09_request_sense(struct us_data *us, unsigned char *sensebuf, int buflen) {
command[4] = buflen; command[4] = buflen;
result = sddr09_send_scsi_command(us, command, 12); result = sddr09_send_scsi_command(us, command, 12);
if (result != USB_STOR_TRANSPORT_GOOD) { if (result)
US_DEBUGP("request sense failed\n");
return result; return result;
}
result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
sensebuf, buflen, NULL); sensebuf, buflen, NULL);
if (result != USB_STOR_XFER_GOOD) { return (result == USB_STOR_XFER_GOOD ? 0 : -EIO);
US_DEBUGP("request sense bulk in failed\n");
return USB_STOR_TRANSPORT_ERROR;
} else {
US_DEBUGP("request sense worked\n");
return USB_STOR_TRANSPORT_GOOD;
}
} }
/* /*
...@@ -383,7 +378,7 @@ sddr09_readX(struct us_data *us, int x, unsigned long fromaddress, ...@@ -383,7 +378,7 @@ sddr09_readX(struct us_data *us, int x, unsigned long fromaddress,
result = sddr09_send_scsi_command(us, command, 12); result = sddr09_send_scsi_command(us, command, 12);
if (result != USB_STOR_TRANSPORT_GOOD) { if (result) {
US_DEBUGP("Result for send_control in sddr09_read2%d %d\n", US_DEBUGP("Result for send_control in sddr09_read2%d %d\n",
x, result); x, result);
return result; return result;
...@@ -395,9 +390,9 @@ sddr09_readX(struct us_data *us, int x, unsigned long fromaddress, ...@@ -395,9 +390,9 @@ sddr09_readX(struct us_data *us, int x, unsigned long fromaddress,
if (result != USB_STOR_XFER_GOOD) { if (result != USB_STOR_XFER_GOOD) {
US_DEBUGP("Result for bulk_transfer in sddr09_read2%d %d\n", US_DEBUGP("Result for bulk_transfer in sddr09_read2%d %d\n",
x, result); x, result);
return USB_STOR_TRANSPORT_ERROR; return -EIO;
} }
return USB_STOR_TRANSPORT_GOOD; return 0;
} }
/* /*
...@@ -511,7 +506,7 @@ sddr09_erase(struct us_data *us, unsigned long Eaddress) { ...@@ -511,7 +506,7 @@ sddr09_erase(struct us_data *us, unsigned long Eaddress) {
result = sddr09_send_scsi_command(us, command, 12); result = sddr09_send_scsi_command(us, command, 12);
if (result != USB_STOR_TRANSPORT_GOOD) if (result)
US_DEBUGP("Result for send_control in sddr09_erase %d\n", US_DEBUGP("Result for send_control in sddr09_erase %d\n",
result); result);
...@@ -569,7 +564,7 @@ sddr09_writeX(struct us_data *us, ...@@ -569,7 +564,7 @@ sddr09_writeX(struct us_data *us,
result = sddr09_send_scsi_command(us, command, 12); result = sddr09_send_scsi_command(us, command, 12);
if (result != USB_STOR_TRANSPORT_GOOD) { if (result) {
US_DEBUGP("Result for send_control in sddr09_writeX %d\n", US_DEBUGP("Result for send_control in sddr09_writeX %d\n",
result); result);
return result; return result;
...@@ -581,9 +576,9 @@ sddr09_writeX(struct us_data *us, ...@@ -581,9 +576,9 @@ sddr09_writeX(struct us_data *us,
if (result != USB_STOR_XFER_GOOD) { if (result != USB_STOR_XFER_GOOD) {
US_DEBUGP("Result for bulk_transfer in sddr09_writeX %d\n", US_DEBUGP("Result for bulk_transfer in sddr09_writeX %d\n",
result); result);
return USB_STOR_TRANSPORT_ERROR; return -EIO;
} }
return USB_STOR_TRANSPORT_GOOD; return 0;
} }
/* erase address, write same address */ /* erase address, write same address */
...@@ -647,7 +642,7 @@ sddr09_read_sg_test_only(struct us_data *us) { ...@@ -647,7 +642,7 @@ sddr09_read_sg_test_only(struct us_data *us) {
result = sddr09_send_scsi_command(us, command, 4*nsg+3); result = sddr09_send_scsi_command(us, command, 4*nsg+3);
if (result != USB_STOR_TRANSPORT_GOOD) { if (result) {
US_DEBUGP("Result for send_control in sddr09_read_sg %d\n", US_DEBUGP("Result for send_control in sddr09_read_sg %d\n",
result); result);
return result; return result;
...@@ -655,7 +650,7 @@ sddr09_read_sg_test_only(struct us_data *us) { ...@@ -655,7 +650,7 @@ sddr09_read_sg_test_only(struct us_data *us) {
buf = (unsigned char *) kmalloc(bulklen, GFP_NOIO); buf = (unsigned char *) kmalloc(bulklen, GFP_NOIO);
if (!buf) if (!buf)
return USB_STOR_TRANSPORT_ERROR; return -ENOMEM;
result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
buf, bulklen, NULL); buf, bulklen, NULL);
...@@ -663,10 +658,10 @@ sddr09_read_sg_test_only(struct us_data *us) { ...@@ -663,10 +658,10 @@ sddr09_read_sg_test_only(struct us_data *us) {
if (result != USB_STOR_XFER_GOOD) { if (result != USB_STOR_XFER_GOOD) {
US_DEBUGP("Result for bulk_transfer in sddr09_read_sg %d\n", US_DEBUGP("Result for bulk_transfer in sddr09_read_sg %d\n",
result); result);
return USB_STOR_TRANSPORT_ERROR; return -EIO;
} }
return USB_STOR_TRANSPORT_GOOD; return 0;
} }
#endif #endif
...@@ -695,14 +690,13 @@ sddr09_read_status(struct us_data *us, unsigned char *status) { ...@@ -695,14 +690,13 @@ sddr09_read_status(struct us_data *us, unsigned char *status) {
command[1] = LUNBITS; command[1] = LUNBITS;
result = sddr09_send_scsi_command(us, command, 12); result = sddr09_send_scsi_command(us, command, 12);
if (result != USB_STOR_TRANSPORT_GOOD) if (result)
return result; return result;
result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
data, 64, NULL); data, 64, NULL);
*status = data[0]; *status = data[0];
return (result == USB_STOR_XFER_GOOD ? return (result == USB_STOR_XFER_GOOD ? 0 : -EIO);
USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_ERROR);
} }
static int static int
...@@ -725,7 +719,7 @@ sddr09_read_data(struct us_data *us, ...@@ -725,7 +719,7 @@ sddr09_read_data(struct us_data *us,
buffer = kmalloc(len, GFP_NOIO); buffer = kmalloc(len, GFP_NOIO);
if (buffer == NULL) { if (buffer == NULL) {
printk("sddr09_read_data: Out of memory\n"); printk("sddr09_read_data: Out of memory\n");
return USB_STOR_TRANSPORT_ERROR; return -ENOMEM;
} }
// Figure out the initial LBA and page // Figure out the initial LBA and page
...@@ -736,7 +730,7 @@ sddr09_read_data(struct us_data *us, ...@@ -736,7 +730,7 @@ sddr09_read_data(struct us_data *us,
// This could be made much more efficient by checking for // This could be made much more efficient by checking for
// contiguous LBA's. Another exercise left to the student. // contiguous LBA's. Another exercise left to the student.
result = USB_STOR_TRANSPORT_GOOD; result = 0;
index = offset = 0; index = offset = 0;
while (sectors > 0) { while (sectors > 0) {
...@@ -749,7 +743,7 @@ sddr09_read_data(struct us_data *us, ...@@ -749,7 +743,7 @@ sddr09_read_data(struct us_data *us,
if (lba >= maxlba) { if (lba >= maxlba) {
US_DEBUGP("Error: Requested lba %u exceeds " US_DEBUGP("Error: Requested lba %u exceeds "
"maximum %u\n", lba, maxlba); "maximum %u\n", lba, maxlba);
result = USB_STOR_TRANSPORT_ERROR; result = -EIO;
break; break;
} }
...@@ -763,7 +757,7 @@ sddr09_read_data(struct us_data *us, ...@@ -763,7 +757,7 @@ sddr09_read_data(struct us_data *us,
/* This is not really an error. It just means /* This is not really an error. It just means
that the block has never been written. that the block has never been written.
Instead of returning USB_STOR_TRANSPORT_ERROR Instead of returning an error
it is better to return all zero data. */ it is better to return all zero data. */
memset(buffer, 0, len); memset(buffer, 0, len);
...@@ -778,7 +772,7 @@ sddr09_read_data(struct us_data *us, ...@@ -778,7 +772,7 @@ sddr09_read_data(struct us_data *us,
result = sddr09_read20(us, address>>1, result = sddr09_read20(us, address>>1,
pages, info->pageshift, buffer, 0); pages, info->pageshift, buffer, 0);
if (result != USB_STOR_TRANSPORT_GOOD) if (result)
break; break;
} }
...@@ -844,7 +838,7 @@ sddr09_write_lba(struct us_data *us, unsigned int lba, ...@@ -844,7 +838,7 @@ sddr09_write_lba(struct us_data *us, unsigned int lba,
pba = sddr09_find_unused_pba(info, lba); pba = sddr09_find_unused_pba(info, lba);
if (!pba) { if (!pba) {
printk("sddr09_write_lba: Out of unused blocks\n"); printk("sddr09_write_lba: Out of unused blocks\n");
return USB_STOR_TRANSPORT_ERROR; return -ENOSPC;
} }
info->pba_to_lba[pba] = lba; info->pba_to_lba[pba] = lba;
info->lba_to_pba[lba] = pba; info->lba_to_pba[lba] = pba;
...@@ -855,7 +849,7 @@ sddr09_write_lba(struct us_data *us, unsigned int lba, ...@@ -855,7 +849,7 @@ sddr09_write_lba(struct us_data *us, unsigned int lba,
/* Maybe it is impossible to write to PBA 1. /* Maybe it is impossible to write to PBA 1.
Fake success, but don't do anything. */ Fake success, but don't do anything. */
printk("sddr09: avoid writing to pba 1\n"); printk("sddr09: avoid writing to pba 1\n");
return USB_STOR_TRANSPORT_GOOD; return 0;
} }
pagelen = (1 << info->pageshift) + (1 << CONTROL_SHIFT); pagelen = (1 << info->pageshift) + (1 << CONTROL_SHIFT);
...@@ -864,7 +858,7 @@ sddr09_write_lba(struct us_data *us, unsigned int lba, ...@@ -864,7 +858,7 @@ sddr09_write_lba(struct us_data *us, unsigned int lba,
address = (pba << (info->pageshift + info->blockshift)); address = (pba << (info->pageshift + info->blockshift));
result = sddr09_read22(us, address>>1, info->blocksize, result = sddr09_read22(us, address>>1, info->blocksize,
info->pageshift, blockbuffer, 0); info->pageshift, blockbuffer, 0);
if (result != USB_STOR_TRANSPORT_GOOD) if (result)
return result; return result;
/* check old contents and fill lba */ /* check old contents and fill lba */
...@@ -911,7 +905,7 @@ sddr09_write_lba(struct us_data *us, unsigned int lba, ...@@ -911,7 +905,7 @@ sddr09_write_lba(struct us_data *us, unsigned int lba,
{ {
unsigned char status = 0; unsigned char status = 0;
int result2 = sddr09_read_status(us, &status); int result2 = sddr09_read_status(us, &status);
if (result2 != USB_STOR_TRANSPORT_GOOD) if (result2)
US_DEBUGP("sddr09_write_inplace: cannot read status\n"); US_DEBUGP("sddr09_write_inplace: cannot read status\n");
else if (status != 0xc0) else if (status != 0xc0)
US_DEBUGP("sddr09_write_inplace: status after write: 0x%x\n", US_DEBUGP("sddr09_write_inplace: status after write: 0x%x\n",
...@@ -952,7 +946,7 @@ sddr09_write_data(struct us_data *us, ...@@ -952,7 +946,7 @@ sddr09_write_data(struct us_data *us,
blockbuffer = kmalloc(blocklen, GFP_NOIO); blockbuffer = kmalloc(blocklen, GFP_NOIO);
if (!blockbuffer) { if (!blockbuffer) {
printk("sddr09_write_data: Out of memory\n"); printk("sddr09_write_data: Out of memory\n");
return USB_STOR_TRANSPORT_ERROR; return -ENOMEM;
} }
// Since we don't write the user data directly to the device, // Since we don't write the user data directly to the device,
...@@ -964,14 +958,14 @@ sddr09_write_data(struct us_data *us, ...@@ -964,14 +958,14 @@ sddr09_write_data(struct us_data *us,
if (buffer == NULL) { if (buffer == NULL) {
printk("sddr09_write_data: Out of memory\n"); printk("sddr09_write_data: Out of memory\n");
kfree(blockbuffer); kfree(blockbuffer);
return USB_STOR_TRANSPORT_ERROR; return -ENOMEM;
} }
// Figure out the initial LBA and page // Figure out the initial LBA and page
lba = address >> info->blockshift; lba = address >> info->blockshift;
page = (address & info->blockmask); page = (address & info->blockmask);
result = USB_STOR_TRANSPORT_GOOD; result = 0;
index = offset = 0; index = offset = 0;
while (sectors > 0) { while (sectors > 0) {
...@@ -987,7 +981,7 @@ sddr09_write_data(struct us_data *us, ...@@ -987,7 +981,7 @@ sddr09_write_data(struct us_data *us,
result = sddr09_write_lba(us, lba, page, pages, result = sddr09_write_lba(us, lba, page, pages,
buffer, blockbuffer); buffer, blockbuffer);
if (result != USB_STOR_TRANSPORT_GOOD) if (result)
break; break;
page = 0; page = 0;
...@@ -1036,7 +1030,7 @@ sddr09_read_deviceID(struct us_data *us, unsigned char *deviceID) { ...@@ -1036,7 +1030,7 @@ sddr09_read_deviceID(struct us_data *us, unsigned char *deviceID) {
command[1] = LUNBITS; command[1] = LUNBITS;
result = sddr09_send_scsi_command(us, command, 12); result = sddr09_send_scsi_command(us, command, 12);
if (result != USB_STOR_TRANSPORT_GOOD) if (result)
return result; return result;
result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
...@@ -1045,8 +1039,7 @@ sddr09_read_deviceID(struct us_data *us, unsigned char *deviceID) { ...@@ -1045,8 +1039,7 @@ sddr09_read_deviceID(struct us_data *us, unsigned char *deviceID) {
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
deviceID[i] = content[i]; deviceID[i] = content[i];
return (result == USB_STOR_XFER_GOOD ? return (result == USB_STOR_XFER_GOOD ? 0 : -EIO);
USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_ERROR);
} }
static int static int
...@@ -1055,7 +1048,7 @@ sddr09_get_wp(struct us_data *us, struct sddr09_card_info *info) { ...@@ -1055,7 +1048,7 @@ sddr09_get_wp(struct us_data *us, struct sddr09_card_info *info) {
unsigned char status; unsigned char status;
result = sddr09_read_status(us, &status); result = sddr09_read_status(us, &status);
if (result != USB_STOR_TRANSPORT_GOOD) { if (result) {
US_DEBUGP("sddr09_get_wp: read_status fails\n"); US_DEBUGP("sddr09_get_wp: read_status fails\n");
return result; return result;
} }
...@@ -1071,7 +1064,7 @@ sddr09_get_wp(struct us_data *us, struct sddr09_card_info *info) { ...@@ -1071,7 +1064,7 @@ sddr09_get_wp(struct us_data *us, struct sddr09_card_info *info) {
if (status & 0x1) if (status & 0x1)
US_DEBUGP(" Error"); US_DEBUGP(" Error");
US_DEBUGP("\n"); US_DEBUGP("\n");
return USB_STOR_TRANSPORT_GOOD; return 0;
} }
#if 0 #if 0
...@@ -1103,7 +1096,7 @@ sddr09_get_cardinfo(struct us_data *us, unsigned char flags) { ...@@ -1103,7 +1096,7 @@ sddr09_get_cardinfo(struct us_data *us, unsigned char flags) {
result = sddr09_read_deviceID(us, deviceID); result = sddr09_read_deviceID(us, deviceID);
if (result != USB_STOR_TRANSPORT_GOOD) { if (result) {
US_DEBUGP("Result of read_deviceID is %d\n", result); US_DEBUGP("Result of read_deviceID is %d\n", result);
printk("sddr09: could not read card info\n"); printk("sddr09: could not read card info\n");
return NULL; return NULL;
...@@ -1214,7 +1207,7 @@ sddr09_read_map(struct us_data *us) { ...@@ -1214,7 +1207,7 @@ sddr09_read_map(struct us_data *us) {
us, address>>1, us, address>>1,
min(alloc_blocks, numblocks - i), min(alloc_blocks, numblocks - i),
buffer, 0); buffer, 0);
if (result != USB_STOR_TRANSPORT_GOOD) { if (result) {
result = -1; result = -1;
goto done; goto done;
} }
...@@ -1402,7 +1395,7 @@ usb_stor_sddr09_dpcm_init(struct us_data *us) { ...@@ -1402,7 +1395,7 @@ usb_stor_sddr09_dpcm_init(struct us_data *us) {
return result; return result;
result = sddr09_send_command(us, 0x01, USB_DIR_IN, data, 2); result = sddr09_send_command(us, 0x01, USB_DIR_IN, data, 2);
if (result != USB_STOR_TRANSPORT_GOOD) { if (result) {
US_DEBUGP("sddr09_init: send_command fails\n"); US_DEBUGP("sddr09_init: send_command fails\n");
return result; return result;
} }
...@@ -1411,7 +1404,7 @@ usb_stor_sddr09_dpcm_init(struct us_data *us) { ...@@ -1411,7 +1404,7 @@ usb_stor_sddr09_dpcm_init(struct us_data *us) {
// get 07 02 // get 07 02
result = sddr09_send_command(us, 0x08, USB_DIR_IN, data, 2); result = sddr09_send_command(us, 0x08, USB_DIR_IN, data, 2);
if (result != USB_STOR_TRANSPORT_GOOD) { if (result) {
US_DEBUGP("sddr09_init: 2nd send_command fails\n"); US_DEBUGP("sddr09_init: 2nd send_command fails\n");
return result; return result;
} }
...@@ -1420,7 +1413,7 @@ usb_stor_sddr09_dpcm_init(struct us_data *us) { ...@@ -1420,7 +1413,7 @@ usb_stor_sddr09_dpcm_init(struct us_data *us) {
// get 07 00 // get 07 00
result = sddr09_request_sense(us, data, 18); result = sddr09_request_sense(us, data, 18);
if (result == USB_STOR_TRANSPORT_GOOD && data[2] != 0) { if (result == 0 && data[2] != 0) {
int j; int j;
for (j=0; j<18; j++) for (j=0; j<18; j++)
printk(" %02X", data[j]); printk(" %02X", data[j]);
...@@ -1567,7 +1560,9 @@ int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us) ...@@ -1567,7 +1560,9 @@ int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
US_DEBUGP("READ_10: read page %d pagect %d\n", US_DEBUGP("READ_10: read page %d pagect %d\n",
page, pages); page, pages);
return sddr09_read_data(us, page, pages); result = sddr09_read_data(us, page, pages);
return (result == 0 ? USB_STOR_TRANSPORT_GOOD :
USB_STOR_TRANSPORT_ERROR);
} }
if (srb->cmnd[0] == WRITE_10) { if (srb->cmnd[0] == WRITE_10) {
...@@ -1580,7 +1575,9 @@ int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us) ...@@ -1580,7 +1575,9 @@ int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
US_DEBUGP("WRITE_10: write page %d pagect %d\n", US_DEBUGP("WRITE_10: write page %d pagect %d\n",
page, pages); page, pages);
return sddr09_write_data(us, page, pages); result = sddr09_write_data(us, page, pages);
return (result == 0 ? USB_STOR_TRANSPORT_GOOD :
USB_STOR_TRANSPORT_ERROR);
} }
/* catch-all for all other commands, except /* catch-all for all other commands, except
...@@ -1606,10 +1603,10 @@ int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us) ...@@ -1606,10 +1603,10 @@ int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
US_DEBUGP("SDDR09: Send control for command %s\n", ptr); US_DEBUGP("SDDR09: Send control for command %s\n", ptr);
result = sddr09_send_scsi_command(us, srb->cmnd, 12); result = sddr09_send_scsi_command(us, srb->cmnd, 12);
if (result != USB_STOR_TRANSPORT_GOOD) { if (result) {
US_DEBUGP("sddr09_transport: sddr09_send_scsi_command " US_DEBUGP("sddr09_transport: sddr09_send_scsi_command "
"returns %d\n", result); "returns %d\n", result);
return result; return USB_STOR_TRANSPORT_ERROR;
} }
if (srb->request_bufflen == 0) if (srb->request_bufflen == 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment