orgads / rpms / kernel

Forked from rpms/kernel 4 years ago
Clone
a8a466
From 87029b097c79483c8a03c68a065a78973e0456db Mon Sep 17 00:00:00 2001
a8a466
From: Sasikumar Chandrasekaran <sasikumar.pc@broadcom.com>
a8a466
Date: Tue, 10 Jan 2017 18:20:50 -0500
a8a466
Subject: [PATCH 08/11] scsi: megaraid_sas: Enable or Disable Fast path based
a8a466
 on the PCI Threshold Bandwidth
a8a466
a8a466
Large SEQ IO workload should sent as non fast path commands
a8a466
a8a466
Signed-off-by: Sasikumar Chandrasekaran <sasikumar.pc@broadcom.com>
a8a466
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
a8a466
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
a8a466
---
a8a466
 drivers/scsi/megaraid/megaraid_sas.h        |  8 +++++
a8a466
 drivers/scsi/megaraid/megaraid_sas_base.c   | 48 +++++++++++++++++++++++++++++
a8a466
 drivers/scsi/megaraid/megaraid_sas_fp.c     |  7 +++++
a8a466
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 16 ++++++----
a8a466
 drivers/scsi/megaraid/megaraid_sas_fusion.h |  2 +-
a8a466
 5 files changed, 74 insertions(+), 7 deletions(-)
a8a466
a8a466
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
a8a466
index d5205c4..f6ac1b2 100644
a8a466
--- a/drivers/scsi/megaraid/megaraid_sas.h
a8a466
+++ b/drivers/scsi/megaraid/megaraid_sas.h
a8a466
@@ -1429,6 +1429,8 @@ enum FW_BOOT_CONTEXT {
a8a466
 #define MFI_1068_FW_HANDSHAKE_OFFSET		0x64
a8a466
 #define MFI_1068_FW_READY			0xDDDD0000
a8a466
 
a8a466
+#define MEGASAS_RAID1_FAST_PATH_STATUS_CHECK_INTERVAL HZ
a8a466
+
a8a466
 #define MR_MAX_REPLY_QUEUES_OFFSET              0X0000001F
a8a466
 #define MR_MAX_REPLY_QUEUES_EXT_OFFSET          0X003FC000
a8a466
 #define MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT    14
a8a466
@@ -2101,6 +2103,10 @@ struct megasas_instance {
a8a466
 	atomic_t ldio_outstanding;
a8a466
 	atomic_t fw_reset_no_pci_access;
a8a466
 
a8a466
+	atomic64_t bytes_wrote; /* used for raid1 fast path enable or disable */
a8a466
+	atomic_t r1_write_fp_capable;
a8a466
+
a8a466
+
a8a466
 	struct megasas_instance_template *instancet;
a8a466
 	struct tasklet_struct isr_tasklet;
a8a466
 	struct work_struct work_init;
a8a466
@@ -2143,6 +2149,7 @@ struct megasas_instance {
a8a466
 	long reset_flags;
a8a466
 	struct mutex reset_mutex;
a8a466
 	struct timer_list sriov_heartbeat_timer;
a8a466
+	struct timer_list r1_fp_hold_timer;
a8a466
 	char skip_heartbeat_timer_del;
a8a466
 	u8 requestorId;
a8a466
 	char PlasmaFW111;
a8a466
@@ -2159,6 +2166,7 @@ struct megasas_instance {
a8a466
 	bool is_ventura;
a8a466
 	bool msix_combined;
a8a466
 	u16 max_raid_mapsize;
a8a466
+	u64 pci_threshold_bandwidth; /* used to control the fp writes */
a8a466
 };
a8a466
 struct MR_LD_VF_MAP {
a8a466
 	u32 size;
a8a466
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
a8a466
index 8b0c686..cab3be8 100644
a8a466
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
a8a466
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
a8a466
@@ -1959,6 +1959,9 @@ void megaraid_sas_kill_hba(struct megasas_instance *instance)
a8a466
 	}
a8a466
 	/* Complete outstanding ioctls when adapter is killed */
a8a466
 	megasas_complete_outstanding_ioctls(instance);
a8a466
+	if (instance->is_ventura)
a8a466
+		del_timer_sync(&instance->r1_fp_hold_timer);
a8a466
+
a8a466
 }
a8a466
 
a8a466
  /**
a8a466
@@ -2457,6 +2460,24 @@ void megasas_sriov_heartbeat_handler(unsigned long instance_addr)
a8a466
 	}
a8a466
 }
a8a466
 
a8a466
+/*Handler for disabling/enabling raid 1 fast paths*/
a8a466
+void megasas_change_r1_fp_status(unsigned long instance_addr)
a8a466
+{
a8a466
+	struct megasas_instance *instance =
a8a466
+			(struct megasas_instance *)instance_addr;
a8a466
+	if (atomic64_read(&instance->bytes_wrote) >=
a8a466
+					instance->pci_threshold_bandwidth) {
a8a466
+
a8a466
+		atomic64_set(&instance->bytes_wrote, 0);
a8a466
+		atomic_set(&instance->r1_write_fp_capable, 0);
a8a466
+	} else {
a8a466
+		atomic64_set(&instance->bytes_wrote, 0);
a8a466
+		atomic_set(&instance->r1_write_fp_capable, 1);
a8a466
+	}
a8a466
+	mod_timer(&instance->r1_fp_hold_timer,
a8a466
+	 jiffies + MEGASAS_RAID1_FAST_PATH_STATUS_CHECK_INTERVAL);
a8a466
+}
a8a466
+
a8a466
 /**
a8a466
  * megasas_wait_for_outstanding -	Wait for all outstanding cmds
a8a466
  * @instance:				Adapter soft state
a8a466
@@ -5403,6 +5424,17 @@ static int megasas_init_fw(struct megasas_instance *instance)
a8a466
 			instance->skip_heartbeat_timer_del = 1;
a8a466
 	}
a8a466
 
a8a466
+	if (instance->is_ventura) {
a8a466
+		atomic64_set(&instance->bytes_wrote, 0);
a8a466
+		atomic_set(&instance->r1_write_fp_capable, 1);
a8a466
+		megasas_start_timer(instance,
a8a466
+			    &instance->r1_fp_hold_timer,
a8a466
+			    megasas_change_r1_fp_status,
a8a466
+			    MEGASAS_RAID1_FAST_PATH_STATUS_CHECK_INTERVAL);
a8a466
+				dev_info(&instance->pdev->dev, "starting the raid 1 fp timer with interval %d\n",
a8a466
+				MEGASAS_RAID1_FAST_PATH_STATUS_CHECK_INTERVAL);
a8a466
+	}
a8a466
+
a8a466
 	return 0;
a8a466
 
a8a466
 fail_get_ld_pd_list:
a8a466
@@ -6202,6 +6234,9 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t state)
a8a466
 	if (instance->requestorId && !instance->skip_heartbeat_timer_del)
a8a466
 		del_timer_sync(&instance->sriov_heartbeat_timer);
a8a466
 
a8a466
+	if (instance->is_ventura)
a8a466
+		del_timer_sync(&instance->r1_fp_hold_timer);
a8a466
+
a8a466
 	megasas_flush_cache(instance);
a8a466
 	megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN);
a8a466
 
a8a466
@@ -6321,6 +6356,16 @@ megasas_resume(struct pci_dev *pdev)
a8a466
 	megasas_setup_jbod_map(instance);
a8a466
 	instance->unload = 0;
a8a466
 
a8a466
+	if (instance->is_ventura) {
a8a466
+		atomic64_set(&instance->bytes_wrote, 0);
a8a466
+		atomic_set(&instance->r1_write_fp_capable, 1);
a8a466
+		megasas_start_timer(instance,
a8a466
+			    &instance->r1_fp_hold_timer,
a8a466
+			    megasas_change_r1_fp_status,
a8a466
+			    MEGASAS_RAID1_FAST_PATH_STATUS_CHECK_INTERVAL);
a8a466
+	}
a8a466
+
a8a466
+
a8a466
 	/*
a8a466
 	 * Initiate AEN (Asynchronous Event Notification)
a8a466
 	 */
a8a466
@@ -6381,6 +6426,9 @@ static void megasas_detach_one(struct pci_dev *pdev)
a8a466
 	if (instance->requestorId && !instance->skip_heartbeat_timer_del)
a8a466
 		del_timer_sync(&instance->sriov_heartbeat_timer);
a8a466
 
a8a466
+	if (instance->is_ventura)
a8a466
+		del_timer_sync(&instance->r1_fp_hold_timer);
a8a466
+
a8a466
 	if (instance->fw_crash_state != UNAVAILABLE)
a8a466
 		megasas_free_host_crash_buffer(instance);
a8a466
 	scsi_remove_host(instance->host);
a8a466
diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
a8a466
index e45affe..5cad7c6 100644
a8a466
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
a8a466
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
a8a466
@@ -197,6 +197,9 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
a8a466
 
a8a466
 	if (instance->max_raid_mapsize) {
a8a466
 		fw_map_dyn = fusion->ld_map[(instance->map_id & 1)];
a8a466
+		if (fw_map_dyn->pci_threshold_bandwidth)
a8a466
+			instance->pci_threshold_bandwidth =
a8a466
+			le64_to_cpu(fw_map_dyn->pci_threshold_bandwidth);
a8a466
 #if VD_EXT_DEBUG
a8a466
 		dev_dbg(&instance->pdev->dev, "raidMapSize 0x%x fw_map_dyn->descTableOffset 0x%x\n",
a8a466
 			le32_to_cpu(fw_map_dyn->raid_map_size),
a8a466
@@ -204,6 +207,8 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
a8a466
 		dev_dbg(&instance->pdev->dev, "descTableSize 0x%x descTableNumElements 0x%x\n",
a8a466
 			le32_to_cpu(fw_map_dyn->desc_table_size),
a8a466
 			le32_to_cpu(fw_map_dyn->desc_table_num_elements));
a8a466
+		dev_dbg(&instance->pdev->dev, "PCIThreasholdBandwidth %llu\n",
a8a466
+			instance->pci_threshold_bandwidth);
a8a466
 		dev_dbg(&instance->pdev->dev, "drv map %p ldCount %d\n",
a8a466
 			drv_map, fw_map_dyn->ld_count);
a8a466
 #endif
a8a466
@@ -434,6 +439,8 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
a8a466
 			sizeof(struct MR_DEV_HANDLE_INFO) *
a8a466
 			MAX_RAIDMAP_PHYSICAL_DEVICES);
a8a466
 	}
a8a466
+	if (instance->is_ventura && !instance->pci_threshold_bandwidth)
a8a466
+		instance->pci_threshold_bandwidth = ULLONG_MAX;
a8a466
 }
a8a466
 
a8a466
 /*
a8a466
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
a8a466
index 1802c57..5689a44 100644
a8a466
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
a8a466
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
a8a466
@@ -95,6 +95,7 @@ extern unsigned int resetwaittime;
a8a466
 extern unsigned int dual_qdepth_disable;
a8a466
 static void megasas_free_rdpq_fusion(struct megasas_instance *instance);
a8a466
 static void megasas_free_reply_fusion(struct megasas_instance *instance);
a8a466
+void megasas_change_r1_fp_status(unsigned long instance_addr);
a8a466
 
a8a466
 
a8a466
 
a8a466
@@ -2628,8 +2629,9 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
a8a466
 	 *	to get new command
a8a466
 	 */
a8a466
 	if (cmd->is_raid_1_fp_write &&
a8a466
-		atomic_inc_return(&instance->fw_outstanding) >
a8a466
-			(instance->host->can_queue)) {
a8a466
+		(atomic_inc_return(&instance->fw_outstanding) >
a8a466
+			(instance->host->can_queue) ||
a8a466
+		(!atomic_read(&instance->r1_write_fp_capable)))) {
a8a466
 		megasas_fpio_to_ldio(instance, cmd, cmd->scmd);
a8a466
 		atomic_dec(&instance->fw_outstanding);
a8a466
 	} else if (cmd->is_raid_1_fp_write) {
a8a466
@@ -2638,17 +2640,19 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
a8a466
 		megasas_prepare_secondRaid1_IO(instance, cmd, r1_cmd);
a8a466
 	}
a8a466
 
a8a466
-
a8a466
 	/*
a8a466
 	 * Issue the command to the FW
a8a466
 	 */
a8a466
+	if (scmd->sc_data_direction == PCI_DMA_TODEVICE && instance->is_ventura)
a8a466
+		atomic64_add(scsi_bufflen(scmd), &instance->bytes_wrote);
a8a466
 
a8a466
 	megasas_fire_cmd_fusion(instance, req_desc, instance->is_ventura);
a8a466
 
a8a466
-	if (r1_cmd)
a8a466
+	if (r1_cmd) {
a8a466
+		atomic64_add(scsi_bufflen(scmd), &instance->bytes_wrote);
a8a466
 		megasas_fire_cmd_fusion(instance, r1_cmd->request_desc,
a8a466
-				instance->is_ventura);
a8a466
-
a8a466
+			instance->is_ventura);
a8a466
+	}
a8a466
 
a8a466
 	return 0;
a8a466
 }
a8a466
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
a8a466
index b24262a..f7384c1 100644
a8a466
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
a8a466
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
a8a466
@@ -977,7 +977,7 @@ struct MR_FW_RAID_MAP_DYNAMIC {
a8a466
 	u32 desc_table_size;  /* Total Size of desc table */
a8a466
 	/* Total Number of elements in the desc table */
a8a466
 	u32 desc_table_num_elements;
a8a466
-	u64	reserved1;
a8a466
+	u64	pci_threshold_bandwidth;
a8a466
 	u32	reserved2[3];	/*future use */
a8a466
 	/* timeout value used by driver in FP IOs */
a8a466
 	u8 fp_pd_io_timeout_sec;
a8a466
-- 
a8a466
1.8.3.1
a8a466