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

2017-02-24 Thread Andy Grover
On 02/23/2017 06:07 PM, Xiubo Li wrote:
>> Cool. This is a good approach for an initial patch but this raises
>> concerns about efficiently managing kernel memory usage -- the data area
>> grows but never shrinks, and total possible usage increases per
>> backstore. (What if there are 1000?) Any ideas how we could also improve
>> these aspects of the design? (Global TCMU data area usage limit?)
> Two ways in my mind:
> 
> The first:
> How about by setting a threshold cmd(SHRINK cmd), something likes
> the PAD cmd, to tell the userspace runner try to shrink the memories?

Why should userspace need to know if the kernel is shrinking memory
allocated to the data area? Userspace knows about memory described in
iovecs for in-flight cmds, we shouldn't need its cooperation to free
other allocated parts of the data area.

But, We likely don't want to release memory from the data area anyways
while active, in any case. How about if we set a timer when active
commands go to zero, and then reduce data area to some minimum if no new
cmds come in before timer expires?

> When the runner get the SHRINK cmd, it will try to remmap uio0's ring
> buffer(?). Then the kernel will get chance to shrink the memories
> 
> The second:
> Try to extern the data area by using /dev/uio1, we could remmap the
> uio1 device when need, so it will be easy to get a chance to shrink the
> memories in uio1.

Userspace should not need to remap the region in order for the kernel to
free and unmap pages from the region.

The only thing we need to watch out for is if blocks are referenced by
in-flight cmds, we can't free them or userspace will segfault. So, if we
wait until there are no in-flight cmds, then it follows that the kernel
can free whatever it wants and userspace will not segfault.

-- Andy



[PATCH v3 07/14] qla2xxx: Export DIF stats via debugfs

2017-02-24 Thread Himanshu Madhani
From: Anil Gurumurthy 

Signed-off-by: Anil Gurumurthy 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h | 12 
 drivers/scsi/qla2xxx/qla_dfs.c | 15 +++
 2 files changed, 27 insertions(+)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 1fcd829..5e2f149 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3112,6 +3112,16 @@ struct qla_chip_state_84xx {
uint32_t gold_fw_version;
 };
 
+struct qla_dif_statistics {
+   uint64_t dif_input_bytes;
+   uint64_t dif_output_bytes;
+   uint64_t dif_input_requests;
+   uint64_t dif_output_requests;
+   uint32_t dif_guard_err;
+   uint32_t dif_ref_tag_err;
+   uint32_t dif_app_tag_err;
+};
+
 struct qla_statistics {
uint32_t total_isp_aborts;
uint64_t input_bytes;
@@ -3124,6 +3134,8 @@ struct qla_statistics {
uint32_t stat_max_pend_cmds;
uint32_t stat_max_qfull_cmds_alloc;
uint32_t stat_max_qfull_cmds_dropped;
+
+   struct qla_dif_statistics qla_dif_stats;
 };
 
 struct bidi_statistics {
diff --git a/drivers/scsi/qla2xxx/qla_dfs.c b/drivers/scsi/qla2xxx/qla_dfs.c
index dabeb8b..0252c2f 100644
--- a/drivers/scsi/qla2xxx/qla_dfs.c
+++ b/drivers/scsi/qla2xxx/qla_dfs.c
@@ -185,6 +185,21 @@
seq_printf(s, "num Q full sent = %lld\n",
vha->tgt_counters.num_q_full_sent);
 
+   /* DIF stats */
+   seq_printf(s, "DIF Inp Bytes = %lld\n",
+   vha->qla_stats.qla_dif_stats.dif_input_bytes);
+   seq_printf(s, "DIF Outp Bytes = %lld\n",
+   vha->qla_stats.qla_dif_stats.dif_output_bytes);
+   seq_printf(s, "DIF Inp Req = %lld\n",
+   vha->qla_stats.qla_dif_stats.dif_input_requests);
+   seq_printf(s, "DIF Outp Req = %lld\n",
+   vha->qla_stats.qla_dif_stats.dif_output_requests);
+   seq_printf(s, "DIF Guard err = %d\n",
+   vha->qla_stats.qla_dif_stats.dif_guard_err);
+   seq_printf(s, "DIF Ref tag err = %d\n",
+   vha->qla_stats.qla_dif_stats.dif_ref_tag_err);
+   seq_printf(s, "DIF App tag err = %d\n",
+   vha->qla_stats.qla_dif_stats.dif_app_tag_err);
return 0;
 }
 
-- 
1.8.3.1



[PATCH v3 08/14] qla2xxx: Change scsi host lookup method.

2017-02-24 Thread Himanshu Madhani
From: Quinn Tran 

For target mode, when new scsi command arrive, driver first performs
a look up of the SCSI Host. The current look up method is based on
the ALPA portion of the NPort ID. For Cisco switch, the ALPA can
not be used as the index. Instead, the new search method is based
on the full value of the Nport_ID via btree lib.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/Kconfig  |  1 +
 drivers/scsi/qla2xxx/qla_def.h|  2 +
 drivers/scsi/qla2xxx/qla_gbl.h|  2 +
 drivers/scsi/qla2xxx/qla_init.c   | 14 +++---
 drivers/scsi/qla2xxx/qla_mbx.c| 28 
 drivers/scsi/qla2xxx/qla_os.c |  1 +
 drivers/scsi/qla2xxx/qla_target.c | 92 +--
 7 files changed, 100 insertions(+), 40 deletions(-)

diff --git a/drivers/scsi/qla2xxx/Kconfig b/drivers/scsi/qla2xxx/Kconfig
index 67c0d5a..de95293 100644
--- a/drivers/scsi/qla2xxx/Kconfig
+++ b/drivers/scsi/qla2xxx/Kconfig
@@ -3,6 +3,7 @@ config SCSI_QLA_FC
depends on PCI && SCSI
depends on SCSI_FC_ATTRS
select FW_LOADER
+   select BTREE
---help---
This qla2xxx driver supports all QLogic Fibre Channel
PCI and PCIe host adapters.
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 5e2f149..f775b6b 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -3301,6 +3302,7 @@ struct qlt_hw_data {
spinlock_t sess_lock;
int rspq_vector_cpuid;
spinlock_t atio_lock cacheline_aligned;
+   struct btree_head32 host_map;
 };
 
 #define MAX_QFULL_CMDS_ALLOC   8192
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index 3cdeb0e..b5e96b7 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -854,5 +854,7 @@ extern struct fc_port 
*qlt_find_sess_invalidate_other(scsi_qla_host_t *,
uint64_t wwn, port_id_t port_id, uint16_t loop_id, struct fc_port **);
 void qla24xx_delete_sess_fn(struct work_struct *);
 void qlt_unknown_atio_work_fn(struct work_struct *);
+void qlt_update_host_map(struct scsi_qla_host *, port_id_t);
+void qlt_remove_target_resources(struct qla_hw_data *);
 
 #endif /* _QLA_GBL_H */
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 5b1108b..c3ab96c 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -3341,8 +3341,8 @@ void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, 
struct event_arg *ea)
uint8_t   domain;
charconnect_type[22];
struct qla_hw_data *ha = vha->hw;
-   unsigned long flags;
scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
+   port_id_t id;
 
/* Get host addresses. */
rval = qla2x00_get_adapter_id(vha,
@@ -3420,13 +3420,11 @@ void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, 
struct event_arg *ea)
 
/* Save Host port and loop ID. */
/* byte order - Big Endian */
-   vha->d_id.b.domain = domain;
-   vha->d_id.b.area = area;
-   vha->d_id.b.al_pa = al_pa;
-
-   spin_lock_irqsave(>vport_slock, flags);
-   qlt_update_vp_map(vha, SET_AL_PA);
-   spin_unlock_irqrestore(>vport_slock, flags);
+   id.b.domain = domain;
+   id.b.area = area;
+   id.b.al_pa = al_pa;
+   id.b.rsvd_1 = 0;
+   qlt_update_host_map(vha, id);
 
if (!vha->flags.init_done)
ql_log(ql_log_info, vha, 0x2010,
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 0a01730..a113ab3 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -3623,6 +3623,7 @@ struct tsk_mgmt_cmd {
scsi_qla_host_t *vp = NULL;
unsigned long   flags;
int found;
+   port_id_t id;
 
ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
"Entered %s.\n", __func__);
@@ -3630,6 +3631,11 @@ struct tsk_mgmt_cmd {
if (rptid_entry->entry_status != 0)
return;
 
+   id.b.domain = rptid_entry->port_id[2];
+   id.b.area   = rptid_entry->port_id[1];
+   id.b.al_pa  = rptid_entry->port_id[0];
+   id.b.rsvd_1 = 0;
+
if (rptid_entry->format == 0) {
/* loop */
ql_dbg(ql_dbg_async, vha, 0x10b7,
@@ -3641,13 +3647,7 @@ struct tsk_mgmt_cmd {
rptid_entry->port_id[2], rptid_entry->port_id[1],
rptid_entry->port_id[0]);
 
-   vha->d_id.b.domain = rptid_entry->port_id[2];
-   vha->d_id.b.area = rptid_entry->port_id[1];
-   vha->d_id.b.al_pa = rptid_entry->port_id[0];
-
-   spin_lock_irqsave(>vport_slock, flags);
-   qlt_update_vp_map(vha, SET_AL_PA);
-   

[PATCH v3 14/14] qla2xxx: Update driver version to 9.00.00.00-k

2017-02-24 Thread Himanshu Madhani
Signed-off-by: Himanshu Madhani 
signed-off-by: Giridhar Malavali 
---
 drivers/scsi/qla2xxx/qla_version.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_version.h 
b/drivers/scsi/qla2xxx/qla_version.h
index 3cb1964..45bc84e 100644
--- a/drivers/scsi/qla2xxx/qla_version.h
+++ b/drivers/scsi/qla2xxx/qla_version.h
@@ -7,9 +7,9 @@
 /*
  * Driver version
  */
-#define QLA2XXX_VERSION  "8.07.00.38-k"
+#define QLA2XXX_VERSION  "9.00.00.00-k"
 
-#define QLA_DRIVER_MAJOR_VER   8
-#define QLA_DRIVER_MINOR_VER   7
+#define QLA_DRIVER_MAJOR_VER   9
+#define QLA_DRIVER_MINOR_VER   0
 #define QLA_DRIVER_PATCH_VER   0
 #define QLA_DRIVER_BETA_VER0
-- 
1.8.3.1



[PATCH v3 04/14] qla2xxx: Use IOCB interface to submit non-critical MBX.

2017-02-24 Thread Himanshu Madhani
From: Quinn Tran 

The Mailbox interface is currently over subscribed. We like
to reserve the Mailbox interface for the chip managment and
link initialization. Any non essential Mailbox command will
be routed through the IOCB interface. The IOCB interface is
able to absorb more commands.

Following commands are being routed through IOCB interface

- Get ID List (007Ch)
- Get Port DB (0064h)
- Get Link Priv Stats (006Dh)

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h|  10 +-
 drivers/scsi/qla2xxx/qla_gbl.h|  10 +-
 drivers/scsi/qla2xxx/qla_init.c   |  46 +--
 drivers/scsi/qla2xxx/qla_isr.c|   2 +-
 drivers/scsi/qla2xxx/qla_mbx.c| 270 --
 drivers/scsi/qla2xxx/qla_target.c |   4 +-
 6 files changed, 277 insertions(+), 65 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index e337020..111861c 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -395,11 +395,15 @@ struct srb_iocb {
struct completion comp;
} abt;
struct ct_arg ctarg;
+#define MAX_IOCB_MB_REG 28
+#define SIZEOF_IOCB_MB_REG (MAX_IOCB_MB_REG * sizeof(uint16_t))
struct {
-   __le16 in_mb[28];   /* fr fw */
-   __le16 out_mb[28];  /* to fw */
+   __le16 in_mb[MAX_IOCB_MB_REG];  /* from FW */
+   __le16 out_mb[MAX_IOCB_MB_REG]; /* to FW */
void *out, *in;
dma_addr_t out_dma, in_dma;
+   struct completion comp;
+   int rc;
} mbx;
struct {
struct imm_ntfy_from_isp *ntfy;
@@ -437,7 +441,7 @@ struct srb_iocb {
uint32_t handle;
uint16_t flags;
uint16_t type;
-   char *name;
+   const char *name;
int iocbs;
struct qla_qpair *qpair;
u32 gen1;   /* scratch */
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index b3d6441..3cdeb0e 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -193,6 +193,7 @@ extern struct scsi_qla_host *qla2x00_create_host(struct 
scsi_host_template *,
 void qla2x00_handle_login_done_event(struct scsi_qla_host *, fc_port_t *,
uint16_t *);
 int qla24xx_post_gnl_work(struct scsi_qla_host *, fc_port_t *);
+int qla24xx_async_abort_cmd(srb_t *);
 
 /*
  * Global Functions in qla_mid.c source file.
@@ -368,7 +369,7 @@ extern int qla24xx_build_scsi_crc_2_iocbs(srb_t *,
 
 extern int
 qla24xx_get_isp_stats(scsi_qla_host_t *, struct link_statistics *,
-dma_addr_t, uint);
+dma_addr_t, uint16_t);
 
 extern int qla24xx_abort_command(srb_t *);
 extern int qla24xx_async_abort_command(srb_t *);
@@ -472,6 +473,13 @@ extern int qla24xx_set_fcp_prio(scsi_qla_host_t *, 
uint16_t, uint16_t,
 extern int
 qla26xx_dport_diagnostics(scsi_qla_host_t *, void *, uint, uint);
 
+int qla24xx_send_mb_cmd(struct scsi_qla_host *, mbx_cmd_t *);
+int qla24xx_gpdb_wait(struct scsi_qla_host *, fc_port_t *, u8);
+int qla24xx_gidlist_wait(struct scsi_qla_host *, void *, dma_addr_t,
+uint16_t *);
+int __qla24xx_parse_gpdb(struct scsi_qla_host *, fc_port_t *,
+   struct port_database_24xx *);
+
 /*
  * Global Function Prototypes in qla_isr.c source file.
  */
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 1f94003..5b1108b 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -629,7 +629,6 @@ void qla24xx_async_gpdb_sp_done(void *s, int res)
struct srb *sp = s;
struct scsi_qla_host *vha = sp->vha;
struct qla_hw_data *ha = vha->hw;
-   uint64_t zero = 0;
struct port_database_24xx *pd;
fc_port_t *fcport = sp->fcport;
u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
@@ -649,48 +648,7 @@ void qla24xx_async_gpdb_sp_done(void *s, int res)
 
pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
 
-   /* Check for logged in state. */
-   if (pd->current_login_state != PDS_PRLI_COMPLETE &&
-   pd->last_login_state != PDS_PRLI_COMPLETE) {
-   ql_dbg(ql_dbg_mbx, vha, 0x,
-   "Unable to verify login-state (%x/%x) for "
-   "loop_id %x.\n", pd->current_login_state,
-   pd->last_login_state, fcport->loop_id);
-   rval = QLA_FUNCTION_FAILED;
-   goto gpd_error_out;
-   }
-
-   if (fcport->loop_id == FC_NO_LOOP_ID ||
-   (memcmp(fcport->port_name, (uint8_t *), 8) &&
-   memcmp(fcport->port_name, pd->port_name, 8))) {
-   /* We lost the device mid way. */
-   rval = QLA_NOT_LOGGED_IN;
-   goto gpd_error_out;
-   }

[PATCH v3 03/14] qla2xxx: Allow vref count to timeout on vport delete.

2017-02-24 Thread Himanshu Madhani
From: Joe Carnuccio 

Cc: 
Signed-off-by: Joe Carnuccio 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_attr.c |  4 +---
 drivers/scsi/qla2xxx/qla_def.h  |  6 +-
 drivers/scsi/qla2xxx/qla_init.c |  1 +
 drivers/scsi/qla2xxx/qla_mid.c  | 14 --
 drivers/scsi/qla2xxx/qla_os.c   |  1 +
 5 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index f610103..435ff7f 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -2154,8 +2154,6 @@ struct device_attribute *qla2x00_host_attrs[] = {
"Timer for the VP[%d] has stopped\n", vha->vp_idx);
}
 
-   BUG_ON(atomic_read(>vref_count));
-
qla2x00_free_fcports(vha);
 
mutex_lock(>vport_lock);
@@ -2166,7 +2164,7 @@ struct device_attribute *qla2x00_host_attrs[] = {
dma_free_coherent(>pdev->dev, vha->gnl.size, vha->gnl.l,
vha->gnl.ldma);
 
-   if (vha->qpair->vp_idx == vha->vp_idx) {
+   if (vha->qpair && vha->qpair->vp_idx == vha->vp_idx) {
if (qla2xxx_delete_qpair(vha, vha->qpair) != QLA_SUCCESS)
ql_log(ql_log_warn, vha, 0x7087,
"Queue Pair delete failed.\n");
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index fea4b79..e337020 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -4086,6 +4086,7 @@ struct qla_tgt_counters {
/* Count of active session/fcport */
int fcport_count;
wait_queue_head_t fcport_waitQ;
+   wait_queue_head_t vref_waitq;
 } scsi_qla_host_t;
 
 struct qla27xx_image_status {
@@ -4141,14 +4142,17 @@ struct qla2_sgx {
mb();   \
if (__vha->flags.delete_progress) { \
atomic_dec(&__vha->vref_count); \
+   wake_up(&__vha->vref_waitq);\
__bail = 1; \
} else {\
__bail = 0; \
}   \
 } while (0)
 
-#define QLA_VHA_MARK_NOT_BUSY(__vha)   \
+#define QLA_VHA_MARK_NOT_BUSY(__vha) do {  \
atomic_dec(&__vha->vref_count); \
+   wake_up(&__vha->vref_waitq);\
+} while (0)\
 
 #define QLA_QPAIR_MARK_BUSY(__qpair, __bail) do {  \
atomic_inc(&__qpair->ref_count);\
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 08f8536..1f94003 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -5158,6 +5158,7 @@ int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
}
}
atomic_dec(>vref_count);
+   wake_up(>vref_waitq);
}
spin_unlock_irqrestore(>vport_slock, flags);
 }
diff --git a/drivers/scsi/qla2xxx/qla_mid.c b/drivers/scsi/qla2xxx/qla_mid.c
index c6d6f0d..09a490c 100644
--- a/drivers/scsi/qla2xxx/qla_mid.c
+++ b/drivers/scsi/qla2xxx/qla_mid.c
@@ -74,13 +74,14 @@
 * ensures no active vp_list traversal while the vport is removed
 * from the queue)
 */
-   spin_lock_irqsave(>vport_slock, flags);
-   while (atomic_read(>vref_count)) {
-   spin_unlock_irqrestore(>vport_slock, flags);
-
-   msleep(500);
+   wait_event_timeout(vha->vref_waitq, atomic_read(>vref_count),
+   10*HZ);
 
-   spin_lock_irqsave(>vport_slock, flags);
+   spin_lock_irqsave(>vport_slock, flags);
+   if (atomic_read(>vref_count)) {
+   ql_dbg(ql_dbg_vport, vha, 0xfffa,
+   "vha->vref_count=%u timeout\n", vha->vref_count.counter);
+   vha->vref_count = (atomic_t)ATOMIC_INIT(0);
}
list_del(>list);
qlt_update_vp_map(vha, RESET_VP_IDX);
@@ -269,6 +270,7 @@
 
spin_lock_irqsave(>vport_slock, flags);
atomic_dec(>vref_count);
+   wake_up(>vref_waitq);
}
i++;
}
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 312972b..4867589 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -4288,6 +4288,7 @@ struct scsi_qla_host *qla2x00_create_host(struct 
scsi_host_template *sht,
spin_lock_init(>work_lock);
spin_lock_init(>cmd_list_lock);
init_waitqueue_head(>fcport_waitQ);
+   init_waitqueue_head(>vref_waitq);
 
vha->gnl.size = sizeof(struct get_name_list_extended) *
(ha->max_loop_id + 1);
-- 

[PATCH v3 09/14] qla2xxx: Fix memory leak for abts processing

2017-02-24 Thread Himanshu Madhani
From: Quinn Tran 

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

diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index 2720b8f6..a09e4a5 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -6766,6 +6766,8 @@ static void qlt_disable_vha(struct scsi_qla_host *vha)
spin_lock_irqsave(>hardware_lock, flags);
qlt_response_pkt_all_vps(vha, (response_t *)>atio);
spin_unlock_irqrestore(>hardware_lock, flags);
+
+   kfree(op);
 }
 
 void
-- 
1.8.3.1



[PATCH v3 02/14] qla2xxx: Allow relogin to proceed if remote login did not finish

2017-02-24 Thread Himanshu Madhani
From: Quinn Tran 

If the remote port have started the login process, then the
PLOGI and PRLI should be back to back. Driver will allow
the remote port to complete the process. For the case where
the remote port decide to back off from sending PRLI, this
local port sets an expiration timer for the PRLI. Once the
expiration time passes, the relogin retry logic is allowed
to go through and perform login with the remote port.

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

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index c264ced..fea4b79 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -2300,6 +2300,8 @@ enum rscn_addr_format {
struct ct_sns_desc ct_desc;
enum discovery_state disc_state;
enum login_state fw_login_state;
+   unsigned long plogi_nack_done_deadline;
+
u32 login_gen, last_login_gen;
u32 rscn_gen, last_rscn_gen;
u32 chip_reset;
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 6b0ec11..08f8536 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -876,10 +876,14 @@ int qla24xx_fcport_handle_login(struct scsi_qla_host 
*vha, fc_port_t *fcport)
fcport->login_retry--;
 
if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
-   (fcport->fw_login_state == DSC_LS_PLOGI_COMP) ||
(fcport->fw_login_state == DSC_LS_PRLI_PEND))
return 0;
 
+   if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
+   if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline))
+   return 0;
+   }
+
/* for pure Target Mode. Login will not be initiated */
if (vha->host->active_mode == MODE_TARGET)
return 0;
@@ -1041,10 +1045,14 @@ void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
fcport->flags);
 
if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
-   (fcport->fw_login_state == DSC_LS_PLOGI_COMP) ||
(fcport->fw_login_state == DSC_LS_PRLI_PEND))
return;
 
+   if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
+   if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline))
+   return;
+   }
+
if (fcport->flags & FCF_ASYNC_SENT) {
fcport->login_retry++;
set_bit(RELOGIN_NEEDED, >dpc_flags);
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index a5faf37..dd4d76c 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -1632,9 +1632,9 @@ static void qla2x00_error_entry(scsi_qla_host_t *, struct 
rsp_que *,
QLA_LOGIO_LOGIN_RETRIED : 0;
if (logio->entry_status) {
ql_log(ql_log_warn, fcport->vha, 0x5034,
-   "Async-%s error entry - hdl=%x"
+   "Async-%s error entry - %8phC hdl=%x"
"portid=%02x%02x%02x entry-status=%x.\n",
-   type, sp->handle, fcport->d_id.b.domain,
+   type, fcport->port_name, sp->handle, fcport->d_id.b.domain,
fcport->d_id.b.area, fcport->d_id.b.al_pa,
logio->entry_status);
ql_dump_buffer(ql_dbg_async + ql_dbg_buffer, vha, 0x504d,
@@ -1645,8 +1645,9 @@ static void qla2x00_error_entry(scsi_qla_host_t *, struct 
rsp_que *,
 
if (le16_to_cpu(logio->comp_status) == CS_COMPLETE) {
ql_dbg(ql_dbg_async, fcport->vha, 0x5036,
-   "Async-%s complete - hdl=%x portid=%02x%02x%02x "
-   "iop0=%x.\n", type, sp->handle, fcport->d_id.b.domain,
+   "Async-%s complete - %8phC hdl=%x portid=%02x%02x%02x "
+   "iop0=%x.\n", type, fcport->port_name, sp->handle,
+   fcport->d_id.b.domain,
fcport->d_id.b.area, fcport->d_id.b.al_pa,
le32_to_cpu(logio->io_parameter[0]));
 
@@ -1686,6 +1687,17 @@ static void qla2x00_error_entry(scsi_qla_host_t *, 
struct rsp_que *,
case LSC_SCODE_NPORT_USED:
data[0] = MBS_LOOP_ID_USED;
break;
+   case LSC_SCODE_CMD_FAILED:
+   if (iop[1] == 0x0606) {
+   /*
+* PLOGI/PRLI Completed. We must have Recv PLOGI/PRLI,
+* Target side acked.
+*/
+   data[0] = MBS_COMMAND_COMPLETE;
+   goto logio_done;
+   }
+   data[0] = MBS_COMMAND_ERROR;
+

[PATCH v3 11/14] qla2xxx: Fix inadequate lock protection for ABTS.

2017-02-24 Thread Himanshu Madhani
From: Quinn Tran 

Normally, ABTS is sent to Target Core as Task MGMT command.
In the case of error, qla2xxx needs to send response, hardware_lock
is required to prevent request queue corruption.

Cc: 
Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_target.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index b5864e5..b751eb6 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -130,6 +130,9 @@ static void qlt_send_term_imm_notif(struct scsi_qla_host 
*vha,
 static struct fc_port *qlt_create_sess(struct scsi_qla_host *vha,
fc_port_t *fcport, bool local);
 void qlt_unreg_sess(struct fc_port *sess);
+static void qlt_24xx_handle_abts(struct scsi_qla_host *,
+   struct abts_recv_from_24xx *);
+
 /*
  * Global Variables
  */
@@ -405,6 +408,8 @@ static bool qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host 
*vha,
(struct abts_recv_from_24xx *)atio;
struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
entry->vp_index);
+   unsigned long flags;
+
if (unlikely(!host)) {
ql_dbg(ql_dbg_tgt, vha, 0x,
"qla_target(%d): Response pkt (ABTS_RECV_24XX) "
@@ -412,9 +417,12 @@ static bool qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host 
*vha,
vha->vp_idx, entry->vp_index);
break;
}
-   qlt_response_pkt(host, (response_t *)atio);
+   if (!ha_locked)
+   spin_lock_irqsave(>hw->hardware_lock, flags);
+   qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio);
+   if (!ha_locked)
+   spin_unlock_irqrestore(>hw->hardware_lock, flags);
break;
-
}
 
/* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */
-- 
1.8.3.1



[PATCH v3 12/14] qla2xxx: Add async new target notification

2017-02-24 Thread Himanshu Madhani
From: Quinn Tran 

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

diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index b751eb6..e523c49 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -6011,13 +6011,13 @@ int qlt_add_target(struct qla_hw_data *ha, struct 
scsi_qla_host *base_vha)
tgt->datasegs_per_cmd = QLA_TGT_DATASEGS_PER_CMD_24XX;
tgt->datasegs_per_cont = QLA_TGT_DATASEGS_PER_CONT_24XX;
 
-   if (base_vha->fc_vport)
-   return 0;
-
mutex_lock(_tgt_mutex);
list_add_tail(>tgt_list_entry, _tgt_glist);
mutex_unlock(_tgt_mutex);
 
+   if (ha->tgt.tgt_ops && ha->tgt.tgt_ops->add_target)
+   ha->tgt.tgt_ops->add_target(base_vha);
+
return 0;
 }
 
diff --git a/drivers/scsi/qla2xxx/qla_target.h 
b/drivers/scsi/qla2xxx/qla_target.h
index c73c938..26fa6a4 100644
--- a/drivers/scsi/qla2xxx/qla_target.h
+++ b/drivers/scsi/qla2xxx/qla_target.h
@@ -693,6 +693,7 @@ struct qla_tgt_func_tmpl {
void (*shutdown_sess)(struct fc_port *);
int (*get_dif_tags)(struct qla_tgt_cmd *cmd, uint16_t *pfw_prot_opts);
int (*chk_dif_tags)(uint32_t tag);
+   void (*add_target)(struct scsi_qla_host *);
 };
 
 int qla2x00_wait_for_hba_online(struct scsi_qla_host *);
-- 
1.8.3.1



[PATCH v3 06/14] qla2xxx: Improve T10-DIF/PI handling in driver.

2017-02-24 Thread Himanshu Madhani
From: Quinn Tran 

Add routines to support T10 DIF tag.

Signed-off-by: Quinn Tran 
Signed-off-by: Anil Gurumurthy 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_dbg.h |   1 +
 drivers/scsi/qla2xxx/qla_dfs.c |   8 +
 drivers/scsi/qla2xxx/qla_target.c  | 521 ++---
 drivers/scsi/qla2xxx/qla_target.h  |  35 ++-
 drivers/scsi/qla2xxx/tcm_qla2xxx.c |  49 ++--
 5 files changed, 377 insertions(+), 237 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_dbg.h b/drivers/scsi/qla2xxx/qla_dbg.h
index e1fc4e6..c6bffe9 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.h
+++ b/drivers/scsi/qla2xxx/qla_dbg.h
@@ -348,6 +348,7 @@ void __attribute__((format (printf, 4, 5)))
 #define ql_dbg_tgt 0x4000 /* Target mode */
 #define ql_dbg_tgt_mgt 0x2000 /* Target mode management */
 #define ql_dbg_tgt_tmr 0x1000 /* Target mode task management */
+#define ql_dbg_tgt_dif  0x0800 /* Target mode dif */
 
 extern int qla27xx_dump_mpi_ram(struct qla_hw_data *, uint32_t, uint32_t *,
uint32_t, void **);
diff --git a/drivers/scsi/qla2xxx/qla_dfs.c b/drivers/scsi/qla2xxx/qla_dfs.c
index 0fb33e6..dabeb8b 100644
--- a/drivers/scsi/qla2xxx/qla_dfs.c
+++ b/drivers/scsi/qla2xxx/qla_dfs.c
@@ -360,6 +360,14 @@
goto out;
}
 
+   ha->tgt.dfs_tgt_port_database = debugfs_create_file("tgt_port_database",
+   S_IRUSR,  ha->dfs_dir, vha, _tgt_port_database_ops);
+   if (!ha->tgt.dfs_tgt_port_database) {
+   ql_log(ql_log_warn, vha, 0x,
+   "Unable to create debugFS tgt_port_database node.\n");
+   goto out;
+   }
+
ha->dfs_fce = debugfs_create_file("fce", S_IRUSR, ha->dfs_dir, vha,
_fce_ops);
if (!ha->dfs_fce) {
diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index 6b60765b5..873cbf7 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -140,6 +140,20 @@ static struct fc_port *qlt_create_sess(struct 
scsi_qla_host *vha,
 static DEFINE_MUTEX(qla_tgt_mutex);
 static LIST_HEAD(qla_tgt_glist);
 
+static const char *prot_op_str(u32 prot_op)
+{
+   switch (prot_op) {
+   case TARGET_PROT_NORMAL:return "NORMAL";
+   case TARGET_PROT_DIN_INSERT:return "DIN_INSERT";
+   case TARGET_PROT_DOUT_INSERT:   return "DOUT_INSERT";
+   case TARGET_PROT_DIN_STRIP: return "DIN_STRIP";
+   case TARGET_PROT_DOUT_STRIP:return "DOUT_STRIP";
+   case TARGET_PROT_DIN_PASS:  return "DIN_PASS";
+   case TARGET_PROT_DOUT_PASS: return "DOUT_PASS";
+   default:return "UNKNOWN";
+   }
+}
+
 /* This API intentionally takes dest as a parameter, rather than returning
  * int value to avoid caller forgetting to issue wmb() after the store */
 void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest)
@@ -2018,6 +2032,71 @@ void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd)
 }
 EXPORT_SYMBOL(qlt_free_mcmd);
 
+/*
+ * ha->hardware_lock supposed to be held on entry. Might drop it, then
+ * reacquire
+ */
+void qlt_send_resp_ctio(scsi_qla_host_t *vha, struct qla_tgt_cmd *cmd,
+uint8_t scsi_status, uint8_t sense_key, uint8_t asc, uint8_t ascq)
+{
+   struct atio_from_isp *atio = >atio;
+   struct ctio7_to_24xx *ctio;
+   uint16_t temp;
+
+   ql_dbg(ql_dbg_tgt_dif, vha, 0x3066,
+   "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, "
+   "sense_key=%02x, asc=%02x, ascq=%02x",
+   vha, atio, scsi_status, sense_key, asc, ascq);
+
+   ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(vha, NULL);
+   if (!ctio) {
+   ql_dbg(ql_dbg_async, vha, 0x3067,
+   "qla2x00t(%ld): %s failed: unable to allocate request 
packet",
+   vha->host_no, __func__);
+   goto out;
+   }
+
+   ctio->entry_type = CTIO_TYPE7;
+   ctio->entry_count = 1;
+   ctio->handle = QLA_TGT_SKIP_HANDLE;
+   ctio->nport_handle = cmd->sess->loop_id;
+   ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
+   ctio->vp_index = vha->vp_idx;
+   ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2];
+   ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1];
+   ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0];
+   ctio->exchange_addr = atio->u.isp24.exchange_addr;
+   ctio->u.status1.flags = (atio->u.isp24.attr << 9) |
+   cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS);
+   temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
+   ctio->u.status1.ox_id = cpu_to_le16(temp);
+   ctio->u.status1.scsi_status =
+   cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID | scsi_status);
+   ctio->u.status1.response_len = cpu_to_le16(18);
+   ctio->u.status1.residual = 

[PATCH v3 05/14] qla2xxx: Add DebugFS node to display Port Database

2017-02-24 Thread Himanshu Madhani
Signed-off-by: Himanshu Madhani 
Signed-off-by: Giridhar Malavali 
---
 drivers/scsi/qla2xxx/qla_def.h |  2 +
 drivers/scsi/qla2xxx/qla_dfs.c | 92 --
 2 files changed, 90 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 111861c..1fcd829 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3278,6 +3278,8 @@ struct qlt_hw_data {
uint8_t tgt_node_name[WWN_SIZE];
 
struct dentry *dfs_tgt_sess;
+   struct dentry *dfs_tgt_port_database;
+
struct list_head q_full_list;
uint32_t num_pend_cmds;
uint32_t num_qfull_cmds_alloc;
diff --git a/drivers/scsi/qla2xxx/qla_dfs.c b/drivers/scsi/qla2xxx/qla_dfs.c
index b48cce6..0fb33e6 100644
--- a/drivers/scsi/qla2xxx/qla_dfs.c
+++ b/drivers/scsi/qla2xxx/qla_dfs.c
@@ -19,11 +19,11 @@
struct qla_hw_data *ha = vha->hw;
unsigned long flags;
struct fc_port *sess = NULL;
-   struct qla_tgt *tgt= vha->vha_tgt.qla_tgt;
+   struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
 
-   seq_printf(s, "%s\n",vha->host_str);
+   seq_printf(s, "%s\n", vha->host_str);
if (tgt) {
-   seq_printf(s, "Port ID   Port NameHandle\n");
+   seq_puts(s, "Port ID   Port NameHandle\n");
 
spin_lock_irqsave(>tgt.sess_lock, flags);
list_for_each_entry(sess, >vp_fcports, list)
@@ -44,7 +44,6 @@
return single_open(file, qla2x00_dfs_tgt_sess_show, vha);
 }
 
-
 static const struct file_operations dfs_tgt_sess_ops = {
.open   = qla2x00_dfs_tgt_sess_open,
.read   = seq_read,
@@ -53,6 +52,78 @@
 };
 
 static int
+qla2x00_dfs_tgt_port_database_show(struct seq_file *s, void *unused)
+{
+   scsi_qla_host_t *vha = s->private;
+   struct qla_hw_data *ha = vha->hw;
+   struct gid_list_info *gid_list;
+   dma_addr_t gid_list_dma;
+   fc_port_t fc_port;
+   char *id_iter;
+   int rc, i;
+   uint16_t entries, loop_id;
+   struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
+
+   seq_printf(s, "%s\n", vha->host_str);
+   if (tgt) {
+   gid_list = dma_alloc_coherent(>pdev->dev,
+   qla2x00_gid_list_size(ha),
+   _list_dma, GFP_KERNEL);
+   if (!gid_list) {
+   ql_dbg(ql_dbg_user, vha, 0x705c,
+   "DMA allocation failed for %u\n",
+qla2x00_gid_list_size(ha));
+   return 0;
+   }
+
+   rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma,
+   );
+   if (rc != QLA_SUCCESS)
+   goto out_free_id_list;
+
+   id_iter = (char *)gid_list;
+
+   seq_puts(s, "Port Name  Port ID Loop ID\n");
+
+   for (i = 0; i < entries; i++) {
+   struct gid_list_info *gid =
+   (struct gid_list_info *)id_iter;
+   loop_id = le16_to_cpu(gid->loop_id);
+   memset(_port, 0, sizeof(fc_port_t));
+
+   fc_port.loop_id = loop_id;
+
+   rc = qla24xx_gpdb_wait(vha, _port, 0);
+   seq_printf(s, "%8phC  %02x%02x%02x  %d\n",
+   fc_port.port_name, fc_port.d_id.b.domain,
+   fc_port.d_id.b.area, fc_port.d_id.b.al_pa,
+   fc_port.loop_id);
+   id_iter += ha->gid_list_info_size;
+   }
+out_free_id_list:
+   dma_free_coherent(>pdev->dev, qla2x00_gid_list_size(ha),
+   gid_list, gid_list_dma);
+   }
+
+   return 0;
+}
+
+static int
+qla2x00_dfs_tgt_port_database_open(struct inode *inode, struct file *file)
+{
+   scsi_qla_host_t *vha = inode->i_private;
+
+   return single_open(file, qla2x00_dfs_tgt_port_database_show, vha);
+}
+
+static const struct file_operations dfs_tgt_port_database_ops = {
+   .open   = qla2x00_dfs_tgt_port_database_open,
+   .read   = seq_read,
+   .llseek = seq_lseek,
+   .release= single_release,
+};
+
+static int
 qla_dfs_fw_resource_cnt_show(struct seq_file *s, void *unused)
 {
struct scsi_qla_host *vha = s->private;
@@ -281,6 +352,14 @@
goto out;
}
 
+   ha->tgt.dfs_tgt_port_database = debugfs_create_file("tgt_port_database",
+   S_IRUSR,  ha->dfs_dir, vha, _tgt_port_database_ops);
+   if (!ha->tgt.dfs_tgt_port_database) {
+   ql_log(ql_log_warn, vha, 0x,
+   "Unable to create debugFS tgt_port_database node.\n");
+   goto out;
+   }
+
ha->dfs_fce = debugfs_create_file("fce", S_IRUSR, 

[PATCH v3 13/14] qla2xxx: Fix sess_lock & hardware_lock lock order problem.

2017-02-24 Thread Himanshu Madhani
From: Quinn Tran 

The main lock that needs to be held for CMD or TMR submission
to upper layer is the sess_lock. The sess_lock is used to
serialize cmd submission and session deletion. The addition
of hardware_lock being held is not necessary. This patch removes
hardware_lock dependency from CMD/TMR submission.

Use hardware_lock only for error response in this case.

Path1
   CPU0CPU1
   
  lock(&(>tgt.sess_lock)->rlock);
   lock(&(>hardware_lock)->rlock);
   lock(&(>tgt.sess_lock)->rlock);
  lock(&(>hardware_lock)->rlock);

Path2/deadlock
*** DEADLOCK ***
Call Trace:
dump_stack+0x85/0xc2
print_circular_bug+0x1e3/0x250
__lock_acquire+0x1425/0x1620
lock_acquire+0xbf/0x210
_raw_spin_lock_irqsave+0x53/0x70
qlt_sess_work_fn+0x21d/0x480 [qla2xxx]
process_one_work+0x1f4/0x6e0

Cc: 
Cc: Bart Van Assche 
Reported-by: Bart Van Assche 
Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_target.c | 41 +--
 1 file changed, 18 insertions(+), 23 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index e523c49..46a409e 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -5831,30 +5831,23 @@ static void qlt_abort_work(struct qla_tgt *tgt,
}
}
 
-   spin_lock_irqsave(>hardware_lock, flags);
-
-   if (tgt->tgt_stop)
-   goto out_term;
-
rc = __qlt_24xx_handle_abts(vha, >abts, sess);
+   ha->tgt.tgt_ops->put_sess(sess);
+   spin_unlock_irqrestore(>tgt.sess_lock, flags2);
+
if (rc != 0)
goto out_term;
-   spin_unlock_irqrestore(>hardware_lock, flags);
-   if (sess)
-   ha->tgt.tgt_ops->put_sess(sess);
-   spin_unlock_irqrestore(>tgt.sess_lock, flags2);
return;
 
 out_term2:
-   spin_lock_irqsave(>hardware_lock, flags);
+   if (sess)
+   ha->tgt.tgt_ops->put_sess(sess);
+   spin_unlock_irqrestore(>tgt.sess_lock, flags2);
 
 out_term:
+   spin_lock_irqsave(>hardware_lock, flags);
qlt_24xx_send_abts_resp(vha, >abts, FCP_TMF_REJECTED, false);
spin_unlock_irqrestore(>hardware_lock, flags);
-
-   if (sess)
-   ha->tgt.tgt_ops->put_sess(sess);
-   spin_unlock_irqrestore(>tgt.sess_lock, flags2);
 }
 
 static void qlt_tmr_work(struct qla_tgt *tgt,
@@ -5874,7 +5867,7 @@ static void qlt_tmr_work(struct qla_tgt *tgt,
spin_lock_irqsave(>tgt.sess_lock, flags);
 
if (tgt->tgt_stop)
-   goto out_term;
+   goto out_term2;
 
s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id;
sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
@@ -5886,11 +5879,11 @@ static void qlt_tmr_work(struct qla_tgt *tgt,
 
spin_lock_irqsave(>tgt.sess_lock, flags);
if (!sess)
-   goto out_term;
+   goto out_term2;
} else {
if (sess->deleted) {
sess = NULL;
-   goto out_term;
+   goto out_term2;
}
 
if (!kref_get_unless_zero(>sess_kref)) {
@@ -5898,7 +5891,7 @@ static void qlt_tmr_work(struct qla_tgt *tgt,
"%s: kref_get fail %8phC\n",
 __func__, sess->port_name);
sess = NULL;
-   goto out_term;
+   goto out_term2;
}
}
 
@@ -5908,17 +5901,19 @@ static void qlt_tmr_work(struct qla_tgt *tgt,
unpacked_lun = scsilun_to_int((struct scsi_lun *));
 
rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0);
-   if (rc != 0)
-   goto out_term;
-
ha->tgt.tgt_ops->put_sess(sess);
spin_unlock_irqrestore(>tgt.sess_lock, flags);
+
+   if (rc != 0)
+   goto out_term;
return;
 
+out_term2:
+   if (sess)
+   ha->tgt.tgt_ops->put_sess(sess);
+   spin_unlock_irqrestore(>tgt.sess_lock, flags);
 out_term:
qlt_send_term_exchange(vha, NULL, >tm_iocb2, 1, 0);
-   ha->tgt.tgt_ops->put_sess(sess);
-   spin_unlock_irqrestore(>tgt.sess_lock, flags);
 }
 
 static void qlt_sess_work_fn(struct work_struct *work)
-- 
1.8.3.1



[PATCH v3 10/14] qla2xxx: Fix request queue corruption.

2017-02-24 Thread Himanshu Madhani
From: Quinn Tran 

When FW notify driver or driver detects low FW resource,
driver tries to send out Busy SCSI Status to tell Initiator
side to back off. During the send process, the lock was not held.

Cc: 
Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_target.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index a09e4a5..b5864e5 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -5183,16 +5183,22 @@ static int __qlt_send_busy(struct scsi_qla_host *vha,
 
 static int
 qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha,
-   struct atio_from_isp *atio)
+   struct atio_from_isp *atio, bool ha_locked)
 {
struct qla_hw_data *ha = vha->hw;
uint16_t status;
+   unsigned long flags;
 
if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha))
return 0;
 
+   if (!ha_locked)
+   spin_lock_irqsave(>hardware_lock, flags);
status = temp_sam_status;
qlt_send_busy(vha, atio, status);
+   if (!ha_locked)
+   spin_unlock_irqrestore(>hardware_lock, flags);
+
return 1;
 }
 
@@ -5237,7 +5243,7 @@ static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha,
 
 
if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) {
-   rc = qlt_chk_qfull_thresh_hold(vha, atio);
+   rc = qlt_chk_qfull_thresh_hold(vha, atio, ha_locked);
if (rc != 0) {
tgt->atio_irq_cmd_count--;
return;
@@ -5360,7 +5366,7 @@ static void qlt_response_pkt(struct scsi_qla_host *vha, 
response_t *pkt)
break;
}
 
-   rc = qlt_chk_qfull_thresh_hold(vha, atio);
+   rc = qlt_chk_qfull_thresh_hold(vha, atio, true);
if (rc != 0) {
tgt->irq_cmd_count--;
return;
-- 
1.8.3.1



[PATCH v3 00/14] qla2xxx: Bug Fixes and updates for target.

2017-02-24 Thread Himanshu Madhani
Hi Nic,

Please consider this series for inclusion in target-pending.

This series contains following changes.

o Fix for the deadlock because of inconsistent lock usage reported by you.
o Added patch to submit non-critical MBX command via IOCB path.
o Improved T10-DIF/PI handling with target stack.
o Changed scsi host lookup method.
o Some minor bug fixes.

Changes from v2 --> v3

o Updated patch to use waitq instead of while loop for waiting.
o Removed duplication of Target stack definitations for T10-DIF/PI.
o In addition, addressed review comments from Bart & Christoph.

Changes from v1 -> v2

o Rebased series based on scsi-target-for-v4.11 branch.

Please apply to target-pending.

Thanks,
Himanshu 

Anil Gurumurthy (1):
  qla2xxx: Export DIF stats via debugfs

Himanshu Madhani (2):
  qla2xxx: Add DebugFS node to display Port Database
  qla2xxx: Update driver version to 9.00.00.00-k

Joe Carnuccio (1):
  qla2xxx: Allow vref count to timeout on vport delete.

Quinn Tran (10):
  qla2xxx: Fix delayed response to command for loop mode/direct connect.
  qla2xxx: Allow relogin to proceed if remote login did not finish
  qla2xxx: Use IOCB interface to submit non-critical MBX.
  qla2xxx: Improve T10-DIF/PI handling in driver.
  qla2xxx: Change scsi host lookup method.
  qla2xxx: Fix memory leak for abts processing
  qla2xxx: Fix request queue corruption.
  qla2xxx: Fix inadequate lock protection for ABTS.
  qla2xxx: Add async new target notification
  qla2xxx: Fix sess_lock & hardware_lock lock order problem.

 drivers/scsi/qla2xxx/Kconfig   |   1 +
 drivers/scsi/qla2xxx/qla_attr.c|   4 +-
 drivers/scsi/qla2xxx/qla_dbg.h |   1 +
 drivers/scsi/qla2xxx/qla_def.h |  46 ++-
 drivers/scsi/qla2xxx/qla_dfs.c | 115 +-
 drivers/scsi/qla2xxx/qla_gbl.h |  12 +-
 drivers/scsi/qla2xxx/qla_init.c|  85 ++---
 drivers/scsi/qla2xxx/qla_isr.c |  41 ++-
 drivers/scsi/qla2xxx/qla_mbx.c | 304 ++--
 drivers/scsi/qla2xxx/qla_mid.c |  14 +-
 drivers/scsi/qla2xxx/qla_os.c  |  24 +-
 drivers/scsi/qla2xxx/qla_target.c  | 729 +++--
 drivers/scsi/qla2xxx/qla_target.h  |  36 +-
 drivers/scsi/qla2xxx/qla_version.h |   6 +-
 drivers/scsi/qla2xxx/tcm_qla2xxx.c |  49 ++-
 15 files changed, 1049 insertions(+), 418 deletions(-)

-- 
1.8.3.1



[PATCH v3 01/14] qla2xxx: Fix delayed response to command for loop mode/direct connect.

2017-02-24 Thread Himanshu Madhani
From: Quinn Tran 

Current driver wait for FW to be in the ready state before
processing in-coming commands. For Arbitrated Loop or
Point-to- Point (not switch), FW Ready state can take a while.
FW will transition to ready state after all Nports have been
logged in. In the mean time, certain initiators have completed
the login and starts IO. Driver needs to start processing all
queues if FW is already started.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h| 12 ++--
 drivers/scsi/qla2xxx/qla_init.c   | 12 
 drivers/scsi/qla2xxx/qla_isr.c| 14 +-
 drivers/scsi/qla2xxx/qla_mbx.c|  6 +++---
 drivers/scsi/qla2xxx/qla_os.c | 22 +-
 drivers/scsi/qla2xxx/qla_target.c | 38 +-
 6 files changed, 84 insertions(+), 20 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 625d438..c264ced 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3290,6 +3290,10 @@ struct qlt_hw_data {
 
 #define LEAK_EXCHG_THRESH_HOLD_PERCENT 75  /* 75 percent */
 
+#define QLA_EARLY_LINKUP(_ha) \
+   ((_ha->flags.n2n_ae || _ha->flags.lip_ae) && \
+_ha->flags.fw_started && !_ha->flags.fw_init_done)
+
 /*
  * Qlogic host adapter specific data structure.
 */
@@ -3339,7 +3343,11 @@ struct qla_hw_data {
uint32_tfawwpn_enabled:1;
uint32_texlogins_enabled:1;
uint32_texchoffld_enabled:1;
-   /* 35 bits */
+
+   uint32_tlip_ae:1;
+   uint32_tn2n_ae:1;
+   uint32_tfw_started:1;
+   uint32_tfw_init_done:1;
} flags;
 
/* This spinlock is used to protect "io transactions", you must
@@ -3432,7 +3440,6 @@ struct qla_hw_data {
 #define P2P_LOOP  3
uint8_t interrupts_on;
uint32_tisp_abort_cnt;
-
 #define PCI_DEVICE_ID_QLOGIC_ISP25320x2532
 #define PCI_DEVICE_ID_QLOGIC_ISP84320x8432
 #define PCI_DEVICE_ID_QLOGIC_ISP8001   0x8001
@@ -3913,6 +3920,7 @@ struct qla_tgt_counters {
struct list_head vp_fcports;/* list of fcports */
struct list_head work_list;
spinlock_t work_lock;
+   struct work_struct iocb_work;
 
/* Commonly used flags and state information. */
struct Scsi_Host *host;
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index ac579fc..6b0ec11 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -3212,6 +3212,7 @@ void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, 
struct event_arg *ea)
} else {
ql_dbg(ql_dbg_init, vha, 0x00d3,
"Init Firmware -- success.\n");
+   ha->flags.fw_started = 1;
}
 
return (rval);
@@ -4036,6 +4037,7 @@ static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t 
*vha, nvram_t *nv)
atomic_set(>loop_state, LOOP_READY);
ql_dbg(ql_dbg_disc, vha, 0x2069,
"LOOP READY.\n");
+   ha->flags.fw_init_done = 1;
 
/*
 * Process any ATIO queue entries that came in
@@ -5526,6 +5528,11 @@ int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
if (!(IS_P3P_TYPE(ha)))
ha->isp_ops->reset_chip(vha);
 
+   ha->flags.n2n_ae = 0;
+   ha->flags.lip_ae = 0;
+   ha->current_topology = 0;
+   ha->flags.fw_started = 0;
+   ha->flags.fw_init_done = 0;
ha->chip_reset++;
 
atomic_set(>loop_down_timer, LOOP_DOWN_TIME);
@@ -6802,6 +6809,8 @@ uint8_t qla27xx_find_valid_image(struct scsi_qla_host 
*vha)
return;
if (!ha->fw_major_version)
return;
+   if (!ha->flags.fw_started)
+   return;
 
ret = qla2x00_stop_firmware(vha);
for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
@@ -6815,6 +6824,9 @@ uint8_t qla27xx_find_valid_image(struct scsi_qla_host 
*vha)
"Attempting retry of stop-firmware command.\n");
ret = qla2x00_stop_firmware(vha);
}
+
+   ha->flags.fw_started = 0;
+   ha->flags.fw_init_done = 0;
 }
 
 int
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 352cfb6..a5faf37 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -708,6 +708,8 @@ static void qla2x00_error_entry(scsi_qla_host_t *, struct 
rsp_que *,
"mbx7=%xh.\n", mb[1], mb[2], mb[3], mbx);
 
ha->isp_ops->fw_dump(vha, 1);
+   ha->flags.fw_init_done = 0;
+   ha->flags.fw_started = 0;
 
if (IS_FWI2_CAPABLE(ha)) 

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

2017-02-24 Thread Guilherme G. Piccoli
On 02/23/2017 07:25 PM, Chris Leech wrote:
> Yikes, my git-send-email settings suppressed the important CCs.  Sorry!
> 
> Guilherme and Ilkka, can you comment about your testing results or review 
> please?

Hi Chris, thanks for looping me. Patch seems nice, I do have some points
below, most nitpicks heheh
Feel free to accept or not the suggestions!

Also, you can add my:

Reviewed-by: Guilherme G. Piccoli 


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

Perhaps worth to follow the checkpatch "rule" of citing commits here?
659743b02c41 ("[SCSI] libiscsi: Reduce locking contention in fast path")


>> Depending on iSCSI target behavior, it's possible to hit the case in
>> iscsi_complete_task where the task is still on a pending list
>> (!list_empty(>running)).  When that happens the task is removed
>> from the list while holding the session back_lock, but other task list
>> modification occur under the frwd_lock.  That leads to linked list
>> corruption and eventually a panicked system.
>>
>> Rather than back out the session lock split entirely, in order to try
>> and keep some of the performance gains this patch adds another lock to
>> maintain the task lists integrity.
>>
>> Major enterprise supported kernels have been backing out the lock split
>> for while now, thanks to the efforts at IBM where a lab setup has the
>> most reliable reproducer I've seen on this issue.  This patch has been
>> tested there successfully.
>>
>> Signed-off-by: Chris Leech 

Guess we're missing here:

(a) Fixes: 659743b02c41 ("[SCSI] libiscsi: Reduce locking contention in
fast path")

(b) CC:  #v3.15+

Also, would be nice to point the original reporter, if possible:

Reported-by: Prashantha Subbarao 


>> ---
>>  drivers/scsi/libiscsi.c | 26 +-
>>  include/scsi/libiscsi.h |  1 +
>>  2 files changed, 26 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
>> index 834d121..acb5ef3 100644
>> --- a/drivers/scsi/libiscsi.c
>> +++ b/drivers/scsi/libiscsi.c
>> @@ -560,8 +560,12 @@ static void iscsi_complete_task(struct iscsi_task *task,
>> int state)
>>  WARN_ON_ONCE(task->state == ISCSI_TASK_FREE);
>>  task->state = state;
>>  
>> -if (!list_empty(>running))
>> +spin_lock_bh(>taskqueuelock);
>> +if (!list_empty(>running)) {
>> +WARN_ONCE(1, "iscsi_complete_task while task on list");

I'm retesting this patch right now, and again I saw this giant warning.
Perhaps worth to make it pr_debug()? So, it can be enabled as user
desire and don't alarm all users too much.

Thanks,


Guilherme


>>  list_del_init(>running);
>> +}
>> +spin_unlock_bh(>taskqueuelock);
>>  
>>  if (conn->task == task)
>>  conn->task = NULL;
>> @@ -783,7 +787,9 @@ __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct
>> iscsi_hdr *hdr,
>>  if (session->tt->xmit_task(task))
>>  goto free_task;
>>  } else {
>> +spin_lock_bh(>taskqueuelock);
>>  list_add_tail(>running, >mgmtqueue);
>> +spin_unlock_bh(>taskqueuelock);
>>  iscsi_conn_queue_work(conn);
>>  }
>>  
>> @@ -1474,8 +1480,10 @@ void iscsi_requeue_task(struct iscsi_task *task)
>>   * this may be on the requeue list already if the xmit_task callout
>>   * is handling the r2ts while we are adding new ones
>>   */
>> +spin_lock_bh(>taskqueuelock);
>>  if (list_empty(>running))
>>  list_add_tail(>running, >requeue);
>> +spin_unlock_bh(>taskqueuelock);
>>  iscsi_conn_queue_work(conn);
>>  }
>>  EXPORT_SYMBOL_GPL(iscsi_requeue_task);
>> @@ -1512,22 +1520,26 @@ static int iscsi_data_xmit(struct iscsi_conn *conn)
>>   * only have one nop-out as a ping from us and targets should not
>>   * overflow us with nop-ins
>>   */
>> +spin_lock_bh(>taskqueuelock);
>>  check_mgmt:
>>  while (!list_empty(>mgmtqueue)) {
>>  conn->task = list_entry(conn->mgmtqueue.next,
>>   struct iscsi_task, running);
>>  list_del_init(>task->running);
>> +spin_unlock_bh(>taskqueuelock);
>>  if (iscsi_prep_mgmt_task(conn, conn->task)) {
>>  /* regular RX path uses back_lock */
>>  spin_lock_bh(>session->back_lock);
>>  __iscsi_put_task(conn->task);
>>  spin_unlock_bh(>session->back_lock);
>>  conn->task = NULL;
>> +spin_lock_bh(>taskqueuelock);
>>  continue;
>>  }
>>  rc = iscsi_xmit_task(conn);
>>  if (rc)
>>  goto done;
>> +spin_lock_bh(>taskqueuelock);
>>  }
>>  
>>  /* 

Kernel crash with 4.10 trying to remove scsi disks

2017-02-24 Thread Farhan Ali

Hello,

I have noticed a kernel crash with 4.10 kernel in our s390 environment, 
running a test trying to remove scsi disks. Here is a snippet of the 
kernel crash message:


[29448.452771] kernfs: can not remove 'node_name', no directory
[29448.452795] [ cut here ]
[29448.452801] WARNING: CPU: 24 PID: 197099 at ../fs/kernfs/dir.c:1406 
kernfs_remove_by_name_ns+0xb4/0xc0
[29448.452802] Modules linked in: ghash_s390 prng dm_service_time 
xt_CHECKSUM iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 
iptable_nat nf_nat_ipv4 nf_nat libcrc32c crc32_vx_s390 nf_conntrack_ipv4 
nf_defrag_ipv4 xt_conntrack nf_conntrack ipt_REJECT nf_reject_ipv4 
bridge stp llc ebtable_filter ebtables ip6table_filter ip6_tables 
iptable_filter aes_s390 des_s390 des_generic sha512_s390 sha256_s390 
sha1_s390 sha_common qeth_l2 eadm_sch qeth tape_3590 tape ccwgroup 
tape_class nfsd auth_rpcgss oid_registry nfs_acl lockd sch_fq_codel 
grace vhost_net vhost sunrpc macvtap macvlan dm_multipath ip_tables
[29448.452825] CPU: 24 PID: 197099 Comm: kworker/24:3 Tainted: G W 
4.10.0-20170222.0.f20083a.b83d822.fc24.s390xkvm #1
[29448.452826] Hardware name: IBM  2964 NC9  704 
 (LPAR)

[29448.452830] Workqueue: fc_wq_5 fc_starget_delete
[29448.452832] task: 00012f1d8000 task.stack: 0003b31e8000
[29448.452833] Krnl PSW : 0704e0018000 003bf3ac 
(kernfs_remove_by_name_ns+0xb4/0xc0)
[29448.452836]R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:2 
PM:0 RI:0 EA:3
[29448.452837] Krnl GPRS:  00cf0064 
0030 0003deae0810
[29448.452839]003bf3a8  
0703b31ebd68 0003c067e810
[29448.452840]0003d2aba060 0003c067e800 
0003804c4828 0003d99bb1e0
[29448.452841]00030001 0084e1d8 
003bf3a8 0003b31ebbe8
[29448.452848] Krnl Code: 003bf39c: c020002e335flarl 
%r2,985a5a

   003bf3a2: c0e5fff6604bbrasl%r14,28b438
  #003bf3a8: a7f40001brc15,3bf3aa
  >003bf3ac: a728fffelhi%r2,-2
   003bf3b0: a7f4ffdcbrc15,3bf368
   003bf3b4: 0707bcr0,%r7
   003bf3b6: 0707bcr0,%r7
   003bf3b8: c004brcl0,3bf3b8
[29448.452860] Call Trace:
[29448.452862] ([<003bf3a8>] kernfs_remove_by_name_ns+0xb0/0xc0)
[29448.452866]  [<005784f6>] 
attribute_container_remove_attrs+0x6e/0xb0
[29448.452868]  [<00578676>] 
attribute_container_class_device_del+0x2e/0x40

[29448.452869]  [<0057890a>] transport_remove_classdev+0x72/0x88
[29448.452871]  [<0057813a>] 
attribute_container_device_trigger+0xea/0xf0

[29448.452873]  [<005a1710>] scsi_target_reap+0x70/0x90
[29448.452876]  [<005a5486>] scsi_remove_target+0x22e/0x280
[29448.452878]  [<00182068>] process_one_work+0x268/0x4f0
[29448.452880]  [<00182342>] worker_thread+0x52/0x520
[29448.452882]  [<001894fa>] kthread+0x13a/0x158
[29448.452885]  [<007dea46>] kernel_thread_starter+0x6/0xc
[29448.452887]  [<007dea40>] kernel_thread_starter+0x0/0xc
[29448.452887] Last Breaking-Event-Address:
[29448.452889]  [<003bf3a8>] kernfs_remove_by_name_ns+0xb0/0xc0
[29448.452890] ---[ end trace 79d2fbfc2a29e8cf ]---
[29448.452891] kernfs: can not remove 'port_name', no directory
29448.453036] [ cut here ]
[29448.453038] WARNING: CPU: 24 PID: 197099 at ../fs/sysfs/group.c:237 
sysfs_remove_group+0xbe/0xd0
[29448.453039] Modules linked in: ghash_s390 prng dm_service_time 
xt_CHECKSUM iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 
iptable_nat nf_nat_ipv4 nf_nat libcrc32c crc32_vx_s390 nf_conntrack_ipv4 
nf_defrag_ipv4 xt_conntrack nf_conntrack ipt_REJECT nf_reject_ipv4 
bridge stp llc ebtable_filter ebtables ip6table_filter ip6_tables 
iptable_filter aes_s390 des_s390 des_generic sha512_s390 sha256_s390 
sha1_s390 sha_common qeth_l2 eadm_sch qeth tape_3590 tape ccwgroup 
tape_class nfsd auth_rpcgss oid_registry nfs_acl lockd sch_fq_codel 
grace vhost_net vhost sunrpc macvtap macvlan dm_multipath ip_tables
[29448.453053] CPU: 24 PID: 197099 Comm: kworker/24:3 Tainted: G 
W   4.10.0-20170222.0.f20083a.b83d822.fc24.s390xkvm #1
[29448.453054] Hardware name: IBM  2964 NC9  704 
 (LPAR)

[29448.453056] Workqueue: fc_wq_5 fc_starget_delete
[29448.453057] task: 00012f1d8000 task.stack: 0003b31e8000
[29448.453058] Krnl PSW : 0704c0018000 003c2be6 
(sysfs_remove_group+0xbe/0xd0)
[29448.453060]R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:0 
PM:0 RI:0 EA:3
[29448.453062] Krnl GPRS:  0006 
0038 0007
[29448.453063]003c2be2 0095 
0703b31ebd68 0003c067e810

[PATCH] scsi: aacraid: remove redundant zero check on ret

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

The check for ret being zero is redundant as a few statements earlier
we break out of the while loop if ret is non-zero.  Thus we can
remove the zero check and also the dead-code non-zero case too.

Detected by CoverityScan, CID#1411632 ("Logically Dead Code")

Signed-off-by: Colin Ian King 
---
 drivers/scsi/aacraid/commsup.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index 1994c74..a3ad042 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -2508,8 +2508,7 @@ int aac_command_thread(void *data)
 && (now.tv_usec > (100 / HZ)))
difference = (((100 - now.tv_usec) * HZ)
  + 50) / 100;
-   else if (ret == 0) {
-
+   else {
if (now.tv_usec > 50)
++now.tv_sec;
 
@@ -2520,9 +2519,6 @@ int aac_command_thread(void *data)
ret = aac_send_hosttime(dev, );
 
difference = (long)(unsigned)update_interval*HZ;
-   } else {
-   /* retry shortly */
-   difference = 10 * HZ;
}
next_jiffies = jiffies + difference;
if (time_before(next_check_jiffies,next_jiffies))
-- 
2.10.2



[PATCH] scsi: lpfc: fix missing spin_unlock on sql_list_lock

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

In the case where sglq is null, the current code just returns without
unlocking the spinlock sql_list_lock. Fix this by breaking out of the
while loop and the exit path will then unlock and return NULL as was
the original intention.

Detected by CoverityScan, CID#1411635 ("Missing unlock")

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

diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 1fba5dc..40720bb 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -952,7 +952,7 @@ __lpfc_sli_get_els_sglq(struct lpfc_hba *phba, struct 
lpfc_iocbq *piocbq)
start_sglq = sglq;
while (!found) {
if (!sglq)
-   return NULL;
+   break;
if (ndlp && ndlp->active_rrqs_xri_bitmap &&
test_bit(sglq->sli4_lxritag,
ndlp->active_rrqs_xri_bitmap)) {
-- 
2.10.2



[PATCH] scsi: lpfc: don't dereference dma_buf->iocbq before null check

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

dma_buf->iocbq is being dereferenced immediately before it is
being null checked, so we have a potential null pointer dereference
bug.  Fix this by only dereferencing it only once we have passed
a null check on the pointer.

Detected by CoverityScan, CID#1411652 ("Dereference before null check")

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

diff --git a/drivers/scsi/lpfc/lpfc_mem.c b/drivers/scsi/lpfc/lpfc_mem.c
index c61d8d6..5986c79 100644
--- a/drivers/scsi/lpfc/lpfc_mem.c
+++ b/drivers/scsi/lpfc/lpfc_mem.c
@@ -646,7 +646,6 @@ lpfc_sli4_nvmet_alloc(struct lpfc_hba *phba)
}
 
dma_buf->iocbq = lpfc_sli_get_iocbq(phba);
-   dma_buf->iocbq->iocb_flag = LPFC_IO_NVMET;
if (!dma_buf->iocbq) {
kfree(dma_buf->context);
pci_pool_free(phba->lpfc_drb_pool, dma_buf->dbuf.virt,
@@ -658,6 +657,7 @@ lpfc_sli4_nvmet_alloc(struct lpfc_hba *phba)
"2621 Ran out of nvmet iocb/WQEs\n");
return NULL;
}
+   dma_buf->iocbq->iocb_flag = LPFC_IO_NVMET;
nvmewqe = dma_buf->iocbq;
wqe = (union lpfc_wqe128 *)>wqe;
/* Initialize WQE */
-- 
2.10.2



[PATCH] scsi: lpfc: sanity check hrq is null before dereferencing it

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

The sanity check for hrq should be moved to before the deference
of hrq to ensure we don't perform a null pointer deference.

Detected by CoverityScan, CID#1411650 ("Dereference before null check")

Signed-off-by: Colin Ian King 
---
 drivers/scsi/lpfc/lpfc_sli.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index e43e5e2..1fba5dc 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -15185,17 +15185,17 @@ lpfc_mrq_create(struct lpfc_hba *phba, struct 
lpfc_queue **hrqp,
drq = drqp[idx];
cq  = cqp[idx];
 
-   if (hrq->entry_count != drq->entry_count) {
-   status = -EINVAL;
-   goto out;
-   }
-
/* sanity check on queue memory */
if (!hrq || !drq || !cq) {
status = -ENODEV;
goto out;
}
 
+   if (hrq->entry_count != drq->entry_count) {
+   status = -EINVAL;
+   goto out;
+   }
+
if (idx == 0) {
bf_set(lpfc_mbx_rq_create_num_pages,
   _create->u.request,
-- 
2.10.2



[PATCH] scsi: lpfc: remove redundant assignment of sgel

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

In the NVMET_FCOP_RSP case, sgel is assigned but never used and
hence is redundant and can be removed.

Detected by CoverityScan, CID#1411658 ("Unused value")

Signed-off-by: Colin Ian King 
---
 drivers/scsi/lpfc/lpfc_nvmet.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/lpfc/lpfc_nvmet.c b/drivers/scsi/lpfc/lpfc_nvmet.c
index c421e17..e59a0a8 100644
--- a/drivers/scsi/lpfc/lpfc_nvmet.c
+++ b/drivers/scsi/lpfc/lpfc_nvmet.c
@@ -1445,7 +1445,6 @@ lpfc_nvmet_prep_fcp_wqe(struct lpfc_hba *phba,
 
case NVMET_FCOP_RSP:
/* Words 0 - 2 */
-   sgel = >sg[0];
physaddr = rsp->rspdma;
wqe->fcp_trsp.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
wqe->fcp_trsp.bde.tus.f.bdeSize = rsp->rsplen;
-- 
2.10.2



Re: [PATCH 2/2] Add S6 support

2017-02-24 Thread Charles Chiou
From: Charles 

Hi all, Ping?
Does this patch has any issue need to fix? Thank you.


Re: [PATCH 1/2] Support Pegasus 3 product

2017-02-24 Thread Charles Chiou
From: Charles 

Hi all, Ping?
Does this patch has any issue need to fix? Thank you.


Re: [PATCH 1/2] Support Pegasus 3 product

2017-02-24 Thread Charles Chiou
From: Charles 



[PATCH] qedi: Fix memory leak in tmf response processing.

2017-02-24 Thread Manish Rangankar
From: "Dupuis, Chad" 

Signed-off-by: Manish Rangankar 
Signed-off-by: Chad Dupuis 
---
 drivers/scsi/qedi/qedi_fw.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qedi/qedi_fw.c b/drivers/scsi/qedi/qedi_fw.c
index b1d3904..c9f0ef4 100644
--- a/drivers/scsi/qedi/qedi_fw.c
+++ b/drivers/scsi/qedi/qedi_fw.c
@@ -165,10 +165,9 @@ static void qedi_tmf_resp_work(struct work_struct *work)
iscsi_block_session(session->cls_session);
rval = qedi_cleanup_all_io(qedi, qedi_conn, qedi_cmd->task, true);
if (rval) {
-   clear_bit(QEDI_CONN_FW_CLEANUP, _conn->flags);
qedi_clear_task_idx(qedi, qedi_cmd->task_id);
iscsi_unblock_session(session->cls_session);
-   return;
+   goto exit_tmf_resp;
}
 
iscsi_unblock_session(session->cls_session);
@@ -177,6 +176,8 @@ static void qedi_tmf_resp_work(struct work_struct *work)
spin_lock(>back_lock);
__iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr_ptr, NULL, 0);
spin_unlock(>back_lock);
+
+exit_tmf_resp:
kfree(resp_hdr_ptr);
clear_bit(QEDI_CONN_FW_CLEANUP, _conn->flags);
 }
-- 
1.8.5.6