Re: [PATCH v2 6/6] qla2xxx: Refactor usage of Active command arrays

2017-07-21 Thread Bart Van Assche
On Fri, 2017-07-21 at 09:32 -0700, Himanshu Madhani wrote:
> From: Quinn Tran 

Thank you for having done this work!

> +#define SRB_TO_U(_p) container_of(_p, struct unify_cmd, srb)
> +#define TCMD_TO_U(_p) container_of(_p, struct unify_cmd, tcmd)

If you have to repost this patch, please change these macros into inline
functions such that the compiler can check the type of the argument (_p).

> @@ -2799,7 +2800,7 @@ qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, 
> struct req_que *req)
> req->num_outstanding_cmds = ha->cur_fw_iocb_count;
> }
>  
> -   req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
> +   req->outstanding_cmds = kzalloc(sizeof(struct unify_cmd *) *
> req->num_outstanding_cmds, GFP_KERNEL);
>  
> if (!req->outstanding_cmds) {
> @@ -2808,7 +2809,7 @@ qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, 
> struct req_que *req)
>  * initialization.
>  */
> req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
> -   req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
> +   req->outstanding_cmds = kzalloc(sizeof(struct unify_cmd *) *
> req->num_outstanding_cmds, GFP_KERNEL);
>  
> if (!req->outstanding_cmds) {

Please use kcalloc() instead of kzalloc(... * ..., ...).

> @@ -2165,6 +2170,7 @@ qla25xx_process_bidir_status_iocb(scsi_qla_host_t *vha, 
> void *pkt,
>   struct fc_bsg_reply *bsg_reply;
>   sts_entry_t *sts;
>   struct sts_entry_24xx *sts24;
> + struct unify_cmd *u;
>   sts = (sts_entry_t *) pkt;
>   sts24 = (struct sts_entry_24xx *) pkt;

Please leave a blank line between declarations and code.
 
Anyway, whether or not these comments get addressed:

Reviewed-by: Bart Van Assche 

[PATCH 1/2] scsi: generate uevent for SCSI sense code

2017-07-21 Thread Song Liu
This patch adds capability for SCSI layer to generate uevent for SCSI
sense code. The feature is gated by CONFIG_SCSI_SENSE_UEVENT.

We can configure which sense keys generate uevent for each device
through sysfs entry sense_event_filter, which is a bitmap of
"sense keys to generate uevent" For example, the following enables
uevent for MEDIUM_ERROR (0x03) and HARDWARE_ERROR (0x04) on scsi
drive sdc:

echo 0x000c > /sys/block/sdc/device/sense_event_filter

Here is an example output captured by udevadm:

KERNEL[587.353177] change   /devices/pci:00/XX
ACTION=change
CDB=\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00
DEVPATH=/devices/pci:00/:00:01.0/:01:00.0/host6/XX
DEVTYPE=scsi_device
DRIVER=sd
MODALIAS=scsi:t-0x00
SDEV_SENSE=1
SENSE_BUFFER=\x72\x03\x11\x14\x00\x00\x00\x34\x00\x0a\x80 
SENSE_CODE=3/11/14
SEQNUM=4796
SUBSYSTEM=scsi

Signed-off-by: Song Liu 
---
 drivers/scsi/Kconfig   | 14 +++
 drivers/scsi/scsi_error.c  | 42 +
 drivers/scsi/scsi_lib.c| 58 +-
 drivers/scsi/scsi_sysfs.c  | 51 
 include/scsi/scsi_common.h |  6 +
 include/scsi/scsi_device.h | 27 -
 6 files changed, 196 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index d384f4f..0fb672b 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -226,6 +226,20 @@ config SCSI_LOGGING
  there should be no noticeable performance impact as long as you have
  logging turned off.
 
+config SCSI_SENSE_UEVENT
+   bool "SCSI sense code logging"
+   depends on SCSI
+   default n
+   ---help---
+ This turns on uevent for SCSI sense code.
+
+ You can configure which sense keys generate uevent for each device
+ through sysfs entry sense_event_filter. For example, the following
+ enables uevent for MEDIUM_ERROR (0x03) and HARDWARE_ERROR (0x04)
+ on scsi drive sdc:
+
+ echo 0x000c > /sys/block/sdc/device/sense_event_filter
+
 config SCSI_SCAN_ASYNC
bool "Asynchronous SCSI scanning"
depends on SCSI
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index ea9f40e..f6107f7 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -426,6 +426,47 @@ static void scsi_report_sense(struct scsi_device *sdev,
}
 }
 
+/*
+ * generate uevent when receiving sense code from device
+ */
+static void scsi_send_sense_uevent(struct scsi_device *sdev,
+  struct scsi_cmnd *scmd,
+  struct scsi_sense_hdr *sshdr)
+{
+#ifdef CONFIG_SCSI_SENSE_UEVENT
+   struct scsi_event *evt;
+   unsigned char sb_len;
+
+   if (!test_bit(sshdr->sense_key, >sense_event_filter))
+   return;
+   evt = sdev_evt_alloc(SDEV_EVT_SCSI_SENSE, GFP_ATOMIC);
+   if (!evt)
+   return;
+
+   evt->sense_evt_data.cmnd = kzalloc(scmd->cmd_len, GFP_ATOMIC);
+   if (!evt->sense_evt_data.cmnd)
+   goto alloc_cmd_fail;
+
+   sb_len = scsi_sense_data_length(scmd->sense_buffer);
+
+   evt->sense_evt_data.sense_buffer = kzalloc(sb_len, GFP_ATOMIC);
+   if (!evt->sense_evt_data.sense_buffer)
+   goto alloc_sense_fail;
+
+   evt->sense_evt_data.cmd_len = scmd->cmd_len;
+   evt->sense_evt_data.sb_len = sb_len;
+   memcpy(evt->sense_evt_data.cmnd, scmd->cmnd, scmd->cmd_len);
+   memcpy(evt->sense_evt_data.sense_buffer, scmd->sense_buffer, sb_len);
+
+   sdev_evt_send(sdev, evt);
+   return;
+alloc_sense_fail:
+   kfree(evt->sense_evt_data.cmnd);
+alloc_cmd_fail:
+   kfree(evt);
+#endif
+}
+
 /**
  * scsi_check_sense - Examine scsi cmd sense
  * @scmd:  Cmd to have sense checked.
@@ -446,6 +487,7 @@ int scsi_check_sense(struct scsi_cmnd *scmd)
return FAILED;  /* no valid sense data */
 
scsi_report_sense(sdev, );
+   scsi_send_sense_uevent(sdev, scmd, );
 
if (scsi_sense_is_deferred())
return NEEDS_RETRY;
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index f6097b8..7c6ab28 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2677,7 +2677,15 @@ EXPORT_SYMBOL(scsi_device_set_state);
 static void scsi_evt_emit(struct scsi_device *sdev, struct scsi_event *evt)
 {
int idx = 0;
-   char *envp[3];
+   char *envp[5];  /* SDEV_EVT_SCSI_SENSE needs most entries (4) */
+#ifdef CONFIG_SCSI_SENSE_UEVENT
+   char *buf = NULL;
+   int i;
+   int buf_size;
+   int offset;
+   struct scsi_sense_hdr sshdr;
+#endif
+
 
switch (evt->evt_type) {
case SDEV_EVT_MEDIA_CHANGE:
@@ -2702,6 +2710,49 @@ static void scsi_evt_emit(struct scsi_device *sdev, 
struct scsi_event *evt)
case SDEV_EVT_ALUA_STATE_CHANGE_REPORTED:

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

2017-07-21 Thread Song Liu
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 2/2] scsi: add rate limit to scsi sense code uevent

2017-07-21 Thread Song Liu
This patch adds rate limits to SCSI sense code uevets. Currently,
the rate limit is hard-coded to 64 events per second per Scsi_Host.

The code tracks nano second time of latest 64 events in a circular
buffer. When a new event arrives, the time is compared against the
latest time in the buffer. If the difference is smaller than one
second, the new event is dropped.

Signed-off-by: Song Liu 
---
 drivers/scsi/hosts.c  |  4 
 drivers/scsi/scsi_error.c | 16 
 include/scsi/scsi_host.h  | 13 +
 3 files changed, 33 insertions(+)

diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 831a1c8..219481b 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -408,6 +408,10 @@ struct Scsi_Host *scsi_host_alloc(struct 
scsi_host_template *sht, int privsize)
init_waitqueue_head(>host_wait);
mutex_init(>scan_mutex);
 
+#ifdef CONFIG_SCSI_SENSE_UEVENT
+   spin_lock_init(>latest_event_lock);
+#endif
+
index = ida_simple_get(_index_ida, 0, 0, GFP_KERNEL);
if (index < 0)
goto fail_kfree;
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index f6107f7..58047f9 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -436,9 +436,25 @@ static void scsi_send_sense_uevent(struct scsi_device 
*sdev,
 #ifdef CONFIG_SCSI_SENSE_UEVENT
struct scsi_event *evt;
unsigned char sb_len;
+   struct Scsi_Host *shost = sdev->host;
+   unsigned long flags;
+   u64 time_ns;
 
if (!test_bit(sshdr->sense_key, >sense_event_filter))
return;
+
+   time_ns = ktime_to_ns(ktime_get());
+   spin_lock_irqsave(>latest_event_lock, flags);
+   if (time_ns - shost->latest_event_times[shost->latest_event_idx] <
+   NSEC_PER_SEC) {
+   spin_unlock_irqrestore(>latest_event_lock, flags);
+   return;
+   }
+   shost->latest_event_times[shost->latest_event_idx] = time_ns;
+   shost->latest_event_idx = (shost->latest_event_idx + 1) %
+   MAX_SENSE_EVENT_PER_SECOND;
+   spin_unlock_irqrestore(>latest_event_lock, flags);
+
evt = sdev_evt_alloc(SDEV_EVT_SCSI_SENSE, GFP_ATOMIC);
if (!evt)
return;
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index afb0481..8aacb15 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -731,6 +731,19 @@ struct Scsi_Host {
 */
struct device *dma_dev;
 
+#ifdef CONFIG_SCSI_SENSE_UEVENT
+#define MAX_SENSE_EVENT_PER_SECOND 64
+   /*
+* To rate limit uevents to MAX_SENSE_EVENT_PER_SECOND, we track
+* nano second time of MAX_SENSE_EVENT_PER_SECOND most recent
+* events. If there are already MAX_SENSE_EVENT_PER_SECOND in the
+* past seconds, new event is dropped.
+*/
+   u64 latest_event_times[MAX_SENSE_EVENT_PER_SECOND];
+   int latest_event_idx;
+   spinlock_t  latest_event_lock;
+#endif
+
/*
 * We should ensure that this is aligned, both for better performance
 * and also because some compilers (m68k) don't automatically force
-- 
2.9.3



[PATCH, RESEND] scsi: lpfc: fix linking against modular NVMe support

2017-07-21 Thread Arnd Bergmann
When LPFC is built-in but NVMe is a loadable module, we fail to
link the kernel:

drivers/scsi/built-in.o: In function `lpfc_nvme_create_localport':
(.text+0x156a82): undefined reference to `nvme_fc_register_localport'
drivers/scsi/built-in.o: In function `lpfc_nvme_destroy_localport':
(.text+0x156eaa): undefined reference to `nvme_fc_unregister_remoteport'

We can avoid this either by forcing lpfc to be a module, or by disabling
NVMe support in this case. This implements the former.

Fixes: 7d7080335f8d ("scsi: lpfc: Finalize Kconfig options for nvme")
Cc: sta...@vger.kernel.org
Link: https://patchwork.kernel.org/patch/9636569/
Signed-off-by: Arnd Bergmann 
---
I originally sent the patch in March 2013, the day after the broken
patch made it into Linux-next. Unfortunately there was some
misunderstanding about it (James Smart thought the broken patch
was the correct version), and my fix never got merged.
---
 drivers/scsi/Kconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index d384f4f86c26..f4538d7a3016 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1230,6 +1230,8 @@ config SCSI_LPFC
tristate "Emulex LightPulse Fibre Channel Support"
depends on PCI && SCSI
depends on SCSI_FC_ATTRS
+   depends on NVME_TARGET_FC || NVME_TARGET_FC=n
+   depends on NVME_FC || NVME_FC=n
select CRC_T10DIF
---help---
   This lpfc driver supports the Emulex LightPulse
-- 
2.9.0



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

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

JT> Jason, can you try the above? If it works and Doug doesn't respond,
JT> I'm inclined yo submit this band aid.

Unfortunately it doesn't appear to work for me.  Maybe I'm building the
wrong thing, though.  I checked out 4.12, cherry picked
68c59fcea1f2c6a54c62aa896cc623c1b5bc9b47 and then applied your one liner
on top of that.  There appears to be no change in behavior:

[root@backup2 ~]# mtx -f /dev/sg7 next 0
Unloading drive 0 into Storage Element 47...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 1047 Failed

I can also apply the debugging patch and try again if that would give
you more useful information.

 - J<


Re: [PATCH] aic7xxx: fix firmware build with O=path

2017-07-21 Thread Jakub Kicinski
On Tue, 18 Jul 2017 18:58:34 -0700, Jakub Kicinski wrote:
> Building firmware with O=path was apparently broken in aic7 for ever.
> Message of the previous commit to the Makefile (from 2008) mentions
> this unfortunate state of affairs already.  Fix this, mostly to make
> randconfig builds more reliable.
> 
> Signed-off-by: Jakub Kicinski 

Gentle ping :)  Hannes, are you still maintaining aic7xxx?


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

2017-07-21 Thread Johannes Thumshirn
Doug,

On Wed, Jul 19, 2017 at 10:36:54AM +0200, Johannes Thumshirn wrote:
> 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?

Any comments on this?

Jason, can you try the above? If it works and Doug doesn't respond, I'm
inclined yo submit this band aid.

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


[PATCH v2 1/6] qla2xxx: Cleanup FC-NVMe code

2017-07-21 Thread Himanshu Madhani
This patch does not change any functionality.

Following cleanups have been done as requested by reviewer

- Changed waitQ --> waitq
- Collapsed multiple debug statements into single
- Remove extra parentheses in if-else as per operator precedence
- Remove unnecessary casting

Cc: Johannes Thumshirn 
Signed-off-by: Himanshu Madhani 
Reviewed-by: Johannes Thumshirn 
---
 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 

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

2017-07-21 Thread Himanshu Madhani
Signed-off-by: Duane Grigsby 
Signed-off-by: Himanshu Madhani 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/qla2xxx/qla_isr.c  | 37 +++--
 drivers/scsi/qla2xxx/qla_nvme.c |  9 +++--
 2 files changed, 38 insertions(+), 8 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 6c5eebbbda4c..97a7b222b549 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -169,8 +169,8 @@ 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;
 
@@ -635,13 +635,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 v2 2/6] qla2xxx: Move function prototype to correct header

2017-07-21 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 v2 4/6] qla2xxx: Simpify unregistration of FC-NVMe local/remote ports

2017-07-21 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  |  6 ++---
 drivers/scsi/qla2xxx/qla_nvme.c | 59 +++--
 2 files changed, 12 insertions(+), 53 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 5ceb50161d89..b3e3982a9db0 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -2302,8 +2302,7 @@ typedef struct fc_port {
unsigned int login_succ:1;
 
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
@@ -4134,8 +4133,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;
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 eecbe8bc4890..6c5eebbbda4c 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;
@@ -233,7 +231,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;
@@ -540,12 +537,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)
@@ -556,8 +551,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) {
@@ -567,6 +560,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);
@@ -609,12 +603,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);
@@ -633,39 +626,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) && 

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

2017-07-21 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 v2 3/6] qla2xxx: Added change to enable ZIO for FC-NVMe devices

2017-07-21 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  | 71 +
 drivers/scsi/qla2xxx/qla_nvme.c | 14 ++--
 drivers/scsi/qla2xxx/qla_os.c   | 25 ---
 7 files changed, 99 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 1635e98867aa..5ceb50161d89 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -977,6 +977,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. */
@@ -4017,6 +4018,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 */
 };
 
 /*
@@ -4089,6 +4093,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..97dcabc790c9 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..28728c49d8df 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 v2 0/6] qla2xxx: Bug fixes for driver

2017-07-21 Thread Himanshu Madhani
Hi Martin, 

This series addresses review comments for previously submitted series for
target multiqueue and FC-NVMe support in 4.13.0-rc1

Patches 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 ZIO support for FC-NVMe

Patch 4 simplifies unregistration of local/remote FC-NVMe ports.

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

Patch 6 addresses review comments by Bart for Target Multiqueue series.
(https://www.spinics.net/lists/target-devel/msg15563.html)

Changes from v1 --> v2

o Added change log into commit message for cleanup patch.
o Dropped Patch for adding completion WQ for FC-NVMe error path for rework.
o Addressed review comments from Johannes in ZIO support patch.
o Added Reviewed by tag.

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

Thanks,
Himanshu

Duane Grigsby (1):
  qla2xxx: Added change to enable ZIO for FC-NVMe devices

Himanshu Madhani (4):
  qla2xxx: Cleanup FC-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|  44 +++-
 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|  77 +
 drivers/scsi/qla2xxx/qla_mr.c |  19 ++---
 drivers/scsi/qla2xxx/qla_nvme.c   | 142 +++---
 drivers/scsi/qla2xxx/qla_nvme.h   |  17 +
 drivers/scsi/qla2xxx/qla_nx.c |   6 +-
 drivers/scsi/qla2xxx/qla_os.c |  60 +++-
 drivers/scsi/qla2xxx/qla_target.c |  18 +++--
 drivers/scsi/qla2xxx/qla_target.h |   5 --
 16 files changed, 336 insertions(+), 239 deletions(-)

-- 
2.12.0



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

2017-07-21 Thread Madhani, Himanshu
Hi Johannes, 

> On Jul 20, 2017, at 12:03 AM, Johannes Thumshirn  wrote:
> 
> On Wed, Jul 19, 2017 at 11:51:49AM -0700, Himanshu Madhani wrote:
>> -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) ||
>> -(sp->type == SRB_NVME_LS)) &&
>> -(sp->fcport == fcport)) {
>> -atomic_inc(>ref_count);
>> -spin_unlock_irqrestore(>hardware_lock,
>> -flags);
>> -qla_nvme_abort(ha, sp);
>> -spin_lock_irqsave(>hardware_lock, flags);
>> -req->outstanding_cmds[cnt] = NULL;
>> -sp->done(sp, 1);
>> -}
>> -}
>> -}
>> -spin_unlock_irqrestore(>hardware_lock, flags);
>> -}
>> -
>> static void qla_nvme_unregister_remote_port(struct work_struct *work)
>> {
>>  struct fc_port *fcport = container_of(work, struct fc_port,
>> @@ -719,12 +679,13 @@ void qla_nvme_delete(struct scsi_qla_host *vha)
>>  ql_log(ql_log_info, fcport->vha, 0x2114, "%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);
>> -qla_nvme_abort_all(fcport);
> 
> What changed the need to abort all outstanding commands?
> 

FC NVMe transport now handles _abort_ so we do not need to call 
qla_nvme_abort_all()

> -- 
> 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

Thanks,
- Himanshu



[PATCH] scsi: qedi: select CONFIG_ISCSI_BOOT_SYSFS

2017-07-21 Thread Arnd Bergmann
Without the base library support, we get a link failure

drivers/scsi/qedi/qedi_main.o: In function `__qedi_probe.constprop.0':
qedi_main.c:(.text+0x2d8e): undefined reference to `iscsi_boot_create_target'
qedi_main.c:(.text+0x2dee): undefined reference to `iscsi_boot_create_initiator'
qedi_main.c:(.text+0x2e1c): undefined reference to `iscsi_boot_create_ethernet'

This selects the Kconfig symbol like the other two users of that
module do.

Fixes: c57ec8fb7c02 ("scsi: qedi: Add support for Boot from SAN over iSCSI 
offload")
Signed-off-by: Arnd Bergmann 
---
 drivers/scsi/qedi/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/scsi/qedi/Kconfig b/drivers/scsi/qedi/Kconfig
index 21331453db7b..8deb8723c4dd 100644
--- a/drivers/scsi/qedi/Kconfig
+++ b/drivers/scsi/qedi/Kconfig
@@ -2,6 +2,7 @@ config QEDI
tristate "QLogic QEDI 25/40/100Gb iSCSI Initiator Driver Support"
depends on PCI && SCSI && UIO
depends on QED
+   select ISCSI_BOOT_SYSFS
select SCSI_ISCSI_ATTRS
select QED_LL2
select QED_ISCSI
-- 
2.9.0



RE: [PATCH] scsi: megaraid_sas: fix memleak in megasas_alloc_cmdlist_fusion

2017-07-21 Thread Sumit Saxena
>-Original Message-
>From: shuw...@redhat.com [mailto:shuw...@redhat.com]
>Sent: Friday, July 21, 2017 4:24 PM
>To: kashyap.de...@broadcom.com; sumit.sax...@broadcom.com;
>shivasharan.srikanteshw...@broadcom.com; j...@linux.vnet.ibm.com;
>martin.peter...@oracle.com
>Cc: megaraidlinux@broadcom.com; linux-scsi@vger.kernel.org; linux-
>ker...@vger.kernel.org; ch...@redhat.com; liw...@redhat.com; Shu Wang
>Subject: [PATCH] scsi: megaraid_sas: fix memleak in
>megasas_alloc_cmdlist_fusion
>
>From: Shu Wang 
>
>Found this issue by kmemleak, a few kb mem was leaked in
>megasas_alloc_cmdlist_fusion when kzalloc failed for one
>megasas_cmd_fusion allocation.
>
>unreferenced object 0x88045dbd2000 (size 8192):
>  comm "systemd-udevd", pid 323, jiffies 4294671759 (age 49.008s)
>  backtrace:
>[] kmemleak_alloc+0x4a/0xa0
>[] __kmalloc+0xe8/0x220
>[] megasas_alloc_cmdlist_fusion+0x34/0xe0
>[megaraid_sas]
>(gdb) list *megasas_alloc_cmdlist_fusion+0x34
>0xd5c4 is in megasas_alloc_cmdlist_fusion
>   (drivers/scsi/megaraid/megaraid_sas_fusion.c:443).
>[] megasas_alloc_cmds_fusion+0x25/0x410
>[megaraid_sas]
>[] megasas_init_adapter_fusion+0x21f/0x640
>[megaraid_sas]
>[] megasas_init_fw+0x357/0xd30 [megaraid_sas]
>[] megasas_probe_one.part.33+0x636/0x1100
>[megaraid_sas]
>[] megasas_probe_one+0x46/0xc0 [megaraid_sas]
>[] local_pci_probe+0x45/0xa0
>[] pci_device_probe+0x192/0x1b0
>[] driver_probe_device+0x2a8/0x460
>[] __driver_attach+0xdd/0xe0
>[] bus_for_each_dev+0x6c/0xc0
>[] driver_attach+0x1e/0x20
>[] bus_add_driver+0x45/0x270
>[] driver_register+0x60/0xe0 unreferenced object
>0x880454ce3600 (size 192):
>  backtrace:
>[] kmemleak_alloc+0x4a/0xa0
>[] kmem_cache_alloc_trace+0xca/0x1d0
>[] megasas_alloc_cmdlist_fusion+0x77/0xe0
>[megaraid_sas]
>(gdb) list *megasas_alloc_cmdlist_fusion+0x77
>0xd607 is in megasas_alloc_cmdlist_fusion
>(drivers/scsi/megaraid/megaraid_sas_fusion.c:450).
>[] megasas_alloc_cmds_fusion+0x25/0x410
>[megaraid_sas]
>[] megasas_init_adapter_fusion+0x21f/0x640
>[megaraid_sas]
>[] megasas_init_fw+0x357/0xd30 [megaraid_sas]
>[] megasas_probe_one.part.33+0x636/0x1100
>[megaraid_sas]
>[] megasas_probe_one+0x46/0xc0 [megaraid_sas]
>[] local_pci_probe+0x45/0xa0
>[] pci_device_probe+0x192/0x1b0
>[] driver_probe_device+0x2a8/0x460
>[] __driver_attach+0xdd/0xe0
>[] bus_for_each_dev+0x6c/0xc0
>[] driver_attach+0x1e/0x20
>[] bus_add_driver+0x45/0x270
>[] driver_register+0x60/0xe0
>
>Signed-off-by: Shu Wang 
>---
> drivers/scsi/megaraid/megaraid_sas_fusion.c | 6 +-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c
>b/drivers/scsi/megaraid/megaraid_sas_fusion.c
>index f990ab4d..9855106 100644
>--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
>+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
>@@ -425,7 +425,7 @@ static int megasas_create_sg_sense_fusion(struct
>megasas_instance *instance)  int  megasas_alloc_cmdlist_fusion(struct
>megasas_instance *instance)  {
>-  u32 max_mpt_cmd, i;
>+  u32 max_mpt_cmd, i, j;
>   struct fusion_context *fusion;
>
>   fusion = instance->ctrl_context;
>@@ -450,11 +450,15 @@ megasas_alloc_cmdlist_fusion(struct
>megasas_instance *instance)
>   fusion->cmd_list[i] = kzalloc(sizeof(struct
>megasas_cmd_fusion),
> GFP_KERNEL);
>   if (!fusion->cmd_list[i]) {
>+  for (j = 0; j < i; j++)
>+  kfree(fusion->cmd_list[j]);
>+  kfree(fusion->cmd_list);
>   dev_err(>pdev->dev,
>   "Failed from %s %d\n",  __func__,
__LINE__);
>   return -ENOMEM;
>   }
>   }
>+
>   return 0;
> }
> int
Acked-by: Sumit Saxena 

>--
>2.5.0


[PATCH] scsi: megaraid_sas: fix memleak in megasas_alloc_cmdlist_fusion

2017-07-21 Thread shuwang
From: Shu Wang 

Found this issue by kmemleak, a few kb mem was leaked in
megasas_alloc_cmdlist_fusion when kzalloc failed for one
megasas_cmd_fusion allocation.

unreferenced object 0x88045dbd2000 (size 8192):
  comm "systemd-udevd", pid 323, jiffies 4294671759 (age 49.008s)
  backtrace:
[] kmemleak_alloc+0x4a/0xa0
[] __kmalloc+0xe8/0x220
[] megasas_alloc_cmdlist_fusion+0x34/0xe0 [megaraid_sas]
(gdb) list *megasas_alloc_cmdlist_fusion+0x34
0xd5c4 is in megasas_alloc_cmdlist_fusion
   (drivers/scsi/megaraid/megaraid_sas_fusion.c:443).
[] megasas_alloc_cmds_fusion+0x25/0x410 [megaraid_sas]
[] megasas_init_adapter_fusion+0x21f/0x640 [megaraid_sas]
[] megasas_init_fw+0x357/0xd30 [megaraid_sas]
[] megasas_probe_one.part.33+0x636/0x1100 [megaraid_sas]
[] megasas_probe_one+0x46/0xc0 [megaraid_sas]
[] local_pci_probe+0x45/0xa0
[] pci_device_probe+0x192/0x1b0
[] driver_probe_device+0x2a8/0x460
[] __driver_attach+0xdd/0xe0
[] bus_for_each_dev+0x6c/0xc0
[] driver_attach+0x1e/0x20
[] bus_add_driver+0x45/0x270
[] driver_register+0x60/0xe0
unreferenced object 0x880454ce3600 (size 192):
  backtrace:
[] kmemleak_alloc+0x4a/0xa0
[] kmem_cache_alloc_trace+0xca/0x1d0
[] megasas_alloc_cmdlist_fusion+0x77/0xe0 [megaraid_sas]
(gdb) list *megasas_alloc_cmdlist_fusion+0x77
0xd607 is in megasas_alloc_cmdlist_fusion
(drivers/scsi/megaraid/megaraid_sas_fusion.c:450).
[] megasas_alloc_cmds_fusion+0x25/0x410 [megaraid_sas]
[] megasas_init_adapter_fusion+0x21f/0x640 [megaraid_sas]
[] megasas_init_fw+0x357/0xd30 [megaraid_sas]
[] megasas_probe_one.part.33+0x636/0x1100 [megaraid_sas]
[] megasas_probe_one+0x46/0xc0 [megaraid_sas]
[] local_pci_probe+0x45/0xa0
[] pci_device_probe+0x192/0x1b0
[] driver_probe_device+0x2a8/0x460
[] __driver_attach+0xdd/0xe0
[] bus_for_each_dev+0x6c/0xc0
[] driver_attach+0x1e/0x20
[] bus_add_driver+0x45/0x270
[] driver_register+0x60/0xe0

Signed-off-by: Shu Wang 
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index f990ab4d..9855106 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -425,7 +425,7 @@ static int megasas_create_sg_sense_fusion(struct 
megasas_instance *instance)
 int
 megasas_alloc_cmdlist_fusion(struct megasas_instance *instance)
 {
-   u32 max_mpt_cmd, i;
+   u32 max_mpt_cmd, i, j;
struct fusion_context *fusion;
 
fusion = instance->ctrl_context;
@@ -450,11 +450,15 @@ megasas_alloc_cmdlist_fusion(struct megasas_instance 
*instance)
fusion->cmd_list[i] = kzalloc(sizeof(struct megasas_cmd_fusion),
  GFP_KERNEL);
if (!fusion->cmd_list[i]) {
+   for (j = 0; j < i; j++)
+   kfree(fusion->cmd_list[j]);
+   kfree(fusion->cmd_list);
dev_err(>pdev->dev,
"Failed from %s %d\n",  __func__, __LINE__);
return -ENOMEM;
}
}
+
return 0;
 }
 int
-- 
2.5.0



Re: [BUG] lockdep splat with cpu_hotplug_lock

2017-07-21 Thread Thomas Gleixner
On Thu, 20 Jul 2017, James Bottomley wrote:
> [redirecting to linux-scsi]
> On Thu, 2017-07-20 at 19:35 -0400, Steven Rostedt wrote:
> > My tests triggered this splat on 4.13-rc1:
> > 
> > Loading iSCSI transport class v2.0-870.
> > QLogic NetXtreme II iSCSI Driver bnx2i v2.7.10.1 (Jul 16, 2014)
> > iscsi: registered transport (bnx2i)
> > 
> > 
> > WARNING: possible recursive locking detected
> > 4.13.0-rc1-test+ #2 Not tainted
> > 
> > swapper/0/1 is trying to acquire lock:
> >  (cpu_hotplug_lock.rw_sem){++}, at: []
> > __cpuhp_setup_state+0x28/0x59
> > 
> > but task is already holding lock:
> >  (cpu_hotplug_lock.rw_sem){++}, at: []
> > bnx2i_mod_init+0x134/0x209
> > 
> > other info that might help us debug this:
> >  Possible unsafe locking scenario:
> > 
> >    CPU0
> >    
> >   lock(cpu_hotplug_lock.rw_sem);
> >   lock(cpu_hotplug_lock.rw_sem);
> 
> It sounds like it's an annotation issue not an actual problem.  I've
> added the correct list, so hopefully our usual enthusiasts can take a
> look.

Nope. It's a recursive locking/\ of cpuhotplug lock. I'll have a look on
monday.

Thanks,

tglx