[scsi-next v2 1/2] scsi: megaraid_sas: Add megasas_dcmd_timeout helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



DCMD timeout is handled in many places, it makes sense to
add a helper to handle it. This patch adds a new helper
named megasas_dcmd_timeout() to reduce duplicate code.

Suggested-by: Geliang Tang <geliang@xxxxxxxxxx>
Co-developed-by: Jackie Liu <liuyun01@xxxxxxxxxx>
Signed-off-by: Jackie Liu <liuyun01@xxxxxxxxxx>
Signed-off-by: Fanhui Meng <mengfanhui@xxxxxxxxxx>
---
 drivers/scsi/megaraid/megaraid_sas.h      |   2 +
 drivers/scsi/megaraid/megaraid_sas_base.c | 198 ++++------------------
 2 files changed, 35 insertions(+), 165 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 5680c6cdb221..277f179157e8 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -2760,5 +2760,7 @@ void megasas_exit_debugfs(void);
 void megasas_setup_debugfs(struct megasas_instance *instance);
 void megasas_destroy_debugfs(struct megasas_instance *instance);
 int megasas_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num);
+void megasas_dcmd_timeout(struct megasas_instance *instance,
+			  struct megasas_cmd *cmd);
 
 #endif				/*LSI_MEGARAID_SAS_H */
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 6c79c350a4d5..e6a9cef027c0 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -4529,6 +4529,30 @@ dcmd_timeout_ocr_possible(struct megasas_instance *instance) {
 		return INITIATE_OCR;
 }
 
+/*
+ * megasas_dcmd_timeout -	Classification processing dcmd timeout.
+ * @instance:				Adapter soft state
+ */
+void megasas_dcmd_timeout(struct megasas_instance *instance, struct megasas_cmd *cmd)
+{
+	switch (dcmd_timeout_ocr_possible(instance)) {
+	case INITIATE_OCR:
+		cmd->flags |= DRV_DCMD_SKIP_REFIRE;
+		mutex_unlock(&instance->reset_mutex);
+		megasas_reset_fusion(instance->host,
+					MFI_IO_TIMEOUT_OCR);
+		mutex_lock(&instance->reset_mutex);
+		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;
+	}
+}
+
 static void
 megasas_get_pd_info(struct megasas_instance *instance, struct scsi_device *sdev)
 {
@@ -4580,24 +4604,7 @@ megasas_get_pd_info(struct megasas_instance *instance, struct scsi_device *sdev)
 		break;
 
 	case DCMD_TIMEOUT:
-
-		switch (dcmd_timeout_ocr_possible(instance)) {
-		case INITIATE_OCR:
-			cmd->flags |= DRV_DCMD_SKIP_REFIRE;
-			mutex_unlock(&instance->reset_mutex);
-			megasas_reset_fusion(instance->host,
-				MFI_IO_TIMEOUT_OCR);
-			mutex_lock(&instance->reset_mutex);
-			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;
-		}
-
+		megasas_dcmd_timeout(instance, cmd);
 		break;
 	}
 
@@ -4676,29 +4683,7 @@ megasas_get_pd_list(struct megasas_instance *instance)
 			instance->pd_list_not_supported = 1;
 		break;
 	case DCMD_TIMEOUT:
-
-		switch (dcmd_timeout_ocr_possible(instance)) {
-		case INITIATE_OCR:
-			cmd->flags |= DRV_DCMD_SKIP_REFIRE;
-			/*
-			 * DCMD failed from AEN path.
-			 * AEN path already hold reset_mutex to avoid PCI access
-			 * while OCR is in progress.
-			 */
-			mutex_unlock(&instance->reset_mutex);
-			megasas_reset_fusion(instance->host,
-						MFI_IO_TIMEOUT_OCR);
-			mutex_lock(&instance->reset_mutex);
-			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;
-		}
-
+		megasas_dcmd_timeout(instance, cmd);
 		break;
 
 	case DCMD_SUCCESS:
@@ -4803,29 +4788,7 @@ megasas_get_ld_list(struct megasas_instance *instance)
 		megaraid_sas_kill_hba(instance);
 		break;
 	case DCMD_TIMEOUT:
-
-		switch (dcmd_timeout_ocr_possible(instance)) {
-		case INITIATE_OCR:
-			cmd->flags |= DRV_DCMD_SKIP_REFIRE;
-			/*
-			 * DCMD failed from AEN path.
-			 * AEN path already hold reset_mutex to avoid PCI access
-			 * while OCR is in progress.
-			 */
-			mutex_unlock(&instance->reset_mutex);
-			megasas_reset_fusion(instance->host,
-						MFI_IO_TIMEOUT_OCR);
-			mutex_lock(&instance->reset_mutex);
-			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;
-		}
-
+		megasas_dcmd_timeout(instance, cmd);
 		break;
 
 	case DCMD_SUCCESS:
@@ -4923,28 +4886,7 @@ megasas_ld_list_query(struct megasas_instance *instance, u8 query_type)
 		ret = megasas_get_ld_list(instance);
 		break;
 	case DCMD_TIMEOUT:
-		switch (dcmd_timeout_ocr_possible(instance)) {
-		case INITIATE_OCR:
-			cmd->flags |= DRV_DCMD_SKIP_REFIRE;
-			/*
-			 * DCMD failed from AEN path.
-			 * AEN path already hold reset_mutex to avoid PCI access
-			 * while OCR is in progress.
-			 */
-			mutex_unlock(&instance->reset_mutex);
-			megasas_reset_fusion(instance->host,
-						MFI_IO_TIMEOUT_OCR);
-			mutex_lock(&instance->reset_mutex);
-			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;
-		}
-
+		megasas_dcmd_timeout(instance, cmd);
 		break;
 	case DCMD_SUCCESS:
 		tgtid_count = le32_to_cpu(ci->count);
@@ -5079,22 +5021,7 @@ megasas_host_device_list_query(struct megasas_instance *instance,
 		break;
 
 	case DCMD_TIMEOUT:
-		switch (dcmd_timeout_ocr_possible(instance)) {
-		case INITIATE_OCR:
-			cmd->flags |= DRV_DCMD_SKIP_REFIRE;
-			mutex_unlock(&instance->reset_mutex);
-			megasas_reset_fusion(instance->host,
-				MFI_IO_TIMEOUT_OCR);
-			mutex_lock(&instance->reset_mutex);
-			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;
-		}
+		megasas_dcmd_timeout(instance, cmd);
 		break;
 	case DCMD_FAILED:
 		dev_err(&instance->pdev->dev,
@@ -5230,22 +5157,7 @@ void megasas_get_snapdump_properties(struct megasas_instance *instance)
 		break;
 
 	case DCMD_TIMEOUT:
-		switch (dcmd_timeout_ocr_possible(instance)) {
-		case INITIATE_OCR:
-			cmd->flags |= DRV_DCMD_SKIP_REFIRE;
-			mutex_unlock(&instance->reset_mutex);
-			megasas_reset_fusion(instance->host,
-				MFI_IO_TIMEOUT_OCR);
-			mutex_lock(&instance->reset_mutex);
-			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;
-		}
+		megasas_dcmd_timeout(instance, cmd);
 	}
 
 	if (ret != DCMD_TIMEOUT)
@@ -5370,22 +5282,7 @@ megasas_get_ctrl_info(struct megasas_instance *instance)
 		break;
 
 	case DCMD_TIMEOUT:
-		switch (dcmd_timeout_ocr_possible(instance)) {
-		case INITIATE_OCR:
-			cmd->flags |= DRV_DCMD_SKIP_REFIRE;
-			mutex_unlock(&instance->reset_mutex);
-			megasas_reset_fusion(instance->host,
-				MFI_IO_TIMEOUT_OCR);
-			mutex_lock(&instance->reset_mutex);
-			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;
-		}
+		megasas_dcmd_timeout(instance, cmd);
 		break;
 	case DCMD_FAILED:
 		megaraid_sas_kill_hba(instance);
@@ -5452,20 +5349,7 @@ int megasas_set_crash_dump_params(struct megasas_instance *instance,
 		ret = megasas_issue_polled(instance, cmd);
 
 	if (ret == 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;
-		}
+		megasas_dcmd_timeout(instance, cmd);
 	} else
 		megasas_return_cmd(instance, cmd);
 
@@ -6838,23 +6722,7 @@ megasas_get_target_prop(struct megasas_instance *instance,
 
 	switch (ret) {
 	case DCMD_TIMEOUT:
-		switch (dcmd_timeout_ocr_possible(instance)) {
-		case INITIATE_OCR:
-			cmd->flags |= DRV_DCMD_SKIP_REFIRE;
-			mutex_unlock(&instance->reset_mutex);
-			megasas_reset_fusion(instance->host,
-					     MFI_IO_TIMEOUT_OCR);
-			mutex_lock(&instance->reset_mutex);
-			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;
-		}
+		megasas_dcmd_timeout(instance, cmd);
 		break;
 
 	default:
-- 
2.25.1





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux