Re: [PATCHv2 0/5] SCSI EH cleanup

2017-02-23 Thread Hannes Reinecke
On 02/24/2017 05:01 AM, Bart Van Assche wrote:
> On Wed, 2017-02-22 at 17:07 +0100, Hannes Reinecke wrote:
>> Primary goal is to make asynchronous aborts mandatory; there hasn't
>> been a single report so far where asynchronous abort won't work, so
>> the 'no_async_abort' flag has never been used and will be removed
>> with this patchset.
> 
> Hello Hannes,
> 
> There is a problem with asynchronous aborts. Some SCSI drivers, e.g. ib_srp,
> support fast error recovery by performing a transport layer reconnect without
> reporting this event as a failure to the SCSI core. While such a reconnect is
> ongoing it is important that no attempt is made to use the data structures
> that represent the connection. Hence the scsi_target_block() call in
> srp_reconnect_rport(). This blocks most .queuecommand() calls except those
> that originate from the SCSI EH. Hence the if (current == shost->ehandler)
> mutex_lock(&rport->mutex) code in srp_queuecommand(). Asynchronous aborts
> break this code because the asynchronous abort code submits an abort from
> another context than the SCSI EH thread. I know that this way of detecting
> the SCSI EH context is not an optimal solution. A few years ago I have tried
> to modify the SCSI EH such that reconnects and .queuecommand() calls could
> be serialized but James was not interested in such patches at that time.
> 
Don't think that's much of an issue.
scsi_abort_command() (ie the call which triggers async aborts) is only
called if the .eh_timed_out() callback returns BLK_EH_NOT_HANDLED.
So during reconnects we will not schedule any calls to async aborts.
We _might_ have scheduled an async abort prior to a call to
srp_reconnect_rport(), but that would be equivalent with calling
srp_reconnect_rport() with commands still in flight.
Is that even possible?
If so, how do you handle these commands after reconnect returns?
Any I_T_L nexus will be gone from the target, right?

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)


Re: [PATCHv2 0/5] SCSI EH cleanup

2017-02-23 Thread Bart Van Assche
On Wed, 2017-02-22 at 17:07 +0100, Hannes Reinecke wrote:
> Primary goal is to make asynchronous aborts mandatory; there hasn't
> been a single report so far where asynchronous abort won't work, so
> the 'no_async_abort' flag has never been used and will be removed
> with this patchset.

Hello Hannes,

There is a problem with asynchronous aborts. Some SCSI drivers, e.g. ib_srp,
support fast error recovery by performing a transport layer reconnect without
reporting this event as a failure to the SCSI core. While such a reconnect is
ongoing it is important that no attempt is made to use the data structures
that represent the connection. Hence the scsi_target_block() call in
srp_reconnect_rport(). This blocks most .queuecommand() calls except those
that originate from the SCSI EH. Hence the if (current == shost->ehandler)
mutex_lock(&rport->mutex) code in srp_queuecommand(). Asynchronous aborts
break this code because the asynchronous abort code submits an abort from
another context than the SCSI EH thread. I know that this way of detecting
the SCSI EH context is not an optimal solution. A few years ago I have tried
to modify the SCSI EH such that reconnects and .queuecommand() calls could
be serialized but James was not interested in such patches at that time.

Bart.

Re: [PATCH] target/user: Add daynmic growing data area featuresupport

2017-02-23 Thread Xiubo Li



When N is bigger, the ratio will be smaller. If N >= 1, the ratio
will be [15/1024, 4/1024), for this the ratio 15 : 1024 will be
enough. But maybe some iscsi cmds has no datas, N == 0. So the ratio
should be bigger.

For now we will increase the data area size to 1G, and the cmd area
size to 128M. The tcmu-runner should mmap() about (128M + 1G) when
running and the TCMU will dynamically grows the data area from 0 to
max 1G size.

Cool. This is a good approach for an initial patch but this raises
concerns about efficiently managing kernel memory usage -- the data area
grows but never shrinks, and total possible usage increases per
backstore. (What if there are 1000?) Any ideas how we could also improve
these aspects of the design? (Global TCMU data area usage limit?)

Two ways in my mind:

The first:
How about by setting a threshold cmd(SHRINK cmd), something likes
the PAD cmd, to tell the userspace runner try to shrink the memories?

When the runner get the SHRINK cmd, it will try to remmap uio0's ring
buffer(?). Then the kernel will get chance to shrink the memories

The second:
Try to extern the data area by using /dev/uio1, we could remmap the
uio1 device when need, so it will be easy to get a chance to shrink the
memories in uio1.

Maybe these are a little ugly, are there other more effective ways ?

Thanks,

BRs
Xiubo



The cmd area memory will be allocated through vmalloc(), and the data
area's blocks will be allocated individually later when needed.








Re: [PATCH] libiscsi: add lock around task lists to fix list corruption regression

2017-02-23 Thread Chris Leech
Yikes, my git-send-email settings suppressed the important CCs.  Sorry!

Guilherme and Ilkka, can you comment about your testing results or review 
please?

- Chris Leech

- Original Message -
> There's a rather long standing regression from commit
> 659743b [SCSI] libiscsi: Reduce locking contention in fast path
> 
> Depending on iSCSI target behavior, it's possible to hit the case in
> iscsi_complete_task where the task is still on a pending list
> (!list_empty(&task->running)).  When that happens the task is removed
> from the list while holding the session back_lock, but other task list
> modification occur under the frwd_lock.  That leads to linked list
> corruption and eventually a panicked system.
> 
> Rather than back out the session lock split entirely, in order to try
> and keep some of the performance gains this patch adds another lock to
> maintain the task lists integrity.
> 
> Major enterprise supported kernels have been backing out the lock split
> for while now, thanks to the efforts at IBM where a lab setup has the
> most reliable reproducer I've seen on this issue.  This patch has been
> tested there successfully.
> 
> Signed-off-by: Chris Leech 
> ---
>  drivers/scsi/libiscsi.c | 26 +-
>  include/scsi/libiscsi.h |  1 +
>  2 files changed, 26 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
> index 834d121..acb5ef3 100644
> --- a/drivers/scsi/libiscsi.c
> +++ b/drivers/scsi/libiscsi.c
> @@ -560,8 +560,12 @@ static void iscsi_complete_task(struct iscsi_task *task,
> int state)
>   WARN_ON_ONCE(task->state == ISCSI_TASK_FREE);
>   task->state = state;
>  
> - if (!list_empty(&task->running))
> + spin_lock_bh(&conn->taskqueuelock);
> + if (!list_empty(&task->running)) {
> + WARN_ONCE(1, "iscsi_complete_task while task on list");
>   list_del_init(&task->running);
> + }
> + spin_unlock_bh(&conn->taskqueuelock);
>  
>   if (conn->task == task)
>   conn->task = NULL;
> @@ -783,7 +787,9 @@ __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct
> iscsi_hdr *hdr,
>   if (session->tt->xmit_task(task))
>   goto free_task;
>   } else {
> + spin_lock_bh(&conn->taskqueuelock);
>   list_add_tail(&task->running, &conn->mgmtqueue);
> + spin_unlock_bh(&conn->taskqueuelock);
>   iscsi_conn_queue_work(conn);
>   }
>  
> @@ -1474,8 +1480,10 @@ void iscsi_requeue_task(struct iscsi_task *task)
>* this may be on the requeue list already if the xmit_task callout
>* is handling the r2ts while we are adding new ones
>*/
> + spin_lock_bh(&conn->taskqueuelock);
>   if (list_empty(&task->running))
>   list_add_tail(&task->running, &conn->requeue);
> + spin_unlock_bh(&conn->taskqueuelock);
>   iscsi_conn_queue_work(conn);
>  }
>  EXPORT_SYMBOL_GPL(iscsi_requeue_task);
> @@ -1512,22 +1520,26 @@ static int iscsi_data_xmit(struct iscsi_conn *conn)
>* only have one nop-out as a ping from us and targets should not
>* overflow us with nop-ins
>*/
> + spin_lock_bh(&conn->taskqueuelock);
>  check_mgmt:
>   while (!list_empty(&conn->mgmtqueue)) {
>   conn->task = list_entry(conn->mgmtqueue.next,
>struct iscsi_task, running);
>   list_del_init(&conn->task->running);
> + spin_unlock_bh(&conn->taskqueuelock);
>   if (iscsi_prep_mgmt_task(conn, conn->task)) {
>   /* regular RX path uses back_lock */
>   spin_lock_bh(&conn->session->back_lock);
>   __iscsi_put_task(conn->task);
>   spin_unlock_bh(&conn->session->back_lock);
>   conn->task = NULL;
> + spin_lock_bh(&conn->taskqueuelock);
>   continue;
>   }
>   rc = iscsi_xmit_task(conn);
>   if (rc)
>   goto done;
> + spin_lock_bh(&conn->taskqueuelock);
>   }
>  
>   /* process pending command queue */
> @@ -1535,19 +1547,24 @@ static int iscsi_data_xmit(struct iscsi_conn *conn)
>   conn->task = list_entry(conn->cmdqueue.next, struct iscsi_task,
>   running);
>   list_del_init(&conn->task->running);
> + spin_unlock_bh(&conn->taskqueuelock);
>   if (conn->session->state == ISCSI_STATE_LOGGING_OUT) {
>   fail_scsi_task(conn->task, DID_IMM_RETRY);
> + spin_lock_bh(&conn->taskqueuelock);
>   continue;
>   }
>   rc = iscsi_prep_scsi_cmd_pdu(conn->task);
>   if (rc) {
>   if (rc == -ENOMEM || rc == -EACCES) {
> + spin_lock_bh(&conn->taskqueuelock);
> 

Re: [PATCH] scsi/mac_scsi: Fix MAC_SCSI=m option when SCSI=m

2017-02-23 Thread Martin K. Petersen
> "Finn" == Finn Thain  writes:

Finn> The mac_scsi driver still gets disabled when SCSI=m. This should
Finn> have been fixed back when I enabled the tristate but I didn't see
Finn> the bug.

Applied to 4.11/scsi-fixes.

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] libiscsi: add lock around task lists to fix list corruption regression

2017-02-23 Thread Martin K. Petersen
> "Chris" == Chris Leech  writes:

Chris> There's a rather long standing regression from commit 659743b
Chris> [SCSI] libiscsi: Reduce locking contention in fast path

Chris> Depending on iSCSI target behavior, it's possible to hit the case
Chris> in iscsi_complete_task where the task is still on a pending list
Chris> (!list_empty(&task->running)).  When that happens the task is
Chris> removed from the list while holding the session back_lock, but
Chris> other task list modification occur under the frwd_lock.  That
Chris> leads to linked list corruption and eventually a panicked system.

Chris> Rather than back out the session lock split entirely, in order to
Chris> try and keep some of the performance gains this patch adds
Chris> another lock to maintain the task lists integrity.

Chris> Major enterprise supported kernels have been backing out the lock
Chris> split for while now, thanks to the efforts at IBM where a lab
Chris> setup has the most reliable reproducer I've seen on this issue.
Chris> This patch has been tested there successfully.

Reviews, please!

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] cciss: correct check map error.

2017-02-23 Thread Martin K. Petersen
> "Don" == Don Brace  writes:

Don> remove device driver failed to check map error messages

Applied to 4.11/scsi-fixes.

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] qla2xxx: fix spelling mistake: "seperator" -> "separator"

2017-02-23 Thread Martin K. Petersen
> "Colin" == Colin King  writes:

Colin> trivial fix to spelling mistake in pr_err message

Applied to 4.11/scsi-fixes.

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCHv4 01/12] mpt3sas: switch to pci_alloc_irq_vectors

2017-02-23 Thread Martin K. Petersen
> "Hannes" == Hannes Reinecke  writes:

Hannes> Cleanup the MSI-X handling allowing us to use the PCI-layer
Hannes> provided vector allocation.

Applied to 4.11/scsi-fixes.

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] aacraid: Fixed expander hotplug for SMART family

2017-02-23 Thread Martin K. Petersen
> "Raghava" == Raghava Aditya Renukunta 
>  writes:

Raghava> Current driver Hotplug processing code skips over Enclosure
Raghava> channel, therefore any addition/removal of expander enclosure
Raghava> is not processed.  Additionally device addition code relies on
Raghava> older device type, which prevents the hotplug of adapter
Raghava> expanders.

Raghava> Fixed by removing code that skips over Enclosure channels and
Raghava> using the latest device type for addition or removal or
Raghava> enclosure expanders.

Applied to 4.11/scsi-fixes.

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] qedf: fixup compilation warning about atomic_t usage

2017-02-23 Thread Martin K. Petersen
> "Chad" == Dupuis, Chad  writes:

Chad> The driver didn't follow the atomic_t vs refcount_t change, and
Chad> anyway one should be using kref_read() instead of accessing the
Chad> counter inside an kref.

Applied to 4.11/scsi-fixes.

Thanks!

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: sense handling improvements, part 2

2017-02-23 Thread Martin K. Petersen
> "Christoph" == Christoph Hellwig  writes:

Christoph> No real changes, but I did an explicit rebase against the
Christoph> 4.11/scsi-fixes branch.

Applied to 4.11/scsi-fixes.

-- 
Martin K. Petersen  Oracle Linux Engineering


RE: [PATCH] aacraid: Fixed expander hotplug for SMART family

2017-02-23 Thread Dave Carroll
> -Original Message-
> From: Raghava Aditya Renukunta
> [mailto:raghavaaditya.renuku...@microsemi.com]
> Sent: Wednesday, February 22, 2017 8:23 AM
> To: j...@linux.vnet.ibm.com; martin.peter...@oracle.com; linux-
> s...@vger.kernel.org
> Cc: Dave Carroll; Gana Sridaran; Scott Benesh
> Subject: [PATCH] aacraid: Fixed expander hotplug for SMART family
> 
> Current driver Hotplug processing code skips over Enclosure channel,
> therefore any addition/removal of expander enclosure is not processed.
> Additionally  device addition code relies on older device type, which
> prevents the hotplug of adapter expanders.
> 
> Fixed by removing code that skips over Enclosure channels and using the
> latest device type for addition or removal or enclosure expanders.
> 
> Fixes: 6223a39fe6fbbeef (scsi: aacraid: Added support for hotplug)
> Signed-off-by: Raghava Aditya Renukunta
> 
> ---
>  drivers/scsi/aacraid/commsup.c | 5 +
>  1 file changed, 1 insertion(+), 4 deletions(-)

Reviewed-by: Dave Carroll 



RE: [PATCH] qla2xxx: fix spelling mistake: "seperator" -> "separator"

2017-02-23 Thread Madhani, Himanshu


> -Original Message-
> From: Colin King [mailto:colin.k...@canonical.com]
> Sent: Thursday, February 23, 2017 2:57 AM
> To: qla2xxx-upstr...@qlogic.com; James E . J . Bottomley
> ; Martin K . Petersen
> ; linux-scsi@vger.kernel.org
> Cc: linux-ker...@vger.kernel.org
> Subject: [PATCH] qla2xxx: fix spelling mistake: "seperator" -> "separator"
> 
> From: Colin Ian King 
> 
> trivial fix to spelling mistake in pr_err message
> 
> Signed-off-by: Colin Ian King 
> ---
>  drivers/scsi/qla2xxx/tcm_qla2xxx.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
> b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
> index c2f8c35..8e8ab0f 100644
> --- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
> +++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
> @@ -1792,7 +1792,7 @@ static struct se_wwn
> *tcm_qla2xxx_npiv_make_lport(
> 
>   p = strchr(tmp, '@');
>   if (!p) {
> - pr_err("Unable to locate NPIV '@' seperator\n");
> + pr_err("Unable to locate NPIV '@' separator\n");
>   return ERR_PTR(-EINVAL);
>   }
>   *p++ = '\0';
> --
> 2.10.2

Looks Good

Acked-by: Himanshu Madhani 


RE:

2017-02-23 Thread Qin's Yanjun

How are you today and your family? I require your attention and honest
co-operation about some issues which i will really want to discuss with you
which.  Looking forward to read from you soon.  

Qin's


__

Sky Silk, http://aknet.kz



Re: [PATCH 00/35] treewide trivial patches converting pr_warning to pr_warn

2017-02-23 Thread Joe Perches
On Thu, 2017-02-23 at 17:41 +, Emil Velikov wrote:
> On 23 February 2017 at 17:18, Joe Perches  wrote:
> > On Thu, 2017-02-23 at 09:28 -0600, Rob Herring wrote:
> > > On Fri, Feb 17, 2017 at 1:11 AM, Joe Perches  wrote:
> > > > There are ~4300 uses of pr_warn and ~250 uses of the older
> > > > pr_warning in the kernel source tree.
> > > > 
> > > > Make the use of pr_warn consistent across all kernel files.
> > > > 
> > > > This excludes all files in tools/ as there is a separate
> > > > define pr_warning for that directory tree and pr_warn is
> > > > not used in tools/.
> > > > 
> > > > Done with 'sed s/\bpr_warning\b/pr_warn/' and some emacsing.
> > 
> > []
> > > Where's the removal of pr_warning so we don't have more sneak in?
> > 
> > After all of these actually get applied,
> > and maybe a cycle or two later, one would
> > get sent.
> > 
> 
> By which point you'll get a few reincarnation of it. So you'll have to
> do the same exercise again :-(

Maybe to one or two files.  Not a big deal.

> I guess the question is - are you expecting to get the series merged
> all together/via one tree ?

No.  The only person that could do that effectively is Linus.

> If not, your plan is perfectly reasonable.



Re: [PATCH 00/35] treewide trivial patches converting pr_warning to pr_warn

2017-02-23 Thread Emil Velikov
On 23 February 2017 at 17:18, Joe Perches  wrote:
> On Thu, 2017-02-23 at 09:28 -0600, Rob Herring wrote:
>> On Fri, Feb 17, 2017 at 1:11 AM, Joe Perches  wrote:
>> > There are ~4300 uses of pr_warn and ~250 uses of the older
>> > pr_warning in the kernel source tree.
>> >
>> > Make the use of pr_warn consistent across all kernel files.
>> >
>> > This excludes all files in tools/ as there is a separate
>> > define pr_warning for that directory tree and pr_warn is
>> > not used in tools/.
>> >
>> > Done with 'sed s/\bpr_warning\b/pr_warn/' and some emacsing.
> []
>> Where's the removal of pr_warning so we don't have more sneak in?
>
> After all of these actually get applied,
> and maybe a cycle or two later, one would
> get sent.
>
By which point you'll get a few reincarnation of it. So you'll have to
do the same exercise again :-(

I guess the question is - are you expecting to get the series merged
all together/via one tree ? If not, your plan is perfectly reasonable.
Fwiw in the DRM subsystem, similar cleanups does purge the respective
macros/other with the final commit. But there one can pull the lot in
one go.

Regards,
Emil


Re: [PATCH] target: Fix NULL dereference during LUN lookup + active I/O shutdown

2017-02-23 Thread Bryant G. Ly



From: Nicholas Bellinger 

When transport_clear_lun_ref() is shutting down a se_lun via
configfs with new I/O in-flight, it's possible to trigger a
NULL pointer dereference in transport_lookup_cmd_lun() due
to the fact percpu_ref_get() doesn't do any __PERCPU_REF_DEAD
checking before incrementing lun->lun_ref.count after
lun->lun_ref has switched to atomic_t mode.

This results in a NULL pointer dereference as LUN shutdown
code in core_tpg_remove_lun() continues running after the
existing ->release() -> core_tpg_lun_ref_release() callback
completes, and clears the RCU protected se_lun->lun_se_dev
pointer.

During the OOPs, the state of lun->lun_ref in the process
which triggered the NULL pointer dereference looks like
the following on v4.1.y stable code:

struct se_lun {
   lun_link_magic = 4294932337,
   lun_status = TRANSPORT_LUN_STATUS_FREE,

   .

   lun_se_dev = 0x0,
   lun_sep = 0x0,

   .

   lun_ref = {
 count = {
   counter = 1
 },
 percpu_count_ptr = 3,
 release = 0xa02fa1e0 ,
 confirm_switch = 0x0,
 force_atomic = false,
 rcu = {
   next = 0x88154fa1a5d0,
   func = 0x8137c4c0 
 }
   }
}

To address this bug, use percpu_ref_tryget_live() to ensure
once __PERCPU_REF_DEAD is visable on all CPUs and ->lun_ref
has switched to atomic_t, all new I/Os will fail to obtain
a new lun->lun_ref reference.

Also use an explicit percpu_ref_kill_and_confirm() callback
to block on ->lun_ref_comp to allow the first stage and
associated RCU grace period to complete, and then block on
->lun_ref_shutdown waiting for the final percpu_ref_put()
to drop the last reference via transport_lun_remove_cmd()
before continuing with core_tpg_remove_lun() shutdown.

Reported-by: Rob Millner 
Tested-by: Rob Millner 
Cc: Rob Millner 
Tested-by: Vaibhav Tandon 
Cc: Vaibhav Tandon 
Signed-off-by: Nicholas Bellinger 
---
  drivers/target/target_core_device.c| 10 --
  drivers/target/target_core_tpg.c   |  3 ++-
  drivers/target/target_core_transport.c | 31 ++-
  include/target/target_core_base.h  |  1 +
  4 files changed, 41 insertions(+), 4 deletions(-)


I have seen this and have tested this with our custom kernel.

So this looks good from me!

-Bryant




Re: [PATCH 00/35] treewide trivial patches converting pr_warning to pr_warn

2017-02-23 Thread Joe Perches
On Thu, 2017-02-23 at 09:28 -0600, Rob Herring wrote:
> On Fri, Feb 17, 2017 at 1:11 AM, Joe Perches  wrote:
> > There are ~4300 uses of pr_warn and ~250 uses of the older
> > pr_warning in the kernel source tree.
> > 
> > Make the use of pr_warn consistent across all kernel files.
> > 
> > This excludes all files in tools/ as there is a separate
> > define pr_warning for that directory tree and pr_warn is
> > not used in tools/.
> > 
> > Done with 'sed s/\bpr_warning\b/pr_warn/' and some emacsing.
[]
> Where's the removal of pr_warning so we don't have more sneak in?

After all of these actually get applied,
and maybe a cycle or two later, one would
get sent.



Re: [PATCH] lpfc: add missing Kconfig NVME dependencies

2017-02-23 Thread James Smart

On 2/23/2017 2:09 AM, Christoph Hellwig wrote:

On Wed, Feb 22, 2017 at 08:20:47AM -0800, James Smart wrote:

add missing Kconfig NVME dependencies

Can't believe I missed posting this

Oh.  I'm not sure everyone is happy having to drag in the whole
nvme and nvme target stack when building lpfc.  Is there a way
to make nvme optional?  And in the future scsi as well?


yes - I'll work on doing that.  Scsi is a little further off as the fc 
transport has to be dealt with - moved out from under scsi and put above 
scsi and nvme in the device tree.  The transport is where the hooks for 
adapter mgmt are right now.


-- james



[PATCH 2/2] scsi: remove scsi_execute_req_flags

2017-02-23 Thread Christoph Hellwig
And switch all callers to use scsi_execute instead.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/device_handler/scsi_dh_alua.c  | 16 ++--
 drivers/scsi/device_handler/scsi_dh_emc.c   |  7 +++
 drivers/scsi/device_handler/scsi_dh_hp_sw.c | 10 --
 drivers/scsi/device_handler/scsi_dh_rdac.c  |  7 +++
 drivers/scsi/scsi_lib.c | 11 ---
 drivers/scsi/sd.c   |  9 -
 drivers/scsi/ufs/ufshcd.c   | 10 +-
 include/scsi/scsi_device.h  |  8 ++--
 8 files changed, 27 insertions(+), 51 deletions(-)

diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c 
b/drivers/scsi/device_handler/scsi_dh_alua.c
index d704752b6332..48e200102221 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -151,11 +151,9 @@ static int submit_rtpg(struct scsi_device *sdev, unsigned 
char *buff,
cdb[1] = MI_REPORT_TARGET_PGS;
put_unaligned_be32(bufflen, &cdb[6]);
 
-   return scsi_execute_req_flags(sdev, cdb, DMA_FROM_DEVICE,
- buff, bufflen, sshdr,
- ALUA_FAILOVER_TIMEOUT * HZ,
- ALUA_FAILOVER_RETRIES, NULL,
- req_flags, 0);
+   return scsi_execute(sdev, cdb, DMA_FROM_DEVICE, buff, bufflen, NULL,
+   sshdr, ALUA_FAILOVER_TIMEOUT * HZ,
+   ALUA_FAILOVER_RETRIES, req_flags, 0, NULL);
 }
 
 /*
@@ -185,11 +183,9 @@ static int submit_stpg(struct scsi_device *sdev, int 
group_id,
cdb[1] = MO_SET_TARGET_PGS;
put_unaligned_be32(stpg_len, &cdb[6]);
 
-   return scsi_execute_req_flags(sdev, cdb, DMA_TO_DEVICE,
- stpg_data, stpg_len,
- sshdr, ALUA_FAILOVER_TIMEOUT * HZ,
- ALUA_FAILOVER_RETRIES, NULL,
- req_flags, 0);
+   return scsi_execute(sdev, cdb, DMA_TO_DEVICE, stpg_data, stpg_len, NULL,
+   sshdr, ALUA_FAILOVER_TIMEOUT * HZ,
+   ALUA_FAILOVER_RETRIES, req_flags, 0, NULL);
 }
 
 static struct alua_port_group *alua_find_get_pg(char *id_str, size_t id_size,
diff --git a/drivers/scsi/device_handler/scsi_dh_emc.c 
b/drivers/scsi/device_handler/scsi_dh_emc.c
index f1578832ec7a..8654e940e1a8 100644
--- a/drivers/scsi/device_handler/scsi_dh_emc.c
+++ b/drivers/scsi/device_handler/scsi_dh_emc.c
@@ -276,10 +276,9 @@ static int send_trespass_cmd(struct scsi_device *sdev,
BUG_ON((len > CLARIION_BUFFER_SIZE));
memcpy(csdev->buffer, page22, len);
 
-   err = scsi_execute_req_flags(sdev, cdb, DMA_TO_DEVICE,
-csdev->buffer, len, &sshdr,
-CLARIION_TIMEOUT * HZ, CLARIION_RETRIES,
-NULL, req_flags, 0);
+   err = scsi_execute(sdev, cdb, DMA_TO_DEVICE, csdev->buffer, len, NULL,
+   &sshdr, CLARIION_TIMEOUT * HZ, CLARIION_RETRIES,
+   req_flags, 0, NULL);
if (err) {
if (scsi_sense_valid(&sshdr))
res = trespass_endio(sdev, &sshdr);
diff --git a/drivers/scsi/device_handler/scsi_dh_hp_sw.c 
b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
index be43c940636d..62d314e07d11 100644
--- a/drivers/scsi/device_handler/scsi_dh_hp_sw.c
+++ b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
@@ -100,9 +100,8 @@ static int hp_sw_tur(struct scsi_device *sdev, struct 
hp_sw_dh_data *h)
REQ_FAILFAST_DRIVER;
 
 retry:
-   res = scsi_execute_req_flags(sdev, cmd, DMA_NONE, NULL, 0, &sshdr,
-HP_SW_TIMEOUT, HP_SW_RETRIES,
-NULL, req_flags, 0);
+   res = scsi_execute(sdev, cmd, DMA_NONE, NULL, 0, NULL, &sshdr,
+   HP_SW_TIMEOUT, HP_SW_RETRIES, req_flags, 0, NULL);
if (res) {
if (scsi_sense_valid(&sshdr))
ret = tur_done(sdev, h, &sshdr);
@@ -139,9 +138,8 @@ static int hp_sw_start_stop(struct hp_sw_dh_data *h)
REQ_FAILFAST_DRIVER;
 
 retry:
-   res = scsi_execute_req_flags(sdev, cmd, DMA_NONE, NULL, 0, &sshdr,
-HP_SW_TIMEOUT, HP_SW_RETRIES,
-NULL, req_flags, 0);
+   res = scsi_execute(sdev, cmd, DMA_NONE, NULL, 0, NULL, &sshdr,
+   HP_SW_TIMEOUT, HP_SW_RETRIES, req_flags, 0, NULL);
if (res) {
if (!scsi_sense_valid(&sshdr)) {
sdev_printk(KERN_WARNING, sdev,
diff --git a/drivers/scsi/device_handler/scsi_dh_rdac.c 
b/drivers/scsi/device_handler/scsi_dh_rdac.c
index b64eaae8533d..3cbab8710e58 100644
--- a/drivers/scsi/device_handler/scsi_dh_rdac.c
+++ b/drivers/sc

[PATCH 1/2] scsi: merge __scsi_execute into scsi_execute

2017-02-23 Thread Christoph Hellwig
All but one caller want the decoded sense header, so offer the existing
__scsi_execute helper as the public scsi_execute API to simply the
callers.

Signed-off-by: Christoph Hellwig 
---
 drivers/ata/libata-scsi.c | 12 --
 drivers/scsi/cxlflash/superpipe.c |  8 +++
 drivers/scsi/cxlflash/vlun.c  |  4 ++--
 drivers/scsi/scsi_lib.c   | 48 +--
 drivers/scsi/scsi_transport_spi.c | 24 
 drivers/scsi/sr_ioctl.c   | 19 +++-
 include/scsi/scsi_device.h|  5 ++--
 7 files changed, 46 insertions(+), 74 deletions(-)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 12d3a66600a3..1ac70744ae7b 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -600,6 +600,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user 
*arg)
u8 args[4], *argbuf = NULL, *sensebuf = NULL;
int argsize = 0;
enum dma_data_direction data_dir;
+   struct scsi_sense_hdr sshdr;
int cmd_result;
 
if (arg == NULL)
@@ -648,7 +649,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user 
*arg)
/* Good values for timeout and retries?  Values below
   from scsi_ioctl_send_command() for default case... */
cmd_result = scsi_execute(scsidev, scsi_cmd, data_dir, argbuf, argsize,
- sensebuf, (10*HZ), 5, 0, NULL);
+ sensebuf, &sshdr, (10*HZ), 5, 0, 0, NULL);
 
if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */
u8 *desc = sensebuf + 8;
@@ -657,9 +658,6 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user 
*arg)
/* If we set cc then ATA pass-through will cause a
 * check condition even if no error. Filter that. */
if (cmd_result & SAM_STAT_CHECK_CONDITION) {
-   struct scsi_sense_hdr sshdr;
-   scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE,
-&sshdr);
if (sshdr.sense_key == RECOVERED_ERROR &&
sshdr.asc == 0 && sshdr.ascq == 0x1d)
cmd_result &= ~SAM_STAT_CHECK_CONDITION;
@@ -707,6 +705,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user 
*arg)
int rc = 0;
u8 scsi_cmd[MAX_COMMAND_SIZE];
u8 args[7], *sensebuf = NULL;
+   struct scsi_sense_hdr sshdr;
int cmd_result;
 
if (arg == NULL)
@@ -734,7 +733,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user 
*arg)
/* Good values for timeout and retries?  Values below
   from scsi_ioctl_send_command() for default case... */
cmd_result = scsi_execute(scsidev, scsi_cmd, DMA_NONE, NULL, 0,
-   sensebuf, (10*HZ), 5, 0, NULL);
+   sensebuf, &sshdr, (10*HZ), 5, 0, 0, NULL);
 
if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */
u8 *desc = sensebuf + 8;
@@ -743,9 +742,6 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user 
*arg)
/* If we set cc then ATA pass-through will cause a
 * check condition even if no error. Filter that. */
if (cmd_result & SAM_STAT_CHECK_CONDITION) {
-   struct scsi_sense_hdr sshdr;
-   scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE,
-   &sshdr);
if (sshdr.sense_key == RECOVERED_ERROR &&
sshdr.asc == 0 && sshdr.ascq == 0x1d)
cmd_result &= ~SAM_STAT_CHECK_CONDITION;
diff --git a/drivers/scsi/cxlflash/superpipe.c 
b/drivers/scsi/cxlflash/superpipe.c
index 90869cee2b20..5b812ed87f22 100644
--- a/drivers/scsi/cxlflash/superpipe.c
+++ b/drivers/scsi/cxlflash/superpipe.c
@@ -305,6 +305,7 @@ static int read_cap16(struct scsi_device *sdev, struct 
llun_info *lli)
struct cxlflash_cfg *cfg = shost_priv(sdev->host);
struct device *dev = &cfg->dev->dev;
struct glun_info *gli = lli->parent;
+   struct scsi_sense_hdr sshdr;
u8 *cmd_buf = NULL;
u8 *scsi_cmd = NULL;
u8 *sense_buf = NULL;
@@ -332,7 +333,8 @@ static int read_cap16(struct scsi_device *sdev, struct 
llun_info *lli)
/* Drop the ioctl read semahpore across lengthy call */
up_read(&cfg->ioctl_rwsem);
result = scsi_execute(sdev, scsi_cmd, DMA_FROM_DEVICE, cmd_buf,
- CMD_BUFSIZE, sense_buf, to, CMD_RETRIES, 0, NULL);
+ CMD_BUFSIZE, sense_buf, &sshdr, to, CMD_RETRIES,
+ 0, 0, NULL);
down_read(&cfg->ioctl_rwsem);
rc = check_state(cfg);
if (rc) {
@@ -345,10 +347,6 @@ static int read_cap16(struct sc

sense handling improvements, part 2

2017-02-23 Thread Christoph Hellwig
No real changes, but I did an explicit rebase against the 4.11/scsi-fixes
branch.



Re: [PATCH 00/35] treewide trivial patches converting pr_warning to pr_warn

2017-02-23 Thread Rob Herring
On Fri, Feb 17, 2017 at 1:11 AM, Joe Perches  wrote:
> There are ~4300 uses of pr_warn and ~250 uses of the older
> pr_warning in the kernel source tree.
>
> Make the use of pr_warn consistent across all kernel files.
>
> This excludes all files in tools/ as there is a separate
> define pr_warning for that directory tree and pr_warn is
> not used in tools/.
>
> Done with 'sed s/\bpr_warning\b/pr_warn/' and some emacsing.
>
> Miscellanea:
>
> o Coalesce formats and realign arguments
>
> Some files not compiled - no cross-compilers
>
> Joe Perches (35):
>   alpha: Convert remaining uses of pr_warning to pr_warn
>   ARM: ep93xx: Convert remaining uses of pr_warning to pr_warn
>   arm64: Convert remaining uses of pr_warning to pr_warn
>   arch/blackfin: Convert remaining uses of pr_warning to pr_warn
>   ia64: Convert remaining use of pr_warning to pr_warn
>   powerpc: Convert remaining uses of pr_warning to pr_warn
>   sh: Convert remaining uses of pr_warning to pr_warn
>   sparc: Convert remaining use of pr_warning to pr_warn
>   x86: Convert remaining uses of pr_warning to pr_warn
>   drivers/acpi: Convert remaining uses of pr_warning to pr_warn
>   block/drbd: Convert remaining uses of pr_warning to pr_warn
>   gdrom: Convert remaining uses of pr_warning to pr_warn
>   drivers/char: Convert remaining use of pr_warning to pr_warn
>   clocksource: Convert remaining use of pr_warning to pr_warn
>   drivers/crypto: Convert remaining uses of pr_warning to pr_warn
>   fmc: Convert remaining use of pr_warning to pr_warn
>   drivers/gpu: Convert remaining uses of pr_warning to pr_warn
>   drivers/ide: Convert remaining uses of pr_warning to pr_warn
>   drivers/input: Convert remaining uses of pr_warning to pr_warn
>   drivers/isdn: Convert remaining uses of pr_warning to pr_warn
>   drivers/macintosh: Convert remaining uses of pr_warning to pr_warn
>   drivers/media: Convert remaining use of pr_warning to pr_warn
>   drivers/mfd: Convert remaining uses of pr_warning to pr_warn
>   drivers/mtd: Convert remaining uses of pr_warning to pr_warn
>   drivers/of: Convert remaining uses of pr_warning to pr_warn
>   drivers/oprofile: Convert remaining uses of pr_warning to pr_warn
>   drivers/platform: Convert remaining uses of pr_warning to pr_warn
>   drivers/rapidio: Convert remaining use of pr_warning to pr_warn
>   drivers/scsi: Convert remaining use of pr_warning to pr_warn
>   drivers/sh: Convert remaining use of pr_warning to pr_warn
>   drivers/tty: Convert remaining uses of pr_warning to pr_warn
>   drivers/video: Convert remaining uses of pr_warning to pr_warn
>   kernel/trace: Convert remaining uses of pr_warning to pr_warn
>   lib: Convert remaining uses of pr_warning to pr_warn
>   sound/soc: Convert remaining uses of pr_warning to pr_warn

Where's the removal of pr_warning so we don't have more sneak in?

Rob


[PATCH] qedf: fixup compilation warning about atomic_t usage

2017-02-23 Thread Dupuis, Chad
From: "Dupuis, Chad" 

Based on an original patch by Hannes Reinecke.

The driver didn't follow the atomic_t vs refcount_t change, and
anyway one should be using kref_read() instead of accessing the
counter inside an kref.

Fixes: 61d8658b4a435e ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver 
framework.)
Cc: Hannes Reinecke 
Cc: Nilesh Javali 
Signed-off-by: Dupuis, Chad 
---
 drivers/scsi/qedf/qedf_els.c | 6 +++---
 drivers/scsi/qedf/qedf_io.c  | 8 
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/qedf/qedf_els.c b/drivers/scsi/qedf/qedf_els.c
index 78f1c25..59f3e5c 100644
--- a/drivers/scsi/qedf/qedf_els.c
+++ b/drivers/scsi/qedf/qedf_els.c
@@ -183,7 +183,7 @@ static void qedf_rrq_compl(struct qedf_els_cb_arg *cb_arg)
rrq_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT)
cancel_delayed_work_sync(&orig_io_req->timeout_work);
 
-   refcount = atomic_read(&orig_io_req->refcount.refcount);
+   refcount = kref_read(&orig_io_req->refcount);
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "rrq_compl: orig io = %p,"
   " orig xid = 0x%x, rrq_xid = 0x%x, refcount=%d\n",
   orig_io_req, orig_io_req->xid, rrq_req->xid, refcount);
@@ -474,7 +474,7 @@ static void qedf_srr_compl(struct qedf_els_cb_arg *cb_arg)
srr_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT)
cancel_delayed_work_sync(&orig_io_req->timeout_work);
 
-   refcount = atomic_read(&orig_io_req->refcount.refcount);
+   refcount = kref_read(&orig_io_req->refcount);
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered: orig_io=%p,"
   " orig_io_xid=0x%x, rec_xid=0x%x, refcount=%d\n",
   orig_io_req, orig_io_req->xid, srr_req->xid, refcount);
@@ -758,7 +758,7 @@ static void qedf_rec_compl(struct qedf_els_cb_arg *cb_arg)
rec_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT)
cancel_delayed_work_sync(&orig_io_req->timeout_work);
 
-   refcount = atomic_read(&orig_io_req->refcount.refcount);
+   refcount = kref_read(&orig_io_req->refcount);
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered: orig_io=%p,"
   " orig_io_xid=0x%x, rec_xid=0x%x, refcount=%d\n",
   orig_io_req, orig_io_req->xid, rec_req->xid, refcount);
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index 486c045..ee0dcf9 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -998,7 +998,7 @@ static void qedf_trace_io(struct qedf_rport *fcport, struct 
qedf_ioreq *io_req,
io_log->sg_count = scsi_sg_count(sc_cmd);
io_log->result = sc_cmd->result;
io_log->jiffies = jiffies;
-   io_log->refcount = atomic_read(&io_req->refcount.refcount);
+   io_log->refcount = kref_read(&io_req->refcount);
 
if (direction == QEDF_IO_TRACE_REQ) {
/* For requests we only care abot the submission CPU */
@@ -1340,7 +1340,7 @@ void qedf_scsi_completion(struct qedf_ctx *qedf, struct 
fcoe_cqe *cqe,
/* Good I/O completion */
sc_cmd->result = DID_OK << 16;
} else {
-   refcount = atomic_read(&io_req->refcount.refcount);
+   refcount = kref_read(&io_req->refcount);
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO,
"%d:0:%d:%d xid=0x%0x op=0x%02x "
"lba=%02x%02x%02x%02x cdb_status=%d "
@@ -1425,7 +1425,7 @@ void qedf_scsi_done(struct qedf_ctx *qedf, struct 
qedf_ioreq *io_req,
qedf_unmap_sg_list(qedf, io_req);
 
sc_cmd->result = result << 16;
-   refcount = atomic_read(&io_req->refcount.refcount);
+   refcount = kref_read(&io_req->refcount);
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, "%d:0:%d:%d: Completing "
"sc_cmd=%p result=0x%08x op=0x%02x lba=0x%02x%02x%02x%02x, "
"allowed=%d retries=%d refcount=%d.\n",
@@ -1556,7 +1556,7 @@ static void qedf_flush_els_req(struct qedf_ctx *qedf,
 {
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO,
"Flushing ELS request xid=0x%x refcount=%d.\n", els_req->xid,
-   atomic_read(&els_req->refcount.refcount));
+   kref_read(&els_req->refcount));
 
/*
 * Need to distinguish this from a timeout when calling the
-- 
1.8.5.6



[PATCH] cciss: correct check map error.

2017-02-23 Thread Don Brace
remove device driver failed to check map error messages

Reported-by: Johnny Bieren 
Tested-by: Johnny Bieren 
Reviewed-by: Scott Teel 
Signed-off-by: Don Brace 
---
 drivers/block/cciss.c |   32 
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 3a44438..9c0a34b 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -347,7 +347,7 @@ static void cciss_unmap_sg_chain_block(ctlr_info_t *h, 
CommandList_struct *c)
pci_unmap_single(h->pdev, temp64.val, chain_sg->Len, PCI_DMA_TODEVICE);
 }
 
-static void cciss_map_sg_chain_block(ctlr_info_t *h, CommandList_struct *c,
+static int cciss_map_sg_chain_block(ctlr_info_t *h, CommandList_struct *c,
SGDescriptor_struct *chain_block, int len)
 {
SGDescriptor_struct *chain_sg;
@@ -358,8 +358,16 @@ static void cciss_map_sg_chain_block(ctlr_info_t *h, 
CommandList_struct *c,
chain_sg->Len = len;
temp64.val = pci_map_single(h->pdev, chain_block, len,
PCI_DMA_TODEVICE);
+   if (dma_mapping_error(&h->pdev->dev, temp64.val)) {
+   dev_warn(&h->pdev->dev,
+   "%s: error mapping chain block for DMA\n",
+   __func__);
+   return -1;
+   }
chain_sg->Addr.lower = temp64.val32.lower;
chain_sg->Addr.upper = temp64.val32.upper;
+
+   return 0;
 }
 
 #include "cciss_scsi.c"/* For SCSI tape support */
@@ -3370,15 +3378,31 @@ static void do_cciss_request(struct request_queue *q)
temp64.val = (__u64) pci_map_page(h->pdev, sg_page(&tmp_sg[i]),
tmp_sg[i].offset,
tmp_sg[i].length, dir);
+   if (dma_mapping_error(&h->pdev->dev, temp64.val)) {
+   dev_warn(&h->pdev->dev,
+   "%s: error mapping page for DMA\n", __func__);
+   creq->errors = make_status_bytes(SAM_STAT_GOOD,
+   0, DRIVER_OK,
+   DID_SOFT_ERROR);
+   cmd_free(h, c);
+   return;
+   }
curr_sg[sg_index].Addr.lower = temp64.val32.lower;
curr_sg[sg_index].Addr.upper = temp64.val32.upper;
curr_sg[sg_index].Ext = 0;  /* we are not chaining */
++sg_index;
}
-   if (chained)
-   cciss_map_sg_chain_block(h, c, h->cmd_sg_list[c->cmdindex],
+   if (chained) {
+   if (cciss_map_sg_chain_block(h, c, h->cmd_sg_list[c->cmdindex],
(seg - (h->max_cmd_sgentries - 1)) *
-   sizeof(SGDescriptor_struct));
+   sizeof(SGDescriptor_struct))) {
+   creq->errors = make_status_bytes(SAM_STAT_GOOD,
+   0, DRIVER_OK,
+   DID_SOFT_ERROR);
+   cmd_free(h, c);
+   return;
+   }
+   }
 
/* track how many SG entries we are using */
if (seg > h->maxSG)



Re: [PATCH] qedf: fixup compilation warning about atomic_t usage

2017-02-23 Thread Chad Dupuis


On Thu, 23 Feb 2017, 11:44am -, Hannes Reinecke wrote:

> The driver didn't follow the atomic_t vs refcount_t change, and
> anyway one should be using kref_read() instead of accessing the
> counter inside an kref.
> 
> Fixes: 61d8658b4a435e ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver 
> framework.)
> Cc: Chad Dupuis 
> Cc: Nilesh Javali 
> Signed-off-by: Hannes Reinecke 
> ---
>  drivers/scsi/qedf/qedf_io.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
> index 486c045..ee0dcf9 100644
> --- a/drivers/scsi/qedf/qedf_io.c
> +++ b/drivers/scsi/qedf/qedf_io.c
> @@ -998,7 +998,7 @@ static void qedf_trace_io(struct qedf_rport *fcport, 
> struct qedf_ioreq *io_req,
>   io_log->sg_count = scsi_sg_count(sc_cmd);
>   io_log->result = sc_cmd->result;
>   io_log->jiffies = jiffies;
> - io_log->refcount = atomic_read(&io_req->refcount.refcount);
> + io_log->refcount = kref_read(&io_req->refcount);
>  
>   if (direction == QEDF_IO_TRACE_REQ) {
>   /* For requests we only care abot the submission CPU */
> @@ -1340,7 +1340,7 @@ void qedf_scsi_completion(struct qedf_ctx *qedf, struct 
> fcoe_cqe *cqe,
>   /* Good I/O completion */
>   sc_cmd->result = DID_OK << 16;
>   } else {
> - refcount = atomic_read(&io_req->refcount.refcount);
> + refcount = kref_read(&io_req->refcount);
>   QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO,
>   "%d:0:%d:%d xid=0x%0x op=0x%02x "
>   "lba=%02x%02x%02x%02x cdb_status=%d "
> @@ -1425,7 +1425,7 @@ void qedf_scsi_done(struct qedf_ctx *qedf, struct 
> qedf_ioreq *io_req,
>   qedf_unmap_sg_list(qedf, io_req);
>  
>   sc_cmd->result = result << 16;
> - refcount = atomic_read(&io_req->refcount.refcount);
> + refcount = kref_read(&io_req->refcount);
>   QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, "%d:0:%d:%d: Completing "
>   "sc_cmd=%p result=0x%08x op=0x%02x lba=0x%02x%02x%02x%02x, "
>   "allowed=%d retries=%d refcount=%d.\n",
> @@ -1556,7 +1556,7 @@ static void qedf_flush_els_req(struct qedf_ctx *qedf,
>  {
>   QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO,
>   "Flushing ELS request xid=0x%x refcount=%d.\n", els_req->xid,
> - atomic_read(&els_req->refcount.refcount));
> + kref_read(&els_req->refcount));
>  
>   /*
>* Need to distinguish this from a timeout when calling the
>

Thanks for the patch Hannes though it looks like the atomic_read's in 
qedf_els.c need to be converted as well.  Will post a patch shortly. 


Re: sense handling improvements

2017-02-23 Thread Christoph Hellwig
On Thu, Feb 23, 2017 at 09:28:20AM -0500, Martin K. Petersen wrote:
> > "Christoph" == Christoph Hellwig  writes:
> 
> Christoph,
> 
> >> I applied 1-4 to 4.11/scsi-fixes. Both 5 and 6 had problems so please
> >> fix those up.
> 
> Christoph> What kind of problem?  I didn't see anything on the list.
> 
> They didn't apply. I tried to fix them up by hand. 5 was easy but 6
> caused a flurry of failures that I ran out of time to look into.
> 
> So please resubmit 5 and 6 against 4.11/scsi-fixes.

Ok, I'll take a look.  They apply fine to mkp/for-next so there must
be some other patches changing the code.


Re: sense handling improvements

2017-02-23 Thread Martin K. Petersen
> "Christoph" == Christoph Hellwig  writes:

Christoph,

>> I applied 1-4 to 4.11/scsi-fixes. Both 5 and 6 had problems so please
>> fix those up.

Christoph> What kind of problem?  I didn't see anything on the list.

They didn't apply. I tried to fix them up by hand. 5 was easy but 6
caused a flurry of failures that I ran out of time to look into.

So please resubmit 5 and 6 against 4.11/scsi-fixes.

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] scsi_error: count medium access timeout only once per EH run

2017-02-23 Thread Laurence Oberman


- Original Message -
> From: "Hannes Reinecke" 
> To: "Martin K. Petersen" 
> Cc: "Christoph Hellwig" , "James Bottomley" 
> ,
> linux-scsi@vger.kernel.org, "Hannes Reinecke" , "Ewan Milne" 
> , "Lawrence Oberman"
> , "Benjamin Block" , "Steffen 
> Maier" , "Hannes
> Reinecke" 
> Sent: Thursday, February 23, 2017 5:27:19 AM
> Subject: [PATCH] scsi_error: count medium access timeout only once per EH run
> 
> The current medium access timeout counter will be increased for
> each command, so if there are enough failed commands we'll hit
> the medium access timeout for even a single failure.
> Fix this by making the timeout per EH run, ie the counter will
> only be increased once per device and EH run.
> 
> Cc: Ewan Milne 
> Cc: Lawrence Oberman 
> Cc: Benjamin Block 
> Cc: Steffen Maier 
> Signed-off-by: Hannes Reinecke 
> ---
>  drivers/scsi/scsi_error.c |  2 ++
>  drivers/scsi/sd.c | 16 ++--
>  drivers/scsi/sd.h |  1 +
>  include/scsi/scsi.h   |  1 +
>  4 files changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
> index f2cafae..481ea1b 100644
> --- a/drivers/scsi/scsi_error.c
> +++ b/drivers/scsi/scsi_error.c
> @@ -58,6 +58,7 @@
>  static int scsi_eh_try_stu(struct scsi_cmnd *scmd);
>  static int scsi_try_to_abort_cmd(struct scsi_host_template *,
>struct scsi_cmnd *);
> +static int scsi_eh_action(struct scsi_cmnd *scmd, int rtn);
>  
>  /* called with shost->host_lock held */
>  void scsi_eh_wakeup(struct Scsi_Host *shost)
> @@ -249,6 +250,7 @@ int scsi_eh_scmd_add(struct scsi_cmnd *scmd, int eh_flag)
>   if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED)
>   eh_flag &= ~SCSI_EH_CANCEL_CMD;
>   scmd->eh_eflags |= eh_flag;
> + scsi_eh_action(scmd, NEEDS_RESET);
>   list_add_tail(&scmd->eh_entry, &shost->eh_cmd_q);
>   shost->host_failed++;
>   scsi_eh_wakeup(shost);
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index be535d4..cd9f290 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -1696,12 +1696,21 @@ static int sd_pr_clear(struct block_device *bdev, u64
> key)
>   *   the eh command is passed in eh_disp.  We're looking for devices that
>   *   fail medium access commands but are OK with non access commands like
>   *   test unit ready (so wrongly see the device as having a successful
> - *   recovery)
> + *   recovery).
> + *   We have to be careful to count a medium access failure only once
> + *   per SCSI EH run; there might be several timed out commands which
> + *   will cause the 'max_medium_access_timeouts' counter to trigger
> + *   after the first SCSI EH run already and set the device to offline.
>   **/
>  static int sd_eh_action(struct scsi_cmnd *scmd, int eh_disp)
>  {
>   struct scsi_disk *sdkp = scsi_disk(scmd->request->rq_disk);
>  
> + if (eh_disp == NEEDS_RESET) {
> + /* New SCSI EH run, reset gate variable */
> + sdkp->medium_access_reset = 0;
> + return eh_disp;
> + }
>   if (!scsi_device_online(scmd->device) ||
>   !scsi_medium_access_command(scmd) ||
>   host_byte(scmd->result) != DID_TIME_OUT ||
> @@ -1715,7 +1724,10 @@ static int sd_eh_action(struct scsi_cmnd *scmd, int
> eh_disp)
>* process of recovering or has it suffered an internal failure
>* that prevents access to the storage medium.
>*/
> - sdkp->medium_access_timed_out++;
> + if (!sdkp->medium_access_reset) {
> + sdkp->medium_access_timed_out++;
> + sdkp->medium_access_reset++;
> + }
>  
>   /*
>* If the device keeps failing read/write commands but TEST UNIT
> diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
> index 4dac35e..19e0bab 100644
> --- a/drivers/scsi/sd.h
> +++ b/drivers/scsi/sd.h
> @@ -85,6 +85,7 @@ struct scsi_disk {
>   unsigned intphysical_block_size;
>   unsigned intmax_medium_access_timeouts;
>   unsigned intmedium_access_timed_out;
> + unsigned intmedium_access_reset;
>   u8  media_present;
>   u8  write_prot;
>   u8  protection_type;/* Data Integrity Field */
> diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
> index a1e1930..b6c750f 100644
> --- a/include/scsi/scsi.h
> +++ b/include/scsi/scsi.h
> @@ -185,6 +185,7 @@ static inline int scsi_is_wlun(u64 lun)
>  #define TIMEOUT_ERROR   0x2007
>  #define SCSI_RETURN_NOT_HANDLED   0x2008
>  #define FAST_IO_FAIL 0x2009
> +#define NEEDS_RESET 0x2010
>  
>  /*
>   * Midlevel queue return values.
> --
> 1.8.5.6
> 
> 

Hello Hannes 
This makes sense to me what you are doing here.
I will also wait for Ewan to weigh in but I wonder if we should make a simple 
change.
Maybe good to clarify the RESET here by simply changing the name.

Change 
+#define NEEDS_RESET 0x2010
to
+#define MAX_MEDIUM_ERROR_NEEDS_RESET

Of course then also change
+   if (

[PATCH] qedf: fixup compilation warning about atomic_t usage

2017-02-23 Thread Hannes Reinecke
The driver didn't follow the atomic_t vs refcount_t change, and
anyway one should be using kref_read() instead of accessing the
counter inside an kref.

Fixes: 61d8658b4a435e ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver 
framework.)
Cc: Chad Dupuis 
Cc: Nilesh Javali 
Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/qedf/qedf_io.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index 486c045..ee0dcf9 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -998,7 +998,7 @@ static void qedf_trace_io(struct qedf_rport *fcport, struct 
qedf_ioreq *io_req,
io_log->sg_count = scsi_sg_count(sc_cmd);
io_log->result = sc_cmd->result;
io_log->jiffies = jiffies;
-   io_log->refcount = atomic_read(&io_req->refcount.refcount);
+   io_log->refcount = kref_read(&io_req->refcount);
 
if (direction == QEDF_IO_TRACE_REQ) {
/* For requests we only care abot the submission CPU */
@@ -1340,7 +1340,7 @@ void qedf_scsi_completion(struct qedf_ctx *qedf, struct 
fcoe_cqe *cqe,
/* Good I/O completion */
sc_cmd->result = DID_OK << 16;
} else {
-   refcount = atomic_read(&io_req->refcount.refcount);
+   refcount = kref_read(&io_req->refcount);
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO,
"%d:0:%d:%d xid=0x%0x op=0x%02x "
"lba=%02x%02x%02x%02x cdb_status=%d "
@@ -1425,7 +1425,7 @@ void qedf_scsi_done(struct qedf_ctx *qedf, struct 
qedf_ioreq *io_req,
qedf_unmap_sg_list(qedf, io_req);
 
sc_cmd->result = result << 16;
-   refcount = atomic_read(&io_req->refcount.refcount);
+   refcount = kref_read(&io_req->refcount);
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, "%d:0:%d:%d: Completing "
"sc_cmd=%p result=0x%08x op=0x%02x lba=0x%02x%02x%02x%02x, "
"allowed=%d retries=%d refcount=%d.\n",
@@ -1556,7 +1556,7 @@ static void qedf_flush_els_req(struct qedf_ctx *qedf,
 {
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO,
"Flushing ELS request xid=0x%x refcount=%d.\n", els_req->xid,
-   atomic_read(&els_req->refcount.refcount));
+   kref_read(&els_req->refcount));
 
/*
 * Need to distinguish this from a timeout when calling the
-- 
1.8.5.6



[PATCHv2] hpsa: expose enclosures

2017-02-23 Thread Hannes Reinecke
Some servers have a built-in enclosure which will show up on the
same bus as the internal physical devices. This patch fixes the
driver to expose them.

Cc: Don Brace 
Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/hpsa.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 524a0c7..a77ed5a 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -4407,7 +4407,10 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h)
 * Expose all devices except for physical devices that
 * are masked.
 */
-   if (MASKED_DEVICE(lunaddrbytes) && this_device->physical_device)
+   if (this_device->devtype == TYPE_ENCLOSURE)
+   this_device->expose_device = 1;
+   else if (MASKED_DEVICE(lunaddrbytes) &&
+this_device->physical_device)
this_device->expose_device = 0;
else
this_device->expose_device = 1;
-- 
1.8.5.6



[PATCH] qla2xxx: fix spelling mistake: "seperator" -> "separator"

2017-02-23 Thread Colin King
From: Colin Ian King 

trivial fix to spelling mistake in pr_err message

Signed-off-by: Colin Ian King 
---
 drivers/scsi/qla2xxx/tcm_qla2xxx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c 
b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index c2f8c35..8e8ab0f 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
@@ -1792,7 +1792,7 @@ static struct se_wwn *tcm_qla2xxx_npiv_make_lport(
 
p = strchr(tmp, '@');
if (!p) {
-   pr_err("Unable to locate NPIV '@' seperator\n");
+   pr_err("Unable to locate NPIV '@' separator\n");
return ERR_PTR(-EINVAL);
}
*p++ = '\0';
-- 
2.10.2



[PATCH] scsi_error: count medium access timeout only once per EH run

2017-02-23 Thread Hannes Reinecke
The current medium access timeout counter will be increased for
each command, so if there are enough failed commands we'll hit
the medium access timeout for even a single failure.
Fix this by making the timeout per EH run, ie the counter will
only be increased once per device and EH run.

Cc: Ewan Milne 
Cc: Lawrence Oberman 
Cc: Benjamin Block 
Cc: Steffen Maier 
Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/scsi_error.c |  2 ++
 drivers/scsi/sd.c | 16 ++--
 drivers/scsi/sd.h |  1 +
 include/scsi/scsi.h   |  1 +
 4 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index f2cafae..481ea1b 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -58,6 +58,7 @@
 static int scsi_eh_try_stu(struct scsi_cmnd *scmd);
 static int scsi_try_to_abort_cmd(struct scsi_host_template *,
 struct scsi_cmnd *);
+static int scsi_eh_action(struct scsi_cmnd *scmd, int rtn);
 
 /* called with shost->host_lock held */
 void scsi_eh_wakeup(struct Scsi_Host *shost)
@@ -249,6 +250,7 @@ int scsi_eh_scmd_add(struct scsi_cmnd *scmd, int eh_flag)
if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED)
eh_flag &= ~SCSI_EH_CANCEL_CMD;
scmd->eh_eflags |= eh_flag;
+   scsi_eh_action(scmd, NEEDS_RESET);
list_add_tail(&scmd->eh_entry, &shost->eh_cmd_q);
shost->host_failed++;
scsi_eh_wakeup(shost);
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index be535d4..cd9f290 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1696,12 +1696,21 @@ static int sd_pr_clear(struct block_device *bdev, u64 
key)
  * the eh command is passed in eh_disp.  We're looking for devices that
  * fail medium access commands but are OK with non access commands like
  * test unit ready (so wrongly see the device as having a successful
- * recovery)
+ * recovery).
+ * We have to be careful to count a medium access failure only once
+ * per SCSI EH run; there might be several timed out commands which
+ * will cause the 'max_medium_access_timeouts' counter to trigger
+ * after the first SCSI EH run already and set the device to offline.
  **/
 static int sd_eh_action(struct scsi_cmnd *scmd, int eh_disp)
 {
struct scsi_disk *sdkp = scsi_disk(scmd->request->rq_disk);
 
+   if (eh_disp == NEEDS_RESET) {
+   /* New SCSI EH run, reset gate variable */
+   sdkp->medium_access_reset = 0;
+   return eh_disp;
+   }
if (!scsi_device_online(scmd->device) ||
!scsi_medium_access_command(scmd) ||
host_byte(scmd->result) != DID_TIME_OUT ||
@@ -1715,7 +1724,10 @@ static int sd_eh_action(struct scsi_cmnd *scmd, int 
eh_disp)
 * process of recovering or has it suffered an internal failure
 * that prevents access to the storage medium.
 */
-   sdkp->medium_access_timed_out++;
+   if (!sdkp->medium_access_reset) {
+   sdkp->medium_access_timed_out++;
+   sdkp->medium_access_reset++;
+   }
 
/*
 * If the device keeps failing read/write commands but TEST UNIT
diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
index 4dac35e..19e0bab 100644
--- a/drivers/scsi/sd.h
+++ b/drivers/scsi/sd.h
@@ -85,6 +85,7 @@ struct scsi_disk {
unsigned intphysical_block_size;
unsigned intmax_medium_access_timeouts;
unsigned intmedium_access_timed_out;
+   unsigned intmedium_access_reset;
u8  media_present;
u8  write_prot;
u8  protection_type;/* Data Integrity Field */
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index a1e1930..b6c750f 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -185,6 +185,7 @@ static inline int scsi_is_wlun(u64 lun)
 #define TIMEOUT_ERROR   0x2007
 #define SCSI_RETURN_NOT_HANDLED   0x2008
 #define FAST_IO_FAIL   0x2009
+#define NEEDS_RESET 0x2010
 
 /*
  * Midlevel queue return values.
-- 
1.8.5.6



Re: [PATCH] lpfc: add missing Kconfig NVME dependencies

2017-02-23 Thread Christoph Hellwig
On Wed, Feb 22, 2017 at 08:20:47AM -0800, James Smart wrote:
> 
> add missing Kconfig NVME dependencies
> 
> Can't believe I missed posting this

Oh.  I'm not sure everyone is happy having to drag in the whole
nvme and nvme target stack when building lpfc.  Is there a way
to make nvme optional?  And in the future scsi as well?


Re: sense handling improvements

2017-02-23 Thread Christoph Hellwig
On Wed, Feb 22, 2017 at 07:51:44PM -0500, Martin K. Petersen wrote:
> I applied 1-4 to 4.11/scsi-fixes. Both 5 and 6 had problems so please
> fix those up.

What kind of problem?  I didn't see anything on the list.


[PATCH v2] scsi: ufs: Factor out ufshcd_read_desc_param

2017-02-23 Thread Potomski, MichalX
Since in UFS 2.1 specification some of the descriptor
lengths differs from 2.0 specification and some devices,
which are reporting spec version 2.0 have different
descriptor lengths we can not rely on hardcoded values
taken from 2.0 specification. This patch introduces
reading these lengths per each device from descriptor
headers at probe time to ensure their correctness.

Signed-off-by: Michal' Potomski 
---
 drivers/scsi/ufs/ufs.h|  22 ++---
 drivers/scsi/ufs/ufshcd.c | 231 ++
 drivers/scsi/ufs/ufshcd.h |  15 +++
 3 files changed, 196 insertions(+), 72 deletions(-)

diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h
index 318e4a1..54deeb7 100644
--- a/drivers/scsi/ufs/ufs.h
+++ b/drivers/scsi/ufs/ufs.h
@@ -146,7 +146,7 @@ enum attr_idn {
 /* Descriptor idn for Query requests */
 enum desc_idn {
QUERY_DESC_IDN_DEVICE   = 0x0,
-   QUERY_DESC_IDN_CONFIGURAION = 0x1,
+   QUERY_DESC_IDN_CONFIGURATION= 0x1,
QUERY_DESC_IDN_UNIT = 0x2,
QUERY_DESC_IDN_RFU_0= 0x3,
QUERY_DESC_IDN_INTERCONNECT = 0x4,
@@ -162,19 +162,13 @@ enum desc_header_offset {
QUERY_DESC_DESC_TYPE_OFFSET = 0x01,
 };
 
-enum ufs_desc_max_size {
-   QUERY_DESC_DEVICE_MAX_SIZE  = 0x40,
-   QUERY_DESC_CONFIGURAION_MAX_SIZE= 0x90,
-   QUERY_DESC_UNIT_MAX_SIZE= 0x23,
-   QUERY_DESC_INTERCONNECT_MAX_SIZE= 0x06,
-   /*
-* Max. 126 UNICODE characters (2 bytes per character) plus 2 bytes
-* of descriptor header.
-*/
-   QUERY_DESC_STRING_MAX_SIZE  = 0xFE,
-   QUERY_DESC_GEOMETRY_MAX_SIZE= 0x44,
-   QUERY_DESC_POWER_MAX_SIZE   = 0x62,
-   QUERY_DESC_RFU_MAX_SIZE = 0x00,
+enum ufs_desc_def_size {
+   QUERY_DESC_DEVICE_DEF_SIZE  = 0x40,
+   QUERY_DESC_CONFIGURATION_DEF_SIZE   = 0x90,
+   QUERY_DESC_UNIT_DEF_SIZE= 0x23,
+   QUERY_DESC_INTERCONNECT_DEF_SIZE= 0x06,
+   QUERY_DESC_GEOMETRY_DEF_SIZE= 0x44,
+   QUERY_DESC_POWER_DEF_SIZE   = 0x62,
 };
 
 /* Unit descriptor parameters offsets in bytes*/
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 8b721f4..b839a17 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -100,19 +100,6 @@
 #define ufshcd_hex_dump(prefix_str, buf, len) \
 print_hex_dump(KERN_ERR, prefix_str, DUMP_PREFIX_OFFSET, 16, 4, buf, len, 
false)
 
-static u32 ufs_query_desc_max_size[] = {
-   QUERY_DESC_DEVICE_MAX_SIZE,
-   QUERY_DESC_CONFIGURAION_MAX_SIZE,
-   QUERY_DESC_UNIT_MAX_SIZE,
-   QUERY_DESC_RFU_MAX_SIZE,
-   QUERY_DESC_INTERCONNECT_MAX_SIZE,
-   QUERY_DESC_STRING_MAX_SIZE,
-   QUERY_DESC_RFU_MAX_SIZE,
-   QUERY_DESC_GEOMETRY_MAX_SIZE,
-   QUERY_DESC_POWER_MAX_SIZE,
-   QUERY_DESC_RFU_MAX_SIZE,
-};
-
 enum {
UFSHCD_MAX_CHANNEL  = 0,
UFSHCD_MAX_ID   = 1,
@@ -2857,7 +2844,7 @@ static int __ufshcd_query_descriptor(struct ufs_hba *hba,
goto out;
}
 
-   if (*buf_len <= QUERY_DESC_MIN_SIZE || *buf_len > QUERY_DESC_MAX_SIZE) {
+   if (*buf_len < QUERY_DESC_MIN_SIZE || *buf_len > QUERY_DESC_MAX_SIZE) {
dev_err(hba->dev, "%s: descriptor buffer size (%d) is out of 
range\n",
__func__, *buf_len);
err = -EINVAL;
@@ -2938,6 +2925,92 @@ static int ufshcd_query_descriptor_retry(struct ufs_hba 
*hba,
 }
 
 /**
+ * ufshcd_read_desc_length - read the specified descriptor length from header
+ * @hba: Pointer to adapter instance
+ * @desc_id: descriptor idn value
+ * @desc_index: descriptor index
+ * @desc_length: pointer to variable to read the length of descriptor
+ *
+ * Return 0 in case of success, non-zero otherwise
+ */
+static int ufshcd_read_desc_length(struct ufs_hba *hba,
+   enum desc_idn desc_id,
+   int desc_index,
+   int *desc_length)
+{
+   int ret;
+   u8 header[QUERY_DESC_HDR_SIZE];
+   int header_len = QUERY_DESC_HDR_SIZE;
+
+   if (desc_id >= QUERY_DESC_IDN_MAX)
+   return -EINVAL;
+
+   ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC,
+   desc_id, desc_index, 0, header,
+   &header_len);
+
+   if (ret) {
+   dev_err(hba->dev, "%s: Failed to get descriptor header id %d",
+   __func__, desc_id);
+   return ret;
+   } else if (desc_id != header[QUERY_DESC_DESC_TYPE_OFFSET]) {
+   dev_warn(hba->dev, "%s: descriptor header id %d and desc_id %d 
mismatch",
+   __func__, header[QUERY_DESC_DESC_TYPE_OFFSET],
+   desc_id);
+   ret = -EINVAL;
+   }
+
+   *desc_length = header[QUERY_DESC_LENG

Re: Advanced Format SAT devices show incorrect physical block size

2017-02-23 Thread Pali Rohár
On Monday 30 January 2017 18:43:12 Pali Rohár wrote:
> On Monday 30 January 2017 17:17:03 Alan Stern wrote:
> > On Sun, 29 Jan 2017, Pali Rohár wrote:
> > > On Wednesday 11 January 2017 16:23:29 Alan Stern wrote:
> > > > On Tue, 10 Jan 2017, James Bottomley wrote:
> > > > > On Tue, 2017-01-10 at 16:00 -0500, Alan Stern wrote:
> > > > > > In theory, I suppose we could change the kernel so that it
> > > > > > would default to READ CAPACITY(16) for devices that report a
> > > > > > SCSI level
> > > > > > 
> > > > > > >= 3, or something along those lines.  In general we hesitate
> > > > > > >to
> > > > > > 
> > > > > > make changes of this sort, because they almost always end up
> > > > > > breaking _some_ devices -- and if that happens then the
> > > > > > change is reverted, with no exceptions.  Linus has a very
> > > > > > strict rule about not breaking working systems.
> > > > > 
> > > > > You shouldn't have to change anything: it already does
> > > > > (otherwise how else would we detect physical exponent for
> > > > > proper SCSI devices) see sd.c:sd_try_rc16_first().  It always
> > > > > returns false for USB because you set sdev->try_rc_10_first
> > > > 
> > > > In fact, this approach probably won't work.  See Bugzilla entries
> > > > #43265 and #43391.  The devices in those reports claimed to be
> > > > ANSI level 4, but they failed anyway.
> > > 
> > > Seems those devices return capacity 0x7F0001 or
> > > 0xFF0001 Maybe there is some error pattern?
> > 
> > As far as I can tell, they both reported 0xFF0001.  That's a
> > pattern -- unless somebody really does have a storage device that
> > large (18 exabytes).  For the time being, perhaps we can ignore this
> > possibility.
> > 
> > > > If you guys want to try the quirk flag, you can apply the patch
> > > > below. Then set the usb-storage module parameter
> > > > quirks=::k where  and  are the Vendor and
> > > > Product ID codes for your device (as 4 hex digits).
> > > > 
> > > > In the long run, however, this is not a viable approach.  We'd be
> > > > better off with an explicit blacklist.
> > > 
> > > Ok, so what are next steps? I think that explicit blacklist would
> > > be needed if "bad" devices is less.
> > > 
> > > How many bug reports were there?
> > 
> > I don't know.
> > 
> > Anyway, please try out the patch below.  I don't know if it will be
> > acceptable to the SCSI maintainers, but we should at least make sure
> > it fixes your problem before submitting it.
> 
> I'm not original reporter of this problem.
> 
> Dainius, can you test it?

Just want to remind this patch so it will not be forgotten...

> > Alan Stern
> > 
> > 
> > 
> > 
> > Index: usb-4.x/drivers/scsi/sd.c
> > ===
> > --- usb-4.x.orig/drivers/scsi/sd.c
> > +++ usb-4.x/drivers/scsi/sd.c
> > @@ -2157,6 +2157,13 @@ static int read_capacity_16(struct scsi_
> > return -ENODEV;
> > }
> > 
> > +   /* Some buggy devices report an impossibly large size */
> > +   if (lba >= (1ULL << 54)) {
> > +   sd_printk(KERN_WARNING, sdkp, "Read Capacity(16) returned 
> > excessively large value: %llu", lba);
> > +   sdkp->capacity = 0;
> > +   return -EINVAL;
> > +   }
> > +
> > if ((sizeof(sdkp->capacity) == 4) && (lba >= 0xULL)) {
> > sd_printk(KERN_ERR, sdkp, "Too big for this kernel. Use a "
> > "kernel compiled with support for large block "
> > Index: usb-4.x/drivers/usb/storage/scsiglue.c
> > ===
> > --- usb-4.x.orig/drivers/usb/storage/scsiglue.c
> > +++ usb-4.x/drivers/usb/storage/scsiglue.c
> > @@ -247,8 +247,11 @@ static int slave_configure(struct scsi_d
> >  * Tell the SCSI layer to try READ_CAPACITY_10 first.
> >  * However some USB 3.0 drive enclosures return capacity
> >  * modulo 2TB. Those must use READ_CAPACITY_16
> > +*
> > +* Assume SPC3 or later devices can handle READ_CAPACITY_16.
> >  */
> > -   if (!(us->fflags & US_FL_NEEDS_CAP16))
> > +   if (sdev->scsi_level <= SCSI_SPC_2 &&
> > +   !(us->fflags & US_FL_NEEDS_CAP16))
> > sdev->try_rc_10_first = 1;
> > 
> > /* assume SPC3 or latter devices support sense size > 18 */
> 

-- 
Pali Rohár
pali.ro...@gmail.com


Re: [PATCHv3 01/10] mpt3sas: switch to pci_alloc_irq_vectors

2017-02-23 Thread Sreekanth Reddy
On Thu, Feb 23, 2017 at 6:22 AM, Martin K. Petersen
 wrote:
>> "Christoph" == Christoph Hellwig  writes:
>
> Christoph> Martin, can we get at least this patch still in for 4.11?
> Christoph> I'd really like to see as many intance of the old MSI-X
> Christoph> allocation and IRQ affinity mess dead as soon as possible.
>
> Me too. I'll queue it up for 4.11 unless Broadcom objects. And then
> we'll do the rest for 4.12.

This patch looks good. Please consider this patch for 4.11.

We need some time to review remaining patches as it has lot code
refinement and we need to cover some basic test cases.

Thanks,
Sreekanth

>
> --
> Martin K. Petersen  Oracle Linux Engineering