mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 05/26] usb: storage: Make usb_stor_inquiry() a standalone function
Date: Thu,  7 Mar 2019 00:00:15 -0800	[thread overview]
Message-ID: <20190307080036.28028-6-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20190307080036.28028-1-andrew.smirnov@gmail.com>

Move special preparation steps done before and after call to
usb_stor_inquiry() inside the function itself for clarity and to allow
futher code improvements. No functional change intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/usb/storage/usb.c | 52 ++++++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index f439cd825..05a3a03c4 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -37,30 +37,43 @@ static LIST_HEAD(us_blkdev_list);
  * USB Storage routines
  ***********************************************************************/
 
-static int usb_stor_inquiry(ccb *srb, struct us_data *us)
+static int usb_stor_inquiry(struct us_blk_dev *usb_blkdev)
 {
+	struct us_data *us = usb_blkdev->us;
 	struct device_d *dev = &us->pusb_dev->dev;
 	int retries, result;
+	ccb srb;
+	u8 *data = xzalloc(36);
 
-	srb->datalen = min(128UL, srb->datalen);
-	if (srb->datalen < 5) {
-		dev_dbg(dev, "SCSI_INQUIRY: invalid data buffer size\n");
-		return -EINVAL;
-	}
+	srb.lun = usb_blkdev->lun;
+	srb.pdata = data;
+	srb.datalen = 36;
 
 	retries = 3;
 	do {
 		dev_dbg(dev, "SCSI_INQUIRY\n");
-		memset(&srb->cmd[0], 0, 6);
-		srb->cmdlen = 6;
-		srb->cmd[0] = SCSI_INQUIRY;
-		srb->cmd[3] = (u8)(srb->datalen >> 8);
-		srb->cmd[4] = (u8)(srb->datalen >> 0);
-		result = us->transport(srb, us);
+		memset(&srb.cmd[0], 0, 6);
+		srb.cmdlen = 6;
+		srb.cmd[0] = SCSI_INQUIRY;
+		srb.cmd[3] = (u8)(srb.datalen >> 8);
+		srb.cmd[4] = (u8)(srb.datalen >> 0);
+		result = us->transport(&srb, us);
 		dev_dbg(dev, "SCSI_INQUIRY returns %d\n", result);
-	} while ((result != USB_STOR_TRANSPORT_GOOD) && retries--);
+		if (result == USB_STOR_TRANSPORT_GOOD) {
+			dev_dbg(dev, "Peripheral type: %x, removable: %x\n",
+				data[0], (data[1] >> 7));
+			dev_dbg(dev, "ISO ver: %x, resp format: %x\n",
+				data[2], data[3]);
+			dev_dbg(dev, "Vendor/product/rev: %28s\n",
+				&data[8]);
+			// TODO:  process and store device info
+			break;
+		}
+	} while (retries--);
 
-	return (result != USB_STOR_TRANSPORT_GOOD) ? -EIO : 0;
+	free(data);
+
+	return result ? -ENODEV : 0;
 }
 
 static int usb_stor_request_sense(ccb *srb, struct us_data *us)
@@ -344,17 +357,12 @@ static int usb_stor_init_blkdev(struct us_blk_dev *pblk_dev)
 
 	/* get device info */
 	dev_dbg(dev, "Reading device info\n");
-	us_ccb.datalen = 36;
-	if (usb_stor_inquiry(&us_ccb, us)) {
+
+	result = usb_stor_inquiry(pblk_dev);
+	if (result) {
 		dev_dbg(dev, "Cannot read device info\n");
-		result = -ENODEV;
 		goto Exit;
 	}
-	dev_dbg(dev, "Peripheral type: %x, removable: %x\n",
-	          us_io_buf[0], (us_io_buf[1] >> 7));
-	dev_dbg(dev, "ISO ver: %x, resp format: %x\n", us_io_buf[2], us_io_buf[3]);
-	dev_dbg(dev, "Vendor/product/rev: %28s\n", &us_io_buf[8]);
-	// TODO:  process and store device info
 
 	/* ensure unit ready */
 	dev_dbg(dev, "Testing for unit ready\n");
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2019-03-07  8:00 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-07  8:00 [PATCH 00/26] USB storage improvements Andrey Smirnov
2019-03-07  8:00 ` [PATCH 01/26] usb: storage: Simplify memory allocation in usb_stor_probe() Andrey Smirnov
2019-03-07  8:00 ` [PATCH 02/26] usb: storage: Replace custom debug tracing with dev_dbg Andrey Smirnov
2019-03-07  8:00 ` [PATCH 03/26] usb: storage: Don't use "unsigned long" for 32-bit values Andrey Smirnov
2019-03-07  8:00 ` [PATCH 04/26] usb: storage: Make usb_stor_read_capacity() a standalone function Andrey Smirnov
2019-03-07  8:00 ` Andrey Smirnov [this message]
2019-03-07  8:00 ` [PATCH 06/26] usb: storage: Make usb_stor_test_unit_ready() " Andrey Smirnov
2019-03-07  8:00 ` [PATCH 07/26] usb: storage: Make usb_stor_read_10() " Andrey Smirnov
2019-03-07  8:00 ` [PATCH 08/26] usb: storage: Make usb_stor_write_10() " Andrey Smirnov
2019-03-07  8:00 ` [PATCH 09/26] usb: storage: Drop extra call to transport in usb_stor_write_10() Andrey Smirnov
2019-03-07  8:00 ` [PATCH 10/26] usb: storage: Share code for READ(10) and WRITE(10) Andrey Smirnov
2019-03-07  8:00 ` [PATCH 11/26] usb: storage: Make usb_stor_request_sense() a standalone function Andrey Smirnov
2019-03-07  8:00 ` [PATCH 12/26] usb: storage: Remove unused variables Andrey Smirnov
2019-03-07  8:00 ` [PATCH 13/26] usb: storage: Drop struct SCSI_cmd_block Andrey Smirnov
2019-03-07  8:00 ` [PATCH 14/26] usb: hub: Do not include <scsi.h> Andrey Smirnov
2019-03-07  8:00 ` [PATCH 15/26] ata: ahci: " Andrey Smirnov
2019-03-07  8:00 ` [PATCH 16/26] usb: storage: Drop unused fields in struct us_data Andrey Smirnov
2019-03-07  8:00 ` [PATCH 17/26] usb: storage: Drop unused us_blkdev_list Andrey Smirnov
2019-03-07  8:00 ` [PATCH 18/26] usb: storage: Introduce usb_stor_transport() Andrey Smirnov
2019-03-07  8:00 ` [PATCH 19/26] usb: storage: Use put_unaligned_be* helpers Andrey Smirnov
2019-03-07  8:00 ` [PATCH 20/26] usb: Drop usb_disable_asynch() Andrey Smirnov
2019-03-07  8:00 ` [PATCH 21/26] usb: storage: Drop unnecessary check in usb_stor_blk_io() Andrey Smirnov
2019-03-07  8:00 ` [PATCH 22/26] usb: storage: Drop needless macro Andrey Smirnov
2019-03-07  8:00 ` [PATCH 23/26] usb: storage: Use simple boolean to speficy read vs. write operation Andrey Smirnov
2019-03-07  8:00 ` [PATCH 24/26] usb: storage: Simplify I/O loop in usb_stor_blk_io() Andrey Smirnov
2019-03-07  8:00 ` [PATCH 25/26] usb: storage: Drop unnecessary assignment Andrey Smirnov
2019-03-07  8:00 ` [PATCH 26/26] usb: storage: Inline usb_limit_blk_cnt() Andrey Smirnov
2019-03-11  7:11 ` [PATCH 00/26] USB storage improvements Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190307080036.28028-6-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox