[PATCH v2 07/15] qla2xxx: move fields from qla_hw_data to qla_qpair

2017-06-13 Thread Himanshu Madhani
From: Quinn Tran 

- Move chip_reset, enable_class_2 fields from qla_hw_data to qla_qpair
 to reduce cache thrash for target MQ.
- Optimizations to reduce unnecessary memory load for good path io.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_attr.c   |  2 +-
 drivers/scsi/qla2xxx/qla_def.h| 25 +++--
 drivers/scsi/qla2xxx/qla_init.c   | 14 ++--
 drivers/scsi/qla2xxx/qla_os.c |  2 +-
 drivers/scsi/qla2xxx/qla_target.c | 75 +++
 drivers/scsi/qla2xxx/qla_target.h |  3 +-
 6 files changed, 73 insertions(+), 48 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index f0f16d313faf..6dd984203666 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -2289,7 +2289,7 @@ qla2x00_init_host_attr(scsi_qla_host_t *vha)
fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
-   fc_host_supported_classes(vha->host) = ha->tgt.enable_class_2 ?
+   fc_host_supported_classes(vha->host) = ha->base_qpair->enable_class_2 ?
(FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 0dec148a4580..dfa001357110 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3252,6 +3252,7 @@ struct qla_qpair {
 */
spinlock_t *qp_lock_ptr;
struct scsi_qla_host *vha;
+   u32 chip_reset;
 
/* distill these fields down to 'online=0/1'
 * ha->flags.eeh_busy
@@ -3263,6 +3264,8 @@ struct qla_qpair {
uint32_t difdix_supported:1;
uint32_t delete_in_progress:1;
uint32_t fw_started:1;
+   uint32_t enable_class_2:1;
+   uint32_t enable_explicit_conf:1;
 
uint16_t id;/* qp number used with FW */
uint16_t vp_idx;/* vport ID */
@@ -3296,8 +3299,6 @@ struct scsi_qlt_host {
 
 struct qlt_hw_data {
/* Protected by hw lock */
-   uint32_t enable_class_2:1;
-   uint32_t enable_explicit_conf:1;
uint32_t node_name_set:1;
 
dma_addr_t atio_dma;/* Physical address. */
@@ -3954,7 +3955,6 @@ struct qla_hw_data {
struct work_struct board_disable;
 
struct mr_data_fx00 mr;
-   uint32_t chip_reset;
 
struct qlt_hw_data tgt;
int allow_cna_fw_dump;
@@ -4247,6 +4247,25 @@ struct qla2_sgx {
 #define QLA_QPAIR_MARK_NOT_BUSY(__qpair)   \
atomic_dec(&__qpair->ref_count);\
 
+
+#define QLA_ENA_CONF(_ha) {\
+int i;\
+_ha->base_qpair->enable_explicit_conf = 1; \
+for (i = 0; i < _ha->max_qpairs; i++) {\
+   if (_ha->queue_pair_map[i]) \
+   _ha->queue_pair_map[i]->enable_explicit_conf = 1; \
+}  \
+}
+
+#define QLA_DIS_CONF(_ha) {\
+int i;\
+_ha->base_qpair->enable_explicit_conf = 0; \
+for (i = 0; i < _ha->max_qpairs; i++) {\
+   if (_ha->queue_pair_map[i]) \
+   _ha->queue_pair_map[i]->enable_explicit_conf = 0; \
+}  \
+}
+
 /*
  * qla2x00 local function return status codes
  */
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index e6a1f9ca0e95..360abede3f6b 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -1322,7 +1322,7 @@ qla24xx_handle_plogi_done_event(struct scsi_qla_host 
*vha, struct event_arg *ea)
ql_dbg(ql_dbg_disc, vha, 0x20ea,
"%s %d %8phC post gpdb\n",
__func__, __LINE__, ea->fcport->port_name);
-   ea->fcport->chip_reset = vha->hw->chip_reset;
+   ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
ea->fcport->logout_on_delete = 1;
qla24xx_post_gpdb_work(vha, ea->fcport, 0);
break;
@@ -5524,6 +5524,7 @@ qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
struct scsi_qla_host *vp;
unsigned long flags;
fc_port_t *fcport;
+   u16 i;
 
/* For ISP82XX, driver waits for completion of the commands.
 * online flag should be set.
@@ -5549,7 +5550,12 @@ qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
ha->current_topology = 0;
ha->flags.fw_started = 0;
ha->flags.fw_init_done = 0;
-   ha->chip_reset++;
+   ha->base_qpair->chip_reset++;
+   for (i = 0; i < ha->max_qpairs; i++) {
+   if (ha->queue_pair_map[i])
+   

[PATCH v2 03/15] qla2xxx: Enable Target Multi Queue

2017-06-13 Thread Himanshu Madhani
From: Quinn Tran 

Enable Multi Queue for Target mode. At Initiator LUN scan time,
each LUN is assign to a QPair. Each QPair is affinitize
to certain CPU. When new cmd arrives from the wire,
the lunid is used to search for qpair. The qpair's affinitized
cpuid will be used to queue up the work element.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h|   3 +-
 drivers/scsi/qla2xxx/qla_init.c   |   3 +
 drivers/scsi/qla2xxx/qla_inline.h |  28 +++
 drivers/scsi/qla2xxx/qla_isr.c|  21 +++--
 drivers/scsi/qla2xxx/qla_os.c |  56 +-
 drivers/scsi/qla2xxx/qla_target.c | 157 --
 drivers/scsi/qla2xxx/qla_target.h |  10 ++-
 7 files changed, 240 insertions(+), 38 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 64109134e276..005ca2de3795 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3245,7 +3245,7 @@ struct req_que {
 struct qla_qpair {
spinlock_t qp_lock;
atomic_t ref_count;
-
+   uint32_t lun_cnt;
/*
 * For qpair 0, qp_lock_ptr will point at hardware_lock due to
 * legacy code. For other Qpair(s), it will point at qp_lock.
@@ -3275,6 +3275,7 @@ struct qla_qpair {
struct qla_hw_data *hw;
struct work_struct q_work;
struct list_head qp_list_elem; /* vha->qp_list */
+   struct list_head hints_list;
uint16_t cpuid;
 };
 
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 7d0847b3d190..fa5e6ab8e4a7 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -7623,6 +7623,7 @@ struct qla_qpair *qla2xxx_create_qpair(struct 
scsi_qla_host *vha, int qos,
ha->queue_pair_map[qpair_id] = qpair;
qpair->id = qpair_id;
qpair->vp_idx = vp_idx;
+   INIT_LIST_HEAD(>hints_list);
 
for (i = 0; i < ha->msix_count; i++) {
msix = >msix_entries[i];
@@ -7666,6 +7667,8 @@ struct qla_qpair *qla2xxx_create_qpair(struct 
scsi_qla_host *vha, int qos,
qpair->req = ha->req_q_map[req_id];
qpair->rsp->req = qpair->req;
qpair->rsp->qpair = qpair;
+   /* init qpair to this cpu. Will adjust at run time. */
+   qla_cpu_update(qpair, smp_processor_id());
 
if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
if (ha->fw_attributes & BIT_4)
diff --git a/drivers/scsi/qla2xxx/qla_inline.h 
b/drivers/scsi/qla2xxx/qla_inline.h
index 99028d48c664..bd8cb796f64e 100644
--- a/drivers/scsi/qla2xxx/qla_inline.h
+++ b/drivers/scsi/qla2xxx/qla_inline.h
@@ -324,3 +324,31 @@ qla_is_exch_offld_enabled(struct scsi_qla_host *vha)
else
return false;
 }
+
+static inline void
+qla_cpu_update(struct qla_qpair *qpair, uint16_t cpuid)
+{
+   qpair->cpuid = cpuid;
+
+   if (!list_empty(>hints_list)) {
+   struct qla_qpair_hint *h;
+
+   list_for_each_entry(h, >hints_list, hint_elem)
+   h->cpuid = qpair->cpuid;
+   }
+}
+
+static inline struct qla_qpair_hint *
+qla_qpair_to_hint(struct qla_tgt *tgt, struct qla_qpair *qpair)
+{
+   struct qla_qpair_hint *h;
+   u16 i;
+
+   for (i = 0; i < tgt->ha->max_qpairs + 1; i++) {
+   h = >qphints[i];
+   if (h->qpair == qpair)
+   return h;
+   }
+
+   return NULL;
+}
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 1535a29a9d9f..9eb946cc8297 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -9,6 +9,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2761,6 +2762,9 @@ void qla24xx_process_response_queue(struct scsi_qla_host 
*vha,
if (!ha->flags.fw_started)
return;
 
+   if (rsp->qpair->cpuid != smp_processor_id())
+   qla_cpu_update(rsp->qpair, smp_processor_id());
+
while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
 
@@ -3196,10 +3200,10 @@ struct qla_init_msix_entry {
 };
 
 static const struct qla_init_msix_entry msix_entries[] = {
-   { "qla2xxx (default)", qla24xx_msix_default },
-   { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
-   { "qla2xxx (atio_q)", qla83xx_msix_atio_q },
-   { "qla2xxx (qpair_multiq)", qla2xxx_msix_rsp_q },
+   { "default", qla24xx_msix_default },
+   { "rsp_q", qla24xx_msix_rsp_q },
+   { "atio_q", qla83xx_msix_atio_q },
+   { "qpair_multiq", qla2xxx_msix_rsp_q },
 };
 
 static const struct qla_init_msix_entry qla82xx_msix_entries[] = {
@@ -3279,7 +3283,7 @@ qla24xx_enable_msix(struct qla_hw_data *ha, struct 
rsp_que *rsp)
 

[PATCH v2 11/15] qla2xxx: Remove unused tgt_enable_64bit_addr flag

2017-06-13 Thread Himanshu Madhani
From: Quinn Tran 

By default this flag is forced to true.  Remove this
flag and unneccessary check for this flag.

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

diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index 84be2b48246f..411c1799c6e3 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -2420,12 +2420,10 @@ static int qlt_24xx_build_ctio_pkt(struct qla_qpair 
*qpair,
  * ha->hardware_lock supposed to be held on entry. We have already made sure
  * that there is sufficient amount of request entries to not drop it.
  */
-static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm,
-   struct scsi_qla_host *vha)
+static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm)
 {
int cnt;
uint32_t *dword_ptr;
-   int enable_64bit_addressing = prm->tgt->tgt_enable_64bit_addr;
 
/* Build continuation packets */
while (prm->seg_cnt > 0) {
@@ -2445,16 +2443,8 @@ static void qlt_load_cont_data_segments(struct 
qla_tgt_prm *prm,
cont_pkt64->entry_count = 1;
cont_pkt64->sys_define = 0;
 
-   if (enable_64bit_addressing) {
-   cont_pkt64->entry_type = CONTINUE_A64_TYPE;
-   dword_ptr =
-   (uint32_t *)_pkt64->dseg_0_address;
-   } else {
-   cont_pkt64->entry_type = CONTINUE_TYPE;
-   dword_ptr =
-   (uint32_t *)&((cont_entry_t *)
-   cont_pkt64)->dseg_0_address;
-   }
+   cont_pkt64->entry_type = CONTINUE_A64_TYPE;
+   dword_ptr = (uint32_t *)_pkt64->dseg_0_address;
 
/* Load continuation entry data segments */
for (cnt = 0;
@@ -2463,12 +2453,8 @@ static void qlt_load_cont_data_segments(struct 
qla_tgt_prm *prm,
*dword_ptr++ =
cpu_to_le32(pci_dma_lo32
(sg_dma_address(prm->sg)));
-   if (enable_64bit_addressing) {
-   *dword_ptr++ =
-   cpu_to_le32(pci_dma_hi32
-   (sg_dma_address
-   (prm->sg)));
-   }
+   *dword_ptr++ = cpu_to_le32(pci_dma_hi32
+   (sg_dma_address(prm->sg)));
*dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg));
 
prm->sg = sg_next(prm->sg);
@@ -2480,12 +2466,10 @@ static void qlt_load_cont_data_segments(struct 
qla_tgt_prm *prm,
  * ha->hardware_lock supposed to be held on entry. We have already made sure
  * that there is sufficient amount of request entries to not drop it.
  */
-static void qlt_load_data_segments(struct qla_tgt_prm *prm,
-   struct scsi_qla_host *vha)
+static void qlt_load_data_segments(struct qla_tgt_prm *prm)
 {
int cnt;
uint32_t *dword_ptr;
-   int enable_64bit_addressing = prm->tgt->tgt_enable_64bit_addr;
struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt;
 
pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen);
@@ -2512,17 +2496,16 @@ static void qlt_load_data_segments(struct qla_tgt_prm 
*prm,
cnt++, prm->seg_cnt--) {
*dword_ptr++ =
cpu_to_le32(pci_dma_lo32(sg_dma_address(prm->sg)));
-   if (enable_64bit_addressing) {
-   *dword_ptr++ =
-   cpu_to_le32(pci_dma_hi32(
-   sg_dma_address(prm->sg)));
-   }
+
+   *dword_ptr++ = cpu_to_le32(pci_dma_hi32(
+   sg_dma_address(prm->sg)));
+
*dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg));
 
prm->sg = sg_next(prm->sg);
}
 
-   qlt_load_cont_data_segments(prm, vha);
+   qlt_load_cont_data_segments(prm);
 }
 
 static inline int qlt_has_data(struct qla_tgt_cmd *cmd)
@@ -3136,7 +3119,7 @@ int qlt_xmit_response(struct qla_tgt_cmd *cmd, int 
xmit_type,
CTIO7_FLAGS_STATUS_MODE_0);
 
if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL)
-   qlt_load_data_segments(, vha);
+   qlt_load_data_segments();
 
if (prm.add_status_pkt == 0) {
if (xmit_type & QLA_TGT_XMIT_STATUS) {
@@ -3272,7 +3255,7 @@ int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd)
CTIO7_FLAGS_STATUS_MODE_0);
 
if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL)
-   

[PATCH v2 14/15] qla2xxx: Include Exchange offload/Extended Login into FW dump

2017-06-13 Thread Himanshu Madhani
From: Quinn Tran 

Add missing memory dump of Exchange Offload and Extended
login into FW dump.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_dbg.c  | 49 +
 drivers/scsi/qla2xxx/qla_dbg.h  | 11 +
 drivers/scsi/qla2xxx/qla_init.c |  7 ++
 drivers/scsi/qla2xxx/qla_os.c   |  3 ---
 4 files changed, 67 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_dbg.c b/drivers/scsi/qla2xxx/qla_dbg.c
index c0c90dcc7c7b..f91ee717202d 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.c
+++ b/drivers/scsi/qla2xxx/qla_dbg.c
@@ -498,6 +498,50 @@ qla25xx_copy_fce(struct qla_hw_data *ha, void *ptr, 
uint32_t **last_chain)
 }
 
 static inline void *
+qla25xx_copy_exlogin(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
+{
+   struct qla2xxx_offld_chain *c = ptr;
+
+   if (!ha->exlogin_buf)
+   return ptr;
+
+   *last_chain = >type;
+
+   c->type = cpu_to_be32(DUMP_CHAIN_EXLOGIN);
+   c->chain_size = cpu_to_be32(sizeof(struct qla2xxx_offld_chain) +
+   ha->exlogin_size);
+   c->size = cpu_to_be32(ha->exlogin_size);
+   c->addr = cpu_to_be64(ha->exlogin_buf_dma);
+
+   ptr += sizeof(struct qla2xxx_offld_chain);
+   memcpy(ptr, ha->exlogin_buf, ha->exlogin_size);
+
+   return (char *)ptr + cpu_to_be32(c->size);
+}
+
+static inline void *
+qla81xx_copy_exchoffld(struct qla_hw_data *ha, void *ptr, uint32_t 
**last_chain)
+{
+   struct qla2xxx_offld_chain *c = ptr;
+
+   if (!ha->exchoffld_buf)
+   return ptr;
+
+   *last_chain = >type;
+
+   c->type = cpu_to_be32(DUMP_CHAIN_EXCHG);
+   c->chain_size = cpu_to_be32(sizeof(struct qla2xxx_offld_chain) +
+   ha->exchoffld_size);
+   c->size = cpu_to_be32(ha->exchoffld_size);
+   c->addr = cpu_to_be64(ha->exchoffld_buf_dma);
+
+   ptr += sizeof(struct qla2xxx_offld_chain);
+   memcpy(ptr, ha->exchoffld_buf, ha->exchoffld_size);
+
+   return (char *)ptr + cpu_to_be32(c->size);
+}
+
+static inline void *
 qla2xxx_copy_atioqueues(struct qla_hw_data *ha, void *ptr,
uint32_t **last_chain)
 {
@@ -1606,6 +1650,7 @@ qla25xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
nxt_chain = qla25xx_copy_fce(ha, nxt_chain, _chain);
nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, _chain);
nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, _chain);
+   nxt_chain = qla25xx_copy_exlogin(ha, nxt_chain, _chain);
if (last_chain) {
ha->fw_dump->version |= htonl(DUMP_CHAIN_VARIANT);
*last_chain |= htonl(DUMP_CHAIN_LAST);
@@ -1932,6 +1977,8 @@ qla81xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
nxt_chain = qla25xx_copy_fce(ha, nxt_chain, _chain);
nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, _chain);
nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, _chain);
+   nxt_chain = qla25xx_copy_exlogin(ha, nxt_chain, _chain);
+   nxt_chain = qla81xx_copy_exchoffld(ha, nxt_chain, _chain);
if (last_chain) {
ha->fw_dump->version |= htonl(DUMP_CHAIN_VARIANT);
*last_chain |= htonl(DUMP_CHAIN_LAST);
@@ -2443,6 +2490,8 @@ qla83xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
nxt_chain = qla25xx_copy_fce(ha, nxt_chain, _chain);
nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, _chain);
nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, _chain);
+   nxt_chain = qla25xx_copy_exlogin(ha, nxt_chain, _chain);
+   nxt_chain = qla81xx_copy_exchoffld(ha, nxt_chain, _chain);
if (last_chain) {
ha->fw_dump->version |= htonl(DUMP_CHAIN_VARIANT);
*last_chain |= htonl(DUMP_CHAIN_LAST);
diff --git a/drivers/scsi/qla2xxx/qla_dbg.h b/drivers/scsi/qla2xxx/qla_dbg.h
index f60138f66dce..8877aa97d829 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.h
+++ b/drivers/scsi/qla2xxx/qla_dbg.h
@@ -232,6 +232,15 @@ struct qla2xxx_fce_chain {
uint32_t eregs[8];
 };
 
+/* used by exchange off load and extended login offload */
+struct qla2xxx_offld_chain {
+   uint32_t type;
+   uint32_t chain_size;
+
+   uint32_t size;
+   u64  addr;
+};
+
 struct qla2xxx_mq_chain {
uint32_t type;
uint32_t chain_size;
@@ -258,6 +267,8 @@ struct qla2xxx_mqueue_chain {
 #define DUMP_CHAIN_FCE 0x7AF0
 #define DUMP_CHAIN_MQ  0x7AF1
 #define DUMP_CHAIN_QUEUE   0x7AF2
+#define DUMP_CHAIN_EXLOGIN 0x7AF3
+#define DUMP_CHAIN_EXCHG   0x7AF4
 #define DUMP_CHAIN_LAST0x8000
 
 struct qla2xxx_fw_dump {
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 48c0a58330d4..72d9ca138ffd 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -2538,6 +2538,13 @@ 

[PATCH v2 06/15] qla2xxx: Add fw_started flags to qpair

2017-06-13 Thread Himanshu Madhani
From: Quinn Tran 

Add fw_started flag to qpair to reduce cache thrash.
This reduce access to qla_hw_data structure by each
qpair.

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

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 18b37c864250..0dec148a4580 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3262,6 +3262,7 @@ struct qla_qpair {
/* move vha->flags.difdix_supported here */
uint32_t difdix_supported:1;
uint32_t delete_in_progress:1;
+   uint32_t fw_started:1;
 
uint16_t id;/* qp number used with FW */
uint16_t vp_idx;/* vport ID */
@@ -4183,6 +4184,26 @@ struct qla2_sgx {
srb_t   *sp;
 };
 
+#define QLA_FW_STARTED(_ha) {  \
+   int i;  \
+   _ha->flags.fw_started = 1;  \
+   _ha->base_qpair->fw_started = 1;\
+   for (i = 0; i < _ha->max_qpairs; i++) { \
+   if (_ha->queue_pair_map[i]) \
+   _ha->queue_pair_map[i]->fw_started = 1; \
+   }   \
+}
+
+#define QLA_FW_STOPPED(_ha) {  \
+   int i;  \
+   _ha->flags.fw_started = 0;  \
+   _ha->base_qpair->fw_started = 0;\
+   for (i = 0; i < _ha->max_qpairs; i++) { \
+   if (_ha->queue_pair_map[i]) \
+   _ha->queue_pair_map[i]->fw_started = 0; \
+   }   \
+}
+
 /*
  * Macros to help code, maintain, etc.
  */
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index dcc306121a3d..e6a1f9ca0e95 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -3207,7 +3207,7 @@ qla2x00_init_rings(scsi_qla_host_t *vha)
} else {
ql_dbg(ql_dbg_init, vha, 0x00d3,
"Init Firmware -- success.\n");
-   ha->flags.fw_started = 1;
+   QLA_FW_STARTED(ha);
}
 
return (rval);
@@ -6841,7 +6841,7 @@ qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
ret = qla2x00_stop_firmware(vha);
}
 
-   ha->flags.fw_started = 0;
+   QLA_FW_STOPPED(ha);
ha->flags.fw_init_done = 0;
 }
 
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 3c9f9aa7f2c2..40385bc1d1fa 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -710,7 +710,7 @@ qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que 
*rsp, uint16_t *mb)
 
ha->isp_ops->fw_dump(vha, 1);
ha->flags.fw_init_done = 0;
-   ha->flags.fw_started = 0;
+   QLA_FW_STOPPED(ha);
 
if (IS_FWI2_CAPABLE(ha)) {
if (mb[1] == 0 && mb[2] == 0) {
diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index cbe6ff9f663e..e25f1fae2c3d 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -3086,7 +3086,7 @@ int qlt_xmit_response(struct qla_tgt_cmd *cmd, int 
xmit_type,
else
vha->tgt_counters.core_qla_que_buf++;
 
-   if (!ha->flags.fw_started || cmd->reset_count != ha->chip_reset) {
+   if (!qpair->fw_started || cmd->reset_count != vha->hw->chip_reset) {
/*
 * Either the port is not online or this request was from
 * previous life, just abort the processing.
@@ -3096,7 +3096,7 @@ int qlt_xmit_response(struct qla_tgt_cmd *cmd, int 
xmit_type,
ql_dbg(ql_dbg_async, vha, 0xe101,
"RESET-RSP online/active/old-count/new-count = 
%d/%d/%d/%d.\n",
vha->flags.online, qla2x00_reset_active(vha),
-   cmd->reset_count, ha->chip_reset);
+   cmd->reset_count, vha->hw->chip_reset);
spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
return 0;
}
@@ -3206,7 +3206,6 @@ int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd)
 {
struct ctio7_to_24xx *pkt;
struct scsi_qla_host *vha = cmd->vha;
-   struct qla_hw_data *ha = vha->hw;
struct qla_tgt *tgt = cmd->tgt;
struct qla_tgt_prm prm;
unsigned long flags = 0;
@@ -3223,7 +3222,7 @@ int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd)
if (qlt_pci_map_calc_cnt() != 0)
return -EAGAIN;
 
-   if (!ha->flags.fw_started || (cmd->reset_count != ha->chip_reset) ||
+   if (!qpair->fw_started || 

[PATCH v2 04/15] qla2xxx: Fix mailbox failure while deleting Queue pairs

2017-06-13 Thread Himanshu Madhani
From: Sawan Chandak 

In target mode driver, queue pairs are not created during driver load time,
instead they are created at the configuration time after chip reset.
If a user tries to load/unload driver after queue pairs are created, then
there would be mailbox failure, while deleting queue pairs.
Flag is added to check if queue pairs are created or not. Queue pairs will
be deleted only If they were created during target configuration.

Signed-off-by: Sawan Chandak 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h  |  2 ++
 drivers/scsi/qla2xxx/qla_init.c | 10 --
 drivers/scsi/qla2xxx/qla_mid.c  |  4 
 drivers/scsi/qla2xxx/qla_os.c   |  1 +
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 005ca2de3795..8b52f431a812 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3997,6 +3997,8 @@ typedef struct scsi_qla_host {
uint32_tfw_tgt_reported:1;
uint32_tbbcr_enable:1;
uint32_tqpairs_available:1;
+   uint32_tqpairs_req_created:1;
+   uint32_tqpairs_rsp_created:1;
} flags;
 
atomic_tloop_state;
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index fa5e6ab8e4a7..dcc306121a3d 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -7719,9 +7719,12 @@ struct qla_qpair *qla2xxx_create_qpair(struct 
scsi_qla_host *vha, int qos,
 
 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
 {
-   int ret;
+   int ret = QLA_FUNCTION_FAILED;
struct qla_hw_data *ha = qpair->hw;
 
+   if (!vha->flags.qpairs_req_created && !vha->flags.qpairs_rsp_created)
+   goto fail;
+
qpair->delete_in_progress = 1;
while (atomic_read(>ref_count))
msleep(500);
@@ -7738,8 +7741,11 @@ int qla2xxx_delete_qpair(struct scsi_qla_host *vha, 
struct qla_qpair *qpair)
clear_bit(qpair->id, ha->qpair_qid_map);
ha->num_qpairs--;
list_del(>qp_list_elem);
-   if (list_empty(>qp_list))
+   if (list_empty(>qp_list)) {
vha->flags.qpairs_available = 0;
+   vha->flags.qpairs_req_created = 0;
+   vha->flags.qpairs_rsp_created = 0;
+   }
mempool_destroy(qpair->srb_mempool);
kfree(qpair);
mutex_unlock(>mq_lock);
diff --git a/drivers/scsi/qla2xxx/qla_mid.c b/drivers/scsi/qla2xxx/qla_mid.c
index 4ad452a42dbe..f0605cd196fb 100644
--- a/drivers/scsi/qla2xxx/qla_mid.c
+++ b/drivers/scsi/qla2xxx/qla_mid.c
@@ -645,6 +645,7 @@ qla25xx_create_req_que(struct qla_hw_data *ha, uint16_t 
options,
int ret = 0;
struct req_que *req = NULL;
struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
+   struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
uint16_t que_id = 0;
device_reg_t *reg;
uint32_t cnt;
@@ -741,6 +742,7 @@ qla25xx_create_req_que(struct qla_hw_data *ha, uint16_t 
options,
mutex_unlock(>mq_lock);
goto que_failed;
}
+   vha->flags.qpairs_req_created = 1;
}
 
return req->id;
@@ -772,6 +774,7 @@ qla25xx_create_rsp_que(struct qla_hw_data *ha, uint16_t 
options,
int ret = 0;
struct rsp_que *rsp = NULL;
struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
+   struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev);
uint16_t que_id = 0;
device_reg_t *reg;
 
@@ -855,6 +858,7 @@ qla25xx_create_rsp_que(struct qla_hw_data *ha, uint16_t 
options,
mutex_unlock(>mq_lock);
goto que_failed;
}
+   vha->flags.qpairs_rsp_created = 1;
}
rsp->req = NULL;
 
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 3963602aef35..13e4d2428a9a 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -384,6 +384,7 @@ static int qla2x00_alloc_queues(struct qla_hw_data *ha, 
struct req_que *req,
ha->base_qpair->rsp = rsp;
ha->base_qpair->vha = vha;
ha->base_qpair->qp_lock_ptr = >hardware_lock;
+   /* init qpair to this cpu. Will adjust at run time. */
ha->base_qpair->msix = >msix_entries[QLA_MSIX_RSP_Q];
INIT_LIST_HEAD(>base_qpair->hints_list);
qla_cpu_update(rsp->qpair, smp_processor_id());
-- 
2.12.0



[PATCH v2 08/15] qla2xxx: use shadow register for ISP27XX

2017-06-13 Thread Himanshu Madhani
From: Quinn Tran 

For ISP27XX, use shadow register to read FW provided
REQQ's consumer index.  The shadow register is dma'ed
by firmware.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h| 1 +
 drivers/scsi/qla2xxx/qla_init.c   | 1 +
 drivers/scsi/qla2xxx/qla_os.c | 1 +
 drivers/scsi/qla2xxx/qla_target.c | 3 ++-
 4 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index dfa001357110..b3ba32773db4 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3266,6 +3266,7 @@ struct qla_qpair {
uint32_t fw_started:1;
uint32_t enable_class_2:1;
uint32_t enable_explicit_conf:1;
+   uint32_t use_shadow_reg:1;
 
uint16_t id;/* qp number used with FW */
uint16_t vp_idx;/* vport ID */
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 360abede3f6b..f586f4f7dc57 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -7614,6 +7614,7 @@ struct qla_qpair *qla2xxx_create_qpair(struct 
scsi_qla_host *vha, int qos,
qpair->vha = vha;
qpair->qp_lock_ptr = >qp_lock;
spin_lock_init(>qp_lock);
+   qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
 
/* Assign available que pair id */
mutex_lock(>mq_lock);
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 44be2c8237fd..1d66954b7e5a 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -384,6 +384,7 @@ static int qla2x00_alloc_queues(struct qla_hw_data *ha, 
struct req_que *req,
ha->base_qpair->rsp = rsp;
ha->base_qpair->vha = vha;
ha->base_qpair->qp_lock_ptr = >hardware_lock;
+   ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
/* init qpair to this cpu. Will adjust at run time. */
ha->base_qpair->msix = >msix_entries[QLA_MSIX_RSP_Q];
INIT_LIST_HEAD(>base_qpair->hints_list);
diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index 66bb4825339f..1d6cc24c0640 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -2288,7 +2288,8 @@ static int qlt_check_reserve_free_req(struct qla_qpair 
*qpair,
struct req_que *req = qpair->req;
 
if (req->cnt < (req_cnt + 2)) {
-   cnt = (uint16_t)RD_REG_DWORD(req->req_q_out);
+   cnt = (uint16_t)(qpair->use_shadow_reg ? *req->out_ptr :
+   RD_REG_DWORD_RELAXED(req->req_q_out));
 
if  (req->ring_index < cnt)
req->cnt = cnt - req->ring_index;
-- 
2.12.0



[PATCH v2 05/15] qla2xxx: Add debug knob for user control workload

2017-06-13 Thread Himanshu Madhani
From: Quinn Tran 

For Target mode, user can control the work load by
placing qla2xxx's irq vector on certain CPU via the
smp_affinity knob. This patch allows user to control
the number of QPair's irq to be active. The irqs are
allocated at driver load time until unload. The work
itself is placed on the QPair based on user setting.

Usage:
  modprobe qla2xxx qlini_mode=disabled ql2xuctrlirq=1
  mount -t debugfs none /sys/kernel/debug
  echo 2 > /sys/kernel/debug/qla2xxx/qla2xxx_[host num]/naqp
  echo [cpu id] > /proc/irq/[irq id]/smp_affinity_list

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h|  7 ++-
 drivers/scsi/qla2xxx/qla_dfs.c| 89 +++
 drivers/scsi/qla2xxx/qla_gbl.h|  2 +
 drivers/scsi/qla2xxx/qla_isr.c| 11 +++--
 drivers/scsi/qla2xxx/qla_target.c | 32 ++
 5 files changed, 137 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 8b52f431a812..18b37c864250 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3322,6 +3322,7 @@ struct qlt_hw_data {
 
struct dentry *dfs_tgt_sess;
struct dentry *dfs_tgt_port_database;
+   struct dentry *dfs_naqp;
 
struct list_head q_full_list;
uint32_t num_pend_cmds;
@@ -3330,7 +3331,8 @@ struct qlt_hw_data {
spinlock_t q_full_lock;
uint32_t leak_exchg_thresh_hold;
spinlock_t sess_lock;
-   int rspq_vector_cpuid;
+   int num_act_qpairs;
+#define DEFAULT_NAQP 2
spinlock_t atio_lock cacheline_aligned;
struct btree_head32 host_map;
 };
@@ -4278,6 +4280,9 @@ enum nexus_wait_type {
WAIT_LUN,
 };
 
+#define USER_CTRL_IRQ(_ha) (ql2xuctrlirq && QLA_TGT_MODE_ENABLED() && \
+   (IS_QLA27XX(_ha) || IS_QLA83XX(_ha)))
+
 #include "qla_target.h"
 #include "qla_gbl.h"
 #include "qla_dbg.h"
diff --git a/drivers/scsi/qla2xxx/qla_dfs.c b/drivers/scsi/qla2xxx/qla_dfs.c
index 391c50be2297..63d7374dce77 100644
--- a/drivers/scsi/qla2xxx/qla_dfs.c
+++ b/drivers/scsi/qla2xxx/qla_dfs.c
@@ -314,6 +314,81 @@ static const struct file_operations dfs_fce_ops = {
.release= qla2x00_dfs_fce_release,
 };
 
+static int
+qla_dfs_naqp_show(struct seq_file *s, void *unused)
+{
+   struct scsi_qla_host *vha = s->private;
+   struct qla_hw_data *ha = vha->hw;
+
+   seq_printf(s, "%d\n", ha->tgt.num_act_qpairs);
+   return 0;
+}
+
+static int
+qla_dfs_naqp_open(struct inode *inode, struct file *file)
+{
+   struct scsi_qla_host *vha = inode->i_private;
+
+   return single_open(file, qla_dfs_naqp_show, vha);
+}
+
+static ssize_t
+qla_dfs_naqp_write(struct file *file, const char __user *buffer,
+size_t count, loff_t *pos)
+{
+   struct seq_file *s = file->private_data;
+   struct scsi_qla_host *vha = s->private;
+   struct qla_hw_data *ha = vha->hw;
+   char *buf;
+   int rc = 0;
+   unsigned long num_act_qp;
+
+   if (!(IS_QLA27XX(ha) || IS_QLA83XX(ha))) {
+   pr_err("host%ld: this adapter does not support Multi Q.",
+   vha->host_no);
+   return -EINVAL;
+   }
+
+   if (!vha->flags.qpairs_available) {
+   pr_err("host%ld: Driver is not setup with Multi Q.",
+   vha->host_no);
+   return -EINVAL;
+   }
+   buf = memdup_user_nul(buffer, count);
+   if (IS_ERR(buf)) {
+   pr_err("host%ld: fail to copy user buffer.",
+   vha->host_no);
+   return PTR_ERR(buf);
+   }
+
+   num_act_qp = simple_strtoul(buf, NULL, 0);
+
+   if (num_act_qp >= vha->hw->max_qpairs) {
+   pr_err("User set invalid number of qpairs %lu. Max = %d",
+   num_act_qp, vha->hw->max_qpairs);
+   rc = -EINVAL;
+   goto out_free;
+   }
+
+   if (num_act_qp != ha->tgt.num_act_qpairs) {
+   ha->tgt.num_act_qpairs = num_act_qp;
+   qlt_clr_qp_table(vha);
+   }
+   rc = count;
+out_free:
+   kfree(buf);
+   return rc;
+}
+
+static const struct file_operations dfs_naqp_ops = {
+   .open   = qla_dfs_naqp_open,
+   .read   = seq_read,
+   .llseek = seq_lseek,
+   .release= single_release,
+   .write  = qla_dfs_naqp_write,
+};
+
+
 int
 qla2x00_dfs_setup(scsi_qla_host_t *vha)
 {
@@ -391,6 +466,15 @@ qla2x00_dfs_setup(scsi_qla_host_t *vha)
goto out;
}
 
+   if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
+   ha->tgt.dfs_naqp = debugfs_create_file("naqp",
+   0400, ha->dfs_dir, vha, _naqp_ops);
+   if (!ha->tgt.dfs_naqp) {
+   ql_log(ql_log_warn, vha, 0xd011,
+   "Unable to create debugFS naqp node.\n");

[PATCH v2 10/15] qla2xxx: Add debug logging routine for qpair

2017-06-13 Thread Himanshu Madhani
From: Quinn Tran 

For target main path io routines that uses qpair,
create new logging & debugging routines to use
qpair instead of reaching for scsi_qla_host to
reduce cache thrash.

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

diff --git a/drivers/scsi/qla2xxx/qla_dbg.c b/drivers/scsi/qla2xxx/qla_dbg.c
index 11e097e123bd..c0c90dcc7c7b 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.c
+++ b/drivers/scsi/qla2xxx/qla_dbg.c
@@ -2713,3 +2713,104 @@ ql_dump_buffer(uint32_t level, scsi_qla_host_t *vha, 
int32_t id,
   buf + cnt, min(16U, size - cnt), false);
}
 }
+
+/*
+ * This function is for formatting and logging log messages.
+ * It is to be used when vha is available. It formats the message
+ * and logs it to the messages file. All the messages will be logged
+ * irrespective of value of ql2xextended_error_logging.
+ * parameters:
+ * level: The level of the log messages to be printed in the
+ *messages file.
+ * vha:   Pointer to the scsi_qla_host_t
+ * id:This is a unique id for the level. It identifies the
+ *part of the code from where the message originated.
+ * msg:   The message to be displayed.
+ */
+void
+ql_log_qp(uint32_t level, struct qla_qpair *qpair, int32_t id,
+const char *fmt, ...)
+{
+   va_list va;
+   struct va_format vaf;
+   char pbuf[128];
+
+   if (level > ql_errlev)
+   return;
+
+   if (qpair != NULL) {
+   const struct pci_dev *pdev = qpair->pdev;
+   /*  : Message */
+   snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x: ",
+   QL_MSGHDR, dev_name(&(pdev->dev)), id);
+   } else {
+   snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x: : ",
+   QL_MSGHDR, ":00:00.0", id);
+   }
+   pbuf[sizeof(pbuf) - 1] = 0;
+
+   va_start(va, fmt);
+
+   vaf.fmt = fmt;
+   vaf.va = 
+
+   switch (level) {
+   case ql_log_fatal: /* FATAL LOG */
+   pr_crit("%s%pV", pbuf, );
+   break;
+   case ql_log_warn:
+   pr_err("%s%pV", pbuf, );
+   break;
+   case ql_log_info:
+   pr_warn("%s%pV", pbuf, );
+   break;
+   default:
+   pr_info("%s%pV", pbuf, );
+   break;
+   }
+
+   va_end(va);
+}
+
+/*
+ * This function is for formatting and logging debug information.
+ * It is to be used when vha is available. It formats the message
+ * and logs it to the messages file.
+ * parameters:
+ * level: The level of the debug messages to be printed.
+ *If ql2xextended_error_logging value is correctly set,
+ *this message will appear in the messages file.
+ * vha:   Pointer to the scsi_qla_host_t.
+ * id:This is a unique identifier for the level. It identifies the
+ *part of the code from where the message originated.
+ * msg:   The message to be displayed.
+ */
+void
+ql_dbg_qp(uint32_t level, struct qla_qpair *qpair, int32_t id,
+const char *fmt, ...)
+{
+   va_list va;
+   struct va_format vaf;
+
+   if (!ql_mask_match(level))
+   return;
+
+   va_start(va, fmt);
+
+   vaf.fmt = fmt;
+   vaf.va = 
+
+   if (qpair != NULL) {
+   const struct pci_dev *pdev = qpair->pdev;
+   /*   : Message */
+   pr_warn("%s [%s]-%04x: %pV",
+   QL_MSGHDR, dev_name(&(pdev->dev)), id + ql_dbg_offset,
+   );
+   } else {
+   pr_warn("%s [%s]-%04x: : %pV",
+   QL_MSGHDR, ":00:00.0", id + ql_dbg_offset, );
+   }
+
+   va_end(va);
+
+}
diff --git a/drivers/scsi/qla2xxx/qla_dbg.h b/drivers/scsi/qla2xxx/qla_dbg.h
index c6bffe929fe7..f60138f66dce 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.h
+++ b/drivers/scsi/qla2xxx/qla_dbg.h
@@ -313,12 +313,18 @@ void __attribute__((format (printf, 4, 5)))
 ql_dbg(uint32_t, scsi_qla_host_t *vha, int32_t, const char *fmt, ...);
 void __attribute__((format (printf, 4, 5)))
 ql_dbg_pci(uint32_t, struct pci_dev *pdev, int32_t, const char *fmt, ...);
+void __attribute__((format (printf, 4, 5)))
+ql_dbg_qp(uint32_t, struct qla_qpair *, int32_t, const char *fmt, ...);
+
 
 void __attribute__((format (printf, 4, 5)))
 ql_log(uint32_t, scsi_qla_host_t *vha, int32_t, const char *fmt, ...);
 void __attribute__((format (printf, 4, 5)))
 ql_log_pci(uint32_t, struct pci_dev *pdev, int32_t, const char *fmt, ...);
 
+void __attribute__((format (printf, 4, 5)))
+ql_log_qp(uint32_t, struct qla_qpair *, int32_t, const char *fmt, ...);
+
 /* Debug Levels */
 /* The 

[PATCH v2 15/15] qla2xxx: Update driver version to 9.01.00.00-k

2017-06-13 Thread Himanshu Madhani
Signed-off-by: Himanshu Madhani 
Signed-off-by: Giridhar Malavali 
---
 drivers/scsi/qla2xxx/qla_version.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_version.h 
b/drivers/scsi/qla2xxx/qla_version.h
index 45bc84e8e3bf..dcbb9bb05e99 100644
--- a/drivers/scsi/qla2xxx/qla_version.h
+++ b/drivers/scsi/qla2xxx/qla_version.h
@@ -7,9 +7,9 @@
 /*
  * Driver version
  */
-#define QLA2XXX_VERSION  "9.00.00.00-k"
+#define QLA2XXX_VERSION  "9.01.00.00-k"
 
 #define QLA_DRIVER_MAJOR_VER   9
-#define QLA_DRIVER_MINOR_VER   0
+#define QLA_DRIVER_MINOR_VER   1
 #define QLA_DRIVER_PATCH_VER   0
 #define QLA_DRIVER_BETA_VER0
-- 
2.12.0



[PATCH v2 13/15] qla2xxx: Move target stat counters from vha to qpair.

2017-06-13 Thread Himanshu Madhani
From: Quinn Tran 

Move counters to qpair to reduce cache miss.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h | 27 +++--
 drivers/scsi/qla2xxx/qla_dfs.c | 48 +++---
 drivers/scsi/qla2xxx/qla_iocb.c|  2 +-
 drivers/scsi/qla2xxx/qla_target.c  | 13 +--
 drivers/scsi/qla2xxx/tcm_qla2xxx.c |  8 +++
 5 files changed, 63 insertions(+), 35 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 17b13dd92511..e1af9db3691d 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3183,6 +3183,18 @@ struct qla_tc_param {
 #define QLA_MAX_VPORTS_QLA24XX 128
 #define QLA_MAX_VPORTS_QLA25XX 256
 
+struct qla_tgt_counters {
+   uint64_t qla_core_sbt_cmd;
+   uint64_t core_qla_que_buf;
+   uint64_t qla_core_ret_ctio;
+   uint64_t core_qla_snd_status;
+   uint64_t qla_core_ret_sta_ctio;
+   uint64_t core_qla_free_cmd;
+   uint64_t num_q_full_sent;
+   uint64_t num_alloc_iocb_failed;
+   uint64_t num_term_xchg_sent;
+};
+
 struct qla_qpair;
 
 /* Response queue data structure */
@@ -3285,6 +3297,7 @@ struct qla_qpair {
struct list_head qp_list_elem; /* vha->qp_list */
struct list_head hints_list;
uint16_t cpuid;
+   struct qla_tgt_counters tgt_counters;
 };
 
 /* Place holder for FW buffer parameters */
@@ -3964,18 +3977,6 @@ struct qla_hw_data {
int allow_cna_fw_dump;
 };
 
-struct qla_tgt_counters {
-   uint64_t qla_core_sbt_cmd;
-   uint64_t core_qla_que_buf;
-   uint64_t qla_core_ret_ctio;
-   uint64_t core_qla_snd_status;
-   uint64_t qla_core_ret_sta_ctio;
-   uint64_t core_qla_free_cmd;
-   uint64_t num_q_full_sent;
-   uint64_t num_alloc_iocb_failed;
-   uint64_t num_term_xchg_sent;
-};
-
 /*
  * Qlogic scsi host structure
  */
@@ -4140,10 +4141,8 @@ typedef struct scsi_qla_host {
struct fc_host_statistics fc_host_stat;
struct qla_statistics qla_stats;
struct bidi_statistics bidi_stats;
-
atomic_tvref_count;
struct qla8044_reset_template reset_tmplt;
-   struct qla_tgt_counters tgt_counters;
uint16_tbbcr;
struct name_list_extended gnl;
/* Count of active session/fcport */
diff --git a/drivers/scsi/qla2xxx/qla_dfs.c b/drivers/scsi/qla2xxx/qla_dfs.c
index 63d7374dce77..d231e7156134 100644
--- a/drivers/scsi/qla2xxx/qla_dfs.c
+++ b/drivers/scsi/qla2xxx/qla_dfs.c
@@ -164,26 +164,56 @@ static int
 qla_dfs_tgt_counters_show(struct seq_file *s, void *unused)
 {
struct scsi_qla_host *vha = s->private;
+   struct qla_qpair *qpair = vha->hw->base_qpair;
+   uint64_t qla_core_sbt_cmd, core_qla_que_buf, qla_core_ret_ctio,
+   core_qla_snd_status, qla_core_ret_sta_ctio, core_qla_free_cmd,
+   num_q_full_sent, num_alloc_iocb_failed, num_term_xchg_sent;
+   u16 i;
+
+   qla_core_sbt_cmd = qpair->tgt_counters.qla_core_sbt_cmd;
+   core_qla_que_buf = qpair->tgt_counters.core_qla_que_buf;
+   qla_core_ret_ctio = qpair->tgt_counters.qla_core_ret_ctio;
+   core_qla_snd_status = qpair->tgt_counters.core_qla_snd_status;
+   qla_core_ret_sta_ctio = qpair->tgt_counters.qla_core_ret_sta_ctio;
+   core_qla_free_cmd = qpair->tgt_counters.core_qla_free_cmd;
+   num_q_full_sent = qpair->tgt_counters.num_q_full_sent;
+   num_alloc_iocb_failed = qpair->tgt_counters.num_alloc_iocb_failed;
+   num_term_xchg_sent = qpair->tgt_counters.num_term_xchg_sent;
+
+   for (i = 0; i < vha->hw->max_qpairs; i++) {
+   qpair = vha->hw->queue_pair_map[i];
+   qla_core_sbt_cmd += qpair->tgt_counters.qla_core_sbt_cmd;
+   core_qla_que_buf += qpair->tgt_counters.core_qla_que_buf;
+   qla_core_ret_ctio += qpair->tgt_counters.qla_core_ret_ctio;
+   core_qla_snd_status += qpair->tgt_counters.core_qla_snd_status;
+   qla_core_ret_sta_ctio +=
+   qpair->tgt_counters.qla_core_ret_sta_ctio;
+   core_qla_free_cmd += qpair->tgt_counters.core_qla_free_cmd;
+   num_q_full_sent += qpair->tgt_counters.num_q_full_sent;
+   num_alloc_iocb_failed +=
+   qpair->tgt_counters.num_alloc_iocb_failed;
+   num_term_xchg_sent += qpair->tgt_counters.num_term_xchg_sent;
+   }
 
seq_puts(s, "Target Counters\n");
seq_printf(s, "qla_core_sbt_cmd = %lld\n",
-   vha->tgt_counters.qla_core_sbt_cmd);
+   qla_core_sbt_cmd);
seq_printf(s, "qla_core_ret_sta_ctio = %lld\n",
-   vha->tgt_counters.qla_core_ret_sta_ctio);
+   qla_core_ret_sta_ctio);
seq_printf(s, "qla_core_ret_ctio = %lld\n",
-   

[PATCH v2 09/15] qla2xxx: Add function call to qpair for door bell

2017-06-13 Thread Himanshu Madhani
From: Quinn Tran 

Add call back to door bell for qpair. This help
reduce access to qla_hw_data structure, in order
to reduce cach thrash.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h|  3 ++
 drivers/scsi/qla2xxx/qla_init.c   |  3 ++
 drivers/scsi/qla2xxx/qla_inline.h | 15 +
 drivers/scsi/qla2xxx/qla_os.c | 35 ---
 drivers/scsi/qla2xxx/qla_target.c | 71 +++
 drivers/scsi/qla2xxx/qla_target.h |  2 +-
 6 files changed, 94 insertions(+), 35 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index b3ba32773db4..17b13dd92511 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3272,6 +3272,9 @@ struct qla_qpair {
uint16_t vp_idx;/* vport ID */
mempool_t *srb_mempool;
 
+   struct pci_dev  *pdev;
+   void (*reqq_start_iocbs)(struct qla_qpair *);
+
/* to do: New driver: move queues to here instead of pointers */
struct req_que *req;
struct rsp_que *rsp;
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index f586f4f7dc57..48c0a58330d4 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -7653,6 +7653,9 @@ struct qla_qpair *qla2xxx_create_qpair(struct 
scsi_qla_host *vha, int qos,
 
qpair->msix->in_use = 1;
list_add_tail(>qp_list_elem, >qp_list);
+   qpair->pdev = ha->pdev;
+   if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
+   qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
 
mutex_unlock(>mq_lock);
 
diff --git a/drivers/scsi/qla2xxx/qla_inline.h 
b/drivers/scsi/qla2xxx/qla_inline.h
index bd8cb796f64e..9a2c86eacf44 100644
--- a/drivers/scsi/qla2xxx/qla_inline.h
+++ b/drivers/scsi/qla2xxx/qla_inline.h
@@ -352,3 +352,18 @@ qla_qpair_to_hint(struct qla_tgt *tgt, struct qla_qpair 
*qpair)
 
return NULL;
 }
+
+static inline void
+qla_83xx_start_iocbs(struct qla_qpair *qpair)
+{
+   struct req_que *req = qpair->req;
+
+   req->ring_index++;
+   if (req->ring_index == req->length) {
+   req->ring_index = 0;
+   req->ring_ptr = req->ring;
+   } else
+   req->ring_ptr++;
+
+   WRT_REG_DWORD(req->req_q_in, req->ring_index);
+}
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 1d66954b7e5a..88e115fcea60 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -351,6 +351,28 @@ int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct 
scsi_cmnd *cmd,
struct qla_qpair *qpair);
 
 /* -- 
*/
+static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
+struct rsp_que *rsp)
+{
+   struct qla_hw_data *ha = vha->hw;
+   rsp->qpair = ha->base_qpair;
+   rsp->req = req;
+   ha->base_qpair->req = req;
+   ha->base_qpair->rsp = rsp;
+   ha->base_qpair->vha = vha;
+   ha->base_qpair->qp_lock_ptr = >hardware_lock;
+   ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
+   ha->base_qpair->msix = >msix_entries[QLA_MSIX_RSP_Q];
+   INIT_LIST_HEAD(>base_qpair->hints_list);
+   ha->base_qpair->enable_class_2 = ql2xenableclass2;
+   /* init qpair to this cpu. Will adjust at run time. */
+   qla_cpu_update(rsp->qpair, smp_processor_id());
+   ha->base_qpair->pdev = ha->pdev;
+
+   if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
+   ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
+}
+
 static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
struct rsp_que *rsp)
 {
@@ -378,18 +400,7 @@ static int qla2x00_alloc_queues(struct qla_hw_data *ha, 
struct req_que *req,
goto fail_base_qpair;
}
 
-   rsp->qpair = ha->base_qpair;
-   rsp->req = req;
-   ha->base_qpair->req = req;
-   ha->base_qpair->rsp = rsp;
-   ha->base_qpair->vha = vha;
-   ha->base_qpair->qp_lock_ptr = >hardware_lock;
-   ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
-   /* init qpair to this cpu. Will adjust at run time. */
-   ha->base_qpair->msix = >msix_entries[QLA_MSIX_RSP_Q];
-   INIT_LIST_HEAD(>base_qpair->hints_list);
-   ha->base_qpair->enable_class_2 = ql2xenableclass2;
-   qla_cpu_update(rsp->qpair, smp_processor_id());
+   qla_init_base_qpair(vha, req, rsp);
 
if (ql2xmqsupport && ha->max_qpairs) {
ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct 
qla_qpair *),
diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index 1d6cc24c0640..f18a50867119 100644
--- 

[PATCH v2 02/15] qla2xxx: Preparation for Target MQ.

2017-06-13 Thread Himanshu Madhani
From: Quinn Tran 

In Current code, Req Q 0, RespQ 0 & hardware_lock
are the main resources for sending and process completion
of Target IO. These resources are now referenced
behind a new qpair/"struct qla_qpair base_qpair".
Main path IO handle will access those resources via the
qpair pointer in preparation for Target MQ.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_attr.c   |   2 +-
 drivers/scsi/qla2xxx/qla_def.h|  17 +-
 drivers/scsi/qla2xxx/qla_gbl.h|  15 +-
 drivers/scsi/qla2xxx/qla_init.c   |  11 +-
 drivers/scsi/qla2xxx/qla_iocb.c   |  30 ++-
 drivers/scsi/qla2xxx/qla_isr.c|  11 +-
 drivers/scsi/qla2xxx/qla_mid.c|  40 +--
 drivers/scsi/qla2xxx/qla_os.c |  23 +-
 drivers/scsi/qla2xxx/qla_target.c | 518 --
 drivers/scsi/qla2xxx/qla_target.h |  10 +-
 10 files changed, 380 insertions(+), 297 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index a93eb42718e5..f0f16d313faf 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -2096,7 +2096,7 @@ qla24xx_vport_create(struct fc_vport *fc_vport, bool 
disable)
}
 
if (qos) {
-   qpair = qla2xxx_create_qpair(vha, qos, vha->vp_idx);
+   qpair = qla2xxx_create_qpair(vha, qos, vha->vp_idx, true);
if (!qpair)
ql_log(ql_log_warn, vha, 0x7084,
"Can't create qpair for VP[%d]\n",
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 1b5049b1ef4a..64109134e276 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3182,6 +3182,9 @@ struct qla_tc_param {
 #define QLA_PRECONFIG_VPORTS 32
 #define QLA_MAX_VPORTS_QLA24XX 128
 #define QLA_MAX_VPORTS_QLA25XX 256
+
+struct qla_qpair;
+
 /* Response queue data structure */
 struct rsp_que {
dma_addr_t  dma;
@@ -3201,6 +3204,7 @@ struct rsp_que {
struct qla_msix_entry *msix;
struct req_que *req;
srb_t *status_srb; /* status continuation entry */
+   struct qla_qpair *qpair;
 
dma_addr_t  dma_fx00;
response_t *ring_fx00;
@@ -3241,6 +3245,14 @@ struct req_que {
 struct qla_qpair {
spinlock_t qp_lock;
atomic_t ref_count;
+
+   /*
+* For qpair 0, qp_lock_ptr will point at hardware_lock due to
+* legacy code. For other Qpair(s), it will point at qp_lock.
+*/
+   spinlock_t *qp_lock_ptr;
+   struct scsi_qla_host *vha;
+
/* distill these fields down to 'online=0/1'
 * ha->flags.eeh_busy
 * ha->flags.pci_channel_io_perm_failure
@@ -3252,10 +3264,7 @@ struct qla_qpair {
uint32_t delete_in_progress:1;
 
uint16_t id;/* qp number used with FW */
-   uint16_t num_active_cmd;/* cmds down at firmware */
-   cpumask_t cpu_mask; /* CPU mask for cpu affinity operation */
uint16_t vp_idx;/* vport ID */
-
mempool_t *srb_mempool;
 
/* to do: New driver: move queues to here instead of pointers */
@@ -3266,7 +3275,7 @@ struct qla_qpair {
struct qla_hw_data *hw;
struct work_struct q_work;
struct list_head qp_list_elem; /* vha->qp_list */
-   struct scsi_qla_host *vha;
+   uint16_t cpuid;
 };
 
 /* Place holder for FW buffer parameters */
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index 63355f40ff2f..f5493eda0110 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -77,8 +77,7 @@ struct qla_work_evt *qla2x00_alloc_work(struct scsi_qla_host 
*,
 enum qla_work_type);
 extern int qla24xx_async_gnl(struct scsi_qla_host *, fc_port_t *);
 int qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e);
-extern void *qla2x00_alloc_iocbs(struct scsi_qla_host *, srb_t *);
-extern void *qla2x00_alloc_iocbs_ready(struct scsi_qla_host *, srb_t *);
+extern void *qla2x00_alloc_iocbs_ready(struct qla_qpair *, srb_t *);
 extern int qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *, fc_port_t *);
 
 extern fc_port_t *
@@ -96,7 +95,7 @@ qla2x00_alloc_outstanding_cmds(struct qla_hw_data *, struct 
req_que *);
 extern int qla2x00_init_rings(scsi_qla_host_t *);
 extern uint8_t qla27xx_find_valid_image(struct scsi_qla_host *);
 extern struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *,
-   int, int);
+   int, int, bool);
 extern int qla2xxx_delete_qpair(struct scsi_qla_host *, struct qla_qpair *);
 void qla2x00_fcport_event_handler(scsi_qla_host_t *, struct event_arg *);
 int qla24xx_async_gpdb(struct scsi_qla_host *, fc_port_t *, u8);
@@ -255,7 +254,8 @@ extern int qla2x00_start_bidir(srb_t *, struct 
scsi_qla_host *, uint32_t);
 extern int qla2xxx_dif_start_scsi_mq(srb_t *);
 extern unsigned long 

[PATCH v2 12/15] qla2xxx: Remove datasegs_per_cmd and datasegs_per_cont field

2017-06-13 Thread Himanshu Madhani
From: Quinn Tran 

These fields only hold one set of value. Replace it with
macros to reduce cache thrash.

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

diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index 411c1799c6e3..48d82c67e223 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -2228,10 +2228,10 @@ static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm)
 * If greater than four sg entries then we need to allocate
 * the continuation entries
 */
-   if (prm->seg_cnt > prm->tgt->datasegs_per_cmd)
+   if (prm->seg_cnt > QLA_TGT_DATASEGS_PER_CMD_24XX)
prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt -
-   prm->tgt->datasegs_per_cmd,
-   prm->tgt->datasegs_per_cont);
+   QLA_TGT_DATASEGS_PER_CMD_24XX,
+   QLA_TGT_DATASEGS_PER_CONT_24XX);
} else {
/* DIF */
if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) ||
@@ -2448,7 +2448,7 @@ static void qlt_load_cont_data_segments(struct 
qla_tgt_prm *prm)
 
/* Load continuation entry data segments */
for (cnt = 0;
-   cnt < prm->tgt->datasegs_per_cont && prm->seg_cnt;
+   cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt;
cnt++, prm->seg_cnt--) {
*dword_ptr++ =
cpu_to_le32(pci_dma_lo32
@@ -2492,7 +2492,7 @@ static void qlt_load_data_segments(struct qla_tgt_prm 
*prm)
 
/* Load command entry data segments */
for (cnt = 0;
-   (cnt < prm->tgt->datasegs_per_cmd) && prm->seg_cnt;
+   (cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt;
cnt++, prm->seg_cnt--) {
*dword_ptr++ =
cpu_to_le32(pci_dma_lo32(sg_dma_address(prm->sg)));
@@ -6170,8 +6170,6 @@ int qlt_add_target(struct qla_hw_data *ha, struct 
scsi_qla_host *base_vha)
base_vha->vp_idx);
/* 3 is reserved */
tgt->sg_tablesize = QLA_TGT_MAX_SG_24XX(base_vha->req->length - 3);
-   tgt->datasegs_per_cmd = QLA_TGT_DATASEGS_PER_CMD_24XX;
-   tgt->datasegs_per_cont = QLA_TGT_DATASEGS_PER_CONT_24XX;
 
mutex_lock(_tgt_mutex);
list_add_tail(>tgt_list_entry, _tgt_glist);
diff --git a/drivers/scsi/qla2xxx/qla_target.h 
b/drivers/scsi/qla2xxx/qla_target.h
index 902685f85506..7fe02d036bdf 100644
--- a/drivers/scsi/qla2xxx/qla_target.h
+++ b/drivers/scsi/qla2xxx/qla_target.h
@@ -806,7 +806,7 @@ struct qla_tgt {
 */
int atio_irq_cmd_count;
 
-   int datasegs_per_cmd, datasegs_per_cont, sg_tablesize;
+   int sg_tablesize;
 
/* Target's flags, serialized by pha->hardware_lock */
unsigned int link_reinit_iocb_pending:1;
-- 
2.12.0



[PATCH v2 00/15] qla2xxx: Add Target Multiqueue support

2017-06-13 Thread Himanshu Madhani
Hi Martin, Nic,

This patch series adds support for multiqueue for qla2xxx target mode driver.

This series depends on the seris applied to Martin's scsi/for-next branch
(https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git/log/?h=for-next)

I've also added followig patch ("qla2xxx: Include Exchange offload/Extended
Login into FW dump") which was dropped from earlier series for rework.

I am planning to send series for FC-NVME support as well which depends on this
series, so I would like this series to be applied to scsi tree instead of
target-pending for only this submission, as both series touches common code
in qla2xxx driver. 

Please apply this series to for-next for inclusion in 4.13 merge window.

Note: Comment from Bart for patch#1 will be addresed as new patch after our 
  FC-NVME series is posted. 

Changes from v1 --> v2

o Fixed 0-day kernel compile failure

Thanks,
Himanshu 

Himanshu Madhani (1):
  qla2xxx: Update driver version to 9.01.00.00-k

Quinn Tran (13):
  qla2xxx: Combine Active command arrays.
  qla2xxx: Preparation for Target MQ.
  qla2xxx: Enable Target Multi Queue
  qla2xxx: Add debug knob for user control workload
  qla2xxx: Add fw_started flags to qpair
  qla2xxx: move fields from qla_hw_data to qla_qpair
  qla2xxx: use shadow register for ISP27XX
  qla2xxx: Add function call to qpair for door bell
  qla2xxx: Add debug logging routine for qpair
  qla2xxx: Remove unused tgt_enable_64bit_addr flag
  qla2xxx: Remove datasegs_per_cmd and datasegs_per_cont field
  qla2xxx: Move target stat counters from vha to qpair.
  qla2xxx: Include Exchange offload/Extended Login into FW dump

Sawan Chandak (1):
  qla2xxx: Fix mailbox failure while deleting Queue pairs

 drivers/scsi/qla2xxx/qla_attr.c|4 +-
 drivers/scsi/qla2xxx/qla_dbg.c |  150 ++
 drivers/scsi/qla2xxx/qla_dbg.h |   17 +
 drivers/scsi/qla2xxx/qla_def.h |  119 -
 drivers/scsi/qla2xxx/qla_dfs.c |  137 -
 drivers/scsi/qla2xxx/qla_gbl.h |   19 +-
 drivers/scsi/qla2xxx/qla_init.c|   53 +-
 drivers/scsi/qla2xxx/qla_inline.h  |   44 ++
 drivers/scsi/qla2xxx/qla_iocb.c|   32 +-
 drivers/scsi/qla2xxx/qla_isr.c |   93 +++-
 drivers/scsi/qla2xxx/qla_mid.c |   44 +-
 drivers/scsi/qla2xxx/qla_os.c  |  156 --
 drivers/scsi/qla2xxx/qla_target.c  | 1028 +---
 drivers/scsi/qla2xxx/qla_target.h  |   50 +-
 drivers/scsi/qla2xxx/qla_version.h |4 +-
 drivers/scsi/qla2xxx/tcm_qla2xxx.c |8 +-
 16 files changed, 1348 insertions(+), 610 deletions(-)

-- 
2.12.0



[PATCH v2 01/15] qla2xxx: Combine Active command arrays.

2017-06-13 Thread Himanshu Madhani
From: Quinn Tran 

Merge active/outstanding cmd arrays from target side
and initiator side together in prepration for Target
Multi Queue support.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h|  15 +++-
 drivers/scsi/qla2xxx/qla_gbl.h|   2 -
 drivers/scsi/qla2xxx/qla_inline.h |   1 +
 drivers/scsi/qla2xxx/qla_isr.c|  48 +
 drivers/scsi/qla2xxx/qla_os.c |  75 ++--
 drivers/scsi/qla2xxx/qla_target.c | 144 --
 drivers/scsi/qla2xxx/qla_target.h |  23 --
 7 files changed, 164 insertions(+), 144 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index ddf93efe3986..1b5049b1ef4a 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -437,7 +437,18 @@ struct srb_iocb {
 #define SRB_NACK_PRLI  17
 #define SRB_NACK_LOGO  18
 
+enum {
+   TYPE_SRB,
+   TYPE_TGT_CMD,
+};
+
 typedef struct srb {
+   /*
+* Do not move cmd_type field, it needs to
+* line up with qla_tgt_cmd->cmd_type
+*/
+   uint8_t cmd_type;
+   uint8_t pad[3];
atomic_t ref_count;
struct fc_port *fcport;
struct scsi_qla_host *vha;
@@ -3287,9 +3298,6 @@ struct qlt_hw_data {
uint32_t __iomem *atio_q_out;
 
struct qla_tgt_func_tmpl *tgt_ops;
-   struct qla_tgt_cmd *cmds[DEFAULT_OUTSTANDING_COMMANDS];
-   uint16_t current_handle;
-
struct qla_tgt_vp_map *tgt_vp_map;
 
int saved_set;
@@ -4258,6 +4266,7 @@ enum nexus_wait_type {
WAIT_LUN,
 };
 
+#include "qla_target.h"
 #include "qla_gbl.h"
 #include "qla_dbg.h"
 #include "qla_inline.h"
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index f8540f5c9e5d..63355f40ff2f 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -834,8 +834,6 @@ extern irqreturn_t qla8044_intr_handler(int, void *);
 extern void qla82xx_mbx_completion(scsi_qla_host_t *, uint16_t);
 extern int qla8044_abort_isp(scsi_qla_host_t *);
 extern int qla8044_check_fw_alive(struct scsi_qla_host *);
-
-extern void qlt_host_reset_handler(struct qla_hw_data *ha);
 extern int qla_get_exlogin_status(scsi_qla_host_t *, uint16_t *,
uint16_t *);
 extern int qla_set_exlogin_mem_cfg(scsi_qla_host_t *vha, dma_addr_t phys_addr);
diff --git a/drivers/scsi/qla2xxx/qla_inline.h 
b/drivers/scsi/qla2xxx/qla_inline.h
index 9996ec0daab1..99028d48c664 100644
--- a/drivers/scsi/qla2xxx/qla_inline.h
+++ b/drivers/scsi/qla2xxx/qla_inline.h
@@ -250,6 +250,7 @@ qla2x00_get_sp(scsi_qla_host_t *vha, fc_port_t *fcport, 
gfp_t flag)
 
memset(sp, 0, sizeof(*sp));
sp->fcport = fcport;
+   sp->cmd_type = TYPE_SRB;
sp->iocbs = 1;
sp->vha = vha;
 done:
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 2984abcc29e7..8aaddb75f964 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -17,7 +17,7 @@
 static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
 static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
 static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *);
-static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
+static int qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
sts_entry_t *);
 
 /**
@@ -2280,6 +2280,14 @@ qla2x00_status_entry(scsi_qla_host_t *vha, struct 
rsp_que *rsp, void *pkt)
return;
}
 
+   if (sp->cmd_type != TYPE_SRB) {
+   req->outstanding_cmds[handle] = NULL;
+   ql_dbg(ql_dbg_io, vha, 0x3015,
+   "Unknown sp->cmd_type %x %p).\n",
+   sp->cmd_type, sp);
+   return;
+   }
+
if (unlikely((state_flags & BIT_1) && (sp->type == SRB_BIDI_CMD))) {
qla25xx_process_bidir_status_iocb(vha, pkt, req, handle);
return;
@@ -2632,8 +2640,9 @@ qla2x00_status_cont_entry(struct rsp_que *rsp, 
sts_cont_entry_t *pkt)
  * qla2x00_error_entry() - Process an error entry.
  * @ha: SCSI driver HA context
  * @pkt: Entry pointer
+ * return : 1=allow further error analysis. 0=no additional error analysis.
  */
-static void
+static int
 qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t 
*pkt)
 {
srb_t *sp;
@@ -2654,18 +2663,35 @@ qla2x00_error_entry(scsi_qla_host_t *vha, struct 
rsp_que *rsp, sts_entry_t *pkt)
if (pkt->entry_status & RF_BUSY)
res = DID_BUS_BUSY << 16;
 
-   if (pkt->entry_type == NOTIFY_ACK_TYPE &&
-   pkt->handle == QLA_TGT_SKIP_HANDLE)
-   return;
+   if ((pkt->handle & ~QLA_TGT_HANDLE_MASK) == QLA_TGT_SKIP_HANDLE)
+   return 0;
 
-   sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
-   

[PATCH v2] storvsc: use default I/O timeout handler for FC devices

2017-06-13 Thread Long Li
From: Long Li 

FC disks issue I/O directly to the host storage port driver, this is
diffirent to VHD disks where I/O is virtualized and timeout is handled
by the host VSP (Virtualization Service Provider).

FC disks are usually setup in a multipath system, and they don't want to
reset timer on I/O timeout. Timeout is detected by multipath as a good 
time to failover and recover.

Patch v2 includes suggestions from Bart Van Assche


Signed-off-by: Long Li 
---
 drivers/scsi/storvsc_drv.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 8d955db..3cc8d67 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -1495,6 +1495,10 @@ static int storvsc_host_reset_handler(struct scsi_cmnd 
*scmnd)
  */
 static enum blk_eh_timer_return storvsc_eh_timed_out(struct scsi_cmnd *scmnd)
 {
+#if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
+   if (scmnd->device->host->transportt == fc_transport_template)
+   return fc_eh_timed_out(scmnd);
+#endif
return BLK_EH_RESET_TIMER;
 }
 
-- 
2.7.4



RE: [PATCH] scsi: aacraid: fix leak of data from stack back to userspace

2017-06-13 Thread Dave Carroll
> -Original Message-
> From: Colin King [mailto:colin.k...@canonical.com]
> Sent: Monday, May 15, 2017 8:56 AM
> To: Raghava Aditya Renukunta ;
> dl-esc-Aacraid Linux Driver ; James E . J . Bottomley
> ; Martin K . Petersen
> ; linux-scsi@vger.kernel.org
> Cc: kernel-janit...@vger.kernel.org; linux-ker...@vger.kernel.org
> Subject: [PATCH] scsi: aacraid: fix leak of data from stack back to userspace
> 
> From: Colin Ian King 
> 
> The fields sense_data_size and sense_data are unitialized garbage from the
> stack and are being copied back to userspace.  Fix this leak of stack 
> information
> by ensuring they are zero'd.
> 
> Detected by CoverityScan, CID#1435473 ("Uninitialized scalar variable")
> 
> Fixes: 423400e64d377 ("scsi: aacraid: Include HBA direct interface")
> Signed-off-by: Colin Ian King 
> ---
>  drivers/scsi/aacraid/commctrl.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
Acked-by: Dave Carroll 


RE: [Possible Phish Fraud][PATCH] storvsc: use default I/O timeout handler for FC devices

2017-06-13 Thread Long Li


> -Original Message-
> From: Bart Van Assche [mailto:bart.vanass...@sandisk.com]
> Sent: Tuesday, June 13, 2017 8:38 AM
> To: linux-ker...@vger.kernel.org; KY Srinivasan ;
> martin.peter...@oracle.com; linux-scsi@vger.kernel.org; Stephen Hemminger
> ; Long Li ;
> j...@linux.vnet.ibm.com; Haiyang Zhang 
> Cc: jthumsh...@suse.de; Long Li 
> Subject: Re: [Possible Phish Fraud][PATCH] storvsc: use default I/O timeout
> handler for FC devices
> 
> On Mon, 2017-06-12 at 17:23 -0700, Long Li wrote:
> > From: Long Li 
> >
> > FC disks are usually setup in a multipath system, and they don't want
> > to unconditionaly reset I/O on timeout. I/O timeout is detected by
> > multipath as a good time to failover and recover.
> >
> > Signed-off-by: Long Li 
> > ---
> >  drivers/scsi/storvsc_drv.c | 7 +++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
> > index 8d955db..d60b5ea 100644
> > --- a/drivers/scsi/storvsc_drv.c
> > +++ b/drivers/scsi/storvsc_drv.c
> > @@ -486,6 +486,7 @@ struct hv_host_device {
> > unsigned int port;
> > unsigned char path;
> > unsigned char target;
> > +   bool is_fc;
> >  };
> >
> >  struct storvsc_scan_work {
> > @@ -1495,6 +1496,11 @@ static int storvsc_host_reset_handler(struct
> scsi_cmnd *scmnd)
> >   */
> >  static enum blk_eh_timer_return storvsc_eh_timed_out(struct scsi_cmnd
> > *scmnd)  {
> > +   struct hv_host_device *host_dev = shost_priv(scmnd->device->host);
> > +
> > +   if (host_dev->is_fc)
> > +   return BLK_EH_NOT_HANDLED;
> > +
> > return BLK_EH_RESET_TIMER;
> >  }
> >
> > @@ -1738,6 +1744,7 @@ static int storvsc_probe(struct hv_device
> > *device,
> >
> > host_dev->port = host->host_no;
> > host_dev->dev = device;
> > +   host_dev->is_fc = is_fc;
> >
> >
> > stor_device = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL);
> 
> Hello Long,
> 
> As far as I know there is no other SCSI driver nor block driver in the Linux 
> kernel
> tree that returns BLK_EH_RESET_TIMER unconditionally. Would a valid
> alternative fix be to remove storvsc_eh_timed_out() entirely? If not, what
> would break if that function would be removed entirely?

Storvsc handles virtualized devices for Hyper-V and Azure. The host decides on 
how to handle I/O timeout, and makes decision based on how long I/O has been in 
flight. This is why we use BLK_EH_RESET_TIMER and leave the I/O timeout 
handling to the host for most cases.

> 
> Additionally, for FC, shouldn't that timeout handler handle the "port blocked"
> state? Shouldn't fc_eh_timed_out() be used for FC instead of just returning
> BLK_EH_NOT_HANDLED?

I agree with you. Storvsc didn't expose rport state. But this has changed with 
a recent commit daf0cd445a218314f9461d67d4f2b9c24cdd534b. I'll send a V2 to 
address this.

Thank you

Long

> 
> Thanks,
> 
> Bart.


Re: [PATCH 0/7] Enable iSCSI offload drivers to use information from iface.

2017-06-13 Thread Robert LeBlanc
On Wed, Jun 7, 2017 at 12:30 PM, Robert LeBlanc  wrote:
> On Wed, Jun 7, 2017 at 10:28 AM, Chris Leech  wrote:
>> On Tue, Jun 06, 2017 at 12:07:10PM -0600, Robert LeBlanc wrote:
>>> This patchset enables iSCSI offload drivers to have access to the iface
>>> information provided by iscsid. This allows users to have more control
>>> of how the driver connects to the iSCSI target. iSER is updated to use
>>> iface.ipaddress to set the source IP address if configured. This allows
>>> iSER to use multiple ports on the same network or in more complicated
>>> routed configurations.
>>>
>>> Since there is already a change to the function parameters, dst_addr
>>> is upgraded to sockaddr_storage so that it is more future proof and makes
>>> the size of the struct static and not dependent on checking the SA_FAMILY.
>>>
>>> This is dependent on updates to Open-iSCSI.
>>
>> Hi Robert,
>>
>> I don't think that passing the iface_rec structure directly from the
>> iscsid internals into a netlink message is a good way to go about this.
>> It's really big, there's an embedded list_head with user address
>> pointers that needs to be left out, and there are 32/64-bit layout
>> differences.
>>
>> Let me take a look at how you're proposing using this info for iSER, if
>> it makes sense I think we should come up with a better designed
>> structure for passing the information.
>>
>> Thanks,
>> Chris
>>
>
> Chris,
>
> Thank you for your feedback. I agree that the entire iface is probably
> overkill, it was more of a proof of concept. We are only using the
> ipaddress in the iface for iSER (in my patch), but I could see other
> drivers benefiting from some of the other data in the iface (mac,
> interface_name, vlan, etc) so I didn't want to be too restrictive so
> that it wouldn't have to be extended later. I've not worked on
> userspace/kernel interaction before so I need some guidance to make
> the transition between userspace and kernel versions smoother.
>
> This patchset works for what we need and it is very important for us
> (and I'm sure others once the feature is available) and I'm happy to
> put in the time to get it accepted upstream, I'm just new to kernel
> development and need some guidance.

Are there other comments/ideas/suggestions specifically from the
iSCSI/iSER guys? I'd like to keep this patch moving.

Thanks.


Robert LeBlanc
PGP Fingerprint 79A2 9CA4 6CC4 45DD A904  C70E E654 3BB2 FA62 B9F1


Re: [Possible Phish Fraud][PATCH] storvsc: use default I/O timeout handler for FC devices

2017-06-13 Thread Bart Van Assche
On Mon, 2017-06-12 at 17:23 -0700, Long Li wrote:
> From: Long Li 
> 
> FC disks are usually setup in a multipath system, and they don't want to 
> unconditionaly reset I/O on timeout. I/O timeout is detected by multipath 
> as a good time to failover and recover.
> 
> Signed-off-by: Long Li 
> ---
>  drivers/scsi/storvsc_drv.c | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
> index 8d955db..d60b5ea 100644
> --- a/drivers/scsi/storvsc_drv.c
> +++ b/drivers/scsi/storvsc_drv.c
> @@ -486,6 +486,7 @@ struct hv_host_device {
>   unsigned int port;
>   unsigned char path;
>   unsigned char target;
> + bool is_fc;
>  };
>  
>  struct storvsc_scan_work {
> @@ -1495,6 +1496,11 @@ static int storvsc_host_reset_handler(struct scsi_cmnd 
> *scmnd)
>   */
>  static enum blk_eh_timer_return storvsc_eh_timed_out(struct scsi_cmnd *scmnd)
>  {
> + struct hv_host_device *host_dev = shost_priv(scmnd->device->host);
> +
> + if (host_dev->is_fc)
> + return BLK_EH_NOT_HANDLED;
> +
>   return BLK_EH_RESET_TIMER;
>  }
>  
> @@ -1738,6 +1744,7 @@ static int storvsc_probe(struct hv_device *device,
>  
>   host_dev->port = host->host_no;
>   host_dev->dev = device;
> + host_dev->is_fc = is_fc;
>  
>  
>   stor_device = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL);

Hello Long,

As far as I know there is no other SCSI driver nor block driver in the Linux
kernel tree that returns BLK_EH_RESET_TIMER unconditionally. Would a valid
alternative fix be to remove storvsc_eh_timed_out() entirely? If not, what
would break if that function would be removed entirely?

Additionally, for FC, shouldn't that timeout handler handle the "port blocked"
state? Shouldn't fc_eh_timed_out() be used for FC instead of just returning
BLK_EH_NOT_HANDLED?

Thanks,

Bart.

Re: [ANNOUNCE]: Broadcom (Emulex) FC Target driver - efct

2017-06-13 Thread Martin K. Petersen

James,

> To start this effort, I'd like a bcmlpfc directory to be made within
> the drivers staging tree. The directory would be populated with the
> efct driver and a copy of the existing lpfc driver.  Work can then
> commence on refactoring lpfc and creating the libraries and
> integrating the libraries into both drivers.  As lpfc is updated in
> the main tree, patches would be posted to the staging version of lpfc
> to keep them on par.

Sounds good to me.

> a) How best to deal with overlapping pci id's ?  E.g. if we do (1) and
> we have an initiator and target driver, there is a lot of adapters
> that are fully functional for target operation, but were sold as
> primarily an initiator adapter. How could we manage target mode
> enablement without code mod or hard pci id partitioning ?  I know
> individual pci unbind/bind could work, but its been frowned upon as a
> long term option. Same thing goes for module parameters to select
> which ports do what role.

I don't have a problem with the binding approach. A bit easier for the
sysadmin to script and manage compared to PCI ID-specific module
parameters that may come with initramfs rebuilds or grub tweaks and
reboots.

I also think the binding approach eases that pain for systems that want,
say, initiator for root fs on one port and target on the other. And
gives you the flexibility to use the WWN or sysfs attributes other than
the PCI ID to locate the ports whose affiliation you want to change.

> b) Assuming we have the lpfc copy in the bcmlpfc directory in the
> staging tree: are there any issues with having a version of lpfc in the
> main tree and another in the staging tree ? For many reasons, I'd
> like to keep the name lpfc on the initiator driver in the staging
> tree. But is that possible ? I assume we would need to develop in the
> staging tree as a new name and pci id space separate from the base
> driver, and we can rename the staging driver to the lpfc name when it
> merges into the main kernel and replaces the existing driver.

I'm with Christoph in terms of avoiding staging. It's better to do out
of tree. And as far as naming is concerned, you have some flexibility in
terms of string prefixes for printk's, module aliases, etc. And then a
final tweak to get things shuffled into place before merging into
mainline.

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH 6/6] sd: add support for TCG OPAL self encrypting disks

2017-06-13 Thread Martin K. Petersen

Christoph,

>> But as we already set no_report_opcodes for all usb-storage and
>> quirked uas devices I think the worst offenders are already covered
>> anyway.
>
> Martin, how do we want to move ahead on this patch?

I was suggesting the VPD because that may be easier for the SAS HBA
vendors to accommodate for SATA passthrough. But we can cross that
bridge when we get to it.

For libata I'm fine with keying off a supports_opal:1 flag in
scsi_device or something to that effect. I'd just like to reduce the
risk of introducing more RSOC regressions.

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH 20/22] scsi: hisi_sas: Add v3 code to support ECC and AXI bus fatal error

2017-06-13 Thread John Garry

On 17/05/2017 13:38, John Garry wrote:

On 17/05/2017 13:27, Arnd Bergmann wrote:

On Wed, May 17, 2017 at 12:49 PM, John Garry 
wrote:

> From: Xiang Chen 
>
> For ECC 1bit error, logic can recover it, so we only print a warning.
> For ECC multi-bit and AXI bus fatal error, we panic.
>
> Signed-off-by: John Garry 
> Signed-off-by: Xiang Chen 

This one is tricky as there are conflicting requirements:

- For debugging purposes, you want to continue running the system
  to figure out what exactly went wrong. Often enough, having the
  kernel panic means you don't get to see the panic message because
  console access is unavailable and you cannot log in any more

- For data consistency purposes you want to stop the system as
  soon as there is any uncorrectable data error

I see that most scsi drivers don't ever call panic or BUG(), though
you already do so for v1 and v2 hw.

Maybe the SCSI maintainers can provide some more guidance here.

  Arnd

.



Hi Arnd,

Actually latest code for v2 has been updated to do a controller reset,
and not panic, for unrecoverable error:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c?h=v4.12-rc1#n2926


We never got around to implementing controller reset for v1 as this
platform (hip05) is not used much anymore.

As for v3, we will change to to do same once controller reset is
implemented. I should have added this to the commit log.

Thanks,
John


It has come to light that hip08 RAS architecture requires handling 
certain errors with firmware first model. I am not sure on the flow of 
controller reset for fatal errors - I'm currently checking the details.


But it is not worth adding this non-critical patch and reverting it 
later, so I'll omit this patch when sending the v6 patchset which 
includes the fix for sloppy spinlock usage.


Thanks,
John




RE: Application stops due to ext4 filesytsem IO error

2017-06-13 Thread Sumit Saxena
Gentle ping.

I have opened kernel BZ for this. Here is the BZ link-
https://bugzilla.kernel.org/show_bug.cgi?id=196057

Thanks,
Sumit
>-Original Message-
>From: Sumit Saxena [mailto:sumit.sax...@broadcom.com]
>Sent: Tuesday, June 06, 2017 9:05 PM
>To: 'Jens Axboe'
>Cc: 'linux-bl...@vger.kernel.org'; 'linux-scsi@vger.kernel.org'
>Subject: RE: Application stops due to ext4 filesytsem IO error
>
>Gentle ping..
>
>>-Original Message-
>>From: Sumit Saxena [mailto:sumit.sax...@broadcom.com]
>>Sent: Monday, June 05, 2017 12:59 PM
>>To: 'Jens Axboe'
>>Cc: 'linux-bl...@vger.kernel.org'; 'linux-scsi@vger.kernel.org'
>>Subject: Application stops due to ext4 filesytsem IO error
>>
>>Jens,
>>
>>We am observing  application stops while running ext4 filesystem IOs
>>along with target reset in parallel.
>>Our suspect is this behavior can be attributed to linux block layer.
>>See below for details-
>>
>>Problem statement - " Application stops due to IO error from file
>>system buffered IO. (Note - It is always a FS meta data read failure)"
>>Issue is reproducible - "Yes. It is consistently reproducible."
>>Brief about setup -
>>Latest 4.11 kernel. Issue hits irrespective of whether SCSI MQ is
>>enabled or disabled. use_blk_mq=Y and use_blk_mq=N has similar issue.
>>Direct attached 4 SAS/SATA drives connected to MegaRAID Invader
>>controller.
>>
>>Reproduction steps -
>>-Create ext4 FS on 4 JBODs(non RAID volumes) behind MegaRAID SAS
>>controller.
>>-Start Data integrity test on all four ext4 mounted partition. (Tool
>>should be configured to send Buffered FS IO).
>>-Send Target Reset  (have some delay between next reset to allow some
>>IO on device) on each JBOD to simulate error condition. (sg_reset -d
>/dev/sdX).
>>
>>End result -
>>Combination of target resets and FS IOs in parallel causes application
>>halt with ext4 Filesystem IO error.
>>We are able to restart  application without cleaning and unmounting
>>filesystem.
>>Below are the error logs at the time of application stop-
>>
>>--
>>sd 0:0:53:0: target reset called for
>>scmd(88003cf25148)
>>sd 0:0:53:0: attempting target reset!
>>scmd(88003cf25148) tm_dev_handle 0xb
>>sd 0:0:53:0: [sde] tag#519 BRCM Debug: request->cmd_flags: 0x80700
>bio-
>>>bi_flags: 0x2  bio->bi_opf: 0x3000 rq_flags 0x20e3
>>..
>>sd 0:0:53:0: [sde] tag#519 CDB: Read(10) 28 00 15 00 11 10 00 00 f8 00
>>EXT4-fs error (device sde): __ext4_get_inode_loc:4465: inode #11018287:
>>block 44040738: comm chaos: unable to read itable block
>>---
>>
>>We debug further to understand what is happening above LLD. See below-
>>
>>During target reset,  there may be IO coming from target with CHECK
>>CONDITION with below sense information-.
>>Sense Key : Aborted Command [current]
>>Add. Sense: No additional sense information
>>
>>Such Aborted command should be retried by SML/Block layer. This happens
>>from SML expect for FS Meta data read.
>>From driver level debug, we found IOs with REQ_FAILFAST_DEV bit set in
>>scmd->request->cmd_flags are not retried by SML and that is also as
>>expected.
>>
>>Below is the code in scsi_error.c(function- scsi_noretry_cmd) which
>>causes IOs with REQ_FAILFAST_DEV enabled not getting retried bit
>>completed back to upper layer-
>>
>>/*
>> * assume caller has checked sense and determined
>> * the check condition was retryable.
>> */
>>if (scmd->request->cmd_flags & REQ_FAILFAST_DEV ||
>>scmd->request->cmd_type == REQ_TYPE_BLOCK_PC)
>>return 1;
>>else
>>return 0;
>>
>>
>>IO which causes application to stop has REQ_FAILFAST_DEV enabled inside
>>"scmd->request->cmd_flags". We noticed that this bit will be set for
>>filesystem Read ahead meta data IOs. In order to confirm the same, we
>>mounted with option inode_readahead_blks=0 to disable ext4's inode
>>table readahead algorithm and did not observe the issue. Issue does not
>>hit with DIRECT IOs but only with cached/buffered IOs.
>>
>>2. From driver level debug prints, we also noticed - There are many IO
>>failures with REQ_FAILFAST_DEV handled gracefully by filesystem.
>>Application level failure happens only If IO has RQF_MIXED_MERGE set.
>>If IO merging is disabled through sysfs parameter for SCSI device in
>>question- nomerges set to 2, we are not seeing the issue.
>>
>>3. We added few prints in driver to dump "scmd->request->cmd_flags" and
>>"scmd->request->rq_flags" for IOs completed with CHECK CONDITION and
>>culprit IOs has all these bits- REQ_FAILFAST_DEV and REQ_RAHEAD bit set
>>in "scmd->request->cmd_flags" and RQF_MIXED_MERGE bit set in "scmd-
>>>request->rq_flags". Also it's not necessarily true that all IOs with
>>>request->these
>>three bits set will cause issue but whenever issue hits, these three
>>bits are set for IO causing failure.
>>
>>
>>In summary,
>>FS mechanism of using READ AHEAD for meta data works fine (in case of
>>IO
>>failure) if there is no mix/merge at block 

[PATCH][V2][target-devel-next] tcmu: make array tcmu_attrib_attrs static const

2017-06-13 Thread Colin King
From: Colin Ian King 

The array tcmu_attrib_attrs does not need to be in global scope, so make
it static.

Cleans up sparse warning:
"symbol 'tcmu_attrib_attrs' was not declared. Should it be static?"

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

diff --git a/drivers/target/target_core_user.c 
b/drivers/target/target_core_user.c
index afc1fd6bacaf..04fb3f720895 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -1672,7 +1672,7 @@ static ssize_t tcmu_emulate_write_cache_store(struct 
config_item *item,
 }
 CONFIGFS_ATTR(tcmu_, emulate_write_cache);
 
-struct configfs_attribute *tcmu_attrib_attrs[] = {
+static struct configfs_attribute *tcmu_attrib_attrs[] = {
_attr_cmd_time_out,
_attr_dev_path,
_attr_dev_size,
-- 
2.11.0



[PATCH][target-devel-next] tcmu: make array tcmu_attrib_attrs static const

2017-06-13 Thread Colin King
From: Colin Ian King 

The guid intel_dsm_guid does not need to be in global scope, so make
it static.

Cleans up sparse warning:
"symbol 'tcmu_attrib_attrs' was not declared. Should it be static?"

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

diff --git a/drivers/target/target_core_user.c 
b/drivers/target/target_core_user.c
index afc1fd6bacaf..04fb3f720895 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -1672,7 +1672,7 @@ static ssize_t tcmu_emulate_write_cache_store(struct 
config_item *item,
 }
 CONFIGFS_ATTR(tcmu_, emulate_write_cache);
 
-struct configfs_attribute *tcmu_attrib_attrs[] = {
+static struct configfs_attribute *tcmu_attrib_attrs[] = {
_attr_cmd_time_out,
_attr_dev_path,
_attr_dev_size,
-- 
2.11.0



Re: [ANNOUNCE]: Broadcom (Emulex) FC Target driver - efct

2017-06-13 Thread Johannes Thumshirn
On 06/13/2017 01:08 AM, James Smart wrote:
> Here's what I'd like to propose for a direction:
> 1) Create an initiator driver and a target driver.  For now, initiator
> would support both SCSI and NVME initiator. Target would support SCSI
> and NVME target.
> 2) SLI3 support would be contained only within the initiator driver and
> limited to SCSI (as it is today in lpfc).
> 3) SLI4 support would be library-ized,so that the code can be shared
> between the two drivers.  Library-izing SLI-4 means SLI-3 will also be
> library-ized.
> 4) Discovery support would be librarized so it can be shared. As part of
> this effort we will minimally move generic functions from the library to
> drivers/scsi/libfc (example: setting RPA payloads, etc).  At this time,
> the drivers will not attempt to use libfc for discovery. There is too
> much sensitive code tied to interlocks with adapter api design that are
> visible in the discovery state machine. Use of libfc can be a future,
> but for the short term, the goal is a single library for the broadcom
> initiator/target drivers.

Good idea, but be aware that libfc unfortunately is using skbs
internally which I don't like, but didn't have the time to clean it up.

> 5) lpfc will be refactored, addressing concerns that have been desired
> for a while.

\o/

When doing you refactoring can you please have a look at the levels of
indent (not more than 3 if possible), no unnecessary camelCase, etc...

The cyclomatic complexity GCC plugin we have in scripts/gcc-plugins
could be of help here, though I only have read about it and never really
used myself.

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


Re: [PATCH] storvsc: use default I/O timeout handler for FC devices

2017-06-13 Thread Johannes Thumshirn
On 06/13/2017 02:23 AM, Long Li wrote:
> From: Long Li 
> 
> FC disks are usually setup in a multipath system, and they don't want to 
> unconditionaly reset I/O on timeout. I/O timeout is detected by multipath 
> as a good time to failover and recover.
> 
> Signed-off-by: Long Li 
> ---

Looks good,
Reviewed-by: Johannes Thumshirn 

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


Re: [PATCH 6/6] sd: add support for TCG OPAL self encrypting disks

2017-06-13 Thread Christoph Hellwig
On Tue, Jun 06, 2017 at 11:58:02AM +0200, Christoph Hellwig wrote:
> On Mon, Jun 05, 2017 at 08:48:00PM -0400, Martin K. Petersen wrote:
> > For WRITE SAME, scsi_report_opcode() is gated not only by
> > sdev->no_report_opcodes but by sdev->no_write_same.
> > 
> > I'm concerned about firing off REPORT OPCODES to random devices without
> > a sufficiently good heuristic. Doesn't look like SAT has anything to
> > offer in this department, though. Maybe it's time to consider a
> > vendor-specific Linux VPD page...
> 
> Eww.  Given that as far as I can tell only ATA devices implement
> OPAL we could key it off that for now.  But that's only going to
> defer the problem until support for other security protocols comes
> along for real SCSI devices.
> 
> But as we already set no_report_opcodes for all usb-storage and
> quirked uas devices I think the worst offenders are already covered
> anyway.

Martin, how do we want to move ahead on this patch?


Re: [ANNOUNCE]: Broadcom (Emulex) FC Target driver - efct

2017-06-13 Thread Christoph Hellwig
Hi James,

I like the plan except for one bit:  The staging tree will be a major
pain due to the rules for applying to it and all the whitespace
cleanup junk you'll get.  I would storngly recommend to you to
do this with a non-mainline tree instead.  I'd be happy to help you
maintaining it if you want.

> Questions:
> a) How best to deal with overlapping pci id's ?  E.g. if we do (1) and we
> have an initiator and target driver, there is a lot of adapters that are
> fully functional for target operation, but were sold as primarily an
> initiator adapter. How could we manage target mode enablement without code
> mod or hard pci id partitioning ?   I know individual pci unbind/bind could
> work, but its been frowned upon as a long term option. Same thing goes for
> module parameters to select which ports do what role.

Let's start with a manual bind for the target driver.  A slightly
more fancy option would be to add the PCI IDs to both and reject
the device with -ENXIO if not configured for the right role.