husy394 / rpms / kernel

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