[U-Boot] [PATCH 2/2] common: usb_storage : Seperate optimal blocks logic calculation for read/write

Rajesh Bhagat rajesh.bhagat at nxp.com
Mon May 30 13:23:55 CEST 2016


Seperates optimal blocks logic calculation for read/write by defining
the usb_max_xfer_blk variable for usb_stor_read and usb_stor_write.

It has been observed, that USB devices are tend to be slower in write as
compared to read operation. Hence, should be handled in diffrent manner.

Signed-off-by: Sriram Dash <sriram.dash at nxp.com>
Signed-off-by: Rajesh Bhagat <rajesh.bhagat at nxp.com>
---
 common/usb_storage.c |   45 +++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/common/usb_storage.c b/common/usb_storage.c
index 7b5ad07..fb3c58a 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -108,7 +108,7 @@ static unsigned short usb_xfer_blk_tbl[5] = {4096, 8192, 16384, 32768, 65535};
 static unsigned short usb_xfer_blk_tbl[1] = {20};
 #endif
 
-static unsigned short USB_MAX_XFER_BLK;
+static unsigned short usb_read_xfer_blk, usb_write_xfer_blk;
 
 #ifndef CONFIG_BLK
 static struct us_data usb_stor[USB_MAX_STOR_DEV];
@@ -1116,7 +1116,7 @@ static unsigned long usb_stor_read(struct blk_desc *block_dev, lbaint_t blknr,
 	unsigned short smallblks;
 	struct usb_device *udev;
 	struct us_data *ss;
-	int retry, next = LOG2((USB_MAX_XFER_BLK + 1) / usb_xfer_blk_tbl[0]);
+	int retry, next = LOG2((usb_read_xfer_blk + 1) / usb_xfer_blk_tbl[0]);
 	bool retry_flag = false;
 	ccb *srb = &usb_ccb;
 #ifdef CONFIG_BLK
@@ -1153,14 +1153,14 @@ static unsigned long usb_stor_read(struct blk_desc *block_dev, lbaint_t blknr,
 		/* XXX need some comment here */
 		retry = 2;
 		srb->pdata = (unsigned char *)buf_addr;
-		if (blks > USB_MAX_XFER_BLK)
-			smallblks = USB_MAX_XFER_BLK;
+		if (blks > usb_read_xfer_blk)
+			smallblks = usb_read_xfer_blk;
 		else
 			smallblks = (unsigned short) blks;
 retry_it:
 		debug("usb_read: retry #%d, xfer_blk %hu, smallblks %hu\n",
-		      retry, USB_MAX_XFER_BLK, smallblks);
-		if (smallblks == USB_MAX_XFER_BLK)
+		      retry, usb_read_xfer_blk, smallblks);
+		if (smallblks == usb_read_xfer_blk)
 			usb_show_progress();
 		srb->datalen = block_dev->blksz * smallblks;
 		srb->pdata = (unsigned char *)buf_addr;
@@ -1168,10 +1168,10 @@ retry_it:
 			debug("Read ERROR\n");
 			usb_request_sense(srb, ss);
 			if (retry--) {
-				/* decrease the USB_MAX_XFER_BLK */
+				/* decrease the usb_read_xfer_blk */
 				if (next >  0) {
 					smallblks = usb_xfer_blk_tbl[--next];
-					USB_MAX_XFER_BLK = smallblks;
+					usb_read_xfer_blk = smallblks;
 				}
 				retry_flag = true;
 				goto retry_it;
@@ -1183,10 +1183,10 @@ retry_it:
 		blks -= smallblks;
 		buf_addr += srb->datalen;
 
-		/* try to increase the USB_MAX_XFER_BLK */
+		/* try to increase the usb_read_xfer_blk */
 		if (next < USB_XFER_BLK_TBL_SZ  - 1)
 			if (!retry_flag && usb_xfer_blk_tbl[next + 1] <= blks)
-				USB_MAX_XFER_BLK = usb_xfer_blk_tbl[++next];
+				usb_read_xfer_blk = usb_xfer_blk_tbl[++next];
 	} while (blks != 0);
 	ss->flags &= ~USB_READY;
 
@@ -1195,7 +1195,7 @@ retry_it:
 	      start, smallblks, buf_addr);
 
 	usb_disable_asynch(0); /* asynch transfer allowed */
-	if (blkcnt >= USB_MAX_XFER_BLK)
+	if (blkcnt >= usb_read_xfer_blk)
 		debug("\n");
 	return blkcnt;
 }
@@ -1213,7 +1213,7 @@ static unsigned long usb_stor_write(struct blk_desc *block_dev, lbaint_t blknr,
 	unsigned short smallblks;
 	struct usb_device *udev;
 	struct us_data *ss;
-	int retry, next = LOG2((USB_MAX_XFER_BLK + 1) / usb_xfer_blk_tbl[0]);
+	int retry, next = LOG2((usb_write_xfer_blk + 1) / usb_xfer_blk_tbl[0]);
 	bool retry_flag = false;
 	ccb *srb = &usb_ccb;
 #ifdef CONFIG_BLK
@@ -1254,14 +1254,14 @@ static unsigned long usb_stor_write(struct blk_desc *block_dev, lbaint_t blknr,
 		 */
 		retry = 2;
 		srb->pdata = (unsigned char *)buf_addr;
-		if (blks > USB_MAX_XFER_BLK)
-			smallblks = USB_MAX_XFER_BLK;
+		if (blks > usb_write_xfer_blk)
+			smallblks = usb_write_xfer_blk;
 		else
 			smallblks = (unsigned short) blks;
 retry_it:
 		debug("usb_write: retry #%d, xfer_blk %hu, smallblks %hu\n",
-		      retry, USB_MAX_XFER_BLK, smallblks);
-		if (smallblks == USB_MAX_XFER_BLK)
+		      retry, usb_write_xfer_blk, smallblks);
+		if (smallblks == usb_write_xfer_blk)
 			usb_show_progress();
 		srb->datalen = block_dev->blksz * smallblks;
 		srb->pdata = (unsigned char *)buf_addr;
@@ -1269,10 +1269,10 @@ retry_it:
 			debug("Write ERROR\n");
 			usb_request_sense(srb, ss);
 			if (retry--) {
-				/* decrease the USB_MAX_XFER_BLK */
+				/* decrease the usb_write_xfer_blk */
 				if (next >  0) {
 					smallblks = usb_xfer_blk_tbl[--next];
-					USB_MAX_XFER_BLK = smallblks;
+					usb_write_xfer_blk = smallblks;
 				}
 				retry_flag = true;
 				goto retry_it;
@@ -1284,10 +1284,10 @@ retry_it:
 		blks -= smallblks;
 		buf_addr += srb->datalen;
 
-		/* try to increase the USB_MAX_XFER_BLK */
+		/* try to increase the usb_write_xfer_blk */
 		if (next < USB_XFER_BLK_TBL_SZ  - 1)
 			if (!retry_flag && usb_xfer_blk_tbl[next + 1] <= blks)
-				USB_MAX_XFER_BLK = usb_xfer_blk_tbl[++next];
+				usb_write_xfer_blk = usb_xfer_blk_tbl[++next];
 	} while (blks != 0);
 	ss->flags &= ~USB_READY;
 
@@ -1295,7 +1295,7 @@ retry_it:
 	      PRIxPTR "\n", start, smallblks, buf_addr);
 
 	usb_disable_asynch(0); /* asynch transfer allowed */
-	if (blkcnt >= USB_MAX_XFER_BLK)
+	if (blkcnt >= usb_write_xfer_blk)
 		debug("\n");
 	return blkcnt;
 
@@ -1361,7 +1361,8 @@ int usb_storage_probe(struct usb_device *dev, unsigned int ifnum,
 	}
 
 	/* Initialize the current transfer blocks to minimum value */
-	USB_MAX_XFER_BLK = usb_xfer_blk_tbl[0];
+	usb_read_xfer_blk = usb_xfer_blk_tbl[0];
+	usb_write_xfer_blk = usb_xfer_blk_tbl[0];
 
 	/*
 	 * We are expecting a minimum of 2 endpoints - in and out (bulk).
-- 
1.7.9.5



More information about the U-Boot mailing list