Re:'Funds AED35,623,785 (US$9.7 Milliön) for you, Write to e-mail: sarah.shuh...@activist.com for dètails.

2017-07-19 Thread Janette Borg



Re: [PATCH] SCSI: remove DRIVER_ATTR() usage

2017-07-19 Thread Bart Van Assche
On Wed, 2017-07-19 at 14:50 +0200, Greg KH wrote:
> From: Greg Kroah-Hartman 
> 
> It's better to use the DRIVER_ATTR_RW() and DRIVER_ATTR_RO() macros to
> explicitly show that this is a read/write or read/only sysfs file.  So
> convert the remaining SCSI drivers that use the old style to use the
> newer macros.
> 
> Bonus is that this removes some checkpatch.pl warnings :)

Reviewed-by: Bart Van Assche 

Re: [PATCH] scsi: mpt3sas_scsih: remove unnecessary statics

2017-07-19 Thread James Bottomley
On Wed, 2017-07-19 at 17:06 -0500, Gustavo A. R. Silva wrote:
> Remove unnecessary static on local variables raid_device.
> Such variables are initialized before being used, on
> every execution path throughout the functions. The
> static has no benefit and, removing it reduces the
> object file size.
> 
> This issue was detected using Coccinelle and the following semantic
> patch:
> 
> @bad exists@
> position p;
> identifier x;
> type T;
> @@
> 
> static T x@p;
> ...
> x = <+...x...+>
> 
> @@
> identifier x;
> expression e;
> type T;
> position p != bad.p;
> @@
> 
> -static
>  T x@p;
>  ... when != x
>  when strict
> ?x = e;
> 
> In the following log you can see a significant difference in the
> object file size. This log is the output of the size command, before
> and after the code change:
> 
> before:
>    textdata bss dec hex filename
>  126304   303841280  157968   26910
> drivers/scsi/mpt3sas/mpt3sas_scsih.o
> 
> after:
>    textdata bss dec hex filename
>  126292   302401152  157684   267f4
> drivers/scsi/mpt3sas/mpt3sas_scsih.o

I've got to say I'm deeply uneasy about using a data/bss size reduction
as the benchmark for saying something shouldn't be declared static.  In
this particular case the reduction is minimal, so it probably doesn't
matter; however, if the reduction were more significant, changing from
static to dynamic (i.e. on stack) allocation would increase the risk
that we'd blow the kernel stack.  Indeed one reason you might find
static declarations in functions is precisely to avoid blowing the
stack, so we wouldn't want to reverse them.

Other reasons for having static allocations instead of dynamic ones is
that you need to DMA to/from the structure (you can't DMA to stack) or
because you want to preserve values across function invocations.

There are definite reasons why statics in functions are a bad idea:
they prevent recursion and trip up code analysis, but in none of the
above cases would the fix be to remove the static qualifier.

James



[PATCH] scsi: Add helper functions to set target ID

2017-07-19 Thread Raghava Aditya Renukunta
This patch adds 3 helper functions to set the initial target id, expander
id and port id numbers.

The ARC/HBA1000 product line  exposes RAID drives on bus number 0 and
sas transport HBA drives use bus 0 as well. We wanted to differentiate
between the RAID and HBA targets when the adapter in mixed mode (both RAID
and HBA are exposed). Since the number of RAID drives we support is
limited to 64 we wanted to block the first 64 targets and then add the
sas enabled HBA drives from target id 64.

Unfortunately the current sas transport implementation does not allow
changing of the next_target_id value (used by rphy to add drives), since
it is not exposed directly to the driver.

One way around this is to add helper functions to explicitly set the
next_target_id and others.

I still have to submit the sas transport aacraid support patches, but
I wanted to send this out to get comments and any other changes if
required.

Signed-off-by: Raghava Aditya Renukunta 
---
 0 files changed

diff --git a/drivers/scsi/scsi_transport_sas.c 
b/drivers/scsi/scsi_transport_sas.c
index 5006a656e16a..a6ef5520cb66 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -294,6 +294,31 @@ static void sas_bsg_remove(struct Scsi_Host *shost, struct 
sas_rphy *rphy)
bsg_unregister_queue(q);
 }
 
+void sas_set_initial_target_id(struct Scsi_Host *shost, u32 target_id)
+{
+   struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
+
+   sas_host->next_target_id = target_id;
+}
+EXPORT_SYMBOL(sas_set_initial_target_id);
+
+void sas_set_initial_expander_id(struct Scsi_Host *shost, u32 expander_id)
+{
+   struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
+
+   sas_host->next_expander_id = expander_id;
+}
+EXPORT_SYMBOL(sas_set_initial_expander_id);
+
+void sas_set_initial_port_id(struct Scsi_Host *shost, u32 port_id)
+{
+   struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
+
+   sas_host->next_port_id = port_id;
+}
+EXPORT_SYMBOL(sas_set_initial_port_id);
+
+
 /*
  * SAS host attributes
  */
diff --git a/include/scsi/scsi_transport_sas.h 
b/include/scsi/scsi_transport_sas.h
index 73d870918939..6917eee7bc24 100644
--- a/include/scsi/scsi_transport_sas.h
+++ b/include/scsi/scsi_transport_sas.h
@@ -179,6 +179,9 @@ struct sas_function_template {
int (*smp_handler)(struct Scsi_Host *, struct sas_rphy *, struct 
request *);
 };
 
+void sas_set_initial_target_id(struct Scsi_Host *shost, u32 target_id);
+void sas_set_initial_expander_id(struct Scsi_Host *shost, u32 expander_id);
+void sas_set_initial_port_id(struct Scsi_Host *shost, u32 port_id);
 
 void sas_remove_children(struct device *);
 extern void sas_remove_host(struct Scsi_Host *);



[PATCH] scsi: mpt3sas_scsih: remove unnecessary statics

2017-07-19 Thread Gustavo A. R. Silva
Remove unnecessary static on local variables raid_device.
Such variables are initialized before being used, on
every execution path throughout the functions. The
static has no benefit and, removing it reduces the
object file size.

This issue was detected using Coccinelle and the following semantic patch:

@bad exists@
position p;
identifier x;
type T;
@@

static T x@p;
...
x = <+...x...+>

@@
identifier x;
expression e;
type T;
position p != bad.p;
@@

-static
 T x@p;
 ... when != x
 when strict
?x = e;

In the following log you can see a significant difference in the object
file size. This log is the output of the size command, before and after
the code change:

before:
   textdata bss dec hex filename
 126304   303841280  157968   26910 drivers/scsi/mpt3sas/mpt3sas_scsih.o

after:
   textdata bss dec hex filename
 126292   302401152  157684   267f4 drivers/scsi/mpt3sas/mpt3sas_scsih.o

Signed-off-by: Gustavo A. R. Silva 
---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c 
b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 22998cb..417e5d1 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -1571,7 +1571,7 @@ scsih_get_resync(struct device *dev)
 {
struct scsi_device *sdev = to_scsi_device(dev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
-   static struct _raid_device *raid_device;
+   struct _raid_device *raid_device;
unsigned long flags;
Mpi2RaidVolPage0_t vol_pg0;
Mpi2ConfigReply_t mpi_reply;
@@ -1632,7 +1632,7 @@ scsih_get_state(struct device *dev)
 {
struct scsi_device *sdev = to_scsi_device(dev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
-   static struct _raid_device *raid_device;
+   struct _raid_device *raid_device;
unsigned long flags;
Mpi2RaidVolPage0_t vol_pg0;
Mpi2ConfigReply_t mpi_reply;
@@ -7027,7 +7027,7 @@ _scsih_sas_ir_operation_status_event(struct 
MPT3SAS_ADAPTER *ioc,
Mpi2EventDataIrOperationStatus_t *event_data =
(Mpi2EventDataIrOperationStatus_t *)
fw_event->event_data;
-   static struct _raid_device *raid_device;
+   struct _raid_device *raid_device;
unsigned long flags;
u16 handle;
 
@@ -7531,7 +7531,7 @@ _scsih_scan_for_devices_after_reset(struct 
MPT3SAS_ADAPTER *ioc)
u64 sas_address;
struct _sas_device *sas_device;
struct _sas_node *expander_device;
-   static struct _raid_device *raid_device;
+   struct _raid_device *raid_device;
u8 retry_count;
unsigned long flags;
 
-- 
2.5.0



Re: [PATCH 1/7] qla2xxx: Cleanup NVMe code.

2017-07-19 Thread Madhani, Himanshu
Hi Bart, 

> On Jul 19, 2017, at 1:44 PM, Bart Van Assche  wrote:
> 
> On Wed, 2017-07-19 at 11:51 -0700, Himanshu Madhani wrote:
>> This patch cleaned up code to make it more readable
> 
> Hello Himanshu,
> 
> "cleaned up code" is a very vague description. Please be more specific and
> please also mention in the patch description what functionality has been
> changed (if any).
> 
> Bart.

There is no functionality change in this patch, it addresses comments to make 
code readable. 

for example, 

Changing waitQ -> wait.
Combined multiple debug statements into single 
Drop extra parenthesis in if() statements

I’ll add this into commit message for more clarity.

Thanks,
- Himanshu



Re: [PATCH 3/7] qla2xxx: Add command completion wq for error path

2017-07-19 Thread Bart Van Assche
On Wed, 2017-07-19 at 11:51 -0700, Himanshu Madhani wrote:
> From: Duane Grigsby 

Hello Himanshu and Duane,

Too many drivers create workqueues for all kinds of purposes. Why is it
necessary to execute qla_nvme_io_work() on the context of a new workqueue?
If any of the existing system workqueues can be used please modify the patch
accordingly. Otherwise please explain why it is necessary to introduce a new
workqueue.

Bart.

Re: [PATCH 1/7] qla2xxx: Cleanup NVMe code.

2017-07-19 Thread Bart Van Assche
On Wed, 2017-07-19 at 11:51 -0700, Himanshu Madhani wrote:
> This patch cleaned up code to make it more readable

Hello Himanshu,

"cleaned up code" is a very vague description. Please be more specific and
please also mention in the patch description what functionality has been
changed (if any).

Bart.

[PATCH 4/7] qla2xxx: Added change to enable ZIO for FC-NVMe devices

2017-07-19 Thread Himanshu Madhani
From: Duane Grigsby 

Add support to the driver to set the exchange threshold value for
the number of outstanding AENs.

Signed-off-by: Duane Grigsby 
Signed-off-by: Darren Trapp 
Signed-off-by: Anil Gurumurthy 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_dbg.c  |  2 +-
 drivers/scsi/qla2xxx/qla_def.h  |  5 +++
 drivers/scsi/qla2xxx/qla_gbl.h  |  3 ++
 drivers/scsi/qla2xxx/qla_isr.c  |  2 +-
 drivers/scsi/qla2xxx/qla_mbx.c  | 76 ++---
 drivers/scsi/qla2xxx/qla_nvme.c | 14 ++--
 drivers/scsi/qla2xxx/qla_os.c   | 26 +++---
 7 files changed, 105 insertions(+), 23 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_dbg.c b/drivers/scsi/qla2xxx/qla_dbg.c
index 26751d34bcf2..7b74973d5788 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.c
+++ b/drivers/scsi/qla2xxx/qla_dbg.c
@@ -14,7 +14,7 @@
  * | Module Init and Probe|   0x0193   | 0x0146 |
  * |  || 0x015b-0x0160 |
  * |  || 0x016e
|
- * | Mailbox commands |   0x1199   | 0x1193
|
+ * | Mailbox commands |   0x1205   | 0x11a2-0x11ff |
  * | Device Discovery |   0x2134   | 0x210e-0x2116  |
  * | || 0x211a |
  * |  || 0x211c-0x2128  |
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 799d25564ed6..015908f99e76 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -978,6 +978,7 @@ struct mbx_cmd_32 {
 #define MBC_ABORT_TARGET   0x17/* Abort target (ID). */
 #define MBC_RESET  0x18/* Reset. */
 #define MBC_GET_ADAPTER_LOOP_ID0x20/* Get loop id of 
ISP2200. */
+#define MBC_GET_SET_ZIO_THRESHOLD  0x21/* Get/SET ZIO THRESHOLD. */
 #define MBC_GET_RETRY_COUNT0x22/* Get f/w retry cnt/delay. */
 #define MBC_DISABLE_VI 0x24/* Disable VI operation. */
 #define MBC_ENABLE_VI  0x25/* Enable VI operation. */
@@ -4018,6 +4019,9 @@ struct qla_hw_data {
 
struct qlt_hw_data tgt;
int allow_cna_fw_dump;
+
+   atomic_tnvme_active_aen_cnt;
+   uint16_tnvme_last_rptd_aen; /* Last recorded aen 
count */
 };
 
 /*
@@ -4090,6 +4094,7 @@ typedef struct scsi_qla_host {
 #define FX00_CRITEMP_RECOVERY  25
 #define FX00_HOST_INFO_RESEND  26
 #define QPAIR_ONLINE_CHECK_NEEDED  27
+#define SET_ZIO_THRESHOLD_NEEDED   28
 
unsigned long   pci_flags;
 #define PFLG_DISCONNECTED  0   /* PCI device removed */
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index 659cdf592678..67864d4492cd 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -484,6 +484,9 @@ int qla24xx_gidlist_wait(struct scsi_qla_host *, void *, 
dma_addr_t,
 int __qla24xx_parse_gpdb(struct scsi_qla_host *, fc_port_t *,
struct port_database_24xx *);
 
+extern int qla27xx_get_zio_threshold(scsi_qla_host_t *, uint16_t *);
+extern int qla27xx_set_zio_threshold(scsi_qla_host_t *, uint16_t );
+
 /*
  * Global Function Prototypes in qla_isr.c source file.
  */
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 9127eee67478..317fe6026856 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -1823,7 +1823,7 @@ qla24xx_nvme_iocb_entry(scsi_qla_host_t *vha, struct 
req_que *req, void *tsk)
nvme = >u.iocb_cmd;
 
if (unlikely(nvme->u.nvme.aen_op))
-   atomic_dec(>vha->nvme_active_aen_cnt);
+   atomic_dec(>vha->hw->nvme_active_aen_cnt);
 
/*
 * State flags: Bit 6 and 0.
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 7c6d1a404011..b271c3f78c85 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -947,20 +947,12 @@ qla2x00_get_fw_version(scsi_qla_host_t *vha)
"%s: Firmware supports Exchange Offload 0x%x\n",
__func__, ha->fw_attributes_h);
 
-   /* bit 26 of fw_attributes */
-   if ((ha->fw_attributes_h & 0x400) && ql2xnvmeenable) {
-   struct init_cb_24xx *icb;
-
-   icb = (struct init_cb_24xx *)ha->init_cb;
-   /*
-* fw supports nvme and driver load
-* parameter requested nvme
-*/
+   /*
+* fw supports nvme and driver load parameter requested nvme
+* bit 26 of fw_attributes indicates 

[PATCH 7/7] qla2xxx: Refactor usage of Active command arrays

2017-07-19 Thread Himanshu Madhani
From: Quinn Tran 

Cc: Bart Van Assche 
Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_bsg.c| 51 ---
 drivers/scsi/qla2xxx/qla_def.h| 31 +++-
 drivers/scsi/qla2xxx/qla_init.c   |  7 +++---
 drivers/scsi/qla2xxx/qla_inline.h | 23 +++---
 drivers/scsi/qla2xxx/qla_iocb.c   | 16 ++--
 drivers/scsi/qla2xxx/qla_isr.c| 31 +++-
 drivers/scsi/qla2xxx/qla_mbx.c|  6 +++--
 drivers/scsi/qla2xxx/qla_mr.c | 19 ---
 drivers/scsi/qla2xxx/qla_nvme.c   |  2 +-
 drivers/scsi/qla2xxx/qla_nx.c |  6 +++--
 drivers/scsi/qla2xxx/qla_os.c | 29 +-
 drivers/scsi/qla2xxx/qla_target.c | 18 --
 drivers/scsi/qla2xxx/qla_target.h |  5 
 13 files changed, 139 insertions(+), 105 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index 2ea0ef93f5cb..356cea400d19 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -1920,7 +1920,7 @@ qla24xx_process_bidir_cmd(struct bsg_job *bsg_job)
return rval;
 
 done_free_srb:
-   mempool_free(sp, ha->srb_mempool);
+   mempool_free(SRB_TO_U(sp), ha->srb_mempool);
 done_unmap_sg:
dma_unmap_sg(>pdev->dev,
bsg_job->reply_payload.sg_list,
@@ -2043,7 +2043,7 @@ qlafx00_mgmt_cmd(struct bsg_job *bsg_job)
if (rval != QLA_SUCCESS) {
ql_log(ql_log_warn, vha, 0x70cd,
"qla2x00_start_sp failed=%d.\n", rval);
-   mempool_free(sp, ha->srb_mempool);
+   mempool_free(SRB_TO_U(sp), ha->srb_mempool);
rval = -EIO;
goto done_free_fcport;
}
@@ -2533,6 +2533,7 @@ qla24xx_bsg_timeout(struct bsg_job *bsg_job)
int cnt, que;
unsigned long flags;
struct req_que *req;
+   struct unify_cmd *u;
 
/* find the bsg job from the active list of commands */
spin_lock_irqsave(>hardware_lock, flags);
@@ -2542,30 +2543,30 @@ qla24xx_bsg_timeout(struct bsg_job *bsg_job)
continue;
 
for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
-   sp = req->outstanding_cmds[cnt];
-   if (sp) {
-   if (((sp->type == SRB_CT_CMD) ||
-   (sp->type == SRB_ELS_CMD_HST) ||
-   (sp->type == SRB_FXIOCB_BCMD))
-   && (sp->u.bsg_job == bsg_job)) {
-   req->outstanding_cmds[cnt] = NULL;
-   
spin_unlock_irqrestore(>hardware_lock, flags);
-   if (ha->isp_ops->abort_command(sp)) {
-   ql_log(ql_log_warn, vha, 0x7089,
-   "mbx abort_command "
-   "failed.\n");
-   scsi_req(bsg_job->req)->result =
-   bsg_reply->result = -EIO;
-   } else {
-   ql_dbg(ql_dbg_user, vha, 0x708a,
-   "mbx abort_command "
-   "success.\n");
-   scsi_req(bsg_job->req)->result =
-   bsg_reply->result = 0;
-   }
-   spin_lock_irqsave(>hardware_lock, 
flags);
-   goto done;
+   u = req->outstanding_cmds[cnt];
+   if (!u || u->cmd_type != TYPE_SRB)
+   continue;
+
+   sp = >srb;
+   if (((sp->type == SRB_CT_CMD) ||
+   (sp->type == SRB_ELS_CMD_HST) ||
+   (sp->type == SRB_FXIOCB_BCMD))
+   && (sp->u.bsg_job == bsg_job)) {
+   req->outstanding_cmds[cnt] = NULL;
+   spin_unlock_irqrestore(>hardware_lock, 
flags);
+   if (ha->isp_ops->abort_command(sp)) {
+   ql_log(ql_log_warn, vha, 0x7089,
+   "mbx abort_command failed.\n");
+   scsi_req(bsg_job->req)->result =
+   bsg_reply->result = -EIO;
+   } else {
+   ql_dbg(ql_dbg_user, vha, 0x708a,
+   

[PATCH 0/7] qla2xxx: Bug fixes for driver

2017-07-19 Thread Himanshu Madhani
Hi Martin, 

This series addresses review comments for previously submitted series for
Target MQ and FC-NVMe support.

Patch 1, 2 addresses review comments by Johannes for FC-NVMe series 
(https://www.spinics.net/lists/linux-scsi/msg110077.html)
(https://www.spinics.net/lists/linux-scsi/msg109985.html)

Patch 3 adds completion wq for FC-NVMe error path.

Patch 4 adds ZIO support for FC-NVMe.

Patch 5 simplifies waiting for unregistration of local/remote FC-NVMe ports.

Patch 6 fixes handling of remote-port disconnect for FC-NVMe.

Patch 7 address review comments by Bart for Target Multi-queue. 
(https://www.spinics.net/lists/target-devel/msg15563.html)

Please apply these patches to scsi-fixes for inclusion in 4.13.0-rc2. 

Thanks,
Himanshu

Duane Grigsby (2):
  qla2xxx: Add command completion wq for error path
  qla2xxx: Added change to enable ZIO for FC-NVMe devices

Himanshu Madhani (4):
  qla2xxx: Cleanup NVMe code.
  qla2xxx: Move function prototype to correct header
  qla2xxx: Simpify unregistration of FC-NVMe local/remote ports
  qla2xxx: Fix remoteport disconnect for FC-NVMe

Quinn Tran (1):
  qla2xxx: Refactor usage of Active command arrays

 drivers/scsi/qla2xxx/qla_bsg.c|  51 ++--
 drivers/scsi/qla2xxx/qla_dbg.c|   2 +-
 drivers/scsi/qla2xxx/qla_def.h|  45 +++
 drivers/scsi/qla2xxx/qla_gbl.h|  14 +---
 drivers/scsi/qla2xxx/qla_init.c   |   7 +-
 drivers/scsi/qla2xxx/qla_inline.h |  23 +++---
 drivers/scsi/qla2xxx/qla_iocb.c   |  16 ++--
 drivers/scsi/qla2xxx/qla_isr.c|  74 -
 drivers/scsi/qla2xxx/qla_mbx.c|  82 +++
 drivers/scsi/qla2xxx/qla_mr.c |  19 ++---
 drivers/scsi/qla2xxx/qla_nvme.c   | 162 +-
 drivers/scsi/qla2xxx/qla_nvme.h   |  17 
 drivers/scsi/qla2xxx/qla_nx.c |   6 +-
 drivers/scsi/qla2xxx/qla_os.c |  69 +++-
 drivers/scsi/qla2xxx/qla_target.c |  18 +++--
 drivers/scsi/qla2xxx/qla_target.h |   5 --
 16 files changed, 371 insertions(+), 239 deletions(-)

-- 
2.12.0



[PATCH 2/7] qla2xxx: Move function prototype to correct header

2017-07-19 Thread Himanshu Madhani
Cc: Johannes Thumshirn 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_gbl.h  | 11 ---
 drivers/scsi/qla2xxx/qla_isr.c  |  4 ++--
 drivers/scsi/qla2xxx/qla_nvme.c |  9 -
 drivers/scsi/qla2xxx/qla_nvme.h | 17 +
 4 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index cadb6e3baacc..659cdf592678 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -10,17 +10,6 @@
 #include 
 
 /*
- * Global functions prototype in qla_nvme.c source file.
- */
-extern void qla_nvme_register_hba(scsi_qla_host_t *);
-extern int  qla_nvme_register_remote(scsi_qla_host_t *, fc_port_t *);
-extern void qla_nvme_delete(scsi_qla_host_t *);
-extern void qla_nvme_abort(struct qla_hw_data *, srb_t *sp);
-extern void qla24xx_nvme_ls4_iocb(scsi_qla_host_t *, struct pt_ls4_request *,
-struct req_que *);
-extern void qla24xx_async_gffid_sp_done(void *, int);
-
-/*
  * Global Function Prototypes in qla_init.c source file.
  */
 extern int qla2x00_initialize_adapter(scsi_qla_host_t *);
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 7b3b702ef622..9127eee67478 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -2827,8 +2827,8 @@ qla24xx_abort_iocb_entry(scsi_qla_host_t *vha, struct 
req_que *req,
sp->done(sp, 0);
 }
 
-void qla24xx_nvme_ls4_iocb(scsi_qla_host_t *vha, struct pt_ls4_request *pkt,
-struct req_que *req)
+void qla24xx_nvme_ls4_iocb(struct scsi_qla_host *vha,
+struct pt_ls4_request *pkt, struct req_que *req)
 {
srb_t *sp;
const char func[] = "LS4_IOCB";
diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
index 3c58d1b71e6e..11494f2f90b5 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -5,7 +5,6 @@
  * See LICENSE.qla2xxx for copyright and licensing details.
  */
 #include "qla_nvme.h"
-#include "qla_def.h"
 #include 
 #include 
 #include 
@@ -15,7 +14,7 @@ static struct nvme_fc_port_template qla_nvme_fc_transport;
 
 static void qla_nvme_unregister_remote_port(struct work_struct *);
 
-int qla_nvme_register_remote(scsi_qla_host_t *vha, fc_port_t *fcport)
+int qla_nvme_register_remote(struct scsi_qla_host *vha, struct fc_port *fcport)
 {
struct nvme_rport *rport;
int ret;
@@ -616,7 +615,7 @@ static int qla_nvme_wait_on_rport_del(fc_port_t *fcport)
return ret;
 }
 
-void qla_nvme_abort(struct qla_hw_data *ha, srb_t *sp)
+void qla_nvme_abort(struct qla_hw_data *ha, struct srb *sp)
 {
int rval;
 
@@ -679,7 +678,7 @@ static void qla_nvme_unregister_remote_port(struct 
work_struct *work)
}
 }
 
-void qla_nvme_delete(scsi_qla_host_t *vha)
+void qla_nvme_delete(struct scsi_qla_host *vha)
 {
struct nvme_rport *rport, *trport;
fc_port_t *fcport;
@@ -711,7 +710,7 @@ void qla_nvme_delete(scsi_qla_host_t *vha)
}
 }
 
-void qla_nvme_register_hba(scsi_qla_host_t *vha)
+void qla_nvme_register_hba(struct scsi_qla_host *vha)
 {
struct nvme_fc_port_template *tmpl;
struct qla_hw_data *ha;
diff --git a/drivers/scsi/qla2xxx/qla_nvme.h b/drivers/scsi/qla2xxx/qla_nvme.h
index dfe56f207b28..7f05fa1c77db 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.h
+++ b/drivers/scsi/qla2xxx/qla_nvme.h
@@ -12,12 +12,18 @@
 #include 
 #include 
 
+#include "qla_def.h"
+
 #define NVME_ATIO_CMD_OFF 32
 #define NVME_FIRST_PACKET_CMDLEN (64 - NVME_ATIO_CMD_OFF)
 #define Q2T_NVME_NUM_TAGS 2048
 #define QLA_MAX_FC_SEGMENTS 64
 
+struct scsi_qla_host;
+struct qla_hw_data;
+struct req_que;
 struct srb;
+
 struct nvme_private {
struct srb  *sp;
struct nvmefc_ls_req *fd;
@@ -129,4 +135,15 @@ struct pt_ls4_rx_unsol {
uint32_t desc_len;
uint32_t payload[3];
 };
+
+/*
+ * Global functions prototype in qla_nvme.c source file.
+ */
+void qla_nvme_register_hba(struct scsi_qla_host *);
+int  qla_nvme_register_remote(struct scsi_qla_host *, struct fc_port *);
+void qla_nvme_delete(struct scsi_qla_host *);
+void qla_nvme_abort(struct qla_hw_data *, struct srb *sp);
+void qla24xx_nvme_ls4_iocb(struct scsi_qla_host *, struct pt_ls4_request *,
+struct req_que *);
+void qla24xx_async_gffid_sp_done(void *, int);
 #endif
-- 
2.12.0



[PATCH 3/7] qla2xxx: Add command completion wq for error path

2017-07-19 Thread Himanshu Madhani
From: Duane Grigsby 

When NVMe commands encounter error NVMe FC transport needs to
teardown the connection. This patch adds worker thread to process
these IO errors.

Signed-off-by: Duane Grigsby 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h  |  2 ++
 drivers/scsi/qla2xxx/qla_nvme.c | 20 +++-
 drivers/scsi/qla2xxx/qla_os.c   | 10 +-
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 1635e98867aa..799d25564ed6 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -430,6 +430,7 @@ struct srb_iocb {
} nvme;
} u;
 
+   struct work_struct rq_work;
struct timer_list timer;
void (*timeout)(void *);
 };
@@ -4132,6 +4133,7 @@ typedef struct scsi_qla_host {
atomic_tnvme_ref_count;
wait_queue_head_t nvme_waitq;
struct list_head nvme_rport_list;
+   struct workqueue_struct *nvme_io_wq;
atomic_tnvme_active_aen_cnt;
uint16_tnvme_last_rptd_aen;
 
diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
index 11494f2f90b5..7543f533edfb 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -156,6 +156,17 @@ static void qla_nvme_sp_ls_done(void *ptr, int res)
qla2x00_rel_sp(sp);
 }
 
+static void qla_nvme_io_work(struct work_struct *work)
+{
+   srb_t *sp;
+   struct srb_iocb *nvme = container_of(work, struct srb_iocb, rq_work);
+   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;
@@ -177,7 +188,13 @@ 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);
+   if (res == QLA_FUNCTION_FAILED) {
+   INIT_WORK(>rq_work, qla_nvme_io_work);
+   queue_work(sp->fcport->vha->nvme_io_wq, >rq_work);
+   return;
+   } else {
+   fd->done(fd);
+   }
 rel:
qla2xxx_rel_qpair_sp(sp->qpair, sp);
 }
@@ -514,6 +531,7 @@ static int qla_nvme_post_cmd(struct nvme_fc_local_port 
*lport,
sp->done = qla_nvme_sp_done;
sp->qpair = qpair;
nvme = >u.iocb_cmd;
+   INIT_WORK(>rq_work, qla_nvme_io_work);
nvme->u.nvme.desc = fd;
 
rval = qla2x00_start_nvme_mq(sp);
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 635ce75c630b..3329512b4b35 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -2751,7 +2751,6 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct 
pci_device_id *id)
spin_lock_init(>tgt.sess_lock);
spin_lock_init(>tgt.atio_lock);
 
-
/* Clear our data area */
ha->bars = bars;
ha->mem_only = mem_only;
@@ -3286,6 +3285,13 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct 
pci_device_id *id)
base_vha->flags.init_done = 1;
base_vha->flags.online = 1;
ha->prev_minidump_failed = 0;
+   atomic_set(_vha->nvme_active_aen_cnt, 0);
+   base_vha->nvme_io_wq = alloc_workqueue("qlnvme-io-wq", 0, 0);
+   if (!base_vha->nvme_io_wq) {
+   ql_log(ql_log_fatal, base_vha, 0x000b,
+   "Unable to allocate workqueue for nvme_io_wq\n");
+   goto disable_device;
+   }
 
ql_dbg(ql_dbg_init, base_vha, 0x00f2,
"Init done and hba is online.\n");
@@ -3559,6 +3565,8 @@ qla2x00_remove_one(struct pci_dev *pdev)
set_bit(UNLOADING, _vha->dpc_flags);
 
qla_nvme_delete(base_vha);
+   if (base_vha->nvme_io_wq)
+   destroy_workqueue(base_vha->nvme_io_wq);
 
dma_free_coherent(>pdev->dev,
base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
-- 
2.12.0



[PATCH 5/7] qla2xxx: Simpify unregistration of FC-NVMe local/remote ports

2017-07-19 Thread Himanshu Madhani
Simplified waiting for unregister local/remote FC-NVMe ports
to complete cleanup.

Signed-off-by: Duane Grigsby 
Signed-off-by: Darren Trapp 
Signed-off-by: Anil Gurumurthy 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h  |  5 ++--
 drivers/scsi/qla2xxx/qla_nvme.c | 59 +++--
 2 files changed, 12 insertions(+), 52 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 015908f99e76..caee4a2b4002 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -2304,7 +2304,7 @@ typedef struct fc_port {
 
struct work_struct nvme_del_work;
atomic_t nvme_ref_count;
-   wait_queue_head_t nvme_waitq;
+   struct completion nvme_del_done;
uint32_t nvme_prli_service_param;
 #define NVME_PRLI_SP_CONF   BIT_7
 #define NVME_PRLI_SP_INITIATOR  BIT_5
@@ -4135,8 +4135,7 @@ typedef struct scsi_qla_host {
uint8_t fabric_node_name[WWN_SIZE];
 
struct  nvme_fc_local_port *nvme_local_port;
-   atomic_tnvme_ref_count;
-   wait_queue_head_t nvme_waitq;
+   struct completion nvme_del_done;
struct list_head nvme_rport_list;
struct workqueue_struct *nvme_io_wq;
atomic_tnvme_active_aen_cnt;
diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
index 4cb5bd20065a..ccafcdb228e8 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -75,8 +75,6 @@ int qla_nvme_register_remote(struct scsi_qla_host *vha, 
struct fc_port *fcport)
 
fcport->nvme_remote_port->private = fcport;
fcport->nvme_flag |= NVME_FLAG_REGISTERED;
-   atomic_set(>nvme_ref_count, 1);
-   init_waitqueue_head(>nvme_waitq);
rport->fcport = fcport;
list_add_tail(>list, >nvme_rport_list);
return 0;
@@ -250,7 +248,6 @@ static int qla_nvme_ls_req(struct nvme_fc_local_port *lport,
sp->name = "nvme_ls";
sp->done = qla_nvme_sp_ls_done;
atomic_set(>ref_count, 1);
-   init_waitqueue_head(>nvme_ls_waitq);
nvme = >u.iocb_cmd;
priv->sp = sp;
priv->fd = fd;
@@ -558,12 +555,10 @@ static void qla_nvme_localport_delete(struct 
nvme_fc_local_port *lport)
 {
struct scsi_qla_host *vha = lport->private;
 
-   atomic_dec(>nvme_ref_count);
-   wake_up_all(>nvme_waitq);
-
ql_log(ql_log_info, vha, 0x210f,
"localport delete of %p completed.\n", vha->nvme_local_port);
vha->nvme_local_port = NULL;
+   complete(>nvme_del_done);
 }
 
 static void qla_nvme_remoteport_delete(struct nvme_fc_remote_port *rport)
@@ -574,8 +569,6 @@ static void qla_nvme_remoteport_delete(struct 
nvme_fc_remote_port *rport)
fcport = rport->private;
fcport->nvme_remote_port = NULL;
fcport->nvme_flag &= ~NVME_FLAG_REGISTERED;
-   atomic_dec(>nvme_ref_count);
-   wake_up_all(>nvme_waitq);
 
list_for_each_entry_safe(r_port, trport,
>vha->nvme_rport_list, list) {
@@ -585,6 +578,7 @@ static void qla_nvme_remoteport_delete(struct 
nvme_fc_remote_port *rport)
}
}
kfree(r_port);
+   complete(>nvme_del_done);
 
ql_log(ql_log_info, fcport->vha, 0x2110,
"remoteport_delete of %p completed.\n", fcport);
@@ -627,12 +621,11 @@ static int qla_nvme_wait_on_command(srb_t *sp)
 static int qla_nvme_wait_on_rport_del(fc_port_t *fcport)
 {
int ret = QLA_SUCCESS;
+   int timeout;
 
-   wait_event_timeout(fcport->nvme_waitq,
-   atomic_read(>nvme_ref_count),
-   NVME_ABORT_POLLING_PERIOD*HZ);
-
-   if (atomic_read(>nvme_ref_count)) {
+   timeout = wait_for_completion_timeout(>nvme_del_done,
+   msecs_to_jiffies(2000));
+   if (!timeout) {
ret = QLA_FUNCTION_FAILED;
ql_log(ql_log_info, fcport->vha, 0x2111,
"timed out waiting for fcport=%p to delete\n", fcport);
@@ -651,39 +644,6 @@ void qla_nvme_abort(struct qla_hw_data *ha, struct srb *sp)
"nvme_wait_on_comand timed out waiting on sp=%p\n", sp);
 }
 
-static void qla_nvme_abort_all(fc_port_t *fcport)
-{
-   int que, cnt;
-   unsigned long flags;
-   srb_t *sp;
-   struct qla_hw_data *ha = fcport->vha->hw;
-   struct req_que *req;
-
-   spin_lock_irqsave(>hardware_lock, flags);
-   for (que = 0; que < ha->max_req_queues; que++) {
-   req = ha->req_q_map[que];
-   if (!req)
-   continue;
-   if (!req->outstanding_cmds)
-   continue;
-   for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
-   sp = req->outstanding_cmds[cnt];
-   if ((sp) && ((sp->type == SRB_NVME_CMD) ||
- 

[PATCH 1/7] qla2xxx: Cleanup NVMe code.

2017-07-19 Thread Himanshu Madhani
This patch cleaned up code to make it more readable

Cc: Johannes Thumshirn 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h  |  6 ++--
 drivers/scsi/qla2xxx/qla_nvme.c | 61 ++---
 drivers/scsi/qla2xxx/qla_os.c   |  6 ++--
 3 files changed, 33 insertions(+), 40 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 0730b10b4280..1635e98867aa 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -470,7 +470,7 @@ typedef struct srb {
uint8_t cmd_type;
uint8_t pad[3];
atomic_t ref_count;
-   wait_queue_head_t nvme_ls_waitQ;
+   wait_queue_head_t nvme_ls_waitq;
struct fc_port *fcport;
struct scsi_qla_host *vha;
uint32_t handle;
@@ -2302,7 +2302,7 @@ typedef struct fc_port {
 
struct work_struct nvme_del_work;
atomic_t nvme_ref_count;
-   wait_queue_head_t nvme_waitQ;
+   wait_queue_head_t nvme_waitq;
uint32_t nvme_prli_service_param;
 #define NVME_PRLI_SP_CONF   BIT_7
 #define NVME_PRLI_SP_INITIATOR  BIT_5
@@ -4130,7 +4130,7 @@ typedef struct scsi_qla_host {
 
struct  nvme_fc_local_port *nvme_local_port;
atomic_tnvme_ref_count;
-   wait_queue_head_t nvme_waitQ;
+   wait_queue_head_t nvme_waitq;
struct list_head nvme_rport_list;
atomic_tnvme_active_aen_cnt;
uint16_tnvme_last_rptd_aen;
diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
index f3710a75fe1f..3c58d1b71e6e 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -77,15 +77,15 @@ int qla_nvme_register_remote(scsi_qla_host_t *vha, 
fc_port_t *fcport)
fcport->nvme_remote_port->private = fcport;
fcport->nvme_flag |= NVME_FLAG_REGISTERED;
atomic_set(>nvme_ref_count, 1);
-   init_waitqueue_head(>nvme_waitQ);
+   init_waitqueue_head(>nvme_waitq);
rport->fcport = fcport;
list_add_tail(>list, >nvme_rport_list);
return 0;
 }
 
 /* Allocate a queue for NVMe traffic */
-static int qla_nvme_alloc_queue(struct nvme_fc_local_port *lport, unsigned int 
qidx,
-u16 qsize, void **handle)
+static int qla_nvme_alloc_queue(struct nvme_fc_local_port *lport,
+unsigned int qidx, u16 qsize, void **handle)
 {
struct scsi_qla_host *vha;
struct qla_hw_data *ha;
@@ -193,13 +193,11 @@ static void qla_nvme_ls_abort(struct nvme_fc_local_port 
*lport,
struct qla_hw_data *ha = fcport->vha->hw;
 
rval = ha->isp_ops->abort_command(sp);
-   if (rval != QLA_SUCCESS)
-   ql_log(ql_log_warn, fcport->vha, 0x2125,
-   "%s: failed to abort LS command for SP:%p rval=%x\n",
-   __func__, sp, rval);
 
ql_dbg(ql_dbg_io, fcport->vha, 0x212b,
-   "%s: aborted sp:%p on fcport:%p\n", __func__, sp, fcport);
+   "%s: %s LS command for sp=%p on fcport=%p rval=%x\n", __func__,
+   (rval != QLA_SUCCESS) ? "Failed to abort" : "Aborted",
+   sp, fcport, rval);
 }
 
 static void qla_nvme_ls_complete(struct work_struct *work)
@@ -214,7 +212,7 @@ static void qla_nvme_ls_complete(struct work_struct *work)
 static int qla_nvme_ls_req(struct nvme_fc_local_port *lport,
 struct nvme_fc_remote_port *rport, struct nvmefc_ls_req *fd)
 {
-   fc_port_t *fcport = (fc_port_t *)rport->private;
+   fc_port_t *fcport = rport->private;
struct srb_iocb   *nvme;
struct nvme_private *priv = fd->private;
struct scsi_qla_host *vha;
@@ -236,7 +234,7 @@ static int qla_nvme_ls_req(struct nvme_fc_local_port *lport,
sp->name = "nvme_ls";
sp->done = qla_nvme_sp_ls_done;
atomic_set(>ref_count, 1);
-   init_waitqueue_head(>nvme_ls_waitQ);
+   init_waitqueue_head(>nvme_ls_waitq);
nvme = >u.iocb_cmd;
priv->sp = sp;
priv->fd = fd;
@@ -258,7 +256,7 @@ static int qla_nvme_ls_req(struct nvme_fc_local_port *lport,
ql_log(ql_log_warn, vha, 0x700e,
"qla2x00_start_sp failed = %d\n", rval);
atomic_dec(>ref_count);
-   wake_up(>nvme_ls_waitQ);
+   wake_up(>nvme_ls_waitq);
return rval;
}
 
@@ -276,20 +274,18 @@ static void qla_nvme_fcp_abort(struct nvme_fc_local_port 
*lport,
struct qla_hw_data *ha = fcport->vha->hw;
 
rval = ha->isp_ops->abort_command(sp);
-   if (!rval)
-   ql_log(ql_log_warn, fcport->vha, 0x2127,
-   "%s: failed to abort command for SP:%p rval=%x\n",
-   __func__, sp, rval);
 
-   ql_dbg(ql_dbg_io, fcport->vha, 0x2126,
-   "%s: aborted sp:%p on fcport:%p\n", __func__, sp, fcport);
+   ql_dbg(ql_dbg_io, fcport->vha, 0x2127,
+   "%s: %s command for sp=%p on fcport=%p rval=%x\n", 

[PATCH 6/7] qla2xxx: Fix remoteport disconnect for FC-NVMe

2017-07-19 Thread Himanshu Madhani
Signed-off-by: Duane Grigsby 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_isr.c  | 37 +++--
 drivers/scsi/qla2xxx/qla_nvme.c | 11 ---
 2 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 317fe6026856..c14fab35fc36 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -1856,17 +1856,42 @@ qla24xx_nvme_iocb_entry(scsi_qla_host_t *vha, struct 
req_que *req, void *tsk)
fd->transferred_length = fd->payload_length -
le32_to_cpu(sts->residual_len);
 
+   /*
+* If transport error then Failure (HBA rejects request)
+* otherwise transport will handle.
+*/
if (sts->entry_status) {
ql_log(ql_log_warn, fcport->vha, 0x5038,
"NVME-%s error - hdl=%x entry-status(%x).\n",
sp->name, sp->handle, sts->entry_status);
ret = QLA_FUNCTION_FAILED;
-   } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
-   ql_log(ql_log_warn, fcport->vha, 0x5039,
-   "NVME-%s error - hdl=%x completion status(%x) resid=%x  
ox_id=%x\n",
-   sp->name, sp->handle, sts->comp_status,
-   le32_to_cpu(sts->residual_len), sts->ox_id);
-   ret = QLA_FUNCTION_FAILED;
+   } else  {
+   switch (le16_to_cpu(sts->comp_status)) {
+   case CS_COMPLETE:
+   ret = 0;
+   break;
+
+   case CS_ABORTED:
+   case CS_RESET:
+   case CS_PORT_UNAVAILABLE:
+   case CS_PORT_LOGGED_OUT:
+   case CS_PORT_BUSY:
+   ql_log(ql_log_warn, fcport->vha, 0x5060,
+   "NVME-%s ERR Handling - hdl=%x completion 
status(%x) resid=%x  ox_id=%x\n",
+   sp->name, sp->handle, sts->comp_status,
+   le32_to_cpu(sts->residual_len), sts->ox_id);
+   fd->transferred_length = fd->payload_length;
+   ret = QLA_ABORTED;
+   break;
+
+   default:
+   ql_log(ql_log_warn, fcport->vha, 0x5060,
+   "NVME-%s error - hdl=%x completion status(%x) 
resid=%x  ox_id=%x\n",
+   sp->name, sp->handle, sts->comp_status,
+   le32_to_cpu(sts->residual_len), sts->ox_id);
+   ret = QLA_FUNCTION_FAILED;
+   break;
+   }
}
sp->done(sp, ret);
 }
diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
index ccafcdb228e8..da32a06f17a0 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -180,13 +180,13 @@ static void qla_nvme_sp_done(void *ptr, int res)
if (!(sp->fcport->nvme_flag & NVME_FLAG_REGISTERED))
goto rel;
 
-   if (unlikely(nvme->u.nvme.comp_status || res))
-   fd->status = -EINVAL;
+   if (unlikely(res == QLA_FUNCTION_FAILED))
+   fd->status = NVME_SC_FC_TRANSPORT_ERROR;
else
fd->status = 0;
 
fd->rcv_rsplen = nvme->u.nvme.rsp_pyld_len;
-   if (res == QLA_FUNCTION_FAILED) {
+   if (res) {
INIT_WORK(>rq_work, qla_nvme_io_work);
queue_work(sp->fcport->vha->nvme_io_wq, >rq_work);
return;
@@ -653,13 +653,18 @@ static void qla_nvme_unregister_remote_port(struct 
work_struct *work)
if (!IS_ENABLED(CONFIG_NVME_FC))
return;
 
+   ql_log(ql_log_warn, NULL, 0x2112,
+   "%s: unregister remoteport on %p\n",__func__, fcport);
+
list_for_each_entry_safe(rport, trport,
>vha->nvme_rport_list, list) {
if (rport->fcport == fcport) {
ql_log(ql_log_info, fcport->vha, 0x2113,
"%s: fcport=%p\n", __func__, fcport);
+   init_completion(>nvme_del_done);
nvme_fc_unregister_remoteport(
fcport->nvme_remote_port);
+   qla_nvme_wait_on_rport_del(fcport);
}
}
 }
-- 
2.12.0



[PATCH] SCSI: remove DRIVER_ATTR() usage

2017-07-19 Thread Greg KH
From: Greg Kroah-Hartman 

It's better to use the DRIVER_ATTR_RW() and DRIVER_ATTR_RO() macros to
explicitly show that this is a read/write or read/only sysfs file.  So
convert the remaining SCSI drivers that use the old style to use the
newer macros.

Bonus is that this removes some checkpatch.pl warnings :)

This is part of a series to drop DRIVER_ATTR() from the tree entirely.

Cc: "James E.J. Bottomley" 
Cc: "Martin K. Petersen" 
Cc: Kashyap Desai 
Cc: Sumit Saxena 
Cc: Shivasharan S 
Cc: Willem Riede 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/scsi/aic94xx/aic94xx_init.c   |4 +--
 drivers/scsi/megaraid/megaraid_sas_base.c |   36 ++
 drivers/scsi/osst.c   |4 +--
 3 files changed, 16 insertions(+), 28 deletions(-)

--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -956,11 +956,11 @@ static int asd_scan_finished(struct Scsi
return 1;
 }
 
-static ssize_t asd_version_show(struct device_driver *driver, char *buf)
+static ssize_t version_show(struct device_driver *driver, char *buf)
 {
return snprintf(buf, PAGE_SIZE, "%s\n", ASD_DRIVER_VERSION);
 }
-static DRIVER_ATTR(version, S_IRUGO, asd_version_show, NULL);
+static DRIVER_ATTR_RO(version);
 
 static int asd_create_driver_attrs(struct device_driver *driver)
 {
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -7323,49 +7323,39 @@ static struct pci_driver megasas_pci_dri
 /*
  * Sysfs driver attributes
  */
-static ssize_t megasas_sysfs_show_version(struct device_driver *dd, char *buf)
+static ssize_t version_show(struct device_driver *dd, char *buf)
 {
return snprintf(buf, strlen(MEGASAS_VERSION) + 2, "%s\n",
MEGASAS_VERSION);
 }
+static DRIVER_ATTR_RO(version);
 
-static DRIVER_ATTR(version, S_IRUGO, megasas_sysfs_show_version, NULL);
-
-static ssize_t
-megasas_sysfs_show_release_date(struct device_driver *dd, char *buf)
+static ssize_t release_date_show(struct device_driver *dd, char *buf)
 {
return snprintf(buf, strlen(MEGASAS_RELDATE) + 2, "%s\n",
MEGASAS_RELDATE);
 }
+static DRIVER_ATTR_RO(release_date);
 
-static DRIVER_ATTR(release_date, S_IRUGO, megasas_sysfs_show_release_date, 
NULL);
-
-static ssize_t
-megasas_sysfs_show_support_poll_for_event(struct device_driver *dd, char *buf)
+static ssize_t support_poll_for_event_show(struct device_driver *dd, char *buf)
 {
return sprintf(buf, "%u\n", support_poll_for_event);
 }
+static DRIVER_ATTR_RO(support_poll_for_event);
 
-static DRIVER_ATTR(support_poll_for_event, S_IRUGO,
-   megasas_sysfs_show_support_poll_for_event, NULL);
-
- static ssize_t
-megasas_sysfs_show_support_device_change(struct device_driver *dd, char *buf)
+static ssize_t support_device_change_show(struct device_driver *dd, char *buf)
 {
return sprintf(buf, "%u\n", support_device_change);
 }
+static DRIVER_ATTR_RO(support_device_change);
 
-static DRIVER_ATTR(support_device_change, S_IRUGO,
-   megasas_sysfs_show_support_device_change, NULL);
-
-static ssize_t
-megasas_sysfs_show_dbg_lvl(struct device_driver *dd, char *buf)
+static ssize_t dbg_lvl_show(struct device_driver *dd, char *buf)
 {
return sprintf(buf, "%u\n", megasas_dbg_lvl);
 }
 
-static ssize_t
-megasas_sysfs_set_dbg_lvl(struct device_driver *dd, const char *buf, size_t 
count)
+static ssize_t dbg_lvl_store(struct device_driver *dd, const char *buf,
+size_t count)
 {
int retval = count;
 
@@ -7375,9 +7365,7 @@ megasas_sysfs_set_dbg_lvl(struct device_
}
return retval;
 }
-
-static DRIVER_ATTR(dbg_lvl, S_IRUGO|S_IWUSR, megasas_sysfs_show_dbg_lvl,
-   megasas_sysfs_set_dbg_lvl);
+static DRIVER_ATTR_RW(dbg_lvl);
 
 static inline void megasas_remove_scsi_device(struct scsi_device *sdev)
 {
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -5667,12 +5667,12 @@ static  struct  osst_support_data support_
  * sysfs support for osst driver parameter information
  */
 
-static ssize_t osst_version_show(struct device_driver *ddd, char *buf)
+static ssize_t version_show(struct device_driver *ddd, char *buf)
 {
return snprintf(buf, PAGE_SIZE, "%s\n", osst_version);
 }
 
-static DRIVER_ATTR(version, S_IRUGO, osst_version_show, NULL);
+static DRIVER_ATTR_RO(version);
 
 static int osst_create_sysfs_files(struct device_driver *sysfs)
 {


[PATCH] qedi: Add ISCSI_BOOT_SYSFS to Kconfig

2017-07-19 Thread Nilesh Javali
qedi uses iscsi_boot_sysfs to export the targets used
for boot to sysfs. Select the config option to make sure
the module is built.

This addresses the compile time issue,
drivers/scsi/qedi/qedi_main.o: In function `qedi_remove':
qedi_main.c:(.text+0x3bbd): undefined reference to `iscsi_boot_destroy_kset'
drivers/scsi/qedi/qedi_main.o: In function `__qedi_probe.constprop.0':
qedi_main.c:(.text+0x577a): undefined reference to 
`iscsi_boot_create_target'
qedi_main.c:(.text+0x5807): undefined reference to 
`iscsi_boot_create_target'
qedi_main.c:(.text+0x587f): undefined reference to 
`iscsi_boot_create_initiator'
qedi_main.c:(.text+0x58f3): undefined reference to 
`iscsi_boot_create_ethernet'
qedi_main.c:(.text+0x5927): undefined reference to `iscsi_boot_destroy_kset'
qedi_main.c:(.text+0x5d7b): undefined reference to 
`iscsi_boot_create_host_kset'

Signed-off-by: Nilesh Javali 
---
 drivers/scsi/qedi/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/scsi/qedi/Kconfig b/drivers/scsi/qedi/Kconfig
index 2133145..6f3773f 100644
--- a/drivers/scsi/qedi/Kconfig
+++ b/drivers/scsi/qedi/Kconfig
@@ -5,6 +5,7 @@ config QEDI
select SCSI_ISCSI_ATTRS
select QED_LL2
select QED_ISCSI
+select ISCSI_BOOT_SYSFS
---help---
This driver supports iSCSI offload for the QLogic FastLinQ
41000 Series Converged Network Adapters.
-- 
1.8.3.1



RE: [PATCH v2 11/15] megaraid_sas: Set device queue_depth same as HBA can_queue value in scsi-mq mode

2017-07-19 Thread Shivasharan Srikanteshwara
> -Original Message-
> From: Shivasharan Srikanteshwara
> [mailto:shivasharan.srikanteshw...@broadcom.com]
> Sent: Wednesday, July 12, 2017 1:51 PM
> To: Kashyap Desai; 'Christoph Hellwig'
> Cc: 'linux-scsi@vger.kernel.org'; 'martin.peter...@oracle.com';
> 'the...@redhat.com'; 'j...@linux.vnet.ibm.com'; Sumit Saxena;
> 'h...@suse.com'
> Subject: RE: [PATCH v2 11/15] megaraid_sas: Set device queue_depth same as
> HBA can_queue value in scsi-mq mode
>
> > -Original Message-
> > From: Kashyap Desai [mailto:kashyap.de...@broadcom.com]
> > Sent: Tuesday, July 11, 2017 9:18 PM
> > To: Christoph Hellwig; Shivasharan Srikanteshwara
> > Cc: linux-scsi@vger.kernel.org; martin.peter...@oracle.com;
> > the...@redhat.com; j...@linux.vnet.ibm.com; Sumit Saxena; h...@suse.com
> > Subject: RE: [PATCH v2 11/15] megaraid_sas: Set device queue_depth same
> > as
> > HBA can_queue value in scsi-mq mode
> >
> > > -Original Message-
> > > From: Christoph Hellwig [mailto:h...@lst.de]
> > > Sent: Tuesday, July 11, 2017 7:28 PM
> > > To: Shivasharan S
> > > Cc: linux-scsi@vger.kernel.org; martin.peter...@oracle.com;
> > > the...@redhat.com; j...@linux.vnet.ibm.com;
> > > kashyap.de...@broadcom.com; sumit.sax...@broadcom.com;
> > h...@suse.com;
> > > h...@lst.de
> > > Subject: Re: [PATCH v2 11/15] megaraid_sas: Set device queue_depth
> > > same
> > as
> > > HBA can_queue value in scsi-mq mode
> > >
> > > On Wed, Jul 05, 2017 at 05:00:25AM -0700, Shivasharan S wrote:
> > > > Currently driver sets default queue_depth for VDs at 256 and JBODs
> > > > based on interface type, ie., for SAS JBOD QD will be 64, for SATA
> > JBOD QD
> > > will be 32.
> > > > During performance runs with scsi-mq enabled, we are seeing better
> > > > results by setting QD same as HBA queue_depth.
> > >
> > > Please no scsi-mq specifics.  just do this unconditionally.
> >
> > Chris -  Intent for mq specific check is mainly because of sequential
> > work load
> > for HDD is having penalty due to mq scheduler issue.
> > We did this exercise prior to mq-deadline support.
> >
> > Making generic change for non-mq and mq was good, but we may see some
> > user may not like to see regression.
> > E.a In case of, QD = 32 for SATA PD file system creation may be faster
> compare
> > to large QD. There may be a soft merger at block layer due to queue
> > depth
> > throttling. Eventually, FS creation goes fast due to IO merges, but same
> > will
> not
> > be true if we change queue depth logic (means, increase device queue
> > depth
> to
> > HBA QD.)
> >
> > We have choice to completely remove this patch and ask users to do sysfs
> > settings in case of scsi-mq performance issue for HDD sequential work
> > load.
> > Having this patch, we want to provide better QD settings as default from
> driver.
> >
> >
> > Thanks, Kashyap
>
> Hi Christoph,
> As Kashyap mentioned, the performance issues seen were specific to scsi-mq
> enabled case when running sequential workloads with HDDs.
> Making this generic might result in regressions in some scenarios for
> non-mq.
> That was the idea behind making the change specific to scsi-mq only.
>
> Let us know if you are ok with having this as is or we could remove
> this patch completely and have users manually tune queue depth settings if
> they
> are seeing performance issues with scsi-mq enabled.
>
> Thanks,
> Shivasharan

Hi Christoph,
Can you please let us know your thoughts on this patch?
Are we good to keep the changes as is?

Thanks,
Shivasharan


Re: [REGRESSION] 28676d869bbb (scsi: sg: check for valid direction before starting the request) breaks mtx tape library control

2017-07-19 Thread Johannes Thumshirn
On Wed, Jul 19, 2017 at 03:13:34AM -0500, Jason L Tibbitts III wrote:
> [   46.304530] sg_is_valid_dxfer: dxfer_direction: -2, dxfer_len: 0

Ahh now I see the -2 (SG_DXFER_TO_DEV) is the crucial point here. It is 0 in
your case.

This would "fix" it but I'm not generally sure it is _the_ solution:

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 1e82d4128a84..b421ec81d775 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -764,7 +764,7 @@ static bool sg_is_valid_dxfer(sg_io_hdr_t *hp)
return true;
case SG_DXFER_TO_DEV:
case SG_DXFER_TO_FROM_DEV:
-   if (!hp->dxferp || hp->dxfer_len == 0)
+   if (!hp->dxferp)
return false;
return true;
case SG_DXFER_UNKNOWN:

Doug, what are the rules for SG_DXFER_TO_{FROM_}DEV? Apparently we can't
be sure len > 0, can we rely on dxferp being present?

Thanks,
Johannes
-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850


Re: [REGRESSION] 28676d869bbb (scsi: sg: check for valid direction before starting the request) breaks mtx tape library control

2017-07-19 Thread Jason L Tibbitts III
> "JT" == Johannes Thumshirn  writes:

JT> Can you please apply this debugging patch, so I can see what's going
JT> on.

Sure, no problem.

I generally run "mtx -f /dev/sg7 status" first just to make sure the
library is there; this has always worked as expected.  With the debug
patch applied, this is sent to the console:
[   33.933422] sg_is_valid_dxfer: dxfer_direction: -3, dxfer_len: 56
[   33.940526] sg_is_valid_dxfer: dxfer_direction: -3, dxfer_len: 136
[   33.982429] sg_is_valid_dxfer: dxfer_direction: -3, dxfer_len: 4240
[   34.569986] sg_is_valid_dxfer: dxfer_direction: -3, dxfer_len: 4240
[   34.623898] sg_is_valid_dxfer: dxfer_direction: -3, dxfer_len: 4240

Then running "mtx -f /dev/sg7 next 0" gives this as stdout/err:

Unloading drive 0 into Storage Element 46...mtx: Request Sense: Long
Report=yes
mtx: Request Sense: Valid Residual=no
mtx: Request Sense: Error Code=0 (Unknown?!)
mtx: Request Sense: Sense Key=No Sense
mtx: Request Sense: FileMark=no
mtx: Request Sense: EOM=no
mtx: Request Sense: ILI=no
mtx: Request Sense: Additional Sense Code = 00
mtx: Request Sense: Additional Sense Qualifier = 00
mtx: Request Sense: BPV=no
mtx: Request Sense: Error in CDB=no
mtx: Request Sense: SKSV=no
MOVE MEDIUM from Element Address 1 to 1046 Failed

And this to the console:
[   45.552524] sg_is_valid_dxfer: dxfer_direction: -3, dxfer_len: 56
[   45.559626] sg_is_valid_dxfer: dxfer_direction: -3, dxfer_len: 136
[   45.603544] sg_is_valid_dxfer: dxfer_direction: -3, dxfer_len: 4240
[   46.204614] sg_is_valid_dxfer: dxfer_direction: -3, dxfer_len: 4240
[   46.258463] sg_is_valid_dxfer: dxfer_direction: -3, dxfer_len: 4240
[   46.304530] sg_is_valid_dxfer: dxfer_direction: -2, dxfer_len: 0

Would you also want to see the output from that patch applied to a
functioning kernel?

 - J<


Re: [PATCH 05/13] mpt3sas: Set NVMe device queue depth as 128

2017-07-19 Thread Suganath Prabu Subramani
Hi Elliott,
We are maintaining NVMe drives as scsi device in mpt3sas driver.
There are lot of firmware/hardware level dependencies and after lot of
discussions we arrived this value (128).
So, we prefer not to provide module parameter to change this at least for now.

Thanks,
Suganath Prabu S

On Tue, Jul 11, 2017 at 10:53 PM, Elliott, Robert (Persistent Memory)
 wrote:
>> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
>> @@ -115,7 +115,7 @@
>>
>>  #define MPT3SAS_RAID_MAX_SECTORS 8192
>>  #define MPT3SAS_HOST_PAGE_SIZE_4K12
>> -
>> +#define MPT3SAS_NVME_QUEUE_DEPTH 128
> ...
>> + /*TODO-right Queue Depth?*/
>> + qdepth = MPT3SAS_NVME_QUEUE_DEPTH;
>> + ds = "NVMe";
>
> The native NVMe driver is getting a modparam to set that value (rather than
> using a #define of 1024) in this patch:
> http://lists.infradead.org/pipermail/linux-nvme/2017-July/011734.html
>
> Perhaps this driver should do the same.
>
> ---
> Robert Elliott, HPE Persistent Memory
>
>


Re: [REGRESSION] 28676d869bbb (scsi: sg: check for valid direction before starting the request) breaks mtx tape library control

2017-07-19 Thread Johannes Thumshirn
On Tue, Jul 18, 2017 at 12:33:59PM -0500, Jason L Tibbitts III wrote:
> I have verified that building a clean v4.12 with
> 68c59fcea1f2c6a54c62aa896cc623c1b5bc9b47 cherry picked on top still
> shows the problem:
> 
> [root@backup2 ~]# mtx -f /dev/sg7 next 0
> Unloading drive 0 into Storage Element 45...mtx: Request Sense: Long
> Report=yes
> mtx: Request Sense: Valid Residual=no
> mtx: Request Sense: Error Code=0 (Unknown?!)
> mtx: Request Sense: Sense Key=No Sense
> mtx: Request Sense: FileMark=no
> mtx: Request Sense: EOM=no
> mtx: Request Sense: ILI=no
> mtx: Request Sense: Additional Sense Code = 00
> mtx: Request Sense: Additional Sense Qualifier = 00
> mtx: Request Sense: BPV=no
> mtx: Request Sense: Error in CDB=no
> mtx: Request Sense: SKSV=no
> MOVE MEDIUM from Element Address 1 to 1045 Failed
> 
> Nothing appears to be logged; is there any kind of debugging information
> I can collect which might help to track this down?  I'm not particularly
> good at this but I am pretty sure that I'm building everything properly
> and am actually booting the patched kernel.


Can you please apply this debugging patch, so I can see what's going on.

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 1e82d4128a84..2505fa0b2062 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -753,6 +753,10 @@ sg_new_write(Sg_fd *sfp, struct file *file, const char 
__user *buf,
 
 static bool sg_is_valid_dxfer(sg_io_hdr_t *hp)
 {
+
+   pr_info("%s: dxfer_direction: %d, dxfer_len: %d\n",
+   __func__, hp->dxfer_direction, hp->dxfer_len);
+
switch (hp->dxfer_direction) {
case SG_DXFER_NONE:
if (hp->dxferp || hp->dxfer_len > 0)

Thanks,
Johannes
-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850