[U-Boot] [PATCH v7 1/3] common: usb_storage: Make common function for usb_read_10/usb_write_10

Rajesh Bhagat rajesh.bhagat at nxp.com
Thu Jun 16 12:35:54 CEST 2016


Performs code cleanup by making common function for usb_read_10/
usb_write_10. Currently only difference in these fucntions is use
of SCSI_READ10/SCSI_WRITE10 scsi commands.

Signed-off-by: Rajesh Bhagat <rajesh.bhagat at nxp.com>
---
Changes in v7:
 - Makes common function for usb_read_10/usb_write_10

 common/usb_storage.c | 26 ++++----------------------
 1 file changed, 4 insertions(+), 22 deletions(-)

diff --git a/common/usb_storage.c b/common/usb_storage.c
index 7e6e52d..98798b5 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -1046,11 +1046,11 @@ static int usb_read_capacity(ccb *srb, struct us_data *ss)
 	return -1;
 }
 
-static int usb_read_10(ccb *srb, struct us_data *ss, unsigned long start,
-		       unsigned short blocks)
+static int usb_read_write_10(ccb *srb, struct us_data *ss, unsigned long start,
+		       unsigned short blocks, bool is_write)
 {
 	memset(&srb->cmd[0], 0, 12);
-	srb->cmd[0] = SCSI_READ10;
+	srb->cmd[0] = is_write ? SCSI_WRITE10 : SCSI_READ10;
 	srb->cmd[1] = srb->lun << 5;
 	srb->cmd[2] = ((unsigned char) (start >> 24)) & 0xff;
 	srb->cmd[3] = ((unsigned char) (start >> 16)) & 0xff;
@@ -1059,28 +1059,10 @@ static int usb_read_10(ccb *srb, struct us_data *ss, unsigned long start,
 	srb->cmd[7] = ((unsigned char) (blocks >> 8)) & 0xff;
 	srb->cmd[8] = (unsigned char) blocks & 0xff;
 	srb->cmdlen = 12;
-	debug("read10: start %lx blocks %x\n", start, blocks);
+	debug("%s: start %lx blocks %x\n", __func__, start, blocks);
 	return ss->transport(srb, ss);
 }
 
-static int usb_write_10(ccb *srb, struct us_data *ss, unsigned long start,
-			unsigned short blocks)
-{
-	memset(&srb->cmd[0], 0, 12);
-	srb->cmd[0] = SCSI_WRITE10;
-	srb->cmd[1] = srb->lun << 5;
-	srb->cmd[2] = ((unsigned char) (start >> 24)) & 0xff;
-	srb->cmd[3] = ((unsigned char) (start >> 16)) & 0xff;
-	srb->cmd[4] = ((unsigned char) (start >> 8)) & 0xff;
-	srb->cmd[5] = ((unsigned char) (start)) & 0xff;
-	srb->cmd[7] = ((unsigned char) (blocks >> 8)) & 0xff;
-	srb->cmd[8] = (unsigned char) blocks & 0xff;
-	srb->cmdlen = 12;
-	debug("write10: start %lx blocks %x\n", start, blocks);
-	return ss->transport(srb, ss);
-}
-
-
 #ifdef CONFIG_USB_BIN_FIXUP
 /*
  * Some USB storage devices queried for SCSI identification data respond with
-- 
2.6.2.198.g614a2ac



More information about the U-Boot mailing list