All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/39] megaraid_sas: Updates for scsi-next
@ 2017-02-08  9:28 Shivasharan S
  2017-02-08  9:28 ` [PATCH v2 01/39] Revert "scsi: megaraid_sas: Enable or Disable Fast path based on the PCI Threshold Bandwidth" Shivasharan S
                   ` (38 more replies)
  0 siblings, 39 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:28 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Changes in v2:
Patch 3: Fix to update status and ex_status from failed r1_cmd
Patch 8: Split into two separate patches,
 1. megasas_get_request_descriptor will always return valid
    request descriptor
 2. With above changes, issue_dcmd always return DCMD_SUCCESS.
    Change return type to void and update all callers.
Patch 11: Update commit description, remove reference to dependent patch.
Patch 12: Update with correct commit description
Patch 14: Fix typo in commit description
Patch 19: Correction to commit description
Drop patch 33 of last patch series which added call for flush_scheduled_work

Shivasharan S (39):
  Revert "scsi: megaraid_sas: Enable or Disable Fast path based on the
    PCI Threshold Bandwidth"
  megaraid_sas: cpu select rework.
  megaraid_sas: raid 1 fast path code optimize
  megaraid_sas: 32 bit descriptor fire cmd optimization
  megaraid_sas: Refactor MEGASAS_IS_LOGICAL macro using sdev
  megaraid_sas: RAID map is accessed for SYS PDs when use_seqnum_jbod_fp
    is not set
  megaraid_sas: Use DID_REQUEUE
  megaraid_sas: megasas_get_request_descriptor always return valid desc
  megaraid_sas: change issue_dcmd to return void from int
  megaraid_sas: NVME Interface detection and prop settings
  megaraid_sas: NVME interface target prop added
  megaraid_sas: NVME fast path io support
  megaraid_sas: raid 1 write performance for large io
  megaraid_sas: set residual bytes count during IO completion
  megaraid_sas: enhance debug logs in OCR context
  megaraid_sas: add print in device removal path
  megaraid_sas: reduce size of fusion_context and use vmalloc if kmalloc
    fails
  megaraid_sas: In validate raid map, raid capability is not converted
    to cpu format for all lds
  megaraid_sas: MR_TargetIdToLdGet u8 to u16 and avoid invalid raid-map
    access
  megaraid_sas: Big endian RDPQ mode fix
  megaraid_sas: big endian support changes
  megaraid_sas: avoid unaligned access in ioctl path
  megaraid_sas: latest controller OCR capability from FW before sending
    shutdown DCMD
  megaraid_sas: set pd_after_lb from MR_BuildRaidContext and initialize
    pDevHandle to MR_DEVHANDLE_INVALID
  megaraid_sas: Change max_cmd from u32 to u16 in all functions
  megaraid_sas: update can_queue only if the new value is less
  megaraid_sas: max_fw_cmds are decremented twice, remove duplicate
  megaraid_sas: megasas_return_cmd does not memset IO frame to zero
  megaraid_sas: Remove unused pd_index from
    megasas_build_ld_nonrw_fusion
  megaraid_sas: Do not set fp_possible if TM capable for non-RW syspdIO,
    change fp_possible to bool
  megaraid_sas: During OCR, if get_ctrl_info fails do not continue with
    OCR
  megaraid_sas: Change build_mpt_mfi_pass_thru to return void
  megaraid_sas: Bail out the driver load if ld_list_query fails
  megaraid_sas: Use synchronize_irq to wait for IRQs to complete
  megaraid_sas: Increase internal command pool
  megaraid_sas: Cleanup VD_EXT_DEBUG and SPAN_DEBUG related debug prints
  megaraid_sas: Indentation and smatch warning fixes
  megaraid_sas: Change RAID_1_10_RMW_CMDS to RAID_1_PEER_CMDS and set
    value to 2
  megaraid_sas: driver version upgrade

 drivers/scsi/megaraid/megaraid_sas.h        |   82 +-
 drivers/scsi/megaraid/megaraid_sas_base.c   |  548 +++++++----
 drivers/scsi/megaraid/megaraid_sas_fp.c     |  427 ++-------
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 1352 ++++++++++++++++-----------
 drivers/scsi/megaraid/megaraid_sas_fusion.h |  144 ++-
 5 files changed, 1434 insertions(+), 1119 deletions(-)

-- 
2.8.3

^ permalink raw reply	[flat|nested] 57+ messages in thread

* [PATCH v2 01/39] Revert "scsi: megaraid_sas: Enable or Disable Fast path based on the PCI Threshold Bandwidth"
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
@ 2017-02-08  9:28 ` Shivasharan S
  2017-02-08  9:28 ` [PATCH v2 02/39] megaraid_sas: cpu select rework Shivasharan S
                   ` (37 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:28 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

This reverts
commit "3e5eadb1a881" ("scsi: megaraid_sas: Enable or Disable Fast path based on the PCI Threshold Bandwidth")

This patch was aimed to increase performance of R1 Write operation for large IO size.
Since this method used timer approach, it turn on/off fast path did not work as expected.
Patch 0013 describes new algorithm and performance number.

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas.h        |  8 -----
 drivers/scsi/megaraid/megaraid_sas_base.c   | 48 -----------------------------
 drivers/scsi/megaraid/megaraid_sas_fp.c     |  7 -----
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 16 ++++------
 drivers/scsi/megaraid/megaraid_sas_fusion.h |  2 +-
 5 files changed, 7 insertions(+), 74 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index ba9fbb7..f5c4742 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -1477,8 +1477,6 @@ enum FW_BOOT_CONTEXT {
 #define MFI_1068_FW_HANDSHAKE_OFFSET		0x64
 #define MFI_1068_FW_READY			0xDDDD0000
 
-#define MEGASAS_RAID1_FAST_PATH_STATUS_CHECK_INTERVAL HZ
-
 #define MR_MAX_REPLY_QUEUES_OFFSET              0X0000001F
 #define MR_MAX_REPLY_QUEUES_EXT_OFFSET          0X003FC000
 #define MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT    14
@@ -2154,10 +2152,6 @@ struct megasas_instance {
 	atomic_t ldio_outstanding;
 	atomic_t fw_reset_no_pci_access;
 
-	atomic64_t bytes_wrote; /* used for raid1 fast path enable or disable */
-	atomic_t r1_write_fp_capable;
-
-
 	struct megasas_instance_template *instancet;
 	struct tasklet_struct isr_tasklet;
 	struct work_struct work_init;
@@ -2199,7 +2193,6 @@ struct megasas_instance {
 	long reset_flags;
 	struct mutex reset_mutex;
 	struct timer_list sriov_heartbeat_timer;
-	struct timer_list r1_fp_hold_timer;
 	char skip_heartbeat_timer_del;
 	u8 requestorId;
 	char PlasmaFW111;
@@ -2216,7 +2209,6 @@ struct megasas_instance {
 	bool is_ventura;
 	bool msix_combined;
 	u16 max_raid_mapsize;
-	u64 pci_threshold_bandwidth; /* used to control the fp writes */
 };
 struct MR_LD_VF_MAP {
 	u32 size;
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 70891a7..3ed876a 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -1940,9 +1940,6 @@ void megaraid_sas_kill_hba(struct megasas_instance *instance)
 	}
 	/* Complete outstanding ioctls when adapter is killed */
 	megasas_complete_outstanding_ioctls(instance);
-	if (instance->is_ventura)
-		del_timer_sync(&instance->r1_fp_hold_timer);
-
 }
 
  /**
@@ -2441,24 +2438,6 @@ void megasas_sriov_heartbeat_handler(unsigned long instance_addr)
 	}
 }
 
-/*Handler for disabling/enabling raid 1 fast paths*/
-void megasas_change_r1_fp_status(unsigned long instance_addr)
-{
-	struct megasas_instance *instance =
-			(struct megasas_instance *)instance_addr;
-	if (atomic64_read(&instance->bytes_wrote) >=
-					instance->pci_threshold_bandwidth) {
-
-		atomic64_set(&instance->bytes_wrote, 0);
-		atomic_set(&instance->r1_write_fp_capable, 0);
-	} else {
-		atomic64_set(&instance->bytes_wrote, 0);
-		atomic_set(&instance->r1_write_fp_capable, 1);
-	}
-	mod_timer(&instance->r1_fp_hold_timer,
-	 jiffies + MEGASAS_RAID1_FAST_PATH_STATUS_CHECK_INTERVAL);
-}
-
 /**
  * megasas_wait_for_outstanding -	Wait for all outstanding cmds
  * @instance:				Adapter soft state
@@ -5386,17 +5365,6 @@ static int megasas_init_fw(struct megasas_instance *instance)
 			instance->skip_heartbeat_timer_del = 1;
 	}
 
-	if (instance->is_ventura) {
-		atomic64_set(&instance->bytes_wrote, 0);
-		atomic_set(&instance->r1_write_fp_capable, 1);
-		megasas_start_timer(instance,
-			    &instance->r1_fp_hold_timer,
-			    megasas_change_r1_fp_status,
-			    MEGASAS_RAID1_FAST_PATH_STATUS_CHECK_INTERVAL);
-				dev_info(&instance->pdev->dev, "starting the raid 1 fp timer with interval %d\n",
-				MEGASAS_RAID1_FAST_PATH_STATUS_CHECK_INTERVAL);
-	}
-
 	return 0;
 
 fail_get_ld_pd_list:
@@ -6187,9 +6155,6 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t state)
 	if (instance->requestorId && !instance->skip_heartbeat_timer_del)
 		del_timer_sync(&instance->sriov_heartbeat_timer);
 
-	if (instance->is_ventura)
-		del_timer_sync(&instance->r1_fp_hold_timer);
-
 	megasas_flush_cache(instance);
 	megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN);
 
@@ -6316,16 +6281,6 @@ megasas_resume(struct pci_dev *pdev)
 	megasas_setup_jbod_map(instance);
 	instance->unload = 0;
 
-	if (instance->is_ventura) {
-		atomic64_set(&instance->bytes_wrote, 0);
-		atomic_set(&instance->r1_write_fp_capable, 1);
-		megasas_start_timer(instance,
-			    &instance->r1_fp_hold_timer,
-			    megasas_change_r1_fp_status,
-			    MEGASAS_RAID1_FAST_PATH_STATUS_CHECK_INTERVAL);
-	}
-
-
 	/*
 	 * Initiate AEN (Asynchronous Event Notification)
 	 */
@@ -6414,9 +6369,6 @@ static void megasas_detach_one(struct pci_dev *pdev)
 	if (instance->requestorId && !instance->skip_heartbeat_timer_del)
 		del_timer_sync(&instance->sriov_heartbeat_timer);
 
-	if (instance->is_ventura)
-		del_timer_sync(&instance->r1_fp_hold_timer);
-
 	if (instance->fw_crash_state != UNAVAILABLE)
 		megasas_free_host_crash_buffer(instance);
 	scsi_remove_host(instance->host);
diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
index 322a72b..f1384b0 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -197,9 +197,6 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 
 	if (instance->max_raid_mapsize) {
 		fw_map_dyn = fusion->ld_map[(instance->map_id & 1)];
-		if (fw_map_dyn->pci_threshold_bandwidth)
-			instance->pci_threshold_bandwidth =
-			le64_to_cpu(fw_map_dyn->pci_threshold_bandwidth);
 #if VD_EXT_DEBUG
 		dev_dbg(&instance->pdev->dev, "raidMapSize 0x%x fw_map_dyn->descTableOffset 0x%x\n",
 			le32_to_cpu(fw_map_dyn->raid_map_size),
@@ -207,8 +204,6 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 		dev_dbg(&instance->pdev->dev, "descTableSize 0x%x descTableNumElements 0x%x\n",
 			le32_to_cpu(fw_map_dyn->desc_table_size),
 			le32_to_cpu(fw_map_dyn->desc_table_num_elements));
-		dev_dbg(&instance->pdev->dev, "PCIThreasholdBandwidth %llu\n",
-			instance->pci_threshold_bandwidth);
 		dev_dbg(&instance->pdev->dev, "drv map %p ldCount %d\n",
 			drv_map, fw_map_dyn->ld_count);
 #endif
@@ -439,8 +434,6 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 			sizeof(struct MR_DEV_HANDLE_INFO) *
 			MAX_RAIDMAP_PHYSICAL_DEVICES);
 	}
-	if (instance->is_ventura && !instance->pci_threshold_bandwidth)
-		instance->pci_threshold_bandwidth = ULLONG_MAX;
 }
 
 /*
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 9a9c84f..54728b3 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -95,7 +95,6 @@ extern unsigned int resetwaittime;
 extern unsigned int dual_qdepth_disable;
 static void megasas_free_rdpq_fusion(struct megasas_instance *instance);
 static void megasas_free_reply_fusion(struct megasas_instance *instance);
-void megasas_change_r1_fp_status(unsigned long instance_addr);
 
 
 
@@ -2634,9 +2633,8 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
 	 *	to get new command
 	 */
 	if (cmd->is_raid_1_fp_write &&
-		(atomic_inc_return(&instance->fw_outstanding) >
-			(instance->host->can_queue) ||
-		(!atomic_read(&instance->r1_write_fp_capable)))) {
+		atomic_inc_return(&instance->fw_outstanding) >
+			(instance->host->can_queue)) {
 		megasas_fpio_to_ldio(instance, cmd, cmd->scmd);
 		atomic_dec(&instance->fw_outstanding);
 	} else if (cmd->is_raid_1_fp_write) {
@@ -2645,19 +2643,17 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
 		megasas_prepare_secondRaid1_IO(instance, cmd, r1_cmd);
 	}
 
+
 	/*
 	 * Issue the command to the FW
 	 */
-	if (scmd->sc_data_direction == PCI_DMA_TODEVICE && instance->is_ventura)
-		atomic64_add(scsi_bufflen(scmd), &instance->bytes_wrote);
 
 	megasas_fire_cmd_fusion(instance, req_desc, instance->is_ventura);
 
-	if (r1_cmd) {
-		atomic64_add(scsi_bufflen(scmd), &instance->bytes_wrote);
+	if (r1_cmd)
 		megasas_fire_cmd_fusion(instance, r1_cmd->request_desc,
-			instance->is_ventura);
-	}
+				instance->is_ventura);
+
 
 	return 0;
 }
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
index 3addd0c..82a4ff7 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
@@ -977,7 +977,7 @@ struct MR_FW_RAID_MAP_DYNAMIC {
 	u32 desc_table_size;  /* Total Size of desc table */
 	/* Total Number of elements in the desc table */
 	u32 desc_table_num_elements;
-	u64	pci_threshold_bandwidth;
+	u64	reserved1;
 	u32	reserved2[3];	/*future use */
 	/* timeout value used by driver in FP IOs */
 	u8 fp_pd_io_timeout_sec;
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 02/39] megaraid_sas: cpu select rework.
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
  2017-02-08  9:28 ` [PATCH v2 01/39] Revert "scsi: megaraid_sas: Enable or Disable Fast path based on the PCI Threshold Bandwidth" Shivasharan S
@ 2017-02-08  9:28 ` Shivasharan S
  2017-02-08  9:28 ` [PATCH v2 03/39] megaraid_sas: raid 1 fast path code optimize Shivasharan S
                   ` (36 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:28 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

No functional change. Code refactor.

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 175 ++++++++++++++++------------
 1 file changed, 100 insertions(+), 75 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 54728b3..514c306 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1819,6 +1819,73 @@ static void megasas_stream_detect(struct megasas_instance *instance,
 }
 
 /**
+ * megasas_set_raidflag_cpu_affinity - This function sets the cpu
+ * affinity (cpu of the controller) and raid_flags in the raid context
+ * based on IO type.
+ *
+ * @praid_context:	IO RAID context
+ * @raid:		LD raid map
+ * @fp_possible:	Is fast path possible?
+ * @is_read:		Is read IO?
+ *
+ */
+static void
+megasas_set_raidflag_cpu_affinity(union RAID_CONTEXT_UNION *praid_context,
+				  struct MR_LD_RAID *raid, bool fp_possible,
+				  u8 is_read)
+{
+	u8 cpu_sel = MR_RAID_CTX_CPUSEL_0;
+	struct RAID_CONTEXT_G35 *rctx_g35;
+
+	rctx_g35 = &praid_context->raid_context_g35;
+	if (fp_possible) {
+		if (is_read) {
+			if ((raid->cpuAffinity.pdRead.cpu0) &&
+			    (raid->cpuAffinity.pdRead.cpu1))
+				cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
+			else if (raid->cpuAffinity.pdRead.cpu1)
+				cpu_sel = MR_RAID_CTX_CPUSEL_1;
+		} else {
+			if ((raid->cpuAffinity.pdWrite.cpu0) &&
+			    (raid->cpuAffinity.pdWrite.cpu1))
+				cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
+			else if (raid->cpuAffinity.pdWrite.cpu1)
+				cpu_sel = MR_RAID_CTX_CPUSEL_1;
+			/* Fast path cache by pass capable R0/R1 VD */
+			if ((raid->level <= 1) &&
+			    (raid->capability.fp_cache_bypass_capable)) {
+				rctx_g35->routing_flags.bits.sld = 1;
+				rctx_g35->raid_flags =
+					(MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS
+					<< MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT);
+			}
+		}
+	} else {
+		if (is_read) {
+			if ((raid->cpuAffinity.ldRead.cpu0) &&
+			    (raid->cpuAffinity.ldRead.cpu1))
+				cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
+			else if (raid->cpuAffinity.ldRead.cpu1)
+				cpu_sel = MR_RAID_CTX_CPUSEL_1;
+		} else {
+			if ((raid->cpuAffinity.ldWrite.cpu0) &&
+			    (raid->cpuAffinity.ldWrite.cpu1))
+				cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
+			else if (raid->cpuAffinity.ldWrite.cpu1)
+				cpu_sel = MR_RAID_CTX_CPUSEL_1;
+
+			if (rctx_g35->stream_detected &&
+			    (raid->level == 5) &&
+			    (raid->writeMode == MR_RL_WRITE_THROUGH_MODE) &&
+			    (cpu_sel == MR_RAID_CTX_CPUSEL_FCFS))
+				cpu_sel = MR_RAID_CTX_CPUSEL_0;
+		}
+	}
+
+	rctx_g35->routing_flags.bits.cpu_sel = cpu_sel;
+}
+
+/**
  * megasas_build_ldio_fusion -	Prepares IOs to devices
  * @instance:		Adapter soft state
  * @scp:		SCSI command
@@ -1832,8 +1899,10 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 			  struct scsi_cmnd *scp,
 			  struct megasas_cmd_fusion *cmd)
 {
-	u8 fp_possible;
-	u32 start_lba_lo, start_lba_hi, device_id, datalength = 0, ld;
+	bool fp_possible;
+	u16 ld;
+	u32 start_lba_lo, start_lba_hi, device_id, datalength = 0;
+	u32 scsi_buff_len;
 	struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
 	union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
 	struct IO_REQUEST_INFO io_info;
@@ -1842,7 +1911,8 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 	u8 *raidLUN;
 	unsigned long spinlock_flags;
 	union RAID_CONTEXT_UNION *praid_context;
-	struct MR_LD_RAID *raid;
+	struct MR_LD_RAID *raid = NULL;
+	struct MR_PRIV_DEVICE *mrdev_priv;
 
 	device_id = MEGASAS_DEV_INDEX(scp);
 
@@ -1858,7 +1928,7 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 
 	start_lba_lo = 0;
 	start_lba_hi = 0;
-	fp_possible = 0;
+	fp_possible = false;
 
 	/*
 	 * 6-byte READ(0x08) or WRITE(0x0A) cdb
@@ -1915,7 +1985,8 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 	io_info.numBlocks = datalength;
 	io_info.ldTgtId = device_id;
 	io_info.r1_alt_dev_handle = MR_PD_INVALID;
-	io_request->DataLength = cpu_to_le32(scsi_bufflen(scp));
+	scsi_buff_len = scsi_bufflen(scp);
+	io_request->DataLength = cpu_to_le32(scsi_buff_len);
 
 	if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
 		io_info.isRead = 1;
@@ -1927,12 +1998,12 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 	if ((MR_TargetIdToLdGet(device_id, local_map_ptr) >=
 		instance->fw_supported_vd_count) || (!fusion->fast_path_io)) {
 		io_request->RaidContext.raid_context.reg_lock_flags  = 0;
-		fp_possible = 0;
+		fp_possible = false;
 	} else {
 		if (MR_BuildRaidContext(instance, &io_info,
 					&io_request->RaidContext.raid_context,
 					local_map_ptr, &raidLUN))
-			fp_possible = io_info.fpOkForIo;
+			fp_possible = (io_info.fpOkForIo > 0) ? true : false;
 	}
 
 	/* Use raw_smp_processor_id() for now until cmd->request->cpu is CPU
@@ -1941,6 +2012,8 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 	cmd->request_desc->SCSIIO.MSIxIndex = instance->msix_vectors ?
 		raw_smp_processor_id() % instance->msix_vectors : 0;
 
+	praid_context = &io_request->RaidContext;
+
 	if (instance->is_ventura) {
 		spin_lock_irqsave(&instance->stream_lock, spinlock_flags);
 		megasas_stream_detect(instance, cmd, &io_info);
@@ -1948,12 +2021,28 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 		/* In ventura if stream detected for a read and it is read ahead
 		 *  capable make this IO as LDIO
 		 */
-		if (io_request->RaidContext.raid_context_g35.stream_detected &&
-				io_info.isRead && io_info.ra_capable)
+		if (praid_context->raid_context_g35.stream_detected &&
+		    io_info.isRead && io_info.ra_capable)
 			fp_possible = false;
-	}
 
-	praid_context = &io_request->RaidContext;
+		if (io_info.r1_alt_dev_handle != MR_PD_INVALID) {
+			mrdev_priv = scp->device->hostdata;
+
+			if (atomic_inc_return(&instance->fw_outstanding) >
+				(instance->host->can_queue)) {
+				fp_possible = false;
+				atomic_dec(&instance->fw_outstanding);
+			}
+		}
+
+		/* If raid is NULL, set CPU affinity to default CPU0 */
+		if (raid)
+			megasas_set_raidflag_cpu_affinity(praid_context,
+				raid, fp_possible, io_info.isRead);
+		else
+			praid_context->raid_context_g35.routing_flags.bits.cpu_sel =
+				MR_RAID_CTX_CPUSEL_0;
+	}
 
 	if (fp_possible) {
 		megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp,
@@ -2016,36 +2105,6 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 		io_request->DevHandle = io_info.devHandle;
 		/* populate the LUN field */
 		memcpy(io_request->LUN, raidLUN, 8);
-		if (instance->is_ventura) {
-			if (io_info.isRead) {
-				if ((raid->cpuAffinity.pdRead.cpu0) &&
-					(raid->cpuAffinity.pdRead.cpu1))
-					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-					= MR_RAID_CTX_CPUSEL_FCFS;
-				else if (raid->cpuAffinity.pdRead.cpu1)
-					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-					= MR_RAID_CTX_CPUSEL_1;
-				else
-					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-					= MR_RAID_CTX_CPUSEL_0;
-			} else {
-			if ((raid->cpuAffinity.pdWrite.cpu0)
-			&& (raid->cpuAffinity.pdWrite.cpu1))
-				praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-					= MR_RAID_CTX_CPUSEL_FCFS;
-				else if (raid->cpuAffinity.pdWrite.cpu1)
-					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-					= MR_RAID_CTX_CPUSEL_1;
-				else
-					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-					= MR_RAID_CTX_CPUSEL_0;
-				if (praid_context->raid_context_g35.routing_flags.bits.sld) {
-					praid_context->raid_context_g35.raid_flags
-					= (MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS
-					<< MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT);
-				}
-			}
-		}
 	} else {
 		io_request->RaidContext.raid_context.timeout_value =
 			cpu_to_le16(local_map_ptr->raidMap.fpPdIoTimeoutSec);
@@ -2074,40 +2133,6 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 		io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
 		io_request->DevHandle = cpu_to_le16(device_id);
 
-		if (instance->is_ventura) {
-			if (io_info.isRead) {
-				if ((raid->cpuAffinity.ldRead.cpu0)
-				&& (raid->cpuAffinity.ldRead.cpu1))
-					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-					= MR_RAID_CTX_CPUSEL_FCFS;
-				else if (raid->cpuAffinity.ldRead.cpu1)
-					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-						= MR_RAID_CTX_CPUSEL_1;
-				else
-					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-						= MR_RAID_CTX_CPUSEL_0;
-			} else {
-				if ((raid->cpuAffinity.ldWrite.cpu0) &&
-					(raid->cpuAffinity.ldWrite.cpu1))
-					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-						= MR_RAID_CTX_CPUSEL_FCFS;
-				else if (raid->cpuAffinity.ldWrite.cpu1)
-					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-						= MR_RAID_CTX_CPUSEL_1;
-				else
-					praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-					= MR_RAID_CTX_CPUSEL_0;
-
-				if (io_request->RaidContext.raid_context_g35.stream_detected
-					&& (raid->level == 5) &&
-					(raid->writeMode == MR_RL_WRITE_THROUGH_MODE)) {
-					if (praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-						== MR_RAID_CTX_CPUSEL_FCFS)
-						praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-							= MR_RAID_CTX_CPUSEL_0;
-				}
-			}
-		}
 	} /* Not FP */
 }
 
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 03/39] megaraid_sas: raid 1 fast path code optimize
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
  2017-02-08  9:28 ` [PATCH v2 01/39] Revert "scsi: megaraid_sas: Enable or Disable Fast path based on the PCI Threshold Bandwidth" Shivasharan S
  2017-02-08  9:28 ` [PATCH v2 02/39] megaraid_sas: cpu select rework Shivasharan S
@ 2017-02-08  9:28 ` Shivasharan S
  2017-02-08 14:34   ` Tomas Henzl
  2017-02-09 13:16   ` Tomas Henzl
  2017-02-08  9:28 ` [PATCH v2 04/39] megaraid_sas: 32 bit descriptor fire cmd optimization Shivasharan S
                   ` (35 subsequent siblings)
  38 siblings, 2 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:28 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

fix in v2 - ex_status and status was wrongly re-used in megasas_complete_r1_command.
discussed below -
http://marc.info/?l=linux-scsi&m=148638763409385&w=2


No functional change. Code refactor.
Remove function megasas_fpio_to_ldio as we never require to convert fpio to ldio because of frame unavailability.
Grab extra frame of raid 1 write fast path before it creates first frame as Fast Path.
Removed is_raid_1_fp_write flag as raid 1 write fast path command is decided using r1_alt_dev_handle only.
Move resetting megasas_cmd_fusion fields at common function megasas_return_cmd_fusion.


Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
---
 drivers/scsi/megaraid/megaraid_sas_fp.c     |  14 +-
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 349 +++++++++-------------------
 drivers/scsi/megaraid/megaraid_sas_fusion.h |   3 +-
 3 files changed, 118 insertions(+), 248 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
index f1384b0..24258af 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -1338,20 +1338,8 @@ MR_BuildRaidContext(struct megasas_instance *instance,
 					ref_in_start_stripe, io_info,
 					pRAID_Context, map);
 		/* If IO on an invalid Pd, then FP is not possible.*/
-		if (io_info->devHandle == cpu_to_le16(MR_PD_INVALID))
+		if (io_info->devHandle == MR_DEVHANDLE_INVALID)
 			io_info->fpOkForIo = FALSE;
-		/* if FP possible, set the SLUD bit in
-		 *  regLockFlags for ventura
-		 */
-		else if ((instance->is_ventura) && (!isRead) &&
-			(raid->writeMode == MR_RL_WRITE_BACK_MODE) &&
-			(raid->capability.fp_cache_bypass_capable))
-			((struct RAID_CONTEXT_G35 *) pRAID_Context)->routing_flags.bits.sld = 1;
-		/* set raid 1/10 fast path write capable bit in io_info */
-		if (io_info->fpOkForIo &&
-		    (io_info->r1_alt_dev_handle != MR_PD_INVALID) &&
-		    (raid->level == 1) && !isRead)
-			io_info->is_raid_1_fp_write = 1;
 		return retval;
 	} else if (isRead) {
 		uint stripIdx;
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 514c306..7516589 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -181,7 +181,9 @@ inline void megasas_return_cmd_fusion(struct megasas_instance *instance,
 	struct megasas_cmd_fusion *cmd)
 {
 	cmd->scmd = NULL;
-	memset(cmd->io_request, 0, sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
+	memset(cmd->io_request, 0, MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE);
+	cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
+	cmd->cmd_completed = false;
 }
 
 /**
@@ -701,7 +703,7 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance)
 		memset(cmd->io_request, 0,
 		       sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
 		cmd->io_request_phys_addr = io_req_base_phys + offset;
-		cmd->is_raid_1_fp_write = 0;
+		cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
 	}
 
 	if (megasas_create_sg_sense_fusion(instance))
@@ -1984,7 +1986,7 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 	io_info.ldStartBlock = ((u64)start_lba_hi << 32) | start_lba_lo;
 	io_info.numBlocks = datalength;
 	io_info.ldTgtId = device_id;
-	io_info.r1_alt_dev_handle = MR_PD_INVALID;
+	io_info.r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
 	scsi_buff_len = scsi_bufflen(scp);
 	io_request->DataLength = cpu_to_le32(scsi_buff_len);
 
@@ -2025,7 +2027,7 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 		    io_info.isRead && io_info.ra_capable)
 			fp_possible = false;
 
-		if (io_info.r1_alt_dev_handle != MR_PD_INVALID) {
+		if (io_info.r1_alt_dev_handle != MR_DEVHANDLE_INVALID) {
 			mrdev_priv = scp->device->hostdata;
 
 			if (atomic_inc_return(&instance->fw_outstanding) >
@@ -2090,9 +2092,10 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 		} else
 			scp->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
 
-		cmd->is_raid_1_fp_write = io_info.is_raid_1_fp_write;
-		if (io_info.is_raid_1_fp_write)
+		if (instance->is_ventura)
 			cmd->r1_alt_dev_handle = io_info.r1_alt_dev_handle;
+		else
+			cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
 
 		if ((raidLUN[0] == 1) &&
 			(local_map_ptr->raidMap.devHndlInfo[io_info.pd_after_lb].validHandles > 1)) {
@@ -2451,72 +2454,6 @@ megasas_get_request_descriptor(struct megasas_instance *instance, u16 index)
 	return (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)p;
 }
 
-/*
- * megasas_fpio_to_ldio-
- * This function converts an fp io to ldio
- */
-
-void megasas_fpio_to_ldio(struct megasas_instance *instance,
-	struct megasas_cmd_fusion *cmd, struct scsi_cmnd *scmd)
-{
-	struct fusion_context *fusion;
-	union RAID_CONTEXT_UNION *praid_context;
-	struct MR_LD_RAID *raid;
-	struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
-	u32 device_id, ld;
-
-	fusion = instance->ctrl_context;
-	cmd->request_desc->SCSIIO.RequestFlags =
-		(MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
-		<< MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
-	cmd->io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
-	cmd->io_request->DevHandle = cpu_to_le16(MEGASAS_DEV_INDEX(scmd));
-
-	/*remove FAST PATH ENABLE bit in IoFlags */
-	cmd->io_request->IoFlags &=
-	cpu_to_le16(~MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
-
-	/* if the numSGE > max_sge_in_main_sge set the chain offset*/
-	if (cmd->io_request->RaidContext.raid_context_g35.num_sge >
-		fusion->max_sge_in_main_msg)
-		cmd->io_request->ChainOffset = fusion->chain_offset_io_request;
-	memcpy(cmd->io_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
-	cmd->io_request->CDB.EEDP32.PrimaryReferenceTag = 0;
-	cmd->io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0;
-	cmd->io_request->EEDPFlags = 0;
-	cmd->io_request->Control = 0;
-	cmd->io_request->EEDPBlockSize = 0;
-	cmd->is_raid_1_fp_write = 0;
-
-	device_id = MEGASAS_DEV_INDEX(cmd->scmd);
-	local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
-	ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
-	raid = MR_LdRaidGet(ld, local_map_ptr);
-	praid_context = &cmd->io_request->RaidContext;
-	if (cmd->scmd->sc_data_direction == PCI_DMA_FROMDEVICE) {
-		if ((raid->cpuAffinity.ldRead.cpu0)
-		&& (raid->cpuAffinity.ldRead.cpu1))
-			praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-			= MR_RAID_CTX_CPUSEL_FCFS;
-		else if (raid->cpuAffinity.ldRead.cpu1)
-			praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-			= MR_RAID_CTX_CPUSEL_1;
-		else
-			praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-			= MR_RAID_CTX_CPUSEL_0;
-	} else {
-	if ((raid->cpuAffinity.ldWrite.cpu0)
-		&& (raid->cpuAffinity.ldWrite.cpu1))
-		praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-			= MR_RAID_CTX_CPUSEL_FCFS;
-	else if (raid->cpuAffinity.ldWrite.cpu1)
-		praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-			= MR_RAID_CTX_CPUSEL_1;
-	else
-		praid_context->raid_context_g35.routing_flags.bits.cpu_sel
-		= MR_RAID_CTX_CPUSEL_0;
-	}
-}
 
 /* megasas_prepate_secondRaid1_IO
  *  It prepares the raid 1 second IO
@@ -2527,60 +2464,36 @@ void megasas_prepare_secondRaid1_IO(struct megasas_instance *instance,
 {
 	union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc, *req_desc2 = NULL;
 	struct fusion_context *fusion;
-
 	fusion = instance->ctrl_context;
 	req_desc = cmd->request_desc;
-	if (r1_cmd) {
-		/* copy the io request frame as well
-		 *  as 8 SGEs data for r1 command
-		 */
-		memcpy(r1_cmd->io_request, cmd->io_request,
-			sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
-		memcpy(&r1_cmd->io_request->SGL, &cmd->io_request->SGL,
-				(fusion->max_sge_in_main_msg *
-				sizeof(union MPI2_SGE_IO_UNION)));
-		/*sense buffer is different for r1 command*/
-		r1_cmd->io_request->SenseBufferLowAddress =
-				cpu_to_le32(r1_cmd->sense_phys_addr);
-		r1_cmd->scmd = cmd->scmd;
-		req_desc2 =
-		megasas_get_request_descriptor(instance, r1_cmd->index-1);
-		if (req_desc2) {
-			req_desc2->Words = 0;
-			r1_cmd->request_desc = req_desc2;
-			req_desc2->SCSIIO.SMID =
-				cpu_to_le16(r1_cmd->index);
-			req_desc2->SCSIIO.RequestFlags =
-				req_desc->SCSIIO.RequestFlags;
-			r1_cmd->is_raid_1_fp_write = 1;
-			r1_cmd->request_desc->SCSIIO.DevHandle =
-				cmd->r1_alt_dev_handle;
-			r1_cmd->io_request->DevHandle = cmd->r1_alt_dev_handle;
-			cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid =
-				 cpu_to_le16(r1_cmd->index);
-			r1_cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid =
-				cpu_to_le16(cmd->index);
-			/* MSIxIndex of both commands request
-			 * descriptors should be same
-			 */
-			r1_cmd->request_desc->SCSIIO.MSIxIndex =
-				cmd->request_desc->SCSIIO.MSIxIndex;
-			/*span arm is different for r1 cmd*/
-			r1_cmd->io_request->RaidContext.raid_context_g35.span_arm =
+	/* copy the io request frame as well as 8 SGEs data for r1 command*/
+	memcpy(r1_cmd->io_request, cmd->io_request,
+	       (sizeof(struct MPI2_RAID_SCSI_IO_REQUEST)));
+	memcpy(&r1_cmd->io_request->SGL, &cmd->io_request->SGL,
+	       (fusion->max_sge_in_main_msg * sizeof(union MPI2_SGE_IO_UNION)));
+	/*sense buffer is different for r1 command*/
+	r1_cmd->io_request->SenseBufferLowAddress =
+			cpu_to_le32(r1_cmd->sense_phys_addr);
+	r1_cmd->scmd = cmd->scmd;
+	req_desc2 = megasas_get_request_descriptor(instance,
+						   (r1_cmd->index - 1));
+	req_desc2->Words = 0;
+	r1_cmd->request_desc = req_desc2;
+	req_desc2->SCSIIO.SMID = cpu_to_le16(r1_cmd->index);
+	req_desc2->SCSIIO.RequestFlags = req_desc->SCSIIO.RequestFlags;
+	r1_cmd->request_desc->SCSIIO.DevHandle = cmd->r1_alt_dev_handle;
+	r1_cmd->io_request->DevHandle = cmd->r1_alt_dev_handle;
+	r1_cmd->r1_alt_dev_handle = cmd->io_request->DevHandle;
+	cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid =
+			cpu_to_le16(r1_cmd->index);
+	r1_cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid =
+			cpu_to_le16(cmd->index);
+	/*MSIxIndex of both commands request descriptors should be same*/
+	r1_cmd->request_desc->SCSIIO.MSIxIndex =
+			cmd->request_desc->SCSIIO.MSIxIndex;
+	/*span arm is different for r1 cmd*/
+	r1_cmd->io_request->RaidContext.raid_context_g35.span_arm =
 			cmd->io_request->RaidContext.raid_context_g35.span_arm + 1;
-		} else {
-			megasas_return_cmd_fusion(instance, r1_cmd);
-			dev_info(&instance->pdev->dev,
-				"unable to get request descriptor, firing as normal IO\n");
-			atomic_dec(&instance->fw_outstanding);
-			megasas_fpio_to_ldio(instance, cmd, cmd->scmd);
-		}
-	} else {
-		dev_info(&instance->pdev->dev,
-			"unable to get command, firing as normal IO\n");
-		atomic_dec(&instance->fw_outstanding);
-		megasas_fpio_to_ldio(instance, cmd, cmd->scmd);
-	}
 }
 
 /**
@@ -2624,10 +2537,6 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
 	index = cmd->index;
 
 	req_desc = megasas_get_request_descriptor(instance, index-1);
-	if (!req_desc) {
-		atomic_dec(&instance->fw_outstanding);
-		return SCSI_MLQUEUE_HOST_BUSY;
-	}
 
 	req_desc->Words = 0;
 	cmd->request_desc = req_desc;
@@ -2657,12 +2566,7 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
 	/*	driver side count always should be less than max_fw_cmds
 	 *	to get new command
 	 */
-	if (cmd->is_raid_1_fp_write &&
-		atomic_inc_return(&instance->fw_outstanding) >
-			(instance->host->can_queue)) {
-		megasas_fpio_to_ldio(instance, cmd, cmd->scmd);
-		atomic_dec(&instance->fw_outstanding);
-	} else if (cmd->is_raid_1_fp_write) {
+	if (cmd->r1_alt_dev_handle != MR_DEVHANDLE_INVALID) {
 		r1_cmd = megasas_get_cmd_fusion(instance,
 				(scmd->request->tag + instance->max_fw_cmds));
 		megasas_prepare_secondRaid1_IO(instance, cmd, r1_cmd);
@@ -2684,6 +2588,61 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
 }
 
 /**
+ * megasas_complete_r1_command -
+ * completes R1 FP write commands which has valid peer smid
+ * @instance:			Adapter soft state
+ * @cmd_fusion:			MPT command frame
+ *
+ */
+static inline void
+megasas_complete_r1_command(struct megasas_instance *instance,
+			    struct megasas_cmd_fusion *cmd)
+{
+	u8 *sense, status, ex_status;
+	u32 data_length;
+	u16 peer_smid;
+	struct fusion_context *fusion;
+	struct megasas_cmd_fusion *r1_cmd = NULL;
+	struct scsi_cmnd *scmd_local = NULL;
+	struct RAID_CONTEXT_G35 *rctx_g35;
+
+	rctx_g35 = &cmd->io_request->RaidContext.raid_context_g35;
+	fusion = instance->ctrl_context;
+	peer_smid = le16_to_cpu(rctx_g35->smid.peer_smid);
+
+	r1_cmd = fusion->cmd_list[peer_smid - 1];
+	scmd_local = cmd->scmd;
+	status = rctx_g35->status;
+	ex_status = rctx_g35->ex_status;
+	data_length = cmd->io_request->DataLength;
+	sense = cmd->sense;
+
+	cmd->cmd_completed = true;
+
+	/* Check if peer command is completed or not*/
+	if (r1_cmd->cmd_completed) {
+		rctx_g35 = &r1_cmd->io_request->RaidContext.raid_context_g35;
+		if (rctx_g35->status != MFI_STAT_OK) {
+			status = rctx_g35->status;
+			ex_status = rctx_g35->ex_status;
+			data_length = r1_cmd->io_request->DataLength;
+			sense = r1_cmd->sense;
+		}
+
+		megasas_return_cmd_fusion(instance, r1_cmd);
+		map_cmd_status(fusion, scmd_local, status, ex_status,
+			       le32_to_cpu(data_length), sense);
+		if (instance->ldio_threshold &&
+		    megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)
+			atomic_dec(&instance->ldio_outstanding);
+		scmd_local->SCp.ptr = NULL;
+		megasas_return_cmd_fusion(instance, cmd);
+		scsi_dma_unmap(scmd_local);
+		scmd_local->scsi_done(scmd_local);
+	}
+}
+
+/**
  * complete_cmd_fusion -	Completes command
  * @instance:			Adapter soft state
  * Completes all commands that is in reply descriptor queue
@@ -2696,10 +2655,10 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex)
 	struct MPI2_RAID_SCSI_IO_REQUEST *scsi_io_req;
 	struct fusion_context *fusion;
 	struct megasas_cmd *cmd_mfi;
-	struct megasas_cmd_fusion *cmd_fusion, *r1_cmd = NULL;
+	struct megasas_cmd_fusion *cmd_fusion;
 	u16 smid, num_completed;
-	u8 reply_descript_type, *sense;
-	u32 status, extStatus, device_id, data_length;
+	u8 reply_descript_type, *sense, status, extStatus;
+	u32 device_id, data_length;
 	union desc_value d_val;
 	struct LD_LOAD_BALANCE_INFO *lbinfo;
 	int threshold_reply_count = 0;
@@ -2729,25 +2688,11 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex)
 
 	while (d_val.u.low != cpu_to_le32(UINT_MAX) &&
 	       d_val.u.high != cpu_to_le32(UINT_MAX)) {
-		   /*
-		    * Ensure that the peer command is NULL here in case a
-		    * command has completed but the R1 FP Write peer has
-		    * not completed yet.If not null, it's possible that
-		    * another thread will complete the peer
-		    * command and should not.
-		    */
-		r1_cmd = NULL;
 
 		smid = le16_to_cpu(reply_desc->SMID);
-
 		cmd_fusion = fusion->cmd_list[smid - 1];
-
-		scsi_io_req =
-			(struct MPI2_RAID_SCSI_IO_REQUEST *)
-		  cmd_fusion->io_request;
-
-		if (cmd_fusion->scmd)
-			cmd_fusion->scmd->SCp.ptr = NULL;
+		scsi_io_req = (struct MPI2_RAID_SCSI_IO_REQUEST *)
+						cmd_fusion->io_request;
 
 		scmd_local = cmd_fusion->scmd;
 		status = scsi_io_req->RaidContext.raid_context.status;
@@ -2768,88 +2713,33 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex)
 			break;
 		case MPI2_FUNCTION_SCSI_IO_REQUEST:  /*Fast Path IO.*/
 			/* Update load balancing info */
-			device_id = MEGASAS_DEV_INDEX(scmd_local);
-			lbinfo = &fusion->load_balance_info[device_id];
-			/*
-			 * check for the raid 1/10 fast path writes
-			 */
-			if (!cmd_fusion->is_raid_1_fp_write &&
-				(cmd_fusion->scmd->SCp.Status &
-					MEGASAS_LOAD_BALANCE_FLAG)) {
+			if (fusion->load_balance_info &&
+			    (cmd_fusion->scmd->SCp.Status &
+			    MEGASAS_LOAD_BALANCE_FLAG)) {
+				device_id = MEGASAS_DEV_INDEX(scmd_local);
+				lbinfo = &fusion->load_balance_info[device_id];
 				atomic_dec(&lbinfo->scsi_pending_cmds[cmd_fusion->pd_r1_lb]);
-				cmd_fusion->scmd->SCp.Status &=
-					~MEGASAS_LOAD_BALANCE_FLAG;
-			} else if (cmd_fusion->is_raid_1_fp_write) {
-				/* get peer command */
-				if (cmd_fusion->index < instance->max_fw_cmds)
-					r1_cmd = fusion->cmd_list[(cmd_fusion->index +
-					instance->max_fw_cmds)-1];
-				else {
-					r1_cmd =
-					fusion->cmd_list[(cmd_fusion->index -
-						 instance->max_fw_cmds)-1];
-				}
-				cmd_fusion->cmd_completed = true;
+				cmd_fusion->scmd->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
 			}
-
-			if (reply_descript_type ==
-			    MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS) {
-				if (megasas_dbg_lvl == 5)
-					dev_err(&instance->pdev->dev, "\nFAST Path "
-					       "IO Success\n");
-			}
-			/* Fall thru and complete IO */
+			//Fall thru and complete IO
 		case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST: /* LD-IO Path */
-			/* Map the FW Cmd Status */
-			/*
-			 * check for the raid 1/10 fast path writes
-			 */
-			if (r1_cmd &&  r1_cmd->is_raid_1_fp_write
-				&& r1_cmd->cmd_completed) {
-				/*
-				 * if the peer  Raid  1/10 fast path failed,
-				 * mark IO as failed to the scsi layer.
-				 * over write the current status by the failed
-				 * status makes sure that if any one of
-				 * command fails,return fail status to
-				 * scsi layer
-				 */
-				if (r1_cmd->io_request->RaidContext.raid_context.status !=
-								MFI_STAT_OK) {
-					status =
-					r1_cmd->io_request->RaidContext.raid_context.status;
-					extStatus =
-					r1_cmd->io_request->RaidContext.raid_context.ex_status;
-					data_length =
-						r1_cmd->io_request->DataLength;
-					sense = r1_cmd->sense;
-				}
-				r1_cmd->io_request->RaidContext.raid_context.status = 0;
-				r1_cmd->io_request->RaidContext.raid_context.ex_status = 0;
-				cmd_fusion->is_raid_1_fp_write = 0;
-				r1_cmd->is_raid_1_fp_write = 0;
-				r1_cmd->cmd_completed = false;
-				cmd_fusion->cmd_completed = false;
-				megasas_return_cmd_fusion(instance, r1_cmd);
-			}
-			if (!cmd_fusion->is_raid_1_fp_write) {
+			atomic_dec(&instance->fw_outstanding);
+			if (cmd_fusion->r1_alt_dev_handle == MR_DEVHANDLE_INVALID) {
 				map_cmd_status(fusion, scmd_local, status,
-					extStatus, data_length, sense);
-				scsi_io_req->RaidContext.raid_context.status = 0;
-				scsi_io_req->RaidContext.raid_context.ex_status = 0;
-				if (instance->ldio_threshold
-					&& megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)
+					       extStatus, le32_to_cpu(data_length),
+					       sense);
+				if (instance->ldio_threshold &&
+				    (megasas_cmd_type(scmd_local) == READ_WRITE_LDIO))
 					atomic_dec(&instance->ldio_outstanding);
+				scmd_local->SCp.ptr = NULL;
 				megasas_return_cmd_fusion(instance, cmd_fusion);
 				scsi_dma_unmap(scmd_local);
 				scmd_local->scsi_done(scmd_local);
-			}
-			atomic_dec(&instance->fw_outstanding);
-
+			} else	/* Optimal VD - R1 FP command completion. */
+				megasas_complete_r1_command(instance, cmd_fusion);
 			break;
 		case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST: /*MFI command */
 			cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
-
 			/* Poll mode. Dummy free.
 			 * In case of Interrupt mode, caller has reverse check.
 			 */
@@ -3896,7 +3786,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason)
 {
 	int retval = SUCCESS, i, j, convert = 0;
 	struct megasas_instance *instance;
-	struct megasas_cmd_fusion *cmd_fusion, *mpt_cmd_fusion;
+	struct megasas_cmd_fusion *cmd_fusion, *r1_cmd;
 	struct fusion_context *fusion;
 	u32 abs_state, status_reg, reset_adapter;
 	u32 io_timeout_in_crash_mode = 0;
@@ -3973,15 +3863,8 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason)
 			cmd_fusion = fusion->cmd_list[i];
 			/*check for extra commands issued by driver*/
 			if (instance->is_ventura) {
-				cmd_fusion->is_raid_1_fp_write = 0;
-				cmd_fusion->cmd_completed = false;
-				mpt_cmd_fusion =
-				fusion->cmd_list[i + instance->max_fw_cmds];
-				mpt_cmd_fusion->is_raid_1_fp_write = 0;
-				mpt_cmd_fusion->cmd_completed = false;
-				if (mpt_cmd_fusion->scmd)
-					megasas_return_cmd_fusion(instance,
-						mpt_cmd_fusion);
+				r1_cmd = fusion->cmd_list[i + instance->max_fw_cmds];
+				megasas_return_cmd_fusion(instance, r1_cmd);
 			}
 			scmd_local = cmd_fusion->scmd;
 			if (cmd_fusion->scmd) {
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
index 82a4ff7..9d9658e 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
@@ -673,6 +673,7 @@ struct MPI2_IOC_INIT_REQUEST {
 
 /* mrpriv defines */
 #define MR_PD_INVALID 0xFFFF
+#define MR_DEVHANDLE_INVALID 0xFFFF
 #define MAX_SPAN_DEPTH 8
 #define MAX_QUAD_DEPTH	MAX_SPAN_DEPTH
 #define MAX_RAIDMAP_SPAN_DEPTH (MAX_SPAN_DEPTH)
@@ -921,7 +922,6 @@ struct IO_REQUEST_INFO {
 	u8  span_arm;	/* span[7:5], arm[4:0] */
 	u8  pd_after_lb;
 	u16 r1_alt_dev_handle; /* raid 1/10 only */
-	bool is_raid_1_fp_write;
 	bool ra_capable;
 };
 
@@ -1060,7 +1060,6 @@ struct megasas_cmd_fusion {
 	u32 index;
 	u8 pd_r1_lb;
 	struct completion done;
-	bool is_raid_1_fp_write;
 	u16 r1_alt_dev_handle; /* raid 1/10 only*/
 	bool cmd_completed;  /* raid 1/10 fp writes status holder */
 
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 04/39] megaraid_sas: 32 bit descriptor fire cmd optimization
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (2 preceding siblings ...)
  2017-02-08  9:28 ` [PATCH v2 03/39] megaraid_sas: raid 1 fast path code optimize Shivasharan S
@ 2017-02-08  9:28 ` Shivasharan S
  2017-02-08 11:15   ` Hannes Reinecke
  2017-02-08  9:28 ` [PATCH v2 05/39] megaraid_sas: Refactor MEGASAS_IS_LOGICAL macro using sdev Shivasharan S
                   ` (34 subsequent siblings)
  38 siblings, 1 reply; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:28 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

No functional change. Code refactor.
megasas_fire_cmd_fusion can always use 32 bit descriptor write for ventura. No need to pass extra flag.
Only IOC INIT required 64 bit Descriptor write.

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 65 +++++++++++++++--------------
 1 file changed, 33 insertions(+), 32 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 7516589..24b72c5 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -188,40 +188,35 @@ inline void megasas_return_cmd_fusion(struct megasas_instance *instance,
 
 /**
  * megasas_fire_cmd_fusion -	Sends command to the FW
+ * @instance:			Adapter soft state
+ * @req_desc:			32bit or 64bit Request descriptor
+ *
+ * Perform PCI Write. Ventura supports 32 bit Descriptor.
+ * Prior to Ventura (12G) MR controller supports 64 bit Descriptor.
  */
+
 static void
 megasas_fire_cmd_fusion(struct megasas_instance *instance,
-	union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc, bool is_32bit)
+		union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc)
 {
-	struct megasas_register_set __iomem *regs = instance->reg_set;
-	unsigned long flags;
-
-	if (is_32bit)
+	if (instance->is_ventura)
 		writel(le32_to_cpu(req_desc->u.low),
-			&(regs)->inbound_single_queue_port);
-	else if (instance->is_ventura) {
+			&instance->reg_set->inbound_single_queue_port);
+	else {
+#if defined(writeq) && defined(CONFIG_64BIT)
+		u64 req_data = (((u64)le32_to_cpu(req_desc->u.high) << 32) |
+				le32_to_cpu(req_desc->u.low));
+
+		writeq(req_data, &instance->reg_set->inbound_low_queue_port);
+#else
+		unsigned long flags;
 		spin_lock_irqsave(&instance->hba_lock, flags);
 		writel(le32_to_cpu(req_desc->u.low),
-			&(regs)->inbound_low_queue_port);
+			&instance->reg_set->inbound_low_queue_port);
 		writel(le32_to_cpu(req_desc->u.high),
-			&(regs)->inbound_high_queue_port);
+			&instance->reg_set->inbound_high_queue_port);
 		mmiowb();
 		spin_unlock_irqrestore(&instance->hba_lock, flags);
-	} else {
-#if defined(writeq) && defined(CONFIG_64BIT)
-	u64 req_data = (((u64)le32_to_cpu(req_desc->u.high) << 32) |
-			le32_to_cpu(req_desc->u.low));
-
-	writeq(req_data, &instance->reg_set->inbound_low_queue_port);
-#else
-
-	spin_lock_irqsave(&instance->hba_lock, flags);
-	writel(le32_to_cpu(req_desc->u.low),
-		&instance->reg_set->inbound_low_queue_port);
-	writel(le32_to_cpu(req_desc->u.high),
-		&instance->reg_set->inbound_high_queue_port);
-	mmiowb();
-	spin_unlock_irqrestore(&instance->hba_lock, flags);
 #endif
 	}
 }
@@ -771,6 +766,7 @@ megasas_ioc_init_fusion(struct megasas_instance *instance)
 	const char *sys_info;
 	MFI_CAPABILITIES *drv_ops;
 	u32 scratch_pad_2;
+	unsigned long flags;
 
 	fusion = instance->ctrl_context;
 
@@ -897,7 +893,14 @@ megasas_ioc_init_fusion(struct megasas_instance *instance)
 			break;
 	}
 
-	megasas_fire_cmd_fusion(instance, &req_desc, false);
+	/* For Ventura also IOC INIT required 64 bit Descriptor write. */
+	spin_lock_irqsave(&instance->hba_lock, flags);
+	writel(le32_to_cpu(req_desc.u.low),
+	       &instance->reg_set->inbound_low_queue_port);
+	writel(le32_to_cpu(req_desc.u.high),
+	       &instance->reg_set->inbound_high_queue_port);
+	mmiowb();
+	spin_unlock_irqrestore(&instance->hba_lock, flags);
 
 	wait_and_poll(instance, cmd, MFI_POLL_TIMEOUT_SECS);
 
@@ -2577,11 +2580,10 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
 	 * Issue the command to the FW
 	 */
 
-	megasas_fire_cmd_fusion(instance, req_desc, instance->is_ventura);
+	megasas_fire_cmd_fusion(instance, req_desc);
 
 	if (r1_cmd)
-		megasas_fire_cmd_fusion(instance, r1_cmd->request_desc,
-				instance->is_ventura);
+		megasas_fire_cmd_fusion(instance, r1_cmd->request_desc);
 
 
 	return 0;
@@ -3001,7 +3003,7 @@ megasas_issue_dcmd_fusion(struct megasas_instance *instance,
 		return DCMD_NOT_FIRED;
 	}
 
-	megasas_fire_cmd_fusion(instance, req_desc, instance->is_ventura);
+	megasas_fire_cmd_fusion(instance, req_desc);
 	return DCMD_SUCCESS;
 }
 
@@ -3294,8 +3296,7 @@ void megasas_refire_mgmt_cmd(struct megasas_instance *instance)
 				cpu_to_le32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO)))
 				&& !(cmd_mfi->flags & DRV_DCMD_SKIP_REFIRE);
 		if (refire_cmd)
-			megasas_fire_cmd_fusion(instance, req_desc,
-				instance->is_ventura);
+			megasas_fire_cmd_fusion(instance, req_desc);
 		else
 			megasas_return_cmd(instance, cmd_mfi);
 	}
@@ -3474,7 +3475,7 @@ megasas_issue_tm(struct megasas_instance *instance, u16 device_handle,
 		mr_request->tmReqFlags.isTMForLD = 1;
 
 	init_completion(&cmd_fusion->done);
-	megasas_fire_cmd_fusion(instance, req_desc, instance->is_ventura);
+	megasas_fire_cmd_fusion(instance, req_desc);
 
 	timeleft = wait_for_completion_timeout(&cmd_fusion->done, 50 * HZ);
 
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 05/39] megaraid_sas: Refactor MEGASAS_IS_LOGICAL macro using sdev
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (3 preceding siblings ...)
  2017-02-08  9:28 ` [PATCH v2 04/39] megaraid_sas: 32 bit descriptor fire cmd optimization Shivasharan S
@ 2017-02-08  9:28 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 06/39] megaraid_sas: RAID map is accessed for SYS PDs when use_seqnum_jbod_fp is not set Shivasharan S
                   ` (33 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:28 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas.h        |  4 ++--
 drivers/scsi/megaraid/megaraid_sas_base.c   | 20 ++++++++++----------
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 12 ++++++------
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index f5c4742..dff877f 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -2301,8 +2301,8 @@ struct megasas_instance_template {
 			    struct megasas_cmd *cmd);
 };
 
-#define MEGASAS_IS_LOGICAL(scp)						\
-	((scp->device->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1)
+#define MEGASAS_IS_LOGICAL(sdev)					\
+	((sdev->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1)
 
 #define MEGASAS_DEV_INDEX(scp)						\
 	(((scp->device->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) +	\
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 3ed876a..6ca49ef 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -1279,7 +1279,7 @@ megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp,
 	u16 flags = 0;
 	struct megasas_pthru_frame *pthru;
 
-	is_logical = MEGASAS_IS_LOGICAL(scp);
+	is_logical = MEGASAS_IS_LOGICAL(scp->device);
 	device_id = MEGASAS_DEV_INDEX(scp);
 	pthru = (struct megasas_pthru_frame *)cmd->frame;
 
@@ -1519,11 +1519,11 @@ inline int megasas_cmd_type(struct scsi_cmnd *cmd)
 	case WRITE_6:
 	case READ_16:
 	case WRITE_16:
-		ret = (MEGASAS_IS_LOGICAL(cmd)) ?
+		ret = (MEGASAS_IS_LOGICAL(cmd->device)) ?
 			READ_WRITE_LDIO : READ_WRITE_SYSPDIO;
 		break;
 	default:
-		ret = (MEGASAS_IS_LOGICAL(cmd)) ?
+		ret = (MEGASAS_IS_LOGICAL(cmd->device)) ?
 			NON_READ_WRITE_LDIO : NON_READ_WRITE_SYSPDIO;
 	}
 	return ret;
@@ -1699,15 +1699,16 @@ megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
 
 	scmd->result = 0;
 
-	if (MEGASAS_IS_LOGICAL(scmd) &&
+	if (MEGASAS_IS_LOGICAL(scmd->device) &&
 	    (scmd->device->id >= instance->fw_supported_vd_count ||
 		scmd->device->lun)) {
 		scmd->result = DID_BAD_TARGET << 16;
 		goto out_done;
 	}
 
-	if ((scmd->cmnd[0] == SYNCHRONIZE_CACHE) && MEGASAS_IS_LOGICAL(scmd) &&
-		(!instance->fw_sync_cache_support)) {
+	if ((scmd->cmnd[0] == SYNCHRONIZE_CACHE) &&
+	    MEGASAS_IS_LOGICAL(scmd->device) &&
+	    (!instance->fw_sync_cache_support)) {
 		scmd->result = DID_OK << 16;
 		goto out_done;
 	}
@@ -1758,7 +1759,7 @@ void megasas_update_sdev_properties(struct scsi_device *sdev)
 	if (!fusion)
 		return;
 
-	if (sdev->channel < MEGASAS_MAX_PD_CHANNELS &&
+	if (!MEGASAS_IS_LOGICAL(sdev) &&
 		instance->use_seqnum_jbod_fp) {
 		pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) +
 			sdev->id;
@@ -1826,8 +1827,7 @@ static int megasas_slave_configure(struct scsi_device *sdev)
 
 	instance = megasas_lookup_instance(sdev->host->host_no);
 	if (instance->pd_list_not_supported) {
-		if (sdev->channel < MEGASAS_MAX_PD_CHANNELS &&
-			sdev->type == TYPE_DISK) {
+		if (!MEGASAS_IS_LOGICAL(sdev) && sdev->type == TYPE_DISK) {
 			pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) +
 				sdev->id;
 			if (instance->pd_list[pd_index].driveState !=
@@ -1854,7 +1854,7 @@ static int megasas_slave_alloc(struct scsi_device *sdev)
 	struct MR_PRIV_DEVICE *mr_device_priv_data;
 
 	instance = megasas_lookup_instance(sdev->host->host_no);
-	if (sdev->channel < MEGASAS_MAX_PD_CHANNELS) {
+	if (!MEGASAS_IS_LOGICAL(sdev)) {
 		/*
 		 * Open the OS scan to the SYSTEM PD
 		 */
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 24b72c5..675afc9 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3581,13 +3581,13 @@ static u16 megasas_get_tm_devhandle(struct scsi_device *sdev)
 	instance = (struct megasas_instance *)sdev->host->hostdata;
 	fusion = instance->ctrl_context;
 
-	if (sdev->channel < MEGASAS_MAX_PD_CHANNELS) {
+	if (!MEGASAS_IS_LOGICAL(sdev)) {
 		if (instance->use_seqnum_jbod_fp) {
-				pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) +
-						sdev->id;
-				pd_sync = (void *)fusion->pd_seq_sync
-						[(instance->pd_seq_map_id - 1) & 1];
-				devhandle = pd_sync->seq[pd_index].devHandle;
+			pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL)
+				    + sdev->id;
+			pd_sync = (void *)fusion->pd_seq_sync
+					[(instance->pd_seq_map_id - 1) & 1];
+			devhandle = pd_sync->seq[pd_index].devHandle;
 		} else
 			sdev_printk(KERN_ERR, sdev, "Firmware expose tmCapable"
 				" without JBOD MAP support from %s %d\n", __func__, __LINE__);
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 06/39] megaraid_sas: RAID map is accessed for SYS PDs when use_seqnum_jbod_fp is not set
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (4 preceding siblings ...)
  2017-02-08  9:28 ` [PATCH v2 05/39] megaraid_sas: Refactor MEGASAS_IS_LOGICAL macro using sdev Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08 11:16   ` Hannes Reinecke
  2017-02-08 14:37   ` Tomas Henzl
  2017-02-08  9:29 ` [PATCH v2 07/39] megaraid_sas: Use DID_REQUEUE Shivasharan S
                   ` (32 subsequent siblings)
  38 siblings, 2 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 6ca49ef..67a205a 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -1756,28 +1756,31 @@ void megasas_update_sdev_properties(struct scsi_device *sdev)
 	fusion = instance->ctrl_context;
 	mr_device_priv_data = sdev->hostdata;
 
-	if (!fusion)
+	if (!fusion || !mr_device_priv_data)
 		return;
 
-	if (!MEGASAS_IS_LOGICAL(sdev) &&
-		instance->use_seqnum_jbod_fp) {
-		pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) +
-			sdev->id;
-		pd_sync = (void *)fusion->pd_seq_sync
-				[(instance->pd_seq_map_id - 1) & 1];
-		mr_device_priv_data->is_tm_capable =
-			pd_sync->seq[pd_index].capability.tmCapable;
-	} else {
+	if (MEGASAS_IS_LOGICAL(sdev)) {
 		device_id = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL)
 					+ sdev->id;
 		local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
 		ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
+		if (ld >= instance->fw_supported_vd_count)
+			return;
 		raid = MR_LdRaidGet(ld, local_map_ptr);
 
 		if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER)
-		blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
+			blk_queue_update_dma_alignment(sdev->request_queue,
+						       0x7);
+
 		mr_device_priv_data->is_tm_capable =
 			raid->capability.tmCapable;
+	} else if (instance->use_seqnum_jbod_fp) {
+		pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) +
+				sdev->id;
+		pd_sync = (void *)fusion->pd_seq_sync
+				[(instance->pd_seq_map_id - 1) & 1];
+		mr_device_priv_data->is_tm_capable =
+				pd_sync->seq[pd_index].capability.tmCapable;
 	}
 }
 
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 07/39] megaraid_sas: Use DID_REQUEUE
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (5 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 06/39] megaraid_sas: RAID map is accessed for SYS PDs when use_seqnum_jbod_fp is not set Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 08/39] megaraid_sas: megasas_get_request_descriptor always return valid desc Shivasharan S
                   ` (31 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Moving to use DID_REQUEUE return type for reliable unconditional retries.
Driver wants unconditional re-queue, so replace DID_RESET with DID_REQUEUE
Discussed below -
https://www.spinics.net/lists/linux-scsi/msg102848.html

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_base.c   | 4 ++--
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 67a205a..80fcdf5 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -1668,7 +1668,7 @@ megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
 	/* Check for an mpio path and adjust behavior */
 	if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) {
 		if (megasas_check_mpio_paths(instance, scmd) ==
-		    (DID_RESET << 16)) {
+		    (DID_REQUEUE << 16)) {
 			return SCSI_MLQUEUE_HOST_BUSY;
 		} else {
 			scmd->result = DID_NO_CONNECT << 16;
@@ -2492,7 +2492,7 @@ static int megasas_wait_for_outstanding(struct megasas_instance *instance)
 						struct megasas_cmd, list);
 			list_del_init(&reset_cmd->list);
 			if (reset_cmd->scmd) {
-				reset_cmd->scmd->result = DID_RESET << 16;
+				reset_cmd->scmd->result = DID_REQUEUE << 16;
 				dev_notice(&instance->pdev->dev, "%d:%p reset [%02x]\n",
 					reset_index, reset_cmd,
 					reset_cmd->scmd->cmnd[0]);
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 675afc9..6ec7a18 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3770,7 +3770,7 @@ int megasas_check_mpio_paths(struct megasas_instance *instance,
 	struct scsi_cmnd *scmd)
 {
 	struct megasas_instance *peer_instance = NULL;
-	int retval = (DID_RESET << 16);
+	int retval = (DID_REQUEUE << 16);
 
 	if (instance->peerIsPresent) {
 		peer_instance = megasas_get_peer_instance(instance);
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 08/39] megaraid_sas: megasas_get_request_descriptor always return valid desc
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (6 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 07/39] megaraid_sas: Use DID_REQUEUE Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08 11:17   ` Hannes Reinecke
                     ` (2 more replies)
  2017-02-08  9:29 ` [PATCH v2 09/39] megaraid_sas: change issue_dcmd to return void from int Shivasharan S
                   ` (30 subsequent siblings)
  38 siblings, 3 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

fix in v2 - split patches into two. 
discussed below 
http://marc.info/?l=linux-scsi&m=148638999110404&w=2

No functional change. Code clean up. Removing error code which is not
valid scenario.
In megasas_get_request_descriptor we can remove the error handling
which is not required.
With fusion controllers, if there is a valid message frame available,
we are guaranteed to get a corresponding request descriptor.

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 24 ++----------------------
 1 file changed, 2 insertions(+), 22 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 6ec7a18..b6c5dc5 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -2438,18 +2438,12 @@ megasas_build_io_fusion(struct megasas_instance *instance,
 	return 0;
 }
 
-union MEGASAS_REQUEST_DESCRIPTOR_UNION *
+static union MEGASAS_REQUEST_DESCRIPTOR_UNION *
 megasas_get_request_descriptor(struct megasas_instance *instance, u16 index)
 {
 	u8 *p;
 	struct fusion_context *fusion;
 
-	if (index >= instance->max_mpt_cmds) {
-		dev_err(&instance->pdev->dev, "Invalid SMID (0x%x)request for "
-		       "descriptor for scsi%d\n", index,
-			instance->host->host_no);
-		return NULL;
-	}
 	fusion = instance->ctrl_context;
 	p = fusion->req_frames_desc +
 		sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) * index;
@@ -2960,7 +2954,7 @@ build_mpt_mfi_pass_thru(struct megasas_instance *instance,
 union MEGASAS_REQUEST_DESCRIPTOR_UNION *
 build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
 {
-	union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
+	union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc = NULL;
 	u16 index;
 
 	if (build_mpt_mfi_pass_thru(instance, cmd)) {
@@ -2972,9 +2966,6 @@ build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
 
 	req_desc = megasas_get_request_descriptor(instance, index - 1);
 
-	if (!req_desc)
-		return NULL;
-
 	req_desc->Words = 0;
 	req_desc->SCSIIO.RequestFlags = (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
 					 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
@@ -2997,11 +2988,6 @@ megasas_issue_dcmd_fusion(struct megasas_instance *instance,
 	union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
 
 	req_desc = build_mpt_cmd(instance, cmd);
-	if (!req_desc) {
-		dev_info(&instance->pdev->dev, "Failed from %s %d\n",
-					__func__, __LINE__);
-		return DCMD_NOT_FIRED;
-	}
 
 	megasas_fire_cmd_fusion(instance, req_desc);
 	return DCMD_SUCCESS;
@@ -3438,12 +3424,6 @@ megasas_issue_tm(struct megasas_instance *instance, u16 device_handle,
 
 	req_desc = megasas_get_request_descriptor(instance,
 			(cmd_fusion->index - 1));
-	if (!req_desc) {
-		dev_err(&instance->pdev->dev, "Failed from %s %d\n",
-			__func__, __LINE__);
-		megasas_return_cmd(instance, cmd_mfi);
-		return -ENOMEM;
-	}
 
 	cmd_fusion->request_desc = req_desc;
 	req_desc->Words = 0;
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 09/39] megaraid_sas: change issue_dcmd to return void from int
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (7 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 08/39] megaraid_sas: megasas_get_request_descriptor always return valid desc Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08 11:17   ` Hannes Reinecke
  2017-02-08 14:40   ` Tomas Henzl
  2017-02-08  9:29 ` [PATCH v2 10/39] megaraid_sas: NVME Interface detection and prop settings Shivasharan S
                   ` (29 subsequent siblings)
  38 siblings, 2 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

fix in v2 : 
1. split patches into two as discussed below 
http://marc.info/?l=linux-scsi&m=148638999110404&w=2
2. issue_dcmd return type changed from int to void.


With the changes to remove checks for a valid request descriptor,
issue_dcmd will now always return DCMD_SUCCESS. This patch changes
return type of issue_dcmd to void and change all callers
appropriately.

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
---
 drivers/scsi/megaraid/megaraid_sas.h        |  2 +-
 drivers/scsi/megaraid/megaraid_sas_base.c   | 19 +++++++++++--------
 drivers/scsi/megaraid/megaraid_sas_fusion.c |  8 ++++----
 3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index dff877f..d9049d5 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -2297,7 +2297,7 @@ struct megasas_instance_template {
 	u32 (*init_adapter)(struct megasas_instance *);
 	u32 (*build_and_issue_cmd) (struct megasas_instance *,
 				    struct scsi_cmnd *);
-	int (*issue_dcmd)(struct megasas_instance *instance,
+	void (*issue_dcmd)(struct megasas_instance *instance,
 			    struct megasas_cmd *cmd);
 };
 
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 80fcdf5..23fb78a 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -202,12 +202,12 @@ void megasas_fusion_ocr_wq(struct work_struct *work);
 static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance,
 					 int initial);
 
-int
+void
 megasas_issue_dcmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
 {
 	instance->instancet->fire_cmd(instance,
 		cmd->frame_phys_addr, 0, instance->reg_set);
-	return 0;
+	return;
 }
 
 /**
@@ -995,13 +995,14 @@ megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd)
 	frame_hdr->cmd_status = MFI_STAT_INVALID_STATUS;
 	frame_hdr->flags |= cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE);
 
-	if ((atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) ||
-		(instance->instancet->issue_dcmd(instance, cmd))) {
+	if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) {
 		dev_err(&instance->pdev->dev, "Failed from %s %d\n",
 			__func__, __LINE__);
 		return DCMD_NOT_FIRED;
 	}
 
+	instance->instancet->issue_dcmd(instance, cmd);
+
 	return wait_and_poll(instance, cmd, instance->requestorId ?
 			MEGASAS_ROUTINE_WAIT_TIME_VF : MFI_IO_TIMEOUT_SECS);
 }
@@ -1023,13 +1024,14 @@ megasas_issue_blocked_cmd(struct megasas_instance *instance,
 	int ret = 0;
 	cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS;
 
-	if ((atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) ||
-		(instance->instancet->issue_dcmd(instance, cmd))) {
+	if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) {
 		dev_err(&instance->pdev->dev, "Failed from %s %d\n",
 			__func__, __LINE__);
 		return DCMD_NOT_FIRED;
 	}
 
+	instance->instancet->issue_dcmd(instance, cmd);
+
 	if (timeout) {
 		ret = wait_event_timeout(instance->int_cmd_wait_q,
 				cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ);
@@ -1087,13 +1089,14 @@ megasas_issue_blocked_abort_cmd(struct megasas_instance *instance,
 	cmd->sync_cmd = 1;
 	cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS;
 
-	if ((atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) ||
-		(instance->instancet->issue_dcmd(instance, cmd))) {
+	if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) {
 		dev_err(&instance->pdev->dev, "Failed from %s %d\n",
 			__func__, __LINE__);
 		return DCMD_NOT_FIRED;
 	}
 
+	instance->instancet->issue_dcmd(instance, cmd);
+
 	if (timeout) {
 		ret = wait_event_timeout(instance->abort_cmd_wait_q,
 				cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ);
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index b6c5dc5..c38fde0 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1115,7 +1115,7 @@ megasas_get_map_info(struct megasas_instance *instance)
 int
 megasas_sync_map_info(struct megasas_instance *instance)
 {
-	int ret = 0, i;
+	int i;
 	struct megasas_cmd *cmd;
 	struct megasas_dcmd_frame *dcmd;
 	u32 size_sync_info, num_lds;
@@ -1184,7 +1184,7 @@ megasas_sync_map_info(struct megasas_instance *instance)
 
 	instance->instancet->issue_dcmd(instance, cmd);
 
-	return ret;
+	return 0;
 }
 
 /*
@@ -2981,7 +2981,7 @@ build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
  * @cmd:			mfi cmd pointer
  *
  */
-int
+void
 megasas_issue_dcmd_fusion(struct megasas_instance *instance,
 			  struct megasas_cmd *cmd)
 {
@@ -2990,7 +2990,7 @@ megasas_issue_dcmd_fusion(struct megasas_instance *instance,
 	req_desc = build_mpt_cmd(instance, cmd);
 
 	megasas_fire_cmd_fusion(instance, req_desc);
-	return DCMD_SUCCESS;
+	return;
 }
 
 /**
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 10/39] megaraid_sas: NVME Interface detection and prop settings
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (8 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 09/39] megaraid_sas: change issue_dcmd to return void from int Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08 11:59   ` Hannes Reinecke
  2017-02-08 14:48   ` Tomas Henzl
  2017-02-08  9:29 ` [PATCH v2 11/39] megaraid_sas: NVME interface target prop added Shivasharan S
                   ` (28 subsequent siblings)
  38 siblings, 2 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

New functionality
Adding detection logic for NVME device attached behind Ventura controller.
Driver set HostPageSize in IOC_INIT frame to inform about page size for NVME devices.
Firmware reports NVME page size to the driver.
PD INFO DCMD provide new interface type NVME_PD. Driver set property of NVME device.

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
---
 drivers/scsi/megaraid/megaraid_sas.h        |  23 ++--
 drivers/scsi/megaraid/megaraid_sas_base.c   | 170 ++++++++++++++++++++--------
 drivers/scsi/megaraid/megaraid_sas_fusion.c |   6 +-
 drivers/scsi/megaraid/megaraid_sas_fusion.h |   2 +-
 4 files changed, 142 insertions(+), 59 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index d9049d5..f9efddf 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -733,7 +733,6 @@ struct megasas_pd_list {
 	u16             tid;
 	u8             driveType;
 	u8             driveState;
-	u8             interface;
 } __packed;
 
  /*
@@ -1530,8 +1529,8 @@ struct megasas_register_set {
 	u32 	outbound_scratch_pad ;		/*00B0h*/
 	u32	outbound_scratch_pad_2;         /*00B4h*/
 	u32	outbound_scratch_pad_3;         /*00B8h*/
+	u32	outbound_scratch_pad_4;         /*00BCh*/
 
-	u32	reserved_4;			/*00BCh*/
 
 	u32 	inbound_low_queue_port ;	/*00C0h*/
 
@@ -1864,6 +1863,7 @@ union megasas_frame {
 struct MR_PRIV_DEVICE {
 	bool is_tm_capable;
 	bool tm_busy;
+	u8   interface_type;
 };
 struct megasas_cmd;
 
@@ -2055,17 +2055,24 @@ struct MR_DRV_SYSTEM_INFO {
 };
 
 enum MR_PD_TYPE {
-		 UNKNOWN_DRIVE = 0,
-		 PARALLEL_SCSI = 1,
-		 SAS_PD = 2,
-		 SATA_PD = 3,
-		 FC_PD = 4,
+	UNKNOWN_DRIVE = 0,
+	PARALLEL_SCSI = 1,
+	SAS_PD = 2,
+	SATA_PD = 3,
+	FC_PD = 4,
+	NVME_PD = 5,
 };
 
 /* JBOD Queue depth definitions */
 #define MEGASAS_SATA_QD	32
 #define MEGASAS_SAS_QD	64
 #define MEGASAS_DEFAULT_PD_QD	64
+#define MEGASAS_NVME_QD		32
+
+#define MR_DEFAULT_NVME_PAGE_SIZE	4096
+#define MR_DEFAULT_NVME_PAGE_SHIFT	12
+#define MR_DEFAULT_NVME_MDTS_KB		128
+#define MR_NVME_PAGE_SIZE_MASK		0x000000FF
 
 struct megasas_instance {
 
@@ -2209,6 +2216,7 @@ struct megasas_instance {
 	bool is_ventura;
 	bool msix_combined;
 	u16 max_raid_mapsize;
+	u32 nvme_page_size;
 };
 struct MR_LD_VF_MAP {
 	u32 size;
@@ -2428,6 +2436,7 @@ int megasas_get_ctrl_info(struct megasas_instance *instance);
 /* PD sequence */
 int
 megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend);
+void megasas_set_dynamic_target_properties(struct scsi_device *sdev);
 int megasas_set_crash_dump_params(struct megasas_instance *instance,
 	u8 crash_buf_state);
 void megasas_free_host_crash_buffer(struct megasas_instance *instance);
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 23fb78a..f383bf2 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -116,8 +116,8 @@ static int megasas_ld_list_query(struct megasas_instance *instance,
 static int megasas_issue_init_mfi(struct megasas_instance *instance);
 static int megasas_register_aen(struct megasas_instance *instance,
 				u32 seq_num, u32 class_locale_word);
-static int
-megasas_get_pd_info(struct megasas_instance *instance, u16 device_id);
+static void megasas_get_pd_info(struct megasas_instance *instance,
+				struct scsi_device *sdev);
 /*
  * PCI ID table for all supported controllers
  */
@@ -1738,16 +1738,21 @@ static struct megasas_instance *megasas_lookup_instance(u16 host_no)
 }
 
 /*
-* megasas_update_sdev_properties - Update sdev structure based on controller's FW capabilities
+* megasas_set_dynamic_target_properties -
+* Device property set by driver may not be static and it is required to be
+* updated after OCR
+*
+* set tm_capable.
+* set dma alignment (only for eedp protection enable vd).
 *
 * @sdev: OS provided scsi device
 *
 * Returns void
 */
-void megasas_update_sdev_properties(struct scsi_device *sdev)
+void megasas_set_dynamic_target_properties(struct scsi_device *sdev)
 {
-	u16 pd_index = 0;
-	u32 device_id, ld;
+	u16 pd_index = 0, ld;
+	u32 device_id;
 	struct megasas_instance *instance;
 	struct fusion_context *fusion;
 	struct MR_PRIV_DEVICE *mr_device_priv_data;
@@ -1772,57 +1777,102 @@ void megasas_update_sdev_properties(struct scsi_device *sdev)
 		raid = MR_LdRaidGet(ld, local_map_ptr);
 
 		if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER)
-			blk_queue_update_dma_alignment(sdev->request_queue,
-						       0x7);
+		blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
 
 		mr_device_priv_data->is_tm_capable =
 			raid->capability.tmCapable;
 	} else if (instance->use_seqnum_jbod_fp) {
 		pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) +
-				sdev->id;
+			sdev->id;
 		pd_sync = (void *)fusion->pd_seq_sync
 				[(instance->pd_seq_map_id - 1) & 1];
 		mr_device_priv_data->is_tm_capable =
-				pd_sync->seq[pd_index].capability.tmCapable;
+			pd_sync->seq[pd_index].capability.tmCapable;
 	}
 }
 
-static void megasas_set_device_queue_depth(struct scsi_device *sdev)
+/*
+ * megasas_set_nvme_device_properties -
+ * set nomerges=2
+ * set virtual page boundary = 4K (current mr_nvme_pg_size is 4K).
+ * set maximum io transfer = MDTS of NVME device provided by MR firmware.
+ *
+ * MR firmware provides value in KB. Caller of this function converts
+ * kb into bytes.
+ *
+ * e.a MDTS=5 means 2^5 * nvme page size. (In case of 4K page size,
+ * MR firmware provides value 128 as (32 * 4K) = 128K.
+ *
+ * @sdev:				scsi device
+ * @max_io_size:				maximum io transfer size
+ *
+ */
+static inline void
+megasas_set_nvme_device_properties(struct scsi_device *sdev, u32 max_io_size)
 {
-	u16				pd_index = 0;
-	int		ret = DCMD_FAILED;
 	struct megasas_instance *instance;
+	u32 mr_nvme_pg_size;
 
-	instance = megasas_lookup_instance(sdev->host->host_no);
+	instance = (struct megasas_instance *)sdev->host->hostdata;
+	mr_nvme_pg_size = max_t(u32, instance->nvme_page_size,
+				MR_DEFAULT_NVME_PAGE_SIZE);
 
-	if (sdev->channel < MEGASAS_MAX_PD_CHANNELS) {
-		pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id;
+	blk_queue_max_hw_sectors(sdev->request_queue, (max_io_size / 512));
 
-		if (instance->pd_info) {
-			mutex_lock(&instance->hba_mutex);
-			ret = megasas_get_pd_info(instance, pd_index);
-			mutex_unlock(&instance->hba_mutex);
-		}
+	queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, sdev->request_queue);
+	blk_queue_virt_boundary(sdev->request_queue, mr_nvme_pg_size - 1);
+}
 
-		if (ret != DCMD_SUCCESS)
-			return;
 
-		if (instance->pd_list[pd_index].driveState == MR_PD_STATE_SYSTEM) {
+/*
+ * megasas_set_static_target_properties -
+ * Device property set by driver are static and it is not required to be
+ * updated after OCR.
+ *
+ * set io timeout
+ * set device queue depth
+ * set nvme device properties. see - megasas_set_nvme_device_properties
+ *
+ * @sdev:				scsi device
+ *
+ */
+static void megasas_set_static_target_properties(struct scsi_device *sdev)
+{
+	u16	target_index = 0;
+	u8 interface_type;
+	u32 device_qd = MEGASAS_DEFAULT_CMD_PER_LUN;
+	u32 max_io_size_kb = MR_DEFAULT_NVME_MDTS_KB;
+	struct megasas_instance *instance;
+	struct MR_PRIV_DEVICE *mr_device_priv_data;
 
-			switch (instance->pd_list[pd_index].interface) {
-			case SAS_PD:
-				scsi_change_queue_depth(sdev, MEGASAS_SAS_QD);
-				break;
+	instance = megasas_lookup_instance(sdev->host->host_no);
+	mr_device_priv_data = sdev->hostdata;
+	interface_type  = mr_device_priv_data->interface_type;
 
-			case SATA_PD:
-				scsi_change_queue_depth(sdev, MEGASAS_SATA_QD);
-				break;
+	/*
+	 * The RAID firmware may require extended timeouts.
+	 */
+	blk_queue_rq_timeout(sdev->request_queue, scmd_timeout * HZ);
 
-			default:
-				scsi_change_queue_depth(sdev, MEGASAS_DEFAULT_PD_QD);
-			}
-		}
+	target_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id;
+
+	switch (interface_type) {
+	case SAS_PD:
+		device_qd = MEGASAS_SAS_QD;
+		break;
+	case SATA_PD:
+		device_qd = MEGASAS_SATA_QD;
+		break;
+	case NVME_PD:
+		device_qd = MEGASAS_NVME_QD;
+		break;
 	}
+
+	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);
+
 }
 
 
@@ -1841,14 +1891,18 @@ static int megasas_slave_configure(struct scsi_device *sdev)
 				return -ENXIO;
 		}
 	}
-	megasas_set_device_queue_depth(sdev);
-	megasas_update_sdev_properties(sdev);
 
-	/*
-	 * The RAID firmware may require extended timeouts.
-	 */
-	blk_queue_rq_timeout(sdev->request_queue,
-		scmd_timeout * HZ);
+	mutex_lock(&instance->hba_mutex);
+	/* Send DCMD to Firmware and cache the information */
+	if ((instance->pd_info) && !MEGASAS_IS_LOGICAL(sdev))
+		megasas_get_pd_info(instance, sdev);
+
+	megasas_set_static_target_properties(sdev);
+
+	mutex_unlock(&instance->hba_mutex);
+
+	/* This sdev property may change post OCR */
+	megasas_set_dynamic_target_properties(sdev);
 
 	return 0;
 }
@@ -3986,18 +4040,22 @@ dcmd_timeout_ocr_possible(struct megasas_instance *instance) {
 		return INITIATE_OCR;
 }
 
-static int
-megasas_get_pd_info(struct megasas_instance *instance, u16 device_id)
+static void
+megasas_get_pd_info(struct megasas_instance *instance, struct scsi_device *sdev)
 {
 	int ret;
 	struct megasas_cmd *cmd;
 	struct megasas_dcmd_frame *dcmd;
 
+	struct MR_PRIV_DEVICE *mr_device_priv_data;
+	u16 device_id = 0;
+
+	device_id = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id;
 	cmd = megasas_get_cmd(instance);
 
 	if (!cmd) {
 		dev_err(&instance->pdev->dev, "Failed to get cmd %s\n", __func__);
-		return -ENOMEM;
+		return;
 	}
 
 	dcmd = &cmd->frame->dcmd;
@@ -4024,7 +4082,9 @@ megasas_get_pd_info(struct megasas_instance *instance, u16 device_id)
 
 	switch (ret) {
 	case DCMD_SUCCESS:
-		instance->pd_list[device_id].interface =
+		mr_device_priv_data = sdev->hostdata;
+		le16_to_cpus((u16 *)&instance->pd_info->state.ddf.pdType);
+		mr_device_priv_data->interface_type =
 				instance->pd_info->state.ddf.pdType.intf;
 		break;
 
@@ -4051,7 +4111,7 @@ megasas_get_pd_info(struct megasas_instance *instance, u16 device_id)
 	if (ret != DCMD_TIMEOUT)
 		megasas_return_cmd(instance, cmd);
 
-	return ret;
+	return;
 }
 /*
  * megasas_get_pd_list_info -	Returns FW's pd_list structure
@@ -5020,8 +5080,8 @@ megasas_setup_jbod_map(struct megasas_instance *instance)
 static int megasas_init_fw(struct megasas_instance *instance)
 {
 	u32 max_sectors_1;
-	u32 max_sectors_2;
-	u32 tmp_sectors, msix_enable, scratch_pad_2, scratch_pad_3;
+	u32 max_sectors_2, tmp_sectors, msix_enable;
+	u32 scratch_pad_2, scratch_pad_3, scratch_pad_4;
 	resource_size_t base_addr;
 	struct megasas_register_set __iomem *reg_set;
 	struct megasas_ctrl_info *ctrl_info = NULL;
@@ -5202,6 +5262,18 @@ static int megasas_init_fw(struct megasas_instance *instance)
 	if (instance->instancet->init_adapter(instance))
 		goto fail_init_adapter;
 
+	if (instance->is_ventura) {
+		scratch_pad_4 =
+			readl(&instance->reg_set->outbound_scratch_pad_4);
+		if ((scratch_pad_4 & MR_NVME_PAGE_SIZE_MASK) >=
+			MR_DEFAULT_NVME_PAGE_SHIFT)
+			instance->nvme_page_size =
+				(1 << (scratch_pad_4 & MR_NVME_PAGE_SIZE_MASK));
+
+		dev_info(&instance->pdev->dev,
+			 "NVME page size\t: (%d)\n", instance->nvme_page_size);
+	}
+
 	if (instance->msix_vectors ?
 		megasas_setup_irqs_msix(instance, 1) :
 		megasas_setup_irqs_ioapic(instance))
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index c38fde0..a481854 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -376,7 +376,8 @@ static int megasas_create_sg_sense_fusion(struct megasas_instance *instance)
 
 	fusion->sg_dma_pool =
 			pci_pool_create("mr_sg", instance->pdev,
-				instance->max_chain_frame_sz, 4, 0);
+				instance->max_chain_frame_sz,
+				MR_DEFAULT_NVME_PAGE_SIZE, 0);
 	/* SCSI_SENSE_BUFFERSIZE  = 96 bytes */
 	fusion->sense_dma_pool =
 			pci_pool_create("mr_sense", instance->pdev,
@@ -823,6 +824,7 @@ megasas_ioc_init_fusion(struct megasas_instance *instance)
 			MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE : 0;
 	IOCInitMessage->SystemRequestFrameBaseAddress = cpu_to_le64(fusion->io_request_frames_phys);
 	IOCInitMessage->HostMSIxVectors = instance->msix_vectors;
+	IOCInitMessage->HostPageSize = MR_DEFAULT_NVME_PAGE_SHIFT;
 	init_frame = (struct megasas_init_frame *)cmd->frame;
 	memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
 
@@ -3935,7 +3937,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason)
 			megasas_setup_jbod_map(instance);
 
 			shost_for_each_device(sdev, shost)
-				megasas_update_sdev_properties(sdev);
+				megasas_set_dynamic_target_properties(sdev);
 
 			/* reset stream detection array */
 			if (instance->is_ventura) {
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
index 9d9658e..9f19f00 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
@@ -657,7 +657,7 @@ struct MPI2_IOC_INIT_REQUEST {
 	__le16			HeaderVersion;                  /* 0x0E */
 	u32                     Reserved5;                      /* 0x10 */
 	__le16			Reserved6;                      /* 0x14 */
-	u8                      Reserved7;                      /* 0x16 */
+	u8                      HostPageSize;                   /* 0x16 */
 	u8                      HostMSIxVectors;                /* 0x17 */
 	__le16			Reserved8;                      /* 0x18 */
 	__le16			SystemRequestFrameSize;         /* 0x1A */
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 11/39] megaraid_sas: NVME interface target prop added
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (9 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 10/39] megaraid_sas: NVME Interface detection and prop settings Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 12/39] megaraid_sas: NVME fast path io support Shivasharan S
                   ` (27 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

This patch fetch true values of NVME property from FW using New DCMD interface MR_DCMD_DEV_GET_TARGET_PROP

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas.h        |  14 +++
 drivers/scsi/megaraid/megaraid_sas_base.c   | 144 +++++++++++++++++++++++++++-
 drivers/scsi/megaraid/megaraid_sas_fusion.h |   1 +
 3 files changed, 155 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index f9efddf..a45ff10 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -695,6 +695,18 @@ struct  MR_PD_INFO {
 	u8 reserved1[512-428];
 } __packed;
 
+/*
+ * Definition of structure used to expose attributes of VD or JBOD
+ * (this structure is to be filled by firmware when MR_DCMD_DRV_GET_TARGET_PROP
+ * is fired by driver)
+ */
+struct MR_TARGET_PROPERTIES {
+	u32    max_io_size_kb;
+	u32    device_qdepth;
+	u32    sector_size;
+	u8     reserved[500];
+} __packed;
+
  /*
  * defines the physical drive address structure
  */
@@ -2090,6 +2102,8 @@ struct megasas_instance {
 	dma_addr_t hb_host_mem_h;
 	struct MR_PD_INFO *pd_info;
 	dma_addr_t pd_info_h;
+	struct MR_TARGET_PROPERTIES *tgt_prop;
+	dma_addr_t tgt_prop_h;
 
 	__le32 *reply_queue;
 	dma_addr_t reply_queue_h;
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index f383bf2..51b35a6 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -118,6 +118,8 @@ static int megasas_register_aen(struct megasas_instance *instance,
 				u32 seq_num, u32 class_locale_word);
 static void megasas_get_pd_info(struct megasas_instance *instance,
 				struct scsi_device *sdev);
+static int megasas_get_target_prop(struct megasas_instance *instance,
+				   struct scsi_device *sdev);
 /*
  * PCI ID table for all supported controllers
  */
@@ -1834,14 +1836,16 @@ megasas_set_nvme_device_properties(struct scsi_device *sdev, u32 max_io_size)
  * set nvme device properties. see - megasas_set_nvme_device_properties
  *
  * @sdev:				scsi device
- *
+ * @is_target_prop			true, if fw provided target properties.
  */
-static void megasas_set_static_target_properties(struct scsi_device *sdev)
+static void megasas_set_static_target_properties(struct scsi_device *sdev,
+						 bool is_target_prop)
 {
 	u16	target_index = 0;
 	u8 interface_type;
 	u32 device_qd = MEGASAS_DEFAULT_CMD_PER_LUN;
 	u32 max_io_size_kb = MR_DEFAULT_NVME_MDTS_KB;
+	u32 tgt_device_qd;
 	struct megasas_instance *instance;
 	struct MR_PRIV_DEVICE *mr_device_priv_data;
 
@@ -1868,6 +1872,18 @@ static void megasas_set_static_target_properties(struct scsi_device *sdev)
 		break;
 	}
 
+	if (is_target_prop) {
+		tgt_device_qd = le32_to_cpu(instance->tgt_prop->device_qdepth);
+		if (tgt_device_qd &&
+		    (tgt_device_qd <= instance->host->can_queue))
+			device_qd = tgt_device_qd;
+
+		/* max_io_size_kb will be set to non zero for
+		 * nvme based vd and syspd.
+		 */
+		max_io_size_kb = le32_to_cpu(instance->tgt_prop->max_io_size_kb);
+	}
+
 	if (instance->nvme_page_size && max_io_size_kb)
 		megasas_set_nvme_device_properties(sdev, (max_io_size_kb << 10));
 
@@ -1880,6 +1896,8 @@ static int megasas_slave_configure(struct scsi_device *sdev)
 {
 	u16 pd_index = 0;
 	struct megasas_instance *instance;
+	int ret_target_prop = DCMD_FAILED;
+	bool is_target_prop = false;
 
 	instance = megasas_lookup_instance(sdev->host->host_no);
 	if (instance->pd_list_not_supported) {
@@ -1897,7 +1915,14 @@ static int megasas_slave_configure(struct scsi_device *sdev)
 	if ((instance->pd_info) && !MEGASAS_IS_LOGICAL(sdev))
 		megasas_get_pd_info(instance, sdev);
 
-	megasas_set_static_target_properties(sdev);
+	/* Some ventura firmware may not have instance->nvme_page_size set.
+	 * Do not send MR_DCMD_DRV_GET_TARGET_PROP
+	 */
+	if ((instance->tgt_prop) && (instance->nvme_page_size))
+		ret_target_prop = megasas_get_target_prop(instance, sdev);
+
+	is_target_prop = (ret_target_prop == DCMD_SUCCESS) ? true : false;
+	megasas_set_static_target_properties(sdev, is_target_prop);
 
 	mutex_unlock(&instance->hba_mutex);
 
@@ -5682,6 +5707,98 @@ megasas_register_aen(struct megasas_instance *instance, u32 seq_num,
 	return 0;
 }
 
+/* megasas_get_target_prop - Send DCMD with below details to firmware.
+ *
+ * This DCMD will fetch few properties of LD/system PD defined
+ * in MR_TARGET_DEV_PROPERTIES. eg. Queue Depth, MDTS value.
+ *
+ * DCMD send by drivers whenever new target is added to the OS.
+ *
+ * dcmd.opcode         - MR_DCMD_DEV_GET_TARGET_PROP
+ * dcmd.mbox.b[0]      - DCMD is to be fired for LD or system PD.
+ *                       0 = system PD, 1 = LD.
+ * dcmd.mbox.s[1]      - TargetID for LD/system PD.
+ * dcmd.sge IN         - Pointer to return MR_TARGET_DEV_PROPERTIES.
+ *
+ * @instance:		Adapter soft state
+ * @sdev:		OS provided scsi device
+ *
+ * Returns 0 on success non-zero on failure.
+ */
+static int
+megasas_get_target_prop(struct megasas_instance *instance,
+			struct scsi_device *sdev)
+{
+	int ret;
+	struct megasas_cmd *cmd;
+	struct megasas_dcmd_frame *dcmd;
+	u16 targetId = (sdev->channel % 2) + sdev->id;
+
+	cmd = megasas_get_cmd(instance);
+
+	if (!cmd) {
+		dev_err(&instance->pdev->dev,
+			"Failed to get cmd %s\n", __func__);
+		return -ENOMEM;
+	}
+
+	dcmd = &cmd->frame->dcmd;
+
+	memset(instance->tgt_prop, 0, sizeof(*instance->tgt_prop));
+	memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
+	dcmd->mbox.b[0] = MEGASAS_IS_LOGICAL(sdev);
+
+	dcmd->mbox.s[1] = cpu_to_le16(targetId);
+	dcmd->cmd = MFI_CMD_DCMD;
+	dcmd->cmd_status = 0xFF;
+	dcmd->sge_count = 1;
+	dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ);
+	dcmd->timeout = 0;
+	dcmd->pad_0 = 0;
+	dcmd->data_xfer_len =
+		cpu_to_le32(sizeof(struct MR_TARGET_PROPERTIES));
+	dcmd->opcode = cpu_to_le32(MR_DCMD_DRV_GET_TARGET_PROP);
+	dcmd->sgl.sge32[0].phys_addr =
+		cpu_to_le32(instance->tgt_prop_h);
+	dcmd->sgl.sge32[0].length =
+		cpu_to_le32(sizeof(struct MR_TARGET_PROPERTIES));
+
+	if (instance->ctrl_context && !instance->mask_interrupts)
+		ret = megasas_issue_blocked_cmd(instance,
+						cmd, MFI_IO_TIMEOUT_SECS);
+	else
+		ret = megasas_issue_polled(instance, cmd);
+
+	switch (ret) {
+	case DCMD_TIMEOUT:
+		switch (dcmd_timeout_ocr_possible(instance)) {
+		case INITIATE_OCR:
+			cmd->flags |= DRV_DCMD_SKIP_REFIRE;
+			megasas_reset_fusion(instance->host,
+					     MFI_IO_TIMEOUT_OCR);
+			break;
+		case KILL_ADAPTER:
+			megaraid_sas_kill_hba(instance);
+			break;
+		case IGNORE_TIMEOUT:
+			dev_info(&instance->pdev->dev,
+				 "Ignore DCMD timeout: %s %d\n",
+				 __func__, __LINE__);
+			break;
+		}
+		break;
+
+	default:
+		megasas_return_cmd(instance, cmd);
+	}
+	if (ret != DCMD_SUCCESS)
+		dev_err(&instance->pdev->dev,
+			"return from %s %d return value %d\n",
+			__func__, __LINE__, ret);
+
+	return ret;
+}
+
 /**
  * megasas_start_aen -	Subscribes to AEN during driver load time
  * @instance:		Adapter soft state
@@ -5958,9 +6075,17 @@ static int megasas_probe_one(struct pci_dev *pdev,
 		instance->pd_info = pci_alloc_consistent(pdev,
 			sizeof(struct MR_PD_INFO), &instance->pd_info_h);
 
+		instance->pd_info = pci_alloc_consistent(pdev,
+			sizeof(struct MR_PD_INFO), &instance->pd_info_h);
+		instance->tgt_prop = pci_alloc_consistent(pdev,
+			sizeof(struct MR_TARGET_PROPERTIES), &instance->tgt_prop_h);
+
 		if (!instance->pd_info)
 			dev_err(&instance->pdev->dev, "Failed to alloc mem for pd_info\n");
 
+		if (!instance->tgt_prop)
+			dev_err(&instance->pdev->dev, "Failed to alloc mem for tgt_prop\n");
+
 		instance->crash_dump_buf = pci_alloc_consistent(pdev,
 						CRASH_DMA_BUF_SIZE,
 						&instance->crash_dump_h);
@@ -6105,6 +6230,10 @@ static int megasas_probe_one(struct pci_dev *pdev,
 		pci_free_consistent(pdev, sizeof(struct MR_PD_INFO),
 					instance->pd_info,
 					instance->pd_info_h);
+	if (instance->tgt_prop)
+		pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES),
+					instance->tgt_prop,
+					instance->tgt_prop_h);
 	if (instance->producer)
 		pci_free_consistent(pdev, sizeof(u32), instance->producer,
 				    instance->producer_h);
@@ -6377,6 +6506,10 @@ megasas_resume(struct pci_dev *pdev)
 		pci_free_consistent(pdev, sizeof(struct MR_PD_INFO),
 					instance->pd_info,
 					instance->pd_info_h);
+	if (instance->tgt_prop)
+		pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES),
+					instance->tgt_prop,
+					instance->tgt_prop_h);
 	if (instance->producer)
 		pci_free_consistent(pdev, sizeof(u32), instance->producer,
 				instance->producer_h);
@@ -6535,11 +6668,14 @@ static void megasas_detach_one(struct pci_dev *pdev)
 	if (instance->evt_detail)
 		pci_free_consistent(pdev, sizeof(struct megasas_evt_detail),
 				instance->evt_detail, instance->evt_detail_h);
-
 	if (instance->pd_info)
 		pci_free_consistent(pdev, sizeof(struct MR_PD_INFO),
 					instance->pd_info,
 					instance->pd_info_h);
+	if (instance->tgt_prop)
+		pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES),
+					instance->tgt_prop,
+					instance->tgt_prop_h);
 	if (instance->vf_affiliation)
 		pci_free_consistent(pdev, (MAX_LOGICAL_DRIVES + 1) *
 				    sizeof(struct MR_LD_VF_AFFILIATION),
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
index 9f19f00..9d02967 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
@@ -694,6 +694,7 @@ struct MPI2_IOC_INIT_REQUEST {
 #define MAX_RAIDMAP_PHYSICAL_DEVICES_DYN 512
 #define MR_DCMD_LD_MAP_GET_INFO             0x0300e101
 #define MR_DCMD_SYSTEM_PD_MAP_GET_INFO      0x0200e102
+#define MR_DCMD_DRV_GET_TARGET_PROP         0x0200e103
 #define MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC  0x010e8485   /* SR-IOV HB alloc*/
 #define MR_DCMD_LD_VF_MAP_GET_ALL_LDS_111   0x03200200
 #define MR_DCMD_LD_VF_MAP_GET_ALL_LDS       0x03150200
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 12/39] megaraid_sas: NVME fast path io support
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (10 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 11/39] megaraid_sas: NVME interface target prop added Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 13/39] megaraid_sas: raid 1 write performance for large io Shivasharan S
                   ` (26 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

This patch provide true fast path IO support.
Driver creates PRP for NVME drives and send Fast Path for performance.
Certain h/w requirement needs to be taken care in driver.

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas.h        |  10 +-
 drivers/scsi/megaraid/megaraid_sas_fp.c     |  55 +++--
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 316 ++++++++++++++++++++++++++--
 drivers/scsi/megaraid/megaraid_sas_fusion.h |  14 +-
 4 files changed, 350 insertions(+), 45 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index a45ff10..075e2e9 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -2172,6 +2172,11 @@ struct megasas_instance {
 	atomic_t fw_outstanding;
 	atomic_t ldio_outstanding;
 	atomic_t fw_reset_no_pci_access;
+	atomic_t ieee_sgl;
+	atomic_t prp_sgl;
+	atomic_t sge_holes_type1;
+	atomic_t sge_holes_type2;
+	atomic_t sge_holes_type3;
 
 	struct megasas_instance_template *instancet;
 	struct tasklet_struct isr_tasklet;
@@ -2443,7 +2448,9 @@ __le16 MR_PdDevHandleGet(u32 pd, struct MR_DRV_RAID_MAP_ALL *map);
 u16 MR_GetLDTgtId(u32 ld, struct MR_DRV_RAID_MAP_ALL *map);
 
 __le16 get_updated_dev_handle(struct megasas_instance *instance,
-	struct LD_LOAD_BALANCE_INFO *lbInfo, struct IO_REQUEST_INFO *in_info);
+			      struct LD_LOAD_BALANCE_INFO *lbInfo,
+			      struct IO_REQUEST_INFO *in_info,
+			      struct MR_DRV_RAID_MAP_ALL *drv_map);
 void mr_update_load_balance_params(struct MR_DRV_RAID_MAP_ALL *map,
 	struct LD_LOAD_BALANCE_INFO *lbInfo);
 int megasas_get_ctrl_info(struct megasas_instance *instance);
@@ -2472,4 +2479,5 @@ void megasas_update_sdev_properties(struct scsi_device *sdev);
 int megasas_reset_fusion(struct Scsi_Host *shost, int reason);
 int megasas_task_abort_fusion(struct scsi_cmnd *scmd);
 int megasas_reset_target_fusion(struct scsi_cmnd *scmd);
+u32 mega_mod64(u64 dividend, u32 divisor);
 #endif				/*LSI_MEGARAID_SAS_H */
diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
index 24258af..c3ef82d 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -155,6 +155,11 @@ __le16 MR_PdDevHandleGet(u32 pd, struct MR_DRV_RAID_MAP_ALL *map)
 	return map->raidMap.devHndlInfo[pd].curDevHdl;
 }
 
+static u8 MR_PdInterfaceTypeGet(u32 pd, struct MR_DRV_RAID_MAP_ALL *map)
+{
+	return map->raidMap.devHndlInfo[pd].interfaceType;
+}
+
 u16 MR_GetLDTgtId(u32 ld, struct MR_DRV_RAID_MAP_ALL *map)
 {
 	return le16_to_cpu(map->raidMap.ldSpanMap[ld].ldRaid.targetId);
@@ -929,6 +934,7 @@ static u8 mr_spanset_get_phy_params(struct megasas_instance *instance, u32 ld,
 	u8	retval = TRUE;
 	u64	*pdBlock = &io_info->pdBlock;
 	__le16	*pDevHandle = &io_info->devHandle;
+	u8	*pPdInterface = &io_info->pd_interface;
 	u32	logArm, rowMod, armQ, arm;
 	struct fusion_context *fusion;
 
@@ -960,15 +966,18 @@ static u8 mr_spanset_get_phy_params(struct megasas_instance *instance, u32 ld,
 
 	if (pd != MR_PD_INVALID) {
 		*pDevHandle = MR_PdDevHandleGet(pd, map);
+		*pPdInterface = MR_PdInterfaceTypeGet(pd, map);
 		/* get second pd also for raid 1/10 fast path writes*/
-		if (raid->level == 1) {
+		if (instance->is_ventura &&
+		    (raid->level == 1) &&
+		    !io_info->isRead) {
 			r1_alt_pd = MR_ArPdGet(arRef, physArm + 1, map);
 			if (r1_alt_pd != MR_PD_INVALID)
 				io_info->r1_alt_dev_handle =
 				MR_PdDevHandleGet(r1_alt_pd, map);
 		}
 	} else {
-		*pDevHandle = cpu_to_le16(MR_PD_INVALID);
+		*pDevHandle = cpu_to_le16(MR_DEVHANDLE_INVALID);
 		if ((raid->level >= 5) &&
 			((fusion->adapter_type == THUNDERBOLT_SERIES)  ||
 			((fusion->adapter_type == INVADER_SERIES) &&
@@ -977,8 +986,10 @@ static u8 mr_spanset_get_phy_params(struct megasas_instance *instance, u32 ld,
 		else if (raid->level == 1) {
 			physArm = physArm + 1;
 			pd = MR_ArPdGet(arRef, physArm, map);
-			if (pd != MR_PD_INVALID)
+			if (pd != MR_PD_INVALID) {
 				*pDevHandle = MR_PdDevHandleGet(pd, map);
+				*pPdInterface = MR_PdInterfaceTypeGet(pd, map);
+			}
 		}
 	}
 
@@ -1025,6 +1036,7 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 ld, u64 stripRow,
 	u8	    retval = TRUE;
 	u64	    *pdBlock = &io_info->pdBlock;
 	__le16	    *pDevHandle = &io_info->devHandle;
+	u8	    *pPdInterface = &io_info->pd_interface;
 	struct fusion_context *fusion;
 
 	fusion = instance->ctrl_context;
@@ -1070,16 +1082,19 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 ld, u64 stripRow,
 	if (pd != MR_PD_INVALID) {
 		/* Get dev handle from Pd. */
 		*pDevHandle = MR_PdDevHandleGet(pd, map);
+		*pPdInterface = MR_PdInterfaceTypeGet(pd, map);
 		/* get second pd also for raid 1/10 fast path writes*/
-		if (raid->level == 1) {
+		if (instance->is_ventura &&
+		    (raid->level == 1) &&
+		    !io_info->isRead) {
 			r1_alt_pd = MR_ArPdGet(arRef, physArm + 1, map);
 			if (r1_alt_pd != MR_PD_INVALID)
 				io_info->r1_alt_dev_handle =
-				MR_PdDevHandleGet(r1_alt_pd, map);
+					MR_PdDevHandleGet(r1_alt_pd, map);
 		}
 	} else {
 		/* set dev handle as invalid. */
-		*pDevHandle = cpu_to_le16(MR_PD_INVALID);
+		*pDevHandle = cpu_to_le16(MR_DEVHANDLE_INVALID);
 		if ((raid->level >= 5) &&
 			((fusion->adapter_type == THUNDERBOLT_SERIES)  ||
 			((fusion->adapter_type == INVADER_SERIES) &&
@@ -1089,9 +1104,11 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 ld, u64 stripRow,
 			/* Get alternate Pd. */
 			physArm = physArm + 1;
 			pd = MR_ArPdGet(arRef, physArm, map);
-			if (pd != MR_PD_INVALID)
+			if (pd != MR_PD_INVALID) {
 				/* Get dev handle from Pd */
 				*pDevHandle = MR_PdDevHandleGet(pd, map);
+				*pPdInterface = MR_PdInterfaceTypeGet(pd, map);
+			}
 		}
 	}
 
@@ -1509,11 +1526,11 @@ void mr_update_load_balance_params(struct MR_DRV_RAID_MAP_ALL *drv_map,
 }
 
 u8 megasas_get_best_arm_pd(struct megasas_instance *instance,
-	struct LD_LOAD_BALANCE_INFO *lbInfo, struct IO_REQUEST_INFO *io_info)
+			   struct LD_LOAD_BALANCE_INFO *lbInfo,
+			   struct IO_REQUEST_INFO *io_info,
+			   struct MR_DRV_RAID_MAP_ALL *drv_map)
 {
-	struct fusion_context *fusion;
 	struct MR_LD_RAID  *raid;
-	struct MR_DRV_RAID_MAP_ALL *drv_map;
 	u16	pd1_dev_handle;
 	u16     pend0, pend1, ld;
 	u64     diff0, diff1;
@@ -1527,9 +1544,6 @@ u8 megasas_get_best_arm_pd(struct megasas_instance *instance,
 			>> RAID_CTX_SPANARM_SPAN_SHIFT);
 	arm = (io_info->span_arm & RAID_CTX_SPANARM_ARM_MASK);
 
-
-	fusion = instance->ctrl_context;
-	drv_map = fusion->ld_drv_map[(instance->map_id & 1)];
 	ld = MR_TargetIdToLdGet(io_info->ldTgtId, drv_map);
 	raid = MR_LdRaidGet(ld, drv_map);
 	span_row_size = instance->UnevenSpanSupport ?
@@ -1544,7 +1558,7 @@ u8 megasas_get_best_arm_pd(struct megasas_instance *instance,
 
 	pd1_dev_handle = MR_PdDevHandleGet(pd1, drv_map);
 
-	if (pd1_dev_handle == MR_PD_INVALID) {
+	if (pd1_dev_handle == MR_DEVHANDLE_INVALID) {
 		bestArm = arm;
 	} else {
 		/* get the pending cmds for the data and mirror arms */
@@ -1581,19 +1595,18 @@ u8 megasas_get_best_arm_pd(struct megasas_instance *instance,
 }
 
 __le16 get_updated_dev_handle(struct megasas_instance *instance,
-	struct LD_LOAD_BALANCE_INFO *lbInfo, struct IO_REQUEST_INFO *io_info)
+			      struct LD_LOAD_BALANCE_INFO *lbInfo,
+			      struct IO_REQUEST_INFO *io_info,
+			      struct MR_DRV_RAID_MAP_ALL *drv_map)
 {
 	u8 arm_pd;
 	__le16 devHandle;
-	struct fusion_context *fusion;
-	struct MR_DRV_RAID_MAP_ALL *drv_map;
-
-	fusion = instance->ctrl_context;
-	drv_map = fusion->ld_drv_map[(instance->map_id & 1)];
 
 	/* get best new arm (PD ID) */
-	arm_pd  = megasas_get_best_arm_pd(instance, lbInfo, io_info);
+	arm_pd  = megasas_get_best_arm_pd(instance, lbInfo, io_info, drv_map);
 	devHandle = MR_PdDevHandleGet(arm_pd, drv_map);
+	io_info->pd_interface = MR_PdInterfaceTypeGet(arm_pd, drv_map);
 	atomic_inc(&lbInfo->scsi_pending_cmds[arm_pd]);
+
 	return devHandle;
 }
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index a481854..379c723 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1482,21 +1482,261 @@ map_cmd_status(struct fusion_context *fusion,
 }
 
 /**
+ * megasas_is_prp_possible -
+ * Checks if native NVMe PRPs can be built for the IO
+ *
+ * @instance:		Adapter soft state
+ * @scmd:		SCSI command from the mid-layer
+ * @sge_count:		scatter gather element count.
+ *
+ * Returns:		true: PRPs can be built
+ *			false: IEEE SGLs needs to be built
+ */
+static bool
+megasas_is_prp_possible(struct megasas_instance *instance,
+			struct scsi_cmnd *scmd, int sge_count)
+{
+	struct fusion_context *fusion;
+	int i;
+	u32 data_length = 0;
+	struct scatterlist *sg_scmd;
+	bool build_prp = false;
+	u32 mr_nvme_pg_size;
+
+	mr_nvme_pg_size = max_t(u32, instance->nvme_page_size,
+				MR_DEFAULT_NVME_PAGE_SIZE);
+	fusion = instance->ctrl_context;
+	data_length = scsi_bufflen(scmd);
+	sg_scmd = scsi_sglist(scmd);
+
+	/*
+	 * NVMe uses one PRP for each page (or part of a page)
+	 * look at the data length - if 4 pages or less then IEEE is OK
+	 * if  > 5 pages then we need to build a native SGL
+	 * if > 4 and <= 5 pages, then check physical address of 1st SG entry
+	 * if this first size in the page is >= the residual beyond 4 pages
+	 * then use IEEE, otherwise use native SGL
+	 */
+
+	if (data_length > (mr_nvme_pg_size * 5)) {
+		build_prp = true;
+	} else if ((data_length > (mr_nvme_pg_size * 4)) &&
+			(data_length <= (mr_nvme_pg_size * 5)))  {
+		/* check if 1st SG entry size is < residual beyond 4 pages */
+		if (sg_dma_len(sg_scmd) < (data_length - (mr_nvme_pg_size * 4)))
+			build_prp = true;
+	}
+
+/*
+ * Below code detects gaps/holes in IO data buffers.
+ * What does holes/gaps mean?
+ * Any SGE except first one in a SGL starts at non NVME page size
+ * aligned address OR Any SGE except last one in a SGL ends at
+ * non NVME page size boundary.
+ *
+ * Driver has already informed block layer by setting boundary rules for
+ * bio merging done at NVME page size boundary calling kernel API
+ * blk_queue_virt_boundary inside slave_config.
+ * Still there is possibility of IO coming with holes to driver because of
+ * IO merging done by IO scheduler.
+ *
+ * With SCSI BLK MQ enabled, there will be no IO with holes as there is no
+ * IO scheduling so no IO merging.
+ *
+ * With SCSI BLK MQ disabled, IO scheduler may attempt to merge IOs and
+ * then sending IOs with holes.
+ *
+ * Though driver can request block layer to disable IO merging by calling-
+ * queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, sdev->request_queue) but
+ * user may tune sysfs parameter- nomerges again to 0 or 1.
+ *
+ * If in future IO scheduling is enabled with SCSI BLK MQ,
+ * this algorithm to detect holes will be required in driver
+ * for SCSI BLK MQ enabled case as well.
+ *
+ *
+ */
+	scsi_for_each_sg(scmd, sg_scmd, sge_count, i) {
+		if ((i != 0) && (i != (sge_count - 1))) {
+			if (mega_mod64(sg_dma_len(sg_scmd), mr_nvme_pg_size) ||
+			    mega_mod64(sg_dma_address(sg_scmd),
+				       mr_nvme_pg_size)) {
+				build_prp = false;
+				atomic_inc(&instance->sge_holes_type1);
+				break;
+			}
+		}
+
+		if ((sge_count > 1) && (i == 0)) {
+			if ((mega_mod64((sg_dma_address(sg_scmd) +
+					sg_dma_len(sg_scmd)),
+					mr_nvme_pg_size))) {
+				build_prp = false;
+				atomic_inc(&instance->sge_holes_type2);
+				break;
+			}
+		}
+
+		if ((sge_count > 1) && (i == (sge_count - 1))) {
+			if (mega_mod64(sg_dma_address(sg_scmd),
+				       mr_nvme_pg_size)) {
+				build_prp = false;
+				atomic_inc(&instance->sge_holes_type3);
+				break;
+			}
+		}
+	}
+
+	return build_prp;
+}
+
+/**
+ * megasas_make_prp_nvme -
+ * Prepare PRPs(Physical Region Page)- SGLs specific to NVMe drives only
+ *
+ * @instance:		Adapter soft state
+ * @scmd:		SCSI command from the mid-layer
+ * @sgl_ptr:		SGL to be filled in
+ * @cmd:		Fusion command frame
+ * @sge_count:		scatter gather element count.
+ *
+ * Returns:		true: PRPs are built
+ *			false: IEEE SGLs needs to be built
+ */
+static bool
+megasas_make_prp_nvme(struct megasas_instance *instance, struct scsi_cmnd *scmd,
+		      struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr,
+		      struct megasas_cmd_fusion *cmd, int sge_count)
+{
+	int sge_len, offset, num_prp_in_chain = 0;
+	struct MPI25_IEEE_SGE_CHAIN64 *main_chain_element, *ptr_first_sgl;
+	u64 *ptr_sgl, *ptr_sgl_phys;
+	u64 sge_addr;
+	u32 page_mask, page_mask_result;
+	struct scatterlist *sg_scmd;
+	u32 first_prp_len;
+	bool build_prp = false;
+	int data_len = scsi_bufflen(scmd);
+	struct fusion_context *fusion;
+	u32 mr_nvme_pg_size = max_t(u32, instance->nvme_page_size,
+					MR_DEFAULT_NVME_PAGE_SIZE);
+
+	fusion = instance->ctrl_context;
+
+	build_prp = megasas_is_prp_possible(instance, scmd, sge_count);
+
+	if (!build_prp)
+		return false;
+
+	/*
+	 * Nvme has a very convoluted prp format.  One prp is required
+	 * for each page or partial page. Driver need to split up OS sg_list
+	 * entries if it is longer than one page or cross a page
+	 * boundary.  Driver also have to insert a PRP list pointer entry as
+	 * the last entry in each physical page of the PRP list.
+	 *
+	 * NOTE: The first PRP "entry" is actually placed in the first
+	 * SGL entry in the main message as IEEE 64 format.  The 2nd
+	 * entry in the main message is the chain element, and the rest
+	 * of the PRP entries are built in the contiguous pcie buffer.
+	 */
+	page_mask = mr_nvme_pg_size - 1;
+	ptr_sgl = (u64 *)cmd->sg_frame;
+	ptr_sgl_phys = (u64 *)cmd->sg_frame_phys_addr;
+	memset(ptr_sgl, 0, instance->max_chain_frame_sz);
+
+	/* Build chain frame element which holds all prps except first*/
+	main_chain_element = (struct MPI25_IEEE_SGE_CHAIN64 *)
+	    ((u8 *)sgl_ptr + sizeof(struct MPI25_IEEE_SGE_CHAIN64));
+
+	main_chain_element->Address = cpu_to_le64((uintptr_t)ptr_sgl_phys);
+	main_chain_element->NextChainOffset = 0;
+	main_chain_element->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT |
+					IEEE_SGE_FLAGS_SYSTEM_ADDR |
+					MPI26_IEEE_SGE_FLAGS_NSF_NVME_PRP;
+
+	/* Build first prp, sge need not to be page aligned*/
+	ptr_first_sgl = sgl_ptr;
+	sg_scmd = scsi_sglist(scmd);
+	sge_addr = sg_dma_address(sg_scmd);
+	sge_len = sg_dma_len(sg_scmd);
+
+	offset = (u32)(sge_addr & page_mask);
+	first_prp_len = mr_nvme_pg_size - offset;
+
+	ptr_first_sgl->Address = cpu_to_le64(sge_addr);
+	ptr_first_sgl->Length = cpu_to_le32(first_prp_len);
+
+	data_len -= first_prp_len;
+
+	if (sge_len > first_prp_len) {
+		sge_addr += first_prp_len;
+		sge_len -= first_prp_len;
+	} else if (sge_len == first_prp_len) {
+		sg_scmd = sg_next(sg_scmd);
+		sge_addr = sg_dma_address(sg_scmd);
+		sge_len = sg_dma_len(sg_scmd);
+	}
+
+	for (;;) {
+		offset = (u32)(sge_addr & page_mask);
+
+		/* Put PRP pointer due to page boundary*/
+		page_mask_result = (uintptr_t)(ptr_sgl + 1) & page_mask;
+		if (unlikely(!page_mask_result)) {
+			scmd_printk(KERN_NOTICE,
+				    scmd, "page boundary ptr_sgl: 0x%p\n",
+				    ptr_sgl);
+			ptr_sgl_phys++;
+			*ptr_sgl =
+				cpu_to_le64((uintptr_t)ptr_sgl_phys);
+			ptr_sgl++;
+			num_prp_in_chain++;
+		}
+
+		*ptr_sgl = cpu_to_le64(sge_addr);
+		ptr_sgl++;
+		ptr_sgl_phys++;
+		num_prp_in_chain++;
+
+		sge_addr += mr_nvme_pg_size;
+		sge_len -= mr_nvme_pg_size;
+		data_len -= mr_nvme_pg_size;
+
+		if (data_len <= 0)
+			break;
+
+		if (sge_len > 0)
+			continue;
+
+		sg_scmd = sg_next(sg_scmd);
+		sge_addr = sg_dma_address(sg_scmd);
+		sge_len = sg_dma_len(sg_scmd);
+	}
+
+	main_chain_element->Length =
+			cpu_to_le32(num_prp_in_chain * sizeof(u64));
+
+	atomic_inc(&instance->prp_sgl);
+	return build_prp;
+}
+
+/**
  * megasas_make_sgl_fusion -	Prepares 32-bit SGL
  * @instance:		Adapter soft state
  * @scp:		SCSI command from the mid-layer
  * @sgl_ptr:		SGL to be filled in
  * @cmd:		cmd we are working on
+ * @sge_count		sge count
  *
- * If successful, this function returns the number of SG elements.
  */
-static int
+static void
 megasas_make_sgl_fusion(struct megasas_instance *instance,
 			struct scsi_cmnd *scp,
 			struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr,
-			struct megasas_cmd_fusion *cmd)
+			struct megasas_cmd_fusion *cmd, int sge_count)
 {
-	int i, sg_processed, sge_count;
+	int i, sg_processed;
 	struct scatterlist *os_sgl;
 	struct fusion_context *fusion;
 
@@ -1508,13 +1748,6 @@ megasas_make_sgl_fusion(struct megasas_instance *instance,
 		sgl_ptr_end->Flags = 0;
 	}
 
-	sge_count = scsi_dma_map(scp);
-
-	BUG_ON(sge_count < 0);
-
-	if (sge_count > instance->max_num_sge || !sge_count)
-		return sge_count;
-
 	scsi_for_each_sg(scp, os_sgl, sge_count, i) {
 		sgl_ptr->Length = cpu_to_le32(sg_dma_len(os_sgl));
 		sgl_ptr->Address = cpu_to_le64(sg_dma_address(os_sgl));
@@ -1523,7 +1756,6 @@ megasas_make_sgl_fusion(struct megasas_instance *instance,
 			if (i == sge_count - 1)
 				sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST;
 		sgl_ptr++;
-
 		sg_processed = i + 1;
 
 		if ((sg_processed ==  (fusion->max_sge_in_main_msg - 1)) &&
@@ -1560,6 +1792,45 @@ megasas_make_sgl_fusion(struct megasas_instance *instance,
 			memset(sgl_ptr, 0, instance->max_chain_frame_sz);
 		}
 	}
+	atomic_inc(&instance->ieee_sgl);
+}
+
+/**
+ * megasas_make_sgl -	Build Scatter Gather List(SGLs)
+ * @scp:		SCSI command pointer
+ * @instance:		Soft instance of controller
+ * @cmd:		Fusion command pointer
+ *
+ * This function will build sgls based on device type.
+ * For nvme drives, there is different way of building sgls in nvme native
+ * format- PRPs(Physical Region Page).
+ *
+ * Returns the number of sg lists actually used, zero if the sg lists
+ * is NULL, or -ENOMEM if the mapping failed
+ */
+static
+int megasas_make_sgl(struct megasas_instance *instance, struct scsi_cmnd *scp,
+		     struct megasas_cmd_fusion *cmd)
+{
+	int sge_count;
+	bool build_prp = false;
+	struct MPI25_IEEE_SGE_CHAIN64 *sgl_chain64;
+
+	sge_count = scsi_dma_map(scp);
+
+	if ((sge_count > instance->max_num_sge) || (sge_count <= 0))
+		return sge_count;
+
+	sgl_chain64 = (struct MPI25_IEEE_SGE_CHAIN64 *)&cmd->io_request->SGL;
+	if ((le16_to_cpu(cmd->io_request->IoFlags) &
+	    MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) &&
+	    (cmd->pd_interface == NVME_PD))
+		build_prp = megasas_make_prp_nvme(instance, scp, sgl_chain64,
+						  cmd, sge_count);
+
+	if (!build_prp)
+		megasas_make_sgl_fusion(instance, scp, sgl_chain64,
+					cmd, sge_count);
 
 	return sge_count;
 }
@@ -2084,7 +2355,7 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 			io_info.devHandle =
 				get_updated_dev_handle(instance,
 					&fusion->load_balance_info[device_id],
-					&io_info);
+					&io_info, local_map_ptr);
 			scp->SCp.Status |= MEGASAS_LOAD_BALANCE_FLAG;
 			cmd->pd_r1_lb = io_info.pd_after_lb;
 			if (instance->is_ventura)
@@ -2111,6 +2382,7 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 
 		cmd->request_desc->SCSIIO.DevHandle = io_info.devHandle;
 		io_request->DevHandle = io_info.devHandle;
+		cmd->pd_interface = io_info.pd_interface;
 		/* populate the LUN field */
 		memcpy(io_request->LUN, raidLUN, 8);
 	} else {
@@ -2253,12 +2525,15 @@ megasas_build_syspd_fusion(struct megasas_instance *instance,
 	struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
 	struct RAID_CONTEXT	*pRAID_Context;
 	struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync;
+	struct MR_PRIV_DEVICE *mr_device_priv_data;
 	struct fusion_context *fusion = instance->ctrl_context;
 	pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id - 1) & 1];
 
 	device_id = MEGASAS_DEV_INDEX(scmd);
 	pd_index = MEGASAS_PD_INDEX(scmd);
 	os_timeout_value = scmd->request->timeout / HZ;
+	mr_device_priv_data = scmd->device->hostdata;
+	cmd->pd_interface = mr_device_priv_data->interface_type;
 
 	io_request = cmd->io_request;
 	/* get RAID_Context pointer */
@@ -2352,7 +2627,7 @@ megasas_build_io_fusion(struct megasas_instance *instance,
 			struct scsi_cmnd *scp,
 			struct megasas_cmd_fusion *cmd)
 {
-	u16 sge_count;
+	int sge_count;
 	u8  cmd_type;
 	struct MPI2_RAID_SCSI_IO_REQUEST *io_request = cmd->io_request;
 
@@ -2398,15 +2673,12 @@ megasas_build_io_fusion(struct megasas_instance *instance,
 	 * Construct SGL
 	 */
 
-	sge_count =
-		megasas_make_sgl_fusion(instance, scp,
-					(struct MPI25_IEEE_SGE_CHAIN64 *)
-					&io_request->SGL, cmd);
+	sge_count = megasas_make_sgl(instance, scp, cmd);
 
-	if (sge_count > instance->max_num_sge) {
-		dev_err(&instance->pdev->dev, "Error. sge_count (0x%x) exceeds "
-		       "max (0x%x) allowed\n", sge_count,
-		       instance->max_num_sge);
+	if (sge_count > instance->max_num_sge || (sge_count < 0)) {
+		dev_err(&instance->pdev->dev,
+			"%s %d sge_count (%d) is out of range. Range is:  0-%d\n",
+			__func__, __LINE__, sge_count, instance->max_num_sge);
 		return 1;
 	}
 
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
index 9d02967..c606ca0 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
@@ -702,7 +702,7 @@ struct MPI2_IOC_INIT_REQUEST {
 struct MR_DEV_HANDLE_INFO {
 	__le16	curDevHdl;
 	u8      validHandles;
-	u8      reserved;
+	u8      interfaceType;
 	__le16	devHandle[2];
 };
 
@@ -914,6 +914,7 @@ struct IO_REQUEST_INFO {
 	u16 ldTgtId;
 	u8 isRead;
 	__le16 devHandle;
+	u8 pd_interface;
 	u64 pdBlock;
 	u8 fpOkForIo;
 	u8 IoforUnevenSpan;
@@ -1025,6 +1026,16 @@ struct MR_FW_RAID_MAP_DYNAMIC {
 #define IEEE_SGE_FLAGS_CHAIN_ELEMENT        (0x80)
 #define IEEE_SGE_FLAGS_END_OF_LIST          (0x40)
 
+#define MPI2_SGE_FLAGS_SHIFT                (0x02)
+#define IEEE_SGE_FLAGS_FORMAT_MASK          (0xC0)
+#define IEEE_SGE_FLAGS_FORMAT_IEEE          (0x00)
+#define IEEE_SGE_FLAGS_FORMAT_NVME          (0x02)
+
+#define MPI26_IEEE_SGE_FLAGS_NSF_MASK           (0x1C)
+#define MPI26_IEEE_SGE_FLAGS_NSF_MPI_IEEE       (0x00)
+#define MPI26_IEEE_SGE_FLAGS_NSF_NVME_PRP       (0x08)
+#define MPI26_IEEE_SGE_FLAGS_NSF_NVME_SGL       (0x10)
+
 struct megasas_register_set;
 struct megasas_instance;
 
@@ -1061,6 +1072,7 @@ struct megasas_cmd_fusion {
 	u32 index;
 	u8 pd_r1_lb;
 	struct completion done;
+	u8 pd_interface;
 	u16 r1_alt_dev_handle; /* raid 1/10 only*/
 	bool cmd_completed;  /* raid 1/10 fp writes status holder */
 
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 13/39] megaraid_sas: raid 1 write performance for large io
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (11 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 12/39] megaraid_sas: NVME fast path io support Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 14/39] megaraid_sas: set residual bytes count during IO completion Shivasharan S
                   ` (25 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Avoid Host side PCI bandwidth bottleneck and hint FW to do Write buffering using
RaidFlag MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT.
Once IO is landed in FW with MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT,
it will do single DMA from host and buffer the Write operation. On back end,
FW will DMA same buffer to the Mirror and Data Arm.
This will improve large block IO performance which bottleneck due to Host side PCI bandwidth limitation.

Consistent ~4000MB T.P for 256K Block size is expected performance numbers.
IOPS for small Block size should be on par with Disk performance.
(E.g 42 SAS Disk in JBOD mode gives 3700MB T.P.
Same Drive used in R1 WT mode, should give ~1800MB T.P)

Using this patch 24 R1 VDs (HDD) gives below performance for Sequential Write.
Without this patch, we cannot reach above 3200MB (Throughput is in MB. )

Block Size   	50% 256K and 50% 4K          100% 256K
4K                 3100                        2030
8K                 3140                        2740
16K                3140                        3140
32K                3400                        3240
64K                3500                        3700
128K               3870                        3870
256K               3920                        3920

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas.h        |  5 +++++
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 32 +++++++++++++++++++++++++++--
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 075e2e9..bed8a37 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -1409,6 +1409,8 @@ struct megasas_ctrl_info {
 #define SCAN_VD_CHANNEL	0x2
 
 #define MEGASAS_KDUMP_QUEUE_DEPTH               100
+#define MR_LARGE_IO_MIN_SIZE			(32 * 1024)
+#define MR_R1_LDIO_PIGGYBACK_DEFAULT		4
 
 enum MR_SCSI_CMD_TYPE {
 	READ_WRITE_LDIO = 0,
@@ -1875,6 +1877,7 @@ union megasas_frame {
 struct MR_PRIV_DEVICE {
 	bool is_tm_capable;
 	bool tm_busy;
+	atomic_t r1_ldio_hint;
 	u8   interface_type;
 };
 struct megasas_cmd;
@@ -2235,6 +2238,8 @@ struct megasas_instance {
 	bool is_ventura;
 	bool msix_combined;
 	u16 max_raid_mapsize;
+	/* preffered count to send as LDIO irrspective of FP capable.*/
+	u8  r1_ldio_hint_default;
 	u32 nvme_page_size;
 };
 struct MR_LD_VF_MAP {
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 379c723..edbecc5 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1383,6 +1383,7 @@ megasas_init_adapter_fusion(struct megasas_instance *instance)
 	}
 
 	instance->flag_ieee = 1;
+	instance->r1_ldio_hint_default =  MR_R1_LDIO_PIGGYBACK_DEFAULT;
 	fusion->fast_path_io = 0;
 
 	fusion->drv_map_pages = get_order(fusion->drv_map_sz);
@@ -2110,7 +2111,7 @@ static void megasas_stream_detect(struct megasas_instance *instance,
 static void
 megasas_set_raidflag_cpu_affinity(union RAID_CONTEXT_UNION *praid_context,
 				  struct MR_LD_RAID *raid, bool fp_possible,
-				  u8 is_read)
+				  u8 is_read, u32 scsi_buff_len)
 {
 	u8 cpu_sel = MR_RAID_CTX_CPUSEL_0;
 	struct RAID_CONTEXT_G35 *rctx_g35;
@@ -2161,6 +2162,17 @@ megasas_set_raidflag_cpu_affinity(union RAID_CONTEXT_UNION *praid_context,
 	}
 
 	rctx_g35->routing_flags.bits.cpu_sel = cpu_sel;
+
+	/* Always give priority to MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT
+	 * vs MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS.
+	 * IO Subtype is not bitmap.
+	 */
+	if ((raid->level == 1) && (!is_read)) {
+		if (scsi_buff_len > MR_LARGE_IO_MIN_SIZE)
+			praid_context->raid_context_g35.raid_flags =
+				(MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT
+				<< MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT);
+	}
 }
 
 /**
@@ -2303,6 +2315,14 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 		    io_info.isRead && io_info.ra_capable)
 			fp_possible = false;
 
+		/* FP for Optimal raid level 1.
+		 * All large RAID-1 writes (> 32 KiB, both WT and WB modes)
+		 * are built by the driver as LD I/Os.
+		 * All small RAID-1 WT writes (<= 32 KiB) are built as FP I/Os
+		 * (there is never a reason to process these as buffered writes)
+		 * All small RAID-1 WB writes (<= 32 KiB) are built as FP I/Os
+		 * with the SLD bit asserted.
+		 */
 		if (io_info.r1_alt_dev_handle != MR_DEVHANDLE_INVALID) {
 			mrdev_priv = scp->device->hostdata;
 
@@ -2310,13 +2330,21 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 				(instance->host->can_queue)) {
 				fp_possible = false;
 				atomic_dec(&instance->fw_outstanding);
+			} else if ((scsi_buff_len > MR_LARGE_IO_MIN_SIZE) ||
+				   atomic_dec_if_positive(&mrdev_priv->r1_ldio_hint)) {
+				fp_possible = false;
+				atomic_dec(&instance->fw_outstanding);
+				if (scsi_buff_len > MR_LARGE_IO_MIN_SIZE)
+					atomic_set(&mrdev_priv->r1_ldio_hint,
+						   instance->r1_ldio_hint_default);
 			}
 		}
 
 		/* If raid is NULL, set CPU affinity to default CPU0 */
 		if (raid)
 			megasas_set_raidflag_cpu_affinity(praid_context,
-				raid, fp_possible, io_info.isRead);
+				raid, fp_possible, io_info.isRead,
+				scsi_buff_len);
 		else
 			praid_context->raid_context_g35.routing_flags.bits.cpu_sel =
 				MR_RAID_CTX_CPUSEL_0;
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 14/39] megaraid_sas: set residual bytes count during IO completion
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (12 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 13/39] megaraid_sas: raid 1 write performance for large io Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 15/39] megaraid_sas: enhance debug logs in OCR context Shivasharan S
                   ` (24 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Fixing issue of not setting residual bytes correctly.

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index edbecc5..4628671 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1445,6 +1445,7 @@ map_cmd_status(struct fusion_context *fusion,
 	struct scsi_cmnd *scmd, u8 status, u8 ext_status,
 			u32 data_length, u8 *sense)
 {
+	int resid;
 
 	switch (status) {
 
@@ -1467,6 +1468,15 @@ map_cmd_status(struct fusion_context *fusion,
 			       SCSI_SENSE_BUFFERSIZE);
 			scmd->result |= DRIVER_SENSE << 24;
 		}
+
+		/*
+		 * If the  IO request is partially completed, then MR FW will
+		 * update "io_request->DataLength" field with actual number of
+		 * bytes transferred.Driver will set residual bytes count in
+		 * SCSI command structure.
+		 */
+		resid = (scsi_bufflen(scmd) - data_length);
+		scsi_set_resid(scmd, resid);
 		break;
 
 	case MFI_STAT_LD_OFFLINE:
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 15/39] megaraid_sas: enhance debug logs in OCR context
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (13 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 14/39] megaraid_sas: set residual bytes count during IO completion Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 16/39] megaraid_sas: add print in device removal path Shivasharan S
                   ` (23 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Add additional logging from driver in OCR context.
Add debug logs for partial completion of IOs is iodone context.

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas.h        |  3 +++
 drivers/scsi/megaraid/megaraid_sas_base.c   | 38 ++++++++++++++++++++++++++---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 35 +++++++++++++++++++++++++-
 3 files changed, 72 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index bed8a37..93da6dc 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -1405,6 +1405,9 @@ struct megasas_ctrl_info {
 
 #define VD_EXT_DEBUG 0
 
+/* Driver's internal Logging levels*/
+#define OCR_LOGS    (1 << 0)
+
 #define SCAN_PD_CHANNEL	0x1
 #define SCAN_VD_CHANNEL	0x2
 
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 51b35a6..b41bbea 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -2742,6 +2742,24 @@ blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd)
 }
 
 /**
+ * megasas_dump_frame -	This function will dump MPT/MFI frame
+ */
+static inline void
+megasas_dump_frame(void *mpi_request, int sz)
+{
+	int i;
+	__le32 *mfp = (__le32 *)mpi_request;
+
+	printk(KERN_INFO "IO request frame:\n\t");
+	for (i = 0; i < sz; i++) {
+		if (i && ((i % 8) == 0))
+			printk("\n\t");
+		printk("%08x ", le32_to_cpu(mfp[i]));
+	}
+	printk("\n");
+}
+
+/**
  * megasas_reset_bus_host -	Bus & host reset handler entry point
  */
 static int megasas_reset_bus_host(struct scsi_cmnd *scmd)
@@ -2751,12 +2769,26 @@ static int megasas_reset_bus_host(struct scsi_cmnd *scmd)
 
 	instance = (struct megasas_instance *)scmd->device->host->hostdata;
 
+	scmd_printk(KERN_INFO, scmd,
+		"Controller reset is requested due to IO timeout\n"
+		"SCSI command pointer: (%p)\t SCSI host state: %d\t"
+		" SCSI host busy: %d\t FW outstanding: %d\n",
+		scmd, scmd->device->host->shost_state,
+		atomic_read((atomic_t *)&scmd->device->host->host_busy),
+		atomic_read(&instance->fw_outstanding));
+
 	/*
 	 * First wait for all commands to complete
 	 */
-	if (instance->ctrl_context)
-		ret = megasas_reset_fusion(scmd->device->host, 1);
-	else
+	if (instance->ctrl_context) {
+		struct megasas_cmd_fusion *cmd;
+		cmd = (struct megasas_cmd_fusion *)scmd->SCp.ptr;
+		if (cmd)
+			megasas_dump_frame(cmd->io_request,
+				sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
+		ret = megasas_reset_fusion(scmd->device->host,
+				SCSIIO_TIMEOUT_OCR);
+	} else
 		ret = megasas_generic_reset(scmd);
 
 	return ret;
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 4628671..1252a3c 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1445,8 +1445,10 @@ map_cmd_status(struct fusion_context *fusion,
 	struct scsi_cmnd *scmd, u8 status, u8 ext_status,
 			u32 data_length, u8 *sense)
 {
+	u8 cmd_type;
 	int resid;
 
+	cmd_type = megasas_cmd_type(scmd);
 	switch (status) {
 
 	case MFI_STAT_OK:
@@ -1477,6 +1479,13 @@ map_cmd_status(struct fusion_context *fusion,
 		 */
 		resid = (scsi_bufflen(scmd) - data_length);
 		scsi_set_resid(scmd, resid);
+
+		if (resid &&
+			((cmd_type == READ_WRITE_LDIO) ||
+			(cmd_type == READ_WRITE_SYSPDIO)))
+			scmd_printk(KERN_INFO, scmd, "BRCM Debug mfi stat 0x%x, data len"
+				" requested/completed 0x%x/0x%x\n",
+				status, scsi_bufflen(scmd), data_length);
 		break;
 
 	case MFI_STAT_LD_OFFLINE:
@@ -3477,6 +3486,14 @@ int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance,
 			       " will reset adapter scsi%d.\n",
 				instance->host->host_no);
 			megasas_complete_cmd_dpc_fusion((unsigned long)instance);
+			if (instance->requestorId && reason) {
+				dev_warn(&instance->pdev->dev, "SR-IOV Found FW in FAULT"
+				" state while polling during"
+				" I/O timeout handling for %d\n",
+				instance->host->host_no);
+				*convert = 1;
+			}
+
 			retval = 1;
 			goto out;
 		}
@@ -3496,7 +3513,7 @@ int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance,
 		}
 
 		/* If SR-IOV VF mode & I/O timeout, check for HB timeout */
-		if (instance->requestorId && reason) {
+		if (instance->requestorId && (reason == SCSIIO_TIMEOUT_OCR)) {
 			if (instance->hb_host_mem->HB.fwCounter !=
 			    instance->hb_host_mem->HB.driverCounter) {
 				instance->hb_host_mem->HB.driverCounter =
@@ -3912,6 +3929,9 @@ int megasas_task_abort_fusion(struct scsi_cmnd *scmd)
 	instance = (struct megasas_instance *)scmd->device->host->hostdata;
 	fusion = instance->ctrl_context;
 
+	scmd_printk(KERN_INFO, scmd, "task abort called for scmd(%p)\n", scmd);
+	scsi_print_command(scmd);
+
 	if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) {
 		dev_err(&instance->pdev->dev, "Controller is not OPERATIONAL,"
 		"SCSI host:%d\n", instance->host->host_no);
@@ -3992,6 +4012,9 @@ int megasas_reset_target_fusion(struct scsi_cmnd *scmd)
 	instance = (struct megasas_instance *)scmd->device->host->hostdata;
 	fusion = instance->ctrl_context;
 
+	sdev_printk(KERN_INFO, scmd->device,
+		    "target reset called for scmd(%p)\n", scmd);
+
 	if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) {
 		dev_err(&instance->pdev->dev, "Controller is not OPERATIONAL,"
 		"SCSI host:%d\n", instance->host->host_no);
@@ -4151,6 +4174,9 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason)
 		if (convert)
 			reason = 0;
 
+		if (megasas_dbg_lvl & OCR_LOGS)
+			dev_info(&instance->pdev->dev, "\nPending SCSI commands:\n");
+
 		/* Now return commands back to the OS */
 		for (i = 0 ; i < instance->max_scsi_cmds; i++) {
 			cmd_fusion = fusion->cmd_list[i];
@@ -4161,6 +4187,13 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason)
 			}
 			scmd_local = cmd_fusion->scmd;
 			if (cmd_fusion->scmd) {
+				if (megasas_dbg_lvl & OCR_LOGS) {
+					sdev_printk(KERN_INFO,
+						cmd_fusion->scmd->device, "SMID: 0x%x\n",
+						cmd_fusion->index);
+					scsi_print_command(cmd_fusion->scmd);
+				}
+
 				scmd_local->result =
 					megasas_check_mpio_paths(instance,
 							scmd_local);
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 16/39] megaraid_sas: add print in device removal path
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (14 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 15/39] megaraid_sas: enhance debug logs in OCR context Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 17/39] megaraid_sas: reduce size of fusion_context and use vmalloc if kmalloc fails Shivasharan S
                   ` (22 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index b41bbea..c8fa480 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -7383,6 +7383,13 @@ megasas_sysfs_set_dbg_lvl(struct device_driver *dd, const char *buf, size_t coun
 static DRIVER_ATTR(dbg_lvl, S_IRUGO|S_IWUSR, megasas_sysfs_show_dbg_lvl,
 		megasas_sysfs_set_dbg_lvl);
 
+static inline void megasas_remove_scsi_device(struct scsi_device *sdev)
+{
+	sdev_printk(KERN_INFO, sdev, "SCSI device is removed\n");
+	scsi_remove_device(sdev);
+	scsi_device_put(sdev);
+}
+
 static void
 megasas_aen_polling(struct work_struct *work)
 {
@@ -7487,10 +7494,8 @@ megasas_aen_polling(struct work_struct *work)
 					else
 						scsi_device_put(sdev1);
 				} else {
-					if (sdev1) {
-						scsi_remove_device(sdev1);
-						scsi_device_put(sdev1);
-					}
+					if (sdev1)
+						megasas_remove_scsi_device(sdev1);
 				}
 			}
 		}
@@ -7507,10 +7512,8 @@ megasas_aen_polling(struct work_struct *work)
 					else
 						scsi_device_put(sdev1);
 				} else {
-					if (sdev1) {
-						scsi_remove_device(sdev1);
-						scsi_device_put(sdev1);
-					}
+					if (sdev1)
+						megasas_remove_scsi_device(sdev1);
 				}
 			}
 		}
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 17/39] megaraid_sas: reduce size of fusion_context and use vmalloc if kmalloc fails
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (15 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 16/39] megaraid_sas: add print in device removal path Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 18/39] megaraid_sas: In validate raid map, raid capability is not converted to cpu format for all lds Shivasharan S
                   ` (21 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Currently fusion context has fixed array load_balance_info. Use dynamic allocation.
In few places, driver do not want physically contigious memory.
Attempt to use vmalloc if physical contiguous memory is not available.

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas.h        |  2 +
 drivers/scsi/megaraid/megaraid_sas_base.c   | 15 ++----
 drivers/scsi/megaraid/megaraid_sas_fp.c     |  3 +-
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 71 +++++++++++++++++++++++++++--
 drivers/scsi/megaraid/megaraid_sas_fusion.h |  3 +-
 5 files changed, 76 insertions(+), 18 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 93da6dc..0a20fff 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -2488,4 +2488,6 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason);
 int megasas_task_abort_fusion(struct scsi_cmnd *scmd);
 int megasas_reset_target_fusion(struct scsi_cmnd *scmd);
 u32 mega_mod64(u64 dividend, u32 divisor);
+int megasas_alloc_fusion_context(struct megasas_instance *instance);
+void megasas_free_fusion_context(struct megasas_instance *instance);
 #endif				/*LSI_MEGARAID_SAS_H */
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index c8fa480..b2da257 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -6029,18 +6029,12 @@ static int megasas_probe_one(struct pci_dev *pdev,
 	case PCI_DEVICE_ID_LSI_CUTLASS_52:
 	case PCI_DEVICE_ID_LSI_CUTLASS_53:
 	{
-		instance->ctrl_context_pages =
-			get_order(sizeof(struct fusion_context));
-		instance->ctrl_context = (void *)__get_free_pages(GFP_KERNEL,
-				instance->ctrl_context_pages);
-		if (!instance->ctrl_context) {
-			dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate "
-			       "memory for Fusion context info\n");
+		if (megasas_alloc_fusion_context(instance)) {
+			megasas_free_fusion_context(instance);
 			goto fail_alloc_dma_buf;
 		}
 		fusion = instance->ctrl_context;
-		memset(fusion, 0,
-			((1 << PAGE_SHIFT) << instance->ctrl_context_pages));
+
 		if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
 			(instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA))
 			fusion->adapter_type = THUNDERBOLT_SERIES;
@@ -6683,8 +6677,7 @@ static void megasas_detach_one(struct pci_dev *pdev)
 					fusion->pd_seq_sync[i],
 					fusion->pd_seq_phys[i]);
 		}
-		free_pages((ulong)instance->ctrl_context,
-			instance->ctrl_context_pages);
+		megasas_free_fusion_context(instance);
 	} else {
 		megasas_release_mfi(instance);
 		pci_free_consistent(pdev, sizeof(u32),
diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
index c3ef82d..d9b0f28 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -489,7 +489,8 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance)
 	if (instance->UnevenSpanSupport)
 		mr_update_span_set(drv_map, ldSpanInfo);
 
-	mr_update_load_balance_params(drv_map, lbInfo);
+	if (lbInfo)
+		mr_update_load_balance_params(drv_map, lbInfo);
 
 	num_lds = le16_to_cpu(drv_map->raidMap.ldCount);
 
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 1252a3c..9019b82 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -47,6 +47,7 @@
 #include <linux/blkdev.h>
 #include <linux/mutex.h>
 #include <linux/poll.h>
+#include <linux/vmalloc.h>
 
 #include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
@@ -2397,8 +2398,9 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 			io_request->IoFlags |=
 			cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
 		}
-		if ((fusion->load_balance_info[device_id].loadBalanceFlag) &&
-		    (io_info.isRead)) {
+		if (fusion->load_balance_info &&
+			(fusion->load_balance_info[device_id].loadBalanceFlag) &&
+			(io_info.isRead)) {
 			io_info.devHandle =
 				get_updated_dev_handle(instance,
 					&fusion->load_balance_info[device_id],
@@ -4270,9 +4272,10 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason)
 				retval = FAILED;
 			}
 			/* Reset load balance info */
-			memset(fusion->load_balance_info, 0,
-			       sizeof(struct LD_LOAD_BALANCE_INFO)
-			       *MAX_LOGICAL_DRIVES_EXT);
+			if (fusion->load_balance_info)
+				memset(fusion->load_balance_info, 0,
+				       (sizeof(struct LD_LOAD_BALANCE_INFO) *
+				       MAX_LOGICAL_DRIVES_EXT));
 
 			if (!megasas_get_map_info(instance))
 				megasas_sync_map_info(instance);
@@ -4426,6 +4429,64 @@ void megasas_fusion_ocr_wq(struct work_struct *work)
 	megasas_reset_fusion(instance->host, 0);
 }
 
+/* Allocate fusion context */
+int
+megasas_alloc_fusion_context(struct megasas_instance *instance)
+{
+	struct fusion_context *fusion;
+
+	instance->ctrl_context_pages = get_order(sizeof(struct fusion_context));
+	instance->ctrl_context = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
+		instance->ctrl_context_pages);
+	if (!instance->ctrl_context) {
+		/* fall back to using vmalloc for fusion_context */
+		instance->ctrl_context = vzalloc(sizeof(struct fusion_context));
+		if (!instance->ctrl_context) {
+			dev_err(&instance->pdev->dev, "Failed from %s %d\n", __func__, __LINE__);
+			return -ENOMEM;
+		}
+	}
+
+	fusion = instance->ctrl_context;
+
+	fusion->load_balance_info_pages = get_order(MAX_LOGICAL_DRIVES_EXT *
+		sizeof(struct LD_LOAD_BALANCE_INFO));
+	fusion->load_balance_info =
+		(struct LD_LOAD_BALANCE_INFO *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
+		fusion->load_balance_info_pages);
+	if (!fusion->load_balance_info) {
+		fusion->load_balance_info = vzalloc(MAX_LOGICAL_DRIVES_EXT *
+			sizeof(struct LD_LOAD_BALANCE_INFO));
+		if (!fusion->load_balance_info)
+			dev_err(&instance->pdev->dev, "Failed to allocate load_balance_info, "
+				"continuing without Load Balance support\n");
+	}
+
+	return 0;
+}
+
+void
+megasas_free_fusion_context(struct megasas_instance *instance)
+{
+	struct fusion_context *fusion = instance->ctrl_context;
+
+	if (fusion) {
+		if (fusion->load_balance_info) {
+			if (is_vmalloc_addr(fusion->load_balance_info))
+				vfree(fusion->load_balance_info);
+			else
+				free_pages((ulong)fusion->load_balance_info,
+					fusion->load_balance_info_pages);
+		}
+
+		if (is_vmalloc_addr(fusion))
+			vfree(fusion);
+		else
+			free_pages((ulong)fusion,
+				instance->ctrl_context_pages);
+	}
+}
+
 struct megasas_instance_template megasas_instance_template_fusion = {
 	.enable_intr = megasas_enable_intr_fusion,
 	.disable_intr = megasas_disable_intr_fusion,
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
index c606ca0..f25a262 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
@@ -1287,7 +1287,8 @@ struct fusion_context {
 	struct MR_PD_CFG_SEQ_NUM_SYNC	*pd_seq_sync[JBOD_MAPS_COUNT];
 	dma_addr_t pd_seq_phys[JBOD_MAPS_COUNT];
 	u8 fast_path_io;
-	struct LD_LOAD_BALANCE_INFO load_balance_info[MAX_LOGICAL_DRIVES_EXT];
+	struct LD_LOAD_BALANCE_INFO *load_balance_info;
+	u32 load_balance_info_pages;
 	LD_SPAN_INFO log_to_span[MAX_LOGICAL_DRIVES_EXT];
 	u8 adapter_type;
 	struct LD_STREAM_DETECT **stream_detect_by_ld;
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 18/39] megaraid_sas: In validate raid map, raid capability is not converted to cpu format for all lds
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (16 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 17/39] megaraid_sas: reduce size of fusion_context and use vmalloc if kmalloc fails Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 19/39] megaraid_sas: MR_TargetIdToLdGet u8 to u16 and avoid invalid raid-map access Shivasharan S
                   ` (20 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

On a host, if an ld is deleted there is a hole in the ld array returned
by the FW. But in MR_ValidateMapInfo we are not accounting for holes in
the ld array and traverse only upto index num_lds.
This patch takes care of converting the capability field of all the
valid lds in the ld raid map.

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_fp.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
index d9b0f28..a0b0e68 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -452,7 +452,7 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance)
 	struct LD_LOAD_BALANCE_INFO *lbInfo;
 	PLD_SPAN_INFO ldSpanInfo;
 	struct MR_LD_RAID         *raid;
-	u16 ldCount, num_lds;
+	u16 num_lds, i;
 	u16 ld;
 	u32 expected_size;
 
@@ -495,10 +495,17 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance)
 	num_lds = le16_to_cpu(drv_map->raidMap.ldCount);
 
 	/*Convert Raid capability values to CPU arch */
-	for (ldCount = 0; ldCount < num_lds; ldCount++) {
-		ld = MR_TargetIdToLdGet(ldCount, drv_map);
+	for (i = 0; (num_lds > 0) && (i < MAX_LOGICAL_DRIVES_EXT); i++) {
+		ld = MR_TargetIdToLdGet(i, drv_map);
+
+		/* For non existing VDs, iterate to next VD*/
+		if (ld >= (MAX_LOGICAL_DRIVES_EXT - 1))
+			continue;
+
 		raid = MR_LdRaidGet(ld, drv_map);
 		le32_to_cpus((u32 *)&raid->capability);
+
+		num_lds--;
 	}
 
 	return 1;
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 19/39] megaraid_sas: MR_TargetIdToLdGet u8 to u16 and avoid invalid raid-map access
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (17 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 18/39] megaraid_sas: In validate raid map, raid capability is not converted to cpu format for all lds Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-09 14:31   ` Kashyap Desai
  2017-02-08  9:29 ` [PATCH v2 20/39] megaraid_sas: Big endian RDPQ mode fix Shivasharan S
                   ` (19 subsequent siblings)
  38 siblings, 1 reply; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

fix in v2 - updated description content.
Change MR_TargetIdToLdGet return type from u8 to u16.

ld id range check is added at two places in this patch - 
@megasas_build_ldio_fusion and @megasas_build_ld_nonrw_fusion.
Previous driver code used different data type for lds TargetId returned from MR_TargetIdToLdGet.
Prior to this change, above two functions was safeguarded due to function always return u8
and maximum value of ld id returned was 255.

In below check, fw_supported_vd_count as of today is 64 or 256 and
valid range  to support is either 0-63 or 0-255. Ideally want to filter accessing
raid map for ld ids which are not valid. With the u16 change, invalid ld id value
is 0xFFFF and we will see kernel panic due to random memory access in MR_LdRaidGet.
The changes will ensure we do not call MR_LdRaidGet if ld id is beyond size of ldSpanMap array.

               if (ld < instance->fw_supported_vd_count)

>From firmware perspective,ld id 0xFF is invalid and even though current driver
code forward such command, firmware fails with target not available.

ld target id issue occurs mainly whenever driver loops to populate raid map (ea. MR_ValidateMapInfo).
These are the only two places where we may see out of range target ids and wants to
protect raid map access based on range provided by Firmware API.


Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
---
 drivers/scsi/megaraid/megaraid_sas.h        |  2 +-
 drivers/scsi/megaraid/megaraid_sas_fp.c     |  5 +++--
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 25 ++++++++++++++-----------
 3 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 0a20fff..efc01a3 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -2448,7 +2448,7 @@ MR_BuildRaidContext(struct megasas_instance *instance,
 		    struct IO_REQUEST_INFO *io_info,
 		    struct RAID_CONTEXT *pRAID_Context,
 		    struct MR_DRV_RAID_MAP_ALL *map, u8 **raidLUN);
-u8 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_DRV_RAID_MAP_ALL *map);
+u16 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_DRV_RAID_MAP_ALL *map);
 struct MR_LD_RAID *MR_LdRaidGet(u32 ld, struct MR_DRV_RAID_MAP_ALL *map);
 u16 MR_ArPdGet(u32 ar, u32 arm, struct MR_DRV_RAID_MAP_ALL *map);
 u16 MR_LdSpanArrayGet(u32 ld, u32 span, struct MR_DRV_RAID_MAP_ALL *map);
diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
index a0b0e68..9d5d485 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -165,7 +165,7 @@ u16 MR_GetLDTgtId(u32 ld, struct MR_DRV_RAID_MAP_ALL *map)
 	return le16_to_cpu(map->raidMap.ldSpanMap[ld].ldRaid.targetId);
 }
 
-u8 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_DRV_RAID_MAP_ALL *map)
+u16 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_DRV_RAID_MAP_ALL *map)
 {
 	return map->raidMap.ldTgtIdToLd[ldTgtId];
 }
@@ -1151,7 +1151,7 @@ MR_BuildRaidContext(struct megasas_instance *instance,
 {
 	struct fusion_context *fusion;
 	struct MR_LD_RAID  *raid;
-	u32         ld, stripSize, stripe_mask;
+	u32         stripSize, stripe_mask;
 	u64         endLba, endStrip, endRow, start_row, start_strip;
 	u64         regStart;
 	u32         regSize;
@@ -1163,6 +1163,7 @@ MR_BuildRaidContext(struct megasas_instance *instance,
 	u8	    retval = 0;
 	u8	    startlba_span = SPAN_INVALID;
 	u64 *pdBlock = &io_info->pdBlock;
+	u16	    ld;
 
 	ldStartBlock = io_info->ldStartBlock;
 	numBlocks = io_info->numBlocks;
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 9019b82..4aaf307 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1121,7 +1121,8 @@ megasas_sync_map_info(struct megasas_instance *instance)
 	int i;
 	struct megasas_cmd *cmd;
 	struct megasas_dcmd_frame *dcmd;
-	u32 size_sync_info, num_lds;
+	u16 num_lds;
+	u32 size_sync_info;
 	struct fusion_context *fusion;
 	struct MR_LD_TARGET_SYNC *ci = NULL;
 	struct MR_DRV_RAID_MAP_ALL *map;
@@ -1870,7 +1871,7 @@ megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len,
 		   struct MR_DRV_RAID_MAP_ALL *local_map_ptr, u32 ref_tag)
 {
 	struct MR_LD_RAID *raid;
-	u32 ld;
+	u16 ld;
 	u64 start_blk = io_info->pdBlock;
 	u8 *cdb = io_request->CDB.CDB32;
 	u32 num_blocks = io_info->numBlocks;
@@ -2303,10 +2304,11 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 
 	local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
 	ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
-	raid = MR_LdRaidGet(ld, local_map_ptr);
 
-	if ((MR_TargetIdToLdGet(device_id, local_map_ptr) >=
-		instance->fw_supported_vd_count) || (!fusion->fast_path_io)) {
+	if (ld < instance->fw_supported_vd_count)
+		raid = MR_LdRaidGet(ld, local_map_ptr);
+
+	if (!raid || (!fusion->fast_path_io)) {
 		io_request->RaidContext.raid_context.reg_lock_flags  = 0;
 		fp_possible = false;
 	} else {
@@ -2478,12 +2480,12 @@ static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance,
 {
 	u32 device_id;
 	struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
-	u16 pd_index = 0;
+	u16 pd_index = 0, ld;
 	struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
 	struct fusion_context *fusion = instance->ctrl_context;
 	u8                          span, physArm;
 	__le16                      devHandle;
-	u32                         ld, arRef, pd;
+	u32                         arRef, pd;
 	struct MR_LD_RAID                  *raid;
 	struct RAID_CONTEXT                *pRAID_Context;
 	u8 fp_possible = 1;
@@ -2506,10 +2508,11 @@ static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance,
 		ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
 		if (ld >= instance->fw_supported_vd_count)
 			fp_possible = 0;
-
-		raid = MR_LdRaidGet(ld, local_map_ptr);
-		if (!(raid->capability.fpNonRWCapable))
-			fp_possible = 0;
+		else {
+			raid = MR_LdRaidGet(ld, local_map_ptr);
+			if (!(raid->capability.fpNonRWCapable))
+				fp_possible = 0;
+		}
 	} else
 		fp_possible = 0;
 
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 20/39] megaraid_sas: Big endian RDPQ mode fix
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (18 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 19/39] megaraid_sas: MR_TargetIdToLdGet u8 to u16 and avoid invalid raid-map access Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 21/39] megaraid_sas: big endian support changes Shivasharan S
                   ` (18 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Fix if RDPQ mode enabled MR FW is deployed on big endian host machine,
driver does not setup reply address correctly.

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 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 4aaf307..b26ee85 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -580,7 +580,7 @@ megasas_alloc_rdpq_fusion(struct megasas_instance *instance)
 		}
 
 		fusion->rdpq_virt[i].RDPQBaseAddress =
-			fusion->reply_frames_desc_phys[i];
+			cpu_to_le64(fusion->reply_frames_desc_phys[i]);
 
 		reply_desc = fusion->reply_frames_desc[i];
 		for (j = 0; j < fusion->reply_q_depth; j++, reply_desc++)
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 21/39] megaraid_sas: big endian support changes
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (19 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 20/39] megaraid_sas: Big endian RDPQ mode fix Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-09 18:04   ` Kashyap Desai
  2017-02-08  9:29 ` [PATCH v2 22/39] megaraid_sas: avoid unaligned access in ioctl path Shivasharan S
                   ` (17 subsequent siblings)
  38 siblings, 1 reply; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Fix endiannes fixes for Ventura specific.

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_fp.c     |  15 ++--
 drivers/scsi/megaraid/megaraid_sas_fusion.c |  70 ++++++++++-------
 drivers/scsi/megaraid/megaraid_sas_fusion.h | 115 +++++++++++++++++-----------
 3 files changed, 122 insertions(+), 78 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
index 9d5d485..68582d9 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -210,7 +210,7 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 			le32_to_cpu(fw_map_dyn->desc_table_size),
 			le32_to_cpu(fw_map_dyn->desc_table_num_elements));
 		dev_dbg(&instance->pdev->dev, "drv map %p ldCount %d\n",
-			drv_map, fw_map_dyn->ld_count);
+			drv_map, le16_to_cpu(fw_map_dyn->ld_count));
 #endif
 		desc_table =
 		(struct MR_RAID_MAP_DESC_TABLE *)((void *)fw_map_dyn + le32_to_cpu(fw_map_dyn->desc_table_offset));
@@ -222,7 +222,8 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 		pDrvRaidMap->ldCount = (__le16)cpu_to_le16(ld_count);
 		pDrvRaidMap->fpPdIoTimeoutSec =
 			fw_map_dyn->fp_pd_io_timeout_sec;
-		pDrvRaidMap->totalSize = sizeof(struct MR_DRV_RAID_MAP_ALL);
+		pDrvRaidMap->totalSize =
+			cpu_to_le32(sizeof(struct MR_DRV_RAID_MAP_ALL));
 		/* point to actual data starting point*/
 		raid_map_data = (void *)fw_map_dyn +
 			le32_to_cpu(fw_map_dyn->desc_table_offset) +
@@ -234,11 +235,11 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 			dev_dbg(&instance->pdev->dev, "desc table %p\n",
 				desc_table);
 			dev_dbg(&instance->pdev->dev, "raidmap type %d, raidmapOffset 0x%x\n",
-				desc_table->raid_map_desc_type,
-				desc_table->raid_map_desc_offset);
+				le32_to_cpu(desc_table->raid_map_desc_type),
+				le32_to_cpu(desc_table->raid_map_desc_offset));
 			dev_dbg(&instance->pdev->dev, "raid map number of elements 0%x, raidmapsize 0x%x\n",
-				desc_table->raid_map_desc_elements,
-				desc_table->raid_map_desc_buffer_size);
+				le32_to_cpu(desc_table->raid_map_desc_elements),
+				le32_to_cpu(desc_table->raid_map_desc_buffer_size));
 #endif
 			switch (le32_to_cpu(desc_table->raid_map_desc_type)) {
 			case RAID_MAP_DESC_TYPE_DEVHDL_INFO:
@@ -263,7 +264,7 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 #endif
 			for (j = 0; j < le32_to_cpu(desc_table->raid_map_desc_elements); j++) {
 				pDrvRaidMap->ldTgtIdToLd[j] =
-				fw_map_dyn->ld_tgt_id_to_ld[j];
+					le16_to_cpu(fw_map_dyn->ld_tgt_id_to_ld[j]);
 #if VD_EXT_DEBUG
 				dev_dbg(&instance->pdev->dev, " %d drv ldTgtIdToLd %d\n",
 					j, pDrvRaidMap->ldTgtIdToLd[j]);
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index b26ee85..f8b4898 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -2080,7 +2080,7 @@ static void megasas_stream_detect(struct megasas_instance *instance,
 			 */
 			continue;
 
-		cmd->io_request->RaidContext.raid_context_g35.stream_detected = true;
+		SET_STREAM_DETECTED(cmd->io_request->RaidContext.raid_context_g35);
 		current_sd->next_seq_lba =
 		io_info->ldStartBlock + io_info->numBlocks;
 		/*
@@ -2154,7 +2154,8 @@ megasas_set_raidflag_cpu_affinity(union RAID_CONTEXT_UNION *praid_context,
 			/* Fast path cache by pass capable R0/R1 VD */
 			if ((raid->level <= 1) &&
 			    (raid->capability.fp_cache_bypass_capable)) {
-				rctx_g35->routing_flags.bits.sld = 1;
+				rctx_g35->routing_flags |=
+					(1 << MR_RAID_CTX_ROUTINGFLAGS_SLD_SHIFT);
 				rctx_g35->raid_flags =
 					(MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS
 					<< MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT);
@@ -2174,7 +2175,7 @@ megasas_set_raidflag_cpu_affinity(union RAID_CONTEXT_UNION *praid_context,
 			else if (raid->cpuAffinity.ldWrite.cpu1)
 				cpu_sel = MR_RAID_CTX_CPUSEL_1;
 
-			if (rctx_g35->stream_detected &&
+			if (is_stream_detected(rctx_g35) &&
 			    (raid->level == 5) &&
 			    (raid->writeMode == MR_RL_WRITE_THROUGH_MODE) &&
 			    (cpu_sel == MR_RAID_CTX_CPUSEL_FCFS))
@@ -2182,7 +2183,8 @@ megasas_set_raidflag_cpu_affinity(union RAID_CONTEXT_UNION *praid_context,
 		}
 	}
 
-	rctx_g35->routing_flags.bits.cpu_sel = cpu_sel;
+	rctx_g35->routing_flags |=
+		(cpu_sel << MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT);
 
 	/* Always give priority to MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT
 	 * vs MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS.
@@ -2333,7 +2335,7 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 		/* In ventura if stream detected for a read and it is read ahead
 		 *  capable make this IO as LDIO
 		 */
-		if (praid_context->raid_context_g35.stream_detected &&
+		if (is_stream_detected(&io_request->RaidContext.raid_context_g35) &&
 		    io_info.isRead && io_info.ra_capable)
 			fp_possible = false;
 
@@ -2368,8 +2370,8 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 				raid, fp_possible, io_info.isRead,
 				scsi_buff_len);
 		else
-			praid_context->raid_context_g35.routing_flags.bits.cpu_sel =
-				MR_RAID_CTX_CPUSEL_0;
+			praid_context->raid_context_g35.routing_flags |=
+				(MR_RAID_CTX_CPUSEL_0 << MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT);
 	}
 
 	if (fp_possible) {
@@ -2393,12 +2395,14 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 			  (MR_RL_FLAGS_GRANT_DESTINATION_CUDA |
 			   MR_RL_FLAGS_SEQ_NUM_ENABLE);
 		} else if (instance->is_ventura) {
-			io_request->RaidContext.raid_context_g35.type
-				= MPI2_TYPE_CUDA;
-			io_request->RaidContext.raid_context_g35.nseg = 0x1;
-			io_request->RaidContext.raid_context_g35.routing_flags.bits.sqn = 1;
+			io_request->RaidContext.raid_context_g35.nseg_type |=
+						(1 << RAID_CONTEXT_NSEG_SHIFT);
+			io_request->RaidContext.raid_context_g35.nseg_type |=
+						(MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT);
+			io_request->RaidContext.raid_context_g35.routing_flags |=
+						(1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
 			io_request->IoFlags |=
-			cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
+				cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
 		}
 		if (fusion->load_balance_info &&
 			(fusion->load_balance_info[device_id].loadBalanceFlag) &&
@@ -2456,10 +2460,12 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
 				 MR_RL_FLAGS_SEQ_NUM_ENABLE);
 			io_request->RaidContext.raid_context.nseg = 0x1;
 		} else if (instance->is_ventura) {
-			io_request->RaidContext.raid_context_g35.type
-				= MPI2_TYPE_CUDA;
-			io_request->RaidContext.raid_context_g35.routing_flags.bits.sqn = 1;
-			io_request->RaidContext.raid_context_g35.nseg = 0x1;
+			io_request->RaidContext.raid_context_g35.routing_flags |=
+					(1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
+			io_request->RaidContext.raid_context_g35.nseg_type |=
+					(1 << RAID_CONTEXT_NSEG_SHIFT);
+			io_request->RaidContext.raid_context_g35.nseg_type |=
+					(MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT);
 		}
 		io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
 		io_request->DevHandle = cpu_to_le16(device_id);
@@ -2609,17 +2615,23 @@ megasas_build_syspd_fusion(struct megasas_instance *instance,
 			pRAID_Context->virtual_disk_tgt_id =
 				pd_sync->seq[pd_index].pd_target_id;
 		else
-		pRAID_Context->virtual_disk_tgt_id =
-			cpu_to_le16(device_id + (MAX_PHYSICAL_DEVICES - 1));
+			pRAID_Context->virtual_disk_tgt_id =
+				cpu_to_le16(device_id + (MAX_PHYSICAL_DEVICES - 1));
 		pRAID_Context->config_seq_num = pd_sync->seq[pd_index].seqNum;
 		io_request->DevHandle = pd_sync->seq[pd_index].devHandle;
-		if (instance->is_ventura)
-			io_request->RaidContext.raid_context_g35.routing_flags.bits.sqn = 1;
-		else
-		pRAID_Context->reg_lock_flags |=
-			(MR_RL_FLAGS_SEQ_NUM_ENABLE|MR_RL_FLAGS_GRANT_DESTINATION_CUDA);
-		pRAID_Context->type = MPI2_TYPE_CUDA;
-		pRAID_Context->nseg = 0x1;
+		if (instance->is_ventura) {
+			io_request->RaidContext.raid_context_g35.routing_flags |=
+				(1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
+			io_request->RaidContext.raid_context_g35.nseg_type |=
+							(1 << RAID_CONTEXT_NSEG_SHIFT);
+			io_request->RaidContext.raid_context_g35.nseg_type |=
+							(MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT);
+		} else {
+			pRAID_Context->type = MPI2_TYPE_CUDA;
+			pRAID_Context->nseg = 0x1;
+			pRAID_Context->reg_lock_flags |=
+				(MR_RL_FLAGS_SEQ_NUM_ENABLE|MR_RL_FLAGS_GRANT_DESTINATION_CUDA);
+		}
 	} else if (fusion->fast_path_io) {
 		pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
 		pRAID_Context->config_seq_num = 0;
@@ -2734,9 +2746,11 @@ megasas_build_io_fusion(struct megasas_instance *instance,
 		return 1;
 	}
 
-	if (instance->is_ventura)
-		io_request->RaidContext.raid_context_g35.num_sge = sge_count;
-	else {
+	if (instance->is_ventura) {
+		set_num_sge(io_request->RaidContext.raid_context_g35, sge_count);
+		cpu_to_le16s(&io_request->RaidContext.raid_context_g35.routing_flags);
+		cpu_to_le16s(&io_request->RaidContext.raid_context_g35.nseg_type);
+	} else {
 		/* numSGE store lower 8 bit of sge_count.
 		 * numSGEExt store higher 8 bit of sge_count
 		 */
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
index f25a262..6c22337 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
@@ -148,44 +148,13 @@ struct RAID_CONTEXT {
  * starts in MPT IO Frames
  */
 struct RAID_CONTEXT_G35 {
-#if   defined(__BIG_ENDIAN_BITFIELD)
-	u16	resvd0:8;
-	u16	nseg:4;
-	u16	type:4;
-#else
-	u16	type:4;		    /* 0x00 */
-	u16	nseg:4;		    /* 0x00 */
-	u16 resvd0:8;
-#endif
+	#define RAID_CONTEXT_NSEG_MASK	0x00F0
+	#define RAID_CONTEXT_NSEG_SHIFT	4
+	#define RAID_CONTEXT_TYPE_MASK	0x000F
+	#define RAID_CONTEXT_TYPE_SHIFT	0
+	u16		nseg_type;
 	u16 timeout_value; /* 0x02 -0x03 */
-	union {
-		struct {
-#if	defined(__BIG_ENDIAN_BITFIELD)
-		u16	set_divert:4;
-		u16	cpu_sel:4;
-		u16	log:1;
-		u16	rw:1;
-		u16	sbs:1;
-		u16	sqn:1;
-		u16	fwn:1;
-		u16	c2f:1;
-		u16	sld:1;
-		u16	reserved:1;
-#else
-		u16	reserved:1;
-		u16	sld:1;
-		u16	c2f:1;
-		u16	fwn:1;
-		u16	sqn:1;
-		u16	sbs:1;
-		u16	rw:1;
-		u16	log:1;
-		u16	cpu_sel:4;
-		u16	set_divert:4;
-#endif
-			} bits;
-		u16 s;
-	} routing_flags;	/* 0x04 -0x05 routing flags */
+	u16		routing_flags;	// 0x04 -0x05 routing flags
 	u16 virtual_disk_tgt_id;   /* 0x06 -0x07 */
 	u64 reg_lock_row_lba;      /* 0x08 - 0x0F */
 	u32 reg_lock_length;      /* 0x10 - 0x13 */
@@ -200,18 +169,78 @@ struct RAID_CONTEXT_G35 {
 				 */
 	u8 span_arm;            /* 0x1C span[7:5], arm[4:0] */
 	u16	config_seq_num;           /* 0x1A -0x1B */
+	union {
+		/*
+		 * Bit format:
+		 *	 ---------------------------------
+		 *	 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+		 *	 ---------------------------------
+		 * Byte0 |    numSGE[7]- numSGE[0]	 |
+		 *	 ---------------------------------
+		 * Byte1 |SD | resvd     | numSGE 8-11   |
+		 *        --------------------------------
+		 */
+		#define NUM_SGE_MASK_LOWER	0xFF
+		#define NUM_SGE_MASK_UPPER	0x0F
+		#define NUM_SGE_SHIFT_UPPER	8
+		#define STREAM_DETECT_SHIFT	7
+		#define STREAM_DETECT_MASK	0x80
+		struct {
 #if   defined(__BIG_ENDIAN_BITFIELD) /* 0x1C - 0x1D */
-	u16 stream_detected:1;
-	u16 reserved:3;
-	u16 num_sge:12;
+			u16 stream_detected:1;
+			u16 reserved:3;
+			u16 num_sge:12;
 #else
-	u16 num_sge:12;
-	u16 reserved:3;
-	u16 stream_detected:1;
+			u16 num_sge:12;
+			u16 reserved:3;
+			u16 stream_detected:1;
 #endif
+		} bits;
+		u8 bytes[2];
+	} u;
 	u8 resvd2[2];          /* 0x1E-0x1F */
 };
 
+#define MR_RAID_CTX_ROUTINGFLAGS_SLD_SHIFT	1
+#define MR_RAID_CTX_ROUTINGFLAGS_C2D_SHIFT	2
+#define MR_RAID_CTX_ROUTINGFLAGS_FWD_SHIFT	3
+#define MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT	4
+#define MR_RAID_CTX_ROUTINGFLAGS_SBS_SHIFT	5
+#define MR_RAID_CTX_ROUTINGFLAGS_RW_SHIFT	6
+#define MR_RAID_CTX_ROUTINGFLAGS_LOG_SHIFT	7
+#define MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT	8
+#define MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_MASK	0x0F00
+#define MR_RAID_CTX_ROUTINGFLAGS_SETDIVERT_SHIFT	12
+#define MR_RAID_CTX_ROUTINGFLAGS_SETDIVERT_MASK	0xF000
+
+static inline void set_num_sge(struct RAID_CONTEXT_G35 rctx_g35,
+			       u16 sge_count)
+{
+	rctx_g35.u.bytes[0] = (u8)(sge_count & NUM_SGE_MASK_LOWER);
+	rctx_g35.u.bytes[1] |= (u8)((sge_count >> NUM_SGE_SHIFT_UPPER)
+							& NUM_SGE_MASK_UPPER);
+}
+
+static inline u16 get_num_sge(struct RAID_CONTEXT_G35 rctx_g35)
+{
+	u16 sge_count;
+
+	sge_count = (u16)(((rctx_g35.u.bytes[1] & NUM_SGE_MASK_UPPER)
+			<< NUM_SGE_SHIFT_UPPER) | (rctx_g35.u.bytes[0]));
+	return sge_count;
+}
+
+#define SET_STREAM_DETECTED(rctx_g35) \
+	(rctx_g35.u.bytes[1] |= STREAM_DETECT_MASK)
+
+#define CLEAR_STREAM_DETECTED(rctx_g35) \
+	(rctx_g35.u.bytes[1] &= ~(STREAM_DETECT_MASK))
+
+static inline bool is_stream_detected(struct RAID_CONTEXT_G35 *rctx_g35)
+{
+	return ((rctx_g35->u.bytes[1] & STREAM_DETECT_MASK));
+}
+
 union RAID_CONTEXT_UNION {
 	struct RAID_CONTEXT raid_context;
 	struct RAID_CONTEXT_G35 raid_context_g35;
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 22/39] megaraid_sas: avoid unaligned access in ioctl path
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (20 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 21/39] megaraid_sas: big endian support changes Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 23/39] megaraid_sas: latest controller OCR capability from FW before sending shutdown DCMD Shivasharan S
                   ` (16 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Fix kernel warning for accessing unaligned memory access in driver.

Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 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 b2da257..5d7aa05 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -43,6 +43,7 @@
 #include <linux/uio.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
+#include <asm/unaligned.h>
 #include <linux/fs.h>
 #include <linux/compat.h>
 #include <linux/blkdev.h>
@@ -7007,7 +7008,8 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
 		sense_ptr = (unsigned long *) ((unsigned long)ioc->frame.raw +
 				ioc->sense_off);
 
-		if (copy_to_user((void __user *)((unsigned long)(*sense_ptr)),
+		if (copy_to_user((void __user *)((unsigned long)
+				 get_unaligned((unsigned long *)sense_ptr)),
 				 sense, ioc->sense_len)) {
 			dev_err(&instance->pdev->dev, "Failed to copy out to user "
 					"sense data\n");
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 23/39] megaraid_sas: latest controller OCR capability from FW before sending shutdown DCMD
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (21 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 22/39] megaraid_sas: avoid unaligned access in ioctl path Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 24/39] megaraid_sas: set pd_after_lb from MR_BuildRaidContext and initialize pDevHandle to MR_DEVHANDLE_INVALID Shivasharan S
                   ` (15 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Fetch the latest controller OCR capability from FW before
sending MR_DCMD_CTRL_SHUTDOWN
When application sends a shutdown DCMD (MR_DCMD_CTRL_SHUTDOWN),
driver will fetch latest controller information from firmware.
This is to ensure that driver always has latest OCR capability
of controller before sending the DCMD.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 5d7aa05..cd9d223 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -6900,6 +6900,13 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
 					       MFI_FRAME_SGL64 |
 					       MFI_FRAME_SENSE64));
 
+	if (cmd->frame->dcmd.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) {
 		error = megasas_set_crash_dump_params_ioctl(cmd);
 		megasas_return_cmd(instance, cmd);
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 24/39] megaraid_sas: set pd_after_lb from MR_BuildRaidContext and initialize pDevHandle to MR_DEVHANDLE_INVALID
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (22 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 23/39] megaraid_sas: latest controller OCR capability from FW before sending shutdown DCMD Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 25/39] megaraid_sas: Change max_cmd from u32 to u16 in all functions Shivasharan S
                   ` (14 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Issue is limited for Syncro firmware where pd_after_lb is not set but is accidentally used.
Not a functional issue, but results in low performance due to improper load balancing between two LUNs.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_fp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
index 68582d9..a5517e7 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -948,6 +948,7 @@ static u8 mr_spanset_get_phy_params(struct megasas_instance *instance, u32 ld,
 	struct fusion_context *fusion;
 
 	fusion = instance->ctrl_context;
+	*pDevHandle = cpu_to_le16(MR_DEVHANDLE_INVALID);
 
 	/*Get row and span from io_info for Uneven Span IO.*/
 	row	    = io_info->start_row;
@@ -986,7 +987,6 @@ static u8 mr_spanset_get_phy_params(struct megasas_instance *instance, u32 ld,
 				MR_PdDevHandleGet(r1_alt_pd, map);
 		}
 	} else {
-		*pDevHandle = cpu_to_le16(MR_DEVHANDLE_INVALID);
 		if ((raid->level >= 5) &&
 			((fusion->adapter_type == THUNDERBOLT_SERIES)  ||
 			((fusion->adapter_type == INVADER_SERIES) &&
@@ -1013,6 +1013,7 @@ static u8 mr_spanset_get_phy_params(struct megasas_instance *instance, u32 ld,
 			(span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
 		io_info->span_arm = pRAID_Context->span_arm;
 	}
+	io_info->pd_after_lb = pd;
 	return retval;
 }
 
@@ -1049,7 +1050,7 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 ld, u64 stripRow,
 	struct fusion_context *fusion;
 
 	fusion = instance->ctrl_context;
-
+	*pDevHandle = cpu_to_le16(MR_DEVHANDLE_INVALID);
 
 	row =  mega_div64_32(stripRow, raid->rowDataSize);
 
@@ -1102,8 +1103,6 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 ld, u64 stripRow,
 					MR_PdDevHandleGet(r1_alt_pd, map);
 		}
 	} else {
-		/* set dev handle as invalid. */
-		*pDevHandle = cpu_to_le16(MR_DEVHANDLE_INVALID);
 		if ((raid->level >= 5) &&
 			((fusion->adapter_type == THUNDERBOLT_SERIES)  ||
 			((fusion->adapter_type == INVADER_SERIES) &&
@@ -1132,6 +1131,7 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 ld, u64 stripRow,
 			(span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
 		io_info->span_arm = pRAID_Context->span_arm;
 	}
+	io_info->pd_after_lb = pd;
 	return retval;
 }
 
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 25/39] megaraid_sas: Change max_cmd from u32 to u16 in all functions
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (23 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 24/39] megaraid_sas: set pd_after_lb from MR_BuildRaidContext and initialize pDevHandle to MR_DEVHANDLE_INVALID Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 26/39] megaraid_sas: update can_queue only if the new value is less Shivasharan S
                   ` (13 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Since maximum supported FW commands are all defined as u16, change
all local variables referring to max_cmd from u32 to u16.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_base.c   | 10 +++++-----
 drivers/scsi/megaraid/megaraid_sas_fusion.c |  5 +++--
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index cd9d223..06001b4 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -1549,7 +1549,7 @@ megasas_dump_pending_frames(struct megasas_instance *instance)
 	struct megasas_io_frame *ldio;
 	struct megasas_pthru_frame *pthru;
 	u32 sgcount;
-	u32 max_cmd = instance->max_fw_cmds;
+	u16 max_cmd = instance->max_fw_cmds;
 
 	dev_err(&instance->pdev->dev, "[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no);
 	dev_err(&instance->pdev->dev, "[%d]: Total OS Pending cmds : %d\n",instance->host->host_no,atomic_read(&instance->fw_outstanding));
@@ -3467,7 +3467,7 @@ megasas_internal_reset_defer_cmds(struct megasas_instance *instance)
 {
 	struct megasas_cmd *cmd;
 	int i;
-	u32 max_cmd = instance->max_fw_cmds;
+	u16 max_cmd = instance->max_fw_cmds;
 	u32 defer_index;
 	unsigned long flags;
 
@@ -3843,7 +3843,7 @@ megasas_transition_to_ready(struct megasas_instance *instance, int ocr)
 static void megasas_teardown_frame_pool(struct megasas_instance *instance)
 {
 	int i;
-	u32 max_cmd = instance->max_mfi_cmds;
+	u16 max_cmd = instance->max_mfi_cmds;
 	struct megasas_cmd *cmd;
 
 	if (!instance->frame_dma_pool)
@@ -3887,7 +3887,7 @@ static void megasas_teardown_frame_pool(struct megasas_instance *instance)
 static int megasas_create_frame_pool(struct megasas_instance *instance)
 {
 	int i;
-	u32 max_cmd;
+	u16 max_cmd;
 	u32 sge_sz;
 	u32 total_sz;
 	u32 frame_count;
@@ -4021,7 +4021,7 @@ int megasas_alloc_cmds(struct megasas_instance *instance)
 {
 	int i;
 	int j;
-	u32 max_cmd;
+	u16 max_cmd;
 	struct megasas_cmd *cmd;
 	struct fusion_context *fusion;
 
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index f8b4898..b8591de 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -367,7 +367,7 @@ megasas_free_cmds_fusion(struct megasas_instance *instance)
 static int megasas_create_sg_sense_fusion(struct megasas_instance *instance)
 {
 	int i;
-	u32 max_cmd;
+	u16 max_cmd;
 	struct fusion_context *fusion;
 	struct megasas_cmd_fusion *cmd;
 
@@ -1274,7 +1274,8 @@ megasas_init_adapter_fusion(struct megasas_instance *instance)
 {
 	struct megasas_register_set __iomem *reg_set;
 	struct fusion_context *fusion;
-	u32 max_cmd, scratch_pad_2;
+	u16 max_cmd;
+	u32 scratch_pad_2;
 	int i = 0, count;
 
 	fusion = instance->ctrl_context;
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 26/39] megaraid_sas: update can_queue only if the new value is less
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (24 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 25/39] megaraid_sas: Change max_cmd from u32 to u16 in all functions Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 27/39] megaraid_sas: max_fw_cmds are decremented twice, remove duplicate Shivasharan S
                   ` (12 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Minor Optimization: No need to update HBA can_queue value
if the current max FW commands is equal to earlier value.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 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 b8591de..02a23d9 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -259,7 +259,7 @@ megasas_fusion_update_can_queue(struct megasas_instance *instance, int fw_boot_c
 
 	if (fw_boot_context == OCR_CONTEXT) {
 		cur_max_fw_cmds = cur_max_fw_cmds - 1;
-		if (cur_max_fw_cmds <= instance->max_fw_cmds) {
+		if (cur_max_fw_cmds < instance->max_fw_cmds) {
 			instance->cur_can_queue =
 				cur_max_fw_cmds - (MEGASAS_FUSION_INTERNAL_CMDS +
 						MEGASAS_FUSION_IOCTL_CMDS);
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 27/39] megaraid_sas: max_fw_cmds are decremented twice, remove duplicate
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (25 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 26/39] megaraid_sas: update can_queue only if the new value is less Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 28/39] megaraid_sas: megasas_return_cmd does not memset IO frame to zero Shivasharan S
                   ` (11 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Fix to account for the reply_q_sz not exceeding
the maximum commands that the firmware can support,
instance->max_fw_cmds is already decremented in
megasas_fusion_update_can_queue().
Remove the extra decrement logic in code.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 02a23d9..9e2a289 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1285,13 +1285,6 @@ megasas_init_adapter_fusion(struct megasas_instance *instance)
 	megasas_fusion_update_can_queue(instance, PROBE_CONTEXT);
 
 	/*
-	 * Reduce the max supported cmds by 1. This is to ensure that the
-	 * reply_q_sz (1 more than the max cmd that driver may send)
-	 * does not exceed max cmds that the FW can support
-	 */
-	instance->max_fw_cmds = instance->max_fw_cmds-1;
-
-	/*
 	 * Only Driver's internal DCMDs and IOCTL DCMDs needs to have MFI frames
 	 */
 	instance->max_mfi_cmds =
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 28/39] megaraid_sas: megasas_return_cmd does not memset IO frame to zero
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (26 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 27/39] megaraid_sas: max_fw_cmds are decremented twice, remove duplicate Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 29/39] megaraid_sas: Remove unused pd_index from megasas_build_ld_nonrw_fusion Shivasharan S
                   ` (10 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Memset the IO frame to zero after release.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas.h      |  1 +
 drivers/scsi/megaraid/megaraid_sas_base.c | 10 ++++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index efc01a3..508516d 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -2238,6 +2238,7 @@ struct megasas_instance {
 	u8 is_rdpq;
 	bool dev_handle;
 	bool fw_sync_cache_support;
+	u32 mfi_frame_size;
 	bool is_ventura;
 	bool msix_combined;
 	u16 max_raid_mapsize;
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 06001b4..30e390c 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -268,6 +268,8 @@ megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
 	cmd->scmd = NULL;
 	cmd->frame_count = 0;
 	cmd->flags = 0;
+	memset(cmd->frame, 0, instance->mfi_frame_size);
+	cmd->frame->io.context = cpu_to_le32(cmd->index);
 	if (!fusion && reset_devices)
 		cmd->frame->hdr.cmd = MFI_CMD_INVALID;
 	list_add(&cmd->list, (&instance->cmd_pool)->next);
@@ -3889,7 +3891,6 @@ static int megasas_create_frame_pool(struct megasas_instance *instance)
 	int i;
 	u16 max_cmd;
 	u32 sge_sz;
-	u32 total_sz;
 	u32 frame_count;
 	struct megasas_cmd *cmd;
 
@@ -3917,12 +3918,13 @@ static int megasas_create_frame_pool(struct megasas_instance *instance)
 	 * Total 192 byte (3 MFI frame of 64 byte)
 	 */
 	frame_count = instance->ctrl_context ? (3 + 1) : (15 + 1);
-	total_sz = MEGAMFI_FRAME_SIZE * frame_count;
+	instance->mfi_frame_size = MEGAMFI_FRAME_SIZE * frame_count;
 	/*
 	 * Use DMA pool facility provided by PCI layer
 	 */
 	instance->frame_dma_pool = pci_pool_create("megasas frame pool",
-					instance->pdev, total_sz, 256, 0);
+					instance->pdev, instance->mfi_frame_size,
+					256, 0);
 
 	if (!instance->frame_dma_pool) {
 		dev_printk(KERN_DEBUG, &instance->pdev->dev, "failed to setup frame pool\n");
@@ -3966,7 +3968,7 @@ static int megasas_create_frame_pool(struct megasas_instance *instance)
 			return -ENOMEM;
 		}
 
-		memset(cmd->frame, 0, total_sz);
+		memset(cmd->frame, 0, instance->mfi_frame_size);
 		cmd->frame->io.context = cpu_to_le32(cmd->index);
 		cmd->frame->io.pad_0 = 0;
 		if (!instance->ctrl_context && reset_devices)
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 29/39] megaraid_sas: Remove unused pd_index from megasas_build_ld_nonrw_fusion
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (27 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 28/39] megaraid_sas: megasas_return_cmd does not memset IO frame to zero Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 30/39] megaraid_sas: Do not set fp_possible if TM capable for non-RW syspdIO, change fp_possible to bool Shivasharan S
                   ` (9 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 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 9e2a289..04a4c43 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -2480,7 +2480,7 @@ static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance,
 {
 	u32 device_id;
 	struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
-	u16 pd_index = 0, ld;
+	u16 ld;
 	struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
 	struct fusion_context *fusion = instance->ctrl_context;
 	u8                          span, physArm;
@@ -2492,7 +2492,6 @@ static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance,
 
 	io_request = cmd->io_request;
 	device_id = MEGASAS_DEV_INDEX(scmd);
-	pd_index = MEGASAS_PD_INDEX(scmd);
 	local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
 	io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
 	/* get RAID_Context pointer */
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 30/39] megaraid_sas: Do not set fp_possible if TM capable for non-RW syspdIO, change fp_possible to bool
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (28 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 29/39] megaraid_sas: Remove unused pd_index from megasas_build_ld_nonrw_fusion Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 31/39] megaraid_sas: During OCR, if get_ctrl_info fails do not continue with OCR Shivasharan S
                   ` (8 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

FIX - firmware wants non-RW SYS PD IOs to avoid FastPath for
better tracking and other functionalities if the device
is task management capable.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 04a4c43..207df1e 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -2566,7 +2566,8 @@ static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance,
  */
 static void
 megasas_build_syspd_fusion(struct megasas_instance *instance,
-	struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd, u8 fp_possible)
+	struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd,
+	bool fp_possible)
 {
 	u32 device_id;
 	struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
@@ -2687,6 +2688,8 @@ megasas_build_io_fusion(struct megasas_instance *instance,
 	int sge_count;
 	u8  cmd_type;
 	struct MPI2_RAID_SCSI_IO_REQUEST *io_request = cmd->io_request;
+	struct MR_PRIV_DEVICE *mr_device_priv_data;
+	mr_device_priv_data = scp->device->hostdata;
 
 	/* Zero out some fields so they don't get reused */
 	memset(io_request->LUN, 0x0, 8);
@@ -2715,12 +2718,14 @@ megasas_build_io_fusion(struct megasas_instance *instance,
 		megasas_build_ld_nonrw_fusion(instance, scp, cmd);
 		break;
 	case READ_WRITE_SYSPDIO:
+		megasas_build_syspd_fusion(instance, scp, cmd, true);
+		break;
 	case NON_READ_WRITE_SYSPDIO:
-		if (instance->secure_jbod_support &&
-			(cmd_type == NON_READ_WRITE_SYSPDIO))
-			megasas_build_syspd_fusion(instance, scp, cmd, 0);
+		if (instance->secure_jbod_support ||
+		    mr_device_priv_data->is_tm_capable)
+			megasas_build_syspd_fusion(instance, scp, cmd, false);
 		else
-			megasas_build_syspd_fusion(instance, scp, cmd, 1);
+			megasas_build_syspd_fusion(instance, scp, cmd, true);
 		break;
 	default:
 		break;
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 31/39] megaraid_sas: During OCR, if get_ctrl_info fails do not continue with OCR
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (29 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 30/39] megaraid_sas: Do not set fp_possible if TM capable for non-RW syspdIO, change fp_possible to bool Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 32/39] megaraid_sas: Change build_mpt_mfi_pass_thru to return void Shivasharan S
                   ` (7 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Error handling: If controller reset is not able to
recover, kill HBA and quit immediately.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 207df1e..00e52a3 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -4285,6 +4285,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason)
 					__func__, __LINE__);
 				megaraid_sas_kill_hba(instance);
 				retval = FAILED;
+				goto out;
 			}
 			/* Reset load balance info */
 			if (fusion->load_balance_info)
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 32/39] megaraid_sas: Change build_mpt_mfi_pass_thru to return void
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (30 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 31/39] megaraid_sas: During OCR, if get_ctrl_info fails do not continue with OCR Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 33/39] megaraid_sas: Bail out the driver load if ld_list_query fails Shivasharan S
                   ` (6 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Code refactoring to build_mpt_mfi_pass_thru to return void.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 00e52a3..b69200b 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3229,7 +3229,7 @@ irqreturn_t megasas_isr_fusion(int irq, void *devp)
  * mfi_cmd:			megasas_cmd pointer
  *
  */
-u8
+void
 build_mpt_mfi_pass_thru(struct megasas_instance *instance,
 			struct megasas_cmd *mfi_cmd)
 {
@@ -3279,8 +3279,6 @@ build_mpt_mfi_pass_thru(struct megasas_instance *instance,
 		MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR;
 
 	mpi25_ieee_chain->Length = cpu_to_le32(instance->max_chain_frame_sz);
-
-	return 0;
 }
 
 /**
@@ -3295,11 +3293,7 @@ build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
 	union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc = NULL;
 	u16 index;
 
-	if (build_mpt_mfi_pass_thru(instance, cmd)) {
-		dev_err(&instance->pdev->dev, "Couldn't build MFI pass thru cmd\n");
-		return NULL;
-	}
-
+	build_mpt_mfi_pass_thru(instance, cmd);
 	index = cmd->context.smid;
 
 	req_desc = megasas_get_request_descriptor(instance, index - 1);
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 33/39] megaraid_sas: Bail out the driver load if ld_list_query fails
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (31 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 32/39] megaraid_sas: Change build_mpt_mfi_pass_thru to return void Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 34/39] megaraid_sas: Use synchronize_irq to wait for IRQs to complete Shivasharan S
                   ` (5 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Error handling: Bail out the driver load if
key FW cmds (LD_LIST) are not return successful.
Clean up error handling in megasas_init_fw.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 30e390c..0e7121d 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -5352,7 +5352,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
 		(MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)));
 	if (megasas_get_pd_list(instance) < 0) {
 		dev_err(&instance->pdev->dev, "failed to get PD list\n");
-		goto fail_get_pd_list;
+		goto fail_get_ld_pd_list;
 	}
 
 	memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS);
@@ -5388,7 +5388,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
 
 	if (megasas_ld_list_query(instance,
 				  MR_LD_QUERY_TYPE_EXPOSED_TO_HOST))
-		megasas_get_ld_list(instance);
+		goto fail_get_ld_pd_list;
 
 	/*
 	 * Compute the max allowed sectors per IO: The controller info has two
@@ -5507,8 +5507,6 @@ static int megasas_init_fw(struct megasas_instance *instance)
 
 fail_get_ld_pd_list:
 	instance->instancet->disable_intr(instance);
-fail_get_pd_list:
-	instance->instancet->disable_intr(instance);
 fail_init_adapter:
 	megasas_destroy_irqs(instance);
 fail_setup_irqs:
@@ -5520,9 +5518,11 @@ static int megasas_init_fw(struct megasas_instance *instance)
 	instance->ctrl_info = NULL;
 	iounmap(instance->reg_set);
 
-      fail_ioremap:
+fail_ioremap:
 	pci_release_selected_regions(instance->pdev, 1<<instance->bar);
 
+	dev_err(&instance->pdev->dev, "Failed from %s %d\n",
+		__func__, __LINE__);
 	return -EINVAL;
 }
 
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 34/39] megaraid_sas: Use synchronize_irq to wait for IRQs to complete
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (32 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 33/39] megaraid_sas: Bail out the driver load if ld_list_query fails Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 35/39] megaraid_sas: Increase internal command pool Shivasharan S
                   ` (4 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

FIX - Do not use random delay to synchronize with IRQ. Use kernel API.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index b69200b..a9a6e5d 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3145,6 +3145,22 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex)
 }
 
 /**
+ * megasas_sync_irqs -	Synchronizes all IRQs owned by adapter
+ * @instance:			Adapter soft state
+ */
+void megasas_sync_irqs(unsigned long instance_addr)
+{
+	u32 count, i;
+	struct megasas_instance *instance =
+		(struct megasas_instance *)instance_addr;
+
+	count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
+
+	for (i = 0; i < count; i++)
+		synchronize_irq(pci_irq_vector(instance->pdev, i));
+}
+
+/**
  * megasas_complete_cmd_dpc_fusion -	Completes command
  * @instance:			Adapter soft state
  *
@@ -3820,7 +3836,7 @@ megasas_issue_tm(struct megasas_instance *instance, u16 device_handle,
 			break;
 		else {
 			instance->instancet->disable_intr(instance);
-			msleep(1000);
+			megasas_sync_irqs((unsigned long)instance);
 			megasas_complete_cmd_dpc_fusion
 					((unsigned long)instance);
 			instance->instancet->enable_intr(instance);
@@ -4174,7 +4190,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason)
 	set_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
 	atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_POLLING);
 	instance->instancet->disable_intr(instance);
-	msleep(1000);
+	megasas_sync_irqs((unsigned long)instance);
 
 	/* First try waiting for commands to complete */
 	if (megasas_wait_for_outstanding_fusion(instance, reason,
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 35/39] megaraid_sas: Increase internal command pool
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (33 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 34/39] megaraid_sas: Use synchronize_irq to wait for IRQs to complete Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 36/39] megaraid_sas: Cleanup VD_EXT_DEBUG and SPAN_DEBUG related debug prints Shivasharan S
                   ` (3 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Fix - increase internal command pool to 8.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas.h        | 2 +-
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 508516d..42c0e1f 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -1460,7 +1460,7 @@ enum FW_BOOT_CONTEXT {
  */
 #define MEGASAS_INT_CMDS			32
 #define MEGASAS_SKINNY_INT_CMDS			5
-#define MEGASAS_FUSION_INTERNAL_CMDS		5
+#define MEGASAS_FUSION_INTERNAL_CMDS		8
 #define MEGASAS_FUSION_IOCTL_CMDS		3
 #define MEGASAS_MFI_IOCTL_CMDS			27
 
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index a9a6e5d..d8877c0 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1350,7 +1350,7 @@ megasas_init_adapter_fusion(struct megasas_instance *instance)
 		fusion->last_reply_idx[i] = 0;
 
 	/*
-	 * For fusion adapters, 3 commands for IOCTL and 5 commands
+	 * For fusion adapters, 3 commands for IOCTL and 8 commands
 	 * for driver's internal DCMDs.
 	 */
 	instance->max_scsi_cmds = instance->max_fw_cmds -
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 36/39] megaraid_sas: Cleanup VD_EXT_DEBUG and SPAN_DEBUG related debug prints
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (34 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 35/39] megaraid_sas: Increase internal command pool Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 37/39] megaraid_sas: Indentation and smatch warning fixes Shivasharan S
                   ` (2 subsequent siblings)
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas.h        |   2 -
 drivers/scsi/megaraid/megaraid_sas_base.c   |  15 --
 drivers/scsi/megaraid/megaraid_sas_fp.c     | 266 +---------------------------
 drivers/scsi/megaraid/megaraid_sas_fusion.c |   5 -
 4 files changed, 2 insertions(+), 286 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 42c0e1f..dc331e8 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -1403,8 +1403,6 @@ struct megasas_ctrl_info {
 
 #define MEGASAS_FW_BUSY				1
 
-#define VD_EXT_DEBUG 0
-
 /* Driver's internal Logging levels*/
 #define OCR_LOGS    (1 << 0)
 
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 0e7121d..5e0dea1 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -4601,17 +4601,6 @@ static void megasas_update_ext_vd_details(struct megasas_instance *instance)
 	}
 	/* irrespective of FW raid maps, driver raid map is constant */
 	fusion->drv_map_sz = sizeof(struct MR_DRV_RAID_MAP_ALL);
-
-#if VD_EXT_DEBUG
-	dev_info(&instance->pdev->dev, "instance->max_raid_mapsize 0x%x\n ",
-		instance->max_raid_mapsize);
-	dev_info(&instance->pdev->dev, "new_map_sz = 0x%x, old_map_sz = 0x%x\n",
-		fusion->new_map_sz, fusion->old_map_sz);
-	dev_info(&instance->pdev->dev, "ventura_map_sz = 0x%x, current_map_sz = 0x%x\n",
-		ventura_map_sz, fusion->current_map_sz);
-	dev_info(&instance->pdev->dev, "fusion->drv_map_sz =0x%x, size of driver raid map 0x%lx\n",
-		fusion->drv_map_sz, sizeof(struct MR_DRV_RAID_MAP_ALL));
-#endif
 }
 
 /**
@@ -5215,10 +5204,6 @@ static int megasas_init_fw(struct megasas_instance *instance)
 	if (instance->is_ventura) {
 		scratch_pad_3 =
 			readl(&instance->reg_set->outbound_scratch_pad_3);
-#if VD_EXT_DEBUG
-		dev_info(&instance->pdev->dev, "scratch_pad3 0x%x\n",
-			scratch_pad_3);
-#endif
 		instance->max_raid_mapsize = ((scratch_pad_3 >>
 			MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT) &
 			MR_MAX_RAID_MAP_SIZE_MASK);
diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
index a5517e7..7dc7708 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -77,7 +77,6 @@ MODULE_PARM_DESC(lb_pending_cmds, "Change raid-1 load balancing outstanding "
 #endif
 #define TRUE 1
 
-#define SPAN_DEBUG 0
 #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
@@ -202,16 +201,6 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 
 	if (instance->max_raid_mapsize) {
 		fw_map_dyn = fusion->ld_map[(instance->map_id & 1)];
-#if VD_EXT_DEBUG
-		dev_dbg(&instance->pdev->dev, "raidMapSize 0x%x fw_map_dyn->descTableOffset 0x%x\n",
-			le32_to_cpu(fw_map_dyn->raid_map_size),
-			le32_to_cpu(fw_map_dyn->desc_table_offset));
-		dev_dbg(&instance->pdev->dev, "descTableSize 0x%x descTableNumElements 0x%x\n",
-			le32_to_cpu(fw_map_dyn->desc_table_size),
-			le32_to_cpu(fw_map_dyn->desc_table_num_elements));
-		dev_dbg(&instance->pdev->dev, "drv map %p ldCount %d\n",
-			drv_map, le16_to_cpu(fw_map_dyn->ld_count));
-#endif
 		desc_table =
 		(struct MR_RAID_MAP_DESC_TABLE *)((void *)fw_map_dyn + le32_to_cpu(fw_map_dyn->desc_table_offset));
 		if (desc_table != fw_map_dyn->raid_map_desc_table)
@@ -230,25 +219,10 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 			le32_to_cpu(fw_map_dyn->desc_table_size);
 
 		for (i = 0; i < le32_to_cpu(fw_map_dyn->desc_table_num_elements); ++i) {
-
-#if VD_EXT_DEBUG
-			dev_dbg(&instance->pdev->dev, "desc table %p\n",
-				desc_table);
-			dev_dbg(&instance->pdev->dev, "raidmap type %d, raidmapOffset 0x%x\n",
-				le32_to_cpu(desc_table->raid_map_desc_type),
-				le32_to_cpu(desc_table->raid_map_desc_offset));
-			dev_dbg(&instance->pdev->dev, "raid map number of elements 0%x, raidmapsize 0x%x\n",
-				le32_to_cpu(desc_table->raid_map_desc_elements),
-				le32_to_cpu(desc_table->raid_map_desc_buffer_size));
-#endif
 			switch (le32_to_cpu(desc_table->raid_map_desc_type)) {
 			case RAID_MAP_DESC_TYPE_DEVHDL_INFO:
 				fw_map_dyn->dev_hndl_info =
 				(struct MR_DEV_HANDLE_INFO *)(raid_map_data + le32_to_cpu(desc_table->raid_map_desc_offset));
-#if VD_EXT_DEBUG
-				dev_dbg(&instance->pdev->dev, "devHndlInfo  address %p\n",
-					fw_map_dyn->dev_hndl_info);
-#endif
 				memcpy(pDrvRaidMap->devHndlInfo,
 				fw_map_dyn->dev_hndl_info,
 				sizeof(struct MR_DEV_HANDLE_INFO) *
@@ -258,28 +232,15 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 				fw_map_dyn->ld_tgt_id_to_ld =
 				(u16 *) (raid_map_data +
 				le32_to_cpu(desc_table->raid_map_desc_offset));
-#if VD_EXT_DEBUG
-			dev_dbg(&instance->pdev->dev, "ldTgtIdToLd  address %p\n",
-				fw_map_dyn->ld_tgt_id_to_ld);
-#endif
 			for (j = 0; j < le32_to_cpu(desc_table->raid_map_desc_elements); j++) {
 				pDrvRaidMap->ldTgtIdToLd[j] =
 					le16_to_cpu(fw_map_dyn->ld_tgt_id_to_ld[j]);
-#if VD_EXT_DEBUG
-				dev_dbg(&instance->pdev->dev, " %d drv ldTgtIdToLd %d\n",
-					j, pDrvRaidMap->ldTgtIdToLd[j]);
-#endif
 			}
 			break;
 			case RAID_MAP_DESC_TYPE_ARRAY_INFO:
 				fw_map_dyn->ar_map_info =
 				(struct MR_ARRAY_INFO *)
 				(raid_map_data + le32_to_cpu(desc_table->raid_map_desc_offset));
-#if VD_EXT_DEBUG
-				dev_dbg(&instance->pdev->dev, "arMapInfo  address %p\n",
-					fw_map_dyn->ar_map_info);
-#endif
-
 				memcpy(pDrvRaidMap->arMapInfo,
 				fw_map_dyn->ar_map_info,
 				sizeof(struct MR_ARRAY_INFO) * le32_to_cpu(desc_table->raid_map_desc_elements));
@@ -291,34 +252,6 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 				memcpy(pDrvRaidMap->ldSpanMap,
 				fw_map_dyn->ld_span_map,
 				sizeof(struct MR_LD_SPAN_MAP) * le32_to_cpu(desc_table->raid_map_desc_elements));
-#if VD_EXT_DEBUG
-				dev_dbg(&instance->pdev->dev, "ldSpanMap  address %p\n",
-					fw_map_dyn->ld_span_map);
-				dev_dbg(&instance->pdev->dev, "MR_LD_SPAN_MAP size 0x%lx\n",
-					sizeof(struct MR_LD_SPAN_MAP));
-				for (j = 0; j < ld_count; j++) {
-					dev_dbg(&instance->pdev->dev, "megaraid_sas(%d) : fw_map_dyn->ldSpanMap[%d].ldRaid.targetId 0x%x\n",
-					j, j, fw_map_dyn->ld_span_map[j].ldRaid.targetId);
-					dev_dbg(&instance->pdev->dev, "fw_map_dyn->ldSpanMap[%d].ldRaid.seqNum 0x%x\n",
-					j, fw_map_dyn->ld_span_map[j].ldRaid.seqNum);
-					dev_dbg(&instance->pdev->dev, "fw_map_dyn->ld_span_map[%d].ldRaid.rowSize 0x%x\n",
-					j, (u32)fw_map_dyn->ld_span_map[j].ldRaid.rowSize);
-
-					dev_dbg(&instance->pdev->dev, "megaraid_sas(%d) :pDrvRaidMap->ldSpanMap[%d].ldRaid.targetId 0x%x\n",
-					j, j, pDrvRaidMap->ldSpanMap[j].ldRaid.targetId);
-					dev_dbg(&instance->pdev->dev, "DrvRaidMap->ldSpanMap[%d].ldRaid.seqNum 0x%x\n",
-					j, pDrvRaidMap->ldSpanMap[j].ldRaid.seqNum);
-					dev_dbg(&instance->pdev->dev, "pDrvRaidMap->ldSpanMap[%d].ldRaid.rowSize 0x%x\n",
-					j, (u32)pDrvRaidMap->ldSpanMap[j].ldRaid.rowSize);
-
-					dev_dbg(&instance->pdev->dev, "megaraid_sas(%d) : drv raid map all %p\n",
-					instance->unique_id, drv_map);
-					dev_dbg(&instance->pdev->dev, "raid map %p LD RAID MAP %p/%p\n",
-					pDrvRaidMap,
-					&fw_map_dyn->ld_span_map[j].ldRaid,
-					&pDrvRaidMap->ldSpanMap[j].ldRaid);
-				}
-#endif
 			break;
 			default:
 				dev_dbg(&instance->pdev->dev, "wrong number of desctableElements %d\n",
@@ -335,17 +268,6 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 			dev_dbg(&instance->pdev->dev, "megaraid_sas: LD count exposed in RAID map in not valid\n");
 			return;
 		}
-#if VD_EXT_DEBUG
-		for (i = 0; i < ld_count; i++) {
-			dev_dbg(&instance->pdev->dev, "megaraid_sas(%d) :Index 0x%x\n",
-				instance->unique_id, i);
-			dev_dbg(&instance->pdev->dev, "Target Id 0x%x\n",
-				fw_map_ext->ldSpanMap[i].ldRaid.targetId);
-			dev_dbg(&instance->pdev->dev, "Seq Num 0x%x Size 0/%llx\n",
-				fw_map_ext->ldSpanMap[i].ldRaid.seqNum,
-				fw_map_ext->ldSpanMap[i].ldRaid.size);
-		}
-#endif
 
 		pDrvRaidMap->ldCount = (__le16)cpu_to_le16(ld_count);
 		pDrvRaidMap->fpPdIoTimeoutSec = fw_map_ext->fpPdIoTimeoutSec;
@@ -354,29 +276,6 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 				(u16)fw_map_ext->ldTgtIdToLd[i];
 		memcpy(pDrvRaidMap->ldSpanMap, fw_map_ext->ldSpanMap,
 				sizeof(struct MR_LD_SPAN_MAP) * ld_count);
-#if VD_EXT_DEBUG
-		for (i = 0; i < ld_count; i++) {
-			dev_dbg(&instance->pdev->dev, "megaraid_sas(%d) : fw_map_ext->ldSpanMap[%d].ldRaid.targetId 0x%x\n",
-			i, i, fw_map_ext->ldSpanMap[i].ldRaid.targetId);
-			dev_dbg(&instance->pdev->dev, "fw_map_ext->ldSpanMap[%d].ldRaid.seqNum 0x%x\n",
-			i, fw_map_ext->ldSpanMap[i].ldRaid.seqNum);
-			dev_dbg(&instance->pdev->dev, "fw_map_ext->ldSpanMap[%d].ldRaid.rowSize 0x%x\n",
-			i, (u32)fw_map_ext->ldSpanMap[i].ldRaid.rowSize);
-
-			dev_dbg(&instance->pdev->dev, "megaraid_sas(%d) : pDrvRaidMap->ldSpanMap[%d].ldRaid.targetId 0x%x\n",
-			i, i, pDrvRaidMap->ldSpanMap[i].ldRaid.targetId);
-			dev_dbg(&instance->pdev->dev, "pDrvRaidMap->ldSpanMap[%d].ldRaid.seqNum 0x%x\n",
-			i, pDrvRaidMap->ldSpanMap[i].ldRaid.seqNum);
-			dev_dbg(&instance->pdev->dev, "pDrvRaidMap->ldSpanMap[%d].ldRaid.rowSize 0x%x\n",
-			i, (u32)pDrvRaidMap->ldSpanMap[i].ldRaid.rowSize);
-
-			dev_dbg(&instance->pdev->dev, "megaraid_sas(%d) : drv raid map all %p\n",
-			instance->unique_id, drv_map);
-			dev_dbg(&instance->pdev->dev, "raid map %p LD RAID MAP %p %p\n",
-			pDrvRaidMap, &fw_map_ext->ldSpanMap[i].ldRaid,
-			&pDrvRaidMap->ldSpanMap[i].ldRaid);
-		}
-#endif
 		memcpy(pDrvRaidMap->arMapInfo, fw_map_ext->arMapInfo,
 			sizeof(struct MR_ARRAY_INFO) * MAX_API_ARRAYS_EXT);
 		memcpy(pDrvRaidMap->devHndlInfo, fw_map_ext->devHndlInfo,
@@ -393,18 +292,6 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 			fusion->ld_map[(instance->map_id & 1)];
 		pFwRaidMap = &fw_map_old->raidMap;
 		ld_count = (u16)le32_to_cpu(pFwRaidMap->ldCount);
-
-#if VD_EXT_DEBUG
-		for (i = 0; i < ld_count; i++) {
-			dev_dbg(&instance->pdev->dev, "(%d) :Index 0x%x "
-				"Target Id 0x%x Seq Num 0x%x Size 0/%llx\n",
-				instance->unique_id, i,
-				fw_map_old->raidMap.ldSpanMap[i].ldRaid.targetId,
-				fw_map_old->raidMap.ldSpanMap[i].ldRaid.seqNum,
-				fw_map_old->raidMap.ldSpanMap[i].ldRaid.size);
-		}
-#endif
-
 		pDrvRaidMap->totalSize = pFwRaidMap->totalSize;
 		pDrvRaidMap->ldCount = (__le16)cpu_to_le16(ld_count);
 		pDrvRaidMap->fpPdIoTimeoutSec = pFwRaidMap->fpPdIoTimeoutSec;
@@ -413,26 +300,6 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 				(u8)pFwRaidMap->ldTgtIdToLd[i];
 		for (i = 0; i < ld_count; i++) {
 			pDrvRaidMap->ldSpanMap[i] = pFwRaidMap->ldSpanMap[i];
-#if VD_EXT_DEBUG
-			dev_dbg(&instance->pdev->dev,
-				"pFwRaidMap->ldSpanMap[%d].ldRaid.targetId 0x%x "
-				"pFwRaidMap->ldSpanMap[%d].ldRaid.seqNum 0x%x "
-				"size 0x%x\n", i, i,
-				pFwRaidMap->ldSpanMap[i].ldRaid.targetId,
-				pFwRaidMap->ldSpanMap[i].ldRaid.seqNum,
-				(u32)pFwRaidMap->ldSpanMap[i].ldRaid.rowSize);
-			dev_dbg(&instance->pdev->dev,
-				"pDrvRaidMap->ldSpanMap[%d].ldRaid.targetId 0x%x "
-				"pDrvRaidMap->ldSpanMap[%d].ldRaid.seqNum 0x%x "
-				"size 0x%x\n", i, i,
-				pDrvRaidMap->ldSpanMap[i].ldRaid.targetId,
-				pDrvRaidMap->ldSpanMap[i].ldRaid.seqNum,
-				(u32)pDrvRaidMap->ldSpanMap[i].ldRaid.rowSize);
-			dev_dbg(&instance->pdev->dev, "Driver raid map all %p "
-				"raid map %p LD RAID MAP %p/%p\n", drv_map,
-				pDrvRaidMap, &pFwRaidMap->ldSpanMap[i].ldRaid,
-				&pDrvRaidMap->ldSpanMap[i].ldRaid);
-#endif
 		}
 		memcpy(pDrvRaidMap->arMapInfo, pFwRaidMap->arMapInfo,
 			sizeof(struct MR_ARRAY_INFO) * MAX_RAIDMAP_ARRAYS);
@@ -548,91 +415,6 @@ u32 MR_GetSpanBlock(u32 ld, u64 row, u64 *span_blk,
 /*
 ******************************************************************************
 *
-* Function to print info about span set created in driver from FW raid map
-*
-* Inputs :
-* map    - LD map
-* ldSpanInfo - ldSpanInfo per HBA instance
-*/
-#if SPAN_DEBUG
-static int getSpanInfo(struct MR_DRV_RAID_MAP_ALL *map,
-	PLD_SPAN_INFO ldSpanInfo)
-{
-
-	u8   span;
-	u32    element;
-	struct MR_LD_RAID *raid;
-	LD_SPAN_SET *span_set;
-	struct MR_QUAD_ELEMENT    *quad;
-	int ldCount;
-	u16 ld;
-
-	for (ldCount = 0; ldCount < MAX_LOGICAL_DRIVES_EXT; ldCount++) {
-		ld = MR_TargetIdToLdGet(ldCount, map);
-			if (ld >= (MAX_LOGICAL_DRIVES_EXT - 1))
-				continue;
-		raid = MR_LdRaidGet(ld, map);
-		dev_dbg(&instance->pdev->dev, "LD %x: span_depth=%x\n",
-			ld, raid->spanDepth);
-		for (span = 0; span < raid->spanDepth; span++)
-			dev_dbg(&instance->pdev->dev, "Span=%x,"
-			" number of quads=%x\n", span,
-			le32_to_cpu(map->raidMap.ldSpanMap[ld].spanBlock[span].
-			block_span_info.noElements));
-		for (element = 0; element < MAX_QUAD_DEPTH; element++) {
-			span_set = &(ldSpanInfo[ld].span_set[element]);
-			if (span_set->span_row_data_width == 0)
-				break;
-
-			dev_dbg(&instance->pdev->dev, "Span Set %x:"
-				"width=%x, diff=%x\n", element,
-				(unsigned int)span_set->span_row_data_width,
-				(unsigned int)span_set->diff);
-			dev_dbg(&instance->pdev->dev, "logical LBA"
-				"start=0x%08lx, end=0x%08lx\n",
-				(long unsigned int)span_set->log_start_lba,
-				(long unsigned int)span_set->log_end_lba);
-			dev_dbg(&instance->pdev->dev, "span row start=0x%08lx,"
-				" end=0x%08lx\n",
-				(long unsigned int)span_set->span_row_start,
-				(long unsigned int)span_set->span_row_end);
-			dev_dbg(&instance->pdev->dev, "data row start=0x%08lx,"
-				" end=0x%08lx\n",
-				(long unsigned int)span_set->data_row_start,
-				(long unsigned int)span_set->data_row_end);
-			dev_dbg(&instance->pdev->dev, "data strip start=0x%08lx,"
-				" end=0x%08lx\n",
-				(long unsigned int)span_set->data_strip_start,
-				(long unsigned int)span_set->data_strip_end);
-
-			for (span = 0; span < raid->spanDepth; span++) {
-				if (le32_to_cpu(map->raidMap.ldSpanMap[ld].spanBlock[span].
-					block_span_info.noElements) >=
-					element + 1) {
-					quad = &map->raidMap.ldSpanMap[ld].
-						spanBlock[span].block_span_info.
-						quad[element];
-				dev_dbg(&instance->pdev->dev, "Span=%x,"
-					"Quad=%x, diff=%x\n", span,
-					element, le32_to_cpu(quad->diff));
-				dev_dbg(&instance->pdev->dev,
-					"offset_in_span=0x%08lx\n",
-					(long unsigned int)le64_to_cpu(quad->offsetInSpan));
-				dev_dbg(&instance->pdev->dev,
-					"logical start=0x%08lx, end=0x%08lx\n",
-					(long unsigned int)le64_to_cpu(quad->logStart),
-					(long unsigned int)le64_to_cpu(quad->logEnd));
-				}
-			}
-		}
-	}
-	return 0;
-}
-#endif
-
-/*
-******************************************************************************
-*
 * This routine calculates the Span block for given row using spanset.
 *
 * Inputs :
@@ -743,19 +525,7 @@ static u64  get_row_from_strip(struct megasas_instance *instance,
 				else
 					break;
 			}
-#if SPAN_DEBUG
-		dev_info(&instance->pdev->dev, "Strip 0x%llx,"
-			"span_set_Strip 0x%llx, span_set_Row 0x%llx"
-			"data width 0x%llx span offset 0x%x\n", strip,
-			(unsigned long long)span_set_Strip,
-			(unsigned long long)span_set_Row,
-			(unsigned long long)span_set->span_row_data_width,
-			span_offset);
-		dev_info(&instance->pdev->dev, "For strip 0x%llx"
-			"row is 0x%llx\n", strip,
-			(unsigned long long) span_set->data_row_start +
-			(unsigned long long) span_set_Row + (span_offset - 1));
-#endif
+
 		retval = (span_set->data_row_start + span_set_Row +
 				(span_offset - 1));
 		return retval;
@@ -872,11 +642,7 @@ static u32 get_arm_from_strip(struct megasas_instance *instance,
 				else
 					break;
 			}
-#if SPAN_DEBUG
-		dev_info(&instance->pdev->dev, "get_arm_from_strip:"
-			"for ld=0x%x strip=0x%lx arm is  0x%x\n", ld,
-			(long unsigned int)strip, (strip_offset - span_offset));
-#endif
+
 		retval = (strip_offset - span_offset);
 		return retval;
 	}
@@ -1239,17 +1005,6 @@ MR_BuildRaidContext(struct megasas_instance *instance,
 		}
 		io_info->start_span	= startlba_span;
 		io_info->start_row	= start_row;
-#if SPAN_DEBUG
-		dev_dbg(&instance->pdev->dev, "Check Span number from %s %d"
-			"for row 0x%llx, start strip 0x%llx end strip 0x%llx"
-			" span 0x%x\n", __func__, __LINE__,
-			(unsigned long long)start_row,
-			(unsigned long long)start_strip,
-			(unsigned long long)endStrip, startlba_span);
-		dev_dbg(&instance->pdev->dev, "start_row 0x%llx endRow 0x%llx"
-			"Start span 0x%x\n", (unsigned long long)start_row,
-			(unsigned long long)endRow, startlba_span);
-#endif
 	} else {
 		start_row = mega_div64_32(start_strip, raid->rowDataSize);
 		endRow    = mega_div64_32(endStrip, raid->rowDataSize);
@@ -1383,12 +1138,6 @@ MR_BuildRaidContext(struct megasas_instance *instance,
 				return TRUE;
 		}
 	}
-
-#if SPAN_DEBUG
-	/* Just for testing what arm we get for strip.*/
-	if (io_info->IoforUnevenSpan)
-		get_arm_from_strip(instance, ld, start_strip, map);
-#endif
 	return TRUE;
 }
 
@@ -1502,10 +1251,6 @@ void mr_update_span_set(struct MR_DRV_RAID_MAP_ALL *map,
 			break;
 	    }
 	}
-#if SPAN_DEBUG
-	getSpanInfo(map, ldSpanInfo);
-#endif
-
 }
 
 void mr_update_load_balance_params(struct MR_DRV_RAID_MAP_ALL *drv_map,
@@ -1594,13 +1339,6 @@ u8 megasas_get_best_arm_pd(struct megasas_instance *instance,
 	}
 
 	lbInfo->last_accessed_block[io_info->pd_after_lb] = block + count - 1;
-#if SPAN_DEBUG
-	if (arm != bestArm)
-		dev_dbg(&instance->pdev->dev, "LSI Debug R1 Load balance "
-			"occur - span 0x%x arm 0x%x bestArm 0x%x "
-			"io_info->span_arm 0x%x\n",
-			span, arm, bestArm, io_info->span_arm);
-#endif
 	return io_info->pd_after_lb;
 }
 
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index d8877c0..7d3b079 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1062,11 +1062,6 @@ megasas_get_ld_map_info(struct megasas_instance *instance)
 
 	memset(ci, 0, fusion->max_map_sz);
 	memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
-#if VD_EXT_DEBUG
-	dev_dbg(&instance->pdev->dev,
-		"%s sending MR_DCMD_LD_MAP_GET_INFO with size %d\n",
-		__func__, cpu_to_le32(size_map_info));
-#endif
 	dcmd->cmd = MFI_CMD_DCMD;
 	dcmd->cmd_status = 0xFF;
 	dcmd->sge_count = 1;
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 37/39] megaraid_sas: Indentation and smatch warning fixes
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (35 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 36/39] megaraid_sas: Cleanup VD_EXT_DEBUG and SPAN_DEBUG related debug prints Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 38/39] megaraid_sas: Change RAID_1_10_RMW_CMDS to RAID_1_PEER_CMDS and set value to 2 Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 39/39] megaraid_sas: driver version upgrade Shivasharan S
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S, Sasikumar Chandrasekaran

Fix indentation issues and smatch warning reported by Dan Carpenter
for previous series as discussed below.
http://www.spinics.net/lists/linux-scsi/msg103635.html
http://www.spinics.net/lists/linux-scsi/msg103603.html

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Sasikumar Chandrasekaran <sasikumar.pc@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas.h        |  2 +-
 drivers/scsi/megaraid/megaraid_sas_base.c   | 10 ++--
 drivers/scsi/megaraid/megaraid_sas_fp.c     | 57 +++++++++---------
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 92 ++++++++++++++---------------
 drivers/scsi/megaraid/megaraid_sas_fusion.h |  2 +-
 5 files changed, 80 insertions(+), 83 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index dc331e8..8c06cbf 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -1376,7 +1376,7 @@ struct megasas_ctrl_info {
 		u16 reserved:8;
 	#endif
 		} adapter_operations4;
-	u8 pad[0x800-0x7FE]; /* 0x7FE pad to 2K for expansion */
+	u8 pad[0x800 - 0x7FE]; /* 0x7FE pad to 2K for expansion */
 } __packed;
 
 /*
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 5e0dea1..dc9f42e 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -5343,14 +5343,14 @@ static int megasas_init_fw(struct megasas_instance *instance)
 	memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS);
 
 	/* stream detection initialization */
-	if (instance->is_ventura) {
+	if (instance->is_ventura && fusion) {
 		fusion->stream_detect_by_ld =
-		kzalloc(sizeof(struct LD_STREAM_DETECT *)
-		* MAX_LOGICAL_DRIVES_EXT,
-		GFP_KERNEL);
+			kzalloc(sizeof(struct LD_STREAM_DETECT *)
+			* MAX_LOGICAL_DRIVES_EXT,
+			GFP_KERNEL);
 		if (!fusion->stream_detect_by_ld) {
 			dev_err(&instance->pdev->dev,
-					"unable to allocate stream detection for pool of LDs\n");
+				"unable to allocate stream detection for pool of LDs\n");
 			goto fail_get_ld_pd_list;
 		}
 		for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) {
diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
index 7dc7708..62affa7 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -197,7 +197,7 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 
 	memset(drv_map, 0, fusion->drv_map_sz);
 	memset(pDrvRaidMap->ldTgtIdToLd,
-		0xff, (sizeof(u16) * MAX_LOGICAL_DRIVES_DYN));
+	       0xff, (sizeof(u16) * MAX_LOGICAL_DRIVES_DYN));
 
 	if (instance->max_raid_mapsize) {
 		fw_map_dyn = fusion->ld_map[(instance->map_id & 1)];
@@ -224,34 +224,37 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 				fw_map_dyn->dev_hndl_info =
 				(struct MR_DEV_HANDLE_INFO *)(raid_map_data + le32_to_cpu(desc_table->raid_map_desc_offset));
 				memcpy(pDrvRaidMap->devHndlInfo,
-				fw_map_dyn->dev_hndl_info,
-				sizeof(struct MR_DEV_HANDLE_INFO) *
-				le32_to_cpu(desc_table->raid_map_desc_elements));
+					fw_map_dyn->dev_hndl_info,
+					sizeof(struct MR_DEV_HANDLE_INFO) *
+					le32_to_cpu(desc_table->raid_map_desc_elements));
 			break;
 			case RAID_MAP_DESC_TYPE_TGTID_INFO:
 				fw_map_dyn->ld_tgt_id_to_ld =
-				(u16 *) (raid_map_data +
-				le32_to_cpu(desc_table->raid_map_desc_offset));
-			for (j = 0; j < le32_to_cpu(desc_table->raid_map_desc_elements); j++) {
-				pDrvRaidMap->ldTgtIdToLd[j] =
-					le16_to_cpu(fw_map_dyn->ld_tgt_id_to_ld[j]);
-			}
+					(u16 *)(raid_map_data +
+					le32_to_cpu(desc_table->raid_map_desc_offset));
+				for (j = 0; j < le32_to_cpu(desc_table->raid_map_desc_elements); j++) {
+					pDrvRaidMap->ldTgtIdToLd[j] =
+						le16_to_cpu(fw_map_dyn->ld_tgt_id_to_ld[j]);
+				}
 			break;
 			case RAID_MAP_DESC_TYPE_ARRAY_INFO:
 				fw_map_dyn->ar_map_info =
-				(struct MR_ARRAY_INFO *)
-				(raid_map_data + le32_to_cpu(desc_table->raid_map_desc_offset));
+					(struct MR_ARRAY_INFO *)
+					(raid_map_data + le32_to_cpu(desc_table->raid_map_desc_offset));
 				memcpy(pDrvRaidMap->arMapInfo,
-				fw_map_dyn->ar_map_info,
-				sizeof(struct MR_ARRAY_INFO) * le32_to_cpu(desc_table->raid_map_desc_elements));
+				       fw_map_dyn->ar_map_info,
+				       sizeof(struct MR_ARRAY_INFO) *
+				       le32_to_cpu(desc_table->raid_map_desc_elements));
 			break;
 			case RAID_MAP_DESC_TYPE_SPAN_INFO:
 				fw_map_dyn->ld_span_map =
-				(struct MR_LD_SPAN_MAP *)
-				(raid_map_data + le32_to_cpu(desc_table->raid_map_desc_offset));
+					(struct MR_LD_SPAN_MAP *)
+					(raid_map_data +
+					le32_to_cpu(desc_table->raid_map_desc_offset));
 				memcpy(pDrvRaidMap->ldSpanMap,
-				fw_map_dyn->ld_span_map,
-				sizeof(struct MR_LD_SPAN_MAP) * le32_to_cpu(desc_table->raid_map_desc_elements));
+				       fw_map_dyn->ld_span_map,
+				       sizeof(struct MR_LD_SPAN_MAP) *
+				       le32_to_cpu(desc_table->raid_map_desc_elements));
 			break;
 			default:
 				dev_dbg(&instance->pdev->dev, "wrong number of desctableElements %d\n",
@@ -262,7 +265,7 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 
 	} else if (instance->supportmax256vd) {
 		fw_map_ext =
-		(struct MR_FW_RAID_MAP_EXT *) fusion->ld_map[(instance->map_id & 1)];
+			(struct MR_FW_RAID_MAP_EXT *)fusion->ld_map[(instance->map_id & 1)];
 		ld_count = (u16)le16_to_cpu(fw_map_ext->ldCount);
 		if (ld_count > MAX_LOGICAL_DRIVES_EXT) {
 			dev_dbg(&instance->pdev->dev, "megaraid_sas: LD count exposed in RAID map in not valid\n");
@@ -275,12 +278,12 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
 			pDrvRaidMap->ldTgtIdToLd[i] =
 				(u16)fw_map_ext->ldTgtIdToLd[i];
 		memcpy(pDrvRaidMap->ldSpanMap, fw_map_ext->ldSpanMap,
-				sizeof(struct MR_LD_SPAN_MAP) * ld_count);
+		       sizeof(struct MR_LD_SPAN_MAP) * ld_count);
 		memcpy(pDrvRaidMap->arMapInfo, fw_map_ext->arMapInfo,
-			sizeof(struct MR_ARRAY_INFO) * MAX_API_ARRAYS_EXT);
+		       sizeof(struct MR_ARRAY_INFO) * MAX_API_ARRAYS_EXT);
 		memcpy(pDrvRaidMap->devHndlInfo, fw_map_ext->devHndlInfo,
-			sizeof(struct MR_DEV_HANDLE_INFO) *
-					MAX_RAIDMAP_PHYSICAL_DEVICES);
+		       sizeof(struct MR_DEV_HANDLE_INFO) *
+		       MAX_RAIDMAP_PHYSICAL_DEVICES);
 
 		/* New Raid map will not set totalSize, so keep expected value
 		 * for legacy code in ValidateMapInfo
@@ -347,7 +350,7 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance)
 		dev_dbg(&instance->pdev->dev, "megasas: map info structure size 0x%x",
 			le32_to_cpu(pDrvRaidMap->totalSize));
 		dev_dbg(&instance->pdev->dev, "is not matching expected size 0x%x\n",
-			(unsigned int) expected_size);
+			(unsigned int)expected_size);
 		dev_err(&instance->pdev->dev, "megasas: span map %x, pDrvRaidMap->totalSize : %x\n",
 			(unsigned int)sizeof(struct MR_LD_SPAN_MAP),
 			le32_to_cpu(pDrvRaidMap->totalSize));
@@ -770,7 +773,7 @@ static u8 mr_spanset_get_phy_params(struct megasas_instance *instance, u32 ld,
 
 	*pdBlock += stripRef + le64_to_cpu(MR_LdSpanPtrGet(ld, span, map)->startBlk);
 	if (instance->is_ventura) {
-		((struct RAID_CONTEXT_G35 *) pRAID_Context)->span_arm =
+		((struct RAID_CONTEXT_G35 *)pRAID_Context)->span_arm =
 			(span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
 		io_info->span_arm =
 			(span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
@@ -888,7 +891,7 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 ld, u64 stripRow,
 
 	*pdBlock += stripRef + le64_to_cpu(MR_LdSpanPtrGet(ld, span, map)->startBlk);
 	if (instance->is_ventura) {
-		((struct RAID_CONTEXT_G35 *) pRAID_Context)->span_arm =
+		((struct RAID_CONTEXT_G35 *)pRAID_Context)->span_arm =
 				(span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
 		io_info->span_arm =
 				(span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
@@ -1329,7 +1332,7 @@ u8 megasas_get_best_arm_pd(struct megasas_instance *instance,
 		 *  keep driver in sync with Firmware
 		 */
 		if ((bestArm == arm && pend0 > pend1 + lb_pending_cmds)  ||
-			(bestArm != arm && pend1 > pend0 + lb_pending_cmds))
+		    (bestArm != arm && pend1 > pend0 + lb_pending_cmds))
 			bestArm ^= 1;
 
 		/* Update the last accessed block on the correct pd */
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 7d3b079..abd11c3 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -446,8 +446,6 @@ megasas_alloc_cmdlist_fusion(struct megasas_instance *instance)
 		return -ENOMEM;
 	}
 
-
-
 	for (i = 0; i < max_mpt_cmd; i++) {
 		fusion->cmd_list[i] = kzalloc(sizeof(struct megasas_cmd_fusion),
 					      GFP_KERNEL);
@@ -1433,8 +1431,8 @@ megasas_init_adapter_fusion(struct megasas_instance *instance)
 
 void
 map_cmd_status(struct fusion_context *fusion,
-	struct scsi_cmnd *scmd, u8 status, u8 ext_status,
-			u32 data_length, u8 *sense)
+		struct scsi_cmnd *scmd, u8 status, u8 ext_status,
+		u32 data_length, u8 *sense)
 {
 	u8 cmd_type;
 	int resid;
@@ -2033,8 +2031,8 @@ megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len,
 
 /** stream detection on read and and write IOs */
 static void megasas_stream_detect(struct megasas_instance *instance,
-				struct megasas_cmd_fusion *cmd,
-				struct IO_REQUEST_INFO *io_info)
+				  struct megasas_cmd_fusion *cmd,
+				  struct IO_REQUEST_INFO *io_info)
 {
 	struct fusion_context *fusion = instance->ctrl_context;
 	u32 device_id = io_info->ldTgtId;
@@ -2048,63 +2046,59 @@ static void megasas_stream_detect(struct megasas_instance *instance,
 	struct STREAM_DETECT *current_sd;
 	/* find possible stream */
 	for (i = 0; i < MAX_STREAMS_TRACKED; ++i) {
-		stream_num =
-		(*track_stream >> (i * BITS_PER_INDEX_STREAM)) &
+		stream_num = (*track_stream >>
+			(i * BITS_PER_INDEX_STREAM)) &
 			STREAM_MASK;
 		current_sd = &current_ld_sd->stream_track[stream_num];
-	/* if we found a stream, update the raid
-	 *  context and also update the mruBitMap
-	 */
-	/*	boundary condition */
-	if ((current_sd->next_seq_lba) &&
-		(io_info->ldStartBlock >= current_sd->next_seq_lba) &&
-		(io_info->ldStartBlock <= (current_sd->next_seq_lba+32)) &&
-		(current_sd->is_read == io_info->isRead)) {
-
-		if ((io_info->ldStartBlock != current_sd->next_seq_lba)
-			&& ((!io_info->isRead) || (!is_read_ahead)))
-			/*
-			 * Once the API availible we need to change this.
-			 * At this point we are not allowing any gap
-			 */
-			continue;
-
-		SET_STREAM_DETECTED(cmd->io_request->RaidContext.raid_context_g35);
-		current_sd->next_seq_lba =
-		io_info->ldStartBlock + io_info->numBlocks;
-		/*
-		 *	update the mruBitMap LRU
+		/* if we found a stream, update the raid
+		 *  context and also update the mruBitMap
 		 */
-		shifted_values_mask =
-			(1 <<  i * BITS_PER_INDEX_STREAM) - 1;
-		shifted_values = ((*track_stream & shifted_values_mask)
-					<< BITS_PER_INDEX_STREAM);
-		index_value_mask =
-			STREAM_MASK << i * BITS_PER_INDEX_STREAM;
-		unshifted_values =
-			*track_stream & ~(shifted_values_mask |
-			index_value_mask);
-		*track_stream =
-			unshifted_values | shifted_values | stream_num;
-		return;
+		/*	boundary condition */
+		if ((current_sd->next_seq_lba) &&
+		    (io_info->ldStartBlock >= current_sd->next_seq_lba) &&
+		    (io_info->ldStartBlock <= (current_sd->next_seq_lba + 32)) &&
+		    (current_sd->is_read == io_info->isRead)) {
+
+			if ((io_info->ldStartBlock != current_sd->next_seq_lba)	&&
+			    ((!io_info->isRead) || (!is_read_ahead)))
+				/*
+				 * Once the API availible we need to change this.
+				 * At this point we are not allowing any gap
+				 */
+				continue;
 
+			SET_STREAM_DETECTED(cmd->io_request->RaidContext.raid_context_g35);
+			current_sd->next_seq_lba =
+			io_info->ldStartBlock + io_info->numBlocks;
+			/*
+			 *	update the mruBitMap LRU
+			 */
+			shifted_values_mask =
+				(1 <<  i * BITS_PER_INDEX_STREAM) - 1;
+			shifted_values = ((*track_stream & shifted_values_mask)
+						<< BITS_PER_INDEX_STREAM);
+			index_value_mask =
+				STREAM_MASK << i * BITS_PER_INDEX_STREAM;
+			unshifted_values =
+				*track_stream & ~(shifted_values_mask |
+				index_value_mask);
+			*track_stream =
+				unshifted_values | shifted_values | stream_num;
+			return;
 		}
-
 	}
 	/*
 	 * if we did not find any stream, create a new one
 	 * from the least recently used
 	 */
-	stream_num =
-	(*track_stream >> ((MAX_STREAMS_TRACKED - 1) * BITS_PER_INDEX_STREAM)) &
-			STREAM_MASK;
+	stream_num = (*track_stream >>
+		((MAX_STREAMS_TRACKED - 1) * BITS_PER_INDEX_STREAM)) &
+		STREAM_MASK;
 	current_sd = &current_ld_sd->stream_track[stream_num];
 	current_sd->is_read = io_info->isRead;
 	current_sd->next_seq_lba = io_info->ldStartBlock + io_info->numBlocks;
-	*track_stream =
-	(((*track_stream & ZERO_LAST_STREAM) << 4) | stream_num);
+	*track_stream = (((*track_stream & ZERO_LAST_STREAM) << 4) | stream_num);
 	return;
-
 }
 
 /**
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
index 6c22337..60566e4 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
@@ -904,7 +904,7 @@ struct MR_LD_RAID {
 	  */
 	struct MR_IO_AFFINITY cpuAffinity;
      /* Bit definiations are specified by MR_IO_AFFINITY */
-	u8 reserved3[0x80-0x40];    /* 0x40 - 0x7f */
+	u8 reserved3[0x80 - 0x40];    /* 0x40 - 0x7f */
 };
 
 struct MR_LD_SPAN_MAP {
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 38/39] megaraid_sas: Change RAID_1_10_RMW_CMDS to RAID_1_PEER_CMDS and set value to 2
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (36 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 37/39] megaraid_sas: Indentation and smatch warning fixes Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  2017-02-08  9:29 ` [PATCH v2 39/39] megaraid_sas: driver version upgrade Shivasharan S
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

For RAID1 FastPath writes, driver needs to allocate extra commands
internally to accommodate for the extra peer command being sent.
Currently driver is allocating 2 extra commands for each but only
one extra command is necessary.
Set RAID_1_10_RMW_CMDS to 2 and also change macro name to
RAID_1_PEER_CMDS.

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 2 +-
 drivers/scsi/megaraid/megaraid_sas_fusion.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index abd11c3..3f198b5 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -293,7 +293,7 @@ megasas_fusion_update_can_queue(struct megasas_instance *instance, int fw_boot_c
 
 	if (instance->is_ventura)
 		instance->max_mpt_cmds =
-		instance->max_fw_cmds * RAID_1_10_RMW_CMDS;
+		instance->max_fw_cmds * RAID_1_PEER_CMDS;
 	else
 		instance->max_mpt_cmds = instance->max_fw_cmds;
 }
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
index 60566e4..c36f9f7 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
@@ -101,7 +101,7 @@ enum MR_RAID_FLAGS_IO_SUB_TYPE {
 #define MEGASAS_FP_CMD_LEN	16
 #define MEGASAS_FUSION_IN_RESET 0
 #define THRESHOLD_REPLY_COUNT 50
-#define RAID_1_10_RMW_CMDS 3
+#define RAID_1_PEER_CMDS 2
 #define JBOD_MAPS_COUNT	2
 
 enum MR_FUSION_ADAPTER_TYPE {
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* [PATCH v2 39/39] megaraid_sas: driver version upgrade
  2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
                   ` (37 preceding siblings ...)
  2017-02-08  9:29 ` [PATCH v2 38/39] megaraid_sas: Change RAID_1_10_RMW_CMDS to RAID_1_PEER_CMDS and set value to 2 Shivasharan S
@ 2017-02-08  9:29 ` Shivasharan S
  38 siblings, 0 replies; 57+ messages in thread
From: Shivasharan S @ 2017-02-08  9:29 UTC (permalink / raw)
  To: linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena, hare,
	Shivasharan S

Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
---
 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 8c06cbf..e7e5974 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.700.00.00-rc1"
-#define MEGASAS_RELDATE				"November 29, 2016"
+#define MEGASAS_VERSION				"07.701.16.00-rc1"
+#define MEGASAS_RELDATE				"February 2, 2017"
 
 /*
  * Device IDs
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 04/39] megaraid_sas: 32 bit descriptor fire cmd optimization
  2017-02-08  9:28 ` [PATCH v2 04/39] megaraid_sas: 32 bit descriptor fire cmd optimization Shivasharan S
@ 2017-02-08 11:15   ` Hannes Reinecke
  0 siblings, 0 replies; 57+ messages in thread
From: Hannes Reinecke @ 2017-02-08 11:15 UTC (permalink / raw)
  To: Shivasharan S, linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena

On 02/08/2017 10:28 AM, Shivasharan S wrote:
> No functional change. Code refactor.
> megasas_fire_cmd_fusion can always use 32 bit descriptor write for ventura. No need to pass extra flag.
> Only IOC INIT required 64 bit Descriptor write.
> 
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Reviewed-by: Tomas Henzl <thenzl@redhat.com>
> ---
>  drivers/scsi/megaraid/megaraid_sas_fusion.c | 65 +++++++++++++++--------------
>  1 file changed, 33 insertions(+), 32 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

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

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 06/39] megaraid_sas: RAID map is accessed for SYS PDs when use_seqnum_jbod_fp is not set
  2017-02-08  9:29 ` [PATCH v2 06/39] megaraid_sas: RAID map is accessed for SYS PDs when use_seqnum_jbod_fp is not set Shivasharan S
@ 2017-02-08 11:16   ` Hannes Reinecke
  2017-02-08 14:37   ` Tomas Henzl
  1 sibling, 0 replies; 57+ messages in thread
From: Hannes Reinecke @ 2017-02-08 11:16 UTC (permalink / raw)
  To: Shivasharan S, linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena

On 02/08/2017 10:29 AM, Shivasharan S wrote:
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> ---
>  drivers/scsi/megaraid/megaraid_sas_base.c | 25 ++++++++++++++-----------
>  1 file changed, 14 insertions(+), 11 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

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

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 08/39] megaraid_sas: megasas_get_request_descriptor always return valid desc
  2017-02-08  9:29 ` [PATCH v2 08/39] megaraid_sas: megasas_get_request_descriptor always return valid desc Shivasharan S
@ 2017-02-08 11:17   ` Hannes Reinecke
  2017-02-08 14:40   ` Tomas Henzl
  2017-02-09 23:39   ` Martin K. Petersen
  2 siblings, 0 replies; 57+ messages in thread
From: Hannes Reinecke @ 2017-02-08 11:17 UTC (permalink / raw)
  To: Shivasharan S, linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena

On 02/08/2017 10:29 AM, Shivasharan S wrote:
> fix in v2 - split patches into two. 
> discussed below 
> http://marc.info/?l=linux-scsi&m=148638999110404&w=2
> 
> No functional change. Code clean up. Removing error code which is not
> valid scenario.
> In megasas_get_request_descriptor we can remove the error handling
> which is not required.
> With fusion controllers, if there is a valid message frame available,
> we are guaranteed to get a corresponding request descriptor.
> 
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> ---
>  drivers/scsi/megaraid/megaraid_sas_fusion.c | 24 ++----------------------
>  1 file changed, 2 insertions(+), 22 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

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

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 09/39] megaraid_sas: change issue_dcmd to return void from int
  2017-02-08  9:29 ` [PATCH v2 09/39] megaraid_sas: change issue_dcmd to return void from int Shivasharan S
@ 2017-02-08 11:17   ` Hannes Reinecke
  2017-02-08 14:40   ` Tomas Henzl
  1 sibling, 0 replies; 57+ messages in thread
From: Hannes Reinecke @ 2017-02-08 11:17 UTC (permalink / raw)
  To: Shivasharan S, linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena

On 02/08/2017 10:29 AM, Shivasharan S wrote:
> fix in v2 : 
> 1. split patches into two as discussed below 
> http://marc.info/?l=linux-scsi&m=148638999110404&w=2
> 2. issue_dcmd return type changed from int to void.
> 
> 
> With the changes to remove checks for a valid request descriptor,
> issue_dcmd will now always return DCMD_SUCCESS. This patch changes
> return type of issue_dcmd to void and change all callers
> appropriately.
> 
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> ---
>  drivers/scsi/megaraid/megaraid_sas.h        |  2 +-
>  drivers/scsi/megaraid/megaraid_sas_base.c   | 19 +++++++++++--------
>  drivers/scsi/megaraid/megaraid_sas_fusion.c |  8 ++++----
>  3 files changed, 16 insertions(+), 13 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

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

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 10/39] megaraid_sas: NVME Interface detection and prop settings
  2017-02-08  9:29 ` [PATCH v2 10/39] megaraid_sas: NVME Interface detection and prop settings Shivasharan S
@ 2017-02-08 11:59   ` Hannes Reinecke
  2017-02-08 14:48   ` Tomas Henzl
  1 sibling, 0 replies; 57+ messages in thread
From: Hannes Reinecke @ 2017-02-08 11:59 UTC (permalink / raw)
  To: Shivasharan S, linux-scsi
  Cc: martin.petersen, thenzl, jejb, kashyap.desai, sumit.saxena

On 02/08/2017 10:29 AM, Shivasharan S wrote:
> New functionality
> Adding detection logic for NVME device attached behind Ventura controller.
> Driver set HostPageSize in IOC_INIT frame to inform about page size for NVME devices.
> Firmware reports NVME page size to the driver.
> PD INFO DCMD provide new interface type NVME_PD. Driver set property of NVME device.
> 
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> ---
>  drivers/scsi/megaraid/megaraid_sas.h        |  23 ++--
>  drivers/scsi/megaraid/megaraid_sas_base.c   | 170 ++++++++++++++++++++--------
>  drivers/scsi/megaraid/megaraid_sas_fusion.c |   6 +-
>  drivers/scsi/megaraid/megaraid_sas_fusion.h |   2 +-
>  4 files changed, 142 insertions(+), 59 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

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

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 03/39] megaraid_sas: raid 1 fast path code optimize
  2017-02-08  9:28 ` [PATCH v2 03/39] megaraid_sas: raid 1 fast path code optimize Shivasharan S
@ 2017-02-08 14:34   ` Tomas Henzl
  2017-02-08 18:51     ` Kashyap Desai
  2017-02-09 13:16   ` Tomas Henzl
  1 sibling, 1 reply; 57+ messages in thread
From: Tomas Henzl @ 2017-02-08 14:34 UTC (permalink / raw)
  To: Shivasharan S, linux-scsi
  Cc: martin.petersen, jejb, kashyap.desai, sumit.saxena, hare

On 8.2.2017 10:28, Shivasharan S wrote:
> fix in v2 - ex_status and status was wrongly re-used in megasas_complete_r1_command.
> discussed below -
> http://marc.info/?l=linux-scsi&m=148638763409385&w=2
>
>
> No functional change. Code refactor.
> Remove function megasas_fpio_to_ldio as we never require to convert fpio to ldio because of frame unavailability.
> Grab extra frame of raid 1 write fast path before it creates first frame as Fast Path.
> Removed is_raid_1_fp_write flag as raid 1 write fast path command is decided using r1_alt_dev_handle only.
> Move resetting megasas_cmd_fusion fields at common function megasas_return_cmd_fusion.
>
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Reviewed-by: Hannes Reinecke <hare@suse.com>
> ---
>  drivers/scsi/megaraid/megaraid_sas_fp.c     |  14 +-
>  drivers/scsi/megaraid/megaraid_sas_fusion.c | 349 +++++++++-------------------
>  drivers/scsi/megaraid/megaraid_sas_fusion.h |   3 +-
>  3 files changed, 118 insertions(+), 248 deletions(-)
>
> diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
> index f1384b0..24258af 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_fp.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
> @@ -1338,20 +1338,8 @@ MR_BuildRaidContext(struct megasas_instance *instance,
>  					ref_in_start_stripe, io_info,
>  					pRAID_Context, map);
>  		/* If IO on an invalid Pd, then FP is not possible.*/
> -		if (io_info->devHandle == cpu_to_le16(MR_PD_INVALID))
> +		if (io_info->devHandle == MR_DEVHANDLE_INVALID)
>  			io_info->fpOkForIo = FALSE;
> -		/* if FP possible, set the SLUD bit in
> -		 *  regLockFlags for ventura
> -		 */
> -		else if ((instance->is_ventura) && (!isRead) &&
> -			(raid->writeMode == MR_RL_WRITE_BACK_MODE) &&
> -			(raid->capability.fp_cache_bypass_capable))
> -			((struct RAID_CONTEXT_G35 *) pRAID_Context)->routing_flags.bits.sld = 1;
> -		/* set raid 1/10 fast path write capable bit in io_info */
> -		if (io_info->fpOkForIo &&
> -		    (io_info->r1_alt_dev_handle != MR_PD_INVALID) &&
> -		    (raid->level == 1) && !isRead)
> -			io_info->is_raid_1_fp_write = 1;
>  		return retval;
>  	} else if (isRead) {
>  		uint stripIdx;
> diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> index 514c306..7516589 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> @@ -181,7 +181,9 @@ inline void megasas_return_cmd_fusion(struct megasas_instance *instance,
>  	struct megasas_cmd_fusion *cmd)
>  {
>  	cmd->scmd = NULL;
> -	memset(cmd->io_request, 0, sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
> +	memset(cmd->io_request, 0, MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE);
> +	cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
> +	cmd->cmd_completed = false;
>  }
>  
>  /**
> @@ -701,7 +703,7 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance)
>  		memset(cmd->io_request, 0,
>  		       sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
>  		cmd->io_request_phys_addr = io_req_base_phys + offset;
> -		cmd->is_raid_1_fp_write = 0;
> +		cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
>  	}
>  
>  	if (megasas_create_sg_sense_fusion(instance))
> @@ -1984,7 +1986,7 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
>  	io_info.ldStartBlock = ((u64)start_lba_hi << 32) | start_lba_lo;
>  	io_info.numBlocks = datalength;
>  	io_info.ldTgtId = device_id;
> -	io_info.r1_alt_dev_handle = MR_PD_INVALID;
> +	io_info.r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
>  	scsi_buff_len = scsi_bufflen(scp);
>  	io_request->DataLength = cpu_to_le32(scsi_buff_len);
>  
> @@ -2025,7 +2027,7 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
>  		    io_info.isRead && io_info.ra_capable)
>  			fp_possible = false;
>  
> -		if (io_info.r1_alt_dev_handle != MR_PD_INVALID) {
> +		if (io_info.r1_alt_dev_handle != MR_DEVHANDLE_INVALID) {
>  			mrdev_priv = scp->device->hostdata;
>  
>  			if (atomic_inc_return(&instance->fw_outstanding) >
> @@ -2090,9 +2092,10 @@ megasas_build_ldio_fusion(struct megasas_instance *instance,
>  		} else
>  			scp->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
>  
> -		cmd->is_raid_1_fp_write = io_info.is_raid_1_fp_write;
> -		if (io_info.is_raid_1_fp_write)
> +		if (instance->is_ventura)
>  			cmd->r1_alt_dev_handle = io_info.r1_alt_dev_handle;
> +		else
> +			cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
>  
>  		if ((raidLUN[0] == 1) &&
>  			(local_map_ptr->raidMap.devHndlInfo[io_info.pd_after_lb].validHandles > 1)) {
> @@ -2451,72 +2454,6 @@ megasas_get_request_descriptor(struct megasas_instance *instance, u16 index)
>  	return (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)p;
>  }
>  
> -/*
> - * megasas_fpio_to_ldio-
> - * This function converts an fp io to ldio
> - */
> -
> -void megasas_fpio_to_ldio(struct megasas_instance *instance,
> -	struct megasas_cmd_fusion *cmd, struct scsi_cmnd *scmd)
> -{
> -	struct fusion_context *fusion;
> -	union RAID_CONTEXT_UNION *praid_context;
> -	struct MR_LD_RAID *raid;
> -	struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
> -	u32 device_id, ld;
> -
> -	fusion = instance->ctrl_context;
> -	cmd->request_desc->SCSIIO.RequestFlags =
> -		(MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
> -		<< MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
> -	cmd->io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
> -	cmd->io_request->DevHandle = cpu_to_le16(MEGASAS_DEV_INDEX(scmd));
> -
> -	/*remove FAST PATH ENABLE bit in IoFlags */
> -	cmd->io_request->IoFlags &=
> -	cpu_to_le16(~MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
> -
> -	/* if the numSGE > max_sge_in_main_sge set the chain offset*/
> -	if (cmd->io_request->RaidContext.raid_context_g35.num_sge >
> -		fusion->max_sge_in_main_msg)
> -		cmd->io_request->ChainOffset = fusion->chain_offset_io_request;
> -	memcpy(cmd->io_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
> -	cmd->io_request->CDB.EEDP32.PrimaryReferenceTag = 0;
> -	cmd->io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0;
> -	cmd->io_request->EEDPFlags = 0;
> -	cmd->io_request->Control = 0;
> -	cmd->io_request->EEDPBlockSize = 0;
> -	cmd->is_raid_1_fp_write = 0;
> -
> -	device_id = MEGASAS_DEV_INDEX(cmd->scmd);
> -	local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
> -	ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
> -	raid = MR_LdRaidGet(ld, local_map_ptr);
> -	praid_context = &cmd->io_request->RaidContext;
> -	if (cmd->scmd->sc_data_direction == PCI_DMA_FROMDEVICE) {
> -		if ((raid->cpuAffinity.ldRead.cpu0)
> -		&& (raid->cpuAffinity.ldRead.cpu1))
> -			praid_context->raid_context_g35.routing_flags.bits.cpu_sel
> -			= MR_RAID_CTX_CPUSEL_FCFS;
> -		else if (raid->cpuAffinity.ldRead.cpu1)
> -			praid_context->raid_context_g35.routing_flags.bits.cpu_sel
> -			= MR_RAID_CTX_CPUSEL_1;
> -		else
> -			praid_context->raid_context_g35.routing_flags.bits.cpu_sel
> -			= MR_RAID_CTX_CPUSEL_0;
> -	} else {
> -	if ((raid->cpuAffinity.ldWrite.cpu0)
> -		&& (raid->cpuAffinity.ldWrite.cpu1))
> -		praid_context->raid_context_g35.routing_flags.bits.cpu_sel
> -			= MR_RAID_CTX_CPUSEL_FCFS;
> -	else if (raid->cpuAffinity.ldWrite.cpu1)
> -		praid_context->raid_context_g35.routing_flags.bits.cpu_sel
> -			= MR_RAID_CTX_CPUSEL_1;
> -	else
> -		praid_context->raid_context_g35.routing_flags.bits.cpu_sel
> -		= MR_RAID_CTX_CPUSEL_0;
> -	}
> -}
>  
>  /* megasas_prepate_secondRaid1_IO
>   *  It prepares the raid 1 second IO
> @@ -2527,60 +2464,36 @@ void megasas_prepare_secondRaid1_IO(struct megasas_instance *instance,
>  {
>  	union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc, *req_desc2 = NULL;
>  	struct fusion_context *fusion;
> -
>  	fusion = instance->ctrl_context;
>  	req_desc = cmd->request_desc;
> -	if (r1_cmd) {
> -		/* copy the io request frame as well
> -		 *  as 8 SGEs data for r1 command
> -		 */
> -		memcpy(r1_cmd->io_request, cmd->io_request,
> -			sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
> -		memcpy(&r1_cmd->io_request->SGL, &cmd->io_request->SGL,
> -				(fusion->max_sge_in_main_msg *
> -				sizeof(union MPI2_SGE_IO_UNION)));
> -		/*sense buffer is different for r1 command*/
> -		r1_cmd->io_request->SenseBufferLowAddress =
> -				cpu_to_le32(r1_cmd->sense_phys_addr);
> -		r1_cmd->scmd = cmd->scmd;
> -		req_desc2 =
> -		megasas_get_request_descriptor(instance, r1_cmd->index-1);
> -		if (req_desc2) {
> -			req_desc2->Words = 0;
> -			r1_cmd->request_desc = req_desc2;
> -			req_desc2->SCSIIO.SMID =
> -				cpu_to_le16(r1_cmd->index);
> -			req_desc2->SCSIIO.RequestFlags =
> -				req_desc->SCSIIO.RequestFlags;
> -			r1_cmd->is_raid_1_fp_write = 1;
> -			r1_cmd->request_desc->SCSIIO.DevHandle =
> -				cmd->r1_alt_dev_handle;
> -			r1_cmd->io_request->DevHandle = cmd->r1_alt_dev_handle;
> -			cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid =
> -				 cpu_to_le16(r1_cmd->index);
> -			r1_cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid =
> -				cpu_to_le16(cmd->index);
> -			/* MSIxIndex of both commands request
> -			 * descriptors should be same
> -			 */
> -			r1_cmd->request_desc->SCSIIO.MSIxIndex =
> -				cmd->request_desc->SCSIIO.MSIxIndex;
> -			/*span arm is different for r1 cmd*/
> -			r1_cmd->io_request->RaidContext.raid_context_g35.span_arm =
> +	/* copy the io request frame as well as 8 SGEs data for r1 command*/
> +	memcpy(r1_cmd->io_request, cmd->io_request,
> +	       (sizeof(struct MPI2_RAID_SCSI_IO_REQUEST)));
> +	memcpy(&r1_cmd->io_request->SGL, &cmd->io_request->SGL,
> +	       (fusion->max_sge_in_main_msg * sizeof(union MPI2_SGE_IO_UNION)));
> +	/*sense buffer is different for r1 command*/
> +	r1_cmd->io_request->SenseBufferLowAddress =
> +			cpu_to_le32(r1_cmd->sense_phys_addr);
> +	r1_cmd->scmd = cmd->scmd;
> +	req_desc2 = megasas_get_request_descriptor(instance,
> +						   (r1_cmd->index - 1));
> +	req_desc2->Words = 0;
> +	r1_cmd->request_desc = req_desc2;
> +	req_desc2->SCSIIO.SMID = cpu_to_le16(r1_cmd->index);
> +	req_desc2->SCSIIO.RequestFlags = req_desc->SCSIIO.RequestFlags;
> +	r1_cmd->request_desc->SCSIIO.DevHandle = cmd->r1_alt_dev_handle;
> +	r1_cmd->io_request->DevHandle = cmd->r1_alt_dev_handle;
> +	r1_cmd->r1_alt_dev_handle = cmd->io_request->DevHandle;
> +	cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid =
> +			cpu_to_le16(r1_cmd->index);
> +	r1_cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid =
> +			cpu_to_le16(cmd->index);
> +	/*MSIxIndex of both commands request descriptors should be same*/
> +	r1_cmd->request_desc->SCSIIO.MSIxIndex =
> +			cmd->request_desc->SCSIIO.MSIxIndex;
> +	/*span arm is different for r1 cmd*/
> +	r1_cmd->io_request->RaidContext.raid_context_g35.span_arm =
>  			cmd->io_request->RaidContext.raid_context_g35.span_arm + 1;
> -		} else {
> -			megasas_return_cmd_fusion(instance, r1_cmd);
> -			dev_info(&instance->pdev->dev,
> -				"unable to get request descriptor, firing as normal IO\n");
> -			atomic_dec(&instance->fw_outstanding);
> -			megasas_fpio_to_ldio(instance, cmd, cmd->scmd);
> -		}
> -	} else {
> -		dev_info(&instance->pdev->dev,
> -			"unable to get command, firing as normal IO\n");
> -		atomic_dec(&instance->fw_outstanding);
> -		megasas_fpio_to_ldio(instance, cmd, cmd->scmd);
> -	}
>  }
>  
>  /**
> @@ -2624,10 +2537,6 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
>  	index = cmd->index;
>  
>  	req_desc = megasas_get_request_descriptor(instance, index-1);
> -	if (!req_desc) {
> -		atomic_dec(&instance->fw_outstanding);
> -		return SCSI_MLQUEUE_HOST_BUSY;
> -	}
>  
>  	req_desc->Words = 0;
>  	cmd->request_desc = req_desc;
> @@ -2657,12 +2566,7 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
>  	/*	driver side count always should be less than max_fw_cmds
>  	 *	to get new command
>  	 */
> -	if (cmd->is_raid_1_fp_write &&
> -		atomic_inc_return(&instance->fw_outstanding) >
> -			(instance->host->can_queue)) {
> -		megasas_fpio_to_ldio(instance, cmd, cmd->scmd);
> -		atomic_dec(&instance->fw_outstanding);
> -	} else if (cmd->is_raid_1_fp_write) {
> +	if (cmd->r1_alt_dev_handle != MR_DEVHANDLE_INVALID) {
>  		r1_cmd = megasas_get_cmd_fusion(instance,
>  				(scmd->request->tag + instance->max_fw_cmds));
>  		megasas_prepare_secondRaid1_IO(instance, cmd, r1_cmd);
> @@ -2684,6 +2588,61 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
>  }
>  
>  /**
> + * megasas_complete_r1_command -
> + * completes R1 FP write commands which has valid peer smid
> + * @instance:			Adapter soft state
> + * @cmd_fusion:			MPT command frame
> + *
> + */
> +static inline void
> +megasas_complete_r1_command(struct megasas_instance *instance,
> +			    struct megasas_cmd_fusion *cmd)
> +{
> +	u8 *sense, status, ex_status;
> +	u32 data_length;
> +	u16 peer_smid;
> +	struct fusion_context *fusion;
> +	struct megasas_cmd_fusion *r1_cmd = NULL;
> +	struct scsi_cmnd *scmd_local = NULL;
> +	struct RAID_CONTEXT_G35 *rctx_g35;
> +
> +	rctx_g35 = &cmd->io_request->RaidContext.raid_context_g35;
> +	fusion = instance->ctrl_context;
> +	peer_smid = le16_to_cpu(rctx_g35->smid.peer_smid);
> +
> +	r1_cmd = fusion->cmd_list[peer_smid - 1];
> +	scmd_local = cmd->scmd;
> +	status = rctx_g35->status;
> +	ex_status = rctx_g35->ex_status;
> +	data_length = cmd->io_request->DataLength;
> +	sense = cmd->sense;
> +
> +	cmd->cmd_completed = true;

Please help me understand how this works
- there are two peer commands sent to the controller
- both are completed and the later calls scsi_done and returns both r1_cmd + cmd
- if both commands can be completed at the same time, is it possible that the
  above line is executed at the same moment for both completions ?
How is the code  protected against a double completion when both completed commands
see the peer cmd_completed as set ?

> +
> +	/* Check if peer command is completed or not*/
> +	if (r1_cmd->cmd_completed) {
> +		rctx_g35 = &r1_cmd->io_request->RaidContext.raid_context_g35;
> +		if (rctx_g35->status != MFI_STAT_OK) {
> +			status = rctx_g35->status;
> +			ex_status = rctx_g35->ex_status;
> +			data_length = r1_cmd->io_request->DataLength;
> +			sense = r1_cmd->sense;
> +		}
> +
> +		megasas_return_cmd_fusion(instance, r1_cmd);
> +		map_cmd_status(fusion, scmd_local, status, ex_status,
> +			       le32_to_cpu(data_length), sense);
> +		if (instance->ldio_threshold &&
> +		    megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)
> +			atomic_dec(&instance->ldio_outstanding);
> +		scmd_local->SCp.ptr = NULL;
> +		megasas_return_cmd_fusion(instance, cmd);
> +		scsi_dma_unmap(scmd_local);
> +		scmd_local->scsi_done(scmd_local);
> +	}
> +}
> +
> +/**
>   * complete_cmd_fusion -	Completes command
>   * @instance:			Adapter soft state
>   * Completes all commands that is in reply descriptor queue
> @@ -2696,10 +2655,10 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex)
>  	struct MPI2_RAID_SCSI_IO_REQUEST *scsi_io_req;
>  	struct fusion_context *fusion;
>  	struct megasas_cmd *cmd_mfi;
> -	struct megasas_cmd_fusion *cmd_fusion, *r1_cmd = NULL;
> +	struct megasas_cmd_fusion *cmd_fusion;
>  	u16 smid, num_completed;
> -	u8 reply_descript_type, *sense;
> -	u32 status, extStatus, device_id, data_length;
> +	u8 reply_descript_type, *sense, status, extStatus;
> +	u32 device_id, data_length;
>  	union desc_value d_val;
>  	struct LD_LOAD_BALANCE_INFO *lbinfo;
>  	int threshold_reply_count = 0;
> @@ -2729,25 +2688,11 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex)
>  
>  	while (d_val.u.low != cpu_to_le32(UINT_MAX) &&
>  	       d_val.u.high != cpu_to_le32(UINT_MAX)) {
> -		   /*
> -		    * Ensure that the peer command is NULL here in case a
> -		    * command has completed but the R1 FP Write peer has
> -		    * not completed yet.If not null, it's possible that
> -		    * another thread will complete the peer
> -		    * command and should not.
> -		    */
> -		r1_cmd = NULL;
>  
>  		smid = le16_to_cpu(reply_desc->SMID);
> -
>  		cmd_fusion = fusion->cmd_list[smid - 1];
> -
> -		scsi_io_req =
> -			(struct MPI2_RAID_SCSI_IO_REQUEST *)
> -		  cmd_fusion->io_request;
> -
> -		if (cmd_fusion->scmd)
> -			cmd_fusion->scmd->SCp.ptr = NULL;
> +		scsi_io_req = (struct MPI2_RAID_SCSI_IO_REQUEST *)
> +						cmd_fusion->io_request;
>  
>  		scmd_local = cmd_fusion->scmd;
>  		status = scsi_io_req->RaidContext.raid_context.status;
> @@ -2768,88 +2713,33 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex)
>  			break;
>  		case MPI2_FUNCTION_SCSI_IO_REQUEST:  /*Fast Path IO.*/
>  			/* Update load balancing info */
> -			device_id = MEGASAS_DEV_INDEX(scmd_local);
> -			lbinfo = &fusion->load_balance_info[device_id];
> -			/*
> -			 * check for the raid 1/10 fast path writes
> -			 */
> -			if (!cmd_fusion->is_raid_1_fp_write &&
> -				(cmd_fusion->scmd->SCp.Status &
> -					MEGASAS_LOAD_BALANCE_FLAG)) {
> +			if (fusion->load_balance_info &&
> +			    (cmd_fusion->scmd->SCp.Status &
> +			    MEGASAS_LOAD_BALANCE_FLAG)) {
> +				device_id = MEGASAS_DEV_INDEX(scmd_local);
> +				lbinfo = &fusion->load_balance_info[device_id];
>  				atomic_dec(&lbinfo->scsi_pending_cmds[cmd_fusion->pd_r1_lb]);
> -				cmd_fusion->scmd->SCp.Status &=
> -					~MEGASAS_LOAD_BALANCE_FLAG;
> -			} else if (cmd_fusion->is_raid_1_fp_write) {
> -				/* get peer command */
> -				if (cmd_fusion->index < instance->max_fw_cmds)
> -					r1_cmd = fusion->cmd_list[(cmd_fusion->index +
> -					instance->max_fw_cmds)-1];
> -				else {
> -					r1_cmd =
> -					fusion->cmd_list[(cmd_fusion->index -
> -						 instance->max_fw_cmds)-1];
> -				}
> -				cmd_fusion->cmd_completed = true;
> +				cmd_fusion->scmd->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
>  			}
> -
> -			if (reply_descript_type ==
> -			    MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS) {
> -				if (megasas_dbg_lvl == 5)
> -					dev_err(&instance->pdev->dev, "\nFAST Path "
> -					       "IO Success\n");
> -			}
> -			/* Fall thru and complete IO */
> +			//Fall thru and complete IO
>  		case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST: /* LD-IO Path */
> -			/* Map the FW Cmd Status */
> -			/*
> -			 * check for the raid 1/10 fast path writes
> -			 */
> -			if (r1_cmd &&  r1_cmd->is_raid_1_fp_write
> -				&& r1_cmd->cmd_completed) {
> -				/*
> -				 * if the peer  Raid  1/10 fast path failed,
> -				 * mark IO as failed to the scsi layer.
> -				 * over write the current status by the failed
> -				 * status makes sure that if any one of
> -				 * command fails,return fail status to
> -				 * scsi layer
> -				 */
> -				if (r1_cmd->io_request->RaidContext.raid_context.status !=
> -								MFI_STAT_OK) {
> -					status =
> -					r1_cmd->io_request->RaidContext.raid_context.status;
> -					extStatus =
> -					r1_cmd->io_request->RaidContext.raid_context.ex_status;
> -					data_length =
> -						r1_cmd->io_request->DataLength;
> -					sense = r1_cmd->sense;
> -				}
> -				r1_cmd->io_request->RaidContext.raid_context.status = 0;
> -				r1_cmd->io_request->RaidContext.raid_context.ex_status = 0;
> -				cmd_fusion->is_raid_1_fp_write = 0;
> -				r1_cmd->is_raid_1_fp_write = 0;
> -				r1_cmd->cmd_completed = false;
> -				cmd_fusion->cmd_completed = false;
> -				megasas_return_cmd_fusion(instance, r1_cmd);
> -			}
> -			if (!cmd_fusion->is_raid_1_fp_write) {
> +			atomic_dec(&instance->fw_outstanding);
> +			if (cmd_fusion->r1_alt_dev_handle == MR_DEVHANDLE_INVALID) {
>  				map_cmd_status(fusion, scmd_local, status,
> -					extStatus, data_length, sense);
> -				scsi_io_req->RaidContext.raid_context.status = 0;
> -				scsi_io_req->RaidContext.raid_context.ex_status = 0;
> -				if (instance->ldio_threshold
> -					&& megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)
> +					       extStatus, le32_to_cpu(data_length),
> +					       sense);
> +				if (instance->ldio_threshold &&
> +				    (megasas_cmd_type(scmd_local) == READ_WRITE_LDIO))
>  					atomic_dec(&instance->ldio_outstanding);
> +				scmd_local->SCp.ptr = NULL;
>  				megasas_return_cmd_fusion(instance, cmd_fusion);
>  				scsi_dma_unmap(scmd_local);
>  				scmd_local->scsi_done(scmd_local);
> -			}
> -			atomic_dec(&instance->fw_outstanding);
> -
> +			} else	/* Optimal VD - R1 FP command completion. */
> +				megasas_complete_r1_command(instance, cmd_fusion);
>  			break;
>  		case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST: /*MFI command */
>  			cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
> -
>  			/* Poll mode. Dummy free.
>  			 * In case of Interrupt mode, caller has reverse check.
>  			 */
> @@ -3896,7 +3786,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason)
>  {
>  	int retval = SUCCESS, i, j, convert = 0;
>  	struct megasas_instance *instance;
> -	struct megasas_cmd_fusion *cmd_fusion, *mpt_cmd_fusion;
> +	struct megasas_cmd_fusion *cmd_fusion, *r1_cmd;
>  	struct fusion_context *fusion;
>  	u32 abs_state, status_reg, reset_adapter;
>  	u32 io_timeout_in_crash_mode = 0;
> @@ -3973,15 +3863,8 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason)
>  			cmd_fusion = fusion->cmd_list[i];
>  			/*check for extra commands issued by driver*/
>  			if (instance->is_ventura) {
> -				cmd_fusion->is_raid_1_fp_write = 0;
> -				cmd_fusion->cmd_completed = false;
> -				mpt_cmd_fusion =
> -				fusion->cmd_list[i + instance->max_fw_cmds];
> -				mpt_cmd_fusion->is_raid_1_fp_write = 0;
> -				mpt_cmd_fusion->cmd_completed = false;
> -				if (mpt_cmd_fusion->scmd)
> -					megasas_return_cmd_fusion(instance,
> -						mpt_cmd_fusion);
> +				r1_cmd = fusion->cmd_list[i + instance->max_fw_cmds];
> +				megasas_return_cmd_fusion(instance, r1_cmd);
>  			}
>  			scmd_local = cmd_fusion->scmd;
>  			if (cmd_fusion->scmd) {
> diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
> index 82a4ff7..9d9658e 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
> +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
> @@ -673,6 +673,7 @@ struct MPI2_IOC_INIT_REQUEST {
>  
>  /* mrpriv defines */
>  #define MR_PD_INVALID 0xFFFF
> +#define MR_DEVHANDLE_INVALID 0xFFFF
>  #define MAX_SPAN_DEPTH 8
>  #define MAX_QUAD_DEPTH	MAX_SPAN_DEPTH
>  #define MAX_RAIDMAP_SPAN_DEPTH (MAX_SPAN_DEPTH)
> @@ -921,7 +922,6 @@ struct IO_REQUEST_INFO {
>  	u8  span_arm;	/* span[7:5], arm[4:0] */
>  	u8  pd_after_lb;
>  	u16 r1_alt_dev_handle; /* raid 1/10 only */
> -	bool is_raid_1_fp_write;
>  	bool ra_capable;
>  };
>  
> @@ -1060,7 +1060,6 @@ struct megasas_cmd_fusion {
>  	u32 index;
>  	u8 pd_r1_lb;
>  	struct completion done;
> -	bool is_raid_1_fp_write;
>  	u16 r1_alt_dev_handle; /* raid 1/10 only*/
>  	bool cmd_completed;  /* raid 1/10 fp writes status holder */
>  

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 06/39] megaraid_sas: RAID map is accessed for SYS PDs when use_seqnum_jbod_fp is not set
  2017-02-08  9:29 ` [PATCH v2 06/39] megaraid_sas: RAID map is accessed for SYS PDs when use_seqnum_jbod_fp is not set Shivasharan S
  2017-02-08 11:16   ` Hannes Reinecke
@ 2017-02-08 14:37   ` Tomas Henzl
  1 sibling, 0 replies; 57+ messages in thread
From: Tomas Henzl @ 2017-02-08 14:37 UTC (permalink / raw)
  To: Shivasharan S, linux-scsi
  Cc: martin.petersen, jejb, kashyap.desai, sumit.saxena, hare

On 8.2.2017 10:29, Shivasharan S wrote:
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>

Reviewed-by: Tomas Henzl <thenzl@redhat.com>

Tomas

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 09/39] megaraid_sas: change issue_dcmd to return void from int
  2017-02-08  9:29 ` [PATCH v2 09/39] megaraid_sas: change issue_dcmd to return void from int Shivasharan S
  2017-02-08 11:17   ` Hannes Reinecke
@ 2017-02-08 14:40   ` Tomas Henzl
  1 sibling, 0 replies; 57+ messages in thread
From: Tomas Henzl @ 2017-02-08 14:40 UTC (permalink / raw)
  To: Shivasharan S, linux-scsi
  Cc: martin.petersen, jejb, kashyap.desai, sumit.saxena, hare

On 8.2.2017 10:29, Shivasharan S wrote:
> fix in v2 : 
> 1. split patches into two as discussed below 
> http://marc.info/?l=linux-scsi&m=148638999110404&w=2
> 2. issue_dcmd return type changed from int to void.
>
>
> With the changes to remove checks for a valid request descriptor,
> issue_dcmd will now always return DCMD_SUCCESS. This patch changes
> return type of issue_dcmd to void and change all callers
> appropriately.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>

Reviewed-by: Tomas Henzl <thenzl@redhat.com>

Tomas

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 08/39] megaraid_sas: megasas_get_request_descriptor always return valid desc
  2017-02-08  9:29 ` [PATCH v2 08/39] megaraid_sas: megasas_get_request_descriptor always return valid desc Shivasharan S
  2017-02-08 11:17   ` Hannes Reinecke
@ 2017-02-08 14:40   ` Tomas Henzl
  2017-02-09 23:39   ` Martin K. Petersen
  2 siblings, 0 replies; 57+ messages in thread
From: Tomas Henzl @ 2017-02-08 14:40 UTC (permalink / raw)
  To: Shivasharan S, linux-scsi
  Cc: martin.petersen, jejb, kashyap.desai, sumit.saxena, hare

On 8.2.2017 10:29, Shivasharan S wrote:
> fix in v2 - split patches into two. 
> discussed below 
> http://marc.info/?l=linux-scsi&m=148638999110404&w=2
>
> No functional change. Code clean up. Removing error code which is not
> valid scenario.
> In megasas_get_request_descriptor we can remove the error handling
> which is not required.
> With fusion controllers, if there is a valid message frame available,
> we are guaranteed to get a corresponding request descriptor.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>

Reviewed-by: Tomas Henzl <thenzl@redhat.com>

Tomas

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 10/39] megaraid_sas: NVME Interface detection and prop settings
  2017-02-08  9:29 ` [PATCH v2 10/39] megaraid_sas: NVME Interface detection and prop settings Shivasharan S
  2017-02-08 11:59   ` Hannes Reinecke
@ 2017-02-08 14:48   ` Tomas Henzl
  1 sibling, 0 replies; 57+ messages in thread
From: Tomas Henzl @ 2017-02-08 14:48 UTC (permalink / raw)
  To: Shivasharan S, linux-scsi
  Cc: martin.petersen, jejb, kashyap.desai, sumit.saxena, hare

On 8.2.2017 10:29, Shivasharan S wrote:
> New functionality
> Adding detection logic for NVME device attached behind Ventura controller.
> Driver set HostPageSize in IOC_INIT frame to inform about page size for NVME devices.
> Firmware reports NVME page size to the driver.
> PD INFO DCMD provide new interface type NVME_PD. Driver set property of NVME device.
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>

Reviewed-by: Tomas Henzl <thenzl@redhat.com>

Tomas

^ permalink raw reply	[flat|nested] 57+ messages in thread

* RE: [PATCH v2 03/39] megaraid_sas: raid 1 fast path code optimize
  2017-02-08 14:34   ` Tomas Henzl
@ 2017-02-08 18:51     ` Kashyap Desai
  2017-02-09 13:15       ` Tomas Henzl
  0 siblings, 1 reply; 57+ messages in thread
From: Kashyap Desai @ 2017-02-08 18:51 UTC (permalink / raw)
  To: Tomas Henzl, Shivasharan Srikanteshwara, linux-scsi
  Cc: martin.petersen, jejb, Sumit Saxena, hare

> > +static inline void
> > +megasas_complete_r1_command(struct megasas_instance *instance,
> > +			    struct megasas_cmd_fusion *cmd) {
> > +	u8 *sense, status, ex_status;
> > +	u32 data_length;
> > +	u16 peer_smid;
> > +	struct fusion_context *fusion;
> > +	struct megasas_cmd_fusion *r1_cmd = NULL;
> > +	struct scsi_cmnd *scmd_local = NULL;
> > +	struct RAID_CONTEXT_G35 *rctx_g35;
> > +
> > +	rctx_g35 = &cmd->io_request->RaidContext.raid_context_g35;
> > +	fusion = instance->ctrl_context;
> > +	peer_smid = le16_to_cpu(rctx_g35->smid.peer_smid);
> > +
> > +	r1_cmd = fusion->cmd_list[peer_smid - 1];
> > +	scmd_local = cmd->scmd;
> > +	status = rctx_g35->status;
> > +	ex_status = rctx_g35->ex_status;
> > +	data_length = cmd->io_request->DataLength;
> > +	sense = cmd->sense;
> > +
> > +	cmd->cmd_completed = true;
>
> Please help me understand how this works
> - there are two peer commands sent to the controller
> - both are completed and the later calls scsi_done and returns both
r1_cmd
> + cmd
> - if both commands can be completed at the same time, is it possible
that
> the
>   above line is executed at the same moment for both completions ?
> How is the code  protected against a double completion when both
> completed commands see the peer cmd_completed as set ?


Tomas,  cmd and r1_cmd (part of  same Raid 1 FP) will be always completed
on same reply queue by firmware. That is one of the key requirement here
for raid 1 fast path.
What you ask is possible if FW completes cmd and r1_cmd on different reply
queue. If you notice when we clone r1_cmd, we also clone MSI-x index from
parent command.
So eventually, FW is aware of binding of both cmd and r1_cmd w.r.t reply
queue index.

` Kashyap

>
> > +

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 03/39] megaraid_sas: raid 1 fast path code optimize
  2017-02-08 18:51     ` Kashyap Desai
@ 2017-02-09 13:15       ` Tomas Henzl
  0 siblings, 0 replies; 57+ messages in thread
From: Tomas Henzl @ 2017-02-09 13:15 UTC (permalink / raw)
  To: Kashyap Desai, Shivasharan Srikanteshwara, linux-scsi
  Cc: martin.petersen, jejb, Sumit Saxena, hare

On 8.2.2017 19:51, Kashyap Desai wrote:
>>> +static inline void
>>> +megasas_complete_r1_command(struct megasas_instance *instance,
>>> +			    struct megasas_cmd_fusion *cmd) {
>>> +	u8 *sense, status, ex_status;
>>> +	u32 data_length;
>>> +	u16 peer_smid;
>>> +	struct fusion_context *fusion;
>>> +	struct megasas_cmd_fusion *r1_cmd = NULL;
>>> +	struct scsi_cmnd *scmd_local = NULL;
>>> +	struct RAID_CONTEXT_G35 *rctx_g35;
>>> +
>>> +	rctx_g35 = &cmd->io_request->RaidContext.raid_context_g35;
>>> +	fusion = instance->ctrl_context;
>>> +	peer_smid = le16_to_cpu(rctx_g35->smid.peer_smid);
>>> +
>>> +	r1_cmd = fusion->cmd_list[peer_smid - 1];
>>> +	scmd_local = cmd->scmd;
>>> +	status = rctx_g35->status;
>>> +	ex_status = rctx_g35->ex_status;
>>> +	data_length = cmd->io_request->DataLength;
>>> +	sense = cmd->sense;
>>> +
>>> +	cmd->cmd_completed = true;
>> Please help me understand how this works
>> - there are two peer commands sent to the controller
>> - both are completed and the later calls scsi_done and returns both
> r1_cmd
>> + cmd
>> - if both commands can be completed at the same time, is it possible
> that
>> the
>>   above line is executed at the same moment for both completions ?
>> How is the code  protected against a double completion when both
>> completed commands see the peer cmd_completed as set ?
>
> Tomas,  cmd and r1_cmd (part of  same Raid 1 FP) will be always completed
> on same reply queue by firmware. That is one of the key requirement here
> for raid 1 fast path.
> What you ask is possible if FW completes cmd and r1_cmd on different reply
> queue. If you notice when we clone r1_cmd, we also clone MSI-x index from
> parent command.
> So eventually, FW is aware of binding of both cmd and r1_cmd w.r.t reply
> queue index.

ok, thanks

>
> ` Kashyap
>
>>> +

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 03/39] megaraid_sas: raid 1 fast path code optimize
  2017-02-08  9:28 ` [PATCH v2 03/39] megaraid_sas: raid 1 fast path code optimize Shivasharan S
  2017-02-08 14:34   ` Tomas Henzl
@ 2017-02-09 13:16   ` Tomas Henzl
  1 sibling, 0 replies; 57+ messages in thread
From: Tomas Henzl @ 2017-02-09 13:16 UTC (permalink / raw)
  To: Shivasharan S, linux-scsi
  Cc: martin.petersen, jejb, kashyap.desai, sumit.saxena, hare

On 8.2.2017 10:28, Shivasharan S wrote:
> fix in v2 - ex_status and status was wrongly re-used in megasas_complete_r1_command.
> discussed below -
> http://marc.info/?l=linux-scsi&m=148638763409385&w=2
>
>
> No functional change. Code refactor.
> Remove function megasas_fpio_to_ldio as we never require to convert fpio to ldio because of frame unavailability.
> Grab extra frame of raid 1 write fast path before it creates first frame as Fast Path.
> Removed is_raid_1_fp_write flag as raid 1 write fast path command is decided using r1_alt_dev_handle only.
> Move resetting megasas_cmd_fusion fields at common function megasas_return_cmd_fusion.
>
>
> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>
> Reviewed-by: Hannes Reinecke <hare@suse.com>

Reviewed-by: Tomas Henzl <thenzl@redhat.com>

Tomas

^ permalink raw reply	[flat|nested] 57+ messages in thread

* RE: [PATCH v2 19/39] megaraid_sas: MR_TargetIdToLdGet u8 to u16 and avoid invalid raid-map access
  2017-02-08  9:29 ` [PATCH v2 19/39] megaraid_sas: MR_TargetIdToLdGet u8 to u16 and avoid invalid raid-map access Shivasharan S
@ 2017-02-09 14:31   ` Kashyap Desai
  0 siblings, 0 replies; 57+ messages in thread
From: Kashyap Desai @ 2017-02-09 14:31 UTC (permalink / raw)
  To: Shivasharan Srikanteshwara, linux-scsi
  Cc: martin.petersen, thenzl, jejb, Sumit Saxena, hare

> Signed-off-by: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
> Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com>

In this patch series, we are done with review but this particular patch
missed Review-by tag.

Kashyap

^ permalink raw reply	[flat|nested] 57+ messages in thread

* RE: [PATCH v2 21/39] megaraid_sas: big endian support changes
  2017-02-08  9:29 ` [PATCH v2 21/39] megaraid_sas: big endian support changes Shivasharan S
@ 2017-02-09 18:04   ` Kashyap Desai
  2017-02-09 23:44     ` Martin K. Petersen
  0 siblings, 1 reply; 57+ messages in thread
From: Kashyap Desai @ 2017-02-09 18:04 UTC (permalink / raw)
  To: Shivasharan Srikanteshwara, linux-scsi
  Cc: martin.petersen, thenzl, jejb, Sumit Saxena, hare

> +static inline void set_num_sge(struct RAID_CONTEXT_G35 rctx_g35,
> +			       u16 sge_count)
> +{
> +	rctx_g35.u.bytes[0] = (u8)(sge_count & NUM_SGE_MASK_LOWER);
> +	rctx_g35.u.bytes[1] |= (u8)((sge_count >> NUM_SGE_SHIFT_UPPER)
> +							&
> NUM_SGE_MASK_UPPER);
> +}

This function and below get_num_sge() need fix.  We have supposed to pass
pointer of struct RAID_CONTEXT_G35 to get correct setting reflected in IO
frame, otherwise it just set in stack local memory and that is not a
intent here. We will fix this patch and resend. Only fixing this patch and
resend works fine with complete series (there is no hunk failure observe),
so just going to push one particular patch with below title.

[PATCH v2 21/39 RESEND] megaraid_sas: big endian support changes

> +
> +static inline u16 get_num_sge(struct RAID_CONTEXT_G35 rctx_g35) {
> +	u16 sge_count;
> +
> +	sge_count = (u16)(((rctx_g35.u.bytes[1] & NUM_SGE_MASK_UPPER)
> +			<< NUM_SGE_SHIFT_UPPER) | (rctx_g35.u.bytes[0]));
> +	return sge_count;
> +}
> +
> +#define SET_STREAM_DETECTED(rctx_g35) \
> +	(rctx_g35.u.bytes[1] |= STREAM_DETECT_MASK)
> +
> +#define CLEAR_STREAM_DETECTED(rctx_g35) \
> +	(rctx_g35.u.bytes[1] &= ~(STREAM_DETECT_MASK))
> +
> +static inline bool is_stream_detected(struct RAID_CONTEXT_G35
> +*rctx_g35) {
> +	return ((rctx_g35->u.bytes[1] & STREAM_DETECT_MASK)); }
> +
>  union RAID_CONTEXT_UNION {
>  	struct RAID_CONTEXT raid_context;
>  	struct RAID_CONTEXT_G35 raid_context_g35;
> --
> 2.8.3

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 08/39] megaraid_sas: megasas_get_request_descriptor always return valid desc
  2017-02-08  9:29 ` [PATCH v2 08/39] megaraid_sas: megasas_get_request_descriptor always return valid desc Shivasharan S
  2017-02-08 11:17   ` Hannes Reinecke
  2017-02-08 14:40   ` Tomas Henzl
@ 2017-02-09 23:39   ` Martin K. Petersen
  2 siblings, 0 replies; 57+ messages in thread
From: Martin K. Petersen @ 2017-02-09 23:39 UTC (permalink / raw)
  To: Shivasharan S
  Cc: linux-scsi, martin.petersen, thenzl, jejb, kashyap.desai,
	sumit.saxena, hare

>>>>> "Shivasharan" == Shivasharan S <shivasharan.srikanteshwara@broadcom.com> writes:

Shivasharan> fix in v2 - split patches into two.  discussed below
Shivasharan> http://marc.info/?l=linux-scsi&m=148638999110404&w=2

^^^ Comments like this need to go after the "---" separator so they
don't show up in the commit message.

Shivasharan> No functional change. Code clean up. Removing error code
Shivasharan> which is not valid scenario.  In
Shivasharan> megasas_get_request_descriptor we can remove the error
Shivasharan> handling which is not required.  With fusion controllers,
Shivasharan> if there is a valid message frame available, we are
Shivasharan> guaranteed to get a corresponding request descriptor.

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 57+ messages in thread

* Re: [PATCH v2 21/39] megaraid_sas: big endian support changes
  2017-02-09 18:04   ` Kashyap Desai
@ 2017-02-09 23:44     ` Martin K. Petersen
  0 siblings, 0 replies; 57+ messages in thread
From: Martin K. Petersen @ 2017-02-09 23:44 UTC (permalink / raw)
  To: Kashyap Desai
  Cc: Shivasharan Srikanteshwara, linux-scsi, martin.petersen, thenzl,
	jejb, Sumit Saxena, hare

>>>>> "Kashyap" == Kashyap Desai <kashyap.desai@broadcom.com> writes:

Kashyap,

Kashyap> We will fix this patch and resend. Only fixing this patch and
Kashyap> resend works fine with complete series (there is no hunk
Kashyap> failure observe), so just going to push one particular patch
Kashyap> with below title.

Please just send a complete v3. Many patches in v2 have changelog
entries in the body of the commit message instead of after the ---
separator and I am not going to fix all those up by hand.

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 57+ messages in thread

end of thread, other threads:[~2017-02-10  6:13 UTC | newest]

Thread overview: 57+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-08  9:28 [PATCH v2 00/39] megaraid_sas: Updates for scsi-next Shivasharan S
2017-02-08  9:28 ` [PATCH v2 01/39] Revert "scsi: megaraid_sas: Enable or Disable Fast path based on the PCI Threshold Bandwidth" Shivasharan S
2017-02-08  9:28 ` [PATCH v2 02/39] megaraid_sas: cpu select rework Shivasharan S
2017-02-08  9:28 ` [PATCH v2 03/39] megaraid_sas: raid 1 fast path code optimize Shivasharan S
2017-02-08 14:34   ` Tomas Henzl
2017-02-08 18:51     ` Kashyap Desai
2017-02-09 13:15       ` Tomas Henzl
2017-02-09 13:16   ` Tomas Henzl
2017-02-08  9:28 ` [PATCH v2 04/39] megaraid_sas: 32 bit descriptor fire cmd optimization Shivasharan S
2017-02-08 11:15   ` Hannes Reinecke
2017-02-08  9:28 ` [PATCH v2 05/39] megaraid_sas: Refactor MEGASAS_IS_LOGICAL macro using sdev Shivasharan S
2017-02-08  9:29 ` [PATCH v2 06/39] megaraid_sas: RAID map is accessed for SYS PDs when use_seqnum_jbod_fp is not set Shivasharan S
2017-02-08 11:16   ` Hannes Reinecke
2017-02-08 14:37   ` Tomas Henzl
2017-02-08  9:29 ` [PATCH v2 07/39] megaraid_sas: Use DID_REQUEUE Shivasharan S
2017-02-08  9:29 ` [PATCH v2 08/39] megaraid_sas: megasas_get_request_descriptor always return valid desc Shivasharan S
2017-02-08 11:17   ` Hannes Reinecke
2017-02-08 14:40   ` Tomas Henzl
2017-02-09 23:39   ` Martin K. Petersen
2017-02-08  9:29 ` [PATCH v2 09/39] megaraid_sas: change issue_dcmd to return void from int Shivasharan S
2017-02-08 11:17   ` Hannes Reinecke
2017-02-08 14:40   ` Tomas Henzl
2017-02-08  9:29 ` [PATCH v2 10/39] megaraid_sas: NVME Interface detection and prop settings Shivasharan S
2017-02-08 11:59   ` Hannes Reinecke
2017-02-08 14:48   ` Tomas Henzl
2017-02-08  9:29 ` [PATCH v2 11/39] megaraid_sas: NVME interface target prop added Shivasharan S
2017-02-08  9:29 ` [PATCH v2 12/39] megaraid_sas: NVME fast path io support Shivasharan S
2017-02-08  9:29 ` [PATCH v2 13/39] megaraid_sas: raid 1 write performance for large io Shivasharan S
2017-02-08  9:29 ` [PATCH v2 14/39] megaraid_sas: set residual bytes count during IO completion Shivasharan S
2017-02-08  9:29 ` [PATCH v2 15/39] megaraid_sas: enhance debug logs in OCR context Shivasharan S
2017-02-08  9:29 ` [PATCH v2 16/39] megaraid_sas: add print in device removal path Shivasharan S
2017-02-08  9:29 ` [PATCH v2 17/39] megaraid_sas: reduce size of fusion_context and use vmalloc if kmalloc fails Shivasharan S
2017-02-08  9:29 ` [PATCH v2 18/39] megaraid_sas: In validate raid map, raid capability is not converted to cpu format for all lds Shivasharan S
2017-02-08  9:29 ` [PATCH v2 19/39] megaraid_sas: MR_TargetIdToLdGet u8 to u16 and avoid invalid raid-map access Shivasharan S
2017-02-09 14:31   ` Kashyap Desai
2017-02-08  9:29 ` [PATCH v2 20/39] megaraid_sas: Big endian RDPQ mode fix Shivasharan S
2017-02-08  9:29 ` [PATCH v2 21/39] megaraid_sas: big endian support changes Shivasharan S
2017-02-09 18:04   ` Kashyap Desai
2017-02-09 23:44     ` Martin K. Petersen
2017-02-08  9:29 ` [PATCH v2 22/39] megaraid_sas: avoid unaligned access in ioctl path Shivasharan S
2017-02-08  9:29 ` [PATCH v2 23/39] megaraid_sas: latest controller OCR capability from FW before sending shutdown DCMD Shivasharan S
2017-02-08  9:29 ` [PATCH v2 24/39] megaraid_sas: set pd_after_lb from MR_BuildRaidContext and initialize pDevHandle to MR_DEVHANDLE_INVALID Shivasharan S
2017-02-08  9:29 ` [PATCH v2 25/39] megaraid_sas: Change max_cmd from u32 to u16 in all functions Shivasharan S
2017-02-08  9:29 ` [PATCH v2 26/39] megaraid_sas: update can_queue only if the new value is less Shivasharan S
2017-02-08  9:29 ` [PATCH v2 27/39] megaraid_sas: max_fw_cmds are decremented twice, remove duplicate Shivasharan S
2017-02-08  9:29 ` [PATCH v2 28/39] megaraid_sas: megasas_return_cmd does not memset IO frame to zero Shivasharan S
2017-02-08  9:29 ` [PATCH v2 29/39] megaraid_sas: Remove unused pd_index from megasas_build_ld_nonrw_fusion Shivasharan S
2017-02-08  9:29 ` [PATCH v2 30/39] megaraid_sas: Do not set fp_possible if TM capable for non-RW syspdIO, change fp_possible to bool Shivasharan S
2017-02-08  9:29 ` [PATCH v2 31/39] megaraid_sas: During OCR, if get_ctrl_info fails do not continue with OCR Shivasharan S
2017-02-08  9:29 ` [PATCH v2 32/39] megaraid_sas: Change build_mpt_mfi_pass_thru to return void Shivasharan S
2017-02-08  9:29 ` [PATCH v2 33/39] megaraid_sas: Bail out the driver load if ld_list_query fails Shivasharan S
2017-02-08  9:29 ` [PATCH v2 34/39] megaraid_sas: Use synchronize_irq to wait for IRQs to complete Shivasharan S
2017-02-08  9:29 ` [PATCH v2 35/39] megaraid_sas: Increase internal command pool Shivasharan S
2017-02-08  9:29 ` [PATCH v2 36/39] megaraid_sas: Cleanup VD_EXT_DEBUG and SPAN_DEBUG related debug prints Shivasharan S
2017-02-08  9:29 ` [PATCH v2 37/39] megaraid_sas: Indentation and smatch warning fixes Shivasharan S
2017-02-08  9:29 ` [PATCH v2 38/39] megaraid_sas: Change RAID_1_10_RMW_CMDS to RAID_1_PEER_CMDS and set value to 2 Shivasharan S
2017-02-08  9:29 ` [PATCH v2 39/39] megaraid_sas: driver version upgrade Shivasharan S

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.