From: Santosh Y <santoshsy@gmail.com>
To: james.bottomley@hansenpartnership.com
Cc: linux-scsi@vger.kernel.org, yoshitake.kobayashi@toshiba.co.jp,
vinholikatti@gmail.com, Santosh Y <santoshsy@gmail.com>
Subject: [PATCH 2/2] [SCSI] ufs: calculate read/write xfer len from cdb
Date: Fri, 6 Apr 2012 17:57:21 +0530 [thread overview]
Message-ID: <1333715241-32346-2-git-send-email-santoshsy@gmail.com> (raw)
In-Reply-To: <1333715241-32346-1-git-send-email-santoshsy@gmail.com>
Currently the Expected data transfer length field in
command UPIU is being updated with "transfersize" from
the scsi_cmnd struct. But, if the read/write data
transfer size exceeds the sector size, the "transfersize"
will be truncated to the sector size. Thanks to KOBAYASHI
Yoshitake for pointing it out.
This patch ensures that the correct read/write data transfer
size is calculated from the "transfer length" available in the
CDB.
Reported-by: KOBAYASHI Yoshitake <yoshitake.kobayashi@toshiba.co.jp>
Reviewed-by: Vinayak Holikatti <vinholikatti@gmail.com>
Signed-off-by: Santosh Y <santoshsy@gmail.com>
---
drivers/scsi/ufs/ufshcd.c | 37 ++++++++++++++++++++++++++++++++++++-
1 files changed, 36 insertions(+), 1 deletions(-)
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 1878cd8..4f99ab4 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -585,6 +585,41 @@ static void ufshcd_int_config(struct ufs_hba *hba, u32 option)
}
/**
+ * ufshcd_get_transfer_len - calculate data transfer size for read/write
+ * commands from the CDB
+ * @cmdp: pointer to SCSI command
+ */
+static inline u32 ufshcd_get_transfer_len(struct scsi_cmnd *cmdp)
+{
+ u32 transfer_len;
+
+ switch (cmdp->cmnd[0]) {
+ case READ_6:
+ case WRITE_6:
+ transfer_len = cmdp->device->sector_size *
+ cmdp->cmnd[4];
+ break;
+ case READ_10:
+ case WRITE_10:
+ transfer_len = cmdp->device->sector_size *
+ ((cmdp->cmnd[7] << 8) |
+ cmdp->cmnd[8]);
+ break;
+ case READ_16:
+ case WRITE_16:
+ transfer_len = cmdp->device->sector_size *
+ ((cmdp->cmnd[10] << 24) |
+ (cmdp->cmnd[11] << 16) |
+ (cmdp->cmnd[12] << 8) |
+ cmdp->cmnd[13]);
+ break;
+ default:
+ transfer_len = cmdp->transfersize;
+ }
+ return transfer_len;
+}
+
+/**
* ufshcd_compose_upiu - form UFS Protocol Information Unit(UPIU)
* @lrb - pointer to local reference block
*/
@@ -640,7 +675,7 @@ static void ufshcd_compose_upiu(struct ufshcd_lrb *lrbp)
ucd_cmd_ptr->header.dword_2 = 0;
ucd_cmd_ptr->exp_data_transfer_len =
- cpu_to_be32(lrbp->cmd->transfersize);
+ cpu_to_be32(ufshcd_get_transfer_len(lrbp->cmd));
memcpy(ucd_cmd_ptr->cdb,
lrbp->cmd->cmnd,
--
1.7.5.4
next prev parent reply other threads:[~2012-04-06 12:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-06 12:27 [PATCH 1/2] [SCSI] ufs: update Response UPIU length in dword Santosh Y
2012-04-06 12:27 ` Santosh Y [this message]
2012-04-08 7:46 ` [PATCH 2/2] [SCSI] ufs: calculate read/write xfer len from cdb Namjae Jeon
2012-04-08 8:44 ` James Bottomley
2012-04-08 11:04 ` Santosh Y
2012-04-08 7:00 ` [PATCH 1/2] [SCSI] ufs: update Response UPIU length in dword Namjae Jeon
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=1333715241-32346-2-git-send-email-santoshsy@gmail.com \
--to=santoshsy@gmail.com \
--cc=james.bottomley@hansenpartnership.com \
--cc=linux-scsi@vger.kernel.org \
--cc=vinholikatti@gmail.com \
--cc=yoshitake.kobayashi@toshiba.co.jp \
/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;
as well as URLs for NNTP newsgroup(s).