From: Matthew Wilcox <matthew@wil.cx>
To: linux-scsi@vger.kernel.org
Cc: Matthew Wilcox <matthew@wil.cx>, Matthew Wilcox <willy@linux.intel.com>
Subject: [PATCH 2/4] shuttle_usbat: Eliminate use of transfersize
Date: Thu, 18 Oct 2007 04:46:13 -0400 [thread overview]
Message-ID: <1192697175963-git-send-email-matthew@wil.cx> (raw)
In-Reply-To: <1192697175888-git-send-email-matthew@wil.cx>
It's more intuitive to go straight to the struct device for the
sector_size, when that's what we want, rather than using transfersize
as a replacement.
Also fix a bug in handling of GPCMD_READ_CD where we were pulling the
wrong bytes out of the packet to calculate the length. I checked this
against MMC5r04.
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
---
drivers/usb/storage/shuttle_usbat.c | 46 +++++++++++++++++++---------------
1 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index 570c125..a172e98 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -49,6 +49,7 @@
#include <scsi/scsi.h>
#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_device.h>
#include "usb.h"
#include "transport.h"
@@ -1164,12 +1165,10 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
unsigned char *buffer;
unsigned int len;
unsigned int sector;
+ unsigned int sector_size;
unsigned int sg_offset = 0;
struct scatterlist *sg = NULL;
- US_DEBUGP("handle_read10: transfersize %d\n",
- srb->transfersize);
-
if (scsi_bufflen(srb) < 0x10000) {
result = usbat_hp8200e_rw_block_test(us, USBAT_ATA,
@@ -1184,25 +1183,32 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
}
/*
- * Since we're requesting more data than we can handle in
- * a single read command (max is 64k-1), we will perform
- * multiple reads, but each read must be in multiples of
- * a sector. Luckily the sector size is in srb->transfersize
- * (see linux/drivers/scsi/sr.c).
+ * Since we're requesting more data than we can handle in a
+ * single read command (max is 64k-1), we will perform multiple
+ * reads, but each read must be in multiples of a sector.
+ *
+ * For ordinary READ_10 commands, we're reading at the current
+ * sector size, so use the device's sector size. If the command
+ * is a READ_CD, we might be reading different sector sizes.
+ * Fortunately, we can calculate the sector size from the
+ * contents of the command.
*/
if (data[7+0] == GPCMD_READ_CD) {
- len = short_pack(data[7+9], data[7+8]);
- len <<= 16;
- len |= data[7+7];
+ len = data[7+8] | ((u32)data[7+7] << 8) |
+ ((u32)data[7+6] << 16);
US_DEBUGP("handle_read10: GPCMD_READ_CD: len %d\n", len);
- srb->transfersize = scsi_bufflen(srb)/len;
+ sector_size = scsi_bufflen(srb) / len;
+ } else {
+ sector_size = srb->device->sector_size;
}
- if (!srb->transfersize) {
- srb->transfersize = 2048; /* A guess */
- US_DEBUGP("handle_read10: transfersize 0, forcing %d\n",
- srb->transfersize);
+ US_DEBUGP("handle_read10: sector_size %d\n", sector_size);
+
+ if (!sector_size) {
+ sector_size = 2048; /* A guess */
+ US_DEBUGP("handle_read10: sector_size 0, forcing %d\n",
+ sector_size);
}
/*
@@ -1211,7 +1217,7 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
* bounce buffer and the actual transfer buffer.
*/
- len = (65535/srb->transfersize) * srb->transfersize;
+ len = (65535/sector_size) * sector_size;
US_DEBUGP("Max read is %d bytes\n", len);
len = min(len, scsi_bufflen(srb));
buffer = kmalloc(len, GFP_NOIO);
@@ -1238,8 +1244,8 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
data[7+5] = LSB_of(sector&0xFFFF);
if (data[7+0] == GPCMD_READ_CD)
data[7+6] = 0;
- data[7+7] = MSB_of(len / srb->transfersize); /* SCSI command */
- data[7+8] = LSB_of(len / srb->transfersize); /* num sectors */
+ data[7+7] = MSB_of(len / sector_size); /* SCSI command */
+ data[7+8] = LSB_of(len / sector_size); /* num sectors */
result = usbat_hp8200e_rw_block_test(us, USBAT_ATA,
registers, data, 19,
@@ -1259,7 +1265,7 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
/* Update the amount transferred and the sector number */
transferred += len;
- sector += len / srb->transfersize;
+ sector += len / sector_size;
} /* while transferred != scsi_bufflen(srb) */
--
1.4.4.2
next prev parent reply other threads:[~2007-10-18 8:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-18 8:46 [PATCH 1/4] scsi_cmnd: Rearrange and shrink some elements Matthew Wilcox
2007-10-18 8:46 ` Matthew Wilcox [this message]
2007-10-18 8:46 ` [PATCH 3/4] qla1280,qla2xxx: Remove display of transfersize Matthew Wilcox
2007-10-18 8:46 ` [PATCH 4/4] Replace scmd->transfersize with scsi_transfer_size() Matthew Wilcox
2007-10-18 10:28 ` [PATCH 1/4] scsi_cmnd: Rearrange and shrink some elements Boaz Harrosh
-- strict thread matches above, loose matches on Subject: below --
2007-10-18 16:27 Matthew Wilcox
2007-10-18 16:27 ` [PATCH 2/4] shuttle_usbat: Eliminate use of transfersize Matthew Wilcox
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=1192697175963-git-send-email-matthew@wil.cx \
--to=matthew@wil.cx \
--cc=linux-scsi@vger.kernel.org \
--cc=willy@linux.intel.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.