[PATCH] scsi: clear UAC before sending SG_IO

2020-09-10 Thread Randall Huang
Make sure UAC is clear before sending SG_IO.

Signed-off-by: Randall Huang 
---
 drivers/scsi/sg.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 20472aaaf630..ad11bca47ae8 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -922,6 +922,7 @@ sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd 
*sfp,
int result, val, read_only;
Sg_request *srp;
unsigned long iflags;
+   int _cmd;
 
SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp,
   "sg_ioctl: cmd=0x%x\n", (int) cmd_in));
@@ -933,6 +934,13 @@ sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd 
*sfp,
return -ENODEV;
if (!scsi_block_when_processing_errors(sdp->device))
return -ENXIO;
+
+   _cmd = SCSI_UFS_REQUEST_SENSE;
+   if (sdp->device->host->wlun_clr_uac) {
+   sdp->device->host->hostt->ioctl(sdp->device, _cmd, 
NULL);
+   sdp->device->host->wlun_clr_uac = false;
+   }
+
result = sg_new_write(sfp, filp, p, SZ_SG_IO_HDR,
 1, read_only, 1, );
if (result < 0)


Re: [PATCH] scsi: associate bio write hint with WRITE CDB

2019-01-03 Thread Randall Huang
On Thu, Jan 03, 2019 at 11:57:38PM -0500, Martin K. Petersen wrote:
> 
> Ewan,
> 
> > SBC-5 says that support for the grouping function is indicated by the
> > GROUP_SUP bit in the Extended Inquiry VPD page (86h).  I'm not sure
> > how many devices actually support that page though.  Probably most
> > don't.
> 
> Several devices support it, albeit for various different purposes. It's
> one of these wonderful features whose interpretation was left outside
> the scope of the spec for a long time.
> 
> So even though we absolutely and positively need to make setting GROUP
> NUMBER conditional on GROUP_SUP being reported, we also need additional
> information from the storage about how the field should be interpreted.
> 
> The official way to report hinting is for the device to implement the IO
> Advice Hints Grouping mode page. I wrote some code to support that but
> no vendors that I know of ended up actually shipping an implementation.
> A few implemented my older I/O class proposal but didn't ship that
> either despite really convincing performance results.
> 
> If Randall has access to a device which implements hinting, I'd love to
> know more.
I am working on Android phone.
The idea is to enable write hint for Turbo write UFS feature.
Turbo write feature in UFS 3.x is under discussion in JEDEC JC-64. 
This patch is the under-lying framework for supporting this feature.
> 
> -- 
> Martin K. PetersenOracle Linux Engineering


[PATCH] scsi: associate bio write hint with WRITE CDB

2019-01-03 Thread Randall Huang
In SPC-3, WRITE(10)/(16) support grouping function.
Let's associate bio write hint with group number for
enabling StreamID or Turbo Write feature.

Change-Id: I565c8e0c1d10e17a23e73f2a02c1adbd198b04b3
Signed-off-by: Randall Huang 
---
 drivers/scsi/sd.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 4b49cb67617e..db48a849107e 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1201,7 +1201,11 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd 
*SCpnt)
SCpnt->cmnd[11] = (unsigned char) (this_count >> 16) & 0xff;
SCpnt->cmnd[12] = (unsigned char) (this_count >> 8) & 0xff;
SCpnt->cmnd[13] = (unsigned char) this_count & 0xff;
-   SCpnt->cmnd[14] = SCpnt->cmnd[15] = 0;
+   if (rq_data_dir(rq) == WRITE)
+   SCpnt->cmnd[14] = rq->bio->bi_write_hint & 0x3f;
+   else
+   SCpnt->cmnd[14] = 0;
+   SCpnt->cmnd[15] = 0;
} else if ((this_count > 0xff) || (block > 0x1f) ||
   scsi_device_protection(SCpnt->device) ||
   SCpnt->device->use_10_for_rw) {
@@ -1211,9 +1215,13 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd 
*SCpnt)
SCpnt->cmnd[3] = (unsigned char) (block >> 16) & 0xff;
SCpnt->cmnd[4] = (unsigned char) (block >> 8) & 0xff;
SCpnt->cmnd[5] = (unsigned char) block & 0xff;
-   SCpnt->cmnd[6] = SCpnt->cmnd[9] = 0;
+   if (rq_data_dir(rq) == WRITE)
+   SCpnt->cmnd[6] = rq->bio->bi_write_hint & 0x1f;
+   else
+   SCpnt->cmnd[6] = 0;
SCpnt->cmnd[7] = (unsigned char) (this_count >> 8) & 0xff;
SCpnt->cmnd[8] = (unsigned char) this_count & 0xff;
+   SCpnt->cmnd[9] = 0;
} else {
if (unlikely(rq->cmd_flags & REQ_FUA)) {
/*
-- 
2.20.1.415.g653613c723-goog



Re: [PATCH] scsi: associate bio write hint with WRITE CDB

2019-01-03 Thread Randall Huang
On Wed, Jan 02, 2019 at 11:51:33PM -0800, Christoph Hellwig wrote:
> On Wed, Dec 26, 2018 at 12:15:04PM +0800, Randall Huang wrote:
> > In SPC-3, WRITE(10)/(16) support grouping function.
> > Let's associate bio write hint with group number for
> > enabling StreamID or Turbo Write feature.
> > 
> > Signed-off-by: Randall Huang 
> > ---
> >  drivers/scsi/sd.c | 14 --
> >  1 file changed, 12 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> > index 4b49cb67617e..28bfa9ed2b54 100644
> > --- a/drivers/scsi/sd.c
> > +++ b/drivers/scsi/sd.c
> > @@ -1201,7 +1201,12 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd 
> > *SCpnt)
> > SCpnt->cmnd[11] = (unsigned char) (this_count >> 16) & 0xff;
> > SCpnt->cmnd[12] = (unsigned char) (this_count >> 8) & 0xff;
> > SCpnt->cmnd[13] = (unsigned char) this_count & 0xff;
> > -   SCpnt->cmnd[14] = SCpnt->cmnd[15] = 0;
> > +   if (rq_data_dir(rq) == WRITE) {
> > +   SCpnt->cmnd[14] = rq->bio->bi_write_hint & 0x3f;
> > +   } else {
> > +   SCpnt->cmnd[14] = 0;
> > +   }
> 
> No need for braces here.
Already send a new version
> 
> But what I'm more worried about is devices not recognizing the feature
> throwing up on the field.  Can you check what SBC version first
> references these or come up with some other decently smart conditional?
My reference is SCSI Block Commands – 3 (SBC-3) Revision 25.
Section 5.32 WRITE (10) and 5.34 WRITE (16)

> Maybe Martin has a good idea, too.


[PATCH] scsi: associate bio write hint with WRITE CDB

2019-01-03 Thread Randall Huang
In SPC-3, WRITE(10)/(16) support grouping function.
Let's associate bio write hint with group number for
enabling StreamID or Turbo Write feature.

Bug: 120900381
Change-Id: I565c8e0c1d10e17a23e73f2a02c1adbd198b04b3
Signed-off-by: Randall Huang 
---
 drivers/scsi/sd.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 4b49cb67617e..831c0c81ffb9 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1201,7 +1201,11 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd 
*SCpnt)
SCpnt->cmnd[11] = (unsigned char) (this_count >> 16) & 0xff;
SCpnt->cmnd[12] = (unsigned char) (this_count >> 8) & 0xff;
SCpnt->cmnd[13] = (unsigned char) this_count & 0xff;
-   SCpnt->cmnd[14] = SCpnt->cmnd[15] = 0;
+   if (rq_data_dir(rq) == WRITE) {
+   SCpnt->cmnd[14] = rq->bio->bi_write_hint & 0x3f;
+   } else
+   SCpnt->cmnd[14] = 0;
+   SCpnt->cmnd[15] = 0;
} else if ((this_count > 0xff) || (block > 0x1f) ||
   scsi_device_protection(SCpnt->device) ||
   SCpnt->device->use_10_for_rw) {
@@ -1211,9 +1215,13 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd 
*SCpnt)
SCpnt->cmnd[3] = (unsigned char) (block >> 16) & 0xff;
SCpnt->cmnd[4] = (unsigned char) (block >> 8) & 0xff;
SCpnt->cmnd[5] = (unsigned char) block & 0xff;
-   SCpnt->cmnd[6] = SCpnt->cmnd[9] = 0;
+   if (rq_data_dir(rq) == WRITE) {
+   SCpnt->cmnd[6] = rq->bio->bi_write_hint & 0x1f;
+   } else
+   SCpnt->cmnd[6] = 0;
SCpnt->cmnd[7] = (unsigned char) (this_count >> 8) & 0xff;
SCpnt->cmnd[8] = (unsigned char) this_count & 0xff;
+   SCpnt->cmnd[9] = 0;
} else {
if (unlikely(rq->cmd_flags & REQ_FUA)) {
/*
-- 
2.20.1.415.g653613c723-goog



[PATCH] scsi: associate bio write hint with WRITE CDB

2018-12-25 Thread Randall Huang
In SPC-3, WRITE(10)/(16) support grouping function.
Let's associate bio write hint with group number for
enabling StreamID or Turbo Write feature.

Signed-off-by: Randall Huang 
---
 drivers/scsi/sd.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 4b49cb67617e..28bfa9ed2b54 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1201,7 +1201,12 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd 
*SCpnt)
SCpnt->cmnd[11] = (unsigned char) (this_count >> 16) & 0xff;
SCpnt->cmnd[12] = (unsigned char) (this_count >> 8) & 0xff;
SCpnt->cmnd[13] = (unsigned char) this_count & 0xff;
-   SCpnt->cmnd[14] = SCpnt->cmnd[15] = 0;
+   if (rq_data_dir(rq) == WRITE) {
+   SCpnt->cmnd[14] = rq->bio->bi_write_hint & 0x3f;
+   } else {
+   SCpnt->cmnd[14] = 0;
+   }
+   SCpnt->cmnd[15] = 0;
} else if ((this_count > 0xff) || (block > 0x1f) ||
   scsi_device_protection(SCpnt->device) ||
   SCpnt->device->use_10_for_rw) {
@@ -1211,9 +1216,14 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd 
*SCpnt)
SCpnt->cmnd[3] = (unsigned char) (block >> 16) & 0xff;
SCpnt->cmnd[4] = (unsigned char) (block >> 8) & 0xff;
SCpnt->cmnd[5] = (unsigned char) block & 0xff;
-   SCpnt->cmnd[6] = SCpnt->cmnd[9] = 0;
+   if (rq_data_dir(rq) == WRITE) {
+   SCpnt->cmnd[6] = rq->bio->bi_write_hint & 0x1f;
+   } else {
+   SCpnt->cmnd[6] = 0;
+   }
SCpnt->cmnd[7] = (unsigned char) (this_count >> 8) & 0xff;
SCpnt->cmnd[8] = (unsigned char) this_count & 0xff;
+   SCpnt->cmnd[9] = 0;
} else {
if (unlikely(rq->cmd_flags & REQ_FUA)) {
/*
-- 
2.20.1.415.g653613c723-goog