[PATCH] cxlflash: return -EFAULT if copy_from_user() fails

2017-06-30 Thread Dan Carpenter
The copy_from/to_user() functions return the number of bytes remaining
to be copied but we had intended to return -EFAULT here.

Fixes: bc88ac47d5cb ("scsi: cxlflash: Support AFU debug")
Signed-off-by: Dan Carpenter 

diff --git a/drivers/scsi/cxlflash/main.c b/drivers/scsi/cxlflash/main.c
index 7a787b6e21c4..56b6e294ab78 100644
--- a/drivers/scsi/cxlflash/main.c
+++ b/drivers/scsi/cxlflash/main.c
@@ -3415,9 +3415,10 @@ static int cxlflash_afu_debug(struct cxlflash_cfg *cfg,
if (is_write) {
req_flags |= SISL_REQ_FLAGS_HOST_WRITE;
 
-   rc = copy_from_user(kbuf, ubuf, ulen);
-   if (unlikely(rc))
+   if (copy_from_user(kbuf, ubuf, ulen)) {
+   rc = -EFAULT;
goto out;
+   }
}
}
 
@@ -3445,8 +3446,10 @@ static int cxlflash_afu_debug(struct cxlflash_cfg *cfg,
goto out;
}
 
-   if (ulen && !is_write)
-   rc = copy_to_user(ubuf, kbuf, ulen);
+   if (ulen && !is_write) {
+   if (copy_to_user(ubuf, kbuf, ulen))
+   rc = -EFAULT;
+   }
 out:
kfree(buf);
dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);


[PATCH] tcmu: Fix flushing cmd entry dcache page

2017-06-30 Thread lixiubo
From: Xiubo Li 

When feeding the tcmu's cmd ring, we need to flush the dcache page
for the cmd entry to make sure these kernel stores are visible to
user space mappings of that page.

For the none PAD cmd entry, this will be flushed at the end of the
tcmu_queue_cmd_ring().

Signed-off-by: Xiubo Li 
---
 drivers/target/target_core_user.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/target/target_core_user.c 
b/drivers/target/target_core_user.c
index 203bff1..930800c 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -699,21 +699,21 @@ static inline size_t tcmu_cmd_get_cmd_size(struct 
tcmu_cmd *tcmu_cmd,
size_t pad_size = head_to_end(cmd_head, udev->cmdr_size);
 
entry = (void *) mb + CMDR_OFF + cmd_head;
-   tcmu_flush_dcache_range(entry, sizeof(*entry));
tcmu_hdr_set_op(>hdr.len_op, TCMU_OP_PAD);
tcmu_hdr_set_len(>hdr.len_op, pad_size);
entry->hdr.cmd_id = 0; /* not used for PAD */
entry->hdr.kflags = 0;
entry->hdr.uflags = 0;
+   tcmu_flush_dcache_range(entry, sizeof(*entry));
 
UPDATE_HEAD(mb->cmd_head, pad_size, udev->cmdr_size);
+   tcmu_flush_dcache_range(mb, sizeof(*mb));
 
cmd_head = mb->cmd_head % udev->cmdr_size; /* UAM */
WARN_ON(cmd_head != 0);
}
 
entry = (void *) mb + CMDR_OFF + cmd_head;
-   tcmu_flush_dcache_range(entry, sizeof(*entry));
tcmu_hdr_set_op(>hdr.len_op, TCMU_OP_CMD);
entry->hdr.cmd_id = tcmu_cmd->cmd_id;
entry->hdr.kflags = 0;
-- 
1.8.3.1





[PATCH 1/2] scsi: lpfc: spin_lock_irq() is not nestable

2017-06-30 Thread Dan Carpenter
We're calling spin_lock_irq() multiple times, the problem is that on the
first spin_unlock_irq() then we will re-enable IRQs and we don't want
that.

Fixes: 966bb5b71196 ("scsi: lpfc: Break up IO ctx list into a separate get and 
put list")
Signed-off-by: Dan Carpenter 

diff --git a/drivers/scsi/lpfc/lpfc_nvmet.c b/drivers/scsi/lpfc/lpfc_nvmet.c
index 7dc061a14f95..afc523209845 100644
--- a/drivers/scsi/lpfc/lpfc_nvmet.c
+++ b/drivers/scsi/lpfc/lpfc_nvmet.c
@@ -866,44 +866,44 @@ lpfc_nvmet_cleanup_io_context(struct lpfc_hba *phba)
unsigned long flags;
 
spin_lock_irqsave(>sli4_hba.nvmet_ctx_get_lock, flags);
-   spin_lock_irq(>sli4_hba.nvmet_ctx_put_lock);
+   spin_lock(>sli4_hba.nvmet_ctx_put_lock);
list_for_each_entry_safe(ctx_buf, next_ctx_buf,
>sli4_hba.lpfc_nvmet_ctx_get_list, list) {
-   spin_lock_irq(>sli4_hba.abts_nvme_buf_list_lock);
+   spin_lock(>sli4_hba.abts_nvme_buf_list_lock);
list_del_init(_buf->list);
-   spin_unlock_irq(>sli4_hba.abts_nvme_buf_list_lock);
+   spin_unlock(>sli4_hba.abts_nvme_buf_list_lock);
__lpfc_clear_active_sglq(phba,
 ctx_buf->sglq->sli4_lxritag);
ctx_buf->sglq->state = SGL_FREED;
ctx_buf->sglq->ndlp = NULL;
 
-   spin_lock_irq(>sli4_hba.sgl_list_lock);
+   spin_lock(>sli4_hba.sgl_list_lock);
list_add_tail(_buf->sglq->list,
  >sli4_hba.lpfc_nvmet_sgl_list);
-   spin_unlock_irq(>sli4_hba.sgl_list_lock);
+   spin_unlock(>sli4_hba.sgl_list_lock);
 
lpfc_sli_release_iocbq(phba, ctx_buf->iocbq);
kfree(ctx_buf->context);
}
list_for_each_entry_safe(ctx_buf, next_ctx_buf,
>sli4_hba.lpfc_nvmet_ctx_put_list, list) {
-   spin_lock_irq(>sli4_hba.abts_nvme_buf_list_lock);
+   spin_lock(>sli4_hba.abts_nvme_buf_list_lock);
list_del_init(_buf->list);
-   spin_unlock_irq(>sli4_hba.abts_nvme_buf_list_lock);
+   spin_unlock(>sli4_hba.abts_nvme_buf_list_lock);
__lpfc_clear_active_sglq(phba,
 ctx_buf->sglq->sli4_lxritag);
ctx_buf->sglq->state = SGL_FREED;
ctx_buf->sglq->ndlp = NULL;
 
-   spin_lock_irq(>sli4_hba.sgl_list_lock);
+   spin_lock(>sli4_hba.sgl_list_lock);
list_add_tail(_buf->sglq->list,
  >sli4_hba.lpfc_nvmet_sgl_list);
-   spin_unlock_irq(>sli4_hba.sgl_list_lock);
+   spin_unlock(>sli4_hba.sgl_list_lock);
 
lpfc_sli_release_iocbq(phba, ctx_buf->iocbq);
kfree(ctx_buf->context);
}
-   spin_unlock_irq(>sli4_hba.nvmet_ctx_put_lock);
+   spin_unlock(>sli4_hba.nvmet_ctx_put_lock);
spin_unlock_irqrestore(>sli4_hba.nvmet_ctx_get_lock, flags);
 }
 


[PATCH 2/2] scsi: lpfc: don't double count abort errors

2017-06-30 Thread Dan Carpenter
If lpfc_nvmet_unsol_fcp_issue_abort() fails then we accidentally
increment "tgtp->xmt_abort_rsp_error" and then two lines later we
increment it a second time.

Fixes: 547077a44b3b ("scsi: lpfc: Adding additional stats counters for nvme.")
Signed-off-by: Dan Carpenter 

diff --git a/drivers/scsi/lpfc/lpfc_nvmet.c b/drivers/scsi/lpfc/lpfc_nvmet.c
index 7dc061a14f95..fbeec344c6cc 100644
--- a/drivers/scsi/lpfc/lpfc_nvmet.c
+++ b/drivers/scsi/lpfc/lpfc_nvmet.c
@@ -2583,7 +2583,6 @@ lpfc_nvmet_unsol_fcp_issue_abort(struct lpfc_hba *phba,
}
 
 aerr:
-   atomic_inc(>xmt_abort_rsp_error);
ctxp->flag &= ~LPFC_NVMET_ABORT_OP;
atomic_inc(>xmt_abort_rsp_error);
lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS,


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

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

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

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index f717fbc..5018a3f 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3826,8 +3826,6 @@ megasas_issue_tm(struct megasas_instance *instance, u16 
device_handle,
else {
instance->instancet->disable_intr(instance);
megasas_sync_irqs((unsigned long)instance);
-   megasas_complete_cmd_dpc_fusion
-   ((unsigned long)instance);
instance->instancet->enable_intr(instance);
if (scsi_lookup->scmd == NULL)
break;
@@ -3839,9 +3837,7 @@ megasas_issue_tm(struct megasas_instance *instance, u16 
device_handle,
if ((channel == 0x) && (id == 0x))
break;
instance->instancet->disable_intr(instance);
-   msleep(1000);
-   megasas_complete_cmd_dpc_fusion
-   ((unsigned long)instance);
+   megasas_sync_irqs((unsigned long)instance);
rc = megasas_track_scsiio(instance, id, channel);
instance->instancet->enable_intr(instance);
 
-- 
2.8.3



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

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

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

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



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

2017-06-30 Thread Shivasharan S
Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 9 +
 1 file changed, 9 insertions(+)

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



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

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

 drivers/scsi/megaraid/megaraid_sas.h|   5 +-
 drivers/scsi/megaraid/megaraid_sas_base.c   |  44 ++--
 drivers/scsi/megaraid/megaraid_sas_fp.c |  40 +++
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 161 +---
 4 files changed, 149 insertions(+), 101 deletions(-)

-- 
2.8.3



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

2017-06-30 Thread Shivasharan S
Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
---
 drivers/scsi/megaraid/megaraid_sas.h|   1 -
 drivers/scsi/megaraid/megaraid_sas_base.c   |  12 ++-
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 113 +---
 3 files changed, 80 insertions(+), 46 deletions(-)

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

[PATCH 15/15] megaraid_sas: driver version upgrade

2017-06-30 Thread Shivasharan S
Signed-off-by: Shivasharan S 
---
 drivers/scsi/megaraid/megaraid_sas.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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



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

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

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

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index f990ab4d..f717fbc 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3283,7 +3283,7 @@ build_mpt_mfi_pass_thru(struct megasas_instance *instance,
mpi25_ieee_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT |
MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR;
 
-   mpi25_ieee_chain->Length = cpu_to_le32(instance->max_chain_frame_sz);
+   mpi25_ieee_chain->Length = cpu_to_le32(instance->mfi_frame_size);
 }
 
 /**
-- 
2.8.3



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

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

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 5018a3f..0f13c58 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3552,6 +3552,7 @@ int megasas_wait_for_outstanding_fusion(struct 
megasas_instance *instance,
}
}
 
+   megasas_complete_cmd_dpc_fusion((unsigned long)instance);
outstanding = atomic_read(>fw_outstanding);
if (!outstanding)
goto out;
@@ -3560,8 +3561,6 @@ int megasas_wait_for_outstanding_fusion(struct 
megasas_instance *instance,
dev_notice(>pdev->dev, "[%2d]waiting for %d "
   "commands to complete for scsi%d\n", i,
   outstanding, instance->host->host_no);
-   megasas_complete_cmd_dpc_fusion(
-   (unsigned long)instance);
}
msleep(1000);
}
-- 
2.8.3



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

2017-06-30 Thread Shivasharan S
Currently driver sets default queue_depth for VDs at 256 and JBODs based on 
interface type,
ie., for SAS JBOD QD will be 64, for SATA JBOD QD will be 32.
During performance runs with scsi-mq enabled, we are seeing better results by
setting QD same as HBA queue_depth.

Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 0230929..c200f1a 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -1891,7 +1891,8 @@ static void megasas_set_static_target_properties(struct 
scsi_device *sdev,
if (instance->nvme_page_size && max_io_size_kb)
megasas_set_nvme_device_properties(sdev, (max_io_size_kb << 
10));
 
-   scsi_change_queue_depth(sdev, device_qd);
+   if (!shost_use_blk_mq(sdev->host))
+   scsi_change_queue_depth(sdev, device_qd);
 
 }
 
@@ -5914,6 +5915,9 @@ static int megasas_io_attach(struct megasas_instance 
*instance)
host->max_lun = MEGASAS_MAX_LUN;
host->max_cmd_len = 16;
 
+   if (shost_use_blk_mq(host))
+   host->cmd_per_lun = host->can_queue;
+
/*
 * Notify the mid-layer about the new controller
 */
-- 
2.8.3



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

2017-06-30 Thread Shivasharan S
Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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



[PATCH 13/15] megaraid_sas: modified few prints in OCR and IOC INIT path

2017-06-30 Thread Shivasharan S
Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 22 +-
 1 file changed, 13 insertions(+), 9 deletions(-)

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



[PATCH 12/15] megaraid_sas: replace internal FALSE/TRUE definitions with false/true

2017-06-30 Thread Shivasharan S
Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
---
 drivers/scsi/megaraid/megaraid_sas_fp.c | 40 +
 1 file changed, 15 insertions(+), 25 deletions(-)

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

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

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

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

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 316c3df..395c3aa 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -5478,7 +5478,8 @@ static int megasas_init_fw(struct megasas_instance 
*instance)
instance->throttlequeuedepth =
MEGASAS_THROTTLE_QUEUE_DEPTH;
 
-   if (resetwaittime > MEGASAS_RESET_WAIT_TIME)
+   if ((resetwaittime < 1) ||
+   (resetwaittime > MEGASAS_RESET_WAIT_TIME))
resetwaittime = MEGASAS_RESET_WAIT_TIME;
 
if ((scmd_timeout < 10) || (scmd_timeout > MEGASAS_DEFAULT_CMD_TIMEOUT))
-- 
2.8.3



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

2017-06-30 Thread Shivasharan S
Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 395c3aa..3c50a7b 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -6867,6 +6867,7 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
void *sense = NULL;
dma_addr_t sense_handle;
unsigned long *sense_ptr;
+   u32 opcode;
 
memset(kbuff_arr, 0, sizeof(kbuff_arr));
 
@@ -6894,15 +6895,16 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
cmd->frame->hdr.flags &= cpu_to_le16(~(MFI_FRAME_IEEE |
   MFI_FRAME_SGL64 |
   MFI_FRAME_SENSE64));
+   opcode = le32_to_cpu(cmd->frame->dcmd.opcode);
 
-   if (cmd->frame->dcmd.opcode == MR_DCMD_CTRL_SHUTDOWN) {
+   if (opcode == MR_DCMD_CTRL_SHUTDOWN) {
if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS) {
megasas_return_cmd(instance, cmd);
return -1;
}
}
 
-   if (cmd->frame->dcmd.opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) {
+   if (opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) {
error = megasas_set_crash_dump_params_ioctl(cmd);
megasas_return_cmd(instance, cmd);
return error;
@@ -6976,8 +6978,7 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
cmd->sync_cmd = 0;
dev_err(>pdev->dev,
"return -EBUSY from %s %d opcode 0x%x 
cmd->cmd_status_drv 0x%x\n",
-   __func__, __LINE__, cmd->frame->dcmd.opcode,
-   cmd->cmd_status_drv);
+   __func__, __LINE__, opcode, cmd->cmd_status_drv);
return -EBUSY;
}
 
-- 
2.8.3



Re: [PATCH 04/47] aacraid: use aac_tmf_callback for reset fib

2017-06-30 Thread Hannes Reinecke
On 06/29/2017 10:06 PM, Raghava Aditya Renukunta wrote:
> [.]
>> @@ -879,8 +906,12 @@ static int aac_eh_dev_reset(struct scsi_cmnd *cmd)
> [..]
>> bus = aac_logical_to_phys(scmd_channel(cmd));
>> cid = scmd_id(cmd);
>> +   info = >hba_map[bus][cid];
>> if (bus >= AAC_MAX_BUSES || cid >= AAC_MAX_TARGETS ||
>> -   aac->hba_map[bus][cid].devtype != AAC_DEVTYPE_NATIVE_RAW)
>> +   info->devtype != AAC_DEVTYPE_NATIVE_RAW)
>> +   return FAILED;
>> +
>> +   if (info->reset_state > 0)
>> return FAILED;
> [..]
>  
>> @@ -932,8 +962,9 @@ static int aac_eh_target_reset(struct scsi_cmnd
>> *cmd)
>>
>> bus = aac_logical_to_phys(scmd_channel(cmd));
>> cid = scmd_id(cmd);
>> +   info = >hba_map[bus][cid];
>> if (bus >= AAC_MAX_BUSES || cid >= AAC_MAX_TARGETS ||
>> -   aac->hba_map[bus][cid].devtype != AAC_DEVTYPE_NATIVE_RAW)
>> +   info->devtype != AAC_DEVTYPE_NATIVE_RAW)
>> return FAILED;
> 
> Can we have a 
>   If (info->reset_state > 0
>   Return FAILED;
> here as well?
> 
Sure.

Thanks for the review.

Cheers

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


Re: [PATCH v5 0/6] g_NCR5380: PDMA fixes and cleanup

2017-06-30 Thread Finn Thain
On Thu, 29 Jun 2017, Ondrej Zary wrote:

> The write corruption is still there. I'm afraid it can't be fixed 
> without rolling "start" back (or inceasing residual) if an error 
> occured, something like this:
> 
> --- a/drivers/scsi/g_NCR5380.c
> +++ b/drivers/scsi/g_NCR5380.c
> @@ -619,6 +621,9 @@ static inline int generic_NCR5380_psend(struct 
>  (int)NCR5380_read(hostdata->c400_blk_cnt) * 128);
> 
>   if (residual != 0) {
> + residual += 128;
>   /* 53c80 interrupt or transfer timeout. Reset 53c400 logic. */
>   NCR5380_write(hostdata->c400_ctl_status, CSR_RESET);
>   NCR5380_write(hostdata->c400_ctl_status, CSR_BASE);
> 
> (seems to work - wrote 230MB and read it back with no differences)
> 
> The corruption mechanism is:
> 1. Host buffer is ready so we write 128 B of data there and increment 
>"start".
> 2. Chip swaps the buffers, decrements the block counter and starts 
>writing the data to drive.
> 3. Drive does not like it (e.g. its buffer is full) so it disconnects.
> 4. Chip stops writing and asserts an IRQ.
> 5. We detect the IRQ. The block counter is already decremented, "start" 
>is already incremented but the data was not written to the drive.
> 
> 

OK. Thanks for that analysis.

It sounds like the c400_blk_cnt value gives the number of buffer swaps 
remaining. If so, that value isn't useful for calculating a residual. I'll 
rework that calculation again.

In your patch, the residual gets increased regardless of the actual cause 
of the short transfer. Nothing prevents the residual from being increased 
beyond the original length of the transfer (due to a flaky target or bus). 
Therefore I've taken a slightly different approach in my patch (below).

> 
> No more log spamming on DTC but reads are corrupted even more than before.
> The IRQ check after data transfer increases the chance of catching an IRQ
> before the buffer could become ready.

If we delay the IRQ check, that just means that CSR_GATED_53C80_IRQ will 
be detected a bit later (128 bytes later)... so not much difference.

> This patch:
> --- a/drivers/scsi/g_NCR5380.c
> +++ b/drivers/scsi/g_NCR5380.c
> @@ -548,8 +548,10 @@ static inline int generic_NCR5380_precv(struct
>   start += 128;
>  
>   if (NCR5380_read(hostdata->c400_ctl_status) &
> - CSR_GATED_53C80_IRQ)
> + CSR_GATED_53C80_IRQ) {
> + printk("r irq at start=%d basr=0x%02x\n", start, 
> NCR5380_read(BUS_AND_STATUS_REG));
>   break;
> + }
>   }
>  
>   residual = len - start;
> 
> produces lots of these lines:
> [  896.194054] r irq at start=128 basr=0x98
> [  896.197758] r irq at start=3968 basr=0x98
> 

Assuming that the registers are available and valid, the value 0x98 means 
BASR_END_DMA_TRANSFER | BASR_IRQ | BASR_PHASE_MATCH. There is no 
BASR_BUSY_ERROR here, so the cause of the CSR_GATED_53C80_IRQ must be that 
the 53c400 has terminated the transfer by asserting /EOP. That shouldn't 
happen before before the counters run down.

It doesn't make sense. So maybe the 53c80 registers are not valid at this 
point? That means a phase mismatch can't be excluded... unlikely at 128 
bytes into the transfer. Busy error? Also unlikely.

I have to conclude that CSR_GATED_53C80_IRQ and BASR_END_DMA_TRANSFER 
can't be trusted on this board. I guess that's why you examine the BASR 
directly in your original algorithm but ignore BASR_END_DMA_TRANSFER.

It does look like some kind of timing issue: the "start" value above 
changes from one log message to the next. Who knows?


> This fixes the DTC read corruption, although I don't like the repeated
> ctl_status register reads:
> --- a/drivers/scsi/g_NCR5380.c
> +++ b/drivers/scsi/g_NCR5380.c
> @@ -533,7 +533,7 @@ static inline int generic_NCR5380_precv(struct
>   break;
>
>   if (NCR5380_read(hostdata->c400_ctl_status) &
> - CSR_HOST_BUF_NOT_RDY)
> + CSR_GATED_53C80_IRQ && 
> (NCR5380_read(hostdata->c400_ctl_status) & CSR_HOST_BUF_NOT_RDY))
>   break;
> 
>   if (hostdata->io_port && hostdata->io_width == 2)

But that means the transfer will continue even when CSR_HOST_BUF_NOT_RDY. 
Your original algorithm doesn't attempt that. Neither does the algorithm 
in the datasheet. We should try to omit this change.

> @@ -546,10 +546,6 @@ static inline int generic_NCR5380_precv(struct 
>   memcpy_fromio(dst + start,
>   hostdata->io + NCR53C400_host_buffer, 128);
>   start += 128;
> -
> - if (NCR5380_read(hostdata->c400_ctl_status) &
> - CSR_GATED_53C80_IRQ)
> - break;
>   }
>  
>   residual = len - start;

I think we should keep the CSR_GATED_53C80_IRQ check for the other boards, 
if this bogus BASR_END_DMA_TRANSFER problem is confined to DTC436.


Re: [PATCH v4 0/5] tcmu: Add Type of reconfig into netlink

2017-06-30 Thread Nicholas A. Bellinger
Hey MNC,

On Mon, 2017-06-12 at 01:43 -0500, Mike Christie wrote:
> On 06/11/2017 04:02 PM, Mike Christie wrote:
> > On 06/09/2017 01:11 AM, Nicholas A. Bellinger wrote:
> >> Hi Bryant & Co,
> >>
> >> On Tue, 2017-06-06 at 09:28 -0500, Bryant G. Ly wrote:
> >>> From: "Bryant G. Ly" 
> >>>
> >>> This patch consists of adding a netlink to allow for reconfiguration
> >>> of a device in tcmu.
> >>>
> >>> It also changes and adds some attributes that are reconfigurable:
> >>> write_cache, device size, and device path.
> >>>
> >>> V2 - Fixes kfree in tcmu: Make dev_config configurable
> >>> V3 - Fixes spelling error
> >>> V4 - change strcpy to strlcpy for tcmu_dev_path_store and move
> >>>  tcmu_reconfig_type into target_core_user.h
> >>>
> >>>
> >>> Bryant G. Ly (5):
> >>>   tcmu: Support emulate_write_cache
> >>>   tcmu: Add netlink for device reconfiguration
> >>>   tcmu: Make dev_size configurable via userspace
> >>>   tcmu: Make dev_config configurable
> >>>   tcmu: Add Type of reconfig into netlink
> >>>
> >>>  drivers/target/target_core_user.c | 152 
> >>> --
> >>>  include/uapi/linux/target_core_user.h |   9 ++
> >>>  2 files changed, 155 insertions(+), 6 deletions(-)
> >>>
> >>
> >> AFAICT, it looks like all of the review comments have been addressed in
> >> -v4.
> >>
> >> Applied to target-pending/for-next, with MNC's (pseudo) Reviewed-by's
> >> added for #3-#5.
> >>
> >> Please let me know if anything else needs to be changed.
> >>
> > 
> > The patches look ok. Thanks. Could you just merge the attached patch
> > into "[PATCH v4 5/5] tcmu: Add Type of reconfig into netlink" or into
> > the patchset after it? It just makes some of the names a little less
> > generic and only returns the reconfig attr for reconfig commands.
> > 
> 
> Actually Nick, do not merge the last patch. I have a lot more fixes/changes.
> 
> Bryant, could you test and adapt your userspace patches for the attached
> patch build over Nicks for-next branch.
> 
> Basically, the patch just has use pass the value being reconfigured with
> the netlink event. Along the way, it fixes a couple bugs.
> 
> Nick, when we have tested the patch, then I can submit as a formal
> patchset, or you can fold into the existing patches or whatever you prefer.
> 

Looking at merging your -v4 patches series here next:

[PATCH V4 00/10] target/tcmu: make tcmu netlink ops sync
http://www.spinics.net/lists/target-devel/msg15706.html

Do you still want me to drop the patch from Bryant below as mentioned
earlier..?

tcmu: Add Type of reconfig into netlink
https://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending.git/commit/?h=for-next=28d44b983000754677155e46f6bdafc7b4d84213



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

2017-06-30 Thread Shivasharan S
An application sending out of range AEN class code for 
registration, will result in kernel panic in MR driver.

Signed-off-by: Kashyap Desai 
Signed-off-by: Shivasharan S 
Cc: sta...@vger.kernel.org
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 8 
 1 file changed, 8 insertions(+)

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



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

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

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

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index a308e14..c239762 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3754,7 +3754,7 @@ megasas_issue_tm(struct megasas_instance *instance, u16 
device_handle,
struct megasas_cmd_fusion *cmd_fusion;
struct megasas_cmd *cmd_mfi;
union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
-   struct fusion_context *fusion;
+   struct fusion_context *fusion = NULL;
struct megasas_cmd_fusion *scsi_lookup;
int rc;
struct MPI2_SCSI_TASK_MANAGE_REPLY *mpi_reply;
@@ -3781,8 +3781,6 @@ megasas_issue_tm(struct megasas_instance *instance, u16 
device_handle,
cmd_fusion->request_desc = req_desc;
req_desc->Words = 0;
 
-   scsi_lookup = fusion->cmd_list[smid_task - 1];
-
mr_request = (struct MR_TASK_MANAGE_REQUEST *) cmd_fusion->io_request;
memset(mr_request, 0, sizeof(struct MR_TASK_MANAGE_REQUEST));
mpi_request = (struct MPI2_SCSI_TASK_MANAGE_REQUEST *) 
_request->TmRequest;
@@ -3829,6 +3827,8 @@ megasas_issue_tm(struct megasas_instance *instance, u16 
device_handle,
rc = SUCCESS;
switch (type) {
case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
+   scsi_lookup = fusion->cmd_list[smid_task - 1];
+
if (scsi_lookup->scmd == NULL)
break;
else {
-- 
2.8.3



[PATCH 2/2] megaraid: drop the 'new driver' statements

2017-06-30 Thread Hannes Reinecke
This driver is hardly new; it has been supersede by at least four
other generations of megaraid RAID HBAs.

Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/megaraid/Kconfig.megaraid | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/megaraid/Kconfig.megaraid 
b/drivers/scsi/megaraid/Kconfig.megaraid
index ad1dc16..cb4952c 100644
--- a/drivers/scsi/megaraid/Kconfig.megaraid
+++ b/drivers/scsi/megaraid/Kconfig.megaraid
@@ -1,11 +1,11 @@
 config MEGARAID_NEWGEN
-   bool "LSI Logic New Generation RAID Device Drivers"
+   bool "LSI Logic RAID Device Drivers"
depends on PCI && SCSI
help
LSI Logic RAID Device Drivers
 
 config MEGARAID_MM
-   tristate "LSI Logic Management Module (New Driver)"
+   tristate "LSI Logic Management Module"
depends on PCI && SCSI && MEGARAID_NEWGEN
help
Management Module provides ioctl, sysfs support for LSI Logic
@@ -15,7 +15,7 @@ config MEGARAID_MM
 
 
 config MEGARAID_MAILBOX
-   tristate "LSI Logic MegaRAID Driver (New Driver)"
+   tristate "LSI Logic MegaRAID Driver"
depends on PCI && SCSI && MEGARAID_MM
help
List of supported controllers
-- 
1.8.5.6



[PATCH 0/2] Drop legacy megaraid implementation

2017-06-30 Thread Hannes Reinecke
The legacy megaraid implementation is ancient, and support for most boards
has been moved to megaraid_mm anyway. So drop the legacy implementation.
And do not refer to 'megaraid_mm' as a 'new driver'; it's close to be obsoleted
itself.

Hannes Reinecke (2):
  Drop legacy megaraid controller
  megaraid: drop the 'new driver' statements

 MAINTAINERS|1 -
 drivers/scsi/Makefile  |1 -
 drivers/scsi/megaraid.c| 4730 
 drivers/scsi/megaraid.h| 1010 ---
 drivers/scsi/megaraid/Kconfig.megaraid |   17 +-
 5 files changed, 3 insertions(+), 5756 deletions(-)
 delete mode 100644 drivers/scsi/megaraid.c
 delete mode 100644 drivers/scsi/megaraid.h

-- 
1.8.5.6



[PATCH 1/2] Drop legacy megaraid controller

2017-06-30 Thread Hannes Reinecke
The hardware is ancient, and support for most cards has been moved
to megaraid_mbox. So drop it.

Signed-off-by: Hannes Reinecke 
---
 MAINTAINERS|1 -
 drivers/scsi/Makefile  |1 -
 drivers/scsi/megaraid.c| 4730 
 drivers/scsi/megaraid.h| 1010 ---
 drivers/scsi/megaraid/Kconfig.megaraid |   11 -
 5 files changed, 5753 deletions(-)
 delete mode 100644 drivers/scsi/megaraid.c
 delete mode 100644 drivers/scsi/megaraid.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 09b5ab6..0ab2205 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8284,7 +8284,6 @@ L:linux-scsi@vger.kernel.org
 W: http://www.avagotech.com/support/
 S: Maintained
 F: Documentation/scsi/megaraid.txt
-F: drivers/scsi/megaraid.*
 F: drivers/scsi/megaraid/
 
 MELFAS MIP4 TOUCHSCREEN DRIVER
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index 93dbe58..3eb4552 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -97,7 +97,6 @@ obj-$(CONFIG_SCSI_EATA)   += eata.o
 obj-$(CONFIG_SCSI_DC395x)  += dc395x.o
 obj-$(CONFIG_SCSI_AM53C974)+= esp_scsi.o   am53c974.o
 obj-$(CONFIG_CXLFLASH) += cxlflash/
-obj-$(CONFIG_MEGARAID_LEGACY)  += megaraid.o
 obj-$(CONFIG_MEGARAID_NEWGEN)  += megaraid/
 obj-$(CONFIG_MEGARAID_SAS) += megaraid/
 obj-$(CONFIG_SCSI_MPT3SAS) += mpt3sas/
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
deleted file mode 100644
index 3c63c29..000
--- a/drivers/scsi/megaraid.c
+++ /dev/null
@@ -1,4730 +0,0 @@
-/*
- *
- * Linux MegaRAID device driver
- *
- * Copyright (c) 2002  LSI Logic Corporation.
- *
- *This program is free software; you can redistribute it and/or
- *modify it under the terms of the GNU General Public License
- *as published by the Free Software Foundation; either version
- *2 of the License, or (at your option) any later version.
- *
- * Copyright (c) 2002  Red Hat, Inc. All rights reserved.
- *   - fixes
- *   - speed-ups (list handling fixes, issued_list, optimizations.)
- *   - lots of cleanups.
- *
- * Copyright (c) 2003  Christoph Hellwig  
- *   - new-style, hotplug-aware pci probing and scsi registration
- *
- * Version : v2.00.4 Mon Nov 14 14:02:43 EST 2005 - Seokmann Ju
- * 
- *
- * Description: Linux device driver for LSI Logic MegaRAID controller
- *
- * Supported controllers: MegaRAID 418, 428, 438, 466, 762, 467, 471, 490, 493
- * 518, 520, 531, 532
- *
- * This driver is supported by LSI Logic, with assistance from Red Hat, Dell,
- * and others. Please send updates to the mailing list
- * linux-scsi@vger.kernel.org .
- *
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "scsi.h"
-#include 
-
-#include "megaraid.h"
-
-#define MEGARAID_MODULE_VERSION "2.00.4"
-
-MODULE_AUTHOR ("s...@lsil.com");
-MODULE_DESCRIPTION ("LSI Logic MegaRAID legacy driver");
-MODULE_LICENSE ("GPL");
-MODULE_VERSION(MEGARAID_MODULE_VERSION);
-
-static DEFINE_MUTEX(megadev_mutex);
-static unsigned int max_cmd_per_lun = DEF_CMD_PER_LUN;
-module_param(max_cmd_per_lun, uint, 0);
-MODULE_PARM_DESC(max_cmd_per_lun, "Maximum number of commands which can be 
issued to a single LUN (default=DEF_CMD_PER_LUN=63)");
-
-static unsigned short int max_sectors_per_io = MAX_SECTORS_PER_IO;
-module_param(max_sectors_per_io, ushort, 0);
-MODULE_PARM_DESC(max_sectors_per_io, "Maximum number of sectors per I/O 
request (default=MAX_SECTORS_PER_IO=128)");
-
-
-static unsigned short int max_mbox_busy_wait = MBOX_BUSY_WAIT;
-module_param(max_mbox_busy_wait, ushort, 0);
-MODULE_PARM_DESC(max_mbox_busy_wait, "Maximum wait for mailbox in microseconds 
if busy (default=MBOX_BUSY_WAIT=10)");
-
-#define RDINDOOR(adapter)  readl((adapter)->mmio_base + 0x20)
-#define RDOUTDOOR(adapter) readl((adapter)->mmio_base + 0x2C)
-#define WRINDOOR(adapter,value) writel(value, (adapter)->mmio_base + 
0x20)
-#define WROUTDOOR(adapter,value) writel(value, (adapter)->mmio_base + 0x2C)
-
-/*
- * Global variables
- */
-
-static int hba_count;
-static adapter_t *hba_soft_state[MAX_CONTROLLERS];
-static struct proc_dir_entry *mega_proc_dir_entry;
-
-/* For controller re-ordering */
-static struct mega_hbas mega_hbas[MAX_CONTROLLERS];
-
-static long
-megadev_unlocked_ioctl(struct file *filep, unsigned int cmd, unsigned long 
arg);
-
-/*
- * The File Operations structure for the serial/ioctl interface of the driver
- */
-static const struct file_operations megadev_fops = {
-   .owner  = THIS_MODULE,
-   .unlocked_ioctl = megadev_unlocked_ioctl,
-   .open   

[PATCH] scsi: snic: fix a couple of spelling mistakes/typos

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

Trivial fix to spelling mistakes/typos:

"Allodating" -> "Allocating"
"incative" -> "inactive"

Signed-off-by: Colin Ian King 
---
 drivers/scsi/snic/snic_isr.c  | 4 ++--
 drivers/scsi/snic/snic_scsi.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/snic/snic_isr.c b/drivers/scsi/snic/snic_isr.c
index d859501e4ccd..c4da3673f2ae 100644
--- a/drivers/scsi/snic/snic_isr.c
+++ b/drivers/scsi/snic/snic_isr.c
@@ -141,7 +141,7 @@ snic_request_intr(struct snic *snic)
  snic->msix[i].devid);
if (ret) {
SNIC_HOST_ERR(snic->shost,
- "MSI-X: requrest_irq(%d) failed %d\n",
+ "MSI-X: request_irq(%d) failed %d\n",
  i,
  ret);
snic_free_intr(snic);
@@ -151,7 +151,7 @@ snic_request_intr(struct snic *snic)
}
 
return ret;
-} /* end of snic_requrest_intr */
+} /* end of snic_request_intr */
 
 int
 snic_set_intr_mode(struct snic *snic)
diff --git a/drivers/scsi/snic/snic_scsi.c b/drivers/scsi/snic/snic_scsi.c
index 05c3a7282d4a..d8a376b7882d 100644
--- a/drivers/scsi/snic/snic_scsi.c
+++ b/drivers/scsi/snic/snic_scsi.c
@@ -1260,7 +1260,7 @@ snic_io_cmpl_handler(struct vnic_dev *vdev,
default:
SNIC_BUG_ON(1);
SNIC_SCSI_DBG(snic->shost,
- "Unknown Firmwqre completion request type %d\n",
+ "Unknown Firmware completion request type %d\n",
  fwreq->hdr.type);
break;
}
-- 
2.11.0



NAK: [PATCH] scsi: snic: fix a couple of spelling mistakes/typos

2017-06-30 Thread Colin Ian King
Incorrect commit message, I'll resend.

On 30/06/17 14:54, Colin King wrote:
> From: Colin Ian King 
> 
> Trivial fix to spelling mistakes/typos:
> 
> "Allodating" -> "Allocating"
> "incative" -> "inactive"
> 
> Signed-off-by: Colin Ian King 
> ---
>  drivers/scsi/snic/snic_isr.c  | 4 ++--
>  drivers/scsi/snic/snic_scsi.c | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/scsi/snic/snic_isr.c b/drivers/scsi/snic/snic_isr.c
> index d859501e4ccd..c4da3673f2ae 100644
> --- a/drivers/scsi/snic/snic_isr.c
> +++ b/drivers/scsi/snic/snic_isr.c
> @@ -141,7 +141,7 @@ snic_request_intr(struct snic *snic)
> snic->msix[i].devid);
>   if (ret) {
>   SNIC_HOST_ERR(snic->shost,
> -   "MSI-X: requrest_irq(%d) failed %d\n",
> +   "MSI-X: request_irq(%d) failed %d\n",
> i,
> ret);
>   snic_free_intr(snic);
> @@ -151,7 +151,7 @@ snic_request_intr(struct snic *snic)
>   }
>  
>   return ret;
> -} /* end of snic_requrest_intr */
> +} /* end of snic_request_intr */
>  
>  int
>  snic_set_intr_mode(struct snic *snic)
> diff --git a/drivers/scsi/snic/snic_scsi.c b/drivers/scsi/snic/snic_scsi.c
> index 05c3a7282d4a..d8a376b7882d 100644
> --- a/drivers/scsi/snic/snic_scsi.c
> +++ b/drivers/scsi/snic/snic_scsi.c
> @@ -1260,7 +1260,7 @@ snic_io_cmpl_handler(struct vnic_dev *vdev,
>   default:
>   SNIC_BUG_ON(1);
>   SNIC_SCSI_DBG(snic->shost,
> -   "Unknown Firmwqre completion request type %d\n",
> +   "Unknown Firmware completion request type %d\n",
> fwreq->hdr.type);
>   break;
>   }
> 



[PATCH][V2] scsi: snic: fix a couple of spelling mistakes/typos

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

Trivial fix to spelling mistakes/typos:

"requrest_irq" -> "request_irq"
"Firmwqre" -> "Firmware"

Signed-off-by: Colin Ian King 
---
 drivers/scsi/snic/snic_isr.c  | 4 ++--
 drivers/scsi/snic/snic_scsi.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/snic/snic_isr.c b/drivers/scsi/snic/snic_isr.c
index d859501e4ccd..c4da3673f2ae 100644
--- a/drivers/scsi/snic/snic_isr.c
+++ b/drivers/scsi/snic/snic_isr.c
@@ -141,7 +141,7 @@ snic_request_intr(struct snic *snic)
  snic->msix[i].devid);
if (ret) {
SNIC_HOST_ERR(snic->shost,
- "MSI-X: requrest_irq(%d) failed %d\n",
+ "MSI-X: request_irq(%d) failed %d\n",
  i,
  ret);
snic_free_intr(snic);
@@ -151,7 +151,7 @@ snic_request_intr(struct snic *snic)
}
 
return ret;
-} /* end of snic_requrest_intr */
+} /* end of snic_request_intr */
 
 int
 snic_set_intr_mode(struct snic *snic)
diff --git a/drivers/scsi/snic/snic_scsi.c b/drivers/scsi/snic/snic_scsi.c
index 05c3a7282d4a..d8a376b7882d 100644
--- a/drivers/scsi/snic/snic_scsi.c
+++ b/drivers/scsi/snic/snic_scsi.c
@@ -1260,7 +1260,7 @@ snic_io_cmpl_handler(struct vnic_dev *vdev,
default:
SNIC_BUG_ON(1);
SNIC_SCSI_DBG(snic->shost,
- "Unknown Firmwqre completion request type %d\n",
+ "Unknown Firmware completion request type %d\n",
  fwreq->hdr.type);
break;
}
-- 
2.11.0



Re: [PATCH 03/15] megaraid_sas: Use synchronize_irq in target reset case

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 10:29 AM, Shivasharan S wrote:
> Similar to task abort case, use synchronize_irq API in target reset case.
> Also, remove redundant call to megasas_complete_cmd_dpc_fusion
> after calling megasas_sync_irqs in task abort case.
> 
> Signed-off-by: Kashyap Desai 
> Signed-off-by: Shivasharan S 
> ---
>  drivers/scsi/megaraid/megaraid_sas_fusion.c | 6 +-
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
> b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> index f717fbc..5018a3f 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> @@ -3826,8 +3826,6 @@ megasas_issue_tm(struct megasas_instance *instance, u16 
> device_handle,
>   else {
>   instance->instancet->disable_intr(instance);
>   megasas_sync_irqs((unsigned long)instance);
> - megasas_complete_cmd_dpc_fusion
> - ((unsigned long)instance);
>   instance->instancet->enable_intr(instance);
>   if (scsi_lookup->scmd == NULL)
>   break;
> @@ -3839,9 +3837,7 @@ megasas_issue_tm(struct megasas_instance *instance, u16 
> device_handle,
>   if ((channel == 0x) && (id == 0x))
>   break;
>   instance->instancet->disable_intr(instance);
> - msleep(1000);
> - megasas_complete_cmd_dpc_fusion
> - ((unsigned long)instance);
> + megasas_sync_irqs((unsigned long)instance);
>   rc = megasas_track_scsiio(instance, id, channel);
>   instance->instancet->enable_intr(instance);
>  
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


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

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 10:29 AM, Shivasharan S wrote:
> Setting resetwaittime to 0 will result in driver not calling the OCR
> during a FW fault state.
> 
> Signed-off-by: Kashyap Desai 
> Signed-off-by: Shivasharan S 
> Cc: sta...@vger.kernel.org
> ---
>  drivers/scsi/megaraid/megaraid_sas_base.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
> b/drivers/scsi/megaraid/megaraid_sas_base.c
> index 316c3df..395c3aa 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_base.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
> @@ -5478,7 +5478,8 @@ static int megasas_init_fw(struct megasas_instance 
> *instance)
>   instance->throttlequeuedepth =
>   MEGASAS_THROTTLE_QUEUE_DEPTH;
>  
> - if (resetwaittime > MEGASAS_RESET_WAIT_TIME)
> + if ((resetwaittime < 1) ||
> + (resetwaittime > MEGASAS_RESET_WAIT_TIME))
>   resetwaittime = MEGASAS_RESET_WAIT_TIME;
>  
>   if ((scmd_timeout < 10) || (scmd_timeout > MEGASAS_DEFAULT_CMD_TIMEOUT))
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


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

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 10:30 AM, Shivasharan S wrote:
> Signed-off-by: Kashyap Desai 
> Signed-off-by: Shivasharan S 
> ---
>  drivers/scsi/megaraid/megaraid_sas.h|   1 -
>  drivers/scsi/megaraid/megaraid_sas_base.c   |  12 ++-
>  drivers/scsi/megaraid/megaraid_sas_fusion.c | 113 
> +---
>  3 files changed, 80 insertions(+), 46 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


Re: [PATCH 12/15] megaraid_sas: replace internal FALSE/TRUE definitions with false/true

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 10:30 AM, Shivasharan S wrote:
> Signed-off-by: Kashyap Desai 
> Signed-off-by: Shivasharan S 
> ---
>  drivers/scsi/megaraid/megaraid_sas_fp.c | 40 
> +
>  1 file changed, 15 insertions(+), 25 deletions(-)
> Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


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

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 10:30 AM, Shivasharan S wrote:
> Currently driver sets default queue_depth for VDs at 256 and JBODs based on 
> interface type,
> ie., for SAS JBOD QD will be 64, for SATA JBOD QD will be 32.
> During performance runs with scsi-mq enabled, we are seeing better results by
> setting QD same as HBA queue_depth.
> 
> Signed-off-by: Kashyap Desai 
> Signed-off-by: Shivasharan S 
> ---
>  drivers/scsi/megaraid/megaraid_sas_base.c | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
> b/drivers/scsi/megaraid/megaraid_sas_base.c
> index 0230929..c200f1a 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_base.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
> @@ -1891,7 +1891,8 @@ static void megasas_set_static_target_properties(struct 
> scsi_device *sdev,
>   if (instance->nvme_page_size && max_io_size_kb)
>   megasas_set_nvme_device_properties(sdev, (max_io_size_kb << 
> 10));
>  
> - scsi_change_queue_depth(sdev, device_qd);
> + if (!shost_use_blk_mq(sdev->host))
> + scsi_change_queue_depth(sdev, device_qd);
>  
>  }
>  
> @@ -5914,6 +5915,9 @@ static int megasas_io_attach(struct megasas_instance 
> *instance)
>   host->max_lun = MEGASAS_MAX_LUN;
>   host->max_cmd_len = 16;
>  
> + if (shost_use_blk_mq(host))
> + host->cmd_per_lun = host->can_queue;
> +
>   /*
>* Notify the mid-layer about the new controller
>*/
> 
Is this bit really necessary? It will be adjusted by the above hunk,
would it not?

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


Re: [PATCH 15/15] megaraid_sas: driver version upgrade

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 10:30 AM, Shivasharan S wrote:
> Signed-off-by: Shivasharan S 
> ---
>  drivers/scsi/megaraid/megaraid_sas.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/megaraid/megaraid_sas.h 
> b/drivers/scsi/megaraid/megaraid_sas.h
> index 6d9f111..a6722c9 100644
> --- a/drivers/scsi/megaraid/megaraid_sas.h
> +++ b/drivers/scsi/megaraid/megaraid_sas.h
> @@ -35,8 +35,8 @@
>  /*
>   * MegaRAID SAS Driver meta data
>   */
> -#define MEGASAS_VERSION  "07.701.17.00-rc1"
> -#define MEGASAS_RELDATE  "March 2, 2017"
> +#define MEGASAS_VERSION  "07.702.06.00-rc1"
> +#define MEGASAS_RELDATE  "June 21, 2017"
>  
>  /*
>   * Device IDs
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


Re: [PATCH 14/15] megaraid_sas: call megasas_dump_frame with correct IO frame size

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 10:30 AM, Shivasharan S wrote:
> Signed-off-by: Kashyap Desai 
> Signed-off-by: Shivasharan S 
> ---
>  drivers/scsi/megaraid/megaraid_sas_base.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
> b/drivers/scsi/megaraid/megaraid_sas_base.c
> index c200f1a..c403e1d 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_base.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
> @@ -2795,7 +2795,7 @@ static int megasas_reset_bus_host(struct scsi_cmnd 
> *scmd)
>   cmd = (struct megasas_cmd_fusion *)scmd->SCp.ptr;
>   if (cmd)
>   megasas_dump_frame(cmd->io_request,
> - sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
> + MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE);
>   ret = megasas_reset_fusion(scmd->device->host,
>   SCSIIO_TIMEOUT_OCR);
>   } else
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


Re: [PATCH 13/15] megaraid_sas: modified few prints in OCR and IOC INIT path

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 10:30 AM, Shivasharan S wrote:
> Signed-off-by: Kashyap Desai 
> Signed-off-by: Shivasharan S 
> ---
>  drivers/scsi/megaraid/megaraid_sas_fusion.c | 22 +-
>  1 file changed, 13 insertions(+), 9 deletions(-)
> Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


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

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 10:29 AM, Shivasharan S wrote:
>  Fix - Driver allocated 256 byte MFI frames bytes but while sending MFI
>  frame (embedded inside chain frame of MPT frame) to firmware, driver
>  sets the length as 4k. This results in DMA read error messages during
>  boot.
> 
> Signed-off-by: Kashyap Desai 
> Signed-off-by: Shivasharan S 
> Cc: sta...@vger.kernel.org
> ---
>  drivers/scsi/megaraid/megaraid_sas_fusion.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
> b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> index f990ab4d..f717fbc 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> @@ -3283,7 +3283,7 @@ build_mpt_mfi_pass_thru(struct megasas_instance 
> *instance,
>   mpi25_ieee_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT |
>   MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR;
>  
> - mpi25_ieee_chain->Length = cpu_to_le32(instance->max_chain_frame_sz);
> + mpi25_ieee_chain->Length = cpu_to_le32(instance->mfi_frame_size);
>  }
>  
>  /**
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


Re: [PATCH 06/15] megaraid_sas: Fix endianness issues in DCMD handling

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 10:30 AM, Shivasharan S wrote:
> Signed-off-by: Kashyap Desai 
> Signed-off-by: Shivasharan S 
> ---
>  drivers/scsi/megaraid/megaraid_sas_base.c | 9 +
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


[PATCH][scsi-next] scsi: qla2xxx: fix a bunch of typos and spelling mistakes

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

Fix the following typos/spelling mistakes:

"attribure" -> "attribute"
"suppored" -> "supported"
"Symobilic" -> "Symbolic"
"iteself" -> "itself"
"reqeust" -> "request"
"nvme_wait_on_comand" -> "nvme_wait_on_command"
"bount" -> "bound"
"captrue_mask" -> "capture_mask"
"tempelate" -> "template"

..and also unwrap a line to fix a checkpatch warning.

Signed-off-by: Colin Ian King 
---
 drivers/scsi/qla2xxx/qla_attr.c | 2 +-
 drivers/scsi/qla2xxx/qla_bsg.c  | 2 +-
 drivers/scsi/qla2xxx/qla_init.c | 2 +-
 drivers/scsi/qla2xxx/qla_isr.c  | 3 +--
 drivers/scsi/qla2xxx/qla_mbx.c  | 2 +-
 drivers/scsi/qla2xxx/qla_nvme.c | 4 ++--
 drivers/scsi/qla2xxx/qla_nx.c   | 4 ++--
 drivers/scsi/qla2xxx/qla_nx2.c  | 2 +-
 8 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 6dd984203666..08a1feb3a195 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -929,7 +929,7 @@ qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
iter->name, ret);
else
ql_dbg(ql_dbg_init, vha, 0x00f4,
-   "Successfully created sysfs %s binary attribure.\n",
+   "Successfully created sysfs %s binary attribute.\n",
iter->name);
}
 }
diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index e093795a0371..2ea0ef93f5cb 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -293,7 +293,7 @@ qla2x00_process_els(struct bsg_job *bsg_job)
if (bsg_job->request_payload.sg_cnt > 1 ||
bsg_job->reply_payload.sg_cnt > 1) {
ql_dbg(ql_dbg_user, vha, 0x7002,
-   "Multiple SG's are not suppored for ELS requests, "
+   "Multiple SG's are not supported for ELS requests, "
"request_sg_cnt=%x reply_sg_cnt=%x.\n",
bsg_job->request_payload.sg_cnt,
bsg_job->reply_payload.sg_cnt);
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 8a5f5ef069ae..072ad1aa5505 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -4660,7 +4660,7 @@ qla2x00_configure_fabric(scsi_qla_host_t *vha)
} else if (qla2x00_rsnn_nn(vha)) {
/* EMPTY */
ql_dbg(ql_dbg_disc, vha, 0x209b,
-   "Register Symobilic Node Name failed.\n");
+   "Register Symbolic Node Name failed.\n");
if (test_bit(LOOP_RESYNC_NEEDED, 
>dpc_flags))
break;
}
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 011faa1dc618..6c6e624a5aa6 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -432,8 +432,7 @@ qla83xx_handle_8200_aen(scsi_qla_host_t *vha, uint16_t *mb)
"Register: 0x%x%x.\n", mb[7], mb[3]);
if (err_level == ERR_LEVEL_NON_FATAL) {
ql_log(ql_log_warn, vha, 0x5063,
-   "Not a fatal error, f/w has recovered "
-   "iteself.\n");
+   "Not a fatal error, f/w has recovered 
itself.\n");
} else if (err_level == ERR_LEVEL_RECOVERABLE_FATAL) {
ql_log(ql_log_fatal, vha, 0x5064,
"Recoverable Fatal error: Chip reset "
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 0764b6172ed1..7c6d1a404011 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -3893,7 +3893,7 @@ qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
rval = QLA_FUNCTION_FAILED;
} else if (vce->comp_status != cpu_to_le16(CS_COMPLETE)) {
ql_dbg(ql_dbg_mbx, vha, 0x10c5,
-   "Failed to complet IOCB -- completion status (%x).\n",
+   "Failed to complete IOCB -- completion status (%x).\n",
le16_to_cpu(vce->comp_status));
rval = QLA_FUNCTION_FAILED;
} else {
diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
index 1da8fa8f641d..53e58e9daba8 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -489,7 +489,7 @@ static int qla_nvme_post_cmd(struct nvme_fc_local_port 
*lport,
struct nvme_private *priv;
 
if (!fd) {
-   ql_log(ql_log_warn, NULL, 0x2134, "NO NVMe FCP reqeust\n");
+   ql_log(ql_log_warn, NULL, 0x2134, "NO NVMe FCP request\n");
return 

Re: [PATCH v4 0/5] tcmu: Add Type of reconfig into netlink

2017-06-30 Thread Mike Christie
On 06/30/2017 02:31 AM, Nicholas A. Bellinger wrote:
> Hey MNC,
> 
> On Mon, 2017-06-12 at 01:43 -0500, Mike Christie wrote:
>> On 06/11/2017 04:02 PM, Mike Christie wrote:
>>> On 06/09/2017 01:11 AM, Nicholas A. Bellinger wrote:
 Hi Bryant & Co,

 On Tue, 2017-06-06 at 09:28 -0500, Bryant G. Ly wrote:
> From: "Bryant G. Ly" 
>
> This patch consists of adding a netlink to allow for reconfiguration
> of a device in tcmu.
>
> It also changes and adds some attributes that are reconfigurable:
> write_cache, device size, and device path.
>
> V2 - Fixes kfree in tcmu: Make dev_config configurable
> V3 - Fixes spelling error
> V4 - change strcpy to strlcpy for tcmu_dev_path_store and move
>  tcmu_reconfig_type into target_core_user.h
>
>
> Bryant G. Ly (5):
>   tcmu: Support emulate_write_cache
>   tcmu: Add netlink for device reconfiguration
>   tcmu: Make dev_size configurable via userspace
>   tcmu: Make dev_config configurable
>   tcmu: Add Type of reconfig into netlink
>
>  drivers/target/target_core_user.c | 152 
> --
>  include/uapi/linux/target_core_user.h |   9 ++
>  2 files changed, 155 insertions(+), 6 deletions(-)
>

 AFAICT, it looks like all of the review comments have been addressed in
 -v4.

 Applied to target-pending/for-next, with MNC's (pseudo) Reviewed-by's
 added for #3-#5.

 Please let me know if anything else needs to be changed.

>>>
>>> The patches look ok. Thanks. Could you just merge the attached patch
>>> into "[PATCH v4 5/5] tcmu: Add Type of reconfig into netlink" or into
>>> the patchset after it? It just makes some of the names a little less
>>> generic and only returns the reconfig attr for reconfig commands.
>>>
>>
>> Actually Nick, do not merge the last patch. I have a lot more fixes/changes.
>>
>> Bryant, could you test and adapt your userspace patches for the attached
>> patch build over Nicks for-next branch.
>>
>> Basically, the patch just has use pass the value being reconfigured with
>> the netlink event. Along the way, it fixes a couple bugs.
>>
>> Nick, when we have tested the patch, then I can submit as a formal
>> patchset, or you can fold into the existing patches or whatever you prefer.
>>
> 
> Looking at merging your -v4 patches series here next:
> 
> [PATCH V4 00/10] target/tcmu: make tcmu netlink ops sync
> http://www.spinics.net/lists/target-devel/msg15706.html
> 
> Do you still want me to drop the patch from Bryant below as mentioned
> earlier..?

Hey,

First, sorry for the mess of comments/patches in various threads.

No need to drop it. The first patch:

[PATCH 01/10] tcmu: reconfigure netlink attr changes

in the thread you referenced above just fixes the stuff that needed to
be fixed.


> 
> tcmu: Add Type of reconfig into netlink
> https://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending.git/commit/?h=for-next=28d44b983000754677155e46f6bdafc7b4d84213
> 



Re: [PATCH v4 0/5] tcmu: Add Type of reconfig into netlink

2017-06-30 Thread Mike Christie
On 06/30/2017 11:58 AM, Mike Christie wrote:
> On 06/30/2017 02:31 AM, Nicholas A. Bellinger wrote:
>> Hey MNC,
>>
>> On Mon, 2017-06-12 at 01:43 -0500, Mike Christie wrote:
>>> On 06/11/2017 04:02 PM, Mike Christie wrote:
 On 06/09/2017 01:11 AM, Nicholas A. Bellinger wrote:
> Hi Bryant & Co,
>
> On Tue, 2017-06-06 at 09:28 -0500, Bryant G. Ly wrote:
>> From: "Bryant G. Ly" 
>>
>> This patch consists of adding a netlink to allow for reconfiguration
>> of a device in tcmu.
>>
>> It also changes and adds some attributes that are reconfigurable:
>> write_cache, device size, and device path.
>>
>> V2 - Fixes kfree in tcmu: Make dev_config configurable
>> V3 - Fixes spelling error
>> V4 - change strcpy to strlcpy for tcmu_dev_path_store and move
>>  tcmu_reconfig_type into target_core_user.h
>>
>>
>> Bryant G. Ly (5):
>>   tcmu: Support emulate_write_cache
>>   tcmu: Add netlink for device reconfiguration
>>   tcmu: Make dev_size configurable via userspace
>>   tcmu: Make dev_config configurable
>>   tcmu: Add Type of reconfig into netlink
>>
>>  drivers/target/target_core_user.c | 152 
>> --
>>  include/uapi/linux/target_core_user.h |   9 ++
>>  2 files changed, 155 insertions(+), 6 deletions(-)
>>
>
> AFAICT, it looks like all of the review comments have been addressed in
> -v4.
>
> Applied to target-pending/for-next, with MNC's (pseudo) Reviewed-by's
> added for #3-#5.
>
> Please let me know if anything else needs to be changed.
>

 The patches look ok. Thanks. Could you just merge the attached patch
 into "[PATCH v4 5/5] tcmu: Add Type of reconfig into netlink" or into
 the patchset after it? It just makes some of the names a little less
 generic and only returns the reconfig attr for reconfig commands.

>>>
>>> Actually Nick, do not merge the last patch. I have a lot more fixes/changes.
>>>
>>> Bryant, could you test and adapt your userspace patches for the attached
>>> patch build over Nicks for-next branch.
>>>
>>> Basically, the patch just has use pass the value being reconfigured with
>>> the netlink event. Along the way, it fixes a couple bugs.
>>>
>>> Nick, when we have tested the patch, then I can submit as a formal
>>> patchset, or you can fold into the existing patches or whatever you prefer.
>>>
>>
>> Looking at merging your -v4 patches series here next:
>>
>> [PATCH V4 00/10] target/tcmu: make tcmu netlink ops sync
>> http://www.spinics.net/lists/target-devel/msg15706.html
>>
>> Do you still want me to drop the patch from Bryant below as mentioned
>> earlier..?
> 
> Hey,
> 
> First, sorry for the mess of comments/patches in various threads.
> 
> No need to drop it. The first patch:

Oh wait. Just to make sure I understood you correctly. I meant you do
not need to drop any of Bryant's patches. But, the patches:

https://www.spinics.net/lists/target-devel/msg15593.html
https://www.spinics.net/lists/target-devel/msg15595.html

I sent in Bryant's thread "[PATCH v4 0/5] tcmu: Add Type of reconfig
into netlink" do not need to be applied. The patch "[PATCH 01/10] tcmu:
reconfigure netlink attr changes" in my patchset you referenced "[PATCH
V4 00/10] target/tcmu: make tcmu netlink ops sync" is the correct up to
date patch.


> 
> [PATCH 01/10] tcmu: reconfigure netlink attr changes
> 
> in the thread you referenced above just fixes the stuff that needed to
> be fixed.
> 
> 
>>
>> tcmu: Add Type of reconfig into netlink
>> https://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending.git/commit/?h=for-next=28d44b983000754677155e46f6bdafc7b4d84213
>>
> 



[PATCH 6/7] aacraid: add fib flag to mark scsi command callback

2017-06-30 Thread Hannes Reinecke
To correctly identify which fib has a scsi command callback this
patch implements a flag FIB_CONTEXT_FLAG_SCSI_CMD.

Signed-off-by: Hannes Reinecke 
Reviewed-by: Raghava Aditya Renukunta  
---
 drivers/scsi/aacraid/aacraid.h | 1 +
 drivers/scsi/aacraid/commsup.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
index d31a9bc..6981299 100644
--- a/drivers/scsi/aacraid/aacraid.h
+++ b/drivers/scsi/aacraid/aacraid.h
@@ -1723,6 +1723,7 @@ struct aac_dev
 #define FIB_CONTEXT_FLAG_FASTRESP  (0x0008)
 #define FIB_CONTEXT_FLAG_NATIVE_HBA(0x0010)
 #define FIB_CONTEXT_FLAG_NATIVE_HBA_TMF(0x0020)
+#define FIB_CONTEXT_FLAG_SCSI_CMD  (0x0040)
 
 /*
  * Define the command values
diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index 348f0ea..dfe8e70 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -770,6 +770,7 @@ int aac_hba_send(u8 command, struct fib *fibptr, 
fib_callback callback,
/* bit1 of request_id must be 0 */
hbacmd->request_id =
cpu_to_le32u32)(fibptr - dev->fibs)) << 2) + 1);
+   fibptr->flags |= FIB_CONTEXT_FLAG_SCSI_CMD;
} else if (command != HBA_IU_TYPE_SCSI_TM_REQ)
return -EINVAL;
 
-- 
1.8.5.6



[PATCH 2/7] aacraid: split off host reset

2017-06-30 Thread Hannes Reinecke
Split off the host reset parts of aac_eh_reset() into a separate
host reset function.

Signed-off-by: Hannes Reinecke 
Reviewed-by: Raghava Aditya Renukunta  
---
 drivers/scsi/aacraid/linit.c | 33 ++---
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 9a8a27f..bf21006 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -874,10 +874,6 @@ static int aac_eh_reset(struct scsi_cmnd* cmd)
u32 bus, cid;
int ret = FAILED;
int status = 0;
-   __le32 supported_options2 = 0;
-   bool is_mu_reset;
-   bool is_ignore_reset;
-   bool is_doorbell_reset;
 
 
bus = aac_logical_to_phys(scmd_channel(cmd));
@@ -923,7 +919,7 @@ static int aac_eh_reset(struct scsi_cmnd* cmd)
}
 
if (ret == SUCCESS)
-   goto out;
+   return ret;
 
} else {
 
@@ -952,8 +948,24 @@ static int aac_eh_reset(struct scsi_cmnd* cmd)
dev_err(>pdev->dev, "Adapter health - %d\n", status);
 
count = get_num_of_incomplete_fibs(aac);
-   if (count == 0)
-   return SUCCESS;
+   return (count == 0) ? SUCCESS : FAILED;
+}
+
+/*
+ * aac_eh_host_reset   - Host reset command handling
+ * @scsi_cmd:  SCSI command block causing the reset
+ *
+ */
+int aac_eh_host_reset(struct scsi_cmnd *cmd)
+{
+   struct scsi_device * dev = cmd->device;
+   struct Scsi_Host * host = dev->host;
+   struct aac_dev * aac = (struct aac_dev *)host->hostdata;
+   int ret = FAILED;
+   __le32 supported_options2 = 0;
+   bool is_mu_reset;
+   bool is_ignore_reset;
+   bool is_doorbell_reset;
 
/*
 * Check if reset is supported by the firmware
@@ -972,10 +984,8 @@ static int aac_eh_reset(struct scsi_cmnd* cmd)
 && (aac_check_reset != -1 || !is_ignore_reset)) {
/* Bypass wait for command quiesce */
aac_reset_adapter(aac, 2, IOP_HWSOFT_RESET);
+   ret = SUCCESS;
}
-   ret = SUCCESS;
-
-out:
return ret;
 }
 
@@ -1399,7 +1409,8 @@ ssize_t aac_get_serial_number(struct device *device, char 
*buf)
.change_queue_depth = aac_change_queue_depth,
.sdev_attrs = aac_dev_attrs,
.eh_abort_handler   = aac_eh_abort,
-   .eh_host_reset_handler  = aac_eh_reset,
+   .eh_bus_reset_handler   = aac_eh_reset,
+   .eh_host_reset_handler  = aac_eh_host_reset,
.can_queue  = AAC_NUM_IO_FIB,
.this_id= MAXIMUM_NUM_CONTAINERS,
.sg_tablesize   = 16,
-- 
1.8.5.6



[PATCH 7/7] aacraid: complete all commands during bus reset

2017-06-30 Thread Hannes Reinecke
When issuing a bus reset we should complete all commands, not
just the command triggering the reset.

Signed-off-by: Hannes Reinecke 
Reviewed-by: Raghava Aditya Renukunta  
---
 drivers/scsi/aacraid/linit.c | 34 --
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index e5d2d91..a8dedc3 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -1010,23 +1010,29 @@ static int aac_eh_bus_reset(struct scsi_cmnd* cmd)
struct Scsi_Host * host = dev->host;
struct aac_dev * aac = (struct aac_dev *)host->hostdata;
int count;
-   u32 bus, cid;
+   u32 cmd_bus;
int status = 0;
 
 
-   bus = aac_logical_to_phys(scmd_channel(cmd));
-   cid = scmd_id(cmd);
-   if (bus >= AAC_MAX_BUSES || cid >= AAC_MAX_TARGETS ||
-   aac->hba_map[bus][cid].devtype != AAC_DEVTYPE_NATIVE_RAW) {
-   /* Mark the assoc. FIB to not complete, eh handler does this */
-   for (count = 0;
-   count < (host->can_queue + AAC_NUM_MGT_FIB);
-   ++count) {
-   struct fib *fib = >fibs[count];
-
-   if (fib->hw_fib_va->header.XferState &&
-   (fib->flags & FIB_CONTEXT_FLAG) &&
-   (fib->callback_data == cmd)) {
+   cmd_bus = aac_logical_to_phys(scmd_channel(cmd));
+   /* Mark the assoc. FIB to not complete, eh handler does this */
+   for (count = 0; count < (host->can_queue + AAC_NUM_MGT_FIB); ++count) {
+   struct fib *fib = >fibs[count];
+
+   if (fib->hw_fib_va->header.XferState &&
+   (fib->flags & FIB_CONTEXT_FLAG) &&
+   (fib->flags & FIB_CONTEXT_FLAG_SCSI_CMD)) {
+   struct aac_hba_map_info *info;
+   u32 bus, cid;
+
+   cmd = (struct scsi_cmnd *)fib->callback_data;
+   bus = aac_logical_to_phys(scmd_channel(cmd));
+   if (bus != cmd_bus)
+   continue;
+   cid = scmd_id(cmd);
+   info = >hba_map[bus][cid];
+   if (bus >= AAC_MAX_BUSES || cid >= AAC_MAX_TARGETS ||
+   info->devtype != AAC_DEVTYPE_NATIVE_RAW) {
fib->flags |= FIB_CONTEXT_FLAG_TIMED_OUT;
cmd->SCp.phase = AAC_OWNER_ERROR_HANDLER;
}
-- 
1.8.5.6



[PATCH 5/7] aacraid: enable sending of TMFs from aac_hba_send()

2017-06-30 Thread Hannes Reinecke
aac_hba_send() will return FAILED for any non-SCSI command requests,
failing any TMFs. This patch updates the check to allow TMFs.

Signed-off-by: Hannes Reinecke 
Reviewed-by: Raghava Aditya Renukunta  
---
 drivers/scsi/aacraid/commsup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index 1c617cc..348f0ea 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -770,7 +770,7 @@ int aac_hba_send(u8 command, struct fib *fibptr, 
fib_callback callback,
/* bit1 of request_id must be 0 */
hbacmd->request_id =
cpu_to_le32u32)(fibptr - dev->fibs)) << 2) + 1);
-   } else
+   } else if (command != HBA_IU_TYPE_SCSI_TM_REQ)
return -EINVAL;
 
 
-- 
1.8.5.6



[PATCH 1/7] aacraid: split off functions to generate reset FIB

2017-06-30 Thread Hannes Reinecke
Split off reset FIB generation into separate functions.

Signed-off-by: Hannes Reinecke 
Reviewed-by: Raghava Aditya Renukunta  
---
 drivers/scsi/aacraid/linit.c | 83 ++--
 1 file changed, 50 insertions(+), 33 deletions(-)

diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 0f277df..9a8a27f 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -814,6 +814,52 @@ static int aac_eh_abort(struct scsi_cmnd* cmd)
return ret;
 }
 
+static u8 aac_eh_tmf_lun_reset_fib(struct aac_dev *aac, struct fib *fib,
+  int bus, int cid, u64 tmf_lun)
+{
+   struct aac_hba_tm_req *tmf;
+   u64 address;
+
+   /* start a HBA_TMF_LUN_RESET TMF request */
+   tmf = (struct aac_hba_tm_req *)fib->hw_fib_va;
+   memset(tmf, 0, sizeof(*tmf));
+   tmf->tmf = HBA_TMF_LUN_RESET;
+   tmf->it_nexus = aac->hba_map[bus][cid].rmw_nexus;
+   int_to_scsilun(tmf_lun, (struct scsi_lun *)tmf->lun);
+
+   address = (u64)fib->hw_error_pa;
+   tmf->error_ptr_hi = cpu_to_le32
+   ((u32)(address >> 32));
+   tmf->error_ptr_lo = cpu_to_le32
+   ((u32)(address & 0x));
+   tmf->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
+   fib->hbacmd_size = sizeof(*tmf);
+
+   return HBA_IU_TYPE_SCSI_TM_REQ;
+}
+
+static u8 aac_eh_tmf_hard_reset_fib(struct aac_dev *aac, struct fib *fib,
+   int bus, int cid)
+{
+   struct aac_hba_reset_req *rst;
+   u64 address;
+
+   /* already tried, start a hard reset now */
+   rst = (struct aac_hba_reset_req *)fib->hw_fib_va;
+   memset(rst, 0, sizeof(*rst));
+   /* reset_type is already zero... */
+   rst->it_nexus = aac->hba_map[bus][cid].rmw_nexus;
+
+   address = (u64)fib->hw_error_pa;
+   rst->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
+   rst->error_ptr_lo = cpu_to_le32
+   ((u32)(address & 0x));
+   rst->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
+   fib->hbacmd_size = sizeof(*rst);
+
+   return HBA_IU_TYPE_SATA_REQ;
+}
+
 /*
  * aac_eh_reset- Reset command handling
  * @scsi_cmd:  SCSI command block causing the reset
@@ -840,7 +886,6 @@ static int aac_eh_reset(struct scsi_cmnd* cmd)
aac->hba_map[bus][cid].devtype == AAC_DEVTYPE_NATIVE_RAW) {
struct fib *fib;
int status;
-   u64 address;
u8 command;
 
pr_err("%s: Host adapter reset request. SCSI hang ?\n",
@@ -852,42 +897,14 @@ static int aac_eh_reset(struct scsi_cmnd* cmd)
 
 
if (aac->hba_map[bus][cid].reset_state == 0) {
-   struct aac_hba_tm_req *tmf;
-
/* start a HBA_TMF_LUN_RESET TMF request */
-   tmf = (struct aac_hba_tm_req *)fib->hw_fib_va;
-   memset(tmf, 0, sizeof(*tmf));
-   tmf->tmf = HBA_TMF_LUN_RESET;
-   tmf->it_nexus = aac->hba_map[bus][cid].rmw_nexus;
-   tmf->lun[1] = cmd->device->lun;
-
-   address = (u64)fib->hw_error_pa;
-   tmf->error_ptr_hi = cpu_to_le32
-   ((u32)(address >> 32));
-   tmf->error_ptr_lo = cpu_to_le32
-   ((u32)(address & 0x));
-   tmf->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
-   fib->hbacmd_size = sizeof(*tmf);
-
-   command = HBA_IU_TYPE_SCSI_TM_REQ;
+   command = aac_eh_tmf_lun_reset_fib(aac, fib,
+  bus, cid,
+  cmd->device->lun);
aac->hba_map[bus][cid].reset_state++;
} else if (aac->hba_map[bus][cid].reset_state >= 1) {
-   struct aac_hba_reset_req *rst;
-
/* already tried, start a hard reset now */
-   rst = (struct aac_hba_reset_req *)fib->hw_fib_va;
-   memset(rst, 0, sizeof(*rst));
-   /* reset_type is already zero... */
-   rst->it_nexus = aac->hba_map[bus][cid].rmw_nexus;
-
-   address = (u64)fib->hw_error_pa;
-   rst->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
-   rst->error_ptr_lo = cpu_to_le32
-   ((u32)(address & 0x));
-   rst->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
-   fib->hbacmd_size = sizeof(*rst);
-
-   command = HBA_IU_TYPE_SATA_REQ;
+   command = 

[PATCH 4/7] aacraid: use aac_tmf_callback for reset fib

2017-06-30 Thread Hannes Reinecke
When sending a reset fib we shouldn't rely on the scsi command,
but rather set the TMF status in the map_info->reset_state variable.
That allows us to send a TMF independent on a scsi command.

Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/aacraid/linit.c | 99 +---
 1 file changed, 74 insertions(+), 25 deletions(-)

diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 57b2077..e5d2d91 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -814,8 +814,8 @@ static int aac_eh_abort(struct scsi_cmnd* cmd)
return ret;
 }
 
-static u8 aac_eh_tmf_lun_reset_fib(struct aac_dev *aac, struct fib *fib,
-  int bus, int cid, u64 tmf_lun)
+static u8 aac_eh_tmf_lun_reset_fib(struct aac_hba_map_info *info,
+  struct fib *fib, u64 tmf_lun)
 {
struct aac_hba_tm_req *tmf;
u64 address;
@@ -824,7 +824,7 @@ static u8 aac_eh_tmf_lun_reset_fib(struct aac_dev *aac, 
struct fib *fib,
tmf = (struct aac_hba_tm_req *)fib->hw_fib_va;
memset(tmf, 0, sizeof(*tmf));
tmf->tmf = HBA_TMF_LUN_RESET;
-   tmf->it_nexus = aac->hba_map[bus][cid].rmw_nexus;
+   tmf->it_nexus = info->rmw_nexus;
int_to_scsilun(tmf_lun, (struct scsi_lun *)tmf->lun);
 
address = (u64)fib->hw_error_pa;
@@ -838,8 +838,8 @@ static u8 aac_eh_tmf_lun_reset_fib(struct aac_dev *aac, 
struct fib *fib,
return HBA_IU_TYPE_SCSI_TM_REQ;
 }
 
-static u8 aac_eh_tmf_hard_reset_fib(struct aac_dev *aac, struct fib *fib,
-   int bus, int cid)
+static u8 aac_eh_tmf_hard_reset_fib(struct aac_hba_map_info *info,
+   struct fib *fib)
 {
struct aac_hba_reset_req *rst;
u64 address;
@@ -847,8 +847,7 @@ static u8 aac_eh_tmf_hard_reset_fib(struct aac_dev *aac, 
struct fib *fib,
/* already tried, start a hard reset now */
rst = (struct aac_hba_reset_req *)fib->hw_fib_va;
memset(rst, 0, sizeof(*rst));
-   /* reset_type is already zero... */
-   rst->it_nexus = aac->hba_map[bus][cid].rmw_nexus;
+   rst->it_nexus = info->rmw_nexus;
 
address = (u64)fib->hw_error_pa;
rst->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
@@ -860,6 +859,33 @@ static u8 aac_eh_tmf_hard_reset_fib(struct aac_dev *aac, 
struct fib *fib,
return HBA_IU_TYPE_SATA_REQ;
 }
 
+void aac_tmf_callback(void *context, struct fib *fibptr)
+{
+   struct aac_hba_resp *err =
+   &((struct aac_native_hba *)fibptr->hw_fib_va)->resp.err;
+   struct aac_hba_map_info *info = context;
+   int res;
+
+   switch (err->service_response) {
+   case HBA_RESP_SVCRES_TMF_REJECTED:
+   res = -1;
+   break;
+   case HBA_RESP_SVCRES_TMF_LUN_INVALID:
+   res = 0;
+   break;
+   case HBA_RESP_SVCRES_TMF_COMPLETE:
+   case HBA_RESP_SVCRES_TMF_SUCCEEDED:
+   res = 0;
+   break;
+   default:
+   res = -2;
+   break;
+   }
+   aac_fib_complete(fibptr);
+
+   info->reset_state = res;
+}
+
 /*
  * aac_eh_dev_reset- Device reset command handling
  * @scsi_cmd:  SCSI command block causing the reset
@@ -870,6 +896,7 @@ static int aac_eh_dev_reset(struct scsi_cmnd *cmd)
struct scsi_device * dev = cmd->device;
struct Scsi_Host * host = dev->host;
struct aac_dev * aac = (struct aac_dev *)host->hostdata;
+   struct aac_hba_map_info *info;
int count;
u32 bus, cid;
struct fib *fib;
@@ -879,8 +906,12 @@ static int aac_eh_dev_reset(struct scsi_cmnd *cmd)
 
bus = aac_logical_to_phys(scmd_channel(cmd));
cid = scmd_id(cmd);
+   info = >hba_map[bus][cid];
if (bus >= AAC_MAX_BUSES || cid >= AAC_MAX_TARGETS ||
-   aac->hba_map[bus][cid].devtype != AAC_DEVTYPE_NATIVE_RAW)
+   info->devtype != AAC_DEVTYPE_NATIVE_RAW)
+   return FAILED;
+
+   if (info->reset_state > 0)
return FAILED;
 
pr_err("%s: Host adapter reset request. SCSI hang ?\n",
@@ -890,21 +921,19 @@ static int aac_eh_dev_reset(struct scsi_cmnd *cmd)
if (!fib)
return ret;
 
-
/* start a HBA_TMF_LUN_RESET TMF request */
-   command = aac_eh_tmf_lun_reset_fib(aac, fib, bus, cid,
-  cmd->device->lun);
+   command = aac_eh_tmf_lun_reset_fib(info, fib, dev->lun);
 
-   cmd->SCp.sent_command = 0;
+   info->reset_state = 1;
 
status = aac_hba_send(command, fib,
- (fib_callback) aac_hba_callback,
- (void *) cmd);
+ (fib_callback) aac_tmf_callback,
+ (void *) info);
 
/* Wait up to 15 seconds for completion */
for 

[PATCH 3/7] aacraid: split off device, target, and bus reset

2017-06-30 Thread Hannes Reinecke
Split off device, target, and bus reset functionality into
individual functions.

Signed-off-by: Hannes Reinecke 
Reviewed-by: Raghava Aditya Renukunta  
---
 drivers/scsi/aacraid/linit.c | 141 +++
 1 file changed, 102 insertions(+), 39 deletions(-)

diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index bf21006..57b2077 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -861,68 +861,129 @@ static u8 aac_eh_tmf_hard_reset_fib(struct aac_dev *aac, 
struct fib *fib,
 }
 
 /*
- * aac_eh_reset- Reset command handling
+ * aac_eh_dev_reset- Device reset command handling
  * @scsi_cmd:  SCSI command block causing the reset
  *
  */
-static int aac_eh_reset(struct scsi_cmnd* cmd)
+static int aac_eh_dev_reset(struct scsi_cmnd *cmd)
 {
struct scsi_device * dev = cmd->device;
struct Scsi_Host * host = dev->host;
struct aac_dev * aac = (struct aac_dev *)host->hostdata;
int count;
u32 bus, cid;
+   struct fib *fib;
int ret = FAILED;
-   int status = 0;
-
+   int status;
+   u8 command;
 
bus = aac_logical_to_phys(scmd_channel(cmd));
cid = scmd_id(cmd);
-   if (bus < AAC_MAX_BUSES && cid < AAC_MAX_TARGETS &&
-   aac->hba_map[bus][cid].devtype == AAC_DEVTYPE_NATIVE_RAW) {
-   struct fib *fib;
-   int status;
-   u8 command;
+   if (bus >= AAC_MAX_BUSES || cid >= AAC_MAX_TARGETS ||
+   aac->hba_map[bus][cid].devtype != AAC_DEVTYPE_NATIVE_RAW)
+   return FAILED;
 
-   pr_err("%s: Host adapter reset request. SCSI hang ?\n",
-   AAC_DRIVERNAME);
+   pr_err("%s: Host adapter reset request. SCSI hang ?\n",
+  AAC_DRIVERNAME);
 
-   fib = aac_fib_alloc(aac);
-   if (!fib)
-   return ret;
+   fib = aac_fib_alloc(aac);
+   if (!fib)
+   return ret;
 
 
-   if (aac->hba_map[bus][cid].reset_state == 0) {
-   /* start a HBA_TMF_LUN_RESET TMF request */
-   command = aac_eh_tmf_lun_reset_fib(aac, fib,
-  bus, cid,
-  cmd->device->lun);
-   aac->hba_map[bus][cid].reset_state++;
-   } else if (aac->hba_map[bus][cid].reset_state >= 1) {
-   /* already tried, start a hard reset now */
-   command = aac_eh_tmf_hard_reset_fib(aac, fib, bus, cid);
-   aac->hba_map[bus][cid].reset_state = 0;
+   /* start a HBA_TMF_LUN_RESET TMF request */
+   command = aac_eh_tmf_lun_reset_fib(aac, fib, bus, cid,
+  cmd->device->lun);
+
+   cmd->SCp.sent_command = 0;
+
+   status = aac_hba_send(command, fib,
+ (fib_callback) aac_hba_callback,
+ (void *) cmd);
+
+   /* Wait up to 15 seconds for completion */
+   for (count = 0; count < 15; ++count) {
+   if (cmd->SCp.sent_command) {
+   ret = SUCCESS;
+   break;
}
-   cmd->SCp.sent_command = 0;
+   msleep(1000);
+   }
 
-   status = aac_hba_send(command, fib,
- (fib_callback) aac_hba_callback,
- (void *) cmd);
+   return ret;
+}
 
-   /* Wait up to 15 seconds for completion */
-   for (count = 0; count < 15; ++count) {
-   if (cmd->SCp.sent_command) {
-   ret = SUCCESS;
-   break;
-   }
-   msleep(1000);
+/*
+ * aac_eh_target_reset - Target reset command handling
+ * @scsi_cmd:  SCSI command block causing the reset
+ *
+ */
+static int aac_eh_target_reset(struct scsi_cmnd *cmd)
+{
+   struct scsi_device * dev = cmd->device;
+   struct Scsi_Host * host = dev->host;
+   struct aac_dev * aac = (struct aac_dev *)host->hostdata;
+   int count;
+   u32 bus, cid;
+   int ret = FAILED;
+   struct fib *fib;
+   int status;
+   u8 command;
+
+   bus = aac_logical_to_phys(scmd_channel(cmd));
+   cid = scmd_id(cmd);
+   if (bus >= AAC_MAX_BUSES || cid >= AAC_MAX_TARGETS ||
+   aac->hba_map[bus][cid].devtype != AAC_DEVTYPE_NATIVE_RAW)
+   return FAILED;
+
+   pr_err("%s: Host adapter reset request. SCSI hang ?\n",
+  AAC_DRIVERNAME);
+
+   fib = aac_fib_alloc(aac);
+   if (!fib)
+   return ret;
+
+
+   /* already tried, start a hard reset now */
+   command = 

[PATCH 0/7] aacraid: split off EH functions

2017-06-30 Thread Hannes Reinecke
Hi all,

this patchset is a split off from the original patchset to rework
SCSI EH function parameters. As it's pretty much independent and
an improvement to the existing EH callback function, so I'm posting
it separately.

As usual, comments and reviews are welcome.

Hannes Reinecke (7):
  aacraid: split off functions to generate reset FIB
  aacraid: split off host reset
  aacraid: split off device, target, and bus reset
  aacraid: use aac_tmf_callback for reset fib
  aacraid: enable sending of TMFs from aac_hba_send()
  aacraid: add fib flag to mark scsi command callback
  aacraid: complete all commands during bus reset

 drivers/scsi/aacraid/aacraid.h |   1 +
 drivers/scsi/aacraid/commsup.c |   3 +-
 drivers/scsi/aacraid/linit.c   | 318 ++---
 3 files changed, 235 insertions(+), 87 deletions(-)

-- 
1.8.5.6



Re: [PATCH 1/2] Drop legacy megaraid controller

2017-06-30 Thread Christoph Hellwig
On Fri, Jun 30, 2017 at 01:05:53PM +0200, Hannes Reinecke wrote:
> The hardware is ancient, and support for most cards has been moved
> to megaraid_mbox. So drop it.


This seems to drop support for the PCI_DEVICE_ID_AMI_MEGARAID
and PCI_DEVICE_ID_AMI_MEGARAID2 cards.  Do we have any suggestions
this code is so broken to not care anymore? Is there any reason why
they can't just work with the megaraid_mbox driver?


Re: [PATCH 1/2] scsi: qla2xxx: remove incorrect byte swap

2017-06-30 Thread Madhani, Himanshu

> On Jun 30, 2017, at 9:41 AM, James Bottomley  wrote:
> 
> On Fri, 2017-06-30 at 18:10 +0200, Arnd Bergmann wrote:
>> cont_pkt->entry_type is an 8-bit field, so doing a 32-bit byteswap
>> on it will store incorrect data:
>> 
>> drivers/scsi/qla2xxx/qla_nvme.c: In function 'qla2x00_start_nvme_mq':
>> include/uapi/linux/byteorder/big_endian.h:32:26: error: large integer
>> implicitly truncated to unsigned type [-Werror=overflow]
>> drivers/scsi/qla2xxx/qla_nvme.c:444:27: note: in expansion of macro
>> 'cpu_to_le32'
>> cont_pkt->entry_type = cpu_to_le32(CONTINUE_A64_TYPE);
>> 
>> This removes the erroneous cpu_to_le32().
>> 
>> Fixes: e84067d74301 ("scsi: qla2xxx: Add FC-NVMe F/W initialization
>> and transport registration")
>> Signed-off-by: Arnd Bergmann 
>> ---
>>  drivers/scsi/qla2xxx/qla_nvme.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/drivers/scsi/qla2xxx/qla_nvme.c
>> b/drivers/scsi/qla2xxx/qla_nvme.c
>> index 1da8fa8f641d..14e25e32e622 100644
>> --- a/drivers/scsi/qla2xxx/qla_nvme.c
>> +++ b/drivers/scsi/qla2xxx/qla_nvme.c
>> @@ -441,7 +441,7 @@ static int qla2x00_start_nvme_mq(srb_t *sp)
>>  req->ring_ptr++;
>>  }
>>  cont_pkt = (cont_a64_entry_t *)req-
>>> ring_ptr;
>> -cont_pkt->entry_type =
>> cpu_to_le32(CONTINUE_A64_TYPE);
>> +cont_pkt->entry_type = CONTINUE_A64_TYPE;
>>  
> 
> We already have a patch proposed for this, but I think it may be wrong
> (it's the same as yours, so yours may be wrong too) see the handling in
> qla_iocb.c
> 
> James

I will send patch which has correct usage in qla_iocb.c shortly. 

Thanks,
- Himanshu



[PATCH 2/2] scsi: qla2xxx: avoid unused-function warning

2017-06-30 Thread Arnd Bergmann
When NVMe support is disabled, we get a couple of harmless warnings:

drivers/scsi/qla2xxx/qla_nvme.c:667:13: error: 
'qla_nvme_unregister_remote_port' defined but not used [-Werror=unused-function]
drivers/scsi/qla2xxx/qla_nvme.c:634:13: error: 'qla_nvme_abort_all' defined but 
not used [-Werror=unused-function]
drivers/scsi/qla2xxx/qla_nvme.c:604:12: error: 'qla_nvme_wait_on_rport_del' 
defined but not used [-Werror=unused-function]

This replaces the preprocessor checks in the code with equivalent
compiler conditionals, which lets gcc drop the unused functions
without warning, and is nicer to read.

Fixes: e84067d74301 ("scsi: qla2xxx: Add FC-NVMe F/W initialization and 
transport registration")
Signed-off-by: Arnd Bergmann 
---
 drivers/scsi/qla2xxx/Kconfig|  1 +
 drivers/scsi/qla2xxx/qla_nvme.c | 20 
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/qla2xxx/Kconfig b/drivers/scsi/qla2xxx/Kconfig
index de952935b5d2..036cc3f217b1 100644
--- a/drivers/scsi/qla2xxx/Kconfig
+++ b/drivers/scsi/qla2xxx/Kconfig
@@ -2,6 +2,7 @@ config SCSI_QLA_FC
tristate "QLogic QLA2XXX Fibre Channel Support"
depends on PCI && SCSI
depends on SCSI_FC_ATTRS
+   depends on NVME_FC || !NVME_FC
select FW_LOADER
select BTREE
---help---
diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
index 14e25e32e622..9c18d754ac33 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -17,10 +17,12 @@ static void qla_nvme_unregister_remote_port(struct 
work_struct *);
 
 int qla_nvme_register_remote(scsi_qla_host_t *vha, fc_port_t *fcport)
 {
-#if (IS_ENABLED(CONFIG_NVME_FC))
struct nvme_rport *rport;
int ret;
 
+   if (!IS_ENABLED(CONFIG_NVME_FC))
+   return 0;
+
if (fcport->nvme_flag & NVME_FLAG_REGISTERED)
return 0;
 
@@ -78,7 +80,6 @@ int qla_nvme_register_remote(scsi_qla_host_t *vha, fc_port_t 
*fcport)
init_waitqueue_head(>nvme_waitQ);
rport->fcport = fcport;
list_add_tail(>list, >nvme_rport_list);
-#endif
return 0;
 }
 
@@ -666,11 +667,13 @@ static void qla_nvme_abort_all(fc_port_t *fcport)
 
 static void qla_nvme_unregister_remote_port(struct work_struct *work)
 {
-#if (IS_ENABLED(CONFIG_NVME_FC))
struct fc_port *fcport = container_of(work, struct fc_port,
nvme_del_work);
struct nvme_rport *rport, *trport;
 
+   if (!IS_ENABLED(CONFIG_NVME_FC))
+   return;
+
list_for_each_entry_safe(rport, trport,
>vha->nvme_rport_list, list) {
if (rport->fcport == fcport) {
@@ -680,16 +683,17 @@ static void qla_nvme_unregister_remote_port(struct 
work_struct *work)
fcport->nvme_remote_port);
}
}
-#endif
 }
 
 void qla_nvme_delete(scsi_qla_host_t *vha)
 {
-#if (IS_ENABLED(CONFIG_NVME_FC))
struct nvme_rport *rport, *trport;
fc_port_t *fcport;
int nv_ret;
 
+   if (!IS_ENABLED(CONFIG_NVME_FC))
+   return;
+
list_for_each_entry_safe(rport, trport, >nvme_rport_list, list) {
fcport = rport->fcport;
 
@@ -711,17 +715,18 @@ void qla_nvme_delete(scsi_qla_host_t *vha)
ql_log(ql_log_info, vha, 0x2115,
"Unregister of localport failed\n");
}
-#endif
 }
 
 void qla_nvme_register_hba(scsi_qla_host_t *vha)
 {
-#if (IS_ENABLED(CONFIG_NVME_FC))
struct nvme_fc_port_template *tmpl;
struct qla_hw_data *ha;
struct nvme_fc_port_info pinfo;
int ret;
 
+   if (!IS_ENABLED(CONFIG_NVME_FC))
+   return;
+
ha = vha->hw;
tmpl = _nvme_fc_transport;
 
@@ -752,5 +757,4 @@ void qla_nvme_register_hba(scsi_qla_host_t *vha)
atomic_set(>nvme_ref_count, 1);
vha->nvme_local_port->private = vha;
init_waitqueue_head(>nvme_waitQ);
-#endif
 }
-- 
2.9.0



[PATCH 1/2] scsi: qla2xxx: remove incorrect byte swap

2017-06-30 Thread Arnd Bergmann
cont_pkt->entry_type is an 8-bit field, so doing a 32-bit byteswap
on it will store incorrect data:

drivers/scsi/qla2xxx/qla_nvme.c: In function 'qla2x00_start_nvme_mq':
include/uapi/linux/byteorder/big_endian.h:32:26: error: large integer 
implicitly truncated to unsigned type [-Werror=overflow]
drivers/scsi/qla2xxx/qla_nvme.c:444:27: note: in expansion of macro 
'cpu_to_le32'
cont_pkt->entry_type = cpu_to_le32(CONTINUE_A64_TYPE);

This removes the erroneous cpu_to_le32().

Fixes: e84067d74301 ("scsi: qla2xxx: Add FC-NVMe F/W initialization and 
transport registration")
Signed-off-by: Arnd Bergmann 
---
 drivers/scsi/qla2xxx/qla_nvme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
index 1da8fa8f641d..14e25e32e622 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -441,7 +441,7 @@ static int qla2x00_start_nvme_mq(srb_t *sp)
req->ring_ptr++;
}
cont_pkt = (cont_a64_entry_t *)req->ring_ptr;
-   cont_pkt->entry_type = cpu_to_le32(CONTINUE_A64_TYPE);
+   cont_pkt->entry_type = CONTINUE_A64_TYPE;
 
cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
avail_dsds = 5;
-- 
2.9.0



Re: [PATCH 1/2] scsi: lpfc: spin_lock_irq() is not nestable

2017-06-30 Thread James Smart

On 6/30/2017 1:02 AM, Dan Carpenter wrote:

We're calling spin_lock_irq() multiple times, the problem is that on the
first spin_unlock_irq() then we will re-enable IRQs and we don't want
that.

Fixes: 966bb5b71196 ("scsi: lpfc: Break up IO ctx list into a separate get and put 
list")
Signed-off-by: Dan Carpenter 



looks good.

Signed-off-By: James Smart 


Re: [PATCH 2/2] scsi: lpfc: don't double count abort errors

2017-06-30 Thread James Smart

On 6/30/2017 1:03 AM, Dan Carpenter wrote:

If lpfc_nvmet_unsol_fcp_issue_abort() fails then we accidentally
increment "tgtp->xmt_abort_rsp_error" and then two lines later we
increment it a second time.

Fixes: 547077a44b3b ("scsi: lpfc: Adding additional stats counters for nvme.")
Signed-off-by: Dan Carpenter 

diff --git a/drivers/scsi/lpfc/lpfc_nvmet.c b/drivers/scsi/lpfc/lpfc_nvmet.c
index 7dc061a14f95..fbeec344c6cc 100644
--- a/drivers/scsi/lpfc/lpfc_nvmet.c
+++ b/drivers/scsi/lpfc/lpfc_nvmet.c
@@ -2583,7 +2583,6 @@ lpfc_nvmet_unsol_fcp_issue_abort(struct lpfc_hba *phba,
}
  
  aerr:

-   atomic_inc(>xmt_abort_rsp_error);
ctxp->flag &= ~LPFC_NVMET_ABORT_OP;
atomic_inc(>xmt_abort_rsp_error);
lpfc_printf_log(phba, KERN_ERR, LOG_NVME_ABTS,


looks good.

Signed-off-By: James Smart 


Re: [PATCH 1/2] scsi: qla2xxx: remove incorrect byte swap

2017-06-30 Thread James Bottomley
On Fri, 2017-06-30 at 18:10 +0200, Arnd Bergmann wrote:
> cont_pkt->entry_type is an 8-bit field, so doing a 32-bit byteswap
> on it will store incorrect data:
> 
> drivers/scsi/qla2xxx/qla_nvme.c: In function 'qla2x00_start_nvme_mq':
> include/uapi/linux/byteorder/big_endian.h:32:26: error: large integer
> implicitly truncated to unsigned type [-Werror=overflow]
> drivers/scsi/qla2xxx/qla_nvme.c:444:27: note: in expansion of macro
> 'cpu_to_le32'
> cont_pkt->entry_type = cpu_to_le32(CONTINUE_A64_TYPE);
> 
> This removes the erroneous cpu_to_le32().
> 
> Fixes: e84067d74301 ("scsi: qla2xxx: Add FC-NVMe F/W initialization
> and transport registration")
> Signed-off-by: Arnd Bergmann 
> ---
>  drivers/scsi/qla2xxx/qla_nvme.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/qla2xxx/qla_nvme.c
> b/drivers/scsi/qla2xxx/qla_nvme.c
> index 1da8fa8f641d..14e25e32e622 100644
> --- a/drivers/scsi/qla2xxx/qla_nvme.c
> +++ b/drivers/scsi/qla2xxx/qla_nvme.c
> @@ -441,7 +441,7 @@ static int qla2x00_start_nvme_mq(srb_t *sp)
>   req->ring_ptr++;
>   }
>   cont_pkt = (cont_a64_entry_t *)req-
> >ring_ptr;
> - cont_pkt->entry_type =
> cpu_to_le32(CONTINUE_A64_TYPE);
> + cont_pkt->entry_type = CONTINUE_A64_TYPE;
> 

We already have a patch proposed for this, but I think it may be wrong
(it's the same as yours, so yours may be wrong too) see the handling in
qla_iocb.c

James



RE: [PATCH 26/28] visorhba: sanitze private device data allocation

2017-06-30 Thread Kershner, David A
> -Original Message-
> From: Hannes Reinecke [mailto:h...@suse.de]
> Sent: Wednesday, June 28, 2017 4:25 AM
> To: Christoph Hellwig 
> Cc: Martin K. Petersen ; James Bottomley
> ; linux-scsi@vger.kernel.org;
> Hannes Reinecke ; Hannes Reinecke ;
> Kershner, David A 
> Subject: [PATCH 26/28] visorhba: sanitze private device data allocation
> 
> There's no need to keep the private data for a device in a separate
> list; better to store it in ->hostdata and do away with the additional
> list.
> 
> Signed-off-by: Hannes Reinecke 
> Cc: David Kershner 

Thanks for the patch, works great!  Tested it on s-Par. 

Acked-by: David Kershner 

Thanks, 
David Kershner

> ---
>  drivers/staging/unisys/visorhba/visorhba_main.c | 123 ++--
> 
>  1 file changed, 53 insertions(+), 70 deletions(-)
> 
> diff --git a/drivers/staging/unisys/visorhba/visorhba_main.c
> b/drivers/staging/unisys/visorhba/visorhba_main.c
> index 6997b16..811abfc 100644
> --- a/drivers/staging/unisys/visorhba/visorhba_main.c
> +++ b/drivers/staging/unisys/visorhba/visorhba_main.c
> @@ -47,8 +47,8 @@
>  MODULE_ALIAS("visorbus:"
> SPAR_VHBA_CHANNEL_PROTOCOL_UUID_STR);
> 
>  struct visordisk_info {
> + struct scsi_device *sdev;
>   u32 valid;
> - u32 channel, id, lun;   /* Disk Path */
>   atomic_t ios_threshold;
>   atomic_t error_count;
>   struct visordisk_info *next;
> @@ -101,12 +101,6 @@ struct visorhba_devices_open {
>   struct visorhba_devdata *devdata;
>  };
> 
> -#define for_each_vdisk_match(iter, list, match) \
> - for (iter = >head; iter->next; iter = iter->next) \
> - if ((iter->channel == match->channel) && \
> - (iter->id == match->id) && \
> - (iter->lun == match->lun))
> -
>  /*
>   *   visor_thread_start - starts a thread for the device
>   *   @threadfn: Function the thread starts
> @@ -296,10 +290,9 @@ static void cleanup_scsitaskmgmt_handles(struct idr
> *idrtable,
>   *   Returns whether the command was queued successfully or not.
>   */
>  static int forward_taskmgmt_command(enum task_mgmt_types tasktype,
> - struct scsi_cmnd *scsicmd)
> + struct scsi_device *scsidev)
>  {
>   struct uiscmdrsp *cmdrsp;
> - struct scsi_device *scsidev = scsicmd->device;
>   struct visorhba_devdata *devdata =
>   (struct visorhba_devdata *)scsidev->host->hostdata;
>   int notifyresult = 0x;
> @@ -347,12 +340,6 @@ static int forward_taskmgmt_command(enum
> task_mgmt_types tasktype,
>   dev_dbg(>sdev_gendev,
>   "visorhba: taskmgmt type=%d success; result=0x%x\n",
>tasktype, notifyresult);
> - if (tasktype == TASK_MGMT_ABORT_TASK)
> - scsicmd->result = DID_ABORT << 16;
> - else
> - scsicmd->result = DID_RESET << 16;
> -
> - scsicmd->scsi_done(scsicmd);
>   cleanup_scsitaskmgmt_handles(>idr, cmdrsp);
>   return SUCCESS;
> 
> @@ -376,17 +363,20 @@ static int visorhba_abort_handler(struct scsi_cmnd
> *scsicmd)
>   /* issue TASK_MGMT_ABORT_TASK */
>   struct scsi_device *scsidev;
>   struct visordisk_info *vdisk;
> - struct visorhba_devdata *devdata;
> + int rtn;
> 
>   scsidev = scsicmd->device;
> - devdata = (struct visorhba_devdata *)scsidev->host->hostdata;
> - for_each_vdisk_match(vdisk, devdata, scsidev) {
> - if (atomic_read(>error_count) <
> VISORHBA_ERROR_COUNT)
> - atomic_inc(>error_count);
> - else
> - atomic_set(>ios_threshold,
> IOS_ERROR_THRESHOLD);
> + vdisk = scsidev->hostdata;
> + if (atomic_read(>error_count) < VISORHBA_ERROR_COUNT)
> + atomic_inc(>error_count);
> + else
> + atomic_set(>ios_threshold,
> IOS_ERROR_THRESHOLD);
> + rtn = forward_taskmgmt_command(TASK_MGMT_ABORT_TASK,
> scsidev);
> + if (rtn == SUCCESS) {
> + scsicmd->result = DID_ABORT << 16;
> + scsicmd->scsi_done(scsicmd);
>   }
> - return forward_taskmgmt_command(TASK_MGMT_ABORT_TASK,
> scsicmd);
> + return rtn;
>  }
> 
>  /*
> @@ -400,17 +390,20 @@ static int visorhba_device_reset_handler(struct
> scsi_cmnd *scsicmd)
>   /* issue TASK_MGMT_LUN_RESET */
>   struct scsi_device *scsidev;
>   struct visordisk_info *vdisk;
> - struct visorhba_devdata *devdata;
> + int rtn;
> 
>   scsidev = scsicmd->device;
> - devdata = (struct visorhba_devdata *)scsidev->host->hostdata;
> - for_each_vdisk_match(vdisk, devdata, scsidev) {
> - if (atomic_read(>error_count) <
> VISORHBA_ERROR_COUNT)
> - atomic_inc(>error_count);
> - else
> - 

Re: [PATCH v5 0/6] g_NCR5380: PDMA fixes and cleanup

2017-06-30 Thread Ondrej Zary
On Friday 30 June 2017 09:12:37 Finn Thain wrote:
> On Thu, 29 Jun 2017, Ondrej Zary wrote:
> > The write corruption is still there. I'm afraid it can't be fixed
> > without rolling "start" back (or inceasing residual) if an error
> > occured, something like this:
> >
> > --- a/drivers/scsi/g_NCR5380.c
> > +++ b/drivers/scsi/g_NCR5380.c
> > @@ -619,6 +621,9 @@ static inline int generic_NCR5380_psend(struct
> >(int)NCR5380_read(hostdata->c400_blk_cnt) * 128);
> >
> > if (residual != 0) {
> > +   residual += 128;
> > /* 53c80 interrupt or transfer timeout. Reset 53c400 logic. */
> > NCR5380_write(hostdata->c400_ctl_status, CSR_RESET);
> > NCR5380_write(hostdata->c400_ctl_status, CSR_BASE);
> >
> > (seems to work - wrote 230MB and read it back with no differences)
> >
> > The corruption mechanism is:
> > 1. Host buffer is ready so we write 128 B of data there and increment
> >"start".
> > 2. Chip swaps the buffers, decrements the block counter and starts
> >writing the data to drive.
> > 3. Drive does not like it (e.g. its buffer is full) so it disconnects.
> > 4. Chip stops writing and asserts an IRQ.
> > 5. We detect the IRQ. The block counter is already decremented, "start"
> >is already incremented but the data was not written to the drive.
>
> OK. Thanks for that analysis.
>
> It sounds like the c400_blk_cnt value gives the number of buffer swaps
> remaining. If so, that value isn't useful for calculating a residual. I'll
> rework that calculation again.
>
> In your patch, the residual gets increased regardless of the actual cause
> of the short transfer. Nothing prevents the residual from being increased
> beyond the original length of the transfer (due to a flaky target or bus).
> Therefore I've taken a slightly different approach in my patch (below).

Yes, that's wrong. My original patch had "start -= 128" and then check for 
negative value.

> > No more log spamming on DTC but reads are corrupted even more than
> > before. The IRQ check after data transfer increases the chance of
> > catching an IRQ before the buffer could become ready.
>
> If we delay the IRQ check, that just means that CSR_GATED_53C80_IRQ will
> be detected a bit later (128 bytes later)... so not much difference.

The main difference is that my original patch read the CSR once and then:
- transfer data if the buffer is ready, ignoring any IRQ
- if the buffer is not ready, check for an IRQ
- if neither buffer is ready nor IRQ was asserted, check for timeout

So yes, the IRQ will be detected 128 bytes later - but the IRQ is asserted at 
3968 bytes which means the transfer will then be complete.

> > This patch:
> > --- a/drivers/scsi/g_NCR5380.c
> > +++ b/drivers/scsi/g_NCR5380.c
> > @@ -548,8 +548,10 @@ static inline int generic_NCR5380_precv(struct
> > start += 128;
> >
> > if (NCR5380_read(hostdata->c400_ctl_status) &
> > -   CSR_GATED_53C80_IRQ)
> > +   CSR_GATED_53C80_IRQ) {
> > +   printk("r irq at start=%d basr=0x%02x\n", start,
> > NCR5380_read(BUS_AND_STATUS_REG)); break;
> > +   }
> > }
> >
> > residual = len - start;
> >
> > produces lots of these lines:
> > [  896.194054] r irq at start=128 basr=0x98
> > [  896.197758] r irq at start=3968 basr=0x98
>
> Assuming that the registers are available and valid, the value 0x98 means
> BASR_END_DMA_TRANSFER | BASR_IRQ | BASR_PHASE_MATCH. There is no
> BASR_BUSY_ERROR here, so the cause of the CSR_GATED_53C80_IRQ must be that
> the 53c400 has terminated the transfer by asserting /EOP. That shouldn't
> happen before before the counters run down.
>
> It doesn't make sense. So maybe the 53c80 registers are not valid at this
> point? That means a phase mismatch can't be excluded... unlikely at 128
> bytes into the transfer. Busy error? Also unlikely.
>
> I have to conclude that CSR_GATED_53C80_IRQ and BASR_END_DMA_TRANSFER
> can't be trusted on this board. I guess that's why you examine the BASR
> directly in your original algorithm but ignore BASR_END_DMA_TRANSFER.

Exactly, BASR_END_DMA_TRANSFER causes problems on DTC.

> It does look like some kind of timing issue: the "start" value above
> changes from one log message to the next. Who knows?

Only that two values (128 and 3968) appeared. 3968 = 4096-128, one block 
before the end of transfer. So probably BASR_END_DMA_TRANSFER is asserted one 
block earlier (i.e. when the last block of data is transferred from the drive 
to the chip buffer).
Haven't seen this problem at start=128 before.

> > This fixes the DTC read corruption, although I don't like the repeated
> > ctl_status register reads:
> > --- a/drivers/scsi/g_NCR5380.c
> > +++ b/drivers/scsi/g_NCR5380.c
> > @@ -533,7 +533,7 @@ static inline int generic_NCR5380_precv(struct
> > break;
> >
> > if (NCR5380_read(hostdata->c400_ctl_status) &
> > -   CSR_HOST_BUF_NOT_RDY)
> > +   

Re: [PATCH 1/2] Drop legacy megaraid controller

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 07:33 PM, Christoph Hellwig wrote:
> On Fri, Jun 30, 2017 at 01:05:53PM +0200, Hannes Reinecke wrote:
>> The hardware is ancient, and support for most cards has been moved
>> to megaraid_mbox. So drop it.
> 
> 
> This seems to drop support for the PCI_DEVICE_ID_AMI_MEGARAID
> and PCI_DEVICE_ID_AMI_MEGARAID2 cards.  Do we have any suggestions
> this code is so broken to not care anymore? Is there any reason why
> they can't just work with the megaraid_mbox driver?
> 
Hmm. Probably no good reason at all.
I'll check which version I have here.

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


Re: [PATCH] qla2xxx: Fix compile warning

2017-06-30 Thread James Bottomley
OK, the subject is technically true, but to most people "fix compile
warning" means yet another pointless patch.  This patch isn't
pointless, though, is it?  The driver is actually broken on big endian
systems without it, so the subject should probably say this because
it's important for distros triaging whether to backport this fix if
they backport the nvme components.

On Fri, 2017-06-30 at 16:56 -0700, Himanshu Madhani wrote:
> drivers/scsi/qla2xxx/qla_nvme.c: In function 'qla2x00_start_nvme_mq':
> include/uapi/linux/byteorder/big_endian.h:32:26: warning: large
> integer implicitly truncated to unsigned type [-Woverflow]
>  #define __cpu_to_le32(x) ((__force __le32)__swab32((x)))

This text doesn't explain why you've fixed the bug this way.  It has to
do with the 32 byte reads the card does for the mailbox, so you should
explain what the actual problem the compile warning picked up is and
why you fixed it by doing an entire 32 bit write.

Preferably ASAP because the merge window will open on Monday.

James



Re: [PATCH 2/2] scsi: qla2xxx: avoid unused-function warning

2017-06-30 Thread Madhani, Himanshu

> On Jun 30, 2017, at 9:10 AM, Arnd Bergmann  wrote:
> 
> When NVMe support is disabled, we get a couple of harmless warnings:
> 
> drivers/scsi/qla2xxx/qla_nvme.c:667:13: error: 
> 'qla_nvme_unregister_remote_port' defined but not used 
> [-Werror=unused-function]
> drivers/scsi/qla2xxx/qla_nvme.c:634:13: error: 'qla_nvme_abort_all' defined 
> but not used [-Werror=unused-function]
> drivers/scsi/qla2xxx/qla_nvme.c:604:12: error: 'qla_nvme_wait_on_rport_del' 
> defined but not used [-Werror=unused-function]
> 
> This replaces the preprocessor checks in the code with equivalent
> compiler conditionals, which lets gcc drop the unused functions
> without warning, and is nicer to read.
> 
> Fixes: e84067d74301 ("scsi: qla2xxx: Add FC-NVMe F/W initialization and 
> transport registration")
> Signed-off-by: Arnd Bergmann 
> ---
> drivers/scsi/qla2xxx/Kconfig|  1 +
> drivers/scsi/qla2xxx/qla_nvme.c | 20 
> 2 files changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/scsi/qla2xxx/Kconfig b/drivers/scsi/qla2xxx/Kconfig
> index de952935b5d2..036cc3f217b1 100644
> --- a/drivers/scsi/qla2xxx/Kconfig
> +++ b/drivers/scsi/qla2xxx/Kconfig
> @@ -2,6 +2,7 @@ config SCSI_QLA_FC
>   tristate "QLogic QLA2XXX Fibre Channel Support"
>   depends on PCI && SCSI
>   depends on SCSI_FC_ATTRS
> + depends on NVME_FC || !NVME_FC
>   select FW_LOADER
>   select BTREE
>   ---help---
> diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
> index 14e25e32e622..9c18d754ac33 100644
> --- a/drivers/scsi/qla2xxx/qla_nvme.c
> +++ b/drivers/scsi/qla2xxx/qla_nvme.c
> @@ -17,10 +17,12 @@ static void qla_nvme_unregister_remote_port(struct 
> work_struct *);
> 
> int qla_nvme_register_remote(scsi_qla_host_t *vha, fc_port_t *fcport)
> {
> -#if (IS_ENABLED(CONFIG_NVME_FC))
>   struct nvme_rport *rport;
>   int ret;
> 
> + if (!IS_ENABLED(CONFIG_NVME_FC))
> + return 0;
> +
>   if (fcport->nvme_flag & NVME_FLAG_REGISTERED)
>   return 0;
> 
> @@ -78,7 +80,6 @@ int qla_nvme_register_remote(scsi_qla_host_t *vha, 
> fc_port_t *fcport)
>   init_waitqueue_head(>nvme_waitQ);
>   rport->fcport = fcport;
>   list_add_tail(>list, >nvme_rport_list);
> -#endif
>   return 0;
> }
> 
> @@ -666,11 +667,13 @@ static void qla_nvme_abort_all(fc_port_t *fcport)
> 
> static void qla_nvme_unregister_remote_port(struct work_struct *work)
> {
> -#if (IS_ENABLED(CONFIG_NVME_FC))
>   struct fc_port *fcport = container_of(work, struct fc_port,
>   nvme_del_work);
>   struct nvme_rport *rport, *trport;
> 
> + if (!IS_ENABLED(CONFIG_NVME_FC))
> + return;
> +
>   list_for_each_entry_safe(rport, trport,
>   >vha->nvme_rport_list, list) {
>   if (rport->fcport == fcport) {
> @@ -680,16 +683,17 @@ static void qla_nvme_unregister_remote_port(struct 
> work_struct *work)
>   fcport->nvme_remote_port);
>   }
>   }
> -#endif
> }
> 
> void qla_nvme_delete(scsi_qla_host_t *vha)
> {
> -#if (IS_ENABLED(CONFIG_NVME_FC))
>   struct nvme_rport *rport, *trport;
>   fc_port_t *fcport;
>   int nv_ret;
> 
> + if (!IS_ENABLED(CONFIG_NVME_FC))
> + return;
> +
>   list_for_each_entry_safe(rport, trport, >nvme_rport_list, list) {
>   fcport = rport->fcport;
> 
> @@ -711,17 +715,18 @@ void qla_nvme_delete(scsi_qla_host_t *vha)
>   ql_log(ql_log_info, vha, 0x2115,
>   "Unregister of localport failed\n");
>   }
> -#endif
> }
> 
> void qla_nvme_register_hba(scsi_qla_host_t *vha)
> {
> -#if (IS_ENABLED(CONFIG_NVME_FC))
>   struct nvme_fc_port_template *tmpl;
>   struct qla_hw_data *ha;
>   struct nvme_fc_port_info pinfo;
>   int ret;
> 
> + if (!IS_ENABLED(CONFIG_NVME_FC))
> + return;
> +
>   ha = vha->hw;
>   tmpl = _nvme_fc_transport;
> 
> @@ -752,5 +757,4 @@ void qla_nvme_register_hba(scsi_qla_host_t *vha)
>   atomic_set(>nvme_ref_count, 1);
>   vha->nvme_local_port->private = vha;
>   init_waitqueue_head(>nvme_waitQ);
> -#endif
> }
> -- 
> 2.9.0
> 

Looks Good. 

Acked-By: Himanshu Madhani 

Thanks,
- Himanshu



[PATCH v6 4/6] g_NCR5380: Use unambiguous terminology for PDMA send and receive

2017-06-30 Thread Finn Thain
The word "read" may be used to mean "DMA read operation" or
"SCSI READ command", though a READ command implies writing to memory.

Signed-off-by: Finn Thain 
---
 drivers/scsi/g_NCR5380.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index dedaed2d16e4..33e1a480c903 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -48,8 +48,8 @@
int pdma_residual
 
 #define NCR5380_dma_xfer_lengeneric_NCR5380_dma_xfer_len
-#define NCR5380_dma_recv_setup  generic_NCR5380_pread
-#define NCR5380_dma_send_setup  generic_NCR5380_pwrite
+#define NCR5380_dma_recv_setup  generic_NCR5380_precv
+#define NCR5380_dma_send_setup  generic_NCR5380_psend
 #define NCR5380_dma_residualgeneric_NCR5380_dma_residual
 
 #define NCR5380_intrgeneric_NCR5380_intr
@@ -481,7 +481,7 @@ static void generic_NCR5380_release_resources(struct 
Scsi_Host *instance)
 }
 
 /**
- * generic_NCR5380_pread - pseudo DMA read
+ * generic_NCR5380_precv - pseudo DMA receive
  * @hostdata: scsi host private data
  * @dst: buffer to write into
  * @len: transfer size
@@ -489,7 +489,7 @@ static void generic_NCR5380_release_resources(struct 
Scsi_Host *instance)
  * Perform a pseudo DMA mode receive from a 53C400 or equivalent device.
  */
 
-static inline int generic_NCR5380_pread(struct NCR5380_hostdata *hostdata,
+static inline int generic_NCR5380_precv(struct NCR5380_hostdata *hostdata,
 unsigned char *dst, int len)
 {
int blocks = len / 128;
@@ -557,7 +557,7 @@ static inline int generic_NCR5380_pread(struct 
NCR5380_hostdata *hostdata,
 }
 
 /**
- * generic_NCR5380_pwrite - pseudo DMA write
+ * generic_NCR5380_psend - pseudo DMA send
  * @hostdata: scsi host private data
  * @src: buffer to read from
  * @len: transfer size
@@ -565,8 +565,8 @@ static inline int generic_NCR5380_pread(struct 
NCR5380_hostdata *hostdata,
  * Perform a pseudo DMA mode send to a 53C400 or equivalent device.
  */
 
-static inline int generic_NCR5380_pwrite(struct NCR5380_hostdata *hostdata,
- unsigned char *src, int len)
+static inline int generic_NCR5380_psend(struct NCR5380_hostdata *hostdata,
+unsigned char *src, int len)
 {
int blocks = len / 128;
int start = 0;
-- 
2.13.0



[PATCH v6 5/6] g_NCR5380: Re-work PDMA loops

2017-06-30 Thread Finn Thain
From: Ondrej Zary 

The polling loops in pread() and pwrite() can easily become infinite
loops and hang the machine.

Merge the IRQ check into host buffer wait loop and add polling limit.

Also place a limit on polling for 53C80 registers accessibility.

[Use NCR5380_poll_politely2() for register polling. Rely on polling for
gated IRQ rather than polling for phase error, like the algorithm in the
53c400 datasheet. Move DTC436 workarounds into a separate patch.
Factor-out common code as wait_for_53c80_access(). Rework the residual
correction. -- F.T.]

Signed-off-by: Ondrej Zary 
Signed-off-by: Finn Thain 
---
 drivers/scsi/g_NCR5380.c | 173 +--
 1 file changed, 92 insertions(+), 81 deletions(-)

diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 33e1a480c903..137ec58c43ac 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -480,6 +480,28 @@ static void generic_NCR5380_release_resources(struct 
Scsi_Host *instance)
release_mem_region(base, region_size);
 }
 
+/* wait_for_53c80_access - wait for 53C80 registers to become accessible
+ * @hostdata: scsi host private data
+ *
+ * The registers within the 53C80 logic block are inaccessible until
+ * bit 7 in the 53C400 control status register gets asserted.
+ */
+
+static void wait_for_53c80_access(struct NCR5380_hostdata *hostdata)
+{
+   int count = 1;
+
+   do {
+   if (NCR5380_read(hostdata->c400_ctl_status) & CSR_53C80_REG)
+   return;
+   } while (--count > 0);
+
+   scmd_printk(KERN_ERR, hostdata->connected,
+   "53c80 registers not accessible, device will be reset\n");
+   NCR5380_write(hostdata->c400_ctl_status, CSR_RESET);
+   NCR5380_write(hostdata->c400_ctl_status, CSR_BASE);
+}
+
 /**
  * generic_NCR5380_precv - pseudo DMA receive
  * @hostdata: scsi host private data
@@ -492,18 +514,23 @@ static void generic_NCR5380_release_resources(struct 
Scsi_Host *instance)
 static inline int generic_NCR5380_precv(struct NCR5380_hostdata *hostdata,
 unsigned char *dst, int len)
 {
-   int blocks = len / 128;
+   int residual;
int start = 0;
 
NCR5380_write(hostdata->c400_ctl_status, CSR_BASE | CSR_TRANS_DIR);
-   NCR5380_write(hostdata->c400_blk_cnt, blocks);
-   while (1) {
-   if (NCR5380_read(hostdata->c400_blk_cnt) == 0)
+   NCR5380_write(hostdata->c400_blk_cnt, len / 128);
+
+   do {
+   if (NCR5380_poll_politely2(hostdata, hostdata->c400_ctl_status,
+  CSR_HOST_BUF_NOT_RDY, 0,
+  hostdata->c400_ctl_status,
+  CSR_GATED_53C80_IRQ,
+  CSR_GATED_53C80_IRQ, HZ / 64) < 0)
+   break;
+
+   if (NCR5380_read(hostdata->c400_ctl_status) &
+   CSR_HOST_BUF_NOT_RDY)
break;
-   if (NCR5380_read(hostdata->c400_ctl_status) & 
CSR_GATED_53C80_IRQ)
-   goto out_wait;
-   while (NCR5380_read(hostdata->c400_ctl_status) & 
CSR_HOST_BUF_NOT_RDY)
-   ; /* FIXME - no timeout */
 
if (hostdata->io_port && hostdata->io_width == 2)
insw(hostdata->io_port + hostdata->c400_host_buf,
@@ -514,44 +541,26 @@ static inline int generic_NCR5380_precv(struct 
NCR5380_hostdata *hostdata,
else
memcpy_fromio(dst + start,
hostdata->io + NCR53C400_host_buffer, 128);
-
start += 128;
-   blocks--;
-   }
-
-   if (blocks) {
-   while (NCR5380_read(hostdata->c400_ctl_status) & 
CSR_HOST_BUF_NOT_RDY)
-   ; /* FIXME - no timeout */
+   } while (start < len);
 
-   if (hostdata->io_port && hostdata->io_width == 2)
-   insw(hostdata->io_port + hostdata->c400_host_buf,
-   dst + start, 64);
-   else if (hostdata->io_port)
-   insb(hostdata->io_port + hostdata->c400_host_buf,
-   dst + start, 128);
-   else
-   memcpy_fromio(dst + start,
-   hostdata->io + NCR53C400_host_buffer, 128);
+   residual = len - start;
 
-   start += 128;
-   blocks--;
+   if (residual != 0) {
+   /* 53c80 interrupt or transfer timeout. Reset 53c400 logic. */
+   NCR5380_write(hostdata->c400_ctl_status, CSR_RESET);
+   NCR5380_write(hostdata->c400_ctl_status, CSR_BASE);
}
+   

[PATCH v6 0/6] g_NCR5380: PDMA fixes and cleanup

2017-06-30 Thread Finn Thain
Ondrej, would you please test this new series?

Changed since v1:
- PDMA transfer residual is calculated earlier.
- End of DMA flag check is now polled (if there is any residual).

Changed since v2:
- Bail out of transfer loops when Gated IRQ gets asserted.
- Make udelay conditional on board type.
- Drop sg_tablesize patch due to performance regression.

Changed since v3:
- Add Ondrej's workaround for corrupt WRITE commands on DTC boards.
- Reset the 53c400 logic after any short PDMA transfer.
- Don't fail the transfer if the 53c400 logic got a reset.

Changed since v4:
- Bail out of transfer loops when Gated IRQ gets asserted. (Again.)
- Always call wait_for_53c80_registers() at end of transfer.
- Drain chip buffers after PDMA receive is interrupted.
- Rework residual calculation.
- Add new patch to correct DMA terminology.

Changed since v5:
- Rework residual calculation to account for on-chip buffer swap.
- Attempt to retain the disconnect/IRQ detection in the DTC436 workaround.
- Move all DTC436 workarounds to final patch.


Finn Thain (2):
  g_NCR5380: Cleanup comments and whitespace
  g_NCR5380: Use unambiguous terminology for PDMA send and receive

Ondrej Zary (4):
  g_NCR5380: Fix PDMA transfer size
  g_NCR5380: End PDMA transfer correctly on target disconnection
  g_NCR5380: Re-work PDMA loops
  g_NCR5380: Various DTC436 workarounds

 drivers/scsi/g_NCR5380.c | 273 ++-
 1 file changed, 151 insertions(+), 122 deletions(-)

-- 
2.13.0



[PATCH v6 6/6] g_NCR5380: Various DTC436 workarounds

2017-06-30 Thread Finn Thain
From: Ondrej Zary 

Limit PDMA send to 512 B to avoid data corruption on DTC3181E. The
corruption is always the same: one byte missing at the beginning of
a 128 B block. It happens only with slow Quantum LPS 240 drive, not with
faster IBM DORS-32160. It's not clear what causes this. Documentation
for the DTC436 chip has not been made available.

On DTC chips, Gated IRQ (for End of DMA) arrives early, and needs
special handling.

Signed-off-by: Finn Thain 
---
 drivers/scsi/g_NCR5380.c | 39 +++
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 137ec58c43ac..49312bf98068 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -45,7 +45,8 @@
int c400_blk_cnt; \
int c400_host_buf; \
int io_width; \
-   int pdma_residual
+   int pdma_residual; \
+   int board
 
 #define NCR5380_dma_xfer_lengeneric_NCR5380_dma_xfer_len
 #define NCR5380_dma_recv_setup  generic_NCR5380_precv
@@ -316,6 +317,7 @@ static int generic_NCR5380_init_one(struct 
scsi_host_template *tpnt,
}
hostdata = shost_priv(instance);
 
+   hostdata->board = board;
hostdata->io = iomem;
hostdata->region_size = region_size;
 
@@ -492,6 +494,8 @@ static void wait_for_53c80_access(struct NCR5380_hostdata 
*hostdata)
int count = 1;
 
do {
+   if (hostdata->board == BOARD_DTC3181E)
+   udelay(4); /* DTC436 chip hangs without this */
if (NCR5380_read(hostdata->c400_ctl_status) & CSR_53C80_REG)
return;
} while (--count > 0);
@@ -521,16 +525,22 @@ static inline int generic_NCR5380_precv(struct 
NCR5380_hostdata *hostdata,
NCR5380_write(hostdata->c400_blk_cnt, len / 128);
 
do {
-   if (NCR5380_poll_politely2(hostdata, hostdata->c400_ctl_status,
-  CSR_HOST_BUF_NOT_RDY, 0,
-  hostdata->c400_ctl_status,
-  CSR_GATED_53C80_IRQ,
-  CSR_GATED_53C80_IRQ, HZ / 64) < 0)
-   break;
-
-   if (NCR5380_read(hostdata->c400_ctl_status) &
-   CSR_HOST_BUF_NOT_RDY)
-   break;
+   if (hostdata->board == BOARD_DTC3181E && start == len - 128) {
+   /* Ignore early CSR_GATED_53C80_IRQ */
+   if (NCR5380_poll_politely(hostdata, 
hostdata->c400_ctl_status,
+ CSR_HOST_BUF_NOT_RDY, 0, HZ / 
64) < 0)
+   break;
+   } else {
+   if (NCR5380_poll_politely2(hostdata, 
hostdata->c400_ctl_status,
+  CSR_HOST_BUF_NOT_RDY, 0,
+  hostdata->c400_ctl_status,
+  CSR_GATED_53C80_IRQ,
+  CSR_GATED_53C80_IRQ, HZ / 
64) < 0)
+   break;
+   if (NCR5380_read(hostdata->c400_ctl_status) &
+   CSR_HOST_BUF_NOT_RDY)
+   break;
+   }
 
if (hostdata->io_port && hostdata->io_width == 2)
insw(hostdata->io_port + hostdata->c400_host_buf,
@@ -655,7 +665,12 @@ static int generic_NCR5380_dma_xfer_len(struct 
NCR5380_hostdata *hostdata,
 
/* 53C400 datasheet: non-modulo-128-byte transfers should use PIO */
if (transfersize % 128)
-   transfersize = 0;
+   return 0;
+
+   /* Limit PDMA send to 512 B to avoid random corruption on DTC3181E */
+   if (hostdata->board == BOARD_DTC3181E &&
+   cmd->sc_data_direction == DMA_TO_DEVICE)
+   transfersize = min(cmd->SCp.this_residual, 512);
 
return min(transfersize, DMA_MAX_SIZE);
 }
-- 
2.13.0



[PATCH v6 2/6] g_NCR5380: End PDMA transfer correctly on target disconnection

2017-06-30 Thread Finn Thain
From: Ondrej Zary 

When an IRQ arrives during PDMA transfer, pread() and pwrite() return
without waiting for the 53C80 registers to be ready and this ends up
messing up the chip state. This was observed with SONY CDU-55S which is
slow enough to disconnect during 4096-byte reads.

IRQ during PDMA is not an error so don't return -1. Instead, store the
remaining byte count for use by NCR5380_dma_residual().

[Poll for the BASR_END_DMA_TRANSFER condition rather than remove the
error message -- F.T.]

Signed-off-by: Ondrej Zary 
Signed-off-by: Finn Thain 
---
 drivers/scsi/g_NCR5380.c | 48 +++-
 1 file changed, 31 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 14ef4e8c4713..911a4300ea51 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -44,12 +44,13 @@
int c400_ctl_status; \
int c400_blk_cnt; \
int c400_host_buf; \
-   int io_width
+   int io_width; \
+   int pdma_residual
 
 #define NCR5380_dma_xfer_lengeneric_NCR5380_dma_xfer_len
 #define NCR5380_dma_recv_setup  generic_NCR5380_pread
 #define NCR5380_dma_send_setup  generic_NCR5380_pwrite
-#define NCR5380_dma_residualNCR5380_dma_residual_none
+#define NCR5380_dma_residualgeneric_NCR5380_dma_residual
 
 #define NCR5380_intrgeneric_NCR5380_intr
 #define NCR5380_queue_command   generic_NCR5380_queue_command
@@ -500,10 +501,8 @@ static inline int generic_NCR5380_pread(struct 
NCR5380_hostdata *hostdata,
while (1) {
if (NCR5380_read(hostdata->c400_blk_cnt) == 0)
break;
-   if (NCR5380_read(hostdata->c400_ctl_status) & 
CSR_GATED_53C80_IRQ) {
-   printk(KERN_ERR "53C400r: Got 53C80_IRQ start=%d, 
blocks=%d\n", start, blocks);
-   return -1;
-   }
+   if (NCR5380_read(hostdata->c400_ctl_status) & 
CSR_GATED_53C80_IRQ)
+   goto out_wait;
while (NCR5380_read(hostdata->c400_ctl_status) & 
CSR_HOST_BUF_NOT_RDY)
; /* FIXME - no timeout */
 
@@ -542,13 +541,19 @@ static inline int generic_NCR5380_pread(struct 
NCR5380_hostdata *hostdata,
if (!(NCR5380_read(hostdata->c400_ctl_status) & CSR_GATED_53C80_IRQ))
printk("53C400r: no 53C80 gated irq after transfer");
 
+out_wait:
+   hostdata->pdma_residual = len - start;
+
/* wait for 53C80 registers to be available */
while (!(NCR5380_read(hostdata->c400_ctl_status) & CSR_53C80_REG))
;
 
-   if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_END_DMA_TRANSFER))
-   printk(KERN_ERR "53C400r: no end dma signal\n");
-   
+   if (NCR5380_poll_politely(hostdata, BUS_AND_STATUS_REG,
+ BASR_END_DMA_TRANSFER, BASR_END_DMA_TRANSFER,
+ HZ / 64) < 0)
+   scmd_printk(KERN_ERR, hostdata->connected, "%s: End of DMA 
timeout (%d)\n",
+   __func__, hostdata->pdma_residual);
+
return 0;
 }
 
@@ -571,10 +576,8 @@ static inline int generic_NCR5380_pwrite(struct 
NCR5380_hostdata *hostdata,
NCR5380_write(hostdata->c400_ctl_status, CSR_BASE);
NCR5380_write(hostdata->c400_blk_cnt, blocks);
while (1) {
-   if (NCR5380_read(hostdata->c400_ctl_status) & 
CSR_GATED_53C80_IRQ) {
-   printk(KERN_ERR "53C400w: Got 53C80_IRQ start=%d, 
blocks=%d\n", start, blocks);
-   return -1;
-   }
+   if (NCR5380_read(hostdata->c400_ctl_status) & 
CSR_GATED_53C80_IRQ)
+   goto out_wait;
 
if (NCR5380_read(hostdata->c400_blk_cnt) == 0)
break;
@@ -612,18 +615,24 @@ static inline int generic_NCR5380_pwrite(struct 
NCR5380_hostdata *hostdata,
blocks--;
}
 
+out_wait:
+   hostdata->pdma_residual = len - start;
+
/* wait for 53C80 registers to be available */
while (!(NCR5380_read(hostdata->c400_ctl_status) & CSR_53C80_REG)) {
udelay(4); /* DTC436 chip hangs without this */
/* FIXME - no timeout */
}
 
-   if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_END_DMA_TRANSFER)) {
-   printk(KERN_ERR "53C400w: no end dma signal\n");
-   }
-
while (!(NCR5380_read(TARGET_COMMAND_REG) & TCR_LAST_BYTE_SENT))
;   // TIMEOUT
+
+   if (NCR5380_poll_politely(hostdata, BUS_AND_STATUS_REG,
+ BASR_END_DMA_TRANSFER, BASR_END_DMA_TRANSFER,
+ HZ / 64) < 0)
+   scmd_printk(KERN_ERR, hostdata->connected, "%s: End of DMA 
timeout (%d)\n",
+

[PATCH v6 3/6] g_NCR5380: Cleanup comments and whitespace

2017-06-30 Thread Finn Thain
Signed-off-by: Finn Thain 
---
 drivers/scsi/g_NCR5380.c | 61 ++--
 1 file changed, 28 insertions(+), 33 deletions(-)

diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 911a4300ea51..dedaed2d16e4 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -1,17 +1,17 @@
 /*
  * Generic Generic NCR5380 driver
- * 
+ *
  * Copyright 1993, Drew Eckhardt
- * Visionary Computing
- * (Unix and Linux consulting and custom programming)
- * d...@colorado.edu
- *  +1 (303) 440-4894
+ * Visionary Computing
+ * (Unix and Linux consulting and custom programming)
+ * d...@colorado.edu
+ * +1 (303) 440-4894
  *
  * NCR53C400 extensions (c) 1994,1995,1996, Kevin Lentin
- *k.len...@cs.monash.edu.au
+ * k.len...@cs.monash.edu.au
  *
  * NCR53C400A extensions (c) 1996, Ingmar Baumgart
- *ing...@gonzo.schwaben.de
+ * ing...@gonzo.schwaben.de
  *
  * DTC3181E extensions (c) 1997, Ronald van Cuijlenborg
  * ronald.van.cuijlenb...@tip.nl or nu...@dds.nl
@@ -481,15 +481,14 @@ static void generic_NCR5380_release_resources(struct 
Scsi_Host *instance)
 }
 
 /**
- * generic_NCR5380_pread - pseudo DMA read
- * @hostdata: scsi host private data
- * @dst: buffer to read into
- * @len: buffer length
+ * generic_NCR5380_pread - pseudo DMA read
+ * @hostdata: scsi host private data
+ * @dst: buffer to write into
+ * @len: transfer size
  *
- * Perform a pseudo DMA mode read from an NCR53C400 or equivalent
- * controller
+ * Perform a pseudo DMA mode receive from a 53C400 or equivalent device.
  */
- 
+
 static inline int generic_NCR5380_pread(struct NCR5380_hostdata *hostdata,
 unsigned char *dst, int len)
 {
@@ -508,10 +507,10 @@ static inline int generic_NCR5380_pread(struct 
NCR5380_hostdata *hostdata,
 
if (hostdata->io_port && hostdata->io_width == 2)
insw(hostdata->io_port + hostdata->c400_host_buf,
-   dst + start, 64);
+dst + start, 64);
else if (hostdata->io_port)
insb(hostdata->io_port + hostdata->c400_host_buf,
-   dst + start, 128);
+dst + start, 128);
else
memcpy_fromio(dst + start,
hostdata->io + NCR53C400_host_buffer, 128);
@@ -558,13 +557,12 @@ static inline int generic_NCR5380_pread(struct 
NCR5380_hostdata *hostdata,
 }
 
 /**
- * generic_NCR5380_pwrite - pseudo DMA write
- * @hostdata: scsi host private data
- * @dst: buffer to read into
- * @len: buffer length
+ * generic_NCR5380_pwrite - pseudo DMA write
+ * @hostdata: scsi host private data
+ * @src: buffer to read from
+ * @len: transfer size
  *
- * Perform a pseudo DMA mode read from an NCR53C400 or equivalent
- * controller
+ * Perform a pseudo DMA mode send to a 53C400 or equivalent device.
  */
 
 static inline int generic_NCR5380_pwrite(struct NCR5380_hostdata *hostdata,
@@ -603,10 +601,10 @@ static inline int generic_NCR5380_pwrite(struct 
NCR5380_hostdata *hostdata,
 
if (hostdata->io_port && hostdata->io_width == 2)
outsw(hostdata->io_port + hostdata->c400_host_buf,
-   src + start, 64);
+ src + start, 64);
else if (hostdata->io_port)
outsb(hostdata->io_port + hostdata->c400_host_buf,
-   src + start, 128);
+ src + start, 128);
else
memcpy_toio(hostdata->io + NCR53C400_host_buffer,
src + start, 128);
@@ -656,10 +654,8 @@ static int generic_NCR5380_dma_residual(struct 
NCR5380_hostdata *hostdata)
return hostdata->pdma_residual;
 }
 
-/*
- * Include the NCR5380 core code that we build our driver around   
- */
- 
+/* Include the core driver code. */
+
 #include "NCR5380.c"
 
 static struct scsi_host_template driver_template = {
@@ -679,11 +675,10 @@ static struct scsi_host_template driver_template = {
.max_sectors= 128,
 };
 
-
 static int generic_NCR5380_isa_match(struct device *pdev, unsigned int ndev)
 {
int ret = generic_NCR5380_init_one(_template, pdev, base[ndev],
- irq[ndev], card[ndev]);
+  irq[ndev], card[ndev]);
if (ret) {
if (base[ndev])
printk(KERN_WARNING "Card not found at address 
0x%03x\n",
@@ -695,7 +690,7 @@ static int generic_NCR5380_isa_match(struct device *pdev, 
unsigned int ndev)
 }
 
 static int generic_NCR5380_isa_remove(struct device 

[PATCH v6 1/6] g_NCR5380: Fix PDMA transfer size

2017-06-30 Thread Finn Thain
From: Ondrej Zary 

generic_NCR5380_dma_xfer_len() incorrectly uses cmd->transfersize
which causes rescan-scsi-bus and CD-ROM access to hang the system.
Use cmd->SCp.this_residual instead, like other NCR5380 drivers.

Signed-off-by: Ondrej Zary 
Signed-off-by: Finn Thain 
---
 drivers/scsi/g_NCR5380.c | 12 +++-
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 67c8dac321ad..14ef4e8c4713 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -76,6 +76,7 @@
 #define IRQ_AUTO 254
 
 #define MAX_CARDS 8
+#define DMA_MAX_SIZE 32768
 
 /* old-style parameters for compatibility */
 static int ncr_irq = -1;
@@ -629,23 +630,16 @@ static inline int generic_NCR5380_pwrite(struct 
NCR5380_hostdata *hostdata,
 static int generic_NCR5380_dma_xfer_len(struct NCR5380_hostdata *hostdata,
 struct scsi_cmnd *cmd)
 {
-   int transfersize = cmd->transfersize;
+   int transfersize = cmd->SCp.this_residual;
 
if (hostdata->flags & FLAG_NO_PSEUDO_DMA)
return 0;
 
-   /* Limit transfers to 32K, for xx400 & xx406
-* pseudoDMA that transfers in 128 bytes blocks.
-*/
-   if (transfersize > 32 * 1024 && cmd->SCp.this_residual &&
-   !(cmd->SCp.this_residual % transfersize))
-   transfersize = 32 * 1024;
-
/* 53C400 datasheet: non-modulo-128-byte transfers should use PIO */
if (transfersize % 128)
transfersize = 0;
 
-   return transfersize;
+   return min(transfersize, DMA_MAX_SIZE);
 }
 
 /*
-- 
2.13.0



[PATCH] qla2xxx: Fix compile warning

2017-06-30 Thread Himanshu Madhani
drivers/scsi/qla2xxx/qla_nvme.c: In function 'qla2x00_start_nvme_mq':
include/uapi/linux/byteorder/big_endian.h:32:26: warning: large integer
implicitly truncated to unsigned type [-Woverflow]
 #define __cpu_to_le32(x) ((__force __le32)__swab32((x)))

Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_nvme.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
index 1da8fa8f641d..367cf8613b15 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -441,7 +441,8 @@ static int qla2x00_start_nvme_mq(srb_t *sp)
req->ring_ptr++;
}
cont_pkt = (cont_a64_entry_t *)req->ring_ptr;
-   cont_pkt->entry_type = cpu_to_le32(CONTINUE_A64_TYPE);
+   *((uint32_t *)(_pkt->entry_type)) =
+   cpu_to_le32(CONTINUE_A64_TYPE);
 
cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
avail_dsds = 5;
-- 
2.11.0



Re: [PATCH] tcmu: Fix flushing cmd entry dcache page

2017-06-30 Thread Mike Christie
On 06/30/2017 03:14 AM, lixi...@cmss.chinamobile.com wrote:
> From: Xiubo Li 
> 
> When feeding the tcmu's cmd ring, we need to flush the dcache page
> for the cmd entry to make sure these kernel stores are visible to
> user space mappings of that page.
> 
> For the none PAD cmd entry, this will be flushed at the end of the
> tcmu_queue_cmd_ring().
> 
> Signed-off-by: Xiubo Li 
> ---
>  drivers/target/target_core_user.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/target/target_core_user.c 
> b/drivers/target/target_core_user.c
> index 203bff1..930800c 100644
> --- a/drivers/target/target_core_user.c
> +++ b/drivers/target/target_core_user.c
> @@ -699,21 +699,21 @@ static inline size_t tcmu_cmd_get_cmd_size(struct 
> tcmu_cmd *tcmu_cmd,
>   size_t pad_size = head_to_end(cmd_head, udev->cmdr_size);
>  
>   entry = (void *) mb + CMDR_OFF + cmd_head;
> - tcmu_flush_dcache_range(entry, sizeof(*entry));


I think this patch looks ok. What was the reason for removing this and
the one at the bottom of the patch? Is it not needed because we are not
reading anything from the entry that could have been touched by userspace?

>   tcmu_hdr_set_op(>hdr.len_op, TCMU_OP_PAD);
>   tcmu_hdr_set_len(>hdr.len_op, pad_size);
>   entry->hdr.cmd_id = 0; /* not used for PAD */
>   entry->hdr.kflags = 0;
>   entry->hdr.uflags = 0;
> + tcmu_flush_dcache_range(entry, sizeof(*entry));
>  
>   UPDATE_HEAD(mb->cmd_head, pad_size, udev->cmdr_size);
> + tcmu_flush_dcache_range(mb, sizeof(*mb));
>  
>   cmd_head = mb->cmd_head % udev->cmdr_size; /* UAM */
>   WARN_ON(cmd_head != 0);
>   }
>  
>   entry = (void *) mb + CMDR_OFF + cmd_head;
> - tcmu_flush_dcache_range(entry, sizeof(*entry));
>   tcmu_hdr_set_op(>hdr.len_op, TCMU_OP_CMD);
>   entry->hdr.cmd_id = tcmu_cmd->cmd_id;
>   entry->hdr.kflags = 0;
> 



Re: [PATCH][scsi-next] scsi: qla2xxx: fix a bunch of typos and spelling mistakes

2017-06-30 Thread Madhani, Himanshu

> On Jun 30, 2017, at 6:47 AM, Colin King  wrote:
> 
> From: Colin Ian King 
> 
> Fix the following typos/spelling mistakes:
> 
> "attribure" -> "attribute"
> "suppored" -> "supported"
> "Symobilic" -> "Symbolic"
> "iteself" -> "itself"
> "reqeust" -> "request"
> "nvme_wait_on_comand" -> "nvme_wait_on_command"
> "bount" -> "bound"
> "captrue_mask" -> "capture_mask"
> "tempelate" -> "template"
> 
> ..and also unwrap a line to fix a checkpatch warning.
> 
> Signed-off-by: Colin Ian King 
> ---
> drivers/scsi/qla2xxx/qla_attr.c | 2 +-
> drivers/scsi/qla2xxx/qla_bsg.c  | 2 +-
> drivers/scsi/qla2xxx/qla_init.c | 2 +-
> drivers/scsi/qla2xxx/qla_isr.c  | 3 +--
> drivers/scsi/qla2xxx/qla_mbx.c  | 2 +-
> drivers/scsi/qla2xxx/qla_nvme.c | 4 ++--
> drivers/scsi/qla2xxx/qla_nx.c   | 4 ++--
> drivers/scsi/qla2xxx/qla_nx2.c  | 2 +-
> 8 files changed, 10 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
> index 6dd984203666..08a1feb3a195 100644
> --- a/drivers/scsi/qla2xxx/qla_attr.c
> +++ b/drivers/scsi/qla2xxx/qla_attr.c
> @@ -929,7 +929,7 @@ qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
>   iter->name, ret);
>   else
>   ql_dbg(ql_dbg_init, vha, 0x00f4,
> - "Successfully created sysfs %s binary attribure.\n",
> + "Successfully created sysfs %s binary attribute.\n",
>   iter->name);
>   }
> }
> diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
> index e093795a0371..2ea0ef93f5cb 100644
> --- a/drivers/scsi/qla2xxx/qla_bsg.c
> +++ b/drivers/scsi/qla2xxx/qla_bsg.c
> @@ -293,7 +293,7 @@ qla2x00_process_els(struct bsg_job *bsg_job)
>   if (bsg_job->request_payload.sg_cnt > 1 ||
>   bsg_job->reply_payload.sg_cnt > 1) {
>   ql_dbg(ql_dbg_user, vha, 0x7002,
> - "Multiple SG's are not suppored for ELS requests, "
> + "Multiple SG's are not supported for ELS requests, "
>   "request_sg_cnt=%x reply_sg_cnt=%x.\n",
>   bsg_job->request_payload.sg_cnt,
>   bsg_job->reply_payload.sg_cnt);
> diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
> index 8a5f5ef069ae..072ad1aa5505 100644
> --- a/drivers/scsi/qla2xxx/qla_init.c
> +++ b/drivers/scsi/qla2xxx/qla_init.c
> @@ -4660,7 +4660,7 @@ qla2x00_configure_fabric(scsi_qla_host_t *vha)
>   } else if (qla2x00_rsnn_nn(vha)) {
>   /* EMPTY */
>   ql_dbg(ql_dbg_disc, vha, 0x209b,
> - "Register Symobilic Node Name failed.\n");
> + "Register Symbolic Node Name failed.\n");
>   if (test_bit(LOOP_RESYNC_NEEDED, 
> >dpc_flags))
>   break;
>   }
> diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
> index 011faa1dc618..6c6e624a5aa6 100644
> --- a/drivers/scsi/qla2xxx/qla_isr.c
> +++ b/drivers/scsi/qla2xxx/qla_isr.c
> @@ -432,8 +432,7 @@ qla83xx_handle_8200_aen(scsi_qla_host_t *vha, uint16_t 
> *mb)
>   "Register: 0x%x%x.\n", mb[7], mb[3]);
>   if (err_level == ERR_LEVEL_NON_FATAL) {
>   ql_log(ql_log_warn, vha, 0x5063,
> - "Not a fatal error, f/w has recovered "
> - "iteself.\n");
> + "Not a fatal error, f/w has recovered 
> itself.\n");
>   } else if (err_level == ERR_LEVEL_RECOVERABLE_FATAL) {
>   ql_log(ql_log_fatal, vha, 0x5064,
>   "Recoverable Fatal error: Chip reset "
> diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
> index 0764b6172ed1..7c6d1a404011 100644
> --- a/drivers/scsi/qla2xxx/qla_mbx.c
> +++ b/drivers/scsi/qla2xxx/qla_mbx.c
> @@ -3893,7 +3893,7 @@ qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
>   rval = QLA_FUNCTION_FAILED;
>   } else if (vce->comp_status != cpu_to_le16(CS_COMPLETE)) {
>   ql_dbg(ql_dbg_mbx, vha, 0x10c5,
> - "Failed to complet IOCB -- completion status (%x).\n",
> + "Failed to complete IOCB -- completion status (%x).\n",
>   le16_to_cpu(vce->comp_status));
>   rval = QLA_FUNCTION_FAILED;
>   } else {
> diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
> index 1da8fa8f641d..53e58e9daba8 100644
> --- a/drivers/scsi/qla2xxx/qla_nvme.c
> +++ b/drivers/scsi/qla2xxx/qla_nvme.c
> @@ -489,7 +489,7 @@ static int qla_nvme_post_cmd(struct nvme_fc_local_port 
> *lport,
>   struct nvme_private *priv;

[PATCH v2] qla2xxx: Fix NVMe entry_type for iocb packet on BE system

2017-06-30 Thread Himanshu Madhani
This patch fixes incorrect assignment for entry_type field for Continuation
Type iocb packet on BE system. This was caught by -Woverflow warning on BE
system compilation.

For Continuation Type iocb driver needs to write complete 32 bit value to
initialize other field members in stucture to 0.

Following warning is seen on BE system compile: 

drivers/scsi/qla2xxx/qla_nvme.c: In function 'qla2x00_start_nvme_mq':
include/uapi/linux/byteorder/big_endian.h:32:26: warning: large integer
implicitly truncated to unsigned type [-Woverflow]
 #define __cpu_to_le32(x) ((__force __le32)__swab32((x)))

Signed-off-by: Himanshu Madhani 

---
Changes from v1 --> v2

o Modified commit message and description to clarify issue 
  in qla2xxx NVMe initiator code on BE system.

---
 drivers/scsi/qla2xxx/qla_nvme.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
index 1da8fa8f641d..367cf8613b15 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -441,7 +441,8 @@ static int qla2x00_start_nvme_mq(srb_t *sp)
req->ring_ptr++;
}
cont_pkt = (cont_a64_entry_t *)req->ring_ptr;
-   cont_pkt->entry_type = cpu_to_le32(CONTINUE_A64_TYPE);
+   *((uint32_t *)(_pkt->entry_type)) =
+   cpu_to_le32(CONTINUE_A64_TYPE);
 
cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
avail_dsds = 5;
-- 
2.11.0



Re: [PATCH v5 0/6] g_NCR5380: PDMA fixes and cleanup

2017-06-30 Thread Finn Thain
On Fri, 30 Jun 2017, Ondrej Zary wrote:

> > > No more log spamming on DTC but reads are corrupted even more than 
> > > before. The IRQ check after data transfer increases the chance of 
> > > catching an IRQ before the buffer could become ready.
> >
> > If we delay the IRQ check, that just means that CSR_GATED_53C80_IRQ 
> > will be detected a bit later (128 bytes later)... so not much 
> > difference.
> 
> The main difference is that my original patch read the CSR once and 
> then:
> - transfer data if the buffer is ready, ignoring any IRQ
> - if the buffer is not ready, check for an IRQ
> - if neither buffer is ready nor IRQ was asserted, check for timeout
> 

I think your pseudocode is equivalent to this code* from the patch,

if (NCR5380_poll_politely2(hostdata, hostdata->c400_ctl_status,
   CSR_HOST_BUF_NOT_RDY, 0,
   hostdata->c400_ctl_status,
   CSR_GATED_53C80_IRQ,
   CSR_GATED_53C80_IRQ, HZ / 64) < 0)
break;

if (NCR5380_read(hostdata->c400_ctl_status) &
CSR_HOST_BUF_NOT_RDY)
break;

/* transfer data */

If this doesn't work on DTC devices, I think we have to special case them 
somehow.

> So yes, the IRQ will be detected 128 bytes later - but the IRQ is 
> asserted at 3968 bytes which means the transfer will then be complete.
> 

Yes, unless the IRQ was asserted 128 bytes into the transfer...

> > > This patch:
> > > --- a/drivers/scsi/g_NCR5380.c
> > > +++ b/drivers/scsi/g_NCR5380.c
> > > @@ -548,8 +548,10 @@ static inline int generic_NCR5380_precv(struct
> > >   start += 128;
> > >
> > >   if (NCR5380_read(hostdata->c400_ctl_status) &
> > > - CSR_GATED_53C80_IRQ)
> > > + CSR_GATED_53C80_IRQ) {
> > > + printk("r irq at start=%d basr=0x%02x\n", start,
> > > NCR5380_read(BUS_AND_STATUS_REG)); break;
> > > + }
> > >   }
> > >
> > >   residual = len - start;
> > >
> > > produces lots of these lines:
> > > [  896.194054] r irq at start=128 basr=0x98
> > > [  896.197758] r irq at start=3968 basr=0x98
> >
> > Assuming that the registers are available and valid, the value 0x98 
> > means BASR_END_DMA_TRANSFER | BASR_IRQ | BASR_PHASE_MATCH. There is no 
> > BASR_BUSY_ERROR here, so the cause of the CSR_GATED_53C80_IRQ must be 
> > that the 53c400 has terminated the transfer by asserting /EOP. That 
> > shouldn't happen before before the counters run down.
> >
> > It doesn't make sense. So maybe the 53c80 registers are not valid at 
> > this point? That means a phase mismatch can't be excluded... unlikely 
> > at 128 bytes into the transfer. Busy error? Also unlikely.
> >
> > I have to conclude that CSR_GATED_53C80_IRQ and BASR_END_DMA_TRANSFER 
> > can't be trusted on this board. I guess that's why you examine the 
> > BASR directly in your original algorithm but ignore 
> > BASR_END_DMA_TRANSFER.
> 
> Exactly, BASR_END_DMA_TRANSFER causes problems on DTC.
> 
> > It does look like some kind of timing issue: the "start" value above 
> > changes from one log message to the next. Who knows?
> 
> Only that two values (128 and 3968) appeared. 3968 = 4096-128, one block 
> before the end of transfer. So probably BASR_END_DMA_TRANSFER is 
> asserted one block earlier (i.e. when the last block of data is 
> transferred from the drive to the chip buffer). Haven't seen this 
> problem at start=128 before.
> 

Well, if we ignore the 128 B short transfer as an aberrant outlier, and if 
we assume that BASR_END_DMA_TRANSFER can be made to work correctly, then 
perhaps we can tweak the timing so that a 4096 byte transfer is not cut 
short.

Alternatively, perhaps we could workaround the BASR_END_DMA_TRANSFER 
issue with a special case that ignores Gated IRQ when
hostdata->board == BOARD_DTC3181E && start == len - 128

> > > This fixes the DTC read corruption, although I don't like the repeated
> > > ctl_status register reads:
> > > --- a/drivers/scsi/g_NCR5380.c
> > > +++ b/drivers/scsi/g_NCR5380.c
> > > @@ -533,7 +533,7 @@ static inline int generic_NCR5380_precv(struct
> > >   break;
> > >
> > >   if (NCR5380_read(hostdata->c400_ctl_status) &
> > > - CSR_HOST_BUF_NOT_RDY)
> > > + CSR_GATED_53C80_IRQ && 
> > > (NCR5380_read(hostdata->c400_ctl_status) &
> > > CSR_HOST_BUF_NOT_RDY)) break;
> > >
> > >   if (hostdata->io_port && hostdata->io_width == 2)
> >
> > But that means the transfer will continue even when 
> > CSR_HOST_BUF_NOT_RDY. Your original algorithm doesn't attempt that. 
> > Neither does the algorithm in the datasheet. We should try to omit 
> > this change.
> 
> Sorry for that, it's a bug. I got lost in the conditions.
> 
> > > @@ -546,10 +546,6 @@ static inline int generic_NCR5380_precv(struct
> > >   memcpy_fromio(dst + start,
> > >   hostdata->io + 

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

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 10:29 AM, Shivasharan S wrote:
> Signed-off-by: Kashyap Desai 
> Signed-off-by: Shivasharan S 
> ---
>  drivers/scsi/megaraid/megaraid_sas_fusion.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
> b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> index 5018a3f..0f13c58 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> @@ -3552,6 +3552,7 @@ int megasas_wait_for_outstanding_fusion(struct 
> megasas_instance *instance,
>   }
>   }
>  
> + megasas_complete_cmd_dpc_fusion((unsigned long)instance);
>   outstanding = atomic_read(>fw_outstanding);
>   if (!outstanding)
>   goto out;
> @@ -3560,8 +3561,6 @@ int megasas_wait_for_outstanding_fusion(struct 
> megasas_instance *instance,
>   dev_notice(>pdev->dev, "[%2d]waiting for %d "
>  "commands to complete for scsi%d\n", i,
>  outstanding, instance->host->host_no);
> - megasas_complete_cmd_dpc_fusion(
> - (unsigned long)instance);
>   }
>   msleep(1000);
>   }
> 
Please add a changelog why this is necessary.

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


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

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 10:29 AM, Shivasharan S wrote:
> Signed-off-by: Kashyap Desai 
> Signed-off-by: Shivasharan S 
> ---
>  drivers/scsi/megaraid/megaraid_sas_fusion.c | 9 +
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
> b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> index 0f13c58..a308e14 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> @@ -3618,6 +3618,15 @@ void megasas_refire_mgmt_cmd(struct megasas_instance 
> *instance)
>  
>   if (!smid)
>   continue;
> +
> + /* Do not refire shutdown command */
> + if (le32_to_cpu(cmd_mfi->frame->dcmd.opcode) ==
> + MR_DCMD_CTRL_SHUTDOWN) {
> + cmd_mfi->frame->dcmd.cmd_status = MFI_STAT_OK;
> + megasas_complete_cmd(instance, cmd_mfi, DID_OK);
> + continue;
> + }
> +
>   req_desc = megasas_get_request_descriptor
>   (instance, smid - 1);
>   refire_cmd = req_desc && ((cmd_mfi->frame->dcmd.opcode !=
> 
Please, no.
You already have a selector further down whether to refire the command,
pending on the DRV_DCMD_SKIP_REFIRE flag.
If you always set this flag for the shutdown command you wouldn't need
to touch this at all.
And if you particularly dislike that solution convert the 'refire_cmd ='
statement into a proper switch and blank it out from there.

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


Re: [PATCH 08/15] megaraid_sas: Use SMID for Task abort case only

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 10:30 AM, Shivasharan S wrote:
> Fix - In TM code, smid_task is valid only in case of task aborts.
> 
> Signed-off-by: Kashyap Desai 
> Signed-off-by: Shivasharan S 
> ---
>  drivers/scsi/megaraid/megaraid_sas_fusion.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
> b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> index a308e14..c239762 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> @@ -3754,7 +3754,7 @@ megasas_issue_tm(struct megasas_instance *instance, u16 
> device_handle,
>   struct megasas_cmd_fusion *cmd_fusion;
>   struct megasas_cmd *cmd_mfi;
>   union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
> - struct fusion_context *fusion;
> + struct fusion_context *fusion = NULL;
>   struct megasas_cmd_fusion *scsi_lookup;
>   int rc;
>   struct MPI2_SCSI_TASK_MANAGE_REPLY *mpi_reply;
> @@ -3781,8 +3781,6 @@ megasas_issue_tm(struct megasas_instance *instance, u16 
> device_handle,
>   cmd_fusion->request_desc = req_desc;
>   req_desc->Words = 0;
>  
> - scsi_lookup = fusion->cmd_list[smid_task - 1];
> -
>   mr_request = (struct MR_TASK_MANAGE_REQUEST *) cmd_fusion->io_request;
>   memset(mr_request, 0, sizeof(struct MR_TASK_MANAGE_REQUEST));
>   mpi_request = (struct MPI2_SCSI_TASK_MANAGE_REQUEST *) 
> _request->TmRequest;
> @@ -3829,6 +3827,8 @@ megasas_issue_tm(struct megasas_instance *instance, u16 
> device_handle,
>   rc = SUCCESS;
>   switch (type) {
>   case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
> + scsi_lookup = fusion->cmd_list[smid_task - 1];
> +
>   if (scsi_lookup->scmd == NULL)
>   break;
>   else {
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


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

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 10:30 AM, Shivasharan S wrote:
> An application sending out of range AEN class code for 
> registration, will result in kernel panic in MR driver.
> 
> Signed-off-by: Kashyap Desai 
> Signed-off-by: Shivasharan S 
> Cc: sta...@vger.kernel.org
> ---
>  drivers/scsi/megaraid/megaraid_sas_base.c | 8 
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
> b/drivers/scsi/megaraid/megaraid_sas_base.c
> index 3c50a7b..e490272 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_base.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
> @@ -5650,6 +5650,14 @@ megasas_register_aen(struct megasas_instance 
> *instance, u32 seq_num,
>   prev_aen.word =
>   le32_to_cpu(instance->aen_cmd->frame->dcmd.mbox.w[1]);
>  
> + if ((curr_aen.members.class < MFI_EVT_CLASS_DEBUG) ||
> + (curr_aen.members.class > MFI_EVT_CLASS_DEAD)) {
> + dev_info(>pdev->dev,
> +  "%s %d out of range class %d send by 
> application\n",
> +  __func__, __LINE__, curr_aen.members.class);
> + return 0;
> + }
> +
>   /*
>* A class whose enum value is smaller is inclusive of all
>* higher values. If a PROGRESS (= -1) was previously
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


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

2017-06-30 Thread Hannes Reinecke
On 06/30/2017 10:30 AM, Shivasharan S wrote:
> Fix - After a kill adapter, since the cmd_status is not set the
> IOCTLs will be hung in driver resulting in application hang.
> Set cmd_status MFI_STAT_WRONG_STATE when completing pended IOCTLs.
> 
> Signed-off-by: Kashyap Desai 
> Signed-off-by: Shivasharan S 
> Cc: sta...@vger.kernel.org
> ---
>  drivers/scsi/megaraid/megaraid_sas_base.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


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

2017-06-30 Thread Tomas Henzl
On 30.6.2017 10:30, Shivasharan S wrote:
> Signed-off-by: Kashyap Desai 
> Signed-off-by: Shivasharan S 
> ---
>  drivers/scsi/megaraid/megaraid_sas.h|   1 -
>  drivers/scsi/megaraid/megaraid_sas_base.c   |  12 ++-
>  drivers/scsi/megaraid/megaraid_sas_fusion.c | 113 
> +---
>  3 files changed, 80 insertions(+), 46 deletions(-)
>
> diff --git a/drivers/scsi/megaraid/megaraid_sas.h 
> b/drivers/scsi/megaraid/megaraid_sas.h
> index 2b209bb..6d9f111 100644
> --- a/drivers/scsi/megaraid/megaraid_sas.h
> +++ b/drivers/scsi/megaraid/megaraid_sas.h
> @@ -2115,7 +2115,6 @@ struct megasas_instance {
>   u32 *crash_dump_buf;
>   dma_addr_t crash_dump_h;
>   void *crash_buf[MAX_CRASH_DUMP_SIZE];
> - u32 crash_buf_pages;
>   unsigned intfw_crash_buffer_size;
>   unsigned intfw_crash_state;
>   unsigned intfw_crash_buffer_offset;
> diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
> b/drivers/scsi/megaraid/megaraid_sas_base.c
> index e490272..c63ef88 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_base.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
> @@ -49,6 +49,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #include 
>  #include 
> @@ -6672,9 +6673,14 @@ static void megasas_detach_one(struct pci_dev *pdev)
> fusion->max_map_sz,
> fusion->ld_map[i],
> fusion->ld_map_phys[i]);
> - if (fusion->ld_drv_map[i])
> - free_pages((ulong)fusion->ld_drv_map[i],
> - fusion->drv_map_pages);
> + if (fusion->ld_drv_map[i]) {
> + if (is_vmalloc_addr(fusion->ld_drv_map[i]))
> + vfree(fusion->ld_drv_map[i]);
> + else
> + free_pages((ulong)fusion->ld_drv_map[i],
> +fusion->drv_map_pages);
> + }
> +
>   if (fusion->pd_seq_sync[i])
>   dma_free_coherent(>pdev->dev,
>   pd_seq_map_sz,
> diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
> b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> index c239762..2f5212d 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> @@ -1257,6 +1257,72 @@ megasas_display_intel_branding(struct megasas_instance 
> *instance)
>  }
>  
>  /**
> + * megasas_allocate_raid_maps -  Allocate memory for RAID maps
> + * @instance:Adapter soft state
> + *
> + * return:   if success: return 0
> + *   failed:  return -ENOMEM
> + */
> +static inline int megasas_allocate_raid_maps(struct megasas_instance 
> *instance)
> +{
> + struct fusion_context *fusion;
> + int i = 0;
> +
> + fusion = instance->ctrl_context;
> +
> + fusion->drv_map_pages = get_order(fusion->drv_map_sz);
> +
> + for (i = 0; i < 2; i++) {
> + fusion->ld_map[i] = NULL;
> +
> + fusion->ld_drv_map[i] = (void *)
> + __get_free_pages(__GFP_ZERO | GFP_KERNEL,
> +  fusion->drv_map_pages);
> +
> + if (!fusion->ld_drv_map[i]) {
> + fusion->ld_drv_map[i] = vzalloc(fusion->drv_map_sz);
> +
> + if (!fusion->ld_drv_map[i]) {
> + dev_err(>pdev->dev,
> + "Could not allocate memory for local 
> map"
> + " size requested: %d\n",
> + fusion->drv_map_sz);
> +
> + if (fusion->ld_drv_map[0]) {
> + if 
> (is_vmalloc_addr(fusion->ld_drv_map[0]))
> + vfree(fusion->ld_drv_map[0]);
> + else
> + 
> free_pages((ulong)fusion->ld_drv_map[0],
> +
> fusion->drv_map_pages);
> + }
> + return -ENOMEM;
> + }
> + }
> + }
> +
> + for (i = 0; i < 2; i++) {
> + fusion->ld_map[i] = dma_alloc_coherent(>pdev->dev,
> +fusion->max_map_sz,
> +>ld_map_phys[i],
> +GFP_KERNEL);
> + if (!fusion->ld_map[i]) {
> + dev_err(>pdev->dev,
> +