From e76a783513021ac95991998de83772b6f5605bb9 Mon Sep 17 00:00:00 2001
From: Lee Duncan <lduncan@suse.com>
Date: Jun 02 2025 19:53:19 +0000
Subject: scsi: hisi_sas: Fix I/O errors caused by hardware port ID

changes (git-fixes).

---

diff --git a/patches.suse/scsi-hisi_sas-Fix-I-O-errors-caused-by-hardware-port-ID-ch.patch b/patches.suse/scsi-hisi_sas-Fix-I-O-errors-caused-by-hardware-port-ID-ch.patch
new file mode 100644
index 0000000..2cbc50f
--- /dev/null
+++ b/patches.suse/scsi-hisi_sas-Fix-I-O-errors-caused-by-hardware-port-ID-ch.patch
@@ -0,0 +1,55 @@
+From: Xingui Yang <yangxingui@huawei.com>
+Date: Wed, 12 Mar 2025 17:51:35 +0800
+Subject: scsi: hisi_sas: Fix I/O errors caused by hardware port ID changes
+Git-commit: daff37f00c7506ca322ccfce95d342022f06ec58
+Patch-mainline: v6.15-rc3
+References: git-fixes
+
+The hw port ID of phy may change when inserting disks in batches, causing
+the port ID in hisi_sas_port and itct to be inconsistent with the hardware,
+resulting in I/O errors. The solution is to set the device state to gone to
+intercept I/O sent to the device, and then execute linkreset to discard and
+find the disk to re-update its information.
+
+Signed-off-by: Xingui Yang <yangxingui@huawei.com>
+Link: https://lore.kernel.org/r/20250312095135.3048379-3-yangxingui@huawei.com
+Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
+Acked-by: Lee Duncan <lduncan@suse.com>
+---
+ drivers/scsi/hisi_sas/hisi_sas_main.c | 20 ++++++++++++++++++++
+ 1 file changed, 20 insertions(+)
+
+diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c
+index 3596414d970b..7a484ad0f9ab 100644
+--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
++++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
+@@ -935,8 +935,28 @@ static void hisi_sas_phyup_work_common(struct work_struct *work,
+ 		container_of(work, typeof(*phy), works[event]);
+ 	struct hisi_hba *hisi_hba = phy->hisi_hba;
+ 	struct asd_sas_phy *sas_phy = &phy->sas_phy;
++	struct asd_sas_port *sas_port = sas_phy->port;
++	struct hisi_sas_port *port = phy->port;
++	struct device *dev = hisi_hba->dev;
++	struct domain_device *port_dev;
+ 	int phy_no = sas_phy->id;
+ 
++	if (!test_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags) &&
++	    sas_port && port && (port->id != phy->port_id)) {
++		dev_info(dev, "phy%d's hw port id changed from %d to %llu\n",
++				phy_no, port->id, phy->port_id);
++		port_dev = sas_port->port_dev;
++		if (port_dev && !dev_is_expander(port_dev->dev_type)) {
++			/*
++			 * Set the device state to gone to block
++			 * sending IO to the device.
++			 */
++			set_bit(SAS_DEV_GONE, &port_dev->state);
++			hisi_sas_notify_phy_event(phy, HISI_PHYE_LINK_RESET);
++			return;
++		}
++	}
++
+ 	phy->wait_phyup_cnt = 0;
+ 	if (phy->identify.target_port_protocols == SAS_PROTOCOL_SSP)
+ 		hisi_hba->hw->sl_notify_ssp(hisi_hba, phy_no);
+
diff --git a/series.conf b/series.conf
index 3c8c3dd..ad89e82 100644
--- a/series.conf
+++ b/series.conf
@@ -31626,6 +31626,7 @@
 	patches.suse/mm-un-track_pfn_copy-fix-doc-improvements.patch
 	patches.suse/ata-libata-sata-Save-all-fields-from-sense-data-desc.patch
 	patches.suse/scsi-hisi_sas-Enable-force-phy-when-SATA-disk-directly-con.patch
+	patches.suse/scsi-hisi_sas-Fix-I-O-errors-caused-by-hardware-port-ID-ch.patch
 	patches.suse/scsi-iscsi-Fix-missing-scsi_host_put-in-error-path.patch
 	patches.suse/asus-laptop-Fix-an-uninitialized-variable.patch
 	patches.suse/ALSA-hda-realtek-Fixed-ASUS-platform-headset-Mic-iss-b5458fc.patch