Re: [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug

2016-05-02 Thread Andrew Morton
On Tue, 03 May 2016 01:10:16 +0200 Arnd Bergmann  wrote:

> On Monday 02 May 2016 16:02:18 Andrew Morton wrote:
> > On Mon, 02 May 2016 23:48:19 +0200 Arnd Bergmann  wrote:
> > 
> > > This is another attempt to avoid a regression in wwn_to_u64() after
> > > that started using get_unaligned_be64(), which in turn ran into a
> > > bug on gcc-4.9 through 6.1.
> > 
> > I'm still getting a couple screenfuls of things like
> > 
> > net/tipc/name_distr.c: In function 'tipc_named_process_backlog':
> > net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned 
> > int', but argument 3 has type 'unsigned int'
> > net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned 
> > int', but argument 4 has type 'unsigned int'
> > net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned 
> > int', but argument 5 has type 'unsigned int'
> > net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned 
> > int', but argument 7 has type 'unsigned int'
> 
> I've built a few thousand kernels (arm32 with gcc-6.1) with the patch applied,
> but didn't see this one. What target architecture and compiler version 
> produced
> this? Does it go away if you add a (__u32) cast? I don't even know what the
> warning is trying to tell me.

heh, I didn't actually read it.

Hopefully we can write this off as a gcc-4.4.4 glitch. 4.8.4 is OK.
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug

2016-05-02 Thread Arnd Bergmann
On Monday 02 May 2016 16:02:18 Andrew Morton wrote:
> On Mon, 02 May 2016 23:48:19 +0200 Arnd Bergmann  wrote:
> 
> > This is another attempt to avoid a regression in wwn_to_u64() after
> > that started using get_unaligned_be64(), which in turn ran into a
> > bug on gcc-4.9 through 6.1.
> 
> I'm still getting a couple screenfuls of things like
> 
> net/tipc/name_distr.c: In function 'tipc_named_process_backlog':
> net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', 
> but argument 3 has type 'unsigned int'
> net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', 
> but argument 4 has type 'unsigned int'
> net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', 
> but argument 5 has type 'unsigned int'
> net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', 
> but argument 7 has type 'unsigned int'

I've built a few thousand kernels (arm32 with gcc-6.1) with the patch applied,
but didn't see this one. What target architecture and compiler version produced
this? Does it go away if you add a (__u32) cast? I don't even know what the
warning is trying to tell me.

Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug

2016-05-02 Thread Andrew Morton
On Mon, 02 May 2016 23:48:19 +0200 Arnd Bergmann  wrote:

> This is another attempt to avoid a regression in wwn_to_u64() after
> that started using get_unaligned_be64(), which in turn ran into a
> bug on gcc-4.9 through 6.1.

I'm still getting a couple screenfuls of things like

net/tipc/name_distr.c: In function 'tipc_named_process_backlog':
net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', 
but argument 3 has type 'unsigned int'
net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', 
but argument 4 has type 'unsigned int'
net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', 
but argument 5 has type 'unsigned int'
net/tipc/name_distr.c:330: warning: format '%u' expects type 'unsigned int', 
but argument 7 has type 'unsigned int'

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [dm-devel] [Lsf] Notes from the four separate IO track sessions at LSF/MM

2016-05-02 Thread Bart Van Assche

On 05/02/2016 12:28 PM, Laurence Oberman wrote:

Even in the case of the ib_srp, don't we also have to still run the
eh_timeout for each of the devices that has inflight requiring error
handling serially. This means we will still have to wait to get a
path failover until all are through the timeout.


Hello Laurence,

It depends. If a transport layer error (e.g. a cable pull) has been 
observed by the ib_srp driver then fast_io_fail_tmo seconds later the 
ib_srp driver will terminate all outstanding SCSI commands without 
waiting for the error handler to finish. If no transport layer error has 
been observed then at most (SCSI timeout) + (number of pending commands 
+ 1) * 5 seconds later srp_reset_device() will have finished terminating 
all pending SCSI commands.


Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug

2016-05-02 Thread Arnd Bergmann
This is another attempt to avoid a regression in wwn_to_u64() after
that started using get_unaligned_be64(), which in turn ran into a
bug on gcc-4.9 through 6.1.

The regression got introduced due to the combination of two
separate workarounds (e3bde9568d99 and ef3fb2422ffe) that each
try to sidestep distinct problems with gcc behavior (code growth
and increased stack usage). Unfortunately after both have been
applied, a more series gcc bug has been uncovered, leading to
incorrect object code that discards part of a function and
causes undefined behavior.

As part of this problem is how __builtin_constant_p gets evaluated
on an argument passed by reference into an inline function, this
avoids the use of __builtin_constant_p() for all architectures
that set CONFIG_ARCH_USE_BUILTIN_BSWAP. Most architectures do not
set ARCH_SUPPORTS_OPTIMIZED_INLINING, which means they probably
do not suffer from the problem in the qla2xxx driver, but they
might still run into it elsewhere.

Both of the original workarounds were only merged in the 4.6 kernel,
and the bug that is fixed by this patch should only appear if
both are there, so we probably don't need to backport the fix.
On the other hand, it works by simplifying the code path and
should not have any negative effects.

Link: https://lkml.org/lkml/headers/2016/4/12/1103
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70232
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70646
Fixes: e3bde9568d99 ("include/linux/unaligned: force inlining of byteswap 
operations")
Fixes: ef3fb2422ffe ("scsi: fc: use get/put_unaligned64 for wwn access")
Tested-by: Josh Poimboeuf  # on gcc-5.3
Tested-by: Quinn Tran 
Reviewed-by: Josh Poimboeuf 
Signed-off-by: Arnd Bergmann 

This contains the extra cast to fix up 64-bit builds, and has
an expanded changelog, compared to the original version.

diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
index 3f10e5317b46..de56fd54428d 100644
--- a/include/uapi/linux/swab.h
+++ b/include/uapi/linux/swab.h
@@ -45,9 +45,7 @@
 
 static inline __attribute_const__ __u16 __fswab16(__u16 val)
 {
-#ifdef __HAVE_BUILTIN_BSWAP16__
-   return __builtin_bswap16(val);
-#elif defined (__arch_swab16)
+#if defined (__arch_swab16)
return __arch_swab16(val);
 #else
return ___constant_swab16(val);
@@ -56,9 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
 
 static inline __attribute_const__ __u32 __fswab32(__u32 val)
 {
-#ifdef __HAVE_BUILTIN_BSWAP32__
-   return __builtin_bswap32(val);
-#elif defined(__arch_swab32)
+#if defined(__arch_swab32)
return __arch_swab32(val);
 #else
return ___constant_swab32(val);
@@ -67,9 +63,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
 
 static inline __attribute_const__ __u64 __fswab64(__u64 val)
 {
-#ifdef __HAVE_BUILTIN_BSWAP64__
-   return __builtin_bswap64(val);
-#elif defined (__arch_swab64)
+#if defined (__arch_swab64)
return __arch_swab64(val);
 #elif defined(__SWAB_64_THRU_32__)
__u32 h = val >> 32;
@@ -102,28 +96,40 @@ static inline __attribute_const__ __u32 __fswahb32(__u32 
val)
  * __swab16 - return a byteswapped 16-bit value
  * @x: value to byteswap
  */
+#ifdef __HAVE_BUILTIN_BSWAP16__
+#define __swab16(x) __builtin_bswap16((__u16)(x))
+#else
 #define __swab16(x)\
(__builtin_constant_p((__u16)(x)) ? \
___constant_swab16(x) : \
__fswab16(x))
+#endif
 
 /**

  * __swab32 - return a byteswapped 32-bit value
  * @x: value to byteswap
  */
+#ifdef __HAVE_BUILTIN_BSWAP32__
+#define __swab32(x) __builtin_bswap32((__u32)(x))
+#else
 #define __swab32(x)\
(__builtin_constant_p((__u32)(x)) ? \
___constant_swab32(x) : \
__fswab32(x))
+#endif
 
 /**
  * __swab64 - return a byteswapped 64-bit value
  * @x: value to byteswap
  */
+#ifdef __HAVE_BUILTIN_BSWAP64__
+#define __swab64(x) (__u64)__builtin_bswap64((__u64)(x))
+#else
 #define __swab64(x)\
(__builtin_constant_p((__u64)(x)) ? \
___constant_swab64(x) : \
__fswab64(x))
+#endif
 
 /**
  * __swahw32 - return a word-swapped 32-bit value

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/3] libata-scsi: Set CmdQue=1 when NCQ is enabled

2016-05-02 Thread tom . ty89
From: Tom Yan 

https://bugzilla.kernel.org/show_bug.cgi?id=105931

This might look trivial at first sight. However, it can be
important to have the bit set accordingly when the device/SATL is
SCSI-passthrough'd to a virtual machine with scsi-block in qemu:

https://github.com/YanVugenfirer/kvm-guest-drivers-windows/issues/63#issuecomment-216199929
Signed-off-by: Tom Yan 

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 567859c..cd30f11 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -2007,7 +2007,10 @@ static unsigned int ata_scsiop_inq_std(struct 
ata_scsi_args *args, u8 *rbuf)
0,
0x5,/* claim SPC-3 version compatibility */
2,
-   95 - 4
+   95 - 4,
+   0,
+   0,
+   0
};
 
VPRINTK("ENTER\n");
@@ -2024,6 +2027,9 @@ static unsigned int ata_scsiop_inq_std(struct 
ata_scsi_args *args, u8 *rbuf)
hdr[2] = 0x6; /* ZBC is defined in SPC-4 */
}
 
+   if (ata_ncq_enabled(args->dev))
+   hdr[7] |= (1 << 1);
+
memcpy(rbuf, hdr, sizeof(hdr));
memcpy([8], "ATA ", 8);
ata_id_string(args->id, [16], ATA_ID_PROD, 16);
-- 
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/3] libata-scsi: Fix SCSI INQUIRY version descriptor

2016-05-02 Thread tom . ty89
From: Tom Yan 

https://bugzilla.kernel.org/show_bug.cgi?id=106931
Signed-off-by: Tom Yan 

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index cd30f11..0295c38 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -1985,8 +1985,8 @@ static unsigned int ata_scsiop_inq_std(struct 
ata_scsi_args *args, u8 *rbuf)
0x03,
0x20,   /* SBC-2 (no version claimed) */
 
-   0x02,
-   0x60/* SPC-3 (no version claimed) */
+   0x03,
+   0x00/* SPC-3 (no version claimed) */
};
const u8 versions_zbc[] = {
0x00,
-- 
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] libata-scsi: Do not partially report ATA read look-ahead

2016-05-02 Thread tom . ty89
From: Tom Yan 

Nothing in the kernel actually makes use of the DRA bit in SCSI
MODE SENSE. Neither is there a sysfs file (like 'cache_type' for
WCE) that allows users to change the bit nor SCSI-ATA Translation
that can toggle the ATA feature.

Hence removing the MODE SENSE SCSI-ATA Translation that is only
triggered by the change of WCE to avoid silliness like this:
https://bugzilla.kernel.org/show_bug.cgi?id=105861#c2

Signed-off-by: Tom Yan 

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 0295c38..8c07db8 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -2316,8 +2316,6 @@ static unsigned int ata_msense_caching(u16 *id, u8 *buf, 
bool changeable)
modecpy(buf, def_cache_mpage, sizeof(def_cache_mpage), changeable);
if (changeable || ata_id_wcache_enabled(id))
buf[2] |= (1 << 2); /* write cache enable */
-   if (!changeable && !ata_id_rahead_enabled(id))
-   buf[12] |= (1 << 5);/* disable read ahead */
return sizeof(def_cache_mpage);
 }
 
-- 
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [dm-devel] [Lsf] Notes from the four separate IO track sessions at LSF/MM

2016-05-02 Thread Laurence Oberman


Laurence Oberman
Principal Software Maintenance Engineer
Red Hat Global Support Services

- Original Message -
From: "Bart Van Assche" 
To: "Laurence Oberman" 
Cc: linux-bl...@vger.kernel.org, "linux-scsi" , 
"Mike Snitzer" , "James Bottomley" 
, "device-mapper development" 
, l...@lists.linux-foundation.org
Sent: Monday, May 2, 2016 2:49:54 PM
Subject: Re: [dm-devel] [Lsf] Notes from the four separate IO track sessions at 
LSF/MM

On 04/29/2016 05:47 PM, Laurence Oberman wrote:
> From: "Bart Van Assche" 
> To: "Laurence Oberman" 
> Cc: "James Bottomley" , "linux-scsi" 
> , "Mike Snitzer" , 
> linux-bl...@vger.kernel.org, "device-mapper development" 
> , l...@lists.linux-foundation.org
> Sent: Friday, April 29, 2016 8:36:22 PM
> Subject: Re: [dm-devel] [Lsf] Notes from the four separate IO track sessions 
> at LSF/MM
>
>> On 04/29/2016 02:47 PM, Laurence Oberman wrote:
>>> Recovery with 21 LUNS is 300s that have in-flights to abort.
>>> [ ... ]
>>> eh_deadline is set to 10 on the 2 qlogic ports, eh_timeout is set
>>> to 10 for all devices. In multipath fast_io_fail_tmo=5
>>>
>>> I jam one of the target array ports and discard the commands
>>> effectively black-holing the commands and leave it that way until
>>> we recover and I watch the I/O. The recovery takes around 300s even
>>> with all the tuning and this effectively lands up in Oracle cluster
>>> evictions.
>>
>> This discussion started as a discussion about the time needed to fail
>> over from one path to another. How long did it take in your test before
>> I/O failed over from the jammed port to another port?
 >
 > Around 300s before the paths were declared hard failed and the
 > devices offlined. This is when I/O restarts.
 > The remaining paths on the second Qlogic port (that are not jammed)
 > will not be used until the error handler activity completes.
 >
 > Until we get these for example, and device-mapper starts declaring
 > paths down we are blocked.
 > Apr 29 17:20:51 localhost kernel: sd 1:0:1:0: Device offlined - not
 > ready after error recovery
 > Apr 29 17:20:51 localhost kernel: sd 1:0:1:13: Device offlined - not
 > ready after error recovery

Hello Laurence,

Everyone else on all mailing lists to which this message has been posted 
replies below the message. Please follow this convention.

Regarding the fail-over time: the ib_srp driver guarantees that 
scsi_done() is invoked from inside its terminate_rport_io() function. 
Apparently the lpfc and the qla2xxx drivers behave differently. Please 
work with the maintainers of these drivers to reduce fail-over time.

Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Hello Bart

Even in the case of the ib_srp, don't we also have to still run the eh_timeout 
for each of the devices that has inflight requiring error handling serially.
This means we will still have to wait to get a path failover until all are 
through the timeout.

Thanks
Laurence
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [dm-devel] [Lsf] Notes from the four separate IO track sessions at LSF/MM

2016-05-02 Thread Bart Van Assche

On 04/29/2016 05:47 PM, Laurence Oberman wrote:

From: "Bart Van Assche" 
To: "Laurence Oberman" 
Cc: "James Bottomley" , "linux-scsi" , 
"Mike Snitzer" , linux-bl...@vger.kernel.org, "device-mapper development" 
, l...@lists.linux-foundation.org
Sent: Friday, April 29, 2016 8:36:22 PM
Subject: Re: [dm-devel] [Lsf] Notes from the four separate IO track sessions at 
LSF/MM


On 04/29/2016 02:47 PM, Laurence Oberman wrote:

Recovery with 21 LUNS is 300s that have in-flights to abort.
[ ... ]
eh_deadline is set to 10 on the 2 qlogic ports, eh_timeout is set
to 10 for all devices. In multipath fast_io_fail_tmo=5

I jam one of the target array ports and discard the commands
effectively black-holing the commands and leave it that way until
we recover and I watch the I/O. The recovery takes around 300s even
with all the tuning and this effectively lands up in Oracle cluster
evictions.


This discussion started as a discussion about the time needed to fail
over from one path to another. How long did it take in your test before
I/O failed over from the jammed port to another port?

>
> Around 300s before the paths were declared hard failed and the
> devices offlined. This is when I/O restarts.
> The remaining paths on the second Qlogic port (that are not jammed)
> will not be used until the error handler activity completes.
>
> Until we get these for example, and device-mapper starts declaring
> paths down we are blocked.
> Apr 29 17:20:51 localhost kernel: sd 1:0:1:0: Device offlined - not
> ready after error recovery
> Apr 29 17:20:51 localhost kernel: sd 1:0:1:13: Device offlined - not
> ready after error recovery

Hello Laurence,

Everyone else on all mailing lists to which this message has been posted 
replies below the message. Please follow this convention.


Regarding the fail-over time: the ib_srp driver guarantees that 
scsi_done() is invoked from inside its terminate_rport_io() function. 
Apparently the lpfc and the qla2xxx drivers behave differently. Please 
work with the maintainers of these drivers to reduce fail-over time.


Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


hpsa: Fix type ZBC conditional checks

2016-05-02 Thread Petros Koutoupis
The device ID obtained from the inquiry can only be of a single type. The 
original
code places a check for TYPE_ZBC right after the check for TYPE_DISK. Logically,
if the first if statement sees a device of a TYPE_DISK and moves on to the 
second
statement checking if not TYPE_ZBC, it will always hit the continue.

--- linux/drivers/scsi/hpsa.c.orig  2016-04-27 21:43:44.463140419 -0500
+++ linux/drivers/scsi/hpsa.c   2016-04-27 22:45:31.015140419 -0500
@@ -1637,9 +1637,8 @@ static void hpsa_figure_phys_disk_ptrs(s
    for (j = 0; j < ndevices; j++) {
    if (dev[j] == NULL)
    continue;
-   if (dev[j]->devtype != TYPE_DISK)
-   continue;
-   if (dev[j]->devtype != TYPE_ZBC)
+   if ((dev[j]->devtype != TYPE_DISK) &&
+   (dev[j]->devtype != TYPE_ZBC))
    continue;
    if (is_logical_device(dev[j]))
    continue;
@@ -1684,9 +1683,8 @@ static void hpsa_update_log_drive_phys_d
    for (i = 0; i < ndevices; i++) {
    if (dev[i] == NULL)
    continue;
-   if (dev[i]->devtype != TYPE_DISK)
-   continue;
-   if (dev[i]->devtype != TYPE_ZBC)
+   if ((dev[i]->devtype != TYPE_DISK) &&
+   (dev[i]->devtype != TYPE_ZBC))
    continue;
    if (!is_logical_device(dev[i]))
    continue;
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2.5 4/6] scsi_debug: vpd and mode page work

2016-05-02 Thread Douglas Gilbert

On 2016-05-02 04:38 AM, Hannes Reinecke wrote:

On 05/01/2016 04:44 AM, Douglas Gilbert wrote:

Cleanup some mode and vpd pages. Stop reporting SBC (disk) pages
when peripheral type is something else (e.g. tape). Update
version descriptors. Expand LBPRZ flag handling.

Signed-off-by: Douglas Gilbert 
---
  drivers/scsi/scsi_debug.c | 187 ++
  1 file changed, 108 insertions(+), 79 deletions(-)

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 0932111..814067d 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -125,7 +125,7 @@ static const char *sdebug_version_date = "20160430";
  #define DEF_PHYSBLK_EXP 0
  #define DEF_PTYPE   TYPE_DISK
  #define DEF_REMOVABLE false
-#define DEF_SCSI_LEVEL   6/* INQUIRY, byte2 [6->SPC-4] */
+#define DEF_SCSI_LEVEL   7/* INQUIRY, byte2 [6->SPC-4; 7->SPC-5] */
  #define DEF_SECTOR_SIZE 512
  #define DEF_UNMAP_ALIGNMENT 0
  #define DEF_UNMAP_GRANULARITY 1
@@ -657,7 +657,11 @@ static const int device_qfull_result =
(DID_OK << 16) | (COMMAND_COMPLETE << 8) | SAM_STAT_TASK_SET_FULL;


-static inline unsigned int scsi_debug_lbp(void)
+/* Only do the extra work involved in logical block provisioning if one or
+ * more of the lbpu, lbpws or lbpws10 parameters are given and we are doing
+ * real reads and writes (i.e. not skipping them for speed).
+ */
+static inline bool scsi_debug_lbp(void)
  {
return 0 == sdebug_fake_rw &&
(sdebug_lbpu || sdebug_lbpws || sdebug_lbpws10);
@@ -918,10 +922,10 @@ static const u64 naa5_comp_b = 0x5330ULL;
  static const u64 naa5_comp_c = 0x5110ULL;

  /* Device identification VPD page. Returns number of bytes placed in arr */
-static int inquiry_evpd_83(unsigned char * arr, int port_group_id,
-  int target_dev_id, int dev_id_num,
-  const char * dev_id_str,
-  int dev_id_str_len)
+static int inquiry_vpd_83(unsigned char *arr, int port_group_id,
+ int target_dev_id, int dev_id_num,
+ const char *dev_id_str,
+ int dev_id_str_len)
  {
int num, port_a;
char b[32];
@@ -1000,14 +1004,14 @@ static unsigned char vpd84_data[] = {
  };

  /*  Software interface identification VPD page */
-static int inquiry_evpd_84(unsigned char * arr)
+static int inquiry_vpd_84(unsigned char *arr)
  {
memcpy(arr, vpd84_data, sizeof(vpd84_data));
return sizeof(vpd84_data);
  }

  /* Management network addresses VPD page */
-static int inquiry_evpd_85(unsigned char * arr)
+static int inquiry_vpd_85(unsigned char *arr)
  {
int num = 0;
const char * na1 = "https://www.kernel.org/config;;
@@ -1042,7 +1046,7 @@ static int inquiry_evpd_85(unsigned char * arr)
  }

  /* SCSI ports VPD page */
-static int inquiry_evpd_88(unsigned char * arr, int target_dev_id)
+static int inquiry_vpd_88(unsigned char *arr, int target_dev_id)
  {
int num = 0;
int port_a, port_b;
@@ -1129,7 +1133,7 @@ static unsigned char vpd89_data[] = {
  };

  /* ATA Information VPD page */
-static int inquiry_evpd_89(unsigned char * arr)
+static int inquiry_vpd_89(unsigned char *arr)
  {
memcpy(arr, vpd89_data, sizeof(vpd89_data));
return sizeof(vpd89_data);
@@ -1144,7 +1148,7 @@ static unsigned char vpdb0_data[] = {
  };

  /* Block limits VPD page (SBC-3) */
-static int inquiry_evpd_b0(unsigned char * arr)
+static int inquiry_vpd_b0(unsigned char *arr)
  {
unsigned int gran;

@@ -1187,7 +1191,7 @@ static int inquiry_evpd_b0(unsigned char * arr)
  }

  /* Block device characteristics VPD page (SBC-3) */
-static int inquiry_evpd_b1(unsigned char *arr)
+static int inquiry_vpd_b1(unsigned char *arr)
  {
memset(arr, 0, 0x3c);
arr[0] = 0;
@@ -1198,24 +1202,22 @@ static int inquiry_evpd_b1(unsigned char *arr)
return 0x3c;
  }

-/* Logical block provisioning VPD page (SBC-3) */
-static int inquiry_evpd_b2(unsigned char *arr)
+/* Logical block provisioning VPD page (SBC-4) */
+static int inquiry_vpd_b2(unsigned char *arr)
  {
memset(arr, 0, 0x4);
arr[0] = 0; /* threshold exponent */
-
if (sdebug_lbpu)
arr[1] = 1 << 7;
-
if (sdebug_lbpws)
arr[1] |= 1 << 6;
-
if (sdebug_lbpws10)
arr[1] |= 1 << 5;
-
-   if (sdebug_lbprz)
-   arr[1] |= 1 << 2;
-
+   if (sdebug_lbprz && scsi_debug_lbp())
+   arr[1] |= (sdebug_lbprz & 0x7) << 2;  /* sbc4r07 and later */
+   /* anc_sup=0; dp=0 (no provisioning group descriptor) */
+   /* minimum_percentage=0; provisioning_type=0 (unknown) */
+   /* threshold_percentage=0 */
return 0x4;
  }

@@ -1228,12 +1230,13 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct 
sdebug_dev_info *devip)
unsigned char 

Re: [PATCH v2.5 3/6] scsi_debug: add multiple queue support

2016-05-02 Thread Douglas Gilbert

On 2016-05-02 04:35 AM, Hannes Reinecke wrote:

On 05/01/2016 04:44 AM, Douglas Gilbert wrote:

Add submit_queue parameter (minimum and default: 1; maximum:
nr_cpu_ids) that controls how many queues are built, each with
their own lock and in_use bit vector. Add statistics parameter
which is default on.

Signed-off-by: Douglas Gilbert 
---
  drivers/scsi/scsi_debug.c | 680 +-
  1 file changed, 426 insertions(+), 254 deletions(-)


Two general questions for this:

- Why do you get rid of the embedded command payload?


I'm not sure what payload you a referring to. And this patch
only adds multiple queues, I can't see that it removes anything.


   Where's the benefit of allocating the commands yourself?


The commands are either replied to "in thread" (e.g. when delay=0
or an error is detected), or queued on a hr timer or work item.
A pointer to the command is held in the queue (the same as before
this patch). The only allocations associated with commands are to
build data-in buffers for responses. (e.g. an INQUIRY command for
a VPD page).


- Wouldn't it be better to move to a per-cpu structure per queue?
   Each queue will be tacked to a CPU anyway, so you could be using
   per-cpu structures. Otherwise you'll run into synchronization
   issues, and any performance gain you might get from scsi-mq is
   lost as you to synchronize on the lower level.


I offer this patch as being necessary, but probably not sufficient
for implementing full scsi "mq". The interface itself for
scsi/block mq does not seem to be documented and is possibly in a
state of flux.

From testing this patch (e.g. by observing
"cat /proc/scsi/scsi_debug/" while fio is running, the
CPU affinity is very good without any per-cpu magic ***. The
"misqueues" count (that is (cpu) miscues on queues) records the
number of times a timer or a workqueue gets its callback on a
different cpu, is extremely low, typically zero. I could get
non-zero numbers if I ran something else (e.g. a kernel build)
while fio was running, still the misqueues were well under 1% of
commands queued.

That said, I see very little performance improvement with
submit_queues=4 (the number of processors on my two test machines)
compared to submit_queues=1 which is effectively what the driver was
doing before this patch. So I'm open to suggestions, especially in
the form of code :-)


Also if we went for per-cpu structures should we worry about the
complex issue of a cpu being hot unplugged (or plugged back in)
while its queue was holding unfinished commands?

Doug Gilbert


*** you are probably correct that without the per-cpu "magic" lock
contention is likely the cause of so little performance
improvement in the multiple submit queues case.
Also while testing with fio, submit_queues=,
'top -H' shows each fio thread at around 100%.


--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: UFS patchset

2016-05-02 Thread Joao Pinto
Hi Martin,

On 4/30/2016 1:24 AM, Martin K. Petersen wrote:
>> "Martin" == Martin K Petersen  writes:
> 
> Joao,
> 
> Martin> In a previous email you said you had sent v14 to
> Martin> linux-scsi. However, I don't see neither v14, nor v13 in
> Martin> patchworks. The latest I have is v12 and it does not apply to
> Martin> 4.7/scsi-queue.
> 
> I found v14 in my mailbox. Not sure why it's not in patchworks.
> 
> In any case: It still doesn't apply to 4.7/scsi-queue and there are
> several checkpatch warnings throughout the series. Please fix.
> 
> Also make sure to prefix your patch subject lines with "ufs:" so it's
> easy to identify which subsystem they go into.
> 
> Thanks!
> 

As promissed I sent you a new patch set based on the latest 4.7 queue branch,
with "ufs:" prefix and completely tested and validated by checkpatch.

Thanks.
Joao
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv2]sd: Don't treat succeeded SYNC as error

2016-05-02 Thread James Bottomley
On Mon, 2016-05-02 at 06:44 -0700, James Bottomley wrote:
> On Mon, 2016-05-02 at 12:05 +0200, Hannes Reinecke wrote:
> > On 04/29/2016 02:49 PM, Jinpu Wang wrote:
> > > Hi, all
> > > 
> > > We hit IO error on fsync, it turns out was because sd treat
> > > succeeded
> > > SYNC as error. From what I checked in SBC spec there is no
> > > indication
> > > we should fail IO in this case, so we create this patch.
> > > 
> > > 
> > > Best Regards,
> > > 
> > > Jack Wang
> > > 
> > > v2:
> > > No change on patch itself, only resend in body as suggested by
> > > Bart,
> > > still keep the attachment in case mail client break the format.
> > > 
> > > From 5d1f72d9643ce61cd9f3d312377378c43f171d0c Mon Sep 17 00:00:00
> > > 2001
> > > From: Jack Wang 
> > > Date: Mon, 25 Apr 2016 12:05:22 +0200
> > > Subject: [PATCH] sd: Don't treat succeeded SYNC as error
> > > 
> > > We hit IO error in our production on multipath devices during
> > > resize
> > > device on target side, the problem turns out sd driver passes up
> > > as
> > > IO
> > > error when sense data is UNIT_ATTENTION and ASC && ASCQ indicate
> > > Capacity data has changed, even storage side sync the data
> > > properly.
> > > 
> > > In order to fix this check in sd_done, report success if
> > > condition
> > > matches.
> > > 
> > > Sebastian Parschauer report/analyze the bug here:
> > > https://sourceforge.net/p/scst/mailman/message/34953416/
> > > 
> > > Signed-off-by: Sebastian Parschauer 
> > > Signed-off-by: Jack Wang 
> > > ---
> > >  drivers/scsi/sd.c | 13 +
> > >  1 file changed, 13 insertions(+)
> > > 
> > Well.
> > Is there anything which guarantees us that 'capacity data has
> > changed' will be the only sense code which we'll be seeing as a
> > response to SYNCHRONIZE CACHE?
> > I sincerely doubt so.
> > So why don't you fall back to the default action (ie retry the
> > command) whenever you hit an UNIT ATTENTION?
> > This way we would cove any resulting sense code, _and_ would get
> > rid
> > of the rather ugly special case here.
> 
> Actually, why are we getting here at all?  should we be eating this
> unit attention once we've reported it in scsi_check_sense()?
> 
> I also don't quite understand why the normal retry mechanism in
> scsi_io_completion() (called after drv->done()) isn't handling this. 
>  We set retries on a flush command and we give sd_sync_cache three
> goes.  Any one of those should also cause the CC/UA to be ignored.

Actually, there's another problem with this patch: you're clearing the
error and indicating success, meaning you never retry.  CC/UA for
notifications is usually signalled in the device before acting on the
command, so the chances are your SYNC request was never executed and if
you never retry we'll be operating in a cache unstaged situation where
we're assuming data will be on the medium.

James


--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v15 2/9] ufs: add UFS 2.0 to ufshcd-pltfrm bindings

2016-05-02 Thread Joao Pinto
Add UFS 2.0 to the ufshcd-pltfrm devicetree binding.

Signed-off-by: Joao Pinto 
Acked-by: Rob Herring 
Acked-by: Tomas Winkler 
---
Changes v12->v15:
- Nothing changed (just to keep up with patch set version).
Changes v0->v12 (Tomas Winkler):
- This patch only appeared in v12

 Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt 
b/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
index 66f6adf..a99ed55 100644
--- a/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
+++ b/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
@@ -4,8 +4,8 @@ UFSHC nodes are defined to describe on-chip UFS host 
controllers.
 Each UFS controller instance should have its own node.
 
 Required properties:
-- compatible   : must contain "jedec,ufs-1.1", may also list one or 
more
- of the following:
+- compatible   : must contain "jedec,ufs-1.1" or "jedec,ufs-2.0", may
+ also list one or more of the following:
  "qcom,msm8994-ufshc"
  "qcom,msm8996-ufshc"
  "qcom,ufshc"
-- 
1.8.1.5

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v15 1/9] ufs:fixed typo in ufshcd-pltfrm

2016-05-02 Thread Joao Pinto
Fixed typo in ufshcd-pltfrm.

Signed-off-by: Joao Pinto 
Acked-by: Arnd Bergmann 
Acked-by: Tomas Winkler 
---
Changes v0->v15:
- Nothing changed (just to keep up with patch set version).

 drivers/scsi/ufs/ufshcd-pltfrm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c
index 718f12e..db53f38 100644
--- a/drivers/scsi/ufs/ufshcd-pltfrm.c
+++ b/drivers/scsi/ufs/ufshcd-pltfrm.c
@@ -372,6 +372,6 @@ EXPORT_SYMBOL_GPL(ufshcd_pltfrm_init);
 
 MODULE_AUTHOR("Santosh Yaragnavi ");
 MODULE_AUTHOR("Vinayak Holikatti ");
-MODULE_DESCRIPTION("UFS host controller Pltform bus based glue driver");
+MODULE_DESCRIPTION("UFS host controller Platform bus based glue driver");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(UFSHCD_DRIVER_VERSION);
-- 
1.8.1.5

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v15 4/9] ufs: added unipro attributes

2016-05-02 Thread Joao Pinto
Added unipro attributes.

Signed-off-by: Joao Pinto 
Acked-by: Tomas Winkler 
---
Changes v12->v15:
- Nothing changed (just to keep up with patch set version).
Changes v0->v12 (Tomas Winkler):
- This patch only appeared in v12

 drivers/scsi/ufs/unipro.h | 39 +++
 1 file changed, 39 insertions(+)

diff --git a/drivers/scsi/ufs/unipro.h b/drivers/scsi/ufs/unipro.h
index e2854e4..eff8b56 100644
--- a/drivers/scsi/ufs/unipro.h
+++ b/drivers/scsi/ufs/unipro.h
@@ -36,6 +36,10 @@
 #define TX_LCC_SEQUENCER   0x0032
 #define TX_MIN_ACTIVATETIME0x0033
 #define TX_PWM_G6_G7_SYNC_LENGTH   0x0034
+#define TX_REFCLKFREQ  0x00EB
+#define TX_CFGCLKFREQVAL   0x00EC
+#defineCFGEXTRATTR 0x00F0
+#define DITHERCTRL20x00F1
 
 /*
  * M-RX Configuration Attributes
@@ -51,10 +55,40 @@
 #define RX_TERMINATION_FORCE_ENABLE0x0089
 #define RX_MIN_ACTIVATETIME_CAPABILITY 0x008F
 #define RX_HIBERN8TIME_CAPABILITY  0x0092
+#define RX_REFCLKFREQ  0x00EB
+#defineRX_CFGCLKFREQVAL0x00EC
+#define CFGWIDEINLN0x00F0
+#define CFGRXCDR8  0x00BA
+#define ENARXDIRECTCFG40x00F2
+#define CFGRXOVR8  0x00BD
+#define RXDIRECTCTRL2  0x00C7
+#define ENARXDIRECTCFG30x00F3
+#define RXCALCTRL  0x00B4
+#define ENARXDIRECTCFG20x00F4
+#define CFGRXOVR4  0x00E9
+#define RXSQCTRL   0x00B5
+#define CFGRXOVR6  0x00BF
 
 #define is_mphy_tx_attr(attr)  (attr < RX_MODE)
 #define RX_MIN_ACTIVATETIME_UNIT_US100
 #define HIBERN8TIME_UNIT_US100
+
+/*
+ * Common Block Attributes
+ */
+#define TX_GLOBALHIBERNATE UNIPRO_CB_OFFSET(0x002B)
+#define REFCLKMODE UNIPRO_CB_OFFSET(0x00BF)
+#define DIRECTCTRL19   UNIPRO_CB_OFFSET(0x00CD)
+#define DIRECTCTRL10   UNIPRO_CB_OFFSET(0x00E6)
+#define CDIRECTCTRL6   UNIPRO_CB_OFFSET(0x00EA)
+#define RTOBSERVESELECTUNIPRO_CB_OFFSET(0x00F0)
+#define CBDIVFACTORUNIPRO_CB_OFFSET(0x00F1)
+#define CBDCOCTRL5 UNIPRO_CB_OFFSET(0x00F3)
+#define CBPRGPLL2  UNIPRO_CB_OFFSET(0x00F8)
+#define CBPRGTUNINGUNIPRO_CB_OFFSET(0x00FB)
+
+#define UNIPRO_CB_OFFSET(x)(0x8000 | x)
+
 /*
  * PHY Adpater attributes
  */
@@ -119,6 +153,11 @@
 #define PA_TACTIVATE_TIME_UNIT_US  10
 #define PA_HIBERN8_TIME_UNIT_US100
 
+/*Other attributes*/
+#define VS_MPHYCFGUPDT 0xD085
+#define VS_DEBUGOMC0xD09E
+#define VS_POWERSTATE  0xD083
+
 /* PHY Adapter Protocol Constants */
 #define PA_MAXDATALANES4
 
-- 
1.8.1.5

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v15 7/9] ufs: added support for Synopsys G210 Test Chip

2016-05-02 Thread Joao Pinto
This patch adds support for Synopsys G210 Test Chip.

Signed-off-by: Joao Pinto 
Acked-by: Arnd Bergmann 
---
Changes v10->v15:
- Nothing changed (just to keep up with patch set version).
Changes v0->v10:
- This patch only appeared in v10

 drivers/scsi/ufs/Kconfig   |   4 +
 drivers/scsi/ufs/Makefile  |   1 +
 drivers/scsi/ufs/tc-dwc-g210.c | 315 +
 drivers/scsi/ufs/tc-dwc-g210.h |  19 +++
 4 files changed, 339 insertions(+)
 create mode 100644 drivers/scsi/ufs/tc-dwc-g210.c
 create mode 100644 drivers/scsi/ufs/tc-dwc-g210.h

diff --git a/drivers/scsi/ufs/Kconfig b/drivers/scsi/ufs/Kconfig
index 06ff8ba..9594558 100644
--- a/drivers/scsi/ufs/Kconfig
+++ b/drivers/scsi/ufs/Kconfig
@@ -87,3 +87,7 @@ config SCSI_UFS_QCOM
 
 config SCSI_UFS_DWC
bool
+
+config SCSI_UFS_DWC_TC
+   bool
+   select SCSI_UFS_DWC
diff --git a/drivers/scsi/ufs/Makefile b/drivers/scsi/ufs/Makefile
index ccbad53..9468d7b 100644
--- a/drivers/scsi/ufs/Makefile
+++ b/drivers/scsi/ufs/Makefile
@@ -1,5 +1,6 @@
 # UFSHCD makefile
 obj-$(CONFIG_SCSI_UFS_DWC) += ufshcd-dwc.o
+obj-$(CONFIG_SCSI_UFS_DWC_TC) += tc-dwc-g210.o
 obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o
 obj-$(CONFIG_SCSI_UFSHCD) += ufshcd.o
 obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o
diff --git a/drivers/scsi/ufs/tc-dwc-g210.c b/drivers/scsi/ufs/tc-dwc-g210.c
new file mode 100644
index 000..181f208
--- /dev/null
+++ b/drivers/scsi/ufs/tc-dwc-g210.c
@@ -0,0 +1,315 @@
+/*
+ * Synopsys G210 Test Chip driver
+ *
+ * Copyright (C) 2015-2016 Synopsys, Inc. (www.synopsys.com)
+ *
+ * Authors: Joao Pinto 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "ufshcd.h"
+#include "unipro.h"
+
+#include "ufshcd-dwc.h"
+#include "ufshci-dwc.h"
+
+/**
+ * tc_dwc_g210_setup_40bit_rmmi()
+ * This function configures Synopsys TC specific atributes (40-bit RMMI)
+ * @hba: Pointer to drivers structure
+ *
+ * Returns 0 on success or non-zero value on failure
+ */
+static int tc_dwc_g210_setup_40bit_rmmi(struct ufs_hba *hba)
+{
+   const struct ufshcd_dme_attr_val setup_attrs[] = {
+   { UIC_ARG_MIB(TX_GLOBALHIBERNATE), 0x00, DME_LOCAL },
+   { UIC_ARG_MIB(REFCLKMODE), 0x01, DME_LOCAL },
+   { UIC_ARG_MIB(CDIRECTCTRL6), 0x80, DME_LOCAL },
+   { UIC_ARG_MIB(CBDIVFACTOR), 0x08, DME_LOCAL },
+   { UIC_ARG_MIB(CBDCOCTRL5), 0x64, DME_LOCAL },
+   { UIC_ARG_MIB(CBPRGTUNING), 0x09, DME_LOCAL },
+   { UIC_ARG_MIB(RTOBSERVESELECT), 0x00, DME_LOCAL },
+   { UIC_ARG_MIB_SEL(TX_REFCLKFREQ, SELIND_LN0_TX), 0x01,
+   DME_LOCAL },
+   { UIC_ARG_MIB_SEL(TX_CFGCLKFREQVAL, SELIND_LN0_TX), 0x19,
+   DME_LOCAL },
+   { UIC_ARG_MIB_SEL(CFGEXTRATTR, SELIND_LN0_TX), 0x14,
+   DME_LOCAL },
+   { UIC_ARG_MIB_SEL(DITHERCTRL2, SELIND_LN0_TX), 0xd6,
+   DME_LOCAL },
+   { UIC_ARG_MIB_SEL(RX_REFCLKFREQ, SELIND_LN0_RX), 0x01,
+   DME_LOCAL },
+   { UIC_ARG_MIB_SEL(RX_CFGCLKFREQVAL, SELIND_LN0_RX), 0x19,
+   DME_LOCAL },
+   { UIC_ARG_MIB_SEL(CFGWIDEINLN, SELIND_LN0_RX), 4,
+   DME_LOCAL },
+   { UIC_ARG_MIB_SEL(CFGRXCDR8, SELIND_LN0_RX), 0x80,
+   DME_LOCAL },
+   { UIC_ARG_MIB(DIRECTCTRL10), 0x04, DME_LOCAL },
+   { UIC_ARG_MIB(DIRECTCTRL19), 0x02, DME_LOCAL },
+   { UIC_ARG_MIB_SEL(CFGRXCDR8, SELIND_LN0_RX), 0x80,
+   DME_LOCAL },
+   { UIC_ARG_MIB_SEL(ENARXDIRECTCFG4, SELIND_LN0_RX), 0x03,
+   DME_LOCAL },
+   { UIC_ARG_MIB_SEL(CFGRXOVR8, SELIND_LN0_RX), 0x16,
+   DME_LOCAL },
+   { UIC_ARG_MIB_SEL(RXDIRECTCTRL2, SELIND_LN0_RX), 0x42,
+   DME_LOCAL },
+   { UIC_ARG_MIB_SEL(ENARXDIRECTCFG3, SELIND_LN0_RX), 0xa4,
+   DME_LOCAL },
+   { UIC_ARG_MIB_SEL(RXCALCTRL, SELIND_LN0_RX), 0x01,
+   DME_LOCAL },
+   { 

[PATCH v15 5/9] ufs: added link status to ufshci

2016-05-02 Thread Joao Pinto
Added link status to ufshci.

Signed-off-by: Joao Pinto 
Acked-by: Tomas Winkler 
---
Changes v12->v15:
- Nothing changed (just to keep up with patch set version).
Changes v0->v12 (Tomas Winkler):
- This patch only appeared in v12

 drivers/scsi/ufs/ufshci.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/scsi/ufs/ufshci.h b/drivers/scsi/ufs/ufshci.h
index 3a2439f..6c7479c 100644
--- a/drivers/scsi/ufs/ufshci.h
+++ b/drivers/scsi/ufs/ufshci.h
@@ -220,6 +220,12 @@ enum {
 #define UIC_ARG_ATTR_TYPE(t)   (((t) & 0xFF) << 16)
 #define UIC_GET_ATTR_ID(v) (((v) >> 16) & 0x)
 
+/* Link Status*/
+enum link_status {
+   UFSHCD_LINK_IS_DOWN = 1,
+   UFSHCD_LINK_IS_UP   = 2,
+};
+
 /* UIC Commands */
 enum uic_cmd_dme {
UIC_CMD_DME_GET = 0x01,
-- 
1.8.1.5

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v15 8/9] ufs: add TC G210 platform driver

2016-05-02 Thread Joao Pinto
This patch adds a glue platform driver for the Synopsys G210 Test Chip.

Signed-off-by: Joao Pinto 
---
Changes v13->v15:
- Nothing changed (just to keep up with patch set version).
Changes v12->v13 (Rob Herring):
- Removed spaces from the compatibility string (pltfm driver and DT bindings)
- Removed underscores from the node descriptor
Changes v11->v12 (Tomas Winkler):
- custom_phy_initialization replaced by phy_initialization
Changes v10->v11 (Arnd Bergmann):
- vops structs are now passed in .data
Changes v0->v10:
- This patch only appeared in v10

 .../devicetree/bindings/ufs/tc-dwc-g210-pltfrm.txt |  26 +
 drivers/scsi/ufs/Kconfig   |   9 ++
 drivers/scsi/ufs/Makefile  |   1 +
 drivers/scsi/ufs/tc-dwc-g210-pltfrm.c  | 113 +
 4 files changed, 149 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ufs/tc-dwc-g210-pltfrm.txt
 create mode 100644 drivers/scsi/ufs/tc-dwc-g210-pltfrm.c

diff --git a/Documentation/devicetree/bindings/ufs/tc-dwc-g210-pltfrm.txt 
b/Documentation/devicetree/bindings/ufs/tc-dwc-g210-pltfrm.txt
new file mode 100644
index 000..71c0777
--- /dev/null
+++ b/Documentation/devicetree/bindings/ufs/tc-dwc-g210-pltfrm.txt
@@ -0,0 +1,26 @@
+* Universal Flash Storage (UFS) DesignWare Host Controller
+
+DWC_UFS nodes are defined to describe on-chip UFS host controllers and MPHY.
+Each UFS controller instance should have its own node.
+
+Required properties:
+- compatible   : compatible list must contain the PHY type & version:
+   "snps,g210-tc-6.00-20bit"
+   "snps,g210-tc-6.00-40bit"
+ complemented with the Controller IP version:
+   "snps,dwc-ufshcd-1.40a"
+ complemented with the JEDEC version:
+   "jedec,ufs-1.1"
+   "jedec,ufs-2.0"
+
+- reg  : 
+- interrupts   : 
+
+Example for a setup using a 1.40a DWC Controller with a 6.00 G210 40-bit TC:
+   dwc-ufs@d000 {
+   compatible = "snps,g210-tc-6.00-40bit",
+"snps,dwc-ufshcd-1.40a",
+"jedec,ufs-2.0";
+   reg = < 0xd000 0x1 >;
+   interrupts = < 24 >;
+   };
diff --git a/drivers/scsi/ufs/Kconfig b/drivers/scsi/ufs/Kconfig
index 9594558..87f20d1 100644
--- a/drivers/scsi/ufs/Kconfig
+++ b/drivers/scsi/ufs/Kconfig
@@ -91,3 +91,12 @@ config SCSI_UFS_DWC
 config SCSI_UFS_DWC_TC
bool
select SCSI_UFS_DWC
+
+config SCSI_UFS_DWC_TC_PLATFORM
+   tristate "DesignWare platform support using a G210 Test Chip"
+   depends on SCSI_UFSHCD_PLATFORM
+   select SCSI_UFS_DWC_TC
+   ---help---
+ Synopsys Test Chip is a PHY for prototyping purposes.
+
+ If unsure, say N."
diff --git a/drivers/scsi/ufs/Makefile b/drivers/scsi/ufs/Makefile
index 9468d7b..a977fe0 100644
--- a/drivers/scsi/ufs/Makefile
+++ b/drivers/scsi/ufs/Makefile
@@ -1,6 +1,7 @@
 # UFSHCD makefile
 obj-$(CONFIG_SCSI_UFS_DWC) += ufshcd-dwc.o
 obj-$(CONFIG_SCSI_UFS_DWC_TC) += tc-dwc-g210.o
+obj-$(CONFIG_SCSI_UFS_DWC_TC_PLATFORM) += tc-dwc-g210-pltfrm.o
 obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o
 obj-$(CONFIG_SCSI_UFSHCD) += ufshcd.o
 obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o
diff --git a/drivers/scsi/ufs/tc-dwc-g210-pltfrm.c 
b/drivers/scsi/ufs/tc-dwc-g210-pltfrm.c
new file mode 100644
index 000..69b7036
--- /dev/null
+++ b/drivers/scsi/ufs/tc-dwc-g210-pltfrm.c
@@ -0,0 +1,113 @@
+/*
+ * Synopsys G210 Test Chip driver
+ *
+ * Copyright (C) 2015-2016 Synopsys, Inc. (www.synopsys.com)
+ *
+ * Authors: Joao Pinto 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ufshcd-pltfrm.h"
+#include "ufshcd-dwc.h"
+#include "tc-dwc-g210.h"
+
+/**
+ * UFS DWC specific variant operations
+ */
+static struct ufs_hba_variant_ops tc_dwc_g210_20bit_pltfm_hba_vops = {
+   .name   = "tc-dwc-g210-pltfm",
+   .link_startup_notify= ufshcd_dwc_link_startup_notify,
+   .phy_initialization = tc_dwc_g210_config_20_bit,
+};
+
+static struct ufs_hba_variant_ops tc_dwc_g210_40bit_pltfm_hba_vops = {
+   .name   = "tc-dwc-g210-pltfm",
+   .link_startup_notify= ufshcd_dwc_link_startup_notify,
+   .phy_initialization = tc_dwc_g210_config_40_bit,
+};
+
+static const struct of_device_id tc_dwc_g210_pltfm_match[] = {
+   {
+   .compatible = "snps,g210-tc-6.00-20bit",
+   .data = _dwc_g210_20bit_pltfm_hba_vops,
+   },
+   {
+   .compatible = "snps,g210-tc-6.00-40bit",
+   .data = _dwc_g210_40bit_pltfm_hba_vops,
+   },
+   { },
+};

[PATCH v15 9/9] ufs: add TC G210 pci driver

2016-05-02 Thread Joao Pinto
This patch adds a glue pci driver for the Synopsys G210 Test Chip.

Signed-off-by: Joao Pinto 
---
Changes v13->v15:
- Nothing changed (just to keep up with patch set version).
Changes v12->v13:
- Nothing changed (just to keep up with patch set version).
Changes v10->v12 (Tomas Winkler):
- custom_phy_initialization replaced by phy_initialization
Changes v10->v11 (Arnd Bergmann):
- tc_type is now initialized to TC_G210_INV
- probe function checks if the test chip version is specified
Changes v0->v10:
- This patch only appeared in v10

 drivers/scsi/ufs/Kconfig   |   9 ++
 drivers/scsi/ufs/Makefile  |   1 +
 drivers/scsi/ufs/tc-dwc-g210-pci.c | 181 +
 3 files changed, 191 insertions(+)
 create mode 100644 drivers/scsi/ufs/tc-dwc-g210-pci.c

diff --git a/drivers/scsi/ufs/Kconfig b/drivers/scsi/ufs/Kconfig
index 87f20d1..54ccff2 100644
--- a/drivers/scsi/ufs/Kconfig
+++ b/drivers/scsi/ufs/Kconfig
@@ -100,3 +100,12 @@ config SCSI_UFS_DWC_TC_PLATFORM
  Synopsys Test Chip is a PHY for prototyping purposes.
 
  If unsure, say N."
+
+config SCSI_UFS_DWC_TC_PCI
+   tristate "DesignWare pci support using a G210 Test Chip"
+   depends on SCSI_UFSHCD_PCI
+   select SCSI_UFS_DWC_TC
+   ---help---
+ Synopsys Test Chip is a PHY for prototyping purposes.
+
+ If unsure, say N."
diff --git a/drivers/scsi/ufs/Makefile b/drivers/scsi/ufs/Makefile
index a977fe0..5303d85 100644
--- a/drivers/scsi/ufs/Makefile
+++ b/drivers/scsi/ufs/Makefile
@@ -2,6 +2,7 @@
 obj-$(CONFIG_SCSI_UFS_DWC) += ufshcd-dwc.o
 obj-$(CONFIG_SCSI_UFS_DWC_TC) += tc-dwc-g210.o
 obj-$(CONFIG_SCSI_UFS_DWC_TC_PLATFORM) += tc-dwc-g210-pltfrm.o
+obj-$(CONFIG_SCSI_UFS_DWC_TC_PCI) += tc-dwc-g210-pci.o
 obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o
 obj-$(CONFIG_SCSI_UFSHCD) += ufshcd.o
 obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o
diff --git a/drivers/scsi/ufs/tc-dwc-g210-pci.c 
b/drivers/scsi/ufs/tc-dwc-g210-pci.c
new file mode 100644
index 000..0667c76
--- /dev/null
+++ b/drivers/scsi/ufs/tc-dwc-g210-pci.c
@@ -0,0 +1,181 @@
+/*
+ * Synopsys G210 Test Chip driver
+ *
+ * Copyright (C) 2015-2016 Synopsys, Inc. (www.synopsys.com)
+ *
+ * Authors: Joao Pinto 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "ufshcd.h"
+#include "ufshcd-dwc.h"
+#include "tc-dwc-g210.h"
+
+#include 
+#include 
+
+/* Test Chip type expected values */
+#define TC_G210_20BIT 20
+#define TC_G210_40BIT 40
+#define TC_G210_INV 0
+
+static int tc_type = TC_G210_INV;
+module_param(tc_type, int, 0);
+MODULE_PARM_DESC(tc_type, "Test Chip Type (20 = 20-bit, 40 = 40-bit)");
+
+static int tc_dwc_g210_pci_suspend(struct device *dev)
+{
+   return ufshcd_system_suspend(dev_get_drvdata(dev));
+}
+
+static int tc_dwc_g210_pci_resume(struct device *dev)
+{
+   return ufshcd_system_resume(dev_get_drvdata(dev));
+}
+
+static int tc_dwc_g210_pci_runtime_suspend(struct device *dev)
+{
+   return ufshcd_runtime_suspend(dev_get_drvdata(dev));
+}
+
+static int tc_dwc_g210_pci_runtime_resume(struct device *dev)
+{
+   return ufshcd_runtime_resume(dev_get_drvdata(dev));
+}
+
+static int tc_dwc_g210_pci_runtime_idle(struct device *dev)
+{
+   return ufshcd_runtime_idle(dev_get_drvdata(dev));
+}
+
+/**
+ * struct ufs_hba_dwc_vops - UFS DWC specific variant operations
+ */
+static struct ufs_hba_variant_ops tc_dwc_g210_pci_hba_vops = {
+   .name   = "tc-dwc-g210-pci",
+   .link_startup_notify= ufshcd_dwc_link_startup_notify,
+};
+
+/**
+ * tc_dwc_g210_pci_shutdown - main function to put the controller in reset 
state
+ * @pdev: pointer to PCI device handle
+ */
+static void tc_dwc_g210_pci_shutdown(struct pci_dev *pdev)
+{
+   ufshcd_shutdown((struct ufs_hba *)pci_get_drvdata(pdev));
+}
+
+/**
+ * tc_dwc_g210_pci_remove - de-allocate PCI/SCSI host and host memory space
+ * data structure memory
+ * @pdev - pointer to PCI handle
+ */
+static void tc_dwc_g210_pci_remove(struct pci_dev *pdev)
+{
+   struct ufs_hba *hba = pci_get_drvdata(pdev);
+
+   pm_runtime_forbid(>dev);
+   pm_runtime_get_noresume(>dev);
+   ufshcd_remove(hba);
+}
+
+/**
+ * tc_dwc_g210_pci_probe - probe routine of the driver
+ * @pdev: pointer to PCI device handle
+ * @id: PCI device id
+ *
+ * Returns 0 on success, non-zero value on failure
+ */
+static int
+tc_dwc_g210_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+   struct ufs_hba *hba;
+   void __iomem *mmio_base;
+   int err;
+
+   /* Check Test Chip type and set the specific setup routine */
+   if (tc_type == TC_G210_20BIT) {
+   tc_dwc_g210_pci_hba_vops.phy_initialization =
+   tc_dwc_g210_config_20_bit;
+   } 

[PATCH v15 6/9] ufs: added support for DesignWare Controller

2016-05-02 Thread Joao Pinto
This patch has the goal to add support for DesignWare UFS Controller
specific operations.

Signed-off-by: Joao Pinto 
Acked-by: Arnd Bergmann 
---
Changes v12->v15:
- Nothing changed (just to keep up with patch set version).
Changes v11->v12 (Tomas Winkler):
- custom_phy_initialization is now phy_initialization
- ufshcd_is_intr_aggr_allowed() has now a DWC tweak
- link status was now moved to a separated patch
Changes v10->v11:
- Nothing changed (just to keep up with patch set version).
Changes v9->v10 (Arnd Bergmann):
- Patch now only has DWC controller specific code
- Added custom_phy_initialization callback for PHY specific code
Changes v8->v9 (Robert Herring):
- drop 0x in the node declaration
- most specific compatibility string declared first
Changes v7->v8 (Akinobu Mita):
- DME sets were simplified for easier reading
- CLK DIV default values definitions names were changed to match the
 register's name
- New line added to dev_err and dev_info statements
Changes v6->v7 (Arnd Bergmann):
- Changed DT node name (to ufs only) and the memory address (to 0xd00)
- Removed CONFIG_PM from the PCI glue driver (pm.h already does this)
- No other changes are necessary in ufshcd.c because of the link up notify
 function usage (it is simpler now)
- Removed the PHY mentioning since the Test Chip is not a real PHY for real
 world usage, since it is a test chip for prototyping with a very specific
 usage
- Added again the Test Chip 20-bit option
Changes v5->v6:
- Patch bad format fixed
Changes v4->v5 (Akinobu Mita):
- All functions used only locally in ufshcd-dwc are now declared as static
- ufshcd_dwc_configuration() was removed in ufshcd-dwc and a notify
 function (ufshcd_dwc_link_startup_notify) was created to deal with the
 DWC specific init routines
- 20-bit RMMI option was removed from Kconfig. Now if MPHY TC is selected
 and 40-bit is not then it assumes a 20-bit config
Changes v3->v4 (Arnd Bergmann and Mark Rutland):
- SCSI_UFS_DWC_HOOKS is now silent and selected by the SCSI_UFS_DWC_PLAT
 or SCSI_UFS_DWC_PCI
- Compatibility string has the ufs core version for info purposes since
 the driver is capable of getting the controller version from its 
 registers
- Created ufs-dwc-pci glue driver with specific DWC data
- MPHY configuration remains in the ufshcd-dwc since it is unipro
 attribute writting only not following the a linux phy framework logic
Changes v2->v3 (Julian Calaby):
- Implement a common DWC code to be used by the platform and pci glue
 drivers
- Synopsys ID & Class added to the existing pci driver and specific DWC
 was also added to the pci driver
Changes v1->v2 (Akinobu Mita):
- Implement a platform driver that uses the existing UFS core driver
- Add DWC specific code to the existing UFS core driver

 MAINTAINERS   |   6 ++
 drivers/scsi/ufs/Kconfig  |   3 +
 drivers/scsi/ufs/Makefile |   1 +
 drivers/scsi/ufs/ufshcd-dwc.c | 150 ++
 drivers/scsi/ufs/ufshcd-dwc.h |  26 
 drivers/scsi/ufs/ufshcd.h |   7 ++
 drivers/scsi/ufs/ufshci-dwc.h |  36 ++
 7 files changed, 229 insertions(+)
 create mode 100644 drivers/scsi/ufs/ufshcd-dwc.c
 create mode 100644 drivers/scsi/ufs/ufshcd-dwc.h
 create mode 100644 drivers/scsi/ufs/ufshci-dwc.h

diff --git a/MAINTAINERS b/MAINTAINERS
index a87defa..08d05a3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11451,6 +11451,12 @@ S: Supported
 F: Documentation/scsi/ufs.txt
 F: drivers/scsi/ufs/
 
+UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER DWC HOOKS
+M: Joao Pinto 
+L: linux-scsi@vger.kernel.org
+S: Supported
+F: drivers/scsi/ufs/*dwc*
+
 UNSORTED BLOCK IMAGES (UBI)
 M: Artem Bityutskiy 
 M: Richard Weinberger 
diff --git a/drivers/scsi/ufs/Kconfig b/drivers/scsi/ufs/Kconfig
index 097894a..06ff8ba 100644
--- a/drivers/scsi/ufs/Kconfig
+++ b/drivers/scsi/ufs/Kconfig
@@ -84,3 +84,6 @@ config SCSI_UFS_QCOM
 
  Select this if you have UFS controller on QCOM chipset.
  If unsure, say N.
+
+config SCSI_UFS_DWC
+   bool
diff --git a/drivers/scsi/ufs/Makefile b/drivers/scsi/ufs/Makefile
index 8303bcc..ccbad53 100644
--- a/drivers/scsi/ufs/Makefile
+++ b/drivers/scsi/ufs/Makefile
@@ -1,4 +1,5 @@
 # UFSHCD makefile
+obj-$(CONFIG_SCSI_UFS_DWC) += ufshcd-dwc.o
 obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o
 obj-$(CONFIG_SCSI_UFSHCD) += ufshcd.o
 obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o
diff --git a/drivers/scsi/ufs/ufshcd-dwc.c b/drivers/scsi/ufs/ufshcd-dwc.c
new file mode 100644
index 000..9b3ca7f
--- /dev/null
+++ b/drivers/scsi/ufs/ufshcd-dwc.c
@@ -0,0 +1,150 @@
+/*
+ * UFS Host driver for Synopsys Designware Core
+ *
+ * Copyright (C) 2015-2016 Synopsys, Inc. (www.synopsys.com)
+ *
+ * Authors: Joao Pinto 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the 

[PATCH v15 3/9] ufs: added UFS 2.0 capabilities

2016-05-02 Thread Joao Pinto
Adding UFS 2.0 support to the UFS core driver.

Signed-off-by: Joao Pinto 
Acked-by: Arnd Bergmann 
Acked-by: Tomas Winkler 
---
Changes v12->v15:
- Nothing changed (just to keep up with patch set version).
Changes v11->v12 (Tomas Winkler):
- devicetree binding tweak was moved to a separated patch
- unipro tweaks were moved to a separated patch
- ufshcd_compose_upiu was decomposed in 2 functions
- UTP_CMD_TYPE_UFS_STORAGE is now 0x1 (previously was 0x11)
Changes v8->v11:
- Nothing changed (just to keep up with patch set version).
Changes v7->v8:
- Added "jedec, ufs-2.0" to the ufschd-platform compatibility strings
Changes v0->v7:
- Nothing changed (just to keep up with patch set version).

 drivers/scsi/ufs/ufshcd.c | 89 +--
 drivers/scsi/ufs/ufshci.h |  5 +++
 2 files changed, 53 insertions(+), 41 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index f8fa72c..891c4fd 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -1173,7 +1173,7 @@ static void ufshcd_disable_intr(struct ufs_hba *hba, u32 
intrs)
  * @cmd_dir: requests data direction
  */
 static void ufshcd_prepare_req_desc_hdr(struct ufshcd_lrb *lrbp,
-   u32 *upiu_flags, enum dma_data_direction cmd_dir)
+   u32 *upiu_flags, enum dma_data_direction cmd_dir)
 {
struct utp_transfer_req_desc *req_desc = lrbp->utr_descriptor_ptr;
u32 data_direction;
@@ -1299,47 +1299,55 @@ static inline void ufshcd_prepare_utp_nop_upiu(struct 
ufshcd_lrb *lrbp)
 }
 
 /**
- * ufshcd_compose_upiu - form UFS Protocol Information Unit(UPIU)
+ * ufshcd_comp_devman_upiu - UFS Protocol Information Unit(UPIU)
+ *  for Device Management Purposes
  * @hba - per adapter instance
  * @lrb - pointer to local reference block
  */
-static int ufshcd_compose_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
+static int ufshcd_comp_devman_upiu(struct ufs_hba *hba, struct ufshcd_lrb 
*lrbp)
 {
u32 upiu_flags;
int ret = 0;
 
-   switch (lrbp->command_type) {
-   case UTP_CMD_TYPE_SCSI:
-   if (likely(lrbp->cmd)) {
-   ufshcd_prepare_req_desc_hdr(lrbp, _flags,
-   lrbp->cmd->sc_data_direction);
-   ufshcd_prepare_utp_scsi_cmd_upiu(lrbp, upiu_flags);
-   } else {
-   ret = -EINVAL;
-   }
-   break;
-   case UTP_CMD_TYPE_DEV_MANAGE:
-   ufshcd_prepare_req_desc_hdr(lrbp, _flags, DMA_NONE);
-   if (hba->dev_cmd.type == DEV_CMD_TYPE_QUERY)
-   ufshcd_prepare_utp_query_req_upiu(
-   hba, lrbp, upiu_flags);
-   else if (hba->dev_cmd.type == DEV_CMD_TYPE_NOP)
-   ufshcd_prepare_utp_nop_upiu(lrbp);
-   else
-   ret = -EINVAL;
-   break;
-   case UTP_CMD_TYPE_UFS:
-   /* For UFS native command implementation */
-   ret = -ENOTSUPP;
-   dev_err(hba->dev, "%s: UFS native command are not supported\n",
-   __func__);
-   break;
-   default:
-   ret = -ENOTSUPP;
-   dev_err(hba->dev, "%s: unknown command type: 0x%x\n",
-   __func__, lrbp->command_type);
-   break;
-   } /* end of switch */
+   if (hba->ufs_version == UFSHCI_VERSION_20)
+   lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE;
+   else
+   lrbp->command_type = UTP_CMD_TYPE_DEV_MANAGE;
+
+   ufshcd_prepare_req_desc_hdr(lrbp, _flags, DMA_NONE);
+   if (hba->dev_cmd.type == DEV_CMD_TYPE_QUERY)
+   ufshcd_prepare_utp_query_req_upiu(hba, lrbp, upiu_flags);
+   else if (hba->dev_cmd.type == DEV_CMD_TYPE_NOP)
+   ufshcd_prepare_utp_nop_upiu(lrbp);
+   else
+   ret = -EINVAL;
+
+   return ret;
+}
+
+/**
+ * ufshcd_comp_scsi_upiu - UFS Protocol Information Unit(UPIU)
+ *for SCSI Purposes
+ * @hba - per adapter instance
+ * @lrb - pointer to local reference block
+ */
+static int ufshcd_comp_scsi_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
+{
+   u32 upiu_flags;
+   int ret = 0;
+
+   if (hba->ufs_version == UFSHCI_VERSION_20)
+   lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE;
+   else
+   lrbp->command_type = UTP_CMD_TYPE_SCSI;
+
+   if (likely(lrbp->cmd)) {
+   ufshcd_prepare_req_desc_hdr(lrbp, _flags,
+   lrbp->cmd->sc_data_direction);
+   ufshcd_prepare_utp_scsi_cmd_upiu(lrbp, upiu_flags);
+   } else {
+   ret = -EINVAL;
+   }
 
return ret;
 }
@@ -1451,10 +1459,9 @@ static int ufshcd_queuecommand(struct 

Re: [PATCHv2]sd: Don't treat succeeded SYNC as error

2016-05-02 Thread James Bottomley
On Mon, 2016-05-02 at 12:05 +0200, Hannes Reinecke wrote:
> On 04/29/2016 02:49 PM, Jinpu Wang wrote:
> > Hi, all
> > 
> > We hit IO error on fsync, it turns out was because sd treat
> > succeeded
> > SYNC as error. From what I checked in SBC spec there is no
> > indication
> > we should fail IO in this case, so we create this patch.
> > 
> > 
> > Best Regards,
> > 
> > Jack Wang
> > 
> > v2:
> > No change on patch itself, only resend in body as suggested by
> > Bart,
> > still keep the attachment in case mail client break the format.
> > 
> > From 5d1f72d9643ce61cd9f3d312377378c43f171d0c Mon Sep 17 00:00:00
> > 2001
> > From: Jack Wang 
> > Date: Mon, 25 Apr 2016 12:05:22 +0200
> > Subject: [PATCH] sd: Don't treat succeeded SYNC as error
> > 
> > We hit IO error in our production on multipath devices during
> > resize
> > device on target side, the problem turns out sd driver passes up as
> > IO
> > error when sense data is UNIT_ATTENTION and ASC && ASCQ indicate
> > Capacity data has changed, even storage side sync the data
> > properly.
> > 
> > In order to fix this check in sd_done, report success if condition
> > matches.
> > 
> > Sebastian Parschauer report/analyze the bug here:
> > https://sourceforge.net/p/scst/mailman/message/34953416/
> > 
> > Signed-off-by: Sebastian Parschauer 
> > Signed-off-by: Jack Wang 
> > ---
> >  drivers/scsi/sd.c | 13 +
> >  1 file changed, 13 insertions(+)
> > 
> Well.
> Is there anything which guarantees us that 'capacity data has
> changed' will be the only sense code which we'll be seeing as a
> response to SYNCHRONIZE CACHE?
> I sincerely doubt so.
> So why don't you fall back to the default action (ie retry the
> command) whenever you hit an UNIT ATTENTION?
> This way we would cove any resulting sense code, _and_ would get rid
> of the rather ugly special case here.

Actually, why are we getting here at all?  should we be eating this
unit attention once we've reported it in scsi_check_sense()?

I also don't quite understand why the normal retry mechanism in
scsi_io_completion() (called after drv->done()) isn't handling this. 
 We set retries on a flush command and we give sd_sync_cache three
goes.  Any one of those should also cause the CC/UA to be ignored.

James


--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv2]sd: Don't treat succeeded SYNC as error

2016-05-02 Thread Hannes Reinecke
On 04/29/2016 02:49 PM, Jinpu Wang wrote:
> Hi, all
> 
> We hit IO error on fsync, it turns out was because sd treat succeeded
> SYNC as error. From what I checked in SBC spec there is no indication
> we should fail IO in this case, so we create this patch.
> 
> 
> Best Regards,
> 
> Jack Wang
> 
> v2:
> No change on patch itself, only resend in body as suggested by Bart,
> still keep the attachment in case mail client break the format.
> 
> From 5d1f72d9643ce61cd9f3d312377378c43f171d0c Mon Sep 17 00:00:00 2001
> From: Jack Wang 
> Date: Mon, 25 Apr 2016 12:05:22 +0200
> Subject: [PATCH] sd: Don't treat succeeded SYNC as error
> 
> We hit IO error in our production on multipath devices during resize
> device on target side, the problem turns out sd driver passes up as IO
> error when sense data is UNIT_ATTENTION and ASC && ASCQ indicate
> Capacity data has changed, even storage side sync the data properly.
> 
> In order to fix this check in sd_done, report success if condition
> matches.
> 
> Sebastian Parschauer report/analyze the bug here:
> https://sourceforge.net/p/scst/mailman/message/34953416/
> 
> Signed-off-by: Sebastian Parschauer 
> Signed-off-by: Jack Wang 
> ---
>  drivers/scsi/sd.c | 13 +
>  1 file changed, 13 insertions(+)
> 
Well.
Is there anything which guarantees us that 'capacity data has
changed' will be the only sense code which we'll be seeing as a
response to SYNCHRONIZE CACHE?
I sincerely doubt so.
So why don't you fall back to the default action (ie retry the
command) whenever you hit an UNIT ATTENTION?
This way we would cove any resulting sense code, _and_ would get rid
of the rather ugly special case here.

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: UFS patchset

2016-05-02 Thread Joao Pinto
Hi Martin!

On 4/30/2016 1:24 AM, Martin K. Petersen wrote:
>> "Martin" == Martin K Petersen  writes:
> 
> Joao,
> 
> Martin> In a previous email you said you had sent v14 to
> Martin> linux-scsi. However, I don't see neither v14, nor v13 in
> Martin> patchworks. The latest I have is v12 and it does not apply to
> Martin> 4.7/scsi-queue.
> 
> I found v14 in my mailbox. Not sure why it's not in patchworks.
> 
> In any case: It still doesn't apply to 4.7/scsi-queue and there are
> several checkpatch warnings throughout the series. Please fix.

The patch were made based on a 4.7-queue from about 1 or 2 months. I will do the
needed fixes and send you the v15.

> 
> Also make sure to prefix your patch subject lines with "ufs:" so it's
> easy to identify which subsystem they go into.
> 
> Thanks!
> 

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2.5 6/6] scsi_debug: use locally assigned naa

2016-05-02 Thread Hannes Reinecke
On 05/01/2016 04:44 AM, Douglas Gilbert wrote:
> For reported SAS addresses replace fake IEEE registered NAAs (5)
> with locally assigned NAAs (3).
> 
> Signed-off-by: Douglas Gilbert 
> ---
>  drivers/scsi/scsi_debug.c | 35 ++-
>  1 file changed, 18 insertions(+), 17 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2.5 5/6] scsi_debug: uuid for lu name

2016-05-02 Thread Hannes Reinecke
On 05/01/2016 04:44 AM, Douglas Gilbert wrote:
> Permit changing of a LU name from a (fake) IEEE registered NAA (5)
> to a locally assigned UUID. Using a UUID (RFC 4122) for a SCSI
> designation descriptor (e.g. a LU name) was added in spc5r08.pdf
> (a draft INCITS standard) on 25 January 2016. Add parameter
> uuid_ctl to use a separate UUID for each LU (storage device) name.
> Additional option for all LU names to have the same UUID (since
> their storage is shared). Previous action of using NAA identifier
> for LU name remains the default.
> 
> Signed-off-by: Douglas Gilbert 
> ---
>  drivers/scsi/scsi_debug.c | 61 
> +++
>  1 file changed, 51 insertions(+), 10 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2.5 4/6] scsi_debug: vpd and mode page work

2016-05-02 Thread Hannes Reinecke
On 05/01/2016 04:44 AM, Douglas Gilbert wrote:
> Cleanup some mode and vpd pages. Stop reporting SBC (disk) pages
> when peripheral type is something else (e.g. tape). Update
> version descriptors. Expand LBPRZ flag handling.
> 
> Signed-off-by: Douglas Gilbert 
> ---
>  drivers/scsi/scsi_debug.c | 187 
> ++
>  1 file changed, 108 insertions(+), 79 deletions(-)
> 
> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index 0932111..814067d 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -125,7 +125,7 @@ static const char *sdebug_version_date = "20160430";
>  #define DEF_PHYSBLK_EXP 0
>  #define DEF_PTYPE   TYPE_DISK
>  #define DEF_REMOVABLE false
> -#define DEF_SCSI_LEVEL   6/* INQUIRY, byte2 [6->SPC-4] */
> +#define DEF_SCSI_LEVEL   7/* INQUIRY, byte2 [6->SPC-4; 7->SPC-5] */
>  #define DEF_SECTOR_SIZE 512
>  #define DEF_UNMAP_ALIGNMENT 0
>  #define DEF_UNMAP_GRANULARITY 1
> @@ -657,7 +657,11 @@ static const int device_qfull_result =
>   (DID_OK << 16) | (COMMAND_COMPLETE << 8) | SAM_STAT_TASK_SET_FULL;
>  
>  
> -static inline unsigned int scsi_debug_lbp(void)
> +/* Only do the extra work involved in logical block provisioning if one or
> + * more of the lbpu, lbpws or lbpws10 parameters are given and we are doing
> + * real reads and writes (i.e. not skipping them for speed).
> + */
> +static inline bool scsi_debug_lbp(void)
>  {
>   return 0 == sdebug_fake_rw &&
>   (sdebug_lbpu || sdebug_lbpws || sdebug_lbpws10);
> @@ -918,10 +922,10 @@ static const u64 naa5_comp_b = 0x5330ULL;
>  static const u64 naa5_comp_c = 0x5110ULL;
>  
>  /* Device identification VPD page. Returns number of bytes placed in arr */
> -static int inquiry_evpd_83(unsigned char * arr, int port_group_id,
> -int target_dev_id, int dev_id_num,
> -const char * dev_id_str,
> -int dev_id_str_len)
> +static int inquiry_vpd_83(unsigned char *arr, int port_group_id,
> +   int target_dev_id, int dev_id_num,
> +   const char *dev_id_str,
> +   int dev_id_str_len)
>  {
>   int num, port_a;
>   char b[32];
> @@ -1000,14 +1004,14 @@ static unsigned char vpd84_data[] = {
>  };
>  
>  /*  Software interface identification VPD page */
> -static int inquiry_evpd_84(unsigned char * arr)
> +static int inquiry_vpd_84(unsigned char *arr)
>  {
>   memcpy(arr, vpd84_data, sizeof(vpd84_data));
>   return sizeof(vpd84_data);
>  }
>  
>  /* Management network addresses VPD page */
> -static int inquiry_evpd_85(unsigned char * arr)
> +static int inquiry_vpd_85(unsigned char *arr)
>  {
>   int num = 0;
>   const char * na1 = "https://www.kernel.org/config;;
> @@ -1042,7 +1046,7 @@ static int inquiry_evpd_85(unsigned char * arr)
>  }
>  
>  /* SCSI ports VPD page */
> -static int inquiry_evpd_88(unsigned char * arr, int target_dev_id)
> +static int inquiry_vpd_88(unsigned char *arr, int target_dev_id)
>  {
>   int num = 0;
>   int port_a, port_b;
> @@ -1129,7 +1133,7 @@ static unsigned char vpd89_data[] = {
>  };
>  
>  /* ATA Information VPD page */
> -static int inquiry_evpd_89(unsigned char * arr)
> +static int inquiry_vpd_89(unsigned char *arr)
>  {
>   memcpy(arr, vpd89_data, sizeof(vpd89_data));
>   return sizeof(vpd89_data);
> @@ -1144,7 +1148,7 @@ static unsigned char vpdb0_data[] = {
>  };
>  
>  /* Block limits VPD page (SBC-3) */
> -static int inquiry_evpd_b0(unsigned char * arr)
> +static int inquiry_vpd_b0(unsigned char *arr)
>  {
>   unsigned int gran;
>  
> @@ -1187,7 +1191,7 @@ static int inquiry_evpd_b0(unsigned char * arr)
>  }
>  
>  /* Block device characteristics VPD page (SBC-3) */
> -static int inquiry_evpd_b1(unsigned char *arr)
> +static int inquiry_vpd_b1(unsigned char *arr)
>  {
>   memset(arr, 0, 0x3c);
>   arr[0] = 0;
> @@ -1198,24 +1202,22 @@ static int inquiry_evpd_b1(unsigned char *arr)
>   return 0x3c;
>  }
>  
> -/* Logical block provisioning VPD page (SBC-3) */
> -static int inquiry_evpd_b2(unsigned char *arr)
> +/* Logical block provisioning VPD page (SBC-4) */
> +static int inquiry_vpd_b2(unsigned char *arr)
>  {
>   memset(arr, 0, 0x4);
>   arr[0] = 0; /* threshold exponent */
> -
>   if (sdebug_lbpu)
>   arr[1] = 1 << 7;
> -
>   if (sdebug_lbpws)
>   arr[1] |= 1 << 6;
> -
>   if (sdebug_lbpws10)
>   arr[1] |= 1 << 5;
> -
> - if (sdebug_lbprz)
> - arr[1] |= 1 << 2;
> -
> + if (sdebug_lbprz && scsi_debug_lbp())
> + arr[1] |= (sdebug_lbprz & 0x7) << 2;  /* sbc4r07 and later */
> + /* anc_sup=0; dp=0 (no provisioning group descriptor) */
> + /* minimum_percentage=0; provisioning_type=0 (unknown) */
> + /* threshold_percentage=0 */
>   return 0x4;
>  }
>  
> 

Re: [PATCH v2.5 3/6] scsi_debug: add multiple queue support

2016-05-02 Thread Hannes Reinecke
On 05/01/2016 04:44 AM, Douglas Gilbert wrote:
> Add submit_queue parameter (minimum and default: 1; maximum:
> nr_cpu_ids) that controls how many queues are built, each with
> their own lock and in_use bit vector. Add statistics parameter
> which is default on.
> 
> Signed-off-by: Douglas Gilbert 
> ---
>  drivers/scsi/scsi_debug.c | 680 
> +-
>  1 file changed, 426 insertions(+), 254 deletions(-)
> 
Two general questions for this:

- Why do you get rid of the embedded command payload?
  Where's the benefit of allocating the commands yourself?
- Wouldn't it be better to move to a per-cpu structure per queue?
  Each queue will be tacked to a CPU anyway, so you could be using
  per-cpu structures. Otherwise you'll run into synchronization
  issues, and any performance gain you might get from scsi-mq is
  lost as you to synchronize on the lower level.

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch] [SCSI] aic94xx: silence a static checker warning

2016-05-02 Thread Dan Carpenter
"ddb" is a number between 0-64.  It can't ever be >= 0x.  But the
static checker complains that since we're capping the upper bound, we
may as well cap the lower bound and disallow negatives as well.

Signed-off-by: Dan Carpenter 

diff --git a/drivers/scsi/aic94xx/aic94xx_dev.c 
b/drivers/scsi/aic94xx/aic94xx_dev.c
index 3307238..84eba3e 100644
--- a/drivers/scsi/aic94xx/aic94xx_dev.c
+++ b/drivers/scsi/aic94xx/aic94xx_dev.c
@@ -73,7 +73,7 @@ out:
 
 static void asd_free_ddb(struct asd_ha_struct *asd_ha, int ddb)
 {
-   if (!ddb || ddb >= 0x)
+   if (ddb <= 0 || ddb >= 0x)
return;
asd_ddbsite_write_byte(asd_ha, ddb, DDB_TYPE, DDB_TYPE_UNUSED);
CLEAR_DDB(ddb, asd_ha);
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH v2.5 2/6] scsi_debug: rework resp_report_luns

2016-05-02 Thread Winkler, Tomas


> -Original Message-
> From: Hannes Reinecke [mailto:h...@suse.de]
> Sent: Monday, May 02, 2016 11:25
> To: Douglas Gilbert ; linux-scsi@vger.kernel.org
> Cc: martin.peter...@oracle.com; Winkler, Tomas
> ; emi...@redhat.com;
> bart.vanass...@sandisk.com
> Subject: Re: [PATCH v2.5 2/6] scsi_debug: rework resp_report_luns
> 
> On 05/01/2016 04:44 AM, Douglas Gilbert wrote:
> > Based on "[PATH V2] scsi_debug: rework resp_report_luns" patch sent by
> > Tomas Winkler on Thursday, 26 Feb 2015. His notes:
> >   1. Remove duplicated boundary checks which simplify the fill-in
> >  loop
> >   2. Use more of scsi generic API
> > Replace fixed length response array a with heap allocation allowing up
> > to 256 normal LUNs per target.
> >
> > Signed-off-by: Douglas Gilbert 
> > ---
> >  drivers/scsi/scsi_debug.c | 135
> > +-
> >  1 file changed, 87 insertions(+), 48 deletions(-)
> >
> Reviewed-by: Hannes Reinecke 
Ack again 

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2.5 1/6] scsi_debug: use pdt constants

2016-05-02 Thread Hannes Reinecke
On 05/01/2016 04:44 AM, Douglas Gilbert wrote:
> Use TYPE_* constants for SCSI peripheral device types instead
> of numbers. Further cleanups requested by checkpatch.pl .
> 
> Signed-off-by: Douglas Gilbert 
> ---
>  drivers/scsi/scsi_debug.c | 86 
> +--
>  1 file changed, 45 insertions(+), 41 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2.5 2/6] scsi_debug: rework resp_report_luns

2016-05-02 Thread Hannes Reinecke
On 05/01/2016 04:44 AM, Douglas Gilbert wrote:
> Based on "[PATH V2] scsi_debug: rework resp_report_luns" patch
> sent by Tomas Winkler on Thursday, 26 Feb 2015. His notes:
>   1. Remove duplicated boundary checks which simplify the fill-in
>  loop
>   2. Use more of scsi generic API
> Replace fixed length response array a with heap allocation
> allowing up to 256 normal LUNs per target.
> 
> Signed-off-by: Douglas Gilbert 
> ---
>  drivers/scsi/scsi_debug.c | 135 
> +-
>  1 file changed, 87 insertions(+), 48 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html