summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2019-03-07 00:00:20 -0800
committerSascha Hauer <s.hauer@pengutronix.de>2019-03-11 08:11:18 +0100
commite8f61db3429d41bf6eb24d2c1720f281a9a87641 (patch)
treee2babb98f1efce9a3c4f944d16312ebe2748ad10 /drivers
parentaa12d1e5be6ee7fb2411d7318567941e403186be (diff)
downloadbarebox-e8f61db3429d41bf6eb24d2c1720f281a9a87641.tar.gz
usb: storage: Share code for READ(10) and WRITE(10)
Both usb_stor_read_10() and usb_stor_write_10() do almost exactly the same thing, so merge them into a signle routine and adjust all of the users accordingly. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/storage/usb.c60
1 files changed, 9 insertions, 51 deletions
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index d601e9c..e63cc40 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -160,12 +160,11 @@ static int usb_stor_read_capacity(struct us_blk_dev *usb_blkdev,
return result ? -EIO : 0;
}
-static int usb_stor_read_10(struct us_blk_dev *usb_blkdev,
- unsigned long start, u8 *data,
- unsigned short blocks)
+static int usb_stor_io_10(struct us_blk_dev *usb_blkdev, u8 cmd,
+ unsigned long start, u8 *data,
+ unsigned short blocks)
{
struct us_data *us = usb_blkdev->us;
- struct device_d *dev = &us->pusb_dev->dev;
int retries, result;
ccb srb;
@@ -175,10 +174,9 @@ static int usb_stor_read_10(struct us_blk_dev *usb_blkdev,
retries = 2;
do {
- dev_dbg(dev, "SCSI_READ10: start %lx blocks %x\n", start, blocks);
memset(&srb.cmd[0], 0, 10);
srb.cmdlen = 10;
- srb.cmd[0] = SCSI_READ10;
+ srb.cmd[0] = cmd;
srb.cmd[2] = (u8)(start >> 24);
srb.cmd[3] = (u8)(start >> 16);
srb.cmd[4] = (u8)(start >> 8);
@@ -186,7 +184,6 @@ static int usb_stor_read_10(struct us_blk_dev *usb_blkdev,
srb.cmd[7] = (u8)(blocks >> 8);
srb.cmd[8] = (u8)(blocks >> 0);
result = us->transport(&srb, us);
- dev_dbg(dev, "SCSI_READ10 returns %d\n", result);
if (result == USB_STOR_TRANSPORT_GOOD)
return 0;
usb_stor_request_sense(&srb, us);
@@ -195,42 +192,6 @@ static int usb_stor_read_10(struct us_blk_dev *usb_blkdev,
return -EIO;
}
-static int usb_stor_write_10(struct us_blk_dev *usb_blkdev,
- unsigned long start, u8 *data,
- unsigned short blocks)
-{
- struct us_data *us = usb_blkdev->us;
- struct device_d *dev = &us->pusb_dev->dev;
- int retries, result;
- ccb srb;
-
- srb.lun = usb_blkdev->lun;
- srb.pdata = data;
- srb.datalen = blocks * SECTOR_SIZE;
-
- retries = 2;
- do {
- dev_dbg(dev, "SCSI_WRITE10: start %lx blocks %x\n", start, blocks);
- memset(&srb.cmd[0], 0, 10);
- srb.cmdlen = 10;
- srb.cmd[0] = SCSI_WRITE10;
- srb.cmd[2] = (u8)(start >> 24);
- srb.cmd[3] = (u8)(start >> 16);
- srb.cmd[4] = (u8)(start >> 8);
- srb.cmd[5] = (u8)(start >> 0);
- srb.cmd[7] = (u8)(blocks >> 8);
- srb.cmd[8] = (u8)(blocks >> 0);
- result = us->transport(&srb, us);
- dev_dbg(dev, "SCSI_WRITE10 returns %d\n", result);
- if (result == USB_STOR_TRANSPORT_GOOD)
- return 0;
- usb_stor_request_sense(&srb, us);
- } while (retries--);
-
- return -EIO;
-}
-
-
/***********************************************************************
* Disk driver interface
***********************************************************************/
@@ -299,14 +260,11 @@ static int usb_stor_blk_io(int io_op, struct block_device *disk_dev,
unsigned n = min(sector_count, US_MAX_IO_BLK);
u8 *data = buffer + (sectors_done * SECTOR_SIZE);
- if (io_op == io_rd)
- result = usb_stor_read_10(pblk_dev,
- (ulong)sector_start,
- data, n);
- else
- result = usb_stor_write_10(pblk_dev,
- (ulong)sector_start,
- data, n);
+ result = usb_stor_io_10(pblk_dev,
+ (io_op == io_rd) ?
+ SCSI_READ10 : SCSI_WRITE10,
+ (ulong)sector_start,
+ data, n);
if (result != 0) {
dev_dbg(dev, "I/O error at sector %d\n", sector_start);
break;