From 71ee4048cf244043c9b67398e05a8f9fb3cd2e23 Mon Sep 17 00:00:00 2001
From: Yihang Li <liyihang9@huawei.com>
Date: Thu, 8 Jun 2023 11:04:49 +0800
Subject: [PATCH 102/108] scsi: hisi_sas: Block requests before take debugfs
 snapshot

driver inclusion
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I8F82P
CVE: NA

----------------------------------------------------------------------

When the FIO is running and the dump is triggered continuously, some SATA
I/Os fail to be returned to the upper layer due to the setting of
HISI_SAS_REJECT_CMD_BIT. The SCSI layer invokes the error processing
thread. However, sas_ata_hard_reset() also fails to be reset due to the
setting of HISI_SAS_REJECT_CMD_BIT. As a result, the device is disabled.
Call scsi_block_requests() and wait command complete before setting
HISI_SAS_REJECT_CMD_BIT to avoid SATA I/O failures.

Signed-off-by: Yihang Li <liyihang9@huawei.com>
Signed-off-by: xiabing <xiabing12@h-partners.com>
Signed-off-by: YunYi Yang <yangyunyi2@huawei.com>

 Conflicts:
	drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
---
 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
index e3fb9a9cd875..dc24bf2ad2c0 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
@@ -3409,22 +3409,25 @@ static const struct hisi_sas_debugfs_reg debugfs_ras_reg = {
 
 static void debugfs_snapshot_prepare_v3_hw(struct hisi_hba *hisi_hba)
 {
-	set_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
-
-	hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0);
+	struct Scsi_Host *shost = hisi_hba->shost;
 
+	scsi_block_requests(shost);
 	/* delay:100ms, timeout:5s */
 	wait_cmds_complete_timeout_v3_hw(hisi_hba, 100, 5000);
-
+	set_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
 	hisi_sas_sync_irqs(hisi_hba);
+	hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0);
 }
 
 static void debugfs_snapshot_restore_v3_hw(struct hisi_hba *hisi_hba)
 {
+	struct Scsi_Host *shost = hisi_hba->shost;
+
 	hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE,
 			 (u32)((1ULL << hisi_hba->queue_count) - 1));
 
 	clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags);
+	scsi_unblock_requests(shost);
 }
 
 static void hisi_sas_bist_test_prep_v3_hw(struct hisi_hba *hisi_hba)
-- 
2.27.0

