Re: possible circular locking dependency detected [was: linux-next: Tree for Aug 22]

2017-08-23 Thread Peter Zijlstra
On Wed, Aug 23, 2017 at 09:03:04AM +0900, Byungchul Park wrote:
> On Tue, Aug 22, 2017 at 09:43:56PM +, Bart Van Assche wrote:

> The report is talking about the following lockup:
> 
> A work in a worker A task work on exit to user
> -- ---
> mutex_lock(&bdev->bd_mutex)
>mutext_lock(&bdev->bd_mutex)
> blk_execute_rq()
>wait_for_completion_io_timeout(&A)
>complete(&A)
> 
> Is this impossible?
> 
> To Peterz,
> 
> Anyway I wanted to avoid lockdep reports in the case using a timeout
> interface. Do you think it's still worth reporting the kind of lockup?

Yes, people might not have expected to hit the timeout on this. They
might think timeout means a dead device or something like that.

I'd like to heard from the block folks if this was constructed thus on
purpose though.


Re: [v4.13-rc BUG] system lockup when running big buffered write(4M) to IB SRP via mpath

2017-08-23 Thread Ming Lei
On Wed, Aug 09, 2017 at 05:10:01PM +, Bart Van Assche wrote:
> On Wed, 2017-08-09 at 12:43 -0400, Laurence Oberman wrote:
> > Your latest patch on stock upstream without Ming's latest patches is 
> > behaving for me.
> > 
> > As already mentioned, the requeue -11 and clone failure messages are 
> > gone and I am not actually seeing any soft lockups or hard lockups.
> > 
> > When Ming gets back I will work with him on his patch set and the lockups.
> > 
> > Running 10 parallel writes which easily trips into soft lockups on 
> > Ming's kernel (even with your patch) has been stable here on 4.13-RC3 
> > with your patch.
> > 
> > I will leave it running for a while now but the patch is good.
> > 
> > If it survives 4 hours I will add a Tested-by to your latest patch.
> 
> Hello Laurence,
> 
> I'm working on an additional patch that should reduce unnecessary requeuing
> even further. I will let you know when it's ready.
> 
> Additionally, please trim e-mails when replying such that e-mails do not get
> too long.

soft lockup still can be observed easily with patch d4acf3650c7c(
block: Make blk_mq_delay_kick_requeue_list() rerun the queue at a quiet time),
but no hard lockup.

With the patchset of 'blk-mq-sched: improve SCSI-MQ performance', hard
lockup can be observed following some failure log:

[  269.277653] device-mapper: multipath: blk_get_request() returned -11 
- requeuing
[  269.321244] device-mapper: multipath: blk_get_request() returned -11 
- requeuing
...
[  273.421688] scsi host2: SRP abort called
[  273.444577] scsi host2: Sending SRP abort for tag 0x6007e
[  273.673871] scsi host2: Null scmnd for RSP w/tag 0x06007e 
received on ch 6 / QP 0x30
...
[  274.372110] device-mapper: multipath: blk_get_request() returned -11 
- requeuing
[  278.658671] scsi host2: SRP abort called
[  278.690630] scsi host2: SRP abort called
[  278.717634] scsi host2: SRP abort called
[  278.745629] scsi host2: SRP abort called
[  279.083227] multipath_clone_and_map: 1092 callbacks suppressed

[  296.210503] scsi host2: SRP reset_device called

[  303.784287] NMI watchdog: Watchdog detected hard LOCKUP on cpu 10

The trick thing is that both hard lockup and soft lockup share
one same stack trace.

Another question, I don't understand why request is allocated with
GFP_ATOMIC in multipath_clone_and_map(), looks it shouldn't be
necessary.


--
Ming


[PATCH v3 00/14] megaraid_sas: Updates for scsi-next

2017-08-23 Thread Shivasharan S
Changes from v2:
- Patch 9: Updated patch description
- Dropped patch 11 of the last series. As per discussion
  with Christoph Hellwig, there was concern over the blk-mq
  specific hack in the changes. Also this needs to be tested with
  latest blk-mq performance improvements patchset from Ming.
  We will follow up on this patch during next phase submission.
- Rebased all patches to latest scsi/for-next branch.

Changes from v1:
- Patch 4: Updated patch description
- Patch 9: Cleanup ld_drv_map in case ld_map allocation fails

Shivasharan S (14):
  megaraid_sas: mismatch of allocated MFI frame size and length exposed
in MFI MPT pass through command
  megaraid_sas: set minimum value of resetwaittime to be 1 secs
  megaraid_sas: Use synchronize_irq in target reset case
  megaraid_sas: Call megasas_complete_cmd_dpc_fusion every 1 second
while there are pending commands
  megaraid_sas: Do not re-fire shutdown DCMD after OCR
  megaraid_sas: Fix endianness issues in DCMD handling
  megaraid_sas: Check valid aen class range to avoid kernel panic
  megaraid_sas: Use SMID for Task abort case only
  megaraid_sas: use vmalloc for crash dump buffers and driver's local
RAID map
  megaraid_sas: Return pended IOCTLs with cmd_status
MFI_STAT_WRONG_STATE in case adapter is dead
  megaraid_sas: replace internal FALSE/TRUE definitions with false/true
  megaraid_sas: modified few prints in OCR and IOC INIT path
  megaraid_sas: call megasas_dump_frame with correct IO frame size
  megaraid_sas: driver version upgrade

 drivers/scsi/megaraid/megaraid_sas.h|   5 +-
 drivers/scsi/megaraid/megaraid_sas_base.c   |  39 +--
 drivers/scsi/megaraid/megaraid_sas_fp.c |  40 +++
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 170 ++--
 4 files changed, 154 insertions(+), 100 deletions(-)

-- 
1.8.3.1



[PATCH v3 02/14] megaraid_sas: set minimum value of resetwaittime to be 1 secs

2017-08-23 Thread Shivasharan S
Setting resetwaittime to 0 during a FW fault will result in driver
not calling the OCR.

Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
Cc: sta...@vger.kernel.org
Reviewed-by: Hannes Reinecke 
Reviewed-by: Tomas Henzl 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 5202c2f..2c309ec 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -5479,7 +5479,8 @@ static int megasas_init_fw(struct megasas_instance 
*instance)
instance->throttlequeuedepth =
MEGASAS_THROTTLE_QUEUE_DEPTH;
 
-   if (resetwaittime > MEGASAS_RESET_WAIT_TIME)
+   if ((resetwaittime < 1) ||
+   (resetwaittime > MEGASAS_RESET_WAIT_TIME))
resetwaittime = MEGASAS_RESET_WAIT_TIME;
 
if ((scmd_timeout < 10) || (scmd_timeout > MEGASAS_DEFAULT_CMD_TIMEOUT))
-- 
1.8.3.1



[PATCH v3 05/14] megaraid_sas: Do not re-fire shutdown DCMD after OCR

2017-08-23 Thread Shivasharan S
Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
Reviewed-by: Hannes Reinecke 
Reviewed-by: Tomas Henzl 
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index d33e833..6efa72a 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3624,6 +3624,15 @@ void megasas_refire_mgmt_cmd(struct megasas_instance 
*instance)
 
if (!smid)
continue;
+
+   /* Do not refire shutdown command */
+   if (le32_to_cpu(cmd_mfi->frame->dcmd.opcode) ==
+   MR_DCMD_CTRL_SHUTDOWN) {
+   cmd_mfi->frame->dcmd.cmd_status = MFI_STAT_OK;
+   megasas_complete_cmd(instance, cmd_mfi, DID_OK);
+   continue;
+   }
+
req_desc = megasas_get_request_descriptor
(instance, smid - 1);
refire_cmd = req_desc && ((cmd_mfi->frame->dcmd.opcode !=
-- 
1.8.3.1



[PATCH v3 03/14] megaraid_sas: Use synchronize_irq in target reset case

2017-08-23 Thread Shivasharan S
Similar to task abort case, use synchronize_irq API in target reset case.
Also, remove redundant call to megasas_complete_cmd_dpc_fusion
after calling megasas_sync_irqs in task abort case.

Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
Reviewed-by: Hannes Reinecke 
Reviewed-by: Tomas Henzl 
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 84cd4f8..28c3264 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3832,8 +3832,6 @@ static int megasas_track_scsiio(struct megasas_instance 
*instance,
else {
instance->instancet->disable_intr(instance);
megasas_sync_irqs((unsigned long)instance);
-   megasas_complete_cmd_dpc_fusion
-   ((unsigned long)instance);
instance->instancet->enable_intr(instance);
if (scsi_lookup->scmd == NULL)
break;
@@ -3845,9 +3843,7 @@ static int megasas_track_scsiio(struct megasas_instance 
*instance,
if ((channel == 0x) && (id == 0x))
break;
instance->instancet->disable_intr(instance);
-   msleep(1000);
-   megasas_complete_cmd_dpc_fusion
-   ((unsigned long)instance);
+   megasas_sync_irqs((unsigned long)instance);
rc = megasas_track_scsiio(instance, id, channel);
instance->instancet->enable_intr(instance);
 
-- 
1.8.3.1



[PATCH v3 01/14] megaraid_sas: mismatch of allocated MFI frame size and length exposed in MFI MPT pass through command

2017-08-23 Thread Shivasharan S
 Fix - Driver allocated 256 byte MFI frames bytes but while sending MFI
 frame (embedded inside chain frame of MPT frame) to firmware, driver
 sets the length as 4k. This results in DMA read error messages during
 boot.

Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
Cc: sta...@vger.kernel.org
Reviewed-by: Hannes Reinecke 
Reviewed-by: Tomas Henzl 
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 6b9db73..84cd4f8 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3289,7 +3289,7 @@ irqreturn_t megasas_isr_fusion(int irq, void *devp)
mpi25_ieee_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT |
MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR;
 
-   mpi25_ieee_chain->Length = cpu_to_le32(instance->max_chain_frame_sz);
+   mpi25_ieee_chain->Length = cpu_to_le32(instance->mfi_frame_size);
 }
 
 /**
-- 
1.8.3.1



[PATCH v3 04/14] megaraid_sas: Call megasas_complete_cmd_dpc_fusion every 1 second while there are pending commands

2017-08-23 Thread Shivasharan S
Fix - megasas_wait_for_outstanding_fusion checks for pending commands every
1second. But megasas_complete_cmd_dpc_fusion is only called every 5seconds.
If the commands are already completed by firmware, there is an additional
delay of 5seconds before driver will process completion for these commands.

Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
Reviewed-by: Tomas Henzl 
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 28c3264..d33e833 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3558,6 +3558,7 @@ int megasas_wait_for_outstanding_fusion(struct 
megasas_instance *instance,
}
}
 
+   megasas_complete_cmd_dpc_fusion((unsigned long)instance);
outstanding = atomic_read(&instance->fw_outstanding);
if (!outstanding)
goto out;
@@ -3566,8 +3567,6 @@ int megasas_wait_for_outstanding_fusion(struct 
megasas_instance *instance,
dev_notice(&instance->pdev->dev, "[%2d]waiting for %d "
   "commands to complete for scsi%d\n", i,
   outstanding, instance->host->host_no);
-   megasas_complete_cmd_dpc_fusion(
-   (unsigned long)instance);
}
msleep(1000);
}
-- 
1.8.3.1



[PATCH v3 06/14] megaraid_sas: Fix endianness issues in DCMD handling

2017-08-23 Thread Shivasharan S
Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
Reviewed-by: Hannes Reinecke 
Reviewed-by: Tomas Henzl 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 2c309ec..b8b4654 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -6866,6 +6866,7 @@ static int megasas_set_crash_dump_params_ioctl(struct 
megasas_cmd *cmd)
void *sense = NULL;
dma_addr_t sense_handle;
unsigned long *sense_ptr;
+   u32 opcode;
 
memset(kbuff_arr, 0, sizeof(kbuff_arr));
 
@@ -6893,15 +6894,16 @@ static int megasas_set_crash_dump_params_ioctl(struct 
megasas_cmd *cmd)
cmd->frame->hdr.flags &= cpu_to_le16(~(MFI_FRAME_IEEE |
   MFI_FRAME_SGL64 |
   MFI_FRAME_SENSE64));
+   opcode = le32_to_cpu(cmd->frame->dcmd.opcode);
 
-   if (cmd->frame->dcmd.opcode == MR_DCMD_CTRL_SHUTDOWN) {
+   if (opcode == MR_DCMD_CTRL_SHUTDOWN) {
if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS) {
megasas_return_cmd(instance, cmd);
return -1;
}
}
 
-   if (cmd->frame->dcmd.opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) {
+   if (opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) {
error = megasas_set_crash_dump_params_ioctl(cmd);
megasas_return_cmd(instance, cmd);
return error;
@@ -6975,8 +6977,7 @@ static int megasas_set_crash_dump_params_ioctl(struct 
megasas_cmd *cmd)
cmd->sync_cmd = 0;
dev_err(&instance->pdev->dev,
"return -EBUSY from %s %d opcode 0x%x 
cmd->cmd_status_drv 0x%x\n",
-   __func__, __LINE__, cmd->frame->dcmd.opcode,
-   cmd->cmd_status_drv);
+   __func__, __LINE__, opcode, cmd->cmd_status_drv);
return -EBUSY;
}
 
-- 
1.8.3.1



[PATCH v3 07/14] megaraid_sas: Check valid aen class range to avoid kernel panic

2017-08-23 Thread Shivasharan S
Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
Cc: sta...@vger.kernel.org
Reviewed-by: Hannes Reinecke 
Reviewed-by: Tomas Henzl 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index b8b4654..df2332f 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -5651,6 +5651,14 @@ static void megasas_release_mfi(struct megasas_instance 
*instance)
prev_aen.word =
le32_to_cpu(instance->aen_cmd->frame->dcmd.mbox.w[1]);
 
+   if ((curr_aen.members.class < MFI_EVT_CLASS_DEBUG) ||
+   (curr_aen.members.class > MFI_EVT_CLASS_DEAD)) {
+   dev_info(&instance->pdev->dev,
+"%s %d out of range class %d send by 
application\n",
+__func__, __LINE__, curr_aen.members.class);
+   return 0;
+   }
+
/*
 * A class whose enum value is smaller is inclusive of all
 * higher values. If a PROGRESS (= -1) was previously
-- 
1.8.3.1



[PATCH v3 09/14] megaraid_sas: use vmalloc for crash dump buffers and driver's local RAID map

2017-08-23 Thread Shivasharan S
Driver's local RAID map is accessed frequently. We will first try to get
memory from __get_free_pages. If this fails, fall back to using vmalloc.
For crash dump buffers always prefer vmalloc.

Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
Reviewed-by: Hannes Reinecke 
Reviewed-by: Tomas Henzl 
---
 drivers/scsi/megaraid/megaraid_sas.h|   1 -
 drivers/scsi/megaraid/megaraid_sas_base.c   |  12 ++-
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 121 ++--
 3 files changed, 88 insertions(+), 46 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h 
b/drivers/scsi/megaraid/megaraid_sas.h
index 2b209bb..6d9f111 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -2115,7 +2115,6 @@ struct megasas_instance {
u32 *crash_dump_buf;
dma_addr_t crash_dump_h;
void *crash_buf[MAX_CRASH_DUMP_SIZE];
-   u32 crash_buf_pages;
unsigned intfw_crash_buffer_size;
unsigned intfw_crash_state;
unsigned intfw_crash_buffer_offset;
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index df2332f..6b715bb 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -49,6 +49,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -6671,9 +6672,14 @@ static void megasas_detach_one(struct pci_dev *pdev)
  fusion->max_map_sz,
  fusion->ld_map[i],
  fusion->ld_map_phys[i]);
-   if (fusion->ld_drv_map[i])
-   free_pages((ulong)fusion->ld_drv_map[i],
-   fusion->drv_map_pages);
+   if (fusion->ld_drv_map[i]) {
+   if (is_vmalloc_addr(fusion->ld_drv_map[i]))
+   vfree(fusion->ld_drv_map[i]);
+   else
+   free_pages((ulong)fusion->ld_drv_map[i],
+  fusion->drv_map_pages);
+   }
+
if (fusion->pd_seq_sync[i])
dma_free_coherent(&instance->pdev->dev,
pd_seq_map_sz,
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 6da1663..bd89962 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1263,6 +1263,80 @@ static int megasas_create_sg_sense_fusion(struct 
megasas_instance *instance)
 }
 
 /**
+ * megasas_allocate_raid_maps -Allocate memory for RAID maps
+ * @instance:  Adapter soft state
+ *
+ * return: if success: return 0
+ * failed:  return -ENOMEM
+ */
+static inline int megasas_allocate_raid_maps(struct megasas_instance *instance)
+{
+   struct fusion_context *fusion;
+   int i = 0;
+
+   fusion = instance->ctrl_context;
+
+   fusion->drv_map_pages = get_order(fusion->drv_map_sz);
+
+   for (i = 0; i < 2; i++) {
+   fusion->ld_map[i] = NULL;
+
+   fusion->ld_drv_map[i] = (void *)
+   __get_free_pages(__GFP_ZERO | GFP_KERNEL,
+fusion->drv_map_pages);
+
+   if (!fusion->ld_drv_map[i]) {
+   fusion->ld_drv_map[i] = vzalloc(fusion->drv_map_sz);
+
+   if (!fusion->ld_drv_map[i]) {
+   dev_err(&instance->pdev->dev,
+   "Could not allocate memory for local 
map"
+   " size requested: %d\n",
+   fusion->drv_map_sz);
+   goto ld_drv_map_alloc_fail;
+   }
+   }
+   }
+
+   for (i = 0; i < 2; i++) {
+   fusion->ld_map[i] = dma_alloc_coherent(&instance->pdev->dev,
+  fusion->max_map_sz,
+  &fusion->ld_map_phys[i],
+  GFP_KERNEL);
+   if (!fusion->ld_map[i]) {
+   dev_err(&instance->pdev->dev,
+   "Could not allocate memory for map info 
%s:%d\n",
+   __func__, __LINE__);
+   goto ld_map_alloc_fail;
+   }
+   }
+
+   return 0;
+
+ld_map_alloc_fail:
+   for (i = 0; i < 2; i++) {
+   if (fusion->ld_map[i])
+   dma_free_coherent(&instance->pdev->dev,
+   

[PATCH v3 08/14] megaraid_sas: Use SMID for Task abort case only

2017-08-23 Thread Shivasharan S
Fix - In TM code, smid_task is valid only in case of task aborts.

Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
Reviewed-by: Hannes Reinecke 
Reviewed-by: Tomas Henzl 
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 6efa72a..6da1663 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3760,7 +3760,7 @@ static int megasas_track_scsiio(struct megasas_instance 
*instance,
struct megasas_cmd_fusion *cmd_fusion;
struct megasas_cmd *cmd_mfi;
union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
-   struct fusion_context *fusion;
+   struct fusion_context *fusion = NULL;
struct megasas_cmd_fusion *scsi_lookup;
int rc;
struct MPI2_SCSI_TASK_MANAGE_REPLY *mpi_reply;
@@ -3787,8 +3787,6 @@ static int megasas_track_scsiio(struct megasas_instance 
*instance,
cmd_fusion->request_desc = req_desc;
req_desc->Words = 0;
 
-   scsi_lookup = fusion->cmd_list[smid_task - 1];
-
mr_request = (struct MR_TASK_MANAGE_REQUEST *) cmd_fusion->io_request;
memset(mr_request, 0, sizeof(struct MR_TASK_MANAGE_REQUEST));
mpi_request = (struct MPI2_SCSI_TASK_MANAGE_REQUEST *) 
&mr_request->TmRequest;
@@ -3835,6 +3833,8 @@ static int megasas_track_scsiio(struct megasas_instance 
*instance,
rc = SUCCESS;
switch (type) {
case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
+   scsi_lookup = fusion->cmd_list[smid_task - 1];
+
if (scsi_lookup->scmd == NULL)
break;
else {
-- 
1.8.3.1



[PATCH v3 10/14] megaraid_sas: Return pended IOCTLs with cmd_status MFI_STAT_WRONG_STATE in case adapter is dead

2017-08-23 Thread Shivasharan S
Fix - After a kill adapter, since the cmd_status is not set the
IOCTLs will be hung in driver resulting in application hang.
Set cmd_status MFI_STAT_WRONG_STATE when completing pended IOCTLs.

Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
Cc: sta...@vger.kernel.org
Reviewed-by: Hannes Reinecke 
Reviewed-by: Tomas Henzl 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 6b715bb..a949a21 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -1996,9 +1996,12 @@ static void megasas_complete_outstanding_ioctls(struct 
megasas_instance *instanc
if (cmd_fusion->sync_cmd_idx != (u32)ULONG_MAX) {
cmd_mfi = 
instance->cmd_list[cmd_fusion->sync_cmd_idx];
if (cmd_mfi->sync_cmd &&
-   cmd_mfi->frame->hdr.cmd != 
MFI_CMD_ABORT)
+   (cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT)) 
{
+   cmd_mfi->frame->hdr.cmd_status =
+   MFI_STAT_WRONG_STATE;
megasas_complete_cmd(instance,
 cmd_mfi, DID_OK);
+   }
}
}
} else {
-- 
1.8.3.1



[PATCH v3 12/14] megaraid_sas: modified few prints in OCR and IOC INIT path

2017-08-23 Thread Shivasharan S
Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
Reviewed-by: Hannes Reinecke 
Reviewed-by: Tomas Henzl 
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 23 ++-
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index bd89962..11bd2e6 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -916,7 +916,6 @@ static int megasas_create_sg_sense_fusion(struct 
megasas_instance *instance)
ret = 1;
goto fail_fw_init;
}
-   dev_info(&instance->pdev->dev, "Init cmd success\n");
 
ret = 0;
 
@@ -927,6 +926,10 @@ static int megasas_create_sg_sense_fusion(struct 
megasas_instance *instance)
  sizeof(struct MPI2_IOC_INIT_REQUEST),
  IOCInitMessage, ioc_init_handle);
 fail_get_cmd:
+   dev_err(&instance->pdev->dev,
+   "Init cmd return status %s for SCSI host %d\n",
+   ret ? "FAILED" : "SUCCESS", instance->host->host_no);
+
return ret;
 }
 
@@ -4314,9 +4317,6 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int 
reason)
megasas_fusion_update_can_queue(instance, OCR_CONTEXT);
 
if (megasas_ioc_init_fusion(instance)) {
-   dev_warn(&instance->pdev->dev,
-  "megasas_ioc_init_fusion() failed! for "
-  "scsi%d\n", instance->host->host_no);
if (instance->requestorId && !reason)
goto fail_kill_adapter;
else
@@ -4362,6 +4362,10 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int 
reason)
instance->instancet->enable_intr(instance);
atomic_set(&instance->adprecovery, 
MEGASAS_HBA_OPERATIONAL);
 
+   dev_info(&instance->pdev->dev, "Interrupts are enabled 
and"
+   " controller is OPERATIONAL for scsi:%d\n",
+   instance->host->host_no);
+
/* Restart SR-IOV heartbeat */
if (instance->requestorId) {
if (!megasas_sriov_start_heartbeat(instance, 0))
@@ -4373,11 +4377,6 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int 
reason)
instance->skip_heartbeat_timer_del = 1;
}
 
-   /* Adapter reset completed successfully */
-   dev_warn(&instance->pdev->dev, "Reset "
-  "successful for scsi%d.\n",
-   instance->host->host_no);
-
if (instance->crash_dump_drv_support &&
instance->crash_dump_app_support)
megasas_set_crash_dump_params(instance,
@@ -4387,6 +4386,12 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int 
reason)
MR_CRASH_BUF_TURN_OFF);
 
retval = SUCCESS;
+
+   /* Adapter reset completed successfully */
+   dev_warn(&instance->pdev->dev,
+"Reset successful for scsi%d.\n",
+instance->host->host_no);
+
goto out;
}
 fail_kill_adapter:
-- 
1.8.3.1



[PATCH v3 14/14] megaraid_sas: driver version upgrade

2017-08-23 Thread Shivasharan S
Signed-off-by: Shivasharan S 
Reviewed-by: Hannes Reinecke 
Reviewed-by: Tomas Henzl 
---
 drivers/scsi/megaraid/megaraid_sas.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h 
b/drivers/scsi/megaraid/megaraid_sas.h
index 6d9f111..a6722c9 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -35,8 +35,8 @@
 /*
  * MegaRAID SAS Driver meta data
  */
-#define MEGASAS_VERSION"07.701.17.00-rc1"
-#define MEGASAS_RELDATE"March 2, 2017"
+#define MEGASAS_VERSION"07.702.06.00-rc1"
+#define MEGASAS_RELDATE"June 21, 2017"
 
 /*
  * Device IDs
-- 
1.8.3.1



[PATCH v3 13/14] megaraid_sas: call megasas_dump_frame with correct IO frame size

2017-08-23 Thread Shivasharan S
Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
Reviewed-by: Hannes Reinecke 
Reviewed-by: Tomas Henzl 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index a949a21..5183184 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -2795,7 +2795,7 @@ static int megasas_reset_bus_host(struct scsi_cmnd *scmd)
cmd = (struct megasas_cmd_fusion *)scmd->SCp.ptr;
if (cmd)
megasas_dump_frame(cmd->io_request,
-   sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
+   MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE);
ret = megasas_reset_fusion(scmd->device->host,
SCSIIO_TIMEOUT_OCR);
} else
-- 
1.8.3.1



[PATCH v3 11/14] megaraid_sas: replace internal FALSE/TRUE definitions with false/true

2017-08-23 Thread Shivasharan S
Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
Reviewed-by: Hannes Reinecke 
Reviewed-by: Tomas Henzl 
---
 drivers/scsi/megaraid/megaraid_sas_fp.c | 40 +
 1 file changed, 15 insertions(+), 25 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c 
b/drivers/scsi/megaraid/megaraid_sas_fp.c
index 62affa7..ecc699a 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -67,16 +67,6 @@
 #define ABS_DIFF(a, b)   (((a) > (b)) ? ((a) - (b)) : ((b) - (a)))
 #define MR_LD_STATE_OPTIMAL 3
 
-#ifdef FALSE
-#undef FALSE
-#endif
-#define FALSE 0
-
-#ifdef TRUE
-#undef TRUE
-#endif
-#define TRUE 1
-
 #define SPAN_ROW_SIZE(map, ld, index_) (MR_LdSpanPtrGet(ld, index_, 
map)->spanRowSize)
 #define SPAN_ROW_DATA_SIZE(map_, ld, index_)   (MR_LdSpanPtrGet(ld, index_, 
map)->spanRowDataSize)
 #define SPAN_INVALID  0xff
@@ -709,7 +699,7 @@ static u8 mr_spanset_get_phy_params(struct megasas_instance 
*instance, u32 ld,
u32 pd, arRef, r1_alt_pd;
u8  physArm, span;
u64 row;
-   u8  retval = TRUE;
+   u8  retval = true;
u64 *pdBlock = &io_info->pdBlock;
__le16  *pDevHandle = &io_info->devHandle;
u8  *pPdInterface = &io_info->pd_interface;
@@ -727,7 +717,7 @@ static u8 mr_spanset_get_phy_params(struct megasas_instance 
*instance, u32 ld,
if (raid->level == 6) {
logArm = get_arm_from_strip(instance, ld, stripRow, map);
if (logArm == -1U)
-   return FALSE;
+   return false;
rowMod = mega_mod64(row, SPAN_ROW_SIZE(map, ld, span));
armQ = SPAN_ROW_SIZE(map, ld, span) - 1 - rowMod;
arm = armQ + 1 + logArm;
@@ -738,7 +728,7 @@ static u8 mr_spanset_get_phy_params(struct megasas_instance 
*instance, u32 ld,
/* Calculate the arm */
physArm = get_arm(instance, ld, span, stripRow, map);
if (physArm == 0xFF)
-   return FALSE;
+   return false;
 
arRef   = MR_LdSpanArrayGet(ld, span, map);
pd  = MR_ArPdGet(arRef, physArm, map);
@@ -812,7 +802,7 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 
ld, u64 stripRow,
u32 pd, arRef, r1_alt_pd;
u8  physArm, span;
u64 row;
-   u8  retval = TRUE;
+   u8  retval = true;
u64 *pdBlock = &io_info->pdBlock;
__le16  *pDevHandle = &io_info->devHandle;
u8  *pPdInterface = &io_info->pd_interface;
@@ -829,7 +819,7 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 
ld, u64 stripRow,
u32 rowMod, armQ, arm;
 
if (raid->rowSize == 0)
-   return FALSE;
+   return false;
/* get logical row mod */
rowMod = mega_mod64(row, raid->rowSize);
armQ = raid->rowSize-1-rowMod; /* index of Q drive */
@@ -839,7 +829,7 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 
ld, u64 stripRow,
physArm = (u8)arm;
} else  {
if (raid->modFactor == 0)
-   return FALSE;
+   return false;
physArm = MR_LdDataArmGet(ld,  mega_mod64(stripRow,
  raid->modFactor),
  map);
@@ -851,7 +841,7 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 
ld, u64 stripRow,
} else {
span = (u8)MR_GetSpanBlock(ld, row, pdBlock, map);
if (span == SPAN_INVALID)
-   return FALSE;
+   return false;
}
 
/* Get the array on which this span is present */
@@ -954,7 +944,7 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 
ld, u64 stripRow,
 */
if (raid->rowDataSize == 0) {
if (MR_LdSpanPtrGet(ld, 0, map)->spanRowDataSize == 0)
-   return FALSE;
+   return false;
else if (instance->UnevenSpanSupport) {
io_info->IoforUnevenSpan = 1;
} else {
@@ -963,7 +953,7 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 
ld, u64 stripRow,
"rowDataSize = 0x%0x,"
"but there is _NO_ UnevenSpanSupport\n",
MR_LdSpanPtrGet(ld, 0, map)->spanRowDataSize);
-   return FALSE;
+   return false;
}
}
 
@@ -988,7 +978,7 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 
ld, u64 stripRow,
dev_info(&instance->pdev->dev, "return from %s %d."
"Send IO w/o region lock.\n",
   

Re: [Regression 4.13-rc1] Resume does not work on Lenovo X60t

2017-08-23 Thread Christoph Hellwig
Are you running with blk-mq enabled?  Also this never
occured with 4.12, right?  Were you also running with or
without blk-mq for scsi there?


Re: [Regression 4.13-rc1] Resume does not work on Lenovo X60t

2017-08-23 Thread Paul Menzel

Dear Christoph,


On 08/23/17 13:48, Christoph Hellwig wrote:

Are you running with blk-mq enabled?  Also this never
occured with 4.12, right?  Were you also running with or
without blk-mq for scsi there?


To my knowledge, I am using the defaults from Debian 9. I’ll check in 
one week, as I am away from the system.



Kind regards,

Paul


Re: [v4.13-rc BUG] system lockup when running big buffered write(4M) to IB SRP via mpath

2017-08-23 Thread Ming Lei
On Wed, Aug 23, 2017 at 07:35:26PM +0800, Ming Lei wrote:
> On Wed, Aug 09, 2017 at 05:10:01PM +, Bart Van Assche wrote:
> > On Wed, 2017-08-09 at 12:43 -0400, Laurence Oberman wrote:
> > > Your latest patch on stock upstream without Ming's latest patches is 
> > > behaving for me.
> > > 
> > > As already mentioned, the requeue -11 and clone failure messages are 
> > > gone and I am not actually seeing any soft lockups or hard lockups.
> > > 
> > > When Ming gets back I will work with him on his patch set and the lockups.
> > > 
> > > Running 10 parallel writes which easily trips into soft lockups on 
> > > Ming's kernel (even with your patch) has been stable here on 4.13-RC3 
> > > with your patch.
> > > 
> > > I will leave it running for a while now but the patch is good.
> > > 
> > > If it survives 4 hours I will add a Tested-by to your latest patch.
> > 
> > Hello Laurence,
> > 
> > I'm working on an additional patch that should reduce unnecessary requeuing
> > even further. I will let you know when it's ready.
> > 
> > Additionally, please trim e-mails when replying such that e-mails do not get
> > too long.
> 
> soft lockup still can be observed easily with patch d4acf3650c7c(
> block: Make blk_mq_delay_kick_requeue_list() rerun the queue at a quiet time),
> but no hard lockup.
> 
> With the patchset of 'blk-mq-sched: improve SCSI-MQ performance', hard
> lockup can be observed following some failure log:
> 
>   [  269.277653] device-mapper: multipath: blk_get_request() returned -11 
> - requeuing
>   [  269.321244] device-mapper: multipath: blk_get_request() returned -11 
> - requeuing
>   ...
>   [  273.421688] scsi host2: SRP abort called
>   [  273.444577] scsi host2: Sending SRP abort for tag 0x6007e
>   [  273.673871] scsi host2: Null scmnd for RSP w/tag 0x06007e 
> received on ch 6 / QP 0x30
>   ...
>   [  274.372110] device-mapper: multipath: blk_get_request() returned -11 
> - requeuing
>   [  278.658671] scsi host2: SRP abort called
>   [  278.690630] scsi host2: SRP abort called
>   [  278.717634] scsi host2: SRP abort called
>   [  278.745629] scsi host2: SRP abort called
>   [  279.083227] multipath_clone_and_map: 1092 callbacks suppressed
>   
>   [  296.210503] scsi host2: SRP reset_device called
>   
>   [  303.784287] NMI watchdog: Watchdog detected hard LOCKUP on cpu 10
> 
> The trick thing is that both hard lockup and soft lockup share
> one same stack trace.

Actually I can reproduce hard lockup too on the latest linus tree(v4.13-rc6+)
by just making the test more aggressive:

1) run hammer_write.sh 32-concurrently. 
2) write 8M each time

So it isn't the patchset of 'blk-mq-sched: improve SCSI-MQ performance'
which causes the lockup.

There must be issue somewhere else, and one thing I saw is that
dm's req's completion handling isn't very efficient:

- when low level driver's req is completed, blk_update_request()
is called from scsi_end_request()

- inside blk_update_request(), end_clone_bio() is called for
each bio

- in end_clone_bio(), blk_update_request() is called to
do partial update for the dm req. That means if one request
has N bios, the same dm req need to do the expensive partial
update N times. In theory, the partial update might be avoided,
I guess the reason is that the dm rq can't be retrieved
via the low level driver's rq.


[1] hard lockup log

[  434.068240] NMI watchdog: Watchdog detected hard LOCKUP on cpu 2
[  434.068243] Modules linked in: dm_round_robin xt_CHECKSUM ipt_MASQUERADE 
nf_nat_masquerade_ipv4 tun ip6t_rpfilter ipt_REJECT nf_reject_ipv4 ip6t_REJECT 
nf_reject_ipv6 xt_conntrack ip_set nfnetlink ebtable_nat ebtable_broute bridge 
stp llc ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 
ip6table_mangle ip6table_security ip6table_raw iptable_nat nf_conntrack_ipv4 
nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack rpcrdma iptable_mangle ib_isert 
iscsi_target_mod iptable_security iptable_raw ebtable_filter ebtables 
ip6table_filter ib_iser libiscsi ip6_tables scsi_transport_iscsi iptable_filter 
target_core_mod ib_srp scsi_transport_srp ib_ipoib rdma_ucm ib_ucm ib_uverbs 
ib_umad rdma_cm ib_cm iw_cm mlx5_ib ib_core intel_powerclamp coretemp kvm_intel 
kvm irqbypass crct10dif_pclmul crc32_pclmul ghash_clmulni_intel
[  434.068279]  pcbc aesni_intel iTCO_wdt crypto_simd gpio_ich ipmi_si 
iTCO_vendor_support cryptd joydev glue_helper ipmi_devintf hpwdt 
acpi_power_meter hpilo sg ipmi_msghandler lpc_ich i7core_edac pcspkr shpchp 
pcc_cpufreq nfsd auth_rpcgss nfs_acl lockd grace sunrpc dm_multipath ip_tables 
xfs libcrc32c sd_mod amdkfd amd_iommu_v2 radeon mlx5_core i2c_algo_bit 
drm_kms_helper syscopyarea sysfillrect sysimgblt fb_sys_fops ttm mlxfw drm ptp 
hpsa pps_core crc32c_intel serio_raw bnx2 i2c_core devlink scsi_transport_sas 
dm_mirror dm_region_hash dm_log dm_mod [last unloaded: ib_srpt]
[  434.068314] CPU: 2 PID: 1039 Comm: dd Tainted: G  I 

Re: [PATCH] storvsc: do not assume SG list is continuous when doing bounce buffers (for 4.1 stable only)

2017-08-23 Thread Greg KH
On Tue, Aug 22, 2017 at 11:43:19PM -0700, Christoph Hellwig wrote:
> Ok.  If the stable maintainers are ok with your small fix
> I'm not going to complain too loudly.  But I'm always worried about
> stable trees divering too much from mainline.

Given that 90% of the time we do this, something breaks, you have a
right to be worried...


[PATCH] scsi: lpfc: avoid false-positive gcc-8 warning

2017-08-23 Thread Arnd Bergmann
This is an interesting regression with gcc-8, showing a harmless
warning for correct code:

In file included from include/linux/kernel.h:13:0,
 ...
 from drivers/scsi/lpfc/lpfc_debugfs.c:23:
include/linux/printk.h:301:2: error: 'eq' may be used uninitialized in this 
function [-Werror=maybe-uninitialized]
  printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  ^~
In file included from drivers/scsi/lpfc/lpfc_debugfs.c:58:0:
drivers/scsi/lpfc/lpfc_debugfs.h:451:31: note: 'eq' was declared here

I tried to come up with a reduced test case for gcc here
a few times, but every time ended up with code that is actually
wrong with older gcc versions missing the bug and gcc-8 finding
it. As this is the only false-positive -Wmaybe-uninitialized
warnign I got with gcc-8 randconfig builds, I'd suggest we
work around it.

Making the index variable 'unsigned' is enough to shut up
the warning, as gcc can then see that comparing eqidx to
phba->io_channel_irqs is fine here.

Signed-off-by: Arnd Bergmann 
---
 drivers/scsi/lpfc/lpfc_debugfs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/lpfc/lpfc_debugfs.h b/drivers/scsi/lpfc/lpfc_debugfs.h
index 7b7d314af0e0..7b7f53a37fd8 100644
--- a/drivers/scsi/lpfc/lpfc_debugfs.h
+++ b/drivers/scsi/lpfc/lpfc_debugfs.h
@@ -450,7 +450,7 @@ lpfc_debug_dump_cq(struct lpfc_hba *phba, int qtype, int 
wqidx)
 {
struct lpfc_queue *wq, *cq, *eq;
char *qtypestr;
-   int eqidx;
+   unsigned int eqidx;
 
/* fcp/nvme wq and cq are 1:1, thus same indexes */
 
-- 
2.9.0



Re: [GIT PULL] SCSI fixes for 4.13-rc6

2017-08-23 Thread Bart Van Assche
On Wed, 2017-08-23 at 07:42 +0100, James Bottomley wrote:
> Six minor and error leg fixes, plus one major change: the reversion of
> scsi-mq as the default.  We're doing the latter temporarily (with a
> backport to stable) to give us time to fix all the issues that turned
> up with this default before trying again.
> [ ... ]
> Damien Le Moal (1):
>   scsi: sd_zbc: Write unlock zone from sd_uninit_cmnd()
> [ ... ]

Hello James,

Had you noticed that Damien had asked not to send the "sd_zbc: Write unlock
zone from sd_uninit_cmnd()" patch to Linus without my "scsi-mq: Always
unprepare before requeuing a request" patch? A quote from an e-mail from
Damien (https://www.spinics.net/lists/stable/msg185436.html):

---
Re: [PATCH] Revert "scsi-mq: Always unprepare before requeuing a request"
>> For an unknown reason this patch causes the boot process to hang on
>> PowerPC systems:
> 
> OK, dropped it from fixes for now.

It means that commit 70e42fd02c46e2aa9ab07b766d418637e3a51de7 "scsi:
sd_zbc: Write unlock zone from sd_uninit_cmnd()" will need to be
reverted too as it will not solve the potential deadlock anymore. Bart's
patch was needed for it to work.
---

Bart.

Re: [v4.13-rc BUG] system lockup when running big buffered write(4M) to IB SRP via mpath

2017-08-23 Thread Bart Van Assche
On Wed, 2017-08-23 at 19:35 +0800, Ming Lei wrote:
> soft lockup still can be observed easily with patch d4acf3650c7c(
> block: Make blk_mq_delay_kick_requeue_list() rerun the queue at a quiet time),
> but no hard lockup.

Hello Ming,

I never claimed that commit d4acf3650c7c was a full solution to avoid these
soft lockups. I assume these results mean that patch series "[PATCH 0/7]
Device mapper and dm-mpath fixes" was not applied to the kernel used in your
tests? A colleague of you has reported that that patch series is sufficient
to avoid these soft lockups. See also
https://www.redhat.com/archives/dm-devel/2017-August/msg00122.html.

Bart.

Re: [PATCH] storvsc: do not assume SG list is continuous when doing bounce buffers (for 4.1 stable only)

2017-08-23 Thread Martin K. Petersen

Christoph,

> Ok.  If the stable maintainers are ok with your small fix
> I'm not going to complain too loudly.  But I'm always worried about
> stable trees divering too much from mainline.

The seemingly innocuous transition from SG_GAPS to virt boundary has
caused several data corruption regressions in the distro kernels. So has
the corresponding conversion of storvsc.

As a result, getting the current upstream code into 4.1 would mean
backporting and testing a significant amount of both block layer and
driver code. I don't think it's worth the risk. This patch is simple and
the path of least resistance.

Acked-by: Martin K. Petersen 

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [GIT PULL] SCSI fixes for 4.13-rc6

2017-08-23 Thread Martin K. Petersen

Hi Bart,

> Had you noticed that Damien had asked not to send the "sd_zbc: Write
> unlock zone from sd_uninit_cmnd()" patch to Linus without my "scsi-mq:
> Always unprepare before requeuing a request" patch?

He did change his mind later in that thread, though.

However, what's more important is that we still need a good version of
your patch for 4.13. I took Brian's workaround for ipr but I still think
Christoph's concerns need to be addressed for me to put your change back
in.

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [GIT PULL] SCSI fixes for 4.13-rc6

2017-08-23 Thread Bart Van Assche
On Wed, 2017-08-23 at 11:27 -0400, Martin K. Petersen wrote:
> However, what's more important is that we still need a good version of
> your patch for 4.13. I took Brian's workaround for ipr but I still think
> Christoph's concerns need to be addressed for me to put your change back
> in.

Hello Martin,

I am not aware of any requests to modify the patch "scsi-mq: Always unprepare
before requeuing a request". See also
https://www.spinics.net/lists/linux-scsi/msg111541.html. Are you perhaps
referring to another patch?

What I remember is that my patch uncovered a bug in the ipr driver. As you
mentioned, a workaround for that bug has already been queued for kernel v4.14
(https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git/commit/?h=4.13/scsi-fixes&id=723cd772fde2344a9810eeaf5106787d535ec4a4).

Further improvements for the SCSI core that are the result of the analysis of
the behavior of the SCSI subsystem on PowerPC systems are under discussion. See
also "[PATCHv2 1/2] scsi: Move scsi_cmd->jiffies_at_alloc initialization to
allocation time" (https://marc.info/?l=linux-next&m=150335524812989) and
"[PATCH 2/2] scsi: Preserve retry counter through scsi_prep_fn"
(https://marc.info/?l=linux-scsi&m=150335371112485).

Please correct me if I got anything wrong.

Bart.

Re: [PATCH] scsi: qedf: Fix a potential NULL pointer dereference

2017-08-23 Thread Chad Dupuis

On Sun, 20 Aug 2017, 1:09pm, Christophe JAILLET wrote:

> At the beginning of 'qedf_srr_compl()' and of 'qedf_rec_compl()', we check
> if 'orig_io_req' is NULL. If this happens, a NULL pointer dereference will
> occur in the error handling path.
> 
> Fix it by adding an additionnal label in the error handling path in order
> to avoid this NULL pointer dereference.
> 
> Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver 
> framework.")
> Signed-off-by: Christophe JAILLET 
> ---
>  drivers/scsi/qedf/qedf_els.c | 14 --
>  1 file changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/scsi/qedf/qedf_els.c b/drivers/scsi/qedf/qedf_els.c
> index eb07f1de8afa..59c18ca4cda9 100644
> --- a/drivers/scsi/qedf/qedf_els.c
> +++ b/drivers/scsi/qedf/qedf_els.c
> @@ -489,7 +489,7 @@ static void qedf_srr_compl(struct qedf_els_cb_arg *cb_arg)
>  
>   /* If a SRR times out, simply free resources */
>   if (srr_req->event == QEDF_IOREQ_EV_ELS_TMO)
> - goto out_free;
> + goto out_put;
>  
>   /* Normalize response data into struct fc_frame */
>   mp_req = &(srr_req->mp_req);
> @@ -501,7 +501,7 @@ static void qedf_srr_compl(struct qedf_els_cb_arg *cb_arg)
>   if (!fp) {
>   QEDF_ERR(&(qedf->dbg_ctx),
>   "fc_frame_alloc failure.\n");
> - goto out_free;
> + goto out_put;
>   }
>  
>   /* Copy frame header from firmware into fp */
> @@ -526,9 +526,10 @@ static void qedf_srr_compl(struct qedf_els_cb_arg 
> *cb_arg)
>   }
>  
>   fc_frame_free(fp);
> -out_free:
> +out_put:
>   /* Put reference for original command since SRR completed */
>   kref_put(&orig_io_req->refcount, qedf_release_cmd);
> +out_free:
>   kfree(cb_arg);
>  }
>  
> @@ -780,7 +781,7 @@ static void qedf_rec_compl(struct qedf_els_cb_arg *cb_arg)
>  
>   /* If a REC times out, free resources */
>   if (rec_req->event == QEDF_IOREQ_EV_ELS_TMO)
> - goto out_free;
> + goto out_put;
>  
>   /* Normalize response data into struct fc_frame */
>   mp_req = &(rec_req->mp_req);
> @@ -792,7 +793,7 @@ static void qedf_rec_compl(struct qedf_els_cb_arg *cb_arg)
>   if (!fp) {
>   QEDF_ERR(&(qedf->dbg_ctx),
>   "fc_frame_alloc failure.\n");
> - goto out_free;
> + goto out_put;
>   }
>  
>   /* Copy frame header from firmware into fp */
> @@ -884,9 +885,10 @@ static void qedf_rec_compl(struct qedf_els_cb_arg 
> *cb_arg)
>  
>  out_free_frame:
>   fc_frame_free(fp);
> -out_free:
> +out_put:
>   /* Put reference for original command since REC completed */
>   kref_put(&orig_io_req->refcount, qedf_release_cmd);
> +out_free:
>   kfree(cb_arg);
>  }
>  
> 

Thanks for the catch.

Acked-by: Chad Dupuis 


Re: [v4.13-rc BUG] system lockup when running big buffered write(4M) to IB SRP via mpath

2017-08-23 Thread Ming Lei
On Wed, Aug 23, 2017 at 11:12 PM, Bart Van Assche
 wrote:
> On Wed, 2017-08-23 at 19:35 +0800, Ming Lei wrote:
>> soft lockup still can be observed easily with patch d4acf3650c7c(
>> block: Make blk_mq_delay_kick_requeue_list() rerun the queue at a quiet 
>> time),
>> but no hard lockup.
>
> Hello Ming,
>
> I never claimed that commit d4acf3650c7c was a full solution to avoid these
> soft lockups. I assume these results mean that patch series "[PATCH 0/7]
> Device mapper and dm-mpath fixes" was not applied to the kernel used in your
> tests? A colleague of you has reported that that patch series is sufficient

OK, thanks for your clarification.

I run v4.13-rc6 with block for-next, so these patches are not applied in my
kernel.

-- 
Ming Lei


Re: [PATCH] scsi: lpfc: remove useless code in lpfc_sli4_bsg_link_diag_test

2017-08-23 Thread James Smart

On 8/22/2017 1:53 PM, Gustavo A. R. Silva wrote:

Remove variable assignments. The value stored in local variable _rc_ is
overwritten at line 2448:rc = lpfc_sli4_bsg_set_link_diag_state(phba, 0);
before it can be used.

Addresses-Coverity-ID: 1226935
Signed-off-by: Gustavo A. R. Silva 
---
This issue was detected by Coverity and it was tested by compilation only.
Notice that this code has been there since 2011.

  drivers/scsi/lpfc/lpfc_bsg.c | 9 +++--
  1 file changed, 3 insertions(+), 6 deletions(-)




looks good. Thanks

Signed-off-by: James Smart 

-- james



Re: [PATCH] scsi: lpfc: avoid false-positive gcc-8 warning

2017-08-23 Thread James Smart

On 8/23/2017 8:01 AM, Arnd Bergmann wrote:

This is an interesting regression with gcc-8, showing a harmless
warning for correct code:

In file included from include/linux/kernel.h:13:0,
  ...
  from drivers/scsi/lpfc/lpfc_debugfs.c:23:
include/linux/printk.h:301:2: error: 'eq' may be used uninitialized in this 
function [-Werror=maybe-uninitialized]
   printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
   ^~
In file included from drivers/scsi/lpfc/lpfc_debugfs.c:58:0:
drivers/scsi/lpfc/lpfc_debugfs.h:451:31: note: 'eq' was declared here

I tried to come up with a reduced test case for gcc here
a few times, but every time ended up with code that is actually
wrong with older gcc versions missing the bug and gcc-8 finding
it. As this is the only false-positive -Wmaybe-uninitialized
warnign I got with gcc-8 randconfig builds, I'd suggest we
work around it.

Making the index variable 'unsigned' is enough to shut up
the warning, as gcc can then see that comparing eqidx to
phba->io_channel_irqs is fine here.

Signed-off-by: Arnd Bergmann 
---
  drivers/scsi/lpfc/lpfc_debugfs.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)



looks good. Thanks

Signed-off-by: James Smart 

-- james


[PATCH] scsi_transport_sas: Fix error handling in sas_smp_request()

2017-08-23 Thread Bart Van Assche
sas_function_template.smp_handler implementations either return
0 or a Unix error code. Convert that error code into a SCSI
result. This patch is what I came up with after having analyzed
the following sparse warnings:

drivers/scsi/scsi_transport_sas.c:187:21: warning: incorrect type in assignment 
(different base types)
drivers/scsi/scsi_transport_sas.c:187:21:expected restricted blk_status_t 
[usertype] ret
drivers/scsi/scsi_transport_sas.c:187:21:got int
drivers/scsi/scsi_transport_sas.c:188:39: warning: incorrect type in assignment 
(different base types)
drivers/scsi/scsi_transport_sas.c:188:39:expected int [signed] result
drivers/scsi/scsi_transport_sas.c:188:39:got restricted blk_status_t 
[usertype] ret

Fixes: commit 17d5363b83f8 ("scsi: introduce a result field in struct 
scsi_request")
Signed-off-by: Bart Van Assche 
Cc: Christoph Hellwig 
Cc: Hannes Reinecke 
Cc: Johannes Thumshirn 
Cc: 
---
 drivers/scsi/scsi_transport_sas.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/scsi_transport_sas.c 
b/drivers/scsi/scsi_transport_sas.c
index 5006a656e16a..a318c46db7cc 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -173,7 +173,7 @@ static void sas_smp_request(struct request_queue *q, struct 
Scsi_Host *shost,
struct sas_rphy *rphy)
 {
struct request *req;
-   blk_status_t ret;
+   int ret;
int (*handler)(struct Scsi_Host *, struct sas_rphy *, struct request *);
 
while ((req = blk_fetch_request(q)) != NULL) {
@@ -185,7 +185,9 @@ static void sas_smp_request(struct request_queue *q, struct 
Scsi_Host *shost,
blk_rq_bytes(req->next_rq);
handler = to_sas_internal(shost->transportt)->f->smp_handler;
ret = handler(shost, rphy, req);
-   scsi_req(req)->result = ret;
+   WARN_ONCE(ret != 0 && !IS_ERR_VALUE(ret + 0UL),
+ "%s: ret = %d\n", __func__, ret);
+   scsi_req(req)->result = ret ? DID_ERROR << 16 : 0;
 
blk_end_request_all(req, 0);
 
-- 
2.14.0



Re: [PATCH] scsi: lpfc: avoid false-positive gcc-8 warning

2017-08-23 Thread Arnd Bergmann
On Wed, Aug 23, 2017 at 5:01 PM, Arnd Bergmann  wrote:
> This is an interesting regression with gcc-8, showing a harmless
> warning for correct code:
>
> In file included from include/linux/kernel.h:13:0,
>  ...
>  from drivers/scsi/lpfc/lpfc_debugfs.c:23:
> include/linux/printk.h:301:2: error: 'eq' may be used uninitialized in this 
> function [-Werror=maybe-uninitialized]
>   printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
>   ^~
> In file included from drivers/scsi/lpfc/lpfc_debugfs.c:58:0:
> drivers/scsi/lpfc/lpfc_debugfs.h:451:31: note: 'eq' was declared here
>
> I tried to come up with a reduced test case for gcc here
> a few times, but every time ended up with code that is actually
> wrong with older gcc versions missing the bug and gcc-8 finding
> it. As this is the only false-positive -Wmaybe-uninitialized
> warnign I got with gcc-8 randconfig builds, I'd suggest we
> work around it.
>
> Making the index variable 'unsigned' is enough to shut up
> the warning, as gcc can then see that comparing eqidx to
> phba->io_channel_irqs is fine here.
>
> Signed-off-by: Arnd Bergmann 

Sorry, I have to retract my patch. While it apparently solved the problem
for most randconfig builds, I have now run into another case that it did
not address, and I still get the warning for one caller:

In file included from /git/arm-soc/include/linux/kernel.h:13:0,
 from /git/arm-soc/arch/x86/include/asm/percpu.h:44,
 from /git/arm-soc/arch/x86/include/asm/current.h:5,
 from /git/arm-soc/include/linux/sched.h:11,
 from /git/arm-soc/include/linux/blkdev.h:4,
 from /git/arm-soc/drivers/scsi/lpfc/lpfc_debugfs.c:23:
/git/arm-soc/drivers/scsi/lpfc/lpfc_debugfs.c: In function
'lpfc_debug_dump_all_queues':
/git/arm-soc/include/linux/printk.h:301:2: error: 'eq' may be used
uninitialized in this function [-Werror=maybe-uninitialized]
  printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  ^~
In file included from /git/arm-soc/drivers/scsi/lpfc/lpfc_debugfs.c:58:0:
/git/arm-soc/drivers/scsi/lpfc/lpfc_debugfs.h:451:31: note: 'eq' was
declared here
  struct lpfc_queue *wq, *cq, *eq;
   ^~
In file included from /git/arm-soc/include/linux/kernel.h:13:0,
 from /git/arm-soc/arch/x86/include/asm/percpu.h:44,
 from /git/arm-soc/arch/x86/include/asm/current.h:5,
 from /git/arm-soc/include/linux/sched.h:11,
 from /git/arm-soc/include/linux/blkdev.h:4,
 from /git/arm-soc/drivers/scsi/lpfc/lpfc_debugfs.c:23:
/git/arm-soc/include/linux/printk.h:301:2: error: 'eq' may be used
uninitialized in this function [-Werror=maybe-uninitialized]
  printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  ^~
In file included from /git/arm-soc/drivers/scsi/lpfc/lpfc_debugfs.c:58:0:
/git/arm-soc/drivers/scsi/lpfc/lpfc_debugfs.h:451:31: note: 'eq' was
declared here
  struct lpfc_queue *wq, *cq, *eq;
   ^~
cc1: all warnings being treated as errors

 Arnd


Re: [GIT PULL] SCSI fixes for 4.13-rc6

2017-08-23 Thread Brian King
On 08/23/2017 10:44 AM, Bart Van Assche wrote:
> On Wed, 2017-08-23 at 11:27 -0400, Martin K. Petersen wrote:
>> However, what's more important is that we still need a good version of
>> your patch for 4.13. I took Brian's workaround for ipr but I still think
>> Christoph's concerns need to be addressed for me to put your change back
>> in.
> 
> Hello Martin,
> 
> I am not aware of any requests to modify the patch "scsi-mq: Always unprepare
> before requeuing a request". See also
> https://www.spinics.net/lists/linux-scsi/msg111541.html. Are you perhaps
> referring to another patch?
> 
> What I remember is that my patch uncovered a bug in the ipr driver. As you
> mentioned, a workaround for that bug has already been queued for kernel v4.14
> (https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git/commit/?h=4.13/scsi-fixes&id=723cd772fde2344a9810eeaf5106787d535ec4a4).

I don't completely agree with that statement. The patch "scsi-mq: Always 
unprepare
before requeueing a request" introduces a regression in the scsi stack.
It alters the behavior of retries such that the retry counter no longer works
and the jiffies_at_alloc use to ensure we don't spend a tremendous amount of
time retrying ops gets broken as well.

As far as ipr is concerned, we do have the workaround in place now and I'll also
queue up a further improvement to ipr to return a better failure response. 
However,
until we fix the retry counter in scsi, any driver that returns an error 
response that
scsi wants to retry could get us stuck in an eternal retry loop, like we were
seeing with ipr.

> Further improvements for the SCSI core that are the result of the analysis of
> the behavior of the SCSI subsystem on PowerPC systems are under discussion. 
> See
> also "[PATCHv2 1/2] scsi: Move scsi_cmd->jiffies_at_alloc initialization to
> allocation time" (https://marc.info/?l=linux-next&m=150335524812989) and
> "[PATCH 2/2] scsi: Preserve retry counter through scsi_prep_fn"
> (https://marc.info/?l=linux-scsi&m=150335371112485).

While my patches highlight the problem, I don't think they are the right fix
and need to be reworked. It looks like we go through scsi_init_rq at
hctx setup time rather than for each new i/o submission. Adding a simple
kprobe to scsi_init_rq never triggers when issuing i/o to already configured
devices. Therefore, we cannot simply move the initialization of 
jiffies_at_alloc to
scsi_init_rq. I've been working on moving the retry counter and jiffies_at_alloc
into struct scsi_request, as that doesn't get reinitialized.

Thanks,

Brian 

-- 
Brian King
Power Linux I/O
IBM Linux Technology Center



Re: [PATCH 0/2] generate uevent for SCSI sense code

2017-08-23 Thread Song Liu
Dear Hannes and James, 

Could you please kindly review this patch and let me know what do we 
need to move forward with this?

Thanks and Regards,
Song


> On Aug 4, 2017, at 10:18 AM, Song Liu  wrote:
> 
> Hi all, 
> 
> Could you please share your feedback on this version of the change? 
> 
> Thanks in advance,
> Song
> 
>>> On 7/21/17, 3:58 PM, "Song Liu"  wrote:
> 
>This change is to follow up our discussion on event log for media
>management during LSF/MM 2017.
> 
>Changes from RFC v3:
>  Incorporate feedback by Johannes Thumshirn
> 
>Thanks,
>Song
> 
>Song Liu (2):
>  scsi: generate uevent for SCSI sense code
>  scsi: add rate limit to scsi sense code uevent
> 
> drivers/scsi/Kconfig   | 14 +++
> drivers/scsi/hosts.c   |  4 
> drivers/scsi/scsi_error.c  | 58 
> ++
> drivers/scsi/scsi_lib.c| 58 
> +-
> drivers/scsi/scsi_sysfs.c  | 51 
> include/scsi/scsi_common.h |  6 +
> include/scsi/scsi_device.h | 27 -
> include/scsi/scsi_host.h   | 13 +++
> 8 files changed, 229 insertions(+), 2 deletions(-)
> 
>--
>2.9.3
> 
> 



[PATCH] Improve requeuing behavior

2017-08-23 Thread Bart Van Assche
Requests are unprepared and reprepared when being requeued. Avoid
that requeuing resets .jiffies_at_alloc and .retries by initializing
these two member variables from inside blk_get_request() and by
preserving both member variables when preparing a request. This patch
affects the requeuing behavior of scsi-sq and scsi-mq.

Reported-by: Brian King 
References: https://lkml.org/lkml/2017/8/18/923 ("Re: [BUG][bisected 270065e] 
linux-next fails to boot on powerpc")
Signed-off-by: Bart Van Assche 
Cc: Brian King 
Cc: Hannes Reinecke 
Cc: Christoph Hellwig 
Cc: Johannes Thumshirn 
---
 drivers/scsi/scsi_lib.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index ebc5c713ee37..8d1ec1e7b0e2 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1122,6 +1122,8 @@ void scsi_initialize_rq(struct request *rq)
struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
 
scsi_req_init(&cmd->req);
+   cmd->jiffies_at_alloc = jiffies;
+   cmd->retries = 0;
 }
 EXPORT_SYMBOL(scsi_initialize_rq);
 
@@ -1160,6 +1162,8 @@ void scsi_init_command(struct scsi_device *dev, struct 
scsi_cmnd *cmd)
void *buf = cmd->sense_buffer;
void *prot = cmd->prot_sdb;
unsigned int unchecked_isa_dma = cmd->flags & SCMD_UNCHECKED_ISA_DMA;
+   unsigned long jiffies_at_alloc = cmd->jiffies_at_alloc;
+   int retries = cmd->retries;
 
/* zero out the cmd, except for the embedded scsi_request */
memset((char *)cmd + sizeof(cmd->req), 0,
@@ -1170,7 +1174,8 @@ void scsi_init_command(struct scsi_device *dev, struct 
scsi_cmnd *cmd)
cmd->prot_sdb = prot;
cmd->flags = unchecked_isa_dma;
INIT_DELAYED_WORK(&cmd->abort_work, scmd_eh_abort_handler);
-   cmd->jiffies_at_alloc = jiffies;
+   cmd->jiffies_at_alloc = jiffies_at_alloc;
+   cmd->retries = retries;
 
scsi_add_cmd_to_list(cmd);
 }
-- 
2.14.0



[PATCH 00/19] SCSI patches for kernel v4.14

2017-08-23 Thread Bart Van Assche
Hello Martin,

The patches in this series fall into two categories:
- Two patches are related to using blk_mq_rq_to_pdu() instead of
  struct request.special.
- Seventeen patches suppress warnings reported by static analysis
  tools. These tools are very useful but unfortunately the current
  code base makes these tools report a significant number of false
  positives.

Please consider these patches for kernel v4.14.

Thanks,

Bart.

Bart Van Assche (19):
  Remove an obsolete function declaration
  Avoid sign extension of scsi_device.type
  Suppress gcc 7 fall-through warnings reported with W=1
  Convert a strncmp() call into a strcmp() call
  scsi_setup_fs_cmnd(): Call scsi_req_init() instead of open-coding it
  Document which queue type a function is intended for
  Fix RCU handling of scsi_device.vpd_pg8[03]
  Use blk_mq_rq_to_pdu() to convert a request to a SCSI command pointer
  sd, sr: Convert two assignments into warning statements
  sd: Fix indentation
  sd: Remove a useless comparison
  sg: Fix type of last blk_trace_setup() argument
  libiscsi: Fix indentation
  libsas: Remove a set-but-not-used variable
  libsas: Annotate fall-through in a switch statement
  scsi_transport_sas, sas_tlr_supported(): Check kzalloc() return value
  scsi_transport_srp: Suppress a W=1 compiler warning
  scsi_debug: Remove a set-but-not-used variable
  iscsi_tcp: Remove a set-but-not-used variable

 drivers/scsi/iscsi_tcp.c|  2 --
 drivers/scsi/libiscsi.c |  2 +-
 drivers/scsi/libsas/sas_ata.c   |  1 +
 drivers/scsi/libsas/sas_scsi_host.c |  3 ---
 drivers/scsi/scsi.c |  6 +++---
 drivers/scsi/scsi_debug.c   |  3 +--
 drivers/scsi/scsi_error.c   | 10 --
 drivers/scsi/scsi_ioctl.c   |  4 +++-
 drivers/scsi/scsi_lib.c | 36 +---
 drivers/scsi/scsi_sysfs.c   |  9 ++---
 drivers/scsi/scsi_transport_sas.c   |  3 +++
 drivers/scsi/scsi_transport_srp.c   |  2 +-
 drivers/scsi/sd.c   |  6 +++---
 drivers/scsi/sg.c   |  3 +--
 drivers/scsi/sr.c   |  2 +-
 include/scsi/scsi_cmnd.h|  1 -
 include/scsi/scsi_device.h  |  2 +-
 include/scsi/scsi_tcq.h |  2 +-
 18 files changed, 55 insertions(+), 42 deletions(-)

-- 
2.14.0



[PATCH 03/19] Suppress gcc 7 fall-through warnings reported with W=1

2017-08-23 Thread Bart Van Assche
The conclusion of a recent discussion about the new warnings
reported by gcc 7 is that the new warnings reported when building
with W=1 should be suppressed. However, gcc 7 still warns about
fall-through in switch statements when building with W=1. Suppress
these warnings by annotating the SCSI core properly.

See also Linus Torvalds, Lots of new warnings with gcc-7.1.1, 11
July 2017 
(https://www.mail-archive.com/linux-media@vger.kernel.org/msg115428.html).

References: commit bd664f6b3e37 ("disable new gcc-7.1.1 warnings for now")
Signed-off-by: Bart Van Assche 
Cc: Hannes Reinecke 
Cc: Christoph Hellwig 
Cc: Johannes Thumshirn 
---
 drivers/scsi/scsi_error.c | 8 +++-
 drivers/scsi/scsi_ioctl.c | 4 +++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index ea9f40e51f68..01b2d2055edf 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -552,6 +552,7 @@ int scsi_check_sense(struct scsi_cmnd *scmd)
set_host_byte(scmd, DID_ALLOC_FAILURE);
return SUCCESS;
}
+   /* FALLTHROUGH */
case COPY_ABORTED:
case VOLUME_OVERFLOW:
case MISCOMPARE:
@@ -573,6 +574,7 @@ int scsi_check_sense(struct scsi_cmnd *scmd)
return ADD_TO_MLQUEUE;
else
set_host_byte(scmd, DID_TARGET_FAILURE);
+   /* FALLTHROUGH */
 
case ILLEGAL_REQUEST:
if (sshdr.asc == 0x20 || /* Invalid command operation code */
@@ -683,6 +685,7 @@ static int scsi_eh_completed_normally(struct scsi_cmnd 
*scmd)
switch (status_byte(scmd->result)) {
case GOOD:
scsi_handle_queue_ramp_up(scmd->device);
+   /* FALLTHROUGH */
case COMMAND_TERMINATED:
return SUCCESS;
case CHECK_CONDITION:
@@ -1734,6 +1737,7 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)
set_host_byte(scmd, DID_TIME_OUT);
return SUCCESS;
}
+   /* FALLTHROUGH */
case DID_NO_CONNECT:
case DID_BAD_TARGET:
/*
@@ -1819,6 +1823,7 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)
 * the case of trying to send too many commands to a
 * tagged queueing device.
 */
+   /* FALLTHROUGH */
case BUSY:
/*
 * device can't talk to us at the moment.  Should only
@@ -1831,6 +1836,7 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)
if (scmd->cmnd[0] == REPORT_LUNS)
scmd->device->sdev_target->expecting_lun_change = 0;
scsi_handle_queue_ramp_up(scmd->device);
+   /* FALLTHROUGH */
case COMMAND_TERMINATED:
return SUCCESS;
case TASK_ABORTED:
@@ -2320,8 +2326,8 @@ scsi_ioctl_reset(struct scsi_device *dev, int __user *arg)
rtn = scsi_try_host_reset(scmd);
if (rtn == SUCCESS)
break;
-   default:
/* FALLTHROUGH */
+   default:
rtn = FAILED;
break;
}
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index b6bf3f29a12a..0a875491f5a7 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -116,13 +116,15 @@ static int ioctl_internal_command(struct scsi_device 
*sdev, char *cmd,
case NOT_READY: /* This happens if there is no disc in drive */
if (sdev->removable)
break;
+   /* FALLTHROUGH */
case UNIT_ATTENTION:
if (sdev->removable) {
sdev->changed = 1;
result = 0; /* This is no longer considered 
an error */
break;
}
-   default:/* Fall through for non-removable media */
+   /* FALLTHROUGH -- for non-removable media */
+   default:
sdev_printk(KERN_INFO, sdev,
"ioctl_internal_command return code = %x\n",
result);
-- 
2.14.0



[PATCH 01/19] Remove an obsolete function declaration

2017-08-23 Thread Bart Van Assche
Commit e9c787e65c0c ("scsi: allocate scsi_cmnd structures as part of
struct request") removed the scsi_get_command() function. Hence also
remove the declaration of that function.

Signed-off-by: Bart Van Assche 
Cc: Christoph Hellwig 
Cc: Hannes Reinecke 
Cc: Johannes Thumshirn 
---
 include/scsi/scsi_cmnd.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index a1266d318c85..f5afcff8d76f 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -158,7 +158,6 @@ static inline struct scsi_driver *scsi_cmd_to_driver(struct 
scsi_cmnd *cmd)
return *(struct scsi_driver **)cmd->request->rq_disk->private_data;
 }
 
-extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t);
 extern void scsi_put_command(struct scsi_cmnd *);
 extern void scsi_finish_command(struct scsi_cmnd *cmd);
 
-- 
2.14.0



[PATCH 04/19] Convert a strncmp() call into a strcmp() call

2017-08-23 Thread Bart Van Assche
This patch avoids that smatch reports the following warning:

drivers/scsi/scsi_sysfs.c:117: check_set() error: strncmp() '"-"' too small (2 
vs 20)

Signed-off-by: Bart Van Assche 
Cc: Christoph Hellwig 
Cc: Hannes Reinecke 
Cc: Johannes Thumshirn 
---
 drivers/scsi/scsi_sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 41891db20108..5ed473a87589 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -114,7 +114,7 @@ static int check_set(unsigned long long *val, char *src)
 {
char *last;
 
-   if (strncmp(src, "-", 20) == 0) {
+   if (strcmp(src, "-") == 0) {
*val = SCAN_WILD_CARD;
} else {
/*
-- 
2.14.0



[PATCH 02/19] Avoid sign extension of scsi_device.type

2017-08-23 Thread Bart Van Assche
This patch avoids that smatch reports the following:

drivers/scsi/scsi_sysfs.c:506 scsi_bus_uevent() warn: argument 3 to %02x 
specifier has type 'char'
drivers/scsi/scsi_sysfs.c:872 sdev_show_modalias() warn: argument 4 to %02x 
specifier has type 'char'

Signed-off-by: Bart Van Assche 
Cc: Christoph Hellwig 
Cc: Hannes Reinecke 
Cc: Johannes Thumshirn 
---
 include/scsi/scsi_device.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 0979a5f3b69a..f054f3f43c75 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -111,7 +111,7 @@ struct scsi_device {
unsigned sector_size;   /* size in bytes */
 
void *hostdata; /* available to low-level driver */
-   char type;
+   unsigned char type;
char scsi_level;
char inq_periph_qual;   /* PQ from INQUIRY data */  
struct mutex inquiry_mutex;
-- 
2.14.0



[PATCH 05/19] scsi_setup_fs_cmnd(): Call scsi_req_init() instead of open-coding it

2017-08-23 Thread Bart Van Assche
The functional changes in this patch for scsi_setup_fs_cmnd() are:
- scsi_request.sense_len is cleared. This is OK since it is the
  responsibility of the LLD to set .sense_len before calling
  .scsi_done().
- scsi_request.cmd_len is changed to BLK_MAX_CDB. This is fine
  since scsi_driver.init_command() must overwrite this member for
  FS commands.

Signed-off-by: Bart Van Assche 
Cc: Christoph Hellwig 
Cc: Hannes Reinecke 
Cc: Johannes Thumshirn 
---
 drivers/scsi/scsi_lib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index efdcd9e79404..f9a0d5b13707 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1215,8 +1215,8 @@ static int scsi_setup_fs_cmnd(struct scsi_device *sdev, 
struct request *req)
return ret;
}
 
-   cmd->cmnd = scsi_req(req)->cmd = scsi_req(req)->__cmd;
-   memset(cmd->cmnd, 0, BLK_MAX_CDB);
+   scsi_req_init(&cmd->req);
+   cmd->cmnd = cmd->req.cmd;
return scsi_cmd_to_driver(cmd)->init_command(cmd);
 }
 
-- 
2.14.0



[PATCH 07/19] Fix RCU handling of scsi_device.vpd_pg8[03]

2017-08-23 Thread Bart Van Assche
Only annotate pointers that are shared across threads with __rcu.
Use rcu_dereference() when dereferencing an RCU pointer. Protect
also the RCU pointer dereferences when freeing RCU pointers. This
patch suppresses about twenty sparse complaints about the vpd_pg8[03]
pointers.

Fixes: commit 09e2b0b14690 ("scsi: rescan VPD attributes")
Signed-off-by: Bart Van Assche 
Cc: Christoph Hellwig 
Cc: Hannes Reinecke 
Cc: Johannes Thumshirn 
Cc: Shane Seymour 
---
 drivers/scsi/scsi.c   | 6 +++---
 drivers/scsi/scsi_lib.c   | 8 
 drivers/scsi/scsi_sysfs.c | 7 +--
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 3d38c6d463b8..5bb15e698969 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -426,7 +426,7 @@ void scsi_attach_vpd(struct scsi_device *sdev)
int vpd_len = SCSI_VPD_PG_LEN;
int pg80_supported = 0;
int pg83_supported = 0;
-   unsigned char __rcu *vpd_buf, *orig_vpd_buf = NULL;
+   unsigned char *vpd_buf, *orig_vpd_buf = NULL;
 
if (!scsi_device_supports_vpd(sdev))
return;
@@ -474,7 +474,7 @@ void scsi_attach_vpd(struct scsi_device *sdev)
goto retry_pg80;
}
mutex_lock(&sdev->inquiry_mutex);
-   orig_vpd_buf = sdev->vpd_pg80;
+   orig_vpd_buf = rcu_dereference(sdev->vpd_pg80);
sdev->vpd_pg80_len = result;
rcu_assign_pointer(sdev->vpd_pg80, vpd_buf);
mutex_unlock(&sdev->inquiry_mutex);
@@ -503,7 +503,7 @@ void scsi_attach_vpd(struct scsi_device *sdev)
goto retry_pg83;
}
mutex_lock(&sdev->inquiry_mutex);
-   orig_vpd_buf = sdev->vpd_pg83;
+   orig_vpd_buf = rcu_dereference(sdev->vpd_pg83);
sdev->vpd_pg83_len = result;
rcu_assign_pointer(sdev->vpd_pg83, vpd_buf);
mutex_unlock(&sdev->inquiry_mutex);
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 1905962fb992..2ca91d251c5f 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -3282,7 +3282,7 @@ int scsi_vpd_lun_id(struct scsi_device *sdev, char *id, 
size_t id_len)
u8 cur_id_type = 0xff;
u8 cur_id_size = 0;
unsigned char *d, *cur_id_str;
-   unsigned char __rcu *vpd_pg83;
+   unsigned char *vpd_pg83;
int id_size = -EINVAL;
 
rcu_read_lock();
@@ -3431,7 +3431,7 @@ EXPORT_SYMBOL(scsi_vpd_lun_id);
 int scsi_vpd_tpg_id(struct scsi_device *sdev, int *rel_id)
 {
unsigned char *d;
-   unsigned char __rcu *vpd_pg83;
+   unsigned char *vpd_pg83;
int group_id = -EAGAIN, rel_port = -1;
 
rcu_read_lock();
@@ -3441,8 +3441,8 @@ int scsi_vpd_tpg_id(struct scsi_device *sdev, int *rel_id)
return -ENXIO;
}
 
-   d = sdev->vpd_pg83 + 4;
-   while (d < sdev->vpd_pg83 + sdev->vpd_pg83_len) {
+   d = vpd_pg83 + 4;
+   while (d < vpd_pg83 + sdev->vpd_pg83_len) {
switch (d[1] & 0xf) {
case 0x4:
/* Relative target port */
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 5ed473a87589..cf8a2088a9ba 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -456,8 +456,11 @@ static void scsi_device_dev_release_usercontext(struct 
work_struct *work)
/* NULL queue means the device can't be used */
sdev->request_queue = NULL;
 
-   kfree(sdev->vpd_pg83);
-   kfree(sdev->vpd_pg80);
+   mutex_lock(&sdev->inquiry_mutex);
+   kfree(rcu_dereference(sdev->vpd_pg83));
+   kfree(rcu_dereference(sdev->vpd_pg80));
+   mutex_unlock(&sdev->inquiry_mutex);
+
kfree(sdev->inquiry);
kfree(sdev);
 
-- 
2.14.0



[PATCH 08/19] Use blk_mq_rq_to_pdu() to convert a request to a SCSI command pointer

2017-08-23 Thread Bart Van Assche
Since commit e9c787e65c0c ("scsi: allocate scsi_cmnd structures as
part of struct request") struct request and struct scsi_cmnd are
adjacent. This means that there is now an alternative to reading
req->special to convert a pointer to a prepared request into a
SCSI command pointer, namely by using blk_mq_rq_to_pdu(). Make
this change where appropriate. Although this patch does not
change any functionality, it slightly improves performance and
slightly improves readability.

Signed-off-by: Bart Van Assche 
Reviewed-by: Hannes Reinecke 
Reviewed-by: Johannes Thumshirn 
Cc: Christoph Hellwig 
---
 drivers/scsi/scsi_error.c |  2 +-
 drivers/scsi/scsi_lib.c   | 18 +-
 include/scsi/scsi_tcq.h   |  2 +-
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 01b2d2055edf..38942050b265 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -259,7 +259,7 @@ void scsi_eh_scmd_add(struct scsi_cmnd *scmd)
  */
 enum blk_eh_timer_return scsi_times_out(struct request *req)
 {
-   struct scsi_cmnd *scmd = req->special;
+   struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req);
enum blk_eh_timer_return rtn = BLK_EH_NOT_HANDLED;
struct Scsi_Host *host = scmd->device->host;
 
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 2ca91d251c5f..e4966f8edbf9 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -627,7 +627,7 @@ static void scsi_release_bidi_buffers(struct scsi_cmnd *cmd)
 static bool scsi_end_request(struct request *req, blk_status_t error,
unsigned int bytes, unsigned int bidi_bytes)
 {
-   struct scsi_cmnd *cmd = req->special;
+   struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req);
struct scsi_device *sdev = cmd->device;
struct request_queue *q = sdev->request_queue;
 
@@ -1176,7 +1176,7 @@ void scsi_init_command(struct scsi_device *dev, struct 
scsi_cmnd *cmd)
 
 static int scsi_setup_scsi_cmnd(struct scsi_device *sdev, struct request *req)
 {
-   struct scsi_cmnd *cmd = req->special;
+   struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req);
 
/*
 * Passthrough requests may transfer data, in which case they must
@@ -1207,7 +1207,7 @@ static int scsi_setup_scsi_cmnd(struct scsi_device *sdev, 
struct request *req)
  */
 static int scsi_setup_fs_cmnd(struct scsi_device *sdev, struct request *req)
 {
-   struct scsi_cmnd *cmd = req->special;
+   struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req);
 
if (unlikely(sdev->handler && sdev->handler->prep_fn)) {
int ret = sdev->handler->prep_fn(sdev, req);
@@ -1222,7 +1222,7 @@ static int scsi_setup_fs_cmnd(struct scsi_device *sdev, 
struct request *req)
 
 static int scsi_setup_cmnd(struct scsi_device *sdev, struct request *req)
 {
-   struct scsi_cmnd *cmd = req->special;
+   struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req);
 
if (!blk_rq_bytes(req))
cmd->sc_data_direction = DMA_NONE;
@@ -1359,7 +1359,7 @@ static int scsi_prep_fn(struct request_queue *q, struct 
request *req)
 
 static void scsi_unprep_fn(struct request_queue *q, struct request *req)
 {
-   scsi_uninit_cmd(req->special);
+   scsi_uninit_cmd(blk_mq_rq_to_pdu(req));
 }
 
 /*
@@ -1550,7 +1550,7 @@ static int scsi_lld_busy(struct request_queue *q)
  */
 static void scsi_kill_request(struct request *req, struct request_queue *q)
 {
-   struct scsi_cmnd *cmd = req->special;
+   struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req);
struct scsi_device *sdev;
struct scsi_target *starget;
struct Scsi_Host *shost;
@@ -1581,7 +1581,7 @@ static void scsi_kill_request(struct request *req, struct 
request_queue *q)
 
 static void scsi_softirq_done(struct request *rq)
 {
-   struct scsi_cmnd *cmd = rq->special;
+   struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
unsigned long wait_for = (cmd->allowed + 1) * rq->timeout;
int disposition;
 
@@ -1769,8 +1769,8 @@ static void scsi_request_fn(struct request_queue *q)
blk_start_request(req);
 
spin_unlock_irq(q->queue_lock);
-   cmd = req->special;
-   if (unlikely(cmd == NULL)) {
+   cmd = blk_mq_rq_to_pdu(req);
+   if (cmd != req->special) {
printk(KERN_CRIT "impossible request in %s.\n"
 "please mail a stack trace to "
 "linux-scsi@vger.kernel.org\n",
diff --git a/include/scsi/scsi_tcq.h b/include/scsi/scsi_tcq.h
index 4416b1026189..5b416debf101 100644
--- a/include/scsi/scsi_tcq.h
+++ b/include/scsi/scsi_tcq.h
@@ -39,7 +39,7 @@ static inline struct scsi_cmnd *scsi_host_find_tag(struct 
Scsi_Host *shost,
 
if (!req)
return NULL;
-   return req->special;
+   return blk_mq_rq_to_pdu(req);
 }
 
 #endif /* CONFIG_BLOCK */
-- 
2.14.0



[PATCH 06/19] Document which queue type a function is intended for

2017-08-23 Thread Bart Van Assche
Document which queue type a function is intended for if this is not
easy to derive from the function name.

Signed-off-by: Bart Van Assche 
Cc: Hannes Reinecke 
Cc: Christoph Hellwig 
Cc: Johannes Thumshirn 
---
 drivers/scsi/scsi_lib.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index f9a0d5b13707..1905962fb992 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2006,6 +2006,7 @@ static enum blk_eh_timer_return scsi_timeout(struct 
request *req,
return scsi_times_out(req);
 }
 
+/* scsi-mq */
 static int scsi_init_request(struct blk_mq_tag_set *set, struct request *rq,
unsigned int hctx_idx, unsigned int numa_node)
 {
@@ -2031,6 +2032,7 @@ static int scsi_init_request(struct blk_mq_tag_set *set, 
struct request *rq,
return 0;
 }
 
+/* scsi-mq */
 static void scsi_exit_request(struct blk_mq_tag_set *set, struct request *rq,
unsigned int hctx_idx)
 {
@@ -2070,6 +2072,7 @@ static u64 scsi_calculate_bounce_limit(struct Scsi_Host 
*shost)
return bounce_limit;
 }
 
+/* scsi-sq and scsi-mq */
 void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q)
 {
struct device *dev = shost->dma_dev;
@@ -2109,6 +2112,7 @@ void __scsi_init_queue(struct Scsi_Host *shost, struct 
request_queue *q)
 }
 EXPORT_SYMBOL_GPL(__scsi_init_queue);
 
+/* scsi-sq */
 static int scsi_init_rq(struct request_queue *q, struct request *rq, gfp_t gfp)
 {
struct Scsi_Host *shost = q->rq_alloc_data;
@@ -2139,6 +2143,7 @@ static int scsi_init_rq(struct request_queue *q, struct 
request *rq, gfp_t gfp)
return -ENOMEM;
 }
 
+/* scsi-sq */
 static void scsi_exit_rq(struct request_queue *q, struct request *rq)
 {
struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
@@ -2149,6 +2154,7 @@ static void scsi_exit_rq(struct request_queue *q, struct 
request *rq)
   cmd->sense_buffer);
 }
 
+/* scsi-sq */
 struct request_queue *scsi_alloc_queue(struct scsi_device *sdev)
 {
struct Scsi_Host *shost = sdev->host;
-- 
2.14.0



[PATCH 09/19] sd, sr: Convert two assignments into warning statements

2017-08-23 Thread Bart Van Assche
Before scsi_prep_fn() calls the ULP .init_command() callback
function it stores the SCSI command pointer in request.special.
This means that the SCpnt = rq->special assignments in the sd
and sr drivers assign a pointer to itself. Hence convert these
two assignment statements into warning statements.

Signed-off-by: Bart Van Assche 
Reviewed-by: Hannes Reinecke 
Reviewed-by: Johannes Thumshirn 
Cc: Christoph Hellwig 
---
 drivers/scsi/sd.c | 2 +-
 drivers/scsi/sr.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index bea36adeee17..a88639fbedb3 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1013,7 +1013,7 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd 
*SCpnt)
ret = scsi_init_io(SCpnt);
if (ret != BLKPREP_OK)
goto out;
-   SCpnt = rq->special;
+   WARN_ON_ONCE(SCpnt != rq->special);
 
/* from here on until we're complete, any goto out
 * is used for a killable error condition */
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index a8f630213a1a..9be34d37c356 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -393,7 +393,7 @@ static int sr_init_command(struct scsi_cmnd *SCpnt)
ret = scsi_init_io(SCpnt);
if (ret != BLKPREP_OK)
goto out;
-   SCpnt = rq->special;
+   WARN_ON_ONCE(SCpnt != rq->special);
cd = scsi_cd(rq->rq_disk);
 
/* from here on until we're complete, any goto out
-- 
2.14.0



[PATCH 11/19] sd: Remove a useless comparison

2017-08-23 Thread Bart Van Assche
This patch avoids that gcc reports the following warning when
building with W=1:

drivers/scsi/sd.c:315:10: warning: comparison of unsigned expression >= 0 is 
always true [-Wtype-limits]
  if (val >= 0 && val <= T10_PI_TYPE3_PROTECTION)

Signed-off-by: Bart Van Assche 
---
 drivers/scsi/sd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 8b3d7994e182..7c0f9eb5a5fd 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -312,7 +312,7 @@ protection_type_store(struct device *dev, struct 
device_attribute *attr,
if (err)
return err;
 
-   if (val >= 0 && val <= T10_PI_TYPE3_PROTECTION)
+   if (val <= T10_PI_TYPE3_PROTECTION)
sdkp->protection_type = val;
 
return count;
-- 
2.14.0



[PATCH 10/19] sd: Fix indentation

2017-08-23 Thread Bart Van Assche
This patch avoids that smatch reports the following:

drivers/scsi/sd.c:3540: sd_suspend_common() warn: inconsistent indenting

Signed-off-by: Bart Van Assche 
Cc: Christoph Hellwig 
Cc: Hannes Reinecke 
Cc: Johannes Thumshirn 
---
 drivers/scsi/sd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index a88639fbedb3..8b3d7994e182 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3537,7 +3537,7 @@ static int sd_suspend_common(struct device *dev, bool 
ignore_stop_errors)
 * doesn't support sync. There's not much to do and
 * suspend shouldn't fail.
 */
-ret = 0;
+   ret = 0;
}
}
 
-- 
2.14.0



[PATCH 13/19] libiscsi: Fix indentation

2017-08-23 Thread Bart Van Assche
This patch avoids that smatch reports the following:

drivers/scsi/libiscsi.c:1081: iscsi_handle_reject() warn: inconsistent indenting

Signed-off-by: Bart Van Assche 
Cc: Christoph Hellwig 
Cc: Hannes Reinecke 
Cc: Johannes Thumshirn 
---
 drivers/scsi/libiscsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 42381adf0769..bd4605a34f54 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -1078,7 +1078,7 @@ static int iscsi_handle_reject(struct iscsi_conn *conn, 
struct iscsi_hdr *hdr,
if (opcode != ISCSI_OP_NOOP_OUT)
return 0;
 
-if (rejected_pdu.itt == cpu_to_be32(ISCSI_RESERVED_TAG)) {
+   if (rejected_pdu.itt == cpu_to_be32(ISCSI_RESERVED_TAG)) {
/*
 * nop-out in response to target's nop-out rejected.
 * Just resend.
-- 
2.14.0



[PATCH 12/19] sg: Fix type of last blk_trace_setup() argument

2017-08-23 Thread Bart Van Assche
Avoid that sparse reports the following:

drivers/scsi/sg.c:1114:41: warning: incorrect type in argument 5 (different 
address spaces)
drivers/scsi/sg.c:1114:41:expected char [noderef] *arg
drivers/scsi/sg.c:1114:41:got char *

This patch does not change any functionality.

Signed-off-by: Bart Van Assche 
Cc: Christoph Hellwig 
Cc: Hannes Reinecke 
Cc: Johannes Thumshirn 
---
 drivers/scsi/sg.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index f5705a95319f..03194c4b6744 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1110,8 +1110,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned 
long arg)
return blk_trace_setup(sdp->device->request_queue,
   sdp->disk->disk_name,
   MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
-  NULL,
-  (char *)arg);
+  NULL, p);
case BLKTRACESTART:
return blk_trace_startstop(sdp->device->request_queue, 1);
case BLKTRACESTOP:
-- 
2.14.0



[PATCH 14/19] libsas: Remove a set-but-not-used variable

2017-08-23 Thread Bart Van Assche
This was detected by building with W=1.

Signed-off-by: Bart Van Assche 
Cc: Christoph Hellwig 
Cc: Hannes Reinecke 
Cc: Johannes Thumshirn 
---
 drivers/scsi/libsas/sas_scsi_host.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/scsi/libsas/sas_scsi_host.c 
b/drivers/scsi/libsas/sas_scsi_host.c
index 87e5079d816b..fc90b8c65860 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -855,7 +855,6 @@ int sas_target_alloc(struct scsi_target *starget)
 int sas_slave_configure(struct scsi_device *scsi_dev)
 {
struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
-   struct sas_ha_struct *sas_ha;
 
BUG_ON(dev->rphy->identify.device_type != SAS_END_DEVICE);
 
@@ -864,8 +863,6 @@ int sas_slave_configure(struct scsi_device *scsi_dev)
return 0;
}
 
-   sas_ha = dev->port->ha;
-
sas_read_port_mode_page(scsi_dev);
 
if (scsi_dev->tagged_supported) {
-- 
2.14.0



[PATCH 15/19] libsas: Annotate fall-through in a switch statement

2017-08-23 Thread Bart Van Assche
Signed-off-by: Bart Van Assche 
Cc: Hannes Reinecke 
Cc: Christoph Hellwig 
Cc: Johannes Thumshirn 
---
 drivers/scsi/libsas/sas_ata.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index 87f5e694dbed..70be4425ae0b 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -343,6 +343,7 @@ static int smp_ata_check_ready(struct ata_link *link)
case SAS_END_DEVICE:
if (ex_phy->attached_sata_dev)
return sas_ata_clear_pending(dev, ex_phy);
+   /* fall through */
default:
return -ENODEV;
}
-- 
2.14.0



[PATCH 16/19] scsi_transport_sas, sas_tlr_supported(): Check kzalloc() return value

2017-08-23 Thread Bart Van Assche
Check whether memory allocation succeeded before dereferencing
the pointer to the allocated memory.

Signed-off-by: Bart Van Assche 
Cc: Hannes Reinecke 
Cc: Christoph Hellwig 
Cc: Johannes Thumshirn 
---
 drivers/scsi/scsi_transport_sas.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/scsi/scsi_transport_sas.c 
b/drivers/scsi/scsi_transport_sas.c
index a318c46db7cc..1a0fa79fd49a 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -423,6 +423,9 @@ sas_tlr_supported(struct scsi_device *sdev)
char *buffer = kzalloc(vpd_len, GFP_KERNEL);
int ret = 0;
 
+   if (!buffer)
+   goto out;
+
if (scsi_get_vpd_page(sdev, 0x90, buffer, vpd_len))
goto out;
 
-- 
2.14.0



[PATCH 19/19] iscsi_tcp: Remove a set-but-not-used variable

2017-08-23 Thread Bart Van Assche
This patch avoids that gcc reports the following warning when
building with W=1:

drivers/scsi/iscsi_tcp.c:166:24: warning: variable ?session? set but not used 
[-Wunused-but-set-variable]

Signed-off-by: Bart Van Assche 
Cc: Lee Duncan 
Cc: Christoph Hellwig 
Cc: Hannes Reinecke 
Cc: Johannes Thumshirn 
---
 drivers/scsi/iscsi_tcp.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 4842fc0e809d..4d934d6c3e13 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -163,7 +163,6 @@ static void iscsi_sw_tcp_state_change(struct sock *sk)
struct iscsi_tcp_conn *tcp_conn;
struct iscsi_sw_tcp_conn *tcp_sw_conn;
struct iscsi_conn *conn;
-   struct iscsi_session *session;
void (*old_state_change)(struct sock *);
 
read_lock_bh(&sk->sk_callback_lock);
@@ -172,7 +171,6 @@ static void iscsi_sw_tcp_state_change(struct sock *sk)
read_unlock_bh(&sk->sk_callback_lock);
return;
}
-   session = conn->session;
 
iscsi_sw_sk_state_check(sk);
 
-- 
2.14.0



[PATCH 18/19] scsi_debug: Remove a set-but-not-used variable

2017-08-23 Thread Bart Van Assche
This patch avoids that gcc reports the following warning when
building with W=1:

drivers/scsi/scsi_debug.c:2264:15: warning: variable ?pcontrol? set but not 
used [-Wunused-but-set-variable]

Signed-off-by: Bart Van Assche 
Cc: Douglas Gilbert 
Cc: Hannes Reinecke 
Cc: Christoph Hellwig 
Cc: Johannes Thumshirn 
---
 drivers/scsi/scsi_debug.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 3be980d47268..77a0335eb757 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -2261,7 +2261,7 @@ static int resp_ie_l_pg(unsigned char * arr)
 static int resp_log_sense(struct scsi_cmnd * scp,
   struct sdebug_dev_info * devip)
 {
-   int ppc, sp, pcontrol, pcode, subpcode, alloc_len, len, n;
+   int ppc, sp, pcode, subpcode, alloc_len, len, n;
unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
unsigned char *cmd = scp->cmnd;
 
@@ -2272,7 +2272,6 @@ static int resp_log_sense(struct scsi_cmnd * scp,
mk_sense_invalid_fld(scp, SDEB_IN_CDB, 1, ppc ? 1 : 0);
return check_condition_result;
}
-   pcontrol = (cmd[2] & 0xc0) >> 6;
pcode = cmd[2] & 0x3f;
subpcode = cmd[3] & 0xff;
alloc_len = get_unaligned_be16(cmd + 7);
-- 
2.14.0



[PATCH 17/19] scsi_transport_srp: Suppress a W=1 compiler warning

2017-08-23 Thread Bart Van Assche
Avoid that the following compiler warning is reported when building
with W=1:

drivers/scsi/scsi_transport_srp.c:92:19: warning: comparison is always false 
due to limited range of data type [-Wtype-limits]

Signed-off-by: Bart Van Assche 
Cc: Christoph Hellwig 
Cc: Hannes Reinecke 
Cc: Johannes Thumshirn 
---
 drivers/scsi/scsi_transport_srp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_transport_srp.c 
b/drivers/scsi/scsi_transport_srp.c
index 698cc4681706..b8f5e4c47579 100644
--- a/drivers/scsi/scsi_transport_srp.c
+++ b/drivers/scsi/scsi_transport_srp.c
@@ -89,7 +89,7 @@ int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo, 
int dev_loss_tmo)
if (fast_io_fail_tmo < 0 &&
dev_loss_tmo > SCSI_DEVICE_BLOCK_MAX_TIMEOUT)
return -EINVAL;
-   if (dev_loss_tmo >= LONG_MAX / HZ)
+   if (dev_loss_tmo + 0UL >= LONG_MAX / HZ)
return -EINVAL;
if (fast_io_fail_tmo >= 0 && dev_loss_tmo >= 0 &&
fast_io_fail_tmo >= dev_loss_tmo)
-- 
2.14.0



[PATCH 01/31] qla2xxx: Correction to vha->vref_count timeout

2017-08-23 Thread Himanshu Madhani
From: Joe Carnuccio 

Fix incorrect second argument for wait_event_timeout()

Fixes: c4a9b538ab2a ("qla2xxx: Allow vref count to timeout on vport delete.")
Cc: 
Signed-off-by: Joe Carnuccio 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_mid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_mid.c b/drivers/scsi/qla2xxx/qla_mid.c
index f0605cd196fb..3089094b48fa 100644
--- a/drivers/scsi/qla2xxx/qla_mid.c
+++ b/drivers/scsi/qla2xxx/qla_mid.c
@@ -74,7 +74,7 @@ qla24xx_deallocate_vp_id(scsi_qla_host_t *vha)
 * ensures no active vp_list traversal while the vport is removed
 * from the queue)
 */
-   wait_event_timeout(vha->vref_waitq, atomic_read(&vha->vref_count),
+   wait_event_timeout(vha->vref_waitq, !atomic_read(&vha->vref_count),
10*HZ);
 
spin_lock_irqsave(&ha->vport_slock, flags);
-- 
2.12.0



[PATCH 03/31] qla2xxx: Update fw_started flags at qpair creation.

2017-08-23 Thread Himanshu Madhani
Fixes: 4b60c82736d0 ("scsi: qla2xxx: Add fw_started flags to qpair")
Cc: 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_init.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 072ad1aa5505..8f83571afc7b 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -7804,6 +7804,7 @@ struct qla_qpair *qla2xxx_create_qpair(struct 
scsi_qla_host *vha, int qos,
ha->queue_pair_map[qpair_id] = qpair;
qpair->id = qpair_id;
qpair->vp_idx = vp_idx;
+   qpair->fw_started = ha->flags.fw_started;
INIT_LIST_HEAD(&qpair->hints_list);
qpair->chip_reset = ha->base_qpair->chip_reset;
qpair->enable_class_2 = ha->base_qpair->enable_class_2;
-- 
2.12.0



[PATCH 00/31] qla2xxx: Patches for scsi "misc" branch

2017-08-23 Thread Himanshu Madhani
Hi Martin,

This series contains various bug fixes and driver updates. Please apply
the following patches to the 4.14/scsi-queue branch at your earliest
convenience for inclusion in the next mainline merge window.

Thanks,
Himanshu 


Darren Trap (1):
  qla2xxx: Fix WWPN/WWNN in debug message

Duane Grigsby (2):
  qla2xxx: Add command completion for error path
  qla2xxx: Fix system panic due to pointer access problem

Giridhar Malavali (1):
  qla2xxx: Ability to process multiple SGEs in Command SGL for CT
passthrough commands.

Himanshu Madhani (3):
  qla2xxx: Update fw_started flags at qpair creation.
  qla2xxx: Enable Async TMF processing
  qla2xxx: Update driver version to 10.00.00.01-k

Joe Carnuccio (10):
  qla2xxx: Correction to vha->vref_count timeout
  qla2xxx: Prevent sp->free null/uninitialized pointer dereference.
  qla2xxx: Use sp->free instead of hard coded call.
  qla2xxx: Move logging default mask to execute once only.
  qla2xxx: Add timeout ability to wait_for_sess_deletion().
  qla2xxx: Allow SNS fabric login to be retried
  qla2xxx: Print correct mailbox registers in failed summary
  qla2xxx: Remove potential macro parameter side-effect in
ql_dump_regs()
  qla2xxx: Add LR distance support from nvram bit
  qla2xxx: Skip zero queue count entry during FW dump capture

Michael Hernandez (2):
  qla2xxx: Fix target multiqueue configuration
  qla2xxx: Increase ql2xmaxqdepth to 64

Quinn Tran (8):
  qla2xxx: Fix NPIV host enable after chip reset
  qla2xxx: Remove extra register read
  qla2xxx: Change ha->wq max_active value to default
  qla2xxx: Use fabric name for Get Port Speed command
  qla2xxx: Add ability to autodetect SFP type
  qla2xxx: Fix task mgmt handling for NPIV
  qla2xxx: Cleanup NPIV host in target mode during config teardown
  qla2xxx: Recheck session state after RSCN

Sawan Chandak (4):
  qla2xxx: Handle PCIe error for driver
  qla2xxx: Use BIT_6 to acquire FAWWPN from switch
  qla2xxx: Add support for minimum link speed
  qla2xxx: Do not call abort handler function during chip reset

 drivers/scsi/qla2xxx/qla_attr.c|  78 ---
 drivers/scsi/qla2xxx/qla_dbg.c |   8 +-
 drivers/scsi/qla2xxx/qla_def.h | 105 +++-
 drivers/scsi/qla2xxx/qla_fw.h  |  28 --
 drivers/scsi/qla2xxx/qla_gbl.h |   7 +-
 drivers/scsi/qla2xxx/qla_gs.c  |  18 ++--
 drivers/scsi/qla2xxx/qla_init.c| 181 ++-
 drivers/scsi/qla2xxx/qla_iocb.c|  55 +++
 drivers/scsi/qla2xxx/qla_isr.c |  25 ++---
 drivers/scsi/qla2xxx/qla_mbx.c | 190 -
 drivers/scsi/qla2xxx/qla_mid.c |  14 ++-
 drivers/scsi/qla2xxx/qla_mr.c  |   7 +-
 drivers/scsi/qla2xxx/qla_nvme.c|  21 +++-
 drivers/scsi/qla2xxx/qla_os.c  |  91 +++---
 drivers/scsi/qla2xxx/qla_target.c  |  25 +++--
 drivers/scsi/qla2xxx/qla_target.h  |   2 +
 drivers/scsi/qla2xxx/qla_tmpl.c|  19 ++--
 drivers/scsi/qla2xxx/qla_version.h |   2 +-
 18 files changed, 696 insertions(+), 180 deletions(-)

-- 
2.12.0



[PATCH 02/31] qla2xxx: Fix target multiqueue configuration

2017-08-23 Thread Himanshu Madhani
From: Michael Hernandez 

Following error will be logged in to message file
while trying to configure target with multiqueue.

"Cmd 0x1f aborted with timeout since ISP Abort is pending"
"qla25xx_init_queues Rsp que: 1 init failed."

Fixes: 82de802ad46e ("scsi: qla2xxx: Preparation for Target MQ.")
Cc: 
Signed-off-by: Quinn Tran 
Signed-off-by: Michael Hernandez 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_isr.c| 2 +-
 drivers/scsi/qla2xxx/qla_mbx.c| 1 +
 drivers/scsi/qla2xxx/qla_target.c | 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 916f685872aa..d3a51df27b0d 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -3454,7 +3454,7 @@ qla24xx_enable_msix(struct qla_hw_data *ha, struct 
rsp_que *rsp)
}
 
/* Enable MSI-X vector for response queue update for queue 0 */
-   if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
+   if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
if (ha->msixbase && ha->mqiobase &&
(ha->max_rsp_queues > 1 || ha->max_req_queues > 1 ||
 ql2xmqsupport))
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 1f91b87b6416..234ef442ef5d 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -54,6 +54,7 @@ static struct rom_cmd {
{ MBC_GET_MEM_OFFLOAD_CNTRL_STAT },
{ MBC_GET_RETRY_COUNT },
{ MBC_TRACE_CONTROL },
+   { MBC_INITIALIZE_MULTIQ },
 };
 
 static int is_rom_cmd(uint16_t cmd)
diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index e101cd3043b9..4e2a64773060 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -6796,7 +6796,7 @@ qlt_probe_one_stage1(struct scsi_qla_host *base_vha, 
struct qla_hw_data *ha)
if (!QLA_TGT_MODE_ENABLED())
return;
 
-   if  (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
+   if  (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in;
ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out;
} else {
-- 
2.12.0



[PATCH 08/31] qla2xxx: Use BIT_6 to acquire FAWWPN from switch

2017-08-23 Thread Himanshu Madhani
From: Sawan Chandak 

If FA-WWPN feature disabled on the switch side and
enabled for the adapter, then driver would update
the port name with switch port name.

This patch fixes issue by checking correct BIT flag to validate.

Fixes: 41dc529a4602 ("qla2xxx: Improve RSCN handling in driver")
Cc: 
Signed-off-by: Sawan Chandak 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_mbx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 234ef442ef5d..6164a2c9a1f4 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -3682,7 +3682,7 @@ qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
if (qla_ini_mode_enabled(vha) &&
ha->flags.fawwpn_enabled &&
(rptid_entry->u.f1.flags &
-VP_FLAGS_NAME_VALID)) {
+BIT_6)) {
memcpy(vha->port_name,
rptid_entry->u.f1.port_name,
WWN_SIZE);
-- 
2.12.0



[PATCH 07/31] qla2xxx: Fix system panic due to pointer access problem

2017-08-23 Thread Himanshu Madhani
From: Duane Grigsby 

[ 1013.772926] BUG: unable to handle kernel paging request at 00030020
[ 1013.772950] IP: qla24xx_els_ct_entry.isra.17+0x78/0x2a0 [qla2xxx]
[ 1013.772951] PGD 0
[ 1013.772952] P4D 0
[ 1013.772952]
[ 1013.772953] Oops:  [#1] SMP
[ 1013.772955] Modules linked in: qla2xxx(+) scsi_transport_fc nvme_fc
nvme_fabrics nvme_core netconsole configfs af_packet iscsi_ibft
iscsi_boot_sysfs xfs intel_rapl sb_edac libcrc32c x86_pkg_temp_thermal
intel_powerclamp coretemp mgag200 kvm_intel ttm kvm drm_kms_helper
ipmi_ssif irqbypass tg3 drm fb_sys_fops crct10dif_pclmul syscopyarea
crc32_pclmul ghash_clmulni_intel ptp pcbc sysfillrect pps_core
aesni_intel joydev aes_x86_64 sysimgblt crypto_simd iTCO_wdt libphy
iTCO_vendor_support i2c_algo_bit glue_helper ipmi_si lpc_ich hpwdt
ioatdma cryptd ipmi_devintf pcspkr mfd_core pcc_cpufreq ipmi_msghandler
hpilo thermal dca button shpchp btrfs xor raid6_pq hid_generic usbhid
sr_mod cdrom sd_mod ata_generic crc32c_intel serio_raw ata_piix ahci
libahci uhci_hcd ehci_pci ehci_hcd libata usbcore hpsa scsi_transport_sas
[ 1013.772994]  sg scsi_mod autofs4
[ 1013.772998] CPU: 0 PID: 374 Comm: systemd-journal Not tainted 
4.13.0-rc1-2-default #2
[ 1013.772999] Hardware name: HP ProLiant DL380p Gen8, BIOS P70 07/15/2012
[ 1013.773000] task: 88082c188380 task.stack: c90004d7c000
[ 1013.773011] RIP: 0010:qla24xx_els_ct_entry.isra.17+0x78/0x2a0 [qla2xxx]
[ 1013.773012] RSP: :88042f603d90 EFLAGS: 00010082
[ 1013.773013] RAX: 88039f723ac8 RBX: 88039f723ac8 RCX: 8803a2e18010
[ 1013.773014] RDX: 88039f723ac0 RSI: 88042f603dc4 RDI: 88041b6787c0
[ 1013.773015] RBP: 88042f603e00 R08: 0002 R09: 000d
[ 1013.773016] R10: 0002 R11:  R12: 8803a2e80080
[ 1013.773016] R13: 88041b6787c0 R14: 0003 R15: 0102
[ 1013.773018] FS:  7fa2e0a73880() GS:88042f60() 
knlGS:
[ 1013.773019] CS:  0010 DS:  ES:  CR0: 80050033
[ 1013.773020] CR2: 00030020 CR3: 00042cd7e000 CR4: 000406f0
[ 1013.773021] Call Trace:
[ 1013.773022]  
[ 1013.773026]  ? consume_skb+0x34/0xa0
[ 1013.773040]  qla24xx_process_response_queue+0x319/0x700 [qla2xxx]
[ 1013.773050]  qla24xx_msix_rsp_q+0x7b/0xd0 [qla2xxx]
[ 1013.773054]  __handle_irq_event_percpu+0x3c/0x1b0
[ 1013.773056]  handle_irq_event_percpu+0x23/0x60
[ 1013.773057]  handle_irq_event+0x42/0x70
[ 1013.773059]  handle_edge_irq+0x8f/0x190
[ 1013.773062]  handle_irq+0x1d/0x30
[ 1013.773065]  do_IRQ+0x48/0xd0
[ 1013.773067]  common_interrupt+0x93/0x93
[ 1013.773068] RIP: 0033:0xed622c6e42
[ 1013.773069] RSP: 002b:7ffee8b5c820 EFLAGS: 0202 ORIG_RAX: 
ff17
[ 1013.773071] RAX: 00ed6316a3f0 RBX: 00ed6316a840 RCX: 000c4e33
[ 1013.773071] RDX: 00ed6316a878 RSI: 00ed6316a840 RDI: 00ed631682d0
[ 1013.773072] RBP: 0001 R08: 0001 R09: 00ed63179b70
[ 1013.773073] R10: 0005f6f8 R11: 0202 R12: 0001
[ 1013.773074] R13: 7ffee8b5c85c R14: 00ed6316a840 R15: 7ffee8b5c850
[ 1013.773074]  
[ 1013.773076] Code: a9 8a 9a e0 48 8d 75 c4 48 89 da 4c 89 e1 4c 89 ef
e8 54 6e fb ff 48 85 c0 48 89 c3 0f 84 0e 02 00 00 44 0f b7 48 36 4c 8b
70 58 <4d> 8b 7e 20 41 8d 41 fd 66 83 f8 0c 77 6c 0f b7 c0 ff 24 c5 88
[ 1013.773102] RIP: qla24xx_els_ct_entry.isra.17+0x78/0x2a0 [qla2xxx] RSP: 
88042f603d90
[ 1013.773102] CR2: 00030020
[ 1013.773129] ---[ end trace 532363559924f426 ]---
[ 1013.773131] Kernel panic - not syncing: Fatal exception in interrupt
[ 1013.19] Kernel Offset: disabled
[ 1013.827528] ---[ end Kernel panic - not syncing: Fatal exception in interrupt

Signed-off-by: Duane Grigsby 
Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_isr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index d3a51df27b0d..c6c066186d97 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -1537,8 +1537,6 @@ qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que 
*req,
sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
if (!sp)
return;
-   bsg_job = sp->u.bsg_job;
-   bsg_reply = bsg_job->reply;
 
type = NULL;
switch (sp->type) {
@@ -1577,6 +1575,8 @@ qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que 
*req,
/* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
 * fc payload  to the caller
 */
+   bsg_job = sp->u.bsg_job;
+   bsg_reply = bsg_job->reply;
bsg_reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
 
-- 
2.12.0



[PATCH 06/31] qla2xxx: Handle PCIe error for driver

2017-08-23 Thread Himanshu Madhani
From: Sawan Chandak 

Driver will perform following

- Set PFLG_DRIVER_REMOVING flag and do not disable PCIe
  error reporting during adapter shutdown.
- If PCIe device count is already zero, return correct
  error type from PCI error interface.
- When device is offline, return correct error type from
  PCIe error path.
- If there is board disable thread active during shutdown
  and PCIe device count is zero then cancel scheduling board
  disable thread during shutdown and return.

Signed-off-by: Sawan Chandak 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_os.c | 32 
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index b43520ca6645..d668ed4bd53e 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -3385,12 +3385,22 @@ qla2x00_shutdown(struct pci_dev *pdev)
scsi_qla_host_t *vha;
struct qla_hw_data  *ha;
 
-   if (!atomic_read(&pdev->enable_cnt))
-   return;
-
vha = pci_get_drvdata(pdev);
ha = vha->hw;
 
+   ql_log(ql_log_info, vha, 0xfffa,
+   "Adapter shutdown\n");
+
+   /*
+* Prevent future board_disable and wait
+* until any pending board_disable has completed.
+*/
+   set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags);
+   cancel_work_sync(&ha->board_disable);
+
+   if (!atomic_read(&pdev->enable_cnt))
+   return;
+
/* Notify ISPFX00 firmware */
if (IS_QLAFX00(ha))
qlafx00_driver_shutdown(vha, 20);
@@ -3421,8 +3431,9 @@ qla2x00_shutdown(struct pci_dev *pdev)
 
qla2x00_free_fw_dump(ha);
 
-   pci_disable_pcie_error_reporting(pdev);
pci_disable_device(pdev);
+   ql_log(ql_log_info, vha, 0xfffe,
+   "Adapter shutdown successfully.\n");
 }
 
 /* Deletes all the virtual ports for a given ha */
@@ -5495,6 +5506,13 @@ qla2x00_disable_board_on_pci_error(struct work_struct 
*work)
ql_log(ql_log_warn, base_vha, 0x015b,
"Disabling adapter.\n");
 
+   if (!atomic_read(&pdev->enable_cnt)) {
+   ql_log(ql_log_info, base_vha, 0xfffc,
+   "PCI device disabled, no action req for PCI error=%lx\n",
+   base_vha->pci_flags);
+   return;
+   }
+
qla2x00_wait_for_sess_deletion(base_vha);
 
set_bit(UNLOADING, &base_vha->dpc_flags);
@@ -6197,6 +6215,12 @@ qla2xxx_pci_error_detected(struct pci_dev *pdev, 
pci_channel_state_t state)
ql_dbg(ql_dbg_aer, vha, 0x9000,
"PCI error detected, state %x.\n", state);
 
+   if (!atomic_read(&pdev->enable_cnt)) {
+   ql_log(ql_log_info, vha, 0x,
+   "PCI device is disabled,state %x\n", state);
+   return PCI_ERS_RESULT_NEED_RESET;
+   }
+
switch (state) {
case pci_channel_io_normal:
ha->flags.eeh_busy = 0;
-- 
2.12.0



[PATCH 05/31] qla2xxx: Fix WWPN/WWNN in debug message

2017-08-23 Thread Himanshu Madhani
From: Darren Trap 

Signed-off-by: Darren Trap 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_nvme.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
index 5692ae128655..1f59e7a74c7b 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -60,8 +60,8 @@ int qla_nvme_register_remote(struct scsi_qla_host *vha, 
struct fc_port *fcport)
rport->req.port_id = fcport->d_id.b24;
 
ql_log(ql_log_info, vha, 0x2102,
-   "%s: traddr=pn-0x%016llx:nn-0x%016llx PortID:%06x\n",
-   __func__, rport->req.port_name, rport->req.node_name,
+   "%s: traddr=nn-0x%016llx:pn-0x%016llx PortID:%06x\n",
+   __func__, rport->req.node_name, rport->req.port_name,
rport->req.port_id);
 
ret = nvme_fc_register_remoteport(vha->nvme_local_port, &rport->req,
@@ -723,8 +723,8 @@ void qla_nvme_register_hba(struct scsi_qla_host *vha)
pinfo.port_id = vha->d_id.b24;
 
ql_log(ql_log_info, vha, 0x,
-   "register_localport: host-traddr=pn-0x%llx:nn-0x%llx on 
portID:%x\n",
-   pinfo.port_name, pinfo.node_name, pinfo.port_id);
+   "register_localport: host-traddr=nn-0x%llx:pn-0x%llx on 
portID:%x\n",
+   pinfo.node_name, pinfo.port_name, pinfo.port_id);
qla_nvme_fc_transport.dma_boundary = vha->host->dma_boundary;
 
ret = nvme_fc_register_localport(&pinfo, tmpl,
-- 
2.12.0



[PATCH 09/31] qla2xxx: Fix NPIV host enable after chip reset

2017-08-23 Thread Himanshu Madhani
From: Quinn Tran 

For NPIV ports, call configure_hba() so that NPIV ports
can proceed to loop initialization.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_dbg.c  | 2 +-
 drivers/scsi/qla2xxx/qla_init.c | 2 +-
 drivers/scsi/qla2xxx/qla_mbx.c  | 2 ++
 drivers/scsi/qla2xxx/qla_mid.c  | 5 +
 4 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_dbg.c b/drivers/scsi/qla2xxx/qla_dbg.c
index 7b74973d5788..7e7cd79038be 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.c
+++ b/drivers/scsi/qla2xxx/qla_dbg.c
@@ -41,7 +41,7 @@
  * |  || 0x70ad-0x70ae  |
  * |  || 0x70d0-0x70d6 |
  * |  || 0x70d7-0x70db  |
- * | Task Management  |   0x8042   | 0x8000,0x800b  |
+ * | Task Management  |   0x8042   | 0x8000 |
  * |  || 0x8019 |
  * |  || 0x8025,0x8026  |
  * |  || 0x8031,0x8032  |
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 988fb5d0f9e7..8f84cedab853 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -5913,7 +5913,7 @@ qla2x00_abort_isp(scsi_qla_host_t *vha)
 
if (!status) {
ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
-
+   qla2x00_configure_hba(vha);
spin_lock_irqsave(&ha->vport_slock, flags);
list_for_each_entry(vp, &ha->vp_list, list) {
if (vp->vp_idx) {
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 6164a2c9a1f4..f101aaa5254b 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -55,6 +55,8 @@ static struct rom_cmd {
{ MBC_GET_RETRY_COUNT },
{ MBC_TRACE_CONTROL },
{ MBC_INITIALIZE_MULTIQ },
+   { MBC_IOCB_COMMAND_A64 },
+   { MBC_GET_ADAPTER_LOOP_ID },
 };
 
 static int is_rom_cmd(uint16_t cmd)
diff --git a/drivers/scsi/qla2xxx/qla_mid.c b/drivers/scsi/qla2xxx/qla_mid.c
index 608d1aeb97be..c0f8f6c17b79 100644
--- a/drivers/scsi/qla2xxx/qla_mid.c
+++ b/drivers/scsi/qla2xxx/qla_mid.c
@@ -187,6 +187,11 @@ qla24xx_enable_vp(scsi_qla_host_t *vha)
!(ha->current_topology & ISP_CFG_F)) {
vha->vp_err_state =  VP_ERR_PORTDWN;
fc_vport_set_state(vha->fc_vport, FC_VPORT_LINKDOWN);
+   ql_dbg(ql_dbg_taskm, vha, 0x800b,
+   "%s skip enable. loop_state %x topo %x\n",
+   __func__, base_vha->loop_state.counter,
+   ha->current_topology);
+
goto enable_failed;
}
 
-- 
2.12.0



[PATCH 11/31] qla2xxx: Change ha->wq max_active value to default

2017-08-23 Thread Himanshu Madhani
From: Quinn Tran 

update ha->wq max_active from 1 to default. MQ interrupts
are queued up via this work queue. This allows interrupts
to be process in parrallel, instead of serialized by the
work queue.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_os.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index d668ed4bd53e..fe5148899117 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -3170,7 +3170,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct 
pci_device_id *id)
if (ha->mqenable) {
bool mq = false;
bool startit = false;
-   ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
+   ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 0);
 
if (QLA_TGT_MODE_ENABLED()) {
mq = true;
-- 
2.12.0



[PATCH 12/31] qla2xxx: Use fabric name for Get Port Speed command

2017-08-23 Thread Himanshu Madhani
From: Quinn Tran 

The Get Port Speed switch command needs the fabric
port name of the remote device.  Current code uses
the registered WWPN.

Fixes: 726b85487067d ("qla2xxx: Add framework for async fabric discovery")
Cc:  # 4.10+
Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_gs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c
index b323a7c71eda..0ec250993e93 100644
--- a/drivers/scsi/qla2xxx/qla_gs.c
+++ b/drivers/scsi/qla2xxx/qla_gs.c
@@ -3080,7 +3080,7 @@ int qla24xx_async_gpsc(scsi_qla_host_t *vha, fc_port_t 
*fcport)
GPSC_RSP_SIZE);
 
/* GPSC req */
-   memcpy(ct_req->req.gpsc.port_name, fcport->port_name,
+   memcpy(ct_req->req.gpsc.port_name, fcport->fabric_port_name,
WWN_SIZE);
 
sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
-- 
2.12.0



[PATCH 15/31] qla2xxx: Use sp->free instead of hard coded call.

2017-08-23 Thread Himanshu Madhani
From: Joe Carnuccio 

Calling sp->free() ensures the context-correct free routine is called.

Signed-off-by: Joe Carnuccio 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_os.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index b6b070db5891..5b033e265a3b 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -742,7 +742,7 @@ qla2x00_sp_compl(void *ptr, int res)
if (!atomic_dec_and_test(&sp->ref_count))
return;
 
-   qla2x00_sp_free_dma(sp);
+   sp->free(sp);
cmd->scsi_done(cmd);
 }
 
@@ -814,7 +814,7 @@ qla2xxx_qpair_sp_compl(void *ptr, int res)
if (!atomic_dec_and_test(&sp->ref_count))
return;
 
-   qla2xxx_qpair_sp_free_dma(sp);
+   sp->free(sp);
cmd->scsi_done(cmd);
 }
 
@@ -935,7 +935,7 @@ qla2xxx_queuecommand(struct Scsi_Host *host, struct 
scsi_cmnd *cmd)
return 0;
 
 qc24_host_busy_free_sp:
-   qla2x00_sp_free_dma(sp);
+   sp->free(sp);
 
 qc24_host_busy:
return SCSI_MLQUEUE_HOST_BUSY;
@@ -1024,7 +1024,7 @@ qla2xxx_mqueuecommand(struct Scsi_Host *host, struct 
scsi_cmnd *cmd,
return 0;
 
 qc24_host_busy_free_sp:
-   qla2xxx_qpair_sp_free_dma(sp);
+   sp->free(sp);
 
 qc24_host_busy:
return SCSI_MLQUEUE_HOST_BUSY;
-- 
2.12.0



[PATCH 04/31] qla2xxx: Add command completion for error path

2017-08-23 Thread Himanshu Madhani
From: Duane Grigsby 

The driver held spinlocks during callbacks for NVME errors
which resulted in a deadlock because recovery LS cmds needed
the same lock.

Signed-off-by: Duane Grigsby 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h  |  2 ++
 drivers/scsi/qla2xxx/qla_gbl.h  |  2 ++
 drivers/scsi/qla2xxx/qla_init.c |  1 +
 drivers/scsi/qla2xxx/qla_mid.c  |  7 +++
 drivers/scsi/qla2xxx/qla_nvme.c | 13 -
 drivers/scsi/qla2xxx/qla_os.c   |  1 +
 6 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index b3e3982a9db0..e3b225cc83f2 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -427,6 +427,7 @@ struct srb_iocb {
enum nvmefc_fcp_datadir dir;
uint32_t dl;
uint32_t timeout_sec;
+   struct  list_head   entry;
} nvme;
} u;
 
@@ -3338,6 +3339,7 @@ struct qla_qpair {
struct work_struct q_work;
struct list_head qp_list_elem; /* vha->qp_list */
struct list_head hints_list;
+   struct list_head nvme_done_list;
uint16_t cpuid;
struct qla_tgt_counters tgt_counters;
 };
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index 97dcabc790c9..f614c37efc9c 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -865,4 +865,6 @@ void qlt_update_host_map(struct scsi_qla_host *, port_id_t);
 void qlt_remove_target_resources(struct qla_hw_data *);
 void qlt_clr_qp_table(struct scsi_qla_host *vha);
 
+void qla_nvme_cmpl_io(struct srb_iocb *);
+
 #endif /* _QLA_GBL_H */
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 8f83571afc7b..988fb5d0f9e7 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -7806,6 +7806,7 @@ struct qla_qpair *qla2xxx_create_qpair(struct 
scsi_qla_host *vha, int qos,
qpair->vp_idx = vp_idx;
qpair->fw_started = ha->flags.fw_started;
INIT_LIST_HEAD(&qpair->hints_list);
+   INIT_LIST_HEAD(&qpair->nvme_done_list);
qpair->chip_reset = ha->base_qpair->chip_reset;
qpair->enable_class_2 = ha->base_qpair->enable_class_2;
qpair->enable_explicit_conf =
diff --git a/drivers/scsi/qla2xxx/qla_mid.c b/drivers/scsi/qla2xxx/qla_mid.c
index 3089094b48fa..608d1aeb97be 100644
--- a/drivers/scsi/qla2xxx/qla_mid.c
+++ b/drivers/scsi/qla2xxx/qla_mid.c
@@ -759,11 +759,18 @@ static void qla_do_work(struct work_struct *work)
struct qla_qpair *qpair = container_of(work, struct qla_qpair, q_work);
struct scsi_qla_host *vha;
struct qla_hw_data *ha = qpair->hw;
+   struct srb_iocb *nvme, *nxt_nvme;
 
spin_lock_irqsave(&qpair->qp_lock, flags);
vha = pci_get_drvdata(ha->pdev);
qla24xx_process_response_queue(vha, qpair->rsp);
spin_unlock_irqrestore(&qpair->qp_lock, flags);
+
+   list_for_each_entry_safe(nvme, nxt_nvme, &qpair->nvme_done_list,
+   u.nvme.entry) {
+   list_del_init(&nvme->u.nvme.entry);
+   qla_nvme_cmpl_io(nvme);
+   }
 }
 
 /* create response queue */
diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
index 97a7b222b549..5692ae128655 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -154,6 +154,16 @@ static void qla_nvme_sp_ls_done(void *ptr, int res)
qla2x00_rel_sp(sp);
 }
 
+void qla_nvme_cmpl_io(struct srb_iocb *nvme)
+{
+   srb_t *sp;
+   struct nvmefc_fcp_req *fd = nvme->u.nvme.desc;
+
+   sp = container_of(nvme, srb_t, u.iocb_cmd);
+   fd->done(fd);
+   qla2xxx_rel_qpair_sp(sp->qpair, sp);
+}
+
 static void qla_nvme_sp_done(void *ptr, int res)
 {
srb_t *sp = ptr;
@@ -175,7 +185,8 @@ static void qla_nvme_sp_done(void *ptr, int res)
fd->status = 0;
 
fd->rcv_rsplen = nvme->u.nvme.rsp_pyld_len;
-   fd->done(fd);
+   list_add_tail(&nvme->u.nvme.entry, &sp->qpair->nvme_done_list);
+   return;
 rel:
qla2xxx_rel_qpair_sp(sp->qpair, sp);
 }
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index d9a115577dc8..b43520ca6645 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -379,6 +379,7 @@ static void qla_init_base_qpair(struct scsi_qla_host *vha, 
struct req_que *req,
ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
INIT_LIST_HEAD(&ha->base_qpair->hints_list);
+   INIT_LIST_HEAD(&ha->base_qpair->nvme_done_list);
ha->base_qpair->enable_class_2 = ql2xenableclass2;
/* init qpair to this cpu. Will adjust at run time. */
qla_cpu_update(rsp->qpair, smp_processor_id());
-- 
2.

[PATCH 14/31] qla2xxx: Prevent sp->free null/uninitialized pointer dereference.

2017-08-23 Thread Himanshu Madhani
From: Joe Carnuccio 

Signed-off-by: Joe Carnuccio 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_init.c | 12 ++--
 drivers/scsi/qla2xxx/qla_mr.c   |  7 ---
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index b380a7c97d5b..d00e0129c51b 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -808,6 +808,12 @@ int qla24xx_async_gpdb(struct scsi_qla_host *vha, 
fc_port_t *fcport, u8 opt)
if (!sp)
goto done;
 
+   sp->type = SRB_MB_IOCB;
+   sp->name = "gpdb";
+   sp->gen1 = fcport->rscn_gen;
+   sp->gen2 = fcport->login_gen;
+   qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
+
pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
if (pd == NULL) {
ql_log(ql_log_warn, vha, 0xd043,
@@ -816,12 +822,6 @@ int qla24xx_async_gpdb(struct scsi_qla_host *vha, 
fc_port_t *fcport, u8 opt)
}
memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
 
-   sp->type = SRB_MB_IOCB;
-   sp->name = "gpdb";
-   sp->gen1 = fcport->rscn_gen;
-   sp->gen2 = fcport->login_gen;
-   qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
-
mb = sp->u.iocb_cmd.u.mbx.out_mb;
mb[0] = MBC_GET_PORT_DATABASE;
mb[1] = fcport->loop_id;
diff --git a/drivers/scsi/qla2xxx/qla_mr.c b/drivers/scsi/qla2xxx/qla_mr.c
index 10b742d27e16..e23a3d4c36f3 100644
--- a/drivers/scsi/qla2xxx/qla_mr.c
+++ b/drivers/scsi/qla2xxx/qla_mr.c
@@ -1819,6 +1819,10 @@ qlafx00_fx_disc(scsi_qla_host_t *vha, fc_port_t *fcport, 
uint16_t fx_type)
if (!sp)
goto done;
 
+   sp->type = SRB_FXIOCB_DCMD;
+   sp->name = "fxdisc";
+   qla2x00_init_timer(sp, FXDISC_TIMEOUT);
+
fdisc = &sp->u.iocb_cmd;
switch (fx_type) {
case FXDISC_GET_CONFIG_INFO:
@@ -1920,9 +1924,6 @@ qlafx00_fx_disc(scsi_qla_host_t *vha, fc_port_t *fcport, 
uint16_t fx_type)
goto done_unmap_req;
}
 
-   sp->type = SRB_FXIOCB_DCMD;
-   sp->name = "fxdisc";
-   qla2x00_init_timer(sp, FXDISC_TIMEOUT);
fdisc->timeout = qla2x00_fxdisc_iocb_timeout;
fdisc->u.fxiocb.req_func_type = cpu_to_le16(fx_type);
sp->done = qla2x00_fxdisc_sp_done;
-- 
2.12.0



[PATCH 16/31] qla2xxx: Move logging default mask to execute once only.

2017-08-23 Thread Himanshu Madhani
From: Joe Carnuccio 

Signed-off-by: Joe Carnuccio 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_dbg.c | 2 --
 drivers/scsi/qla2xxx/qla_os.c  | 2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_dbg.c b/drivers/scsi/qla2xxx/qla_dbg.c
index 7e7cd79038be..065449e0f347 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.c
+++ b/drivers/scsi/qla2xxx/qla_dbg.c
@@ -2520,8 +2520,6 @@ qla83xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
 static inline int
 ql_mask_match(uint32_t level)
 {
-   if (ql2xextended_error_logging == 1)
-   ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
return (level & ql2xextended_error_logging) == level;
 }
 
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 5b033e265a3b..10c3ee53ec3a 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -6648,6 +6648,8 @@ qla2x00_module_init(void)
strcpy(qla2x00_version_str, QLA2XXX_VERSION);
if (ql2xextended_error_logging)
strcat(qla2x00_version_str, "-debug");
+   if (ql2xextended_error_logging == 1)
+   ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
 
qla2xxx_transport_template =
fc_attach_transport(&qla2xxx_transport_functions);
-- 
2.12.0



[PATCH 10/31] qla2xxx: Remove extra register read

2017-08-23 Thread Himanshu Madhani
From: Quinn Tran 

Remove extra register read for each interrupt
for performance improvement.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_isr.c| 9 -
 drivers/scsi/qla2xxx/qla_target.c | 1 -
 2 files changed, 10 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index c6c066186d97..df8a7f378e72 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -3157,7 +3157,6 @@ qla24xx_msix_rsp_q(int irq, void *dev_id)
struct device_reg_24xx __iomem *reg;
struct scsi_qla_host *vha;
unsigned long flags;
-   uint32_t stat = 0;
 
rsp = (struct rsp_que *) dev_id;
if (!rsp) {
@@ -3171,19 +3170,11 @@ qla24xx_msix_rsp_q(int irq, void *dev_id)
spin_lock_irqsave(&ha->hardware_lock, flags);
 
vha = pci_get_drvdata(ha->pdev);
-   /*
-* Use host_status register to check to PCI disconnection before we
-* we process the response queue.
-*/
-   stat = RD_REG_DWORD(®->host_status);
-   if (qla2x00_check_reg32_for_disconnect(vha, stat))
-   goto out;
qla24xx_process_response_queue(vha, rsp);
if (!ha->flags.disable_msix_handshake) {
WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT);
RD_REG_DWORD_RELAXED(®->hccr);
}
-out:
spin_unlock_irqrestore(&ha->hardware_lock, flags);
 
return IRQ_HANDLED;
diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index 4e2a64773060..3bcfbee2ae26 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -6530,7 +6530,6 @@ qlt_24xx_process_atio_queue(struct scsi_qla_host *vha, 
uint8_t ha_locked)
 
/* Adjust ring index */
WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), ha->tgt.atio_ring_index);
-   RD_REG_DWORD_RELAXED(ISP_ATIO_Q_OUT(vha));
 }
 
 void
-- 
2.12.0



[PATCH 24/31] qla2xxx: Cleanup NPIV host in target mode during config teardown

2017-08-23 Thread Himanshu Madhani
From: Quinn Tran 

When we tear down the NPIV host configuration in target mode, the
qla_tgt struct was left dangling on the global list. This patch
cleans up link list and frees memory.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_target.c | 11 +++
 drivers/scsi/qla2xxx/qla_target.h |  1 +
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index 4f1621fd5ef2..43113d52893b 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -1528,6 +1528,7 @@ static void qlt_release(struct qla_tgt *tgt)
u64 key = 0;
u16 i;
struct qla_qpair_hint *h;
+   struct qla_hw_data *ha = vha->hw;
 
if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stop &&
!tgt->tgt_stopped)
@@ -1548,12 +1549,18 @@ static void qlt_release(struct qla_tgt *tgt)
}
}
kfree(tgt->qphints);
+   mutex_lock(&qla_tgt_mutex);
+   list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry);
+   mutex_unlock(&qla_tgt_mutex);
 
btree_for_each_safe64(&tgt->lun_qpair_map, key, node)
btree_remove64(&tgt->lun_qpair_map, key);
 
btree_destroy64(&tgt->lun_qpair_map);
 
+   if (ha->tgt.tgt_ops && ha->tgt.tgt_ops->remove_target)
+   ha->tgt.tgt_ops->remove_target(vha);
+
vha->vha_tgt.qla_tgt = NULL;
 
ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d,
@@ -6175,10 +6182,6 @@ int qlt_remove_target(struct qla_hw_data *ha, struct 
scsi_qla_host *vha)
/* free left over qfull cmds */
qlt_init_term_exchange(vha);
 
-   mutex_lock(&qla_tgt_mutex);
-   list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry);
-   mutex_unlock(&qla_tgt_mutex);
-
ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)",
vha->host_no, ha);
qlt_release(vha->vha_tgt.qla_tgt);
diff --git a/drivers/scsi/qla2xxx/qla_target.h 
b/drivers/scsi/qla2xxx/qla_target.h
index 96fce43e1e46..aba58d3848a6 100644
--- a/drivers/scsi/qla2xxx/qla_target.h
+++ b/drivers/scsi/qla2xxx/qla_target.h
@@ -705,6 +705,7 @@ struct qla_tgt_func_tmpl {
int (*get_dif_tags)(struct qla_tgt_cmd *cmd, uint16_t *pfw_prot_opts);
int (*chk_dif_tags)(uint32_t tag);
void (*add_target)(struct scsi_qla_host *);
+   void (*remove_target)(struct scsi_qla_host *);
 };
 
 int qla2x00_wait_for_hba_online(struct scsi_qla_host *);
-- 
2.12.0



[PATCH 13/31] qla2xxx: Add ability to autodetect SFP type

2017-08-23 Thread Himanshu Madhani
From: Quinn Tran 

SFP can come in 2 formats: short range/SR and long range/LR.
For LR, user the can increase the number of Buffer to Buffer
credits between end points, via Cavium's command line tool.
By default, FW uses a lower BB Credit value optimized for SR.
This patch will read the SFP for each link up event and during
chip reset sequence. If the SFP type and setting are mismatch,
then the chip is reset 1 time to use the appropriate setting.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_attr.c |  42 ++--
 drivers/scsi/qla2xxx/qla_def.h  |  92 +-
 drivers/scsi/qla2xxx/qla_gbl.h  |   3 +
 drivers/scsi/qla2xxx/qla_init.c | 143 
 drivers/scsi/qla2xxx/qla_isr.c  |   5 ++
 drivers/scsi/qla2xxx/qla_mbx.c  |  83 +--
 drivers/scsi/qla2xxx/qla_os.c   |  36 +-
 7 files changed, 361 insertions(+), 43 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 08a1feb3a195..9d2862233e3c 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -565,47 +565,17 @@ qla2x00_sysfs_read_sfp(struct file *filp, struct kobject 
*kobj,
 {
struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
struct device, kobj)));
-   struct qla_hw_data *ha = vha->hw;
-   uint16_t iter, addr, offset;
int rval;
 
-   if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
+   if (!capable(CAP_SYS_ADMIN) || off != 0 || count < SFP_DEV_SIZE)
return 0;
 
-   if (ha->sfp_data)
-   goto do_read;
-
-   ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
-   &ha->sfp_data_dma);
-   if (!ha->sfp_data) {
-   ql_log(ql_log_warn, vha, 0x706c,
-   "Unable to allocate memory for SFP read-data.\n");
+   if (qla2x00_reset_active(vha))
return 0;
-   }
-
-do_read:
-   memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
-   addr = 0xa0;
-   for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
-   iter++, offset += SFP_BLOCK_SIZE) {
-   if (iter == 4) {
-   /* Skip to next device address. */
-   addr = 0xa2;
-   offset = 0;
-   }
-
-   rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
-   addr, offset, SFP_BLOCK_SIZE, BIT_1);
-   if (rval != QLA_SUCCESS) {
-   ql_log(ql_log_warn, vha, 0x706d,
-   "Unable to read SFP data (%x/%x/%x).\n", rval,
-   addr, offset);
 
-   return -EIO;
-   }
-   memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
-   buf += SFP_BLOCK_SIZE;
-   }
+   rval = qla2x00_read_sfp_dev(vha, buf, count);
+   if (rval)
+   return -EIO;
 
return count;
 }
@@ -615,7 +585,7 @@ static struct bin_attribute sysfs_sfp_attr = {
.name = "sfp",
.mode = S_IRUSR | S_IWUSR,
},
-   .size = SFP_DEV_SIZE * 2,
+   .size = SFP_DEV_SIZE,
.read = qla2x00_sysfs_read_sfp,
 };
 
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index e3b225cc83f2..609687d04e3c 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3465,8 +3465,15 @@ struct qla_hw_data {
uint32_tn2n_ae:1;
uint32_tfw_started:1;
uint32_tfw_init_done:1;
+
+   uint32_tdetected_lr_sfp:1;
+   uint32_tusing_lr_setting:1;
} flags;
 
+   u8 long_range_distance; /* 32G & above */
+#define LR_DISTANCE_5K  1
+#define LR_DISTANCE_10K 0
+
/* This spinlock is used to protect "io transactions", you must
* acquire it before doing any IO to the card, eg with RD_REG*() and
* WRT_REG*() for the duration of your entire commandtransaction.
@@ -3714,7 +3721,7 @@ struct qla_hw_data {
struct sns_cmd_pkt  *sns_cmd;
dma_addr_t  sns_cmd_dma;
 
-#define SFP_DEV_SIZE256
+#define SFP_DEV_SIZE512
 #define SFP_BLOCK_SIZE  64
void*sfp_data;
dma_addr_t  sfp_data_dma;
@@ -4095,6 +4102,7 @@ typedef struct scsi_qla_host {
 #define FX00_HOST_INFO_RESEND  26
 #define QPAIR_ONLINE_CHECK_NEEDED  27
 #define SET_ZIO_THRESHOLD_NEEDED   28
+#define DETECT_SFP_CHANGE  29
 
unsigned long   pci_flags;
 #define PFLG_DISCONNECTED  0   /* PCI device removed */
@@ -4378,6 +4386,88 @@ enum nexus_wait_type {
WAIT_LUN,
 };
 
+/* Refer to SNIA SFF 8247 */
+struct sff_8247_a0 {
+   u8 txid;/* transceiver id */
+   u8 ext_txid;
+   u8 connector;
+   /* compliance code */
+   u8 

[PATCH 19/31] qla2xxx: Fix task mgmt handling for NPIV

2017-08-23 Thread Himanshu Madhani
From: Quinn Tran 

Fix task management response for NPIV Target mode.
Current code uses the wrong vp index.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_target.c | 7 ++-
 drivers/scsi/qla2xxx/qla_target.h | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index 6a6d9db6479f..4f1621fd5ef2 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -1901,6 +1901,7 @@ static int __qlt_24xx_handle_abts(struct scsi_qla_host 
*vha,
mcmd->reset_count = ha->base_qpair->chip_reset;
mcmd->tmr_func = QLA_TGT_ABTS;
mcmd->qpair = ha->base_qpair;
+   mcmd->vha = vha;
 
/*
 * LUN is looked up by target-core internally based on the passed
@@ -2003,7 +2004,7 @@ static void qlt_24xx_handle_abts(struct scsi_qla_host 
*vha,
 static void qlt_24xx_send_task_mgmt_ctio(struct qla_qpair *qpair,
struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code)
 {
-   struct scsi_qla_host *ha = qpair->vha;
+   struct scsi_qla_host *ha = mcmd->vha;
struct atio_from_isp *atio = &mcmd->orig_iocb.atio;
struct ctio7_to_24xx *ctio;
uint16_t temp;
@@ -3464,6 +3465,9 @@ static int __qlt_send_term_exchange(struct qla_qpair 
*qpair,
 
ql_dbg(ql_dbg_tgt, vha, 0xe009, "Sending TERM EXCH CTIO (ha=%p)\n", ha);
 
+   if (cmd)
+   vha = cmd->vha;
+
pkt = (request_t *)qla2x00_alloc_iocbs_ready(qpair, NULL);
if (pkt == NULL) {
ql_dbg(ql_dbg_tgt, vha, 0xe050,
@@ -4379,6 +4383,7 @@ static int qlt_issue_task_mgmt(struct fc_port *sess, u64 
lun,
mcmd->flags = flags;
mcmd->reset_count = ha->base_qpair->chip_reset;
mcmd->qpair = ha->base_qpair;
+   mcmd->vha = vha;
 
switch (fn) {
case QLA_TGT_LUN_RESET:
diff --git a/drivers/scsi/qla2xxx/qla_target.h 
b/drivers/scsi/qla2xxx/qla_target.h
index 7fe02d036bdf..96fce43e1e46 100644
--- a/drivers/scsi/qla2xxx/qla_target.h
+++ b/drivers/scsi/qla2xxx/qla_target.h
@@ -959,6 +959,7 @@ struct qla_tgt_mgmt_cmd {
uint8_t fc_tm_rsp;
struct fc_port *sess;
struct qla_qpair *qpair;
+   struct scsi_qla_host *vha;
struct se_cmd se_cmd;
struct work_struct free_work;
unsigned int flags;
-- 
2.12.0



[PATCH 18/31] qla2xxx: Allow SNS fabric login to be retried

2017-08-23 Thread Himanshu Madhani
From: Joe Carnuccio 

If SNS fabric login fails, set loop resync flag to retry via dpc.

Signed-off-by: Joe Carnuccio 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_init.c | 18 +-
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index d00e0129c51b..fe2d196833aa 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -4752,24 +4752,16 @@ qla2x00_configure_fabric(scsi_qla_host_t *vha)
qla2x00_fdmi_register(vha);
 
/* Ensure we are logged into the SNS. */
-   if (IS_FWI2_CAPABLE(ha))
-   loop_id = NPH_SNS;
-   else
-   loop_id = SIMPLE_NAME_SERVER;
+   loop_id = NPH_SNS_LID(ha);
rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
0xfc, mb, BIT_1|BIT_0);
-   if (rval != QLA_SUCCESS) {
+   if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
+   ql_dbg(ql_dbg_disc, vha, 0x20a1,
+   "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x 
mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
+   loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
return rval;
}
-   if (mb[0] != MBS_COMMAND_COMPLETE) {
-   ql_dbg(ql_dbg_disc, vha, 0x20a1,
-   "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x 
mb[2]=%x "
-   "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
-   mb[2], mb[6], mb[7]);
-   return (QLA_SUCCESS);
-   }
-
if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
if (qla2x00_rft_id(vha)) {
/* EMPTY */
-- 
2.12.0



[PATCH 17/31] qla2xxx: Add timeout ability to wait_for_sess_deletion().

2017-08-23 Thread Himanshu Madhani
From: Joe Carnuccio 

Signed-off-by: Joe Carnuccio 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_os.c | 2 +-
 drivers/scsi/qla2xxx/qla_target.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 10c3ee53ec3a..c217cec4dd49 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -1141,7 +1141,7 @@ qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
 {
qla2x00_mark_all_devices_lost(vha, 0);
 
-   wait_event(vha->fcport_waitQ, test_fcport_count(vha));
+   wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha), 10*HZ);
 }
 
 /*
diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index 3bcfbee2ae26..6a6d9db6479f 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -1479,7 +1479,7 @@ int qlt_stop_phase1(struct qla_tgt *tgt)
ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a,
"Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count);
 
-   wait_event(tgt->waitQ, test_tgt_sess_count(tgt));
+   wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ);
 
/* Big hammer */
if (!ha->flags.host_shutting_down &&
@@ -1487,7 +1487,7 @@ int qlt_stop_phase1(struct qla_tgt *tgt)
qlt_disable_vha(vha);
 
/* Wait for sessions to clear out (just in case) */
-   wait_event(tgt->waitQ, test_tgt_sess_count(tgt));
+   wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ);
return 0;
 }
 EXPORT_SYMBOL(qlt_stop_phase1);
-- 
2.12.0



[PATCH 25/31] qla2xxx: Enable Async TMF processing

2017-08-23 Thread Himanshu Madhani
Signed-off-by: Himanshu Madhani 
Signed-off-by: Giridhar Malavali 
---
 drivers/scsi/qla2xxx/qla_os.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index c217cec4dd49..0814ff4fa2c0 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -200,7 +200,7 @@ MODULE_PARM_DESC(ql2xgffidenable,
"Enables GFF_ID checks of port type. "
"Default is 0 - Do not use GFF_ID information.");
 
-int ql2xasynctmfenable;
+int ql2xasynctmfenable = 1;
 module_param(ql2xasynctmfenable, int, S_IRUGO);
 MODULE_PARM_DESC(ql2xasynctmfenable,
"Enables issue of TM IOCBs asynchronously via IOCB mechanism"
-- 
2.12.0



[PATCH 26/31] qla2xxx: Increase ql2xmaxqdepth to 64

2017-08-23 Thread Himanshu Madhani
From: Michael Hernandez 

ql2xmaxqdepth is the module parameter that seeds the per target
queue depth in the Scsi midlayer (sdev->queue_depth). Performance
testing revealed that increasing this value would improve IOPS
numbers under certain workloads.

Signed-off-by: Michael Hernandez 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_os.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 0814ff4fa2c0..715427f8e732 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -113,12 +113,12 @@ MODULE_PARM_DESC(ql2xfdmienable,
"Enables FDMI registrations. "
"0 - no FDMI. Default is 1 - perform FDMI.");
 
-#define MAX_Q_DEPTH32
+#define MAX_Q_DEPTH64
 static int ql2xmaxqdepth = MAX_Q_DEPTH;
 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
 MODULE_PARM_DESC(ql2xmaxqdepth,
"Maximum queue depth to set for each LUN. "
-   "Default is 32.");
+   "Default is 64.");
 
 #if (IS_ENABLED(CONFIG_NVME_FC))
 int ql2xenabledif;
-- 
2.12.0



[PATCH 31/31] qla2xxx: Update driver version to 10.00.00.01-k

2017-08-23 Thread Himanshu Madhani
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_version.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_version.h 
b/drivers/scsi/qla2xxx/qla_version.h
index 005a378f7fab..8c4b505c9f66 100644
--- a/drivers/scsi/qla2xxx/qla_version.h
+++ b/drivers/scsi/qla2xxx/qla_version.h
@@ -7,7 +7,7 @@
 /*
  * Driver version
  */
-#define QLA2XXX_VERSION  "10.00.00.00-k"
+#define QLA2XXX_VERSION  "10.00.00.01-k"
 
 #define QLA_DRIVER_MAJOR_VER   10
 #define QLA_DRIVER_MINOR_VER   0
-- 
2.12.0



[PATCH 21/31] qla2xxx: Remove potential macro parameter side-effect in ql_dump_regs()

2017-08-23 Thread Himanshu Madhani
From: Joe Carnuccio 

Signed-off-by: Joe Carnuccio 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_dbg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_dbg.c b/drivers/scsi/qla2xxx/qla_dbg.c
index 065449e0f347..3e9dc54b89a3 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.c
+++ b/drivers/scsi/qla2xxx/qla_dbg.c
@@ -2736,9 +2736,9 @@ ql_dump_regs(uint32_t level, scsi_qla_host_t *vha, 
int32_t id)
mbx_reg = MAILBOX_REG(ha, reg, 0);
 
ql_dbg(level, vha, id, "Mailbox registers:\n");
-   for (i = 0; i < 6; i++)
+   for (i = 0; i < 6; i++, mbx_reg++)
ql_dbg(level, vha, id,
-   "mbox[%d] 0x%04x\n", i, RD_REG_WORD(mbx_reg++));
+   "mbox[%d] 0x%04x\n", i, RD_REG_WORD(mbx_reg));
 }
 
 
-- 
2.12.0



[PATCH 28/31] qla2xxx: Skip zero queue count entry during FW dump capture

2017-08-23 Thread Himanshu Madhani
From: Joe Carnuccio 

If queue count is zero while reading FW dump template, for entry
T263/T274, skip capturing those entries during FW dump capture.

Signed-off-by: Joe Carnuccio 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_tmpl.c | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_tmpl.c b/drivers/scsi/qla2xxx/qla_tmpl.c
index b18646d6057f..733e8dcccf5c 100644
--- a/drivers/scsi/qla2xxx/qla_tmpl.c
+++ b/drivers/scsi/qla2xxx/qla_tmpl.c
@@ -443,8 +443,12 @@ qla27xx_fwdt_entry_t263(struct scsi_qla_host *vha,
qla27xx_skip_entry(ent, buf);
}
 
-   if (buf)
-   ent->t263.num_queues = count;
+   if (buf) {
+   if (count)
+   ent->t263.num_queues = count;
+   else
+   qla27xx_skip_entry(ent, buf);
+   }
 
return false;
 }
@@ -692,11 +696,12 @@ qla27xx_fwdt_entry_t274(struct scsi_qla_host *vha,
qla27xx_skip_entry(ent, buf);
}
 
-   if (buf)
-   ent->t274.num_queues = count;
-
-   if (!count)
-   qla27xx_skip_entry(ent, buf);
+   if (buf) {
+   if (count)
+   ent->t274.num_queues = count;
+   else
+   qla27xx_skip_entry(ent, buf);
+   }
 
return false;
 }
-- 
2.12.0



[PATCH 30/31] qla2xxx: Do not call abort handler function during chip reset

2017-08-23 Thread Himanshu Madhani
From: Sawan Chandak 

If there are IO's running and host reset or chip reset is triggered,
IO's can fail due to rport time out. During chip reset recovery process,
driver notifies the transport layer that remote port no longer exist,
by calling fc_remote_port_delete(). When this function is called,
it actually delays deletion by "blocking" it. It sets the remote
port state to "FC_PORTSTATE_BLOCKED" and sets FC_RPORT_DEVLOSS_PENDING.
When driver tries to abort the command by calling its abort handler
function, abort handler will wait until remote port state is blocked
state or wait for dev_loss_tmo time. Due to this bocking, rport times
out and results in an IO failure. This patch adds a check for any
active reset process before calling abort handler function.

Signed-off-by: Sawan Chandak 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_os.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 715427f8e732..56bd086b79ea 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -1732,6 +1732,8 @@ qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
&ha->hardware_lock, flags);
} else if (GET_CMD_SP(sp) &&
!ha->flags.eeh_busy &&
+   (!test_bit(ABORT_ISP_ACTIVE,
+   &vha->dpc_flags)) &&
(sp->type == SRB_SCSI_CMD)) {
/*
 * Don't abort commands in
-- 
2.12.0



[PATCH 29/31] qla2xxx: Ability to process multiple SGEs in Command SGL for CT passthrough commands.

2017-08-23 Thread Himanshu Madhani
From: Giridhar Malavali 

Signed-off-by: Giridhar Malavali 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_iocb.c | 55 ++---
 1 file changed, 35 insertions(+), 20 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index a36c485fae50..2f94159186d7 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -2682,12 +2682,12 @@ qla24xx_ct_iocb(srb_t *sp, struct ct_entry_24xx 
*ct_iocb)
uint32_t*cur_dsd;
struct scatterlist *sg;
int index;
-   uint16_t tot_dsds;
+   uint16_t cmd_dsds, rsp_dsds;
scsi_qla_host_t *vha = sp->vha;
struct qla_hw_data *ha = vha->hw;
struct bsg_job *bsg_job = sp->u.bsg_job;
-   int loop_iterartion = 0;
int entry_count = 1;
+   cont_a64_entry_t *cont_pkt = NULL;
 
ct_iocb->entry_type = CT_IOCB_TYPE;
 ct_iocb->entry_status = 0;
@@ -2698,30 +2698,46 @@ qla24xx_ct_iocb(srb_t *sp, struct ct_entry_24xx 
*ct_iocb)
ct_iocb->vp_index = sp->vha->vp_idx;
ct_iocb->comp_status = cpu_to_le16(0);
 
-   ct_iocb->cmd_dsd_count =
-   cpu_to_le16(bsg_job->request_payload.sg_cnt);
+   cmd_dsds = bsg_job->request_payload.sg_cnt;
+   rsp_dsds = bsg_job->reply_payload.sg_cnt;
+
+   ct_iocb->cmd_dsd_count = cpu_to_le16(cmd_dsds);
 ct_iocb->timeout = 0;
-ct_iocb->rsp_dsd_count =
-   cpu_to_le16(bsg_job->reply_payload.sg_cnt);
-ct_iocb->rsp_byte_count =
-cpu_to_le32(bsg_job->reply_payload.payload_len);
+   ct_iocb->rsp_dsd_count = cpu_to_le16(rsp_dsds);
 ct_iocb->cmd_byte_count =
 cpu_to_le32(bsg_job->request_payload.payload_len);
-ct_iocb->dseg_0_address[0] = cpu_to_le32(LSD(sg_dma_address
-(bsg_job->request_payload.sg_list)));
-ct_iocb->dseg_0_address[1] = cpu_to_le32(MSD(sg_dma_address
-   (bsg_job->request_payload.sg_list)));
-ct_iocb->dseg_0_len = cpu_to_le32(sg_dma_len
-(bsg_job->request_payload.sg_list));
 
-   avail_dsds = 1;
-   cur_dsd = (uint32_t *)ct_iocb->dseg_1_address;
+   avail_dsds = 2;
+   cur_dsd = (uint32_t *)ct_iocb->dseg_0_address;
index = 0;
-   tot_dsds = bsg_job->reply_payload.sg_cnt;
 
-   for_each_sg(bsg_job->reply_payload.sg_list, sg, tot_dsds, index) {
+   for_each_sg(bsg_job->request_payload.sg_list, sg, cmd_dsds, index) {
+   dma_addr_t   sle_dma;
+
+   /* Allocate additional continuation packets? */
+   if (avail_dsds == 0) {
+   /*
+* Five DSDs are available in the Cont.
+* Type 1 IOCB.
+*/
+   cont_pkt = qla2x00_prep_cont_type1_iocb(
+   vha, ha->req_q_map[0]);
+   cur_dsd = (uint32_t *) cont_pkt->dseg_0_address;
+   avail_dsds = 5;
+   entry_count++;
+   }
+
+   sle_dma = sg_dma_address(sg);
+   *cur_dsd++   = cpu_to_le32(LSD(sle_dma));
+   *cur_dsd++   = cpu_to_le32(MSD(sle_dma));
+   *cur_dsd++   = cpu_to_le32(sg_dma_len(sg));
+   avail_dsds--;
+   }
+
+   index = 0;
+
+   for_each_sg(bsg_job->reply_payload.sg_list, sg, rsp_dsds, index) {
dma_addr_t   sle_dma;
-   cont_a64_entry_t *cont_pkt;
 
/* Allocate additional continuation packets? */
if (avail_dsds == 0) {
@@ -2740,7 +2756,6 @@ qla24xx_ct_iocb(srb_t *sp, struct ct_entry_24xx *ct_iocb)
*cur_dsd++   = cpu_to_le32(LSD(sle_dma));
*cur_dsd++   = cpu_to_le32(MSD(sle_dma));
*cur_dsd++   = cpu_to_le32(sg_dma_len(sg));
-   loop_iterartion++;
avail_dsds--;
}
 ct_iocb->entry_count = entry_count;
-- 
2.12.0



[PATCH 22/31] qla2xxx: Add support for minimum link speed

2017-08-23 Thread Himanshu Madhani
From: Sawan Chandak 

Signed-off-by: Sawan Chandak 
Signed-off-by: Joe Carnuccio 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_attr.c | 36 
 drivers/scsi/qla2xxx/qla_def.h  |  4 
 drivers/scsi/qla2xxx/qla_fw.h   |  4 +++-
 drivers/scsi/qla2xxx/qla_isr.c  |  5 +
 drivers/scsi/qla2xxx/qla_mbx.c  | 46 ++---
 5 files changed, 91 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 9d2862233e3c..75c4b312645e 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -1481,6 +1481,38 @@ qla2x00_pep_version_show(struct device *dev, struct 
device_attribute *attr,
ha->pep_version[0], ha->pep_version[1], ha->pep_version[2]);
 }
 
+static ssize_t
+qla2x00_min_link_speed_show(struct device *dev, struct device_attribute *attr,
+char *buf)
+{
+   scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
+   struct qla_hw_data *ha = vha->hw;
+
+   if (!IS_QLA27XX(ha))
+   return scnprintf(buf, PAGE_SIZE, "\n");
+
+   return scnprintf(buf, PAGE_SIZE, "%s\n",
+   ha->min_link_speed == 5 ? "32Gps" :
+   ha->min_link_speed == 4 ? "16Gps" :
+   ha->min_link_speed == 3 ? "8Gps" :
+   ha->min_link_speed == 2 ? "4Gps" :
+   ha->min_link_speed != 0 ? "unknown" : "");
+}
+
+static ssize_t
+qla2x00_max_speed_sup_show(struct device *dev, struct device_attribute *attr,
+char *buf)
+{
+   scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
+   struct qla_hw_data *ha = vha->hw;
+
+   if (!IS_QLA27XX(ha))
+   return scnprintf(buf, PAGE_SIZE, "\n");
+
+   return scnprintf(buf, PAGE_SIZE, "%s\n",
+   ha->max_speed_sup ? "32Gps" : "16Gps");
+}
+
 static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
@@ -1526,6 +1558,8 @@ static DEVICE_ATTR(allow_cna_fw_dump, S_IRUGO | S_IWUSR,
   qla2x00_allow_cna_fw_dump_show,
   qla2x00_allow_cna_fw_dump_store);
 static DEVICE_ATTR(pep_version, S_IRUGO, qla2x00_pep_version_show, NULL);
+static DEVICE_ATTR(min_link_speed, S_IRUGO, qla2x00_min_link_speed_show, NULL);
+static DEVICE_ATTR(max_speed_sup, S_IRUGO, qla2x00_max_speed_sup_show, NULL);
 
 struct device_attribute *qla2x00_host_attrs[] = {
&dev_attr_driver_version,
@@ -1560,6 +1594,8 @@ struct device_attribute *qla2x00_host_attrs[] = {
&dev_attr_fw_dump_size,
&dev_attr_allow_cna_fw_dump,
&dev_attr_pep_version,
+   &dev_attr_min_link_speed,
+   &dev_attr_max_speed_sup,
NULL,
 };
 
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 609687d04e3c..0f80b812f4a7 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -902,6 +902,7 @@ struct mbx_cmd_32 {
 #define MBA_SHUTDOWN_REQUESTED 0x8062  /* Shutdown Requested */
 #define MBA_TEMPERATURE_ALERT  0x8070  /* Temperature Alert */
 #define MBA_DPORT_DIAGNOSTICS  0x8080  /* D-port Diagnostics */
+#define MBA_TRANS_INSERT   0x8130  /* Transceiver Insertion */
 #define MBA_FW_INIT_FAILURE0x8401  /* Firmware initialization failure */
 #define MBA_MIRROR_LUN_CHANGE  0x8402  /* Mirror LUN State Change
   Notification */
@@ -4026,6 +4027,8 @@ struct qla_hw_data {
 
struct qlt_hw_data tgt;
int allow_cna_fw_dump;
+   uint16_t min_link_speed;
+   uint16_t max_speed_sup;
 
atomic_tnvme_active_aen_cnt;
uint16_tnvme_last_rptd_aen; /* Last recorded aen 
count */
@@ -4212,6 +4215,7 @@ typedef struct scsi_qla_host {
int fcport_count;
wait_queue_head_t fcport_waitQ;
wait_queue_head_t vref_waitq;
+   uint8_t min_link_speed_feat;
 } scsi_qla_host_t;
 
 struct qla27xx_image_status {
diff --git a/drivers/scsi/qla2xxx/qla_fw.h b/drivers/scsi/qla2xxx/qla_fw.h
index b9c9886e8b1d..94eb1694fc3e 100644
--- a/drivers/scsi/qla2xxx/qla_fw.h
+++ b/drivers/scsi/qla2xxx/qla_fw.h
@@ -1745,7 +1745,9 @@ struct nvram_81xx {
uint16_t reserved_6_3[14];
 
/* Offset 192. */
-   uint16_t reserved_7[32];
+   uint8_t min_link_speed;
+   uint8_t reserved_7_0;
+   uint16_t reserved_7[31];
 
/*
 * BIT 0  = Enable spinup delay
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index c58fb493dbd9..527c5218e10b 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -1233,6 +1233,11 @@ qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que 
*rsp, uint16_t *mb)
schedule_work(&ha->board_disable);
break;
 
+   case MBA_TRANS_INSERT:
+   ql_dbg(ql_

[PATCH 20/31] qla2xxx: Print correct mailbox registers in failed summary

2017-08-23 Thread Himanshu Madhani
From: Joe Carnuccio 

Signed-off-by: Joe Carnuccio 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_mbx.c | 26 ++
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 52cb9882bf31..da992b761402 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -106,7 +106,6 @@ qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t 
*mcp)
uint16_t __iomem *optr;
uint32_tcnt;
uint32_tmboxes;
-   uint16_t __iomem *mbx_reg;
unsigned long   wait_time;
struct qla_hw_data *ha = vha->hw;
scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
@@ -490,21 +489,24 @@ qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t 
*mcp)
 
 mbx_done:
if (rval) {
-   ql_dbg(ql_dbg_disc, base_vha, 0x1020,
-   " Failed mbx[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x, 
cmd=%x .\n",
-   mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3], command);
-
+   if (ql2xextended_error_logging & (ql_dbg_disc|ql_dbg_mbx)) {
+   pr_warn("%s [%s]-%04x:%ld:  Failed", QL_MSGHDR,
+   dev_name(&ha->pdev->dev), 0x1020+0x800,
+   vha->host_no);
+   mboxes = mcp->in_mb;
+   cnt = 4;
+   for (i = 0; i < ha->mbx_count && cnt; i++, mboxes >>= 1)
+   if (mboxes & BIT_0) {
+   printk(" mb[%u]=%x", i, mcp->mb[i]);
+   cnt--;
+   }
+   pr_warn(" cmd=%x \n", command);
+   }
ql_dbg(ql_dbg_mbx, vha, 0x1198,
-   "host status: 0x%x, flags:0x%lx, intr ctrl reg:0x%x, intr 
status:0x%x\n",
+   "host_status=%#x intr_ctrl=%#x intr_status=%#x\n",
RD_REG_DWORD(®->isp24.host_status),
-   ha->fw_dump_cap_flags,
RD_REG_DWORD(®->isp24.ictrl),
RD_REG_DWORD(®->isp24.istatus));
-
-   mbx_reg = ®->isp24.mailbox0;
-   for (i = 0; i < 6; i++)
-   ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1199,
-   "mbox[%d] 0x%04x\n", i, RD_REG_WORD(mbx_reg++));
} else {
ql_dbg(ql_dbg_mbx, base_vha, 0x1021, "Done %s.\n", __func__);
}
-- 
2.12.0



[PATCH 23/31] qla2xxx: Add LR distance support from nvram bit

2017-08-23 Thread Himanshu Madhani
From: Joe Carnuccio 

Signed-off-by: Joe Carnuccio 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h |  9 ++-
 drivers/scsi/qla2xxx/qla_fw.h  | 24 +++---
 drivers/scsi/qla2xxx/qla_mbx.c | 56 --
 3 files changed, 61 insertions(+), 28 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 0f80b812f4a7..486c075998f6 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3471,7 +3471,7 @@ struct qla_hw_data {
uint32_tusing_lr_setting:1;
} flags;
 
-   u8 long_range_distance; /* 32G & above */
+   uint16_t long_range_distance;   /* 32G & above */
 #define LR_DISTANCE_5K  1
 #define LR_DISTANCE_10K 0
 
@@ -4027,6 +4027,7 @@ struct qla_hw_data {
 
struct qlt_hw_data tgt;
int allow_cna_fw_dump;
+   uint32_t fw_ability_mask;
uint16_t min_link_speed;
uint16_t max_speed_sup;
 
@@ -4034,6 +4035,12 @@ struct qla_hw_data {
uint16_tnvme_last_rptd_aen; /* Last recorded aen 
count */
 };
 
+#define FW_ABILITY_MAX_SPEED_MASK  0xFUL
+#define FW_ABILITY_MAX_SPEED_16G   0x0
+#define FW_ABILITY_MAX_SPEED_32G   0x1
+#define FW_ABILITY_MAX_SPEED(ha)   \
+   (ha->fw_ability_mask & FW_ABILITY_MAX_SPEED_MASK)
+
 /*
  * Qlogic scsi host structure
  */
diff --git a/drivers/scsi/qla2xxx/qla_fw.h b/drivers/scsi/qla2xxx/qla_fw.h
index 94eb1694fc3e..bec641aae7b3 100644
--- a/drivers/scsi/qla2xxx/qla_fw.h
+++ b/drivers/scsi/qla2xxx/qla_fw.h
@@ -1699,6 +1699,15 @@ struct access_chip_rsp_84xx {
 #define FAC_OPT_CMD_UNLOCK_SEMAPHORE   0x04
 #define FAC_OPT_CMD_GET_SECTOR_SIZE0x05
 
+/* enhanced features bit definitions */
+#define NEF_LR_DIST_ENABLE BIT_0
+
+/* LR Distance bit positions */
+#define LR_DIST_NV_POS 2
+#define LR_DIST_FW_POS 12
+#define LR_DIST_FW_SHIFT   (LR_DIST_FW_POS - LR_DIST_NV_POS)
+#define LR_DIST_FW_FIELD(x)((x) << LR_DIST_FW_SHIFT & 0xf000)
+
 struct nvram_81xx {
/* NVRAM header. */
uint8_t id[4];
@@ -1841,16 +1850,13 @@ struct nvram_81xx {
uint8_t reserved_21[16];
uint16_t reserved_22[3];
 
-   /*
-* BIT 0 = Extended BB credits for LR
-* BIT 1 = Virtual Fabric Enable
-* BIT 2 = Enhanced Features Unused
-* BIT 3-7 = Enhanced Features Reserved
+   /* Offset 406 (0x196) Enhanced Features
+* BIT 0= Extended BB credits for LR
+* BIT 1= Virtual Fabric Enable
+* BIT 2-5  = Distance Support if BIT 0 is on
+* BIT 6-15 = Unused
 */
-   /* Enhanced Features */
-   uint8_t enhanced_features;
-
-   uint8_t reserved_23;
+   uint16_t enhanced_features;
uint16_t reserved_24[4];
 
/* Offset 416. */
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 32bbbd50567d..99502fa90810 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -567,6 +567,28 @@ qla2x00_load_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, 
uint32_t risc_addr,
 
 #defineEXTENDED_BB_CREDITS BIT_0
 #defineNVME_ENABLE_FLAGBIT_3
+static inline uint16_t qla25xx_set_sfp_lr_dist(struct qla_hw_data *ha)
+{
+   uint16_t mb4 = BIT_0;
+
+   if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
+   mb4 |= ha->long_range_distance << LR_DIST_FW_POS;
+
+   return mb4;
+}
+
+static inline uint16_t qla25xx_set_nvr_lr_dist(struct qla_hw_data *ha)
+{
+   uint16_t mb4 = BIT_0;
+
+   if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
+   struct nvram_81xx *nv = ha->nvram;
+
+   mb4 |= LR_DIST_FW_FIELD(nv->enhanced_features);
+   }
+
+   return mb4;
+}
 
 /*
  * qla2x00_execute_fw
@@ -602,27 +624,25 @@ qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t 
risc_addr)
mcp->mb[2] = LSW(risc_addr);
mcp->mb[3] = 0;
mcp->mb[4] = 0;
+   ha->flags.using_lr_setting = 0;
if (IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
IS_QLA27XX(ha)) {
if (ql2xautodetectsfp) {
if (ha->flags.detected_lr_sfp) {
-   mcp->mb[4] |= EXTENDED_BB_CREDITS;
-   if (IS_QLA27XX(ha))
-   mcp->mb[4] |=
-   (u16)ha->long_range_distance << 12;
+   mcp->mb[4] |=
+   qla25xx_set_sfp_lr_dist(ha);
ha->flags.using_lr_setting = 1;
}
} else {
struct nvram_81xx *nv = ha->nvram;
-
+   /* set LR distance if specified in nvram */
   

[PATCH 27/31] qla2xxx: Recheck session state after RSCN

2017-08-23 Thread Himanshu Madhani
From: Quinn Tran 

When RSCN is delivered for specific remote port,
Use ADISC to verify the session is still valid or not.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_gbl.h  |  2 +-
 drivers/scsi/qla2xxx/qla_gs.c   | 16 +++-
 drivers/scsi/qla2xxx/qla_init.c |  4 +---
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index 3aada5dd597f..0b219b3ca653 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -106,7 +106,7 @@ int qla24xx_post_newsess_work(struct scsi_qla_host *, 
port_id_t *, u8 *,
 void *);
 int qla24xx_fcport_handle_login(struct scsi_qla_host *, fc_port_t *);
 int qla24xx_detect_sfp(scsi_qla_host_t *vha);
-
+int qla24xx_post_gpdb_work(struct scsi_qla_host *, fc_port_t *, u8);
 /*
  * Global Data in qla_os.c source file.
  */
diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c
index 0ec250993e93..bc3db6abc9a0 100644
--- a/drivers/scsi/qla2xxx/qla_gs.c
+++ b/drivers/scsi/qla2xxx/qla_gs.c
@@ -2816,13 +2816,19 @@ void qla24xx_handle_gidpn_event(scsi_qla_host_t *vha, 
struct event_arg *ea)
case MODE_INITIATOR:
case MODE_DUAL:
default:
+   ql_dbg(ql_dbg_disc, vha, 0x201f,
+   "%s %d %8phC post %s\n", __func__,
+   __LINE__, fcport->port_name,
+   (atomic_read(&fcport->state) ==
+   FCS_ONLINE) ? "gpdb" : "gnl");
+
if (atomic_read(&fcport->state) ==
FCS_ONLINE)
-   break;
-   ql_dbg(ql_dbg_disc, vha, 0x201f,
-   "%s %d %8phC post gnl\n",
-   __func__, __LINE__, 
fcport->port_name);
-   qla24xx_post_gnl_work(vha, fcport);
+   qla24xx_post_gpdb_work(vha,
+   fcport, PDO_FORCE_ADISC);
+   else
+   qla24xx_post_gnl_work(vha,
+   fcport);
break;
}
} else { /* fcport->d_id.b24 != ea->id.b24 */
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index fe2d196833aa..30b3acacbfca 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -36,7 +36,6 @@ static int qla2x00_restart_isp(scsi_qla_host_t *);
 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
 static int qla84xx_init_chip(scsi_qla_host_t *);
 static int qla25xx_init_queues(struct qla_hw_data *);
-static int qla24xx_post_gpdb_work(struct scsi_qla_host *, fc_port_t *, u8);
 static int qla24xx_post_prli_work(struct scsi_qla_host*, fc_port_t *);
 static void qla24xx_handle_plogi_done_event(struct scsi_qla_host *,
 struct event_arg *);
@@ -774,8 +773,7 @@ qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t 
*fcport)
return rval;
 }
 
-static int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport,
-u8 opt)
+int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 
opt)
 {
struct qla_work_evt *e;
 
-- 
2.12.0



Re: [v4.13-rc BUG] system lockup when running big buffered write(4M) to IB SRP via mpath

2017-08-23 Thread Mike Snitzer
On Wed, Aug 23 2017 at 11:12am -0400,
Bart Van Assche  wrote:

> On Wed, 2017-08-23 at 19:35 +0800, Ming Lei wrote:
> > soft lockup still can be observed easily with patch d4acf3650c7c(
> > block: Make blk_mq_delay_kick_requeue_list() rerun the queue at a quiet 
> > time),
> > but no hard lockup.
> 
> Hello Ming,
> 
> I never claimed that commit d4acf3650c7c was a full solution to avoid these
> soft lockups. I assume these results mean that patch series "[PATCH 0/7]
> Device mapper and dm-mpath fixes" was not applied to the kernel used in your
> tests? A colleague of you has reported that that patch series is sufficient
> to avoid these soft lockups. See also
> https://www.redhat.com/archives/dm-devel/2017-August/msg00122.html.

FYI, I'll try to review/stage that patchset for 4.14 over the next few
days.

(I'm not yet back to working full-time but will try to handle my
upstream responsibilities)

Mike


[PATCH v3 03/20] lpfc: Fix rediscovery on switch blade pull

2017-08-23 Thread James Smart
From: Dick Kennedy 

When the switch blade is pulled out then plugged back in, the driver
does not issue a PLOGI to the target

When the switch blade is pulled out, it does not reset the link. The
driver ends up issuing a LOGO to the target, and finally sees devloss.
Since the driver believes that a LOGO is outstanding, it does not
issue a PLOGI to the target upon link up

Correct by placing the ndlp in UNUSED state When devloss happens in
LOGO_ISSUE state.

Signed-off-by: Dick Kennedy 
Signed-off-by: James Smart 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/lpfc/lpfc_nportdisc.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c 
b/drivers/scsi/lpfc/lpfc_nportdisc.c
index 95b2b43ac37d..a4488d6339c1 100644
--- a/drivers/scsi/lpfc/lpfc_nportdisc.c
+++ b/drivers/scsi/lpfc/lpfc_nportdisc.c
@@ -2192,12 +2192,15 @@ lpfc_device_rm_logo_issue(struct lpfc_vport *vport, 
struct lpfc_nodelist *ndlp,
  void *arg, uint32_t evt)
 {
/*
-* Take no action.  If a LOGO is outstanding, then possibly DevLoss has
-* timed out and is calling for Device Remove.  In this case, the LOGO
-* must be allowed to complete in state LOGO_ISSUE so that the rpi
-* and other NLP flags are correctly cleaned up.
+* DevLoss has timed out and is calling for Device Remove.
+* In this case, abort the LOGO and cleanup the ndlp
 */
-   return ndlp->nlp_state;
+
+   lpfc_unreg_rpi(vport, ndlp);
+   /* software abort outstanding PLOGI */
+   lpfc_els_abort(vport->phba, ndlp);
+   lpfc_drop_node(vport, ndlp);
+   return NLP_STE_FREED_NODE;
 }
 
 static uint32_t
-- 
2.13.1



[PATCH v3 00/20] lpfc updates for 11.4.0.3

2017-08-23 Thread James Smart
This patch set provides a number of bug fixes and one additions.
The additions are BB credit support.

The patches were cut against the Martin's 4.13/scsi-fixes tree.
There are no outside dependencies.

V2:
 removed redundant Expresslane patch
 removed if type 6 support. Will add later.
 Incorporated patch from Maurizio Lombardi int constant too large

V3:
 Address v2 review comments:
   revise if tests for better indentation
   removed unnecessary typecasts
   slight reword patch description or comment
   use list_splict_init


Dick Kennedy (17):
  lpfc: Fix plogi collision that causes illegal state transition
  lpfc: Fix loop mode target discovery
  lpfc: Fix rediscovery on switch blade pull
  lpfc: Fix oops when NVME Target is discovered in a nonNVME environment
  lpfc: convert info messages to standard messages
  lpfc: Correct return error codes to align with nvme_fc transport
  lpfc: Fix handling of FCP and NVME FC4 types in Pt2Pt topology
  lpfc: Fix duplicate NVME rport entries and namespaces.
  lpfc: Fix crash in lpfc nvmet when fc port is reset
  lpfc: Fix NVME PRLI handling during RSCN
  lpfc: Correct issues with FAWWN and FDISCs
  lpfc: Limit amount of work processed in IRQ
  lpfc: Fix MRQ > 1 context list handling
  lpfc: Fix relative offset error on large nvmet target ios
  lpfc: Fix nvme target failure after 2nd adapter reset
  lpfc: Fix bad sgl reposting after 2nd adapter reset
  lpfc: lpfc version bump 11.4.0.3

James Smart (2):
  lpfc: remove console log clutter
  lpfc: Add Buffer to Buffer credit recovery support

Maurizio Lombardi (1):
  scsi: lpfc: fix "integer constant too large" error on 32bit archs

 drivers/scsi/lpfc/lpfc.h   |   3 +-
 drivers/scsi/lpfc/lpfc_attr.c  |  52 ++-
 drivers/scsi/lpfc/lpfc_attr.h  |  10 ++
 drivers/scsi/lpfc/lpfc_crtn.h  |   5 +-
 drivers/scsi/lpfc/lpfc_ct.c|   4 +-
 drivers/scsi/lpfc/lpfc_debugfs.c   |  11 +-
 drivers/scsi/lpfc/lpfc_disc.h  |   1 +
 drivers/scsi/lpfc/lpfc_els.c   |  93 -
 drivers/scsi/lpfc/lpfc_hbadisc.c   |  12 +-
 drivers/scsi/lpfc/lpfc_hw.h|  18 ++-
 drivers/scsi/lpfc/lpfc_hw4.h   |  23 +++-
 drivers/scsi/lpfc/lpfc_init.c  |  57 +---
 drivers/scsi/lpfc/lpfc_mbox.c  |  35 -
 drivers/scsi/lpfc/lpfc_nportdisc.c |  25 +++-
 drivers/scsi/lpfc/lpfc_nvme.c  |  25 ++--
 drivers/scsi/lpfc/lpfc_nvmet.c | 270 -
 drivers/scsi/lpfc/lpfc_nvmet.h |  14 ++
 drivers/scsi/lpfc/lpfc_sli.c   |  56 +---
 drivers/scsi/lpfc/lpfc_sli4.h  |  23 +++-
 drivers/scsi/lpfc/lpfc_version.h   |   2 +-
 20 files changed, 584 insertions(+), 155 deletions(-)

-- 
2.13.1



[PATCH v3 02/20] lpfc: Fix loop mode target discovery

2017-08-23 Thread James Smart
From: Dick Kennedy 

The driver does not discover targets when in loop mode.

The NLP type is correctly getting set when a fabric connection is
detected but, not for loop. The unknown NLP type means that the
driver does not issue a PRLI when in loop topology. Thus target
discovery fails.

Fix by checking the topology during discovery.  If it is loop,
set the NLP FC4 type to FCP.

Signed-off-by: Dick Kennedy 
Signed-off-by: James Smart 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/lpfc/lpfc_nportdisc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c 
b/drivers/scsi/lpfc/lpfc_nportdisc.c
index f74cb0142fd4..95b2b43ac37d 100644
--- a/drivers/scsi/lpfc/lpfc_nportdisc.c
+++ b/drivers/scsi/lpfc/lpfc_nportdisc.c
@@ -1724,6 +1724,9 @@ lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport 
*vport,
lpfc_nvme_update_localport(vport);
}
 
+   } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
+   ndlp->nlp_fc4_type |= NLP_FC4_FCP;
+
} else if (ndlp->nlp_fc4_type == 0) {
rc = lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID,
 0, ndlp->nlp_DID);
-- 
2.13.1



[PATCH v3 01/20] lpfc: Fix plogi collision that causes illegal state transition

2017-08-23 Thread James Smart
From: Dick Kennedy 

Message "0271 Illegal State Transition: node" seen in logs, all
luns are unuseable for that target.

A window exists in the rcv_plogi path where if the state is plogi
issue but the driver has not issued a plogi, then two reglogins will
be sent for the same RPI. The first one to complete will advance
the state to prli issue the second one will be detected as an
illegal state, and leave the node in an unusable state.

Correct the completion routine for the PLOGI ACC that detects the
state change when the driver starts discovery on the node again
and drop the REGLOGIN mailbox command.

Signed-off-by: Dick Kennedy 
Signed-off-by: James Smart 
Reviewed-by: Johannes Thumshirn 

---
v3:
  revise if test for better indentation per review
  removed unnecessary typecast
---
 drivers/scsi/lpfc/lpfc_els.c | 20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 6d1d6f691df4..2dae501dc323 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -3930,7 +3930,25 @@ lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct 
lpfc_iocbq *cmdiocb,
if (mbox) {
if ((rspiocb->iocb.ulpStatus == 0)
&& (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
-   lpfc_unreg_rpi(vport, ndlp);
+   if (!lpfc_unreg_rpi(vport, ndlp) &&
+   (ndlp->nlp_state ==  NLP_STE_PLOGI_ISSUE ||
+ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) {
+   lpfc_printf_vlog(vport, KERN_INFO,
+   LOG_DISCOVERY,
+   "0314 PLOGI recov DID x%x "
+   "Data: x%x x%x x%x\n",
+   ndlp->nlp_DID, ndlp->nlp_state,
+   ndlp->nlp_rpi, ndlp->nlp_flag);
+   mp = mbox->context1;
+   if (mp) {
+   lpfc_mbuf_free(phba, mp->virt,
+  mp->phys);
+   kfree(mp);
+   }
+   mempool_free(mbox, phba->mbox_mem_pool);
+   goto out;
+   }
+
/* Increment reference count to ndlp to hold the
 * reference to ndlp for the callback function.
 */
-- 
2.13.1



[PATCH v3 07/20] lpfc: Fix handling of FCP and NVME FC4 types in Pt2Pt topology

2017-08-23 Thread James Smart
From: Dick Kennedy 

After link bounce in a NVME Pt2Pt config, the driver managed to
map the same nport twice, resulting in multiple device nodes for the
same namespace.

In Pt2Pt, the driver must send PRLI's for both (scsi) FCP and NVME
rather than using fabric aids. The driver was inconsistent on handling
various PRLI completions, especially rejects, which had reject codes
cross the different protocol PRLI completions.

Fixed to perform the following:
if nvmet mode (fc port can only be a nvme target) - rejects all
unsolicitly FCP PRLI's. Never issues a FCP PRLI.

The multiple protocol PRLI's are sent simultaneously. However, driver
will now only state transition after both PRLI's are complete. New
flags were added to aid tracking the responses from the different PRLI's.

Signed-off-by: Dick Kennedy 
Signed-off-by: James Smart 

---
v3:
  small change to if test for better indentation per review
---
 drivers/scsi/lpfc/lpfc_disc.h  |  1 +
 drivers/scsi/lpfc/lpfc_els.c   | 28 
 drivers/scsi/lpfc/lpfc_nportdisc.c |  9 +
 3 files changed, 38 insertions(+)

diff --git a/drivers/scsi/lpfc/lpfc_disc.h b/drivers/scsi/lpfc/lpfc_disc.h
index 094c97b9e5f7..f9a566eaef04 100644
--- a/drivers/scsi/lpfc/lpfc_disc.h
+++ b/drivers/scsi/lpfc/lpfc_disc.h
@@ -159,6 +159,7 @@ struct lpfc_node_rrq {
 #define NLP_RNID_SND   0x0400  /* sent RNID request for this entry */
 #define NLP_ELS_SND_MASK   0x07e0  /* sent ELS request for this entry */
 #define NLP_NVMET_RECOV0x1000   /* NVMET auditing node for recovery. */
+#define NLP_FCP_PRLI_RJT   0x2000   /* Rport does not support FCP PRLI. */
 #define NLP_DEFER_RM   0x0001  /* Remove this ndlp if no longer used */
 #define NLP_DELAY_TMO  0x0002  /* delay timeout is running for node */
 #define NLP_NPR_2B_DISC0x0004  /* node is included in num_disc_nodes */
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 2dae501dc323..19af0e6e7667 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -1966,6 +1966,7 @@ int
 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
 {
struct lpfc_hba  *phba = vport->phba;
+   struct Scsi_Host *shost;
struct serv_parm *sp;
struct lpfc_nodelist *ndlp;
struct lpfc_iocbq *elsiocb;
@@ -1984,6 +1985,11 @@ lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t 
did, uint8_t retry)
if (!elsiocb)
return 1;
 
+   shost = lpfc_shost_from_vport(vport);
+   spin_lock_irq(shost->host_lock);
+   ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
+   spin_unlock_irq(shost->host_lock);
+
pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
 
/* For PLOGI request, remainder of payload is service parameters */
@@ -3442,6 +3448,21 @@ lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq 
*cmdiocb,
goto out_retry;
}
break;
+   case LSRJT_CMD_UNSUPPORTED:
+   /* lpfc nvmet returns this type of LS_RJT when it
+* receives an FCP PRLI because lpfc nvmet only
+* support NVME.  ELS request is terminated for FCP4
+* on this rport.
+*/
+   if (stat.un.b.lsRjtRsnCodeExp ==
+   LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
+   spin_lock_irq(shost->host_lock);
+   ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
+   spin_unlock_irq(shost->host_lock);
+   retry = 0;
+   goto out_retry;
+   }
+   break;
}
break;
 
@@ -8007,6 +8028,13 @@ lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct 
lpfc_sli_ring *pring,
rjt_exp = LSEXP_NOTHING_MORE;
break;
}
+
+   /* NVMET accepts NVME PRLI only.  Reject FCP PRLI */
+   if (cmd == ELS_CMD_PRLI && phba->nvmet_support) {
+   rjt_err = LSRJT_CMD_UNSUPPORTED;
+   rjt_exp = LSEXP_REQ_UNSUPPORTED;
+   break;
+   }
lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
break;
case ELS_CMD_LIRR:
diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c 
b/drivers/scsi/lpfc/lpfc_nportdisc.c
index a4488d6339c1..f3ad7cac355d 100644
--- a/drivers/scsi/lpfc/lpfc_nportdisc.c
+++ b/drivers/scsi/lpfc/lpfc_nportdisc.c
@@ -1895,6 +1895,15 @@ lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, 
struct lpfc_nodelist *ndlp,
goto out;
}
 
+   /* When the rport rejected the FCP PRLI as unsupported.
+  

[PATCH v3 04/20] lpfc: Fix oops when NVME Target is discovered in a nonNVME environment

2017-08-23 Thread James Smart
From: Dick Kennedy 

lpfc oops when it discovers a NVME target but is configured for SCSI
only operation. Oops is in lpfc_nvme_register_port+0x33/0x300.

The localport is not valid so it should not have been referenced.

Added validity check for localport

Signed-off-by: Dick Kennedy 
Signed-off-by: James Smart 
---
 drivers/scsi/lpfc/lpfc_nvme.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/scsi/lpfc/lpfc_nvme.c b/drivers/scsi/lpfc/lpfc_nvme.c
index c18db8707fed..ce8d6bbf8148 100644
--- a/drivers/scsi/lpfc/lpfc_nvme.c
+++ b/drivers/scsi/lpfc/lpfc_nvme.c
@@ -2296,6 +2296,9 @@ lpfc_nvme_register_port(struct lpfc_vport *vport, struct 
lpfc_nodelist *ndlp)
 ndlp->nlp_DID, ndlp->nlp_type);
 
localport = vport->localport;
+   if (!localport)
+   return 0;
+
lport = (struct lpfc_nvme_lport *)localport->private;
 
/* NVME rports are not preserved across devloss.
-- 
2.13.1



[PATCH v3 16/20] lpfc: Fix bad sgl reposting after 2nd adapter reset

2017-08-23 Thread James Smart
From: Dick Kennedy 

Fix bad sgl reposting after 2nd adapter reset

port issue was fixed, the hbacmd reset would take
more than 8 minutes to complete.

There were conflicting NVME SGL posting/reposting responsibilities
between lpfc_online()/lpfc_sli4_hba_setup() and
lpfc_nvme_create_localport().  The lpfc_online() causes a REPOST
on existing NVME SGLs which is not released during the fc port reset.
However, lpfc_nvme_create_localport() wants to allocate new NVME
buffers and post them. Both cancelled out each other which had a side
effect of hosing the mailbox handling that was used to remove the sgl
lists - causing multiple 60s mbx timeouts.

Fix by preserving all SGL lists over the fc port reset.

Signed-off-by: Dick Kennedy 
Signed-off-by: James Smart 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/lpfc/lpfc_nvme.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_nvme.c b/drivers/scsi/lpfc/lpfc_nvme.c
index 24dc69de6023..bb9ede2521b9 100644
--- a/drivers/scsi/lpfc/lpfc_nvme.c
+++ b/drivers/scsi/lpfc/lpfc_nvme.c
@@ -2181,8 +2181,15 @@ lpfc_nvme_create_localport(struct lpfc_vport *vport)
vport->localport = localport;
lport->vport = vport;
vport->nvmei_support = 1;
-   len  = lpfc_new_nvme_buf(vport, phba->sli4_hba.nvme_xri_max);
-   vport->phba->total_nvme_bufs += len;
+
+   /* Don't post more new bufs if repost already recovered
+* the nvme sgls.
+*/
+   if (phba->sli4_hba.nvme_xri_cnt == 0) {
+   len  = lpfc_new_nvme_buf(vport,
+phba->sli4_hba.nvme_xri_max);
+   vport->phba->total_nvme_bufs += len;
+   }
}
 
return ret;
-- 
2.13.1



[PATCH v3 10/20] lpfc: Fix NVME PRLI handling during RSCN

2017-08-23 Thread James Smart
From: Dick Kennedy 

A race condition was found whereby the initiator would receive
the RSCN for a new NVME device before it had a chance to register
its FC4 support with the fabric. Thus, when queried by the initiator,
it would see that the target supported FC-NVME.

Corrected by making the assumption that the target always supports
FC-NVME thus a PRLI is sent. It's ok for the target to reject it.

Signed-off-by: Dick Kennedy 
Signed-off-by: James Smart 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/lpfc/lpfc_els.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index ffbd3eddeabb..6de470e158ef 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -2177,6 +2177,16 @@ lpfc_issue_els_prli(struct lpfc_vport *vport, struct 
lpfc_nodelist *ndlp,
uint16_t cmdsize;
u32 local_nlp_type, elscmd;
 
+   /*
+* If we are in RSCN mode, the FC4 types supported from a
+* previous GFT_ID command may not be accurate. So, if we
+* are a NVME Initiator, always look for the possibility of
+* the remote NPort beng a NVME Target.
+*/
+   if (phba->sli_rev == LPFC_SLI_REV4 &&
+   vport->fc_flag & FC_RSCN_MODE &&
+   vport->nvmei_support)
+   ndlp->nlp_fc4_type |= NLP_FC4_NVME;
local_nlp_type = ndlp->nlp_fc4_type;
 
  send_next_prli:
-- 
2.13.1



[PATCH v3 11/20] lpfc: Correct issues with FAWWN and FDISCs

2017-08-23 Thread James Smart
From: Dick Kennedy 

When using fabric-assigned WWNs, the switch doesn't like copy of
the FLOGI payload, which includes valid VVL bits, to be used as
the FDISC paylaod.

Rather than wait for corrected switch firmware, ensure the VVL bits
are marked invalid on FDISCs.

Signed-off-by: Dick Kennedy 
Signed-off-by: James Smart 
---
 drivers/scsi/lpfc/lpfc_els.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 6de470e158ef..8d8fbfab0c9f 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -8860,6 +8860,7 @@ lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct 
lpfc_nodelist *ndlp,
pcmd += sizeof(uint32_t); /* Node Name */
pcmd += sizeof(uint32_t); /* Node Name */
memcpy(pcmd, &vport->fc_nodename, 8);
+   sp->cmn.valid_vendor_ver_level = 0;
memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
lpfc_set_disctmo(vport);
 
-- 
2.13.1



[PATCH v3 09/20] lpfc: Fix crash in lpfc nvmet when fc port is reset

2017-08-23 Thread James Smart
From: Dick Kennedy 

in adapter reset tests, an oops was seen with a NULL pointer in
lpfc_free_rq_buffer+0x20/0x60

The driver is failing to properly repost the nvmet sgl list when
recovering from the reset. Thus the driver eventually trys to
walk an errant buffer list.

Corrected the sgl buffer recovery as well as strengthening the
initialization of the bufferlist.

Signed-off-by: Dick Kennedy 
Signed-off-by: James Smart 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/lpfc/lpfc_init.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 9294c89c7ccd..f82618a8918f 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -3226,6 +3226,13 @@ lpfc_offline(struct lpfc_hba *phba)
 
/* stop port and all timers associated with this hba */
lpfc_stop_port(phba);
+
+   /* Tear down the local and target port registrations.  The
+* nvme transports need to cleanup.
+*/
+   lpfc_nvmet_destroy_targetport(phba);
+   lpfc_nvme_destroy_localport(phba->pport);
+
vports = lpfc_create_vport_work_array(phba);
if (vports != NULL)
for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
@@ -6516,6 +6523,12 @@ lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
kfree(sglq_entry);
}
+
+   /* Update the nvmet_xri_cnt to reflect no current sgls.
+* The next initialization cycle sets the count and allocates
+* the sgls over again.
+*/
+   phba->sli4_hba.nvmet_xri_cnt = 0;
 }
 
 /**
@@ -8301,6 +8314,9 @@ lpfc_sli4_queue_create(struct lpfc_hba *phba)
goto out_error;
}
 
+   /* Put list in known state in case driver load fails. */
+   INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
+
/* Create NVMET Receive Queue for data */
qdesc = lpfc_sli4_queue_alloc(phba,
  phba->sli4_hba.rq_esize,
-- 
2.13.1



[PATCH v3 08/20] lpfc: Fix duplicate NVME rport entries and namespaces.

2017-08-23 Thread James Smart
From: Dick Kennedy 

After lip, the driver sometimes would have two rports for the same
device, allowing the namespaces to be duplicated by nvme.

In lpfc_plogi_confirm_nport() the driver was not swapping the
nrport maintained by the ndlp's undergoing address swapping. This
allowed the 2nd rport to sneak in as it was considered a separate
device.

This patch adds the fixes to Swap the nrport in each ndlp and take
care of the reference counts on the ndlps similar to FCP rports.

Signed-off-by: Dick Kennedy 
Signed-off-by: James Smart 
Reviewed-by: Johannes Thumshirn 

---
v3:
  revise comment to clarify per review
---
 drivers/scsi/lpfc/lpfc_els.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 19af0e6e7667..ffbd3eddeabb 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -1527,6 +1527,7 @@ lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t 
*prsp,
uint8_t  name[sizeof(struct lpfc_name)];
uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
uint16_t keep_nlp_state;
+   struct lpfc_nvme_rport *keep_nrport = NULL;
int  put_node;
int  put_rport;
unsigned long *active_rrqs_xri_bitmap = NULL;
@@ -1624,6 +1625,10 @@ lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t 
*prsp,
keep_nlp_state = new_ndlp->nlp_state;
lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
 
+   /* interchange the nvme remoteport structs */
+   keep_nrport = new_ndlp->nrport;
+   new_ndlp->nrport = ndlp->nrport;
+
/* Move this back to NPR state */
if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
/* The new_ndlp is replacing ndlp totally, so we need
@@ -1646,6 +1651,13 @@ lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t 
*prsp,
}
new_ndlp->nlp_type = ndlp->nlp_type;
}
+
+   /* Fix up the nvme rport */
+   if (ndlp->nrport) {
+   ndlp->nrport = NULL;
+   lpfc_nlp_put(ndlp);
+   }
+
/* We shall actually free the ndlp with both nlp_DID and
 * nlp_portname fields equals 0 to avoid any ndlp on the
 * nodelist never to be used.
@@ -1690,6 +1702,14 @@ lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t 
*prsp,
keep_nlp_state = NLP_STE_NPR_NODE;
lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
 
+   /* Previous ndlp no longer active with nvme host transport.
+* Remove reference from earlier registration unless the
+* nvme host took care of it.
+*/
+   if (ndlp->nrport)
+   lpfc_nlp_put(ndlp);
+   ndlp->nrport = keep_nrport;
+
/* Fix up the rport accordingly */
rport = ndlp->rport;
if (rport) {
-- 
2.13.1



  1   2   >